dsh-session-title-stamp 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,6 +14,7 @@ title. Beyond automatic naming:
14
14
  - **Generate title** — the conversation-header ↻ button, the session row's
15
15
  **Generate title** menu item, or `/retitle`.
16
16
  - **Copy title** — an extra item in the session `···` menu copies the full title.
17
+ - **Settings page** — preview and change format, emoji, and refresh cadence without editing YAML.
17
18
  - **Optional category emoji** — `categoryEmoji: true` renders titles such as
18
19
  `1027 | ⚡ 优化 | ...`.
19
20
  - **Hover stats** — elapsed time, estimated CNY cost, and token count on the
@@ -63,7 +64,7 @@ and mirrors conventions used by other coding agents.
63
64
  Add this market index source in **Plugins → Discover → Index sources**:
64
65
 
65
66
  ```text
66
- https://cdn.jsdelivr.net/gh/xuedipiaofei/dsh-session-title-stamp@v0.6.0/market/index.json
67
+ https://cdn.jsdelivr.net/gh/xuedipiaofei/dsh-session-title-stamp@v0.7.0/market/index.json
67
68
  ```
68
69
 
69
70
  Then install **Session title stamp** from the list. The plugin installs as a
@@ -133,7 +134,7 @@ mode using `retitleEvery`.
133
134
 
134
135
  ### Header button and hover stats
135
136
 
136
- 0.6.0 adds a small browser half:
137
+ 0.7.0 adds a small browser half:
137
138
 
138
139
  - a **refresh icon** in the conversation header; it runs the same `/retitle`
139
140
  command as typing it, and is disabled while the session is running.
@@ -152,6 +153,23 @@ so this plugin does **not** add a second status-color layer.
152
153
  If the hover line is missing, the browser half could not reach the host stats
153
154
  route; the refresh button and automatic titles are unaffected.
154
155
 
156
+ ### Settings page
157
+
158
+ ![Session title settings](docs/0.7.0-settings-mock.png)
159
+
160
+ 0.7.0 adds **Settings → Plugins → Session titles**:
161
+
162
+ - a live preview of the exact title the current template will produce;
163
+ - category language (Chinese/English), optional category emoji, date format,
164
+ and the title template;
165
+ - the auto-refresh switch, minimum interval, message freeze, and opt-in startup
166
+ backfill, with the cost trade-off stated in place;
167
+ - advanced name-length and recent-message controls; timeouts, budgets, and
168
+ model routing stay in the profile configuration.
169
+
170
+ Saving writes the current profile's plugin config, so it applies to the next
171
+ generated title without a restart. Existing titles are never rewritten.
172
+
155
173
  ### Failures
156
174
 
157
175
  - A failed retitle **keeps the existing title**: the provider throws, which is
@@ -213,7 +231,8 @@ An unknown placeholder is left verbatim (`{MMDD} {bogus}` keeps `{bogus}`), so a
213
231
  typo is visible instead of silently disappearing. The template owns the final
214
232
  format; `maxTitleBytes` still clips the result.
215
233
 
216
- The default taxonomy is Chinese. `categoryPreset: en` switches it to
234
+ The Settings page covers the common fields; the YAML table below remains the
235
+ automation/advanced source. The default taxonomy is Chinese. `categoryPreset: en` switches it to
217
236
  `Analysis / Build / Fix / Optimize / Debug / QA / Release / Docs / Other`; `categories`
218
237
  overrides either preset with any labels you want. The prompt lists the configured
219
238
  labels and the local fallback maps common keywords onto them.
package/README.zh.md CHANGED
@@ -7,6 +7,7 @@
7
7
  - **自动重算**:回答完成后更新,2 分钟冷却,超过 100 条消息后冻结;fork、子代理和手动固定的标题跳过。
8
8
  - **生成标题**:会话头 ↻ 按钮、会话行 `···` 菜单「自动生成标题」、或 `/retitle`。
9
9
  - **复制标题**:会话行 `···` 菜单多一项复制完整标题。
10
+ - **设置页**:可视化调整格式、emoji 和重算节奏,带实时预览,不用改 YAML。
10
11
  - **可选 emoji 分类**:`categoryEmoji: true` 后标题形如 `1027 | ⚡ 优化 | ...`。
11
12
  - **悬停统计**:会话行悬停显示耗时、估算 CNY 成本、token 数。
12
13
  - **分类语言**:`categoryPreset: zh | en`,也可以用 `categories` 自定义。
@@ -46,7 +47,7 @@
46
47
  在 **插件 → 发现(Discover)→ 索引源** 添加:
47
48
 
48
49
  ```text
49
- https://cdn.jsdelivr.net/gh/xuedipiaofei/dsh-session-title-stamp@v0.6.0/market/index.json
50
+ https://cdn.jsdelivr.net/gh/xuedipiaofei/dsh-session-title-stamp@v0.7.0/market/index.json
50
51
  ```
51
52
 
52
53
  然后在列表里安装 **Session title stamp / 会话标题印章**。插件以 profile bundle 的形式安装,之后可在插件页启停。
@@ -96,7 +97,7 @@ fork 子会话、子代理会话,以及用户手动改名固定的标题都会
96
97
 
97
98
  ### 会话头按钮与悬停统计
98
99
 
99
- 0.6.0 增加了一个很小的浏览器半边:
100
+ 0.7.0 增加了一个很小的浏览器半边:
100
101
 
101
102
  - 会话头有一个**刷新图标**,效果等同输入 `/retitle`,会话运行中禁用;
102
103
  - 鼠标悬停会话行时,在原生相对时间下面多一行:
@@ -108,6 +109,19 @@ fork 子会话、子代理会话,以及用户手动改名固定的标题都会
108
109
 
