@parcha/agentrun-serve 0.1.0-beta.62 → 0.1.0-beta.63
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/CHANGELOG.md +47 -0
- package/README.md +32 -13
- package/dist/adapters.js +4 -2
- package/dist/agent-delete.d.ts +3 -3
- package/dist/agent-delete.js +50 -4
- package/dist/chatgpt-plan.d.ts +8 -1
- package/dist/chatgpt-plan.js +55 -6
- package/dist/console/assets/{backend-DEgVn5lC.js → backend-BxQ2G1M0.js} +2 -2
- package/dist/console/assets/{index-CG5tELph.js → index-C8Y5Zl8x.js} +2 -2
- package/dist/console/assets/share-CjBJ_rxP.js +6 -0
- package/dist/console/index.html +1 -1
- package/dist/console/share.html +1 -1
- package/dist/harness-opencode/adapter.d.ts +3 -1
- package/dist/harness-opencode/adapter.js +6 -2
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +6 -1
- package/dist/host-tools.d.ts +18 -3
- package/dist/host-tools.js +27 -4
- package/dist/learn/ledger.d.ts +37 -16
- package/dist/learn/ledger.js +56 -24
- package/dist/learn/promote.d.ts +4 -1
- package/dist/learning-cost.d.ts +5 -3
- package/dist/learning-model.js +7 -5
- package/dist/learning-work.d.ts +69 -0
- package/dist/learning-work.js +148 -0
- package/dist/openapi.js +23 -9
- package/dist/run-export.js +7 -4
- package/dist/run-launch.d.ts +6 -1
- package/dist/run-launch.js +10 -3
- package/dist/run-view.js +9 -3
- package/dist/runnable.js +5 -5
- package/dist/runner/adapter-loop.js +31 -3
- package/dist/runner/adapter-run-spec.d.ts +14 -3
- package/dist/runner/adapter-run-spec.js +50 -19
- package/dist/runner/adapters/index.d.ts +2 -0
- package/dist/runner/adapters/index.js +3 -0
- package/dist/runner/adapters/pi.d.ts +42 -3
- package/dist/runner/adapters/pi.js +114 -13
- package/dist/runner/audit.d.ts +8 -2
- package/dist/runner/audit.js +34 -18
- package/dist/runner/book-cut.d.ts +6 -0
- package/dist/runner/book-cut.js +38 -0
- package/dist/runner/claim-secrets.d.ts +9 -4
- package/dist/runner/claim-secrets.js +10 -5
- package/dist/runner/cli-run-spec.d.ts +0 -2
- package/dist/runner/cli-run-spec.js +44 -19
- package/dist/runner/held.d.ts +6 -3
- package/dist/runner/learned-first.d.ts +5 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +15 -8
- package/dist/runner/learning-end.js +23 -7
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +2 -0
- package/dist/runner/model-route.d.ts +4 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/pr-checkout.d.ts +12 -0
- package/dist/runner/pr-checkout.js +21 -2
- package/dist/runner/promotion.d.ts +9 -2
- package/dist/runner/promotion.js +79 -28
- package/dist/runner/reflect-hook.d.ts +7 -0
- package/dist/runner/reflect-hook.js +2 -1
- package/dist/runner/run-child-host.js +21 -12
- package/dist/runner/run-child.js +1 -0
- package/dist/runner/runner.d.ts +9 -0
- package/dist/runner/runner.js +156 -25
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/workflow-first.js +4 -3
- package/dist/runner/workflow-loop.js +13 -1
- package/dist/secret-cut.d.ts +4 -0
- package/dist/secret-cut.js +1 -1
- package/dist/secret-rules.d.ts +2 -0
- package/dist/secret-rules.js +63 -19
- package/dist/server.js +20 -9
- package/dist/share-host.js +6 -3
- package/dist/store/schema.d.ts +4 -3
- package/dist/store/schema.js +4 -3
- package/dist/store/seal.d.ts +8 -2
- package/dist/store/seal.js +13 -2
- package/dist/store/sqlite/learning-rows.js +2 -1
- package/dist/store/sqlite/run-patch.js +4 -4
- package/dist/store/sqlite/store.js +28 -4
- package/dist/store/store.d.ts +5 -0
- package/dist/store-reads/journal.d.ts +2 -0
- package/dist/store-reads/journal.js +1 -1
- package/dist/store-reads/learning.d.ts +4 -3
- package/dist/store-reads/learning.js +62 -18
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +18 -1
- package/dist/tool-list.d.ts +4 -0
- package/dist/tool-list.js +4 -0
- package/dist/tools.js +2 -2
- package/dist/workspace/attach.js +22 -5
- package/dist/workspace/kind-skills/desktop/SKILL.md +7 -3
- package/package.json +12 -12
- package/templates/kyb/agent.md +7 -1
- package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
- package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
- package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
- package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
- package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
- package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
- package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
- package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
- package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
- package/templates/kyb/kyb.schema.json +2 -2
- package/templates/kyb/rules/SANCTIONS.md +82 -13
- package/dist/console/assets/share-CIeFK2Oe.js +0 -6
package/dist/runner/promotion.js
CHANGED
|
@@ -50,7 +50,9 @@ import { LEARNED_WORKFLOW_TOOL } from "../learned-workflow.js";
|
|
|
50
50
|
import { launchBody, readLaunchBody } from "../run-launch.js";
|
|
51
51
|
import { uuidv7 } from "../ids.js";
|
|
52
52
|
import { FINAL_STATES, RunFinal, RunPurged, StoreConstraint } from "../store/store.js";
|
|
53
|
-
import {
|
|
53
|
+
import { openRunLaunch, sealHandedLaunch } from "../store/seal.js";
|
|
54
|
+
import { LEARNING_CHILD_MS, learningChildrenOf, noteLearningChild, RUN_CAP_MIN_USD } from "../learning-work.js";
|
|
55
|
+
import { roomAtEndOf } from "./learning-end.js";
|
|
54
56
|
import { isCliRecord, piShaped, runEntries, runTimeline } from "../store-reads/journal.js";
|
|
55
57
|
import { pinAnnotations, recordedCalls, replayCalls, SKIPPED_WRITE, toolClassOf, toolWord, unmarkedWords } from "../learn/replay-calls.js";
|
|
56
58
|
import { listed } from "../learning-words.js";
|
|
@@ -344,12 +346,13 @@ const checkable = (deps, row) => row.id !== deps.runId && agentRun(row) && row.a
|
|
|
344
346
|
* never push them out of the read. And `audited`: an audit hold's disagreeing shadow runs (auditInputsOf), each ended.
|
|
345
347
|
* Of those, the ones whose input `workflow` takes (fits), each with its launch read back; one with an uploaded file is
|
|
346
348
|
* never an input. With how many of the agent's runs it looked at (`looked`) and why each it looked at is no input
|
|
347
|
-
* (`unfit`, `files`). Every one of them a run
|
|
348
|
-
*
|
|
349
|
+
* (`unfit`, `files`). Every one of them a run of the agent's own (the named and audited ones are read by bare id, so a
|
|
350
|
+
* record naming another agent's run never makes it an input) on no named disk (one on a named disk learns nothing,
|
|
351
|
+
* learn/learning-of.ts) since the agent's learning's reset (sinceReset). */
|
|
349
352
|
async function checkInputs(deps, workflow, pick, audited = []) {
|
|
350
353
|
const { resolveSchemaForWorkflow } = await import("@parcha/agentrun-dsl");
|
|
351
354
|
const since = await sinceReset(deps.store, deps.agentId);
|
|
352
|
-
const learns = (row) => (row.disk ?? null) === null && since(row);
|
|
355
|
+
const learns = (row) => row.agentId === deps.agentId && (row.disk ?? null) === null && since(row);
|
|
353
356
|
const named = (await Promise.all(pick.of.map((id) => deps.store.runs.get(id)))).filter((row) => row !== undefined && checkable(deps, row) && learns(row));
|
|
354
357
|
const last = pick.n ? await lastOwnRuns(deps.store, deps.agentId, pick.n + pick.of.length, deps.runId) : [];
|
|
355
358
|
const own = [...named, ...last.filter((row) => !pick.of.includes(row.id)).slice(0, pick.n)];
|
|
@@ -382,11 +385,20 @@ async function startCheck(deps, workflow, digest) {
|
|
|
382
385
|
log(`workflow-first: ${PROJECT_REPLAY_REFUSED}`);
|
|
383
386
|
return;
|
|
384
387
|
}
|
|
385
|
-
// Its replay runs are runs the runner starts
|
|
386
|
-
// the server holds none (claimSpendOff).
|
|
388
|
+
// Its replay runs are runs the runner starts: on the claimed run's own key while its claim holds it, else on the
|
|
389
|
+
// server's; skipped where the run's key was erased, or the server holds none (claimSpendOff).
|
|
387
390
|
const off = deps.spendOff?.("A learned workflow's replay check");
|
|
388
391
|
if (off)
|
|
389
392
|
return void log(`workflow-first: ${off} ${workflow.name} at ${digest} is not checked and does not serve this run`);
|
|
393
|
+
// On the run's own key it starts at the run's end, out of what the run's cap leaves then (keyedCapOf): never beside
|
|
394
|
+
// the run's own turn, which it would leave no room. Only where the runner can seal the key for its runs.
|
|
395
|
+
const keyed = deps.keyed?.() === true;
|
|
396
|
+
if (keyed && !deps.ending) {
|
|
397
|
+
if (!deps.atEnd || !deps.sealKey || !deps.runId)
|
|
398
|
+
return void log(`workflow-first: ${workflow.name} at ${digest} is not checked on this claim: its runs would spend on this run's own key, which this claim cannot hand them; it does not serve this run`);
|
|
399
|
+
deps.atEnd.later(() => startCheck({ ...deps, ending: true }, workflow, digest));
|
|
400
|
+
return void log(`workflow-first: ${workflow.name} at ${digest} is new: it is checked at this run's end, on this run's own key, out of what its cap leaves then; it does not serve this run`);
|
|
401
|
+
}
|
|
390
402
|
// Only the agent's newest revision is checked: a run pinned to an older save lays an older text.
|
|
391
403
|
const newest = deps.newest ? await deps.newest(workflow.name) : undefined;
|
|
392
404
|
if (newest !== undefined && newest !== digest) {
|
|
@@ -416,8 +428,15 @@ async function startCheck(deps, workflow, digest) {
|
|
|
416
428
|
await stopUnchecked(deps, workflow.name, digest, bar, why, (was) => was === undefined);
|
|
417
429
|
return;
|
|
418
430
|
}
|
|
431
|
+
// Each keyed replay's share of what the run's cap leaves; too little for each, it drops (`no_budget`), named as the
|
|
432
|
+
// run's learning work so its learning_work reads ended, and nothing is reserved: a later claim checks it.
|
|
433
|
+
const capUsd = keyed ? await keyedCapOf(deps, inputs.length) : undefined;
|
|
434
|
+
if (capUsd === null) {
|
|
435
|
+
await noteLearningChild(store.settings, deps.runId, { run: null, kind: "replay", at: (deps.now ?? Date.now)(), keyed: true, dropped: "no_budget" });
|
|
436
|
+
return void log(`workflow-first: ${workflow.name} at ${digest} is not checked: what this run's cap leaves is too little for ${plural(inputs.length, "replay run")} on its own key, or not known (no_budget); it does not serve this run`);
|
|
437
|
+
}
|
|
419
438
|
const said = `checking it on ${plural(inputs.length, "input")} of the agent's last ${plural(bar.compile_after, "completed run")} against its own answers`;
|
|
420
|
-
const reserved = await reserve(deps, workflow, digest, inputs, said, (was) => was === undefined, bar);
|
|
439
|
+
const reserved = await reserve(deps, workflow, digest, inputs, said, (was) => was === undefined, bar, keyed ? { capUsd } : undefined);
|
|
421
440
|
if (!reserved.won) {
|
|
422
441
|
log(`workflow-first: ${workflow.name} at ${digest}: another claim's decision on it came first; it does not serve this run`);
|
|
423
442
|
return;
|
|
@@ -685,16 +704,30 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
|
|
|
685
704
|
* now and no other revision of the workflow replays, in the one guarded write. Only the writer that kept it starts them:
|
|
686
705
|
* a claim of the same digest, or of another revision, or a person's ask, at once, starts none. A claim's (startCheck) and
|
|
687
706
|
* a person's (askReplay) are this one reservation. */
|
|
688
|
-
async function reserve(deps, workflow, digest, inputs, reason, still, check) {
|
|
707
|
+
async function reserve(deps, workflow, digest, inputs, reason, still, check, keyed) {
|
|
689
708
|
const now = deps.now ?? Date.now;
|
|
690
709
|
const ids = inputs.map(() => uuidv7());
|
|
691
|
-
const launch = replayLaunchOf(deps);
|
|
710
|
+
const launch = replayLaunchOf(deps, keyed);
|
|
692
711
|
const reserved = await recordPromotion(deps.store.learning, deps.agentId, { workflow: workflow.name, digest, at: iso(now()), decided: "replaying", reason, runs: ids, inputs: inputs.map((one) => one.run), replay_id: uuidv7(), launch, ...seedOf(deps), check }, (was, items) => still(was) && replayingOf(items, workflow.name, digest).length === 0);
|
|
693
712
|
if (reserved.won)
|
|
694
713
|
for (const [i, one] of inputs.entries())
|
|
695
|
-
await startReplay(deps, workflow, digest, one.run, one.launch, ids[i], launch);
|
|
714
|
+
await startReplay(deps, workflow, digest, one.run, one.launch, ids[i], launch, deps.runId);
|
|
696
715
|
return reserved;
|
|
697
716
|
}
|
|
717
|
+
/** The cap of each of `n` replay runs of a check on the claimed run's own key, at that run's end: what its cap leaves
|
|
718
|
+
* then (learning-end.ts roomAtEndOf: its turns, its compile turn, and the learning work it started already), shared
|
|
719
|
+
* among them to a millionth. Undefined for a run with no cap (its replays have none either). Null where that share is
|
|
720
|
+
* under a run's smallest cap, or what it spent is not known: the check drops (`no_budget`). */
|
|
721
|
+
async function keyedCapOf(deps, n) {
|
|
722
|
+
const capUsd = deps.launch.maxCostUsd;
|
|
723
|
+
if (capUsd === undefined || !deps.runId)
|
|
724
|
+
return undefined;
|
|
725
|
+
const room = await roomAtEndOf(deps.store, deps.runId, capUsd);
|
|
726
|
+
if (room === null)
|
|
727
|
+
return null;
|
|
728
|
+
const each = Math.floor((room / n) * 1e6 + 1e-6) / 1e6;
|
|
729
|
+
return each < RUN_CAP_MIN_USD ? null : each;
|
|
730
|
+
}
|
|
698
731
|
/** How many of a connected agent's reserved native turns its check gives back in a row (failed, a learned workflow or
|
|
699
732
|
* nested call in it, redacted evidence, no shadow report, or a shadow that did not answer; never a cancel, and a turn
|
|
700
733
|
* that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the
|
|
@@ -866,9 +899,10 @@ async function setAside(deps, pending) {
|
|
|
866
899
|
/** The launch a replay's runs all run with (PromotionRecord.launch), chosen once by the claim or person reserving it:
|
|
867
900
|
* `deps.launch` as a replay run takes it (a claim's claimed run's; a person's ask makes one now), the revision it runs,
|
|
868
901
|
* and the claimed run as the one whose per_run MCP credentials its runs are handed, when the server can seal them. A
|
|
869
|
-
* person's ask claims no run, so an owner's replay runs are handed none.
|
|
870
|
-
|
|
871
|
-
|
|
902
|
+
* person's ask claims no run, so an owner's replay runs are handed none. `keyed`: its runs spend on the claimed run's own
|
|
903
|
+
* model key, each capped at `capUsd` (keyedCapOf; none for a run with no cap), never at the claimed run's whole cap. */
|
|
904
|
+
function replayLaunchOf(deps, keyed) {
|
|
905
|
+
const launch = keyed ? { ...deps.launch, maxCostUsd: keyed.capUsd } : deps.launch;
|
|
872
906
|
const base = {
|
|
873
907
|
input: null,
|
|
874
908
|
title: "",
|
|
@@ -885,7 +919,7 @@ function replayLaunchOf(deps) {
|
|
|
885
919
|
...(launch.learning ? { learning: launch.learning } : {}),
|
|
886
920
|
...(launch.archilDisk ? { archilDisk: launch.archilDisk } : {}),
|
|
887
921
|
};
|
|
888
|
-
return { revision: deps.revisionId, body: launchBody(base), ...((deps.sealKey || held()) && deps.runId ? { handed_from: deps.runId } : {}) };
|
|
922
|
+
return { revision: deps.revisionId, body: launchBody(base), ...((deps.sealKey || held()) && deps.runId ? { handed_from: deps.runId } : {}), ...(keyed ? { keyed: true } : {}) };
|
|
889
923
|
}
|
|
890
924
|
/** Whether `was`, a digest's newest record now, is still the replay `record` reserved: replaying, under the same replay
|
|
891
925
|
* id. A replay settled meanwhile, and a newer replay of the same revision its owner started since (a held revision may
|
|
@@ -918,20 +952,23 @@ async function cancelUnended(deps, record) {
|
|
|
918
952
|
return cancelled;
|
|
919
953
|
}
|
|
920
954
|
/** The per_run MCP credentials run `launch.handed_from` was handed (its launch's sealed column, opened under the seal
|
|
921
|
-
* key),
|
|
922
|
-
*
|
|
923
|
-
* names no such run (an owner's), that run
|
|
924
|
-
*
|
|
955
|
+
* key), and its own model key for a `keyed` replay, sealed for the replay run `id` alone (store/seal.ts
|
|
956
|
+
* sealHandedLaunch): the replay's claim reads them where any run's claim does (runner/mcp-claim.ts, claim-secrets.ts
|
|
957
|
+
* claimModelKey), and its end erases them as any run's. None when the replay names no such run (an owner's), that run
|
|
958
|
+
* was handed none, or they do not open. A keyed replay whose run holds no key now is never started (throws): it would
|
|
959
|
+
* spend on the server's key. Never written anywhere else, never logged. */
|
|
925
960
|
async function handedTo(deps, launch, id) {
|
|
926
961
|
const from = launch.handed_from;
|
|
927
962
|
if (!from)
|
|
928
963
|
return undefined;
|
|
964
|
+
const keyed = launch.keyed === true;
|
|
929
965
|
// A run's own process holds no seal key: its runner seals them again, from its own run alone (held.ts handOn).
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
966
|
+
const sealed = deps.sealKey
|
|
967
|
+
? await deps.store.runs.launch(from).then((one) => (one.sealed === null ? undefined : sealHandedLaunch(deps.sealKey, from, one.sealed, id, keyed)), () => undefined)
|
|
968
|
+
: await held()?.handOn(from, id, keyed);
|
|
969
|
+
if (keyed && (!deps.sealKey || !sealed || !openRunLaunch(deps.sealKey, id, sealed)?.model))
|
|
970
|
+
throw new Error(`the replay ${id} is not started: the run whose own model key it would spend on holds none now`);
|
|
971
|
+
return sealed;
|
|
935
972
|
}
|
|
936
973
|
/** Starts the replay of `workflow` at `digest` on agent run `of` (its launch `from`) as run `id` (the id its reserved
|
|
937
974
|
* record names), with the replay's chosen `launch` (replayLaunchOf: its run launch, revision and handed credentials,
|
|
@@ -939,7 +976,7 @@ async function handedTo(deps, launch, id) {
|
|
|
939
976
|
* relaunch and the reserving claim at once), and it is left to that one; false too when run `of` was purged since its
|
|
940
977
|
* launch was read (the store refuses it, RunPurged, nothing written): the replay never starts, counted so past its
|
|
941
978
|
* deadline. */
|
|
942
|
-
async function startReplay(deps, workflow, digest, of, from, id, launch) {
|
|
979
|
+
async function startReplay(deps, workflow, digest, of, from, id, launch, parent) {
|
|
943
980
|
const { store, agentId } = deps;
|
|
944
981
|
const base = readLaunchBody(launch.body);
|
|
945
982
|
if (!base)
|
|
@@ -947,8 +984,17 @@ async function startReplay(deps, workflow, digest, of, from, id, launch) {
|
|
|
947
984
|
const source = sourceSyncOf((await store.agents.revision(launch.revision))?.body);
|
|
948
985
|
if (base.sourceProject || source && !deps.admitAuxiliary)
|
|
949
986
|
throw new ReplayRefused("conflict", PROJECT_REPLAY_REFUSED);
|
|
950
|
-
|
|
987
|
+
// A keyed replay names the run whose own key it spends on: its cost is that run's learning, never its revision's
|
|
988
|
+
// (learn/ledger.ts record).
|
|
989
|
+
const paidBy = launch.keyed && launch.handed_from ? { paidBy: launch.handed_from } : {};
|
|
990
|
+
// Its start, and its deadline from it (learning-work.ts LEARNING_CHILD_MS): its runner cancels it there.
|
|
991
|
+
const at = (deps.now ?? Date.now)();
|
|
992
|
+
const replay = { ...base, input: from.input, title: `Replay of ${workflow.name}: ${from.title}`.slice(0, 200), replay: { of, workflow: workflow.name, digest, ...paidBy, deadlineAt: at + LEARNING_CHILD_MS } };
|
|
951
993
|
const sealed = await handedTo(deps, launch, id);
|
|
994
|
+
// The reserving claim's run names it as its learning work before it exists (learning-work.ts), so no replay runs that
|
|
995
|
+
// its run's learning_work does not list; the same write moves that run's learning deadline to this one's.
|
|
996
|
+
if (parent)
|
|
997
|
+
await noteLearningChild(store.settings, parent, { run: id, kind: "replay", at, ...(launch.keyed ? { keyed: true } : {}) });
|
|
952
998
|
try {
|
|
953
999
|
if (source)
|
|
954
1000
|
return (await deps.admitAuxiliary({ runId: id, agentId, revisionId: launch.revision, launch: replay, ...(sealed ? { sealed } : {}) })).created;
|
|
@@ -973,16 +1019,21 @@ async function startReplay(deps, workflow, digest, of, from, id, launch) {
|
|
|
973
1019
|
* this claim created. */
|
|
974
1020
|
async function relaunch(deps, workflow, digest, record) {
|
|
975
1021
|
const { store } = deps;
|
|
976
|
-
|
|
1022
|
+
// Its runs spend on the server's key: a claim on its run's own key starts none of them, and a check on another run's
|
|
1023
|
+
// key (`keyed`) is never created again, that key being erased with its run's claim.
|
|
1024
|
+
if (deps.spendOff?.("A replay") || deps.keyed?.())
|
|
977
1025
|
return 0;
|
|
978
1026
|
const since = (deps.now ?? Date.now)() - Date.parse(record.at);
|
|
979
1027
|
const launch = record.launch;
|
|
980
|
-
if (!launch || since <= REPLAY_LAUNCH_GRACE_MS || since > REPLAY_DEADLINE_MS)
|
|
1028
|
+
if (!launch || launch.keyed || since <= REPLAY_LAUNCH_GRACE_MS || since > REPLAY_DEADLINE_MS)
|
|
981
1029
|
return 0;
|
|
1030
|
+
// A run the reserving claim named as its learning work and did not create (it crashed between the two) stays missing,
|
|
1031
|
+
// counted as never started: that run's learning_work read it ended, and never reads it running again.
|
|
1032
|
+
const named = launch.handed_from ? new Set((await learningChildrenOf(store.settings, launch.handed_from)).map((one) => one.run)) : new Set();
|
|
982
1033
|
let made = 0;
|
|
983
1034
|
for (const [i, id] of (record.runs ?? []).entries()) {
|
|
984
1035
|
const of = record.inputs?.[i];
|
|
985
|
-
if (!of || (await store.runs.get(id)))
|
|
1036
|
+
if (!of || named.has(id) || (await store.runs.get(id)))
|
|
986
1037
|
continue;
|
|
987
1038
|
const from = await store.runs.launch(of).then((one) => readLaunchBody(one.body), () => undefined);
|
|
988
1039
|
if (from && (await startReplay(deps, workflow, digest, of, from, id, launch)))
|
|
@@ -76,6 +76,13 @@ export interface ReflectDeps {
|
|
|
76
76
|
}) => Promise<void>;
|
|
77
77
|
/** The compile turn's deadline, every attempt in it. Default learn/compile.ts COMPILE_TIMEOUT_MS. */
|
|
78
78
|
readonly compileDeadlineMs?: number;
|
|
79
|
+
/** Keeps the run's learning deadline at least `until` (its compile turn's start + that deadline), before the turn asks a
|
|
80
|
+
* model (learning-work.ts noteLearningDeadline). A write that fails fails the step: no compile turn without its bound.
|
|
81
|
+
* Absent: none kept. */
|
|
82
|
+
readonly compileStarts?: (input: {
|
|
83
|
+
runId: string;
|
|
84
|
+
until: number;
|
|
85
|
+
}) => Promise<void>;
|
|
79
86
|
/** One compile draft through the checks (learning-end.ts checkDraftOf): its errors, else what is committed and its
|
|
80
87
|
* digest. `revised`: a revision's workflow and the commit of main it was read at, its conflict base. */
|
|
81
88
|
readonly checkDraft: (input: {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// nothing.
|
|
13
13
|
import { cutStrings } from "../key-refusal.js";
|
|
14
14
|
import { redactSecrets } from "../learn/index.js";
|
|
15
|
-
import { compileTurn } from "../learn/compile.js";
|
|
15
|
+
import { COMPILE_TIMEOUT_MS, compileTurn } from "../learn/compile.js";
|
|
16
16
|
import { correctionsCapOf, said, STOPPED } from "../learning-words.js";
|
|
17
17
|
/** A turn the spend cap refused (the cap's refusal words, cap.ts CAP_REFUSAL_PREFIX). */
|
|
18
18
|
export const CAP_REFUSAL = /^spend_cap_reached(?: \([^)]*\))?: /;
|
|
@@ -92,6 +92,7 @@ export function createReflectHook(deps) {
|
|
|
92
92
|
// since), and it is the revised workflow's conflict base in every check of the turn.
|
|
93
93
|
let revised = compile.mode === "revise" && compile.base ? { workflow: compile.workflow, base: compile.base } : undefined;
|
|
94
94
|
let capped = false;
|
|
95
|
+
await deps.compileStarts?.({ runId: input.runId, until: now() + (deps.compileDeadlineMs ?? COMPILE_TIMEOUT_MS) });
|
|
95
96
|
const result = await compileTurn({
|
|
96
97
|
ask: async (prompt, attempt, left) => {
|
|
97
98
|
asked = true;
|
|
@@ -40,7 +40,7 @@ import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
|
|
|
40
40
|
import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
|
|
41
41
|
import { FAUX_VENDOR_API_ENV } from "../tools.js";
|
|
42
42
|
import { withinCarried } from "../paid-calls.js";
|
|
43
|
-
import {
|
|
43
|
+
import { sealHandedLaunch } from "../store/seal.js";
|
|
44
44
|
import { runZone } from "../environment.js";
|
|
45
45
|
import { shadowRunId } from "../learn/audit.js";
|
|
46
46
|
import { agreeOnOf } from "../learning-setting.js";
|
|
@@ -50,7 +50,8 @@ import { agentDirName, recordingsFolder, runFolder, scratchFolder } from "../wor
|
|
|
50
50
|
import { keptKeyOf } from "../workspace/computer-kept.js";
|
|
51
51
|
import { waitEndedKey } from "../browser-wait-ended.js";
|
|
52
52
|
import { browserHoldKey } from "../browser-hold.js";
|
|
53
|
-
import { claimModelKey, claimSecrets, claimSpendOff, hostDecisionKeys, learnedDecisionKeys, openRunModelKey, savedModelKeys, sendsNoModelKey, serverKeyless, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
53
|
+
import { claimModelKey, claimSecrets, claimSpendOff, hostDecisionKeys, keyedNow, learnedDecisionKeys, openRunModelKey, savedModelKeys, sendsNoModelKey, serverKeyless, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
|
|
54
|
+
import { atRunEnd, keyedBesideOf } from "../learning-work.js";
|
|
54
55
|
import { githubAppAccess } from "./github-app.js";
|
|
55
56
|
import { githubPullOf, githubTargetOf } from "../github.js";
|
|
56
57
|
import { isObject } from "../validate.js";
|
|
@@ -452,8 +453,9 @@ const writableSetting = ([key, value], bound) => {
|
|
|
452
453
|
/** The store's methods a run's loop calls, each with what binds it to the claim. A method not here is refused, and the
|
|
453
454
|
* refusal is said on the runner's log. Reads of the claim's run, its launch, its commands and its agent's revisions;
|
|
454
455
|
* of what was spent beside it (its learning grades, its own audit's shadow run's row and launch, which its cap gates
|
|
455
|
-
* read
|
|
456
|
-
* claim's own rows (settingReadable).
|
|
456
|
+
* read; the replays it started on its own key are summed by its runner, Held.keyedBeside); of the agent's own runs (its
|
|
457
|
+
* learning reads its past runs); the server's settings its tools read and the claim's own rows (settingReadable).
|
|
458
|
+
* Writes only under the claim. */
|
|
457
459
|
const STORE_CALLS = new Map([
|
|
458
460
|
["flush", always],
|
|
459
461
|
["runs.get", ownRunOrShadow],
|
|
@@ -695,6 +697,8 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
695
697
|
let learnedFlows = [];
|
|
696
698
|
/** The claim's one learned first choice: its promotion's writes are made once, however often the process asks. */
|
|
697
699
|
let chosen;
|
|
700
|
+
/** What the claim's learned first choice queued for its run's end (a check on its own key), run by its end-of-run step. */
|
|
701
|
+
const atEnd = atRunEnd(log);
|
|
698
702
|
const held = {
|
|
699
703
|
projectCheckpoint: (...args) => {
|
|
700
704
|
if (args.length > 1 || args[0] !== undefined && !(args[0] instanceof AbortSignal))
|
|
@@ -916,13 +920,14 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
916
920
|
liveViewerDrop: (tag) => dropLiveViewer(store, claim, tag),
|
|
917
921
|
// The claim's own run, whatever the process names: its view on this runner hears the change.
|
|
918
922
|
computerHold: async (change) => heardComputerHold(claim.runId, change, cut),
|
|
919
|
-
handOn: async (from, id) => {
|
|
923
|
+
handOn: async (from, id, keyed) => {
|
|
920
924
|
if (from !== claim.runId || typeof id !== "string")
|
|
921
925
|
return undefined;
|
|
922
926
|
const sealed = await store.runs.launch(from).then((one) => one.sealed ?? null, () => null);
|
|
923
|
-
|
|
924
|
-
return handed && Object.keys(handed).length ? sealRunMcpAuth(sealKey, id, handed) : undefined;
|
|
927
|
+
return sealed === null ? undefined : sealHandedLaunch(sealKey, from, sealed, id, keyed === true);
|
|
925
928
|
},
|
|
929
|
+
// The claim's own run's, whatever the process names: its learning_work row and the replays it names are read here.
|
|
930
|
+
keyedBeside: () => keyedBesideOf(store, claim.runId),
|
|
926
931
|
signInPeek: (resolution) => peekSignIn(store, sealKey, run.agentId, String(resolution)),
|
|
927
932
|
signInForgotten: (resolution) => forgottenSignIns(store, sealKey, run.agentId, String(resolution)),
|
|
928
933
|
emailAccount: async () => (grantsEmail(granted) ? openAccount(store, sealKey) : undefined),
|
|
@@ -1017,9 +1022,10 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
1017
1022
|
return rows?.compared ? { also: [], compared: dataOnly(rows.compared) } : undefined;
|
|
1018
1023
|
}
|
|
1019
1024
|
// The audit's spend, skipped as the run's spec skips it (claim-secrets.ts claimSpendOff): over the claim's own key.
|
|
1020
|
-
const
|
|
1025
|
+
const runKey = await claimModelKey(keys, claim.runId);
|
|
1026
|
+
const spendOff = await claimSpendOff(keys, runKey);
|
|
1021
1027
|
// The audit's start after the step (audit.ts withAudit) is this runner's too: it reads the run's journal and writes
|
|
1022
|
-
// the ledger and a run.
|
|
1028
|
+
// the ledger and a run, and starts what the claim queued for the run's end first.
|
|
1023
1029
|
const step = withAudit(learningEndOfRun(launch, {
|
|
1024
1030
|
store,
|
|
1025
1031
|
data: deps.data,
|
|
@@ -1029,7 +1035,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
1029
1035
|
stored: () => storeSecrets(store, sealKey, deps.data),
|
|
1030
1036
|
log,
|
|
1031
1037
|
decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys(keys, DECISION_PROVIDER_KEYS)) }),
|
|
1032
|
-
}), { store, agentId: run.agentId, revisionId: run.revisionId, context: BACKGROUND_CONTEXT, shown, log, sealKey, spendOff, launch, redact: cut, admitAuxiliary });
|
|
1038
|
+
}), { store, agentId: run.agentId, revisionId: run.revisionId, context: BACKGROUND_CONTEXT, shown, log, sealKey, spendOff, keyed: keyedNow(runKey), atEnd, launch, redact: cut, admitAuxiliary });
|
|
1033
1039
|
if (!step)
|
|
1034
1040
|
return undefined;
|
|
1035
1041
|
// keptOf is the run's process's, asked over the channel: read once, for the round learningEndOfRun reads (the
|
|
@@ -1058,9 +1064,10 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
|
1058
1064
|
// workflows).
|
|
1059
1065
|
const start = learningStartOf(launch);
|
|
1060
1066
|
const laid = ask?.laid === true && start && !seedFailed(start) && !start.noWorkflows ? await workflowsAt({ store, agentId: run.agentId, shown }, start.seed).catch(() => []) : [];
|
|
1061
|
-
const
|
|
1067
|
+
const runKey = await claimModelKey(keys, claim.runId);
|
|
1068
|
+
const spendOff = await claimSpendOff(keys, runKey);
|
|
1062
1069
|
const outputSchema = revision.body.outputSchema;
|
|
1063
|
-
const got = await learnedFirst({ store, sealKey, agentId: run.agentId, runId: claim.runId, revisionId: run.revisionId, kind: revision.kind, ...(outputSchema !== undefined ? { outputSchema } : {}), launch, context: BACKGROUND_CONTEXT, log, shown, spendOff, admitAuxiliary }, laid);
|
|
1070
|
+
const got = await learnedFirst({ store, sealKey, agentId: run.agentId, runId: claim.runId, revisionId: run.revisionId, kind: revision.kind, ...(outputSchema !== undefined ? { outputSchema } : {}), launch, context: BACKGROUND_CONTEXT, log, shown, spendOff, keyed: keyedNow(runKey), atEnd, admitAuxiliary }, laid);
|
|
1064
1071
|
learnedFlows = got.workflows;
|
|
1065
1072
|
return cutDeep(dataOnly(got), cut);
|
|
1066
1073
|
})()),
|
|
@@ -1425,6 +1432,8 @@ export function childLoop(options, slots, loopDeps, login) {
|
|
|
1425
1432
|
const reach = await mcpReachOf(deps);
|
|
1426
1433
|
const init = {
|
|
1427
1434
|
claim, data: deps.data, signal: loopDeps.signal, where: deps.store.where, ...(traced ? { traced: true } : {}),
|
|
1435
|
+
// A learning child's deadline, its abort posted across (run-channel.ts) to the process's request gate.
|
|
1436
|
+
...(loopDeps.pastDeadline ? { pastDeadline: loopDeps.pastDeadline } : {}),
|
|
1428
1437
|
// The plane its keys were chosen by (`capped`): the process runs its tools on it, never on a later read of the
|
|
1429
1438
|
// server's settings, which may have moved since.
|
|
1430
1439
|
...(capped.plane ? { plane: capped.plane } : {}),
|
package/dist/runner/run-child.js
CHANGED
|
@@ -222,6 +222,7 @@ channel.expose("loop", async (method, args) => {
|
|
|
222
222
|
journal: () => journal,
|
|
223
223
|
flush: () => channel.call("runner", "flush", []),
|
|
224
224
|
signal: init.signal,
|
|
225
|
+
...(init.pastDeadline ? { pastDeadline: init.pastDeadline } : {}),
|
|
225
226
|
delivered: channel.call("runner", "delivered", []).catch(() => undefined),
|
|
226
227
|
deliverNow: () => channel.call("runner", "deliverNow", []),
|
|
227
228
|
live: (reader) => void (read = reader),
|
package/dist/runner/runner.d.ts
CHANGED
|
@@ -131,6 +131,10 @@ export interface RunnerOptions {
|
|
|
131
131
|
clock?: BoundTimer & {
|
|
132
132
|
now(): number;
|
|
133
133
|
};
|
|
134
|
+
/** For tests: the clock (epoch ms) a held learning child's deadline is read on (its launch's replay or audit
|
|
135
|
+
* deadline_at, store.runs.learningDeadlines): one still held at it is cancelled, as a person's cancel is. Default
|
|
136
|
+
* Date.now. */
|
|
137
|
+
learningClock?: () => number;
|
|
134
138
|
}
|
|
135
139
|
/** A runner's memory budget and its runs' weights, in MiB (RunnerOptions.memory). `weigh` answers each id it is given; an
|
|
136
140
|
* id it leaves out weighs nothing. */
|
|
@@ -195,6 +199,11 @@ export type RunnerEvent = {
|
|
|
195
199
|
| {
|
|
196
200
|
type: "refusing";
|
|
197
201
|
reason: string | null;
|
|
202
|
+
}
|
|
203
|
+
/** A learning child (a check's replay run, an audit's shadow run) held at its deadline: its cancel is written. */
|
|
204
|
+
| {
|
|
205
|
+
type: "learning-deadline";
|
|
206
|
+
runId: string;
|
|
198
207
|
} | {
|
|
199
208
|
type: "error";
|
|
200
209
|
runId?: string;
|