pi-spine 2.2.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/spine-cli/verify.mjs +15 -46
- package/package.json +1 -1
- package/src/batch/attached-runner-promote.mjs +370 -0
- package/src/batch/attached-runner-reconcile.mjs +291 -0
- package/src/batch/attached-runner.mjs +24 -645
- package/src/batch/batch-guards.mjs +69 -0
- package/src/batch/contract-exec.mjs +483 -0
- package/src/batch/contract-parse.mjs +243 -0
- package/src/batch/contract-verify.mjs +32 -707
- package/src/batch/detached-diagnostics.mjs +255 -0
- package/src/batch/detached-run.mjs +326 -0
- package/src/batch/detached-start.mjs +18 -894
- package/src/batch/detached-wait.mjs +346 -0
- package/src/batch/diagnosis.mjs +35 -4
- package/src/batch/engine-lanes/orch-sync.mjs +126 -0
- package/src/batch/engine-lanes.mjs +69 -0
- package/src/batch/engine.mjs +8 -67
- package/src/batch/integrate-git.mjs +21 -0
- package/src/batch/integrate.mjs +5 -15
- package/src/batch/journal-rebuild-structural.mjs +352 -0
- package/src/batch/journal-rebuild.mjs +16 -348
- package/src/batch/lane-dirty-check-commit.mjs +361 -0
- package/src/batch/lane-dirty-check-git.mjs +298 -0
- package/src/batch/lane-dirty-check.mjs +31 -297
- package/src/batch/reconcile-batch.mjs +495 -0
- package/src/batch/reconcile-classify.mjs +433 -0
- package/src/batch/reconcile-diagnosis.mjs +459 -0
- package/src/batch/reconcile-light-cache.mjs +61 -0
- package/src/batch/reconcile-orphan.mjs +198 -0
- package/src/batch/reconcile.mjs +19 -1693
- package/src/batch/resume-multi-lanes.mjs +6 -148
- package/src/batch/resume-multi-queue.mjs +159 -0
- package/src/batch/resume-single-validate.mjs +25 -0
- package/src/batch/resume.mjs +3 -20
- package/src/batch/review-artifacts.mjs +419 -0
- package/src/batch/review-step-run.mjs +383 -0
- package/src/batch/review-step.mjs +451 -0
- package/src/batch/review.mjs +32 -1199
- package/src/batch/salvage-batch-list.mjs +291 -0
- package/src/batch/salvage-batch.mjs +10 -284
- package/src/batch/sequence-plan.mjs +234 -0
- package/src/batch/sequence-run.mjs +418 -0
- package/src/batch/sequence-wait.mjs +167 -0
- package/src/batch/sequence.mjs +22 -783
- package/src/batch/state-guards.mjs +284 -0
- package/src/batch/state-io.mjs +135 -0
- package/src/batch/state.mjs +27 -396
- package/src/batch/worker-heartbeat.mjs +382 -0
- package/src/batch/worker-host.mjs +56 -548
- package/src/batch/worker-spawn.mjs +326 -0
- package/src/batch/worktree.mjs +68 -0
- package/src/config/preflight/integrate-plan.mjs +6 -1
- package/src/config/preflight/loc-capstone.mjs +274 -0
- package/src/config/spine-preflight-lib.mjs +14 -0
- package/src/planner/index.mjs +14 -3
- package/src/process/terminate-tree.mjs +154 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sequence wait/land helpers: batch terminal poll and wave land loop (SP-600).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
6
|
+
import { DEFAULT_SEQUENCE_POLL_MS } from "../config/spine-config-schema.mjs";
|
|
7
|
+
import { isProcessAlive } from "../process/liveness.mjs";
|
|
8
|
+
import { approveIntegrateGate, loadGateRecord } from "./gate.mjs";
|
|
9
|
+
import { integrateOrchToBase } from "./integrate.mjs";
|
|
10
|
+
import { completeBatch } from "./lifecycle.mjs";
|
|
11
|
+
import { reconcileBatch } from "./reconcile.mjs";
|
|
12
|
+
import { loadSpineBatchState } from "./state.mjs";
|
|
13
|
+
|
|
14
|
+
const WAVE_BATCH_SETTLED_DIAGNOSES = new Set([
|
|
15
|
+
"completed",
|
|
16
|
+
"completed_manual",
|
|
17
|
+
"needs_integrate",
|
|
18
|
+
"limbo_stale",
|
|
19
|
+
]);
|
|
20
|
+
const WAVE_BATCH_FAILURE_DIAGNOSES = new Set(["failed", "aborted"]);
|
|
21
|
+
const WAVE_BATCH_WAITING_DIAGNOSES = new Set([
|
|
22
|
+
"running",
|
|
23
|
+
"paused",
|
|
24
|
+
"needs_retry",
|
|
25
|
+
"worker_orphaned",
|
|
26
|
+
"engine_orphaned",
|
|
27
|
+
"state_drift",
|
|
28
|
+
"needs_merge",
|
|
29
|
+
"needs_replan",
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
function sleep(ms) {
|
|
33
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isSequenceBatchSettled(diagnosis) {
|
|
37
|
+
return Boolean(diagnosis && WAVE_BATCH_SETTLED_DIAGNOSES.has(diagnosis));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function isSequenceBatchFailure(diagnosis) {
|
|
41
|
+
return Boolean(diagnosis && WAVE_BATCH_FAILURE_DIAGNOSES.has(diagnosis));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function isSequenceBatchWaiting(diagnosis) {
|
|
45
|
+
return Boolean(diagnosis && WAVE_BATCH_WAITING_DIAGNOSES.has(diagnosis));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function waitForSequenceBatchTerminal({
|
|
49
|
+
projectRoot,
|
|
50
|
+
pollIntervalMs = DEFAULT_SEQUENCE_POLL_MS,
|
|
51
|
+
timeoutMs = 120_000,
|
|
52
|
+
enginePid = null,
|
|
53
|
+
reconcileFn = reconcileBatch,
|
|
54
|
+
}) {
|
|
55
|
+
const deadline = Date.now() + timeoutMs;
|
|
56
|
+
let useLightReconcile = false;
|
|
57
|
+
while (Date.now() < deadline || isEngineStillRunning(enginePid, projectRoot)) {
|
|
58
|
+
const reconciliation = reconcileFn({ projectRoot, light: useLightReconcile });
|
|
59
|
+
useLightReconcile = true;
|
|
60
|
+
const diagnosis = reconciliation.diagnosis;
|
|
61
|
+
if (isSequenceBatchFailure(diagnosis)) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
halted: true,
|
|
65
|
+
diagnosis,
|
|
66
|
+
reconciliation,
|
|
67
|
+
batchId: reconciliation.batchId ?? null,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (isSequenceBatchSettled(diagnosis)) {
|
|
71
|
+
return {
|
|
72
|
+
ok: true,
|
|
73
|
+
diagnosis,
|
|
74
|
+
reconciliation,
|
|
75
|
+
batchId: reconciliation.batchId ?? null,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
await sleep(pollIntervalMs);
|
|
79
|
+
}
|
|
80
|
+
const reconciliation = reconcileFn({ projectRoot });
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
error: "timeout_waiting_for_batch",
|
|
84
|
+
diagnosis: reconciliation.diagnosis ?? null,
|
|
85
|
+
reconciliation,
|
|
86
|
+
batchId: reconciliation.batchId ?? null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns true when a detached engine PID is alive or the batch phase is active,
|
|
92
|
+
* preventing sequence timeout while work is still in progress.
|
|
93
|
+
*/
|
|
94
|
+
function isEngineStillRunning(enginePid, projectRoot) {
|
|
95
|
+
if (enginePid && isProcessAlive(enginePid)) return true;
|
|
96
|
+
const { raw } = loadSpineBatchState(projectRoot);
|
|
97
|
+
const pid = raw?.enginePid ?? null;
|
|
98
|
+
if (pid && isProcessAlive(pid)) return true;
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {object} params
|
|
104
|
+
* @param {string} params.projectRoot
|
|
105
|
+
* @param {string|null} params.batchId
|
|
106
|
+
* @param {boolean} [params.autoApproveGate]
|
|
107
|
+
*/
|
|
108
|
+
export function runSequenceWaveLandLoop({ projectRoot, batchId, autoApproveGate = false }) {
|
|
109
|
+
const reconciliation = reconcileBatch({ projectRoot });
|
|
110
|
+
const diagnosis = reconciliation.diagnosis;
|
|
111
|
+
const activeBatchId =
|
|
112
|
+
batchId ?? reconciliation.batchId ?? loadSpineBatchState(projectRoot).raw?.batchId ?? null;
|
|
113
|
+
|
|
114
|
+
if (!isSequenceBatchSettled(diagnosis)) {
|
|
115
|
+
return {
|
|
116
|
+
ok: false,
|
|
117
|
+
step: "land_loop",
|
|
118
|
+
error: "batch_not_settled",
|
|
119
|
+
diagnosis,
|
|
120
|
+
batchId: activeBatchId,
|
|
121
|
+
headline: `Cannot land wave — batch diagnosis is ${diagnosis ?? "unknown"}`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const config = loadSpineConfig(projectRoot).config ?? {};
|
|
126
|
+
const gateRequired = config.gates?.requireBeforeIntegrate !== false;
|
|
127
|
+
const gate = activeBatchId ? loadGateRecord(projectRoot, activeBatchId) : null;
|
|
128
|
+
|
|
129
|
+
if (gateRequired && gate?.status === "pending") {
|
|
130
|
+
if (!autoApproveGate) {
|
|
131
|
+
return {
|
|
132
|
+
ok: false,
|
|
133
|
+
step: "gate_approve",
|
|
134
|
+
error: "gate_approval_required",
|
|
135
|
+
diagnosis,
|
|
136
|
+
batchId: activeBatchId,
|
|
137
|
+
headline: "Integrate gate requires approval — pass autoApproveGate or approve manually",
|
|
138
|
+
suggestedCommand: "spine gate approve",
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const approve = approveIntegrateGate({ projectRoot, batchId: activeBatchId });
|
|
142
|
+
if (!approve.ok) {
|
|
143
|
+
return { ok: false, step: "gate_approve", diagnosis, batchId: activeBatchId, ...approve };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const integrate = integrateOrchToBase({ projectRoot, batchId: activeBatchId });
|
|
148
|
+
if (!integrate.ok) {
|
|
149
|
+
return { ok: false, step: "integrate", diagnosis, batchId: activeBatchId, ...integrate };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const complete = completeBatch({ projectRoot, batchId: activeBatchId });
|
|
153
|
+
if (!complete.ok) {
|
|
154
|
+
return { ok: false, step: "complete", diagnosis, batchId: activeBatchId, ...complete };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
ok: true,
|
|
159
|
+
diagnosis,
|
|
160
|
+
batchId: activeBatchId,
|
|
161
|
+
headline: `Wave batch ${activeBatchId} landed on main`,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {object} ctx
|
|
167
|
+
*/
|