feat(hermes): add kanban profile routing controls

This commit is contained in:
晴天
2026-05-27 01:14:10 +08:00
parent ae9d6e8844
commit 8703dffc5b
6 changed files with 168 additions and 1 deletions

View File

@@ -3425,6 +3425,15 @@ function formHermesBool(form, key, fallback) {
return readHermesBool(form?.[key], fallback)
}
function normalizeHermesKanbanOptionalString(value, key, strict = false) {
if (value === undefined || value === null) return ''
if (typeof value !== 'string') {
if (strict) throw new Error(`${key} must be a string`)
return ''
}
return value.trim()
}
function normalizeHermesStreamingTransport(value, strict = false) {
const transport = String(value ?? '').trim().toLowerCase() || 'edit'
if (HERMES_STREAMING_TRANSPORTS.has(transport)) return transport
@@ -3816,6 +3825,16 @@ export function buildHermesKanbanConfigValues(config = {}) {
100,
false,
),
orchestratorProfile: normalizeHermesKanbanOptionalString(
kanban.orchestrator_profile,
'kanban.orchestrator_profile',
false,
),
defaultAssignee: normalizeHermesKanbanOptionalString(
kanban.default_assignee,
'kanban.default_assignee',
false,
),
dispatchStaleTimeoutSeconds: parseHermesInteger(
kanban.dispatch_stale_timeout_seconds,
'kanban.dispatch_stale_timeout_seconds',
@@ -3896,6 +3915,20 @@ export function mergeHermesKanbanConfig(config = {}, form = {}) {
100,
true,
)
const orchestratorProfile = normalizeHermesKanbanOptionalString(
Object.hasOwn(form, 'orchestratorProfile') ? form.orchestratorProfile : currentValues.orchestratorProfile,
'kanban.orchestrator_profile',
true,
)
if (orchestratorProfile) kanban.orchestrator_profile = orchestratorProfile
else delete kanban.orchestrator_profile
const defaultAssignee = normalizeHermesKanbanOptionalString(
Object.hasOwn(form, 'defaultAssignee') ? form.defaultAssignee : currentValues.defaultAssignee,
'kanban.default_assignee',
true,
)
if (defaultAssignee) kanban.default_assignee = defaultAssignee
else delete kanban.default_assignee
kanban.dispatch_stale_timeout_seconds = parseHermesInteger(
Object.hasOwn(form, 'dispatchStaleTimeoutSeconds') ? form.dispatchStaleTimeoutSeconds : currentValues.dispatchStaleTimeoutSeconds,
'kanban.dispatch_stale_timeout_seconds',

View File

@@ -6605,6 +6605,12 @@ fn build_hermes_kanban_config_values(config: &serde_yaml::Value) -> Value {
100,
))
.unwrap_or(1),
"orchestratorProfile": kanban
.and_then(|map| yaml_string_field(map, "orchestrator_profile"))
.unwrap_or_default(),
"defaultAssignee": kanban
.and_then(|map| yaml_string_field(map, "default_assignee"))
.unwrap_or_default(),
"dispatchStaleTimeoutSeconds": kanban
.map(|map| bounded_hermes_i64(
yaml_i64_field(map, "dispatch_stale_timeout_seconds"),
@@ -6674,6 +6680,30 @@ fn merge_hermes_kanban_config(config: &mut serde_yaml::Value, form: &Value) -> R
0,
100,
)?;
let orchestrator_profile = if form.get("orchestratorProfile").is_some() {
form_string(form, "orchestratorProfile")
.ok_or_else(|| "kanban.orchestrator_profile must be a string".to_string())?
.trim()
.to_string()
} else {
current["orchestratorProfile"]
.as_str()
.unwrap_or_default()
.trim()
.to_string()
};
let default_assignee = if form.get("defaultAssignee").is_some() {
form_string(form, "defaultAssignee")
.ok_or_else(|| "kanban.default_assignee must be a string".to_string())?
.trim()
.to_string()
} else {
current["defaultAssignee"]
.as_str()
.unwrap_or_default()
.trim()
.to_string()
};
let stale_timeout = validate_hermes_i64(
form_i64(form, "dispatchStaleTimeoutSeconds")
.or_else(|| current["dispatchStaleTimeoutSeconds"].as_i64()),
@@ -6728,6 +6758,8 @@ fn merge_hermes_kanban_config(config: &mut serde_yaml::Value, form: &Value) -> R
yaml_key("worker_log_backup_count"),
serde_yaml::Value::Number(serde_yaml::Number::from(worker_log_backup_count)),
);
set_optional_yaml_string(kanban, "orchestrator_profile", orchestrator_profile);
set_optional_yaml_string(kanban, "default_assignee", default_assignee);
kanban.insert(
yaml_key("dispatch_stale_timeout_seconds"),
serde_yaml::Value::Number(serde_yaml::Number::from(stale_timeout)),
@@ -19500,6 +19532,8 @@ mod hermes_kanban_config_tests {
assert_eq!(values["autoDecomposePerTick"], 3);
assert_eq!(values["workerLogRotateBytes"], 2097152);
assert_eq!(values["workerLogBackupCount"], 1);
assert_eq!(values["orchestratorProfile"], "");
assert_eq!(values["defaultAssignee"], "");
assert_eq!(values["dispatchStaleTimeoutSeconds"], 14400);
}
@@ -19517,6 +19551,8 @@ kanban:
auto_decompose_per_tick: "7"
worker_log_rotate_bytes: "4194304"
worker_log_backup_count: "3"
orchestrator_profile: triage
default_assignee: builder
dispatch_stale_timeout_seconds: "7200"
"#,
)
@@ -19531,6 +19567,8 @@ kanban:
assert_eq!(values["autoDecomposePerTick"], 7);
assert_eq!(values["workerLogRotateBytes"], 4194304);
assert_eq!(values["workerLogBackupCount"], 3);
assert_eq!(values["orchestratorProfile"], "triage");
assert_eq!(values["defaultAssignee"], "builder");
assert_eq!(values["dispatchStaleTimeoutSeconds"], 7200);
}
@@ -19563,6 +19601,8 @@ memory:
"autoDecomposePerTick": 2,
"workerLogRotateBytes": 1048576,
"workerLogBackupCount": 0,
"orchestratorProfile": "triage",
"defaultAssignee": "builder",
"dispatchStaleTimeoutSeconds": 0,
}),
)
@@ -19595,12 +19635,46 @@ memory:
config["kanban"]["worker_log_backup_count"].as_i64(),
Some(0)
);
assert_eq!(
config["kanban"]["orchestrator_profile"].as_str(),
Some("triage")
);
assert_eq!(
config["kanban"]["default_assignee"].as_str(),
Some("builder")
);
assert_eq!(
config["kanban"]["dispatch_stale_timeout_seconds"].as_i64(),
Some(0)
);
}
#[test]
fn merge_kanban_config_removes_optional_profile_routes() {
let mut config: serde_yaml::Value = serde_yaml::from_str(
r#"
kanban:
orchestrator_profile: triage
default_assignee: builder
custom_flag: keep-me
"#,
)
.unwrap();
merge_hermes_kanban_config(
&mut config,
&json!({
"orchestratorProfile": " ",
"defaultAssignee": "",
}),
)
.unwrap();
assert_eq!(config["kanban"]["custom_flag"].as_str(), Some("keep-me"));
assert!(config["kanban"].get("orchestrator_profile").is_none());
assert!(config["kanban"].get("default_assignee").is_none());
}
#[test]
fn merge_kanban_config_removes_optional_concurrency_limits() {
let mut config: serde_yaml::Value = serde_yaml::from_str(
@@ -19657,6 +19731,14 @@ kanban:
.unwrap_err();
assert!(err.contains("kanban.worker_log_backup_count"));
let err = merge_hermes_kanban_config(&mut config, &json!({ "orchestratorProfile": 123 }))
.unwrap_err();
assert!(err.contains("kanban.orchestrator_profile"));
let err = merge_hermes_kanban_config(&mut config, &json!({ "defaultAssignee": false }))
.unwrap_err();
assert!(err.contains("kanban.default_assignee"));
let err =
merge_hermes_kanban_config(&mut config, &json!({ "dispatchStaleTimeoutSeconds": -1 }))
.unwrap_err();

View File

@@ -183,6 +183,8 @@ const KANBAN_DEFAULTS = {
autoDecomposePerTick: 3,
workerLogRotateBytes: 2097152,
workerLogBackupCount: 1,
orchestratorProfile: '',
defaultAssignee: '',
dispatchStaleTimeoutSeconds: 14400,
}
@@ -1535,6 +1537,14 @@ export function render() {
<span class="hm-field-label">${t('engine.hermesKanbanConfigWorkerLogBackupCount')}</span>
<input id="hm-kanban-worker-log-backup-count" class="hm-input" type="number" inputmode="numeric" min="0" max="100" step="1" value="${esc(kanbanValues.workerLogBackupCount)}" ${disabled ? 'disabled' : ''}>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesKanbanConfigOrchestratorProfile')}</span>
<input id="hm-kanban-orchestrator-profile" class="hm-input" type="text" value="${esc(kanbanValues.orchestratorProfile)}" placeholder="${t('engine.hermesKanbanConfigProfileDefault')}" ${disabled ? 'disabled' : ''}>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesKanbanConfigDefaultAssignee')}</span>
<input id="hm-kanban-default-assignee" class="hm-input" type="text" value="${esc(kanbanValues.defaultAssignee)}" placeholder="${t('engine.hermesKanbanConfigProfileDefault')}" ${disabled ? 'disabled' : ''}>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesKanbanConfigDispatchStaleTimeoutSeconds')}</span>
<input id="hm-kanban-dispatch-stale-timeout-seconds" class="hm-input" type="number" inputmode="numeric" min="0" max="604800" step="60" value="${esc(kanbanValues.dispatchStaleTimeoutSeconds)}" ${disabled ? 'disabled' : ''}>
@@ -3542,6 +3552,8 @@ export function render() {
autoDecomposePerTick: el.querySelector('#hm-kanban-auto-decompose-per-tick')?.value || '3',
workerLogRotateBytes: el.querySelector('#hm-kanban-worker-log-rotate-bytes')?.value || '2097152',
workerLogBackupCount: el.querySelector('#hm-kanban-worker-log-backup-count')?.value || '1',
orchestratorProfile: el.querySelector('#hm-kanban-orchestrator-profile')?.value || '',
defaultAssignee: el.querySelector('#hm-kanban-default-assignee')?.value || '',
dispatchStaleTimeoutSeconds: el.querySelector('#hm-kanban-dispatch-stale-timeout-seconds')?.value || '14400',
}
kanbanSaving = true

View File

@@ -1044,8 +1044,11 @@ export default {
hermesKanbanConfigAutoDecomposePerTick: _('每轮自动拆解数量', 'Auto decompose per tick', '每輪自動拆解數量'),
hermesKanbanConfigWorkerLogRotateBytes: _('Worker 日志轮转大小(字节)', 'Worker log rotation size (bytes)', 'Worker 日誌輪轉大小(位元組)'),
hermesKanbanConfigWorkerLogBackupCount: _('Worker 日志备份数量', 'Worker log backups', 'Worker 日誌備份數量'),
hermesKanbanConfigOrchestratorProfile: _('拆解任务使用的 Profile', 'Profile for decomposing tasks', '拆解任務使用的 Profile'),
hermesKanbanConfigDefaultAssignee: _('无法匹配时分配给', 'Assign to when no match is found', '無法匹配時分配給'),
hermesKanbanConfigProfileDefault: _('留空使用当前默认 Profile', 'Leave empty to use the current default profile', '留空使用目前預設 Profile'),
hermesKanbanConfigDispatchStaleTimeoutSeconds: _('无心跳回收时间(秒)', 'Heartbeat reclaim timeout (s)', '無心跳回收時間(秒)'),
hermesKanbanConfigFootnote: _('写入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、worker_log_rotate_bytes、worker_log_backup_count、dispatch_stale_timeout_seconds。两个并发上限填 0 表示不写入限制Worker 日志超过轮转大小会在下次启动前处理,备份数量填 0 表示超限时不保留旧日志;无心跳回收填 0 表示关闭自动回收。', 'Writes kanban.dispatch_in_gateway, dispatch_interval_seconds, max_spawn, max_in_progress, failure_limit, auto_decompose, auto_decompose_per_tick, worker_log_rotate_bytes, worker_log_backup_count, and dispatch_stale_timeout_seconds. Set concurrency caps to 0 to omit limits; worker logs are handled before the next worker starts after they exceed the rotation size, and 0 backups means old logs are not kept; set heartbeat reclaim to 0 to disable automatic reclaim.', '寫入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、worker_log_rotate_bytes、worker_log_backup_count、dispatch_stale_timeout_seconds。兩個並發上限填 0 表示不寫入限制Worker 日誌超過輪轉大小會在下次啟動前處理,備份數量填 0 表示超限時不保留舊日誌;無心跳回收填 0 表示關閉自動回收。'),
hermesKanbanConfigFootnote: _('写入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、worker_log_rotate_bytes、worker_log_backup_count、orchestrator_profile、default_assignee、dispatch_stale_timeout_seconds。两个并发上限填 0 表示不写入限制Worker 日志超过轮转大小会在下次启动前处理,备份数量填 0 表示超限时不保留旧日志;Profile 路由留空时使用 Hermes 当前默认 Profile无心跳回收填 0 表示关闭自动回收。', 'Writes kanban.dispatch_in_gateway, dispatch_interval_seconds, max_spawn, max_in_progress, failure_limit, auto_decompose, auto_decompose_per_tick, worker_log_rotate_bytes, worker_log_backup_count, orchestrator_profile, default_assignee, and dispatch_stale_timeout_seconds. Set concurrency caps to 0 to omit limits; worker logs are handled before the next worker starts after they exceed the rotation size, and 0 backups means old logs are not kept; empty profile routing uses Hermes current default profile; set heartbeat reclaim to 0 to disable automatic reclaim.', '寫入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、worker_log_rotate_bytes、worker_log_backup_count、orchestrator_profile、default_assignee、dispatch_stale_timeout_seconds。兩個並發上限填 0 表示不寫入限制Worker 日誌超過輪轉大小會在下次啟動前處理,備份數量填 0 表示超限時不保留舊日誌;Profile 路由留空時使用 Hermes 目前預設 Profile無心跳回收填 0 表示關閉自動回收。'),
hermesSecurityConfigTitle: _('Tirith 安全扫描', 'Tirith security scanning', 'Tirith 安全掃描'),
hermesSecurityConfigDesc: _('控制终端命令执行前的 Tirith 内容扫描,拦截明显的 URL 伪装、管道执行和注入风险。', 'Control Tirith content scanning before terminal commands run to catch obvious URL spoofing, pipe-to-shell, and injection risks.', '控制終端命令執行前的 Tirith 內容掃描,攔截明顯的 URL 偽裝、管道執行和注入風險。'),
hermesSecurityConfigStatusReady: _('结构化配置', 'structured settings', '結構化設定'),

View File

@@ -437,6 +437,8 @@ test('Hermes 配置页会暴露 Kanban 调度稳定性结构化配置字段', ()
'hm-kanban-auto-decompose-per-tick',
'hm-kanban-worker-log-rotate-bytes',
'hm-kanban-worker-log-backup-count',
'hm-kanban-orchestrator-profile',
'hm-kanban-default-assignee',
'hm-kanban-dispatch-stale-timeout-seconds',
]) {
assert.match(source, new RegExp(`id="${id}"`), `缺少 ${id}`)

View File

@@ -19,6 +19,8 @@ test('Hermes Kanban 配置读取会提供上游默认值', () => {
autoDecomposePerTick: 3,
workerLogRotateBytes: 2097152,
workerLogBackupCount: 1,
orchestratorProfile: '',
defaultAssignee: '',
dispatchStaleTimeoutSeconds: 14400,
})
})
@@ -35,6 +37,8 @@ test('Hermes Kanban 配置读取会规范化已有字段', () => {
auto_decompose_per_tick: '7',
worker_log_rotate_bytes: '4194304',
worker_log_backup_count: '3',
orchestrator_profile: 'triage',
default_assignee: 'builder',
dispatch_stale_timeout_seconds: '7200',
},
})
@@ -48,6 +52,8 @@ test('Hermes Kanban 配置读取会规范化已有字段', () => {
assert.equal(values.autoDecomposePerTick, 7)
assert.equal(values.workerLogRotateBytes, 4194304)
assert.equal(values.workerLogBackupCount, 3)
assert.equal(values.orchestratorProfile, 'triage')
assert.equal(values.defaultAssignee, 'builder')
assert.equal(values.dispatchStaleTimeoutSeconds, 7200)
})
@@ -71,6 +77,8 @@ test('Hermes Kanban 配置保存会保留未知 YAML 并写入 kanban', () => {
autoDecomposePerTick: '2',
workerLogRotateBytes: '1048576',
workerLogBackupCount: '0',
orchestratorProfile: 'triage',
defaultAssignee: 'builder',
dispatchStaleTimeoutSeconds: '0',
})
@@ -86,9 +94,28 @@ test('Hermes Kanban 配置保存会保留未知 YAML 并写入 kanban', () => {
assert.equal(next.kanban.auto_decompose_per_tick, 2)
assert.equal(next.kanban.worker_log_rotate_bytes, 1048576)
assert.equal(next.kanban.worker_log_backup_count, 0)
assert.equal(next.kanban.orchestrator_profile, 'triage')
assert.equal(next.kanban.default_assignee, 'builder')
assert.equal(next.kanban.dispatch_stale_timeout_seconds, 0)
})
test('Hermes Kanban profile 路由保存为空会移除可选字段', () => {
const next = mergeHermesKanbanConfig({
kanban: {
orchestrator_profile: 'triage',
default_assignee: 'builder',
custom_flag: 'keep-me',
},
}, {
orchestratorProfile: ' ',
defaultAssignee: '',
})
assert.equal(next.kanban.custom_flag, 'keep-me')
assert.equal(Object.hasOwn(next.kanban, 'orchestrator_profile'), false)
assert.equal(Object.hasOwn(next.kanban, 'default_assignee'), false)
})
test('Hermes Kanban 并发上限保存为 0 会移除可选限制字段', () => {
const next = mergeHermesKanbanConfig({
kanban: {
@@ -135,6 +162,14 @@ test('Hermes Kanban 配置保存会拒绝非法调度参数', () => {
() => mergeHermesKanbanConfig({}, { workerLogBackupCount: '-1' }),
/kanban\.worker_log_backup_count/,
)
assert.throws(
() => mergeHermesKanbanConfig({}, { orchestratorProfile: 123 }),
/kanban\.orchestrator_profile/,
)
assert.throws(
() => mergeHermesKanbanConfig({}, { defaultAssignee: false }),
/kanban\.default_assignee/,
)
assert.throws(
() => mergeHermesKanbanConfig({}, { dispatchStaleTimeoutSeconds: '-1' }),
/kanban\.dispatch_stale_timeout_seconds/,