@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.
- package/.env.example +27 -0
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/dist/checkers/file/index.d.ts +26 -0
- package/dist/checkers/file/index.js +396 -0
- package/dist/checkers/judge/index.d.ts +20 -0
- package/dist/checkers/judge/index.js +474 -0
- package/dist/checkers/judge/prompt.d.ts +19 -0
- package/dist/checkers/judge/prompt.js +55 -0
- package/dist/checkers/judge/trace.d.ts +6 -0
- package/dist/checkers/judge/trace.js +41 -0
- package/dist/checkers/mock/index.d.ts +18 -0
- package/dist/checkers/mock/index.js +127 -0
- package/dist/checkers/shell/index.d.ts +10 -0
- package/dist/checkers/shell/index.js +61 -0
- package/dist/checkers/trace/index.d.ts +22 -0
- package/dist/checkers/trace/index.js +183 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +453 -0
- package/dist/engine/authoring.d.ts +24 -0
- package/dist/engine/authoring.js +356 -0
- package/dist/engine/check-runner.d.ts +1 -0
- package/dist/engine/check-runner.js +127 -0
- package/dist/engine/check-sandbox.d.ts +18 -0
- package/dist/engine/check-sandbox.js +171 -0
- package/dist/engine/config.d.ts +171 -0
- package/dist/engine/config.js +368 -0
- package/dist/engine/env-source.d.ts +10 -0
- package/dist/engine/env-source.js +114 -0
- package/dist/engine/files.d.ts +84 -0
- package/dist/engine/files.js +304 -0
- package/dist/engine/forwarder.sh +61 -0
- package/dist/engine/ignore.d.ts +29 -0
- package/dist/engine/ignore.js +67 -0
- package/dist/engine/messages.d.ts +8 -0
- package/dist/engine/messages.js +9 -0
- package/dist/engine/mock-match.d.ts +44 -0
- package/dist/engine/mock-match.js +104 -0
- package/dist/engine/mocks.d.ts +35 -0
- package/dist/engine/mocks.js +336 -0
- package/dist/engine/params.d.ts +18 -0
- package/dist/engine/params.js +96 -0
- package/dist/engine/placement.d.ts +26 -0
- package/dist/engine/placement.js +107 -0
- package/dist/engine/regex.d.ts +10 -0
- package/dist/engine/regex.js +16 -0
- package/dist/engine/registry.d.ts +243 -0
- package/dist/engine/registry.js +127 -0
- package/dist/engine/report.d.ts +17 -0
- package/dist/engine/report.js +420 -0
- package/dist/engine/results.d.ts +50 -0
- package/dist/engine/results.js +42 -0
- package/dist/engine/run.d.ts +50 -0
- package/dist/engine/run.js +710 -0
- package/dist/engine/runtime-assets.d.ts +6 -0
- package/dist/engine/runtime-assets.js +11 -0
- package/dist/engine/skills.d.ts +49 -0
- package/dist/engine/skills.js +270 -0
- package/dist/engine/truncate.d.ts +3 -0
- package/dist/engine/truncate.js +7 -0
- package/dist/engine/values.d.ts +18 -0
- package/dist/engine/values.js +75 -0
- package/dist/engine/view.d.ts +10 -0
- package/dist/engine/view.js +150 -0
- package/dist/engine/workspace.d.ts +63 -0
- package/dist/engine/workspace.js +305 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +7 -0
- package/dist/platform/macos/launch.d.ts +13 -0
- package/dist/platform/macos/launch.js +14 -0
- package/dist/platform/macos/policy.d.ts +33 -0
- package/dist/platform/macos/policy.js +131 -0
- package/dist/platform/macos/supervise.d.ts +26 -0
- package/dist/platform/macos/supervise.js +98 -0
- package/dist/platform/macos/supervisor.sh +13 -0
- package/dist/runners/acp/agent.d.ts +17 -0
- package/dist/runners/acp/agent.js +38 -0
- package/dist/runners/acp/commands.d.ts +2 -0
- package/dist/runners/acp/commands.js +112 -0
- package/dist/runners/acp/environment.d.ts +71 -0
- package/dist/runners/acp/environment.js +280 -0
- package/dist/runners/acp/index.d.ts +21 -0
- package/dist/runners/acp/index.js +135 -0
- package/dist/runners/acp/session.d.ts +7 -0
- package/dist/runners/acp/session.js +48 -0
- package/dist/runners/acp/trace.d.ts +23 -0
- package/dist/runners/acp/trace.js +44 -0
- package/dist/runners/acp/usage.d.ts +12 -0
- package/dist/runners/acp/usage.js +56 -0
- package/dist/runners/noop/index.d.ts +12 -0
- package/dist/runners/noop/index.js +22 -0
- package/dist/runners/pi/index.d.ts +21 -0
- package/dist/runners/pi/index.js +116 -0
- package/dist/runners/pi/params.d.ts +10 -0
- package/dist/runners/pi/params.js +3 -0
- package/dist/runners/pi/rpc.d.ts +30 -0
- package/dist/runners/pi/rpc.js +341 -0
- package/dist/runners/pi/safe-process-group.d.ts +7 -0
- package/dist/runners/pi/safe-process-group.js +13 -0
- package/dist/runners/pi/session.d.ts +56 -0
- package/dist/runners/pi/session.js +298 -0
- package/dist/runners/pi/shell-wrapper.sh +46 -0
- package/dist/runners/pi/supervisor.d.ts +1 -0
- package/dist/runners/pi/supervisor.js +101 -0
- 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,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Agent Evals
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/LelouchHe/agent-evals/actions/workflows/ci.yml)
|
|
4
|
+
[](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 -- run examples/cases/deploy-runbook/case.yml --reps 3 --jobs 3 --retain on-failure --results-dir /tmp/deploy-runbook
|
|
85
|
+
npm run eval -- report --matrix /tmp/deploy-runbook # after a sweep: one row per check
|
|
86
|
+
```
|
|
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`).
|
|
92
|
+
|
|
93
|
+
## Documentation
|
|
94
|
+
|
|
95
|
+
| Document | Question it answers |
|
|
96
|
+
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
97
|
+
| [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? |
|
|
98
|
+
| [Writing Cases](https://github.com/LelouchHe/agent-evals/blob/main/docs/cases.md) | How should tasks, fixtures, baselines and assertions be designed? |
|
|
99
|
+
| [Configuration Reference](https://github.com/LelouchHe/agent-evals/blob/main/docs/configuration.md) | How do YAML files, placeholders, runners, checkers and result records work? |
|
|
100
|
+
| [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? |
|
|
101
|
+
| [Extensions](https://github.com/LelouchHe/agent-evals/blob/main/docs/extensions.md) | How do I write and load a custom runner or checker? |
|
|
102
|
+
| [Architecture](https://github.com/LelouchHe/agent-evals/blob/main/docs/architecture.md) | How do the modules cooperate, and what runtime/development limits apply today? |
|
|
103
|
+
| [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? |
|
|
104
|
+
|
|
105
|
+
Delivered milestone records (`M1`–`M5`) are preserved under [`docs/archive/`](https://github.com/LelouchHe/agent-evals/blob/main/docs/archive/).
|
|
106
|
+
|
|
107
|
+
## Development
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
npm run check # ESLint, Prettier, TypeScript, build, and deterministic model-free tests
|
|
111
|
+
npm run test:package # Pack tarball, install into an external prefix, and verify the installed CLI
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
116
|
+
## Releasing
|
|
117
|
+
|
|
118
|
+
[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`.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
[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,396 @@
|
|
|
1
|
+
import { lstat, readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { join, posix } from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { patternListSchema, runFilePathSchema } from "../../engine/params.js";
|
|
5
|
+
import { truncate } from "../../engine/truncate.js";
|
|
6
|
+
import { searches } from "../../engine/regex.js";
|
|
7
|
+
import { WorkspacePathError, assertRunRoot, isMissing, readRunFile, readRunTree, resolveWorkspacePath, runPathExists, } from "../../engine/workspace.js";
|
|
8
|
+
import { ConfigError, errorMessage } from "../../engine/config.js";
|
|
9
|
+
const GLOB_META = /[*?[\]{}]/u;
|
|
10
|
+
function isGlob(path) {
|
|
11
|
+
return GLOB_META.test(path);
|
|
12
|
+
}
|
|
13
|
+
const fileCheckParamsSchema = z
|
|
14
|
+
.strictObject({
|
|
15
|
+
path: runFilePathSchema,
|
|
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
|
+
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
|
+
}
|
|
38
|
+
})
|
|
39
|
+
.transform((params) => ({
|
|
40
|
+
path: params.path,
|
|
41
|
+
...(params.exists === undefined ? {} : { exists: params.exists }),
|
|
42
|
+
...(params.changed === undefined ? {} : { changed: params.changed }),
|
|
43
|
+
matches: params.matches ?? [],
|
|
44
|
+
notMatches: params.notMatches ?? [],
|
|
45
|
+
}));
|
|
46
|
+
/** Declarative workspace file assertions: exists, changed, matches, notMatches. */
|
|
47
|
+
export const fileChecker = {
|
|
48
|
+
type: "file",
|
|
49
|
+
params: fileCheckParamsSchema,
|
|
50
|
+
create(params, context) {
|
|
51
|
+
if (params.path.startsWith("~/") && !context.runnerSupportsHome) {
|
|
52
|
+
throw new ConfigError(`file check path "${params.path}" is in the run HOME, which the selected runner does not provide`);
|
|
53
|
+
}
|
|
54
|
+
return new FileChecker(params);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
class FileChecker {
|
|
58
|
+
#params;
|
|
59
|
+
constructor(params) {
|
|
60
|
+
this.#params = params;
|
|
61
|
+
}
|
|
62
|
+
check = async (context) => {
|
|
63
|
+
const params = this.#params;
|
|
64
|
+
const target = this.#target(context);
|
|
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
|
+
}
|
|
73
|
+
if (params.exists !== undefined) {
|
|
74
|
+
const expected = params.exists;
|
|
75
|
+
results.push(await condition(`${params.path} ${expected ? "exists" : "does not exist"}`, async () => {
|
|
76
|
+
const exists = await runPathExists(target.root, target.relative);
|
|
77
|
+
if (exists === expected) {
|
|
78
|
+
return pass(`${params.path} ${expected ? "exists" : "is absent"}`);
|
|
79
|
+
}
|
|
80
|
+
return fail(`${params.path} ${exists ? "exists" : "does not exist"}`);
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
if (params.changed !== undefined) {
|
|
84
|
+
results.push(await this.#changed(context, params.changed));
|
|
85
|
+
}
|
|
86
|
+
if (declared.length > 0) {
|
|
87
|
+
results.push(...(await this.#patterns(context, declared)));
|
|
88
|
+
}
|
|
89
|
+
return results;
|
|
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
|
+
}
|
|
168
|
+
async #changed(context, expected) {
|
|
169
|
+
const { path } = this.#params;
|
|
170
|
+
const target = this.#target(context);
|
|
171
|
+
return condition(`${path} ${expected ? "changed" : "unchanged"} since run start`, async () => {
|
|
172
|
+
const [current, baseline] = await Promise.all([
|
|
173
|
+
readRunTree(target.root, target.relative),
|
|
174
|
+
readRunTree(target.baseline, target.relative),
|
|
175
|
+
]);
|
|
176
|
+
const changes = await diffTrees({ root: target.baseline, relative: target.relative, entries: baseline }, { root: target.root, relative: target.relative, entries: current });
|
|
177
|
+
const isChanged = changes.length > 0;
|
|
178
|
+
return (isChanged === expected ? pass : fail)(describeChanges(path, baseline, current, changes));
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Read the file once for every declared pattern. A missing file fails both kinds: a restraint
|
|
183
|
+
* check must not pass because the agent wrote nothing at all.
|
|
184
|
+
*/
|
|
185
|
+
async #patterns(context, declared) {
|
|
186
|
+
const { path } = this.#params;
|
|
187
|
+
const target = this.#target(context);
|
|
188
|
+
let text;
|
|
189
|
+
let readError;
|
|
190
|
+
try {
|
|
191
|
+
text = (await readRunFile(target.root, target.relative)).toString("utf8");
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
if (!isMissing(error)) {
|
|
195
|
+
readError = errorMessage(error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return declared.map(({ kind, pattern }) => {
|
|
199
|
+
const subject = `${path} ${kind === "matches" ? "matches" : "does not match"} ${display(pattern)}`;
|
|
200
|
+
if (readError !== undefined) {
|
|
201
|
+
return errorResult(subject, readError);
|
|
202
|
+
}
|
|
203
|
+
if (text === undefined) {
|
|
204
|
+
return { ...fail(`${path} does not exist`), subject };
|
|
205
|
+
}
|
|
206
|
+
const found = pattern.regex ? searches(pattern.source, text) : text.includes(pattern.source);
|
|
207
|
+
const reason = found ? "pattern found" : "pattern not found";
|
|
208
|
+
return { ...(found === (kind === "matches") ? pass : fail)(reason), subject };
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/** Which run root a declared path names, and the path inside it. */
|
|
212
|
+
#target(context) {
|
|
213
|
+
const { path } = this.#params;
|
|
214
|
+
return path.startsWith("~/")
|
|
215
|
+
? { root: context.home, baseline: context.homeBaseline, relative: path.slice(2) }
|
|
216
|
+
: { root: context.workspace, baseline: context.baseline, relative: path };
|
|
217
|
+
}
|
|
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
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Every path that differs, sorted; the root is `""`, so a replaced path is one change.
|
|
302
|
+
* Files are compared one pair at a time, so peak memory follows the check's per-file
|
|
303
|
+
* cap rather than the size of the tree.
|
|
304
|
+
*/
|
|
305
|
+
async function diffTrees(baseline, current) {
|
|
306
|
+
if (baseline.entries === undefined || current.entries === undefined) {
|
|
307
|
+
const present = current.entries === undefined ? baseline : current;
|
|
308
|
+
if (present.entries === undefined) {
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
const kind = current.entries === undefined ? "removed" : "added";
|
|
312
|
+
return [...present.entries.keys()].sort().map((path) => ({ kind, path }));
|
|
313
|
+
}
|
|
314
|
+
const changes = [];
|
|
315
|
+
const paths = [...new Set([...baseline.entries.keys(), ...current.entries.keys()])].sort();
|
|
316
|
+
for (const path of paths) {
|
|
317
|
+
const before = baseline.entries.get(path);
|
|
318
|
+
const after = current.entries.get(path);
|
|
319
|
+
if (before === undefined) {
|
|
320
|
+
changes.push({ kind: "added", path });
|
|
321
|
+
}
|
|
322
|
+
else if (after === undefined) {
|
|
323
|
+
changes.push({ kind: "removed", path });
|
|
324
|
+
}
|
|
325
|
+
else if (before.kind !== after.kind || before.size !== after.size) {
|
|
326
|
+
changes.push({ kind: "modified", path });
|
|
327
|
+
}
|
|
328
|
+
else if (before.kind === "file" && !(await sameContent(baseline, current, path))) {
|
|
329
|
+
changes.push({ kind: "modified", path });
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return changes;
|
|
333
|
+
}
|
|
334
|
+
/** Compare two files with equal size by their bytes, read one pair at a time. */
|
|
335
|
+
async function sameContent(baseline, current, path) {
|
|
336
|
+
const [before, after] = await Promise.all([
|
|
337
|
+
readRunFile(baseline.root, runPath(baseline.relative, path)),
|
|
338
|
+
readRunFile(current.root, runPath(current.relative, path)),
|
|
339
|
+
]);
|
|
340
|
+
return before.equals(after);
|
|
341
|
+
}
|
|
342
|
+
/** The run-relative path of `path` under a compared path: `""` is the compared path itself. */
|
|
343
|
+
function runPath(relative, path) {
|
|
344
|
+
return path === "" ? relative : relative === "" ? path : `${relative}/${path}`;
|
|
345
|
+
}
|
|
346
|
+
/** Why the comparison held, keeping a single file's wording and summarizing a tree. */
|
|
347
|
+
function describeChanges(path, baseline, current, changes) {
|
|
348
|
+
if (changes.length === 0) {
|
|
349
|
+
return current === undefined
|
|
350
|
+
? "the file is absent in both the run and the initial baseline"
|
|
351
|
+
: "content matches the initial baseline";
|
|
352
|
+
}
|
|
353
|
+
const [only] = changes;
|
|
354
|
+
if (changes.length === 1 && only !== undefined && only.path === "") {
|
|
355
|
+
if (only.kind === "added") {
|
|
356
|
+
return `${path} was created during the run`;
|
|
357
|
+
}
|
|
358
|
+
if (only.kind === "removed") {
|
|
359
|
+
return `${path} was removed during the run`;
|
|
360
|
+
}
|
|
361
|
+
const beforeKind = baseline?.get("")?.kind ?? "absent";
|
|
362
|
+
const afterKind = current?.get("")?.kind ?? "absent";
|
|
363
|
+
return beforeKind === "file" && afterKind === "file"
|
|
364
|
+
? "content changed during the run"
|
|
365
|
+
: `${path} changed from a ${beforeKind} to a ${afterKind}`;
|
|
366
|
+
}
|
|
367
|
+
const shown = changes
|
|
368
|
+
.slice(0, 5)
|
|
369
|
+
.map((change) => `${change.kind} ${change.path === "" ? "." : change.path}`)
|
|
370
|
+
.join(", ");
|
|
371
|
+
const rest = changes.length > 5 ? `, and ${changes.length - 5} more` : "";
|
|
372
|
+
const count = `${changes.length} change${changes.length === 1 ? "" : "s"}`;
|
|
373
|
+
return truncate(`${count}: ${shown}${rest}`, 300);
|
|
374
|
+
}
|
|
375
|
+
/** A literal in quotes, or a regex between slashes, so the subject says which pattern was used. */
|
|
376
|
+
function display(pattern) {
|
|
377
|
+
return pattern.regex ? `/${truncate(pattern.source, 120)}/` : `"${truncate(pattern.source, 120)}"`;
|
|
378
|
+
}
|
|
379
|
+
async function condition(subject, body) {
|
|
380
|
+
try {
|
|
381
|
+
const result = await body();
|
|
382
|
+
return { ...result, subject };
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
return errorResult(subject, errorMessage(error));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function pass(reason) {
|
|
389
|
+
return { checker: "file", subject: "", status: "pass", reason };
|
|
390
|
+
}
|
|
391
|
+
function fail(reason) {
|
|
392
|
+
return { checker: "file", subject: "", status: "fail", reason };
|
|
393
|
+
}
|
|
394
|
+
function errorResult(subject, reason) {
|
|
395
|
+
return { checker: "file", subject, status: "error", reason };
|
|
396
|
+
}
|
|
@@ -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
|
+
files: z.ZodOptional<z.ZodArray<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 {};
|