@lelouchhe/agent-evals 0.1.1 → 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/README.md +5 -1
- package/dist/checkers/file/index.js +181 -13
- package/dist/checkers/judge/index.d.ts +1 -1
- package/dist/checkers/judge/index.js +243 -31
- package/dist/checkers/judge/prompt.d.ts +4 -3
- package/dist/checkers/judge/prompt.js +22 -3
- package/dist/cli.js +132 -31
- package/dist/engine/authoring.js +108 -13
- package/dist/engine/config.d.ts +31 -2
- package/dist/engine/config.js +16 -10
- package/dist/engine/files.d.ts +2 -5
- package/dist/engine/files.js +2 -5
- package/dist/engine/params.d.ts +2 -0
- package/dist/engine/params.js +10 -0
- package/dist/engine/registry.d.ts +9 -0
- package/dist/engine/report.js +43 -8
- package/dist/engine/results.d.ts +7 -0
- package/dist/engine/results.js +9 -6
- package/dist/engine/run.d.ts +4 -1
- package/dist/engine/run.js +168 -24
- package/dist/engine/view.d.ts +1 -1
- package/dist/engine/view.js +120 -8
- package/dist/engine/workspace.d.ts +7 -0
- package/dist/engine/workspace.js +26 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/runners/acp/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,10 +81,14 @@ cp .env.example .env # fill in harness paths and keys (se
|
|
|
81
81
|
npm run eval -- view examples/cases/deploy-runbook/case.yml --case pi-with-skill
|
|
82
82
|
npm run eval -- config examples/agents/pi.yml
|
|
83
83
|
npm run eval -- run examples/cases/deploy-runbook/case.yml --case pi-with-skill
|
|
84
|
+
npm run eval -- run examples/cases/deploy-runbook/case.yml --reps 3 --jobs 3 --retain on-failure --results-dir /tmp/deploy-runbook
|
|
84
85
|
npm run eval -- report --matrix /tmp/deploy-runbook # after a sweep: one row per check
|
|
85
86
|
```
|
|
86
87
|
|
|
87
|
-
|
|
88
|
+
Additional examples showcase other angles of the toolkit:
|
|
89
|
+
|
|
90
|
+
- [`deploy-runbook-native`](https://github.com/LelouchHe/agent-evals/blob/main/examples/cases/deploy-runbook-native/case.yml) runs the same task through the native Pi runner using an installed `pi` CLI and provider key alone, with `judge` inheriting the case's runner.
|
|
91
|
+
- [`notes-home`](https://github.com/LelouchHe/agent-evals/blob/main/examples/cases/notes-home/case.yml) demonstrates `~/` HOME placement, disjoint top-level and case `files` merging, directory-level `changed: false` restraints, and glob `path` checks (`{decisions,changelog}.md`).
|
|
88
92
|
|
|
89
93
|
## Documentation
|
|
90
94
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import { lstat, readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { join, posix } from "node:path";
|
|
1
3
|
import { z } from "zod";
|
|
2
|
-
import { patternListSchema,
|
|
4
|
+
import { patternListSchema, runFilePathSchema } from "../../engine/params.js";
|
|
3
5
|
import { truncate } from "../../engine/truncate.js";
|
|
4
6
|
import { searches } from "../../engine/regex.js";
|
|
5
|
-
import { isMissing, readRunFile, readRunTree, runPathExists, } from "../../engine/workspace.js";
|
|
7
|
+
import { WorkspacePathError, assertRunRoot, isMissing, readRunFile, readRunTree, resolveWorkspacePath, runPathExists, } from "../../engine/workspace.js";
|
|
6
8
|
import { ConfigError, errorMessage } from "../../engine/config.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
});
|
|
9
|
+
const GLOB_META = /[*?[\]{}]/u;
|
|
10
|
+
function isGlob(path) {
|
|
11
|
+
return GLOB_META.test(path);
|
|
12
|
+
}
|
|
13
13
|
const fileCheckParamsSchema = z
|
|
14
14
|
.strictObject({
|
|
15
|
-
path:
|
|
15
|
+
path: runFilePathSchema,
|
|
16
16
|
exists: z.boolean().optional(),
|
|
17
17
|
changed: z.boolean().optional(),
|
|
18
18
|
matches: patternListSchema.optional(),
|
|
@@ -28,6 +28,13 @@ const fileCheckParamsSchema = z
|
|
|
28
28
|
message: "needs at least one of exists, changed, matches, or notMatches",
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
if (isGlob(params.path) && params.changed !== undefined) {
|
|
32
|
+
context.addIssue({
|
|
33
|
+
code: "custom",
|
|
34
|
+
path: ["changed"],
|
|
35
|
+
message: "changed does not support glob patterns; name a specific file or directory",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
31
38
|
})
|
|
32
39
|
.transform((params) => ({
|
|
33
40
|
path: params.path,
|
|
@@ -56,6 +63,13 @@ class FileChecker {
|
|
|
56
63
|
const params = this.#params;
|
|
57
64
|
const target = this.#target(context);
|
|
58
65
|
const results = [];
|
|
66
|
+
const declared = [
|
|
67
|
+
...params.matches.map((pattern) => ({ kind: "matches", pattern })),
|
|
68
|
+
...params.notMatches.map((pattern) => ({ kind: "notMatches", pattern })),
|
|
69
|
+
];
|
|
70
|
+
if (isGlob(params.path)) {
|
|
71
|
+
return this.#checkGlob(target, declared, context.signal);
|
|
72
|
+
}
|
|
59
73
|
if (params.exists !== undefined) {
|
|
60
74
|
const expected = params.exists;
|
|
61
75
|
results.push(await condition(`${params.path} ${expected ? "exists" : "does not exist"}`, async () => {
|
|
@@ -69,15 +83,88 @@ class FileChecker {
|
|
|
69
83
|
if (params.changed !== undefined) {
|
|
70
84
|
results.push(await this.#changed(context, params.changed));
|
|
71
85
|
}
|
|
72
|
-
const declared = [
|
|
73
|
-
...params.matches.map((pattern) => ({ kind: "matches", pattern })),
|
|
74
|
-
...params.notMatches.map((pattern) => ({ kind: "notMatches", pattern })),
|
|
75
|
-
];
|
|
76
86
|
if (declared.length > 0) {
|
|
77
87
|
results.push(...(await this.#patterns(context, declared)));
|
|
78
88
|
}
|
|
79
89
|
return results;
|
|
80
90
|
};
|
|
91
|
+
async #checkGlob(target, declared, signal) {
|
|
92
|
+
const params = this.#params;
|
|
93
|
+
const results = [];
|
|
94
|
+
let matched;
|
|
95
|
+
let globError;
|
|
96
|
+
try {
|
|
97
|
+
matched = await resolveGlobMatches(target.root, target.relative, signal);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
globError = errorMessage(error);
|
|
101
|
+
}
|
|
102
|
+
const prefix = params.path.startsWith("~/") ? "~/" : "";
|
|
103
|
+
if (params.exists !== undefined) {
|
|
104
|
+
const expected = params.exists;
|
|
105
|
+
const subject = `${params.path} ${expected ? "exists" : "does not exist"}`;
|
|
106
|
+
if (globError !== undefined || matched === undefined) {
|
|
107
|
+
results.push(errorResult(subject, globError ?? "glob resolution failed"));
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const found = matched.all.length > 0;
|
|
111
|
+
const reason = found
|
|
112
|
+
? `matched ${matched.all.length} path(s), e.g. ${prefix}${matched.all[0]}`
|
|
113
|
+
: `no paths matched ${params.path}`;
|
|
114
|
+
results.push({ ...(found === expected ? pass : fail)(reason), subject });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (declared.length === 0) {
|
|
118
|
+
return results;
|
|
119
|
+
}
|
|
120
|
+
if (globError !== undefined || matched === undefined) {
|
|
121
|
+
for (const { kind, pattern } of declared) {
|
|
122
|
+
results.push(errorResult(`${params.path} ${kind === "matches" ? "matches" : "does not match"} ${display(pattern)}`, globError ?? "glob resolution failed"));
|
|
123
|
+
}
|
|
124
|
+
return results;
|
|
125
|
+
}
|
|
126
|
+
if (matched.files.length === 0) {
|
|
127
|
+
for (const { kind, pattern } of declared) {
|
|
128
|
+
const subject = `${params.path} ${kind === "matches" ? "matches" : "does not match"} ${display(pattern)}`;
|
|
129
|
+
results.push({ ...fail(`no files matched ${params.path}`), subject });
|
|
130
|
+
}
|
|
131
|
+
return results;
|
|
132
|
+
}
|
|
133
|
+
// Stream matched files one at a time so aggregate memory stays bounded by one file.
|
|
134
|
+
const hits = new Array(declared.length).fill(undefined);
|
|
135
|
+
let readError;
|
|
136
|
+
try {
|
|
137
|
+
for (const rel of matched.files) {
|
|
138
|
+
if (signal.aborted) {
|
|
139
|
+
throw new Error("check cancelled");
|
|
140
|
+
}
|
|
141
|
+
const text = (await readRunFile(target.root, rel)).toString("utf8");
|
|
142
|
+
const displayPath = `${prefix}${rel}`;
|
|
143
|
+
for (const [index, { pattern }] of declared.entries()) {
|
|
144
|
+
if (hits[index] !== undefined)
|
|
145
|
+
continue;
|
|
146
|
+
const found = pattern.regex ? searches(pattern.source, text) : text.includes(pattern.source);
|
|
147
|
+
if (found)
|
|
148
|
+
hits[index] = displayPath;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
readError = errorMessage(error);
|
|
154
|
+
}
|
|
155
|
+
for (const [index, { kind, pattern }] of declared.entries()) {
|
|
156
|
+
const subject = `${params.path} ${kind === "matches" ? "matches" : "does not match"} ${display(pattern)}`;
|
|
157
|
+
if (readError !== undefined) {
|
|
158
|
+
results.push(errorResult(subject, readError));
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const hit = hits[index];
|
|
162
|
+
const found = hit !== undefined;
|
|
163
|
+
const reason = found ? `pattern found in ${hit}` : `pattern not found in ${matched.files.length} matched file(s)`;
|
|
164
|
+
results.push({ ...(found === (kind === "matches") ? pass : fail)(reason), subject });
|
|
165
|
+
}
|
|
166
|
+
return results;
|
|
167
|
+
}
|
|
81
168
|
async #changed(context, expected) {
|
|
82
169
|
const { path } = this.#params;
|
|
83
170
|
const target = this.#target(context);
|
|
@@ -129,6 +216,87 @@ class FileChecker {
|
|
|
129
216
|
: { root: context.workspace, baseline: context.baseline, relative: path };
|
|
130
217
|
}
|
|
131
218
|
}
|
|
219
|
+
async function resolveGlobMatches(root, pattern, signal) {
|
|
220
|
+
await assertRunRoot(root);
|
|
221
|
+
const normalized = pattern.replaceAll("\\", "/").replace(/^(?:\.\/)+/u, "");
|
|
222
|
+
const segments = normalized.split("/");
|
|
223
|
+
const staticSegments = [];
|
|
224
|
+
for (const segment of segments) {
|
|
225
|
+
if (isGlob(segment))
|
|
226
|
+
break;
|
|
227
|
+
staticSegments.push(segment);
|
|
228
|
+
}
|
|
229
|
+
const baseDir = staticSegments.length === 0 ? "." : staticSegments.join("/");
|
|
230
|
+
const startAbs = baseDir === "." ? root.path : await resolveWorkspacePath(root, baseDir);
|
|
231
|
+
let startStats;
|
|
232
|
+
try {
|
|
233
|
+
startStats = await lstat(startAbs);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (isMissing(error))
|
|
237
|
+
return { all: [], files: [] };
|
|
238
|
+
throw new WorkspacePathError(`could not inspect ${baseDir}: ${errorMessage(error)}`);
|
|
239
|
+
}
|
|
240
|
+
if (!startStats.isDirectory()) {
|
|
241
|
+
return { all: [], files: [] };
|
|
242
|
+
}
|
|
243
|
+
const all = [];
|
|
244
|
+
const files = [];
|
|
245
|
+
const visit = async (dirAbs, relPrefix) => {
|
|
246
|
+
if (signal.aborted) {
|
|
247
|
+
throw new Error("check cancelled");
|
|
248
|
+
}
|
|
249
|
+
const names = (await readdir(dirAbs)).sort();
|
|
250
|
+
for (const name of names) {
|
|
251
|
+
if (signal.aborted) {
|
|
252
|
+
throw new Error("check cancelled");
|
|
253
|
+
}
|
|
254
|
+
const childAbs = join(dirAbs, name);
|
|
255
|
+
const relative = relPrefix === "" ? name : `${relPrefix}/${name}`;
|
|
256
|
+
let info;
|
|
257
|
+
try {
|
|
258
|
+
info = await lstat(childAbs);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (isMissing(error))
|
|
262
|
+
continue;
|
|
263
|
+
throw new WorkspacePathError(`could not inspect ${relative}: ${errorMessage(error)}`);
|
|
264
|
+
}
|
|
265
|
+
if (posix.matchesGlob(relative, normalized)) {
|
|
266
|
+
if (info.isFile()) {
|
|
267
|
+
all.push(relative);
|
|
268
|
+
files.push(relative);
|
|
269
|
+
}
|
|
270
|
+
else if (info.isDirectory()) {
|
|
271
|
+
all.push(relative);
|
|
272
|
+
}
|
|
273
|
+
else if (info.isSymbolicLink()) {
|
|
274
|
+
// Validate symlinks with the exact-path rules: escaping/broken links and special targets error.
|
|
275
|
+
const resolved = await resolveWorkspacePath(root, relative);
|
|
276
|
+
const targetInfo = await stat(resolved);
|
|
277
|
+
if (targetInfo.isFile()) {
|
|
278
|
+
all.push(relative);
|
|
279
|
+
files.push(relative);
|
|
280
|
+
}
|
|
281
|
+
else if (targetInfo.isDirectory()) {
|
|
282
|
+
all.push(relative);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
throw new WorkspacePathError(`not a regular file or directory: ${relative}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
throw new WorkspacePathError(`not a regular file or directory: ${relative}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (info.isDirectory()) {
|
|
293
|
+
await visit(childAbs, relative);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
await visit(startAbs, baseDir === "." ? "" : baseDir);
|
|
298
|
+
return { all, files };
|
|
299
|
+
}
|
|
132
300
|
/**
|
|
133
301
|
* Every path that differs, sorted; the root is `""`, so a replaced path is one change.
|
|
134
302
|
* Files are compared one pair at a time, so peak memory follows the check's per-file
|
|
@@ -4,7 +4,7 @@ import type { CheckerDefinition } from "../../engine/registry.js";
|
|
|
4
4
|
declare const judgeParamsSchema: z.ZodObject<{
|
|
5
5
|
runner: z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodTransform<ImplementationRecord, Record<string, unknown>>>>;
|
|
6
6
|
rubric: z.ZodArray<z.ZodString>;
|
|
7
|
-
|
|
7
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
8
8
|
trace: z.ZodOptional<z.ZodLiteral<true>>;
|
|
9
9
|
}, z.core.$strict>;
|
|
10
10
|
type JudgeParams = z.output<typeof judgeParamsSchema>;
|
|
@@ -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,
|
|
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
|
-
/**
|
|
18
|
-
|
|
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.
|
|
23
|
-
message: "needs
|
|
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
|
|
157
|
-
*
|
|
158
|
-
*
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
224
|
+
resolved = await resolveWorkspacePath(root, rawRel);
|
|
167
225
|
}
|
|
168
226
|
catch (error) {
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
/**
|
|
187
|
-
function
|
|
188
|
-
const
|
|
189
|
-
|
|
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
|
-
/**
|
|
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
|
|
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 `${
|
|
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
|
-
? `${
|
|
35
|
-
: `${
|
|
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
|
}
|