pi-spine 1.0.2 → 1.2.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.
Files changed (129) hide show
  1. package/README.md +61 -489
  2. package/bin/get-version.mjs +1 -13
  3. package/bin/spine-batch.mjs +162 -51
  4. package/bin/spine-cli/batch.mjs +3 -3
  5. package/bin/spine-cli/lane-logs.mjs +24 -0
  6. package/bin/spine-cli/scenarios.mjs +298 -0
  7. package/bin/spine-cli/wait.mjs +30 -0
  8. package/bin/spine-cli/watch.mjs +27 -0
  9. package/bin/spine-config.mjs +1 -212
  10. package/bin/spine-doctor.mjs +2 -418
  11. package/bin/spine-init.mjs +1 -398
  12. package/bin/spine-issue.mjs +196 -0
  13. package/bin/spine-journal.mjs +1 -0
  14. package/bin/spine-preflight.mjs +1 -700
  15. package/bin/spine-review-step.mjs +6 -4
  16. package/bin/spine-run.mjs +30 -0
  17. package/bin/spine-status.mjs +19 -1
  18. package/bin/spine-tasks.mjs +112 -13
  19. package/bin/spine-worker-runner.mjs +24 -14
  20. package/bin/spine.mjs +52 -2
  21. package/extensions/spine/worker-tools.ts +14 -12
  22. package/package.json +5 -2
  23. package/skills/create-spine-tasks/SKILL.md +135 -6
  24. package/skills/create-spine-tasks/references/clarify-template.md +73 -0
  25. package/skills/create-spine-tasks/references/contract-template.md +19 -0
  26. package/skills/create-spine-tasks/references/prompt-template.md +2 -0
  27. package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
  28. package/src/batch/abort.mjs +3 -12
  29. package/src/batch/agent-session-worker.mjs +45 -5
  30. package/src/batch/attached-engine-handoff.mjs +188 -0
  31. package/src/batch/attached-runner.mjs +312 -0
  32. package/src/batch/contract-prelanded.mjs +180 -0
  33. package/src/batch/contract-verify.mjs +140 -2
  34. package/src/batch/detached-start.mjs +105 -7
  35. package/src/batch/diagnosis-alternatives.mjs +46 -0
  36. package/src/batch/diagnosis-merge-failure.mjs +79 -0
  37. package/src/batch/diagnosis-retry-limbo.mjs +34 -0
  38. package/src/batch/diagnosis-stub.mjs +109 -0
  39. package/src/batch/diagnosis-task-done.mjs +110 -0
  40. package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
  41. package/src/batch/diagnosis.mjs +174 -62
  42. package/src/batch/engine-lanes/merge.mjs +168 -77
  43. package/src/batch/engine-lanes/queue.mjs +4 -1
  44. package/src/batch/engine-lanes/review.mjs +32 -74
  45. package/src/batch/engine-lanes/watch.mjs +29 -0
  46. package/src/batch/engine-lanes.mjs +1 -0
  47. package/src/batch/engine-scope.mjs +42 -5
  48. package/src/batch/engine.mjs +115 -68
  49. package/src/batch/evidence.mjs +81 -17
  50. package/src/batch/gate.mjs +46 -17
  51. package/src/batch/git-helpers.mjs +96 -0
  52. package/src/batch/heartbeat.mjs +73 -7
  53. package/src/batch/integrate.mjs +3 -5
  54. package/src/batch/journal.mjs +25 -0
  55. package/src/batch/lane-commit.mjs +90 -5
  56. package/src/batch/lifecycle.mjs +131 -4
  57. package/src/batch/macro-phase.mjs +226 -0
  58. package/src/batch/merge/adoption-doc-merge.mjs +243 -0
  59. package/src/batch/merge/wave-merge-state.mjs +108 -0
  60. package/src/batch/metrics.mjs +74 -5
  61. package/src/batch/orphan-detect.mjs +74 -0
  62. package/src/batch/pause.mjs +223 -0
  63. package/src/batch/post-merge-limbo.mjs +345 -17
  64. package/src/batch/reconcile.mjs +473 -50
  65. package/src/batch/resume-common.mjs +6 -2
  66. package/src/batch/resume-engine.mjs +58 -1
  67. package/src/batch/resume-lane-reviews.mjs +16 -0
  68. package/src/batch/resume-multi-lanes.mjs +56 -1
  69. package/src/batch/resume-multi-validate.mjs +148 -8
  70. package/src/batch/resume-multi.mjs +45 -44
  71. package/src/batch/resume.mjs +64 -47
  72. package/src/batch/retry.mjs +56 -5
  73. package/src/batch/review-shared.mjs +196 -0
  74. package/src/batch/review-spawn.mjs +326 -0
  75. package/src/batch/review.mjs +178 -212
  76. package/src/batch/rules-manifest-drift.mjs +157 -0
  77. package/src/batch/salvage.mjs +2 -1
  78. package/src/batch/sequence.mjs +454 -0
  79. package/src/batch/state.mjs +18 -3
  80. package/src/batch/status-json.mjs +67 -0
  81. package/src/batch/task-stall-budget.mjs +94 -10
  82. package/src/batch/worker-host.mjs +185 -37
  83. package/src/batch/worker-output.mjs +196 -3
  84. package/src/batch/worktree.mjs +10 -0
  85. package/src/cli/handoff.mjs +1 -1
  86. package/src/cli/issue-draft.mjs +180 -0
  87. package/src/cli/journal-follow.mjs +239 -0
  88. package/src/cli/lane-logs.mjs +291 -0
  89. package/src/cli/rules.mjs +1 -1
  90. package/src/cli/sequence.mjs +108 -0
  91. package/src/cli/settings-set.mjs +3 -22
  92. package/src/cli/settings-slash.mjs +27 -5
  93. package/src/cli/wait.mjs +187 -0
  94. package/src/cli/watch.mjs +160 -0
  95. package/src/config/agent-model-resolve.mjs +48 -0
  96. package/src/config/cursor-rules/discover.mjs +3 -21
  97. package/src/config/defaults.mjs +7 -1
  98. package/src/config/settings-fields.mjs +48 -0
  99. package/src/config/spine-config-load.mjs +221 -0
  100. package/src/config/spine-init-constants.mjs +424 -0
  101. package/src/config/spine-preflight-lib.mjs +1180 -0
  102. package/src/dashboard/lane-throughput.mjs +351 -0
  103. package/src/dashboard/public/dashboard.css +25 -1
  104. package/src/dashboard/public/dashboard.js +224 -40
  105. package/src/dashboard/public/index.html +15 -9
  106. package/src/dashboard/server.mjs +4 -0
  107. package/src/dashboard/snapshot.mjs +387 -6
  108. package/src/dashboard/view.mjs +170 -15
  109. package/src/doctor/agent-model-inherit.mjs +61 -6
  110. package/src/doctor/run-doctor-checks.mjs +483 -0
  111. package/src/doctor/sequence-safety.mjs +57 -0
  112. package/src/doctor/stale-path.mjs +22 -0
  113. package/src/doctor/stale-worktrees.mjs +102 -0
  114. package/src/fixtures/scenario-registry.mjs +194 -0
  115. package/src/fs/atomic-write.mjs +49 -0
  116. package/src/migrate/taskplane-config.mjs +1 -1
  117. package/src/planner/file-scope.mjs +246 -0
  118. package/src/planner/format-plan.mjs +9 -7
  119. package/src/planner/index.mjs +6 -2
  120. package/src/planner/pending.mjs +92 -1
  121. package/src/planner/wave-scope.mjs +136 -0
  122. package/src/planner/waves.mjs +133 -0
  123. package/src/tasks/analyze/index.mjs +453 -0
  124. package/src/tasks/packet/index.mjs +1 -0
  125. package/src/tasks/packet/parse-prompt.mjs +42 -1
  126. package/src/tasks/packet/validate-prompt.mjs +124 -0
  127. package/src/util/command-exists.mjs +19 -0
  128. package/templates/docs/constitution.md +61 -0
  129. package/templates/spine-config.json +9 -2
