dsh-colophon 0.1.0 → 0.2.1

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/README.md CHANGED
@@ -12,21 +12,39 @@
12
12
  - 历史会话在启动时**本地回填**一次(读本地事件日志,无模型调用)。
13
13
  - 崩溃 / 断电 / 强制结束:每轮落盘 checkpoint + `lifecycle.json` 标记;下次启动检测到"非正常关闭"后自动本地重建,与 Office 自动恢复的预期一致。
14
14
 
15
- ## 安装(本地开发)
15
+ ## 截图
16
+
17
+ 设置页(引擎 / 触发 / API 预算 / 用量):
18
+
19
+ ![settings](docs/screenshots/settings.png)
20
+
21
+ 输入框上方的卷末卡片 + 崩溃恢复条:
22
+
23
+ ![composer](docs/screenshots/composer.png)
24
+
25
+ ## 安装
26
+
27
+ **npm(推荐)**
28
+
29
+ ```bash
30
+ dsh plugin --profile <你的 profile> add dsh-colophon
31
+ ```
32
+
33
+ > `dsh-colophon@0.1.0` 已发布到 npm;市场条目见 [awesome-dsh-plugin](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)。与 billion-context 可共存——colophon 不接管上下文压缩,只做摘要沉淀与读取。
34
+
35
+ **本地开发 / 手动**
16
36
 
17
37
  ```bash
18
38
  dsh plugin --profile desktop add /Users/shibuya/Desktop/DeepSeek/colophon
19
39
  ```
20
40
 
21
- 或手动把本目录加进 profile `package.json` 的 `dsh.profile.bundles`:
41
+ 或把本目录加进 profile `package.json` 的 `dsh.profile.bundles`:
22
42
 
23
43
  ```json
24
44
  "dsh-colophon": "link:/Users/shibuya/Desktop/DeepSeek/colophon"
25
45
  ```
26
46
 
27
- > 注意:与 billion-context 可共存——colophon 不接管上下文压缩,只做摘要沉淀与读取。
28
-
29
- 没有 pnpm 的环境(本机)可手动安装,改两处:
47
+ 没有 pnpm 的环境可手动安装,改两处:
30
48
 
31
49
  ```bash
32
50
  mkdir -p ~/.dsh/profiles/desktop/node_modules
@@ -73,10 +91,25 @@ usage.jsonl API 调用账本(rules 引擎不写)
73
91
 
74
92
  - `session/event` 采集 → 每会话尾部状态(用户原文、最新回复、文件足迹、命令、工具错误)
75
93
  - 每轮 checkpoint(原子写)+ 30s 周期落盘 + `process.on('exit')` 同步落盘
76
- - `rules` 摘要引擎(Markdown,含 目标/结论/已完成/下一步/风险)
94
+ - `rules` 摘要引擎(Markdown,含 目标/结论/决策/涉及文件/已完成/下一步/风险)
77
95
  - 崩溃检测(`lifecycle.json`)与启动时本地回填(`sessionPersistence.open(id,'read')`)
78
96
  - 用量账本(token + 人民币,支持 时/日/周/月/自定义 窗口)
79
97
 
98
+ ## 0.2.0(摘要质量与配置安全)
99
+
100
+ - `rules` 提取升级:`## 决策` 小节、最后一条「已完成…」段落优先作结论、`- [ ]` 待办自动进下一步、写入文件单列「涉及文件」、规则版本号(旧摘要启动时自动重建)
101
+ - 凭据脱敏:`sk-*`、`ghp_*`、`AKIA*`、`Bearer …`、`password=…` 写入摘要前替换为 `[redacted]`
102
+ - API 引擎更稳:兼容 JSON 对象回复(字段 goal/conclusion/decisions/done/nextSteps/risks/writes),Markdown 小节继续可用,缺失字段回退本地事实
103
+ - 摘要面板新增「下载 Markdown」按钮(直接保存为 `.md` 文件)
104
+ - 版本号 0.2.0;测试 38 项全绿
105
+
106
+ ## 0.2.1(设置界面可读性)
107
+
108
+ - 设置页重做:渐变标题卡 + 状态胶囊、强调条卡片、整行可点的开关(带滑动圆钮)、蓝底主按钮「保存修改」、描边次按钮「处理队列」/「查询」
109
+ - 所有可点击元素都有明确的按钮形态与悬停反馈,队列为空时「处理队列」自动置灰
110
+ - 触发时机、API 预算、用量区间(时/日/周/月/自定义)分组更清晰,警告文案用琥珀色提示条
111
+ - 版本号 0.2.1;截图更新至 `docs/screenshots/settings.png`
112
+
80
113
  ## 已实现(P2 · 客户端)
81
114
 
82
115
  - 输入框上方「卷末」胶囊:点击展开摘要面板(Markdown 预览、复制、重新生成)
