dsh-progress-union 0.1.7 → 0.1.9

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/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
4
 
5
+ ## 0.1.8 (2026-11-26)
6
+
7
+ **修复:registered 通道写错 DSH LLM 契约;配置面搬回宿主设置页。**
8
+
9
+ - 事故:registered 模式把 system prompt 塞进 `messages[{role:'system'}]`、content 又传裸字符串,而 `llm.stream` 的 `GenerateOptions.system` 才是 adapter 映射到 provider system 槽的字段 → 请求实际没有 system,DeepSeek 回落到内置 “You are a helpful assistant.” 并把它当正文返回,`parseProposal` 失败只剩 `proposal-unparsable`(旧测试把 chunk 桩成 `{content}`,跟着一起错,没能拦住)。
10
+ - 修复:改为 `system: ASSISTANT_SYSTEM` + `messages: [{ role: 'user', content: [{ type: 'text', text }] }]`,chunk 只认 `type === 'text-delta'`,`finish.reason` 非 stop/max-tokens 直接报错,空正文报 `assistant-empty`;并透传 `signal`。
11
+ - 回归测试:锁定 system 必须在 `options.system`、`messages` 不得出现 `role:system`、content 必须是块数组。
12
+ - 设置面:`Config.assistant` 改为**逐叶子 `.volatile()`**(整对象标 volatile 不会生成字段表单——这就是「设置 → 插件」里看不到辅助 LLM 配置的原因);侧边栏不再放编辑表单,只留只读状态并指向设置页;新增「live ref 逐字段重读」测试。
13
+
14
+ ## 0.1.9 (2026-11-26)
15
+
16
+ **设置面真正落地:顶层 settings.section + configForms 三组卡片。**
17
+
18
+ - 上一版只标了 schema 的 volatile,仍无入口——宿主不会凭导出的 `Config` 自动生成表单,设置面必须由**客户端**注册到 `settings.section` 槽(与 dsh-browser-cdp / dsh-spirit 同式)。
19
+ - 新增独立分节「进度板」(id `dsh-progress-union`,order 215),卡内三组:
20
+ - 辅助 LLM:mode / provider / model / baseUrl / apiKey / authority / minIntervalMs / autoApply;
21
+ - 观察者:enabled / maxIdleSteps / maxIdleMs / autoSyncCurrent / autoSyncThrottleMs / maxItems;
22
+ - API(只读):`progressAnchor` service、`/progress-anchor`、`/snapshot`、`/dsh-progress/status` 三条 HTTP。
23
+ - 数据臂走宿主原生 `configForms.get(entryId)` 句柄(subscribe / getSnapshot / set,写值带 revision);宿主无该服务时卡内显示只读提示,不静默丢入口。
24
+ - `Config` 增 `protocolHint` 与 `observer.*` 叶子级 volatile;`apply` 对 `cfg.observer` / `cfg.protocolHint` 改用 getter 解包 live ref → 设置页改阈值立即生效。
25
+ - 侧边栏保持只读状态行(编辑统一留在设置页,避免两处写同一命名空间)。
26
+ - 测试:新增 3 条设置面契约守卫(逐叶子 volatile、外层不标、客户端注册 settings.section + configForms),共 51 用例全绿。
27
+
5
28
  > 说明:0.1.0 是真实构建产物;0.1.1–0.1.6 由 0.1.0 → 最终态的可核验 diff 按功能块「逻辑分化重建」,每一版都只包含该版本描述的能力,源码逐版可执行;0.1.7 是发布工程面。
6
29
 
7
30
  ## 0.1.7 (2026-11-26)
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm i dsh-progress-union # 走 npm 版本号
14
14
  # 或本地开发:pnpm --dir <profile> add file:<repo>/dsh-progress-union-<ver>.tgz
15
15
  ```
16
16
 
17
- 装好后在 profile 的 `dsh.profile.bundles` 里挂上 `dsh-progress-union`,重启宿主加载;设置面在「设置 → 插件 → progress-union」。
17
+ 装好后在 profile 的 `dsh.profile.bundles` 里挂上 `dsh-progress-union`,重启宿主加载;**所有配置面在设置页的独立分节「进度板」**(与记忆 / 模型 / 插件并列,由客户端注册 `settings.section` 槽、经宿主 `configForms` 读写,改完即生效、无需重启);也可在 profile 的 `cordis.patch.yml` 里写 `config:` 作部署面默认值。
18
18
 
19
19
  ## 它解决什么
20
20
 
@@ -118,27 +118,30 @@ observer:
118
118
 
119
119
  ## 辅助 LLM(审查/监视进度)
120
120
 
121
- 观察者默认是**规则版(零 LLM 费用)**。可选的辅助模型会把"清单 + 最近输出 + 最近动作 + 最近改动"交给一个小模型做审查,只让它校准 `current / next / percent`:
121
+ 观察者默认是**规则版(零 LLM 费用)**。可选的辅助模型会把"清单 + 最近输出 + 最近动作 + 最近改动"交给一个小模型做审查:
122
+
123
+ **配置位置:设置 → 进度板**(分节内三组:辅助 LLM / 观察者 / 只读 API;观察者的滞后阈值也在这张卡里)。
122
124
 
123
125
  ```yaml
124
126
  assistant:
125
- mode: direct # '' 关(默认)| 'direct'
126
- baseUrl: http://127.0.0.1:8000/v1
127
- model: qwen2.5-3b # 小模型即可
128
- apiKey: '' # 可选;快照只回布尔 hasApiKey
129
- timeoutMs: 20000
127
+ mode: '' # '' 关(默认)| 'registered' | 'direct'
128
+ provider: local-35b # registered:Settings→模型 里的 provider 名(走宿主 llm.stream,免密钥)
129
+ model: qwen2.5-3b # registered/direct 共用的模型 id
130
+ baseUrl: http://127.0.0.1:8000/v1 # direct 专用
131
+ apiKey: '' # direct 专用;快照只回布尔 hasApiKey
132
+ authority: both # slots | rounds | both
130
133
  minIntervalMs: 90000 # 两次审查的最小间隔
131
- maxCallsPerTurn: 1 # 每回合至多一次
132
134
  autoApply: true # false = 只记录建议不落地
133
135
  ```
134
136
 
137
+ - **两条通道**:`registered` 走宿主 `llm.stream`(复用 Settings→模型 里已配好的 provider/model,无需另存密钥;system prompt 走 `options.system`,输入走 `ContentBlock[]`);`direct` 直连自建 OpenAI 兼容端点;
135
138
  - **触发**:板有未完成项,且主模型滞后(`maxIdleSteps`/`maxIdleMs` 超阈值)——与催办/自补同一时机,不额外打扰;
136
- - **硬约束**:只改 `current/next/percent`;不存在的 id 丢弃;**不增删任务、不改 title/status**;每回合配额 + 最小间隔双节流;失败静默(`assistantError` 入观察块,不阻断板与主流程);
139
+ - **职责**:按 `authority` 可增删改槽位(≤8 条/次,用户未确认改动优先)并产出轮次草案(仅建议,判断权归主模型);每回合配额 + 最小间隔双节流;失败静默(`assistantError` 入观察块,不阻断板与主流程);
137
140
  - **产出**:落地项 `updatedBy=assistant`;审查结论一行进观察块:`助手审查:<note>`;
138
- - **端点建议**:优先本地/局域网自建 OpenAI 兼容端点(Ollama、LM Studio、自建 llama.cpp、vLLM、SGLang、Strata、Ninfer 等),也就是面板首区块那条提示的含义;
139
- - 面板侧边栏与全展开两个视图的**第一个内容块**都显示该通道状态(未启用/已启用 + 端点 + 频率),即本插件的"费用提示永远第一"落点。
141
+ - **端点建议**:`direct` 优先本地/局域网自建 OpenAI 兼容端点(Ollama、LM Studio、自建 llama.cpp、vLLM、SGLang、Strata、Ninfer 等);
142
+ - 侧边栏与全展开两个视图的**第一个内容块**只做只读状态展示(未启用/已启用 + 端点 + 频率)并指向设置页,**不再放编辑表单**——配置单挂在宿主设置面,避免两处写同一命名空间。
140
143
 
141
- **为什么不做 host 通道**:union 是纯宿主插件,没有取得宿主 chat 调用的公开面;`direct` 是唯一不靠内部 API 的可靠路径,也正好对应"本地小模型"的推荐用法。
144
+ **为什么不做 host 通道**:union 自身不直接持有宿主 chat 会话;`registered` 只借 `llm.stream` 一次性调用(不走主对话),`direct` 则完全不依赖宿主内部 API,两路都只拿回一段 JSON,不触碰会话历史。
142
145
 
143
146
  ## 明确不做
144
147
 
@@ -155,5 +158,5 @@ assistant:
155
158
  ## 开发与测试
156
159
 
157
160
  ```bash
