pi-spine 1.6.0 → 1.7.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 (37) hide show
  1. package/bin/spine-wait.mjs +12 -0
  2. package/package.json +2 -2
  3. package/skills/spine-release-operator/SKILL.md +37 -7
  4. package/src/batch/attached-runner.mjs +18 -7
  5. package/src/batch/contract-task-start.mjs +12 -7
  6. package/src/batch/contract-verify.mjs +25 -1
  7. package/src/batch/detached-spawn.mjs +78 -0
  8. package/src/batch/detached-start.mjs +25 -71
  9. package/src/batch/diagnosis.mjs +25 -2
  10. package/src/batch/evidence.mjs +30 -250
  11. package/src/batch/gate-evidence-collect.mjs +172 -0
  12. package/src/batch/gate-evidence-read.mjs +145 -0
  13. package/src/batch/gate.mjs +28 -38
  14. package/src/batch/lane-dirty-check.mjs +102 -0
  15. package/src/batch/lifecycle.mjs +6 -5
  16. package/src/batch/post-merge-limbo.mjs +1 -1
  17. package/src/batch/postmortem.mjs +1 -2
  18. package/src/batch/reconcile.mjs +1 -1
  19. package/src/batch/resume-common.mjs +7 -1
  20. package/src/batch/resume-multi-validate.mjs +25 -101
  21. package/src/batch/resume-validation.mjs +120 -0
  22. package/src/batch/sequence.mjs +11 -2
  23. package/src/batch/supervisor-spawn.mjs +379 -0
  24. package/src/cli/spine-wait.mjs +114 -0
  25. package/src/cli/wait.mjs +7 -43
  26. package/src/config/defaults.mjs +4 -1
  27. package/src/config/settings-fields.mjs +23 -0
  28. package/src/config/spine-config-load.mjs +6 -0
  29. package/src/config/spine-config-schema.mjs +121 -0
  30. package/src/config/spine-init-constants.mjs +19 -1
  31. package/src/config/worktree-setup-hook.mjs +221 -0
  32. package/src/doctor/agent-models.mjs +1 -0
  33. package/src/doctor/run-doctor-checks.mjs +14 -0
  34. package/src/doctor/supervisor.mjs +66 -0
  35. package/src/doctor/worktree-health.mjs +1 -1
  36. package/templates/agents/supervisor.md +27 -18
  37. package/templates/spine-config.json +16 -1
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Re-export spine wait helpers from src (bin must not be imported by src/).
3
+ */
4
+ export {
5
+ WAIT_UNTIL_PSEUDO_DIAGNOSES,
6
+ VALID_UNTIL_DIAGNOSES,
7
+ formatValidWaitUntilDiagnoses,
8
+ parseUntilDiagnoses,
9
+ deriveWaitPseudoDiagnoses,
10
+ diagnosisMatchesUntil,
11
+ reconciliationMatchesUntil,
12
+ } from "../src/cli/spine-wait.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -32,7 +32,7 @@
32
32
  "doctor": "node bin/spine.mjs doctor",
33
33
  "lint": "eslint --max-warnings 0 src bin tests scripts",
34
34
  "typecheck": "tsc --project tsconfig.json --noEmit && tsc --project tsconfig.batch.json --noEmit",
