pi-spine 1.4.0 → 1.6.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 +3 -2
- package/bin/spine.mjs +12 -0
- package/extensions/spine/slash-commands.ts +170 -1
- package/package.json +6 -3
- package/skills/create-spine-tasks/SKILL.md +13 -1
- package/skills/create-spine-tasks/references/contract-template.md +6 -3
- package/skills/create-spine-tasks/references/requirements-checklist-template.md +1 -0
- package/skills/spine-orchestrate-waves/SKILL.md +200 -0
- package/skills/spine-orchestrate-waves/references/outer-loop.md +165 -0
- package/skills/spine-release-operator/SKILL.md +341 -0
- package/skills/spine-release-operator/references/issue-intake-checklist.md +107 -0
- package/skills/spine-release-operator/references/issue-template.md +51 -0
- package/skills/spine-release-operator/references/release-manifest-template.md +76 -0
- package/skills/spine-release-operator/references/release-profiles.md +100 -0
- package/src/batch/batch-state-io.mjs +137 -0
- package/src/batch/contract-prelanded.mjs +116 -14
- package/src/batch/contract-verify.mjs +48 -2
- package/src/batch/diagnosis-alternatives.mjs +8 -0
- package/src/batch/diagnosis.mjs +28 -2
- package/src/batch/engine-lanes/commit.mjs +6 -0
- package/src/batch/engine.mjs +10 -1
- package/src/batch/integrate-worktree.mjs +65 -15
- package/src/batch/lane-dirty-check.mjs +124 -0
- package/src/batch/lifecycle.mjs +10 -6
- package/src/batch/reconcile.mjs +254 -0
- package/src/batch/sequence-waves.mjs +221 -0
- package/src/batch/sequence.mjs +117 -4
- package/src/batch/state.mjs +18 -1
- package/src/cli/batch-complete.mjs +16 -0
- package/src/cli/sync-base.mjs +354 -0
- package/src/config/defaults.mjs +8 -1
- package/src/config/spine-preflight-lib.mjs +146 -2
- package/src/doctor/agents-model-inherit.mjs +318 -0
- package/src/doctor/run-doctor-checks.mjs +14 -0
- package/templates/spine-config.json +4 -0
- package/templates/spine-worktree-setup-flutter.sh +44 -0
package/src/batch/engine.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { installAttachedEngineShutdownHandlers } from "./attached-engine-handoff
|
|
|
15
15
|
import { finalizeBatchForIntegrate, tryFinalizePostMergeLimbo } from "./post-merge-limbo.mjs";
|
|
16
16
|
import { detectPostMergeLimboForResume } from "./resume-multi-validate.mjs";
|
|
17
17
|
import { appendJournalEvent } from "./journal.mjs";
|
|
18
|
+
import { recordBatchBaseSnapshotOnStart } from "./lifecycle.mjs";
|
|
18
19
|
import { adoptPauseIfRequested, saveEngineBatchState } from "./pause.mjs";
|
|
19
20
|
import {
|
|
20
21
|
assertNoActiveBatch,
|
|
@@ -88,6 +89,13 @@ export function detectNestedWorkerContext(projectRoot) {
|
|
|
88
89
|
if (process.env.SPINE_IS_WORKER === "1") {
|
|
89
90
|
return "SPINE_IS_WORKER=1 is set (running inside a worker process)";
|
|
90
91
|
}
|
|
92
|
+
const parentBatchId = process.env.SPINE_PARENT_BATCH_ID ?? process.env.SPINE_BATCH_ID;
|
|
93
|
+
if (parentBatchId && WORKTREE_SPINE_PATTERN.test(projectRoot)) {
|
|
94
|
+
return (
|
|
95
|
+
`parent batch ${parentBatchId} is active and projectRoot is inside a ` +
|
|
96
|
+
`.worktrees/spine-* lane directory`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
91
99
|
if (WORKTREE_SPINE_PATTERN.test(projectRoot)) {
|
|
92
100
|
return "projectRoot is inside a .worktrees/spine-* lane directory";
|
|
93
101
|
}
|
|
@@ -113,7 +121,7 @@ export async function startBatch({
|
|
|
113
121
|
}) {
|
|
114
122
|
const nestedReason = detectNestedWorkerContext(projectRoot);
|
|
115
123
|
if (nestedReason) {
|
|
116
|
-
const parentBatchId = process.env.SPINE_BATCH_ID ?? "unknown";
|
|
124
|
+
const parentBatchId = process.env.SPINE_PARENT_BATCH_ID ?? process.env.SPINE_BATCH_ID ?? "unknown";
|
|
117
125
|
try {
|
|
118
126
|
appendJournalEvent(projectRoot, parentBatchId, "engine.nested_spawn_blocked", {
|
|
119
127
|
projectRoot,
|
|
@@ -243,6 +251,7 @@ export async function startBatch({
|
|
|
243
251
|
lanes,
|
|
244
252
|
});
|
|
245
253
|
|
|
254
|
+
recordBatchBaseSnapshotOnStart(projectRoot, state);
|
|
246
255
|
saveEngineBatchState(projectRoot, state);
|
|
247
256
|
|
|
248
257
|
try {
|
|
@@ -202,6 +202,44 @@ function gitWithTimeout(cwd, args, { timeoutMs } = {}) {
|
|
|
202
202
|
}).trim();
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* @param {string} message
|
|
207
|
+
*/
|
|
208
|
+
function debugSyncLog(message) {
|
|
209
|
+
if (process.env.DEBUG || process.env.SPINE_DEBUG) {
|
|
210
|
+
process.stderr.write(`${message}\n`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @param {unknown} err
|
|
216
|
+
* @returns {boolean}
|
|
217
|
+
*/
|
|
218
|
+
function isPathspecMismatchError(err) {
|
|
219
|
+
const stderr = err && typeof err === "object" && "stderr" in err ? String(err.stderr ?? "") : "";
|
|
220
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
221
|
+
return /pathspec.*did not match/i.test(`${message}\n${stderr}`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @param {string} cwd
|
|
226
|
+
* @param {string} treeRef
|
|
227
|
+
* @param {string} filePath
|
|
228
|
+
* @param {{ timeoutMs?: number }} [options]
|
|
229
|
+
* @returns {boolean}
|
|
230
|
+
*/
|
|
231
|
+
function pathExistsInTree(cwd, treeRef, filePath, { timeoutMs } = {}) {
|
|
232
|
+
try {
|
|
233
|
+
gitWithTimeout(cwd, ["cat-file", "-e", `${treeRef}:${filePath}`], { timeoutMs });
|
|
234
|
+
return true;
|
|
235
|
+
} catch (err) {
|
|
236
|
+
if (isTimeoutError(err)) {
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
205
243
|
/**
|
|
206
244
|
* Materialize paths introduced/changed by a plumbing merge without resetting human edits.
|
|
207
245
|
* Returns a result object so callers can detect timeout and emit integrate.failed.
|
|
@@ -236,45 +274,57 @@ export function syncPlumbingMergePathsToWorktree(projectRoot, baseSha, mergeComm
|
|
|
236
274
|
let processedCount = 0;
|
|
237
275
|
|
|
238
276
|
for (const filePath of paths) {
|
|
239
|
-
let
|
|
277
|
+
let existsInMerge = false;
|
|
240
278
|
try {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
{ timeoutMs: effectiveTimeout },
|
|
245
|
-
);
|
|
279
|
+
existsInMerge = pathExistsInTree(projectRoot, mergeCommit, filePath, {
|
|
280
|
+
timeoutMs: effectiveTimeout,
|
|
281
|
+
});
|
|
246
282
|
} catch (err) {
|
|
247
283
|
if (isTimeoutError(err)) {
|
|
248
284
|
return {
|
|
249
285
|
ok: false,
|
|
250
286
|
timedOut: true,
|
|
251
|
-
error: `git
|
|
287
|
+
error: `git cat-file timed out for ${filePath} after ${effectiveTimeout}ms`,
|
|
252
288
|
processedPaths: processedCount,
|
|
253
289
|
totalPaths: paths.length,
|
|
254
290
|
};
|
|
255
291
|
}
|
|
256
|
-
|
|
292
|
+
existsInMerge = false;
|
|
257
293
|
}
|
|
258
|
-
|
|
294
|
+
|
|
295
|
+
if (!existsInMerge) {
|
|
296
|
+
debugSyncLog(
|
|
297
|
+
`syncPlumbingMergePathsToWorktree: skip ${filePath} — not present in merge commit ${mergeCommit}`,
|
|
298
|
+
);
|
|
259
299
|
continue;
|
|
260
300
|
}
|
|
261
301
|
|
|
262
|
-
const absPath = path.join(projectRoot, filePath);
|
|
263
|
-
fs.mkdirSync(path.dirname(absPath), { recursive: true });
|
|
264
|
-
fs.writeFileSync(absPath, content.endsWith("\n") ? content : `${content}\n`, "utf-8");
|
|
265
|
-
|
|
266
302
|
try {
|
|
267
|
-
gitWithTimeout(
|
|
303
|
+
gitWithTimeout(
|
|
304
|
+
projectRoot,
|
|
305
|
+
["restore", "--source", mergeCommit, "--staged", "--worktree", "--", filePath],
|
|
306
|
+
{ timeoutMs: effectiveTimeout },
|
|
307
|
+
);
|
|
268
308
|
} catch (err) {
|
|
269
309
|
if (isTimeoutError(err)) {
|
|
270
310
|
return {
|
|
271
311
|
ok: false,
|
|
272
312
|
timedOut: true,
|
|
273
|
-
error: `git
|
|
313
|
+
error: `git restore timed out for ${filePath} after ${effectiveTimeout}ms`,
|
|
274
314
|
processedPaths: processedCount,
|
|
275
315
|
totalPaths: paths.length,
|
|
276
316
|
};
|
|
277
317
|
}
|
|
318
|
+
if (isPathspecMismatchError(err)) {
|
|
319
|
+
debugSyncLog(
|
|
320
|
+
`syncPlumbingMergePathsToWorktree: skip ${filePath} — pathspec did not match merge commit`,
|
|
321
|
+
);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
debugSyncLog(
|
|
325
|
+
`syncPlumbingMergePathsToWorktree: skip ${filePath} — ${err instanceof Error ? err.message : String(err)}`,
|
|
326
|
+
);
|
|
327
|
+
continue;
|
|
278
328
|
}
|
|
279
329
|
processedCount++;
|
|
280
330
|
}
|
|
@@ -16,6 +16,21 @@ import { runWorktreeSetupHook } from "./worktree.mjs";
|
|
|
16
16
|
*/
|
|
17
17
|
export const COVERAGE_ARTIFACT_MARKERS = ["/coverage/", "coverage/"];
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Path segments for gitignored build artifacts that npm test and similar tools
|
|
21
|
+
* regenerate in lane worktrees (SP-471 / #95).
|
|
22
|
+
*/
|
|
23
|
+
export const GITIGNORED_ARTIFACT_MARKERS = [
|
|
24
|
+
"/node_modules/",
|
|
25
|
+
"node_modules/",
|
|
26
|
+
"/coverage/",
|
|
27
|
+
"coverage/",
|
|
28
|
+
"/__pycache__/",
|
|
29
|
+
"__pycache__/",
|
|
30
|
+
"/graphify-out/",
|
|
31
|
+
"graphify-out/",
|
|
32
|
+
];
|
|
33
|
+
|
|
19
34
|
/**
|
|
20
35
|
* @param {string} filePath
|
|
21
36
|
* @returns {boolean}
|
|
@@ -359,6 +374,115 @@ export function resolveSetupHookSymlinkDriftPorcelain(
|
|
|
359
374
|
* @param {string[]} gitignoredPaths
|
|
360
375
|
* @returns {{ indexTracked: string[], worktreeOnly: string[] }}
|
|
361
376
|
*/
|
|
377
|
+
/**
|
|
378
|
+
* @param {string} filePath
|
|
379
|
+
* @returns {boolean}
|
|
380
|
+
*/
|
|
381
|
+
export function isGitignoredArtifactPath(filePath) {
|
|
382
|
+
if (!filePath || typeof filePath !== "string") return false;
|
|
383
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
384
|
+
return GITIGNORED_ARTIFACT_MARKERS.some(
|
|
385
|
+
(marker) =>
|
|
386
|
+
normalized === marker.slice(0, -1) ||
|
|
387
|
+
normalized.startsWith(marker) ||
|
|
388
|
+
normalized.includes(marker),
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* @param {string} filePath
|
|
394
|
+
* @returns {string | null}
|
|
395
|
+
*/
|
|
396
|
+
function gitignoredArtifactRootForPath(filePath) {
|
|
397
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
398
|
+
for (const marker of ["/node_modules/", "/coverage/", "/__pycache__/", "/graphify-out/"]) {
|
|
399
|
+
const markerIdx = normalized.indexOf(marker);
|
|
400
|
+
if (markerIdx >= 0) {
|
|
401
|
+
return normalized.slice(0, markerIdx + marker.length - 1);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (normalized === "node_modules" || normalized.startsWith("node_modules/")) {
|
|
405
|
+
return "node_modules";
|
|
406
|
+
}
|
|
407
|
+
if (normalized === "coverage" || normalized.startsWith("coverage/")) {
|
|
408
|
+
return "coverage";
|
|
409
|
+
}
|
|
410
|
+
if (normalized === "__pycache__" || normalized.startsWith("__pycache__/")) {
|
|
411
|
+
return "__pycache__";
|
|
412
|
+
}
|
|
413
|
+
if (normalized === "graphify-out" || normalized.startsWith("graphify-out/")) {
|
|
414
|
+
return "graphify-out";
|
|
415
|
+
}
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @param {string[]} filePaths
|
|
421
|
+
* @returns {string[]}
|
|
422
|
+
*/
|
|
423
|
+
export function listGitignoredArtifactRoots(filePaths) {
|
|
424
|
+
const roots = new Set();
|
|
425
|
+
for (const filePath of filePaths) {
|
|
426
|
+
if (!isGitignoredArtifactPath(filePath)) continue;
|
|
427
|
+
const root = gitignoredArtifactRootForPath(filePath);
|
|
428
|
+
if (root) roots.add(root);
|
|
429
|
+
}
|
|
430
|
+
return [...roots].sort();
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* @param {string} worktreePath
|
|
435
|
+
* @returns {string[]}
|
|
436
|
+
*/
|
|
437
|
+
function listIgnoredUntrackedPaths(worktreePath) {
|
|
438
|
+
let output = "";
|
|
439
|
+
try {
|
|
440
|
+
output = execFileSync("git", ["ls-files", "-o", "-i", "--exclude-standard"], {
|
|
441
|
+
cwd: worktreePath,
|
|
442
|
+
encoding: "utf-8",
|
|
443
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
444
|
+
}).trim();
|
|
445
|
+
} catch {
|
|
446
|
+
return [];
|
|
447
|
+
}
|
|
448
|
+
if (!output) return [];
|
|
449
|
+
return output.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Auto-clean worktree-only gitignored artifacts under known dirs before lane dirty gate.
|
|
454
|
+
*
|
|
455
|
+
* @param {string} worktreePath
|
|
456
|
+
* @param {{ projectRoot?: string, porcelain?: string, enabled?: boolean }} [options]
|
|
457
|
+
* @returns {{ cleanedRoots: string[] }}
|
|
458
|
+
*/
|
|
459
|
+
export function sanitizeGitignoredArtifactsBeforeLaneCommit(
|
|
460
|
+
worktreePath,
|
|
461
|
+
{ projectRoot, porcelain, enabled = true } = {},
|
|
462
|
+
) {
|
|
463
|
+
if (!enabled) return { cleanedRoots: [] };
|
|
464
|
+
|
|
465
|
+
const identityRoot = projectRoot ?? worktreePath;
|
|
466
|
+
const rawPorcelain = typeof porcelain === "string" ? porcelain : "";
|
|
467
|
+
const dirtyPaths = listPorcelainPaths(rawPorcelain);
|
|
468
|
+
const ignoredUntrackedPaths = listIgnoredUntrackedPaths(worktreePath);
|
|
469
|
+
const gitignoredCandidates = [...new Set([...dirtyPaths, ...ignoredUntrackedPaths])];
|
|
470
|
+
if (gitignoredCandidates.length === 0) {
|
|
471
|
+
return { cleanedRoots: [] };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const { worktreeOnly } = classifyGitignoredPaths(worktreePath, gitignoredCandidates);
|
|
475
|
+
const artifactRoots = listGitignoredArtifactRoots(worktreeOnly);
|
|
476
|
+
for (const root of artifactRoots) {
|
|
477
|
+
gitExec(worktreePath, ["clean", "-fdX", "--", root], {
|
|
478
|
+
projectRoot: identityRoot,
|
|
479
|
+
throwOnError: false,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return { cleanedRoots: artifactRoots };
|
|
484
|
+
}
|
|
485
|
+
|
|
362
486
|
export function classifyGitignoredPaths(worktreePath, gitignoredPaths) {
|
|
363
487
|
if (!Array.isArray(gitignoredPaths) || gitignoredPaths.length === 0) {
|
|
364
488
|
return { indexTracked: [], worktreeOnly: [] };
|
package/src/batch/lifecycle.mjs
CHANGED
|
@@ -16,11 +16,16 @@ import {
|
|
|
16
16
|
saveSpineBatchState,
|
|
17
17
|
} from "./state.mjs";
|
|
18
18
|
import { loadBatchStateFile, parseBatchState, reconcileBatch } from "./reconcile.mjs";
|
|
19
|
+
import {
|
|
20
|
+
clearActiveBatchStateIfMatches,
|
|
21
|
+
} from "./batch-state-io.mjs";
|
|
19
22
|
import { terminateLaneWorkers } from "./worker-host.mjs";
|
|
20
23
|
import { removeLaneWorktrees } from "./worktree.mjs";
|
|
21
24
|
|
|
22
25
|
const DISMISS_ALLOWED = new Set(["limbo_stale", "completed_manual", "aborted"]);
|
|
23
26
|
|
|
27
|
+
export { recordBatchBaseSnapshot as recordBatchBaseSnapshotOnStart } from "./integrate-worktree.mjs";
|
|
28
|
+
|
|
24
29
|
/**
|
|
25
30
|
* Terminal merge-blocked state when the engine exits after a wave merge failure (GitHub #38).
|
|
26
31
|
* Clears stale enginePid so status does not imply an in-progress merge.
|
|
@@ -106,11 +111,10 @@ function archiveBatchState(projectRoot, batchId, raw) {
|
|
|
106
111
|
|
|
107
112
|
/**
|
|
108
113
|
* @param {string|null} batchStatePath
|
|
114
|
+
* @param {string} batchId
|
|
109
115
|
*/
|
|
110
|
-
function
|
|
111
|
-
|
|
112
|
-
fs.unlinkSync(batchStatePath);
|
|
113
|
-
}
|
|
116
|
+
function clearCompletedBatchState(batchStatePath, batchId) {
|
|
117
|
+
clearActiveBatchStateIfMatches(batchStatePath, batchId);
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
/**
|
|
@@ -309,7 +313,7 @@ export function dismissBatch(ctx) {
|
|
|
309
313
|
batchState: loaded.raw,
|
|
310
314
|
config,
|
|
311
315
|
});
|
|
312
|
-
|
|
316
|
+
clearCompletedBatchState(loaded.path, batchId);
|
|
313
317
|
|
|
314
318
|
return {
|
|
315
319
|
ok: true,
|
|
@@ -476,7 +480,7 @@ export function completeBatch(ctx) {
|
|
|
476
480
|
batchState: loaded.raw,
|
|
477
481
|
config,
|
|
478
482
|
});
|
|
479
|
-
|
|
483
|
+
clearCompletedBatchState(loaded.path, batchId);
|
|
480
484
|
|
|
481
485
|
return {
|
|
482
486
|
ok: true,
|
package/src/batch/reconcile.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { execFileSync } from "node:child_process";
|
|
|
8
8
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
9
9
|
import { PACKAGE_ROOT } from "../config/spine-init-constants.mjs";
|
|
10
10
|
import { resolveTasksRootPath } from "../config/env-overrides.mjs";
|
|
11
|
+
import { resolveCurrentGitBranch } from "../config/spine-preflight-lib.mjs";
|
|
11
12
|
import { buildStalePathDoctorCheck } from "../doctor/stale-path.mjs";
|
|
12
13
|
import { loadGateRecord } from "./gate.mjs";
|
|
13
14
|
import { deriveMacroPhase, macroPhaseLabel } from "./macro-phase.mjs";
|
|
@@ -40,6 +41,7 @@ import { isProcessAlive } from "../process/liveness.mjs";
|
|
|
40
41
|
import {
|
|
41
42
|
loadBatchStateFile,
|
|
42
43
|
parseBatchState,
|
|
44
|
+
readBaseBranchHeadAtStart,
|
|
43
45
|
} from "./batch-state-io.mjs";
|
|
44
46
|
import {
|
|
45
47
|
clearBatchEnginePid,
|
|
@@ -294,6 +296,239 @@ export function inspectGitState(ctx) {
|
|
|
294
296
|
return result;
|
|
295
297
|
}
|
|
296
298
|
|
|
299
|
+
/**
|
|
300
|
+
* @typedef {object} HumanBaseSyncInspection
|
|
301
|
+
* @property {"human_base_diverged"|"integrate_isolated_ok"} diagnosis
|
|
302
|
+
* @property {string} headline
|
|
303
|
+
* @property {string[]} [overlapPaths]
|
|
304
|
+
* @property {string} [humanHead]
|
|
305
|
+
* @property {string} [baseTip]
|
|
306
|
+
* @property {string|null} [orchBranch]
|
|
307
|
+
* @property {boolean} [preIntegrate]
|
|
308
|
+
*/
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @param {string} projectRoot
|
|
312
|
+
* @param {string} refA
|
|
313
|
+
* @param {string} refB
|
|
314
|
+
* @returns {string[]}
|
|
315
|
+
*/
|
|
316
|
+
export function listGitChangedPaths(projectRoot, refA, refB) {
|
|
317
|
+
if (!refA || !refB || refA === refB) return [];
|
|
318
|
+
try {
|
|
319
|
+
const output = execFileSync("git", ["diff", "--name-only", `${refA}..${refB}`], {
|
|
320
|
+
cwd: projectRoot,
|
|
321
|
+
encoding: "utf-8",
|
|
322
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
323
|
+
timeout: 5000,
|
|
324
|
+
});
|
|
325
|
+
return output
|
|
326
|
+
.split(/\r?\n/)
|
|
327
|
+
.map((line) => line.trim())
|
|
328
|
+
.filter(Boolean);
|
|
329
|
+
} catch {
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Paths touched by human commits on base since batch snapshot, excluding orch ancestry.
|
|
336
|
+
*
|
|
337
|
+
* @param {string} projectRoot
|
|
338
|
+
* @param {string} snapshot
|
|
339
|
+
* @param {string} humanHead
|
|
340
|
+
* @param {string|null} orchBranch
|
|
341
|
+
* @returns {string[]}
|
|
342
|
+
*/
|
|
343
|
+
export function listHumanOnlyPaths(projectRoot, snapshot, humanHead, orchBranch) {
|
|
344
|
+
if (!snapshot || !humanHead || snapshot === humanHead) return [];
|
|
345
|
+
const args = ["log", "--name-only", "--pretty=format:", `${snapshot}..${humanHead}`];
|
|
346
|
+
if (orchBranch && gitRefExists(projectRoot, orchBranch)) {
|
|
347
|
+
args.push("--not", orchBranch);
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
const output = execFileSync("git", args, {
|
|
351
|
+
cwd: projectRoot,
|
|
352
|
+
encoding: "utf-8",
|
|
353
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
354
|
+
timeout: 5000,
|
|
355
|
+
});
|
|
356
|
+
return [...new Set(output.split(/\r?\n/).map((line) => line.trim()).filter(Boolean))];
|
|
357
|
+
} catch {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @param {string} projectRoot
|
|
364
|
+
* @param {string} ref
|
|
365
|
+
* @param {string} filePath
|
|
366
|
+
*/
|
|
367
|
+
function pathExistsAtRef(projectRoot, ref, filePath) {
|
|
368
|
+
try {
|
|
369
|
+
execFileSync("git", ["cat-file", "-e", `${ref}:${filePath}`], {
|
|
370
|
+
cwd: projectRoot,
|
|
371
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
372
|
+
timeout: 5000,
|
|
373
|
+
});
|
|
374
|
+
return true;
|
|
375
|
+
} catch {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @param {string} projectRoot
|
|
382
|
+
* @param {string} baseTip
|
|
383
|
+
* @param {string} snapshot
|
|
384
|
+
* @returns {boolean}
|
|
385
|
+
*/
|
|
386
|
+
function humanCheckoutNeedsPathSync(projectRoot, baseTip, snapshot) {
|
|
387
|
+
const landPaths = listGitChangedPaths(projectRoot, snapshot, baseTip);
|
|
388
|
+
for (const filePath of landPaths) {
|
|
389
|
+
if (!pathExistsAtRef(projectRoot, baseTip, filePath)) continue;
|
|
390
|
+
if (!fs.existsSync(path.join(projectRoot, filePath))) {
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Detect human/base divergence or post-isolated-integrate sync need (FR-WT-08 / #91).
|
|
399
|
+
*
|
|
400
|
+
* @param {object} ctx
|
|
401
|
+
* @param {string} ctx.projectRoot
|
|
402
|
+
* @param {string} ctx.baseBranch
|
|
403
|
+
* @param {string} ctx.baseBranchHeadAtStart
|
|
404
|
+
* @param {string|null} ctx.orchBranch
|
|
405
|
+
* @param {ReturnType<typeof inspectGitState>} ctx.git
|
|
406
|
+
* @param {object[]} [ctx.journalEvents]
|
|
407
|
+
* @returns {HumanBaseSyncInspection|null}
|
|
408
|
+
*/
|
|
409
|
+
export function inspectHumanBaseSync(ctx) {
|
|
410
|
+
const { projectRoot, baseBranch, baseBranchHeadAtStart, orchBranch, git, journalEvents } = ctx;
|
|
411
|
+
if (!git?.inGitRepo) return null;
|
|
412
|
+
|
|
413
|
+
const snapshot = String(baseBranchHeadAtStart ?? "").trim();
|
|
414
|
+
if (!snapshot) return null;
|
|
415
|
+
|
|
416
|
+
let baseTip = "";
|
|
417
|
+
let humanHead = "";
|
|
418
|
+
try {
|
|
419
|
+
baseTip = execFileSync("git", ["rev-parse", baseBranch], {
|
|
420
|
+
cwd: projectRoot,
|
|
421
|
+
encoding: "utf-8",
|
|
422
|
+
timeout: 5000,
|
|
423
|
+
}).trim();
|
|
424
|
+
humanHead = execFileSync("git", ["rev-parse", "HEAD"], {
|
|
425
|
+
cwd: projectRoot,
|
|
426
|
+
encoding: "utf-8",
|
|
427
|
+
timeout: 5000,
|
|
428
|
+
}).trim();
|
|
429
|
+
} catch {
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const integrateCompleted = Array.isArray(journalEvents)
|
|
434
|
+
? journalEvents.some((event) => event.type === "integrate.completed")
|
|
435
|
+
: false;
|
|
436
|
+
const landSucceeded =
|
|
437
|
+
git.orchMergedToBase ||
|
|
438
|
+
integrateCompleted ||
|
|
439
|
+
(baseTip !== snapshot && gitIsAncestor(projectRoot, snapshot, baseTip));
|
|
440
|
+
|
|
441
|
+
const resolvedOrch =
|
|
442
|
+
orchBranch && gitRefExists(projectRoot, orchBranch)
|
|
443
|
+
? orchBranch
|
|
444
|
+
: git.mergedOrchBranch && gitRefExists(projectRoot, git.mergedOrchBranch)
|
|
445
|
+
? git.mergedOrchBranch
|
|
446
|
+
: null;
|
|
447
|
+
|
|
448
|
+
const branchResult = resolveCurrentGitBranch(projectRoot);
|
|
449
|
+
const onBaseBranch = branchResult.branch === baseBranch;
|
|
450
|
+
|
|
451
|
+
const humanSinceSnapshot =
|
|
452
|
+
onBaseBranch &&
|
|
453
|
+
gitIsAncestor(projectRoot, snapshot, humanHead) &&
|
|
454
|
+
humanHead !== snapshot;
|
|
455
|
+
const humanPaths = humanSinceSnapshot
|
|
456
|
+
? listHumanOnlyPaths(projectRoot, snapshot, humanHead, resolvedOrch)
|
|
457
|
+
: [];
|
|
458
|
+
const landPaths = landSucceeded ? listGitChangedPaths(projectRoot, snapshot, baseTip) : [];
|
|
459
|
+
const orchPaths =
|
|
460
|
+
resolvedOrch && gitRefExists(projectRoot, resolvedOrch)
|
|
461
|
+
? listGitChangedPaths(projectRoot, snapshot, resolvedOrch)
|
|
462
|
+
: landPaths;
|
|
463
|
+
const overlapPaths = humanPaths.filter((filePath) => orchPaths.includes(filePath));
|
|
464
|
+
|
|
465
|
+
if (overlapPaths.length > 0) {
|
|
466
|
+
return {
|
|
467
|
+
diagnosis: "human_base_diverged",
|
|
468
|
+
headline: onBaseBranch
|
|
469
|
+
? `Human commits on ${baseBranch} overlap orch land (${overlapPaths.length} path(s))`
|
|
470
|
+
: `Human commits overlap orch land (${overlapPaths.length} path(s))`,
|
|
471
|
+
overlapPaths,
|
|
472
|
+
humanHead,
|
|
473
|
+
baseTip,
|
|
474
|
+
orchBranch: resolvedOrch,
|
|
475
|
+
preIntegrate: !landSucceeded,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (!landSucceeded) return null;
|
|
480
|
+
|
|
481
|
+
const needsCommitSync =
|
|
482
|
+
humanHead !== baseTip && onBaseBranch && gitIsAncestor(projectRoot, humanHead, baseTip);
|
|
483
|
+
const needsPathSync =
|
|
484
|
+
onBaseBranch && humanHead === baseTip && humanCheckoutNeedsPathSync(projectRoot, baseTip, snapshot);
|
|
485
|
+
|
|
486
|
+
if (!needsCommitSync && !needsPathSync) {
|
|
487
|
+
if (!onBaseBranch) {
|
|
488
|
+
const mergeBase = (() => {
|
|
489
|
+
try {
|
|
490
|
+
return execFileSync("git", ["merge-base", humanHead, baseTip], {
|
|
491
|
+
cwd: projectRoot,
|
|
492
|
+
encoding: "utf-8",
|
|
493
|
+
timeout: 5000,
|
|
494
|
+
}).trim();
|
|
495
|
+
} catch {
|
|
496
|
+
return "";
|
|
497
|
+
}
|
|
498
|
+
})();
|
|
499
|
+
if (mergeBase && mergeBase !== baseTip && gitIsAncestor(projectRoot, mergeBase, baseTip)) {
|
|
500
|
+
return {
|
|
501
|
+
diagnosis: "integrate_isolated_ok",
|
|
502
|
+
headline: `${baseBranch} advanced during batch; feature branch needs sync`,
|
|
503
|
+
humanHead,
|
|
504
|
+
baseTip,
|
|
505
|
+
orchBranch: resolvedOrch,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return {
|
|
513
|
+
diagnosis: "integrate_isolated_ok",
|
|
514
|
+
headline: needsPathSync
|
|
515
|
+
? `Isolated integrate landed on ${baseBranch}; working tree needs path sync`
|
|
516
|
+
: `Isolated integrate landed on ${baseBranch}; checkout needs sync`,
|
|
517
|
+
humanHead,
|
|
518
|
+
baseTip,
|
|
519
|
+
orchBranch: resolvedOrch,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const HUMAN_SYNC_OVERRIDE_DIAGNOSES = new Set([
|
|
524
|
+
"completed",
|
|
525
|
+
"completed_manual",
|
|
526
|
+
"needs_integrate",
|
|
527
|
+
"limbo_stale",
|
|
528
|
+
"running",
|
|
529
|
+
"paused",
|
|
530
|
+
]);
|
|
531
|
+
|
|
297
532
|
/**
|
|
298
533
|
* @param {unknown} rawTasks
|
|
299
534
|
* @param {string|null} failedTaskId
|
|
@@ -888,6 +1123,19 @@ export function reconcileBatch(ctx) {
|
|
|
888
1123
|
failedTaskId = stubSucceededTaskId;
|
|
889
1124
|
exitReason = "stub";
|
|
890
1125
|
}
|
|
1126
|
+
|
|
1127
|
+
const humanBaseSync = inspectHumanBaseSync({
|
|
1128
|
+
projectRoot,
|
|
1129
|
+
baseBranch: batch.baseBranch,
|
|
1130
|
+
baseBranchHeadAtStart: readBaseBranchHeadAtStart(batch.raw),
|
|
1131
|
+
orchBranch: batch.orchBranch,
|
|
1132
|
+
git,
|
|
1133
|
+
journalEvents,
|
|
1134
|
+
});
|
|
1135
|
+
if (humanBaseSync && HUMAN_SYNC_OVERRIDE_DIAGNOSES.has(diagnosis)) {
|
|
1136
|
+
diagnosis = humanBaseSync.diagnosis;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
891
1139
|
const doneMissingHint =
|
|
892
1140
|
diagnosis === "worker_done_missing"
|
|
893
1141
|
? inferWorkerDoneMissingFailure({
|
|
@@ -1006,8 +1254,14 @@ export function reconcileBatch(ctx) {
|
|
|
1006
1254
|
tasksRoot,
|
|
1007
1255
|
macroPhase,
|
|
1008
1256
|
...(doneMissingContext ?? {}),
|
|
1257
|
+
humanBaseSync,
|
|
1258
|
+
overlapPaths: humanBaseSync?.overlapPaths ?? [],
|
|
1009
1259
|
});
|
|
1010
1260
|
|
|
1261
|
+
if (humanBaseSync && (diagnosis === "human_base_diverged" || diagnosis === "integrate_isolated_ok")) {
|
|
1262
|
+
output.headline = humanBaseSync.headline;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1011
1265
|
if (diagnosis === "git_unavailable") {
|
|
1012
1266
|
output.headline = `Batch ${batch.batchId} — git inspection failed: ${git.gitInspectionError}`;
|
|
1013
1267
|
output.suggestedCommand = "spine doctor";
|