dsh-colophon 0.2.0 → 0.2.2

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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/client.js +444 -114
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -103,6 +103,13 @@ usage.jsonl API 调用账本(rules 引擎不写)
103
103
  - 摘要面板新增「下载 Markdown」按钮(直接保存为 `.md` 文件)
104
104
  - 版本号 0.2.0;测试 38 项全绿
105
105
 
106
+ ## 0.2.1(设置界面可读性)
107
+
108
+ - 设置页重做:渐变标题卡 + 状态胶囊、强调条卡片、整行可点的开关(带滑动圆钮)、蓝底主按钮「保存修改」、描边次按钮「处理队列」/「查询」
109
+ - 所有可点击元素都有明确的按钮形态与悬停反馈,队列为空时「处理队列」自动置灰
110
+ - 触发时机、API 预算、用量区间(时/日/周/月/自定义)分组更清晰,警告文案用琥珀色提示条
111
+ - 版本号 0.2.1;截图更新至 `docs/screenshots/settings.png`
112
+
106
113
  ## 已实现(P2 · 客户端)
107
114
 
108
115
  - 输入框上方「卷末」胶囊:点击展开摘要面板(Markdown 预览、复制、重新生成)
package/client.js CHANGED
@@ -37,11 +37,13 @@ window.__ModuleLoader__.load({
37
37
  failed: '读取失败:{message}',
38
38
  crash: '上次 DSH 没有正常退出,卷末已在本地恢复(0 token)。',
39
39
  crashAck: '知道了',
40
- settingsLabel: '卷末 · Colophon',
40
+ settingsLabel: '卷末 Colophon',
41
41
  settingsIntro: '规则引擎只读本地日志,不调用模型、不花 token;API 摘要为可选项。',
42
42
  engine: '摘要引擎',
43
- engineRules: '本地规则(0 token)',
44
- engineApi: 'API 摘要(可选的增强)',
43
+ engineRules: '本地规则',
44
+ engineRulesHint: '0 token · 本地生成',
45
+ engineApi: 'API 摘要',
46
+ engineApiHint: '按次调用模型',
45
47
  enabled: '启用卷末',
46
48
  triggers: '触发时机',
47
49
  onIdle: '会话空闲时',
@@ -85,6 +87,34 @@ window.__ModuleLoader__.load({
85
87
  queueRun: '队列已处理',
86
88
  apiUnavailable: '当前环境没有可用的模型服务(llm):API 引擎会回退到本地 rules 摘要,并把它放进待确认队列。',
87
89
  statusFailed: '状态读取失败',
90
+ basicTitle: '基本设置',
91
+ statusOn: '已启用',
92
+ statusOff: '已暂停',
93
+ settingsSubtitle: '把每次对话的最终结论留在本地;重开会话时先看结论,不必重读整段历史。',
94
+ saveHint: '保存后立即生效,无需重启。',
95
+ note: '注意',
96
+ unitSessions: '个会话',
97
+ unitMessages: '条',
98
+ unitPrice: '元 / 百万 token',
99
+ perSummaryCapHint: '单次调用超过此金额则按右侧策略处理',
100
+ dailyBudgetHint: '每天累计消耗的上限',
101
+ overCapHint: '达到单次/每日上限后的动作',
102
+ minMessagesHint: '低于该消息数的会话不生成',
103
+ minTokensHint: '低于该 token 数的会话不生成',
104
+ queueReason: '原因:{reason}',
105
+ saving: '保存中…',
106
+ rangeEmptyHint: '可查询任意自定义区间;结束时间留空表示到当前时刻。',
107
+ enabledHint: '关闭后不再采集新会话;已有摘要仍可查看。',
108
+ engineHint: 'rules 完全本地,0 token;api 每次生成会调用模型,并受下方预算限制。',
109
+ onIdleHint: '智能体停止后几秒内写出摘要。',
110
+ onSwitchHint: '在另一个会话里开始输入时,先总结上一个会话。',
111
+ apiOn: '已开启',
112
+ apiOff: '未开启',
113
+ apply: '查询',
114
+ rangeInvalid: '时间范围无效(开始时间需早于结束时间)。',
115
+ customHint: '结束时间留空表示到当前时刻。',
116
+ queueHint: '这些会话在花费 token 前等待你确认。',
117
+ save: '保存修改',
88
118
  },
89
119
  en: {
90
120
  chip: 'Colophon',
@@ -105,8 +135,10 @@ window.__ModuleLoader__.load({
105
135
  settingsLabel: 'Colophon',
106
136
  settingsIntro: 'The rules engine only reads local logs — no model call, no token spend. API summaries are optional.',
107
137
  engine: 'Summary engine',
108
- engineRules: 'Local rules (0 tokens)',
109
- engineApi: 'API summary (optional)',
138
+ engineRules: 'Local rules',
139
+ engineRulesHint: '0 tokens · local',
140
+ engineApi: 'API summary',
141
+ engineApiHint: 'Calls a model per digest',
110
142
  enabled: 'Enable Colophon',
111
143
  triggers: 'Triggers',
112
144
  onIdle: 'When a session goes idle',
@@ -150,6 +182,34 @@ window.__ModuleLoader__.load({
150
182
  queueRun: 'Queue processed',
151
183
  apiUnavailable: 'No model service (llm) is available here: the API engine falls back to local rules digests and queues the session for confirmation.',
152
184
  statusFailed: 'Status unavailable',
185
+ basicTitle: 'Basics',
186
+ statusOn: 'Enabled',
187
+ statusOff: 'Paused',
188
+ settingsSubtitle: 'Keep every conversation’s final conclusion locally. Reopen a session and read the conclusion first — no need to replay the whole history.',
189
+ saveHint: 'Changes take effect immediately after saving.',
190
+ note: 'Note',
191
+ unitSessions: 'sessions',
192
+ unitMessages: 'messages',
193
+ unitPrice: 'CNY / 1M tokens',
194
+ perSummaryCapHint: 'Above this per-call cost, the policy on the right applies',
195
+ dailyBudgetHint: 'Daily token ceiling',
196
+ overCapHint: 'What to do after hitting a cap',
197
+ minMessagesHint: 'Sessions below this are skipped',
198
+ minTokensHint: 'Sessions below this are skipped',
199
+ queueReason: 'Reason: {reason}',
200
+ saving: 'Saving…',
201
+ rangeEmptyHint: 'Any custom range; leave the end empty to use now.',
202
+ enabledHint: 'When off, new sessions are no longer captured; existing digests stay readable.',
203
+ engineHint: 'Local rules cost 0 tokens. The API engine calls a model per digest and is capped by the budgets below.',
204
+ onIdleHint: 'Write the digest a few seconds after the agent stops.',
205
+ onSwitchHint: 'Summarize the previous session when you start typing in another one.',
206
+ apiOn: 'On',
207
+ apiOff: 'Off',
208
+ apply: 'Apply',
209
+ rangeInvalid: 'Pick a valid time range (from ≤ to).',
210
+ customHint: 'Leave the end empty to use the current moment.',
211
+ queueHint: 'Sessions waiting for your confirmation before spending tokens.',
212
+ save: 'Save changes',
153
213
  },
154
214
  }
155
215
 
@@ -204,7 +264,7 @@ window.__ModuleLoader__.load({
204
264
  banner: {
205
265
  position: 'fixed', top: 12, left: '50%', transform: 'translateX(-50%)', zIndex: 70,
206
266
  display: 'flex', alignItems: 'center', gap: 10, padding: '8px 12px',
207
- background: 'rgba(84,64,16,0.98)', color: '#ffe9b0', border: '1px solid rgba(255,220,140,0.35)',
267
+ background: 'rgba(24,28,38,0.97)', color: '#dfe7f7', border: '1px solid rgba(109,151,255,0.4)',
208
268
  borderRadius: 10, fontSize: 12, boxShadow: '0 8px 24px rgba(0,0,0,0.35)',
209
269
  },
210
270
  field: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 120 },
@@ -222,6 +282,112 @@ window.__ModuleLoader__.load({
222
282
  cardValue: { fontSize: 15, fontWeight: 600, marginTop: 2 },
223
283
  warn: { color: '#ffd27a', fontSize: 11 },
224
284
  ok: { color: '#4cc38a', fontSize: 11 },
285
+
286
+ // ---- Design tokens: one palette + one spacing scale for every control ----
287
+ // text / muted / faint -> three text contrast levels
288
+ // accent -> the only "selected / action" color
289
+ // amber / green / red -> status only, always paired with an icon dot
290
+ page: { display: 'flex', flexDirection: 'column', gap: 12, fontSize: 13, maxWidth: 780, paddingBottom: 6, color: '#e9edf3', lineHeight: 1.55 },
291
+ headCard: {
292
+ display: 'flex', flexDirection: 'column', gap: 8, padding: '18px 18px 16px', borderRadius: 12,
293
+ border: '1px solid rgba(255,255,255,0.08)',
294
+ background: 'linear-gradient(135deg, rgba(109,151,255,0.18), rgba(109,151,255,0.03) 58%, rgba(255,255,255,0.015))',
295
+ },
296
+ headTitle: { fontSize: 17, fontWeight: 650, letterSpacing: '-0.01em' },
297
+ headSub: { fontSize: 12.5, lineHeight: 1.65, color: '#9aa4b5', maxWidth: 600 },
298
+ headMeta: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap', marginTop: 2 },
299
+ pill: { display: 'inline-flex', alignItems: 'center', gap: 6, height: 22, padding: '0 10px', borderRadius: 999, fontSize: 11.5, fontWeight: 600, whiteSpace: 'nowrap', border: '1px solid transparent' },
300
+ pillOn: { background: 'rgba(127,215,162,0.12)', color: '#7fd7a2', borderColor: 'rgba(127,215,162,0.32)' },
301
+ pillOff: { background: 'rgba(255,255,255,0.05)', color: '#9aa4b5', borderColor: 'rgba(255,255,255,0.12)' },
302
+ pillCount: { background: 'rgba(109,151,255,0.12)', color: '#9db9ff', borderColor: 'rgba(109,151,255,0.3)' },
303
+ pillDot: { width: 6, height: 6, borderRadius: 999, display: 'inline-block' },
304
+ card: { borderRadius: 12, border: '1px solid rgba(255,255,255,0.08)', background: 'rgba(255,255,255,0.026)', overflow: 'hidden' },
305
+ cardHead: { display: 'flex', alignItems: 'center', gap: 8, padding: '11px 14px', borderBottom: '1px solid rgba(255,255,255,0.07)' },
306
+ cardTitle: { display: 'inline-flex', alignItems: 'center', gap: 8, fontSize: 13, fontWeight: 600 },
307
+ accentBar: { width: 3, height: 12, borderRadius: 2, background: '#6d97ff', display: 'inline-block' },
308
+ cardMeta: { marginLeft: 'auto', fontSize: 11.5, color: '#76819a' },
309
+ row: { display: 'flex', alignItems: 'center', gap: 16, padding: '12px 14px', minHeight: 46, borderBottom: '1px solid rgba(255,255,255,0.07)', boxSizing: 'border-box' },
310
+ rowLast: { borderBottom: 'none' },
311
+ labelBlock: { display: 'flex', flexDirection: 'column', gap: 3, flex: '1 1 180px', minWidth: 0 },
312
+ label: { fontSize: 13, color: '#e9edf3' },
313
+ hint: { fontSize: 11.5, lineHeight: 1.6, color: '#9aa4b5' },
314
+ control: { display: 'flex', alignItems: 'center', gap: 8, flex: '0 0 auto', flexWrap: 'wrap', justifyContent: 'flex-end' },
315
+ input: {
316
+ height: 34, boxSizing: 'border-box', padding: '0 10px', borderRadius: 8,
317
+ border: '1px solid rgba(255,255,255,0.14)', background: 'rgba(0,0,0,0.28)',
318
+ color: '#e9edf3', fontSize: 12.5, outline: 'none',
319
+ },
320
+ inputNum: { width: 112, textAlign: 'right', fontVariantNumeric: 'tabular-nums' },
321
+ inputText: { width: 168 },
322
+ unit: { fontSize: 11.5, color: '#76819a', whiteSpace: 'nowrap' },
323
+ selectWrap: { position: 'relative', display: 'inline-flex', alignItems: 'center' },
324
+ select: {
325
+ appearance: 'none', WebkitAppearance: 'none', height: 34, boxSizing: 'border-box',
326
+ padding: '0 26px 0 10px', borderRadius: 8, border: '1px solid rgba(255,255,255,0.14)',
327
+ background: 'rgba(0,0,0,0.28)', color: '#e9edf3', fontSize: 12.5, cursor: 'pointer', outline: 'none',
328
+ },
329
+ chevron: { position: 'absolute', right: 10, pointerEvents: 'none', fontSize: 9, color: '#9aa4b5' },
330
+ segmented: { display: 'inline-flex', gap: 3, padding: 3, borderRadius: 9, background: 'rgba(0,0,0,0.25)', border: '1px solid rgba(255,255,255,0.1)' },
331
+ segItem: {
332
+ appearance: 'none', border: '1px solid transparent', background: 'transparent', color: '#9aa4b5',
333
+ borderRadius: 7, padding: '5px 11px', cursor: 'pointer', display: 'inline-flex', flexDirection: 'column',
334
+ alignItems: 'flex-start', gap: 1, minWidth: 108, textAlign: 'left',
335
+ },
336
+ segItemOn: { background: 'rgba(109,151,255,0.16)', borderColor: 'rgba(109,151,255,0.5)', color: '#bcd0ff' },
337
+ segTitle: { fontSize: 12.5, fontWeight: 550 },
338
+ segHint: { fontSize: 10.5, color: '#76819a' },
339
+ segHintOn: { color: 'rgba(188,208,255,0.75)' },
340
+ switchRow: {
341
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16,
342
+ padding: '12px 14px', minHeight: 52, borderBottom: '1px solid rgba(255,255,255,0.07)',
343
+ cursor: 'pointer', boxSizing: 'border-box', outline: 'none',
344
+ },
345
+ switchRowOn: { background: 'rgba(109,151,255,0.05)' },
346
+ switchTrack: {
347
+ position: 'relative', flex: '0 0 auto', width: 40, height: 23, borderRadius: 999,
348
+ background: 'rgba(255,255,255,0.16)', transition: 'background 140ms ease',
349
+ },
350
+ switchTrackOn: { background: '#5b8cff' },
351
+ switchKnob: {
352
+ position: 'absolute', top: 3, left: 3, width: 17, height: 17, borderRadius: 999,
353
+ background: '#fff', transition: 'transform 140ms ease', boxShadow: '0 1px 3px rgba(0,0,0,0.45)',
354
+ },
355
+ switchKnobOn: { transform: 'translateX(17px)' },
356
+ callout: { display: 'flex', gap: 8, alignItems: 'flex-start', margin: '10px 14px', padding: '9px 11px', borderRadius: 8, fontSize: 11.5, lineHeight: 1.6, border: '1px solid transparent' },
357
+ calloutInfo: { background: 'rgba(109,151,255,0.08)', borderColor: 'rgba(109,151,255,0.28)', color: '#c7d7ff' },
358
+ calloutWarn: { background: 'rgba(238,207,148,0.10)', borderColor: 'rgba(238,207,148,0.34)', color: '#eed7a6' },
359
+ calloutError: { background: 'rgba(255,130,130,0.10)', borderColor: 'rgba(255,130,130,0.30)', color: '#ffb3b3' },
360
+ calloutOk: { background: 'rgba(127,215,162,0.10)', borderColor: 'rgba(127,215,162,0.30)', color: '#8fe0b1' },
361
+ calloutDot: { width: 6, height: 6, borderRadius: 999, marginTop: 6, flex: '0 0 auto' },
362
+ calloutLabel: { fontWeight: 600, marginRight: 4 },
363
+ buttonPrimary: {
364
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 6, height: 36,
365
+ minWidth: 108, padding: '0 18px', borderRadius: 9, border: '1px solid #5b8cff',
366
+ background: '#4f7cff', color: '#fff', fontSize: 13, fontWeight: 650, cursor: 'pointer',
367
+ boxShadow: '0 2px 10px rgba(79,124,255,0.35)', boxSizing: 'border-box',
368
+ },
369
+ buttonSecondary: {
370
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 6, height: 34,
371
+ minWidth: 84, padding: '0 14px', borderRadius: 8, border: '1px solid rgba(255,255,255,0.2)',
372
+ background: 'rgba(255,255,255,0.045)', color: '#e9edf3', fontSize: 12.5, fontWeight: 550,
373
+ cursor: 'pointer', boxSizing: 'border-box',
374
+ },
375
+ buttonDisabled: { opacity: 0.4, cursor: 'not-allowed', boxShadow: 'none' },
376
+ actionsBar: { display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: 10, padding: '10px 14px' },
377
+ footer: {
378
+ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 14px', borderRadius: 10,
379
+ border: '1px solid rgba(255,255,255,0.08)', background: 'rgba(20,23,30,0.94)',
380
+ backdropFilter: 'blur(8px)', position: 'sticky', bottom: 0, zIndex: 2,
381
+ },
382
+ footerText: { flex: '1 1 auto', fontSize: 11.5, color: '#76819a', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
383
+ usageGrid: { display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 8, padding: '12px 14px 0' },
384
+ usageCard: { display: 'flex', flexDirection: 'column', gap: 2, padding: '11px 12px', borderRadius: 10, border: '1px solid rgba(255,255,255,0.07)', background: 'rgba(0,0,0,0.2)' },
385
+ usageLabel: { fontSize: 11, color: '#9aa4b5' },
386
+ usageValue: { fontSize: 18, fontWeight: 650, letterSpacing: '-0.01em', fontVariantNumeric: 'tabular-nums' },
387
+ usageMeta: { fontSize: 10.5, color: '#76819a' },
388
+ listRow: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', padding: '8px 10px', borderRadius: 8, background: 'rgba(0,0,0,0.2)', fontSize: 12 },
389
+ emptyBox: { margin: '12px 14px 4px', padding: '14px 12px', borderRadius: 9, border: '1px dashed rgba(255,255,255,0.16)', color: '#76819a', fontSize: 11.5, textAlign: 'center' },
390
+ grid2: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, padding: '12px 14px' },
225
391
  }
226
392
 
227
393
  /** Read/persist the crash banner acknowledgement. */
@@ -333,42 +499,127 @@ window.__ModuleLoader__.load({
333
499
  : digest?.markdown ? h('pre', { style: styles.pre }, digest.markdown)
334
500
  : h('div', { style: styles.muted }, tr('empty')),
335
501
  h('div', { style: styles.actions },
336
- h('button', { style: styles.button, onClick: () => void generate(), disabled: loading },
502
+ h('button', { style: styles.buttonPrimary, onClick: () => void generate(), disabled: loading },
337
503
  digest ? tr('regenerate') : tr('generate')),
338
- digest?.markdown ? h('button', { style: styles.button, onClick: () => void copy() }, copied ? tr('copied') : tr('copy')) : null,
339
- digest?.markdown ? h('button', { style: styles.button, onClick: () => void download() }, tr('download')) : null,
340
- h('button', { style: styles.button, onClick: () => setOpen(false) }, tr('close')))) : null
504
+ digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void copy() }, copied ? tr('copied') : tr('copy')) : null,
505
+ digest?.markdown ? h('button', { style: styles.buttonSecondary, onClick: () => void download() }, tr('download')) : null,
506
+ h('button', { style: styles.buttonSecondary, onClick: () => setOpen(false) }, tr('close')))) : null
341
507
 
342
508
  return h(React.Fragment, null, h(CrashBanner), h('div', null, chip), panel)
343
509
  }
344
510
 
345
- /** One labelled number input bound to a form field. */
346
- function NumberField({ label, value, onChange, step }) {
347
- return h('label', { style: styles.field },
511
+ /** A labelled row: text block on the left, control on the right. */
512
+ function Row({ children, last }) {
513
+ return h('div', { style: last ? { ...styles.row, ...styles.rowLast } : styles.row }, children)
514
+ }
515
+
516
+ function LabelBlock({ label, hint }) {
517
+ return h('div', { style: styles.labelBlock },
348
518
  h('span', { style: styles.label }, label),
349
- h('input', {
350
- style: styles.input,
351
- type: 'number',
352
- step: step ?? 1,
353
- value: value ?? '',
354
- onChange: event => onChange(Number(event.target.value)),
519
+ hint ? h('span', { style: styles.hint }, hint) : null)
520
+ }
521
+
522
+ /** One card section on the settings page: accent bar + title + optional meta. */
523
+ function Card({ title, meta, children }) {
524
+ return h('div', { style: styles.card },
525
+ h('div', { style: styles.cardHead },
526
+ h('div', { style: styles.cardTitle }, h('span', { style: styles.accentBar }), title),
527
+ meta ? h('span', { style: styles.cardMeta }, meta) : null),
528
+ children)
529
+ }
530
+
531
+ /** A full-row toggle: the whole row is the click target, the knob is obvious. */
532
+ function SwitchRow({ label, hint, checked, onChange, last }) {
533
+ const on = checked === true
534
+ const toggle = () => onChange(!on)
535
+ return h('div', {
536
+ role: 'switch',
537
+ 'aria-checked': on,
538
+ tabIndex: 0,
539
+ style: on ? { ...styles.switchRow, ...styles.switchRowOn, ...(last ? styles.rowLast : null) } : { ...styles.switchRow, ...(last ? styles.rowLast : null) },
540
+ onClick: toggle,
541
+ onKeyDown: event => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); toggle() } },
542
+ },
543
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0 } },
544
+ h('span', { style: styles.label }, label),
545
+ hint ? h('span', { style: styles.hint }, hint) : null),
546
+ h('div', { style: on ? { ...styles.switchTrack, ...styles.switchTrackOn } : styles.switchTrack },
547
+ h('div', { style: on ? { ...styles.switchKnob, ...styles.switchKnobOn } : styles.switchKnob })))
548
+ }
549
+
550
+ /** Two-option (or N-option) segmented control, used instead of native selects for the mode fields. */
551
+ function Segmented({ options, value, onChange }) {
552
+ return h('div', { style: styles.segmented, role: 'tablist' },
553
+ options.map(option => {
554
+ const on = option.value === value
555
+ return h('button', {
556
+ key: option.value, type: 'button', role: 'tab', 'aria-selected': on,
557
+ style: on ? { ...styles.segItem, ...styles.segItemOn } : styles.segItem,
558
+ onClick: () => onChange(option.value),
559
+ },
560
+ h('span', { style: styles.segTitle }, option.label),
561
+ option.hint ? h('span', { style: on ? { ...styles.segHint, ...styles.segHintOn } : styles.segHint }, option.hint) : null)
355
562
  }))
356
563
  }
357
564
 
358
- /** One checkbox row. */
359
- function Check({ label, checked, onChange }) {
360
- return h('label', { style: styles.check },
361
- h('input', { type: 'checkbox', checked: checked === true, onChange: event => onChange(event.target.checked) }),
362
- h('span', null, label))
565
+ function Select({ value, onChange, children, width }) {
566
+ return h('div', { style: styles.selectWrap },
567
+ h('select', { style: { ...styles.select, width: width ?? 168 }, value, onChange: event => onChange(event.target.value) }, children),
568
+ h('span', { style: styles.chevron, 'aria-hidden': 'true' }, '▾'))
363
569
  }
364
570
 
365
- /** Settings page section: engine, triggers, API budget and usage cards. */
571
+ /** Exactly one numeric input with a trailing unit; used by every numeric setting. */
572
+ function NumberRow({ label, hint, value, onChange, step, unit, last }) {
573
+ return h(Row, { last },
574
+ h(LabelBlock, { label, hint }),
575
+ h('div', { style: styles.control },
576
+ h('input', {
577
+ style: { ...styles.input, ...styles.inputNum }, type: 'number', step: step ?? 1,
578
+ value: value ?? '', onChange: event => onChange(Number(event.target.value)),
579
+ }),
580
+ unit ? h('span', { style: styles.unit }, unit) : null))
581
+ }
582
+
583
+ function TextRow({ label, hint, value, onChange, placeholder, width, last }) {
584
+ return h(Row, { last },
585
+ h(LabelBlock, { label, hint }),
586
+ h('div', { style: styles.control },
587
+ h('input', {
588
+ style: { ...styles.input, ...styles.inputText, width: width ?? styles.inputText.width },
589
+ value: value ?? '', placeholder, onChange: event => onChange(event.target.value),
590
+ })))
591
+ }
592
+
593
+ /** Inline status message with one consistent shape: a colored dot + readable text. */
594
+ function Callout({ tone = 'info', label, children }) {
595
+ const palette = {
596
+ info: [styles.calloutInfo, '#6d97ff'],
597
+ warn: [styles.calloutWarn, '#eecf94'],
598
+ error: [styles.calloutError, '#ff9b9b'],
599
+ ok: [styles.calloutOk, '#7fd7a2'],
600
+ }[tone] || [styles.calloutInfo, '#6d97ff']
601
+ return h('div', { style: { ...styles.callout, ...palette[0] }, role: tone === 'error' ? 'alert' : 'status' },
602
+ h('span', { style: { ...styles.calloutDot, background: palette[1] } }),
603
+ h('span', { style: { minWidth: 0 } },
604
+ label ? h('span', { style: styles.calloutLabel }, label) : null,
605
+ children))
606
+ }
607
+
608
+ function StatusPill({ on, onText, offText }) {
609
+ return h('span', { style: on ? { ...styles.pill, ...styles.pillOn } : { ...styles.pill, ...styles.pillOff } },
610
+ h('span', { style: { ...styles.pillDot, background: on ? '#7fd7a2' : 'rgba(255,255,255,0.35)' } }),
611
+ on ? onText : offText)
612
+ }
613
+
614
+ /** Settings page section: unified controls, one palette, one spacing scale. */
366
615
  function ColophonSettings() {
367
616
  const [form, setForm] = useState(null)
368
617
  const [status, setStatus] = useState(null)
369
618
  const [custom, setCustom] = useState(null)
619
+ const [range, setRange] = useState({ from: '', to: '' })
370
620
  const [message, setMessage] = useState('')
371
621
  const [failed, setFailed] = useState('')
622
+ const [saving, setSaving] = useState(false)
372
623
 
373
624
  useEffect(() => {
374
625
  let alive = true
@@ -388,8 +639,7 @@ window.__ModuleLoader__.load({
388
639
  const update = (section, key, value) => {
389
640
  setForm(current => {
390
641
  if (!current) return current
391
- const next = { ...current, [section]: { ...current[section], [key]: value } }
392
- return next
642
+ return { ...current, [section]: { ...current[section], [key]: value } }
393
643
  })
394
644
  setMessage('')
395
645
  }
@@ -400,6 +650,7 @@ window.__ModuleLoader__.load({
400
650
 
401
651
  const save = async () => {
402
652
  if (!form) return
653
+ setSaving(true)
403
654
  setFailed('')
404
655
  try {
405
656
  const patch = {
@@ -415,6 +666,8 @@ window.__ModuleLoader__.load({
415
666
  setMessage(tr('saved'))
416
667
  } catch (cause) {
417
668
  setFailed(tr('saveFailed', { message: String(cause?.message ?? cause) }))
669
+ } finally {
670
+ setSaving(false)
418
671
  }
419
672
  }
420
673
 
@@ -426,79 +679,149 @@ window.__ModuleLoader__.load({
426
679
  } catch { setCustom(null) }
427
680
  }
428
681
 
682
+ const applyRange = () => {
683
+ const from = Date.parse(range.from)
684
+ const to = range.to === '' ? Date.now() : Date.parse(range.to)
685
+ if (!Number.isFinite(from) || !Number.isFinite(to) || from > to) {
686
+ setFailed(tr('rangeInvalid'))
687
+ setMessage('')
688
+ return
689
+ }
690
+ setFailed('')
691
+ setCustom(null)
692
+ void loadCustom(from, to)
693
+ }
694
+
429
695
  if (!form) {
430
- return h('div', { style: styles.section },
696
+ return h('div', { style: { ...styles.page, padding: 14 } },
431
697
  h(CrashBanner),
432
- h('div', { style: styles.muted }, failed || tr('loading')))
698
+ h('div', { style: { fontSize: 12, color: '#9aa4b5' } }, failed || tr('loading')))
433
699
  }
434
700
 
435
701
  const usage = status?.usage ?? {}
436
- const card = (label, range) => h('div', { style: styles.card },
437
- h('div', { style: styles.label }, label),
438
- h('div', { style: styles.cardValue }, money(range?.costCNY)),
439
- h('div', { style: styles.muted }, tr('tokensLabel', { tokens: integer(range?.tokens) }), ' · ', tr('calls', { count: range?.calls ?? 0 })))
702
+ const usageCard = (label, slot) => h('div', { style: styles.usageCard },
703
+ h('div', { style: styles.usageLabel }, label),
704
+ h('div', { style: styles.usageValue }, money(slot?.costCNY)),
705
+ h('div', { style: styles.usageMeta }, tr('tokensLabel', { tokens: integer(slot?.tokens) }), ' · ', tr('calls', { count: slot?.calls ?? 0 })))
706
+
707
+ const queueItems = status?.queueItems ?? []
708
+ const queueCount = Number(status?.queueCount ?? status?.queue ?? 0) || 0
709
+ const enabled = form.enabled === true
710
+ const apiOn = form.engine === 'api'
711
+ const batchOn = form.triggers.closeBatch === true
440
712
 
441
- return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12, fontSize: 13 } },
713
+ return h('div', { style: styles.page },
442
714
  h(CrashBanner),
443
- h('div', { style: styles.muted }, tr('settingsIntro')),
444
- h('div', { style: styles.section },
445
- h(Check, { label: tr('enabled'), checked: form.enabled, onChange: value => updateTop('enabled', value) }),
446
- h('label', { style: styles.field },
447
- h('span', { style: styles.label }, tr('engine')),
448
- h('select', { style: styles.input, value: form.engine, onChange: event => updateTop('engine', event.target.value) },
449
- h('option', { value: 'rules' }, tr('engineRules')),
450
- h('option', { value: 'api' }, tr('engineApi'))))),
451
- h('div', { style: styles.section },
452
- h('div', { style: styles.sectionTitle }, tr('triggers')),
453
- h(Check, { label: tr('onIdle'), checked: form.triggers.onIdle, onChange: value => update('triggers', 'onIdle', value) }),
454
- h(Check, { label: tr('onSwitch'), checked: form.triggers.onSwitch, onChange: value => update('triggers', 'onSwitch', value) }),
455
- h(Check, { label: tr('closeBatch'), checked: form.triggers.closeBatch, onChange: value => update('triggers', 'closeBatch', value) }),
456
- h('div', { style: styles.warn }, tr('closeBatchWarn')),
457
- h(NumberField, {
458
- label: tr('closeBatchMax'), value: form.triggers.closeBatchMaxSessions, step: 1,
459
- onChange: value => update('triggers', 'closeBatchMaxSessions', value),
715
+ h('div', { style: styles.headCard },
716
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
717
+ h('span', { style: styles.headTitle }, '卷末 Colophon'),
718
+ h(StatusPill, { on: enabled, onText: tr('statusOn'), offText: tr('statusOff') })),
719
+ h('div', { style: styles.headSub }, tr('settingsSubtitle')),
720
+ h('div', { style: styles.headMeta },
721
+ h('span', { style: styles.hint }, tr('saveHint')),
722
+ status ? h('span', { style: { ...styles.hint, marginLeft: 'auto' } }, tr('dataRoot'), ':', status.dataRoot) : null)),
723
+
724
+ h(Card, { title: tr('basicTitle') },
725
+ h(SwitchRow, {
726
+ label: tr('enabled'), hint: tr('enabledHint'), checked: enabled,
727
+ onChange: value => updateTop('enabled', value), last: true,
728
+ }),
729
+ h(Row, { last: true },
730
+ h(LabelBlock, { label: tr('engine'), hint: tr('engineHint') }),
731
+ h('div', { style: styles.control },
732
+ h(Segmented, {
733
+ value: form.engine,
734
+ onChange: value => updateTop('engine', value),
735
+ options: [
736
+ { value: 'rules', label: tr('engineRules'), hint: tr('engineRulesHint') },
737
+ { value: 'api', label: tr('engineApi'), hint: tr('engineApiHint') },
738
+ ],
739
+ })))),
740
+
741
+ h(Card, { title: tr('triggers') },
742
+ h(SwitchRow, {
743
+ label: tr('onIdle'), hint: tr('onIdleHint'), checked: form.triggers.onIdle === true,
744
+ onChange: value => update('triggers', 'onIdle', value),
745
+ }),
746
+ h(SwitchRow, {
747
+ label: tr('onSwitch'), hint: tr('onSwitchHint'), checked: form.triggers.onSwitch === true,
748
+ onChange: value => update('triggers', 'onSwitch', value),
749
+ }),
750
+ h(SwitchRow, {
751
+ label: tr('closeBatch'), checked: batchOn, last: !batchOn,
752
+ onChange: value => update('triggers', 'closeBatch', value),
753
+ }),
754
+ batchOn ? h('div', null,
755
+ h(NumberRow, {
756
+ label: tr('closeBatchMax'), unit: tr('unitSessions'), step: 1,
757
+ value: form.triggers.closeBatchMaxSessions, last: true,
758
+ onChange: value => update('triggers', 'closeBatchMaxSessions', value),
759
+ }),
760
+ h(Callout, { tone: 'warn', label: tr('note') }, tr('closeBatchWarn'))) : null),
761
+
762
+ h(Card, { title: tr('apiSection'), meta: h(StatusPill, { on: apiOn, onText: tr('apiOn'), offText: tr('apiOff') }) },
763
+ h(Callout, { tone: 'info' }, tr('apiNote')),
764
+ h(TextRow, { label: tr('provider'), hint: 'deepseek-official', value: form.api.provider, width: 200, onChange: value => update('api', 'provider', value) }),
765
+ h(TextRow, { label: tr('model'), hint: 'deepseek-chat', value: form.api.model, width: 200, onChange: value => update('api', 'model', value) }),
766
+ h(Row, null,
767
+ h(LabelBlock, { label: tr('priceIn'), hint: tr('unitPrice') }),
768
+ h('div', { style: styles.control },
769
+ h('input', {
770
+ style: { ...styles.input, ...styles.inputNum }, type: 'number', step: 0.1,
771
+ value: form.api.priceInCNYPerM ?? '', onChange: event => update('api', 'priceInCNYPerM', Number(event.target.value)),
772
+ }),
773
+ h('span', { style: styles.unit }, '元')),
774
+ ),
775
+ h(NumberRow, {
776
+ label: tr('priceOut'), hint: tr('unitPrice'), step: 0.1, unit: '元',
777
+ value: form.api.priceOutCNYPerM, onChange: value => update('api', 'priceOutCNYPerM', value),
778
+ }),
779
+ h(NumberRow, {
780
+ label: tr('perSummaryCap'), hint: tr('perSummaryCapHint'), step: 0.01, unit: '元',
781
+ value: form.api.maxCostPerSummaryCNY, onChange: value => update('api', 'maxCostPerSummaryCNY', value),
782
+ }),
783
+ h(NumberRow, {
784
+ label: tr('dailyBudget'), hint: tr('dailyBudgetHint'), step: 1000, unit: 'tokens',
785
+ value: form.api.dailyTokenBudget, onChange: value => update('api', 'dailyTokenBudget', value),
786
+ }),
787
+ h(Row, { last: !(apiOn && status && status.apiAvailable === false) },
788
+ h(LabelBlock, { label: tr('overCap'), hint: tr('overCapHint') }),
789
+ h('div', { style: styles.control },
790
+ h(Segmented, {
791
+ value: form.api.overCap,
792
+ onChange: value => update('api', 'overCap', value),
793
+ options: [
794
+ { value: 'queue', label: tr('overCapQueue') },
795
+ { value: 'skip', label: tr('overCapSkip') },
796
+ ],
797
+ }))),
798
+ apiOn && status && status.apiAvailable === false
799
+ ? h(Callout, { tone: 'warn', label: tr('note') }, tr('apiUnavailable'))
800
+ : null),
801
+
802
+ h(Card, { title: tr('filter') },
803
+ h(NumberRow, {
804
+ label: tr('minMessages'), hint: tr('minMessagesHint'), unit: tr('unitMessages'),
805
+ value: form.filter.minMessages, onChange: value => update('filter', 'minMessages', value),
806
+ }),
807
+ h(NumberRow, {
808
+ label: tr('minTokens'), hint: tr('minTokensHint'), unit: 'tokens', step: 500, last: true,
809
+ value: form.filter.minTokens, onChange: value => update('filter', 'minTokens', value),
460
810
  })),
461
- h('div', { style: styles.section },
462
- h('div', { style: styles.sectionTitle }, tr('apiSection')),
463
- h('div', { style: styles.muted }, tr('apiNote')),
464
- h('div', { style: styles.row },
465
- h('label', { style: styles.field, key: 'provider' },
466
- h('span', { style: styles.label }, tr('provider')),
467
- h('input', { style: styles.input, value: form.api.provider, placeholder: 'deepseek', onChange: event => update('api', 'provider', event.target.value) })),
468
- h('label', { style: styles.field, key: 'model' },
469
- h('span', { style: styles.label }, tr('model')),
470
- h('input', { style: styles.input, value: form.api.model, onChange: event => update('api', 'model', event.target.value) }))),
471
- h('div', { style: styles.row },
472
- h(NumberField, { label: tr('priceIn'), value: form.api.priceInCNYPerM, step: 0.1, onChange: value => update('api', 'priceInCNYPerM', value) }),
473
- h(NumberField, { label: tr('priceOut'), value: form.api.priceOutCNYPerM, step: 0.1, onChange: value => update('api', 'priceOutCNYPerM', value) })),
474
- h('div', { style: styles.row },
475
- h(NumberField, { label: tr('perSummaryCap'), value: form.api.maxCostPerSummaryCNY, step: 0.01, onChange: value => update('api', 'maxCostPerSummaryCNY', value) }),
476
- h(NumberField, { label: tr('dailyBudget'), value: form.api.dailyTokenBudget, step: 1000, onChange: value => update('api', 'dailyTokenBudget', value) }),
477
- h('label', { style: styles.field, key: 'overCap' },
478
- h('span', { style: styles.label }, tr('overCap')),
479
- h('select', { style: styles.input, value: form.api.overCap, onChange: event => update('api', 'overCap', event.target.value) },
480
- h('option', { value: 'queue' }, tr('overCapQueue')),
481
- h('option', { value: 'skip' }, tr('overCapSkip')))))),
482
- h('div', { style: styles.section },
483
- h('div', { style: styles.sectionTitle }, tr('filter')),
484
- h('div', { style: styles.row },
485
- h(NumberField, { label: tr('minMessages'), value: form.filter.minMessages, onChange: value => update('filter', 'minMessages', value) }),
486
- h(NumberField, { label: tr('minTokens'), value: form.filter.minTokens, step: 500, onChange: value => update('filter', 'minTokens', value) }))),
487
- form.engine === 'api' && status && status.apiAvailable === false
488
- ? h('div', { style: styles.warn }, tr('apiUnavailable'))
489
- : null,
490
- h('div', { style: styles.section },
491
- h('div', { style: styles.sectionTitle }, tr('queueTitle'), ' · ',
492
- h('span', { style: styles.muted }, String(status?.queueCount ?? status?.queue ?? 0))),
493
- (status?.queueItems ?? []).length === 0
494
- ? h('div', { style: styles.muted }, tr('queueEmpty'))
495
- : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
496
- status.queueItems.map(item => h('div', { key: item.sessionId, style: styles.muted },
497
- item.sessionId, ' · ', item.reason, ' · ', new Date(item.at).toLocaleString()))),
498
- h('div', { style: styles.actions },
811
+
812
+ h(Card, { title: tr('queueTitle'), meta: h(StatusPill, { on: queueCount > 0, onText: `${queueCount}`, offText: `0` }) },
813
+ h('div', { style: { ...styles.hint, padding: '10px 14px 2px' } }, tr('queueHint')),
814
+ queueItems.length === 0
815
+ ? h('div', { style: styles.emptyBox }, tr('queueEmpty'))
816
+ : h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, padding: '10px 14px 2px' } },
817
+ queueItems.map(item => h('div', { key: item.sessionId, style: styles.listRow },
818
+ h('span', { style: { fontWeight: 600 } }, String(item.sessionId).slice(0, 14)),
819
+ h('span', { style: styles.hint }, tr('queueReason', { reason: item.reason })),
820
+ h('span', { style: { ...styles.hint, marginLeft: 'auto' } }, new Date(item.at).toLocaleString())))),
821
+ h('div', { style: styles.actionsBar },
499
822
  h('button', {
500
- style: styles.button,
501
- disabled: (status?.queueCount ?? 0) === 0,
823
+ style: queueCount === 0 ? { ...styles.buttonSecondary, ...styles.buttonDisabled } : styles.buttonSecondary,
824
+ disabled: queueCount === 0,
502
825
  onClick: async () => {
503
826
  setFailed('')
504
827
  try {
@@ -510,29 +833,36 @@ window.__ModuleLoader__.load({
510
833
  }
511
834
  },
512
835
  }, tr('queueProcess')))),
513
- h('div', { style: styles.section },
514
- h('div', { style: styles.sectionTitle }, tr('usage'), ' · ', h('span', { style: styles.ok }, tr('localZero'))),
515
- h('div', { style: styles.cards },
516
- card(tr('usageHour'), usage.hour),
517
- card(tr('usageDay'), usage.day),
518
- card(tr('usageWeek'), usage.week),
519
- card(tr('usageMonth'), usage.month),
520
- custom ? card(tr('usageCustom'), custom) : null),
521
- h('div', { style: styles.row },
522
- h('label', { style: styles.field },
523
- h('span', { style: styles.label }, tr('from')),
524
- h('input', { style: styles.input, type: 'datetime-local', onChange: event => {
525
- const from = Date.parse(event.target.value)
526
- const to = Date.now()
527
- setCustom(null)
528
- void loadCustom(from, to)
529
- } }))),
530
- status ? h('div', { style: styles.muted },
531
- tr('dataRoot'), ': ', status.dataRoot, ' · ', tr('queue'), ': ', status.queue ?? 0) : null),
532
- failed ? h('div', { style: styles.warn }, failed) : null,
533
- message ? h('div', { style: styles.ok }, message) : null,
534
- h('div', { style: styles.actions },
535
- h('button', { style: styles.button, onClick: () => void save() }, tr('save'))))
836
+
837
+ h(Card, { title: tr('usage'), meta: h('span', { style: styles.hint }, tr('localZero')) },
838
+ h('div', { style: styles.usageGrid },
839
+ usageCard(tr('usageHour'), usage.hour),
840
+ usageCard(tr('usageDay'), usage.day),
841
+ usageCard(tr('usageWeek'), usage.week),
842
+ usageCard(tr('usageMonth'), usage.month)),
843
+ custom ? h('div', { style: { ...styles.usageGrid, gridTemplateColumns: 'repeat(1, minmax(0,1fr))', paddingTop: 8 } },
844
+ usageCard(tr('usageCustom'), custom)) : null,
845
+ h('div', { style: { display: 'flex', alignItems: 'flex-end', gap: 10, flexWrap: 'wrap', padding: '12px 14px 4px' } },
846
+ h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
847
+ h('span', { style: styles.unit }, tr('from')),
848
+ h('input', { style: styles.input, type: 'datetime-local', value: range.from,
849
+ onChange: event => setRange(current => ({ ...current, from: event.target.value })) })),
850
+ h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
851
+ h('span', { style: styles.unit }, tr('to')),
852
+ h('input', { style: styles.input, type: 'datetime-local', value: range.to,
853
+ onChange: event => setRange(current => ({ ...current, to: event.target.value })) })),
854
+ h('button', { style: styles.buttonSecondary, onClick: () => void applyRange() }, tr('apply')),
855
+ custom ? null : h('span', { style: styles.unit }, tr('customHint'))),
856
+ h('div', { style: { padding: '0 14px 12px' } }, h('span', { style: styles.unit }, tr('rangeEmptyHint')))),
857
+
858
+ h('div', { style: styles.footer },
859
+ failed
860
+ ? h('span', { style: { ...styles.footerText, color: '#ffb3b3' } }, failed)
861
+ : message
862
+ ? h('span', { style: { ...styles.footerText, color: '#8fe0b1' } }, message)
863
+ : h('span', { style: styles.footerText }, tr('saveHint')),
864
+ h('button', { style: saving ? { ...styles.buttonPrimary, opacity: 0.7 } : styles.buttonPrimary, disabled: saving, onClick: () => void save() },
865
+ saving ? tr('saving') : tr('save'))))
536
866
  }
537
867
 
538
868
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-colophon",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",