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
|
@@ -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 {
|
package/src/planner/lanes.mjs
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* FR-SCHED-03/04: greedy lane assignment subject to file-scope disjointness.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { deriveMatrixRowId } from './matrix.mjs';
|
|
6
|
+
|
|
5
7
|
function normalizeFileScopePath(p) {
|
|
6
8
|
let s = String(p ?? '').trim();
|
|
7
9
|
if (!s) return null;
|
|
@@ -40,9 +42,36 @@ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess
|
|
|
40
42
|
const planned = [];
|
|
41
43
|
|
|
42
44
|
for (let waveIndex = 0; waveIndex < waves.length; waveIndex++) {
|
|
43
|
-
const
|
|
45
|
+
const rawWaveTaskIds = waves[waveIndex];
|
|
46
|
+
const waveTaskIds = [];
|
|
47
|
+
|
|
48
|
+
// Expand matrix tasks
|
|
49
|
+
for (const taskId of rawWaveTaskIds) {
|
|
50
|
+
const task = tasksById[taskId];
|
|
51
|
+
if (!task) {
|
|
52
|
+
throw new Error(`Missing task packet for ${taskId} during lane assignment`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (task.matrix && Array.isArray(task.matrix) && task.matrix.length > 0) {
|
|
56
|
+
for (const row of task.matrix) {
|
|
57
|
+
const rowId = deriveMatrixRowId(row, task.matrixColumns || []);
|
|
58
|
+
const subTaskId = `${taskId}[${rowId}]`;
|
|
59
|
+
waveTaskIds.push(subTaskId);
|
|
60
|
+
if (!tasksById[subTaskId]) {
|
|
61
|
+
tasksById[subTaskId] = {
|
|
62
|
+
...task,
|
|
63
|
+
taskId: subTaskId,
|
|
64
|
+
matrixRow: row,
|
|
65
|
+
parentTaskId: taskId
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
waveTaskIds.push(taskId);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
44
73
|
|
|
45
|
-
/** @type {{ lanePaths: string[] }} */
|
|
74
|
+
/** @type {{ lanePaths: string[], taskIds: string[] }} */
|
|
46
75
|
const virtualLanes = [];
|
|
47
76
|
|
|
48
77
|
/** @type {Record<string, { virtualLane: number, tick: number, laneInTick: number }>} */
|
|
@@ -53,10 +82,7 @@ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess
|
|
|
53
82
|
// Greedy packing into virtual lanes.
|
|
54
83
|
for (const taskId of waveTaskIds) {
|
|
55
84
|
const task = tasksById[taskId];
|
|
56
|
-
|
|
57
|
-
throw new Error(`Missing task packet for ${taskId} during lane assignment`);
|
|
58
|
-
}
|
|
59
|
-
|
|
85
|
+
|
|
60
86
|
const taskPaths = (task.fileScope ?? [])
|
|
61
87
|
.map(normalizeFileScopePath)
|
|
62
88
|
.filter(Boolean);
|
|
@@ -64,10 +90,18 @@ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess
|
|
|
64
90
|
let placed = false;
|
|
65
91
|
for (let i = 0; i < virtualLanes.length; i++) {
|
|
66
92
|
const lane = virtualLanes[i];
|
|
67
|
-
|
|
93
|
+
|
|
94
|
+
// Matrix sub-tasks of the same parent task do not conflict with each other
|
|
95
|
+
const hasSameParent = lane.taskIds.some(id => {
|
|
96
|
+
const other = tasksById[id];
|
|
97
|
+
return other && other.parentTaskId && other.parentTaskId === task.parentTaskId;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (!hasSameParent && taskOverlapsLane(taskPaths, lane.lanePaths)) {
|
|
68
101
|
virtualLaneForTask[taskId] = i;
|
|
69
102
|
// Append to lane paths so future tasks are checked against everything already assigned.
|
|
70
103
|
lane.lanePaths.push(...taskPaths);
|
|
104
|
+
lane.taskIds.push(taskId);
|
|
71
105
|
placed = true;
|
|
72
106
|
break;
|
|
73
107
|
}
|
|
@@ -75,7 +109,7 @@ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess
|
|
|
75
109
|
|
|
76
110
|
if (!placed) {
|
|
77
111
|
const i = virtualLanes.length;
|
|
78
|
-
virtualLanes.push({ lanePaths: [...taskPaths] });
|
|
112
|
+
virtualLanes.push({ lanePaths: [...taskPaths], taskIds: [taskId] });
|
|
79
113
|
virtualLaneForTask[taskId] = i;
|
|
80
114
|
}
|
|
81
115
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse a markdown table into an array of objects.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} markdown
|
|
7
|
+
* @returns {{ rows: Array<Record<string, string>>, columns: string[] }}
|
|
8
|
+
*/
|
|
9
|
+
export function parseMatrixTable(markdown) {
|
|
10
|
+
if (!markdown || !markdown.trim()) {
|
|
11
|
+
return { rows: [], columns: [] };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const lines = markdown.split(/\r?\n/).map(line => line.trim()).filter(line => line.startsWith('|') && line.endsWith('|'));
|
|
15
|
+
|
|
16
|
+
if (lines.length < 2) {
|
|
17
|
+
return { rows: [], columns: [] };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @param {string} line */
|
|
21
|
+
const parseCells = (line) => {
|
|
22
|
+
const parts = line.split('|');
|
|
23
|
+
// Remove the first and last parts since they are outside the bounding pipes
|
|
24
|
+
return parts.slice(1, parts.length - 1).map(s => s.trim());
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const columns = parseCells(lines[0]);
|
|
28
|
+
if (columns.length === 0 || columns.every(c => !c)) {
|
|
29
|
+
return { rows: [], columns: [] };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @type {Array<Record<string, string>>} */
|
|
33
|
+
const rows = [];
|
|
34
|
+
// Skip line[1] which is the separator
|
|
35
|
+
for (let i = 2; i < lines.length; i++) {
|
|
36
|
+
const cellValues = parseCells(lines[i]);
|
|
37
|
+
/** @type {Record<string, string>} */
|
|
38
|
+
const rowObj = {};
|
|
39
|
+
let hasValue = false;
|
|
40
|
+
for (let c = 0; c < columns.length; c++) {
|
|
41
|
+
const col = columns[c];
|
|
42
|
+
if (!col) continue; // Skip empty header columns
|
|
43
|
+
const val = cellValues[c] ?? "";
|
|
44
|
+
rowObj[col] = val;
|
|
45
|
+
if (val) hasValue = true;
|
|
46
|
+
}
|
|
47
|
+
if (hasValue) {
|
|
48
|
+
rows.push(rowObj);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { rows, columns };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Derives a string id for a row. Prefer `run_id`, else join values.
|
|
57
|
+
* @param {Record<string, string>} row
|
|
58
|
+
* @param {string[]} columns
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
export function deriveMatrixRowId(row, columns) {
|
|
62
|
+
if (row['run_id']) {
|
|
63
|
+
return row['run_id'];
|
|
64
|
+
}
|
|
65
|
+
return columns.map(col => row[col]).join('_').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Matches `{matrix.<column>}` placeholders. Column names are `[a-zA-Z0-9_-]+`. */
|
|
69
|
+
const MATRIX_VAR_RE = /\{matrix\.([a-zA-Z0-9_-]+)\}/g;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Substitute `{matrix.<column>}` placeholders in a template string with the
|
|
73
|
+
* matching value from a matrix row.
|
|
74
|
+
*
|
|
75
|
+
* Fails loud (throws) on any reference whose column is absent from the row, so a
|
|
76
|
+
* typo such as `{matrix.rnu_id}` never silently reaches execution. When no row is
|
|
77
|
+
* supplied, text without placeholders is returned unchanged (non-matrix tasks).
|
|
78
|
+
*
|
|
79
|
+
* @param {string} template Arbitrary text (PROMPT body, contract field, step command).
|
|
80
|
+
* @param {Record<string, string> | null | undefined} row Matrix row values keyed by column.
|
|
81
|
+
* @returns {string}
|
|
82
|
+
*/
|
|
83
|
+
export function substituteMatrixVariables(template, row) {
|
|
84
|
+
const text = String(template ?? "");
|
|
85
|
+
|
|
86
|
+
// No row: a template without placeholders (non-matrix task) is returned verbatim.
|
|
87
|
+
// A leftover {matrix.X} with no row is an authoring error — fail loud.
|
|
88
|
+
if (!row) {
|
|
89
|
+
return text.replace(MATRIX_VAR_RE, (match, column) => {
|
|
90
|
+
throw new Error(`Unknown matrix variable reference: {matrix.${column}}`);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const values = row;
|
|
95
|
+
return text.replace(MATRIX_VAR_RE, (match, column) => {
|
|
96
|
+
if (!Object.prototype.hasOwnProperty.call(values, column)) {
|
|
97
|
+
throw new Error(`Unknown matrix variable reference: {matrix.${column}}`);
|
|
98
|
+
}
|
|
99
|
+
const value = values[column];
|
|
100
|
+
return value == null ? "" : String(value);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Substitute `{matrix.<column>}` placeholders in parsed step titles and bodies.
|
|
106
|
+
* Returns a new steps array; the input is returned unchanged when no row is
|
|
107
|
+
* supplied (non-matrix tasks are untouched).
|
|
108
|
+
*
|
|
109
|
+
* @param {Array<{ number: number, title: string, body: string }>} steps Parsed steps from `parsePrompt`.
|
|
110
|
+
* @param {Record<string, string> | null | undefined} row Matrix row values keyed by column.
|
|
111
|
+
* @returns {Array<{ number: number, title: string, body: string }>}
|
|
112
|
+
*/
|
|
113
|
+
export function applyMatrixRowToSteps(steps, row) {
|
|
114
|
+
if (!Array.isArray(steps) || !row || Object.keys(row).length === 0) {
|
|
115
|
+
return steps;
|
|
116
|
+
}
|
|
117
|
+
return steps.map((step) => ({
|
|
118
|
+
...step,
|
|
119
|
+
title: substituteMatrixVariables(step.title, row),
|
|
120
|
+
body: substituteMatrixVariables(step.body, row),
|
|
121
|
+
}));
|
|
122
|
+
}
|
package/src/planner/waves.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { fileScopesOverlap, findWaveFileScopeOverlaps } from './file-scope.mjs';
|
|
7
|
+
import { deriveMatrixRowId } from './matrix.mjs';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @param {string[]} taskScope
|
|
@@ -27,9 +28,35 @@ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess
|
|
|
27
28
|
const planned = [];
|
|
28
29
|
|
|
29
30
|
for (let waveIndex = 0; waveIndex < waves.length; waveIndex++) {
|
|
30
|
-
const
|
|
31
|
+
const rawWaveTaskIds = waves[waveIndex];
|
|
32
|
+
const waveTaskIds = [];
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
for (const taskId of rawWaveTaskIds) {
|
|
35
|
+
const task = tasksById[taskId];
|
|
36
|
+
if (!task) {
|
|
37
|
+
throw new Error(`Missing task packet for ${taskId} during lane assignment`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (task.matrix && Array.isArray(task.matrix) && task.matrix.length > 0) {
|
|
41
|
+
for (const row of task.matrix) {
|
|
42
|
+
const rowId = deriveMatrixRowId(row, task.matrixColumns || []);
|
|
43
|
+
const subTaskId = `${taskId}[${rowId}]`;
|
|
44
|
+
waveTaskIds.push(subTaskId);
|
|
45
|
+
if (!tasksById[subTaskId]) {
|
|
46
|
+
tasksById[subTaskId] = {
|
|
47
|
+
...task,
|
|
48
|
+
taskId: subTaskId,
|
|
49
|
+
matrixRow: row,
|
|
50
|
+
parentTaskId: taskId
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
waveTaskIds.push(taskId);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @type {{ taskScopes: string[][], taskIds: string[] }} */
|
|
33
60
|
const virtualLanes = [];
|
|
34
61
|
|
|
35
62
|
/** @type {Record<string, { virtualLane: number, tick: number, laneInTick: number }>} */
|
|
@@ -39,18 +66,22 @@ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess
|
|
|
39
66
|
|
|
40
67
|
for (const taskId of waveTaskIds) {
|
|
41
68
|
const task = tasksById[taskId];
|
|
42
|
-
|
|
43
|
-
throw new Error(`Missing task packet for ${taskId} during lane assignment`);
|
|
44
|
-
}
|
|
45
|
-
|
|
69
|
+
|
|
46
70
|
const taskScope = Array.isArray(task.fileScope) ? task.fileScope : [];
|
|
47
71
|
|
|
48
72
|
let placed = false;
|
|
49
73
|
for (let i = 0; i < virtualLanes.length; i++) {
|
|
50
74
|
const lane = virtualLanes[i];
|
|
51
|
-
|
|
75
|
+
|
|
76
|
+
const hasSameParent = lane.taskIds.some(id => {
|
|
77
|
+
const other = tasksById[id];
|
|
78
|
+
return other && other.parentTaskId && other.parentTaskId === task.parentTaskId;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (!hasSameParent && taskOverlapsLane(taskScope, lane.taskScopes)) {
|
|
52
82
|
virtualLaneForTask[taskId] = i;
|
|
53
83
|
lane.taskScopes.push(taskScope);
|
|
84
|
+
lane.taskIds.push(taskId);
|
|
54
85
|
placed = true;
|
|
55
86
|
break;
|
|
56
87
|
}
|
|
@@ -58,7 +89,7 @@ export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess
|
|
|
58
89
|
|
|
59
90
|
if (!placed) {
|
|
60
91
|
const i = virtualLanes.length;
|
|
61
|
-
virtualLanes.push({ taskScopes: [taskScope] });
|
|
92
|
+
virtualLanes.push({ taskScopes: [taskScope], taskIds: [taskId] });
|
|
62
93
|
virtualLaneForTask[taskId] = i;
|
|
63
94
|
}
|
|
64
95
|
}
|