pi-spine 2.4.0 → 2.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.mjs +22 -0
- package/package.json +1 -1
- package/src/batch/attached-runner-promote.mjs +95 -11
- package/src/batch/blocker-codes.mjs +63 -0
- package/src/batch/diagnosis-alternatives.mjs +18 -0
- package/src/batch/diagnosis-gate-ready.mjs +23 -0
- package/src/batch/diagnosis-pending-lane.mjs +63 -0
- package/src/batch/diagnosis-retry-command.mjs +23 -0
- package/src/batch/diagnosis-tail-state.mjs +68 -0
- package/src/batch/diagnosis.mjs +69 -52
- package/src/batch/engine-lanes/commit.mjs +2 -0
- package/src/batch/engine-lanes.mjs +2 -3
- package/src/batch/evidence-command.mjs +125 -4
- package/src/batch/gate-posture-approve.mjs +345 -0
- package/src/batch/gate-posture-defaults.mjs +64 -0
- package/src/batch/gate-posture-evaluate.mjs +133 -0
- package/src/batch/gate-posture-streak.mjs +290 -0
- package/src/batch/gate-revision.mjs +95 -0
- package/src/batch/gate.mjs +89 -117
- package/src/batch/integrate.mjs +1 -0
- package/src/batch/lane-commit.mjs +77 -8
- package/src/batch/lifecycle-archive.mjs +71 -0
- package/src/batch/lifecycle.mjs +27 -67
- package/src/batch/orphan-detect.mjs +68 -5
- package/src/batch/post-merge-limbo.mjs +137 -22
- package/src/batch/reconcile-batch.mjs +40 -43
- package/src/batch/reconcile-diagnosis-context.mjs +88 -0
- package/src/batch/reconcile-diagnosis.mjs +14 -32
- package/src/batch/resume-multi-validate.mjs +51 -9
- package/src/batch/retry.mjs +18 -2
- package/src/batch/sequence-wait.mjs +20 -6
- package/src/config/gate-posture-config.mjs +190 -0
- package/src/config/pi-spine-root.mjs +22 -0
- package/src/config/spine-config-load.mjs +33 -0
- package/src/doctor/duplicate-install.mjs +100 -0
- package/src/doctor/run-doctor-checks.mjs +10 -1
- package/src/doctor/worktree-health.mjs +4 -0
- package/templates/spine-config.json +3 -2
|
@@ -7,11 +7,8 @@ import { buildStalePathDoctorCheck } from "../doctor/stale-path.mjs";
|
|
|
7
7
|
import { PACKAGE_ROOT } from "../config/spine-init-constants.mjs";
|
|
8
8
|
import { loadGateRecord } from "./gate-evidence-read.mjs";
|
|
9
9
|
import { deriveMacroPhase, macroPhaseLabel } from "./macro-phase.mjs";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
inferMergeGitignoredFailure,
|
|
13
|
-
isGateReadyHeadlineContext,
|
|
14
|
-
} from "./diagnosis.mjs";
|
|
10
|
+
import { buildDiagnosisOutput, inferMergeGitignoredFailure } from "./diagnosis.mjs";
|
|
11
|
+
import { isGateReadyHeadlineContext } from "./diagnosis-gate-ready.mjs";
|
|
15
12
|
import {
|
|
16
13
|
classifyTasks,
|
|
17
14
|
inspectGitState,
|
|
@@ -47,6 +44,7 @@ import {
|
|
|
47
44
|
} from "./batch-state-io.mjs";
|
|
48
45
|
import { readBatchEnginePid } from "./state.mjs";
|
|
49
46
|
import {
|
|
47
|
+
buildReconcileDiagnosisContext,
|
|
50
48
|
deriveDiagnosis,
|
|
51
49
|
enrichLaunchFailureFromWorkerOutput,
|
|
52
50
|
enrichWorkerDoneMissingContext,
|
|
@@ -395,49 +393,48 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
395
393
|
const enginePid = readBatchEnginePid(batch.raw);
|
|
396
394
|
const staleEnginePid =
|
|
397
395
|
enginePid != null && !isProcessAlive(enginePid);
|
|
396
|
+
const engineStillRunning = enginePid != null && !staleEnginePid;
|
|
398
397
|
const engineOrphanCause =
|
|
399
398
|
diagnosis === "engine_orphaned"
|
|
400
399
|
? inferEngineOrphanCause({ journalEvents, staleEnginePid })
|
|
401
400
|
: null;
|
|
402
401
|
|
|
403
|
-
const output = buildDiagnosisOutput(
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
overlapPaths: humanBaseSync?.overlapPaths ?? [],
|
|
440
|
-
});
|
|
402
|
+
const output = buildDiagnosisOutput(
|
|
403
|
+
diagnosis,
|
|
404
|
+
buildReconcileDiagnosisContext({
|
|
405
|
+
batch,
|
|
406
|
+
git,
|
|
407
|
+
signals,
|
|
408
|
+
classifiedTasks,
|
|
409
|
+
diagnosis,
|
|
410
|
+
failedTaskId,
|
|
411
|
+
driftTaskStatus,
|
|
412
|
+
exitReason,
|
|
413
|
+
resolvedLaunchFailureKind,
|
|
414
|
+
pendingTaskCount,
|
|
415
|
+
salvageChangedFileCount,
|
|
416
|
+
salvageRetryCommand,
|
|
417
|
+
ghostRunningCluster,
|
|
418
|
+
integrateGateOpen,
|
|
419
|
+
stalePathSpine,
|
|
420
|
+
planReviewNestedSpawnBlocked,
|
|
421
|
+
mergeGitignoredFailure,
|
|
422
|
+
mergeFailedForHeadline,
|
|
423
|
+
mergeFailureSummary,
|
|
424
|
+
taskBranch,
|
|
425
|
+
gitignoredPaths,
|
|
426
|
+
hasRunningTasks,
|
|
427
|
+
hasPendingTasks,
|
|
428
|
+
macroPhase,
|
|
429
|
+
reviewHonorSignal,
|
|
430
|
+
doneMissingContext,
|
|
431
|
+
engineOrphanCause,
|
|
432
|
+
staleEnginePid,
|
|
433
|
+
enginePid,
|
|
434
|
+
engineStillRunning,
|
|
435
|
+
humanBaseSync,
|
|
436
|
+
}),
|
|
437
|
+
);
|
|
441
438
|
|
|
442
439
|
if (humanBaseSync && (diagnosis === "human_base_diverged" || diagnosis === "integrate_isolated_ok")) {
|
|
443
440
|
output.headline = humanBaseSync.headline;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/** Diagnosis output context after reconcile signal enrichment (#201 / SP-645). */
|
|
3
|
+
|
|
4
|
+
import { findPendingLaneLandTasks } from "./diagnosis-pending-lane.mjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {object} params
|
|
8
|
+
*/
|
|
9
|
+
export function buildReconcileDiagnosisContext(params) {
|
|
10
|
+
const {
|
|
11
|
+
batch,
|
|
12
|
+
git,
|
|
13
|
+
signals,
|
|
14
|
+
classifiedTasks,
|
|
15
|
+
diagnosis: _diagnosis,
|
|
16
|
+
failedTaskId,
|
|
17
|
+
driftTaskStatus,
|
|
18
|
+
exitReason,
|
|
19
|
+
resolvedLaunchFailureKind,
|
|
20
|
+
pendingTaskCount,
|
|
21
|
+
salvageChangedFileCount,
|
|
22
|
+
salvageRetryCommand,
|
|
23
|
+
ghostRunningCluster,
|
|
24
|
+
integrateGateOpen,
|
|
25
|
+
stalePathSpine,
|
|
26
|
+
planReviewNestedSpawnBlocked,
|
|
27
|
+
mergeGitignoredFailure,
|
|
28
|
+
mergeFailedForHeadline,
|
|
29
|
+
mergeFailureSummary,
|
|
30
|
+
taskBranch,
|
|
31
|
+
gitignoredPaths,
|
|
32
|
+
hasRunningTasks,
|
|
33
|
+
hasPendingTasks,
|
|
34
|
+
macroPhase,
|
|
35
|
+
reviewHonorSignal,
|
|
36
|
+
doneMissingContext,
|
|
37
|
+
engineOrphanCause,
|
|
38
|
+
staleEnginePid,
|
|
39
|
+
enginePid,
|
|
40
|
+
engineStillRunning,
|
|
41
|
+
humanBaseSync,
|
|
42
|
+
} = params;
|
|
43
|
+
|
|
44
|
+
const pendingLaneLandTasks = findPendingLaneLandTasks(classifiedTasks);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
batchId: batch.batchId,
|
|
48
|
+
baseBranch: batch.baseBranch ?? git.baseBranch ?? "main",
|
|
49
|
+
pendingLaneLandTasks,
|
|
50
|
+
phase: batch.phase,
|
|
51
|
+
failedTasks: signals.failedTasks,
|
|
52
|
+
failedTaskId,
|
|
53
|
+
driftTaskStatus,
|
|
54
|
+
exitReason,
|
|
55
|
+
launchFailureKind: resolvedLaunchFailureKind,
|
|
56
|
+
gitMerged: git.orchMergedToBase,
|
|
57
|
+
pendingTaskCount,
|
|
58
|
+
salvageChangedFileCount,
|
|
59
|
+
salvageRetryCommand,
|
|
60
|
+
ghostRunningCluster,
|
|
61
|
+
postMergeLimbo: signals.postMergeLimbo === true,
|
|
62
|
+
integrateGateOpen,
|
|
63
|
+
stalePathSpine,
|
|
64
|
+
planReviewNestedSpawnBlocked,
|
|
65
|
+
mergeGitignoredFailure,
|
|
66
|
+
mergeFailed: mergeFailedForHeadline,
|
|
67
|
+
failedWaveIndex: mergeFailureSummary.failedWaveIndex,
|
|
68
|
+
failedLane: mergeFailureSummary.failedLane,
|
|
69
|
+
lastError: mergeFailureSummary.lastError,
|
|
70
|
+
succeededTasks: batch.succeededTasks,
|
|
71
|
+
totalTasks: batch.totalTasks,
|
|
72
|
+
taskBranch,
|
|
73
|
+
gitignoredPaths,
|
|
74
|
+
hasRunningTasks,
|
|
75
|
+
hasPendingTasks,
|
|
76
|
+
allTasksTerminalSuccess: signals.allTasksTerminalSuccess,
|
|
77
|
+
tasksRoot: signals.tasksRoot,
|
|
78
|
+
macroPhase,
|
|
79
|
+
reviewHonorSignal,
|
|
80
|
+
...(doneMissingContext ?? {}),
|
|
81
|
+
engineOrphanCause,
|
|
82
|
+
staleEnginePid,
|
|
83
|
+
enginePid,
|
|
84
|
+
engineStillRunning,
|
|
85
|
+
humanBaseSync,
|
|
86
|
+
overlapPaths: humanBaseSync?.overlapPaths ?? [],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
/** Diagnosis derivation (SP-596/SP-606 / #192). */
|
|
3
3
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
+
import { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis.mjs";
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./diagnosis.mjs";
|
|
7
|
+
findPendingLaneLandTasks,
|
|
8
|
+
shouldDiagnosePendingLaneLand,
|
|
9
|
+
} from "./diagnosis-pending-lane.mjs";
|
|
9
10
|
import { inferWorkerDoneMissingFailure } from "./diagnosis-worker-done-missing.mjs";
|
|
10
11
|
import { inferStubExitReasonForTask } from "./diagnosis-stub.mjs";
|
|
11
12
|
import { workerOutputLogPath, workerOutputLogRef } from "./worker-output.mjs";
|
|
12
|
-
import { journalEventsSinceResume } from "./orphan-detect.mjs";
|
|
13
13
|
import { isPostMergeLimbo } from "./limbo-detect.mjs";
|
|
14
|
-
import { isProcessAlive } from "../process/liveness.mjs";
|
|
15
|
-
import { readBatchEnginePid } from "./state.mjs";
|
|
16
14
|
import {
|
|
17
15
|
LIMBO_PHASES,
|
|
18
16
|
RUNNING_PHASES,
|
|
19
17
|
} from "./reconcile-light-cache.mjs";
|
|
18
|
+
export { buildReconcileDiagnosisContext } from "./reconcile-diagnosis-context.mjs";
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @param {unknown} rawTasks
|
|
@@ -241,22 +240,6 @@ function withFailureContext(diagnosis, failedTaskId, signals, exitReason = null)
|
|
|
241
240
|
};
|
|
242
241
|
}
|
|
243
242
|
|
|
244
|
-
/**
|
|
245
|
-
* @param {object[]} journalEvents
|
|
246
|
-
* @param {Record<string, unknown>|null|undefined} raw
|
|
247
|
-
* @param {string|null} taskId
|
|
248
|
-
*/
|
|
249
|
-
function journalIndicatesResumeRulesStall(journalEvents, raw, taskId) {
|
|
250
|
-
const scoped = journalEventsSinceResume(journalEvents, raw);
|
|
251
|
-
const hasRulesSelected = scoped.some((event) => {
|
|
252
|
-
if (event.type !== "worker.rules_selected") return false;
|
|
253
|
-
const eventTaskId = event.taskId ?? event.payload?.taskId;
|
|
254
|
-
return !taskId || !eventTaskId || eventTaskId === taskId;
|
|
255
|
-
});
|
|
256
|
-
const hasBatchResumed = scoped.some((event) => event.type === "batch.resumed");
|
|
257
|
-
return hasRulesSelected && hasBatchResumed;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
243
|
/**
|
|
261
244
|
* @param {object} signals
|
|
262
245
|
*/
|
|
@@ -300,21 +283,20 @@ export function deriveDiagnosis(signals) {
|
|
|
300
283
|
|
|
301
284
|
if (orphanRunning) {
|
|
302
285
|
if (orphanRunning.kind === "lane" && orphanRunning.taskId) {
|
|
303
|
-
const enginePid = readBatchEnginePid(signals.raw);
|
|
304
|
-
const engineDead = enginePid == null || !isProcessAlive(enginePid);
|
|
305
|
-
const resumeRulesStall = journalIndicatesResumeRulesStall(
|
|
306
|
-
signals.journalEvents ?? [],
|
|
307
|
-
signals.raw,
|
|
308
|
-
orphanRunning.taskId,
|
|
309
|
-
);
|
|
310
|
-
if (engineDead && resumeRulesStall) {
|
|
311
|
-
return withFailureContext("engine_orphaned", orphanRunning.taskId, signals);
|
|
312
|
-
}
|
|
313
286
|
return withFailureContext("worker_orphaned", orphanRunning.taskId, signals);
|
|
314
287
|
}
|
|
315
288
|
return withFailureContext("engine_orphaned", orphanRunning.taskId ?? null, signals);
|
|
316
289
|
}
|
|
317
290
|
|
|
291
|
+
if (shouldDiagnosePendingLaneLand(signals)) {
|
|
292
|
+
const pendingLaneLandTasks = findPendingLaneLandTasks(signals.tasks);
|
|
293
|
+
return withFailureContext(
|
|
294
|
+
"pending_lane_land",
|
|
295
|
+
pendingLaneLandTasks[0]?.taskId ?? null,
|
|
296
|
+
signals,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
318
300
|
if (signals.stateDrift?.drifted) {
|
|
319
301
|
const driftTask = signals.stateDrift.entries.find((entry) => entry.taskId !== "*");
|
|
320
302
|
return withFailureContext("state_drift", driftTask?.taskId ?? null, signals);
|
|
@@ -61,24 +61,66 @@ export function detectPostMergeLimboForResume({ projectRoot, state }) {
|
|
|
61
61
|
export { hasPendingWaveMerge } from "./merge/wave-merge-state.mjs";
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Terminal-success evidence for force-resume eligibility (#196 / #197).
|
|
65
|
+
* Prefer classification / done* markers over raw `status === "succeeded"` only —
|
|
66
|
+
* diagnose and salvage use the same signals when the status cache lags.
|
|
67
|
+
*
|
|
68
|
+
* @param {object|null|undefined} task
|
|
69
|
+
*/
|
|
70
|
+
function isTerminalSuccessForResume(task) {
|
|
71
|
+
const status = String(task?.status ?? "").toLowerCase();
|
|
72
|
+
if (status === "succeeded" || status === "skipped") return true;
|
|
73
|
+
if (task?.doneInLane === true || task?.doneFileFound === true || task?.doneOnMain === true) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return String(task?.classification ?? "").toLowerCase() === "terminal-success";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Whether every task is terminal-success (or skipped) for drift recovery (#196 / #197).
|
|
65
81
|
*
|
|
66
82
|
* @param {object|null|undefined} state
|
|
67
83
|
*/
|
|
68
84
|
function allTasksTerminalSuccessForResume(state) {
|
|
69
85
|
const tasks = state?.tasks ?? [];
|
|
70
86
|
if (tasks.length < 1) return false;
|
|
71
|
-
return tasks.every((task) =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
return tasks.every((task) => isTerminalSuccessForResume(task));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Pending wave merge for resume eligibility.
|
|
92
|
+
*
|
|
93
|
+
* Status-only `hasPendingWaveMerge` misses #197 when tasks are still `status: running`
|
|
94
|
+
* but classification / doneInLane already show terminal success. In that case treat any
|
|
95
|
+
* wave without a succeeded mergeResults row as pending merge (same intent as
|
|
96
|
+
* findFirstWaveNeedingMerge, without widening wave-merge-state blast radius).
|
|
97
|
+
*
|
|
98
|
+
* @param {object|null|undefined} state
|
|
99
|
+
*/
|
|
100
|
+
function hasPendingWaveMergeForResume(state) {
|
|
101
|
+
if (hasPendingWaveMerge(state)) return true;
|
|
102
|
+
if (!allTasksTerminalSuccessForResume(state)) return false;
|
|
103
|
+
const wavePlan = state?.wavePlan ?? [];
|
|
104
|
+
if (wavePlan.length < 1) return false;
|
|
105
|
+
const mergeResults = state?.mergeResults ?? [];
|
|
106
|
+
const succeeded = new Set(
|
|
107
|
+
mergeResults
|
|
108
|
+
.filter((entry) => String(entry?.status ?? "").toLowerCase() === "succeeded")
|
|
109
|
+
.map((entry) => Number(entry.waveIndex))
|
|
110
|
+
.filter((waveIndex) => Number.isFinite(waveIndex)),
|
|
111
|
+
);
|
|
112
|
+
for (let waveIndex = 0; waveIndex < wavePlan.length; waveIndex++) {
|
|
113
|
+
if (!succeeded.has(waveIndex)) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
75
116
|
}
|
|
76
117
|
|
|
77
118
|
/**
|
|
78
119
|
* Assess whether a running-phase batch may resume after a dead detached engine (SP-296).
|
|
79
120
|
*
|
|
80
|
-
* Also covers SP-613 / #196: pidless engine + all tasks terminal-success
|
|
81
|
-
*
|
|
121
|
+
* Also covers SP-613 / #196 and SP-635 / #197: pidless engine + all tasks terminal-success
|
|
122
|
+
* (status healed or classification/doneInLane) + pending wave merge must not dead-end on
|
|
123
|
+
* phase=running.
|
|
82
124
|
*
|
|
83
125
|
* @param {object} params
|
|
84
126
|
* @param {string} params.projectRoot
|
|
@@ -101,11 +143,11 @@ export function assessRunningPhaseResumeEligibility({ projectRoot, state }) {
|
|
|
101
143
|
const enginePid = readBatchEnginePid(state);
|
|
102
144
|
const enginePidDead = enginePid != null && !isProcessAlive(enginePid);
|
|
103
145
|
const pidlessEngineOrphan = enginePid == null && orphanRunning?.kind === "engine";
|
|
104
|
-
// Dead/missing engine with work finished but merge not landed — agent-safe detached resume (#196).
|
|
146
|
+
// Dead/missing engine with work finished but merge not landed — agent-safe detached resume (#196 / #197).
|
|
105
147
|
const pidlessTerminalSuccessPendingMerge =
|
|
106
148
|
enginePid == null &&
|
|
107
149
|
allTasksTerminalSuccessForResume(state) &&
|
|
108
|
-
|
|
150
|
+
hasPendingWaveMergeForResume(state);
|
|
109
151
|
const engineConfirmedDead =
|
|
110
152
|
enginePidDead || pidlessEngineOrphan || pidlessTerminalSuccessPendingMerge;
|
|
111
153
|
|
package/src/batch/retry.mjs
CHANGED
|
@@ -18,6 +18,16 @@ import {
|
|
|
18
18
|
const RETRY_ALLOWED_PHASES = new Set(["paused", "failed"]);
|
|
19
19
|
const RETRY_BLOCKED_PHASES = new Set(["running", "planning"]);
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Fail running tasks and clear dead engine/worker PIDs before retry/skip (#203 / SP-647).
|
|
23
|
+
*
|
|
24
|
+
* @param {string} projectRoot
|
|
25
|
+
* @param {object} state
|
|
26
|
+
*/
|
|
27
|
+
function reconcileOrphanBeforeTaskMutation(projectRoot, state) {
|
|
28
|
+
return reconcileOrphanRunningState({ projectRoot, state });
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
/**
|
|
22
32
|
* @param {object} state
|
|
23
33
|
* @param {string} taskId
|
|
@@ -115,7 +125,7 @@ export function retryTask({ projectRoot, taskId }) {
|
|
|
115
125
|
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
116
126
|
}
|
|
117
127
|
|
|
118
|
-
|
|
128
|
+
reconcileOrphanBeforeTaskMutation(projectRoot, loaded.raw);
|
|
119
129
|
|
|
120
130
|
const reloaded = loadSpineBatchState(projectRoot);
|
|
121
131
|
const state = reloaded.raw;
|
|
@@ -255,7 +265,13 @@ export function skipTask({ projectRoot, taskId }) {
|
|
|
255
265
|
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
256
266
|
}
|
|
257
267
|
|
|
258
|
-
|
|
268
|
+
reconcileOrphanBeforeTaskMutation(projectRoot, loaded.raw);
|
|
269
|
+
|
|
270
|
+
const reloaded = loadSpineBatchState(projectRoot);
|
|
271
|
+
const state = reloaded.raw;
|
|
272
|
+
if (!state) {
|
|
273
|
+
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
274
|
+
}
|
|
259
275
|
const phase = String(state.phase ?? "");
|
|
260
276
|
|
|
261
277
|
if (RETRY_BLOCKED_PHASES.has(phase)) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
6
6
|
import { DEFAULT_SEQUENCE_POLL_MS } from "../config/spine-config-schema.mjs";
|
|
7
7
|
import { isProcessAlive } from "../process/liveness.mjs";
|
|
8
|
-
import { approveIntegrateGate, loadGateRecord } from "./gate.mjs";
|
|
8
|
+
import { approveIntegrateGate, loadGateRecord, maybeAutoApproveIntegrateGate } from "./gate.mjs";
|
|
9
9
|
import { integrateOrchToBase } from "./integrate.mjs";
|
|
10
10
|
import { completeBatch } from "./lifecycle.mjs";
|
|
11
11
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
@@ -127,7 +127,14 @@ export function runSequenceWaveLandLoop({ projectRoot, batchId, autoApproveGate
|
|
|
127
127
|
const gate = activeBatchId ? loadGateRecord(projectRoot, activeBatchId) : null;
|
|
128
128
|
|
|
129
129
|
if (gateRequired && gate?.status === "pending") {
|
|
130
|
-
|
|
130
|
+
const postureAuto = maybeAutoApproveIntegrateGate({
|
|
131
|
+
projectRoot,
|
|
132
|
+
batchId: activeBatchId,
|
|
133
|
+
config,
|
|
134
|
+
});
|
|
135
|
+
if (postureAuto.approved) {
|
|
136
|
+
// Posture opt-in allowed auto-approve; continue to integrate.
|
|
137
|
+
} else if (!autoApproveGate) {
|
|
131
138
|
return {
|
|
132
139
|
ok: false,
|
|
133
140
|
step: "gate_approve",
|
|
@@ -136,11 +143,18 @@ export function runSequenceWaveLandLoop({ projectRoot, batchId, autoApproveGate
|
|
|
136
143
|
batchId: activeBatchId,
|
|
137
144
|
headline: "Integrate gate requires approval — pass autoApproveGate or approve manually",
|
|
138
145
|
suggestedCommand: "spine gate approve",
|
|
146
|
+
postureEvaluation: postureAuto.evaluation ?? null,
|
|
139
147
|
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
} else {
|
|
149
|
+
// Blunt --auto-approve-gate path (still gated by validateSequenceAutoApproveGate upstream).
|
|
150
|
+
const approve = approveIntegrateGate({
|
|
151
|
+
projectRoot,
|
|
152
|
+
batchId: activeBatchId,
|
|
153
|
+
decidedBy: "auto",
|
|
154
|
+
});
|
|
155
|
+
if (!approve.ok) {
|
|
156
|
+
return { ok: false, step: "gate_approve", diagnosis, batchId: activeBatchId, ...approve };
|
|
157
|
+
}
|
|
144
158
|
}
|
|
145
159
|
}
|
|
146
160
|
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Resolve gate postures from spine-config with fail-closed defaults (SP-629 / FR-REL250-07 / #123).
|
|
4
|
+
* Invalid or missing overlay never unlocks locked categories and never rejects whole config load.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_POSTURES,
|
|
9
|
+
GATE_CATEGORIES,
|
|
10
|
+
LOCKED_CATEGORIES,
|
|
11
|
+
POSTURES,
|
|
12
|
+
} from "../batch/gate-posture-defaults.mjs";
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("../batch/gate-posture-defaults.mjs").GateCategory} GateCategory */
|
|
15
|
+
/** @typedef {import("../batch/gate-posture-defaults.mjs").GatePosture} GatePosture */
|
|
16
|
+
/** @typedef {import("../batch/gate-posture-defaults.mjs").CategoryPostureDefault} CategoryPostureDefault */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* categories: Readonly<Record<GateCategory, Readonly<CategoryPostureDefault>>>,
|
|
21
|
+
* alwaysBreakOn: ReadonlyArray<string>,
|
|
22
|
+
* }} GatePostureConfig
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const KNOWN_POSTURES = new Set(Object.values(POSTURES));
|
|
26
|
+
const LOCKED_SET = new Set(/** @type {GateCategory[]} */ ([...LOCKED_CATEGORIES]));
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {unknown} value
|
|
30
|
+
* @returns {value is Record<string, unknown>}
|
|
31
|
+
*/
|
|
32
|
+
function isPlainObject(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Fail-closed locked entry used for unknown postures and locked categories.
|
|
38
|
+
* @returns {Readonly<CategoryPostureDefault>}
|
|
39
|
+
*/
|
|
40
|
+
function lockedEntry() {
|
|
41
|
+
return Object.freeze({ posture: POSTURES.LOCKED, autoApproveAfterN: null });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Clone DEFAULT_POSTURES into a mutable record for overlay.
|
|
46
|
+
* @returns {Record<GateCategory, CategoryPostureDefault>}
|
|
47
|
+
*/
|
|
48
|
+
function cloneDefaults() {
|
|
49
|
+
/** @type {Record<GateCategory, CategoryPostureDefault>} */
|
|
50
|
+
const out = /** @type {Record<GateCategory, CategoryPostureDefault>} */ ({});
|
|
51
|
+
for (const category of GATE_CATEGORIES) {
|
|
52
|
+
const entry = DEFAULT_POSTURES[category];
|
|
53
|
+
out[category] = { posture: entry.posture, autoApproveAfterN: entry.autoApproveAfterN };
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {unknown} raw
|
|
60
|
+
* @returns {Readonly<CategoryPostureDefault>}
|
|
61
|
+
*/
|
|
62
|
+
function normalizeCategoryEntry(raw) {
|
|
63
|
+
if (!isPlainObject(raw)) {
|
|
64
|
+
return lockedEntry();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const postureRaw = raw.posture;
|
|
68
|
+
if (typeof postureRaw !== "string" || !KNOWN_POSTURES.has(/** @type {GatePosture} */ (postureRaw))) {
|
|
69
|
+
return lockedEntry();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const posture = /** @type {GatePosture} */ (postureRaw);
|
|
73
|
+
if (posture === POSTURES.LOCKED) {
|
|
74
|
+
return lockedEntry();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const thresholdRaw = raw.autoApproveAfterN;
|
|
78
|
+
if (thresholdRaw === undefined) {
|
|
79
|
+
return Object.freeze({ posture, autoApproveAfterN: 0 });
|
|
80
|
+
}
|
|
81
|
+
if (
|
|
82
|
+
typeof thresholdRaw !== "number" ||
|
|
83
|
+
!Number.isInteger(thresholdRaw) ||
|
|
84
|
+
thresholdRaw < 0
|
|
85
|
+
) {
|
|
86
|
+
return lockedEntry();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return Object.freeze({ posture, autoApproveAfterN: thresholdRaw });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Accept string tags only; invalid shapes fail closed to [].
|
|
94
|
+
* @param {unknown} raw
|
|
95
|
+
* @returns {string[]}
|
|
96
|
+
*/
|
|
97
|
+
function normalizeAlwaysBreakOn(raw) {
|
|
98
|
+
if (raw == null) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
if (!Array.isArray(raw)) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
/** @type {string[]} */
|
|
105
|
+
const tags = [];
|
|
106
|
+
for (const entry of raw) {
|
|
107
|
+
if (typeof entry === "string" && entry.trim() !== "") {
|
|
108
|
+
tags.push(entry.trim());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return tags;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Locate optional postures overlay and alwaysBreakOn from spine-config.
|
|
116
|
+
* Supports `gates.postures` map and `alwaysBreakOn` on `gates` or under `gates.postures`.
|
|
117
|
+
*
|
|
118
|
+
* @param {unknown} config
|
|
119
|
+
* @returns {{ overlay: Record<string, unknown> | null, alwaysBreakOnRaw: unknown }}
|
|
120
|
+
*/
|
|
121
|
+
function extractPostureSection(config) {
|
|
122
|
+
if (!isPlainObject(config)) {
|
|
123
|
+
return { overlay: null, alwaysBreakOnRaw: undefined };
|
|
124
|
+
}
|
|
125
|
+
const gates = config.gates;
|
|
126
|
+
if (!isPlainObject(gates)) {
|
|
127
|
+
return { overlay: null, alwaysBreakOnRaw: undefined };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const posturesRaw = gates.postures;
|
|
131
|
+
/** @type {unknown} */
|
|
132
|
+
let alwaysBreakOnRaw = gates.alwaysBreakOn;
|
|
133
|
+
|
|
134
|
+
if (posturesRaw == null) {
|
|
135
|
+
return { overlay: null, alwaysBreakOnRaw };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!isPlainObject(posturesRaw)) {
|
|
139
|
+
// Invalid postures container — fail closed: ignore overlay, keep alwaysBreakOn if present.
|
|
140
|
+
return { overlay: null, alwaysBreakOnRaw };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (alwaysBreakOnRaw === undefined && "alwaysBreakOn" in posturesRaw) {
|
|
144
|
+
alwaysBreakOnRaw = posturesRaw.alwaysBreakOn;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { overlay: posturesRaw, alwaysBreakOnRaw };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Merge optional `gates.postures` / `gates.alwaysBreakOn` over DEFAULT_POSTURES.
|
|
152
|
+
* Missing config → defaults. Unknown posture / invalid threshold → locked.
|
|
153
|
+
* destroy/auth stay locked even if config tries to relax them.
|
|
154
|
+
*
|
|
155
|
+
* @param {unknown} config Parsed spine-config (or partial with `gates`)
|
|
156
|
+
* @returns {GatePostureConfig}
|
|
157
|
+
*/
|
|
158
|
+
export function resolveGatePostureConfig(config) {
|
|
159
|
+
const { overlay, alwaysBreakOnRaw } = extractPostureSection(config);
|
|
160
|
+
const categories = cloneDefaults();
|
|
161
|
+
|
|
162
|
+
if (overlay) {
|
|
163
|
+
for (const category of GATE_CATEGORIES) {
|
|
164
|
+
if (!(category in overlay)) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (LOCKED_SET.has(category)) {
|
|
168
|
+
categories[category] = lockedEntry();
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
categories[category] = normalizeCategoryEntry(overlay[category]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Hard fail-closed: locked categories never leave locked.
|
|
176
|
+
for (const category of LOCKED_CATEGORIES) {
|
|
177
|
+
categories[category] = lockedEntry();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** @type {Record<GateCategory, Readonly<CategoryPostureDefault>>} */
|
|
181
|
+
const frozenCategories = /** @type {Record<GateCategory, Readonly<CategoryPostureDefault>>} */ ({});
|
|
182
|
+
for (const category of GATE_CATEGORIES) {
|
|
183
|
+
frozenCategories[category] = Object.freeze(categories[category]);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return Object.freeze({
|
|
187
|
+
categories: Object.freeze(frozenCategories),
|
|
188
|
+
alwaysBreakOn: Object.freeze(normalizeAlwaysBreakOn(alwaysBreakOnRaw)),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
@@ -30,6 +30,28 @@ function realpathOrResolve(root) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Default `PI_SPINE_ROOT` to cwd when unset/empty so CLI doctor/preflight
|
|
35
|
+
* do not require a manual export (SP-643 / #203). Does not override an
|
|
36
|
+
* explicit env value. Worker package-root resolution stays in
|
|
37
|
+
* {@link resolvePiSpineRoot}.
|
|
38
|
+
*
|
|
39
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
40
|
+
* @param {string} [cwd]
|
|
41
|
+
* @returns {string} Effective `PI_SPINE_ROOT` after ensure
|
|
42
|
+
*/
|
|
43
|
+
export function ensureDefaultPiSpineRootEnv(
|
|
44
|
+
env = process.env,
|
|
45
|
+
cwd = process.cwd(),
|
|
46
|
+
) {
|
|
47
|
+
const current = env.PI_SPINE_ROOT;
|
|
48
|
+
if (typeof current === "string" && current.trim()) {
|
|
49
|
+
return current.trim();
|
|
50
|
+
}
|
|
51
|
+
env.PI_SPINE_ROOT = cwd;
|
|
52
|
+
return cwd;
|
|
53
|
+
}
|
|
54
|
+
|
|
33
55
|
/**
|
|
34
56
|
* @param {object} [config]
|
|
35
57
|
* @param {string} [projectRoot]
|