@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.
- package/.env.example +27 -0
- package/LICENSE +21 -0
- package/README.md +117 -2
- package/dist/checkers/file/index.d.ts +26 -0
- package/dist/checkers/file/index.js +228 -0
- package/dist/checkers/judge/index.d.ts +20 -0
- package/dist/checkers/judge/index.js +262 -0
- package/dist/checkers/judge/prompt.d.ts +18 -0
- package/dist/checkers/judge/prompt.js +36 -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 +352 -0
- package/dist/engine/authoring.d.ts +24 -0
- package/dist/engine/authoring.js +261 -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 +142 -0
- package/dist/engine/config.js +362 -0
- package/dist/engine/env-source.d.ts +10 -0
- package/dist/engine/env-source.js +114 -0
- package/dist/engine/files.d.ts +87 -0
- package/dist/engine/files.js +307 -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 +16 -0
- package/dist/engine/params.js +86 -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 +234 -0
- package/dist/engine/registry.js +127 -0
- package/dist/engine/report.d.ts +17 -0
- package/dist/engine/report.js +385 -0
- package/dist/engine/results.d.ts +43 -0
- package/dist/engine/results.js +39 -0
- package/dist/engine/run.d.ts +47 -0
- package/dist/engine/run.js +566 -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 +38 -0
- package/dist/engine/workspace.d.ts +56 -0
- package/dist/engine/workspace.js +280 -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 +131 -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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { lstat, readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { dirname, join, relative } from "node:path";
|
|
3
|
+
import { ConfigError, errorMessage, resolveAuthoringAsset, workspaceTargetPath } from "./config.js";
|
|
4
|
+
import { homeEntries, isHomeDestination, workspaceEntries } from "./files.js";
|
|
5
|
+
import { ignoreDecision, IgnoreTree, IGNORE_FILE_NAME } from "./ignore.js";
|
|
6
|
+
import { isMissing } from "./workspace.js";
|
|
7
|
+
/**
|
|
8
|
+
* Describe what the case's `fixture` and `files` entries would place, using the same traversal
|
|
9
|
+
* and ignore rules as the run. Only the case is described: the agent file's HOME content is the
|
|
10
|
+
* runner's, and check-time `files` are not part of the initial environment.
|
|
11
|
+
*/
|
|
12
|
+
export async function describePlacement(loadedCase) {
|
|
13
|
+
const summaries = [];
|
|
14
|
+
const fixture = loadedCase.config.fixture;
|
|
15
|
+
if (fixture !== undefined) {
|
|
16
|
+
summaries.push(await describeEntry(loadedCase, {
|
|
17
|
+
label: `fixture ${fixture}`,
|
|
18
|
+
source: fixture,
|
|
19
|
+
pathPrefix: "",
|
|
20
|
+
sourceDisplay: fixture,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
for (const entry of [...workspaceEntries(loadedCase.config.files), ...homeEntries(loadedCase.config.files)]) {
|
|
24
|
+
const home = isHomeDestination(entry.destination);
|
|
25
|
+
const target = home ? join("~", entry.target) : entry.target;
|
|
26
|
+
summaries.push(await describeEntry(loadedCase, {
|
|
27
|
+
label: `${home ? "home" : "files"} ${JSON.stringify(entry.destination)}`,
|
|
28
|
+
source: entry.source,
|
|
29
|
+
pathPrefix: target,
|
|
30
|
+
sourceDisplay: entry.source,
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
return summaries;
|
|
34
|
+
}
|
|
35
|
+
async function describeEntry(loadedCase, request) {
|
|
36
|
+
const root = resolveAuthoringAsset(loadedCase.dir, request.source, request.label);
|
|
37
|
+
const placed = [];
|
|
38
|
+
const excluded = [];
|
|
39
|
+
await describePath(root, root, [], request, loadedCase.dir, placed, excluded, new IgnoreTree());
|
|
40
|
+
return { label: request.label, placed, excluded };
|
|
41
|
+
}
|
|
42
|
+
async function describePath(source, root, segments, request, caseDir, placed, excluded, tree) {
|
|
43
|
+
let info;
|
|
44
|
+
try {
|
|
45
|
+
info = await lstat(source);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new ConfigError(`${request.label} source ${request.source} is not accessible: ${errorMessage(error)}`);
|
|
49
|
+
}
|
|
50
|
+
let kind;
|
|
51
|
+
if (info.isSymbolicLink()) {
|
|
52
|
+
let target;
|
|
53
|
+
try {
|
|
54
|
+
target = await stat(source);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new ConfigError(`${request.label} source ${request.source} is not accessible: ${errorMessage(error)}`);
|
|
58
|
+
}
|
|
59
|
+
kind = target.isFile() ? "file" : "other";
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
kind = info.isDirectory() ? "directory" : info.isFile() ? "file" : "other";
|
|
63
|
+
}
|
|
64
|
+
if (segments.length > 0) {
|
|
65
|
+
const decision = await ignoreDecision(tree, root, segments, kind === "directory");
|
|
66
|
+
if (decision.ignored) {
|
|
67
|
+
// The declaration file itself is not content and is not reported.
|
|
68
|
+
if (segments[segments.length - 1] !== IGNORE_FILE_NAME) {
|
|
69
|
+
excluded.push({
|
|
70
|
+
path: destinationOf(request, segments),
|
|
71
|
+
directory: kind === "directory",
|
|
72
|
+
ignoreDir: relative(caseDir, dirname(decision.file ?? "")),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (kind === "other") {
|
|
79
|
+
// The copy rejects a special file; the report names it rather than silently dropping it.
|
|
80
|
+
placed.push({ path: destinationOf(request, segments), source: sourceOf(request, segments) });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (kind === "file") {
|
|
84
|
+
placed.push({ path: destinationOf(request, segments), source: sourceOf(request, segments) });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
let names;
|
|
88
|
+
try {
|
|
89
|
+
names = await readdir(source);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (isMissing(error))
|
|
93
|
+
throw new ConfigError(`${request.label} source ${request.source} is not accessible`);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
for (const name of [...names].sort()) {
|
|
97
|
+
await describePath(join(source, name), root, [...segments, name], request, caseDir, placed, excluded, tree);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function destinationOf(request, segments) {
|
|
101
|
+
const relativePath = segments.join("/");
|
|
102
|
+
const prefix = workspaceTargetPath(request.pathPrefix);
|
|
103
|
+
return prefix.length === 0 ? relativePath : relativePath.length === 0 ? prefix : `${prefix}/${relativePath}`;
|
|
104
|
+
}
|
|
105
|
+
function sourceOf(request, segments) {
|
|
106
|
+
return join(request.sourceDisplay, ...segments);
|
|
107
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RE2JS } from "re2js";
|
|
2
|
+
/**
|
|
3
|
+
* Compile one RE2 pattern. RE2 rejects lookaround and backreferences, so every accepted pattern
|
|
4
|
+
* is linear-time and can run in the engine without a worker or a timeout.
|
|
5
|
+
*/
|
|
6
|
+
export declare function compilePattern(source: string): RE2JS;
|
|
7
|
+
/** True when the pattern matches anywhere in the text; the normal search semantics. */
|
|
8
|
+
export declare function searches(source: string, text: string): boolean;
|
|
9
|
+
/** True when the pattern matches the whole text, as an argv token is matched. */
|
|
10
|
+
export declare function matchesWhole(source: string, text: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RE2JS } from "re2js";
|
|
2
|
+
/**
|
|
3
|
+
* Compile one RE2 pattern. RE2 rejects lookaround and backreferences, so every accepted pattern
|
|
4
|
+
* is linear-time and can run in the engine without a worker or a timeout.
|
|
5
|
+
*/
|
|
6
|
+
export function compilePattern(source) {
|
|
7
|
+
return RE2JS.compile(source);
|
|
8
|
+
}
|
|
9
|
+
/** True when the pattern matches anywhere in the text; the normal search semantics. */
|
|
10
|
+
export function searches(source, text) {
|
|
11
|
+
return compilePattern(source).matcher(text).find();
|
|
12
|
+
}
|
|
13
|
+
/** True when the pattern matches the whole text, as an argv token is matched. */
|
|
14
|
+
export function matchesWhole(source, text) {
|
|
15
|
+
return compilePattern(source).matcher(text).matches();
|
|
16
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
import type { ImplementationRecord } from "./config.js";
|
|
3
|
+
import type { ValueSource } from "./values.js";
|
|
4
|
+
import type { RunRoot } from "./workspace.js";
|
|
5
|
+
export interface RunnerContext {
|
|
6
|
+
readonly workspaceDir: string;
|
|
7
|
+
readonly homeDir: string;
|
|
8
|
+
/** Temporary directory named by `TMPDIR`. */
|
|
9
|
+
readonly tmpDir: string;
|
|
10
|
+
/** Engine-private state; unreadable to the agent. */
|
|
11
|
+
readonly engineDir: string;
|
|
12
|
+
/** A runner-owned writable configuration directory; the native Pi runner's own layout. */
|
|
13
|
+
readonly configDir: string;
|
|
14
|
+
readonly runRootDir: string;
|
|
15
|
+
/** The case's initial user message. An engine-owned value, not a runner parameter. */
|
|
16
|
+
readonly input: string;
|
|
17
|
+
readonly timeoutMs: number;
|
|
18
|
+
readonly signal: AbortSignal;
|
|
19
|
+
/** Present when the case declares mocks and the runner wires them into its environment. */
|
|
20
|
+
readonly mocks?: MockWiring;
|
|
21
|
+
}
|
|
22
|
+
/** What a runner needs to place the engine's mocked commands. */
|
|
23
|
+
export interface MockWiring {
|
|
24
|
+
/** Directory of one forwarder per mocked `PATH` command; the runner puts it first on `PATH`. */
|
|
25
|
+
readonly forwarderDir: string;
|
|
26
|
+
/** Unix socket the forwarders use to reach the engine's host service. */
|
|
27
|
+
readonly socketPath: string;
|
|
28
|
+
/** `PATH` targets no rule can pass to the real command; their binaries stay denied. */
|
|
29
|
+
readonly denyTargets: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface RunnerOutcome {
|
|
32
|
+
readonly finalText: string | null;
|
|
33
|
+
/** Small, bounded diagnostics such as a stderr tail or protocol warnings. */
|
|
34
|
+
readonly diagnostics: readonly string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* One step of a run in order of first appearance: joined message or reasoning text, or one tool
|
|
38
|
+
* call in its final state with the harness's own fields.
|
|
39
|
+
*/
|
|
40
|
+
export type TraceEntry = {
|
|
41
|
+
readonly type: "message" | "thought";
|
|
42
|
+
readonly text: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: "tool";
|
|
45
|
+
readonly toolCallId: string;
|
|
46
|
+
readonly [field: string]: unknown;
|
|
47
|
+
};
|
|
48
|
+
/** One call that reached a mocked collaborator: what was asked for and with which arguments. */
|
|
49
|
+
export interface MockRecord {
|
|
50
|
+
readonly target: string;
|
|
51
|
+
readonly arguments: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/** One end-of-run measurement as the harness reported it. Every part is optional and unestimated. */
|
|
54
|
+
export interface RunnerUsage {
|
|
55
|
+
/** The last reported context size: tokens in the context and the context window. */
|
|
56
|
+
readonly context?: {
|
|
57
|
+
readonly used: number;
|
|
58
|
+
readonly size: number;
|
|
59
|
+
};
|
|
60
|
+
/** The last reported cumulative session cost. */
|
|
61
|
+
readonly cost?: {
|
|
62
|
+
readonly amount: number;
|
|
63
|
+
readonly currency: string;
|
|
64
|
+
};
|
|
65
|
+
/** Totals the harness sent with the completed turn. */
|
|
66
|
+
readonly tokens?: RunnerTokens;
|
|
67
|
+
}
|
|
68
|
+
/** Tokens a completed turn consumed, as the harness's unstable usage field reports them. */
|
|
69
|
+
export interface RunnerTokens {
|
|
70
|
+
readonly totalTokens: number;
|
|
71
|
+
readonly inputTokens: number;
|
|
72
|
+
readonly outputTokens: number;
|
|
73
|
+
readonly thoughtTokens?: number;
|
|
74
|
+
readonly cachedReadTokens?: number;
|
|
75
|
+
readonly cachedWriteTokens?: number;
|
|
76
|
+
}
|
|
77
|
+
/** What a check-time program did in the engine's fixed check sandbox. */
|
|
78
|
+
export type CheckSandboxOutcome = {
|
|
79
|
+
readonly kind: "exited";
|
|
80
|
+
readonly exitCode: number;
|
|
81
|
+
readonly output: string;
|
|
82
|
+
} | {
|
|
83
|
+
readonly kind: "signalled";
|
|
84
|
+
readonly signal: string;
|
|
85
|
+
readonly output: string;
|
|
86
|
+
} | {
|
|
87
|
+
readonly kind: "failed";
|
|
88
|
+
readonly reason: string;
|
|
89
|
+
readonly output: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Run one program at check time. The engine supplies the fixed sandbox: open reads, writes only
|
|
93
|
+
* beneath the workspace and a private HOME and temporary directory, and no network.
|
|
94
|
+
*/
|
|
95
|
+
export interface CheckSandbox {
|
|
96
|
+
/**
|
|
97
|
+
* Start `command` in the workspace root; program and arguments are never given to a shell.
|
|
98
|
+
* `files` maps workspace destinations to authoring sources; the engine validates and stages
|
|
99
|
+
* them inside the sandbox, copying them into the workspace immediately before the program.
|
|
100
|
+
*/
|
|
101
|
+
readonly run: (command: readonly string[], options?: {
|
|
102
|
+
readonly files?: Readonly<Record<string, string>>;
|
|
103
|
+
}) => Promise<CheckSandboxOutcome>;
|
|
104
|
+
}
|
|
105
|
+
/** A prepared runner instance; its factory already captured validated parameters. */
|
|
106
|
+
export interface Runner {
|
|
107
|
+
/**
|
|
108
|
+
* Place runner-owned HOME content (agent files, login state) before the case's `~/` entries.
|
|
109
|
+
* Returns the HOME-relative login files the case may not touch. Absent for a runner without
|
|
110
|
+
* a HOME.
|
|
111
|
+
*/
|
|
112
|
+
readonly prepareHome?: (context: RunnerContext) => Promise<readonly string[]>;
|
|
113
|
+
/** HOME-relative login files a case may never place over; independent of `prepareHome`. */
|
|
114
|
+
readonly homeFiles?: readonly string[];
|
|
115
|
+
readonly run: (context: RunnerContext) => Promise<RunnerOutcome>;
|
|
116
|
+
/** Stop the harness and its owned processes. Must be idempotent. */
|
|
117
|
+
readonly stop: () => Promise<void>;
|
|
118
|
+
/** What the run recorded so far, also after a failed run; absent when the runner records no trace. */
|
|
119
|
+
readonly trace?: () => readonly TraceEntry[];
|
|
120
|
+
/** What the harness reported it consumed, also after a failed run; absent when it reports nothing. */
|
|
121
|
+
readonly usage?: () => RunnerUsage | undefined;
|
|
122
|
+
}
|
|
123
|
+
/** A runner instance created from a declaration, named by the type that produced it. */
|
|
124
|
+
export interface PreparedRunner {
|
|
125
|
+
readonly type: string;
|
|
126
|
+
readonly runner: Runner;
|
|
127
|
+
}
|
|
128
|
+
export interface ImplementationContext {
|
|
129
|
+
readonly authoringDir: string;
|
|
130
|
+
/** The run's placeholder sources, for parameters an implementation loads itself. */
|
|
131
|
+
readonly values: ValueSource;
|
|
132
|
+
/** Validate and stage a checker's check-time `files` at load time, relative to `authoringDir`. */
|
|
133
|
+
readonly validateFiles: (files: Readonly<Record<string, string>>) => Promise<void>;
|
|
134
|
+
/** The case's declared `mocks.shell` targets, for a checker that must name one at load time. */
|
|
135
|
+
readonly mockTargets?: readonly string[];
|
|
136
|
+
/** True when the selected runner gives the run a HOME a case may place files in. */
|
|
137
|
+
readonly runnerSupportsHome: boolean;
|
|
138
|
+
/** Fail at load time when the engine's check sandbox cannot run on this host. */
|
|
139
|
+
readonly validateCheckPlatform: () => Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Create a runner instance from a declaration, or from the case's own runner when none is
|
|
142
|
+
* named. The declaration is validated by that runner's schema with this same context, so a
|
|
143
|
+
* checker that must run a prompt (the `judge`) asks the engine instead of holding a private
|
|
144
|
+
* invocation path.
|
|
145
|
+
*/
|
|
146
|
+
readonly createRunner: (record?: ImplementationRecord) => Promise<PreparedRunner>;
|
|
147
|
+
}
|
|
148
|
+
export interface RunnerDefinition<P> {
|
|
149
|
+
readonly type: string;
|
|
150
|
+
/** Declarative Zod parameter schema; the engine validates raw data once. */
|
|
151
|
+
readonly params: ZodType<P>;
|
|
152
|
+
/** True when the runner wires the mocks it receives into `PATH` and its sandbox. */
|
|
153
|
+
readonly mocks?: true;
|
|
154
|
+
/** True when the runner gives the run a HOME that a case may place `~/` files in. */
|
|
155
|
+
readonly home?: true;
|
|
156
|
+
/** Validate operational readiness for parsed params, then create the instance. */
|
|
157
|
+
readonly create: (params: P, context: ImplementationContext) => Runner | Promise<Runner>;
|
|
158
|
+
}
|
|
159
|
+
/** Type-erased definition as stored by the registry. */
|
|
160
|
+
export interface RegisteredRunnerDefinition {
|
|
161
|
+
readonly type: string;
|
|
162
|
+
readonly params: ZodType<unknown>;
|
|
163
|
+
readonly create: (params: unknown, context: ImplementationContext) => Runner | Promise<Runner>;
|
|
164
|
+
/** Declared by the definition when the runner wires mocks. */
|
|
165
|
+
readonly mocks?: boolean;
|
|
166
|
+
/** Declared by the definition when the runner gives the run a HOME. */
|
|
167
|
+
readonly home?: boolean;
|
|
168
|
+
}
|
|
169
|
+
export interface CheckerContext {
|
|
170
|
+
/** Prepared workspace root; its identity is verified for every operation. */
|
|
171
|
+
readonly workspace: RunRoot;
|
|
172
|
+
/** Initial workspace snapshot, outside the evaluated agent's writable area. */
|
|
173
|
+
readonly baseline: RunRoot;
|
|
174
|
+
/** The run HOME; only checks whose runner declares `home` receive meaningful content. */
|
|
175
|
+
readonly home: RunRoot;
|
|
176
|
+
/** What the case placed in HOME, outside the evaluated agent's writable area. */
|
|
177
|
+
readonly homeBaseline: RunRoot;
|
|
178
|
+
readonly runRootDir: string;
|
|
179
|
+
readonly input: string;
|
|
180
|
+
/** The runner's trace, when it records one. */
|
|
181
|
+
readonly trace?: readonly TraceEntry[];
|
|
182
|
+
/** The run's recorded mock calls, when the case declares mocks. */
|
|
183
|
+
readonly mockRecords?: readonly MockRecord[];
|
|
184
|
+
/** The engine's fixed sandbox for running a program at check time. */
|
|
185
|
+
readonly checkSandbox: CheckSandbox;
|
|
186
|
+
readonly timeoutMs: number;
|
|
187
|
+
readonly signal: AbortSignal;
|
|
188
|
+
}
|
|
189
|
+
export type CheckStatus = "pass" | "fail" | "error";
|
|
190
|
+
/** A checker's judgment. An implementation never says which declaration produced it. */
|
|
191
|
+
export interface CheckResult {
|
|
192
|
+
readonly checker: string;
|
|
193
|
+
readonly subject: string;
|
|
194
|
+
readonly status: CheckStatus;
|
|
195
|
+
readonly reason: string;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* A result as the engine records it: the checker's judgment plus the declared check that produced
|
|
199
|
+
* it. The engine owns this stamp; a record written before it existed lacks the field.
|
|
200
|
+
*/
|
|
201
|
+
export interface RecordedCheckResult extends CheckResult {
|
|
202
|
+
readonly declaration?: number;
|
|
203
|
+
}
|
|
204
|
+
/** A prepared checker instance; its factory already captured validated parameters. */
|
|
205
|
+
export interface Checker {
|
|
206
|
+
/** Results, or a promise for them: a checker that answers directly is awaited like any other. */
|
|
207
|
+
readonly check: (context: CheckerContext) => Promise<readonly CheckResult[]> | readonly CheckResult[];
|
|
208
|
+
}
|
|
209
|
+
export interface CheckerDefinition<P> {
|
|
210
|
+
readonly type: string;
|
|
211
|
+
/** Declarative Zod parameter schema; the engine validates raw data once. */
|
|
212
|
+
readonly params: ZodType<P>;
|
|
213
|
+
/** Validate operational readiness for parsed params, then create the instance. */
|
|
214
|
+
readonly create: (params: P, context: ImplementationContext) => Checker | Promise<Checker>;
|
|
215
|
+
}
|
|
216
|
+
/** Type-erased definition as stored by the registry. */
|
|
217
|
+
export interface RegisteredCheckerDefinition {
|
|
218
|
+
readonly type: string;
|
|
219
|
+
readonly params: ZodType<unknown>;
|
|
220
|
+
readonly create: (params: unknown, context: ImplementationContext) => Checker | Promise<Checker>;
|
|
221
|
+
}
|
|
222
|
+
export interface Registry {
|
|
223
|
+
readonly runners: Map<string, RegisteredRunnerDefinition>;
|
|
224
|
+
readonly checkers: Map<string, RegisteredCheckerDefinition>;
|
|
225
|
+
}
|
|
226
|
+
export declare function createRegistry(): Registry;
|
|
227
|
+
export declare function addRunner<P>(registry: Registry, definition: RunnerDefinition<P>, source: string): void;
|
|
228
|
+
export declare function addChecker<P>(registry: Registry, definition: CheckerDefinition<P>, source: string): void;
|
|
229
|
+
export declare function requireRunner(registry: Registry, type: string): RegisteredRunnerDefinition;
|
|
230
|
+
export declare function requireChecker(registry: Registry, type: string): RegisteredCheckerDefinition;
|
|
231
|
+
/** Load one implementation per subdirectory of each explicitly trusted extension root. */
|
|
232
|
+
export declare function loadTrustedImplementations(registry: Registry, options: {
|
|
233
|
+
extensionDirs?: readonly string[];
|
|
234
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { readdir } from "node:fs/promises";
|
|
10
|
+
import { join, resolve } from "node:path";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
import { ConfigError, errorMessage } from "./config.js";
|
|
13
|
+
export function createRegistry() {
|
|
14
|
+
return { runners: new Map(), checkers: new Map() };
|
|
15
|
+
}
|
|
16
|
+
export function addRunner(registry, definition, source) {
|
|
17
|
+
assertDefinition(definition, "runner");
|
|
18
|
+
registerRunner(registry, definition, source);
|
|
19
|
+
}
|
|
20
|
+
export function addChecker(registry, definition, source) {
|
|
21
|
+
assertDefinition(definition, "checker");
|
|
22
|
+
registerChecker(registry, definition, source);
|
|
23
|
+
}
|
|
24
|
+
export function requireRunner(registry, type) {
|
|
25
|
+
const definition = registry.runners.get(type);
|
|
26
|
+
if (definition === undefined) {
|
|
27
|
+
throw new ConfigError(`unknown runner implementation "${type}" (available: ${list(registry.runners.keys())})`);
|
|
28
|
+
}
|
|
29
|
+
return definition;
|
|
30
|
+
}
|
|
31
|
+
export function requireChecker(registry, type) {
|
|
32
|
+
const definition = registry.checkers.get(type);
|
|
33
|
+
if (definition === undefined) {
|
|
34
|
+
throw new ConfigError(`unknown checker implementation "${type}" (available: ${list(registry.checkers.keys())})`);
|
|
35
|
+
}
|
|
36
|
+
return definition;
|
|
37
|
+
}
|
|
38
|
+
const ENTRY_FILES = ["index.ts", "index.js", "index.mjs"];
|
|
39
|
+
/** Load one implementation per subdirectory of each explicitly trusted extension root. */
|
|
40
|
+
export async function loadTrustedImplementations(registry, options) {
|
|
41
|
+
for (const directory of options.extensionDirs ?? []) {
|
|
42
|
+
await loadDirectory(registry, directory);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function loadDirectory(registry, directory) {
|
|
46
|
+
const root = resolve(directory);
|
|
47
|
+
let entries;
|
|
48
|
+
try {
|
|
49
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new ConfigError(`trusted extension directory ${root} is not readable: ${errorMessage(error)}`);
|
|
53
|
+
}
|
|
54
|
+
const names = entries
|
|
55
|
+
.filter((entry) => entry.isDirectory() && entry.name !== "node_modules" && !entry.name.startsWith("."))
|
|
56
|
+
.map((entry) => entry.name)
|
|
57
|
+
.sort();
|
|
58
|
+
for (const name of names) {
|
|
59
|
+
const file = join(root, name, await entryFile(join(root, name)));
|
|
60
|
+
let module;
|
|
61
|
+
try {
|
|
62
|
+
module = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new ConfigError(`failed to load extension ${file}: ${errorMessage(error)}`);
|
|
66
|
+
}
|
|
67
|
+
const runner = module.runner;
|
|
68
|
+
const checker = module.checker;
|
|
69
|
+
if (runner === undefined && checker === undefined) {
|
|
70
|
+
throw new ConfigError(`${file} must export a named "runner" or "checker" implementation`);
|
|
71
|
+
}
|
|
72
|
+
if (runner !== undefined) {
|
|
73
|
+
registerRunner(registry, assertDefinition(runner, "runner"), file);
|
|
74
|
+
}
|
|
75
|
+
if (checker !== undefined) {
|
|
76
|
+
registerChecker(registry, assertDefinition(checker, "checker"), file);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function entryFile(directory) {
|
|
81
|
+
let entries;
|
|
82
|
+
try {
|
|
83
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new ConfigError(`extension ${directory} is not readable: ${errorMessage(error)}`);
|
|
87
|
+
}
|
|
88
|
+
const files = new Set(entries.filter((entry) => entry.isFile()).map((entry) => entry.name));
|
|
89
|
+
const name = ENTRY_FILES.find((entry) => files.has(entry));
|
|
90
|
+
if (name === undefined) {
|
|
91
|
+
throw new ConfigError(`extension ${directory} has no index.ts, index.js, or index.mjs entry point`);
|
|
92
|
+
}
|
|
93
|
+
return name;
|
|
94
|
+
}
|
|
95
|
+
function registerRunner(registry, definition, source) {
|
|
96
|
+
if (registry.runners.has(definition.type)) {
|
|
97
|
+
throw new ConfigError(`duplicate runner implementation type "${definition.type}" from ${source}`);
|
|
98
|
+
}
|
|
99
|
+
registry.runners.set(definition.type, definition);
|
|
100
|
+
}
|
|
101
|
+
function registerChecker(registry, definition, source) {
|
|
102
|
+
if (registry.checkers.has(definition.type)) {
|
|
103
|
+
throw new ConfigError(`duplicate checker implementation type "${definition.type}" from ${source}`);
|
|
104
|
+
}
|
|
105
|
+
registry.checkers.set(definition.type, definition);
|
|
106
|
+
}
|
|
107
|
+
function assertDefinition(definition, kind) {
|
|
108
|
+
if (typeof definition !== "object" || definition === null) {
|
|
109
|
+
throw new ConfigError(`${kind} implementation must be an object`);
|
|
110
|
+
}
|
|
111
|
+
const candidate = definition;
|
|
112
|
+
if (typeof candidate.type !== "string" || candidate.type.length === 0) {
|
|
113
|
+
throw new ConfigError(`${kind} implementation must declare a non-empty string type`);
|
|
114
|
+
}
|
|
115
|
+
const schema = candidate.params;
|
|
116
|
+
if ((typeof schema !== "object" && typeof schema !== "function") ||
|
|
117
|
+
schema === null ||
|
|
118
|
+
typeof schema.safeParseAsync !== "function" ||
|
|
119
|
+
typeof candidate.create !== "function") {
|
|
120
|
+
throw new ConfigError(`${kind} implementation "${candidate.type}" must provide a Zod params schema and create()`);
|
|
121
|
+
}
|
|
122
|
+
return candidate;
|
|
123
|
+
}
|
|
124
|
+
function list(keys) {
|
|
125
|
+
const values = [...keys].sort();
|
|
126
|
+
return values.length === 0 ? "none" : values.join(", ");
|
|
127
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type EvaluationRecord } from "./results.js";
|
|
2
|
+
/**
|
|
3
|
+
* Render run records the way a test runner reports a session: one line per case with its status,
|
|
4
|
+
* time, tokens and cost, the non-passing assertions indented beneath it, and a totals line. A case
|
|
5
|
+
* is a test and its checks are its assertions, so a passing assertion needs no line of its own.
|
|
6
|
+
*
|
|
7
|
+
* Records are grouped by case document and ordered by completion, which is declaration order for a
|
|
8
|
+
* serial sweep: `startedAt` is stamped when an invocation prepares its runs, so it cannot order them.
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatReport(records: readonly EvaluationRecord[]): string;
|
|
11
|
+
/**
|
|
12
|
+
* Render one markdown table per document: a row per declared check, a column per case, and a cell
|
|
13
|
+
* of `passes/judged` over that case's repetitions. A document qualifies only when every case
|
|
14
|
+
* declares the same checks, because a position must mean the same thing in every column; otherwise
|
|
15
|
+
* the requested comparison does not exist and the command says so.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatMatrix(records: readonly EvaluationRecord[]): string;
|