pi-spine 1.6.0 → 1.7.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 (37) hide show
  1. package/bin/spine-wait.mjs +12 -0
  2. package/package.json +2 -2
  3. package/skills/spine-release-operator/SKILL.md +37 -7
  4. package/src/batch/attached-runner.mjs +18 -7
  5. package/src/batch/contract-task-start.mjs +12 -7
  6. package/src/batch/contract-verify.mjs +25 -1
  7. package/src/batch/detached-spawn.mjs +78 -0
  8. package/src/batch/detached-start.mjs +25 -71
  9. package/src/batch/diagnosis.mjs +25 -2
  10. package/src/batch/evidence.mjs +30 -250
  11. package/src/batch/gate-evidence-collect.mjs +172 -0
  12. package/src/batch/gate-evidence-read.mjs +145 -0
  13. package/src/batch/gate.mjs +28 -38
  14. package/src/batch/lane-dirty-check.mjs +102 -0
  15. package/src/batch/lifecycle.mjs +6 -5
  16. package/src/batch/post-merge-limbo.mjs +1 -1
  17. package/src/batch/postmortem.mjs +1 -2
  18. package/src/batch/reconcile.mjs +1 -1
  19. package/src/batch/resume-common.mjs +7 -1
  20. package/src/batch/resume-multi-validate.mjs +25 -101
  21. package/src/batch/resume-validation.mjs +120 -0
  22. package/src/batch/sequence.mjs +11 -2
  23. package/src/batch/supervisor-spawn.mjs +379 -0
  24. package/src/cli/spine-wait.mjs +114 -0
  25. package/src/cli/wait.mjs +7 -43
  26. package/src/config/defaults.mjs +4 -1
  27. package/src/config/settings-fields.mjs +23 -0
  28. package/src/config/spine-config-load.mjs +6 -0
  29. package/src/config/spine-config-schema.mjs +121 -0
  30. package/src/config/spine-init-constants.mjs +19 -1
  31. package/src/config/worktree-setup-hook.mjs +221 -0
  32. package/src/doctor/agent-models.mjs +1 -0
  33. package/src/doctor/run-doctor-checks.mjs +14 -0
  34. package/src/doctor/supervisor.mjs +66 -0
  35. package/src/doctor/worktree-health.mjs +1 -1
  36. package/templates/agents/supervisor.md +27 -18
  37. package/templates/spine-config.json +16 -1
