pi-evals 0.7.0 → 0.8.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/CHANGELOG.md +11 -0
- package/README.md +20 -0
- package/dist/cli.js +5 -1
- package/dist/exp/cli.js +97 -0
- package/dist/exp/fixture.js +73 -0
- package/dist/exp/grade.js +156 -0
- package/dist/exp/labels.js +172 -0
- package/dist/exp/run.js +154 -0
- package/dist/exp/show.js +54 -0
- package/dist/exp/stats.js +63 -0
- package/dist/exp/summary.js +125 -0
- package/dist/exp/task.js +57 -0
- package/dist/exp/trial.js +191 -0
- package/dist/exp/validity.js +81 -0
- package/dist/labels.js +2 -1
- package/package.json +1 -1
- package/src/cli.ts +4 -1
- package/src/exp/cli.ts +97 -0
- package/src/exp/fixture.ts +74 -0
- package/src/exp/grade.ts +185 -0
- package/src/exp/labels.ts +178 -0
- package/src/exp/run.ts +178 -0
- package/src/exp/show.ts +57 -0
- package/src/exp/stats.ts +77 -0
- package/src/exp/summary.ts +149 -0
- package/src/exp/task.ts +100 -0
- package/src/exp/trial.ts +239 -0
- package/src/exp/validity.ts +76 -0
- package/src/labels.ts +4 -2
package/src/exp/trial.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One trial: clone the fixture into a fresh work dir outside the run dir, run pi headless with the arm's flags and a
|
|
3
|
+
* private agent dir and session dir, then (only after the agent ended) copy the hidden check in and run it, keep the
|
|
4
|
+
* diff, grade, and delete the work dir.
|
|
5
|
+
*/
|
|
6
|
+
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
7
|
+
import { cpSync, createWriteStream, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { homedir, tmpdir } from "node:os";
|
|
9
|
+
import { basename, join } from "node:path";
|
|
10
|
+
import { stateDir } from "../paths.ts";
|
|
11
|
+
import { cloneTree, git } from "./fixture.ts";
|
|
12
|
+
import { type Efficiency, efficiency, gradeTranscript, readSession, shouldNotOutcome } from "./grade.ts";
|
|
13
|
+
import type { Suite, Task } from "./task.ts";
|
|
14
|
+
|
|
15
|
+
export interface TrialOutcomeRaw {
|
|
16
|
+
exit: number | null;
|
|
17
|
+
signal: string | null;
|
|
18
|
+
timedOut: boolean;
|
|
19
|
+
wallMs: number;
|
|
20
|
+
startedAt: string;
|
|
21
|
+
endedAt: string;
|
|
22
|
+
dirty: boolean;
|
|
23
|
+
checkExit?: number | null;
|
|
24
|
+
checkMs?: number;
|
|
25
|
+
/** The provider refused for quota or rate limit: the run should stop. */
|
|
26
|
+
quota: boolean;
|
|
27
|
+
/** The suite's follow-up turn ran. */
|
|
28
|
+
followedUp?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TrialRecord {
|
|
32
|
+
task: string;
|
|
33
|
+
kind: Task["kind"];
|
|
34
|
+
arm: string;
|
|
35
|
+
n: number;
|
|
36
|
+
valid: boolean;
|
|
37
|
+
invalid?: string;
|
|
38
|
+
outcome: boolean;
|
|
39
|
+
checkExit?: number | null;
|
|
40
|
+
missingFacts?: string[];
|
|
41
|
+
dirty: boolean;
|
|
42
|
+
process: Record<string, { label: string; explanation: string; value?: number }>;
|
|
43
|
+
editedWhenShouldNot?: boolean;
|
|
44
|
+
leak?: string;
|
|
45
|
+
claimsDone: boolean;
|
|
46
|
+
doneClaimVsOutcome: boolean;
|
|
47
|
+
notices: number;
|
|
48
|
+
timedOut: boolean;
|
|
49
|
+
quota: boolean;
|
|
50
|
+
efficiency: Efficiency;
|
|
51
|
+
session?: string;
|
|
52
|
+
workDir: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface TrialSpec {
|
|
56
|
+
suite: Suite;
|
|
57
|
+
task: Task;
|
|
58
|
+
arm: string;
|
|
59
|
+
n: number;
|
|
60
|
+
runDir: string;
|
|
61
|
+
fixture: string;
|
|
62
|
+
piBin?: string;
|
|
63
|
+
/** pi's auth.json, symlinked into the trial's agent dir so OAuth refresh can write it. */
|
|
64
|
+
authFile?: string;
|
|
65
|
+
tmpRoot?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const trialDirOf = (runDir: string, task: string, arm: string, n: number) => join(runDir, "trials", task, arm, String(n));
|
|
69
|
+
|
|
70
|
+
const QUOTA = /usage limit|quota|rate.?limit|too many requests|\b429\b/i;
|
|
71
|
+
|
|
72
|
+
/** Every spelling of a path an agent might type: absolute, `~/…`, `$HOME/…` (absolute only when HOME is the trial's). */
|
|
73
|
+
function spellings(path: string, ownHome: boolean): string[] {
|
|
74
|
+
const home = homedir();
|
|
75
|
+
if (ownHome || !path.startsWith(`${home}/`)) return [path];
|
|
76
|
+
const rest = path.slice(home.length + 1);
|
|
77
|
+
return [path, `~/${rest}`, `$HOME/${rest}`, `\${HOME}/${rest}`];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function forbiddenFor(suite: Suite, task: Task): string[] {
|
|
81
|
+
const paths = [...suite.forbidden, ...(task.leak_paths ?? []), join(homedir(), ".pi", "agent", "sessions"), join(stateDir(), "experiments")];
|
|
82
|
+
if (task.fixture.repo) paths.push(task.fixture.repo);
|
|
83
|
+
return [...new Set(paths.flatMap((p) => spellings(p, task.home === "work")))];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The headless pi command line; `session` resumes that session file (the follow-up turn) instead of starting one. */
|
|
87
|
+
export function piArgs(suite: Suite, task: Task, arm: string, sessionDir: string, followUp?: { session: string; prompt: string }): string[] {
|
|
88
|
+
const a = suite.arms.get(arm);
|
|
89
|
+
if (!a) throw new Error(`unknown arm ${arm}; arms: ${[...suite.arms.keys()].join(", ")}`);
|
|
90
|
+
const args = ["-p", "--mode", "json", "--model", suite.model, "--thinking", suite.thinking, "-ns", "-ne", "-nc", "-np", "--no-mcp", "--no-themes", "-na", "--offline", "--session-dir", sessionDir];
|
|
91
|
+
if (followUp) args.push("--session", followUp.session);
|
|
92
|
+
for (const e of [...suite.extensions, ...a.extensions]) args.push("-e", e);
|
|
93
|
+
for (const s of a.skills) args.push("--skill", s);
|
|
94
|
+
for (const p of a.appendSystemPrompt) args.push("--append-system-prompt", p);
|
|
95
|
+
args.push("--", followUp ? followUp.prompt : task.prompt.trim());
|
|
96
|
+
return args;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function cleanEnv(extra: Record<string, string>): NodeJS.ProcessEnv {
|
|
100
|
+
const env: NodeJS.ProcessEnv = {};
|
|
101
|
+
// The parent's pi, Herdr and sb session variables must not reach the trial.
|
|
102
|
+
for (const [k, v] of Object.entries(process.env)) if (!/^(?:PI_|HERDR_|SB_|PI$)/.test(k)) env[k] = v;
|
|
103
|
+
return { ...env, ...extra };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function findSession(dir: string): string | undefined {
|
|
107
|
+
if (!existsSync(dir)) return undefined;
|
|
108
|
+
for (const entry of readdirSync(dir, { withFileTypes: true, recursive: true })) {
|
|
109
|
+
if (entry.isFile() && entry.name.endsWith(".jsonl")) return join(entry.parentPath, entry.name);
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function runAgent(bin: string, args: string[], cwd: string, env: NodeJS.ProcessEnv, trialDir: string, timeoutMs: number, suffix = "") {
|
|
115
|
+
return new Promise<{ exit: number | null; signal: string | null; timedOut: boolean }>((resolve, reject) => {
|
|
116
|
+
const child = spawn(bin, args, { cwd, env, stdio: ["ignore", "pipe", "pipe"], detached: true });
|
|
117
|
+
child.stdout.pipe(createWriteStream(join(trialDir, `events${suffix}.jsonl`)));
|
|
118
|
+
child.stderr.pipe(createWriteStream(join(trialDir, `stderr${suffix}.txt`)));
|
|
119
|
+
let timedOut = false;
|
|
120
|
+
const timer = setTimeout(() => {
|
|
121
|
+
timedOut = true;
|
|
122
|
+
try {
|
|
123
|
+
process.kill(-(child.pid as number), "SIGTERM");
|
|
124
|
+
} catch {}
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
try {
|
|
127
|
+
process.kill(-(child.pid as number), "SIGKILL");
|
|
128
|
+
} catch {}
|
|
129
|
+
}, 10_000).unref();
|
|
130
|
+
}, timeoutMs);
|
|
131
|
+
child.on("error", reject);
|
|
132
|
+
child.on("close", (exit, signal) => {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
resolve({ exit, signal, timedOut });
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function runCheck(task: Task, workDir: string, env: NodeJS.ProcessEnv, trialDir: string): { exit: number | null; ms: number } {
|
|
140
|
+
cpSync(join(task.dir, "check"), join(workDir, ".exp-check"), { recursive: true });
|
|
141
|
+
const started = Date.now();
|
|
142
|
+
const r = spawnSync("bash", [join(".exp-check", "check.sh")], { cwd: workDir, env: { ...env, EXP_CHECK_DIR: join(workDir, ".exp-check") }, encoding: "utf8", timeout: (task.check_timeout_s ?? 300) * 1000, maxBuffer: 1 << 26 });
|
|
143
|
+
writeFileSync(join(trialDir, "check.log"), `${r.stdout ?? ""}${r.stderr ?? ""}${r.error ? `\n${r.error.message}\n` : ""}\nexit ${r.status}\n`);
|
|
144
|
+
return { exit: r.status, ms: Date.now() - started };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Grade a finished trial from its stored files; rerunnable after a grader fix. */
|
|
148
|
+
export function gradeTrial(spec: { suite: Suite; task: Task; arm: string; n: number; trialDir: string; workDir?: string }): TrialRecord {
|
|
149
|
+
const { suite, task, arm, n, trialDir } = spec;
|
|
150
|
+
const raw = JSON.parse(readFileSync(join(trialDir, "outcome.json"), "utf8")) as TrialOutcomeRaw;
|
|
151
|
+
const session = findSession(join(trialDir, "session"));
|
|
152
|
+
const entries = session ? readSession(session) : [];
|
|
153
|
+
const g = gradeTranscript(entries, { kind: task.kind, forbidden: forbiddenFor(suite, task) });
|
|
154
|
+
const eff = efficiency(entries, raw.wallMs);
|
|
155
|
+
let outcome: boolean;
|
|
156
|
+
let missingFacts: string[] | undefined;
|
|
157
|
+
if (task.kind === "should_not") {
|
|
158
|
+
const s = shouldNotOutcome({ finalText: g.finalText, dirty: raw.dirty, edits: g.edits.length, facts: task.facts ?? [] });
|
|
159
|
+
outcome = s.pass;
|
|
160
|
+
missingFacts = s.missing;
|
|
161
|
+
} else outcome = raw.checkExit === 0;
|
|
162
|
+
const invalid = raw.quota ? "quota" : !session ? "no_session" : eff.turns === 0 ? "no_turn" : g.leak ? `leak: ${g.leak}` : undefined;
|
|
163
|
+
const record: TrialRecord = {
|
|
164
|
+
task: task.id,
|
|
165
|
+
kind: task.kind,
|
|
166
|
+
arm,
|
|
167
|
+
n,
|
|
168
|
+
valid: !invalid,
|
|
169
|
+
...(invalid ? { invalid } : {}),
|
|
170
|
+
outcome,
|
|
171
|
+
...(raw.checkExit === undefined ? {} : { checkExit: raw.checkExit }),
|
|
172
|
+
...(missingFacts ? { missingFacts } : {}),
|
|
173
|
+
dirty: raw.dirty,
|
|
174
|
+
process: Object.fromEntries(Object.entries(g.process).map(([k, r]) => [k, { label: r.label, explanation: r.explanation, ...(r.value === undefined ? {} : { value: r.value }) }])),
|
|
175
|
+
...(g.editedWhenShouldNot === undefined ? {} : { editedWhenShouldNot: g.editedWhenShouldNot || raw.dirty }),
|
|
176
|
+
...(g.leak ? { leak: g.leak } : {}),
|
|
177
|
+
claimsDone: g.claimsDone,
|
|
178
|
+
doneClaimVsOutcome: g.claimsDone && !outcome,
|
|
179
|
+
notices: g.notices,
|
|
180
|
+
timedOut: raw.timedOut,
|
|
181
|
+
quota: raw.quota,
|
|
182
|
+
efficiency: eff,
|
|
183
|
+
...(session ? { session } : {}),
|
|
184
|
+
workDir: spec.workDir ?? "",
|
|
185
|
+
};
|
|
186
|
+
writeFileSync(join(trialDir, "grade.json"), `${JSON.stringify(record, null, 2)}\n`);
|
|
187
|
+
return record;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function runTrial(spec: TrialSpec): Promise<TrialRecord> {
|
|
191
|
+
const { suite, task, arm, n, runDir, fixture } = spec;
|
|
192
|
+
const trialDir = trialDirOf(runDir, task.id, arm, n);
|
|
193
|
+
// An earlier attempt (a leak rerun) is kept beside it, not overwritten.
|
|
194
|
+
if (existsSync(trialDir)) renameSync(trialDir, `${trialDir}.prev-${Date.now()}`);
|
|
195
|
+
mkdirSync(trialDir, { recursive: true });
|
|
196
|
+
const box = mkdtempSync(join(spec.tmpRoot ?? tmpdir(), `pi-evals-trial-${basename(runDir)}-${task.id}-${arm}-${n}-`));
|
|
197
|
+
const workDir = join(box, "work");
|
|
198
|
+
cloneTree(fixture, workDir);
|
|
199
|
+
const fixtureHead = git(workDir, "rev-parse", "HEAD");
|
|
200
|
+
const agentDir = join(trialDir, "agent");
|
|
201
|
+
mkdirSync(agentDir, { recursive: true });
|
|
202
|
+
writeFileSync(join(agentDir, "settings.json"), "{}\n");
|
|
203
|
+
if (spec.authFile && existsSync(spec.authFile)) symlinkSync(spec.authFile, join(agentDir, "auth.json"));
|
|
204
|
+
const sessionDir = join(trialDir, "session");
|
|
205
|
+
mkdirSync(sessionDir, { recursive: true });
|
|
206
|
+
const env = cleanEnv({ PI_CODING_AGENT_DIR: agentDir, PI_OFFLINE: "1", ...(task.home === "work" ? { HOME: workDir } : {}) });
|
|
207
|
+
const args = piArgs(suite, task, arm, sessionDir);
|
|
208
|
+
writeFileSync(join(trialDir, "command.json"), `${JSON.stringify({ bin: spec.piBin ?? "pi", args, cwd: workDir, home: task.home === "work" ? workDir : undefined }, null, 2)}\n`);
|
|
209
|
+
const startedAt = new Date();
|
|
210
|
+
const timeoutMs = (task.timeout_min ?? 60) * 60_000;
|
|
211
|
+
let r = await runAgent(spec.piBin ?? "pi", args, workDir, env, trialDir, timeoutMs);
|
|
212
|
+
// One identical follow-up turn in every arm, so a close-guard notice left at settle can be read and acted on.
|
|
213
|
+
const first = findSession(sessionDir);
|
|
214
|
+
let followedUp = false;
|
|
215
|
+
if (suite.followUp && first && r.exit === 0 && !r.timedOut) {
|
|
216
|
+
const more = piArgs(suite, task, arm, sessionDir, { session: first, prompt: suite.followUp });
|
|
217
|
+
r = await runAgent(spec.piBin ?? "pi", more, workDir, env, trialDir, Math.max(60_000, timeoutMs - (Date.now() - startedAt.getTime())), "-2");
|
|
218
|
+
followedUp = true;
|
|
219
|
+
}
|
|
220
|
+
const endedAt = new Date();
|
|
221
|
+
const dirty = git(workDir, "status", "--porcelain").length > 0 || git(workDir, "rev-parse", "HEAD") !== fixtureHead;
|
|
222
|
+
git(workDir, "add", "-A");
|
|
223
|
+
writeFileSync(join(trialDir, "diff.patch"), execFileSync("git", ["diff", "--cached", "--binary", fixtureHead], { cwd: workDir, maxBuffer: 1 << 28 }));
|
|
224
|
+
const tail = (file: string) => (existsSync(file) ? readFileSync(file, "utf8").slice(-20_000) : "");
|
|
225
|
+
const suffix = followedUp ? "-2" : "";
|
|
226
|
+
const quota = r.exit !== 0 && QUOTA.test(tail(join(trialDir, `stderr${suffix}.txt`)) + tail(join(trialDir, `events${suffix}.jsonl`)));
|
|
227
|
+
const raw: TrialOutcomeRaw = { exit: r.exit, signal: r.signal, timedOut: r.timedOut, wallMs: endedAt.getTime() - startedAt.getTime(), startedAt: startedAt.toISOString(), endedAt: endedAt.toISOString(), dirty, quota, followedUp };
|
|
228
|
+
if (task.kind !== "should_not") {
|
|
229
|
+
const c = runCheck(task, workDir, cleanEnv(task.home === "work" ? { HOME: workDir } : {}), trialDir);
|
|
230
|
+
raw.checkExit = c.exit;
|
|
231
|
+
raw.checkMs = c.ms;
|
|
232
|
+
}
|
|
233
|
+
writeFileSync(join(trialDir, "outcome.json"), `${JSON.stringify(raw, null, 2)}\n`);
|
|
234
|
+
writeFileSync(join(trialDir, "timing.json"), `${JSON.stringify({ startedAt: raw.startedAt, endedAt: raw.endedAt, wallMs: raw.wallMs, checkMs: raw.checkMs }, null, 2)}\n`);
|
|
235
|
+
const record = gradeTrial({ suite, task, arm, n, trialDir, workDir });
|
|
236
|
+
rmSync(box, { recursive: true, force: true });
|
|
237
|
+
rmSync(join(agentDir, "auth.json"), { force: true });
|
|
238
|
+
return record;
|
|
239
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The validity gate per task: the fixture builds; the prompt does not hand both arms an anchor; the base fails the
|
|
3
|
+
* hidden check; the reference passes it 3 of 3 times (flake screen), each run under 3 minutes. For should-not tasks the
|
|
4
|
+
* reference answer passes the fact list on a clean tree and an empty answer fails it.
|
|
5
|
+
*/
|
|
6
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
7
|
+
import { cpSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { cloneTree } from "./fixture.ts";
|
|
11
|
+
import { promptCreditsAnchor, shouldNotOutcome } from "./grade.ts";
|
|
12
|
+
import type { Task } from "./task.ts";
|
|
13
|
+
|
|
14
|
+
export interface GateResult {
|
|
15
|
+
task: string;
|
|
16
|
+
ok: boolean;
|
|
17
|
+
lines: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A reference check slower than this fails the gate; a task that sets check_timeout_s raises it to that. */
|
|
21
|
+
const LIMIT_MS = 180_000;
|
|
22
|
+
const limitMs = (task: Task) => (task.check_timeout_s ? task.check_timeout_s * 1000 : LIMIT_MS);
|
|
23
|
+
|
|
24
|
+
function check(task: Task, work: string): { exit: number | null; ms: number; tail: string } {
|
|
25
|
+
rmSync(join(work, ".exp-check"), { recursive: true, force: true });
|
|
26
|
+
cpSync(join(task.dir, "check"), join(work, ".exp-check"), { recursive: true });
|
|
27
|
+
const started = Date.now();
|
|
28
|
+
const env = { ...process.env, ...(task.home === "work" ? { HOME: work } : {}), EXP_CHECK_DIR: join(work, ".exp-check") };
|
|
29
|
+
const r = spawnSync("bash", [join(".exp-check", "check.sh")], { cwd: work, env, encoding: "utf8", timeout: (task.check_timeout_s ?? 300) * 1000, maxBuffer: 1 << 26 });
|
|
30
|
+
const out = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim().split("\n");
|
|
31
|
+
return { exit: r.status, ms: Date.now() - started, tail: out.slice(-3).join(" | ") };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function gate(task: Task, fixture: string, options: { runs?: number } = {}): GateResult {
|
|
35
|
+
const lines: string[] = [];
|
|
36
|
+
let ok = true;
|
|
37
|
+
const fail = (line: string) => {
|
|
38
|
+
ok = false;
|
|
39
|
+
lines.push(`FAIL ${line}`);
|
|
40
|
+
};
|
|
41
|
+
// Process metrics count only on tasks that ask for a change, so only their prompts must leave the anchor to the agent.
|
|
42
|
+
if (task.kind === "should_not") lines.push("n/a prompt anchor (process is not scored on should_not tasks)");
|
|
43
|
+
else if (promptCreditsAnchor(task.prompt)) fail("prompt names a check: the detectors would credit both arms with an anchor (anchor_in_brief)");
|
|
44
|
+
else lines.push("ok prompt hands no anchor to either arm");
|
|
45
|
+
if (task.kind === "should_not") {
|
|
46
|
+
const answer = readFileSync(join(task.dir, task.reference.answer as string), "utf8");
|
|
47
|
+
const ref = shouldNotOutcome({ finalText: answer, dirty: false, edits: 0, facts: task.facts ?? [] });
|
|
48
|
+
if (ref.pass) lines.push(`ok reference answer names all ${task.facts?.length} facts`);
|
|
49
|
+
else fail(`reference answer misses ${ref.missing.join(", ")}`);
|
|
50
|
+
if (shouldNotOutcome({ finalText: "", dirty: false, edits: 0, facts: task.facts ?? [] }).pass) fail("an empty answer passes");
|
|
51
|
+
else lines.push("ok an empty answer fails");
|
|
52
|
+
if (shouldNotOutcome({ finalText: answer, dirty: true, edits: 1, facts: task.facts ?? [] }).pass) fail("an edited tree passes");
|
|
53
|
+
else lines.push("ok the reference answer with an edit fails");
|
|
54
|
+
return { task: task.id, ok, lines };
|
|
55
|
+
}
|
|
56
|
+
const box = mkdtempSync(join(tmpdir(), `pi-evals-gate-${task.id}-`));
|
|
57
|
+
try {
|
|
58
|
+
const base = join(box, "base");
|
|
59
|
+
cloneTree(fixture, base);
|
|
60
|
+
const b = check(task, base);
|
|
61
|
+
if (b.exit === 0) fail(`base passes the check (${b.tail})`);
|
|
62
|
+
else lines.push(`ok base fails the check (exit ${b.exit}, ${(b.ms / 1000).toFixed(1)} s: ${b.tail})`);
|
|
63
|
+
const ref = join(box, "reference");
|
|
64
|
+
cloneTree(fixture, ref);
|
|
65
|
+
execFileSync("git", ["apply", "--whitespace=nowarn", join(task.dir, task.reference.patch as string)], { cwd: ref });
|
|
66
|
+
for (let i = 1; i <= (options.runs ?? 3); i++) {
|
|
67
|
+
const r = check(task, ref);
|
|
68
|
+
if (r.exit !== 0) fail(`reference run ${i} fails the check (exit ${r.exit}: ${r.tail})`);
|
|
69
|
+
else if (r.ms > limitMs(task)) fail(`reference run ${i} takes ${(r.ms / 1000).toFixed(0)} s (limit ${limitMs(task) / 1000} s)`);
|
|
70
|
+
else lines.push(`ok reference run ${i} passes (${(r.ms / 1000).toFixed(1)} s)`);
|
|
71
|
+
}
|
|
72
|
+
} finally {
|
|
73
|
+
rmSync(box, { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
return { task: task.id, ok, lines };
|
|
76
|
+
}
|
package/src/labels.ts
CHANGED
|
@@ -19,8 +19,9 @@ export type FailureType = (typeof FAILURE_TYPES)[number];
|
|
|
19
19
|
/**
|
|
20
20
|
* `live-prompt`: the user's words after `/evals label`, which the agent turned into rows on the user's behalf.
|
|
21
21
|
* `recheck`: the user's later verdict on a label given after the fact; it replaces that label.
|
|
22
|
+
* `experiment`: a verdict on a `pi-evals exp` trial; read by `exp show`, never by the monitoring report.
|
|
22
23
|
*/
|
|
23
|
-
export type LabelSource = "batch" | "live" | "live-prompt" | "correction" | "recheck";
|
|
24
|
+
export type LabelSource = "batch" | "live" | "live-prompt" | "correction" | "recheck" | "experiment";
|
|
24
25
|
export const NOTE_MAX = 500;
|
|
25
26
|
|
|
26
27
|
const t = (en: string, zh: string): Text => ({ en, zh });
|
|
@@ -186,7 +187,8 @@ export function labelsModel(labelsFile: string, evalsFile: string, scope: LabelS
|
|
|
186
187
|
if (scope.selected.has(id)) return true;
|
|
187
188
|
return r.source !== undefined && !scope.indexed?.has(id) && typeof r.at === "string" && inDates(r.at) && (!scope.project || r.project === scope.project);
|
|
188
189
|
};
|
|
189
|
-
|
|
190
|
+
// Experiment trials are not production sessions: their labels are read by `pi-evals exp show` only.
|
|
191
|
+
const rows = readLabels(labelsFile).filter((r) => r.source !== "experiment" && inScope(r));
|
|
190
192
|
const human = rows.filter((r) => r.annotator !== "agent");
|
|
191
193
|
const by = new Map<string, { unclear: number; batch: Count; live: Count }>();
|
|
192
194
|
const sessions = { batch: new Set<string>(), live: new Set<string>() };
|