@@ -2,6 +2,9 @@
2
2
  * Dashboard snapshot builder (PRD §16, NFR-OBS-04).
3
3
  */
4
4
 
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { deriveMacroPhase, macroPhaseLabel } from "../batch/macro-phase.mjs";
5
8
  import {
6
9
  classifyTasks,
7
10
  loadBatchStateFile,
@@ -15,7 +18,27 @@ import {
15
18
  summarizeJournalEvent,
16
19
  } from "../batch/journal.mjs";
17
20
  import { resolveStallConfig } from "../batch/heartbeat.mjs";
18
- import { loadSpineConfig } from "../../bin/spine-config.mjs";
21
+ import { loadSpineConfig } from "../config/spine-config-load.mjs";
22
+ import {
23
+ deriveLanesThroughput,
24
+ deriveLaneThroughputStats,
25
+ emptyLaneThroughputStats,
26
+ summarizeLaneThroughput,
27
+ } from "./lane-throughput.mjs";
28
+ import {
29
+ filterMetricsLines,
30
+ metricsFilePath,
31
+ readMetricsLines,
32
+ } from "../batch/metrics.mjs";
33
+ import {
34
+ workerLiveLogPath,
35
+ workerLiveLogRef,
36
+ workerOutputLogPath,
37
+ workerOutputLogRef,
38
+ } from "../batch/worker-output.mjs";
39
+
40
+ const LANE_RECENT_EVENTS_LIMIT = 5;
41
+ const LANE_LOG_TAIL_LINES = 10;
19
42
 
20
43
  /**
21
44
  * @param {string|null|undefined} worktreePath
@@ -125,6 +148,166 @@ export function computeActiveTaskIdsForLane({ lane, classifiedTasks, currentWave
125
148
  */
126
149
  const LANE_ALERT_RECENT_MS = 30 * 60 * 1000;
127
150
 
151
+ /** @type {Record<string, string>} */
152
+ const REVIEW_TYPE_TO_ACTIVITY_PHASE = {
153
+ plan: "plan_review",
154
+ code: "code_review",
155
+ final: "final_review",
156
+ };
157
+
158
+ /** @type {Record<string, string>} */
159
+ const ACTIVITY_PHASE_LABELS = {
160
+ idle: "—",
161
+ queued: "queued",
162
+ launching: "launching",
163
+ worker: "worker",
164
+ verifying: "verifying",
165
+ plan_review: "plan review",
166
+ code_review: "code review",
167
+ final_review: "final review",
168
+ rework: "rework",
169
+ failed: "failed",
170
+ };
171
+
172
+ /**
173
+ * @param {number} laneNumber
174
+ * @param {object} event
175
+ */
176
+ export function laneEventMatches(laneNumber, event) {
177
+ const laneId = `lane-${laneNumber}`;
178
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
179
+ if (payload.laneNumber != null && payload.laneNumber !== laneNumber) return false;
180
+ if (event.laneId && event.laneId !== laneId) return false;
181
+ return true;
182
+ }
183
+
184
+ /**
185
+ * @param {object} event
186
+ */
187
+ function journalEventTaskId(event) {
188
+ if (typeof event.taskId === "string" && event.taskId) return event.taskId;
189
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
190
+ return typeof payload.taskId === "string" ? payload.taskId : null;
191
+ }
192
+
193
+ /**
194
+ * @param {object[]} journalEvents
195
+ * @param {string} taskId
196
+ * @param {unknown} stepNumber
197
+ */
198
+ function isReviewClosedForTaskStep(journalEvents, taskId, stepNumber) {
199
+ return journalEvents.some((event) => {
200
+ if (journalEventTaskId(event) !== taskId) return false;
201
+ if (event.type !== "review.completed" && event.type !== "review.failed") return false;
202
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
203
+ return payload.stepNumber === stepNumber;
204
+ });
205
+ }
206
+
207
+ /**
208
+ * @param {object[]} journalEvents
209
+ * @param {string} taskId
210
+ */
211
+ function taskFailedWithoutRestart(journalEvents, taskId) {
212
+ let lastFailedIdx = -1;
213
+ let lastStartedIdx = -1;
214
+ for (let i = 0; i < journalEvents.length; i += 1) {
215
+ const event = journalEvents[i];
216
+ if (journalEventTaskId(event) !== taskId) continue;
217
+ if (event.type === "task.failed") lastFailedIdx = i;
218
+ if (event.type === "task.started") lastStartedIdx = i;
219
+ }
220
+ return lastFailedIdx >= 0 && lastFailedIdx > lastStartedIdx;
221
+ }
222
+
223
+ /**
224
+ * @param {number} laneNumber
225
+ * @param {string} taskId
226
+ * @param {object[]} journalEvents
227
+ */
228
+ function taskHasReworkMarker(laneNumber, taskId, journalEvents) {
229
+ for (let i = journalEvents.length - 1; i >= 0; i -= 1) {
230
+ const event = journalEvents[i];
231
+ if (event.type !== "lane.completed") continue;
232
+ if (!laneEventMatches(laneNumber, event)) continue;
233
+ if (journalEventTaskId(event) !== taskId) continue;
234
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
235
+ const phase = payload.phase;
236
+ if (phase === "code_rework" || phase === "final_rework") return true;
237
+ }
238
+ return false;
239
+ }
240
+
241
+ /**
242
+ * @param {object} params
243
+ * @param {number} params.laneNumber
244
+ * @param {string[]} params.activeTaskIds
245
+ * @param {import("../batch/reconcile.mjs").NormalizedTask[]} params.classifiedTasks
246
+ * @param {object[]} params.journalEvents
247
+ */
248
+ export function resolveLaneActivityPhase({
249
+ laneNumber,
250
+ activeTaskIds = [],
251
+ classifiedTasks = [],
252
+ journalEvents = [],
253
+ }) {
254
+ const activeIds = new Set((activeTaskIds ?? []).map(String));
255
+ if (activeIds.size === 0) {
256
+ return { activityPhase: "idle", activityPhaseLabel: ACTIVITY_PHASE_LABELS.idle };
257
+ }
258
+
259
+ const events = journalEvents ?? [];
260
+
261
+ for (let i = events.length - 1; i >= 0; i -= 1) {
262
+ const event = events[i];
263
+ if (event.type !== "review.started") continue;
264
+ if (!laneEventMatches(laneNumber, event)) continue;
265
+ const taskId = journalEventTaskId(event);
266
+ if (!taskId || !activeIds.has(String(taskId))) continue;
267
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
268
+ const reviewType = payload.reviewType;
269
+ const stepNumber = payload.stepNumber;
270
+ if (typeof reviewType !== "string") continue;
271
+ if (isReviewClosedForTaskStep(events, taskId, stepNumber)) continue;
272
+ const activityPhase = REVIEW_TYPE_TO_ACTIVITY_PHASE[reviewType];
273
+ if (!activityPhase) continue;
274
+ return {
275
+ activityPhase,
276
+ activityPhaseLabel: ACTIVITY_PHASE_LABELS[activityPhase],
277
+ };
278
+ }
279
+
280
+ for (const taskId of activeIds) {
281
+ if (taskFailedWithoutRestart(events, String(taskId))) {
282
+ return { activityPhase: "failed", activityPhaseLabel: ACTIVITY_PHASE_LABELS.failed };
283
+ }
284
+ }
285
+
286
+ for (const taskId of activeIds) {
287
+ if (taskHasReworkMarker(laneNumber, String(taskId), events)) {
288
+ return { activityPhase: "rework", activityPhaseLabel: ACTIVITY_PHASE_LABELS.rework };
289
+ }
290
+ }
291
+
292
+ const heartbeatMeta = resolveLaneHeartbeatMeta(laneNumber, events);
293
+ if (heartbeatMeta.workerPhase === "launching") {
294
+ return { activityPhase: "launching", activityPhaseLabel: ACTIVITY_PHASE_LABELS.launching };
295
+ }
296
+ if (heartbeatMeta.workerPhase === "pi") {
297
+ return { activityPhase: "worker", activityPhaseLabel: ACTIVITY_PHASE_LABELS.worker };
298
+ }
299
+ if (heartbeatMeta.workerPhase === "verify") {
300
+ return { activityPhase: "verifying", activityPhaseLabel: ACTIVITY_PHASE_LABELS.verifying };
301
+ }
302
+
303
+ const activeTasks = (classifiedTasks ?? []).filter((task) => activeIds.has(String(task.taskId)));
304
+ if (activeTasks.some((task) => task.classification === "pending")) {
305
+ return { activityPhase: "queued", activityPhaseLabel: ACTIVITY_PHASE_LABELS.queued };
306
+ }
307
+
308
+ return { activityPhase: "worker", activityPhaseLabel: ACTIVITY_PHASE_LABELS.worker };
309
+ }
310
+
128
311
  /**
129
312
  * @param {number} laneNumber
130
313
  * @param {ReturnType<typeof formatJournalTailEntry>[]} journalTail
@@ -148,13 +331,11 @@ export function resolveLaneAlert(laneNumber, journalTail, now = Date.now()) {
148
331
  * @param {object[]} journalEvents
149
332
  */
150
333
  export function resolveLaneHeartbeatMeta(laneNumber, journalEvents) {
151
- const laneId = `lane-${laneNumber}`;
152
334
  for (let i = journalEvents.length - 1; i >= 0; i -= 1) {
153
335
  const event = journalEvents[i];
154
336
  if (event.type !== "lane.heartbeat") continue;
337
+ if (!laneEventMatches(laneNumber, event)) continue;
155
338
  const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
156
- if (payload.laneNumber != null && payload.laneNumber !== laneNumber) continue;
157
- if (event.laneId && event.laneId !== laneId) continue;
158
339
  return {
159
340
  heartbeatKind:
160
341
  typeof payload.heartbeatKind === "string" ? payload.heartbeatKind : null,
@@ -183,6 +364,9 @@ export function formatLaneHeartbeatDisplay({ workerPhase, heartbeatAgeSeconds })
183
364
  * @param {string[]} [params.currentWaveTaskIds]
184
365
  * @param {number} [params.now]
185
366
  * @param {object[]} [params.journalEvents]
367
+ * @param {object[]} [params.metricsLines]
368
+ * @param {string|null} [params.projectRoot]
369
+ * @param {string|null} [params.batchId]
186
370
  */
187
371
  export function buildLaneRows({
188
372
  lanes,
@@ -191,16 +375,48 @@ export function buildLaneRows({
191
375
  currentWaveTaskIds = [],
192
376
  journalTail = [],
193
377
  journalEvents = [],
378
+ metricsLines = [],
379
+ projectRoot = null,
380
+ batchId = null,
194
381
  now = Date.now(),
195
382
  }) {
383
+ const throughputByLane = deriveLanesThroughput({
384
+ lanes,
385
+ journalEvents,
386
+ metricsLines,
387
+ now,
388
+ });
389
+
196
390
  return (lanes ?? []).map((lane) => {
197
391
  const heartbeatMeta = resolveLaneHeartbeatMeta(lane.laneNumber, journalEvents);
198
392
  const heartbeatAgeSecondsValue = heartbeatAgeSeconds(lane.lastHeartbeatAt, now);
393
+ const activeTaskIds = computeActiveTaskIdsForLane({ lane, classifiedTasks, currentWaveTaskIds });
394
+ const activity = resolveLaneActivityPhase({
395
+ laneNumber: lane.laneNumber,
396
+ activeTaskIds,
397
+ classifiedTasks,
398
+ journalEvents,
399
+ });
400
+ const throughput =
401
+ throughputByLane.get(lane.laneNumber) ?? emptyLaneThroughputStats();
402
+ const recentEvents = buildLaneRecentEvents(lane.laneNumber, journalEvents);
403
+ const logDetail =
404
+ projectRoot && batchId
405
+ ? buildLaneLogTail(
406
+ projectRoot,
407
+ batchId,
408
+ lane.laneNumber,
409
+ activeTaskIds,
410
+ lane.taskIds ?? [],
411
+ )
412
+ : { logTail: [], workerLogRef: null };
199
413
  return {
200
414
  laneId: lane.laneId ?? `lane-${lane.laneNumber}`,
201
415
  laneNumber: lane.laneNumber,
202
416
  status: classifyLaneStatus({ lane, classifiedTasks, stallConfig, now }),
203
- activeTaskIds: computeActiveTaskIdsForLane({ lane, classifiedTasks, currentWaveTaskIds }),
417
+ activeTaskIds,
418
+ activityPhase: activity.activityPhase,
419
+ activityPhaseLabel: activity.activityPhaseLabel,
204
420
  taskIds: lane.taskIds ?? [],
205
421
  heartbeatAgeSeconds: heartbeatAgeSecondsValue,
206
422
  heartbeatKind: heartbeatMeta.heartbeatKind,
@@ -211,6 +427,10 @@ export function buildLaneRows({
211
427
  }),
212
428
  worktree: truncateWorktreePath(lane.worktreePath),
213
429
  laneAlert: resolveLaneAlert(lane.laneNumber, journalTail, now),
430
+ throughput,
431
+ recentEvents,
432
+ logTail: logDetail.logTail,
433
+ workerLogRef: logDetail.workerLogRef,
214
434
  };
215
435
  });
216
436
  }
@@ -254,6 +474,128 @@ export function formatJournalTailEntry(event) {
254
474
  };
255
475
  }
256
476
 
477
+ /**
478
+ * @param {number} laneNumber
479
+ * @param {object} event
480
+ */
481
+ function journalEventScopedToLane(laneNumber, event) {
482
+ const laneId = `lane-${laneNumber}`;
483
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
484
+ if (event.laneId) return event.laneId === laneId;
485
+ if (payload.laneNumber != null) return payload.laneNumber === laneNumber;
486
+ return false;
487
+ }
488
+
489
+ /**
490
+ * Last N journal events scoped to a physical lane.
491
+ *
492
+ * @param {number} laneNumber
493
+ * @param {object[]} journalEvents
494
+ * @param {number} [limit]
495
+ */
496
+ export function buildLaneRecentEvents(laneNumber, journalEvents, limit = LANE_RECENT_EVENTS_LIMIT) {
497
+ const matching = (journalEvents ?? []).filter(
498
+ (event) => journalEventScopedToLane(laneNumber, event) && laneEventMatches(laneNumber, event),
499
+ );
500
+ return readJournalTail(matching, limit).map(formatJournalTailEntry);
501
+ }
502
+
503
+ /**
504
+ * @param {string|null|undefined} filePath
505
+ * @param {number} [lineCount]
506
+ * @returns {string[]}
507
+ */
508
+ export function readLogFileTailLines(filePath, lineCount = LANE_LOG_TAIL_LINES) {
509
+ if (!filePath || !fs.existsSync(filePath)) return [];
510
+ const content = fs.readFileSync(filePath, "utf-8");
511
+ const lines = content.split("\n");
512
+ if (lines.at(-1) === "") lines.pop();
513
+ if (lines.length === 0) return [];
514
+ return lines.slice(-lineCount);
515
+ }
516
+
517
+ /**
518
+ * Prefer live worker log for active tasks, then terminal output log, then newest in lane dir.
519
+ *
520
+ * @param {string} projectRoot
521
+ * @param {string} batchId
522
+ * @param {number} laneNumber
523
+ * @param {string[]} activeTaskIds
524
+ * @param {string[]} taskIds
525
+ * @returns {{ path: string, ref: string } | null}
526
+ */
527
+ export function resolveLaneWorkerLog(projectRoot, batchId, laneNumber, activeTaskIds, taskIds) {
528
+ /** @type {string[]} */
529
+ const orderedTaskIds = [];
530
+ const seen = new Set();
531
+ for (const taskId of [...(activeTaskIds ?? []), ...(taskIds ?? [])]) {
532
+ if (!taskId || seen.has(taskId)) continue;
533
+ seen.add(taskId);
534
+ orderedTaskIds.push(String(taskId));
535
+ }
536
+
537
+ for (const taskId of orderedTaskIds) {
538
+ const livePath = workerLiveLogPath(projectRoot, batchId, laneNumber, taskId);
539
+ if (fs.existsSync(livePath)) {
540
+ return { path: livePath, ref: workerLiveLogRef(batchId, laneNumber, taskId) };
541
+ }
542
+ const outputPath = workerOutputLogPath(projectRoot, batchId, laneNumber, taskId);
543
+ if (fs.existsSync(outputPath)) {
544
+ return { path: outputPath, ref: workerOutputLogRef(batchId, laneNumber, taskId) };
545
+ }
546
+ }
547
+
548
+ const laneDir = path.join(
549
+ projectRoot,
550
+ ".spine",
551
+ "runtime",
552
+ batchId,
553
+ "lanes",
554
+ `lane-${laneNumber}`,
555
+ );
556
+ if (!fs.existsSync(laneDir)) return null;
557
+
558
+ /** @type {{ path: string, ref: string, mtime: number } | null} */
559
+ let newest = null;
560
+ for (const name of fs.readdirSync(laneDir)) {
561
+ const isLive = name.startsWith("worker-live-") && name.endsWith(".log");
562
+ const isOutput = name.startsWith("worker-output-") && name.endsWith(".log");
563
+ if (!isLive && !isOutput) continue;
564
+ const candidate = path.join(laneDir, name);
565
+ const mtime = fs.statSync(candidate).mtimeMs;
566
+ if (!newest || mtime >= newest.mtime) {
567
+ const taskId = name.replace(/^worker-(?:live|output)-/, "").replace(/\.log$/, "");
568
+ newest = {
569
+ path: candidate,
570
+ ref: isLive
571
+ ? workerLiveLogRef(batchId, laneNumber, taskId)
572
+ : workerOutputLogRef(batchId, laneNumber, taskId),
573
+ mtime,
574
+ };
575
+ }
576
+ }
577
+
578
+ return newest ? { path: newest.path, ref: newest.ref } : null;
579
+ }
580
+
581
+ /**
582
+ * @param {string} projectRoot
583
+ * @param {string} batchId
584
+ * @param {number} laneNumber
585
+ * @param {string[]} activeTaskIds
586
+ * @param {string[]} taskIds
587
+ */
588
+ export function buildLaneLogTail(projectRoot, batchId, laneNumber, activeTaskIds, taskIds) {
589
+ const resolved = resolveLaneWorkerLog(projectRoot, batchId, laneNumber, activeTaskIds, taskIds);
590
+ if (!resolved) {
591
+ return { logTail: [], workerLogRef: null };
592
+ }
593
+ return {
594
+ logTail: readLogFileTailLines(resolved.path, LANE_LOG_TAIL_LINES),
595
+ workerLogRef: resolved.ref,
596
+ };
597
+ }
598
+
257
599
  /**
258
600
  * @param {import("../batch/reconcile.mjs").NormalizedBatchState | null} batch
259
601
  */
@@ -382,6 +724,15 @@ export function buildDashboardSnapshot(projectRoot) {
382
724
  ? wavePlan[currentWaveIndex].map(String)
383
725
  : [];
384
726
 
727
+ const config = configResult.config ?? {};
728
+ let metricsLines = [];
729
+ if (reconciliation.batchId) {
730
+ const metricsPath = metricsFilePath(projectRoot, config);
731
+ metricsLines = filterMetricsLines(readMetricsLines(metricsPath), {
732
+ batchId: reconciliation.batchId,
733
+ });
734
+ }
735
+
385
736
  const lanes = buildLaneRows({
386
737
  lanes: batch?.lanes ?? [],
387
738
  classifiedTasks,
@@ -389,11 +740,38 @@ export function buildDashboardSnapshot(projectRoot) {
389
740
  currentWaveTaskIds,
390
741
  journalTail,
391
742
  journalEvents,
743
+ metricsLines,
744
+ projectRoot,
745
+ batchId: reconciliation.batchId,
392
746
  now,
393
747
  });
748
+ const laneThroughputSummary = summarizeLaneThroughput(
749
+ deriveLanesThroughput({
750
+ lanes: batch?.lanes ?? [],
751
+ journalEvents,
752
+ metricsLines,
753
+ tasks: batch?.tasks,
754
+ now,
755
+ }),
756
+ );
394
757
  const waves = buildWaveProgress(batch);
395
758
  const defaultView = buildDefaultViewStatus(reconciliation, gate);
396
759
 
760
+ const macroPhase = deriveMacroPhase({
761
+ diagnosis: reconciliation.diagnosis,
762
+ batchPhase: batch?.phase ?? reconciliation.phase,
763
+ currentWaveIndex,
764
+ mergeResults: Array.isArray(rawBatch.mergeResults) ? rawBatch.mergeResults : [],
765
+ gateRecord: gate,
766
+ postMergeLimbo: reconciliation.signals?.postMergeLimbo === true,
767
+ journalEvents,
768
+ });
769
+ const batchSummary = summarizeBatch(batch);
770
+ if (batchSummary) {
771
+ batchSummary.macroPhase = macroPhase;
772
+ batchSummary.macroPhaseLabel = macroPhaseLabel(macroPhase);
773
+ }
774
+
397
775
  return {
398
776
  generatedAt: new Date(now).toISOString(),
399
777
  defaultView,
@@ -405,8 +783,11 @@ export function buildDashboardSnapshot(projectRoot) {
405
783
  phase: reconciliation.phase,
406
784
  batchStatePath: reconciliation.batchStatePath,
407
785
  reconciliation,
408
- batch: summarizeBatch(batch),
786
+ batch: batchSummary,
787
+ macroPhase,
788
+ macroPhaseLabel: macroPhaseLabel(macroPhase),
409
789
  lanes,
790
+ laneThroughputSummary,
410
791
  gate,
411
792
  journalTail,
412
793
  waves,