@agentswf/lab 0.0.0-stage → 0.3.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/case-check.schema.json +64 -0
- package/schema/case-config.schema.json +187 -0
- package/schema/case-final.schema.json +48 -0
- package/schema/case-good-record.schema.json +70 -0
- package/schema/case-grade.schema.json +49 -0
- package/schema/case-key.schema.json +117 -0
- package/schema/case-label.schema.json +32 -0
- package/schema/case-loop-report.schema.json +210 -0
- package/schema/case-loop.schema.json +141 -0
- package/schema/case-plan.schema.json +117 -0
- package/schema/case-previous.schema.json +70 -0
- package/schema/case-proposal.schema.json +52 -0
- package/schema/case-report.schema.json +892 -0
- package/schema/case-run.schema.json +253 -0
- package/schema/case-runs.schema.json +125 -0
- package/schema/case-score.schema.json +319 -0
- package/schema/case-spread.schema.json +110 -0
- package/schema/case-trial.schema.json +543 -0
- package/schema/case-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 +128 -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 +182 -0
- package/src/format/key.ts +144 -0
- package/src/format/loop.ts +178 -0
- package/src/format/output.ts +481 -0
- package/src/format/records.ts +440 -0
- package/src/format/schema-files.ts +64 -0
- package/src/format/settings.ts +552 -0
- package/src/format/trial-env.ts +64 -0
- package/src/format/trial-file.ts +134 -0
- package/src/help/awf-lab.txt +29 -0
- package/src/help/case.txt +38 -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 +60 -0
- package/src/help/runs.txt +10 -0
- package/src/help/score.txt +27 -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 +249 -0
- package/src/lab/capture-command.ts +298 -0
- package/src/lab/capture.ts +234 -0
- package/src/lab/check-command.ts +187 -0
- package/src/lab/cli.ts +324 -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 +278 -0
- package/src/lab/criteria.ts +69 -0
- package/src/lab/dataset.ts +356 -0
- package/src/lab/eval-files.ts +185 -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 +153 -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 +226 -0
- package/src/lab/labels.ts +206 -0
- package/src/lab/loop-code.ts +255 -0
- package/src/lab/loop-command.ts +770 -0
- package/src/lab/loop-records.ts +144 -0
- package/src/lab/loop.ts +859 -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 +150 -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 +156 -0
- package/src/lab/report.ts +838 -0
- package/src/lab/reuse.ts +126 -0
- package/src/lab/run-command.ts +853 -0
- package/src/lab/run-logs.ts +89 -0
- package/src/lab/run-report.ts +259 -0
- package/src/lab/runs-command.ts +163 -0
- package/src/lab/runs.ts +172 -0
- package/src/lab/scaffold.ts +91 -0
- package/src/lab/score-command.ts +189 -0
- package/src/lab/score.ts +396 -0
- package/src/lab/store.ts +383 -0
- package/src/lab/text.ts +29 -0
- package/src/lab/trial-settings.ts +100 -0
- package/src/lab/trial-stub.txt +18 -0
- package/src/lab/trial.ts +443 -0
- package/src/lab/usage.ts +273 -0
- package/src/lab/verdict.ts +161 -0
- package/src/lab/workflow-graders.ts +161 -0
- package/src/lab/workspace.ts +489 -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
package/src/lab/reuse.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { Params, TrialRecord } from "../format/records";
|
|
4
|
+
import { versionKey } from "../shared/version";
|
|
5
|
+
import { type CaseInfo, folderDigest, sha256 } from "./dataset";
|
|
6
|
+
import { buildCase } from "./folders";
|
|
7
|
+
import { canonical } from "./grading";
|
|
8
|
+
import { trialOutcome } from "./outcome";
|
|
9
|
+
import { REUSED_FILE, readableRuns, type StoredTrial, type TrialRef, trialDirOf } from "./store";
|
|
10
|
+
import type { ResolvedSettings } from "./trial-settings";
|
|
11
|
+
import { durationMs } from "./trial-settings";
|
|
12
|
+
|
|
13
|
+
// A stored trial is reused while what it was declared and given matches (lab-config, Versions):
|
|
14
|
+
// the version's major, minor and pre-release tag, the `agentswf` and lab versions, the resolved
|
|
15
|
+
// trial settings and parameters as values, and the built case by its content. The lab never looks
|
|
16
|
+
// at the code: a change the person didn't version reuses the trials, and `--fresh` runs them again.
|
|
17
|
+
|
|
18
|
+
export { REUSE_DAYS } from "./workspace";
|
|
19
|
+
|
|
20
|
+
/** This lab's own version, which a trial's record is made by. */
|
|
21
|
+
export const LAB_VERSION: string = JSON.parse(
|
|
22
|
+
readFileSync(join(import.meta.dir, "../../package.json"), "utf8"),
|
|
23
|
+
).version;
|
|
24
|
+
|
|
25
|
+
export function reuseKey(parts: {
|
|
26
|
+
/** The column's version: its `trial.ts`'s, or a loop's id of its code. */
|
|
27
|
+
version: string;
|
|
28
|
+
params: Params;
|
|
29
|
+
input: string;
|
|
30
|
+
/** The column's sandbox and limits, resolved. */
|
|
31
|
+
settings: ResolvedSettings;
|
|
32
|
+
awf: string;
|
|
33
|
+
}): string {
|
|
34
|
+
// A limit is its length, however written: 60s and 1m are one setting.
|
|
35
|
+
const { limits } = parts.settings;
|
|
36
|
+
const settings = {
|
|
37
|
+
...parts.settings,
|
|
38
|
+
limits: {
|
|
39
|
+
setup: durationMs(limits.setup),
|
|
40
|
+
run: durationMs(limits.run),
|
|
41
|
+
after: durationMs(limits.after),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
return sha256(
|
|
45
|
+
canonical({ ...parts, settings, version: versionKey(parts.version), lab: LAB_VERSION }),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A stored trial that may stand in for a new one: it ran to an end the workflow owns. */
|
|
50
|
+
function reusable(record: TrialRecord, now: Date, days: number): boolean {
|
|
51
|
+
// One whose grading couldn't start is kept: `grading.ts` is what to fix, and grades it again.
|
|
52
|
+
const errored = record.errored && record.errored.phase !== "facts";
|
|
53
|
+
if (!record.reuse || !record.runId || record.leaked || errored) return false;
|
|
54
|
+
if (record.stopped !== undefined) return false;
|
|
55
|
+
return now.getTime() - Date.parse(record.at) <= days * 86_400_000;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The stored trials of a dataset each reuse key may take, newest first, one per workflow run (a
|
|
60
|
+
* reused trial is a copy, and never counts twice).
|
|
61
|
+
*/
|
|
62
|
+
export function reusableTrials(
|
|
63
|
+
store: string,
|
|
64
|
+
dataset: string,
|
|
65
|
+
now: Date,
|
|
66
|
+
days: number,
|
|
67
|
+
): Map<string, StoredTrial[]> {
|
|
68
|
+
const byKey = new Map<string, StoredTrial[]>();
|
|
69
|
+
const seen = new Set<string>();
|
|
70
|
+
for (const { trials } of readableRuns(store, { dataset, newest: true })) {
|
|
71
|
+
for (const trial of trials.sort((a, b) => b.record.at.localeCompare(a.record.at))) {
|
|
72
|
+
const { record } = trial;
|
|
73
|
+
if (!reusable(record, now, days) || seen.has(record.runId!)) continue;
|
|
74
|
+
seen.add(record.runId!);
|
|
75
|
+
// A trial the lab couldn't grade for its own reasons is run again rather than kept, and so is
|
|
76
|
+
// one whose workflow threw: a fix to the bug should show on the next run, bumped or not.
|
|
77
|
+
if (
|
|
78
|
+
record.workflowError !== undefined ||
|
|
79
|
+
(trialOutcome(record, trial.scores).outcome === "errored" &&
|
|
80
|
+
record.errored?.phase !== "facts")
|
|
81
|
+
)
|
|
82
|
+
continue;
|
|
83
|
+
byKey.set(record.reuse!, [...(byKey.get(record.reuse!) ?? []), trial]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return byKey;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Puts a stored trial in a run as that run's trial: a pointer to where it ran, never a copy. */
|
|
90
|
+
export function reuseTrial(
|
|
91
|
+
store: string,
|
|
92
|
+
run: string,
|
|
93
|
+
from: StoredTrial,
|
|
94
|
+
column: number,
|
|
95
|
+
trial: number,
|
|
96
|
+
): void {
|
|
97
|
+
const dir = trialDirOf(store, run, from.record.case, column, trial);
|
|
98
|
+
mkdirSync(dir, { recursive: true });
|
|
99
|
+
const ref: TrialRef = from.record.reused ?? {
|
|
100
|
+
run: from.record.run,
|
|
101
|
+
column: from.record.column,
|
|
102
|
+
trial: from.record.trial,
|
|
103
|
+
};
|
|
104
|
+
writeFileSync(join(dir, REUSED_FILE), `${JSON.stringify(ref)}\n`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Each case built once, as a trial would see it, for its digest. */
|
|
108
|
+
export function caseDigests(
|
|
109
|
+
dataDir: string,
|
|
110
|
+
cases: readonly CaseInfo[],
|
|
111
|
+
tmp: string,
|
|
112
|
+
): Map<string, string> {
|
|
113
|
+
const digests = new Map<string, string>();
|
|
114
|
+
const scratch = mkdtempSync(join(tmp, "awf-lab-reuse-"));
|
|
115
|
+
try {
|
|
116
|
+
for (const [i, info] of cases.entries()) {
|
|
117
|
+
const built = join(scratch, String(i));
|
|
118
|
+
mkdirSync(built);
|
|
119
|
+
buildCase(dataDir, info, built);
|
|
120
|
+
digests.set(info.name, folderDigest(built));
|
|
121
|
+
}
|
|
122
|
+
} finally {
|
|
123
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
124
|
+
}
|
|
125
|
+
return digests;
|
|
126
|
+
}
|