@lelouchhe/agent-evals 0.0.0-stage → 0.2.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/.env.example +27 -0
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/dist/checkers/file/index.d.ts +26 -0
- package/dist/checkers/file/index.js +396 -0
- package/dist/checkers/judge/index.d.ts +20 -0
- package/dist/checkers/judge/index.js +474 -0
- package/dist/checkers/judge/prompt.d.ts +19 -0
- package/dist/checkers/judge/prompt.js +55 -0
- package/dist/checkers/judge/trace.d.ts +6 -0
- package/dist/checkers/judge/trace.js +41 -0
- package/dist/checkers/mock/index.d.ts +18 -0
- package/dist/checkers/mock/index.js +127 -0
- package/dist/checkers/shell/index.d.ts +10 -0
- package/dist/checkers/shell/index.js +61 -0
- package/dist/checkers/trace/index.d.ts +22 -0
- package/dist/checkers/trace/index.js +183 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +453 -0
- package/dist/engine/authoring.d.ts +24 -0
- package/dist/engine/authoring.js +356 -0
- package/dist/engine/check-runner.d.ts +1 -0
- package/dist/engine/check-runner.js +127 -0
- package/dist/engine/check-sandbox.d.ts +18 -0
- package/dist/engine/check-sandbox.js +171 -0
- package/dist/engine/config.d.ts +171 -0
- package/dist/engine/config.js +368 -0
- package/dist/engine/env-source.d.ts +10 -0
- package/dist/engine/env-source.js +114 -0
- package/dist/engine/files.d.ts +84 -0
- package/dist/engine/files.js +304 -0
- package/dist/engine/forwarder.sh +61 -0
- package/dist/engine/ignore.d.ts +29 -0
- package/dist/engine/ignore.js +67 -0
- package/dist/engine/messages.d.ts +8 -0
- package/dist/engine/messages.js +9 -0
- package/dist/engine/mock-match.d.ts +44 -0
- package/dist/engine/mock-match.js +104 -0
- package/dist/engine/mocks.d.ts +35 -0
- package/dist/engine/mocks.js +336 -0
- package/dist/engine/params.d.ts +18 -0
- package/dist/engine/params.js +96 -0
- package/dist/engine/placement.d.ts +26 -0
- package/dist/engine/placement.js +107 -0
- package/dist/engine/regex.d.ts +10 -0
- package/dist/engine/regex.js +16 -0
- package/dist/engine/registry.d.ts +243 -0
- package/dist/engine/registry.js +127 -0
- package/dist/engine/report.d.ts +17 -0
- package/dist/engine/report.js +420 -0
- package/dist/engine/results.d.ts +50 -0
- package/dist/engine/results.js +42 -0
- package/dist/engine/run.d.ts +50 -0
- package/dist/engine/run.js +710 -0
- package/dist/engine/runtime-assets.d.ts +6 -0
- package/dist/engine/runtime-assets.js +11 -0
- package/dist/engine/skills.d.ts +49 -0
- package/dist/engine/skills.js +270 -0
- package/dist/engine/truncate.d.ts +3 -0
- package/dist/engine/truncate.js +7 -0
- package/dist/engine/values.d.ts +18 -0
- package/dist/engine/values.js +75 -0
- package/dist/engine/view.d.ts +10 -0
- package/dist/engine/view.js +150 -0
- package/dist/engine/workspace.d.ts +63 -0
- package/dist/engine/workspace.js +305 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +7 -0
- package/dist/platform/macos/launch.d.ts +13 -0
- package/dist/platform/macos/launch.js +14 -0
- package/dist/platform/macos/policy.d.ts +33 -0
- package/dist/platform/macos/policy.js +131 -0
- package/dist/platform/macos/supervise.d.ts +26 -0
- package/dist/platform/macos/supervise.js +98 -0
- package/dist/platform/macos/supervisor.sh +13 -0
- package/dist/runners/acp/agent.d.ts +17 -0
- package/dist/runners/acp/agent.js +38 -0
- package/dist/runners/acp/commands.d.ts +2 -0
- package/dist/runners/acp/commands.js +112 -0
- package/dist/runners/acp/environment.d.ts +71 -0
- package/dist/runners/acp/environment.js +280 -0
- package/dist/runners/acp/index.d.ts +21 -0
- package/dist/runners/acp/index.js +135 -0
- package/dist/runners/acp/session.d.ts +7 -0
- package/dist/runners/acp/session.js +48 -0
- package/dist/runners/acp/trace.d.ts +23 -0
- package/dist/runners/acp/trace.js +44 -0
- package/dist/runners/acp/usage.d.ts +12 -0
- package/dist/runners/acp/usage.js +56 -0
- package/dist/runners/noop/index.d.ts +12 -0
- package/dist/runners/noop/index.js +22 -0
- package/dist/runners/pi/index.d.ts +21 -0
- package/dist/runners/pi/index.js +116 -0
- package/dist/runners/pi/params.d.ts +10 -0
- package/dist/runners/pi/params.js +3 -0
- package/dist/runners/pi/rpc.d.ts +30 -0
- package/dist/runners/pi/rpc.js +341 -0
- package/dist/runners/pi/safe-process-group.d.ts +7 -0
- package/dist/runners/pi/safe-process-group.js +13 -0
- package/dist/runners/pi/session.d.ts +56 -0
- package/dist/runners/pi/session.js +298 -0
- package/dist/runners/pi/shell-wrapper.sh +46 -0
- package/dist/runners/pi/supervisor.d.ts +1 -0
- package/dist/runners/pi/supervisor.js +101 -0
- package/package.json +77 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { fileChecker } from "./checkers/file/index.js";
|
|
6
|
+
import { judgeChecker } from "./checkers/judge/index.js";
|
|
7
|
+
import { mockChecker } from "./checkers/mock/index.js";
|
|
8
|
+
import { shellChecker } from "./checkers/shell/index.js";
|
|
9
|
+
import { traceChecker } from "./checkers/trace/index.js";
|
|
10
|
+
import { loadCases } from "./engine/authoring.js";
|
|
11
|
+
import { ConfigError, errorMessage } from "./engine/config.js";
|
|
12
|
+
import { createEnvSource } from "./engine/env-source.js";
|
|
13
|
+
import { addChecker, addRunner, createRegistry, loadTrustedImplementations } from "./engine/registry.js";
|
|
14
|
+
import { executeEvaluation, prepareEvaluation } from "./engine/run.js";
|
|
15
|
+
import { formatMatrix, formatReport } from "./engine/report.js";
|
|
16
|
+
import { runOutcome } from "./engine/results.js";
|
|
17
|
+
import { describePlacement } from "./engine/placement.js";
|
|
18
|
+
import { formatResolvedCase } from "./engine/view.js";
|
|
19
|
+
import { piRunner } from "./runners/pi/index.js";
|
|
20
|
+
import { noopRunner } from "./runners/noop/index.js";
|
|
21
|
+
import { runAgentCommand } from "./runners/acp/commands.js";
|
|
22
|
+
import { acpRunner } from "./runners/acp/index.js";
|
|
23
|
+
const USAGE = `Usage: agent-evals <command> <config.yml> [options]
|
|
24
|
+
|
|
25
|
+
Commands:
|
|
26
|
+
run <config.yml> Execute the selected case, or every case when --case is omitted
|
|
27
|
+
view <config.yml> Show the selected case, or every case when --case is omitted
|
|
28
|
+
report <results-dir>... Print a session report from retained run records
|
|
29
|
+
config <agent.yml> Query ACP configuration values without prompting
|
|
30
|
+
login <agent.yml> Run the declared native command and save login files
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--case <name> Named case to select (omitting selects every case in a cases document)
|
|
34
|
+
--reps <n> Repeat each selected case n times (default: 1)
|
|
35
|
+
--jobs <n> Maximum concurrent runs (default: 1)
|
|
36
|
+
--retain <mode> Retain workspace and home (excluding login): none, on-failure, all (default: none)
|
|
37
|
+
--results-dir <path> Where run records are written (default: .agent-evals)
|
|
38
|
+
--extension-dir <path> Trusted extension root, one implementation per subdirectory (repeatable)
|
|
39
|
+
--files With view: list every placed and excluded path
|
|
40
|
+
--matrix With report: one table of checks by case instead of the session report
|
|
41
|
+
--version, -V Show version
|
|
42
|
+
--help Show this help
|
|
43
|
+
|
|
44
|
+
Configuration errors exit with code 2 before any run resource is created.
|
|
45
|
+
`;
|
|
46
|
+
async function main(argv) {
|
|
47
|
+
const major = Number(process.versions.node.split(".")[0] ?? "0");
|
|
48
|
+
if (major < 24) {
|
|
49
|
+
process.stderr.write(`error: Node.js 24 or newer is required (running ${process.versions.node})\n`);
|
|
50
|
+
return 2;
|
|
51
|
+
}
|
|
52
|
+
let options;
|
|
53
|
+
try {
|
|
54
|
+
options = parseArguments(argv);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof HelpRequested) {
|
|
58
|
+
process.stdout.write(USAGE);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
if (error instanceof VersionRequested) {
|
|
62
|
+
const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
|
|
63
|
+
process.stdout.write(`${pkg.version ?? "unknown"}\n`);
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
process.stderr.write(`error: ${errorMessage(error)}\n\n${USAGE}`);
|
|
67
|
+
return 2;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
if (options.command === "view") {
|
|
71
|
+
const cases = await loadCases(options.configPath, {
|
|
72
|
+
...(options.caseName === undefined ? {} : { caseName: options.caseName }),
|
|
73
|
+
});
|
|
74
|
+
const rendered = [];
|
|
75
|
+
for (const resolved of cases) {
|
|
76
|
+
const placement = await describePlacement(resolved);
|
|
77
|
+
rendered.push(formatResolvedCase(resolved, { placement, files: options.showFiles }));
|
|
78
|
+
}
|
|
79
|
+
process.stdout.write(rendered.join("\n"));
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
if (options.command === "report") {
|
|
83
|
+
const records = await readRecords(options.configPath, ...options.extraPaths);
|
|
84
|
+
process.stdout.write(options.matrix ? formatMatrix(records) : formatReport(records));
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
if (options.command === "config" || options.command === "login") {
|
|
88
|
+
const abort = new AbortController();
|
|
89
|
+
const onSignal = () => abort.abort();
|
|
90
|
+
process.on("SIGINT", onSignal);
|
|
91
|
+
process.on("SIGTERM", onSignal);
|
|
92
|
+
try {
|
|
93
|
+
process.stdout.write(await runAgentCommand(options.command, options.configPath, abort.signal));
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
process.off("SIGINT", onSignal);
|
|
98
|
+
process.off("SIGTERM", onSignal);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return await runCommand(options);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error instanceof ConfigError) {
|
|
105
|
+
process.stderr.write(`configuration error: ${error.message}\n`);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
process.stderr.write(`error: ${errorMessage(error)}\n`);
|
|
109
|
+
}
|
|
110
|
+
return 2;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function runCommand(options) {
|
|
114
|
+
const registry = createRegistry();
|
|
115
|
+
addRunner(registry, piRunner, "built-in");
|
|
116
|
+
addRunner(registry, acpRunner, "built-in");
|
|
117
|
+
addRunner(registry, noopRunner, "built-in");
|
|
118
|
+
addChecker(registry, fileChecker, "built-in");
|
|
119
|
+
addChecker(registry, judgeChecker, "built-in");
|
|
120
|
+
addChecker(registry, mockChecker, "built-in");
|
|
121
|
+
addChecker(registry, shellChecker, "built-in");
|
|
122
|
+
addChecker(registry, traceChecker, "built-in");
|
|
123
|
+
const abort = new AbortController();
|
|
124
|
+
let interrupted = false;
|
|
125
|
+
const onSignal = () => {
|
|
126
|
+
if (interrupted) {
|
|
127
|
+
process.exit(130);
|
|
128
|
+
}
|
|
129
|
+
interrupted = true;
|
|
130
|
+
abort.abort();
|
|
131
|
+
};
|
|
132
|
+
process.on("SIGINT", onSignal);
|
|
133
|
+
process.on("SIGTERM", onSignal);
|
|
134
|
+
try {
|
|
135
|
+
// Resolve and validate every selected case before the first one runs, so a configuration
|
|
136
|
+
// error in any of them runs none.
|
|
137
|
+
const cases = await loadCases(options.configPath, {
|
|
138
|
+
...(options.caseName === undefined ? {} : { caseName: options.caseName }),
|
|
139
|
+
});
|
|
140
|
+
await loadTrustedImplementations(registry, { extensionDirs: options.extensionDirs });
|
|
141
|
+
const resultsDir = options.resultsDir ?? resolve(".agent-evals");
|
|
142
|
+
const envSource = createEnvSource(process.cwd(), abort.signal);
|
|
143
|
+
const prepared = [];
|
|
144
|
+
for (let rep = 0; rep < options.reps; rep += 1) {
|
|
145
|
+
for (const entry of cases) {
|
|
146
|
+
prepared.push(await prepareEvaluation({
|
|
147
|
+
case: entry,
|
|
148
|
+
registry,
|
|
149
|
+
resultsDir,
|
|
150
|
+
retain: options.retain,
|
|
151
|
+
signal: abort.signal,
|
|
152
|
+
envSource,
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// One repetition of one case keeps the single-run output; so does an ordinary document.
|
|
157
|
+
if (options.reps === 1 && (options.caseName !== undefined || !cases.some((entry) => entry.name !== undefined))) {
|
|
158
|
+
const record = await executeEvaluation(prepared[0]);
|
|
159
|
+
printRecord(record, resultsDir);
|
|
160
|
+
process.stdout.write(`\n${formatReport([record])}`);
|
|
161
|
+
return exitCode(record);
|
|
162
|
+
}
|
|
163
|
+
const slots = new Array(prepared.length);
|
|
164
|
+
const pending = prepared.map((_, index) => index);
|
|
165
|
+
const inFlightKeys = new Set();
|
|
166
|
+
let firstError;
|
|
167
|
+
let active = 0;
|
|
168
|
+
// Event-driven bounded pool: runs sharing a `concurrencyKey` (e.g., persistent ACP login.dir)
|
|
169
|
+
// serialize while unrelated runs execute concurrently up to `options.jobs`. If any worker
|
|
170
|
+
// rejects unexpectedly, abort and wait for all active workers to drain before exiting.
|
|
171
|
+
await new Promise((resolvePool) => {
|
|
172
|
+
const schedule = () => {
|
|
173
|
+
while (active < options.jobs && !abort.signal.aborted && firstError === undefined) {
|
|
174
|
+
const pos = pending.findIndex((index) => prepared[index].registered.concurrencyKeys.every((key) => !inFlightKeys.has(key)));
|
|
175
|
+
if (pos === -1)
|
|
176
|
+
break;
|
|
177
|
+
const [index] = pending.splice(pos, 1);
|
|
178
|
+
const entry = prepared[index];
|
|
179
|
+
const keys = entry.registered.concurrencyKeys;
|
|
180
|
+
for (const key of keys)
|
|
181
|
+
inFlightKeys.add(key);
|
|
182
|
+
active += 1;
|
|
183
|
+
void executeEvaluation(entry)
|
|
184
|
+
.then((record) => {
|
|
185
|
+
slots[index] = record;
|
|
186
|
+
}, (caught) => {
|
|
187
|
+
firstError ??= caught;
|
|
188
|
+
abort.abort();
|
|
189
|
+
})
|
|
190
|
+
.finally(() => {
|
|
191
|
+
for (const key of keys)
|
|
192
|
+
inFlightKeys.delete(key);
|
|
193
|
+
active -= 1;
|
|
194
|
+
schedule();
|
|
195
|
+
if (active === 0 && (pending.length === 0 || abort.signal.aborted || firstError !== undefined)) {
|
|
196
|
+
resolvePool();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (active === 0) {
|
|
201
|
+
resolvePool();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
schedule();
|
|
205
|
+
});
|
|
206
|
+
if (firstError !== undefined) {
|
|
207
|
+
throw firstError;
|
|
208
|
+
}
|
|
209
|
+
const records = [];
|
|
210
|
+
const casesPerRep = cases.length;
|
|
211
|
+
for (const [index, record] of slots.entries()) {
|
|
212
|
+
if (record === undefined)
|
|
213
|
+
continue;
|
|
214
|
+
records.push(record);
|
|
215
|
+
const repLabel = options.reps === 1 ? "" : `rep ${Math.floor(index / casesPerRep) + 1}/${options.reps} `;
|
|
216
|
+
printCaseLine(record, resultsDir, repLabel);
|
|
217
|
+
}
|
|
218
|
+
const notRunCases = prepared.length - records.length;
|
|
219
|
+
if (notRunCases > 0) {
|
|
220
|
+
process.stdout.write(`cancelled: ${notRunCases} run${notRunCases === 1 ? "" : "s"} not run\n`);
|
|
221
|
+
// The retained runs still get their report; the exit code carries the shortfall.
|
|
222
|
+
if (records.length > 0)
|
|
223
|
+
process.stdout.write(`\n${formatReport(records)}`);
|
|
224
|
+
return 2;
|
|
225
|
+
}
|
|
226
|
+
// Every invocation ends with a session report, one run or many; nothing is written to disk.
|
|
227
|
+
process.stdout.write(`\n${formatReport(records)}`);
|
|
228
|
+
return aggregateExit(records);
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
process.off("SIGINT", onSignal);
|
|
232
|
+
process.off("SIGTERM", onSignal);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function parseArguments(argv) {
|
|
236
|
+
let parsed;
|
|
237
|
+
try {
|
|
238
|
+
parsed = parseArgs({
|
|
239
|
+
args: argv,
|
|
240
|
+
allowPositionals: true,
|
|
241
|
+
strict: true,
|
|
242
|
+
options: {
|
|
243
|
+
case: { type: "string" },
|
|
244
|
+
"results-dir": { type: "string" },
|
|
245
|
+
"extension-dir": { type: "string", multiple: true },
|
|
246
|
+
files: { type: "boolean" },
|
|
247
|
+
matrix: { type: "boolean" },
|
|
248
|
+
reps: { type: "string" },
|
|
249
|
+
jobs: { type: "string" },
|
|
250
|
+
retain: { type: "string" },
|
|
251
|
+
version: { type: "boolean", short: "V" },
|
|
252
|
+
help: { type: "boolean", short: "h" },
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
throw new ConfigError(errorMessage(error));
|
|
258
|
+
}
|
|
259
|
+
const { values, positionals } = parsed;
|
|
260
|
+
if (values.help === true) {
|
|
261
|
+
throw new HelpRequested();
|
|
262
|
+
}
|
|
263
|
+
if (values.version === true) {
|
|
264
|
+
throw new VersionRequested();
|
|
265
|
+
}
|
|
266
|
+
const [command, rawConfigPath, ...unexpected] = positionals;
|
|
267
|
+
if (command !== "run" && command !== "view" && command !== "report" && command !== "config" && command !== "login") {
|
|
268
|
+
throw new ConfigError(command === undefined ? "a command is required" : `unknown command: ${command}`);
|
|
269
|
+
}
|
|
270
|
+
if (rawConfigPath === undefined) {
|
|
271
|
+
throw new ConfigError(command === "report" ? "a results directory is required" : "a configuration file is required");
|
|
272
|
+
}
|
|
273
|
+
if (command !== "report" && unexpected.length > 0) {
|
|
274
|
+
throw new ConfigError(`unexpected argument: ${unexpected[0]}`);
|
|
275
|
+
}
|
|
276
|
+
if ((command === "config" || command === "login") &&
|
|
277
|
+
(values.case !== undefined ||
|
|
278
|
+
values["results-dir"] !== undefined ||
|
|
279
|
+
values["extension-dir"] !== undefined ||
|
|
280
|
+
values.reps !== undefined ||
|
|
281
|
+
values.jobs !== undefined ||
|
|
282
|
+
values.retain !== undefined)) {
|
|
283
|
+
throw new ConfigError(`${command} accepts only an agent configuration file, not case or run options`);
|
|
284
|
+
}
|
|
285
|
+
const extensionDirs = (values["extension-dir"] ?? []).map((directory) => resolve(directory));
|
|
286
|
+
if (command === "view" &&
|
|
287
|
+
(values["results-dir"] !== undefined ||
|
|
288
|
+
extensionDirs.length > 0 ||
|
|
289
|
+
values.reps !== undefined ||
|
|
290
|
+
values.jobs !== undefined ||
|
|
291
|
+
values.retain !== undefined)) {
|
|
292
|
+
throw new ConfigError("view does not accept --results-dir, --extension-dir, --reps, --jobs or --retain");
|
|
293
|
+
}
|
|
294
|
+
if (command !== "view" && values.files === true) {
|
|
295
|
+
throw new ConfigError("--files applies only to view");
|
|
296
|
+
}
|
|
297
|
+
if (command !== "report" && values.matrix === true) {
|
|
298
|
+
throw new ConfigError("--matrix applies only to report");
|
|
299
|
+
}
|
|
300
|
+
if (command === "report" &&
|
|
301
|
+
(values.case !== undefined ||
|
|
302
|
+
values["results-dir"] !== undefined ||
|
|
303
|
+
values["extension-dir"] !== undefined ||
|
|
304
|
+
values.reps !== undefined ||
|
|
305
|
+
values.jobs !== undefined ||
|
|
306
|
+
values.retain !== undefined)) {
|
|
307
|
+
throw new ConfigError("report accepts only results directories");
|
|
308
|
+
}
|
|
309
|
+
const reps = values.reps === undefined ? 1 : expectPositiveInt(values.reps, "--reps");
|
|
310
|
+
const jobs = values.jobs === undefined ? 1 : expectPositiveInt(values.jobs, "--jobs");
|
|
311
|
+
const retain = values.retain === undefined ? "none" : expectRetain(values.retain);
|
|
312
|
+
return {
|
|
313
|
+
command,
|
|
314
|
+
configPath: resolve(rawConfigPath),
|
|
315
|
+
...(values.case === undefined ? {} : { caseName: values.case }),
|
|
316
|
+
...(values["results-dir"] === undefined ? {} : { resultsDir: resolve(values["results-dir"]) }),
|
|
317
|
+
extensionDirs,
|
|
318
|
+
showFiles: values.files === true,
|
|
319
|
+
matrix: values.matrix === true,
|
|
320
|
+
reps,
|
|
321
|
+
jobs,
|
|
322
|
+
retain,
|
|
323
|
+
extraPaths: unexpected.map((path) => resolve(path)),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/** A count flag is a positive integer written in decimal that a loop can count to. */
|
|
327
|
+
function expectPositiveInt(value, flag) {
|
|
328
|
+
const count = Number(value);
|
|
329
|
+
if (!/^[0-9]+$/.test(value) || !Number.isSafeInteger(count) || count < 1) {
|
|
330
|
+
throw new ConfigError(`${flag} must be a positive integer, got ${JSON.stringify(value)}`);
|
|
331
|
+
}
|
|
332
|
+
return count;
|
|
333
|
+
}
|
|
334
|
+
function expectRetain(value) {
|
|
335
|
+
if (value !== "none" && value !== "on-failure" && value !== "all") {
|
|
336
|
+
throw new ConfigError(`--retain must be "none", "on-failure", or "all", got ${JSON.stringify(value)}`);
|
|
337
|
+
}
|
|
338
|
+
return value;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Read every retained run record under the given paths. A path may be a results directory (walked
|
|
342
|
+
* recursively), a single run directory or a `result.json` file.
|
|
343
|
+
*/
|
|
344
|
+
async function readRecords(...paths) {
|
|
345
|
+
const files = [];
|
|
346
|
+
for (const path of paths) {
|
|
347
|
+
for (const file of await findResultFiles(path))
|
|
348
|
+
files.push(file);
|
|
349
|
+
}
|
|
350
|
+
if (files.length === 0) {
|
|
351
|
+
throw new ConfigError(`no result.json found under ${paths.join(", ")}`);
|
|
352
|
+
}
|
|
353
|
+
const records = [];
|
|
354
|
+
const seen = new Set();
|
|
355
|
+
for (const file of files) {
|
|
356
|
+
let parsed;
|
|
357
|
+
try {
|
|
358
|
+
parsed = JSON.parse(await readFile(file, "utf8"));
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
throw new ConfigError(`cannot read ${file}: ${errorMessage(error)}`);
|
|
362
|
+
}
|
|
363
|
+
if (typeof parsed !== "object" || parsed === null || !Array.isArray(parsed.checks)) {
|
|
364
|
+
throw new ConfigError(`${file} is not an agent-evals result record`);
|
|
365
|
+
}
|
|
366
|
+
const record = parsed;
|
|
367
|
+
// Overlapping arguments can name one record twice; a record is one run however it is reached.
|
|
368
|
+
if (seen.has(record.runId))
|
|
369
|
+
continue;
|
|
370
|
+
seen.add(record.runId);
|
|
371
|
+
records.push(record);
|
|
372
|
+
}
|
|
373
|
+
return records;
|
|
374
|
+
}
|
|
375
|
+
async function findResultFiles(path) {
|
|
376
|
+
let info;
|
|
377
|
+
try {
|
|
378
|
+
info = await stat(path);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
throw new ConfigError(`cannot read ${path}: ${errorMessage(error)}`);
|
|
382
|
+
}
|
|
383
|
+
if (info.isFile()) {
|
|
384
|
+
return [path];
|
|
385
|
+
}
|
|
386
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
387
|
+
// A directory with `result.json` is a single run record; do not recurse into its subdirectories.
|
|
388
|
+
if (entries.some((entry) => !entry.isDirectory() && entry.name === "result.json")) {
|
|
389
|
+
return [join(path, "result.json")];
|
|
390
|
+
}
|
|
391
|
+
const found = [];
|
|
392
|
+
for (const entry of entries) {
|
|
393
|
+
// Never descend into retained artifact trees, even for an incomplete run with no `result.json`.
|
|
394
|
+
if (entry.isDirectory() && entry.name !== "artifacts") {
|
|
395
|
+
for (const file of await findResultFiles(join(path, entry.name)))
|
|
396
|
+
found.push(file);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return found.sort();
|
|
400
|
+
}
|
|
401
|
+
function printRecord(record, resultsDir) {
|
|
402
|
+
const caseLabel = record.case.name === undefined ? record.case.path : `${record.case.name} (${record.case.path})`;
|
|
403
|
+
const lines = [`run ${record.runId}: ${runOutcome(record)}`, ` case: ${caseLabel}`];
|
|
404
|
+
lines.push(` runner ${record.runner.type}: ${record.runner.status} (${record.runner.durationMs}ms)`);
|
|
405
|
+
for (const check of record.checks) {
|
|
406
|
+
lines.push(` ${check.status.toUpperCase().padEnd(5)} ${check.checker} ${check.subject}${check.reason.length > 0 ? ` — ${check.reason}` : ""}`);
|
|
407
|
+
}
|
|
408
|
+
if (record.error !== undefined) {
|
|
409
|
+
lines.push(` error: ${record.error}`);
|
|
410
|
+
}
|
|
411
|
+
if (record.artifacts?.status === "retained" && record.artifacts.path !== undefined) {
|
|
412
|
+
lines.push(` artifacts: ${join(resultsDir, record.runId, record.artifacts.path)}`);
|
|
413
|
+
}
|
|
414
|
+
else if (record.artifacts?.status === "failed") {
|
|
415
|
+
lines.push(` artifacts: failed — ${record.artifacts.error ?? "unknown error"}`);
|
|
416
|
+
}
|
|
417
|
+
lines.push(` results: ${join(resultsDir, record.runId, "result.json")}`);
|
|
418
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
419
|
+
}
|
|
420
|
+
/** The outcome a reader sees, with the case's `expect` applied; an error is still an error. */
|
|
421
|
+
function exitCode(record) {
|
|
422
|
+
switch (runOutcome(record)) {
|
|
423
|
+
case "pass":
|
|
424
|
+
case "expected-fail":
|
|
425
|
+
return 0;
|
|
426
|
+
case "fail":
|
|
427
|
+
case "unexpected-pass":
|
|
428
|
+
return 1;
|
|
429
|
+
default:
|
|
430
|
+
return 2;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** One summary line per executed case: name, status and the retained result record. */
|
|
434
|
+
function printCaseLine(record, resultsDir, prefix = "") {
|
|
435
|
+
const name = record.case.name ?? record.case.path;
|
|
436
|
+
const retainNote = record.artifacts?.status === "failed"
|
|
437
|
+
? ` (artifacts retention failed: ${record.artifacts.error ?? "unknown error"})`
|
|
438
|
+
: "";
|
|
439
|
+
process.stdout.write(`${prefix}${name}: ${runOutcome(record)} ${join(resultsDir, record.runId, "result.json")}${retainNote}\n`);
|
|
440
|
+
}
|
|
441
|
+
/** Zero only when every case passed, 1 for failed checks, 2 for anything that could not be judged. */
|
|
442
|
+
function aggregateExit(records) {
|
|
443
|
+
if (records.every((record) => exitCode(record) === 0)) {
|
|
444
|
+
return 0;
|
|
445
|
+
}
|
|
446
|
+
return records.some((record) => exitCode(record) === 2) ? 2 : 1;
|
|
447
|
+
}
|
|
448
|
+
class HelpRequested extends Error {
|
|
449
|
+
}
|
|
450
|
+
class VersionRequested extends Error {
|
|
451
|
+
}
|
|
452
|
+
const code = await main(process.argv.slice(2));
|
|
453
|
+
process.exitCode = code;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
import { type ValueSource } from "./values.js";
|
|
3
|
+
import { type ResolvedCase } from "./config.js";
|
|
4
|
+
export interface CaseSelection {
|
|
5
|
+
/** The named case to select. Required when the document defines `cases`. */
|
|
6
|
+
readonly caseName?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Resolve one YAML authoring document to a single case.
|
|
10
|
+
*
|
|
11
|
+
* `view` and execution both use this function, so they see the same values and
|
|
12
|
+
* field origins. Runtime implementation validation remains a separate step.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadCase(path: string, selection?: CaseSelection): Promise<ResolvedCase>;
|
|
15
|
+
/**
|
|
16
|
+
* Resolve every selected case in declaration order: the named one when a name is
|
|
17
|
+
* given, all entries of a `cases` document when it is not, or the one ordinary case.
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadCases(path: string, selection?: CaseSelection): Promise<readonly ResolvedCase[]>;
|
|
20
|
+
/** Load a standalone implementation object using the same YAML and placeholder rules as cases. */
|
|
21
|
+
export declare function loadImplementationParameters<P>(path: string, schema: ZodType<P>, source: ValueSource): Promise<{
|
|
22
|
+
params: P;
|
|
23
|
+
dir: string;
|
|
24
|
+
}>;
|