@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,181 @@
|
|
|
1
|
+
import type Type from "typebox";
|
|
2
|
+
import { Check, Errors } from "typebox/value";
|
|
3
|
+
|
|
4
|
+
export type Problem = {
|
|
5
|
+
path: string;
|
|
6
|
+
message: string;
|
|
7
|
+
/** What the schema check said, for `explain` to put in words; absent from a hand-made problem. */
|
|
8
|
+
raw?: { keyword: string; schemaPath: string; params: Record<string, unknown> };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type Checked<T> = { ok: true; value: T } | { ok: false; problems: Problem[] };
|
|
12
|
+
|
|
13
|
+
/** Checks a value against a schema, each problem once. */
|
|
14
|
+
export function checkSchema<S extends Type.TSchema>(
|
|
15
|
+
schema: S,
|
|
16
|
+
value: unknown,
|
|
17
|
+
): Checked<Type.Static<S>> {
|
|
18
|
+
if (Check(schema, value)) return { ok: true, value };
|
|
19
|
+
const seen = new Set<string>();
|
|
20
|
+
const problems: Problem[] = [];
|
|
21
|
+
for (const error of Errors(schema, value)) {
|
|
22
|
+
const problem = {
|
|
23
|
+
path: error.instancePath || "/",
|
|
24
|
+
message: error.message,
|
|
25
|
+
raw: {
|
|
26
|
+
keyword: error.keyword,
|
|
27
|
+
schemaPath: error.schemaPath,
|
|
28
|
+
params: error.params as Record<string, unknown>,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const key = `${problem.path} ${problem.message}`;
|
|
32
|
+
if (seen.has(key)) continue;
|
|
33
|
+
seen.add(key);
|
|
34
|
+
problems.push(problem);
|
|
35
|
+
}
|
|
36
|
+
return { ok: false, problems };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How `explainProblems` words a file's problems: what the file is, and phrases for its patterns. */
|
|
40
|
+
type Explain = {
|
|
41
|
+
schema: Type.TSchema;
|
|
42
|
+
value: unknown;
|
|
43
|
+
/** The file's root, as "a key" in "a key's fields". */
|
|
44
|
+
noun: string;
|
|
45
|
+
/** A pattern's meaning, by the pattern: "a number and a unit, such as 30m or 90s". */
|
|
46
|
+
patterns?: Readonly<Record<string, string>>;
|
|
47
|
+
/** What to do about a missing field, by its path without the leading slash. */
|
|
48
|
+
hints?: Readonly<Record<string, string>>;
|
|
49
|
+
/**
|
|
50
|
+
* What a field is, by its path without the leading slash, for a value of the wrong type or
|
|
51
|
+
* constant: the one line said for it, given the value written.
|
|
52
|
+
*/
|
|
53
|
+
kinds?: Readonly<Record<string, (value: unknown) => string>>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** A file's problems, one a line; a worded one, with no path, as it is. */
|
|
57
|
+
export function describeProblems(file: string, problems: readonly Problem[]): string {
|
|
58
|
+
return [
|
|
59
|
+
`${file} is not valid:`,
|
|
60
|
+
...problems.map((p) => ` ${p.path ? `${p.path}: ` : ""}${p.message}`),
|
|
61
|
+
].join("\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type Node = Record<string, unknown>;
|
|
65
|
+
|
|
66
|
+
const segments = (pointer: string) =>
|
|
67
|
+
pointer
|
|
68
|
+
.split("/")
|
|
69
|
+
.filter((s) => s !== "" && s !== "#")
|
|
70
|
+
.map((s) => s.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
71
|
+
|
|
72
|
+
function at(root: unknown, pointer: string): unknown {
|
|
73
|
+
let node = root;
|
|
74
|
+
for (const s of segments(pointer)) node = (node as Node | undefined)?.[s];
|
|
75
|
+
return node;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A path as said in a line: `sandbox`, `sandbox/network/agents/0`; the root as "". */
|
|
79
|
+
const field = (path: string) => segments(path).join("/");
|
|
80
|
+
|
|
81
|
+
const shown = (value: unknown) => (typeof value === "string" ? value : JSON.stringify(value));
|
|
82
|
+
|
|
83
|
+
/** One of a union's members, as an example of it: `"workflow"`, `{ "lab": "srt" }`. */
|
|
84
|
+
function sample(member: Node): string {
|
|
85
|
+
if ("const" in member) return JSON.stringify(member.const);
|
|
86
|
+
const properties = member.properties as Record<string, Node> | undefined;
|
|
87
|
+
if (member.type === "object" && properties) {
|
|
88
|
+
const required = (member.required as string[] | undefined) ?? Object.keys(properties);
|
|
89
|
+
const shown = required.map(
|
|
90
|
+
(name) =>
|
|
91
|
+
`"${name}": ${"const" in properties[name]! ? JSON.stringify(properties[name]!.const) : "…"}`,
|
|
92
|
+
);
|
|
93
|
+
return `{ ${shown.join(", ")} }`;
|
|
94
|
+
}
|
|
95
|
+
return typeof member.type === "string" ? `a ${member.type}` : "something else";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A member's description, to its first stop: "the lab's box". */
|
|
99
|
+
function gist(member: Node): string | undefined {
|
|
100
|
+
if (typeof member.description !== "string") return undefined;
|
|
101
|
+
const head = member.description.split(/[:.]/)[0]!.trim();
|
|
102
|
+
return head ? head[0]!.toLowerCase() + head.slice(1) : undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A schema check's problems in words: an unknown field with the fields there are, a missing one
|
|
107
|
+
* with what to do, a constant, a pattern's meaning, and a union's members in place of each
|
|
108
|
+
* member's own complaint. What it has no words for stays as the check said it.
|
|
109
|
+
*/
|
|
110
|
+
export function explainProblems(problems: readonly Problem[], explain: Explain): Problem[] {
|
|
111
|
+
const unions = problems
|
|
112
|
+
.filter((p) => p.raw?.keyword === "anyOf")
|
|
113
|
+
.map((p) => `${p.raw!.schemaPath}/anyOf/`);
|
|
114
|
+
const lines: Problem[] = [];
|
|
115
|
+
const say = (message: string) => lines.push({ path: "", message });
|
|
116
|
+
// A field of the wrong kind is one mistake, however many of the check's complaints it makes.
|
|
117
|
+
const kinded = new Set<string>();
|
|
118
|
+
for (const problem of problems) {
|
|
119
|
+
const raw = problem.raw;
|
|
120
|
+
const where = field(problem.path);
|
|
121
|
+
if (!raw) {
|
|
122
|
+
lines.push(problem);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (unions.some((u) => raw.schemaPath.startsWith(u))) continue;
|
|
126
|
+
const kind = explain.kinds?.[where];
|
|
127
|
+
if (kind && (raw.keyword === "type" || raw.keyword === "const")) {
|
|
128
|
+
if (!kinded.has(where)) say(kind(at(explain.value, problem.path)));
|
|
129
|
+
kinded.add(where);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (raw.keyword === "boolean" && raw.schemaPath.endsWith("/additionalProperties")) continue;
|
|
133
|
+
const value = at(explain.value, problem.path);
|
|
134
|
+
switch (raw.keyword) {
|
|
135
|
+
case "anyOf": {
|
|
136
|
+
const members = ((at(explain.schema, raw.schemaPath) as Node | undefined)?.anyOf ??
|
|
137
|
+
[]) as Node[];
|
|
138
|
+
const each = members.map((m) => {
|
|
139
|
+
const about = gist(m);
|
|
140
|
+
return `${sample(m)}${about ? ` (${about})` : ""}`;
|
|
141
|
+
});
|
|
142
|
+
const listed =
|
|
143
|
+
each.length > 1 ? `${each.slice(0, -1).join(", ")} or ${each.at(-1)}` : each.join("");
|
|
144
|
+
say(`${where} ${JSON.stringify(value)}: ${listed}`);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case "additionalProperties": {
|
|
148
|
+
const names = (raw.params.additionalProperties as string[] | undefined) ?? [];
|
|
149
|
+
const properties = (at(explain.schema, raw.schemaPath) as Node | undefined)?.properties;
|
|
150
|
+
const known = Object.keys((properties as Node | undefined) ?? {}).join(", ");
|
|
151
|
+
const unknown = `unknown field ${names.join(", ")}`;
|
|
152
|
+
say(
|
|
153
|
+
where
|
|
154
|
+
? `${unknown} in ${where}; its fields: ${known}`
|
|
155
|
+
: `${unknown}; ${explain.noun}'s fields: ${known}`,
|
|
156
|
+
);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "required": {
|
|
160
|
+
for (const name of (raw.params.requiredProperties as string[] | undefined) ?? []) {
|
|
161
|
+
const full = where ? `${where}/${name}` : name;
|
|
162
|
+
const hint = explain.hints?.[full];
|
|
163
|
+
say(`no ${full}${hint ? `: ${hint}` : ""}`);
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case "const":
|
|
168
|
+
say(`${where} must be ${shown(raw.params.allowedValue)}`);
|
|
169
|
+
break;
|
|
170
|
+
case "pattern": {
|
|
171
|
+
const meaning = explain.patterns?.[raw.params.pattern as string];
|
|
172
|
+
if (meaning) say(`${where} is ${meaning}, not ${JSON.stringify(value)}`);
|
|
173
|
+
else lines.push(problem);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
lines.push(problem);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return lines;
|
|
181
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A version as a person declares it, on a trial or a grader: semver, `MAJOR.MINOR.PATCH` with an
|
|
3
|
+
* optional pre-release tag and build part. Kept trials and grades belong to its major, minor and
|
|
4
|
+
* pre-release tag: a patch or a build part says nothing that matters changed, and is recorded.
|
|
5
|
+
* What counts as mattering is the author's call; nothing checks it.
|
|
6
|
+
*/
|
|
7
|
+
export const SEMVER =
|
|
8
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
9
|
+
|
|
10
|
+
/** `MAJOR.MINOR.PATCH` alone: a comparison's version, which takes no tag. */
|
|
11
|
+
const RELEASE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
12
|
+
|
|
13
|
+
/** A comparison's version when it gives none. */
|
|
14
|
+
export const DEFAULT_VERSION = "1.0.0";
|
|
15
|
+
|
|
16
|
+
export function checkVersion(version: unknown): string | undefined {
|
|
17
|
+
if (typeof version !== "string") {
|
|
18
|
+
return `version is semver, such as "1.0.0": got ${JSON.stringify(version) ?? String(version)}`;
|
|
19
|
+
}
|
|
20
|
+
return SEMVER.test(version)
|
|
21
|
+
? undefined
|
|
22
|
+
: `version ${version} is not semver: {major}.{minor}.{patch}, with an optional -{tag} and +{build}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function checkRelease(version: string): string | undefined {
|
|
26
|
+
return RELEASE.test(version) ? undefined : `version ${version} is not {major}.{minor}.{patch}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What kept trials and grades are matched on: `{major}.{minor}`, and `-{tag}` when the version has
|
|
31
|
+
* one. A patch or a build part never changes it.
|
|
32
|
+
*/
|
|
33
|
+
export function versionKey(version: string): string;
|
|
34
|
+
export function versionKey(version: string | undefined): string | undefined;
|
|
35
|
+
export function versionKey(version: string | undefined): string | undefined {
|
|
36
|
+
if (version === undefined) return undefined;
|
|
37
|
+
const match = SEMVER.exec(version);
|
|
38
|
+
if (!match) return version;
|
|
39
|
+
const [, major, minor, , tag] = match;
|
|
40
|
+
return `${major}.${minor}${tag !== undefined ? `-${tag}` : ""}`;
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// bun packages/lab/src/write-schemas.ts — regenerates schema/*.schema.json from the formats.
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { LAB_SCHEMA_FILES, renderLabSchemaFile } from "./format/schema-files";
|
|
4
|
+
|
|
5
|
+
const SCHEMA_DIR = join(import.meta.dir, "..", "schema");
|
|
6
|
+
|
|
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
|
+
console.log(`wrote schema/${name}`);
|
|
10
|
+
}
|