pi-spine 2.19.0 → 2.20.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.
@@ -14,6 +14,7 @@ import { parseBatchStartWaveFilter } from "../src/planner/wave-scope.mjs";
14
14
  import { pauseBatch } from "../src/batch/pause.mjs";
15
15
  import { resumeBatch } from "../src/batch/resume.mjs";
16
16
  import { retryTask, skipTask } from "../src/batch/retry.mjs";
17
+ import { retryTaskRow, skipTaskRow, parseMatrixRowRef } from "../src/batch/retry-row.mjs";
17
18
  import { reconcileBatch } from "../src/batch/reconcile.mjs";
18
19
  import {
19
20
  finishAttachedBatchCli,
@@ -38,7 +39,8 @@ const BATCH_FLAG_VALUE_TAKERS = new Set([
38
39
  */
39
40
  export function printBatchHelp() {
40
41
  return (
41
- "Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|salvage|abort|dismiss|complete [--batch ID] [--lane N] [--integrate] [--yes] [--reason TEXT] [--hard] [--force] [--force-superseded] [--attached] [--dry-run] [--wave N] [--through-wave N] [--skip-preflight] [--detect-manual-merge] [--json]\n" +
42
+ "Usage: spine batch start <scope>|pause|resume|retry <taskId|[rowId]>|skip <taskId|[rowId]>|force-merge [--wave N]|salvage|abort|dismiss|complete [--batch ID] [--lane N] [--integrate] [--yes] [--reason TEXT] [--hard] [--force] [--force-superseded] [--attached] [--dry-run] [--wave N] [--through-wave N] [--skip-preflight] [--detect-manual-merge] [--json]\n" +
43
+ " Row identity: retry/skip 'SP-X[rowId]' targets one matrix row; plain SP-X targets the whole task.\n" +
42
44
  " abort --dry-run Preview abort (reason/archive target); does not archive, journal, or clear live batch\n"
43
45
  );
44
46
  }
@@ -349,10 +351,13 @@ export async function runSpineBatch(options) {
349
351
  if (!parsed.taskId) {
350
352
  return {
351
353
  exitCode: 1,
352
- output: "Usage: spine batch retry <taskId> [--json]\n",
354
+ output: "Usage: spine batch retry <taskId> | <taskId>[rowId] [--json]\n",
353
355
  };
354
356
  }
355
- const result = retryTask({ projectRoot, taskId: parsed.taskId });
357
+ const rowRef = parseMatrixRowRef(parsed.taskId);
358
+ const result = rowRef
359
+ ? retryTaskRow({ projectRoot, taskId: rowRef.taskId, rowId: rowRef.rowId })
360
+ : retryTask({ projectRoot, taskId: parsed.taskId });
356
361
  if (parsed.json) {
357
362
  return {
358
363
  exitCode: result.exitCode ?? (result.ok ? 0 : 1),
@@ -368,6 +373,7 @@ export async function runSpineBatch(options) {
368
373
  ];
369
374
  if (result.batchId) lines.push("", ` Batch: ${result.batchId}`);
370
375
  if (result.taskId) lines.push(` Task: ${result.taskId}`);
376
+ if (result.rowId) lines.push(` Row: ${result.rowId}`);
371
377
  if (result.pendingSegments != null) lines.push(` Pending segments: ${result.pendingSegments}`);
372
378
  lines.push("");
373
379
  return {
@@ -381,10 +387,13 @@ export async function runSpineBatch(options) {
381
387
  if (!parsed.taskId) {
382
388
  return {
383
389
  exitCode: 1,
384
- output: "Usage: spine batch skip <taskId> [--json]\n",
390
+ output: "Usage: spine batch skip <taskId> | <taskId>[rowId] [--json]\n",
385
391
  };
386
392
  }
387
- const result = skipTask({ projectRoot, taskId: parsed.taskId });
393
+ const rowRef = parseMatrixRowRef(parsed.taskId);
394
+ const result = rowRef
395
+ ? skipTaskRow({ projectRoot, taskId: rowRef.taskId, rowId: rowRef.rowId })
396
+ : skipTask({ projectRoot, taskId: parsed.taskId });
388
397
  if (parsed.json) {
389
398
  return {
390
399
  exitCode: result.exitCode ?? (result.ok ? 0 : 1),
@@ -400,6 +409,7 @@ export async function runSpineBatch(options) {
400
409
  ];
401
410
  if (result.batchId) lines.push("", ` Batch: ${result.batchId}`);
402
411
  if (result.taskId) lines.push(` Task: ${result.taskId}`);
412
+ if (result.rowId) lines.push(` Row: ${result.rowId}`);
403
413
  lines.push("");
404
414
  return {
405
415
  exitCode: result.exitCode ?? (result.ok ? 0 : 1),
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * Integrate gate inspection and resolution (PRD §12, FR-GATE).
4
- * Usage: spine gate [approve|reject|status|reopen] [--batch ID] [--reason text] [--json]
4
+ * Usage: spine gate [approve|reject|status|reopen] [--batch ID] [--reason text] [--synthesis text] [--json]
5
5
  */
6
6
 
7
7
  import { isCliEntrypoint } from "./spine-cli/shared.mjs";
@@ -32,6 +32,10 @@ export function formatGateHuman(result, json = false) {
32
32
  ` Status: ${result.gate.status}`,
33
33
  ` Kind: ${result.gate.kind}`,
34
34
  );
35
+ // SP-747 / #280: show the operator's synthesis readback when one was recorded.
36
+ if (typeof result.gate.synthesis === "string" && result.gate.synthesis.trim() !== "") {
37
+ lines.push(` Synthesis: ${result.gate.synthesis}`);
38
+ }
35
39
  if (Array.isArray(result.gate.evidenceRefs) && result.gate.evidenceRefs.length > 0) {
36
40
  lines.push("", " Evidence:");
37
41
  for (const ref of result.gate.evidenceRefs) {
@@ -87,6 +91,12 @@ export function runSpineGate(options) {
87
91
  reason = args[reasonIdx + 1];
88
92
  }
89
93
 
94
+ let synthesis = null;
95
+ const synthesisIdx = args.indexOf("--synthesis");
96
+ if (synthesisIdx >= 0 && args[synthesisIdx + 1]) {
97
+ synthesis = args[synthesisIdx + 1];
98
+ }
99
+
90
100
  batchId = resolveActiveBatchId(projectRoot, batchId);
91
101
  if (!batchId) {
92
102
  const result = {
@@ -106,10 +116,15 @@ export function runSpineGate(options) {
106
116
  let result;
107
117
  switch (action) {
108
118
  case "approve":
109
- result = approveIntegrateGate({ projectRoot, batchId });
119
+ result = approveIntegrateGate({ projectRoot, batchId, synthesis: synthesis ?? undefined });
110
120
  break;
111
121
  case "reject":
112
- result = rejectIntegrateGate({ projectRoot, batchId, reason: reason ?? undefined });
122
+ result = rejectIntegrateGate({
123
+ projectRoot,
124
+ batchId,
125
+ reason: reason ?? undefined,
126
+ synthesis: synthesis ?? undefined,
127
+ });
113
128
  break;
114
129
  case "status":
115
130
  result = getIntegrateGateStatus({ projectRoot, batchId });
@@ -4,6 +4,49 @@ import { readJournalEvents, readJournalTail } from "../src/batch/journal.mjs";
4
4
  import { reconcileBatch } from "../src/batch/reconcile.mjs";
5
5
  import { formatStatusJson } from "../src/batch/status-json.mjs";
6
6
 
7
+ /**
8
+ * Per-row matrix state lines (#230): one block per matrix task listing each
9
+ * row's running/succeeded/failed state, plus concrete retry/cancel commands
10
+ * for the failing rows. Rendered for both plain and --diagnose human output.
11
+ *
12
+ * @param {string[]} lines Output lines (mutated).
13
+ * @param {object} result Reconciliation result from reconcileBatch.
14
+ */
15
+ function appendMatrixRowSections(lines, result) {
16
+ const matrixTasks = (result.signals?.tasks ?? []).filter(
17
+ (task) => Array.isArray(task?.matrixRows) && task.matrixRows.length > 0,
18
+ );
19
+ if (matrixTasks.length === 0) return;
20
+
21
+ for (const task of matrixTasks) {
22
+ const failedRowIds = task.matrixRows
23
+ .filter((row) => row && row.status === "failed")
24
+ .map((row) => row.rowId)
25
+ .filter(Boolean);
26
+ lines.push("", ` Matrix rows (${task.taskId}):`);
27
+ for (const row of task.matrixRows) {
28
+ if (!row || typeof row !== "object") continue;
29
+ const status = String(row.status ?? "pending");
30
+ const exit = row.exitCode != null ? ` exit=${row.exitCode}` : "";
31
+ const commit = typeof row.commitSha === "string" && row.commitSha ? ` @ ${row.commitSha.slice(0, 8)}` : "";
32
+ lines.push(` ${row.rowId}: ${status}${exit}${commit}`);
33
+ }
34
+ if (failedRowIds.length > 0) {
35
+ lines.push(
36
+ ` → Retry one failed row: spine batch retry '${task.taskId}[${failedRowIds[0]}]'`,
37
+ );
38
+ }
39
+ const cancellable = task.matrixRows.some(
40
+ (row) => row && row.status !== "succeeded" && row.status !== "canceled",
41
+ );
42
+ if (cancellable) {
43
+ lines.push(
44
+ ` → Cancel one row: spine batch skip '${task.taskId}[<rowId>]' (whole matrix: spine batch skip ${task.taskId})`,
45
+ );
46
+ }
47
+ }
48
+ }
49
+
7
50
  /**
8
51
  * @param {object} options
9
52
  * @param {string} options.projectRoot
@@ -56,6 +99,8 @@ export function runSpineStatus(options) {
56
99
  lines.push(` → ${result.suggestedCommand}`);
57
100
  }
58
101
 
102
+ appendMatrixRowSections(lines, result);
103
+
59
104
  if (diagnose && result.mergeFailed) {
60
105
  lines.push("");
61
106
  lines.push(` Merge failed: ${result.failedMerges} wave(s)`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "2.19.0",
3
+ "version": "2.20.0",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Contract testCommand execution, npm guard, and verifyContract (SP-603 / SP-541).
4
3
  */
@@ -29,7 +28,7 @@ import {
29
28
  import { formatRefusedContractMetacharMessage, isRefusedContractMetacharCommand } from "../tasks/packet/parse-prompt.mjs";
30
29
 
31
30
  // Shared pre-spawn refusal envelope for the npm-scope (#187) and metachar (#268) guards.
32
- function refusedBeforeSpawnResult(summary) {
31
+ function refusedBeforeSpawnResult(/** @type {string} */ summary) {
33
32
  return { ok: false, exitCode: 1, output: summary, summary, refusedBeforeSpawn: true };
34
33
  }
35
34
 
@@ -147,12 +146,11 @@ function formatRefusedNpmTestDashDashMessage(command) {
147
146
  return `Contract testCommand refused before spawn: npm test -- <path> is blocked at runtime (command: ${command}). ${TEST_COMMAND_NPM_TEST_DASH_DASH_FIX_HINT}`;
148
147
  }
149
148
 
150
- /**
151
-
152
149
  /**
153
150
  * @param {string} worktreePath
154
151
  * @param {string} command
155
152
  * @param {{ maxBuffer?: number }} [options]
153
+ * @returns {{ ok: boolean, exitCode: number, output: string, bufferOverflow?: boolean, summary?: string, refusedBeforeSpawn?: boolean }}
156
154
  */
157
155
  export function runContractTestCommand(worktreePath, command, options = {}) {
158
156
  const trimmed = String(command ?? "").trim();
@@ -183,7 +181,7 @@ export function runContractTestCommand(worktreePath, command, options = {}) {
183
181
  const stderr = String(result.stderr ?? "");
184
182
  const output = `${stdout}\n${stderr}`;
185
183
 
186
- if (result.error?.code === "ENOBUFS") {
184
+ if (/** @type {NodeJS.ErrnoException | undefined} */ (result.error)?.code === "ENOBUFS") {
187
185
  const limitLabel = formatMaxBufferLabel(maxBuffer);
188
186
  return {
189
187
  ok: false,
@@ -204,8 +202,7 @@ export function runContractTestCommand(worktreePath, command, options = {}) {
204
202
  }
205
203
 
206
204
  /**
207
- * @param {string} worktreePath
208
- * @param {object} config
205
+ * @param {{ testing?: { test?: string, testWithCoverage?: string } }} [config]
209
206
  */
210
207
  function resolveCoverageCommand(config) {
211
208
  return (
@@ -260,7 +257,7 @@ function findArtifactMatch(worktreePath, artifactPattern) {
260
257
  /** @type {Array<{ abs: string, rel: string }>} */
261
258
  const stack = [{ abs: searchRoot, rel: baseDir === "." ? "" : baseDir }];
262
259
  while (stack.length > 0) {
263
- const { abs, rel } = stack.pop();
260
+ const { abs, rel } = /** @type {{ abs: string, rel: string }} */ (stack.pop());
264
261
  for (const entry of fs.readdirSync(abs, { withFileTypes: true })) {
265
262
  const entryRel = rel ? `${rel}/${entry.name}` : entry.name;
266
263
  const entryAbs = path.join(abs, entry.name);
@@ -306,6 +303,9 @@ export function prepareContractVerifyEnvironment(worktreePath, parsedContract, c
306
303
  * @param {string} [config.batchId] Batch ID for journal events (optional).
307
304
  * @param {string} [config.taskId] Task ID for journal events (optional).
308
305
  * @param {string} [config.taskFolder] Task folder path for writing failure logs to .reviews/ (optional).
306
+ * @param {{ testRetries?: number, testRetryDelayMs?: number }} [config.contract] Retry tuning for testCommand attempts.
307
+ * @param {number} [config.contractTestMaxBuffer] stdout/stderr capture limit override.
308
+ * @param {{ test?: string, testWithCoverage?: string }} [config.testing] Coverage command selection.
309
309
  * @returns {{ ok: boolean, checks: Array<{ field: string, ok: boolean, message: string }>, retries?: number }}
310
310
  */
311
311
  export function verifyContract(worktreePath, parsedContract, config = {}) {
@@ -315,7 +315,8 @@ export function verifyContract(worktreePath, parsedContract, config = {}) {
315
315
  const sinceCommit = config?.sinceCommit ?? config?.taskStartCommit ?? undefined;
316
316
  const committedFiles = listChangedFiles(worktreePath, baseBranch, sinceCommit);
317
317
 
318
- let indexAndWorktreeFiles = [];
318
+ /** @type {string[]} */
319
+ let indexAndWorktreeFiles = /** @type {string[]} */ ([]);
319
320
  try {
320
321
  const stdout = execFileSync("git", ["diff", "--name-only", "HEAD"], { cwd: worktreePath, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
321
322
  indexAndWorktreeFiles = stdout.split(/\r?\n/).map(l => l.trim()).filter(Boolean);
@@ -334,8 +335,7 @@ export function verifyContract(worktreePath, parsedContract, config = {}) {
334
335
  const maxRetries = config?.contract?.testRetries ?? CONTRACT_TEST_DEFAULT_RETRIES;
335
336
  const retryDelayMs = config?.contract?.testRetryDelayMs ?? CONTRACT_TEST_RETRY_DELAY_MS;
336
337
  const totalAttempts = maxRetries + 1;
337
- let lastResult = null;
338
- let successAttempt = 0;
338
+ let lastResult = /** @type {{ ok: boolean, exitCode: number, output: string, bufferOverflow?: boolean, summary?: string, refusedBeforeSpawn?: boolean } | null} */ (null), successAttempt = 0;
339
339
 
340
340
  for (let attempt = 1; attempt <= totalAttempts; attempt++) {
341
341
  lastResult = runContractTestCommand(worktreePath, parsedContract.testCommand, {
@@ -369,19 +369,20 @@ export function verifyContract(worktreePath, parsedContract, config = {}) {
369
369
  }
370
370
  }
371
371
 
372
- testCommandOutput = lastResult.output;
373
- testCommandOk = lastResult.ok;
372
+ const finalResult = /** @type {{ ok: boolean, exitCode: number, output: string, bufferOverflow?: boolean, summary?: string, refusedBeforeSpawn?: boolean }} */ (lastResult);
373
+ testCommandOutput = finalResult.output;
374
+ testCommandOk = finalResult.ok;
374
375
  const attemptLabel = successAttempt > 1
375
376
  ? ` (passed on attempt ${successAttempt} of ${totalAttempts})`
376
377
  : "";
377
378
  checks.push({
378
379
  field: "testCommand",
379
- ok: lastResult.ok,
380
- message: lastResult.ok
380
+ ok: finalResult.ok,
381
+ message: finalResult.ok
381
382
  ? `testCommand passed${attemptLabel}`
382
- : lastResult.bufferOverflow
383
- ? `Contract ${lastResult.summary}`
384
- : `Contract testCommand failed after ${totalAttempts} attempt(s) (exit ${lastResult.exitCode}): ${lastResult.summary || "(no output)"}`,
383
+ : finalResult.bufferOverflow
384
+ ? `Contract ${finalResult.summary}`
385
+ : `Contract testCommand failed after ${totalAttempts} attempt(s) (exit ${finalResult.exitCode}): ${finalResult.summary || "(no output)"}`,
385
386
  });
386
387
  }
387
388
 
@@ -65,6 +65,11 @@ export function commitLaneAndValidateWorktree({
65
65
  porcelain: preCommitPorcelain,
66
66
  });
67
67
 
68
+ const canceledMatrixRowIds = (Array.isArray(task?.matrixRows) ? task.matrixRows : [])
69
+ .filter((row) => row && row.status === "canceled")
70
+ .map((row) => row.rowId)
71
+ .filter(Boolean);
72
+
68
73
  const laneCommit = commitLaneWorktree({
69
74
  worktreePath,
70
75
  taskBranch,
@@ -74,6 +79,7 @@ export function commitLaneAndValidateWorktree({
74
79
  projectRoot,
75
80
  ignorePatterns,
76
81
  fileScopePaths,
82
+ canceledMatrixRowIds,
77
83
  });
78
84
  if (!laneCommit.ok) {
79
85
  task.status = "failed";