@lelouchhe/agent-evals 0.1.1 → 0.3.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.
Files changed (79) hide show
  1. package/README.md +27 -18
  2. package/dist/checkers/file/index.js +181 -13
  3. package/dist/checkers/judge/index.d.ts +1 -1
  4. package/dist/checkers/judge/index.js +243 -31
  5. package/dist/checkers/judge/prompt.d.ts +4 -3
  6. package/dist/checkers/judge/prompt.js +22 -3
  7. package/dist/cli.js +171 -35
  8. package/dist/engine/authoring.js +108 -13
  9. package/dist/engine/check-runner.js +18 -3
  10. package/dist/engine/check-sandbox.js +9 -6
  11. package/dist/engine/config.d.ts +31 -2
  12. package/dist/engine/config.js +16 -10
  13. package/dist/engine/env-source.js +82 -14
  14. package/dist/engine/files.d.ts +2 -5
  15. package/dist/engine/files.js +4 -6
  16. package/dist/engine/mocks.js +72 -46
  17. package/dist/engine/params.d.ts +2 -0
  18. package/dist/engine/params.js +10 -0
  19. package/dist/engine/registry.d.ts +11 -0
  20. package/dist/engine/report.js +43 -8
  21. package/dist/engine/results.d.ts +7 -0
  22. package/dist/engine/results.js +9 -6
  23. package/dist/engine/run.d.ts +4 -1
  24. package/dist/engine/run.js +171 -28
  25. package/dist/engine/skills.js +12 -5
  26. package/dist/engine/view.d.ts +1 -1
  27. package/dist/engine/view.js +125 -10
  28. package/dist/engine/workspace.d.ts +7 -0
  29. package/dist/engine/workspace.js +37 -27
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +2 -2
  32. package/dist/platform/index.d.ts +31 -0
  33. package/dist/platform/index.js +88 -0
  34. package/dist/platform/linux/index.d.ts +2 -0
  35. package/dist/platform/linux/index.js +40 -0
  36. package/dist/platform/linux/launch.d.ts +8 -0
  37. package/dist/platform/linux/launch.js +25 -0
  38. package/dist/platform/linux/policy.d.ts +46 -0
  39. package/dist/platform/linux/policy.js +388 -0
  40. package/dist/platform/linux/supervise.d.ts +8 -0
  41. package/dist/platform/linux/supervise.js +124 -0
  42. package/dist/platform/macos/index.d.ts +2 -0
  43. package/dist/platform/macos/index.js +59 -0
  44. package/dist/platform/macos/launch.d.ts +2 -8
  45. package/dist/platform/macos/launch.js +5 -3
  46. package/dist/platform/macos/policy.d.ts +3 -21
  47. package/dist/platform/macos/policy.js +5 -2
  48. package/dist/platform/macos/supervise.d.ts +3 -25
  49. package/dist/platform/posix-forwarder-client.mjs +129 -0
  50. package/dist/platform/posix-forwarder.sh +9 -0
  51. package/dist/platform/posix-helpers.d.ts +22 -0
  52. package/dist/platform/posix-helpers.js +97 -0
  53. package/dist/platform/types.d.ts +118 -0
  54. package/dist/platform/types.js +1 -0
  55. package/dist/platform/windows/forwarder-client.mjs +165 -0
  56. package/dist/platform/windows/forwarder.cmd +3 -0
  57. package/dist/platform/windows/forwarder.ps1 +2 -0
  58. package/dist/platform/windows/forwarder.sh +2 -0
  59. package/dist/platform/windows/index.d.ts +2 -0
  60. package/dist/platform/windows/index.js +225 -0
  61. package/dist/platform/windows/launch.d.ts +3 -0
  62. package/dist/platform/windows/launch.js +30 -0
  63. package/dist/platform/windows/policy.d.ts +17 -0
  64. package/dist/platform/windows/policy.js +155 -0
  65. package/dist/platform/windows/setup.ps1 +112 -0
  66. package/dist/platform/windows/supervise.d.ts +2 -0
  67. package/dist/platform/windows/supervise.js +142 -0
  68. package/dist/platform/windows/win-sandbox.exe +0 -0
  69. package/dist/runners/acp/commands.js +2 -3
  70. package/dist/runners/acp/environment.d.ts +1 -7
  71. package/dist/runners/acp/environment.js +18 -48
  72. package/dist/runners/acp/index.js +5 -1
  73. package/dist/runners/acp/session.d.ts +1 -1
  74. package/dist/runners/pi/index.js +2 -2
  75. package/dist/runners/pi/session.d.ts +1 -1
  76. package/dist/runners/pi/session.js +27 -44
  77. package/dist/runners/pi/supervisor.js +1 -0
  78. package/package.json +5 -3
  79. package/dist/engine/forwarder.sh +0 -61
