pi-spine 2.5.0 → 2.7.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.
Files changed (33) hide show
  1. package/bin/spine-plan.mjs +2 -1
  2. package/bin/spine-tasks.mjs +2 -1
  3. package/bin/spine.mjs +22 -0
  4. package/package.json +1 -1
  5. package/src/batch/attached-runner-promote.mjs +95 -11
  6. package/src/batch/diagnosis-alternatives.mjs +18 -0
  7. package/src/batch/diagnosis-gate-ready.mjs +23 -0
  8. package/src/batch/diagnosis-pending-lane.mjs +63 -0
  9. package/src/batch/diagnosis-retry-command.mjs +23 -0
  10. package/src/batch/diagnosis-tail-state.mjs +68 -0
  11. package/src/batch/diagnosis.mjs +69 -52
  12. package/src/batch/engine-lanes/commit.mjs +2 -0
  13. package/src/batch/engine-lanes.mjs +2 -3
  14. package/src/batch/evidence-command.mjs +241 -16
  15. package/src/batch/lane-commit.mjs +77 -8
  16. package/src/batch/lifecycle-archive.mjs +71 -0
  17. package/src/batch/lifecycle.mjs +27 -67
  18. package/src/batch/orphan-detect.mjs +68 -5
  19. package/src/batch/post-merge-limbo.mjs +137 -22
  20. package/src/batch/reconcile-batch.mjs +40 -43
  21. package/src/batch/reconcile-diagnosis-context.mjs +88 -0
  22. package/src/batch/reconcile-diagnosis.mjs +14 -32
  23. package/src/batch/resume-multi-validate.mjs +51 -9
  24. package/src/batch/retry.mjs +18 -2
  25. package/src/config/missing-config-hint.mjs +19 -0
  26. package/src/config/pi-spine-root.mjs +22 -0
  27. package/src/config/preflight/discovery.mjs +6 -4
  28. package/src/config/spine-config-load.mjs +30 -2
  29. package/src/config/spine-init-constants.mjs +7 -3
  30. package/src/doctor/duplicate-install.mjs +100 -0
  31. package/src/doctor/run-doctor-checks.mjs +10 -1
  32. package/src/doctor/worktree-health.mjs +4 -0
  33. package/templates/spine-config.json +5 -4
@@ -23,8 +23,14 @@ export {
23
23
  inferMergeGitignoredFailure,
24
24
  summarizeMergeFailures,
25
25
  } from "./diagnosis-merge-failure.mjs";
26
- import { buildRunningTailHeadline } from "./diagnosis-tail-state.mjs";
27
- export { buildRunningTailHeadline, isRunningWithoutActiveWorkers } from "./diagnosis-tail-state.mjs";
26
+ import { buildRunningTailHeadline, isPostIntegrateEngineLimbo, buildPostIntegrateEngineLimboHeadline } from "./diagnosis-tail-state.mjs";
27
+ export {
28
+ buildPostIntegrateEngineLimboHeadline,
29
+ buildRunningTailHeadline,
30
+ isEngineStillRunning,
31
+ isPostIntegrateEngineLimbo,
32
+ isRunningWithoutActiveWorkers,
33
+ } from "./diagnosis-tail-state.mjs";
28
34
  export { buildReviewHonorHeadlineSuffix, findLatestReviewHonorSignal } from "./review.mjs";
