@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.
Files changed (88) hide show
  1. package/package.json +4 -4
  2. package/schema/{case-check.schema.json → lab-check.schema.json} +1 -1
  3. package/schema/{case-config.schema.json → lab-config.schema.json} +1 -1
  4. package/schema/{case-final.schema.json → lab-final.schema.json} +6 -6
  5. package/schema/{case-grade.schema.json → lab-grade.schema.json} +1 -1
  6. package/schema/{case-key.schema.json → lab-key.schema.json} +7 -0
  7. package/schema/{case-label.schema.json → lab-label.schema.json} +3 -3
  8. package/schema/{case-loop-report.schema.json → lab-loop-report.schema.json} +26 -15
  9. package/schema/{case-loop.schema.json → lab-loop.schema.json} +1 -1
  10. package/schema/{case-plan.schema.json → lab-plan.schema.json} +14 -3
  11. package/schema/{case-proposal.schema.json → lab-proposal.schema.json} +3 -3
  12. package/schema/{case-report.schema.json → lab-report.schema.json} +272 -36
  13. package/schema/{case-run.schema.json → lab-run.schema.json} +4 -4
  14. package/schema/{case-runs.schema.json → lab-runs.schema.json} +8 -1
  15. package/schema/{case-score.schema.json → lab-score.schema.json} +2 -2
  16. package/schema/{case-spread.schema.json → lab-spread.schema.json} +6 -6
  17. package/schema/{case-trial.schema.json → lab-trial.schema.json} +9 -9
  18. package/schema/{case-try.schema.json → lab-try.schema.json} +6 -6
  19. package/schema/local.json +3 -3
  20. package/src/env/capture.ts +1 -1
  21. package/src/env/compare.ts +7 -7
  22. package/src/env/fetch.ts +1 -1
  23. package/src/env/files.ts +14 -14
  24. package/src/env/grade-helper.ts +15 -15
  25. package/src/env/grader.ts +5 -2
  26. package/src/env/index.ts +18 -18
  27. package/src/env/trial.ts +5 -2
  28. package/src/format/key.ts +24 -0
  29. package/src/format/loop.ts +20 -19
  30. package/src/format/output.ts +120 -59
  31. package/src/format/records.ts +23 -20
  32. package/src/format/schema-files.ts +30 -30
  33. package/src/format/settings.ts +20 -13
  34. package/src/format/trial-env.ts +9 -6
  35. package/src/help/awf-lab.txt +1 -1
  36. package/src/help/case.txt +5 -4
  37. package/src/help/config.txt +2 -2
  38. package/src/help/label.txt +2 -2
  39. package/src/help/loop.txt +10 -10
  40. package/src/help/report.txt +1 -1
  41. package/src/help/run.txt +11 -10
  42. package/src/help/runs.txt +4 -3
  43. package/src/help/score.txt +4 -3
  44. package/src/lab/blame.ts +1 -1
  45. package/src/lab/box.ts +7 -5
  46. package/src/lab/capture-command.ts +11 -7
  47. package/src/lab/capture.ts +1 -1
  48. package/src/lab/check-command.ts +3 -3
  49. package/src/lab/cli.ts +9 -8
  50. package/src/lab/columns.ts +5 -5
  51. package/src/lab/command-context.ts +7 -7
  52. package/src/lab/compare.ts +8 -8
  53. package/src/lab/config-command.ts +25 -20
  54. package/src/lab/dataset.ts +37 -18
  55. package/src/lab/eval-files.ts +27 -16
  56. package/src/lab/folders.ts +26 -7
  57. package/src/lab/good.ts +1 -1
  58. package/src/lab/grading-stub.txt +2 -2
  59. package/src/lab/inspect.ts +13 -12
  60. package/src/lab/labels.ts +16 -11
  61. package/src/lab/loop-command.ts +68 -64
  62. package/src/lab/loop-records.ts +5 -5
  63. package/src/lab/loop.ts +105 -100
  64. package/src/lab/rates.ts +11 -6
  65. package/src/lab/record-copies.ts +1 -1
  66. package/src/lab/report-command.ts +8 -7
  67. package/src/lab/report.ts +172 -74
  68. package/src/lab/reuse.ts +29 -21
  69. package/src/lab/run-command.ts +304 -199
  70. package/src/lab/run-report.ts +49 -22
  71. package/src/lab/runs-command.ts +35 -27
  72. package/src/lab/scaffold.ts +19 -16
  73. package/src/lab/score-command.ts +72 -64
  74. package/src/lab/score.ts +1 -1
  75. package/src/lab/store.ts +3 -3
  76. package/src/lab/{trial-stub.txt → target-stub.txt} +3 -3
  77. package/src/lab/trial-settings.ts +17 -12
  78. package/src/lab/trial.ts +19 -23
  79. package/src/lab/usage.ts +1 -0
  80. package/src/lab/workflow-graders.ts +4 -1
  81. package/src/lab/workspace.ts +16 -9
  82. package/src/loop/propose.workflow.ts +1 -1
  83. package/src/shared/compare/index.ts +2 -2
  84. package/src/shared/compare/paired.ts +20 -20
  85. package/src/shared/compare/types.ts +4 -4
  86. package/src/write-schemas.ts +3 -3
  87. /package/schema/{case-good-record.schema.json → lab-good-record.schema.json} +0 -0
  88. /package/schema/{case-previous.schema.json → lab-previous.schema.json} +0 -0
