pi-spine 2.14.0 → 2.15.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-worker-runner.mjs +28 -1
- package/package.json +2 -2
- package/src/batch/batch-id.mjs +103 -0
- package/src/batch/diagnosis.mjs +12 -7
- package/src/batch/engine.mjs +1 -1
- package/src/batch/evidence-command-error.mjs +14 -0
- package/src/batch/evidence-command.mjs +55 -13
- package/src/batch/evidence-path-prefix.mjs +111 -0
- package/src/batch/journal.mjs +9 -32
- package/src/batch/metrics.mjs +13 -26
- package/src/batch/reconcile-orphan.mjs +3 -2
- package/src/batch/salvage-batch-list.mjs +12 -1
- package/src/batch/state-guards.mjs +26 -3
- package/src/batch/state-io.mjs +62 -4
- package/src/batch/state.mjs +7 -13
- package/src/batch/worker-output.mjs +5 -16
- package/src/cli/handoff.mjs +10 -27
- package/src/cli/journal-follow.mjs +11 -2
- package/src/cli/lane-logs.mjs +9 -1
- package/src/cli/spine-wait.mjs +8 -0
- package/src/config/spine-config-load.mjs +11 -4
- package/src/doctor/evidence-config-warn.mjs +50 -0
- package/src/doctor/run-doctor-checks.mjs +60 -19
- package/src/process/liveness.mjs +188 -1
- package/src/util/secret-redact.mjs +140 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import {
|
|
8
|
+
import { isEngineProcessAlive } from "../process/liveness.mjs";
|
|
9
9
|
|
|
10
10
|
/** @type {ReadonlySet<string>} */
|
|
11
11
|
export const ACTIVE_PHASES = new Set(["planning", "running", "paused"]);
|
|
@@ -54,16 +54,17 @@ export function evaluateBatchStateWriteGuard(projectRoot, state) {
|
|
|
54
54
|
const incomingBatchId = String(state.batchId ?? "");
|
|
55
55
|
const onDiskPhase = String(onDisk.phase ?? "");
|
|
56
56
|
const ownerPid = readBatchEnginePid(onDisk);
|
|
57
|
+
const ownerStartedAt = readBatchEngineStartedAt(onDisk);
|
|
57
58
|
if (
|
|
58
59
|
incomingBatchId &&
|
|
59
60
|
onDiskBatchId &&
|
|
60
61
|
incomingBatchId !== onDiskBatchId &&
|
|
61
62
|
TERMINAL_BATCH_PHASES.has(onDiskPhase) &&
|
|
62
|
-
(!ownerPid || !
|
|
63
|
+
(!ownerPid || !isEngineProcessAlive(ownerPid, ownerStartedAt))
|
|
63
64
|
) {
|
|
64
65
|
return { allowed: true };
|
|
65
66
|
}
|
|
66
|
-
if (ownerPid && ownerPid !== process.pid &&
|
|
67
|
+
if (ownerPid && ownerPid !== process.pid && isEngineProcessAlive(ownerPid, ownerStartedAt)) {
|
|
67
68
|
return { allowed: false, reason: "stale_engine_pid" };
|
|
68
69
|
}
|
|
69
70
|
} catch {
|
|
@@ -97,6 +98,28 @@ export function readBatchEnginePid(raw) {
|
|
|
97
98
|
return null;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Stored engine start time (epoch ms) paired with `enginePid` for PID-reuse-safe
|
|
103
|
+
* liveness checks (SP-715 / #259).
|
|
104
|
+
*
|
|
105
|
+
* @param {unknown} raw
|
|
106
|
+
* @returns {number|null}
|
|
107
|
+
*/
|
|
108
|
+
export function readBatchEngineStartedAt(raw) {
|
|
109
|
+
if (!raw || typeof raw !== "object") return null;
|
|
110
|
+
/** @type {Record<string, unknown>} */
|
|
111
|
+
const state = /** @type {Record<string, unknown>} */ (raw);
|
|
112
|
+
const resilience =
|
|
113
|
+
state.resilience && typeof state.resilience === "object"
|
|
114
|
+
? /** @type {Record<string, unknown>} */ (state.resilience)
|
|
115
|
+
: null;
|
|
116
|
+
const fromResilience = Number(resilience?.engineStartedAt);
|
|
117
|
+
if (Number.isFinite(fromResilience) && fromResilience > 0) return fromResilience;
|
|
118
|
+
const topLevel = Number(state.engineStartedAt);
|
|
119
|
+
if (Number.isFinite(topLevel) && topLevel > 0) return topLevel;
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
100
123
|
/**
|
|
101
124
|
* @param {object} state
|
|
102
125
|
* @param {number} enginePid
|
package/src/batch/state-io.mjs
CHANGED
|
@@ -111,6 +111,52 @@ export function resolveBatchStateFileForValidation(projectRoot, batchId = null)
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
+
* Quarantine a corrupt batch-history file instead of silently resetting it to
|
|
115
|
+
* `[]`. The audit trail is operator-facing state: losing it silently hides
|
|
116
|
+
* evidence of what batches ran, so the original bytes are preserved under
|
|
117
|
+
* `.spine/runtime/` and a loud error is emitted (#261).
|
|
118
|
+
*
|
|
119
|
+
* @param {string} projectRoot
|
|
120
|
+
* @param {string} filePath
|
|
121
|
+
* @param {string} reason
|
|
122
|
+
* @returns {string|null} quarantine path, or null if quarantine failed
|
|
123
|
+
*/
|
|
124
|
+
function quarantineCorruptBatchHistory(projectRoot, filePath, reason) {
|
|
125
|
+
const quarantineDir = path.join(projectRoot, ".spine", "runtime");
|
|
126
|
+
const quarantinePath = path.join(quarantineDir, `batch-history.json.corrupt.${Date.now()}`);
|
|
127
|
+
try {
|
|
128
|
+
fs.mkdirSync(quarantineDir, { recursive: true });
|
|
129
|
+
try {
|
|
130
|
+
fs.renameSync(filePath, quarantinePath);
|
|
131
|
+
} catch {
|
|
132
|
+
// Fall back to copy+unlink when rename is unsupported (e.g. cross-device).
|
|
133
|
+
fs.copyFileSync(filePath, quarantinePath);
|
|
134
|
+
fs.unlinkSync(filePath);
|
|
135
|
+
}
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error(
|
|
138
|
+
`[spine] batch-history.json is corrupt (${reason}) and quarantine failed: ${
|
|
139
|
+
err instanceof Error ? err.message : String(err)
|
|
140
|
+
}. Refusing to overwrite the corrupt file.`,
|
|
141
|
+
);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
console.error(
|
|
145
|
+
`[spine] batch-history.json is corrupt (${reason}); quarantined to ${path.relative(
|
|
146
|
+
projectRoot,
|
|
147
|
+
quarantinePath,
|
|
148
|
+
)}. Starting a fresh history — inspect the quarantined file to recover prior entries.`,
|
|
149
|
+
);
|
|
150
|
+
return quarantinePath;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Append an entry to `.spine/batch-history.json` atomically.
|
|
155
|
+
*
|
|
156
|
+
* The write goes through `writeJsonAtomic` (temp file + rename) so a crash or
|
|
157
|
+
* concurrent reader never observes a truncated history (#261). A corrupt
|
|
158
|
+
* existing file is quarantined, never silently reset to `[]`.
|
|
159
|
+
*
|
|
114
160
|
* @param {string} projectRoot
|
|
115
161
|
* @param {object} entry
|
|
116
162
|
*/
|
|
@@ -123,13 +169,25 @@ export function appendBatchHistoryEntry(projectRoot, entry) {
|
|
|
123
169
|
if (fs.existsSync(filePath)) {
|
|
124
170
|
try {
|
|
125
171
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
126
|
-
if (Array.isArray(parsed))
|
|
127
|
-
|
|
128
|
-
|
|
172
|
+
if (Array.isArray(parsed)) {
|
|
173
|
+
history = parsed;
|
|
174
|
+
} else {
|
|
175
|
+
if (quarantineCorruptBatchHistory(projectRoot, filePath, "root value is not an array") === null) {
|
|
176
|
+
throw new Error(`Refusing to append batch history: ${filePath} is corrupt and could not be quarantined`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
if (err instanceof SyntaxError) {
|
|
181
|
+
if (quarantineCorruptBatchHistory(projectRoot, filePath, err.message) === null) {
|
|
182
|
+
throw new Error(`Refusing to append batch history: ${filePath} is corrupt and could not be quarantined`);
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
129
187
|
}
|
|
130
188
|
}
|
|
131
189
|
|
|
132
190
|
history.push(entry);
|
|
133
|
-
|
|
191
|
+
writeJsonAtomic(filePath, history);
|
|
134
192
|
return filePath;
|
|
135
193
|
}
|
package/src/batch/state.mjs
CHANGED
|
@@ -34,19 +34,13 @@ export {
|
|
|
34
34
|
clearBatchEnginePid,
|
|
35
35
|
validateBatchState,
|
|
36
36
|
} from "./state-guards.mjs";
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const d = String(now.getUTCDate()).padStart(2, "0");
|
|
45
|
-
const h = String(now.getUTCHours()).padStart(2, "0");
|
|
46
|
-
const min = String(now.getUTCMinutes()).padStart(2, "0");
|
|
47
|
-
const s = String(now.getUTCSeconds()).padStart(2, "0");
|
|
48
|
-
return `${y}${m}${d}T${h}${min}${s}`;
|
|
49
|
-
}
|
|
37
|
+
export {
|
|
38
|
+
BATCH_ID_PATTERN,
|
|
39
|
+
batchIdRejectionReason,
|
|
40
|
+
generateBatchId,
|
|
41
|
+
isValidBatchId,
|
|
42
|
+
validateBatchId,
|
|
43
|
+
} from "./batch-id.mjs";
|
|
50
44
|
|
|
51
45
|
/**
|
|
52
46
|
* Reset lane stall clocks at resume handoff so dashboard does not show pre-resume heartbeats as stale.
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { writeJsonAtomic, writeTextAtomic } from "../fs/atomic-write.mjs";
|
|
9
|
+
import { redactTextSecrets } from "../util/secret-redact.mjs";
|
|
9
10
|
import { appendJournalEvent } from "./journal.mjs";
|
|
10
11
|
|
|
11
12
|
const DEFAULT_MAX_BYTES = 262_144;
|
|
@@ -13,14 +14,6 @@ const DEFAULT_LIVE_LOG_MAX_BYTES = 262_144;
|
|
|
13
14
|
const DEFAULT_TAIL_LINES = 200;
|
|
14
15
|
const TRUNCATION_MARKER = "\n...[worker output truncated]...\n";
|
|
15
16
|
|
|
16
|
-
const BUILTIN_REDACT_PATTERNS = [
|
|
17
|
-
/DATABASE_URL=\S+/gi,
|
|
18
|
-
/(?:postgres|mysql|mongodb)(?:\+srv)?:\/\/[^\s]+/gi,
|
|
19
|
-
/(?:bearer|token|secret|password|api[_-]?key)\s*[:=]\s*\S+/gi,
|
|
20
|
-
/sk-[a-zA-Z0-9]{20,}/g,
|
|
21
|
-
/ghp_[a-zA-Z0-9]{20,}/g,
|
|
22
|
-
];
|
|
23
|
-
|
|
24
17
|
/**
|
|
25
18
|
* @param {object} [config]
|
|
26
19
|
*/
|
|
@@ -57,19 +50,15 @@ export function resolveWorkerOutputConfig(config = {}) {
|
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
/**
|
|
53
|
+
* Redact value-shaped secrets in worker output via the shared policy
|
|
54
|
+
* (SP-716); caller-configured deny patterns run after the builtin set.
|
|
55
|
+
*
|
|
60
56
|
* @param {string} text
|
|
61
57
|
* @param {ReturnType<typeof resolveWorkerOutputConfig>} outputConfig
|
|
62
58
|
*/
|
|
63
59
|
export function redactWorkerOutput(text, outputConfig) {
|
|
64
60
|
if (!text) return "";
|
|
65
|
-
|
|
66
|
-
for (const pattern of BUILTIN_REDACT_PATTERNS) {
|
|
67
|
-
out = out.replace(pattern, "[REDACTED]");
|
|
68
|
-
}
|
|
69
|
-
for (const pattern of outputConfig.denyPatterns) {
|
|
70
|
-
out = out.replace(pattern, "[REDACTED]");
|
|
71
|
-
}
|
|
72
|
-
return out;
|
|
61
|
+
return /** @type {string} */ (redactTextSecrets(String(text), outputConfig.denyPatterns));
|
|
73
62
|
}
|
|
74
63
|
|
|
75
64
|
/**
|
package/src/cli/handoff.mjs
CHANGED
|
@@ -16,47 +16,30 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
readJournalEvents,
|
|
18
18
|
readJournalTail,
|
|
19
|
-
redactSecrets,
|
|
20
19
|
} from "../batch/journal.mjs";
|
|
20
|
+
import { redactSecretsDeep, redactTextSecrets } from "../util/secret-redact.mjs";
|
|
21
21
|
import { computePendingTasks } from "../batch/resume-multi-validate.mjs";
|
|
22
22
|
import { formatJournalTailEntry } from "../dashboard/snapshot.mjs";
|
|
23
23
|
|
|
24
|
-
const SECRET_VALUE_PATTERN =
|
|
25
|
-
/\b[A-Z][A-Z0-9_]*(?:KEY|TOKEN|SECRET)[A-Z0-9_]*\s*=\s*\S+|\b(sk-[A-Za-z0-9_-]{8,})\b/gi;
|
|
26
|
-
|
|
27
24
|
const JOURNAL_TAIL_LIMIT = 10;
|
|
28
25
|
|
|
29
26
|
/**
|
|
27
|
+
* Redact value-shaped secrets in free text via the shared policy (SP-716).
|
|
28
|
+
*
|
|
30
29
|
* @param {string} text
|
|
31
30
|
*/
|
|
32
31
|
export function redactHandoffText(text) {
|
|
33
|
-
|
|
34
|
-
return text.replace(SECRET_VALUE_PATTERN, "[REDACTED]");
|
|
32
|
+
return redactTextSecrets(text);
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
/**
|
|
36
|
+
* Recursively redact denylisted keys and value-shaped secrets via the
|
|
37
|
+
* shared policy (SP-716).
|
|
38
|
+
*
|
|
38
39
|
* @param {unknown} value
|
|
39
40
|
*/
|
|
40
41
|
export function redactHandoffSecrets(value) {
|
|
41
|
-
|
|
42
|
-
return typeof value === "string" ? redactHandoffText(value) : value;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (Array.isArray(value)) {
|
|
46
|
-
return value.map((entry) => redactHandoffSecrets(entry));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const redacted = redactSecrets(value);
|
|
50
|
-
if (!redacted || typeof redacted !== "object") {
|
|
51
|
-
return typeof redacted === "string" ? redactHandoffText(redacted) : redacted;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** @type {Record<string, unknown>} */
|
|
55
|
-
const out = {};
|
|
56
|
-
for (const [key, entry] of Object.entries(/** @type {Record<string, unknown>} */ (redacted))) {
|
|
57
|
-
out[key] = redactHandoffSecrets(entry);
|
|
58
|
-
}
|
|
59
|
-
return out;
|
|
42
|
+
return redactSecretsDeep(value);
|
|
60
43
|
}
|
|
61
44
|
|
|
62
45
|
/**
|
|
@@ -97,7 +80,7 @@ function loadArchivedBatchState(projectRoot, batchId) {
|
|
|
97
80
|
function buildLaneSummary(lanes, classifiedTasks) {
|
|
98
81
|
return (lanes ?? []).map((lane) => {
|
|
99
82
|
const taskIds = lane.taskIds ?? [];
|
|
100
|
-
return
|
|
83
|
+
return redactHandoffSecrets({
|
|
101
84
|
laneNumber: lane.laneNumber,
|
|
102
85
|
laneId: lane.laneId ?? `lane-${lane.laneNumber}`,
|
|
103
86
|
taskIds,
|
|
@@ -132,7 +115,7 @@ function buildRestoreCommands(reconciliation) {
|
|
|
132
115
|
*/
|
|
133
116
|
function formatPendingTasks(pendingTasks) {
|
|
134
117
|
return pendingTasks.map((task) =>
|
|
135
|
-
|
|
118
|
+
redactHandoffSecrets({
|
|
136
119
|
taskId: task.taskId,
|
|
137
120
|
status: task.status ?? "pending",
|
|
138
121
|
taskFolder: task.taskFolder ?? null,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
|
+
import { validateBatchId } from "../batch/batch-id.mjs";
|
|
6
7
|
import {
|
|
7
8
|
journalPath,
|
|
8
9
|
normalizeJournalEvent,
|
|
@@ -40,7 +41,7 @@ export function formatJournalFollowLine(event) {
|
|
|
40
41
|
* @param {string|null|undefined} batchId
|
|
41
42
|
*/
|
|
42
43
|
export function resolveFollowBatchId(projectRoot, batchId) {
|
|
43
|
-
if (batchId) return batchId;
|
|
44
|
+
if (batchId) return validateBatchId(batchId);
|
|
44
45
|
|
|
45
46
|
const reconciliation = reconcileBatch({ projectRoot });
|
|
46
47
|
if (reconciliation.batchId) return reconciliation.batchId;
|
|
@@ -160,7 +161,15 @@ const defaultDeps = {
|
|
|
160
161
|
export async function runJournalFollow(options) {
|
|
161
162
|
const { projectRoot, args = [], follow = true, deps = defaultDeps } = options;
|
|
162
163
|
const { batchId: argBatchId, laneId, json } = parseJournalFollowArgs(args);
|
|
163
|
-
|
|
164
|
+
let batchId = null;
|
|
165
|
+
try {
|
|
166
|
+
batchId = resolveFollowBatchId(projectRoot, argBatchId);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return {
|
|
169
|
+
exitCode: 1,
|
|
170
|
+
output: `${error instanceof Error ? error.message : String(error)}\n`,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
164
173
|
|
|
165
174
|
if (!batchId) {
|
|
166
175
|
return {
|
package/src/cli/lane-logs.mjs
CHANGED
|
@@ -204,7 +204,15 @@ export async function runLaneLogs(options) {
|
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
let batchId = null;
|
|
208
|
+
try {
|
|
209
|
+
batchId = resolveFollowBatchId(projectRoot, argBatchId);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
return {
|
|
212
|
+
exitCode: 1,
|
|
213
|
+
output: `${error instanceof Error ? error.message : String(error)}\n`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
208
216
|
if (!batchId) {
|
|
209
217
|
return {
|
|
210
218
|
exitCode: 1,
|
package/src/cli/spine-wait.mjs
CHANGED
|
@@ -104,6 +104,14 @@ export function reconciliationMatchesUntil(result, untilDiagnoses) {
|
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
// `--until failed` must wake on terminal batch failure even when reconcile
|
|
108
|
+
// reports a failure-class diagnosis (worker_done_missing, worker_orphaned,
|
|
109
|
+
// engine_orphaned) instead of the literal "failed" token (#252). Explicit
|
|
110
|
+
// diagnosis tokens still match directly via the check above.
|
|
111
|
+
if (untilDiagnoses.has("failed") && result.phase === "failed") {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
107
115
|
for (const pseudo of deriveWaitPseudoDiagnoses(result)) {
|
|
108
116
|
if (untilDiagnoses.has(pseudo)) {
|
|
109
117
|
return true;
|
|
@@ -16,14 +16,21 @@ import { missingConfigHint } from "./missing-config-hint.mjs";
|
|
|
16
16
|
export { resolveGatePostureConfig } from "./gate-posture-config.mjs";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Default hook paths skipped at lane commit when config omits ignore paths (SP-640 / #200
|
|
20
|
-
* Worktree setup hooks commonly `ln -s` `.venv` into lane worktrees
|
|
19
|
+
* Default hook paths skipped at lane commit when config omits ignore paths (SP-640 / #200,
|
|
20
|
+
* SP-711 / #255). Worktree setup hooks commonly `ln -s` `.venv` into lane worktrees, and pi
|
|
21
|
+
* worker sessions write runtime trees under `.pi/` / `.pi-smart-router/`; do not stage any of
|
|
22
|
+
* those into orch merges.
|
|
21
23
|
*/
|
|
22
|
-
export const DEFAULT_WORKTREE_SETUP_IGNORE_PATHS = Object.freeze([
|
|
24
|
+
export const DEFAULT_WORKTREE_SETUP_IGNORE_PATHS = Object.freeze([
|
|
25
|
+
".venv",
|
|
26
|
+
".pi",
|
|
27
|
+
".pi-smart-router",
|
|
28
|
+
]);
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* Resolve effective `worktreeSetupIgnorePaths`, always unioning defaults so hook `.venv`
|
|
26
|
-
*
|
|
32
|
+
* and pi session trees stay ignored. Opt in to committing an ignore path via task
|
|
33
|
+
* `fileScope`, not by clearing config.
|
|
27
34
|
*
|
|
28
35
|
* @param {Record<string, unknown> | null | undefined} config
|
|
29
36
|
* @returns {string[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advisory doctor checks for gate-evidence command safety (SP-710, #254).
|
|
3
|
+
*
|
|
4
|
+
* Every `testing.*` evidence slot runs through the no-shell argv executor in
|
|
5
|
+
* `src/batch/evidence-command.mjs` at integrate-gate time. When a configured
|
|
6
|
+
* command would be rejected there (unallowed executable, shell metacharacters,
|
|
7
|
+
* arbitrary `$` expansion), evidence output degrades to a `[rejected]` line and
|
|
8
|
+
* operators lose test/build proof. These checks surface that misconfiguration
|
|
9
|
+
* early as non-blocking warnings (`ok: true, warning: true`) — doctor and
|
|
10
|
+
* preflight must stay green.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { parseEvidenceCommandChain } from "../batch/evidence-command.mjs";
|
|
14
|
+
|
|
15
|
+
/** Evidence slots executed through the no-shell evidence executor. */
|
|
16
|
+
const EVIDENCE_TESTING_KEYS = ["build", "test", "testWithCoverage", "review"];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Warn (non-blocking) when a configured `testing.*` evidence command would be
|
|
20
|
+
* rejected by the gate evidence validator.
|
|
21
|
+
*
|
|
22
|
+
* @param {{ testing?: Record<string, string> }} [config] spine-config object
|
|
23
|
+
* @returns {Array<{ label: string, ok: boolean, warning?: boolean, detail: string, suggestedCommand?: string }>}
|
|
24
|
+
*/
|
|
25
|
+
export function buildEvidenceConfigWarnDoctorChecks(config = {}) {
|
|
26
|
+
const testing = config.testing ?? {};
|
|
27
|
+
/** @type {Array<{ label: string, ok: boolean, warning?: boolean, detail: string, suggestedCommand?: string }>} */
|
|
28
|
+
const checks = [];
|
|
29
|
+
|
|
30
|
+
for (const key of EVIDENCE_TESTING_KEYS) {
|
|
31
|
+
const command = testing[key];
|
|
32
|
+
if (typeof command !== "string" || !command.trim()) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
parseEvidenceCommandChain(command);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
39
|
+
checks.push({
|
|
40
|
+
label: `testing.${key} evidence-safe`,
|
|
41
|
+
ok: true,
|
|
42
|
+
warning: true,
|
|
43
|
+
detail: `testing.${key} would be rejected at gate evidence time: ${message}`,
|
|
44
|
+
suggestedCommand: `spine settings set testing.${key} "<allowlisted evidence command>"`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return checks;
|
|
50
|
+
}
|
|
@@ -34,6 +34,7 @@ import { buildPiExtensionConflictDoctorCheck } from "./pi-extension-conflict.mjs
|
|
|
34
34
|
import { buildSupervisorConfigDoctorCheck } from "./supervisor.mjs";
|
|
35
35
|
import { buildAttachedOrphanRiskDoctorCheck } from "./attached-orphan-risk.mjs";
|
|
36
36
|
import { buildQuotaRiskDoctorCheck } from "./quota-risk.mjs";
|
|
37
|
+
import { buildEvidenceConfigWarnDoctorChecks } from "./evidence-config-warn.mjs";
|
|
37
38
|
import { metricsFilePath, readMetricsLines } from "../batch/metrics.mjs";
|
|
38
39
|
import {
|
|
39
40
|
buildCheckoutVersionSkewDoctorCheck,
|
|
@@ -166,39 +167,73 @@ function parsePiListModelsOutput(output) {
|
|
|
166
167
|
return null;
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
const LIST_MODELS_TIMEOUT_MS = 30_000;
|
|
171
|
+
|
|
172
|
+
function isListModelsTimeout(err) {
|
|
173
|
+
return err?.code === "ETIMEDOUT";
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function listModelsTimeoutCheck() {
|
|
177
|
+
// Advisory (#256): a slow model catalog fetch is not an auth failure, so
|
|
178
|
+
// preflight must not hard-fail or suggest `pi login` on timeout alone.
|
|
179
|
+
return {
|
|
180
|
+
ok: true,
|
|
181
|
+
warning: true,
|
|
182
|
+
detail: `pi --list-models timed out after ${LIST_MODELS_TIMEOUT_MS / 1000}s (slow model catalog fetch) — not an auth failure`,
|
|
183
|
+
suggestedCommand: "retry spine doctor",
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {object} [options]
|
|
189
|
+
* @param {(cmd: string, args: string[], opts: object) => any} [options.spawn]
|
|
190
|
+
* @param {(cmd: string) => boolean} [options.commandExistsFn]
|
|
191
|
+
*/
|
|
192
|
+
export function checkModelProvider({ spawn = spawnSync, commandExistsFn = commandExists } = {}) {
|
|
193
|
+
if (!commandExistsFn("pi")) {
|
|
171
194
|
return { ok: false, detail: "pi not installed", suggestedCommand: "https://pi.dev" };
|
|
172
195
|
}
|
|
173
196
|
|
|
197
|
+
let result;
|
|
174
198
|
try {
|
|
175
|
-
|
|
199
|
+
result = spawn("pi", ["--list-models"], {
|
|
176
200
|
encoding: "utf-8",
|
|
177
201
|
stdio: ["ignore", "pipe", "pipe"],
|
|
178
|
-
timeout:
|
|
202
|
+
timeout: LIST_MODELS_TIMEOUT_MS,
|
|
179
203
|
});
|
|
180
|
-
if (result.error) throw result.error;
|
|
181
|
-
const output = `${result.stdout ?? ""}
|
|
182
|
-
${result.stderr ?? ""}`.trim();
|
|
183
|
-
const model = parsePiListModelsOutput(output);
|
|
184
|
-
if (!model) {
|
|
185
|
-
return {
|
|
186
|
-
ok: false,
|
|
187
|
-
detail: "no models available",
|
|
188
|
-
suggestedCommand: "pi login",
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
ok: true,
|
|
193
|
-
detail: `${model.provider}/${model.id}`,
|
|
194
|
-
};
|
|
195
204
|
} catch (err) {
|
|
205
|
+
if (isListModelsTimeout(err)) return listModelsTimeoutCheck();
|
|
196
206
|
return {
|
|
197
207
|
ok: false,
|
|
198
208
|
detail: err.message,
|
|
199
209
|
suggestedCommand: "pi login",
|
|
200
210
|
};
|
|
201
211
|
}
|
|
212
|
+
|
|
213
|
+
const spawnError = result?.error;
|
|
214
|
+
if (isListModelsTimeout(spawnError)) return listModelsTimeoutCheck();
|
|
215
|
+
if (spawnError) {
|
|
216
|
+
return {
|
|
217
|
+
ok: false,
|
|
218
|
+
detail: spawnError.message,
|
|
219
|
+
suggestedCommand: "pi login",
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const output = `${result?.stdout ?? ""}
|
|
224
|
+
${result?.stderr ?? ""}`.trim();
|
|
225
|
+
const model = parsePiListModelsOutput(output);
|
|
226
|
+
if (!model) {
|
|
227
|
+
return {
|
|
228
|
+
ok: false,
|
|
229
|
+
detail: "no models available",
|
|
230
|
+
suggestedCommand: "pi login",
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
ok: true,
|
|
235
|
+
detail: `${model.provider}/${model.id}`,
|
|
236
|
+
};
|
|
202
237
|
}
|
|
203
238
|
|
|
204
239
|
function resolveTasksRoot(projectRoot, configResult) {
|
|
@@ -327,6 +362,7 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
|
327
362
|
record("model provider configured", modelCheck.ok, {
|
|
328
363
|
detail: modelCheck.detail,
|
|
329
364
|
suggestedCommand: modelCheck.suggestedCommand,
|
|
365
|
+
warning: modelCheck.warning,
|
|
330
366
|
});
|
|
331
367
|
|
|
332
368
|
const configResult = loadSpineConfig(projectRoot);
|
|
@@ -410,6 +446,11 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
|
410
446
|
for (const testingCheck of buildTestingEvidenceDoctorChecks(configResult.config)) {
|
|
411
447
|
checks.push(testingCheck);
|
|
412
448
|
}
|
|
449
|
+
// Advisory only (SP-710): warn when configured testing.* commands would be
|
|
450
|
+
// rejected by the no-shell evidence executor at gate time; never hard-fail.
|
|
451
|
+
for (const evidenceWarnCheck of buildEvidenceConfigWarnDoctorChecks(configResult.config)) {
|
|
452
|
+
checks.push(evidenceWarnCheck);
|
|
453
|
+
}
|
|
413
454
|
let quotaMetricsLines;
|
|
414
455
|
try {
|
|
415
456
|
quotaMetricsLines = readMetricsLines(
|