dsh-chief 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/README.en.md +281 -129
- package/README.md +286 -134
- package/api-routes.js +232 -2
- package/board-actions.js +1452 -2005
- package/board-handoff.js +709 -0
- package/board-schema.js +365 -7
- package/chief-approvals.js +6 -2
- package/chief-archives.js +1 -0
- package/chief-commands.js +1884 -3484
- package/chief-compaction.js +1 -0
- package/chief-executor.js +6 -1
- package/chief-models.js +112 -5
- package/chief-network.js +1098 -869
- package/chief-review.js +448 -51
- package/chief-state.js +1996 -2523
- package/chief-view.js +10 -4
- package/client.js +20318 -11591
- package/command-helpers.js +568 -0
- package/command-ops.js +1226 -0
- package/digest.js +29 -4
- package/idle-guard.js +233 -8
- package/index.js +6 -0
- package/locale/en.json +72 -1
- package/locale/zh.json +72 -1
- package/model-tools.js +46 -3
- package/network-harness.js +1047 -0
- package/package.json +13 -5
- package/runtime-hooks.js +316 -14
- package/safety/guard-walls.js +5 -0
- package/safety/invariant-guards.js +126 -6
- package/safety/tool-gate.js +2 -0
- package/state-media.js +173 -0
- package/state-schema.js +1505 -0
- package/subagent-runtime.js +85 -4
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-chief",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"icon": "icon.svg",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "Right-sidebar supervisor for DeepSeek Harness (DSH):
|
|
6
|
+
"description": "Right-sidebar supervisor plugin for DeepSeek Harness (DSH): saves findings before compaction, monitors subagent workflows, checks file edits and shell commands against guard rules, stops repeat-error loops, and hands off long sessions.",
|
|
7
7
|
"author": "gluztm",
|
|
8
8
|
"license": "AGPL-3.0-only",
|
|
9
9
|
"repository": {
|
|
@@ -55,7 +55,9 @@
|
|
|
55
55
|
"thinking-effort",
|
|
56
56
|
"dream-roam",
|
|
57
57
|
"认知桌面",
|
|
58
|
-
"物理驻墙"
|
|
58
|
+
"物理驻墙",
|
|
59
|
+
"workflow-topology",
|
|
60
|
+
"bilingual"
|
|
59
61
|
],
|
|
60
62
|
"engines": {
|
|
61
63
|
"node": ">=22.13.0",
|
|
@@ -66,8 +68,8 @@
|
|
|
66
68
|
"build:client": "node ./scripts/build-client.mjs",
|
|
67
69
|
"check:client": "node ./scripts/build-client.mjs --check",
|
|
68
70
|
"check:syntax": "node -e \"const fs=require('fs'),path=require('path'),cp=require('child_process');const walk=d=>{for(const e of fs.readdirSync(d,{withFileTypes:true})){const p=path.join(d,e.name);if(e.isDirectory()&&(e.name==='safety'||e.name==='src'||e.name==='client'))walk(p);else if(e.isFile()&&e.name.endsWith('.js'))cp.execFileSync(process.execPath,['--check',p]);}};walk('.');\"",
|
|
69
|
-
"test:ci": "npm run check:client && npm run check:syntax && node ./tests/verify-v130-release-gate.mjs && node ./tests/verify-v140-safety-gate.mjs && node ./tests/verify-v140-collab-gate.mjs && node ./tests/verify-v150-final-gate.mjs",
|
|
70
|
-
"test": "node ./tests/verify-v130-release-gate.mjs && node ./tests/verify-v140-safety-gate.mjs && node ./tests/verify-v140-collab-gate.mjs && node ./tests/verify-v150-final-gate.mjs && node -e \"const fs=require('fs'),path=require('path'),cp=require('child_process');if(fs.existsSync('../tools')){for(const s of ['verify-chief-facade-split.mjs','verify-index-modular-split.mjs','verify-archives-modular-split.mjs','verify-client-modular-build.mjs','verify-v121-permissions-and-ui.mjs','verify-compaction-and-blank-chat.mjs','check-action-surface.mjs','verify-v130-four-chains.mjs']){cp.execFileSync(process.execPath,[path.resolve('..','tools',s)],{stdio:'inherit'});}}\""
|
|
71
|
+
"test:ci": "npm run check:client && npm run check:syntax && node ./tests/verify-v130-release-gate.mjs && node ./tests/verify-v140-safety-gate.mjs && node ./tests/verify-v140-collab-gate.mjs && node ./tests/verify-v150-final-gate.mjs && node ./tests/verify-v160-flow-gate.mjs",
|
|
72
|
+
"test": "node ./tests/verify-v130-release-gate.mjs && node ./tests/verify-v140-safety-gate.mjs && node ./tests/verify-v140-collab-gate.mjs && node ./tests/verify-v150-final-gate.mjs && node ./tests/verify-v160-flow-gate.mjs && node -e \"const fs=require('fs'),path=require('path'),cp=require('child_process');if(fs.existsSync('../tools')){for(const s of ['verify-chief-facade-split.mjs','verify-index-modular-split.mjs','verify-archives-modular-split.mjs','verify-client-modular-build.mjs','verify-v121-permissions-and-ui.mjs','verify-compaction-and-blank-chat.mjs','check-action-surface.mjs','verify-v130-four-chains.mjs']){cp.execFileSync(process.execPath,[path.resolve('..','tools',s)],{stdio:'inherit'});}}\""
|
|
71
73
|
},
|
|
72
74
|
"exports": {
|
|
73
75
|
".": "./index.js",
|
|
@@ -98,6 +100,12 @@
|
|
|
98
100
|
"chief-review.js",
|
|
99
101
|
"chief-approvals.js",
|
|
100
102
|
"chief-executor.js",
|
|
103
|
+
"board-handoff.js",
|
|
104
|
+
"network-harness.js",
|
|
105
|
+
"state-schema.js",
|
|
106
|
+
"state-media.js",
|
|
107
|
+
"command-helpers.js",
|
|
108
|
+
"command-ops.js",
|
|
101
109
|
"safety/*.js",
|
|
102
110
|
"auto-continue.js",
|
|
103
111
|
"archives.js",
|
package/runtime-hooks.js
CHANGED
|
@@ -10,8 +10,13 @@ import { renderDigest } from './digest.js'
|
|
|
10
10
|
import { appendMemory, captureTurn } from './memory.js'
|
|
11
11
|
import {
|
|
12
12
|
buildNotice,
|
|
13
|
+
buildMidTurnSpinNotice,
|
|
13
14
|
clearCallTrail,
|
|
15
|
+
clearMidTurnSpin,
|
|
16
|
+
detectMidTurnSpin,
|
|
14
17
|
isPlanWrite,
|
|
18
|
+
markMidTurnSpinActed,
|
|
19
|
+
noteCallResult,
|
|
15
20
|
noteCallTrail,
|
|
16
21
|
noteIntervention,
|
|
17
22
|
notePlanWrite,
|
|
@@ -36,11 +41,17 @@ import {
|
|
|
36
41
|
upsertTaskLedgerOnWs,
|
|
37
42
|
normalizeSuggestion,
|
|
38
43
|
ensureWorkspace,
|
|
44
|
+
recordWorkspaceAlertEvent,
|
|
45
|
+
isChiefSessionEnabled,
|
|
46
|
+
activateChiefSession,
|
|
39
47
|
SUGGESTIONS_CAP,
|
|
48
|
+
CHAT_CAP,
|
|
49
|
+
nextId,
|
|
50
|
+
clamp,
|
|
40
51
|
} from './chief-state.js'
|
|
41
52
|
import { createAutoContinueEngine } from './auto-continue.js'
|
|
42
53
|
import { bootstrapArchivesFromSharedBoard } from './archives.js'
|
|
43
|
-
import { normalizePermissionMode, evaluatePreExecuteDefense, evaluateSafetyGuardHardRules, listGuardWalls } from './chief-executor.js'
|
|
54
|
+
import { normalizePermissionMode, buildCapabilityScope, evaluatePreExecuteDefense, evaluateSafetyGuardHardRules, listGuardWalls } from './chief-executor.js'
|
|
44
55
|
import {
|
|
45
56
|
newId,
|
|
46
57
|
nowMs,
|
|
@@ -172,12 +183,34 @@ export function createRuntimeHooks(deps) {
|
|
|
172
183
|
pushLog,
|
|
173
184
|
})
|
|
174
185
|
|
|
186
|
+
const isExplicitStopped = (rootKey, sid) => {
|
|
187
|
+
try {
|
|
188
|
+
const st = loadChiefState()
|
|
189
|
+
const rk = resolveRootSessionId(rootKey || sid) || rootKey || sid
|
|
190
|
+
const cfg = resolveWorkspaceConfig(st, rk)
|
|
191
|
+
return Boolean(cfg.stopped || cfg.paceMode === 'stopped')
|
|
192
|
+
} catch {
|
|
193
|
+
return false
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
175
197
|
const isRootStopped = (rootKey, sid) => {
|
|
176
198
|
try {
|
|
177
199
|
const st = loadChiefState()
|
|
178
200
|
const rk = resolveRootSessionId(rootKey || sid) || rootKey || sid
|
|
179
201
|
const cfg = resolveWorkspaceConfig(st, rk)
|
|
180
|
-
return Boolean(cfg.stopped || cfg.paceMode === 'stopped' || cfg.runMode === 'off')
|
|
202
|
+
return Boolean(cfg.stopped || cfg.paceMode === 'stopped' || (cfg.runMode === 'off' && !(cfg.tacticalModes && cfg.tacticalModes.intervention)))
|
|
203
|
+
} catch {
|
|
204
|
+
return false
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const isSessionActive = (sid, agentObj = null) => {
|
|
209
|
+
try {
|
|
210
|
+
const raw = String(sid || (agentObj && agentObj.id) || '').trim()
|
|
211
|
+
const rk = resolveRootSessionId(raw, agentObj) || raw
|
|
212
|
+
if (!rk || rk === 'global') return false
|
|
213
|
+
return isChiefSessionEnabled(loadChiefState(), rk)
|
|
181
214
|
} catch {
|
|
182
215
|
return false
|
|
183
216
|
}
|
|
@@ -208,15 +241,17 @@ export function createRuntimeHooks(deps) {
|
|
|
208
241
|
const ws = state && state.workspaces && state.workspaces[key] ? state.workspaces[key] : null
|
|
209
242
|
const effCfg = resolveWorkspaceConfig(state, key)
|
|
210
243
|
const runMode = effCfg && effCfg.runMode ? effCfg.runMode : 'off'
|
|
211
|
-
|
|
212
|
-
|
|
244
|
+
const interventionOn = Boolean(effCfg && effCfg.tacticalModes && effCfg.tacticalModes.intervention)
|
|
245
|
+
if ((effCfg && effCfg.stopped) || (runMode !== 'patrol' && runMode !== 'managed' && !interventionOn)) {
|
|
246
|
+
return { allowed: false, skipped: 'run-mode-off', logMessage: '参谋处于「⏸ 关停」模式,仅 patrol/managed 或强介入激活时允许 Auto continue 唤醒' }
|
|
213
247
|
}
|
|
214
248
|
|
|
215
249
|
// Check forbidden bounds and active guard walls BEFORE continuing
|
|
216
250
|
const cwdForCheck = (key && key !== 'global' && getSessionCwd(runtime, key)) || process.cwd()
|
|
217
251
|
const board = key && key !== 'global' ? boardForSession(boardFileFor(key)) : null
|
|
218
252
|
const detailSample = `${trigger || ''} ${detail || ''}`.trim()
|
|
219
|
-
const
|
|
253
|
+
const safetyGuardEnabled = !(effCfg && effCfg.tacticalModes && effCfg.tacticalModes.safetyGuardEnabled === false)
|
|
254
|
+
const safetyGuard = evaluateSafetyGuardHardRules({ tool: 'relay', opClass: 'workflow', command: detailSample, board, safetyGuardEnabled })
|
|
220
255
|
if (safetyGuard && safetyGuard.blocked) {
|
|
221
256
|
appendChiefAuditLog(key, {
|
|
222
257
|
mode: effCfg.permissionMode || 'advisor',
|
|
@@ -337,6 +372,15 @@ export function createRuntimeHooks(deps) {
|
|
|
337
372
|
pushLog(board, `🔄 断线续跑:${msg}`, 'chief', sid)
|
|
338
373
|
saveBoard(board, file)
|
|
339
374
|
})
|
|
375
|
+
if (String(msg || '').includes('断线续跑已触发')) {
|
|
376
|
+
recordWorkspaceAlertEvent(rootId, {
|
|
377
|
+
kind: 'auto_continue_rescue',
|
|
378
|
+
level: 'info',
|
|
379
|
+
title: '🔄 断流救活已触发续跑',
|
|
380
|
+
body: String(msg).slice(0, 180),
|
|
381
|
+
dedupeKey: `rescue:${rootId}:${Math.floor(Date.now() / 5_000)}`,
|
|
382
|
+
})
|
|
383
|
+
}
|
|
340
384
|
} catch {}
|
|
341
385
|
},
|
|
342
386
|
})
|
|
@@ -362,6 +406,7 @@ export function createRuntimeHooks(deps) {
|
|
|
362
406
|
if (!decision || decision.kind === 'reject' || signal?.aborted || !Array.isArray(decision.messages)) {
|
|
363
407
|
return decision
|
|
364
408
|
}
|
|
409
|
+
if (!isSessionActive(agent && agent.id, agent)) return decision
|
|
365
410
|
const deltaMsg = await consumePreStepDelta(makeChiefDeps(runtime), agent)
|
|
366
411
|
if (!deltaMsg) return decision
|
|
367
412
|
return { ...decision, messages: [deltaMsg, ...decision.messages] }
|
|
@@ -389,6 +434,7 @@ export function createRuntimeHooks(deps) {
|
|
|
389
434
|
const liveAgent = (promptCtx && promptCtx.agent) || (spCtx && spCtx.agent) || null
|
|
390
435
|
const curId = liveAgent && liveAgent.id ? String(liveAgent.id) : fallbackAgentId
|
|
391
436
|
const rootId = resolveRootSessionId(curId, liveAgent) || curId
|
|
437
|
+
if (!isSessionActive(rootId, liveAgent)) return ''
|
|
392
438
|
let teamTasks
|
|
393
439
|
try {
|
|
394
440
|
const svc = runtime.get('agentTeams')
|
|
@@ -408,6 +454,7 @@ export function createRuntimeHooks(deps) {
|
|
|
408
454
|
subagents,
|
|
409
455
|
linkedPeersCount: linked.linkedPeersCount,
|
|
410
456
|
linkedPeersProgress: linked.linkedPeersProgress,
|
|
457
|
+
bubbleSquad: linked.bubbleSquad,
|
|
411
458
|
takenOutArchives: archCtx.takenOutArchives,
|
|
412
459
|
sessionHookedArchives: archCtx.sessionHookedArchives,
|
|
413
460
|
desktopUsedTokens: archCtx.desktopUsedTokens,
|
|
@@ -425,6 +472,7 @@ export function createRuntimeHooks(deps) {
|
|
|
425
472
|
const caller = exec.agent || null
|
|
426
473
|
const sessionId = caller && caller.id ? String(caller.id) : ''
|
|
427
474
|
const rootId = resolveRootSessionId(sessionId, caller) || sessionId
|
|
475
|
+
if (!isSessionActive(rootId, caller)) return
|
|
428
476
|
if (exec.name === 'todo_write') syncPlanFromTodos(exec.arguments, rootId)
|
|
429
477
|
else if (exec.name === 'create_goal' || exec.name === 'update_goal') syncObjective(exec.name, exec.arguments, rootId)
|
|
430
478
|
else if (exec.name === 'subagent' || exec.name === 'subagent_fork' || exec.name === 'send_message' || exec.name === 'interrupt_agent') {
|
|
@@ -443,6 +491,7 @@ export function createRuntimeHooks(deps) {
|
|
|
443
491
|
const pendingDeploy = readPendingDeploy()
|
|
444
492
|
if (pendingDeploy && pendingDeploy.fromSessionId && pendingDeploy.fromSessionId !== id) {
|
|
445
493
|
clearPendingDeploy()
|
|
494
|
+
activateChiefSession(id, { force: true })
|
|
446
495
|
try {
|
|
447
496
|
deployStateToTargetChief(runtime, {
|
|
448
497
|
fromSessionId: pendingDeploy.fromSessionId,
|
|
@@ -457,6 +506,7 @@ export function createRuntimeHooks(deps) {
|
|
|
457
506
|
|
|
458
507
|
const pending = readPending()
|
|
459
508
|
if (!pending) return
|
|
509
|
+
activateChiefSession(id, { force: true })
|
|
460
510
|
const delivered = await injectInto(agent, pending.text)
|
|
461
511
|
if (delivered.ok) clearPending()
|
|
462
512
|
const file = boardFileFor(id)
|
|
@@ -489,6 +539,128 @@ export function createRuntimeHooks(deps) {
|
|
|
489
539
|
} catch {}
|
|
490
540
|
}), 'dsh-chief: deliver pending transfer')
|
|
491
541
|
|
|
542
|
+
function handleMidTurnSpinCheck(id, rootId) {
|
|
543
|
+
try {
|
|
544
|
+
const agents = runtime && runtime.get ? runtime.get('agents') : null
|
|
545
|
+
const liveAgent = agents && typeof agents.get === 'function' ? agents.get(id) : null
|
|
546
|
+
if (!liveAgent || liveAgent.status !== 'running') return
|
|
547
|
+
|
|
548
|
+
const st = loadChiefState()
|
|
549
|
+
const effCfg = resolveWorkspaceConfig(st, rootId)
|
|
550
|
+
if (effCfg.stopped || effCfg.paceMode === 'stopped') return
|
|
551
|
+
|
|
552
|
+
const strongIntervention = Boolean(effCfg.tacticalModes && effCfg.tacticalModes.intervention)
|
|
553
|
+
const shared = loadBoard(boardFile())
|
|
554
|
+
const board = boardForSession(boardFileFor(id))
|
|
555
|
+
const settings = { ...(board.settings || {}), ...(shared.settings || {}) }
|
|
556
|
+
const guardIdleEnabled = settings.guardIdle !== false
|
|
557
|
+
if (!strongIntervention && !guardIdleEnabled) return
|
|
558
|
+
|
|
559
|
+
const spin = detectMidTurnSpin(id, { strongIntervention })
|
|
560
|
+
if (!spin) return
|
|
561
|
+
|
|
562
|
+
const canSteer = typeof liveAgent.steer === 'function'
|
|
563
|
+
const logLine = guardLogText({ kind: 'mid-turn-spin', spin }, 0, 0)
|
|
564
|
+
const ident = resolveAgentIdentity(runtime, id, liveAgent)
|
|
565
|
+
const targetHandle = (ident && ident.isChild && ident.self) ? ident.self : 'lead'
|
|
566
|
+
|
|
567
|
+
if (spin.kind === 'exact-loop' && guardIdleEnabled) {
|
|
568
|
+
if (!canSteer) return
|
|
569
|
+
liveAgent.steer(buildMidTurnSpinNotice(spin, board))
|
|
570
|
+
markMidTurnSpinActed(id)
|
|
571
|
+
const bFile = boardFileFor(id)
|
|
572
|
+
withBoardLock(bFile, () => {
|
|
573
|
+
const b = loadBoard(bFile)
|
|
574
|
+
pushLog(b, logLine, 'guard', id)
|
|
575
|
+
saveBoard(b, bFile)
|
|
576
|
+
})
|
|
577
|
+
scheduleChiefTurnReview(makeChiefDeps(runtime), { agent: liveAgent, sessionId: id, abnormalTrigger: 'mid_turn_spin' })
|
|
578
|
+
return
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (!strongIntervention) return
|
|
582
|
+
const wsSnap = st.workspaces && st.workspaces[rootId] ? st.workspaces[rootId] : null
|
|
583
|
+
const permMode = normalizePermissionMode(effCfg.permissionMode, {
|
|
584
|
+
requireAck: true,
|
|
585
|
+
hasChiefRiskAck: hasValidChiefRiskAck(wsSnap),
|
|
586
|
+
})
|
|
587
|
+
const spinSummary = `${spin.name || 'tool'}${spin.preview ? ' (' + String(spin.preview).slice(0, 60) + ')' : ''}`
|
|
588
|
+
|
|
589
|
+
if (permMode === 'chief' && canSteer) {
|
|
590
|
+
liveAgent.steer(buildMidTurnSpinNotice(spin, board))
|
|
591
|
+
markMidTurnSpinActed(id)
|
|
592
|
+
mutateChiefState((s) => {
|
|
593
|
+
const ws = ensureWorkspace(s, rootId)
|
|
594
|
+
ws.chat.push({
|
|
595
|
+
id: nextId('chat'),
|
|
596
|
+
role: 'chief',
|
|
597
|
+
kind: 'receipt',
|
|
598
|
+
text: `- 【⚡ 强介入 · 运行中空转急刹】已当场插话制止 \`@${targetHandle}\` 原地空转/连续报错(${spin.kind} ×${spin.count}:${clamp(spinSummary, 140)})。`,
|
|
599
|
+
actions: [`⚡ 急刹 ×${spin.count}`],
|
|
600
|
+
at: Date.now(),
|
|
601
|
+
})
|
|
602
|
+
if (ws.chat.length > CHAT_CAP) ws.chat = ws.chat.slice(-CHAT_CAP)
|
|
603
|
+
})
|
|
604
|
+
appendChiefAuditLog(rootId, {
|
|
605
|
+
mode: permMode,
|
|
606
|
+
stage: 'executor',
|
|
607
|
+
rule: 'mid_turn_spin_brake',
|
|
608
|
+
decision: 'executed',
|
|
609
|
+
operation: '强介入运行中空转急刹',
|
|
610
|
+
target: id,
|
|
611
|
+
reason: `${spin.kind} ×${spin.count}: ${clamp(spinSummary, 120)}`,
|
|
612
|
+
outcome: 'ok',
|
|
613
|
+
by: 'chief',
|
|
614
|
+
})
|
|
615
|
+
} else if (permMode === 'strategist') {
|
|
616
|
+
markMidTurnSpinActed(id)
|
|
617
|
+
const noticeObj = buildMidTurnSpinNotice(spin, board)
|
|
618
|
+
const noticeTxt = (noticeObj.content && noticeObj.content[0] && noticeObj.content[0].text) || ''
|
|
619
|
+
queueChiefApproval(rootId, {
|
|
620
|
+
category: 'main_workflow',
|
|
621
|
+
operationLabel: '强介入 · 运行中空转急刹插话',
|
|
622
|
+
targetLabel: targetHandle === 'lead' ? '主对话 (@lead)' : `@${targetHandle}`,
|
|
623
|
+
reason: `检测到运行中连续空转/报错(${spin.kind} ×${spin.count}),L2 参谋模式需您授权后插话急刹`,
|
|
624
|
+
impact: '允许后立即向运行中的目标插入纠偏通知',
|
|
625
|
+
preview: clamp(spinSummary, 200),
|
|
626
|
+
dedupeKey: `midspin:${rootId}:${spin.kind}:${spin.name}`,
|
|
627
|
+
kind: 'relay',
|
|
628
|
+
capabilityScope: buildCapabilityScope({ kind: 'relay', tool: 'relay', target: targetHandle }),
|
|
629
|
+
payload: {
|
|
630
|
+
fromSession: rootId,
|
|
631
|
+
fromLabel: 'DSH 参谋 (运行中空转急刹)',
|
|
632
|
+
target: targetHandle,
|
|
633
|
+
subject: '运行中空转急刹',
|
|
634
|
+
text: noticeTxt,
|
|
635
|
+
mode: 'steer',
|
|
636
|
+
},
|
|
637
|
+
by: 'chief',
|
|
638
|
+
})
|
|
639
|
+
} else {
|
|
640
|
+
markMidTurnSpinActed(id)
|
|
641
|
+
mutateChiefState((s) => {
|
|
642
|
+
const ws = ensureWorkspace(s, rootId)
|
|
643
|
+
ws.chat.push({
|
|
644
|
+
id: nextId('chat'),
|
|
645
|
+
role: 'chief',
|
|
646
|
+
kind: 'receipt',
|
|
647
|
+
text: `- 【👁 运行中空转告警 (${permMode === 'assistant' ? 'L1' : 'L0'})】检测到 \`@${targetHandle}\` 正在连续空转/报错(${spin.kind} ×${spin.count}:${clamp(spinSummary, 140)}),当前权限不自动插话。`,
|
|
648
|
+
actions: ['⚠️ 运行空转告警'],
|
|
649
|
+
at: Date.now(),
|
|
650
|
+
})
|
|
651
|
+
if (ws.chat.length > CHAT_CAP) ws.chat = ws.chat.slice(-CHAT_CAP)
|
|
652
|
+
})
|
|
653
|
+
}
|
|
654
|
+
const bFile = boardFileFor(id)
|
|
655
|
+
withBoardLock(bFile, () => {
|
|
656
|
+
const b = loadBoard(bFile)
|
|
657
|
+
pushLog(b, logLine, 'guard', id)
|
|
658
|
+
saveBoard(b, bFile)
|
|
659
|
+
})
|
|
660
|
+
scheduleChiefTurnReview(makeChiefDeps(runtime), { agent: liveAgent, sessionId: id, abnormalTrigger: 'mid_turn_spin' })
|
|
661
|
+
} catch {}
|
|
662
|
+
}
|
|
663
|
+
|
|
492
664
|
// 2c) Incremental record of what each turn actually did + Auto-Continue detection
|
|
493
665
|
// on interruptions / transient failures / empty outputs (unless Chief is stopped).
|
|
494
666
|
ctx.effect(() => ctx.on('session/event', (session, event) => {
|
|
@@ -496,14 +668,21 @@ export function createRuntimeHooks(deps) {
|
|
|
496
668
|
if (!event || !session || !session.id) return
|
|
497
669
|
const id = String(session.id)
|
|
498
670
|
const rootIdForAct = resolveRootSessionId(id) || id
|
|
671
|
+
if (!isSessionActive(rootIdForAct)) return
|
|
499
672
|
if (event.type === 'turn/start' || event.type === 'message/user' || event.type === 'tool/call' || event.type === 'turn/end') {
|
|
500
673
|
touchWorkspaceActivity(rootIdForAct)
|
|
501
674
|
}
|
|
502
|
-
if (event.type === '
|
|
675
|
+
if (event.type === 'turn/start') {
|
|
676
|
+
clearMidTurnSpin(id)
|
|
677
|
+
} else if (event.type === 'tool/call' && event.data) {
|
|
503
678
|
const turn = event.data.turn
|
|
504
679
|
noteToolCall(id, turn)
|
|
505
680
|
if (isPlanWrite(event.data.name, event.data.arguments)) notePlanWrite(id, turn)
|
|
506
681
|
noteCallTrail(id, event.data.name, event.data.arguments)
|
|
682
|
+
handleMidTurnSpinCheck(id, rootIdForAct)
|
|
683
|
+
} else if (event.type === 'tool/result' && event.data) {
|
|
684
|
+
noteCallResult(id, event.data)
|
|
685
|
+
handleMidTurnSpinCheck(id, rootIdForAct)
|
|
507
686
|
}
|
|
508
687
|
autoContinue.onSessionEvent(session, event)
|
|
509
688
|
|
|
@@ -519,8 +698,11 @@ export function createRuntimeHooks(deps) {
|
|
|
519
698
|
const steerKey = `${id}:${turnNum}`
|
|
520
699
|
const steeredAt = deps.hostState.autoSteeredTurns.get(steerKey) || 0
|
|
521
700
|
if (steeredAt) deps.hostState.autoSteeredTurns.delete(steerKey)
|
|
522
|
-
|
|
523
|
-
|
|
701
|
+
const stNow = loadChiefState()
|
|
702
|
+
const rootId = resolveRootSessionId(id) || id
|
|
703
|
+
const cfgNow = resolveWorkspaceConfig(stNow, rootId)
|
|
704
|
+
const strongIntervention = Boolean(cfgNow.tacticalModes && cfgNow.tacticalModes.intervention)
|
|
705
|
+
if (!isStoppedByUserOrPolicy && (strongIntervention || !(steeredAt && Date.now() - steeredAt < 30_000))) {
|
|
524
706
|
if (!isRootStopped(rootId, id) || abnormalTrig) {
|
|
525
707
|
const agents = runtime && runtime.get ? runtime.get('agents') : null
|
|
526
708
|
const liveAgent = agents && typeof agents.get === 'function' ? agents.get(id) : null
|
|
@@ -547,6 +729,8 @@ export function createRuntimeHooks(deps) {
|
|
|
547
729
|
const agent = payload && payload.agent
|
|
548
730
|
id = agent && agent.id ? String(agent.id) : ''
|
|
549
731
|
if (!id) return
|
|
732
|
+
const turnRootId = resolveRootSessionId(id, agent) || id
|
|
733
|
+
if (!isSessionActive(turnRootId, agent)) return
|
|
550
734
|
|
|
551
735
|
const turn = Number(payload && payload.turn)
|
|
552
736
|
const file = boardFileFor(id)
|
|
@@ -607,7 +791,12 @@ export function createRuntimeHooks(deps) {
|
|
|
607
791
|
}
|
|
608
792
|
task.updatedAt = nowMs()
|
|
609
793
|
settledCount += 1
|
|
610
|
-
|
|
794
|
+
const returnStepId = task.targetPlanStepId || task.planStepId
|
|
795
|
+
const returnStepIdx = returnStepId && Array.isArray(board.plan)
|
|
796
|
+
? board.plan.findIndex(s => s && s.id === returnStepId)
|
|
797
|
+
: -1
|
|
798
|
+
const returnTag = returnStepIdx >= 0 ? '(已回指步骤 ' + (returnStepIdx + 1) + ')' : ''
|
|
799
|
+
pushLog(board, '✅ 子代理 ' + identity.self + ' 完成任务 #' + task.id + '「' + task.title.slice(0, 36) + '」' + returnTag, identity.self, id)
|
|
611
800
|
}
|
|
612
801
|
}
|
|
613
802
|
if (settledCount > 0) {
|
|
@@ -622,7 +811,7 @@ export function createRuntimeHooks(deps) {
|
|
|
622
811
|
}
|
|
623
812
|
|
|
624
813
|
const rootId = resolveRootSessionId(id, agent) || id
|
|
625
|
-
if (
|
|
814
|
+
if (isExplicitStopped(rootId, id)) {
|
|
626
815
|
saveBoard(board, file)
|
|
627
816
|
return
|
|
628
817
|
}
|
|
@@ -631,7 +820,18 @@ export function createRuntimeHooks(deps) {
|
|
|
631
820
|
// same rule so one switch turns the guard off everywhere.
|
|
632
821
|
const shared = loadBoard(boardFile())
|
|
633
822
|
const settings = { ...(board.settings || {}), ...(shared.settings || {}) }
|
|
634
|
-
const
|
|
823
|
+
const effCfg = resolveWorkspaceConfig(loadChiefState(), rootId)
|
|
824
|
+
const strongIntervention = Boolean(effCfg.tacticalModes && effCfg.tacticalModes.intervention)
|
|
825
|
+
const maxInterventionTurns = Number(effCfg.tacticalModes && effCfg.tacticalModes.maxInterventionTurns) || 0
|
|
826
|
+
const verdict = shouldGuard({
|
|
827
|
+
board,
|
|
828
|
+
session: agent && agent.session,
|
|
829
|
+
sessionId: id,
|
|
830
|
+
turn,
|
|
831
|
+
settings,
|
|
832
|
+
strongIntervention,
|
|
833
|
+
maxInterventionTurns,
|
|
834
|
+
})
|
|
635
835
|
if (!verdict) {
|
|
636
836
|
saveBoard(board, file)
|
|
637
837
|
scheduleChiefTurnReview(makeChiefDeps(runtime), { agent, sessionId: id, turn })
|
|
@@ -658,7 +858,8 @@ export function createRuntimeHooks(deps) {
|
|
|
658
858
|
// Clear the trail only once the steer landed: a loop that survived a
|
|
659
859
|
// failed steer deserves the next nudge, not a silent reset.
|
|
660
860
|
if (verdict.kind === 'loop') clearCallTrail(id)
|
|
661
|
-
|
|
861
|
+
const remAfter = remainingInterventions(id, settings, { strongIntervention, maxInterventionTurns })
|
|
862
|
+
pushLog(board, guardLogText(verdict, turn, remAfter), 'guard', id)
|
|
662
863
|
|
|
663
864
|
// Auto-handoff: when the guard has spent its last intervention and the
|
|
664
865
|
// session still has open work, the turn is not idle — it is stuck in a
|
|
@@ -666,7 +867,7 @@ export function createRuntimeHooks(deps) {
|
|
|
666
867
|
// handover packet right now so the next Session (or a manual reopen)
|
|
667
868
|
// inherits it instead of a blank board. The steer already fired above
|
|
668
869
|
// tells the model to wrap up; this packet is what the next one reads.
|
|
669
|
-
if (
|
|
870
|
+
if (remAfter === 0) {
|
|
670
871
|
try {
|
|
671
872
|
const packet = resolveEffectiveHandoff(runtime, id, board).text
|
|
672
873
|
const pendingFile_ = pendingFile()
|
|
@@ -714,6 +915,10 @@ export function createRuntimeHooks(deps) {
|
|
|
714
915
|
const caller = exec.agent || null
|
|
715
916
|
const sid = caller && caller.id ? String(caller.id) : ''
|
|
716
917
|
const rootId = resolveRootSessionId(sid, caller) || sid || 'global'
|
|
918
|
+
if (!isSessionActive(rootId, caller)) return next()
|
|
919
|
+
const preState = loadChiefState()
|
|
920
|
+
const preEffCfg = resolveWorkspaceConfig(preState, rootId)
|
|
921
|
+
const safetyGuardEnabled = !(preEffCfg && preEffCfg.tacticalModes && preEffCfg.tacticalModes.safetyGuardEnabled === false)
|
|
717
922
|
const cwd = (sid && getSessionCwd(runtime, sid)) || (rootId !== 'global' && getSessionCwd(runtime, rootId)) || process.cwd()
|
|
718
923
|
const board = rootId && rootId !== 'global' ? boardForSession(boardFileFor(rootId)) : loadBoard(boardFile())
|
|
719
924
|
const verdict = evaluatePreExecuteDefense({
|
|
@@ -721,6 +926,7 @@ export function createRuntimeHooks(deps) {
|
|
|
721
926
|
args: exec.arguments && typeof exec.arguments === 'object' ? exec.arguments : {},
|
|
722
927
|
cwd,
|
|
723
928
|
board,
|
|
929
|
+
safetyGuardEnabled,
|
|
724
930
|
})
|
|
725
931
|
if (verdict && verdict.decision === 'deny') {
|
|
726
932
|
const st = loadChiefState()
|
|
@@ -742,6 +948,13 @@ export function createRuntimeHooks(deps) {
|
|
|
742
948
|
outcome: 'blocked',
|
|
743
949
|
by: actorName,
|
|
744
950
|
})
|
|
951
|
+
recordWorkspaceAlertEvent(rootId, {
|
|
952
|
+
kind: 'guard_wall_blocked',
|
|
953
|
+
level: 'danger',
|
|
954
|
+
title: '🧱 物理驻墙已拦截越界调用',
|
|
955
|
+
body: `@${actorName} 调用 ${exec.name}:${String(verdict.reason || '').slice(0, 140)}`,
|
|
956
|
+
dedupeKey: `wall:${rootId}:${exec.name}:${verdict.wallId || verdict.rule || ''}`,
|
|
957
|
+
})
|
|
745
958
|
try {
|
|
746
959
|
const bFile = rootId !== 'global' ? boardFileFor(rootId) : boardFile()
|
|
747
960
|
withBoardLock(bFile, () => {
|
|
@@ -812,7 +1025,7 @@ export function createRuntimeHooks(deps) {
|
|
|
812
1025
|
}
|
|
813
1026
|
})
|
|
814
1027
|
|
|
815
|
-
// Runtime capability probe for DSH >= 0.2.2-rc.2 named subagent APIs
|
|
1028
|
+
// Runtime capability probe for DSH >= 0.2.2-rc.2 named subagent APIs & external Harness provider tracking
|
|
816
1029
|
ctx.inject(['subagents'], () => {
|
|
817
1030
|
const compat = probeSubagentSupport(runtime)
|
|
818
1031
|
if (compat.present && !compat.namedSubagentsSupported) {
|
|
@@ -820,7 +1033,45 @@ export function createRuntimeHooks(deps) {
|
|
|
820
1033
|
console.warn('[dsh-chief] ' + compat.warning)
|
|
821
1034
|
} catch {}
|
|
822
1035
|
}
|
|
1036
|
+
try {
|
|
1037
|
+
const sub = runtime && typeof runtime.get === 'function' ? runtime.get('subagents') : null
|
|
1038
|
+
if (sub && sub.providers instanceof Map) {
|
|
1039
|
+
for (const [pname, prov] of sub.providers.entries()) {
|
|
1040
|
+
if (pname && pname !== 'spawn' && pname !== 'fork') {
|
|
1041
|
+
deps.hostState.detectedHarnessProviders.set(pname, prov || { name: pname })
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
} catch {}
|
|
823
1046
|
})
|
|
1047
|
+
try {
|
|
1048
|
+
ctx.on?.('subagent/provider-added', (prov) => {
|
|
1049
|
+
const pname = String((prov && prov.name) || '').trim()
|
|
1050
|
+
if (!pname || pname === 'spawn' || pname === 'fork') return
|
|
1051
|
+
if (typeof prov?.prepareContinuable === 'function') return
|
|
1052
|
+
deps.hostState.detectedHarnessProviders.set(pname, prov)
|
|
1053
|
+
})
|
|
1054
|
+
ctx.on?.('subagent/provider-removed', (pname) => {
|
|
1055
|
+
if (pname) deps.hostState.detectedHarnessProviders.delete(String(pname))
|
|
1056
|
+
})
|
|
1057
|
+
ctx.on?.('subagent/end', (info) => {
|
|
1058
|
+
const cid = String((info && info.id) || '').trim()
|
|
1059
|
+
if (!cid) return
|
|
1060
|
+
for (const [k, run] of deps.hostState.activeBubbleRuns.entries()) {
|
|
1061
|
+
if (run && String(run.childId || '') === cid) {
|
|
1062
|
+
deps.hostState.activeBubbleRuns.delete(k)
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
})
|
|
1066
|
+
} catch {}
|
|
1067
|
+
try {
|
|
1068
|
+
ctx.inject(['subprocess'], (subProcCtx) => {
|
|
1069
|
+
const rt = deps.hostState.activeRuntime
|
|
1070
|
+
deps.hostState.activeSubprocess = (subProcCtx && subProcCtx.subprocess)
|
|
1071
|
+
|| (rt && typeof rt.get === 'function' ? rt.get('subprocess') : null)
|
|
1072
|
+
|| null
|
|
1073
|
+
})
|
|
1074
|
+
} catch {}
|
|
824
1075
|
|
|
825
1076
|
// Cold-start safety reconciliation for persistent TaskLedger (stale running/resuming -> interrupted; past TTL -> expired)
|
|
826
1077
|
try {
|
|
@@ -830,6 +1081,57 @@ export function createRuntimeHooks(deps) {
|
|
|
830
1081
|
)
|
|
831
1082
|
if (hasNeedReconcile) mutateChiefState(() => {})
|
|
832
1083
|
} catch {}
|
|
1084
|
+
|
|
1085
|
+
// Idle watchdog for Strong Intervention: catch already-stalled lead sessions cleanly without extra turns
|
|
1086
|
+
const lastWatchdogByRoot = new Map()
|
|
1087
|
+
const watchdogTimer = setInterval(() => {
|
|
1088
|
+
try {
|
|
1089
|
+
const agents = runtime && runtime.get ? runtime.get('agents') : null
|
|
1090
|
+
const allAgents = agents && typeof agents.list === 'function' ? (agents.list() || []) : []
|
|
1091
|
+
if (!allAgents.length) return
|
|
1092
|
+
const state = loadChiefState()
|
|
1093
|
+
const now = Date.now()
|
|
1094
|
+
for (const ag of allAgents) {
|
|
1095
|
+
const agId = String((ag && ag.id) || '').trim()
|
|
1096
|
+
if (!agId) continue
|
|
1097
|
+
const rootId = resolveRootSessionId(agId, ag) || agId
|
|
1098
|
+
if (rootId !== agId) continue
|
|
1099
|
+
if (!isChiefSessionEnabled(state, rootId)) continue
|
|
1100
|
+
const effCfg = resolveWorkspaceConfig(state, rootId)
|
|
1101
|
+
if (effCfg.stopped || effCfg.paceMode === 'stopped') continue
|
|
1102
|
+
if (!(effCfg.tacticalModes && effCfg.tacticalModes.intervention)) continue
|
|
1103
|
+
if (ag.status === 'running') continue
|
|
1104
|
+
|
|
1105
|
+
const hasRunningChild = allAgents.some(c => {
|
|
1106
|
+
const cId = String((c && c.id) || '').trim()
|
|
1107
|
+
if (!cId || cId === rootId) return false
|
|
1108
|
+
if ((resolveRootSessionId(cId, c) || cId) !== rootId) return false
|
|
1109
|
+
if (/^mnemon-(?:review|run)/i.test(String((c && c.name) || cId))) return false
|
|
1110
|
+
return c && c.status === 'running'
|
|
1111
|
+
})
|
|
1112
|
+
if (hasRunningChild) continue
|
|
1113
|
+
|
|
1114
|
+
const ws = state.workspaces && state.workspaces[rootId] ? state.workspaces[rootId] : null
|
|
1115
|
+
const rg = (ws && ws.runtimeGuard) || {}
|
|
1116
|
+
if (rg.circuitBroken || rg.hazardAlert) continue
|
|
1117
|
+
const hasPendingApr = Array.isArray(ws && ws.pendingApprovals) && ws.pendingApprovals.some(a => a && a.status === 'pending')
|
|
1118
|
+
if (hasPendingApr || (ws && ws.pendingElevation)) continue
|
|
1119
|
+
const hasPendingGoalSug = Array.isArray(ws && ws.suggestions) && ws.suggestions.some(s => s && s.status === 'pending' && s.kind === 'goal_approval')
|
|
1120
|
+
if (hasPendingGoalSug) continue
|
|
1121
|
+
|
|
1122
|
+
const refAt = Math.max(Number(rg.lastActivityAt) || 0, Number(lastWatchdogByRoot.get(rootId)) || 0)
|
|
1123
|
+
if (now - refAt < 22_000) continue
|
|
1124
|
+
lastWatchdogByRoot.set(rootId, now)
|
|
1125
|
+
scheduleChiefTurnReview(makeChiefDeps(runtime), {
|
|
1126
|
+
agent: ag,
|
|
1127
|
+
sessionId: rootId,
|
|
1128
|
+
abnormalTrigger: 'idle_watchdog',
|
|
1129
|
+
})
|
|
1130
|
+
}
|
|
1131
|
+
} catch {}
|
|
1132
|
+
}, 25_000)
|
|
1133
|
+
watchdogTimer.unref?.()
|
|
1134
|
+
ctx.effect(() => () => clearInterval(watchdogTimer), 'dsh-chief: strong intervention watchdog cleanup')
|
|
833
1135
|
}
|
|
834
1136
|
|
|
835
1137
|
return {
|
package/safety/guard-walls.js
CHANGED
|
@@ -807,6 +807,7 @@ export function evaluatePreExecuteDefense({
|
|
|
807
807
|
cwd = '',
|
|
808
808
|
board = null,
|
|
809
809
|
walls = null,
|
|
810
|
+
safetyGuardEnabled = true,
|
|
810
811
|
} = {}) {
|
|
811
812
|
const toolName = String(tool || '').trim()
|
|
812
813
|
const lower = toolName.toLowerCase()
|
|
@@ -862,6 +863,10 @@ export function evaluatePreExecuteDefense({
|
|
|
862
863
|
}
|
|
863
864
|
}
|
|
864
865
|
|
|
866
|
+
if (safetyGuardEnabled === false) {
|
|
867
|
+
return { decision: 'allow', bypassedBySafetyGuardToggle: true }
|
|
868
|
+
}
|
|
869
|
+
|
|
865
870
|
const extraText = [
|
|
866
871
|
argObj.content,
|
|
867
872
|
argObj.new_string,
|