@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.
Files changed (105) hide show
  1. package/.env.example +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +121 -2
  4. package/dist/checkers/file/index.d.ts +26 -0
  5. package/dist/checkers/file/index.js +396 -0
  6. package/dist/checkers/judge/index.d.ts +20 -0
  7. package/dist/checkers/judge/index.js +474 -0
  8. package/dist/checkers/judge/prompt.d.ts +19 -0
  9. package/dist/checkers/judge/prompt.js +55 -0
  10. package/dist/checkers/judge/trace.d.ts +6 -0
  11. package/dist/checkers/judge/trace.js +41 -0
  12. package/dist/checkers/mock/index.d.ts +18 -0
  13. package/dist/checkers/mock/index.js +127 -0
  14. package/dist/checkers/shell/index.d.ts +10 -0
  15. package/dist/checkers/shell/index.js +61 -0
  16. package/dist/checkers/trace/index.d.ts +22 -0
  17. package/dist/checkers/trace/index.js +183 -0
  18. package/dist/cli.d.ts +2 -0
  19. package/dist/cli.js +453 -0
  20. package/dist/engine/authoring.d.ts +24 -0
  21. package/dist/engine/authoring.js +356 -0
  22. package/dist/engine/check-runner.d.ts +1 -0
  23. package/dist/engine/check-runner.js +127 -0
  24. package/dist/engine/check-sandbox.d.ts +18 -0
  25. package/dist/engine/check-sandbox.js +171 -0
  26. package/dist/engine/config.d.ts +171 -0
  27. package/dist/engine/config.js +368 -0
  28. package/dist/engine/env-source.d.ts +10 -0
  29. package/dist/engine/env-source.js +114 -0
  30. package/dist/engine/files.d.ts +84 -0
  31. package/dist/engine/files.js +304 -0
  32. package/dist/engine/forwarder.sh +61 -0
  33. package/dist/engine/ignore.d.ts +29 -0
  34. package/dist/engine/ignore.js +67 -0
  35. package/dist/engine/messages.d.ts +8 -0
  36. package/dist/engine/messages.js +9 -0
  37. package/dist/engine/mock-match.d.ts +44 -0
  38. package/dist/engine/mock-match.js +104 -0
  39. package/dist/engine/mocks.d.ts +35 -0
  40. package/dist/engine/mocks.js +336 -0
  41. package/dist/engine/params.d.ts +18 -0
  42. package/dist/engine/params.js +96 -0
  43. package/dist/engine/placement.d.ts +26 -0
  44. package/dist/engine/placement.js +107 -0
  45. package/dist/engine/regex.d.ts +10 -0
  46. package/dist/engine/regex.js +16 -0
  47. package/dist/engine/registry.d.ts +243 -0
  48. package/dist/engine/registry.js +127 -0
  49. package/dist/engine/report.d.ts +17 -0
  50. package/dist/engine/report.js +420 -0
  51. package/dist/engine/results.d.ts +50 -0
  52. package/dist/engine/results.js +42 -0
  53. package/dist/engine/run.d.ts +50 -0
  54. package/dist/engine/run.js +710 -0
  55. package/dist/engine/runtime-assets.d.ts +6 -0
  56. package/dist/engine/runtime-assets.js +11 -0
  57. package/dist/engine/skills.d.ts +49 -0
  58. package/dist/engine/skills.js +270 -0
  59. package/dist/engine/truncate.d.ts +3 -0
  60. package/dist/engine/truncate.js +7 -0
  61. package/dist/engine/values.d.ts +18 -0
  62. package/dist/engine/values.js +75 -0
  63. package/dist/engine/view.d.ts +10 -0
  64. package/dist/engine/view.js +150 -0
  65. package/dist/engine/workspace.d.ts +63 -0
  66. package/dist/engine/workspace.js +305 -0
  67. package/dist/index.d.ts +16 -0
  68. package/dist/index.js +7 -0
  69. package/dist/platform/macos/launch.d.ts +13 -0
  70. package/dist/platform/macos/launch.js +14 -0
  71. package/dist/platform/macos/policy.d.ts +33 -0
  72. package/dist/platform/macos/policy.js +131 -0
  73. package/dist/platform/macos/supervise.d.ts +26 -0
  74. package/dist/platform/macos/supervise.js +98 -0
  75. package/dist/platform/macos/supervisor.sh +13 -0
  76. package/dist/runners/acp/agent.d.ts +17 -0
  77. package/dist/runners/acp/agent.js +38 -0
  78. package/dist/runners/acp/commands.d.ts +2 -0
  79. package/dist/runners/acp/commands.js +112 -0
  80. package/dist/runners/acp/environment.d.ts +71 -0
  81. package/dist/runners/acp/environment.js +280 -0
  82. package/dist/runners/acp/index.d.ts +21 -0
  83. package/dist/runners/acp/index.js +135 -0
  84. package/dist/runners/acp/session.d.ts +7 -0
  85. package/dist/runners/acp/session.js +48 -0
  86. package/dist/runners/acp/trace.d.ts +23 -0
  87. package/dist/runners/acp/trace.js +44 -0
  88. package/dist/runners/acp/usage.d.ts +12 -0
  89. package/dist/runners/acp/usage.js +56 -0
  90. package/dist/runners/noop/index.d.ts +12 -0
  91. package/dist/runners/noop/index.js +22 -0
  92. package/dist/runners/pi/index.d.ts +21 -0
  93. package/dist/runners/pi/index.js +116 -0
  94. package/dist/runners/pi/params.d.ts +10 -0
  95. package/dist/runners/pi/params.js +3 -0
  96. package/dist/runners/pi/rpc.d.ts +30 -0
  97. package/dist/runners/pi/rpc.js +341 -0
  98. package/dist/runners/pi/safe-process-group.d.ts +7 -0
  99. package/dist/runners/pi/safe-process-group.js +13 -0
  100. package/dist/runners/pi/session.d.ts +56 -0
  101. package/dist/runners/pi/session.js +298 -0
  102. package/dist/runners/pi/shell-wrapper.sh +46 -0
  103. package/dist/runners/pi/supervisor.d.ts +1 -0
  104. package/dist/runners/pi/supervisor.js +101 -0
  105. package/package.json +77 -4
