pi-spine 2.2.0 → 2.3.1
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/verify.mjs +15 -46
- package/package.json +1 -1
- package/src/batch/attached-runner-promote.mjs +370 -0
- package/src/batch/attached-runner-reconcile.mjs +291 -0
- package/src/batch/attached-runner.mjs +24 -645
- package/src/batch/batch-guards.mjs +69 -0
- package/src/batch/contract-exec.mjs +483 -0
- package/src/batch/contract-parse.mjs +243 -0
- package/src/batch/contract-verify.mjs +32 -707
- package/src/batch/detached-diagnostics.mjs +255 -0
- package/src/batch/detached-run.mjs +326 -0
- package/src/batch/detached-start.mjs +18 -894
- package/src/batch/detached-wait.mjs +346 -0
- package/src/batch/diagnosis.mjs +35 -4
- package/src/batch/engine-lanes/orch-sync.mjs +126 -0
- package/src/batch/engine-lanes.mjs +69 -0
- package/src/batch/engine.mjs +8 -67
- package/src/batch/integrate-git.mjs +21 -0
- package/src/batch/integrate.mjs +5 -15
- package/src/batch/journal-rebuild-structural.mjs +352 -0
- package/src/batch/journal-rebuild.mjs +16 -348
- package/src/batch/lane-dirty-check-commit.mjs +361 -0
- package/src/batch/lane-dirty-check-git.mjs +298 -0
- package/src/batch/lane-dirty-check.mjs +31 -297
- package/src/batch/reconcile-batch.mjs +495 -0
- package/src/batch/reconcile-classify.mjs +433 -0
- package/src/batch/reconcile-diagnosis.mjs +459 -0
- package/src/batch/reconcile-light-cache.mjs +61 -0
- package/src/batch/reconcile-orphan.mjs +198 -0
- package/src/batch/reconcile.mjs +19 -1693
- package/src/batch/resume-multi-lanes.mjs +6 -148
- package/src/batch/resume-multi-queue.mjs +159 -0
- package/src/batch/resume-single-validate.mjs +25 -0
- package/src/batch/resume.mjs +3 -20
- package/src/batch/review-artifacts.mjs +419 -0
- package/src/batch/review-step-run.mjs +383 -0
- package/src/batch/review-step.mjs +451 -0
- package/src/batch/review.mjs +32 -1199
- package/src/batch/salvage-batch-list.mjs +291 -0
- package/src/batch/salvage-batch.mjs +10 -284
- package/src/batch/sequence-plan.mjs +234 -0
- package/src/batch/sequence-run.mjs +418 -0
- package/src/batch/sequence-wait.mjs +167 -0
- package/src/batch/sequence.mjs +22 -783
- package/src/batch/state-guards.mjs +284 -0
- package/src/batch/state-io.mjs +135 -0
- package/src/batch/state.mjs +27 -396
- package/src/batch/worker-heartbeat.mjs +382 -0
- package/src/batch/worker-host.mjs +56 -548
- package/src/batch/worker-spawn.mjs +326 -0
- package/src/batch/worktree.mjs +68 -0
- package/src/config/preflight/integrate-plan.mjs +6 -1
- package/src/config/preflight/loc-capstone.mjs +274 -0
- package/src/config/spine-preflight-lib.mjs +14 -0
- package/src/planner/index.mjs +14 -3
- package/src/process/terminate-tree.mjs +154 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Contract field parsing, changed-file listing, and file-scope matchers (SP-585).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import micromatch from "micromatch";
|
|
9
|
+
import { resolveContractMode } from "../tasks/packet/validate-contract.mjs";
|
|
10
|
+
import {
|
|
11
|
+
isBaseScopeSatisfied,
|
|
12
|
+
isStubPrelandedFileScopeSatisfied,
|
|
13
|
+
} from "./contract-prelanded.mjs";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} taskId
|
|
17
|
+
* @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
|
|
18
|
+
* @param {object} [config]
|
|
19
|
+
*/
|
|
20
|
+
export function shouldRunContractVerify(taskId, parsedContract, config = {}) {
|
|
21
|
+
const mode = resolveContractMode({
|
|
22
|
+
mode: config.contract?.mode,
|
|
23
|
+
taskId,
|
|
24
|
+
legacyTaskIdPrefixes: config.contract?.legacyTaskIdPrefixes,
|
|
25
|
+
});
|
|
26
|
+
if (mode === "legacy") return false;
|
|
27
|
+
if (!parsedContract?.hasSection) return false;
|
|
28
|
+
|
|
29
|
+
return Boolean(
|
|
30
|
+
parsedContract.testCommand ||
|
|
31
|
+
(parsedContract.fileScopeMustChange?.length ?? 0) > 0 ||
|
|
32
|
+
(parsedContract.fileScopeMustNotChange?.length ?? 0) > 0 ||
|
|
33
|
+
parsedContract.minLineCoverage != null ||
|
|
34
|
+
(parsedContract.artifactsMustExist?.length ?? 0) > 0,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Exit-verification tasks (§8 phase exit) must not stub-complete without contract pass.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} promptMarkdown
|
|
42
|
+
*/
|
|
43
|
+
export function isExitVerificationTask(promptMarkdown) {
|
|
44
|
+
const text = String(promptMarkdown ?? "");
|
|
45
|
+
if (/^#\s*Task:.*exit verification/im.test(text)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (/^##\s*Exit verification/im.test(text)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (/Phase\s+\d+\s+exit verification/i.test(text)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} promptMarkdown
|
|
59
|
+
* @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
|
|
60
|
+
* @param {object} [config]
|
|
61
|
+
*/
|
|
62
|
+
export function shouldRunContractVerifyForWorker(promptMarkdown, parsedContract, config = {}) {
|
|
63
|
+
if (!shouldRunContractVerify(null, parsedContract, config)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const stubMode =
|
|
67
|
+
process.env.SPINE_WORKER_STUB === "1" || process.env.SPINE_WORKER_STUB === "true";
|
|
68
|
+
if (!stubMode) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return isExitVerificationTask(promptMarkdown);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
export function isStubWorkerMode() {
|
|
78
|
+
return process.env.SPINE_WORKER_STUB === "1" || process.env.SPINE_WORKER_STUB === "true";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Legacy stub workers write "Task: stub" in `.DONE` body.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} doneContent
|
|
85
|
+
*/
|
|
86
|
+
export function isLegacyStubDoneMarker(doneContent) {
|
|
87
|
+
return /Task:\s*stub/i.test(String(doneContent ?? ""));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {string} donePath
|
|
92
|
+
*/
|
|
93
|
+
export function isLegacyStubDoneFile(donePath) {
|
|
94
|
+
if (!fs.existsSync(donePath)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return isLegacyStubDoneMarker(fs.readFileSync(donePath, "utf-8"));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Lane commit enforces `fileScopeMustChange` when stub mode is active or `.DONE` is legacy stub.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} donePath
|
|
104
|
+
*/
|
|
105
|
+
export function shouldEnforceStubContractAtLaneCommit(donePath) {
|
|
106
|
+
if (isStubWorkerMode()) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return isLegacyStubDoneFile(donePath);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
|
|
114
|
+
*/
|
|
115
|
+
export function hasReleaseCriticalContract(parsedContract) {
|
|
116
|
+
return (parsedContract?.fileScopeMustChange?.length ?? 0) > 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {string} worktreePath
|
|
121
|
+
*/
|
|
122
|
+
function listUntrackedFiles(worktreePath) {
|
|
123
|
+
try {
|
|
124
|
+
const output = execFileSync("git", ["ls-files", "-o", "--exclude-standard"], {
|
|
125
|
+
cwd: worktreePath,
|
|
126
|
+
encoding: "utf-8",
|
|
127
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
128
|
+
timeout: 30_000,
|
|
129
|
+
});
|
|
130
|
+
return output
|
|
131
|
+
.split(/\r?\n/)
|
|
132
|
+
.map((line) => line.trim())
|
|
133
|
+
.filter(Boolean);
|
|
134
|
+
} catch {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {string} worktreePath
|
|
141
|
+
* @param {string} baseBranch
|
|
142
|
+
* @param {string[]} [pendingPaths]
|
|
143
|
+
*/
|
|
144
|
+
export function listEffectiveChangedFiles(worktreePath, baseBranch = "main", pendingPaths = []) {
|
|
145
|
+
return [
|
|
146
|
+
...new Set([
|
|
147
|
+
...listChangedFiles(worktreePath, baseBranch),
|
|
148
|
+
...pendingPaths,
|
|
149
|
+
...listUntrackedFiles(worktreePath),
|
|
150
|
+
]),
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {string} worktreePath
|
|
156
|
+
* @param {string} [baseBranch]
|
|
157
|
+
* @param {string} [sinceCommit] When set, diff `sinceCommit..HEAD` instead of `baseBranch...HEAD`.
|
|
158
|
+
*/
|
|
159
|
+
export function listChangedFiles(worktreePath, baseBranch = "main", sinceCommit = undefined) {
|
|
160
|
+
const scopedSince = String(sinceCommit ?? "").trim();
|
|
161
|
+
const diffRange =
|
|
162
|
+
scopedSince.length > 0 ? `${scopedSince}..HEAD` : `${baseBranch}...HEAD`;
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
const output = execFileSync("git", ["diff", "--name-only", diffRange], {
|
|
166
|
+
cwd: worktreePath,
|
|
167
|
+
encoding: "utf-8",
|
|
168
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
169
|
+
timeout: 30_000,
|
|
170
|
+
});
|
|
171
|
+
return output
|
|
172
|
+
.split(/\r?\n/)
|
|
173
|
+
.map((line) => line.trim())
|
|
174
|
+
.filter(Boolean);
|
|
175
|
+
} catch {
|
|
176
|
+
if (scopedSince.length > 0) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
const output = execFileSync("git", ["diff", "--name-only", "HEAD"], {
|
|
181
|
+
cwd: worktreePath,
|
|
182
|
+
encoding: "utf-8",
|
|
183
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
184
|
+
timeout: 30_000,
|
|
185
|
+
});
|
|
186
|
+
return output
|
|
187
|
+
.split(/\r?\n/)
|
|
188
|
+
.map((line) => line.trim())
|
|
189
|
+
.filter(Boolean);
|
|
190
|
+
} catch {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {string} file
|
|
198
|
+
* @param {string} pattern
|
|
199
|
+
*/
|
|
200
|
+
export function matchesContractPattern(file, pattern) {
|
|
201
|
+
return micromatch.isMatch(file, pattern, { dot: true });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {string} worktreePath
|
|
206
|
+
* @param {ReturnType<import("../tasks/packet/parse-prompt.mjs").parseContract>} parsedContract
|
|
207
|
+
* @param {string} [baseBranch]
|
|
208
|
+
* @param {string[]} [pendingPaths] Uncommitted paths about to be lane-committed
|
|
209
|
+
* @param {object} [config]
|
|
210
|
+
* @returns {{ ok: boolean, failures: string[] }}
|
|
211
|
+
*/
|
|
212
|
+
export function verifyStubFileScopeMustChange(
|
|
213
|
+
worktreePath,
|
|
214
|
+
parsedContract,
|
|
215
|
+
baseBranch = "main",
|
|
216
|
+
pendingPaths = [],
|
|
217
|
+
config = {},
|
|
218
|
+
) {
|
|
219
|
+
const patterns = parsedContract?.fileScopeMustChange ?? [];
|
|
220
|
+
if (patterns.length === 0) {
|
|
221
|
+
return { ok: true, failures: [] };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const changedFiles = listEffectiveChangedFiles(worktreePath, baseBranch, pendingPaths);
|
|
225
|
+
/** @type {string[]} */
|
|
226
|
+
const failures = [];
|
|
227
|
+
for (const pattern of patterns) {
|
|
228
|
+
const matched = changedFiles.some((file) =>
|
|
229
|
+
pattern.endsWith("/") ? file.startsWith(pattern) : matchesContractPattern(file, pattern),
|
|
230
|
+
);
|
|
231
|
+
if (matched) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (isStubPrelandedFileScopeSatisfied(worktreePath, pattern, changedFiles, config, baseBranch)) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (isBaseScopeSatisfied(worktreePath, pattern, changedFiles, baseBranch, config)) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
failures.push(`Contract fileScopeMustChange: no matching changes for ${pattern}`);
|
|
241
|
+
}
|
|
242
|
+
return { ok: failures.length === 0, failures };
|
|
243
|
+
}
|