@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.
- package/package.json +4 -4
- package/schema/{case-check.schema.json → lab-check.schema.json} +1 -1
- package/schema/{case-config.schema.json → lab-config.schema.json} +1 -1
- package/schema/{case-final.schema.json → lab-final.schema.json} +6 -6
- package/schema/{case-grade.schema.json → lab-grade.schema.json} +1 -1
- package/schema/{case-key.schema.json → lab-key.schema.json} +7 -0
- package/schema/{case-label.schema.json → lab-label.schema.json} +3 -3
- package/schema/{case-loop-report.schema.json → lab-loop-report.schema.json} +26 -15
- package/schema/{case-loop.schema.json → lab-loop.schema.json} +1 -1
- package/schema/{case-plan.schema.json → lab-plan.schema.json} +14 -3
- package/schema/{case-proposal.schema.json → lab-proposal.schema.json} +3 -3
- package/schema/{case-report.schema.json → lab-report.schema.json} +272 -36
- package/schema/{case-run.schema.json → lab-run.schema.json} +4 -4
- package/schema/{case-runs.schema.json → lab-runs.schema.json} +8 -1
- package/schema/{case-score.schema.json → lab-score.schema.json} +2 -2
- package/schema/{case-spread.schema.json → lab-spread.schema.json} +6 -6
- package/schema/{case-trial.schema.json → lab-trial.schema.json} +9 -9
- package/schema/{case-try.schema.json → lab-try.schema.json} +6 -6
- package/schema/local.json +3 -3
- package/src/env/capture.ts +1 -1
- package/src/env/compare.ts +7 -7
- package/src/env/fetch.ts +1 -1
- package/src/env/files.ts +14 -14
- package/src/env/grade-helper.ts +15 -15
- package/src/env/grader.ts +5 -2
- package/src/env/index.ts +18 -18
- package/src/env/trial.ts +5 -2
- package/src/format/key.ts +24 -0
- package/src/format/loop.ts +20 -19
- package/src/format/output.ts +120 -59
- package/src/format/records.ts +23 -20
- package/src/format/schema-files.ts +30 -30
- package/src/format/settings.ts +20 -13
- package/src/format/trial-env.ts +9 -6
- package/src/help/awf-lab.txt +1 -1
- package/src/help/case.txt +5 -4
- package/src/help/config.txt +2 -2
- package/src/help/label.txt +2 -2
- package/src/help/loop.txt +10 -10
- package/src/help/report.txt +1 -1
- package/src/help/run.txt +11 -10
- package/src/help/runs.txt +4 -3
- package/src/help/score.txt +4 -3
- package/src/lab/blame.ts +1 -1
- package/src/lab/box.ts +7 -5
- package/src/lab/capture-command.ts +11 -7
- package/src/lab/capture.ts +1 -1
- package/src/lab/check-command.ts +3 -3
- package/src/lab/cli.ts +9 -8
- package/src/lab/columns.ts +5 -5
- package/src/lab/command-context.ts +7 -7
- package/src/lab/compare.ts +8 -8
- package/src/lab/config-command.ts +25 -20
- package/src/lab/dataset.ts +37 -18
- package/src/lab/eval-files.ts +27 -16
- package/src/lab/folders.ts +26 -7
- package/src/lab/good.ts +1 -1
- package/src/lab/grading-stub.txt +2 -2
- package/src/lab/inspect.ts +13 -12
- package/src/lab/labels.ts +16 -11
- package/src/lab/loop-command.ts +68 -64
- package/src/lab/loop-records.ts +5 -5
- package/src/lab/loop.ts +105 -100
- package/src/lab/rates.ts +11 -6
- package/src/lab/record-copies.ts +1 -1
- package/src/lab/report-command.ts +8 -7
- package/src/lab/report.ts +172 -74
- package/src/lab/reuse.ts +29 -21
- package/src/lab/run-command.ts +304 -199
- package/src/lab/run-report.ts +49 -22
- package/src/lab/runs-command.ts +35 -27
- package/src/lab/scaffold.ts +19 -16
- package/src/lab/score-command.ts +72 -64
- package/src/lab/score.ts +1 -1
- package/src/lab/store.ts +3 -3
- package/src/lab/{trial-stub.txt → target-stub.txt} +3 -3
- package/src/lab/trial-settings.ts +17 -12
- package/src/lab/trial.ts +19 -23
- package/src/lab/usage.ts +1 -0
- package/src/lab/workflow-graders.ts +4 -1
- package/src/lab/workspace.ts +16 -9
- package/src/loop/propose.workflow.ts +1 -1
- package/src/shared/compare/index.ts +2 -2
- package/src/shared/compare/paired.ts +20 -20
- package/src/shared/compare/types.ts +4 -4
- package/src/write-schemas.ts +3 -3
- /package/schema/{case-good-record.schema.json → lab-good-record.schema.json} +0 -0
- /package/schema/{case-previous.schema.json → lab-previous.schema.json} +0 -0
package/src/lab/loop-command.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, realpathSync, statSync } from "nod
|
|
|
2
2
|
import { join, relative } from "node:path";
|
|
3
3
|
import { HypothesisSchema } from "../format/loop";
|
|
4
4
|
import {
|
|
5
|
-
type
|
|
5
|
+
type LabPlan,
|
|
6
6
|
LOOP_REPORT_KIND,
|
|
7
7
|
type LoopReport,
|
|
8
8
|
LoopReportSchema,
|
|
@@ -26,18 +26,18 @@ import {
|
|
|
26
26
|
import { roomOf } from "./compare";
|
|
27
27
|
import { type CaseInfo, comparingFile, type DatasetInfo, fileDigest } from "./dataset";
|
|
28
28
|
import { gitState } from "./git";
|
|
29
|
-
import {
|
|
29
|
+
import { checkTargetScript, inspectFolder } from "./inspect";
|
|
30
30
|
import {
|
|
31
|
+
bestSoFarOf,
|
|
31
32
|
changedDefinition,
|
|
32
33
|
codeOf,
|
|
33
34
|
digestOf,
|
|
34
|
-
incumbentOf,
|
|
35
35
|
keepRuns,
|
|
36
36
|
type LoopDefinition,
|
|
37
37
|
type LoopDeps,
|
|
38
38
|
loopDirOf,
|
|
39
|
+
loopEstimates,
|
|
39
40
|
loopIdOf,
|
|
40
|
-
loopSpend,
|
|
41
41
|
newestLoop,
|
|
42
42
|
readFinals,
|
|
43
43
|
readLoop,
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
import { Refusal } from "./refusal";
|
|
64
64
|
import { differingCases } from "./report";
|
|
65
65
|
import { earlierTrials, estimateOf, estimateText, type RunGiven, run } from "./run-command";
|
|
66
|
-
import {
|
|
66
|
+
import { columnDecisions } from "./run-report";
|
|
67
67
|
import { barsOf, type CaseBar, rowsOf } from "./runs";
|
|
68
68
|
import { awfRunsOf, newRunId, readRunRecord, readTrials, runSpan, type StoredTrial } from "./store";
|
|
69
69
|
import { plural, usd } from "./text";
|
|
@@ -113,7 +113,7 @@ export async function loopCommand(context: Context, names: readonly string[]): P
|
|
|
113
113
|
new Refusal(`no loop ${name} in ${workspace.store}: awf-lab loop run ${name} starts one`);
|
|
114
114
|
if (verb === "patch") {
|
|
115
115
|
if (!newest) throw none();
|
|
116
|
-
const kept =
|
|
116
|
+
const kept = bestSoFarOf(readTries(newest.dir));
|
|
117
117
|
if (kept === 0) {
|
|
118
118
|
context.stderr(`loop ${loopIdOf(newest.loop)} kept nothing: no patch`);
|
|
119
119
|
return 1;
|
|
@@ -147,9 +147,9 @@ export async function loopCommand(context: Context, names: readonly string[]): P
|
|
|
147
147
|
const dir = resuming?.dir ?? loopDirOf(workspace.store, loopIdOf({ name, started }));
|
|
148
148
|
const { info, cases } = loadDataset(context, workspace, definition.dataset);
|
|
149
149
|
const { cases: held } = loadDataset(context, workspace, info.name, true);
|
|
150
|
-
if (info.
|
|
150
|
+
if (info.target.sandbox?.by === "workflow") {
|
|
151
151
|
throw new Refusal(
|
|
152
|
-
`a loop runs code no person wrote: ${info.name}'s
|
|
152
|
+
`a loop runs code no person wrote: ${info.name}'s target.ts needs the lab's sandbox, sandbox.by "lab", the default`,
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
155
|
if (!info.grading.compare) {
|
|
@@ -179,7 +179,7 @@ export async function loopCommand(context: Context, names: readonly string[]): P
|
|
|
179
179
|
|
|
180
180
|
if (final) {
|
|
181
181
|
const loop = resuming!.loop;
|
|
182
|
-
const kept =
|
|
182
|
+
const kept = bestSoFarOf(readTries(dir));
|
|
183
183
|
const plan: LoopPlan = {
|
|
184
184
|
command: "loop final",
|
|
185
185
|
dataset: info.name,
|
|
@@ -195,7 +195,9 @@ export async function loopCommand(context: Context, names: readonly string[]): P
|
|
|
195
195
|
};
|
|
196
196
|
if (options.dryRun) {
|
|
197
197
|
if (kept === 0) {
|
|
198
|
-
|
|
198
|
+
const nothing = `loop ${loopIdOf(loop)} kept nothing: there is nothing to check`;
|
|
199
|
+
if (options.json) printPlan(context, { ...planOf(context, plan).json, trials: 0, nothing });
|
|
200
|
+
else context.stderr(nothing);
|
|
199
201
|
return 1;
|
|
200
202
|
}
|
|
201
203
|
showPlan(context, plan);
|
|
@@ -214,7 +216,7 @@ export async function loopCommand(context: Context, names: readonly string[]): P
|
|
|
214
216
|
const tuning = resuming
|
|
215
217
|
? cases.filter((c) => resuming.loop.tuning.includes(c.name))
|
|
216
218
|
: tuningOf(name, info.name, cases, definition);
|
|
217
|
-
const
|
|
219
|
+
const tries = options.tries ?? 1;
|
|
218
220
|
const spreadFirst = definition.spread && !readSpread(dir) && readTries(dir).length === 0;
|
|
219
221
|
const plan: LoopPlan = {
|
|
220
222
|
command: "loop run",
|
|
@@ -223,15 +225,15 @@ export async function loopCommand(context: Context, names: readonly string[]): P
|
|
|
223
225
|
cases: tuning.map((c) => c.name),
|
|
224
226
|
trials: definition.trials,
|
|
225
227
|
columns: 2,
|
|
226
|
-
|
|
228
|
+
tries,
|
|
227
229
|
spread: spreadFirst,
|
|
228
230
|
lines: [
|
|
229
|
-
`loop ${name} · ${info.name} · ${plural(tuning.length, "tuning case")} · ${plural(definition.trials, "trial")} each · up to ${
|
|
231
|
+
`loop ${name} · ${info.name} · ${plural(tuning.length, "tuning case")} · ${plural(definition.trials, "trial")} each · up to ${tries} ${tries === 1 ? "try" : "tries"}${resuming ? `, going on with ${loopIdOf(resuming.loop)}` : ""}`,
|
|
230
232
|
...(spreadFirst ? ["first: the start twice on the tuning cases"] : []),
|
|
231
|
-
"each try: the
|
|
233
|
+
"each try: the best version so far on the tuning cases, a proposal, then the try against it",
|
|
232
234
|
],
|
|
233
|
-
// A try runs its own column anew, and the
|
|
234
|
-
newTrials: tuning.length * definition.trials * (
|
|
235
|
+
// A try runs its own column anew, and the best version so far reuses what it ran; the spread, two.
|
|
236
|
+
newTrials: tuning.length * definition.trials * (tries + (spreadFirst ? 2 : 0)),
|
|
235
237
|
workspace,
|
|
236
238
|
};
|
|
237
239
|
if (options.dryRun) {
|
|
@@ -248,7 +250,7 @@ export async function loopCommand(context: Context, names: readonly string[]): P
|
|
|
248
250
|
workspace,
|
|
249
251
|
tuning,
|
|
250
252
|
holdout: held.map((c) => c.name),
|
|
251
|
-
|
|
253
|
+
tries,
|
|
252
254
|
budget: options.budget!,
|
|
253
255
|
definition,
|
|
254
256
|
briefFile: fromEntry!.brief,
|
|
@@ -330,7 +332,7 @@ type LoopPlan = {
|
|
|
330
332
|
cases: readonly string[];
|
|
331
333
|
trials: number;
|
|
332
334
|
columns: number;
|
|
333
|
-
|
|
335
|
+
tries?: number;
|
|
334
336
|
spread?: boolean;
|
|
335
337
|
lines: string[];
|
|
336
338
|
/** The trials it would run at most, none reused. */
|
|
@@ -339,13 +341,13 @@ type LoopPlan = {
|
|
|
339
341
|
};
|
|
340
342
|
|
|
341
343
|
/** A loop command's plan: what it runs, an estimate from earlier trials, and its budget. */
|
|
342
|
-
function planOf(context: Context, plan: LoopPlan): { text: string; json:
|
|
344
|
+
function planOf(context: Context, plan: LoopPlan): { text: string; json: LabPlan } {
|
|
343
345
|
const { workspace } = plan;
|
|
344
346
|
const { budget } = context.options;
|
|
345
347
|
const earlier = earlierTrials(workspace.store, plan.dataset, plan.cases);
|
|
346
348
|
const atOnce = workspace.concurrency;
|
|
347
349
|
const estimate = estimateOf(earlier, plan.newTrials, atOnce);
|
|
348
|
-
const json:
|
|
350
|
+
const json: LabPlan = {
|
|
349
351
|
kind: PLAN_KIND,
|
|
350
352
|
command: plan.command,
|
|
351
353
|
dataset: plan.dataset,
|
|
@@ -353,7 +355,7 @@ function planOf(context: Context, plan: LoopPlan): { text: string; json: CasePla
|
|
|
353
355
|
cases: plan.cases.map((c) => ({ case: c, trials: plan.trials })),
|
|
354
356
|
columns: plan.columns,
|
|
355
357
|
trials: plan.newTrials,
|
|
356
|
-
...(plan.
|
|
358
|
+
...(plan.tries !== undefined ? { tries: plan.tries } : {}),
|
|
357
359
|
...(plan.spread !== undefined ? { spread: plan.spread } : {}),
|
|
358
360
|
...(estimate ? { estimate } : {}),
|
|
359
361
|
...(budget !== undefined ? { budget } : {}),
|
|
@@ -403,14 +405,14 @@ export function loopReport(context: Context, given: string): number {
|
|
|
403
405
|
? "the start twice: not yet"
|
|
404
406
|
: spread === "skipped"
|
|
405
407
|
? "the start twice: skipped"
|
|
406
|
-
: `the start twice: ${spread.
|
|
408
|
+
: `the start twice: ${spread.decision ?? "no comparison"}, ${spread.unsteady.length} of ${json.tuning.length} cases differed · run ${spread.labRun} · est. ${usd(spread.estimate)}`,
|
|
407
409
|
...json.tries.map(
|
|
408
410
|
(t) =>
|
|
409
|
-
`try ${t.n} against ${from(t.parent)}: ${t.
|
|
411
|
+
`try ${t.n} against ${from(t.parent)}: ${t.outcome}: ${t.why}${t.labRun ? ` · run ${t.labRun}` : ""} · est. ${usd(t.estimate)}`,
|
|
410
412
|
),
|
|
411
413
|
...json.finals.map(
|
|
412
414
|
(f) =>
|
|
413
|
-
`final check ${f.k}: try ${f.
|
|
415
|
+
`final check ${f.k}: try ${f.kept} against the start: ${f.why} · est. ${usd(f.estimate)}`,
|
|
414
416
|
),
|
|
415
417
|
`keeps ${json.kept === 0 ? "the start: no try kept" : `try ${json.kept}`} · est. ${usd(json.estimate)} so far`,
|
|
416
418
|
];
|
|
@@ -423,8 +425,8 @@ function loopReportJson(workspace: CaseWorkspace, dir: string): LoopReport {
|
|
|
423
425
|
const tries = readTries(dir);
|
|
424
426
|
const spread = readSpread(dir);
|
|
425
427
|
const finals = readFinals(dir);
|
|
426
|
-
const
|
|
427
|
-
ids.reduce((sum, id) => sum +
|
|
428
|
+
const estimates = loopEstimates(dir, (ids) =>
|
|
429
|
+
ids.reduce((sum, id) => sum + estimatedIn(workspace.store, id), 0),
|
|
428
430
|
);
|
|
429
431
|
const report: LoopReport = {
|
|
430
432
|
kind: LOOP_REPORT_KIND,
|
|
@@ -439,34 +441,36 @@ function loopReportJson(workspace: CaseWorkspace, dir: string): LoopReport {
|
|
|
439
441
|
holdout: [...loop.holdout],
|
|
440
442
|
spread: !spread
|
|
441
443
|
? null
|
|
442
|
-
: "
|
|
444
|
+
: "labRun" in spread
|
|
443
445
|
? {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
+
labRun: spread.labRun,
|
|
447
|
+
decision: spread.decision,
|
|
446
448
|
unsteady: spread.unsteady.map((d) => d.case),
|
|
447
|
-
|
|
449
|
+
estimate: spread.estimate,
|
|
448
450
|
}
|
|
449
451
|
: "skipped",
|
|
450
452
|
tries: tries.map((t) => ({
|
|
451
453
|
n: t.n,
|
|
452
454
|
parent: t.parent,
|
|
453
|
-
|
|
455
|
+
outcome: t.outcome,
|
|
454
456
|
why: t.why,
|
|
455
457
|
...(t.hypothesis ? { change: t.hypothesis.change } : {}),
|
|
456
458
|
changed: [...t.changed],
|
|
457
|
-
...(t.
|
|
458
|
-
|
|
459
|
+
...(t.labRun ? { labRun: t.labRun } : {}),
|
|
460
|
+
...(t.decision !== undefined ? { decision: t.decision } : {}),
|
|
461
|
+
estimate: t.estimate.proposer + t.estimate.trials,
|
|
459
462
|
})),
|
|
460
|
-
kept:
|
|
463
|
+
kept: bestSoFarOf(tries),
|
|
461
464
|
finals: finals.map((f) => ({
|
|
462
465
|
k: f.k,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
+
kept: f.kept,
|
|
467
|
+
labRun: f.labRun,
|
|
468
|
+
decision: f.decision,
|
|
466
469
|
why: f.why,
|
|
467
|
-
|
|
470
|
+
estimate: f.estimate,
|
|
468
471
|
})),
|
|
469
|
-
estimate:
|
|
472
|
+
estimate:
|
|
473
|
+
estimates.spread + estimates.tries + (estimates.pending?.estimate ?? 0) + estimates.finals,
|
|
470
474
|
};
|
|
471
475
|
const checked = checkSchema(LoopReportSchema, report);
|
|
472
476
|
if (!checked.ok) throw new Error(describeProblems("report --loop --json", checked.problems));
|
|
@@ -510,7 +514,7 @@ function loopDeps(
|
|
|
510
514
|
if (wait) await wait({ argv: named() });
|
|
511
515
|
},
|
|
512
516
|
estimatedIn(runIds) {
|
|
513
|
-
return runIds.reduce((sum, id) => sum +
|
|
517
|
+
return runIds.reduce((sum, id) => sum + estimatedIn(workspace.store, id), 0);
|
|
514
518
|
},
|
|
515
519
|
async checkGood({ cases }) {
|
|
516
520
|
const all = loadDataset(context, workspace, info.name, "all").cases;
|
|
@@ -551,7 +555,7 @@ function loopDeps(
|
|
|
551
555
|
rowsOf(workspace.store, asked, trials, bars, 1),
|
|
552
556
|
);
|
|
553
557
|
},
|
|
554
|
-
async runFolders({ folders, order, budget,
|
|
558
|
+
async runFolders({ folders, order, budget, stopOnDecision, holdout, started }) {
|
|
555
559
|
const { budget: _, ...rest } = options;
|
|
556
560
|
const scoped: Context = {
|
|
557
561
|
...context,
|
|
@@ -577,11 +581,11 @@ function loopDeps(
|
|
|
577
581
|
...(loop ? { loop: loopIdOf(loop) } : {}),
|
|
578
582
|
...(ranOnce ? { waitForStore: true } : {}),
|
|
579
583
|
...(started ? { started } : {}),
|
|
580
|
-
...(
|
|
584
|
+
...(stopOnDecision
|
|
581
585
|
? {
|
|
582
586
|
stop: async (run, trials) => {
|
|
583
|
-
const
|
|
584
|
-
await
|
|
587
|
+
const said = (
|
|
588
|
+
await columnDecisions(scoped, {
|
|
585
589
|
workspace,
|
|
586
590
|
info,
|
|
587
591
|
run,
|
|
@@ -589,7 +593,7 @@ function loopDeps(
|
|
|
589
593
|
bars,
|
|
590
594
|
})
|
|
591
595
|
)?.[0];
|
|
592
|
-
return
|
|
596
|
+
return said !== undefined && !("error" in said) && said.stop;
|
|
593
597
|
},
|
|
594
598
|
}
|
|
595
599
|
: {}),
|
|
@@ -608,7 +612,7 @@ function loopDeps(
|
|
|
608
612
|
const trials = readTrials(workspace.store, runId);
|
|
609
613
|
const verdicts =
|
|
610
614
|
folders.length > 1
|
|
611
|
-
? await
|
|
615
|
+
? await columnDecisions(scoped, {
|
|
612
616
|
workspace,
|
|
613
617
|
info,
|
|
614
618
|
run: record,
|
|
@@ -618,7 +622,7 @@ function loopDeps(
|
|
|
618
622
|
: undefined;
|
|
619
623
|
const first = verdicts?.[0];
|
|
620
624
|
const result: TryRun = {
|
|
621
|
-
runId,
|
|
625
|
+
labRun: runId,
|
|
622
626
|
...(record.stopped ? { stopped: record.stopped } : {}),
|
|
623
627
|
...(record.stopped === "precondition"
|
|
624
628
|
? { precondition: preconditionFailure(trials) ?? "no trial says which" }
|
|
@@ -628,18 +632,18 @@ function loopDeps(
|
|
|
628
632
|
: {}),
|
|
629
633
|
...(first
|
|
630
634
|
? {
|
|
631
|
-
|
|
632
|
-
"
|
|
633
|
-
? {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
635
|
+
decision:
|
|
636
|
+
"error" in first
|
|
637
|
+
? { error: first.error }
|
|
638
|
+
: {
|
|
639
|
+
decision: first.decision,
|
|
640
|
+
stop: first.stop,
|
|
641
|
+
reason: first.reason,
|
|
642
|
+
metrics: first.metrics,
|
|
643
|
+
},
|
|
640
644
|
}
|
|
641
645
|
: {}),
|
|
642
|
-
|
|
646
|
+
estimate: estimatedIn(workspace.store, runId),
|
|
643
647
|
};
|
|
644
648
|
return result;
|
|
645
649
|
},
|
|
@@ -685,7 +689,7 @@ function loopDeps(
|
|
|
685
689
|
const copyRoot = join(code, relative(at.top, workspace.root));
|
|
686
690
|
const folder = await (environment.inspect ?? inspectFolder)(
|
|
687
691
|
copyRoot,
|
|
688
|
-
|
|
692
|
+
checkTargetScript(join(copyRoot, relative(workspace.root, info.evalDir))),
|
|
689
693
|
);
|
|
690
694
|
const id = newRunId((environment.now ?? (() => new Date()))());
|
|
691
695
|
const own = join(tryDir, "proposer");
|
|
@@ -721,10 +725,10 @@ function loopDeps(
|
|
|
721
725
|
// A proposer cut short prints no record; its folder still says what its agent is estimated at.
|
|
722
726
|
const unrecorded =
|
|
723
727
|
record || !estimate ? undefined : await estimate(folder.awf, runRoot, id, envOf(context));
|
|
724
|
-
const
|
|
728
|
+
const estimated = record?.accounting.totals.estimate ?? unrecorded ?? 0;
|
|
725
729
|
if (record?.outcome !== "completed") {
|
|
726
730
|
return {
|
|
727
|
-
|
|
731
|
+
estimate: estimated,
|
|
728
732
|
...(record ? { runId: record.runId } : {}),
|
|
729
733
|
why: `the proposer's run ${record?.outcome ?? "printed no record"}: ${
|
|
730
734
|
(record && "reason" in record ? record.reason : undefined) ??
|
|
@@ -737,18 +741,18 @@ function loopDeps(
|
|
|
737
741
|
const checked = checkSchema(HypothesisSchema, record.value);
|
|
738
742
|
if (!checked.ok) {
|
|
739
743
|
return {
|
|
740
|
-
|
|
744
|
+
estimate: estimated,
|
|
741
745
|
runId: record.runId,
|
|
742
746
|
why: describeProblems("the proposer's answer", checked.problems),
|
|
743
747
|
};
|
|
744
748
|
}
|
|
745
|
-
return {
|
|
749
|
+
return { estimate: estimated, runId: record.runId, hypothesis: checked.value };
|
|
746
750
|
},
|
|
747
751
|
};
|
|
748
752
|
}
|
|
749
753
|
|
|
750
754
|
/**
|
|
751
|
-
* The trials of the cases every column has run: a try's run holds the
|
|
755
|
+
* The trials of the cases every column has run: a try's run holds the best version so far's reused trials of
|
|
752
756
|
* every case from its start, and a comparison weighs only what both have.
|
|
753
757
|
*/
|
|
754
758
|
function bothRan(trials: readonly StoredTrial[], columns: number): StoredTrial[] {
|
|
@@ -762,7 +766,7 @@ function bothRan(trials: readonly StoredTrial[], columns: number): StoredTrial[]
|
|
|
762
766
|
}
|
|
763
767
|
|
|
764
768
|
/** What a run's trials and their grades are estimated at, as its `--budget` counted them. */
|
|
765
|
-
function
|
|
769
|
+
function estimatedIn(store: string, id: string): number {
|
|
766
770
|
const run = readRunRecord(store, id);
|
|
767
771
|
if (!run) return 0;
|
|
768
772
|
const span = runSpan(store, run);
|
package/src/lab/loop-records.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { basename, dirname, join } from "node:path";
|
|
|
3
3
|
import { git } from "./git";
|
|
4
4
|
import {
|
|
5
5
|
BRIEF_FILE,
|
|
6
|
+
bestSoFarOf,
|
|
6
7
|
CHANGE_FILE,
|
|
7
8
|
codeOf,
|
|
8
|
-
incumbentOf,
|
|
9
9
|
loopDirOf,
|
|
10
10
|
newestLoop,
|
|
11
11
|
readLoop,
|
|
@@ -17,7 +17,7 @@ import { Refusal } from "./refusal";
|
|
|
17
17
|
import type { CaseWorkspace } from "./workspace";
|
|
18
18
|
|
|
19
19
|
// A loop's own records in the records folder, `{records}/loops/{id}/`, beside its runs': what it
|
|
20
|
-
// was started with, each try's
|
|
20
|
+
// was started with, each try's outcome, proposal, ledger and change, and each final check. The
|
|
21
21
|
// code is not kept: a store that lacks it builds it again from the start commit and the changes
|
|
22
22
|
// of the tries it needs, so a loop goes on from a clone of the project that ran it.
|
|
23
23
|
|
|
@@ -107,7 +107,7 @@ function rebuildCode(dir: string, name: string, top: string, workspace: CaseWork
|
|
|
107
107
|
if (!loop) return;
|
|
108
108
|
const tries = readTries(dir);
|
|
109
109
|
const decided = new Set(tries.map((t) => t.n));
|
|
110
|
-
const kept = new Set(tries.filter((t) => t.
|
|
110
|
+
const kept = new Set(tries.filter((t) => t.outcome === "kept").map((t) => t.n));
|
|
111
111
|
// An undecided try resumes with its change: its proposal was made and paid for.
|
|
112
112
|
const open = existsSync(join(dir, "tries"))
|
|
113
113
|
? readdirSync(join(dir, "tries"))
|
|
@@ -134,8 +134,8 @@ function rebuildCode(dir: string, name: string, top: string, workspace: CaseWork
|
|
|
134
134
|
}
|
|
135
135
|
const parentOf = (n: number) =>
|
|
136
136
|
tries.find((t) => t.n === n)?.parent ??
|
|
137
|
-
// An undecided try's parent is the
|
|
138
|
-
|
|
137
|
+
// An undecided try's parent is the best version so far among the tries decided before it.
|
|
138
|
+
bestSoFarOf(tries.filter((t) => t.n < n));
|
|
139
139
|
for (const n of needed) {
|
|
140
140
|
if (existsSync(codeOf(dir, n))) continue;
|
|
141
141
|
const change = readFileSync(join(dir, "tries", String(n), CHANGE_FILE), "utf8");
|