pi-spine 2.28.1 → 2.30.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-batch.mjs +6 -1
- package/package.json +7 -4
- package/skills/create-spine-tasks/SKILL.md +2 -2
- package/skills/create-spine-tasks/references/contract-template.md +2 -0
- package/src/batch/contract-exec.mjs +14 -29
- package/src/batch/contract-review.mjs +266 -0
- package/src/batch/contract-spawn.mjs +31 -0
- package/src/batch/detached-wait.mjs +15 -8
- package/src/batch/diagnosis-primary-failure.mjs +28 -5
- package/src/batch/diagnosis-suggested-command.mjs +7 -0
- package/src/batch/engine-lanes/commit.mjs +4 -0
- package/src/batch/integrate.mjs +23 -3
- package/src/batch/journal-rebuild-drift.mjs +46 -1
- 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/lifecycle-archive.mjs +44 -0
- package/src/batch/review-scope.mjs +17 -4
- package/src/config/contract.mjs +40 -0
- package/src/config/settings-fields.mjs +50 -1
- package/src/config/spine-config-schema.mjs +32 -0
- package/src/config/worker-context.mjs +36 -15
- package/src/doctor/run-doctor-checks.mjs +2 -1
- package/src/doctor/stet-capacity.mjs +46 -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
|
@@ -66,22 +66,37 @@ export function resolveContextDocPath(projectRoot, relPath) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
+
* A path that was not loaded, with the reason it was skipped.
|
|
70
|
+
*
|
|
71
|
+
* @typedef {object} ContextDocSkip
|
|
72
|
+
* @property {string} path
|
|
73
|
+
* @property {"never_load"|"missing"|"byte_cap"} reason
|
|
74
|
+
* @property {number} [sizeBytes] UTF-8 size of the file, set for `byte_cap` skips.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* SP-852: a path whose content would exceed the remaining byte budget is
|
|
79
|
+
* recorded in `skipped` and loading continues, so one oversize rule no longer
|
|
80
|
+
* drops later rules that fit.
|
|
81
|
+
*
|
|
69
82
|
* @param {object} params
|
|
70
83
|
* @param {string} params.projectRoot
|
|
71
84
|
* @param {string[]} params.paths
|
|
72
85
|
* @param {Set<string>} [params.neverLoad]
|
|
73
86
|
* @param {number} [params.byteCap]
|
|
87
|
+
* @returns {{ ok: boolean, entries?: { relPath: string, content: string }[], truncated?: boolean, skipped?: ContextDocSkip[], bytesUsed?: number, byteCap?: number, error?: string, relPath?: string }}
|
|
74
88
|
*/
|
|
75
89
|
export function loadContextDocEntries({ projectRoot, paths, neverLoad = new Set(), byteCap = DEFAULT_WORKER_CONTEXT_BYTE_CAP }) {
|
|
76
90
|
/** @type {{ relPath: string, content: string }[]} */
|
|
77
91
|
const loaded = [];
|
|
78
92
|
let totalBytes = 0;
|
|
79
|
-
/** @type {
|
|
93
|
+
/** @type {ContextDocSkip[]} */
|
|
80
94
|
const skipped = [];
|
|
95
|
+
let capSkipped = false;
|
|
81
96
|
|
|
82
97
|
for (const relPath of paths) {
|
|
83
98
|
if (neverLoad.has(relPath)) {
|
|
84
|
-
skipped.push(relPath);
|
|
99
|
+
skipped.push({ path: relPath, reason: "never_load" });
|
|
85
100
|
continue;
|
|
86
101
|
}
|
|
87
102
|
|
|
@@ -91,21 +106,16 @@ export function loadContextDocEntries({ projectRoot, paths, neverLoad = new Set(
|
|
|
91
106
|
}
|
|
92
107
|
|
|
93
108
|
if (!fs.existsSync(resolved.absPath) || !fs.statSync(resolved.absPath).isFile()) {
|
|
94
|
-
skipped.push(relPath);
|
|
109
|
+
skipped.push({ path: relPath, reason: "missing" });
|
|
95
110
|
continue;
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
const content = fs.readFileSync(resolved.absPath, "utf-8");
|
|
99
114
|
const size = Buffer.byteLength(content, "utf-8");
|
|
100
115
|
if (totalBytes + size > byteCap) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
truncated: true,
|
|
105
|
-
skipped: [...skipped, relPath, "...remaining paths omitted (byte cap)"],
|
|
106
|
-
bytesUsed: totalBytes,
|
|
107
|
-
byteCap,
|
|
108
|
-
};
|
|
116
|
+
skipped.push({ path: relPath, reason: "byte_cap", sizeBytes: size });
|
|
117
|
+
capSkipped = true;
|
|
118
|
+
continue;
|
|
109
119
|
}
|
|
110
120
|
|
|
111
121
|
loaded.push({ relPath: resolved.relPath, content });
|
|
@@ -115,7 +125,7 @@ export function loadContextDocEntries({ projectRoot, paths, neverLoad = new Set(
|
|
|
115
125
|
return {
|
|
116
126
|
ok: true,
|
|
117
127
|
entries: loaded,
|
|
118
|
-
truncated:
|
|
128
|
+
truncated: capSkipped,
|
|
119
129
|
skipped,
|
|
120
130
|
bytesUsed: totalBytes,
|
|
121
131
|
byteCap,
|
|
@@ -223,7 +233,7 @@ export function emitWorkerRulesSelected(journal, payload) {
|
|
|
223
233
|
* @param {string[]} [params.taskFileScope]
|
|
224
234
|
* @param {number} [params.byteCap]
|
|
225
235
|
* @param {WorkerRulesJournalContext} [params.journal]
|
|
226
|
-
* @returns {{ text: string, entries: object[], truncated: boolean, skipped:
|
|
236
|
+
* @returns {{ text: string, entries: object[], truncated: boolean, skipped: ContextDocSkip[], bytesUsed: number, byteCap: number, selection: object, error?: string, blockedPath?: string }}
|
|
227
237
|
*/
|
|
228
238
|
export function buildWorkerContextAsync({
|
|
229
239
|
config = {},
|
|
@@ -303,7 +313,7 @@ export function buildWorkerContextAsync({
|
|
|
303
313
|
...referenceDocs.filter((entry) => !neverLoad.has(entry) && !selectedSet.has(entry)),
|
|
304
314
|
];
|
|
305
315
|
|
|
306
|
-
|
|
316
|
+
const journalPayload = {
|
|
307
317
|
mode: "auto",
|
|
308
318
|
manifestSource,
|
|
309
319
|
profileSource: profileResult.source,
|
|
@@ -318,9 +328,12 @@ export function buildWorkerContextAsync({
|
|
|
318
328
|
referenceDocCount: referenceDocs.filter(
|
|
319
329
|
(entry) => !neverLoad.has(entry) && !selectedSet.has(entry),
|
|
320
330
|
).length,
|
|
321
|
-
}
|
|
331
|
+
};
|
|
332
|
+
const emitPostLoad = (loadStats) =>
|
|
333
|
+
emitWorkerRulesSelected(journal, { ...journalPayload, ...loadStats });
|
|
322
334
|
|
|
323
335
|
if (orderedPaths.length === 0) {
|
|
336
|
+
emitPostLoad({ bytesUsed: 0, byteCap, truncated: false, skipped: [] });
|
|
324
337
|
return {
|
|
325
338
|
text: "",
|
|
326
339
|
entries: [],
|
|
@@ -344,6 +357,7 @@ export function buildWorkerContextAsync({
|
|
|
344
357
|
byteCap,
|
|
345
358
|
});
|
|
346
359
|
if (!loaded.ok) {
|
|
360
|
+
emitPostLoad({ bytesUsed: 0, byteCap, truncated: false, skipped: [] });
|
|
347
361
|
return {
|
|
348
362
|
text: "",
|
|
349
363
|
entries: [],
|
|
@@ -362,6 +376,13 @@ export function buildWorkerContextAsync({
|
|
|
362
376
|
};
|
|
363
377
|
}
|
|
364
378
|
|
|
379
|
+
emitPostLoad({
|
|
380
|
+
bytesUsed: loaded.bytesUsed,
|
|
381
|
+
byteCap: loaded.byteCap,
|
|
382
|
+
truncated: loaded.truncated,
|
|
383
|
+
skipped: loaded.skipped,
|
|
384
|
+
});
|
|
385
|
+
|
|
365
386
|
const parts = loaded.entries.map(
|
|
366
387
|
(entry) => `--- ${entry.relPath} ---\n${entry.content.trim()}\n`,
|
|
367
388
|
);
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
} from "./stall-config.mjs";
|
|
25
25
|
import { buildRulesManifestDoctorCheck } from "./rules-manifest.mjs";
|
|
26
26
|
import { buildAgentTemplateDriftDoctorCheck } from "./agent-template-drift.mjs";
|
|
27
|
-
import { buildStetCapacityDoctorCheck } from "./stet-capacity.mjs";
|
|
27
|
+
import { buildStetCapacityDoctorCheck, buildStetVersionDoctorCheck } from "./stet-capacity.mjs";
|
|
28
28
|
import { buildWorktreeHealthDoctorCheck } from "./worktree-health.mjs";
|
|
29
29
|
import { buildGitignoredPubspecAssetsDoctorCheck } from "../config/worktree-setup-hook.mjs";
|
|
30
30
|
import { buildStaleWorktreesDoctorCheck } from "./stale-worktrees.mjs";
|
|
@@ -539,6 +539,7 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
|
539
539
|
});
|
|
540
540
|
}
|
|
541
541
|
checks.push(buildAgentTemplateDriftDoctorCheck({ projectRoot }));
|
|
542
|
+
checks.push(buildStetVersionDoctorCheck());
|
|
542
543
|
checks.push(buildStetCapacityDoctorCheck());
|
|
543
544
|
|
|
544
545
|
const tasksRootPath = resolveTasksRoot(projectRoot, configResult);
|
|
@@ -114,6 +114,52 @@ export const DEFAULT_STET_CAPACITY_PROBES = {
|
|
|
114
114
|
totalMemBytes: () => os.totalmem(),
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
/** Contract gating needs `stet list --min-severity/--min-confidence`, added in stet v1.4.0. */
|
|
118
|
+
export const STET_MIN_VERSION = { major: 1, minor: 4, patch: 0 };
|
|
119
|
+
const STET_INSTALL_COMMAND = "curl -fsSL https://raw.githubusercontent.com/beettlle/stet/main/install.sh | bash";
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {string} text raw `stet --version` stdout, e.g. "stet version v1.4.0"
|
|
123
|
+
* @returns {StetSemVer|null}
|
|
124
|
+
*/
|
|
125
|
+
export function parseStetVersion(text) {
|
|
126
|
+
const match = /(\d+)\.(\d+)\.(\d+)/.exec(text);
|
|
127
|
+
return match ? { major: +match[1], minor: +match[2], patch: +match[3] } : null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @typedef {{ major: number, minor: number, patch: number }} StetSemVer */
|
|
131
|
+
|
|
132
|
+
/** Numeric per-component compare (1.10.0 ≥ 1.4.0; string compare would not). @param {StetSemVer} v @param {StetSemVer} min */
|
|
133
|
+
function atLeast(v, min) {
|
|
134
|
+
return v.major !== min.major ? v.major > min.major
|
|
135
|
+
: v.minor !== min.minor ? v.minor > min.minor
|
|
136
|
+
: v.patch >= min.patch;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Advisory doctor check: warns (never fails) when stet predates the version that
|
|
141
|
+
* contract gating needs (`stet list --min-severity/--min-confidence`, stet v1.4.0+).
|
|
142
|
+
* @param {{ stetVersion?: () => string|null }} [opts]
|
|
143
|
+
*/
|
|
144
|
+
export function buildStetVersionDoctorCheck(opts = {}) {
|
|
145
|
+
const probes = { stetVersion: () => tryExec("stet", ["--version"])?.trim() ?? null, ...opts };
|
|
146
|
+
const label = "stet version";
|
|
147
|
+
const raw = probes.stetVersion();
|
|
148
|
+
if (raw === null) return { label, ok: true, detail: "stet not on PATH (skipped)" };
|
|
149
|
+
const version = parseStetVersion(raw);
|
|
150
|
+
if (version !== null && atLeast(version, STET_MIN_VERSION)) {
|
|
151
|
+
return { label, ok: true, detail: `stet v${version.major}.${version.minor}.${version.patch}` };
|
|
152
|
+
}
|
|
153
|
+
const shown = raw.split("\n")[0].slice(0, 60) || "(no output)";
|
|
154
|
+
return {
|
|
155
|
+
label,
|
|
156
|
+
ok: true,
|
|
157
|
+
warning: true,
|
|
158
|
+
detail: `${shown}: older than or incompatible with stet v${STET_MIN_VERSION.major}.${STET_MIN_VERSION.minor}.${STET_MIN_VERSION.patch} — the contract gate falls back to gating on every active finding`,
|
|
159
|
+
suggestedCommand: STET_INSTALL_COMMAND,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
117
163
|
/** @param {number} bytes */
|
|
118
164
|
const gib = (bytes) => `${(bytes / (1024 * BYTES_PER_MIB)).toFixed(1)} GiB`;
|
|
119
165
|
|
|
@@ -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
|
-
}
|