pi-spine 1.2.0 → 1.4.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 (76) hide show
  1. package/README.md +4 -4
  2. package/bin/spine-cli/verify.mjs +6 -0
  3. package/bin/spine-deps.mjs +0 -2
  4. package/bin/spine-plan.mjs +49 -1
  5. package/bin/spine-rules.mjs +0 -2
  6. package/bin/spine-settings.mjs +0 -2
  7. package/bin/spine-worker-runner.mjs +136 -4
  8. package/bin/spine.mjs +2 -5
  9. package/package.json +2 -2
  10. package/skills/create-spine-tasks/SKILL.md +7 -2
  11. package/skills/create-spine-tasks/references/contract-template.md +95 -3
  12. package/src/batch/attached-engine-handoff.mjs +0 -1
  13. package/src/batch/attached-runner.mjs +81 -5
  14. package/src/batch/contract-stub-delivery.mjs +110 -0
  15. package/src/batch/contract-task-start.mjs +204 -0
  16. package/src/batch/contract-verify.mjs +160 -16
  17. package/src/batch/detached-start.mjs +72 -2
  18. package/src/batch/diagnosis-launch-failure.mjs +114 -0
  19. package/src/batch/diagnosis-primary-failure.mjs +89 -0
  20. package/src/batch/diagnosis-retry-limbo.mjs +1 -1
  21. package/src/batch/diagnosis-tail-state.mjs +57 -0
  22. package/src/batch/diagnosis.mjs +22 -114
  23. package/src/batch/engine-lanes/commit.mjs +145 -0
  24. package/src/batch/engine-lanes/merge.mjs +1 -2
  25. package/src/batch/engine-lanes/review.mjs +124 -121
  26. package/src/batch/engine-lanes.mjs +21 -81
  27. package/src/batch/engine.mjs +46 -1
  28. package/src/batch/evidence.mjs +1 -2
  29. package/src/batch/git-exec.mjs +5 -2
  30. package/src/batch/heartbeat.mjs +2 -2
  31. package/src/batch/integrate-assert.mjs +69 -0
  32. package/src/batch/integrate-worktree.mjs +354 -0
  33. package/src/batch/integrate.mjs +195 -102
  34. package/src/batch/journal-rebuild.mjs +158 -3
  35. package/src/batch/journal.mjs +63 -0
  36. package/src/batch/lane-commit.mjs +6 -5
  37. package/src/batch/lane-dirty-check.mjs +513 -0
  38. package/src/batch/limbo-detect.mjs +34 -0
  39. package/src/batch/macro-phase.mjs +76 -0
  40. package/src/batch/metrics.mjs +2 -0
  41. package/src/batch/pause.mjs +18 -7
  42. package/src/batch/post-merge-limbo.mjs +3 -28
  43. package/src/batch/reconcile.mjs +79 -10
  44. package/src/batch/resume-common.mjs +27 -0
  45. package/src/batch/resume-multi-lanes.mjs +11 -0
  46. package/src/batch/resume-multi.mjs +3 -1
  47. package/src/batch/resume.mjs +8 -4
  48. package/src/batch/retry.mjs +41 -10
  49. package/src/batch/review-spawn.mjs +1 -1
  50. package/src/batch/review.mjs +0 -4
  51. package/src/batch/rules-manifest-drift.mjs +43 -2
  52. package/src/batch/sequence-state.mjs +290 -0
  53. package/src/batch/sequence.mjs +113 -51
  54. package/src/batch/state.mjs +16 -0
  55. package/src/batch/worker-host.mjs +14 -5
  56. package/src/cli/deps.mjs +0 -2
  57. package/src/cli/sequence.mjs +14 -1
  58. package/src/cli/settings-set.mjs +33 -3
  59. package/src/config/contract.mjs +10 -0
  60. package/src/config/model-id.mjs +103 -0
  61. package/src/config/spine-init-constants.mjs +1 -0
  62. package/src/config/spine-preflight-lib.mjs +23 -1
  63. package/src/dashboard/public/dashboard.css +8 -0
  64. package/src/dashboard/public/dashboard.js +36 -9
  65. package/src/dashboard/running-tail-state.mjs +31 -0
  66. package/src/dashboard/server.mjs +4 -0
  67. package/src/dashboard/snapshot.mjs +260 -29
  68. package/src/dashboard/view.mjs +112 -2
  69. package/src/doctor/agent-models.mjs +53 -0
  70. package/src/doctor/batch-size-guidance.mjs +30 -2
  71. package/src/doctor/pi-extension-conflict.mjs +169 -0
  72. package/src/doctor/run-doctor-checks.mjs +6 -0
  73. package/src/planner/scope.mjs +5 -1
  74. package/src/tasks/packet/parse-prompt.mjs +31 -1
  75. package/src/tasks/packet/validate-contract.mjs +108 -0
  76. package/src/tasks/packet/validate-prompt.mjs +0 -1
