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/board-schema.js
CHANGED
|
@@ -8,7 +8,7 @@ import { normalizeMemory } from './memory.js'
|
|
|
8
8
|
|
|
9
9
|
export const API = '/api/dsh-chief'
|
|
10
10
|
|
|
11
|
-
export const BACKEND_BUILD = '1.
|
|
11
|
+
export const BACKEND_BUILD = '1.7.0'
|
|
12
12
|
|
|
13
13
|
export const BOARD_VERSION = 1
|
|
14
14
|
|
|
@@ -252,6 +252,8 @@ export function normalizeTask(raw) {
|
|
|
252
252
|
evidence: str(task.evidence, '').slice(0, 600),
|
|
253
253
|
blockedBy: Array.isArray(task.blockedBy) ? task.blockedBy.map(item => str(item, '')).filter(Boolean) : [],
|
|
254
254
|
parentId: str(task.parentId, '').slice(0, 200),
|
|
255
|
+
planStepId: str(task.planStepId, '').slice(0, 120),
|
|
256
|
+
targetPlanStepId: str(task.targetPlanStepId, '').slice(0, 120),
|
|
255
257
|
assumptions: Array.isArray(task.assumptions) ? task.assumptions.map(a => ({
|
|
256
258
|
text: str(a && a.text, '').slice(0, CAP_ASSUMPTION),
|
|
257
259
|
verified: a && a.verified === true,
|
|
@@ -404,6 +406,39 @@ function normalizeGoalApproval(raw) {
|
|
|
404
406
|
}
|
|
405
407
|
}
|
|
406
408
|
|
|
409
|
+
const CURSOR_BLOCKED_REAL_CONTRAST_RE = /(?:但|但是|不过|然而|仍|依然|还是).{0,12}(?:卡在|卡住|阻塞|受阻|无法|失败|报错|错误|缺少|缺失|无权限|权限拒绝|拒绝|冲突|超限|超时|未通过)|\b(?:but|however|still)\b.{0,24}\b(?:blocked|stalled|fail(?:ed|ing)?|error|missing|denied|cannot|can't|unable|timeout)\b/i
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Normalize `board.cursor.blocked` so non-blocking / cleared / user-approved remarks
|
|
413
|
+
* (e.g. "无", "无(已获用户批准执行)", "用户已接受当前配置…", "None (approved)")
|
|
414
|
+
* collapse to `""` instead of lighting up a false-positive red alarm pill, while
|
|
415
|
+
* preserving genuine blockers (e.g. "无法连接", "无权限", "没有找到", "等待用户批准",
|
|
416
|
+
* "None of the tests passed", or contrast clauses like "用户已确认,但仍缺少…").
|
|
417
|
+
*/
|
|
418
|
+
export function normalizeCursorBlocked(raw) {
|
|
419
|
+
const s = String(raw === null || raw === undefined ? '' : raw).replace(/\s+/g, ' ').trim()
|
|
420
|
+
if (!s) return ''
|
|
421
|
+
const unwrapped = s.replace(/^[\s\-—–_\/.,;:!?~`'"“”‘’()()【】\[\]{}]+|[\s\-—–_\/.,;:!?~`'"“”‘’()()【】\[\]{}]+$/g, '').trim()
|
|
422
|
+
if (!unwrapped) return ''
|
|
423
|
+
if (/^(?:无|暂无|没有|木有|空|正常|无阻塞|无卡点|无阻碍|无受阻|无障碍|未受阻|未阻塞|不阻塞|不受阻|非阻塞|目前无阻塞|当前无阻塞|暂无阻塞|暂无卡点|没有阻塞|没有卡点|无异常|无报错|已解除|已解决|已清空|已清零|已放行|已通过|已恢复|已批准|已获批|已获批准|已获用户批准|已获用户批准执行|已确认|已同意|none|no|n\/?a|nil|null|empty|nothing|false|ok|clear|cleared|resolved|unblocked|not\s+blocked|no\s+blockers?|no\s+issues?|approved|user\s+approved)$/i.test(unwrapped)) {
|
|
424
|
+
return ''
|
|
425
|
+
}
|
|
426
|
+
if (CURSOR_BLOCKED_REAL_CONTRAST_RE.test(s)) {
|
|
427
|
+
return s.slice(0, 400)
|
|
428
|
+
}
|
|
429
|
+
if (
|
|
430
|
+
/^(?:(?:目前|当前)?(?:无|暂无)(?=$|[\s((【\[,,;;::。.\-—/、])|(?:目前|当前)?(?:无|暂无|没有|未|不|非)(?:明显|任何)?(?:阻塞|卡点|阻碍|受阻|障碍|卡住|异常|报错|问题)(?=$|[\s((【\[,,;;::。.\-—/、])|(?:已解除|已解决|已放行|已清空|已清零|已恢复|已获(?:用户)?批(?:准)?(?:执行)?|已由用户(?:批准|确认|同意|接受)|用户已(?:接受|批准|确认|同意|拍板|放行|认可)))/.test(s)
|
|
431
|
+
) {
|
|
432
|
+
return ''
|
|
433
|
+
}
|
|
434
|
+
if (
|
|
435
|
+
/^(?:(?:none|n\/?a|nil|null|nothing)(?=$|\s*[(\[.,;:\-\/])|(?:not\s+blocked|no\s+blockers?(?:\s+found|\s+now|\s+remaining)?|unblocked|resolved|cleared|approved(?:\s+by\s+user)?|user\s+(?:approved|accepted|confirmed))(?=$|[\s(\[.,;:\-\/]))/i.test(s)
|
|
436
|
+
) {
|
|
437
|
+
return ''
|
|
438
|
+
}
|
|
439
|
+
return s.slice(0, 400)
|
|
440
|
+
}
|
|
441
|
+
|
|
407
442
|
export function normalizeBoard(raw) {
|
|
408
443
|
const board = raw && typeof raw === 'object' ? raw : {}
|
|
409
444
|
const plan = Array.isArray(board.plan) ? board.plan : []
|
|
@@ -453,16 +488,20 @@ export function normalizeBoard(raw) {
|
|
|
453
488
|
at: board.cursor && typeof board.cursor.at === 'number' ? board.cursor.at : 0,
|
|
454
489
|
step: str(board.cursor && board.cursor.step, '').slice(0, 400),
|
|
455
490
|
next: str(board.cursor && board.cursor.next, '').slice(0, 400),
|
|
456
|
-
blocked:
|
|
491
|
+
blocked: normalizeCursorBlocked(board.cursor && board.cursor.blocked),
|
|
457
492
|
by: str(board.cursor && board.cursor.by, ''),
|
|
458
493
|
session: str(board.cursor && board.cursor.session, ''),
|
|
459
494
|
},
|
|
460
495
|
plan: plan
|
|
461
|
-
.map(step =>
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
496
|
+
.map(step => {
|
|
497
|
+
const cleanSummary = str(step && step.summary, '').trim().slice(0, 240)
|
|
498
|
+
return {
|
|
499
|
+
id: str(step && step.id, newId('s')),
|
|
500
|
+
text: str(step && step.text, '').slice(0, 400),
|
|
501
|
+
done: step && step.done === true,
|
|
502
|
+
...(cleanSummary ? { summary: cleanSummary } : {}),
|
|
503
|
+
}
|
|
504
|
+
})
|
|
466
505
|
.filter(step => step.text !== ''),
|
|
467
506
|
tasks: tasks.map(normalizeTask).filter(task => task.title !== ''),
|
|
468
507
|
notes: dedupeNotes(notes.map(normalizeNote).filter(note => note.title !== '' || note.body !== '')),
|
|
@@ -493,6 +532,15 @@ export function guardLogText(verdict, turn, remaining) {
|
|
|
493
532
|
return '空转拦截:第 ' + turn + ' 轮同一个调用连着做了 ' + (loop.count || 0) + ' 次('
|
|
494
533
|
+ String(loop.name || '?').slice(0, 40) + ')结果没变' + tail
|
|
495
534
|
}
|
|
535
|
+
if (verdict && verdict.kind === 'premature-promise') {
|
|
536
|
+
return '空转拦截:第 ' + turn + ' 轮口头预告「'
|
|
537
|
+
+ String(verdict.promiseCue || '').slice(0, 40) + '」却未执行就收工' + tail
|
|
538
|
+
}
|
|
539
|
+
if (verdict && verdict.kind === 'mid-turn-spin') {
|
|
540
|
+
const spin = verdict.spin || verdict.loop || {}
|
|
541
|
+
return '运行中空转急刹:连续空转/报错 ' + (spin.count || 0) + ' 次('
|
|
542
|
+
+ String(spin.name || '?').slice(0, 40) + ')已当场插话纠偏'
|
|
543
|
+
}
|
|
496
544
|
if (verdict && verdict.kind === 'no-goal') {
|
|
497
545
|
return '空转拦截:第 ' + turn + ' 轮板子处在 goal 模式却没有目标' + tail
|
|
498
546
|
}
|
|
@@ -538,6 +586,8 @@ export function summary(board, subagents) {
|
|
|
538
586
|
preset: task.preset || '',
|
|
539
587
|
session: task.session,
|
|
540
588
|
parentId: task.parentId || '',
|
|
589
|
+
planStepId: task.planStepId || '',
|
|
590
|
+
targetPlanStepId: task.targetPlanStepId || '',
|
|
541
591
|
blockedBy: Array.isArray(task.blockedBy) ? task.blockedBy : [],
|
|
542
592
|
intent: task.intent || '',
|
|
543
593
|
evidence: task.evidence || '',
|
|
@@ -578,3 +628,311 @@ export function summary(board, subagents) {
|
|
|
578
628
|
updatedAt: board.updatedAt,
|
|
579
629
|
}
|
|
580
630
|
}
|
|
631
|
+
|
|
632
|
+
/* ------------------------------------------------------ workflow pipeline */
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Resolve which plan step ID is currently active for auto-attaching tasks/subagents.
|
|
636
|
+
* Prefers an open step matching `cursor.step`, then the first incomplete step,
|
|
637
|
+
* and finally the last step when all are done.
|
|
638
|
+
*/
|
|
639
|
+
export function resolveActivePlanStepId(board) {
|
|
640
|
+
const plan = board && Array.isArray(board.plan) ? board.plan.filter(s => s && s.text) : []
|
|
641
|
+
if (!plan.length) return ''
|
|
642
|
+
const cursorStep = str(board && board.cursor && board.cursor.step, '').trim().toLowerCase()
|
|
643
|
+
if (cursorStep) {
|
|
644
|
+
const exact = plan.find(s => !s.done && str(s.text, '').trim().toLowerCase() === cursorStep)
|
|
645
|
+
if (exact) return exact.id
|
|
646
|
+
const prefix = plan.find(s => !s.done && (
|
|
647
|
+
str(s.text, '').trim().toLowerCase().startsWith(cursorStep)
|
|
648
|
+
|| cursorStep.startsWith(str(s.text, '').trim().toLowerCase().slice(0, 24))
|
|
649
|
+
))
|
|
650
|
+
if (prefix) return prefix.id
|
|
651
|
+
}
|
|
652
|
+
const firstOpen = plan.find(s => !s.done)
|
|
653
|
+
return firstOpen ? firstOpen.id : plan[plan.length - 1].id
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function topoSortRootTasks(roots) {
|
|
657
|
+
if (roots.length <= 1) return roots.slice()
|
|
658
|
+
const byId = new Map(roots.map(t => [t.id, t]))
|
|
659
|
+
const inDeg = new Map(roots.map(t => [t.id, 0]))
|
|
660
|
+
const adj = new Map(roots.map(t => [t.id, []]))
|
|
661
|
+
for (const t of roots) {
|
|
662
|
+
const deps = Array.isArray(t.blockedBy) ? t.blockedBy : []
|
|
663
|
+
for (const depId of deps) {
|
|
664
|
+
if (byId.has(depId) && depId !== t.id) {
|
|
665
|
+
inDeg.set(t.id, (inDeg.get(t.id) || 0) + 1)
|
|
666
|
+
adj.get(depId).push(t.id)
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const ready = roots.filter(t => (inDeg.get(t.id) || 0) === 0).sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0))
|
|
671
|
+
const ordered = []
|
|
672
|
+
const placed = new Set()
|
|
673
|
+
while (ready.length) {
|
|
674
|
+
const cur = ready.shift()
|
|
675
|
+
if (!cur || placed.has(cur.id)) continue
|
|
676
|
+
placed.add(cur.id)
|
|
677
|
+
ordered.push(cur)
|
|
678
|
+
for (const nxtId of adj.get(cur.id) || []) {
|
|
679
|
+
const deg = (inDeg.get(nxtId) || 1) - 1
|
|
680
|
+
inDeg.set(nxtId, deg)
|
|
681
|
+
if (deg <= 0) {
|
|
682
|
+
ready.push(byId.get(nxtId))
|
|
683
|
+
ready.sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0))
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
for (const t of roots) {
|
|
688
|
+
if (!placed.has(t.id)) ordered.push(t)
|
|
689
|
+
}
|
|
690
|
+
return ordered
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function isInternalProbeAgentName(name) {
|
|
694
|
+
const raw = String(name || '').trim().replace(/^@/, '')
|
|
695
|
+
if (!raw) return false
|
|
696
|
+
const leaf = raw.split('/').pop() || raw
|
|
697
|
+
return /^mnemon-(?:review|run)(?:[-_]|$)/i.test(leaf)
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Derive sequential workflow stages (`① -> ② -> ③ ...`), attached tasks,
|
|
702
|
+
* sprouted subagent branches, return-edge targets, and unified 4-state colors.
|
|
703
|
+
*/
|
|
704
|
+
export function derivePlanFlowProgress(board, subagents = []) {
|
|
705
|
+
const safeBoard = board && typeof board === 'object' ? board : {}
|
|
706
|
+
const plan = Array.isArray(safeBoard.plan) ? safeBoard.plan.filter(s => s && s.text) : []
|
|
707
|
+
const tasks = Array.isArray(safeBoard.tasks) ? safeBoard.tasks.filter(t => t && t.title) : []
|
|
708
|
+
const rawAgents = Array.isArray(subagents) ? subagents.filter(a => a && a.name && a.name !== 'lead') : []
|
|
709
|
+
const visibleAgents = rawAgents.filter(a => !(isInternalProbeAgentName(a.name) && a.status !== 'running'))
|
|
710
|
+
|
|
711
|
+
let mode = 'empty'
|
|
712
|
+
let stages = []
|
|
713
|
+
|
|
714
|
+
if (plan.length > 0) {
|
|
715
|
+
mode = 'plan'
|
|
716
|
+
stages = plan.map((s, idx) => ({
|
|
717
|
+
id: str(s.id, `s-${idx + 1}`),
|
|
718
|
+
index: idx + 1,
|
|
719
|
+
text: str(s.text, ''),
|
|
720
|
+
done: s.done === true,
|
|
721
|
+
summary: str(s.summary, ''),
|
|
722
|
+
source: 'plan',
|
|
723
|
+
rootTaskId: '',
|
|
724
|
+
tasks: [],
|
|
725
|
+
agents: [],
|
|
726
|
+
returnEdges: [],
|
|
727
|
+
status: 'todo',
|
|
728
|
+
}))
|
|
729
|
+
} else if (tasks.length > 0) {
|
|
730
|
+
mode = 'task-root'
|
|
731
|
+
const taskIds = new Set(tasks.map(t => t.id))
|
|
732
|
+
const roots = topoSortRootTasks(tasks.filter(t => !t.parentId || !taskIds.has(t.parentId) || t.parentId === t.id))
|
|
733
|
+
stages = roots.map((t, idx) => ({
|
|
734
|
+
id: 's-' + t.id,
|
|
735
|
+
index: idx + 1,
|
|
736
|
+
text: t.title,
|
|
737
|
+
done: t.status === 'done',
|
|
738
|
+
summary: t.evidence || '',
|
|
739
|
+
source: 'task-root',
|
|
740
|
+
rootTaskId: t.id,
|
|
741
|
+
tasks: [],
|
|
742
|
+
agents: [],
|
|
743
|
+
returnEdges: [],
|
|
744
|
+
status: 'todo',
|
|
745
|
+
}))
|
|
746
|
+
} else if (visibleAgents.length > 0 || str(safeBoard.objective, '').trim()) {
|
|
747
|
+
mode = 'synthetic'
|
|
748
|
+
stages = [{
|
|
749
|
+
id: 'stage-main',
|
|
750
|
+
index: 1,
|
|
751
|
+
text: str(safeBoard.objective, '').trim() || '当前主线任务',
|
|
752
|
+
done: false,
|
|
753
|
+
summary: '',
|
|
754
|
+
source: 'synthetic',
|
|
755
|
+
rootTaskId: '',
|
|
756
|
+
tasks: [],
|
|
757
|
+
agents: [],
|
|
758
|
+
returnEdges: [],
|
|
759
|
+
status: 'todo',
|
|
760
|
+
}]
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
if (!stages.length) {
|
|
764
|
+
return {
|
|
765
|
+
mode: 'empty',
|
|
766
|
+
stages: [],
|
|
767
|
+
activeStageId: '',
|
|
768
|
+
orphanTasks: [],
|
|
769
|
+
stats: {
|
|
770
|
+
totalStages: 0,
|
|
771
|
+
doneStages: 0,
|
|
772
|
+
doingStages: 0,
|
|
773
|
+
blockedStages: 0,
|
|
774
|
+
totalAgents: 0,
|
|
775
|
+
runningAgents: 0,
|
|
776
|
+
doneAgents: 0,
|
|
777
|
+
},
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
const stageById = new Map(stages.map(s => [s.id, s]))
|
|
782
|
+
const taskById = new Map(tasks.map(t => [t.id, t]))
|
|
783
|
+
const activeStepId = resolveActivePlanStepId(safeBoard) || (stages.find(s => !s.done)?.id || stages[stages.length - 1].id)
|
|
784
|
+
const doneStagesRev = [...stages].reverse().find(s => s.done)
|
|
785
|
+
const lastDoneStepId = doneStagesRev ? doneStagesRev.id : activeStepId
|
|
786
|
+
|
|
787
|
+
const taskStageCache = new Map()
|
|
788
|
+
const resolveTaskStageId = (task, seen = new Set()) => {
|
|
789
|
+
if (!task) return ''
|
|
790
|
+
if (taskStageCache.has(task.id)) return taskStageCache.get(task.id)
|
|
791
|
+
let hitId = ''
|
|
792
|
+
if (task.planStepId && stageById.has(task.planStepId)) {
|
|
793
|
+
hitId = task.planStepId
|
|
794
|
+
} else if (stageById.has('s-' + task.id)) {
|
|
795
|
+
hitId = 's-' + task.id
|
|
796
|
+
} else {
|
|
797
|
+
const byPrefix = stages.find(s => s.text && task.title && s.text.startsWith(task.title))
|
|
798
|
+
if (byPrefix) hitId = byPrefix.id
|
|
799
|
+
}
|
|
800
|
+
if (!hitId && task.parentId && taskById.has(task.parentId) && !seen.has(task.id)) {
|
|
801
|
+
seen.add(task.id)
|
|
802
|
+
hitId = resolveTaskStageId(taskById.get(task.parentId), seen)
|
|
803
|
+
}
|
|
804
|
+
if (!hitId) {
|
|
805
|
+
if (task.status === 'done') hitId = lastDoneStepId || activeStepId
|
|
806
|
+
else hitId = activeStepId
|
|
807
|
+
}
|
|
808
|
+
taskStageCache.set(task.id, hitId)
|
|
809
|
+
return hitId
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const orphanTasks = []
|
|
813
|
+
for (const t of tasks) {
|
|
814
|
+
const sid = resolveTaskStageId(t)
|
|
815
|
+
const st = sid ? stageById.get(sid) : null
|
|
816
|
+
if (st) st.tasks.push(t)
|
|
817
|
+
else orphanTasks.push(t)
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const matchAgentTasks = agentObj => {
|
|
821
|
+
const aName = str(agentObj && agentObj.name, '').trim().toLowerCase()
|
|
822
|
+
const aLeaf = aName.split('/').pop()
|
|
823
|
+
const aId = str(agentObj && agentObj.id, '').trim()
|
|
824
|
+
const aTaskId = str(agentObj && agentObj.taskId, '').trim()
|
|
825
|
+
const aTaskIds = new Set(Array.isArray(agentObj && agentObj.tasks) ? agentObj.tasks.map(x => str(x && x.id, '').trim()).filter(Boolean) : [])
|
|
826
|
+
if (aTaskId) aTaskIds.add(aTaskId)
|
|
827
|
+
return tasks.filter(t => {
|
|
828
|
+
if (aTaskIds.has(t.id)) return true
|
|
829
|
+
if (aId && t.session && String(t.session) === aId) return true
|
|
830
|
+
const ref = str(t.subagent || t.owner, '').trim().toLowerCase()
|
|
831
|
+
if (!ref || ref === 'lead' || ref === 'agent' || ref === 'operator') return false
|
|
832
|
+
return ref === aName || (aLeaf && ref.split('/').pop() === aLeaf)
|
|
833
|
+
})
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
let runningAgents = 0
|
|
837
|
+
let doneAgents = 0
|
|
838
|
+
for (const agentObj of visibleAgents) {
|
|
839
|
+
const agentTasks = matchAgentTasks(agentObj)
|
|
840
|
+
const rawAgentSt = str(agentObj.status, '').trim().toLowerCase()
|
|
841
|
+
const hasBlockedTask = agentTasks.some(t => t.status === 'blocked')
|
|
842
|
+
const hasDoingTask = agentTasks.some(t => t.status === 'doing')
|
|
843
|
+
const hasOpenTask = agentTasks.some(t => t.status === 'todo' || t.status === 'doing' || t.status === 'blocked')
|
|
844
|
+
const allTasksDone = agentTasks.length > 0 && agentTasks.every(t => t.status === 'done')
|
|
845
|
+
const isAgentFailed = /error|fail|crash|blocked/.test(rawAgentSt)
|
|
846
|
+
const isAgentRunning = rawAgentSt === 'running' || rawAgentSt === 'active' || rawAgentSt === 'working'
|
|
847
|
+
const isAgentEnded = rawAgentSt !== '' && !isAgentRunning && !isAgentFailed && rawAgentSt !== 'todo' && rawAgentSt !== 'queued'
|
|
848
|
+
|
|
849
|
+
let agentStatus = 'todo'
|
|
850
|
+
if (hasBlockedTask || isAgentFailed) agentStatus = 'blocked'
|
|
851
|
+
else if (isAgentRunning || hasDoingTask) agentStatus = 'doing'
|
|
852
|
+
else if (allTasksDone || (isAgentEnded && !hasOpenTask)) agentStatus = 'done'
|
|
853
|
+
|
|
854
|
+
if (agentStatus === 'doing') runningAgents += 1
|
|
855
|
+
else if (agentStatus === 'done') doneAgents += 1
|
|
856
|
+
|
|
857
|
+
const primaryTask = agentTasks.find(t => t.status === 'doing' || t.status === 'blocked')
|
|
858
|
+
|| agentTasks.find(t => t.status === 'todo')
|
|
859
|
+
|| agentTasks[0]
|
|
860
|
+
|| null
|
|
861
|
+
|
|
862
|
+
let fromStepId = primaryTask ? resolveTaskStageId(primaryTask) : ''
|
|
863
|
+
if (!fromStepId || !stageById.has(fromStepId)) {
|
|
864
|
+
fromStepId = agentStatus === 'done' ? (lastDoneStepId || activeStepId) : activeStepId
|
|
865
|
+
}
|
|
866
|
+
const rawTargetId = primaryTask && primaryTask.targetPlanStepId ? primaryTask.targetPlanStepId : ''
|
|
867
|
+
const toStepId = (rawTargetId && stageById.has(rawTargetId)) ? rawTargetId : fromStepId
|
|
868
|
+
|
|
869
|
+
const stage = stageById.get(fromStepId) || stages[0]
|
|
870
|
+
const node = {
|
|
871
|
+
name: str(agentObj.name, ''),
|
|
872
|
+
id: str(agentObj.id, ''),
|
|
873
|
+
parentId: str(agentObj.parentId, ''),
|
|
874
|
+
rawStatus: rawAgentSt,
|
|
875
|
+
agentStatus,
|
|
876
|
+
taskIds: agentTasks.map(t => t.id),
|
|
877
|
+
primaryTaskId: primaryTask ? primaryTask.id : '',
|
|
878
|
+
fromStepId: stage.id,
|
|
879
|
+
toStepId,
|
|
880
|
+
crossStep: toStepId !== stage.id,
|
|
881
|
+
}
|
|
882
|
+
stage.agents.push(node)
|
|
883
|
+
stage.returnEdges.push({
|
|
884
|
+
fromAgent: node.name,
|
|
885
|
+
taskId: node.primaryTaskId,
|
|
886
|
+
fromStepId: stage.id,
|
|
887
|
+
toStepId,
|
|
888
|
+
status: agentStatus,
|
|
889
|
+
crossStep: toStepId !== stage.id,
|
|
890
|
+
})
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const firstOpenStage = stages.find(s => !s.done) || null
|
|
894
|
+
const hasAnyDone = stages.some(s => s.done)
|
|
895
|
+
const hasCursorStep = Boolean(str(safeBoard.cursor && safeBoard.cursor.step, '').trim())
|
|
896
|
+
const hasAnyActivity = hasAnyDone
|
|
897
|
+
|| hasCursorStep
|
|
898
|
+
|| tasks.some(t => t.status !== 'todo')
|
|
899
|
+
|| visibleAgents.length > 0
|
|
900
|
+
|
|
901
|
+
let doneStages = 0
|
|
902
|
+
let doingStages = 0
|
|
903
|
+
let blockedStages = 0
|
|
904
|
+
for (const stage of stages) {
|
|
905
|
+
if (stage.done) {
|
|
906
|
+
stage.status = 'done'
|
|
907
|
+
doneStages += 1
|
|
908
|
+
} else if (stage.tasks.some(t => t.status === 'blocked') || stage.agents.some(a => a.agentStatus === 'blocked')) {
|
|
909
|
+
stage.status = 'blocked'
|
|
910
|
+
blockedStages += 1
|
|
911
|
+
} else if (
|
|
912
|
+
stage.tasks.some(t => t.status === 'doing')
|
|
913
|
+
|| stage.agents.some(a => a.agentStatus === 'doing')
|
|
914
|
+
|| (firstOpenStage && firstOpenStage.id === stage.id && hasAnyActivity)
|
|
915
|
+
) {
|
|
916
|
+
stage.status = 'doing'
|
|
917
|
+
doingStages += 1
|
|
918
|
+
} else {
|
|
919
|
+
stage.status = 'todo'
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
return {
|
|
924
|
+
mode,
|
|
925
|
+
stages,
|
|
926
|
+
activeStageId: activeStepId,
|
|
927
|
+
orphanTasks,
|
|
928
|
+
stats: {
|
|
929
|
+
totalStages: stages.length,
|
|
930
|
+
doneStages,
|
|
931
|
+
doingStages,
|
|
932
|
+
blockedStages,
|
|
933
|
+
totalAgents: visibleAgents.length,
|
|
934
|
+
runningAgents,
|
|
935
|
+
doneAgents,
|
|
936
|
+
},
|
|
937
|
+
}
|
|
938
|
+
}
|
package/chief-approvals.js
CHANGED
|
@@ -417,6 +417,7 @@ export async function executeBatchSuggestions(deps, {
|
|
|
417
417
|
command: cmdSample,
|
|
418
418
|
args: { text: sug.draftText || '', title: sug.title || '' },
|
|
419
419
|
board,
|
|
420
|
+
safetyGuardEnabled: !(effCfg && effCfg.tacticalModes && effCfg.tacticalModes.safetyGuardEnabled === false),
|
|
420
421
|
})
|
|
421
422
|
if (guardRes.blocked) {
|
|
422
423
|
mutateChiefState((st) => {
|
|
@@ -532,6 +533,7 @@ export async function handleApprovalDecision(deps, {
|
|
|
532
533
|
let found = null
|
|
533
534
|
let currentMode = DEFAULT_CHIEF_PERMISSION_MODE
|
|
534
535
|
let effPolicyPlugins = []
|
|
536
|
+
let effSafetyGuardEnabled = true
|
|
535
537
|
let existingNonPending = false
|
|
536
538
|
let hashMismatch = false
|
|
537
539
|
|
|
@@ -541,6 +543,7 @@ export async function handleApprovalDecision(deps, {
|
|
|
541
543
|
const eff = resolveWorkspaceConfig(state, rootId)
|
|
542
544
|
currentMode = normalizePermissionMode(eff.permissionMode, { requireAck: true, hasChiefRiskAck: ackOk })
|
|
543
545
|
effPolicyPlugins = Array.isArray(eff.policyPlugins) ? eff.policyPlugins : []
|
|
546
|
+
effSafetyGuardEnabled = !(eff && eff.tacticalModes && eff.tacticalModes.safetyGuardEnabled === false)
|
|
544
547
|
const item = (ws.pendingApprovals || []).find(a => a && a.id === approvalId && a.status === 'pending')
|
|
545
548
|
if (!item) {
|
|
546
549
|
existingNonPending = (ws.pendingApprovals || []).some(a => a && a.id === approvalId)
|
|
@@ -689,6 +692,7 @@ export async function handleApprovalDecision(deps, {
|
|
|
689
692
|
permissionMode: currentMode === 'chief' ? 'chief' : 'strategist',
|
|
690
693
|
hasChiefRiskAck: currentMode === 'chief',
|
|
691
694
|
policyPlugins: effPolicyPlugins,
|
|
695
|
+
safetyGuardEnabled: effSafetyGuardEnabled,
|
|
692
696
|
capabilityScope: resolvedScope,
|
|
693
697
|
approvedOnce: true,
|
|
694
698
|
board,
|
|
@@ -709,7 +713,7 @@ export async function handleApprovalDecision(deps, {
|
|
|
709
713
|
resultMsg = scopeCheck.error
|
|
710
714
|
appendChiefAuditLog(rootId, { mode: currentMode, stage: 'scope_guard', rule: scopeCheck.rule, decision: 'rejected', operation: found.operationLabel, target: found.targetLabel, reason: scopeCheck.error, outcome: 'rejected', by: 'operator' })
|
|
711
715
|
} else {
|
|
712
|
-
const guardRes = evaluateSafetyGuardHardRules({ tool: 'relay', opClass: 'workflow', command: payload.text || '', board })
|
|
716
|
+
const guardRes = evaluateSafetyGuardHardRules({ tool: 'relay', opClass: 'workflow', command: payload.text || '', board, safetyGuardEnabled: effSafetyGuardEnabled })
|
|
713
717
|
if (guardRes.blocked) {
|
|
714
718
|
execOk = false
|
|
715
719
|
execRes = { ok: false, blockedBySafetyGuard: true, error: guardRes.reason }
|
|
@@ -753,7 +757,7 @@ export async function handleApprovalDecision(deps, {
|
|
|
753
757
|
}
|
|
754
758
|
}
|
|
755
759
|
} else if (found.kind === 'compact') {
|
|
756
|
-
const guardRes = evaluateSafetyGuardHardRules({ tool: 'session_compact', opClass: 'workflow', board })
|
|
760
|
+
const guardRes = evaluateSafetyGuardHardRules({ tool: 'session_compact', opClass: 'workflow', board, safetyGuardEnabled: effSafetyGuardEnabled })
|
|
757
761
|
if (guardRes.blocked) {
|
|
758
762
|
execOk = false
|
|
759
763
|
execRes = { ok: false, blockedBySafetyGuard: true, error: guardRes.reason }
|
package/chief-archives.js
CHANGED
|
@@ -420,6 +420,7 @@ export async function harvestTurnDetailsToArchive(deps, {
|
|
|
420
420
|
try {
|
|
421
421
|
const llmRes = await callChiefLlm(deps, {
|
|
422
422
|
sessionId: rootId,
|
|
423
|
+
reasonKind: 'archive_harvest',
|
|
423
424
|
system: HARVEST_ARCHIVE_SYSTEM,
|
|
424
425
|
prompt: `触发模式:${trigger === 'pre-compaction' ? '上下文压缩前自动高保真抢救' : '用户手动抢救当前工作细节入柜'}\n\n${cleanMultiline(bodySource, 5200)}`,
|
|
425
426
|
maxTokens: SUMMARY_MAX_TOKENS,
|