dsh-progress-union 0.7.8 → 0.7.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,19 @@
2
2
 
3
3
  本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
4
 
5
+ ## 0.7.9 (2026-12-04)
6
+
7
+ **feat(ops):校验不再上按钮;LLM 每次回答分「思考 / 输出」两区;输出不符合校验格式一律打回重问(最多三轮)。**
8
+
9
+ 侧边栏「LLM 操作」原来把 `validateBoard` 做成了第四个按钮,但它本质是每次改板都该跑的内部闸门 —— 摆在界面上既误导用户「不点一下就不安全」,又与落盘后的自动体检重复。同时它掩盖了一个更实质的问题:旧 `runOps` 对模型输出是**宽容丢弃**(`opsChanges` 把幽灵 id、空 title、非法 status 一条条滤掉、剩下的照常落盘),于是一次 refine 可能只改半块板,而模型永远收不到「你刚才哪一条不合规」的反馈。本版改成严格闸门:
10
+
11
+ - **`validateProposal(state, proposal, op)`(纯函数,新增)**:判定模型这一次的输出吃不吃得下 —— 非对象 / 缺 `changes` 数组 / 条目不是对象 / `kind` 非 `add|edit|remove` / `edit|remove` 指认板上没有的 id / `add` 缺 title 或 title 过长 / `edit` 空转 / `status` 非枚举 / `percent` 越界 / `order` 非数字 / 问询没给 `answer`。与 `validateBoard` 分工明确:后者管板数据合不合法,前者管模型输出能不能吃,它的 `errors` 就是打回时要逐条喂回去的话术。
12
+ - **打回重试(`OPS_MAX_ATTEMPTS = 3`)**:`withOpsFeedback` 把逐条原因贴回原提示重新要一次;三轮仍不合规则 **502 且板 revision 一次都不动**(取消半应用)。两条护栏**不**打回:条数超 8 走截断(可部分交付,不为格式多烧一次 token),问询硬塞的 `changes` 直接丢弃。
13
+ - **回答分两区**:三路 system 的输出形状升级为 `{"thinking":"…","changes":[…],"answer":"…"}`;`opsOutcome` 返回 `{think, kind, text}`,面板把 `thinking` 渲染成低一档灰字(`--dsw-alias-label-tertiary`)的思考区(模型没给就整块缺席、不留空框),结论进输出区;回执新增 `thinking` / `attempts` / `validation`。
14
+ - **界面去掉「校验」按钮**:`OPS_ACTIONS` 降为三项(refine/mutate/ask);体检随每次回答自动跑,**顺利通过时不再占输出区一行**,只在硬错或有提醒时落进结论。`op:"validate"` 路由保留(外部消费者与单测仍在用)。i18n 去掉 `opsValidate`,补 `opsThink` / `opsOut` / `opsRetried`。
15
+
16
+ 门禁:`node --check index.js client.js anchor.js` 绿;`npm test` **253 pass / 0 fail**(较 0.7.8 +7:`validateProposal` 三例、打回重试与 ask 空答打回三例、两区渲染一例)。`ANCHOR_VERSION` 仍为 1(只追加回执字段,不动既有键)。传输失败(宿主报错/超时)不在打回范围内 —— 那不是格式问题,重试只会多花一份 token。
17
+
5
18
  ## 0.7.8 (2026-12-04)
6
19
 
7
20
  **docs:把 0.7.x 开发期写坏的四句中文注释/文案改回人话(零行为变更)。**
package/README.md CHANGED
@@ -303,16 +303,21 @@ npm test # node --test test/*.test.mjs(246 用例,纯 mock ctx,无需宿
303
303
 
304
304
  ## 侧边栏 LLM 任务操作(v0.7.0)
305
305
 
306
- 侧边栏板内(AddTask 与页脚之间)多一块「LLM 操作」:provider/model 双下拉 + 输入 + 四个按钮,**不新开顶级标签**。
306
+ 侧边栏板内(AddTask 与页脚之间)多一块「LLM 操作」:provider/model 双下拉 + 输入 + **三个按钮**,**不新开顶级标签**。
307
307
 
308
308
  - **细化拆分**:让辅助模型按板上现状把一个粗项拆成可交付小步(add/edit)。
309
309
  - **按指令改板**:一句自然语言翻成 add/edit/remove/`order` 排序。
310
310
  - **问询**:只回文本,模型硬塞 `changes` 也不写板。
311
- - **校验**:`validateBoard` 纯本地跑,一次 token 都不花;硬错(项数 >60、缺/过长 title、status 非枚举、percent 越界、`done` 但 pct≠100)与 warnings(空板、重复 title、多 doing)分档显示。
312
311
 
313
- 选模型口径同 prime-memory:`GET /ops/providers` 读宿主 `llm.listProviders()` 与默认模型选择,宿主没给服务时退回设置页里的 `assistant.provider/model`(下拉显示「沿用设置页」),不报错。落盘走同一条 `callAssistant → parseProposal → applyChanges(origin:'ops')` 通道:改动截 8 条、未知 id 与空 title 丢弃、模型答非 JSON 返 502 且**板 revision 不动**、未配置模型返 400。`origin:'ops'` 不算「主模型刚刚同步过」,催办计时不被侧边栏操作抹平。
312
+ **回答分两区(v0.7.9)**:模型这一次的输出形状是 `{"thinking":"…","changes":[…],"answer":"…"}` —— `thinking` 渲染成低一档灰字的**思考区**(`--dsw-alias-label-tertiary`,模型没给就整块缺席、不留空框),`answer` 与改动条数、体检提醒渲染成**输出区**,输出区按 ok/warn/bad 三档取左边条颜色。
314
313
 
