@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,8 +1,8 @@
1
1
  import { existsSync, realpathSync } from "node:fs";
2
2
  import { dirname, join, relative, resolve } from "node:path";
3
- import { type CasePlan, PLAN_KIND } from "../format/output";
3
+ import { type LabPlan, PLAN_KIND } from "../format/output";
4
4
  import { type Column, type Params, RUN_KIND, type RunRecord } from "../format/records";
5
- import type { Limits, TrialFile } from "../format/settings";
5
+ import type { Limits, TargetFile } from "../format/settings";
6
6
  import { versionKey } from "../shared/version";
7
7
  import {
8
8
  columnLabel,
@@ -30,16 +30,16 @@ import {
30
30
  workspaceOf,
31
31
  } from "./command-context";
32
32
  import { type CaseInfo, type DatasetInfo, judgesSentences } from "./dataset";
33
- import { checkTrialFile, describeFiles, TRIAL_FILE } from "./eval-files";
33
+ import { checkTargetFile, describeFiles, TARGET_FILE } from "./eval-files";
34
34
  import type { FactsReader } from "./facts";
35
35
  import { clearStale } from "./folders";
36
36
  import { gitState } from "./git";
37
37
  import type { LabGrader } from "./grading";
38
- import { checkTrialScript, type FolderSetup, inspectFolder } from "./inspect";
38
+ import { checkTargetScript, type FolderSetup, inspectFolder } from "./inspect";
39
39
  import { failedPrecondition, gradingSpend, scoresInRun, trialOutcome, trialSpend } from "./outcome";
40
40
  import { writeRecords } from "./record-copies";
41
41
  import { Refusal } from "./refusal";
42
- import { caseDigests, reusableTrials, reuseKey, reuseTrial } from "./reuse";
42
+ import { type BuiltCase, buildCases, reusableTrials, reuseKey, reuseTrial } from "./reuse";
43
43
  import { runReport } from "./run-report";
44
44
  import { barsOf, type CaseBar, criteriaCount, failedCases } from "./runs";
45
45
  import { regradePlan, runScore, type ScoreDone, type ScorePlan } from "./score";
@@ -64,7 +64,7 @@ import { type CaseWorkspace, codeFolderOf, inside } from "./workspace";
64
64
  * the next case; and after each case whether to stop, from the trials so far.
65
65
  */
66
66
  export type RunGiven = {
67
- /** Each with the loop's id of its code, which stands in for a version: no `trial.ts` is asked. */
67
+ /** Each with the loop's id of its code, which stands in for a version: no `target.ts` is asked. */
68
68
  folders?: readonly { dir: string; version: string }[];
69
69
  order?: readonly string[];
70
70
  stop?: (run: RunRecord, trials: readonly StoredTrial[]) => Promise<boolean>;
@@ -85,12 +85,12 @@ export type RunDone = { exit: number; id?: string; unstarted?: string };
85
85
  class LabBroke extends Error {}
86
86
 
87
87
  /**
88
- * A folder of code, its `trial.ts`, the version its trials run under, the sandbox and limits its
89
- * own `trial.ts` gives with `--limit` over them, and its git state.
88
+ * A folder of code, its `target.ts`, the version its trials run under, the sandbox and limits its
89
+ * own `target.ts` gives with `--limit` over them, and its git state.
90
90
  */
91
91
  type CodeFolder = {
92
92
  folder: FolderSetup;
93
- trialScript: string;
93
+ targetScript: string;
94
94
  version: string;
95
95
  settings: ResolvedSettings;
96
96
  state: ReturnType<typeof gitState>;
@@ -118,9 +118,9 @@ export async function run(context: Context, given: RunGiven = {}): Promise<RunDo
118
118
  }
119
119
  const now = environment.now ?? (() => new Date());
120
120
  const limits = readLimits(options.limit);
121
- let checkedTrial: string | undefined;
122
- const trialScriptOf = () => (checkedTrial ??= checkTrialScript(info.evalDir));
123
- const folderOf = checkoutFolder(context, workspace, trialScriptOf);
121
+ let checkedTarget: string | undefined;
122
+ const targetScriptOf = () => (checkedTarget ??= checkTargetScript(info.evalDir));
123
+ const folderOf = checkoutFolder(context, workspace, targetScriptOf);
124
124
  const graders = await datasetGraders(context, workspace, info, folderOf, now);
125
125
  const facts = datasetFacts(context, workspace, info);
126
126
  const bars = barsOf(info, cases, graders);
@@ -128,11 +128,22 @@ export async function run(context: Context, given: RunGiven = {}): Promise<RunDo
128
128
  const combos = withDeclared(info, combinations(paramPlan));
129
129
  const chosen = selectCases(context, workspace, info, cases, bars, combos[0]!, given);
130
130
  if ("nothing" in chosen) {
131
- context.stdout(chosen.nothing);
132
- return { exit: chosen.exit, unstarted: chosen.nothing };
131
+ if (options.json) {
132
+ printPlan(context, {
133
+ kind: PLAN_KIND,
134
+ command: "run",
135
+ dataset: info.name,
136
+ cases: [],
137
+ columns: combos.length * (1 + options.against.length),
138
+ trials: 0,
139
+ nothing: chosen.nothing,
140
+ concurrency: workspace.concurrency,
141
+ });
142
+ } else context.stdout(chosen.nothing);
143
+ return { exit: 0, unstarted: chosen.nothing };
133
144
  }
134
145
  const { selected, trialsOf } = chosen;
135
- const trialScript = trialScriptOf();
146
+ const targetScript = targetScriptOf();
136
147
  const criteria = criteriaCount(
137
148
  selected,
138
149
  selected.map((c) => c.name),
@@ -145,7 +156,7 @@ export async function run(context: Context, given: RunGiven = {}): Promise<RunDo
145
156
  const codeFolders: CodeFolder[] = [];
146
157
  if (given.folders) {
147
158
  // A loop's copies hold your checkout's evals/ as the loop started, which no try may change.
148
- const settings = resolveSettings(info.trial, limits);
159
+ const settings = resolveSettings(info.target, limits);
149
160
  for (const { dir, version } of given.folders) {
150
161
  // A loop may name one folder twice: the start against itself, for its spread.
151
162
  codeFolders.push(
@@ -155,9 +166,9 @@ export async function run(context: Context, given: RunGiven = {}): Promise<RunDo
155
166
  } else {
156
167
  codeFolders.push({
157
168
  folder: await folderOf(),
158
- trialScript,
159
- version: info.trial.version,
160
- settings: resolveSettings(info.trial, limits),
169
+ targetScript,
170
+ version: info.target.version,
171
+ settings: resolveSettings(info.target, limits),
161
172
  state: gitState(workspace.root),
162
173
  });
163
174
  for (const dir of options.against) {
@@ -166,133 +177,140 @@ export async function run(context: Context, given: RunGiven = {}): Promise<RunDo
166
177
  }
167
178
  const columns = columnsOf(codeFolders.length, combos);
168
179
  const tmp = tmpOf(context);
169
- const reuse = await planReuse({
170
- context,
171
- workspace,
172
- info,
173
- cases,
174
- selected,
175
- trialsOf,
176
- columns,
177
- codeFolders,
178
- graders,
179
- facts,
180
- tmp,
181
- now,
182
- });
183
- const plan = planText({
184
- workspace,
185
- info,
186
- selected,
187
- trialsOf,
188
- codeFolders,
189
- paramPlan,
190
- columns,
191
- reuse,
192
- ...(options.budget !== undefined ? { budget: options.budget } : {}),
193
- });
194
- if (options.dryRun) {
195
- if (options.json) printPlan(context, plan.json);
196
- else context.stdout(plan.text);
197
- return { exit: 0, unstarted: "a dry run" };
198
- }
199
- const withBudget =
200
- options.budget !== undefined
201
- ? `${plan.text}\nstops starting trials once their estimates reach ${usd(options.budget)}`
202
- : plan.text;
203
- if (!(await confirmPlan(context, withBudget))) {
204
- stderr("declined; nothing run");
205
- return { exit: 2, unstarted: "declined" };
206
- }
180
+ const { built, drop } = buildCases(info.dataDir, selected, tmp);
181
+ try {
182
+ const reuse = await planReuse({
183
+ context,
184
+ workspace,
185
+ info,
186
+ cases,
187
+ selected,
188
+ trialsOf,
189
+ columns,
190
+ codeFolders,
191
+ graders,
192
+ facts,
193
+ tmp,
194
+ now,
195
+ built,
196
+ });
197
+ const plan = planText({
198
+ workspace,
199
+ info,
200
+ selected,
201
+ trialsOf,
202
+ codeFolders,
203
+ paramPlan,
204
+ columns,
205
+ reuse,
206
+ ...(options.budget !== undefined ? { budget: options.budget } : {}),
207
+ });
208
+ if (options.dryRun) {
209
+ if (options.json) printPlan(context, plan.json);
210
+ else context.stdout(plan.text);
211
+ return { exit: 0, unstarted: "a dry run" };
212
+ }
213
+ const withBudget =
214
+ options.budget !== undefined
215
+ ? `${plan.text}\nstops starting trials once their estimates reach ${usd(options.budget)}`
216
+ : plan.text;
217
+ if (!(await confirmPlan(context, withBudget))) {
218
+ stderr("declined; nothing run");
219
+ return { exit: 2, unstarted: "declined" };
220
+ }
207
221
 
208
- const ran = await withLock(
209
- context,
210
- workspace,
211
- async (): Promise<RunRecord | RunDone> => {
212
- let record: RunRecord | undefined;
213
- try {
214
- const id = claimRun(workspace.store, now());
215
- record = {
216
- kind: RUN_KIND,
217
- id,
218
- dataset: info.name,
219
- folders: codeFolders.map((c) => ({
220
- path: c.folder.root,
221
- ...c.state,
222
- version: c.version,
223
- ...c.settings,
224
- })),
225
- columns,
226
- asked: selected.map((c) => ({ case: c.name, trials: trialsOf(c.name) })),
227
- ...(given.loop ? { loop: given.loop } : {}),
228
- started: now().toISOString(),
229
- };
230
- writeRun(workspace.store, record);
231
- given.started?.(id);
232
- clearStale(tmp);
233
- clearStaleTrialFiles(workspace.labHome);
234
- const { runner, logs, estimate } = externalsOf(environment);
235
- const lab: TrialLab = {
236
- workspace,
237
- dataset: info,
238
- run: id,
239
- runner,
240
- logs,
241
- ...(estimate ? { estimate } : {}),
242
- tmp,
243
- env: environment.env ?? process.env,
244
- graders,
245
- facts,
246
- now,
247
- };
222
+ const ran = await withLock(
223
+ context,
224
+ workspace,
225
+ async (): Promise<RunRecord | RunDone> => {
226
+ let record: RunRecord | undefined;
248
227
  try {
249
- record = await runPasses({
250
- context,
251
- lab,
252
- record,
253
- selected,
254
- trialsOf,
255
- codeFolders,
256
- reuse,
257
- bars,
258
- given,
259
- });
260
- } catch (error) {
261
- record = { ...record, broke: (error as Error).message, finished: now().toISOString() };
228
+ const id = claimRun(workspace.store, now());
229
+ record = {
230
+ kind: RUN_KIND,
231
+ id,
232
+ dataset: info.name,
233
+ folders: codeFolders.map((c) => ({
234
+ path: c.folder.root,
235
+ ...c.state,
236
+ version: c.version,
237
+ ...c.settings,
238
+ })),
239
+ columns,
240
+ asked: selected.map((c) => ({ case: c.name, trials: trialsOf(c.name) })),
241
+ ...(given.loop ? { loop: given.loop } : {}),
242
+ started: now().toISOString(),
243
+ };
262
244
  writeRun(workspace.store, record);
263
- throw new LabBroke(`the lab broke during run ${id}: ${(error as Error).message}`);
264
- }
265
- record = { ...record, finished: now().toISOString() };
266
- writeRun(workspace.store, record);
267
- return record;
268
- } catch (error) {
269
- if (error instanceof LabBroke) {
270
- stderr(`awf-lab: ${error.message}`);
271
- return { exit: 4, ...(record ? { id: record.id } : {}) };
245
+ given.started?.(id);
246
+ clearStale(tmp);
247
+ clearStaleTrialFiles(workspace.labHome);
248
+ const { runner, logs, estimate } = externalsOf(environment);
249
+ const lab: TrialLab = {
250
+ workspace,
251
+ dataset: info,
252
+ run: id,
253
+ runner,
254
+ logs,
255
+ ...(estimate ? { estimate } : {}),
256
+ tmp,
257
+ env: environment.env ?? process.env,
258
+ graders,
259
+ facts,
260
+ now,
261
+ };
262
+ try {
263
+ record = await runPasses({
264
+ context,
265
+ lab,
266
+ record,
267
+ selected,
268
+ trialsOf,
269
+ codeFolders,
270
+ reuse,
271
+ built,
272
+ bars,
273
+ given,
274
+ });
275
+ } catch (error) {
276
+ record = { ...record, broke: (error as Error).message, finished: now().toISOString() };
277
+ writeRun(workspace.store, record);
278
+ throw new LabBroke(`the lab broke during run ${id}: ${(error as Error).message}`);
279
+ }
280
+ record = { ...record, finished: now().toISOString() };
281
+ writeRun(workspace.store, record);
282
+ return record;
283
+ } catch (error) {
284
+ if (error instanceof LabBroke) {
285
+ stderr(`awf-lab: ${error.message}`);
286
+ return { exit: 4, ...(record ? { id: record.id } : {}) };
287
+ }
288
+ throw error;
289
+ } finally {
290
+ if (record && info.records) writeRecords(workspace.store, info.records, record.id);
272
291
  }
273
- throw error;
274
- } finally {
275
- if (record && info.records) writeRecords(workspace.store, info.records, record.id);
276
- }
277
- },
278
- given.waitForStore ?? false,
279
- );
280
- if ("exit" in ran) return ran;
281
- const record = ran;
282
- const report = await runReport(context, workspace, {
283
- info,
284
- run: record,
285
- trials: readTrials(workspace.store, record.id),
286
- bars,
287
- graders,
288
- criteria,
289
- followsPlan: true,
290
- });
291
- const exit = budgetExit(record.stopped === "budget", report.exit);
292
- if (given.report !== false) {
293
- context.stdout(options.json ? JSON.stringify(report.json(exit), null, 2) : report.text);
292
+ },
293
+ given.waitForStore ?? false,
294
+ );
295
+ if ("exit" in ran) return ran;
296
+ const record = ran;
297
+ const report = await runReport(context, workspace, {
298
+ info,
299
+ run: record,
300
+ trials: readTrials(workspace.store, record.id),
301
+ bars,
302
+ graders,
303
+ criteria,
304
+ followsPlan: true,
305
+ });
306
+ const exit = budgetExit(record.stopped === "budget", report.exit);
307
+ if (given.report !== false) {
308
+ context.stdout(options.json ? JSON.stringify(report.json(exit), null, 2) : report.text);
309
+ }
310
+ return { exit, id: record.id };
311
+ } finally {
312
+ drop();
294
313
  }
295
- return { exit, id: record.id };
296
314
  }
297
315
 
298
316
  /** The cases to run and each one's trials: `--cases`, a loop's order, `--tags` and `--failed`. */
@@ -304,9 +322,7 @@ function selectCases(
304
322
  bars: ReadonlyMap<string, CaseBar>,
305
323
  reference: Params,
306
324
  given: RunGiven,
307
- ):
308
- | { selected: CaseInfo[]; trialsOf: (name: string) => number }
309
- | { nothing: string; exit: number } {
325
+ ): { selected: CaseInfo[]; trialsOf: (name: string) => number } | { nothing: string } {
310
326
  const { options } = context;
311
327
  const byName = new Map(cases.map((c) => [c.name, c]));
312
328
  for (const name of options.cases ?? []) {
@@ -322,10 +338,9 @@ function selectCases(
322
338
  ? cases.filter((c) => options.cases!.includes(c.name))
323
339
  : [...cases];
324
340
  if (selected.length === 0) {
325
- return {
326
- nothing: `no cases in ${shownPath(context, info.dataDir)}; awf-lab case new ${info.name}/{case} makes one`,
327
- exit: 2,
328
- };
341
+ throw new Refusal(
342
+ `no cases in ${shownPath(context, info.dataDir)}; awf-lab case new ${info.name}/{case} makes one`,
343
+ );
329
344
  }
330
345
  if (options.tags) {
331
346
  const before = selected;
@@ -333,14 +348,13 @@ function selectCases(
333
348
  if (selected.length === 0) {
334
349
  const tags = options.tags.join(" or ");
335
350
  if (options.cases) {
336
- return { nothing: `none of --cases ${options.cases.join(",")} has tag ${tags}`, exit: 2 };
351
+ throw new Refusal(`none of --cases ${options.cases.join(",")} has tag ${tags}`);
337
352
  }
338
353
  const known = [...new Set(before.flatMap((c) => c.key.tags ?? []))].sort();
339
354
  const which = options.holdout ? "held-out case" : "case";
340
- return {
341
- nothing: `no ${which} in ${info.name} has tag ${tags}; ${known.length > 0 ? `its tags: ${known.join(", ")}` : `its ${which}s have no tags`}`,
342
- exit: 2,
343
- };
355
+ throw new Refusal(
356
+ `no ${which} in ${info.name} has tag ${tags}; ${known.length > 0 ? `its tags: ${known.join(", ")}` : `its ${which}s have no tags`}`,
357
+ );
344
358
  }
345
359
  }
346
360
  const failed = options.failed
@@ -350,10 +364,7 @@ function selectCases(
350
364
  if (failed) for (const [name] of failed) if (bars.get(name)?.knownFailing) failed.delete(name);
351
365
  if (failed) selected = selected.filter((c) => failed.has(c.name));
352
366
  if (selected.length === 0) {
353
- return {
354
- nothing: "nothing to run: no case's newest verdict is failed, flaky or unclear",
355
- exit: 0,
356
- };
367
+ return { nothing: "nothing to run: no case's newest verdict is failed, flaky or unclear" };
357
368
  }
358
369
  return { selected, trialsOf: (name) => options.trials ?? failed?.get(name) ?? 1 };
359
370
  }
@@ -375,11 +386,11 @@ async function planReuse(args: {
375
386
  facts: FactsReader;
376
387
  tmp: string;
377
388
  now: () => Date;
389
+ built: ReadonlyMap<string, BuiltCase>;
378
390
  }): Promise<Reuse> {
379
391
  const { options } = args.context;
380
392
  const { workspace, info, columns, codeFolders } = args;
381
393
  const days = options.fresh || options.failed ? 0 : workspace.reuseDays;
382
- const inputs = caseDigests(info.dataDir, args.selected, args.tmp);
383
394
  const keyOf = (n: number, input: string) => {
384
395
  const { folder, params } = columns[n]!;
385
396
  const { version, settings, folder: setup } = codeFolders[folder]!;
@@ -395,11 +406,11 @@ async function planReuse(args: {
395
406
  const taken = new Set<string>();
396
407
  for (const c of args.selected) {
397
408
  for (const n of columns.keys()) {
398
- const found = (stored.get(keyOf(n, inputs.get(c.name)!)) ?? []).filter(
399
- (t) => t.record.case === c.name && !taken.has(t.record.runId!),
409
+ const found = (stored.get(keyOf(n, args.built.get(c.name)!.input)) ?? []).filter(
410
+ (t) => t.record.case === c.name && !taken.has(t.record.trialId!),
400
411
  );
401
412
  const chosen = found.slice(0, args.trialsOf(c.name));
402
- for (const t of chosen) taken.add(t.record.runId!);
413
+ for (const t of chosen) taken.add(t.record.trialId!);
403
414
  if (chosen.length > 0) slots.set(slotOf(c.name, n), { column: n, trials: chosen });
404
415
  }
405
416
  }
@@ -435,26 +446,21 @@ function planText(args: {
435
446
  columns: readonly Column[];
436
447
  reuse: Reuse;
437
448
  budget?: number;
438
- }): { text: string; json: CasePlan } {
449
+ }): { text: string; json: LabPlan } {
439
450
  const { info, selected, trialsOf, columns, reuse } = args;
440
451
  const total = selected.reduce((n, c) => n + trialsOf(c.name), 0);
441
452
  const counts = new Set(selected.map((c) => trialsOf(c.name)));
442
453
  const regrade = reuse.regrade;
443
454
  const atOnce = args.workspace.concurrency;
444
455
  const toRun = total * columns.length - reuse.count;
445
- const earlier = earlierTrials(
446
- args.workspace.store,
447
- info.name,
448
- selected.map((c) => c.name),
449
- );
450
- const estimated = estimateOf(earlier, toRun, atOnce);
456
+ const estimated = columnsEstimate(args);
451
457
  const text = [
452
458
  `${info.name} · ${plural(selected.length, "case")} · ${counts.size === 1 ? `${plural([...counts][0]!, "trial")} each` : plural(total, "trial")}`,
453
459
  ...args.codeFolders.map(
454
460
  (c, i) =>
455
461
  `${i === 0 ? "code" : c.folder.root === args.codeFolders[0]!.folder.root ? "the same code again" : `against ${i}`}: ${describeFolder({ path: i === 0 && c.folder.root === args.workspace.root ? undefined : c.folder.root, ...c.state })} · version ${c.version} · agentswf ${c.folder.version}`,
456
462
  ),
457
- ...paramLines(args.paramPlan, columns.length),
463
+ ...paramLines(args.paramPlan, columns),
458
464
  ...(reuse.count > 0
459
465
  ? [
460
466
  `reuses ${reuse.count} of ${plural(total * columns.length, "trial")}: the same version, settings and cases; --fresh runs new ones`,
@@ -466,9 +472,9 @@ function planText(args: {
466
472
  ]
467
473
  : []),
468
474
  ...(atOnce > 1 ? [`runs up to ${plural(atOnce, "trial")} at once`] : []),
469
- estimateText(earlier, toRun, atOnce),
475
+ ...estimated.lines,
470
476
  ].join("\n");
471
- const json: CasePlan = {
477
+ const json: LabPlan = {
472
478
  kind: PLAN_KIND,
473
479
  command: "run",
474
480
  dataset: info.name,
@@ -477,13 +483,94 @@ function planText(args: {
477
483
  trials: toRun,
478
484
  reused: reuse.count,
479
485
  ...(regrade ? { grades: Object.fromEntries(regrade.counts) } : {}),
480
- ...(estimated ? { estimate: estimated } : {}),
486
+ ...(toRun === 0 ? { nothing: "every trial reused: nothing to run" } : {}),
487
+ ...(estimated.json ? { estimate: estimated.json } : {}),
488
+ ...(estimated.unestimated.length > 0 ? { unestimated: estimated.unestimated } : {}),
481
489
  ...(args.budget !== undefined ? { budget: args.budget } : {}),
482
490
  concurrency: atOnce,
483
491
  };
484
492
  return { text, json };
485
493
  }
486
494
 
495
+ /**
496
+ * The plan's estimate, column by column: each from the earlier trials under its parameters and
497
+ * version, since a column of another model may cost many times the reference's. A column with
498
+ * none is named, never priced as another's.
499
+ */
500
+ function columnsEstimate(args: {
501
+ workspace: CaseWorkspace;
502
+ info: DatasetInfo;
503
+ selected: readonly CaseInfo[];
504
+ trialsOf: (name: string) => number;
505
+ codeFolders: readonly CodeFolder[];
506
+ columns: readonly Column[];
507
+ reuse: Reuse;
508
+ }): { lines: string[]; json?: LabPlan["estimate"]; unestimated: string[] } {
509
+ const { workspace, info, selected, trialsOf, codeFolders, columns, reuse } = args;
510
+ const atOnce = workspace.concurrency;
511
+ const names = selected.map((c) => c.name);
512
+ const toRunIn = (n: number) =>
513
+ selected.reduce(
514
+ (sum, c) =>
515
+ sum +
516
+ Math.max(0, trialsOf(c.name) - (reuse.slots.get(slotOf(c.name, n))?.trials.length ?? 0)),
517
+ 0,
518
+ );
519
+ const total = columns.reduce((sum, _, n) => sum + toRunIn(n), 0);
520
+ if (total === 0) return { lines: ["every trial reused: nothing to run"], unestimated: [] };
521
+ const labelled = { columns, folders: codeFolders.map((c) => ({ path: c.folder.root })) };
522
+ const each = columns.map((column, n) => ({
523
+ label: columnLabel(labelled as unknown as RunRecord, n),
524
+ count: toRunIn(n),
525
+ earlier: earlierTrials(workspace.store, info.name, names, {
526
+ params: column.params,
527
+ version: codeFolders[column.folder]!.version,
528
+ }),
529
+ }));
530
+ const asked = each.filter((c) => c.count > 0);
531
+ const priced = asked.filter((c) => c.earlier);
532
+ const missing = asked.filter((c) => !c.earlier);
533
+ if (columns.length === 1) {
534
+ const [only] = asked;
535
+ const params = Object.entries(columns[0]!.params).map(([name, value]) => `${name}=${value}`);
536
+ const under = `version ${versionKey(codeFolders[0]!.version)}${params.length > 0 ? `, ${params.join(" ")}` : ""}`;
537
+ return {
538
+ lines: [
539
+ only!.earlier
540
+ ? estimateText(only!.earlier, only!.count, atOnce)
541
+ : `no estimate yet: no earlier trials of these cases under ${under}`,
542
+ ],
543
+ ...(only!.earlier ? { json: estimateOf(only!.earlier, only!.count, atOnce) } : {}),
544
+ unestimated: [],
545
+ };
546
+ }
547
+ const parts = priced.map((c) => estimateOf(c.earlier, c.count, atOnce)!);
548
+ const json =
549
+ parts.length > 0
550
+ ? {
551
+ ms: parts.reduce((sum, p) => sum + (p.ms ?? 0), 0),
552
+ ...(parts.some((p) => p.usd !== undefined)
553
+ ? { usd: parts.reduce((sum, p) => sum + (p.usd ?? 0), 0) }
554
+ : {}),
555
+ }
556
+ : undefined;
557
+ const grading = priced.reduce((sum, c) => sum + c.earlier!.grading * c.count, 0);
558
+ const workflowUnpriced = priced.some((c) => c.earlier!.usd === undefined);
559
+ const price =
560
+ json?.usd === undefined
561
+ ? ""
562
+ : `, est. ${usd(json.usd)}${grading > 0 ? `, grading ${usd(grading)} of it` : ""}${workflowUnpriced ? `, the workflow partly unpriced` : ""}`;
563
+ const lines = [
564
+ ...(json
565
+ ? [
566
+ `from earlier trials: about ${seconds(json.ms)}${price}${missing.length > 0 ? `, for ${priced.map((c) => c.label).join(", ")} alone` : ""}`,
567
+ ]
568
+ : []),
569
+ ...missing.map((c) => `no estimate for ${c.label}: no earlier trials under it`),
570
+ ];
571
+ return { lines, ...(json ? { json } : {}), unestimated: missing.map((c) => c.label) };
572
+ }
573
+
487
574
  /**
488
575
  * The run's trials: the reused ones put in place and graded again where a key or grader changed,
489
576
  * then trial t of every case, then t + 1; under a loop's `stop`, a case's every trial first. Up to
@@ -499,10 +586,11 @@ async function runPasses(args: {
499
586
  trialsOf: (name: string) => number;
500
587
  codeFolders: readonly CodeFolder[];
501
588
  reuse: Reuse;
589
+ built: ReadonlyMap<string, BuiltCase>;
502
590
  bars: ReadonlyMap<string, CaseBar>;
503
591
  given: RunGiven;
504
592
  }): Promise<RunRecord> {
505
- const { context, lab, selected, trialsOf, codeFolders, reuse, bars, given } = args;
593
+ const { context, lab, selected, trialsOf, codeFolders, reuse, built, bars, given } = args;
506
594
  const { budget } = context.options;
507
595
  const { store } = lab.workspace;
508
596
  let record = args.record;
@@ -520,8 +608,8 @@ async function runPasses(args: {
520
608
  const trialIn = (n: number, info: CaseInfo, trial: number) => {
521
609
  const column = columns[n]!;
522
610
  const code = codeFolders[column.folder]!;
523
- return runTrial(lab, code.folder, info, n, trial, {
524
- trialScript: code.trialScript,
611
+ return runTrial(lab, code.folder, info, built.get(info.name)!, n, trial, {
612
+ targetScript: code.targetScript,
525
613
  params: column.params,
526
614
  version: code.version,
527
615
  settings: code.settings,
@@ -690,14 +778,26 @@ export function earlierTrials(
690
778
  store: string,
691
779
  dataset: string,
692
780
  names: readonly string[],
781
+ /** A column's parameters and version: only trials under both. */
782
+ under?: { params: Params; version: string },
693
783
  ): Earlier | undefined {
694
784
  const ms: number[] = [];
695
785
  const cost: number[] = [];
696
786
  const grading: number[] = [];
787
+ const same = (params: Params) =>
788
+ under !== undefined &&
789
+ Object.keys(params).length === Object.keys(under.params).length &&
790
+ Object.entries(under.params).every(([name, value]) => params[name] === value);
697
791
  for (const { run, trials } of readableRuns(store, { dataset })) {
698
792
  const span = runSpan(store, run);
699
793
  for (const { record: trial, scores } of trials) {
700
- if (!names.includes(trial.case) || !trial.runId || trial.reused) continue;
794
+ if (!names.includes(trial.case) || !trial.trialId || trial.reused) continue;
795
+ if (
796
+ under &&
797
+ (!same(trial.params) || versionKey(trial.version) !== versionKey(under.version))
798
+ ) {
799
+ continue;
800
+ }
701
801
  if (trialOutcome(trial, scores).outcome === "errored") continue;
702
802
  const graded = scoresInRun(scores, span);
703
803
  ms.push(trial.ms + graded.flatMap((s) => s.entries).reduce((sum, e) => sum + (e.ms ?? 0), 0));
@@ -716,7 +816,7 @@ export function estimateOf(
716
816
  earlier: Earlier | undefined,
717
817
  count: number,
718
818
  atOnce: number,
719
- ): CasePlan["estimate"] | undefined {
819
+ ): LabPlan["estimate"] | undefined {
720
820
  if (!earlier) return undefined;
721
821
  const priced =
722
822
  earlier.usd !== undefined || earlier.grading > 0
@@ -743,14 +843,19 @@ export function estimateText(
743
843
  return `from earlier trials: ${about}${seconds(earlier.ms * Math.ceil(count / atOnce))}${price}`;
744
844
  }
745
845
 
746
- /** The plan's lines for parameters: those every column shares, and what varies. */
747
- function paramLines(plan: ParamPlan, columns: number): string[] {
748
- const fixed = Object.entries(plan.fixed).map(([name, value]) => `${name}=${value}`);
846
+ /**
847
+ * The plan's lines for parameters: those every column shares, `target.ts`'s defaults included, as
848
+ * the report prints them; and what varies.
849
+ */
850
+ function paramLines(plan: ParamPlan, columns: readonly Column[]): string[] {
851
+ const fixed = Object.entries(columns[0]!.params)
852
+ .filter(([name, value]) => columns.every((c) => c.params[name] === value))
853
+ .map(([name, value]) => `${name}=${value}`);
749
854
  return [
750
855
  ...(fixed.length > 0 ? [`params: ${fixed.join(" ")}`] : []),
751
856
  ...(plan.varied.length > 0
752
857
  ? [
753
- `vary: ${plan.varied.map(([name, values]) => `${name}=${values.join(",")}`).join(" ")} · ${plural(columns, "column")}, the first value of each the reference`,
858
+ `vary: ${plan.varied.map(([name, values]) => `${name}=${values.join(",")}`).join(" ")} · ${plural(columns.length, "column")}, the first value of each the reference`,
754
859
  ]
755
860
  : []),
756
861
  ];
@@ -758,8 +863,8 @@ function paramLines(plan: ParamPlan, columns: number): string[] {
758
863
 
759
864
  /**
760
865
  * A folder `--against` names: another checkout of the project, holding the dataset at the same
761
- * path as yours. Only its `trial.ts`, its code and its `awf` are used; its cases, keys and grading
762
- * are never read. Its `trial.ts` gives its version, sandbox and limits, `--limit` over them.
866
+ * path as yours. Only its `target.ts`, its code and its `awf` are used; its cases, keys and grading
867
+ * are never read. Its `target.ts` gives its version, sandbox and limits, `--limit` over them.
763
868
  * Checked as your checkout is before the first trial.
764
869
  */
765
870
  async function againstFolder(
@@ -769,7 +874,7 @@ async function againstFolder(
769
874
  given: string,
770
875
  taken: readonly CodeFolder[],
771
876
  limits: Limits,
772
- /** A loop's id of the code and its settings, in place of what its `trial.ts` declares. */
877
+ /** A loop's id of the code and its settings, in place of what its `target.ts` declares. */
773
878
  loop?: { version: string; settings: ResolvedSettings },
774
879
  ): Promise<CodeFolder> {
775
880
  const at = resolve(context.cwd, given);
@@ -778,9 +883,9 @@ async function againstFolder(
778
883
  const top = workspace.repository ?? workspace.root;
779
884
  const evalDir = join(dir, relative(top, info.evalDir));
780
885
  const evals = join(dir, relative(top, workspace.evals));
781
- if (!existsSync(join(evalDir, TRIAL_FILE))) {
886
+ if (!existsSync(join(evalDir, TARGET_FILE))) {
782
887
  throw new Refusal(
783
- `--against ${given}: no ${relative(top, join(info.evalDir, TRIAL_FILE))} there; it names another checkout of this project, holding the eval folder at the same path`,
888
+ `--against ${given}: no ${relative(top, join(info.evalDir, TARGET_FILE))} there; it names another checkout of this project, holding the eval folder at the same path`,
784
889
  );
785
890
  }
786
891
  if (dir === workspace.root || dir === workspace.repository) {
@@ -796,48 +901,48 @@ async function againstFolder(
796
901
  if (taken.some((c) => c.folder.root === root)) {
797
902
  throw new Refusal(`--against ${given}: ${root} is named twice`);
798
903
  }
799
- let trialScript: string;
904
+ let targetScript: string;
800
905
  try {
801
- trialScript = checkTrialScript(evalDir);
906
+ targetScript = checkTargetScript(evalDir);
802
907
  } catch (error) {
803
908
  throw new Refusal(`--against ${given}: ${(error as Error).message}`);
804
909
  }
805
- const shaped = loop ?? againstTrial(context, root, trialScript, given, taken, limits);
806
- const folder = await (context.environment.inspect ?? inspectFolder)(root, trialScript);
807
- return { folder, trialScript, ...shaped, state: gitState(root) };
910
+ const shaped = loop ?? againstTarget(context, root, targetScript, given, taken, limits);
911
+ const folder = await (context.environment.inspect ?? inspectFolder)(root, targetScript);
912
+ return { folder, targetScript, ...shaped, state: gitState(root) };
808
913
  }
809
914
 
810
915
  /**
811
- * The version, sandbox and limits an `--against` folder's `trial.ts` declares, read in that
916
+ * The version, sandbox and limits an `--against` folder's `target.ts` declares, read in that
812
917
  * folder. Its version must differ from every other column's in its major, minor or pre-release
813
918
  * tag: the lab never looks at the code, so the same version would share the other's kept trials.
814
919
  */
815
- function againstTrial(
920
+ function againstTarget(
816
921
  context: Context,
817
922
  root: string,
818
- trialScript: string,
923
+ targetScript: string,
819
924
  given: string,
820
925
  taken: readonly CodeFolder[],
821
926
  limits: Limits,
822
927
  ): { version: string; settings: ResolvedSettings } {
823
- let trial: TrialFile;
928
+ let target: TargetFile;
824
929
  try {
825
930
  const described = describeFiles(
826
- { trial: trialScript },
931
+ { target: targetScript },
827
932
  { root, env: envOf(context), tmp: tmpOf(context) },
828
933
  );
829
- trial = checkTrialFile(trialScript, described.trial);
934
+ target = checkTargetFile(targetScript, described.target);
830
935
  } catch (error) {
831
936
  throw new Refusal(`--against ${given}: ${(error as Error).message}`);
832
937
  }
833
- const { version } = trial;
938
+ const { version } = target;
834
939
  const same = taken.find((c) => versionKey(c.version) === versionKey(version));
835
940
  if (same) {
836
941
  throw new Refusal(
837
942
  `--against ${given}: both columns are version ${versionKey(version)}, so they would share each other's kept trials: bump it in the one you changed`,
838
943
  );
839
944
  }
840
- return { version, settings: resolveSettings(trial, limits) };
945
+ return { version, settings: resolveSettings(target, limits) };
841
946
  }
842
947
 
843
948
  function progress(