dsh-todo-board 0.4.1

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.
@@ -0,0 +1,561 @@
1
+ /**
2
+ * Host-half smoke test for dsh-todo-board.
3
+ *
4
+ * Loads lib/index.js against a stubbed Cordis context and a throwaway DSH_HOME,
5
+ * then exercises apply(), the todo_board tool, the HTTP route, persistence, the
6
+ * top-to-bottom ordering rule, scheduled execution and newSession binding.
7
+ *
8
+ * node tools/smoke.mjs
9
+ */
10
+
11
+ import assert from 'node:assert/strict'
12
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
13
+ import { tmpdir } from 'node:os'
14
+ import { join } from 'node:path'
15
+
16
+ const home = mkdtempSync(join(tmpdir(), 'dshtb-smoke-'))
17
+ process.env.DSH_HOME = home
18
+
19
+ const mod = await import('../lib/index.js')
20
+
21
+ const registered = { tool: null, section: null, routes: [], listeners: [], effects: [] }
22
+
23
+ const DIR = 'D:\\smoke\\project'
24
+ const agent = {
25
+ id: 'session-smoke',
26
+ session: { header: { id: 'session-smoke', cwd: DIR } },
27
+ sent: [],
28
+ followup(message) {
29
+ this.sent.push(message)
30
+ },
31
+ steer(message) {
32
+ this.sent.push(message)
33
+ },
34
+ }
35
+ const exec = { agent }
36
+
37
+ /** Live agents the stub registry knows about: the origin session plus spawned ones. */
38
+ const live = new Map([[agent.id, agent]])
39
+ const spawnedAgents = []
40
+
41
+ function spawnStubAgent(id) {
42
+ const spawned = {
43
+ id,
44
+ status: 'idle',
45
+ session: { header: { id, cwd: DIR } },
46
+ sent: [],
47
+ followup(message) {
48
+ this.sent.push(message)
49
+ },
50
+ steer(message) {
51
+ this.sent.push(message)
52
+ },
53
+ }
54
+ live.set(spawned.id, spawned)
55
+ spawnedAgents.push(spawned)
56
+ return spawned
57
+ }
58
+
59
+ const agentsStub = {
60
+ list: () => [...live.values()],
61
+ get: (id) => live.get(id),
62
+ async create(options) {
63
+ // The factory is handed the caller's session id; honour it like the real one.
64
+ const spawned = spawnStubAgent(options.sessionId)
65
+ if (typeof options.setup === 'function') await options.setup({})
66
+ return { agent: spawned, dispose: async () => {} }
67
+ },
68
+ }
69
+
70
+ const presetsStub = {
71
+ async resolve() {
72
+ return { id: 'standard' }
73
+ },
74
+ async mount() {
75
+ return { id: 'standard' }
76
+ },
77
+ }
78
+
79
+ /** Records which sessions the plugin files under a workspace directory. */
80
+ const attached = []
81
+ const workspaces = new Map()
82
+
83
+ /** In-memory stand-in for the durable attachment store. */
84
+ const savedImages = new Map()
85
+ let imageSeq = 0
86
+
87
+ const attachmentsStub = {
88
+ async saveImage(input) {
89
+ if (!(input.data instanceof Uint8Array) || input.data.length === 0) {
90
+ throw new Error('image bytes are empty')
91
+ }
92
+ imageSeq += 1
93
+ const ref = {
94
+ attachmentId: 'att-' + imageSeq,
95
+ mediaType: input.mediaType,
96
+ bytes: input.data.length,
97
+ width: 2,
98
+ height: 3,
99
+ }
100
+ if (typeof input.name === 'string' && input.name !== '') ref.name = input.name
101
+ savedImages.set(ref.attachmentId, input.data)
102
+ return ref
103
+ },
104
+ async readImage(ref) {
105
+ const data = savedImages.get(ref.attachmentId)
106
+ if (data === undefined) throw new Error('unknown attachment ' + ref.attachmentId)
107
+ return { ref, data }
108
+ },
109
+ }
110
+
111
+ /** A 1x1 transparent PNG — enough for admission and a real byte round trip. */
112
+ const PNG_BASE64 =
113
+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=='
114
+
115
+ const workspaceStub = {
116
+ async resolveByPath(path) {
117
+ return workspaces.get(path)
118
+ },
119
+ async create(path) {
120
+ const workspace = {
121
+ id: 'ws-' + (workspaces.size + 1),
122
+ path,
123
+ async attachSession(sessionId) {
124
+ attached.push({ workspaceId: this.id, path, sessionId })
125
+ },
126
+ }
127
+ workspaces.set(path, workspace)
128
+ return workspace
129
+ },
130
+ }
131
+
132
+ function makeCtx() {
133
+ // `inject(['webServer'], cb)` hands cb a context where the service is a
134
+ // property, so the stub exposes it both ways.
135
+ const webServer = {
136
+ register(route) {
137
+ registered.routes.push(route)
138
+ return () => {}
139
+ },
140
+ }
141
+ const ctx = {
142
+ root: undefined,
143
+ webServer,
144
+ get(key) {
145
+ if (key === 'tools') {
146
+ return {
147
+ register(definition) {
148
+ registered.tool = definition
149
+ return () => {}
150
+ },
151
+ }
152
+ }
153
+ if (key === 'systemPrompt') {
154
+ return {
155
+ section(section) {
156
+ registered.section = section
157
+ return () => {}
158
+ },
159
+ }
160
+ }
161
+ if (key === 'agents') return agentsStub
162
+ if (key === 'agentPresets') return presetsStub
163
+ if (key === 'attachments') return attachmentsStub
164
+ if (key === 'workspaceRegistry') return workspaceStub
165
+ if (key === 'webServer') return webServer
166
+ return undefined
167
+ },
168
+ on(event, listener) {
169
+ registered.listeners.push({ event, listener })
170
+ return () => {}
171
+ },
172
+ effect(callback, label) {
173
+ registered.effects.push(label)
174
+ const disposer = callback()
175
+ return typeof disposer === 'function' ? disposer : () => {}
176
+ },
177
+ inject(names, callback) {
178
+ callback(ctx)
179
+ },
180
+ logger: { error() {} },
181
+ }
182
+ return ctx
183
+ }
184
+
185
+ function fakeResponse() {
186
+ const box = { status: 0, body: '' }
187
+ return {
188
+ box,
189
+ writeHead(status) {
190
+ box.status = status
191
+ },
192
+ end(body) {
193
+ box.body = body === undefined ? '' : String(body)
194
+ },
195
+ }
196
+ }
197
+
198
+ /** Local `YYYY-MM-DDTHH:mm`, the board's schedule format. */
199
+ function localStamp(ms) {
200
+ const date = new Date(ms)
201
+ const pad = (n) => String(n).padStart(2, '0')
202
+ return (
203
+ date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) +
204
+ 'T' + pad(date.getHours()) + ':' + pad(date.getMinutes())
205
+ )
206
+ }
207
+
208
+ /**
209
+ * Fire the turn-end hook and let the dispatch promise chain settle — dispatch
210
+ * awaits the model-capability probe before it sends, so a synchronous call
211
+ * would observe the message count before the message exists.
212
+ */
213
+ async function turnStopping() {
214
+ for (const entry of registered.listeners) {
215
+ if (entry.event === 'agent/turn-stopping') entry.listener({ agent })
216
+ }
217
+ await settle()
218
+ }
219
+
220
+ /** Drain microtasks and timers the plugin scheduled with no delay. */
221
+ function settle() {
222
+ return new Promise((resolve) => setTimeout(resolve, 0))
223
+ }
224
+
225
+ // ------------------------------------------------------------------ apply()
226
+
227
+ assert.equal(mod.name, 'dsh-todo-board')
228
+ mod.apply(makeCtx())
229
+
230
+ assert.equal(registered.tool?.name, 'todo_board', 'todo_board registered')
231
+ assert.equal(registered.tool.parameters.required[0], 'action')
232
+ assert.equal(registered.section?.name, 'todo-board', 'prompt section registered')
233
+ assert.equal(registered.section.order, 150)
234
+ assert.equal(registered.routes.length, 2, 'api and image routes')
235
+ assert.equal(registered.routes[0].path, '/dsh-todo-board/image')
236
+ assert.equal(registered.routes[1].path, '/dsh-todo-board/api')
237
+ const apiRoute = registered.routes[1]
238
+ const imageRoute = registered.routes[0]
239
+ assert.ok(
240
+ registered.listeners.some((entry) => entry.event === 'agent/turn-stopping'),
241
+ 'turn-stopping listener registered',
242
+ )
243
+ assert.ok(existsSync(join(home, 'todo-board', 'board.json')), 'board file created on first load')
244
+ console.log('apply() OK')
245
+
246
+ // --------------------------------------------------------------- tool: add
247
+
248
+ const added = await registered.tool.execute(
249
+ { action: 'add', title: '第二条', mode: 'resume' },
250
+ exec,
251
+ )
252
+ assert.equal(added.todos.length, 1)
253
+ assert.equal(added.todos[0].title, '第二条')
254
+ assert.equal(added.todos[0].mode, 'resume')
255
+ assert.equal(added.todos[0].schedule, '', 'a plain add carries no schedule')
256
+ assert.equal(added.todos[0].aiDone, false)
257
+ assert.deepEqual(
258
+ Object.keys(added.todos[0]).sort(),
259
+ ['aiDone', 'dirLabel', 'id', 'imageCount', 'mode', 'schedule', 'title', 'verified'],
260
+ 'tool rows carry exactly the declared schema keys',
261
+ )
262
+ const firstId = added.todos[0].id
263
+
264
+ await registered.tool.execute({ action: 'add', title: '第一条', mode: 'resume' }, exec)
265
+
266
+ // -------------------------------------------------------------- tool: list
267
+
268
+ const listed = await registered.tool.execute({ action: 'list' }, exec)
269
+ assert.equal(listed.todos.length, 2)
270
+ assert.equal(listed.todos[0].title, '第二条', 'appended rows keep insertion order first')
271
+ assert.ok(listed.message.includes('从上到下就是执行顺序'), 'list explains the order')
272
+
273
+ // ------------------------------------------------------ reorder via route
274
+
275
+ // The route reads the raw request stream, so drive it with an async iterable.
276
+ async function postJson(payload) {
277
+ const response = fakeResponse()
278
+ const chunks = [Buffer.from(JSON.stringify(payload), 'utf8')]
279
+ const request = {
280
+ method: 'POST',
281
+ async *[Symbol.asyncIterator]() {
282
+ for (const chunk of chunks) yield chunk
283
+ },
284
+ }
285
+ await apiRoute.handler(request, response)
286
+ return JSON.parse(response.box.body)
287
+ }
288
+
289
+ const snapshot = await registered.tool.execute({ action: 'list' }, exec)
290
+ const ids = snapshot.todos.map((todo) => todo.id)
291
+ const reordered = await postJson({ action: 'reorder', ids: [ids[1], ids[0]] })
292
+ assert.equal(reordered.ok, true, 'reorder accepted')
293
+ assert.equal(reordered.count, 2)
294
+
295
+ const afterReorder = await registered.tool.execute({ action: 'list' }, exec)
296
+ assert.equal(afterReorder.todos[0].id, ids[1], 'top-to-bottom order persisted')
297
+ assert.equal(afterReorder.todos[1].id, ids[0])
298
+ console.log('order OK')
299
+
300
+ // ------------------------------------------------------------ tool: done
301
+
302
+ const done = await registered.tool.execute({ action: 'done', id: firstId }, exec)
303
+ assert.equal(done.todos[0].aiDone, true)
304
+ assert.ok(done.message.includes('已标记 AI 完成'))
305
+
306
+ const notFound = await registered.tool.execute({ action: 'done', id: 'nope' }, exec)
307
+ assert.ok(notFound.message.includes('找不到'))
308
+
309
+ // -------------------------------------------------------- route: GET + patch
310
+
311
+ const getResponse = fakeResponse()
312
+ await apiRoute.handler({ method: 'GET' }, getResponse)
313
+ const snapshot2 = JSON.parse(getResponse.box.body)
314
+ assert.equal(snapshot2.ok, true)
315
+ assert.equal(snapshot2.todos.length, 2)
316
+ assert.ok(snapshot2.storagePath.endsWith('board.json'))
317
+ assert.ok(snapshot2.todos.every((todo) => typeof todo.order === 'number'))
318
+ assert.ok(snapshot2.todos.every((todo) => typeof todo.schedule === 'string'))
319
+ assert.ok(snapshot2.todos.every((todo) => typeof todo.dueAt === 'number'), 'panel rows expose dueAt')
320
+
321
+ const patched = await postJson({ action: 'patch', id: firstId, patch: { verified: true } })
322
+ assert.equal(patched.ok, true)
323
+ assert.equal(patched.todo.verified, true)
324
+
325
+ const bad = await postJson({ action: 'nonsense' })
326
+ assert.equal(bad.ok, false)
327
+ console.log('route OK')
328
+
329
+ // ------------------------------------------------------------- persistence
330
+
331
+ const onDisk = JSON.parse(readFileSync(join(home, 'todo-board', 'board.json'), 'utf8'))
332
+ assert.equal(onDisk.todos.length, 2)
333
+ assert.equal(onDisk.todos[0].id, ids[1], 'disk order matches the reordered order')
334
+ assert.equal(onDisk.todos[0].order, 0)
335
+ assert.equal(onDisk.todos[1].order, 1)
336
+ console.log('persist OK')
337
+
338
+ // ---------------------------------------------------------------- schedule
339
+
340
+ // Created the way the panel creates it: bound to a session, so a scheduled
341
+ // `resume` row has somewhere to land when its time comes.
342
+ const startCount = agent.sent.length
343
+ const minuteStart = Math.floor(Date.now() / 60000) * 60000
344
+ const created = await postJson({
345
+ action: 'create',
346
+ title: '到点再干',
347
+ mode: 'resume',
348
+ dir: DIR,
349
+ sessionId: agent.id,
350
+ schedule: localStamp(minuteStart + 60000),
351
+ })
352
+ assert.equal(created.ok, true, 'create accepts a schedule')
353
+ const scheduledId = created.todo.id
354
+ assert.equal(created.todo.schedule, localStamp(minuteStart + 60000), 'a local stamp round-trips')
355
+ assert.equal(created.todo.dueAt, minuteStart + 60000, 'dueAt mirrors the stamp')
356
+ assert.equal(agent.sent.length, startCount, 'a future row does not fire on creation')
357
+
358
+ const rejected = await postJson({ action: 'create', title: '坏时间', dir: DIR, schedule: 'nonsense' })
359
+ assert.equal(rejected.ok, false, 'create refuses an unparseable schedule')
360
+
361
+ const byTool = await registered.tool.execute(
362
+ { action: 'schedule', id: scheduledId, schedule: localStamp(minuteStart + 7200000) },
363
+ exec,
364
+ )
365
+ assert.equal(byTool.todos[0].schedule, localStamp(minuteStart + 7200000), 'schedule action moves the time')
366
+ await registered.tool.execute({ action: 'schedule', id: scheduledId, schedule: '' }, exec)
367
+ assert.equal(
368
+ (await registered.tool.execute({ action: 'list' }, exec)).todos.find((todo) => todo.id === scheduledId)
369
+ .schedule,
370
+ '',
371
+ 'an empty schedule clears the timer',
372
+ )
373
+ await registered.tool.execute({ action: 'schedule', id: scheduledId, schedule: 'not-a-date' }, exec)
374
+ assert.equal(
375
+ (await registered.tool.execute({ action: 'list' }, exec)).todos.find((todo) => todo.id === scheduledId)
376
+ .schedule,
377
+ '',
378
+ 'an unparseable schedule never arms a wrong instant',
379
+ )
380
+
381
+ // A future time must hold the row back at turn end, even though it sits above
382
+ // every other pending row in this directory.
383
+ await registered.tool.execute(
384
+ { action: 'schedule', id: scheduledId, schedule: localStamp(minuteStart + 7200000) },
385
+ exec,
386
+ )
387
+ await registered.tool.execute({ action: 'done', id: ids[0] }, exec)
388
+ await registered.tool.execute({ action: 'done', id: ids[1] }, exec)
389
+ const gatedCount = agent.sent.length
390
+ await registered.tool.execute({ action: 'add', title: '没有定时的一条', mode: 'resume' }, exec)
391
+ const boardOrder = (await registered.tool.execute({ action: 'list' }, exec)).todos
392
+ assert.equal(
393
+ boardOrder.findIndex((todo) => todo.id === scheduledId) <
394
+ boardOrder.findIndex((todo) => todo.title === '没有定时的一条'),
395
+ true,
396
+ 'the future row really is the topmost pending row',
397
+ )
398
+ await turnStopping()
399
+ assert.equal(agent.sent.length, gatedCount + 1, 'turn end dispatches the next todo that is actually due')
400
+ assert.ok(
401
+ agent.sent[gatedCount].content[0].text.includes('没有定时的一条'),
402
+ 'turn end steps over the not-yet-due row instead of running it',
403
+ )
404
+ assert.equal(
405
+ (await registered.tool.execute({ action: 'list' }, exec)).todos.find((todo) => todo.id === scheduledId)
406
+ .schedule,
407
+ localStamp(minuteStart + 7200000),
408
+ 'the future row keeps its schedule',
409
+ )
410
+
411
+ // Moving the time into the past re-arms the timer, which dispatches the row and
412
+ // records it so nothing can fire twice.
413
+ await registered.tool.execute({ action: 'schedule', id: scheduledId, schedule: localStamp(minuteStart) }, exec)
414
+ assert.equal(agent.sent.length, gatedCount + 2, 'a due todo dispatches through the timer')
415
+ assert.ok(
416
+ agent.sent[gatedCount + 1].content[0].text.includes('到点再干'),
417
+ 'the dispatched prompt carries the todo title',
418
+ )
419
+ assert.equal(
420
+ JSON.parse(readFileSync(join(home, 'todo-board', 'board.json'), 'utf8')).todos.find(
421
+ (todo) => todo.id === scheduledId,
422
+ ).dispatchedAt > 0,
423
+ true,
424
+ 'dispatch is persisted, so it can never fire twice',
425
+ )
426
+ console.log('schedule OK')
427
+
428
+ // ------------------------------------------------------- newSession binding
429
+
430
+ // The first run opens a session and binds it; the second run must reuse that
431
+ // binding instead of opening yet another session.
432
+ const spawnedTodo = await postJson({
433
+ action: 'create',
434
+ title: '新会话只开一次',
435
+ mode: 'newSession',
436
+ dir: DIR,
437
+ sessionId: agent.id,
438
+ })
439
+ assert.equal(spawnedTodo.ok, true)
440
+ const boundId = spawnedTodo.todo.id
441
+ const firstRun = await postJson({ action: 'run', id: boundId, sessionId: agent.id })
442
+ assert.equal(firstRun.ok, true, 'the first run opens a session')
443
+ assert.equal(firstRun.target, 'new-session')
444
+ assert.equal(spawnedAgents.length, 1, 'exactly one session was created')
445
+ assert.equal(firstRun.sessionId, spawnedAgents[0].id)
446
+ assert.equal(spawnedAgents[0].sent.length, 1, 'the created session received the task')
447
+ assert.equal(attached.length, 1, 'the created session is filed under a workspace')
448
+ assert.equal(attached[0].sessionId, spawnedAgents[0].id)
449
+ assert.equal(attached[0].path, DIR, 'the workspace is the todo directory')
450
+
451
+ const snapshotResponse = fakeResponse()
452
+ await apiRoute.handler({ method: 'GET' }, snapshotResponse)
453
+ const panelRow = JSON.parse(snapshotResponse.box.body).todos.find((todo) => todo.id === boundId)
454
+ assert.equal(panelRow.runSessionId, spawnedAgents[0].id, 'the created session is bound on the row')
455
+
456
+ const secondRun = await postJson({ action: 'run', id: boundId, sessionId: agent.id })
457
+ assert.equal(secondRun.ok, true, 'the second run succeeds')
458
+ assert.equal(secondRun.target, 'session', 'the second run reuses the binding')
459
+ assert.equal(secondRun.sessionId, spawnedAgents[0].id)
460
+ assert.equal(spawnedAgents.length, 1, 'no second session is created')
461
+ assert.equal(spawnedAgents[0].sent.length, 2, 'the bound session got the task again')
462
+
463
+ // Unbinding is what re-enables opening a fresh session.
464
+ const unbound = await postJson({ action: 'patch', id: boundId, patch: { runSessionId: '' } })
465
+ assert.equal(unbound.ok, true)
466
+ assert.equal(unbound.todo.runSessionId, '', 'the panel can drop the binding')
467
+ const thirdRun = await postJson({ action: 'run', id: boundId, sessionId: agent.id })
468
+ assert.equal(thirdRun.target, 'new-session', 'after unbinding a new session is opened again')
469
+ assert.equal(spawnedAgents.length, 2, 'unbinding really allows a second session')
470
+ console.log('binding OK')
471
+
472
+ // ------------------------------------------------------------------- images
473
+
474
+ // One todo carries images: they are admitted through the attachment store,
475
+ // persisted as durable refs, rendered by the plugin's own byte route, and sent
476
+ // to the model as real image blocks.
477
+ const withImage = await postJson({
478
+ action: 'create',
479
+ title: '看图干活',
480
+ mode: 'resume',
481
+ dir: DIR,
482
+ sessionId: agent.id,
483
+ images: [{ data: PNG_BASE64, mediaType: 'image/png', name: 'shot.png' }],
484
+ })
485
+ assert.equal(withImage.ok, true, 'create accepts an image')
486
+ const imageId = withImage.todo.id
487
+ assert.equal(withImage.todo.images.length, 1, 'the image reference is stored on the row')
488
+ const ref = withImage.todo.images[0]
489
+ assert.equal(ref.mediaType, 'image/png')
490
+ assert.equal(ref.name, 'shot.png')
491
+ assert.ok(ref.bytes > 0 && ref.width > 0 && ref.height > 0, 'the ref carries normalized metadata')
492
+
493
+ const refused = await postJson({
494
+ action: 'create',
495
+ title: '非法图片',
496
+ dir: DIR,
497
+ images: [{ data: PNG_BASE64, mediaType: 'image/tiff' }],
498
+ })
499
+ assert.equal(refused.ok, false, 'an unsupported media type is refused')
500
+ assert.ok(refused.error.includes('不支持的图片格式'), 'the refusal names the reason')
501
+
502
+ const tooMany = await postJson({
503
+ action: 'create',
504
+ title: '太多图片',
505
+ dir: DIR,
506
+ images: new Array(5).fill({ data: PNG_BASE64, mediaType: 'image/png' }),
507
+ })
508
+ assert.equal(tooMany.ok, false, 'more images than the cap is refused')
509
+
510
+ // The plugin's own route serves the bytes, and only for a referenced id.
511
+ const imageResponse = {
512
+ status: 0,
513
+ headers: {},
514
+ body: null,
515
+ writeHead(status, headers) {
516
+ this.status = status
517
+ this.headers = headers === undefined ? {} : headers
518
+ },
519
+ end(body) {
520
+ this.body = body
521
+ },
522
+ }
523
+ await imageRoute.handler({ method: 'GET', url: '/dsh-todo-board/image?id=' + ref.attachmentId }, imageResponse)
524
+ assert.equal(imageResponse.status, 200, 'a referenced attachment is served')
525
+ assert.equal(imageResponse.headers['content-type'], 'image/png')
526
+ assert.ok(Buffer.from(imageResponse.body).length > 0, 'the served bytes are non-empty')
527
+
528
+ const missingResponse = {
529
+ status: 0,
530
+ writeHead(status) {
531
+ this.status = status
532
+ },
533
+ end() {},
534
+ }
535
+ await imageRoute.handler({ method: 'GET', url: '/dsh-todo-board/image?id=att-nope' }, missingResponse)
536
+ assert.equal(missingResponse.status, 404, 'an unreferenced id is not readable')
537
+
538
+ // Dispatch turns the attached image into a real image block.
539
+ const beforeImageRun = agent.sent.length
540
+ await postJson({ action: 'run', id: imageId, sessionId: agent.id })
541
+ assert.equal(agent.sent.length, beforeImageRun + 1, 'the todo dispatched')
542
+ const sentContent = agent.sent[beforeImageRun].content
543
+ assert.equal(sentContent[0].type, 'text')
544
+ assert.ok(sentContent[0].text.includes('附带的 1 张图片'), 'the prompt announces the images')
545
+ const imageBlocks = sentContent.filter((block) => block.type === 'image')
546
+ assert.equal(imageBlocks.length, 1, 'the message carries one image block')
547
+ assert.deepEqual(imageBlocks[0].attachment, ref, 'the block is the durable reference itself')
548
+
549
+ // Dropping the image leaves a text-only todo, and the list reports the count.
550
+ const cleared = await postJson({ action: 'patch', id: imageId, patch: { clearImages: true } })
551
+ assert.equal(cleared.todo.images.length, 0, 'images can be dropped again')
552
+ const listedWithCount = await registered.tool.execute({ action: 'list' }, exec)
553
+ assert.equal(
554
+ listedWithCount.todos.every((todo) => typeof todo.imageCount === 'number'),
555
+ true,
556
+ 'tool rows report imageCount',
557
+ )
558
+ console.log('images OK')
559
+
560
+ rmSync(home, { recursive: true, force: true })
561
+ console.log('\nall host-half smoke checks passed')