pi-spine 2.0.0 → 2.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 (36) hide show
  1. package/bin/spine-batch.mjs +74 -5
  2. package/bin/spine-cleanup.mjs +89 -0
  3. package/bin/spine-cli/verify.mjs +1 -0
  4. package/bin/spine-doctor.mjs +8 -0
  5. package/bin/spine.mjs +13 -0
  6. package/package.json +4 -1
  7. package/skills/create-spine-tasks/SKILL.md +28 -0
  8. package/skills/create-spine-tasks/references/contract-template.md +11 -0
  9. package/skills/create-spine-tasks/references/prompt-template.md +7 -1
  10. package/skills/spine-autonomous-operator/SKILL.md +19 -3
  11. package/skills/spine-autonomous-operator/references/agent-shell-batch-policy.md +18 -0
  12. package/skills/spine-orchestrate-waves/SKILL.md +9 -2
  13. package/skills/spine-orchestrate-waves/references/outer-loop.md +24 -2
  14. package/skills/spine-release-operator/SKILL.md +25 -2
  15. package/skills/spine-release-operator/references/post-integrate-regression-gate.md +96 -0
  16. package/skills/spine-release-operator/references/release-manifest-template.md +7 -3
  17. package/src/batch/abort.mjs +10 -14
  18. package/src/batch/attached-runner.mjs +12 -1
  19. package/src/batch/diagnosis-merge-failure.mjs +66 -0
  20. package/src/batch/diagnosis-parent-exit.mjs +125 -0
  21. package/src/batch/diagnosis.mjs +26 -73
  22. package/src/batch/engine-lanes/merge.mjs +25 -0
  23. package/src/batch/journal-rebuild.mjs +80 -1
  24. package/src/batch/lane-dirty-check.mjs +10 -0
  25. package/src/batch/lifecycle.mjs +1 -18
  26. package/src/batch/reconcile.mjs +11 -0
  27. package/src/batch/resume-multi-lanes.mjs +38 -1
  28. package/src/batch/review.mjs +20 -0
  29. package/src/batch/salvage-batch.mjs +691 -0
  30. package/src/batch/worktree.mjs +130 -1
  31. package/src/config/preflight/git-batch.mjs +14 -3
  32. package/src/doctor/duplicate-install.mjs +148 -0
  33. package/src/doctor/pi-cli-resolution.mjs +222 -0
  34. package/src/doctor/run-doctor-checks.mjs +4 -0
  35. package/src/doctor/stale-worktrees.mjs +1 -1
  36. package/src/tasks/packet/parse-prompt.mjs +29 -0
@@ -7,6 +7,10 @@ import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import { execFileSync, spawnSync } from "node:child_process";
9
9
  import { resolveWorktreeSetupHook } from "../config/worktree-setup-hook.mjs";
10
+ import {
11
+ listStaleSpineWorktreeBatchIds,
12
+ resolveInProgressSpineBatchId,
13
+ } from "../doctor/stale-worktrees.mjs";
10
14
 
11
15
  const WORKTREE_SETUP_HOOK_TIMEOUT_MS = 120_000;
12
16
 
@@ -145,13 +149,56 @@ export function repairLaneWorktreeGitMetadata({ projectRoot, worktreePath }) {
145
149
  assertLaneWorktreeGitHealthy(worktreePath);
146
150
  }
147
151
 
152
+ /**
153
+ * @param {string} projectRoot
154
+ * @param {string} batchId
155
+ */
156
+ export function batchWorktreeDir(projectRoot, batchId) {
157
+ return path.join(projectRoot, ".worktrees", `spine-${batchId}`);
158
+ }
159
+
148
160
  /**
149
161
  * @param {string} projectRoot
150
162
  * @param {string} batchId
151
163
  * @param {number} laneNumber
152
164
  */
