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
package/bin/spine.mjs
CHANGED
|
@@ -169,49 +169,62 @@ async function cmdIssue(args) {
|
|
|
169
169
|
|
|
170
170
|
async function cmdMetrics(args) {
|
|
171
171
|
const sub = args[0];
|
|
172
|
-
if (sub
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
if (sub === "show") {
|
|
173
|
+
const projectRoot = process.cwd();
|
|
174
|
+
const json = args.includes("--json");
|
|
175
|
+
let batchId = null;
|
|
176
|
+
let last = null;
|
|
177
|
+
for (let i = 1; i < args.length; i++) {
|
|
178
|
+
const arg = args[i];
|
|
179
|
+
if (arg === "--batch") batchId = args[++i] ?? null;
|
|
180
|
+
else if (arg === "--last") last = Number(args[++i]);
|
|
181
|
+
}
|
|
175
182
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
184
|
+
const config = configResult.config ?? {};
|
|
185
|
+
const {
|
|
186
|
+
filterMetricsLines,
|
|
187
|
+
formatMetricsTable,
|
|
188
|
+
metricsFilePath,
|
|
189
|
+
readMetricsLines,
|
|
190
|
+
} = await import("../src/batch/metrics.mjs");
|
|
191
|
+
const { rollupMetrics, formatMetricsRollups } = await import("../src/batch/metrics-rollup.mjs");
|
|
192
|
+
const filePath = metricsFilePath(projectRoot, config);
|
|
193
|
+
|
|
194
|
+
if (!fs.existsSync(filePath)) {
|
|
195
|
+
if (json) {
|
|
196
|
+
process.stdout.write(`${JSON.stringify({ lines: [] }, null, 2)}\n`);
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
die(`Metrics file not found: ${path.relative(projectRoot, filePath)}\n`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const lines = filterMetricsLines(readMetricsLines(filePath), {
|
|
203
|
+
batchId: batchId ?? undefined,
|
|
204
|
+
last: last ?? undefined,
|
|
205
|
+
});
|
|
206
|
+
const rollups = rollupMetrics(lines);
|
|
185
207
|
|
|
186
|
-
const configResult = loadSpineConfig(projectRoot);
|
|
187
|
-
const config = configResult.config ?? {};
|
|
188
|
-
const {
|
|
189
|
-
filterMetricsLines,
|
|
190
|
-
formatMetricsTable,
|
|
191
|
-
metricsFilePath,
|
|
192
|
-
readMetricsLines,
|
|
193
|
-
} = await import("../src/batch/metrics.mjs");
|
|
194
|
-
const filePath = metricsFilePath(projectRoot, config);
|
|
195
|
-
|
|
196
|
-
if (!fs.existsSync(filePath)) {
|
|
197
208
|
if (json) {
|
|
198
|
-
process.stdout.write(`${JSON.stringify({ lines
|
|
199
|
-
|
|
209
|
+
process.stdout.write(`${JSON.stringify({ lines, rollups }, null, 2)}\n`);
|
|
210
|
+
return;
|
|
200
211
|
}
|
|
201
|
-
die(`Metrics file not found: ${path.relative(projectRoot, filePath)}\n`);
|
|
202
|
-
}
|
|
203
212
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
});
|
|
213
|
+
process.stdout.write(formatMetricsTable(lines) + formatMetricsRollups(rollups));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
208
216
|
|
|
209
|
-
if (
|
|
210
|
-
|
|
217
|
+
if (sub === "quota") {
|
|
218
|
+
const { runQuotaReport } = await import("../src/metrics/quota-cli.mjs");
|
|
219
|
+
const result = runQuotaReport({ projectRoot: process.cwd(), args: args.slice(1) });
|
|
220
|
+
process.stdout.write(result.output);
|
|
221
|
+
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
211
222
|
return;
|
|
212
223
|
}
|
|
213
224
|
|
|
214
|
-
|
|
225
|
+
die(
|
|
226
|
+
`Unknown metrics subcommand: ${sub ?? "(none)"}\nRun ${c.cyan}spine metrics show${c.reset} or ${c.cyan}spine metrics quota${c.reset} for usage.`,
|
|
227
|
+
);
|
|
215
228
|
}
|
|
216
229
|
|
|
217
230
|
async function cmdReport(args) {
|
|
@@ -288,7 +301,7 @@ ${c.bold}Commands:${c.reset}
|
|
|
288
301
|
${c.cyan}run${c.reset} Start batch or planner wave sequence (PRD §15.2, #54)
|
|
289
302
|
${c.cyan}handoff${c.reset} Write operator handoff note (FR-UXB-05)
|
|
290
303
|
${c.cyan}issue draft${c.reset} Build GitHub issue draft from project state (#60)
|
|
291
|
-
${c.cyan}metrics${c.reset} Show run metrics
|
|
304
|
+
${c.cyan}metrics${c.reset} Show run metrics and quota snapshots (FR-UXB-06)
|
|
292
305
|
${c.cyan}review step${c.reset} Spawn reviewer for a task step (FR-REV)
|
|
293
306
|
${c.cyan}report progress${c.reset} Emit task.step_completed to batch journal (FR-WORK-09)
|
|
294
307
|
${c.cyan}gate${c.reset} Inspect or resolve integrate gate (FR-GATE)
|
|
@@ -347,7 +360,8 @@ ${c.bold}Examples:${c.reset}
|
|
|
347
360
|
spine batch complete --detect-manual-merge # complete after manual git merge
|
|
348
361
|
spine handoff [--batch ID] [--json] # operator handoff note
|
|
349
362
|
spine issue draft [--type bug] [--json] # GitHub issue draft from diagnose state
|
|
350
|
-
spine metrics show [--batch ID] [--last N] # read run-metrics.jsonl
|
|
363
|
+
spine metrics show [--batch ID] [--last N] # read run-metrics.jsonl (usage rollups when present)
|
|
364
|
+
spine metrics quota [--json] [--open] # write .spine/reports/quota-snapshot-*.json
|
|
351
365
|
spine review step --step N [--type plan|code|final] # step or final review
|
|
352
366
|
spine report progress --step N # journal step progress (worker shell-out)
|
|
353
367
|
spine gate [approve|reject|status] # integrate gate FSM
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { spawnSync, execFileSync } from "node:child_process";
|
|
9
9
|
import micromatch from "micromatch";
|
|
10
10
|
import { parseAggregateLineCoverage } from "../../scripts/coverage-parse.mjs";
|
|
11
11
|
import {
|
|
@@ -309,7 +309,17 @@ export function verifyContract(worktreePath, parsedContract, config = {}) {
|
|
|
309
309
|
const checks = [];
|
|
310
310
|
const baseBranch = config?.baseBranch ?? "main";
|
|
311
311
|
const sinceCommit = config?.sinceCommit ?? config?.taskStartCommit ?? undefined;
|
|
312
|
-
const
|
|
312
|
+
const committedFiles = listChangedFiles(worktreePath, baseBranch, sinceCommit);
|
|
313
|
+
|
|
314
|
+
let indexAndWorktreeFiles = [];
|
|
315
|
+
try {
|
|
316
|
+
const stdout = execFileSync("git", ["diff", "--name-only", "HEAD"], { cwd: worktreePath, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
|
|
317
|
+
indexAndWorktreeFiles = stdout.split(/\r?\n/).map(l => l.trim()).filter(Boolean);
|
|
318
|
+
} catch {
|
|
319
|
+
// Ignore git diff failures; fall back to committedFiles only.
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const changedFiles = [...new Set([...committedFiles, ...indexAndWorktreeFiles])];
|
|
313
323
|
|
|
314
324
|
prepareContractVerifyEnvironment(worktreePath, parsedContract, config);
|
|
315
325
|
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
isBaseScopeSatisfied,
|
|
12
12
|
isStubPrelandedFileScopeSatisfied,
|
|
13
13
|
} from "./contract-prelanded.mjs";
|
|
14
|
+
import { substituteMatrixVariables } from "../planner/matrix.mjs";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* @param {string} taskId
|
|
@@ -241,3 +242,57 @@ export function verifyStubFileScopeMustChange(
|
|
|
241
242
|
}
|
|
242
243
|
return { ok: failures.length === 0, failures };
|
|
243
244
|
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Substitute `{matrix.<column>}` placeholders in a single scalar contract field.
|
|
248
|
+
* @param {string | null | undefined} value
|
|
249
|
+
* @param {Record<string, string>} row
|
|
250
|
+
* @returns {string | null | undefined}
|
|
251
|
+
*/
|
|
252
|
+
function substituteContractScalar(value, row) {
|
|
253
|
+
return value == null ? value : substituteMatrixVariables(value, row);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Substitute `{matrix.<column>}` placeholders across each path in a contract list field.
|
|
258
|
+
* @param {string[] | null | undefined} values
|
|
259
|
+
* @param {Record<string, string>} row
|
|
260
|
+
* @returns {string[] | null | undefined}
|
|
261
|
+
*/
|
|
262
|
+
function substituteContractList(values, row) {
|
|
263
|
+
if (!Array.isArray(values)) {
|
|
264
|
+
return values;
|
|
265
|
+
}
|
|
266
|
+
return values.map((pattern) => substituteMatrixVariables(pattern, row));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Apply a matrix row to a parsed contract, substituting `{matrix.<column>}`
|
|
271
|
+
* placeholders in `testCommand`, `runCommand`, `fileScopeMustChange`,
|
|
272
|
+
* `fileScopeMustNotChange`, and `artifactsMustExist`. Numeric and boolean fields
|
|
273
|
+
* (`minLineCoverage`, `stallTimeoutMinutes`, `extendGraceOnFileScope`) are passed
|
|
274
|
+
* through unchanged.
|
|
275
|
+
*
|
|
276
|
+
* Returns a new parsed contract object; the input is returned unchanged when no
|
|
277
|
+
* row is supplied so non-matrix tasks keep their parsed contract verbatim. Throws
|
|
278
|
+
* on unknown `{matrix.X}` references (fail-loud) — `substituteMatrixVariables` owns
|
|
279
|
+
* the validation.
|
|
280
|
+
*
|
|
281
|
+
* @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
|
|
282
|
+
* @param {Record<string, string> | null | undefined} row Matrix row values keyed by column.
|
|
283
|
+
* @returns {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>}
|
|
284
|
+
*/
|
|
285
|
+
export function applyMatrixRowToContract(parsedContract, row) {
|
|
286
|
+
if (!parsedContract || !row || Object.keys(row).length === 0) {
|
|
287
|
+
return parsedContract;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
...parsedContract,
|
|
292
|
+
testCommand: substituteContractScalar(parsedContract.testCommand, row),
|
|
293
|
+
runCommand: substituteContractScalar(parsedContract.runCommand, row),
|
|
294
|
+
fileScopeMustChange: substituteContractList(parsedContract.fileScopeMustChange, row),
|
|
295
|
+
fileScopeMustNotChange: substituteContractList(parsedContract.fileScopeMustNotChange, row),
|
|
296
|
+
artifactsMustExist: substituteContractList(parsedContract.artifactsMustExist, row),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
@@ -23,8 +23,13 @@ export {
|
|
|
23
23
|
shouldRunContractVerify,
|
|
24
24
|
shouldRunContractVerifyForWorker,
|
|
25
25
|
verifyStubFileScopeMustChange,
|
|
26
|
+
applyMatrixRowToContract,
|
|
26
27
|
} from "./contract-parse.mjs";
|
|
27
28
|
|
|
29
|
+
import { verifyContract as _verifyContract } from "./contract-exec.mjs";
|
|
30
|
+
import { stageUntrackedScopeFiles } from "./lane-dirty-check-git.mjs";
|
|
31
|
+
import { applyMatrixRowToContract } from "./contract-parse.mjs";
|
|
32
|
+
|
|
28
33
|
export {
|
|
29
34
|
CONTRACT_TEST_COMMAND_MAX_BUFFER,
|
|
30
35
|
CONTRACT_TEST_DEFAULT_RETRIES,
|
|
@@ -34,6 +39,41 @@ export {
|
|
|
34
39
|
isRefusedNpmTestDashDashCommand,
|
|
35
40
|
prepareContractVerifyEnvironment,
|
|
36
41
|
runContractTestCommand,
|
|
37
|
-
verifyContract,
|
|
38
42
|
writeContractFailureLog,
|
|
39
43
|
} from "./contract-exec.mjs";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Verify contract and auto-stage untracked scope files before verification.
|
|
47
|
+
*
|
|
48
|
+
* When `config.matrixRow` is supplied (a matrix sub-lane), `{matrix.<column>}`
|
|
49
|
+
* placeholders in `testCommand`, `fileScopeMustChange`, and other string/list
|
|
50
|
+
* contract fields are substituted with the row values before staging and
|
|
51
|
+
* verification. Omit `config.matrixRow` for non-matrix tasks — the parsed
|
|
52
|
+
* contract is used verbatim, preserving existing behavior.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} worktreePath
|
|
55
|
+
* @param {object} parsedContract
|
|
56
|
+
* @param {object} [config]
|
|
57
|
+
*/
|
|
58
|
+
export function verifyContract(worktreePath, parsedContract, config = {}) {
|
|
59
|
+
const effectiveContract = config?.matrixRow
|
|
60
|
+
? applyMatrixRowToContract(parsedContract, config.matrixRow)
|
|
61
|
+
: parsedContract;
|
|
62
|
+
|
|
63
|
+
const stageResult = stageUntrackedScopeFiles(worktreePath, effectiveContract.fileScopeMustChange || []);
|
|
64
|
+
|
|
65
|
+
if (stageResult.error) {
|
|
66
|
+
return {
|
|
67
|
+
ok: false,
|
|
68
|
+
checks: [
|
|
69
|
+
{
|
|
70
|
+
field: "fileScopeMustChange",
|
|
71
|
+
ok: false,
|
|
72
|
+
message: `Failed to auto-stage untracked scope files: ${stageResult.error}`,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return _verifyContract(worktreePath, effectiveContract, config);
|
|
79
|
+
}
|