pi-spine 2.23.0 → 2.24.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/README.md +1 -1
- package/package.json +5 -5
- package/src/batch/reconcile-batch.mjs +13 -18
- package/src/batch/reconcile-classify.mjs +21 -11
- package/src/batch/reconcile-diagnosis-context.mjs +1 -2
- package/src/batch/reconcile-diagnosis.mjs +18 -19
- package/src/batch/reconcile-light-cache.mjs +0 -1
- package/src/batch/reconcile-orphan.mjs +9 -8
- package/src/batch/reconcile.mjs +0 -1
- package/src/doctor/run-doctor-checks.mjs +41 -3
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ Primary monitor surfaces: **`spine status --diagnose`**, **`spine dashboard`** /
|
|
|
49
49
|
| [pi](https://pi.dev) coding agent | ≥ 0.80.0 (`pi.minPiVersion`) | Yes |
|
|
50
50
|
| Git (worktree support) | — | Yes |
|
|
51
51
|
|
|
52
|
-
These are the Wave A floors ([#285](https://github.com/beettlle/pi-spine/issues/285)). `spine doctor` **warns** when the installed pi is below `pi.minPiVersion` ("pi version supported"). The optional peer `@earendil-works/pi-coding-agent` is developed and tested against `^0.87.
|
|
52
|
+
These are the Wave A floors ([#285](https://github.com/beettlle/pi-spine/issues/285)). `spine doctor` **warns** when the installed pi is below `pi.minPiVersion` ("pi version supported"). The optional peer `@earendil-works/pi-coding-agent` is developed and tested against `^0.87.1` (pinned in `devDependencies`; the `peerDependencies` range stays `*`).
|
|
53
53
|
|
|
54
54
|
## Install
|
|
55
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-spine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0",
|
|
4
4
|
"description": "Orchestration spine for long-running pi development",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@earendil-works/pi-coding-agent": "^0.87.
|
|
76
|
-
"@types/node": "^22.
|
|
77
|
-
"eslint": "^10.
|
|
75
|
+
"@earendil-works/pi-coding-agent": "^0.87.1",
|
|
76
|
+
"@types/node": "^22.20.4",
|
|
77
|
+
"eslint": "^10.11.0",
|
|
78
78
|
"globals": "^17.12.0",
|
|
79
|
-
"typebox": "1.3.
|
|
79
|
+
"typebox": "1.3.34",
|
|
80
80
|
"typescript": "6.0.3"
|
|
81
81
|
},
|
|
82
82
|
"license": "MIT",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/** Main reconcileBatch orchestration (SP-606 / #192). */
|
|
3
2
|
|
|
4
3
|
import fs from "node:fs";
|
|
@@ -126,7 +125,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
const tasksRoot = resolveTasksRoot(projectRoot);
|
|
129
|
-
let classifiedTasks = classifyTasks(batch, tasksRoot, projectRoot);
|
|
128
|
+
let classifiedTasks = /** @type {{ taskId: string, classification: string, laneNumber?: number|null }[]} */ (classifyTasks(batch, tasksRoot, projectRoot));
|
|
130
129
|
const useLightGit =
|
|
131
130
|
ctx.light === true &&
|
|
132
131
|
!_lightRetry &&
|
|
@@ -142,12 +141,10 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
142
141
|
|
|
143
142
|
const hasRunningTasks = classifiedTasks.some((task) => task.classification === "running");
|
|
144
143
|
const hasPendingTasks = classifiedTasks.some((task) => task.classification === "pending");
|
|
145
|
-
const pendingWithFailedSegment = batch.segments.some(
|
|
146
|
-
|
|
147
|
-
);
|
|
148
|
-
const driftTask = batch.tasks.find((task) => {
|
|
144
|
+
const pendingWithFailedSegment = /** @type {Record<string, any>[]} */ (batch.segments).some((segment) => segment.classification === "terminal-failure");
|
|
145
|
+
const driftTask = /** @type {Record<string, any>[]} */ (batch.tasks).find((task) => {
|
|
149
146
|
if (task.classification !== "pending") return false;
|
|
150
|
-
return batch.segments.some(
|
|
147
|
+
return /** @type {Record<string, any>[]} */ (batch.segments).some(
|
|
151
148
|
(segment) => segment.taskId === task.taskId && segment.classification === "terminal-failure",
|
|
152
149
|
);
|
|
153
150
|
});
|
|
@@ -161,7 +158,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
161
158
|
classifiedTasks.every((task) => task.classification === "terminal-success");
|
|
162
159
|
const failedTask = classifiedTasks.find((task) => task.classification === "terminal-failure");
|
|
163
160
|
|
|
164
|
-
const signals = {
|
|
161
|
+
const signals = /** @type {Record<string, any>} */ ({
|
|
165
162
|
phase: batch.phase,
|
|
166
163
|
endedAt: batch.endedAt,
|
|
167
164
|
failedTasks: hasFailedTasks ? Math.max(batch.failedTasks, 1) : batch.failedTasks,
|
|
@@ -178,7 +175,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
178
175
|
segments: batch.segments,
|
|
179
176
|
lanes: batch.lanes,
|
|
180
177
|
raw: batch.raw,
|
|
181
|
-
};
|
|
178
|
+
});
|
|
182
179
|
|
|
183
180
|
const journalFile = journalPath(projectRoot, batch.batchId);
|
|
184
181
|
/** @type {object[]} */
|
|
@@ -193,11 +190,11 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
193
190
|
|
|
194
191
|
if (journalEvents.length > 0 && batch.raw) {
|
|
195
192
|
let rebuilt = rebuildBatchStateFromJournal(batch.raw, journalEvents);
|
|
196
|
-
let drift = detectBatchStateDrift(batch.raw, rebuilt, journalEvents, classifiedTasks);
|
|
193
|
+
let drift = detectBatchStateDrift(batch.raw, rebuilt, /** @type {any} */ (journalEvents), /** @type {any} */ (classifiedTasks));
|
|
197
194
|
const healed = reconcileBatchStateDrift({
|
|
198
195
|
projectRoot,
|
|
199
196
|
state: batch.raw,
|
|
200
|
-
classifiedTasks,
|
|
197
|
+
classifiedTasks: /** @type {any} */ (classifiedTasks),
|
|
201
198
|
journalEvents,
|
|
202
199
|
drift,
|
|
203
200
|
});
|
|
@@ -213,7 +210,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
213
210
|
}
|
|
214
211
|
classifiedTasks = classifyTasks(batch, tasksRoot, projectRoot);
|
|
215
212
|
rebuilt = rebuildBatchStateFromJournal(batch.raw, journalEvents);
|
|
216
|
-
drift = detectBatchStateDrift(batch.raw, rebuilt, journalEvents, classifiedTasks);
|
|
213
|
+
drift = detectBatchStateDrift(batch.raw, rebuilt, /** @type {any} */ (journalEvents), /** @type {any} */ (classifiedTasks));
|
|
217
214
|
}
|
|
218
215
|
signals.stateDrift = drift;
|
|
219
216
|
signals.rebuiltFromJournal = rebuilt;
|
|
@@ -345,13 +342,13 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
345
342
|
|
|
346
343
|
const mergeGitignoredFailureInferred = inferMergeGitignoredFailure({
|
|
347
344
|
exitReason,
|
|
348
|
-
failureClass: batch.raw?.mergeResults?.find((entry) => entry?.failureClass)?.failureClass ?? null,
|
|
349
|
-
lastError: batch.raw?.lastError ?? null,
|
|
345
|
+
failureClass: /** @type {Record<string, any>[] | undefined} */ (batch.raw?.mergeResults)?.find((entry) => entry?.failureClass)?.failureClass ?? null,
|
|
346
|
+
lastError: /** @type {any} */ (batch.raw?.lastError) ?? null,
|
|
350
347
|
journalEvents,
|
|
351
348
|
});
|
|
352
349
|
const mergeFailureSummary = summarizeMergeFailures(
|
|
353
350
|
batch.mergeResults,
|
|
354
|
-
batch.raw?.lastError ?? null,
|
|
351
|
+
/** @type {any} */ (batch.raw?.lastError) ?? null,
|
|
355
352
|
);
|
|
356
353
|
signals.mergeFailed = mergeFailureSummary.mergeFailed;
|
|
357
354
|
signals.failedMerges = mergeFailureSummary.failedMerges;
|
|
@@ -376,9 +373,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
376
373
|
: null;
|
|
377
374
|
const driftTaskStatus =
|
|
378
375
|
failedTaskId != null
|
|
379
|
-
? String(
|
|
380
|
-
(batch.raw?.tasks ?? []).find((entry) => entry?.taskId === failedTaskId)?.status ?? "",
|
|
381
|
-
)
|
|
376
|
+
? String((/** @type {Record<string, any>[]} */ (batch.raw?.tasks) ?? []).find((entry) => entry?.taskId === failedTaskId)?.status ?? "")
|
|
382
377
|
: null;
|
|
383
378
|
|
|
384
379
|
const activeReviewTaskId =
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/** Task classification and git inspection for batch reconciliation (SP-578). */
|
|
3
2
|
|
|
4
3
|
import fs from "node:fs";
|
|
@@ -21,7 +20,7 @@ export function resolveTasksRoot(projectRoot, configResult) {
|
|
|
21
20
|
return resolveTasksRootPath(projectRoot, loaded.config);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
/** Align classification with batch-state status (SP-516 / #166, SP-512). @param {
|
|
23
|
+
/** Align classification with batch-state status (SP-516 / #166, SP-512). @param {Record<string, any>} classified */
|
|
25
24
|
export function alignTaskClassificationWithStatus(classified) {
|
|
26
25
|
const status = String(classified.status ?? "").toLowerCase();
|
|
27
26
|
let classification = classified.classification;
|
|
@@ -43,9 +42,9 @@ export function alignTaskClassificationWithStatus(classified) {
|
|
|
43
42
|
return { ...classified, classification };
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
/** @param {
|
|
45
|
+
/** @param {Record<string, any>} batch @param {string|null} tasksRoot @param {string} [projectRoot] */
|
|
47
46
|
export function classifyTasks(batch, tasksRoot, projectRoot = "") {
|
|
48
|
-
return batch.tasks.map((task) =>
|
|
47
|
+
return batch.tasks.map((/** @type {any} */ task) =>
|
|
49
48
|
alignTaskClassificationWithStatus(
|
|
50
49
|
classifyTaskDoneSemantics(task, {
|
|
51
50
|
tasksRoot,
|
|
@@ -57,7 +56,7 @@ export function classifyTasks(batch, tasksRoot, projectRoot = "") {
|
|
|
57
56
|
);
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
/** @param {{ projectRoot: string, state:
|
|
59
|
+
/** @param {{ projectRoot: string, state: Record<string, any> }} params @returns {{ changed: boolean }} */
|
|
61
60
|
export function syncPersistedClassifications({ projectRoot, state }) {
|
|
62
61
|
if (!state || typeof state !== "object") {
|
|
63
62
|
return { changed: false };
|
|
@@ -70,7 +69,7 @@ export function syncPersistedClassifications({ projectRoot, state }) {
|
|
|
70
69
|
|
|
71
70
|
const tasksRoot = resolveTasksRoot(projectRoot);
|
|
72
71
|
const classified = classifyTasks(batch, tasksRoot, projectRoot);
|
|
73
|
-
const alignedById = new Map(classified.map((task) => [String(task.taskId), task]));
|
|
72
|
+
const alignedById = new Map(classified.map((/** @type {any} */ task) => [String(task.taskId), task]));
|
|
74
73
|
let changed = false;
|
|
75
74
|
|
|
76
75
|
for (const task of state.tasks ?? []) {
|
|
@@ -116,6 +115,7 @@ export function syncPersistedClassifications({ projectRoot, state }) {
|
|
|
116
115
|
return { changed };
|
|
117
116
|
}
|
|
118
117
|
|
|
118
|
+
/** @param {string} projectRoot */
|
|
119
119
|
function isInsideGitRepo(projectRoot) {
|
|
120
120
|
try {
|
|
121
121
|
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
@@ -129,6 +129,7 @@ function isInsideGitRepo(projectRoot) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/** @param {string} projectRoot @param {string} ref */
|
|
132
133
|
function gitRefExists(projectRoot, ref) {
|
|
133
134
|
try {
|
|
134
135
|
execFileSync("git", ["rev-parse", "--verify", ref], {
|
|
@@ -142,6 +143,7 @@ function gitRefExists(projectRoot, ref) {
|
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
|
|
146
|
+
/** @param {string} projectRoot @param {string} ancestor @param {string} descendant */
|
|
145
147
|
function gitIsAncestor(projectRoot, ancestor, descendant) {
|
|
146
148
|
try {
|
|
147
149
|
execFileSync("git", ["merge-base", "--is-ancestor", ancestor, descendant], {
|
|
@@ -155,6 +157,7 @@ function gitIsAncestor(projectRoot, ancestor, descendant) {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
/** @param {Record<string, any>} result @param {unknown} err @param {string} context */
|
|
158
161
|
function recordGitInspectionError(result, err, context) {
|
|
159
162
|
const message = err instanceof Error ? err.message : String(err);
|
|
160
163
|
const detail = `${context}: ${message}`;
|
|
@@ -163,6 +166,7 @@ function recordGitInspectionError(result, err, context) {
|
|
|
163
166
|
: detail;
|
|
164
167
|
}
|
|
165
168
|
|
|
169
|
+
/** @param {string} projectRoot @param {string} batchId @returns {string[]} */
|
|
166
170
|
function listOrchBranches(projectRoot, batchId) {
|
|
167
171
|
try {
|
|
168
172
|
const output = execFileSync("git", ["branch", "-a", "--list", "*orch*"], {
|
|
@@ -184,7 +188,7 @@ function listOrchBranches(projectRoot, batchId) {
|
|
|
184
188
|
/** @param {{ projectRoot: string, batchId: string, baseBranch: string, orchBranch: string|null }} ctx */
|
|
185
189
|
export function inspectGitState(ctx) {
|
|
186
190
|
const { projectRoot, batchId, baseBranch, orchBranch } = ctx;
|
|
187
|
-
const result = {
|
|
191
|
+
const result = /** @type {Record<string, any>} */ ({
|
|
188
192
|
inGitRepo: isInsideGitRepo(projectRoot),
|
|
189
193
|
baseBranch,
|
|
190
194
|
orchBranch,
|
|
@@ -194,7 +198,7 @@ export function inspectGitState(ctx) {
|
|
|
194
198
|
mergedOrchBranch: null,
|
|
195
199
|
orchCommitsAhead: null,
|
|
196
200
|
gitInspectionError: null,
|
|
197
|
-
};
|
|
201
|
+
});
|
|
198
202
|
|
|
199
203
|
if (!result.inGitRepo) return result;
|
|
200
204
|
|
|
@@ -273,7 +277,9 @@ export function listGitChangedPaths(projectRoot, refA, refB) {
|
|
|
273
277
|
}
|
|
274
278
|
}
|
|
275
279
|
|
|
276
|
-
/** Paths from human commits since snapshot, excluding orch ancestry.
|
|
280
|
+
/** Paths from human commits since snapshot, excluding orch ancestry.
|
|
281
|
+
* @param {string} projectRoot @param {string|null} snapshot @param {string|null} humanHead @param {string|null} orchBranch @returns {string[]}
|
|
282
|
+
*/
|
|
277
283
|
export function listHumanOnlyPaths(projectRoot, snapshot, humanHead, orchBranch) {
|
|
278
284
|
if (!snapshot || !humanHead || snapshot === humanHead) return [];
|
|
279
285
|
const args = ["log", "--name-only", "--pretty=format:", `${snapshot}..${humanHead}`];
|
|
@@ -293,6 +299,7 @@ export function listHumanOnlyPaths(projectRoot, snapshot, humanHead, orchBranch)
|
|
|
293
299
|
}
|
|
294
300
|
}
|
|
295
301
|
|
|
302
|
+
/** @param {string} projectRoot @param {string} ref @param {string} filePath */
|
|
296
303
|
function pathExistsAtRef(projectRoot, ref, filePath) {
|
|
297
304
|
try {
|
|
298
305
|
execFileSync("git", ["cat-file", "-e", `${ref}:${filePath}`], {
|
|
@@ -306,6 +313,7 @@ function pathExistsAtRef(projectRoot, ref, filePath) {
|
|
|
306
313
|
}
|
|
307
314
|
}
|
|
308
315
|
|
|
316
|
+
/** @param {string} projectRoot @param {string} baseTip @param {string} snapshot */
|
|
309
317
|
function humanCheckoutNeedsPathSync(projectRoot, baseTip, snapshot) {
|
|
310
318
|
const landPaths = listGitChangedPaths(projectRoot, snapshot, baseTip);
|
|
311
319
|
for (const filePath of landPaths) {
|
|
@@ -317,7 +325,9 @@ function humanCheckoutNeedsPathSync(projectRoot, baseTip, snapshot) {
|
|
|
317
325
|
return false;
|
|
318
326
|
}
|
|
319
327
|
|
|
320
|
-
/** Human/base divergence or post-isolated-integrate sync (FR-WT-08 / #91).
|
|
328
|
+
/** Human/base divergence or post-isolated-integrate sync (FR-WT-08 / #91).
|
|
329
|
+
* @param {Record<string, any>} ctx
|
|
330
|
+
*/
|
|
321
331
|
export function inspectHumanBaseSync(ctx) {
|
|
322
332
|
const { projectRoot, baseBranch, baseBranchHeadAtStart, orchBranch, git, journalEvents } = ctx;
|
|
323
333
|
if (!git?.inGitRepo) return null;
|
|
@@ -343,7 +353,7 @@ export function inspectHumanBaseSync(ctx) {
|
|
|
343
353
|
}
|
|
344
354
|
|
|
345
355
|
const integrateCompleted = Array.isArray(journalEvents)
|
|
346
|
-
? journalEvents.some((event) => event.type === "integrate.completed")
|
|
356
|
+
? journalEvents.some((/** @type {any} */ event) => event.type === "integrate.completed")
|
|
347
357
|
: false;
|
|
348
358
|
const landSucceeded =
|
|
349
359
|
git.orchMergedToBase ||
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/** Diagnosis output context after reconcile signal enrichment (#201 / SP-645). */
|
|
3
2
|
|
|
4
3
|
import { findPendingLaneLandTasks } from "./diagnosis-pending-lane.mjs";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
* @param {
|
|
6
|
+
* @param {Record<string, any>} params
|
|
8
7
|
*/
|
|
9
8
|
export function buildReconcileDiagnosisContext(params) {
|
|
10
9
|
const {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/** Diagnosis derivation (SP-596/SP-606 / #192). */
|
|
3
2
|
|
|
4
3
|
import { inferLaunchFailureKind } from "./diagnosis.mjs";
|
|
@@ -29,7 +28,7 @@ export {
|
|
|
29
28
|
*/
|
|
30
29
|
function resolveFailedExitReason(rawTasks, failedTaskId) {
|
|
31
30
|
if (!failedTaskId || !Array.isArray(rawTasks)) return null;
|
|
32
|
-
const match = rawTasks.find((entry) => {
|
|
31
|
+
const match = rawTasks.find((/** @type {any} */ entry) => {
|
|
33
32
|
if (!entry || typeof entry !== "object") return false;
|
|
34
33
|
return String(entry.taskId ?? entry.id ?? "") === failedTaskId;
|
|
35
34
|
});
|
|
@@ -40,7 +39,7 @@ function resolveFailedExitReason(rawTasks, failedTaskId) {
|
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* @param {string|null} failedTaskId
|
|
43
|
-
* @param {
|
|
42
|
+
* @param {Record<string, any>} signals
|
|
44
43
|
* @returns {string|null}
|
|
45
44
|
*/
|
|
46
45
|
function resolvePrimaryFailureExitReason(failedTaskId, signals) {
|
|
@@ -48,7 +47,7 @@ function resolvePrimaryFailureExitReason(failedTaskId, signals) {
|
|
|
48
47
|
if (fromTask) return fromTask;
|
|
49
48
|
if (!failedTaskId) return null;
|
|
50
49
|
if (Array.isArray(signals.segments)) {
|
|
51
|
-
const segment = signals.segments.find((entry) => entry?.taskId === failedTaskId);
|
|
50
|
+
const segment = signals.segments.find((/** @type {any} */ entry) => entry?.taskId === failedTaskId);
|
|
52
51
|
const classification = segment?.classification;
|
|
53
52
|
if (
|
|
54
53
|
typeof classification === "string" &&
|
|
@@ -75,7 +74,7 @@ function resolvePrimaryFailureExitReason(failedTaskId, signals) {
|
|
|
75
74
|
/**
|
|
76
75
|
* @param {string|null} failedTaskId
|
|
77
76
|
* @param {string|null} exitReason
|
|
78
|
-
* @param {
|
|
77
|
+
* @param {Record<string, any>} signals
|
|
79
78
|
* @returns {{ exitReason: string|null, launchFailureKind: string|null }}
|
|
80
79
|
*/
|
|
81
80
|
function deriveFailureContext(failedTaskId, exitReason, signals) {
|
|
@@ -83,7 +82,7 @@ function deriveFailureContext(failedTaskId, exitReason, signals) {
|
|
|
83
82
|
exitReason ?? resolvePrimaryFailureExitReason(failedTaskId, signals);
|
|
84
83
|
if (failedTaskId && signals.tasksRoot) {
|
|
85
84
|
const taskFolder =
|
|
86
|
-
signals.tasks?.find((entry) => entry.taskId === failedTaskId)?.taskFolder ?? null;
|
|
85
|
+
signals.tasks?.find((/** @type {any} */ entry) => entry.taskId === failedTaskId)?.taskFolder ?? null;
|
|
87
86
|
const stubReason = inferStubExitReasonForTask(signals.tasksRoot, failedTaskId, taskFolder);
|
|
88
87
|
if (stubReason) {
|
|
89
88
|
resolvedExitReason = stubReason;
|
|
@@ -100,7 +99,7 @@ function deriveFailureContext(failedTaskId, exitReason, signals) {
|
|
|
100
99
|
/**
|
|
101
100
|
* @param {string} diagnosis
|
|
102
101
|
* @param {string|null} failedTaskId
|
|
103
|
-
* @param {
|
|
102
|
+
* @param {Record<string, any>} signals
|
|
104
103
|
* @param {string|null} [exitReason]
|
|
105
104
|
*/
|
|
106
105
|
function withFailureContext(diagnosis, failedTaskId, signals, exitReason = null) {
|
|
@@ -114,13 +113,13 @@ function withFailureContext(diagnosis, failedTaskId, signals, exitReason = null)
|
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
/**
|
|
117
|
-
* @param {
|
|
116
|
+
* @param {Record<string, any>} signals
|
|
118
117
|
*/
|
|
119
118
|
function findNeedsReplanTask(signals) {
|
|
120
119
|
const tasks = signals.raw?.tasks ?? signals.tasks ?? [];
|
|
121
120
|
return (
|
|
122
121
|
tasks.find(
|
|
123
|
-
(task) =>
|
|
122
|
+
(/** @type {any} */ task) =>
|
|
124
123
|
task?.exitReason === "needs_replan" &&
|
|
125
124
|
(task.status === "failed" || task.classification === "terminal-failure"),
|
|
126
125
|
) ?? null
|
|
@@ -128,11 +127,11 @@ function findNeedsReplanTask(signals) {
|
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
/**
|
|
131
|
-
* @param {
|
|
130
|
+
* @param {Record<string, any>} signals
|
|
132
131
|
*/
|
|
133
132
|
function hasNeedsReplanBlocker(signals) {
|
|
134
133
|
const tasks = signals.raw?.tasks ?? signals.tasks ?? [];
|
|
135
|
-
return tasks.some((task) => task?.exitReason === "needs_replan");
|
|
134
|
+
return tasks.some((/** @type {any} */ task) => task?.exitReason === "needs_replan");
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
/**
|
|
@@ -158,8 +157,8 @@ const POST_DONE_PLAN_REVIEW_EXIT_REASONS = new Set([
|
|
|
158
157
|
* The salvage command itself hard-gates on commits-ahead, so pointing at it
|
|
159
158
|
* without lane commits is safe (dry-run reports none salvageable).
|
|
160
159
|
*
|
|
161
|
-
* @param {
|
|
162
|
-
* @returns {
|
|
160
|
+
* @param {Record<string, any>} signals
|
|
161
|
+
* @returns {Record<string, any>|null}
|
|
163
162
|
*/
|
|
164
163
|
function findPostDonePlanReviewSpawnFailedTask(signals) {
|
|
165
164
|
const tasks = Array.isArray(signals.tasks) ? signals.tasks : [];
|
|
@@ -180,7 +179,7 @@ function findPostDonePlanReviewSpawnFailedTask(signals) {
|
|
|
180
179
|
}
|
|
181
180
|
|
|
182
181
|
/**
|
|
183
|
-
* @param {
|
|
182
|
+
* @param {Record<string, any>} signals
|
|
184
183
|
*/
|
|
185
184
|
export function deriveDiagnosis(signals) {
|
|
186
185
|
const {
|
|
@@ -206,7 +205,7 @@ export function deriveDiagnosis(signals) {
|
|
|
206
205
|
}
|
|
207
206
|
|
|
208
207
|
if (shouldDiagnosePendingLaneLand(signals)) {
|
|
209
|
-
const pendingLaneLandTasks = findPendingLaneLandTasks(signals.tasks);
|
|
208
|
+
const pendingLaneLandTasks = /** @type {any} */ (findPendingLaneLandTasks(signals.tasks));
|
|
210
209
|
return withFailureContext(
|
|
211
210
|
"pending_lane_land",
|
|
212
211
|
pendingLaneLandTasks[0]?.taskId ?? null,
|
|
@@ -215,7 +214,7 @@ export function deriveDiagnosis(signals) {
|
|
|
215
214
|
}
|
|
216
215
|
|
|
217
216
|
if (signals.stateDrift?.drifted) {
|
|
218
|
-
const driftTask = signals.stateDrift.entries.find((entry) => entry.taskId !== "*");
|
|
217
|
+
const driftTask = signals.stateDrift.entries.find((/** @type {any} */ entry) => entry.taskId !== "*");
|
|
219
218
|
return withFailureContext("state_drift", driftTask?.taskId ?? null, signals);
|
|
220
219
|
}
|
|
221
220
|
|
|
@@ -224,12 +223,12 @@ export function deriveDiagnosis(signals) {
|
|
|
224
223
|
hasPendingTasks &&
|
|
225
224
|
Array.isArray(signals.tasks) &&
|
|
226
225
|
signals.tasks.some(
|
|
227
|
-
(task) =>
|
|
226
|
+
(/** @type {any} */ task) =>
|
|
228
227
|
task?.doneInLane === true &&
|
|
229
228
|
(task.status === "pending" || task.status === "running" || task.classification === "pending" || task.classification === "running"),
|
|
230
229
|
)
|
|
231
230
|
) {
|
|
232
|
-
const driftTask = signals.tasks.find((task) => task?.doneInLane);
|
|
231
|
+
const driftTask = signals.tasks.find((/** @type {any} */ task) => task?.doneInLane);
|
|
233
232
|
return withFailureContext("needs_retry", driftTask?.taskId ?? null, signals);
|
|
234
233
|
}
|
|
235
234
|
|
|
@@ -318,7 +317,7 @@ export function deriveDiagnosis(signals) {
|
|
|
318
317
|
phase === "merging" &&
|
|
319
318
|
endedAt != null &&
|
|
320
319
|
Array.isArray(signals.raw?.mergeResults) &&
|
|
321
|
-
signals.raw.mergeResults.some((entry) => String(entry?.status ?? "").toLowerCase() === "failed")
|
|
320
|
+
signals.raw.mergeResults.some((/** @type {any} */ entry) => String(entry?.status ?? "").toLowerCase() === "failed")
|
|
322
321
|
) {
|
|
323
322
|
return withFailureContext("failed", null, signals);
|
|
324
323
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/** Orphan reconcile helpers (SP-606 / #192). Post-DONE heal: SP-657 / #205. */
|
|
3
2
|
|
|
4
3
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
@@ -37,7 +36,7 @@ export function runReconciliationCheck(ctx) {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
|
-
* @param {
|
|
39
|
+
* @param {Record<string, any>[]} lanes
|
|
41
40
|
* @param {number|null|undefined} laneNumber
|
|
42
41
|
*/
|
|
43
42
|
function findLaneForOrphanReconcile(lanes, laneNumber) {
|
|
@@ -52,7 +51,7 @@ function findLaneForOrphanReconcile(lanes, laneNumber) {
|
|
|
52
51
|
/**
|
|
53
52
|
* Classify tasks for orphan reconcile (status-only, mirrors resume validation).
|
|
54
53
|
*
|
|
55
|
-
* @param {
|
|
54
|
+
* @param {Record<string, any>[]} tasks
|
|
56
55
|
*/
|
|
57
56
|
function classifyTasksForOrphanReconcile(tasks) {
|
|
58
57
|
return (tasks ?? []).map((task) => {
|
|
@@ -66,7 +65,7 @@ function classifyTasksForOrphanReconcile(tasks) {
|
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
/**
|
|
69
|
-
* @param {
|
|
68
|
+
* @param {Record<string, any>[]} journalEvents
|
|
70
69
|
* @param {string} taskId
|
|
71
70
|
* @param {string} eventType
|
|
72
71
|
*/
|
|
@@ -111,8 +110,8 @@ function orphanTaskReadyForSkipDoneHeal({ projectRoot, batchId, task, lanes, tas
|
|
|
111
110
|
* @param {object} params
|
|
112
111
|
* @param {string} params.projectRoot
|
|
113
112
|
* @param {string} params.batchId
|
|
114
|
-
* @param {
|
|
115
|
-
* @param {
|
|
113
|
+
* @param {Record<string, any>} params.state
|
|
114
|
+
* @param {Record<string, any>} params.task
|
|
116
115
|
* @param {object[]} params.journalEvents
|
|
117
116
|
* @returns {boolean}
|
|
118
117
|
*/
|
|
@@ -146,7 +145,7 @@ function healPostDoneOrphanTask({ projectRoot, batchId, state, task, journalEven
|
|
|
146
145
|
*
|
|
147
146
|
* @param {object} params
|
|
148
147
|
* @param {string} params.projectRoot
|
|
149
|
-
* @param {
|
|
148
|
+
* @param {Record<string, any>} params.state
|
|
150
149
|
* @returns {{ reconciled: boolean, taskId?: string|null, kind?: string, exitReason?: string, healedTaskIds?: string[] }}
|
|
151
150
|
*/
|
|
152
151
|
export function reconcileOrphanRunningState({ projectRoot, state }) {
|
|
@@ -202,7 +201,9 @@ export function reconcileOrphanRunningState({ projectRoot, state }) {
|
|
|
202
201
|
const taskIdsFailed = [];
|
|
203
202
|
|
|
204
203
|
for (const taskId of taskIdsToConsider) {
|
|
205
|
-
const task = (state.tasks ?? []).find(
|
|
204
|
+
const task = /** @type {Record<string, any>[]} */ (state.tasks ?? []).find(
|
|
205
|
+
(entry) => entry?.taskId === taskId,
|
|
206
|
+
);
|
|
206
207
|
if (!task || task.status !== "running") continue;
|
|
207
208
|
|
|
208
209
|
if (
|
package/src/batch/reconcile.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/**
|
|
3
2
|
* Doctor check orchestration — library surface for preflight and CLI.
|
|
4
3
|
*/
|
|
@@ -56,6 +55,11 @@ const SPINE_CLI_ENTRY = path.join(PACKAGE_ROOT, "bin", "spine.mjs");
|
|
|
56
55
|
|
|
57
56
|
const REQUIRED_AGENT_FILES = ["worker.md", "reviewer.md", "supervisor.md"];
|
|
58
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} cmd
|
|
60
|
+
* @param {string} [flag]
|
|
61
|
+
* @returns {string | null}
|
|
62
|
+
*/
|
|
59
63
|
function getVersion(cmd, flag = "--version") {
|
|
60
64
|
let result;
|
|
61
65
|
try {
|
|
@@ -94,6 +98,10 @@ function getMinPiVersion() {
|
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
|
|
101
|
+
/**
|
|
102
|
+
* @param {unknown} versionText
|
|
103
|
+
* @returns {{ major: number, minor: number, patch: number } | null}
|
|
104
|
+
*/
|
|
97
105
|
function parseSemver(versionText) {
|
|
98
106
|
const match = String(versionText ?? "")
|
|
99
107
|
.trim()
|
|
@@ -106,6 +114,11 @@ function parseSemver(versionText) {
|
|
|
106
114
|
};
|
|
107
115
|
}
|
|
108
116
|
|
|
117
|
+
/**
|
|
118
|
+
* @param {{ major: number, minor: number, patch: number } | null} a
|
|
119
|
+
* @param {{ major: number, minor: number, patch: number } | null} b
|
|
120
|
+
* @returns {number | null}
|
|
121
|
+
*/
|
|
109
122
|
function compareSemver(a, b) {
|
|
110
123
|
if (!a || !b) return null;
|
|
111
124
|
if (a.major !== b.major) return a.major - b.major;
|
|
@@ -113,6 +126,10 @@ function compareSemver(a, b) {
|
|
|
113
126
|
return a.patch - b.patch;
|
|
114
127
|
}
|
|
115
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} dir
|
|
131
|
+
* @returns {boolean}
|
|
132
|
+
*/
|
|
116
133
|
function isInsideGitRepo(dir) {
|
|
117
134
|
try {
|
|
118
135
|
execFileSync("git", ["rev-parse", "--is-inside-work-tree"], {
|
|
@@ -138,6 +155,10 @@ function gitSupportsWorktrees() {
|
|
|
138
155
|
}
|
|
139
156
|
}
|
|
140
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @param {string} output
|
|
160
|
+
* @returns {{ provider: string, id: string } | null}
|
|
161
|
+
*/
|
|
141
162
|
function parsePiListModelsOutput(output) {
|
|
142
163
|
const lines = output.split(/\r?\n/).filter(Boolean);
|
|
143
164
|
let providerCol = 0;
|
|
@@ -170,6 +191,10 @@ function parsePiListModelsOutput(output) {
|
|
|
170
191
|
|
|
171
192
|
const LIST_MODELS_TIMEOUT_MS = 30_000;
|
|
172
193
|
|
|
194
|
+
/**
|
|
195
|
+
* @param {any} err
|
|
196
|
+
* @returns {boolean}
|
|
197
|
+
*/
|
|
173
198
|
function isListModelsTimeout(err) {
|
|
174
199
|
return err?.code === "ETIMEDOUT";
|
|
175
200
|
}
|
|
@@ -189,6 +214,7 @@ function listModelsTimeoutCheck() {
|
|
|
189
214
|
* @param {object} [options]
|
|
190
215
|
* @param {(cmd: string, args: string[], opts: object) => any} [options.spawn]
|
|
191
216
|
* @param {(cmd: string) => boolean} [options.commandExistsFn]
|
|
217
|
+
* @returns {{ ok: boolean, warning?: boolean, detail?: string, suggestedCommand?: string }}
|
|
192
218
|
*/
|
|
193
219
|
export function checkModelProvider({ spawn = spawnSync, commandExistsFn = commandExists } = {}) {
|
|
194
220
|
if (!commandExistsFn("pi")) {
|
|
@@ -206,7 +232,7 @@ export function checkModelProvider({ spawn = spawnSync, commandExistsFn = comman
|
|
|
206
232
|
if (isListModelsTimeout(err)) return listModelsTimeoutCheck();
|
|
207
233
|
return {
|
|
208
234
|
ok: false,
|
|
209
|
-
detail: err.message,
|
|
235
|
+
detail: /** @type {Error} */ (err).message,
|
|
210
236
|
suggestedCommand: "pi login",
|
|
211
237
|
};
|
|
212
238
|
}
|
|
@@ -237,6 +263,10 @@ ${result?.stderr ?? ""}`.trim();
|
|
|
237
263
|
};
|
|
238
264
|
}
|
|
239
265
|
|
|
266
|
+
/**
|
|
267
|
+
* @param {string} projectRoot
|
|
268
|
+
* @param {ReturnType<typeof loadSpineConfig>} configResult
|
|
269
|
+
*/
|
|
240
270
|
function resolveTasksRoot(projectRoot, configResult) {
|
|
241
271
|
if (!configResult.config) {
|
|
242
272
|
return null;
|
|
@@ -244,6 +274,9 @@ function resolveTasksRoot(projectRoot, configResult) {
|
|
|
244
274
|
return resolveTasksRootPath(projectRoot, configResult.config);
|
|
245
275
|
}
|
|
246
276
|
|
|
277
|
+
/**
|
|
278
|
+
* @param {unknown} command
|
|
279
|
+
*/
|
|
247
280
|
function isTestingCommandEmpty(command) {
|
|
248
281
|
return !command || String(command).trim() === "";
|
|
249
282
|
}
|
|
@@ -251,7 +284,7 @@ function isTestingCommandEmpty(command) {
|
|
|
251
284
|
/**
|
|
252
285
|
* Warn when evidence gates expect commands that are missing (SP-112).
|
|
253
286
|
*
|
|
254
|
-
* @param {
|
|
287
|
+
* @param {Record<string, any>} [config]
|
|
255
288
|
* @returns {Array<{ label: string, ok: boolean, warning?: boolean, detail: string, suggestedCommand?: string }>}
|
|
256
289
|
*/
|
|
257
290
|
export function buildTestingEvidenceDoctorChecks(config = {}) {
|
|
@@ -286,6 +319,11 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
|
286
319
|
const checks = [];
|
|
287
320
|
let issueCount = 0;
|
|
288
321
|
|
|
322
|
+
/**
|
|
323
|
+
* @param {string} label
|
|
324
|
+
* @param {boolean} ok
|
|
325
|
+
* @param {Record<string, any>} [extra]
|
|
326
|
+
*/
|
|
289
327
|
const record = (label, ok, extra = {}) => {
|
|
290
328
|
checks.push({ label, ok, ...extra });
|
|
291
329
|
if (!ok) issueCount++;
|