@agentswf/lab 0.3.0 → 0.4.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/package.json +4 -4
- package/schema/{case-check.schema.json → lab-check.schema.json} +1 -1
- package/schema/{case-config.schema.json → lab-config.schema.json} +1 -1
- package/schema/{case-final.schema.json → lab-final.schema.json} +6 -6
- package/schema/{case-grade.schema.json → lab-grade.schema.json} +1 -1
- package/schema/{case-key.schema.json → lab-key.schema.json} +7 -0
- package/schema/{case-label.schema.json → lab-label.schema.json} +3 -3
- package/schema/{case-loop-report.schema.json → lab-loop-report.schema.json} +26 -15
- package/schema/{case-loop.schema.json → lab-loop.schema.json} +1 -1
- package/schema/{case-plan.schema.json → lab-plan.schema.json} +14 -3
- package/schema/{case-proposal.schema.json → lab-proposal.schema.json} +3 -3
- package/schema/{case-report.schema.json → lab-report.schema.json} +272 -36
- package/schema/{case-run.schema.json → lab-run.schema.json} +4 -4
- package/schema/{case-runs.schema.json → lab-runs.schema.json} +8 -1
- package/schema/{case-score.schema.json → lab-score.schema.json} +2 -2
- package/schema/{case-spread.schema.json → lab-spread.schema.json} +6 -6
- package/schema/{case-trial.schema.json → lab-trial.schema.json} +9 -9
- package/schema/{case-try.schema.json → lab-try.schema.json} +6 -6
- package/schema/local.json +3 -3
- package/src/env/capture.ts +1 -1
- package/src/env/compare.ts +7 -7
- package/src/env/fetch.ts +1 -1
- package/src/env/files.ts +14 -14
- package/src/env/grade-helper.ts +15 -15
- package/src/env/grader.ts +5 -2
- package/src/env/index.ts +18 -18
- package/src/env/trial.ts +5 -2
- package/src/format/key.ts +24 -0
- package/src/format/loop.ts +20 -19
- package/src/format/output.ts +120 -59
- package/src/format/records.ts +23 -20
- package/src/format/schema-files.ts +30 -30
- package/src/format/settings.ts +20 -13
- package/src/format/trial-env.ts +9 -6
- package/src/help/awf-lab.txt +1 -1
- package/src/help/case.txt +5 -4
- package/src/help/config.txt +2 -2
- package/src/help/label.txt +2 -2
- package/src/help/loop.txt +10 -10
- package/src/help/report.txt +1 -1
- package/src/help/run.txt +11 -10
- package/src/help/runs.txt +4 -3
- package/src/help/score.txt +4 -3
- package/src/lab/blame.ts +1 -1
- package/src/lab/box.ts +7 -5
- package/src/lab/capture-command.ts +11 -7
- package/src/lab/capture.ts +1 -1
- package/src/lab/check-command.ts +3 -3
- package/src/lab/cli.ts +9 -8
- package/src/lab/columns.ts +5 -5
- package/src/lab/command-context.ts +7 -7
- package/src/lab/compare.ts +8 -8
- package/src/lab/config-command.ts +25 -20
- package/src/lab/dataset.ts +37 -18
- package/src/lab/eval-files.ts +27 -16
- package/src/lab/folders.ts +26 -7
- package/src/lab/good.ts +1 -1
- package/src/lab/grading-stub.txt +2 -2
- package/src/lab/inspect.ts +13 -12
- package/src/lab/labels.ts +16 -11
- package/src/lab/loop-command.ts +68 -64
- package/src/lab/loop-records.ts +5 -5
- package/src/lab/loop.ts +105 -100
- package/src/lab/rates.ts +11 -6
- package/src/lab/record-copies.ts +1 -1
- package/src/lab/report-command.ts +8 -7
- package/src/lab/report.ts +172 -74
- package/src/lab/reuse.ts +29 -21
- package/src/lab/run-command.ts +304 -199
- package/src/lab/run-report.ts +49 -22
- package/src/lab/runs-command.ts +35 -27
- package/src/lab/scaffold.ts +19 -16
- package/src/lab/score-command.ts +72 -64
- package/src/lab/score.ts +1 -1
- package/src/lab/store.ts +3 -3
- package/src/lab/{trial-stub.txt → target-stub.txt} +3 -3
- package/src/lab/trial-settings.ts +17 -12
- package/src/lab/trial.ts +19 -23
- package/src/lab/usage.ts +1 -0
- package/src/lab/workflow-graders.ts +4 -1
- package/src/lab/workspace.ts +16 -9
- package/src/loop/propose.workflow.ts +1 -1
- package/src/shared/compare/index.ts +2 -2
- package/src/shared/compare/paired.ts +20 -20
- package/src/shared/compare/types.ts +4 -4
- package/src/write-schemas.ts +3 -3
- /package/schema/{case-good-record.schema.json → lab-good-record.schema.json} +0 -0
- /package/schema/{case-previous.schema.json → lab-previous.schema.json} +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { type
|
|
4
|
-
import { LIMIT_PHASES, type
|
|
3
|
+
import { CONFIG_KIND, type LabConfig, LabConfigSchema } from "../format/output";
|
|
4
|
+
import { LIMIT_PHASES, type TargetFile } from "../format/settings";
|
|
5
5
|
import { checkSchema, describeProblems } from "../shared/validate";
|
|
6
6
|
import { type Context, helperPlace, shownPath, workspaceOf } from "./command-context";
|
|
7
7
|
import { type DatasetInfo, KEY_FILE, readCases, readDataset } from "./dataset";
|
|
8
8
|
import {
|
|
9
9
|
CONFIG_FILE,
|
|
10
10
|
checkGradingFile,
|
|
11
|
-
|
|
11
|
+
checkTargetFile,
|
|
12
12
|
describeFiles,
|
|
13
13
|
GRADING_FILE,
|
|
14
|
-
|
|
14
|
+
TARGET_FILE,
|
|
15
15
|
} from "./eval-files";
|
|
16
16
|
import { ALWAYS_DENIED } from "./loop-code";
|
|
17
17
|
import { Refusal } from "./refusal";
|
|
@@ -60,8 +60,8 @@ export function config(context: Context): number {
|
|
|
60
60
|
definedIn: l.definedIn.map(shown),
|
|
61
61
|
})),
|
|
62
62
|
};
|
|
63
|
-
const print = (json:
|
|
64
|
-
const checked = checkSchema(
|
|
63
|
+
const print = (json: LabConfig) => {
|
|
64
|
+
const checked = checkSchema(LabConfigSchema, json);
|
|
65
65
|
if (!checked.ok) throw new Error(describeProblems("config --json", checked.problems));
|
|
66
66
|
context.stdout(JSON.stringify(json, null, 2));
|
|
67
67
|
};
|
|
@@ -104,13 +104,13 @@ export function config(context: Context): number {
|
|
|
104
104
|
for (const loop of workspace.loops) loopValues(loop, shown);
|
|
105
105
|
for (const name of existsSync(workspace.evals) ? readdirSync(workspace.evals) : []) {
|
|
106
106
|
const dir = join(workspace.evals, name);
|
|
107
|
-
if (used.has(dir) || !existsSync(join(dir,
|
|
107
|
+
if (used.has(dir) || !existsSync(join(dir, TARGET_FILE))) continue;
|
|
108
108
|
const files = {
|
|
109
|
-
|
|
109
|
+
target: join(dir, TARGET_FILE),
|
|
110
110
|
...(existsSync(join(dir, GRADING_FILE)) ? { grading: join(dir, GRADING_FILE) } : {}),
|
|
111
111
|
};
|
|
112
112
|
const described = describeFiles(files, place);
|
|
113
|
-
|
|
113
|
+
checkTargetFile(files.target, described.target);
|
|
114
114
|
if (files.grading) checkGradingFile(files.grading, described.grading);
|
|
115
115
|
}
|
|
116
116
|
if (options.json) {
|
|
@@ -129,9 +129,9 @@ export function config(context: Context): number {
|
|
|
129
129
|
workspace.datasets.map((d) => [
|
|
130
130
|
d.name,
|
|
131
131
|
d.eval.value === d.data.value
|
|
132
|
-
? shown(d.eval.value)
|
|
132
|
+
? `eval and data ${shown(d.eval.value)}`
|
|
133
133
|
: `eval ${shown(d.eval.value)} · data ${shown(d.data.value)}`,
|
|
134
|
-
d.definedIn.map(shown).join(", ")
|
|
134
|
+
`defined in ${d.definedIn.map(shown).join(", ")}`,
|
|
135
135
|
]),
|
|
136
136
|
)
|
|
137
137
|
: [" none: awf-lab case new {dataset}/{case} makes one"]),
|
|
@@ -141,7 +141,7 @@ export function config(context: Context): number {
|
|
|
141
141
|
workspace.loops.map((l) => [
|
|
142
142
|
l.name,
|
|
143
143
|
`dataset ${l.dataset.value}`,
|
|
144
|
-
l.definedIn.map(shown).join(", ")
|
|
144
|
+
`defined in ${l.definedIn.map(shown).join(", ")}`,
|
|
145
145
|
]),
|
|
146
146
|
)
|
|
147
147
|
: [` none: an entry of loops in evals/${CONFIG_FILE} makes one`]),
|
|
@@ -178,11 +178,11 @@ function loopValues(loop: LoopRef, shown: (path: string) => string): Row[] {
|
|
|
178
178
|
];
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
/** `
|
|
182
|
-
function settingRows(
|
|
183
|
-
const resolved = resolveSettings(
|
|
181
|
+
/** `target.ts`'s sandbox and limits, each part resolved, from the file or the lab's default. */
|
|
182
|
+
function settingRows(target: TargetFile, file: string): Row[] {
|
|
183
|
+
const resolved = resolveSettings(target);
|
|
184
184
|
const { sandbox, limits } = resolved;
|
|
185
|
-
const given =
|
|
185
|
+
const given = target.sandbox;
|
|
186
186
|
const list = (xs: readonly string[]) => (xs.length > 0 ? xs.join(", ") : "none");
|
|
187
187
|
const row = (name: string, value: string, set: boolean): Row => [
|
|
188
188
|
name,
|
|
@@ -211,7 +211,7 @@ function settingRows(trial: TrialFile, file: string): Row[] {
|
|
|
211
211
|
given?.network?.sockets !== undefined,
|
|
212
212
|
),
|
|
213
213
|
...LIMIT_PHASES.map((phase) =>
|
|
214
|
-
row(`limits.${phase}`, limits[phase],
|
|
214
|
+
row(`limits.${phase}`, limits[phase], target.limits?.[phase] !== undefined),
|
|
215
215
|
),
|
|
216
216
|
];
|
|
217
217
|
}
|
|
@@ -223,8 +223,8 @@ function datasetValues(
|
|
|
223
223
|
info: DatasetInfo,
|
|
224
224
|
shown: (path: string) => string,
|
|
225
225
|
): { dataset: Row[]; case?: { name: string; rows: Row[] } } {
|
|
226
|
-
const { ref,
|
|
227
|
-
const
|
|
226
|
+
const { ref, target, grading } = info;
|
|
227
|
+
const targetFile = shown(join(info.evalDir, TARGET_FILE));
|
|
228
228
|
const gradingFile = shown(join(info.evalDir, GRADING_FILE));
|
|
229
229
|
const graders = (grading.graders ?? []).map(
|
|
230
230
|
(g) =>
|
|
@@ -241,7 +241,7 @@ function datasetValues(
|
|
|
241
241
|
...Object.entries(info.params).map(
|
|
242
242
|
([name, p]): Row => [`params.${name}`, p.value ?? "required, no value", shown(p.from)],
|
|
243
243
|
),
|
|
244
|
-
...settingRows(
|
|
244
|
+
...settingRows(target, targetFile),
|
|
245
245
|
["pass", grading.pass ?? "all", grading.pass ? gradingFile : DEFAULT],
|
|
246
246
|
["graders", graders.join(", ") || "none", gradingFile],
|
|
247
247
|
["compare", grading.compare ? "set" : "none", gradingFile],
|
|
@@ -272,6 +272,11 @@ function datasetValues(
|
|
|
272
272
|
["draft", ...flag(found.key.draft)],
|
|
273
273
|
["known-failing", ...flag(found.key["known-failing"])],
|
|
274
274
|
["tags", found.key.tags?.join(", ") ?? "none", found.key.tags ? key : DEFAULT],
|
|
275
|
+
[
|
|
276
|
+
"shared",
|
|
277
|
+
found.key.shared ? found.key.shared.join(", ") || "none" : "all",
|
|
278
|
+
found.key.shared ? key : DEFAULT,
|
|
279
|
+
],
|
|
275
280
|
],
|
|
276
281
|
},
|
|
277
282
|
};
|
package/src/lab/dataset.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, statSyn
|
|
|
3
3
|
import { join, relative } from "node:path";
|
|
4
4
|
import type { Reads } from "../env/grader";
|
|
5
5
|
import { parseKey } from "../format/key";
|
|
6
|
-
import type { GradingFile, Key,
|
|
6
|
+
import type { GradingFile, Key, TargetFile } from "../format/settings";
|
|
7
7
|
import type { Agent } from "../shared/config";
|
|
8
8
|
import { describeProblems } from "../shared/validate";
|
|
9
9
|
import {
|
|
10
10
|
checkGradingFile,
|
|
11
|
-
|
|
11
|
+
checkTargetFile,
|
|
12
12
|
describeFiles,
|
|
13
13
|
GRADING_FILE,
|
|
14
14
|
type HelperPlace,
|
|
15
15
|
refuseStub,
|
|
16
|
-
|
|
16
|
+
TARGET_FILE,
|
|
17
17
|
} from "./eval-files";
|
|
18
18
|
import { Refusal } from "./refusal";
|
|
19
19
|
import { type DatasetRef, inside, type Traced } from "./workspace";
|
|
@@ -29,13 +29,13 @@ export type ParamValue = Traced<string | undefined>;
|
|
|
29
29
|
|
|
30
30
|
export type DatasetInfo = {
|
|
31
31
|
name: string;
|
|
32
|
-
/** The eval folder: `
|
|
32
|
+
/** The eval folder: `target.ts`, `grading.ts`, `graders/`, `capture.ts`. */
|
|
33
33
|
evalDir: string;
|
|
34
34
|
/** The data folder: `cases/` and `shared/`. */
|
|
35
35
|
dataDir: string;
|
|
36
|
-
|
|
36
|
+
target: TargetFile;
|
|
37
37
|
grading: GradingFile;
|
|
38
|
-
/** Every parameter `
|
|
38
|
+
/** Every parameter `target.ts` declares: its default, under the dataset entries' values. */
|
|
39
39
|
params: Record<string, ParamValue>;
|
|
40
40
|
/** Where a copy of the dataset's records is kept. */
|
|
41
41
|
records?: string;
|
|
@@ -73,33 +73,33 @@ function folders(dir: string): string[] {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* A dataset: its eval folder's `
|
|
76
|
+
* A dataset: its eval folder's `target.ts` and `grading.ts`, loaded in the helper in your checkout
|
|
77
77
|
* and checked, and its parameters resolved against the dataset's entries.
|
|
78
78
|
*/
|
|
79
79
|
export function readDataset(ref: DatasetRef, place: HelperPlace): DatasetInfo {
|
|
80
80
|
const evalDir = ref.eval.value;
|
|
81
|
-
const
|
|
81
|
+
const targetFile = join(evalDir, TARGET_FILE);
|
|
82
82
|
const gradingFile = join(evalDir, GRADING_FILE);
|
|
83
83
|
if (!existsSync(gradingFile)) {
|
|
84
84
|
throw new Refusal(
|
|
85
85
|
`${evalDir} has no ${GRADING_FILE}: export default defineGrading({}) grades by the keys alone`,
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
|
-
refuseStub(
|
|
89
|
-
const described = describeFiles({
|
|
90
|
-
const
|
|
88
|
+
refuseStub(targetFile);
|
|
89
|
+
const described = describeFiles({ target: targetFile, grading: gradingFile }, place);
|
|
90
|
+
const target = checkTargetFile(targetFile, described.target);
|
|
91
91
|
const grading = checkGradingFile(gradingFile, described.grading);
|
|
92
92
|
const params: Record<string, ParamValue> = {};
|
|
93
|
-
for (const [name, declared] of Object.entries(
|
|
93
|
+
for (const [name, declared] of Object.entries(target.params ?? {})) {
|
|
94
94
|
params[name] = {
|
|
95
95
|
value: typeof declared === "string" ? declared : undefined,
|
|
96
|
-
from:
|
|
96
|
+
from: targetFile,
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
for (const [name, value] of Object.entries(ref.params)) {
|
|
100
100
|
if (!(name in params)) {
|
|
101
101
|
throw new Refusal(
|
|
102
|
-
`${value.from}: dataset ${ref.name} gives parameter ${name}, which ${
|
|
102
|
+
`${value.from}: dataset ${ref.name} gives parameter ${name}, which ${targetFile} doesn't declare${declaredList(params)}`,
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
params[name] = value;
|
|
@@ -116,7 +116,7 @@ export function readDataset(ref: DatasetRef, place: HelperPlace): DatasetInfo {
|
|
|
116
116
|
name: ref.name,
|
|
117
117
|
evalDir,
|
|
118
118
|
dataDir: ref.data.value,
|
|
119
|
-
|
|
119
|
+
target,
|
|
120
120
|
grading,
|
|
121
121
|
params,
|
|
122
122
|
...(ref.records ? { records: ref.records.value } : {}),
|
|
@@ -208,7 +208,7 @@ export function refuseLinks(dir: string): void {
|
|
|
208
208
|
/** Every case of a dataset, its key read strictly. */
|
|
209
209
|
export function readCases(dataset: DatasetInfo): CaseInfo[] {
|
|
210
210
|
const root = join(dataset.dataDir, "cases");
|
|
211
|
-
return folders(root).map((name) => readCase(name, join(root, name)));
|
|
211
|
+
return folders(root).map((name) => readCase(name, join(root, name), dataset.dataDir));
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/** Every case of a dataset, each read or the reason it doesn't: `case check` names them all. */
|
|
@@ -218,7 +218,7 @@ export function readEachCase(
|
|
|
218
218
|
const root = join(dataset.dataDir, "cases");
|
|
219
219
|
return folders(root).map((name) => {
|
|
220
220
|
try {
|
|
221
|
-
return { name, info: readCase(name, join(root, name)) };
|
|
221
|
+
return { name, info: readCase(name, join(root, name), dataset.dataDir) };
|
|
222
222
|
} catch (error) {
|
|
223
223
|
if (error instanceof Refusal) return { name, problem: error.message };
|
|
224
224
|
throw error;
|
|
@@ -226,7 +226,25 @@ export function readEachCase(
|
|
|
226
226
|
});
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
/**
|
|
230
|
+
* What of the data folder's `shared/` a case is built from, each path relative to it: what its key
|
|
231
|
+
* names, or all of it. A named path `shared/` doesn't hold is refused.
|
|
232
|
+
*/
|
|
233
|
+
export function sharedOf(dataDir: string, info: Pick<CaseInfo, "name" | "key">): string[] {
|
|
234
|
+
const root = join(dataDir, SHARED_DIR);
|
|
235
|
+
const named = info.key.shared;
|
|
236
|
+
if (named === undefined) return existsSync(root) ? ["."] : [];
|
|
237
|
+
for (const path of named) {
|
|
238
|
+
if (!existsSync(join(root, path))) {
|
|
239
|
+
throw new Refusal(
|
|
240
|
+
`case ${info.name}'s ${KEY_FILE} names shared ${path}, which ${root} doesn't hold`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return named;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function readCase(name: string, dir: string, dataDir: string): CaseInfo {
|
|
230
248
|
const keyFile = join(dir, KEY_FILE);
|
|
231
249
|
refuseLinks(join(dir, INPUT_DIR));
|
|
232
250
|
refuseLinks(join(dir, "key"));
|
|
@@ -256,6 +274,7 @@ function readCase(name: string, dir: string): CaseInfo {
|
|
|
256
274
|
}
|
|
257
275
|
const good =
|
|
258
276
|
existsSync(goodDir) && statSync(goodDir).isDirectory() ? { dir: goodDir } : undefined;
|
|
277
|
+
sharedOf(dataDir, { name, key: read.value.key });
|
|
259
278
|
return {
|
|
260
279
|
name,
|
|
261
280
|
dir,
|
package/src/lab/eval-files.ts
CHANGED
|
@@ -10,22 +10,22 @@ import {
|
|
|
10
10
|
LocalFileSchema,
|
|
11
11
|
passProblem,
|
|
12
12
|
SETTINGS_PATTERNS,
|
|
13
|
-
type
|
|
14
|
-
|
|
13
|
+
type TargetFile,
|
|
14
|
+
TargetFileSchema,
|
|
15
15
|
} from "../format/settings";
|
|
16
16
|
import { checkSchema, describeProblems, explainProblems } from "../shared/validate";
|
|
17
17
|
import { Refusal } from "./refusal";
|
|
18
18
|
|
|
19
|
-
// The files a person writes for the lab: `
|
|
19
|
+
// The files a person writes for the lab: `target.ts` and `grading.ts` in an eval folder,
|
|
20
20
|
// `evals/awf-lab.config.ts`, and the one JSON file, `evals/awf-lab.local.json`. The TypeScript ones
|
|
21
21
|
// are read in the grade helper, in your checkout, which runs nothing they define; each comes back
|
|
22
22
|
// as JSON and is checked here, strictly.
|
|
23
23
|
|
|
24
|
-
export const
|
|
24
|
+
export const TARGET_FILE = "target.ts";
|
|
25
25
|
export const GRADING_FILE = "grading.ts";
|
|
26
26
|
export const CONFIG_FILE = "awf-lab.config.ts";
|
|
27
27
|
export const LOCAL_FILE = "awf-lab.local.json";
|
|
28
|
-
/** The line `case new` writes into a stub `
|
|
28
|
+
/** The line `case new` writes into a stub `target.ts`; `run` refuses the file while it is there. */
|
|
29
29
|
export const STUB_LINE = "// awf-lab: a stub.";
|
|
30
30
|
|
|
31
31
|
/** Refuses the stub `case new` wrote, before anything loads it. */
|
|
@@ -44,11 +44,11 @@ const DESCRIBE_MS = 120_000;
|
|
|
44
44
|
/** Where the helper runs: your checkout, its environment, and a folder for its request. */
|
|
45
45
|
export type HelperPlace = { root: string; env: Record<string, string>; tmp: string };
|
|
46
46
|
|
|
47
|
-
type Described = {
|
|
47
|
+
type Described = { target?: unknown; grading?: unknown; lab?: unknown };
|
|
48
48
|
|
|
49
49
|
/** Loads the TypeScript files in the helper, as JSON; refused naming the first that doesn't load. */
|
|
50
50
|
export function describeFiles(
|
|
51
|
-
files: {
|
|
51
|
+
files: { target?: string; grading?: string; lab?: string },
|
|
52
52
|
place: HelperPlace,
|
|
53
53
|
): Described {
|
|
54
54
|
const work = mkdtempSync(join(place.tmp, "awf-lab-describe-"));
|
|
@@ -100,11 +100,11 @@ function checked<S extends Type.TSchema>(
|
|
|
100
100
|
return result.value;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
/** The fields `
|
|
104
|
-
const
|
|
103
|
+
/** The fields `target.ts` no longer takes, each with what replaced it. */
|
|
104
|
+
const GONE_TARGET_FIELDS: Readonly<Record<string, string>> = {
|
|
105
105
|
agentReach:
|
|
106
106
|
"it is sandbox.network: its network is agents, and webSearch and sockets (now a list of socket paths) moved with it",
|
|
107
|
-
timeout: "it is limits.
|
|
107
|
+
timeout: "it is limits.workflow",
|
|
108
108
|
setupTimeout: "it is limits.setup for setup and limits.after for evidence and cleanup",
|
|
109
109
|
realHosts: "it is sandbox.network.code",
|
|
110
110
|
};
|
|
@@ -120,15 +120,15 @@ function goneSandbox(sandbox: unknown): string | undefined {
|
|
|
120
120
|
return undefined;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
export function
|
|
123
|
+
export function checkTargetFile(file: string, raw: unknown): TargetFile {
|
|
124
124
|
if (raw && typeof raw === "object") {
|
|
125
|
-
const gone = Object.keys(raw).find((field) => field in
|
|
125
|
+
const gone = Object.keys(raw).find((field) => field in GONE_TARGET_FIELDS);
|
|
126
126
|
if (gone)
|
|
127
|
-
throw new Refusal(`${file}:
|
|
127
|
+
throw new Refusal(`${file}: defineTarget takes no ${gone}: ${GONE_TARGET_FIELDS[gone]}`);
|
|
128
128
|
const sandbox = goneSandbox((raw as { sandbox?: unknown }).sandbox);
|
|
129
129
|
if (sandbox) throw new Refusal(`${file}: ${sandbox}`);
|
|
130
130
|
}
|
|
131
|
-
return checked(
|
|
131
|
+
return checked(TargetFileSchema, file, "defineTarget", raw);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
export function checkGradingFile(file: string, raw: unknown): GradingFile {
|
|
@@ -164,12 +164,23 @@ export function checkLabConfig(file: string, raw: unknown): LabConfig {
|
|
|
164
164
|
* untracked file isn't enough, since `git add -A` would commit it.
|
|
165
165
|
*/
|
|
166
166
|
export function readLocalFile(file: string): LocalFile {
|
|
167
|
+
const folder = join(file, "..");
|
|
167
168
|
const ignored = Bun.spawnSync(["git", "check-ignore", "-q", file], {
|
|
168
|
-
cwd:
|
|
169
|
+
cwd: folder,
|
|
169
170
|
stdout: "ignore",
|
|
170
|
-
stderr: "
|
|
171
|
+
stderr: "pipe",
|
|
171
172
|
stdin: "ignore",
|
|
172
173
|
});
|
|
174
|
+
// 1 is "not ignored"; anything else is git failing, as in a worktree whose repository moved.
|
|
175
|
+
if (ignored.exitCode !== 0 && ignored.exitCode !== 1) {
|
|
176
|
+
const said = ignored.stderr.toString().trim();
|
|
177
|
+
const moved = /not a git repository|does not point to a valid repository/.test(said)
|
|
178
|
+
? "; a worktree whose repository moved: git worktree repair"
|
|
179
|
+
: "";
|
|
180
|
+
throw new Refusal(
|
|
181
|
+
`git check-ignore fails in ${folder} (exit ${ignored.exitCode})${said ? `: ${said}` : ""}; the lab asks git whether ${LOCAL_FILE} is ignored${moved}`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
173
184
|
if (ignored.exitCode !== 0) {
|
|
174
185
|
throw new Refusal(
|
|
175
186
|
`${file} is not ignored by git, and the lab reads it only then: add ${LOCAL_FILE} to evals/.gitignore`,
|
package/src/lab/folders.ts
CHANGED
|
@@ -20,11 +20,14 @@ import {
|
|
|
20
20
|
refuseLinks,
|
|
21
21
|
SHARED_DIR,
|
|
22
22
|
sha256,
|
|
23
|
+
sharedOf,
|
|
23
24
|
} from "./dataset";
|
|
24
25
|
import { blobIdOf, blobIds, historyHolds } from "./git";
|
|
25
26
|
import { alive } from "./store";
|
|
26
27
|
|
|
27
28
|
const PREFIX = "awf-lab-case-";
|
|
29
|
+
/** A run's cases, built once as it starts, which its trials copy. */
|
|
30
|
+
const SNAPSHOT_PREFIX = "awf-lab-reuse-";
|
|
28
31
|
const OWNER = "owner.json";
|
|
29
32
|
|
|
30
33
|
export type TrialFolders = { parent: string; dir: string; scratch: string };
|
|
@@ -43,12 +46,22 @@ export function makeTrialFolders(tmp: string, run: string): TrialFolders {
|
|
|
43
46
|
return { parent, dir, scratch };
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
/**
|
|
49
|
+
/** A folder for a run's built cases, owned by this process as a trial's folders are. */
|
|
50
|
+
export function makeSnapshotFolder(tmp: string): string {
|
|
51
|
+
const dir = realpathSync(mkdtempSync(join(tmp, SNAPSHOT_PREFIX)));
|
|
52
|
+
writeFileSync(join(dir, OWNER), JSON.stringify({ pid: process.pid }));
|
|
53
|
+
return dir;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Removes trial and snapshot folders whose process is gone; never one without an owner, or still
|
|
58
|
+
* owned.
|
|
59
|
+
*/
|
|
47
60
|
export function clearStale(tmp: string): number {
|
|
48
61
|
if (!existsSync(tmp)) return 0;
|
|
49
62
|
let removed = 0;
|
|
50
63
|
for (const name of readdirSync(tmp)) {
|
|
51
|
-
if (!name.startsWith(PREFIX)) continue;
|
|
64
|
+
if (!name.startsWith(PREFIX) && !name.startsWith(SNAPSHOT_PREFIX)) continue;
|
|
52
65
|
const owner = join(tmp, name, OWNER);
|
|
53
66
|
try {
|
|
54
67
|
const { pid } = JSON.parse(readFileSync(owner, "utf8")) as { pid?: unknown };
|
|
@@ -62,14 +75,20 @@ export function clearStale(tmp: string): number {
|
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
/**
|
|
65
|
-
* The built case folder: the data folder's `shared
|
|
66
|
-
* the case's
|
|
78
|
+
* The built case folder: of the data folder's `shared/`, what the case's key names under `shared`,
|
|
79
|
+
* or all of it, at the same paths, and the case's `input/` merged over it at its root, the case's
|
|
80
|
+
* winning. Never `key.md` or `key/`.
|
|
67
81
|
*/
|
|
68
82
|
export function buildCase(dataDir: string, info: CaseInfo, target: string): void {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
const shared = join(dataDir, SHARED_DIR);
|
|
84
|
+
refuseLinks(shared);
|
|
85
|
+
for (const path of sharedOf(dataDir, info)) {
|
|
86
|
+
mkdirSync(dirname(join(target, path)), { recursive: true });
|
|
87
|
+
cpSync(join(shared, path), join(target, path), { recursive: true, force: true });
|
|
72
88
|
}
|
|
89
|
+
const input = join(info.dir, INPUT_DIR);
|
|
90
|
+
refuseLinks(input);
|
|
91
|
+
if (existsSync(input)) cpSync(input, target, { recursive: true, force: true });
|
|
73
92
|
}
|
|
74
93
|
|
|
75
94
|
export type Needle = { marker: string; keyFiles: readonly KeyFile[] };
|
package/src/lab/good.ts
CHANGED
|
@@ -203,7 +203,7 @@ export function writeGood(caseDir: string, trial: StoredTrial): string {
|
|
|
203
203
|
const keptDir = join(trial.dir, "kept");
|
|
204
204
|
if (existsSync(join(keptDir, GOOD_RECORD))) {
|
|
205
205
|
throw new Refusal(
|
|
206
|
-
`trial ${trial.record.
|
|
206
|
+
`trial ${trial.record.trialId}'s evidence saved a file named ${GOOD_RECORD}, which the known good record's own name would hide`,
|
|
207
207
|
);
|
|
208
208
|
}
|
|
209
209
|
const target = join(caseDir, "key", GOOD_DIR);
|
package/src/lab/grading-stub.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineGrading } from "@agentswf/lab";
|
|
2
|
-
import type
|
|
2
|
+
import type target from "./target";
|
|
3
3
|
|
|
4
4
|
// The key's expect checks the facts read off each trial record; list graders here for rules that
|
|
5
5
|
// hold for every case.
|
|
6
|
-
export default defineGrading<typeof
|
|
6
|
+
export default defineGrading<typeof target>({
|
|
7
7
|
facts: (record) => ({ done: record.result !== undefined }),
|
|
8
8
|
});
|
package/src/lab/inspect.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { dirname, join, relative, resolve } from "node:path";
|
|
11
11
|
import { OUTPUT_RECORD_VERSION } from "@agentswf/contract/records";
|
|
12
12
|
import { type AwfBin, probeRecordVersion } from "../shared/runner";
|
|
13
|
-
import { GRADING_FILE, refuseStub,
|
|
13
|
+
import { GRADING_FILE, refuseStub, TARGET_FILE } from "./eval-files";
|
|
14
14
|
import { Refusal } from "./refusal";
|
|
15
15
|
import { LAB_VERSION } from "./reuse";
|
|
16
16
|
import { inside } from "./workspace";
|
|
@@ -36,11 +36,11 @@ export type FolderSetup = {
|
|
|
36
36
|
bin: string;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
/** The eval folder's `
|
|
40
|
-
export function
|
|
41
|
-
const file = join(evalDir,
|
|
39
|
+
/** The eval folder's `target.ts` is there and filled in. */
|
|
40
|
+
export function checkTargetScript(evalDir: string): string {
|
|
41
|
+
const file = join(evalDir, TARGET_FILE);
|
|
42
42
|
if (!existsSync(file)) {
|
|
43
|
-
throw new Refusal(`${file} is missing: an eval folder's
|
|
43
|
+
throw new Refusal(`${file} is missing: an eval folder's target.ts sets up each case's world`);
|
|
44
44
|
}
|
|
45
45
|
refuseStub(file);
|
|
46
46
|
return file;
|
|
@@ -75,10 +75,10 @@ function compareVersions(a: string, b: string): number {
|
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* The checks on a folder before the first trial: its own `awf`, at least the `agentswf` this lab
|
|
78
|
-
* reads; `@agentswf/lab` and its `fetch` resolving there; and `
|
|
78
|
+
* reads; `@agentswf/lab` and its `fetch` resolving there; and `target.ts` and `grading.ts`
|
|
79
79
|
* type-checked by the folder's own `tsc`, only errors in the eval folder counting.
|
|
80
80
|
*/
|
|
81
|
-
export async function inspectFolder(root: string,
|
|
81
|
+
export async function inspectFolder(root: string, targetScript: string): Promise<FolderSetup> {
|
|
82
82
|
const problems: string[] = [];
|
|
83
83
|
const manifest = upward(root, "agentswf/package.json");
|
|
84
84
|
let awf: Required<AwfBin> | undefined;
|
|
@@ -116,8 +116,9 @@ export async function inspectFolder(root: string, trialScript: string): Promise<
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
const tsc = upward(root, ".bin/tsc");
|
|
119
|
-
if (!tsc)
|
|
120
|
-
|
|
119
|
+
if (!tsc)
|
|
120
|
+
problems.push(`no tsc in ${root}: install typescript there, for the check of target.ts`);
|
|
121
|
+
else problems.push(...(await typeCheck(root, tsc, targetScript)));
|
|
121
122
|
if (problems.length > 0 || !awf) {
|
|
122
123
|
throw new Refusal(`${root} can't run trials:\n${problems.map((p) => ` ${p}`).join("\n")}`);
|
|
123
124
|
}
|
|
@@ -162,7 +163,7 @@ function resolveFrom(root: string, spec: string): string | undefined {
|
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
/** `tsc --noEmit` on the eval folder's files alone, through a tsconfig beside the folder's own, extending it. */
|
|
165
|
-
async function typeCheck(root: string, tsc: string,
|
|
166
|
+
async function typeCheck(root: string, tsc: string, targetScript: string): Promise<string[]> {
|
|
166
167
|
const config = join(root, `tsconfig.awf-lab-${randomBytes(4).toString("hex")}.json`);
|
|
167
168
|
const own = join(root, "tsconfig.json");
|
|
168
169
|
writeFileSync(
|
|
@@ -184,7 +185,7 @@ async function typeCheck(root: string, tsc: string, trialScript: string): Promis
|
|
|
184
185
|
allowImportingTsExtensions: true,
|
|
185
186
|
}),
|
|
186
187
|
},
|
|
187
|
-
files: [
|
|
188
|
+
files: [targetScript, join(dirname(targetScript), GRADING_FILE)]
|
|
188
189
|
.filter((file) => existsSync(file))
|
|
189
190
|
.map((file) => relative(root, file)),
|
|
190
191
|
include: [],
|
|
@@ -203,7 +204,7 @@ async function typeCheck(root: string, tsc: string, trialScript: string): Promis
|
|
|
203
204
|
new Response(child.stderr).text(),
|
|
204
205
|
child.exited,
|
|
205
206
|
]);
|
|
206
|
-
return errorsIn(`${out}\n${err}`, root, dirname(
|
|
207
|
+
return errorsIn(`${out}\n${err}`, root, dirname(targetScript));
|
|
207
208
|
} finally {
|
|
208
209
|
rmSync(config, { force: true });
|
|
209
210
|
}
|
package/src/lab/labels.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import { type LabelRecord, LabelRecordSchema } from "../format/records";
|
|
3
|
+
import { LABEL_KIND, type LabelRecord, LabelRecordSchema } from "../format/records";
|
|
4
4
|
import { checkSchema, describeProblems } from "../shared/validate";
|
|
5
5
|
import { versionKey } from "../shared/version";
|
|
6
6
|
import { newestEntries, trialOutcome, votersOf } from "./outcome";
|
|
7
7
|
import { Refusal } from "./refusal";
|
|
8
8
|
import type { StoredTrial } from "./store";
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
10
|
+
// Your marks: `{store}/labels/{dataset}.jsonl`, one line per label, newest last. They are on the
|
|
11
|
+
// trial, found by its trial id, not on each criterion; a note says why.
|
|
12
|
+
|
|
13
|
+
const LABEL_FAMILY = LABEL_KIND.slice(0, LABEL_KIND.indexOf("/") + 1);
|
|
12
14
|
|
|
13
15
|
export const labelsFileOf = (store: string, dataset: string) =>
|
|
14
16
|
join(store, "labels", `${dataset}.jsonl`);
|
|
@@ -33,21 +35,24 @@ function readLines(file: string): LabelRecord[] {
|
|
|
33
35
|
} catch {
|
|
34
36
|
return [];
|
|
35
37
|
}
|
|
36
|
-
//
|
|
38
|
+
// A line of another format, such as an older one, is left out, as other records are; a label
|
|
39
|
+
// of this format that doesn't read stops the command rather than drop out unseen.
|
|
40
|
+
const kind = (value as { kind?: unknown } | null)?.kind;
|
|
41
|
+
if (typeof kind !== "string" || !kind.startsWith(LABEL_FAMILY)) return [];
|
|
37
42
|
const checked = checkSchema(LabelRecordSchema, value);
|
|
38
43
|
if (!checked.ok) throw new Refusal(describeProblems(file, checked.problems));
|
|
39
44
|
return [checked.value];
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
/** Each labeled trial's newest label, by its
|
|
48
|
+
/** Each labeled trial's newest label, by its trial id; a cleared one is no label. */
|
|
44
49
|
export function readLabels(store: string, dataset: string): Map<string, LabelRecord> {
|
|
45
50
|
const labels = new Map<string, LabelRecord>();
|
|
46
51
|
const lines = readLines(labelsFileOf(store, dataset));
|
|
47
52
|
// A stable sort: two labels made in the same instant keep the order they were written in.
|
|
48
53
|
for (const line of [...lines].sort((x, y) => x.at.localeCompare(y.at))) {
|
|
49
|
-
if (line.mark === "cleared") labels.delete(line.
|
|
50
|
-
else labels.set(line.
|
|
54
|
+
if (line.mark === "cleared") labels.delete(line.trialId);
|
|
55
|
+
else labels.set(line.trialId, line);
|
|
51
56
|
}
|
|
52
57
|
return labels;
|
|
53
58
|
}
|
|
@@ -128,7 +133,7 @@ export function agreementOf(
|
|
|
128
133
|
const disagreements: PersonAgreement["disagreements"] = [];
|
|
129
134
|
let notCompared = 0;
|
|
130
135
|
for (const { record, scores } of trials) {
|
|
131
|
-
const label = record.
|
|
136
|
+
const label = record.trialId ? labels.get(record.trialId) : undefined;
|
|
132
137
|
if (!label || label.mark === "cleared") continue;
|
|
133
138
|
const deciders = decidersOf(record.case);
|
|
134
139
|
const { outcome } = trialOutcome(record, scores, deciders);
|
|
@@ -184,8 +189,8 @@ export function judgeLabeled(
|
|
|
184
189
|
const seen = new Map<string, LabelRecord>();
|
|
185
190
|
for (const trials of runs) {
|
|
186
191
|
for (const { record, scores } of trials) {
|
|
187
|
-
const label = record.
|
|
188
|
-
if (!label || seen.has(record.
|
|
192
|
+
const label = record.trialId ? labels.get(record.trialId) : undefined;
|
|
193
|
+
if (!label || seen.has(record.trialId!)) continue;
|
|
189
194
|
const entry = newestEntries(scores).find((e) => e.grader === judge.grader);
|
|
190
195
|
if (!entry || entry.skipped || entry.errored || !entry.verdict) continue;
|
|
191
196
|
const minor = versionKey(entry.version);
|
|
@@ -195,7 +200,7 @@ export function judgeLabeled(
|
|
|
195
200
|
minor !== judge.minor
|
|
196
201
|
)
|
|
197
202
|
continue;
|
|
198
|
-
seen.set(record.
|
|
203
|
+
seen.set(record.trialId!, label);
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
206
|
const marks = [...seen.values()];
|