@nethiel/dsh-turn-report 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/LICENSE +21 -0
- package/README.md +353 -2
- package/client.js +940 -0
- package/cordis.patch.yml +35 -0
- package/docs/DETAIL.md +161 -0
- package/docs/DETAIL.zh.md +136 -0
- package/docs/demo-card.png +0 -0
- package/docs/dsh-market-entry.json +12 -0
- package/icon.svg +16 -0
- package/index.js +1052 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +72 -3
- package/test/fold.test.mjs +718 -0
|
@@ -0,0 +1,718 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone check for the turn-report fold and the tree renderer.
|
|
3
|
+
*
|
|
4
|
+
* Runs the real `apply()` against a fake `sessionProjections` registry, feeds a
|
|
5
|
+
* synthetic event stream, and asserts the wire payload. No DSH host needed.
|
|
6
|
+
*/
|
|
7
|
+
import { apply } from '../index.js'
|
|
8
|
+
|
|
9
|
+
/** Minimal fake registry that captures the unit definition. */
|
|
10
|
+
function fakeContext() {
|
|
11
|
+
const captured = {}
|
|
12
|
+
return {
|
|
13
|
+
ctx: {
|
|
14
|
+
sessionProjections: {
|
|
15
|
+
async register(definition) {
|
|
16
|
+
captured.definition = definition
|
|
17
|
+
return { stateOf: () => captured.state, async dispose() {} }
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
captured,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Run one event stream through a fresh registration and return the folded state + wire. */
|
|
26
|
+
async function fold(events, config, header) {
|
|
27
|
+
const { ctx, captured } = fakeContext()
|
|
28
|
+
await apply(ctx, config ?? { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true })
|
|
29
|
+
const def = captured.definition
|
|
30
|
+
let state = def.init(header)
|
|
31
|
+
for (const [type, data] of events) state = def.apply(state, { type, data })
|
|
32
|
+
return { state, wire: def.wire.view(state) }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let failures = 0
|
|
36
|
+
function check(name, actual, expected) {
|
|
37
|
+
const a = JSON.stringify(actual)
|
|
38
|
+
const e = JSON.stringify(expected)
|
|
39
|
+
if (a === e) {
|
|
40
|
+
console.log(' PASS ' + name)
|
|
41
|
+
} else {
|
|
42
|
+
failures += 1
|
|
43
|
+
console.log(' FAIL ' + name + '\n expected: ' + e + '\n actual: ' + a)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const todos = [
|
|
48
|
+
{ content: '## 阶段一:搭骨架', status: 'completed' },
|
|
49
|
+
{ content: '- 写 manifest', status: 'completed' },
|
|
50
|
+
{ content: ' - 加 icon', status: 'completed' },
|
|
51
|
+
{ content: '## 阶段二:验证', status: 'in_progress' },
|
|
52
|
+
{ content: '- 跑测试', status: 'pending' },
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
const stream = [
|
|
56
|
+
['turn/start', { turn: 1 }],
|
|
57
|
+
['todo/write', { todos }],
|
|
58
|
+
['tool/call', { turn: 1, step: 1, callId: 'c1', name: 'write', arguments: '{"file_path":"a/b.js"}' }],
|
|
59
|
+
['tool/result', { turn: 1, step: 1, message: { isError: false } }],
|
|
60
|
+
['tool/call', { turn: 1, step: 2, callId: 'c2', name: 'write', arguments: '{"file_path":"a/b.js"}' }],
|
|
61
|
+
['tool/call', { turn: 1, step: 2, callId: 'c3', name: 'read', arguments: '{"file_path":"a/c.js"}' }],
|
|
62
|
+
['tool/result', { turn: 1, step: 2, message: { isError: true } }],
|
|
63
|
+
['tool/call', { turn: 1, step: 3, callId: 'c4', name: 'edit', arguments: '{"file_path":"d/e.js"}' }],
|
|
64
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
const { state, wire } = await fold(stream)
|
|
68
|
+
|
|
69
|
+
console.log('fold assertions')
|
|
70
|
+
check('one turn recorded', Object.keys(wire.turns).length, 1)
|
|
71
|
+
const entry = wire.turns['1']
|
|
72
|
+
check('turn number', entry.n, 1)
|
|
73
|
+
check('end kind', entry.end, 'completed')
|
|
74
|
+
check('tool calls counted', entry.tools, 4)
|
|
75
|
+
check('failures counted', entry.failed, 1)
|
|
76
|
+
check('files deduped', entry.files, ['a/b.js', 'd/e.js'])
|
|
77
|
+
check('todo total', entry.todo.total, 5)
|
|
78
|
+
check('todo done', entry.todo.done, 3)
|
|
79
|
+
check('todo doing', entry.todo.doing, 1)
|
|
80
|
+
check('todo left', entry.todo.left, 1)
|
|
81
|
+
check('todoUpdated flag', entry.todo.updated, true)
|
|
82
|
+
check('labels strip markers', entry.todo.rows.map(r => r.c), [
|
|
83
|
+
'## 阶段一:搭骨架', '写 manifest', '加 icon', '## 阶段二:验证', '跑测试',
|
|
84
|
+
])
|
|
85
|
+
check('depths derived from indent', entry.todo.rows.map(r => r.d), [0, 0, 1, 0, 0])
|
|
86
|
+
check('live turn closed', state.cur, null)
|
|
87
|
+
|
|
88
|
+
console.log('caps')
|
|
89
|
+
const many = Array.from({ length: 30 }, (_, i) => ({ content: 'item ' + i, status: 'pending' }))
|
|
90
|
+
const capped = await fold([
|
|
91
|
+
['turn/start', { turn: 2 }],
|
|
92
|
+
['todo/write', { todos: many }],
|
|
93
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
94
|
+
], { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true })
|
|
95
|
+
check('rows capped at maxRows', capped.wire.turns['2'].todo.rows.length, 6)
|
|
96
|
+
check('overflow counted', capped.wire.turns['2'].todo.more, 24)
|
|
97
|
+
|
|
98
|
+
console.log('turn window')
|
|
99
|
+
const windowEvents = []
|
|
100
|
+
for (let n = 1; n <= 20; n += 1) {
|
|
101
|
+
windowEvents.push(['turn/start', { turn: n }], ['turn/end', { turn: n, reason: { kind: 'completed' } }])
|
|
102
|
+
}
|
|
103
|
+
const windowed = await fold(windowEvents)
|
|
104
|
+
check('keeps last 15 turns', Object.keys(windowed.wire.turns).length, 15)
|
|
105
|
+
check('oldest dropped', windowed.wire.turns['5'], undefined)
|
|
106
|
+
check('newest kept', windowed.wire.turns['20'] !== undefined, true)
|
|
107
|
+
|
|
108
|
+
console.log('turn-scoped todo list')
|
|
109
|
+
{
|
|
110
|
+
// A turn that never writes a todo list must not inherit the previous one.
|
|
111
|
+
const stale = await fold([
|
|
112
|
+
['turn/start', { turn: 1 }],
|
|
113
|
+
['todo/write', { todos }],
|
|
114
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
115
|
+
['turn/start', { turn: 2 }],
|
|
116
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
117
|
+
])
|
|
118
|
+
check('turn 1 keeps its list', stale.wire.turns['1'].todo.done, 3)
|
|
119
|
+
check('turn 2 has no list', stale.wire.turns['2'].todo, null)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log('file labels are workspace-relative')
|
|
123
|
+
{
|
|
124
|
+
const withCwd = await fold([
|
|
125
|
+
['turn/start', { turn: 1 }],
|
|
126
|
+
['tool/call', { turn: 1, step: 1, callId: 'c1', name: 'write', arguments: '{"file_path":"D:\\\\ws\\\\proj\\\\a\\\\b.js"}' }],
|
|
127
|
+
['tool/call', { turn: 1, step: 1, callId: 'c2', name: 'edit', arguments: '{"file_path":"D:\\\\other\\\\c.js"}' }],
|
|
128
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
129
|
+
], { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true }, { cwd: 'D:\\ws\\proj' })
|
|
130
|
+
check('inside the workspace is relative', withCwd.wire.turns['1'].files[0], 'a/b.js')
|
|
131
|
+
check('outside stays absolute', withCwd.wire.turns['1'].files[1], 'D:\\other\\c.js')
|
|
132
|
+
const noCwd = await fold([
|
|
133
|
+
['turn/start', { turn: 1 }],
|
|
134
|
+
['tool/call', { turn: 1, step: 1, callId: 'c1', name: 'write', arguments: '{"file_path":"D:\\\\ws\\\\a.js"}' }],
|
|
135
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
136
|
+
], { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true }, {})
|
|
137
|
+
check('no cwd leaves paths untouched', noCwd.wire.turns['1'].files[0], 'D:\\ws\\a.js')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log('finished-this-turn delta')
|
|
141
|
+
{
|
|
142
|
+
const cfg = { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, todoView: 'auto' }
|
|
143
|
+
// Turn 1 builds a plan and finishes two of it; nothing was finished before.
|
|
144
|
+
const t1 = await fold([
|
|
145
|
+
['turn/start', { turn: 1 }],
|
|
146
|
+
['todo/write', { todos }],
|
|
147
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
148
|
+
], cfg)
|
|
149
|
+
check('turn 1 finished = all completed items', t1.wire.turns['1'].todo.finished.map(f => f.c), ['## 阶段一:搭骨架', '写 manifest', '加 icon'])
|
|
150
|
+
|
|
151
|
+
// Turn 2 keeps the same list but ticks one more item off.
|
|
152
|
+
const turn2 = [
|
|
153
|
+
['turn/start', { turn: 2 }],
|
|
154
|
+
['todo/write', { todos: [
|
|
155
|
+
{ content: '## 阶段一:搭骨架', status: 'completed' },
|
|
156
|
+
{ content: '- 写 manifest', status: 'completed' },
|
|
157
|
+
{ content: ' - 加 icon', status: 'completed' },
|
|
158
|
+
{ content: '## 阶段二:验证', status: 'completed' },
|
|
159
|
+
{ content: '- 跑测试', status: 'pending' },
|
|
160
|
+
] }],
|
|
161
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
162
|
+
]
|
|
163
|
+
const t2all = await fold([
|
|
164
|
+
['turn/start', { turn: 1 }],
|
|
165
|
+
['todo/write', { todos }],
|
|
166
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
167
|
+
...turn2,
|
|
168
|
+
], cfg)
|
|
169
|
+
check('turn 2 finished only the newly ticked item', t2all.wire.turns['2'].todo.finished.map(f => f.c), ['## 阶段二:验证'])
|
|
170
|
+
check('already-finished items are not re-reported', t2all.wire.turns['2'].todo.finished.some(f => f.c === '写 manifest'), false)
|
|
171
|
+
|
|
172
|
+
// A rewording of an already-finished item must NOT be reported as new work.
|
|
173
|
+
const reworded = await fold([
|
|
174
|
+
['turn/start', { turn: 1 }],
|
|
175
|
+
['todo/write', { todos: [{ content: '- 写测试', status: 'completed' }] }],
|
|
176
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
177
|
+
['turn/start', { turn: 2 }],
|
|
178
|
+
// Same task, punctuation and marker stripped, plus one genuinely new item.
|
|
179
|
+
['todo/write', { todos: [
|
|
180
|
+
{ content: '写测试', status: 'completed' },
|
|
181
|
+
{ content: ' 部署上线', status: 'completed' },
|
|
182
|
+
] }],
|
|
183
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
184
|
+
], cfg)
|
|
185
|
+
check('reworded item is not new work', reworded.wire.turns['2'].todo.finished.map(f => f.c), ['部署上线'])
|
|
186
|
+
|
|
187
|
+
// A plan that finishes nothing produces no finished list at all.
|
|
188
|
+
const nothing = await fold([
|
|
189
|
+
['turn/start', { turn: 1 }],
|
|
190
|
+
['todo/write', { todos: [{ content: 'a', status: 'pending' }, { content: 'b', status: 'in_progress' }] }],
|
|
191
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
192
|
+
], cfg)
|
|
193
|
+
check('no finished items → empty list', nothing.wire.turns['1'].todo.finished, [])
|
|
194
|
+
check('tree rows still carry the whole plan', nothing.wire.turns['1'].todo.rows.length, 2)
|
|
195
|
+
|
|
196
|
+
// The finished list is capped by HARD_MAX_ROWS (20), not by the display budget:
|
|
197
|
+
// it is the card's headline, so a 4-row table setting must not truncate it to 4.
|
|
198
|
+
const manyDone = Array.from({ length: 9 }, (_, i) => ({ content: 'done ' + i, status: 'completed' }))
|
|
199
|
+
const capped3 = await fold([
|
|
200
|
+
['turn/start', { turn: 1 }],
|
|
201
|
+
['todo/write', { todos: manyDone }],
|
|
202
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
203
|
+
], { ...cfg, maxRows: 4 })
|
|
204
|
+
check('finished ignores the small maxRows budget', capped3.wire.turns['1'].todo.finished.length, 9)
|
|
205
|
+
check('so nothing is reported as truncated', capped3.wire.turns['1'].todo.finishedMore, 0)
|
|
206
|
+
|
|
207
|
+
// At the hard ceiling it does truncate, and says how many are left.
|
|
208
|
+
const beyond = Array.from({ length: 25 }, (_, i) => ({ content: 'x ' + i, status: 'completed' }))
|
|
209
|
+
const over = await fold([
|
|
210
|
+
['turn/start', { turn: 1 }],
|
|
211
|
+
['todo/write', { todos: beyond }],
|
|
212
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
213
|
+
], { ...cfg, maxRows: 4 })
|
|
214
|
+
check('hard ceiling still caps', over.wire.turns['1'].todo.finished.length, 20)
|
|
215
|
+
check('overflow counted past the ceiling', over.wire.turns['1'].todo.finishedMore, 5)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
console.log('config aliases and todoView')
|
|
219
|
+
{
|
|
220
|
+
const applyCfg = async (raw) => {
|
|
221
|
+
const { ctx, captured } = fakeContext()
|
|
222
|
+
await apply(ctx, raw)
|
|
223
|
+
return captured.definition
|
|
224
|
+
}
|
|
225
|
+
const def = await applyCfg({ showPending: false })
|
|
226
|
+
const state = def.init({ cwd: 'D:\\ws' })
|
|
227
|
+
check('legacy showPending honoured as showFinished', def.wire.view(state).opts.showFinished, false)
|
|
228
|
+
const def2 = await applyCfg({ todoView: 'pending' })
|
|
229
|
+
check('legacy todoView pending maps to auto', def2.wire.view(def2.init({})).opts.todoView, 'auto')
|
|
230
|
+
const def3 = await applyCfg({})
|
|
231
|
+
check('default todoView is auto', def3.wire.view(def3.init({})).opts.todoView, 'auto')
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
console.log('llm accounting (model / calls / tokens)')
|
|
235
|
+
{
|
|
236
|
+
const cfg = { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, showLlm: true, todoView: 'auto' }
|
|
237
|
+
const msg = (route, usage) => ['assistant/message', {
|
|
238
|
+
turn: 1,
|
|
239
|
+
step: 1,
|
|
240
|
+
message: { role: 'assistant', content: [], source: { provider: route[0], model: route[1] } },
|
|
241
|
+
usage,
|
|
242
|
+
}]
|
|
243
|
+
const accounted = await fold([
|
|
244
|
+
['turn/start', { turn: 1 }],
|
|
245
|
+
msg(['ustc', 'deepseek-flash'], { inputTokens: 100, outputTokens: 20, totalTokens: 120, cacheReadTokens: 0 }),
|
|
246
|
+
msg(['ustc', 'deepseek-flash'], { inputTokens: 50, outputTokens: 10, totalTokens: 60, cacheReadTokens: 900 }),
|
|
247
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
248
|
+
], cfg)
|
|
249
|
+
const llm = accounted.wire.turns['1'].llm
|
|
250
|
+
check('counts each model response', llm.calls, 2)
|
|
251
|
+
check('dedupes the same route', llm.models, ['ustc/deepseek-flash'])
|
|
252
|
+
check('sums uncached input', llm.usage.input, 150)
|
|
253
|
+
check('sums output', llm.usage.output, 30)
|
|
254
|
+
check('sums cache read', llm.usage.cacheRead, 900)
|
|
255
|
+
check('sums provider totals', llm.usage.total, 180)
|
|
256
|
+
|
|
257
|
+
// Two different models in one turn are both reported.
|
|
258
|
+
const mixed = await fold([
|
|
259
|
+
['turn/start', { turn: 1 }],
|
|
260
|
+
msg(['ustc', 'deepseek-flash'], { inputTokens: 10, outputTokens: 5, totalTokens: 15 }),
|
|
261
|
+
msg(['qoder-cn', 'DeepSeek-Flash'], { inputTokens: 10, outputTokens: 5, totalTokens: 15 }),
|
|
262
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
263
|
+
], cfg)
|
|
264
|
+
check('keeps every distinct route', mixed.wire.turns['1'].llm.models, ['ustc/deepseek-flash', 'qoder-cn/DeepSeek-Flash'])
|
|
265
|
+
|
|
266
|
+
// A turn with no model response reports no llm block at all.
|
|
267
|
+
const silent = await fold([
|
|
268
|
+
['turn/start', { turn: 1 }],
|
|
269
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
270
|
+
], cfg)
|
|
271
|
+
check('no responses → no llm block', silent.wire.turns['1'].llm, null)
|
|
272
|
+
|
|
273
|
+
// A message with no usage still counts as a call, contributing zero tokens.
|
|
274
|
+
const bare = await fold([
|
|
275
|
+
['turn/start', { turn: 1 }],
|
|
276
|
+
['assistant/message', { turn: 1, step: 1, message: { source: { provider: 'p', model: 'm' } } }],
|
|
277
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
278
|
+
], cfg)
|
|
279
|
+
check('usage-less response still counts', bare.wire.turns['1'].llm.calls, 1)
|
|
280
|
+
check('usage-less response adds zero tokens', bare.wire.turns['1'].llm.usage.total, 0)
|
|
281
|
+
|
|
282
|
+
// showLlm:false suppresses it on the wire.
|
|
283
|
+
const hidden = await fold([
|
|
284
|
+
['turn/start', { turn: 1 }],
|
|
285
|
+
msg(['p', 'm'], { inputTokens: 1, outputTokens: 1, totalTokens: 2 }),
|
|
286
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
287
|
+
], { ...cfg, showLlm: false })
|
|
288
|
+
check('showLlm false reaches the wire', hidden.wire.opts.showLlm, false)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
console.log('status bar live view (status sections + next up)')
|
|
292
|
+
{
|
|
293
|
+
const cfg = { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, showLlm: true, showStatusBar: true, todoView: 'auto' }
|
|
294
|
+
// A realistic FLAT list: real todo_write payloads carry no indentation at all.
|
|
295
|
+
const flat = [
|
|
296
|
+
{ content: '阶段一:调研', status: 'completed' },
|
|
297
|
+
{ content: '阶段二:实现', status: 'in_progress' },
|
|
298
|
+
{ content: '阶段三:发布', status: 'pending' },
|
|
299
|
+
{ content: '写测试', status: 'pending' },
|
|
300
|
+
]
|
|
301
|
+
const mid = await fold([
|
|
302
|
+
['turn/start', { turn: 1 }],
|
|
303
|
+
['todo/write', { todos: flat }],
|
|
304
|
+
], cfg)
|
|
305
|
+
const live = mid.wire.live
|
|
306
|
+
check('live has totals', [live.total, live.done, live.doing, live.left], [4, 1, 1, 2])
|
|
307
|
+
check('live next-up lists unfinished in order', live.nextUp.map(r => r.c), ['阶段二:实现', '阶段三:发布', '写测试'])
|
|
308
|
+
check('groups by status, not indentation', live.groups.map(g => g.k), ['done', 'doing', 'left'])
|
|
309
|
+
check('each section counts its own rows', live.groups.map(g => g.total), [1, 1, 2])
|
|
310
|
+
check('finished section folds by default', live.groups[0].startOpen, false)
|
|
311
|
+
check('pending section starts open', live.groups[2].startOpen, true)
|
|
312
|
+
check('multi-item section can fold', live.groups[2].collapsible, true)
|
|
313
|
+
check('single-item section cannot fold', live.groups[1].collapsible, false)
|
|
314
|
+
|
|
315
|
+
// The exact failure this replaced: a fully flat all-done list used to produce one
|
|
316
|
+
// non-collapsible section per item, so no arrows ever rendered.
|
|
317
|
+
const allDone = await fold([
|
|
318
|
+
['turn/start', { turn: 1 }],
|
|
319
|
+
['todo/write', { todos: [
|
|
320
|
+
{ content: 'Host:新增视图', status: 'completed' },
|
|
321
|
+
{ content: 'Client:状态栏组件', status: 'completed' },
|
|
322
|
+
{ content: '配置开关,测试全过', status: 'completed' },
|
|
323
|
+
] }],
|
|
324
|
+
], cfg)
|
|
325
|
+
check('flat all-done list fills the done slot', allDone.wire.live.groups[0].total, 3)
|
|
326
|
+
check('that slot holds every item', allDone.wire.live.groups[0].children.length, 3)
|
|
327
|
+
check('so the fold arrow exists', allDone.wire.live.groups[0].collapsible, true)
|
|
328
|
+
// All three slots stay present at 0 — a HUD that hides empty slots reads as
|
|
329
|
+
// lost data, which is exactly how the user reported it.
|
|
330
|
+
check('all three slots always present', allDone.wire.live.groups.map(g => g.k), ['done', 'doing', 'left'])
|
|
331
|
+
check('empty slots are flagged, not dropped', allDone.wire.live.groups.map(g => g.empty), [false, true, true])
|
|
332
|
+
|
|
333
|
+
// Indented lists keep their structure inside the status section.
|
|
334
|
+
const indented = await fold([
|
|
335
|
+
['turn/start', { turn: 1 }],
|
|
336
|
+
['todo/write', { todos: [
|
|
337
|
+
{ content: '阶段一', status: 'completed' },
|
|
338
|
+
{ content: ' 子项 A', status: 'completed' },
|
|
339
|
+
{ content: ' 子项 B', status: 'pending' },
|
|
340
|
+
] }],
|
|
341
|
+
], cfg)
|
|
342
|
+
check('indent still recorded per row', indented.wire.live.groups.flatMap(g => g.children.map(c => c.d)), [0, 1, 1])
|
|
343
|
+
check('slots keep a fixed order', indented.wire.live.groups.map(g => g.k), ['done', 'doing', 'left'])
|
|
344
|
+
check('the empty doing slot sits between', indented.wire.live.groups.map(g => g.empty), [false, true, false])
|
|
345
|
+
|
|
346
|
+
// Across a turn boundary with no new list, the bar keeps showing the plan.
|
|
347
|
+
const carried = await fold([
|
|
348
|
+
['turn/start', { turn: 1 }],
|
|
349
|
+
['todo/write', { todos: flat }],
|
|
350
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
351
|
+
['turn/start', { turn: 2 }],
|
|
352
|
+
], cfg)
|
|
353
|
+
check('plan survives the turn boundary', carried.wire.live.total, 4)
|
|
354
|
+
|
|
355
|
+
// Each card must show ITS OWN plan, not the conversation's latest one.
|
|
356
|
+
const twoTurns = await fold([
|
|
357
|
+
['turn/start', { turn: 1 }],
|
|
358
|
+
['todo/write', { todos: [{ content: 'a', status: 'pending' }, { content: 'b', status: 'pending' }] }],
|
|
359
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
360
|
+
['turn/start', { turn: 2 }],
|
|
361
|
+
['todo/write', { todos: [
|
|
362
|
+
{ content: 'a', status: 'completed' },
|
|
363
|
+
{ content: 'b', status: 'completed' },
|
|
364
|
+
{ content: 'c', status: 'pending' },
|
|
365
|
+
] }],
|
|
366
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
367
|
+
], cfg)
|
|
368
|
+
check('turn 1 froze its own plan', twoTurns.wire.turns['1'].plan.total, 2)
|
|
369
|
+
check('turn 1 plan is still unfinished', twoTurns.wire.turns['1'].plan.done, 0)
|
|
370
|
+
check('turn 2 froze its own plan', twoTurns.wire.turns['2'].plan.total, 3)
|
|
371
|
+
check('turn 2 plan shows its own progress', twoTurns.wire.turns['2'].plan.done, 2)
|
|
372
|
+
check('live view still tracks the latest', twoTurns.wire.live.total, 3)
|
|
373
|
+
|
|
374
|
+
// A turn that writes no list carries the newest plan forward, flagged stale.
|
|
375
|
+
// Two earlier designs failed on this: rendering nothing left most cards with no
|
|
376
|
+
// HUD ("改完后怎么什么都没了"), while rendering the live plan repeated today's
|
|
377
|
+
// state with no explanation. The carried-forward flag is what keeps a repeat from
|
|
378
|
+
// reading as a frozen UI.
|
|
379
|
+
const quiet = await fold([
|
|
380
|
+
['turn/start', { turn: 1 }],
|
|
381
|
+
['todo/write', { todos: [{ content: 'p1', status: 'pending' }] }],
|
|
382
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
383
|
+
['turn/start', { turn: 2 }],
|
|
384
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
385
|
+
['turn/start', { turn: 3 }],
|
|
386
|
+
['turn/end', { turn: 3, reason: { kind: 'completed' } }],
|
|
387
|
+
], cfg)
|
|
388
|
+
check('turn 1 plan is its own, not stale', quiet.wire.turns['1'].plan.stale, false)
|
|
389
|
+
check('turn 1 reports its own list', quiet.wire.turns['1'].plan.total, 1)
|
|
390
|
+
check('turn 2 carries the plan forward', quiet.wire.turns['2'].plan.total, 1)
|
|
391
|
+
check('turn 2 marks it stale', quiet.wire.turns['2'].plan.stale, true)
|
|
392
|
+
check('turn 3 still carries it', quiet.wire.turns['3'].plan.stale, true)
|
|
393
|
+
check('live still tracks the session plan', quiet.wire.live.total, 1)
|
|
394
|
+
|
|
395
|
+
// A turn with no list still shows the plan in force, also marked stale.
|
|
396
|
+
const noList = await fold([
|
|
397
|
+
['turn/start', { turn: 1 }],
|
|
398
|
+
['todo/write', { todos: flat }],
|
|
399
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
400
|
+
['turn/start', { turn: 2 }],
|
|
401
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
402
|
+
], cfg)
|
|
403
|
+
check('turn without a list shows the carried plan', noList.wire.turns['2'].plan.total, 4)
|
|
404
|
+
check('and flags it stale', noList.wire.turns['2'].plan.stale, true)
|
|
405
|
+
check('live plan still available for context', noList.wire.live.total, 4)
|
|
406
|
+
|
|
407
|
+
// With no list ever written, there is nothing to carry and nothing to show.
|
|
408
|
+
const never = await fold([
|
|
409
|
+
['turn/start', { turn: 1 }],
|
|
410
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
411
|
+
], cfg)
|
|
412
|
+
check('no plan ever written → no plan block', never.wire.turns['1'].plan, null)
|
|
413
|
+
|
|
414
|
+
// REGRESSION: the last real plan must survive many plan-less turns. Before the
|
|
415
|
+
// fix `turn/start` set prevTodos = state.todos (null on a plan-less turn), so two
|
|
416
|
+
// turns after the list was written it was gone forever and long sessions lost the
|
|
417
|
+
// todo section entirely. Session-34847 wrote its list at turn 21 and showed
|
|
418
|
+
// nothing from turn 30 onward because of this.
|
|
419
|
+
const longGap = []
|
|
420
|
+
longGap.push(['turn/start', { turn: 1 }])
|
|
421
|
+
longGap.push(['todo/write', { todos: flat }])
|
|
422
|
+
longGap.push(['turn/end', { turn: 1, reason: { kind: 'completed' } }])
|
|
423
|
+
for (let turn = 2; turn <= 12; turn += 1) {
|
|
424
|
+
longGap.push(['turn/start', { turn }])
|
|
425
|
+
longGap.push(['turn/end', { turn, reason: { kind: 'completed' } }])
|
|
426
|
+
}
|
|
427
|
+
const gap = await fold(longGap, cfg)
|
|
428
|
+
check('plan survives 11 plan-less turns', gap.wire.live.total, 4)
|
|
429
|
+
check('and its groups are still intact', gap.wire.live.groups.length, 3)
|
|
430
|
+
|
|
431
|
+
// No plan at all → no live view, so nothing renders.
|
|
432
|
+
const empty = await fold([['turn/start', { turn: 1 }], ['turn/end', { turn: 1, reason: { kind: 'completed' } }]], cfg)
|
|
433
|
+
check('no plan → no live view', empty.wire.live, null)
|
|
434
|
+
|
|
435
|
+
// Config can hide the whole HUD.
|
|
436
|
+
const hidden = await fold([['turn/start', { turn: 1 }], ['todo/write', { todos: flat }]], { ...cfg, showStatusBar: false })
|
|
437
|
+
check('showStatusBar false reaches the wire', hidden.wire.opts.showStatusBar, false)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
console.log('stage grouping (【阶段】 prefixes)')
|
|
441
|
+
{
|
|
442
|
+
const cfg = { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, showLlm: true, showStatusBar: true, todoView: 'auto' }
|
|
443
|
+
// A staged plan: sections become the stages, each with its own state.
|
|
444
|
+
const staged = await fold([
|
|
445
|
+
['turn/start', { turn: 1 }],
|
|
446
|
+
['todo/write', { todos: [
|
|
447
|
+
{ content: '【阶段一】确认技术路径', status: 'completed' },
|
|
448
|
+
{ content: '【阶段一】读参考文档', status: 'completed' },
|
|
449
|
+
{ content: '【阶段二】搭插件骨架', status: 'in_progress' },
|
|
450
|
+
{ content: '【阶段二】实现投影', status: 'pending' },
|
|
451
|
+
{ content: '【阶段三】市场发布', status: 'pending' },
|
|
452
|
+
] }],
|
|
453
|
+
], cfg)
|
|
454
|
+
const g = staged.wire.live.groups
|
|
455
|
+
check('sections are the stages, in first-seen order', g.map(x => x.t), ['阶段一', '阶段二', '阶段三'])
|
|
456
|
+
check('a fully-done stage reports done', g[0].s, 'done')
|
|
457
|
+
check('a running stage reports doing', g[1].s, 'doing')
|
|
458
|
+
check('an untouched stage reports left', g[2].s, 'left')
|
|
459
|
+
check('stage counts its own items', g.map(x => x.total), [2, 2, 1])
|
|
460
|
+
check('stage prefixes are stripped from rows', g[0].children.map(c => c.c), ['确认技术路径', '读参考文档'])
|
|
461
|
+
check('finished stage starts folded', g[0].startOpen, false)
|
|
462
|
+
check('running stage starts open', g[1].startOpen, true)
|
|
463
|
+
|
|
464
|
+
// Alternate bracket styles are accepted.
|
|
465
|
+
const alt = await fold([
|
|
466
|
+
['turn/start', { turn: 1 }],
|
|
467
|
+
['todo/write', { todos: [
|
|
468
|
+
{ content: '〔P1〕做 A', status: 'completed' },
|
|
469
|
+
{ content: '[P2] 做 B', status: 'pending' },
|
|
470
|
+
] }],
|
|
471
|
+
], cfg)
|
|
472
|
+
check('〔〕 and [] both mark stages', alt.wire.live.groups.map(x => x.t), ['P1', 'P2'])
|
|
473
|
+
|
|
474
|
+
// Lines without a marker join an "其他" section rather than being dropped.
|
|
475
|
+
const mixed = await fold([
|
|
476
|
+
['turn/start', { turn: 1 }],
|
|
477
|
+
['todo/write', { todos: [
|
|
478
|
+
{ content: '【阶段一】有标记', status: 'completed' },
|
|
479
|
+
{ content: '没标记的任务', status: 'pending' },
|
|
480
|
+
] }],
|
|
481
|
+
], cfg)
|
|
482
|
+
check('unmarked lines fall into 其他', mixed.wire.live.groups.map(x => x.t), ['阶段一', '其他'])
|
|
483
|
+
check('其他 keeps the row', mixed.wire.live.groups[1].children.map(c => c.c), ['没标记的任务'])
|
|
484
|
+
|
|
485
|
+
// With no markers at all, the status buckets are used (unchanged behaviour).
|
|
486
|
+
const flatOnly = await fold([
|
|
487
|
+
['turn/start', { turn: 1 }],
|
|
488
|
+
['todo/write', { todos: [{ content: '任务甲', status: 'completed' }] }],
|
|
489
|
+
], cfg)
|
|
490
|
+
check('flat list still uses status slots', flatOnly.wire.live.groups.map(x => x.k), ['done', 'doing', 'left'])
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
console.log('cleared vs absent plan (external review finding)')
|
|
494
|
+
{
|
|
495
|
+
const cfg = { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, showLlm: true, showStatusBar: true, todoView: 'auto' }
|
|
496
|
+
// Writing an explicit empty list means "the plan was cleared", which is different
|
|
497
|
+
// from "this turn wrote nothing". Treating them the same made a cleared plan keep
|
|
498
|
+
// reappearing as a stale plan.
|
|
499
|
+
const run = await fold([
|
|
500
|
+
['turn/start', { turn: 1 }],
|
|
501
|
+
['todo/write', { todos: [{ content: '任务A', status: 'in_progress' }, { content: '任务B', status: 'pending' }] }],
|
|
502
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
503
|
+
['turn/start', { turn: 2 }],
|
|
504
|
+
['todo/write', { todos: [] }],
|
|
505
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
506
|
+
['turn/start', { turn: 3 }],
|
|
507
|
+
['turn/end', { turn: 3, reason: { kind: 'completed' } }],
|
|
508
|
+
], cfg)
|
|
509
|
+
check('clearing the list drops the plan (turn 2)', run.wire.turns['2'].plan, null)
|
|
510
|
+
check('and the card can say it was cleared', run.wire.turns['2'].cleared, true)
|
|
511
|
+
check('cleared plan does not revive later (turn 3)', run.wire.turns['3'].plan, null)
|
|
512
|
+
|
|
513
|
+
// A turn that wrote nothing still carries the last plan forward, marked stale.
|
|
514
|
+
const silent = await fold([
|
|
515
|
+
['turn/start', { turn: 1 }],
|
|
516
|
+
['todo/write', { todos: [{ content: '任务A', status: 'pending' }] }],
|
|
517
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
518
|
+
['turn/start', { turn: 2 }],
|
|
519
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
520
|
+
], cfg)
|
|
521
|
+
check('silent turn still carries the plan', silent.wire.turns['2'].plan.total, 1)
|
|
522
|
+
check('and marks it stale', silent.wire.turns['2'].plan.stale, true)
|
|
523
|
+
check('silent turn is not reported as cleared', silent.wire.turns['2'].cleared, false)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
console.log('finished-delta identity: relabelled and duplicate items')
|
|
527
|
+
{
|
|
528
|
+
const cfg = { maxRows: 20, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, showLlm: true, showStatusBar: true, todoView: 'auto' }
|
|
529
|
+
// Moving a completed item to another stage must not read as new work: the stage
|
|
530
|
+
// label is presentation, not identity.
|
|
531
|
+
const relabel = await fold([
|
|
532
|
+
['turn/start', { turn: 1 }],
|
|
533
|
+
['todo/write', { todos: [{ content: '【实现】更新卡片', status: 'completed' }, { content: '【实现】其他', status: 'pending' }] }],
|
|
534
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
535
|
+
['turn/start', { turn: 2 }],
|
|
536
|
+
['todo/write', { todos: [{ content: '【验证】更新卡片', status: 'completed' }, { content: '【实现】其他', status: 'pending' }] }],
|
|
537
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
538
|
+
], cfg)
|
|
539
|
+
check('relabelling between stages is not new work', relabel.wire.turns['2'].todo.finished, [])
|
|
540
|
+
|
|
541
|
+
// Two identically named items: finishing the second one IS a completion, even
|
|
542
|
+
// though the set of completed keys is unchanged.
|
|
543
|
+
const dup = await fold([
|
|
544
|
+
['turn/start', { turn: 1 }],
|
|
545
|
+
['todo/write', { todos: [{ content: '文案', status: 'completed' }, { content: '文案', status: 'pending' }] }],
|
|
546
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
547
|
+
['turn/start', { turn: 2 }],
|
|
548
|
+
['todo/write', { todos: [{ content: '文案', status: 'completed' }, { content: '文案', status: 'completed' }] }],
|
|
549
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
550
|
+
], cfg)
|
|
551
|
+
check('duplicate item completion is counted', dup.wire.turns['2'].todo.finished.map(f => f.c), ['文案'])
|
|
552
|
+
check('total done reflects both', dup.wire.turns['2'].todo.done, 2)
|
|
553
|
+
|
|
554
|
+
// Finishing both duplicates at once reports both.
|
|
555
|
+
const dupBoth = await fold([
|
|
556
|
+
['turn/start', { turn: 1 }],
|
|
557
|
+
['todo/write', { todos: [{ content: '文案', status: 'pending' }, { content: '文案', status: 'pending' }] }],
|
|
558
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
559
|
+
['turn/start', { turn: 2 }],
|
|
560
|
+
['todo/write', { todos: [{ content: '文案', status: 'completed' }, { content: '文案', status: 'completed' }] }],
|
|
561
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
562
|
+
], cfg)
|
|
563
|
+
check('both duplicates counted as new', dupBoth.wire.turns['2'].todo.finished.length, 2)
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
console.log('decision extraction from human messages')
|
|
567
|
+
{
|
|
568
|
+
const cfg = { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, showLlm: true, showStatusBar: true, todoView: 'auto' }
|
|
569
|
+
const human = text => ['user/message', { content: [{ type: 'text', text }], role: 'user' }]
|
|
570
|
+
// Injected context arrives as user/message too. Measured on a real session: 92 of
|
|
571
|
+
// 145 user events were injected, so this filter does most of the work.
|
|
572
|
+
const injected = text => ['user/message', { content: [{ type: 'text', text }], role: 'user' }]
|
|
573
|
+
|
|
574
|
+
const quoted = await fold([
|
|
575
|
+
['turn/start', { turn: 1 }],
|
|
576
|
+
human('你先建私有仓,明天我们再发 npm 和转公有'),
|
|
577
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
578
|
+
], cfg)
|
|
579
|
+
check('a stated decision is quoted', quoted.wire.turns['1'].decisions.length, 1)
|
|
580
|
+
check('quoted verbatim', quoted.wire.turns['1'].decisions[0].includes('你先建私有仓'), true)
|
|
581
|
+
|
|
582
|
+
// Injection must not be mistaken for a person speaking.
|
|
583
|
+
const noise = await fold([
|
|
584
|
+
['turn/start', { turn: 1 }],
|
|
585
|
+
injected('<system-reminder>\nThe following workspace instructions may be relevant'),
|
|
586
|
+
injected('Time sampled while preparing turn 1, step 1: 2026-11-01T00:00:00+08:00'),
|
|
587
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
588
|
+
], cfg)
|
|
589
|
+
check('injected context is not a decision', noise.wire.turns['1'].decisions, null)
|
|
590
|
+
|
|
591
|
+
// A question is not a decision, even with a decision-shaped cue inside.
|
|
592
|
+
const question = await fold([
|
|
593
|
+
['turn/start', { turn: 1 }],
|
|
594
|
+
human('要不要把打包拆成签名和出包?'),
|
|
595
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
596
|
+
], cfg)
|
|
597
|
+
check('a question is not quoted', question.wire.turns['1'].decisions, null)
|
|
598
|
+
|
|
599
|
+
const speculation = await fold([
|
|
600
|
+
['turn/start', { turn: 1 }],
|
|
601
|
+
human('如果验收失败就先别合并'),
|
|
602
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
603
|
+
], cfg)
|
|
604
|
+
check('a hypothetical is not quoted', speculation.wire.turns['1'].decisions, null)
|
|
605
|
+
|
|
606
|
+
// Short whole-message answers ARE decisions and were the clearest ones here.
|
|
607
|
+
const short = await fold([
|
|
608
|
+
['turn/start', { turn: 1 }],
|
|
609
|
+
human('做吧'),
|
|
610
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
611
|
+
], cfg)
|
|
612
|
+
check('a one-word go-ahead is quoted', short.wire.turns['1'].decisions, ['做吧'])
|
|
613
|
+
|
|
614
|
+
const option = await fold([
|
|
615
|
+
['turn/start', { turn: 1 }],
|
|
616
|
+
human('方案 E'),
|
|
617
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
618
|
+
], cfg)
|
|
619
|
+
check('a bare option pick is quoted', option.wire.turns['1'].decisions, ['方案 E'])
|
|
620
|
+
|
|
621
|
+
// Per-turn cap: two is already a busy turn.
|
|
622
|
+
const many = await fold([
|
|
623
|
+
['turn/start', { turn: 1 }],
|
|
624
|
+
human('做吧'),
|
|
625
|
+
human('方案 E'),
|
|
626
|
+
human('先建私有仓'),
|
|
627
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
628
|
+
], cfg)
|
|
629
|
+
check('decisions are capped', many.wire.turns['1'].decisions.length, 2)
|
|
630
|
+
check('and the newest two are kept', many.wire.turns['1'].decisions, ['方案 E', '先建私有仓'])
|
|
631
|
+
|
|
632
|
+
// The review's cases: sentences ABOUT the absence of a decision must not quote.
|
|
633
|
+
for (const [text, label] of [
|
|
634
|
+
['我还没决定用哪个方案。', 'undecided'],
|
|
635
|
+
['C 方向要做吗', 'question without a mark'],
|
|
636
|
+
['请对比这两个方案的区别。', 'comparison request'],
|
|
637
|
+
]) {
|
|
638
|
+
const r = await fold([
|
|
639
|
+
['turn/start', { turn: 1 }],
|
|
640
|
+
human(text),
|
|
641
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
642
|
+
], cfg)
|
|
643
|
+
check('not quoted: ' + label, r.wire.turns['1'].decisions, null)
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// A retraction in the same turn withdraws the earlier choice.
|
|
647
|
+
const retracted = await fold([
|
|
648
|
+
['turn/start', { turn: 1 }],
|
|
649
|
+
human('方案 A'),
|
|
650
|
+
human('先别做,刚才的决定撤回'),
|
|
651
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
652
|
+
], cfg)
|
|
653
|
+
check('a retraction clears the earlier choice', retracted.wire.turns['1'].decisions, null)
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
console.log('sessionHasPlan distinguishes the two silences')
|
|
657
|
+
{
|
|
658
|
+
const cfg = { maxRows: 6, showWithoutTasks: true, showTree: true, showFiles: true, showFinished: true, showLlm: true, showStatusBar: true, todoView: 'auto' }
|
|
659
|
+
// A session that never used a task list would otherwise show a bare metrics card
|
|
660
|
+
// with no explanation, which reads as "the plugin is broken".
|
|
661
|
+
const never = await fold([
|
|
662
|
+
['turn/start', { turn: 1 }],
|
|
663
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
664
|
+
], cfg)
|
|
665
|
+
check('a session with no list reports sessionHasPlan=false', never.wire.turns['1'].sessionHasPlan, false)
|
|
666
|
+
|
|
667
|
+
// The same turn shape, but the session HAS used a list earlier → the card knows a
|
|
668
|
+
// list exists and stays quiet rather than claiming the session never planned.
|
|
669
|
+
const usedEarlier = await fold([
|
|
670
|
+
['turn/start', { turn: 1 }],
|
|
671
|
+
['todo/write', { todos: [{ content: '任务甲', status: 'pending' }] }],
|
|
672
|
+
['turn/end', { turn: 1, reason: { kind: 'completed' } }],
|
|
673
|
+
['turn/start', { turn: 2 }],
|
|
674
|
+
['turn/end', { turn: 2, reason: { kind: 'completed' } }],
|
|
675
|
+
], cfg)
|
|
676
|
+
check('a session that used a list reports sessionHasPlan=true', usedEarlier.wire.turns['2'].sessionHasPlan, true)
|
|
677
|
+
check('and its plan is the carried one', usedEarlier.wire.turns['2'].plan.total, 1)
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
console.log('no-op events keep the state reference')
|
|
681
|
+
{
|
|
682
|
+
const { ctx, captured } = fakeContext()
|
|
683
|
+
await apply(ctx, {})
|
|
684
|
+
const def = captured.definition
|
|
685
|
+
const initial = def.init()
|
|
686
|
+
const afterStart = def.apply(initial, { type: 'turn/start', data: { turn: 1 } })
|
|
687
|
+
const afterUserMessage = def.apply(afterStart, { type: 'user/message', data: {} })
|
|
688
|
+
check('unrelated event returns same reference', afterUserMessage === afterStart, true)
|
|
689
|
+
check('wire cached per state', def.wire.view(afterStart) === def.wire.view(afterStart), true)
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
console.log('client tree renderer')
|
|
693
|
+
{
|
|
694
|
+
const ModuleLoader = { load: spec => { globalThis.__loaded = spec } }
|
|
695
|
+
globalThis.window = { __ModuleLoader__: ModuleLoader }
|
|
696
|
+
const requireShim = () => ({ createElement: () => null })
|
|
697
|
+
await import('../client.js')
|
|
698
|
+
const loaded = globalThis.__loaded
|
|
699
|
+
const mod = loaded.factory(requireShim)
|
|
700
|
+
const lines = mod.treeLines([
|
|
701
|
+
{ s: 'done', c: '阶段一', d: 0 },
|
|
702
|
+
{ s: 'done', c: '子项 A', d: 1 },
|
|
703
|
+
{ s: 'doing', c: '阶段二', d: 0 },
|
|
704
|
+
{ s: 'left', c: '子项 B', d: 1 },
|
|
705
|
+
{ s: 'left', c: '孙项 C', d: 2 },
|
|
706
|
+
])
|
|
707
|
+
const flat = lines.map(l => l.rail.join('') + l.branch + ' ' + l.icon + ' ' + l.c)
|
|
708
|
+
check('root with siblings uses ├─', lines[0].branch, '├─')
|
|
709
|
+
check('only child is last under a non-last root', flat[1], '│ └─ ✅ 子项 A')
|
|
710
|
+
check('last root uses └─', lines[2].branch, '└─')
|
|
711
|
+
check('rail has one cell per level', lines[4].rail.length, 2)
|
|
712
|
+
check('line count', lines.length, 5)
|
|
713
|
+
console.log(' rendered:')
|
|
714
|
+
for (const line of flat) console.log(' ' + line)
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
console.log(failures === 0 ? '\nALL PASS' : '\n' + failures + ' FAILURE(S)')
|
|
718
|
+
process.exit(failures === 0 ? 0 : 1)
|