@@ -1,27 +1,27 @@
1
- import { type CaseReport, CaseReportSchema, REPORT_KIND } from "../format/output";
1
+ import { type LabReport, LabReportSchema, REPORT_KIND } from "../format/output";
2
2
  import type { RunRecord } from "../format/records";
3
3
  import { checkSchema, describeProblems } from "../shared/validate";
4
4
  import { versionKey } from "../shared/version";
5
5
  import { columnLabel } from "./columns";
6
6
  import { type Context, envOf, tmpOf } from "./command-context";
7
- import { type ColumnVerdict, compareColumns } from "./compare";
7
+ import { type ColumnDecision, compareColumns } from "./compare";
8
8
  import { comparingFile, type DatasetInfo } from "./dataset";
9
9
  import type { LabGrader } from "./grading";
10
10
  import { agreementOf, judgeLabeled, type PersonAgreement, readLabels } from "./labels";
11
11
  import { type CaseRow, newestEntries } from "./outcome";
12
12
  import { agreements, poolNumbers } from "./pooled";
13
13
  import { pairedDifference, ratesOf } from "./rates";
14
- import { type RunReport, renderRun, tagRows } from "./report";
14
+ import { notRunOf, type RunReport, renderRun, tagRows, trialSums } from "./report";
15
15
  import { type CaseBar, rowsOf } from "./runs";
16
16
  import { readableRuns, type StoredTrial } from "./store";
17
17
  import { afterMsOf } from "./trial-settings";
18
18
  import type { CaseWorkspace } from "./workspace";
19
19
 
20
- // The report a run ends with: its rows, the other columns, compare's verdicts and the person's
20
+ // The report a run ends with: its rows, the other columns, compare's decisions and the person's
21
21
  // agreement.
22
22
 
23
23
  /** `compare`'s verdict on each column but the reference; undefined when the dataset has none. */