@@ -13,7 +13,7 @@ import { validateResumeBatch } from "./resume.mjs";
13
13
  import { assessRunningPhaseResumeEligibility } from "./resume-multi-validate.mjs";
14
14
  import { readLastTaskFailedEvent } from "./journal.mjs";
15
15
  import { prepareOrphanResumeHandoff } from "./resume-engine.mjs";
16
- import { finalizeResumePostMergeLimbo } from "./attached-runner.mjs";
16
+ import { enforceAttachedEngineSingleOwner, finalizeResumePostMergeLimbo } from "./attached-runner.mjs";
17
17
  import {
18
18
  ACTIVE_PHASES,
19
19
  loadSpineBatchState,
@@ -87,6 +87,37 @@ function readLogTailLines(filePath, lineCount = FAILURE_LOG_TAIL_LINES) {
87
87
  return lines.slice(-lineCount).join("\n");
88
88
  }
89
89
 
90
+ const DETACHED_ENGINE_LOG_HEADER_RE = /^--- detached batch engine /;
91
+
92
+ /**
93
+ * Read tail of detached engine log, scoped to the current (last) batch session.
94
+ * The append-only log contains headers like `--- detached batch engine <ISO> argv=... ---`
95
+ * separating sessions. Without filtering, stale entries from previous batches are shown.
96
+ *
97
+ * @param {string} filePath
98
+ * @param {number} [lineCount]
99
+ * @returns {string|null}
100
+ */
101
+ export function readCurrentBatchLogTail(filePath, lineCount = FAILURE_LOG_TAIL_LINES) {
102
+ if (!fs.existsSync(filePath)) return null;
103
+ const content = fs.readFileSync(filePath, "utf-8");
104
+ const lines = content.split("\n");
105
+ if (lines.at(-1) === "") lines.pop();
106
+ if (lines.length === 0) return null;
107
+
108
+ let lastHeaderIdx = -1;
109
+ for (let i = lines.length - 1; i >= 0; i--) {
110
+ if (DETACHED_ENGINE_LOG_HEADER_RE.test(lines[i])) {
111
+ lastHeaderIdx = i;
112
+ break;
113
+ }
114
+ }
115
+
116
+ const sessionLines = lastHeaderIdx >= 0 ? lines.slice(lastHeaderIdx) : lines;
117
+ if (sessionLines.length === 0) return null;
118
+ return sessionLines.slice(-lineCount).join("\n");
119
+ }
120
+
90
121
  /**
91
122
  * @param {string} projectRoot
92
123
  * @param {string} batchId
@@ -170,7 +201,7 @@ export function collectDetachedFailureDiagnostics({ projectRoot, batchId, taskId
170
201
  ? logPath
171
202
  : path.join(projectRoot, logPath)
172
203
  : detachedEngineLogPath(projectRoot);
173
- const engineTail = readLogTailLines(engineLogPath);
204
+ const engineTail = readCurrentBatchLogTail(engineLogPath);
174
205
  if (engineTail) {
175
206
  diagnostics.engineLogPath = path.isAbsolute(logPath ?? "")
176
207
  ? logPath
@@ -671,6 +702,25 @@ export async function startBatchDetached({
671
702
 
672
703
  const before = loadSpineBatchState(projectRoot);
673
704
  const previousBatchId = before.raw?.batchId ?? null;
705
+ const engineLock = enforceAttachedEngineSingleOwner({ projectRoot, force: false, operation: "start" });
706
+ if (!engineLock.ok) {
707
+ const payload = {
708
+ ok: false,
709
+ detached: true,
710
+ operation: "start",
711
+ batchId: engineLock.batchId,
712
+ error: engineLock.error,
713
+ output: engineLock.output,
714
+ enginePid: engineLock.enginePid,
715
+ suggestedCommand: "spine batch resume --attached --force",
716
+ };
717
+ return {
718
+ ok: false,
719
+ exitCode: engineLock.exitCode ?? 1,
720
+ output: formatDetachedEngineOutput(payload, json),
721
+ result: payload,
722
+ };
723
+ }
674
724
  const argv = buildAttachedBatchStartArgv({
675
725
  scope,
676
726
  skipPreflight: true,
@@ -747,6 +797,26 @@ export async function resumeBatchDetached({
747
797
  waitTerminal = false,
748
798
  json = false,
749
799
  }) {
800
+ const engineLock = enforceAttachedEngineSingleOwner({ projectRoot, force, operation: "resume" });
801
+ if (!engineLock.ok) {
802
+ const payload = {
803
+ ok: false,
804
+ detached: true,
805
+ operation: "resume",
806
+ batchId: engineLock.batchId,
807
+ error: engineLock.error,
808
+ output: engineLock.output,
809
+ enginePid: engineLock.enginePid,
810
+ suggestedCommand: "spine batch resume --attached --force",
811
+ };
812
+ return {
813
+ ok: false,
814
+ exitCode: engineLock.exitCode ?? 1,
815
+ output: formatDetachedEngineOutput(payload, json),
816
+ result: payload,
817
+ };
818
+ }
819
+
750
820
  const resumeCheck = validateResumeBatch({ projectRoot, force });
751
821
  if (!resumeCheck.ok) {
752
822
  const payload = {
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Worker launch failure inference for diagnosis headlines (SP-105, SP-421).
3
+ */
4
+ import { isPrimaryTaskFailureExitReason } from "./diagnosis-primary-failure.mjs";
5
+
6
+ /**
7
+ * @param {string} haystack
8
+ * @param {object} [hints]
9
+ * @param {boolean} [hints.launchingPhase]
10
+ * @returns {string|null}
11
+ */
12
+ function classifyLaunchFailureHaystack(haystack, hints = {}) {
13
+ const normalized = haystack.toLowerCase();
14
+
15
+ if (
16
+ normalized.includes("dirtyworktree") ||
17
+ normalized.includes("gitignoreddirtyworktree") ||
18
+ normalized.includes("lane_commit_failed")
19
+ ) {
20
+ return null;
21
+ }
22
+
23
+ if (hints.launchingPhase) {
24
+ if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
25
+ return "pi_spine_root";
26
+ }
27
+ return "launch_failed";
28
+ }
29
+
30
+ if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
31
+ return "pi_spine_root";
32
+ }
33
+
34
+ if (
35
+ normalized.includes("not a git repository") ||
36
+ normalized.includes("worktree") ||
37
+ normalized.includes("worktreeunhealthy")
38
+ ) {
39
+ return "worktree_unhealthy";
40
+ }
41
+
42
+ return null;
43
+ }
44
+
45
+ /**
46
+ * @param {object|null} failedEvent
47
+ * @param {string|null} exitReason
48
+ * @returns {string|null}
49
+ */
50
+ function classifyLaunchFailureFromEvent(failedEvent, exitReason) {
51
+ const payload = failedEvent?.payload && typeof failedEvent.payload === "object" ? failedEvent.payload : {};
52
+ const haystack = [
53
+ exitReason,
54
+ payload.classification,
55
+ payload.output,
56
+ payload.exitReason,
57
+ ].filter(Boolean).join("\n");
58
+
59
+ return classifyLaunchFailureHaystack(haystack, {
60
+ launchingPhase:
61
+ payload.workerPhase === "launching" || payload.classification === "launch_failed",
62
+ });
63
+ }
64
+
65
+ /**
66
+ * @param {string|null|undefined} outputText
67
+ * @returns {string|null}
68
+ */
69
+ export function inferLaunchFailureFromWorkerOutputTail(outputText) {
70
+ if (!outputText || !String(outputText).trim()) return null;
71
+ return classifyLaunchFailureHaystack(String(outputText));
72
+ }
73
+
74
+ /**
75
+ * @param {object} ctx
76
+ * @param {string|null} [ctx.exitReason]
77
+ * @param {object[]} [ctx.journalEvents]
78
+ * @param {string|null} [ctx.failedTaskId]
79
+ * @returns {string|null}
80
+ */
81
+ export function inferLaunchFailureKind(ctx = {}) {
82
+ const { exitReason, journalEvents, failedTaskId } = ctx;
83
+ if (isPrimaryTaskFailureExitReason(exitReason)) {
84
+ return null;
85
+ }
86
+ if (exitReason === "launch_failed" || exitReason === "worker_launch_failed") {
87
+ return "launch_failed";
88
+ }
89
+
90
+ const kinds = [];
91
+ if (Array.isArray(journalEvents)) {
92
+ const taskFailedEvents = journalEvents.filter((event) => event.type === "task.failed");
93
+ const prioritized = failedTaskId
94
+ ? [
95
+ ...taskFailedEvents.filter(
96
+ (event) => (event.taskId ?? event.payload?.taskId) === failedTaskId,
97
+ ),
98
+ ...taskFailedEvents.filter(
99
+ (event) => (event.taskId ?? event.payload?.taskId) !== failedTaskId,
100
+ ),
101
+ ]
102
+ : taskFailedEvents;
103
+
104
+ for (const failedEvent of prioritized) {
105
+ const kind = classifyLaunchFailureFromEvent(failedEvent, exitReason);
106
+ if (kind) kinds.push(kind);
107
+ }
108
+ }
109
+
110
+ if (kinds.includes("pi_spine_root")) return "pi_spine_root";
111
+ if (kinds.includes("launch_failed")) return "launch_failed";
112
+ if (kinds.includes("worktree_unhealthy")) return "worktree_unhealthy";
113
+ return null;
114
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Primary task failure headlines and commands (SP-421 / GitHub #74).
3
+ */
4
+
5
+ export const PRIMARY_TASK_FAILURE_EXIT_REASONS = new Set([
6
+ "DirtyWorktree",
7
+ "GitignoredDirtyWorktree",
8
+ "lane_commit_failed",
9
+ "review_exhausted",
10
+ "contract_failed",
11
+ "needs_replan",
12
+ "prompt_parse_failed",
13
+ ]);
14
+
15
+ const LANE_COMMIT_EXIT_REASONS = new Set(["DirtyWorktree", "lane_commit_failed"]);
16
+
17
+ /**
18
+ * @param {string|null|undefined} exitReason
19
+ */
20
+ export function isPrimaryTaskFailureExitReason(exitReason) {
21
+ return PRIMARY_TASK_FAILURE_EXIT_REASONS.has(exitReason ?? "");
22
+ }
23
+
24
+ /**
25
+ * @param {string} batchLabel
26
+ * @param {object} ctx
27
+ * @param {string|null} [ctx.exitReason]
28
+ * @param {string|null} [ctx.failedTaskId]
29
+ * @param {boolean} [ctx.mergeGitignoredFailure]
30
+ */
31
+ export function buildPrimaryFailureHeadline(batchLabel, ctx = {}) {
32
+ if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
33
+ if (ctx.exitReason === "GitignoredDirtyWorktree" || ctx.mergeGitignoredFailure) {
34
+ return ctx.failedTaskId
35
+ ? `${batchLabel} task ${ctx.failedTaskId} left gitignored dirty files on the lane branch`
36
+ : `${batchLabel} lane commit refused gitignored-only dirty files`;
37
+ }
38
+ if (ctx.exitReason === "DirtyWorktree") {
39
+ return ctx.failedTaskId
40
+ ? `${batchLabel} task ${ctx.failedTaskId} left dirty lane worktree after completion — clean coverage artifacts, then retry`
41
+ : `${batchLabel} lane worktree dirty after completion — clean coverage artifacts, then retry`;
42
+ }
43
+ return ctx.failedTaskId
44
+ ? `${batchLabel} task ${ctx.failedTaskId} completed but lane commit failed`
45
+ : `${batchLabel} completed but lane commit failed`;
46
+ }
47
+ if (ctx.exitReason === "review_exhausted") {
48
+ return ctx.failedTaskId
49
+ ? `${batchLabel} task ${ctx.failedTaskId} exhausted final review attempts — fix scope or implementation, then retry`
50
+ : `${batchLabel} review attempts exhausted — fix scope or implementation, then retry`;
51
+ }
52
+ if (ctx.exitReason === "contract_failed") {
53
+ return ctx.failedTaskId
54
+ ? `${batchLabel} task ${ctx.failedTaskId} failed contract verification — fix PROMPT.md scope, then retry`
55
+ : `${batchLabel} contract verification failed — fix PROMPT.md scope, then retry`;
56
+ }
57
+ return null;
58
+ }
59
+
60
+ /**
61
+ * @param {object} ctx
62
+ * @param {string|null} [ctx.exitReason]
63
+ * @param {string|null} [ctx.failedTaskId]
64
+ * @param {string} [ctx.tasksRoot]
65
+ */
66
+ export function buildPrimaryFailureSuggestedCommand(ctx = {}) {
67
+ if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
68
+ if (ctx.exitReason === "DirtyWorktree") {
69
+ return ctx.failedTaskId
70
+ ? `git checkout -- extension/coverage && spine batch retry ${ctx.failedTaskId}`
71
+ : "git checkout -- extension/coverage && spine batch retry";
72
+ }
73
+ return ctx.failedTaskId
74
+ ? `spine batch retry ${ctx.failedTaskId}`
75
+ : "spine status --diagnose";
76
+ }
77
+ if (ctx.exitReason === "review_exhausted") {
78
+ return ctx.failedTaskId
79
+ ? `spine batch retry ${ctx.failedTaskId}`
80
+ : "spine status --diagnose";
81
+ }
82
+ if (ctx.exitReason === "contract_failed") {
83
+ const tasksRoot = ctx.tasksRoot ?? "spine-tasks";
84
+ return ctx.failedTaskId
85
+ ? `edit ${tasksRoot}/${ctx.failedTaskId}/PROMPT.md then spine batch retry ${ctx.failedTaskId}`
86
+ : "spine status --diagnose";
87
+ }
88
+ return null;
89
+ }
@@ -22,7 +22,7 @@ export function isFailedPhasePendingOnlyLimbo(ctx = {}) {
22
22
  * @param {string} batchLabel
23
23
  * @param {object} ctx
24
24
  */
25
- export function buildFailedPhasePendingOnlyHeadline(batchLabel, ctx = {}) {
25
+ export function buildFailedPhasePendingOnlyHeadline(batchLabel, _ctx = {}) {
26
26
  return `${batchLabel} failed with pending task(s) and no failed tasks — resume to continue`;
27
27
  }
28
28
 
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Running diagnosis headlines when batch phase is active but no workers are scheduled (GitHub #68).
3
+ */
4
+ import { isRunningWithoutActiveWorkers } from "../dashboard/running-tail-state.mjs";
5
+ import { macroPhaseLabel } from "./macro-phase.mjs";
6
+
7
+ export { isRunningWithoutActiveWorkers };
8
+
9
+ /**
10
+ * @param {string} batchLabel
11
+ * @param {object} ctx
12
+ * @returns {string|null}
13
+ */
14
+ export function buildRunningTailHeadline(batchLabel, ctx = {}) {
15
+ if (!isRunningWithoutActiveWorkers(ctx)) {
16
+ return null;
17
+ }
18
+
19
+ const macroPhase = ctx.macroPhase ?? null;
20
+
21
+ if (ctx.postMergeLimbo || macroPhase === "gating") {
22
+ if (ctx.integrateGateOpen) {
23
+ return `${batchLabel} gate opened — approve to continue land loop`;
24
+ }
25
+ if (ctx.stalePathSpine) {
26
+ return `${batchLabel} merged but gate not opened — use node bin/spine.mjs batch resume --attached (PATH spine may be stale)`;
27
+ }
28
+ return `${batchLabel} finalizing land loop — opening integrate gate…`;
29
+ }
30
+
31
+ if (macroPhase === "integrating") {
32
+ return `${batchLabel} integrating orch branch to main…`;
33
+ }
34
+
35
+ if (macroPhase === "merging" || ctx.phase === "merging") {
36
+ return `${batchLabel} tasks done — merging lane branches…`;
37
+ }
38
+
39
+ if (macroPhase === "reviewing") {
40
+ return `${batchLabel} running reviews — no workers scheduled`;
41
+ }
42
+
43
+ if (macroPhase === "planning") {
44
+ return `${batchLabel} planning — no workers scheduled`;
45
+ }
46
+
47
+ if (macroPhase != null && macroPhase !== "executing") {
48
+ const label = macroPhaseLabel(macroPhase);
49
+ return `${batchLabel} ${label.toLowerCase()} — finalizing batch`;
50
+ }
51
+
52
+ if (ctx.gitMerged === false || ctx.allTasksTerminalSuccess === true) {
53
+ return `${batchLabel} tasks done — merging lane branches…`;
54
+ }
55
+
56
+ return `${batchLabel} finalizing batch — no active workers`;
57
+ }
@@ -14,21 +14,27 @@ import { buildAlternatives } from "./diagnosis-alternatives.mjs";
14
14
  export { buildAlternatives } from "./diagnosis-alternatives.mjs";
15
15
  import {
16
16
  buildMergeFailureHeadline,
17
- summarizeMergeFailures,
18
17
  } from "./diagnosis-merge-failure.mjs";
19
18
  export { buildMergeFailureHeadline, summarizeMergeFailures } from "./diagnosis-merge-failure.mjs";
19
+ import { buildRunningTailHeadline } from "./diagnosis-tail-state.mjs";
20
+ export { buildRunningTailHeadline, isRunningWithoutActiveWorkers } from "./diagnosis-tail-state.mjs";
20
21
  import {
21
22
  buildStubFailureHeadline,
22
23
  buildStubFailureSuggestedCommand,
23
24
  STUB_EXIT_REASONS,
24
25
  } from "./diagnosis-stub.mjs";
26
+ /** @typedef {import("./reconcile.mjs").ReconciliationResult} ReconciliationResult */
25
27
  export {
26
28
  classifyTaskDoneSemantics,
27
29
  resolveTaskFolderPath,
28
30
  resolveTaskLaneWorktreePath,
29
31
  TASK_DONE_FLAG_FIELD_NAMES,
30
32
  } from "./diagnosis-task-done.mjs";
31
- /** @typedef {import("./reconcile.mjs").ReconciliationResult} ReconciliationResult */
33
+ import {
34
+ buildPrimaryFailureHeadline,
35
+ buildPrimaryFailureSuggestedCommand,
36
+ } from "./diagnosis-primary-failure.mjs";
37
+ export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis-launch-failure.mjs";
32
38
 
33
39
  export const DIAGNOSIS_TAXONOMY = [
34
40
  "running",
@@ -49,7 +55,6 @@ export const DIAGNOSIS_TAXONOMY = [
49
55
  ];
50
56
 
51
57
  const NO_PAUSE_DIAGNOSES = new Set(["limbo_stale", "completed_manual", "needs_integrate", "engine_orphaned"]);
52
- const LANE_COMMIT_EXIT_REASONS = new Set(["DirtyWorktree", "lane_commit_failed"]);
53
58
  const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
54
59
  const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
55
60
  "code_review_spawn_failed",
@@ -58,66 +63,6 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
58
63
  "final_review_timeout",
59
64
  ]);
60
65
 
61
- /**
62
- * @param {string} haystack
63
- * @param {object} [hints]
64
- * @param {boolean} [hints.launchingPhase]
65
- * @returns {string|null}
66
- */
67
- function classifyLaunchFailureHaystack(haystack, hints = {}) {
68
- const normalized = haystack.toLowerCase();
69
-
70
- if (hints.launchingPhase) {
71
- if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
72
- return "pi_spine_root";
73
- }
74
- return "launch_failed";
75
- }
76
-
77
- if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
78
- return "pi_spine_root";
79
- }
80
-
81
- if (
82
- normalized.includes("not a git repository") ||
83
- normalized.includes("worktree") ||
84
- normalized.includes("worktreeunhealthy")
85
- ) {
86
- return "worktree_unhealthy";
87
- }
88
-
89
- return null;
90
- }
91
-
92
- /**
93
- * @param {object|null} failedEvent
94
- * @param {string|null} exitReason
95
- * @returns {string|null}
96
- */
97
- function classifyLaunchFailureFromEvent(failedEvent, exitReason) {
98
- const payload = failedEvent?.payload && typeof failedEvent.payload === "object" ? failedEvent.payload : {};
99
- const haystack = [
100
- exitReason,
101
- payload.classification,
102
- payload.output,
103
- payload.exitReason,
104
- ].filter(Boolean).join("\n");
105
-
106
- return classifyLaunchFailureHaystack(haystack, {
107
- launchingPhase:
108
- payload.workerPhase === "launching" || payload.classification === "launch_failed",
109
- });
110
- }
111
-
112
- /**
113
- * @param {string|null|undefined} outputText
114
- * @returns {string|null}
115
- */
116
- export function inferLaunchFailureFromWorkerOutputTail(outputText) {
117
- if (!outputText || !String(outputText).trim()) return null;
118
- return classifyLaunchFailureHaystack(String(outputText));
119
- }
120
-
121
66
  /**
122
67
  * @param {object} [ctx]
123
68
  * @param {string|null} [ctx.exitReason]
@@ -166,46 +111,6 @@ export function buildGitignoredMergeRepairCommand(taskBranch, gitignoredPaths) {
166
111
  return `${branchHint} && ${pathHint} && spine batch resume --force`;
167
112
  }
168
113
 
169
- /**
170
- * @param {object} ctx
171
- * @param {string|null} [ctx.exitReason]
172
- * @param {string|null} [ctx.launchFailureKind]
173
- * @param {object[]} [ctx.journalEvents]
174
- * @param {string|null} [ctx.failedTaskId]
175
- * @returns {string|null}
176
- */
177
- export function inferLaunchFailureKind(ctx = {}) {
178
- const { exitReason, journalEvents, failedTaskId } = ctx;
179
- if (exitReason === "launch_failed" || exitReason === "worker_launch_failed") {
180
- return "launch_failed";
181
- }
182
-
183
- const kinds = [];
184
- if (Array.isArray(journalEvents)) {
185
- const taskFailedEvents = journalEvents.filter((event) => event.type === "task.failed");
186
- const prioritized = failedTaskId
187
- ? [
188
- ...taskFailedEvents.filter(
189
- (event) => (event.taskId ?? event.payload?.taskId) === failedTaskId,
190
- ),
191
- ...taskFailedEvents.filter(
192
- (event) => (event.taskId ?? event.payload?.taskId) !== failedTaskId,
193
- ),
194
- ]
195
- : taskFailedEvents;
196
-
197
- for (const failedEvent of prioritized) {
198
- const kind = classifyLaunchFailureFromEvent(failedEvent, exitReason);
199
- if (kind) kinds.push(kind);
200
- }
201
- }
202
-
203
- if (kinds.includes("pi_spine_root")) return "pi_spine_root";
204
- if (kinds.includes("launch_failed")) return "launch_failed";
205
- if (kinds.includes("worktree_unhealthy")) return "worktree_unhealthy";
206
- return null;
207
- }
208
-
209
114
  /**
210
115
  * @param {string} diagnosis
211
116
  * @param {object} [ctx]
@@ -240,6 +145,10 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
240
145
  if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
241
146
  return buildStubFailureSuggestedCommand(ctx);
242
147
  }
148
+ {
149
+ const primaryCommand = buildPrimaryFailureSuggestedCommand(ctx);
150
+ if (primaryCommand) return primaryCommand;
151
+ }
243
152
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
244
153
  return "spine doctor";
245
154
  }
@@ -358,22 +267,16 @@ export function buildHeadline(diagnosis, ctx = {}) {
358
267
  if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
359
268
  return buildStubFailureHeadline(batchLabel, ctx);
360
269
  }
270
+ {
271
+ const primaryHeadline = buildPrimaryFailureHeadline(batchLabel, ctx);
272
+ if (primaryHeadline) return primaryHeadline;
273
+ }
361
274
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
362
275
  return `${batchLabel} failed at worker launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
363
276
  }
364
277
  if (ctx.launchFailureKind === "worktree_unhealthy") {
365
278
  return `${batchLabel} failed at worker launch — repair lane worktree git, then retry`;
366
279
  }
367
- if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
368
- if (ctx.exitReason === "GitignoredDirtyWorktree" || ctx.mergeGitignoredFailure) {
369
- return ctx.failedTaskId
370
- ? `${batchLabel} task ${ctx.failedTaskId} left gitignored dirty files on the lane branch`
371
- : `${batchLabel} lane commit refused gitignored-only dirty files`;
372
- }
373
- return ctx.failedTaskId
374
- ? `${batchLabel} task ${ctx.failedTaskId} completed but lane commit failed`
375
- : `${batchLabel} completed but lane commit failed`;
376
- }
377
280
  if (REVIEW_SPAWN_FAILURE_EXIT_REASONS.has(ctx.exitReason ?? "")) {
378
281
  const reviewKind =
379
282
  ctx.exitReason === "final_review_spawn_failed" ||
@@ -448,8 +351,13 @@ export function buildHeadline(diagnosis, ctx = {}) {
448
351
  return ctx.failedTaskId
449
352
  ? `Task ${ctx.failedTaskId} needs replan — edit PROMPT.md before retry`
450
353
  : `${batchLabel} has tasks needing replan — edit PROMPT.md before retry`;
451
- case "running":
354
+ case "running": {
355
+ const tailHeadline = buildRunningTailHeadline(batchLabel, ctx);
356
+ if (tailHeadline) {
357
+ return tailHeadline;
358
+ }
452
359
  return `${batchLabel} is running`;
360
+ }
453
361
  case "paused": {
454
362
  const pending = ctx.pendingTaskCount ?? 0;
455
363
  if (pending > 1) {