153
165
  export function laneWorktreePath(projectRoot, batchId, laneNumber = 1) {
154
- return path.join(projectRoot, ".worktrees", `spine-${batchId}`, `lane-${laneNumber}`);
166
+ return path.join(batchWorktreeDir(projectRoot, batchId), `lane-${laneNumber}`);
167
+ }
168
+
169
+ /**
170
+ * @param {unknown} batchState
171
+ */
172
+ export function maxLaneNumberFromBatchState(batchState) {
173
+ const lanes = /** @type {{ lanes?: unknown }} */ (batchState)?.lanes;
174
+ if (!Array.isArray(lanes) || lanes.length === 0) return 1;
175
+ let max = 1;
176
+ for (const lane of lanes) {
177
+ if (!lane || typeof lane !== "object") continue;
178
+ const laneNumber = Number(/** @type {{ laneNumber?: number }} */ (lane).laneNumber);
179
+ if (Number.isFinite(laneNumber) && laneNumber > max) {
180
+ max = laneNumber;
181
+ }
182
+ }
183
+ return max;
184
+ }
185
+
186
+ /**
187
+ * Remove `.worktrees/spine-<batchId>/` when it has no remaining entries.
188
+ *
189
+ * @param {string} projectRoot
190
+ * @param {string} batchId
191
+ * @returns {boolean} true when the batch shell dir was removed
192
+ */
193
+ export function removeEmptyBatchWorktreeDir(projectRoot, batchId) {
194
+ const batchDir = batchWorktreeDir(projectRoot, batchId);
195
+ if (!fs.existsSync(batchDir)) return false;
196
+
197
+ const entries = fs.readdirSync(batchDir);
198
+ if (entries.length > 0) return false;
199
+
200
+ fs.rmdirSync(batchDir);
201
+ return true;
155
202
  }
156
203
 
157
204
  /**
@@ -228,6 +275,7 @@ export function removeLaneWorktrees(projectRoot, batchId, maxLaneNumber) {
228
275
  for (let laneNumber = 1; laneNumber <= maxLaneNumber; laneNumber++) {
229
276
  removeLaneWorktree(projectRoot, batchId, laneNumber);
230
277
  }
278
+ removeEmptyBatchWorktreeDir(projectRoot, batchId);
231
279
  }
232
280
 
233
281
  /**
@@ -298,3 +346,84 @@ export function runWorktreeSetupHook({
298
346
 
299
347
  return { ok: true, durationMs };
300
348
  }
349
+
350
+ /**
351
+ * Scan stale spine batch worktree dirs and empty shells eligible for cleanup.
352
+ *
353
+ * @param {string} projectRoot
354
+ * @param {string|null} [activeBatchId]
355
+ * @returns {{ batchIds: string[], emptyShells: string[], danglingWorktrees: string[] }}
356
+ */
357
+ export function scanStaleWorktrees(projectRoot, activeBatchId = null) {
358
+ const inProgressBatchId =
359
+ activeBatchId === undefined ? resolveInProgressSpineBatchId(projectRoot) : activeBatchId;
360
+ const batchIds = listStaleSpineWorktreeBatchIds(projectRoot, inProgressBatchId);
361
+
362
+ /** @type {string[]} */
363
+ const emptyShells = [];
364
+ for (const batchId of batchIds) {
365
+ const batchDir = batchWorktreeDir(projectRoot, batchId);
366
+ if (!fs.existsSync(batchDir)) continue;
367
+ const entries = fs.readdirSync(batchDir);
368
+ if (entries.length === 0) {
369
+ emptyShells.push(batchId);
370
+ }
371
+ }
372
+
373
+ /** @type {string[]} */
374
+ let danglingWorktrees = [];
375
+ try {
376
+ const pruneOutput = git(projectRoot, ["worktree", "prune", "--dry-run", "--verbose"]);
377
+ danglingWorktrees = pruneOutput
378
+ .split(/\r?\n/)
379
+ .map((line) => line.trim())
380
+ .filter((line) => line.length > 0);
381
+ } catch {
382
+ danglingWorktrees = [];
383
+ }
384
+
385
+ return { batchIds, emptyShells, danglingWorktrees };
386
+ }
387
+
388
+ /**
389
+ * Prune empty batch shells and git worktree admin metadata.
390
+ *
391
+ * @param {string} projectRoot
392
+ * @param {object} [options]
393
+ * @param {boolean} [options.dryRun]
394
+ * @param {string|null} [options.activeBatchId]
395
+ * @returns {{ removedShells: string[], prunedWorktrees: string[] }}
396
+ */
397
+ export function pruneStaleWorktrees(projectRoot, { dryRun = false, activeBatchId = null } = {}) {
398
+ const scan = scanStaleWorktrees(projectRoot, activeBatchId);
399
+ /** @type {string[]} */
400
+ const removedShells = [];
401
+
402
+ for (const batchId of scan.emptyShells) {
403
+ if (dryRun) {
404
+ removedShells.push(batchId);
405
+ continue;
406
+ }
407
+ if (removeEmptyBatchWorktreeDir(projectRoot, batchId)) {
408
+ removedShells.push(batchId);
409
+ }
410
+ }
411
+
412
+ /** @type {string[]} */
413
+ let prunedWorktrees = [];
414
+ if (dryRun) {
415
+ prunedWorktrees = scan.danglingWorktrees;
416
+ } else {
417
+ try {
418
+ const pruneOutput = git(projectRoot, ["worktree", "prune", "--verbose"]);
419
+ prunedWorktrees = pruneOutput
420
+ .split(/\r?\n/)
421
+ .map((line) => line.trim())
422
+ .filter((line) => line.length > 0);
423
+ } catch {
424
+ prunedWorktrees = [];
425
+ }
426
+ }
427
+
428
+ return { removedShells, prunedWorktrees };
429
+ }
@@ -14,19 +14,26 @@ import { METRICS_DEFAULTS } from "../defaults.mjs";
14
14
  const HEALTHY_ACTIVE_PHASES = new Set(["planning", "running", "paused"]);