315
- **整块开关 `ops.enabled`(v0.7.2,默认开)**:关掉后 `GET /ops/providers` 直接报 `disabled:true` 且**不再打宿主 `listProviders`**,客户端据此把「LLM 操作」块整块收起(不是一堆禁用按钮,也不是报错);`POST /ops` 的 refine / mutate / ask 一律 **403**,唯独 `validate` 照常 200 —— 它是零 token 的本地板面体检,与花不花钱无关。该键与 `download.*` / `toolGloss.*` / `notifyMajorChanges` 同级:逐叶子 `.volatile()`、`DEFAULT_CONFIG.ops`、`flatSection('ops', …)` 三处齐全。表单入口从 **v0.7.5** 起真的存在(见下一节);开关关掉时服务端的 403 / `disabled` 判定是即时的,客户端块的隐去靠一次轮询重探(最多 15s),无需重加载页面。默认模型仍只走 `assistant.*` 与宿主当前选择,本开关不提供 `defaultProvider/defaultModel` 覆盖(计划里的那两个字段由宿主选择器承担,避免第二套模型配置面)。
314
+ **校验不再上按钮(v0.7.9)**:`validateBoard` 是零 token 的纯本地体检,现在**随每次回答自动跑**,结论只在「有硬错或有提醒」时落进输出区,顺利通过时不再占一行。`POST /ops` 的 `op:"validate"` 路由保留给外部消费者与单测。
315
+
316
+ **输出不合格 → 打回重试(v0.7.9)**:`validateProposal` 先判模型输出吃不吃得下 —— 非对象 / 缺 `changes` 数组 / 条目不是对象 / `kind` 非 `add|edit|remove` / `edit|remove` 指认板上没有的 id / `add` 缺 title 或 title 过长 / `edit` 空转 / `status` 非枚举 / `percent` 越界 / `order` 非数字 / 问询没给 `answer`。任一项不过,就把逐条原因贴回原提示**重新要一次**(`withOpsFeedback`),最多 `OPS_MAX_ATTEMPTS = 3` 轮(一次原始 + 两次打回);三轮仍不合规则 **502 且板 revision 一次都不动**——不再有「丢弃非法条目、落盘其余」的半应用。两条**不**打回的护栏:条数超 8 走截断(可部分交付,不为格式多烧一次 token),问询硬塞的 `changes` 直接丢弃。回执带 `attempts`,客户端只在 `>1` 时往输出区补一行「打回重问了 N」。
317
+
318
+ 选模型口径同 prime-memory:`GET /ops/providers` 读宿主 `llm.listProviders()` 与默认模型选择,宿主没给服务时退回设置页里的 `assistant.provider/model`(下拉显示「沿用设置页」),不报错。落盘走同一条 `callAssistant → parseProposal → validateProposal → applyChanges(origin:'ops')` 通道:改动截 8 条、非法输出整条打回、未配置模型返 400。`origin:'ops'` 不算「主模型同步过这块板」,催办计时不被侧边栏操作抹平。
319
+
320
+ **整块开关 `ops.enabled`(v0.7.2,默认开)**:关掉后 `GET /ops/providers` 直接报 `disabled:true` 且**不再打宿主 `listProviders`**,客户端据此把「LLM 操作」块整块收起(不是一堆禁用按钮,也不是报错);`POST /ops` 的 refine / mutate / ask 一律 **403**,唯独 `op:"validate"` 这条路由照常 200 —— 它是零 token 的本地板面体检,与花不花钱无关(v0.7.9 后面板上已无此按钮,路由只为外部消费者与单测保留)。该键与 `download.*` / `toolGloss.*` / `notifyMajorChanges` 同级:逐叶子 `.volatile()`、`DEFAULT_CONFIG.ops`、`flatSection('ops', …)` 三处齐全。表单入口从 **v0.7.5** 起真的存在(见下一节);开关关掉时服务端的 403 / `disabled` 判定是即时的,客户端块的隐去靠一次轮询重探(最多 15s),无需重加载页面。默认模型仍只走 `assistant.*` 与宿主当前选择,本开关不提供 `defaultProvider/defaultModel` 覆盖(计划里的那两个字段由宿主选择器承担,避免第二套模型配置面)。
316
321
 
317
322
  ## 设置页开关(v0.7.5 表单入口,v0.7.6 写面修正,v0.7.7 脏位修正)
318
323
 
