@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
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type Limits,
|
|
5
5
|
type ResolvedLimits,
|
|
6
6
|
type ResolvedSandbox,
|
|
7
|
-
type
|
|
7
|
+
type TargetFile,
|
|
8
8
|
} from "../format/settings";
|
|
9
9
|
import type { TrialSettings } from "../format/trial-env";
|
|
10
10
|
import type { DatasetInfo } from "./dataset";
|
|
@@ -17,8 +17,8 @@ import { Refusal } from "./refusal";
|
|
|
17
17
|
*/
|
|
18
18
|
export const ENGINE_HOSTS = ["openrouter.ai"] as const;
|
|
19
19
|
|
|
20
|
-
/** Each phase's limit when neither `
|
|
21
|
-
export const LIMIT_DEFAULTS: ResolvedLimits = { setup: "10m",
|
|
20
|
+
/** Each phase's limit when neither `target.ts` nor `--limit` gives one. */
|
|
21
|
+
export const LIMIT_DEFAULTS: ResolvedLimits = { setup: "10m", workflow: "30m", after: "10m" };
|
|
22
22
|
|
|
23
23
|
/** What shapes a column's trials beyond its parameters: its sandbox and limits, resolved. */
|
|
24
24
|
export type ResolvedSettings = { sandbox: ResolvedSandbox; limits: ResolvedLimits };
|
|
@@ -33,13 +33,18 @@ export function durationMs(text: string): number {
|
|
|
33
33
|
return Number(match[1]) * UNIT[match[2] as keyof typeof UNIT];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/** `--limit {phase}={duration}`, each repeatable: a phase once, of setup,
|
|
36
|
+
/** `--limit {phase}={duration}`, each repeatable: a phase once, of setup, workflow and after. */
|
|
37
37
|
export function readLimits(given: readonly string[]): Limits {
|
|
38
38
|
const limits: Limits = {};
|
|
39
39
|
for (const each of given) {
|
|
40
40
|
const at = each.indexOf("=");
|
|
41
41
|
const phase = at > 0 ? each.slice(0, at) : "";
|
|
42
42
|
const duration = at > 0 ? each.slice(at + 1) : "";
|
|
43
|
+
if (phase === "run") {
|
|
44
|
+
throw new Refusal(
|
|
45
|
+
`--limit run is now --limit workflow: --limit workflow=${duration || "{duration}"}`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
43
48
|
if (!(LIMIT_PHASES as readonly string[]).includes(phase)) {
|
|
44
49
|
throw new Refusal(
|
|
45
50
|
`--limit ${each}: give {phase}={duration}, the phase ${LIMIT_PHASES.join(", ")}`,
|
|
@@ -56,9 +61,9 @@ export function readLimits(given: readonly string[]): Limits {
|
|
|
56
61
|
return limits;
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
/** A `
|
|
60
|
-
export function resolveSettings(
|
|
61
|
-
const given =
|
|
64
|
+
/** A `target.ts`'s sandbox and limits, every part given: `--limit` over the file over the defaults. */
|
|
65
|
+
export function resolveSettings(target: TargetFile, limits: Limits = {}): ResolvedSettings {
|
|
66
|
+
const given = target.sandbox ?? {};
|
|
62
67
|
const network = {
|
|
63
68
|
agents: [...(given.network?.agents ?? [])],
|
|
64
69
|
code: [...(given.network?.code ?? [])],
|
|
@@ -70,7 +75,7 @@ export function resolveSettings(trial: TrialFile, limits: Limits = {}): Resolved
|
|
|
70
75
|
given.by === "workflow"
|
|
71
76
|
? { by: "workflow", network }
|
|
72
77
|
: { by: "lab", provider: given.provider ?? "srt", network };
|
|
73
|
-
return { sandbox, limits: { ...LIMIT_DEFAULTS, ...
|
|
78
|
+
return { sandbox, limits: { ...LIMIT_DEFAULTS, ...target.limits, ...limits } };
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
/** What the trial's process is told: the dataset, its limits in ms and the hosts its code may reach. */
|
|
@@ -79,7 +84,7 @@ export function trialSettingsOf(info: DatasetInfo, settings: ResolvedSettings):
|
|
|
79
84
|
dataset: info.name,
|
|
80
85
|
datasetDir: info.evalDir,
|
|
81
86
|
setupMs: durationMs(settings.limits.setup),
|
|
82
|
-
|
|
87
|
+
workflowMs: durationMs(settings.limits.workflow),
|
|
83
88
|
afterMs: durationMs(settings.limits.after),
|
|
84
89
|
codeHosts: [...new Set([...settings.sandbox.network.code, ...ENGINE_HOSTS])],
|
|
85
90
|
};
|
|
@@ -87,14 +92,14 @@ export function trialSettingsOf(info: DatasetInfo, settings: ResolvedSettings):
|
|
|
87
92
|
|
|
88
93
|
/**
|
|
89
94
|
* The limit of what the lab runs in your checkout's helper after a trial: code graders, `facts`,
|
|
90
|
-
* `compare` and `capture.ts`, under `
|
|
95
|
+
* `compare` and `capture.ts`, under `target.ts`'s `limits.after`.
|
|
91
96
|
*/
|
|
92
97
|
export function afterMsOf(info: DatasetInfo): number {
|
|
93
|
-
return durationMs(info.
|
|
98
|
+
return durationMs(info.target.limits?.after ?? LIMIT_DEFAULTS.after);
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
/** `awf run --timeout`: a backstop the engine records as `timed-out`, past every phase's own. */
|
|
97
102
|
export function backstopOf(settings: TrialSettings): string {
|
|
98
|
-
const ms = settings.setupMs + settings.
|
|
103
|
+
const ms = settings.setupMs + settings.workflowMs + settings.afterMs + 60_000;
|
|
99
104
|
return `${Math.ceil(ms / 1000)}s`;
|
|
100
105
|
}
|
package/src/lab/trial.ts
CHANGED
|
@@ -13,19 +13,13 @@ import { TRIAL_ENV } from "../format/trial-env";
|
|
|
13
13
|
import { type AwfBin, loginRefused, type Runner, withoutCallingSession } from "../shared/runner";
|
|
14
14
|
import { blame, harnessStop, readTrialLines } from "./blame";
|
|
15
15
|
import { type BoxSpec, boxNetwork, boxReach, boxSpec, hiddenOf, writeBoxSpec } from "./box";
|
|
16
|
-
import {
|
|
16
|
+
import type { CaseInfo, DatasetInfo } from "./dataset";
|
|
17
17
|
import { type FactsReader, recordOf } from "./facts";
|
|
18
|
-
import {
|
|
19
|
-
buildCase,
|
|
20
|
-
keepFiles,
|
|
21
|
-
makeTrialFolders,
|
|
22
|
-
type Needle,
|
|
23
|
-
searchFolder,
|
|
24
|
-
searchText,
|
|
25
|
-
} from "./folders";
|
|
18
|
+
import { keepFiles, makeTrialFolders, type Needle, searchFolder, searchText } from "./folders";
|
|
26
19
|
import { decidersOf, gradeTrial, type LabGrader } from "./grading";
|
|
27
20
|
import type { FolderSetup } from "./inspect";
|
|
28
21
|
import { checkReach, type OpenedAgent } from "./reach";
|
|
22
|
+
import type { BuiltCase } from "./reuse";
|
|
29
23
|
import { agentsOpenedOf, runFactsOf, turnsOf } from "./run-logs";
|
|
30
24
|
import {
|
|
31
25
|
appendScore,
|
|
@@ -71,34 +65,36 @@ export type TrialLab = {
|
|
|
71
65
|
|
|
72
66
|
export type TrialDone = { record: TrialRecord; score?: ScoreRecord; dir: string };
|
|
73
67
|
|
|
74
|
-
/** What a column's trials run under: its `
|
|
68
|
+
/** What a column's trials run under: its `target.ts`, parameters, version and settings. */
|
|
75
69
|
export type ColumnShape = {
|
|
76
|
-
/** The column's `
|
|
77
|
-
|
|
70
|
+
/** The column's `target.ts`: your checkout's, or the same file in a folder `--against` names. */
|
|
71
|
+
targetScript: string;
|
|
78
72
|
params: Params;
|
|
79
|
-
/** The column's version: its `
|
|
73
|
+
/** The column's version: its `target.ts`'s, or the loop's id of its code. */
|
|
80
74
|
version: string;
|
|
81
|
-
/** Its `
|
|
75
|
+
/** Its `target.ts`'s sandbox and limits, resolved, `--limit` over them. */
|
|
82
76
|
settings: ResolvedSettings;
|
|
83
77
|
/** The trial's reuse key, from its built case's digest; absent, never reused. */
|
|
84
78
|
reuseOf?: (input: string) => string | undefined;
|
|
85
79
|
};
|
|
86
80
|
|
|
87
81
|
/**
|
|
88
|
-
* One trial: the case folder
|
|
89
|
-
* run on `
|
|
90
|
-
* facts graded; then both folders deleted.
|
|
82
|
+
* One trial: the case folder copied as the run started, without the key, the marker looked for,
|
|
83
|
+
* the folder's own `awf` run on `target.ts`, its ending blamed, its agents' reach checked, the
|
|
84
|
+
* marker looked for again, the facts graded; then both folders deleted.
|
|
91
85
|
*/
|
|
92
86
|
export async function runTrial(
|
|
93
87
|
lab: TrialLab,
|
|
94
88
|
folder: FolderSetup,
|
|
95
89
|
info: CaseInfo,
|
|
90
|
+
/** The case as the run started. */
|
|
91
|
+
built: BuiltCase,
|
|
96
92
|
column: number,
|
|
97
93
|
trial: number,
|
|
98
94
|
shape: ColumnShape,
|
|
99
95
|
): Promise<TrialDone> {
|
|
100
96
|
const { workspace, dataset } = lab;
|
|
101
|
-
const {
|
|
97
|
+
const { targetScript, params, version, settings: shaped } = shape;
|
|
102
98
|
const { sandbox } = shaped;
|
|
103
99
|
const started = Date.now();
|
|
104
100
|
const dir = trialDirOf(workspace.store, lab.run, info.name, column, trial);
|
|
@@ -112,14 +108,14 @@ export async function runTrial(
|
|
|
112
108
|
? join(folders.parent, "trial", "trial.jsonl")
|
|
113
109
|
: trialFileOf(workspace.labHome);
|
|
114
110
|
try {
|
|
115
|
-
|
|
116
|
-
const input =
|
|
111
|
+
cpSync(built.dir, folders.dir, { recursive: true });
|
|
112
|
+
const { input } = built;
|
|
117
113
|
keepInput(workspace.store, input, folders.dir);
|
|
118
114
|
const reuse = shape.reuseOf?.(input);
|
|
119
115
|
const needle: Needle = { marker: info.key.marker, keyFiles: info.keyFiles };
|
|
120
116
|
const base: TrialRecord = {
|
|
121
117
|
kind: TRIAL_KIND,
|
|
122
|
-
|
|
118
|
+
labRun: lab.run,
|
|
123
119
|
dataset: dataset.name,
|
|
124
120
|
case: info.name,
|
|
125
121
|
column,
|
|
@@ -176,7 +172,7 @@ export async function runTrial(
|
|
|
176
172
|
[TRIAL_ENV.params]: JSON.stringify(params),
|
|
177
173
|
};
|
|
178
174
|
const result = await lab.runner({
|
|
179
|
-
workflow:
|
|
175
|
+
workflow: targetScript,
|
|
180
176
|
cwd: folders.scratch,
|
|
181
177
|
timeout: backstopOf(settings),
|
|
182
178
|
argv: [],
|
|
@@ -264,7 +260,7 @@ export async function runTrial(
|
|
|
264
260
|
const record: TrialRecord = {
|
|
265
261
|
...base,
|
|
266
262
|
...(blamed.workflow ? { workflow: blamed.workflow } : {}),
|
|
267
|
-
...(run ? {
|
|
263
|
+
...(run ? { trialId: run.runId, runOutcome: run.outcome } : {}),
|
|
268
264
|
...(run && run.outcome !== "completed" ? { runReason: run.reason } : {}),
|
|
269
265
|
models: accounting ? accounting.byModel.map((m) => m.model) : [],
|
|
270
266
|
ms: accounting?.wallMs ?? result.ms,
|
package/src/lab/usage.ts
CHANGED
|
@@ -119,6 +119,7 @@ const GONE: Record<string, string> = {
|
|
|
119
119
|
"--proposer is gone: a loop's proposer is its entry's proposer, in loops of evals/awf-lab.config.ts or the local file",
|
|
120
120
|
"--no-spread":
|
|
121
121
|
"--no-spread is gone: spread: false in the loop's entry, in loops of evals/awf-lab.config.ts or the local file",
|
|
122
|
+
"--rounds": "--rounds is now --tries: loop run {name} --tries {n}",
|
|
122
123
|
};
|
|
123
124
|
|
|
124
125
|
/** The loop's flags that are its entry's fields now, each with the field. */
|
|
@@ -84,7 +84,10 @@ function workflowGrader(lab: WorkflowGraderLab, spec: WorkflowSpec): LabGrader {
|
|
|
84
84
|
return {
|
|
85
85
|
...graderWorkflow(
|
|
86
86
|
{ runner: lab.runner, runRoot: lab.runRoot, now: lab.now, awf: lab.awf },
|
|
87
|
-
{
|
|
87
|
+
{
|
|
88
|
+
...spec,
|
|
89
|
+
timeout: spec.timeout ?? lab.dataset.target.limits?.workflow ?? LIMIT_DEFAULTS.workflow,
|
|
90
|
+
},
|
|
88
91
|
),
|
|
89
92
|
version: spec.version,
|
|
90
93
|
};
|
package/src/lab/workspace.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type HelperPlace,
|
|
11
11
|
LOCAL_FILE,
|
|
12
12
|
readLocalFile,
|
|
13
|
-
|
|
13
|
+
TARGET_FILE,
|
|
14
14
|
} from "./eval-files";
|
|
15
15
|
import { gitTop, projectOf } from "./git";
|
|
16
16
|
import { Refusal } from "./refusal";
|
|
@@ -24,11 +24,11 @@ export const DEFAULT = "default";
|
|
|
24
24
|
/** A dataset as the project names it: an eval folder and a data folder, and its own values. */
|
|
25
25
|
export type DatasetRef = {
|
|
26
26
|
name: string;
|
|
27
|
-
/** The eval folder: `
|
|
27
|
+
/** The eval folder: `target.ts`, `grading.ts`, `graders/`, `capture.ts`. */
|
|
28
28
|
eval: Traced<string>;
|
|
29
29
|
/** The data folder: `cases/`, and optionally `shared/`. */
|
|
30
30
|
data: Traced<string>;
|
|
31
|
-
/** Values over `
|
|
31
|
+
/** Values over `target.ts`'s defaults, by parameter. */
|
|
32
32
|
params: Record<string, Traced<string>>;
|
|
33
33
|
/** Where a copy of the dataset's records is kept: `{records}/{first commit}`. */
|
|
34
34
|
records?: Traced<string>;
|
|
@@ -126,7 +126,7 @@ function folders(dir: string): string[] {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
* The folders of `evals/` that are datasets of their own: each with a `
|
|
129
|
+
* The folders of `evals/` that are datasets of their own: each with a `target.ts` and `cases/`. A
|
|
130
130
|
* folder still holding the files they replaced is refused, saying so.
|
|
131
131
|
*/
|
|
132
132
|
export function folderDatasets(evals: string): { name: string; dir: string }[] {
|
|
@@ -137,11 +137,12 @@ export function folderDatasets(evals: string): { name: string; dir: string }[] {
|
|
|
137
137
|
}
|
|
138
138
|
return folders(evals).flatMap((name) => {
|
|
139
139
|
const dir = join(evals, name);
|
|
140
|
-
if (!existsSync(join(dir,
|
|
140
|
+
if (!existsSync(join(dir, TARGET_FILE))) {
|
|
141
|
+
if (existsSync(join(dir, "trial.ts"))) throw new Refusal(renamedTrial(dir));
|
|
141
142
|
for (const old of ["dataset.json", "env.ts", "graders.ts"]) {
|
|
142
143
|
if (existsSync(join(dir, old))) {
|
|
143
144
|
throw new Refusal(
|
|
144
|
-
`${join(dir, old)}: dataset.json, env.ts and graders.ts are replaced by
|
|
145
|
+
`${join(dir, old)}: dataset.json, env.ts and graders.ts are replaced by target.ts (defineTarget) and grading.ts (defineGrading)`,
|
|
145
146
|
);
|
|
146
147
|
}
|
|
147
148
|
}
|
|
@@ -151,6 +152,10 @@ export function folderDatasets(evals: string): { name: string; dir: string }[] {
|
|
|
151
152
|
});
|
|
152
153
|
}
|
|
153
154
|
|
|
155
|
+
function renamedTrial(dir: string): string {
|
|
156
|
+
return `${join(dir, "trial.ts")}: trial.ts is renamed ${TARGET_FILE}, defineTrial defineTarget and limits.run limits.workflow`;
|
|
157
|
+
}
|
|
158
|
+
|
|
154
159
|
/**
|
|
155
160
|
* The project's names: in the store, `{main checkout}-{first commit}`; in a records folder, its
|
|
156
161
|
* first commit alone, which every clone shares whatever its folder is called.
|
|
@@ -177,7 +182,7 @@ function checkIgnore(project: string, evals: string, file: string, globs: readon
|
|
|
177
182
|
);
|
|
178
183
|
}
|
|
179
184
|
const trial = folders(evals)
|
|
180
|
-
.map((name) => relative(project, join(evals, name,
|
|
185
|
+
.map((name) => relative(project, join(evals, name, TARGET_FILE)))
|
|
181
186
|
.find((path) => new Bun.Glob(clean).match(path) || path.startsWith(`${clean}/`));
|
|
182
187
|
if (trial) {
|
|
183
188
|
throw new Refusal(`${file}: ignore ${glob} takes in ${trial}, which shapes every trial`);
|
|
@@ -313,9 +318,11 @@ function datasetRefs(args: {
|
|
|
313
318
|
};
|
|
314
319
|
const evalDir = place("eval");
|
|
315
320
|
const dataDir = place("data");
|
|
316
|
-
if (!existsSync(join(evalDir.value,
|
|
321
|
+
if (!existsSync(join(evalDir.value, TARGET_FILE))) {
|
|
322
|
+
if (existsSync(join(evalDir.value, "trial.ts")))
|
|
323
|
+
throw new Refusal(renamedTrial(evalDir.value));
|
|
317
324
|
throw new Refusal(
|
|
318
|
-
`${evalDir.from}: dataset ${name}'s eval folder ${evalDir.value} has no ${
|
|
325
|
+
`${evalDir.from}: dataset ${name}'s eval folder ${evalDir.value} has no ${TARGET_FILE}`,
|
|
319
326
|
);
|
|
320
327
|
}
|
|
321
328
|
if (!inside(root, evalDir.value)) {
|
|
@@ -17,7 +17,7 @@ const PROMPT = `You are the proposer in a loop that improves a workflow against
|
|
|
17
17
|
- \`bundle/brief.md\`: the operator's brief: what to improve, and what is known about the problem. Read it first and follow it.
|
|
18
18
|
- \`bundle/feedback.json\`: how the current code did on each tuning case and trial: its facts; its run facts, from the run's own record (\`_turns\`, \`_turns_{outcome}\`, \`_turns_by_{agent}\`), and its time and each stage's in ms, which say where a slow or stopped trial spent its time; its outcome; and every grader's verdict, numbers, reasons and parts.
|
|
19
19
|
- \`bundle/history.json\`: every earlier try, its change, its prediction and what the comparison decided. Do not repeat a discarded idea unchanged.
|
|
20
|
-
- \`bundle/rules.json\`: how a try is judged, the
|
|
20
|
+
- \`bundle/rules.json\`: how a try is judged, the budget left, and \`edit\`: the files you may change, globs relative to \`code/{edit.root}\`. A file may change only when \`allow\` matches it and \`deny\` doesn't, and never one \`alwaysDenied\` names; a try that changes any other is refused before it runs. \`unsteady\`, when given, lists the cases that came out differently between two runs of the unchanged start, so their outcome moves on its own: weigh what they show as noise.
|
|
21
21
|
- \`code/\`: a copy of the project's code, the best so far. \`code/evals/\` holds how the dataset is measured and is read-only.
|
|
22
22
|
|
|
23
23
|
Change only files \`edit\` allows in \`code/\`, and nothing else anywhere. Your shell is your only tool: read and write files with it.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// How two columns' per-case numbers become a
|
|
1
|
+
// How two columns' per-case numbers become a decision, for `better.paired` in `env/compare.ts`.
|
|
2
2
|
export { compareMetric, type PairedOptions, pairedComparison, perCase } from "./paired";
|
|
3
|
-
export type { CaseScore, ComparedMetric,
|
|
3
|
+
export type { CaseScore, ComparedMetric, Decision, MetricSpec } from "./types";
|
|
@@ -4,8 +4,8 @@ import type {
|
|
|
4
4
|
ComparedMetric,
|
|
5
5
|
Comparison,
|
|
6
6
|
ComparisonInput,
|
|
7
|
+
Decision,
|
|
7
8
|
MetricSpec,
|
|
8
|
-
Verdict,
|
|
9
9
|
} from "./types";
|
|
10
10
|
|
|
11
11
|
/** Below this many paired cases no interval is given, only cases won, tied and lost. */
|
|
@@ -179,7 +179,7 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
179
179
|
if (!(margin >= 0)) throw new Error(`${metric}'s margin is ${margin}; a margin is 0 or more`);
|
|
180
180
|
}
|
|
181
181
|
return {
|
|
182
|
-
compare(input):
|
|
182
|
+
compare(input): Decision {
|
|
183
183
|
if (!(Number.isInteger(input.planned) && input.planned >= 1)) {
|
|
184
184
|
throw new Error(`planned is a count of cases, from 1: ${input.planned}`);
|
|
185
185
|
}
|
|
@@ -208,8 +208,8 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
208
208
|
const primary = byName.get(options.primary)!;
|
|
209
209
|
const n = primary.cases;
|
|
210
210
|
const counts = `won ${primary.won}, tied ${primary.tied}, lost ${primary.lost}`;
|
|
211
|
-
const
|
|
212
|
-
|
|
211
|
+
const decision = (d: Decision["decision"], stop: boolean, reason: string): Decision => ({
|
|
212
|
+
decision: d,
|
|
213
213
|
stop,
|
|
214
214
|
reason,
|
|
215
215
|
metrics,
|
|
@@ -235,12 +235,12 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
235
235
|
if (n < FEWEST) {
|
|
236
236
|
const few = `${n} ${n === 1 ? "case" : "cases"} with ${options.primary}: too few for an interval; ${counts}`;
|
|
237
237
|
return last
|
|
238
|
-
?
|
|
239
|
-
:
|
|
238
|
+
? decision("undecided", true, `${few}; ${more(FEWEST - n)} would give one`)
|
|
239
|
+
: decision("undecided", false, `${few}; ${pending}`);
|
|
240
240
|
}
|
|
241
241
|
const primaryGain = gainInterval(primary, primarySpec)!;
|
|
242
242
|
if (primaryGain[1] < 0) {
|
|
243
|
-
return
|
|
243
|
+
return decision("worse", true, `stopped, looked worse: ${shown(primary)}`);
|
|
244
244
|
}
|
|
245
245
|
const guardState = guards.map((g) => {
|
|
246
246
|
const m = byName.get(g.metric)!;
|
|
@@ -254,7 +254,7 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
254
254
|
});
|
|
255
255
|
const failed = guardState.find((g) => g.failed);
|
|
256
256
|
if (failed) {
|
|
257
|
-
return
|
|
257
|
+
return decision(
|
|
258
258
|
"worse",
|
|
259
259
|
true,
|
|
260
260
|
`stopped, ${failed.m.name} worse by more than ${failed.margin}: ${shown(failed.m)}`,
|
|
@@ -277,7 +277,7 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
277
277
|
const k = Math.ceil(m.cases * ((high - low) / 2 / room) ** 2) - m.cases;
|
|
278
278
|
return `about ${more(Math.max(1, k))} at this spread would show ${m.name} within ${margin}`;
|
|
279
279
|
});
|
|
280
|
-
if (look < 0) return
|
|
280
|
+
if (look < 0) return decision("undecided", false, `${shown(primary)} ${pending}`);
|
|
281
281
|
|
|
282
282
|
const c = obrienFleming(
|
|
283
283
|
looks.map((l) => l / input.planned),
|
|
@@ -302,7 +302,7 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
302
302
|
: unproven.length > 0
|
|
303
303
|
? `not shown within margin: ${unproven.join(", ")}`
|
|
304
304
|
: undefined;
|
|
305
|
-
if (past && !blocked) return
|
|
305
|
+
if (past && !blocked) return decision("better", true, `better at ${at}: ${shown(primary)}`);
|
|
306
306
|
// At the last look, what would settle it: the cases the rule itself can count.
|
|
307
307
|
const settle = (bound: boolean) => {
|
|
308
308
|
const clauses = [
|
|
@@ -319,7 +319,7 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
319
319
|
return clauses.length > 0 ? `; ${clauses.join("; ")}` : "";
|
|
320
320
|
};
|
|
321
321
|
if (!last && !past && options.minGain !== undefined && primaryGain[1] < options.minGain) {
|
|
322
|
-
return
|
|
322
|
+
return decision(
|
|
323
323
|
"undecided",
|
|
324
324
|
true,
|
|
325
325
|
`stopped at ${at}, no gain of ${options.minGain} in reach: ${shown(primary)}; ${counts}`,
|
|
@@ -327,7 +327,7 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
327
327
|
}
|
|
328
328
|
if (!last) {
|
|
329
329
|
const why = past ? `past the bound, but ${blocked}` : `not past the bound at ${at}`;
|
|
330
|
-
return
|
|
330
|
+
return decision("undecided", false, `${shown(primary)} ${why}; ${pending}`);
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
// The plan has run. The tie-breakers go in order, each one-sided on the primary: a better
|
|
@@ -349,14 +349,14 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
349
349
|
}
|
|
350
350
|
const decided = `decided by ${shown(m)}, past its margin of ${margin}, with ${shown(primary)}`;
|
|
351
351
|
if (mayBetter && gain[0] > margin) {
|
|
352
|
-
if (unproven.length === 0) return
|
|
353
|
-
return
|
|
352
|
+
if (unproven.length === 0) return decision("better", true, decided);
|
|
353
|
+
return decision(
|
|
354
354
|
"undecided",
|
|
355
355
|
true,
|
|
356
356
|
`${decided}, but not shown within margin: ${unproven.join(", ")}${settle(false)}`,
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
|
-
if (mayWorse && gain[1] < -margin) return
|
|
359
|
+
if (mayWorse && gain[1] < -margin) return decision("worse", true, decided);
|
|
360
360
|
mayBetter &&= gain[0] >= -margin;
|
|
361
361
|
mayWorse &&= gain[1] <= margin;
|
|
362
362
|
if (!mayBetter || !mayWorse)
|
|
@@ -365,7 +365,7 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
365
365
|
}
|
|
366
366
|
const why = notes.length > 0 ? `; ${notes.join("; ")}` : "";
|
|
367
367
|
if (past)
|
|
368
|
-
return
|
|
368
|
+
return decision(
|
|
369
369
|
"undecided",
|
|
370
370
|
true,
|
|
371
371
|
`${shown(primary)} past the bound, but ${blocked}${settle(false)}`,
|
|
@@ -375,23 +375,23 @@ export function pairedComparison(options: PairedOptions): Comparison {
|
|
|
375
375
|
primaryGain[0] >= -equivalence &&
|
|
376
376
|
primaryGain[1] <= equivalence;
|
|
377
377
|
if (equivalent) {
|
|
378
|
-
return
|
|
378
|
+
return decision("tie", true, `within ±${equivalence}: ${shown(primary)}; ${counts}${why}`);
|
|
379
379
|
}
|
|
380
380
|
if (primaryGain[0] > 0) {
|
|
381
|
-
return
|
|
381
|
+
return decision(
|
|
382
382
|
"undecided",
|
|
383
383
|
true,
|
|
384
384
|
`${shown(primary)}: a gain, but not past the bound that planned looks require${settle(true)}`,
|
|
385
385
|
);
|
|
386
386
|
}
|
|
387
387
|
if (equivalence !== undefined) {
|
|
388
|
-
return
|
|
388
|
+
return decision(
|
|
389
389
|
"undecided",
|
|
390
390
|
true,
|
|
391
391
|
`no difference shown, nor one within ±${equivalence}: ${shown(primary)}; ${counts}${why}`,
|
|
392
392
|
);
|
|
393
393
|
}
|
|
394
|
-
return
|
|
394
|
+
return decision("tie", true, `no difference shown: ${shown(primary)}; ${counts}`);
|
|
395
395
|
},
|
|
396
396
|
};
|
|
397
397
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// How two columns' per-case numbers become a
|
|
1
|
+
// How two columns' per-case numbers become a decision. Knows nothing of one workflow's domain: the
|
|
2
2
|
// caller names the metrics, and this reads only their numbers.
|
|
3
3
|
|
|
4
4
|
/** One number each trial gives. */
|
|
@@ -48,8 +48,8 @@ export type ComparedMetric = {
|
|
|
48
48
|
* `undecided` with `stop` means the plan ran out without an answer, as when too few cases are won,
|
|
49
49
|
* or the rule stopped early because more cases could not give an answer worth having.
|
|
50
50
|
*/
|
|
51
|
-
export type
|
|
52
|
-
|
|
51
|
+
export type Decision = {
|
|
52
|
+
decision: "better" | "worse" | "tie" | "undecided";
|
|
53
53
|
/** Whether a run should run no more trials of this pair. */
|
|
54
54
|
stop: boolean;
|
|
55
55
|
/** One sentence a person reads first. */
|
|
@@ -71,5 +71,5 @@ export type ComparisonInput = {
|
|
|
71
71
|
|
|
72
72
|
/** A rule over two columns' numbers, which `better.paired` wraps as a comparison export. */
|
|
73
73
|
export type Comparison = {
|
|
74
|
-
compare(input: ComparisonInput):
|
|
74
|
+
compare(input: ComparisonInput): Decision;
|
|
75
75
|
};
|
package/src/write-schemas.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// bun packages/lab/src/write-schemas.ts — regenerates schema/*.schema.json from the formats.
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { LAB_SCHEMA_FILES, renderLabSchemaFile } from "./format/schema-files";
|
|
4
4
|
|
|
5
5
|
const SCHEMA_DIR = join(import.meta.dir, "..", "schema");
|
|
6
6
|
|
|
7
|
-
for (const name of Object.keys(
|
|
8
|
-
await Bun.write(join(SCHEMA_DIR, name),
|
|
7
|
+
for (const name of Object.keys(LAB_SCHEMA_FILES) as (keyof typeof LAB_SCHEMA_FILES)[]) {
|
|
8
|
+
await Bun.write(join(SCHEMA_DIR, name), renderLabSchemaFile(name));
|
|
9
9
|
console.log(`wrote schema/${name}`);
|
|
10
10
|
}
|
|
File without changes
|
|
File without changes
|