@@ -0,0 +1,84 @@
1
+ import { type ResolvedCase } from "./config.js";
2
+ import { fileIdentity } from "./workspace.js";
3
+ /**
4
+ * Place the case's workspace `files` entries into the prepared workspace. Entries are
5
+ * combined in an otherwise empty staging directory first, so an entry can
6
+ * replace what the fixture provided but never another entry.
7
+ */
8
+ export declare function placeCaseFiles(loadedCase: ResolvedCase, stagingDir: string, workspaceDir: string): Promise<void>;
9
+ /** One placement: the declared destination, where it goes under its root, and its source. */
10
+ export interface PlacementEntry {
11
+ /** The destination as the author declared it, for messages and reporting. */
12
+ readonly destination: string;
13
+ /** The root-relative path the source is placed at. */
14
+ readonly target: string;
15
+ readonly source: string;
16
+ }
17
+ /** The case `files` entries that go to the workspace, with normalized relative targets. */
18
+ export declare function workspaceEntries(files: Readonly<Record<string, string>> | undefined): readonly PlacementEntry[];
19
+ /** The case `files` entries that go into HOME, with `~/` stripped from their targets. */
20
+ export declare function homeEntries(files: Readonly<Record<string, string>> | undefined): readonly PlacementEntry[];
21
+ /** A `~/` destination names HOME; anything else names the workspace. */
22
+ export declare function isHomeDestination(destination: string): boolean;
23
+ /** The HOME-relative path a `~/` destination names; the HOME root itself is the empty path. */
24
+ export declare function homePathOf(destination: string): string;
25
+ /**
26
+ * Copy placement entries into an empty staging directory: the same traversal and ignore rules
27
+ * as a workspace placement, with each target taken relative to the staging root. Two entries
28
+ * normalized to one path collide there, because staging never overwrites.
29
+ */
30
+ export declare function stageEntries(entries: readonly PlacementEntry[], authoringDir: string, stagingDir: string, label: string, signal?: AbortSignal): Promise<void>;
31
+ /** Files a placement may never create or replace: by declared path and by file identity. */
32
+ export interface PlacementProtection {
33
+ /** Target-relative paths, compared as written (login files as declared). */
34
+ readonly paths?: readonly string[];
35
+ /** File identities (`dev:ino`), so an alias in any spelling cannot be written through. */
36
+ readonly identities?: readonly string[];
37
+ }
38
+ /**
39
+ * The target-relative paths a placement would write, without copying anything. Used at load
40
+ * time to reject a placement that would land on login state before any run resource exists.
41
+ * The traversal and ignore answers are the staging copy's, so the answer matches what would be
42
+ * placed; a source that cannot be placed is the same error as it would be there.
43
+ */
44
+ export declare function placedPaths(entries: readonly PlacementEntry[], authoringDir: string, label: string, signal?: AbortSignal): Promise<readonly string[]>;
45
+ /**
46
+ * Copy a staged placement tree onto its target. `overwrite` decides file-on-file replacement;
47
+ * `protect` names the login state no copy may place over.
48
+ */
49
+ export declare function copyPlacement(stagingDir: string, targetDir: string, options: {
50
+ readonly label: string;
51
+ readonly overwrite: boolean;
52
+ readonly protect?: PlacementProtection;
53
+ readonly signal?: AbortSignal;
54
+ }): Promise<void>;
55
+ export { fileIdentity };
56
+ /**
57
+ * Validate a checker's check-time `files`: workspace destinations and authoring sources, with
58
+ * the same rules as `case.files` destinations plus a non-root destination. Throws `ConfigError`
59
+ * so an extension checker that did no schema validation of its own still gets safe paths.
60
+ */
61
+ export declare function expectCheckFiles(files: Readonly<Record<string, unknown>>): void;
62
+ /**
63
+ * Validate a checker's files, then stage them for the check sandbox. The destination is created
64
+ * by the caller and is read-only inside the sandbox.
65
+ */
66
+ export declare function stageCheckFiles(files: Readonly<Record<string, string>>, authoringDir: string, stagingDir: string, signal?: AbortSignal, label?: string): Promise<void>;
67
+ /**
68
+ * Validate and stage a checker's files once at load, then discard the staging tree. A missing or
69
+ * special source, a nested symlink that is not a regular file, or two entries producing one file
70
+ * is a `ConfigError` before any run directory exists.
71
+ */
72
+ export declare function validateCheckFiles(files: Readonly<Record<string, string>>, authoringDir: string, label?: string, signal?: AbortSignal): Promise<void>;
73
+ /**
74
+ * Copy authoring `files` entries into an empty staging directory. Every visited source must be a
75
+ * regular file or directory; a symlink is accepted only when its target is a regular file, so a
76
+ * link to a FIFO, device or directory fails cleanly instead of blocking or escaping. Two entries
77
+ * producing the same file are an error, as is a file and a directory at one path.
78
+ */
79
+ export declare function stageFiles(files: Readonly<Record<string, string>>, authoringDir: string, stagingDir: string, label: string, signal?: AbortSignal): Promise<void>;
80
+ /**
81
+ * A `cp` filter that applies `.agentevalsignore` to the fixture copy. It shares the ignore
82
+ * decision with the directory copier below, so both place the same paths.
83
+ */
84
+ export declare function authoringCopyFilter(source: string): (path: string) => Promise<boolean>;
@@ -0,0 +1,304 @@
1
+ import { copyFile, lstat, mkdir, mkdtemp, readdir, rm, stat } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { dirname, join, relative, resolve, sep } from "node:path";
4
+ import { ConfigError, errorMessage, expectRelativePath, expectWorkspaceDestination, resolveAuthoringAsset, workspaceTargetPath, } from "./config.js";
5
+ import { IgnoreTree, isIgnored } from "./ignore.js";
6
+ import { fileIdentity, isMissing } from "./workspace.js";
7
+ /**
8
+ * Place the case's workspace `files` entries into the prepared workspace. Entries are
9
+ * combined in an otherwise empty staging directory first, so an entry can
10
+ * replace what the fixture provided but never another entry.
11
+ */
12
+ export async function placeCaseFiles(loadedCase, stagingDir, workspaceDir) {
13
+ const entries = workspaceEntries(loadedCase.config.files);
14
+ if (entries.length === 0) {
15
+ return;
16
+ }
17
+ await stageEntries(entries, loadedCase.dir, stagingDir, "files");
18
+ await copyPlacement(stagingDir, workspaceDir, { label: "files", overwrite: true });
19
+ await rm(stagingDir, { recursive: true, force: true });
20
+ }
21
+ /** The case `files` entries that go to the workspace, with normalized relative targets. */
22
+ export function workspaceEntries(files) {
23
+ return Object.entries(files ?? {})
24
+ .filter(([destination]) => !isHomeDestination(destination))
25
+ .map(([destination, source]) => ({ destination, target: workspaceTargetPath(destination), source }));
26
+ }
27
+ /** The case `files` entries that go into HOME, with `~/` stripped from their targets. */
28
+ export function homeEntries(files) {
29
+ return Object.entries(files ?? {})
30
+ .filter(([destination]) => isHomeDestination(destination))
31
+ .map(([destination, source]) => ({ destination, target: homePathOf(destination), source }));
32
+ }
33
+ /** A `~/` destination names HOME; anything else names the workspace. */
34
+ export function isHomeDestination(destination) {
35
+ return destination.startsWith("~/");
36
+ }
37
+ /** The HOME-relative path a `~/` destination names; the HOME root itself is the empty path. */
38
+ export function homePathOf(destination) {
39
+ return workspaceTargetPath(destination.slice(2));
40
+ }
41
+ /**
42
+ * Copy placement entries into an empty staging directory: the same traversal and ignore rules
43
+ * as a workspace placement, with each target taken relative to the staging root. Two entries
44
+ * normalized to one path collide there, because staging never overwrites.
45
+ */
46
+ export async function stageEntries(entries, authoringDir, stagingDir, label, signal) {
47
+ await mkdir(stagingDir, { recursive: true });
48
+ const tree = new IgnoreTree();
49
+ for (const entry of entries) {
50
+ signal?.throwIfAborted();
51
+ const path = resolveAuthoringAsset(authoringDir, entry.source, `${label}["${entry.destination}"]`);
52
+ await copyInto(path, resolve(stagingDir, entry.target), entry.destination, `${label} entry "${entry.destination}"`, false, signal, { tree, root: path, segments: [] });
53
+ }
54
+ }
55
+ /**
56
+ * The target-relative paths a placement would write, without copying anything. Used at load
57
+ * time to reject a placement that would land on login state before any run resource exists.
58
+ * The traversal and ignore answers are the staging copy's, so the answer matches what would be
59
+ * placed; a source that cannot be placed is the same error as it would be there.
60
+ */
61
+ export async function placedPaths(entries, authoringDir, label, signal) {
62
+ const targets = [];
63
+ const tree = new IgnoreTree();
64
+ const walk = async (source, target, destination, segments, root) => {
65
+ const classified = await classify(source, destination, label, signal, { tree, root, segments });
66
+ if (classified.kind === "ignored") {
67
+ return;
68
+ }
69
+ if (classified.kind === "other") {
70
+ throw new Error(`${label} source for ${destination} must be a regular file or directory`);
71
+ }
72
+ targets.push(target);
73
+ if (classified.kind === "file") {
74
+ return;
75
+ }
76
+ for (const name of await readdir(source)) {
77
+ await walk(join(source, name), join(target, name), join(destination, name), [...segments, name], root);
78
+ }
79
+ };
80
+ for (const entry of entries) {
81
+ signal?.throwIfAborted();
82
+ const source = resolveAuthoringAsset(authoringDir, entry.source, `${label}["${entry.destination}"]`);
83
+ await walk(source, entry.target, entry.destination, [], source);
84
+ }
85
+ return targets;
86
+ }
87
+ /**
88
+ * Copy a staged placement tree onto its target. `overwrite` decides file-on-file replacement;
89
+ * `protect` names the login state no copy may place over.
90
+ */
91
+ export async function copyPlacement(stagingDir, targetDir, options) {
92
+ 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
+ export { fileIdentity };
95
+ /** Target-relative files a placement may never create or replace. */
96
+ class ProtectedPaths {
97
+ #paths;
98
+ #identities;
99
+ constructor(protection) {
100
+ this.#paths = (protection.paths ?? []).map((path) => normalizeRelative(path));
101
+ this.#identities = new Set(protection.identities ?? []);
102
+ }
103
+ /**
104
+ * A protected file at `destination`, or a path beneath one, which cannot be written. The
105
+ * declared spelling is not enough: the filesystem decides whether the target is the login
106
+ * file, so the existing target's identity is compared too. A case-insensitive or otherwise
107
+ * normalising filesystem reports the login file's identity for another spelling.
108
+ */
109
+ async blocks(target, destination) {
110
+ const normalized = normalizeRelative(destination);
111
+ if (this.#paths.some((path) => path === normalized || normalized.startsWith(`${path}/`))) {
112
+ return true;
113
+ }
114
+ if (this.#identities.size === 0) {
115
+ return false;
116
+ }
117
+ try {
118
+ const info = await lstat(target, { bigint: true });
119
+ return this.#identities.has(fileIdentity(info));
120
+ }
121
+ catch {
122
+ // Nothing exists at the target spelling, so it cannot alias an existing login file.
123
+ return false;
124
+ }
125
+ }
126
+ }
127
+ function normalizeRelative(path) {
128
+ return workspaceTargetPath(path);
129
+ }
130
+ /**
131
+ * Validate a checker's check-time `files`: workspace destinations and authoring sources, with
132
+ * the same rules as `case.files` destinations plus a non-root destination. Throws `ConfigError`
133
+ * so an extension checker that did no schema validation of its own still gets safe paths.
134
+ */
135
+ export function expectCheckFiles(files) {
136
+ for (const [destination, source] of Object.entries(files)) {
137
+ expectWorkspaceDestination(destination, `check files destination "${destination}"`);
138
+ if (workspaceTargetPath(destination) === "") {
139
+ throw new ConfigError(`check files destination "${destination}" must name a file or directory inside the workspace`);
140
+ }
141
+ if (typeof source !== "string") {
142
+ throw new ConfigError(`check files["${destination}"] must be a string`);
143
+ }
144
+ expectRelativePath(source, `check files["${destination}"]`);
145
+ }
146
+ }
147
+ /**
148
+ * Validate a checker's files, then stage them for the check sandbox. The destination is created
149
+ * by the caller and is read-only inside the sandbox.
150
+ */
151
+ export async function stageCheckFiles(files, authoringDir, stagingDir, signal, label = "check files") {
152
+ expectCheckFiles(files);
153
+ await stageFiles(files, authoringDir, stagingDir, label, signal);
154
+ }
155
+ /**
156
+ * Validate and stage a checker's files once at load, then discard the staging tree. A missing or
157
+ * special source, a nested symlink that is not a regular file, or two entries producing one file
158
+ * is a `ConfigError` before any run directory exists.
159
+ */
160
+ export async function validateCheckFiles(files, authoringDir, label = "check files", signal) {
161
+ if (Object.keys(files).length === 0)
162
+ return;
163
+ const staging = await mkdtemp(join(tmpdir(), "agent-evals-check-files-"));
164
+ try {
165
+ await stageCheckFiles(files, authoringDir, staging, signal, label);
166
+ }
167
+ catch (error) {
168
+ if (signal?.aborted)
169
+ throw error;
170
+ throw new ConfigError(`${label}: ${errorMessage(error)}`, { cause: error });
171
+ }
172
+ finally {
173
+ await rm(staging, { recursive: true, force: true, maxRetries: 3 });
174
+ }
175
+ }
176
+ /**
177
+ * Copy authoring `files` entries into an empty staging directory. Every visited source must be a
178
+ * regular file or directory; a symlink is accepted only when its target is a regular file, so a
179
+ * link to a FIFO, device or directory fails cleanly instead of blocking or escaping. Two entries
180
+ * producing the same file are an error, as is a file and a directory at one path.
181
+ */
182
+ export async function stageFiles(files, authoringDir, stagingDir, label, signal) {
183
+ const tree = new IgnoreTree();
184
+ for (const [destination, source] of Object.entries(files)) {
185
+ signal?.throwIfAborted();
186
+ const path = resolveAuthoringAsset(authoringDir, source, `${label}["${destination}"]`);
187
+ await copyInto(path, resolve(stagingDir, destination), destination, `${label} entry "${destination}"`, false, signal, { tree, root: path, segments: [] });
188
+ }
189
+ }
190
+ /**
191
+ * A `cp` filter that applies `.agentevalsignore` to the fixture copy. It shares the ignore
192
+ * decision with the directory copier below, so both place the same paths.
193
+ */
194
+ export function authoringCopyFilter(source) {
195
+ const tree = new IgnoreTree();
196
+ return async (path) => {
197
+ const segments = relative(source, path)
198
+ .split(sep)
199
+ .filter((segment) => segment.length > 0);
200
+ if (segments.length === 0) {
201
+ return true;
202
+ }
203
+ // `cp` filters receive only a path, so the entry type has to be stat'ed. A symlink is a file
204
+ // here, matching how the directory copier treats one.
205
+ const info = await lstat(path);
206
+ return !(await isIgnored(tree, source, segments, info.isDirectory()));
207
+ };
208
+ }
209
+ /**
210
+ * Copy one authoring file or directory tree onto `target`. A file landing where
211
+ * a directory exists, or the reverse, is an error rather than a replacement;
212
+ * `overwrite` decides only file-on-file, which splits fixture replacement from
213
+ * entry-versus-entry overlap. Each directory may declare `.agentevalsignore`,
214
+ * which applies as traversal reaches it, so a directly named source is placed.
215
+ */
216
+ /**
217
+ * Classify one authoring entry against the ignore rules. `ignored` is decided before a special
218
+ * file is rejected, so an excluded special file is silently skipped rather than an error.
219
+ */
220
+ async function classify(source, destination, label, signal, traversal) {
221
+ signal?.throwIfAborted();
222
+ let info;
223
+ try {
224
+ info = await lstat(source);
225
+ }
226
+ catch (error) {
227
+ throw new Error(`${label} source for ${destination} is not accessible: ${errorMessage(error)}`, { cause: error });
228
+ }
229
+ let kind;
230
+ if (info.isSymbolicLink()) {
231
+ // A link is copied as its target's content, and only when that target is a regular file.
232
+ let resolved;
233
+ try {
234
+ resolved = await stat(source);
235
+ }
236
+ catch (error) {
237
+ throw new Error(`${label} source for ${destination} is not accessible: ${errorMessage(error)}`, {
238
+ cause: error,
239
+ });
240
+ }
241
+ kind = resolved.isFile() ? "file" : "other";
242
+ }
243
+ else if (info.isDirectory()) {
244
+ kind = "directory";
245
+ }
246
+ else {
247
+ kind = info.isFile() ? "file" : "other";
248
+ }
249
+ signal?.throwIfAborted();
250
+ // Classifying first is what lets a directory-only pattern match a directory entry.
251
+ if (await isIgnored(traversal.tree, traversal.root, traversal.segments, kind === "directory")) {
252
+ return { kind: "ignored" };
253
+ }
254
+ return { kind };
255
+ }
256
+ async function copyInto(source, target, destination, label, overwrite, signal, traversal, protect) {
257
+ const classified = await classify(source, destination, label, signal, traversal);
258
+ if (classified.kind === "ignored") {
259
+ return;
260
+ }
261
+ const { kind } = classified;
262
+ if (kind === "other") {
263
+ throw new Error(`${label} source for ${destination} must be a regular file or directory`);
264
+ }
265
+ if (protect !== undefined && (await protect.blocks(target, destination))) {
266
+ throw new Error(`${label} may not replace ${destination}, which is login state`);
267
+ }
268
+ await expectTarget(target, destination, label, kind, overwrite);
269
+ signal?.throwIfAborted();
270
+ if (kind === "file") {
271
+ await mkdir(dirname(target), { recursive: true });
272
+ signal?.throwIfAborted();
273
+ await copyFile(source, target);
274
+ signal?.throwIfAborted();
275
+ return;
276
+ }
277
+ await mkdir(target, { recursive: true });
278
+ signal?.throwIfAborted();
279
+ const entries = await readdir(source);
280
+ signal?.throwIfAborted();
281
+ for (const name of entries) {
282
+ await copyInto(join(source, name), join(target, name), join(destination, name), label, overwrite, signal, { ...traversal, segments: [...traversal.segments, name] }, protect);
283
+ }
284
+ }
285
+ /** Reject an existing path that cannot receive `kind`, or a file one entry would overwrite. */
286
+ async function expectTarget(target, destination, label, kind, overwrite) {
287
+ let info;
288
+ try {
289
+ info = await lstat(target);
290
+ }
291
+ catch (error) {
292
+ if (isMissing(error)) {
293
+ return;
294
+ }
295
+ throw error;
296
+ }
297
+ const existing = info.isDirectory() ? "directory" : "file";
298
+ if (existing !== kind) {
299
+ throw new Error(`${label} places a ${kind} at ${destination}, where a ${existing} already exists`);
300
+ }
301
+ if (kind === "file" && !overwrite) {
302
+ throw new Error(`${label} overwrites ${destination}, which another files entry provides`);
303
+ }
304
+ }
@@ -0,0 +1,61 @@
1
+ #!/bin/sh
2
+ self=$0
3
+ bindir=__BINDIR__
4
+ socket=__SOCKET__
5
+ fault=__FAULT__
6
+ encode() {
7
+ printf '%s' "$1" | /usr/bin/base64 | /usr/bin/tr -d '\n'
8
+ printf '\n'
9
+ }
10
+ # Canonicalise our own path so the host can tell which forwarder directory we came from.
11
+ folder=${self%/*}
12
+ [ "$folder" = "$self" ] && folder=.
13
+ self=$(cd "$folder" && pwd -P)/${self##*/}
14
+ reply=$(
15
+ {
16
+ encode "$self"
17
+ for argument in "$@"; do
18
+ encode "$argument"
19
+ done
20
+ } | /usr/bin/nc -U "$socket"
21
+ ) || {
22
+ printf '%s: Service unavailable\n' "${self##*/}" >&2
23
+ printf '%s\n' "${self##*/}" >>"$fault" 2>/dev/null
24
+ exit 126
25
+ }
26
+ IFS=' ' read -r kind code out err <<EOF
27
+ $reply
28
+ EOF
29
+ if [ "$kind" = pass ]; then
30
+ name=${self##*/}
31
+ case $self in
32
+ "$bindir"/*)
33
+ oldifs=$IFS
34
+ IFS=:
35
+ set -f
36
+ for folder in $PATH; do
37
+ candidate=$folder/$name
38
+ [ -f "$candidate" ] || continue
39
+ [ -x "$candidate" ] || continue
40
+ # Skip our own entry even when PATH spells the directory differently.
41
+ if [ "$(cd "$folder" 2>/dev/null && pwd -P)/$name" = "$self" ]; then continue; fi
42
+ set +f
43
+ IFS=$oldifs
44
+ exec "$candidate" "$@"
45
+ done
46
+ set +f
47
+ IFS=$oldifs
48
+ ;;
49
+ *)
50
+ real=${self%/*}/.${name}
51
+ if [ -x "$real" ]; then exec "$real" "$@"; fi
52
+ ;;
53
+ esac
54
+ printf '%s: Operation not permitted\n' "$name" >&2
55
+ exit 126
56
+ fi
57
+ [ "$out" = - ] && out=""
58
+ [ "$err" = - ] && err=""
59
+ if [ -n "$out" ]; then printf '%s' "$out" | /usr/bin/base64 -D; fi
60
+ if [ -n "$err" ]; then printf '%s' "$err" | /usr/bin/base64 -D >&2; fi
61
+ exit "$code"
@@ -0,0 +1,29 @@
1
+ import { type Ignore } from "ignore";
2
+ /** The file a source directory uses to declare what is not placed into a run. */
3
+ export declare const IGNORE_FILE_NAME = ".agentevalsignore";
4
+ /**
5
+ * The ignore files one copy consults, read at most once per directory and kept for that copy so
6
+ * two entries sharing a subtree share the answers.
7
+ */
8
+ export declare class IgnoreTree {
9
+ #private;
10
+ read(dir: string): Promise<Ignore>;
11
+ }
12
+ /** One exclusion: the path, and the ignore file whose rules decided it. */
13
+ export interface IgnoreDecision {
14
+ readonly ignored: boolean;
15
+ /** The `.agentevalsignore` file that decided the exclusion. */
16
+ readonly file?: string;
17
+ }
18
+ /**
19
+ * Decide whether the path `segments`, relative to `root`, is not placed, and which ignore file
20
+ * decided it. Each directory's patterns are matched from that directory, and the answers are
21
+ * combined, so a deeper file cannot re-include what a higher one excluded; the first (highest)
22
+ * decision is the one reported.
23
+ *
24
+ * `directory` supplies the one thing a bare path cannot: a trailing `/` marks the entry as a
25
+ * directory, which is how gitignore spells a directory-only pattern such as `evals/`.
26
+ */
27
+ export declare function ignoreDecision(tree: IgnoreTree, root: string, segments: readonly string[], directory: boolean): Promise<IgnoreDecision>;
28
+ /** True when the path is not placed, as {@link ignoreDecision} decides. */
29
+ export declare function isIgnored(tree: IgnoreTree, root: string, segments: readonly string[], directory: boolean): Promise<boolean>;
@@ -0,0 +1,67 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import ignore, {} from "ignore";
4
+ import { ConfigError, errorMessage } from "./config.js";
5
+ import { isMissing } from "./workspace.js";
6
+ /** The file a source directory uses to declare what is not placed into a run. */
7
+ export const IGNORE_FILE_NAME = ".agentevalsignore";
8
+ /**
9
+ * The ignore files one copy consults, read at most once per directory and kept for that copy so
10
+ * two entries sharing a subtree share the answers.
11
+ */
12
+ export class IgnoreTree {
13
+ #rules = new Map();
14
+ read(dir) {
15
+ let rules = this.#rules.get(dir);
16
+ if (rules === undefined) {
17
+ rules = readRules(dir);
18
+ this.#rules.set(dir, rules);
19
+ }
20
+ return rules;
21
+ }
22
+ }
23
+ /** Parse one directory's ignore file with the gitignore implementation; no file means no rules. */
24
+ async function readRules(dir) {
25
+ const path = join(dir, IGNORE_FILE_NAME);
26
+ let text;
27
+ try {
28
+ text = await readFile(path, "utf8");
29
+ }
30
+ catch (error) {
31
+ if (isMissing(error)) {
32
+ return ignore();
33
+ }
34
+ throw new ConfigError(`could not read ${path}: ${errorMessage(error)}`);
35
+ }
36
+ return ignore().add(text);
37
+ }
38
+ /**
39
+ * Decide whether the path `segments`, relative to `root`, is not placed, and which ignore file
40
+ * decided it. Each directory's patterns are matched from that directory, and the answers are
41
+ * combined, so a deeper file cannot re-include what a higher one excluded; the first (highest)
42
+ * decision is the one reported.
43
+ *
44
+ * `directory` supplies the one thing a bare path cannot: a trailing `/` marks the entry as a
45
+ * directory, which is how gitignore spells a directory-only pattern such as `evals/`.
46
+ */
47
+ export async function ignoreDecision(tree, root, segments, directory) {
48
+ if (segments.length === 0) {
49
+ return { ignored: false };
50
+ }
51
+ if (segments[segments.length - 1] === IGNORE_FILE_NAME) {
52
+ return { ignored: true, file: join(root, ...segments) };
53
+ }
54
+ for (let depth = 0; depth < segments.length; depth += 1) {
55
+ const directoryPath = join(root, ...segments.slice(0, depth));
56
+ const rules = await tree.read(directoryPath);
57
+ const relative = segments.slice(depth).join("/") + (directory ? "/" : "");
58
+ if (rules.ignores(relative)) {
59
+ return { ignored: true, file: join(directoryPath, IGNORE_FILE_NAME) };
60
+ }
61
+ }
62
+ return { ignored: false };
63
+ }
64
+ /** True when the path is not placed, as {@link ignoreDecision} decides. */
65
+ export async function isIgnored(tree, root, segments, directory) {
66
+ return (await ignoreDecision(tree, root, segments, directory)).ignored;
67
+ }
@@ -0,0 +1,8 @@
1
+ import type { TraceEntry } from "./registry.js";
2
+ /**
3
+ * The text the agent produced: every `message` entry of a trace, in run order, concatenated with
4
+ * no separator. `thought` and `tool` entries never contribute, so reasoning and tool output stay
5
+ * out of the artifact. Nothing is truncated; the artifact is the whole recorded text, and a trace
6
+ * with no message text yields the empty string rather than a match target.
7
+ */
8
+ export declare function messageText(trace: readonly TraceEntry[]): string;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The text the agent produced: every `message` entry of a trace, in run order, concatenated with
3
+ * no separator. `thought` and `tool` entries never contribute, so reasoning and tool output stay
4
+ * out of the artifact. Nothing is truncated; the artifact is the whole recorded text, and a trace
5
+ * with no message text yields the empty string rather than a match target.
6
+ */
7
+ export function messageText(trace) {
8
+ return trace.flatMap((entry) => (entry.type === "message" ? [entry.text] : [])).join("");
9
+ }
@@ -0,0 +1,44 @@
1
+ import type { RE2JS } from "re2js";
2
+ import { type MockAction, type MockArgs, type MockRule, type ShellMocks } from "./config.js";
3
+ interface CompiledPattern {
4
+ readonly literal: string | undefined;
5
+ readonly re: RE2JS | undefined;
6
+ }
7
+ type CompiledArgument = {
8
+ readonly key: CompiledPattern;
9
+ readonly kind: "required" | "forbidden";
10
+ } | {
11
+ readonly key: CompiledPattern;
12
+ readonly kind: "value";
13
+ readonly value: CompiledPattern;
14
+ };
15
+ interface CompiledRule {
16
+ /** Absent for the fallback rule. */
17
+ readonly positional: readonly CompiledPattern[] | undefined;
18
+ readonly options: readonly CompiledArgument[] | undefined;
19
+ readonly action: MockAction;
20
+ }
21
+ /** One target's compiled ordered rules. */
22
+ export type CompiledRules = readonly CompiledRule[];
23
+ /** One workspace target: the declared spelling and its compiled rules. */
24
+ export interface CompiledWorkspaceTarget {
25
+ readonly target: string;
26
+ readonly rules: CompiledRules;
27
+ }
28
+ /** Compiled rules split by where the target lives; a bare name and `./name` differ. */
29
+ export interface CompiledShellMocks {
30
+ readonly path: ReadonlyMap<string, CompiledRules>;
31
+ readonly workspace: ReadonlyMap<string, CompiledWorkspaceTarget>;
32
+ }
33
+ /** Compile every pattern once, when the host starts. Invalid patterns already failed at load. */
34
+ export declare function compileShellMocks(shell: ShellMocks): CompiledShellMocks;
35
+ /**
36
+ * Compile one argument specification into a predicate over a call's argv. A checker asks whether a
37
+ * recorded call matches; ordered dispatch and actions belong to the host, not to the check.
38
+ */
39
+ export declare function compileMockArgs(args: MockArgs): (argv: readonly string[]) => boolean;
40
+ /** Compile one target's ordered rules; the same path serves the host and a mock check. */
41
+ export declare function compileRules(rules: readonly MockRule[]): CompiledRules;
42
+ /** First matching rule wins; a rule without conditions is the fallback. */
43
+ export declare function matchCall(rules: CompiledRules, argv: readonly string[]): MockAction | undefined;
44
+ export {};