@@ -9,17 +9,23 @@ export class ConfigError extends Error {
9
9
  }
10
10
  /** Basic environment-variable name grammar used by placeholders and declared variables. */
11
11
  export const ENV_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
12
+ /**
13
+ * Single source of truth for case fields and their structural types.
14
+ * Naming convention: plural names (`files`, `checks`, `mocks`) are collections (`list` / `map`);
15
+ * singular names (`input`, `runner`, `fixture`, `timeoutMs`, `expect`) are atomic `value`s.
16
+ */
17
+ export const CASE_FIELDS = {
18
+ input: "value",
19
+ fixture: "value",
20
+ files: { kind: "map", child: "value" },
21
+ timeoutMs: "value",
22
+ mocks: { kind: "map", child: { kind: "map", child: "value" } },
23
+ expect: "value",
24
+ checks: "list",
25
+ runner: "value",
26
+ };
12
27
  /** Top-level fields allowed in a complete resolved case. */
13
- export const CASE_FIELD_KEYS = new Set([
14
- "input",
15
- "fixture",
16
- "files",
17
- "timeoutMs",
18
- "mocks",
19
- "expect",
20
- "checks",
21
- "runner",
22
- ]);
28
+ export const CASE_FIELD_KEYS = new Set(Object.keys(CASE_FIELDS));
23
29
  /** The document-level authoring control for named cases. */
24
30
  export const CASES_KEY = "cases";
25
31
  const MOCK_KEYS = new Set(["shell"]);
@@ -1,7 +1,7 @@
1
- import { execFile } from "node:child_process";
2
1
  import { readFile } from "node:fs/promises";
3
2
  import { join } from "node:path";
4
3
  import { parseEnv } from "node:util";
4
+ import { spawnShellLookup } from "../platform/index.js";
5
5
  import { ConfigError, errorMessage } from "./config.js";
6
6
  const COMMAND_TIMEOUT_MS = 5_000;
7
7
  const COMMAND_MAX_OUTPUT_BYTES = 64 * 1024;