29
35
  import {
30
36
  buildStubFailureHeadline,
@@ -53,44 +59,20 @@ export {
53
59
  } from "./diagnosis-parent-exit.mjs";
54
60
  import { buildReviewHonorHeadlineSuffix } from "./review.mjs";
55
61
  export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis-launch-failure.mjs";
56
-
57
- const INVALID_BARE_RETRY_FORCE = /^spine batch retry --force$/;
58
-
59
- /**
60
- * Gate-ready batches must not headline historical merge/gitignored blockers (#195 / FR-REL231-01).
61
- *
62
- * @param {string} diagnosis
63
- * @param {object} [ctx]
64
- * @param {boolean} [ctx.allTasksTerminalSuccess]
65
- * @param {boolean} [ctx.integrateGateOpen]
66
- * @returns {boolean}
67
- */
68
- export function isGateReadyHeadlineContext(diagnosis, ctx = {}) {
69
- if (diagnosis === "needs_integrate") {
70
- return true;
71
- }
72
- if (ctx.allTasksTerminalSuccess === true && ctx.integrateGateOpen === true) {
73
- return true;
74
- }
75
- return false;
76
- }
77
-
78
- /**
79
- * Retry suggestions must include a task id; journal salvage payloads may be stale.
80
- *
81
- * @param {string|null|undefined} command
82
- * @param {string|null|undefined} taskId
83
- * @returns {string|null}
84
- */
85
- export function sanitizeRetrySuggestedCommand(command, taskId) {
86
- if (typeof command !== "string" || command.length === 0) {
87
- return command ?? null;
88
- }
89
- if (INVALID_BARE_RETRY_FORCE.test(command.trim())) {
90
- return taskId ? `spine batch retry ${taskId}` : "spine status --diagnose";
91
- }
92
- return command;
93
- }
62
+ import { isGateReadyHeadlineContext } from "./diagnosis-gate-ready.mjs";
63
+ export { isGateReadyHeadlineContext };
64
+ import { sanitizeRetrySuggestedCommand } from "./diagnosis-retry-command.mjs";
65
+ export { sanitizeRetrySuggestedCommand };
66
+ import {
67
+ buildPendingLaneLandHeadline,
68
+ buildPendingLaneLandSuggestedCommand,
69
+ } from "./diagnosis-pending-lane.mjs";
70
+ export {
71
+ buildPendingLaneLandHeadline,
72
+ buildPendingLaneLandSuggestedCommand,
73
+ findPendingLaneLandTasks,
74
+ shouldDiagnosePendingLaneLand,
75
+ } from "./diagnosis-pending-lane.mjs";
94
76
 
95
77
  export const DIAGNOSIS_TAXONOMY = [
96
78
  "running",
@@ -108,6 +90,8 @@ export const DIAGNOSIS_TAXONOMY = [
108
90
  "limbo_stale",
109
91
  "human_base_diverged",
110
92
  "integrate_isolated_ok",
93
+ "pending_lane_land",
94
+ "engine_still_running",
111
95
  "failed",
112
96
  "aborted",
113
97
  ];
@@ -118,6 +102,7 @@ const NO_PAUSE_DIAGNOSES = new Set([
118
102
  "needs_integrate",
119
103
  "engine_orphaned",
120
104
  "integrate_isolated_ok",
105
+ "engine_still_running",
121
106
  ]);
122
107
  const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
123
108
  "code_review_spawn_failed",
@@ -138,6 +123,7 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
138
123
  * @param {boolean} [ctx.mergeFailed]
139
124
  * @param {string|null} [ctx.taskBranch]
140
125
  * @param {string[]|null} [ctx.gitignoredPaths]
126
+ * @param {object[]} [ctx.pendingLaneLandTasks]
141
127
  */
142
128
  export function buildSuggestedCommand(diagnosis, ctx = {}) {
143
129
  const preferGateReady = isGateReadyHeadlineContext(diagnosis, ctx);
@@ -157,6 +143,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
157
143
  }
158
144
 
159
145
  switch (diagnosis) {
146
+ case "engine_still_running":
147
+ return "spine wait --until completed,failed,needs_integrate --timeout 2h";
160
148
  case "limbo_stale":
161
149
  case "completed_manual":
162
150
  return "spine batch dismiss";
@@ -182,10 +170,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
182
170
  if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
183
171
  return buildStubFailureSuggestedCommand(ctx);
184
172
  }
185
- {
186
- const primaryCommand = buildPrimaryFailureSuggestedCommand(ctx);
187
- if (primaryCommand) return primaryCommand;
188
- }
173
+ const primaryCommand = buildPrimaryFailureSuggestedCommand(ctx);
174
+ if (primaryCommand) return primaryCommand;
189
175
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
190
176
  return "spine doctor";
191
177
  }
@@ -274,6 +260,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
274
260
  return "spine sync-base";
275
261
  case "integrate_isolated_ok":
276
262
  return "spine sync-base";
263
+ case "pending_lane_land":
264
+ return buildPendingLaneLandSuggestedCommand(ctx.batchId, ctx.pendingLaneLandTasks ?? []);
277
265
  default:
278
266
  return "spine status --diagnose";
279
267
  }
