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-models.js
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
SUMMARY_MAX_TOKENS,
|
|
11
11
|
SUMMARY_RETRY_MAX_TOKENS,
|
|
12
12
|
clamp,
|
|
13
|
+
normalizeThinkingEffort,
|
|
14
|
+
resolveAlignedModelEffort,
|
|
13
15
|
resolveWorkspaceConfig,
|
|
14
16
|
loadChiefState,
|
|
15
17
|
mutateChiefState,
|
|
@@ -180,6 +182,75 @@ function profileDefaultModelRef(runtime) {
|
|
|
180
182
|
return ''
|
|
181
183
|
}
|
|
182
184
|
|
|
185
|
+
const modelEffortCache = new Map()
|
|
186
|
+
|
|
187
|
+
export function decideAdaptiveChiefEffort({
|
|
188
|
+
reasonKind = '',
|
|
189
|
+
userText = '',
|
|
190
|
+
isBlankContext = false,
|
|
191
|
+
tactical = {},
|
|
192
|
+
} = {}) {
|
|
193
|
+
const rk = String(reasonKind || '').trim().toLowerCase()
|
|
194
|
+
const txt = String(userText || '').trim()
|
|
195
|
+
|
|
196
|
+
if (rk === 'chat_summary' || rk === 'dream_roam' || rk === 'quick_status' || rk === 'auto_summary') {
|
|
197
|
+
return 'off'
|
|
198
|
+
}
|
|
199
|
+
if (rk === 'hazard_diagnosis' || rk === 'multi_wall_collision') {
|
|
200
|
+
return 'xhigh'
|
|
201
|
+
}
|
|
202
|
+
if (
|
|
203
|
+
rk === 'blank_explore'
|
|
204
|
+
|| rk === 'wall_blocked'
|
|
205
|
+
|| rk === 'strong_intervention'
|
|
206
|
+
|| rk === 'precipitate'
|
|
207
|
+
|| rk === 'distill'
|
|
208
|
+
|| rk === 'craft_wall'
|
|
209
|
+
|| isBlankContext === true
|
|
210
|
+
) {
|
|
211
|
+
if (tactical && tactical.intervention && /(?:架构|根因|死锁|并发|重构|安全审计)/.test(txt)) {
|
|
212
|
+
return 'xhigh'
|
|
213
|
+
}
|
|
214
|
+
return 'high'
|
|
215
|
+
}
|
|
216
|
+
if (txt && /(?:深度|全面|彻底|根因|重构|架构|死锁|并发|安全审计|复盘|仔细想|好好想|正则墙|物理墙)/.test(txt)) {
|
|
217
|
+
return 'high'
|
|
218
|
+
}
|
|
219
|
+
if (rk === 'ask_chat' && txt && txt.length <= 28 && /^(?:在吗|进度|到哪一步|怎么样|状态|你好|看看)/.test(txt)) {
|
|
220
|
+
return 'low'
|
|
221
|
+
}
|
|
222
|
+
return 'medium'
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export async function resolveRouteCapabilities(llm, provider, model) {
|
|
226
|
+
const ref = provider && model ? `${provider}/${model}` : ''
|
|
227
|
+
if (ref && modelEffortCache.has(ref)) {
|
|
228
|
+
const cached = modelEffortCache.get(ref)
|
|
229
|
+
if (Date.now() - cached.at < CATALOG_TTL_MS * 6) return cached.data
|
|
230
|
+
}
|
|
231
|
+
const data = { defaultMaxTokens: 0, efforts: [], defaultEffort: '' }
|
|
232
|
+
try {
|
|
233
|
+
if (llm && typeof llm.resolveModelInfo === 'function' && provider && model) {
|
|
234
|
+
const info = await llm.resolveModelInfo(provider, model)
|
|
235
|
+
if (typeof info?.defaultMaxTokens === 'number' && info.defaultMaxTokens > 0) {
|
|
236
|
+
data.defaultMaxTokens = info.defaultMaxTokens
|
|
237
|
+
}
|
|
238
|
+
if (Array.isArray(info?.reasoning?.efforts)) {
|
|
239
|
+
data.efforts = info.reasoning.efforts.map(e => (
|
|
240
|
+
typeof e === 'string'
|
|
241
|
+
? { id: e, name: e }
|
|
242
|
+
: { id: String(e?.id || ''), name: String(e?.name || e?.id || ''), description: String(e?.description || '') }
|
|
243
|
+
)).filter(e => e.id)
|
|
244
|
+
}
|
|
245
|
+
if (typeof info?.reasoning?.defaultEffort === 'string') {
|
|
246
|
+
data.defaultEffort = info.reasoning.defaultEffort
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} catch {}
|
|
250
|
+
if (ref) modelEffortCache.set(ref, { at: Date.now(), data })
|
|
251
|
+
return data
|
|
252
|
+
}
|
|
253
|
+
|
|
183
254
|
export async function listChiefModels(deps, fresh = false, sessionId = '') {
|
|
184
255
|
const llm = deps.getLlm ? deps.getLlm() : null
|
|
185
256
|
const runtime = deps.runtime
|
|
@@ -297,6 +368,16 @@ export async function listChiefModels(deps, fresh = false, sessionId = '') {
|
|
|
297
368
|
|
|
298
369
|
const picked = pickRouteFromItems(items, selectedRef, followRef, deps, sessionId, registeredProviderIds)
|
|
299
370
|
const resolvedRef = (picked && picked.ref) || selectedRef || followRef || ''
|
|
371
|
+
let supportedEfforts = []
|
|
372
|
+
let defaultEffort = ''
|
|
373
|
+
if (resolvedRef) {
|
|
374
|
+
const parsedResolved = splitModelRef(resolvedRef)
|
|
375
|
+
if (parsedResolved) {
|
|
376
|
+
const caps = await resolveRouteCapabilities(llm, parsedResolved.provider, parsedResolved.model)
|
|
377
|
+
supportedEfforts = caps.efforts || []
|
|
378
|
+
defaultEffort = caps.defaultEffort || ''
|
|
379
|
+
}
|
|
380
|
+
}
|
|
300
381
|
return {
|
|
301
382
|
available: items.length > 0 || Boolean(resolvedRef),
|
|
302
383
|
selectedRef,
|
|
@@ -305,6 +386,8 @@ export async function listChiefModels(deps, fresh = false, sessionId = '') {
|
|
|
305
386
|
defaultRef: followRef,
|
|
306
387
|
resolvedRef,
|
|
307
388
|
resolvedLabel: formatChiefModelLabel(resolvedRef, items, rawProviders, true),
|
|
389
|
+
supportedEfforts,
|
|
390
|
+
defaultEffort,
|
|
308
391
|
models: items,
|
|
309
392
|
}
|
|
310
393
|
}
|
|
@@ -397,21 +480,11 @@ function pickRouteFromItems(items, selectedRef, followRef, deps, sessionId, regi
|
|
|
397
480
|
return queue[0] || null
|
|
398
481
|
}
|
|
399
482
|
|
|
400
|
-
async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MAX_TOKENS, sessionId = '', imageBlocks = []) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const info = await llm.resolveModelInfo(route.provider, route.model)
|
|
406
|
-
if (typeof info?.defaultMaxTokens === 'number' && info.defaultMaxTokens > 0) {
|
|
407
|
-
modelDefaultMaxTokens = info.defaultMaxTokens
|
|
408
|
-
}
|
|
409
|
-
const efforts = info?.reasoning?.efforts
|
|
410
|
-
if (Array.isArray(efforts) && efforts.length > 0) {
|
|
411
|
-
effort = efforts.some(e => e.id === 'off') ? 'off' : efforts[0]?.id
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
} catch {}
|
|
483
|
+
async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MAX_TOKENS, sessionId = '', imageBlocks = [], desiredEffort = 'medium') {
|
|
484
|
+
const caps = await resolveRouteCapabilities(llm, route.provider, route.model)
|
|
485
|
+
const modelDefaultMaxTokens = caps.defaultMaxTokens || 0
|
|
486
|
+
const efforts = Array.isArray(caps.efforts) ? caps.efforts : []
|
|
487
|
+
const effort = resolveAlignedModelEffort(desiredEffort, efforts)
|
|
415
488
|
|
|
416
489
|
const targetBudget = Math.max(Number(maxTokens) || 0, SUMMARY_MAX_TOKENS)
|
|
417
490
|
const firstBudget = modelDefaultMaxTokens ? Math.min(modelDefaultMaxTokens, targetBudget) : targetBudget
|
|
@@ -450,7 +523,7 @@ async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MA
|
|
|
450
523
|
.map(b => b.text)
|
|
451
524
|
.join('\n')
|
|
452
525
|
.trim()
|
|
453
|
-
return { text, finishKind: finish?.kind || '', modelRef: route.ref }
|
|
526
|
+
return { text, finishKind: finish?.kind || '', modelRef: route.ref, thinkingEffort: effort || 'none' }
|
|
454
527
|
}
|
|
455
528
|
|
|
456
529
|
// Pure standalone fallback stream reader (for unit tests / lightweight hosts)
|
|
@@ -472,18 +545,18 @@ async function callOneRoute(llm, route, system, userText, maxTokens = SUMMARY_MA
|
|
|
472
545
|
}
|
|
473
546
|
}
|
|
474
547
|
}
|
|
475
|
-
return { text: parts.join('').trim(), finishKind, modelRef: route.ref }
|
|
548
|
+
return { text: parts.join('').trim(), finishKind, modelRef: route.ref, thinkingEffort: effort || 'none' }
|
|
476
549
|
}
|
|
477
550
|
|
|
478
|
-
let lastRes = { text: '', finishKind: '', modelRef: route.ref }
|
|
551
|
+
let lastRes = { text: '', finishKind: '', modelRef: route.ref, thinkingEffort: effort || 'none' }
|
|
479
552
|
for (let i = 0; i < budgets.length; i += 1) {
|
|
480
553
|
const res = await runOnce(budgets[i])
|
|
481
554
|
lastRes = res
|
|
482
555
|
if (res.text && res.finishKind !== 'max-tokens') {
|
|
483
|
-
return { text: res.text, modelRef: res.modelRef }
|
|
556
|
+
return { text: res.text, modelRef: res.modelRef, thinkingEffort: res.thinkingEffort }
|
|
484
557
|
}
|
|
485
558
|
}
|
|
486
|
-
return { text: lastRes.text, modelRef: lastRes.modelRef }
|
|
559
|
+
return { text: lastRes.text, modelRef: lastRes.modelRef, thinkingEffort: lastRes.thinkingEffort }
|
|
487
560
|
}
|
|
488
561
|
|
|
489
562
|
async function filterVisionRoutes(llm, queue) {
|
|
@@ -515,14 +588,51 @@ export async function callChiefLlm(deps, {
|
|
|
515
588
|
maxTokens = SUMMARY_MAX_TOKENS,
|
|
516
589
|
imageBlocks = [],
|
|
517
590
|
allowTextFallbackOnVisionMiss = false,
|
|
591
|
+
reasonKind = '',
|
|
592
|
+
userText = '',
|
|
593
|
+
isBlankContext = false,
|
|
594
|
+
tactical = null,
|
|
595
|
+
effortOverride = '',
|
|
518
596
|
}) {
|
|
519
597
|
const safeImages = Array.isArray(imageBlocks) ? imageBlocks : []
|
|
598
|
+
const rootSid = (deps && deps.resolveRootSessionId ? deps.resolveRootSessionId(sessionId) : '') || String(sessionId || '').trim()
|
|
599
|
+
const st = loadChiefState()
|
|
600
|
+
const effCfg = resolveWorkspaceConfig(st, rootSid)
|
|
601
|
+
const cfgEffort = normalizeThinkingEffort(effortOverride || effCfg.thinkingEffort || 'auto')
|
|
602
|
+
const thinkingEffortMode = cfgEffort === 'auto' ? 'auto' : 'manual'
|
|
603
|
+
const desiredEffort = cfgEffort === 'auto'
|
|
604
|
+
? decideAdaptiveChiefEffort({
|
|
605
|
+
reasonKind,
|
|
606
|
+
userText: userText || prompt,
|
|
607
|
+
isBlankContext,
|
|
608
|
+
tactical: tactical || effCfg.tacticalModes || {},
|
|
609
|
+
})
|
|
610
|
+
: cfgEffort
|
|
611
|
+
|
|
520
612
|
if (deps && typeof deps.callLlmOverride === 'function') {
|
|
521
|
-
|
|
613
|
+
const overrideRes = await deps.callLlmOverride({
|
|
614
|
+
sessionId,
|
|
615
|
+
system,
|
|
616
|
+
prompt,
|
|
617
|
+
maxTokens,
|
|
618
|
+
imageBlocks: safeImages,
|
|
619
|
+
allowTextFallbackOnVisionMiss,
|
|
620
|
+
reasonKind,
|
|
621
|
+
desiredEffort,
|
|
622
|
+
thinkingEffortMode,
|
|
623
|
+
})
|
|
624
|
+
if (overrideRes && typeof overrideRes === 'object') {
|
|
625
|
+
return {
|
|
626
|
+
thinkingEffort: overrideRes.thinkingEffort || desiredEffort,
|
|
627
|
+
thinkingEffortMode: overrideRes.thinkingEffortMode || thinkingEffortMode,
|
|
628
|
+
...overrideRes,
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return overrideRes
|
|
522
632
|
}
|
|
523
633
|
const llm = deps.getLlm ? deps.getLlm() : null
|
|
524
634
|
if (!llm || typeof llm.stream !== 'function') {
|
|
525
|
-
return { ok: false, error: '当前环境未挂载 LLM 服务' }
|
|
635
|
+
return { ok: false, error: '当前环境未挂载 LLM 服务', thinkingEffort: desiredEffort, thinkingEffortMode }
|
|
526
636
|
}
|
|
527
637
|
const catalog = await listChiefModels(deps, false, sessionId)
|
|
528
638
|
const regSet = typeof llm.listProviders === 'function'
|
|
@@ -530,7 +640,7 @@ export async function callChiefLlm(deps, {
|
|
|
530
640
|
: null
|
|
531
641
|
const baseQueue = buildRouteQueue(catalog.models, catalog.selectedRef, catalog.followRef || catalog.defaultRef, deps, sessionId, regSet)
|
|
532
642
|
if (!baseQueue.length) {
|
|
533
|
-
return { ok: false, error: '未找到可用的参谋长模型,请在 DSH 设置中配置模型供应商' }
|
|
643
|
+
return { ok: false, error: '未找到可用的参谋长模型,请在 DSH 设置中配置模型供应商', thinkingEffort: desiredEffort, thinkingEffortMode }
|
|
534
644
|
}
|
|
535
645
|
|
|
536
646
|
let queue = baseQueue
|
|
@@ -548,6 +658,8 @@ export async function callChiefLlm(deps, {
|
|
|
548
658
|
return {
|
|
549
659
|
ok: false,
|
|
550
660
|
error: '当前参谋长及备选模型均不支持图片输入(仅纯文本),请在右上角切换支持视觉的多模态模型(如 Gemini / Claude / GPT-4o / Qwen-VL 等)后再试。',
|
|
661
|
+
thinkingEffort: desiredEffort,
|
|
662
|
+
thinkingEffortMode,
|
|
551
663
|
}
|
|
552
664
|
}
|
|
553
665
|
}
|
|
@@ -555,22 +667,40 @@ export async function callChiefLlm(deps, {
|
|
|
555
667
|
let lastError = '模型返回内容为空'
|
|
556
668
|
for (const route of queue.slice(0, 4)) {
|
|
557
669
|
try {
|
|
558
|
-
const res = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, sendImages)
|
|
559
|
-
if (res.text)
|
|
670
|
+
const res = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, sendImages, desiredEffort)
|
|
671
|
+
if (res.text) {
|
|
672
|
+
return {
|
|
673
|
+
ok: true,
|
|
674
|
+
text: res.text,
|
|
675
|
+
modelRef: res.modelRef,
|
|
676
|
+
degradedToTextOnly,
|
|
677
|
+
thinkingEffort: res.thinkingEffort || desiredEffort,
|
|
678
|
+
thinkingEffortMode,
|
|
679
|
+
}
|
|
680
|
+
}
|
|
560
681
|
lastError = `${route.ref} 返回内容为空`
|
|
561
682
|
markRouteFailure(route, new Error(lastError))
|
|
562
683
|
} catch (err) {
|
|
563
684
|
lastError = String(err && err.message ? err.message : err)
|
|
564
685
|
if (sendImages.length > 0 && allowTextFallbackOnVisionMiss) {
|
|
565
686
|
try {
|
|
566
|
-
const textRes = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, [])
|
|
567
|
-
if (textRes.text)
|
|
687
|
+
const textRes = await callOneRoute(llm, route, system, prompt, maxTokens, sessionId, [], desiredEffort)
|
|
688
|
+
if (textRes.text) {
|
|
689
|
+
return {
|
|
690
|
+
ok: true,
|
|
691
|
+
text: textRes.text,
|
|
692
|
+
modelRef: textRes.modelRef,
|
|
693
|
+
degradedToTextOnly: true,
|
|
694
|
+
thinkingEffort: textRes.thinkingEffort || desiredEffort,
|
|
695
|
+
thinkingEffortMode,
|
|
696
|
+
}
|
|
697
|
+
}
|
|
568
698
|
} catch {}
|
|
569
699
|
}
|
|
570
700
|
markRouteFailure(route, err)
|
|
571
701
|
}
|
|
572
702
|
}
|
|
573
|
-
return { ok: false, error: lastError, degradedToTextOnly }
|
|
703
|
+
return { ok: false, error: lastError, degradedToTextOnly, thinkingEffort: desiredEffort, thinkingEffortMode }
|
|
574
704
|
}
|
|
575
705
|
|
|
576
706
|
/* -------------------------------------------------------------------------- */
|
package/chief-network.js
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
MAIL_CAP,
|
|
10
10
|
CHIEF_UPDATE_SOURCE,
|
|
11
11
|
CHIEF_RELAY_SOURCE,
|
|
12
|
+
CHIEF_INQUIRY_SOURCE,
|
|
13
|
+
CHIEF_EXEC_REQ_SOURCE,
|
|
12
14
|
persistChiefImagesToWorkspace,
|
|
13
15
|
admitChiefImages,
|
|
14
16
|
nextId,
|
|
@@ -17,6 +19,7 @@ import {
|
|
|
17
19
|
normalizeMail,
|
|
18
20
|
loadChiefState,
|
|
19
21
|
mutateChiefState,
|
|
22
|
+
answerChiefInquiry,
|
|
20
23
|
getLinkedCluster,
|
|
21
24
|
ensureWorkspace,
|
|
22
25
|
clusterView,
|
|
@@ -25,6 +28,12 @@ import {
|
|
|
25
28
|
} from './chief-state.js'
|
|
26
29
|
import { loadDshLlm } from './chief-models.js'
|
|
27
30
|
|
|
31
|
+
let chiefDirectRequestHook = null
|
|
32
|
+
|
|
33
|
+
export function registerChiefDirectRequestHook(fn) {
|
|
34
|
+
chiefDirectRequestHook = typeof fn === 'function' ? fn : null
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
export async function buildMessageEnvelope(text, sourceKind = CHIEF_RELAY_SOURCE, extraSource = {}, imageBlocks = []) {
|
|
29
38
|
const dshLlm = await loadDshLlm()
|
|
30
39
|
const safeImages = Array.isArray(imageBlocks) ? imageBlocks : []
|
|
@@ -244,6 +253,9 @@ export async function deliverCrossMessage(deps, {
|
|
|
244
253
|
text = '',
|
|
245
254
|
subject = '',
|
|
246
255
|
mode = 'steer',
|
|
256
|
+
envelopeKind = 'relay',
|
|
257
|
+
taskId = '',
|
|
258
|
+
inquiryId = '',
|
|
247
259
|
images = [],
|
|
248
260
|
imageBlocks: preAdmittedBlocks = null,
|
|
249
261
|
savedImagePaths: preSavedPaths = null,
|
|
@@ -280,9 +292,100 @@ export async function deliverCrossMessage(deps, {
|
|
|
280
292
|
const imgTag = totalImgCount > 0 ? ` [附图 ×${totalImgCount}]` : ''
|
|
281
293
|
|
|
282
294
|
const rootId = (deps.resolveRootSessionId && deps.resolveRootSessionId(fromSession)) || String(fromSession || directoryRootFallback(fromSession))
|
|
295
|
+
const rawTargetPre = String(target || 'lead').trim().replace(/^@/, '')
|
|
296
|
+
if (/^(?:chief|dsh-chief|参谋长|参谋)$/i.test(rawTargetPre)) {
|
|
297
|
+
const cleanChiefBody = cleanMultiline(text, 2400)
|
|
298
|
+
if (envelopeKind === 'inquiry_reply') {
|
|
299
|
+
if (!cleanChiefBody) return { ok: false, error: 'inquiry.reply 必须提供非空答复文本 (text)' }
|
|
300
|
+
const effInqId = String(inquiryId || taskId || '').trim()
|
|
301
|
+
const ansRes = answerChiefInquiry(rootId || 'global', {
|
|
302
|
+
inquiryId: effInqId,
|
|
303
|
+
answer: cleanChiefBody,
|
|
304
|
+
by: fromLabel,
|
|
305
|
+
})
|
|
306
|
+
if (recordBoardLog && rootId && typeof deps.appendBoardLog === 'function' && ansRes && ansRes.ok && ansRes.inquiry) {
|
|
307
|
+
deps.appendBoardLog(rootId, `⚡ ${fromLabel} 已原路回传问询 #${ansRes.inquiry.inquiryId}`, fromLabel)
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
ok: Boolean(ansRes && ansRes.ok),
|
|
311
|
+
target: 'DSH 参谋长',
|
|
312
|
+
targetId: 'chief',
|
|
313
|
+
deliveryMode: 'inquiry-reply',
|
|
314
|
+
inquiryAnswered: ansRes && ansRes.inquiry ? ansRes.inquiry : null,
|
|
315
|
+
continueOwnWork: true,
|
|
316
|
+
...(ansRes && !ansRes.ok ? { error: ansRes.error } : {}),
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (!cleanChiefBody) return { ok: false, error: '传话给参谋长的内容不能为空' }
|
|
320
|
+
const chiefMail = normalizeMail({
|
|
321
|
+
id: nextId('mail'),
|
|
322
|
+
from: fromLabel,
|
|
323
|
+
fromSession,
|
|
324
|
+
fromRootId: rootId,
|
|
325
|
+
to: 'chief',
|
|
326
|
+
toSession: 'chief',
|
|
327
|
+
toRootId: rootId,
|
|
328
|
+
participantRoots: rootId ? [rootId] : [],
|
|
329
|
+
channelType: 'internal',
|
|
330
|
+
subject: subject || '主对话求助与协同请求',
|
|
331
|
+
text: cleanChiefBody,
|
|
332
|
+
mode: mode || 'followup',
|
|
333
|
+
deliveredPhysical: true,
|
|
334
|
+
readBy: ['chief'],
|
|
335
|
+
at: Date.now(),
|
|
336
|
+
})
|
|
337
|
+
mutateChiefState((state) => {
|
|
338
|
+
const ws = ensureWorkspace(state, rootId || 'global')
|
|
339
|
+
if (chiefMail) {
|
|
340
|
+
ws.mailbox.push(chiefMail)
|
|
341
|
+
if (ws.mailbox.length > MAIL_CAP) ws.mailbox = ws.mailbox.slice(-MAIL_CAP)
|
|
342
|
+
}
|
|
343
|
+
})
|
|
344
|
+
if (recordBoardLog && rootId && typeof deps.appendBoardLog === 'function') {
|
|
345
|
+
deps.appendBoardLog(rootId, `📨 ${fromLabel} → @参谋长:${clamp(cleanChiefBody, 56)}`, fromLabel)
|
|
346
|
+
}
|
|
347
|
+
if (chiefDirectRequestHook) {
|
|
348
|
+
try {
|
|
349
|
+
const hookRes = await chiefDirectRequestHook(deps, {
|
|
350
|
+
fromSession: rootId || fromSession,
|
|
351
|
+
fromLabel,
|
|
352
|
+
subject,
|
|
353
|
+
text: cleanChiefBody,
|
|
354
|
+
mail: chiefMail,
|
|
355
|
+
})
|
|
356
|
+
if (hookRes && typeof hookRes === 'object') {
|
|
357
|
+
return {
|
|
358
|
+
ok: hookRes.ok !== false,
|
|
359
|
+
target: 'DSH 参谋长',
|
|
360
|
+
targetId: 'chief',
|
|
361
|
+
deliveryMode: 'chief-direct-request',
|
|
362
|
+
deliveredPhysical: true,
|
|
363
|
+
mail: chiefMail,
|
|
364
|
+
...hookRes,
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
} catch (err) {
|
|
368
|
+
return {
|
|
369
|
+
ok: false,
|
|
370
|
+
target: 'DSH 参谋长',
|
|
371
|
+
mail: chiefMail,
|
|
372
|
+
error: String(err && err.message ? err.message : err),
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
ok: true,
|
|
378
|
+
target: 'DSH 参谋长',
|
|
379
|
+
targetId: 'chief',
|
|
380
|
+
deliveryMode: 'chief-mailbox',
|
|
381
|
+
deliveredPhysical: true,
|
|
382
|
+
mail: chiefMail,
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
283
386
|
const directory = await listPeerDirectory(deps, rootId || fromSession)
|
|
284
387
|
const senderRootId = rootId || directory.rootId || ''
|
|
285
|
-
const rawTarget =
|
|
388
|
+
const rawTarget = rawTargetPre
|
|
286
389
|
|
|
287
390
|
// Broadcast support: 'all' / '全体' / 'team' (deduplicated single mailbox record for clean drawer UI)
|
|
288
391
|
if (['all', 'team', '全体', '所有人'].includes(rawTarget.toLowerCase())) {
|
|
@@ -430,6 +533,8 @@ export async function deliverCrossMessage(deps, {
|
|
|
430
533
|
text: effectiveText,
|
|
431
534
|
subject,
|
|
432
535
|
mode,
|
|
536
|
+
envelopeKind,
|
|
537
|
+
taskId,
|
|
433
538
|
imageBlocks: admittedBlocks,
|
|
434
539
|
savedImagePaths: savedPaths,
|
|
435
540
|
recordBoardLog,
|
|
@@ -448,6 +553,8 @@ async function deliverSinglePeer(deps, directory, peer, {
|
|
|
448
553
|
text,
|
|
449
554
|
subject,
|
|
450
555
|
mode,
|
|
556
|
+
envelopeKind = 'relay',
|
|
557
|
+
taskId = '',
|
|
451
558
|
imageBlocks = [],
|
|
452
559
|
savedImagePaths = [],
|
|
453
560
|
recordBoardLog,
|
|
@@ -462,10 +569,17 @@ async function deliverSinglePeer(deps, directory, peer, {
|
|
|
462
569
|
const imgSuffix = imgCount > 0 ? ` [附图 ×${imgCount}]` : ''
|
|
463
570
|
const imgNoticeBlock = buildSavedImageNotice(safePaths)
|
|
464
571
|
const textWithImagePaths = imgNoticeBlock ? `${text}\n${imgNoticeBlock}` : text
|
|
465
|
-
const headerTag =
|
|
466
|
-
? `[
|
|
467
|
-
:
|
|
468
|
-
|
|
572
|
+
const headerTag = envelopeKind === 'execution_request'
|
|
573
|
+
? `[EXECUTION_REQUEST${taskId ? ' #' + taskId : ''} · 来自 ${fromLabel}]`
|
|
574
|
+
: (envelopeKind === 'inquiry'
|
|
575
|
+
? `[INQUIRY${taskId ? ' #' + taskId : ''} · DSH 参谋长优先问询]`
|
|
576
|
+
: (mode === 'steer'
|
|
577
|
+
? `[DSH 参谋长插话 · 来自 ${fromLabel}]`
|
|
578
|
+
: `[DSH 参谋长递话 · 来自 ${fromLabel}]`))
|
|
579
|
+
const footerGuide = envelopeKind === 'inquiry'
|
|
580
|
+
? '(请顺手调用 chief_board({ action: "inquiry.reply", text: "…" }) 原路作答,无需中断手头当前任务!)'
|
|
581
|
+
: `(如遇到需要参谋长协调、建议、或提权执行的需求,可调用 chief_board({ action: "chief.request", text: "…" }) 或 mail.send({ target: "chief", text: "…" }))`
|
|
582
|
+
const formatted = `${headerTag}${subject ? ' ' + subject : ''}\n${textWithImagePaths}\n\n${footerGuide}`
|
|
469
583
|
|
|
470
584
|
let deliveredPhysical = false
|
|
471
585
|
let deliveryMode = 'mailbox-queued'
|
|
@@ -507,10 +621,16 @@ async function deliverSinglePeer(deps, directory, peer, {
|
|
|
507
621
|
} catch {}
|
|
508
622
|
}
|
|
509
623
|
if (targetAgent) {
|
|
510
|
-
const
|
|
624
|
+
const envelopeSourceKind = envelopeKind === 'execution_request'
|
|
625
|
+
? CHIEF_EXEC_REQ_SOURCE
|
|
626
|
+
: (envelopeKind === 'inquiry' ? CHIEF_INQUIRY_SOURCE : CHIEF_RELAY_SOURCE)
|
|
627
|
+
const envelope = await buildMessageEnvelope(formatted, envelopeSourceKind, {
|
|
511
628
|
senderName: fromLabel,
|
|
512
629
|
senderSessionId: fromSession || undefined,
|
|
513
|
-
role:
|
|
630
|
+
role: envelopeKind === 'execution_request'
|
|
631
|
+
? 'execution_request'
|
|
632
|
+
: (envelopeKind === 'inquiry' ? 'inquiry' : (mode === 'steer' ? 'steer' : 'relay')),
|
|
633
|
+
...(taskId ? { taskId } : {}),
|
|
514
634
|
}, safeBlocks)
|
|
515
635
|
try {
|
|
516
636
|
if (mode === 'steer' && targetAgent.status === 'running' && typeof targetAgent.steer === 'function') {
|
|
@@ -618,10 +738,35 @@ export async function consumePreStepDelta(deps, agent) {
|
|
|
618
738
|
)
|
|
619
739
|
|
|
620
740
|
const deltaLines = []
|
|
741
|
+
let hasPriorityInquiry = false
|
|
621
742
|
mutateChiefState((state) => {
|
|
622
743
|
const view = clusterView(state, rootId)
|
|
623
744
|
const ownWs = ensureWorkspace(state, rootId)
|
|
624
745
|
|
|
746
|
+
// 0. Highest priority: DSH Chief Inquiry Channel (answer without interrupting own task!)
|
|
747
|
+
if (Array.isArray(ownWs.inquiries)) {
|
|
748
|
+
const nowInq = Date.now()
|
|
749
|
+
for (const inq of ownWs.inquiries) {
|
|
750
|
+
if (!inq || inq.status !== 'pending') continue
|
|
751
|
+
if (inq.expiresAt && nowInq > inq.expiresAt) {
|
|
752
|
+
inq.status = 'expired'
|
|
753
|
+
continue
|
|
754
|
+
}
|
|
755
|
+
const tLower = String(inq.target || 'lead').toLowerCase()
|
|
756
|
+
const matchesMe = myHandles.has(tLower) || (!identity?.isChild && tLower === 'lead')
|
|
757
|
+
if (!matchesMe) continue
|
|
758
|
+
inq.status = 'delivered'
|
|
759
|
+
inq.deliveredAt = nowInq
|
|
760
|
+
hasPriorityInquiry = true
|
|
761
|
+
deltaLines.push(
|
|
762
|
+
`⚡ [INQUIRY #${inq.inquiryId}${inq.taskId ? ' / ' + inq.taskId : ''} · DSH 参谋长优先问询 · 答复后继续原动作勿中断]`
|
|
763
|
+
+ `\n 问题:${inq.question}`
|
|
764
|
+
+ (inq.context ? `\n 背景:${inq.context}` : '')
|
|
765
|
+
+ `\n ↳ 请在当前回合顺手调用 chief_board({ action: "inquiry.reply", inquiryId: "${inq.inquiryId}", text: "基于真实代码与状态的准确答复" }) 原路回传,然后立即继续你刚才的工作,切勿打断当前计划!`,
|
|
766
|
+
)
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
625
770
|
// 1. Unread mailbox messages addressed to this session/handle (STRICT cluster isolation: ignore detached external peers!)
|
|
626
771
|
for (const mail of view.mailbox) {
|
|
627
772
|
if (mail.detachedFromCluster) continue
|
|
@@ -675,7 +820,11 @@ export async function consumePreStepDelta(deps, agent) {
|
|
|
675
820
|
...deltaLines,
|
|
676
821
|
].join('\n')
|
|
677
822
|
|
|
678
|
-
return buildMessageEnvelope(
|
|
823
|
+
return buildMessageEnvelope(
|
|
824
|
+
text,
|
|
825
|
+
hasPriorityInquiry ? CHIEF_INQUIRY_SOURCE : CHIEF_UPDATE_SOURCE,
|
|
826
|
+
{ form: hasPriorityInquiry ? 'priority_inquiry' : 'snapshot' },
|
|
827
|
+
)
|
|
679
828
|
}
|
|
680
829
|
|
|
681
830
|
/* -------------------------------------------------------------------------- */
|