pi-spine 2.14.1 → 2.16.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/package.json +2 -2
- package/skills/spine-release-operator/SKILL.md +60 -7
- package/skills/spine-release-operator/references/issue-intake-checklist.md +1 -1
- package/skills/spine-release-operator/references/post-integrate-regression-gate.md +1 -0
- package/src/batch/abort.mjs +82 -68
- package/src/batch/batch-id.mjs +103 -0
- package/src/batch/batch-state-lock.mjs +357 -0
- package/src/batch/contract-exec.mjs +12 -8
- package/src/batch/diagnosis.mjs +12 -7
- package/src/batch/engine-lanes/review-code.mjs +224 -0
- package/src/batch/engine-lanes/review-final.mjs +318 -0
- package/src/batch/engine-lanes/review-plan.mjs +315 -0
- package/src/batch/engine-lanes/review-poll.mjs +427 -0
- package/src/batch/engine-lanes/review-stub.mjs +146 -0
- package/src/batch/engine-lanes/review.mjs +4 -1532
- package/src/batch/engine.mjs +1 -1
- package/src/batch/journal.mjs +9 -32
- package/src/batch/lifecycle.mjs +106 -95
- 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 +101 -29
- 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/config/cursor-rules/profile.mjs +5 -1
- package/src/config/defaults.mjs +10 -1
- package/src/config/settings-fields.mjs +14 -0
- package/src/planner/file-scope.mjs +109 -7
- package/src/process/liveness.mjs +188 -1
- package/src/tasks/analyze/index.mjs +14 -27
- package/src/tasks/packet/parse-prompt.mjs +138 -3
- package/src/util/secret-redact.mjs +140 -0
|
@@ -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,
|
|
@@ -374,11 +374,15 @@ export function mergeRulesProfile(defaults, fileProfile) {
|
|
|
374
374
|
function normalizeRulePaths(paths) {
|
|
375
375
|
/** @type {string[]} */
|
|
376
376
|
const seen = [];
|
|
377
|
+
// Set-backed membership so dedup is O(1) per entry instead of O(N) (#271);
|
|
378
|
+
// `seen` keeps first-seen order for the return value.
|
|
379
|
+
const seenSet = new Set();
|
|
377
380
|
for (const entry of paths) {
|
|
378
381
|
const normalized = entry.trim().replace(/\\/g, "/").replace(/^\.\/+/, "");
|
|
379
|
-
if (!normalized ||
|
|
382
|
+
if (!normalized || seenSet.has(normalized)) {
|
|
380
383
|
continue;
|
|
381
384
|
}
|
|
385
|
+
seenSet.add(normalized);
|
|
382
386
|
seen.push(normalized);
|
|
383
387
|
}
|
|
384
388
|
return seen;
|
package/src/config/defaults.mjs
CHANGED
|
@@ -5,10 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
import { ORCHESTRATOR_DEFAULTS } from "./spine-config-schema.mjs";
|
|
7
7
|
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* `maxCodeReviewAttempts` / `maxPlanReviewAttempts` default to `null` (= unset), which
|
|
10
|
+
* falls back to `maxFinalAttempts` at the phase runners (SP-725 / #265). Numeric defaults
|
|
11
|
+
* here would be merged into every loaded config by `applyConfigDefaults` and silently
|
|
12
|
+
* clobber a custom `maxFinalAttempts`, so `null` keeps existing configs behavior-identical.
|
|
13
|
+
*
|
|
14
|
+
* @type {Readonly<{ requireFinalVerdict: boolean; maxFinalAttempts: number; maxCodeReviewAttempts: number | null; maxPlanReviewAttempts: number | null }>}
|
|
15
|
+
*/
|
|
9
16
|
export const REVIEW_DEFAULTS = Object.freeze({
|
|
10
17
|
requireFinalVerdict: true,
|
|
11
18
|
maxFinalAttempts: 3,
|
|
19
|
+
maxCodeReviewAttempts: null,
|
|
20
|
+
maxPlanReviewAttempts: null,
|
|
12
21
|
});
|
|
13
22
|
|
|
14
23
|
/** @type {Readonly<{ path: string; autoWriteOn: readonly string[] }>} */
|
|
@@ -48,6 +48,20 @@ export const SETTINGS_FIELDS = Object.freeze([
|
|
|
48
48
|
label: "Require gate before integrate",
|
|
49
49
|
type: "boolean",
|
|
50
50
|
},
|
|
51
|
+
{
|
|
52
|
+
path: "review.maxCodeReviewAttempts",
|
|
53
|
+
label: "Max code review attempts (unset inherits maxFinalAttempts)",
|
|
54
|
+
type: "number",
|
|
55
|
+
min: 1,
|
|
56
|
+
max: 10,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
path: "review.maxPlanReviewAttempts",
|
|
60
|
+
label: "Max plan review attempts (unset inherits maxFinalAttempts)",
|
|
61
|
+
type: "number",
|
|
62
|
+
min: 1,
|
|
63
|
+
max: 10,
|
|
64
|
+
},
|
|
51
65
|
{
|
|
52
66
|
path: "agents.worker.model",
|
|
53
67
|
label: "Worker model",
|
|
@@ -15,6 +15,7 @@ const PROBE_BASENAME = '__probe__';
|
|
|
15
15
|
const SYNTHETIC_PROBE_EXTENSIONS = Object.freeze([
|
|
16
16
|
'.mjs',
|
|
17
17
|
'.js',
|
|
18
|
+
'.cjs',
|
|
18
19
|
'.ts',
|
|
19
20
|
'.tsx',
|
|
20
21
|
'.swift',
|
|
@@ -23,8 +24,90 @@ const SYNTHETIC_PROBE_EXTENSIONS = Object.freeze([
|
|
|
23
24
|
'.java',
|
|
24
25
|
'.rs',
|
|
25
26
|
'.md',
|
|
27
|
+
'.json',
|
|
28
|
+
'.yaml',
|
|
29
|
+
'.yml',
|
|
26
30
|
]);
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Cap on brace-expanded variants per scope entry. Bounds the synthetic probe
|
|
34
|
+
* count so wide `{a,b,c,...}` scopes cannot cause probe storms on large repos.
|
|
35
|
+
*/
|
|
36
|
+
const MAX_BRACE_EXPANSIONS = 32;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Expand `{a,b}` brace groups into concrete entry variants (micromatch-style).
|
|
40
|
+
* Nested groups are expanded recursively; expansion stops at
|
|
41
|
+
* MAX_BRACE_EXPANSIONS so probe generation stays bounded.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} entry
|
|
44
|
+
* @returns {string[]}
|
|
45
|
+
*/
|
|
46
|
+
function expandBracePattern(entry) {
|
|
47
|
+
/** @type {string[]} */
|
|
48
|
+
const results = [];
|
|
49
|
+
|
|
50
|
+
/** @param {string} text */
|
|
51
|
+
const visit = (text) => {
|
|
52
|
+
if (results.length >= MAX_BRACE_EXPANSIONS) return;
|
|
53
|
+
|
|
54
|
+
const start = text.indexOf('{');
|
|
55
|
+
if (start === -1) {
|
|
56
|
+
results.push(text);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Find the matching closing brace for the first group.
|
|
61
|
+
let depth = 0;
|
|
62
|
+
let end = -1;
|
|
63
|
+
for (let i = start; i < text.length; i++) {
|
|
64
|
+
if (text[i] === '{') depth++;
|
|
65
|
+
else if (text[i] === '}') {
|
|
66
|
+
depth--;
|
|
67
|
+
if (depth === 0) {
|
|
68
|
+
end = i;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (end === -1) {
|
|
74
|
+
// Unbalanced brace — treat as a literal character.
|
|
75
|
+
results.push(text);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Split the group body on top-level commas.
|
|
80
|
+
/** @type {string[]} */
|
|
81
|
+
const parts = [];
|
|
82
|
+
let last = start + 1;
|
|
83
|
+
depth = 0;
|
|
84
|
+
for (let i = start + 1; i < end; i++) {
|
|
85
|
+
const ch = text[i];
|
|
86
|
+
if (ch === '{') depth++;
|
|
87
|
+
else if (ch === '}') depth--;
|
|
88
|
+
else if (ch === ',' && depth === 0) {
|
|
89
|
+
parts.push(text.slice(last, i));
|
|
90
|
+
last = i + 1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
parts.push(text.slice(last, end));
|
|
94
|
+
|
|
95
|
+
if (parts.length <= 1) {
|
|
96
|
+
// `{a}` is not a brace set — keep the text as-is.
|
|
97
|
+
results.push(text);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (const part of parts) {
|
|
102
|
+
visit(text.slice(0, start) + part + text.slice(end + 1));
|
|
103
|
+
if (results.length >= MAX_BRACE_EXPANSIONS) return;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
visit(entry);
|
|
108
|
+
return results;
|
|
109
|
+
}
|
|
110
|
+
|
|
28
111
|
/**
|
|
29
112
|
* @param {string} raw: raw File Scope path or glob from PROMPT.md
|
|
30
113
|
* @returns {string|null}
|
|
@@ -66,15 +149,12 @@ function normalizeScopeEntry(raw) {
|
|
|
66
149
|
}
|
|
67
150
|
|
|
68
151
|
/**
|
|
69
|
-
* Expand
|
|
152
|
+
* Expand one brace-free scope entry into concrete probe paths.
|
|
70
153
|
*
|
|
71
|
-
* @param {string}
|
|
154
|
+
* @param {string} entry: normalized scope entry (no leading `./`)
|
|
72
155
|
* @returns {string[]}
|
|
73
156
|
*/
|
|
74
|
-
function
|
|
75
|
-
const entry = normalizeScopeEntry(raw);
|
|
76
|
-
if (!entry) return [];
|
|
77
|
-
|
|
157
|
+
function expandSingleEntryProbes(entry) {
|
|
78
158
|
/** @type {Set<string>} */
|
|
79
159
|
const probes = new Set([entry]);
|
|
80
160
|
|
|
@@ -110,6 +190,28 @@ function expandScopeEntryProbes(raw) {
|
|
|
110
190
|
return [...probes];
|
|
111
191
|
}
|
|
112
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Expand a single File Scope entry into concrete paths for glob overlap probes.
|
|
195
|
+
* Brace groups (`{a,b}`) are expanded first so probes cover every alternative.
|
|
196
|
+
*
|
|
197
|
+
* @param {string} raw
|
|
198
|
+
* @returns {string[]}
|
|
199
|
+
*/
|
|
200
|
+
function expandScopeEntryProbes(raw) {
|
|
201
|
+
const entry = normalizeScopeEntry(raw);
|
|
202
|
+
if (!entry) return [];
|
|
203
|
+
|
|
204
|
+
/** @type {Set<string>} */
|
|
205
|
+
const probes = new Set();
|
|
206
|
+
for (const variant of expandBracePattern(entry)) {
|
|
207
|
+
for (const probe of expandSingleEntryProbes(variant)) {
|
|
208
|
+
probes.add(probe);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return [...probes];
|
|
213
|
+
}
|
|
214
|
+
|
|
113
215
|
/**
|
|
114
216
|
* @param {string[]} fileScope
|
|
115
217
|
* @returns {string[]}
|
|
@@ -136,7 +238,7 @@ export function expandFileScopeProbes(fileScope) {
|
|
|
136
238
|
* @returns {boolean}
|
|
137
239
|
*/
|
|
138
240
|
function patternHasGlobMeta(pattern) {
|
|
139
|
-
return /[*?[\\]/.test(pattern);
|
|
241
|
+
return /[*?[\\]{}]/.test(pattern);
|
|
140
242
|
}
|
|
141
243
|
|
|
142
244
|
/**
|
package/src/process/liveness.mjs
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Cross-platform process liveness
|
|
2
|
+
* Cross-platform process liveness checks (signal 0 / kill -0 equivalent),
|
|
3
|
+
* plus engine liveness paired with process start time (SP-715 / #259).
|
|
3
4
|
*/
|
|
4
5
|
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Default tolerance (ms) when comparing a probed process start time with the
|
|
11
|
+
* stored `engineStartedAt`. Absorbs `ps lstart` second-level granularity and
|
|
12
|
+
* the delay between engine process spawn and `recordBatchEnginePid`.
|
|
13
|
+
*/
|
|
14
|
+
export const ENGINE_STARTTIME_TOLERANCE_MS = 60_000;
|
|
15
|
+
|
|
5
16
|
/**
|
|
6
17
|
* @param {unknown} pid
|
|
7
18
|
* @returns {boolean}
|
|
@@ -19,3 +30,179 @@ export function isProcessAlive(pid) {
|
|
|
19
30
|
return false;
|
|
20
31
|
}
|
|
21
32
|
}
|
|
33
|
+
|
|
34
|
+
/** @type {number|null} */
|
|
35
|
+
let cachedClockTicksPerSecond = null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Clock ticks per second (sysconf _SC_CLK_TCK) for /proc starttime conversion.
|
|
39
|
+
*
|
|
40
|
+
* @returns {number}
|
|
41
|
+
*/
|
|
42
|
+
function clockTicksPerSecond() {
|
|
43
|
+
if (cachedClockTicksPerSecond != null) return cachedClockTicksPerSecond;
|
|
44
|
+
let hz = 100;
|
|
45
|
+
try {
|
|
46
|
+
const out = execFileSync("getconf", ["CLK_TCK"], {
|
|
47
|
+
encoding: "utf-8",
|
|
48
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
49
|
+
}).trim();
|
|
50
|
+
const parsed = Number(out);
|
|
51
|
+
if (Number.isFinite(parsed) && parsed > 0) hz = parsed;
|
|
52
|
+
} catch {
|
|
53
|
+
/* getconf unavailable — Linux default USER_HZ is 100 */
|
|
54
|
+
}
|
|
55
|
+
cachedClockTicksPerSecond = hz;
|
|
56
|
+
return hz;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Linux: absolute process start time from `/proc/<pid>/starttime` (field 22 of
|
|
61
|
+
* stat, clock ticks since boot) combined with `btime` from /proc/stat.
|
|
62
|
+
* The comm field (2) may contain spaces/parens, so fields are parsed after the
|
|
63
|
+
* last ")".
|
|
64
|
+
*
|
|
65
|
+
* @param {number} pid
|
|
66
|
+
* @returns {number|null} epoch ms
|
|
67
|
+
*/
|
|
68
|
+
function readLinuxProcessStartMs(pid) {
|
|
69
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
70
|
+
const closeParen = stat.lastIndexOf(")");
|
|
71
|
+
if (closeParen < 0) return null;
|
|
72
|
+
const rest = stat.slice(closeParen + 1).trim().split(/\s+/);
|
|
73
|
+
// rest[0] is field 3 (state); starttime is field 22 → index 19.
|
|
74
|
+
const startTicks = Number(rest[19]);
|
|
75
|
+
if (!Number.isFinite(startTicks) || startTicks < 0) return null;
|
|
76
|
+
const procStat = fs.readFileSync("/proc/stat", "utf-8");
|
|
77
|
+
const btimeLine = procStat.split("\n").find((line) => line.startsWith("btime "));
|
|
78
|
+
if (!btimeLine) return null;
|
|
79
|
+
const bootSeconds = Number(btimeLine.slice("btime ".length).trim());
|
|
80
|
+
if (!Number.isFinite(bootSeconds) || bootSeconds <= 0) return null;
|
|
81
|
+
return (bootSeconds + startTicks / clockTicksPerSecond()) * 1000;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @type {Record<string, number>} */
|
|
85
|
+
const PS_MONTH_INDEX = {
|
|
86
|
+
Jan: 0,
|
|
87
|
+
Feb: 1,
|
|
88
|
+
Mar: 2,
|
|
89
|
+
Apr: 3,
|
|
90
|
+
May: 4,
|
|
91
|
+
Jun: 5,
|
|
92
|
+
Jul: 6,
|
|
93
|
+
Aug: 7,
|
|
94
|
+
Sep: 8,
|
|
95
|
+
Oct: 9,
|
|
96
|
+
Nov: 10,
|
|
97
|
+
Dec: 11,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Parse `ps -o lstart=` output ("Www Mmm dd hh:mm:ss yyyy") without relying on
|
|
102
|
+
* Date.parse, whose acceptance of this shape is implementation-defined.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} text
|
|
105
|
+
* @returns {number|null} epoch ms (local time, matching ps output)
|
|
106
|
+
*/
|
|
107
|
+
function parsePsLstartMs(text) {
|
|
108
|
+
const match = /^\w{3}\s+(\w{3})\s+(\d{1,2})\s+(\d{2}):(\d{2}):(\d{2})\s+(\d{4})$/.exec(
|
|
109
|
+
text.trim(),
|
|
110
|
+
);
|
|
111
|
+
if (!match) return null;
|
|
112
|
+
const month = PS_MONTH_INDEX[match[1]];
|
|
113
|
+
if (month == null) return null;
|
|
114
|
+
const ms = new Date(
|
|
115
|
+
Number(match[6]),
|
|
116
|
+
month,
|
|
117
|
+
Number(match[2]),
|
|
118
|
+
Number(match[3]),
|
|
119
|
+
Number(match[4]),
|
|
120
|
+
Number(match[5]),
|
|
121
|
+
).getTime();
|
|
122
|
+
return Number.isFinite(ms) ? ms : null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* macOS / generic Unix fallback: process start time via `ps -p <pid> -o lstart=`.
|
|
127
|
+
*
|
|
128
|
+
* @param {number} pid
|
|
129
|
+
* @returns {number|null} epoch ms
|
|
130
|
+
*/
|
|
131
|
+
function readPsProcessStartMs(pid) {
|
|
132
|
+
const out = execFileSync("ps", ["-p", String(pid), "-o", "lstart="], {
|
|
133
|
+
encoding: "utf-8",
|
|
134
|
+
env: { ...process.env, LC_ALL: "C" },
|
|
135
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
136
|
+
}).trim();
|
|
137
|
+
if (!out) return null;
|
|
138
|
+
return parsePsLstartMs(out);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Best-effort absolute process start time (epoch ms) for a live pid.
|
|
143
|
+
* Returns null when the platform or probe cannot provide one.
|
|
144
|
+
*
|
|
145
|
+
* @param {unknown} pid
|
|
146
|
+
* @returns {number|null}
|
|
147
|
+
*/
|
|
148
|
+
export function probeProcessStartTimeMs(pid) {
|
|
149
|
+
const n = Number(pid);
|
|
150
|
+
if (!Number.isFinite(n) || n <= 0) return null;
|
|
151
|
+
// Windows limitation (SP-715 / #259): no start-time probe here; callers fall
|
|
152
|
+
// back to PID-only liveness, which can confuse a recycled PID for the engine.
|
|
153
|
+
if (process.platform === "win32") return null;
|
|
154
|
+
try {
|
|
155
|
+
if (process.platform === "linux") {
|
|
156
|
+
const fromProc = readLinuxProcessStartMs(n);
|
|
157
|
+
if (fromProc != null) return fromProc;
|
|
158
|
+
}
|
|
159
|
+
return readPsProcessStartMs(n);
|
|
160
|
+
} catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Engine liveness paired with the stored `engineStartedAt` so a recycled PID
|
|
167
|
+
* owned by an unrelated process is not mistaken for the batch engine
|
|
168
|
+
* (SP-715 / #259).
|
|
169
|
+
*
|
|
170
|
+
* Fallbacks (all preserve the previous PID-only behavior):
|
|
171
|
+
* - no `expectedStartedAt` recorded → PID-only
|
|
172
|
+
* - Windows → PID-only (documented limitation: PID reuse is not detected)
|
|
173
|
+
* - start-time probe unavailable → PID-only
|
|
174
|
+
*
|
|
175
|
+
* @param {unknown} pid
|
|
176
|
+
* @param {unknown} expectedStartedAt epoch ms recorded by recordBatchEnginePid
|
|
177
|
+
* @param {object} [options]
|
|
178
|
+
* @param {(pid: unknown) => boolean} [options.isAlive] injectable liveness probe
|
|
179
|
+
* @param {(pid: unknown) => number|null} [options.probeStartTimeMs] injectable start-time probe
|
|
180
|
+
* @param {string} [options.platform] injectable platform override
|
|
181
|
+
* @param {number} [options.toleranceMs] match tolerance (default ENGINE_STARTTIME_TOLERANCE_MS)
|
|
182
|
+
* @returns {boolean}
|
|
183
|
+
*/
|
|
184
|
+
export function isEngineProcessAlive(pid, expectedStartedAt, options = {}) {
|
|
185
|
+
const isAlive = options.isAlive ?? isProcessAlive;
|
|
186
|
+
if (!isAlive(pid)) return false;
|
|
187
|
+
|
|
188
|
+
const expected = Number(expectedStartedAt);
|
|
189
|
+
if (!Number.isFinite(expected) || expected <= 0) return true;
|
|
190
|
+
|
|
191
|
+
const platform = options.platform ?? process.platform;
|
|
192
|
+
if (platform === "win32") return true;
|
|
193
|
+
|
|
194
|
+
const probe = options.probeStartTimeMs ?? probeProcessStartTimeMs;
|
|
195
|
+
/** @type {number|null} */
|
|
196
|
+
let startedMs = null;
|
|
197
|
+
try {
|
|
198
|
+
startedMs = probe(pid);
|
|
199
|
+
} catch {
|
|
200
|
+
startedMs = null;
|
|
201
|
+
}
|
|
202
|
+
if (startedMs == null || !Number.isFinite(startedMs) || startedMs <= 0) return true;
|
|
203
|
+
|
|
204
|
+
const tolerance = Number.isFinite(Number(options.toleranceMs))
|
|
205
|
+
? Number(options.toleranceMs)
|
|
206
|
+
: ENGINE_STARTTIME_TOLERANCE_MS;
|
|
207
|
+
return Math.abs(startedMs - expected) <= tolerance;
|
|
208
|
+
}
|
|
@@ -17,6 +17,10 @@ import path from 'node:path';
|
|
|
17
17
|
import { resolveTasksRootPath } from '../../config/env-overrides.mjs';
|
|
18
18
|
import { loadSpineConfig } from '../../config/spine-config-load.mjs';
|
|
19
19
|
import { findCyclePath } from '../../planner/cycles.mjs';
|
|
20
|
+
import {
|
|
21
|
+
fileScopesOverlap as plannerFileScopesOverlap,
|
|
22
|
+
pathsOverlap as plannerPathsOverlap,
|
|
23
|
+
} from '../../planner/file-scope.mjs';
|
|
20
24
|
import { buildGraph, topoWaves } from '../../planner/graph.mjs';
|
|
21
25
|
import { parseScope } from '../../planner/scope.mjs';
|
|
22
26
|
import {
|
|
@@ -39,46 +43,28 @@ import {
|
|
|
39
43
|
* }} AnalyzeFinding
|
|
40
44
|
*/
|
|
41
45
|
|
|
42
|
-
function normalizeFileScopePath(p) {
|
|
43
|
-
let s = String(p ?? '').trim();
|
|
44
|
-
if (!s) return null;
|
|
45
|
-
|
|
46
|
-
s = s.replace(/\\/g, '/');
|
|
47
|
-
if (s.startsWith('./')) s = s.slice(2);
|
|
48
|
-
s = s.replace(/\/+$/g, '');
|
|
49
|
-
|
|
50
|
-
if (s.endsWith('/*')) s = s.slice(0, -2);
|
|
51
|
-
if (s.endsWith('/**')) s = s.slice(0, -3);
|
|
52
|
-
|
|
53
|
-
return s || null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
/**
|
|
47
|
+
* Re-exported from the planner so `spine tasks analyze` uses the same
|
|
48
|
+
* glob-aware overlap detection (brace globs and extension probes, #269).
|
|
49
|
+
*
|
|
57
50
|
* @param {string} a
|
|
58
51
|
* @param {string} b
|
|
59
52
|
* @returns {boolean}
|
|
60
53
|
*/
|
|
61
54
|
export function pathsOverlap(a, b) {
|
|
62
|
-
|
|
63
|
-
return a.startsWith(b + '/') || b.startsWith(a + '/');
|
|
55
|
+
return plannerPathsOverlap(a, b);
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
/**
|
|
59
|
+
* Re-exported from the planner so `spine tasks analyze` flags the same brace
|
|
60
|
+
* glob and extension collisions as the wave planner (#269).
|
|
61
|
+
*
|
|
67
62
|
* @param {string[]} left
|
|
68
63
|
* @param {string[]} right
|
|
69
64
|
* @returns {boolean}
|
|
70
65
|
*/
|
|
71
66
|
export function fileScopesOverlap(left, right) {
|
|
72
|
-
|
|
73
|
-
const rightPaths = right.map(normalizeFileScopePath).filter(Boolean);
|
|
74
|
-
|
|
75
|
-
for (const a of leftPaths) {
|
|
76
|
-
for (const b of rightPaths) {
|
|
77
|
-
if (pathsOverlap(a, b)) return true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return false;
|
|
67
|
+
return plannerFileScopesOverlap(left, right);
|
|
82
68
|
}
|
|
83
69
|
|
|
84
70
|
/**
|
|
@@ -274,7 +260,8 @@ export function collectPromptJsonDepsDriftFindings(tasksById, depsJson) {
|
|
|
274
260
|
continue;
|
|
275
261
|
}
|
|
276
262
|
|
|
277
|
-
const
|
|
263
|
+
const jsonDepSet = new Set(jsonDeps);
|
|
264
|
+
const missing = promptDeps.filter((depId) => !jsonDepSet.has(depId));
|
|
278
265
|
if (missing.length === 0) continue;
|
|
279
266
|
|
|
280
267
|
findings.push({
|