pi-spine 2.2.0 → 2.3.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/verify.mjs +2 -19
- 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/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 +483 -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 +375 -0
- package/src/batch/worker-host.mjs +50 -541
- package/src/batch/worker-spawn.mjs +315 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Post-lane-commit dirty worktree hygiene (SP-427 / #73).
|
|
4
4
|
* Coverage artifacts regenerated by npm test are ephemeral when not in task file scope.
|
|
5
|
+
* SP-583/SP-601 strangler split — git porcelain helpers in lane-dirty-check-git.mjs.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import { execFileSync } from "node:child_process";
|
|
@@ -9,15 +10,38 @@ import fs from "node:fs";
|
|
|
9
10
|
import path from "node:path";
|
|
10
11
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
11
12
|
import { resolveWorktreeSetupHook } from "../config/worktree-setup-hook.mjs";
|
|
12
|
-
import {
|
|
13
|
+
import { gitPorcelain } from "./lane-commit.mjs";
|
|
13
14
|
import { gitExec } from "./git-exec.mjs";
|
|
14
|
-
import { runWorktreeSetupHook } from "./worktree.mjs";
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
export {
|
|
17
|
+
COVERAGE_ARTIFACT_MARKERS,
|
|
18
|
+
extractPorcelainPath,
|
|
19
|
+
filterOutOfScopeCoveragePorcelain,
|
|
20
|
+
filterSetupHookSymlinkDriftPorcelain,
|
|
21
|
+
isCoverageArtifactPath,
|
|
22
|
+
isPathInFileScope,
|
|
23
|
+
isSymlinkDeletionPorcelainLine,
|
|
24
|
+
isSymlinkOnlyDriftPorcelain,
|
|
25
|
+
isWorktreeDeletionPorcelainLine,
|
|
26
|
+
listOutOfScopeCoveragePaths,
|
|
27
|
+
listOutOfScopeCoverageRoots,
|
|
28
|
+
listPorcelainPaths,
|
|
29
|
+
listTrackedPorcelainPaths,
|
|
30
|
+
parseLaneWorktreeIdentity,
|
|
31
|
+
repairSetupHookSymlinkDrift,
|
|
32
|
+
resolveSetupHookSymlinkDriftPorcelain,
|
|
33
|
+
} from "./lane-dirty-check-git.mjs";
|
|
34
|
+
|
|
35
|
+
import {
|
|
36
|
+
extractPorcelainPath,
|
|
37
|
+
filterOutOfScopeCoveragePorcelain,
|
|
38
|
+
isSymlinkOnlyDriftPorcelain,
|
|
39
|
+
listOutOfScopeCoveragePaths,
|
|
40
|
+
listOutOfScopeCoverageRoots,
|
|
41
|
+
listPorcelainPaths,
|
|
42
|
+
listTrackedPorcelainPaths,
|
|
43
|
+
repairSetupHookSymlinkDrift,
|
|
44
|
+
} from "./lane-dirty-check-git.mjs";
|
|
21
45
|
|
|
22
46
|
/**
|
|
23
47
|
* Path segments for gitignored build artifacts that npm test and similar tools
|
|
@@ -138,119 +162,6 @@ export function sanitizeFlutterBuildBeforeAnalyze(worktreePath, { enabled = true
|
|
|
138
162
|
return { cleaned: true, buildDir: FLUTTER_BUILD_DIR };
|
|
139
163
|
}
|
|
140
164
|
|
|
141
|
-
/**
|
|
142
|
-
* @param {string} filePath
|
|
143
|
-
* @returns {boolean}
|
|
144
|
-
*/
|
|
145
|
-
export function isCoverageArtifactPath(filePath) {
|
|
146
|
-
if (!filePath || typeof filePath !== "string") return false;
|
|
147
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
148
|
-
return COVERAGE_ARTIFACT_MARKERS.some(
|
|
149
|
-
(marker) =>
|
|
150
|
-
normalized === marker.slice(0, -1) ||
|
|
151
|
-
normalized.startsWith(marker) ||
|
|
152
|
-
normalized.includes(marker),
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @param {string} filePath
|
|
158
|
-
* @param {string[]} [fileScopePaths]
|
|
159
|
-
* @returns {boolean}
|
|
160
|
-
*/
|
|
161
|
-
export function isPathInFileScope(filePath, fileScopePaths) {
|
|
162
|
-
if (!filePath || !Array.isArray(fileScopePaths) || fileScopePaths.length === 0) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
167
|
-
const scopePrefixes = [];
|
|
168
|
-
for (const rel of fileScopePaths) {
|
|
169
|
-
if (!rel || typeof rel !== "string") continue;
|
|
170
|
-
const normalized = rel.replace(/\\/g, "/");
|
|
171
|
-
scopePrefixes.push(normalized.endsWith("/") ? normalized : `${normalized}/`);
|
|
172
|
-
scopePrefixes.push(normalized);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return scopePrefixes.some(
|
|
176
|
-
(prefix) => normalizedPath === prefix || normalizedPath.startsWith(prefix),
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @param {string} line
|
|
182
|
-
* @returns {string | null}
|
|
183
|
-
*/
|
|
184
|
-
function extractPorcelainPath(line) {
|
|
185
|
-
if (!line.trim()) return null;
|
|
186
|
-
let filePath = line.length > 2 && line[2] === " " ? line.slice(3) : line.slice(2);
|
|
187
|
-
filePath = filePath.trim();
|
|
188
|
-
if (!filePath) return null;
|
|
189
|
-
if (filePath.includes(" -> ")) {
|
|
190
|
-
return filePath.split(" -> ").pop()?.trim() ?? null;
|
|
191
|
-
}
|
|
192
|
-
return filePath;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @param {string} porcelain
|
|
197
|
-
* @returns {string[]}
|
|
198
|
-
*/
|
|
199
|
-
export function listPorcelainPaths(porcelain) {
|
|
200
|
-
if (!porcelain?.trim()) return [];
|
|
201
|
-
return porcelain
|
|
202
|
-
.split("\n")
|
|
203
|
-
.map((line) => extractPorcelainPath(line))
|
|
204
|
-
.filter((entry) => Boolean(entry));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @param {string[]} dirtyPaths
|
|
209
|
-
* @param {string[]} [fileScopePaths]
|
|
210
|
-
* @returns {string[]}
|
|
211
|
-
*/
|
|
212
|
-
export function listOutOfScopeCoveragePaths(dirtyPaths, fileScopePaths) {
|
|
213
|
-
if (!Array.isArray(dirtyPaths) || dirtyPaths.length === 0) return [];
|
|
214
|
-
return dirtyPaths.filter(
|
|
215
|
-
(filePath) => isCoverageArtifactPath(filePath) && !isPathInFileScope(filePath, fileScopePaths),
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @param {string} filePath
|
|
221
|
-
* @returns {string | null}
|
|
222
|
-
*/
|
|
223
|
-
function coverageRootForPath(filePath) {
|
|
224
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
225
|
-
const markerIdx = normalized.indexOf("/coverage/");
|
|
226
|
-
if (markerIdx >= 0) {
|
|
227
|
-
return normalized.slice(0, markerIdx + "/coverage".length);
|
|
228
|
-
}
|
|
229
|
-
if (normalized === "coverage" || normalized.startsWith("coverage/")) {
|
|
230
|
-
return "coverage";
|
|
231
|
-
}
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @param {string[]} filePaths
|
|
237
|
-
* @param {string[]} [fileScopePaths]
|
|
238
|
-
* @returns {string[]}
|
|
239
|
-
*/
|
|
240
|
-
export function listOutOfScopeCoverageRoots(filePaths, fileScopePaths) {
|
|
241
|
-
const roots = new Set();
|
|
242
|
-
for (const filePath of filePaths) {
|
|
243
|
-
if (!isCoverageArtifactPath(filePath) || isPathInFileScope(filePath, fileScopePaths)) {
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
const root = coverageRootForPath(filePath);
|
|
247
|
-
if (root && !isPathInFileScope(root, fileScopePaths)) {
|
|
248
|
-
roots.add(root);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return [...roots].sort();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
165
|
/**
|
|
255
166
|
* Restore tracked and remove untracked out-of-scope coverage before lane commit.
|
|
256
167
|
*
|
|
@@ -284,23 +195,6 @@ export function sanitizeOutOfScopeCoverageBeforeLaneCommit(
|
|
|
284
195
|
return { restored, cleanedRoots };
|
|
285
196
|
}
|
|
286
197
|
|
|
287
|
-
/**
|
|
288
|
-
* @param {string} porcelain
|
|
289
|
-
* @returns {Set<string>}
|
|
290
|
-
*/
|
|
291
|
-
function listTrackedPorcelainPaths(porcelain) {
|
|
292
|
-
const tracked = new Set();
|
|
293
|
-
if (!porcelain?.trim()) return tracked;
|
|
294
|
-
for (const line of porcelain.split("\n")) {
|
|
295
|
-
if (!line.trim()) continue;
|
|
296
|
-
const status = line.slice(0, 2);
|
|
297
|
-
if (status === "??" || status === "!!") continue;
|
|
298
|
-
const filePath = extractPorcelainPath(line);
|
|
299
|
-
if (filePath) tracked.add(filePath);
|
|
300
|
-
}
|
|
301
|
-
return tracked;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
198
|
/**
|
|
305
199
|
* Restore tracked coverage artifacts that are outside task file scope.
|
|
306
200
|
*
|
|
@@ -337,150 +231,6 @@ export function restoreOutOfScopeCoverageArtifacts(
|
|
|
337
231
|
return { restored: toRestore };
|
|
338
232
|
}
|
|
339
233
|
|
|
340
|
-
/**
|
|
341
|
-
* Drop out-of-scope coverage artifact lines from porcelain after ignore patterns.
|
|
342
|
-
*
|
|
343
|
-
* @param {string} porcelain
|
|
344
|
-
* @param {string[]} [fileScopePaths]
|
|
345
|
-
* @param {string[]} [ignorePatterns]
|
|
346
|
-
* @returns {string}
|
|
347
|
-
*/
|
|
348
|
-
/**
|
|
349
|
-
* @param {string} line
|
|
350
|
-
* @returns {boolean}
|
|
351
|
-
*/
|
|
352
|
-
export function isSymlinkDeletionPorcelainLine(line) {
|
|
353
|
-
if (!line?.trim() || line.length < 3) return false;
|
|
354
|
-
const indexStatus = line[0];
|
|
355
|
-
const worktreeStatus = line[1];
|
|
356
|
-
const disallowed = new Set(["M", "A", "R", "C", "U"]);
|
|
357
|
-
if (disallowed.has(indexStatus) || disallowed.has(worktreeStatus)) {
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
return indexStatus === "D" || worktreeStatus === "D";
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* @param {string} line
|
|
365
|
-
* @returns {boolean}
|
|
366
|
-
*/
|
|
367
|
-
export function isWorktreeDeletionPorcelainLine(line) {
|
|
368
|
-
return isSymlinkDeletionPorcelainLine(line) && line[1] === "D";
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* True when every porcelain line is a symlink/hook deletion (` D`, `D `, or `DD`).
|
|
373
|
-
*
|
|
374
|
-
* @param {string} porcelain
|
|
375
|
-
* @returns {boolean}
|
|
376
|
-
*/
|
|
377
|
-
export function isSymlinkOnlyDriftPorcelain(porcelain) {
|
|
378
|
-
if (!porcelain?.trim()) return false;
|
|
379
|
-
for (const line of porcelain.split("\n")) {
|
|
380
|
-
if (!line.trim()) continue;
|
|
381
|
-
if (!isSymlinkDeletionPorcelainLine(line)) return false;
|
|
382
|
-
}
|
|
383
|
-
return true;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* @param {string} worktreePath
|
|
388
|
-
* @returns {{ batchId: string, laneNumber: number } | null}
|
|
389
|
-
*/
|
|
390
|
-
export function parseLaneWorktreeIdentity(worktreePath) {
|
|
391
|
-
const normalized = worktreePath.replace(/\\/g, "/");
|
|
392
|
-
const match = normalized.match(/\/\.worktrees\/spine-([^/]+)\/lane-(\d+)\/?$/);
|
|
393
|
-
if (!match) return null;
|
|
394
|
-
return { batchId: match[1], laneNumber: Number(match[2]) };
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* @param {string} porcelain
|
|
399
|
-
* @returns {string}
|
|
400
|
-
*/
|
|
401
|
-
export function filterSetupHookSymlinkDriftPorcelain(porcelain) {
|
|
402
|
-
if (!porcelain?.trim() || !isSymlinkOnlyDriftPorcelain(porcelain)) {
|
|
403
|
-
return porcelain ?? "";
|
|
404
|
-
}
|
|
405
|
-
return "";
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Re-run worktreeSetupHook to recreate hook-managed symlinks after drift.
|
|
410
|
-
*
|
|
411
|
-
* @param {string} worktreePath
|
|
412
|
-
* @param {{ projectRoot: string, config?: object, batchId?: string, laneNumber?: number }} options
|
|
413
|
-
* @returns {{ repaired: boolean, reason?: string }}
|
|
414
|
-
*/
|
|
415
|
-
export function repairSetupHookSymlinkDrift(worktreePath, { projectRoot, config, batchId, laneNumber }) {
|
|
416
|
-
const effectiveConfig = config ?? loadSpineConfig(projectRoot).config ?? {};
|
|
417
|
-
const hookPath = resolveWorktreeSetupHook(projectRoot, effectiveConfig);
|
|
418
|
-
if (!hookPath) {
|
|
419
|
-
return { repaired: false, reason: "no_hook" };
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
const identity = parseLaneWorktreeIdentity(worktreePath);
|
|
423
|
-
const effectiveBatchId = batchId ?? identity?.batchId ?? "unknown";
|
|
424
|
-
const effectiveLaneNumber = laneNumber ?? identity?.laneNumber ?? 1;
|
|
425
|
-
|
|
426
|
-
try {
|
|
427
|
-
runWorktreeSetupHook({
|
|
428
|
-
projectRoot,
|
|
429
|
-
worktreePath,
|
|
430
|
-
batchId: effectiveBatchId,
|
|
431
|
-
laneNumber: effectiveLaneNumber,
|
|
432
|
-
config: effectiveConfig,
|
|
433
|
-
});
|
|
434
|
-
return { repaired: true };
|
|
435
|
-
} catch {
|
|
436
|
-
return { repaired: false, reason: "hook_failed" };
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Repair or ignore symlink-only deletions from worktreeSetupHook paths (#87 / SP-429).
|
|
442
|
-
*
|
|
443
|
-
* @param {string} worktreePath
|
|
444
|
-
* @param {string} porcelain
|
|
445
|
-
* @param {{ projectRoot?: string, config?: object, batchId?: string, laneNumber?: number }} [options]
|
|
446
|
-
* @returns {string}
|
|
447
|
-
*/
|
|
448
|
-
export function resolveSetupHookSymlinkDriftPorcelain(
|
|
449
|
-
worktreePath,
|
|
450
|
-
porcelain,
|
|
451
|
-
{ projectRoot, config, batchId, laneNumber } = {},
|
|
452
|
-
) {
|
|
453
|
-
if (!porcelain?.trim() || !isSymlinkOnlyDriftPorcelain(porcelain)) {
|
|
454
|
-
return porcelain ?? "";
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
const identityRoot = projectRoot ?? worktreePath;
|
|
458
|
-
const effectiveConfig = config ?? loadSpineConfig(identityRoot).config ?? {};
|
|
459
|
-
if (!resolveWorktreeSetupHook(identityRoot, effectiveConfig)) {
|
|
460
|
-
return porcelain;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
const repair = repairSetupHookSymlinkDrift(worktreePath, {
|
|
464
|
-
projectRoot: identityRoot,
|
|
465
|
-
config: effectiveConfig,
|
|
466
|
-
batchId,
|
|
467
|
-
laneNumber,
|
|
468
|
-
});
|
|
469
|
-
if (repair.repaired) {
|
|
470
|
-
return porcelain;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
return filterSetupHookSymlinkDriftPorcelain(porcelain);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Split gitignored paths into index-tracked (removable with git rm --cached)
|
|
478
|
-
* and worktree-only (ephemeral artifacts not in the index).
|
|
479
|
-
*
|
|
480
|
-
* @param {string} worktreePath
|
|
481
|
-
* @param {string[]} gitignoredPaths
|
|
482
|
-
* @returns {{ indexTracked: string[], worktreeOnly: string[] }}
|
|
483
|
-
*/
|
|
484
234
|
/**
|
|
485
235
|
* @param {string} filePath
|
|
486
236
|
* @returns {boolean}
|
|
@@ -664,22 +414,6 @@ export function formatGitignoredRemediationMessage(indexTracked, worktreeOnly) {
|
|
|
664
414
|
);
|
|
665
415
|
}
|
|
666
416
|
|
|
667
|
-
export function filterOutOfScopeCoveragePorcelain(porcelain, fileScopePaths, ignorePatterns = []) {
|
|
668
|
-
const afterIgnore = filterPorcelain(porcelain, ignorePatterns);
|
|
669
|
-
if (!afterIgnore?.trim()) return "";
|
|
670
|
-
|
|
671
|
-
const kept = [];
|
|
672
|
-
for (const line of afterIgnore.split("\n")) {
|
|
673
|
-
if (!line.trim()) continue;
|
|
674
|
-
const filePath = extractPorcelainPath(line);
|
|
675
|
-
if (filePath && isCoverageArtifactPath(filePath) && !isPathInFileScope(filePath, fileScopePaths)) {
|
|
676
|
-
continue;
|
|
677
|
-
}
|
|
678
|
-
kept.push(line);
|
|
679
|
-
}
|
|
680
|
-
return kept.length === 0 ? "" : kept.join("\n");
|
|
681
|
-
}
|
|
682
|
-
|
|
683
417
|
/**
|
|
684
418
|
* Resolve porcelain for post-lane-commit validation: restore ephemeral coverage, then filter.
|
|
685
419
|
*
|