pi-spine 1.0.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/LICENSE +21 -0
- package/README.md +563 -0
- package/bin/get-version.mjs +35 -0
- package/bin/spine-batch.mjs +425 -0
- package/bin/spine-cli/batch.mjs +47 -0
- package/bin/spine-cli/gate.mjs +10 -0
- package/bin/spine-cli/integrate.mjs +10 -0
- package/bin/spine-cli/plan.mjs +12 -0
- package/bin/spine-cli/shared.mjs +73 -0
- package/bin/spine-cli/status.mjs +18 -0
- package/bin/spine-cli/verify.mjs +199 -0
- package/bin/spine-config.mjs +212 -0
- package/bin/spine-dashboard.mjs +178 -0
- package/bin/spine-deps.mjs +69 -0
- package/bin/spine-doctor.mjs +468 -0
- package/bin/spine-gate.mjs +137 -0
- package/bin/spine-init.mjs +398 -0
- package/bin/spine-integrate.mjs +77 -0
- package/bin/spine-journal.mjs +198 -0
- package/bin/spine-migrate-from-taskplane.mjs +136 -0
- package/bin/spine-plan.mjs +83 -0
- package/bin/spine-preflight.mjs +700 -0
- package/bin/spine-report-progress.d.mts +28 -0
- package/bin/spine-report-progress.mjs +126 -0
- package/bin/spine-review-step.d.mts +24 -0
- package/bin/spine-review-step.mjs +124 -0
- package/bin/spine-rules.mjs +35 -0
- package/bin/spine-settings.mjs +186 -0
- package/bin/spine-state.mjs +110 -0
- package/bin/spine-status.mjs +79 -0
- package/bin/spine-tasks.mjs +293 -0
- package/bin/spine-worker-runner.mjs +314 -0
- package/bin/spine.mjs +404 -0
- package/extensions/spine/settings-slash.ts +20 -0
- package/extensions/spine/slash-commands.ts +806 -0
- package/extensions/spine/worker-tools.ts +279 -0
- package/extensions/spine-orchestrator.ts +12 -0
- package/package.json +72 -0
- package/skills/.gitkeep +0 -0
- package/skills/create-spine-tasks/SKILL.md +375 -0
- package/skills/create-spine-tasks/references/context-template.md +25 -0
- package/skills/create-spine-tasks/references/contract-template.md +98 -0
- package/skills/create-spine-tasks/references/explore-template.md +63 -0
- package/skills/create-spine-tasks/references/prompt-template.md +276 -0
- package/src/batch/abort.mjs +272 -0
- package/src/batch/agent-session-worker.mjs +297 -0
- package/src/batch/batch-state-io.mjs +53 -0
- package/src/batch/contract-verify.mjs +310 -0
- package/src/batch/detached-start.mjs +778 -0
- package/src/batch/diagnosis.mjs +378 -0
- package/src/batch/engine-lanes/merge.mjs +632 -0
- package/src/batch/engine-lanes/queue.mjs +208 -0
- package/src/batch/engine-lanes/review.mjs +970 -0
- package/src/batch/engine-lanes.mjs +388 -0
- package/src/batch/engine-scope.mjs +251 -0
- package/src/batch/engine.mjs +445 -0
- package/src/batch/evidence-command.mjs +157 -0
- package/src/batch/evidence.mjs +203 -0
- package/src/batch/gate.mjs +359 -0
- package/src/batch/git-commit-env.mjs +46 -0
- package/src/batch/git-exec.mjs +26 -0
- package/src/batch/heartbeat.mjs +430 -0
- package/src/batch/integrate.mjs +414 -0
- package/src/batch/journal-rebuild.mjs +388 -0
- package/src/batch/journal.mjs +373 -0
- package/src/batch/lane-commit.mjs +153 -0
- package/src/batch/lifecycle.mjs +364 -0
- package/src/batch/metrics.mjs +265 -0
- package/src/batch/orphan-detect.mjs +210 -0
- package/src/batch/post-merge-limbo.mjs +80 -0
- package/src/batch/postmortem.mjs +296 -0
- package/src/batch/readers/spine-state.mjs +95 -0
- package/src/batch/readers/taskplane-state.mjs +136 -0
- package/src/batch/reconcile.mjs +729 -0
- package/src/batch/resume-common.mjs +104 -0
- package/src/batch/resume-engine.mjs +66 -0
- package/src/batch/resume-multi-lanes.mjs +479 -0
- package/src/batch/resume-multi-validate.mjs +187 -0
- package/src/batch/resume-multi.mjs +254 -0
- package/src/batch/resume.mjs +475 -0
- package/src/batch/retry.mjs +257 -0
- package/src/batch/review-scope.mjs +136 -0
- package/src/batch/review.mjs +1045 -0
- package/src/batch/salvage.mjs +332 -0
- package/src/batch/state.mjs +680 -0
- package/src/batch/task-stall-budget.mjs +88 -0
- package/src/batch/worker-host.mjs +683 -0
- package/src/batch/worker-output.mjs +253 -0
- package/src/batch/worker-prompt.mjs +84 -0
- package/src/batch/worktree.mjs +290 -0
- package/src/cli/deps.mjs +141 -0
- package/src/cli/handoff.mjs +364 -0
- package/src/cli/rules.mjs +429 -0
- package/src/cli/settings-set.mjs +171 -0
- package/src/cli/settings-show.mjs +140 -0
- package/src/cli/settings-slash.mjs +107 -0
- package/src/config/contract.mjs +56 -0
- package/src/config/cursor-rules/discover.mjs +416 -0
- package/src/config/cursor-rules/index.mjs +39 -0
- package/src/config/cursor-rules/match-globs.mjs +132 -0
- package/src/config/cursor-rules/parse-frontmatter.mjs +222 -0
- package/src/config/cursor-rules/priority.mjs +26 -0
- package/src/config/cursor-rules/profile.mjs +403 -0
- package/src/config/cursor-rules/select.mjs +259 -0
- package/src/config/defaults.mjs +36 -0
- package/src/config/env-overrides.mjs +207 -0
- package/src/config/merge-defaults.mjs +47 -0
- package/src/config/pi-spine-root.mjs +93 -0
- package/src/config/reviewer-context.mjs +243 -0
- package/src/config/settings-fields.mjs +265 -0
- package/src/config/worker-backend.mjs +116 -0
- package/src/config/worker-context.mjs +402 -0
- package/src/config/worker-launch-script.mjs +130 -0
- package/src/config/worktree-setup-hook.mjs +122 -0
- package/src/dashboard/public/dashboard.css +77 -0
- package/src/dashboard/public/dashboard.js +349 -0
- package/src/dashboard/public/index.html +80 -0
- package/src/dashboard/server.mjs +155 -0
- package/src/dashboard/snapshot.mjs +414 -0
- package/src/dashboard/sse.mjs +15 -0
- package/src/dashboard/view.mjs +292 -0
- package/src/doctor/agent-model-inherit.mjs +101 -0
- package/src/doctor/batch-size-guidance.mjs +72 -0
- package/src/doctor/coexistence.mjs +312 -0
- package/src/doctor/rules-manifest.mjs +133 -0
- package/src/doctor/stale-path.mjs +156 -0
- package/src/doctor/stall-config.mjs +108 -0
- package/src/doctor/suggest-max-parallel.mjs +53 -0
- package/src/doctor/task-packet-size.mjs +110 -0
- package/src/doctor/worktree-health.mjs +71 -0
- package/src/migrate/taskplane-config.mjs +116 -0
- package/src/planner/cycles.mjs +63 -0
- package/src/planner/format-plan.mjs +132 -0
- package/src/planner/graph.mjs +99 -0
- package/src/planner/index.mjs +125 -0
- package/src/planner/lanes.mjs +111 -0
- package/src/planner/pending.mjs +39 -0
- package/src/planner/scope.mjs +142 -0
- package/src/process/liveness.mjs +21 -0
- package/src/tasks/packet/discover.mjs +40 -0
- package/src/tasks/packet/index.mjs +81 -0
- package/src/tasks/packet/merge-deps.mjs +79 -0
- package/src/tasks/packet/parse-prompt.mjs +445 -0
- package/src/tasks/packet/parse-status.mjs +118 -0
- package/src/tasks/packet/validate-contract.mjs +115 -0
- package/src/tasks/packet/validate-prompt.mjs +99 -0
- package/src/worker-tools/report-progress.d.mts +18 -0
- package/src/worker-tools/report-progress.mjs +59 -0
- package/src/worker-tools/request-gate.d.mts +17 -0
- package/src/worker-tools/request-gate.mjs +54 -0
- package/templates/agents/reviewer.md +123 -0
- package/templates/agents/supervisor.md +59 -0
- package/templates/agents/worker.md +122 -0
- package/templates/rules-profile.json +27 -0
- package/templates/spine-config.json +64 -0
- package/templates/tasks/CONTEXT.md +30 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* spine doctor — installation and project configuration checks (SP-093 manifest warnings).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
8
|
+
|
|
9
|
+
import { commandExists, getVersion } from "./get-version.mjs";
|
|
10
|
+
import { loadSpineConfig } from "./spine-config.mjs";
|
|
11
|
+
import { SPINE_GITIGNORE_ENTRIES } from "./spine-init.mjs";
|
|
12
|
+
import {
|
|
13
|
+
c,
|
|
14
|
+
FAIL,
|
|
15
|
+
getMinPiVersion,
|
|
16
|
+
getPackageVersion,
|
|
17
|
+
isCliEntrypoint,
|
|
18
|
+
OK,
|
|
19
|
+
PACKAGE_ROOT,
|
|
20
|
+
WARN,
|
|
21
|
+
} from "./spine-cli/shared.mjs";
|
|
22
|
+
import {
|
|
23
|
+
buildMaxParallelDoctorCheck,
|
|
24
|
+
detectCpuCount,
|
|
25
|
+
} from "../src/doctor/suggest-max-parallel.mjs";
|
|
26
|
+
import { buildStalePathDoctorCheck } from "../src/doctor/stale-path.mjs";
|
|
27
|
+
import { buildCoexistenceDoctorCheck } from "../src/doctor/coexistence.mjs";
|
|
28
|
+
import { buildTaskPacketSizeDoctorCheck } from "../src/doctor/task-packet-size.mjs";
|
|
29
|
+
import {
|
|
30
|
+
buildPiWorkerTimeoutDoctorCheck,
|
|
31
|
+
buildStallConfigDoctorCheck,
|
|
32
|
+
} from "../src/doctor/stall-config.mjs";
|
|
33
|
+
import { buildRulesManifestDoctorCheck } from "../src/doctor/rules-manifest.mjs";
|
|
34
|
+
import { buildWorktreeHealthDoctorCheck } from "../src/doctor/worktree-health.mjs";
|
|
35
|
+
import { buildWorkerBackendDoctorCheck } from "../src/config/worker-backend.mjs";
|
|
36
|
+
import { buildAgentModelInheritDoctorCheck } from "../src/doctor/agent-model-inherit.mjs";
|
|
37
|
+
import { CURSOR_RULES_ROOT_REL } from "../src/config/cursor-rules/discover.mjs";
|
|
38
|
+
import { RULES_PROFILE_REL_PATH } from "../src/config/cursor-rules/profile.mjs";
|
|
39
|
+
import {
|
|
40
|
+
formatConfigSourceDetail,
|
|
41
|
+
resolveTasksRootPath,
|
|
42
|
+
} from "../src/config/env-overrides.mjs";
|
|
43
|
+
|
|
44
|
+
const MIN_NODE_MAJOR = 22;
|
|
45
|
+
const nodeMajor = parseInt(process.versions.node.split(".")[0], 10);
|
|
46
|
+
|
|
47
|
+
const SPINE_CLI_ENTRY = path.join(PACKAGE_ROOT, "bin", "spine.mjs");
|
|
48
|
+
|
|
49
|
+
const REQUIRED_AGENT_FILES = ["worker.md", "reviewer.md", "supervisor.md"];
|
|
50
|
+
|
|
51
|
+
function parseSemver(versionText) {
|
|
52
|
+
const match = String(versionText ?? "")
|
|
53
|
+
.trim()
|
|
54
|
+
.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
55
|
+
if (!match) return null;
|
|
56
|
+
return {
|
|
57
|
+
major: Number(match[1]),
|
|
58
|
+
minor: Number(match[2]),
|
|
59
|
+
patch: Number(match[3]),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function compareSemver(a, b) {
|
|
64
|
+
if (!a || !b) return null;
|
|
65
|
+
if (a.major !== b.major) return a.major - b.major;
|
|
66
|
+
if (a.minor !== b.minor) return a.minor - b.minor;
|
|
67
|
+
return a.patch - b.patch;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isInsideGitRepo(dir) {
|
|
71
|
+
try {
|
|
72
|
+
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
73
|
+
cwd: dir,
|
|
74
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
75
|
+
timeout: 5000,
|
|
76
|
+
});
|
|
77
|
+
return true;
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function gitSupportsWorktrees() {
|
|
84
|
+
try {
|
|
85
|
+
execFileSync("git", ["worktree", "--help"], {
|
|
86
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
87
|
+
timeout: 5000,
|
|
88
|
+
});
|
|
89
|
+
return true;
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function parsePiListModelsOutput(output) {
|
|
96
|
+
const lines = output.split(/\r?\n/).filter(Boolean);
|
|
97
|
+
let providerCol = 0;
|
|
98
|
+
let modelCol = 1;
|
|
99
|
+
let headerSeen = false;
|
|
100
|
+
|
|
101
|
+
for (const line of lines) {
|
|
102
|
+
const trimmed = line.trim();
|
|
103
|
+
if (!headerSeen && /^provider\b/i.test(trimmed)) {
|
|
104
|
+
headerSeen = true;
|
|
105
|
+
const lowerHeader = trimmed.toLowerCase().split(/\s+/);
|
|
106
|
+
const providerIdx = lowerHeader.indexOf("provider");
|
|
107
|
+
const modelIdx = lowerHeader.indexOf("model");
|
|
108
|
+
if (providerIdx >= 0) providerCol = providerIdx;
|
|
109
|
+
if (modelIdx >= 0) modelCol = modelIdx;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const parts = trimmed.split(/\s+/);
|
|
114
|
+
const provider = String(parts[providerCol] ?? parts[0] ?? "").trim();
|
|
115
|
+
const id = String(parts[modelCol] ?? parts[1] ?? "").trim();
|
|
116
|
+
if (!provider || !id) continue;
|
|
117
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(provider)) continue;
|
|
118
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(id)) continue;
|
|
119
|
+
return { provider, id };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function checkModelProvider() {
|
|
126
|
+
if (!commandExists("pi")) {
|
|
127
|
+
return { ok: false, detail: "pi not installed", suggestedCommand: "https://pi.dev" };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const result = spawnSync("pi", ["--list-models"], {
|
|
132
|
+
encoding: "utf-8",
|
|
133
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
134
|
+
timeout: 30_000,
|
|
135
|
+
});
|
|
136
|
+
if (result.error) throw result.error;
|
|
137
|
+
const output = `${result.stdout ?? ""}
|
|
138
|
+
${result.stderr ?? ""}`.trim();
|
|
139
|
+
const model = parsePiListModelsOutput(output);
|
|
140
|
+
if (!model) {
|
|
141
|
+
return {
|
|
142
|
+
ok: false,
|
|
143
|
+
detail: "no models available",
|
|
144
|
+
suggestedCommand: "pi login",
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
ok: true,
|
|
149
|
+
detail: `${model.provider}/${model.id}`,
|
|
150
|
+
};
|
|
151
|
+
} catch (err) {
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
detail: err.message,
|
|
155
|
+
suggestedCommand: "pi login",
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function resolveTasksRoot(projectRoot, configResult) {
|
|
161
|
+
if (!configResult.config) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return resolveTasksRootPath(projectRoot, configResult.config);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isTestingCommandEmpty(command) {
|
|
168
|
+
return !command || String(command).trim() === "";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Warn when evidence gates expect commands that are missing (SP-112).
|
|
173
|
+
*
|
|
174
|
+
* @param {object} [config]
|
|
175
|
+
* @returns {Array<{ label: string, ok: boolean, warning?: boolean, detail: string, suggestedCommand?: string }>}
|
|
176
|
+
*/
|
|
177
|
+
export function buildTestingEvidenceDoctorChecks(config = {}) {
|
|
178
|
+
const gates = config.gates ?? {};
|
|
179
|
+
const testing = config.testing ?? {};
|
|
180
|
+
const checks = [];
|
|
181
|
+
|
|
182
|
+
if (gates.collectBuildEvidence === true && isTestingCommandEmpty(testing.build)) {
|
|
183
|
+
checks.push({
|
|
184
|
+
label: "testing.build (evidence gate)",
|
|
185
|
+
ok: true,
|
|
186
|
+
warning: true,
|
|
187
|
+
detail: "collectBuildEvidence enabled but testing.build is empty — integrate evidence will skip build proof",
|
|
188
|
+
suggestedCommand: "spine settings set testing.build \"npm run typecheck\"",
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (gates.collectTestEvidence !== false && isTestingCommandEmpty(testing.test)) {
|
|
193
|
+
checks.push({
|
|
194
|
+
label: "testing.test (evidence gate)",
|
|
195
|
+
ok: true,
|
|
196
|
+
warning: true,
|
|
197
|
+
detail: "collectTestEvidence enabled but testing.test is empty — integrate evidence will skip test proof",
|
|
198
|
+
suggestedCommand: "spine settings set testing.test \"npm test\"",
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return checks;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
206
|
+
const checks = [];
|
|
207
|
+
let issueCount = 0;
|
|
208
|
+
|
|
209
|
+
const record = (label, ok, extra = {}) => {
|
|
210
|
+
checks.push({ label, ok, ...extra });
|
|
211
|
+
if (!ok) issueCount++;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
record("Node.js >= 22.0.0", nodeMajor >= MIN_NODE_MAJOR, {
|
|
215
|
+
detail: `v${process.versions.node}`,
|
|
216
|
+
});
|
|
217
|
+
record("git installed", commandExists("git"), { detail: getVersion("git") });
|
|
218
|
+
record("git worktree support", gitSupportsWorktrees(), { detail: getVersion("git") });
|
|
219
|
+
record("pi installed", commandExists("pi"), { detail: getVersion("pi") });
|
|
220
|
+
|
|
221
|
+
const piVersionText = getVersion("pi");
|
|
222
|
+
const minPiVersion = getMinPiVersion();
|
|
223
|
+
if (piVersionText && minPiVersion) {
|
|
224
|
+
const current = parseSemver(piVersionText);
|
|
225
|
+
const minimum = parseSemver(minPiVersion);
|
|
226
|
+
const cmp = compareSemver(current, minimum);
|
|
227
|
+
if (cmp === null) {
|
|
228
|
+
checks.push({
|
|
229
|
+
label: "pi version supported",
|
|
230
|
+
ok: true,
|
|
231
|
+
warning: true,
|
|
232
|
+
detail: `could not parse pi version (${piVersionText})`,
|
|
233
|
+
});
|
|
234
|
+
} else if (cmp < 0) {
|
|
235
|
+
checks.push({
|
|
236
|
+
label: "pi version supported",
|
|
237
|
+
ok: true,
|
|
238
|
+
warning: true,
|
|
239
|
+
detail: `${piVersionText} is below supported minimum ${minPiVersion}`,
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
checks.push({
|
|
243
|
+
label: "pi version supported",
|
|
244
|
+
ok: true,
|
|
245
|
+
detail: `>= ${minPiVersion}`,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const pkgVersion = getPackageVersion();
|
|
251
|
+
const isProjectLocal = PACKAGE_ROOT.includes(".pi");
|
|
252
|
+
const installType = isProjectLocal ? "project-local" : "development";
|
|
253
|
+
checks.push({
|
|
254
|
+
label: "pi-spine package",
|
|
255
|
+
ok: true,
|
|
256
|
+
detail: `v${pkgVersion}, ${installType}`,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
checks.push(
|
|
260
|
+
buildStalePathDoctorCheck({
|
|
261
|
+
packageRoot: PACKAGE_ROOT,
|
|
262
|
+
runningSpinePath: SPINE_CLI_ENTRY,
|
|
263
|
+
}),
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const coexistenceCheck = buildCoexistenceDoctorCheck({ projectRoot });
|
|
267
|
+
checks.push(coexistenceCheck);
|
|
268
|
+
if (!coexistenceCheck.ok) issueCount++;
|
|
269
|
+
|
|
270
|
+
record("git repository detected", isInsideGitRepo(projectRoot));
|
|
271
|
+
|
|
272
|
+
const modelCheck = checkModelProvider();
|
|
273
|
+
record("model provider configured", modelCheck.ok, {
|
|
274
|
+
detail: modelCheck.detail,
|
|
275
|
+
suggestedCommand: modelCheck.suggestedCommand,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
279
|
+
if (configResult.error) {
|
|
280
|
+
record(".spine/spine-config.json valid", false, {
|
|
281
|
+
detail: configResult.error.message,
|
|
282
|
+
code: configResult.error.code,
|
|
283
|
+
suggestedCommand: configResult.error.suggestedCommand,
|
|
284
|
+
});
|
|
285
|
+
} else {
|
|
286
|
+
const tasksRootDetail = formatConfigSourceDetail(
|
|
287
|
+
configResult.sources,
|
|
288
|
+
configResult.envVars,
|
|
289
|
+
"paths.tasksRoot",
|
|
290
|
+
configResult.config.paths?.tasksRoot,
|
|
291
|
+
);
|
|
292
|
+
const maxParallelDetail = formatConfigSourceDetail(
|
|
293
|
+
configResult.sources,
|
|
294
|
+
configResult.envVars,
|
|
295
|
+
"lanes.maxParallel",
|
|
296
|
+
configResult.config.lanes?.maxParallel,
|
|
297
|
+
);
|
|
298
|
+
record(".spine/spine-config.json valid", true, {
|
|
299
|
+
detail: `project: ${configResult.config.project.name}`,
|
|
300
|
+
});
|
|
301
|
+
checks.push({
|
|
302
|
+
label: "paths.tasksRoot (effective)",
|
|
303
|
+
ok: true,
|
|
304
|
+
detail: tasksRootDetail,
|
|
305
|
+
});
|
|
306
|
+
checks.push({
|
|
307
|
+
label: "lanes.maxParallel (effective)",
|
|
308
|
+
ok: true,
|
|
309
|
+
detail: maxParallelDetail,
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
const configuredMaxParallel = configResult.config.lanes?.maxParallel ?? 3;
|
|
313
|
+
checks.push(
|
|
314
|
+
buildMaxParallelDoctorCheck({
|
|
315
|
+
configured: configuredMaxParallel,
|
|
316
|
+
cpuCount: detectCpuCount(),
|
|
317
|
+
}),
|
|
318
|
+
);
|
|
319
|
+
checks.push(buildStallConfigDoctorCheck({ config: configResult.config }));
|
|
320
|
+
checks.push(buildPiWorkerTimeoutDoctorCheck({ config: configResult.config }));
|
|
321
|
+
checks.push(buildAgentModelInheritDoctorCheck({
|
|
322
|
+
config: configResult.config,
|
|
323
|
+
projectRoot,
|
|
324
|
+
}));
|
|
325
|
+
const worktreeHealthCheck = buildWorktreeHealthDoctorCheck({
|
|
326
|
+
projectRoot,
|
|
327
|
+
config: configResult.config,
|
|
328
|
+
});
|
|
329
|
+
checks.push(worktreeHealthCheck);
|
|
330
|
+
if (!worktreeHealthCheck.ok) issueCount++;
|
|
331
|
+
const workerBackendCheck = buildWorkerBackendDoctorCheck(configResult.config);
|
|
332
|
+
checks.push(workerBackendCheck);
|
|
333
|
+
if (!workerBackendCheck.ok) issueCount++;
|
|
334
|
+
for (const testingCheck of buildTestingEvidenceDoctorChecks(configResult.config)) {
|
|
335
|
+
checks.push(testingCheck);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
for (const agentFile of REQUIRED_AGENT_FILES) {
|
|
340
|
+
const relPath = `.spine/agents/${agentFile}`;
|
|
341
|
+
record(`${relPath} exists`, fs.existsSync(path.join(projectRoot, relPath)), {
|
|
342
|
+
suggestedCommand: "spine init",
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
|
|
347
|
+
const metricsPath = path.join(
|
|
348
|
+
projectRoot,
|
|
349
|
+
configResult.config?.metrics?.path ?? ".spine/run-metrics.jsonl",
|
|
350
|
+
);
|
|
351
|
+
if (fs.existsSync(metricsPath)) {
|
|
352
|
+
try {
|
|
353
|
+
const lines = fs
|
|
354
|
+
.readFileSync(metricsPath, "utf-8")
|
|
355
|
+
.trim()
|
|
356
|
+
.split("\n")
|
|
357
|
+
.filter(Boolean);
|
|
358
|
+
checks.push({
|
|
359
|
+
label: "run metrics available",
|
|
360
|
+
ok: true,
|
|
361
|
+
detail: `${lines.length} record(s) in ${path.relative(projectRoot, metricsPath)}`,
|
|
362
|
+
suggestedCommand: "spine metrics show",
|
|
363
|
+
});
|
|
364
|
+
} catch {
|
|
365
|
+
checks.push({
|
|
366
|
+
label: "run metrics available",
|
|
367
|
+
ok: true,
|
|
368
|
+
warning: true,
|
|
369
|
+
detail: `present but unreadable: ${path.relative(projectRoot, metricsPath)}`,
|
|
370
|
+
suggestedCommand: "spine metrics show",
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (tasksRootPath) {
|
|
376
|
+
record("tasks root exists", fs.existsSync(tasksRootPath), {
|
|
377
|
+
detail: path.relative(projectRoot, tasksRootPath),
|
|
378
|
+
suggestedCommand: `mkdir -p ${path.relative(projectRoot, tasksRootPath)}`,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
const contextPath = path.join(tasksRootPath, "CONTEXT.md");
|
|
382
|
+
checks.push({
|
|
383
|
+
label: "CONTEXT.md exists",
|
|
384
|
+
ok: true,
|
|
385
|
+
warning: !fs.existsSync(contextPath),
|
|
386
|
+
optional: true,
|
|
387
|
+
detail: fs.existsSync(contextPath) ? "present" : "missing (optional)",
|
|
388
|
+
});
|
|
389
|
+
checks.push(buildTaskPacketSizeDoctorCheck({ tasksRoot: tasksRootPath }));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (isInsideGitRepo(projectRoot)) {
|
|
393
|
+
const gitignorePath = path.join(projectRoot, ".gitignore");
|
|
394
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
395
|
+
checks.push({
|
|
396
|
+
label: ".gitignore has spine runtime entries",
|
|
397
|
+
ok: true,
|
|
398
|
+
warning: true,
|
|
399
|
+
detail: ".gitignore missing",
|
|
400
|
+
suggestedCommand: "spine init",
|
|
401
|
+
});
|
|
402
|
+
} else {
|
|
403
|
+
const content = fs.readFileSync(gitignorePath, "utf-8");
|
|
404
|
+
const existingLines = new Set(content.split(/\r?\n/).map((line) => line.trim()));
|
|
405
|
+
const missing = SPINE_GITIGNORE_ENTRIES.filter((entry) => !existingLines.has(entry));
|
|
406
|
+
checks.push({
|
|
407
|
+
label: ".gitignore has spine runtime entries",
|
|
408
|
+
ok: true,
|
|
409
|
+
warning: missing.length > 0,
|
|
410
|
+
detail:
|
|
411
|
+
missing.length === 0
|
|
412
|
+
? "complete"
|
|
413
|
+
: `missing ${missing.length} entr${missing.length === 1 ? "y" : "ies"}`,
|
|
414
|
+
suggestedCommand: missing.length > 0 ? "spine init" : undefined,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const rulesRootPath = path.join(projectRoot, CURSOR_RULES_ROOT_REL);
|
|
420
|
+
const rulesProfilePath = path.join(projectRoot, RULES_PROFILE_REL_PATH);
|
|
421
|
+
if (fs.existsSync(rulesRootPath) || fs.existsSync(rulesProfilePath)) {
|
|
422
|
+
checks.push(buildRulesManifestDoctorCheck(projectRoot));
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return {
|
|
426
|
+
ok: issueCount === 0,
|
|
427
|
+
issueCount,
|
|
428
|
+
checks,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function cmdDoctor() {
|
|
433
|
+
const projectRoot = process.cwd();
|
|
434
|
+
const result = runDoctorChecks(projectRoot);
|
|
435
|
+
|
|
436
|
+
console.log(`\n${c.bold}pi-spine Doctor${c.reset}\n`);
|
|
437
|
+
|
|
438
|
+
for (const check of result.checks) {
|
|
439
|
+
if (check.warning) {
|
|
440
|
+
console.log(` ${WARN} ${check.label} ${c.dim}(${check.detail})${c.reset}`);
|
|
441
|
+
if (check.suggestedCommand) {
|
|
442
|
+
console.log(` ${c.dim}→ Run: ${check.suggestedCommand}${c.reset}`);
|
|
443
|
+
}
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const info = check.detail ? ` ${c.dim}(${check.detail})${c.reset}` : "";
|
|
448
|
+
console.log(` ${check.ok ? OK : FAIL} ${check.label}${info}`);
|
|
449
|
+
if (!check.ok && check.suggestedCommand) {
|
|
450
|
+
console.log(` ${c.dim}→ Run: ${c.cyan}${check.suggestedCommand}${c.reset}`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
console.log();
|
|
455
|
+
if (result.ok) {
|
|
456
|
+
console.log(`${OK} ${c.green}All checks passed!${c.reset}\n`);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
console.log(
|
|
461
|
+
`${FAIL} ${result.issueCount} issue(s) found. Run ${c.cyan}spine init${c.reset} to fix config issues.\n`,
|
|
462
|
+
);
|
|
463
|
+
process.exit(1);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
467
|
+
cmdDoctor();
|
|
468
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Integrate gate inspection and resolution (PRD §12, FR-GATE).
|
|
4
|
+
* Usage: spine gate [approve|reject|status] [--batch ID] [--reason text] [--json]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
8
|
+
import { loadBatchStateFile } from "../src/batch/reconcile.mjs";
|
|
9
|
+
import {
|
|
10
|
+
approveIntegrateGate,
|
|
11
|
+
getIntegrateGateStatus,
|
|
12
|
+
rejectIntegrateGate,
|
|
13
|
+
} from "../src/batch/gate.mjs";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {object} result
|
|
17
|
+
* @param {boolean} json
|
|
18
|
+
*/
|
|
19
|
+
export function formatGateHuman(result, json = false) {
|
|
20
|
+
if (json) return `${JSON.stringify(result, null, 2)}\n`;
|
|
21
|
+
|
|
22
|
+
const lines = ["", result.ok ? "Gate" : "Gate action failed", "", ` ${result.headline}`];
|
|
23
|
+
|
|
24
|
+
if (result.error) {
|
|
25
|
+
lines.push("", ` Error: ${result.error}`);
|
|
26
|
+
}
|
|
27
|
+
if (result.gate) {
|
|
28
|
+
lines.push(
|
|
29
|
+
"",
|
|
30
|
+
` Gate ID: ${result.gate.gateId}`,
|
|
31
|
+
` Status: ${result.gate.status}`,
|
|
32
|
+
` Kind: ${result.gate.kind}`,
|
|
33
|
+
);
|
|
34
|
+
if (Array.isArray(result.gate.evidenceRefs) && result.gate.evidenceRefs.length > 0) {
|
|
35
|
+
lines.push("", " Evidence:");
|
|
36
|
+
for (const ref of result.gate.evidenceRefs) {
|
|
37
|
+
lines.push(` • ${ref}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
lines.push("", ` → ${result.suggestedCommand}`);
|
|
43
|
+
|
|
44
|
+
if (result.alternatives?.length) {
|
|
45
|
+
lines.push("", " Alternatives:");
|
|
46
|
+
for (const alt of result.alternatives) {
|
|
47
|
+
lines.push(` • ${alt}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
lines.push("");
|
|
52
|
+
return lines.join("\n");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} projectRoot
|
|
57
|
+
* @param {string|null} batchId
|
|
58
|
+
*/
|
|
59
|
+
function resolveActiveBatchId(projectRoot, batchId) {
|
|
60
|
+
if (batchId) return batchId;
|
|
61
|
+
const loaded = loadBatchStateFile(projectRoot, null);
|
|
62
|
+
if (!loaded.raw) return null;
|
|
63
|
+
return String(loaded.raw.batchId ?? loaded.raw.id ?? "");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {object} options
|
|
68
|
+
* @param {string} options.projectRoot
|
|
69
|
+
* @param {string[]} options.args
|
|
70
|
+
*/
|
|
71
|
+
export function runSpineGate(options) {
|
|
72
|
+
const { projectRoot, args } = options;
|
|
73
|
+
const flags = new Set(args.filter((a) => a.startsWith("--")));
|
|
74
|
+
const positional = args.filter((a) => !a.startsWith("--"));
|
|
75
|
+
const action = positional[0] ?? "status";
|
|
76
|
+
|
|
77
|
+
let batchId = null;
|
|
78
|
+
const batchIdx = args.indexOf("--batch");
|
|
79
|
+
if (batchIdx >= 0 && args[batchIdx + 1]) {
|
|
80
|
+
batchId = args[batchIdx + 1];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let reason = null;
|
|
84
|
+
const reasonIdx = args.indexOf("--reason");
|
|
85
|
+
if (reasonIdx >= 0 && args[reasonIdx + 1]) {
|
|
86
|
+
reason = args[reasonIdx + 1];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
batchId = resolveActiveBatchId(projectRoot, batchId);
|
|
90
|
+
if (!batchId) {
|
|
91
|
+
const result = {
|
|
92
|
+
ok: false,
|
|
93
|
+
exitCode: 1,
|
|
94
|
+
headline: "No active batch for gate operations",
|
|
95
|
+
suggestedCommand: "spine status --diagnose",
|
|
96
|
+
error: "batchId required (no active batch-state.json)",
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
exitCode: result.exitCode,
|
|
100
|
+
output: formatGateHuman(result, flags.has("--json")),
|
|
101
|
+
result,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let result;
|
|
106
|
+
switch (action) {
|
|
107
|
+
case "approve":
|
|
108
|
+
result = approveIntegrateGate({ projectRoot, batchId });
|
|
109
|
+
break;
|
|
110
|
+
case "reject":
|
|
111
|
+
result = rejectIntegrateGate({ projectRoot, batchId, reason: reason ?? undefined });
|
|
112
|
+
break;
|
|
113
|
+
case "status":
|
|
114
|
+
result = getIntegrateGateStatus({ projectRoot, batchId });
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
result = {
|
|
118
|
+
ok: false,
|
|
119
|
+
exitCode: 1,
|
|
120
|
+
headline: `Unknown gate action: ${action}`,
|
|
121
|
+
suggestedCommand: "spine gate status",
|
|
122
|
+
error: "Use approve, reject, or status",
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
128
|
+
output: formatGateHuman(result, flags.has("--json")),
|
|
129
|
+
result,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
134
|
+
const { exitCode, output } = runSpineGate({ projectRoot: process.cwd(), args: process.argv.slice(2) });
|
|
135
|
+
process.stdout.write(output);
|
|
136
|
+
process.exit(exitCode);
|
|
137
|
+
}
|