package/client.js CHANGED
@@ -31,12 +31,13 @@ window.__ModuleLoader__.load({
31
31
  regenerate: '重新生成',
32
32
  copy: '复制 Markdown',
33
33
  copied: '已复制',
34
+ download: '下载 Markdown',
34
35
  close: '关闭',
35
36
  loading: '读取中…',
36
37
  failed: '读取失败:{message}',
37
38
  crash: '上次 DSH 没有正常退出,卷末已在本地恢复(0 token)。',
38
39
  crashAck: '知道了',
39
- settingsLabel: '卷末 · Colophon',
40
+ settingsLabel: '卷末 Colophon',
40
41
  settingsIntro: '规则引擎只读本地日志,不调用模型、不花 token;API 摘要为可选项。',
41
42
  engine: '摘要引擎',
42
43
  engineRules: '本地规则(0 token)',
@@ -84,6 +85,22 @@ window.__ModuleLoader__.load({
84
85
  queueRun: '队列已处理',
85
86
  apiUnavailable: '当前环境没有可用的模型服务(llm):API 引擎会回退到本地 rules 摘要,并把它放进待确认队列。',
86
87
  statusFailed: '状态读取失败',
88
+ basicTitle: '基本设置',
89
+ statusOn: '已启用',
90
+ statusOff: '已暂停',
91
+ settingsSubtitle: '把每次对话的最终结论留在本地;重开会话时先看结论,不必重读整段历史。',
92
+ saveHint: '保存后立即生效,无需重启。',
93
+ enabledHint: '关闭后不再采集新会话;已有摘要仍可查看。',
94
+ engineHint: 'rules 完全本地,0 token;api 每次生成会调用模型,并受下方预算限制。',
95
+ onIdleHint: '智能体停止后几秒内写出摘要。',
96
+ onSwitchHint: '在另一个会话里开始输入时,先总结上一个会话。',
97
+ apiOn: '已开启',
98
+ apiOff: '未开启',
99
+ apply: '查询',
100
+ rangeInvalid: '时间范围无效(开始时间需早于结束时间)。',
101
+ customHint: '结束时间留空表示到当前时刻。',
102
+ queueHint: '这些会话在花费 token 前等待你确认。',
103
+ save: '保存修改',
87
104
  },
88
105
  en: {
89
106
  chip: 'Colophon',
@@ -95,6 +112,7 @@ window.__ModuleLoader__.load({
95
112
  regenerate: 'Regenerate',
96
113
  copy: 'Copy Markdown',
97
114
  copied: 'Copied',
115
+ download: 'Download',
98
116
  close: 'Close',
99
117
  loading: 'Loading…',
100
118
  failed: 'Failed: {message}',
@@ -148,6 +166,22 @@ window.__ModuleLoader__.load({
148
166
  queueRun: 'Queue processed',
149
167
  apiUnavailable: 'No model service (llm) is available here: the API engine falls back to local rules digests and queues the session for confirmation.',
150
168
  statusFailed: 'Status unavailable',
169
+ basicTitle: 'Basics',
170
+ statusOn: 'Enabled',
171
+ statusOff: 'Paused',
172
+ settingsSubtitle: 'Keep every conversation’s final conclusion locally. Reopen a session and read the conclusion first — no need to replay the whole history.',
173
+ saveHint: 'Changes take effect immediately after saving.',
174
+ enabledHint: 'When off, new sessions are no longer captured; existing digests stay readable.',
175
+ engineHint: 'Local rules cost 0 tokens. The API engine calls a model per digest and is capped by the budgets below.',
176
+ onIdleHint: 'Write the digest a few seconds after the agent stops.',
177
+ onSwitchHint: 'Summarize the previous session when you start typing in another one.',
178
+ apiOn: 'On',
179
+ apiOff: 'Off',
180
+ apply: 'Apply',
181
+ rangeInvalid: 'Pick a valid time range (from ≤ to).',
182
+ customHint: 'Leave the end empty to use the current moment.',
183
+ queueHint: 'Sessions waiting for your confirmation before spending tokens.',
184
+ save: 'Save changes',
151
185
  },
152
186
  }
153
187
 
@@ -220,6 +254,82 @@ window.__ModuleLoader__.load({
220
254
  cardValue: { fontSize: 15, fontWeight: 600, marginTop: 2 },
221
255
  warn: { color: '#ffd27a', fontSize: 11 },
222
256
  ok: { color: '#4cc38a', fontSize: 11 },
257
+
258
+ // ---- Settings page ----
259
+ page: { display: 'flex', flexDirection: 'column', gap: 14, fontSize: 13, maxWidth: 760, paddingBottom: 8, lineHeight: 1.5 },
260
+ headCard: {
261
+ display: 'flex', flexDirection: 'column', gap: 6, padding: '18px 20px', borderRadius: 14,
262
+ border: '1px solid rgba(255,255,255,0.08)',
263
+ background: 'linear-gradient(135deg, rgba(79,124,255,0.12), rgba(255,255,255,0.02) 62%)',
264
+ },
265
+ headTitle: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', fontSize: 17, fontWeight: 650 },
266
+ headSub: { fontSize: 12.5, lineHeight: 1.6, opacity: 0.7, maxWidth: 560 },
267
+ pill: { display: 'inline-flex', alignItems: 'center', gap: 6, height: 22, padding: '0 10px', borderRadius: 999, fontSize: 11.5, fontWeight: 600, whiteSpace: 'nowrap' },
268
+ pillOn: { background: 'rgba(76,195,138,0.14)', color: '#6fe0a8', border: '1px solid rgba(76,195,138,0.3)' },
269
+ pillOff: { background: 'rgba(255,255,255,0.06)', color: 'rgba(255,255,255,0.62)', border: '1px solid rgba(255,255,255,0.12)' },
270
+ card2: {
271
+ display: 'flex', flexDirection: 'column', gap: 12, padding: '16px 18px', borderRadius: 14,
272
+ border: '1px solid rgba(255,255,255,0.08)', background: 'rgba(255,255,255,0.028)',
273
+ },
274
+ cardHead: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10 },
275
+ cardTitle: { display: 'flex', alignItems: 'center', gap: 8, fontSize: 13.5, fontWeight: 650 },
276
+ accentBar: { width: 3, height: 14, borderRadius: 2, background: '#4f7cff', display: 'inline-block' },
277
+ hint: { fontSize: 12, lineHeight: 1.6, opacity: 0.6 },
278
+ switchRow: {
279
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 14,
280
+ padding: '10px 12px', borderRadius: 10, border: '1px solid rgba(255,255,255,0.07)',
281
+ background: 'rgba(0,0,0,0.16)', cursor: 'pointer', minHeight: 46, boxSizing: 'border-box',
282
+ },
283
+ switchRowOn: { borderColor: 'rgba(79,124,255,0.45)', background: 'rgba(79,124,255,0.1)' },
284
+ switchTrack: {
285
+ position: 'relative', flex: '0 0 auto', width: 38, height: 22, borderRadius: 999,
286
+ background: 'rgba(255,255,255,0.18)', transition: 'background 120ms ease',
287
+ },
288
+ switchTrackOn: { background: '#4f7cff' },
289
+ switchKnob: {
290
+ position: 'absolute', top: 3, left: 3, width: 16, height: 16, borderRadius: 999,
291
+ background: '#fff', transition: 'transform 120ms ease', boxShadow: '0 1px 3px rgba(0,0,0,0.4)',
292
+ },
293
+ switchKnobOn: { transform: 'translateX(16px)' },
294
+ callout: {
295
+ display: 'flex', gap: 8, padding: '10px 12px', borderRadius: 10,
296
+ border: '1px solid rgba(255,210,122,0.28)', background: 'rgba(255,210,122,0.08)',
297
+ color: '#ffd27a', fontSize: 12, lineHeight: 1.55,
298
+ },
299
+ fieldWide: { display: 'flex', flexDirection: 'column', gap: 5, minWidth: 150, flex: '1 1 150px', maxWidth: 300 },
300
+ inputWide: {
301
+ background: 'rgba(0,0,0,0.3)', color: 'inherit', border: '1px solid rgba(255,255,255,0.14)',
302
+ borderRadius: 8, height: 34, padding: '0 10px', fontSize: 13, width: '100%', boxSizing: 'border-box',
303
+ },
304
+ row2: { display: 'flex', gap: 12, flexWrap: 'wrap', alignItems: 'flex-end' },
305
+ actionsBar: { display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: 10, paddingTop: 2 },
306
+ buttonPrimary: {
307
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 6,
308
+ height: 36, minWidth: 104, padding: '0 18px', borderRadius: 9,
309
+ border: '1px solid rgba(79,124,255,0.9)', background: '#4f7cff', color: '#fff',
310
+ fontSize: 13, fontWeight: 650, cursor: 'pointer', boxShadow: '0 2px 10px rgba(79,124,255,0.35)',
311
+ },
312
+ buttonSecondary: {
313
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 6,
314
+ height: 36, minWidth: 84, padding: '0 14px', borderRadius: 9,
315
+ border: '1px solid rgba(255,255,255,0.22)', background: 'rgba(255,255,255,0.05)',
316
+ color: 'inherit', fontSize: 13, fontWeight: 550, cursor: 'pointer',
317
+ },
318
+ buttonDisabled: { opacity: 0.45, cursor: 'not-allowed', boxShadow: 'none' },
319
+ usageGrid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: 10 },
320
+ usageCard: {
321
+ display: 'flex', flexDirection: 'column', gap: 2, padding: '12px 14px', borderRadius: 12,
322
+ border: '1px solid rgba(255,255,255,0.08)', background: 'rgba(0,0,0,0.18)',
323
+ },
324
+ usageValue: { fontSize: 19, fontWeight: 650, letterSpacing: '-0.01em' },
325
+ listRow: {
326
+ display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap',
327
+ padding: '8px 10px', borderRadius: 8, background: 'rgba(0,0,0,0.16)', fontSize: 12,
328
+ },
329
+ emptyBox: {
330
+ padding: '14px 12px', borderRadius: 10, border: '1px dashed rgba(255,255,255,0.16)',
331
+ color: 'rgba(255,255,255,0.5)', fontSize: 12, textAlign: 'center',
332
+ },
223
333
  }
224
334
 
225
335
  /** Read/persist the crash banner acknowledgement. */
@@ -298,6 +408,19 @@ window.__ModuleLoader__.load({
298
408
  } catch { /* clipboard denied */ }
299
409
  }, [digest])
300
410
 
411
+ const download = useCallback(() => {
412
+ if (!digest?.markdown) return
413
+ try {
414
+ const blob = new Blob([digest.markdown], { type: 'text/markdown;charset=utf-8' })
415
+ const url = URL.createObjectURL(blob)
416
+ const anchor = document.createElement('a')
417
+ anchor.href = url
418
+ anchor.download = `colophon-${String(sessionId).slice(0, 8)}.md`
419
+ anchor.click()
420
+ setTimeout(() => URL.revokeObjectURL(url), 1000)
421
+ } catch { /* download blocked */ }
422
+ }, [digest, sessionId])
423
+
301
424
  // The hero (new session) has no history yet; keep it clean.
302
425
  if (variant === 'hero' || !sessionId) return null
303
426
 
@@ -318,20 +441,21 @@ window.__ModuleLoader__.load({
318
441
  : digest?.markdown ? h('pre', { style: styles.pre }, digest.markdown)
319
442
  : h('div', { style: styles.muted }, tr('empty')),
320
443
  h('div', { style: styles.actions },
321
- h('button', { style: styles.button, onClick: () => void generate(), disabled: loading },
444
+ h('button', { style: styles.buttonPrimary, onClick: () => void generate(), disabled: loading },
322
445
  digest ? tr('regenerate') : tr('generate')),
323
- digest?.markdown ? h('button', { style: styles.button, onClick: () => void copy() }, copied ? tr('copied') : tr('copy')) : null,
324
- h('button', { style: styles.button, onClick: () => setOpen(false) }, tr('close')))) : null
446
+ digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void copy() }, copied ? tr('copied') : tr('copy')) : null,
447
+ digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void download() }, tr('download')) : null,
448
+ h('button', { style: styles.buttonSecondary, onClick: () => setOpen(false) }, tr('close')))) : null
325
449
 
