@lelouchhe/agent-evals 0.0.0-stage → 0.1.1

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 +117 -2
  4. package/dist/checkers/file/index.d.ts +26 -0
  5. package/dist/checkers/file/index.js +228 -0
  6. package/dist/checkers/judge/index.d.ts +20 -0
  7. package/dist/checkers/judge/index.js +262 -0
  8. package/dist/checkers/judge/prompt.d.ts +18 -0
  9. package/dist/checkers/judge/prompt.js +36 -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 +352 -0
  20. package/dist/engine/authoring.d.ts +24 -0
  21. package/dist/engine/authoring.js +261 -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 +142 -0
  27. package/dist/engine/config.js +362 -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 +87 -0
  31. package/dist/engine/files.js +307 -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 +16 -0
  42. package/dist/engine/params.js +86 -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 +234 -0
  48. package/dist/engine/registry.js +127 -0
  49. package/dist/engine/report.d.ts +17 -0
  50. package/dist/engine/report.js +385 -0
  51. package/dist/engine/results.d.ts +43 -0
  52. package/dist/engine/results.js +39 -0
  53. package/dist/engine/run.d.ts +47 -0
  54. package/dist/engine/run.js +566 -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 +38 -0
  65. package/dist/engine/workspace.d.ts +56 -0
  66. package/dist/engine/workspace.js +280 -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 +131 -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