15
15
  const LIMBO_DIAGNOSES = new Set(["limbo_stale", "completed_manual"]);
16
16
  const PI_SESSION_METADATA_PREFIX = ".pi/";
17
+ const PI_SMART_ROUTER_PREFIX = ".pi-smart-router/";
17
18
 
18
19
  function makeCheck(id, ok, message, extra = {}) {
19
20
  return { id, ok, message, ...extra };
20
21
  }
21
22
 
22
23
  /**
23
- * Pi session metadata under `.pi/` is not project source (issue #81).
24
+ * Pi session metadata under `.pi/` and ephemeral `.pi-smart-router/` WAL dirs
25
+ * are not project source (issues #81, v1.10.1 preflight git-clean).
24
26
  *
25
27
  * @param {string} relPath
26
28
  */
27
29
  export function isPiSessionMetadataPath(relPath) {
28
30
  const normalized = String(relPath).replace(/\\/g, "/").replace(/^\.\/+/, "");
29
- return normalized === ".pi" || normalized.startsWith(PI_SESSION_METADATA_PREFIX);
31
+ return (
32
+ normalized === ".pi" ||
33
+ normalized.startsWith(PI_SESSION_METADATA_PREFIX) ||
34
+ normalized === ".pi-smart-router" ||
35
+ normalized.startsWith(PI_SMART_ROUTER_PREFIX)
36
+ );
30
37
  }
31
38
 
