pi-spine 1.10.1 → 2.1.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.
- package/bin/spine-cleanup.mjs +89 -0
- package/bin/spine-doctor.mjs +8 -0
- package/bin/spine.mjs +13 -0
- package/package.json +4 -1
- package/skills/create-spine-tasks/SKILL.md +29 -0
- package/skills/create-spine-tasks/references/contract-template.md +11 -0
- package/skills/create-spine-tasks/references/prompt-template.md +15 -20
- package/skills/spine-autonomous-operator/SKILL.md +19 -3
- package/skills/spine-autonomous-operator/references/agent-shell-batch-policy.md +18 -0
- package/skills/spine-orchestrate-waves/SKILL.md +9 -2
- package/skills/spine-orchestrate-waves/references/outer-loop.md +24 -2
- package/skills/spine-release-operator/SKILL.md +25 -2
- package/skills/spine-release-operator/references/post-integrate-regression-gate.md +96 -0
- package/skills/spine-release-operator/references/release-manifest-template.md +7 -3
- package/src/batch/abort.mjs +10 -14
- package/src/batch/diagnosis-merge-failure.mjs +66 -0
- package/src/batch/diagnosis-parent-exit.mjs +125 -0
- package/src/batch/diagnosis.mjs +26 -73
- package/src/batch/engine-lanes/watch.mjs +4 -2
- package/src/batch/heartbeat-subprocess.mjs +214 -0
- package/src/batch/heartbeat.mjs +38 -63
- package/src/batch/lane-dirty-check.mjs +10 -0
- package/src/batch/lifecycle.mjs +1 -18
- package/src/batch/reconcile.mjs +11 -0
- package/src/batch/review.mjs +20 -0
- package/src/batch/worktree.mjs +130 -1
- package/src/config/preflight/git-batch.mjs +14 -3
- package/src/dashboard/public/dashboard.js +6 -2
- package/src/dashboard/snapshot.mjs +85 -11
- package/src/doctor/duplicate-install.mjs +148 -0
- package/src/doctor/pi-cli-resolution.mjs +222 -0
- package/src/doctor/run-doctor-checks.mjs +4 -0
- package/src/doctor/stale-worktrees.mjs +1 -1
- package/src/tasks/packet/parse-prompt.mjs +29 -0
|
@@ -227,8 +227,12 @@ function renderLanes(lanes, laneTableSummary, tailActivity, expandedLaneId) {
|
|
|
227
227
|
tr.dataset.laneId = lane.laneId;
|
|
228
228
|
tr.setAttribute("aria-expanded", lane.laneId === expandedLaneId ? "true" : "false");
|
|
229
229
|
const throughput = lane.throughput ?? {};
|
|
230
|
-
const
|
|
231
|
-
|
|
230
|
+
const isTerminalFailure = lane.activityPhase === "failed";
|
|
231
|
+
// Completed lanes use terminal outcome only; failedCount stays a retry metric.
|
|
232
|
+
const isTaskFailed =
|
|
233
|
+
lane.status === "completed"
|
|
234
|
+
? isTerminalFailure
|
|
235
|
+
: (throughput.failedCount ?? 0) > 0 || isTerminalFailure;
|
|
232
236
|
const isTaskSucceeded = lane.status === "completed" && !isTaskFailed;
|
|
233
237
|
const isTaskRunning = lane.status === "running" && !isTaskFailed;
|
|
234
238
|
if (isTaskFailed) tr.classList.add("task-failed");
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "../batch/journal.mjs";
|
|
18
18
|
import { resolveStallConfig } from "../batch/heartbeat.mjs";
|
|
19
19
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
20
|
+
import { formatElapsedMs } from "./lane-throughput.mjs";
|
|
20
21
|
import {
|
|
21
22
|
deriveLanesThroughput,
|
|
22
23
|
summarizeLaneThroughput,
|
|
@@ -39,6 +40,75 @@ import {
|
|
|
39
40
|
/** Last N journal events included in dashboard snapshot tail (not full journal per client). */
|
|
40
41
|
export const DASHBOARD_JOURNAL_TAIL_LIMIT = 20;
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @param {number} laneNumber
|
|
45
|
+
* @param {object[]} journalEvents
|
|
46
|
+
*/
|
|
47
|
+
export function resolveSubprocessHeartbeatMeta(laneNumber, journalEvents) {
|
|
48
|
+
for (let index = journalEvents.length - 1; index >= 0; index -= 1) {
|
|
49
|
+
const event = journalEvents[index];
|
|
50
|
+
if (event.type !== "lane.heartbeat") continue;
|
|
51
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
52
|
+
if (payload.laneNumber != null && payload.laneNumber !== laneNumber) continue;
|
|
53
|
+
if (event.laneId && event.laneId !== `lane-${laneNumber}`) continue;
|
|
54
|
+
return {
|
|
55
|
+
workerPhase: typeof payload.workerPhase === "string" ? payload.workerPhase : null,
|
|
56
|
+
subprocessCommand:
|
|
57
|
+
typeof payload.subprocessCommand === "string" ? payload.subprocessCommand : null,
|
|
58
|
+
subprocessStartedAtMs:
|
|
59
|
+
payload.subprocessStartedAtMs != null ? Number(payload.subprocessStartedAtMs) : null,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return { workerPhase: null, subprocessCommand: null, subprocessStartedAtMs: null };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {object} params
|
|
67
|
+
* @param {string} params.subprocessCommand
|
|
68
|
+
* @param {number | null} [params.subprocessStartedAtMs]
|
|
69
|
+
* @param {number} [params.now]
|
|
70
|
+
*/
|
|
71
|
+
export function formatSubprocessHeartbeatDisplay({
|
|
72
|
+
subprocessCommand,
|
|
73
|
+
subprocessStartedAtMs,
|
|
74
|
+
now = Date.now(),
|
|
75
|
+
}) {
|
|
76
|
+
const elapsedMs =
|
|
77
|
+
subprocessStartedAtMs != null && Number.isFinite(subprocessStartedAtMs)
|
|
78
|
+
? Math.max(0, now - subprocessStartedAtMs)
|
|
79
|
+
: null;
|
|
80
|
+
const elapsed = elapsedMs != null ? formatElapsedMs(elapsedMs) : null;
|
|
81
|
+
if (elapsed && elapsed !== "—") {
|
|
82
|
+
return `running ${subprocessCommand} (${elapsed})`;
|
|
83
|
+
}
|
|
84
|
+
return `running ${subprocessCommand}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {object[]} lanes
|
|
89
|
+
* @param {object[]} journalEvents
|
|
90
|
+
* @param {number} [now]
|
|
91
|
+
*/
|
|
92
|
+
export function enrichLaneRowsWithSubprocessHeartbeat(lanes, journalEvents, now = Date.now()) {
|
|
93
|
+
return (lanes ?? []).map((lane) => {
|
|
94
|
+
const subprocessMeta = resolveSubprocessHeartbeatMeta(lane.laneNumber, journalEvents);
|
|
95
|
+
if (subprocessMeta.workerPhase !== "subprocess" || !subprocessMeta.subprocessCommand) {
|
|
96
|
+
return lane;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
...lane,
|
|
100
|
+
workerPhase: subprocessMeta.workerPhase,
|
|
101
|
+
subprocessCommand: subprocessMeta.subprocessCommand,
|
|
102
|
+
subprocessStartedAtMs: subprocessMeta.subprocessStartedAtMs,
|
|
103
|
+
heartbeatDisplay: formatSubprocessHeartbeatDisplay({
|
|
104
|
+
subprocessCommand: subprocessMeta.subprocessCommand,
|
|
105
|
+
subprocessStartedAtMs: subprocessMeta.subprocessStartedAtMs,
|
|
106
|
+
now,
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
42
112
|
/**
|
|
43
113
|
* @param {string} projectRoot
|
|
44
114
|
*/
|
|
@@ -105,19 +175,23 @@ export function buildDashboardSnapshot(projectRoot) {
|
|
|
105
175
|
});
|
|
106
176
|
}
|
|
107
177
|
|
|
108
|
-
const lanes =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
178
|
+
const lanes = enrichLaneRowsWithSubprocessHeartbeat(
|
|
179
|
+
buildLaneRows({
|
|
180
|
+
lanes: batch?.lanes ?? [],
|
|
181
|
+
classifiedTasks,
|
|
182
|
+
stallConfig,
|
|
183
|
+
currentWaveTaskIds,
|
|
184
|
+
journalTail,
|
|
185
|
+
journalEvents,
|
|
186
|
+
metricsLines,
|
|
187
|
+
projectRoot,
|
|
188
|
+
batchId: reconciliation.batchId,
|
|
189
|
+
now,
|
|
190
|
+
diagnosis: reconciliation.diagnosis,
|
|
191
|
+
}),
|
|
114
192
|
journalEvents,
|
|
115
|
-
metricsLines,
|
|
116
|
-
projectRoot,
|
|
117
|
-
batchId: reconciliation.batchId,
|
|
118
193
|
now,
|
|
119
|
-
|
|
120
|
-
});
|
|
194
|
+
);
|
|
121
195
|
const laneThroughputSummary = summarizeLaneThroughput(
|
|
122
196
|
deriveLanesThroughput({
|
|
123
197
|
lanes: batch?.lanes ?? [],
|
|
@@ -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
|
-
"
|
|
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
|
*
|