109
110
  如果悬停行不显示,说明浏览器半边没连上宿主统计路由;刷新按钮和自动标题不受影响。
110
111
 
112
+ ### 设置页
113
+
114
+ ![会话标题设置页](docs/0.7.0-settings-mock.png)
115
+
116
+ 0.7.0 增加 **设置 → 插件设置 → 会话标题**:
117
+
118
+ - 顶部实时预览当前模板会生成的标题;
119
+ - 分类语言(中文/English)、可选分类 emoji、日期格式、标题模板;
120
+ - 自动重算开关、最小间隔、消息数冻结、启动补刷,并把额外模型成本写在说明里;
121
+ - 高级项只放名称长度和最近消息数;超时、预算、模型路由仍在配置文件里。
122
+
123
+ 保存会写入当前 profile 的插件配置,对下一次生成的标题生效,不需要重启;已有标题不会被改写。
124
+
111
125
  ### 失败时
112
126
 
113
127
  - 已经有标题时,重算失败会**保留旧标题**:provider 抛错,标题服务据此不提交新修订。
@@ -164,7 +178,7 @@ fork 子会话、子代理会话,以及用户手动改名固定的标题都会
164
178
 
165
179
  不认识的占位符会**原样保留**(`{MMDD} {bogus}` 会保留 `{bogus}`),方便一眼看出模板写错,而不是悄悄消失。最终仍受 `maxTitleBytes` 截断。
166
180
 
167
- 默认分类是中文。`categoryPreset: en` 可切到
181
+ 设置页覆盖常用字段;下面的 YAML 表仍用于自动化和高级配置。默认分类是中文。`categoryPreset: en` 可切到
168
182
  `Analysis / Build / Fix / Optimize / Debug / QA / Release / Docs / Other`;`categories`
169
183
  可以覆盖任意预设。提示词使用配置的标签,本地兜底也会把常见中英文关键词映射过去。
170
184
 
