pi-spine 2.2.0 → 2.3.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.
Files changed (56) hide show
  1. package/bin/spine-cli/verify.mjs +15 -46
  2. package/package.json +1 -1
  3. package/src/batch/attached-runner-promote.mjs +370 -0
  4. package/src/batch/attached-runner-reconcile.mjs +291 -0
  5. package/src/batch/attached-runner.mjs +24 -645
  6. package/src/batch/batch-guards.mjs +69 -0
  7. package/src/batch/contract-exec.mjs +483 -0
  8. package/src/batch/contract-parse.mjs +243 -0
  9. package/src/batch/contract-verify.mjs +32 -707
  10. package/src/batch/detached-diagnostics.mjs +255 -0
  11. package/src/batch/detached-run.mjs +326 -0
  12. package/src/batch/detached-start.mjs +18 -894
  13. package/src/batch/detached-wait.mjs +346 -0
  14. package/src/batch/diagnosis.mjs +35 -4
  15. package/src/batch/engine-lanes/orch-sync.mjs +126 -0
  16. package/src/batch/engine-lanes.mjs +69 -0
  17. package/src/batch/engine.mjs +8 -67
  18. package/src/batch/integrate-git.mjs +21 -0
  19. package/src/batch/integrate.mjs +5 -15
  20. package/src/batch/journal-rebuild-structural.mjs +352 -0
  21. package/src/batch/journal-rebuild.mjs +16 -348
  22. package/src/batch/lane-dirty-check-commit.mjs +361 -0
  23. package/src/batch/lane-dirty-check-git.mjs +298 -0
  24. package/src/batch/lane-dirty-check.mjs +31 -297
  25. package/src/batch/reconcile-batch.mjs +495 -0
  26. package/src/batch/reconcile-classify.mjs +433 -0
  27. package/src/batch/reconcile-diagnosis.mjs +459 -0
  28. package/src/batch/reconcile-light-cache.mjs +61 -0
  29. package/src/batch/reconcile-orphan.mjs +198 -0
  30. package/src/batch/reconcile.mjs +19 -1693
  31. package/src/batch/resume-multi-lanes.mjs +6 -148
  32. package/src/batch/resume-multi-queue.mjs +159 -0
  33. package/src/batch/resume-single-validate.mjs +25 -0
  34. package/src/batch/resume.mjs +3 -20
  35. package/src/batch/review-artifacts.mjs +419 -0
  36. package/src/batch/review-step-run.mjs +383 -0
  37. package/src/batch/review-step.mjs +451 -0
  38. package/src/batch/review.mjs +32 -1199
  39. package/src/batch/salvage-batch-list.mjs +291 -0
  40. package/src/batch/salvage-batch.mjs +10 -284
  41. package/src/batch/sequence-plan.mjs +234 -0
  42. package/src/batch/sequence-run.mjs +418 -0
  43. package/src/batch/sequence-wait.mjs +167 -0
  44. package/src/batch/sequence.mjs +22 -783
  45. package/src/batch/state-guards.mjs +284 -0
  46. package/src/batch/state-io.mjs +135 -0
  47. package/src/batch/state.mjs +27 -396
  48. package/src/batch/worker-heartbeat.mjs +382 -0
  49. package/src/batch/worker-host.mjs +56 -548
  50. package/src/batch/worker-spawn.mjs +326 -0
  51. package/src/batch/worktree.mjs +68 -0
  52. package/src/config/preflight/integrate-plan.mjs +6 -1
  53. package/src/config/preflight/loc-capstone.mjs +274 -0
  54. package/src/config/spine-preflight-lib.mjs +14 -0
  55. package/src/planner/index.mjs +14 -3
  56. package/src/process/terminate-tree.mjs +154 -0
