pi-spine 2.8.0 → 2.10.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/package.json +1 -1
- package/src/batch/contract-exec.mjs +12 -2
- package/src/batch/contract-parse.mjs +55 -0
- package/src/batch/contract-verify.mjs +41 -1
- package/src/batch/engine-lanes/matrix-run.mjs +532 -0
- package/src/batch/engine-lanes/matrix.mjs +314 -0
- package/src/batch/engine-lanes.mjs +81 -48
- package/src/batch/engine.mjs +3 -4
- package/src/batch/journal.mjs +5 -0
- package/src/batch/lane-commit.mjs +54 -4
- package/src/batch/lane-dirty-check-git.mjs +63 -0
- package/src/batch/worker-host.mjs +38 -21
- package/src/batch/worker-spawn.mjs +49 -0
- package/src/cli/wait.mjs +150 -2
- package/src/config/settings-fields.mjs +6 -0
- package/src/config/spine-config-load.mjs +87 -2
- package/src/config/spine-config-schema.mjs +150 -0
- package/src/dashboard/public/dashboard.css +3 -0
- package/src/dashboard/public/dashboard.js +34 -8
- package/src/dashboard/snapshot.mjs +110 -13
- package/src/doctor/agent-models.mjs +43 -18
- package/src/planner/lanes.mjs +42 -8
- package/src/planner/matrix.mjs +122 -0
- package/src/planner/waves.mjs +39 -8
- package/src/tasks/packet/parse-prompt.mjs +40 -1
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
resolveWorkerPiTimeoutMs,
|
|
11
11
|
parseTaskSizeFromFolder,
|
|
12
12
|
} from "./task-stall-budget.mjs";
|
|
13
|
-
import { parseContract } from "../tasks/packet/parse-prompt.mjs";
|
|
13
|
+
import { parseContract, parsePrompt } from "../tasks/packet/parse-prompt.mjs";
|
|
14
14
|
import { appendJournalEvent } from "./journal.mjs";
|
|
15
15
|
import { assertReviewToolAvailable } from "./review.mjs";
|
|
16
16
|
import { finalizeWorkerOutput, createWorkerLiveLogWriter } from "./worker-output.mjs";
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
resolveWorkerLaunchScript,
|
|
23
23
|
resolveWorkerPhase,
|
|
24
24
|
spawnWorkerHandle,
|
|
25
|
+
spawnExecutionOnlyHandle,
|
|
25
26
|
terminateHungWorkerChild,
|
|
26
27
|
CHILD_DONE_TIMEOUT_MS,
|
|
27
28
|
} from "./worker-spawn.mjs";
|
|
@@ -203,32 +204,48 @@ export async function runWorker({
|
|
|
203
204
|
|
|
204
205
|
const taskSize = parseTaskSizeFromFolder(taskFolder);
|
|
205
206
|
const promptPath = path.join(taskFolder, "PROMPT.md");
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
const promptText = fs.existsSync(promptPath) ? fs.readFileSync(promptPath, "utf-8") : "";
|
|
208
|
+
const parsedPrompt = promptText ? parsePrompt(promptText) : null;
|
|
209
|
+
const contract = promptText ? parseContract(promptText) : { stallTimeoutMinutes: null, extendGraceOnFileScope: null, runCommand: null, testCommand: null };
|
|
209
210
|
const stallConfig = resolveStallConfigForTask({ config, taskSize, contract });
|
|
210
211
|
const piTimeoutMs = resolveWorkerPiTimeoutMs({ config, taskSize, contract });
|
|
211
212
|
const startedAt = Date.now();
|
|
212
213
|
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
214
|
+
const isExecute = parsedPrompt?.type === "execute";
|
|
215
|
+
const runCommand = contract.runCommand || contract.testCommand;
|
|
216
|
+
|
|
217
|
+
const child = isExecute
|
|
218
|
+
? spawnExecutionOnlyHandle({
|
|
219
|
+
worktreePath,
|
|
220
|
+
taskFolder,
|
|
221
|
+
command: runCommand || "echo 'No runCommand or testCommand provided' && exit 1",
|
|
222
|
+
projectRoot,
|
|
223
|
+
batchId,
|
|
224
|
+
laneNumber,
|
|
225
|
+
taskId,
|
|
226
|
+
laneCorrelationId,
|
|
227
|
+
fileScopePaths,
|
|
228
|
+
config,
|
|
229
|
+
})
|
|
230
|
+
: spawnWorkerHandle({
|
|
231
|
+
worktreePath,
|
|
232
|
+
taskFolder,
|
|
233
|
+
useStub,
|
|
234
|
+
timeoutMs: piTimeoutMs,
|
|
235
|
+
piTimeoutMs,
|
|
236
|
+
projectRoot,
|
|
237
|
+
batchId,
|
|
238
|
+
laneNumber,
|
|
239
|
+
taskId,
|
|
240
|
+
laneCorrelationId,
|
|
241
|
+
fileScopePaths,
|
|
242
|
+
config,
|
|
243
|
+
workerBackendDeps,
|
|
244
|
+
});
|
|
228
245
|
const workerChild = /** @type {WorkerChildHandle} */ (child);
|
|
229
|
-
let childPastPreflight = !useLaunchScript;
|
|
246
|
+
let childPastPreflight = isExecute ? true : !useLaunchScript;
|
|
230
247
|
/** @type {WorkerPhase} */
|
|
231
|
-
const initialWorkerPhase = resolveWorkerPhase({ childPastPreflight, useStub, workerBackend });
|
|
248
|
+
const initialWorkerPhase = isExecute ? "pi" : resolveWorkerPhase({ childPastPreflight, useStub, workerBackend });
|
|
232
249
|
markChildPastPreflight(workerChild, () => {
|
|
233
250
|
childPastPreflight = true;
|
|
234
251
|
});
|
|
@@ -167,6 +167,55 @@ export function spawnWorkerChild({
|
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* @param {object} params
|
|
172
|
+
* @param {string} params.worktreePath
|
|
173
|
+
* @param {string} params.taskFolder
|
|
174
|
+
* @param {string} params.command
|
|
175
|
+
* @param {string} [params.projectRoot]
|
|
176
|
+
* @param {string} [params.batchId]
|
|
177
|
+
* @param {number} [params.laneNumber]
|
|
178
|
+
* @param {string} [params.taskId]
|
|
179
|
+
* @param {string} [params.laneCorrelationId]
|
|
180
|
+
* @param {string[]} [params.fileScopePaths]
|
|
181
|
+
* @param {object} [params.config]
|
|
182
|
+
*/
|
|
183
|
+
export function spawnExecutionOnlyHandle({
|
|
184
|
+
worktreePath,
|
|
185
|
+
taskFolder,
|
|
186
|
+
command,
|
|
187
|
+
projectRoot,
|
|
188
|
+
batchId,
|
|
189
|
+
laneNumber,
|
|
190
|
+
taskId,
|
|
191
|
+
laneCorrelationId,
|
|
192
|
+
fileScopePaths = [],
|
|
193
|
+
config = {},
|
|
194
|
+
}) {
|
|
195
|
+
const env = buildWorkerChildEnv({
|
|
196
|
+
taskFolder,
|
|
197
|
+
worktreePath,
|
|
198
|
+
projectRoot,
|
|
199
|
+
batchId,
|
|
200
|
+
laneNumber,
|
|
201
|
+
taskId,
|
|
202
|
+
laneCorrelationId,
|
|
203
|
+
fileScopePaths,
|
|
204
|
+
config,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Create a wrapper script that runs the command and then creates .DONE
|
|
208
|
+
// This matches the behavior expected by the heartbeat loop.
|
|
209
|
+
// We run `/bin/sh -c "<command> && touch .DONE"`
|
|
210
|
+
const script = `${command} && touch "${path.join(taskFolder, ".DONE")}"`;
|
|
211
|
+
|
|
212
|
+
return spawn("/bin/sh", ["-c", script], {
|
|
213
|
+
cwd: worktreePath,
|
|
214
|
+
env,
|
|
215
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
170
219
|
/**
|
|
171
220
|
* @param {WorkerChildHandle} child
|
|
172
221
|
* @param {() => void} onPreflightComplete
|
package/src/cli/wait.mjs
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Block until reconcile diagnosis reaches a target set (issue #46, SP-362).
|
|
3
|
+
*
|
|
4
|
+
* Batch-scoped since #215: the wait records the batch id at start and exits with a
|
|
5
|
+
* distinct `archived`/`superseded` status if another operator session integrates or
|
|
6
|
+
* supersedes that batch while we are waiting — it never re-diagnoses the newly active
|
|
7
|
+
* batch or re-drives land/recovery prompts for it.
|
|
3
8
|
*/
|
|
4
9
|
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
|
|
5
13
|
import { reconcileBatch } from "../batch/reconcile.mjs";
|
|
6
14
|
import { parseUntilDiagnoses, reconciliationMatchesUntil } from "./spine-wait.mjs";
|
|
7
15
|
import {
|
|
@@ -87,6 +95,78 @@ export function parseWaitArgs(argv) {
|
|
|
87
95
|
return args;
|
|
88
96
|
}
|
|
89
97
|
|
|
98
|
+
/** Exit code when the waited-on batch was archived or superseded by another session (#215). */
|
|
99
|
+
export const WAIT_SUPERSEDED_EXIT_CODE = 2;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Read the archived batch-state for a scoped batch id (#215). Archived batches are copied
|
|
103
|
+
* to `.spine/runtime/{batchId}/archive/batch-state.json` on integrate/complete (see
|
|
104
|
+
* `src/batch/lifecycle-archive.mjs`). Lets wait report the real terminal phase instead of
|
|
105
|
+
* the newly active batch. Leaf read — never throws.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} projectRoot
|
|
108
|
+
* @param {string} scopedBatchId
|
|
109
|
+
* @returns {{ archivedPhase: string | null, archivedAt: string | null }}
|
|
110
|
+
*/
|
|
111
|
+
function readArchivedBatchRecord(projectRoot, scopedBatchId) {
|
|
112
|
+
try {
|
|
113
|
+
const archivePath = path.join(
|
|
114
|
+
projectRoot,
|
|
115
|
+
".spine",
|
|
116
|
+
"runtime",
|
|
117
|
+
scopedBatchId,
|
|
118
|
+
"archive",
|
|
119
|
+
"batch-state.json",
|
|
120
|
+
);
|
|
121
|
+
if (!fs.existsSync(archivePath)) {
|
|
122
|
+
return { archivedPhase: null, archivedAt: null };
|
|
123
|
+
}
|
|
124
|
+
const raw = JSON.parse(fs.readFileSync(archivePath, "utf-8"));
|
|
125
|
+
const archivedPhase =
|
|
126
|
+
raw && typeof raw === "object" && raw.phase != null ? String(raw.phase) : null;
|
|
127
|
+
const archivedAt =
|
|
128
|
+
raw && typeof raw === "object" && raw.endedAt != null ? String(raw.endedAt) : null;
|
|
129
|
+
return { archivedPhase, archivedAt };
|
|
130
|
+
} catch {
|
|
131
|
+
return { archivedPhase: null, archivedAt: null };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Human headline for the batch-scoped supersede/archived exit (#215). Ambiguous-free: it
|
|
137
|
+
* names the scoped batch and never references the new active batch's recovery state.
|
|
138
|
+
*/
|
|
139
|
+
function formatSupersededHeadline({ scopedBatchId, activeBatchId, batchScope, archive }) {
|
|
140
|
+
if (batchScope === "archived") {
|
|
141
|
+
const phaseSuffix = archive.archivedPhase ? ` (archived as ${archive.archivedPhase})` : "";
|
|
142
|
+
return `Batch ${scopedBatchId} was archived${phaseSuffix} by another session — no longer the active batch`;
|
|
143
|
+
}
|
|
144
|
+
return `Batch ${scopedBatchId} was superseded by batch ${activeBatchId} — no longer the active batch`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Build the batch-scoped snapshot emitted when the waited-on batch was archived or
|
|
149
|
+
* superseded (#215). Scoped to the original batch id; never reflects the new active batch.
|
|
150
|
+
*/
|
|
151
|
+
function buildSupersededSnapshot({ scopedBatchId, activeBatchId, batchScope, archive, observedAt }) {
|
|
152
|
+
const snapshot = buildWatchSnapshot(
|
|
153
|
+
{
|
|
154
|
+
diagnosis: null,
|
|
155
|
+
batchId: scopedBatchId,
|
|
156
|
+
phase: archive.archivedPhase,
|
|
157
|
+
macroPhase: "archived",
|
|
158
|
+
macroPhaseLabel: archive.archivedPhase ? `Archived (${archive.archivedPhase})` : "Archived",
|
|
159
|
+
headline: formatSupersededHeadline({ scopedBatchId, activeBatchId, batchScope, archive }),
|
|
160
|
+
suggestedCommand: "spine status --diagnose",
|
|
161
|
+
},
|
|
162
|
+
observedAt,
|
|
163
|
+
);
|
|
164
|
+
snapshot.activeBatchId = activeBatchId;
|
|
165
|
+
snapshot.batchScope = batchScope;
|
|
166
|
+
snapshot.archivedPhase = archive.archivedPhase;
|
|
167
|
+
return snapshot;
|
|
168
|
+
}
|
|
169
|
+
|
|
90
170
|
/**
|
|
91
171
|
* @param {object} options
|
|
92
172
|
* @param {string} options.projectRoot
|
|
@@ -110,6 +190,7 @@ export async function runSpineWait(options) {
|
|
|
110
190
|
sleepFn = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
111
191
|
nowFn = () => Date.now(),
|
|
112
192
|
writeStdout = (text) => process.stdout.write(text),
|
|
193
|
+
writeStderr = (text) => process.stderr.write(text),
|
|
113
194
|
} = options;
|
|
114
195
|
|
|
115
196
|
const startedAt = nowFn();
|
|
@@ -122,23 +203,90 @@ export async function runSpineWait(options) {
|
|
|
122
203
|
};
|
|
123
204
|
process.on("SIGINT", onSigInt);
|
|
124
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Batch id this wait is scoped to (#215). Captured from the first reconcile that
|
|
208
|
+
* observes an active batch so the wait never reports on a batch another operator
|
|
209
|
+
* session integrated/superseded while we were waiting.
|
|
210
|
+
*/
|
|
211
|
+
let scopedBatchId = null;
|
|
212
|
+
let scopedBatchIdCaptured = false;
|
|
213
|
+
|
|
125
214
|
try {
|
|
126
215
|
while (running) {
|
|
127
216
|
const result = reconcileFn({ projectRoot });
|
|
217
|
+
if (!scopedBatchIdCaptured) {
|
|
218
|
+
const candidate = result.batchId ?? null;
|
|
219
|
+
if (candidate != null) {
|
|
220
|
+
scopedBatchId = candidate;
|
|
221
|
+
scopedBatchIdCaptured = true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
128
224
|
const diagnosis = result.diagnosis ?? null;
|
|
129
225
|
|
|
226
|
+
// Batch-scoped guard (#215): the active batch drifted away from the one we
|
|
227
|
+
// started waiting on, so another session integrated/superseded it. Exit promptly
|
|
228
|
+
// with a distinct status instead of re-diagnosing the new batch and re-driving
|
|
229
|
+
// land/recovery prompts for it. This check runs before the match check on
|
|
230
|
+
// purpose — any match against the new batch would be a false positive.
|
|
231
|
+
if (scopedBatchId != null && (result.batchId ?? null) !== scopedBatchId) {
|
|
232
|
+
const activeBatchId = result.batchId ?? null;
|
|
233
|
+
const batchScope = activeBatchId == null ? "archived" : "superseded";
|
|
234
|
+
const archive = readArchivedBatchRecord(projectRoot, scopedBatchId);
|
|
235
|
+
const observedAt = nowFn();
|
|
236
|
+
if (json) {
|
|
237
|
+
writeStdout(
|
|
238
|
+
`${JSON.stringify(
|
|
239
|
+
buildSupersededSnapshot({
|
|
240
|
+
scopedBatchId,
|
|
241
|
+
activeBatchId,
|
|
242
|
+
batchScope,
|
|
243
|
+
archive,
|
|
244
|
+
observedAt,
|
|
245
|
+
}),
|
|
246
|
+
)}\n`,
|
|
247
|
+
);
|
|
248
|
+
} else {
|
|
249
|
+
writeStderr(
|
|
250
|
+
`${formatSupersededHeadline({ scopedBatchId, activeBatchId, batchScope, archive })}\n`,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
exitCode: WAIT_SUPERSEDED_EXIT_CODE,
|
|
255
|
+
matched: false,
|
|
256
|
+
diagnosis: null,
|
|
257
|
+
timedOut: false,
|
|
258
|
+
superseded: true,
|
|
259
|
+
batchScope,
|
|
260
|
+
batchId: scopedBatchId,
|
|
261
|
+
activeBatchId,
|
|
262
|
+
archivedPhase: archive.archivedPhase,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
130
266
|
if (reconciliationMatchesUntil(result, untilDiagnoses)) {
|
|
131
267
|
if (json) {
|
|
132
268
|
writeStdout(`${JSON.stringify(buildWatchSnapshot(result, nowFn()))}\n`);
|
|
133
269
|
}
|
|
134
|
-
return {
|
|
270
|
+
return {
|
|
271
|
+
exitCode: 0,
|
|
272
|
+
matched: true,
|
|
273
|
+
diagnosis,
|
|
274
|
+
timedOut: false,
|
|
275
|
+
batchId: scopedBatchId,
|
|
276
|
+
};
|
|
135
277
|
}
|
|
136
278
|
|
|
137
279
|
if (deadline != null && nowFn() >= deadline) {
|
|
138
280
|
if (json) {
|
|
139
281
|
writeStdout(`${JSON.stringify(buildWatchSnapshot(result, nowFn()))}\n`);
|
|
140
282
|
}
|
|
141
|
-
return {
|
|
283
|
+
return {
|
|
284
|
+
exitCode: 1,
|
|
285
|
+
matched: false,
|
|
286
|
+
diagnosis,
|
|
287
|
+
timedOut: true,
|
|
288
|
+
batchId: scopedBatchId,
|
|
289
|
+
};
|
|
142
290
|
}
|
|
143
291
|
|
|
144
292
|
await sleepFn(intervalSec * 1000);
|
|
@@ -131,6 +131,12 @@ export const SETTINGS_FIELDS = Object.freeze([
|
|
|
131
131
|
label: "Supervisor auto nudge (deferred)",
|
|
132
132
|
type: "boolean",
|
|
133
133
|
},
|
|
134
|
+
{
|
|
135
|
+
path: "agents.activeProfile",
|
|
136
|
+
label: "Active agent model profile",
|
|
137
|
+
type: "string",
|
|
138
|
+
optional: true,
|
|
139
|
+
},
|
|
134
140
|
{
|
|
135
141
|
path: "dashboard.port",
|
|
136
142
|
label: "Dashboard port",
|
|
@@ -10,7 +10,7 @@ import { validateWorkerBackendConfig } from "./worker-backend.mjs";
|
|
|
10
10
|
import { validateWorkerContextConfig } from "./worker-context.mjs";
|
|
11
11
|
import { validateWorkerLaunchScriptConfig } from "./worker-launch-script.mjs";
|
|
12
12
|
import { validateWorktreeSetupHookConfig } from "./worktree-setup-hook.mjs";
|
|
13
|
-
import { validateOrchestratorConfig } from "./spine-config-schema.mjs";
|
|
13
|
+
import { validateOrchestratorConfig, validateAgentProfilesConfig } from "./spine-config-schema.mjs";
|
|
14
14
|
import { missingConfigHint } from "./missing-config-hint.mjs";
|
|
15
15
|
|
|
16
16
|
export { resolveGatePostureConfig } from "./gate-posture-config.mjs";
|
|
@@ -38,6 +38,82 @@ export function resolveWorktreeSetupIgnorePaths(config) {
|
|
|
38
38
|
return [...new Set([...DEFAULT_WORKTREE_SETUP_IGNORE_PATHS, ...configured])];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// --- Named agent model profile resolution (SP-664 / GitHub #216) ---
|
|
42
|
+
|
|
43
|
+
/** Agent sections that a named profile may override on top of the base agents config. */
|
|
44
|
+
const AGENT_SECTIONS = Object.freeze(["worker", "reviewer", "supervisor"]);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {unknown} value
|
|
48
|
+
* @returns {value is Record<string, unknown>}
|
|
49
|
+
*/
|
|
50
|
+
function isPlainObject(value) {
|
|
51
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Deep-merge `override` over `base` for a single agent section.
|
|
56
|
+
*
|
|
57
|
+
* Profile values win; base fills gaps. Recurses into plain objects so a profile's
|
|
58
|
+
* nested reviewer `plan`/`code`/`final` pins merge without clobbering siblings
|
|
59
|
+
* left at their base value.
|
|
60
|
+
*
|
|
61
|
+
* @param {unknown} base
|
|
62
|
+
* @param {Record<string, unknown>} override
|
|
63
|
+
* @returns {Record<string, unknown>}
|
|
64
|
+
*/
|
|
65
|
+
function deepMergeAgentSection(base, override) {
|
|
66
|
+
const out = isPlainObject(base) ? structuredClone(base) : {};
|
|
67
|
+
for (const [key, value] of Object.entries(override)) {
|
|
68
|
+
if (isPlainObject(value) && isPlainObject(out[key])) {
|
|
69
|
+
out[key] = deepMergeAgentSection(out[key], value);
|
|
70
|
+
} else if (isPlainObject(value)) {
|
|
71
|
+
out[key] = structuredClone(value);
|
|
72
|
+
} else {
|
|
73
|
+
out[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Resolve the named active agent profile over the base `agents` config.
|
|
81
|
+
*
|
|
82
|
+
* Each profile mirrors the base `worker`/`reviewer`/`supervisor` shape. When
|
|
83
|
+
* `agents.activeProfile` names a defined `agents.profiles` entry, that profile is
|
|
84
|
+
* deep-merged over the base agents (profile wins, base fills gaps) so downstream
|
|
85
|
+
* consumers — worker/reviewer/supervisor spawns and `spine doctor` — observe the
|
|
86
|
+
* effective configuration rather than the raw base.
|
|
87
|
+
*
|
|
88
|
+
* Pure: returns a new config object and never mutates the input. No-op when no
|
|
89
|
+
* active profile is set or the named profile does not exist.
|
|
90
|
+
*
|
|
91
|
+
* @param {Record<string, any>} config Effective config (defaults + env already applied).
|
|
92
|
+
* @returns {Record<string, any>} Config with the active profile resolved into `agents`.
|
|
93
|
+
*/
|
|
94
|
+
export function applyActiveAgentProfile(config) {
|
|
95
|
+
const result = structuredClone(config);
|
|
96
|
+
const agents = result?.agents;
|
|
97
|
+
if (!isPlainObject(agents)) return result;
|
|
98
|
+
|
|
99
|
+
const active = agents.activeProfile;
|
|
100
|
+
if (typeof active !== "string" || active.trim() === "") return result;
|
|
101
|
+
|
|
102
|
+
const profiles = agents.profiles;
|
|
103
|
+
if (!isPlainObject(profiles)) return result;
|
|
104
|
+
|
|
105
|
+
const profile = profiles[active.trim()];
|
|
106
|
+
if (!isPlainObject(profile)) return result;
|
|
107
|
+
|
|
108
|
+
for (const section of AGENT_SECTIONS) {
|
|
109
|
+
const override = profile[section];
|
|
110
|
+
if (isPlainObject(override)) {
|
|
111
|
+
agents[section] = deepMergeAgentSection(agents[section], override);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
41
117
|
const REQUIRED_TOP_LEVEL = [
|
|
42
118
|
"configVersion",
|
|
43
119
|
"project",
|
|
@@ -141,9 +217,13 @@ export function loadSpineConfig(projectRoot) {
|
|
|
141
217
|
// Soft attach: posture merge fails closed inside the helper and never rejects load.
|
|
142
218
|
const gatePostureConfig = resolveGatePostureConfig(envResult.config);
|
|
143
219
|
|
|
220
|
+
// SP-664 / #216: resolve the named active agent profile over the base agents config
|
|
221
|
+
// so spawns and doctor observe effective (base + profile) model pins.
|
|
222
|
+
const resolvedConfig = applyActiveAgentProfile(envResult.config);
|
|
223
|
+
|
|
144
224
|
return {
|
|
145
225
|
configPath: fileResult.configPath,
|
|
146
|
-
config:
|
|
226
|
+
config: resolvedConfig,
|
|
147
227
|
fileConfig: config,
|
|
148
228
|
gatePostureConfig,
|
|
149
229
|
sources: envResult.sources,
|
|
@@ -223,6 +303,11 @@ export function validateSpineConfig(config) {
|
|
|
223
303
|
return orchestratorError;
|
|
224
304
|
}
|
|
225
305
|
|
|
306
|
+
const profilesError = validateAgentProfilesConfig(config);
|
|
307
|
+
if (profilesError) {
|
|
308
|
+
return profilesError;
|
|
309
|
+
}
|
|
310
|
+
|
|
226
311
|
if (config.worktreeSetupIgnorePaths != null) {
|
|
227
312
|
if (!Array.isArray(config.worktreeSetupIgnorePaths)) {
|
|
228
313
|
return {
|
|
@@ -120,3 +120,153 @@ export function resolveDashboardPollMs({ config = {} } = {}) {
|
|
|
120
120
|
}
|
|
121
121
|
return DEFAULT_DASHBOARD_POLL_MS;
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
// --- Named agent model profiles (SP-664 / GitHub #216) ---
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Model-field accessors shared by schema validation and doctor checks.
|
|
128
|
+
* Each accessor reads a model id from an `agents`-shaped object
|
|
129
|
+
* (the base `agents` section or any named `agents.profiles.<name>` entry).
|
|
130
|
+
* @type {ReadonlyArray<{ rel: string, get: (agents: any) => unknown }>}
|
|
131
|
+
*/
|
|
132
|
+
export const AGENT_MODEL_ACCESSORS = Object.freeze([
|
|
133
|
+
{ rel: "worker.model", get: (agents) => agents?.worker?.model },
|
|
134
|
+
{ rel: "reviewer.model", get: (agents) => agents?.reviewer?.model },
|
|
135
|
+
{ rel: "reviewer.plan.model", get: (agents) => agents?.reviewer?.plan?.model },
|
|
136
|
+
{ rel: "reviewer.code.model", get: (agents) => agents?.reviewer?.code?.model },
|
|
137
|
+
{ rel: "reviewer.final.model", get: (agents) => agents?.reviewer?.final?.model },
|
|
138
|
+
{ rel: "supervisor.model", get: (agents) => agents?.supervisor?.model },
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {unknown} value
|
|
143
|
+
* @returns {value is Record<string, unknown>}
|
|
144
|
+
*/
|
|
145
|
+
function isPlainObject(value) {
|
|
146
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Type-check every model field reachable from an agents-shaped object so malformed
|
|
151
|
+
* profile sections (e.g. numeric model ids) fail fast at validation time rather than
|
|
152
|
+
* surfacing later as a downstream spawn error.
|
|
153
|
+
*
|
|
154
|
+
* @param {any} agents An agents-shaped object (base section or named profile).
|
|
155
|
+
* @param {string} label Dotted prefix used in error messages.
|
|
156
|
+
* @returns {null | { code: string; message: string; suggestedCommand: string }}
|
|
157
|
+
*/
|
|
158
|
+
function validateAgentSectionModelTypes(agents, label) {
|
|
159
|
+
for (const { rel, get } of AGENT_MODEL_ACCESSORS) {
|
|
160
|
+
const value = get(agents);
|
|
161
|
+
if (value != null && typeof value !== "string") {
|
|
162
|
+
return {
|
|
163
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
164
|
+
message: `${label}.${rel} must be a string when set`,
|
|
165
|
+
suggestedCommand: "spine init --force",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Validate `agents.profiles`, `agents.activeProfile`, and `agents.escalatePolicy`.
|
|
174
|
+
*
|
|
175
|
+
* Named profiles mirror the base `worker`/`reviewer`/`supervisor` shape; the active
|
|
176
|
+
* profile is resolved over base at load time (see `applyActiveAgentProfile`).
|
|
177
|
+
* Structural validation only — canonical model-id format is checked by `spine doctor`.
|
|
178
|
+
*
|
|
179
|
+
* @param {Record<string, any>} config
|
|
180
|
+
* @returns {null | { code: string; message: string; suggestedCommand: string }}
|
|
181
|
+
*/
|
|
182
|
+
export function validateAgentProfilesConfig(config) {
|
|
183
|
+
const agents = config?.agents;
|
|
184
|
+
if (agents == null || !isPlainObject(agents)) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const profiles = agents.profiles;
|
|
189
|
+
if (profiles != null) {
|
|
190
|
+
if (!isPlainObject(profiles)) {
|
|
191
|
+
return {
|
|
192
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
193
|
+
message: "agents.profiles must be an object keyed by profile name",
|
|
194
|
+
suggestedCommand: "spine init --force",
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
for (const [name, profile] of Object.entries(profiles)) {
|
|
198
|
+
if (!isPlainObject(profile)) {
|
|
199
|
+
return {
|
|
200
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
201
|
+
message: `agents.profiles.${name} must be an object mirroring worker/reviewer/supervisor`,
|
|
202
|
+
suggestedCommand: "spine init --force",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const shapeError = validateAgentSectionModelTypes(profile, `agents.profiles.${name}`);
|
|
206
|
+
if (shapeError) return shapeError;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const activeProfile = agents.activeProfile;
|
|
211
|
+
if (activeProfile != null) {
|
|
212
|
+
if (typeof activeProfile !== "string") {
|
|
213
|
+
return {
|
|
214
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
215
|
+
message: "agents.activeProfile must be a string when set",
|
|
216
|
+
suggestedCommand: "spine settings set agents.activeProfile default",
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const trimmed = activeProfile.trim();
|
|
220
|
+
// An empty/whitespace value clears the active profile; otherwise it must name a real profile.
|
|
221
|
+
if (
|
|
222
|
+
trimmed !== "" &&
|
|
223
|
+
(!isPlainObject(profiles) || !Object.prototype.hasOwnProperty.call(profiles, trimmed))
|
|
224
|
+
) {
|
|
225
|
+
return {
|
|
226
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
227
|
+
message: `agents.activeProfile "${trimmed}" does not match a defined agents.profiles entry`,
|
|
228
|
+
suggestedCommand: "spine settings set agents.activeProfile default",
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const escalatePolicy = agents.escalatePolicy;
|
|
234
|
+
if (escalatePolicy != null) {
|
|
235
|
+
if (!isPlainObject(escalatePolicy)) {
|
|
236
|
+
return {
|
|
237
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
238
|
+
message: "agents.escalatePolicy must be an object when set",
|
|
239
|
+
suggestedCommand: "spine init --force",
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (escalatePolicy.enabled != null && typeof escalatePolicy.enabled !== "boolean") {
|
|
243
|
+
return {
|
|
244
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
245
|
+
message: "agents.escalatePolicy.enabled must be a boolean when set",
|
|
246
|
+
suggestedCommand: "spine settings set agents.escalatePolicy.enabled true",
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (escalatePolicy.toProfile != null) {
|
|
250
|
+
if (typeof escalatePolicy.toProfile !== "string") {
|
|
251
|
+
return {
|
|
252
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
253
|
+
message: "agents.escalatePolicy.toProfile must be a string when set",
|
|
254
|
+
suggestedCommand: "spine init --force",
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const target = escalatePolicy.toProfile.trim();
|
|
258
|
+
if (
|
|
259
|
+
target !== "" &&
|
|
260
|
+
(!isPlainObject(profiles) || !Object.prototype.hasOwnProperty.call(profiles, target))
|
|
261
|
+
) {
|
|
262
|
+
return {
|
|
263
|
+
code: "CONFIG_AGENT_PROFILE_INVALID",
|
|
264
|
+
message: `agents.escalatePolicy.toProfile "${target}" does not match a defined agents.profiles entry`,
|
|
265
|
+
suggestedCommand: "spine settings set agents.escalatePolicy.toProfile hard",
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
@@ -78,6 +78,9 @@ body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
|
|
|
78
78
|
.table-wrap { overflow-x: auto; }
|
|
79
79
|
.lane-task-running { color: var(--running); font-weight: 600; }
|
|
80
80
|
.lane-task-queued { color: var(--text); }
|
|
81
|
+
/* Running cell now carries the task title (#214): cap its width and let long
|
|
82
|
+
titles wrap rather than stretching the lane table off-screen. */
|
|
83
|
+
.lane-table td.col-running { max-width: 22rem; overflow-wrap: anywhere; }
|
|
81
84
|
@media (max-width: 720px) {
|
|
82
85
|
.lane-table th.col-running,
|
|
83
86
|
.lane-table th.col-queued,
|