package/client.js CHANGED
@@ -24,7 +24,7 @@ window.__ModuleLoader__.load({
24
24
  var REPO_URL = "https://github.com/drscrewdriver/dsh-progress-union";
25
25
  var STAR_NS = "progress-union";
26
26
  var STAR_GEN = "v4"; /* ladder:gen */
27
- var STAR_VERSION = "0.7.8"; /* ladder:ver */
27
+ var STAR_VERSION = "0.7.9"; /* ladder:ver */
28
28
  var LANGS = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es", "pt"];
29
29
 
30
30
  // 三代共享:GitHub 单色 mark(octicon 轮廓,fill 随 currentColor)。
@@ -424,7 +424,7 @@ window.__ModuleLoader__.load({
424
424
  llmSettingsHint: '在设置页修改',
425
425
  // v0.7.0 R3:侧边栏「LLM 操作」小块(就地写回本板,不新开顶级标签)
426
426
  opsTitle: 'LLM 操作',
427
- opsHint: '让辅助模型拆分细化、按指令改板、问询或校验;结果直接写回这块板,不会新开标签。',
427
+ opsHint: '让辅助模型拆分细化、按指令改板或问询;回答分「思考 / 输出」两区,输出不合格会被打回重问。结果直接写回这块板,不会新开标签。',
428
428
  opsProvider: '提供方',
429
429
  opsModel: '模型',
430
430
  opsProviderNone: '沿用设置页',
@@ -432,9 +432,11 @@ window.__ModuleLoader__.load({
432
432
  opsRefine: '细化拆分',
433
433
  opsMutate: '按指令改板',
434
434
  opsAsk: '问询',
435
- opsValidate: '校验',
436
435
  opsBusy: '处理中…',
437
436
  opsNoChanges: '没有可落地的改动',
437
+ opsThink: '思考',
438
+ opsOut: '输出',
439
+ opsRetried: '打回重问了',
438
440
  opsValidOk: '校验通过',
439
441
  opsValidBad: '校验未通过',
440
442
  opsItemsUnit: '项',
@@ -490,7 +492,7 @@ window.__ModuleLoader__.load({
490
492
  setGlossMaxLen: '工序句上限(字)',
491
493
  setOpsGroup: 'LLM 操作与队列提醒',
492
494
  setOpsBadge: '操作',
493
- setOpsHint: '关掉即侧边栏「LLM 操作」整块收起:提供方不再枚举,细化/改板/问询返回 403;「校验」是零 token 的本地板面体检,照常可用。',
495
+ setOpsHint: '关掉即侧边栏「LLM 操作」整块收起:提供方不再枚举,细化/改板/问询返回 403。板面体检从 v0.7.9 起不再占按钮:它随每次回答自动跑,输出不合格直接打回重问。',
494
496
  setOpsEnabled: '开放 LLM 任务操作',
495
497
  setNotifyMajor: '结构性变更落输入队列(黄档)',
496
498
  setNotifyMajorHint: '增删/重排任务时往队列插一条提醒,让模型先对齐板面;纯状态刷新不触发。',
@@ -641,7 +643,7 @@ window.__ModuleLoader__.load({
641
643
  llmSettingsHint: 'Change in Settings',
642
644
  // v0.7.0 R3: in-panel "LLM actions" block (writes back here, no new top-level tab)
643
645
  opsTitle: 'LLM actions',
644
- opsHint: 'Let the helper model refine, apply an instruction, ask or validate. Results write straight back to this board — no new tab.',
646
+ opsHint: 'Let the helper model refine, apply an instruction or ask. Each reply shows a thinking area and an output area, and non-conforming output is rejected and asked again. Results write straight back to this board — no new tab.',
645
647
  opsProvider: 'Provider',
646
648
  opsModel: 'Model',
647
649
  opsProviderNone: 'Use settings',
@@ -649,9 +651,11 @@ window.__ModuleLoader__.load({
649
651
  opsRefine: 'Refine',
650
652
  opsMutate: 'Apply',
651
653
  opsAsk: 'Ask',
652
- opsValidate: 'Validate',
653
654
  opsBusy: 'Working…',
654
655
  opsNoChanges: 'Nothing to apply',
656
+ opsThink: 'Thinking',
657
+ opsOut: 'Output',
658
+ opsRetried: 'Asked again',
655
659
  opsValidOk: 'Board is valid',
656
660
  opsValidBad: 'Board has errors',
657
661
  opsItemsUnit: 'items',
@@ -707,7 +711,7 @@ window.__ModuleLoader__.load({
707
711
  setGlossMaxLen: 'Max gloss length (chars)',
708
712
  setOpsGroup: 'LLM actions & queue notices',
709
713
  setOpsBadge: 'Actions',
710
- setOpsHint: 'Off collapses the sidebar “LLM actions” block: providers stop enumerating and refine/mutate/ask return 403. Validate is a zero-token local check and stays available.',
714
+ setOpsHint: 'Off collapses the sidebar “LLM actions” block: providers stop enumerating and refine/mutate/ask return 403. The board check no longer needs a button — since v0.7.9 it runs on every reply, and non-conforming output is rejected and asked again.',
711
715
  setOpsEnabled: 'Allow LLM board actions',
712
716
  setNotifyMajor: 'Route structural changes into the input queue (yellow tier)',
713
717
  setNotifyMajorHint: 'Inserts one queue message on add/remove/reorder so the model re-aligns the board; pure status refreshes never trigger it.',
@@ -1077,6 +1081,9 @@ window.__ModuleLoader__.load({
1077
1081
  .pb-ops-out { margin-top: 7px; border-left: 2px solid var(--dsw-alias-brand-primary); padding: 2px 0 2px 7px; color: var(--dsw-alias-label-secondary); font-size: 11px; white-space: pre-wrap; word-break: break-word; }
1078
1082
  .pb-ops-out.bad { border-left-color: var(--dsw-alias-state-error-primary); }
1079
1083
  .pb-ops-out.warn { border-left-color: var(--dsw-alias-state-warn-primary); }
1084
+ .pb-ops-think { margin-top: 7px; border-left: 2px solid var(--dsw-alias-border-l2); padding: 2px 0 2px 7px; }
1085
+ .pb-ops-think-body { color: var(--dsw-alias-label-tertiary); font-size: 10px; white-space: pre-wrap; word-break: break-word; }
1086
+ .pb-ops-area-label { display: block; color: var(--dsw-alias-label-tertiary); font-size: 9px; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 2px; }
1080
1087
  @media (max-width: 760px) { .pb-ops-hint { display: none; } }
1081
1088
  @media (max-width: 520px) { .pb-ops-row { flex-direction: column; } }
1082
1089
  .pb-side-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--dsw-alias-border-l1); color: var(--dsw-alias-label-secondary); font-size: 11px; }
@@ -1608,12 +1615,12 @@ window.__ModuleLoader__.load({
1608
1615
 
1609
1616
  // v0.7.0 R3:侧边栏「LLM 操作」小块。选模型口径学 prime-memory——provider/model
1610
1617
  // 两个下拉由 GET /ops/providers 喂(宿主没给 llm 服务时退回「沿用设置页」)。
1611
- // 四个动作一律 POST /ops,结果就地写回本板(onApplied),不新开顶级标签。
1618
+ // 三个动作一律 POST /ops,结果就地写回本板(onApplied),不新开顶级标签。
1619
+ // v0.7.9:「校验」不再是按钮——板面体检随每次回答自动跑,输出不合格服务端直接打回重问。
1612
1620
  const OPS_ACTIONS = [
1613
1621
  ['refine', 'opsRefine'],
1614
1622
  ['mutate', 'opsMutate'],
1615
1623
  ['ask', 'opsAsk'],
1616
- ['validate', 'opsValidate'],
1617
1624
  ]
1618
1625
 
1619
1626
  async function postOps(payload) {
@@ -1650,19 +1657,27 @@ window.__ModuleLoader__.load({
1650
1657
  return String(m && typeof m === 'object' ? (m.label || m.id || '') : (m || ''))
1651
1658
  }
1652
1659
 
1653
- /** 把 /ops 回执压成一小段可读文本 + 档位(ok/warn/bad 只影响左边条颜色)。 */
1660
+ /**
1661
+ * 把 /ops 回执拆成两区:think = 模型给的一句话理由,text = 结论区。
1662
+ * kind 只决定结论区左边条颜色(ok / warn / bad)。
1663
+ * 体检结论不再单独占一个按钮:refine/mutate 回执里的 validation 顺利通过时
1664
+ * 不占输出区,只有硬错或提醒才落进结论;op=validate(仅剩外部/单测在用)依旧给结论。
1665
+ */
1654
1666
  function opsOutcome(t, json) {
1655
- if (json.op === 'validate') {
1656
- const v = json.validation || {}
1657
- const head = `${v.ok ? t('opsValidOk') : t('opsValidBad')} · ${Number(v.count) || 0} ${t('opsItemsUnit')}`
1658
- const lines = [].concat(v.errors || [], v.warnings || [])
1659
- return { kind: lines.length ? (v.ok ? 'warn' : 'bad') : 'ok', text: [head].concat(lines).join('\n') }
1660
- }
1667
+ const think = String(json.thinking || '').trim()
1668
+ const v = json.validation && typeof json.validation === 'object' ? json.validation : null
1661
1669
  const answer = String(json.answer || '').trim()
1662
1670
  const changed = Array.isArray(json.changes) ? json.changes.length : 0
1663
1671
  const notes = [].concat(json.warnings || [])
1664
- const text = [answer || (changed ? '' : t('opsNoChanges')), notes.join('\n')].filter(Boolean).join('\n')
1665
- return { kind: notes.length ? 'warn' : 'ok', text }
1672
+ const lines = v ? [].concat(v.errors || [], v.warnings || []) : []
1673
+ const verdict = v && (json.op === 'validate' || v.ok !== true || lines.length > 0)
1674
+ ? `${v.ok ? t('opsValidOk') : t('opsValidBad')} · ${Number(v.count) || 0} ${t('opsItemsUnit')}`
1675
+ : ''
1676
+ const retried = Number(json.attempts) > 1 ? `${t('opsRetried')} ${Number(json.attempts) - 1}` : ''
1677
+ const filler = (answer || changed || json.op === 'validate') ? '' : t('opsNoChanges')
1678
+ const text = [filler, answer, verdict, retried, notes.join('\n'), lines.join('\n')].filter(Boolean).join('\n')
1679
+ const kind = v && v.ok !== true ? 'bad' : (notes.length || lines.length ? 'warn' : 'ok')
1680
+ return { think, kind, text }
1666
1681
  }
1667
1682
 
1668
1683
  function LlmOpsBlock({ t, sessionId, disabled, onApplied, onError }) {
@@ -1825,7 +1840,18 @@ window.__ModuleLoader__.load({
1825
1840
  busy === pair[0] ? t('opsBusy') : t(pair[1]),
1826
1841
  )),
1827
1842
  ),
1828
- out ? h('div', { className: out.kind === 'ok' ? 'pb-ops-out' : `pb-ops-out ${out.kind}` }, out.text) : null,
1843
+ out && out.think ? h(
1844
+ 'div',
1845
+ { className: 'pb-ops-think' },
1846
+ h('span', { className: 'pb-ops-area-label' }, t('opsThink')),
1847
+ h('div', { className: 'pb-ops-think-body' }, out.think),
1848
+ ) : null,
1849
+ out && out.text ? h(
1850
+ 'div',
1851
+ { className: out.kind === 'ok' ? 'pb-ops-out' : `pb-ops-out ${out.kind}` },
1852
+ h('span', { className: 'pb-ops-area-label' }, t('opsOut')),
1853
+ out.text,
1854
+ ) : null,
1829
1855
  )
1830
1856
  }
1831
1857
 
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.7.8",
3
+ "version": "0.7.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 双平面),并在 0.6.0 起每回合落一版会话归档(handoff 规则摘要 + 重启注入一次)。",
6
6
  "engines": {
package/index.js CHANGED
@@ -661,7 +661,11 @@ function resultDigest(text, failed) {
661
661
  const OPS_MAX_ITEMS = 60
662
662
  const OPS_MAX_TITLE = 180
663
663
  const OPS_MAX_CHANGES = 8
664
+ const OPS_MAX_ATTEMPTS = 3
664
665
  const OPS_KINDS = new Set(['refine', 'mutate', 'ask', 'validate'])
666
+ const OPS_CHANGE_KINDS = new Set(['add', 'edit', 'remove'])
667
+ // edit 至少要动这一个字段,否则这条改动落下去什么都没变(模型爱犯的空转)。
668
+ const OPS_EDIT_FIELDS = ['title', 'status', 'percent', 'current', 'next', 'note', 'order']
665
669
  // R4:只认这三类结构性变更(增/删/排序)——它们会让「板上第几项在做什么」整体位移。
666
670
  const MAJOR_CHANGE_TAG = 'progress-major-change'
667
671
  const STRUCTURAL_KINDS = new Set(['add', 'remove', 'order'])
@@ -728,34 +732,113 @@ function validateBoard(input) {
728
732
  return { ok: errors.length === 0, count: items.length, errors, warnings }
729
733
  }
730
734
 
731
- // ops 三路 system:严格 JSON、统一形状 `{changes,answer}`、最多 8 条改动。
735
+ /**
736
+ * 校验辅助模型「这一次的输出」吃不吃得下 —— 与 validateBoard 分工不同:
737
+ * validateBoard 管板数据本身合不合法,validateProposal 管模型给回来的形状,
738
+ * 它的 errors 就是打回时要逐条喂回去的话术。绝不抛错。
739
+ * 拦下:非对象 / refine-mutate 缺 changes 数组 / 条目不是对象 / kind 非枚举 /
740
+ * edit-remove 指认板上没有的 id / add 缺 title 或 title 过长 / edit 空转 /
741
+ * status 非枚举 / percent 越界 / order 非数字 / ask 没给 answer。
742
+ * 不拦(走截断或丢弃):条数超 OPS_MAX_CHANGES(截断后仍可部分交付)、
743
+ * ask 硬塞 changes(路由丢弃,不改板就算通过)。
744
+ */
745
+ function validateProposal(state, proposal, op) {
746
+ const errors = []
747
+ if (!isObject(proposal)) {
748
+ return { ok: false, errors: ['输出不是可解析的 JSON 对象(只许输出一个对象,不要解释或代码围栏)'] }
749
+ }
750
+ const answer = typeof proposal.answer === 'string' ? proposal.answer.trim() : ''
751
+ if (op === 'ask') {
752
+ if (!answer) errors.push('answer 必须是非空字符串(问询只回文本,不动板)')
753
+ return { ok: errors.length === 0, errors }
754
+ }
755
+ const raw = Array.isArray(proposal.changes)
756
+ ? proposal.changes
757
+ : (isObject(proposal.board) && Array.isArray(proposal.board.changes) ? proposal.board.changes : null)
758
+ if (!raw) {
759
+ return { ok: false, errors: ['缺少 changes 数组(形状应为 {"thinking":"…","changes":[…],"answer":"…"})'] }
760
+ }
761
+ const items = state && Array.isArray(state.items) ? state.items : []
762
+ const byId = new Map(items.map((item) => [item.id, item]))
763
+ raw.slice(0, OPS_MAX_CHANGES).forEach((c, index) => {
764
+ const at = `第 ${index + 1} 条`
765
+ if (!isObject(c)) {
766
+ errors.push(`${at} 不是对象`)
767
+ return
768
+ }
769
+ const kind = String(c.kind || (c.id ? 'edit' : 'add')).toLowerCase()
770
+ if (!OPS_CHANGE_KINDS.has(kind)) {
771
+ errors.push(`${at} kind 非法:${c.kind}(合法值 add|edit|remove)`)
772
+ return
773
+ }
774
+ if (kind === 'add') {
775
+ const title = typeof c.title === 'string' ? c.title.trim() : ''
776
+ if (!title) errors.push(`${at} kind=add 缺少 title`)
777
+ else if (title.length > OPS_MAX_TITLE) errors.push(`${at} title 过长(${title.length} 字 >${OPS_MAX_TITLE})`)
778
+ } else if (!byId.has(String(c.id || ''))) {
779
+ errors.push(`${at} kind=${kind} 指认的 id 不在板上:${String(c.id || '(空)')}(只能用清单里给过的 id)`)
780
+ return
781
+ } else if (kind === 'edit' && !OPS_EDIT_FIELDS.some((field) => c[field] !== undefined && c[field] !== null && String(c[field]).trim() !== '')) {
782
+ errors.push(`${at} kind=edit 没有任何要改的字段`)
783
+ }
784
+ let status
785
+ if (c.status !== undefined && c.status !== null && String(c.status).trim() !== '') {
786
+ status = normalizeStatus(c.status)
787
+ if (status === undefined) errors.push(`${at} status 非法:${c.status}(合法值 todo|doing|done|blocked)`)
788
+ }
789
+ if (c.percent !== undefined && c.percent !== null) {
790
+ const pct = Number(c.percent)
791
+ if (!Number.isFinite(pct) || pct < 0 || pct > 100) errors.push(`${at} percent 越界:${c.percent}(应为 0-100)`)
792
+ }
793
+ if (c.order !== undefined && c.order !== null && !Number.isFinite(Number(c.order))) {
794
+ errors.push(`${at} order 不是数字:${c.order}`)
795
+ }
796
+ })
797
+ return { ok: errors.length === 0, errors }
798
+ }
799
+
800
+ // 打回时要重新要一次:把上一轮的不合规条目逐条贴回原提示之后。
801
+ function withOpsFeedback(prompt, errors) {
802
+ if (!Array.isArray(errors) || errors.length === 0) return prompt
803
+ return `${prompt}\n\n上一次输出不符合校验格式,逐条问题:\n${errors.map((line) => `- ${line}`).join('\n')}\n请重新只输出一个 JSON 对象(字段与格式同上),不要解释、不要代码围栏。`
804
+ }
805
+
806
+ // ops 三路 system:严格 JSON、统一形状 `{thinking,changes,answer}`、最多 8 条改动。
732
807
  // 只有 refine/mutate 会动板;ask 只回文本,模型若硬塞 changes 也会被路由丢掉。
808
+ // thinking 是给面板「思考区」看的一句话理由,不参与格式判定(缺了不打回)。
809
+ const OPS_JSON_SHAPE = '{"thinking":"<一句话说明你为什么这样改,与板同语言,≤200 字>",'
810
+ + '"changes":[{"kind":"add|edit|remove","id"?:string,"title"?:string,"status"?:"todo|doing|done|blocked","percent"?:0-100,"current"?:string,"next"?:string,"order"?:number}],'
811
+ + '"answer":"<一行结论,同语言>"}'
812
+ const OPS_STRICT_NOTE = ' Your output is checked line by line before it touches the board: every id must exist in the list given to you, '
813
+ + 'kind must be add|edit|remove, status must be one of todo|doing|done|blocked, percent must be 0-100. '
814
+ + 'If anything fails you get the exact reasons back and must output the object again.'
815
+
733
816
  const OPS_REFINE_SYSTEM = 'You refine a user-facing task board so the work is easier to track. '
734
817
  + 'Given the board checklist and an optional focus item, split coarse items into smaller verifiable ones, '
735
818
  + 'give each a concrete title and (when known) current/next text. '
736
819
  + 'Rules: at most ' + OPS_MAX_CHANGES + ' changes; only ONE item may be doing; keep existing ids when editing; '
737
820
  + 'never invent completed work; never touch items outside the given board. '
738
821
  + 'Output strictly ONE JSON object: '
739
- + '{"changes":[{"kind":"add|edit|remove","id"?:string,"title"?:string,"status"?:"todo|doing|done|blocked","percent"?:0-100,"current"?:string,"next"?:string,"order"?:number}],"answer":"<one line, same language as the board>"}. '
740
- + 'Respond with the JSON object only — no prose, no code fences.'
822
+ + OPS_JSON_SHAPE + '.' + OPS_STRICT_NOTE
823
+ + ' Respond with the JSON object only — no prose, no code fences.'
741
824
 
742
825
  const OPS_MUTATE_SYSTEM = 'You apply one user instruction to a user-facing task board: add, edit, reorder or remove items. '
743
826
  + 'Rules: change only what the instruction asks for; at most ' + OPS_MAX_CHANGES + ' changes; use the ids given in the board for edit/remove; '
744
827
  + 'use "order" (0-based) to reorder; never invent completed work; if the instruction is not actionable on a task board, '
745
828
  + 'return zero changes and say why in the answer. '
746
829
  + 'Output strictly ONE JSON object: '
747
- + '{"changes":[{"kind":"add|edit|remove","id"?:string,"title"?:string,"status"?:"todo|doing|done|blocked","percent"?:0-100,"current"?:string,"next"?:string,"order"?:number}],"answer":"<one line, same language as the board>"}. '
748
- + 'Respond with the JSON object only — no prose, no code fences.'
830
+ + OPS_JSON_SHAPE + '.' + OPS_STRICT_NOTE
831
+ + ' Respond with the JSON object only — no prose, no code fences.'
749
832
 
750
833
  const OPS_ASK_SYSTEM = 'You answer ONE short question about a task board, using ONLY the checklist given to you. '
751
834
  + 'You must not change the board: always return an empty changes array. '
752
835
  + 'If the board does not contain the answer, say so plainly instead of guessing. '
753
836
  + 'Answer in the same language as the board, in at most 600 characters. '
754
- + 'Output strictly ONE JSON object: {"changes":[],"answer":"<text>"}. '
837
+ + 'Output strictly ONE JSON object: {"thinking":"<你凭什么这么答,≤200 字>","changes":[],"answer":"<text>"}. '
755
838
  + 'Respond with the JSON object only — no prose, no code fences.'
756
839
 
757
840
  // 纯解析函数导出(仅供 test/plan.test.mjs 单测;不在 dsh 契约面上,勿在插件间消费)。
758
- export { parseChecklistMarkdown, parseSpecOutline, normalizeStatus, planDirCandidates, pickPlanDir, classifyDownload, parseProgress, unwrapAct, isDownloadItem, describeToolStep, glossCommand, resultDigest, validateBoard }
841
+ export { parseChecklistMarkdown, parseSpecOutline, normalizeStatus, planDirCandidates, pickPlanDir, classifyDownload, parseProgress, unwrapAct, isDownloadItem, describeToolStep, glossCommand, resultDigest, validateBoard, validateProposal, withOpsFeedback }
759
842
 
760
843
  const PROGRESS_POLICY = `## 进度板
761
844
  progress_update 维护用户可见的实时进度板。每项含 title/status/percent/current/next/approach/note。
@@ -3453,7 +3536,8 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
3453
3536
  const question = text(body && body.question, 1200) || ''
3454
3537
  const targetId = String(body && body.targetId ? body.targetId : '')
3455
3538
 
3456
- // 校验是纯本地活:不进 LLM、不花 token,面板随时能拿到体检结论。
3539
+ // 校验是纯本地活:不进 LLM、不花 token。面板从 v0.7.9 起不再把它做成按钮
3540
+ // (体检随每次回答自动跑),但路由保留:外部消费者与单测仍能直接要一份体检结论。
3457
3541
  if (op === 'validate') {
3458
3542
  const v = validateBoard(state.items)
3459
3543
  return {
@@ -3494,28 +3578,47 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
3494
3578
  lines.push(`指令:${question}`)
3495
3579
  }
3496
3580
  const system = op === 'refine' ? OPS_REFINE_SYSTEM : (op === 'mutate' ? OPS_MUTATE_SYSTEM : OPS_ASK_SYSTEM)
3497
- let raw
3498
- try {
3499
- raw = await callAssistant({ system, user: lines.join('\n'), a })
3500
- } catch (err) {
3501
- const error = new Error(`辅助模型调用失败:${err instanceof Error ? err.message : String(err)}`)
3502
- error.statusCode = 502
3503
- throw error
3581
+ // 打回重试(v0.7.9):模型这一次的输出必须先过 validateProposal,不过就把
3582
+ // 逐条原因喂回去重新要一次,最多 OPS_MAX_ATTEMPTS 次。不再「丢弃非法条目、
3583
+ // 落盘其余」——那样板会半改,模型也永远收不到「你刚才哪条不合规」的反馈。
3584
+ // 传输失败(宿主报错/超时)不重跑:那不是格式问题,重试只会多花一份 token。
3585
+ const basePrompt = lines.join('\n')
3586
+ let proposal = null
3587
+ let reject = null
3588
+ let attempts = 0
3589
+ while (attempts < OPS_MAX_ATTEMPTS) {
3590
+ attempts += 1
3591
+ let raw
3592
+ try {
3593
+ raw = await callAssistant({ system, user: withOpsFeedback(basePrompt, reject), a })
3594
+ } catch (err) {
3595
+ const error = new Error(`辅助模型调用失败:${err instanceof Error ? err.message : String(err)}`)
3596
+ error.statusCode = 502
3597
+ throw error
3598
+ }
3599
+ const parsed = parseProposal(raw)
3600
+ const check = validateProposal(state, parsed, op)
3601
+ if (check.ok) {
3602
+ proposal = parsed
3603
+ reject = null
3604
+ break
3605
+ }
3606
+ reject = check.errors
3504
3607
  }
3505
- const proposal = parseProposal(raw)
3506
3608
  if (!proposal) {
3507
- const error = new Error('辅助模型没有返回可解析的 JSON')
3609
+ const error = new Error(`辅助模型没有返回符合校验格式的输出(已打回 ${OPS_MAX_ATTEMPTS - 1} 次):${(reject || []).join(';')}`)
3508
3610
  error.statusCode = 502
3509
3611
  throw error
3510
3612
  }
3613
+ const thinking = text(String(proposal.thinking || proposal.reason || ''), 600)
3511
3614
  const answer = text(String(proposal.answer || proposal.note || ''), 1200)
3512
3615
  if (op === 'ask') {
3513
3616
  // 问询只回文本:即使模型硬塞了 changes 也不落盘。
3514
- return { ok: true, op, applied: false, changes: [], warnings: [], answer: answer || '(模型未给出回答)' }
3617
+ return { ok: true, op, applied: false, changes: [], warnings: [], thinking, attempts, answer: answer || '(模型未给出回答)' }
3515
3618
  }
3516
3619
  const mapped = opsChanges(state, proposal)
3517
3620
  if (mapped.length === 0) {
3518
- return { ok: true, op, applied: false, changes: [], warnings: answer ? [] : ['模型未提出可用改动'], answer: answer || '无需改动' }
3621
+ return { ok: true, op, applied: false, changes: [], warnings: answer ? [] : ['模型未提出可用改动'], thinking, attempts, answer: answer || '无需改动' }
3519
3622
  }
3520
3623
  const result = await applyChanges({ sessionId, changes: mapped, origin: 'ops' })
3521
3624
  const post = validateBoard(result.snapshot.items)
@@ -3524,7 +3627,12 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
3524
3627
  op,
3525
3628
  applied: true,
3526
3629
  changes: result.changed,
3527
- warnings: (result.warnings || []).concat(post.errors),
3630
+ warnings: result.warnings || [],
3631
+ thinking,
3632
+ attempts,
3633
+ // 落盘后的板面体检结论:不再占一个按钮,随每次回答自动跑。
3634
+ // 客户端只在「不 ok 或有提醒」时才把它显示出来,顺利通过时不占输出区。
3635
+ validation: { ok: post.ok, count: post.count, errors: post.errors, warnings: post.warnings },
3528
3636
  answer: answer || `已应用 ${result.changed.length} 条改动`,
3529
3637
  notified: result.notified === true,
3530
3638
  noticeMerged: result.noticeMerged === true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "type": "module",
5
5
  "description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎;向压缩插件暴露只读三层进度锚点(service + HTTP 双平面);0.6.0 起每回合落一版会话归档(handoff + 重启注入一次)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
6
6
  "license": "MIT",
@@ -315,11 +315,44 @@ test('rc.3:opsOutcome 对 refine/mutate/ask 只回文本,没落地也不冒
315
315
  assert.equal(warned.text, '只有 1 项在做\n同时 doing 2 项')
316
316
  })
317
317
 
318
+ test('0.7.9:回执拆「思考 / 输出」两区,体检通过不占输出区,打回次数只在 >1 时出现', () => {
319
+ const outcome = loadOpsOutcome()
320
+ const t = (key) => key
321
+ const clean = outcome(t, {
322
+ op: 'refine',
323
+ thinking: '按数据面与展示面拆两步',
324
+ answer: '已拆成两步',
325
+ changes: [{ id: 'a' }],
326
+ warnings: [],
327
+ attempts: 1,
328
+ validation: { ok: true, count: 4, errors: [], warnings: [] },
329
+ })
330
+ assert.equal(clean.think, '按数据面与展示面拆两步', '思考区拿 thinking 字段')
331
+ assert.equal(clean.text, '已拆成两步', '体检顺利通过时不再往输出区插一行「校验通过」')
332
+ assert.equal(clean.kind, 'ok')
333
+ const retried = outcome(t, { op: 'mutate', answer: '重新给一版', changes: [{ id: 'a' }], warnings: [], attempts: 2 })
334
+ assert.match(retried.text, /opsRetried 1/, '被打回过一次必须告知用户重问了几轮')
335
+ const noRetry = outcome(t, { op: 'mutate', answer: '删掉了', changes: [{ id: 'a' }], warnings: [], attempts: 1 })
336
+ assert.equal(noRetry.text.includes('opsRetried'), false, '一次过的不应多一行噪声')
337
+ const warned = outcome(t, { op: 'refine', answer: '已落盘', changes: [{ id: 'a' }], warnings: [], attempts: 1, validation: { ok: true, count: 4, errors: [], warnings: ['同时 doing 2 项'] } })
338
+ assert.equal(warned.kind, 'warn', '体检有提醒 → warn 档,要落进输出区')
339
+ assert.match(warned.text, /同时 doing 2 项/)
340
+ const broken = outcome(t, { op: 'refine', answer: '已落盘', changes: [{ id: 'a' }], warnings: [], attempts: 1, validation: { ok: false, count: 61, errors: ['项数 61 超过上限'], warnings: [] } })
341
+ assert.equal(broken.kind, 'bad')
342
+ assert.match(broken.text, /opsValidBad/)
343
+ assert.match(broken.text, /项数 61 超过上限/)
344
+ const quiet = outcome(t, { op: 'ask', answer: '只有 1 项在做', changes: [], warnings: [] })
345
+ assert.equal(quiet.think, '', '模型没给 thinking 时思考区整块缺席,不留空框')
346
+ })
347
+
318
348
  test('rc.3:LLM 操作块只读 providers + POST /ops,不开新标签也不动路由面', () => {
319
349
  const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
320
350
  assert.match(src, /fetch\(`\$\{API\}\/ops\/providers`/, 'provider 下拉必须拉宿主面,不在客户端写死')
321
- assert.match(src, /fetch\(`\$\{API\}\/ops`, \{\n\s+method: 'POST'/, '四个动作统一走 POST /ops')
322
- assert.match(src, /const OPS_ACTIONS = \[\s*\['refine', 'opsRefine'\],\s*\['mutate', 'opsMutate'\],\s*\['ask', 'opsAsk'\],\s*\['validate', 'opsValidate'\],/, '恰好四个动作,不多不少')
351
+ assert.match(src, /fetch\(`\$\{API\}\/ops`, \{\n\s+method: 'POST'/, '动作统一走 POST /ops')
352
+ assert.match(src, /const OPS_ACTIONS = \[\s*\['refine', 'opsRefine'\],\s*\['mutate', 'opsMutate'\],\s*\['ask', 'opsAsk'\],/, '恰好三个动作——v0.7.9 起「校验」不再上按钮')
353
+ assert.equal(src.includes("['validate', 'opsValidate']"), false, '按钮位不得残留 validate')
354
+ const server = fs.readFileSync(path.join(path.dirname(clientFile), 'index.js'), 'utf8')
355
+ assert.ok(server.includes("if (op === 'validate')"), '服务端 validate 路由必须保留(只是面板不再露出)')
323
356
  // 不新开顶级标签:只允许在 ProgressSidePanel 里渲染一次,且不能新增任何 tab/slot 注册
324
357
  const panelStart = src.indexOf('function ProgressSidePanel(props) {')
325
358
  const panelEnd = src.indexOf("inject: ['slots', 'locale'", panelStart)
@@ -340,6 +373,9 @@ test('rc.3:LLM 操作块只读 providers + POST /ops,不开新标签也不
340
373
  assert.match(block, /if \(data\.disabled\) \{[\s\S]*setOff\(true\)/, 'disabled 必须先于 setProviders 短路')
341
374
  assert.match(block, /if \(off\) return null/, '开关关掉时整个操作块不渲染')
342
375
  assert.ok(block.indexOf('if (off) return null') > block.indexOf('useEffect('), '早退必须在全部 hooks 之后,不破坏 hook 顺序')
376
+ // 两区渲染:思考区只在模型给了 thinking 时出现,不留空框
377
+ assert.match(block, /out && out\.think \? h\(\s*'div',\s*\{ className: 'pb-ops-think' \}/, '思考区挂在输出区之前')
378
+ assert.match(block, /out && out\.text \? h\(\s*'div',\s*\{ className: out\.kind === 'ok' \? 'pb-ops-out'/, '结论区仍按 ok/warn/bad 三档取色')
343
379
  })
344
380
 
345
381
  test('rc.3:操作块样式只用宿主令牌,窄屏降级', () => {
@@ -355,11 +391,14 @@ test('rc.3:操作块样式只用宿主令牌,窄屏降级', () => {
355
391
  assert.match(css, /\.pb-ops-out\.warn \{[^}]*var\(--dsw-alias-state-warn-primary\)/, '可疑档用 warn 令牌')
356
392
  assert.match(css, /@media \(max-width: 760px\) \{ \.pb-ops-hint \{ display: none; \} \}/, '窄屏收掉提示文案')
357
393
  assert.match(css, /@media \(max-width: 520px\) \{ \.pb-ops-row \{ flex-direction: column; \} \}/, '极窄屏下拉竖排')
394
+ assert.match(css, /\.pb-ops-think \{[^}]*var\(--dsw-alias-border-l2\)/, '思考区左边线用次级边框令牌')
395
+ assert.match(css, /\.pb-ops-think-body \{[^}]*var\(--dsw-alias-label-tertiary\)/, '思考区正文用三级文字令牌(比输出区低一档)')
396
+ assert.match(css, /\.pb-ops-area-label \{[^}]*var\(--dsw-alias-label-tertiary\)/, '分区标题用文字令牌')
358
397
  })
359
398
 
360
399
  test('rc.3:操作块文案 zh/en 成对(本仓 client 只有内联 zh/en 两份字典)', () => {
361
400
  const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
362
- const keys = ['opsTitle', 'opsHint', 'opsProvider', 'opsModel', 'opsProviderNone', 'opsQuestion', 'opsRefine', 'opsMutate', 'opsAsk', 'opsValidate', 'opsBusy', 'opsNoChanges', 'opsValidOk', 'opsValidBad', 'opsItemsUnit']
401
+ const keys = ['opsTitle', 'opsHint', 'opsProvider', 'opsModel', 'opsProviderNone', 'opsQuestion', 'opsRefine', 'opsMutate', 'opsAsk', 'opsBusy', 'opsNoChanges', 'opsThink', 'opsOut', 'opsRetried', 'opsValidOk', 'opsValidBad', 'opsItemsUnit']
363
402
  for (const k of keys) {
364
403
  const hits = src.match(new RegExp(`\\n\\s+${k}: '[^']+',`, 'g')) || []
365
404
  assert.equal(hits.length, 2, `${k} 必须在 zh/en 各出现一次(实得 ${hits.length})`)
package/test/ops.test.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * 0.7.0 rc.3 验收:R3 侧边栏 LLM 任务操作。
3
- * validateBoard 纯函数 + /ops/providers + /ops 四操作(refine/mutate/ask/validate)。
4
- * 硬约束:不新开顶级标签、零新增依赖;模型返回非法数据一律不落盘;
5
- * origin='ops' 不得让主模型看起来「刚刚同步过板」(stepsSinceModel 不归零)。
3
+ * validateBoard / validateProposal 纯函数 + /ops/providers + /ops 三操作
4
+ * (refine/mutate/ask;validate 只留路由,面板不再放按钮)。
5
+ * 0.7.9 硬约束:模型输出不符格式一律打回重问(最多三轮),绝不半应用;
6
+ * 不新开顶级标签、零新增依赖;
7
+ * origin='ops' 不得让主模型看起来「同步过板」(stepsSinceModel 不归零)。
6
8
  */
7
9
  import assert from 'node:assert/strict'
8
10
  import fs from 'node:fs'
@@ -12,7 +14,7 @@ import test from 'node:test'
12
14
 
13
15
  process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
14
16
  const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
15
- const { validateBoard } = await import('../index.js')
17
+ const { validateBoard, validateProposal } = await import('../index.js')
16
18
 
17
19
  const OPS = '/progress-union/ops'
18
20
 
@@ -85,6 +87,42 @@ test('validateBoard:可疑但可写的只进 warnings(空板/重复 title/or
85
87
  assert.match(dup.warnings.join(' '), /同时 doing 2 项/)
86
88
  })
87
89
 
90
+ // ── validateProposal(模型输出格式门)────────────────────────────────
91
+
92
+ test('validateProposal:合规输出直接过;thinking 只是展示字段,缺了不打回', () => {
93
+ const state = { items: [{ id: 'a', title: '甲' }, { id: 'b', title: '乙' }] }
94
+ assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'doing' }], answer: 'ok' }, 'refine').ok, true)
95
+ assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }] }, 'mutate').ok, true, '无 thinking 也必须过')
96
+ assert.equal(validateProposal(state, { board: { changes: [{ kind: 'remove', id: 'b' }] } }, 'mutate').ok, true, '兼容 {board:{changes}} 旧形状')
97
+ assert.equal(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'done' }], answer: '完成' }, 'mutate').ok, true, 'done 不强制带 percent:落盘时由 applyOneChange 补 100')
98
+ })
99
+
100
+ test('validateProposal:吃不下的一律打回(非对象/缺 changes/kind 非枚举/幽灵 id/缺 title/edit 空转/percent 越界)', () => {
101
+ const state = { items: [{ id: 'a', title: '甲' }] }
102
+ const none = validateProposal(state, null, 'refine')
103
+ assert.equal(none.ok, false)
104
+ assert.match(none.errors[0], /不是可解析的 JSON 对象/)
105
+ assert.match(validateProposal(state, { answer: 'x' }, 'refine').errors.join(' '), /缺少 changes 数组/)
106
+ assert.match(validateProposal(state, { changes: ['nope'] }, 'refine').errors.join(' '), /不是对象/)
107
+ assert.match(validateProposal(state, { changes: [{ kind: 'teleport', id: 'a' }] }, 'refine').errors.join(' '), /kind 非法/)
108
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'ghost', status: 'done' }] }, 'refine').errors.join(' '), /不在板上/)
109
+ assert.match(validateProposal(state, { changes: [{ kind: 'remove', id: 'ghost' }] }, 'mutate').errors.join(' '), /不在板上/)
110
+ assert.match(validateProposal(state, { changes: [{ kind: 'add', title: ' ' }] }, 'refine').errors.join(' '), /缺少 title/)
111
+ assert.match(validateProposal(state, { changes: [{ kind: 'add', title: '很长的'.repeat(70) }] }, 'refine').errors.join(' '), /title 过长/)
112
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a' }] }, 'refine').errors.join(' '), /没有任何要改的字段/)
113
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', status: 'pending-ish' }] }, 'refine').errors.join(' '), /status 非法/)
114
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', percent: 140 }] }, 'refine').errors.join(' '), /percent 越界/)
115
+ assert.match(validateProposal(state, { changes: [{ kind: 'edit', id: 'a', order: 'x' }] }, 'refine').errors.join(' '), /order 不是数字/)
116
+ })
117
+
118
+ test('validateProposal:条数超上限只截断不打回;ask 只硬要求 answer', () => {
119
+ const state = { items: [{ id: 'a', title: '甲' }] }
120
+ const many = { changes: Array.from({ length: 12 }, (_, i) => ({ kind: 'add', title: '拆项 ' + i })) }
121
+ assert.equal(validateProposal(state, many, 'refine').ok, true, '超上限走截断(可部分交付),不因此烧 token 重问')
122
+ assert.equal(validateProposal(state, { changes: [], answer: ' ' }, 'ask').ok, false, 'ask 没 answer 等于没回答')
123
+ assert.equal(validateProposal(state, { changes: [{ kind: 'add', title: '丙' }], answer: '好' }, 'ask').ok, true, 'ask 硬塞 changes 由路由丢弃,不算格式错')
124
+ })
125
+
88
126
  // ── /ops/providers ──────────────────────────────────────────────────────
