@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
package/src/env/compare.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type CaseScore,
|
|
3
|
+
type Decision,
|
|
3
4
|
type MetricSpec,
|
|
4
5
|
type PairedOptions,
|
|
5
6
|
pairedComparison,
|
|
6
|
-
type Verdict,
|
|
7
7
|
} from "../shared/compare";
|
|
8
8
|
|
|
9
|
-
// What "better" means for a dataset: `
|
|
9
|
+
// What "better" means for a dataset: `compare` in its grading.ts. The lab gives
|
|
10
10
|
// it every trial of the reference column and of one other, and it says whether the other is
|
|
11
11
|
// better, worse, a tie or undecided, with a reason and whether more trials could change that.
|
|
12
12
|
|
|
13
|
-
/** What a comparison export carries, checked by the helper that loads `
|
|
14
|
-
export const COMPARISON_KIND = "awf.
|
|
13
|
+
/** What a comparison export carries, checked by the helper that loads `grading.ts`. */
|
|
14
|
+
export const COMPARISON_KIND = "awf.lab-comparison/0";
|
|
15
15
|
|
|
16
16
|
/** One trial, as a comparison sees it. */
|
|
17
17
|
export type ComparedTrial = {
|
|
@@ -51,16 +51,16 @@ export type Room = { canWin: number; needed: number; what: string };
|
|
|
51
51
|
|
|
52
52
|
export type CaseComparison = {
|
|
53
53
|
readonly kind: typeof COMPARISON_KIND;
|
|
54
|
-
compare(call: ComparisonCall):
|
|
54
|
+
compare(call: ComparisonCall): Decision;
|
|
55
55
|
/** Optional: undefined, or no `room`, when the rule can't tell from the start alone. */
|
|
56
56
|
room?(call: RoomCall): Room | undefined;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export type {
|
|
59
|
+
export type { Decision };
|
|
60
60
|
|
|
61
61
|
/** A comparison of your own: `compare` gets both columns' trials and returns the verdict. */
|
|
62
62
|
export function defineComparison(options: {
|
|
63
|
-
compare(call: ComparisonCall):
|
|
63
|
+
compare(call: ComparisonCall): Decision;
|
|
64
64
|
/** How many cases a column could still win against the start, and how many it must. */
|
|
65
65
|
room?(call: RoomCall): Room | undefined;
|
|
66
66
|
}): CaseComparison {
|
package/src/env/fetch.ts
CHANGED
|
@@ -45,7 +45,7 @@ export function installFetch(codeHosts: readonly string[] = []): void {
|
|
|
45
45
|
throw refuse(
|
|
46
46
|
`${request.method} ${request.url}`,
|
|
47
47
|
"host",
|
|
48
|
-
`reached ${url.hostname}: add a route, list it in
|
|
48
|
+
`reached ${url.hostname}: add a route, list it in target.ts's sandbox.network.code, or trial.mockFetch.allow it`,
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
found.route.calls += 1;
|
package/src/env/files.ts
CHANGED
|
@@ -2,23 +2,23 @@ import type { DatasetEntry, LoopEntry } from "../format/settings";
|
|
|
2
2
|
import { checkVersion } from "../shared/version";
|
|
3
3
|
import type { CaseComparison } from "./compare";
|
|
4
4
|
import type { CodeGrader, Reads } from "./grader";
|
|
5
|
-
import type { Facts, RecordOf,
|
|
5
|
+
import type { Facts, RecordOf, TargetDefinition } from "./index";
|
|
6
6
|
|
|
7
7
|
// What `grading.ts` and `evals/awf-lab.config.ts` export, and what marks each value the lab's
|
|
8
8
|
// helper hands over. The marks live in code, never in the files a person writes.
|
|
9
9
|
|
|
10
|
-
/** The spec `
|
|
11
|
-
export const
|
|
10
|
+
/** The spec `defineTarget` was given, on what it returns: what the lab reads of `target.ts`. */
|
|
11
|
+
export const TARGET_SPEC = Symbol.for("agentswf.lab.target");
|
|
12
12
|
const REQUIRED = Symbol.for("agentswf.lab.required");
|
|
13
13
|
const DESCRIBING = Symbol.for("agentswf.lab.describing");
|
|
14
14
|
|
|
15
|
-
export const GRADING_KIND = "awf.
|
|
16
|
-
export const LAB_KIND = "awf.
|
|
17
|
-
export const WORKFLOW_GRADER_KIND = "awf.
|
|
18
|
-
export const SENTENCES_KIND = "awf.
|
|
15
|
+
export const GRADING_KIND = "awf.lab-grading/0";
|
|
16
|
+
export const LAB_KIND = "awf.lab-settings/0";
|
|
17
|
+
export const WORKFLOW_GRADER_KIND = "awf.lab-workflow-grader/0";
|
|
18
|
+
export const SENTENCES_KIND = "awf.lab-sentences/0";
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Whether these files are being read by the lab's helper, rather than run: `
|
|
21
|
+
* Whether these files are being read by the lab's helper, rather than run: `defineTarget` then
|
|
22
22
|
* makes no workflow, and loads no engine.
|
|
23
23
|
*/
|
|
24
24
|
export function describing(): boolean {
|
|
@@ -29,14 +29,14 @@ export function startDescribing(): void {
|
|
|
29
29
|
(globalThis as { [DESCRIBING]?: boolean })[DESCRIBING] = true;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/** A parameter `
|
|
32
|
+
/** A parameter `target.ts` declares with no default: a run is refused until it is given a value. */
|
|
33
33
|
export type RequiredParam<T extends string = string> = {
|
|
34
34
|
readonly [REQUIRED]: true;
|
|
35
35
|
/** Never set: carries the value's type. */
|
|
36
36
|
readonly value?: T;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
/** A parameter with no default, in `
|
|
39
|
+
/** A parameter with no default, in `defineTarget`'s `params`. */
|
|
40
40
|
export function required<T extends string = string>(): RequiredParam<T> {
|
|
41
41
|
return { [REQUIRED]: true };
|
|
42
42
|
}
|
|
@@ -167,7 +167,7 @@ export function sentences(options: {
|
|
|
167
167
|
|
|
168
168
|
export type Grader = CodeGrader | WorkflowGrader | SentencesGrader;
|
|
169
169
|
|
|
170
|
-
export type GradingSpec<T =
|
|
170
|
+
export type GradingSpec<T = TargetDefinition> = {
|
|
171
171
|
/**
|
|
172
172
|
* Turns a trial record into flat facts: strings, numbers, booleans or `null`. The key's `expect`
|
|
173
173
|
* checks them, and graders read them. A plain function of the record, run outside the trial in
|
|
@@ -189,10 +189,10 @@ export type GradingSpec<T = TrialDefinition> = {
|
|
|
189
189
|
export type Grading = GradingSpec<never> & { readonly kind: typeof GRADING_KIND };
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
|
-
* `grading.ts`'s default export: everything that decides a grade. `defineGrading<typeof
|
|
193
|
-
* with `import type
|
|
192
|
+
* `grading.ts`'s default export: everything that decides a grade. `defineGrading<typeof target>`,
|
|
193
|
+
* with `import type target from "./target"`, types the record `facts` reads.
|
|
194
194
|
*/
|
|
195
|
-
export function defineGrading<T =
|
|
195
|
+
export function defineGrading<T = TargetDefinition>(spec: GradingSpec<T>): Grading {
|
|
196
196
|
return { ...(spec as GradingSpec<never>), kind: GRADING_KIND };
|
|
197
197
|
}
|
|
198
198
|
|
package/src/env/grade-helper.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
SENTENCES_KIND,
|
|
17
17
|
type SentencesGrader,
|
|
18
18
|
startDescribing,
|
|
19
|
-
|
|
19
|
+
TARGET_SPEC,
|
|
20
20
|
WORKFLOW_GRADER_KIND,
|
|
21
21
|
type WorkflowGrader,
|
|
22
22
|
} from "./files";
|
|
@@ -26,14 +26,14 @@ import { type CodeGrader, GRADER_KIND } from "./grader";
|
|
|
26
26
|
* Runs in a Bun process of its own the lab starts in your checkout, so dataset code never loads
|
|
27
27
|
* into the lab's process. Reads a request file and writes its answer to the file it names:
|
|
28
28
|
*
|
|
29
|
-
* - `describe`: reads `
|
|
29
|
+
* - `describe`: reads `target.ts`, `grading.ts` and `awf-lab.config.ts`, running nothing they
|
|
30
30
|
* define; answers each as JSON, or `{ error }` naming the first that doesn't load.
|
|
31
31
|
* - `facts`: runs `grading.ts`'s `facts` on each trial record; answers `{ facts: [...] }`, each
|
|
32
32
|
* `{ facts }` or `{ problem: { code, reason } }`, or `{ error }` when the file doesn't load.
|
|
33
33
|
* - `grade`: runs one code grader of `grading.ts`; answers `{ grade, version }` or
|
|
34
34
|
* `{ error, version? }`.
|
|
35
35
|
* - `capture`: runs the dataset's `capture.ts` on a real run; answers `{ cases }` or `{ error }`.
|
|
36
|
-
* - `compare`: runs `grading.ts`'s `compare` on two columns' trials; answers `{
|
|
36
|
+
* - `compare`: runs `grading.ts`'s `compare` on two columns' trials; answers `{ decision }`,
|
|
37
37
|
* `{ none: true }` when it has none, or `{ error }`.
|
|
38
38
|
* - `room`: runs its `room` on the start's trials; answers `{ room }`, `{ none: true }` when it has
|
|
39
39
|
* none or can't tell, or `{ error }`.
|
|
@@ -41,7 +41,7 @@ import { type CodeGrader, GRADER_KIND } from "./grader";
|
|
|
41
41
|
type Request =
|
|
42
42
|
| {
|
|
43
43
|
mode: "describe";
|
|
44
|
-
files: {
|
|
44
|
+
files: { target?: string; grading?: string; lab?: string };
|
|
45
45
|
out: string;
|
|
46
46
|
}
|
|
47
47
|
| {
|
|
@@ -221,26 +221,26 @@ async function describeGrading(file: string): Promise<unknown> {
|
|
|
221
221
|
return described;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
async function
|
|
224
|
+
async function describeTarget(file: string): Promise<unknown> {
|
|
225
225
|
const module = (await import(file)) as { default?: Record<symbol, unknown> };
|
|
226
|
-
const spec = module.default?.[
|
|
226
|
+
const spec = module.default?.[TARGET_SPEC];
|
|
227
227
|
if (typeof spec !== "object" || spec === null) {
|
|
228
228
|
throw new Error(
|
|
229
|
-
`${file} has no
|
|
229
|
+
`${file} has no target as its default export: export default defineTarget({ … })`,
|
|
230
230
|
);
|
|
231
231
|
}
|
|
232
232
|
const { version, ...rest } = spec as { version?: unknown };
|
|
233
|
-
// A version function is the one thing of `
|
|
233
|
+
// A version function is the one thing of `target.ts` the lab runs: once, in this checkout.
|
|
234
234
|
let declared: unknown = version;
|
|
235
235
|
if (typeof version === "function") {
|
|
236
236
|
try {
|
|
237
237
|
declared = await version();
|
|
238
238
|
} catch (error) {
|
|
239
|
-
throw new Error(`
|
|
239
|
+
throw new Error(`target: version() threw: ${messageOf(error)}`);
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
return {
|
|
243
|
-
...(asJson(rest, "
|
|
243
|
+
...(asJson(rest, "target") as object),
|
|
244
244
|
...(declared !== undefined ? { version: declared } : {}),
|
|
245
245
|
};
|
|
246
246
|
}
|
|
@@ -259,14 +259,14 @@ if (request.mode === "describe") {
|
|
|
259
259
|
const answered: Record<string, unknown> = {};
|
|
260
260
|
let at = "";
|
|
261
261
|
try {
|
|
262
|
-
const {
|
|
262
|
+
const { target, grading, lab } = request.files;
|
|
263
263
|
if (lab) {
|
|
264
264
|
at = lab;
|
|
265
265
|
answered.lab = await describeLab(lab);
|
|
266
266
|
}
|
|
267
|
-
if (
|
|
268
|
-
at =
|
|
269
|
-
answered.
|
|
267
|
+
if (target) {
|
|
268
|
+
at = target;
|
|
269
|
+
answered.target = await describeTarget(target);
|
|
270
270
|
}
|
|
271
271
|
if (grading) {
|
|
272
272
|
at = grading;
|
|
@@ -286,7 +286,7 @@ if (request.mode === "describe") {
|
|
|
286
286
|
error: `${request.file}'s compare is not a comparison: compare: better.paired({ primary: "passed" })`,
|
|
287
287
|
});
|
|
288
288
|
} else {
|
|
289
|
-
answer({
|
|
289
|
+
answer({ decision: comparison.compare(request.input) });
|
|
290
290
|
}
|
|
291
291
|
} catch (error) {
|
|
292
292
|
answer({ error: error instanceof Error ? error.message : String(error) });
|
package/src/env/grader.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { checkGraderName, readsOf, refuseUnknown } from "./files";
|
|
|
5
5
|
import type { Fact } from "./index";
|
|
6
6
|
|
|
7
7
|
/** What a code grader's export carries, checked by the helper that loads `grading.ts`. */
|
|
8
|
-
export const GRADER_KIND = "awf.
|
|
8
|
+
export const GRADER_KIND = "awf.lab-grader/0";
|
|
9
9
|
|
|
10
10
|
/** What a grader reads: `"facts"`, the facts alone; `"trial"`, also the record and saved files. */
|
|
11
11
|
export type Reads = "facts" | "trial";
|
|
@@ -14,7 +14,10 @@ export type Reads = "facts" | "trial";
|
|
|
14
14
|
export type GradeInput = {
|
|
15
15
|
case: {
|
|
16
16
|
name: string;
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* The built case folder: the dataset's shared files, or those the key's `shared` names, and
|
|
19
|
+
* the case's own, and `input.json`.
|
|
20
|
+
*/
|
|
18
21
|
dir: string;
|
|
19
22
|
// biome-ignore lint/suspicious/noExplicitAny: typed by the reader, as `trial.input` is.
|
|
20
23
|
input: any;
|
package/src/env/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type EnvValue, TRIAL_ENV, type TrialSettings } from "../format/trial-env";
|
|
2
2
|
import type { DatasetError, Gathered, Phase } from "../format/trial-file";
|
|
3
|
-
import { describing, type RequiredParam,
|
|
3
|
+
import { describing, type RequiredParam, TARGET_SPEC } from "./files";
|
|
4
4
|
import { asJson, fileOf, Mocks } from "./mock";
|
|
5
5
|
import { copiedModule } from "./sources";
|
|
6
6
|
import { type HttpRequest, shared, trialParams, trialSettings, writeLine } from "./state";
|
|
@@ -17,11 +17,11 @@ export {
|
|
|
17
17
|
type CaseComparison,
|
|
18
18
|
type ComparedTrial,
|
|
19
19
|
type ComparisonCall,
|
|
20
|
+
type Decision,
|
|
20
21
|
defineComparison,
|
|
21
22
|
type MetricOptions,
|
|
22
23
|
type Room,
|
|
23
24
|
type RoomCall,
|
|
24
|
-
type Verdict,
|
|
25
25
|
} from "./compare";
|
|
26
26
|
export {
|
|
27
27
|
defineGrading,
|
|
@@ -120,7 +120,7 @@ export type TrialRecord<R = unknown, V = unknown> = {
|
|
|
120
120
|
|
|
121
121
|
declare const RECORD: unique symbol;
|
|
122
122
|
|
|
123
|
-
/** The trial record a `
|
|
123
|
+
/** The trial record a `target.ts`'s trials end in, typed from it. */
|
|
124
124
|
export type RecordOf<T> = T extends {
|
|
125
125
|
readonly [RECORD]?: { result: infer R; values: infer V };
|
|
126
126
|
}
|
|
@@ -140,7 +140,7 @@ export type ParamValues<P extends ParamsSpec> = { readonly [K in keyof P]: strin
|
|
|
140
140
|
|
|
141
141
|
type Duration = `${number}${"ms" | "s" | "m" | "h"}`;
|
|
142
142
|
|
|
143
|
-
export type
|
|
143
|
+
export type TargetSpec<M extends WorkflowModule, P extends ParamsSpec, V = undefined> = {
|
|
144
144
|
/**
|
|
145
145
|
* Semver, required: when kept trials go stale. Bump its major or minor, or give it a pre-release
|
|
146
146
|
* tag, for any change to the workflow, `setup`, a fake or anything else a trial runs that should
|
|
@@ -171,15 +171,15 @@ export type TrialSpec<M extends WorkflowModule, P extends ParamsSpec, V = undefi
|
|
|
171
171
|
sockets?: readonly string[];
|
|
172
172
|
};
|
|
173
173
|
};
|
|
174
|
-
/** Each phase's limit: `setup` 10m,
|
|
175
|
-
limits?: { setup?: Duration;
|
|
174
|
+
/** Each phase's limit: `setup` 10m, `workflow` 30m, `after` (evidence and cleanup) 10m unless set. */
|
|
175
|
+
limits?: { setup?: Duration; workflow?: Duration; after?: Duration };
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
|
-
* The workflow `
|
|
179
|
+
* The workflow `defineTarget` makes, which `awf run` loads; opaque to `target.ts`. It carries the
|
|
180
180
|
* types of its record for `defineGrading<typeof trial>`.
|
|
181
181
|
*/
|
|
182
|
-
export type
|
|
182
|
+
export type TargetDefinition<R = unknown, V = unknown> = {
|
|
183
183
|
readonly kind: string;
|
|
184
184
|
readonly meta: { readonly name: string };
|
|
185
185
|
readonly [RECORD]?: { result: R; values: V };
|
|
@@ -187,17 +187,17 @@ export type TrialDefinition<R = unknown, V = unknown> = {
|
|
|
187
187
|
|
|
188
188
|
const NOT_IN_A_TRIAL = `this is a trial, run by awf-lab: \`awf-lab run\` in the project runs its cases, and sets ${TRIAL_ENV.case} and the rest for each trial`;
|
|
189
189
|
|
|
190
|
-
/** How a case becomes a run of one workflow, as `
|
|
191
|
-
export function
|
|
190
|
+
/** How a case becomes a run of one workflow, as `target.ts`'s default export. */
|
|
191
|
+
export function defineTarget<
|
|
192
192
|
M extends WorkflowModule,
|
|
193
193
|
const P extends ParamsSpec = Record<never, never>,
|
|
194
194
|
V = undefined,
|
|
195
|
-
>(spec:
|
|
195
|
+
>(spec: TargetSpec<M, P, V>): TargetDefinition<ResultOf<M>, V> {
|
|
196
196
|
const made = describing()
|
|
197
197
|
? {}
|
|
198
198
|
: defineWorkflow({
|
|
199
199
|
meta: {
|
|
200
|
-
name: trialSettings()?.dataset ? `
|
|
200
|
+
name: trialSettings()?.dataset ? `lab-trial-${trialSettings()?.dataset}` : "lab-trial",
|
|
201
201
|
description: "Runs a workflow on one case of an awf-lab dataset.",
|
|
202
202
|
},
|
|
203
203
|
prepare: () => {
|
|
@@ -206,10 +206,10 @@ export function defineTrial<
|
|
|
206
206
|
},
|
|
207
207
|
// biome-ignore lint/suspicious/noExplicitAny: the engine's context, typed structurally here.
|
|
208
208
|
run: async (wf: any) =>
|
|
209
|
-
(await runInTrial(spec as unknown as
|
|
209
|
+
(await runInTrial(spec as unknown as TargetSpec<M, ParamsSpec, unknown>, wf)) as never,
|
|
210
210
|
});
|
|
211
|
-
Object.defineProperty(made,
|
|
212
|
-
return made as
|
|
211
|
+
Object.defineProperty(made, TARGET_SPEC, { value: spec });
|
|
212
|
+
return made as TargetDefinition<ResultOf<M>, V>;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
|
@@ -405,7 +405,7 @@ async function runCleanups(cleanups: readonly (() => unknown)[]): Promise<void>
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
async function runInTrial<M extends WorkflowModule>(
|
|
408
|
-
spec:
|
|
408
|
+
spec: TargetSpec<M, ParamsSpec, unknown>,
|
|
409
409
|
wf: EngineContext,
|
|
410
410
|
): Promise<EnvValue> {
|
|
411
411
|
const settings = trialSettings();
|
|
@@ -520,7 +520,7 @@ async function runInTrial<M extends WorkflowModule>(
|
|
|
520
520
|
};
|
|
521
521
|
|
|
522
522
|
run.enter("body");
|
|
523
|
-
const body = run.timer("body", settings.
|
|
523
|
+
const body = run.timer("body", settings.workflowMs);
|
|
524
524
|
let module: unknown;
|
|
525
525
|
try {
|
|
526
526
|
module = await body.race(Promise.resolve().then(() => spec.workflow(trial)));
|
|
@@ -550,7 +550,7 @@ async function runInTrial<M extends WorkflowModule>(
|
|
|
550
550
|
if (file && loadedBefore.has(file)) {
|
|
551
551
|
return refuse(
|
|
552
552
|
"workflow-loaded-early",
|
|
553
|
-
`${file} was loaded before setup, so mocks missed what it took as it loaded:
|
|
553
|
+
`${file} was loaded before setup, so mocks missed what it took as it loaded: target.ts reaches the workflow only through its lazy workflow import, and imports its types with import type`,
|
|
554
554
|
);
|
|
555
555
|
}
|
|
556
556
|
if (inner.events !== undefined) {
|
package/src/env/trial.ts
CHANGED
|
@@ -31,14 +31,17 @@ export type Trial<P extends Readonly<Record<string, string>> = Readonly<Record<s
|
|
|
31
31
|
/** The case's `input.json`, typed where it is read: `const input: { today: string } = trial.input`. `{}` without one. */
|
|
32
32
|
// biome-ignore lint/suspicious/noExplicitAny: typed by the reader, as `JSON.parse` is.
|
|
33
33
|
readonly input: any;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* The built case folder: the data folder's `shared/`, or what the key's `shared` names of it,
|
|
36
|
+
* and the case's `input/`, merged. The only place a trial reads `shared/`.
|
|
37
|
+
*/
|
|
35
38
|
readonly dir: string;
|
|
36
39
|
/** The trial's empty working folder, the run's `--cwd`. */
|
|
37
40
|
readonly scratch: string;
|
|
38
41
|
/** The code folder: your checkout, or the folder `--against` names. */
|
|
39
42
|
readonly root: string;
|
|
40
43
|
/**
|
|
41
|
-
* The trial's parameters: each one `
|
|
44
|
+
* The trial's parameters: each one `target.ts` declares, from its default, a dataset entry,
|
|
42
45
|
* `--param` or `--vary`. Turn them into argv or a module to load; a value is always a string.
|
|
43
46
|
*/
|
|
44
47
|
readonly params: P;
|
package/src/format/key.ts
CHANGED
|
@@ -37,11 +37,21 @@ function expectedProblem(name: string, value: Expected): string | undefined {
|
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/** Why a `shared` entry names no path inside `shared/`, or names one again; undefined when fine. */
|
|
41
|
+
function sharedPathProblem(path: string, seen: ReadonlySet<string>): string | undefined {
|
|
42
|
+
if (path === "") return "is empty: name a file or folder in shared/";
|
|
43
|
+
if (path.startsWith("/")) return `${path} is absolute: name it relative to shared/`;
|
|
44
|
+
if (path.split("/").includes("..")) return `${path} leaves shared/: name a path inside it`;
|
|
45
|
+
if (seen.has(path)) return `${path} is given twice`;
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
/** A key field written as the wrong kind of value, in a line. */
|
|
41
50
|
const KINDS: Record<string, (value: unknown) => string> = {
|
|
42
51
|
must: () => 'must is a list: write each criterion on its own line, starting "- "',
|
|
43
52
|
"must-not": () => 'must-not is a list: write each criterion on its own line, starting "- "',
|
|
44
53
|
tags: () => "tags is a list, such as tags: [forms]",
|
|
54
|
+
shared: () => "shared is a list of paths in shared/, such as shared: [policy.md, history]",
|
|
45
55
|
expect: () => "expect maps fact names to values, such as expect: { answer: 42 }",
|
|
46
56
|
"known-failing": (value) => `known-failing is true or left out, not ${JSON.stringify(value)}`,
|
|
47
57
|
draft: (value) => `draft is true or left out, not ${JSON.stringify(value)}`,
|
|
@@ -87,6 +97,14 @@ export function parseKey(text: string): Checked<ReadKey> {
|
|
|
87
97
|
patterns: SETTINGS_PATTERNS,
|
|
88
98
|
hints: { marker: "case new writes one; copy one from another key, or remake the case" },
|
|
89
99
|
kinds: KINDS,
|
|
100
|
+
}).map((problem) => {
|
|
101
|
+
const index = /^\/shared\/(\d+)$/.exec(problem.path)?.[1];
|
|
102
|
+
if (index === undefined || problem.raw?.keyword !== "type") return problem;
|
|
103
|
+
const value = (raw as { shared: unknown[] }).shared[Number(index)];
|
|
104
|
+
return {
|
|
105
|
+
path: problem.path,
|
|
106
|
+
message: `is ${JSON.stringify(value)}: a path in shared/ is a string, such as policy.md`,
|
|
107
|
+
};
|
|
90
108
|
}),
|
|
91
109
|
};
|
|
92
110
|
}
|
|
@@ -128,6 +146,12 @@ export function parseKey(text: string): Checked<ReadKey> {
|
|
|
128
146
|
seen.add(criterion);
|
|
129
147
|
});
|
|
130
148
|
}
|
|
149
|
+
const seenShared = new Set<string>();
|
|
150
|
+
(key.shared ?? []).forEach((path, index) => {
|
|
151
|
+
const problem = sharedPathProblem(path, seenShared);
|
|
152
|
+
if (problem) problems.push({ path: `/shared/${index}`, message: problem });
|
|
153
|
+
seenShared.add(path);
|
|
154
|
+
});
|
|
131
155
|
if (problems.length > 0) return { ok: false, problems };
|
|
132
156
|
return { ok: true, value: { key, note: match[2]!.trim() } };
|
|
133
157
|
}
|
package/src/format/loop.ts
CHANGED
|
@@ -9,11 +9,11 @@ import Type from "typebox";
|
|
|
9
9
|
* try. The code itself is `start/` and `tries/{n}/code/`.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
export const LOOP_KIND = "awf.
|
|
13
|
-
export const TRY_KIND = "awf.
|
|
14
|
-
export const PROPOSAL_KIND = "awf.
|
|
15
|
-
export const FINAL_KIND = "awf.
|
|
16
|
-
export const SPREAD_KIND = "awf.
|
|
12
|
+
export const LOOP_KIND = "awf.lab-loop/1";
|
|
13
|
+
export const TRY_KIND = "awf.lab-try/1";
|
|
14
|
+
export const PROPOSAL_KIND = "awf.lab-proposal/1";
|
|
15
|
+
export const FINAL_KIND = "awf.lab-final/1";
|
|
16
|
+
export const SPREAD_KIND = "awf.lab-spread/1";
|
|
17
17
|
|
|
18
18
|
/** The proposer a loop's entry gets when it names none. */
|
|
19
19
|
export const DEFAULT_PROPOSER = "claude/claude-sonnet-5-5";
|
|
@@ -44,8 +44,8 @@ export const ProposalSchema = Type.Object(
|
|
|
44
44
|
kind: Type.Literal(PROPOSAL_KIND),
|
|
45
45
|
hypothesis: HypothesisSchema,
|
|
46
46
|
/** The proposer's run, its estimate, as the try counts it. */
|
|
47
|
-
|
|
48
|
-
/** The
|
|
47
|
+
estimate: Usd,
|
|
48
|
+
/** The run of the best version so far on the tuning cases the proposer read, its estimate. */
|
|
49
49
|
feedback: Usd,
|
|
50
50
|
runId: Type.Optional(Text),
|
|
51
51
|
},
|
|
@@ -101,7 +101,7 @@ export const TrySchema = Type.Object(
|
|
|
101
101
|
at: Text,
|
|
102
102
|
/** The try it changed: 0, the start. */
|
|
103
103
|
parent: Type.Integer({ minimum: 0 }),
|
|
104
|
-
|
|
104
|
+
outcome: Type.Union([
|
|
105
105
|
Type.Literal("kept"),
|
|
106
106
|
Type.Literal("discarded"),
|
|
107
107
|
Type.Literal("refused"),
|
|
@@ -111,10 +111,11 @@ export const TrySchema = Type.Object(
|
|
|
111
111
|
hypothesis: Type.Optional(HypothesisSchema),
|
|
112
112
|
/** The files it changed against its parent. */
|
|
113
113
|
changed: Type.Array(Text),
|
|
114
|
-
/** The run that compared it with its parent. */
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
/** The lab run that compared it with its parent. */
|
|
115
|
+
labRun: Type.Optional(Text),
|
|
116
|
+
/** The dataset's `compare`, its decision on it against its parent. */
|
|
117
|
+
decision: Type.Optional(Type.Union([Text, Type.Null()])),
|
|
118
|
+
estimate: Type.Object({ proposer: Usd, trials: Usd }, { additionalProperties: false }),
|
|
118
119
|
},
|
|
119
120
|
{ additionalProperties: false },
|
|
120
121
|
);
|
|
@@ -126,11 +127,11 @@ export const FinalSchema = Type.Object(
|
|
|
126
127
|
k: Type.Integer({ minimum: 1 }),
|
|
127
128
|
at: Text,
|
|
128
129
|
/** The kept try checked against the start. */
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
kept: Type.Integer({ minimum: 1 }),
|
|
131
|
+
labRun: Text,
|
|
132
|
+
decision: Type.Union([Text, Type.Null()]),
|
|
132
133
|
why: Text,
|
|
133
|
-
|
|
134
|
+
estimate: Usd,
|
|
134
135
|
},
|
|
135
136
|
{ additionalProperties: false },
|
|
136
137
|
);
|
|
@@ -154,11 +155,11 @@ export const SpreadSchema = Type.Union([
|
|
|
154
155
|
{
|
|
155
156
|
kind: Type.Literal(SPREAD_KIND),
|
|
156
157
|
at: Text,
|
|
157
|
-
|
|
158
|
+
labRun: Text,
|
|
158
159
|
trials: Type.Integer({ minimum: 1 }),
|
|
159
160
|
cases: Type.Integer({ minimum: 0 }),
|
|
160
161
|
/** The dataset's `compare`, the start against itself: `better` or `worse` is noise. */
|
|
161
|
-
|
|
162
|
+
decision: Type.Union([Text, Type.Null()]),
|
|
162
163
|
/** The comparison's primary metric, the second run's minus the first's. */
|
|
163
164
|
primary: Type.Optional(
|
|
164
165
|
Type.Object(
|
|
@@ -170,7 +171,7 @@ export const SpreadSchema = Type.Union([
|
|
|
170
171
|
unsteady: Type.Array(
|
|
171
172
|
Type.Object({ case: Text, a: Text, b: Text }, { additionalProperties: false }),
|
|
172
173
|
),
|
|
173
|
-
|
|
174
|
+
estimate: Usd,
|
|
174
175
|
},
|
|
175
176
|
{ additionalProperties: false },
|
|
176
177
|
),
|