dsh-progress-union 0.1.5 → 0.1.7

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 ADDED
@@ -0,0 +1,68 @@
1
+ # 更新日志
2
+
3
+ 本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
+
5
+ > 说明:0.1.0 是真实构建产物;0.1.1–0.1.6 由 0.1.0 → 最终态的可核验 diff 按功能块「逻辑分化重建」,每一版都只包含该版本描述的能力,源码逐版可执行;0.1.7 是发布工程面。
6
+
7
+ ## 0.1.7 (2026-11-26)
8
+
9
+ **发布工程面。**
10
+
11
+ - 仓库落地:`repository`/`homepage`/`bugs` 指向 GitHub,`publishConfig` 固定 npmjs + public + latest;
12
+ - `engines.dsh` 与 `dsh.plugin.json` 对齐(`>=0.2.0-0 <0.3.0-0`),双清单版本同值;
13
+ - 包内容纳入 `test/` 与 `CHANGELOG.md`;README 补安装面并移除"不发 npm"表述;
14
+ - 测试:47 用例全绿(`node --test test/*.test.mjs`);代码与 0.1.6 一致,无行为变更。
15
+
16
+ ## 0.1.6 (2026-11-26)
17
+
18
+ **`/progress-goal` 命令面。**
19
+
20
+ - `status`/`budget <n>`/`edit <objective>`/`pause`/`resume`/`clear` 六个子命令,其余输入视为新目标;
21
+ - 命令只在宿主注册了 `commands` 服务时挂载,缺失则静默降级。
22
+
23
+ ## 0.1.5 (2026-11-26)
24
+
25
+ **模型侧 `progress_goal_report` 工具。**
26
+
27
+ - 模型每轮末上报 `continue|complete|blocked`:`complete` 必须给证据且进度板已全 done;`blocked` 需具体 blocker 且连续 3 轮同因才落 phase;
28
+ - 助手草案只作建议,绝不自动调用此工具。
29
+
30
+ ## 0.1.4 (2026-11-26)
31
+
32
+ **助手双通道 + 护栏 + 面板可编辑。**
33
+
34
+ - `registered` 走宿主 `llm.stream`(复用 Settings→模型里的 provider/model,免密钥);`direct` 走自建 OpenAI 兼容端点;
35
+ - `authority` 三档(slots/rounds/both)+`maxSlotChanges` 护栏:助手可增删改槽位、产出轮次草案,判断权仍归主模型;用户未确认改动优先(先 ack);
36
+ - 面板 `LlmAssistNotice` 升级为可展开编辑器(模式/提供方/模型/端点/密钥/权限/保存),配置写入 settings 命名空间即时生效。
37
+
38
+ ## 0.1.3 (2026-11-26)
39
+
40
+ **续轮驱动器(重试)。**
41
+
42
+ - idle 时自动派发下一轮 `followup`,消息带自建 `source.kind`;`pre-step` 身份栅栏精确匹配 attempt/goalId/revision/round,不匹配直接 reject;
43
+ - 任何非本域消息进 inbox 视为用户抢占:标记 attempt stale 并暂停目标;
44
+ - 轮次草案随 followup 拼入,回合切换时清空,避免跨轮复用。
45
+
46
+ ## 0.1.2 (2026-11-26)
47
+
48
+ **迷你目标域内核(自建,不复用官方 goals 域)。**
49
+
50
+ - `goal` 状态机(idle/active/paused/blocked/complete)+ 状态归一化 + 预算 `maxRounds`;
51
+ - create/edit/budget/pause/resume/clear 与 `goalView` 播报视图;快照回声新增 `goal` 字段;
52
+ - 助手提示词带上当前目标,观察者不再只看到板。
53
+
54
+ ## 0.1.1 (2026-11-26)
55
+
56
+ **设置面。**
57
+
58
+ - 导出 `Config`(schemastery),progress-union 出现在「设置 → 插件」,客户端 `scopeOf('progress-union')` 可读写;
59
+ - 注入 `settings`/`llm`/`commands`;`.volatile()` 字段支持 live ref(带 `.get()`)解包,面板改了立即生效;
60
+ - `DEFAULT_CONFIG.assistant` 扩展(provider/authority/maxSlotChanges),配置回声按 settings 实时值输出。
61
+
62
+ ## 0.1.0 (2026-11-25)
63
+
64
+ **首个原型。**
65
+
66
+ - board 槽位真相源(用户可编辑、revision/diff/ack 增量、staleness nudge);
67
+ - 鲸程时间引擎(step 计数、elapsed、ETA 四档 board > todo > local > prior);
68
+ - 只读三层进度锚点 `progressAnchor`(service + HTTP 双平面),供压缩类插件消费。
package/README.md CHANGED
@@ -7,6 +7,15 @@
7
7
  - [l3j3y3/dsh-progress-board](https://github.com/l3j3y3/dsh-progress-board) —— 用户可编辑实时进度板(槽位、revision/diff/ack、staleness nudge)
8
8
  - [uuhihj/task-progress-bar](https://github.com/uuhihj/task-progress-bar)(鲸程 dsh-progress-widget)—— 事件时间引擎(steps/elapsed/ETA 学习链)
9
9
 
10
+ ## 安装
11
+
12
+ ```bash
13
+ npm i dsh-progress-union # 走 npm 版本号
14
+ # 或本地开发:pnpm --dir <profile> add file:<repo>/dsh-progress-union-<ver>.tgz
15
+ ```
16
+
17
+ 装好后在 profile 的 `dsh.profile.bundles` 里挂上 `dsh-progress-union`,重启宿主加载;设置面在「设置 → 插件 → progress-union」。
18
+
10
19
  ## 它解决什么
11
20
 
12
21
  长程任务被上下文压缩时最容易丢的是"我干到哪了"。本插件把这件事拆成两个正交数据面并统一出口:
@@ -135,7 +144,7 @@ assistant:
135
144
 
136
145
  - 不修改上游两仓库;不改 dsh-prime-memory / dsh-spirit / dsh-brief-sidebar / dsh-context-compression-improved 的任何代码。
137
146
  - `slotTrail` 恒为 `null`:prime-memory 关闭槽位 → L1 记忆的"后置清理扇出"仅有定性方案(见 `docs/`),字段为未来集成预留。
138
- - 不发 npm;原型验证消费方后再谈发布门禁。
147
+ - 发布形态:npm 包 `dsh-progress-union` 自 0.1.0 起逐版打 tag 与 GitHub Release;宿主侧按 npm 版本号安装,不再依赖本地 tgz。
139
148
 
140
149
  ## docs/
141
150
 
@@ -146,5 +155,5 @@ assistant:
146
155
  ## 开发与测试
147
156
 
148
157
  ```bash
149
- npm test # node --test test/*.test.mjs(41 用例,纯 mock ctx,无需宿主进程)
158
+ npm test # node --test test/*.test.mjs(47 用例,纯 mock ctx,无需宿主进程)
150
159
  ```
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
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
@@ -2660,6 +2660,57 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
2660
2660
  'progress-union: progress_goal_report tool',
2661
2661
  )
2662
2662
 
2663
+ if (commands) {
2664
+ ctx.effect(
2665
+ () =>
2666
+ commands.register({
2667
+ name: 'progress-goal',
2668
+ description: '设置一个长程目标,自动续轮推进(预算/检查/重试),替代 /goal',
2669
+ input: { hint: '[<objective>|status|budget <n>|edit <objective>|pause|resume|clear]' },
2670
+ handler: async ({ agent, rawInput }) => {
2671
+ const sessionId = sessionOfAgent(agent)
2672
+ const raw = String(rawInput || '').trim()
2673
+ const lower = raw.toLowerCase()
2674
+ try {
2675
+ if (lower === 'status' || raw === '') {
2676
+ const view = goalView(sessionId)
2677
+ return { kind: 'success', text: view.phase === 'idle' ? '没有目标。用法:/progress-goal <objective>' : renderGoalViewText(view) }
2678
+ }
2679
+ if (lower === 'clear') {
2680
+ const current = goalView(sessionId)
2681
+ if (current.phase === 'idle') return { kind: 'success', text: '没有目标可清除。' }
2682
+ await clearGoal(sessionId)
2683
+ return { kind: 'success', text: '目标已清除。' }
2684
+ }
2685
+ if (lower === 'pause') {
2686
+ const view = await pauseGoal(sessionId)
2687
+ return { kind: 'success', text: `目标已暂停\n${renderGoalViewText(view)}` }
2688
+ }
2689
+ if (lower === 'resume') {
2690
+ const view = await resumeGoal(sessionId)
2691
+ return { kind: 'success', text: `目标已恢复\n${renderGoalViewText(view)}` }
2692
+ }
2693
+ if (/^budget(?=\s)/i.test(raw)) {
2694
+ const value = raw.slice(6).trim()
2695
+ const view = await setGoalBudget(sessionId, Number(value))
2696
+ return { kind: 'success', text: `预算已更新\n${renderGoalViewText(view)}` }
2697
+ }
2698
+ if (/^edit(?=\s)/i.test(raw)) {
2699
+ const view = await editGoal(sessionId, raw.slice(4).trim())
2700
+ return { kind: 'success', text: `目标已更新\n${renderGoalViewText(view)}` }
2701
+ }
2702
+ // 其余一律当作新目标 objective
2703
+ const view = await createGoal(sessionId, raw)
2704
+ return { kind: 'success', text: `目标已创建\n${renderGoalViewText(view)}` }
2705
+ } catch (err) {
2706
+ return { kind: 'error', text: err instanceof Error ? err.message : String(err) }
2707
+ }
2708
+ },
2709
+ }),
2710
+ 'progress-union: /progress-goal command',
2711
+ )
2712
+ }
2713
+
2663
2714
  const agentDisposers = new Map()
2664
2715
  function bindAgentContext(agent) {
2665
2716
  const sessionId = sessionOfAgent(agent)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
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",
@@ -27,13 +27,16 @@
27
27
  "cordis.patch.yml",
28
28
  "dsh.plugin.json",
29
29
  "icon.svg",
30
- "docs/"
30
+ "docs/",
31
+ "test/",
32
+ "CHANGELOG.md"
31
33
  ],
32
34
  "scripts": {
33
35
  "test": "node --test test/*.test.mjs"
34
36
  },
35
37
  "engines": {
36
- "node": ">=22.19.0"
38
+ "node": ">=22.19.0",
39
+ "dsh": ">=0.2.0-0 <0.3.0-0"
37
40
  },
38
41
  "dsh": {
39
42
  "bundle": {
@@ -57,7 +60,9 @@
57
60
  "dsh-plugin",
58
61
  "progress-board",
59
62
  "progress-anchor",
60
- "compaction"
63
+ "compaction",
64
+ "progress-tracking",
65
+ "eta"
61
66
  ],
62
67
  "repository": {
63
68
  "type": "git",
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Phase 3 验收:progressAnchor 锚点——schema 全集 / 双平面字节同形 / 同态 /
3
+ * rev 对账 / userEdits 硬约束可见 / projection 判脏。
4
+ */
5
+ import assert from 'node:assert/strict'
6
+ import fs from 'node:fs'
7
+ import os from 'node:os'
8
+ import path from 'node:path'
9
+ import test from 'node:test'
10
+
11
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
12
+ const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
13
+
14
+ async function booted() {
15
+ const harness = createHarness()
16
+ await harness.run()
17
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
18
+ return harness
19
+ }
20
+
21
+ function execUpdate(harness, args) {
22
+ return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
23
+ }
24
+
25
+ function anchorOf(harness, atMs) {
26
+ return harness.provided.get('progressAnchor').get(SESSION, atMs)
27
+ }
28
+
29
+ test('schema 全集:version=1 字段齐、类型对、slotTrail 预留为 null', async () => {
30
+ const harness = await booted()
31
+ await execUpdate(harness, { changes: [{ title: '甲', status: 'doing', current: '写代码', next: '测试' }] })
32
+ harness.emit('turn/start', {})
33
+ const anchor = anchorOf(harness)
34
+ assert.equal(anchor.version, 1)
35
+ assert.equal(anchor.sessionId, SESSION)
36
+ assert.equal(typeof anchor.revision, 'number')
37
+ assert.equal(typeof anchor.updatedAt, 'number')
38
+ assert.deepEqual(Object.keys(anchor.board).sort(), ['enabled', 'inFlight', 'pendingUserChanges', 'summary'])
39
+ assert.deepEqual(Object.keys(anchor.board.summary).sort(), ['blocked', 'doing', 'done', 'percent', 'todo', 'total'])
40
+ assert.deepEqual(Object.keys(anchor.board.inFlight[0]).sort(), ['current', 'id', 'next', 'percent', 'status', 'title'])
41
+ assert.deepEqual(Object.keys(anchor.time).sort(), ['elapsedSec', 'etaBasis', 'etaMin', 'etaP75Min', 'overMin', 'staleMin', 'startedAt', 'steps', 'todoDone', 'todoTotal'])
42
+ assert.equal(typeof anchor.persistent, 'boolean')
43
+ assert.equal(anchor.slotTrail, null)
44
+ assert.ok(Array.isArray(anchor.userEdits))
45
+ })
46
+
47
+ test('双平面字节同形 + 同态:同 (revision, now) service 与 HTTP 输出逐字节相等', async () => {
48
+ const harness = await booted()
49
+ await execUpdate(harness, { changes: [{ title: '甲', status: 'done' }, { title: '乙', status: 'doing' }] })
50
+ harness.emit('turn/start', {})
51
+ const started = anchorOf(harness).time.startedAt
52
+ const fixed = started + 45_000
53
+
54
+ const viaService = JSON.stringify(anchorOf(harness, fixed))
55
+ const again = JSON.stringify(anchorOf(harness, fixed))
56
+ assert.equal(viaService, again, '同 now 两次读取必须同字节(同态)')
57
+
58
+ const res = await callRoute(harness, '/progress-union/anchor', {
59
+ method: 'GET',
60
+ url: `/progress-union/anchor?sessionId=${SESSION}&now=${fixed}`,
61
+ headers: {},
62
+ })
63
+ assert.equal(res.status, 200)
64
+ assert.equal(JSON.stringify(res.json().anchor), viaService, 'HTTP 与 service 双平面同形')
65
+ })
66
+
67
+ test('rev 对账:历史 progress_update 返回 rev < 当前锚点 rev ⇒ 该段已兑现可剪', async () => {
68
+ const harness = await booted()
69
+ const first = await execUpdate(harness, { changes: [{ title: '步骤一' }] })
70
+ const second = await execUpdate(harness, { changes: [{ id: first.changed[0].id, status: 'done' }] })
71
+ const anchor = anchorOf(harness)
72
+ assert.equal(anchor.revision, second.revision)
73
+ assert.ok(first.revision < anchor.revision, '第一段工具返回 rev 已被锚点覆盖(可安全剪)')
74
+ assert.ok(second.changed.length >= 1)
75
+ })
76
+
77
+ test('userEdits 硬约束:pending>0 必出条目;超 20 条封顶;长值压缩 240+…', async () => {
78
+ const harness = await booted()
79
+ const added = await execUpdate(harness, { changes: [{ title: '任务', approach: 'x'.repeat(600) }] })
80
+ const itemId = added.changed[0].id
81
+ for (let i = 0; i < 25; i++) {
82
+ await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: `改动 ${i}` }] }))
83
+ }
84
+ const anchor = anchorOf(harness)
85
+ assert.equal(anchor.board.pendingUserChanges, 25)
86
+ assert.equal(anchor.userEdits.length, 20, '注入体积有界(最近 20 条)')
87
+ assert.equal(anchor.userEdits[anchor.userEdits.length - 1].kind, 'edit')
88
+ const longField = anchor.userEdits.flatMap((e) => e.fields).find((f) => typeof f.to === 'string' && f.to.length > 200)
89
+ assert.equal(longField, undefined, 'userEdits 只含用户改动;agent 建立的长 approach 不在其中')
90
+
91
+ // ack 后清空
92
+ await execUpdate(harness, { changes: [], ackUserRevision: anchor.revision })
93
+ const after = anchorOf(harness)
94
+ assert.equal(after.board.pendingUserChanges, 0)
95
+ assert.equal(after.userEdits.length, 0)
96
+ })
97
+
98
+ test('空会话锚点:revision=0、board 关闭、etaBasis=none、userEdits 空', () => {
99
+ const fresh = createHarness()
100
+ return fresh.run().then(() => {
101
+ const anchor = fresh.provided.get('progressAnchor').get('session-nope')
102
+ assert.equal(anchor.revision, 0)
103
+ assert.equal(anchor.board.enabled, false)
104
+ assert.equal(anchor.board.summary.total, 0)
105
+ assert.equal(anchor.time.etaBasis, 'none')
106
+ assert.deepEqual(anchor.board.inFlight, [])
107
+ assert.deepEqual(anchor.userEdits, [])
108
+ })
109
+ })
110
+
111
+ test('projection progressAnchor:注册、init 形状、未变同引用、板写后重建', async () => {
112
+ const harness = await booted()
113
+ const proj = harness.projections.get('progressAnchor')
114
+ assert.ok(proj, 'sessionProjections 可得时必须注册 progressAnchor')
115
+ const state0 = proj.init()
116
+ assert.equal(state0.version, 1)
117
+ assert.ok(state0.sessions.some((s) => s.sessionId === SESSION && s.enabled === true))
118
+
119
+ const state1 = proj.apply(state0, { type: 'user/message', data: {} })
120
+ assert.equal(state1, state0, 'agg 未变必须返回同引用(不 republish)')
121
+
122
+ await execUpdate(harness, { changes: [{ title: '新任务', status: 'doing' }] })
123
+ const state2 = proj.apply(state1, { type: 'tool/result', data: {} })
124
+ assert.notEqual(state2, state1, '板写入后 agg 变,必须重建')
125
+ const row = state2.sessions.find((s) => s.sessionId === SESSION)
126
+ assert.equal(row.revision, 1)
127
+ assert.equal(row.summary.doing, 1)
128
+ assert.doesNotThrow(() => proj.stateSchema.parse(state2))
129
+ assert.doesNotThrow(() => proj.wire.viewSchema.parse(state2))
130
+ assert.throws(() => proj.stateSchema.parse({ version: 1, agg: 'bad', sessions: [] }))
131
+ })
132
+
133
+ test('list() 面:多会话聚合可用', async () => {
134
+ const harness = await booted()
135
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: 'session-other', active: true, source: 'command' }))
136
+ const list = harness.provided.get('progressAnchor').list(Date.now())
137
+ assert.ok(Array.isArray(list))
138
+ assert.deepEqual(list.map((a) => a.sessionId).sort(), [SESSION, 'session-other'].sort())
139
+ })
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Phase 8 验收:辅助 LLM(审查/监视)通道。
3
+ * - 直连端点、滞后触发、只改 current/next/percent(updatedBy=assistant);
4
+ * - 每回合配额 + 最小间隔节流;失败静默入 assistantError;
5
+ * - 快照只回非机密字段(apiKey 只回布尔);关着时零 fetch。
6
+ */
7
+ import assert from 'node:assert/strict'
8
+ import fs from 'node:fs'
9
+ import os from 'node:os'
10
+ import path from 'node:path'
11
+ import test from 'node:test'
12
+
13
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
14
+ const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
15
+
16
+ function stubFetch(handler) {
17
+ const calls = []
18
+ const original = globalThis.fetch
19
+ globalThis.fetch = async (url, init) => {
20
+ calls.push({ url: String(url), init })
21
+ return handler(url, init, calls.length)
22
+ }
23
+ return {
24
+ calls,
25
+ restore: () => {
26
+ globalThis.fetch = original
27
+ },
28
+ }
29
+ }
30
+
31
+ function proposal(content) {
32
+ return {
33
+ ok: true,
34
+ status: 200,
35
+ async json() {
36
+ return { choices: [{ message: { content } }] }
37
+ },
38
+ }
39
+ }
40
+
41
+ async function booted(config) {
42
+ const harness = createHarness({ config })
43
+ await harness.run()
44
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
45
+ return harness
46
+ }
47
+
48
+ function execUpdate(harness, args) {
49
+ return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
50
+ }
51
+
52
+ async function settle(ms = 30) {
53
+ await new Promise((resolve) => setTimeout(resolve, ms))
54
+ }
55
+
56
+ async function snapshotOf(harness) {
57
+ const res = await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })
58
+ return res.json()
59
+ }
60
+
61
+ test('命中的提议落地:只改 current/percent,updatedBy=assistant,快照不含密钥明文', async () => {
62
+ const harness = await booted({
63
+ assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', apiKey: 'sekret', model: 'mini', minIntervalMs: 0, maxCallsPerTurn: 1, timeoutMs: 5000 },
64
+ })
65
+ const added = await execUpdate(harness, { changes: [{ title: '造帧', status: 'doing', percent: 10, current: '热身' }] })
66
+ const itemId = added.changed[0].id
67
+ const stub = stubFetch(() => proposal('```json\n{"board":{"changes":[{"kind":"edit","id":"' + itemId + '","current":"审查:跑集成测试","percent":60},{"kind":"edit","id":"p_fake","current":"x"}]},"round":{"status":"continue","summary":"推进中"},"note":"滞后 6 步,已校准"}\n```'))
68
+ try {
69
+ harness.emit('tool/call', { name: 'Bash', arguments: JSON.stringify({ command: 'npm test' }) })
70
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
71
+ await settle()
72
+ assert.equal(stub.calls.length, 1, '滞后触发一次审查')
73
+ assert.ok(stub.calls[0].url.endsWith('/chat/completions'))
74
+ assert.equal(stub.calls[0].init.headers.authorization, 'Bearer sekret')
75
+
76
+ const snap = await snapshotOf(harness)
77
+ const item = snap.items.find((x) => x.id === itemId)
78
+ assert.equal(item.current, '审查:跑集成测试')
79
+ assert.equal(item.percent, 60)
80
+ assert.equal(item.status, 'doing', '审查不得改状态')
81
+ assert.equal(item.updatedBy, 'assistant')
82
+ assert.equal(snap.items.length, 1, '不存在的 id 被丢弃,不得新增任务')
83
+
84
+ assert.equal(snap.assistant.enabled, true)
85
+ assert.equal(snap.assistant.hasApiKey, true)
86
+ assert.equal('apiKey' in snap.assistant, false, '密钥不得回传')
87
+ assert.match(harness.contexts.get('progress-union-observer')(), /助手审查:滞后 6 步,已校准/)
88
+ } finally {
89
+ stub.restore()
90
+ }
91
+ })
92
+
93
+ test('关着时零 fetch;autoApply=false 只记录建议不落地', async () => {
94
+ const off = await booted()
95
+ await execUpdate(off, { changes: [{ title: '任务', status: 'doing' }] })
96
+ const stubOff = stubFetch(() => proposal('{"changes":[],"note":"x"}'))
97
+ try {
98
+ for (let i = 0; i < 6; i++) off.emit('step/start', {})
99
+ await settle()
100
+ assert.equal(stubOff.calls.length, 0, '未启用不得发起请求')
101
+ assert.equal((await snapshotOf(off)).assistant.enabled, false)
102
+ } finally {
103
+ stubOff.restore()
104
+ }
105
+
106
+ const dry = await booted({ assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini', minIntervalMs: 0, autoApply: false } })
107
+ const added = await execUpdate(dry, { changes: [{ title: '任务', status: 'doing', percent: 10, current: '原样' }] })
108
+ const itemId = added.changed[0].id
109
+ const stubDry = stubFetch(() => proposal('{"board":{"changes":[{"kind":"edit","id":"' + itemId + '","percent":90}]},"round":{"status":"continue"},"note":"建议 90%"}'))
110
+ try {
111
+ for (let i = 0; i < 6; i++) dry.emit('step/start', {})
112
+ await settle()
113
+ const snap = await snapshotOf(dry)
114
+ assert.equal(snap.items[0].percent, 10, 'autoApply=false 不落地')
115
+ assert.match(dry.contexts.get('progress-union-observer')(), /助手审查:建议 90%/)
116
+ } finally {
117
+ stubDry.restore()
118
+ }
119
+ })
120
+
121
+ test('失败静默:HTTP 错误/坏 JSON 只进 assistantError,不阻断板', async () => {
122
+ const harness = await booted({ assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini', minIntervalMs: 0 } })
123
+ await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
124
+ const stub = stubFetch(() => ({ ok: false, status: 503, async json() { return {} } }))
125
+ try {
126
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
127
+ await settle()
128
+ const text = harness.contexts.get('progress-union-observer')()
129
+ assert.match(text, /助手审查失败:HTTP 503/)
130
+ assert.equal((await snapshotOf(harness)).items[0].status, 'doing', '板本体不受影响')
131
+ } finally {
132
+ stub.restore()
133
+ }
134
+ })
135
+
136
+ test('节流与每回合配额:minIntervalMs 内不再发;新回合重置配额', async () => {
137
+ const harness = await booted({ assistant: { mode: 'direct', baseUrl: 'http://127.0.0.1:9999/v1', model: 'mini', minIntervalMs: 60_000, maxCallsPerTurn: 1 } })
138
+ await execUpdate(harness, { changes: [{ title: '任务', status: 'doing' }] })
139
+ const stub = stubFetch(() => proposal('{"changes":[],"note":"ok"}'))
140
+ try {
141
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
142
+ await settle()
143
+ assert.equal(stub.calls.length, 1)
144
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
145
+ await settle()
146
+ assert.equal(stub.calls.length, 1, '最小间隔内不得重发')
147
+ } finally {
148
+ stub.restore()
149
+ }
150
+ })
151
+
152
+ test('registered 模式:走宿主 llm.stream,消费 chunk + 槽位管理 + 轮次草案', async () => {
153
+ const streamCalls = []
154
+ const llm = {
155
+ async *stream(options) {
156
+ streamCalls.push(options)
157
+ // 第一段先占位;真实 id 在下面覆盖,这里先给一个失败的 JSON(不会被用)
158
+ yield { content: '{}' }
159
+ },
160
+ }
161
+ const harness = createHarness({
162
+ config: { assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0, maxCallsPerTurn: 1 } },
163
+ llm,
164
+ })
165
+ await harness.run()
166
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
167
+ const added = await execUpdate(harness, { changes: [{ title: '任务', status: 'doing', percent: 10 }] })
168
+ const itemId = added.changed[0].id
169
+ llm.stream = async function* (options) {
170
+ 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 校准"}' }
174
+ }
175
+ for (let i = 0; i < 6; i++) harness.emit('step/start', {})
176
+ await settle()
177
+ assert.equal(streamCalls.length, 1, 'registered 走 llm.stream 而非 fetch')
178
+ assert.equal(streamCalls[0].provider, 'local')
179
+ assert.equal(streamCalls[0].model, 'qwen')
180
+ const snap = await snapshotOf(harness)
181
+ assert.equal(snap.items[0].percent, 75, '助手改了槽位')
182
+ assert.equal(snap.items[0].updatedBy, 'assistant')
183
+ assert.match(harness.contexts.get('progress-union-observer')(), /助手轮次草案.*推进中/)
184
+ })
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Phase 4 验收:client 契约守卫。
3
+ * 1) 客户端文件不得残留 board 旧命名空间/旧 API 调用(fork 改造回归);
4
+ * 2) 客户端消费的两条路由形状(snapshot / status)由宿主实测钉住。
5
+ */
6
+ import assert from 'node:assert/strict'
7
+ import fs from 'node:fs'
8
+ import os from 'node:os'
9
+ import path from 'node:path'
10
+ import test from 'node:test'
11
+
12
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
13
+ const { SESSION, createHarness, jsonReq, callRoute } = await import('./harness.mjs')
14
+
15
+ const clientFile = new URL('../client.js', import.meta.url).pathname.replace(/^\//, '')
16
+
17
+ test('client.js 命名空间已切到 union,无 progress-board API 残留', () => {
18
+ const src = fs.readFileSync(clientFile, 'utf8')
19
+ assert.match(src, /id: 'dsh-progress-union'/)
20
+ assert.match(src, /const API = '\/progress-union'/)
21
+ assert.match(src, /STATUS_API = '\/dsh-progress\/status'/)
22
+ assert.doesNotMatch(src, /fetch\(`\/progress-board/, '不得残留旧 API 前缀的直接调用')
23
+ assert.match(src, /useUnionTiming/, '迷你条时间面钩子必须在')
24
+ })
25
+
26
+ test('宿主 snapshot/status 两路由的客户端消费形状', async () => {
27
+ const harness = createHarness()
28
+ await harness.run()
29
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
30
+ await harness.toolMap.get('progress_update').definition.execute(
31
+ { changes: [{ title: '渲染截图', status: 'doing', current: '渲染第 7/24 张' }, { title: '合成音轨' }] },
32
+ { agent: harness.agent },
33
+ )
34
+ harness.emit('turn/start', {})
35
+ harness.emit('step/start', {})
36
+
37
+ const snap = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json()
38
+ assert.equal(snap.ok, true)
39
+ assert.equal(snap.enabled, true)
40
+ assert.deepEqual(snap.items.map((i) => i.title), ['渲染截图', '合成音轨'])
41
+ assert.equal(typeof snap.summary.percent, 'number')
42
+ assert.equal('pendingUserChanges' in snap, true)
43
+
44
+ const status = (await callRoute(harness, '/dsh-progress/status', { method: 'GET', url: '/dsh-progress/status', headers: {} })).json()
45
+ assert.equal(status.ok, true)
46
+ assert.equal(status.config.pollMs, 1000)
47
+ assert.ok(status.task, 'status.task 必须存在(迷你条数据源)')
48
+ assert.equal(String(status.task.id), String(SESSION))
49
+ // 板开:阶段直接取板 items,不再走关键词猜测
50
+ assert.deepEqual(status.task.stages, ['渲染截图', '合成音轨'])
51
+ assert.equal(status.task.boardDriven, true)
52
+ assert.equal(status.task.current, 0)
53
+ assert.ok(Array.isArray(status.tasks))
54
+ })
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Phase 5 端到端冒烟(task_22):建板 → 用户改 → 不 ack 读锚点 → ack 后再读 →
3
+ * 时钟推进 12 分钟读 staleMin;另验 KV 缺席时锚点仍出且 persistent=false。
4
+ */
5
+ import assert from 'node:assert/strict'
6
+ import fs from 'node:fs'
7
+ import os from 'node:os'
8
+ import path from 'node:path'
9
+ import test from 'node:test'
10
+
11
+ process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), 'union-test-'))
12
+ const { SESSION, createHarness, jsonReq, callRoute, withClock } = await import('./harness.mjs')
13
+
14
+ function execUpdate(harness, args) {
15
+ return harness.toolMap.get('progress_update').definition.execute(args, { agent: harness.agent })
16
+ }
17
+
18
+ test('端到端:建板→用户改→ack→陈旧推进,锚点各阶段状态正确迁移', async () => {
19
+ const harness = createHarness()
20
+ await harness.run()
21
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
22
+ const anchor = () => harness.provided.get('progressAnchor').get(SESSION)
23
+
24
+ // 阶段 0:启用但空板
25
+ assert.equal(anchor().board.summary.total, 0)
26
+ assert.match(harness.contexts.get('progress-union-kickoff')(), /第一个工具调用必须是 progress_update/)
27
+
28
+ // 阶段 1:建板(3 项,1 doing)
29
+ const added = await execUpdate(harness, {
30
+ changes: [{ title: '抓帧', status: 'doing', current: '渲染第 1/900 帧' }, { title: '合成' }, { title: '字幕' }],
31
+ })
32
+ assert.equal(added.summary.total, 3)
33
+ assert.equal(anchor().board.inFlight.length, 1)
34
+ assert.equal(anchor().board.inFlight[0].title, '抓帧')
35
+
36
+ // 阶段 2:用户面板改"合成"备注 → pending=1,userEdits 出现,时间戳推进
37
+ const itemId = (await callRoute(harness, '/progress-union/snapshot', { method: 'GET', url: `/progress-union/snapshot?sessionId=${SESSION}`, headers: {} })).json().items[1].id
38
+ await callRoute(harness, '/progress-union/action', jsonReq('POST', '/progress-union/action', { sessionId: SESSION, changes: [{ id: itemId, note: '用 4K' }] }))
39
+ const pending = anchor()
40
+ assert.equal(pending.board.pendingUserChanges, 1)
41
+ assert.equal(pending.userEdits[0].fields[0].field, 'note')
42
+ assert.ok(pending.revision > added.revision)
43
+
44
+ // 阶段 3:agent ack → pending=0,锚点 revision 不因确认增长
45
+ const acked = await execUpdate(harness, { changes: [], ackUserRevision: pending.revision })
46
+ assert.equal(acked.revision, pending.revision)
47
+ assert.equal(anchor().board.pendingUserChanges, 0)
48
+ assert.equal(anchor().userEdits.length, 0)
49
+
50
+ // 阶段 4:真实时钟推进 12 分钟无更新 → staleMin=12 且 kickoff 提醒复现
51
+ const clock = withClock()
52
+ try {
53
+ clock.advance(12 * 60 * 1000)
54
+ const later = harness.provided.get('progressAnchor').get(SESSION)
55
+ assert.equal(later.time.staleMin, 12)
56
+ assert.match(harness.contexts.get('progress-union-kickoff')(), /12 分钟没有更新/)
57
+ } finally {
58
+ clock.restore()
59
+ }
60
+
61
+ // 阶段 5:完成推进 → percent 迁移
62
+ await execUpdate(harness, { changes: [{ id: added.changed[0].id, status: 'done' }] })
63
+ const afterDone = anchor()
64
+ assert.equal(afterDone.board.summary.done, 1)
65
+ assert.equal(afterDone.board.summary.percent, 33) // (100+0+0)/3
66
+ })
67
+
68
+ test('KV 缺席:内存态可用,锚点照出且 persistent=false', async () => {
69
+ const harness = createHarness({ storageless: true })
70
+ await harness.run()
71
+ await callRoute(harness, '/progress-union/active', jsonReq('POST', '/progress-union/active', { sessionId: SESSION, active: true, source: 'command' }))
72
+ await execUpdate(harness, { changes: [{ title: '仅内存', status: 'doing' }] })
73
+ const anchor = harness.provided.get('progressAnchor').get(SESSION)
74
+ assert.equal(anchor.persistent, false)
75
+ assert.equal(anchor.board.summary.total, 1)
76
+ assert.equal(anchor.board.inFlight[0].title, '仅内存')
77
+ })