24
- export async function columnVerdicts(
24
+ export async function columnDecisions(
25
25
  context: Context,
26
26
  {
27
27
  workspace,
@@ -36,7 +36,7 @@ export async function columnVerdicts(
36
36
  trials: readonly StoredTrial[];
37
37
  bars: ReadonlyMap<string, CaseBar>;
38
38
  },
39
- ): Promise<ColumnVerdict[] | undefined> {
39
+ ): Promise<ColumnDecision[] | undefined> {
40
40
  return compareColumns({
41
41
  run,
42
42
  trials,
@@ -105,7 +105,7 @@ function otherColumns(
105
105
 
106
106
  /**
107
107
  * How a run, report or score ends: the run's rows and the other columns', the person's agreement
108
- * and `compare`'s verdicts, rendered, and as `--json` for an exit the caller settles.
108
+ * and `compare`'s decisions, rendered, and as `--json` for an exit the caller settles.
109
109
  */
110
110
  export async function runReport(
111
111
  context: Context,
@@ -118,7 +118,7 @@ export async function runReport(
118
118
  bars: ReadonlyMap<string, CaseBar>;
119
119
  graders: readonly LabGrader[] | undefined;
120
120
  criteria: number;
121
- stale?: CaseReport["stale"];
121
+ stale?: LabReport["stale"];
122
122
  /** The run's plan was printed just before. */
123
123
  followsPlan?: boolean;
124
124
  },
@@ -133,8 +133,8 @@ export async function runReport(
133
133
  bars,
134
134
  graders: args.graders,
135
135
  });
136
- const verdicts = info
137
- ? await columnVerdicts(context, { workspace, info, run, trials, bars })
136
+ const decisions = info
137
+ ? await columnDecisions(context, { workspace, info, run, trials, bars })
138
138
  : undefined;
139
139
  const { text, exit } = renderRun({
140
140
  run,
@@ -147,17 +147,17 @@ export async function runReport(
147
147
  tagsOf: (name) => bars.get(name)?.tags ?? [],
148
148
  ungradedOf: (name) => bars.get(name)?.ungraded,
149
149
  ...(args.followsPlan ? { followsPlan: true } : {}),
150
- ...(verdicts ? { verdicts } : {}),
150
+ ...(decisions ? { decisions } : {}),
151
151
  ...personal,
152
152
  });
153
153
  return {
154
154
  rows,
155
155
  others,
156
156
  person: personal.person,
157
- verdicts,
157
+ decisions,
158
158
  text,
159
159
  exit,
160
- json: (exit: number, scored?: CaseReport["scored"]) =>
160
+ json: (exit: number, scored?: LabReport["scored"]) =>
161
161
  reportJson({
162
162
  ...(scored ? { scored } : {}),
163
163
  run,
@@ -168,7 +168,7 @@ export async function runReport(
168
168
  others,
169
169
  ...(stale !== undefined ? { stale } : {}),
170
170
  ...(personal.person ? { person: personal.person } : {}),
171
- ...(verdicts ? { verdicts } : {}),
171
+ ...(decisions ? { decisions } : {}),
172
172
  }),
173
173
  };
174
174
  }
@@ -180,23 +180,47 @@ export function reportJson(args: {
180
180
  trials: readonly StoredTrial[];
181
181
  exit: number;
182
182
  bars: ReadonlyMap<string, CaseBar>;
183
- stale?: CaseReport["stale"];
183
+ stale?: LabReport["stale"];
184
184
  withTrials?: boolean;
185
185
  others?: readonly CaseRow[][];
186
186
  person?: PersonAgreement;
187
- verdicts?: readonly ColumnVerdict[];
188
- scored?: CaseReport["scored"];
189
- }): CaseReport {
187
+ decisions?: readonly ColumnDecision[];
188
+ scored?: LabReport["scored"];
189
+ }): LabReport {
190
190
  const { run, rows, trials, exit, bars } = args;
191
191
  const own = trials.filter((t) => t.record.column === 0);
192
192
  const pooled = poolNumbers(own);
193
- const report: CaseReport = {
193
+ const decidersOf = (name: string) => bars.get(name)?.deciders;
194
+ const sumsOf = (column: number) => {
195
+ const sums = trialSums(
196
+ trials.filter((t) => t.record.column === column),
197
+ decidersOf,
198
+ );
199
+ return {
200
+ ...(sums.msMedian !== undefined ? { msMedian: sums.msMedian } : {}),
201
+ ...(sums.estimateMedian !== undefined ? { estimateMedian: sums.estimateMedian } : {}),
202
+ estimate: sums.estimate,
203
+ reusedEstimate: sums.reused,
204
+ gradingEstimate: sums.grading,
205
+ unpriced: sums.unpriced,
206
+ };
207
+ };
208
+ const idsOf = (name: string, column: number) =>
209
+ trials.flatMap((t) =>
210
+ t.record.case === name && t.record.column === column && t.record.trialId
211
+ ? [t.record.trialId]
212
+ : [],
213
+ );
214
+ const report: LabReport = {
194
215
  kind: REPORT_KIND,
195
- run: run.id,
216
+ labRun: run.id,
196
217
  dataset: run.dataset,
197
218
  partial: run.finished === undefined || run.broke !== undefined,
219
+ ...(run.stopped ? { stop: { why: run.stopped, notRun: notRunOf(run, trials) } } : {}),
198
220
  exit,
199
221
  params: run.columns[0]!.params,
222
+ code: run.folders[run.columns[0]!.folder]!,
223
+ sums: sumsOf(0),
200
224
  reused: trials.filter((t) => t.record.reused).length,
201
225
  rates: ratesOf(rows),
202
226
  tags: tagRows(rows, (name) => bars.get(name)?.tags ?? []),
@@ -206,6 +230,7 @@ export function reportJson(args: {
206
230
  ...(row.tally.none ? { none: row.tally.none } : {}),
207
231
  passed: row.tally.passed,
208
232
  trials: row.tally.trials,
233
+ trialIds: idsOf(row.name, 0),
209
234
  knownFailing: row.knownFailing,
210
235
  outcomes: row.outcomes,
211
236
  ...(row.why ? { why: row.why } : {}),
@@ -228,11 +253,12 @@ export function reportJson(args: {
228
253
  const difference = pairedDifference(rows, column);
229
254
  return {
230
255
  label: columnLabel(run, i + 1),
231
- ...(args.verdicts?.[i] ? { compare: args.verdicts[i] } : {}),
256
+ ...(args.decisions?.[i] ? { compare: args.decisions[i] } : {}),
232
257
  rates: ratesOf(column),
233
258
  ...(difference ? { difference } : {}),
234
259
  ...folder,
235
260
  params,
261
+ sums: sumsOf(i + 1),
236
262
  numbers: Object.fromEntries(
237
263
  [...theirs.graders].map(([grader, numbers]) => [
238
264
  grader,
@@ -245,6 +271,7 @@ export function reportJson(args: {
245
271
  verdict: row.tally.verdict ?? null,
246
272
  passed: row.tally.passed,
247
273
  trials: row.tally.trials,
274
+ trialIds: idsOf(row.name, i + 1),
248
275
  })),
249
276
  };
250
277
  }),
@@ -253,7 +280,7 @@ export function reportJson(args: {
253
280
  ...(args.withTrials ? { trials: trials.map((t) => ({ ...t.record, scores: t.scores })) } : {}),
254
281
  ...(args.scored ? { scored: args.scored } : {}),
255
282
  };
256
- const checked = checkSchema(CaseReportSchema, report);
283
+ const checked = checkSchema(LabReportSchema, report);
257
284
  if (!checked.ok) throw new Error(describeProblems("report --json", checked.problems));
258
285
  return report;
259
286
  }
@@ -1,21 +1,20 @@
1
1
  import { basename } from "node:path";
2
- import { type CaseRuns, CaseRunsSchema, RUNS_KIND } from "../format/output";
2
+ import { type LabRuns, LabRunsSchema, RUNS_KIND } from "../format/output";
3
3
  import type { RunRecord } from "../format/records";
4
4
  import { checkSchema, describeProblems } from "../shared/validate";
5
5
  import { type Context, loadDataset, workspaceOf } from "./command-context";
6
6
  import { graderSpecs } from "./dataset";
7
- import { incumbentOf, loopIdOf, readLoopFolders, readTries } from "./loop";
8
- import { trialOutcome } from "./outcome";
7
+ import { bestSoFarOf, loopIdOf, readLoopFolders, readTries } from "./loop";
8
+ import { caseRow } from "./outcome";
9
9
  import { barsOf, type CaseBar } from "./runs";
10
10
  import { readRunRecord, readTrials, runIds, type StoredTrial, UnreadableRecord } from "./store";
11
11
  import { plural } from "./text";
12
- import { caseVerdict } from "./verdict";
13
12
  import type { CaseWorkspace } from "./workspace";
14
13
 
15
14
  type Listed =
16
- | { at: string; run: CaseRuns["runs"][number] }
17
- | { at: string; loop: CaseRuns["loops"][number] }
18
- | { at: string; unread: CaseRuns["unread"][number]; dataset?: string };
15
+ | { at: string; run: LabRuns["runs"][number] }
16
+ | { at: string; loop: LabRuns["loops"][number] }
17
+ | { at: string; unread: LabRuns["unread"][number]; dataset?: string };
19
18
 
20
19
  /** `runs`: the store's runs and loops, newest first, and any run whose records don't read. */
21
20
  export function runs(context: Context): number {
@@ -65,19 +64,19 @@ export function runs(context: Context): number {
65
64
  dataset: loop.dataset,
66
65
  started: loop.started,
67
66
  tries: tries.length,
68
- kept: incumbentOf(tries),
67
+ kept: bestSoFarOf(tries),
69
68
  },
70
69
  });
71
70
  }
72
71
  listed.sort((a, b) => (a.at < b.at ? 1 : a.at > b.at ? -1 : 0));
73
72
  if (context.options.json) {
74
- const json: CaseRuns = {
73
+ const json: LabRuns = {
75
74
  kind: RUNS_KIND,
76
75
  runs: listed.flatMap((l) => ("run" in l ? [l.run] : [])),
77
76
  loops: listed.flatMap((l) => ("loop" in l ? [l.loop] : [])),
78
77
  unread: listed.flatMap((l) => ("unread" in l ? [l.unread] : [])),
79
78
  };
80
- const checked = checkSchema(CaseRunsSchema, json);
79
+ const checked = checkSchema(LabRunsSchema, json);
81
80
  if (!checked.ok) throw new Error(describeProblems("runs --json", checked.problems));
82
81
  context.stdout(JSON.stringify(json, null, 2));
83
82
  return 0;
@@ -89,20 +88,23 @@ export function runs(context: Context): number {
89
88
  const { id, dataset, tries, kept } = l.loop;
90
89
  return `${id} ${dataset} loop, ${tries} ${tries === 1 ? "try" : "tries"}, ${kept === 0 ? "keeps the start" : `keeps try ${kept}`}`;
91
90
  }
92
- const { id, dataset, cases, trials, columns, state, verdicts } = l.run;
93
- const counted = (["passed", "failed", "flaky", "unclear", "none"] as const)
91
+ const { id, dataset, cases, trials, columns, state, stopped, verdicts } = l.run;
92
+ const counted = (["passed", "failed", "flaky", "unclear", "knownFailing", "none"] as const)
94
93
  .filter((v) => (verdicts[v] ?? 0) > 0)
95
- .map((v) => `${v === "none" ? "no verdict" : v} ${verdicts[v]}`);
94
+ .map(
95
+ (v) =>
96
+ `${v === "none" ? "no verdict" : v === "knownFailing" ? "known failing" : v} ${verdicts[v]}`,
97
+ );
96
98
  return [
97
- `${id} ${dataset} ${plural(cases, "case")}, ${plural(trials, "trial")}${columns > 1 ? `, ${columns} columns` : ""}`,
98
- state === "broke" ? "the lab broke" : state,
99
+ `${id} ${dataset} ${plural(cases, "case")}, ${plural(trials, "trial")}${columns > 1 ? ` in ${columns} columns` : ""}`,
100
+ state === "broke" ? "the lab broke" : stopped ? STOPS[stopped] : state,
99
101
  ...(counted.length > 0 ? [counted.join(" · ")] : []),
100
102
  ].join(" ");
101
103
  });
102
104
  // Nearly always an older lab's records: the count is enough here, --json names each and why.
103
105
  if (unread.length > 0) {
104
106
  lines.push(
105
- `${unread.length === 1 ? "1 run or loop" : `${unread.length} runs or loops`} whose records don't read, left out (--json names them)`,
107
+ `${unread.length === 1 ? "1 run or loop" : `${unread.length} runs or loops`} whose records don't read, left out: older records this lab won't read, in ${workspace.store} (--json names them)`,
106
108
  );
107
109
  }
108
110
  context.stdout(
@@ -134,30 +136,36 @@ function barsBy(
134
136
  };
135
137
  }
136
138
 
139
+ /** How a stopped run is said: as its report says it. */
140
+ const STOPS: Record<NonNullable<RunRecord["stopped"]>, string> = {
141
+ budget: "stopped at --budget",
142
+ compare: "stopped by the comparison",
143
+ precondition: "stopped on preconditions",
144
+ stage: "stopped: a stage never entered",
145
+ };
146
+
147
+ /** A run's line in the list, its verdicts as its report counts them. */
137
148
  function runOf(
138
149
  run: RunRecord,
139
150
  trials: readonly StoredTrial[],
140
151
  bars: ReadonlyMap<string, CaseBar>,
141
- ): CaseRuns["runs"][number] {
142
- const verdicts: CaseRuns["runs"][number]["verdicts"] = {};
152
+ ): LabRuns["runs"][number] {
153
+ const verdicts: LabRuns["runs"][number]["verdicts"] = {};
143
154
  for (const { case: name, trials: asked } of run.asked) {
144
- const bar = bars.get(name);
145
- const outcomes = trials
146
- .filter((t) => t.record.case === name && t.record.column === 0)
147
- .map((t) => trialOutcome(t.record, t.scores, bar?.deciders).outcome);
148
- const verdict =
149
- outcomes.length === 0
150
- ? "none"
151
- : (caseVerdict(outcomes, asked, bar?.pass ?? "all").verdict ?? "none");
155
+ const bar = bars.get(name) ?? { pass: "all", knownFailing: false, tags: [] };
156
+ const own = trials.filter((t) => t.record.case === name && t.record.column === 0);
157
+ const row = caseRow(name, own, asked, bar.pass, bar.knownFailing, [], bar.deciders);
158
+ const verdict = row.knownFailing ? "knownFailing" : (row.tally.verdict ?? "none");
152
159
  verdicts[verdict] = (verdicts[verdict] ?? 0) + 1;
153
160
  }
154
161
  return {
155
162
  id: run.id,
156
163
  dataset: run.dataset,
157
164
  cases: run.asked.length,
158
- trials: run.asked.reduce((sum, a) => sum + a.trials, 0),
165
+ trials: trials.length,
159
166
  columns: run.columns.length,
160
167
  state: run.broke ? "broke" : run.finished ? "finished" : "partial",
168
+ ...(run.stopped && !run.broke ? { stopped: run.stopped } : {}),
161
169
  verdicts,
162
170
  };
163
171
  }
@@ -1,17 +1,19 @@
1
1
  import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { KEY_FILE } from "./dataset";
4
- import { GRADING_FILE, LOCAL_FILE, STUB_LINE, TRIAL_FILE } from "./eval-files";
4
+ import { GRADING_FILE, LOCAL_FILE, STUB_LINE, TARGET_FILE } from "./eval-files";
5
5
  import GRADING_STUB from "./grading-stub.txt" with { type: "text" };
6
6
  import { newMarker } from "./marker";
7
7
  import { Refusal } from "./refusal";
8
- import STUB_BODY from "./trial-stub.txt" with { type: "text" };
8
+ import STUB_BODY from "./target-stub.txt" with { type: "text" };
9
9
  import { type CaseWorkspace, folderDatasets } from "./workspace";
10
10
 
11
11
  const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
12
12
 
13
+ // A draft, so the empty stub is never graded as a case until its key is written.
13
14
  const key = (marker: string) => `---
14
15
  marker: ${marker}
16
+ draft: true
15
17
  # expect:
16
18
  # done: true
17
19
  # must:
@@ -23,13 +25,13 @@ marker: ${marker}
23
25
  Why this case exists.
24
26
  `;
25
27
 
26
- export type Made = { written: string[]; caseDir: string };
28
+ export type Made = { written: string[]; made: string[]; caseDir: string };
27
29
 
28
30
  /**
29
31
  * `case new {dataset}/{case}`: the case folder, its `input/` and its key's marker, in the
30
- * dataset's data folder; for a dataset not yet there, the folder `evals/{dataset}/` with stub
31
- * `trial.ts` and `grading.ts`, and the line in `evals/.gitignore` that keeps the local file out
32
- * of git.
32
+ * dataset's data folder, the key a draft; for a dataset not yet there, the folder
33
+ * `evals/{dataset}/` with stub `target.ts` and `grading.ts`, and the line in `evals/.gitignore`
34
+ * that keeps the local file out of git.
33
35
  */
34
36
  export function newCase(
35
37
  evals: string,
@@ -73,19 +75,20 @@ export function newCase(
73
75
  };
74
76
  if (!known.some((d) => d.name === datasetName)) {
75
77
  mkdirSync(dataDir, { recursive: true });
76
- const trialFile = join(dataDir, TRIAL_FILE);
78
+ const trialFile = join(dataDir, TARGET_FILE);
77
79
  if (!existsSync(trialFile)) write(trialFile, `${STUB_LINE} ${STUB_BODY}`);
78
80
  const gradingFile = join(dataDir, GRADING_FILE);
79
81
  if (!existsSync(gradingFile)) write(gradingFile, GRADING_STUB);
82
+ const ignore = join(evals, ".gitignore");
83
+ const lines = existsSync(ignore) ? readFileSync(ignore, "utf8").split("\n") : [];
84
+ if (!lines.some((line) => line.trim() === LOCAL_FILE || line.trim() === `/${LOCAL_FILE}`)) {
85
+ const before = lines.length > 0 && lines.at(-1) !== "" ? "\n" : "";
86
+ appendFileSync(ignore, `${before}${LOCAL_FILE}\n`);
87
+ written.push(ignore);
88
+ }
80
89
  }
81
- const ignore = join(evals, ".gitignore");
82
- const lines = existsSync(ignore) ? readFileSync(ignore, "utf8").split("\n") : [];
83
- if (!lines.some((line) => line.trim() === LOCAL_FILE || line.trim() === `/${LOCAL_FILE}`)) {
84
- const before = lines.length > 0 && lines.at(-1) !== "" ? "\n" : "";
85
- appendFileSync(ignore, `${before}${LOCAL_FILE}\n`);
86
- written.push(ignore);
87
- }
88
- mkdirSync(join(caseDir, "input"), { recursive: true });
90
+ const input = join(caseDir, "input");
91
+ mkdirSync(input, { recursive: true });
89
92
  write(join(caseDir, KEY_FILE), key(newMarker()));
90
- return { written, caseDir };
93
+ return { written, made: [input], caseDir };
91
94
  }
@@ -1,4 +1,4 @@
1
- import { type CasePlan, PLAN_KIND } from "../format/output";
1
+ import { type LabPlan, PLAN_KIND } from "../format/output";
2
2
  import {
3
3
  budgetExit,
4
4
  type Context,
@@ -17,7 +17,7 @@ import {
17
17
  } from "./command-context";
18
18
  import { clearStale } from "./folders";
19
19
  import type { LabGrader } from "./grading";
20
- import { checkTrialScript } from "./inspect";
20
+ import { checkTargetScript } from "./inspect";
21
21
  import { writeRecords } from "./record-copies";
22
22
  import { Refusal } from "./refusal";
23
23
  import { runReport } from "./run-report";
@@ -27,7 +27,7 @@ import { readTrials } from "./store";
27
27
  import { usd } from "./text";
28
28
 
29
29
  /**
30
- * Grades a kept run again, without running a trial: never `trial.ts` or the workflow. `facts`
30
+ * Grades a kept run again, without running a trial: never `target.ts` or the workflow. `facts`
31
31
  * reads each trial record again.
32
32
  * Graders in `grading.ts`'s order, each skipped again while one before it still fails the trial.
33
33
  * `--grader` names one alone, a `manual` one included.
@@ -42,7 +42,7 @@ export async function score(context: Context, names: readonly string[]): Promise
42
42
  context,
43
43
  workspace,
44
44
  info,
45
- checkoutFolder(context, workspace, () => checkTrialScript(info.evalDir)),
45
+ checkoutFolder(context, workspace, () => checkTargetScript(info.evalDir)),
46
46
  now,
47
47
  );
48
48
  let chosen: LabGrader[];
@@ -90,11 +90,11 @@ export async function score(context: Context, names: readonly string[]): Promise
90
90
  perCase.set(item.trial.record.case, (perCase.get(item.trial.record.case) ?? 0) + 1);
91
91
  }
92
92
  const atOnce = workspace.concurrency;
93
- const planJson: CasePlan = {
93
+ const planJson: LabPlan = {
94
94
  kind: PLAN_KIND,
95
95
  command: "score",
96
96
  dataset: info.name,
97
- run: run.id,
97
+ labRun: run.id,
98
98
  cases: [...perCase].map(([name, n]) => ({ case: name, trials: n })),
99
99
  columns: run.columns.length,
100
100
  trials: plan.items.length,
@@ -113,75 +113,83 @@ export async function score(context: Context, names: readonly string[]): Promise
113
113
  concurrency: atOnce,
114
114
  };
115
115
  if (options.dryRun) {
116
- if (options.json) printPlan(context, planJson);
117
- else context.stdout(described);
116
+ if (options.json) {
117
+ printPlan(context, {
118
+ ...planJson,
119
+ ...(plan.items.length === 0 ? { nothing: "every grade is current" } : {}),
120
+ });
121
+ } else context.stdout(described);
118
122
  return 0;
119
123
  }
120
- let done: ScoreDone | undefined;
121
- if (plan.items.length > 0) {
122
- if (!(await confirmPlan(context, described, "grade them?"))) {
123
- stderr("declined; nothing graded");
124
- return 2;
125
- }
126
- done = await withLock(context, workspace, async () => {
127
- try {
128
- clearStale(tmp);
129
- return await runScore({
130
- plan,
131
- tmp,
132
- run: run.id,
133
- store: workspace.store,
134
- env: envOf(context),
135
- ...(options.budget !== undefined ? { budget: options.budget } : {}),
136
- atOnce,
137
- now,
138
- progress: stderr,
139
- });
140
- } finally {
141
- if (info.records) writeRecords(workspace.store, info.records, run.id);
142
- }
124
+ const reported = () =>
125
+ runReport(context, workspace, {
126
+ info,
127
+ run,
128
+ trials: readTrials(workspace.store, run.id),
129
+ bars: barsOf(info, cases, graders),
130
+ graders,
131
+ criteria: criteriaCount(
132
+ cases,
133
+ run.asked.map((a) => a.case),
134
+ ),
143
135
  });
144
- } else stderr(described);
145
- const rendered = await runReport(context, workspace, {
146
- info,
147
- run,
148
- trials: readTrials(workspace.store, run.id),
149
- bars: barsOf(info, cases, graders),
150
- graders,
151
- criteria: criteriaCount(
152
- cases,
153
- run.asked.map((a) => a.case),
154
- ),
136
+ // With nothing to grade, the report would only say again what the run's already did; its exit
137
+ // code stands.
138
+ if (plan.items.length === 0) {
139
+ const { exit } = await reported();
140
+ if (options.json) printPlan(context, { ...planJson, nothing: "every grade is current" });
141
+ else context.stdout(described);
142
+ return exit;
143
+ }
144
+ if (!(await confirmPlan(context, described, "grade them?"))) {
145
+ stderr("declined; nothing graded");
146
+ return 2;
147
+ }
148
+ const done: ScoreDone = await withLock(context, workspace, async () => {
149
+ try {
150
+ clearStale(tmp);
151
+ return await runScore({
152
+ plan,
153
+ tmp,
154
+ run: run.id,
155
+ store: workspace.store,
156
+ env: envOf(context),
157
+ ...(options.budget !== undefined ? { budget: options.budget } : {}),
158
+ atOnce,
159
+ now,
160
+ progress: stderr,
161
+ });
162
+ } finally {
163
+ if (info.records) writeRecords(workspace.store, info.records, run.id);
164
+ }
155
165
  });
156
- const exit = budgetExit(done?.stopped ?? false, rendered.exit);
166
+ const rendered = await reported();
167
+ const exit = budgetExit(done.stopped, rendered.exit);
157
168
  if (options.json) {
158
169
  const scored = {
159
- graded: Object.fromEntries(done?.graded ?? []),
160
- errored: Object.fromEntries(done?.errored ?? []),
161
- estimate: done?.estimate ?? 0,
162
- stopped: done?.stopped ?? false,
170
+ graded: Object.fromEntries(done.graded),
171
+ errored: Object.fromEntries(done.errored),
172
+ estimate: done.estimate,
173
+ stopped: done.stopped,
163
174
  };
164
175
  context.stdout(JSON.stringify(rendered.json(exit, scored), null, 2));
165
176
  return exit;
166
177
  }
167
- const lines: string[] = [];
168
- if (done) {
169
- const counted = (map: Map<string, number>) =>
170
- [...map].map(([name, n]) => `${name} ×${n}`).join(", ");
171
- lines.push(
172
- [
173
- `graded again: ${counted(done.graded) || "nothing"}`,
174
- ...(done.errored.size > 0 ? [`errored: ${counted(done.errored)}`] : []),
175
- ...(done.estimate > 0 ? [`est. ${usd(done.estimate)}`] : []),
176
- ...(done.stopped
177
- ? [`stopped at the budget, ${usd(options.budget!)}: the rest is not graded`]
178
- : []),
179
- ].join(" · "),
180
- "",
181
- );
182
- }
178
+ const counted = (map: Map<string, number>) =>
179
+ [...map].map(([name, n]) => `${name} ×${n}`).join(", ");
180
+ const lines = [
181
+ [
182
+ `graded again: ${counted(done.graded) || "nothing"}`,
183
+ ...(done.errored.size > 0 ? [`errored: ${counted(done.errored)}`] : []),
184
+ ...(done.estimate > 0 ? [`est. ${usd(done.estimate)}`] : []),
185
+ ...(done.stopped
186
+ ? [`stopped at the budget, ${usd(options.budget!)}: the rest is not graded`]
187
+ : []),
188
+ ].join(" · "),
189
+ "",
190
+ ];
183
191
  const text =
184
- done?.stopped && rendered.exit === 0
192
+ done.stopped && rendered.exit === 0
185
193
  ? rendered.text.replace(/exit 0: .*$/, "exit 3: score stopped at its budget")
186
194
  : rendered.text;
187
195
  context.stdout([...lines, text].join("\n"));
package/src/lab/score.ts CHANGED
@@ -229,7 +229,7 @@ export async function regradePlan(args: {
229
229
  /** The plan in lines, for the operator. */
230
230
  export function describePlan(plan: ScorePlan, run: string): string {
231
231
  const lines: string[] = [];
232
- if (plan.items.length === 0) lines.push(`nothing in run ${run} to grade again`);
232
+ if (plan.items.length === 0) lines.push(`nothing to grade: every grade in run ${run} is current`);
233
233
  else {
234
234
  const graders = [
235
235
  ...[...plan.counts].map(([name, n]) => `${name} ×${n}`),
package/src/lab/store.ts CHANGED
@@ -34,7 +34,7 @@ export const SCORES_FILE = "scores.jsonl";
34
34
  /** In a run's trial folder in place of `trial.json`: the trial it reuses, where that one ran. */
35
35
  export const REUSED_FILE = "reused.json";
36
36
 
37
- export type TrialRef = { run: string; column: number; trial: number };
37
+ export type TrialRef = { labRun: string; column: number; trial: number };
38
38
 
39
39
  export const awfRunsOf = (store: string) => join(store, "awf-runs");
40
40
  export const runDirOf = (store: string, id: string) => join(store, "runs", id);
@@ -364,13 +364,13 @@ export function readTrials(store: string, id: string): StoredTrial[] {
364
364
  const pointer = join(dir, REUSED_FILE);
365
365
  if (existsSync(pointer)) {
366
366
  const ref = readJson(pointer) as TrialRef;
367
- const at = trialDirOf(store, ref.run, name, ref.column, ref.trial);
367
+ const at = trialDirOf(store, ref.labRun, name, ref.column, ref.trial);
368
368
  const ran = readSlot(at);
369
369
  if (!ran) continue; // the run it reuses is gone from this store
370
370
  const [column, trial] = slot.split("-").map(Number) as [number, number];
371
371
  found.push({
372
372
  dir: at,
373
- record: { ...ran.record, run: id, column, trial, reused: ref },
373
+ record: { ...ran.record, labRun: id, column, trial, reused: ref },
374
374
  scores: ran.scores,
375
375
  });
376
376
  continue;
@@ -1,14 +1,14 @@
1
1
  Fill in workflow and setup, then delete this line: run refuses the file until then.
2
- import { defineTrial } from "@agentswf/lab";
2
+ import { defineTarget } from "@agentswf/lab";
3
3
 
4
- export default defineTrial({
4
+ export default defineTarget({
5
5
  // Bump the minor, or add a -{tag}, for a change that should rerun the kept trials.
6
6
  version: "1.0.0",
7
7
  // The workflow as it ships, imported lazily so the mocks setup makes exist before it loads.
8
8
  workflow: () => import("../../path/to/workflow"),
9
9
  // The whole trial runs in the lab's sandbox, everything closed, unless sandbox says otherwise:
10
10
  // sandbox: { by: "workflow" } runs the agents in the sandboxes the workflow opens instead, and
11
- // sandbox.network opens what a trial may reach. limits: { setup, run, after } are 10m, 30m, 10m.
11
+ // sandbox.network opens what a trial may reach. limits: { setup, workflow, after } are 10m, 30m, 10m.
12
12
 
13
13
  setup(trial) {
14
14
  // Build the case's world from trial.readJson(...) and trial.readText(...), the case's input/, with trial.mock("name", module, { … }), trial.fake and trial.mockFetch.