dsh-colophon 0.2.3 → 0.2.5
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 +15 -0
- package/client.js +162 -18
- package/index.js +4 -2
- package/lib/api.js +42 -3
- package/lib/app.js +9 -5
- package/lib/digest.js +73 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## 0.2.5(摘要面板排版精修)
|
|
2
|
+
|
|
3
|
+
- 区块标题加大到 15px 并使用主题强调色,标题前带强调竖条。
|
|
4
|
+
- 面板右上角新增 ✕ 关闭按钮。
|
|
5
|
+
- 底部操作区与正文用分隔线分开。
|
|
6
|
+
- 区块内的条目改为有序编号(1. 2. 3.),不再使用短横线。
|
|
7
|
+
|
|
8
|
+
## 0.2.4(摘要区块可配置 + 明亮摘要面板)
|
|
9
|
+
|
|
10
|
+
- 摘要内容改为**区块制**,可在设置页逐项开关:目标 / 结论 / 决策 / 涉及文件 / 完成情况 / 下一步 / 风险与注意 / 关键词 / 待确认问题(默认只开目标、结论、决策、下一步、风险与注意,不再输出中间的已完成动作)。
|
|
11
|
+
- 摘要面板改用主题变量配色(浅色主题下为明亮白底),按区块显示带标题的内容,不再是整段黑色等宽文本。
|
|
12
|
+
- 对话输入框上方改为明确的「生成卷末摘要」按钮,面板标题栏内直接提供「立即生成 / 重新生成」主按钮。
|
|
13
|
+
- 短对话也支持总结:默认门槛降为 2 条消息 / 100 token;阈值仍可在设置页调整。
|
|
14
|
+
- 本地规则引擎补上关键词与待确认问题的抽取;API 引擎按所选区块生成对应小节。
|
|
15
|
+
|
|
1
16
|
# Colophon(卷末)
|
|
2
17
|
|
|
3
18
|
> 旧书卷末的那一笔,记录这本书由谁写成、在哪一页收束。
|
package/client.js
CHANGED
|
@@ -23,8 +23,8 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const DICT = {
|
|
24
24
|
zh: {
|
|
25
25
|
chip: '卷末',
|
|
26
|
-
chipReady: '
|
|
27
|
-
chipEmpty: '
|
|
26
|
+
chipReady: '卷末摘要',
|
|
27
|
+
chipEmpty: '生成卷末摘要',
|
|
28
28
|
panelTitle: '卷末',
|
|
29
29
|
empty: '这条会话还没有卷末:对话太短,或者还没生成。',
|
|
30
30
|
generate: '立即生成',
|
|
@@ -87,6 +87,13 @@ window.__ModuleLoader__.load({
|
|
|
87
87
|
queueRun: '队列已处理',
|
|
88
88
|
apiUnavailable: '当前环境没有可用的模型服务(llm):API 引擎会回退到本地 rules 摘要,并把它放进待确认队列。',
|
|
89
89
|
statusFailed: '状态读取失败',
|
|
90
|
+
sectionsTitle: '摘要区块',
|
|
91
|
+
sectionsHint: '总结里会出现哪些区块,按需勾选;区块越多,内容越长。',
|
|
92
|
+
secGoal: '目标', secConclusion: '结论', secDecisions: '决策', secFiles: '涉及文件',
|
|
93
|
+
secProgress: '完成情况', secNextSteps: '下一步', secRisks: '风险与注意', secKeywords: '关键词', secQuestions: '待确认问题',
|
|
94
|
+
secGoalHint: '用户最终想要什么', secConclusionHint: '当前状态与结论', secDecisionsHint: '关键决定及理由',
|
|
95
|
+
secFilesHint: '被修改的文件', secProgressHint: '已确认完成的事(中间动作)', secNextStepsHint: '还没做完的事',
|
|
96
|
+
secRisksHint: '报错、限制与未验证假设', secKeywordsHint: '便于检索的短词', secQuestionsHint: '仍需确认的问题',
|
|
90
97
|
basicTitle: '基本设置',
|
|
91
98
|
statusOn: '已启用',
|
|
92
99
|
statusOff: '已暂停',
|
|
@@ -118,8 +125,8 @@ window.__ModuleLoader__.load({
|
|
|
118
125
|
},
|
|
119
126
|
en: {
|
|
120
127
|
chip: 'Colophon',
|
|
121
|
-
chipReady: 'Colophon
|
|
122
|
-
chipEmpty: '
|
|
128
|
+
chipReady: 'Colophon summary',
|
|
129
|
+
chipEmpty: 'Generate summary',
|
|
123
130
|
panelTitle: 'Colophon',
|
|
124
131
|
empty: 'No digest yet for this session: the conversation is short or nothing was generated.',
|
|
125
132
|
generate: 'Generate now',
|
|
@@ -182,6 +189,13 @@ window.__ModuleLoader__.load({
|
|
|
182
189
|
queueRun: 'Queue processed',
|
|
183
190
|
apiUnavailable: 'No model service (llm) is available here: the API engine falls back to local rules digests and queues the session for confirmation.',
|
|
184
191
|
statusFailed: 'Status unavailable',
|
|
192
|
+
sectionsTitle: 'Summary blocks',
|
|
193
|
+
sectionsHint: 'Pick the blocks that appear in the digest; more blocks make it longer.',
|
|
194
|
+
secGoal: 'Goal', secConclusion: 'Conclusion', secDecisions: 'Decisions', secFiles: 'Files',
|
|
195
|
+
secProgress: 'Progress', secNextSteps: 'Next steps', secRisks: 'Risks', secKeywords: 'Keywords', secQuestions: 'Open questions',
|
|
196
|
+
secGoalHint: 'what the user ultimately wants', secConclusionHint: 'current state and result', secDecisionsHint: 'key decisions and why',
|
|
197
|
+
secFilesHint: 'files that were changed', secProgressHint: 'confirmed completed work', secNextStepsHint: 'what is left to do',
|
|
198
|
+
secRisksHint: 'errors, limits, unverified guesses', secKeywordsHint: 'short search terms', secQuestionsHint: 'questions needing confirmation',
|
|
185
199
|
basicTitle: 'Basics',
|
|
186
200
|
statusOn: 'Enabled',
|
|
187
201
|
statusOff: 'Paused',
|
|
@@ -239,23 +253,51 @@ window.__ModuleLoader__.load({
|
|
|
239
253
|
|
|
240
254
|
const styles = {
|
|
241
255
|
chip: {
|
|
242
|
-
display: 'inline-flex', alignItems: 'center', gap: 6, padding: '
|
|
243
|
-
border: '1px solid rgba(
|
|
244
|
-
|
|
256
|
+
display: 'inline-flex', alignItems: 'center', gap: 6, padding: '0 12px', height: 28,
|
|
257
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.14))', borderRadius: 8,
|
|
258
|
+
background: 'var(--dsw-alias-bg-layer-2, #f2f3f5)',
|
|
259
|
+
color: 'var(--dsw-alias-label-primary, #1f2329)', cursor: 'pointer', fontSize: 13, fontWeight: 500,
|
|
260
|
+
},
|
|
261
|
+
chipOn: {
|
|
262
|
+
border: '1px solid var(--dsw-alias-button-primary-fill, #4d6bfe)',
|
|
263
|
+
background: 'color-mix(in srgb, var(--dsw-alias-button-primary-fill, #4d6bfe) 12%, transparent)',
|
|
245
264
|
},
|
|
246
265
|
dot: { width: 7, height: 7, borderRadius: 999, background: '#4cc38a', display: 'inline-block' },
|
|
247
266
|
dotEmpty: { width: 7, height: 7, borderRadius: 999, background: 'rgba(255,255,255,0.35)', display: 'inline-block' },
|
|
248
267
|
panel: {
|
|
249
268
|
position: 'fixed', right: 16, bottom: 96, width: 380, maxWidth: 'calc(100vw - 32px)',
|
|
250
269
|
maxHeight: '62vh', overflow: 'auto', zIndex: 60, padding: 14,
|
|
251
|
-
background: '
|
|
252
|
-
|
|
253
|
-
|
|
270
|
+
background: 'var(--dsw-alias-bg-layer-2, #ffffff)',
|
|
271
|
+
color: 'var(--dsw-alias-label-primary, #1f2329)',
|
|
272
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(0,0,0,0.12))', borderRadius: 12,
|
|
273
|
+
boxShadow: '0 12px 40px rgba(0,0,0,0.22)', fontSize: 13, lineHeight: 1.55,
|
|
274
|
+
},
|
|
275
|
+
panelHead: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 },
|
|
276
|
+
title: { fontSize: 15, fontWeight: 600, color: 'var(--dsw-alias-label-primary, #1f2329)' },
|
|
277
|
+
digestTitle: {
|
|
278
|
+
fontSize: 15, fontWeight: 650, letterSpacing: '-0.01em',
|
|
279
|
+
color: 'var(--dsw-alias-state-business-primary, #4d6bfe)', marginBottom: 6,
|
|
280
|
+
display: 'flex', alignItems: 'center', gap: 7,
|
|
281
|
+
},
|
|
282
|
+
digestTitleBar: { width: 3, height: 14, borderRadius: 2, background: 'currentColor', display: 'inline-block' },
|
|
283
|
+
digestBlock: { marginTop: 6, paddingTop: 14, borderTop: '1px solid var(--dsw-alias-border-l1, rgba(0,0,0,0.07))' },
|
|
284
|
+
digestPara: { margin: '0 0 6px', fontSize: 13, lineHeight: 1.65, color: 'var(--dsw-alias-label-primary, #1f2329)' },
|
|
285
|
+
digestList: { margin: '4px 0 6px', paddingLeft: 20, fontSize: 13, lineHeight: 1.7, color: 'var(--dsw-alias-label-primary, #1f2329)' },
|
|
286
|
+
digestItem: { marginBottom: 2, paddingLeft: 2 },
|
|
287
|
+
digestBody: {
|
|
288
|
+
whiteSpace: 'pre-wrap', wordBreak: 'break-word', margin: 0, fontFamily: 'inherit',
|
|
289
|
+
fontSize: 13, lineHeight: 1.65, color: 'var(--dsw-alias-label-primary, #1f2329)',
|
|
254
290
|
},
|
|
255
|
-
panelHead: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8 },
|
|
256
|
-
title: { fontSize: 13, fontWeight: 600 },
|
|
257
291
|
pre: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', margin: 0, fontFamily: 'var(--dsh-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)', fontSize: 11, lineHeight: 1.6 },
|
|
258
|
-
actions: {
|
|
292
|
+
actions: {
|
|
293
|
+
display: 'flex', gap: 8, marginTop: 14, paddingTop: 12, flexWrap: 'wrap',
|
|
294
|
+
borderTop: '1px solid var(--dsw-alias-border-l1, rgba(0,0,0,0.07))',
|
|
295
|
+
},
|
|
296
|
+
closeIcon: {
|
|
297
|
+
appearance: 'none', border: 0, background: 'transparent', cursor: 'pointer', marginLeft: 4,
|
|
298
|
+
width: 26, height: 26, borderRadius: 6, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
299
|
+
color: 'var(--dsw-alias-label-tertiary, #8b93a1)', fontSize: 14, lineHeight: 1,
|
|
300
|
+
},
|
|
259
301
|
button: {
|
|
260
302
|
padding: '4px 10px', borderRadius: 8, border: '1px solid rgba(255,255,255,0.2)',
|
|
261
303
|
background: 'rgba(255,255,255,0.08)', color: 'inherit', cursor: 'pointer', fontSize: 12,
|
|
@@ -417,6 +459,65 @@ window.__ModuleLoader__.load({
|
|
|
417
459
|
}, tr('crashAck')))
|
|
418
460
|
}
|
|
419
461
|
|
|
462
|
+
/** Split a rendered digest Markdown into titled blocks. */
|
|
463
|
+
function parseDigestBlocks(markdown) {
|
|
464
|
+
const out = []
|
|
465
|
+
let current = null
|
|
466
|
+
for (const raw of String(markdown ?? '').split('\n')) {
|
|
467
|
+
const line = raw.trimEnd()
|
|
468
|
+
if (line.startsWith('#')) {
|
|
469
|
+
const heading = line.replace(/^#+\s*/, '').trim()
|
|
470
|
+
if (!heading) continue
|
|
471
|
+
current = { heading, body: [] }
|
|
472
|
+
out.push(current)
|
|
473
|
+
continue
|
|
474
|
+
}
|
|
475
|
+
if (current) current.body.push(line)
|
|
476
|
+
}
|
|
477
|
+
return out
|
|
478
|
+
.map(block => ({ heading: block.heading, body: block.body.join('\n').trim() }))
|
|
479
|
+
.filter(block => block.body !== '' || /^(卷末|Colophon)/i.test(block.heading) === false)
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** Render one digest block: paragraphs plus a numbered list for bullet lines. */
|
|
483
|
+
function renderDigestBlock(block, key) {
|
|
484
|
+
const nodes = []
|
|
485
|
+
let paragraphs = []
|
|
486
|
+
let items = []
|
|
487
|
+
const flushParagraph = () => {
|
|
488
|
+
if (paragraphs.length > 0) {
|
|
489
|
+
nodes.push(h('p', { key: `p${nodes.length}`, style: styles.digestPara }, paragraphs.join('\n')))
|
|
490
|
+
paragraphs = []
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const flushItems = () => {
|
|
494
|
+
if (items.length > 0) {
|
|
495
|
+
nodes.push(h('ol', { key: `l${nodes.length}`, style: styles.digestList },
|
|
496
|
+
items.map((item, index) => h('li', { key: index, style: styles.digestItem }, item))))
|
|
497
|
+
items = []
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
for (const raw of block.body.split('\n')) {
|
|
501
|
+
const line = raw.trim()
|
|
502
|
+
const bullet = line.match(/^[-*•]\s+(.*)$/)
|
|
503
|
+
if (bullet) {
|
|
504
|
+
flushParagraph()
|
|
505
|
+
items.push(bullet[1])
|
|
506
|
+
} else if (line === '') {
|
|
507
|
+
flushParagraph()
|
|
508
|
+
flushItems()
|
|
509
|
+
} else {
|
|
510
|
+
flushItems()
|
|
511
|
+
paragraphs.push(line)
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
flushItems()
|
|
515
|
+
flushParagraph()
|
|
516
|
+
return h('div', { key, style: styles.digestBlock },
|
|
517
|
+
h('div', { style: styles.digestTitle }, h('span', { style: styles.digestTitleBar }), block.heading),
|
|
518
|
+
nodes)
|
|
519
|
+
}
|
|
520
|
+
|
|
420
521
|
/** The chip + floating digest panel above the composer. */
|
|
421
522
|
function ColophonDock(props) {
|
|
422
523
|
const sessionId = props.sessionId
|
|
@@ -483,24 +584,31 @@ window.__ModuleLoader__.load({
|
|
|
483
584
|
if (variant === 'hero' || !sessionId) return null
|
|
484
585
|
|
|
485
586
|
const chip = h('button', {
|
|
486
|
-
style: styles.chip,
|
|
587
|
+
style: digest ? { ...styles.chip, ...styles.chipOn } : styles.chip,
|
|
487
588
|
title: tr('panelTitle'),
|
|
488
589
|
onClick: () => setOpen(current => !current),
|
|
489
590
|
},
|
|
490
591
|
h('span', { style: digest ? styles.dot : styles.dotEmpty }),
|
|
491
592
|
h('span', null, digest ? tr('chipReady') : tr('chipEmpty')))
|
|
492
593
|
|
|
594
|
+
const blocks = digest?.markdown ? parseDigestBlocks(digest.markdown) : []
|
|
595
|
+
|
|
493
596
|
const panel = open ? h('div', { style: styles.panel, role: 'dialog', 'aria-label': tr('panelTitle') },
|
|
494
597
|
h('div', { style: styles.panelHead },
|
|
495
598
|
h('span', { style: styles.title }, tr('panelTitle')),
|
|
496
|
-
h('span', { style: styles.muted }, digest?.updatedAt ? new Date(digest.updatedAt).toLocaleString() : '')
|
|
599
|
+
h('span', { style: { ...styles.muted, marginRight: 'auto' } }, digest?.updatedAt ? new Date(digest.updatedAt).toLocaleString() : ''),
|
|
600
|
+
h('button', { style: { ...styles.buttonPrimary, minWidth: 92, height: 30 }, onClick: () => void generate(), disabled: loading },
|
|
601
|
+
digest ? tr('regenerate') : tr('generate')),
|
|
602
|
+
h('button', {
|
|
603
|
+
style: styles.closeIcon, title: tr('close'), 'aria-label': tr('close'),
|
|
604
|
+
onClick: () => setOpen(false),
|
|
605
|
+
}, '✕')),
|
|
497
606
|
loading ? h('div', { style: styles.muted }, tr('loading'))
|
|
498
607
|
: error ? h('div', { style: styles.warn }, tr('failed', { message: error }))
|
|
499
|
-
:
|
|
608
|
+
: blocks.length > 0
|
|
609
|
+
? h('div', null, blocks.map((block, index) => renderDigestBlock(block, index)))
|
|
500
610
|
: h('div', { style: styles.muted }, tr('empty')),
|
|
501
611
|
h('div', { style: styles.actions },
|
|
502
|
-
h('button', { style: styles.buttonPrimary, onClick: () => void generate(), disabled: loading },
|
|
503
|
-
digest ? tr('regenerate') : tr('generate')),
|
|
504
612
|
digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void copy() }, copied ? tr('copied') : tr('copy')) : null,
|
|
505
613
|
digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void download() }, tr('download')) : null,
|
|
506
614
|
h('button', { style: styles.buttonSecondary, onClick: () => setOpen(false) }, tr('close')))) : null
|
|
@@ -733,6 +841,19 @@ window.__ModuleLoader__.load({
|
|
|
733
841
|
h('span', { style: { ...ui.pillDot, background: 'currentColor', opacity: on || count ? 1 : 0.6 } }),
|
|
734
842
|
count ? onText : on ? onText : offText)
|
|
735
843
|
}
|
|
844
|
+
/** Digest blocks the user can include, in presentation order. */
|
|
845
|
+
const SECTION_META = [
|
|
846
|
+
['goal', 'secGoal', 'secGoalHint'],
|
|
847
|
+
['conclusion', 'secConclusion', 'secConclusionHint'],
|
|
848
|
+
['decisions', 'secDecisions', 'secDecisionsHint'],
|
|
849
|
+
['files', 'secFiles', 'secFilesHint'],
|
|
850
|
+
['progress', 'secProgress', 'secProgressHint'],
|
|
851
|
+
['nextSteps', 'secNextSteps', 'secNextStepsHint'],
|
|
852
|
+
['risks', 'secRisks', 'secRisksHint'],
|
|
853
|
+
['keywords', 'secKeywords', 'secKeywordsHint'],
|
|
854
|
+
['questions', 'secQuestions', 'secQuestionsHint'],
|
|
855
|
+
]
|
|
856
|
+
|
|
736
857
|
/** Settings page: native DSH layout (rows + hairlines) and token colors. */
|
|
737
858
|
function ColophonSettings() {
|
|
738
859
|
const [form, setForm] = useState(null)
|
|
@@ -770,6 +891,16 @@ window.__ModuleLoader__.load({
|
|
|
770
891
|
setMessage('')
|
|
771
892
|
}
|
|
772
893
|
|
|
894
|
+
const toggleSection = (id) => {
|
|
895
|
+
setForm(current => {
|
|
896
|
+
if (!current) return current
|
|
897
|
+
const list = Array.isArray(current.sections) ? current.sections : []
|
|
898
|
+
const next = list.includes(id) ? list.filter(item => item !== id) : [...list, id]
|
|
899
|
+
return { ...current, sections: next }
|
|
900
|
+
})
|
|
901
|
+
setMessage('')
|
|
902
|
+
}
|
|
903
|
+
|
|
773
904
|
const save = async () => {
|
|
774
905
|
if (!form) return
|
|
775
906
|
setSaving(true)
|
|
@@ -777,6 +908,7 @@ window.__ModuleLoader__.load({
|
|
|
777
908
|
try {
|
|
778
909
|
const patch = {
|
|
779
910
|
enabled: form.enabled, engine: form.engine,
|
|
911
|
+
sections: form.sections,
|
|
780
912
|
api: form.api, triggers: form.triggers, filter: form.filter,
|
|
781
913
|
}
|
|
782
914
|
const value = await callHost('config', { method: 'POST', body: { patch } })
|
|
@@ -853,6 +985,18 @@ window.__ModuleLoader__.load({
|
|
|
853
985
|
],
|
|
854
986
|
})))),
|
|
855
987
|
|
|
988
|
+
h(Group, { title: tr('sectionsTitle'), meta: `${(form.sections ?? []).length}/${SECTION_META.length}` },
|
|
989
|
+
h('div', { style: { paddingBottom: 4 } },
|
|
990
|
+
h('div', null,
|
|
991
|
+
SECTION_META.map(([id, labelKey, hintKey], index) => h(SwitchRow, {
|
|
992
|
+
key: id,
|
|
993
|
+
label: tr(labelKey),
|
|
994
|
+
hint: tr(hintKey),
|
|
995
|
+
checked: (form.sections ?? []).includes(id),
|
|
996
|
+
last: index === SECTION_META.length - 1,
|
|
997
|
+
onChange: () => toggleSection(id),
|
|
998
|
+
}))))),
|
|
999
|
+
|
|
856
1000
|
h(Group, { title: tr('triggers') },
|
|
857
1001
|
h(SwitchRow, {
|
|
858
1002
|
label: tr('onIdle'), hint: tr('onIdleHint'), checked: form.triggers.onIdle === true,
|
package/index.js
CHANGED
|
@@ -42,9 +42,11 @@ export const Config = Schema.object({
|
|
|
42
42
|
closeBatch: Schema.boolean().default(false),
|
|
43
43
|
closeBatchMaxSessions: Schema.number().default(10),
|
|
44
44
|
}),
|
|
45
|
+
/** Blocks shown in the digest, in the order the settings page lists them. */
|
|
46
|
+
sections: Schema.array(Schema.string()).default(['goal', 'conclusion', 'decisions', 'nextSteps', 'risks']),
|
|
45
47
|
filter: Schema.object({
|
|
46
|
-
minMessages: Schema.number().default(
|
|
47
|
-
minTokens: Schema.number().default(
|
|
48
|
+
minMessages: Schema.number().default(2),
|
|
49
|
+
minTokens: Schema.number().default(100),
|
|
48
50
|
maxAgeDays: Schema.number().default(30),
|
|
49
51
|
sessionTypes: Schema.array(Schema.string()).default(['root']),
|
|
50
52
|
}),
|
package/lib/api.js
CHANGED
|
@@ -9,6 +9,19 @@ import { bullets, clip, estimateTokens, lastParagraph, redactSecrets, section, w
|
|
|
9
9
|
import { costCNY } from './usage.js'
|
|
10
10
|
import { renderDigest } from './digest.js'
|
|
11
11
|
|
|
12
|
+
/** Per-block instructions; only the user-selected blocks are requested. */
|
|
13
|
+
export const SECTION_PROMPTS = {
|
|
14
|
+
goal: ['## 目标', '一段话,说明用户最终想要什么。'],
|
|
15
|
+
conclusion: ['## 结论', '一段话,说明现在处于什么状态、结论是什么;没有结论就写“尚无结论”。'],
|
|
16
|
+
decisions: ['## 决策', '- 条目列表(最多 4 条),列出关键决定及一句话理由;没有就省略该小节。'],
|
|
17
|
+
files: ['## 涉及文件', '- 条目列表(最多 8 条),列出被修改的文件路径;没有就省略该小节。'],
|
|
18
|
+
progress: ['## 完成情况', '- 条目列表(最多 8 条),只列已确认完成的事。'],
|
|
19
|
+
nextSteps: ['## 下一步', '- 条目列表(最多 5 条),来自未完成项;没有就省略该小节。'],
|
|
20
|
+
risks: ['## 风险与注意', '- 条目列表(最多 4 条),来自报错、限制、未验证的假设;没有就省略该小节。'],
|
|
21
|
+
keywords: ['## 关键词', '- 3 到 6 个短词,便于检索;没有就省略该小节。'],
|
|
22
|
+
questions: ['## 待确认问题', '- 条目列表(最多 4 条),列出仍需用户确认的问题;没有就省略该小节。'],
|
|
23
|
+
}
|
|
24
|
+
|
|
12
25
|
/** Instruction sent to the summarizer. Short by design: the tail carries the facts. */
|
|
13
26
|
export const API_PROMPT = [
|
|
14
27
|
'你是「卷末」撰写器:为一个即将结束的编码会话写一份最终交接摘要。',
|
|
@@ -29,6 +42,23 @@ export const API_PROMPT = [
|
|
|
29
42
|
'保持中文、简洁、可执行;不要复述整段对话。',
|
|
30
43
|
].join('\n')
|
|
31
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Build the instruction for the blocks the user enabled.
|
|
47
|
+
* @param {string[]} [sections] enabled block ids.
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
export function buildApiPrompt(sections) {
|
|
51
|
+
const ids = Array.isArray(sections) && sections.length > 0 ? sections.filter(id => SECTION_PROMPTS[id]) : ['goal', 'conclusion', 'decisions', 'nextSteps', 'risks']
|
|
52
|
+
const lines = [
|
|
53
|
+
'你是「卷末」撰写器:为一个即将结束的编码会话写一份最终交接摘要。',
|
|
54
|
+
'只依据用户消息、最后一条助手回复和工具足迹,不要编造未发生的事。',
|
|
55
|
+
'输出严格使用以下小节(不要输出未列出的小节,也不要在小节前加任何前言):',
|
|
56
|
+
]
|
|
57
|
+
for (const id of ids) lines.push(...SECTION_PROMPTS[id])
|
|
58
|
+
lines.push('保持中文、简洁、可执行;不要复述整段对话。')
|
|
59
|
+
return lines.join('\n')
|
|
60
|
+
}
|
|
61
|
+
|
|
32
62
|
/**
|
|
33
63
|
* Compose the summarizer messages for one checkpoint.
|
|
34
64
|
* @param {ReturnType<import('./collect.js').SessionTail['snapshot']>} checkpoint session tail.
|
|
@@ -63,12 +93,13 @@ export function buildApiMessages(checkpoint, config) {
|
|
|
63
93
|
parts.push(`工具错误:\n${errors.slice(0, 6).map(error => `- ${clip(error?.name ?? 'tool', 60)}${error?.reason ? `:${clip(error.reason, 120)}` : ''}`).join('\n')}`)
|
|
64
94
|
}
|
|
65
95
|
const userText = parts.join('\n\n')
|
|
96
|
+
const system = buildApiPrompt(Array.isArray(config?.sections) ? config.sections : undefined)
|
|
66
97
|
const messages = [
|
|
67
|
-
{ role: /** @type {const} */ ('system'), content:
|
|
98
|
+
{ role: /** @type {const} */ ('system'), content: system },
|
|
68
99
|
{ role: /** @type {const} */ ('user'), content: userText },
|
|
69
100
|
]
|
|
70
|
-
const inputTokens = estimateTokens(
|
|
71
|
-
return { system
|
|
101
|
+
const inputTokens = estimateTokens(system) + estimateTokens(userText)
|
|
102
|
+
return { system, messages, inputTokens, userText }
|
|
72
103
|
}
|
|
73
104
|
|
|
74
105
|
/**
|
|
@@ -121,6 +152,11 @@ export function parseApiDigest(text, checkpoint, meta = {}) {
|
|
|
121
152
|
}
|
|
122
153
|
}
|
|
123
154
|
}
|
|
155
|
+
const keywords = toList(fromJson?.keywords, 6, 40)
|
|
156
|
+
if (keywords.length === 0) keywords.push(...bullets(reply, /(关键词|keywords)/iu, 6, 40))
|
|
157
|
+
const questions = toList(fromJson?.questions, 4, 140)
|
|
158
|
+
if (questions.length === 0) questions.push(...bullets(reply, /(待确认|问题|questions)/iu, 4, 140))
|
|
159
|
+
const sections = Array.isArray(meta.sections) && meta.sections.length > 0 ? meta.sections : ['goal', 'conclusion', 'decisions', 'nextSteps', 'risks']
|
|
124
160
|
const usage = meta.usage ?? {}
|
|
125
161
|
const digest = {
|
|
126
162
|
v: 1,
|
|
@@ -141,6 +177,9 @@ export function parseApiDigest(text, checkpoint, meta = {}) {
|
|
|
141
177
|
done,
|
|
142
178
|
nextSteps,
|
|
143
179
|
risks,
|
|
180
|
+
keywords,
|
|
181
|
+
questions,
|
|
182
|
+
sections,
|
|
144
183
|
tokens: {
|
|
145
184
|
input: Number(usage.inputTokens) || 0,
|
|
146
185
|
output: Number(usage.outputTokens) || 0,
|
package/lib/app.js
CHANGED
|
@@ -9,7 +9,7 @@ import { ensureDir } from './files.js'
|
|
|
9
9
|
import { dataRoot } from './files.js'
|
|
10
10
|
import { Collector, SessionTail } from './collect.js'
|
|
11
11
|
import { buildApiMessages, estimateCost, parseApiDigest } from './api.js'
|
|
12
|
-
import { RULES_VERSION, buildDigest, shouldSummarize } from './digest.js'
|
|
12
|
+
import { DEFAULT_SECTIONS, RULES_VERSION, SECTION_IDS, buildDigest, shouldSummarize } from './digest.js'
|
|
13
13
|
import { Store } from './store.js'
|
|
14
14
|
import { UsageLedger, costCNY } from './usage.js'
|
|
15
15
|
import { estimateTokens } from './text.js'
|
|
@@ -99,6 +99,10 @@ export function sanitizeSettings(patch) {
|
|
|
99
99
|
if (max !== undefined) triggers.closeBatchMaxSessions = Math.max(1, Math.min(50, Math.round(max)))
|
|
100
100
|
if (Object.keys(triggers).length > 0) out.triggers = triggers
|
|
101
101
|
}
|
|
102
|
+
if (Array.isArray(patch.sections)) {
|
|
103
|
+
const sections = [...new Set(patch.sections.filter(id => typeof id === 'string' && SECTION_IDS.includes(id)))]
|
|
104
|
+
out.sections = sections.length > 0 ? sections : [...DEFAULT_SECTIONS]
|
|
105
|
+
}
|
|
102
106
|
if (patch.filter && typeof patch.filter === 'object') {
|
|
103
107
|
const filter = {}
|
|
104
108
|
for (const key of ['minMessages', 'minTokens', 'maxAgeDays']) {
|
|
@@ -292,7 +296,7 @@ export function install(ctx, rawConfig) {
|
|
|
292
296
|
const checkpoint = tail.snapshot()
|
|
293
297
|
if (!shouldSummarize(checkpoint, config.filter).ok) { recovery.skipped += 1; continue }
|
|
294
298
|
await store.saveCheckpoint(checkpoint)
|
|
295
|
-
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now() }))
|
|
299
|
+
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now(), sections: config.sections }))
|
|
296
300
|
recovery.created += 1
|
|
297
301
|
log(`recovered digest for ${sessionId}`)
|
|
298
302
|
} catch (error) {
|
|
@@ -320,7 +324,7 @@ export function install(ctx, rawConfig) {
|
|
|
320
324
|
const digest = await tryApiDigest(sessionId, checkpoint, trigger)
|
|
321
325
|
if (digest) return digest
|
|
322
326
|
}
|
|
323
|
-
const digest = buildDigest(checkpoint, { engine: 'rules', now: Date.now() })
|
|
327
|
+
const digest = buildDigest(checkpoint, { engine: 'rules', now: Date.now(), sections: config.sections })
|
|
324
328
|
await store.saveDigest(digest)
|
|
325
329
|
return digest
|
|
326
330
|
}
|
|
@@ -388,7 +392,7 @@ export function install(ctx, rawConfig) {
|
|
|
388
392
|
} catch (error) {
|
|
389
393
|
warn(`usage record failed for ${sessionId}: ${String(error)}`)
|
|
390
394
|
}
|
|
391
|
-
const digest = parseApiDigest(text, checkpoint, { model: api.model, usage: real, now: Date.now() })
|
|
395
|
+
const digest = parseApiDigest(text, checkpoint, { model: api.model, usage: real, now: Date.now(), sections: config.sections })
|
|
392
396
|
await store.saveDigest(digest)
|
|
393
397
|
store.dequeueJob(sessionId)
|
|
394
398
|
await store.persist()
|
|
@@ -442,7 +446,7 @@ export function install(ctx, rawConfig) {
|
|
|
442
446
|
continue
|
|
443
447
|
}
|
|
444
448
|
if (config.engine !== 'api') {
|
|
445
|
-
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now() }))
|
|
449
|
+
await store.saveDigest(buildDigest(checkpoint, { engine: 'rules', now: Date.now(), sections: config.sections }))
|
|
446
450
|
store.dequeueJob(sessionId)
|
|
447
451
|
await store.persist()
|
|
448
452
|
results.push({ sessionId, ok: true, engine: 'rules' })
|
package/lib/digest.js
CHANGED
|
@@ -7,10 +7,18 @@
|
|
|
7
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 =
|
|
10
|
+
export const RULES_VERSION = 4
|
|
11
11
|
|
|
12
12
|
/** Defaults for the length filter (also mirrored in the Config schema). */
|
|
13
|
-
export const FILTER_DEFAULTS = Object.freeze({ minMessages:
|
|
13
|
+
export const FILTER_DEFAULTS = Object.freeze({ minMessages: 2, minTokens: 100 })
|
|
14
|
+
|
|
15
|
+
/** Every block a digest can contain; the settings page lets users pick. */
|
|
16
|
+
export const SECTION_IDS = Object.freeze(['goal', 'conclusion', 'decisions', 'files', 'progress', 'nextSteps', 'risks', 'keywords', 'questions'])
|
|
17
|
+
|
|
18
|
+
/** Blocks shown when the user has not chosen anything (no intermediate actions). */
|
|
19
|
+
export const DEFAULT_SECTIONS = Object.freeze(['goal', 'conclusion', 'decisions', 'nextSteps', 'risks'])
|
|
20
|
+
|
|
21
|
+
const STOPWORDS = new Set(['这个', '那个', '我们', '你们', '他们', '可以', '需要', '现在', '就是', '因为', '所以', '如果', '然后', '并且', '或者', '一个', '没有', '已经', '还是', '这样', '那样', '这里', '那里', '什么', '怎么', '如何', 'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'will', 'should', 'would', 'could'])
|
|
14
22
|
|
|
15
23
|
const CONCLUSION_HEADING = /(结论|总结|完成情况|conclusion|summary|outcome)/iu
|
|
16
24
|
const NEXT_HEADING = /(下一步|后续|待办|next step|next steps|todo|follow[- ]?up)/iu
|
|
@@ -141,6 +149,20 @@ export function buildDigest(checkpoint, options = {}) {
|
|
|
141
149
|
const goal = redactSecrets(typeof checkpoint.goal === 'string' && checkpoint.goal !== '' ? checkpoint.goal : '(未捕捉到目标)')
|
|
142
150
|
const conclusion = conclusionOf(assistantText) || (checkpoint.messageCount === 0 ? '(空会话)' : '(本次对话没有留下文字结论)')
|
|
143
151
|
|
|
152
|
+
const keywords = extractKeywords(`${checkpoint.title ?? ''} ${goal} ${conclusion}`)
|
|
153
|
+
const questions = []
|
|
154
|
+
for (const line of assistantText.split('\n')) {
|
|
155
|
+
const item = line.replace(/^[#>*\-\s`]+/u, '').trim()
|
|
156
|
+
if (item === '' || item.length > 160) continue
|
|
157
|
+
if (!/[??]|是否|要不要|待确认/u.test(item)) continue
|
|
158
|
+
const question = clip(redactSecrets(item), 140)
|
|
159
|
+
if (!questions.includes(question)) questions.push(question)
|
|
160
|
+
if (questions.length >= 4) break
|
|
161
|
+
}
|
|
162
|
+
const sections = Array.isArray(options.sections) && options.sections.length > 0
|
|
163
|
+
? options.sections.filter(id => SECTION_IDS.includes(id))
|
|
164
|
+
: [...DEFAULT_SECTIONS]
|
|
165
|
+
|
|
144
166
|
const digest = {
|
|
145
167
|
v: 1,
|
|
146
168
|
rulesVersion: RULES_VERSION,
|
|
@@ -161,66 +183,75 @@ export function buildDigest(checkpoint, options = {}) {
|
|
|
161
183
|
done,
|
|
162
184
|
nextSteps,
|
|
163
185
|
risks,
|
|
186
|
+
keywords,
|
|
187
|
+
questions,
|
|
188
|
+
sections,
|
|
164
189
|
params: { minMessages: FILTER_DEFAULTS.minMessages, minTokens: FILTER_DEFAULTS.minTokens },
|
|
165
190
|
}
|
|
166
191
|
digest.markdown = renderDigest(digest)
|
|
167
192
|
return digest
|
|
168
193
|
}
|
|
169
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Pick up to six salient terms for the keyword block.
|
|
197
|
+
* @param {string} text combined title/goal/conclusion.
|
|
198
|
+
* @returns {string[]}
|
|
199
|
+
*/
|
|
200
|
+
export function extractKeywords(text) {
|
|
201
|
+
const seen = new Set()
|
|
202
|
+
const out = []
|
|
203
|
+
for (const raw of String(text ?? '').split(/[^\p{L}\p{N}_\-+.]+/u)) {
|
|
204
|
+
const token = raw.trim()
|
|
205
|
+
if (token.length < 2 || token.length > 32) continue
|
|
206
|
+
const key = token.toLowerCase()
|
|
207
|
+
if (STOPWORDS.has(key) || seen.has(key)) continue
|
|
208
|
+
seen.add(key)
|
|
209
|
+
out.push(token)
|
|
210
|
+
if (out.length >= 6) break
|
|
211
|
+
}
|
|
212
|
+
return out
|
|
213
|
+
}
|
|
214
|
+
|
|
170
215
|
/**
|
|
171
216
|
* Render a digest as the Markdown block a user reads (and can paste).
|
|
217
|
+
* Only the sections selected in the config are rendered; intermediate tool
|
|
218
|
+
* actions are never part of the default set.
|
|
172
219
|
* @param {object} digest a digest record.
|
|
173
220
|
* @returns {string}
|
|
174
221
|
*/
|
|
175
222
|
export function renderDigest(digest) {
|
|
223
|
+
const enabled = Array.isArray(digest.sections) && digest.sections.length > 0
|
|
224
|
+
? digest.sections.filter(id => SECTION_IDS.includes(id))
|
|
225
|
+
: [...DEFAULT_SECTIONS]
|
|
226
|
+
const has = id => enabled.includes(id)
|
|
176
227
|
const lines = []
|
|
177
228
|
lines.push(`# 卷末 · ${digest.title ?? digest.sessionId}`)
|
|
178
229
|
lines.push('')
|
|
179
|
-
const meta = [
|
|
180
|
-
`会话 \`${digest.sessionId}\``,
|
|
181
|
-
`引擎 ${digest.engine}`,
|
|
182
|
-
`更新 ${new Date(digest.updatedAt).toISOString().replace('T', ' ').slice(0, 19)}`,
|
|
183
|
-
]
|
|
230
|
+
const meta = [digest.engine === 'api' ? 'API 摘要' : '本地规则', `更新 ${new Date(digest.updatedAt).toISOString().replace('T', ' ').slice(0, 16)}`]
|
|
184
231
|
if (digest.messageCount) meta.push(`${digest.messageCount} 条消息`)
|
|
185
232
|
lines.push(`> ${meta.join(' · ')}`)
|
|
186
233
|
lines.push('')
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
lines.push('## 结论')
|
|
192
|
-
lines.push('')
|
|
193
|
-
lines.push(digest.conclusion)
|
|
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) {
|
|
207
|
-
lines.push('')
|
|
208
|
-
lines.push('## 已完成')
|
|
209
|
-
lines.push('')
|
|
210
|
-
for (const item of digest.done) lines.push(`- ${item}`)
|
|
211
|
-
}
|
|
212
|
-
if (digest.nextSteps.length > 0) {
|
|
213
|
-
lines.push('')
|
|
214
|
-
lines.push('## 下一步')
|
|
215
|
-
lines.push('')
|
|
216
|
-
for (const item of digest.nextSteps) lines.push(`- ${item}`)
|
|
217
|
-
}
|
|
218
|
-
if (digest.risks.length > 0) {
|
|
234
|
+
|
|
235
|
+
const block = (heading, body) => {
|
|
236
|
+
if (body === '' || body === undefined || body === null) return
|
|
237
|
+
lines.push(`## ${heading}`)
|
|
219
238
|
lines.push('')
|
|
220
|
-
|
|
239
|
+
if (Array.isArray(body)) {
|
|
240
|
+
for (const item of body) lines.push(`- ${item}`)
|
|
241
|
+
} else {
|
|
242
|
+
lines.push(body)
|
|
243
|
+
}
|
|
221
244
|
lines.push('')
|
|
222
|
-
for (const item of digest.risks) lines.push(`- ${item}`)
|
|
223
245
|
}
|
|
224
|
-
|
|
246
|
+
|
|
247
|
+
if (has('goal')) block('目标', digest.goal)
|
|
248
|
+
if (has('conclusion')) block('结论', digest.conclusion)
|
|
249
|
+
if (has('decisions')) block('决策', Array.isArray(digest.decisions) && digest.decisions.length > 0 ? digest.decisions : '')
|
|
250
|
+
if (has('files')) block('涉及文件', Array.isArray(digest.writes) && digest.writes.length > 0 ? digest.writes : '')
|
|
251
|
+
if (has('progress')) block('完成情况', Array.isArray(digest.done) && digest.done.length > 0 ? digest.done : '')
|
|
252
|
+
if (has('nextSteps')) block('下一步', Array.isArray(digest.nextSteps) && digest.nextSteps.length > 0 ? digest.nextSteps : '')
|
|
253
|
+
if (has('risks')) block('风险与注意', Array.isArray(digest.risks) && digest.risks.length > 0 ? digest.risks : '')
|
|
254
|
+
if (has('keywords')) block('关键词', Array.isArray(digest.keywords) && digest.keywords.length > 0 ? digest.keywords : '')
|
|
255
|
+
if (has('questions')) block('待确认问题', Array.isArray(digest.questions) && digest.questions.length > 0 ? digest.questions : '')
|
|
225
256
|
return `${lines.join('\n')}\n`
|
|
226
257
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-colophon",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
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",
|