@@ -66,22 +66,90 @@ async function runLookupCommand(name, command, cwd, signal) {
66
66
  let stdout;
67
67
  try {
68
68
  stdout = await new Promise((resolve, reject) => {
69
- execFile("/bin/sh", ["-c", command], {
70
- cwd,
71
- env: process.env,
72
- encoding: "utf8",
73
- timeout: COMMAND_TIMEOUT_MS,
74
- maxBuffer: COMMAND_MAX_OUTPUT_BYTES,
75
- signal,
76
- killSignal: "SIGKILL",
77
- }, (error, output) => {
78
- if (error === null) {
79
- resolve(output);
69
+ const lookup = spawnShellLookup(command, cwd);
70
+ const { child } = lookup;
71
+ const chunks = [];
72
+ let bytes = 0;
73
+ let settled = false;
74
+ let terminating;
75
+ let reapTimer;
76
+ const finish = (fn) => {
77
+ if (settled)
78
+ return;
79
+ settled = true;
80
+ clearTimeout(timer);
81
+ if (reapTimer !== undefined)
82
+ clearTimeout(reapTimer);
83
+ signal?.removeEventListener("abort", onAbort);
84
+ fn();
85
+ };
86
+ const terminate = (reason) => {
87
+ if (terminating !== undefined)
88
+ return;
89
+ terminating = reason;
90
+ clearTimeout(timer);
91
+ signal?.removeEventListener("abort", onAbort);
92
+ child.stdout.destroy();
93
+ child.stderr.destroy();
94
+ lookup.terminate();
95
+ // Wait briefly for the direct child to be reaped, without hanging on detached
96
+ // descendants that may still hold inherited file descriptors.
97
+ reapTimer = setTimeout(() => finish(() => reject(reason)), 200);
98
+ reapTimer.unref();
99
+ };
100
+ const onAbort = () => {
101
+ terminate(Object.assign(new Error("aborted"), { code: "ABORT_ERR" }));
102
+ };
103
+ const timer = setTimeout(() => {
104
+ terminate(Object.assign(new Error("timed out"), { killed: true }));
105
+ }, COMMAND_TIMEOUT_MS);
106
+ signal?.addEventListener("abort", onAbort, { once: true });
107
+ const onData = (chunk, collect) => {
108
+ if (terminating !== undefined)
109
+ return;
110
+ bytes += chunk.length;
111
+ if (bytes > COMMAND_MAX_OUTPUT_BYTES) {
112
+ terminate(Object.assign(new Error("maxBuffer exceeded"), { code: "ERR_CHILD_PROCESS_STDIO_MAXBUFFER" }));
113
+ return;
80
114
  }
81
- else {
82
- reject(error);
115
+ if (collect)
116
+ chunks.push(chunk);
117
+ };
118
+ child.stdout.on("data", (chunk) => onData(chunk, true));
119
+ child.stderr.on("data", (chunk) => onData(chunk, false));
120
+ child.on("error", (error) => {
121
+ finish(() => reject(terminating ?? error));
122
+ });
123
+ child.on("exit", (code, exitSignal) => {
124
+ if (terminating !== undefined) {
125
+ const reason = terminating;
126
+ finish(() => reject(reason));
127
+ return;
128
+ }
129
+ if (code !== 0) {
130
+ const reason = code !== null
131
+ ? Object.assign(new Error("non-zero exit"), { code })
132
+ : Object.assign(new Error("signalled"), { signal: exitSignal ?? "SIGKILL" });
133
+ terminate(reason);
134
+ finish(() => reject(reason));
83
135
  }
84
136
  });
137
+ child.on("close", (code, exitSignal) => {
138
+ finish(() => {
139
+ if (terminating !== undefined) {
140
+ reject(terminating);
141
+ }
142
+ else if (code === 0) {
143
+ resolve(Buffer.concat(chunks).toString("utf8"));
144
+ }
145
+ else if (code !== null) {
146
+ reject(Object.assign(new Error("non-zero exit"), { code }));
147
+ }
148
+ else {
149
+ reject(Object.assign(new Error("signalled"), { signal: exitSignal ?? "SIGKILL" }));
150
+ }
151
+ });
152
+ });
85
153
  });
86
154
  }
87
155
  catch (error) {
@@ -1,4 +1,5 @@
1
1
  import { type ResolvedCase } from "./config.js";
2
+ import { fileIdentity } from "./workspace.js";
2
3
  /**
3
4
  * Place the case's workspace `files` entries into the prepared workspace. Entries are
4
5
  * combined in an otherwise empty staging directory first, so an entry can
@@ -51,11 +52,7 @@ export declare function copyPlacement(stagingDir: string, targetDir: string, opt
51
52
  readonly protect?: PlacementProtection;
52
53
  readonly signal?: AbortSignal;
53
54
  }): Promise<void>;
54
- /** The identity a filesystem uses for one file, independent of the spelling that reached it. */
55
- export declare function fileIdentity(info: {
56
- readonly dev: bigint;
57
- readonly ino: bigint;
58
- }): string;
55
+ export { fileIdentity };
59
56
  /**
60
57
  * Validate a checker's check-time `files`: workspace destinations and authoring sources, with
61
58
  * the same rules as `case.files` destinations plus a non-root destination. Throws `ConfigError`
@@ -3,7 +3,7 @@ import { tmpdir } from "node:os";
3
3
  import { dirname, join, relative, resolve, sep } from "node:path";
4
4
  import { ConfigError, errorMessage, expectRelativePath, expectWorkspaceDestination, resolveAuthoringAsset, workspaceTargetPath, } from "./config.js";
5
5
  import { IgnoreTree, isIgnored } from "./ignore.js";
6
- import { isMissing } from "./workspace.js";
6
+ import { fileIdentity, isMissing } from "./workspace.js";
7
7
  /**
8
8
  * Place the case's workspace `files` entries into the prepared workspace. Entries are
9
9
  * combined in an otherwise empty staging directory first, so an entry can
@@ -74,7 +74,8 @@ export async function placedPaths(entries, authoringDir, label, signal) {
74
74
  return;
75
75
  }
76
76
  for (const name of await readdir(source)) {
77
- await walk(join(source, name), join(target, name), join(destination, name), [...segments, name], root);
77
+ const childTarget = target === "" ? name : `${target}/${name}`;
78
+ await walk(join(source, name), childTarget, `${destination}/${name}`, [...segments, name], root);
78
79
  }
79
80
  };
80
81
  for (const entry of entries) {
@@ -91,10 +92,7 @@ export async function placedPaths(entries, authoringDir, label, signal) {
91
92
  export async function copyPlacement(stagingDir, targetDir, options) {
92
93
  await copyInto(stagingDir, targetDir, ".", options.label, options.overwrite, options.signal, { tree: new IgnoreTree(), root: stagingDir, segments: [] }, options.protect === undefined ? undefined : new ProtectedPaths(options.protect));
93
94
  }
94
- /** The identity a filesystem uses for one file, independent of the spelling that reached it. */
95
- export function fileIdentity(info) {
96
- return `${info.dev}:${info.ino}`;
97
- }
95
+ export { fileIdentity };
98
96
  /** Target-relative files a placement may never create or replace. */
99
97
  class ProtectedPaths {
100
98
  #paths;
@@ -1,9 +1,9 @@
1
1
  import { spawn } from "node:child_process";
2
- import { link, mkdir, readFile, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
2
+ import { link, mkdir, readFile, realpath, rename, stat, writeFile } from "node:fs/promises";
3
3
  import { createServer } from "node:net";
4
4
  import { basename, dirname, join, relative, sep } from "node:path";
5
5
  import { setTimeout as delay } from "node:timers/promises";
6
- import { tmpdir } from "node:os";
6
+ import { listenMockServer, mockForwarderSpec, } from "../platform/index.js";
7
7
  import { ConfigError, errorMessage } from "./config.js";
8
8
  import { compileShellMocks, matchCall } from "./mock-match.js";
9
9
  import { isMissing, isWithin, openRunRoot, resolveWorkspacePath } from "./workspace.js";
@@ -15,41 +15,23 @@ const MAX_CALL_BYTES = 1_000_000;
15
15
  const PASS_MARKER = Buffer.from("agent-evals:pass");
16
16
  const PASS_MARKER_LINE = Buffer.from("agent-evals:pass\n");
17
17
  const EMPTY = Buffer.alloc(0);
18
- // The forwarder is a POSIX shell asset beside this module, copied unchanged by the build, so
19
- // source and built runs read one text. It reports the call over the run's socket and reads the
20
- // reply from a single line: capturing the reply would strip the trailing newlines that make an
21
- // empty stdout or stderr distinguishable. The name it is executed under selects the target.
22
- const FORWARDER_ASSET = new URL("./forwarder.sh", import.meta.url);
23
18
  /**
24
19
  * Write every forwarder, workspace scripts included, and start answering calls. The caller
25
20
  * runs this before the baseline snapshot, so the snapshot already holds the forwarders.
26
21
  */
27
22
  export async function startMockHost(options) {
23
+ const spec = mockForwarderSpec();
28
24
  const forwarderDir = options.mocksDir;
29
- // A Unix socket path is limited to about 100 bytes, so it cannot live under the run root.
30
- const socketPath = join(tmpdir(), `${basename(options.runRootDir)}.sock`);
31
25
  const faultPath = join(options.tmpDir, ".forward-fault");
32
26
  // The template lives in engine-private state; only its hard links are runnable in mocks/.
33
- const scriptPath = join(options.engineDir, "forward");
27
+ const scriptPath = join(options.engineDir, spec.templateName);
34
28
  const rules = compileShellMocks(options.shell);
35
29
  const workspaceRoot = await openRunRoot(options.workspaceDir);
36
30
  await mkdir(forwarderDir, { recursive: true, mode: 0o700 });
37
31
  // The forwarder canonicalises its own path, so identity comparisons use the real directory.
38
32
  const forwarderRoot = await realpath(forwarderDir);
39
- const forwarder = (await readFile(FORWARDER_ASSET, "utf8"))
40
- .replace("__BINDIR__", quote(forwarderRoot))
41
- .replace("__SOCKET__", quote(socketPath))
42
- .replace("__FAULT__", quote(faultPath));
43
- await writeFile(scriptPath, forwarder, { mode: 0o500, flag: "wx" });
44
- for (const target of Object.keys(options.shell).sort()) {
45
- if (target.includes("/")) {
46
- await placeWorkspaceForwarder(workspaceRoot.path, options, target, forwarder);
47
- }
48
- else {
49
- await link(scriptPath, join(forwarderDir, target));
50
- }
51
- }
52
- const wiring = { forwarderDir, socketPath, denyTargets: denyTargetsOf(options.shell) };
33
+ const nodeExecutable = await realpath(process.execPath);
34
+ const clientPath = await realpath(spec.clientPath);
53
35
  const records = [];
54
36
  const faults = [];
55
37
  /** Process-group leaders still owning descendants we must not leave behind. */
@@ -78,19 +60,76 @@ export async function startMockHost(options) {
78
60
  });
79
61
  });
80
62
  });
81
- await listen(server, socketPath);
63
+ const endpoint = await listenMockServer(server, options.runRootDir);
64
+ const { socketPath, expectedNonce } = endpoint;
65
+ const renderForwarder = async (template) => {
66
+ const replacements = {
67
+ __NODE__: template.quote(nodeExecutable),
68
+ __CLIENT__: template.quote(clientPath),
69
+ __BINDIR__: template.quote(forwarderRoot),
70
+ __SOCKET__: template.quote(socketPath),
71
+ __FAULT__: template.quote(faultPath),
72
+ };
73
+ return (await readFile(template.assetPath, "utf8")).replace(/__NODE__|__CLIENT__|__BINDIR__|__SOCKET__|__FAULT__/g, (token) => replacements[token]);
74
+ };
75
+ const forwarder = await renderForwarder(spec);
76
+ const extraPathTemplates = await Promise.all((spec.extraPathForwarders ?? []).map(async (extra) => ({
77
+ extra,
78
+ scriptPath: join(options.engineDir, extra.templateName),
79
+ content: await renderForwarder(extra),
80
+ })));
81
+ try {
82
+ await writeFile(scriptPath, forwarder, { mode: 0o500, flag: "wx" });
83
+ for (const entry of extraPathTemplates) {
84
+ await writeFile(entry.scriptPath, entry.content, { mode: 0o500, flag: "wx" });
85
+ }
86
+ for (const target of Object.keys(options.shell).sort()) {
87
+ if (target.includes("/")) {
88
+ const wsTemplate = spec.workspaceForwarder?.(target);
89
+ const wsForwarder = wsTemplate === undefined || wsTemplate.assetPath === spec.assetPath
90
+ ? forwarder
91
+ : await renderForwarder(wsTemplate);
92
+ await placeWorkspaceForwarder(workspaceRoot.path, options, target, wsForwarder);
93
+ }
94
+ else {
95
+ await link(scriptPath, join(forwarderDir, spec.targetFileName(target)));
96
+ for (const entry of extraPathTemplates) {
97
+ await link(entry.scriptPath, join(forwarderDir, entry.extra.targetFileName(target)));
98
+ }
99
+ }
100
+ }
101
+ }
102
+ catch (error) {
103
+ server.close();
104
+ await endpoint.cleanup().catch(() => { });
105
+ throw error;
106
+ }
107
+ const wiring = {
108
+ forwarderDir,
109
+ socketPath,
110
+ denyTargets: denyTargetsOf(options.shell),
111
+ readableFiles: [nodeExecutable, clientPath],
112
+ };
82
113
  async function answer(socket, message) {
83
114
  const lines = message.toString("utf8").split("\n");
84
115
  if (lines.pop() !== "" || lines.length === 0) {
85
116
  socket.end(denied("call"));
86
117
  return;
87
118
  }
88
- const call = resolveCall(decode(lines[0]), forwarderRoot, workspaceRoot.path, rules);
119
+ let startIndex = 0;
120
+ if (expectedNonce !== undefined) {
121
+ if (decode(lines[0]) !== `nonce:${expectedNonce}` || lines.length < 2) {
122
+ socket.end(denied("call"));
123
+ return;
124
+ }
125
+ startIndex = 1;
126
+ }
127
+ const call = resolveCall(decode(lines[startIndex]), forwarderRoot, workspaceRoot.path, rules, spec);
89
128
  if (call === undefined) {
90
129
  socket.end(denied("call"));
91
130
  return;
92
131
  }
93
- const argv = lines.slice(1).map(decode);
132
+ const argv = lines.slice(startIndex + 1).map(decode);
94
133
  records.push({ target: call.target, arguments: argv });
95
134
  const action = matchCall(call.rules, argv);
96
135
  socket.end(action === undefined ? denied(call.target) : await reply(action, call.target, argv));
@@ -140,7 +179,7 @@ export async function startMockHost(options) {
140
179
  for (const socket of sockets)
141
180
  socket.destroy();
142
181
  await closed;
143
- await rm(socketPath, { force: true });
182
+ await endpoint.cleanup();
144
183
  faults.push(...(await transportFaults(faultPath)));
145
184
  return { records: [...records], faults: [...faults] };
146
185
  }
@@ -159,11 +198,11 @@ function denyTargetsOf(shell) {
159
198
  * or at its workspace-relative path. A bare name and `./name` are different targets: a `PATH`
160
199
  * command and a workspace-root script.
161
200
  */
162
- function resolveCall(self, forwarderRoot, workspaceDir, rules) {
163
- if (dirname(self) === forwarderRoot) {
164
- const name = basename(self);
165
- const targetRules = rules.path.get(name);
166
- return targetRules === undefined ? undefined : { target: name, rules: targetRules };
201
+ function resolveCall(self, forwarderRoot, workspaceDir, rules, spec) {
202
+ const pathTarget = spec.resolvePathTargetName(self, forwarderRoot);
203
+ if (pathTarget !== undefined) {
204
+ const targetRules = rules.path.get(pathTarget);
205
+ return targetRules === undefined ? undefined : { target: pathTarget, rules: targetRules };
167
206
  }
168
207
  if (isWithin(workspaceDir, self)) {
169
208
  const path = relative(workspaceDir, self).split(sep).join("/");
@@ -318,19 +357,6 @@ function denied(target) {
318
357
  function field(bytes) {
319
358
  return bytes.length === 0 ? "-" : bytes.toString("base64");
320
359
  }
321
- /** Quote a value as one POSIX shell word. */
322
- function quote(value) {
323
- return `'${value.replaceAll("'", "'\\''")}'`;
324
- }
325
360
  function decode(line) {
326
361
  return Buffer.from(line, "base64").toString("utf8");
327
362
  }
328
- function listen(server, path) {
329
- return new Promise((resolve, reject) => {
330
- server.once("error", reject);
331
- server.listen(path, () => {
332
- server.off("error", reject);
333
- resolve();
334
- });
335
- });
336
- }
@@ -12,5 +12,7 @@ export declare const patternListSchema: z.ZodPipe<z.ZodUnknown, z.ZodTransform<r
12
12
  export declare const nonEmptyTrimmedString: z.ZodString;
13
13
  /** Shared schema rule for check targets relative to the evaluated workspace. */
14
14
  export declare const runRelativePathSchema: z.ZodString;
15
+ /** A workspace path, or `~/…` for a file or directory inside the run HOME. `~/` alone names HOME itself. */
16
+ export declare const runFilePathSchema: z.ZodString;
15
17
  /** Parse raw declared parameters exactly once with the implementation's Zod schema. */
16
18
  export declare function parseImplementationParams<P>(schema: ZodType<P>, raw: ImplementationParams, label: string): Promise<P>;
@@ -1,3 +1,4 @@
1
+ import { posix } from "node:path";
1
2
  import { z } from "zod";
2
3
  import { ConfigError, parsePatternScalar, } from "./config.js";
3
4
  /**
@@ -67,6 +68,15 @@ export const runRelativePathSchema = z
67
68
  .refine((value) => !value.startsWith("/") && !value.split(/[\\/]+/).includes(".."), {
68
69
  message: "must be relative to the run workspace without '..' segments",
69
70
  });
71
+ /** A workspace path, or `~/…` for a file or directory inside the run HOME. `~/` alone names HOME itself. */
72
+ export const runFilePathSchema = runRelativePathSchema.superRefine((value, context) => {
73
+ if (value.startsWith("~/")) {
74
+ const inner = posix.normalize(value.slice(2)).replace(/\/+$/u, "");
75
+ if (inner === "" || inner === ".") {
76
+ context.addIssue({ code: "custom", message: "must name a file or directory inside HOME, not HOME itself" });
77
+ }
78
+ }
79
+ });
70
80
  /** Parse raw declared parameters exactly once with the implementation's Zod schema. */
71
81
  export async function parseImplementationParams(schema, raw, label) {
72
82
  const result = await schema.safeParseAsync(raw);
@@ -27,6 +27,8 @@ export interface MockWiring {
27
27
  readonly socketPath: string;
28
28
  /** `PATH` targets no rule can pass to the real command; their binaries stay denied. */
29
29
  readonly denyTargets: readonly string[];
30
+ /** Additional read-only files the forwarders need inside a deny-default sandbox (e.g. Node). */
31
+ readonly readableFiles?: readonly string[];
30
32
  }
31
33
  export interface RunnerOutcome {
32
34
  readonly finalText: string | null;
@@ -112,6 +114,8 @@ export interface Runner {
112
114
  readonly prepareHome?: (context: RunnerContext) => Promise<readonly string[]>;
113
115
  /** HOME-relative login files a case may never place over; independent of `prepareHome`. */
114
116
  readonly homeFiles?: readonly string[];
117
+ /** Shared mutable host resource key (e.g., persistent login dir); runs with the same key serialize. */
118
+ readonly concurrencyKey?: string;
115
119
  readonly run: (context: RunnerContext) => Promise<RunnerOutcome>;
116
120
  /** Stop the harness and its owned processes. Must be idempotent. */
117
121
  readonly stop: () => Promise<void>;
@@ -166,6 +170,11 @@ export interface RegisteredRunnerDefinition {
166
170
  /** Declared by the definition when the runner gives the run a HOME. */
167
171
  readonly home?: boolean;
168
172
  }
173
+ /** HOME-relative paths and file identities belonging to runner login state, never exposed to checks. */
174
+ export interface HomeProtection {
175
+ readonly paths: readonly string[];
176
+ readonly identities: readonly string[];
177
+ }
169
178
  export interface CheckerContext {
170
179
  /** Prepared workspace root; its identity is verified for every operation. */
171
180
  readonly workspace: RunRoot;
@@ -175,6 +184,8 @@ export interface CheckerContext {
175
184
  readonly home: RunRoot;
176
185
  /** What the case placed in HOME, outside the evaluated agent's writable area. */
177
186
  readonly homeBaseline: RunRoot;
187
+ /** Runner login files in HOME that checks must not expose. */
188
+ readonly protectedHome?: HomeProtection;
178
189
  readonly runRootDir: string;
179
190
  readonly input: string;
180
191
  /** The runner's trace, when it records one. */
@@ -220,7 +220,16 @@ function document(path, cases) {
220
220
  function instrument(cases) {
221
221
  const runs = [...cases.values()].flat();
222
222
  const counts = new Set([...cases.values()].map((entry) => entry.length));
223
- return `runner ${listed(runs.map((run) => value(run.resolvedConfig.runner["$type"])))} · harness ${listed(runs.map(harness))} · model ${listed(runs.map(model))} · ${counts.size === 1 ? `reps ${[...counts][0]}` : "reps mixed"} · cases ${cases.size}`;
223
+ const judges = judgeInstruments(runs);
224
+ const parts = [
225
+ `runner ${listed(runs.map((run) => value(run.resolvedConfig.runner["$type"])))}`,
226
+ `harness ${listed(runs.map(harness))}`,
227
+ `model ${listed(runs.map(model))}`,
228
+ ...(judges.length === 0 ? [] : [`judge ${listed(judges)}`]),
229
+ counts.size === 1 ? `reps ${[...counts][0]}` : "reps mixed",
230
+ `cases ${cases.size}`,
231
+ ];
232
+ return parts.join(" · ");
224
233
  }
225
234
  function caseLine(label, runs, width, verdictWidth) {
226
235
  const verdict = verdictOf(runs);
@@ -346,19 +355,45 @@ function longest(values) {
346
355
  return size;
347
356
  }
348
357
  function harness(record) {
349
- const agent = record.resolvedConfig.runner["agent"];
358
+ return harnessOf(record.resolvedConfig.runner);
359
+ }
360
+ function model(record) {
361
+ return modelOf(record.resolvedConfig.runner);
362
+ }
363
+ function harnessOf(runner) {
364
+ const agent = runner["agent"];
350
365
  if (typeof agent !== "string")
351
- return value(record.resolvedConfig.runner["$type"]);
366
+ return value(runner["$type"]);
352
367
  const name = basename(agent);
353
- return name.includes(".") ? name.slice(0, name.lastIndexOf(".")) : name;
368
+ return value(name.includes(".") ? name.slice(0, name.lastIndexOf(".")) : name);
354
369
  }
355
- function model(record) {
356
- const config = record.resolvedConfig.runner["config"];
370
+ function modelOf(runner) {
371
+ const config = runner["config"];
357
372
  const configured = typeof config === "object" && config !== null ? config["model"] : undefined;
358
- return value(configured ?? record.resolvedConfig.runner["model"]);
373
+ return value(configured ?? runner["model"]);
374
+ }
375
+ function judgeInstruments(runs) {
376
+ const result = [];
377
+ for (const run of runs) {
378
+ for (const check of run.resolvedConfig.checks) {
379
+ if (check["$type"] !== "judge")
380
+ continue;
381
+ const declared = check["runner"];
382
+ const runner = typeof declared === "object" && declared !== null && !Array.isArray(declared)
383
+ ? declared
384
+ : run.resolvedConfig.runner;
385
+ const judgeHarness = harnessOf(runner);
386
+ const judgeModel = modelOf(runner);
387
+ result.push(judgeModel === "—" ? judgeHarness : `${judgeHarness}/${judgeModel}`);
388
+ }
389
+ }
390
+ return result;
359
391
  }
360
392
  function value(input) {
361
- return typeof input === "string" && input !== "" ? input : "—";
393
+ if (typeof input !== "string")
394
+ return "—";
395
+ const singleLine = input.replace(/\r\n?|[\n\u0085\u2028\u2029]/gu, " ").trim();
396
+ return singleLine === "" ? "—" : singleLine;
362
397
  }
363
398
  function sum(runs, pick) {
364
399
  return runs.reduce((total, run) => total + pick(run), 0);
@@ -1,8 +1,10 @@
1
1
  import type { CaseConfig } from "./config.js";
2
2
  import type { MockRecord, RecordedCheckResult, RunnerUsage, TraceEntry } from "./registry.js";
3
3
  export type RunStatus = "pass" | "fail" | "error" | "timeout" | "cancelled";
4
+ export type RetainArtifacts = "none" | "on-failure" | "all";
4
5
  /** A run read against its case's expectation; the only place `expect` changes a status's meaning. */
5
6
  export type RunOutcome = RunStatus | "expected-fail" | "unexpected-pass";
7
+ export declare function classifyOutcome(status: RunStatus, expect: CaseConfig["expect"]): RunOutcome;
6
8
  export declare function runOutcome(run: EvaluationRecord): RunOutcome;
7
9
  export type RunnerStatus = "completed" | "error" | "timeout" | "cancelled";
8
10
  export interface RunnerRecord {
@@ -33,6 +35,11 @@ export interface EvaluationRecord {
33
35
  readonly status: "removed" | "failed";
34
36
  readonly error?: string;
35
37
  };
38
+ readonly artifacts?: {
39
+ readonly status: "retained" | "failed";
40
+ readonly path?: string;
41
+ readonly error?: string;
42
+ };
36
43
  }
37
44
  export interface ResultPaths {
38
45
  readonly directory: string;
@@ -1,14 +1,17 @@
1
1
  import { mkdir, rename, writeFile } from "node:fs/promises";
2
2
  import { join, resolve } from "node:path";
3
3
  import { randomUUID } from "node:crypto";
4
- export function runOutcome(run) {
5
- if (run.status === "pass") {
6
- return run.resolvedConfig.expect === "fail" ? "unexpected-pass" : "pass";
4
+ export function classifyOutcome(status, expect) {
5
+ if (status === "pass") {
6
+ return expect === "fail" ? "unexpected-pass" : "pass";
7
7
  }
8
- if (run.status === "fail") {
9
- return run.resolvedConfig.expect === "fail" ? "expected-fail" : "fail";
8
+ if (status === "fail") {
9
+ return expect === "fail" ? "expected-fail" : "fail";
10
10
  }
11
- return run.status;
11
+ return status;
12
+ }
13
+ export function runOutcome(run) {
14
+ return classifyOutcome(run.status, run.resolvedConfig.expect);
12
15
  }
13
16
  export function newRunId(now = new Date()) {
14
17
  return `${now.toISOString().replaceAll(":", "-").replaceAll(".", "-")}-${randomUUID().slice(0, 8)}`;
@@ -1,11 +1,12 @@
1
1
  import { type ResolvedCase } from "./config.js";
2
2
  import { type Checker, type Registry, type Runner } from "./registry.js";
3
- import { type EvaluationRecord } from "./results.js";
3
+ import { type EvaluationRecord, type RetainArtifacts } from "./results.js";
4
4
  import { type EnvSource } from "./env-source.js";
5
5
  export interface RunRequest {
6
6
  readonly case: ResolvedCase;
7
7
  readonly registry: Registry;
8
8
  readonly resultsDir: string;
9
+ readonly retain?: RetainArtifacts;
9
10
  readonly signal?: AbortSignal;
10
11
  /** Parent directory for the temporary run root. Tests use this to inspect cleanup. */
11
12
  readonly tempParent?: string;
@@ -34,6 +35,8 @@ export interface PreparedEvaluation {
34
35
  readonly type: string;
35
36
  readonly checker: Checker;
36
37
  }[];
38
+ /** Shared mutable resource keys across all runners created for this evaluation (case + checkers). */
39
+ readonly concurrencyKeys: readonly string[];
37
40
  };
38
41
  }
39
42
  /**