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,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advisory host-capacity preflight for stet-backed contract review. Local LLM
|
|
3
|
+
* review competes with batch workers for RAM; the v2.28 release stalled when a
|
|
4
|
+
* second stet session and a 16 GB model ran with swap nearly exhausted.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
|
|
11
|
+
const PROBE_TIMEOUT_MS = 3000;
|
|
12
|
+
const BYTES_PER_MIB = 1024 * 1024;
|
|
13
|
+
export const SWAP_FREE_WARN_BYTES = 2 * 1024 * BYTES_PER_MIB;
|
|
14
|
+
/** Loaded local-model bytes above this share of physical RAM leave too little for lanes. */
|
|
15
|
+
export const LOADED_MODEL_RAM_SHARE_WARN = 0.5;
|
|
16
|
+
|
|
17
|
+
const STET_SESSION_PATTERN = "stet (start|run|rerun)( |$)";
|
|
18
|
+
const SPINE_BATCH_PATTERN = "spine(\\.mjs)? batch (start|resume)";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} file
|
|
22
|
+
* @param {string[]} args
|
|
23
|
+
* @param {number|null} [emptyExitStatus] Exit status meaning "ran fine, no results".
|
|
24
|
+
* @returns {string|null} stdout, or null when the probe is unavailable.
|
|
25
|
+
*/
|
|
26
|
+
function tryExec(file, args, emptyExitStatus = null) {
|
|
27
|
+
try {
|
|
28
|
+
return execFileSync(file, args, {
|
|
29
|
+
encoding: "utf-8",
|
|
30
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
31
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
32
|
+
});
|
|
33
|
+
} catch (err) {
|
|
34
|
+
const status = err && typeof err === "object" && "status" in err ? err.status : null;
|
|
35
|
+
return emptyExitStatus !== null && status === emptyExitStatus ? "" : null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @param {string} pattern @returns {number[]|null} */
|
|
40
|
+
function pgrepPids(pattern) {
|
|
41
|
+
const PGREP_NO_MATCH_STATUS = 1;
|
|
42
|
+
const out = tryExec("pgrep", ["-f", pattern], PGREP_NO_MATCH_STATUS);
|
|
43
|
+
if (out === null) return null;
|
|
44
|
+
return out
|
|
45
|
+
.split("\n")
|
|
46
|
+
.map((line) => Number.parseInt(line, 10))
|
|
47
|
+
.filter((pid) => Number.isInteger(pid) && pid !== process.pid);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} text `sysctl vm.swapusage` output
|
|
52
|
+
* @returns {number|null}
|
|
53
|
+
*/
|
|
54
|
+
export function parseDarwinSwapFreeBytes(text) {
|
|
55
|
+
const match = /free\s*=\s*([\d.]+)M/.exec(text);
|
|
56
|
+
return match ? Math.round(Number.parseFloat(match[1]) * BYTES_PER_MIB) : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} text /proc/meminfo contents
|
|
61
|
+
* @returns {number|null} null when the host has no swap configured.
|
|
62
|
+
*/
|
|
63
|
+
export function parseLinuxSwapFreeBytes(text) {
|
|
64
|
+
const total = /^SwapTotal:\s+(\d+) kB/m.exec(text);
|
|
65
|
+
const free = /^SwapFree:\s+(\d+) kB/m.exec(text);
|
|
66
|
+
if (!total || !free || Number(total[1]) === 0) return null;
|
|
67
|
+
return Number(free[1]) * 1024;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @returns {number|null} */
|
|
71
|
+
function probeSwapFreeBytes() {
|
|
72
|
+
if (process.platform === "darwin") {
|
|
73
|
+
const out = tryExec("sysctl", ["vm.swapusage"]);
|
|
74
|
+
return out === null ? null : parseDarwinSwapFreeBytes(out);
|
|
75
|
+
}
|
|
76
|
+
if (process.platform === "linux") {
|
|
77
|
+
try {
|
|
78
|
+
return parseLinuxSwapFreeBytes(fs.readFileSync("/proc/meminfo", "utf-8"));
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} text `lms ps --json` output
|
|
88
|
+
* @returns {{ id: string, sizeBytes: number }[]|null}
|
|
89
|
+
*/
|
|
90
|
+
export function parseLmsLoadedModels(text) {
|
|
91
|
+
try {
|
|
92
|
+
const parsed = JSON.parse(text);
|
|
93
|
+
if (!Array.isArray(parsed)) return null;
|
|
94
|
+
return parsed
|
|
95
|
+
.filter((m) => m && typeof m.sizeBytes === "number")
|
|
96
|
+
.map((m) => ({ id: String(m.identifier ?? m.modelKey ?? "unknown"), sizeBytes: m.sizeBytes }));
|
|
97
|
+
} catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @returns {{ id: string, sizeBytes: number }[]|null} */
|
|
103
|
+
function probeLoadedModels() {
|
|
104
|
+
const out = tryExec("lms", ["ps", "--json"]);
|
|
105
|
+
return out === null ? null : parseLmsLoadedModels(out);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const DEFAULT_STET_CAPACITY_PROBES = {
|
|
109
|
+
stetOnPath: () => tryExec("stet", ["--version"]) !== null,
|
|
110
|
+
stetSessionPids: () => pgrepPids(STET_SESSION_PATTERN),
|
|
111
|
+
spineBatchPids: () => pgrepPids(SPINE_BATCH_PATTERN),
|
|
112
|
+
swapFreeBytes: probeSwapFreeBytes,
|
|
113
|
+
loadedModels: probeLoadedModels,
|
|
114
|
+
totalMemBytes: () => os.totalmem(),
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** @param {number} bytes */
|
|
118
|
+
const gib = (bytes) => `${(bytes / (1024 * BYTES_PER_MIB)).toFixed(1)} GiB`;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {{ probes?: Partial<typeof DEFAULT_STET_CAPACITY_PROBES> }} [opts]
|
|
122
|
+
*/
|
|
123
|
+
export function buildStetCapacityDoctorCheck(opts = {}) {
|
|
124
|
+
const probes = { ...DEFAULT_STET_CAPACITY_PROBES, ...opts.probes };
|
|
125
|
+
const label = "stet review capacity";
|
|
126
|
+
if (!probes.stetOnPath()) {
|
|
127
|
+
return { label, ok: true, detail: "stet not on PATH (skipped)" };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @type {string[]} */
|
|
131
|
+
const warnings = [];
|
|
132
|
+
/** @type {string[]} */
|
|
133
|
+
const unknown = [];
|
|
134
|
+
|
|
135
|
+
const stetPids = probes.stetSessionPids();
|
|
136
|
+
if (stetPids === null) unknown.push("stet processes");
|
|
137
|
+
else if (stetPids.length > 0) warnings.push(`stet review already running (pid ${stetPids.join(", ")})`);
|
|
138
|
+
|
|
139
|
+
const batchPids = probes.spineBatchPids();
|
|
140
|
+
if (batchPids === null) unknown.push("spine batches");
|
|
141
|
+
else if (batchPids.length > 0) warnings.push(`other spine batch running (pid ${batchPids.join(", ")})`);
|
|
142
|
+
|
|
143
|
+
const swapFree = probes.swapFreeBytes();
|
|
144
|
+
if (swapFree !== null && swapFree < SWAP_FREE_WARN_BYTES) {
|
|
145
|
+
warnings.push(`swap nearly exhausted (${gib(swapFree)} free)`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const models = probes.loadedModels();
|
|
149
|
+
if (models === null) {
|
|
150
|
+
unknown.push("LM Studio models");
|
|
151
|
+
} else {
|
|
152
|
+
const loadedBytes = models.reduce((sum, m) => sum + m.sizeBytes, 0);
|
|
153
|
+
const totalMem = probes.totalMemBytes();
|
|
154
|
+
if (loadedBytes > totalMem * LOADED_MODEL_RAM_SHARE_WARN) {
|
|
155
|
+
const ids = models.map((m) => m.id).join(", ");
|
|
156
|
+
warnings.push(`LM Studio models use ${gib(loadedBytes)} of ${gib(totalMem)} RAM (${ids})`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const unknownNote = unknown.length > 0 ? `; not probed: ${unknown.join(", ")}` : "";
|
|
161
|
+
if (warnings.length === 0) {
|
|
162
|
+
return { label, ok: true, detail: `host has headroom for stet review${unknownNote}` };
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
label,
|
|
166
|
+
ok: true,
|
|
167
|
+
warning: true,
|
|
168
|
+
detail: `${warnings.join("; ")}${unknownNote}`,
|
|
169
|
+
suggestedCommand: "lms unload --all # or wait for the other stet/spine run to finish",
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -24,6 +24,7 @@ const STEP_HEADING_RE = /^### Step (\d+): (.+)$/gm;
|
|
|
24
24
|
export const CONTRACT_FIELD_NAMES = Object.freeze([
|
|
25
25
|
"testCommand",
|
|
26
26
|
"runCommand",
|
|
27
|
+
"reviewCommand",
|
|
27
28
|
"fileScopeMustChange",
|
|
28
29
|
"fileScopeMustNotChange",
|
|
29
30
|
"minLineCoverage",
|
|
@@ -328,6 +329,7 @@ function collectDuplicateStepNumberErrors(steps) {
|
|
|
328
329
|
* @returns {{
|
|
329
330
|
* testCommand: string | null,
|
|
330
331
|
* runCommand: string | null,
|
|
332
|
+
* reviewCommand: string | null,
|
|
331
333
|
* fileScopeMustChange: string[],
|
|
332
334
|
* fileScopeMustNotChange: string[],
|
|
333
335
|
* minLineCoverage: number | null,
|
|
@@ -352,6 +354,7 @@ export function parseContract(markdown) {
|
|
|
352
354
|
const parsed = {
|
|
353
355
|
testCommand: null,
|
|
354
356
|
runCommand: null,
|
|
357
|
+
reviewCommand: null,
|
|
355
358
|
fileScopeMustChange: [],
|
|
356
359
|
fileScopeMustNotChange: [],
|
|
357
360
|
minLineCoverage: null,
|
|
@@ -469,44 +472,26 @@ function applyContractField(parsed, field, rawValue) {
|
|
|
469
472
|
}
|
|
470
473
|
|
|
471
474
|
switch (field) {
|
|
472
|
-
case "testCommand":
|
|
475
|
+
case "testCommand":
|
|
476
|
+
case "runCommand":
|
|
477
|
+
case "reviewCommand": {
|
|
473
478
|
const command = parseContractScalar(value);
|
|
474
479
|
if (command.includes("\n")) {
|
|
475
|
-
parsed.errors.push(
|
|
480
|
+
parsed.errors.push(`Contract ${field} must not contain newlines`);
|
|
476
481
|
return;
|
|
477
482
|
}
|
|
478
483
|
if (command.length > TEST_COMMAND_MAX_LENGTH) {
|
|
479
|
-
parsed.errors.push(`Contract
|
|
484
|
+
parsed.errors.push(`Contract ${field} exceeds ${TEST_COMMAND_MAX_LENGTH} characters`);
|
|
480
485
|
return;
|
|
481
486
|
}
|
|
482
|
-
const
|
|
483
|
-
if (
|
|
487
|
+
const commandMetacharIssue = findContractCommandMetacharIssue(command);
|
|
488
|
+
if (commandMetacharIssue) {
|
|
484
489
|
parsed.errors.push(
|
|
485
|
-
`Contract
|
|
490
|
+
`Contract ${field} contains forbidden shell metacharacters: ${commandMetacharIssue}; ${CONTRACT_METACHAR_FIX_HINT}`,
|
|
486
491
|
);
|
|
487
492
|
return;
|
|
488
493
|
}
|
|
489
|
-
parsed
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
case "runCommand": {
|
|
493
|
-
const command = parseContractScalar(value);
|
|
494
|
-
if (command.includes("\n")) {
|
|
495
|
-
parsed.errors.push("Contract runCommand must not contain newlines");
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
if (command.length > TEST_COMMAND_MAX_LENGTH) {
|
|
499
|
-
parsed.errors.push(`Contract runCommand exceeds ${TEST_COMMAND_MAX_LENGTH} characters`);
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
const runCommandIssue = findContractCommandMetacharIssue(command);
|
|
503
|
-
if (runCommandIssue) {
|
|
504
|
-
parsed.errors.push(
|
|
505
|
-
`Contract runCommand contains forbidden shell metacharacters: ${runCommandIssue}; ${CONTRACT_METACHAR_FIX_HINT}`,
|
|
506
|
-
);
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
parsed.runCommand = command;
|
|
494
|
+
parsed[field] = command;
|
|
510
495
|
return;
|
|
511
496
|
}
|
|
512
497
|
case "fileScopeMustChange":
|
|
@@ -215,6 +215,8 @@ function patternBlocksCurrentTaskFolder(pattern, taskId, tasksRoot) {
|
|
|
215
215
|
function isContractTableEmpty(parsed) {
|
|
216
216
|
return (
|
|
217
217
|
parsed.testCommand === null &&
|
|
218
|
+
parsed.runCommand === null &&
|
|
219
|
+
parsed.reviewCommand === null &&
|
|
218
220
|
parsed.fileScopeMustChange.length === 0 &&
|
|
219
221
|
parsed.fileScopeMustNotChange.length === 0 &&
|
|
220
222
|
parsed.minLineCoverage === null &&
|
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* Lane-commit dirty hygiene: coverage restore/clean, gitignored artifact
|
|
4
|
-
* sanitization, and post-lane-commit porcelain resolution (SP-601 / #117).
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { execFileSync } from "node:child_process";
|
|
8
|
-
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
9
|
-
import { resolveWorktreeSetupHook } from "../config/worktree-setup-hook.mjs";
|
|
10
|
-
import { gitPorcelain } from "./lane-commit.mjs";
|
|
11
|
-
import { gitExec } from "./git-exec.mjs";
|
|
12
|
-
import {
|
|
13
|
-
extractPorcelainPath,
|
|
14
|
-
filterOutOfScopeCoveragePorcelain,
|
|
15
|
-
isSymlinkOnlyDriftPorcelain,
|
|
16
|
-
listOutOfScopeCoveragePaths,
|
|
17
|
-
listOutOfScopeCoverageRoots,
|
|
18
|
-
listPorcelainPaths,
|
|
19
|
-
listTrackedPorcelainPaths,
|
|
20
|
-
repairSetupHookSymlinkDrift,
|
|
21
|
-
} from "./lane-dirty-check-git.mjs";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Path segments for gitignored build artifacts that npm test and similar tools
|
|
25
|
-
* regenerate in lane worktrees (SP-471 / #95).
|
|
26
|
-
*/
|
|
27
|
-
export const GITIGNORED_ARTIFACT_MARKERS = [
|
|
28
|
-
"/node_modules/",
|
|
29
|
-
"node_modules/",
|
|
30
|
-
"/coverage/",
|
|
31
|
-
"coverage/",
|
|
32
|
-
"/__pycache__/",
|
|
33
|
-
"__pycache__/",
|
|
34
|
-
"/graphify-out/",
|
|
35
|
-
"graphify-out/",
|
|
36
|
-
"/.review/",
|
|
37
|
-
".review/",
|
|
38
|
-
"/.pi-smart-router/",
|
|
39
|
-
".pi-smart-router/",
|
|
40
|
-
"/.spine/runtime/",
|
|
41
|
-
".spine/runtime/",
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Restore tracked and remove untracked out-of-scope coverage before lane commit.
|
|
46
|
-
*
|
|
47
|
-
* @param {string} worktreePath
|
|
48
|
-
* @param {string[]} [fileScopePaths]
|
|
49
|
-
* @param {{ projectRoot?: string, porcelain?: string }} [options]
|
|
50
|
-
* @returns {{ restored: string[], cleanedRoots: string[] }}
|
|
51
|
-
*/
|
|
52
|
-
export function sanitizeOutOfScopeCoverageBeforeLaneCommit(
|
|
53
|
-
worktreePath,
|
|
54
|
-
fileScopePaths,
|
|
55
|
-
{ projectRoot, porcelain } = {},
|
|
56
|
-
) {
|
|
57
|
-
const identityRoot = projectRoot ?? worktreePath;
|
|
58
|
-
const rawPorcelain = porcelain ?? "";
|
|
59
|
-
const dirtyPaths = listPorcelainPaths(rawPorcelain);
|
|
60
|
-
const { restored } = restoreOutOfScopeCoverageArtifacts(worktreePath, fileScopePaths, {
|
|
61
|
-
projectRoot: identityRoot,
|
|
62
|
-
dirtyPaths,
|
|
63
|
-
porcelain: rawPorcelain,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const cleanedRoots = listOutOfScopeCoverageRoots(dirtyPaths, fileScopePaths);
|
|
67
|
-
for (const root of cleanedRoots) {
|
|
68
|
-
gitExec(worktreePath, ["clean", "-fd", "--", root], {
|
|
69
|
-
projectRoot: identityRoot,
|
|
70
|
-
throwOnError: false,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return { restored, cleanedRoots };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Restore tracked coverage artifacts that are outside task file scope.
|
|
79
|
-
*
|
|
80
|
-
* @param {string} worktreePath
|
|
81
|
-
* @param {string[]} [fileScopePaths]
|
|
82
|
-
* @param {{ projectRoot?: string, dirtyPaths?: string[], porcelain?: string }} [options]
|
|
83
|
-
* @returns {{ restored: string[] }}
|
|
84
|
-
*/
|
|
85
|
-
export function restoreOutOfScopeCoverageArtifacts(
|
|
86
|
-
worktreePath,
|
|
87
|
-
fileScopePaths,
|
|
88
|
-
{ projectRoot, dirtyPaths, porcelain } = {},
|
|
89
|
-
) {
|
|
90
|
-
const identityRoot = projectRoot ?? worktreePath;
|
|
91
|
-
const candidates = Array.isArray(dirtyPaths) ? dirtyPaths : [];
|
|
92
|
-
const outOfScope = listOutOfScopeCoveragePaths(candidates, fileScopePaths);
|
|
93
|
-
if (outOfScope.length === 0) {
|
|
94
|
-
return { restored: [] };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const trackedPaths = listTrackedPorcelainPaths(porcelain ?? "");
|
|
98
|
-
const toRestore = trackedPaths.size > 0
|
|
99
|
-
? outOfScope.filter((filePath) => trackedPaths.has(filePath))
|
|
100
|
-
: outOfScope;
|
|
101
|
-
if (toRestore.length === 0) {
|
|
102
|
-
return { restored: [] };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
gitExec(
|
|
106
|
-
worktreePath,
|
|
107
|
-
["restore", "--source=HEAD", "--worktree", "--", ...toRestore],
|
|
108
|
-
{ projectRoot: identityRoot },
|
|
109
|
-
);
|
|
110
|
-
return { restored: toRestore };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @param {string} filePath
|
|
115
|
-
* @returns {boolean}
|
|
116
|
-
*/
|
|
117
|
-
export function isGitignoredArtifactPath(filePath) {
|
|
118
|
-
if (!filePath || typeof filePath !== "string") return false;
|
|
119
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
120
|
-
return GITIGNORED_ARTIFACT_MARKERS.some(
|
|
121
|
-
(marker) =>
|
|
122
|
-
normalized === marker.slice(0, -1) ||
|
|
123
|
-
normalized.startsWith(marker) ||
|
|
124
|
-
normalized.includes(marker),
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @param {string} filePath
|
|
130
|
-
* @returns {string | null}
|
|
131
|
-
*/
|
|
132
|
-
function gitignoredArtifactRootForPath(filePath) {
|
|
133
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
134
|
-
for (const marker of ["/node_modules/", "/coverage/", "/__pycache__/", "/graphify-out/"]) {
|
|
135
|
-
const markerIdx = normalized.indexOf(marker);
|
|
136
|
-
if (markerIdx >= 0) {
|
|
137
|
-
return normalized.slice(0, markerIdx + marker.length - 1);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (normalized === "node_modules" || normalized.startsWith("node_modules/")) {
|
|
141
|
-
return "node_modules";
|
|
142
|
-
}
|
|
143
|
-
if (normalized === "coverage" || normalized.startsWith("coverage/")) {
|
|
144
|
-
return "coverage";
|
|
145
|
-
}
|
|
146
|
-
if (normalized === "__pycache__" || normalized.startsWith("__pycache__/")) {
|
|
147
|
-
return "__pycache__";
|
|
148
|
-
}
|
|
149
|
-
if (normalized === "graphify-out" || normalized.startsWith("graphify-out/")) {
|
|
150
|
-
return "graphify-out";
|
|
151
|
-
}
|
|
152
|
-
if (normalized === ".review" || normalized.startsWith(".review/")) {
|
|
153
|
-
return ".review";
|
|
154
|
-
}
|
|
155
|
-
if (normalized === ".pi-smart-router" || normalized.startsWith(".pi-smart-router/")) {
|
|
156
|
-
return ".pi-smart-router";
|
|
157
|
-
}
|
|
158
|
-
if (normalized === ".spine/runtime" || normalized.startsWith(".spine/runtime/")) {
|
|
159
|
-
return ".spine/runtime";
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* @param {string[]} filePaths
|
|
166
|
-
* @returns {string[]}
|
|
167
|
-
*/
|
|
168
|
-
export function listGitignoredArtifactRoots(filePaths) {
|
|
169
|
-
const roots = new Set();
|
|
170
|
-
for (const filePath of filePaths) {
|
|
171
|
-
if (!isGitignoredArtifactPath(filePath)) continue;
|
|
172
|
-
const root = gitignoredArtifactRootForPath(filePath);
|
|
173
|
-
if (root) roots.add(root);
|
|
174
|
-
}
|
|
175
|
-
return [...roots].sort();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @param {string} worktreePath
|
|
180
|
-
* @returns {string[]}
|
|
181
|
-
*/
|
|
182
|
-
function listIgnoredUntrackedPaths(worktreePath) {
|
|
183
|
-
let output = "";
|
|
184
|
-
try {
|
|
185
|
-
output = execFileSync("git", ["ls-files", "-o", "-i", "--exclude-standard"], {
|
|
186
|
-
cwd: worktreePath,
|
|
187
|
-
encoding: "utf-8",
|
|
188
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
189
|
-
}).trim();
|
|
190
|
-
} catch {
|
|
191
|
-
return [];
|
|
192
|
-
}
|
|
193
|
-
if (!output) return [];
|
|
194
|
-
return output.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Auto-clean worktree-only gitignored artifacts under known dirs before lane dirty gate.
|
|
199
|
-
*
|
|
200
|
-
* @param {string} worktreePath
|
|
201
|
-
* @param {{ projectRoot?: string, porcelain?: string, enabled?: boolean }} [options]
|
|
202
|
-
* @returns {{ cleanedRoots: string[] }}
|
|
203
|
-
*/
|
|
204
|
-
export function sanitizeGitignoredArtifactsBeforeLaneCommit(
|
|
205
|
-
worktreePath,
|
|
206
|
-
{ projectRoot, porcelain, enabled = true } = {},
|
|
207
|
-
) {
|
|
208
|
-
if (!enabled) return { cleanedRoots: [] };
|
|
209
|
-
|
|
210
|
-
const identityRoot = projectRoot ?? worktreePath;
|
|
211
|
-
const rawPorcelain = typeof porcelain === "string" ? porcelain : "";
|
|
212
|
-
const dirtyPaths = listPorcelainPaths(rawPorcelain);
|
|
213
|
-
const ignoredUntrackedPaths = listIgnoredUntrackedPaths(worktreePath);
|
|
214
|
-
const gitignoredCandidates = [...new Set([...dirtyPaths, ...ignoredUntrackedPaths])];
|
|
215
|
-
if (gitignoredCandidates.length === 0) {
|
|
216
|
-
return { cleanedRoots: [] };
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const { worktreeOnly } = classifyGitignoredPaths(worktreePath, gitignoredCandidates);
|
|
220
|
-
const artifactRoots = listGitignoredArtifactRoots(worktreeOnly);
|
|
221
|
-
for (const root of artifactRoots) {
|
|
222
|
-
gitExec(worktreePath, ["clean", "-fdX", "--", root], {
|
|
223
|
-
projectRoot: identityRoot,
|
|
224
|
-
throwOnError: false,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return { cleanedRoots: artifactRoots };
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export function classifyGitignoredPaths(worktreePath, gitignoredPaths) {
|
|
232
|
-
if (!Array.isArray(gitignoredPaths) || gitignoredPaths.length === 0) {
|
|
233
|
-
return { indexTracked: [], worktreeOnly: [] };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
let indexedOutput = "";
|
|
237
|
-
try {
|
|
238
|
-
indexedOutput = execFileSync(
|
|
239
|
-
"git",
|
|
240
|
-
["ls-files", "--cached", "--", ...gitignoredPaths],
|
|
241
|
-
{
|
|
242
|
-
cwd: worktreePath,
|
|
243
|
-
encoding: "utf-8",
|
|
244
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
245
|
-
},
|
|
246
|
-
).trim();
|
|
247
|
-
} catch {
|
|
248
|
-
// If ls-files fails, treat all as worktree-only (safe fallback).
|
|
249
|
-
return { indexTracked: [], worktreeOnly: [...gitignoredPaths] };
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const indexedSet = new Set(
|
|
253
|
-
indexedOutput ? indexedOutput.split("\n").map((l) => l.trim()).filter(Boolean) : [],
|
|
254
|
-
);
|
|
255
|
-
const indexTracked = [];
|
|
256
|
-
const worktreeOnly = [];
|
|
257
|
-
for (const p of gitignoredPaths) {
|
|
258
|
-
if (indexedSet.has(p)) {
|
|
259
|
-
indexTracked.push(p);
|
|
260
|
-
} else {
|
|
261
|
-
worktreeOnly.push(p);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return { indexTracked, worktreeOnly };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Build a remediation message appropriate for the gitignored path classification.
|
|
269
|
-
*
|
|
270
|
-
* @param {string[]} indexTracked
|
|
271
|
-
* @param {string[]} worktreeOnly
|
|
272
|
-
* @returns {string}
|
|
273
|
-
*/
|
|
274
|
-
export function formatGitignoredRemediationMessage(indexTracked, worktreeOnly) {
|
|
275
|
-
const allPaths = [...indexTracked, ...worktreeOnly];
|
|
276
|
-
const preview = allPaths.slice(0, 20).join(", ");
|
|
277
|
-
const suffix = allPaths.length > 20 ? "…" : "";
|
|
278
|
-
const prefix = `Lane worktree has gitignored dirty files only (${preview}${suffix})`;
|
|
279
|
-
|
|
280
|
-
if (indexTracked.length > 0 && worktreeOnly.length > 0) {
|
|
281
|
-
return (
|
|
282
|
-
`${prefix} — ` +
|
|
283
|
-
`remove index-tracked paths with git rm --cached on the task branch, ` +
|
|
284
|
-
`then git clean -fdX to remove worktree-only artifacts before resume`
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
if (indexTracked.length > 0) {
|
|
288
|
-
return (
|
|
289
|
-
`${prefix} — ` +
|
|
290
|
-
`remove from the index with git rm --cached on the task branch before resume`
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
return (
|
|
294
|
-
`${prefix} — ` +
|
|
295
|
-
`worktree-only artifacts (not in git index); clean with git clean -fdX before resume`
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Resolve porcelain for post-lane-commit validation: restore ephemeral coverage, then filter.
|
|
301
|
-
*
|
|
302
|
-
* @param {string} worktreePath
|
|
303
|
-
* @param {object} [options]
|
|
304
|
-
* @param {string[]} [options.fileScopePaths]
|
|
305
|
-
* @param {string[]} [options.ignorePatterns]
|
|
306
|
-
* @param {string} [options.projectRoot]
|
|
307
|
-
* @param {string} [options.porcelain]
|
|
308
|
-
* @returns {string}
|
|
309
|
-
*/
|
|
310
|
-
export function resolvePostLaneCommitPorcelain(
|
|
311
|
-
worktreePath,
|
|
312
|
-
{ fileScopePaths, ignorePatterns = [], projectRoot, porcelain, config, batchId, laneNumber } = {},
|
|
313
|
-
) {
|
|
314
|
-
const rawPorcelain = typeof porcelain === "string" ? porcelain : "";
|
|
315
|
-
const dirtyPaths = listPorcelainPaths(rawPorcelain);
|
|
316
|
-
const { restored } = restoreOutOfScopeCoverageArtifacts(worktreePath, fileScopePaths, {
|
|
317
|
-
projectRoot,
|
|
318
|
-
dirtyPaths,
|
|
319
|
-
porcelain: rawPorcelain,
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
let effectivePorcelain = rawPorcelain;
|
|
323
|
-
if (restored.length > 0) {
|
|
324
|
-
const restoredSet = new Set(restored);
|
|
325
|
-
const kept = [];
|
|
326
|
-
for (const line of rawPorcelain.split("\n")) {
|
|
327
|
-
if (!line.trim()) continue;
|
|
328
|
-
const filePath = extractPorcelainPath(line);
|
|
329
|
-
if (filePath && restoredSet.has(filePath)) continue;
|
|
330
|
-
kept.push(line);
|
|
331
|
-
}
|
|
332
|
-
effectivePorcelain = kept.length === 0 ? "" : kept.join("\n");
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
let filtered = filterOutOfScopeCoveragePorcelain(effectivePorcelain, fileScopePaths, ignorePatterns);
|
|
336
|
-
if (!filtered?.trim()) {
|
|
337
|
-
return "";
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (isSymlinkOnlyDriftPorcelain(filtered)) {
|
|
341
|
-
const identityRoot = projectRoot ?? worktreePath;
|
|
342
|
-
const effectiveConfig = config ?? loadSpineConfig(identityRoot).config ?? {};
|
|
343
|
-
if (resolveWorktreeSetupHook(identityRoot, effectiveConfig)) {
|
|
344
|
-
repairSetupHookSymlinkDrift(worktreePath, {
|
|
345
|
-
projectRoot: identityRoot,
|
|
346
|
-
config: effectiveConfig,
|
|
347
|
-
batchId,
|
|
348
|
-
laneNumber,
|
|
349
|
-
});
|
|
350
|
-
const refreshedPorcelain = gitPorcelain(worktreePath);
|
|
351
|
-
filtered = filterOutOfScopeCoveragePorcelain(
|
|
352
|
-
refreshedPorcelain,
|
|
353
|
-
fileScopePaths,
|
|
354
|
-
ignorePatterns,
|
|
355
|
-
);
|
|
356
|
-
if (!filtered?.trim()) {
|
|
357
|
-
return "";
|
|
358
|
-
}
|
|
359
|
-
if (isSymlinkOnlyDriftPorcelain(filtered)) {
|
|
360
|
-
return "";
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return filtered;
|
|
366
|
-
}
|