@@ -298,6 +286,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
298
286
  * @param {string|null} [ctx.lastError]
299
287
  * @param {number} [ctx.succeededTasks]
300
288
  * @param {number} [ctx.totalTasks]
289
+ * @param {object[]} [ctx.pendingLaneLandTasks]
290
+ * @param {string|null|undefined} [ctx.baseBranch]
301
291
  */
302
292
  export function buildHeadline(diagnosis, ctx = {}) {
303
293
  const batchLabel = ctx.batchId ? `Batch ${ctx.batchId}` : "Batch";
@@ -317,6 +307,17 @@ export function buildHeadline(diagnosis, ctx = {}) {
317
307
  }
318
308
 
319
309
  switch (diagnosis) {
310
+ case "engine_still_running": {
311
+ const enginePid = ctx.enginePid;
312
+ const pidSuffix =
313
+ enginePid != null && Number.isFinite(Number(enginePid))
314
+ ? ` (PID ${enginePid})`
315
+ : "";
316
+ if (ctx.gitMerged === true) {
317
+ return `${batchLabel} resume engine still running after integrate${pidSuffix} — wait, abort, or batch complete after exit`;
318
+ }
319
+ return `${batchLabel} engine still running${pidSuffix} — complete refused`;
320
+ }
320
321
  case "limbo_stale":
321
322
  return `${batchLabel} finished but state is stale — dismiss to clear`;
322
323
  case "completed_manual":
@@ -325,10 +326,8 @@ export function buildHeadline(diagnosis, ctx = {}) {
325
326
  if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
326
327
  return buildStubFailureHeadline(batchLabel, ctx);
327
328
  }
328
- {
329
- const primaryHeadline = buildPrimaryFailureHeadline(batchLabel, ctx);
330
- if (primaryHeadline) return primaryHeadline;
331
- }
329
+ const primaryHeadline = buildPrimaryFailureHeadline(batchLabel, ctx);
330
+ if (primaryHeadline) return primaryHeadline;
332
331
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
333
332
  return `${batchLabel} failed at worker launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
334
333
  }
@@ -413,6 +412,9 @@ export function buildHeadline(diagnosis, ctx = {}) {
413
412
  ? `Task ${ctx.failedTaskId} needs replan — edit PROMPT.md before retry`
414
413
  : `${batchLabel} has tasks needing replan — edit PROMPT.md before retry`;
415
414
  case "running": {
415
+ if (isPostIntegrateEngineLimbo(ctx)) {
416
+ return buildPostIntegrateEngineLimboHeadline(batchLabel, ctx);
417
+ }
416
418
  const reviewHonorSuffix = buildReviewHonorHeadlineSuffix(ctx.reviewHonorSignal);
417
419
  if (reviewHonorSuffix && ctx.reviewHonorSignal?.taskId) {
418
420
  return `${batchLabel} task ${ctx.reviewHonorSignal.taskId}: ${reviewHonorSuffix}`;
@@ -444,6 +446,8 @@ export function buildHeadline(diagnosis, ctx = {}) {
444
446
  }
445
447
  case "integrate_isolated_ok":
446
448
  return `${batchLabel} — isolated integrate landed; sync human checkout with base`;
449
+ case "pending_lane_land":
450
+ return buildPendingLaneLandHeadline(batchLabel, ctx);
447
451
  default:
448
452
  return `${batchLabel} requires attention (phase: ${ctx.phase ?? "unknown"})`;
449
453
  }
@@ -456,16 +460,29 @@ export function shouldNeverSuggestPause(diagnosis) {
456
460
  return NO_PAUSE_DIAGNOSES.has(diagnosis);
457
461
  }
458
462
 
463
+ /**
464
+ * @param {string} diagnosis
465
+ * @param {object} ctx
466
+ * @returns {string}
467
+ */
468
+ export function resolveEffectiveDiagnosis(diagnosis, ctx = {}) {
469
+ if (diagnosis === "running" && isPostIntegrateEngineLimbo(ctx)) {
470
+ return "engine_still_running";
471
+ }
472
+ return diagnosis;
473
+ }
474
+
459
475
  /**
460
476
  * @param {string} diagnosis
461
477
  * @param {object} ctx
462
478
  * @returns {Pick<ReconciliationResult, "diagnosis" | "headline" | "suggestedCommand" | "alternatives">}
463
479
  */
464
480
  export function buildDiagnosisOutput(diagnosis, ctx = {}) {
481
+ const effectiveDiagnosis = resolveEffectiveDiagnosis(diagnosis, ctx);
465
482
  return {
466
- diagnosis,
467
- headline: buildHeadline(diagnosis, ctx),
468
- suggestedCommand: buildSuggestedCommand(diagnosis, ctx),
469
- alternatives: buildAlternatives(diagnosis, ctx),
483
+ diagnosis: effectiveDiagnosis,
484
+ headline: buildHeadline(effectiveDiagnosis, ctx),
485
+ suggestedCommand: buildSuggestedCommand(effectiveDiagnosis, ctx),
486
+ alternatives: buildAlternatives(effectiveDiagnosis, ctx),
470
487
  };
471
488
  }
@@ -72,6 +72,8 @@ export function commitLaneAndValidateWorktree({
72
72
  batchId,
73
73
  taskFolder,
74
74
  projectRoot,
75
+ ignorePatterns,
76
+ fileScopePaths,
75
77
  });
76
78
  if (!laneCommit.ok) {
77
79
  task.status = "failed";
@@ -23,6 +23,7 @@ import {
23
23
  import { runWorker } from "./worker-host.mjs";
24
24
  import { runCodeReviewPhase, runFinalReviewPhase } from "./engine-lanes/review.mjs";
25
25
  import { ensureLaneSyncedForSharedScopeDeps } from "./engine-lanes/orch-sync.mjs";
26
+ import { resolveWorktreeSetupIgnorePaths } from "../config/spine-config-load.mjs";
26
27
 
27
28
  export {
28
29
  buildTasksAndLanesFromPlan,
@@ -347,9 +348,7 @@ export async function runTaskOnLane({
347
348
  }
348
349
  }
349
350
 
350
- const ignorePatterns = Array.isArray(config?.worktreeSetupIgnorePaths)
351
- ? config.worktreeSetupIgnorePaths
352
- : [];
351
+ const ignorePatterns = resolveWorktreeSetupIgnorePaths(config);
353
352
  const commitResult = commitLaneAndValidateWorktree({
354
353
  worktreePath: wt,
355
354
  taskBranch,
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Safe argv execution for config-derived integrate-gate evidence commands.
3
3
  * Allowlisted executables only; rejects shell metacharacters (no shell: true).
4
+ * Phase B: allowlisted package-manager segments may be joined with `&&` only.
4
5
  */
5
6
 
6
7
  import path from "node:path";
7
8
  import { execFileSync } from "node:child_process";
9
+ import { validateWorkerLaunchScriptPath } from "../config/worker-launch-script.mjs";
8
10
 
9
11
  /**
10
12
  * Allowed first-token executables for evidence commands.
@@ -13,6 +15,24 @@ import { execFileSync } from "node:child_process";
13
15
  */
14
16
  export const ALLOWED_EVIDENCE_EXECUTABLES = new Set(["npm", "node", "pnpm", "yarn", "npx"]);
15
17
 
18
+ /**
19
+ * Interpreter basenames allowed only as project-local relative paths under
20
+ * `.venv/` or `venv/` (see {@link isAllowedProjectLocalInterpreter}).
21
+ * Bare names (PATH lookup) and absolute/outside-project paths stay rejected.
22
+ * @type {Set<string>}
23
+ */
24
+ export const ALLOWED_PROJECT_LOCAL_INTERPRETERS = new Set(["python", "python3"]);
25
+
26
+ /** Relative venv roots that may host an allowed interpreter (posix-normalized). */
27
+ const PROJECT_LOCAL_VENV_PREFIXES = [".venv/", "venv/"];
28
+
29
+ /** Relative prefix for validated gate-evidence scripts (posix-normalized). */
30
+ const EVIDENCE_SCRIPTS_PREFIX = "scripts/";
31
+
32
+ /**
33
+ * Forbidden shell metacharacters. Checked after stripping allowlisted `&&`
34
+ * chain separators so a lone `&` still fails closed.
35
+ */
16
36
  const SHELL_METACHAR_PATTERN = /[;|&`<>]|>>|\$\(|\$\{/;
17
37
 
18
38
  export class EvidenceCommandError extends Error {
@@ -37,32 +57,231 @@ export function assertSafeEvidenceCommand(command) {
37
57
  if (/[\r\n]/.test(trimmed)) {
38
58
  throw new EvidenceCommandError("evidence command contains newlines");
39
59
  }
40
- if (SHELL_METACHAR_PATTERN.test(trimmed)) {
60
+
61
+ // Allow `&&` as the only chain operator; strip it before metachar / `$` scans.
62
+ const withoutChains = trimmed.replaceAll("&&", " ");
63
+ if (SHELL_METACHAR_PATTERN.test(withoutChains)) {
41
64
  throw new EvidenceCommandError("evidence command contains shell metacharacters");
42
65
  }
43
- if (/\$/.test(trimmed)) {
66
+ if (/\$/.test(withoutChains)) {
44
67
  throw new EvidenceCommandError("evidence command contains shell variable expansion");
45
68
  }
46
69
  }
47
70
 
71
+ /**
72
+ * Split an evidence command on `&&` outside quotes (Phase B chain grammar).
73
+ * @param {string} line
74
+ * @returns {string[]}
75
+ */
76
+ function splitEvidenceChainSegments(line) {
77
+ /** @type {string[]} */
78
+ const segments = [];
79
+ let current = "";
80
+ /** @type {"'" | '"' | null} */
81
+ let quote = null;
82
+
83
+ for (let i = 0; i < line.length; i++) {
84
+ const ch = line[i];
85
+ if (quote) {
86
+ // Preserve escapes so tokenizeCommandLine can re-parse the segment.
87
+ if (ch === "\\" && quote === '"' && i + 1 < line.length) {
88
+ current += ch;
89
+ i += 1;
90
+ current += line[i];
91
+ continue;
92
+ }
93
+ current += ch;
94
+ if (ch === quote) {
95
+ quote = null;
96
+ }
97
+ continue;
98
+ }
99
+
100
+ if (ch === "'" || ch === '"') {
101
+ quote = ch;
102
+ current += ch;
103
+ continue;
104
+ }
105
+
106
+ if (ch === "&" && line[i + 1] === "&") {
107
+ segments.push(current.trim());
108
+ current = "";
109
+ i += 1;
110
+ continue;
111
+ }
112
+
113
+ current += ch;
114
+ }
115
+
116
+ if (quote) {
117
+ throw new EvidenceCommandError("unclosed quote in evidence command");
118
+ }
119
+
120
+ segments.push(current.trim());
121
+ return segments;
122
+ }
123
+
124
+ /**
125
+ * Parse a config testing command into one or more argv arrays without a shell.
126
+ * Multi-segment results are allowlisted `&&` chains (Phase B).
127
+ * @param {string} command
128
+ * @returns {string[][]}
129
+ */
130
+ export function parseEvidenceCommandChain(command) {
131
+ assertSafeEvidenceCommand(command);
132
+ const segments = splitEvidenceChainSegments(command.trim());
133
+ if (segments.length === 0) {
134
+ throw new EvidenceCommandError("empty evidence command");
135
+ }
136
+ if (segments.some((segment) => !segment)) {
137
+ throw new EvidenceCommandError("empty evidence command chain segment");
138
+ }
139
+
140
+ const chainMode = segments.length > 1;
141
+ return segments.map((segment) => parseEvidenceSegmentArgv(segment, chainMode));
142
+ }
143
+
48
144
  /**
49
145
  * Parse a config testing command into argv without invoking a shell.
146
+ * Single-segment only; use {@link parseEvidenceCommandChain} for `&&` chains.
50
147
  * @param {string} command
51
148
  * @returns {string[]}
52
149
  */
53
150
  export function parseEvidenceCommandArgv(command) {
54
- assertSafeEvidenceCommand(command);
55
- const argv = tokenizeCommandLine(command.trim());
151
+ const chain = parseEvidenceCommandChain(command);
152
+ if (chain.length !== 1) {
153
+ throw new EvidenceCommandError(
154
+ "evidence command && chains must use parseEvidenceCommandChain or runEvidenceCommand",
155
+ );
156
+ }
157
+ return chain[0];
158
+ }
159
+
160
+ /**
161
+ * @param {string} segment
162
+ * @param {boolean} chainMode
163
+ * @returns {string[]}
164
+ */
165
+ function parseEvidenceSegmentArgv(segment, chainMode) {
166
+ const argv = tokenizeCommandLine(segment);
56
167
  if (argv.length === 0) {
57
168
  throw new EvidenceCommandError("empty evidence command");
58
169
  }
59
170
 
60
171
  const executable = path.basename(argv[0]);
61
- if (!ALLOWED_EVIDENCE_EXECUTABLES.has(executable)) {
62
- throw new EvidenceCommandError(`evidence executable not allowed: ${executable}`);
172
+ if (ALLOWED_EVIDENCE_EXECUTABLES.has(executable)) {
173
+ return argv;
174
+ }
175
+
176
+ // Phase A single-segment paths stay available; multi-segment chains are
177
+ // package-manager / node allowlist only (FR-REL270-05).
178
+ if (!chainMode && isAllowedProjectLocalInterpreter(argv[0])) {
179
+ return argv;
180
+ }
181
+ if (!chainMode && isAllowedEvidenceScriptsPath(argv[0])) {
182
+ return argv;
183
+ }
184
+
185
+ throw new EvidenceCommandError(`evidence executable not allowed: ${executable}`);
186
+ }
187
+
188
+ /**
189
+ * Allow project-local interpreters for gate evidence (e.g. `.venv/bin/python`).
190
+ *
191
+ * Exact rule: first token must be a relative path (not absolute), with no `..`
192
+ * segments after posix normalization, whose normalized form starts with
193
+ * `.venv/` or `venv/`, and whose basename is in
194
+ * {@link ALLOWED_PROJECT_LOCAL_INTERPRETERS} (`python` or `python3`).
195
+ * Rejects bare interpreter names and absolute/outside-project paths.
196
+ *
197
+ * @param {string} firstToken
198
+ * @returns {boolean}
199
+ */
200
+ export function isAllowedProjectLocalInterpreter(firstToken) {
201
+ if (typeof firstToken !== "string" || !firstToken) {
202
+ return false;
203
+ }
204
+ if (path.isAbsolute(firstToken)) {
205
+ return false;
206
+ }
207
+
208
+ const posixToken = firstToken.replaceAll("\\", "/");
209
+ const segments = posixToken.split("/");
210
+ if (segments.some((segment) => segment === "..")) {
211
+ return false;
212
+ }
213
+
214
+ const normalized = path.posix.normalize(posixToken);
215
+ if (normalized.startsWith("../") || normalized === "..") {
216
+ return false;
217
+ }
218
+ if (path.posix.isAbsolute(normalized)) {
219
+ return false;
220
+ }
221
+
222
+ const underVenv = PROJECT_LOCAL_VENV_PREFIXES.some((prefix) => normalized.startsWith(prefix));
223
+ if (!underVenv) {
224
+ return false;
63
225
  }
64
226
 
65
- return argv;
227
+ const basename = path.posix.basename(normalized);
228
+ return ALLOWED_PROJECT_LOCAL_INTERPRETERS.has(basename);
229
+ }
230
+
231
+ /**
232
+ * Lightweight parse-time check: first token is a relative path under `scripts/`
233
+ * with no parent traversal. Full symlink/root validation runs at execution via
234
+ * {@link validateWorkerLaunchScriptPath} (same sandbox as workerLaunchScript).
235
+ *
236
+ * @param {string} firstToken
237
+ * @returns {boolean}
238
+ */
239
+ export function isAllowedEvidenceScriptsPath(firstToken) {
240
+ if (typeof firstToken !== "string" || !firstToken) {
241
+ return false;
242
+ }
243
+ if (path.isAbsolute(firstToken)) {
244
+ return false;
245
+ }
246
+
247
+ const posixToken = firstToken.replaceAll("\\", "/");
248
+ const segments = posixToken.split("/");
249
+ if (segments.some((segment) => segment === "..")) {
250
+ return false;
251
+ }
252
+
253
+ const normalized = path.posix.normalize(posixToken);
254
+ if (normalized.startsWith("../") || normalized === "..") {
255
+ return false;
256
+ }
257
+ if (path.posix.isAbsolute(normalized)) {
258
+ return false;
259
+ }
260
+
261
+ return normalized.startsWith(EVIDENCE_SCRIPTS_PREFIX);
262
+ }
263
+
264
+ /**
265
+ * Resolve and validate a scripts/ evidence argv for execFile (no shell).
266
+ *
267
+ * @param {string} projectRoot
268
+ * @param {string[]} argv
269
+ * @returns {string[]}
270
+ */
271
+ export function resolveEvidenceScriptsArgv(projectRoot, argv) {
272
+ if (!isAllowedEvidenceScriptsPath(argv[0])) {
273
+ return argv;
274
+ }
275
+
276
+ const validated = validateWorkerLaunchScriptPath(projectRoot, argv[0]);
277
+ if (!validated.ok) {
278
+ throw new EvidenceCommandError(validated.message ?? "evidence script path invalid");
279
+ }
280
+ if (!validated.scriptPath) {
281
+ throw new EvidenceCommandError("evidence script path invalid");
282
+ }
283
+
284
+ return [validated.scriptPath, ...argv.slice(1)];
66
285
  }
67
286
 
68
287
  /**
@@ -127,15 +346,21 @@ export function runEvidenceCommand(projectRoot, command, maxBytes = 256 * 1024)
127
346
  if (!command) return { ok: false, skipped: true, output: "" };
128
347
 
129
348
  try {
130
- const argv = parseEvidenceCommandArgv(command);
131
- const output = execFileSync(argv[0], argv.slice(1), {
132
- cwd: projectRoot,
133
- encoding: "utf-8",
134
- stdio: ["ignore", "pipe", "pipe"],
135
- timeout: 10 * 60 * 1000,
136
- maxBuffer: maxBytes,
137
- });
138
- return { ok: true, skipped: false, output: String(output ?? "") };
349
+ const chain = parseEvidenceCommandChain(command);
350
+ /** @type {string[]} */
351
+ const outputs = [];
352
+ for (const argv of chain) {
353
+ const execArgv = resolveEvidenceScriptsArgv(projectRoot, argv);
354
+ const output = execFileSync(execArgv[0], execArgv.slice(1), {
355
+ cwd: projectRoot,
356
+ encoding: "utf-8",
357
+ stdio: ["ignore", "pipe", "pipe"],
358
+ timeout: 10 * 60 * 1000,
359
+ maxBuffer: maxBytes,
360
+ });
361
+ outputs.push(String(output ?? ""));
362
+ }
363
+ return { ok: true, skipped: false, output: outputs.join("") };
139
364
  } catch (err) {
140
365
  if (err instanceof EvidenceCommandError) {
141
366
  return {