pi-spine 2.28.0 → 2.29.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-cli/cli-args.mjs +117 -0
- package/bin/spine-gate.mjs +28 -21
- package/bin/spine-integrate.mjs +28 -7
- package/bin/spine-issue.mjs +2 -1
- package/bin/spine-settings.mjs +7 -9
- package/bin/spine-worker-runner.mjs +5 -5
- package/bin/spine.mjs +10 -3
- package/package.json +1 -1
- package/src/batch/contract-exec.mjs +15 -31
- package/src/batch/contract-review.mjs +266 -0
- package/src/batch/contract-spawn.mjs +31 -0
- package/src/batch/diagnosis-primary-failure.mjs +58 -0
- package/src/batch/engine-lanes/commit.mjs +4 -0
- package/src/batch/engine-lanes/matrix-run.mjs +2 -0
- package/src/batch/evidence-command.mjs +18 -21
- package/src/batch/evidence-exec.mjs +79 -0
- package/src/batch/lane-commit-keep-paths.mjs +75 -0
- package/src/batch/lane-commit.mjs +19 -3
- package/src/batch/lane-dirty-check.mjs +17 -7
- package/src/batch/provider-quota.mjs +19 -0
- package/src/batch/reconcile-classify.mjs +28 -1
- package/src/batch/reconcile-diagnosis-context.mjs +2 -0
- package/src/batch/sequence-wait.mjs +7 -5
- package/src/batch/state-io.mjs +29 -3
- package/src/config/contract.mjs +60 -0
- package/src/config/settings-fields.mjs +59 -1
- package/src/config/spine-config-schema.mjs +32 -0
- package/src/doctor/agent-template-drift.mjs +65 -0
- package/src/doctor/run-doctor-checks.mjs +4 -0
- package/src/doctor/stet-capacity.mjs +171 -0
- package/src/tasks/packet/parse-prompt.mjs +12 -27
- package/src/tasks/packet/validate-contract.mjs +2 -0
- package/src/batch/lane-dirty-check-commit.mjs +0 -366
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract reviewCommand step (SP-845).
|
|
3
|
+
*
|
|
4
|
+
* Runs once after testCommand passes, with its own timeout
|
|
5
|
+
* (`contract.reviewTimeoutMs`) and an explicit policy (`contract.reviewPolicy`
|
|
6
|
+
* = `blocking` | `advisory`). No retries: reviewers resume their own session,
|
|
7
|
+
* so a re-run would re-review rather than resume.
|
|
8
|
+
*
|
|
9
|
+
* Blocking: a non-zero exit or a timeout fails the contract with a
|
|
10
|
+
* `reviewCommand` check. Advisory: the check passes, but the engine journals
|
|
11
|
+
* `contract.review_advisory` and appends a row to the task STATUS.md
|
|
12
|
+
* Discoveries table so the failure stays visible.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
|
|
18
|
+
import { CONTRACT_REVIEW_TIMEOUT_DEFAULT_MS } from "../config/contract.mjs";
|
|
19
|
+
import { findContractCommandMetacharIssue } from "../tasks/packet/parse-prompt.mjs";
|
|
20
|
+
import { appendJournalEvent } from "./journal.mjs";
|
|
21
|
+
import { buildContractTestEnv, runShellCommandAsync } from "./contract-spawn.mjs";
|
|
22
|
+
|
|
23
|
+
/** Default stdout/stderr capture limit for contract reviewCommand (mirrors #86). */
|
|
24
|
+
export const CONTRACT_REVIEW_COMMAND_MAX_BUFFER = 10 * 1024 * 1024;
|
|
25
|
+
|
|
26
|
+
/** Policy applied when `contract.reviewPolicy` is unset — reviews block. */
|
|
27
|
+
export const CONTRACT_REVIEW_POLICY_DEFAULT = "blocking";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {Object} ContractReviewCommandResult
|
|
31
|
+
* @property {boolean} ok
|
|
32
|
+
* @property {number} exitCode
|
|
33
|
+
* @property {string} output
|
|
34
|
+
* @property {boolean} [timedOut]
|
|
35
|
+
* @property {boolean} [bufferOverflow]
|
|
36
|
+
* @property {boolean} [refusedBeforeSpawn]
|
|
37
|
+
* @property {string} [summary]
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {number} timeoutMs
|
|
42
|
+
* @returns {string} e.g. "20 min" / "0.5 min", matching runContractTestCommand labels.
|
|
43
|
+
*/
|
|
44
|
+
export function formatReviewTimeoutLabel(timeoutMs) {
|
|
45
|
+
return `${(timeoutMs / 60000).toFixed(2).replace(/\.?0+$/, "")} min`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Shared pre-spawn refusal envelope, mirroring contract-exec's shape.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} summary
|
|
52
|
+
*/
|
|
53
|
+
function refusedBeforeSpawnResult(summary) {
|
|
54
|
+
return { ok: false, exitCode: 1, output: summary, summary, refusedBeforeSpawn: true };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Run the contract reviewCommand once.
|
|
59
|
+
*
|
|
60
|
+
* Mirrors runContractTestCommand's shell semantics ($SHELL, capped capture,
|
|
61
|
+
* tree-kill on timeout) minus the npm-scope guard and retries — reviewCommand
|
|
62
|
+
* never retries. "true" and empty commands pass without spawning, like
|
|
63
|
+
* testCommand.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} worktreePath
|
|
66
|
+
* @param {string} command
|
|
67
|
+
* @param {{ timeoutMs?: number, maxBuffer?: number }} [options]
|
|
68
|
+
* @returns {Promise<ContractReviewCommandResult>}
|
|
69
|
+
*/
|
|
70
|
+
export async function runContractReviewCommand(worktreePath, command, options = {}) {
|
|
71
|
+
const trimmed = String(command ?? "").trim();
|
|
72
|
+
if (!trimmed || trimmed === "true") {
|
|
73
|
+
return { ok: true, exitCode: 0, output: "" };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Defense in depth: parse-prompt already rejects these at packet parse
|
|
77
|
+
// time; matrix-row substitution can still inject them afterwards (SP-781).
|
|
78
|
+
if (trimmed.includes("\n")) {
|
|
79
|
+
return refusedBeforeSpawnResult("Contract reviewCommand must not contain newlines");
|
|
80
|
+
}
|
|
81
|
+
const metacharIssue = findContractCommandMetacharIssue(trimmed);
|
|
82
|
+
if (metacharIssue) {
|
|
83
|
+
return refusedBeforeSpawnResult(
|
|
84
|
+
`Contract reviewCommand refused before spawn: ${metacharIssue} (command: ${trimmed}). reviewCommand runs through a shell; remove $, backticks, ;, |, || or lone & — && chains are allowed (#268).`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const timeoutMs = options.timeoutMs ?? CONTRACT_REVIEW_TIMEOUT_DEFAULT_MS;
|
|
89
|
+
const maxBuffer = options.maxBuffer ?? CONTRACT_REVIEW_COMMAND_MAX_BUFFER;
|
|
90
|
+
const result = await runShellCommandAsync(worktreePath, trimmed, {
|
|
91
|
+
env: buildContractTestEnv(),
|
|
92
|
+
timeoutMs,
|
|
93
|
+
maxBuffer,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const output = `${String(result.stdout ?? "")}\n${String(result.stderr ?? "")}`;
|
|
97
|
+
|
|
98
|
+
if (result.timedOut) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
exitCode: Number(result.exitCode ?? 1),
|
|
102
|
+
output,
|
|
103
|
+
timedOut: true,
|
|
104
|
+
summary: `reviewCommand timed out after ${formatReviewTimeoutLabel(timeoutMs)} and was terminated`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (result.truncated) {
|
|
109
|
+
return {
|
|
110
|
+
ok: false,
|
|
111
|
+
exitCode: Number(result.exitCode ?? 255),
|
|
112
|
+
output,
|
|
113
|
+
bufferOverflow: true,
|
|
114
|
+
summary: `reviewCommand output exceeded maxBuffer (${maxBuffer} bytes); use a scoped reviewCommand instead. Command: ${trimmed}`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const exitCode = Number(result.exitCode ?? 1);
|
|
119
|
+
if (exitCode === 0) {
|
|
120
|
+
return { ok: true, exitCode: 0, output };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const detail = [
|
|
124
|
+
String(result.stdout ?? "").trim(),
|
|
125
|
+
String(result.stderr ?? "").trim(),
|
|
126
|
+
]
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.join("\n")
|
|
129
|
+
.slice(0, 500);
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
exitCode,
|
|
133
|
+
output,
|
|
134
|
+
summary: `reviewCommand failed (exit ${exitCode})${detail ? `: ${detail}` : ""}`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Resolve review step options from spine config (SP-845): the review timeout
|
|
140
|
+
* defaults to 20 minutes and is independent of `contract.testTimeoutMs`; the
|
|
141
|
+
* policy defaults to blocking.
|
|
142
|
+
*
|
|
143
|
+
* @param {{ contract?: { reviewTimeoutMs?: number, reviewPolicy?: string } }} [config]
|
|
144
|
+
* @returns {{ timeoutMs: number, policy: "blocking" | "advisory" }}
|
|
145
|
+
*/
|
|
146
|
+
export function resolveContractReviewOptions(config = {}) {
|
|
147
|
+
return {
|
|
148
|
+
timeoutMs: config?.contract?.reviewTimeoutMs ?? CONTRACT_REVIEW_TIMEOUT_DEFAULT_MS,
|
|
149
|
+
policy:
|
|
150
|
+
config?.contract?.reviewPolicy === "advisory"
|
|
151
|
+
? "advisory"
|
|
152
|
+
: CONTRACT_REVIEW_POLICY_DEFAULT,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Run the contract review step and build the `reviewCommand` check.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} worktreePath
|
|
160
|
+
* @param {{ reviewCommand?: string | null }} parsedContract
|
|
161
|
+
* @param {{ contract?: { reviewTimeoutMs?: number, reviewPolicy?: string, testRetries?: number, testTimeoutMs?: number }, contractTestMaxBuffer?: number, projectRoot?: string, batchId?: string, taskId?: string, taskFolder?: string }} [config]
|
|
162
|
+
* verifyContract config — reads `contract.reviewTimeoutMs`,
|
|
163
|
+
* `contract.reviewPolicy`, `contractTestMaxBuffer`, plus projectRoot/batchId/
|
|
164
|
+
* taskId/taskFolder for advisory journaling.
|
|
165
|
+
* @returns {Promise<{ field: "reviewCommand", ok: boolean, message: string } | null>}
|
|
166
|
+
* null when the contract has no reviewCommand.
|
|
167
|
+
*/
|
|
168
|
+
export async function runContractReviewStep(worktreePath, parsedContract, config = {}) {
|
|
169
|
+
const command = parsedContract?.reviewCommand;
|
|
170
|
+
if (!command) return null;
|
|
171
|
+
|
|
172
|
+
const { timeoutMs, policy } = resolveContractReviewOptions(config);
|
|
173
|
+
const result = await runContractReviewCommand(worktreePath, command, {
|
|
174
|
+
timeoutMs,
|
|
175
|
+
maxBuffer: config?.contractTestMaxBuffer,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
if (result.ok) {
|
|
179
|
+
return { field: "reviewCommand", ok: true, message: "reviewCommand passed" };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const detail = result.summary ?? `reviewCommand failed (exit ${result.exitCode})`;
|
|
183
|
+
if (policy === "advisory") {
|
|
184
|
+
recordReviewAdvisory(config, {
|
|
185
|
+
exitCode: result.exitCode,
|
|
186
|
+
timedOut: result.timedOut === true,
|
|
187
|
+
summary: detail,
|
|
188
|
+
});
|
|
189
|
+
return {
|
|
190
|
+
field: "reviewCommand",
|
|
191
|
+
ok: true,
|
|
192
|
+
message: `Contract reviewCommand failed (advisory, not blocking): ${detail}`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return { field: "reviewCommand", ok: false, message: `Contract reviewCommand failed: ${detail}` };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Advisory review failures never block, but they must stay visible: journal a
|
|
201
|
+
* `contract.review_advisory` event and append a row to the task STATUS.md
|
|
202
|
+
* Discoveries table.
|
|
203
|
+
*
|
|
204
|
+
* @param {{ contract?: { reviewTimeoutMs?: number, reviewPolicy?: string }, contractTestMaxBuffer?: number, projectRoot?: string, batchId?: string, taskId?: string, taskFolder?: string }} config
|
|
205
|
+
* @param {{ exitCode: number, timedOut: boolean, summary: string }} payload
|
|
206
|
+
*/
|
|
207
|
+
function recordReviewAdvisory(config, payload) {
|
|
208
|
+
if (config?.projectRoot && config?.batchId) {
|
|
209
|
+
appendJournalEvent(config.projectRoot, config.batchId, "contract.review_advisory", {
|
|
210
|
+
taskId: config?.taskId,
|
|
211
|
+
exitCode: payload.exitCode,
|
|
212
|
+
timedOut: payload.timedOut,
|
|
213
|
+
summary: String(payload.summary ?? "").slice(0, 200),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
appendReviewAdvisoryDiscovery(config?.taskFolder, payload.summary);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Append one row to the task STATUS.md Discoveries table (SP-845 advisory).
|
|
221
|
+
* Best-effort: skips silently when the task folder or Discoveries table is
|
|
222
|
+
* missing; never throws into contract verification.
|
|
223
|
+
*
|
|
224
|
+
* @param {string | undefined} taskFolder
|
|
225
|
+
* @param {string | undefined} summary
|
|
226
|
+
* @returns {boolean} true when a row was appended
|
|
227
|
+
*/
|
|
228
|
+
export function appendReviewAdvisoryDiscovery(taskFolder, summary) {
|
|
229
|
+
if (!taskFolder) return false;
|
|
230
|
+
const statusPath = path.join(taskFolder, "STATUS.md");
|
|
231
|
+
let content;
|
|
232
|
+
try {
|
|
233
|
+
content = fs.readFileSync(statusPath, "utf-8");
|
|
234
|
+
} catch {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
const lines = content.split("\n");
|
|
238
|
+
const headingIndex = lines.findIndex((line) => line.trim() === "## Discoveries");
|
|
239
|
+
if (headingIndex === -1) return false;
|
|
240
|
+
|
|
241
|
+
const cell = String(summary ?? "reviewCommand failed (advisory)")
|
|
242
|
+
.replace(/\|/g, "\\|")
|
|
243
|
+
.replace(/\r?\n/g, " ")
|
|
244
|
+
.slice(0, 160);
|
|
245
|
+
const row = `| ${cell} | advisory — noted, not blocking | contract review step |`;
|
|
246
|
+
|
|
247
|
+
// Insert after the Discoveries table's header separator so newest-first
|
|
248
|
+
// ordering matches the template; fall back to directly under the heading.
|
|
249
|
+
let insertAt = headingIndex + 1;
|
|
250
|
+
for (let index = headingIndex + 1; index < lines.length; index += 1) {
|
|
251
|
+
const line = lines[index];
|
|
252
|
+
if (line.startsWith("## ")) break;
|
|
253
|
+
if (/^\|[\s|-]+$/.test(line)) {
|
|
254
|
+
insertAt = index + 1;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
lines.splice(insertAt, 0, row);
|
|
260
|
+
try {
|
|
261
|
+
fs.writeFileSync(statusPath, lines.join("\n"), "utf-8");
|
|
262
|
+
} catch {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
@@ -32,6 +32,37 @@ const DEFAULT_MAX_BUFFER = 10 * 1024 * 1024;
|
|
|
32
32
|
/** Exit code reported when the shell itself cannot be spawned (ENOENT convention). */
|
|
33
33
|
const SPAWN_ERROR_EXIT_CODE = 127;
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Worker-only env keys stripped from contract command subprocesses so full-suite
|
|
37
|
+
* tests match operator re-run outside worker-host (SP-491, issue #155).
|
|
38
|
+
*/
|
|
39
|
+
export const CONTRACT_TEST_WORKER_ENV_KEYS = ["SPINE_IS_WORKER"];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Build env for contract testCommand/reviewCommand subprocess — omits worker-only
|
|
43
|
+
* keys inherited from worker-host.mjs that would false-fail batch-spawn integration
|
|
44
|
+
* tests (SP-482 guard). Preserves parent batch id as SPINE_PARENT_BATCH_ID so the
|
|
45
|
+
* nested-spawn guard can block live engines in lane worktrees while still allowing
|
|
46
|
+
* isolated fixture tests (#162).
|
|
47
|
+
*
|
|
48
|
+
* Lives here (not in contract-exec.mjs) so the test and review runners (SP-845)
|
|
49
|
+
* share one implementation without an import cycle.
|
|
50
|
+
*
|
|
51
|
+
* @param {NodeJS.ProcessEnv} [sourceEnv]
|
|
52
|
+
* @returns {NodeJS.ProcessEnv}
|
|
53
|
+
*/
|
|
54
|
+
export function buildContractTestEnv(sourceEnv = process.env) {
|
|
55
|
+
const env = { ...sourceEnv };
|
|
56
|
+
for (const key of CONTRACT_TEST_WORKER_ENV_KEYS) {
|
|
57
|
+
delete env[key];
|
|
58
|
+
}
|
|
59
|
+
if (env.SPINE_BATCH_ID && !env.SPINE_PARENT_BATCH_ID) {
|
|
60
|
+
env.SPINE_PARENT_BATCH_ID = env.SPINE_BATCH_ID;
|
|
61
|
+
}
|
|
62
|
+
delete env.SPINE_BATCH_ID;
|
|
63
|
+
return env;
|
|
64
|
+
}
|
|
65
|
+
|
|
35
66
|
/**
|
|
36
67
|
* Resolve the contract shell exactly like runContractTestCommand: $SHELL, else
|
|
37
68
|
* cmd.exe on Windows and /bin/sh elsewhere, with the matching command flag.
|
|
@@ -14,6 +14,46 @@ export const PRIMARY_TASK_FAILURE_EXIT_REASONS = new Set([
|
|
|
14
14
|
|
|
15
15
|
const LANE_COMMIT_EXIT_REASONS = new Set(["DirtyWorktree", "lane_commit_failed"]);
|
|
16
16
|
|
|
17
|
+
/** Suggested `contract.testTimeoutMs` after a timeout: double the 10-minute default. */
|
|
18
|
+
const CONTRACT_TIMEOUT_SUGGESTED_MS = 20 * 60 * 1000;
|
|
19
|
+
|
|
20
|
+
/** Suggested `contract.reviewTimeoutMs` after a review timeout: double the 20-minute default (SP-845). */
|
|
21
|
+
const CONTRACT_REVIEW_TIMEOUT_SUGGESTED_MS = 40 * 60 * 1000;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* True when the latest contract verification for `taskId` failed because its
|
|
25
|
+
* testCommand timed out (#369), so diagnosis can name the timeout instead of
|
|
26
|
+
* pointing at PROMPT.md scope.
|
|
27
|
+
*
|
|
28
|
+
* SP-845: a `reviewCommand` timeout is distinguished from a test timeout —
|
|
29
|
+
* returns `"review"` for review timeouts (truthy, so `contractTimedOut`
|
|
30
|
+
* consumers keep working while builders can name `contract.reviewTimeoutMs`).
|
|
31
|
+
*
|
|
32
|
+
* @param {Array<{ type?: string, payload?: Record<string, any> }>} journalEvents
|
|
33
|
+
* @param {string|null|undefined} taskId
|
|
34
|
+
* @returns {boolean | "review"}
|
|
35
|
+
*/
|
|
36
|
+
export function isContractTimeoutFailure(journalEvents, taskId) {
|
|
37
|
+
if (!taskId || !Array.isArray(journalEvents)) return false;
|
|
38
|
+
for (let index = journalEvents.length - 1; index >= 0; index -= 1) {
|
|
39
|
+
const event = journalEvents[index];
|
|
40
|
+
if (event?.type !== "contract.verified" && event?.type !== "contract.failed") continue;
|
|
41
|
+
if (event.payload?.taskId !== taskId) continue;
|
|
42
|
+
const checks = Array.isArray(event.payload?.checks) ? event.payload.checks : [];
|
|
43
|
+
if (
|
|
44
|
+
checks.some(
|
|
45
|
+
(check) => check?.field === "reviewCommand" && check.ok === false && /timed out after/.test(String(check.message ?? "")),
|
|
46
|
+
)
|
|
47
|
+
) {
|
|
48
|
+
return "review";
|
|
49
|
+
}
|
|
50
|
+
return checks.some(
|
|
51
|
+
(check) => check?.field === "testCommand" && check.ok === false && /timed out after/.test(String(check.message ?? "")),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
17
57
|
/**
|
|
18
58
|
* @param {string|null|undefined} exitReason
|
|
19
59
|
*/
|
|
@@ -27,6 +67,7 @@ export function isPrimaryTaskFailureExitReason(exitReason) {
|
|
|
27
67
|
* @param {string|null} [ctx.exitReason]
|
|
28
68
|
* @param {string|null} [ctx.failedTaskId]
|
|
29
69
|
* @param {boolean} [ctx.mergeGitignoredFailure]
|
|
70
|
+
* @param {boolean | "review"} [ctx.contractTimedOut] SP-845: "review" marks a reviewCommand timeout.
|
|
30
71
|
*/
|
|
31
72
|
export function buildPrimaryFailureHeadline(batchLabel, ctx = {}) {
|
|
32
73
|
if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
|
|
@@ -49,6 +90,13 @@ export function buildPrimaryFailureHeadline(batchLabel, ctx = {}) {
|
|
|
49
90
|
? `${batchLabel} task ${ctx.failedTaskId} exhausted final review attempts — fix scope or implementation, then retry`
|
|
50
91
|
: `${batchLabel} review attempts exhausted — fix scope or implementation, then retry`;
|
|
51
92
|
}
|
|
93
|
+
if (ctx.exitReason === "contract_failed" && ctx.contractTimedOut) {
|
|
94
|
+
const isReviewTimeout = ctx.contractTimedOut === "review";
|
|
95
|
+
const field = isReviewTimeout ? "reviewCommand" : "testCommand";
|
|
96
|
+
const key = isReviewTimeout ? "contract.reviewTimeoutMs" : "contract.testTimeoutMs";
|
|
97
|
+
const subject = ctx.failedTaskId ? `task ${ctx.failedTaskId} contract ${field}` : `contract ${field}`;
|
|
98
|
+
return `${batchLabel} ${subject} timed out — raise ${key} or speed up the command, then retry`;
|
|
99
|
+
}
|
|
52
100
|
if (ctx.exitReason === "contract_failed") {
|
|
53
101
|
return ctx.failedTaskId
|
|
54
102
|
? `${batchLabel} task ${ctx.failedTaskId} failed contract verification — fix PROMPT.md scope, then retry`
|
|
@@ -95,6 +143,7 @@ export function buildDirtyWorktreeSuggestedCommand(ctx = {}) {
|
|
|
95
143
|
* @param {string|null} [ctx.exitReason]
|
|
96
144
|
* @param {string|null} [ctx.failedTaskId]
|
|
97
145
|
* @param {string} [ctx.tasksRoot]
|
|
146
|
+
* @param {boolean | "review"} [ctx.contractTimedOut] SP-845: "review" marks a reviewCommand timeout.
|
|
98
147
|
*/
|
|
99
148
|
export function buildPrimaryFailureSuggestedCommand(ctx = {}) {
|
|
100
149
|
if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
|
|
@@ -110,6 +159,15 @@ export function buildPrimaryFailureSuggestedCommand(ctx = {}) {
|
|
|
110
159
|
? `spine batch retry ${ctx.failedTaskId}`
|
|
111
160
|
: "spine status --diagnose";
|
|
112
161
|
}
|
|
162
|
+
if (ctx.exitReason === "contract_failed" && ctx.contractTimedOut) {
|
|
163
|
+
const retry = ctx.failedTaskId ? `spine batch retry ${ctx.failedTaskId}` : "spine batch resume";
|
|
164
|
+
const suggested =
|
|
165
|
+
ctx.contractTimedOut === "review"
|
|
166
|
+
? CONTRACT_REVIEW_TIMEOUT_SUGGESTED_MS
|
|
167
|
+
: CONTRACT_TIMEOUT_SUGGESTED_MS;
|
|
168
|
+
const key = ctx.contractTimedOut === "review" ? "contract.reviewTimeoutMs" : "contract.testTimeoutMs";
|
|
169
|
+
return `spine settings set ${key} ${suggested} && ${retry}`;
|
|
170
|
+
}
|
|
113
171
|
if (ctx.exitReason === "contract_failed") {
|
|
114
172
|
const tasksRoot = ctx.tasksRoot ?? "spine-tasks";
|
|
115
173
|
return ctx.failedTaskId
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
sanitizeGitignoredArtifactsBeforeLaneCommit,
|
|
10
10
|
sanitizeOutOfScopeCoverageBeforeLaneCommit,
|
|
11
11
|
} from "../lane-dirty-check.mjs";
|
|
12
|
+
import { resolveLaneCommitKeepPaths } from "../../config/spine-config-schema.mjs";
|
|
12
13
|
import {
|
|
13
14
|
recomputeTaskCounters,
|
|
14
15
|
saveSpineBatchState,
|
|
@@ -54,10 +55,12 @@ export function commitLaneAndValidateWorktree({
|
|
|
54
55
|
config,
|
|
55
56
|
}) {
|
|
56
57
|
const preCommitPorcelain = gitPorcelain(worktreePath);
|
|
58
|
+
const keepPaths = resolveLaneCommitKeepPaths({ config });
|
|
57
59
|
sanitizeGitignoredArtifactsBeforeLaneCommit(worktreePath, {
|
|
58
60
|
projectRoot,
|
|
59
61
|
porcelain: preCommitPorcelain,
|
|
60
62
|
enabled: config?.lanes?.autoCleanGitignoredArtifacts !== false,
|
|
63
|
+
keepPaths,
|
|
61
64
|
});
|
|
62
65
|
sanitizeOutOfScopeCoverageBeforeLaneCommit(worktreePath, fileScopePaths, {
|
|
63
66
|
projectRoot,
|
|
@@ -79,6 +82,7 @@ export function commitLaneAndValidateWorktree({
|
|
|
79
82
|
ignorePatterns,
|
|
80
83
|
fileScopePaths,
|
|
81
84
|
canceledMatrixRowIds,
|
|
85
|
+
keepPaths,
|
|
82
86
|
});
|
|
83
87
|
if (!laneCommit.ok) {
|
|
84
88
|
task.status = "failed";
|
|
@@ -322,6 +322,8 @@ export async function runMatrixSubLane({
|
|
|
322
322
|
const verify = await verifyContract(worktreePath, contract, {
|
|
323
323
|
matrixRow: values,
|
|
324
324
|
baseBranch,
|
|
325
|
+
contract: config?.contract,
|
|
326
|
+
contractTestMaxBuffer: config?.contractTestMaxBuffer,
|
|
325
327
|
});
|
|
326
328
|
if (verify.ok) {
|
|
327
329
|
result = {
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import { execFileSync } from "node:child_process";
|
|
9
8
|
import { validateWorkerLaunchScriptPath } from "../config/worker-launch-script.mjs";
|
|
10
9
|
import { EvidenceCommandError } from "./evidence-command-error.mjs";
|
|
10
|
+
import { EVIDENCE_DEFAULT_MAX_BYTES, runEvidenceArgvToFile } from "./evidence-exec.mjs";
|
|
11
11
|
import {
|
|
12
12
|
expandEvidencePathEntries,
|
|
13
13
|
isAllowedEvidencePathEntry,
|
|
@@ -376,8 +376,8 @@ function collectEvidencePathPrefixEntries(command) {
|
|
|
376
376
|
* @param {string} command
|
|
377
377
|
* @param {number} [maxBytes]
|
|
378
378
|
*/
|
|
379
|
-
export function runEvidenceCommand(projectRoot, command, maxBytes =
|
|
380
|
-
if (!command) return { ok: false, skipped: true, output: "" };
|
|
379
|
+
export function runEvidenceCommand(projectRoot, command, maxBytes = EVIDENCE_DEFAULT_MAX_BYTES) {
|
|
380
|
+
if (!command) return { ok: false, skipped: true, output: "", truncated: false };
|
|
381
381
|
|
|
382
382
|
try {
|
|
383
383
|
const chain = parseEvidenceCommandChain(command);
|
|
@@ -393,35 +393,32 @@ export function runEvidenceCommand(projectRoot, command, maxBytes = 256 * 1024)
|
|
|
393
393
|
}
|
|
394
394
|
/** @type {string[]} */
|
|
395
395
|
const outputs = [];
|
|
396
|
+
let truncated = false;
|
|
396
397
|
for (const argv of chain) {
|
|
397
398
|
const execArgv = resolveEvidenceScriptsArgv(projectRoot, argv);
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
399
|
+
const step = runEvidenceArgvToFile({ projectRoot, argv: execArgv, env, maxBytes });
|
|
400
|
+
outputs.push(step.output);
|
|
401
|
+
truncated = truncated || step.truncated;
|
|
402
|
+
if (!step.ok) {
|
|
403
|
+
return {
|
|
404
|
+
ok: false,
|
|
405
|
+
skipped: false,
|
|
406
|
+
output: `${outputs.join("")}\n[exit] ${step.exitDetail}`.trim(),
|
|
407
|
+
truncated,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
407
410
|
}
|
|
408
|
-
return { ok: true, skipped: false, output: outputs.join("") };
|
|
411
|
+
return { ok: true, skipped: false, output: outputs.join(""), truncated };
|
|
409
412
|
} catch (err) {
|
|
410
413
|
if (err instanceof EvidenceCommandError) {
|
|
411
414
|
return {
|
|
412
415
|
ok: false,
|
|
413
416
|
skipped: false,
|
|
414
417
|
output: `[rejected] ${err.message}`,
|
|
418
|
+
truncated: false,
|
|
415
419
|
};
|
|
416
420
|
}
|
|
417
|
-
|
|
418
|
-
const stdout = err && typeof err === "object" && "stdout" in err ? String(err.stdout ?? "") : "";
|
|
419
|
-
const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr ?? "") : "";
|
|
420
421
|
const message = err instanceof Error ? err.message : String(err);
|
|
421
|
-
return {
|
|
422
|
-
ok: false,
|
|
423
|
-
skipped: false,
|
|
424
|
-
output: `${stdout}${stderr}\n[exit] ${message}`.trim(),
|
|
425
|
-
};
|
|
422
|
+
return { ok: false, skipped: false, output: `[exit] ${message}`, truncated: false };
|
|
426
423
|
}
|
|
427
424
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run one validated evidence argv with stdout+stderr streamed to a temp file.
|
|
3
|
+
* Pipe buffers (execFileSync maxBuffer) kill the child with ENOBUFS on large
|
|
4
|
+
* test logs and lose the exit status; a file sink keeps the true exit status
|
|
5
|
+
* and lets us retain only the tail, which is where test failures summarize.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
|
|
13
|
+
export const EVIDENCE_TIMEOUT_MS = 10 * 60 * 1000;
|
|
14
|
+
export const EVIDENCE_DEFAULT_MAX_BYTES = 256 * 1024;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} filePath
|
|
18
|
+
* @param {number} maxBytes
|
|
19
|
+
* @returns {{ text: string, totalBytes: number, truncated: boolean }}
|
|
20
|
+
*/
|
|
21
|
+
function readFileTail(filePath, maxBytes) {
|
|
22
|
+
const totalBytes = fs.statSync(filePath).size;
|
|
23
|
+
if (totalBytes <= maxBytes) {
|
|
24
|
+
return { text: fs.readFileSync(filePath, "utf-8"), totalBytes, truncated: false };
|
|
25
|
+
}
|
|
26
|
+
const fd = fs.openSync(filePath, "r");
|
|
27
|
+
try {
|
|
28
|
+
const buffer = Buffer.alloc(maxBytes);
|
|
29
|
+
fs.readSync(fd, buffer, 0, maxBytes, totalBytes - maxBytes);
|
|
30
|
+
return { text: buffer.toString("utf-8"), totalBytes, truncated: true };
|
|
31
|
+
} finally {
|
|
32
|
+
fs.closeSync(fd);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {object} opts
|
|
38
|
+
* @param {string} opts.projectRoot
|
|
39
|
+
* @param {string[]} opts.argv
|
|
40
|
+
* @param {NodeJS.ProcessEnv | undefined} opts.env
|
|
41
|
+
* @param {number} opts.maxBytes Tail bytes retained from combined output.
|
|
42
|
+
* @param {number} [opts.timeoutMs]
|
|
43
|
+
* @returns {{ ok: boolean, output: string, truncated: boolean, exitDetail: string|null }}
|
|
44
|
+
*/
|
|
45
|
+
export function runEvidenceArgvToFile({ projectRoot, argv, env, maxBytes, timeoutMs = EVIDENCE_TIMEOUT_MS }) {
|
|
46
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "spine-evidence-"));
|
|
47
|
+
const outPath = path.join(dir, "output.log");
|
|
48
|
+
const fd = fs.openSync(outPath, "w");
|
|
49
|
+
let fdOpen = true;
|
|
50
|
+
try {
|
|
51
|
+
const result = spawnSync(argv[0], argv.slice(1), {
|
|
52
|
+
cwd: projectRoot,
|
|
53
|
+
stdio: ["ignore", fd, fd],
|
|
54
|
+
timeout: timeoutMs,
|
|
55
|
+
...(env ? { env } : {}),
|
|
56
|
+
});
|
|
57
|
+
fs.closeSync(fd);
|
|
58
|
+
fdOpen = false;
|
|
59
|
+
const tail = readFileTail(outPath, maxBytes);
|
|
60
|
+
const marker = tail.truncated
|
|
61
|
+
? `[evidence truncated: kept last ${maxBytes} of ${tail.totalBytes} bytes]\n`
|
|
62
|
+
: "";
|
|
63
|
+
const output = `${marker}${tail.text}`;
|
|
64
|
+
if (result.error) {
|
|
65
|
+
return { ok: false, output, truncated: tail.truncated, exitDetail: result.error.message };
|
|
66
|
+
}
|
|
67
|
+
if (result.status === 0) {
|
|
68
|
+
return { ok: true, output, truncated: tail.truncated, exitDetail: null };
|
|
69
|
+
}
|
|
70
|
+
const exitDetail =
|
|
71
|
+
result.signal !== null
|
|
72
|
+
? `Command terminated by ${result.signal}: ${argv.join(" ")}`
|
|
73
|
+
: `Command failed with exit code ${result.status}: ${argv.join(" ")}`;
|
|
74
|
+
return { ok: false, output, truncated: tail.truncated, exitDetail };
|
|
75
|
+
} finally {
|
|
76
|
+
if (fdOpen) fs.closeSync(fd);
|
|
77
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lane-commit keep paths (SP-844 / #349): gitignored artifact roots that hold
|
|
3
|
+
* active tool state — stet sessions, baseline refs — which the lane-commit
|
|
4
|
+
* sanitizer must preserve across lane commits serialized on one worktree.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Normalize a keep path for root comparison: backslashes → slashes, no
|
|
9
|
+
* leading "./", no trailing slash.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} keepPath
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeKeepPath(keepPath) {
|
|
15
|
+
let normalized = String(keepPath).trim().replace(/\\/g, "/");
|
|
16
|
+
while (normalized.startsWith("./")) normalized = normalized.slice(2);
|
|
17
|
+
while (normalized.endsWith("/")) {
|
|
18
|
+
normalized = normalized.slice(0, -1);
|
|
19
|
+
}
|
|
20
|
+
return normalized;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Whether a cleaned artifact root is covered by a keep path. `.review/` keeps
|
|
25
|
+
* the artifact root `.review` and every root under it.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} artifactRoot
|
|
28
|
+
* @param {string[]} keepPaths
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
export function isKeptArtifactRoot(artifactRoot, keepPaths) {
|
|
32
|
+
if (!artifactRoot || !Array.isArray(keepPaths) || keepPaths.length === 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const root = normalizeKeepPath(artifactRoot);
|
|
36
|
+
if (root === "") return false;
|
|
37
|
+
return keepPaths.some((keepPath) => {
|
|
38
|
+
const kept = normalizeKeepPath(keepPath);
|
|
39
|
+
return kept !== "" && (root === kept || root.startsWith(`${kept}/`));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Split artifact roots into roots the sanitizer may clean and roots that must
|
|
45
|
+
* survive the lane commit.
|
|
46
|
+
*
|
|
47
|
+
* @param {string[]} artifactRoots
|
|
48
|
+
* @param {string[]} [keepPaths]
|
|
49
|
+
* @returns {{ cleanableRoots: string[], keptRoots: string[] }}
|
|
50
|
+
*/
|
|
51
|
+
export function partitionArtifactRootsByKeepPaths(artifactRoots, keepPaths = []) {
|
|
52
|
+
const cleanableRoots = [];
|
|
53
|
+
const keptRoots = [];
|
|
54
|
+
for (const root of Array.isArray(artifactRoots) ? artifactRoots : []) {
|
|
55
|
+
if (isKeptArtifactRoot(root, keepPaths)) {
|
|
56
|
+
keptRoots.push(root);
|
|
57
|
+
} else {
|
|
58
|
+
cleanableRoots.push(root);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { cleanableRoots, keptRoots };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Whether a gitignored path sits under a kept root — kept paths are
|
|
66
|
+
* operator-blessed tool state, not cleanable artifacts, so the lane-commit
|
|
67
|
+
* dirty gate must not count them (SP-844 / #349).
|
|
68
|
+
*
|
|
69
|
+
* @param {string} filePath
|
|
70
|
+
* @param {string[]} keepPaths
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
export function isPathUnderKeptRoot(filePath, keepPaths) {
|
|
74
|
+
return isKeptArtifactRoot(filePath, keepPaths);
|
|
75
|
+
}
|