35
- "test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
35
+ "test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
36
36
  "test:batch": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/batch/*.test.mjs",
37
37
  "test:core": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs",
38
38
  "test:coverage": "node scripts/run-coverage.mjs --report-only",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: spine-release-operator
3
3
  description: End-to-end pi-spine release operator. Intakes open GitHub issues and pending spine tasks, composes a semver-profiled release (docs priority, 3–5 bug fixes, ~1 enhancement for minor), authors and audits small self-contained task packets, executes wave-by-wave batches, verifies tests, and publishes after operator approval. Use when asked to run a spine release cycle, release vX.Y.Z, patch/minor/major release, or ship pi-spine to npm.
4
- compatibility: Requires spine CLI, gh CLI, git, Node >= 22. Run from pi-spine repo root on main.
4
+ compatibility: Requires spine CLI, gh CLI, git, Node >= 22, gitnexus (pi-gitnexus extension or `gitnexus` on PATH). Run from pi-spine repo root on main.
5
5
  ---
6
6
 
7
7
  # Spine Release Operator
@@ -26,11 +26,12 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
26
26
 
27
27
  ## Success criteria
28
28
 
29
- 1. Release manifest written and operator-approved
30
- 2. All **release-scoped** tasks `.DONE` and integrated on `main`
31
- 3. `spine preflight` green; local test/coverage gates pass
32
- 4. Operator explicitly approved publish; version bumped and tag pushed (if approved)
33
- 5. Final report with composition table, issues closed/deferred, verification output
29
+ 1. GitNexus index refreshed (`gitnexus status` up-to-date with HEAD)
30
+ 2. Release manifest written and operator-approved
31
+ 3. All **release-scoped** tasks `.DONE` and integrated on `main`
32
+ 4. `spine preflight` green; local test/coverage gates pass
33
+ 5. Operator explicitly approved publish; version bumped and tag pushed (if approved)
34
+ 6. Final report with composition table, issues closed/deferred, verification output
34
35
 
35
36
  ## Hard rules
36
37
 
@@ -43,6 +44,34 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
43
44
  - **Always** run `spine gate approve` before `spine integrate`
44
45
  - **Always** run `npm install` on `main` after successful integrate
45
46
  - **Do not** execute tasks outside the approved manifest scope
47
+ - **Always** run `/gitnexus analyze` (Pre-work) before Phase 0 — do not start intake, authoring, or batches on a stale index
48
+
49
+ ---
50
+
51
+ ## Pre-work — GitNexus index
52
+
53
+ **First step on every release cycle.** Refresh the knowledge graph so GitNexus auto-augment, impact analysis, and symbol lookups reflect current `main` before intake, packet audit, or batch execution.
54
+
55
+ In pi:
56
+
57
+ ```
58
+ /gitnexus analyze
59
+ ```
60
+
61
+ Outside pi (same repo root):
62
+
63
+ ```bash
64
+ cd <repo-root>
65
+ gitnexus analyze
66
+ ```
67
+
68
+ Verify before continuing:
69
+
70
+ ```bash
71
+ gitnexus status # Status: up-to-date; indexed commit matches HEAD
72
+ ```
73
+
74
+ If analyze fails or status is not up-to-date, **stop** and report — do not proceed to Phase 0.
46
75
 
47
76
  ---
48
77
 
@@ -333,7 +362,8 @@ Close GitHub issues where tasks had `Closes: #NNN` and work shipped.
333
362
  ## Short prompt (resume mid-release)
334
363
 
335
364
  ```text
336
- Resume spine release v{TARGET}: check manifest at spine-tasks/_authoring/release-v{TARGET}/manifest.md →
365
+ Resume spine release v{TARGET}: /gitnexus analyze (or gitnexus analyze) → gitnexus status →
366
+ check manifest at spine-tasks/_authoring/release-v{TARGET}/manifest.md →
337
367
  verify remaining scope → preflight → for each wave: batch start --attached → diagnose →
338
368
  gate approve → integrate → npm install → batch complete →
339
369
  when scope done: tests + preflight → STOP for publish approval.
@@ -15,6 +15,13 @@ import { reconcileBatch } from "./reconcile.mjs";
15
15
  import { readJournalEventsCached } from "./journal.mjs";
16
16
  import { enforceOperatorPauseOnDisk } from "./pause.mjs";
17
17
  import { loadSpineBatchState, readBatchEnginePid, saveSpineBatchState } from "./state.mjs";
18
+ import { loadSpineConfig } from "../config/spine-config-load.mjs";
19
+ import { resolveAttachedMilestonePollMs } from "../config/spine-config-schema.mjs";
20
+
21
+ export { DEFAULT_ATTACHED_MILESTONE_POLL_MS } from "../config/spine-config-schema.mjs";
22
+
23
+ /** @type {boolean} */
24
+ let attachedExitHandlersInstalled = false;
18
25
 
