pi-spine 1.0.2 → 1.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 (129) hide show
  1. package/README.md +61 -489
  2. package/bin/get-version.mjs +1 -13
  3. package/bin/spine-batch.mjs +162 -51
  4. package/bin/spine-cli/batch.mjs +3 -3
  5. package/bin/spine-cli/lane-logs.mjs +24 -0
  6. package/bin/spine-cli/scenarios.mjs +298 -0
  7. package/bin/spine-cli/wait.mjs +30 -0
  8. package/bin/spine-cli/watch.mjs +27 -0
  9. package/bin/spine-config.mjs +1 -212
  10. package/bin/spine-doctor.mjs +2 -418
  11. package/bin/spine-init.mjs +1 -398
  12. package/bin/spine-issue.mjs +196 -0
  13. package/bin/spine-journal.mjs +1 -0
  14. package/bin/spine-preflight.mjs +1 -700
  15. package/bin/spine-review-step.mjs +6 -4
  16. package/bin/spine-run.mjs +30 -0
  17. package/bin/spine-status.mjs +19 -1
  18. package/bin/spine-tasks.mjs +112 -13
  19. package/bin/spine-worker-runner.mjs +24 -14
  20. package/bin/spine.mjs +52 -2
  21. package/extensions/spine/worker-tools.ts +14 -12
  22. package/package.json +5 -2
  23. package/skills/create-spine-tasks/SKILL.md +135 -6
  24. package/skills/create-spine-tasks/references/clarify-template.md +73 -0
  25. package/skills/create-spine-tasks/references/contract-template.md +19 -0
  26. package/skills/create-spine-tasks/references/prompt-template.md +2 -0
  27. package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
  28. package/src/batch/abort.mjs +3 -12
  29. package/src/batch/agent-session-worker.mjs +45 -5
  30. package/src/batch/attached-engine-handoff.mjs +188 -0
  31. package/src/batch/attached-runner.mjs +312 -0
  32. package/src/batch/contract-prelanded.mjs +180 -0
  33. package/src/batch/contract-verify.mjs +140 -2
  34. package/src/batch/detached-start.mjs +105 -7
  35. package/src/batch/diagnosis-alternatives.mjs +46 -0
  36. package/src/batch/diagnosis-merge-failure.mjs +79 -0
  37. package/src/batch/diagnosis-retry-limbo.mjs +34 -0
  38. package/src/batch/diagnosis-stub.mjs +109 -0
  39. package/src/batch/diagnosis-task-done.mjs +110 -0
  40. package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
  41. package/src/batch/diagnosis.mjs +174 -62
  42. package/src/batch/engine-lanes/merge.mjs +168 -77
  43. package/src/batch/engine-lanes/queue.mjs +4 -1
  44. package/src/batch/engine-lanes/review.mjs +32 -74
  45. package/src/batch/engine-lanes/watch.mjs +29 -0
  46. package/src/batch/engine-lanes.mjs +1 -0
  47. package/src/batch/engine-scope.mjs +42 -5
  48. package/src/batch/engine.mjs +115 -68
  49. package/src/batch/evidence.mjs +81 -17
  50. package/src/batch/gate.mjs +46 -17
  51. package/src/batch/git-helpers.mjs +96 -0
  52. package/src/batch/heartbeat.mjs +73 -7
  53. package/src/batch/integrate.mjs +3 -5
  54. package/src/batch/journal.mjs +25 -0
  55. package/src/batch/lane-commit.mjs +90 -5
  56. package/src/batch/lifecycle.mjs +131 -4
  57. package/src/batch/macro-phase.mjs +226 -0
  58. package/src/batch/merge/adoption-doc-merge.mjs +243 -0
  59. package/src/batch/merge/wave-merge-state.mjs +108 -0
  60. package/src/batch/metrics.mjs +74 -5
  61. package/src/batch/orphan-detect.mjs +74 -0
  62. package/src/batch/pause.mjs +223 -0
  63. package/src/batch/post-merge-limbo.mjs +345 -17
  64. package/src/batch/reconcile.mjs +473 -50
  65. package/src/batch/resume-common.mjs +6 -2
  66. package/src/batch/resume-engine.mjs +58 -1
  67. package/src/batch/resume-lane-reviews.mjs +16 -0
  68. package/src/batch/resume-multi-lanes.mjs +56 -1
  69. package/src/batch/resume-multi-validate.mjs +148 -8
  70. package/src/batch/resume-multi.mjs +45 -44
  71. package/src/batch/resume.mjs +64 -47
  72. package/src/batch/retry.mjs +56 -5
  73. package/src/batch/review-shared.mjs +196 -0
  74. package/src/batch/review-spawn.mjs +326 -0
  75. package/src/batch/review.mjs +178 -212
  76. package/src/batch/rules-manifest-drift.mjs +157 -0
  77. package/src/batch/salvage.mjs +2 -1
  78. package/src/batch/sequence.mjs +454 -0
  79. package/src/batch/state.mjs +18 -3
  80. package/src/batch/status-json.mjs +67 -0
  81. package/src/batch/task-stall-budget.mjs +94 -10
  82. package/src/batch/worker-host.mjs +185 -37
  83. package/src/batch/worker-output.mjs +196 -3
  84. package/src/batch/worktree.mjs +10 -0
  85. package/src/cli/handoff.mjs +1 -1
  86. package/src/cli/issue-draft.mjs +180 -0
  87. package/src/cli/journal-follow.mjs +239 -0
  88. package/src/cli/lane-logs.mjs +291 -0
  89. package/src/cli/rules.mjs +1 -1
  90. package/src/cli/sequence.mjs +108 -0
  91. package/src/cli/settings-set.mjs +3 -22
  92. package/src/cli/settings-slash.mjs +27 -5
  93. package/src/cli/wait.mjs +187 -0
  94. package/src/cli/watch.mjs +160 -0
  95. package/src/config/agent-model-resolve.mjs +48 -0
  96. package/src/config/cursor-rules/discover.mjs +3 -21
  97. package/src/config/defaults.mjs +7 -1
  98. package/src/config/settings-fields.mjs +48 -0
  99. package/src/config/spine-config-load.mjs +221 -0
  100. package/src/config/spine-init-constants.mjs +424 -0
  101. package/src/config/spine-preflight-lib.mjs +1180 -0
  102. package/src/dashboard/lane-throughput.mjs +351 -0
  103. package/src/dashboard/public/dashboard.css +25 -1
  104. package/src/dashboard/public/dashboard.js +224 -40
  105. package/src/dashboard/public/index.html +15 -9
  106. package/src/dashboard/server.mjs +4 -0
  107. package/src/dashboard/snapshot.mjs +387 -6
  108. package/src/dashboard/view.mjs +170 -15
  109. package/src/doctor/agent-model-inherit.mjs +61 -6
  110. package/src/doctor/run-doctor-checks.mjs +483 -0
  111. package/src/doctor/sequence-safety.mjs +57 -0
  112. package/src/doctor/stale-path.mjs +22 -0
  113. package/src/doctor/stale-worktrees.mjs +102 -0
  114. package/src/fixtures/scenario-registry.mjs +194 -0
  115. package/src/fs/atomic-write.mjs +49 -0
  116. package/src/migrate/taskplane-config.mjs +1 -1
  117. package/src/planner/file-scope.mjs +246 -0
  118. package/src/planner/format-plan.mjs +9 -7
  119. package/src/planner/index.mjs +6 -2
  120. package/src/planner/pending.mjs +92 -1
  121. package/src/planner/wave-scope.mjs +136 -0
  122. package/src/planner/waves.mjs +133 -0
  123. package/src/tasks/analyze/index.mjs +453 -0
  124. package/src/tasks/packet/index.mjs +1 -0
  125. package/src/tasks/packet/parse-prompt.mjs +42 -1
  126. package/src/tasks/packet/validate-prompt.mjs +124 -0
  127. package/src/util/command-exists.mjs +19 -0
  128. package/templates/docs/constitution.md +61 -0
  129. package/templates/spine-config.json +9 -2
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Foreground poll loop over reconcileBatch (issue #44, SP-360).
3
+ */
4
+
5
+ import { reconcileBatch } from "../batch/reconcile.mjs";
6
+
7
+ export const DEFAULT_WATCH_INTERVAL_SEC = 5;
8
+
9
+ const PROGRESS_FIELD_NAMES = [
10
+ "succeededTasks",
11
+ "pendingTasks",
12
+ "totalTasks",
13
+ "currentWaveIndex",
14
+ "waveCount",
15
+ ];
16
+
17
+ /**
18
+ * @param {string[]} argv
19
+ */
20
+ export function parseWatchArgs(argv) {
21
+ /** @type {{ intervalSec: number, json: boolean, once: boolean }} */
22
+ const args = {
23
+ intervalSec: DEFAULT_WATCH_INTERVAL_SEC,
24
+ json: false,
25
+ once: false,
26
+ };
27
+
28
+ for (let i = 0; i < argv.length; i++) {
29
+ const arg = argv[i];
30
+ if (arg === "--interval") {
31
+ const raw = argv[++i];
32
+ const value = Number(raw);
33
+ if (!Number.isFinite(value) || value <= 0) {
34
+ throw new Error("--interval requires a positive number of seconds");
35
+ }
36
+ args.intervalSec = value;
37
+ } else if (arg === "--json") {
38
+ args.json = true;
39
+ } else if (arg === "--once") {
40
+ args.once = true;
41
+ } else if (arg.startsWith("-")) {
42
+ throw new Error(`Unknown watch option: ${arg}`);
43
+ }
44
+ }
45
+
46
+ return args;
47
+ }
48
+
49
+ /**
50
+ * @param {import("../batch/reconcile.mjs").ReconciliationResult & Record<string, unknown>} reconcileResult
51
+ */
52
+ export function formatWatchHumanLine(reconcileResult) {
53
+ const diagnosis = reconcileResult.diagnosis ?? "idle";
54
+ const batchId = reconcileResult.batchId ?? "—";
55
+ const macroPhase =
56
+ reconcileResult.macroPhaseLabel ?? reconcileResult.macroPhase ?? "—";
57
+ const headline = reconcileResult.headline ?? "";
58
+ return `${diagnosis} | ${batchId} | ${macroPhase} | ${headline}`;
59
+ }
60
+
61
+ /**
62
+ * Stable NDJSON snapshot for `spine watch --json`.
63
+ *
64
+ * @param {import("../batch/reconcile.mjs").ReconciliationResult & Record<string, unknown>} reconcileResult
65
+ * @param {number} [observedAt]
66
+ */
67
+ export function buildWatchSnapshot(reconcileResult, observedAt = Date.now()) {
68
+ /** @type {Record<string, unknown>} */
69
+ const snapshot = {
70
+ observedAt,
71
+ diagnosis: reconcileResult.diagnosis ?? null,
72
+ batchId: reconcileResult.batchId ?? null,
73
+ phase: reconcileResult.phase ?? null,
74
+ macroPhase: reconcileResult.macroPhase ?? null,
75
+ macroPhaseLabel: reconcileResult.macroPhaseLabel ?? null,
76
+ headline: reconcileResult.headline,
77
+ suggestedCommand: reconcileResult.suggestedCommand,
78
+ };
79
+
80
+ if (reconcileResult.progress != null && typeof reconcileResult.progress === "object") {
81
+ snapshot.progress = reconcileResult.progress;
82
+ } else {
83
+ /** @type {Record<string, unknown>} */
84
+ const progress = {};
85
+ for (const field of PROGRESS_FIELD_NAMES) {
86
+ if (reconcileResult[field] != null) {
87
+ progress[field] = reconcileResult[field];
88
+ }
89
+ }
90
+ if (Object.keys(progress).length > 0) {
91
+ snapshot.progress = progress;
92
+ }
93
+ }
94
+
95
+ return snapshot;
96
+ }
97
+
98
+ /**
99
+ * @param {object} options
100
+ * @param {string} options.projectRoot
101
+ * @param {number} [options.intervalSec]
102
+ * @param {boolean} [options.json]
103
+ * @param {boolean} [options.once]
104
+ * @param {(ctx: { projectRoot: string }) => import("../batch/reconcile.mjs").ReconciliationResult} [options.reconcileFn]
105
+ * @param {(ms: number) => Promise<void>} [options.sleepFn]
106
+ * @param {() => number} [options.nowFn]
107
+ * @param {(text: string) => void} [options.writeStdout]
108
+ * @param {boolean} [options.isTTY]
109
+ */
110
+ export async function runSpineWatch(options) {
111
+ const {
112
+ projectRoot,
113
+ intervalSec = DEFAULT_WATCH_INTERVAL_SEC,
114
+ json = false,
115
+ once = false,
116
+ reconcileFn = reconcileBatch,
117
+ sleepFn = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
118
+ nowFn = () => Date.now(),
119
+ writeStdout = (text) => process.stdout.write(text),
120
+ isTTY = process.stdout.isTTY,
121
+ } = options;
122
+
123
+ let running = true;
124
+ const onSigInt = () => {
125
+ running = false;
126
+ };
127
+ process.on("SIGINT", onSigInt);
128
+
129
+ try {
130
+ do {
131
+ const result = reconcileFn({ projectRoot });
132
+ const snapshot = buildWatchSnapshot(result, nowFn());
133
+
134
+ if (json) {
135
+ writeStdout(`${JSON.stringify(snapshot)}\n`);
136
+ } else {
137
+ const line = formatWatchHumanLine(result);
138
+ if (isTTY && !once) {
139
+ writeStdout(`\r\x1b[K${line}`);
140
+ } else {
141
+ writeStdout(`${line}\n`);
142
+ }
143
+ }
144
+
145
+ if (once || !running) {
146
+ break;
147
+ }
148
+
149
+ await sleepFn(intervalSec * 1000);
150
+ } while (running);
151
+
152
+ if (!json && isTTY && !once) {
153
+ writeStdout("\n");
154
+ }
155
+
156
+ return { exitCode: 0 };
157
+ } finally {
158
+ process.off("SIGINT", onSigInt);
159
+ }
160
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Agent model/thinking pin resolution for reviewer spawns (issue #53 / SP-369).
3
+ */
4
+
5
+ /**
6
+ * @param {object} config
7
+ * @param {"plan"|"code"|"final"} reviewType
8
+ * @returns {string|null} Pin value or null to omit `--model`
9
+ */
10
+ export function resolveReviewerModelPin(config, reviewType) {
11
+ const reviewer = config?.agents?.reviewer;
12
+ if (!reviewer) return null;
13
+
14
+ const typePin = reviewer[reviewType]?.model;
15
+ if (typeof typePin === "string" && typePin.length > 0 && typePin !== "inherit") {
16
+ return typePin;
17
+ }
18
+
19
+ const topPin = reviewer.model;
20
+ if (typeof topPin === "string" && topPin.length > 0 && topPin !== "inherit") {
21
+ return topPin;
22
+ }
23
+
24
+ return null;
25
+ }
26
+
27
+ /**
28
+ * @param {object} config
29
+ * @param {"plan"|"code"|"final"} reviewType
30
+ * @returns {string|null} Pin value or null to omit `--thinking`
31
+ */
32
+ export function resolveReviewerThinkingPin(config, reviewType) {
33
+ const reviewer = config?.agents?.reviewer;
34
+ if (!reviewer) return null;
35
+
36
+ const typePin = reviewer[reviewType]?.thinking;
37
+ if (typeof typePin === "string" && typePin.length > 0) {
38
+ if (typePin === "off") return null;
39
+ if (typePin !== "inherit") return typePin;
40
+ }
41
+
42
+ const topPin = reviewer.thinking;
43
+ if (typeof topPin === "string" && topPin.length > 0 && topPin !== "inherit" && topPin !== "off") {
44
+ return topPin;
45
+ }
46
+
47
+ return null;
48
+ }
@@ -5,10 +5,11 @@
5
5
  import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import { execFileSync } from "node:child_process";
8
- import { randomBytes } from "node:crypto";
9
8
 
10
9
  import micromatch from "micromatch";
11
10
 
11
+ import { writeJsonAtomic } from "../../fs/atomic-write.mjs";
12
+
12
13
  import { parseCursorRuleFrontmatter } from "./parse-frontmatter.mjs";
13
14
  import { DEFAULT_RULES_PROFILE, loadRulesProfile } from "./profile.mjs";
14
15
 
@@ -175,26 +176,7 @@ function collectRuleFiles(rulesRootAbs, currentAbs = rulesRootAbs) {
175
176
  */
176
177
  export function writeRulesManifestAtomic(projectRoot, manifest) {
177
178
  const manifestPath = path.join(projectRoot, RULES_MANIFEST_REL_PATH);
178
- const dir = path.dirname(manifestPath);
179
- fs.mkdirSync(dir, { recursive: true });
180
-
181
- const tmpPath = `${manifestPath}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
182
- const content = `${JSON.stringify(manifest, null, 2)}\n`;
183
-
184
- try {
185
- fs.writeFileSync(tmpPath, content, "utf-8");
186
- fs.renameSync(tmpPath, manifestPath);
187
- } catch (err) {
188
- try {
189
- if (fs.existsSync(tmpPath)) {
190
- fs.unlinkSync(tmpPath);
191
- }
192
- } catch {
193
- // ignore cleanup failure
194
- }
195
- throw err;
196
- }
197
-
179
+ writeJsonAtomic(manifestPath, manifest);
198
180
  return manifestPath;
199
181
  }
200
182
 
@@ -27,10 +27,16 @@ export const CONTRACT_DEFAULTS = Object.freeze({
27
27
  legacyTaskIdPrefixes: Object.freeze(["TP-"]),
28
28
  });
29
29
 
30
- /** @type {Readonly<{ review: typeof REVIEW_DEFAULTS; handoff: typeof HANDOFF_DEFAULTS; metrics: typeof METRICS_DEFAULTS; contract: typeof CONTRACT_DEFAULTS }>} */
30
+ /** @type {Readonly<{ cleanupWorktreesOnComplete: boolean }>} */
31
+ export const LANES_DEFAULTS = Object.freeze({
32
+ cleanupWorktreesOnComplete: true,
33
+ });
34
+
35
+ /** @type {Readonly<{ review: typeof REVIEW_DEFAULTS; handoff: typeof HANDOFF_DEFAULTS; metrics: typeof METRICS_DEFAULTS; contract: typeof CONTRACT_DEFAULTS; lanes: typeof LANES_DEFAULTS }>} */
31
36
  export const CONFIG_V2_SECTION_DEFAULTS = Object.freeze({
32
37
  review: REVIEW_DEFAULTS,
33
38
  handoff: HANDOFF_DEFAULTS,
34
39
  metrics: METRICS_DEFAULTS,
35
40
  contract: CONTRACT_DEFAULTS,
41
+ lanes: LANES_DEFAULTS,
36
42
  });
@@ -59,6 +59,54 @@ export const SETTINGS_FIELDS = Object.freeze([
59
59
  type: "enum",
60
60
  enum: ["off", "low", "medium", "high"],
61
61
  },
62
+ {
63
+ path: "agents.reviewer.model",
64
+ label: "Reviewer model",
65
+ type: "string",
66
+ optional: true,
67
+ },
68
+ {
69
+ path: "agents.reviewer.thinking",
70
+ label: "Reviewer thinking level",
71
+ type: "enum",
72
+ enum: ["off", "low", "medium", "high", "inherit"],
73
+ },
74
+ {
75
+ path: "agents.reviewer.plan.model",
76
+ label: "Plan reviewer model",
77
+ type: "string",
78
+ optional: true,
79
+ },
80
+ {
81
+ path: "agents.reviewer.plan.thinking",
82
+ label: "Plan reviewer thinking level",
83
+ type: "enum",
84
+ enum: ["off", "low", "medium", "high", "inherit"],
85
+ },
86
+ {
87
+ path: "agents.reviewer.code.model",
88
+ label: "Code reviewer model",
89
+ type: "string",
90
+ optional: true,
91
+ },
92
+ {
93
+ path: "agents.reviewer.code.thinking",
94
+ label: "Code reviewer thinking level",
95
+ type: "enum",
96
+ enum: ["off", "low", "medium", "high", "inherit"],
97
+ },
98
+ {
99
+ path: "agents.reviewer.final.model",
100
+ label: "Final reviewer model",
101
+ type: "string",
102
+ optional: true,
103
+ },
104
+ {
105
+ path: "agents.reviewer.final.thinking",
106
+ label: "Final reviewer thinking level",
107
+ type: "enum",
108
+ enum: ["off", "low", "medium", "high", "inherit"],
109
+ },
62
110
  {
63
111
  path: "dashboard.port",
64
112
  label: "Dashboard port",
@@ -0,0 +1,221 @@
1
+ // @ts-check
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+
5
+ import { applyEnvOverrides } from "./env-overrides.mjs";
6
+ import { applyConfigDefaults } from "./merge-defaults.mjs";
7
+ import { validateContractConfig } from "./contract.mjs";
8
+ import { validateWorkerBackendConfig } from "./worker-backend.mjs";
9
+ import { validateWorkerContextConfig } from "./worker-context.mjs";
10
+ import { validateWorkerLaunchScriptConfig } from "./worker-launch-script.mjs";
11
+ import { validateWorktreeSetupHookConfig } from "./worktree-setup-hook.mjs";
12
+
13
+ const REQUIRED_TOP_LEVEL = [
14
+ "configVersion",
15
+ "project",
16
+ "paths",
17
+ "baseBranch",
18
+ "testing",
19
+ "agents",
20
+ "lanes",
21
+ "gates",
22
+ ];
23
+
24
+ /**
25
+ * Load spine-config.json from disk only (no FR-CFG-04 env overrides).
26
+ * Use for persistence paths (e.g. settings set) so env values are not written to file.
27
+ *
28
+ * @param {string} projectRoot
29
+ */
30
+ export function loadSpineConfigFile(projectRoot) {
31
+ const configPath = path.join(projectRoot, ".spine", "spine-config.json");
32
+
33
+ if (!fs.existsSync(configPath)) {
34
+ return {
35
+ configPath,
36
+ config: null,
37
+ error: {
38
+ code: "CONFIG_MISSING",
39
+ message: ".spine/spine-config.json not found",
40
+ suggestedCommand: "spine init",
41
+ },
42
+ };
43
+ }
44
+
45
+ let parsed;
46
+ try {
47
+ parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"));
48
+ } catch (err) {
49
+ const message = err instanceof Error ? err.message : String(err);
50
+ return {
51
+ configPath,
52
+ config: null,
53
+ error: {
54
+ code: "CONFIG_PARSE_ERROR",
55
+ message: `Cannot parse spine config: ${message}`,
56
+ suggestedCommand: "spine init --force",
57
+ },
58
+ };
59
+ }
60
+
61
+ const validationError = validateSpineConfig(parsed);
62
+ if (validationError) {
63
+ return {
64
+ configPath,
65
+ config: null,
66
+ error: validationError,
67
+ };
68
+ }
69
+
70
+ return {
71
+ configPath,
72
+ config: parsed,
73
+ error: null,
74
+ };
75
+ }
76
+
77
+ /**
78
+ * Load config with FR-CFG-04 env overrides applied (precedence: env > file).
79
+ *
80
+ * @param {string} projectRoot
81
+ */
82
+ export function loadSpineConfig(projectRoot) {
83
+ const fileResult = loadSpineConfigFile(projectRoot);
84
+ if (fileResult.error) {
85
+ return fileResult;
86
+ }
87
+
88
+ const config = structuredClone(fileResult.config);
89
+ applyConfigDefaults(config);
90
+
91
+ const contractError = validateContractConfig(config);
92
+ if (contractError) {
93
+ return {
94
+ configPath: fileResult.configPath,
95
+ config: null,
96
+ error: contractError,
97
+ };
98
+ }
99
+
100
+ const envResult = applyEnvOverrides(config, projectRoot);
101
+ if (!envResult.ok) {
102
+ return {
103
+ configPath: fileResult.configPath,
104
+ config: null,
105
+ error: envResult.error,
106
+ };
107
+ }
108
+
109
+ return {
110
+ configPath: fileResult.configPath,
111
+ config: envResult.config,
112
+ fileConfig: config,
113
+ sources: envResult.sources,
114
+ envVars: envResult.envVars,
115
+ error: null,
116
+ };
117
+ }
118
+
119
+ /**
120
+ * @param {Record<string, any>} config
121
+ */
122
+ export function validateSpineConfig(config) {
123
+ if (typeof config !== "object" || config === null || Array.isArray(config)) {
124
+ return {
125
+ code: "CONFIG_SCHEMA_INVALID",
126
+ message: "spine-config.json must be a JSON object",
127
+ suggestedCommand: "spine init --force",
128
+ };
129
+ }
130
+
131
+ if (config.configVersion !== 1) {
132
+ return {
133
+ code: "CONFIG_VERSION_UNSUPPORTED",
134
+ message: `configVersion must be 1 (found ${config.configVersion ?? "missing"})`,
135
+ suggestedCommand: "spine migrate-from-taskplane",
136
+ };
137
+ }
138
+
139
+ for (const key of REQUIRED_TOP_LEVEL) {
140
+ if (!(key in config)) {
141
+ return {
142
+ code: "CONFIG_SCHEMA_INVALID",
143
+ message: `Missing required field: ${key}`,
144
+ suggestedCommand: "spine init --force",
145
+ };
146
+ }
147
+ }
148
+
149
+ if (typeof config.paths?.tasksRoot !== "string" || config.paths.tasksRoot.trim() === "") {
150
+ return {
151
+ code: "CONFIG_TASKS_ROOT_INVALID",
152
+ message: "paths.tasksRoot must be a non-empty string",
153
+ suggestedCommand: "spine init",
154
+ };
155
+ }
156
+
157
+ if (typeof config.lanes?.maxParallel !== "number" || config.lanes.maxParallel < 1) {
158
+ return {
159
+ code: "CONFIG_LANES_INVALID",
160
+ message: "lanes.maxParallel must be a number >= 1",
161
+ suggestedCommand: "/spine-settings",
162
+ };
163
+ }
164
+
165
+ const workerBackendError = validateWorkerBackendConfig(config);
166
+ if (workerBackendError) {
167
+ return workerBackendError;
168
+ }
169
+
170
+ const workerContextError = validateWorkerContextConfig(config);
171
+ if (workerContextError) {
172
+ return workerContextError;
173
+ }
174
+
175
+ const launchScriptError = validateWorkerLaunchScriptConfig(config);
176
+ if (launchScriptError) {
177
+ return launchScriptError;
178
+ }
179
+
180
+ const setupHookError = validateWorktreeSetupHookConfig(config);
181
+ if (setupHookError) {
182
+ return setupHookError;
183
+ }
184
+
185
+ if (config.worktreeSetupIgnorePaths != null) {
186
+ if (!Array.isArray(config.worktreeSetupIgnorePaths)) {
187
+ return {
188
+ code: "CONFIG_SETUP_IGNORE_INVALID",
189
+ message: "worktreeSetupIgnorePaths must be an array of strings when set",
190
+ suggestedCommand: "spine settings set worktreeSetupIgnorePaths '[]'",
191
+ };
192
+ }
193
+ for (const entry of config.worktreeSetupIgnorePaths) {
194
+ if (typeof entry !== "string" || !entry.trim()) {
195
+ return {
196
+ code: "CONFIG_SETUP_IGNORE_INVALID",
197
+ message: "worktreeSetupIgnorePaths entries must be non-empty strings",
198
+ suggestedCommand: "spine settings set worktreeSetupIgnorePaths '[]'",
199
+ };
200
+ }
201
+ }
202
+ }
203
+
204
+ if (
205
+ config.lanes?.autoCommitOnStall != null &&
206
+ typeof config.lanes.autoCommitOnStall !== "boolean"
207
+ ) {
208
+ return {
209
+ code: "CONFIG_LANES_INVALID",
210
+ message: "lanes.autoCommitOnStall must be a boolean when set",
211
+ suggestedCommand: "spine settings set lanes.autoCommitOnStall false",
212
+ };
213
+ }
214
+
215
+ const contractError = validateContractConfig(config);
216
+ if (contractError) {
217
+ return contractError;
218
+ }
219
+
220
+ return null;
221
+ }