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/chief-view.js CHANGED
@@ -5,11 +5,13 @@
5
5
  */
6
6
 
7
7
  import crypto from 'node:crypto'
8
- import { stripToolCallMarkup } from './chief-executor.js'
8
+ import { stripToolCallMarkup, listGuardWalls } from './chief-executor.js'
9
9
  import {
10
10
  AUTO_SUMMARY_COOLDOWN_MS,
11
+ CHAT_OPPORTUNISTIC_SUMMARY_COOLDOWN_MS,
11
12
  SUMMARY_MAX_TOKENS,
12
13
  collectChiefVisibleArchives,
14
+ resolveSessionWorkspaceCwd,
13
15
  clamp,
14
16
  resolveWorkspaceConfig,
15
17
  loadChiefState,
@@ -20,6 +22,9 @@ import {
20
22
  shortAgentBriefName,
21
23
  stripCheckpointNoise,
22
24
  isInternalCheckpointNoise,
25
+ beginChiefActiveWork,
26
+ endChiefActiveWork,
27
+ getChiefActiveWork,
23
28
  } from './chief-state.js'
24
29
  import { listChiefModels, callChiefLlm } from './chief-models.js'
25
30
  import { collectClusterPeerProgress, listPeerDirectory } from './chief-network.js'
@@ -258,28 +263,30 @@ function buildNarrativeInput({ board, facts, cluster, targets, peerProgress = []
258
263
  const dGlob = Array.isArray(archiveDigest.deskGlobalItems) ? archiveDigest.deskGlobalItems : []
259
264
  const dFlip = Array.isArray(archiveDigest.deskFlippedItems) ? archiveDigest.deskFlippedItems : []
260
265
  const mGlob = Array.isArray(archiveDigest.mountedGlobalItems) ? archiveDigest.mountedGlobalItems : []
261
- const sw = archiveDigest.sealedWatch || {}
266
+ const sAll = Array.isArray(archiveDigest.sessionItems) ? archiveDigest.sessionItems : []
267
+ const gHooks = Array.isArray(archiveDigest.globalHookIndex) ? archiveDigest.globalHookIndex : []
268
+ const recentWatch = Array.isArray(archiveDigest.recentlyUnpinnedWatch) ? archiveDigest.recentlyUnpinnedWatch : []
262
269
  const deskAll = [
263
270
  ...dSess.map(it => `[桌面·本局(主可见)] 《${clamp(it.title, 40)}》:${clamp(it.summary || it.body, 140)}`),
264
271
  ...dGlob.map(it => `[桌面·全局(主可见)] 《${clamp(it.title, 40)}》:${clamp(it.summary || it.body, 140)}`),
265
- ...dFlip.map(it => `[桌面·沉淀(主可见)] 《${clamp(it.title, 40)}》:${clamp(it.summary || it.rawBody, 140)}`),
272
+ ...dFlip.map(it => `[桌面·冷藏已翻牌(主可见)] 《${clamp(it.title, 40)}》:${clamp(it.summary || it.rawBody, 140)}`),
266
273
  ]
267
274
  if (deskAll.length > 0) {
268
- lines.push('', '【当前摆上桌面备选(重点强调,主对话与参谋长共同可见)】', ...deskAll.slice(0, 8).map(x => '- ' + x))
275
+ lines.push('', '【当前认知桌面置顶(主对话与参谋长共同可见)】', ...deskAll.slice(0, 6).map(x => '- ' + x))
269
276
  }
270
277
  if (mGlob.length > 0) {
271
- lines.push('', '【参谋长单独参阅中的全局档案(主对话不可见)】')
278
+ lines.push('', '【参谋长已拉阅的全局档案(主对话不可见)】')
272
279
  for (const it of mGlob.slice(0, 5)) {
273
280
  lines.push(`- [全局参阅] 《${clamp(it.title, 40)}》:${clamp(it.summary || it.body, 120)}`)
274
281
  }
275
282
  }
276
- const sealedLines = [
277
- ...((sw.sessionSealed || []).slice(0, 4).map(it => `- [本局封存·仅参谋关注] 《${clamp(it.title, 36)}》:${clamp(it.summary, 90)}`)),
278
- ...((sw.globalSealed || []).slice(0, 4).map(it => `- [全局封存·仅参谋关注] 《${clamp(it.title, 36)}》:${clamp(it.summary, 90)}`)),
279
- ...((sw.precipSealed || []).slice(0, 3).map(it => `- [沉淀封存·仅参谋关注] 《${clamp(it.title, 36)}》:${clamp(it.summary, 90)}`)),
283
+ const vaultIndexLines = [
284
+ ...sAll.filter(it => !it.takenOut).slice(0, 6).map(it => `- [本局档案·参谋随时可读] 《${clamp(it.title, 36)}》${it.hasHook ? '🪝[' + (it.hookKeywords || []).slice(0, 3).join('·') + ']' : '(待织钩)'}:${clamp(it.summary, 90)}`),
285
+ ...gHooks.slice(0, 5).map(it => `- [全局钩子·参谋见钩可拉] 《${clamp(it.title, 36)}》🪝[${(it.hookKeywords || []).slice(0, 3).join('·')}] ${clamp(it.hookCue, 60)}`),
286
+ ...recentWatch.slice(0, 3).map(w => `- [近期撤下桌面·待观察] 《${clamp(w.title, 36)}》`),
280
287
  ]
281
- if (sealedLines.length > 0) {
282
- lines.push('', '【参谋长后台守望的三库封存索引(主对话上下文零注入)】', ...sealedLines)
288
+ if (vaultIndexLines.length > 0) {
289
+ lines.push('', '【参谋长后台档案柜与钩子索引(未置顶桌面,主对话不注入)】', ...vaultIndexLines)
283
290
  }
284
291
  }
285
292
 
@@ -357,7 +364,7 @@ function buildFallbackNarrative({ board, facts, targets, peerProgress = [], conc
357
364
 
358
365
  export const summarizingLocks = new Map()
359
366
 
360
- export async function getChiefView(deps, sessionId, { regenerate = false, autoSummarize = false, syncHandoff = undefined, _skipAutoPilotCheck = false } = {}) {
367
+ export async function getChiefView(deps, sessionId, { regenerate = false, autoSummarize = false, chatTriggered = false, syncHandoff = undefined, _skipAutoPilotCheck = false } = {}) {
361
368
  const rootId = deps.resolveRootSessionId(sessionId) || String(sessionId || 'global')
362
369
  const directory = await listPeerDirectory(deps, rootId)
363
370
  const board = deps.boardForSession(deps.boardFileFor(rootId))
@@ -365,7 +372,7 @@ export async function getChiefView(deps, sessionId, { regenerate = false, autoSu
365
372
  const view = clusterView(state, rootId)
366
373
  const modelsInfo = await listChiefModels(deps, false, rootId)
367
374
  const effCfgBefore = resolveWorkspaceConfig(state, rootId)
368
- const paceMode = effCfgBefore.paceMode || 'manual'
375
+ const runMode = effCfgBefore.runMode || 'off'
369
376
  const isConciseBrief = Boolean(effCfgBefore.tacticalModes && effCfgBefore.tacticalModes.conciseBrief)
370
377
  const currentSig = view.clusterSig || computeClusterSig(directory.cluster)
371
378
  const peerProgress = directory.cluster.length > 1
@@ -396,17 +403,23 @@ export async function getChiefView(deps, sessionId, { regenerate = false, autoSu
396
403
  const lastSummaryAt = Number((view.narrative && view.narrative.at) || 0)
397
404
  const isFresh = !rawInput || (hasSaved && view.narrative.hash === inputHash)
398
405
  const cooledForAuto = Date.now() - lastSummaryAt >= AUTO_SUMMARY_COOLDOWN_MS
399
- const allowBackgroundSummary = paceMode === 'auto' && autoSummarize && !isFresh && cooledForAuto
400
-
401
- // Human-paced rule: ONLY call LLM when operator explicitly clicked Regenerate (`regenerate: true`),
402
- // OR when operator explicitly chose `paceMode === 'auto'` AND the 5-minute cooldown has elapsed!
403
- if (rawInput && (regenerate || allowBackgroundSummary) && modelsInfo.available && !summarizingLocks.has(rootId)) {
406
+ const cooledForChat = Date.now() - lastSummaryAt >= CHAT_OPPORTUNISTIC_SUMMARY_COOLDOWN_MS
407
+ const allowBackgroundSummary = runMode === 'managed' && autoSummarize && !isFresh && cooledForAuto
408
+ const allowChatSummary = Boolean(chatTriggered) && !isFresh && cooledForChat
409
+
410
+ // Opportunistically refresh stale narrative in background after Chief chats (60s debounce),
411
+ // explicitly on Regenerate, or on autoSummarize cooldown.
412
+ if (rawInput && (regenerate || allowBackgroundSummary || allowChatSummary) && modelsInfo.available && !summarizingLocks.has(rootId)) {
413
+ const bgSummaryWorkId = getChiefActiveWork(rootId)
414
+ ? ''
415
+ : beginChiefActiveWork(rootId, { tone: 'neon', tab: 'chief', label: '参谋长正在自动提炼全局摘要中...' })
404
416
  const job = (async () => {
405
417
  const sysPrompt = isConciseBrief
406
418
  ? (NARRATIVE_SYSTEM + CONCISE_BRIEF_NARRATIVE_EXTRA)
407
419
  : NARRATIVE_SYSTEM
408
420
  const res = await callChiefLlm(deps, {
409
421
  sessionId: rootId,
422
+ reasonKind: chatTriggered ? 'chat_summary' : 'auto_summary',
410
423
  system: sysPrompt,
411
424
  prompt: rawInput + (isConciseBrief
412
425
  ? '\n\n请开启【极简战报模式】:分结构列出多个简明短句,不写具体数字参数,精确概括现状:'
@@ -428,6 +441,7 @@ export async function getChiefView(deps, sessionId, { regenerate = false, autoSu
428
441
  }
429
442
  })().finally(() => {
430
443
  summarizingLocks.delete(rootId)
444
+ if (bgSummaryWorkId) endChiefActiveWork(rootId, bgSummaryWorkId)
431
445
  })
432
446
  summarizingLocks.set(rootId, job)
433
447
  if (regenerate) {
@@ -489,8 +503,8 @@ export async function getChiefView(deps, sessionId, { regenerate = false, autoSu
489
503
  !_skipAutoPilotCheck
490
504
  && rootId
491
505
  && rootId !== 'global'
492
- && effectiveConfigBeforeStop.autoPilot
493
- && effectiveConfigBeforeStop.paceMode === 'auto'
506
+ && (effectiveConfigBeforeStop.autoPilot || effectiveConfigBeforeStop.runMode === 'managed')
507
+ && effectiveConfigBeforeStop.runMode === 'managed'
494
508
  && !effectiveConfigBeforeStop.stopped
495
509
  ) {
496
510
  if (idleAutoPilotHook) {
@@ -548,6 +562,10 @@ export async function getChiefView(deps, sessionId, { regenerate = false, autoSu
548
562
  chiefRiskAck: ownWs.chiefRiskAck ? { ...ownWs.chiefRiskAck } : null,
549
563
  pendingApprovals: (Array.isArray(ownWs.pendingApprovals) ? ownWs.pendingApprovals : []).slice(-15).reverse(),
550
564
  pendingElevation: ownWs.pendingElevation ? { ...ownWs.pendingElevation } : null,
565
+ taskLedger: (Array.isArray(ownWs.taskLedger) ? ownWs.taskLedger : []).slice(-15).reverse(),
566
+ inquiries: (Array.isArray(ownWs.inquiries) ? ownWs.inquiries : []).slice(-12).reverse(),
567
+ guardWalls: listGuardWalls({ cwd: resolveSessionWorkspaceCwd(deps, rootId) }),
568
+ activeWork: getChiefActiveWork(rootId),
551
569
  auditLog: (Array.isArray(ownWs.auditLog) ? ownWs.auditLog : []).slice(-50).reverse(),
552
570
  }
553
571
  }