@babylonjs-toolkit/agent 1.2.1 → 1.2.3
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/README.md +34 -21
- package/lib/claude-settings.js +146 -1
- package/lib/doctor.js +21 -4
- package/lib/install.js +67 -4
- package/package.json +1 -1
- package/scripts/hooks/block-sleep.js +138 -0
- package/skills/bt-execute/SKILL.md +99 -117
- package/skills/bt-execute/scripts/dashboard.mjs +441 -24
- package/skills/bt-execute/templates/dashboard/data-schema.md +43 -16
- package/skills/bt-plan/SKILL.md +52 -62
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Feature dashboard helper for bt-execute: the one way agents write a feature's dashboard data,
|
|
4
|
-
*
|
|
3
|
+
* Feature dashboard helper for bt-execute: the one way agents write a feature's dashboard data, the writer of the
|
|
4
|
+
* live status, the gate that catches a skipped deliverable, and a watchdog for manual use.
|
|
5
5
|
*
|
|
6
6
|
* Every write reads the data file, parses its strict JSON, changes it and writes it back atomically (a temp file
|
|
7
7
|
* renamed over the original), so the page can never load a half-written file and no hand edit can break it.
|
|
8
8
|
*
|
|
9
9
|
* node dashboard.mjs live <feature-folder> --task T19 --role implementer --activity "…" [--phase 7] [--step "…"]… [--reset] [--title "…"]
|
|
10
|
-
* node dashboard.mjs task <feature-folder> <task-id> --set '{"status":"built","summary":"…"}' [--note "why an earlier result changed" --by T21]
|
|
10
|
+
* node dashboard.mjs task <feature-folder> <task-id> --set '{"status":"built","summary":"…"}' [--note "why an earlier result changed" --by T21] [--no-frame "why a visual task has no built frame"]
|
|
11
11
|
* node dashboard.mjs snapshot <feature-folder> <T7|P2|plan> --src snapshots/T7-01-stage.png --caption "…" [--title "…"] [--source unity]
|
|
12
12
|
* (comparison: --before snapshots/a.png --after snapshots/b.png [--before-caption …] [--after-caption …];
|
|
13
13
|
* progression: --frame "snapshots/x.png|stage|caption" repeated)
|
|
14
|
+
* node dashboard.mjs snapshot <feature-folder> comparison --before snapshots/plan-before.png --after snapshots/plan-after.png --caption "…"
|
|
15
|
+
* (the After Action Report's one plan-wide before/after — replaces the previous one)
|
|
14
16
|
* node dashboard.mjs activity <feature-folder> "Phase 2 verified — T4–T6 PASS"
|
|
15
17
|
* node dashboard.mjs status <feature-folder> in-progress|paused|complete|incomplete
|
|
16
18
|
* node dashboard.mjs check <feature-folder>
|
|
@@ -18,15 +20,53 @@
|
|
|
18
20
|
*
|
|
19
21
|
* <feature-folder> is .agents/specs/<slug>. Timestamps come from this machine's local clock.
|
|
20
22
|
*
|
|
23
|
+
* The live file (`documents/<slug>_live.js`) is written by this helper, not by agents: every `task --set` that
|
|
24
|
+
* changes a task's `status` rewrites it from that change (the task, its phase, the role its status implies, one
|
|
25
|
+
* sentence on its new state plus the summary's first sentence, and a step in its log), and every `status` write
|
|
26
|
+
* records the run starting or ending. A `--set` without `status` leaves it untouched. `live` remains for a hand
|
|
27
|
+
* write; `watch` is a manual tool — no skill launches it.
|
|
28
|
+
*
|
|
21
29
|
* Snapshots go in only through `snapshot`. `task --set` and `check` refuse any snapshot entry the page cannot show —
|
|
22
30
|
* an image under `path` (or `file`, `image`, …) instead of `src`, or a `src` that is not a file under the feature
|
|
23
31
|
* folder — because such an entry renders as "No snapshot".
|
|
32
|
+
*
|
|
33
|
+
* The snapshots are the story of how the plan was built, so frames are never left behind. A `task --set` that moves
|
|
34
|
+
* a task to `built`, `verifying` or `done` is refused while `snapshots/` holds a `<task-id>-…` image no dashboard entry
|
|
35
|
+
* shows — add each with `snapshot` first. Moving a visual task (kind live, game or unity) to `built` with no snapshot
|
|
36
|
+
* at all is refused too, unless `--no-frame "<reason>"` records why it has nothing to show yet.
|
|
37
|
+
*
|
|
38
|
+
* `check` is the gate at every phase boundary and at run end. Beyond the snapshots it fails, listing every problem in
|
|
39
|
+
* one message, when a deliverable was skipped: a `documents/<slug>_plan.md` without `dashboard.html`, the dashboard
|
|
40
|
+
* data or the live file; dashboard tasks that differ from the plan's checklist (ids or order); a `complete` status
|
|
41
|
+
* while the plan has an unticked box or without `documents/<slug>_summary.html`; a visual task (kind live, game or
|
|
42
|
+
* unity) that is `done` with no snapshot of its own or progression frame tagged with its id; a task ticked in the plan
|
|
43
|
+
* whose dashboard entry has no verifier result. With no plan in the folder, the plan checks are skipped. It also
|
|
44
|
+
* fails on frames left behind in `snapshots/`: a built or finished task's `T<n>-…` images, a closed phase's `P<N>-…`
|
|
45
|
+
* images and — once a run has ended — a `plan-before` image that no dashboard entry shows.
|
|
24
46
|
*/
|
|
25
47
|
import { existsSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
26
|
-
import { basename, join, relative } from 'node:path';
|
|
48
|
+
import { basename, join, relative, resolve } from 'node:path';
|
|
27
49
|
|
|
28
50
|
/** How many entries a task's live step log keeps. */
|
|
29
51
|
const MAXIMUM_LIVE_STEPS = 12;
|
|
52
|
+
/** The prefix a live file starts with when the helper creates it. */
|
|
53
|
+
const LIVE_PREFIX = 'window.FEATURE_LIVE';
|
|
54
|
+
/** Who is working on a task in each status — the live file's `role` after a `task` write; anything else is the orchestrator. */
|
|
55
|
+
const ROLE_FOR_TASK_STATUS = { 'in-progress': 'implementer', built: 'implementer', verifying: 'verifier' };
|
|
56
|
+
/** Task kinds whose result is seen on screen, so a `done` task of this kind must have a snapshot. */
|
|
57
|
+
const VISUAL_TASK_KINDS = new Set(['live', 'game', 'unity']);
|
|
58
|
+
/** Task statuses that mean its builder is finished, so every frame saved for it belongs on the dashboard. */
|
|
59
|
+
const BUILT_TASK_STATUSES = new Set(['built', 'verifying', 'done']);
|
|
60
|
+
/** Phase statuses that mean a phase is closed, so every `P<N>-…` frame saved for it belongs on the dashboard. */
|
|
61
|
+
const CLOSED_PHASE_STATUSES = new Set(['done', 'partial', 'deferred']);
|
|
62
|
+
/** Run statuses that mean a run has ended and written its After Action Report. */
|
|
63
|
+
const RUN_ENDED_STATUSES = new Set(['paused', 'complete', 'incomplete']);
|
|
64
|
+
/** Image files a snapshot can show. */
|
|
65
|
+
const SNAPSHOT_IMAGE_FILE = /\.(png|jpe?g|webp|gif|avif)$/i;
|
|
66
|
+
/** The plan-wide "before" frame, saved before T1 of the first run. */
|
|
67
|
+
const PLAN_BEFORE_FILE = /^plan-before\.(png|jpe?g|webp|gif|avif)$/i;
|
|
68
|
+
/** A plan checklist line: `- [ ] **T3.1** — …` or `- [x] T4 …`; captures the tick mark and the task id. */
|
|
69
|
+
const PLAN_CHECKLIST_LINE = /^\s*[-*]\s+\[([ xX])\]\s+(?:\*\*)?(T\d+(?:\.\d+)*)\b/;
|
|
30
70
|
/** Folders the watchdog never descends into when looking for signs of work. */
|
|
31
71
|
const IGNORED_FOLDERS = new Set(['node_modules', '.git', 'Library', 'Temp', 'Logs', 'obj', 'dist', 'build', '.cache', 'profile']);
|
|
32
72
|
/** How deep the watchdog looks inside each watched folder. */
|
|
@@ -129,6 +169,15 @@ function parseOptions(argumentList, repeatable = []) {
|
|
|
129
169
|
return { options, positional };
|
|
130
170
|
}
|
|
131
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Reads the live file, or an empty one when it does not exist yet (the next write creates it).
|
|
174
|
+
* @param {string} livePath The live file.
|
|
175
|
+
* @returns {{ prefix: string, data: any }}
|
|
176
|
+
*/
|
|
177
|
+
function readLive(livePath) {
|
|
178
|
+
return existsSync(livePath) ? readData(livePath) : { prefix: LIVE_PREFIX, data: {} };
|
|
179
|
+
}
|
|
180
|
+
|
|
132
181
|
/**
|
|
133
182
|
* Rewrites the live status: what is happening this minute.
|
|
134
183
|
* @param {string} folder The feature folder.
|
|
@@ -137,7 +186,7 @@ function parseOptions(argumentList, repeatable = []) {
|
|
|
137
186
|
function writeLive(folder, argumentList) {
|
|
138
187
|
const { options } = parseOptions(argumentList, ['step']);
|
|
139
188
|
const { livePath } = dataPaths(folder);
|
|
140
|
-
const existing =
|
|
189
|
+
const existing = readLive(livePath);
|
|
141
190
|
const live = existing.data;
|
|
142
191
|
const now = localTime();
|
|
143
192
|
const taskChanged = options.task !== undefined && options.task !== live.task;
|
|
@@ -157,21 +206,127 @@ function writeLive(folder, argumentList) {
|
|
|
157
206
|
}
|
|
158
207
|
|
|
159
208
|
/**
|
|
160
|
-
*
|
|
209
|
+
* The first sentence of a text — up to the first `.`, `!` or `?` followed by a space or the end.
|
|
210
|
+
* @param {string} [text] The text, e.g. a task summary.
|
|
211
|
+
* @returns {string} The sentence, trimmed; the whole text when it has no sentence end; `""` for no text.
|
|
212
|
+
*/
|
|
213
|
+
function firstSentence(text) {
|
|
214
|
+
const trimmed = String(text || '').trim();
|
|
215
|
+
const match = /^[\s\S]*?[.!?](?=\s|$)/.exec(trimmed);
|
|
216
|
+
return match ? match[0] : trimmed;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* One plain-language sentence on a task's state, for the live file.
|
|
221
|
+
* @param {any} task The task, after the change (its `status`, `title`, `attempts`, `deferredReason`).
|
|
222
|
+
* @returns {string}
|
|
223
|
+
*/
|
|
224
|
+
function taskStatusSentence(task) {
|
|
225
|
+
const name = task.title ? `${task.id} — ${task.title}` : task.id;
|
|
226
|
+
const attempt = Number(task.attempts) || 1;
|
|
227
|
+
const reason = String(task.deferredReason || '').trim().replace(/[.!?]+$/, '');
|
|
228
|
+
switch (task.status) {
|
|
229
|
+
case 'in-progress':
|
|
230
|
+
return attempt > 1 ? `Fixing ${name} after a failed check (attempt ${attempt}).` : `Building ${name}.`;
|
|
231
|
+
case 'built':
|
|
232
|
+
return `${task.id} is built and its tests pass — waiting for the verifier.`;
|
|
233
|
+
case 'verifying':
|
|
234
|
+
return `The verifier is checking ${name}.`;
|
|
235
|
+
case 'done':
|
|
236
|
+
return `${task.id} passed verification and is done.`;
|
|
237
|
+
case 'deferred':
|
|
238
|
+
return reason ? `${task.id} was deferred: ${reason}.` : `${task.id} was deferred.`;
|
|
239
|
+
case 'failed':
|
|
240
|
+
return `${task.id} failed verification.`;
|
|
241
|
+
case 'pending':
|
|
242
|
+
return `${name} is waiting to start.`;
|
|
243
|
+
default:
|
|
244
|
+
return `${task.id} is now ${task.status}.`;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Rewrites the live file from a task's status change: its phase, the task, the role its status implies, one sentence
|
|
250
|
+
* on its new state (plus the first sentence of the summary written with it), and that sentence appended to the task's
|
|
251
|
+
* step log — a fresh log when the live file named another task. Creates the live file when it is missing.
|
|
252
|
+
* @param {string} folder The feature folder.
|
|
253
|
+
* @param {number} phaseNumber The number of the phase holding the task.
|
|
254
|
+
* @param {any} task The task, after the change.
|
|
255
|
+
* @param {string} [summary] The summary written in the same change, if any.
|
|
256
|
+
*/
|
|
257
|
+
function writeLiveForTask(folder, phaseNumber, task, summary) {
|
|
258
|
+
const { livePath } = dataPaths(folder);
|
|
259
|
+
const { prefix, data: live } = readLive(livePath);
|
|
260
|
+
const now = localTime();
|
|
261
|
+
const summarySentence = firstSentence(summary);
|
|
262
|
+
const activity = summarySentence ? `${taskStatusSentence(task)} ${summarySentence}` : taskStatusSentence(task);
|
|
263
|
+
const steps = live.task === task.id && Array.isArray(live.steps) ? live.steps : [];
|
|
264
|
+
steps.push({ at: now.clock, text: activity });
|
|
265
|
+
writeData(livePath, prefix, {
|
|
266
|
+
updatedAt: now.stamp,
|
|
267
|
+
phase: phaseNumber,
|
|
268
|
+
task: task.id,
|
|
269
|
+
title: '',
|
|
270
|
+
role: ROLE_FOR_TASK_STATUS[task.status] || 'orchestrator',
|
|
271
|
+
activity,
|
|
272
|
+
steps: steps.slice(-MAXIMUM_LIVE_STEPS),
|
|
273
|
+
source: 'agent',
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Rewrites the live file when the run's status changes: a run starting clears the last run's task and steps; a run
|
|
279
|
+
* ending says so (the page hides the live file once the status is no longer in-progress).
|
|
280
|
+
* @param {string} folder The feature folder.
|
|
281
|
+
* @param {string} status The dashboard's new status.
|
|
282
|
+
*/
|
|
283
|
+
function writeLiveForRun(folder, status) {
|
|
284
|
+
const { livePath } = dataPaths(folder);
|
|
285
|
+
const { prefix, data: live } = readLive(livePath);
|
|
286
|
+
const now = localTime();
|
|
287
|
+
const starting = status === 'in-progress';
|
|
288
|
+
const title = starting ? 'Run started — preparing the first task' : `Run ended — the plan is ${status}`;
|
|
289
|
+
writeData(livePath, prefix, {
|
|
290
|
+
updatedAt: now.stamp,
|
|
291
|
+
phase: live.phase,
|
|
292
|
+
task: '',
|
|
293
|
+
title,
|
|
294
|
+
role: 'orchestrator',
|
|
295
|
+
activity: `${title}.`,
|
|
296
|
+
steps: [{ at: now.clock, text: `${title}.` }],
|
|
297
|
+
source: 'agent',
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Finds a task anywhere in the dashboard data, with the phase that holds it.
|
|
161
303
|
* @param {any} dashboard The dashboard data.
|
|
162
304
|
* @param {string} taskId The task id, e.g. `T12.2`.
|
|
163
|
-
* @returns {any | undefined}
|
|
305
|
+
* @returns {{ phase: any, task: any } | undefined}
|
|
164
306
|
*/
|
|
165
|
-
function
|
|
307
|
+
function findTaskWithPhase(dashboard, taskId) {
|
|
166
308
|
for (const phase of dashboard.phases || []) {
|
|
167
309
|
const task = (phase.tasks || []).find((candidate) => candidate.id === taskId);
|
|
168
|
-
if (task) return task;
|
|
310
|
+
if (task) return { phase, task };
|
|
169
311
|
}
|
|
170
312
|
return undefined;
|
|
171
313
|
}
|
|
172
314
|
|
|
173
315
|
/**
|
|
174
|
-
*
|
|
316
|
+
* Finds a task anywhere in the dashboard data.
|
|
317
|
+
* @param {any} dashboard The dashboard data.
|
|
318
|
+
* @param {string} taskId The task id, e.g. `T12.2`.
|
|
319
|
+
* @returns {any | undefined}
|
|
320
|
+
*/
|
|
321
|
+
function findTask(dashboard, taskId) {
|
|
322
|
+
const found = findTaskWithPhase(dashboard, taskId);
|
|
323
|
+
return found ? found.task : undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Merges fields into one task, optionally recording why an earlier result changed. A change that sets `status` also
|
|
328
|
+
* rewrites the live file (see `writeLiveForTask`); any other change leaves it as it was. A move to `built`,
|
|
329
|
+
* `verifying` or `done` is refused while the task's frames are left behind (see `frameHandOffProblem`).
|
|
175
330
|
* @param {string} folder The feature folder.
|
|
176
331
|
* @param {string[]} argumentList The task id and options.
|
|
177
332
|
*/
|
|
@@ -181,8 +336,9 @@ function writeTask(folder, argumentList) {
|
|
|
181
336
|
if (!taskId || typeof options.set !== 'string') throw new Error('usage: task <feature-folder> <task-id> --set \'{"status":"built"}\'');
|
|
182
337
|
const { dashboardPath } = dataPaths(folder);
|
|
183
338
|
const { prefix, data } = readData(dashboardPath);
|
|
184
|
-
const
|
|
185
|
-
if (!
|
|
339
|
+
const found = findTaskWithPhase(data, taskId);
|
|
340
|
+
if (!found) throw new Error(`task ${taskId} is not in ${dashboardPath} — sync the dashboard with the plan first`);
|
|
341
|
+
const { phase, task } = found;
|
|
186
342
|
const changes = JSON.parse(options.set);
|
|
187
343
|
checkTaskShape(changes);
|
|
188
344
|
if (Array.isArray(changes.snapshots)) {
|
|
@@ -192,13 +348,55 @@ function writeTask(folder, argumentList) {
|
|
|
192
348
|
if (problems.length) throw new Error(snapshotRefusal(problems));
|
|
193
349
|
}
|
|
194
350
|
Object.assign(task, changes);
|
|
351
|
+
const noFrameReason = typeof options['no-frame'] === 'string' ? options['no-frame'] : '';
|
|
352
|
+
const handOffProblem = frameHandOffProblem(folder, data, task, changes.status, noFrameReason);
|
|
353
|
+
if (handOffProblem) throw new Error(handOffProblem);
|
|
195
354
|
const now = localTime();
|
|
196
355
|
if (typeof options.note === 'string') {
|
|
197
356
|
task.updates = Array.isArray(task.updates) ? task.updates : [];
|
|
198
357
|
task.updates.push({ at: now.stamp, by: typeof options.by === 'string' ? options.by : taskId, note: options.note });
|
|
199
358
|
}
|
|
359
|
+
if (noFrameReason && changes.status === 'built') {
|
|
360
|
+
data.activity = Array.isArray(data.activity) ? data.activity : [];
|
|
361
|
+
data.activity.push({ at: now.stamp, text: `${taskId} built with no frame yet — ${noFrameReason}` });
|
|
362
|
+
}
|
|
200
363
|
data.updatedAt = now.stamp;
|
|
201
364
|
writeData(dashboardPath, prefix, data);
|
|
365
|
+
if (typeof changes.status === 'string') writeLiveForTask(folder, phase.number, task, changes.summary);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Why a status change must wait for the task's frames, or `''` when it may go ahead. The snapshots are the story of
|
|
370
|
+
* the build, so a task never moves past its builder while a frame saved for it (`snapshots/<task-id>-…`) is on no
|
|
371
|
+
* dashboard entry, and a visual task is not `built` until its built frame is on the page — unless the builder gives
|
|
372
|
+
* a reason it has nothing to show yet.
|
|
373
|
+
* @param {string} folder The feature folder.
|
|
374
|
+
* @param {any} dashboard The dashboard data, with the change already merged.
|
|
375
|
+
* @param {any} task The task, with the change already merged.
|
|
376
|
+
* @param {string | undefined} newStatus The status being written, if any.
|
|
377
|
+
* @param {string} noFrameReason The `--no-frame` reason, or `''`.
|
|
378
|
+
* @returns {string} The refusal message, or `''`.
|
|
379
|
+
*/
|
|
380
|
+
function frameHandOffProblem(folder, dashboard, task, newStatus, noFrameReason) {
|
|
381
|
+
if (!BUILT_TASK_STATUSES.has(newStatus)) return '';
|
|
382
|
+
const leftBehind = framesNamedFor(unshownSnapshotFiles(folder, dashboard), task.id);
|
|
383
|
+
if (leftBehind.length) {
|
|
384
|
+
return [
|
|
385
|
+
`refused — ${task.id} cannot be "${newStatus}" while its frames are on disk but not on the dashboard (the snapshots tell the story of the build):`,
|
|
386
|
+
...leftBehind.map((name) => ` snapshots/${name}`),
|
|
387
|
+
'Add them first, then repeat this write — a progression from one camera, or a still each:',
|
|
388
|
+
` node dashboard.mjs snapshot ${folder} ${task.id} --frame "snapshots/${leftBehind[0]}|<stage>|<what this stage added>" … --caption "…"`,
|
|
389
|
+
` node dashboard.mjs snapshot ${folder} ${task.id} --src snapshots/${leftBehind[0]} --caption "…"`,
|
|
390
|
+
].join('\n');
|
|
391
|
+
}
|
|
392
|
+
const isVisual = VISUAL_TASK_KINDS.has(task.kind);
|
|
393
|
+
if (newStatus !== 'built' || !isVisual || noFrameReason || taskIdsWithSnapshots(dashboard).has(task.id)) return '';
|
|
394
|
+
return [
|
|
395
|
+
`refused — ${task.id} (kind ${task.kind}) is visual and has no snapshot, so the dashboard would show nothing of what was built.`,
|
|
396
|
+
`Save its built frame (and the before / milestone frames you took) to snapshots/${task.id}-<NN>-<stage>.png, add them with`,
|
|
397
|
+
` node dashboard.mjs snapshot ${folder} ${task.id} --src snapshots/${task.id}-01-<stage>.png --caption "…"`,
|
|
398
|
+
'then repeat this write. Only when it truly has nothing to show yet, add --no-frame "<why>" to this write.',
|
|
399
|
+
].join('\n');
|
|
202
400
|
}
|
|
203
401
|
|
|
204
402
|
/**
|
|
@@ -291,15 +489,20 @@ function snapshotListFor(dashboard, target) {
|
|
|
291
489
|
/**
|
|
292
490
|
* Appends one snapshot — a still (`--src`), a comparison (`--before` and `--after`) or a progression (`--frame`,
|
|
293
491
|
* repeated, each `src|stage|caption`) — to a task, a phase or the plan, building the shape the page renders and
|
|
294
|
-
* refusing an image that is not on disk.
|
|
492
|
+
* refusing an image that is not on disk. The target `comparison` instead sets the After Action Report's one
|
|
493
|
+
* plan-wide before/after. This is the way to add snapshots: nobody writes snapshot JSON by hand.
|
|
295
494
|
* @param {string} folder The feature folder.
|
|
296
495
|
* @param {string[]} argumentList The target and options.
|
|
297
496
|
*/
|
|
298
497
|
function writeSnapshot(folder, argumentList) {
|
|
299
498
|
const { options, positional } = parseOptions(argumentList, ['frame']);
|
|
300
499
|
const [target] = positional;
|
|
301
|
-
const usage = 'usage: snapshot <feature-folder> <T3|P1|plan> (--src snapshots/x.png | --before snapshots/a.png --after snapshots/b.png | --frame "snapshots/x.png|stage|caption"…) --caption "…" [--title "…"] [--source browser|unity|blender|reference] [--before-caption "…"] [--after-caption "…"] [--task T3]';
|
|
500
|
+
const usage = 'usage: snapshot <feature-folder> <T3|P1|plan|comparison> (--src snapshots/x.png | --before snapshots/a.png --after snapshots/b.png | --frame "snapshots/x.png|stage|caption"…) --caption "…" [--title "…"] [--source browser|unity|blender|reference] [--before-caption "…"] [--after-caption "…"] [--task T3]';
|
|
302
501
|
if (!target) throw new Error(usage);
|
|
502
|
+
const isPlanComparison = target === 'comparison';
|
|
503
|
+
if (isPlanComparison && !(typeof options.before === 'string' && typeof options.after === 'string')) {
|
|
504
|
+
throw new Error('the plan-wide comparison takes --before snapshots/plan-before.png --after snapshots/plan-after.png');
|
|
505
|
+
}
|
|
303
506
|
const caption = typeof options.caption === 'string' ? options.caption : '';
|
|
304
507
|
const snapshot = { title: typeof options.title === 'string' ? options.title : caption, caption, source: typeof options.source === 'string' ? options.source : 'browser' };
|
|
305
508
|
if (typeof options.src === 'string') {
|
|
@@ -321,7 +524,12 @@ function writeSnapshot(folder, argumentList) {
|
|
|
321
524
|
if (problems.length) throw new Error(snapshotRefusal(problems));
|
|
322
525
|
const { dashboardPath } = dataPaths(folder);
|
|
323
526
|
const { prefix, data } = readData(dashboardPath);
|
|
324
|
-
|
|
527
|
+
if (isPlanComparison) {
|
|
528
|
+
data.afterAction = data.afterAction && typeof data.afterAction === 'object' ? data.afterAction : {};
|
|
529
|
+
data.afterAction.comparison = snapshot;
|
|
530
|
+
} else {
|
|
531
|
+
snapshotListFor(data, target).push(snapshot);
|
|
532
|
+
}
|
|
325
533
|
data.updatedAt = localTime().stamp;
|
|
326
534
|
writeData(dashboardPath, prefix, data);
|
|
327
535
|
}
|
|
@@ -448,6 +656,53 @@ function allSnapshots(dashboard) {
|
|
|
448
656
|
return entries;
|
|
449
657
|
}
|
|
450
658
|
|
|
659
|
+
/**
|
|
660
|
+
* The images one snapshot entry shows: a progression's frames, a comparison's two sides, or the still itself.
|
|
661
|
+
* @param {any} snapshot A still, comparison or progression.
|
|
662
|
+
* @returns {any[]} Objects that carry a `src`.
|
|
663
|
+
*/
|
|
664
|
+
function snapshotImages(snapshot) {
|
|
665
|
+
if (!snapshot || typeof snapshot !== 'object') return [];
|
|
666
|
+
if (Array.isArray(snapshot.frames)) return snapshot.frames;
|
|
667
|
+
if (snapshot.before !== undefined || snapshot.after !== undefined) return [snapshot.before, snapshot.after];
|
|
668
|
+
return [snapshot];
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* The images in the feature folder's `snapshots/` that no dashboard entry shows — frames a builder or verifier saved
|
|
673
|
+
* that never reached the page, so the story of the build is missing them.
|
|
674
|
+
* @param {string} folder The feature folder.
|
|
675
|
+
* @param {any} dashboard The dashboard data.
|
|
676
|
+
* @returns {string[]} File names inside `snapshots/`, e.g. `T1-02-lit.png`.
|
|
677
|
+
*/
|
|
678
|
+
function unshownSnapshotFiles(folder, dashboard) {
|
|
679
|
+
const snapshotsFolder = join(folder, 'snapshots');
|
|
680
|
+
if (!existsSync(snapshotsFolder)) return [];
|
|
681
|
+
const shownPaths = new Set(
|
|
682
|
+
allSnapshots(dashboard)
|
|
683
|
+
.flatMap(({ snapshot }) => snapshotImages(snapshot))
|
|
684
|
+
.map((image) => (image && typeof image.src === 'string' ? image.src : ''))
|
|
685
|
+
.filter((source) => source && !/^[a-z]+:/i.test(source))
|
|
686
|
+
.map((source) => resolve(folder, source)),
|
|
687
|
+
);
|
|
688
|
+
return readdirSync(snapshotsFolder)
|
|
689
|
+
.filter((name) => SNAPSHOT_IMAGE_FILE.test(name))
|
|
690
|
+
.filter((name) => !shownPaths.has(resolve(snapshotsFolder, name)))
|
|
691
|
+
.sort();
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* The file names saved for one task or phase: those named `<id>-…` (`T7-02-lit.png`, `P2-01-blockout.png`).
|
|
696
|
+
* `T1-` never matches `T10-…` or `T1.2-…`.
|
|
697
|
+
* @param {string[]} fileNames File names inside `snapshots/`.
|
|
698
|
+
* @param {string} ownerId A task id (`T7`, `T3.1`) or phase id (`P2`).
|
|
699
|
+
* @returns {string[]}
|
|
700
|
+
*/
|
|
701
|
+
function framesNamedFor(fileNames, ownerId) {
|
|
702
|
+
const prefix = `${ownerId}-`.toLowerCase();
|
|
703
|
+
return fileNames.filter((name) => name.toLowerCase().startsWith(prefix));
|
|
704
|
+
}
|
|
705
|
+
|
|
451
706
|
/**
|
|
452
707
|
* Appends one milestone to the activity log.
|
|
453
708
|
* @param {string} folder The feature folder.
|
|
@@ -466,7 +721,7 @@ function writeActivity(folder, argumentList) {
|
|
|
466
721
|
}
|
|
467
722
|
|
|
468
723
|
/**
|
|
469
|
-
* Sets the dashboard's run status.
|
|
724
|
+
* Sets the dashboard's run status, and records the run starting or ending in the live file.
|
|
470
725
|
* @param {string} folder The feature folder.
|
|
471
726
|
* @param {string[]} argumentList The new status.
|
|
472
727
|
*/
|
|
@@ -479,16 +734,174 @@ function writeStatus(folder, argumentList) {
|
|
|
479
734
|
data.status = status;
|
|
480
735
|
data.updatedAt = localTime().stamp;
|
|
481
736
|
writeData(dashboardPath, prefix, data);
|
|
737
|
+
if (status !== 'planned') writeLiveForRun(folder, status);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Reads a plan's checklist: every `- [ ]` / `- [x]` line that starts with a task id, in file order, skipping fenced
|
|
742
|
+
* code blocks (a plan may quote a checklist as an example).
|
|
743
|
+
* @param {string} planPath The plan file.
|
|
744
|
+
* @returns {{ id: string, ticked: boolean }[]}
|
|
745
|
+
*/
|
|
746
|
+
function readPlanChecklist(planPath) {
|
|
747
|
+
const tasks = [];
|
|
748
|
+
let insideFence = false;
|
|
749
|
+
for (const line of readFileSync(planPath, 'utf8').split(/\r?\n/)) {
|
|
750
|
+
if (/^\s*(```|~~~)/.test(line)) {
|
|
751
|
+
insideFence = !insideFence;
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
const match = insideFence ? null : PLAN_CHECKLIST_LINE.exec(line);
|
|
755
|
+
if (match) tasks.push({ id: match[2], ticked: match[1] !== ' ' });
|
|
756
|
+
}
|
|
757
|
+
return tasks;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* The feature-folder files a written plan must have beside it.
|
|
762
|
+
* @param {string} folder The feature folder.
|
|
763
|
+
* @returns {string[]} One problem per missing file.
|
|
764
|
+
*/
|
|
765
|
+
function missingDeliverables(folder) {
|
|
766
|
+
const { slug } = dataPaths(folder);
|
|
767
|
+
const required = [
|
|
768
|
+
['dashboard.html', `copy it from bt-execute's templates/dashboard/ with {{slug}} replaced`],
|
|
769
|
+
[join('documents', `${slug}_dashboard.js`), 'create it from templates/dashboard/dashboard.template.js and the plan'],
|
|
770
|
+
[join('documents', `${slug}_live.js`), 'create it from templates/dashboard/live.template.js'],
|
|
771
|
+
];
|
|
772
|
+
return required
|
|
773
|
+
.filter(([file]) => !existsSync(join(folder, file)))
|
|
774
|
+
.map(([file, remedy]) => `the plan has no ${file} — ${remedy}`);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Compares the dashboard's tasks with the plan's checklist: tasks missing on either side, or the same tasks in a
|
|
779
|
+
* different order.
|
|
780
|
+
* @param {string[]} planIds The plan's task ids, in plan order.
|
|
781
|
+
* @param {string[]} dashboardIds The dashboard's task ids, in page order.
|
|
782
|
+
* @returns {string[]} One problem per kind of mismatch.
|
|
783
|
+
*/
|
|
784
|
+
function taskListProblems(planIds, dashboardIds) {
|
|
785
|
+
const missing = planIds.filter((id) => !dashboardIds.includes(id));
|
|
786
|
+
const extra = dashboardIds.filter((id) => !planIds.includes(id));
|
|
787
|
+
const problems = [];
|
|
788
|
+
if (missing.length) problems.push(`plan tasks missing from the dashboard: ${missing.join(', ')} — sync the dashboard with the plan`);
|
|
789
|
+
if (extra.length) problems.push(`dashboard tasks the plan does not have: ${extra.join(', ')} — sync the dashboard with the plan`);
|
|
790
|
+
if (problems.length) return problems;
|
|
791
|
+
const position = planIds.findIndex((id, index) => dashboardIds[index] !== id);
|
|
792
|
+
if (position >= 0) {
|
|
793
|
+
problems.push(`the dashboard lists the tasks in a different order from the plan (position ${position + 1}: plan ${planIds[position]}, dashboard ${dashboardIds[position]}) — sync the dashboard with the plan`);
|
|
794
|
+
}
|
|
795
|
+
return problems;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* The plan checks: the dashboard's tasks match the checklist, a `complete` status is true and has its plan summary,
|
|
800
|
+
* and every ticked task has a verifier result.
|
|
801
|
+
* @param {string} folder The feature folder.
|
|
802
|
+
* @param {any} dashboard The dashboard data.
|
|
803
|
+
* @param {{ id: string, ticked: boolean }[]} planTasks The plan's checklist.
|
|
804
|
+
* @returns {string[]} One line per problem.
|
|
805
|
+
*/
|
|
806
|
+
function planProblems(folder, dashboard, planTasks) {
|
|
807
|
+
const { slug } = dataPaths(folder);
|
|
808
|
+
const dashboardTasks = (dashboard.phases || []).flatMap((phase) => phase.tasks || []);
|
|
809
|
+
const problems = taskListProblems(planTasks.map((task) => task.id), dashboardTasks.map((task) => task.id));
|
|
810
|
+
if (dashboard.status === 'complete') {
|
|
811
|
+
const unticked = planTasks.filter((task) => !task.ticked).map((task) => task.id);
|
|
812
|
+
if (unticked.length) problems.push(`status is complete but the plan still has unticked tasks: ${unticked.join(', ')} — set paused or incomplete`);
|
|
813
|
+
const summaryFile = join('documents', `${slug}_summary.html`);
|
|
814
|
+
if (!existsSync(join(folder, summaryFile))) problems.push(`status is complete but ${summaryFile} is missing — write the plan summary`);
|
|
815
|
+
}
|
|
816
|
+
for (const planTask of planTasks.filter((task) => task.ticked)) {
|
|
817
|
+
const dashboardTask = dashboardTasks.find((task) => task.id === planTask.id);
|
|
818
|
+
if (dashboardTask && !dashboardTask.verifier) problems.push(`${planTask.id} is ticked in the plan but has no verifier result on the dashboard`);
|
|
819
|
+
}
|
|
820
|
+
return problems;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* The ids of tasks that have something on the page: a snapshot of their own, or a phase or After Action Report
|
|
825
|
+
* progression frame tagged with their id.
|
|
826
|
+
* @param {any} dashboard The dashboard data.
|
|
827
|
+
* @returns {Set<string>}
|
|
828
|
+
*/
|
|
829
|
+
function taskIdsWithSnapshots(dashboard) {
|
|
830
|
+
const sharedLists = [dashboard.afterAction && dashboard.afterAction.snapshots, ...(dashboard.phases || []).map((phase) => phase.snapshots)];
|
|
831
|
+
const taskIds = new Set(
|
|
832
|
+
sharedLists
|
|
833
|
+
.flatMap((list) => (Array.isArray(list) ? list : []))
|
|
834
|
+
.flatMap((snapshot) => (snapshot && Array.isArray(snapshot.frames) ? snapshot.frames : []))
|
|
835
|
+
.map((frame) => frame && frame.task),
|
|
836
|
+
);
|
|
837
|
+
for (const task of (dashboard.phases || []).flatMap((phase) => phase.tasks || [])) {
|
|
838
|
+
if (Array.isArray(task.snapshots) && task.snapshots.length) taskIds.add(task.id);
|
|
839
|
+
}
|
|
840
|
+
return taskIds;
|
|
482
841
|
}
|
|
483
842
|
|
|
484
843
|
/**
|
|
485
|
-
*
|
|
486
|
-
*
|
|
844
|
+
* Visual tasks marked `done` with nothing to show for it: no snapshot of their own and no phase or After Action
|
|
845
|
+
* Report progression frame tagged with their id.
|
|
846
|
+
* @param {any} dashboard The dashboard data.
|
|
847
|
+
* @returns {string[]} One line per task.
|
|
848
|
+
*/
|
|
849
|
+
function visualTaskProblems(dashboard) {
|
|
850
|
+
const taskIds = taskIdsWithSnapshots(dashboard);
|
|
851
|
+
return (dashboard.phases || [])
|
|
852
|
+
.flatMap((phase) => phase.tasks || [])
|
|
853
|
+
.filter((task) => task.status === 'done' && VISUAL_TASK_KINDS.has(task.kind) && !taskIds.has(task.id))
|
|
854
|
+
.map((task) => `${task.id} (kind ${task.kind}) is done with no snapshot — add the builder's frames and the verifier's comparison with \`dashboard.mjs snapshot\``);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Frames left behind in `snapshots/`: a built or finished task's `T<n>-…` images, a closed phase's `P<N>-…` images,
|
|
859
|
+
* and — once a run has ended — a `plan-before` image, that no dashboard entry shows.
|
|
487
860
|
* @param {string} folder The feature folder.
|
|
488
|
-
* @
|
|
861
|
+
* @param {any} dashboard The dashboard data.
|
|
862
|
+
* @returns {string[]} One line per task, phase or plan-wide frame.
|
|
863
|
+
*/
|
|
864
|
+
function unshownFrameProblems(folder, dashboard) {
|
|
865
|
+
const unshown = unshownSnapshotFiles(folder, dashboard);
|
|
866
|
+
if (!unshown.length) return [];
|
|
867
|
+
const problems = [];
|
|
868
|
+
const report = (ownerId, names) => {
|
|
869
|
+
if (names.length) problems.push(`${ownerId} has frames on disk that no dashboard entry shows: ${names.map((name) => `snapshots/${name}`).join(', ')} — add each to ${ownerId} with \`dashboard.mjs snapshot\``);
|
|
870
|
+
};
|
|
871
|
+
for (const phase of dashboard.phases || []) {
|
|
872
|
+
for (const task of (phase.tasks || []).filter((candidate) => BUILT_TASK_STATUSES.has(candidate.status))) report(task.id, framesNamedFor(unshown, task.id));
|
|
873
|
+
if (CLOSED_PHASE_STATUSES.has(phase.status)) report(`P${phase.number}`, framesNamedFor(unshown, `P${phase.number}`));
|
|
874
|
+
}
|
|
875
|
+
if (RUN_ENDED_STATUSES.has(dashboard.status)) {
|
|
876
|
+
for (const name of unshown.filter((candidate) => PLAN_BEFORE_FILE.test(candidate))) {
|
|
877
|
+
problems.push(`snapshots/${name} is not in the After Action Report — make it the plan-wide "before": \`dashboard.mjs snapshot <feature-folder> comparison --before snapshots/${name} --after snapshots/plan-after.png --caption "…"\``);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return problems;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Builds the refusal message for skipped deliverables.
|
|
885
|
+
* @param {string[]} problems What is missing or false, one line each.
|
|
886
|
+
* @returns {string}
|
|
887
|
+
*/
|
|
888
|
+
function deliverableRefusal(problems) {
|
|
889
|
+
return `refused — ${problems.length} deliverable problem${problems.length === 1 ? '' : 's'}:\n ${problems.join('\n ')}`;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* The gate at every phase boundary and at run end. Confirms both data files parse and every snapshot entry will show
|
|
894
|
+
* its image, and — when the folder holds the plan — that no deliverable was skipped (see the header). Fails listing
|
|
895
|
+
* every problem in one message.
|
|
896
|
+
* @param {string} folder The feature folder.
|
|
897
|
+
* @throws {Error} When a file does not parse, a snapshot entry is broken or a deliverable is missing or false.
|
|
489
898
|
*/
|
|
490
899
|
function checkData(folder) {
|
|
491
|
-
const { dashboardPath, livePath } = dataPaths(folder);
|
|
900
|
+
const { slug, dashboardPath, livePath } = dataPaths(folder);
|
|
901
|
+
const planPath = join(folder, 'documents', `${slug}_plan.md`);
|
|
902
|
+
const planTasks = existsSync(planPath) ? readPlanChecklist(planPath) : null;
|
|
903
|
+
const missing = planTasks ? missingDeliverables(folder) : [];
|
|
904
|
+
if (missing.length && !existsSync(dashboardPath)) throw new Error(deliverableRefusal(missing));
|
|
492
905
|
const { prefix, data } = readData(dashboardPath);
|
|
493
906
|
if (existsSync(livePath)) readData(livePath);
|
|
494
907
|
const repairs = repairSnapshots(data);
|
|
@@ -502,8 +915,11 @@ function checkData(folder) {
|
|
|
502
915
|
}
|
|
503
916
|
const snapshots = allSnapshots(data);
|
|
504
917
|
const problems = snapshots.flatMap(({ snapshot, where }) => snapshotProblems(folder, snapshot, where));
|
|
505
|
-
|
|
506
|
-
|
|
918
|
+
const deliverables = [...missing, ...visualTaskProblems(data), ...unshownFrameProblems(folder, data), ...(planTasks ? planProblems(folder, data, planTasks) : [])];
|
|
919
|
+
const refusals = [problems.length ? snapshotRefusal(problems) : '', deliverables.length ? deliverableRefusal(deliverables) : ''].filter(Boolean);
|
|
920
|
+
if (refusals.length) throw new Error(refusals.join('\n'));
|
|
921
|
+
const planNote = planTasks ? `; the dashboard matches the plan's ${planTasks.length} tasks` : '';
|
|
922
|
+
console.log(`ok: ${dashboardPath}${existsSync(livePath) ? ` and ${livePath}` : ''} parse; ${snapshots.length} snapshot entries all show an image${planNote}`);
|
|
507
923
|
}
|
|
508
924
|
|
|
509
925
|
/**
|
|
@@ -526,7 +942,7 @@ function latestChange(roots) {
|
|
|
526
942
|
if (depth < MAXIMUM_SCAN_DEPTH && !IGNORED_FOLDERS.has(entry.name)) visit(path, depth + 1);
|
|
527
943
|
continue;
|
|
528
944
|
}
|
|
529
|
-
// The dashboard's own data files are written by
|
|
945
|
+
// The dashboard's own data files are written by this helper and the watchdog itself — not a sign of work.
|
|
530
946
|
if (!entry.isFile() || entry.name.endsWith('.tmp') || /_(dashboard|live)\.js$/.test(entry.name)) continue;
|
|
531
947
|
try {
|
|
532
948
|
const modified = statSync(path).mtimeMs;
|
|
@@ -553,7 +969,8 @@ function parseStamp(stamp) {
|
|
|
553
969
|
}
|
|
554
970
|
|
|
555
971
|
/**
|
|
556
|
-
* The watchdog
|
|
972
|
+
* The watchdog — a manual tool (no skill launches it; `task` and `status` keep the live file current). While the
|
|
973
|
+
* dashboard says a run is in progress it checks the live status every interval:
|
|
557
974
|
* - the live status names a task that is already finished while another task is active → it points the live
|
|
558
975
|
* status at the active task (the agent working on it has not written yet);
|
|
559
976
|
* - nothing has been written for `quiet-minutes` → it writes a heartbeat naming the latest file that changed in
|