@agentswf/lab 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +15 -2
- package/package.json +46 -4
- package/schema/lab-check.schema.json +64 -0
- package/schema/lab-config.schema.json +187 -0
- package/schema/lab-final.schema.json +48 -0
- package/schema/lab-good-record.schema.json +70 -0
- package/schema/lab-grade.schema.json +49 -0
- package/schema/lab-key.schema.json +124 -0
- package/schema/lab-label.schema.json +32 -0
- package/schema/lab-loop-report.schema.json +221 -0
- package/schema/lab-loop.schema.json +141 -0
- package/schema/lab-plan.schema.json +128 -0
- package/schema/lab-previous.schema.json +70 -0
- package/schema/lab-proposal.schema.json +52 -0
- package/schema/lab-report.schema.json +1128 -0
- package/schema/lab-run.schema.json +253 -0
- package/schema/lab-runs.schema.json +132 -0
- package/schema/lab-score.schema.json +319 -0
- package/schema/lab-spread.schema.json +110 -0
- package/schema/lab-trial.schema.json +543 -0
- package/schema/lab-try.schema.json +113 -0
- package/schema/local.json +155 -0
- package/src/cli.ts +9 -0
- package/src/env/capture.ts +48 -0
- package/src/env/compare.ts +201 -0
- package/src/env/facts.ts +51 -0
- package/src/env/fetch.ts +57 -0
- package/src/env/files.ts +228 -0
- package/src/env/grade-case.ts +80 -0
- package/src/env/grade-helper.ts +352 -0
- package/src/env/grader.ts +131 -0
- package/src/env/index.ts +727 -0
- package/src/env/mock.ts +374 -0
- package/src/env/routes.ts +90 -0
- package/src/env/sources.ts +19 -0
- package/src/env/state.ts +79 -0
- package/src/env/trial.ts +185 -0
- package/src/format/key.ts +168 -0
- package/src/format/loop.ts +179 -0
- package/src/format/output.ts +542 -0
- package/src/format/records.ts +443 -0
- package/src/format/schema-files.ts +64 -0
- package/src/format/settings.ts +559 -0
- package/src/format/trial-env.ts +67 -0
- package/src/format/trial-file.ts +134 -0
- package/src/help/awf-lab.txt +29 -0
- package/src/help/case.txt +39 -0
- package/src/help/config.txt +14 -0
- package/src/help/label.txt +12 -0
- package/src/help/loop.txt +44 -0
- package/src/help/report.txt +20 -0
- package/src/help/run.txt +61 -0
- package/src/help/runs.txt +11 -0
- package/src/help/score.txt +28 -0
- package/src/judge/criteria.workflow.ts +237 -0
- package/src/judge/version.ts +6 -0
- package/src/lab/answer.ts +47 -0
- package/src/lab/blame.ts +204 -0
- package/src/lab/box.ts +251 -0
- package/src/lab/capture-command.ts +302 -0
- package/src/lab/capture.ts +234 -0
- package/src/lab/check-command.ts +187 -0
- package/src/lab/cli.ts +325 -0
- package/src/lab/code-graders.ts +108 -0
- package/src/lab/columns.ts +138 -0
- package/src/lab/command-context.ts +436 -0
- package/src/lab/compare.ts +123 -0
- package/src/lab/config-command.ts +283 -0
- package/src/lab/criteria.ts +69 -0
- package/src/lab/dataset.ts +375 -0
- package/src/lab/eval-files.ts +196 -0
- package/src/lab/expect.ts +79 -0
- package/src/lab/facts.ts +59 -0
- package/src/lab/families.ts +32 -0
- package/src/lab/folders.ts +172 -0
- package/src/lab/git.ts +128 -0
- package/src/lab/good.ts +224 -0
- package/src/lab/grading-stub.txt +8 -0
- package/src/lab/grading.ts +332 -0
- package/src/lab/inspect.ts +227 -0
- package/src/lab/labels.ts +211 -0
- package/src/lab/loop-code.ts +255 -0
- package/src/lab/loop-command.ts +774 -0
- package/src/lab/loop-records.ts +144 -0
- package/src/lab/loop.ts +864 -0
- package/src/lab/marker.ts +23 -0
- package/src/lab/outcome.ts +196 -0
- package/src/lab/pooled.ts +106 -0
- package/src/lab/project-env.ts +39 -0
- package/src/lab/rates.ts +155 -0
- package/src/lab/reach.ts +111 -0
- package/src/lab/record-copies.ts +202 -0
- package/src/lab/refusal.ts +2 -0
- package/src/lab/report-command.ts +157 -0
- package/src/lab/report.ts +936 -0
- package/src/lab/reuse.ts +134 -0
- package/src/lab/run-command.ts +958 -0
- package/src/lab/run-logs.ts +89 -0
- package/src/lab/run-report.ts +286 -0
- package/src/lab/runs-command.ts +171 -0
- package/src/lab/runs.ts +172 -0
- package/src/lab/scaffold.ts +94 -0
- package/src/lab/score-command.ts +197 -0
- package/src/lab/score.ts +396 -0
- package/src/lab/store.ts +383 -0
- package/src/lab/target-stub.txt +18 -0
- package/src/lab/text.ts +29 -0
- package/src/lab/trial-settings.ts +105 -0
- package/src/lab/trial.ts +439 -0
- package/src/lab/usage.ts +274 -0
- package/src/lab/verdict.ts +161 -0
- package/src/lab/workflow-graders.ts +164 -0
- package/src/lab/workspace.ts +496 -0
- package/src/loop/propose.workflow.ts +84 -0
- package/src/shared/allowance.ts +185 -0
- package/src/shared/compare/index.ts +3 -0
- package/src/shared/compare/paired.ts +397 -0
- package/src/shared/compare/stats.ts +139 -0
- package/src/shared/compare/types.ts +75 -0
- package/src/shared/config.ts +15 -0
- package/src/shared/runner.ts +321 -0
- package/src/shared/validate.ts +181 -0
- package/src/shared/version.ts +41 -0
- package/src/write-schemas.ts +10 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import Type from "typebox";
|
|
2
|
+
import { SEMVER } from "../shared/version";
|
|
3
|
+
import { AgentSchema, FactSchema, ResolvedLimitsSchema, ResolvedSandboxSchema } from "./settings";
|
|
4
|
+
import { DATASET_ERRORS, GatheredSchema, RefusedSchema } from "./trial-file";
|
|
5
|
+
|
|
6
|
+
// The records the lab writes in its store: a run, a trial, a score and a label; and the grade
|
|
7
|
+
// folder's `grade.json`. Each is checked against its schema before it is written and when it is
|
|
8
|
+
// read.
|
|
9
|
+
|
|
10
|
+
export const RUN_KIND = "awf.lab-run/1";
|
|
11
|
+
export const TRIAL_KIND = "awf.lab-trial/1";
|
|
12
|
+
export const SCORE_KIND = "awf.lab-score/1";
|
|
13
|
+
export const GRADE_KIND = "awf.lab-grade/1";
|
|
14
|
+
export const LABEL_KIND = "awf.lab-label/1";
|
|
15
|
+
|
|
16
|
+
const Text = Type.String({ minLength: 1 });
|
|
17
|
+
const Time = Type.String({ format: "date-time" });
|
|
18
|
+
const Digest = Type.String({ pattern: "^[0-9a-f]{64}$" });
|
|
19
|
+
export const RunId = Type.String({ pattern: "^[0-9]{8}-[0-9]{6}-[0-9a-f]{4}$" });
|
|
20
|
+
|
|
21
|
+
/** A folder of code: a column of the report. */
|
|
22
|
+
export const FolderSchema = Type.Object(
|
|
23
|
+
{
|
|
24
|
+
path: Text,
|
|
25
|
+
/** null: detached. */
|
|
26
|
+
branch: Type.Union([Text, Type.Null()]),
|
|
27
|
+
commit: Type.Union([Text, Type.Null()]),
|
|
28
|
+
dirty: Type.Boolean(),
|
|
29
|
+
/**
|
|
30
|
+
* The version its trials ran under: its `target.ts`'s, semver, or under a loop the lab's own id
|
|
31
|
+
* of the code, `loop {name} {started}` for the start and `… try {n}` for a try.
|
|
32
|
+
*/
|
|
33
|
+
version: Text,
|
|
34
|
+
/** The sandbox its trials ran under, from its own `target.ts`, resolved. */
|
|
35
|
+
sandbox: ResolvedSandboxSchema,
|
|
36
|
+
/** The limits its trials ran under: `--limit` over its own `target.ts`'s over the defaults. */
|
|
37
|
+
limits: ResolvedLimitsSchema,
|
|
38
|
+
},
|
|
39
|
+
{ additionalProperties: false },
|
|
40
|
+
);
|
|
41
|
+
export type Folder = Type.Static<typeof FolderSchema>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A parameter's name: plain words a `target.ts` declares and reads as `trial.params`. A dot is kept for the
|
|
45
|
+
* lab's own parameters.
|
|
46
|
+
*/
|
|
47
|
+
export const PARAM_NAME = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
48
|
+
|
|
49
|
+
/** The parameters a trial ran under, each a string. */
|
|
50
|
+
export const ParamsSchema = Type.Record(Type.String({ pattern: PARAM_NAME.source }), Text);
|
|
51
|
+
export type Params = Type.Static<typeof ParamsSchema>;
|
|
52
|
+
|
|
53
|
+
/** A column of the report: a folder of code and the parameters its trials ran under. */
|
|
54
|
+
export const ColumnSchema = Type.Object(
|
|
55
|
+
{
|
|
56
|
+
/** The folder's index in the run's `folders`. */
|
|
57
|
+
folder: Type.Integer({ minimum: 0 }),
|
|
58
|
+
params: ParamsSchema,
|
|
59
|
+
},
|
|
60
|
+
{ additionalProperties: false },
|
|
61
|
+
);
|
|
62
|
+
export type Column = Type.Static<typeof ColumnSchema>;
|
|
63
|
+
|
|
64
|
+
/** `{store}/runs/{n}/run.json`. No `finished`, or `broke`, means partial. */
|
|
65
|
+
export const RunRecordSchema = Type.Object(
|
|
66
|
+
{
|
|
67
|
+
kind: Type.Literal(RUN_KIND),
|
|
68
|
+
/** The time and four random hex digits: `20261117-142233-a3f9`. */
|
|
69
|
+
id: RunId,
|
|
70
|
+
dataset: Text,
|
|
71
|
+
folders: Type.Array(FolderSchema, { minItems: 1 }),
|
|
72
|
+
/**
|
|
73
|
+
* Each folder under each combination of parameters, the folders outermost. The first is the
|
|
74
|
+
* reference column: your checkout under `--param` and each `--vary`'s first value.
|
|
75
|
+
*/
|
|
76
|
+
columns: Type.Array(ColumnSchema, { minItems: 1 }),
|
|
77
|
+
asked: Type.Array(
|
|
78
|
+
Type.Object(
|
|
79
|
+
{ case: Text, trials: Type.Integer({ minimum: 1 }) },
|
|
80
|
+
{ additionalProperties: false },
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
/** The loop that ran it, by its id: `report` and `score` never take it unasked. */
|
|
84
|
+
loop: Type.Optional(Text),
|
|
85
|
+
started: Time,
|
|
86
|
+
/** When it ended, or broke; none when it was killed. */
|
|
87
|
+
finished: Type.Optional(Time),
|
|
88
|
+
/** Set when the lab broke during the run. */
|
|
89
|
+
broke: Type.Optional(Type.String()),
|
|
90
|
+
/**
|
|
91
|
+
* Set when the run stopped starting trials: `budget`, its estimates reached `--budget`;
|
|
92
|
+
* `compare`, a loop's try that the dataset's comparison stopped; `precondition`, two trials in
|
|
93
|
+
* a row, in the order they ended, failed a precondition; `stage`, a trial's run never entered
|
|
94
|
+
* a stage its case named in `stubStages` or `stopAfterStage`.
|
|
95
|
+
*/
|
|
96
|
+
stopped: Type.Optional(
|
|
97
|
+
Type.Union([
|
|
98
|
+
Type.Literal("budget"),
|
|
99
|
+
Type.Literal("compare"),
|
|
100
|
+
Type.Literal("precondition"),
|
|
101
|
+
Type.Literal("stage"),
|
|
102
|
+
]),
|
|
103
|
+
),
|
|
104
|
+
},
|
|
105
|
+
{ additionalProperties: false },
|
|
106
|
+
);
|
|
107
|
+
export type RunRecord = Type.Static<typeof RunRecordSchema>;
|
|
108
|
+
|
|
109
|
+
export const OUTCOMES = [
|
|
110
|
+
"leaked",
|
|
111
|
+
"errored",
|
|
112
|
+
"failed",
|
|
113
|
+
"stopped",
|
|
114
|
+
"undecided",
|
|
115
|
+
"passed",
|
|
116
|
+
"graded by numbers",
|
|
117
|
+
"not graded",
|
|
118
|
+
] as const;
|
|
119
|
+
export type Outcome = (typeof OUTCOMES)[number];
|
|
120
|
+
|
|
121
|
+
export const ErroredSchema = Type.Object(
|
|
122
|
+
{
|
|
123
|
+
by: Type.Union([
|
|
124
|
+
Type.Literal("dataset"),
|
|
125
|
+
Type.Literal("grading"),
|
|
126
|
+
Type.Literal("provider"),
|
|
127
|
+
Type.Literal("harness"),
|
|
128
|
+
Type.Literal("lab"),
|
|
129
|
+
]),
|
|
130
|
+
phase: Type.Union([
|
|
131
|
+
Type.Literal("setup"),
|
|
132
|
+
Type.Literal("body"),
|
|
133
|
+
Type.Literal("evidence"),
|
|
134
|
+
Type.Literal("teardown"),
|
|
135
|
+
Type.Literal("after"),
|
|
136
|
+
/** `grading.ts`'s `facts`, run on the trial record outside the trial. */
|
|
137
|
+
Type.Literal("facts"),
|
|
138
|
+
]),
|
|
139
|
+
code: Type.Optional(Type.Enum([...DATASET_ERRORS, "reach", "login"] as const)),
|
|
140
|
+
reason: Type.String(),
|
|
141
|
+
},
|
|
142
|
+
{ additionalProperties: false },
|
|
143
|
+
);
|
|
144
|
+
export type Errored = Type.Static<typeof ErroredSchema>;
|
|
145
|
+
|
|
146
|
+
/** One agent's sandbox, as the reach check read it. */
|
|
147
|
+
const ReachSchema = Type.Object(
|
|
148
|
+
{
|
|
149
|
+
ok: Type.Boolean(),
|
|
150
|
+
problems: Type.Array(Type.String()),
|
|
151
|
+
sockets: Type.Array(Type.String()),
|
|
152
|
+
sandboxes: Type.Array(
|
|
153
|
+
Type.Object(
|
|
154
|
+
{
|
|
155
|
+
key: Type.String(),
|
|
156
|
+
provider: Type.String(),
|
|
157
|
+
network: Type.Array(Type.String()),
|
|
158
|
+
webSearch: Type.Boolean(),
|
|
159
|
+
agents: Type.Array(Type.String()),
|
|
160
|
+
},
|
|
161
|
+
{ additionalProperties: false },
|
|
162
|
+
),
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
{ additionalProperties: false },
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
/** `{store}/runs/{n}/trials/{case}/{column}-{trial}/trial.json`. */
|
|
169
|
+
export const TrialRecordSchema = Type.Object(
|
|
170
|
+
{
|
|
171
|
+
kind: Type.Literal(TRIAL_KIND),
|
|
172
|
+
labRun: RunId,
|
|
173
|
+
dataset: Text,
|
|
174
|
+
case: Text,
|
|
175
|
+
/** The column's index in the run's `columns`. */
|
|
176
|
+
column: Type.Integer({ minimum: 0 }),
|
|
177
|
+
trial: Type.Integer({ minimum: 1 }),
|
|
178
|
+
/** The column's parameters, as `target.ts` and the graders were given them. */
|
|
179
|
+
params: ParamsSchema,
|
|
180
|
+
/**
|
|
181
|
+
* The column's version, as its folder's: kept whole, though only its major, minor and
|
|
182
|
+
* pre-release tag are in `reuse`.
|
|
183
|
+
*/
|
|
184
|
+
version: Text,
|
|
185
|
+
/**
|
|
186
|
+
* What a later trial must match to stand in for this one, as one digest: the version's major,
|
|
187
|
+
* minor and pre-release tag, the `agentswf` and lab versions, the resolved target settings and
|
|
188
|
+
* parameters, and the built case.
|
|
189
|
+
*/
|
|
190
|
+
reuse: Type.Optional(Digest),
|
|
191
|
+
/**
|
|
192
|
+
* Set when read through a later run that reused this trial: where it ran. Never written: the
|
|
193
|
+
* later run's folder holds `reused.json`, a pointer, and the trial's grades stay where it ran.
|
|
194
|
+
*/
|
|
195
|
+
reused: Type.Optional(
|
|
196
|
+
Type.Object(
|
|
197
|
+
{
|
|
198
|
+
labRun: RunId,
|
|
199
|
+
column: Type.Integer({ minimum: 0 }),
|
|
200
|
+
trial: Type.Integer({ minimum: 1 }),
|
|
201
|
+
},
|
|
202
|
+
{ additionalProperties: false },
|
|
203
|
+
),
|
|
204
|
+
),
|
|
205
|
+
awf: Type.Object({ bin: Text, version: Text }, { additionalProperties: false }),
|
|
206
|
+
/** The built case folder's digest; the folder is kept once, in the store's `inputs/`. */
|
|
207
|
+
input: Digest,
|
|
208
|
+
/** The column's sandbox as it resolved: `by: "lab"`, the lab's box around the whole trial. */
|
|
209
|
+
sandbox: ResolvedSandboxSchema,
|
|
210
|
+
/** The column's limits as they resolved, `--limit` over `target.ts`'s over the defaults. */
|
|
211
|
+
limits: ResolvedLimitsSchema,
|
|
212
|
+
models: Type.Array(Text),
|
|
213
|
+
at: Time,
|
|
214
|
+
workflow: Type.Optional(
|
|
215
|
+
Type.Object(
|
|
216
|
+
{ name: Text, version: Type.Optional(Type.String()) },
|
|
217
|
+
{ additionalProperties: false },
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
/**
|
|
221
|
+
* The trial's id: its workflow run's, as `awf` named it. Absent when the trial ended before
|
|
222
|
+
* one started (leaked, the lab).
|
|
223
|
+
*/
|
|
224
|
+
trialId: Type.Optional(Text),
|
|
225
|
+
runOutcome: Type.Optional(Text),
|
|
226
|
+
runReason: Type.Optional(Type.String()),
|
|
227
|
+
ms: Type.Number({ minimum: 0 }),
|
|
228
|
+
setupMs: Type.Optional(Type.Number({ minimum: 0 })),
|
|
229
|
+
estimate: Type.Optional(Type.Number({ minimum: 0 })),
|
|
230
|
+
known: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
231
|
+
priced: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
232
|
+
agents: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
233
|
+
/**
|
|
234
|
+
* The trial record's own parts, what grading reads: `grading.ts`'s `facts` is run on them
|
|
235
|
+
* each time a trial is graded, so facts are never kept here. Absent on a trial that ended
|
|
236
|
+
* before the workflow did, or whose `evidence` failed.
|
|
237
|
+
*/
|
|
238
|
+
...partial(GatheredSchema),
|
|
239
|
+
files: Type.Array(Type.String()),
|
|
240
|
+
/**
|
|
241
|
+
* The run facts, read from the run's own logs once it ended: turns by outcome and by agent.
|
|
242
|
+
* Under `_` names, which `expect` reads beside the facts; no other grader is given them. Empty
|
|
243
|
+
* when the logs were no page; absent on a trial kept before the lab read them.
|
|
244
|
+
*/
|
|
245
|
+
runFacts: Type.Optional(
|
|
246
|
+
Type.Record(Type.String({ pattern: "^_" }), Type.Number({ minimum: 0 }), {
|
|
247
|
+
additionalProperties: false,
|
|
248
|
+
}),
|
|
249
|
+
),
|
|
250
|
+
/** Each stage the workflow ran, by name: how long it took. A stubbed stage ran no work. */
|
|
251
|
+
stageMs: Type.Optional(Type.Record(Type.String(), Type.Number({ minimum: 0 }))),
|
|
252
|
+
unused: Type.Array(Type.String()),
|
|
253
|
+
refused: Type.Array(RefusedSchema),
|
|
254
|
+
leaked: Type.Boolean(),
|
|
255
|
+
reach: Type.Optional(ReachSchema),
|
|
256
|
+
stopped: Type.Optional(Type.String()),
|
|
257
|
+
/** The workflow's own error: it threw or timed out. Never graded. */
|
|
258
|
+
workflowError: Type.Optional(Type.String()),
|
|
259
|
+
errored: Type.Optional(ErroredSchema),
|
|
260
|
+
/** Tried again at the end of its round after the provider's error. */
|
|
261
|
+
retried: Type.Optional(Type.Boolean()),
|
|
262
|
+
},
|
|
263
|
+
{ additionalProperties: false },
|
|
264
|
+
);
|
|
265
|
+
export type TrialRecord = Type.Static<typeof TrialRecordSchema>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* A case's known good record, `key/good/record.json`: a trial record a person vouches for, in the
|
|
269
|
+
* trial record's shape. Only the parts `facts` and the code graders read need be there, so one can
|
|
270
|
+
* be written by hand before any trial ran; `case pin` writes a trial's whole. No format marker: a
|
|
271
|
+
* person may write it.
|
|
272
|
+
*/
|
|
273
|
+
export const GoodRecordSchema = Type.Object(partial(GatheredSchema), {
|
|
274
|
+
additionalProperties: false,
|
|
275
|
+
});
|
|
276
|
+
export type GoodRecord = Type.Static<typeof GoodRecordSchema>;
|
|
277
|
+
|
|
278
|
+
/** An object schema's properties, each optional. */
|
|
279
|
+
function partial<P extends Type.TProperties>(
|
|
280
|
+
schema: Type.TObject<P>,
|
|
281
|
+
): { [K in keyof P]: Type.TOptional<P[K]> } {
|
|
282
|
+
return Object.fromEntries(
|
|
283
|
+
Object.entries(schema.properties).map(([name, each]) => [name, Type.Optional(each)]),
|
|
284
|
+
) as never;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const VERDICTS = ["passed", "failed", "undecided"] as const;
|
|
288
|
+
export type Verdict = (typeof VERDICTS)[number];
|
|
289
|
+
|
|
290
|
+
/** A count out of a total, pooled per column by summing; `of: 0` is none in this case. Or a value. */
|
|
291
|
+
const NumberSchema = Type.Union([
|
|
292
|
+
Type.Object(
|
|
293
|
+
{ count: Type.Number({ minimum: 0 }), of: Type.Number({ minimum: 0 }) },
|
|
294
|
+
{ additionalProperties: false },
|
|
295
|
+
),
|
|
296
|
+
Type.Object({ value: Type.Number() }, { additionalProperties: false }),
|
|
297
|
+
]);
|
|
298
|
+
|
|
299
|
+
const ReasonSchema = Type.Object(
|
|
300
|
+
{ about: Text, text: Type.String() },
|
|
301
|
+
{ additionalProperties: false },
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const Judged = Type.Enum([...VERDICTS, "not judged"] as const);
|
|
305
|
+
|
|
306
|
+
/** One voter's say on a part: a verdict, or a label of the grader's own (a finding's `hit`). */
|
|
307
|
+
export const VoteSchema = Type.Object(
|
|
308
|
+
{
|
|
309
|
+
by: Text,
|
|
310
|
+
role: Type.Optional(Text),
|
|
311
|
+
verdict: Type.Optional(Judged),
|
|
312
|
+
label: Type.Optional(Text),
|
|
313
|
+
data: Type.Optional(Type.Unknown()),
|
|
314
|
+
why: Type.Optional(Type.String()),
|
|
315
|
+
},
|
|
316
|
+
{ additionalProperties: false },
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
/** One thing a grader judged, such as a criterion or a finding: its verdict or label, and votes. */
|
|
320
|
+
export const PartSchema = Type.Object(
|
|
321
|
+
{
|
|
322
|
+
about: Text,
|
|
323
|
+
verdict: Type.Optional(Judged),
|
|
324
|
+
label: Type.Optional(Text),
|
|
325
|
+
data: Type.Optional(Type.Unknown()),
|
|
326
|
+
why: Type.Optional(Type.String()),
|
|
327
|
+
settled: Type.Optional(
|
|
328
|
+
Type.Enum(["agreed", "majority", "tiebreak", "unsettled", "given"] as const),
|
|
329
|
+
),
|
|
330
|
+
votes: Type.Optional(Type.Array(VoteSchema)),
|
|
331
|
+
},
|
|
332
|
+
{ additionalProperties: false },
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
export type Part = Type.Static<typeof PartSchema>;
|
|
336
|
+
|
|
337
|
+
export const GraderEntrySchema = Type.Object(
|
|
338
|
+
{
|
|
339
|
+
grader: Text,
|
|
340
|
+
/**
|
|
341
|
+
* The grader's version, semver: results belong to its major, minor and pre-release tag, so a
|
|
342
|
+
* patch bump keeps them. Absent when the grader errored before its version was read.
|
|
343
|
+
*/
|
|
344
|
+
version: Type.Optional(Type.String({ pattern: SEMVER.source })),
|
|
345
|
+
key: Digest,
|
|
346
|
+
/**
|
|
347
|
+
* What the grader was given beside the key, as one digest: its settings as values and the
|
|
348
|
+
* facts it read. Another digest grades it again. Absent on a grade by `expect` alone.
|
|
349
|
+
*/
|
|
350
|
+
given: Type.Optional(Digest),
|
|
351
|
+
verdict: Type.Optional(Type.Enum(VERDICTS)),
|
|
352
|
+
numbers: Type.Optional(Type.Record(Text, NumberSchema)),
|
|
353
|
+
reasons: Type.Array(ReasonSchema),
|
|
354
|
+
parts: Type.Optional(Type.Array(PartSchema)),
|
|
355
|
+
/** The grader does not apply to this case, and why: neither a verdict nor numbers. */
|
|
356
|
+
notApplies: Type.Optional(Type.String()),
|
|
357
|
+
models: Type.Optional(Type.Array(Text)),
|
|
358
|
+
/** The harness and model a grader that runs one agent of its choosing used: the judge's. */
|
|
359
|
+
agent: Type.Optional(AgentSchema),
|
|
360
|
+
ms: Type.Optional(Type.Number({ minimum: 0 })),
|
|
361
|
+
estimate: Type.Optional(Type.Number({ minimum: 0 })),
|
|
362
|
+
runId: Type.Optional(Text),
|
|
363
|
+
errored: Type.Optional(
|
|
364
|
+
Type.Object(
|
|
365
|
+
{ reason: Type.String(), problems: Type.Optional(Type.Array(Type.String())) },
|
|
366
|
+
{ additionalProperties: false },
|
|
367
|
+
),
|
|
368
|
+
),
|
|
369
|
+
/** Skipped, as a grader before it failed the trial: graded by `score` once it passes them. */
|
|
370
|
+
skipped: Type.Optional(Type.Literal(true)),
|
|
371
|
+
},
|
|
372
|
+
{ additionalProperties: false },
|
|
373
|
+
);
|
|
374
|
+
export type GraderEntry = Type.Static<typeof GraderEntrySchema>;
|
|
375
|
+
|
|
376
|
+
/** A line of `{trial}/scores.jsonl`: every score a trial is given, newest last. */
|
|
377
|
+
export const ScoreRecordSchema = Type.Object(
|
|
378
|
+
{
|
|
379
|
+
kind: Type.Literal(SCORE_KIND),
|
|
380
|
+
at: Time,
|
|
381
|
+
/** The facts `grading.ts`'s `facts` read off the trial record for this score. */
|
|
382
|
+
facts: Type.Optional(Type.Record(Type.String(), FactSchema)),
|
|
383
|
+
/**
|
|
384
|
+
* Grading couldn't start, as the dataset's mistake: `facts` threw or gave a fact `undefined`,
|
|
385
|
+
* or the key's `expect` can't compare a fact. The trial reads as errored while this is its
|
|
386
|
+
* newest score with facts or an error, so `score` grades it again once `grading.ts` is fixed.
|
|
387
|
+
*/
|
|
388
|
+
errored: Type.Optional(ErroredSchema),
|
|
389
|
+
entries: Type.Array(GraderEntrySchema),
|
|
390
|
+
},
|
|
391
|
+
{ additionalProperties: false },
|
|
392
|
+
);
|
|
393
|
+
export type ScoreRecord = Type.Static<typeof ScoreRecordSchema>;
|
|
394
|
+
|
|
395
|
+
/** A grader's earlier parts, given to it as `previous.json` so it judges only what changed. */
|
|
396
|
+
export const PreviousSchema = Type.Object(
|
|
397
|
+
{
|
|
398
|
+
/** The digest of the key those parts were graded on. */
|
|
399
|
+
key: Digest,
|
|
400
|
+
parts: Type.Array(PartSchema),
|
|
401
|
+
},
|
|
402
|
+
{ additionalProperties: false },
|
|
403
|
+
);
|
|
404
|
+
export type Previous = Type.Static<typeof PreviousSchema>;
|
|
405
|
+
|
|
406
|
+
/** `grade.json` in a grade folder: what a grader workflow reads with `gradeCase()`. */
|
|
407
|
+
export const GradeFileSchema = Type.Object(
|
|
408
|
+
{
|
|
409
|
+
kind: Type.Literal(GRADE_KIND),
|
|
410
|
+
case: Text,
|
|
411
|
+
/** The trial's working folder, during the trial; null under `score`, which has none. */
|
|
412
|
+
scratch: Type.Union([Text, Type.Null()]),
|
|
413
|
+
/** The trial's parameters. */
|
|
414
|
+
params: ParamsSchema,
|
|
415
|
+
/** `"facts"`: the grader is given the facts alone; `"trial"`: the record and saved files too. */
|
|
416
|
+
reads: Type.Union([Type.Literal("facts"), Type.Literal("trial")]),
|
|
417
|
+
},
|
|
418
|
+
{ additionalProperties: false },
|
|
419
|
+
);
|
|
420
|
+
export type GradeFile = Type.Static<typeof GradeFileSchema>;
|
|
421
|
+
|
|
422
|
+
const MARKS = ["good", "needs-work", "cleared"] as const;
|
|
423
|
+
export type Mark = (typeof MARKS)[number];
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* A line of `{store}/labels/{dataset}.jsonl`: the person's mark on one trial, found by its
|
|
427
|
+
* trial id, so a reused copy keeps it. The newest line of a trial wins; `cleared` takes
|
|
428
|
+
* a label back.
|
|
429
|
+
*/
|
|
430
|
+
export const LabelRecordSchema = Type.Object(
|
|
431
|
+
{
|
|
432
|
+
kind: Type.Literal(LABEL_KIND),
|
|
433
|
+
/** The trial's id, its workflow run's as `awf` named it: not the lab run's. */
|
|
434
|
+
trialId: Text,
|
|
435
|
+
case: Text,
|
|
436
|
+
mark: Type.Enum(MARKS),
|
|
437
|
+
/** Why it needs work. */
|
|
438
|
+
note: Type.Optional(Text),
|
|
439
|
+
at: Time,
|
|
440
|
+
},
|
|
441
|
+
{ additionalProperties: false },
|
|
442
|
+
);
|
|
443
|
+
export type LabelRecord = Type.Static<typeof LabelRecordSchema>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { FinalSchema, LoopSchema, ProposalSchema, SpreadSchema, TrySchema } from "./loop";
|
|
2
|
+
import {
|
|
3
|
+
LabCheckSchema,
|
|
4
|
+
LabConfigSchema,
|
|
5
|
+
LabPlanSchema,
|
|
6
|
+
LabReportSchema,
|
|
7
|
+
LabRunsSchema,
|
|
8
|
+
LoopReportSchema,
|
|
9
|
+
} from "./output";
|
|
10
|
+
import {
|
|
11
|
+
GoodRecordSchema,
|
|
12
|
+
GradeFileSchema,
|
|
13
|
+
LabelRecordSchema,
|
|
14
|
+
PreviousSchema,
|
|
15
|
+
RunRecordSchema,
|
|
16
|
+
ScoreRecordSchema,
|
|
17
|
+
TrialRecordSchema,
|
|
18
|
+
} from "./records";
|
|
19
|
+
import { KeySchema, LocalFileSchema } from "./settings";
|
|
20
|
+
|
|
21
|
+
const DRAFT = "https://json-schema.org/draft/2020-12/schema";
|
|
22
|
+
|
|
23
|
+
/** The lab's published JSON Schemas, by file name under `packages/lab/schema/`. */
|
|
24
|
+
export const LAB_SCHEMA_FILES = {
|
|
25
|
+
"local.json": { title: "awf-lab's evals/awf-lab.local.json", schema: LocalFileSchema },
|
|
26
|
+
"lab-key.schema.json": { title: "awf-lab case key, its frontmatter", schema: KeySchema },
|
|
27
|
+
"lab-run.schema.json": { title: "awf-lab lab run", schema: RunRecordSchema },
|
|
28
|
+
"lab-trial.schema.json": { title: "awf-lab trial", schema: TrialRecordSchema },
|
|
29
|
+
"lab-score.schema.json": { title: "awf-lab trial score", schema: ScoreRecordSchema },
|
|
30
|
+
"lab-good-record.schema.json": {
|
|
31
|
+
title: "awf-lab case's known good record, key/good/record.json",
|
|
32
|
+
schema: GoodRecordSchema,
|
|
33
|
+
},
|
|
34
|
+
"lab-grade.schema.json": { title: "awf-lab grade folder's grade.json", schema: GradeFileSchema },
|
|
35
|
+
"lab-previous.schema.json": {
|
|
36
|
+
title: "awf-lab grade folder's previous.json",
|
|
37
|
+
schema: PreviousSchema,
|
|
38
|
+
},
|
|
39
|
+
"lab-report.schema.json": {
|
|
40
|
+
title: "awf-lab run, score and report --json",
|
|
41
|
+
schema: LabReportSchema,
|
|
42
|
+
},
|
|
43
|
+
"lab-plan.schema.json": { title: "awf-lab --dry-run --json", schema: LabPlanSchema },
|
|
44
|
+
"lab-check.schema.json": { title: "awf-lab case check --json", schema: LabCheckSchema },
|
|
45
|
+
"lab-runs.schema.json": { title: "awf-lab runs --json", schema: LabRunsSchema },
|
|
46
|
+
"lab-config.schema.json": { title: "awf-lab config --json", schema: LabConfigSchema },
|
|
47
|
+
"lab-loop-report.schema.json": {
|
|
48
|
+
title: "awf-lab report --loop --json",
|
|
49
|
+
schema: LoopReportSchema,
|
|
50
|
+
},
|
|
51
|
+
"lab-label.schema.json": { title: "awf-lab label", schema: LabelRecordSchema },
|
|
52
|
+
"lab-loop.schema.json": { title: "awf-lab loop's loop.json", schema: LoopSchema },
|
|
53
|
+
"lab-try.schema.json": { title: "awf-lab loop's try.json", schema: TrySchema },
|
|
54
|
+
"lab-proposal.schema.json": { title: "awf-lab loop's proposal.json", schema: ProposalSchema },
|
|
55
|
+
"lab-final.schema.json": { title: "awf-lab loop's final check", schema: FinalSchema },
|
|
56
|
+
"lab-spread.schema.json": { title: "awf-lab loop's spread.json", schema: SpreadSchema },
|
|
57
|
+
} as const;
|
|
58
|
+
|
|
59
|
+
export type LabSchemaName = keyof typeof LAB_SCHEMA_FILES;
|
|
60
|
+
|
|
61
|
+
export function renderLabSchemaFile(name: LabSchemaName): string {
|
|
62
|
+
const { title, schema } = LAB_SCHEMA_FILES[name];
|
|
63
|
+
return `${JSON.stringify({ $schema: DRAFT, title, ...schema }, null, 2)}\n`;
|
|
64
|
+
}
|