pi-spine 1.0.2 → 1.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.
Files changed (63) hide show
  1. package/README.md +61 -489
  2. package/bin/get-version.mjs +1 -13
  3. package/bin/spine-batch.mjs +5 -1
  4. package/bin/spine-config.mjs +1 -212
  5. package/bin/spine-doctor.mjs +2 -418
  6. package/bin/spine-init.mjs +1 -398
  7. package/bin/spine-preflight.mjs +1 -700
  8. package/bin/spine-review-step.mjs +6 -4
  9. package/bin/spine-tasks.mjs +96 -11
  10. package/bin/spine-worker-runner.mjs +14 -4
  11. package/bin/spine.mjs +3 -1
  12. package/extensions/spine/worker-tools.ts +14 -12
  13. package/package.json +5 -2
  14. package/skills/create-spine-tasks/SKILL.md +135 -6
  15. package/skills/create-spine-tasks/references/clarify-template.md +73 -0
  16. package/skills/create-spine-tasks/references/prompt-template.md +2 -0
  17. package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
  18. package/src/batch/abort.mjs +1 -1
  19. package/src/batch/detached-start.mjs +41 -7
  20. package/src/batch/diagnosis.mjs +51 -6
  21. package/src/batch/engine-lanes/merge.mjs +70 -7
  22. package/src/batch/engine-lanes/review.mjs +32 -74
  23. package/src/batch/engine-scope.mjs +31 -4
  24. package/src/batch/engine.mjs +40 -48
  25. package/src/batch/evidence.mjs +3 -2
  26. package/src/batch/gate.mjs +3 -3
  27. package/src/batch/integrate.mjs +1 -1
  28. package/src/batch/journal.mjs +22 -0
  29. package/src/batch/lifecycle.mjs +1 -1
  30. package/src/batch/merge/adoption-doc-merge.mjs +160 -0
  31. package/src/batch/merge/wave-merge-state.mjs +105 -0
  32. package/src/batch/post-merge-limbo.mjs +87 -15
  33. package/src/batch/reconcile.mjs +50 -2
  34. package/src/batch/resume-common.mjs +1 -1
  35. package/src/batch/resume-engine.mjs +58 -1
  36. package/src/batch/resume-multi-validate.mjs +82 -3
  37. package/src/batch/resume-multi.mjs +36 -40
  38. package/src/batch/resume.mjs +20 -10
  39. package/src/batch/review-shared.mjs +196 -0
  40. package/src/batch/review-spawn.mjs +320 -0
  41. package/src/batch/review.mjs +178 -212
  42. package/src/batch/task-stall-budget.mjs +72 -0
  43. package/src/batch/worker-host.mjs +94 -34
  44. package/src/batch/worktree.mjs +10 -0
  45. package/src/cli/handoff.mjs +1 -1
  46. package/src/cli/rules.mjs +1 -1
  47. package/src/cli/settings-set.mjs +1 -1
  48. package/src/cli/settings-slash.mjs +27 -5
  49. package/src/config/spine-config-load.mjs +221 -0
  50. package/src/config/spine-init-constants.mjs +423 -0
  51. package/src/config/spine-preflight-lib.mjs +725 -0
  52. package/src/dashboard/public/dashboard.js +4 -25
  53. package/src/dashboard/public/index.html +1 -7
  54. package/src/dashboard/snapshot.mjs +172 -5
  55. package/src/dashboard/view.mjs +2 -0
  56. package/src/doctor/run-doctor-checks.mjs +458 -0
  57. package/src/doctor/stale-path.mjs +22 -0
  58. package/src/migrate/taskplane-config.mjs +1 -1
  59. package/src/planner/pending.mjs +92 -1
  60. package/src/tasks/analyze/index.mjs +453 -0
  61. package/src/util/command-exists.mjs +19 -0
  62. package/templates/docs/constitution.md +61 -0
  63. package/templates/spine-config.json +1 -1
@@ -1,18 +1,6 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
 
3
- export function commandExists(cmd) {
4
- let result;
5
- try {
6
- result = spawnSync("which", [cmd], {
7
- encoding: "utf-8",
8
- stdio: ["ignore", "pipe", "pipe"],
9
- });
10
- } catch {
11
- return false;
12
- }
13
-
14
- return Boolean(result && !result.error && result.status === 0);
15
- }
3
+ export { commandExists } from "../src/util/command-exists.mjs";
16
4
 