package/.env.example ADDED
@@ -0,0 +1,27 @@
1
+ # Copy this file to .env in the directory where you invoke `agent-evals`.
2
+ # Implementation parameters can reference a value from this file, for example:
3
+ # apiKey: ${env:OPENCODE_API_KEY}
4
+ # Only referenced names are read from this file.
5
+
6
+ # Plain value (synthetic example only; do not commit a real key):
7
+ # OPENCODE_API_KEY=replace-with-key
8
+
9
+ # Or an explicit trusted local lookup command, executed from that directory:
10
+ # OPENCODE_API_KEY="!security find-generic-password -w -s opencode-api-key"
11
+
12
+ # ACP runner and preparation helpers: caller-owned software and login directories.
13
+ # `deps` holds software only; the agent file's `files` map supplies the harness
14
+ # settings copied into the run HOME (see docs/setup.md).
15
+ # PI_DEPS=/absolute/path/to/agent-evals-home/pi/deps
16
+ # CLAUDE_DEPS=/absolute/path/to/agent-evals-home/claude/deps
17
+ # CLAUDE_LOGIN=/absolute/path/to/agent-evals-home/claude/login
18
+ # COPILOT_DEPS=/absolute/path/to/agent-evals-home/copilot/deps
19
+ # A Copilot token (fine-grained PAT with "Copilot Requests", or a Copilot CLI OAuth token)
20
+ # stored in the keychain:
21
+ # COPILOT_GITHUB_TOKEN="!security find-generic-password -w -s copilot-github-token"
22
+ # A `claude setup-token` token stored in the keychain:
23
+ # CLAUDE_OAUTH_TOKEN="!security find-generic-password -w -s claude-oauth-token"
24
+
25
+ # Other referenced names can be used, for example:
26
+ # DEEPSEEK_API_KEY=replace-with-key
27
+ # DEEPSEEK_API_KEY="!op read op://private/deepseek/api-key"
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lelouch He
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,118 @@
1
- # Temporary Holding Version
1
+ # Agent Evals
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/LelouchHe/agent-evals/actions/workflows/ci.yml/badge.svg)](https://github.com/LelouchHe/agent-evals/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@lelouchhe/agent-evals)](https://www.npmjs.com/package/@lelouchhe/agent-evals)
5
+
6
+ A toolkit for evaluating AI agent systems on the real CLI and harness layer.
7
+
8
+ Requirements: macOS with `sandbox-exec` and Node.js 24+. The package declares `os: darwin`, so npm refuses to install it on another platform; the CLI is published as `@lelouchhe/agent-evals`, and a run additionally needs an invocation `.env` and prepared harness directories, per [Setup](https://github.com/LelouchHe/agent-evals/blob/main/docs/setup.md). Version 0.1.1 is the first published state — the toolkit, not a finished instrument; [Roadmap](https://github.com/LelouchHe/agent-evals/blob/main/docs/roadmap.md) lists what is still open.
9
+
10
+ > **Status: pre-1.0.** Breaking changes ship in a minor release until 1.0.
11
+
12
+ ## Why Agent Evals
13
+
14
+ - **Evaluate the whole agent system, not a bare model API.** Outcomes depend on the model _plus_ its harness, skills, instructions and tool loop. One generic [ACP runner](https://github.com/LelouchHe/agent-evals/blob/main/docs/configuration.md#acp-runner-type-acp) drives unmodified [Pi](https://github.com/LelouchHe/agent-evals/blob/main/examples/agents/pi.yml), [Claude Code](https://github.com/LelouchHe/agent-evals/blob/main/examples/agents/claude.yml) and [GitHub Copilot CLI](https://github.com/LelouchHe/agent-evals/blob/main/examples/agents/copilot.yml) side by side, so changing a skill, instruction, flag or harness is a controlled experiment.
15
+ - **Host-native OS sandboxing, not Linux containers.** Each run executes on the host under macOS Seatbelt in its own run root with a private `HOME` and workspace ([layout](https://github.com/LelouchHe/agent-evals/blob/main/docs/setup.md#how-isolated-harness-homes-work)). Host toolchains and platform behavior stay real, while operator dotfiles, login keychains, rubrics and check-time acceptance tests stay unreachable to the agent.
16
+ - **Three evidence sources, deterministic first.** Checks read workspace side effects (`file`, sandboxed `shell`), host-recorded calls to [mocked commands](https://github.com/LelouchHe/agent-evals/blob/main/docs/mocks.md) (`mock`) and the run's trace (`trace`), with an LLM `judge` only where qualitative judgment is needed. A `noop` baseline runner catches checks that pass without an agent.
17
+
18
+ ## What a Case Looks Like
19
+
20
+ A case is one YAML file: a task, a prepared environment, and the checks that judge what the run left behind. Abridged from the [worked example](https://github.com/LelouchHe/agent-evals/blob/main/examples/cases/deploy-runbook/case.yml):
21
+
22
+ ```yaml
23
+ input: Our deploy failed. Read deploy.log, confirm the release state with `deployctl status`, then write the cause and the commands to fix it into diagnosis.md.
24
+ fixture: fixture # copied into the workspace
25
+ mocks:
26
+ shell:
27
+ deployctl: # answered and recorded on the host, never run
28
+ return:
29
+ stdout: "state: failed at publish\n"
30
+ make: # the fix must not be run: refused and recorded
31
+ pass: false
32
+ checks:
33
+ - $type: file
34
+ path: diagnosis.md
35
+ matches: "make rotate-signing-cert"
36
+ - $type: mock
37
+ shell: [make]
38
+ times: 0
39
+ - $type: trace # did the agent consult the skill?
40
+ event: skill
41
+ name: deploy-runbook
42
+ cases:
43
+ pi-with-skill:
44
+ runner:
45
+ $type: acp
46
+ agent: ../../agents/pi.yml
47
+ files:
48
+ .agents/skills/deploy-runbook: skill # the variable under test
49
+ pi-without-skill:
50
+ runner:
51
+ $type: acp
52
+ agent: ../../agents/pi.yml
53
+ baseline:
54
+ runner:
55
+ $type: noop
56
+ expect: fail # a vacuity arm: its failures are the expected outcome
57
+ ```
58
+
59
+ Checker and runner [extensions](https://github.com/LelouchHe/agent-evals-extensions) live in their own repository and load with `--extension-dir` ([contract](https://github.com/LelouchHe/agent-evals/blob/main/docs/extensions.md)).
60
+
61
+ The package entry is also importable: it exports the runner and checker contracts, the evidence access a checker uses, and the trace derivations. It is ESM-only, and TypeScript consumers need `@types/node`.
62
+
63
+ ```ts
64
+ import { messageText, readRunFile, type CheckerContext } from "@lelouchhe/agent-evals";
65
+ ```
66
+
67
+ ## Quick Start
68
+
69
+ ```sh
70
+ npm install -g @lelouchhe/agent-evals # or: npx @lelouchhe/agent-evals
71
+ agent-evals --help
72
+ ```
73
+
74
+ Running a case is macOS-only and needs an invocation `.env` plus a prepared harness directory ([Setup](https://github.com/LelouchHe/agent-evals/blob/main/docs/setup.md)). The worked example below runs from a checkout, because its fixtures and agent files live in the repository.
75
+
76
+ Follow [Setup](https://github.com/LelouchHe/agent-evals/blob/main/docs/setup.md) once to configure `.env` and prepare the harness directories you want to run, then inspect and run the worked example ([`examples/cases/deploy-runbook`](https://github.com/LelouchHe/agent-evals/blob/main/examples/cases/deploy-runbook/case.yml) — seven named cases across Pi, Claude Code, Copilot CLI and `noop`, exercising project skills, every `mocks.shell` action, hidden check-time `shell` acceptance scripts and all five checkers):
77
+
78
+ ```sh
79
+ npm ci
80
+ cp .env.example .env # fill in harness paths and keys (see docs/setup.md)
81
+ npm run eval -- view examples/cases/deploy-runbook/case.yml --case pi-with-skill
82
+ npm run eval -- config examples/agents/pi.yml
83
+ npm run eval -- run examples/cases/deploy-runbook/case.yml --case pi-with-skill
84
+ npm run eval -- report --matrix /tmp/deploy-runbook # after a sweep: one row per check
85
+ ```
86
+
87
+ [`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.
88
+
89
+ ## Documentation
90
+
91
+ | Document | Question it answers |
92
+ | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
93
+ | [Setup](https://github.com/LelouchHe/agent-evals/blob/main/docs/setup.md) | How do I install the CLI, configure `.env`, and prepare Pi, Claude Code and Copilot? |
94
+ | [Writing Cases](https://github.com/LelouchHe/agent-evals/blob/main/docs/cases.md) | How should tasks, fixtures, baselines and assertions be designed? |
95
+ | [Configuration Reference](https://github.com/LelouchHe/agent-evals/blob/main/docs/configuration.md) | How do YAML files, placeholders, runners, checkers and result records work? |
96
+ | [Mocks](https://github.com/LelouchHe/agent-evals/blob/main/docs/mocks.md) | How do I substitute or spy on shell commands, and what does `mocks.json` contain? |
97
+ | [Extensions](https://github.com/LelouchHe/agent-evals/blob/main/docs/extensions.md) | How do I write and load a custom runner or checker? |
98
+ | [Architecture](https://github.com/LelouchHe/agent-evals/blob/main/docs/architecture.md) | How do the modules cooperate, and what runtime/development limits apply today? |
99
+ | [Roadmap](https://github.com/LelouchHe/agent-evals/blob/main/docs/roadmap.md) | What is planned next (M6 sandbox config, M7 MCP mocks), and where are past archives? |
100
+
101
+ Delivered milestone records (`M1`–`M5`) are preserved under [`docs/archive/`](https://github.com/LelouchHe/agent-evals/blob/main/docs/archive/).
102
+
103
+ ## Development
104
+
105
+ ```sh
106
+ npm run check # ESLint, Prettier, TypeScript, build, and deterministic model-free tests
107
+ npm run test:package # Pack tarball, install into an external prefix, and verify the installed CLI
108
+ ```
109
+
110
+ Serialize checkout build/test/eval commands because `npm run build` replaces `dist/` non-atomically; see [Architecture](https://github.com/LelouchHe/agent-evals/blob/main/docs/architecture.md#known-limitations) for runtime and development constraints.
111
+
112
+ ## Releasing
113
+
114
+ [CI](https://github.com/LelouchHe/agent-evals/blob/main/.github/workflows/ci.yml) runs the gate on macOS for every pull request and push to `main`. A release is a tag: push `vX.Y.Z` matching `package.json`'s version, and [publish](https://github.com/LelouchHe/agent-evals/blob/main/.github/workflows/publish.yml) re-runs that gate on macOS, publishes `@lelouchhe/agent-evals` to npm with provenance, and creates the GitHub release. The workflow needs the `NPM_TOKEN` repository secret: an npm token with publish rights for the `@lelouchhe` scope. A scoped package defaults to restricted, so the publish command passes `--access public`.
115
+
116
+ ## License
117
+
118
+ [MIT](https://github.com/LelouchHe/agent-evals/blob/main/LICENSE)
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+ import type { CheckerDefinition } from "../../engine/registry.js";
3
+ import { type PatternSyntax } from "../../engine/config.js";
4
+ declare const fileCheckParamsSchema: z.ZodPipe<z.ZodObject<{
5
+ path: z.ZodString;
6
+ exists: z.ZodOptional<z.ZodBoolean>;
7
+ changed: z.ZodOptional<z.ZodBoolean>;
8
+ matches: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<readonly PatternSyntax[], unknown>>>;
9
+ notMatches: z.ZodOptional<z.ZodPipe<z.ZodUnknown, z.ZodTransform<readonly PatternSyntax[], unknown>>>;
10
+ }, z.core.$strict>, z.ZodTransform<{
11
+ matches: readonly PatternSyntax[];
12
+ notMatches: readonly PatternSyntax[];
13
+ changed?: boolean | undefined;
14
+ exists?: boolean | undefined;
15
+ path: string;
16
+ }, {
17
+ path: string;
18
+ exists?: boolean | undefined;
19
+ changed?: boolean | undefined;
20
+ matches?: readonly PatternSyntax[] | undefined;
21
+ notMatches?: readonly PatternSyntax[] | undefined;
22
+ }>>;
23
+ type FileCheckParams = z.output<typeof fileCheckParamsSchema>;
24
+ /** Declarative workspace file assertions: exists, changed, matches, notMatches. */
25
+ export declare const fileChecker: CheckerDefinition<FileCheckParams>;
26
+ export {};
@@ -0,0 +1,228 @@
1
+ import { z } from "zod";
2
+ import { patternListSchema, runRelativePathSchema } from "../../engine/params.js";
3
+ import { truncate } from "../../engine/truncate.js";
4
+ import { searches } from "../../engine/regex.js";
5
+ import { isMissing, readRunFile, readRunTree, runPathExists, } from "../../engine/workspace.js";
6
+ import { ConfigError, errorMessage } from "../../engine/config.js";
7
+ /** A workspace path, or `~/…` for a file in the run HOME. `~/` alone names HOME, not a file. */
8
+ const filePathSchema = runRelativePathSchema.superRefine((value, context) => {
9
+ if (value === "~/" || value === "~/.") {
10
+ context.addIssue({ code: "custom", message: "must name a file or directory inside HOME, not HOME itself" });
11
+ }
12
+ });
13
+ const fileCheckParamsSchema = z
14
+ .strictObject({
15
+ path: filePathSchema,
16
+ exists: z.boolean().optional(),
17
+ changed: z.boolean().optional(),
18
+ matches: patternListSchema.optional(),
19
+ notMatches: patternListSchema.optional(),
20
+ })
21
+ .superRefine((params, context) => {
22
+ if (params.exists === undefined &&
23
+ params.changed === undefined &&
24
+ params.matches === undefined &&
25
+ params.notMatches === undefined) {
26
+ context.addIssue({
27
+ code: "custom",
28
+ message: "needs at least one of exists, changed, matches, or notMatches",
29
+ });
30
+ }
31
+ })
32
+ .transform((params) => ({
33
+ path: params.path,
34
+ ...(params.exists === undefined ? {} : { exists: params.exists }),
35
+ ...(params.changed === undefined ? {} : { changed: params.changed }),
36
+ matches: params.matches ?? [],
37
+ notMatches: params.notMatches ?? [],
38
+ }));
39
+ /** Declarative workspace file assertions: exists, changed, matches, notMatches. */
40
+ export const fileChecker = {
41
+ type: "file",
42
+ params: fileCheckParamsSchema,
43
+ create(params, context) {
44
+ if (params.path.startsWith("~/") && !context.runnerSupportsHome) {
45
+ throw new ConfigError(`file check path "${params.path}" is in the run HOME, which the selected runner does not provide`);
46
+ }
47
+ return new FileChecker(params);
48
+ },
49
+ };
50
+ class FileChecker {
51
+ #params;
52
+ constructor(params) {
53
+ this.#params = params;
54
+ }
55
+ check = async (context) => {
56
+ const params = this.#params;
57
+ const target = this.#target(context);
58
+ const results = [];
59
+ if (params.exists !== undefined) {
60
+ const expected = params.exists;
61
+ results.push(await condition(`${params.path} ${expected ? "exists" : "does not exist"}`, async () => {
62
+ const exists = await runPathExists(target.root, target.relative);
63
+ if (exists === expected) {
64
+ return pass(`${params.path} ${expected ? "exists" : "is absent"}`);
65
+ }
66
+ return fail(`${params.path} ${exists ? "exists" : "does not exist"}`);
67
+ }));
68
+ }
69
+ if (params.changed !== undefined) {
70
+ results.push(await this.#changed(context, params.changed));
71
+ }
72
+ const declared = [
73
+ ...params.matches.map((pattern) => ({ kind: "matches", pattern })),
74
+ ...params.notMatches.map((pattern) => ({ kind: "notMatches", pattern })),
75
+ ];
76
+ if (declared.length > 0) {
77
+ results.push(...(await this.#patterns(context, declared)));
78
+ }
79
+ return results;
80
+ };
81
+ async #changed(context, expected) {
82
+ const { path } = this.#params;
83
+ const target = this.#target(context);
84
+ return condition(`${path} ${expected ? "changed" : "unchanged"} since run start`, async () => {
85
+ const [current, baseline] = await Promise.all([
86
+ readRunTree(target.root, target.relative),
87
+ readRunTree(target.baseline, target.relative),
88
+ ]);
89
+ const changes = await diffTrees({ root: target.baseline, relative: target.relative, entries: baseline }, { root: target.root, relative: target.relative, entries: current });
90
+ const isChanged = changes.length > 0;
91
+ return (isChanged === expected ? pass : fail)(describeChanges(path, baseline, current, changes));
92
+ });
93
+ }
94
+ /**
95
+ * Read the file once for every declared pattern. A missing file fails both kinds: a restraint
96
+ * check must not pass because the agent wrote nothing at all.
97
+ */
98
+ async #patterns(context, declared) {
99
+ const { path } = this.#params;
100
+ const target = this.#target(context);
101
+ let text;
102
+ let readError;
103
+ try {
104
+ text = (await readRunFile(target.root, target.relative)).toString("utf8");
105
+ }
106
+ catch (error) {
107
+ if (!isMissing(error)) {
108
+ readError = errorMessage(error);
109
+ }
110
+ }
111
+ return declared.map(({ kind, pattern }) => {
112
+ const subject = `${path} ${kind === "matches" ? "matches" : "does not match"} ${display(pattern)}`;
113
+ if (readError !== undefined) {
114
+ return errorResult(subject, readError);
115
+ }
116
+ if (text === undefined) {
117
+ return { ...fail(`${path} does not exist`), subject };
118
+ }
119
+ const found = pattern.regex ? searches(pattern.source, text) : text.includes(pattern.source);
120
+ const reason = found ? "pattern found" : "pattern not found";
121
+ return { ...(found === (kind === "matches") ? pass : fail)(reason), subject };
122
+ });
123
+ }
124
+ /** Which run root a declared path names, and the path inside it. */
125
+ #target(context) {
126
+ const { path } = this.#params;
127
+ return path.startsWith("~/")
128
+ ? { root: context.home, baseline: context.homeBaseline, relative: path.slice(2) }
129
+ : { root: context.workspace, baseline: context.baseline, relative: path };
130
+ }
131
+ }
132
+ /**
133
+ * Every path that differs, sorted; the root is `""`, so a replaced path is one change.
134
+ * Files are compared one pair at a time, so peak memory follows the check's per-file
135
+ * cap rather than the size of the tree.
136
+ */
137
+ async function diffTrees(baseline, current) {
138
+ if (baseline.entries === undefined || current.entries === undefined) {
139
+ const present = current.entries === undefined ? baseline : current;
140
+ if (present.entries === undefined) {
141
+ return [];
142
+ }
143
+ const kind = current.entries === undefined ? "removed" : "added";
144
+ return [...present.entries.keys()].sort().map((path) => ({ kind, path }));
145
+ }
146
+ const changes = [];
147
+ const paths = [...new Set([...baseline.entries.keys(), ...current.entries.keys()])].sort();
148
+ for (const path of paths) {
149
+ const before = baseline.entries.get(path);
150
+ const after = current.entries.get(path);
151
+ if (before === undefined) {
152
+ changes.push({ kind: "added", path });
153
+ }
154
+ else if (after === undefined) {
155
+ changes.push({ kind: "removed", path });
156
+ }
157
+ else if (before.kind !== after.kind || before.size !== after.size) {
158
+ changes.push({ kind: "modified", path });
159
+ }
160
+ else if (before.kind === "file" && !(await sameContent(baseline, current, path))) {
161
+ changes.push({ kind: "modified", path });
162
+ }
163
+ }
164
+ return changes;
165
+ }
166
+ /** Compare two files with equal size by their bytes, read one pair at a time. */
167
+ async function sameContent(baseline, current, path) {
168
+ const [before, after] = await Promise.all([
169
+ readRunFile(baseline.root, runPath(baseline.relative, path)),
170
+ readRunFile(current.root, runPath(current.relative, path)),
171
+ ]);
172
+ return before.equals(after);
173
+ }
174
+ /** The run-relative path of `path` under a compared path: `""` is the compared path itself. */
175
+ function runPath(relative, path) {
176
+ return path === "" ? relative : relative === "" ? path : `${relative}/${path}`;
177
+ }
178
+ /** Why the comparison held, keeping a single file's wording and summarizing a tree. */
179
+ function describeChanges(path, baseline, current, changes) {
180
+ if (changes.length === 0) {
181
+ return current === undefined
182
+ ? "the file is absent in both the run and the initial baseline"
183
+ : "content matches the initial baseline";
184
+ }
185
+ const [only] = changes;
186
+ if (changes.length === 1 && only !== undefined && only.path === "") {
187
+ if (only.kind === "added") {
188
+ return `${path} was created during the run`;
189
+ }
190
+ if (only.kind === "removed") {
191
+ return `${path} was removed during the run`;
192
+ }
193
+ const beforeKind = baseline?.get("")?.kind ?? "absent";
194
+ const afterKind = current?.get("")?.kind ?? "absent";
195
+ return beforeKind === "file" && afterKind === "file"
196
+ ? "content changed during the run"
197
+ : `${path} changed from a ${beforeKind} to a ${afterKind}`;
198
+ }
199
+ const shown = changes
200
+ .slice(0, 5)
201
+ .map((change) => `${change.kind} ${change.path === "" ? "." : change.path}`)
202
+ .join(", ");
203
+ const rest = changes.length > 5 ? `, and ${changes.length - 5} more` : "";
204
+ const count = `${changes.length} change${changes.length === 1 ? "" : "s"}`;
205
+ return truncate(`${count}: ${shown}${rest}`, 300);
206
+ }
207
+ /** A literal in quotes, or a regex between slashes, so the subject says which pattern was used. */
208
+ function display(pattern) {
209
+ return pattern.regex ? `/${truncate(pattern.source, 120)}/` : `"${truncate(pattern.source, 120)}"`;
210
+ }
211
+ async function condition(subject, body) {
212
+ try {
213
+ const result = await body();
214
+ return { ...result, subject };
215
+ }
216
+ catch (error) {
217
+ return errorResult(subject, errorMessage(error));
218
+ }
219
+ }
220
+ function pass(reason) {
221
+ return { checker: "file", subject: "", status: "pass", reason };
222
+ }
223
+ function fail(reason) {
224
+ return { checker: "file", subject: "", status: "fail", reason };
225
+ }
226
+ function errorResult(subject, reason) {
227
+ return { checker: "file", subject, status: "error", reason };
228
+ }
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ import { type ImplementationRecord } from "../../engine/config.js";
3
+ import type { CheckerDefinition } from "../../engine/registry.js";
4
+ declare const judgeParamsSchema: z.ZodObject<{
5
+ runner: z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodTransform<ImplementationRecord, Record<string, unknown>>>>;
6
+ rubric: z.ZodArray<z.ZodString>;
7
+ file: z.ZodOptional<z.ZodString>;
8
+ trace: z.ZodOptional<z.ZodLiteral<true>>;
9
+ }, z.core.$strict>;
10
+ type JudgeParams = z.output<typeof judgeParamsSchema>;
11
+ export declare class JudgeError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ /**
15
+ * Model judgment of the task against file or trace evidence: the checker stages that evidence in
16
+ * its own workspace and runs the declared runner there. Everything about how the model is
17
+ * reached — harness, model, credentials, tools, sandbox — belongs to that runner.
18
+ */
19
+ export declare const judgeChecker: CheckerDefinition<JudgeParams>;
20
+ export {};