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.
@@ -10,6 +10,7 @@ import {
10
10
  POINTS_CAP,
11
11
  PRECIPITATED_CAP,
12
12
  SECRET_PATTERN,
13
+ DEFAULT_ARCHIVE_FOLDERS,
13
14
  nextId,
14
15
  str,
15
16
  clamp,
@@ -26,6 +27,7 @@ import {
26
27
  normalizeTags,
27
28
  firstMeaningfulSentence,
28
29
  extractStructuredPoints,
30
+ deriveHookFromStructuredItem,
29
31
  invokeArchiveMutatorHook,
30
32
  } from './archive-core.js'
31
33
  import { loadGlobalVaultRaw, loadArchiveStore } from './archive-cabinets.js'
@@ -42,6 +44,17 @@ export function hasAnyPrecipitatedFilesOnDisk(targetOpt) {
42
44
  }
43
45
  }
44
46
 
47
+ function mapPrecipitatedCategoryToFolder(category = '', rawFolder = '') {
48
+ const f = str(rawFolder, '').trim()
49
+ if (f) return f.slice(0, 64)
50
+ const cat = str(category, '').trim().toLowerCase()
51
+ if (cat === 'coords' || cat === 'env') return 'coords'
52
+ if (cat === 'incidents' || cat === 'troubleshooting' || cat === 'pitfalls') return 'incidents'
53
+ if (cat === 'contracts' || cat === 'architecture' || cat === 'contract') return 'contracts'
54
+ if (cat === 'plans' || cat === 'workflow') return 'plans'
55
+ return 'ops'
56
+ }
57
+
45
58
  function normalizePrecipitatedEntry(raw) {
46
59
  if (!raw || typeof raw !== 'object') return null
47
60
  const title = clamp(raw.title || '', 180)
@@ -51,8 +64,22 @@ function normalizePrecipitatedEntry(raw) {
51
64
  .map((p, idx) => normalizePoint(p, idx))
52
65
  .filter(Boolean)
53
66
  .slice(0, POINTS_CAP)
54
- const validCategories = ['coords', 'incidents', 'contracts', 'ops', 'plans', 'architecture', 'env', 'contract', 'troubleshooting', 'workflow', 'general']
67
+ const validCategories = ['coords', 'incidents', 'contracts', 'ops', 'plans', 'architecture', 'env', 'contract', 'troubleshooting', 'workflow', 'patterns', 'pitfalls', 'toolchain', 'general']
55
68
  const category = validCategories.includes(raw.category) ? raw.category : 'general'
69
+ const folder = mapPrecipitatedCategoryToFolder(category, raw.folder)
70
+ const paperclip = ['gold', 'silver', 'copper'].includes(raw.paperclip) ? raw.paperclip : 'gold'
71
+ const tags = normalizeTags(Array.isArray(raw.tags) ? raw.tags : [])
72
+ const summary = clamp(raw.summary || (points[0] && points[0].cue) || firstMeaningfulSentence(rawBody) || title, 180)
73
+ const normPoints = points.length ? points : extractStructuredPoints(title, rawBody)
74
+ const hook = deriveHookFromStructuredItem({
75
+ ...raw,
76
+ title: title || '跨会话可复用工程经验',
77
+ summary,
78
+ folder,
79
+ tags,
80
+ points: normPoints,
81
+ body: rawBody,
82
+ }, true)
56
83
  const flippedOutSessions = Array.isArray(raw.flippedOutSessions)
57
84
  ? [...new Set(raw.flippedOutSessions.map(s => str(s, '').trim()).filter(Boolean))].slice(0, 32)
58
85
  : []
@@ -61,15 +88,20 @@ function normalizePrecipitatedEntry(raw) {
61
88
  id: str(raw.id, '').trim() || nextId('prec'),
62
89
  title: title || '跨会话可复用工程经验',
63
90
  category,
64
- summary: clamp(raw.summary || (points[0] && points[0].cue) || firstMeaningfulSentence(rawBody) || title, 180),
65
- points: points.length ? points : extractStructuredPoints(title, rawBody),
91
+ folder,
92
+ paperclip,
93
+ summary,
94
+ points: normPoints,
66
95
  rawBody,
67
96
  purified: raw.purified !== false,
68
97
  sourceCabinetId: str(raw.sourceCabinetId || raw.sourceCabinet, '').trim(),
69
98
  sourceDrawer: str(raw.sourceDrawer, '').trim(),
70
99
  sourceSession: str(raw.sourceSession, '').trim(),
71
100
  sourceTitles: Array.isArray(raw.sourceTitles) ? raw.sourceTitles.map(t => clamp(t, 80)).slice(0, 40) : [],
72
- tags: normalizeTags(Array.isArray(raw.tags) ? raw.tags : []),
101
+ tags,
102
+ hasHook: true,
103
+ hookKeywords: hook.hookKeywords,
104
+ hookCue: hook.hookCue,
73
105
  flippedOutSessions,
74
106
  by: clamp(raw.by || 'chief', 40),
75
107
  createdAt: Number(raw.createdAt) || Date.now(),
@@ -249,15 +281,21 @@ export function copyPrecipitatedToVault(projectKey = 'proj-default', payload = {
249
281
  }
250
282
  }
251
283
 
252
- /** Listed ONLY for Chief background sealed-archive watch (never injected into Lead prompt unless placed on desk). */
253
- export function collectSealedWatchSummary(rootSessionId = '', projectKey = 'proj-default', targetOpt, opts = {}) {
284
+ /**
285
+ * Listed ONLY for Chief background hook/sealed-archive watch (never injected into Lead prompt unless placed on desk).
286
+ * Three-tier hook contract:
287
+ * - Session vault: Chief always sees session sealed entries (Lead sees only Chief-curated hooks).
288
+ * - Global vault: Chief sees ONLY entries that already have Chief-curated hooks (`hasHook === true`), zero raw leak!
289
+ * - Precipitated vault: 100% human-only (0 disk read, 0 hook leak to Chief or Lead).
290
+ */
291
+ export function collectSealedWatchSummary(rootSessionId = '', _projectKey = 'proj-default', targetOpt, opts = {}) {
254
292
  const sid = cleanRootSessionId(rootSessionId)
255
293
  const base = resolveTargetOpts(targetOpt)
256
294
  const capPerVault = Math.max(2, Math.min(Number(opts.limitPerVault) || 8, 16))
257
295
 
258
296
  let sessionSealed = []
259
297
  let globalSealed = []
260
- let precipSealed = []
298
+ const precipSealed = []
261
299
 
262
300
  if (sid) {
263
301
  try {
@@ -273,7 +311,16 @@ export function collectSealedWatchSummary(rootSessionId = '', projectKey = 'proj
273
311
  sessionSealed = (sStore.items || [])
274
312
  .filter(it => !Array.isArray(it.takenOutSessions) || !it.takenOutSessions.includes(sid))
275
313
  .slice(0, capPerVault)
276
- .map(it => ({ id: it.id, scope: 'session', title: it.title, folder: it.folder, summary: it.summary }))
314
+ .map(it => ({
315
+ id: it.id,
316
+ scope: 'session',
317
+ title: it.title,
318
+ folder: it.folder,
319
+ summary: it.summary,
320
+ hasHook: Boolean(it.hasHook),
321
+ hookKeywords: Array.isArray(it.hookKeywords) ? it.hookKeywords : [],
322
+ hookCue: it.hookCue || '',
323
+ }))
277
324
  }
278
325
  } catch {}
279
326
  }
@@ -281,21 +328,28 @@ export function collectSealedWatchSummary(rootSessionId = '', projectKey = 'proj
281
328
  try {
282
329
  const gStore = loadGlobalVaultRaw(base)
283
330
  globalSealed = (gStore.items || [])
284
- .filter(it => !sid || !Array.isArray(it.takenOutSessions) || !it.takenOutSessions.includes(sid))
331
+ .filter(it =>
332
+ it.hasHook === true
333
+ && (!sid || !Array.isArray(it.takenOutSessions) || !it.takenOutSessions.includes(sid))
334
+ )
285
335
  .slice(0, capPerVault)
286
- .map(it => ({ id: it.id, scope: 'global', title: it.title, folder: it.folder, summary: it.summary, chiefMounted: Boolean(sid && Array.isArray(it.chiefMountedSessions) && it.chiefMountedSessions.includes(sid)) }))
336
+ .map(it => ({
337
+ id: it.id,
338
+ scope: 'global',
339
+ title: it.title,
340
+ folder: it.folder,
341
+ hasHook: true,
342
+ hookKeywords: Array.isArray(it.hookKeywords) ? it.hookKeywords : [],
343
+ hookCue: it.hookCue || '',
344
+ chiefMounted: Boolean(
345
+ sid && (
346
+ (Array.isArray(it.chiefMountedSessions) && it.chiefMountedSessions.includes(sid))
347
+ || (Array.isArray(it.chiefPulledSessions) && it.chiefPulledSessions.includes(sid))
348
+ )
349
+ ),
350
+ }))
287
351
  } catch {}
288
352
 
289
- if (hasAnyPrecipitatedFilesOnDisk(base)) {
290
- try {
291
- const pStore = loadPrecipitatedStoreRaw(projectKey || base.projectKey || 'proj-default', base)
292
- precipSealed = (pStore.items || [])
293
- .filter(it => !sid || !Array.isArray(it.flippedOutSessions) || !it.flippedOutSessions.includes(sid))
294
- .slice(0, capPerVault)
295
- .map(it => ({ id: it.id, scope: 'precipitated', title: it.title, category: it.category, summary: it.summary }))
296
- } catch {}
297
- }
298
-
299
353
  return { sessionSealed, globalSealed, precipSealed }
300
354
  }
301
355
 
@@ -305,22 +359,33 @@ export function listPrecipitatedHeaders(projectKey = 'proj-default', rootSession
305
359
  if (!fs.existsSync(file)) return []
306
360
  const sid = str(rootSessionId, '').trim()
307
361
  const store = loadPrecipitatedStoreRaw(projectKey, targetOpt)
308
- return store.items.map(it => ({
309
- id: it.id,
310
- title: it.title,
311
- category: it.category,
312
- summary: it.summary,
313
- purified: it.purified,
314
- sourceCabinetId: it.sourceCabinetId,
315
- sourceDrawer: it.sourceDrawer,
316
- sourceTitles: it.sourceTitles,
317
- tags: it.tags,
318
- pointCount: Array.isArray(it.points) ? it.points.length : 0,
319
- flippedOut: Boolean(sid && Array.isArray(it.flippedOutSessions) && it.flippedOutSessions.includes(sid)),
320
- points: (it.points || []).map(p => ({ id: p.id, title: p.title, cue: p.cue, detail: p.detail })),
321
- createdAt: it.createdAt,
322
- updatedAt: it.updatedAt,
323
- }))
362
+ return store.items.map(it => {
363
+ const flippedOut = Boolean(sid && Array.isArray(it.flippedOutSessions) && it.flippedOutSessions.includes(sid))
364
+ return {
365
+ id: it.id,
366
+ title: it.title,
367
+ category: it.category,
368
+ folder: it.folder || mapPrecipitatedCategoryToFolder(it.category),
369
+ paperclip: it.paperclip || 'gold',
370
+ summary: it.summary,
371
+ hasHook: true,
372
+ hookKeywords: Array.isArray(it.hookKeywords) ? it.hookKeywords : [],
373
+ hookCue: it.hookCue || '',
374
+ purified: it.purified,
375
+ sourceCabinetId: it.sourceCabinetId,
376
+ sourceDrawer: it.sourceDrawer,
377
+ sourceTitles: it.sourceTitles,
378
+ tags: it.tags,
379
+ pointCount: Array.isArray(it.points) ? it.points.length : 0,
380
+ flippedOut,
381
+ viewerStatus: flippedOut
382
+ ? { code: 'human_unsealed', tone: 'amber', label: '🔓 人类已翻出 · 仅本局参阅' }
383
+ : { code: 'human_only', tone: 'ice', label: '🧊 仅人类可见 · 钩子速览' },
384
+ points: (it.points || []).map(p => ({ id: p.id, title: p.title, cue: p.cue, detail: p.detail })),
385
+ createdAt: it.createdAt,
386
+ updatedAt: it.updatedAt,
387
+ }
388
+ })
324
389
  }
325
390
 
326
391
  export function getPrecipitatedDetail(projectKey = 'proj-default', id = '', rootSessionId = '', targetOpt) {
@@ -412,6 +477,20 @@ export function mutatePrecipitated(projectKey = 'proj-default', payload = {}, ta
412
477
  return { ok: true, removedId: removed.id, title: removed.title }
413
478
  }
414
479
 
480
+ if (op === 'moveFolder' || op === 'setFolder') {
481
+ const item = store.items.find(it => it.id === id)
482
+ if (!item) return { ok: false, error: '未找到沉淀经验:' + id }
483
+ const folder = str(payload.folder, '').trim()
484
+ if (!folder) return { ok: false, error: '请选择目标抽屉' }
485
+ item.folder = folder.slice(0, 64)
486
+ if (['gold', 'silver', 'copper'].includes(payload.paperclip)) {
487
+ item.paperclip = payload.paperclip
488
+ }
489
+ item.updatedAt = Date.now()
490
+ savePrecipitatedStoreRaw(resolvedKey, store, targetOpt)
491
+ return { ok: true, id: item.id, folder: item.folder, item }
492
+ }
493
+
415
494
  if (op === 'updatePrecipitated') {
416
495
  const item = store.items.find(it => it.id === id)
417
496
  if (!item) return { ok: false, error: '未找到沉淀经验:' + id }
package/auto-continue.js CHANGED
@@ -183,7 +183,7 @@ export function classifyTurnEndReason(reason, eventData = null) {
183
183
  return { kind, nestedKind, failure }
184
184
  }
185
185
 
186
- function buildContinuePrompt(trigger, toolSummary = {}, failure = null) {
186
+ function buildContinuePrompt(trigger, toolSummary = {}, failure = null, taskId = '') {
187
187
  const pendingCount = Number(toolSummary.pendingCount) || 0
188
188
  const doneCount = Number(toolSummary.doneCount) || 0
189
189
 
@@ -216,7 +216,8 @@ function buildContinuePrompt(trigger, toolSummary = {}, failure = null) {
216
216
  guardText = `\n[幂等安全提醒] 上一轮已有工具调用完成${doneList},请先核实已有产出,切勿重复执行会覆盖或叠加副作用的步骤。`
217
217
  }
218
218
 
219
- return `[DSH 参谋长 · 断线续跑] ${lead}${guardText}`
219
+ const envelopeTag = taskId ? `[EXECUTION_REQUEST #${taskId}] ` : '[EXECUTION_REQUEST] '
220
+ return `${envelopeTag}[DSH 参谋长 · 断线续跑执行请求] ${lead}${guardText}`
220
221
  }
221
222
 
222
223
  /**
@@ -322,12 +323,18 @@ export function createAutoContinueEngine(options = {}) {
322
323
  return { ok: false, skipped: 'chief-stopped' }
323
324
  }
324
325
 
326
+ let verdict = null
325
327
  if (!bypassGate && typeof canAutoContinue === 'function') {
326
- const verdict = await Promise.resolve(canAutoContinue({ sessionId, rootId, trigger, detail }))
328
+ verdict = await Promise.resolve(canAutoContinue({ sessionId, rootId, trigger, detail }))
327
329
  if (verdict && verdict.allowed === false) {
328
330
  st.stats.skippedStopped += 1
329
331
  if (verdict.logMessage) onLog(sessionId, verdict.logMessage)
330
- return { ok: false, skipped: verdict.skipped || 'permission-mode', approvalId: verdict.approvalId }
332
+ return {
333
+ ok: false,
334
+ skipped: verdict.skipped || 'permission-mode',
335
+ approvalId: verdict.approvalId,
336
+ ...(verdict.taskId ? { taskId: verdict.taskId } : {}),
337
+ }
331
338
  }
332
339
  }
333
340
 
@@ -349,7 +356,8 @@ export function createAutoContinueEngine(options = {}) {
349
356
  return { ok: false, skipped: 'no-followup' }
350
357
  }
351
358
 
352
- const text = buildContinuePrompt(trigger, st.lastToolSummary, st.lastFailure) + (detail ? `\n补充上下文:${clampText(detail, 180)}` : '')
359
+ const envelopeTaskId = (verdict && verdict.taskId) ? String(verdict.taskId) : ''
360
+ const text = buildContinuePrompt(trigger, st.lastToolSummary, st.lastFailure, envelopeTaskId) + (detail ? `\n补充上下文:${clampText(detail, 180)}` : '')
353
361
  const fallbackId = `ac-${Date.now().toString(36)}-${crypto.randomBytes(3).toString('hex')}`
354
362
  let envelope = null
355
363
  if (typeof createMessage === 'function') {
package/board-actions.js CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  } from './chief.js'
17
17
  import {
18
18
  resolveProjectKey,
19
+ listArchiveHeaders,
19
20
  getArchiveDetail,
20
21
  searchArchives,
21
22
  mutateArchive,
@@ -24,7 +25,13 @@ import {
24
25
  getTakenOutGlobalForSession,
25
26
  getFlippedOutPrecipitatedForSession,
26
27
  } from './archives.js'
27
- import { DEFAULT_CHIEF_PERMISSION_MODE, normalizePermissionMode } from './chief-executor.js'
28
+ import {
29
+ DEFAULT_CHIEF_PERMISSION_MODE,
30
+ normalizePermissionMode,
31
+ verifyBoundsWriteAuth,
32
+ listGuardWalls,
33
+ mutateGuardWalls,
34
+ } from './chief-executor.js'
28
35
  import {
29
36
  enforceAnchorCap,
30
37
  STATUSES,
@@ -137,6 +144,7 @@ export function createBoardActions(deps) {
137
144
  || action === 'memory.ask'
138
145
  || action === 'archive.search'
139
146
  || action === 'archive.read'
147
+ || action === 'archive.pull'
140
148
  || action === 'archive.save'
141
149
  ) {
142
150
  return runActionUnlocked(args)
@@ -180,13 +188,46 @@ export function createBoardActions(deps) {
180
188
  }
181
189
  }
182
190
 
191
+ if (action === 'archive.pull') {
192
+ const target = str(args.archiveId !== undefined ? args.archiveId : (args.id !== undefined ? args.id : args.title), '').trim()
193
+ if (!target) return { ok: false, error: 'archive.pull requires archiveId, id, or title' }
194
+ const reqScope = str(args.vaultScope || args.scope, 'session').trim().toLowerCase()
195
+ if (reqScope === 'global' || reqScope === 'precipitated' || reqScope === 'cold') {
196
+ return { ok: false, denied: true, error: '主代理禁止直接拉取全局或冷藏档案柜卷宗,请仅拉取本局档案柜带钩子卷宗' }
197
+ }
198
+ const rootSid = resolveRootSessionId(session) || session
199
+ if (!rootSid) return { ok: false, error: '当前未绑定对话会话,无法拉取本局档案柜' }
200
+ const res = mutateArchive({
201
+ op: 'pullByLead',
202
+ vaultScope: 'session',
203
+ rootSessionId: rootSid,
204
+ id: target,
205
+ archiveId: target,
206
+ title: target,
207
+ }, archiveTarget(deps.hostState.activeRuntime, rootSid, { cabinetId: str(args.cabinetId, ''), vaultScope: 'session' }))
208
+ if (!res || !res.ok) return { ok: false, error: (res && res.error) || '拉取本局档案失败' }
209
+ return {
210
+ ok: true,
211
+ archiveItem: res.item,
212
+ board: session ? loadBoard(file) : emptyBoard(),
213
+ }
214
+ }
215
+
183
216
  if (action === 'archive.read') {
184
217
  const target = str(args.archiveId !== undefined ? args.archiveId : (args.id !== undefined ? args.id : args.title), '').trim()
185
218
  if (!target) return { ok: false, error: 'archive.read requires archiveId, id, or title' }
219
+ const reqScope = str(args.vaultScope || args.scope, 'session').trim().toLowerCase()
220
+ if (reqScope === 'global' || reqScope === 'precipitated' || reqScope === 'cold') {
221
+ return { ok: false, denied: true, error: '主代理禁止跨柜读取全局或冷藏档案柜' }
222
+ }
186
223
  const rootSid = resolveRootSessionId(session) || session
187
224
  if (!rootSid) return { ok: false, error: '当前未绑定对话会话,无法读取本会话档案柜' }
188
- const res = getArchiveDetail(target, rootSid, archiveTarget(deps.hostState.activeRuntime, rootSid, { cabinetId: str(args.cabinetId, ''), vaultScope: 'session' }))
225
+ const archOpt = archiveTarget(deps.hostState.activeRuntime, rootSid, { cabinetId: str(args.cabinetId, ''), vaultScope: 'session' })
226
+ const res = getArchiveDetail(target, rootSid, archOpt)
189
227
  if (!res.ok) return { ok: false, error: res.error }
228
+ if (res.item && res.item.hasHook) {
229
+ mutateArchive({ op: 'pullByLead', vaultScope: 'session', rootSessionId: rootSid, id: res.item.id }, archOpt)
230
+ }
190
231
  return {
191
232
  ok: true,
192
233
  archiveItem: res.item,
@@ -675,6 +716,15 @@ export function createBoardActions(deps) {
675
716
  }
676
717
 
677
718
  if (action === 'bounds.set') {
719
+ const auth = verifyBoundsWriteAuth({
720
+ action,
721
+ field: args.field,
722
+ callerOrigin: args._callerOrigin || '',
723
+ humanConfirmToken: args._humanConfirmToken || null,
724
+ })
725
+ if (!auth.ok) {
726
+ return { ok: false, blockedBySafetyGuard: true, rule: auth.rule, error: auth.error }
727
+ }
678
728
  const current = board.bounds || { allowed: [], forbidden: [], notes: [] }
679
729
  // A partial list that looks complete is the worst of the three options: the
680
730
  // caller walks away believing it imposed 25 restrictions while the board
@@ -719,6 +769,15 @@ export function createBoardActions(deps) {
719
769
  }
720
770
 
721
771
  if (action === 'bounds.add' || action === 'bounds.pin' || action === 'bounds.remove' || action === 'bounds.edit' || action === 'bounds.consolidate') {
772
+ const auth = verifyBoundsWriteAuth({
773
+ action,
774
+ field: args.field,
775
+ callerOrigin: args._callerOrigin || '',
776
+ humanConfirmToken: args._humanConfirmToken || null,
777
+ })
778
+ if (!auth.ok) {
779
+ return { ok: false, blockedBySafetyGuard: true, rule: auth.rule, error: auth.error }
780
+ }
722
781
  const col = normalizeBoundFieldName(args.field)
723
782
  if (!col) {
724
783
  return { ok: false, error: 'bounds operation requires field: allowed (必做) | forbidden (禁止) | notes (注意)' }
@@ -935,6 +994,53 @@ export function createBoardActions(deps) {
935
994
  return clipped({ ok: true, cursor: current, board: saveBoard(board, file) }, clips)
936
995
  }
937
996
 
997
+ if (action === 'wall.list') {
998
+ const targetCwd = session ? getSessionCwd(deps.hostState && deps.hostState.activeRuntime, session) : process.cwd()
999
+ return {
1000
+ ok: true,
1001
+ guardWalls: listGuardWalls({ cwd: targetCwd }),
1002
+ board: loadBoard(file),
1003
+ }
1004
+ }
1005
+
1006
+ if (action === 'wall.save' || action === 'wall.setScope' || action === 'wall.remove' || action === 'wall.merge') {
1007
+ const targetCwd = session ? getSessionCwd(deps.hostState && deps.hostState.activeRuntime, session) : process.cwd()
1008
+ const op = action === 'wall.save'
1009
+ ? 'save'
1010
+ : (action === 'wall.setScope'
1011
+ ? 'set_scope'
1012
+ : (action === 'wall.merge' ? 'merge' : 'remove'))
1013
+ const res = mutateGuardWalls({
1014
+ op,
1015
+ wall: (args.wall && typeof args.wall === 'object') ? args.wall : args,
1016
+ wallId: args.wallId !== undefined ? args.wallId : args.id,
1017
+ wallIds: Array.isArray(args.wallIds) ? args.wallIds : [],
1018
+ autoGroup: Boolean(args.autoGroup),
1019
+ title: typeof args.title === 'string' ? args.title : '',
1020
+ scope: args.scope,
1021
+ cwd: targetCwd,
1022
+ callerOrigin: args._callerOrigin || '',
1023
+ humanConfirmToken: args._humanConfirmToken || null,
1024
+ })
1025
+ if (!res.ok) return res
1026
+ const actionLabel = op === 'remove'
1027
+ ? `移除物理驻墙 ${args.wallId || args.id || ''}`
1028
+ : (op === 'merge'
1029
+ ? `合并同类物理驻墙(${res.mergedCount || 0} 条合为 ${res.createdCount || 1} 条)`
1030
+ : (op === 'set_scope'
1031
+ ? `切换物理驻墙「${(res.wall && res.wall.title) || ''}」状态为 ${args.scope}`
1032
+ : `驻防物理墙「${(res.wall && res.wall.title) || ''}」(${res.wall && res.wall.scope === 'workspace' ? '本工程' : (res.wall && res.wall.scope === 'paused' ? '暂挂' : '全局常驻')})`))
1033
+ pushLog(board, '🧱 ' + actionLabel, by, session)
1034
+ return {
1035
+ ok: true,
1036
+ mergedCount: res.mergedCount || 0,
1037
+ createdCount: res.createdCount || 0,
1038
+ wall: res.wall,
1039
+ guardWalls: res.walls,
1040
+ board: saveBoard(board, file),
1041
+ }
1042
+ }
1043
+
938
1044
  if (action === 'note.unpin') {
939
1045
  const id = str(args.noteId !== undefined ? args.noteId : args.id, '')
940
1046
  const note = board.notes.find(item => item.id === id)
@@ -1442,10 +1548,30 @@ export function createBoardActions(deps) {
1442
1548
  return [...working, ...takenGlobal, ...mappedFlipped]
1443
1549
  }
1444
1550
 
1445
- /** Collect digest-safe archive context for Lead/Subagent prompt: ONLY desk-spotlight items across all 3 vaults (sealed items NEVER leak to Lead), plus Smart Compaction flag & posture. */
1551
+ /** Collect digest-safe archive context for Lead/Subagent prompt: ONLY desk-spotlight items + Chief-curated session hooks (0 raw/global/cold leak!). */
1446
1552
  function collectDigestArchiveContext(runtime, rootId, cabinetId = '') {
1447
1553
  const takenOutArchives = rootId ? collectTakenOutAndFlipped(runtime, rootId, cabinetId) : []
1448
- const sessionArchiveBriefs = []
1554
+ let sessionHookedArchives = []
1555
+ let desktopUsedTokens = 0
1556
+ if (rootId && rootId !== 'global') {
1557
+ try {
1558
+ const targetOpt = archiveTarget(runtime, rootId, { cabinetId, vaultScope: 'session' })
1559
+ const hdrRes = listArchiveHeaders(rootId, { vaultScope: 'session', includeCounts: false }, targetOpt)
1560
+ if (hdrRes && hdrRes.ok) {
1561
+ desktopUsedTokens = Number(hdrRes.desktop && hdrRes.desktop.usedTokens) || 0
1562
+ sessionHookedArchives = (Array.isArray(hdrRes.items) ? hdrRes.items : [])
1563
+ .filter(it => it && it.hasHook && !it.takenOut)
1564
+ .slice(0, 6)
1565
+ .map(it => ({
1566
+ id: it.id,
1567
+ title: it.title,
1568
+ folder: it.folder,
1569
+ hookKeywords: Array.isArray(it.hookKeywords) ? it.hookKeywords : [],
1570
+ hookCue: it.hookCue || '',
1571
+ }))
1572
+ }
1573
+ } catch {}
1574
+ }
1449
1575
  let smartCompactActive = false
1450
1576
  let chiefPermissionMode = DEFAULT_CHIEF_PERMISSION_MODE
1451
1577
  if (rootId) {
@@ -1461,7 +1587,7 @@ export function createBoardActions(deps) {
1461
1587
  })
1462
1588
  } catch {}
1463
1589
  }
1464
- return { takenOutArchives, sessionArchiveBriefs, smartCompactActive, chiefPermissionMode }
1590
+ return { takenOutArchives, sessionHookedArchives, desktopUsedTokens, smartCompactActive, chiefPermissionMode }
1465
1591
  }
1466
1592
 
1467
1593
  /* ------------------------------------------------------------------- auto sync */
package/board-schema.js CHANGED
@@ -8,7 +8,7 @@ import { normalizeMemory } from './memory.js'
8
8
 
9
9
  export const API = '/api/dsh-chief'
10
10
 
11
- export const BACKEND_BUILD = '1.3.0'
11
+ export const BACKEND_BUILD = '1.5.0'
12
12
 
13
13
  export const BOARD_VERSION = 1
14
14