getshrike 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +27 -2
- package/bin/shrike.mjs +30 -0
- package/dist/apply.d.ts +6 -0
- package/dist/args.d.ts +16 -0
- package/dist/baseline.d.ts +8 -0
- package/dist/build/builder.d.ts +9 -0
- package/dist/build/load.d.ts +3 -0
- package/dist/build/normalize.d.ts +11 -0
- package/dist/build/paths.d.ts +32 -0
- package/dist/build/records.d.ts +10 -0
- package/dist/build/types.d.ts +58 -0
- package/dist/build.d.ts +17 -0
- package/dist/cli-types.d.ts +168 -0
- package/dist/commands/basic.d.ts +10 -0
- package/dist/commands/hook.d.ts +23 -0
- package/dist/commands/mcp.d.ts +8 -0
- package/dist/commands/prune.d.ts +5 -0
- package/dist/commands/scan.d.ts +3 -0
- package/dist/commands/verify.d.ts +2 -0
- package/dist/config.d.ts +80 -0
- package/dist/config.js +1054 -0
- package/dist/dependencies.d.ts +86 -0
- package/dist/diagnostics.d.ts +37 -0
- package/dist/engine.d.ts +51 -0
- package/dist/errors.d.ts +37 -0
- package/dist/git.d.ts +25 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1103 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +6609 -0
- package/dist/output.d.ts +30 -0
- package/dist/plan-store.d.ts +16 -0
- package/dist/receipts.d.ts +23 -0
- package/dist/recovery.d.ts +43 -0
- package/dist/render.d.ts +4 -0
- package/dist/session.d.ts +24 -0
- package/dist/timing.d.ts +3 -0
- package/dist/version.d.ts +4 -0
- package/package.json +70 -3
package/dist/config.js
ADDED
|
@@ -0,0 +1,1054 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// ../verifier/src/types.ts
|
|
12
|
+
var init_types = __esm({
|
|
13
|
+
"../verifier/src/types.ts"() {
|
|
14
|
+
"use strict";
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// ../verifier/src/normalize.ts
|
|
19
|
+
import { createHash } from "node:crypto";
|
|
20
|
+
import { basename } from "node:path";
|
|
21
|
+
import { homedir } from "node:os";
|
|
22
|
+
function stripAnsi(input) {
|
|
23
|
+
return input.replace(ANSI_PATTERN, "");
|
|
24
|
+
}
|
|
25
|
+
function replaceLiteralAll(input, needle) {
|
|
26
|
+
if (needle.length === 0) return input;
|
|
27
|
+
const forward = needle.replaceAll("\\", "/");
|
|
28
|
+
const backward = forward.replaceAll("/", "\\");
|
|
29
|
+
return input.split(forward).join("").split(backward).join("");
|
|
30
|
+
}
|
|
31
|
+
function normalizeOutput(input, options = {}) {
|
|
32
|
+
let text = input.replace(/\r\n?/g, "\n");
|
|
33
|
+
text = stripAnsi(text);
|
|
34
|
+
text = text.replace(/\u0000/g, "");
|
|
35
|
+
const roots = [
|
|
36
|
+
options.cwd,
|
|
37
|
+
options.root,
|
|
38
|
+
options.homeDir ?? homedir()
|
|
39
|
+
].filter((value) => Boolean(value && value.length > 1));
|
|
40
|
+
for (const root of roots) {
|
|
41
|
+
text = replaceLiteralAll(text, root);
|
|
42
|
+
}
|
|
43
|
+
text = text.replace(ABSOLUTE_PATH_PATTERN, (match) => {
|
|
44
|
+
const normalized = match.replaceAll("\\", "/");
|
|
45
|
+
return basename(normalized);
|
|
46
|
+
});
|
|
47
|
+
text = text.replace(ISO_TIMESTAMP_PATTERN, "<timestamp>");
|
|
48
|
+
text = text.replace(DATE_PATTERN, "<date>");
|
|
49
|
+
text = text.replace(DURATION_WORD_PATTERN, "<duration>");
|
|
50
|
+
text = text.replace(DURATION_PATTERN, "<duration>");
|
|
51
|
+
const maxLines = options.maxLines ?? 400;
|
|
52
|
+
const lines = [];
|
|
53
|
+
for (const rawLine of text.split("\n")) {
|
|
54
|
+
const line = rawLine.replace(/[ \t]+/g, " ").trim();
|
|
55
|
+
if (line.length === 0) continue;
|
|
56
|
+
if (lines.length > 0 && lines[lines.length - 1] === line) continue;
|
|
57
|
+
lines.push(line);
|
|
58
|
+
if (lines.length >= maxLines) break;
|
|
59
|
+
}
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
function hashText(input) {
|
|
63
|
+
const digest = createHash("sha256").update(input, "utf8").digest("hex");
|
|
64
|
+
return `sha256:${digest}`;
|
|
65
|
+
}
|
|
66
|
+
function failureSignature(input, options = {}) {
|
|
67
|
+
return hashText(normalizeOutput(input, options));
|
|
68
|
+
}
|
|
69
|
+
function capOutput(input, maxBytes = 8192) {
|
|
70
|
+
if (Buffer.byteLength(input, "utf8") <= maxBytes) return input;
|
|
71
|
+
const truncated = Buffer.from(input, "utf8").subarray(0, maxBytes).toString("utf8");
|
|
72
|
+
return `${truncated}
|
|
73
|
+
[output truncated]`;
|
|
74
|
+
}
|
|
75
|
+
var ANSI_PATTERN, ABSOLUTE_PATH_PATTERN, DURATION_WORD_PATTERN, DURATION_PATTERN, ISO_TIMESTAMP_PATTERN, DATE_PATTERN;
|
|
76
|
+
var init_normalize = __esm({
|
|
77
|
+
"../verifier/src/normalize.ts"() {
|
|
78
|
+
"use strict";
|
|
79
|
+
ANSI_PATTERN = /\u001B(?:\][^\u0007]*(?:\u0007|\u001B\\)|\[[0-?]*[ -/]*[@-~]|[@-_])/g;
|
|
80
|
+
ABSOLUTE_PATH_PATTERN = /(?<![\w:])(?:[A-Za-z]:[\\/]|\/)(?:[^\s:;"'`()<>[\]{}]+[\\/])*[^\s:;"'`()<>[\]{}]+/g;
|
|
81
|
+
DURATION_WORD_PATTERN = /\b(?:duration|elapsed|time|took|finished(?:\s+in)?)\s*[:=]?\s*\d+(?:\.\d+)?\s*(?:ns|µs|us|ms|s|secs?|seconds?|m|min|mins|minutes?)\b/gi;
|
|
82
|
+
DURATION_PATTERN = /\b\d+(?:\.\d+)?\s*(?:ns|µs|us|ms|secs?|seconds?|mins?|minutes?)\b/gi;
|
|
83
|
+
ISO_TIMESTAMP_PATTERN = /\b\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?\b/g;
|
|
84
|
+
DATE_PATTERN = /\b\d{4}-\d{2}-\d{2}\b/g;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// ../verifier/src/run/environment.ts
|
|
89
|
+
function baseEnvironment() {
|
|
90
|
+
const env = {};
|
|
91
|
+
for (const key of SAFE_ENV_KEYS) {
|
|
92
|
+
const value = process.env[key];
|
|
93
|
+
if (value !== void 0) env[key] = value;
|
|
94
|
+
}
|
|
95
|
+
return env;
|
|
96
|
+
}
|
|
97
|
+
function shellForPlatform() {
|
|
98
|
+
if (process.platform === "win32") {
|
|
99
|
+
return {
|
|
100
|
+
file: process.env.ComSpec ?? "cmd.exe",
|
|
101
|
+
args: ["/d", "/s", "/c"]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return { file: "/bin/sh", args: ["-c"] };
|
|
105
|
+
}
|
|
106
|
+
function killProcess(child) {
|
|
107
|
+
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
108
|
+
try {
|
|
109
|
+
if (process.platform !== "win32" && child.pid !== void 0) {
|
|
110
|
+
process.kill(-child.pid, "SIGTERM");
|
|
111
|
+
} else {
|
|
112
|
+
child.kill("SIGTERM");
|
|
113
|
+
}
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
const timer = setTimeout(() => {
|
|
117
|
+
try {
|
|
118
|
+
if (process.platform !== "win32" && child.pid !== void 0) {
|
|
119
|
+
process.kill(-child.pid, "SIGKILL");
|
|
120
|
+
} else {
|
|
121
|
+
child.kill("SIGKILL");
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
}, 1e3);
|
|
126
|
+
timer.unref();
|
|
127
|
+
}
|
|
128
|
+
var DEFAULT_TIMEOUT_MS, MAX_CAPTURE_BYTES, SAFE_ENV_KEYS;
|
|
129
|
+
var init_environment = __esm({
|
|
130
|
+
"../verifier/src/run/environment.ts"() {
|
|
131
|
+
"use strict";
|
|
132
|
+
DEFAULT_TIMEOUT_MS = 3e5;
|
|
133
|
+
MAX_CAPTURE_BYTES = 1048576;
|
|
134
|
+
SAFE_ENV_KEYS = [
|
|
135
|
+
"PATH",
|
|
136
|
+
"Path",
|
|
137
|
+
"PATHEXT",
|
|
138
|
+
"HOME",
|
|
139
|
+
"USERPROFILE",
|
|
140
|
+
"HOMEDRIVE",
|
|
141
|
+
"HOMEPATH",
|
|
142
|
+
"USER",
|
|
143
|
+
"LOGNAME",
|
|
144
|
+
"SHELL",
|
|
145
|
+
"TMPDIR",
|
|
146
|
+
"TMP",
|
|
147
|
+
"TEMP",
|
|
148
|
+
"SystemRoot",
|
|
149
|
+
"SYSTEMROOT",
|
|
150
|
+
"WINDIR",
|
|
151
|
+
"ComSpec",
|
|
152
|
+
"COMSPEC",
|
|
153
|
+
"LANG",
|
|
154
|
+
"LC_ALL",
|
|
155
|
+
"LC_CTYPE",
|
|
156
|
+
"TERM",
|
|
157
|
+
"NO_COLOR",
|
|
158
|
+
"FORCE_COLOR",
|
|
159
|
+
"CI"
|
|
160
|
+
];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// ../verifier/src/run/execute.ts
|
|
165
|
+
import { spawn } from "node:child_process";
|
|
166
|
+
function executeCommand(command, options = {}) {
|
|
167
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
168
|
+
const maxBytes = options.maxOutputBytes ?? MAX_CAPTURE_BYTES;
|
|
169
|
+
const shell = shellForPlatform();
|
|
170
|
+
const startedAt = Date.now();
|
|
171
|
+
return new Promise((resolve2) => {
|
|
172
|
+
let stdout = "";
|
|
173
|
+
let stderr = "";
|
|
174
|
+
let timedOut = false;
|
|
175
|
+
let spawnError = null;
|
|
176
|
+
let settled = false;
|
|
177
|
+
let timeoutTimer;
|
|
178
|
+
let child;
|
|
179
|
+
try {
|
|
180
|
+
child = spawn(shell.file, [...shell.args, command], {
|
|
181
|
+
cwd: options.cwd,
|
|
182
|
+
// Inherit only the check-safe host environment. Secrets are passed
|
|
183
|
+
// explicitly through CheckSpec.env; see docs/09 §2.3.
|
|
184
|
+
env: { ...baseEnvironment(), ...options.env },
|
|
185
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
186
|
+
detached: process.platform !== "win32",
|
|
187
|
+
windowsHide: true
|
|
188
|
+
});
|
|
189
|
+
} catch (error) {
|
|
190
|
+
resolve2({
|
|
191
|
+
exitCode: null,
|
|
192
|
+
signal: null,
|
|
193
|
+
stdout: "",
|
|
194
|
+
stderr: "",
|
|
195
|
+
durationMs: Date.now() - startedAt,
|
|
196
|
+
timedOut: false,
|
|
197
|
+
spawnError: error instanceof Error ? error.message : String(error)
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const append = (current, chunk) => {
|
|
202
|
+
if (Buffer.byteLength(current, "utf8") >= maxBytes) return current;
|
|
203
|
+
const remaining = maxBytes - Buffer.byteLength(current, "utf8");
|
|
204
|
+
return current + chunk.subarray(0, remaining).toString("utf8");
|
|
205
|
+
};
|
|
206
|
+
child.stdout?.on("data", (chunk) => {
|
|
207
|
+
stdout = append(stdout, chunk);
|
|
208
|
+
});
|
|
209
|
+
child.stderr?.on("data", (chunk) => {
|
|
210
|
+
stderr = append(stderr, chunk);
|
|
211
|
+
});
|
|
212
|
+
child.on("error", (error) => {
|
|
213
|
+
spawnError = error.message;
|
|
214
|
+
});
|
|
215
|
+
const finish = (exitCode, signal) => {
|
|
216
|
+
if (settled) return;
|
|
217
|
+
settled = true;
|
|
218
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
219
|
+
resolve2({
|
|
220
|
+
exitCode,
|
|
221
|
+
signal,
|
|
222
|
+
stdout,
|
|
223
|
+
stderr,
|
|
224
|
+
durationMs: Date.now() - startedAt,
|
|
225
|
+
timedOut,
|
|
226
|
+
spawnError
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
child.on("close", (code, signal) => {
|
|
230
|
+
finish(code, signal);
|
|
231
|
+
});
|
|
232
|
+
if (timeoutMs > 0) {
|
|
233
|
+
timeoutTimer = setTimeout(() => {
|
|
234
|
+
timedOut = true;
|
|
235
|
+
killProcess(child);
|
|
236
|
+
}, timeoutMs);
|
|
237
|
+
timeoutTimer.unref();
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function combinedOutput(raw) {
|
|
242
|
+
const parts = [raw.stdout, raw.stderr].filter((part) => part.length > 0);
|
|
243
|
+
if (raw.spawnError) parts.push(raw.spawnError);
|
|
244
|
+
return parts.join("\n");
|
|
245
|
+
}
|
|
246
|
+
var init_execute = __esm({
|
|
247
|
+
"../verifier/src/run/execute.ts"() {
|
|
248
|
+
"use strict";
|
|
249
|
+
init_environment();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// ../verifier/src/run/check.ts
|
|
254
|
+
import { isAbsolute, join } from "node:path";
|
|
255
|
+
async function runCheck(spec, options = {}) {
|
|
256
|
+
const cwd = spec.cwd === void 0 ? options.cwd : isAbsolute(spec.cwd) ? spec.cwd : join(options.cwd ?? process.cwd(), spec.cwd);
|
|
257
|
+
const raw = await executeCommand(spec.command, {
|
|
258
|
+
...options,
|
|
259
|
+
cwd,
|
|
260
|
+
timeoutMs: spec.timeoutMs ?? options.timeoutMs,
|
|
261
|
+
env: { ...options.env, ...spec.env }
|
|
262
|
+
});
|
|
263
|
+
let status;
|
|
264
|
+
if (raw.spawnError) {
|
|
265
|
+
status = "error";
|
|
266
|
+
} else if (raw.timedOut) {
|
|
267
|
+
status = "timeout";
|
|
268
|
+
} else if (raw.exitCode === 0) {
|
|
269
|
+
status = "pass";
|
|
270
|
+
} else {
|
|
271
|
+
status = "fail";
|
|
272
|
+
}
|
|
273
|
+
const combined = combinedOutput(raw);
|
|
274
|
+
const normalized = normalizeOutput(combined, {
|
|
275
|
+
cwd,
|
|
276
|
+
root: options.cwd
|
|
277
|
+
});
|
|
278
|
+
const signature = status === "pass" ? null : failureSignature(combined, { cwd, root: options.cwd });
|
|
279
|
+
return {
|
|
280
|
+
name: spec.name,
|
|
281
|
+
command: spec.command,
|
|
282
|
+
status,
|
|
283
|
+
exitCode: raw.exitCode,
|
|
284
|
+
durationMs: raw.durationMs,
|
|
285
|
+
output: capOutput(normalized),
|
|
286
|
+
signature,
|
|
287
|
+
timedOut: raw.timedOut,
|
|
288
|
+
reruns: 0,
|
|
289
|
+
flaky: false,
|
|
290
|
+
required: spec.required ?? true
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
async function runCheckWithReruns(spec, options = {}) {
|
|
294
|
+
const first = await runCheck(spec, options);
|
|
295
|
+
if (first.status === "pass" || first.status === "skipped") return first;
|
|
296
|
+
const extraRuns = Math.max(0, spec.reruns ?? 0);
|
|
297
|
+
if (extraRuns === 0) return first;
|
|
298
|
+
const failures = [first];
|
|
299
|
+
let totalDuration = first.durationMs;
|
|
300
|
+
for (let attempt = 1; attempt <= extraRuns; attempt += 1) {
|
|
301
|
+
const next = await runCheck(spec, options);
|
|
302
|
+
totalDuration += next.durationMs;
|
|
303
|
+
if (next.status === "pass") {
|
|
304
|
+
return {
|
|
305
|
+
...next,
|
|
306
|
+
durationMs: totalDuration,
|
|
307
|
+
reruns: attempt,
|
|
308
|
+
flaky: true,
|
|
309
|
+
signature: first.signature,
|
|
310
|
+
output: first.output
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
failures.push(next);
|
|
314
|
+
}
|
|
315
|
+
const signatures = new Set(
|
|
316
|
+
failures.map((result) => result.signature).filter((value) => Boolean(value))
|
|
317
|
+
);
|
|
318
|
+
const last = failures[failures.length - 1] ?? first;
|
|
319
|
+
return {
|
|
320
|
+
...last,
|
|
321
|
+
durationMs: totalDuration,
|
|
322
|
+
reruns: extraRuns,
|
|
323
|
+
flaky: signatures.size > 1,
|
|
324
|
+
signature: first.signature,
|
|
325
|
+
output: first.output
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async function runChecks(specs, options = {}) {
|
|
329
|
+
const results = [];
|
|
330
|
+
for (const spec of specs) {
|
|
331
|
+
results.push(await runCheckWithReruns(spec, options));
|
|
332
|
+
}
|
|
333
|
+
return results;
|
|
334
|
+
}
|
|
335
|
+
var init_check = __esm({
|
|
336
|
+
"../verifier/src/run/check.ts"() {
|
|
337
|
+
"use strict";
|
|
338
|
+
init_normalize();
|
|
339
|
+
init_execute();
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// ../verifier/src/run.ts
|
|
344
|
+
var init_run = __esm({
|
|
345
|
+
"../verifier/src/run.ts"() {
|
|
346
|
+
"use strict";
|
|
347
|
+
init_environment();
|
|
348
|
+
init_execute();
|
|
349
|
+
init_check();
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// ../verifier/src/classify.ts
|
|
354
|
+
function classifyCheck(after, baseline) {
|
|
355
|
+
const baselineStatus = baseline?.status ?? "missing";
|
|
356
|
+
if (after.status === "skipped") return "skipped";
|
|
357
|
+
if (after.flaky) return "flaky";
|
|
358
|
+
if (after.status === "pass") {
|
|
359
|
+
if (baselineStatus === "fail" || baselineStatus === "timeout" || baselineStatus === "error") {
|
|
360
|
+
return "improvement";
|
|
361
|
+
}
|
|
362
|
+
return "pass";
|
|
363
|
+
}
|
|
364
|
+
const sameSignature = after.signature !== null && baseline?.signature !== null && baseline?.signature !== void 0 && after.signature === baseline.signature;
|
|
365
|
+
if (after.status === "timeout") {
|
|
366
|
+
if (baselineStatus === "timeout" && sameSignature) return "known-failure";
|
|
367
|
+
if (baselineStatus === "fail" && sameSignature) return "known-failure";
|
|
368
|
+
return "timeout";
|
|
369
|
+
}
|
|
370
|
+
if (after.status === "error") {
|
|
371
|
+
return "error";
|
|
372
|
+
}
|
|
373
|
+
if (baselineStatus === "fail" || baselineStatus === "timeout" || baselineStatus === "error") {
|
|
374
|
+
return sameSignature ? "known-failure" : "new-failure";
|
|
375
|
+
}
|
|
376
|
+
return "fail";
|
|
377
|
+
}
|
|
378
|
+
function compareToBaseline(baseline, after) {
|
|
379
|
+
const byName = /* @__PURE__ */ new Map();
|
|
380
|
+
for (const check of baseline.checks) {
|
|
381
|
+
byName.set(check.name, check);
|
|
382
|
+
}
|
|
383
|
+
return after.map((result) => {
|
|
384
|
+
const baselineResult = byName.get(result.name);
|
|
385
|
+
return {
|
|
386
|
+
...result,
|
|
387
|
+
baselineStatus: baselineResult?.status ?? "missing",
|
|
388
|
+
baselineSignature: baselineResult?.signature ?? null,
|
|
389
|
+
classification: classifyCheck(result, baselineResult)
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function isBlocking(classification) {
|
|
394
|
+
return classification === "new-failure" || classification === "fail" || classification === "timeout" || classification === "error";
|
|
395
|
+
}
|
|
396
|
+
function hasBlockingFailure(checks, options = {}) {
|
|
397
|
+
const requiredOnly = options.requiredOnly ?? true;
|
|
398
|
+
return checks.some((check) => {
|
|
399
|
+
if (requiredOnly && !check.required) return false;
|
|
400
|
+
return isBlocking(check.classification);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
function batchOutcome(checks, options = {}) {
|
|
404
|
+
const requiredOnly = options.requiredOnly ?? true;
|
|
405
|
+
const considered = checks.filter((check) => !requiredOnly || check.required);
|
|
406
|
+
if (considered.some((check) => check.classification === "error")) return "error";
|
|
407
|
+
if (considered.some((check) => isBlocking(check.classification))) return "rejected";
|
|
408
|
+
if (considered.some((check) => check.classification === "flaky")) return "flaky";
|
|
409
|
+
if (considered.some((check) => check.classification === "known-failure")) {
|
|
410
|
+
return "known-failure";
|
|
411
|
+
}
|
|
412
|
+
return "verified";
|
|
413
|
+
}
|
|
414
|
+
function summarizeChecks(checks) {
|
|
415
|
+
if (checks.length === 0) return "no checks";
|
|
416
|
+
return checks.map((check) => `${check.name}:${check.classification}`).join(" ");
|
|
417
|
+
}
|
|
418
|
+
function unstableBaseline(baseline) {
|
|
419
|
+
return baseline.checks.filter((check) => check.flaky);
|
|
420
|
+
}
|
|
421
|
+
var init_classify = __esm({
|
|
422
|
+
"../verifier/src/classify.ts"() {
|
|
423
|
+
"use strict";
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// ../verifier/src/baseline.ts
|
|
428
|
+
async function captureBaseline(options) {
|
|
429
|
+
const runOptions = {
|
|
430
|
+
cwd: options.cwd,
|
|
431
|
+
env: options.env
|
|
432
|
+
};
|
|
433
|
+
const checks = await runChecks(options.specs, runOptions);
|
|
434
|
+
return {
|
|
435
|
+
schemaVersion: "1.0",
|
|
436
|
+
head: options.head,
|
|
437
|
+
capturedAt: options.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
438
|
+
checks,
|
|
439
|
+
...options.configHash ? { configHash: options.configHash } : {}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function emptyBaseline(head, options = {}) {
|
|
443
|
+
return {
|
|
444
|
+
schemaVersion: "1.0",
|
|
445
|
+
head,
|
|
446
|
+
capturedAt: options.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
447
|
+
checks: [],
|
|
448
|
+
...options.configHash ? { configHash: options.configHash } : {}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
var init_baseline = __esm({
|
|
452
|
+
"../verifier/src/baseline.ts"() {
|
|
453
|
+
"use strict";
|
|
454
|
+
init_run();
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// ../verifier/src/checks.ts
|
|
459
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
460
|
+
import { join as join2 } from "node:path";
|
|
461
|
+
function isInteractiveScript(script) {
|
|
462
|
+
return /(^|[\s;&|])(--watch|-w|--watchAll|watch)([\s;&|]|$)/i.test(script) || /\b(vite|webpack|next|nodemon)\s+(dev|serve)\b/i.test(script);
|
|
463
|
+
}
|
|
464
|
+
function readPackageScripts(root) {
|
|
465
|
+
const path = join2(root, "package.json");
|
|
466
|
+
if (!existsSync(path)) return {};
|
|
467
|
+
try {
|
|
468
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
469
|
+
if (typeof parsed === "object" && parsed !== null && "scripts" in parsed && typeof parsed.scripts === "object" && parsed.scripts !== null) {
|
|
470
|
+
const scripts = {};
|
|
471
|
+
for (const [key, value] of Object.entries(parsed.scripts)) {
|
|
472
|
+
if (typeof value === "string") scripts[key] = value;
|
|
473
|
+
}
|
|
474
|
+
return scripts;
|
|
475
|
+
}
|
|
476
|
+
} catch {
|
|
477
|
+
return {};
|
|
478
|
+
}
|
|
479
|
+
return {};
|
|
480
|
+
}
|
|
481
|
+
function detectPackageManager(root) {
|
|
482
|
+
const packageJsonPath = join2(root, "package.json");
|
|
483
|
+
if (existsSync(packageJsonPath)) {
|
|
484
|
+
try {
|
|
485
|
+
const parsed = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
486
|
+
if (typeof parsed === "object" && parsed !== null && "packageManager" in parsed && typeof parsed.packageManager === "string") {
|
|
487
|
+
const name = parsed.packageManager.split("@")[0];
|
|
488
|
+
if (name === "pnpm" || name === "npm" || name === "yarn" || name === "bun") {
|
|
489
|
+
return name;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
} catch {
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if (existsSync(join2(root, "pnpm-lock.yaml"))) return "pnpm";
|
|
496
|
+
if (existsSync(join2(root, "package-lock.json"))) return "npm";
|
|
497
|
+
if (existsSync(join2(root, "yarn.lock"))) return "yarn";
|
|
498
|
+
if (existsSync(join2(root, "bun.lockb")) || existsSync(join2(root, "bun.lock"))) {
|
|
499
|
+
return "bun";
|
|
500
|
+
}
|
|
501
|
+
return "pnpm";
|
|
502
|
+
}
|
|
503
|
+
function managerCommand(manager, script) {
|
|
504
|
+
if (manager === "npm") return `npm run ${script}`;
|
|
505
|
+
return `${manager} run ${script}`;
|
|
506
|
+
}
|
|
507
|
+
function detectChecks(scripts, options = {}) {
|
|
508
|
+
const tier = options.tier ?? "fast";
|
|
509
|
+
if (tier === "none") return [];
|
|
510
|
+
const manager = options.manager ?? "pnpm";
|
|
511
|
+
const rank = TIER_RANK[tier];
|
|
512
|
+
const specs = [];
|
|
513
|
+
for (const definition of SCRIPT_DEFINITIONS) {
|
|
514
|
+
const script = definition.scripts.find((name) => name in scripts);
|
|
515
|
+
if (script === void 0) continue;
|
|
516
|
+
const command = scripts[script] ?? "";
|
|
517
|
+
if (isInteractiveScript(command)) continue;
|
|
518
|
+
if (TIER_RANK[definition.tiers[0]] > rank) continue;
|
|
519
|
+
specs.push({
|
|
520
|
+
name: definition.name,
|
|
521
|
+
command: managerCommand(manager, script),
|
|
522
|
+
timeoutMs: options.timeoutMs ?? definition.timeoutMs,
|
|
523
|
+
reruns: definition.name === "test" ? options.testReruns ?? definition.reruns : definition.reruns,
|
|
524
|
+
required: true
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
return specs;
|
|
528
|
+
}
|
|
529
|
+
function detectRepositoryChecks(root, options = {}) {
|
|
530
|
+
const scripts = readPackageScripts(root);
|
|
531
|
+
return detectChecks(scripts, {
|
|
532
|
+
...options,
|
|
533
|
+
manager: options.manager ?? detectPackageManager(root)
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
var SCRIPT_DEFINITIONS, TIER_RANK;
|
|
537
|
+
var init_checks = __esm({
|
|
538
|
+
"../verifier/src/checks.ts"() {
|
|
539
|
+
"use strict";
|
|
540
|
+
SCRIPT_DEFINITIONS = [
|
|
541
|
+
{
|
|
542
|
+
name: "typecheck",
|
|
543
|
+
scripts: ["typecheck", "type-check", "tsc"],
|
|
544
|
+
timeoutMs: 18e4,
|
|
545
|
+
reruns: 0,
|
|
546
|
+
tiers: ["fast", "standard", "full"]
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
name: "lint",
|
|
550
|
+
scripts: ["lint"],
|
|
551
|
+
timeoutMs: 18e4,
|
|
552
|
+
reruns: 0,
|
|
553
|
+
tiers: ["fast", "standard", "full"]
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
name: "test",
|
|
557
|
+
scripts: ["test"],
|
|
558
|
+
timeoutMs: 6e5,
|
|
559
|
+
reruns: 1,
|
|
560
|
+
tiers: ["standard", "full"]
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
name: "build",
|
|
564
|
+
scripts: ["build"],
|
|
565
|
+
timeoutMs: 9e5,
|
|
566
|
+
reruns: 0,
|
|
567
|
+
tiers: ["full"]
|
|
568
|
+
}
|
|
569
|
+
];
|
|
570
|
+
TIER_RANK = {
|
|
571
|
+
fast: 0,
|
|
572
|
+
standard: 1,
|
|
573
|
+
full: 2
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// ../verifier/src/bisect/types.ts
|
|
579
|
+
var init_types2 = __esm({
|
|
580
|
+
"../verifier/src/bisect/types.ts"() {
|
|
581
|
+
"use strict";
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
// ../verifier/src/bisect/search.ts
|
|
586
|
+
function findRoot(parent, index) {
|
|
587
|
+
let current = index;
|
|
588
|
+
while (parent[current] !== current) {
|
|
589
|
+
current = parent[current];
|
|
590
|
+
}
|
|
591
|
+
return current;
|
|
592
|
+
}
|
|
593
|
+
function union(parent, left, right) {
|
|
594
|
+
const a = findRoot(parent, left);
|
|
595
|
+
const b = findRoot(parent, right);
|
|
596
|
+
if (a !== b) parent[b] = a;
|
|
597
|
+
}
|
|
598
|
+
function clusterUnits(units) {
|
|
599
|
+
const parent = units.map((_, index) => index);
|
|
600
|
+
for (let left = 0; left < units.length; left += 1) {
|
|
601
|
+
const leftFiles = new Set(units[left]?.files ?? []);
|
|
602
|
+
for (let right = left + 1; right < units.length; right += 1) {
|
|
603
|
+
const rightFiles = units[right]?.files ?? [];
|
|
604
|
+
if (rightFiles.some((file) => leftFiles.has(file))) {
|
|
605
|
+
union(parent, left, right);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const groups = /* @__PURE__ */ new Map();
|
|
610
|
+
for (let index = 0; index < units.length; index += 1) {
|
|
611
|
+
const root = findRoot(parent, index);
|
|
612
|
+
const unit = units[index];
|
|
613
|
+
if (!unit) continue;
|
|
614
|
+
const group = groups.get(root);
|
|
615
|
+
if (group) group.push(unit);
|
|
616
|
+
else groups.set(root, [unit]);
|
|
617
|
+
}
|
|
618
|
+
return [...groups.values()].map((group) => group.sort((a, b) => a.id.localeCompare(b.id))).sort((a, b) => (a[0]?.id ?? "").localeCompare(b[0]?.id ?? ""));
|
|
619
|
+
}
|
|
620
|
+
function splitClusters(clusters) {
|
|
621
|
+
const left = [];
|
|
622
|
+
const right = [];
|
|
623
|
+
for (const cluster of clusters) {
|
|
624
|
+
if (left.length <= right.length) left.push(...cluster);
|
|
625
|
+
else right.push(...cluster);
|
|
626
|
+
}
|
|
627
|
+
return [left, right];
|
|
628
|
+
}
|
|
629
|
+
async function bisectSet(units, verify, state) {
|
|
630
|
+
if (units.length <= 1) {
|
|
631
|
+
return {
|
|
632
|
+
status: "failed",
|
|
633
|
+
rejected: units,
|
|
634
|
+
passing: [],
|
|
635
|
+
attempts: state.attempts,
|
|
636
|
+
reason: "single unit"
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
if (state.attempts >= state.maxAttempts) {
|
|
640
|
+
return {
|
|
641
|
+
status: "inconclusive",
|
|
642
|
+
rejected: units,
|
|
643
|
+
passing: [],
|
|
644
|
+
attempts: state.attempts,
|
|
645
|
+
reason: `bisection exceeded ${state.maxAttempts} attempts`
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
const clusters = clusterUnits(units);
|
|
649
|
+
if (clusters.length <= 1) {
|
|
650
|
+
return {
|
|
651
|
+
status: "failed",
|
|
652
|
+
rejected: units,
|
|
653
|
+
passing: [],
|
|
654
|
+
attempts: state.attempts,
|
|
655
|
+
reason: "units share files and cannot be split safely"
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
const [left, right] = splitClusters(clusters);
|
|
659
|
+
if (left.length === 0 || right.length === 0) {
|
|
660
|
+
return {
|
|
661
|
+
status: "failed",
|
|
662
|
+
rejected: units,
|
|
663
|
+
passing: [],
|
|
664
|
+
attempts: state.attempts,
|
|
665
|
+
reason: "no independent split available"
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
state.attempts += 1;
|
|
669
|
+
const leftPasses = await verify(left);
|
|
670
|
+
state.attempts += 1;
|
|
671
|
+
const rightPasses = await verify(right);
|
|
672
|
+
if (leftPasses && rightPasses) {
|
|
673
|
+
return {
|
|
674
|
+
status: "interaction-failure",
|
|
675
|
+
rejected: units,
|
|
676
|
+
passing: [],
|
|
677
|
+
attempts: state.attempts,
|
|
678
|
+
reason: "each half passes but the full batch fails"
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
if (leftPasses && !rightPasses) {
|
|
682
|
+
return bisectSet(right, verify, state);
|
|
683
|
+
}
|
|
684
|
+
if (!leftPasses && rightPasses) {
|
|
685
|
+
return bisectSet(left, verify, state);
|
|
686
|
+
}
|
|
687
|
+
const leftResult = await bisectSet(left, verify, state);
|
|
688
|
+
const rightResult = await bisectSet(right, verify, state);
|
|
689
|
+
if (leftResult.status === "inconclusive" || rightResult.status === "inconclusive") {
|
|
690
|
+
return {
|
|
691
|
+
status: "inconclusive",
|
|
692
|
+
rejected: units,
|
|
693
|
+
passing: [],
|
|
694
|
+
attempts: state.attempts,
|
|
695
|
+
reason: "both halves failed and bisection was inconclusive"
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
return {
|
|
699
|
+
status: "failed",
|
|
700
|
+
rejected: [...leftResult.rejected, ...rightResult.rejected],
|
|
701
|
+
passing: [...leftResult.passing, ...rightResult.passing],
|
|
702
|
+
attempts: state.attempts,
|
|
703
|
+
reason: "multiple failing units"
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
async function bisectFailure(units, verify, options = {}) {
|
|
707
|
+
const sorted = [...units].sort((a, b) => a.id.localeCompare(b.id));
|
|
708
|
+
const state = {
|
|
709
|
+
attempts: 0,
|
|
710
|
+
maxAttempts: options.maxAttempts ?? 32
|
|
711
|
+
};
|
|
712
|
+
if (sorted.length === 0) {
|
|
713
|
+
return {
|
|
714
|
+
status: "pass",
|
|
715
|
+
rejected: [],
|
|
716
|
+
passing: [],
|
|
717
|
+
attempts: 0,
|
|
718
|
+
reason: "empty batch"
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
state.attempts += 1;
|
|
722
|
+
const fullPasses = await verify(sorted);
|
|
723
|
+
if (fullPasses) {
|
|
724
|
+
return {
|
|
725
|
+
status: "pass",
|
|
726
|
+
rejected: [],
|
|
727
|
+
passing: sorted,
|
|
728
|
+
attempts: state.attempts,
|
|
729
|
+
reason: "full batch passes"
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
return bisectSet(sorted, verify, state);
|
|
733
|
+
}
|
|
734
|
+
var init_search = __esm({
|
|
735
|
+
"../verifier/src/bisect/search.ts"() {
|
|
736
|
+
"use strict";
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
// ../verifier/src/bisect.ts
|
|
741
|
+
var init_bisect = __esm({
|
|
742
|
+
"../verifier/src/bisect.ts"() {
|
|
743
|
+
"use strict";
|
|
744
|
+
init_types2();
|
|
745
|
+
init_search();
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// ../verifier/src/index.ts
|
|
750
|
+
var src_exports = {};
|
|
751
|
+
__export(src_exports, {
|
|
752
|
+
baseEnvironment: () => baseEnvironment,
|
|
753
|
+
batchOutcome: () => batchOutcome,
|
|
754
|
+
bisectFailure: () => bisectFailure,
|
|
755
|
+
capOutput: () => capOutput,
|
|
756
|
+
captureBaseline: () => captureBaseline,
|
|
757
|
+
classifyCheck: () => classifyCheck,
|
|
758
|
+
clusterUnits: () => clusterUnits,
|
|
759
|
+
compareToBaseline: () => compareToBaseline,
|
|
760
|
+
detectChecks: () => detectChecks,
|
|
761
|
+
detectPackageManager: () => detectPackageManager,
|
|
762
|
+
detectRepositoryChecks: () => detectRepositoryChecks,
|
|
763
|
+
emptyBaseline: () => emptyBaseline,
|
|
764
|
+
executeCommand: () => executeCommand,
|
|
765
|
+
failureSignature: () => failureSignature,
|
|
766
|
+
hasBlockingFailure: () => hasBlockingFailure,
|
|
767
|
+
hashText: () => hashText,
|
|
768
|
+
isBlocking: () => isBlocking,
|
|
769
|
+
normalizeOutput: () => normalizeOutput,
|
|
770
|
+
readPackageScripts: () => readPackageScripts,
|
|
771
|
+
runCheck: () => runCheck,
|
|
772
|
+
runCheckWithReruns: () => runCheckWithReruns,
|
|
773
|
+
runChecks: () => runChecks,
|
|
774
|
+
stripAnsi: () => stripAnsi,
|
|
775
|
+
summarizeChecks: () => summarizeChecks,
|
|
776
|
+
unstableBaseline: () => unstableBaseline
|
|
777
|
+
});
|
|
778
|
+
var init_src = __esm({
|
|
779
|
+
"../verifier/src/index.ts"() {
|
|
780
|
+
"use strict";
|
|
781
|
+
init_types();
|
|
782
|
+
init_normalize();
|
|
783
|
+
init_run();
|
|
784
|
+
init_classify();
|
|
785
|
+
init_baseline();
|
|
786
|
+
init_checks();
|
|
787
|
+
init_bisect();
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
// src/config.ts
|
|
792
|
+
import { spawnSync } from "node:child_process";
|
|
793
|
+
import { randomUUID } from "node:crypto";
|
|
794
|
+
import { existsSync as existsSync2, mkdtempSync, readFileSync as readFileSync2, rmSync, writeFileSync } from "node:fs";
|
|
795
|
+
import { tmpdir } from "node:os";
|
|
796
|
+
import { dirname, extname, join as join3, resolve } from "node:path";
|
|
797
|
+
import { pathToFileURL } from "node:url";
|
|
798
|
+
|
|
799
|
+
// src/errors.ts
|
|
800
|
+
var ExitCode = {
|
|
801
|
+
OK: 0,
|
|
802
|
+
FINDINGS: 1,
|
|
803
|
+
USAGE: 2,
|
|
804
|
+
VERIFICATION_FAILED: 3,
|
|
805
|
+
COULD_NOT_RUN: 4,
|
|
806
|
+
REVERT_FAILED: 5
|
|
807
|
+
};
|
|
808
|
+
var CliError = class extends Error {
|
|
809
|
+
exitCode;
|
|
810
|
+
code;
|
|
811
|
+
details;
|
|
812
|
+
constructor(exitCode, code, message, details) {
|
|
813
|
+
super(message);
|
|
814
|
+
this.name = "CliError";
|
|
815
|
+
this.exitCode = exitCode;
|
|
816
|
+
this.code = code;
|
|
817
|
+
this.details = details;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
var ConfigError = class extends CliError {
|
|
821
|
+
constructor(message, details) {
|
|
822
|
+
super(ExitCode.USAGE, "config", message, details);
|
|
823
|
+
this.name = "ConfigError";
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
// src/config.ts
|
|
828
|
+
var DEFAULT_CONFIG = {
|
|
829
|
+
schemaVersion: "1.0",
|
|
830
|
+
include: [
|
|
831
|
+
"**/*.ts",
|
|
832
|
+
"**/*.tsx",
|
|
833
|
+
"**/*.js",
|
|
834
|
+
"**/*.jsx",
|
|
835
|
+
"**/*.mjs",
|
|
836
|
+
"**/*.cjs",
|
|
837
|
+
"**/*.mdx",
|
|
838
|
+
"**/*.svelte",
|
|
839
|
+
"**/*.vue",
|
|
840
|
+
"**/*.astro",
|
|
841
|
+
"**/index.html"
|
|
842
|
+
],
|
|
843
|
+
ignore: [
|
|
844
|
+
"node_modules/**",
|
|
845
|
+
".git/**",
|
|
846
|
+
".next/**",
|
|
847
|
+
".shrike/**",
|
|
848
|
+
"dist/**",
|
|
849
|
+
"build/**",
|
|
850
|
+
"out/**",
|
|
851
|
+
"coverage/**",
|
|
852
|
+
".turbo/**",
|
|
853
|
+
".vercel/**",
|
|
854
|
+
"*.min.js",
|
|
855
|
+
"*.generated.*"
|
|
856
|
+
],
|
|
857
|
+
tsconfig: "tsconfig.json",
|
|
858
|
+
cacheDir: ".shrike/cache",
|
|
859
|
+
entryPolicy: "local",
|
|
860
|
+
testEntries: true,
|
|
861
|
+
includeGenerated: false,
|
|
862
|
+
clientBoundaryPolicy: "graph",
|
|
863
|
+
serverActionPolicy: "graph",
|
|
864
|
+
ignoreDependencies: [],
|
|
865
|
+
publicApi: [],
|
|
866
|
+
generated: [],
|
|
867
|
+
batchPolicy: { maxSymbols: 50, maxFiles: 10, maxLiveGraphPercent: 5, allowOversized: false },
|
|
868
|
+
entryAdapters: ["next-app", "next-pages", "react", "packages", "tests", "configs"],
|
|
869
|
+
checks: [],
|
|
870
|
+
pr: {
|
|
871
|
+
draft: true,
|
|
872
|
+
labels: ["shrike", "cleanup"],
|
|
873
|
+
branchPrefix: "shrike/cleanup",
|
|
874
|
+
commentReceipt: true,
|
|
875
|
+
base: null,
|
|
876
|
+
title: "Shrike: verified cleanup"
|
|
877
|
+
},
|
|
878
|
+
verification: {
|
|
879
|
+
mode: "worktree",
|
|
880
|
+
allowDirty: false,
|
|
881
|
+
tier: "standard",
|
|
882
|
+
baselinePath: ".shrike/baseline.json"
|
|
883
|
+
},
|
|
884
|
+
build: {
|
|
885
|
+
evidence: false,
|
|
886
|
+
snapshot: ".next/analyze.jsonl",
|
|
887
|
+
requireEvidence: false
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
var CONFIG_FILES = ["shrike.config.ts", "shrike.config.js", "shrike.config.mjs", "shrike.config.json"];
|
|
891
|
+
function findConfigPath(root) {
|
|
892
|
+
for (const name of CONFIG_FILES) {
|
|
893
|
+
const path = join3(root, name);
|
|
894
|
+
if (existsSync2(path)) return path;
|
|
895
|
+
}
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
898
|
+
function mergeConfig(input = {}) {
|
|
899
|
+
return {
|
|
900
|
+
...DEFAULT_CONFIG,
|
|
901
|
+
...input,
|
|
902
|
+
schemaVersion: "1.0",
|
|
903
|
+
batchPolicy: { ...DEFAULT_CONFIG.batchPolicy, ...input.batchPolicy ?? {} },
|
|
904
|
+
pr: { ...DEFAULT_CONFIG.pr, ...input.pr ?? {} },
|
|
905
|
+
verification: { ...DEFAULT_CONFIG.verification, ...input.verification ?? {} },
|
|
906
|
+
build: { ...DEFAULT_CONFIG.build, ...input.build ?? {} },
|
|
907
|
+
include: input.include ?? DEFAULT_CONFIG.include,
|
|
908
|
+
ignore: input.ignore ?? DEFAULT_CONFIG.ignore,
|
|
909
|
+
checks: input.checks ?? DEFAULT_CONFIG.checks
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
function executableConfigCandidates(path) {
|
|
913
|
+
const extension = extname(path).toLowerCase();
|
|
914
|
+
const candidates = [];
|
|
915
|
+
const copy = (suffix) => {
|
|
916
|
+
const temporary = join3(dirname(path), `.shrike-config-${randomUUID()}${suffix}`);
|
|
917
|
+
try {
|
|
918
|
+
writeFileSync(temporary, readFileSync2(path, "utf8"));
|
|
919
|
+
candidates.push({
|
|
920
|
+
url: pathToFileURL(temporary).href,
|
|
921
|
+
cleanup: () => rmSync(temporary, { force: true })
|
|
922
|
+
});
|
|
923
|
+
} catch {
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
if (extension === ".ts" || extension === ".mts" || extension === ".cts") {
|
|
927
|
+
copy(".mts");
|
|
928
|
+
copy(".cts");
|
|
929
|
+
} else {
|
|
930
|
+
candidates.push({ url: pathToFileURL(path).href, cleanup: () => {
|
|
931
|
+
} });
|
|
932
|
+
if (extension === ".js" || extension === ".jsx") copy(".mjs");
|
|
933
|
+
}
|
|
934
|
+
if (candidates.length === 0) {
|
|
935
|
+
candidates.push({ url: pathToFileURL(path).href, cleanup: () => {
|
|
936
|
+
} });
|
|
937
|
+
}
|
|
938
|
+
return candidates;
|
|
939
|
+
}
|
|
940
|
+
async function loadExecutableConfig(path, root) {
|
|
941
|
+
const { baseEnvironment: baseEnvironment2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
942
|
+
const directory = mkdtempSync(join3(tmpdir(), "shrike-config-"));
|
|
943
|
+
const output = join3(directory, "config.json");
|
|
944
|
+
const timeout = Number(process.env.SHRIKE_CONFIG_TIMEOUT_MS ?? 5e3);
|
|
945
|
+
const script = `
|
|
946
|
+
import { writeFileSync } from "node:fs";
|
|
947
|
+
const loaded = await import(process.env.SHRIKE_CONFIG_URL);
|
|
948
|
+
const value = loaded.default ?? loaded.config ?? {};
|
|
949
|
+
writeFileSync(process.env.SHRIKE_CONFIG_OUTPUT, JSON.stringify(value));
|
|
950
|
+
`;
|
|
951
|
+
const candidates = executableConfigCandidates(path);
|
|
952
|
+
let lastError;
|
|
953
|
+
try {
|
|
954
|
+
for (const candidate of candidates) {
|
|
955
|
+
try {
|
|
956
|
+
const result = spawnSync(process.execPath, ["--input-type=module", "-e", script], {
|
|
957
|
+
cwd: root,
|
|
958
|
+
encoding: "utf8",
|
|
959
|
+
timeout: Number.isFinite(timeout) && timeout > 0 ? timeout : 5e3,
|
|
960
|
+
env: {
|
|
961
|
+
...baseEnvironment2(),
|
|
962
|
+
SHRIKE_CONFIG_URL: candidate.url,
|
|
963
|
+
SHRIKE_CONFIG_OUTPUT: output
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
if (result.error) {
|
|
967
|
+
const code = result.error.code;
|
|
968
|
+
if (code === "ETIMEDOUT") {
|
|
969
|
+
throw new ConfigError(`config evaluation timed out after ${timeout}ms: ${path}`);
|
|
970
|
+
}
|
|
971
|
+
lastError = result.error.message;
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if (result.signal) {
|
|
975
|
+
throw new ConfigError(`config evaluation was terminated (${result.signal}): ${path}`);
|
|
976
|
+
}
|
|
977
|
+
if (result.status !== 0) {
|
|
978
|
+
lastError = (result.stderr ?? "").trim().split("\n").slice(-5).join("\n");
|
|
979
|
+
continue;
|
|
980
|
+
}
|
|
981
|
+
if (!existsSync2(output)) {
|
|
982
|
+
lastError = "config did not produce a value";
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
const parsed = JSON.parse(readFileSync2(output, "utf8"));
|
|
986
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
987
|
+
throw new ConfigError(`config must export an object: ${path}`);
|
|
988
|
+
}
|
|
989
|
+
return parsed;
|
|
990
|
+
} finally {
|
|
991
|
+
rmSync(output, { force: true });
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
throw new ConfigError(
|
|
995
|
+
`config evaluation failed: ${path}`,
|
|
996
|
+
lastError || "no executable config form succeeded"
|
|
997
|
+
);
|
|
998
|
+
} catch (error) {
|
|
999
|
+
if (error instanceof ConfigError) throw error;
|
|
1000
|
+
throw new ConfigError(
|
|
1001
|
+
`could not load ${path}: ${error instanceof Error ? error.message : String(error)}`
|
|
1002
|
+
);
|
|
1003
|
+
} finally {
|
|
1004
|
+
for (const candidate of candidates) candidate.cleanup();
|
|
1005
|
+
rmSync(directory, { recursive: true, force: true });
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
async function loadConfig(root) {
|
|
1009
|
+
const path = findConfigPath(root);
|
|
1010
|
+
if (!path) return mergeConfig();
|
|
1011
|
+
if (path.endsWith(".json")) {
|
|
1012
|
+
try {
|
|
1013
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
1014
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
1015
|
+
throw new ConfigError(`config must be an object: ${path}`);
|
|
1016
|
+
}
|
|
1017
|
+
return mergeConfig(parsed);
|
|
1018
|
+
} catch (error) {
|
|
1019
|
+
if (error instanceof ConfigError) throw error;
|
|
1020
|
+
throw new ConfigError(
|
|
1021
|
+
`could not load ${path}: ${error instanceof Error ? error.message : String(error)}`
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return mergeConfig(await loadExecutableConfig(path, root));
|
|
1026
|
+
}
|
|
1027
|
+
function engineConfig(config) {
|
|
1028
|
+
const {
|
|
1029
|
+
checks: _checks,
|
|
1030
|
+
pr: _pr,
|
|
1031
|
+
verification: _verification,
|
|
1032
|
+
build: _build,
|
|
1033
|
+
cacheDir: _cacheDir,
|
|
1034
|
+
schemaVersion: _schemaVersion,
|
|
1035
|
+
ignoreDependencies: _ignoreDependencies,
|
|
1036
|
+
...rest
|
|
1037
|
+
} = config;
|
|
1038
|
+
return rest;
|
|
1039
|
+
}
|
|
1040
|
+
function cacheDirectory(root, config) {
|
|
1041
|
+
return config.cacheDir.startsWith("/") ? config.cacheDir : join3(root, config.cacheDir);
|
|
1042
|
+
}
|
|
1043
|
+
function repoRoot(cwd = process.cwd()) {
|
|
1044
|
+
return resolve(cwd);
|
|
1045
|
+
}
|
|
1046
|
+
export {
|
|
1047
|
+
DEFAULT_CONFIG,
|
|
1048
|
+
cacheDirectory,
|
|
1049
|
+
engineConfig,
|
|
1050
|
+
findConfigPath,
|
|
1051
|
+
loadConfig,
|
|
1052
|
+
mergeConfig,
|
|
1053
|
+
repoRoot
|
|
1054
|
+
};
|