19
26
  /** Journal types surfaced on attached stdout during the land loop. */
20
27
  export const ATTACHED_LAND_LOOP_MILESTONE_TYPES = new Set([
@@ -33,11 +40,6 @@ export const ATTACHED_LAND_LOOP_MILESTONE_TYPES = new Set([
33
40
  "batch.completed",
34
41
  ]);
35
42
 
36
- const ATTACHED_MILESTONE_POLL_MS = 200;
37
-
38
- /** @type {boolean} */
39
- let attachedExitHandlersInstalled = false;
40
-
41
43
  /**
42
44
  * Install journal-aware SIGTERM/SIGINT handlers before attached engine exit (SP-378).
43
45
  *
@@ -101,9 +103,18 @@ export function formatAttachedMilestoneLine(event) {
101
103
  * @param {object} params
102
104
  * @param {string} params.projectRoot
103
105
  * @param {(line: string) => void} [params.write]
106
+ * @param {number} [params.pollIntervalMs]
104
107
  * @returns {Promise<{ stop: () => Promise<void> }>}
105
108
  */
106
- export async function startAttachedMilestoneReporter({ projectRoot, write = (line) => process.stdout.write(line) }) {
109
+ export async function startAttachedMilestoneReporter({
110
+ projectRoot,
111
+ write = (line) => process.stdout.write(line),
112
+ pollIntervalMs,
113
+ }) {
114
+ const configResult = loadSpineConfig(projectRoot);
115
+ const resolvedPollMs =
116
+ pollIntervalMs ??
117
+ resolveAttachedMilestonePollMs({ config: configResult.config ?? {} });
107
118
  /** @type {Set<string>} */
108
119
  const printed = new Set();
109
120
  let batchId = null;
@@ -126,7 +137,7 @@ export async function startAttachedMilestoneReporter({ projectRoot, write = (lin
126
137
  write(formatAttachedMilestoneLine(event));
127
138
  }
128
139
  }
129
- await sleep(ATTACHED_MILESTONE_POLL_MS);
140
+ await sleep(resolvedPollMs);
130
141
  }
131
142
  };
132
143
 
@@ -98,9 +98,10 @@ function batchMatches(event, batchId) {
98
98
  * @param {object[]} journal
99
99
  * @param {string|null|undefined} laneId
100
100
  * @param {number} beforeIndex
101
+ * @param {string|null|undefined} [excludeTaskId] Skip lane.committed for this task (SP-478 / issue #105).
101
102
  * @returns {string|null}
102
103
  */
103
- function resolvePriorLaneCommit(journal, laneId, beforeIndex) {
104
+ function resolvePriorLaneCommit(journal, laneId, beforeIndex, excludeTaskId) {
104
105
  for (let index = beforeIndex - 1; index >= 0; index -= 1) {
105
106
  const event = journal[index];
106
107
  if (String(event?.type ?? "") !== "lane.committed") {
@@ -109,6 +110,9 @@ function resolvePriorLaneCommit(journal, laneId, beforeIndex) {
109
110
  if (!lanesMatch(readEventLaneId(event), laneId)) {
110
111
  continue;
111
112
  }
113
+ if (excludeTaskId && readEventTaskId(event) === excludeTaskId) {
114
+ continue;
115
+ }
112
116
  const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
113
117
  const sha = payload.commitSha ?? payload.mergeCommit;
114
118
  if (typeof sha === "string" && sha.trim()) {
@@ -138,14 +142,15 @@ function resolveHeadAtTimestamp(worktreePath, timestampIso) {
138
142
  }
139
143
 
140
144
  /**
145
+ * First task.started for a task — stable baseline across retry/resume (SP-478 / issue #105).
146
+ *
141
147
  * @param {object[]} journal
142
148
  * @param {string} taskId
143
149
  * @param {string|null|undefined} laneId
144
150
  * @param {string|null|undefined} batchId
145
151
  * @returns {{ event: object, index: number } | null}
146
152
  */
147
- function findLastTaskStarted(journal, taskId, laneId, batchId) {
148
- let match = null;
153
+ function findFirstTaskStarted(journal, taskId, laneId, batchId) {
149
154
  for (let index = 0; index < journal.length; index += 1) {
150
155
  const event = journal[index];
151
156
  if (String(event?.type ?? "") !== "task.started") {
@@ -160,9 +165,9 @@ function findLastTaskStarted(journal, taskId, laneId, batchId) {
160
165
  if (!batchMatches(event, batchId)) {
161
166
  continue;
162
167
  }
163
- match = { event, index };
168
+ return { event, index };
164
169
  }
165
- return match;
170
+ return null;
166
171
  }
167
172
 
168
173
  /**
@@ -177,7 +182,7 @@ export function resolveTaskStartCommit({ journal, taskId, laneId, batchId, workt
177
182
  return null;
178
183
  }
179
184
 
180
- const started = findLastTaskStarted(journal, taskId, laneId, batchId);
185
+ const started = findFirstTaskStarted(journal, taskId, laneId, batchId);
181
186
  if (!started) {
182
187
  return null;
183
188
  }
@@ -188,7 +193,7 @@ export function resolveTaskStartCommit({ journal, taskId, laneId, batchId, workt
188
193
  }
189
194
 
190
195
  const eventLaneId = readEventLaneId(started.event);
191
- const priorLaneCommit = resolvePriorLaneCommit(journal, eventLaneId, started.index);
196
+ const priorLaneCommit = resolvePriorLaneCommit(journal, eventLaneId, started.index, taskId);
192
197
  if (priorLaneCommit) {
193
198
  return priorLaneCommit;
194
199
  }
@@ -15,6 +15,10 @@ import {
15
15
  isStubPrelandedFileScopeSatisfied,
16
16
  } from "./contract-prelanded.mjs";
17
17
  import { appendJournalEvent } from "./journal.mjs";
18
+ import {
19
+ sanitizeFlutterBuildBeforeAnalyze,
20
+ shouldCleanFlutterBuildBeforeAnalyze,
21
+ } from "./lane-dirty-check.mjs";
18
22
 
19
23
  export { resolvePromptRelPath, isFileScopePatternPrelanded, hasSpineTaskDeliveryChanges } from "./contract-prelanded.mjs";
20
24
 
@@ -461,13 +465,31 @@ function findArtifactMatch(worktreePath, artifactPattern) {
461
465
  return { ok: false };
462
466
  }
463
467
 
468
+ /**
469
+ * Prepare lane worktree before contract testCommand (Flutter analyzer hygiene #78).
470
+ *
471
+ * @param {string} worktreePath
472
+ * @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
473
+ * @param {object} [config]
474
+ * @returns {{ hygieneApplied: boolean, cleaned?: boolean, buildDir?: string, reason?: string }}
475
+ */
476
+ export function prepareContractVerifyEnvironment(worktreePath, parsedContract, config = {}) {
477
+ const testCommand = parsedContract?.testCommand;
478
+ if (!testCommand || !shouldCleanFlutterBuildBeforeAnalyze(testCommand, config)) {
479
+ return { hygieneApplied: false };
480
+ }
481
+
482
+ const result = sanitizeFlutterBuildBeforeAnalyze(worktreePath);
483
+ return { hygieneApplied: true, ...result };
484
+ }
485
+
464
486
  /**
465
487
  * @param {string} worktreePath
466
488
  * @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
467
489
  * @param {object} [config]
468
490
  * @param {string} [config.baseBranch]
469
491
  * @param {string} [config.sinceCommit] When set, scope file-scope checks to `sinceCommit..HEAD` (serialized lanes).
470
- * @param {string} [config.taskStartCommit] Alias for `sinceCommit` (SP-415 journal resolution).
492
+ * @param {string} [config.taskStartCommit] Alias for `sinceCommit` (SP-415 journal resolution; anchor stable across retry/resume per SP-478).
471
493
  * @param {string} [config.projectRoot] Repo root for journal events (optional).
472
494
  * @param {string} [config.batchId] Batch ID for journal events (optional).
473
495
  * @param {string} [config.taskId] Task ID for journal events (optional).
@@ -481,6 +503,8 @@ export function verifyContract(worktreePath, parsedContract, config = {}) {
481
503
  const sinceCommit = config?.sinceCommit ?? config?.taskStartCommit ?? undefined;
482
504
  const changedFiles = listChangedFiles(worktreePath, baseBranch, sinceCommit);
483
505
 
506
+ prepareContractVerifyEnvironment(worktreePath, parsedContract, config);
507
+
484
508
  let testCommandOutput = "";
485
509
  let testCommandOk = true;
486
510
  let retriedCount = 0;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Detached batch engine spawn argv builders — leaf module (SP-469 / #83-C).
3
+ * No imports from detached-start, reconcile, or post-merge-limbo.
4
+ */
5
+
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { spawn } from "node:child_process";
9
+
10
+ export const DETACHED_ENGINE_LOG_REL = path.join(".spine", "runtime", "detached-engine.log");
11
+
12
+ /**
13
+ * @param {string} projectRoot
14
+ */
15
+ export function detachedEngineLogPath(projectRoot) {
16
+ return path.join(projectRoot, DETACHED_ENGINE_LOG_REL);
17
+ }
18
+
19
+ /**
20
+ * @param {object} params
21
+ * @param {string} params.scope
22
+ * @param {boolean} [params.skipPreflight]
23
+ * @param {boolean} [params.forceSuperseded]
24
+ * @param {number|null} [params.waveFilter]
25
+ */
26
+ export function buildAttachedBatchStartArgv({
27
+ scope,
28
+ skipPreflight = false,
29
+ forceSuperseded = false,
30
+ waveFilter = null,
31
+ }) {
32
+ const tokens = String(scope ?? "")
33
+ .trim()
34
+ .split(/\s+/)
35
+ .filter(Boolean);
36
+ const args = ["batch", "start", ...tokens, "--attached"];
37
+ if (skipPreflight) args.push("--skip-preflight");
38
+ if (forceSuperseded) args.push("--force-superseded");
39
+ if (waveFilter != null) args.push("--wave", String(waveFilter));
40
+ return args;
41
+ }
42
+
43
+ /**
44
+ * @param {object} params
45
+ * @param {boolean} [params.force]
46
+ */
47
+ export function buildAttachedBatchResumeArgv({ force = false }) {
48
+ const args = ["batch", "resume", "--attached"];
49
+ if (force) args.push("--force");
50
+ return args;
51
+ }
52
+
53
+ /**
54
+ * @param {object} params
55
+ * @param {string} params.projectRoot
56
+ * @param {string} params.spineBin
57
+ * @param {string[]} params.argv
58
+ */
59
+ export function spawnDetachedBatchEngine({ projectRoot, spineBin, argv }) {
60
+ const logPath = detachedEngineLogPath(projectRoot);
61
+ fs.mkdirSync(path.dirname(logPath), { recursive: true });
62
+ const logFd = fs.openSync(logPath, "a");
63
+ fs.writeFileSync(
64
+ logFd,
65
+ `\n--- detached batch engine ${new Date().toISOString()} argv=${argv.join(" ")} ---\n`,
66
+ );
67
+
68
+ const child = spawn(process.execPath, [spineBin, ...argv], {
69
+ cwd: projectRoot,
70
+ detached: true,
71
+ stdio: ["ignore", logFd, logFd],
72
+ env: process.env,
73
+ });
74
+ child.unref();
75
+ fs.closeSync(logFd);
76
+
77
+ return { enginePid: child.pid ?? null, logPath: DETACHED_ENGINE_LOG_REL };
78
+ }
@@ -4,8 +4,23 @@
4
4
 
5
5
  import fs from "node:fs";
6
6
  import path from "node:path";
7
- import { spawn } from "node:child_process";
8
7
  import { loadSpineConfig } from "../config/spine-config-load.mjs";
8
+ import {
9
+ buildAttachedBatchResumeArgv,
10
+ buildAttachedBatchStartArgv,
11
+ DETACHED_ENGINE_LOG_REL,
12
+ detachedEngineLogPath,
13
+ spawnDetachedBatchEngine,
14
+ } from "./detached-spawn.mjs";
15
+
16
+ export {
17
+ buildAttachedBatchResumeArgv,
18
+ buildAttachedBatchStartArgv,
19
+ DETACHED_ENGINE_LOG_REL,
20
+ detachedEngineLogPath,
21
+ spawnDetachedBatchEngine,
22
+ } from "./detached-spawn.mjs";
23
+ import { maybeSpawnSupervisorOnDetachedStart } from "./supervisor-spawn.mjs";
9
24
  import { runBatchPreflight } from "../config/spine-preflight-lib.mjs";
10
25
  import { loadGateRecord } from "./gate.mjs";
11
26
  import { reconcileBatch } from "./reconcile.mjs";
@@ -22,8 +37,6 @@ import {
22
37
  TERMINAL_BATCH_PHASES,
23
38
  } from "./state.mjs";
24
39
 
25
- export const DETACHED_ENGINE_LOG_REL = path.join(".spine", "runtime", "detached-engine.log");
26
-
27
40
  /** Diagnoses that benefit from blocking until resume engine reaches terminal phase. */
28
41
  const RESUME_WAIT_TERMINAL_DIAGNOSES = new Set([
29
42
  "engine_orphaned",
@@ -308,74 +321,6 @@ function evaluateDetachedResumeWait(raw, taskId, updatedAtBefore) {
308
321
  return null;
309
322
  }
310
323
 
311
- /**
312
- * @param {string} projectRoot
313
- */
314
- export function detachedEngineLogPath(projectRoot) {
315
- return path.join(projectRoot, DETACHED_ENGINE_LOG_REL);
316
- }
317
-
318
- /**
319
- * @param {object} params
320
- * @param {string} params.scope
321
- * @param {boolean} [params.skipPreflight]
322
- * @param {boolean} [params.forceSuperseded]
323
- * @param {number|null} [params.waveFilter]
324
- */
325
- export function buildAttachedBatchStartArgv({
326
- scope,
327
- skipPreflight = false,
328
- forceSuperseded = false,
329
- waveFilter = null,
330
- }) {
331
- const tokens = String(scope ?? "")
332
- .trim()
333
- .split(/\s+/)
334
- .filter(Boolean);
335
- const args = ["batch", "start", ...tokens, "--attached"];
336
- if (skipPreflight) args.push("--skip-preflight");
337
- if (forceSuperseded) args.push("--force-superseded");
338
- if (waveFilter != null) args.push("--wave", String(waveFilter));
339
- return args;
340
- }
341
-
342
- /**
343
- * @param {object} params
344
- * @param {boolean} [params.force]
345
- */
346
- export function buildAttachedBatchResumeArgv({ force = false }) {
347
- const args = ["batch", "resume", "--attached"];
348
- if (force) args.push("--force");
349
- return args;
350
- }
351
-
352
- /**
353
- * @param {object} params
354
- * @param {string} params.projectRoot
355
- * @param {string} params.spineBin
356
- * @param {string[]} params.argv
357
- */
358
- export function spawnDetachedBatchEngine({ projectRoot, spineBin, argv }) {
359
- const logPath = detachedEngineLogPath(projectRoot);
360
- fs.mkdirSync(path.dirname(logPath), { recursive: true });
361
- const logFd = fs.openSync(logPath, "a");
362
- fs.writeFileSync(
363
- logFd,
364
- `\n--- detached batch engine ${new Date().toISOString()} argv=${argv.join(" ")} ---\n`,
365
- );
366
-
367
- const child = spawn(process.execPath, [spineBin, ...argv], {
368
- cwd: projectRoot,
369
- detached: true,
370
- stdio: ["ignore", logFd, logFd],
371
- env: process.env,
372
- });
373
- child.unref();
374
- fs.closeSync(logFd);
375
-
376
- return { enginePid: child.pid ?? null, logPath: DETACHED_ENGINE_LOG_REL };
377
- }
378
-
379
324
  /**
380
325
  * @param {string} projectRoot
381
326
  * @param {number|null} enginePid
@@ -762,6 +707,13 @@ export async function startBatchDetached({
762
707
  };
763
708
  }
764
709
 
710
+ const configResult = loadSpineConfig(projectRoot);
711
+ const supervisorSpawn = maybeSpawnSupervisorOnDetachedStart({
712
+ projectRoot,
713
+ batchId: wait.batchId,
714
+ config: configResult.config ?? {},
715
+ });
716
+
765
717
  const payload = {
766
718
  ok: true,
767
719
  detached: true,
@@ -773,6 +725,8 @@ export async function startBatchDetached({
773
725
  enginePid,
774
726
  logPath,
775
727
  suggestedCommand: "spine status --diagnose",
728
+ supervisorSpawned: supervisorSpawn.spawned === true,
729
+ supervisorPid: supervisorSpawn.supervisorPid ?? null,
776
730
  };
777
731
  return {
778
732
  ok: true,
@@ -36,6 +36,25 @@ import {
36
36
  } from "./diagnosis-primary-failure.mjs";
37
37
  export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis-launch-failure.mjs";
38
38
 
39
+ const INVALID_BARE_RETRY_FORCE = /^spine batch retry --force$/;
40
+
41
+ /**
42
+ * Retry suggestions must include a task id; journal salvage payloads may be stale.
43
+ *
44
+ * @param {string|null|undefined} command
45
+ * @param {string|null|undefined} taskId
46
+ * @returns {string|null}
47
+ */
48
+ export function sanitizeRetrySuggestedCommand(command, taskId) {
49
+ if (typeof command !== "string" || command.length === 0) {
50
+ return command ?? null;
51
+ }
52
+ if (INVALID_BARE_RETRY_FORCE.test(command.trim())) {
53
+ return taskId ? `spine batch retry ${taskId}` : "spine status --diagnose";
54
+ }
55
+ return command;
56
+ }
57
+
39
58
  export const DIAGNOSIS_TAXONOMY = [
40
59
  "running",
41
60
  "paused",
@@ -169,7 +188,9 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
169
188
  if (ctx.launchFailureKind === "worktree_unhealthy") {
170
189
  return "spine doctor";
171
190
  }
172
- if (ctx.salvageRetryCommand) return ctx.salvageRetryCommand;
191
+ if (ctx.salvageRetryCommand) {
192
+ return sanitizeRetrySuggestedCommand(ctx.salvageRetryCommand, ctx.failedTaskId);
193
+ }
173
194
  if (isFailedPhasePendingOnlyLimbo(ctx)) {
174
195
  return buildFailedPhasePendingOnlySuggestedCommand(ctx);
175
196
  }
@@ -197,7 +218,9 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
197
218
  if (ctx.launchFailureKind === "worktree_unhealthy") {
198
219
  return "spine doctor";
199
220
  }
200
- if (ctx.salvageRetryCommand) return ctx.salvageRetryCommand;
221
+ if (ctx.salvageRetryCommand) {
222
+ return sanitizeRetrySuggestedCommand(ctx.salvageRetryCommand, ctx.failedTaskId);
223
+ }
201
224
  return ctx.failedTaskId
202
225
  ? `spine batch retry ${ctx.failedTaskId}`
203
226
  : "spine batch abort";