17
5
  export function getVersion(cmd, flag = "--version") {
18
6
  let result;
@@ -76,6 +76,7 @@ export function parseBatchArgs(args) {
76
76
 
77
77
  const dryRun = flags.has("--dry-run");
78
78
  const skipPreflight = flags.has("--skip-preflight");
79
+ const forceSuperseded = flags.has("--force-superseded");
79
80
 
80
81
  const subcommand =
81
82
  args.find(
@@ -103,6 +104,7 @@ export function parseBatchArgs(args) {
103
104
  noWaitTerminal: flags.has("--no-wait-terminal"),
104
105
  dryRun,
105
106
  skipPreflight,
107
+ forceSuperseded,
106
108
  batchId,
107
109
  reason,
108
110
  waveIndex,
@@ -318,6 +320,7 @@ export async function runSpineBatch(options) {
318
320
  spineBin: path.join(__dirname, "spine.mjs"),
319
321
  scope: parsed.scope,
320
322
  skipPreflight: parsed.skipPreflight,
323
+ forceSuperseded: parsed.forceSuperseded,
321
324
  waitTerminal: parsed.waitTerminal,
322
325
  json: parsed.json,
323
326
  });
@@ -333,6 +336,7 @@ export async function runSpineBatch(options) {
333
336
  scope: parsed.scope,
334
337
  dryRun: parsed.dryRun,
335
338
  skipPreflight: parsed.skipPreflight,
339
+ forceSuperseded: parsed.forceSuperseded,
336
340
  });
337
341
  if (parsed.json) {
338
342
  return {
@@ -360,7 +364,7 @@ export async function runSpineBatch(options) {
360
364
  return {
361
365
  exitCode: 1,
362
366
  output:
363
- "Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|abort|dismiss|complete [--batch ID] [--reason TEXT] [--hard] [--force] [--attached] [--dry-run] [--skip-preflight] [--detect-manual-merge] [--json]\n",
367
+ "Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|abort|dismiss|complete [--batch ID] [--reason TEXT] [--hard] [--force] [--force-superseded] [--attached] [--dry-run] [--skip-preflight] [--detect-manual-merge] [--json]\n",
364
368
  };
365
369
  }
366
370
 
@@ -1,212 +1 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
-
4
- import { applyEnvOverrides } from "../src/config/env-overrides.mjs";
5
- import { applyConfigDefaults } from "../src/config/merge-defaults.mjs";
6
- import { validateContractConfig } from "../src/config/contract.mjs";
7
- import { validateWorkerBackendConfig } from "../src/config/worker-backend.mjs";
8
- import { validateWorkerContextConfig } from "../src/config/worker-context.mjs";
9
- import { validateWorkerLaunchScriptConfig } from "../src/config/worker-launch-script.mjs";
10
- import { validateWorktreeSetupHookConfig } from "../src/config/worktree-setup-hook.mjs";
11
-
12
- const REQUIRED_TOP_LEVEL = [
13
- "configVersion",
14
- "project",
15
- "paths",
16
- "baseBranch",
17
- "testing",
18
- "agents",
19
- "lanes",
20
- "gates",
21
- ];
22
-
23
- /**
24
- * Load spine-config.json from disk only (no FR-CFG-04 env overrides).
25
- * Use for persistence paths (e.g. settings set) so env values are not written to file.
26
- */
27
- export function loadSpineConfigFile(projectRoot) {
28
- const configPath = path.join(projectRoot, ".spine", "spine-config.json");
29
-
30
- if (!fs.existsSync(configPath)) {
31
- return {
32
- configPath,
33
- config: null,
34
- error: {
35
- code: "CONFIG_MISSING",
36
- message: ".spine/spine-config.json not found",
37
- suggestedCommand: "spine init",
38
- },
39
- };
40
- }
41
-
42
- let parsed;
43
- try {
44
- parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"));
45
- } catch (err) {
46
- return {
47
- configPath,
48
- config: null,
49
- error: {
50
- code: "CONFIG_PARSE_ERROR",
51
- message: `Cannot parse spine config: ${err.message}`,
52
- suggestedCommand: "spine init --force",
53
- },
54
- };
55
- }
56
-
57
- const validationError = validateSpineConfig(parsed);
58
- if (validationError) {
59
- return {
60
- configPath,
61
- config: null,
62
- error: validationError,
63
- };
64
- }
65
-
66
- return {
67
- configPath,
68
- config: parsed,
69
- error: null,
70
- };
71
- }
72
-
73
- /**
74
- * Load config with FR-CFG-04 env overrides applied (precedence: env > file).
75
- */
76
- export function loadSpineConfig(projectRoot) {
77
- const fileResult = loadSpineConfigFile(projectRoot);
78
- if (fileResult.error) {
79
- return fileResult;
80
- }
81
-
82
- const config = structuredClone(fileResult.config);
83
- applyConfigDefaults(config);
84
-
85
- const contractError = validateContractConfig(config);
86
- if (contractError) {
87
- return {
88
- configPath: fileResult.configPath,
89
- config: null,
90
- error: contractError,
91
- };
92
- }
93
-
94
- const envResult = applyEnvOverrides(config, projectRoot);
95
- if (!envResult.ok) {
96
- return {
97
- configPath: fileResult.configPath,
98
- config: null,
99
- error: envResult.error,
100
- };
101
- }
102
-
103
- return {
104
- configPath: fileResult.configPath,
105
- config: envResult.config,
106
- fileConfig: config,
107
- sources: envResult.sources,
108
- envVars: envResult.envVars,
109
- error: null,
110
- };
111
- }
112
-
113
- export function validateSpineConfig(config) {
114
- if (typeof config !== "object" || config === null || Array.isArray(config)) {
115
- return {
116
- code: "CONFIG_SCHEMA_INVALID",
117
- message: "spine-config.json must be a JSON object",
118
- suggestedCommand: "spine init --force",
119
- };
120
- }
121
-
122
- if (config.configVersion !== 1) {
123
- return {
124
- code: "CONFIG_VERSION_UNSUPPORTED",
125
- message: `configVersion must be 1 (found ${config.configVersion ?? "missing"})`,
126
- suggestedCommand: "spine migrate-from-taskplane",
127
- };
128
- }
129
-
130
- for (const key of REQUIRED_TOP_LEVEL) {
131
- if (!(key in config)) {
132
- return {
133
- code: "CONFIG_SCHEMA_INVALID",
134
- message: `Missing required field: ${key}`,
135
- suggestedCommand: "spine init --force",
136
- };
137
- }
138
- }
139
-
140
- if (typeof config.paths?.tasksRoot !== "string" || config.paths.tasksRoot.trim() === "") {
141
- return {
142
- code: "CONFIG_TASKS_ROOT_INVALID",
143
- message: "paths.tasksRoot must be a non-empty string",
144
- suggestedCommand: "spine init",
145
- };
146
- }
147
-
148
- if (typeof config.lanes?.maxParallel !== "number" || config.lanes.maxParallel < 1) {
149
- return {
150
- code: "CONFIG_LANES_INVALID",
151
- message: "lanes.maxParallel must be a number >= 1",
152
- suggestedCommand: "/spine-settings",
153
- };
154
- }
155
-
156
- const workerBackendError = validateWorkerBackendConfig(config);
157
- if (workerBackendError) {
158
- return workerBackendError;
159
- }
160
-
161
- const workerContextError = validateWorkerContextConfig(config);
162
- if (workerContextError) {
163
- return workerContextError;
164
- }
165
-
166
- const launchScriptError = validateWorkerLaunchScriptConfig(config);
167
- if (launchScriptError) {
168
- return launchScriptError;
169
- }
170
-
171
- const setupHookError = validateWorktreeSetupHookConfig(config);
172
- if (setupHookError) {
173
- return setupHookError;
174
- }
175
-
176
- if (config.worktreeSetupIgnorePaths != null) {
177
- if (!Array.isArray(config.worktreeSetupIgnorePaths)) {
178
- return {
179
- code: "CONFIG_SETUP_IGNORE_INVALID",
180
- message: "worktreeSetupIgnorePaths must be an array of strings when set",
181
- suggestedCommand: "spine settings set worktreeSetupIgnorePaths '[]'",
182
- };
183
- }
184
- for (const entry of config.worktreeSetupIgnorePaths) {
185
- if (typeof entry !== "string" || !entry.trim()) {
186
- return {
187
- code: "CONFIG_SETUP_IGNORE_INVALID",
188
- message: "worktreeSetupIgnorePaths entries must be non-empty strings",
189
- suggestedCommand: "spine settings set worktreeSetupIgnorePaths '[]'",
190
- };
191
- }
192
- }
193
- }
194
-
195
- if (
196
- config.lanes?.autoCommitOnStall != null &&
197
- typeof config.lanes.autoCommitOnStall !== "boolean"
198
- ) {
199
- return {
200
- code: "CONFIG_LANES_INVALID",
201
- message: "lanes.autoCommitOnStall must be a boolean when set",
202
- suggestedCommand: "spine settings set lanes.autoCommitOnStall false",
203
- };
204
- }
205
-
206
- const contractError = validateContractConfig(config);
207
- if (contractError) {
208
- return contractError;
209
- }
210
-
211
- return null;
212
- }
1
+ export * from "../src/config/spine-config-load.mjs";
@@ -2,432 +2,16 @@
2
2
  * spine doctor — installation and project configuration checks (SP-093 manifest warnings).
3
3
  */
4
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
5
  import {
13
6
  c,
14
7
  FAIL,
15
- getMinPiVersion,
16
- getPackageVersion,
17
8
  isCliEntrypoint,
18
9
  OK,
19
- PACKAGE_ROOT,
20
10
  WARN,
21
11
  } 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
- });
12
+ import { runDoctorChecks } from "../src/doctor/run-doctor-checks.mjs";
277
13
 
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
- }
14
+ export { buildTestingEvidenceDoctorChecks, runDoctorChecks } from "../src/doctor/run-doctor-checks.mjs";
431
15
 
432
16
  export function cmdDoctor() {
433
17
  const projectRoot = process.cwd();