326
450
  return h(React.Fragment, null, h(CrashBanner), h('div', null, chip), panel)
327
451
  }
328
452
 
329
453
  /** One labelled number input bound to a form field. */
330
454
  function NumberField({ label, value, onChange, step }) {
331
- return h('label', { style: styles.field },
455
+ return h('label', { style: styles.fieldWide },
332
456
  h('span', { style: styles.label }, label),
333
457
  h('input', {
334
- style: styles.input,
458
+ style: styles.inputWide,
335
459
  type: 'number',
336
460
  step: step ?? 1,
337
461
  value: value ?? '',
@@ -346,11 +470,45 @@ window.__ModuleLoader__.load({
346
470
  h('span', null, label))
347
471
  }
348
472
 
473
+ /** One card section on the settings page. */
474
+ function Card({ title, extra, children }) {
475
+ return h('div', { style: styles.card2 },
476
+ h('div', { style: styles.cardHead },
477
+ h('div', { style: styles.cardTitle }, h('span', { style: styles.accentBar }), title),
478
+ extra ?? null),
479
+ children)
480
+ }
481
+
482
+ /** A full-row toggle: the whole row is the click target, the knob is obvious. */
483
+ function SwitchRow({ label, hint, checked, onChange }) {
484
+ const on = checked === true
485
+ const toggle = () => onChange(!on)
486
+ return h('div', {
487
+ role: 'switch',
488
+ 'aria-checked': on,
489
+ tabIndex: 0,
490
+ style: on ? { ...styles.switchRow, ...styles.switchRowOn } : styles.switchRow,
491
+ onClick: toggle,
492
+ onKeyDown: event => {
493
+ if (event.key === 'Enter' || event.key === ' ') {
494
+ event.preventDefault()
495
+ toggle()
496
+ }
497
+ },
498
+ },
499
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0 } },
500
+ h('span', { style: { fontSize: 13 } }, label),
501
+ hint ? h('span', { style: styles.hint }, hint) : null),
502
+ h('div', { style: on ? { ...styles.switchTrack, ...styles.switchTrackOn } : styles.switchTrack },
503
+ h('div', { style: on ? { ...styles.switchKnob, ...styles.switchKnobOn } : styles.switchKnob })))
504
+ }
505
+
349
506
  /** Settings page section: engine, triggers, API budget and usage cards. */
350
507
  function ColophonSettings() {
351
508
  const [form, setForm] = useState(null)
352
509
  const [status, setStatus] = useState(null)
353
510
  const [custom, setCustom] = useState(null)
511
+ const [range, setRange] = useState({ from: '', to: '' })
354
512
  const [message, setMessage] = useState('')
355
513
  const [failed, setFailed] = useState('')
356
514
 
@@ -410,6 +568,19 @@ window.__ModuleLoader__.load({
410
568
  } catch { setCustom(null) }
411
569
  }
412
570
 
571
+ const applyRange = () => {
572
+ const from = Date.parse(range.from)
573
+ const to = range.to === '' ? Date.now() : Date.parse(range.to)
574
+ if (!Number.isFinite(from) || !Number.isFinite(to) || from > to) {
575
+ setFailed(tr('rangeInvalid'))
576
+ setMessage('')
577
+ return
578
+ }
579
+ setFailed('')
580
+ setCustom(null)
581
+ void loadCustom(from, to)
582
+ }
583
+
413
584
  if (!form) {
414
585
  return h('div', { style: styles.section },
415
586
  h(CrashBanner),
@@ -417,72 +588,100 @@ window.__ModuleLoader__.load({
417
588
  }
418
589
 
419
590
  const usage = status?.usage ?? {}
420
- const card = (label, range) => h('div', { style: styles.card },
591
+ const usageCard = (label, range) => h('div', { style: styles.usageCard },
421
592
  h('div', { style: styles.label }, label),
422
- h('div', { style: styles.cardValue }, money(range?.costCNY)),
423
- h('div', { style: styles.muted }, tr('tokensLabel', { tokens: integer(range?.tokens) }), ' · ', tr('calls', { count: range?.calls ?? 0 })))
593
+ h('div', { style: styles.usageValue }, money(range?.costCNY)),
594
+ h('div', { style: styles.hint }, tr('tokensLabel', { tokens: integer(range?.tokens) }), ' · ', tr('calls', { count: range?.calls ?? 0 })))
595
+
596
+ const queueItems = status?.queueItems ?? []
597
+ const queueCount = Number(status?.queueCount ?? status?.queue ?? 0) || 0
598
+ const enabled = form.enabled === true
599
+ const apiOn = form.engine === 'api'
600
+ const pill = (on, onText, offText) => h('span', { style: on ? { ...styles.pill, ...styles.pillOn } : { ...styles.pill, ...styles.pillOff } },
601
+ h('span', { style: { width: 6, height: 6, borderRadius: 999, background: on ? '#6fe0a8' : 'rgba(255,255,255,0.4)' } }),
602
+ on ? onText : offText)
424
603
 
425
- return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12, fontSize: 13 } },
604
+ return h('div', { style: styles.page },
426
605
  h(CrashBanner),
427
- h('div', { style: styles.muted }, tr('settingsIntro')),
428
- h('div', { style: styles.section },
429
- h(Check, { label: tr('enabled'), checked: form.enabled, onChange: value => updateTop('enabled', value) }),
430
- h('label', { style: styles.field },
431
- h('span', { style: styles.label }, tr('engine')),
432
- h('select', { style: styles.input, value: form.engine, onChange: event => updateTop('engine', event.target.value) },
433
- h('option', { value: 'rules' }, tr('engineRules')),
434
- h('option', { value: 'api' }, tr('engineApi'))))),
435
- h('div', { style: styles.section },
436
- h('div', { style: styles.sectionTitle }, tr('triggers')),
437
- h(Check, { label: tr('onIdle'), checked: form.triggers.onIdle, onChange: value => update('triggers', 'onIdle', value) }),
438
- h(Check, { label: tr('onSwitch'), checked: form.triggers.onSwitch, onChange: value => update('triggers', 'onSwitch', value) }),
439
- h(Check, { label: tr('closeBatch'), checked: form.triggers.closeBatch, onChange: value => update('triggers', 'closeBatch', value) }),
440
- h('div', { style: styles.warn }, tr('closeBatchWarn')),
606
+ h('div', { style: styles.headCard },
607
+ h('div', { style: styles.headTitle },
608
+ '卷末 · Colophon',
609
+ pill(enabled, tr('statusOn'), tr('statusOff'))),
610
+ h('div', { style: styles.headSub }, tr('settingsSubtitle')),
611
+ h('div', { style: styles.hint }, tr('saveHint'))),
612
+ h(Card, { title: tr('basicTitle') },
613
+ h(SwitchRow, {
614
+ label: tr('enabled'), hint: tr('enabledHint'), checked: enabled,
615
+ onChange: value => updateTop('enabled', value),
616
+ }),
617
+ h('div', { style: styles.row2 },
618
+ h('label', { style: styles.fieldWide },
619
+ h('span', { style: styles.label }, tr('engine')),
620
+ h('select', { style: styles.inputWide, value: form.engine, onChange: event => updateTop('engine', event.target.value) },
621
+ h('option', { value: 'rules' }, tr('engineRules')),
622
+ h('option', { value: 'api' }, tr('engineApi')))),
623
+ h('div', { style: { ...styles.hint, flex: '1 1 240px', paddingBottom: 6 } }, tr('engineHint')))),
624
+ h(Card, { title: tr('triggers') },
625
+ h(SwitchRow, {
626
+ label: tr('onIdle'), hint: tr('onIdleHint'), checked: form.triggers.onIdle === true,
627
+ onChange: value => update('triggers', 'onIdle', value),
628
+ }),
629
+ h(SwitchRow, {
630
+ label: tr('onSwitch'), hint: tr('onSwitchHint'), checked: form.triggers.onSwitch === true,
631
+ onChange: value => update('triggers', 'onSwitch', value),
632
+ }),
633
+ h(SwitchRow, {
634
+ label: tr('closeBatch'), checked: form.triggers.closeBatch === true,
635
+ onChange: value => update('triggers', 'closeBatch', value),
636
+ }),
637
+ h('div', { style: styles.callout }, tr('closeBatchWarn')),
441
638
  h(NumberField, {
442
639
  label: tr('closeBatchMax'), value: form.triggers.closeBatchMaxSessions, step: 1,
443
640
  onChange: value => update('triggers', 'closeBatchMaxSessions', value),
444
641
  })),
445
- h('div', { style: styles.section },
446
- h('div', { style: styles.sectionTitle }, tr('apiSection')),
447
- h('div', { style: styles.muted }, tr('apiNote')),
448
- h('div', { style: styles.row },
449
- h('label', { style: styles.field, key: 'provider' },
642
+ h(Card, {
643
+ title: tr('apiSection'),
644
+ extra: pill(apiOn, tr('apiOn'), tr('apiOff')),
645
+ },
646
+ h('div', { style: styles.hint }, tr('apiNote')),
647
+ h('div', { style: styles.row2 },
648
+ h('label', { style: styles.fieldWide },
450
649
  h('span', { style: styles.label }, tr('provider')),
451
- h('input', { style: styles.input, value: form.api.provider, placeholder: 'deepseek', onChange: event => update('api', 'provider', event.target.value) })),
452
- h('label', { style: styles.field, key: 'model' },
650
+ h('input', { style: styles.inputWide, value: form.api.provider, placeholder: 'deepseek', onChange: event => update('api', 'provider', event.target.value) })),
651
+ h('label', { style: styles.fieldWide },
453
652
  h('span', { style: styles.label }, tr('model')),
454
- h('input', { style: styles.input, value: form.api.model, onChange: event => update('api', 'model', event.target.value) }))),
455
- h('div', { style: styles.row },
653
+ h('input', { style: styles.inputWide, value: form.api.model, onChange: event => update('api', 'model', event.target.value) }))),
654
+ h('div', { style: styles.row2 },
456
655
  h(NumberField, { label: tr('priceIn'), value: form.api.priceInCNYPerM, step: 0.1, onChange: value => update('api', 'priceInCNYPerM', value) }),
457
656
  h(NumberField, { label: tr('priceOut'), value: form.api.priceOutCNYPerM, step: 0.1, onChange: value => update('api', 'priceOutCNYPerM', value) })),
458
- h('div', { style: styles.row },
657
+ h('div', { style: styles.row2 },
459
658
  h(NumberField, { label: tr('perSummaryCap'), value: form.api.maxCostPerSummaryCNY, step: 0.01, onChange: value => update('api', 'maxCostPerSummaryCNY', value) }),
460
659
  h(NumberField, { label: tr('dailyBudget'), value: form.api.dailyTokenBudget, step: 1000, onChange: value => update('api', 'dailyTokenBudget', value) }),
461
- h('label', { style: styles.field, key: 'overCap' },
660
+ h('label', { style: styles.fieldWide },
462
661
  h('span', { style: styles.label }, tr('overCap')),
463
- h('select', { style: styles.input, value: form.api.overCap, onChange: event => update('api', 'overCap', event.target.value) },
662
+ h('select', { style: styles.inputWide, value: form.api.overCap, onChange: event => update('api', 'overCap', event.target.value) },
464
663
  h('option', { value: 'queue' }, tr('overCapQueue')),
465
- h('option', { value: 'skip' }, tr('overCapSkip')))))),
466
- h('div', { style: styles.section },
467
- h('div', { style: styles.sectionTitle }, tr('filter')),
468
- h('div', { style: styles.row },
664
+ h('option', { value: 'skip' }, tr('overCapSkip'))))),
665
+ apiOn && status && status.apiAvailable === false
666
+ ? h('div', { style: styles.callout }, tr('apiUnavailable'))
667
+ : null),
668
+ h(Card, { title: tr('filter') },
669
+ h('div', { style: styles.row2 },
469
670
  h(NumberField, { label: tr('minMessages'), value: form.filter.minMessages, onChange: value => update('filter', 'minMessages', value) }),
470
671
  h(NumberField, { label: tr('minTokens'), value: form.filter.minTokens, step: 500, onChange: value => update('filter', 'minTokens', value) }))),
471
- form.engine === 'api' && status && status.apiAvailable === false
472
- ? h('div', { style: styles.warn }, tr('apiUnavailable'))
473
- : null,
474
- h('div', { style: styles.section },
475
- h('div', { style: styles.sectionTitle }, tr('queueTitle'), ' · ',
476
- h('span', { style: styles.muted }, String(status?.queueCount ?? status?.queue ?? 0))),
477
- (status?.queueItems ?? []).length === 0
478
- ? h('div', { style: styles.muted }, tr('queueEmpty'))
479
- : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
480
- status.queueItems.map(item => h('div', { key: item.sessionId, style: styles.muted },
481
- item.sessionId, ' · ', item.reason, ' · ', new Date(item.at).toLocaleString()))),
482
- h('div', { style: styles.actions },
672
+ h(Card, { title: tr('queueTitle'), extra: pill(queueCount > 0, String(queueCount), String(queueCount)) },
673
+ h('div', { style: styles.hint }, tr('queueHint')),
674
+ queueItems.length === 0
675
+ ? h('div', { style: styles.emptyBox }, tr('queueEmpty'))
676
+ : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
677
+ queueItems.map(item => h('div', { key: item.sessionId, style: styles.listRow },
678
+ h('span', { style: { fontWeight: 600 } }, String(item.sessionId).slice(0, 14)),
679
+ h('span', { style: styles.hint }, item.reason),
680
+ h('span', { style: { ...styles.hint, marginLeft: 'auto' } }, new Date(item.at).toLocaleString())))),
681
+ h('div', { style: styles.actionsBar },
483
682
  h('button', {
484
- style: styles.button,
485
- disabled: (status?.queueCount ?? 0) === 0,
683
+ style: queueCount === 0 ? { ...styles.buttonSecondary, ...styles.buttonDisabled } : styles.buttonSecondary,
684
+ disabled: queueCount === 0,
486
685
  onClick: async () => {
487
686
  setFailed('')
488
687
  try {
@@ -494,29 +693,36 @@ window.__ModuleLoader__.load({
494
693
  }
495
694
  },
496
695
  }, tr('queueProcess')))),
497
- h('div', { style: styles.section },
498
- h('div', { style: styles.sectionTitle }, tr('usage'), ' · ', h('span', { style: styles.ok }, tr('localZero'))),
499
- h('div', { style: styles.cards },
500
- card(tr('usageHour'), usage.hour),
501
- card(tr('usageDay'), usage.day),
502
- card(tr('usageWeek'), usage.week),
503
- card(tr('usageMonth'), usage.month),
504
- custom ? card(tr('usageCustom'), custom) : null),
505
- h('div', { style: styles.row },
506
- h('label', { style: styles.field },
696
+ h(Card, {
697
+ title: tr('usage'),
698
+ extra: h('span', { style: styles.hint }, tr('localZero')),
699
+ },
700
+ h('div', { style: styles.usageGrid },
701
+ usageCard(tr('usageHour'), usage.hour),
702
+ usageCard(tr('usageDay'), usage.day),
703
+ usageCard(tr('usageWeek'), usage.week),
704
+ usageCard(tr('usageMonth'), usage.month),
705
+ custom ? usageCard(tr('usageCustom'), custom) : null),
706
+ h('div', { style: styles.row2 },
707
+ h('label', { style: styles.fieldWide },
507
708
  h('span', { style: styles.label }, tr('from')),
508
- h('input', { style: styles.input, type: 'datetime-local', onChange: event => {
509
- const from = Date.parse(event.target.value)
510
- const to = Date.now()
511
- setCustom(null)
512
- void loadCustom(from, to)
513
- } }))),
514
- status ? h('div', { style: styles.muted },
515
- tr('dataRoot'), ': ', status.dataRoot, ' · ', tr('queue'), ': ', status.queue ?? 0) : null),
516
- failed ? h('div', { style: styles.warn }, failed) : null,
709
+ h('input', {
710
+ style: styles.inputWide, type: 'datetime-local', value: range.from,
711
+ onChange: event => setRange(current => ({ ...current, from: event.target.value })),
712
+ })),
713
+ h('label', { style: styles.fieldWide },
714
+ h('span', { style: styles.label }, tr('to')),
715
+ h('input', {
716
+ style: styles.inputWide, type: 'datetime-local', value: range.to,
717
+ onChange: event => setRange(current => ({ ...current, to: event.target.value })),
718
+ })),
719
+ h('button', { style: styles.buttonSecondary, onClick: () => void applyRange() }, tr('apply'))),
720
+ h('div', { style: styles.hint }, tr('customHint')),
721
+ status ? h('div', { style: styles.hint }, tr('dataRoot'), ': ', status.dataRoot) : null),
722
+ failed ? h('div', { style: styles.callout }, failed) : null,
517
723
  message ? h('div', { style: styles.ok }, message) : null,
518
- h('div', { style: styles.actions },
519
- h('button', { style: styles.button, onClick: () => void save() }, tr('save'))))
724
+ h('div', { style: styles.actionsBar },
725
+ h('button', { style: styles.buttonPrimary, onClick: () => void save() }, tr('save'))))
520
726
  }
521
727
 
522
728
  return {
package/lib/api.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * @module dsh-colophon/lib/api
6
6
  */
7
7
 
8
- import { bullets, clip, estimateTokens, lastParagraph, section } from './text.js'
8
+ import { bullets, clip, estimateTokens, lastParagraph, redactSecrets, section, withoutTrailingFence } from './text.js'
9
9
  import { costCNY } from './usage.js'
10
10
  import { renderDigest } from './digest.js'
11
11
 
@@ -18,6 +18,8 @@ export const API_PROMPT = [
18
18
  '一段话,说明用户最终想要什么。',
19
19
  '## 结论',
20
20
  '一段话,说明现在处于什么状态、结论是什么;没有结论就写“尚无结论”。',
21
+ '## 决策',
22
+ '- 条目列表(最多 4 条),列出会话中做出的关键决定及一句话理由;没有就省略该小节。',
21
23
  '## 已完成',
22
24
  '- 条目列表(最多 8 条),只列已确认完成的事。',
23
25
  '## 下一步',
@@ -96,13 +98,29 @@ export function estimateCost(built, config) {
96
98
  * @returns {object}
97
99
  */
98
100
  export function parseApiDigest(text, checkpoint, meta = {}) {
99
- const reply = String(text ?? '').trim()
100
101
  const now = meta.now ?? Date.now()
101
- const goal = section(reply, /(目标|goal)/iu) || (typeof checkpoint?.goal === 'string' ? checkpoint.goal : '')
102
- const conclusion = section(reply, /(结论|总结|conclusion|summary)/iu) || lastParagraph(reply)
103
- const done = bullets(reply, /(已完成|完成情况|done)/iu, 8, 140)
104
- const nextSteps = bullets(reply, /(下一步|后续|待办|next)/iu, 5, 140)
105
- const risks = bullets(reply, /(风险|注意|警告|warning|risk)/iu, 4, 140)
102
+ const reply = withoutTrailingFence(String(text ?? '').trim())
103
+ const fromJson = tryParseJsonDigest(reply)
104
+ const goal = fromJson?.goal ?? (section(reply, /(目标|goal)/iu) || (typeof checkpoint?.goal === 'string' ? checkpoint.goal : ''))
105
+ const conclusion = fromJson?.conclusion ?? (section(reply, /(结论|总结|conclusion|summary)/iu) || lastParagraph(reply))
106
+ const decisions = toList(fromJson?.decisions, 4, 140)
107
+ if (decisions.length === 0) decisions.push(...bullets(reply, /(决策|方案|决定|decision)/iu, 4, 140))
108
+ const done = toList(fromJson?.done, 8, 140)
109
+ if (done.length === 0) done.push(...bullets(reply, /(已完成|完成情况|done)/iu, 8, 140))
110
+ const nextSteps = toList(fromJson?.nextSteps, 5, 140)
111
+ if (nextSteps.length === 0) nextSteps.push(...bullets(reply, /(下一步|后续|待办|next)/iu, 5, 140))
112
+ const risks = toList(fromJson?.risks, 4, 140)
113
+ if (risks.length === 0) risks.push(...bullets(reply, /(风险|注意|警告|warning|risk)/iu, 4, 140))
114
+ const writes = toList(fromJson?.writes ?? fromJson?.files, 8, 160)
115
+ if (writes.length === 0) {
116
+ writes.push(...bullets(reply, /(涉及文件|相关文件|files|changed)/iu, 8, 160))
117
+ if (writes.length === 0) {
118
+ for (const file of Array.isArray(checkpoint?.files) ? checkpoint.files : []) {
119
+ if (file?.op === 'write' && typeof file.path === 'string' && !writes.includes(clip(redactSecrets(file.path), 160))) writes.push(clip(redactSecrets(file.path), 160))
120
+ if (writes.length >= 8) break
121
+ }
122
+ }
123
+ }
106
124
  const usage = meta.usage ?? {}
107
125
  const digest = {
108
126
  v: 1,
@@ -116,8 +134,10 @@ export function parseApiDigest(text, checkpoint, meta = {}) {
116
134
  messageCount: checkpoint?.messageCount ?? 0,
117
135
  estTokens: checkpoint?.estTokens ?? 0,
118
136
  seq: checkpoint?.seq ?? 0,
119
- goal: goal === '' ? '(未捕捉到目标)' : clip(goal, 900),
120
- conclusion: conclusion === '' ? '(本次对话没有留下文字结论)' : clip(conclusion, 900),
137
+ goal: goal === '' ? '(未捕捉到目标)' : clip(redactSecrets(String(goal)), 900),
138
+ conclusion: conclusion === '' ? '(本次对话没有留下文字结论)' : clip(redactSecrets(String(conclusion)), 900),
139
+ decisions,
140
+ writes,
121
141
  done,
122
142
  nextSteps,
123
143
  risks,
@@ -125,8 +145,46 @@ export function parseApiDigest(text, checkpoint, meta = {}) {
125
145
  input: Number(usage.inputTokens) || 0,
126
146
  output: Number(usage.outputTokens) || 0,
127
147
  },
128
- params: {},
148
+ params: { rulesVersion: 3 },
129
149
  }
130
150
  digest.markdown = renderDigest(digest)
131
151
  return digest
132
152
  }
153
+
154
+ /**
155
+ * Accept either the requested Markdown sections or a JSON object when the
156
+ * model answers with one (both are common; neither must break the digest).
157
+ * @param {string} reply trimmed reply text.
158
+ * @returns {any}
159
+ */
160
+ function tryParseJsonDigest(reply) {
161
+ const start = reply.indexOf('{')
162
+ if (start < 0) return null
163
+ const end = reply.lastIndexOf('}')
164
+ if (end <= start) return null
165
+ try {
166
+ const parsed = JSON.parse(reply.slice(start, end + 1))
167
+ return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null
168
+ } catch {
169
+ return null
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Coerce a JSON field into a bounded list of redacted strings.
175
+ * @param {any} value JSON field (array of strings or objects with `text`).
176
+ * @param {number} limit maximum items.
177
+ * @param {number} maxChars per-item character cap.
178
+ * @returns {string[]}
179
+ */
180
+ function toList(value, limit, maxChars) {
181
+ if (!Array.isArray(value)) return []
182
+ const items = []
183
+ for (const entry of value) {
184
+ const text = typeof entry === 'string' ? entry : entry && typeof entry.text === 'string' ? entry.text : ''
185
+ const trimmed = text.trim()
186
+ if (trimmed !== '') items.push(clip(redactSecrets(trimmed), maxChars))
187
+ if (items.length >= limit) break
188
+ }
189
+ return items
190
+ }
package/lib/digest.js CHANGED
@@ -4,18 +4,21 @@
4
4
  * @module dsh-colophon/lib/digest
5
5
  */
6
6
 
7
- import { bullets, clip, lastParagraph, section, withoutTrailingFence } from './text.js'
7
+ import { bullets, clip, lastParagraph, redactSecrets, section, withoutTrailingFence } from './text.js'
8
8
 
9
9
  /** Bump when summary extraction rules change; startup backfill rebuilds stale rules digests. */
10
- export const RULES_VERSION = 2
10
+ export const RULES_VERSION = 3
11
11
 
12
12
  /** Defaults for the length filter (also mirrored in the Config schema). */
13
13
  export const FILTER_DEFAULTS = Object.freeze({ minMessages: 20, minTokens: 4000 })
14
14
 
15
- const CONCLUSION_HEADING = /(结论|总结|conclusion|summary|完成情况)/iu
15
+ const CONCLUSION_HEADING = /(结论|总结|完成情况|conclusion|summary|outcome)/iu
16
16
  const NEXT_HEADING = /(下一步|后续|待办|next step|next steps|todo|follow[- ]?up)/iu
17
17
  const RISK_HEADING = /(注意|风险|警告|warning|caution|limitation|限制|blocker)/iu
18
18
  const RISK_LINE = /(注意|风险|警告|warning|caution|blocker|无法|失败|cannot|can't)/iu
19
+ const DECISION_HEADING = /(决策|方案|决定|取舍|design|decision)/iu
20
+ const DONE_WORDS = /(完成|已完成|已实现|已修复|已更新|已通过|fixed|done|implemented|shipped)/iu
21
+ const CHECKBOX = /^\s*[-*]\s*\[ \]\s+\S/u
19
22
 
20
23
  /**
21
24
  * Decide whether a session is long enough to deserve a digest.
@@ -33,15 +36,39 @@ export function shouldSummarize(checkpoint, filter = {}) {
33
36
 
34
37
  /**
35
38
  * The conclusion of a session tail: an explicit conclusion section wins, then
36
- * the last paragraph of the last reply.
39
+ * the last paragraph that reports completion, then the last paragraph.
37
40
  * @param {string} assistantText last assistant reply.
38
41
  * @returns {string}
39
42
  */
40
43
  export function conclusionOf(assistantText) {
41
44
  const explicit = section(assistantText, CONCLUSION_HEADING)
42
- if (explicit !== '') return clip(explicit, 700)
45
+ if (explicit !== '') return clip(redactSecrets(explicit), 700)
46
+ const paragraphs = String(assistantText ?? '')
47
+ .replace(/\r\n/gu, '\n')
48
+ .split(/\n{2,}/u)
49
+ .map(part => part.trim())
50
+ .filter(part => part !== '')
51
+ const finished = [...paragraphs].reverse().find(part => DONE_WORDS.test(part))
52
+ if (finished !== undefined) return clip(redactSecrets(withoutTrailingFence(finished)), 700)
43
53
  const paragraph = withoutTrailingFence(lastParagraph(assistantText))
44
- return paragraph === '' ? '' : clip(paragraph, 700)
54
+ return paragraph === '' ? '' : clip(redactSecrets(paragraph), 700)
55
+ }
56
+
57
+ /**
58
+ * Unchecked markdown checkboxes of a reply, i.e. the author's own todo list.
59
+ * @param {string} text assistant reply.
60
+ * @param {number} [limit] maximum items.
61
+ * @returns {string[]}
62
+ */
63
+ export function uncheckedTodos(text, limit = 4) {
64
+ const items = []
65
+ for (const line of String(text ?? '').split('\n')) {
66
+ if (!CHECKBOX.test(line)) continue
67
+ const item = line.replace(/^\s*[-*]\s*\[ \]\s+/u, '').trim()
68
+ if (item !== '') items.push(clip(redactSecrets(item), 140))
69
+ if (items.length >= limit) break
70
+ }
71
+ return items
45
72
  }
46
73
 
47
74
  /**
@@ -58,43 +85,60 @@ export function buildDigest(checkpoint, options = {}) {
58
85
  const errors = Array.isArray(checkpoint.toolErrors) ? checkpoint.toolErrors : []
59
86
  const assistantText = String(checkpoint.assistantText ?? '')
60
87
 
88
+ const writes = []
61
89
  const done = []
62
90
  for (const file of files) {
63
- if (done.length >= 8) break
64
- if (file && typeof file.path === 'string') done.push(`${file.op === 'write' ? '写入' : '读取'} ${clip(file.path, 120)}`)
91
+ if (!file || typeof file.path !== 'string') continue
92
+ const path = clip(file.path, 120)
93
+ if (file.op === 'write' && !writes.includes(path)) writes.push(path)
94
+ if (done.length >= 8) continue
95
+ done.push(`${file.op === 'write' ? '修改' : '读取'} ${path}`)
65
96
  }
66
97
  for (const command of commands) {
67
98
  if (done.length >= 8) break
68
99
  done.push(`运行 ${clip(command, 120)}`)
69
100
  }
70
101
 
71
- let nextSteps = bullets(assistantText, NEXT_HEADING, 5, 140)
102
+ const nextSteps = uncheckedTodos(assistantText)
103
+ if (nextSteps.length === 0) nextSteps.push(...bullets(assistantText, NEXT_HEADING, 5, 140))
72
104
  if (nextSteps.length === 0) {
73
105
  for (const line of assistantText.split('\n')) {
74
106
  const item = line.replace(/^\s*(?:[-*+]|\d+[.)])\s+/u, '').trim()
75
- if (item !== '' && /^(?:下一步|待办|todo|next)[::]/iu.test(item)) nextSteps.push(clip(item, 140))
107
+ if (item !== '' && /^(?:下一步|待办|todo|next)[::]/iu.test(item)) nextSteps.push(clip(redactSecrets(item), 140))
76
108
  if (nextSteps.length >= 5) break
77
109
  }
78
110
  }
79
111
 
112
+ const decisions = bullets(assistantText, DECISION_HEADING, 4, 140)
113
+ if (decisions.length === 0) {
114
+ for (const line of assistantText.split('\n')) {
115
+ const item = line.trim()
116
+ if (item !== '' && item.length <= 160 && /(决定|采用|选择|取舍|改用)/u.test(item)) {
117
+ decisions.push(clip(redactSecrets(item.replace(/^[#>\-*\s`]+/u, '')), 140))
118
+ }
119
+ if (decisions.length >= 3) break
120
+ }
121
+ }
122
+
80
123
  const risks = []
81
124
  const seenErrors = new Set()
82
125
  for (const error of errors) {
83
126
  const name = typeof error?.name === 'string' ? error.name : 'tool'
84
127
  if (seenErrors.has(name)) continue
85
128
  seenErrors.add(name)
86
- risks.push(`工具 ${clip(name, 60)} 报错${typeof error?.reason === 'string' ? `:${clip(error.reason, 80)}` : ''}`)
129
+ risks.push(`工具 ${clip(name, 60)} 报错${typeof error?.reason === 'string' ? `:${clip(redactSecrets(error.reason), 80)}` : ''}`)
87
130
  if (risks.length >= 3) break
88
131
  }
89
132
  for (const line of assistantText.split('\n')) {
90
133
  if (risks.length >= 4) break
91
134
  const item = line.replace(/^\s*(?:[-*+]|\d+[.)])\s+/u, '').trim()
92
- if (item !== '' && item.length <= 160 && RISK_LINE.test(item) && !risks.includes(clip(item, 140))) {
93
- risks.push(clip(item, 140))
135
+ if (item !== '' && item.length <= 160 && RISK_LINE.test(item)) {
136
+ const risk = clip(redactSecrets(item), 140)
137
+ if (!risks.includes(risk)) risks.push(risk)
94
138
  }
95
139
  }
96
140
 
97
- const goal = typeof checkpoint.goal === 'string' && checkpoint.goal !== '' ? checkpoint.goal : '(未捕捉到目标)'
141
+ const goal = redactSecrets(typeof checkpoint.goal === 'string' && checkpoint.goal !== '' ? checkpoint.goal : '(未捕捉到目标)')
98
142
  const conclusion = conclusionOf(assistantText) || (checkpoint.messageCount === 0 ? '(空会话)' : '(本次对话没有留下文字结论)')
99
143
 
100
144
  const digest = {
@@ -112,6 +156,8 @@ export function buildDigest(checkpoint, options = {}) {
112
156
  seq: checkpoint.seq ?? 0,
113
157
  goal,
114
158
  conclusion,
159
+ decisions,
160
+ writes,
115
161
  done,
116
162
  nextSteps,
117
163
  risks,
@@ -145,7 +191,19 @@ export function renderDigest(digest) {
145
191
  lines.push('## 结论')
146
192
  lines.push('')
147
193
  lines.push(digest.conclusion)
148
- if (digest.done.length > 0) {
194
+ if (Array.isArray(digest.decisions) && digest.decisions.length > 0) {
195
+ lines.push('')
196
+ lines.push('## 决策')
197
+ lines.push('')
198
+ for (const item of digest.decisions) lines.push(`- ${item}`)
199
+ }
200
+ if (Array.isArray(digest.writes) && digest.writes.length > 0) {
201
+ lines.push('')
202
+ lines.push('## 涉及文件')
203
+ lines.push('')
204
+ for (const item of digest.writes) lines.push(`- ${item}`)
205
+ }
206
+ if (Array.isArray(digest.done) && digest.done.length > 0) {
149
207
  lines.push('')
150
208
  lines.push('## 已完成')
151
209
  lines.push('')
package/lib/text.js CHANGED
@@ -157,6 +157,32 @@ export function bullets(text, heading, limit = 5, maxChars = 120) {
157
157
  return items
158
158
  }
159
159
 
160
+ /**
161
+ * Redact credential-shaped strings before a digest is written to disk or
162
+ * pasted into another conversation.
163
+ * @param {string} text source text.
164
+ * @returns {string}
165
+ */
166
+ export function redactSecrets(text) {
167
+ return String(text ?? '')
168
+ .replace(/\b(?:sk|rk|pk)-[A-Za-z0-9_-]{12,}\b/gu, '[redacted-key]')
169
+ .replace(/\bgh[pousr]_[A-Za-z0-9]{16,}\b/gu, '[redacted-token]')
170
+ .replace(/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/gu, '[redacted-aws-key]')
171
+ .replace(/\b(Bearer)\s+[A-Za-z0-9._-]{12,}/giu, '$1 [redacted]')
172
+ .replace(/\b(password|passwd|secret|token|api[_-]?key)\s*[=:]\s*['"]?[^\s'"]{6,}/giu, '$1=[redacted]')
173
+ }
174
+
175
+ /**
176
+ * Whether a text is predominantly Chinese (used to pick the digest wording).
177
+ * @param {string} text source text.
178
+ * @returns {boolean}
179
+ */
180
+ export function isChinese(text) {
181
+ const value = String(text ?? '')
182
+ const cjk = (value.match(/[\u3400-\u9fff]/gu) ?? []).length
183
+ return cjk >= Math.max(2, value.length / 8)
184
+ }
185
+
160
186
  /**
161
187
  * Rough token estimate for a string (the 4-chars-per-token heuristic used by
162
188
  * the context dashboards).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-colophon",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Colophon(卷末)— keep a local, token-free conclusion digest for every conversation, so reopening an old session starts from its final state instead of its full history.",
5
5
  "documentation": "README.md",
6
6
  "license": "MIT",