@@ -0,0 +1,379 @@
1
+ /**
2
+ * FR-SHIP-11 Tier 1 — opt-in supervisor monitor spawn on detached batch start.
3
+ * Detached node child polls reconcileBatch and journals supervisor.* events.
4
+ */
5
+
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { spawn } from "node:child_process";
9
+ import { fileURLToPath } from "node:url";
10
+ import { loadSpineConfig } from "../config/spine-config-load.mjs";
11
+ import { appendJournalEvent } from "./journal.mjs";
12
+ import { reconcileBatch } from "./reconcile.mjs";
13
+ import { buildDiagnosisOutput } from "./diagnosis.mjs";
14
+ import { TERMINAL_BATCH_PHASES } from "./state.mjs";
15
+
16
+ const __filename = fileURLToPath(import.meta.url);
17
+
18
+ /** Default reconcile poll interval when config omits pollIntervalMs. */
19
+ export const DEFAULT_SUPERVISOR_POLL_INTERVAL_MS = 30_000;
20
+
21
+ /** Diagnoses that warrant a supervisor.nudge journal event on transition. */
22
+ export const SUPERVISOR_NUDGE_DIAGNOSES = new Set([
23
+ "needs_retry",
24
+ "engine_orphaned",
25
+ "worker_orphaned",
26
+ "state_drift",
27
+ "needs_integrate",
28
+ "needs_merge",
29
+ "limbo_stale",
30
+ "completed_manual",
31
+ "failed",
32
+ "aborted",
33
+ "worker_done_missing",
34
+ "human_base_diverged",
35
+ ]);
36
+
37
+ /**
38
+ * @param {object} [config]
39
+ */
40
+ export function isSupervisorSpawnEnabled(config = {}) {
41
+ return config.agents?.supervisor?.enabled === true;
42
+ }
43
+
44
+ /**
45
+ * @param {object} [config]
46
+ */
47
+ export function resolveSupervisorPollIntervalMs(config = {}) {
48
+ const raw = Number(config.agents?.supervisor?.pollIntervalMs);
49
+ if (Number.isFinite(raw) && raw >= 1_000) {
50
+ return raw;
51
+ }
52
+ return DEFAULT_SUPERVISOR_POLL_INTERVAL_MS;
53
+ }
54
+
55
+ /**
56
+ * @param {object} [config]
57
+ * @returns {string}
58
+ */
59
+ export function resolveSupervisorModel(config = {}) {
60
+ const model = config.agents?.supervisor?.model;
61
+ if (typeof model === "string" && model.length > 0) {
62
+ return model;
63
+ }
64
+ return "inherit";
65
+ }
66
+
67
+ /**
68
+ * @param {string} projectRoot
69
+ * @param {string} batchId
70
+ */
71
+ export function supervisorStatePath(projectRoot, batchId) {
72
+ return path.join(projectRoot, ".spine", "runtime", batchId, "supervisor.json");
73
+ }
74
+
75
+ /**
76
+ * @param {string} projectRoot
77
+ * @param {string} batchId
78
+ */
79
+ export function readSupervisorState(projectRoot, batchId) {
80
+ const filePath = supervisorStatePath(projectRoot, batchId);
81
+ if (!fs.existsSync(filePath)) return null;
82
+ try {
83
+ return JSON.parse(fs.readFileSync(filePath, "utf-8"));
84
+ } catch {
85
+ return null;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @param {string} projectRoot
91
+ * @param {string} batchId
92
+ * @param {object} state
93
+ */
94
+ export function writeSupervisorState(projectRoot, batchId, state) {
95
+ const filePath = supervisorStatePath(projectRoot, batchId);
96
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
97
+ fs.writeFileSync(filePath, `${JSON.stringify(state, null, 2)}\n`, "utf-8");
98
+ }
99
+
100
+ /**
101
+ * @param {string} projectRoot
102
+ * @param {string} batchId
103
+ */
104
+ export function clearSupervisorState(projectRoot, batchId) {
105
+ const filePath = supervisorStatePath(projectRoot, batchId);
106
+ if (fs.existsSync(filePath)) {
107
+ fs.unlinkSync(filePath);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * @param {number} ms
113
+ */
114
+ function sleep(ms) {
115
+ return new Promise((resolve) => setTimeout(resolve, ms));
116
+ }
117
+
118
+ /**
119
+ * @param {object} reconciliation
120
+ */
121
+ export function isSupervisorMonitorTerminal(reconciliation) {
122
+ if (!reconciliation?.batchId) return true;
123
+ const phase = String(reconciliation.phase ?? "");
124
+ if (TERMINAL_BATCH_PHASES.has(phase)) return true;
125
+ const diagnosis = String(reconciliation.diagnosis ?? "");
126
+ if (diagnosis === "completed" || diagnosis === "completed_manual") return true;
127
+ return false;
128
+ }
129
+
130
+ /**
131
+ * @param {object} reconciliation
132
+ */
133
+ function countTasksByStatus(reconciliation) {
134
+ const tasks = reconciliation.signals?.tasks;
135
+ if (!Array.isArray(tasks)) {
136
+ return { runningTaskCount: 0, pendingTaskCount: 0 };
137
+ }
138
+ let runningTaskCount = 0;
139
+ let pendingTaskCount = 0;
140
+ for (const task of tasks) {
141
+ const status = String(task?.status ?? "");
142
+ if (status === "running") runningTaskCount += 1;
143
+ if (status === "pending") pendingTaskCount += 1;
144
+ }
145
+ return { runningTaskCount, pendingTaskCount };
146
+ }
147
+
148
+ /**
149
+ * @param {object} reconciliation
150
+ */
151
+ export function buildSupervisorObservationPayload(reconciliation) {
152
+ const { runningTaskCount, pendingTaskCount } = countTasksByStatus(reconciliation);
153
+ return {
154
+ diagnosis: reconciliation.diagnosis ?? null,
155
+ macroPhase: reconciliation.macroPhase ?? null,
156
+ macroPhaseLabel: reconciliation.macroPhaseLabel ?? null,
157
+ phase: reconciliation.phase ?? null,
158
+ runningTaskCount,
159
+ pendingTaskCount,
160
+ suggestedCommand: reconciliation.suggestedCommand ?? null,
161
+ };
162
+ }
163
+
164
+ /**
165
+ * @param {string|null|undefined} diagnosis
166
+ * @param {object} [ctx]
167
+ */
168
+ export function buildSupervisorNudgePayload(diagnosis, ctx = {}) {
169
+ const output = buildDiagnosisOutput(diagnosis ?? "running", ctx);
170
+ return {
171
+ diagnosis: diagnosis ?? null,
172
+ headline: output.headline ?? null,
173
+ suggestedCommand: output.suggestedCommand ?? null,
174
+ };
175
+ }
176
+
177
+ /**
178
+ * @param {string|null|undefined} diagnosis
179
+ */
180
+ export function shouldEmitSupervisorNudge(diagnosis) {
181
+ return Boolean(diagnosis && SUPERVISOR_NUDGE_DIAGNOSES.has(diagnosis));
182
+ }
183
+
184
+ /**
185
+ * Detached poll loop — runs in child process when SPINE_SUPERVISOR_MONITOR=1.
186
+ *
187
+ * @param {object} params
188
+ * @param {string} params.projectRoot
189
+ * @param {string} params.batchId
190
+ * @param {object} [params.config]
191
+ * @param {number|null} [params.supervisorPid]
192
+ */
193
+ export async function runSupervisorMonitorLoop({
194
+ projectRoot,
195
+ batchId,
196
+ config = {},
197
+ supervisorPid = null,
198
+ }) {
199
+ const pollIntervalMs = resolveSupervisorPollIntervalMs(config);
200
+ const model = resolveSupervisorModel(config);
201
+ const pid = supervisorPid ?? process.pid;
202
+
203
+ appendJournalEvent(projectRoot, batchId, "supervisor.started", {
204
+ batchId,
205
+ model,
206
+ pid,
207
+ pollIntervalMs,
208
+ });
209
+
210
+ /** @type {string|null} */
211
+ let lastNudgeDiagnosis = null;
212
+
213
+ while (true) {
214
+ const reconciliation = reconcileBatch({ projectRoot, verbose: true });
215
+ if (!reconciliation.batchId || reconciliation.batchId !== batchId) {
216
+ appendJournalEvent(projectRoot, batchId, "supervisor.stopped", {
217
+ reason: "batch_state_cleared",
218
+ pid,
219
+ });
220
+ clearSupervisorState(projectRoot, batchId);
221
+ return;
222
+ }
223
+
224
+ appendJournalEvent(
225
+ projectRoot,
226
+ batchId,
227
+ "supervisor.observation",
228
+ buildSupervisorObservationPayload(reconciliation),
229
+ );
230
+
231
+ const diagnosis = reconciliation.diagnosis ?? null;
232
+ if (
233
+ shouldEmitSupervisorNudge(diagnosis) &&
234
+ diagnosis !== lastNudgeDiagnosis
235
+ ) {
236
+ lastNudgeDiagnosis = diagnosis;
237
+ appendJournalEvent(
238
+ projectRoot,
239
+ batchId,
240
+ "supervisor.nudge",
241
+ buildSupervisorNudgePayload(diagnosis, {
242
+ batchId,
243
+ phase: reconciliation.phase,
244
+ failedTaskId: reconciliation.signals?.failedTaskId ?? null,
245
+ }),
246
+ );
247
+ }
248
+
249
+ if (isSupervisorMonitorTerminal(reconciliation)) {
250
+ appendJournalEvent(projectRoot, batchId, "supervisor.stopped", {
251
+ reason: "batch_terminal",
252
+ diagnosis,
253
+ phase: reconciliation.phase ?? null,
254
+ pid,
255
+ });
256
+ clearSupervisorState(projectRoot, batchId);
257
+ return;
258
+ }
259
+
260
+ await sleep(pollIntervalMs);
261
+ }
262
+ }
263
+
264
+ /**
265
+ * @param {number} pid
266
+ */
267
+ function killProcess(pid) {
268
+ try {
269
+ process.kill(pid, "SIGTERM");
270
+ } catch {
271
+ return;
272
+ }
273
+ setTimeout(() => {
274
+ try {
275
+ process.kill(pid, 0);
276
+ process.kill(pid, "SIGKILL");
277
+ } catch {
278
+ // already exited
279
+ }
280
+ }, 1_000).unref?.();
281
+ }
282
+
283
+ /**
284
+ * @param {object} params
285
+ * @param {string} params.projectRoot
286
+ * @param {string} params.batchId
287
+ * @param {string} [params.reason]
288
+ */
289
+ export function killSupervisor({ projectRoot, batchId, reason = "killed" }) {
290
+ const state = readSupervisorState(projectRoot, batchId);
291
+ if (!state) return { killed: false, reason: "no_supervisor_state" };
292
+
293
+ const pid = Number(state.pid);
294
+ if (Number.isFinite(pid) && pid > 0) {
295
+ killProcess(pid);
296
+ }
297
+
298
+ appendJournalEvent(projectRoot, batchId, "supervisor.stopped", {
299
+ reason,
300
+ pid: Number.isFinite(pid) ? pid : null,
301
+ });
302
+ clearSupervisorState(projectRoot, batchId);
303
+ return { killed: true, pid: Number.isFinite(pid) ? pid : null };
304
+ }
305
+
306
+ /**
307
+ * @param {string} projectRoot
308
+ * @param {string} batchId
309
+ * @param {string} [reason]
310
+ */
311
+ export function terminateSupervisorIfRunning(projectRoot, batchId, reason = "batch_lifecycle") {
312
+ return killSupervisor({ projectRoot, batchId, reason });
313
+ }
314
+
315
+ /**
316
+ * Spawn detached supervisor monitor when opt-in config is enabled.
317
+ *
318
+ * @param {object} params
319
+ * @param {string} params.projectRoot
320
+ * @param {string} params.batchId
321
+ * @param {object} [params.config]
322
+ */
323
+ export function spawnDetachedSupervisor({ projectRoot, batchId, config = {} }) {
324
+ if (!isSupervisorSpawnEnabled(config)) {
325
+ return { spawned: false };
326
+ }
327
+
328
+ const model = resolveSupervisorModel(config);
329
+ const pollIntervalMs = resolveSupervisorPollIntervalMs(config);
330
+
331
+ const child = spawn(process.execPath, [__filename], {
332
+ cwd: projectRoot,
333
+ detached: true,
334
+ stdio: "ignore",
335
+ env: {
336
+ ...process.env,
337
+ SPINE_SUPERVISOR_MONITOR: "1",
338
+ SPINE_PROJECT_ROOT: projectRoot,
339
+ SPINE_BATCH_ID: batchId,
340
+ },
341
+ });
342
+ child.unref();
343
+
344
+ const supervisorPid = child.pid ?? null;
345
+ if (supervisorPid) {
346
+ writeSupervisorState(projectRoot, batchId, {
347
+ pid: supervisorPid,
348
+ model,
349
+ pollIntervalMs,
350
+ startedAt: Date.now(),
351
+ });
352
+ }
353
+
354
+ return { spawned: true, supervisorPid, model, pollIntervalMs };
355
+ }
356
+
357
+ /**
358
+ * @param {object} params
359
+ * @param {string} params.projectRoot
360
+ * @param {string} params.batchId
361
+ * @param {object} [params.config]
362
+ */
363
+ export function maybeSpawnSupervisorOnDetachedStart({ projectRoot, batchId, config }) {
364
+ if (!batchId) return { spawned: false };
365
+ const resolvedConfig = config ?? loadSpineConfig(projectRoot).config ?? {};
366
+ return spawnDetachedSupervisor({ projectRoot, batchId, config: resolvedConfig });
367
+ }
368
+
369
+ if (process.env.SPINE_SUPERVISOR_MONITOR === "1") {
370
+ const projectRoot = process.env.SPINE_PROJECT_ROOT ?? process.cwd();
371
+ const batchId = process.env.SPINE_BATCH_ID ?? "";
372
+ const config = loadSpineConfig(projectRoot).config ?? {};
373
+ runSupervisorMonitorLoop({ projectRoot, batchId, config, supervisorPid: process.pid })
374
+ .then(() => process.exit(0))
375
+ .catch((err) => {
376
+ console.error(err);
377
+ process.exit(1);
378
+ });
379
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * spine wait --until validation and land-loop pseudo-diagnosis matching (SP-479, issue #105).
3
+ */
4
+
5
+ import { DIAGNOSIS_TAXONOMY } from "../batch/diagnosis.mjs";
6
+
7
+ /** Operator-facing wait targets not in reconcile diagnosis taxonomy. */
8
+ export const WAIT_UNTIL_PSEUDO_DIAGNOSES = [
9
+ "gate_open",
10
+ "needs_approval",
11
+ "post_merge_limbo",
12
+ ];
13
+
14
+ /** @type {ReadonlySet<string>} */
15
+ export const VALID_UNTIL_DIAGNOSES = new Set([
16
+ ...DIAGNOSIS_TAXONOMY,
17
+ ...WAIT_UNTIL_PSEUDO_DIAGNOSES,
18
+ ]);
19
+
20
+ /**
21
+ * Comma-separated list for CLI error messages.
22
+ */
23
+ export function formatValidWaitUntilDiagnoses() {
24
+ return [...DIAGNOSIS_TAXONOMY, ...WAIT_UNTIL_PSEUDO_DIAGNOSES].join(", ");
25
+ }
26
+
27
+ /**
28
+ * @param {string} raw
29
+ * @returns {Set<string>}
30
+ */
31
+ export function parseUntilDiagnoses(raw) {
32
+ const trimmed = String(raw).trim();
33
+ if (trimmed.length === 0) {
34
+ throw new Error("--until requires a comma-separated diagnosis list");
35
+ }
36
+
37
+ /** @type {Set<string>} */
38
+ const diagnoses = new Set();
39
+ for (const part of trimmed.split(",")) {
40
+ const diagnosis = part.trim();
41
+ if (diagnosis.length === 0) {
42
+ throw new Error("--until contains an empty diagnosis entry");
43
+ }
44
+ if (!VALID_UNTIL_DIAGNOSES.has(diagnosis)) {
45
+ throw new Error(
46
+ `Unknown diagnosis in --until: ${diagnosis} (valid: ${formatValidWaitUntilDiagnoses()})`,
47
+ );
48
+ }
49
+ diagnoses.add(diagnosis);
50
+ }
51
+
52
+ return diagnoses;
53
+ }
54
+
55
+ /**
56
+ * Derive land-loop pseudo-diagnoses from a reconcile snapshot.
57
+ *
58
+ * @param {import("../batch/reconcile.mjs").ReconciliationResult & Record<string, unknown>} result
59
+ * @returns {Set<string>}
60
+ */
61
+ export function deriveWaitPseudoDiagnoses(result) {
62
+ /** @type {Set<string>} */
63
+ const pseudo = new Set();
64
+ const suggestedCommand = String(result.suggestedCommand ?? "");
65
+ const headline = String(result.headline ?? "");
66
+ const macroPhase = String(result.macroPhase ?? "");
67
+
68
+ const gateOpened =
69
+ suggestedCommand === "spine gate approve" || headline.includes("gate opened");
70
+ if (gateOpened) {
71
+ pseudo.add("gate_open");
72
+ pseudo.add("needs_approval");
73
+ }
74
+
75
+ const postMergeLimbo =
76
+ macroPhase === "gating" &&
77
+ (suggestedCommand.includes("batch resume --force") ||
78
+ headline.includes("gate not opened") ||
79
+ headline.includes("finalizing land loop"));
80
+ if (postMergeLimbo && !gateOpened) {
81
+ pseudo.add("post_merge_limbo");
82
+ }
83
+
84
+ return pseudo;
85
+ }
86
+
87
+ /**
88
+ * @param {string | null | undefined} diagnosis
89
+ * @param {Set<string>} untilDiagnoses
90
+ */
91
+ export function diagnosisMatchesUntil(diagnosis, untilDiagnoses) {
92
+ if (diagnosis == null) {
93
+ return false;
94
+ }
95
+ return untilDiagnoses.has(diagnosis);
96
+ }
97
+
98
+ /**
99
+ * @param {import("../batch/reconcile.mjs").ReconciliationResult & Record<string, unknown>} result
100
+ * @param {Set<string>} untilDiagnoses
101
+ */
102
+ export function reconciliationMatchesUntil(result, untilDiagnoses) {
103
+ if (diagnosisMatchesUntil(result.diagnosis ?? null, untilDiagnoses)) {
104
+ return true;
105
+ }
106
+
107
+ for (const pseudo of deriveWaitPseudoDiagnoses(result)) {
108
+ if (untilDiagnoses.has(pseudo)) {
109
+ return true;
110
+ }
111
+ }
112
+
113
+ return false;
114
+ }
package/src/cli/wait.mjs CHANGED
@@ -2,15 +2,18 @@
2
2
  * Block until reconcile diagnosis reaches a target set (issue #46, SP-362).
3
3
  */
4
4
 
5
- import { DIAGNOSIS_TAXONOMY } from "../batch/diagnosis.mjs";
6
5
  import { reconcileBatch } from "../batch/reconcile.mjs";
6
+ import { parseUntilDiagnoses, reconciliationMatchesUntil } from "./spine-wait.mjs";
7
7
  import {
8
8
  buildWatchSnapshot,
9
9
  DEFAULT_WATCH_INTERVAL_SEC,
10
10
  } from "./watch.mjs";
11
11
 
12
- /** @type {ReadonlySet<string>} */
13
- const VALID_UNTIL_DIAGNOSES = new Set(DIAGNOSIS_TAXONOMY);
12
+ export {
13
+ diagnosisMatchesUntil,
14
+ parseUntilDiagnoses,
15
+ reconciliationMatchesUntil,
16
+ } from "./spine-wait.mjs";
14
17
 
15
18
  /**
16
19
  * @param {string} raw
@@ -45,34 +48,6 @@ export function parseDurationMs(raw) {
45
48
  return value * multipliers[unit];
46
49
  }
47
50
 
48
- /**
49
- * @param {string} raw
50
- * @returns {Set<string>}
51
- */
52
- export function parseUntilDiagnoses(raw) {
53
- const trimmed = String(raw).trim();
54
- if (trimmed.length === 0) {
55
- throw new Error("--until requires a comma-separated diagnosis list");
56
- }
57
-
58
- /** @type {Set<string>} */
59
- const diagnoses = new Set();
60
- for (const part of trimmed.split(",")) {
61
- const diagnosis = part.trim();
62
- if (diagnosis.length === 0) {
63
- throw new Error("--until contains an empty diagnosis entry");
64
- }
65
- if (!VALID_UNTIL_DIAGNOSES.has(diagnosis)) {
66
- throw new Error(
67
- `Unknown diagnosis in --until: ${diagnosis} (valid: ${DIAGNOSIS_TAXONOMY.join(", ")})`,
68
- );
69
- }
70
- diagnoses.add(diagnosis);
71
- }
72
-
73
- return diagnoses;
74
- }
75
-
76
51
  /**
77
52
  * @param {string[]} argv
78
53
  */
@@ -112,17 +87,6 @@ export function parseWaitArgs(argv) {
112
87
  return args;
113
88
  }
114
89
 
115
- /**
116
- * @param {string | null | undefined} diagnosis
117
- * @param {Set<string>} untilDiagnoses
118
- */
119
- export function diagnosisMatchesUntil(diagnosis, untilDiagnoses) {
120
- if (diagnosis == null) {
121
- return false;
122
- }
123
- return untilDiagnoses.has(diagnosis);
124
- }
125
-
126
90
  /**
127
91
  * @param {object} options
128
92
  * @param {string} options.projectRoot
@@ -163,7 +127,7 @@ export async function runSpineWait(options) {
163
127
  const result = reconcileFn({ projectRoot });
164
128
  const diagnosis = result.diagnosis ?? null;
165
129
 
166
- if (diagnosisMatchesUntil(diagnosis, untilDiagnoses)) {
130
+ if (reconciliationMatchesUntil(result, untilDiagnoses)) {
167
131
  if (json) {
168
132
  writeStdout(`${JSON.stringify(buildWatchSnapshot(result, nowFn()))}\n`);
169
133
  }
@@ -3,6 +3,8 @@
3
3
  * Contract defaults are added in SP-142.
4
4
  */
5
5
 
6
+ import { ORCHESTRATOR_DEFAULTS } from "./spine-config-schema.mjs";
7
+
6
8
  /** @type {Readonly<{ requireFinalVerdict: boolean; maxFinalAttempts: number }>} */
7
9
  export const REVIEW_DEFAULTS = Object.freeze({
8
10
  requireFinalVerdict: true,
@@ -38,7 +40,7 @@ export const INTEGRATE_DEFAULTS = Object.freeze({
38
40
  allowHumanOnBaseBranch: "warn",
39
41
  });
40
42
 
41
- /** @type {Readonly<{ review: typeof REVIEW_DEFAULTS; handoff: typeof HANDOFF_DEFAULTS; metrics: typeof METRICS_DEFAULTS; contract: typeof CONTRACT_DEFAULTS; lanes: typeof LANES_DEFAULTS; integrate: typeof INTEGRATE_DEFAULTS }>} */
43
+ /** @type {Readonly<{ review: typeof REVIEW_DEFAULTS; handoff: typeof HANDOFF_DEFAULTS; metrics: typeof METRICS_DEFAULTS; contract: typeof CONTRACT_DEFAULTS; lanes: typeof LANES_DEFAULTS; integrate: typeof INTEGRATE_DEFAULTS; orchestrator: typeof ORCHESTRATOR_DEFAULTS }>} */
42
44
  export const CONFIG_V2_SECTION_DEFAULTS = Object.freeze({
43
45
  review: REVIEW_DEFAULTS,
44
46
  handoff: HANDOFF_DEFAULTS,
@@ -46,4 +48,5 @@ export const CONFIG_V2_SECTION_DEFAULTS = Object.freeze({
46
48
  contract: CONTRACT_DEFAULTS,
47
49
  lanes: LANES_DEFAULTS,
48
50
  integrate: INTEGRATE_DEFAULTS,
51
+ orchestrator: ORCHESTRATOR_DEFAULTS,
49
52
  });
@@ -107,6 +107,29 @@ export const SETTINGS_FIELDS = Object.freeze([
107
107
  type: "enum",
108
108
  enum: ["off", "low", "medium", "high", "inherit"],
109
109
  },
110
+ {
111
+ path: "agents.supervisor.enabled",
112
+ label: "Supervisor monitor enabled",
113
+ type: "boolean",
114
+ },
115
+ {
116
+ path: "agents.supervisor.model",
117
+ label: "Supervisor model",
118
+ type: "string",
119
+ optional: true,
120
+ },
121
+ {
122
+ path: "agents.supervisor.pollIntervalMs",
123
+ label: "Supervisor poll interval (ms)",
124
+ type: "number",
125
+ min: 1000,
126
+ max: 3_600_000,
127
+ },
128
+ {
129
+ path: "agents.supervisor.autoNudge",
130
+ label: "Supervisor auto nudge (deferred)",
131
+ type: "boolean",
132
+ },
110
133
  {
111
134
  path: "dashboard.port",
112
135
  label: "Dashboard port",
@@ -9,6 +9,7 @@ import { validateWorkerBackendConfig } from "./worker-backend.mjs";
9
9
  import { validateWorkerContextConfig } from "./worker-context.mjs";
10
10
  import { validateWorkerLaunchScriptConfig } from "./worker-launch-script.mjs";
11
11
  import { validateWorktreeSetupHookConfig } from "./worktree-setup-hook.mjs";
12
+ import { validateOrchestratorConfig } from "./spine-config-schema.mjs";
12
13
 
13
14
  const REQUIRED_TOP_LEVEL = [
14
15
  "configVersion",
@@ -182,6 +183,11 @@ export function validateSpineConfig(config) {
182
183
  return setupHookError;
183
184
  }
184
185
 
186
+ const orchestratorError = validateOrchestratorConfig(config);
187
+ if (orchestratorError) {
188
+ return orchestratorError;
189
+ }
190
+
185
191
  if (config.worktreeSetupIgnorePaths != null) {
186
192
  if (!Array.isArray(config.worktreeSetupIgnorePaths)) {
187
193
  return {