32
39
  /**
@@ -155,7 +162,11 @@ export function checkGitClean(ctx) {
155
162
 
156
163
  if (dirtyPaths.length === 0) {
157
164
  if (allDirtyPaths.length > 0) {
158
- return makeCheck("git-clean", true, "working tree clean (.pi/ session metadata ignored)");
165
+ return makeCheck(
166
+ "git-clean",
167
+ true,
168
+ "working tree clean (pi session metadata ignored)",
169
+ );
159
170
  }
160
171
  return makeCheck("git-clean", true, "working tree clean");
161
172
  }
@@ -0,0 +1,148 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Detect duplicate pi-spine installs (Pi-private vs npm-global) with version drift.
4
+ * Taskplane v0.30.2+ pattern (issue #128 / SP-559).
5
+ */
6
+
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+
10
+ import { resolvePiAgentDir } from "./pi-extension-conflict.mjs";
11
+ import { getNpmGlobalRoot } from "./pi-cli-resolution.mjs";
12
+
13
+ export const PI_SPINE_PACKAGE_NAME = "pi-spine";
14
+
15
+ /**
16
+ * @param {string} [agentDir]
17
+ */
18
+ export function resolvePiPrivateSpineRoot(agentDir = resolvePiAgentDir()) {
19
+ return path.join(agentDir, "npm", "node_modules", PI_SPINE_PACKAGE_NAME);
20
+ }
21
+
22
+ /**
23
+ * @param {typeof import("node:child_process").spawnSync} [spawn]
24
+ */
25
+ export function resolveNpmGlobalSpineRoot(spawn) {
26
+ const npmRoot = getNpmGlobalRoot(spawn);
27
+ if (!npmRoot) return null;
28
+ return path.join(npmRoot, PI_SPINE_PACKAGE_NAME);
29
+ }
30
+
31
+ /**
32
+ * @param {string | null | undefined} packageRoot
33
+ */
34
+ export function readInstalledPackageVersion(packageRoot) {
35
+ if (!packageRoot) return null;
36
+ const packageJsonPath = path.join(packageRoot, "package.json");
37
+ if (!fs.existsSync(packageJsonPath)) return null;
38
+ try {
39
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
40
+ return String(pkg.version ?? "").trim() || null;
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * @param {object} [options]
48
+ * @param {string} [options.agentDir]
49
+ * @param {(p: string) => boolean} [options.exists]
50
+ * @param {typeof import("node:child_process").spawnSync} [options.spawn]
51
+ */
52
+ export function detectDuplicatePiSpineInstall({
53
+ agentDir = resolvePiAgentDir(),
54
+ exists = fs.existsSync,
55
+ spawn,
56
+ } = {}) {
57
+ const piPrivatePath = resolvePiPrivateSpineRoot(agentDir);
58
+ const npmGlobalPath = resolveNpmGlobalSpineRoot(spawn);
59
+
60
+ const piPrivatePresent = exists(piPrivatePath);
61
+ const npmGlobalPresent = npmGlobalPath ? exists(npmGlobalPath) : false;
62
+
63
+ const piPrivateVersion = piPrivatePresent ? readInstalledPackageVersion(piPrivatePath) : null;
64
+ const npmGlobalVersion = npmGlobalPresent ? readInstalledPackageVersion(npmGlobalPath) : null;
65
+
66
+ const bothPresent = piPrivatePresent && npmGlobalPresent;
67
+ const diverged =
68
+ bothPresent &&
69
+ piPrivateVersion != null &&
70
+ npmGlobalVersion != null &&
71
+ piPrivateVersion !== npmGlobalVersion;
72
+
73
+ return {
74
+ piPrivatePath,
75
+ npmGlobalPath,
76
+ piPrivatePresent,
77
+ npmGlobalPresent,
78
+ piPrivateVersion,
79
+ npmGlobalVersion,
80
+ bothPresent,
81
+ diverged,
82
+ };
83
+ }
84
+
85
+ /**
86
+ * Platform-aware remediation when duplicate installs diverge.
87
+ */
88
+ export function formatDuplicateInstallRemediation() {
89
+ const bash = "npm uninstall -g pi-spine # then use: pi install npm:pi-spine";
90
+ if (process.platform === "win32") {
91
+ return `PowerShell: npm uninstall -g pi-spine | Bash: ${bash}`;
92
+ }
93
+ return bash;
94
+ }
95
+
96
+ /**
97
+ * @param {object} [options]
98
+ * @param {string} [options.agentDir]
99
+ * @param {(p: string) => boolean} [options.exists]
100
+ * @param {typeof import("node:child_process").spawnSync} [options.spawn]
101
+ */
102
+ export function buildDuplicateInstallDoctorCheck(options = {}) {
103
+ const assessment = detectDuplicatePiSpineInstall(options);
104
+
105
+ if (!assessment.bothPresent) {
106
+ if (assessment.piPrivatePresent) {
107
+ return {
108
+ label: "pi-spine duplicate install",
109
+ ok: true,
110
+ detail: `Pi-private only (${assessment.piPrivateVersion ?? "unknown"})`,
111
+ };
112
+ }
113
+ if (assessment.npmGlobalPresent) {
114
+ return {
115
+ label: "pi-spine duplicate install",
116
+ ok: true,
117
+ detail: `npm-global only (${assessment.npmGlobalVersion ?? "unknown"})`,
118
+ };
119
+ }
120
+ return {
121
+ label: "pi-spine duplicate install",
122
+ ok: true,
123
+ detail: "no Pi-private or npm-global pi-spine copy detected",
124
+ };
125
+ }
126
+
127
+ if (!assessment.diverged) {
128
+ const version = assessment.piPrivateVersion ?? assessment.npmGlobalVersion ?? "unknown";
129
+ return {
130
+ label: "pi-spine duplicate install",
131
+ ok: true,
132
+ detail: `both copies present, same version v${version}`,
133
+ };
134
+ }
135
+
136
+ const detail = [
137
+ `Pi-private v${assessment.piPrivateVersion} (${assessment.piPrivatePath})`,
138
+ `npm-global v${assessment.npmGlobalVersion} (${assessment.npmGlobalPath})`,
139
+ ].join(" — ");
140
+
141
+ return {
142
+ label: "pi-spine duplicate install (version drift)",
143
+ ok: true,
144
+ warning: true,
145
+ detail,
146
+ suggestedCommand: formatDuplicateInstallRemediation(),
147
+ };
148
+ }
@@ -0,0 +1,222 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Resolve the authoritative Pi CLI entrypoint and compare with PATH `pi`.
4
+ * Mirrors Taskplane path-resolver argv-first strategy (issue #128 / SP-559).
5
+ */
6
+
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { execFileSync, spawnSync } from "node:child_process";
10
+
11
+ /** Pi coding-agent npm scopes — canonical first, legacy second (Pi v0.74+ rename). */
12
+ export const PI_PACKAGE_SCOPES = ["@earendil-works", "@mariozechner"];
13
+
14
+ /** @type {string | null} */
15
+ let cachedNpmGlobalRoot = null;
16
+
17
+ /**
18
+ * @param {typeof spawnSync} [spawn]
19
+ * @returns {string}
20
+ */
21
+ export function getNpmGlobalRoot(spawn = spawnSync) {
22
+ if (cachedNpmGlobalRoot !== null) return cachedNpmGlobalRoot;
23
+ try {
24
+ const result = spawn("npm", ["root", "-g"], {
25
+ encoding: "utf-8",
26
+ stdio: ["ignore", "pipe", "pipe"],
27
+ timeout: 5000,
28
+ shell: process.platform === "win32",
29
+ });
30
+ cachedNpmGlobalRoot = result.stdout?.trim() || "";
31
+ } catch {
32
+ cachedNpmGlobalRoot = "";
33
+ }
34
+ return cachedNpmGlobalRoot;
35
+ }
36
+
37
+ /**
38
+ * Reset module cache (tests only).
39
+ */
40
+ export function resetNpmGlobalRootCache() {
41
+ cachedNpmGlobalRoot = null;
42
+ }
43
+
44
+ /**
45
+ * @param {string} filePath
46
+ * @param {(p: string) => string} [realpathFn]
47
+ */
48
+ function safeRealpath(filePath, realpathFn = fs.realpathSync) {
49
+ try {
50
+ return realpathFn(filePath);
51
+ } catch {
52
+ return path.resolve(filePath);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * @param {(cmd: string) => string | null} [which]
58
+ */
59
+ export function resolvePiOnPath(which = defaultWhich) {
60
+ return which("pi");
61
+ }
62
+
63
+ function defaultWhich(cmd) {
64
+ try {
65
+ const out = execFileSync("which", [cmd], {
66
+ encoding: "utf-8",
67
+ stdio: ["ignore", "pipe", "pipe"],
68
+ });
69
+ const resolved = out.trim().split(/\r?\n/)[0]?.trim();
70
+ return resolved || null;
71
+ } catch {
72
+ return null;
73
+ }
74
+ }
75
+
76
+ /**
77
+ * @param {string} [argv1]
78
+ * @param {(p: string) => boolean} [exists]
79
+ */
80
+ export function resolvePiCliFromArgv(argv1 = process.argv[1], exists = fs.existsSync) {
81
+ const piEntry = String(argv1 ?? "").trim();
82
+ if (piEntry.endsWith("cli.js") && exists(piEntry)) {
83
+ return piEntry;
84
+ }
85
+ return null;
86
+ }
87
+
88
+ /**
89
+ * Collect npm-global and static fallback bases for Pi CLI discovery.
90
+ *
91
+ * @param {NodeJS.ProcessEnv} [env]
92
+ * @param {typeof spawnSync} [spawn]
93
+ */
94
+ export function collectPiCliSearchBases(env = process.env, spawn = spawnSync) {
95
+ const bases = [];
96
+ const npmRoot = getNpmGlobalRoot(spawn);
97
+ if (npmRoot) bases.push(npmRoot);
98
+
99
+ const home = env.HOME || env.USERPROFILE || "";
100
+ if (env.APPDATA) {
101
+ bases.push(path.join(env.APPDATA, "npm", "node_modules"));
102
+ }
103
+ if (home) {
104
+ bases.push(path.join(home, "AppData", "Roaming", "npm", "node_modules"));
105
+ bases.push(path.join(home, ".npm-global", "lib", "node_modules"));
106
+ bases.push(path.join(home, ".pi", "agent", "npm", "node_modules"));
107
+ }
108
+ if (env.NVM_SYMLINK) {
109
+ bases.push(path.join(env.NVM_SYMLINK, "node_modules"));
110
+ }
111
+ if (env.NVM_BIN) {
112
+ bases.push(path.join(env.NVM_BIN, "..", "lib", "node_modules"));
113
+ }
114
+ bases.push(path.join("/usr", "local", "lib", "node_modules"));
115
+ bases.push(path.join("/opt", "homebrew", "lib", "node_modules"));
116
+ return bases;
117
+ }
118
+
119
+ /**
120
+ * @param {object} [options]
121
+ * @param {string} [options.argv1]
122
+ * @param {NodeJS.ProcessEnv} [options.env]
123
+ * @param {(p: string) => boolean} [options.exists]
124
+ * @param {typeof spawnSync} [options.spawn]
125
+ */
126
+ export function resolveAuthoritativePiCliPath({
127
+ argv1 = process.argv[1],
128
+ env = process.env,
129
+ exists = fs.existsSync,
130
+ spawn = spawnSync,
131
+ } = {}) {
132
+ const fromArgv = resolvePiCliFromArgv(argv1, exists);
133
+ if (fromArgv) {
134
+ return { path: fromArgv, source: "argv" };
135
+ }
136
+
137
+ for (const base of collectPiCliSearchBases(env, spawn)) {
138
+ for (const scope of PI_PACKAGE_SCOPES) {
139
+ const candidate = path.join(base, scope, "pi-coding-agent", "dist", "cli.js");
140
+ if (exists(candidate)) {
141
+ return { path: candidate, source: "search" };
142
+ }
143
+ }
144
+ }
145
+
146
+ return { path: null, source: "unresolved" };
147
+ }
148
+
149
+ /**
150
+ * @param {object} [options]
151
+ * @param {string} [options.argv1]
152
+ * @param {NodeJS.ProcessEnv} [options.env]
153
+ * @param {(cmd: string) => string | null} [options.which]
154
+ * @param {(p: string) => boolean} [options.exists]
155
+ * @param {(p: string) => string} [options.realpath]
156
+ * @param {typeof spawnSync} [options.spawn]
157
+ */
158
+ export function buildPiCliResolutionDoctorCheck({
159
+ argv1 = process.argv[1],
160
+ env = process.env,
161
+ which,
162
+ exists = fs.existsSync,
163
+ realpath = fs.realpathSync,
164
+ spawn = spawnSync,
165
+ } = {}) {
166
+ const authoritative = resolveAuthoritativePiCliPath({ argv1, env, exists, spawn });
167
+ const pathPi = resolvePiOnPath(which);
168
+
169
+ if (!authoritative.path && !pathPi) {
170
+ return {
171
+ label: "pi CLI resolution",
172
+ ok: true,
173
+ warning: true,
174
+ detail: "pi not found via argv/search or PATH",
175
+ suggestedCommand: "npm install -g @earendil-works/pi-coding-agent",
176
+ };
177
+ }
178
+
179
+ if (!authoritative.path) {
180
+ return {
181
+ label: "pi CLI resolution",
182
+ ok: true,
183
+ detail: `PATH: ${pathPi} (argv/search unresolved)`,
184
+ };
185
+ }
186
+
187
+ const authResolved = safeRealpath(authoritative.path, realpath);
188
+ const sourceLabel = authoritative.source === "argv" ? "argv" : "search";
189
+
190
+ if (!pathPi) {
191
+ return {
192
+ label: "pi CLI resolution",
193
+ ok: true,
194
+ warning: true,
195
+ detail: `resolved via ${sourceLabel}: ${authoritative.path} (not on PATH)`,
196
+ suggestedCommand:
197
+ process.platform === "win32"
198
+ ? "Add npm global bin to PATH or use npx pi"
199
+ : 'export PATH="$(npm bin -g):$PATH"',
200
+ };
201
+ }
202
+
203
+ const pathResolved = safeRealpath(pathPi, realpath);
204
+ if (pathResolved === authResolved) {
205
+ return {
206
+ label: "pi CLI resolution",
207
+ ok: true,
208
+ detail: `${pathPi} (matches ${sourceLabel} resolution)`,
209
+ };
210
+ }
211
+
212
+ return {
213
+ label: "pi CLI resolution (PATH mismatch)",
214
+ ok: true,
215
+ warning: true,
216
+ detail: `PATH: ${pathPi} — authoritative (${sourceLabel}): ${authoritative.path}`,
217
+ suggestedCommand:
218
+ process.platform === "win32"
219
+ ? "Align PATH with the Pi install npm bin directory"
220
+ : 'export PATH="$(npm bin -g):$PATH" # or use the argv-resolved pi directly',
221
+ };
222
+ }
@@ -33,6 +33,8 @@ import { buildAgentModelIdsDoctorCheck } from "./agent-models.mjs";
33
33
  import { buildPiExtensionConflictDoctorCheck } from "./pi-extension-conflict.mjs";
34
34
  import { buildSupervisorConfigDoctorCheck } from "./supervisor.mjs";
35
35
  import { buildAttachedOrphanRiskDoctorCheck } from "./attached-orphan-risk.mjs";
36
+ import { buildDuplicateInstallDoctorCheck } from "./duplicate-install.mjs";
37
+ import { buildPiCliResolutionDoctorCheck } from "./pi-cli-resolution.mjs";
36
38
  import { CURSOR_RULES_ROOT_REL } from "../config/cursor-rules/discover.mjs";
37
39
  import { RULES_PROFILE_REL_PATH } from "../config/cursor-rules/profile.mjs";
38
40
  import {
@@ -254,6 +256,8 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
254
256
  record("git installed", commandExists("git"), { detail: getVersion("git") });
255
257
  record("git worktree support", gitSupportsWorktrees(), { detail: getVersion("git") });
256
258
  record("pi installed", commandExists("pi"), { detail: getVersion("pi") });
259
+ checks.push(buildPiCliResolutionDoctorCheck());
260
+ checks.push(buildDuplicateInstallDoctorCheck());
257
261
  checks.push(buildPiExtensionConflictDoctorCheck({ projectRoot }));
258
262
  checks.push(buildAttachedOrphanRiskDoctorCheck());
259
263
 
@@ -97,6 +97,6 @@ export function buildStaleWorktreesDoctorCheck({
97
97
  warning: true,
98
98
  detail: `${staleBatchIds.length} leftover batch dir(s): ${preview}${suffix}`,
99
99
  suggestedCommand:
100
- "After spine batch complete/dismiss, lane worktrees auto-clean (lanes.cleanupWorktreesOnComplete). Remove legacy dirs: git worktree remove --force .worktrees/spine-<batchId>/lane-N; rm -rf .worktrees/spine-<batchId>",
100
+ "spine cleanup worktrees --dry-run (then --yes) or remove legacy dirs: git worktree remove --force .worktrees/spine-<batchId>/lane-N; rm -rf .worktrees/spine-<batchId>",
101
101
  };
102
102
  }
@@ -111,9 +111,38 @@ export function validatePrompt(markdown) {
111
111
  errors.push('Size XL is not allowed — split into multiple S/M tasks (see create-spine-tasks skill)');
112
112
  }
113
113
 
114
+ errors.push(...collectDuplicateStepNumberErrors(prompt.steps));
115
+
114
116
  return { ok: errors.length === 0, errors, prompt };
115
117
  }
116
118
 
119
+ /**
120
+ * @param {Array<{ number: number, title: string }>} steps
121
+ * @returns {string[]}
122
+ */
123
+ function collectDuplicateStepNumberErrors(steps) {
124
+ /** @type {Map<number, string[]>} */
125
+ const titlesByNumber = new Map();
126
+
127
+ for (const step of steps) {
128
+ const titles = titlesByNumber.get(step.number) ?? [];
129
+ titles.push(step.title);
130
+ titlesByNumber.set(step.number, titles);
131
+ }
132
+
133
+ /** @type {string[]} */
134
+ const errors = [];
135
+ for (const [number, titles] of [...titlesByNumber.entries()].sort((a, b) => a[0] - b[0])) {
136
+ if (titles.length <= 1) {
137
+ continue;
138
+ }
139
+ const quotedTitles = titles.map((title) => `"${title}"`).join(", ");
140
+ errors.push(`Duplicate step number ${number} in ## Steps: ${quotedTitles}`);
141
+ }
142
+
143
+ return errors;
144
+ }
145
+
117
146
  /**
118
147
  * Parse the `## Contract` Markdown table from PROMPT.md (handoff §4.3).
119
148
  *