@@ -0,0 +1,495 @@
1
+ // @ts-nocheck
2
+ /** Main reconcileBatch orchestration (SP-606 / #192). */
3
+
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { buildStalePathDoctorCheck } from "../doctor/stale-path.mjs";
7
+ import { PACKAGE_ROOT } from "../config/spine-init-constants.mjs";
8
+ import { loadGateRecord } from "./gate-evidence-read.mjs";
9
+ import { deriveMacroPhase, macroPhaseLabel } from "./macro-phase.mjs";
10
+ import {
11
+ buildDiagnosisOutput,
12
+ inferMergeGitignoredFailure,
13
+ isGateReadyHeadlineContext,
14
+ } from "./diagnosis.mjs";
15
+ import {
16
+ classifyTasks,
17
+ inspectGitState,
18
+ inspectHumanBaseSync,
19
+ resolveTasksRoot,
20
+ syncPersistedClassifications,
21
+ } from "./reconcile-classify.mjs";
22
+ import { findLatestReviewHonorSignal } from "./review.mjs";
23
+ import { summarizeMergeFailures } from "./diagnosis-merge-failure.mjs";
24
+ import { inferWorkerDoneMissingFailure } from "./diagnosis-worker-done-missing.mjs";
25
+ import { inferEngineOrphanCause } from "./diagnosis-parent-exit.mjs";
26
+ import { findStubMarkedSucceededTask } from "./diagnosis-stub.mjs";
27
+ import { detectOrphanRunning, journalEventsSinceResume } from "./orphan-detect.mjs";
28
+ import { computePendingTasks } from "./resume-multi.mjs";
29
+ import { computeStatusProgress } from "./status-json.mjs";
30
+ import {
31
+ detectBatchStateDrift,
32
+ rebuildBatchStateFromJournal,
33
+ reconcileBatchStateDrift,
34
+ } from "./journal-rebuild.mjs";
35
+ import {
36
+ extractJournalDiagnosisHints,
37
+ findPlanReviewNestedSpawnBlockedFailure,
38
+ journalPath,
39
+ readJournalEvents,
40
+ } from "./journal.mjs";
41
+ import { findLatestSalvageInspection } from "./salvage.mjs";
42
+ import { isProcessAlive } from "../process/liveness.mjs";
43
+ import {
44
+ loadBatchStateFile,
45
+ parseBatchState,
46
+ readBaseBranchHeadAtStart,
47
+ } from "./batch-state-io.mjs";
48
+ import { readBatchEnginePid } from "./state.mjs";
49
+ import {
50
+ deriveDiagnosis,
51
+ enrichLaunchFailureFromWorkerOutput,
52
+ enrichWorkerDoneMissingContext,
53
+ extractGitignoredPathsFromJournal,
54
+ hasGhostRunningCluster,
55
+ laneTaskBranchForDiagnosis,
56
+ } from "./reconcile-diagnosis.mjs";
57
+ import {
58
+ HUMAN_SYNC_OVERRIDE_DIAGNOSES,
59
+ _lightReconcileCache,
60
+ clearLightReconcileCache,
61
+ lightReconcileCacheMatches,
62
+ updateLightReconcileCache,
63
+ } from "./reconcile-light-cache.mjs";
64
+
65
+ /**
66
+ * @param {object} ctx
67
+ * @param {string} ctx.projectRoot
68
+ * @param {object|null} [ctx.batchState]
69
+ * @param {string|null} [ctx.batchStatePath]
70
+ * @param {boolean} [ctx.verbose]
71
+ * @param {boolean} [ctx.light] Skip git branch scans when batch phase unchanged since last full reconcile.
72
+ * @param {boolean} [ctx._lightRetry] Internal — full reconcile after light diagnosis transition.
73
+ */
74
+ export function reconcileBatch(ctx, _lightRetry = false) {
75
+ const { projectRoot } = ctx;
76
+ const loaded = ctx.batchState
77
+ ? {
78
+ path: ctx.batchStatePath ?? null,
79
+ raw: ctx.batchState,
80
+ parseError: null,
81
+ }
82
+ : loadBatchStateFile(projectRoot, ctx.batchStatePath ?? null);
83
+
84
+ if (!loaded.path && !loaded.raw) {
85
+ clearLightReconcileCache();
86
+ return {
87
+ diagnosis: null,
88
+ headline: "No active batch — ready to plan or start",
89
+ suggestedCommand: "spine preflight",
90
+ alternatives: ["spine plan all"],
91
+ batchId: null,
92
+ batchStatePath: null,
93
+ phase: null,
94
+ macroPhase: "idle",
95
+ macroPhaseLabel: macroPhaseLabel("idle"),
96
+ signals: { idle: true, macroPhase: "idle" },
97
+ };
98
+ }
99
+
100
+ if (loaded.parseError) {
101
+ return {
102
+ diagnosis: "failed",
103
+ headline: `Cannot parse batch state: ${loaded.parseError}`,
104
+ suggestedCommand: "spine status --diagnose",
105
+ alternatives: ["spine doctor"],
106
+ batchId: null,
107
+ batchStatePath: loaded.path,
108
+ phase: null,
109
+ macroPhase: "failed",
110
+ macroPhaseLabel: macroPhaseLabel("failed"),
111
+ signals: { parseError: loaded.parseError, macroPhase: "failed" },
112
+ };
113
+ }
114
+
115
+ const batch = parseBatchState(loaded.raw ?? ctx.batchState, loaded.path ?? ctx.batchStatePath ?? "");
116
+ if (!batch) {
117
+ return {
118
+ diagnosis: "failed",
119
+ headline: "Batch state is unreadable",
120
+ suggestedCommand: "spine status --diagnose",
121
+ batchId: null,
122
+ batchStatePath: loaded.path,
123
+ phase: null,
124
+ macroPhase: "failed",
125
+ macroPhaseLabel: macroPhaseLabel("failed"),
126
+ signals: { unreadable: true, macroPhase: "failed" },
127
+ };
128
+ }
129
+
130
+ const tasksRoot = resolveTasksRoot(projectRoot);
131
+ let classifiedTasks = classifyTasks(batch, tasksRoot, projectRoot);
132
+ const useLightGit =
133
+ ctx.light === true &&
134
+ !_lightRetry &&
135
+ lightReconcileCacheMatches(projectRoot, batch.batchId, batch.phase);
136
+ const git = useLightGit
137
+ ? /** @type {ReturnType<typeof inspectGitState>} */ (_lightReconcileCache.git)
138
+ : inspectGitState({
139
+ projectRoot,
140
+ batchId: batch.batchId,
141
+ baseBranch: batch.baseBranch,
142
+ orchBranch: batch.orchBranch,
143
+ });
144
+
145
+ const hasRunningTasks = classifiedTasks.some((task) => task.classification === "running");
146
+ const hasPendingTasks = classifiedTasks.some((task) => task.classification === "pending");
147
+ const pendingWithFailedSegment = batch.segments.some(
148
+ (segment) => segment.classification === "terminal-failure",
149
+ );
150
+ const driftTask = batch.tasks.find((task) => {
151
+ if (task.classification !== "pending") return false;
152
+ return batch.segments.some(
153
+ (segment) => segment.taskId === task.taskId && segment.classification === "terminal-failure",
154
+ );
155
+ });
156
+ const hasSegmentDrift = pendingWithFailedSegment || Boolean(driftTask);
157
+ const hasFailedTasks =
158
+ classifiedTasks.some((task) => task.classification === "terminal-failure") ||
159
+ hasSegmentDrift ||
160
+ batch.failedTasks > 0;
161
+ const allTasksTerminalSuccess =
162
+ classifiedTasks.length > 0 &&
163
+ classifiedTasks.every((task) => task.classification === "terminal-success");
164
+ const failedTask = classifiedTasks.find((task) => task.classification === "terminal-failure");
165
+
166
+ const signals = {
167
+ phase: batch.phase,
168
+ endedAt: batch.endedAt,
169
+ failedTasks: hasFailedTasks ? Math.max(batch.failedTasks, 1) : batch.failedTasks,
170
+ allTasksTerminalSuccess,
171
+ hasRunningTasks,
172
+ hasPendingTasks,
173
+ hasFailedTasks,
174
+ hasSegmentDrift,
175
+ failedTaskId: failedTask?.taskId ?? driftTask?.taskId ?? null,
176
+ mergeResultsEmpty: batch.mergeResults.length === 0,
177
+ git,
178
+ tasks: classifiedTasks,
179
+ tasksRoot,
180
+ segments: batch.segments,
181
+ lanes: batch.lanes,
182
+ raw: batch.raw,
183
+ };
184
+
185
+ const journalFile = journalPath(projectRoot, batch.batchId);
186
+ /** @type {object[]} */
187
+ let journalEvents = [];
188
+ if (fs.existsSync(journalFile)) {
189
+ journalEvents = readJournalEvents(projectRoot, batch.batchId);
190
+ signals.journalHints = extractJournalDiagnosisHints(journalEvents);
191
+ signals.journalEvents = journalEvents;
192
+ }
193
+
194
+ const engineSessionJournalEvents = journalEventsSinceResume(journalEvents, batch.raw);
195
+
196
+ if (journalEvents.length > 0 && batch.raw) {
197
+ let rebuilt = rebuildBatchStateFromJournal(batch.raw, journalEvents);
198
+ let drift = detectBatchStateDrift(batch.raw, rebuilt, journalEvents, classifiedTasks);
199
+ const healed = reconcileBatchStateDrift({
200
+ projectRoot,
201
+ state: batch.raw,
202
+ classifiedTasks,
203
+ journalEvents,
204
+ drift,
205
+ });
206
+ if (healed.reconciled) {
207
+ journalEvents = readJournalEvents(projectRoot, batch.batchId);
208
+ const refreshed = parseBatchState(batch.raw, loaded.path ?? ctx.batchStatePath ?? "");
209
+ if (refreshed) {
210
+ batch.tasks = refreshed.tasks;
211
+ batch.segments = refreshed.segments;
212
+ batch.succeededTasks = refreshed.succeededTasks;
213
+ batch.failedTasks = refreshed.failedTasks;
214
+ batch.lanes = refreshed.lanes;
215
+ }
216
+ classifiedTasks = classifyTasks(batch, tasksRoot, projectRoot);
217
+ rebuilt = rebuildBatchStateFromJournal(batch.raw, journalEvents);
218
+ drift = detectBatchStateDrift(batch.raw, rebuilt, journalEvents, classifiedTasks);
219
+ }
220
+ signals.stateDrift = drift;
221
+ signals.rebuiltFromJournal = rebuilt;
222
+ if (healed.reconciled) {
223
+ signals.journalEvents = journalEvents;
224
+ signals.tasks = classifiedTasks;
225
+ signals.hasRunningTasks = classifiedTasks.some((task) => task.classification === "running");
226
+ signals.hasPendingTasks = classifiedTasks.some((task) => task.classification === "pending");
227
+ signals.allTasksTerminalSuccess =
228
+ classifiedTasks.length > 0 &&
229
+ classifiedTasks.every((task) => task.classification === "terminal-success");
230
+ const healedFailedTask = classifiedTasks.find(
231
+ (task) => task.classification === "terminal-failure",
232
+ );
233
+ signals.failedTaskId = healedFailedTask?.taskId ?? signals.failedTaskId;
234
+ }
235
+ }
236
+
237
+ if (batch.raw) {
238
+ syncPersistedClassifications({ projectRoot, state: batch.raw });
239
+ }
240
+
241
+ signals.orphanRunning = detectOrphanRunning({
242
+ phase: batch.phase,
243
+ hasRunningTasks: signals.hasRunningTasks,
244
+ tasks: classifiedTasks,
245
+ lanes: batch.lanes,
246
+ raw: batch.raw,
247
+ journalEvents: engineSessionJournalEvents,
248
+ });
249
+
250
+ const pendingTaskCount = computePendingTasks(batch.raw ?? {}).length;
251
+ signals.pendingTaskCount = pendingTaskCount;
252
+
253
+ const derived = deriveDiagnosis(signals);
254
+ let { diagnosis, failedTaskId, exitReason } = derived;
255
+ const launchFailureKind = derived.launchFailureKind;
256
+ const stubSucceededTaskId = findStubMarkedSucceededTask(tasksRoot, classifiedTasks);
257
+ if (
258
+ stubSucceededTaskId &&
259
+ (diagnosis === "completed" ||
260
+ diagnosis === "needs_integrate" ||
261
+ diagnosis === "limbo_stale" ||
262
+ diagnosis === "completed_manual")
263
+ ) {
264
+ diagnosis = "needs_retry";
265
+ failedTaskId = stubSucceededTaskId;
266
+ exitReason = "stub";
267
+ }
268
+
269
+ const humanBaseSync = inspectHumanBaseSync({
270
+ projectRoot,
271
+ baseBranch: batch.baseBranch,
272
+ baseBranchHeadAtStart: readBaseBranchHeadAtStart(batch.raw),
273
+ orchBranch: batch.orchBranch,
274
+ git,
275
+ journalEvents,
276
+ });
277
+ if (humanBaseSync && HUMAN_SYNC_OVERRIDE_DIAGNOSES.has(diagnosis)) {
278
+ diagnosis = humanBaseSync.diagnosis;
279
+ }
280
+
281
+ const doneMissingHint =
282
+ diagnosis === "worker_done_missing"
283
+ ? inferWorkerDoneMissingFailure({
284
+ journalEvents,
285
+ failedTaskId,
286
+ })
287
+ : null;
288
+ const doneMissingContext =
289
+ diagnosis === "worker_done_missing"
290
+ ? enrichWorkerDoneMissingContext(
291
+ projectRoot,
292
+ batch.batchId,
293
+ failedTaskId,
294
+ classifiedTasks,
295
+ doneMissingHint,
296
+ )
297
+ : null;
298
+ const resolvedLaunchFailureKind =
299
+ diagnosis === "worker_orphaned"
300
+ ? enrichLaunchFailureFromWorkerOutput(
301
+ projectRoot,
302
+ batch.batchId,
303
+ failedTaskId,
304
+ classifiedTasks,
305
+ launchFailureKind,
306
+ )
307
+ : launchFailureKind;
308
+ const ghostRunningCluster =
309
+ diagnosis === "worker_orphaned" && hasGhostRunningCluster(classifiedTasks, failedTaskId);
310
+ const salvagePayload = findLatestSalvageInspection(journalEvents, failedTaskId);
311
+ const salvageChangedFileCount = Number(salvagePayload?.changedFileCount ?? 0) || 0;
312
+ const salvageRetryCommand =
313
+ typeof salvagePayload?.retryCommand === "string"
314
+ ? salvagePayload.retryCommand
315
+ : signals.orphanRunning?.taskId
316
+ ? `spine batch retry ${signals.orphanRunning.taskId}`
317
+ : null;
318
+
319
+ const gateRecord = batch.batchId ? loadGateRecord(projectRoot, batch.batchId) : null;
320
+ const integrateGateOpen = signals.postMergeLimbo === true && Boolean(gateRecord);
321
+
322
+ const macroPhase = deriveMacroPhase({
323
+ diagnosis,
324
+ batchPhase: batch.phase,
325
+ gateRecord,
326
+ postMergeLimbo: signals.postMergeLimbo === true,
327
+ journalEvents,
328
+ mergeResults: batch.mergeResults,
329
+ hasActiveWorkerTasks: hasRunningTasks || hasPendingTasks,
330
+ allTasksTerminalSuccess: signals.allTasksTerminalSuccess,
331
+ mergeResultsEmpty: signals.mergeResultsEmpty,
332
+ });
333
+ const resolvedMacroPhaseLabel = macroPhaseLabel(macroPhase);
334
+ if (ctx.verbose) {
335
+ signals.macroPhase = macroPhase;
336
+ signals.reconcileMode = useLightGit ? "light" : "full";
337
+ }
338
+
339
+ const stalePathCheck = buildStalePathDoctorCheck({
340
+ packageRoot: PACKAGE_ROOT,
341
+ runningSpinePath: path.join(PACKAGE_ROOT, "bin", "spine.mjs"),
342
+ });
343
+ const stalePathSpine = stalePathCheck.warning === true;
344
+ const planReviewNestedSpawnBlocked =
345
+ diagnosis === "worker_orphaned" &&
346
+ findPlanReviewNestedSpawnBlockedFailure(journalEvents, failedTaskId);
347
+
348
+ const mergeGitignoredFailureInferred = inferMergeGitignoredFailure({
349
+ exitReason,
350
+ failureClass: batch.raw?.mergeResults?.find((entry) => entry?.failureClass)?.failureClass ?? null,
351
+ lastError: batch.raw?.lastError ?? null,
352
+ journalEvents,
353
+ });
354
+ const mergeFailureSummary = summarizeMergeFailures(
355
+ batch.mergeResults,
356
+ batch.raw?.lastError ?? null,
357
+ );
358
+ signals.mergeFailed = mergeFailureSummary.mergeFailed;
359
+ signals.failedMerges = mergeFailureSummary.failedMerges;
360
+ signals.failedWaveIndex = mergeFailureSummary.failedWaveIndex;
361
+ signals.failedLane = mergeFailureSummary.failedLane;
362
+ signals.lastError = mergeFailureSummary.lastError;
363
+ // Keep historical gitignored merge evidence in signals; demote for headline once gate-ready (#195).
364
+ signals.mergeGitignoredFailure = mergeGitignoredFailureInferred;
365
+ const gateReadyHeadline = isGateReadyHeadlineContext(diagnosis, {
366
+ allTasksTerminalSuccess: signals.allTasksTerminalSuccess === true,
367
+ integrateGateOpen,
368
+ });
369
+ const mergeGitignoredFailure = gateReadyHeadline ? false : mergeGitignoredFailureInferred;
370
+ const mergeFailedForHeadline = gateReadyHeadline ? false : mergeFailureSummary.mergeFailed;
371
+ if (ctx.verbose && gateReadyHeadline && mergeGitignoredFailureInferred) {
372
+ signals.mergeGitignoredFailureSuperseded = true;
373
+ }
374
+ const gitignoredPaths = extractGitignoredPathsFromJournal(journalEvents, failedTaskId);
375
+ const taskBranch =
376
+ failedTaskId != null
377
+ ? laneTaskBranchForDiagnosis(batch.raw, batch.batchId, failedTaskId)
378
+ : null;
379
+ const driftTaskStatus =
380
+ failedTaskId != null
381
+ ? String(
382
+ (batch.raw?.tasks ?? []).find((entry) => entry?.taskId === failedTaskId)?.status ?? "",
383
+ )
384
+ : null;
385
+
386
+ const activeReviewTaskId =
387
+ failedTaskId ??
388
+ classifiedTasks.find((task) => task.classification === "running")?.taskId ??
389
+ null;
390
+ const reviewHonorSignal = findLatestReviewHonorSignal(journalEvents, activeReviewTaskId);
391
+ if (ctx.verbose) {
392
+ signals.reviewHonor = reviewHonorSignal;
393
+ }
394
+
395
+ const enginePid = readBatchEnginePid(batch.raw);
396
+ const staleEnginePid =
397
+ enginePid != null && !isProcessAlive(enginePid);
398
+ const engineOrphanCause =
399
+ diagnosis === "engine_orphaned"
400
+ ? inferEngineOrphanCause({ journalEvents, staleEnginePid })
401
+ : null;
402
+
403
+ const output = buildDiagnosisOutput(diagnosis, {
404
+ batchId: batch.batchId,
405
+ phase: batch.phase,
406
+ failedTasks: signals.failedTasks,
407
+ failedTaskId,
408
+ driftTaskStatus,
409
+ exitReason,
410
+ launchFailureKind: resolvedLaunchFailureKind,
411
+ gitMerged: git.orchMergedToBase,
412
+ pendingTaskCount,
413
+ salvageChangedFileCount,
414
+ salvageRetryCommand,
415
+ ghostRunningCluster,
416
+ postMergeLimbo: signals.postMergeLimbo === true,
417
+ integrateGateOpen,
418
+ stalePathSpine,
419
+ planReviewNestedSpawnBlocked,
420
+ mergeGitignoredFailure,
421
+ mergeFailed: mergeFailedForHeadline,
422
+ failedWaveIndex: mergeFailureSummary.failedWaveIndex,
423
+ failedLane: mergeFailureSummary.failedLane,
424
+ lastError: mergeFailureSummary.lastError,
425
+ succeededTasks: batch.succeededTasks,
426
+ totalTasks: batch.totalTasks,
427
+ taskBranch,
428
+ gitignoredPaths,
429
+ hasRunningTasks,
430
+ hasPendingTasks,
431
+ allTasksTerminalSuccess: signals.allTasksTerminalSuccess,
432
+ tasksRoot,
433
+ macroPhase,
434
+ reviewHonorSignal,
435
+ ...(doneMissingContext ?? {}),
436
+ engineOrphanCause,
437
+ staleEnginePid,
438
+ humanBaseSync,
439
+ overlapPaths: humanBaseSync?.overlapPaths ?? [],
440
+ });
441
+
442
+ if (humanBaseSync && (diagnosis === "human_base_diverged" || diagnosis === "integrate_isolated_ok")) {
443
+ output.headline = humanBaseSync.headline;
444
+ }
445
+
446
+ if (diagnosis === "git_unavailable") {
447
+ output.headline = `Batch ${batch.batchId} — git inspection failed: ${git.gitInspectionError}`;
448
+ output.suggestedCommand = "spine doctor";
449
+ output.alternatives = ["spine status --diagnose"];
450
+ }
451
+
452
+ const progress = computeStatusProgress({
453
+ batchRaw: batch.raw,
454
+ succeededTasks: batch.succeededTasks,
455
+ totalTasks: batch.totalTasks,
456
+ pendingTasks: pendingTaskCount,
457
+ });
458
+
459
+ if (
460
+ ctx.light === true &&
461
+ useLightGit &&
462
+ !_lightRetry &&
463
+ _lightReconcileCache.diagnosis != null &&
464
+ _lightReconcileCache.diagnosis !== diagnosis
465
+ ) {
466
+ return reconcileBatch({ ...ctx, light: false }, true);
467
+ }
468
+
469
+ if (!useLightGit) {
470
+ updateLightReconcileCache(projectRoot, batch.batchId, batch.phase, git, diagnosis);
471
+ } else {
472
+ _lightReconcileCache.diagnosis = diagnosis;
473
+ }
474
+
475
+ return {
476
+ ...output,
477
+ batchId: batch.batchId,
478
+ batchStatePath: loaded.path ?? ctx.batchStatePath ?? null,
479
+ phase: batch.phase,
480
+ macroPhase,
481
+ macroPhaseLabel: resolvedMacroPhaseLabel,
482
+ failedTasks: signals.failedTasks,
483
+ succeededTasks: batch.succeededTasks,
484
+ totalTasks: batch.totalTasks,
485
+ pendingTasks: progress?.pendingTasks,
486
+ currentWaveIndex: progress?.currentWaveIndex,
487
+ waveCount: progress?.waveCount,
488
+ mergeFailed: mergeFailureSummary.mergeFailed,
489
+ failedMerges: mergeFailureSummary.failedMerges,
490
+ failedWaveIndex: mergeFailureSummary.failedWaveIndex,
491
+ failedLane: mergeFailureSummary.failedLane,
492
+ lastError: mergeFailureSummary.lastError,
493
+ signals: ctx.verbose ? signals : undefined,
494
+ };
495
+ }