158
- npm test # node --test test/*.test.mjs(47 用例,纯 mock ctx,无需宿主进程)
161
+ npm test # node --test test/*.test.mjs(51 用例,纯 mock ctx,无需宿主进程)
159
162
  ```
package/client.js CHANGED
@@ -18,23 +18,8 @@ window.__ModuleLoader__.load({
18
18
  window.dispatchEvent(new CustomEvent(PROGRESS_EVENT, { detail: { sessionId, snapshot } }))
19
19
  }
20
20
 
21
- // 辅助 LLM 可编辑设置:settingsScope.bind({namespace})(0.1.7+)或 configForms.get(ns)(旧)。
22
- // 通过 ctx.inject 软注入,拿不到时 scopeOf 恒 undefined,面板退化为只读提示。
23
- let scopeOf = undefined
24
- function installSettingsScope(ctx) {
25
- const tryInject = (deps, pick) => {
26
- try {
27
- ctx.inject(deps, (scope) => {
28
- const src = scope && pick(scope)
29
- if (src === undefined) return
30
- if (typeof src.bind === 'function') scopeOf = (ns) => src.bind({ namespace: ns })
31
- else if (typeof src.get === 'function') scopeOf = (ns) => src.get(ns)
32
- })
33
- } catch (_err) {}
34
- }
35
- tryInject(['settingsScope'], (s) => s.settingsScope)
36
- tryInject(['configForms'], (s) => s.configForms)
37
- }
21
+ // 辅助 LLM 的配置面不在客户端:宿主设置页(设置 → 插件 → dsh-progress-union)
22
+ // 按插件导出的 Config 逐叶子 .volatile() 自动生成表单,本面板只做只读状态展示。
38
23
 
39
24
  /*
40
25
  * DeepSeek list prices in CNY per 1M tokens (api-docs.deepseek.com,
@@ -228,25 +213,46 @@ window.__ModuleLoader__.load({
228
213
  llmOn: '已启用',
229
214
  llmOff: '未启用:观察者为规则版(零 LLM 费用)。启用后由辅助模型管理任务槽位、产出续轮建议。',
230
215
  llmAuto: ',自动落地',
231
- llmHint: '选「已注册」复用 Settings→模型里的 provider/model(走宿主,免密钥);或「直连」自建 OpenAI 兼容端点。仅滞后时触发,每回合至多一次。助手可增删改槽位并产出轮次草案(仅供参考),判断权归主模型。',
232
- llmMode: '模式',
233
- llmModeOff: '关闭',
234
- llmModeRegistered: '已注册 provider',
235
- llmModeDirect: '直连端点',
236
- llmProvider: '提供方',
237
- llmModel: '模型',
238
- llmBaseUrl: '端点地址',
239
- llmApiKey: 'API 密钥',
240
- llmAuthority: '权限',
241
- llmAuthoritySlots: '管理槽位',
242
- llmAuthorityRounds: '轮次草案',
243
- llmAuthorityBoth: '两者',
244
- llmPickModel: '选择模型…',
245
- llmNoProviders: 'Settings→模型 里没有已配置的 provider/model',
246
- llmSave: '保存',
247
- llmSaved: '已保存',
248
- llmSaveFail: '保存失败',
249
- llmResult: '结果',
216
+ llmHint: '配置在「设置 → 插件 → dsh-progress-union」:mode 选 registered 复用 Settings→模型 里的 provider/model(走宿主,免密钥),或 direct 直连自建 OpenAI 兼容端点。仅滞后时触发,每回合至多一次。助手可增删改槽位并产出轮次草案(仅供参考),判断权归主模型。',
217
+ llmSettingsHint: '在设置页修改',
218
+ setTitle: '进度板',
219
+ setLlmGroup: '辅助 LLM(监控/审查)',
220
+ setLlmHint: '选「已注册」复用 Settings→模型 里的 provider/model(走宿主 llm.stream,免密钥);「直连」打自建 OpenAI 兼容端点。仅在进度板滞后时触发,每回合至多一次。',
221
+ setObserverGroup: '观察者(监控)',
222
+ setObserverHint: '板滞后到什么程度才催办/审查;关掉自动同步后只做提醒,不改 current。',
223
+ setApiGroup: 'API(只读)',
224
+ setApiHint: '同一 builder 双平面出口:进程内 service + HTTP,供压缩类插件只读消费。',
225
+ setMode: '模式',
226
+ setModeOff: '关闭',
227
+ setModeRegistered: '已注册 provider',
228
+ setModeDirect: '直连端点',
229
+ setProvider: '提供方',
230
+ setProviderHint: 'Settings→模型 里的 provider 名(registered 必填)',
231
+ setModel: '模型',
232
+ setBaseUrl: '端点地址',
233
+ setApiKey: 'API 密钥',
234
+ setApiKeyHint: '只写不回显;保存后快照只回布尔 hasApiKey',
235
+ setAuthority: '助手权限',
236
+ setAuthorityBoth: '槽位 + 轮次草案',
237
+ setAuthoritySlots: '只管理槽位',
238
+ setAuthorityRounds: '只产轮次草案',
239
+ setInterval: '最小间隔(毫秒)',
240
+ setIntervalHint: '两次审查之间的最小间隔,默认 90000',
241
+ setAutoApply: '自动落地槽位',
242
+ setObserverEnabled: '启用观察者',
243
+ setMaxIdleSteps: '滞后步数阈值',
244
+ setMaxIdleMs: '滞后时长阈值(毫秒)',
245
+ setAutoSyncCurrent: '自动同步 current',
246
+ setAutoSyncThrottleMs: '自动同步节流(毫秒)',
247
+ setMaxItems: '清单条目上限',
248
+ setSaved: '已保存',
249
+ setFailed: '保存失败',
250
+ setReadOnly: '当前 config 不可写',
251
+ setNoScope: '此宿主未提供设置写入面(configForms),只能从 profile 的 cordis.patch.yml 改配置。',
252
+ setApiService: 'service',
253
+ setApiAnchor: 'HTTP',
254
+ setApiSnapshot: '快照',
255
+ setApiStatus: '迷你条状态',
250
256
  etaLeft: '预计剩',
251
257
  etaOver: '已超预估',
252
258
  staleTag: '中断',
@@ -356,25 +362,46 @@ window.__ModuleLoader__.load({
356
362
  llmOn: 'Enabled',
357
363
  llmOff: 'Disabled: the observer is rule-based (zero LLM cost). When enabled, the assistant manages task slots and produces round suggestions.',
358
364
  llmAuto: ', auto-applied',
359
- llmHint: 'Use "Registered" to reuse a provider/model from Settings → Models (via host, no API key needed), or "Direct" for a self-hosted OpenAI-compatible endpoint. Triggered only while overdue, at most once per turn. The assistant may add/edit/remove slots and emit round suggestions (advice only); the main model decides.',
360
- llmMode: 'Mode',
361
- llmModeOff: 'Off',
362
- llmModeRegistered: 'Registered provider',
363
- llmModeDirect: 'Direct endpoint',
364
- llmProvider: 'Provider',
365
- llmModel: 'Model',
366
- llmBaseUrl: 'Endpoint URL',
367
- llmApiKey: 'API key',
368
- llmAuthority: 'Authority',
369
- llmAuthoritySlots: 'Manage slots',
370
- llmAuthorityRounds: 'Round draft',
371
- llmAuthorityBoth: 'Both',
372
- llmPickModel: 'Pick a model…',
373
- llmNoProviders: 'No configured provider/model under Settings → Models',
374
- llmSave: 'Save',
375
- llmSaved: 'Saved',
376
- llmSaveFail: 'Save failed',
377
- llmResult: 'Result',
365
+ llmHint: 'Configure in Settings → Plugins → dsh-progress-union: set mode=registered to reuse a provider/model from Settings → Models (via host, no API key), or mode=direct for a self-hosted OpenAI-compatible endpoint. Triggered only while overdue, at most once per turn. The assistant may add/edit/remove slots and emit round suggestions (advice only); the main model decides.',
366
+ llmSettingsHint: 'Change in Settings',
367
+ setTitle: 'Progress board',
368
+ setLlmGroup: 'Assistant LLM (monitor/audit)',
369
+ setLlmHint: 'Pick "Registered" to reuse a provider/model from Settings → Models (via host llm.stream, no API key), or "Direct" for a self-hosted OpenAI-compatible endpoint. Runs only while the board is overdue, at most once per turn.',
370
+ setObserverGroup: 'Observer (monitoring)',
371
+ setObserverHint: 'How overdue the board must be before nudging/auditing; once auto-sync is off the observer only reminds and never edits current.',
372
+ setApiGroup: 'API (read-only)',
373
+ setApiHint: 'One builder, two planes: in-process service plus HTTP, consumed read-only by compaction plugins.',
374
+ setMode: 'Mode',
375
+ setModeOff: 'Off',
376
+ setModeRegistered: 'Registered provider',
377
+ setModeDirect: 'Direct endpoint',
378
+ setProvider: 'Provider',
379
+ setProviderHint: 'Provider name under Settings → Models (required for registered)',
380
+ setModel: 'Model',
381
+ setBaseUrl: 'Endpoint URL',
382
+ setApiKey: 'API key',
383
+ setApiKeyHint: 'Write-only; the snapshot only reports hasApiKey',
384
+ setAuthority: 'Assistant authority',
385
+ setAuthorityBoth: 'Slots + round draft',
386
+ setAuthoritySlots: 'Slots only',
387
+ setAuthorityRounds: 'Round draft only',
388
+ setInterval: 'Min interval (ms)',
389
+ setIntervalHint: 'Minimum gap between two audits, default 90000',
390
+ setAutoApply: 'Auto-apply slot changes',
391
+ setObserverEnabled: 'Enable observer',
392
+ setMaxIdleSteps: 'Overdue step threshold',
393
+ setMaxIdleMs: 'Overdue time threshold (ms)',
394
+ setAutoSyncCurrent: 'Auto-sync current',
395
+ setAutoSyncThrottleMs: 'Auto-sync throttle (ms)',
396
+ setMaxItems: 'Checklist item cap',
397
+ setSaved: 'Saved',
398
+ setFailed: 'Save failed',
399
+ setReadOnly: 'Current config is not writable',
400
+ setNoScope: 'This host exposes no settings write surface (configForms); edit the profile cordis.patch.yml instead.',
401
+ setApiService: 'service',
402
+ setApiAnchor: 'HTTP',
403
+ setApiSnapshot: 'Snapshot',
404
+ setApiStatus: 'Dock status',
378
405
  etaLeft: '~',
379
406
  etaOver: 'over by',
380
407
  staleTag: 'idle',
@@ -564,10 +591,20 @@ window.__ModuleLoader__.load({
564
591
  .pb-llm-title { font-size: 12px; font-weight: 650; }
565
592
  .pb-llm-line { margin-top: 4px; font-size: 12px; line-height: 1.5; }
566
593
  .pb-llm-hint { margin-top: 4px; font-size: 11px; line-height: 1.5; opacity: .75; }
567
- .pb-llm-editor { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(217,119,6,.25); display: grid; gap: 6px; }
568
- .pb-llm-field { display: flex; align-items: center; gap: 8px; font-size: 11px; }
569
- .pb-llm-field > span { flex: 0 0 72px; opacity: .8; }
570
- .pb-llm-field select, .pb-llm-field input { flex: 1; min-width: 0; padding: 3px 6px; font-size: 11px; border: 1px solid rgba(128,128,128,.4); border-radius: 4px; background: transparent; color: inherit; }
594
+ .pb-set { display: grid; gap: 14px; font-size: 12px; }
595
+ .pb-set-group { display: grid; gap: 8px; padding: 14px 16px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; }
596
+ .pb-set-group-title { font-size: 13px; font-weight: 650; }
597
+ .pb-set-group-hint { font-size: 11px; line-height: 1.5; opacity: .68; }
598
+ .pb-set-row { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 4px 12px; align-items: center; }
599
+ .pb-set-label { opacity: .85; }
600
+ .pb-set-control { min-width: 0; display: flex; gap: 6px; align-items: center; }
601
+ .pb-set-control > input[type="text"], .pb-set-control > input[type="password"], .pb-set-control > input[type="number"], .pb-set-control > select { flex: 1; min-width: 0; padding: 5px 8px; font: inherit; font-size: 12px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; background: transparent; color: inherit; }
602
+ .pb-set-control > input[type="checkbox"] { width: 15px; height: 15px; }
603
+ .pb-set-hint { grid-column: 2; font-size: 11px; line-height: 1.5; opacity: .65; }
604
+ .pb-set-banner { padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(217,119,6,.35); background: rgba(217,119,6,.08); font-size: 12px; line-height: 1.5; }
605
+ .pb-set-status { font-size: 12px; opacity: .75; }
606
+ .pb-set-api { display: grid; gap: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; opacity: .85; word-break: break-all; }
607
+ .pb-set-api b { font-weight: 600; opacity: .8; margin-right: 6px; }
571
608
  .pb-header-btn {
572
609
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
573
610
  border: 1px solid transparent; border-radius: 6px; background: transparent;
@@ -1488,105 +1525,195 @@ window.__ModuleLoader__.load({
1488
1525
  )
1489
1526
  }
1490
1527
 
1528
+ // 只读状态行:配置面归宿主设置页(设置 → 插件 → dsh-progress-union),
1529
+ // 侧边栏不再放编辑表单(避免两处写同一命名空间)。
1491
1530
  function LlmAssistNotice(props) {
1492
1531
  const t = makeT(props)
1493
1532
  const a = props.assistant
1494
- const cfg = props.assistantCfg
1495
- const [open, setOpen] = useState(false)
1496
- const [mode, setMode] = useState((a && a.mode) || '')
1497
- const [provider, setProvider] = useState((a && a.provider) || '')
1498
- const [model, setModel] = useState((a && a.model) || '')
1499
- const [baseUrl, setBaseUrl] = useState((a && a.baseUrl) || '')
1500
- const [apiKey, setApiKey] = useState('')
1501
- const [authority, setAuthority] = useState((a && a.authority) || 'both')
1502
- const [status, setStatus] = useState('')
1503
1533
  if (!a) return null
1504
1534
  const on = a.enabled === true
1505
- const providers = cfg && cfg.available ? cfg.providers() : []
1506
- const selectedProvider = providers.find((p) => p.name === provider)
1507
- const models = selectedProvider ? selectedProvider.models : []
1535
+ const every = Math.max(1, Math.round((a.minIntervalMs || 0) / 60000))
1536
+ const line = on
1537
+ ? (a.mode === 'registered'
1538
+ ? `${t('llmOn')}:${a.provider} · ${a.model}(≤${every} min/次${a.autoApply ? t('llmAuto') : ''})`
1539
+ : `${t('llmOn')}:${a.baseUrl} · ${a.model}(≤${every} min/次${a.autoApply ? t('llmAuto') : ''})`)
1540
+ : t('llmOff')
1541
+ return h(
1542
+ 'div',
1543
+ { className: on ? 'pb-llm' : 'pb-llm pb-llm-off' },
1544
+ h('div', { className: 'pb-llm-title' }, t('llmTitle')),
1545
+ h('div', { className: 'pb-llm-line' }, line),
1546
+ h('div', { className: 'pb-llm-hint' }, t('llmHint')),
1547
+ )
1548
+ }
1508
1549
 
1509
- const save = async () => {
1510
- if (!cfg || !cfg.available) { setStatus(t('llmSaveFail')); return }
1511
- const patch = { mode, provider, model, baseUrl, authority, apiKey }
1550
+ // ── 设置分节(顶层 settings.section,与 dsh-browser-cdp 同式)─────────────
1551
+ // 宿主不会凭导出的 Config 自动生成表单:设置面必须由客户端注册到
1552
+ // `settings.section` 槽,数据臂走宿主原生 `configForms` 句柄
1553
+ // (get(entryId) → subscribe/getSnapshot/set),写值带 revision、改完即生效。
1554
+ function unionFormsScope(ctx) {
1555
+ let forms
1556
+ try {
1557
+ forms = typeof ctx.get === 'function' ? ctx.get('configForms') : undefined
1558
+ } catch (_error) {
1559
+ forms = undefined
1560
+ }
1561
+ if (!forms || typeof forms.get !== 'function') return undefined
1562
+ // entry id 在 cordis.patch.yml 里是 `progress-union`,包名是 `dsh-progress-union`,两个都试。
1563
+ for (const id of ['progress-union', 'dsh-progress-union']) {
1564
+ let scope
1512
1565
  try {
1513
- await cfg.save(patch)
1514
- setStatus(t('llmSaved'))
1515
- if (apiKey) setApiKey('')
1516
- } catch (_err) {
1517
- setStatus(t('llmSaveFail'))
1566
+ scope = forms.get(id)
1567
+ } catch (_error) {
1568
+ scope = undefined
1518
1569
  }
1570
+ if (scope && typeof scope.getSnapshot === 'function' && typeof scope.subscribe === 'function' && typeof scope.set === 'function') return scope
1519
1571
  }
1572
+ return undefined
1573
+ }
1574
+
1575
+ function SettingsRow(props) {
1576
+ return h(
1577
+ 'label',
1578
+ { className: 'pb-set-row' },
1579
+ h('span', { className: 'pb-set-label' }, props.label),
1580
+ h('span', { className: 'pb-set-control' }, props.children),
1581
+ props.hint ? h('span', { className: 'pb-set-hint' }, props.hint) : null,
1582
+ )
1583
+ }
1584
+
1585
+ function SettingsGroup(props) {
1586
+ return h(
1587
+ 'section',
1588
+ { className: 'pb-set-group' },
1589
+ h('div', { className: 'pb-set-group-title' }, props.title),
1590
+ props.hint ? h('div', { className: 'pb-set-group-hint' }, props.hint) : null,
1591
+ props.children,
1592
+ )
1593
+ }
1594
+
1595
+ function ProgressUnionSettings(props) {
1596
+ const t = makeT(props)
1597
+ const scope = props.scope
1598
+ const [snap, setSnap] = useState(null)
1599
+ const [status, setStatus] = useState('')
1600
+ useEffect(() => {
1601
+ if (!scope) return undefined
1602
+ let alive = true
1603
+ const read = () => {
1604
+ if (!alive) return
1605
+ try {
1606
+ setSnap(scope.getSnapshot())
1607
+ } catch (_error) {
1608
+ // 句柄随时会随 entry 重载重建;读失败就保持上一帧
1609
+ }
1610
+ }
1611
+ read()
1612
+ let off
1613
+ try {
1614
+ off = scope.subscribe(read)
1615
+ } catch (_error) {
1616
+ off = undefined
1617
+ }
1618
+ return () => {
1619
+ alive = false
1620
+ if (typeof off === 'function') {
1621
+ try {
1622
+ off()
1623
+ } catch (_error) {
1624
+ // 卸载期失败无关紧要
1625
+ }
1626
+ }
1627
+ }
1628
+ }, [scope])
1520
1629
 
1521
- const select = (label, value, onChange, options) =>
1630
+ const value = (snap && snap.value) || {}
1631
+ const writable = Boolean(scope) && (!snap || snap.writable !== false)
1632
+ const assistant = value.assistant && typeof value.assistant === 'object' ? value.assistant : {}
1633
+ const observer = value.observer && typeof value.observer === 'object' ? value.observer : {}
1634
+
1635
+ const write = async (field, next) => {
1636
+ if (!scope) {
1637
+ setStatus(t('setNoScope'))
1638
+ return
1639
+ }
1640
+ if (!writable) {
1641
+ setStatus(t('setReadOnly'))
1642
+ return
1643
+ }
1644
+ try {
1645
+ const ok = await scope.set(field, next)
1646
+ setStatus(ok === false ? t('setFailed') : t('setSaved'))
1647
+ } catch (_error) {
1648
+ setStatus(t('setFailed'))
1649
+ }
1650
+ }
1651
+ const putAssistant = (key, v) => void write('assistant', { ...assistant, [key]: v })
1652
+ const putObserver = (key, v) => void write('observer', { ...observer, [key]: v })
1653
+
1654
+ const textOf = (v) => (v === undefined || v === null ? '' : String(v))
1655
+ const inputText = (v, onChange) => h('input', { type: 'text', value: textOf(v), onChange: (e) => onChange(e.target.value) })
1656
+ const inputSecret = (v, placeholder, onChange) => h('input', { type: 'password', value: textOf(v), placeholder, onChange: (e) => onChange(e.target.value) })
1657
+ const inputNum = (v, step, onChange) => h('input', { type: 'number', step, value: Number.isFinite(Number(v)) ? Number(v) : 0, onChange: (e) => onChange(Number(e.target.value)) })
1658
+ const inputBool = (v, fallback, onChange) => h('input', { type: 'checkbox', checked: v === undefined ? fallback : v !== false, onChange: (e) => onChange(e.target.checked) })
1659
+ const inputSelect = (v, options, onChange) =>
1522
1660
  h(
1523
- 'label',
1524
- { className: 'pb-llm-field' },
1525
- h('span', null, label),
1526
- h(
1527
- 'select',
1528
- { value, onChange: (e) => onChange(e.target.value) },
1529
- options.map((opt) => h('option', { key: opt.value, value: opt.value }, opt.label)),
1530
- ),
1661
+ 'select',
1662
+ { value: textOf(v), onChange: (e) => onChange(e.target.value) },
1663
+ options.map((opt) => h('option', { key: opt[0], value: opt[0] }, opt[1])),
1531
1664
  )
1532
1665
 
1533
- const line = on
1534
- ? (a.mode === 'registered'
1535
- ? `${t('llmOn')}:${a.provider} · ${a.model}(≤${Math.max(1, Math.round((a.minIntervalMs || 0) / 60000))} min/次${a.autoApply ? t('llmAuto') : ''})`
1536
- : `${t('llmOn')}:${a.baseUrl} · ${a.model}(≤${Math.max(1, Math.round((a.minIntervalMs || 0) / 60000))} min/次${a.autoApply ? t('llmAuto') : ''})`)
1537
- : t('llmOff')
1538
-
1539
1666
  return h(
1540
1667
  'div',
1541
- { className: on ? 'pb-llm' : 'pb-llm pb-llm-off' },
1542
- h('div', { className: 'pb-llm-title' }, t('llmTitle')),
1543
- h('div', { className: 'pb-llm-line' }, line),
1544
- h('div', { className: 'pb-llm-hint' }, t('llmHint')),
1545
- h('button', { type: 'button', className: 'pb-side-link', style: { marginTop: '4px' }, onClick: () => setOpen((v) => !v) }, open ? '▾' : '▸'),
1546
- open
1547
- ? h(
1548
- 'div',
1549
- { className: 'pb-llm-editor' },
1550
- select(t('llmMode'), mode, setMode, [
1551
- { value: '', label: t('llmModeOff') },
1552
- { value: 'registered', label: t('llmModeRegistered') },
1553
- { value: 'direct', label: t('llmModeDirect') },
1554
- ]),
1555
- mode === 'registered'
1556
- ? h(
1557
- 'div',
1558
- null,
1559
- providers.length === 0
1560
- ? h('div', { className: 'pb-llm-hint' }, t('llmNoProviders'))
1561
- : select(t('llmProvider'), provider, (v) => { setProvider(v); setModel('') }, [
1562
- { value: '', label: t('llmPickModel') },
1563
- ...providers.map((p) => ({ value: p.name, label: p.name })),
1564
- ]),
1565
- models.length > 0
1566
- ? select(t('llmModel'), model, setModel, [
1567
- { value: '', label: t('llmPickModel') },
1568
- ...models.map((m) => ({ value: m, label: m })),
1569
- ])
1570
- : null,
1571
- )
1572
- : mode === 'direct'
1573
- ? h(
1574
- 'div',
1575
- null,
1576
- h('label', { className: 'pb-llm-field' }, h('span', null, t('llmBaseUrl')), h('input', { type: 'text', value: baseUrl, onChange: (e) => setBaseUrl(e.target.value) })),
1577
- h('label', { className: 'pb-llm-field' }, h('span', null, t('llmModel')), h('input', { type: 'text', value: model, onChange: (e) => setModel(e.target.value) })),
1578
- h('label', { className: 'pb-llm-field' }, h('span', null, t('llmApiKey')), h('input', { type: 'password', value: apiKey, placeholder: a.hasApiKey ? '••••••' : '', onChange: (e) => setApiKey(e.target.value) })),
1579
- )
1580
- : null,
1581
- select(t('llmAuthority'), authority, setAuthority, [
1582
- { value: 'both', label: t('llmAuthorityBoth') },
1583
- { value: 'slots', label: t('llmAuthoritySlots') },
1584
- { value: 'rounds', label: t('llmAuthorityRounds') },
1585
- ]),
1586
- h('button', { type: 'button', className: 'pb-btn pb-btn-primary', style: { marginTop: '6px' }, onClick: () => void save() }, t('llmSave')),
1587
- status ? h('span', { className: 'pb-llm-hint', style: { marginLeft: '8px' } }, status) : null,
1588
- )
1589
- : null,
1668
+ { className: 'pb-set' },
1669
+ scope ? null : h('div', { className: 'pb-set-banner' }, t('setNoScope')),
1670
+ h(
1671
+ SettingsGroup,
1672
+ { title: t('setLlmGroup'), hint: t('setLlmHint') },
1673
+ h(SettingsRow, { label: t('setMode') },
1674
+ inputSelect(assistant.mode || '', [['', t('setModeOff')], ['registered', t('setModeRegistered')], ['direct', t('setModeDirect')]], (v) => putAssistant('mode', v))),
1675
+ h(SettingsRow, { label: t('setProvider'), hint: t('setProviderHint') },
1676
+ inputText(assistant.provider || '', (v) => putAssistant('provider', v))),
1677
+ h(SettingsRow, { label: t('setModel') },
1678
+ inputText(assistant.model || '', (v) => putAssistant('model', v))),
1679
+ h(SettingsRow, { label: t('setBaseUrl') },
1680
+ inputText(assistant.baseUrl || '', (v) => putAssistant('baseUrl', v))),
1681
+ h(SettingsRow, { label: t('setApiKey'), hint: t('setApiKeyHint') },
1682
+ inputSecret('', assistant.hasApiKey ? '••••••' : '', (v) => putAssistant('apiKey', v))),
1683
+ h(SettingsRow, { label: t('setAuthority') },
1684
+ inputSelect(assistant.authority || 'both', [['both', t('setAuthorityBoth')], ['slots', t('setAuthoritySlots')], ['rounds', t('setAuthorityRounds')]], (v) => putAssistant('authority', v))),
1685
+ h(SettingsRow, { label: t('setInterval'), hint: t('setIntervalHint') },
1686
+ inputNum(assistant.minIntervalMs === undefined ? 90000 : assistant.minIntervalMs, 1000, (v) => putAssistant('minIntervalMs', v))),
1687
+ h(SettingsRow, { label: t('setAutoApply') },
1688
+ inputBool(assistant.autoApply, true, (v) => putAssistant('autoApply', v))),
1689
+ ),
1690
+ h(
1691
+ SettingsGroup,
1692
+ { title: t('setObserverGroup'), hint: t('setObserverHint') },
1693
+ h(SettingsRow, { label: t('setObserverEnabled') },
1694
+ inputBool(observer.enabled, true, (v) => putObserver('enabled', v))),
1695
+ h(SettingsRow, { label: t('setMaxIdleSteps') },
1696
+ inputNum(observer.maxIdleSteps === undefined ? 6 : observer.maxIdleSteps, 1, (v) => putObserver('maxIdleSteps', v))),
1697
+ h(SettingsRow, { label: t('setMaxIdleMs') },
1698
+ inputNum(observer.maxIdleMs === undefined ? 180000 : observer.maxIdleMs, 1000, (v) => putObserver('maxIdleMs', v))),
1699
+ h(SettingsRow, { label: t('setAutoSyncCurrent') },
1700
+ inputBool(observer.autoSyncCurrent, true, (v) => putObserver('autoSyncCurrent', v))),
1701
+ h(SettingsRow, { label: t('setAutoSyncThrottleMs') },
1702
+ inputNum(observer.autoSyncThrottleMs === undefined ? 60000 : observer.autoSyncThrottleMs, 1000, (v) => putObserver('autoSyncThrottleMs', v))),
1703
+ h(SettingsRow, { label: t('setMaxItems') },
1704
+ inputNum(observer.maxItems === undefined ? 12 : observer.maxItems, 1, (v) => putObserver('maxItems', v))),
1705
+ ),
1706
+ h(
1707
+ SettingsGroup,
1708
+ { title: t('setApiGroup'), hint: t('setApiHint') },
1709
+ h('div', { className: 'pb-set-api' },
1710
+ h('div', null, h('b', null, t('setApiService')), 'ctx.get(\'progressAnchor\').get(sessionId) / .list()'),
1711
+ h('div', null, h('b', null, t('setApiAnchor')), 'GET /progress-union/anchor?sessionId=<id>'),
1712
+ h('div', null, h('b', null, t('setApiSnapshot')), 'GET /progress-union/snapshot?sessionId=<id>'),
1713
+ h('div', null, h('b', null, t('setApiStatus')), 'GET /dsh-progress/status?sessionId=<id>'),
1714
+ ),
1715
+ ),
1716
+ status ? h('div', { className: 'pb-set-status' }, status) : null,
1590
1717
  )
1591
1718
  }
1592
1719
 
@@ -1743,7 +1870,7 @@ window.__ModuleLoader__.load({
1743
1870
  ),
1744
1871
  ),
1745
1872
  readError ? h('div', { className: 'pb-side-error' }, `${t('readError')}${readError}`) : null,
1746
- h(LlmAssistNotice, { assistant: snapshot?.assistant, t: props.t, assistantCfg: props.assistantCfg }),
1873
+ h(LlmAssistNotice, { assistant: snapshot?.assistant, t: props.t }),
1747
1874
  actionError ? h('div', { className: 'pb-side-error' }, `${t('saveError')}${actionError}`) : null,
1748
1875
  usageView
1749
1876
  ? h(
@@ -2163,7 +2290,7 @@ window.__ModuleLoader__.load({
2163
2290
  ),
2164
2291
  ),
2165
2292
  ),
2166
- h(LlmAssistNotice, { assistant: snapshot?.assistant, t: props.t, assistantCfg: props.assistantCfg }),
2293
+ h(LlmAssistNotice, { assistant: snapshot?.assistant, t: props.t }),
2167
2294
  snapshot?.enabled === false
2168
2295
  ? h(
2169
2296
  'div',
@@ -2301,7 +2428,6 @@ window.__ModuleLoader__.load({
2301
2428
  return {
2302
2429
  inject: ['slots', 'locale', 'layout', 'sidebarRight', 'sidebarRightTabs', 'sessions'],
2303
2430
  apply(ctx) {
2304
- installSettingsScope(ctx)
2305
2431
  ctx.effect(
2306
2432
  () =>
2307
2433
  ctx.locale.register(NS, {
@@ -2312,46 +2438,29 @@ window.__ModuleLoader__.load({
2312
2438
  )
2313
2439
 
2314
2440
  const t = ctx.locale.bind(NS)
2315
- // 辅助 LLM 配置读写面:面板用它在 settings 里改 assistant(运行时生效,无需重启)。
2316
- const assistantCfg = {
2317
- available: () => Boolean(scopeOf),
2318
- // llm-pi-ai 里的 provider/model 列表(供下拉)
2319
- providers() {
2320
- if (!scopeOf) return []
2321
- try {
2322
- const scope = scopeOf('llm-pi-ai')
2323
- const snap = scope && typeof scope.getSnapshot === 'function' ? scope.getSnapshot() : null
2324
- const value = snap && (snap.value !== undefined ? snap.value : snap)
2325
- const providers = value && Array.isArray(value.providers) ? value.providers : []
2326
- return providers.map((p) => ({
2327
- name: String(p && (p.name || p.id || p.provider) || ''),
2328
- models: Array.isArray(p && p.models)
2329
- ? p.models.map((m) => String((m && (m.id || m.name)) || '')).filter(Boolean)
2330
- : [],
2331
- })).filter((p) => p.name)
2332
- } catch (_err) {
2333
- return []
2334
- }
2335
- },
2336
- // progress-union settings 里当前的 assistant 配置
2337
- current() {
2338
- if (!scopeOf) return null
2339
- try {
2340
- const scope = scopeOf('progress-union')
2341
- const snap = scope && typeof scope.getSnapshot === 'function' ? scope.getSnapshot() : null
2342
- const value = snap && (snap.value !== undefined ? snap.value : snap)
2343
- return value && typeof value === 'object' && value.assistant ? value.assistant : null
2344
- } catch (_err) {
2345
- return null
2346
- }
2347
- },
2348
- async save(patch) {
2349
- if (!scopeOf) throw new Error('settings unavailable')
2350
- const scope = scopeOf('progress-union')
2351
- if (!scope || typeof scope.set !== 'function') throw new Error('scope.set unavailable')
2352
- await scope.set('assistant', patch)
2353
- },
2354
- }
2441
+
2442
+ // 独立设置分节:顶层 `settings.section`(与记忆/模型/插件并列)。
2443
+ // order 215 接在宿主内置分节之后;旧宿主没声明该槽时 inject 空转,
2444
+ // 面板与迷你条不受影响(不靠版本号判断,只靠槽位存在性)。
2445
+ const settingsScope = unionFormsScope(ctx)
2446
+ ctx.effect(
2447
+ () =>
2448
+ ctx.slots.inject('settings.section', () =>
2449
+ ctx.slots.register(
2450
+ {
2451
+ name: 'settings.section',
2452
+ id: 'dsh-progress-union',
2453
+ order: 215,
2454
+ locale: NS,
2455
+ label: () => t('setTitle'),
2456
+ inject: () => ({ scope: settingsScope }),
2457
+ },
2458
+ ProgressUnionSettings,
2459
+ ),
2460
+ ),
2461
+ 'progress-union: settings section',
2462
+ )
2463
+
2355
2464
  const wakeAgent = (sessionId, text) => {
2356
2465
  try {
2357
2466
  const binding = ctx.sessions.binding(sessionId)
@@ -2448,7 +2557,6 @@ window.__ModuleLoader__.load({
2448
2557
  openFullPanel,
2449
2558
  wakeAgent,
2450
2559
  usage: usageApi,
2451
- assistantCfg,
2452
2560
  }),
2453
2561
  },
2454
2562
  ProgressSidePanel,
@@ -2465,7 +2573,7 @@ window.__ModuleLoader__.load({
2465
2573
  name: 'main',
2466
2574
  key: PANEL_ID,
2467
2575
  locale: NS,
2468
- inject: () => ({ wakeAgent, usage: usageApi, assistantCfg }),
2576
+ inject: () => ({ wakeAgent, usage: usageApi }),
2469
2577
  },
2470
2578
  ProgressPanel,
2471
2579
  ),
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "main": "./index.js",
5
5
  "description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior、悬浮迷你条),并向压缩插件暴露只读三层进度锚点 progressAnchor(board 语义锚 + time 时间锚 + userEdits 未确认改动,service 与 HTTP 双平面)。",
6
6
  "engines": {
package/index.js CHANGED
@@ -21,20 +21,30 @@ import os from 'node:os'
21
21
  import path from 'node:path'
22
22
  import z from '@deepseek-ai/schemastery'
23
23
 
24
- // 设置页可见性:宿主 settings.describe() 只看插件导出的 Config(带 .volatile() 的字段
25
- // 才会生成可编辑表单)。导出它,progress-union 才会出现在「设置 → 插件」里,客户端
26
- // scopeOf('progress-union') 也才拿得到命名空间做运行时读写。
24
+ // 设置页可见性:0.1.7+ 宿主把 composition entry 当设置节,直接按导出的 Config
25
+ // **逐叶子**的 .volatile() 标记生成「设置 → 插件」里的表单,并把 volatile 字段以
26
+ // live ref(带 .get())注入 apply。整对象套一层 .volatile() 不生成字段表单(面板
27
+ // 只会空空如也),所以必须每个叶子单独标——与 dsh-llm-openai-completions 同式。
27
28
  export const Config = z.object({
29
+ protocolHint: z.boolean().default(true).volatile(),
28
30
  assistant: z.object({
29
- mode: z.union(['', 'registered', 'direct']).default(''),
30
- provider: z.string().default(''),
31
- model: z.string().default(''),
32
- baseUrl: z.string().default(''),
33
- apiKey: z.string().role('secret').default(''),
34
- authority: z.union(['slots', 'rounds', 'both']).default('both'),
35
- minIntervalMs: z.number().step(1000).min(0).default(90000),
36
- autoApply: z.boolean().default(true),
37
- }).default({}).volatile(),
31
+ mode: z.union(['', 'registered', 'direct']).default('').volatile(),
32
+ provider: z.string().default('').volatile(),
33
+ model: z.string().default('').volatile(),
34
+ baseUrl: z.string().default('').volatile(),
35
+ apiKey: z.string().role('secret').default('').volatile(),
36
+ authority: z.union(['slots', 'rounds', 'both']).default('both').volatile(),
37
+ minIntervalMs: z.number().step(1000).min(0).default(90000).volatile(),
38
+ autoApply: z.boolean().default(true).volatile(),
39
+ }).default({}),
40
+ observer: z.object({
41
+ enabled: z.boolean().default(true).volatile(),
42
+ maxIdleSteps: z.number().step(1).min(1).default(6).volatile(),
43
+ maxIdleMs: z.number().step(1000).min(1000).default(180000).volatile(),
44
+ autoSyncCurrent: z.boolean().default(true).volatile(),
45
+ autoSyncThrottleMs: z.number().step(1000).min(0).default(60000).volatile(),
46
+ maxItems: z.number().step(1).min(1).default(12).volatile(),
47
+ }).default({}),
38
48
  })
39
49
 
40
50
  // —— 路由与存储标识 ——
@@ -518,21 +528,57 @@ const DEFAULT_CONFIG = {
518
528
  }
519
529
 
520
530
  // .volatile() 字段在 0.1.7+ 宿主以 live ref(带 .get())传入,旧宿主为普通值。
521
- function readVolatile(value, fallback) {
531
+ function unwrapLive(value) {
522
532
  if (value !== null && typeof value === 'object' && typeof value.get === 'function') {
523
533
  const snap = value.get()
524
- return snap === undefined ? fallback : snap
534
+ return snap === undefined ? undefined : snap
525
535
  }
526
- return value ?? fallback
536
+ return value === undefined || value === null ? undefined : value
537
+ }
538
+
539
+ function readVolatile(value, fallback) {
540
+ const v = unwrapLive(value)
541
+ return v === undefined ? fallback : v
527
542
  }
528
543
 
529
544
  export async function apply(ctx, config) {
530
545
  const cfg = Object.assign({}, DEFAULT_CONFIG, config && typeof config === 'object' ? config : {})
531
- cfg.observer = Object.assign({}, DEFAULT_CONFIG.observer, cfg.observer && typeof cfg.observer === 'object' ? cfg.observer : {})
532
- // assistant 是 volatile 字段:保留原始 ref,每次读取时解包(设置面板改了立即生效)。
546
+ // observer 的每个叶子都是 volatile(设置页可改):统一每次读取时解包。
547
+ const observerRaw = config && typeof config === 'object' ? config.observer : undefined
548
+ function observerNow() {
549
+ const base = DEFAULT_CONFIG.observer
550
+ const raw = unwrapLive(observerRaw)
551
+ if (!isObject(raw)) return { ...base }
552
+ const out = { ...base }
553
+ for (const key of Object.keys(base)) {
554
+ const v = unwrapLive(raw[key])
555
+ if (v !== undefined) out[key] = v
556
+ }
557
+ return out
558
+ }
559
+ // 用 getter 而不是快照:所有 `cfg.observer.x` 读点无需逐个改,设置页改完即生效。
560
+ Object.defineProperty(cfg, 'observer', { get: observerNow, configurable: true, enumerable: true })
561
+ const protocolHintRaw = config && typeof config === 'object' ? config.protocolHint : undefined
562
+ Object.defineProperty(cfg, 'protocolHint', {
563
+ get: () => readVolatile(protocolHintRaw, DEFAULT_CONFIG.protocolHint),
564
+ configurable: true,
565
+ enumerable: true,
566
+ })
567
+ // assistant 的每个字段都是 volatile:保留原始 ref(整对象或逐叶子皆可),
568
+ // 每次读取时解包,设置页改完下一次审查即生效,无需重启。
533
569
  const assistantRaw = config && typeof config === 'object' ? config.assistant : undefined
534
- const unwrappedAssistant = readVolatile(assistantRaw, {})
535
- cfg.assistant = Object.assign({}, DEFAULT_CONFIG.assistant, unwrappedAssistant && typeof unwrappedAssistant === 'object' ? unwrappedAssistant : {})
570
+ function assistantNow() {
571
+ const base = DEFAULT_CONFIG.assistant
572
+ const raw = unwrapLive(assistantRaw)
573
+ if (!isObject(raw)) return { ...base }
574
+ const out = { ...base }
575
+ for (const key of Object.keys(base)) {
576
+ const v = unwrapLive(raw[key])
577
+ if (v !== undefined) out[key] = v
578
+ }
579
+ return out
580
+ }
581
+ cfg.assistant = assistantNow()
536
582
  const now = () => Date.now()
537
583
 
538
584
  // —— 状态容器 ——
@@ -575,11 +621,12 @@ export async function apply(ctx, config) {
575
621
  } catch (_err) {}
576
622
  return undefined
577
623
  }
578
- // 运行时配置:settings 里的 assistant 覆盖静态 cfg.assistant(面板改了立即生效)。
624
+ // 运行时配置:设置页(volatile live ref)优先,settings 命名空间作补充覆盖。
579
625
  function liveAssistant() {
626
+ const current = assistantNow()
580
627
  const section = readAssistantSection()
581
628
  const fromSettings = section && isObject(section.value) && isObject(section.value.assistant) ? section.value.assistant : undefined
582
- return fromSettings ? { ...cfg.assistant, ...fromSettings } : cfg.assistant
629
+ return fromSettings ? { ...current, ...fromSettings } : current
583
630
  }
584
631
 
585
632
  // ==========================================================================
@@ -1478,18 +1525,26 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
1478
1525
  try {
1479
1526
  let raw = ''
1480
1527
  if (a.mode === 'registered') {
1481
- // 宿主 llm.stream:把 chunk 拼成正文(兼容 content/text 字段与 delta 形态)。
1528
+ // 应主 llm.stream 契约:system 必须走 options.system(adapter 才把它映射到
1529
+ // provider 的 system 槽);写进 messages 的 role:'system' 会被忽略 → 请求实际
1530
+ // 没有 system,DeepSeek 回落到内置 "You are a helpful assistant." 并把它当正文
1531
+ // 吐回来。content 也必须是 ContentBlock[](块数组)而非裸字符串。
1532
+ // 参考 dsh-media-lens/src/providers/registered.ts 的调用形状。
1482
1533
  const stream = llm.stream({
1483
1534
  provider: String(a.provider),
1484
1535
  model: String(a.model),
1485
- messages: [{ role: 'system', content: ASSISTANT_SYSTEM }, { role: 'user', content: lines.join('\n') }],
1536
+ system: ASSISTANT_SYSTEM,
1537
+ messages: [{ role: 'user', content: [{ type: 'text', text: lines.join('\n') }] }],
1538
+ signal: controller.signal,
1486
1539
  })
1487
1540
  for await (const chunk of stream) {
1488
- if (chunk && typeof chunk.content === 'string') raw += chunk.content
1489
- else if (chunk && typeof chunk.text === 'string') raw += chunk.text
1490
- else if (chunk && chunk.delta && typeof chunk.delta === 'string') raw += chunk.delta
1491
1541
  if (controller.signal.aborted) break
1542
+ if (chunk && chunk.type === 'text-delta' && typeof chunk.text === 'string') raw += chunk.text
1543
+ else if (chunk && chunk.type === 'finish' && chunk.reason && chunk.reason.kind !== 'stop' && chunk.reason.kind !== 'max-tokens') {
1544
+ throw new Error(`assistant finish: ${chunk.reason.kind}`)
1545
+ }
1492
1546
  }
1547
+ if (raw.trim() === '') throw new Error('assistant-empty')
1493
1548
  } else {
1494
1549
  const base = String(a.baseUrl || '').replace(/\/+$/, '')
1495
1550
  const response = await fetch(`${base}/chat/completions`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎,另向压缩插件暴露只读三层进度锚点(service + HTTP 双平面)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
6
6
  "license": "MIT",
@@ -149,13 +149,34 @@ test('节流与每回合配额:minIntervalMs 内不再发;新回合重置配
149
149
  }
150
150
  })
151
151
 
152
- test('registered 模式:走宿主 llm.stream,消费 chunk + 槽位管理 + 轮次草案', async () => {
152
+ test('assistant 逐叶子 volatile:live ref 每回合重读,改值不需重启', async () => {
153
+ const ref = (getter) => ({ get: getter })
154
+ const live = { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini' }
155
+ const harness = createHarness({
156
+ config: {
157
+ assistant: {
158
+ mode: ref(() => live.mode),
159
+ baseUrl: ref(() => live.baseUrl),
160
+ model: ref(() => live.model),
161
+ minIntervalMs: ref(() => 0),
162
+ },
163
+ },
164
+ })
165
+ await harness.run()
166
+ const on = await snapshotOf(harness)
167
+ assert.equal(on.assistant.mode, 'direct')
168
+ assert.equal(on.assistant.enabled, true)
169
+ live.mode = ''
170
+ const off = await snapshotOf(harness)
171
+ assert.equal(off.assistant.enabled, false, '设置页关掉后下一次读即生效')
172
+ })
173
+ test('registered 模式:走宿主 llm.stream(system 走 options.system,content 为块数组),消费 text-delta + 槽位管理 + 轮次草案', async () => {
153
174
  const streamCalls = []
154
175
  const llm = {
155
176
  async *stream(options) {
156
177
  streamCalls.push(options)
157
- // 第一段先占位;真实 id 在下面覆盖,这里先给一个失败的 JSON(不会被用)
158
- yield { content: '{}' }
178
+ yield { type: 'text-delta', text: '{}' }
179
+ yield { type: 'finish', reason: { kind: 'stop' } }
159
180
  },
160
181
  }
161
182
  const harness = createHarness({
@@ -168,15 +189,25 @@ test('registered 模式:走宿主 llm.stream,消费 chunk + 槽位管理 +
168
189
  const itemId = added.changed[0].id
169
190
  llm.stream = async function* (options) {
170
191
  streamCalls.push(options)
171
- yield { content: '{"board":{"changes":[' }
172
- yield { content: `{"kind":"edit","id":"${itemId}","percent":75}` }
173
- yield { content: ']},"round":{"status":"continue","summary":"推进中"},"note":"registered 校准"}' }
192
+ yield { type: 'text-delta', text: '{"board":{"changes":[' }
193
+ yield { type: 'text-delta', text: `{"kind":"edit","id":"${itemId}","percent":75}` }
194
+ yield { type: 'text-delta', text: ']},"round":{"status":"continue","summary":"推进中"},"note":"registered 校准"}' }
195
+ yield { type: 'finish', reason: { kind: 'stop' } }
174
196
  }
175
197
  for (let i = 0; i < 6; i++) harness.emit('step/start', {})
176
198
  await settle()
177
199
  assert.equal(streamCalls.length, 1, 'registered 走 llm.stream 而非 fetch')
178
200
  assert.equal(streamCalls[0].provider, 'local')
179
201
  assert.equal(streamCalls[0].model, 'qwen')
202
+ // 契约守卫(2026-11-26 事故回归):system 必须在 options.system,不能藏在 messages 里,
203
+ // 否则 adapter 不映射 system 槽 → DeepSeek 回落到内置 "You are a helpful assistant."
204
+ assert.equal(typeof streamCalls[0].system, 'string')
205
+ assert.match(streamCalls[0].system, /progress assistant/, 'system 必须是 ASSISTANT_SYSTEM 正文')
206
+ assert.deepEqual(streamCalls[0].messages.map((m) => m.role), ['user'], 'messages 里不得出现 role:system')
207
+ const blocks = streamCalls[0].messages[0].content
208
+ assert.ok(Array.isArray(blocks), 'content 必须是 ContentBlock[],不能是裸字符串')
209
+ assert.equal(blocks[0].type, 'text')
210
+ assert.match(blocks[0].text, /目标|\[~\]/, '输入正文必须带上板清单')
180
211
  const snap = await snapshotOf(harness)
181
212
  assert.equal(snap.items[0].percent, 75, '助手改了槽位')
182
213
  assert.equal(snap.items[0].updatedBy, 'assistant')
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 设置面契约守卫(2026-11-26 事故回归)。
3
+ *
4
+ * 1) 设置页字段表单靠 **schema 叶子** 的 `.volatile()` 标记生成:整对象标 volatile
5
+ * 时一个字段都不渲染(客户端也就看不到任何可编辑项)。这里逐叶子断言标记存在。
6
+ * 2) 客户端必须把设置卡注册到 `settings.section` 槽,并通过宿主 `configForms`
7
+ * 句柄读写——否则「bundle 页 / 设置页」都没有配置入口。
8
+ */
9
+ import assert from 'node:assert/strict'
10
+ import fs from 'node:fs'
11
+ import os from 'node:os'
12
+ import path from 'node:path'
13
+ import test from 'node:test'
14
+
15
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
16
+ const { Config } = await import('../index.js')
17
+
18
+ /** 递归收集点分键 → 是否带 volatile 标记。 */
19
+ function volatileLeaves(node, prefix = '', out = {}) {
20
+ const inner = node && (node.dict || node.inner)
21
+ if (!inner || typeof inner !== 'object') return out
22
+ for (const [key, child] of Object.entries(inner)) {
23
+ const dotted = prefix ? `${prefix}.${key}` : key
24
+ const meta = (child && child.meta) || {}
25
+ const nested = child && (child.dict || child.inner)
26
+ if (nested && typeof nested === 'object') volatileLeaves(child, dotted, out)
27
+ else out[dotted] = meta.volatile !== undefined
28
+ }
29
+ return out
30
+ }
31
+
32
+ test('Config:assistant / observer 的每个叶子都带 volatile(否则设置页不生成字段)', () => {
33
+ const leaves = volatileLeaves(Config)
34
+ const expected = [
35
+ 'protocolHint',
36
+ 'assistant.mode',
37
+ 'assistant.provider',
38
+ 'assistant.model',
39
+ 'assistant.baseUrl',
40
+ 'assistant.apiKey',
41
+ 'assistant.authority',
42
+ 'assistant.minIntervalMs',
43
+ 'assistant.autoApply',
44
+ 'observer.enabled',
45
+ 'observer.maxIdleSteps',
46
+ 'observer.maxIdleMs',
47
+ 'observer.autoSyncCurrent',
48
+ 'observer.autoSyncThrottleMs',
49
+ 'observer.maxItems',
50
+ ]
51
+ for (const key of expected) {
52
+ assert.ok(key in leaves, `缺少配置键 ${key}`)
53
+ assert.equal(leaves[key], true, `${key} 必须是叶子级 .volatile()`)
54
+ }
55
+ })
56
+
57
+ test('Config:外层对象不得自己标 volatile(嵌套 volatile 会被宿主拒绝)', () => {
58
+ for (const key of ['assistant', 'observer']) {
59
+ const node = (Config.dict || Config.inner || {})[key]
60
+ assert.ok(node, `缺少 ${key} 节点`)
61
+ assert.equal((node.meta || {}).volatile, undefined, `${key} 这层不能标 volatile`)
62
+ }
63
+ })
64
+
65
+ test('客户端:设置卡注册到 settings.section 且走 configForms 句柄', () => {
66
+ const file = new URL('../client.js', import.meta.url).pathname.replace(/^\//, '')
67
+ const src = fs.readFileSync(file, 'utf8')
68
+ assert.match(src, /name: 'settings\.section'/, '必须注册 settings.section 槽')
69
+ assert.match(src, /id: 'dsh-progress-union'/, '分节 id 必须固定')
70
+ assert.match(src, /configForms/, '必须经宿主 configForms 读写配置')
71
+ assert.match(src, /function ProgressUnionSettings\(/, '设置卡组件必须在')
72
+ assert.match(src, /scope\.subscribe/, '设置卡要订阅句柄快照')
73
+ })