89
127
 
90
128
  test('providers:llm.listProviders 有值就列出来;服务缺失退回空数组不报错', async () => {
@@ -144,26 +182,30 @@ test('op=validate 纯本地跑,一次 llm 调用都不发', async () => {
144
182
 
145
183
  // ── /ops refine / mutate:落盘 + 护栏 ──────────────────────────────────
146
184
 
147
- test('op=refine 落盘 add+edit(order),并回 snapshot;updatedBy 走 ops 通道', async () => {
185
+ test('op=refine 合规输出落盘 add+edit(order):thinking / attempts / 自动体检一并回给客户端', async () => {
186
+ let reply = '{}'
148
187
  const calls = []
149
- const harness = await booted({
150
- calls,
151
- reply: JSON.stringify({
152
- changes: [
153
- { kind: 'add', title: '拆:解析 tool/result', status: 'todo', percent: 0 },
154
- { kind: 'edit', id: 'not-a-real-id', status: 'done' },
155
- { kind: 'add', title: '' },
156
- ],
157
- answer: '已按数据面拆成两步',
158
- }),
159
- })
188
+ const harness = await booted({ calls, reply: () => reply })
160
189
  const before = await snapshot(harness)
190
+ const target = before.items.find((i) => i.title === '写面板')
191
+ assert.ok(target, '种子板必须有「写面板」项')
192
+ reply = JSON.stringify({
193
+ thinking: '「写面板」偏粗,拆成数据面与展示面两步',
194
+ changes: [
195
+ { kind: 'add', title: '拆:解析 tool/result', status: 'todo', percent: 0 },
196
+ { kind: 'edit', id: target.id, status: 'doing', percent: 40 },
197
+ ],
198
+ answer: '已按数据面拆成两步',
199
+ })
161
200
  const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
162
201
  assert.equal(r.json.ok, true)
163
202
  assert.equal(r.json.applied, true)
164
- assert.equal(r.json.changes.length, 1, '假 id 与空 title 必须被丢掉')
165
- assert.equal(r.json.changes[0].change, 'add')
203
+ assert.equal(r.json.changes.length, 2)
166
204
  assert.equal(r.json.answer, '已按数据面拆成两步')
205
+ assert.equal(r.json.thinking, '「写面板」偏粗,拆成数据面与展示面两步', '思考区要原样透出')
206
+ assert.equal(r.json.attempts, 1, '一次就合规不应重试')
207
+ assert.equal(r.json.validation.ok, true, '落盘后的体检结论随回执自动带回')
208
+ assert.deepEqual(r.json.validation.errors, [])
167
209
  assert.equal(calls.length, 1)
168
210
  assert.equal(calls[0].provider, 'local')
169
211
  assert.equal(calls[0].model, 'qwen')
@@ -172,15 +214,62 @@ test('op=refine 落盘 add+edit(order),并回 snapshot;updatedBy 走 ops 通
172
214
  assert.equal(after.revision, before.revision + 1)
173
215
  })
174
216
 
217
+ test('输出不符格式(幽灵 id + 空 title)→ 打回重问,第两轮合规才落盘', async () => {
218
+ const seq = [
219
+ JSON.stringify({ changes: [{ kind: 'edit', id: 'not-a-real-id', status: 'done' }, { kind: 'add', title: '' }], answer: 'x' }),
220
+ JSON.stringify({ thinking: '上一条用了板上没有的 id', changes: [{ kind: 'add', title: '拆:校验回写' }], answer: '重新给一版' }),
221
+ ]
222
+ const calls = []
223
+ const harness = await booted({ calls, reply: () => seq.shift() })
224
+ const before = await snapshot(harness)
225
+ const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
226
+ assert.equal(r.json.applied, true)
227
+ assert.equal(r.json.attempts, 2, '第一轮必须被打回')
228
+ assert.equal(r.json.changes.length, 1)
229
+ assert.equal(r.json.answer, '重新给一版')
230
+ assert.equal(calls.length, 2, '打回要真的再问一次')
231
+ const second = calls[1].messages[0].content[0].text
232
+ assert.match(second, /不符合校验格式/, '打回时要把原提示与错误清单一起喂回')
233
+ assert.match(second, /不在板上/)
234
+ assert.match(second, /缺少 title/)
235
+ const after = await snapshot(harness)
236
+ assert.equal(after.revision, before.revision + 1, '不允许半应用:只在合规那一轮落盘')
237
+ })
238
+
239
+ test('三轮都不合规 → 502,一次板都未动', async () => {
240
+ const calls = []
241
+ const harness = await booted({ calls, reply: '{"changes":[{"kind":"teleport","id":"x"}]}' })
242
+ const before = await snapshot(harness)
243
+ const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
244
+ assert.equal(r.status, 502)
245
+ assert.match(r.json.error, /没有返回符合校验格式的输出/)
246
+ assert.match(r.json.error, /kind 非法/)
247
+ assert.equal(calls.length, 3, '一次原始 + 两次打回')
248
+ assert.equal((await snapshot(harness)).revision, before.revision, '打回失败不许留痕')
249
+ })
250
+
251
+ test('op=ask 没给 answer 也算不合格,打回一轮后取到回答', async () => {
252
+ const seq = ['{"changes":[]}', '{"thinking":"板上只有一项 doing","changes":[],"answer":"只有「接数据面」在做"}']
253
+ const calls = []
254
+ const harness = await booted({ calls, reply: () => seq.shift() })
255
+ const r = await ops(harness, { sessionId: SESSION, op: 'ask', question: '现在卡在哪' })
256
+ assert.equal(r.json.ok, true)
257
+ assert.equal(r.json.attempts, 2)
258
+ assert.match(r.json.answer, /只有「接数据面」/)
259
+ assert.equal(r.json.thinking, '板上只有一项 doing')
260
+ assert.equal(calls.length, 2)
261
+ })
262
+
175
263
  test('op=mutate 能把指令翻成删除(只认板上真 id),并触发 R4 队列提醒', async () => {
176
264
  let reply = '{}'
177
265
  const harness = await booted({ reply: () => reply })
178
266
  const snap = await snapshot(harness)
179
267
  const last = snap.items.find((i) => i.title === '补测试')
180
- reply = JSON.stringify({ changes: [{ kind: 'remove', id: last.id }, { kind: 'remove', id: 'ghost-id' }], answer: '删掉了' })
268
+ reply = JSON.stringify({ changes: [{ kind: 'remove', id: last.id }], answer: '删掉了' })
181
269
  const r = await ops(harness, { sessionId: SESSION, op: 'mutate', question: '把补测试删掉' })
182
270
  assert.equal(r.json.applied, true)
183
- assert.deepEqual(r.json.changes, [{ id: last.id, title: '补测试', removed: true }], '不存在的 id 必须被丢掉')
271
+ assert.equal(r.json.attempts, 1, '只给板上真 id 就是一次过')
272
+ assert.deepEqual(r.json.changes, [{ id: last.id, title: '补测试', removed: true }])
184
273
  const after = await snapshot(harness)
185
274
  assert.equal(after.items.some((i) => i.title === '补测试'), false)
186
275
  // R4:删除是结构性变更 → idle 走 followup 落队列
@@ -219,12 +308,14 @@ test('未配置辅助模型 → 400,且不落任何改动', async () => {
219
308
  assert.equal(after.revision, before.revision, '拿不到模型就不许动板')
220
309
  })
221
310
 
222
- test('模型乱答(无 JSON)→ 502,板不变', async () => {
223
- const harness = await booted({ reply: '我觉得可以拆成三步,你先看看代码' })
311
+ test('模型乱答(无 JSON)→ 三轮都拉不回来,502 且板不变', async () => {
312
+ const calls = []
313
+ const harness = await booted({ calls, reply: '我觉得可以拆成三步,你先看看代码' })
224
314
  const before = await snapshot(harness)
225
315
  const r = await ops(harness, { sessionId: SESSION, op: 'refine' })
226
316
  assert.equal(r.status, 502)
227
- assert.match(r.json.error, /无法解析|没有返回/)
317
+ assert.match(r.json.error, /无法解析|没有返回|不是可解析/)
318
+ assert.equal(calls.length, 3, '纯文本回答同样走打回,不是一次就放弃')
228
319
  assert.equal((await snapshot(harness)).revision, before.revision)
229
320
  })
230
321