pi-spine 2.9.0 → 2.11.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/bin/spine.mjs +50 -36
- 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/gate-evidence-collect.mjs +6 -0
- package/src/batch/gate-evidence-read.mjs +2 -0
- 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/metrics-rollup.mjs +119 -0
- package/src/batch/metrics.mjs +6 -1
- package/src/batch/worker-host.mjs +38 -21
- package/src/batch/worker-spawn.mjs +49 -0
- package/src/metrics/quota-cli.mjs +123 -0
- package/src/metrics/quota-html.mjs +465 -0
- package/src/metrics/quota-probes.mjs +312 -0
- package/src/metrics/quota-snapshot.mjs +272 -0
- 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
- package/templates/spine-config.json +3 -2
|
@@ -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
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { parseSizeLineFromMarkdown } from "./size-line.mjs";
|
|
3
3
|
|
|
4
|
+
import { parseMatrixTable } from "../../planner/matrix.mjs";
|
|
5
|
+
|
|
4
6
|
/** PRD §13.4 — em dash (U+2014) required between ID and title. */
|
|
5
7
|
export const TASK_HEADING_RE = /^# Task: ([A-Z][A-Z0-9]*-\d+) — (.+)$/m;
|
|
6
8
|
|
|
@@ -13,7 +15,7 @@ const REQUIRED_SECTIONS = [
|
|
|
13
15
|
"Do NOT",
|
|
14
16
|
];
|
|
15
17
|
|
|
16
|
-
const OPTIONAL_SECTIONS = ["Testing", "Context to Read First", "Environment", "Documentation Requirements"];
|
|
18
|
+
const OPTIONAL_SECTIONS = ["Testing", "Context to Read First", "Environment", "Documentation Requirements", "Matrix"];
|
|
17
19
|
|
|
18
20
|
const H2_SECTION_RE = /^## (.+)$/gm;
|
|
19
21
|
const STEP_HEADING_RE = /^### Step (\d+): (.+)$/gm;
|
|
@@ -21,6 +23,7 @@ const STEP_HEADING_RE = /^### Step (\d+): (.+)$/gm;
|
|
|
21
23
|
/** Normative contract table fields per handoff §4.1. */
|
|
22
24
|
export const CONTRACT_FIELD_NAMES = Object.freeze([
|
|
23
25
|
"testCommand",
|
|
26
|
+
"runCommand",
|
|
24
27
|
"fileScopeMustChange",
|
|
25
28
|
"fileScopeMustNotChange",
|
|
26
29
|
"minLineCoverage",
|
|
@@ -65,11 +68,24 @@ export function parsePrompt(markdown) {
|
|
|
65
68
|
|
|
66
69
|
const missingSections = REQUIRED_SECTIONS.filter((name) => !sections[name]);
|
|
67
70
|
const size = parseSizeLineFromMarkdown(markdown);
|
|
71
|
+
const typeMatch = /^\*\*Type:\*\*\s*(llm|execute)\s*$/im.exec(markdown);
|
|
72
|
+
const type = typeMatch ? typeMatch[1].toLowerCase() : "llm";
|
|
73
|
+
|
|
74
|
+
let matrix = null;
|
|
75
|
+
let matrixColumns = null;
|
|
76
|
+
if (sections.Matrix) {
|
|
77
|
+
const parsedMatrix = parseMatrixTable(sections.Matrix);
|
|
78
|
+
if (parsedMatrix.rows.length > 0) {
|
|
79
|
+
matrix = parsedMatrix.rows;
|
|
80
|
+
matrixColumns = parsedMatrix.columns;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
68
83
|
|
|
69
84
|
return {
|
|
70
85
|
taskId,
|
|
71
86
|
title,
|
|
72
87
|
size,
|
|
88
|
+
type,
|
|
73
89
|
headingLine,
|
|
74
90
|
sections,
|
|
75
91
|
steps,
|
|
@@ -79,6 +95,7 @@ export function parsePrompt(markdown) {
|
|
|
79
95
|
missingSections,
|
|
80
96
|
requiredSections: REQUIRED_SECTIONS,
|
|
81
97
|
optionalSections: OPTIONAL_SECTIONS,
|
|
98
|
+
...(matrix ? { matrix, matrixColumns } : {})
|
|
82
99
|
};
|
|
83
100
|
}
|
|
84
101
|
|
|
@@ -113,6 +130,13 @@ export function validatePrompt(markdown) {
|
|
|
113
130
|
|
|
114
131
|
errors.push(...collectDuplicateStepNumberErrors(prompt.steps));
|
|
115
132
|
|
|
133
|
+
if (prompt.type === "execute") {
|
|
134
|
+
const contract = parseContract(markdown);
|
|
135
|
+
if (!contract.testCommand && !contract.runCommand) {
|
|
136
|
+
errors.push("Type: execute tasks require a testCommand or runCommand in the ## Contract section");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
116
140
|
return { ok: errors.length === 0, errors, prompt };
|
|
117
141
|
}
|
|
118
142
|
|
|
@@ -149,6 +173,7 @@ function collectDuplicateStepNumberErrors(steps) {
|
|
|
149
173
|
* @param {string} markdown PROMPT.md contents
|
|
150
174
|
* @returns {{
|
|
151
175
|
* testCommand: string | null,
|
|
176
|
+
* runCommand: string | null,
|
|
152
177
|
* fileScopeMustChange: string[],
|
|
153
178
|
* fileScopeMustNotChange: string[],
|
|
154
179
|
* minLineCoverage: number | null,
|
|
@@ -171,6 +196,7 @@ export function parseContract(markdown) {
|
|
|
171
196
|
/** @type {ReturnType<typeof parseContract>} */
|
|
172
197
|
const parsed = {
|
|
173
198
|
testCommand: null,
|
|
199
|
+
runCommand: null,
|
|
174
200
|
fileScopeMustChange: [],
|
|
175
201
|
fileScopeMustNotChange: [],
|
|
176
202
|
minLineCoverage: null,
|
|
@@ -297,6 +323,19 @@ function applyContractField(parsed, field, rawValue) {
|
|
|
297
323
|
parsed.testCommand = command;
|
|
298
324
|
return;
|
|
299
325
|
}
|
|
326
|
+
case "runCommand": {
|
|
327
|
+
const command = parseContractScalar(value);
|
|
328
|
+
if (command.includes("\n")) {
|
|
329
|
+
parsed.errors.push("Contract runCommand must not contain newlines");
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (command.length > TEST_COMMAND_MAX_LENGTH) {
|
|
333
|
+
parsed.errors.push(`Contract runCommand exceeds ${TEST_COMMAND_MAX_LENGTH} characters`);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
parsed.runCommand = command;
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
300
339
|
case "fileScopeMustChange":
|
|
301
340
|
parsed.fileScopeMustChange = parseContractPathList(value);
|
|
302
341
|
return;
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"testing": {
|
|
12
12
|
"build": "npm run typecheck",
|
|
13
13
|
"test": "npm test",
|
|
14
|
-
"testWithCoverage": "npm run coverage:check"
|
|
14
|
+
"testWithCoverage": "npm run coverage:check",
|
|
15
|
+
"review": ""
|
|
15
16
|
},
|
|
16
17
|
"agents": {
|
|
17
18
|
"worker": { "model": "cursor/auto", "thinking": "high" },
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
"_examples": {
|
|
82
83
|
"worktreeSetupHook": "scripts/spine-worktree-setup-flutter.sh",
|
|
83
84
|
"_worktreeSetupHookNote": "Optional Flutter: symlink gitignored pubspec assets from SPINE_PROJECT_ROOT into lane worktrees — see docs/adoption/flutter-worktree-guide.md",
|
|
84
|
-
"_testingScriptsNote": "testing.build/test/testWithCoverage may use a relative scripts/*.sh path (validated sandbox, no shell metacharacters); e.g. scripts/run-gate-evidence.sh"
|
|
85
|
+
"_testingScriptsNote": "testing.build/test/testWithCoverage/review may use a relative scripts/*.sh path (validated sandbox, no shell metacharacters); e.g. scripts/run-gate-evidence.sh. testing.review is optional and, when set, runs through the same validated executor and is included in the gate evidence bundle."
|
|
85
86
|
},
|
|
86
87
|
"worktreeSetupHook": "",
|
|
87
88
|
"worktreeSetupIgnorePaths": [".venv"],
|