pi-spine 2.8.0 → 2.9.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/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/package.json
CHANGED
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,
|
|
@@ -161,10 +161,17 @@ function renderWaves(waves) {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
/**
|
|
165
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Running cell text. Shows the task title alongside the id when the snapshot
|
|
166
|
+
* payload resolved one (PRD §16, #214); falls back to the id-only form when the
|
|
167
|
+
* title is unavailable so the cell never goes blank.
|
|
168
|
+
*
|
|
169
|
+
* @param {string|null|undefined} taskId
|
|
170
|
+
* @param {string|null|undefined} title
|
|
171
|
+
*/
|
|
172
|
+
function formatRunningCell(taskId, title) {
|
|
166
173
|
if (!taskId) return "—";
|
|
167
|
-
return `▶ ${taskId}`;
|
|
174
|
+
return title ? `▶ ${taskId} — ${title}` : `▶ ${taskId}`;
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
/** @param {string[]} taskIds */
|
|
@@ -173,10 +180,16 @@ function formatQueuedCell(taskIds) {
|
|
|
173
180
|
return taskIds.map((id) => `○ ${id}`).join(", ");
|
|
174
181
|
}
|
|
175
182
|
|
|
176
|
-
/**
|
|
177
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Accessible label for the running cell. Mirrors the visible text so screen
|
|
185
|
+
* readers announce the task title, not just the id.
|
|
186
|
+
*
|
|
187
|
+
* @param {string|null|undefined} taskId
|
|
188
|
+
* @param {string|null|undefined} title
|
|
189
|
+
*/
|
|
190
|
+
function runningCellAriaLabel(taskId, title) {
|
|
178
191
|
if (!taskId) return "No running task";
|
|
179
|
-
return `Running task ${taskId}`;
|
|
192
|
+
return title ? `Running task ${taskId} — ${title}` : `Running task ${taskId}`;
|
|
180
193
|
}
|
|
181
194
|
|
|
182
195
|
/** @param {string[]} taskIds */
|
|
@@ -218,6 +231,15 @@ function renderLanes(lanes, laneTableSummary, tailActivity, expandedLaneId) {
|
|
|
218
231
|
tbody.appendChild(tr);
|
|
219
232
|
return;
|
|
220
233
|
}
|
|
234
|
+
// The lane-table VM projection (view.mjs) does not carry the title, so look it
|
|
235
|
+
// up from the raw snapshot payload where Step 0 attaches `runningTaskTitle`.
|
|
236
|
+
/** @type {Map<string, string>} */
|
|
237
|
+
const runningTitleById = new Map();
|
|
238
|
+
for (const rawLane of lastSnapshot?.lanes ?? []) {
|
|
239
|
+
if (rawLane?.runningTaskId != null && rawLane.runningTaskTitle) {
|
|
240
|
+
runningTitleById.set(String(rawLane.runningTaskId), rawLane.runningTaskTitle);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
221
243
|
for (const lane of lanes) {
|
|
222
244
|
const tr = document.createElement("tr");
|
|
223
245
|
tr.className = "lane-row";
|
|
@@ -253,7 +275,11 @@ function renderLanes(lanes, laneTableSummary, tailActivity, expandedLaneId) {
|
|
|
253
275
|
} else {
|
|
254
276
|
statusLabel = lane.status;
|
|
255
277
|
}
|
|
256
|
-
const
|
|
278
|
+
const runningTitle =
|
|
279
|
+
lane.runningTaskId != null
|
|
280
|
+
? runningTitleById.get(String(lane.runningTaskId))
|
|
281
|
+
: undefined;
|
|
282
|
+
const runningText = formatRunningCell(lane.runningTaskId, runningTitle);
|
|
257
283
|
const queuedText = formatQueuedCell(lane.queuedTaskIds ?? []);
|
|
258
284
|
const cellSpecs = [
|
|
259
285
|
{ text: lane.laneId, className: "", ariaLabel: null },
|
|
@@ -262,7 +288,7 @@ function renderLanes(lanes, laneTableSummary, tailActivity, expandedLaneId) {
|
|
|
262
288
|
{
|
|
263
289
|
text: runningText,
|
|
264
290
|
className: "lane-task-running",
|
|
265
|
-
ariaLabel: runningCellAriaLabel(lane.runningTaskId),
|
|
291
|
+
ariaLabel: runningCellAriaLabel(lane.runningTaskId, runningTitle),
|
|
266
292
|
},
|
|
267
293
|
{
|
|
268
294
|
text: queuedText,
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Thin assembly: `buildDashboardSnapshot` composes snapshot-lanes and snapshot-waves.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
6
8
|
import { deriveMacroPhase, macroPhaseLabel } from "../batch/macro-phase.mjs";
|
|
7
9
|
import {
|
|
8
10
|
classifyTasks,
|
|
@@ -28,6 +30,7 @@ import {
|
|
|
28
30
|
readMetricsLines,
|
|
29
31
|
} from "../batch/metrics.mjs";
|
|
30
32
|
import { consumeDashboardInvalidateSignal } from "./cache-invalidate.mjs";
|
|
33
|
+
import { parsePrompt } from "../tasks/packet/parse-prompt.mjs";
|
|
31
34
|
import { buildLaneRows } from "./snapshot-lanes.mjs";
|
|
32
35
|
import {
|
|
33
36
|
buildDefaultViewStatus,
|
|
@@ -109,6 +112,97 @@ export function enrichLaneRowsWithSubprocessHeartbeat(lanes, journalEvents, now
|
|
|
109
112
|
});
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
/**
|
|
116
|
+
* In-memory cache of parsed task titles keyed by absolute PROMPT.md path.
|
|
117
|
+
* Titles are immutable per file; mtime invalidates the entry so edits show up.
|
|
118
|
+
* Keyed by path (not taskId) so distinct project roots never cross-contaminate.
|
|
119
|
+
* @type {Map<string, { mtimeMs: number, title: string | null }>}
|
|
120
|
+
*/
|
|
121
|
+
const taskTitleCache = new Map();
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Read and parse a single PROMPT.md title with mtime-aware caching.
|
|
125
|
+
* Any read/parse failure degrades gracefully to null (PRD: graceful fallback).
|
|
126
|
+
*
|
|
127
|
+
* @param {string} promptPath Absolute path to a task PROMPT.md
|
|
128
|
+
* @returns {string | null}
|
|
129
|
+
*/
|
|
130
|
+
function readTaskTitleFromPrompt(promptPath) {
|
|
131
|
+
try {
|
|
132
|
+
const stat = fs.statSync(promptPath);
|
|
133
|
+
const cached = taskTitleCache.get(promptPath);
|
|
134
|
+
if (cached && cached.mtimeMs === stat.mtimeMs) return cached.title;
|
|
135
|
+
const title = parsePrompt(fs.readFileSync(promptPath, "utf-8")).title ?? null;
|
|
136
|
+
taskTitleCache.set(promptPath, { mtimeMs: stat.mtimeMs, title });
|
|
137
|
+
return title;
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Resolve the absolute PROMPT.md path for a task. Uses the batch's `taskFolder`
|
|
145
|
+
* when present, falling back to scanning the tasks root for `${taskId}-*`.
|
|
146
|
+
*
|
|
147
|
+
* @param {string} tasksRootPath Absolute tasks root directory
|
|
148
|
+
* @param {string} taskId
|
|
149
|
+
* @param {string | null | undefined} taskFolder
|
|
150
|
+
* @returns {string | null}
|
|
151
|
+
*/
|
|
152
|
+
function resolveTaskPromptPath(tasksRootPath, taskId, taskFolder) {
|
|
153
|
+
if (taskFolder) {
|
|
154
|
+
return path.join(tasksRootPath, taskFolder, "PROMPT.md");
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
for (const name of fs.readdirSync(tasksRootPath)) {
|
|
158
|
+
if (name.startsWith(`${taskId}-`)) {
|
|
159
|
+
return path.join(tasksRootPath, name, "PROMPT.md");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch {
|
|
163
|
+
// Tasks root missing or unreadable — degrade to no title.
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Build a taskId → title map by parsing each task's PROMPT.md.
|
|
170
|
+
*
|
|
171
|
+
* @param {string} projectRoot
|
|
172
|
+
* @param {string | null | undefined} tasksRoot Configured tasks root (relative to projectRoot)
|
|
173
|
+
* @param {Array<{ taskId?: unknown, taskFolder?: string | null }> | null | undefined} tasks
|
|
174
|
+
* @returns {Map<string, string | null>}
|
|
175
|
+
*/
|
|
176
|
+
export function resolveRunningTaskTitles(projectRoot, tasksRoot, tasks) {
|
|
177
|
+
const titles = new Map();
|
|
178
|
+
if (!projectRoot || !tasksRoot || !Array.isArray(tasks)) return titles;
|
|
179
|
+
const tasksRootPath = path.join(projectRoot, tasksRoot);
|
|
180
|
+
for (const task of tasks) {
|
|
181
|
+
const taskId = task?.taskId != null ? String(task.taskId) : "";
|
|
182
|
+
if (!taskId || titles.has(taskId)) continue;
|
|
183
|
+
const promptPath = resolveTaskPromptPath(tasksRootPath, taskId, task?.taskFolder ?? null);
|
|
184
|
+
titles.set(taskId, promptPath ? readTaskTitleFromPrompt(promptPath) : null);
|
|
185
|
+
}
|
|
186
|
+
return titles;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Attach `runningTaskTitle` to each lane row from the resolved title map.
|
|
191
|
+
* Lanes without a running task (or an unresolvable title) get null.
|
|
192
|
+
*
|
|
193
|
+
* @param {object[]} lanes
|
|
194
|
+
* @param {Map<string, string | null>} taskTitles
|
|
195
|
+
*/
|
|
196
|
+
export function enrichLaneRowsWithRunningTaskTitle(lanes, taskTitles) {
|
|
197
|
+
return (lanes ?? []).map((lane) => {
|
|
198
|
+
const title =
|
|
199
|
+
lane?.runningTaskId != null
|
|
200
|
+
? (taskTitles.get(String(lane.runningTaskId)) ?? null)
|
|
201
|
+
: null;
|
|
202
|
+
return { ...lane, runningTaskTitle: title };
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
112
206
|
/**
|
|
113
207
|
* @param {string} projectRoot
|
|
114
208
|
*/
|
|
@@ -176,19 +270,22 @@ export function buildDashboardSnapshot(projectRoot) {
|
|
|
176
270
|
}
|
|
177
271
|
|
|
178
272
|
const lanes = enrichLaneRowsWithSubprocessHeartbeat(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
273
|
+
enrichLaneRowsWithRunningTaskTitle(
|
|
274
|
+
buildLaneRows({
|
|
275
|
+
lanes: batch?.lanes ?? [],
|
|
276
|
+
classifiedTasks,
|
|
277
|
+
stallConfig,
|
|
278
|
+
currentWaveTaskIds,
|
|
279
|
+
journalTail,
|
|
280
|
+
journalEvents,
|
|
281
|
+
metricsLines,
|
|
282
|
+
projectRoot,
|
|
283
|
+
batchId: reconciliation.batchId,
|
|
284
|
+
now,
|
|
285
|
+
diagnosis: reconciliation.diagnosis,
|
|
286
|
+
}),
|
|
287
|
+
resolveRunningTaskTitles(projectRoot, config?.paths?.tasksRoot ?? null, batch?.tasks),
|
|
288
|
+
),
|
|
192
289
|
journalEvents,
|
|
193
290
|
now,
|
|
194
291
|
);
|
|
@@ -1,42 +1,67 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
/**
|
|
3
3
|
* Doctor check: validate that all agent model pins use canonical provider/model format (SP-422 / #76).
|
|
4
|
+
* Extended in SP-664 / #216 to also validate every named `agents.profiles.<name>` entry.
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
import { validateModelIdFormat } from "../config/model-id.mjs";
|
|
7
|
-
|
|
8
|
-
/** @type {ReadonlyArray<{ path: string, get: (c: object) => unknown }>} */
|
|
9
|
-
const MODEL_PATHS = Object.freeze([
|
|
10
|
-
{ path: "agents.worker.model", get: (c) => c?.agents?.worker?.model },
|
|
11
|
-
{ path: "agents.reviewer.model", get: (c) => c?.agents?.reviewer?.model },
|
|
12
|
-
{ path: "agents.reviewer.plan.model", get: (c) => c?.agents?.reviewer?.plan?.model },
|
|
13
|
-
{ path: "agents.reviewer.code.model", get: (c) => c?.agents?.reviewer?.code?.model },
|
|
14
|
-
{ path: "agents.reviewer.final.model", get: (c) => c?.agents?.reviewer?.final?.model },
|
|
15
|
-
{ path: "agents.supervisor.model", get: (c) => c?.agents?.supervisor?.model },
|
|
16
|
-
]);
|
|
8
|
+
import { AGENT_MODEL_ACCESSORS } from "../config/spine-config-schema.mjs";
|
|
17
9
|
|
|
18
10
|
/**
|
|
19
|
-
* @param {
|
|
20
|
-
* @
|
|
21
|
-
* @returns {{ label: string, ok: boolean, detail: string, suggestedCommand?: string }}
|
|
11
|
+
* @param {unknown} value
|
|
12
|
+
* @returns {value is Record<string, unknown>}
|
|
22
13
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
function isPlainObject(value) {
|
|
15
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
+
}
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Collect canonical-format failures for every model pin reachable from an
|
|
20
|
+
* agents-shaped object. Used for both the base `agents` section and each named
|
|
21
|
+
* profile entry, which share the worker/reviewer/supervisor shape.
|
|
22
|
+
*
|
|
23
|
+
* @param {unknown} agentsRoot Agents-shaped object (base section or a profile).
|
|
24
|
+
* @param {string} pathPrefix Dotted prefix for messages (e.g. `agents` or `agents.profiles.hard`).
|
|
25
|
+
* @param {Array<{ path: string, error: string, suggestedCommand?: string }>} failures Accumulator.
|
|
26
|
+
*/
|
|
27
|
+
function collectModelFailures(agentsRoot, pathPrefix, failures) {
|
|
28
|
+
for (const { rel, get } of AGENT_MODEL_ACCESSORS) {
|
|
29
|
+
const value = get(agentsRoot);
|
|
29
30
|
if (value == null || value === "" || value === "inherit") continue;
|
|
30
31
|
if (typeof value !== "string") continue;
|
|
31
32
|
|
|
32
33
|
const result = validateModelIdFormat(value);
|
|
33
34
|
if (!result.ok) {
|
|
35
|
+
const path = `${pathPrefix}.${rel}`;
|
|
34
36
|
const suggested = result.canonical
|
|
35
37
|
? `spine settings set ${path} ${result.canonical}`
|
|
36
38
|
: undefined;
|
|
37
39
|
failures.push({ path, error: result.error, suggestedCommand: suggested });
|
|
38
40
|
}
|
|
39
41
|
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {object} params
|
|
46
|
+
* @param {object} [params.config]
|
|
47
|
+
* @returns {{ label: string, ok: boolean, detail: string, suggestedCommand?: string }}
|
|
48
|
+
*/
|
|
49
|
+
export function buildAgentModelIdsDoctorCheck({ config = {} } = {}) {
|
|
50
|
+
/** @type {Array<{ path: string, error: string, suggestedCommand?: string }>} */
|
|
51
|
+
const failures = [];
|
|
52
|
+
|
|
53
|
+
// Base agent pins — already reflect the active profile after load-time resolution.
|
|
54
|
+
collectModelFailures(config?.agents, "agents", failures);
|
|
55
|
+
|
|
56
|
+
// Validate each named profile independently so a misconfigured-but-inactive profile
|
|
57
|
+
// is still flagged before an operator can activate it (SP-664 / #216).
|
|
58
|
+
const profiles = config?.agents?.profiles;
|
|
59
|
+
if (isPlainObject(profiles)) {
|
|
60
|
+
for (const [name, profile] of Object.entries(profiles)) {
|
|
61
|
+
if (!isPlainObject(profile)) continue;
|
|
62
|
+
collectModelFailures(profile, `agents.profiles.${name}`, failures);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
40
65
|
|
|
41
66
|
if (failures.length === 0) {
|
|
42
67
|
return {
|