dsh-chief 0.0.0-stage → 1.0.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/handoff.js ADDED
@@ -0,0 +1,481 @@
1
+ /**
2
+ * The handover packet.
3
+ *
4
+ * A fresh Session inherits neither this transcript nor its summaries, so the
5
+ * packet must stand on its own: what we are doing, what is already done and on
6
+ * what evidence, the ordered next actions with the intent behind each, the
7
+ * bounds to respect before touching anything, the coordinates of the work, what
8
+ * was already tried and failed, and what still waits on the human.
9
+ *
10
+ * If a reader needs to open the old conversation to act, this file is broken.
11
+ */
12
+
13
+ import { sectionLabel } from './memory.js'
14
+
15
+ /** 给「关键坐标」预留的字数:锚点是压缩后唯一活下来的硬事实,不能被边界条数挤掉。 */
16
+ const ANCHOR_RESERVE = 900
17
+ /** 一段分不到这个额度就整段不进,免得留下来只剩一个标题。 */
18
+ const MIN_SECTION = 100
19
+
20
+ function clip(text, limit) {
21
+ const value = String(text === undefined || text === null ? '' : text).replace(/\r/g, '').trim()
22
+ return value.length > limit ? value.slice(0, limit) + '…' : value
23
+ }
24
+
25
+ function stamp(at) {
26
+ if (!at) return '—'
27
+ const date = new Date(at)
28
+ const pad = value => String(value).padStart(2, '0')
29
+ return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + ' ' + pad(date.getHours()) + ':' + pad(date.getMinutes())
30
+ }
31
+
32
+ function shortId(id) {
33
+ return String(id || '').replace(/^session-/, '').slice(0, 8)
34
+ }
35
+
36
+ // Session id or plain actor label: the packet says who set the objective, and
37
+ // claiming 会话 for a label that is not one sends the reader looking for a
38
+ // truncated id that never existed.
39
+ function ownerName(id) {
40
+ const text = String(id || '')
41
+ return text.indexOf('session-') === 0 ? '会话 ' + shortId(text) : text
42
+ }
43
+
44
+ /**
45
+ * 段尾的「交代行」:告诉读者这一段没装完、剩下的去哪取。
46
+ * 行级兜底遇到它们要优先保住——同一条单子里,读者知道自己漏了什么
47
+ * 比多读一条条目重要。
48
+ */
49
+ const TAIL_NOTICE = /^(?:…还有|…另有|(正文太长|(按预算)/
50
+
51
+ function isTailNotice(line) {
52
+ return TAIL_NOTICE.test(String(line || '').trim())
53
+ }
54
+
55
+ function tagged(board, tag) {
56
+ const needle = String(tag).toLowerCase()
57
+ return (board.notes || []).filter(note => (note.tags || []).some(item => String(item).toLowerCase() === needle))
58
+ }
59
+
60
+ /**
61
+ * 整项装入:只收整条,收不下就停,并给出「还有 N 条没进」的提示。
62
+ * 一张单子里最贵的资产(锚点、边界、断点)宁可少收,也不在半句处切断——
63
+ * 半句的路径和半句的命令比没有更危险。
64
+ */
65
+ function takeWhole(items, room, hintFor) {
66
+ const kept = []
67
+ let used = 0
68
+ for (const item of items) {
69
+ if (used + item.length + 1 > room) break
70
+ kept.push(item)
71
+ used += item.length + 1
72
+ }
73
+ const rest = items.length - kept.length
74
+ return { kept, rest, hint: rest > 0 ? hintFor(rest) : '' }
75
+ }
76
+
77
+ /**
78
+ * @param board the stored board
79
+ * @param boundaries the live boundary facts from the Host, or {}
80
+ * @param budget maximum characters for the whole packet
81
+ * @param viewer who is rendering this packet right now: a Session id, or a
82
+ * plain actor label. It is NOT read off the board on purpose —
83
+ * see the note at the byline below.
84
+ */
85
+ export function renderHandoff(board, boundaries, budget = 5200, viewer = '', extras) {
86
+ try {
87
+ const b = board || {}
88
+ const limits = boundaries || {}
89
+ const plan = Array.isArray(b.plan) ? b.plan : []
90
+ const tasks = Array.isArray(b.tasks) ? b.tasks : []
91
+ const log = Array.isArray(b.log) ? b.log : []
92
+ const memory = Array.isArray(b.memory) ? b.memory : []
93
+ const done = tasks.filter(task => task.status === 'done')
94
+ const open = tasks.filter(task => task.status !== 'done')
95
+ const doing = open.filter(task => task.status === 'doing')
96
+ const blocked = open.filter(task => task.status === 'blocked')
97
+ const openSteps = plan.filter(step => !step.done)
98
+ const doneSteps = plan.filter(step => step.done)
99
+ const bounds = b.bounds || { allowed: [], forbidden: [], notes: [] }
100
+ const anchors = tagged(b, 'anchor')
101
+ const deadEnds = tagged(b, 'dead-end')
102
+ const decisions = tagged(b, 'decision')
103
+ const evidence = done.filter(task => task.evidence)
104
+
105
+ const head = []
106
+ head.push('# 交接单 · ' + (clip(b.objective, 48) || '(未写目标)'))
107
+ // 落款说的是「谁把这张单子渲染出来的」,不是「谁上次盖过章」。
108
+ // 旧写法读 b.handoff.session:没盖过章就打成「会话 —」,盖过章就把上一个
109
+ // 交班的人当成生成者——两种都在骗读者。生成者只有调用方知道,所以从参数进来。
110
+ head.push('生成 ' + stamp(Date.now()) + ' · 生成者 ' + (viewer ? clip(ownerName(viewer), 40) : '未指名(直接渲染)') + ' · 板子 rev ' + stamp(b.updatedAt))
111
+ if (b.handoff && b.handoff.at) {
112
+ // 盖章是另一件事:它说的是「这张单子被正式交出过」,交班人可能是上一个会话。
113
+ // 章上既记了动作方(by)也记了会话(session),两个都写出来,读者才不会把
114
+ // 「谁交的」和「谁生成的」搅在一起。
115
+ const stampWho = []
116
+ if (b.handoff.by) stampWho.push(clip(b.handoff.by, 20))
117
+ if (b.handoff.session) stampWho.push(ownerName(b.handoff.session))
118
+ head.push('最近一次交接盖章 ' + stamp(b.handoff.at) + (stampWho.length ? '(' + stampWho.join(' · ') + ')' : ''))
119
+ }
120
+ head.push('')
121
+ head.push('## 一句话')
122
+ head.push(clip(b.objective, 300) || '(板上没有写目标:先补一句再动手)')
123
+ if (b.objectiveBy) head.push('(由' + ownerName(b.objectiveBy) + ' 于 ' + stamp(b.objectiveAt) + ' 设定)')
124
+ head.push('')
125
+
126
+ // 「别做的事」是这张单子的底线:读者即使只读了最后几行,也必须看见这四条。
127
+ // 所以它先算好成本,后面每一段都为它留出位置。
128
+ const tail = [
129
+ '## 别做的事',
130
+ '- 不要回翻旧会话、不要解压缩历史摘要:这份单子就是全部所需。真要实现细节,读上面的路径,不要去猜。',
131
+ '- 不要重做「已完成」里带证据的条目;要改先读证据,确认它真的错了。',
132
+ '- 不要把未验证的东西写成已完成;验收口径不清就先问。',
133
+ '- 改板子用 chief_board(snapshot / task.* / plan.set / note.write / log.add),人和你看同一份。',
134
+ ]
135
+ const tailReserve = tail.join('\n').length + 2
136
+ const anchorReserve = anchors.length ? ANCHOR_RESERVE : 0
137
+
138
+ // 任务树:父子关系是结构信息,比 flat 列表更能告诉接手人「这条任务属于谁」。
139
+ // 排在「接下来按这个顺序做」之前——读者先看到全貌,再看顺序。
140
+ const taskTreeLines = (() => {
141
+ const childrenOf = {}
142
+ for (const task of tasks) {
143
+ const pid = String(task.parentId || '')
144
+ if (!childrenOf[pid]) childrenOf[pid] = []
145
+ childrenOf[pid].push(task)
146
+ }
147
+ const roots = tasks.filter(task => {
148
+ const pid = String(task.parentId || '')
149
+ return !pid || pid === ' ' || !tasks.some(t => t.id === pid)
150
+ })
151
+ const lines = []
152
+ const walk = (task, depth) => {
153
+ const status = task.status === 'done' ? '✓' : task.status === 'doing' ? '◐' : task.status === 'blocked' ? '✗' : '○'
154
+ const deps = (task.blockedBy || []).length ? ' [等 ' + (task.blockedBy || []).map(id => shortId(id)).join(',') + ']' : ''
155
+ const unverified = (task.assumptions || []).filter(a => !a.verified).length
156
+ const warn = unverified ? ' ⚠' + unverified : ''
157
+ lines.push(' '.repeat(depth) + status + ' ' + clip(task.title, 50) + deps + warn + '(' + shortId(task.id) + ')')
158
+ const kids = (childrenOf[task.id] || []).filter(t => t.status !== 'done')
159
+ for (const kid of kids) walk(kid, depth + 1)
160
+ }
161
+ for (const root of roots) {
162
+ if (root.status === 'done' && !(childrenOf[root.id] || []).some(t => t.status !== 'done')) continue
163
+ walk(root, 0)
164
+ }
165
+ return lines
166
+ })()
167
+
168
+ // 段序就是读者需要的顺序。每段自己按分到的额度裁剪,前面的段不许花掉后面段
169
+ // 的预留——旧写法是全部拼好再按字数砍尾巴,边界一多就把「关键坐标」和「已
170
+ // 完成与证据」整段砍掉,且不留任何提示。
171
+ // 官方 AgentTeam 任务:digest 里有交接单也该有,多代理接手时得看到团队板。
172
+ const teamTasks = Array.isArray(extras && extras.teamTasks) ? extras.teamTasks : []
173
+ const teamTaskLines = (() => {
174
+ if (!teamTasks.length) return []
175
+ const open = teamTasks.filter(t => t.status !== 'completed' && t.status !== 'deleted')
176
+ const done = teamTasks.filter(t => t.status === 'completed')
177
+ const lines = ['## 团队共享任务(' + open.length + ' 项' + (done.length ? ',' + done.length + ' 已完成' : '') + ')']
178
+ for (const t of open.slice(0, 8)) {
179
+ const status = t.status === 'in_progress' ? 'doing' : t.status === 'completed' ? 'done' : t.status || 'pending'
180
+ const owner = t.ownerName ? ' → ' + clip(t.ownerName, 20) : ''
181
+ const deps = (Array.isArray(t.blockedBy) ? t.blockedBy : []).length && t.status !== 'completed' ? ' [等 ' + t.blockedBy.join(',') + ']' : ''
182
+ lines.push('- [' + status + '] ' + clip(t.id, 12) + ' ' + clip(t.subject, 60) + owner + deps)
183
+ }
184
+ if (open.length > 8) lines.push('…另有 ' + (open.length - 8) + ' 项(调 team_task_list 看全量)')
185
+ return lines
186
+ })()
187
+
188
+ const sections = [
189
+ {
190
+ key: '任务树',
191
+ hold: anchorReserve + tailReserve,
192
+ build: room => {
193
+ if (!taskTreeLines.length) return []
194
+ const lines = ['## 任务树(父子结构)']
195
+ const take = takeWhole(taskTreeLines, room - lines[0].length - 1, rest => '…还有 ' + rest + ' 条任务没进(用 chief_board snapshot 看全量)')
196
+ for (const item of take.kept) lines.push(item)
197
+ if (take.hint) lines.push(take.hint)
198
+ return lines
199
+ },
200
+ },
201
+ {
202
+ key: '团队任务',
203
+ hold: anchorReserve + tailReserve,
204
+ build: room => {
205
+ if (!teamTaskLines.length) return []
206
+ const take = takeWhole(teamTaskLines, room, rest => '…还有 ' + rest + ' 条团队任务没进(调 team_task_list 看全量)')
207
+ const lines = []
208
+ for (const item of take.kept) lines.push(item)
209
+ if (take.hint) lines.push(take.hint)
210
+ return lines
211
+ },
212
+ },
213
+ {
214
+ key: '现在在哪',
215
+ hold: anchorReserve + tailReserve,
216
+ build: room => {
217
+ const lines = ['## 现在在哪']
218
+ const cursor = b.cursor || {}
219
+ const hasCursor = !!(cursor.step || cursor.next || cursor.blocked)
220
+ if (hasCursor) {
221
+ // 断点是下一句该敲什么,换会话后无法从规划里推出来:先给它位置。
222
+ if (cursor.step) lines.push('- 做到:' + clip(cursor.step, 220))
223
+ if (cursor.next) lines.push('- 下一句就做:' + clip(cursor.next, 220))
224
+ if (cursor.blocked) lines.push('- 卡在:' + clip(cursor.blocked, 220))
225
+ lines.push('(断点由 ' + (shortId(cursor.session) || '—') + ' 于 ' + stamp(cursor.at) + ' 写下)')
226
+ }
227
+ lines.push('规划 ' + doneSteps.length + '/' + plan.length + ' 步完成 · 待办 ' + open.length + ' 条(进行中 ' + doing.length + ' / 受阻 ' + blocked.length + ')· 已完成 ' + done.length + ' 条')
228
+ const doingLines = doing.slice(0, 4).map(task => '正在做: ' + clip(task.title, 90) + (task.intent ? ' → 打算 ' + clip(task.intent, 120) : ''))
229
+ const left = room - lines.join('\n').length - 1
230
+ const take = takeWhole(doingLines, left, rest => '…还有 ' + rest + ' 条「正在做」没进(用 chief_board snapshot 看全量)')
231
+ for (const line of take.kept) lines.push(line)
232
+ if (take.hint) lines.push(take.hint)
233
+ return lines
234
+ },
235
+ },
236
+ {
237
+ key: '这一程记住的(本会话自动记忆)',
238
+ hold: anchorReserve + tailReserve,
239
+ build: room => {
240
+ const lines = ['## 这一程记住的(本会话自动记忆)']
241
+ if (!memory.length) {
242
+ lines.push('(这个会话还没攒出记忆:参谋看板会在每轮结束时自己写一条,这里空着说明它还没关过轮)')
243
+ return lines
244
+ }
245
+ const items = memory.slice(-6).map(item => {
246
+ const row = ['- [' + sectionLabel(item.section) + '] ' + clip(item.title || item.text, 90)]
247
+ if (item.text && item.title) row.push(' ' + clip(item.text, 180))
248
+ if ((item.tools || []).length) row.push(' 用过:' + clip(item.tools.join(' / '), 120))
249
+ return row.join('\n')
250
+ })
251
+ const left = room - lines[0].length - 1
252
+ const take = takeWhole(items, left, rest => '…还有 ' + rest + ' 条记忆没进(在右上角参谋看板的「记忆」页签里看全文)')
253
+ for (const item of take.kept) lines.push(item)
254
+ if (take.hint) lines.push(take.hint)
255
+ return lines
256
+ },
257
+ },
258
+ {
259
+ key: '接下来按这个顺序做',
260
+ hold: anchorReserve + tailReserve,
261
+ build: room => {
262
+ const lines = ['## 接下来按这个顺序做']
263
+ const items = []
264
+ if (openSteps.length) {
265
+ openSteps.slice(0, 8).forEach((step, index) => items.push((index + 1) + '. ' + clip(step.text, 160)))
266
+ } else if (open.length) {
267
+ items.push('(规划已全部完成,接着做这些待办)')
268
+ open.slice(0, 8).forEach((task, index) => {
269
+ const tag = task.status === 'blocked' && task.blockedReason
270
+ ? '(卡在:' + clip(task.blockedReason, 60) + ')'
271
+ : task.status === 'blocked' ? '(卡在:受阻)' : ''
272
+ items.push((index + 1) + '. ' + clip(task.title, 160) + tag)
273
+ })
274
+ } else {
275
+ items.push('(板上没有下一步:先问用户这一段要达成什么)')
276
+ }
277
+ for (const task of open.filter(item => item.status !== 'doing').slice(0, 6)) {
278
+ const intent = task.intent ? '打算:' + clip(task.intent, 140) : ''
279
+ const judge = task.note ? '判据:' + clip(task.note, 140) : ''
280
+ if (intent || judge) items.push(' · ' + clip(task.title, 70) + ' — ' + [intent, judge].filter(Boolean).join(';'))
281
+ }
282
+ const left = room - lines[0].length - 1
283
+ const take = takeWhole(items, left, rest => '…还有 ' + rest + ' 条没进(用 chief_board snapshot 看全量)')
284
+ for (const item of take.kept) lines.push(item)
285
+ if (take.hint) lines.push(take.hint)
286
+ return lines
287
+ },
288
+ },
289
+ {
290
+ key: '边界(动手前先读这段)',
291
+ hold: anchorReserve + tailReserve,
292
+ build: room => {
293
+ const lines = ['## 边界(动手前先读这段)']
294
+ const mode = limits.sessionSandboxMode || limits.sandboxMode || 'unknown'
295
+ lines.push('- 沙箱:' + mode + (limits.sessionSandboxOverride ? '(会话覆盖)' : '(部署默认)') + ' · 默认 ' + (limits.sandboxMode || '—'))
296
+ lines.push('- 本会话目录:' + (limits.sessionWorkingDirectory || limits.workingDirectory || '—'))
297
+ lines.push('- 部署默认可写根(会话没有 cwd 时用它):' + (limits.workspaceRoot || '—') + (limits.extraWritableRoots ? ' + ' + limits.extraWritableRoots.join(', ') : ''))
298
+ const items = []
299
+ // 顺序就是优先级:空间不够时先丢「允许」,绝不先丢「禁止」。
300
+ // 板子对每个数组各有 20 条上限,所以最坏是 60 条,挤爆时必须靠这个次序活着。
301
+ for (const forbidden of bounds.forbidden) items.push({ label: '禁止', cap: 200, text: forbidden })
302
+ for (const note of bounds.notes) items.push({ label: '注意', cap: 240, text: note })
303
+ for (const allowed of bounds.allowed) items.push({ label: '允许', cap: 200, text: allowed })
304
+ if (!items.length) return lines
305
+ const left = room - lines.join('\n').length - 2
306
+ // 先按「每条都至少还读得懂」的下限排;排不下就让 takeWhole 从队尾丢
307
+ // (队尾就是「允许」),并写明还有几条没列出。
308
+ // 反面教材:把 60 条全压到 24 字,一条条都是「禁止 第1条:bbbb…」,
309
+ // 读者既不知道禁的是什么,也不知道自己漏了什么,比少列几条贵得多。
310
+ const share = Math.floor(left / items.length) - 8
311
+ const built = items.map(item => '- ' + item.label + ':' + clip(item.text, Math.max(40, Math.min(item.cap, share))))
312
+ const take = takeWhole(built, left, rest => '…还有 ' + rest + ' 条边界没列出(用 chief_board snapshot 取全量)')
313
+ for (const line of take.kept) lines.push(line)
314
+ if (take.hint) lines.push(take.hint)
315
+ return lines
316
+ },
317
+ },
318
+ {
319
+ key: '主动取出的工程档案(本会话桌面备查)',
320
+ hold: tailReserve,
321
+ build: room => {
322
+ const taken = extras && Array.isArray(extras.takenOutArchives) ? extras.takenOutArchives : []
323
+ if (!taken.length) return []
324
+ const lines = ['## 主动取出的工程档案(本会话桌面备查)']
325
+ const shown = taken.slice(0, 4)
326
+ const left = room - lines[0].length - 2
327
+ const share = Math.max(80, Math.floor(left / shown.length) - 16)
328
+ const items = shown.map(item => {
329
+ const pts = (Array.isArray(item.points) ? item.points : [])
330
+ .slice(0, 4)
331
+ .map((p, idx) => `${idx + 1}) ${clip(p.title, 40)}: ${clip(p.cue || p.detail, 90)}`)
332
+ .join('\n')
333
+ return '### ' + clip(item.title, 60) + '\n' + clip(pts || item.summary || item.body, Math.min(420, share))
334
+ })
335
+ const take = takeWhole(items, left, rest => '…还有 ' + rest + ' 份取出的档案未列出(用 chief_board archive.read 按需调取)')
336
+ for (const item of take.kept) lines.push(item)
337
+ if (take.hint) lines.push(take.hint)
338
+ return lines
339
+ },
340
+ },
341
+ {
342
+ key: '关键坐标(压缩会丢,所以写在这里)',
343
+ // 只有 tailReserve 要留:锚点自己在为后面的段让路,不许别人再挤它。
344
+ hold: tailReserve,
345
+ build: room => {
346
+ if (!anchors.length) return []
347
+ const lines = ['## 关键坐标(压缩会丢,所以写在这里)']
348
+ const shown = anchors.slice(0, 6)
349
+ const left = room - lines[0].length - 2
350
+ // 先保证每条都有名有正文:等额分配,再谈正文多长。
351
+ const share = Math.floor(left / shown.length) - 12
352
+ const items = shown.map(note => '### ' + clip(note.title, 60) + '\n' + clip(note.body, Math.max(60, Math.min(480, share))))
353
+ let take = takeWhole(items, left, rest => '…还有 ' + rest + ' 条锚点没进(用 chief_board snapshot 取全量)')
354
+ if (!take.kept.length && left > 40) {
355
+ // 连一条都装不下:至少把标题留住,让读者知道去哪取。
356
+ const titles = shown.map(note => '### ' + clip(note.title, 60))
357
+ take = takeWhole(titles, left, rest => '…还有 ' + rest + ' 条锚点没进(用 chief_board snapshot 取全量)')
358
+ for (const line of take.kept) lines.push(line)
359
+ lines.push('(正文太长,这里只列了标题:全文用 chief_board snapshot 取)')
360
+ if (anchors.length > 6) lines.push('…另有 ' + (anchors.length - 6) + ' 条锚点未列出')
361
+ return lines
362
+ }
363
+ for (const item of take.kept) lines.push(item)
364
+ if (take.hint) lines.push(take.hint)
365
+ if (anchors.length > 6) lines.push('…另有 ' + (anchors.length - 6) + ' 条锚点未列出(用 chief_board snapshot 取全量)')
366
+ return lines
367
+ },
368
+ },
369
+ {
370
+ key: '已完成与证据',
371
+ hold: tailReserve,
372
+ build: room => {
373
+ if (!evidence.length) return []
374
+ const lines = ['## 已完成与证据']
375
+ const items = evidence.slice(0, 8).map(task => '- ' + clip(task.title, 80) + ' — ' + clip(task.evidence, 220))
376
+ const left = room - lines[0].length - 1
377
+ const take = takeWhole(items, left, rest => '…还有 ' + rest + ' 条已完成的证据没进(用 chief_board snapshot 看全量)')
378
+ for (const item of take.kept) lines.push(item)
379
+ if (take.hint) lines.push(take.hint)
380
+ return lines
381
+ },
382
+ },
383
+ {
384
+ key: '试过但没走通(别再试一遍)',
385
+ hold: tailReserve,
386
+ build: room => {
387
+ if (!deadEnds.length) return []
388
+ const lines = ['## 试过但没走通(别再试一遍)']
389
+ const items = deadEnds.slice(0, 6).map(note => '- ' + clip(note.title, 50) + ':' + clip(note.body, 260))
390
+ const left = room - lines[0].length - 1
391
+ const take = takeWhole(items, left, rest => '…还有 ' + rest + ' 条失败记录没进(用 chief_board snapshot 看全量)')
392
+ for (const item of take.kept) lines.push(item)
393
+ if (take.hint) lines.push(take.hint)
394
+ return lines
395
+ },
396
+ },
397
+ {
398
+ key: '等用户决定',
399
+ hold: tailReserve,
400
+ build: room => {
401
+ if (!decisions.length) return []
402
+ const lines = ['## 等用户决定']
403
+ const items = decisions.slice(0, 6).map(note => '- ' + clip(note.title, 50) + ':' + clip(note.body, 260))
404
+ const left = room - lines[0].length - 1
405
+ const take = takeWhole(items, left, rest => '…还有 ' + rest + ' 条待定没进(用 chief_board snapshot 看全量)')
406
+ for (const item of take.kept) lines.push(item)
407
+ if (take.hint) lines.push(take.hint)
408
+ return lines
409
+ },
410
+ },
411
+ {
412
+ key: '最近交接痕迹',
413
+ hold: tailReserve,
414
+ build: room => {
415
+ if (!log.length) return []
416
+ const lines = ['## 最近交接痕迹']
417
+ const items = log.slice(-5).map(entry => '- ' + stamp(entry.at) + ' ' + clip(entry.by || '?', 12) + (entry.session ? '(' + shortId(entry.session) + ')' : '') + ':' + clip(entry.text, 100))
418
+ const left = room - lines[0].length - 1
419
+ const take = takeWhole(items, left, rest => '…还有 ' + rest + ' 条痕迹没进(用 chief_board snapshot 看全量)')
420
+ for (const item of take.kept) lines.push(item)
421
+ if (take.hint) lines.push(take.hint)
422
+ return lines
423
+ },
424
+ },
425
+ ]
426
+
427
+ const body = []
428
+ const dropped = []
429
+ // 「哪些段没进」这行提示也要占字,先给它留出来,否则预算恰好在边界上时
430
+ // 整张单子会超出 budget 一截。
431
+ const hintReserve = sections.length ? 130 : 0
432
+ let used = head.join('\n').length + 1 + hintReserve
433
+ for (const section of sections) {
434
+ const room = budget - used - (section.hold || 0)
435
+ if (room < MIN_SECTION) {
436
+ dropped.push(section.key)
437
+ continue
438
+ }
439
+ const lines = section.build(room)
440
+ if (!lines.length) continue
441
+ let block = lines.join('\n')
442
+ if (block.length > room) {
443
+ // 兜底:整行丢弃,绝不在半句处切断。
444
+ // 但段尾那几行「…还有 N 条没列出」是这张单子里唯一的交代:读者正是
445
+ // 靠它知道自己漏了什么。所以先把它们摘出来留好位,再从前往后装。
446
+ // 反面教材:直接从头逐行 break,第一版就是这么把「还有 39 条边界没列出」
447
+ // 连同整行一起砍掉的 —— 单子上看不出少了一半,读者以为自己读到了全部。
448
+ const notices = []
449
+ while (lines.length && isTailNotice(lines[lines.length - 1])) notices.unshift(lines.pop())
450
+ const noticeSize = notices.reduce((sum, line) => sum + line.length + 1, 0)
451
+ const fill = room - noticeSize
452
+ const kept = []
453
+ let size = 0
454
+ for (const line of lines) {
455
+ if (size + line.length + 1 > fill) break
456
+ kept.push(line)
457
+ size += line.length + 1
458
+ }
459
+ if (!kept.length && !notices.length) {
460
+ dropped.push(section.key)
461
+ continue
462
+ }
463
+ // 连一条正文都装不下时,至少把交代行留下:读者要知道自己没读到全部。
464
+ block = kept.concat(notices).join('\n')
465
+ dropped.push(section.key + (kept.length ? '(截断)' : '(只留了交代行)'))
466
+ }
467
+ body.push(block)
468
+ used += block.length + 1
469
+ }
470
+
471
+ const out = head.concat(body)
472
+ if (dropped.length) {
473
+ out.push('(按预算装了这一份,没进或只进了一部分的段:' + dropped.join('、') + '。要全量用 chief_board snapshot,或直接读 board.json。)')
474
+ }
475
+ out.push('')
476
+ for (const line of tail) out.push(line)
477
+ return out.join('\n')
478
+ } catch (error) {
479
+ return '# 交接单生成失败\n' + String((error && error.message) || error)
480
+ }
481
+ }
package/icon.svg ADDED
@@ -0,0 +1,52 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" role="img" aria-label="DSH Chief">
2
+ <defs>
3
+ <linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0%" stop-color="#0B132B"/>
5
+ <stop offset="55%" stop-color="#14244B"/>
6
+ <stop offset="100%" stop-color="#1E1B4B"/>
7
+ </linearGradient>
8
+ <radialGradient id="glow" cx="50%" cy="34%" r="52%">
9
+ <stop offset="0%" stop-color="#FFE033" stop-opacity="0.28"/>
10
+ <stop offset="100%" stop-color="#FFE033" stop-opacity="0"/>
11
+ </radialGradient>
12
+ <linearGradient id="gold" x1="0" y1="0" x2="1" y2="1">
13
+ <stop offset="0%" stop-color="#FFF394"/>
14
+ <stop offset="45%" stop-color="#FFE033"/>
15
+ <stop offset="100%" stop-color="#F59E0B"/>
16
+ </linearGradient>
17
+ <linearGradient id="rim" x1="0" y1="0" x2="1" y2="1">
18
+ <stop offset="0%" stop-color="#FFE033" stop-opacity="0.55"/>
19
+ <stop offset="50%" stop-color="#38BDF8" stop-opacity="0.35"/>
20
+ <stop offset="100%" stop-color="#818CF8" stop-opacity="0.45"/>
21
+ </linearGradient>
22
+ </defs>
23
+
24
+ <rect x="8" y="8" width="112" height="112" rx="28" fill="url(#bg)"/>
25
+ <rect x="8" y="8" width="112" height="112" rx="28" fill="url(#glow)"/>
26
+ <rect x="9.5" y="9.5" width="109" height="109" rx="26.5" fill="none" stroke="url(#rim)" stroke-width="2.5"/>
27
+
28
+ <!-- Subtle tactical arc -->
29
+ <path d="M28 52 A38 38 0 0 1 100 52" fill="none" stroke="#38BDF8" stroke-opacity="0.24" stroke-width="2" stroke-dasharray="4 5" stroke-linecap="round"/>
30
+
31
+ <!-- Command DAG links from Chief Star to 3 execution nodes -->
32
+ <g stroke-width="3.2" stroke-linecap="round" fill="none">
33
+ <path d="M64 48 L34 84" stroke="#38BDF8" stroke-opacity="0.85"/>
34
+ <path d="M64 48 L64 88" stroke="#FFE033" stroke-opacity="0.9"/>
35
+ <path d="M64 48 L94 84" stroke="#34D399" stroke-opacity="0.85"/>
36
+ <path d="M34 84 L64 88 L94 84" stroke="#94A3B8" stroke-opacity="0.32" stroke-width="2"/>
37
+ </g>
38
+
39
+ <!-- Subagent / Archive tier nodes -->
40
+ <circle cx="34" cy="84" r="8.5" fill="#0F172A" stroke="#38BDF8" stroke-width="3.2"/>
41
+ <circle cx="34" cy="84" r="3.2" fill="#38BDF8"/>
42
+
43
+ <rect x="55" y="79" width="18" height="18" rx="5" fill="#0F172A" stroke="#FFE033" stroke-width="3.2"/>
44
+ <circle cx="64" cy="88" r="3.4" fill="#FFE033"/>
45
+
46
+ <circle cx="94" cy="84" r="8.5" fill="#0F172A" stroke="#34D399" stroke-width="3.2"/>
47
+ <circle cx="94" cy="84" r="3.2" fill="#34D399"/>
48
+
49
+ <!-- Sovereign Chief 4-point Command Star -->
50
+ <path d="M64 20 L70.2 35.8 L86 42 L70.2 48.2 L64 64 L57.8 48.2 L42 42 L57.8 35.8 Z" fill="url(#gold)"/>
51
+ <circle cx="64" cy="42" r="4.2" fill="#FFFFFF" fill-opacity="0.92"/>
52
+ </svg>