package/client.js CHANGED
@@ -18,6 +18,7 @@ window.__ModuleLoader__.load({
18
18
  const h = React.createElement
19
19
 
20
20
  const NS = 'dsh-session-title-stamp'
21
+ const SETTINGS_NAMESPACE = 'session-title-stamp'
21
22
  const STATS_PATH = '/api/session-title-stamp/stats'
22
23
  const inject = ['slots', 'remote', 'remote.commands', 'locale']
23
24
  const DICT = {
@@ -29,6 +30,48 @@ window.__ModuleLoader__.load({
29
30
  estimate: '估算',
30
31
  copyTitle: '复制标题',
31
32
  copyHint: '复制完整会话标题',
33
+ 'settings.nav': '会话标题',
34
+ 'settings.title': '会话标题',
35
+ 'settings.intro': '让侧栏里的每个会话都有一个稳定、可扫读的名字。修改后立即对新生成的标题生效。',
36
+ 'settings.preview': '实时预览',
37
+ 'settings.previewHint': '开启 emoji 后',
38
+ 'settings.format': '标题格式',
39
+ 'settings.categoryLanguage': '分类语言',
40
+ 'settings.categoryLanguageHint': '中文使用「分析 / 实现 / 修复 / 优化…」,英文使用 Analysis / Build / Fix / Optimize…',
41
+ 'settings.categoryEmoji': '分类 emoji 前缀',
42
+ 'settings.categoryEmojiHint': '为分类增加视觉标记;默认关闭,开启后会占用少量标题字节。',
43
+ 'settings.dateFormat': '日期格式',
44
+ 'settings.dateFormatHint': '日期由本地时间计算,不交给模型。',
45
+ 'settings.template': '标题模板',
46
+ 'settings.templateHint': '支持 {date}、{type}、{topic},也可用 {YYYYMMDD}、{HHmm} 等。',
47
+ 'settings.auto': '自动重算',
48
+ 'settings.autoBadge': '默认开启',
49
+ 'settings.autoRefresh': '回答完成后自动重算',
50
+ 'settings.autoRefreshHint': '每个完成的 turn 结束后更新标题;fork、子代理和手动固定的标题会跳过。',
51
+ 'settings.minInterval': '最小刷新间隔',
52
+ 'settings.minIntervalHint': '避免首轮刚生成又再次调用模型。',
53
+ 'settings.minutes': '分钟',
54
+ 'settings.freeze': '消息数冻结',
55
+ 'settings.freezeHint': '超过该用户消息数后停止自动重算,0 表示不冻结。',
56
+ 'settings.messages': '条',
57
+ 'settings.backfill': '启动时补刷旧标题',
58
+ 'settings.backfillHint': '启动后修复仍是兜底标题的 live 会话;会额外调用模型,默认关闭。',
59
+ 'settings.advanced': '高级',
60
+ 'settings.advancedHint': '名称长度、最近消息数;其它参数请用设置右上角的「打开配置文件」。',
61
+ 'settings.nameLimit': '名称最大字符数',
62
+ 'settings.nameLimitHint': '标题名称部分的上限,最终还受标题字节上限约束。',
63
+ 'settings.recentMessages': '最近消息数',
64
+ 'settings.recentMessagesHint': '生成标题时包含最近多少条消息。',
65
+ 'settings.chars': '字符',
66
+ 'settings.restore': '恢复默认',
67
+ 'settings.dirty': '有未保存的修改',
68
+ 'settings.save': '保存',
69
+ 'settings.saving': '保存中…',
70
+ 'settings.saved': '已保存',
71
+ 'settings.failed': '保存失败',
72
+ 'settings.readOnly': '当前 profile 不接受配置写入。',
73
+ 'settings.loading': '正在读取配置…',
74
+ 'settings.unavailable': '当前 profile 里没有这个插件的配置项,这里没有可编辑的内容。请在插件页启用后重开。',
32
75
  },
33
76
  en: {
34
77
  menu: 'Generate title',
@@ -38,6 +81,48 @@ window.__ModuleLoader__.load({
38
81
  estimate: 'est.',
39
82
  copyTitle: 'Copy title',
40
83
  copyHint: 'Copy the full session title',
84
+ 'settings.nav': 'Session titles',
85
+ 'settings.title': 'Session titles',
86
+ 'settings.intro': 'Give every row a stable, scannable name. Changes apply to titles generated after saving.',
87
+ 'settings.preview': 'Live preview',
88
+ 'settings.previewHint': 'With emoji',
89
+ 'settings.format': 'Title format',
90
+ 'settings.categoryLanguage': 'Category language',
91
+ 'settings.categoryLanguageHint': 'Chinese uses 分析 / 实现 / 修复 / 优化…; English uses Analysis / Build / Fix / Optimize…',
92
+ 'settings.categoryEmoji': 'Category emoji prefix',
93
+ 'settings.categoryEmojiHint': 'Adds a visual marker and a few title bytes. Off by default.',
94
+ 'settings.dateFormat': 'Date format',
95
+ 'settings.dateFormatHint': 'The date is computed locally, never by the model.',
96
+ 'settings.template': 'Title template',
97
+ 'settings.templateHint': 'Supports {date}, {type}, {topic}, plus {YYYYMMDD}, {HHmm}, and more.',
98
+ 'settings.auto': 'Auto refresh',
99
+ 'settings.autoBadge': 'on by default',
100
+ 'settings.autoRefresh': 'Refresh after a completed turn',
101
+ 'settings.autoRefreshHint': 'Updates the title after each completed turn; forks, subagents, and manually pinned titles are skipped.',
102
+ 'settings.minInterval': 'Minimum interval',
103
+ 'settings.minIntervalHint': 'Avoids a second request right after the first title.',
104
+ 'settings.minutes': 'minutes',
105
+ 'settings.freeze': 'Freeze after',
106
+ 'settings.freezeHint': 'Stop automatic refreshes after this many user messages; 0 disables the freeze.',
107
+ 'settings.messages': 'messages',
108
+ 'settings.backfill': 'Backfill old titles on startup',
109
+ 'settings.backfillHint': 'Repairs live sessions still using a fallback title; calls the model extra. Off by default.',
110
+ 'settings.advanced': 'Advanced',
111
+ 'settings.advancedHint': 'Name length and recent messages; use “Open config file” in the top-right for everything else.',
112
+ 'settings.nameLimit': 'Maximum name characters',
113
+ 'settings.nameLimitHint': 'Caps the name before the title byte budget applies.',
114
+ 'settings.recentMessages': 'Recent messages',
115
+ 'settings.recentMessagesHint': 'How many recent messages are sent with the title request.',
116
+ 'settings.chars': 'chars',
117
+ 'settings.restore': 'Restore defaults',
118
+ 'settings.dirty': 'Unsaved changes',
119
+ 'settings.save': 'Save',
120
+ 'settings.saving': 'Saving…',
121
+ 'settings.saved': 'Saved',
122
+ 'settings.failed': 'Not saved',
123
+ 'settings.readOnly': 'This profile does not accept configuration writes.',
124
+ 'settings.loading': 'Reading configuration…',
125
+ 'settings.unavailable': 'This profile has no configuration entry for the plugin. Enable it and reopen this page.',
41
126
  },
42
127
  }
43
128
 
@@ -257,6 +342,278 @@ window.__ModuleLoader__.load({
257
342
  )
258
343
  }
259
344
 
345
+ function useLocaleRevision(ctx) {
346
+ const [, force] = React.useState(0)
347
+ React.useEffect(() => {
348
+ if (typeof ctx?.locale?.subscribe !== 'function') return undefined
349
+ return ctx.locale.subscribe(() => force((value) => value + 1))
350
+ }, [ctx])
351
+ }
352
+
353
+ const SETTINGS_STYLE = {
354
+ page: { display: 'flex', flexDirection: 'column', maxWidth: '720px', color: 'var(--dsw-alias-label-primary, #e8e8ea)' },
355
+ h2: { margin: '0 0 6px', fontSize: '18px', lineHeight: '26px', fontWeight: 600 },
356
+ intro: { margin: '0 0 20px', fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-label-tertiary, #8b8d94)' },
357
+ preview: { border: '1px solid var(--dsw-alias-border-l2, #33363d)', background: 'var(--dsw-alias-bg-layer-2, #15171b)', borderRadius: '12px', padding: '14px 16px', marginBottom: '20px' },
358
+ previewLabel: { fontSize: '11px', color: 'var(--dsw-alias-label-caption, #737985)', letterSpacing: '.06em', marginBottom: '6px' },
359
+ previewTitle: { fontSize: '15px', lineHeight: '23px', color: 'var(--dsw-alias-label-primary, #fff)', fontWeight: 500, wordBreak: 'break-word' },
360
+ section: { marginTop: '18px' },
361
+ sectionTitle: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px', color: 'var(--dsw-alias-label-caption, #737985)', letterSpacing: '.06em', textTransform: 'uppercase', margin: '0 0 2px' },
362
+ row: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '24px', padding: '15px 0', borderBottom: '.5px solid var(--dsw-alias-border-l2, #2b2e35)' },
363
+ rowColumn: { display: 'flex', flexDirection: 'column', alignItems: 'stretch', gap: '10px', padding: '15px 0', borderBottom: '.5px solid var(--dsw-alias-border-l2, #2b2e35)' },
364
+ text: { minWidth: 0 },
365
+ label: { fontSize: '13px', fontWeight: 500, lineHeight: '20px' },
366
+ desc: { marginTop: '4px', fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary, #8b8d94)' },
367
+ seg: { display: 'inline-flex', padding: '2px', border: '1px solid var(--dsw-alias-border-l2, #343842)', borderRadius: '9px', background: 'var(--dsw-alias-bg-layer-1, #191b20)', flex: 'none' },
368
+ segButton: { border: 0, background: 'transparent', color: 'var(--dsw-alias-label-secondary, #9a9da6)', font: 'inherit', fontSize: '12px', padding: '5px 11px', borderRadius: '7px', cursor: 'pointer' },
369
+ segButtonOn: { background: 'var(--dsw-alias-interactive-bg-hover, #2d3340)', color: 'var(--dsw-alias-label-primary, #fff)' },
370
+ switch: (on) => ({ width: '40px', height: '23px', borderRadius: '999px', background: on ? 'var(--dsw-alias-brand-primary, #6f96ff)' : 'var(--dsw-alias-border-l2, #3a3f49)', position: 'relative', flex: 'none', border: 0, cursor: 'pointer', padding: 0 }),
371
+ thumb: (on) => ({ position: 'absolute', top: '2px', left: on ? '19px' : '2px', width: '19px', height: '19px', borderRadius: '50%', background: '#fff', transition: 'left 120ms ease' }),
372
+ input: { background: 'var(--dsw-alias-bg-layer-1, #17191e)', border: '1px solid var(--dsw-alias-border-l2, #383c46)', borderRadius: '7px', color: 'var(--dsw-alias-label-primary, #eceef2)', font: 'inherit', fontSize: '12px', padding: '6px 9px' },
373
+ number: { width: '64px', textAlign: 'right' },
374
+ fullInput: { width: '100%', boxSizing: 'border-box', fontFamily: '"SF Mono", ui-monospace, monospace' },
375
+ unit: { fontSize: '12px', color: 'var(--dsw-alias-label-caption, #737985)' },
376
+ num: { display: 'flex', alignItems: 'center', gap: '7px', flex: 'none' },
377
+ advanced: { display: 'flex', alignItems: 'center', gap: '7px', border: 0, background: 'transparent', color: 'var(--dsw-alias-label-caption, #737985)', font: 'inherit', fontSize: '12px', padding: '14px 0 0', cursor: 'pointer', textAlign: 'left' },
378
+ footer: { display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: '12px', paddingTop: '20px' },
379
+ restore: { border: 0, background: 'transparent', color: 'var(--dsw-alias-label-secondary, #9a9da6)', font: 'inherit', fontSize: '12px', marginRight: 'auto', padding: 0, cursor: 'pointer' },
380
+ save: { border: '1px solid transparent', background: 'var(--dsw-alias-label-primary, #e8e8ea)', color: 'var(--dsw-alias-bg-layer-3, #15171b)', borderRadius: '8px', font: 'inherit', fontSize: '13px', fontWeight: 600, padding: '7px 18px', cursor: 'pointer' },
381
+ status: { fontSize: '12px', lineHeight: '18px' },
382
+ }
383
+
384
+ function buildSettingsSection(React, configForms, t, ctx) {
385
+ const h = React.createElement
386
+ const DEFAULT_TEMPLATE = '{date} | {type} | {topic}'
387
+ const readText = (key) => t(`settings.${key}`)
388
+ const sample = (preset, emoji, dateFormat, template) => {
389
+ const base = preset === 'en' ? 'Optimize' : '优化'
390
+ const type = emoji ? `⚡ ${base}` : base
391
+ const topic = preset === 'en' ? 'Reduce renderer memory usage' : '降低渲染器内存占用'
392
+ const date = dateFormat === 'YYMM' ? '2610' : dateFormat === 'YYYYMMDD' ? '20261027' : '1027'
393
+ const values = { date, type, topic, YYYY: '2026', YY: '26', MM: '10', DD: '27', HH: '12', mm: '30', ss: '00' }
394
+ return (template || DEFAULT_TEMPLATE).replace(/\{([A-Za-z]+)\}/g, (match, key) => values[key] ?? match)
395
+ }
396
+
397
+ return function SessionTitleSettings() {
398
+ const form = React.useMemo(() => configForms.get(SETTINGS_NAMESPACE), [])
399
+ const [snapshot, setSnapshot] = React.useState(() => form.getSnapshot())
400
+ React.useEffect(() => form.subscribe(() => setSnapshot(form.getSnapshot())), [form])
401
+ useLocaleRevision(ctx)
402
+
403
+ const stored = snapshot.value ?? {}
404
+ const storedPreset = stored.categoryPreset === 'en' ? 'en' : 'zh'
405
+ const storedEmoji = stored.categoryEmoji === true
406
+ const storedDateFormat = ['MMDD', 'YYMM', 'YYYYMMDD'].includes(stored.dateFormat) ? stored.dateFormat : 'MMDD'
407
+ const storedTemplate = typeof stored.template === 'string' && stored.template.trim() !== '' ? stored.template.trim() : DEFAULT_TEMPLATE
408
+ const storedAuto = stored.refreshOnTurnEnd !== false
409
+ const storedMinutes = String(Math.max(0, Math.round((Number(stored.refreshMinIntervalMs) || 120000) / 60000)))
410
+ const storedFreeze = String(Number.isFinite(stored.refreshMaxTurns) ? stored.refreshMaxTurns : 100)
411
+ const storedBackfill = stored.backfillOnStart === true
412
+ const storedNameChars = String(Number.isFinite(stored.maxNameChars) ? stored.maxNameChars : 20)
413
+ const storedRecent = String(Number.isFinite(stored.recentMessages) ? stored.recentMessages : 8)
414
+
415
+ const [categoryPreset, setCategoryPreset] = React.useState(storedPreset)
416
+ const [categoryEmoji, setCategoryEmoji] = React.useState(storedEmoji)
417
+ const [dateFormat, setDateFormat] = React.useState(storedDateFormat)
418
+ const [template, setTemplate] = React.useState(storedTemplate)
419
+ const [autoRefresh, setAutoRefresh] = React.useState(storedAuto)
420
+ const [minutes, setMinutes] = React.useState(storedMinutes)
421
+ const [freeze, setFreeze] = React.useState(storedFreeze)
422
+ const [backfill, setBackfill] = React.useState(storedBackfill)
423
+ const [nameChars, setNameChars] = React.useState(storedNameChars)
424
+ const [recentMessages, setRecentMessages] = React.useState(storedRecent)
425
+ const [advancedOpen, setAdvancedOpen] = React.useState(false)
426
+ const [saveState, setSaveState] = React.useState('idle')
427
+
428
+ React.useEffect(() => {
429
+ setCategoryPreset(storedPreset)
430
+ setCategoryEmoji(storedEmoji)
431
+ setDateFormat(storedDateFormat)
432
+ setTemplate(storedTemplate)
433
+ setAutoRefresh(storedAuto)
434
+ setMinutes(storedMinutes)
435
+ setFreeze(storedFreeze)
436
+ setBackfill(storedBackfill)
437
+ setNameChars(storedNameChars)
438
+ setRecentMessages(storedRecent)
439
+ }, [snapshot.revision])
440
+
441
+ const busy = saveState === 'saving'
442
+ const writable = snapshot.writable !== false
443
+ const dirty =
444
+ categoryPreset !== storedPreset ||
445
+ categoryEmoji !== storedEmoji ||
446
+ dateFormat !== storedDateFormat ||
447
+ template !== storedTemplate ||
448
+ autoRefresh !== storedAuto ||
449
+ minutes !== storedMinutes ||
450
+ freeze !== storedFreeze ||
451
+ backfill !== storedBackfill ||
452
+ nameChars !== storedNameChars ||
453
+ recentMessages !== storedRecent
454
+
455
+ const row = (key, title, desc, control, column = false) =>
456
+ h(
457
+ 'div',
458
+ { key, style: column ? SETTINGS_STYLE.rowColumn : SETTINGS_STYLE.row },
459
+ h('div', { style: SETTINGS_STYLE.text }, h('div', { style: SETTINGS_STYLE.label }, title), desc ? h('div', { style: SETTINGS_STYLE.desc }, desc) : null),
460
+ control,
461
+ )
462
+
463
+ const segment = (options, value, onChange) =>
464
+ h(
465
+ 'div',
466
+ { style: SETTINGS_STYLE.seg, role: 'radiogroup' },
467
+ options.map((option) =>
468
+ h(
469
+ 'button',
470
+ {
471
+ key: option.value,
472
+ type: 'button',
473
+ role: 'radio',
474
+ 'aria-checked': value === option.value,
475
+ disabled: !writable || busy,
476
+ onClick: () => onChange(option.value),
477
+ style: { ...SETTINGS_STYLE.segButton, ...(value === option.value ? SETTINGS_STYLE.segButtonOn : {}) },
478
+ },
479
+ option.label,
480
+ ),
481
+ ),
482
+ )
483
+
484
+ const toggle = (checked, onChange, label) =>
485
+ h(
486
+ 'button',
487
+ { type: 'button', role: 'switch', 'aria-checked': checked, 'aria-label': label, disabled: !writable || busy, onClick: () => onChange(!checked), style: SETTINGS_STYLE.switch(checked) },
488
+ h('span', { style: SETTINGS_STYLE.thumb(checked) }),
489
+ )
490
+
491
+ const number = (value, onChange, min, max) =>
492
+ h(
493
+ 'div',
494
+ { style: SETTINGS_STYLE.num },
495
+ h('input', { type: 'number', min, max, value, disabled: !writable || busy, onChange: (event) => onChange(event.target.value), style: { ...SETTINGS_STYLE.input, ...SETTINGS_STYLE.number } }),
496
+ )
497
+
498
+ const save = async () => {
499
+ if (busy) return
500
+ setSaveState('saving')
501
+ const parsedMinutes = Math.max(0, Math.min(3600000, Math.round(Number.parseInt(minutes, 10) || 0) * 60000))
502
+ const parsedFreeze = Math.max(0, Math.min(100000, Number.parseInt(freeze, 10) || 0))
503
+ const parsedName = Math.max(4, Math.min(40, Number.parseInt(nameChars, 10) || 20))
504
+ const parsedRecent = Math.max(2, Math.min(20, Number.parseInt(recentMessages, 10) || 8))
505
+ const nextTemplate = template.trim() === '' ? DEFAULT_TEMPLATE : template.trim()
506
+ try {
507
+ const ok = await form.mutate(
508
+ [
509
+ { op: 'set', path: ['categoryPreset'], value: categoryPreset },
510
+ { op: 'set', path: ['categoryEmoji'], value: categoryEmoji },
511
+ { op: 'set', path: ['dateFormat'], value: dateFormat },
512
+ { op: 'set', path: ['template'], value: nextTemplate },
513
+ { op: 'set', path: ['refreshOnTurnEnd'], value: autoRefresh },
514
+ { op: 'set', path: ['refreshMinIntervalMs'], value: parsedMinutes },
515
+ { op: 'set', path: ['refreshMaxTurns'], value: parsedFreeze },
516
+ { op: 'set', path: ['backfillOnStart'], value: backfill },
517
+ { op: 'set', path: ['maxNameChars'], value: parsedName },
518
+ { op: 'set', path: ['recentMessages'], value: parsedRecent },
519
+ ],
520
+ snapshot.revision,
521
+ )
522
+ setSaveState(ok === false ? 'failed' : 'saved')
523
+ } catch {
524
+ setSaveState('failed')
525
+ }
526
+ }
527
+
528
+ const restore = () => {
529
+ setCategoryPreset('zh')
530
+ setCategoryEmoji(false)
531
+ setDateFormat('MMDD')
532
+ setTemplate(DEFAULT_TEMPLATE)
533
+ setAutoRefresh(true)
534
+ setMinutes('2')
535
+ setFreeze('100')
536
+ setBackfill(false)
537
+ setNameChars('20')
538
+ setRecentMessages('8')
539
+ setSaveState('idle')
540
+ }
541
+
542
+ if (snapshot.status === 'loading') return h('div', { style: SETTINGS_STYLE.desc }, readText('loading'))
543
+ if (snapshot.status === 'unavailable') return h('div', { style: SETTINGS_STYLE.desc }, readText('unavailable'))
544
+
545
+ const preview = sample(categoryPreset, categoryEmoji, dateFormat, template)
546
+ return h(
547
+ 'div',
548
+ { style: SETTINGS_STYLE.page },
549
+ h('h2', { style: SETTINGS_STYLE.h2 }, readText('title')),
550
+ h('p', { style: SETTINGS_STYLE.intro }, readText('intro')),
551
+ h(
552
+ 'div',
553
+ { style: SETTINGS_STYLE.preview },
554
+ h('div', { style: SETTINGS_STYLE.previewLabel }, readText('preview')),
555
+ h('div', { style: SETTINGS_STYLE.previewTitle }, preview),
556
+ ),
557
+ h('div', { style: SETTINGS_STYLE.sectionTitle }, readText('format')),
558
+ row('preset', readText('categoryLanguage'), readText('categoryLanguageHint'),
559
+ segment([{ value: 'zh', label: '中文' }, { value: 'en', label: 'English' }], categoryPreset, setCategoryPreset)),
560
+ row('emoji', readText('categoryEmoji'), readText('categoryEmojiHint'), toggle(categoryEmoji, setCategoryEmoji, readText('categoryEmoji'))),
561
+ row('date', readText('dateFormat'), readText('dateFormatHint'),
562
+ segment([{ value: 'MMDD', label: 'MMDD' }, { value: 'YYMM', label: 'YYMM' }, { value: 'YYYYMMDD', label: 'YYYYMMDD' }], dateFormat, setDateFormat)),
563
+ row('template', readText('template'), readText('templateHint'),
564
+ h('input', { value: template, disabled: !writable || busy, onChange: (event) => setTemplate(event.target.value), spellCheck: false, style: { ...SETTINGS_STYLE.input, ...SETTINGS_STYLE.fullInput } }), true),
565
+ h('div', { style: SETTINGS_STYLE.sectionTitle }, readText('auto')),
566
+ row('auto', readText('autoRefresh'), readText('autoRefreshHint'), toggle(autoRefresh, setAutoRefresh, readText('autoRefresh'))),
567
+ row('minutes', readText('minInterval'), readText('minIntervalHint'), number(minutes, setMinutes, 0, 60)),
568
+ row('freeze', readText('freeze'), readText('freezeHint'), number(freeze, setFreeze, 0, 100000)),
569
+ row('backfill', readText('backfill'), readText('backfillHint'), toggle(backfill, setBackfill, readText('backfill'))),
570
+ h(
571
+ 'button',
572
+ { type: 'button', style: SETTINGS_STYLE.advanced, onClick: () => setAdvancedOpen((value) => !value) },
573
+ h('span', { style: { fontSize: 10, transform: advancedOpen ? 'rotate(90deg)' : 'rotate(-90deg)', display: 'inline-block' } }, '▼'),
574
+ readText('advanced'),
575
+ ),
576
+ advancedOpen
577
+ ? h('div', null,
578
+ row('nameChars', readText('nameLimit'), readText('nameLimitHint'), number(nameChars, setNameChars, 4, 40)),
579
+ row('recent', readText('recentMessages'), readText('recentMessagesHint'), number(recentMessages, setRecentMessages, 2, 20)),
580
+ h('div', { style: { ...SETTINGS_STYLE.desc, marginTop: '8px' } }, readText('advancedHint')),
581
+ )
582
+ : null,
583
+ h(
584
+ 'div',
585
+ { style: SETTINGS_STYLE.footer },
586
+ h('button', { type: 'button', style: SETTINGS_STYLE.restore, disabled: !writable || busy, onClick: restore }, readText('restore')),
587
+ h('span', { style: { ...SETTINGS_STYLE.status, color: saveState === 'failed' ? 'var(--dsw-alias-state-error-primary, #f87171)' : 'var(--dsw-alias-state-success-primary, #65d39a)' } }, saveState === 'saved' ? readText('saved') : saveState === 'failed' ? readText('failed') : ''),
588
+ dirty && saveState !== 'saved' ? h('span', { style: { ...SETTINGS_STYLE.desc, marginTop: 0 } }, readText('dirty')) : null,
589
+ writable ? null : h('span', { style: { ...SETTINGS_STYLE.desc, marginTop: 0 } }, readText('readOnly')),
590
+ h('button', { type: 'button', style: { ...SETTINGS_STYLE.save, opacity: writable && !busy ? 1 : 0.4, cursor: writable && !busy ? 'pointer' : 'default' }, disabled: !writable || busy, onClick: () => void save() }, busy ? readText('saving') : readText('save')),
591
+ ),
592
+ )
593
+ }
594
+ }
595
+
596
+ function registerSettingsPage(ctx, t) {
597
+ try {
598
+ if (typeof ctx.inject !== 'function') return
599
+ ctx.inject(['configForms', 'slots'], (scope) => {
600
+ try {
601
+ const Section = buildSettingsSection(React, scope.configForms, t, ctx)
602
+ scope.slots.inject('settings.section', () => scope.slots.register({
603
+ name: 'settings.section',
604
+ id: NS,
605
+ order: 60,
606
+ label: () => t('settings.nav'),
607
+ }, Section))
608
+ } catch (error) {
609
+ console.warn('session-title-stamp: settings page unavailable', error)
610
+ }
611
+ })
612
+ } catch (error) {
613
+ console.warn('session-title-stamp: settings page unavailable', error)
614
+ }
615
+ }
616
+
260
617
  const STYLE_ID = 'dsh-session-title-stamp-style'
261
618
 
262
619
 
@@ -278,6 +635,7 @@ window.__ModuleLoader__.load({
278
635
  installStyle(ctx)
279
636
  ctx.effect?.(() => ctx.locale.register(NS, DICT))
280
637
  const t = ctx.locale.bind(NS)
638
+ registerSettingsPage(ctx, t)
281
639
  const run = async (sessionId) => {
282
640
  const response = await ctx.remote.commands.execute(sessionId, '/retitle', [])
283
641
  if (!response?.ok) {
Binary file
package/lib/index.js CHANGED
@@ -12,6 +12,7 @@
12
12
  * without one cannot leave this entry pending and hold up startup.
13
13
  */
14
14
 
15
+ import Schema from '@deepseek-ai/schemastery'
15
16
  import { readFile } from 'node:fs/promises'
16
17
  import { homedir } from 'node:os'
17
18
  import { join } from 'node:path'
@@ -30,6 +31,83 @@ import {
30
31
  textFromResponse,
31
32
  } from './format.js'
32
33
 
34
+ const PrefsSchema = Schema.object({
35
+ categoryPreset: Schema.union([Schema.const('zh'), Schema.const('en')])
36
+ .default('zh')
37
+ .description('分类词表语言:zh 中文 / en English'),
38
+ categoryEmoji: Schema.boolean()
39
+ .default(false)
40
+ .description('给分类加 emoji 前缀,例如 ⚡ 优化'),
41
+ dateFormat: Schema.union([Schema.const('MMDD'), Schema.const('YYMM'), Schema.const('YYYYMMDD')])
42
+ .default('MMDD')
43
+ .description('{date} 使用日期格式'),
44
+ template: Schema.string()
45
+ .default('{date} | {type} | {topic}')
46
+ .description('标题模板'),
47
+ refreshOnTurnEnd: Schema.boolean()
48
+ .default(true)
49
+ .description('回答完成后自动重算标题'),
50
+ refreshMinIntervalMs: Schema.natural()
51
+ .default(120000)
52
+ .description('自动重算最小间隔(毫秒)'),
53
+ refreshMaxTurns: Schema.natural()
54
+ .default(100)
55
+ .description('超过多少条用户消息后停止自动重算,0 表示不冻结'),
56
+ backfillOnStart: Schema.boolean()
57
+ .default(false)
58
+ .description('启动时补刷仍为兜底标题的 live 会话'),
59
+ maxNameChars: Schema.natural()
60
+ .default(20)
61
+ .description('名称最大字符数'),
62
+ recentMessages: Schema.natural()
63
+ .default(8)
64
+ .description('标题请求包含的最近消息数'),
65
+ })
66
+
67
+ const LimitsSchema = Schema.object({
68
+ categories: Schema.array(Schema.string())
69
+ .default([])
70
+ .hidden(true)
71
+ .description('自定义分类词表,覆盖 categoryPreset'),
72
+ maxTitleBytes: Schema.natural().default(80).hidden(true),
73
+ maxInputBytes: Schema.natural().default(4096).hidden(true),
74
+ maxOutputTokens: Schema.natural().default(4096).hidden(true),
75
+ timeoutMs: Schema.natural().default(90000).hidden(true),
76
+ provider: Schema.string().default('').hidden(true),
77
+ model: Schema.string().default('').hidden(true),
78
+ timeZone: Schema.string().default('').hidden(true),
79
+ backfillMaxSessions: Schema.natural().default(30).hidden(true),
80
+ backfillIntervalMs: Schema.natural().default(2000).hidden(true),
81
+ retitleEvery: Schema.natural().default(10).hidden(true),
82
+ cadence: Schema.union([Schema.const('first-prompt'), Schema.const('all-prompts')]).hidden(true),
83
+ })
84
+
85
+ /** Every preference is live-editable from the settings page. */
86
+ const volatilePrefs = Object.fromEntries(
87
+ Object.entries(PrefsSchema.dict ?? {}).map(([key, field]) => [key, field.volatile()]),
88
+ )
89
+
90
+ /** Config schema: live preferences plus the deployment limits the form hides. */
91
+ export const Config = Schema.object({
92
+ ...volatilePrefs,
93
+ ...LimitsSchema.dict,
94
+ })
95
+
96
+ /** The protocol symbol a parsed volatile field carries. */
97
+ const VOLATILE_WRITE = Symbol.for('cosmokit.volatile.write')
98
+
99
+ function readField(value) {
100
+ if (value !== null && typeof value === 'object' && VOLATILE_WRITE in value && typeof value.get === 'function') {
101
+ return value.get()
102
+ }
103
+ return value
104
+ }
105
+
106
+ function readConfig(config) {
107
+ const source = config !== null && typeof config === 'object' ? config : {}
108
+ return Object.fromEntries(Object.entries(source).map(([key, value]) => [key, readField(value)]))
109
+ }
110
+
33
111
  const PROVIDER_ID = 'title-stamp'
34
112
  const EXECUTOR_SPECIFIER = '@deepseek-ai/dsh-session-title-llm'
35
113
  const MAX_TRACKED_SESSIONS = 64
@@ -357,7 +435,8 @@ function scheduleBackfill(ctx, settings, logger, shouldStop) {
357
435
  */
358
436
  export function apply(ctx, config) {
359
437
  const serviceMaxBytes = Number(ctx.sessionTitle?.config?.maxTitleBytes)
360
- const settings = resolveSettings(config, serviceMaxBytes)
438
+ const settingsNow = () => resolveSettings(readConfig(config), serviceMaxBytes)
439
+ const settings = settingsNow()
361
440
  const logger = ctx.logger
362
441
  let stopped = false
363
442
 
@@ -384,6 +463,7 @@ export function apply(ctx, config) {
384
463
  // duplicate title event on every single user message.
385
464
  automatic: 'first-prompt',
386
465
  async generate(request) {
466
+ const settings = settingsNow()
387
467
  const startedAt = Date.now()
388
468
  const used = selectMessages(request?.messages, settings)
389
469
  if (used.length === 0) {
@@ -520,6 +600,7 @@ export function apply(ctx, config) {
520
600
  if (reasonKind(event.data?.reason) !== 'completed') return
521
601
  if (isExcluded(session)) return
522
602
 
603
+ const settings = settingsNow()
523
604
  const count = counts.get(session.id) ?? countUserMessages(session)
524
605
  if (count <= 0) return
525
606
  if (settings.refreshMaxTurns > 0 && count > settings.refreshMaxTurns) return
package/market/index.json CHANGED
@@ -34,8 +34,8 @@
34
34
  "zh": "会话标题印章"
35
35
  },
36
36
  "description": {
37
- "en": "Keeps DSH session titles in DATE | CATEGORY | NAME with turn-aware auto-retitle, a Generate title action, and hover cost/duration.",
38
- "zh": "把 DSH 会话标题固定为「日期 | 分类 | 名称」,支持回答后自动重算、自动生成标题和悬停成本/耗时。"
37
+ "en": "Keeps DSH session titles in DATE | CATEGORY | NAME with turn-aware auto-retitle, a settings page, manual generation, and hover cost/duration.",
38
+ "zh": "把 DSH 会话标题固定为「日期 | 分类 | 名称」,支持回答后自动重算、设置页、手动生成和悬停成本/耗时。"
39
39
  },
40
40
  "author": "xuedipiaofei",
41
41
  "icon": "../icon.svg",
@@ -57,12 +57,12 @@
57
57
  },
58
58
  "versions": [
59
59
  {
60
- "version": "0.6.0",
61
- "publishTimestamp": 1793714709,
60
+ "version": "0.7.0",
61
+ "publishTimestamp": 1793721856,
62
62
  "source": {
63
63
  "type": "git",
64
64
  "url": "https://github.com/xuedipiaofei/dsh-session-title-stamp",
65
- "commit": "cfe08afebb3fd605cdb0af44acf22d8906bba400"
65
+ "commit": "e46d3544174626f922a2c1749bb300db93d01d04"
66
66
  },
67
67
  "engines": {
68
68
  "dsh": ">=0.2.1-rc.3 <0.3.0"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-session-title-stamp",
3
- "version": "0.6.0",
4
- "description": "DSH session titles in a DATE | CATEGORY | NAME template, with turn-aware auto-generation, a Generate title button, and hover cost/duration.",
3
+ "version": "0.7.0",
4
+ "description": "DSH session titles in a DATE | CATEGORY | NAME template, with turn-aware auto-generation, a settings page, a Generate title button, and hover cost/duration.",
5
5
  "keywords": [
6
6
  "dsh",
7
7
  "dsh-plugin",
@@ -34,13 +34,15 @@
34
34
  "market/index.json",
35
35
  "icon.svg",
36
36
  "README.md",
37
- "README.zh.md"
37
+ "README.zh.md",
38
+ "docs/0.7.0-settings-mock.png"
38
39
  ],
39
40
  "engines": {
40
41
  "dsh": ">=0.2.1-rc.3 <0.3.0"
41
42
  },
42
43
  "peerDependencies": {
43
- "@deepseek-ai/dsh-session-title-llm": "^0.2.1-rc.3"
44
+ "@deepseek-ai/dsh-session-title-llm": "^0.2.1-rc.3",
45
+ "@deepseek-ai/schemastery": "^3.18.5"
44
46
  },
45
47
  "dsh": {
46
48
  "bundle": {
@@ -62,9 +64,12 @@
62
64
  "access": "public"
63
65
  },
64
66
  "scripts": {
65
- "test": "node --check client.js && node test/format.test.mjs && node test/provider.test.mjs && node test/client.test.mjs && node scripts/check.mjs",
67
+ "test": "node --check client.js && node test/format.test.mjs && node test/provider.test.mjs && node test/client.test.mjs && node test/config.test.mjs && node scripts/check.mjs",
66
68
  "check": "node scripts/check.mjs",
67
69
  "validate:index": "node scripts/validate-index.mjs",
68
70
  "pack:check": "npm pack --dry-run"
71
+ },
72
+ "devDependencies": {
73
+ "@deepseek-ai/schemastery": "^3.18.5"
69
74
  }
70
75
  }