@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
@@ -1,30 +1,30 @@
1
- import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
2
- import { dirname, join, posix } from "node:path";
1
+ import { lstat, mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
2
+ import { dirname, join, posix, relative, sep } from "node:path";
3
3
  import { z } from "zod";
4
- import { errorMessage } from "../../engine/config.js";
5
- import { nonEmptyTrimmedString, runRelativePathSchema } from "../../engine/params.js";
4
+ import { ConfigError, errorMessage } from "../../engine/config.js";
5
+ import { nonEmptyTrimmedString, runFilePathSchema } from "../../engine/params.js";
6
6
  import { truncate } from "../../engine/truncate.js";
7
- import { isMissing, readRunFile } from "../../engine/workspace.js";
7
+ import { assertRunRoot, fileIdentity, isMissing, isProtectedHomePath, readRunFile, resolveWorkspacePath, } from "../../engine/workspace.js";
8
8
  import { buildJudgePrompt } from "./prompt.js";
9
9
  import { renderTrace } from "./trace.js";
10
10
  /** Where the judge's workspace holds the run's rendered trace. */
11
11
  const TRACE_PATH = "trace.md";
12
+ const GLOB_META = /[*?[\]{}]/u;
13
+ function isGlob(path) {
14
+ return GLOB_META.test(path);
15
+ }
12
16
  const judgeParamsSchema = z
13
17
  .strictObject({
14
18
  /** A runner declaration: any runner's own parameters, and the type it names. */
15
19
  runner: z.record(z.string(), z.unknown()).transform(runnerDeclaration).optional(),
16
20
  rubric: z.array(nonEmptyTrimmedString).min(1, "must contain at least one statement"),
17
- /** A workspace file given as evidence. */
18
- file: runRelativePathSchema.optional(),
21
+ /** Workspace or `~/` file, directory, or glob paths given as evidence. */
22
+ files: z.array(runFilePathSchema).min(1, "must contain at least one path").optional(),
19
23
  /** Give the run's trace as evidence; the runner must record one. */
20
24
  trace: z.literal(true).optional(),
21
25
  })
22
- .refine((params) => params.file !== undefined || params.trace !== undefined, {
23
- message: "needs file, trace or both as evidence",
24
- })
25
- .refine((params) => params.file === undefined || params.trace === undefined || !shadowsTrace(params.file), {
26
- message: `file cannot be ${TRACE_PATH}, or under it, when the trace is evidence too`,
27
- path: ["file"],
26
+ .refine((params) => params.files !== undefined || params.trace !== undefined, {
27
+ message: "needs files, trace or both as evidence",
28
28
  });
29
29
  const verdictSchema = z.object({
30
30
  criteria: z.array(z.object({
@@ -47,6 +47,10 @@ export const judgeChecker = {
47
47
  type: "judge",
48
48
  params: judgeParamsSchema,
49
49
  async create(params, context) {
50
+ const homePath = params.files?.find((entry) => entry.startsWith("~/"));
51
+ if (homePath !== undefined && !context.runnerSupportsHome) {
52
+ throw new ConfigError(`judge files path "${homePath}" is in the run HOME, which the selected runner does not provide`);
53
+ }
50
54
  return new JudgeChecker(params, await context.createRunner(params.runner));
51
55
  },
52
56
  };
@@ -153,29 +157,123 @@ async function prepareRun(params, context, judgeDir) {
153
157
  };
154
158
  }
155
159
  /**
156
- * Copy the requested evidence out of the run and into the judge's workspace. The evaluated
157
- * workspace is read once, through the same regular-file evidence access every checker uses, so a
158
- * run can never hand the judge a path it replaced.
160
+ * Copy the requested evidence out of the run and into the judge's workspace under `workspace/` and
161
+ * `home/`, keeping `trace.md` at the root. Files are read through the same regular-file access
162
+ * every checker uses, and runner login state is never exposed to the judge.
159
163
  */
160
164
  async function stageEvidence(params, context, workspaceDir) {
161
165
  const evidence = [];
162
- if (params.file !== undefined) {
163
- const path = params.file;
164
- let content = null;
166
+ const stagedPaths = new Set();
167
+ const absentPaths = new Set();
168
+ const protectedPaths = context.protectedHome?.paths ?? [];
169
+ const protectedIdentities = new Set(context.protectedHome?.identities ?? []);
170
+ const stageRegularFile = async (root, rel, stagedRel, source, declared) => {
171
+ if (context.signal.aborted) {
172
+ throw new JudgeError("judge was cancelled before its runner started");
173
+ }
174
+ const destRel = `${source}/${stagedRel}`;
175
+ if (stagedPaths.has(destRel)) {
176
+ return;
177
+ }
178
+ let content;
179
+ try {
180
+ content = await readRunFile(root, rel);
181
+ }
182
+ catch (error) {
183
+ throw new JudgeError(`could not read judge evidence ${declared}: ${errorMessage(error)}`);
184
+ }
185
+ if (context.signal.aborted) {
186
+ throw new JudgeError("judge was cancelled before its runner started");
187
+ }
188
+ const target = join(workspaceDir, destRel);
189
+ await mkdir(dirname(target), { recursive: true, mode: 0o700 });
190
+ await writeFile(target, content, { mode: 0o600 });
191
+ stagedPaths.add(destRel);
192
+ evidence.push({ path: destRel, kind: "file", present: true, source });
193
+ };
194
+ for (const entry of params.files ?? []) {
195
+ if (context.signal.aborted) {
196
+ throw new JudgeError("judge was cancelled before its runner started");
197
+ }
198
+ const isHome = entry.startsWith("~/");
199
+ const source = isHome ? "home" : "workspace";
200
+ const root = isHome ? context.home : context.workspace;
201
+ const rawRel = isHome ? entry.slice(2) : entry;
202
+ if (isGlob(rawRel)) {
203
+ const matched = await matchGlobFiles(root, rawRel, context.signal, {
204
+ isHome,
205
+ protectedPaths,
206
+ protectedIdentities,
207
+ });
208
+ if (matched.length === 0) {
209
+ evidence.push({ path: entry, kind: "glob", present: false, source });
210
+ }
211
+ else {
212
+ for (const fileRel of matched) {
213
+ await stageRegularFile(root, fileRel, fileRel, source, entry);
214
+ }
215
+ }
216
+ continue;
217
+ }
218
+ const normalized = stagedPath(rawRel);
219
+ if (isHome && isProtectedHomePath(normalized, protectedPaths)) {
220
+ throw new JudgeError(`refusing to stage protected file: ${entry}`);
221
+ }
222
+ let resolved;
165
223
  try {
166
- content = await readRunFile(context.workspace, path);
224
+ resolved = await resolveWorkspacePath(root, rawRel);
167
225
  }
168
226
  catch (error) {
169
- if (!isMissing(error)) {
170
- throw new JudgeError(`could not read judge evidence ${path}: ${errorMessage(error)}`);
227
+ throw new JudgeError(`could not read judge evidence ${entry}: ${errorMessage(error)}`);
228
+ }
229
+ let info;
230
+ try {
231
+ info = await lstat(resolved, { bigint: true });
232
+ }
233
+ catch (error) {
234
+ if (isMissing(error)) {
235
+ const destRel = normalized === "." ? source : `${source}/${normalized}`;
236
+ if (!absentPaths.has(destRel)) {
237
+ absentPaths.add(destRel);
238
+ evidence.push({ path: destRel, kind: "file", present: false, source });
239
+ }
240
+ continue;
171
241
  }
242
+ throw new JudgeError(`could not read judge evidence ${entry}: ${errorMessage(error)}`);
172
243
  }
173
- if (content !== null) {
174
- const target = join(workspaceDir, stagedPath(path));
175
- await mkdir(dirname(target), { recursive: true, mode: 0o700 });
176
- await writeFile(target, content, { mode: 0o600 });
244
+ const resolvedRel = relative(root.path, resolved).split(sep).join("/");
245
+ if (isHome && resolvedRel.length > 0 && isProtectedHomePath(resolvedRel, protectedPaths)) {
246
+ throw new JudgeError(`refusing to stage protected file: ${entry}`);
247
+ }
248
+ if (info.isFile()) {
249
+ if (protectedIdentities.has(fileIdentity(info))) {
250
+ throw new JudgeError(`refusing to stage protected file: ${entry}`);
251
+ }
252
+ await stageRegularFile(root, rawRel, normalized, source, entry);
253
+ }
254
+ else if (info.isDirectory()) {
255
+ const dirFiles = await collectDirectoryFiles(root, resolved, normalized === "." ? "" : normalized, context.signal, {
256
+ isHome,
257
+ protectedPaths,
258
+ protectedIdentities,
259
+ });
260
+ if (dirFiles.length === 0) {
261
+ evidence.push({
262
+ path: normalized === "." ? source : `${source}/${normalized}`,
263
+ kind: "directory",
264
+ present: true,
265
+ source,
266
+ });
267
+ }
268
+ else {
269
+ for (const fileRel of dirFiles) {
270
+ await stageRegularFile(root, fileRel, fileRel, source, entry);
271
+ }
272
+ }
273
+ }
274
+ else {
275
+ throw new JudgeError(`could not read judge evidence ${entry}: not a regular file or directory`);
177
276
  }
178
- evidence.push({ path: stagedPath(path), kind: "file", present: content !== null });
179
277
  }
180
278
  if (params.trace) {
181
279
  await writeFile(join(workspaceDir, TRACE_PATH), `${renderTrace(context.trace)}\n`, { mode: 0o600 });
@@ -183,10 +281,124 @@ async function stageEvidence(params, context, workspaceDir) {
183
281
  }
184
282
  return evidence;
185
283
  }
186
- /** True when a declared evidence path would land on the trace's own destination. */
187
- function shadowsTrace(path) {
188
- const staged = stagedPath(path).toLowerCase();
189
- return staged === TRACE_PATH || staged.startsWith(`${TRACE_PATH}/`);
284
+ /** Collect regular files under a directory in sorted order, skipping symlinks and protected files. */
285
+ async function collectDirectoryFiles(root, dirAbs, relPrefix, signal, filter, shouldDescend = () => true) {
286
+ const files = [];
287
+ const visit = async (currentAbs, prefix) => {
288
+ if (signal.aborted) {
289
+ throw new JudgeError("judge was cancelled before its runner started");
290
+ }
291
+ const names = (await readdir(currentAbs)).sort();
292
+ for (const name of names) {
293
+ if (signal.aborted) {
294
+ throw new JudgeError("judge was cancelled before its runner started");
295
+ }
296
+ const childRel = prefix === "" ? name : `${prefix}/${name}`;
297
+ const childAbs = join(currentAbs, name);
298
+ if (filter.isHome) {
299
+ const canonicalRel = relative(root.path, childAbs).split(sep).join("/");
300
+ if (isProtectedHomePath(childRel, filter.protectedPaths) ||
301
+ isProtectedHomePath(canonicalRel, filter.protectedPaths)) {
302
+ continue;
303
+ }
304
+ }
305
+ let info;
306
+ try {
307
+ info = await lstat(childAbs, { bigint: true });
308
+ }
309
+ catch (error) {
310
+ if (isMissing(error))
311
+ continue;
312
+ throw new JudgeError(`could not inspect judge evidence ${childRel}: ${errorMessage(error)}`);
313
+ }
314
+ if (info.isFile()) {
315
+ if (filter.protectedIdentities.has(fileIdentity(info)))
316
+ continue;
317
+ files.push(childRel);
318
+ }
319
+ else if (info.isDirectory() && shouldDescend(childRel)) {
320
+ await visit(childAbs, childRel);
321
+ }
322
+ // Symlinks and special files are skipped so an agent-created link cannot pull outside files.
323
+ }
324
+ };
325
+ await visit(dirAbs, relPrefix);
326
+ return files;
327
+ }
328
+ /** Resolve regular files matching a glob pattern, skipping symlinks and protected files. */
329
+ async function matchGlobFiles(root, pattern, signal, filter) {
330
+ await assertRunRoot(root);
331
+ const normalized = posix.normalize(pattern).replace(/\/+$/u, "");
332
+ const segments = normalized.split("/");
333
+ const staticSegments = [];
334
+ for (const segment of segments) {
335
+ if (isGlob(segment))
336
+ break;
337
+ staticSegments.push(segment);
338
+ }
339
+ // Walk the static prefix without following symlinks so prefix symlinks are skipped just like
340
+ // symlinks encountered below the wildcard.
341
+ let startAbs = root.path;
342
+ let prefixRel = "";
343
+ for (const segment of staticSegments) {
344
+ if (signal.aborted) {
345
+ throw new JudgeError("judge was cancelled before its runner started");
346
+ }
347
+ prefixRel = prefixRel === "" ? segment : `${prefixRel}/${segment}`;
348
+ if (filter.isHome && isProtectedHomePath(prefixRel, filter.protectedPaths)) {
349
+ return [];
350
+ }
351
+ startAbs = join(startAbs, segment);
352
+ let info;
353
+ try {
354
+ info = await lstat(startAbs, { bigint: true });
355
+ }
356
+ catch (error) {
357
+ if (isMissing(error))
358
+ return [];
359
+ throw new JudgeError(`could not inspect judge evidence ${prefixRel}: ${errorMessage(error)}`);
360
+ }
361
+ if (!info.isDirectory()) {
362
+ return [];
363
+ }
364
+ }
365
+ const pruneDepth = !segments.includes("**") && !hasCrossSegmentBrace(normalized);
366
+ const shouldDescend = (dirRel) => {
367
+ if (!pruneDepth)
368
+ return true;
369
+ const depth = dirRel.split("/").length;
370
+ if (depth >= segments.length)
371
+ return false;
372
+ return posix.matchesGlob(dirRel, segments.slice(0, depth).join("/"));
373
+ };
374
+ const allFiles = await collectDirectoryFiles(root, startAbs, prefixRel, signal, filter, shouldDescend);
375
+ return allFiles.filter((fileRel) => posix.matchesGlob(fileRel, normalized));
376
+ }
377
+ /** True when a brace expression contains a path separator, so single-segment prefix pruning cannot apply. */
378
+ function hasCrossSegmentBrace(pattern) {
379
+ let depth = 0;
380
+ let inClass = false;
381
+ for (let index = 0; index < pattern.length; index += 1) {
382
+ const char = pattern[index];
383
+ if (char === "\\") {
384
+ index += 1;
385
+ continue;
386
+ }
387
+ if (inClass) {
388
+ if (char === "]")
389
+ inClass = false;
390
+ continue;
391
+ }
392
+ if (char === "[")
393
+ inClass = true;
394
+ else if (char === "{")
395
+ depth += 1;
396
+ else if (char === "}" && depth > 0)
397
+ depth -= 1;
398
+ else if (char === "/" && depth > 0)
399
+ return true;
400
+ }
401
+ return false;
190
402
  }
191
403
  /**
192
404
  * The run-relative path as the judge's workspace will hold it: POSIX segments, no `.` segments and
@@ -1,10 +1,11 @@
1
1
  /** One evidence artifact staged into the judge's own workspace. */
2
2
  export interface JudgeEvidence {
3
- /** Run-relative path the artifact is staged at, and the path the prompt names. */
3
+ /** Workspace-relative path in the judge's workspace (or the unmatched glob pattern). */
4
4
  readonly path: string;
5
- /** Whether the run produced it. A requested file the run never wrote is staged as absent. */
5
+ /** Whether the run produced it. A requested file or glob with no match is staged as absent. */
6
6
  readonly present: boolean;
7
- readonly kind: "file" | "trace";
7
+ readonly kind: "file" | "directory" | "glob" | "trace";
8
+ readonly source?: "workspace" | "home";
8
9
  }
9
10
  export interface JudgePromptInput {
10
11
  readonly task: string;
@@ -27,10 +27,29 @@ export function buildJudgePrompt(input) {
27
27
  ].join("\n");
28
28
  }
29
29
  function describe(entry) {
30
+ const displayPath = sanitizePromptPath(entry.path);
30
31
  if (entry.kind === "trace") {
31
- return `${entry.path}: the run's messages, reasoning and tool calls in order. A tool call shows what the agent asked for and what its harness reported, not every effect.`;
32
+ return `${displayPath}: the run's messages, reasoning and tool calls in order. A tool call shows what the agent asked for and what its harness reported, not every effect.`;
33
+ }
34
+ const origin = entry.source === "home" ? "the run's HOME" : "the run's workspace";
35
+ if (entry.kind === "glob") {
36
+ return `${displayPath}: no files matched this pattern in ${origin}.`;
37
+ }
38
+ if (entry.kind === "directory") {
39
+ return `${displayPath}: an empty directory from ${origin} (no regular files).`;
32
40
  }
33
41
  return entry.present
34
- ? `${entry.path}: a file the run left in its workspace.`
35
- : `${entry.path}: the run produced no such file; it does not exist.`;
42
+ ? `${displayPath}: a file from ${origin}.`
43
+ : `${displayPath}: the run produced no such file; it does not exist.`;
44
+ }
45
+ const LINE_BREAK_ESCAPES = {
46
+ "\r": "\\r",
47
+ "\n": "\\n",
48
+ "\u0085": "\\u0085",
49
+ "\u2028": "\\u2028",
50
+ "\u2029": "\\u2029",
51
+ };
52
+ /** Escape line-breaking control characters in agent-controlled paths so filenames stay single-line data. */
53
+ function sanitizePromptPath(path) {
54
+ return path.replace(/[\r\n\u0085\u2028\u2029]/gu, (char) => LINE_BREAK_ESCAPES[char] ?? char);
36
55
  }