feat(hermes): add execution limits config form

This commit is contained in:
晴天
2026-05-24 19:28:30 +08:00
parent c0b40070c0
commit 122d7a63be
10 changed files with 834 additions and 9 deletions

View File

@@ -51,8 +51,22 @@ const STREAMING_DEFAULTS = {
freshFinalAfterSeconds: 60,
}
const EXECUTION_LIMITS_DEFAULTS = {
codeExecutionMode: 'project',
codeExecutionTimeout: 300,
codeExecutionMaxToolCalls: 50,
delegationMaxIterations: 50,
delegationChildTimeoutSeconds: 600,
delegationMaxConcurrentChildren: 3,
delegationMaxSpawnDepth: 1,
delegationOrchestratorEnabled: true,
delegationSubagentAutoApprove: false,
delegationInheritMcpToolsets: true,
}
const SESSION_RESET_MODES = ['both', 'idle', 'daily', 'none']
const STREAMING_TRANSPORTS = ['edit', 'auto', 'draft', 'off']
const CODE_EXECUTION_MODES = ['project', 'strict']
export function render() {
const el = document.createElement('div')
@@ -64,24 +78,28 @@ export function render() {
let toolGuardrailsValues = { ...TOOL_GUARDRAILS_DEFAULTS }
let memoryValues = { ...MEMORY_DEFAULTS }
let streamingValues = { ...STREAMING_DEFAULTS }
let executionLimitsValues = { ...EXECUTION_LIMITS_DEFAULTS }
let loading = true
let runtimeLoading = true
let compressionLoading = true
let toolGuardrailsLoading = true
let memoryLoading = true
let streamingLoading = true
let executionLimitsLoading = true
let saving = false
let runtimeSaving = false
let compressionSaving = false
let toolGuardrailsSaving = false
let memorySaving = false
let streamingSaving = false
let executionLimitsSaving = false
let error = null
let runtimeError = null
let compressionError = null
let toolGuardrailsError = null
let memoryError = null
let streamingError = null
let executionLimitsError = null
function esc(value) {
return String(value ?? '')
@@ -92,7 +110,7 @@ export function render() {
}
function isBusy() {
return loading || runtimeLoading || compressionLoading || toolGuardrailsLoading || memoryLoading || streamingLoading || saving || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving || streamingSaving
return loading || runtimeLoading || compressionLoading || toolGuardrailsLoading || memoryLoading || streamingLoading || executionLimitsLoading || saving || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving || streamingSaving || executionLimitsSaving
}
function option(labelKey, value, selected) {
@@ -109,7 +127,7 @@ export function render() {
}
function renderRuntimePanel() {
const disabled = loading || saving || runtimeLoading || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving || streamingSaving
const disabled = loading || saving || runtimeLoading || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving || streamingSaving || executionLimitsSaving
return `
<div class="hm-panel hm-config-runtime-panel">
<div class="hm-panel-header">
@@ -157,7 +175,7 @@ export function render() {
}
function renderCompressionPanel() {
const disabled = loading || saving || compressionLoading || compressionSaving || runtimeSaving || toolGuardrailsSaving || memorySaving || streamingSaving
const disabled = loading || saving || compressionLoading || compressionSaving || runtimeSaving || toolGuardrailsSaving || memorySaving || streamingSaving || executionLimitsSaving
return `
<div class="hm-panel hm-config-runtime-panel hm-config-compression-panel">
<div class="hm-panel-header">
@@ -207,7 +225,7 @@ export function render() {
}
function renderToolGuardrailsPanel() {
const disabled = loading || saving || toolGuardrailsLoading || toolGuardrailsSaving || runtimeSaving || compressionSaving || memorySaving || streamingSaving
const disabled = loading || saving || toolGuardrailsLoading || toolGuardrailsSaving || runtimeSaving || compressionSaving || memorySaving || streamingSaving || executionLimitsSaving
return `
<div class="hm-panel hm-config-runtime-panel hm-config-guardrails-panel">
<div class="hm-panel-header">
@@ -269,7 +287,7 @@ export function render() {
}
function renderMemoryPanel() {
const disabled = loading || saving || memoryLoading || memorySaving || runtimeSaving || compressionSaving || toolGuardrailsSaving || streamingSaving
const disabled = loading || saving || memoryLoading || memorySaving || runtimeSaving || compressionSaving || toolGuardrailsSaving || streamingSaving || executionLimitsSaving
return `
<div class="hm-panel hm-config-runtime-panel hm-config-memory-panel">
<div class="hm-panel-header">
@@ -315,7 +333,7 @@ export function render() {
}
function renderStreamingPanel() {
const disabled = loading || saving || streamingLoading || streamingSaving || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving
const disabled = loading || saving || streamingLoading || streamingSaving || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving || executionLimitsSaving
return `
<div class="hm-panel hm-config-runtime-panel hm-config-streaming-panel">
<div class="hm-panel-header">
@@ -366,6 +384,78 @@ export function render() {
`
}
function renderExecutionLimitsPanel() {
const disabled = loading || saving || executionLimitsLoading || executionLimitsSaving || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving || streamingSaving
return `
<div class="hm-panel hm-config-runtime-panel hm-config-execution-limits-panel">
<div class="hm-panel-header">
<div>
<div class="hm-panel-title">${t('engine.hermesExecutionLimitsTitle')}</div>
<div class="hm-channel-panel-desc">${t('engine.hermesExecutionLimitsDesc')}</div>
</div>
<div class="hm-panel-actions">
<span class="hm-muted">${executionLimitsSaving ? t('engine.hermesConfigStatusSaving') : executionLimitsLoading ? t('engine.hermesConfigStatusLoading') : t('engine.hermesExecutionLimitsStatusReady')}</span>
<button class="hm-btn hm-btn--cta hm-btn--sm" id="hm-execution-limits-save" ${disabled ? 'disabled' : ''}>${t('engine.hermesExecutionLimitsSave')}</button>
</div>
</div>
<div class="hm-panel-body">
${renderError(executionLimitsError)}
<div class="hm-config-subtitle">${t('engine.hermesExecutionLimitsCodeTitle')}</div>
<div class="hm-config-runtime-grid hm-config-execution-grid">
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesExecutionLimitsCodeMode')}</span>
<select id="hm-code-execution-mode" class="hm-input" ${disabled ? 'disabled' : ''}>
${CODE_EXECUTION_MODES.map(mode => option(`engine.hermesExecutionLimitsCodeMode_${mode}`, mode, executionLimitsValues.codeExecutionMode)).join('')}
</select>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesExecutionLimitsCodeTimeout')}</span>
<input id="hm-code-execution-timeout" class="hm-input" type="number" inputmode="numeric" min="1" max="86400" step="1" value="${esc(executionLimitsValues.codeExecutionTimeout)}" ${disabled ? 'disabled' : ''}>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesExecutionLimitsCodeMaxToolCalls')}</span>
<input id="hm-code-execution-max-tool-calls" class="hm-input" type="number" inputmode="numeric" min="1" max="10000" step="1" value="${esc(executionLimitsValues.codeExecutionMaxToolCalls)}" ${disabled ? 'disabled' : ''}>
</label>
</div>
<div class="hm-config-subtitle">${t('engine.hermesExecutionLimitsDelegationTitle')}</div>
<div class="hm-config-runtime-grid hm-config-delegation-grid">
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesExecutionLimitsDelegationMaxIterations')}</span>
<input id="hm-delegation-max-iterations" class="hm-input" type="number" inputmode="numeric" min="1" max="1000" step="1" value="${esc(executionLimitsValues.delegationMaxIterations)}" ${disabled ? 'disabled' : ''}>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesExecutionLimitsDelegationChildTimeout')}</span>
<input id="hm-delegation-child-timeout-seconds" class="hm-input" type="number" inputmode="numeric" min="30" max="86400" step="1" value="${esc(executionLimitsValues.delegationChildTimeoutSeconds)}" ${disabled ? 'disabled' : ''}>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesExecutionLimitsDelegationMaxConcurrent')}</span>
<input id="hm-delegation-max-concurrent-children" class="hm-input" type="number" inputmode="numeric" min="1" max="100" step="1" value="${esc(executionLimitsValues.delegationMaxConcurrentChildren)}" ${disabled ? 'disabled' : ''}>
</label>
<label class="hm-field">
<span class="hm-field-label">${t('engine.hermesExecutionLimitsDelegationMaxSpawnDepth')}</span>
<input id="hm-delegation-max-spawn-depth" class="hm-input" type="number" inputmode="numeric" min="1" max="3" step="1" value="${esc(executionLimitsValues.delegationMaxSpawnDepth)}" ${disabled ? 'disabled' : ''}>
</label>
</div>
<div class="hm-config-check-grid">
<label class="hm-channel-check">
<input id="hm-delegation-orchestrator-enabled" type="checkbox" ${executionLimitsValues.delegationOrchestratorEnabled ? 'checked' : ''} ${disabled ? 'disabled' : ''}>
<span>${t('engine.hermesExecutionLimitsDelegationOrchestratorEnabled')}</span>
</label>
<label class="hm-channel-check">
<input id="hm-delegation-inherit-mcp-toolsets" type="checkbox" ${executionLimitsValues.delegationInheritMcpToolsets ? 'checked' : ''} ${disabled ? 'disabled' : ''}>
<span>${t('engine.hermesExecutionLimitsDelegationInheritMcp')}</span>
</label>
<label class="hm-channel-check hm-channel-check--danger">
<input id="hm-delegation-subagent-auto-approve" type="checkbox" ${executionLimitsValues.delegationSubagentAutoApprove ? 'checked' : ''} ${disabled ? 'disabled' : ''}>
<span>${t('engine.hermesExecutionLimitsDelegationAutoApprove')}</span>
</label>
</div>
<div class="hm-channel-footnote">${t('engine.hermesExecutionLimitsFootnote')}</div>
</div>
</div>
`
}
function draw() {
el.innerHTML = `
<div class="hm-hero">
@@ -382,6 +472,7 @@ export function render() {
${renderRuntimePanel()}
${renderStreamingPanel()}
${renderExecutionLimitsPanel()}
${renderCompressionPanel()}
${renderToolGuardrailsPanel()}
${renderMemoryPanel()}
@@ -409,6 +500,7 @@ export function render() {
el.querySelector('#hm-tool-guardrails-save')?.addEventListener('click', saveToolGuardrails)
el.querySelector('#hm-memory-save')?.addEventListener('click', saveMemory)
el.querySelector('#hm-streaming-save')?.addEventListener('click', saveStreaming)
el.querySelector('#hm-execution-limits-save')?.addEventListener('click', saveExecutionLimits)
}
async function loadRaw() {
@@ -441,6 +533,11 @@ export function render() {
streamingValues = { ...STREAMING_DEFAULTS, ...(data?.values || {}) }
}
async function loadExecutionLimits() {
const data = await api.hermesExecutionLimitsConfigRead()
executionLimitsValues = { ...EXECUTION_LIMITS_DEFAULTS, ...(data?.values || {}) }
}
async function load() {
loading = true
runtimeLoading = true
@@ -448,12 +545,14 @@ export function render() {
toolGuardrailsLoading = true
memoryLoading = true
streamingLoading = true
executionLimitsLoading = true
error = null
runtimeError = null
compressionError = null
toolGuardrailsError = null
memoryError = null
streamingError = null
executionLimitsError = null
draw()
try {
await loadRaw()
@@ -494,6 +593,14 @@ export function render() {
streamingLoading = false
draw()
}
try {
await loadExecutionLimits()
} catch (err) {
executionLimitsError = humanizeError(err, t('engine.hermesExecutionLimitsLoadFailed') || 'Load execution limit config failed')
} finally {
executionLimitsLoading = false
draw()
}
try {
await loadMemory()
} catch (err) {
@@ -538,6 +645,9 @@ export function render() {
try {
await loadStreaming()
} catch {}
try {
await loadExecutionLimits()
} catch {}
} catch (err) {
error = humanizeError(err, t('engine.hermesConfigSaveFailed') || 'Save failed')
toast(error, 'error')
@@ -697,6 +807,40 @@ export function render() {
}
}
async function saveExecutionLimits() {
const form = {
codeExecutionMode: el.querySelector('#hm-code-execution-mode')?.value || 'project',
codeExecutionTimeout: el.querySelector('#hm-code-execution-timeout')?.value || '300',
codeExecutionMaxToolCalls: el.querySelector('#hm-code-execution-max-tool-calls')?.value || '50',
delegationMaxIterations: el.querySelector('#hm-delegation-max-iterations')?.value || '50',
delegationChildTimeoutSeconds: el.querySelector('#hm-delegation-child-timeout-seconds')?.value || '600',
delegationMaxConcurrentChildren: el.querySelector('#hm-delegation-max-concurrent-children')?.value || '3',
delegationMaxSpawnDepth: el.querySelector('#hm-delegation-max-spawn-depth')?.value || '1',
delegationOrchestratorEnabled: !!el.querySelector('#hm-delegation-orchestrator-enabled')?.checked,
delegationSubagentAutoApprove: !!el.querySelector('#hm-delegation-subagent-auto-approve')?.checked,
delegationInheritMcpToolsets: !!el.querySelector('#hm-delegation-inherit-mcp-toolsets')?.checked,
}
executionLimitsSaving = true
executionLimitsError = null
draw()
try {
const result = await api.hermesExecutionLimitsConfigSave(form)
executionLimitsValues = { ...EXECUTION_LIMITS_DEFAULTS, ...(result?.values || form) }
await refreshRawAfterStructuredSave()
const backup = result?.backup || ''
toast({
message: t('engine.hermesExecutionLimitsSaveSuccess'),
hint: backup ? t('engine.hermesConfigBackupHint', { path: backup }) : '',
}, 'success')
} catch (err) {
executionLimitsError = humanizeError(err, t('engine.hermesExecutionLimitsSaveFailed') || 'Save execution limit config failed')
toast(executionLimitsError, 'error')
} finally {
executionLimitsSaving = false
draw()
}
}
draw()
load()
return el

View File

@@ -6769,6 +6769,14 @@ body[data-active-engine="hermes"][data-theme="dark"] {
grid-template-columns: repeat(5, minmax(140px, 1fr));
margin-top: 18px;
}
[data-engine="hermes"] .hm-config-execution-grid {
grid-template-columns: minmax(180px, 1.2fr) repeat(2, minmax(150px, 1fr));
margin-top: 12px;
}
[data-engine="hermes"] .hm-config-delegation-grid {
grid-template-columns: repeat(4, minmax(150px, 1fr));
margin-top: 12px;
}
[data-engine="hermes"] .hm-config-subtitle {
margin-top: 20px;
color: var(--hm-text-secondary);
@@ -6834,6 +6842,9 @@ body[data-active-engine="hermes"][data-theme="dark"] {
accent-color: var(--hm-accent);
flex: 0 0 auto;
}
[data-engine="hermes"] .hm-channel-check--danger span {
color: var(--hm-warning, #a16207);
}
[data-engine="hermes"] .hm-channel-section {
display: grid;
gap: 16px;
@@ -6910,6 +6921,8 @@ body[data-active-engine="hermes"][data-theme="dark"] {
[data-engine="hermes"] .hm-config-guardrails-grid,
[data-engine="hermes"] .hm-config-memory-grid,
[data-engine="hermes"] .hm-config-streaming-grid,
[data-engine="hermes"] .hm-config-execution-grid,
[data-engine="hermes"] .hm-config-delegation-grid,
[data-engine="hermes"] .hm-config-check-grid {
grid-template-columns: 1fr;
}

View File

@@ -519,6 +519,8 @@ export const api = {
hermesMemoryConfigSave: (form) => invoke('hermes_memory_config_save', { form }),
hermesStreamingConfigRead: () => invoke('hermes_streaming_config_read'),
hermesStreamingConfigSave: (form) => invoke('hermes_streaming_config_save', { form }),
hermesExecutionLimitsConfigRead: () => invoke('hermes_execution_limits_config_read'),
hermesExecutionLimitsConfigSave: (form) => invoke('hermes_execution_limits_config_save', { form }),
hermesLazyDepsFeatures: () => cachedInvoke('hermes_lazy_deps_features', {}, 600000),
hermesLazyDepsStatus: (features) => invoke('hermes_lazy_deps_status', { features }),
hermesLazyDepsEnsure: (feature) => invoke('hermes_lazy_deps_ensure', { feature }),

View File

@@ -516,6 +516,28 @@ export default {
hermesStreamingConfigFreshFinalAfterSeconds: _('长回复完成新消息时间(秒)', 'Fresh final message after (s)', '長回覆完成新訊息時間(秒)'),
hermesStreamingConfigCursor: _('生成中标记', 'In-progress marker', '生成中標記'),
hermesStreamingConfigFootnote: _('这里写入顶层 streaming 配置;旧版 gateway.streaming、display.streaming 和其他高级字段会保留在 raw YAML 中。将“长回复完成新消息时间”设为 0 可关闭完成后新消息。', 'This writes the top-level streaming settings. Legacy gateway.streaming, display.streaming, and other advanced fields are preserved in raw YAML. Set fresh final message time to 0 to disable the final follow-up message.', '這裡寫入頂層 streaming 設定;舊版 gateway.streaming、display.streaming 和其他進階欄位會保留在 raw YAML 中。將「長回覆完成新訊息時間」設為 0 可關閉完成後新訊息。'),
hermesExecutionLimitsTitle: _('执行与委派限制', 'Execution and delegation limits', '執行與委派限制'),
hermesExecutionLimitsDesc: _('控制 execute_code 沙箱和 delegate_task 子 Agent 的超时、并发、深度与自动批准策略,降低长跑任务失控和成本放大的风险。', 'Control execute_code sandbox and delegate_task child-agent timeouts, concurrency, depth, and auto-approval policy to reduce runaway long-run tasks and cost amplification.', '控制 execute_code 沙箱和 delegate_task 子 Agent 的逾時、並發、深度與自動批准策略,降低長跑任務失控和成本放大的風險。'),
hermesExecutionLimitsStatusReady: _('结构化配置', 'structured settings', '結構化設定'),
hermesExecutionLimitsSave: _('保存执行限制', 'Save execution limits', '儲存執行限制'),
hermesExecutionLimitsSaveSuccess: _('执行与委派限制已保存,建议重启 Hermes Gateway 生效', 'Execution and delegation limits saved. Restart Hermes Gateway to take effect.', '執行與委派限制已儲存,建議重啟 Hermes Gateway 生效'),
hermesExecutionLimitsLoadFailed: _('加载执行与委派限制失败', 'Load execution and delegation limits failed', '載入執行與委派限制失敗'),
hermesExecutionLimitsSaveFailed: _('保存执行与委派限制失败', 'Save execution and delegation limits failed', '儲存執行與委派限制失敗'),
hermesExecutionLimitsCodeTitle: _('代码执行沙箱', 'Code execution sandbox', '程式碼執行沙箱'),
hermesExecutionLimitsCodeMode: _('执行模式', 'Execution mode', '執行模式'),
hermesExecutionLimitsCodeMode_project: _('项目环境', 'Project environment', '專案環境'),
hermesExecutionLimitsCodeMode_strict: _('严格隔离', 'Strict isolation', '嚴格隔離'),
hermesExecutionLimitsCodeTimeout: _('脚本超时(秒)', 'Script timeout (s)', '腳本逾時(秒)'),
hermesExecutionLimitsCodeMaxToolCalls: _('最大工具调用数', 'Max tool calls', '最大工具呼叫數'),
hermesExecutionLimitsDelegationTitle: _('子 Agent 委派', 'Child-agent delegation', '子 Agent 委派'),
hermesExecutionLimitsDelegationMaxIterations: _('每个子任务最大轮数', 'Max turns per child', '每個子任務最大輪數'),
hermesExecutionLimitsDelegationChildTimeout: _('每个子任务超时(秒)', 'Child timeout (s)', '每個子任務逾時(秒)'),
hermesExecutionLimitsDelegationMaxConcurrent: _('最大并发子任务', 'Max concurrent children', '最大並發子任務'),
hermesExecutionLimitsDelegationMaxSpawnDepth: _('委派深度上限', 'Spawn depth limit', '委派深度上限'),
hermesExecutionLimitsDelegationOrchestratorEnabled: _('允许中间协调 Agent', 'Allow orchestrator children', '允許中間協調 Agent'),
hermesExecutionLimitsDelegationInheritMcp: _('保留父任务 MCP 工具集', 'Inherit parent MCP toolsets', '保留父任務 MCP 工具集'),
hermesExecutionLimitsDelegationAutoApprove: _('自动批准子任务危险命令', 'Auto-approve child dangerous commands', '自動批准子任務危險命令'),
hermesExecutionLimitsFootnote: _('默认会拒绝子任务危险命令审批,适合交互式和长跑任务。只有在完全信任无人值守环境时才开启自动批准。', 'By default, dangerous-command approvals from child agents are auto-denied, which fits interactive and long-running tasks. Enable auto-approval only in fully trusted unattended environments.', '預設會拒絕子任務危險命令審批,適合互動式和長跑任務。只有在完全信任無人值守環境時才啟用自動批准。'),
hermesCompressionTitle: _('上下文压缩', 'Context compression', '上下文壓縮'),
hermesCompressionDesc: _('控制长对话何时触发压缩、压缩目标和保留范围,降低上下文过长导致的失败与费用浪费。', 'Control when long conversations are compressed, the target size, and protected message ranges to reduce failures and wasted cost from oversized context.', '控制長對話何時觸發壓縮、壓縮目標和保留範圍,降低上下文過長導致的失敗與費用浪費。'),
hermesCompressionStatusReady: _('结构化配置', 'structured settings', '結構化設定'),

View File

@@ -404,8 +404,8 @@ async function boot() {
banner.style.cssText = 'position:fixed;top:0;left:0;right:0;z-index:999;background:linear-gradient(135deg,#6366f1,#8b5cf6);color:#fff;padding:10px 20px;display:flex;align-items:center;justify-content:center;gap:12px;font-size:13px;font-weight:500;box-shadow:0 2px 8px rgba(0,0,0,0.15)'
banner.innerHTML = `
<span>${statusIcon('warn', 14)} ${t('common.defaultPasswordBanner')}</span>
<a href="#/security" style="color:#fff;background:rgba(255,255,255,0.2);padding:4px 14px;border-radius:6px;text-decoration:none;font-size:12px;font-weight:600" onclick="document.getElementById('pw-change-banner').remove();sessionStorage.removeItem('clawpanel_must_change_pw')">${t('common.goSecurity')}</a>
<button onclick="this.parentElement.remove()" style="background:none;border:none;color:rgba(255,255,255,0.7);cursor:pointer;font-size:16px;padding:0 4px;margin-left:4px">✕</button>
<a href="#/security" style="color:#fff;background:rgba(255,255,255,0.2);min-height:44px;padding:0 14px;border-radius:8px;text-decoration:none;font-size:12px;font-weight:600;display:inline-flex;align-items:center;justify-content:center" onclick="document.getElementById('pw-change-banner').remove();sessionStorage.removeItem('clawpanel_must_change_pw')">${t('common.goSecurity')}</a>
<button aria-label="${t('common.close')}" title="${t('common.close')}" onclick="this.parentElement.remove()" style="width:44px;height:44px;flex:0 0 44px;display:inline-flex;align-items:center;justify-content:center;background:none;border:none;border-radius:8px;color:rgba(255,255,255,0.7);cursor:pointer;font-size:16px;padding:0;margin-left:0">✕</button>
`
document.body.prepend(banner)
}