dsh-chief 1.3.0 → 1.5.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 +84 -12
- package/README.en.md +156 -113
- package/README.md +149 -140
- package/api-routes.js +183 -4
- package/archive-core.js +136 -8
- package/archive-dossiers.js +450 -20
- package/archive-precipitated.js +115 -36
- package/auto-continue.js +13 -5
- package/board-actions.js +131 -5
- package/board-schema.js +1 -1
- package/chief-approvals.js +415 -90
- package/chief-archives.js +191 -29
- package/chief-commands.js +1178 -207
- package/chief-executor.js +279 -555
- package/chief-models.js +158 -28
- package/chief-network.js +157 -8
- package/chief-review.js +240 -67
- package/chief-state.js +855 -109
- package/chief-view.js +38 -20
- package/client.js +5602 -2618
- package/digest.js +18 -9
- package/model-tools.js +92 -6
- package/package.json +41 -25
- package/runtime-hooks.js +221 -12
- package/safety/audit-log.js +95 -0
- package/safety/command-analyzer.js +339 -0
- package/safety/guard-walls.js +993 -0
- package/safety/index.js +78 -0
- package/safety/invariant-guards.js +280 -0
- package/safety/path-guard.js +227 -0
- package/safety/policy-engine.js +387 -0
- package/safety/policy-plugin.js +391 -0
- package/safety/tool-gate.js +278 -0
- package/subagent-runtime.js +266 -3
package/chief-commands.js
CHANGED
|
@@ -26,6 +26,9 @@ import {
|
|
|
26
26
|
getToolOpClass,
|
|
27
27
|
evaluateSafetyGuardHardRules,
|
|
28
28
|
evaluateChiefPermissionGate,
|
|
29
|
+
buildCapabilityScope,
|
|
30
|
+
validateGuardWallInput,
|
|
31
|
+
listGuardWalls,
|
|
29
32
|
CHIEF_TOOLS_PROMPT_GUIDE,
|
|
30
33
|
runChiefAgenticLoop,
|
|
31
34
|
stripToolCallMarkup,
|
|
@@ -49,9 +52,11 @@ import {
|
|
|
49
52
|
normalizeSuggestion,
|
|
50
53
|
resolveWorkspaceConfig,
|
|
51
54
|
appendChiefAuditLog,
|
|
55
|
+
pushAuditToWs,
|
|
52
56
|
queueChiefApproval,
|
|
53
57
|
requestChiefElevation,
|
|
54
|
-
|
|
58
|
+
upsertTaskLedgerOnWs,
|
|
59
|
+
enqueueChiefInquiryOnWs,
|
|
55
60
|
loadChiefState,
|
|
56
61
|
mutateChiefState,
|
|
57
62
|
getLinkedCluster,
|
|
@@ -63,9 +68,18 @@ import {
|
|
|
63
68
|
isInternalCheckpointNoise,
|
|
64
69
|
updateWorkspaceFlippedIds,
|
|
65
70
|
extractJsonObject,
|
|
71
|
+
resolveSessionWorkspaceCwd,
|
|
72
|
+
CHIEF_INQUIRY_SOURCE,
|
|
73
|
+
beginChiefActiveWork,
|
|
74
|
+
endChiefActiveWork,
|
|
66
75
|
} from './chief-state.js'
|
|
67
76
|
import { callChiefLlm } from './chief-models.js'
|
|
68
|
-
import {
|
|
77
|
+
import {
|
|
78
|
+
collectClusterPeerProgress,
|
|
79
|
+
listPeerDirectory,
|
|
80
|
+
deliverCrossMessage,
|
|
81
|
+
registerChiefDirectRequestHook,
|
|
82
|
+
} from './chief-network.js'
|
|
69
83
|
import {
|
|
70
84
|
sanitizeConciseBriefText,
|
|
71
85
|
buildConciseSixLineReport,
|
|
@@ -94,7 +108,29 @@ const ASK_CHIEF_SYSTEM = [
|
|
|
94
108
|
' "requestedActionSummary": "拟执行的核心动作简述"',
|
|
95
109
|
' },',
|
|
96
110
|
' "relays": [',
|
|
97
|
-
' { "target": "成员 key 或名字(如 lead / 子代理名 / session-xxx / all)", "mode": "steer|followup|silent", "subject": "简短事由", "text": "
|
|
111
|
+
' { "target": "成员 key 或名字(如 lead / 子代理名 / session-xxx / all)", "mode": "steer|followup|silent", "subject": "简短事由", "text": "替用户转化好的清晰可执行执行请求" }',
|
|
112
|
+
' ],',
|
|
113
|
+
' "inquiries": [',
|
|
114
|
+
' { "target": "lead", "question": "缺情报时向主对话提出的优先问询(禁止凭空瞎猜)", "context": "简短问询背景" }',
|
|
115
|
+
' ],',
|
|
116
|
+
' "wallProposals": [',
|
|
117
|
+
' {',
|
|
118
|
+
' "title": "物理驻墙名称",',
|
|
119
|
+
' "scope": "global|workspace",',
|
|
120
|
+
' "ruleType": "forbid_path|restrict_write|forbid_cmd|require_approval_cmd|deny_tool",',
|
|
121
|
+
' "patterns": ["被锁路径前缀/目录名 或 禁跑命令正则"],',
|
|
122
|
+
' "writeOnly": false,',
|
|
123
|
+
' "reason": "手搓这堵物理墙的原因"',
|
|
124
|
+
' }',
|
|
125
|
+
' ],',
|
|
126
|
+
' "wallRemovalProposals": [',
|
|
127
|
+
' {',
|
|
128
|
+
' "wallId": "阻塞任务的动态物理驻墙 ID(必须精确匹配上下文清单中的 wallId,极低概率仅在确认无替代路时填写)",',
|
|
129
|
+
' "wallTitle": "对应物理驻墙名称",',
|
|
130
|
+
' "action": "pause|remove",',
|
|
131
|
+
' "blockerEvidence": "主/子代理撞墙且确无绕过可能的实测证据(必填)",',
|
|
132
|
+
' "reason": "为何必须申请暂挂/拆除这堵物理墙才能继续当前任务"',
|
|
133
|
+
' }',
|
|
98
134
|
' ],',
|
|
99
135
|
' "memoryChanges": [',
|
|
100
136
|
' { "op": "add", "category": "discipline|architecture|progress|preference|team", "text": "一句独立完整的持久事实或规矩(不超过200字,绝不存密钥密码)" },',
|
|
@@ -125,10 +161,15 @@ const ASK_CHIEF_SYSTEM = [
|
|
|
125
161
|
' { "op": "bounds.remove", "field": "forbidden|allowed|notes", "item": "要移除的旧边界条文", "pinGlobal": false }',
|
|
126
162
|
' ],',
|
|
127
163
|
' "archiveOps": [',
|
|
128
|
-
' { "op": "organize", "vaultScope": "session|global", "scope": "unorganized|all", "instruction": "
|
|
164
|
+
' { "op": "organize", "vaultScope": "session|global", "scope": "unorganized|all", "instruction": "整理分类并织就钩子要求" },',
|
|
129
165
|
' { "op": "distill_to_global", "ids": ["可选:指定本局档案ID,留空自动筛选可复用本局经验"], "instruction": "提炼入全局要求" },',
|
|
130
|
-
' { "op": "
|
|
131
|
-
' { "op": "
|
|
166
|
+
' { "op": "pull_global", "id": "全局钩子档案ID", "title": "或标题关键词(参谋见全局钩子后按需拉阅全文)" },',
|
|
167
|
+
' { "op": "pin_to_desktop|unpin_from_desktop|deliver_to_lead", "vaultScope": "session|global", "id": "档案ID", "title": "或标题关键词", "target": "lead", "instruction": "可选附言(仅本局/已织钩全局;严禁触碰冷藏柜)" },',
|
|
168
|
+
' { "op": "copy_to_global|copy_to_session|move_folder|delete", "vaultScope": "session|global", "id": "目标档案ID", "title": "或标题关键词", "folder": "可选抽屉ID" },',
|
|
169
|
+
' { "op": "save", "vaultScope": "session|global", "title": "档案标题", "folder": "inbox|coords|incidents|contracts|ops|plans", "summary": "摘要", "body": "正文", "takeOut": false }',
|
|
170
|
+
' ],',
|
|
171
|
+
' "effortOps": [',
|
|
172
|
+
' { "target": "lead 或子代理名(如 coder)", "effort": "off|low|medium|high|xhigh", "reason": "为何调整该模型思考强度" }',
|
|
132
173
|
' ],',
|
|
133
174
|
' "networkOps": [',
|
|
134
175
|
' { "op": "link|unlink", "targetSessionId": "目标独立会话ID或名称关键词" }',
|
|
@@ -136,8 +177,10 @@ const ASK_CHIEF_SYSTEM = [
|
|
|
136
177
|
'}',
|
|
137
178
|
'',
|
|
138
179
|
'宰相参谋与行事准则:',
|
|
139
|
-
'-
|
|
140
|
-
'-
|
|
180
|
+
'- 【懒介入与主会话优先铁律(严禁抢活越俎代庖)】:即使你已拥有高权限,也必须遏制亲自写代码或跑项目命令的冲动!凡是修改项目源码、跑构建测试、长程勘探排障,只要主对话在线可用且用户没有明确指定“参谋长你亲自来做/别找主对话”,一律优先放在 `"relays"` 中以正式执行请求形式交由 `@lead` 动手执行!只有用户点名直办、纯参谋内务(看板/档案/记忆/边界/物理墙草案)或主对话失联卡死时才亲自调工具。',
|
|
181
|
+
'- 【优先问询渠道(缺信息就问主对话,严禁瞎猜)】:无论是在自主调配还是回答用户问题时,只要缺乏代码细节或实时状态确认,请输出 `"inquiries"` 向 `@lead` 发出优先问询,主对话会在不打断手头动作的情况下原路快答。',
|
|
182
|
+
'- 【手搓动态物理墙与极低概率请示拆墙】:\n 1) 当用户让你“筑一堵物理墙/锁死某个目录或仓库/禁跑某个高危命令”时,直接将大白话诉求编译成 `"wallProposals"`(跨会话常驻设 `"scope": "global"`),呈交用户一键确认落锁;\n 2) **拆墙红线(极低触发)**:任何权限下(哪怕是 L3 最高权限)你都绝无权私拆或绕过物理驻墙!仅当主代理或子代理真实撞墙并确认无法绕过、向你上报阻断情况,且你独立复核确认确因该动态物理墙导致任务彻底无法推进、无合法替代路径时,才允许填入 `"wallRemovalProposals"` 向人类提交拆墙审批申请(硬安全内核规则永远不可申请拆除);平时一切情形严禁主动填 `"wallRemovalProposals"`。',
|
|
183
|
+
'- 【许愿框全权自治与三层档案隔离】:无论整理/分类/织钩/提炼档案入全局、`pin_to_desktop` 摆上认知桌面(2400 Tokens / 6 份上限)、`deliver_to_lead` 一次性向主对话递送关键档案、还是设定边界/重编任务、`effortOps` 调配主对话/子代理思考深度,只要符合当前权限,直接输出对应 JSON ops 执行到位。严禁触碰或读取冷藏档案柜(`precipitated` 100% 人类专属);严禁越级让本局档案直接跳级沉淀,必须遵循 `本局 -> 全局 -> 冷藏` 梯度。',
|
|
141
184
|
'- 【严守当前权限与禁止红线】:绝不越过当前权限等级上限,也绝不执行触发 `禁止红线 (forbidden)` 的写操作或高危命令。',
|
|
142
185
|
'- 【问进展 / 问步骤 / 问卡点 / 求建议】:当用户询问“现在在做什么 / 处于什么步骤 / 目前进度如何 / 卡在哪里”等态势问题时,你面前的上下文已经完整包含「实时对话流快照」+「小任务板 (Plan)」+「任务图」+「断点游标」!直接用简明人话分点作答并放进 JSON 的 `reply` 字段,**严禁退化成纯工具 XML/DSML 标签输出,更严禁盲目运行 `run_command` / `list_dir` 扫盘**!只有用户明确要求去核查具体源码文件/跑命令实测时,才在 JSON `toolCalls` 里调工具。',
|
|
143
186
|
'- 【代维护看板】:当用户让你「把某任务标为完成/受阻」「记一下下一步干啥」「改总目标」时,直接通过 `boardOps`(`task.update` / `cursor.set` / `objective.set` / `task.add`)落实(若强介入已锁定核心目标,则提示先解锁或关闭强介入)。',
|
|
@@ -159,8 +202,49 @@ const CONCISE_BRIEF_ASK_EXTRA = [
|
|
|
159
202
|
' - 【🧰 需要什么】一句话说明还需什么条件或验证',
|
|
160
203
|
' - 【🙋 用户需要提供什么】一句话说明需用户提供/拍板的内容(或“暂无需您额外提供”)',
|
|
161
204
|
' - 【💡 参谋长建议】一句话给出明确建议',
|
|
205
|
+
'- ⚠️ JSON 顶层结构铁律:上述六句话战报只能作为顶层合法 JSON 对象内 `"reply"` 字段的字符串值!绝不允许直接裸输出 Markdown!若用户要求手搓物理驻墙或提炼/总结工作边界(或你在回复中提出了要补充/禁用的红线或边界),必须同步将完整条目填入 `"wallProposals"` 与 `"boundProposals"` 数组(JSON 字符串内的正则反斜杠须写双反斜杠 `\\\\`)。',
|
|
206
|
+
].join('\n')
|
|
207
|
+
|
|
208
|
+
const CONSULT_CHIEF_EXTRA = [
|
|
209
|
+
'',
|
|
210
|
+
'💡 【当前为「参谋页面咨询(按需给建议)」模式 — 实事求是铁律】:',
|
|
211
|
+
'- 请结合当前任务进展、最近对话、工作边界与团队状态,在 `"reply"` 中坦诚给出真正有价值的观察、风险提醒或推进建议。',
|
|
212
|
+
'- 若当前推进顺利确实暂无建议,或用户关心的事项属于人类拍板/外部事务/非参谋与代理会话能管得了的范畴:**直接如实告诉用户就行!严禁为了凑动作而硬编 `"relays"`、`"boardOps"`、`"archiveOps"`、`"boundProposals"` 或执行建议,上述动作数组务必全部留空 `[]`**!',
|
|
213
|
+
'- 仅当确实存在可落地的具体动作建议时,才填入对应 JSON 字段,并严格遵守当前四级权限(L0 仅文本分析与必要提权申请,L1–L3 按对应权限审批/执行机制运行)。',
|
|
162
214
|
].join('\n')
|
|
163
215
|
|
|
216
|
+
function extractFallbackBoundProposalsFromText(rawText = '', userInput = '') {
|
|
217
|
+
const txt = String(rawText || '')
|
|
218
|
+
if (!txt.trim()) return []
|
|
219
|
+
const wantBounds = /boundProposals|提炼.*边界|总结.*边界|边界注入/i.test(String(userInput || ''))
|
|
220
|
+
|| /(?:提案\s*\d+|boundProposals)/i.test(txt)
|
|
221
|
+
if (!wantBounds) return []
|
|
222
|
+
const out = []
|
|
223
|
+
const seen = new Set()
|
|
224
|
+
for (const line of txt.split(/\r?\n/)) {
|
|
225
|
+
const clean = line.trim()
|
|
226
|
+
const m = clean.match(/^[-*•]?\s*【(?:提案\s*\d*[·::\s]*)?(红线|禁止红线|禁止|必做事项|必做|允许|注意事项|注意)[^】]*】\s*(.+)$/)
|
|
227
|
+
if (!m) continue
|
|
228
|
+
const kindWord = m[1]
|
|
229
|
+
const field = /必做|允许/.test(kindWord) ? 'allowed' : (/注意/.test(kindWord) ? 'notes' : 'forbidden')
|
|
230
|
+
const rawItem = m[2]
|
|
231
|
+
.replace(/[((]\s*(?:📌\s*)?(?:全局|本任务)[^))]*[))]\s*$/g, '')
|
|
232
|
+
.replace(/\s+/g, ' ')
|
|
233
|
+
.trim()
|
|
234
|
+
const item = clamp(rawItem, 220)
|
|
235
|
+
if (!item || seen.has(item)) continue
|
|
236
|
+
seen.add(item)
|
|
237
|
+
out.push({
|
|
238
|
+
field,
|
|
239
|
+
item,
|
|
240
|
+
pinGlobal: /📌|全局/.test(clean),
|
|
241
|
+
reason: '从参谋长提炼建议自动提取入审,请用户拍板确认。',
|
|
242
|
+
})
|
|
243
|
+
if (out.length >= 4) break
|
|
244
|
+
}
|
|
245
|
+
return out
|
|
246
|
+
}
|
|
247
|
+
|
|
164
248
|
const CONSOLIDATE_BOUNDS_SYSTEM = [
|
|
165
249
|
'你是「DSH 参谋长」(宰相级边界治理中枢)。用户的边界列表中积累了多条零散、重复或同一主题的规则。',
|
|
166
250
|
'请将给定的多条零散边界**浓缩合并成唯一 1 条**高信息密度、表述清晰、可直接执行的精炼总则(不超过 180 字)。',
|
|
@@ -345,6 +429,7 @@ export function applyBoardOps(deps, rootId, boardOps, opts = {}) {
|
|
|
345
429
|
if (!Array.isArray(boardOps) || !boardOps.length || !deps || typeof deps.runAction !== 'function') return executed
|
|
346
430
|
const forceSessionOnly = Boolean(opts && opts.forceSessionOnly)
|
|
347
431
|
const allowLockedObjectiveWrite = Boolean(opts && opts.allowLockedObjectiveWrite)
|
|
432
|
+
const callerOrigin = String((opts && opts.callerOrigin) || 'chief_llm')
|
|
348
433
|
const effCfg = resolveWorkspaceConfig(loadChiefState(), rootId)
|
|
349
434
|
const objectiveLocked = Boolean(effCfg && effCfg.tacticalModes && effCfg.tacticalModes.intervention) && !allowLockedObjectiveWrite
|
|
350
435
|
|
|
@@ -441,8 +526,9 @@ export function applyBoardOps(deps, rootId, boardOps, opts = {}) {
|
|
|
441
526
|
const col = ['forbidden', 'allowed', 'notes'].includes(normField) ? normField : ''
|
|
442
527
|
if (col && Array.isArray(opItem.items)) {
|
|
443
528
|
const items = opItem.items.map(x => clamp(x, 220)).filter(Boolean)
|
|
444
|
-
const res = deps.runAction({ action: 'bounds.set', field: col, items, session: rootId, by: 'chief' })
|
|
529
|
+
const res = deps.runAction({ action: 'bounds.set', field: col, items, session: rootId, by: 'chief', _callerOrigin: callerOrigin })
|
|
445
530
|
if (res && res.ok) executed.push(`覆写边界(${col})共 ${items.length} 条`)
|
|
531
|
+
else if (res && res.blockedBySafetyGuard) executed.push(`🛡️ 已拦截覆写红线(${col})`)
|
|
446
532
|
} else if (Array.isArray(opItem.allowed) || Array.isArray(opItem.must) || Array.isArray(opItem.forbidden) || Array.isArray(opItem.notes)) {
|
|
447
533
|
const allowList = Array.isArray(opItem.allowed) ? opItem.allowed : opItem.must
|
|
448
534
|
const res = deps.runAction({
|
|
@@ -452,8 +538,10 @@ export function applyBoardOps(deps, rootId, boardOps, opts = {}) {
|
|
|
452
538
|
...(Array.isArray(opItem.notes) ? { notes: opItem.notes.map(x => clamp(x, 220)).filter(Boolean) } : {}),
|
|
453
539
|
session: rootId,
|
|
454
540
|
by: 'chief',
|
|
541
|
+
_callerOrigin: callerOrigin,
|
|
455
542
|
})
|
|
456
543
|
if (res && res.ok) executed.push('重置边界列表')
|
|
544
|
+
else if (res && res.blockedBySafetyGuard) executed.push('🛡️ 已拦截批量覆写边界')
|
|
457
545
|
}
|
|
458
546
|
} else if ((op === 'bounds.forbid' || op === 'bounds.allow' || op === 'bounds.must' || op === 'bounds.note') && opItem.item) {
|
|
459
547
|
const field = op === 'bounds.forbid' ? 'forbidden' : (op === 'bounds.note' ? 'notes' : 'allowed')
|
|
@@ -468,9 +556,12 @@ export function applyBoardOps(deps, rootId, boardOps, opts = {}) {
|
|
|
468
556
|
pinned,
|
|
469
557
|
session: rootId,
|
|
470
558
|
by: 'chief',
|
|
559
|
+
_callerOrigin: callerOrigin,
|
|
471
560
|
})
|
|
472
561
|
if (res && res.ok) {
|
|
473
562
|
executed.push(`${pinned ? '📌全局' : '本任务'}${label}:${clamp(val, 30)}`)
|
|
563
|
+
} else if (res && res.blockedBySafetyGuard) {
|
|
564
|
+
executed.push(`🛡️ 已拦截写入边界(${field})`)
|
|
474
565
|
}
|
|
475
566
|
}
|
|
476
567
|
} else if (op === 'bounds.remove' && opItem.item) {
|
|
@@ -485,9 +576,12 @@ export function applyBoardOps(deps, rootId, boardOps, opts = {}) {
|
|
|
485
576
|
pinned,
|
|
486
577
|
session: rootId,
|
|
487
578
|
by: 'chief',
|
|
579
|
+
_callerOrigin: callerOrigin,
|
|
488
580
|
})
|
|
489
581
|
if (res && res.ok) {
|
|
490
582
|
executed.push(`移除边界:${clamp(val, 30)}`)
|
|
583
|
+
} else if (res && res.blockedBySafetyGuard) {
|
|
584
|
+
executed.push(`🛡️ 已拦截移除红线(${field})`)
|
|
491
585
|
}
|
|
492
586
|
}
|
|
493
587
|
}
|
|
@@ -500,52 +594,156 @@ export function applyBoardOps(deps, rootId, boardOps, opts = {}) {
|
|
|
500
594
|
* while strictly preserving the upward gradient (`session -> global -> precipitated`;
|
|
501
595
|
* direct session -> precipitated jump is forbidden).
|
|
502
596
|
*/
|
|
597
|
+
const MAIN_INJECT_ARCHIVE_OPS = new Set(['pin_to_desktop', 'unpin_from_desktop', 'take_out', 'put_back', 'deliver_to_lead'])
|
|
598
|
+
|
|
599
|
+
function normalizeArchiveOpName(rawOp) {
|
|
600
|
+
const s = String(rawOp || '').trim()
|
|
601
|
+
if (s === 'take_out') return 'pin_to_desktop'
|
|
602
|
+
if (s === 'put_back') return 'unpin_from_desktop'
|
|
603
|
+
return s
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function resolveItemIdForChiefScope(scope, rawId, rawTitle, { sessionOpt, globalOpt }) {
|
|
607
|
+
const idQ = String(rawId || '').trim()
|
|
608
|
+
const titleQ = String(rawTitle || '').trim().toLowerCase()
|
|
609
|
+
const opt = scope === 'global' ? globalOpt : sessionOpt
|
|
610
|
+
if (!opt) return idQ
|
|
611
|
+
const store = loadArchiveStore(opt)
|
|
612
|
+
const items = Array.isArray(store.items) ? store.items : []
|
|
613
|
+
if (idQ) {
|
|
614
|
+
const exact = items.find(it => it.id === idQ)
|
|
615
|
+
if (exact) return exact.id
|
|
616
|
+
}
|
|
617
|
+
if (titleQ) {
|
|
618
|
+
const byTitle = items.find(it => String(it.title || '').toLowerCase().includes(titleQ))
|
|
619
|
+
if (byTitle) return byTitle.id
|
|
620
|
+
}
|
|
621
|
+
return idQ
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Shared Chief executor for main-session archive injection ops (`pin_to_desktop`, `unpin_from_desktop`, `deliver_to_lead`)
|
|
626
|
+
* and `pull_global`, enforcing strict cold-vault isolation and dual-channel injection rules.
|
|
627
|
+
*/
|
|
628
|
+
export async function executeChiefArchiveInjectionOp(deps, rootId, opItem = {}, opts = {}) {
|
|
629
|
+
const sid = rootId && rootId !== 'global' ? String(rootId).trim() : ''
|
|
630
|
+
const op = normalizeArchiveOpName(opItem.op)
|
|
631
|
+
const scope = opItem.vaultScope === 'precipitated'
|
|
632
|
+
? 'precipitated'
|
|
633
|
+
: (opItem.vaultScope === 'global' ? 'global' : 'session')
|
|
634
|
+
if (scope === 'precipitated' || op === 'pull_precipitated') {
|
|
635
|
+
return { ok: false, blocked: true, error: '冷藏档案柜 100% 归属人类专属隔离,参谋无权读档或推送。' }
|
|
636
|
+
}
|
|
637
|
+
if (!sid) {
|
|
638
|
+
return { ok: false, error: '当前为空白未绑定会话,无法推上桌面或递送主对话。' }
|
|
639
|
+
}
|
|
640
|
+
const globalOpt = archiveTargetForRoot(deps, sid, { vaultScope: 'global' })
|
|
641
|
+
const sessionOpt = archiveTargetForRoot(deps, sid, { vaultScope: 'session' })
|
|
642
|
+
const hitId = resolveItemIdForChiefScope(scope, opItem.id || opItem.archiveId, opItem.title, { sessionOpt, globalOpt })
|
|
643
|
+
if (!hitId) {
|
|
644
|
+
return { ok: false, error: '未匹配到目标工程档案。' }
|
|
645
|
+
}
|
|
646
|
+
const targetOpt = scope === 'global' ? globalOpt : sessionOpt
|
|
647
|
+
|
|
648
|
+
if (op === 'pin_to_desktop' || op === 'unpin_from_desktop') {
|
|
649
|
+
const mOp = op === 'pin_to_desktop' ? 'pinToDesktop' : 'unpinFromDesktop'
|
|
650
|
+
const r = mutateArchive({
|
|
651
|
+
op: mOp,
|
|
652
|
+
vaultScope: scope,
|
|
653
|
+
rootSessionId: sid,
|
|
654
|
+
id: hitId,
|
|
655
|
+
by: opts.by || 'chief',
|
|
656
|
+
}, targetOpt)
|
|
657
|
+
if (!r || !r.ok) {
|
|
658
|
+
return { ok: false, error: (r && r.error) || '桌面调配失败' }
|
|
659
|
+
}
|
|
660
|
+
const ev = Array.isArray(r.evicted) && r.evicted.length > 0 ? `(超 2400 Tokens/6 份自动撤回:${r.evicted.map(x => `《${clamp(x.title, 18)}》`).join('、')})` : ''
|
|
661
|
+
const actionText = `${op === 'pin_to_desktop' ? '📌 摆上桌面' : '撤出桌面'} #${hitId}${ev}`
|
|
662
|
+
return { ok: true, op, scope, id: hitId, evicted: r.evicted || [], actionText }
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (op === 'deliver_to_lead') {
|
|
666
|
+
const det = getArchiveDetail(hitId, sid, targetOpt)
|
|
667
|
+
if (!det || !det.ok || !det.item) {
|
|
668
|
+
return { ok: false, error: '未读取到待递送档案内容' }
|
|
669
|
+
}
|
|
670
|
+
const it = det.item
|
|
671
|
+
const ptLines = Array.isArray(it.points) && it.points.length > 0
|
|
672
|
+
? it.points.slice(0, 5).map(pt => `- ${pt.title}:${clamp(pt.detail || pt.cue, 180)}`)
|
|
673
|
+
: []
|
|
674
|
+
const instr = cleanMultiline(opItem.instruction || opItem.note || '', 240)
|
|
675
|
+
const msgBody = [
|
|
676
|
+
`[DSH 参谋长档案馆 · 一次性重点递送(不占桌面置顶槽)]`,
|
|
677
|
+
`来源:${scope === 'global' ? '🌐 全局档案柜(参谋核准后专递)' : '🗂️ 本局档案柜'} · 《${clamp(it.title, 48)}》 (id=${it.id})`,
|
|
678
|
+
instr ? `参谋附言:${instr}` : '',
|
|
679
|
+
it.summary ? `提要:${clamp(it.summary, 200)}` : '',
|
|
680
|
+
...(ptLines.length ? ['核心要点:', ...ptLines] : []),
|
|
681
|
+
!ptLines.length && it.body ? `正文节选:\n${clamp(it.body, 900)}` : '',
|
|
682
|
+
].filter(Boolean).join('\n')
|
|
683
|
+
|
|
684
|
+
const deliverTarget = String(opItem.target || 'lead').trim() || 'lead'
|
|
685
|
+
const deliv = await deliverCrossMessage(deps, {
|
|
686
|
+
fromSession: sid,
|
|
687
|
+
fromLabel: opts.byLabel || 'DSH 参谋长 (档案馆重点递送)',
|
|
688
|
+
target: deliverTarget,
|
|
689
|
+
subject: `档案馆递送《${clamp(it.title, 28)}》`,
|
|
690
|
+
text: msgBody,
|
|
691
|
+
mode: 'steer',
|
|
692
|
+
envelopeKind: 'execution_request',
|
|
693
|
+
recordBoardLog: true,
|
|
694
|
+
})
|
|
695
|
+
mutateArchive({ op: 'markDeliveredToLead', vaultScope: scope, rootSessionId: sid, id: hitId }, targetOpt)
|
|
696
|
+
return {
|
|
697
|
+
ok: Boolean(deliv && deliv.ok),
|
|
698
|
+
op,
|
|
699
|
+
scope,
|
|
700
|
+
id: hitId,
|
|
701
|
+
delivery: deliv,
|
|
702
|
+
actionText: deliv && deliv.ok
|
|
703
|
+
? `📨 递送档案《${clamp(it.title, 20)}》→ ${deliv.target || deliverTarget}`
|
|
704
|
+
: `递送失败:${(deliv && deliv.error) || '目标不可达'}`,
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
if (op === 'pull_global') {
|
|
709
|
+
const r = mutateArchive({ op: 'pullByChief', vaultScope: 'global', rootSessionId: sid, id: hitId }, globalOpt)
|
|
710
|
+
if (r && r.ok) {
|
|
711
|
+
return { ok: true, op, scope: 'global', id: hitId, actionText: `👁️ 参谋拉阅全局档案 #${hitId}` }
|
|
712
|
+
}
|
|
713
|
+
return { ok: false, error: (r && r.error) || '全局拉阅失败' }
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
return { ok: false, error: `不支持的档案注入指令:${op}` }
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Execute Wishing-Box `archiveOps` requested by user in natural language (`整理`/`提炼入全局`/内务操作),
|
|
721
|
+
* strictly enforcing cold-vault 0-byte isolation (`precipitated` blocked) and upward gradient (`session -> global -> precipitated`).
|
|
722
|
+
*/
|
|
503
723
|
async function applyArchiveOps(deps, rootId, archiveOps, ctx = {}) {
|
|
504
724
|
const executed = []
|
|
505
725
|
if (!Array.isArray(archiveOps) || !archiveOps.length) return { executed, changed: false }
|
|
506
726
|
const sid = rootId && rootId !== 'global' ? String(rootId).trim() : ''
|
|
507
727
|
const globalOpt = archiveTargetForRoot(deps, sid || 'global', { vaultScope: 'global' })
|
|
508
728
|
const sessionOpt = sid ? archiveTargetForRoot(deps, sid, { vaultScope: 'session' }) : null
|
|
509
|
-
const projectKey = resolveProjectKey(globalOpt.cwd)
|
|
510
729
|
let changed = false
|
|
511
730
|
|
|
512
|
-
const resolveItemInScope = (scope, rawId, rawTitle) =>
|
|
513
|
-
|
|
514
|
-
const titleQ = String(rawTitle || '').trim().toLowerCase()
|
|
515
|
-
if (scope === 'precipitated') {
|
|
516
|
-
const items = listPrecipitatedHeaders(projectKey, sid, globalOpt) || []
|
|
517
|
-
if (idQ) {
|
|
518
|
-
const exact = items.find(it => it.id === idQ)
|
|
519
|
-
if (exact) return exact.id
|
|
520
|
-
}
|
|
521
|
-
if (titleQ) {
|
|
522
|
-
const byTitle = items.find(it => String(it.title || '').toLowerCase().includes(titleQ))
|
|
523
|
-
if (byTitle) return byTitle.id
|
|
524
|
-
}
|
|
525
|
-
return idQ
|
|
526
|
-
}
|
|
527
|
-
const opt = scope === 'global' ? globalOpt : sessionOpt
|
|
528
|
-
if (!opt) return idQ
|
|
529
|
-
const store = loadArchiveStore(opt)
|
|
530
|
-
const items = Array.isArray(store.items) ? store.items : []
|
|
531
|
-
if (idQ) {
|
|
532
|
-
const exact = items.find(it => it.id === idQ)
|
|
533
|
-
if (exact) return exact.id
|
|
534
|
-
}
|
|
535
|
-
if (titleQ) {
|
|
536
|
-
const byTitle = items.find(it => String(it.title || '').toLowerCase().includes(titleQ))
|
|
537
|
-
if (byTitle) return byTitle.id
|
|
538
|
-
}
|
|
539
|
-
return idQ
|
|
540
|
-
}
|
|
731
|
+
const resolveItemInScope = (scope, rawId, rawTitle) =>
|
|
732
|
+
resolveItemIdForChiefScope(scope, rawId, rawTitle, { sessionOpt, globalOpt })
|
|
541
733
|
|
|
542
734
|
for (const opItem of archiveOps.slice(0, 8)) {
|
|
543
735
|
if (!opItem || typeof opItem !== 'object') continue
|
|
544
|
-
const op =
|
|
736
|
+
const op = normalizeArchiveOpName(opItem.op)
|
|
545
737
|
const scope = opItem.vaultScope === 'precipitated'
|
|
546
738
|
? 'precipitated'
|
|
547
739
|
: (opItem.vaultScope === 'global' ? 'global' : 'session')
|
|
548
740
|
|
|
741
|
+
// Cold vault (`precipitated`) is 100% human-only: Chief may never inspect, pin, or pull from it.
|
|
742
|
+
if (scope === 'precipitated' || op === 'pull_precipitated') {
|
|
743
|
+
executed.push('🧊 已拦截:冷藏档案柜仅人类可见,参谋无权读取或调取')
|
|
744
|
+
continue
|
|
745
|
+
}
|
|
746
|
+
|
|
549
747
|
if (op === 'organize') {
|
|
550
748
|
const orgScope = opItem.vaultScope === 'global' ? 'global' : 'session'
|
|
551
749
|
if (orgScope === 'session' && !sid) continue
|
|
@@ -571,10 +769,16 @@ async function applyArchiveOps(deps, rootId, archiveOps, ctx = {}) {
|
|
|
571
769
|
changed = true
|
|
572
770
|
executed.push(`提炼入全局 ×${r.createdCount ?? 0}`)
|
|
573
771
|
}
|
|
772
|
+
} else if (op === 'pull_global') {
|
|
773
|
+
const r = await executeChiefArchiveInjectionOp(deps, rootId, { ...opItem, op: 'pull_global', vaultScope: 'global' })
|
|
774
|
+
if (r && r.ok) {
|
|
775
|
+
changed = true
|
|
776
|
+
executed.push(r.actionText)
|
|
777
|
+
}
|
|
574
778
|
} else if (op === 'save' || op === 'create') {
|
|
575
|
-
if (scope === 'precipitated') continue // strict gradient: cannot write directly into precipitated
|
|
576
779
|
if (scope === 'session' && !sid) continue
|
|
577
780
|
const targetOpt = scope === 'global' ? globalOpt : sessionOpt
|
|
781
|
+
const allowPin = Boolean(opItem.takeOut) && optsTakeOutAllowed(ctx)
|
|
578
782
|
const r = mutateArchive({
|
|
579
783
|
op: 'save',
|
|
580
784
|
vaultScope: scope,
|
|
@@ -584,37 +788,19 @@ async function applyArchiveOps(deps, rootId, archiveOps, ctx = {}) {
|
|
|
584
788
|
title: clamp(opItem.title || '参谋长工作归档', 160),
|
|
585
789
|
summary: clamp(opItem.summary || '', 400),
|
|
586
790
|
body: cleanMultiline(opItem.body || opItem.summary || opItem.title || '', 12000),
|
|
587
|
-
takeOutNow:
|
|
791
|
+
takeOutNow: allowPin,
|
|
792
|
+
organizedBy: 'chief',
|
|
588
793
|
by: 'chief',
|
|
589
794
|
}, targetOpt)
|
|
590
795
|
if (r && r.ok) {
|
|
591
796
|
changed = true
|
|
592
797
|
executed.push(`存档(${scope === 'global' ? '全局' : '本局'}):《${clamp(opItem.title || '', 24)}》`)
|
|
593
798
|
}
|
|
594
|
-
} else if (op === '
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const pOp = op === 'take_out' ? 'flipOut' : 'sealBack'
|
|
600
|
-
const r = mutatePrecipitated(projectKey, { op: pOp, id: hitId, rootSessionId: sid }, { ...globalOpt, rootSessionId: sid })
|
|
601
|
-
if (r && r.ok) {
|
|
602
|
-
updateWorkspaceFlippedIds(sid, pOp === 'flipOut' ? { flippedId: hitId } : { sealId: hitId })
|
|
603
|
-
changed = true
|
|
604
|
-
executed.push(`${op === 'take_out' ? '摆上桌面(沉淀)' : '放回封存(沉淀)'} #${hitId}`)
|
|
605
|
-
}
|
|
606
|
-
} else {
|
|
607
|
-
const targetOpt = scope === 'global' ? globalOpt : sessionOpt
|
|
608
|
-
const r = mutateArchive({
|
|
609
|
-
op: op === 'take_out' ? 'takeOut' : 'putBack',
|
|
610
|
-
vaultScope: scope,
|
|
611
|
-
rootSessionId: sid,
|
|
612
|
-
id: hitId,
|
|
613
|
-
}, targetOpt)
|
|
614
|
-
if (r && r.ok) {
|
|
615
|
-
changed = true
|
|
616
|
-
executed.push(`${op === 'take_out' ? '摆上桌面' : '放回封存'} #${hitId}`)
|
|
617
|
-
}
|
|
799
|
+
} else if (op === 'pin_to_desktop' || op === 'unpin_from_desktop' || op === 'deliver_to_lead') {
|
|
800
|
+
const r = await executeChiefArchiveInjectionOp(deps, rootId, opItem, ctx)
|
|
801
|
+
if (r && r.ok) {
|
|
802
|
+
changed = true
|
|
803
|
+
executed.push(r.actionText)
|
|
618
804
|
}
|
|
619
805
|
} else if (op === 'mount_chief' || op === 'unmount_chief') {
|
|
620
806
|
if (!sid) continue
|
|
@@ -648,23 +834,7 @@ async function applyArchiveOps(deps, rootId, archiveOps, ctx = {}) {
|
|
|
648
834
|
changed = true
|
|
649
835
|
executed.push(`全局调入本局 #${hitId}`)
|
|
650
836
|
}
|
|
651
|
-
} else if (op === 'pull_precipitated') {
|
|
652
|
-
const targetScope = opItem.targetScope === 'global' ? 'global' : 'session'
|
|
653
|
-
if (targetScope === 'session' && !sid) continue
|
|
654
|
-
const hitId = resolveItemInScope('precipitated', opItem.id || opItem.archiveId, opItem.title)
|
|
655
|
-
if (!hitId) continue
|
|
656
|
-
const r = copyPrecipitatedToVault(projectKey, {
|
|
657
|
-
id: hitId,
|
|
658
|
-
targetScope,
|
|
659
|
-
rootSessionId: sid,
|
|
660
|
-
takeOutNow: Boolean(opItem.takeOut),
|
|
661
|
-
}, { ...globalOpt, rootSessionId: sid })
|
|
662
|
-
if (r && r.ok) {
|
|
663
|
-
changed = true
|
|
664
|
-
executed.push(`沉淀无损调入${targetScope === 'global' ? '全局' : '本局'} #${hitId}`)
|
|
665
|
-
}
|
|
666
837
|
} else if (op === 'move_folder' && opItem.folder) {
|
|
667
|
-
if (scope === 'precipitated') continue
|
|
668
838
|
if (scope === 'session' && !sid) continue
|
|
669
839
|
const targetOpt = scope === 'global' ? globalOpt : sessionOpt
|
|
670
840
|
const hitId = resolveItemInScope(scope, opItem.id || opItem.archiveId, opItem.title)
|
|
@@ -675,7 +845,6 @@ async function applyArchiveOps(deps, rootId, archiveOps, ctx = {}) {
|
|
|
675
845
|
executed.push(`移动档案分类 → ${opItem.folder}`)
|
|
676
846
|
}
|
|
677
847
|
} else if (op === 'delete' || op === 'remove') {
|
|
678
|
-
if (scope === 'precipitated') continue
|
|
679
848
|
if (scope === 'session' && !sid) continue
|
|
680
849
|
const targetOpt = scope === 'global' ? globalOpt : sessionOpt
|
|
681
850
|
const hitId = resolveItemInScope(scope, opItem.id || opItem.archiveId, opItem.title)
|
|
@@ -691,6 +860,10 @@ async function applyArchiveOps(deps, rootId, archiveOps, ctx = {}) {
|
|
|
691
860
|
return { executed, changed }
|
|
692
861
|
}
|
|
693
862
|
|
|
863
|
+
function optsTakeOutAllowed(ctx) {
|
|
864
|
+
return Boolean(ctx && ctx.allowPinToDesktop !== false)
|
|
865
|
+
}
|
|
866
|
+
|
|
694
867
|
/** Execute Wishing-Box `networkOps` to link or unlink standalone DSH sessions. */
|
|
695
868
|
function applyNetworkOps(rootId, networkOps, directory) {
|
|
696
869
|
const executed = []
|
|
@@ -994,79 +1167,89 @@ export async function consolidateBoundsWithChief(deps, {
|
|
|
994
1167
|
}
|
|
995
1168
|
}
|
|
996
1169
|
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
''
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1170
|
+
const consWorkId = beginChiefActiveWork(rootId, {
|
|
1171
|
+
tone: 'bounds',
|
|
1172
|
+
tab: 'boundaries',
|
|
1173
|
+
boundSubTab: 'rules',
|
|
1174
|
+
label: '参谋长正在浓缩边界中...',
|
|
1175
|
+
})
|
|
1176
|
+
try {
|
|
1177
|
+
const createdProposals = []
|
|
1178
|
+
for (const { col, sourceItems } of targetCols) {
|
|
1179
|
+
const colLabel = BOUND_COL_LABEL[col] || '禁止红线'
|
|
1180
|
+
const hadPinned = sourceItems.some(x => (pinnedBounds[col] || []).includes(x))
|
|
1181
|
+
const prompt = [
|
|
1182
|
+
`目标边界分栏:【${colLabel}】(${col})`,
|
|
1183
|
+
instruction ? `用户额外要求:${clamp(instruction, 200)}` : '',
|
|
1184
|
+
`待浓缩合并的 ${sourceItems.length} 条零散边界:`,
|
|
1185
|
+
...sourceItems.map((it, idx) => `${idx + 1}. ${(pinnedBounds[col] || []).includes(it) ? '[📌全局定住] ' : ''}${it}`),
|
|
1186
|
+
'',
|
|
1187
|
+
'请将以上零散规则浓缩合并为唯一 1 条高密度总则(保留具体命令、路径与硬红线),只输出 JSON:',
|
|
1188
|
+
].filter(Boolean).join('\n')
|
|
1189
|
+
|
|
1190
|
+
const llmRes = await callChiefLlm(deps, {
|
|
1191
|
+
sessionId: rootId,
|
|
1192
|
+
system: CONSOLIDATE_BOUNDS_SYSTEM,
|
|
1193
|
+
prompt,
|
|
1194
|
+
maxTokens: SUMMARY_MAX_TOKENS,
|
|
1195
|
+
})
|
|
1016
1196
|
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1197
|
+
const parsed = llmRes.ok ? extractJsonObject(llmRes.text) : null
|
|
1198
|
+
const mergedText = clamp(
|
|
1199
|
+
(parsed && (parsed.item || parsed.draftText || parsed.text)) || deterministicConsolidateClauses(sourceItems),
|
|
1200
|
+
220,
|
|
1201
|
+
)
|
|
1202
|
+
const mergedReason = clamp(
|
|
1203
|
+
(parsed && parsed.reason) || `已将【${colLabel}】下 ${sourceItems.length} 条零散边界浓缩合成为 1 条总则,批准后自动替换原零散条目。`,
|
|
1204
|
+
180,
|
|
1205
|
+
)
|
|
1026
1206
|
|
|
1027
|
-
|
|
1207
|
+
if (!mergedText || secretLike(mergedText)) continue
|
|
1028
1208
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1209
|
+
mutateChiefState((s) => {
|
|
1210
|
+
const ws = ensureWorkspace(s, rootId)
|
|
1211
|
+
// Dismiss older pending consolidation proposals for the exact same column to avoid clutter
|
|
1212
|
+
for (const existing of ws.suggestions) {
|
|
1213
|
+
if (existing.status === 'pending' && existing.kind === 'bound' && existing.boundField === col && Array.isArray(existing.replaces) && existing.replaces.length > 0) {
|
|
1214
|
+
existing.status = 'dismissed'
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
const sug = normalizeSuggestion({
|
|
1218
|
+
kind: 'bound',
|
|
1219
|
+
boundField: col,
|
|
1220
|
+
fromAgent: '✦ 参谋长浓缩',
|
|
1221
|
+
title: `${colLabel} ${sourceItems.length} 合 1:${clamp(mergedText, 26)}`,
|
|
1222
|
+
reason: mergedReason,
|
|
1223
|
+
target: 'bounds',
|
|
1224
|
+
targetLabel: colLabel,
|
|
1225
|
+
mode: 'silent',
|
|
1226
|
+
draftText: mergedText,
|
|
1227
|
+
replaces: sourceItems,
|
|
1228
|
+
pinGlobal: hadPinned,
|
|
1229
|
+
})
|
|
1230
|
+
if (sug) {
|
|
1231
|
+
ws.suggestions.push(sug)
|
|
1232
|
+
createdProposals.push(sug)
|
|
1035
1233
|
}
|
|
1036
|
-
}
|
|
1037
|
-
const sug = normalizeSuggestion({
|
|
1038
|
-
kind: 'bound',
|
|
1039
|
-
boundField: col,
|
|
1040
|
-
fromAgent: '✦ 参谋长浓缩',
|
|
1041
|
-
title: `${colLabel} ${sourceItems.length} 合 1:${clamp(mergedText, 26)}`,
|
|
1042
|
-
reason: mergedReason,
|
|
1043
|
-
target: 'bounds',
|
|
1044
|
-
targetLabel: colLabel,
|
|
1045
|
-
mode: 'silent',
|
|
1046
|
-
draftText: mergedText,
|
|
1047
|
-
replaces: sourceItems,
|
|
1048
|
-
pinGlobal: hadPinned,
|
|
1049
1234
|
})
|
|
1050
|
-
|
|
1051
|
-
ws.suggestions.push(sug)
|
|
1052
|
-
createdProposals.push(sug)
|
|
1053
|
-
}
|
|
1054
|
-
})
|
|
1055
|
-
}
|
|
1235
|
+
}
|
|
1056
1236
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1237
|
+
if (!createdProposals.length) {
|
|
1238
|
+
return { ok: false, error: '未能生成浓缩边界,请稍后重试。' }
|
|
1239
|
+
}
|
|
1060
1240
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1241
|
+
const replyLines = createdProposals.map(p =>
|
|
1242
|
+
`- 【${p.targetLabel} · ${p.replaces.length} 合 1】${p.draftText}(可在上方请示卡片选「📌 定住全局」或「仅本任务」一键替换)`,
|
|
1243
|
+
)
|
|
1064
1244
|
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1245
|
+
return {
|
|
1246
|
+
ok: true,
|
|
1247
|
+
proposals: createdProposals,
|
|
1248
|
+
reply: replyLines.join('\n'),
|
|
1249
|
+
view: await getChiefView(deps, rootId, { autoSummarize: false }),
|
|
1250
|
+
}
|
|
1251
|
+
} finally {
|
|
1252
|
+
endChiefActiveWork(rootId, consWorkId)
|
|
1070
1253
|
}
|
|
1071
1254
|
}
|
|
1072
1255
|
|
|
@@ -1075,8 +1258,11 @@ export async function askOrCommandChief(deps, {
|
|
|
1075
1258
|
text = '',
|
|
1076
1259
|
forcedTarget = '',
|
|
1077
1260
|
forcedMode = 'steer',
|
|
1261
|
+
quickAction = '',
|
|
1078
1262
|
images = [],
|
|
1079
1263
|
_resumeCtx = null,
|
|
1264
|
+
_fromLeadRequest = false,
|
|
1265
|
+
_wallBlockerEscalation = false,
|
|
1080
1266
|
}) {
|
|
1081
1267
|
const rawInput = cleanMultiline(text, 2000)
|
|
1082
1268
|
const rawImages = Array.isArray(images) ? images : []
|
|
@@ -1114,6 +1300,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1114
1300
|
const board = deps.boardForSession(deps.boardFileFor(rootId))
|
|
1115
1301
|
const state = loadChiefState()
|
|
1116
1302
|
const effCfg = resolveWorkspaceConfig(state, rootId)
|
|
1303
|
+
const policyPlugins = Array.isArray(effCfg.policyPlugins) ? effCfg.policyPlugins : []
|
|
1117
1304
|
const ownWs = ensureWorkspace(state, rootId)
|
|
1118
1305
|
const hasChiefRiskAck = hasValidChiefRiskAck(ownWs)
|
|
1119
1306
|
const permissionMode = normalizePermissionMode(effCfg.permissionMode || DEFAULT_CHIEF_PERMISSION_MODE, {
|
|
@@ -1135,13 +1322,15 @@ export async function askOrCommandChief(deps, {
|
|
|
1135
1322
|
pendingApprovalList = [],
|
|
1136
1323
|
target = '',
|
|
1137
1324
|
forceReceipt = false,
|
|
1325
|
+
thinkingEffort = '',
|
|
1326
|
+
thinkingEffortMode = '',
|
|
1138
1327
|
}) => {
|
|
1139
1328
|
const cleanActions = Array.isArray(actions) ? actions.filter(Boolean) : []
|
|
1140
|
-
const isReceipt = Boolean(isResumeTurn || forceReceipt || elevationObj || pendingApprovalList.length > 0 || cleanActions.length > 0)
|
|
1329
|
+
const isReceipt = Boolean(isResumeTurn || _fromLeadRequest || forceReceipt || elevationObj || pendingApprovalList.length > 0 || cleanActions.length > 0)
|
|
1141
1330
|
const finalActions = isResumeTurn
|
|
1142
1331
|
? [...new Set(['⚡ 授权自动续跑', ...cleanActions])].slice(0, 8)
|
|
1143
1332
|
: cleanActions.slice(0, 8)
|
|
1144
|
-
if (!isResumeTurn) {
|
|
1333
|
+
if (!isResumeTurn && !_fromLeadRequest) {
|
|
1145
1334
|
ws.chat.push({
|
|
1146
1335
|
id: nextId('chat'),
|
|
1147
1336
|
role: 'user',
|
|
@@ -1155,13 +1344,24 @@ export async function askOrCommandChief(deps, {
|
|
|
1155
1344
|
let attachedTaskId = resumeTaskId
|
|
1156
1345
|
if (canAttachResume && (elevationObj || pendingApprovalList.length > 0)) {
|
|
1157
1346
|
const aprIds = pendingApprovalList.map(a => a && a.id).filter(Boolean)
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1347
|
+
const primaryApr = pendingApprovalList.find(Boolean) || null
|
|
1348
|
+
const task = upsertTaskLedgerOnWs(ws, {
|
|
1349
|
+
...(resumeTaskId ? { id: resumeTaskId, taskId: resumeTaskId } : {}),
|
|
1350
|
+
kind: aprIds.length > 0 ? 'approval_resume' : 'elevation_resume',
|
|
1160
1351
|
status: aprIds.length > 0 ? 'awaiting_approval' : 'awaiting_elevation',
|
|
1352
|
+
capabilityScope: primaryApr && primaryApr.capabilityScope ? primaryApr.capabilityScope : null,
|
|
1353
|
+
payloadHash: primaryApr && primaryApr.payloadHash ? primaryApr.payloadHash : '',
|
|
1354
|
+
resumeSpec: {
|
|
1355
|
+
originalText: input,
|
|
1356
|
+
forcedTarget,
|
|
1357
|
+
forcedMode,
|
|
1358
|
+
savedImagePaths,
|
|
1359
|
+
},
|
|
1161
1360
|
originalText: input,
|
|
1162
1361
|
forcedTarget,
|
|
1163
1362
|
forcedMode,
|
|
1164
1363
|
savedImagePaths,
|
|
1364
|
+
retryCount: resumeDepth,
|
|
1165
1365
|
resumeDepth,
|
|
1166
1366
|
elevationId: elevationObj ? elevationObj.id : '',
|
|
1167
1367
|
pendingApprovalIds: aprIds,
|
|
@@ -1170,9 +1370,11 @@ export async function askOrCommandChief(deps, {
|
|
|
1170
1370
|
if (task) {
|
|
1171
1371
|
attachedTaskId = task.id
|
|
1172
1372
|
if (elevationObj) {
|
|
1373
|
+
elevationObj.taskId = task.id
|
|
1173
1374
|
elevationObj.resumeTaskId = task.id
|
|
1174
1375
|
if (task.expiresAt) elevationObj.expiresAt = task.expiresAt
|
|
1175
1376
|
if (ws.pendingElevation && ws.pendingElevation.id === elevationObj.id) {
|
|
1377
|
+
ws.pendingElevation.taskId = task.id
|
|
1176
1378
|
ws.pendingElevation.resumeTaskId = task.id
|
|
1177
1379
|
if (task.expiresAt) ws.pendingElevation.expiresAt = task.expiresAt
|
|
1178
1380
|
}
|
|
@@ -1183,6 +1385,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1183
1385
|
if (!Array.isArray(listRef)) continue
|
|
1184
1386
|
for (const apr of listRef) {
|
|
1185
1387
|
if (apr && idSet.has(apr.id)) {
|
|
1388
|
+
apr.taskId = task.id
|
|
1186
1389
|
apr.resumeTaskId = task.id
|
|
1187
1390
|
if (task.expiresAt && !apr.expiresAt) apr.expiresAt = task.expiresAt
|
|
1188
1391
|
}
|
|
@@ -1196,6 +1399,8 @@ export async function askOrCommandChief(deps, {
|
|
|
1196
1399
|
role: 'chief',
|
|
1197
1400
|
kind: isReceipt ? 'receipt' : 'qa',
|
|
1198
1401
|
...(attachedTaskId ? { resumeTaskId: attachedTaskId } : {}),
|
|
1402
|
+
...(thinkingEffort ? { thinkingEffort } : {}),
|
|
1403
|
+
...(thinkingEffortMode ? { thinkingEffortMode } : {}),
|
|
1199
1404
|
text: chiefText,
|
|
1200
1405
|
actions: finalActions,
|
|
1201
1406
|
at: Date.now(),
|
|
@@ -1277,7 +1482,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1277
1482
|
savedImagePaths,
|
|
1278
1483
|
memoryChanges: [],
|
|
1279
1484
|
boardOps: [],
|
|
1280
|
-
view: await getChiefView(deps, rootId, { autoSummarize: false }),
|
|
1485
|
+
view: await getChiefView(deps, rootId, { autoSummarize: false, chatTriggered: !_fromLeadRequest }),
|
|
1281
1486
|
}
|
|
1282
1487
|
}
|
|
1283
1488
|
|
|
@@ -1349,39 +1554,48 @@ export async function askOrCommandChief(deps, {
|
|
|
1349
1554
|
}
|
|
1350
1555
|
}
|
|
1351
1556
|
|
|
1352
|
-
// Watch
|
|
1557
|
+
// Watch session & hooked global archives in background (cold vault is 100% isolated from Chief & Lead!)
|
|
1353
1558
|
const visibleArchives = collectChiefVisibleArchives(deps, rootId, state)
|
|
1354
1559
|
const watchLines = []
|
|
1355
|
-
const fmtWatchTag = (label, it) => `[${label}${it.id ? ` | id=${it.id}` : ''}] 《${clamp(it.title, 36)}》:${clamp(it.summary, 80)}`
|
|
1560
|
+
const fmtWatchTag = (label, it) => `[${label}${it.id ? ` | id=${it.id}` : ''}] 《${clamp(it.title, 36)}》:${clamp(it.summary || it.hookCue, 80)}`
|
|
1356
1561
|
const watchEntries = [
|
|
1357
|
-
...visibleArchives.deskSessionItems.map(it => fmtWatchTag('桌面·本局(
|
|
1358
|
-
...visibleArchives.deskGlobalItems.map(it => fmtWatchTag('桌面·全局(
|
|
1359
|
-
...visibleArchives.deskFlippedItems.map(it => fmtWatchTag('
|
|
1360
|
-
...visibleArchives.mountedGlobalItems.map(it => fmtWatchTag('
|
|
1361
|
-
...((visibleArchives.
|
|
1362
|
-
...((visibleArchives.
|
|
1363
|
-
...((visibleArchives.
|
|
1562
|
+
...visibleArchives.deskSessionItems.map(it => fmtWatchTag('桌面·本局(主与参谋共阅)', it)),
|
|
1563
|
+
...visibleArchives.deskGlobalItems.map(it => fmtWatchTag('桌面·全局(主与参谋共阅)', it)),
|
|
1564
|
+
...visibleArchives.deskFlippedItems.map(it => fmtWatchTag('桌面·冷藏已翻牌(主与参谋共阅)', it)),
|
|
1565
|
+
...visibleArchives.mountedGlobalItems.map(it => fmtWatchTag('全局已拉阅·主隐', it)),
|
|
1566
|
+
...((visibleArchives.sessionItems || []).filter(it => !it.takenOut).slice(0, 8).map(it => `[本局档案·参谋随时可读${it.hasHook ? ' 🪝已织钩' : ' (未织钩)'} | id=${it.id}] 《${clamp(it.title, 36)}》:${clamp(it.summary, 70)}`)),
|
|
1567
|
+
...((visibleArchives.recentlyUnpinnedWatch || []).slice(0, 4).map(w => `[刚撤下桌面·待观察归位 | id=${w.id}] 《${clamp(w.title, 36)}》`)),
|
|
1568
|
+
...((visibleArchives.globalHookIndex || []).slice(0, 8).map(it => `[全局钩子·参谋见钩可拉(发 pull_global) | id=${it.id}] 《${clamp(it.title, 36)}》 🪝[${(it.hookKeywords || []).slice(0, 3).join('·')}] ${clamp(it.hookCue, 60)}`)),
|
|
1364
1569
|
]
|
|
1365
1570
|
if (watchEntries.length > 0) {
|
|
1366
|
-
watchLines.push('', '## 9.
|
|
1571
|
+
watchLines.push('', '## 9. 参谋长档案馆线索与认知桌面(冷库严密隔离;桌面主对话可见;全局仅暴露已织钩子)', ...watchEntries.map(x => '- ' + x))
|
|
1367
1572
|
}
|
|
1368
1573
|
|
|
1369
|
-
// On-demand lazy archive lookup ONLY when the user explicitly asks Chief about archives (
|
|
1370
|
-
const asksArchiveExplicitly = /(
|
|
1574
|
+
// On-demand lazy archive lookup ONLY when the user explicitly asks Chief about archives (searches Session + Hooked Global Vault; unhooked Global/Cold blocked)
|
|
1575
|
+
const asksArchiveExplicitly = /(?:档案|卷宗|归档|以前|历史记录|工程坐标|老笔记|全局|查一下.*(?:怎么|路径|命令|配置))/.test(input)
|
|
1371
1576
|
const onDemandArchiveLines = []
|
|
1372
1577
|
if (asksArchiveExplicitly) {
|
|
1373
1578
|
const sessionTarget = rootId && rootId !== 'global' ? archiveTargetForRoot(deps, rootId, { vaultScope: 'session' }) : null
|
|
1374
1579
|
const globalTarget = archiveTargetForRoot(deps, rootId, { vaultScope: 'global' })
|
|
1375
1580
|
const foundSess = sessionTarget ? searchArchives(input, { limit: 3, vaultScope: 'session' }, sessionTarget) : { ok: true, hits: [] }
|
|
1376
|
-
const
|
|
1581
|
+
const foundGlobRaw = searchGlobalVaultForChief(input, { limit: 5 }, globalTarget)
|
|
1582
|
+
const pulledOrDeskGlobIds = new Set([
|
|
1583
|
+
...(visibleArchives.mountedGlobalItems || []).map(x => x.id),
|
|
1584
|
+
...(visibleArchives.deskGlobalItems || []).map(x => x.id),
|
|
1585
|
+
])
|
|
1586
|
+
const foundGlobHits = (Array.isArray(foundGlobRaw.hits) ? foundGlobRaw.hits : []).filter(h => h && h.hasHook === true).slice(0, 3)
|
|
1377
1587
|
const combinedHits = [
|
|
1378
|
-
...(Array.isArray(foundSess.hits) ? foundSess.hits.map(h => ({ ...h, _scopeLabel: '本会话档案', _target: sessionTarget })) : []),
|
|
1379
|
-
...
|
|
1588
|
+
...(Array.isArray(foundSess.hits) ? foundSess.hits.map(h => ({ ...h, _scope: 'session', _scopeLabel: '本会话档案', _target: sessionTarget })) : []),
|
|
1589
|
+
...foundGlobHits.map(h => ({ ...h, _scope: 'global', _scopeLabel: '系统全局档案(已织钩)', _target: globalTarget })),
|
|
1380
1590
|
]
|
|
1381
1591
|
if (combinedHits.length > 0) {
|
|
1382
|
-
onDemandArchiveLines.push('', '## 7.
|
|
1592
|
+
onDemandArchiveLines.push('', '## 7. 按需检索到的档案卷宗(仅本局与已织钩全局;未拉阅全局仅展示钩子)')
|
|
1383
1593
|
for (let i = 0; i < combinedHits.length; i += 1) {
|
|
1384
1594
|
const hit = combinedHits[i]
|
|
1595
|
+
if (hit._scope === 'global' && !pulledOrDeskGlobIds.has(hit.id)) {
|
|
1596
|
+
onDemandArchiveLines.push(`- 🪝 [全局钩子待拉阅/${hit.folderLabel} | id=${hit.id}] 《${hit.title}》 关键词=[${(hit.hookKeywords || []).join('·')}] ${clamp(hit.hookCue || hit.summary, 90)}(如需详情可输出 archiveOps pull_global)`)
|
|
1597
|
+
continue
|
|
1598
|
+
}
|
|
1385
1599
|
onDemandArchiveLines.push(`- 📎 [${hit._scopeLabel}/${hit.folderLabel}] 《${hit.title}》:${hit.summary}`)
|
|
1386
1600
|
if (i < 3) {
|
|
1387
1601
|
const det = getArchiveDetail(hit.id, rootId, hit._target)
|
|
@@ -1498,19 +1712,56 @@ export async function askOrCommandChief(deps, {
|
|
|
1498
1712
|
|
|
1499
1713
|
const isBlankContext = liveDigest.summaryLines.length === 0 && !board.objective && !(board.plan || []).length
|
|
1500
1714
|
const resolvedCwd = deps && typeof deps.getSessionCwd === 'function' ? deps.getSessionCwd(rootId) : ''
|
|
1715
|
+
const cwdForPromptWalls = resolveSessionWorkspaceCwd(deps, rootId) || resolvedCwd
|
|
1716
|
+
const activeDynamicWalls = listGuardWalls({ cwd: cwdForPromptWalls }).filter(w => w && w.scope !== 'paused')
|
|
1717
|
+
if (activeDynamicWalls.length > 0) {
|
|
1718
|
+
promptLines.push(
|
|
1719
|
+
'',
|
|
1720
|
+
'## 6.8 当前生效动态物理驻墙参考(仅作阻断排查,严禁私拆;仅代理撞墙无法绕过上报且确无法继续时才可请示审批)',
|
|
1721
|
+
...activeDynamicWalls.slice(0, 8).map(w => `- [${w.id}] (${w.scope}/${w.ruleType}) ${w.title} :: ${Array.isArray(w.patterns) ? w.patterns.join(', ') : ''}`),
|
|
1722
|
+
)
|
|
1723
|
+
}
|
|
1501
1724
|
const explicitCompactReq = !imageBlocks.length && isExplicitCompactCommand(input)
|
|
1502
|
-
const statusOnlyInquiry = !imageBlocks.length && !explicitCompactReq && isPureStatusInquiry(input)
|
|
1725
|
+
const statusOnlyInquiry = !imageBlocks.length && !explicitCompactReq && quickAction !== 'consult_chief' && !_wallBlockerEscalation && isPureStatusInquiry(input)
|
|
1726
|
+
const userExplicitDirect = /(?:参谋长.*?(?:亲自|自己|直接|别找主)|你自己(?:动手|改|跑|查|写)|别派发|勿转主对话)/.test(input)
|
|
1727
|
+
const hasLiveLead = Boolean(
|
|
1728
|
+
deps
|
|
1729
|
+
&& deps.runtime
|
|
1730
|
+
&& typeof deps.runtime.get === 'function'
|
|
1731
|
+
&& deps.runtime.get('agents')
|
|
1732
|
+
&& typeof deps.runtime.get('agents').get === 'function'
|
|
1733
|
+
&& deps.runtime.get('agents').get(rootId),
|
|
1734
|
+
)
|
|
1735
|
+
const lazyDeferWorkspaceWritesToLead = Boolean(
|
|
1736
|
+
!isResumeTurn
|
|
1737
|
+
&& !_fromLeadRequest
|
|
1738
|
+
&& !userExplicitDirect
|
|
1739
|
+
&& hasLiveLead
|
|
1740
|
+
&& permissionMode === 'chief',
|
|
1741
|
+
)
|
|
1503
1742
|
|
|
1504
1743
|
const effectiveSystem = [
|
|
1505
1744
|
ASK_CHIEF_SYSTEM,
|
|
1506
1745
|
...(isConciseBrief ? [CONCISE_BRIEF_ASK_EXTRA] : []),
|
|
1746
|
+
...(quickAction === 'consult_chief' ? [CONSULT_CHIEF_EXTRA] : []),
|
|
1747
|
+
...(_wallBlockerEscalation
|
|
1748
|
+
? [
|
|
1749
|
+
'',
|
|
1750
|
+
'🧱 【当前正在评估主/子代理提交的“撞墙阻断上报”】:',
|
|
1751
|
+
'- 请严格核对代理是否真的撞到了上述动态物理驻墙,以及**是否真的没有任何合法替代途径继续完成任务**;',
|
|
1752
|
+
'- 若有替代做法(如改用只读核查、调整目标路径/命令或分步处理),**绝不申请拆墙**,直接在 `reply` 中给出合法绕行路径即可;',
|
|
1753
|
+
'- 只有确认确被某堵动态墙彻底卡死无法推进时,才可在 `"wallRemovalProposals"` 中提出针对该精确 `wallId` 的暂挂/拆墙申请单供人类逐项批示!',
|
|
1754
|
+
]
|
|
1755
|
+
: []),
|
|
1507
1756
|
...(isBlankContext
|
|
1508
1757
|
? [
|
|
1509
1758
|
'',
|
|
1510
|
-
'🌱
|
|
1759
|
+
'🌱 【当前处于空白新上下文(主对话尚未开聊 · 首轮勘探与计划立项策略)】:',
|
|
1511
1760
|
resolvedCwd ? `- 当前已解析工作区根目录:${resolvedCwd}` : '',
|
|
1512
|
-
|
|
1513
|
-
|
|
1761
|
+
!userExplicitDirect
|
|
1762
|
+
? '- 默认开场铁律:首轮优先通过 `"relays"`(`target: "lead"`, `mode: "followup"`)向主对话 @lead 下发开场执行请求,要求主对话:① 先只读勘探代码库与目录结构;② 调用 `chief_board({ action: "graph.plan" })` / 计划工具进入计划模式立项拆解;③ 得出明确结论后调用 `chief_board({ action: "chief.request", subject: "勘探与计划回报", text: "..." })` 回报给参谋长。若当前为 L0/L1 权限不足以投递工作流指令,请同时填写 `"elevationRequest": { "targetMode": "strategist", "reason": "空白新对话首轮需授权向主对话下发勘探与计划立项指令" }`,并将完整勘探请求放进 `"relays"` 或建议备妥(绝对禁止向用户输出 `<|DSML|calls>` 等原始工具标签)。'
|
|
1763
|
+
: '- 用户已明确点名由你亲自排查/处理工作区,请依据当前 `permissionMode` 调用真实 JSON `toolCalls` 工具(`list_dir` / `search_files` / `read_file` / `edit_file` / `run_command`)处理并如实汇报;绝对禁止向用户输出 `<|DSML|calls>` 等原始工具调用标签!',
|
|
1764
|
+
'- 若尚无主对话历史,除非用户明确命令且会话已存在,不要无故调用 `session_compact`。',
|
|
1514
1765
|
].filter(Boolean)
|
|
1515
1766
|
: []),
|
|
1516
1767
|
...(statusOnlyInquiry
|
|
@@ -1528,6 +1779,14 @@ export async function askOrCommandChief(deps, {
|
|
|
1528
1779
|
const upsertArchiveFn = buildChiefArchiveUpsertFn(deps, rootId)
|
|
1529
1780
|
const compactNowFn = buildChiefCompactFn(deps, rootId)
|
|
1530
1781
|
|
|
1782
|
+
const askReasonKind = statusOnlyInquiry
|
|
1783
|
+
? 'quick_status'
|
|
1784
|
+
: (/筑墙|物理墙|guard.?wall/i.test(input)
|
|
1785
|
+
? 'craft_wall'
|
|
1786
|
+
: (isBlankContext
|
|
1787
|
+
? 'blank_explore'
|
|
1788
|
+
: ((effCfg.tacticalModes && effCfg.tacticalModes.intervention) ? 'strong_intervention' : 'ask_chat')))
|
|
1789
|
+
|
|
1531
1790
|
const loopRes = await runChiefAgenticLoop(deps, {
|
|
1532
1791
|
rootId,
|
|
1533
1792
|
sessionId: rootId,
|
|
@@ -1537,11 +1796,13 @@ export async function askOrCommandChief(deps, {
|
|
|
1537
1796
|
allowTextFallbackOnVisionMiss: savedImagePaths.length > 0,
|
|
1538
1797
|
permissionMode,
|
|
1539
1798
|
hasChiefRiskAck,
|
|
1799
|
+
policyPlugins,
|
|
1540
1800
|
board,
|
|
1541
1801
|
maxSteps: statusOnlyInquiry ? 1 : 4,
|
|
1542
1802
|
readOnlyToolsOnly: false,
|
|
1543
|
-
disableTools: statusOnlyInquiry,
|
|
1544
|
-
|
|
1803
|
+
disableTools: statusOnlyInquiry || (_wallBlockerEscalation && permRank < 3),
|
|
1804
|
+
lazyDeferWorkspaceWritesToLead,
|
|
1805
|
+
callLlmFn: (callOpts) => callChiefLlm(deps, { reasonKind: askReasonKind, ...callOpts, maxTokens: SUMMARY_MAX_TOKENS }),
|
|
1545
1806
|
extractJsonFn: extractJsonObject,
|
|
1546
1807
|
upsertArchiveFn,
|
|
1547
1808
|
compactNowFn,
|
|
@@ -1575,12 +1836,12 @@ export async function askOrCommandChief(deps, {
|
|
|
1575
1836
|
loopBadges.push(compactGuard.badge || '🛡️ 卫兵拦截压缩')
|
|
1576
1837
|
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'safety_guard', decision: 'blocked', operation: '压缩主对话', target: 'current', reason: compactGuard.reason, outcome: 'blocked', by: 'chief' })
|
|
1577
1838
|
} else {
|
|
1578
|
-
const compactGate = evaluateChiefPermissionGate({ permissionMode, hasChiefRiskAck, opClass: 'workflow', tool: 'session_compact' })
|
|
1579
|
-
if (compactGate.decision === 'deny_mode' || compactGate.decision === 'deny_unacknowledged_l3') {
|
|
1580
|
-
workflowBlockedNeedsElevation =
|
|
1839
|
+
const compactGate = evaluateChiefPermissionGate({ permissionMode, hasChiefRiskAck, policyPlugins, opClass: 'workflow', tool: 'session_compact' })
|
|
1840
|
+
if (compactGate.decision === 'deny_mode' || compactGate.decision === 'deny_unacknowledged_l3' || compactGate.decision === 'deny_policy_plugin') {
|
|
1841
|
+
workflowBlockedNeedsElevation = compactGate.decision !== 'deny_policy_plugin'
|
|
1581
1842
|
forcedCompactOut = { ok: false, deniedByMode: true, error: compactGate.error }
|
|
1582
1843
|
loopBadges.push(compactGate.badge || '🔒 权限禁压')
|
|
1583
|
-
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'permission_gate', decision: compactGate.decision, operation: '压缩主对话', target: 'current', reason: compactGate.error, outcome: 'denied', by: 'chief' })
|
|
1844
|
+
appendChiefAuditLog(rootId, { mode: permissionMode, stage: compactGate.decision === 'deny_policy_plugin' ? 'policy_plugin' : 'permission_gate', rule: compactGate.rule || compactGate.decision, decision: compactGate.decision, operation: '压缩主对话', target: 'current', reason: compactGate.error, outcome: 'denied', by: 'chief' })
|
|
1584
1845
|
} else if (compactGate.decision === 'require_approval') {
|
|
1585
1846
|
const apr = queueChiefApproval(rootId, {
|
|
1586
1847
|
category: 'main_workflow',
|
|
@@ -1589,6 +1850,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1589
1850
|
reason: clamp(input, 140),
|
|
1590
1851
|
impact: '会触发主会话历史压缩,先抢救细节入本会话档案柜再压缩裁剪历史上下文',
|
|
1591
1852
|
kind: 'compact',
|
|
1853
|
+
capabilityScope: buildCapabilityScope({ kind: 'compact', tool: 'session_compact' }),
|
|
1592
1854
|
payload: { reason: `用户指令触发:${input}` },
|
|
1593
1855
|
by: 'chief',
|
|
1594
1856
|
})
|
|
@@ -1654,7 +1916,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1654
1916
|
savedImagePaths,
|
|
1655
1917
|
memoryChanges: [],
|
|
1656
1918
|
boardOps: [],
|
|
1657
|
-
view: await getChiefView(deps, rootId, { autoSummarize: false }),
|
|
1919
|
+
view: await getChiefView(deps, rootId, { autoSummarize: false, chatTriggered: !_fromLeadRequest }),
|
|
1658
1920
|
}
|
|
1659
1921
|
}
|
|
1660
1922
|
|
|
@@ -1745,7 +2007,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1745
2007
|
memoryChanges: [],
|
|
1746
2008
|
boardOps: ['重设任务看板'],
|
|
1747
2009
|
board: resetRes.board,
|
|
1748
|
-
view: await getChiefView(deps, rootId, { autoSummarize: false }),
|
|
2010
|
+
view: await getChiefView(deps, rootId, { autoSummarize: false, chatTriggered: !_fromLeadRequest }),
|
|
1749
2011
|
}
|
|
1750
2012
|
}
|
|
1751
2013
|
}
|
|
@@ -1783,7 +2045,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1783
2045
|
memoryChanges: [],
|
|
1784
2046
|
boardOps: [],
|
|
1785
2047
|
networkOps: badges,
|
|
1786
|
-
view: await getChiefView(deps, rootId, { autoSummarize: false }),
|
|
2048
|
+
view: await getChiefView(deps, rootId, { autoSummarize: false, chatTriggered: !_fromLeadRequest }),
|
|
1787
2049
|
}
|
|
1788
2050
|
}
|
|
1789
2051
|
}
|
|
@@ -1818,6 +2080,8 @@ export async function askOrCommandChief(deps, {
|
|
|
1818
2080
|
elevationObj: autoElevOut,
|
|
1819
2081
|
pendingApprovalList: queuedApprovals,
|
|
1820
2082
|
forceReceipt: true,
|
|
2083
|
+
thinkingEffort: llmRes.thinkingEffort || '',
|
|
2084
|
+
thinkingEffortMode: llmRes.thinkingEffortMode || effCfg.thinkingEffort || 'auto',
|
|
1821
2085
|
})
|
|
1822
2086
|
})
|
|
1823
2087
|
return {
|
|
@@ -1830,7 +2094,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1830
2094
|
toolRecords: loopToolRecords,
|
|
1831
2095
|
pendingApprovals: queuedApprovals,
|
|
1832
2096
|
...(autoElevOut ? { elevationRequested: autoElevOut } : {}),
|
|
1833
|
-
view: await getChiefView(deps, rootId, { autoSummarize: false }),
|
|
2097
|
+
view: await getChiefView(deps, rootId, { autoSummarize: false, chatTriggered: !_fromLeadRequest }),
|
|
1834
2098
|
}
|
|
1835
2099
|
}
|
|
1836
2100
|
|
|
@@ -1848,7 +2112,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1848
2112
|
}
|
|
1849
2113
|
const strippedPlain = llmRes.ok && llmRes.text ? stripToolCallMarkup(llmRes.text).trim() : ''
|
|
1850
2114
|
const usablePlainLlm = strippedPlain && !strippedPlain.startsWith('{') && strippedPlain.length >= 6
|
|
1851
|
-
? cleanMultiline(strippedPlain,
|
|
2115
|
+
? cleanMultiline(strippedPlain, 2200)
|
|
1852
2116
|
: ''
|
|
1853
2117
|
const archiveFallback = onDemandArchiveLines.length > 1
|
|
1854
2118
|
? ['- 【已从沉淀档案柜按需检索到以下卷宗】', ...onDemandArchiveLines.slice(2)].join('\n')
|
|
@@ -1863,14 +2127,46 @@ export async function askOrCommandChief(deps, {
|
|
|
1863
2127
|
conciseBrief: isConciseBrief,
|
|
1864
2128
|
})
|
|
1865
2129
|
const replyText = isConciseBrief ? sanitizeConciseBriefText(rawFallbackReply) : rawFallbackReply
|
|
2130
|
+
const fallbackBounds = (permRank >= 1 && quickAction !== 'consult_chief') ? extractFallbackBoundProposalsFromText(rawFallbackReply, input) : []
|
|
2131
|
+
const createdFallbackBounds = []
|
|
2132
|
+
const BOUND_COL_LABEL_FB = { forbidden: '禁止红线', allowed: '必做事项', notes: '注意事项' }
|
|
1866
2133
|
|
|
1867
2134
|
mutateChiefState((s) => {
|
|
1868
2135
|
const ws = ensureWorkspace(s, rootId)
|
|
2136
|
+
const existingFb = (board && board.bounds) || { allowed: [], forbidden: [], notes: [] }
|
|
2137
|
+
for (const fb of fallbackBounds) {
|
|
2138
|
+
const col = ['forbidden', 'allowed', 'notes'].includes(fb.field) ? fb.field : 'forbidden'
|
|
2139
|
+
const colList = Array.isArray(existingFb[col]) ? existingFb[col] : []
|
|
2140
|
+
if (colList.some(x => String(x).trim() === fb.item)) continue
|
|
2141
|
+
if (ws.suggestions.some(ex => ex && ex.status === 'pending' && ex.kind === 'bound' && ex.draftText === fb.item)) continue
|
|
2142
|
+
const colLabel = BOUND_COL_LABEL_FB[col] || '禁止红线'
|
|
2143
|
+
const sug = normalizeSuggestion({
|
|
2144
|
+
kind: 'bound',
|
|
2145
|
+
boundField: col,
|
|
2146
|
+
fromAgent: '✦ 参谋长提炼',
|
|
2147
|
+
title: `拟入${colLabel}:${clamp(fb.item, 30)}`,
|
|
2148
|
+
reason: fb.reason,
|
|
2149
|
+
target: 'bounds',
|
|
2150
|
+
targetLabel: colLabel,
|
|
2151
|
+
mode: 'silent',
|
|
2152
|
+
draftText: fb.item,
|
|
2153
|
+
pinGlobal: Boolean(fb.pinGlobal),
|
|
2154
|
+
})
|
|
2155
|
+
if (sug) {
|
|
2156
|
+
ws.suggestions.push(sug)
|
|
2157
|
+
if (ws.suggestions.length > SUGGESTIONS_CAP) ws.suggestions = ws.suggestions.slice(-SUGGESTIONS_CAP)
|
|
2158
|
+
createdFallbackBounds.push(sug)
|
|
2159
|
+
loopBadges.push(`呈批${colLabel}:${clamp(fb.item, 18)}`)
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
1869
2162
|
persistTurnChatAndResume(ws, {
|
|
1870
2163
|
chiefText: replyText,
|
|
1871
2164
|
actions: loopBadges,
|
|
1872
2165
|
elevationObj: fallbackElev,
|
|
1873
2166
|
pendingApprovalList: queuedApprovals,
|
|
2167
|
+
forceReceipt: createdFallbackBounds.length > 0,
|
|
2168
|
+
thinkingEffort: llmRes.thinkingEffort || '',
|
|
2169
|
+
thinkingEffortMode: llmRes.thinkingEffortMode || effCfg.thinkingEffort || 'auto',
|
|
1874
2170
|
})
|
|
1875
2171
|
})
|
|
1876
2172
|
return {
|
|
@@ -1879,11 +2175,12 @@ export async function askOrCommandChief(deps, {
|
|
|
1879
2175
|
relays: [],
|
|
1880
2176
|
memoryChanges: [],
|
|
1881
2177
|
boardOps: [],
|
|
2178
|
+
boundProposals: createdFallbackBounds,
|
|
1882
2179
|
actionBadges: loopBadges,
|
|
1883
2180
|
toolRecords: loopToolRecords,
|
|
1884
2181
|
pendingApprovals: queuedApprovals,
|
|
1885
2182
|
...(fallbackElev ? { elevationRequested: fallbackElev } : {}),
|
|
1886
|
-
view: await getChiefView(deps, rootId, { autoSummarize: false }),
|
|
2183
|
+
view: await getChiefView(deps, rootId, { autoSummarize: false, chatTriggered: !_fromLeadRequest }),
|
|
1887
2184
|
}
|
|
1888
2185
|
}
|
|
1889
2186
|
|
|
@@ -1893,6 +2190,7 @@ export async function askOrCommandChief(deps, {
|
|
|
1893
2190
|
const relayGate = evaluateChiefPermissionGate({
|
|
1894
2191
|
permissionMode,
|
|
1895
2192
|
hasChiefRiskAck,
|
|
2193
|
+
policyPlugins,
|
|
1896
2194
|
opClass: 'workflow',
|
|
1897
2195
|
tool: 'relay',
|
|
1898
2196
|
})
|
|
@@ -1907,15 +2205,15 @@ export async function askOrCommandChief(deps, {
|
|
|
1907
2205
|
if (relayGuard.blocked) {
|
|
1908
2206
|
actionBadges.push(relayGuard.badge || '🛡️ 卫兵拦递话')
|
|
1909
2207
|
relayResults.push({ ok: false, target: targetName, blockedBySafetyGuard: true, error: relayGuard.reason })
|
|
1910
|
-
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'safety_guard', decision: 'blocked', operation: '工作流递话', target: String(targetName), reason: relayGuard.reason, outcome: 'blocked', by: 'chief' })
|
|
2208
|
+
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'safety_guard', rule: relayGuard.rule || 'hard_guard', decision: 'blocked', operation: '工作流递话', target: String(targetName), reason: relayGuard.reason, outcome: 'blocked', by: 'chief' })
|
|
1911
2209
|
continue
|
|
1912
2210
|
}
|
|
1913
2211
|
|
|
1914
|
-
if (relayGate.decision === 'deny_mode' || relayGate.decision === 'deny_unacknowledged_l3') {
|
|
1915
|
-
workflowBlockedNeedsElevation = true
|
|
2212
|
+
if (relayGate.decision === 'deny_mode' || relayGate.decision === 'deny_unacknowledged_l3' || relayGate.decision === 'deny_policy_plugin') {
|
|
2213
|
+
if (relayGate.decision !== 'deny_policy_plugin') workflowBlockedNeedsElevation = true
|
|
1916
2214
|
actionBadges.push(relayGate.badge || '🔒 权限禁调工作流')
|
|
1917
2215
|
relayResults.push({ ok: false, target: targetName, deniedByMode: true, error: relayGate.error })
|
|
1918
|
-
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'permission_gate', decision: relayGate.decision, operation: isLeadTarget ? '调整主对话工作流' : '调整子代理工作流', target: String(targetName), reason: relayGate.error, outcome: 'denied', by: 'chief' })
|
|
2216
|
+
appendChiefAuditLog(rootId, { mode: permissionMode, stage: relayGate.decision === 'deny_policy_plugin' ? 'policy_plugin' : 'permission_gate', rule: relayGate.rule || relayGate.decision, decision: relayGate.decision, operation: isLeadTarget ? '调整主对话工作流' : '调整子代理工作流', target: String(targetName), reason: relayGate.error, outcome: 'denied', by: 'chief' })
|
|
1919
2217
|
continue
|
|
1920
2218
|
}
|
|
1921
2219
|
|
|
@@ -1928,13 +2226,16 @@ export async function askOrCommandChief(deps, {
|
|
|
1928
2226
|
impact: isLeadTarget ? '将向主对话注入工作流指令并触发继续推进' : '将唤醒或引导子代理执行新任务指令',
|
|
1929
2227
|
preview: clamp(r.text, 240),
|
|
1930
2228
|
kind: 'relay',
|
|
2229
|
+
capabilityScope: buildCapabilityScope({ kind: 'relay', tool: 'relay', target: targetName }),
|
|
1931
2230
|
payload: {
|
|
1932
2231
|
fromSession: rootId,
|
|
1933
|
-
fromLabel: 'DSH 参谋 (逐项授权)',
|
|
2232
|
+
fromLabel: 'DSH 参谋 (执行请求 · 逐项授权)',
|
|
1934
2233
|
target: targetName,
|
|
1935
2234
|
subject: r.subject || '',
|
|
1936
2235
|
text: r.text,
|
|
1937
2236
|
mode: relayMode,
|
|
2237
|
+
envelopeKind: 'execution_request',
|
|
2238
|
+
taskId: r.taskId || '',
|
|
1938
2239
|
imageBlocks,
|
|
1939
2240
|
savedImagePaths,
|
|
1940
2241
|
isBlankContext,
|
|
@@ -1948,14 +2249,16 @@ export async function askOrCommandChief(deps, {
|
|
|
1948
2249
|
continue
|
|
1949
2250
|
}
|
|
1950
2251
|
|
|
1951
|
-
// L3 Chief mode: execute
|
|
2252
|
+
// L3 Chief mode: execute via explicit execution_request envelope (never impersonate user)
|
|
1952
2253
|
const deliv = await deliverCrossMessage(deps, {
|
|
1953
2254
|
fromSession: rootId,
|
|
1954
|
-
fromLabel: 'DSH 参谋长 (
|
|
2255
|
+
fromLabel: 'DSH 参谋长 (执行请求)',
|
|
1955
2256
|
target: targetName,
|
|
1956
2257
|
subject: r.subject || '',
|
|
1957
2258
|
text: r.text,
|
|
1958
2259
|
mode: relayMode,
|
|
2260
|
+
envelopeKind: 'execution_request',
|
|
2261
|
+
taskId: r.taskId || '',
|
|
1959
2262
|
imageBlocks,
|
|
1960
2263
|
savedImagePaths,
|
|
1961
2264
|
})
|
|
@@ -1978,16 +2281,49 @@ export async function askOrCommandChief(deps, {
|
|
|
1978
2281
|
}
|
|
1979
2282
|
|
|
1980
2283
|
// Execute Chief-system ops (L1 Assistant+ required; strictly denied in L0 Advisor)
|
|
2284
|
+
const rawInquiries = Array.isArray(parsed.inquiries) ? parsed.inquiries.slice(0, 3) : []
|
|
2285
|
+
const rawWallListSrc = Array.isArray(parsed.wallProposals)
|
|
2286
|
+
? parsed.wallProposals
|
|
2287
|
+
: (Array.isArray(parsed.guardWalls) ? parsed.guardWalls : [])
|
|
2288
|
+
const rawWallProposals = rawWallListSrc.slice(0, 4)
|
|
2289
|
+
const rawBoundListSrc = Array.isArray(parsed.boundProposals) && parsed.boundProposals.length > 0
|
|
2290
|
+
? parsed.boundProposals
|
|
2291
|
+
: (Array.isArray(parsed.boundaryProposals) && parsed.boundaryProposals.length > 0
|
|
2292
|
+
? parsed.boundaryProposals
|
|
2293
|
+
: extractFallbackBoundProposalsFromText(parsed.reply || '', input))
|
|
2294
|
+
const rawArchiveOps = Array.isArray(parsed.archiveOps) ? parsed.archiveOps.slice(0, 8) : []
|
|
2295
|
+
const rawEffortOps = Array.isArray(parsed.effortOps) ? parsed.effortOps.slice(0, 6) : []
|
|
2296
|
+
const internalArchiveOps = []
|
|
2297
|
+
const mainInjectArchiveOps = []
|
|
2298
|
+
for (const opItem of rawArchiveOps) {
|
|
2299
|
+
if (!opItem || typeof opItem !== 'object') continue
|
|
2300
|
+
const normOp = normalizeArchiveOpName(opItem.op)
|
|
2301
|
+
const sc = opItem.vaultScope === 'precipitated'
|
|
2302
|
+
? 'precipitated'
|
|
2303
|
+
: (opItem.vaultScope === 'global' ? 'global' : 'session')
|
|
2304
|
+
if (sc === 'precipitated' || normOp === 'pull_precipitated') {
|
|
2305
|
+
internalArchiveOps.push(opItem)
|
|
2306
|
+
} else if (MAIN_INJECT_ARCHIVE_OPS.has(normOp)) {
|
|
2307
|
+
mainInjectArchiveOps.push({ ...opItem, op: normOp, vaultScope: sc })
|
|
2308
|
+
} else if (normOp === 'save' && opItem.takeOut) {
|
|
2309
|
+
internalArchiveOps.push({ ...opItem, takeOut: false })
|
|
2310
|
+
mainInjectArchiveOps.push({ op: 'pin_to_desktop', vaultScope: sc, title: opItem.title, instruction: opItem.summary || '' })
|
|
2311
|
+
} else {
|
|
2312
|
+
internalArchiveOps.push(opItem)
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
1981
2315
|
const hasSystemOps = Boolean(
|
|
1982
2316
|
(Array.isArray(parsed.boardOps) && parsed.boardOps.length > 0)
|
|
1983
|
-
||
|
|
2317
|
+
|| internalArchiveOps.length > 0
|
|
1984
2318
|
|| (Array.isArray(parsed.networkOps) && parsed.networkOps.length > 0)
|
|
1985
2319
|
|| (Array.isArray(parsed.memoryChanges) && parsed.memoryChanges.length > 0)
|
|
1986
|
-
||
|
|
2320
|
+
|| rawBoundListSrc.length > 0
|
|
2321
|
+
|| rawWallProposals.length > 0,
|
|
1987
2322
|
)
|
|
1988
2323
|
const systemGate = evaluateChiefPermissionGate({
|
|
1989
2324
|
permissionMode,
|
|
1990
2325
|
hasChiefRiskAck,
|
|
2326
|
+
policyPlugins,
|
|
1991
2327
|
opClass: 'chief_system',
|
|
1992
2328
|
tool: 'chief_system',
|
|
1993
2329
|
})
|
|
@@ -1995,18 +2331,22 @@ export async function askOrCommandChief(deps, {
|
|
|
1995
2331
|
let executedBoardOps = []
|
|
1996
2332
|
let executedArchiveOps = []
|
|
1997
2333
|
let executedNetworkOps = []
|
|
2334
|
+
let executedEffortOps = []
|
|
2335
|
+
const pendingArchiveSuggestions = []
|
|
2336
|
+
const pendingEffortSuggestions = []
|
|
1998
2337
|
let appliedFacts = []
|
|
1999
2338
|
const proposedBounds = []
|
|
2000
2339
|
const existingBounds = (board && board.bounds) || { allowed: [], forbidden: [], notes: [] }
|
|
2001
|
-
const rawBoundProposals =
|
|
2340
|
+
const rawBoundProposals = rawBoundListSrc.slice(0, 4)
|
|
2002
2341
|
|
|
2003
|
-
if (hasSystemOps && systemGate.decision
|
|
2004
|
-
chiefSystemBlockedNeedsElevation =
|
|
2342
|
+
if (hasSystemOps && systemGate.decision !== 'allow' && systemGate.decision !== 'allow_approved') {
|
|
2343
|
+
chiefSystemBlockedNeedsElevation = systemGate.decision === 'deny_mode'
|
|
2005
2344
|
actionBadges.push(systemGate.badge || '🔒 L0禁改参谋系统')
|
|
2006
2345
|
appendChiefAuditLog(rootId, {
|
|
2007
2346
|
mode: permissionMode,
|
|
2008
|
-
stage: 'permission_gate',
|
|
2009
|
-
|
|
2347
|
+
stage: systemGate.decision === 'deny_policy_plugin' ? 'policy_plugin' : 'permission_gate',
|
|
2348
|
+
rule: systemGate.rule || systemGate.decision,
|
|
2349
|
+
decision: systemGate.decision,
|
|
2010
2350
|
operation: '修改参谋系统(看板/记忆/档案)',
|
|
2011
2351
|
target: 'chief_system',
|
|
2012
2352
|
reason: systemGate.error,
|
|
@@ -2014,10 +2354,10 @@ export async function askOrCommandChief(deps, {
|
|
|
2014
2354
|
by: 'chief',
|
|
2015
2355
|
})
|
|
2016
2356
|
} else if (hasSystemOps) {
|
|
2017
|
-
executedBoardOps = applyBoardOps(deps, rootId, parsed.boardOps)
|
|
2357
|
+
executedBoardOps = applyBoardOps(deps, rootId, parsed.boardOps, { callerOrigin: 'chief_llm' })
|
|
2018
2358
|
for (const b of executedBoardOps) actionBadges.push(b)
|
|
2019
2359
|
|
|
2020
|
-
const archiveExec = await applyArchiveOps(deps, rootId,
|
|
2360
|
+
const archiveExec = await applyArchiveOps(deps, rootId, internalArchiveOps, { input, allowPinToDesktop: false })
|
|
2021
2361
|
executedArchiveOps = archiveExec.executed || []
|
|
2022
2362
|
for (const a of executedArchiveOps) actionBadges.push(a)
|
|
2023
2363
|
|
|
@@ -2038,6 +2378,161 @@ export async function askOrCommandChief(deps, {
|
|
|
2038
2378
|
}
|
|
2039
2379
|
}
|
|
2040
2380
|
|
|
2381
|
+
// Dual-channel main injection from archives (Channel A: desktop pin/unpin, Channel B: deliver_to_lead)
|
|
2382
|
+
// L0/L1 -> Suggestion pill; L2 -> Approval card + TaskLedger; L3 -> Direct execution
|
|
2383
|
+
for (const item of mainInjectArchiveOps) {
|
|
2384
|
+
const scopeLabel = item.vaultScope === 'global' ? '全局档案柜' : '本局档案柜'
|
|
2385
|
+
const refText = item.title ? `《${clamp(item.title, 28)}》` : `#${item.id || item.archiveId || '?'}`
|
|
2386
|
+
const opDesc = item.op === 'pin_to_desktop'
|
|
2387
|
+
? `将${scopeLabel}档案置顶桌面`
|
|
2388
|
+
: (item.op === 'unpin_from_desktop' ? `将${scopeLabel}档案撤回抽屉` : `向主对话递送${scopeLabel}档案`)
|
|
2389
|
+
if (relayGate.decision === 'deny_mode' || relayGate.decision === 'deny_unacknowledged_l3' || relayGate.decision === 'deny_policy_plugin') {
|
|
2390
|
+
if (relayGate.decision !== 'deny_policy_plugin' && permRank < 2) {
|
|
2391
|
+
pendingArchiveSuggestions.push({
|
|
2392
|
+
kind: 'archive_op',
|
|
2393
|
+
fromAgent: '📌 参谋档案馆通道',
|
|
2394
|
+
title: `${opDesc}:${refText}`,
|
|
2395
|
+
reason: clamp(item.instruction || `当前处于 L${permRank} 只读/助手档,后台不直接注入主会话;点「执行建议」即刻落位。`, 180),
|
|
2396
|
+
target: item.target || 'lead',
|
|
2397
|
+
targetLabel: item.op === 'deliver_to_lead' ? '主对话 (@lead)' : '📌 认知桌面',
|
|
2398
|
+
mode: 'steer',
|
|
2399
|
+
draftText: `${opDesc} ${refText}${item.instruction ? ' — ' + item.instruction : ''}`,
|
|
2400
|
+
archiveSpec: {
|
|
2401
|
+
op: item.op,
|
|
2402
|
+
vaultScope: item.vaultScope,
|
|
2403
|
+
id: item.id || item.archiveId || '',
|
|
2404
|
+
title: item.title || '',
|
|
2405
|
+
target: item.target || 'lead',
|
|
2406
|
+
instruction: item.instruction || '',
|
|
2407
|
+
},
|
|
2408
|
+
})
|
|
2409
|
+
actionBadges.push(`💡 建议档案注入:${refText}`)
|
|
2410
|
+
} else {
|
|
2411
|
+
workflowBlockedNeedsElevation = workflowBlockedNeedsElevation || relayGate.decision !== 'deny_policy_plugin'
|
|
2412
|
+
actionBadges.push(relayGate.badge || '🔒 权限禁注档案')
|
|
2413
|
+
}
|
|
2414
|
+
continue
|
|
2415
|
+
}
|
|
2416
|
+
if (relayGate.decision === 'require_approval') {
|
|
2417
|
+
const apr = queueChiefApproval(rootId, {
|
|
2418
|
+
category: 'main_workflow',
|
|
2419
|
+
operationLabel: opDesc,
|
|
2420
|
+
targetLabel: `${scopeLabel} · ${refText}`,
|
|
2421
|
+
reason: clamp(item.instruction || 'L2 参谋模式:向主对话桌面或正文注入档案前需逐项确认', 140),
|
|
2422
|
+
impact: item.op === 'deliver_to_lead' ? '将把该卷宗摘要与要点投递至主对话并唤醒查收' : '将调整主对话共享认知桌面置顶列表(受 2400 Tokens/6 份预算约束)',
|
|
2423
|
+
preview: clamp(`${opDesc} ${refText}${item.instruction ? '\n附言:' + item.instruction : ''}`, 240),
|
|
2424
|
+
kind: 'archive_op',
|
|
2425
|
+
capabilityScope: buildCapabilityScope({ kind: 'archive_op', tool: 'archive_op', target: refText }),
|
|
2426
|
+
payload: {
|
|
2427
|
+
op: item.op,
|
|
2428
|
+
vaultScope: item.vaultScope,
|
|
2429
|
+
id: item.id || item.archiveId || '',
|
|
2430
|
+
title: item.title || '',
|
|
2431
|
+
target: item.target || 'lead',
|
|
2432
|
+
instruction: item.instruction || '',
|
|
2433
|
+
},
|
|
2434
|
+
by: 'chief',
|
|
2435
|
+
})
|
|
2436
|
+
if (apr) queuedApprovals.push(apr)
|
|
2437
|
+
actionBadges.push(`🛡️ 待确认档案注入:${refText}`)
|
|
2438
|
+
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'permission_gate', decision: 'pending_approval', operation: opDesc, target: refText, reason: clamp(input, 120), outcome: 'pending', by: 'chief' })
|
|
2439
|
+
continue
|
|
2440
|
+
}
|
|
2441
|
+
const execOut = await executeChiefArchiveInjectionOp(deps, rootId, item, { input })
|
|
2442
|
+
if (execOut && execOut.ok) {
|
|
2443
|
+
executedArchiveOps.push(execOut.actionText)
|
|
2444
|
+
actionBadges.push(execOut.actionText)
|
|
2445
|
+
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'executor', decision: 'executed', operation: opDesc, target: refText, reason: clamp(input, 120), outcome: 'ok', by: 'chief' })
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2449
|
+
// Hot reasoning-effort shifting (`effortOps`) with 4-tier permission gate + teamEffortMode + per-agent user 🔒 veto lock
|
|
2450
|
+
const userLocks = (effCfg && effCfg.lockedModelEfforts && typeof effCfg.lockedModelEfforts === 'object') ? effCfg.lockedModelEfforts : {}
|
|
2451
|
+
const isManualTeamEffort = Boolean(effCfg && effCfg.teamEffortMode === 'manual')
|
|
2452
|
+
if (isManualTeamEffort && rawEffortOps.length > 0) {
|
|
2453
|
+
actionBadges.push('✋ 团队思考强度已设为手动,跳过自动调挡')
|
|
2454
|
+
appendChiefAuditLog(rootId, {
|
|
2455
|
+
mode: permissionMode,
|
|
2456
|
+
stage: 'model_effort_lock',
|
|
2457
|
+
decision: 'blocked',
|
|
2458
|
+
operation: '调节模型思考强度',
|
|
2459
|
+
target: rawEffortOps.map(ef => String((ef && (ef.target || ef.agent)) || 'lead').replace(/^@/, '')).join(','),
|
|
2460
|
+
reason: '团队思考强度处于「手动」模式,已跳过自动调挡',
|
|
2461
|
+
outcome: 'blocked',
|
|
2462
|
+
by: 'chief',
|
|
2463
|
+
})
|
|
2464
|
+
}
|
|
2465
|
+
for (const ef of (isManualTeamEffort ? [] : rawEffortOps)) {
|
|
2466
|
+
if (!ef || typeof ef !== 'object') continue
|
|
2467
|
+
const efTarget = clamp(String(ef.target || ef.agent || 'lead').trim().replace(/^@/, ''), 64) || 'lead'
|
|
2468
|
+
const rawEf = String(ef.effort || ef.reasoningEffort || 'medium').trim().toLowerCase()
|
|
2469
|
+
const efVal = ['off', 'low', 'medium', 'high', 'xhigh'].includes(rawEf) ? rawEf : 'medium'
|
|
2470
|
+
const efReason = clamp(String(ef.reason || '按任务复杂度协同调节模型思考强度').trim(), 180)
|
|
2471
|
+
const shortEfTarget = efTarget.split('/').pop()
|
|
2472
|
+
const isUserLocked = Boolean(userLocks[efTarget] === true || userLocks[shortEfTarget] === true)
|
|
2473
|
+
if (isUserLocked) {
|
|
2474
|
+
actionBadges.push(`🔒 用户已锁挡 @${efTarget}`)
|
|
2475
|
+
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'model_effort_lock', decision: 'blocked', operation: '调节模型思考强度', target: efTarget, reason: `用户开启「🔒 锁挡」,阻止调为 ${efVal}`, outcome: 'blocked', by: 'chief' })
|
|
2476
|
+
continue
|
|
2477
|
+
}
|
|
2478
|
+
if (relayGate.decision === 'deny_mode' || relayGate.decision === 'deny_unacknowledged_l3' || relayGate.decision === 'deny_policy_plugin') {
|
|
2479
|
+
if (relayGate.decision !== 'deny_policy_plugin' && permRank < 2) {
|
|
2480
|
+
pendingEffortSuggestions.push({
|
|
2481
|
+
kind: 'model_effort',
|
|
2482
|
+
fromAgent: '🧠 思考强度建议',
|
|
2483
|
+
title: `建议调挡 @${efTarget} → ${efVal}`,
|
|
2484
|
+
reason: efReason,
|
|
2485
|
+
target: efTarget,
|
|
2486
|
+
targetLabel: efTarget === 'lead' ? '主对话 (@lead)' : `@${efTarget}`,
|
|
2487
|
+
mode: 'silent',
|
|
2488
|
+
draftText: `将 @${efTarget} 思考强度设为 ${efVal}(${efReason})`,
|
|
2489
|
+
effortSpec: { target: efTarget, effort: efVal, reason: efReason },
|
|
2490
|
+
})
|
|
2491
|
+
actionBadges.push(`💡 建议调挡 @${efTarget}→${efVal}`)
|
|
2492
|
+
} else {
|
|
2493
|
+
workflowBlockedNeedsElevation = workflowBlockedNeedsElevation || relayGate.decision !== 'deny_policy_plugin'
|
|
2494
|
+
actionBadges.push(relayGate.badge || '🔒 权限禁调档位')
|
|
2495
|
+
}
|
|
2496
|
+
continue
|
|
2497
|
+
}
|
|
2498
|
+
if (relayGate.decision === 'require_approval') {
|
|
2499
|
+
const apr = queueChiefApproval(rootId, {
|
|
2500
|
+
category: 'main_workflow',
|
|
2501
|
+
operationLabel: '调节模型思考强度',
|
|
2502
|
+
targetLabel: efTarget === 'lead' ? '主对话 (@lead)' : `@${efTarget}`,
|
|
2503
|
+
reason: efReason,
|
|
2504
|
+
impact: `批准后将静默热调节 @${efTarget} 的推理思考深度为 ${efVal}`,
|
|
2505
|
+
preview: `@${efTarget} → ${efVal}`,
|
|
2506
|
+
kind: 'model_effort',
|
|
2507
|
+
capabilityScope: buildCapabilityScope({ kind: 'model_effort', tool: 'model_effort', target: efTarget }),
|
|
2508
|
+
payload: { target: efTarget, reasoningEffort: efVal, reason: efReason },
|
|
2509
|
+
by: 'chief',
|
|
2510
|
+
})
|
|
2511
|
+
if (apr) queuedApprovals.push(apr)
|
|
2512
|
+
actionBadges.push(`🛡️ 待确认调挡 @${efTarget}→${efVal}`)
|
|
2513
|
+
appendChiefAuditLog(rootId, { mode: permissionMode, stage: 'permission_gate', decision: 'pending_approval', operation: '调节模型思考强度', target: efTarget, reason: efReason, outcome: 'pending', by: 'chief' })
|
|
2514
|
+
continue
|
|
2515
|
+
}
|
|
2516
|
+
if (deps && typeof deps.controlMainAgent === 'function') {
|
|
2517
|
+
const ctrlRes = await deps.controlMainAgent({
|
|
2518
|
+
rootId,
|
|
2519
|
+
sessionId: rootId,
|
|
2520
|
+
op: 'set_effort',
|
|
2521
|
+
target: efTarget,
|
|
2522
|
+
reasoningEffort: efVal,
|
|
2523
|
+
reason: efReason,
|
|
2524
|
+
byUser: false,
|
|
2525
|
+
}).catch(e => ({ ok: false, error: (e && e.message) || 'effort-control-failed' }))
|
|
2526
|
+
if (ctrlRes && ctrlRes.ok) {
|
|
2527
|
+
const tag = `🧠 调挡 @${efTarget} → ${ctrlRes.reasoningEffort || efVal}`
|
|
2528
|
+
executedEffortOps.push(tag)
|
|
2529
|
+
actionBadges.push(tag)
|
|
2530
|
+
} else if (ctrlRes && ctrlRes.lockedByUser) {
|
|
2531
|
+
actionBadges.push(`🔒 用户已锁挡 @${efTarget}`)
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2041
2536
|
// Handle explicit model elevationRequest OR auto-generate when an action hit mode wall
|
|
2042
2537
|
let finalElevation = queuedElevations[0] || null
|
|
2043
2538
|
if (parsed.elevationRequest && typeof parsed.elevationRequest === 'object' && parsed.elevationRequest.targetMode) {
|
|
@@ -2102,14 +2597,142 @@ export async function askOrCommandChief(deps, {
|
|
|
2102
2597
|
baseParsedReply,
|
|
2103
2598
|
...permissionStatusNotes,
|
|
2104
2599
|
].filter(Boolean).join('\n')
|
|
2105
|
-
const rawReplyText = cleanMultiline(combinedParsedReply,
|
|
2600
|
+
const rawReplyText = cleanMultiline(combinedParsedReply, 1800)
|
|
2106
2601
|
const replyText = isConciseBrief ? sanitizeConciseBriefText(rawReplyText) : rawReplyText
|
|
2107
2602
|
|
|
2108
2603
|
const BOUND_COL_LABEL = { forbidden: '禁止红线', allowed: '必做事项', notes: '注意事项' }
|
|
2604
|
+
const createdInquiries = []
|
|
2605
|
+
const proposedWalls = []
|
|
2606
|
+
const proposedWallRemovals = []
|
|
2607
|
+
const cwdForWall = resolveSessionWorkspaceCwd(deps, rootId)
|
|
2608
|
+
const rawWallRemovalProposals = Array.isArray(parsed.wallRemovalProposals) ? parsed.wallRemovalProposals.slice(0, 2) : []
|
|
2109
2609
|
|
|
2110
2610
|
mutateChiefState((s) => {
|
|
2111
2611
|
const ws = ensureWorkspace(s, rootId)
|
|
2112
|
-
|
|
2612
|
+
|
|
2613
|
+
// Ultra-strict, all-tier (L0-L3) Human Approval Wall-Removal Proposal Gate
|
|
2614
|
+
if (rawWallRemovalProposals.length > 0) {
|
|
2615
|
+
const hasWallBlockLog = (Array.isArray(ws.auditLog) ? ws.auditLog : [])
|
|
2616
|
+
.some(e => e && e.stage === 'guard_wall' && e.outcome === 'blocked')
|
|
2617
|
+
const mentionsBlocker = /(?:撞墙|物理驻墙|物理墙|无法绕过|事前物理拦截|guard_wall|wall-)/i.test(input)
|
|
2618
|
+
const hasWallBlockerEvidence = Boolean(_wallBlockerEscalation || (hasWallBlockLog && mentionsBlocker))
|
|
2619
|
+
if (!hasWallBlockerEvidence) {
|
|
2620
|
+
pushAuditToWs(ws, {
|
|
2621
|
+
mode: permissionMode,
|
|
2622
|
+
stage: 'guard_wall',
|
|
2623
|
+
rule: 'wall_removal_denied_no_blocker_evidence',
|
|
2624
|
+
decision: 'rejected',
|
|
2625
|
+
operation: '拦截无依据拆墙提议',
|
|
2626
|
+
target: 'guard_walls',
|
|
2627
|
+
reason: '未收到主/子代理真实撞墙且无法绕过阻断上报,拒绝生成拆墙申请',
|
|
2628
|
+
outcome: 'rejected',
|
|
2629
|
+
by: 'chief',
|
|
2630
|
+
}, rootId)
|
|
2631
|
+
} else {
|
|
2632
|
+
const activeWalls = listGuardWalls({ cwd: cwdForWall }).filter(w => w && w.scope !== 'paused')
|
|
2633
|
+
for (const rawWr of rawWallRemovalProposals) {
|
|
2634
|
+
if (!rawWr || typeof rawWr !== 'object') continue
|
|
2635
|
+
const reqId = String(rawWr.wallId || rawWr.id || '').trim()
|
|
2636
|
+
const reqTitle = String(rawWr.wallTitle || rawWr.title || '').trim()
|
|
2637
|
+
const matchedWall = activeWalls.find(w =>
|
|
2638
|
+
(reqId && w.id === reqId)
|
|
2639
|
+
|| (reqTitle && w.title === reqTitle),
|
|
2640
|
+
)
|
|
2641
|
+
if (!matchedWall) continue
|
|
2642
|
+
const blockerEv = cleanMultiline(rawWr.blockerEvidence || rawWr.evidence || '', 260)
|
|
2643
|
+
const removeReason = cleanMultiline(rawWr.reason || '', 220)
|
|
2644
|
+
if (!blockerEv || !removeReason) continue
|
|
2645
|
+
const dupWr = ws.suggestions.some(ex =>
|
|
2646
|
+
ex
|
|
2647
|
+
&& ex.status === 'pending'
|
|
2648
|
+
&& ex.kind === 'wall_removal'
|
|
2649
|
+
&& ex.wallRemovalSpec
|
|
2650
|
+
&& ex.wallRemovalSpec.wallId === matchedWall.id,
|
|
2651
|
+
)
|
|
2652
|
+
if (dupWr) continue
|
|
2653
|
+
const actMode = String(rawWr.action || '').trim().toLowerCase() === 'remove' ? 'remove' : 'pause'
|
|
2654
|
+
const patStr = Array.isArray(matchedWall.patterns) ? matchedWall.patterns.join(', ') : ''
|
|
2655
|
+
const sug = normalizeSuggestion({
|
|
2656
|
+
kind: 'wall_removal',
|
|
2657
|
+
fromAgent: '⚠️ 参谋请示拆墙(极低概率 · 阻断复核)',
|
|
2658
|
+
title: `请示${actMode === 'remove' ? '拆除' : '暂挂'}物理墙:${clamp(matchedWall.title, 28)}`,
|
|
2659
|
+
reason: clamp(removeReason, 200),
|
|
2660
|
+
target: 'guard_walls',
|
|
2661
|
+
targetLabel: clamp(matchedWall.title, 36),
|
|
2662
|
+
mode: 'silent',
|
|
2663
|
+
draftText: [
|
|
2664
|
+
`目标物理驻墙:${matchedWall.title} (${matchedWall.id})`,
|
|
2665
|
+
`拦截规则:[${matchedWall.ruleType}] ${patStr}`,
|
|
2666
|
+
`代理阻断依据:${blockerEv}`,
|
|
2667
|
+
`拟批准操作:${actMode === 'remove' ? '永久移除该物理驻墙' : '暂挂休眠该物理驻墙(可随时恢复)'}`,
|
|
2668
|
+
].join('\n'),
|
|
2669
|
+
evidence: blockerEv,
|
|
2670
|
+
wallRemovalSpec: {
|
|
2671
|
+
wallId: matchedWall.id,
|
|
2672
|
+
wallTitle: matchedWall.title,
|
|
2673
|
+
action: actMode,
|
|
2674
|
+
patterns: matchedWall.patterns || [],
|
|
2675
|
+
reason: removeReason,
|
|
2676
|
+
blockerEvidence: blockerEv,
|
|
2677
|
+
reportedBy: _fromLeadRequest ? 'lead/subagent' : 'chief_review',
|
|
2678
|
+
},
|
|
2679
|
+
popup: true,
|
|
2680
|
+
urgency: 'high',
|
|
2681
|
+
})
|
|
2682
|
+
if (sug) {
|
|
2683
|
+
ws.suggestions.push(sug)
|
|
2684
|
+
if (ws.suggestions.length > SUGGESTIONS_CAP) ws.suggestions = ws.suggestions.slice(-SUGGESTIONS_CAP)
|
|
2685
|
+
proposedWallRemovals.push(sug)
|
|
2686
|
+
actionBadges.push(`⚠️ 请示拆墙:${clamp(matchedWall.title, 18)}`)
|
|
2687
|
+
pushAuditToWs(ws, {
|
|
2688
|
+
mode: permissionMode,
|
|
2689
|
+
stage: 'guard_wall',
|
|
2690
|
+
rule: 'wall_removal_requested',
|
|
2691
|
+
decision: 'pending_approval',
|
|
2692
|
+
operation: '参谋呈报人工审批拆墙',
|
|
2693
|
+
target: `${matchedWall.title} (${matchedWall.id})`,
|
|
2694
|
+
reason: clamp(removeReason, 180),
|
|
2695
|
+
outcome: 'pending',
|
|
2696
|
+
by: 'chief',
|
|
2697
|
+
}, rootId)
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
for (const rawInq of rawInquiries) {
|
|
2703
|
+
if (!rawInq || typeof rawInq !== 'object') continue
|
|
2704
|
+
const qText = cleanMultiline(rawInq.question || rawInq.text || '', 500)
|
|
2705
|
+
if (!qText || secretLike(qText)) continue
|
|
2706
|
+
const inqTarget = clamp(rawInq.target || 'lead', 48) || 'lead'
|
|
2707
|
+
const inqTask = upsertTaskLedgerOnWs(ws, {
|
|
2708
|
+
kind: 'inquiry',
|
|
2709
|
+
status: 'awaiting_inquiry',
|
|
2710
|
+
originalText: `问询 @${inqTarget}:${qText}`,
|
|
2711
|
+
forcedTarget: inqTarget,
|
|
2712
|
+
})
|
|
2713
|
+
const inqItem = enqueueChiefInquiryOnWs(ws, {
|
|
2714
|
+
target: inqTarget,
|
|
2715
|
+
question: qText,
|
|
2716
|
+
context: cleanMultiline(rawInq.context || '', 240),
|
|
2717
|
+
taskId: inqTask ? inqTask.taskId : '',
|
|
2718
|
+
})
|
|
2719
|
+
if (inqItem) {
|
|
2720
|
+
createdInquiries.push(inqItem)
|
|
2721
|
+
if (inqTask) {
|
|
2722
|
+
upsertTaskLedgerOnWs(ws, {
|
|
2723
|
+
id: inqTask.taskId,
|
|
2724
|
+
taskId: inqTask.taskId,
|
|
2725
|
+
kind: 'inquiry',
|
|
2726
|
+
status: 'awaiting_inquiry',
|
|
2727
|
+
originalText: inqTask.originalText,
|
|
2728
|
+
inquiryId: inqItem.inquiryId,
|
|
2729
|
+
})
|
|
2730
|
+
}
|
|
2731
|
+
actionBadges.push(`⚡ 问询 @${inqItem.target} #${inqItem.inquiryId}`)
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
if (systemGate.decision === 'allow' || systemGate.decision === 'allow_approved') {
|
|
2113
2736
|
const activeCluster = getLinkedCluster(s, rootId)
|
|
2114
2737
|
appliedFacts = applyFactChanges(ws, numberedFacts, parsed.memoryChanges, 'user', {
|
|
2115
2738
|
originRootId: rootId,
|
|
@@ -2119,12 +2742,56 @@ export async function askOrCommandChief(deps, {
|
|
|
2119
2742
|
actionBadges.push((f.op === 'add' ? '记入:' : f.op === 'edit' ? '修订:' : '移除:') + clamp(f.text, 24))
|
|
2120
2743
|
}
|
|
2121
2744
|
|
|
2122
|
-
for (const
|
|
2745
|
+
for (const rawWp of rawWallProposals) {
|
|
2746
|
+
if (!rawWp || typeof rawWp !== 'object') continue
|
|
2747
|
+
const mappedRuleType = rawWp.ruleType || rawWp.type
|
|
2748
|
+
|| (rawWp.field === 'path' ? 'forbid_path' : (rawWp.field === 'command' ? 'forbid_cmd' : undefined))
|
|
2749
|
+
const wp = {
|
|
2750
|
+
...rawWp,
|
|
2751
|
+
title: rawWp.title || rawWp.name || '',
|
|
2752
|
+
...(mappedRuleType ? { ruleType: mappedRuleType } : {}),
|
|
2753
|
+
patterns: rawWp.patterns || rawWp.pattern || rawWp.rules,
|
|
2754
|
+
}
|
|
2755
|
+
const val = validateGuardWallInput(wp, { cwd: cwdForWall })
|
|
2756
|
+
if (!val || !val.ok || !val.wall) continue
|
|
2757
|
+
if (secretLike(val.wall.title) || val.wall.patterns.some(p => secretLike(p))) continue
|
|
2758
|
+
const dupPendingWall = ws.suggestions.some(
|
|
2759
|
+
existing => existing
|
|
2760
|
+
&& existing.status === 'pending'
|
|
2761
|
+
&& existing.kind === 'guard_wall'
|
|
2762
|
+
&& existing.wallSpec
|
|
2763
|
+
&& existing.wallSpec.title === val.wall.title,
|
|
2764
|
+
)
|
|
2765
|
+
if (dupPendingWall) continue
|
|
2766
|
+
const sug = normalizeSuggestion({
|
|
2767
|
+
kind: 'guard_wall',
|
|
2768
|
+
fromAgent: '🧱 参谋长筑墙提案',
|
|
2769
|
+
title: `拟筑物理墙:${clamp(val.wall.title, 30)}`,
|
|
2770
|
+
reason: clamp(val.wall.reason || '事前硬拦截高危命令或敏感路径,确认后写入 guard-walls 持久落锁。', 180),
|
|
2771
|
+
target: 'guard_walls',
|
|
2772
|
+
targetLabel: val.wall.scope === 'workspace' ? '📁 本工程驻墙' : '🌐 全局随身驻墙',
|
|
2773
|
+
mode: 'silent',
|
|
2774
|
+
draftText: `[${val.wall.ruleType}] ${val.wall.patterns.join(', ')}`,
|
|
2775
|
+
wallSpec: val.wall,
|
|
2776
|
+
})
|
|
2777
|
+
if (sug) {
|
|
2778
|
+
ws.suggestions.push(sug)
|
|
2779
|
+
if (ws.suggestions.length > SUGGESTIONS_CAP) ws.suggestions = ws.suggestions.slice(-SUGGESTIONS_CAP)
|
|
2780
|
+
proposedWalls.push(sug)
|
|
2781
|
+
actionBadges.push(`🧱 呈批驻墙:${clamp(val.wall.title, 18)}`)
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
for (const rawBp of rawBoundProposals) {
|
|
2786
|
+
if (!rawBp) continue
|
|
2787
|
+
const bp = typeof rawBp === 'string'
|
|
2788
|
+
? { field: 'forbidden', item: rawBp, reason: '根据会话上下文提炼的工作边界,请拍板注入。' }
|
|
2789
|
+
: rawBp
|
|
2123
2790
|
if (!bp || typeof bp !== 'object') continue
|
|
2124
2791
|
const rawBpField = String(bp.field || '').trim().toLowerCase()
|
|
2125
2792
|
const normBpField = rawBpField === 'must' ? 'allowed' : rawBpField
|
|
2126
2793
|
const col = ['forbidden', 'allowed', 'notes'].includes(normBpField) ? normBpField : 'forbidden'
|
|
2127
|
-
const itemText = clamp(bp.item || bp.draftText || bp.text || '', 220)
|
|
2794
|
+
const itemText = clamp(bp.item || bp.rule || bp.content || bp.draftText || bp.text || '', 220)
|
|
2128
2795
|
if (!itemText || secretLike(itemText)) continue
|
|
2129
2796
|
const replaces = Array.isArray(bp.replaces)
|
|
2130
2797
|
? bp.replaces.filter(x => typeof x === 'string' && x.trim()).map(x => x.trim().slice(0, 240)).slice(0, 20)
|
|
@@ -2165,16 +2832,32 @@ export async function askOrCommandChief(deps, {
|
|
|
2165
2832
|
}
|
|
2166
2833
|
}
|
|
2167
2834
|
|
|
2835
|
+
for (const rawSug of [...pendingArchiveSuggestions, ...pendingEffortSuggestions]) {
|
|
2836
|
+
const sug = normalizeSuggestion(rawSug)
|
|
2837
|
+
if (!sug) continue
|
|
2838
|
+
const dup = ws.suggestions.some(ex => ex && ex.status === 'pending' && ex.kind === sug.kind && ex.title === sug.title)
|
|
2839
|
+
if (!dup) {
|
|
2840
|
+
ws.suggestions.push(sug)
|
|
2841
|
+
if (ws.suggestions.length > SUGGESTIONS_CAP) ws.suggestions = ws.suggestions.slice(-SUGGESTIONS_CAP)
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2168
2845
|
persistTurnChatAndResume(ws, {
|
|
2169
2846
|
chiefText: replyText,
|
|
2170
2847
|
actions: actionBadges,
|
|
2171
2848
|
elevationObj: finalElevation,
|
|
2172
2849
|
pendingApprovalList: queuedApprovals,
|
|
2850
|
+
thinkingEffort: llmRes.thinkingEffort || '',
|
|
2851
|
+
thinkingEffortMode: llmRes.thinkingEffortMode || effCfg.thinkingEffort || 'auto',
|
|
2173
2852
|
forceReceipt: Boolean(
|
|
2174
2853
|
relayResults.length > 0
|
|
2854
|
+
|| createdInquiries.length > 0
|
|
2855
|
+
|| proposedWalls.length > 0
|
|
2856
|
+
|| proposedWallRemovals.length > 0
|
|
2175
2857
|
|| appliedFacts.length > 0
|
|
2176
2858
|
|| executedBoardOps.length > 0
|
|
2177
2859
|
|| executedArchiveOps.length > 0
|
|
2860
|
+
|| executedEffortOps.length > 0
|
|
2178
2861
|
|| executedNetworkOps.length > 0
|
|
2179
2862
|
|| loopToolRecords.some(r => {
|
|
2180
2863
|
const tName = r && ((r.call && (r.call.tool || r.call.name)) || (r.result && r.result.tool) || r.tool || '')
|
|
@@ -2184,12 +2867,49 @@ export async function askOrCommandChief(deps, {
|
|
|
2184
2867
|
})
|
|
2185
2868
|
})
|
|
2186
2869
|
|
|
2187
|
-
//
|
|
2870
|
+
// Gently wake idle lead/peer for queued inquiries (if currently running, agent/pre-step picks them up without interruption)
|
|
2871
|
+
if (createdInquiries.length > 0 && deps && deps.runtime && typeof deps.runtime.get === 'function') {
|
|
2872
|
+
const agentsSvc = deps.runtime.get('agents')
|
|
2873
|
+
const leadAgent = agentsSvc && typeof agentsSvc.get === 'function' ? agentsSvc.get(rootId) : null
|
|
2874
|
+
if (leadAgent && leadAgent.status && leadAgent.status !== 'running') {
|
|
2875
|
+
for (const inqItem of createdInquiries) {
|
|
2876
|
+
if (!/^(?:lead|主对话)$/i.test(inqItem.target || 'lead')) continue
|
|
2877
|
+
try {
|
|
2878
|
+
const nudgeRes = await deliverCrossMessage(deps, {
|
|
2879
|
+
fromSession: rootId,
|
|
2880
|
+
fromLabel: 'DSH 参谋长 (优先问询)',
|
|
2881
|
+
target: inqItem.target || 'lead',
|
|
2882
|
+
subject: `#${inqItem.inquiryId}`,
|
|
2883
|
+
text: `${inqItem.question}${inqItem.context ? `\n背景:${inqItem.context}` : ''}\n请调用 chief_board({ action: "inquiry.reply", inquiryId: "${inqItem.inquiryId}", text: "..." }) 原路回传,无需中断原计划。`,
|
|
2884
|
+
mode: 'followup',
|
|
2885
|
+
envelopeKind: 'inquiry',
|
|
2886
|
+
taskId: inqItem.inquiryId,
|
|
2887
|
+
recordBoardLog: false,
|
|
2888
|
+
})
|
|
2889
|
+
if (nudgeRes && nudgeRes.deliveredPhysical) {
|
|
2890
|
+
mutateChiefState((s) => {
|
|
2891
|
+
const ws = ensureWorkspace(s, rootId)
|
|
2892
|
+
const rec = Array.isArray(ws.inquiries) && ws.inquiries.find(q => q && q.inquiryId === inqItem.inquiryId)
|
|
2893
|
+
if (rec && rec.status === 'pending') {
|
|
2894
|
+
rec.status = 'delivered'
|
|
2895
|
+
rec.deliveredAt = Date.now()
|
|
2896
|
+
}
|
|
2897
|
+
})
|
|
2898
|
+
}
|
|
2899
|
+
} catch {}
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
// Refresh narrative summary in background if facts, board, archives, or network changed (plus 60s debounced opportunistic refresh on user chat)
|
|
2188
2905
|
const shouldRefreshNarrative = appliedFacts.length > 0
|
|
2189
2906
|
|| executedBoardOps.length > 0
|
|
2190
2907
|
|| executedArchiveOps.length > 0
|
|
2191
2908
|
|| executedNetworkOps.length > 0
|
|
2192
|
-
const freshView = await getChiefView(deps, rootId, {
|
|
2909
|
+
const freshView = await getChiefView(deps, rootId, {
|
|
2910
|
+
autoSummarize: shouldRefreshNarrative,
|
|
2911
|
+
chatTriggered: !_fromLeadRequest,
|
|
2912
|
+
})
|
|
2193
2913
|
const freshBoard = executedBoardOps.length > 0 && deps.boardForSession && deps.boardFileFor
|
|
2194
2914
|
? deps.boardForSession(deps.boardFileFor(rootId))
|
|
2195
2915
|
: undefined
|
|
@@ -2207,14 +2927,20 @@ export async function askOrCommandChief(deps, {
|
|
|
2207
2927
|
ok: true,
|
|
2208
2928
|
reply: replyText,
|
|
2209
2929
|
relays: relayResults,
|
|
2930
|
+
inquiries: createdInquiries,
|
|
2931
|
+
wallProposals: proposedWalls,
|
|
2932
|
+
wallRemovalProposals: proposedWallRemovals,
|
|
2210
2933
|
actionBadges,
|
|
2211
2934
|
memoryChanges: appliedFacts,
|
|
2212
2935
|
boardOps: executedBoardOps,
|
|
2213
2936
|
archiveOps: executedArchiveOps,
|
|
2937
|
+
effortOps: executedEffortOps,
|
|
2214
2938
|
networkOps: executedNetworkOps,
|
|
2215
2939
|
boundProposals: proposedBounds,
|
|
2216
2940
|
toolRecords: loopToolRecords,
|
|
2217
2941
|
pendingApprovals: queuedApprovals,
|
|
2942
|
+
thinkingEffort: llmRes.thinkingEffort || '',
|
|
2943
|
+
thinkingEffortMode: llmRes.thinkingEffortMode || effCfg.thinkingEffort || 'auto',
|
|
2218
2944
|
...(finalElevation ? { elevationRequested: finalElevation } : {}),
|
|
2219
2945
|
permissionMode,
|
|
2220
2946
|
...(freshBoard ? { board: freshBoard } : {}),
|
|
@@ -2511,3 +3237,248 @@ export async function suggestCoreObjectiveWithChief(deps, {
|
|
|
2511
3237
|
llmUsed,
|
|
2512
3238
|
}
|
|
2513
3239
|
}
|
|
3240
|
+
|
|
3241
|
+
/**
|
|
3242
|
+
* Lead-to-Chief direct communication handler (`chief.request` / `mail.send({ target: 'chief' })`).
|
|
3243
|
+
* Applies L0–L3 permission-tiered handling so Lead requests either queue advice + elevation (L0/L1),
|
|
3244
|
+
* queue one-click user approval (L2), or execute & reply directly via Chief (L3).
|
|
3245
|
+
*/
|
|
3246
|
+
export async function handleLeadDirectRequestToChief(deps, {
|
|
3247
|
+
fromSession = '',
|
|
3248
|
+
fromLabel = '主对话 (@lead)',
|
|
3249
|
+
subject = '',
|
|
3250
|
+
text = '',
|
|
3251
|
+
} = {}) {
|
|
3252
|
+
const cleanBody = cleanMultiline(text, 2400)
|
|
3253
|
+
if (!cleanBody) return { ok: false, error: '传话给参谋长的内容不能为空' }
|
|
3254
|
+
const rootId = (deps && typeof deps.resolveRootSessionId === 'function' ? deps.resolveRootSessionId(fromSession) : '') || String(fromSession || 'global')
|
|
3255
|
+
const state = loadChiefState()
|
|
3256
|
+
const ownWs = ensureWorkspace(state, rootId)
|
|
3257
|
+
const effCfg = resolveWorkspaceConfig(state, rootId)
|
|
3258
|
+
const hasChiefRiskAck = hasValidChiefRiskAck(ownWs)
|
|
3259
|
+
const permissionMode = normalizePermissionMode(effCfg.permissionMode || DEFAULT_CHIEF_PERMISSION_MODE, {
|
|
3260
|
+
requireAck: true,
|
|
3261
|
+
hasChiefRiskAck,
|
|
3262
|
+
})
|
|
3263
|
+
const permRank = permissionRank(permissionMode)
|
|
3264
|
+
const summaryTitle = clamp(subject || cleanBody, 48)
|
|
3265
|
+
let ledgerTaskId = ''
|
|
3266
|
+
|
|
3267
|
+
// Rare path: Lead / Subagent reports an insurmountable dynamic guard-wall blocker -> read-only Chief evaluation first; any wall removal still requires explicit human approval across L0-L3
|
|
3268
|
+
const combinedReqText = `${subject || ''} ${cleanBody}`
|
|
3269
|
+
const isWallBlockerEscalation = /(?:撞墙阻断|物理驻墙|物理墙|无法绕过|事前物理拦截|guard_wall|wall-[a-z0-9]+)/i.test(combinedReqText)
|
|
3270
|
+
if (isWallBlockerEscalation) {
|
|
3271
|
+
const cwdNow = resolveSessionWorkspaceCwd(deps, rootId)
|
|
3272
|
+
const activeWallsNow = listGuardWalls({ cwd: cwdNow }).filter(w => w && w.scope !== 'paused')
|
|
3273
|
+
if (activeWallsNow.length > 0) {
|
|
3274
|
+
const evalRes = await askOrCommandChief(deps, {
|
|
3275
|
+
sessionId: rootId,
|
|
3276
|
+
text: `[来自 ${fromLabel} 的撞墙阻断上报 · ${subject || '物理墙评估'}]\n${cleanBody}`,
|
|
3277
|
+
_fromLeadRequest: true,
|
|
3278
|
+
_wallBlockerEscalation: true,
|
|
3279
|
+
})
|
|
3280
|
+
if (evalRes && Array.isArray(evalRes.wallRemovalProposals) && evalRes.wallRemovalProposals.length > 0) {
|
|
3281
|
+
return {
|
|
3282
|
+
ok: true,
|
|
3283
|
+
mode: permissionMode,
|
|
3284
|
+
actionTaken: 'wall_removal_requested',
|
|
3285
|
+
wallRemovalProposals: evalRes.wallRemovalProposals,
|
|
3286
|
+
reply: evalRes.reply || '',
|
|
3287
|
+
...(evalRes.view ? { view: evalRes.view } : {}),
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
mutateChiefState((s) => {
|
|
3294
|
+
const ws = ensureWorkspace(s, rootId)
|
|
3295
|
+
const entry = upsertTaskLedgerOnWs(ws, {
|
|
3296
|
+
kind: permRank < 2 ? 'elevation_resume' : (permRank === 2 ? 'approval_resume' : 'tool_execution'),
|
|
3297
|
+
status: permRank < 2 ? 'awaiting_elevation' : (permRank === 2 ? 'awaiting_approval' : 'running'),
|
|
3298
|
+
originalText: `[主对话直传求助 · ${fromLabel}] ${subject ? subject + ':' : ''}${cleanBody}`,
|
|
3299
|
+
forcedTarget: 'lead',
|
|
3300
|
+
lastReceipt: `收到 ${fromLabel} 直传协同请求,按 ${permissionMode} 权限处置中`,
|
|
3301
|
+
})
|
|
3302
|
+
if (entry) ledgerTaskId = entry.taskId
|
|
3303
|
+
})
|
|
3304
|
+
|
|
3305
|
+
// L0 (advisor) / L1 (assistant): queue readable advice + optional elevation request (never mutate workspace directly)
|
|
3306
|
+
if (permRank < 2) {
|
|
3307
|
+
const elv = requestChiefElevation(rootId, {
|
|
3308
|
+
fromMode: permissionMode,
|
|
3309
|
+
targetMode: 'strategist',
|
|
3310
|
+
reason: `主对话(${fromLabel})请求参谋长协同处置:${clamp(subject || cleanBody, 90)}`,
|
|
3311
|
+
requestedActionSummary: clamp(cleanBody, 160),
|
|
3312
|
+
by: 'chief',
|
|
3313
|
+
})
|
|
3314
|
+
mutateChiefState((s) => {
|
|
3315
|
+
const ws = ensureWorkspace(s, rootId)
|
|
3316
|
+
const sug = normalizeSuggestion({
|
|
3317
|
+
kind: 'advice',
|
|
3318
|
+
fromAgent: '📨 主对话直传求助',
|
|
3319
|
+
title: `参谋建议 · 响应主对话:${clamp(summaryTitle, 32)}`,
|
|
3320
|
+
reason: `主对话主动发起协同请示(当前 ${CHIEF_PERMISSION_META[permissionMode]?.level || permissionMode} 只读/参谋档),请您拍板或批准升档执行。`,
|
|
3321
|
+
target: 'lead',
|
|
3322
|
+
targetLabel: '主对话 (@lead)',
|
|
3323
|
+
mode: 'followup',
|
|
3324
|
+
draftText: clamp(`关于「${subject || '协同请求'}」的参谋建议:请先评估影响范围与验证方案;如已批准升档,我可进一步协调执行。原请求:${cleanBody}`, 420),
|
|
3325
|
+
})
|
|
3326
|
+
if (sug) {
|
|
3327
|
+
ws.suggestions.push(sug)
|
|
3328
|
+
if (ws.suggestions.length > SUGGESTIONS_CAP) ws.suggestions = ws.suggestions.slice(-SUGGESTIONS_CAP)
|
|
3329
|
+
}
|
|
3330
|
+
if (ledgerTaskId) {
|
|
3331
|
+
upsertTaskLedgerOnWs(ws, {
|
|
3332
|
+
id: ledgerTaskId,
|
|
3333
|
+
taskId: ledgerTaskId,
|
|
3334
|
+
kind: 'elevation_resume',
|
|
3335
|
+
status: 'awaiting_elevation',
|
|
3336
|
+
originalText: `[主对话直传求助 · ${fromLabel}] ${cleanBody}`,
|
|
3337
|
+
elevationId: elv ? elv.id : '',
|
|
3338
|
+
lastReceipt: `已生成参谋建议${elv ? '并发起 L2 提权请示' : ''}`,
|
|
3339
|
+
})
|
|
3340
|
+
}
|
|
3341
|
+
ws.chat.push({
|
|
3342
|
+
id: nextId('chat'),
|
|
3343
|
+
role: 'chief',
|
|
3344
|
+
kind: 'receipt',
|
|
3345
|
+
text: [
|
|
3346
|
+
`- 【📨 收到主对话直传请求(当前 ${CHIEF_PERMISSION_META[permissionMode]?.level || permissionMode})】来自 ${fromLabel}${subject ? ` · ${subject}` : ''}`,
|
|
3347
|
+
`- 【请求摘要】${clamp(cleanBody, 220)}`,
|
|
3348
|
+
`- 【处置结果】已生成参谋建议并${elv ? '向您发起「🔐 升至 L2 · 参谋模式」提权请示' : '记入建议栏'};您拍板或提权后即可向主对话投递执行批复。`,
|
|
3349
|
+
].join('\n'),
|
|
3350
|
+
actions: ['主对话直传求助', ...(elv ? ['🔐 请示提权 L2'] : ['💡 已呈报建议'])],
|
|
3351
|
+
at: Date.now(),
|
|
3352
|
+
})
|
|
3353
|
+
if (ws.chat.length > CHAT_CAP) ws.chat = ws.chat.slice(-CHAT_CAP)
|
|
3354
|
+
})
|
|
3355
|
+
return {
|
|
3356
|
+
ok: true,
|
|
3357
|
+
mode: permissionMode,
|
|
3358
|
+
actionTaken: 'suggested_or_elevation_requested',
|
|
3359
|
+
taskId: ledgerTaskId,
|
|
3360
|
+
...(elv ? { elevationRequested: elv } : {}),
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
|
|
3364
|
+
// L2 (strategist): queue actionable approval & suggestion for one-click human confirmation
|
|
3365
|
+
if (permRank === 2) {
|
|
3366
|
+
const replyDraft = `已核准来自主对话的协同请求(${subject || '协同处理'}):请按约定继续推进,并在完成后提交验证证据。`
|
|
3367
|
+
const apr = queueChiefApproval(rootId, {
|
|
3368
|
+
category: 'main_workflow',
|
|
3369
|
+
operationLabel: '响应主对话直接协同请求',
|
|
3370
|
+
targetLabel: '主对话 (@lead)',
|
|
3371
|
+
reason: clamp(subject || '主对话请求参谋长协同处置', 140),
|
|
3372
|
+
impact: '点击「允许本次操作」后,将向主对话投递参谋协同批复执行请求',
|
|
3373
|
+
preview: clamp(cleanBody, 240),
|
|
3374
|
+
kind: 'relay',
|
|
3375
|
+
capabilityScope: buildCapabilityScope({ kind: 'relay', tool: 'relay', target: 'lead' }),
|
|
3376
|
+
payload: {
|
|
3377
|
+
fromSession: rootId,
|
|
3378
|
+
fromLabel: 'DSH 参谋 (获批响应主对话)',
|
|
3379
|
+
target: 'lead',
|
|
3380
|
+
subject: subject || '参谋协同批复',
|
|
3381
|
+
text: replyDraft,
|
|
3382
|
+
mode: 'steer',
|
|
3383
|
+
envelopeKind: 'execution_request',
|
|
3384
|
+
taskId: ledgerTaskId,
|
|
3385
|
+
},
|
|
3386
|
+
by: 'chief',
|
|
3387
|
+
})
|
|
3388
|
+
mutateChiefState((s) => {
|
|
3389
|
+
const ws = ensureWorkspace(s, rootId)
|
|
3390
|
+
const sug = normalizeSuggestion({
|
|
3391
|
+
kind: 'relay',
|
|
3392
|
+
fromAgent: '📨 主对话直传求助',
|
|
3393
|
+
title: `批复主对话:${clamp(summaryTitle, 32)}`,
|
|
3394
|
+
reason: 'L2 参谋模式下已挂入逐项授权弹窗,也可直接点击上方「执行建议」批准投递。',
|
|
3395
|
+
target: 'lead',
|
|
3396
|
+
targetLabel: '主对话 (@lead)',
|
|
3397
|
+
mode: 'steer',
|
|
3398
|
+
draftText: replyDraft,
|
|
3399
|
+
})
|
|
3400
|
+
if (sug) {
|
|
3401
|
+
ws.suggestions.push(sug)
|
|
3402
|
+
if (ws.suggestions.length > SUGGESTIONS_CAP) ws.suggestions = ws.suggestions.slice(-SUGGESTIONS_CAP)
|
|
3403
|
+
}
|
|
3404
|
+
if (ledgerTaskId) {
|
|
3405
|
+
upsertTaskLedgerOnWs(ws, {
|
|
3406
|
+
id: ledgerTaskId,
|
|
3407
|
+
taskId: ledgerTaskId,
|
|
3408
|
+
kind: 'approval_resume',
|
|
3409
|
+
status: 'awaiting_approval',
|
|
3410
|
+
originalText: `[主对话直传求助 · ${fromLabel}] ${cleanBody}`,
|
|
3411
|
+
pendingApprovalIds: apr ? [apr.id] : [],
|
|
3412
|
+
lastReceipt: '已挂入 L2 待确认审批与参谋建议',
|
|
3413
|
+
})
|
|
3414
|
+
}
|
|
3415
|
+
ws.chat.push({
|
|
3416
|
+
id: nextId('chat'),
|
|
3417
|
+
role: 'chief',
|
|
3418
|
+
kind: 'receipt',
|
|
3419
|
+
text: [
|
|
3420
|
+
`- 【📨 收到主对话直传请求(L2 · 参谋逐项授权)】来自 ${fromLabel}${subject ? ` · ${subject}` : ''}`,
|
|
3421
|
+
`- 【请求摘要】${clamp(cleanBody, 220)}`,
|
|
3422
|
+
`- 【处置结果】已生成待确认动作${apr ? `(#${apr.id})` : ''}并弹出授权提示,您确认后将立刻投递给主对话。`,
|
|
3423
|
+
].join('\n'),
|
|
3424
|
+
actions: ['主对话直传求助', '🛡️ 待逐项确认'],
|
|
3425
|
+
at: Date.now(),
|
|
3426
|
+
})
|
|
3427
|
+
if (ws.chat.length > CHAT_CAP) ws.chat = ws.chat.slice(-CHAT_CAP)
|
|
3428
|
+
})
|
|
3429
|
+
return {
|
|
3430
|
+
ok: true,
|
|
3431
|
+
mode: 'strategist',
|
|
3432
|
+
actionTaken: 'queued_for_approval',
|
|
3433
|
+
taskId: ledgerTaskId,
|
|
3434
|
+
approval: apr,
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
// L3 (chief): directly run Chief handling & reply back to @lead via execution_request
|
|
3439
|
+
const execRes = await askOrCommandChief(deps, {
|
|
3440
|
+
sessionId: rootId,
|
|
3441
|
+
text: `[来自 ${fromLabel} 的直接协同请求${subject ? ` · ${subject}` : ''}]\n${cleanBody}`,
|
|
3442
|
+
_fromLeadRequest: true,
|
|
3443
|
+
})
|
|
3444
|
+
const alreadyRelayed = Boolean(execRes && Array.isArray(execRes.relays) && execRes.relays.some(r => r && r.ok))
|
|
3445
|
+
if (!alreadyRelayed && execRes && execRes.reply) {
|
|
3446
|
+
try {
|
|
3447
|
+
await deliverCrossMessage(deps, {
|
|
3448
|
+
fromSession: rootId,
|
|
3449
|
+
fromLabel: 'DSH 参谋长 (L3 协同批复)',
|
|
3450
|
+
target: 'lead',
|
|
3451
|
+
subject: subject || '参谋长协同批复',
|
|
3452
|
+
text: execRes.reply,
|
|
3453
|
+
mode: 'steer',
|
|
3454
|
+
envelopeKind: 'execution_request',
|
|
3455
|
+
taskId: ledgerTaskId,
|
|
3456
|
+
})
|
|
3457
|
+
} catch {}
|
|
3458
|
+
}
|
|
3459
|
+
mutateChiefState((s) => {
|
|
3460
|
+
const ws = ensureWorkspace(s, rootId)
|
|
3461
|
+
if (ledgerTaskId) {
|
|
3462
|
+
upsertTaskLedgerOnWs(ws, {
|
|
3463
|
+
id: ledgerTaskId,
|
|
3464
|
+
taskId: ledgerTaskId,
|
|
3465
|
+
kind: 'tool_execution',
|
|
3466
|
+
status: execRes && execRes.ok === false ? 'failed' : 'completed',
|
|
3467
|
+
originalText: `[主对话直传求助 · ${fromLabel}] ${cleanBody}`,
|
|
3468
|
+
lastReceipt: clamp((execRes && (execRes.reply || execRes.error)) || 'L3 参谋长已完成处置', 220),
|
|
3469
|
+
resolvedAt: Date.now(),
|
|
3470
|
+
})
|
|
3471
|
+
}
|
|
3472
|
+
})
|
|
3473
|
+
return {
|
|
3474
|
+
ok: Boolean(execRes && execRes.ok !== false),
|
|
3475
|
+
mode: 'chief',
|
|
3476
|
+
actionTaken: 'executed_directly',
|
|
3477
|
+
taskId: ledgerTaskId,
|
|
3478
|
+
reply: (execRes && execRes.reply) || '',
|
|
3479
|
+
...(execRes && execRes.view ? { view: execRes.view } : {}),
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
|
|
3483
|
+
registerChiefDirectRequestHook(handleLeadDirectRequestToChief)
|
|
3484
|
+
|