@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.
Files changed (128) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +32 -13
  3. package/dist/adapters.js +4 -2
  4. package/dist/agent-delete.d.ts +3 -3
  5. package/dist/agent-delete.js +50 -4
  6. package/dist/chatgpt-plan.d.ts +8 -1
  7. package/dist/chatgpt-plan.js +55 -6
  8. package/dist/console/assets/{backend-DEgVn5lC.js → backend-BxQ2G1M0.js} +2 -2
  9. package/dist/console/assets/{index-CG5tELph.js → index-C8Y5Zl8x.js} +2 -2
  10. package/dist/console/assets/share-CjBJ_rxP.js +6 -0
  11. package/dist/console/index.html +1 -1
  12. package/dist/console/share.html +1 -1
  13. package/dist/harness-opencode/adapter.d.ts +3 -1
  14. package/dist/harness-opencode/adapter.js +6 -2
  15. package/dist/harness-opencode/harness.d.ts +4 -0
  16. package/dist/harness-opencode/harness.js +6 -1
  17. package/dist/host-tools.d.ts +18 -3
  18. package/dist/host-tools.js +27 -4
  19. package/dist/learn/ledger.d.ts +37 -16
  20. package/dist/learn/ledger.js +56 -24
  21. package/dist/learn/promote.d.ts +4 -1
  22. package/dist/learning-cost.d.ts +5 -3
  23. package/dist/learning-model.js +7 -5
  24. package/dist/learning-work.d.ts +69 -0
  25. package/dist/learning-work.js +148 -0
  26. package/dist/openapi.js +23 -9
  27. package/dist/run-export.js +7 -4
  28. package/dist/run-launch.d.ts +6 -1
  29. package/dist/run-launch.js +10 -3
  30. package/dist/run-view.js +9 -3
  31. package/dist/runnable.js +5 -5
  32. package/dist/runner/adapter-loop.js +31 -3
  33. package/dist/runner/adapter-run-spec.d.ts +14 -3
  34. package/dist/runner/adapter-run-spec.js +50 -19
  35. package/dist/runner/adapters/index.d.ts +2 -0
  36. package/dist/runner/adapters/index.js +3 -0
  37. package/dist/runner/adapters/pi.d.ts +42 -3
  38. package/dist/runner/adapters/pi.js +114 -13
  39. package/dist/runner/audit.d.ts +8 -2
  40. package/dist/runner/audit.js +34 -18
  41. package/dist/runner/book-cut.d.ts +6 -0
  42. package/dist/runner/book-cut.js +38 -0
  43. package/dist/runner/claim-secrets.d.ts +9 -4
  44. package/dist/runner/claim-secrets.js +10 -5
  45. package/dist/runner/cli-run-spec.d.ts +0 -2
  46. package/dist/runner/cli-run-spec.js +44 -19
  47. package/dist/runner/held.d.ts +6 -3
  48. package/dist/runner/learned-first.d.ts +5 -0
  49. package/dist/runner/learned-first.js +1 -1
  50. package/dist/runner/learning-end.d.ts +15 -8
  51. package/dist/runner/learning-end.js +23 -7
  52. package/dist/runner/loop-contract.d.ts +4 -0
  53. package/dist/runner/main.js +2 -0
  54. package/dist/runner/model-route.d.ts +4 -0
  55. package/dist/runner/model-route.js +1 -1
  56. package/dist/runner/pr-checkout.d.ts +12 -0
  57. package/dist/runner/pr-checkout.js +21 -2
  58. package/dist/runner/promotion.d.ts +9 -2
  59. package/dist/runner/promotion.js +79 -28
  60. package/dist/runner/reflect-hook.d.ts +7 -0
  61. package/dist/runner/reflect-hook.js +2 -1
  62. package/dist/runner/run-child-host.js +21 -12
  63. package/dist/runner/run-child.js +1 -0
  64. package/dist/runner/runner.d.ts +9 -0
  65. package/dist/runner/runner.js +156 -25
  66. package/dist/runner/store-port.d.ts +4 -1
  67. package/dist/runner/workflow-first.js +4 -3
  68. package/dist/runner/workflow-loop.js +13 -1
  69. package/dist/secret-cut.d.ts +4 -0
  70. package/dist/secret-cut.js +1 -1
  71. package/dist/secret-rules.d.ts +2 -0
  72. package/dist/secret-rules.js +63 -19
  73. package/dist/server.js +20 -9
  74. package/dist/share-host.js +6 -3
  75. package/dist/store/schema.d.ts +4 -3
  76. package/dist/store/schema.js +4 -3
  77. package/dist/store/seal.d.ts +8 -2
  78. package/dist/store/seal.js +13 -2
  79. package/dist/store/sqlite/learning-rows.js +2 -1
  80. package/dist/store/sqlite/run-patch.js +4 -4
  81. package/dist/store/sqlite/store.js +28 -4
  82. package/dist/store/store.d.ts +5 -0
  83. package/dist/store-reads/journal.d.ts +2 -0
  84. package/dist/store-reads/journal.js +1 -1
  85. package/dist/store-reads/learning.d.ts +4 -3
  86. package/dist/store-reads/learning.js +62 -18
  87. package/dist/store-view.d.ts +3 -0
  88. package/dist/store-view.js +18 -1
  89. package/dist/tool-list.d.ts +4 -0
  90. package/dist/tool-list.js +4 -0
  91. package/dist/tools.js +2 -2
  92. package/dist/workspace/attach.js +22 -5
  93. package/dist/workspace/kind-skills/desktop/SKILL.md +7 -3
  94. package/package.json +12 -12
  95. package/templates/kyb/agent.md +7 -1
  96. package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
  97. package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
  98. package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
  99. package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
  100. package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
  101. package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
  102. package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
  103. package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
  104. package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
  105. package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
  106. package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
  107. package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
  108. package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
  109. package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
  110. package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
  111. package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
  112. package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
  113. package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
  114. package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
  115. package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
  116. package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
  117. package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
  118. package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
  119. package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
  120. package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
  121. package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
  122. package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
  123. package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
  124. package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
  125. package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
  126. package/templates/kyb/kyb.schema.json +2 -2
  127. package/templates/kyb/rules/SANCTIONS.md +82 -13
  128. package/dist/console/assets/share-CIeFK2Oe.js +0 -6
@@ -51,14 +51,15 @@ import { settingOfDefinition } from "../computer-setting.js";
51
51
  import { computerFilesNote, computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
52
52
  import { computerTurnedOff, hadComputer, recordComputerOff } from "./computer-journal.js";
53
53
  import { hostLifecycle } from "./adapter-loop.js";
54
- import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, graderRouteOf, heldModelOf, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, seedEvalFiles, webHostTools } from "./adapter-run-spec.js";
54
+ import { adapterRunGate, answersCut, BROWSER_TOOL, browserHostTools, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, graderRouteOf, heldModelOf, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, seedEvalFiles, webHostTools } from "./adapter-run-spec.js";
55
55
  import { openTierProxies } from "./adapters/pi.js";
56
56
  import { signInReads } from "../sign-ins-store.js";
57
57
  import { isWebHostTool } from "../tool-list.js";
58
58
  import { hostToolOf } from "../host-tools.js";
59
59
  import { ASK_TOOL, askPerson } from "../tools.js";
60
60
  import { fakedPlane } from "../web-fake.js";
61
- import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
61
+ import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, keyedNow, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
62
+ import { atRunEnd } from "../learning-work.js";
62
63
  import { claimMetering, mcpWhereHeld } from "./mcp-run.js";
63
64
  import { held as runnerSeam, heldSignInReads } from "./held.js";
64
65
  import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
@@ -82,7 +83,7 @@ import { heldTokenLogin } from "../claude-login-token.js";
82
83
  import { heldSpecOf } from "./held-run.js";
83
84
  import { loopComputerOf } from "./computer-channel.js";
84
85
  import { githubAppAccess } from "./github-app.js";
85
- import { prCheckoutForClaim } from "./pr-checkout.js";
86
+ import { checkoutWhereNoExec, prCheckoutForClaim } from "./pr-checkout.js";
86
87
  import { holdStored, storeSecrets } from "./store-secrets.js";
87
88
  import { bashPolicyOf } from "../bash-read-only.js";
88
89
  import { monidForClaim, withMonid } from "./monid-run.js";
@@ -90,8 +91,6 @@ import { verifyPlacedProject, movedSkillFiles } from "../source-sync/claim.js";
90
91
  import { projectCheckpointForRun } from "./project-checkpoint.js";
91
92
  import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
92
93
  import { agentOfRun, routeTrace } from "../otel/genai.js";
93
- /** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
94
- export const cliRefusesKind = (kind) => kind === "browser" ? "This agent's computer is a browser, which only the pi harness drives here: pick pi for this agent, or another kind of computer in Settings → Computers." : undefined;
95
94
  /** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
96
95
  * harness's own wire where its entry says its model is chosen there (a pin there is its own provider/model-id, never a
97
96
  * gateway's), else as the run's usual models, a pin sent as pinned (modelAskOf). */
@@ -155,6 +154,14 @@ function chosenCapModel(entry, env, chosen, wire) {
155
154
  // toward the run's free-model limit, as pi's on the same route do (model-route.ts ModelRoute.local).
156
155
  return priced.provider === OLLAMA_PROVIDER ? { ...capped, local: true } : capped;
157
156
  }
157
+ /** The context window of the run's model (modelsOf), in tokens, from its catalog entry, or the entry that bills it (its
158
+ * entry's priceModel) where the chosen one is not listed: the session's window (SessionSpec.contextWindow), which the
159
+ * kernel's tool bridge holds each result to its share of. Undefined where neither names one: the host's bound alone. */
160
+ function chosenWindow(entry, env, chosen) {
161
+ const windowOf = (ref) => chosen.models.getModel(ref.provider, ref.modelId)?.contextWindow;
162
+ const window = windowOf(chosen.model) ?? windowOf(entry.priceModel(env, chosen.model));
163
+ return typeof window === "number" && Number.isFinite(window) && window > 0 ? window : undefined;
164
+ }
158
165
  /** The model a run of the CLI harness `entry` on `ref` (a revision's model; none, this host's default for it) is capped
159
166
  * at here, as its run's spec prices it (modelsOf, chosenCapModel), before any run: a save's cap warning (cap-short.ts)
160
167
  * prices its least step on it. */
@@ -421,8 +428,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
421
428
  const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, toolSettings: body.toolSettings, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, redact: run.redact, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, say: (words) => run.phase?.(words), ...(facts.toolsFixedAtStart ? { toolsFixedAtStart: true } : {}), ...claimMetering(deps, web, launch) });
422
429
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
423
430
  holds.hold({ passed: mcp });
424
- // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
425
- const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
431
+ // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts): on an Archil
432
+ // region with no serverless exec, in the run's computer once it mounts the folder (below, checkoutWhereNoExec).
433
+ let checkout = body.checkout && noExec === undefined ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
426
434
  holds.hold({ checkout });
427
435
  // A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
428
436
  if (!(deps.sealKey === undefined && runnerSeam()))
@@ -455,14 +463,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
455
463
  // revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
456
464
  // run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does, with
457
465
  // what became of the agent's own computer said on the run's timeline.
458
- // A browser computer is driven by the browser tool, which runs on pi's native route alone: a CLI's run of an agent
459
- // whose computer is a browser is refused in words at its claim, before anything is made.
466
+ // A browser computer is driven by the browser tool, bound below as host tools (browserHostTools) on that computer.
460
467
  // A person's stop ends the claim's waits at once: a first image pull or registration (Agent37's runs minutes) among them.
461
468
  // Whether an earlier claim made the run a computer of its own is the run's journal's to say (hadComputer), as the pi
462
469
  // spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount); a park's
463
470
  // row names the disk that credential is on (mountDisk). Its screen's recording (computer.record) goes in the run's
464
471
  // recordings folder, as the pi spec's does.
465
- { ...deps.computerDeps, mode, noExec, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(offAlready ? { turnedOff: offAlready } : {}), recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit(), mountDisk: () => archil.disk.id } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
472
+ { ...deps.computerDeps, mode, noExec, workspace: ws.workspace, sealKey: deps.sealKey, ...(offAlready ? { turnedOff: offAlready } : {}), recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit(), mountDisk: () => archil.disk.id } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
466
473
  holds.hold({ computer });
467
474
  const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
468
475
  const heldComputer = heldSpecOf(launch, loopComputer);
@@ -491,6 +498,11 @@ async function cliSpec(launch, run, deps, claim, holds) {
491
498
  filedIn = tools.workspace;
492
499
  let remoteProjectCapture = false;
493
500
  holds.hold({ tools: { end: () => remoteProjectCapture ? Promise.resolve() : tools.end() } });
501
+ // On an Archil region with no serverless exec, the checkout now, as the pi spec makes it (pr-checkout.ts).
502
+ if (body.checkout && noExec !== undefined) {
503
+ checkout = await checkoutWhereNoExec(deps, tools.shell === "computer" ? tools.workspace : undefined, noExec, launch, cut, claimSignal, (part) => holds.hold({ checkout: part }), body.checkout, (words) => run.phase?.(words));
504
+ holds.hold({ checkout });
505
+ }
494
506
  const root = runFolder(deps.data, runRow.agentId, claim.runId);
495
507
  // The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
496
508
  // learned laid in (learning.ts laidLearned, from the launch's learning start, so the runner reads no learning rows), its
@@ -565,6 +577,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
565
577
  // no key saved for its harness, above) and takes no learning step (below), so it holds the computer on a host with no
566
578
  // key for its model, and a key saved since runs a new run, never this one.
567
579
  const chosen = heldRefusal !== undefined ? heldChoice(body.model) : await modelsOf(entry, env, modelAskOf(launch.model, body.model));
580
+ // A held run starts no model, so it has no window to hold results to.
581
+ const window = heldRefusal === undefined ? chosenWindow(entry, env, chosen) : undefined;
568
582
  if (heldRefusal === undefined) {
569
583
  await planBeforeRun(env, chosen.model);
570
584
  if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
@@ -681,8 +695,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
681
695
  // session's proxied models (learnedWorkflowHostTool), each node a request on the run's one route labelled
682
696
  // learned_workflow, booked on the run's one ledger. The web tools and the learned workflow's call nodes run on the run's
683
697
  // scoped keys (claim-secrets.ts), the run's plane threaded for the web tools. Each call goes through the run's gate
684
- // (spec.gate), and a web tool books its paid requests on the run's one ledger itself (bookedIn). The browser is pi's
685
- // only (its native route): a CLI harness is not handed it.
698
+ // (spec.gate), and a web tool books its paid requests on the run's one ledger itself (bookedIn). The browser, granted or
699
+ // the agent's computer, is bound on the same ToolHost (browserHostTools): its registrations are host tools, its money on
700
+ // the run's one ledger.
686
701
  const results = new Map();
687
702
  const ctx = hostToolCtxOf(run, context, results, root);
688
703
  // The runner's one redactor (the loop's), else this spec's log cut: the claim's keys join it, and the answers of the tools
@@ -696,8 +711,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
696
711
  // live search) is not handed the host's web_search beside it.
697
712
  const webGranted = ownSearchRuns(ownerFacts, launch.plane) ? granted.filter((name) => name !== "web_search") : granted;
698
713
  const webNames = webGranted.filter(isWebHostTool);
714
+ // An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
715
+ const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
716
+ const browsing = granted.includes(BROWSER_TOOL) || claimBrowser !== undefined;
699
717
  let learnedTool;
700
718
  let webTools = [];
719
+ let browserTools = [];
701
720
  let life;
702
721
  // The claim's computers' time booked up to now before the run's end or park is written (compute-cost.ts), so the end's
703
722
  // cost holds it: the release that deletes them comes after the end.
@@ -717,7 +736,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
717
736
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
718
737
  const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
719
738
  // None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
720
- const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, shown, sealKey: deps.sealKey, spendOff: await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey), admitAuxiliary } : undefined;
739
+ // A claim on the run's own key runs its learning work on that key (keyed), its check at the run's end (atEnd).
740
+ const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, shown, sealKey: deps.sealKey, spendOff: await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey), keyed: keyedNow(runKey), atEnd: atRunEnd(log), admitAuxiliary } : undefined;
721
741
  // A replay run's or a shadow's grader (runner/compare-end.ts), on a proxy of its own beside the CLI session's, as pi's
722
742
  // is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
723
743
  // None for a held run its model kept from running, whose model runs nowhere.
@@ -728,7 +748,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
728
748
  // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
729
749
  // running takes none of them, as on pi: it settles no audit and starts no replay run, starts on no workflow, and its
730
750
  // tool runs none (so no learned tier is routed, below).
731
- const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, shown, spendOff: audits.spendOff, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: { reason: "held" }, workflows: [] };
751
+ const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, shown, spendOff: audits.spendOff, keyed: audits.keyed, atEnd: audits.atEnd, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: { reason: "held" }, workflows: [] };
732
752
  const firstChoice = learned.choice;
733
753
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
734
754
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -737,7 +757,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
737
757
  // The tool runs what serves, never a revision not promoted (runner/promotion.ts toolFlowsFor).
738
758
  const workflows = learned.workflows;
739
759
  const learns = learnsWorkflows(revision.kind, workflows);
740
- if (webNames.length || learns) {
760
+ if (webNames.length || browsing || learns) {
741
761
  // The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below: its tool and
742
762
  // decision keys alone, since its model keys are not enumerable (claimSecrets), so no spread or spawn of it carries one.
743
763
  const toolEnv = { ...claimed };
@@ -756,12 +776,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
756
776
  delete toolEnv[TOOL_PLANE_ENV];
757
777
  if (launch.plane && Object.keys(launch.plane).length)
758
778
  toolEnv[TOOL_PLANE_ENV] = JSON.stringify(launch.plane);
759
- if (webNames.length) {
779
+ if (webNames.length || browsing) {
760
780
  life ??= hostLifecycle();
761
781
  const liveAt = await claimLiveAt(deps, claim.runId);
762
- const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}), ...(deps.saveSlots ? { saveSlots: deps.saveSlots } : {}) });
782
+ const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}), ...(deps.saveSlots ? { saveSlots: deps.saveSlots } : {}) }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
763
783
  gate.askedOn(host);
764
784
  webTools = await webHostTools(host, webGranted, ctx);
785
+ browserTools = await browserHostTools(host, granted, launch.plane, ctx);
765
786
  }
766
787
  if (learns) {
767
788
  // A tier the learned workflows name that the host has a model of, routed as pi's are (learnedTierRoutes: the run's
@@ -798,9 +819,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
798
819
  system: [environmentLine(now, zone), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line)),
799
820
  // The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
800
821
  // redactor, as pi's do. Listed in the order the agent grants them, as main lists a CLI run's tools.
801
- tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), { results, writes: gate.writes(), opsRefused: gate.opsRefused() }), ...[...webTools, ...(askTool ? [askTool] : []), ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
822
+ tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), { results, writes: gate.writes(), opsRefused: gate.opsRefused() }), ...[...webTools, ...browserTools, ...(askTool ? [askTool] : []), ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
802
823
  context: "fresh",
803
824
  ...(thinking ? { thinking } : {}),
825
+ // The run's model's window, from its catalog: the CLI adapter holds each tool result to its share (and Codex and
826
+ // OpenCode are told it in place of their 272,000 guess).
827
+ ...(window ? { contextWindow: window } : {}),
804
828
  };
805
829
  // A typed input's other fields follow its content as one json block (inputMessage).
806
830
  const input = await firstMessage(inputMessage(launch.input), ws.workspace);
@@ -851,7 +875,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
851
875
  ...(start ? { learningLaid: laidOf(seedLaid) } : {}),
852
876
  ...(workflowFirst ? { workflowFirst } : {}),
853
877
  ...(workflowRevise ? { workflowRevise } : {}),
854
- // The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
878
+ // The tool host's install lifecycle, run by the adapter loop, as the pi spec's: the browser's reconcile, release and
879
+ // drain hang off it (the web tools register none).
855
880
  ...(life ? { lifecycle: life } : {}),
856
881
  agentId: runRow.agentId,
857
882
  // An audit's shadow run waits on no one, as the pi spec's (runner/audit.ts AUDIT_PARKED).
@@ -125,9 +125,12 @@ export interface Held {
125
125
  /** A change of the claim's computer's hold, committed to the run's journal here: signalled on the runner, whose live
126
126
  * view of the computer tells its open viewer (computer-journal.ts heardComputerHold). */
127
127
  computerHold(change: ComputerHoldChange): Promise<void>;
128
- /** The MCP credentials run `from` was handed, sealed again for run `id`, a run this one starts (promotion.ts,
129
- * audit.ts): none unless `from` is the claim's own run. */
130
- handOn(from: string, id: string): Promise<Uint8Array | undefined>;
128
+ /** The MCP credentials run `from` was handed, and its own model key when `keyed` (store/seal.ts sealHandedLaunch),
129
+ * sealed again for run `id`, a run this one starts (promotion.ts, audit.ts): none unless `from` is the claim's own run. */
130
+ handOn(from: string, id: string, keyed: boolean): Promise<Uint8Array | undefined>;
131
+ /** What the replays the claim's own run started on its own key took beside it (learning-work.ts keyedBesideOf), read by
132
+ * the runner: its learning_work row and those replays' rows and launches, none of which the run's process reads. */
133
+ keyedBeside(): Promise<number | null>;
131
134
  /** The run's agent's live sign-in pointer for `resolution`, and its forgotten ones (sign-ins-store.ts signInReads): what
132
135
  * its learning end holds to refuse a pointer in what the run learned. */
133
136
  signInPeek(resolution: string): Promise<unknown>;
@@ -1,5 +1,6 @@
1
1
  import type { Context } from "@earendil-works/chord/context";
2
2
  import type { LearnedWorkflow, Shown } from "../learning.js";
3
+ import type { AtRunEnd } from "../learning-work.js";
3
4
  import type { Recorded } from "../learn/replay-calls.js";
4
5
  import type { RunLaunch } from "../run-launch.js";
5
6
  import type { Store } from "../store/store.js";
@@ -21,6 +22,10 @@ export interface LearnedFirstDeps {
21
22
  readonly log: (line: string) => void;
22
23
  readonly shown: () => Promise<Shown>;
23
24
  readonly spendOff?: (what: string) => string | undefined;
25
+ /** Whether the claim holds its run's own key now, and where it queues what starts at its run's end (promotion.ts
26
+ * startCheck: a check on that key starts there). */
27
+ readonly keyed?: () => boolean;
28
+ readonly atEnd?: AtRunEnd;
24
29
  }
25
30
  /** What the claim starts with: its first choice, the workflows its learned_workflow tool runs, and a replay run's
26
31
  * recorded calls (by learn/replay-calls.ts callKey; none for any other run). Data alone. */
@@ -8,7 +8,7 @@ import { toolStopsOf, workflowFirstOf } from "./workflow-first.js";
8
8
  * claim that is refused throws ClaimRefused, as replayClaimed does. */
9
9
  export async function learnedFirst(deps, laid) {
10
10
  const { store, agentId, runId, revisionId, launch, context, log, shown } = deps;
11
- const own = { ...(deps.sealKey ? { sealKey: deps.sealKey } : {}), ...(deps.spendOff ? { spendOff: deps.spendOff } : {}), ...(deps.admitAuxiliary ? { admitAuxiliary: deps.admitAuxiliary } : {}) };
11
+ const own = { ...(deps.sealKey ? { sealKey: deps.sealKey } : {}), ...(deps.spendOff ? { spendOff: deps.spendOff } : {}), ...(deps.admitAuxiliary ? { admitAuxiliary: deps.admitAuxiliary } : {}), ...(deps.keyed ? { keyed: deps.keyed } : {}), ...(deps.atEnd ? { atEnd: deps.atEnd } : {}) };
12
12
  // A replay run lays only the workflow it replays (promotion.ts replayLaid).
13
13
  const laidFlows = replayLaid(launch, laid);
14
14
  if (launch.learning && !launch.replay && !launch.audit)
@@ -38,10 +38,14 @@ export interface LearningEndDeps {
38
38
  /** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
39
39
  * does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
40
40
  export declare function learningEndOfRun(launch: RunLaunch, deps: LearningEndDeps): EndOfRunTurn | undefined;
41
- /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): its
42
- * audit's shadow run (shadowBesideOf), for a capped run with a learning start, the only run whose end may start one;
43
- * none for any other, whose gates read only its own sessions. */
44
- export declare function spentBesideOf(launch: RunLaunch, store: Pick<Store, "runs">, runId: string): (() => Promise<number | null>) | undefined;
41
+ /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): the
42
+ * learning work it started (childrenBesideOf), for a capped run with a learning start, the only run whose claims may
43
+ * start any; none for any other, whose gates read only its own sessions. */
44
+ export declare function spentBesideOf(launch: RunLaunch, store: Pick<Store, "runs" | "settings">, runId: string): (() => Promise<number | null>) | undefined;
45
+ /** What run `runId`'s learning work took beside it under its cap: its audit's shadow run (shadowBesideOf) and the replay
46
+ * runs of a check on its own key (learning-work.ts keyedBesideOf; in a run's own process, its runner's read of them,
47
+ * Held.keyedBeside, as the process's store reads no other run's row). Null when either is unknown. */
48
+ export declare function childrenBesideOf(store: Pick<Store, "runs" | "settings">, runId: string): Promise<number | null>;
45
49
  /** What run `runId`'s audit's shadow run took beside it (runner/audit.ts, started at its end with what its cap left): at
46
50
  * its cost once it ended, at its own cap while it has not (the most it may take) or when it ended at a cost not known,
47
51
  * 0 when none was started. Null: unknown. */
@@ -49,10 +53,13 @@ export declare function shadowBesideOf(store: Pick<Store, "runs">, runId: string
49
53
  /** What run `runId`'s cap leaves its audit's shadow run at its end (runner/audit.ts startAudit): the cap it is held to now
50
54
  * (capNowOf: its newest raise's, else `launchCapUsd`), less what it spent under it (capSpendOf over `entries`, its
51
55
  * journal: its job, its follow-ups, its compile turns). Null when that spend is unknown. */
52
- export declare function auditRoomOf(store: Pick<Store, "runs">, runId: string, launchCapUsd: number, entries: readonly EntryLike[]): Promise<number | null>;
56
+ export declare function auditRoomOf(store: Pick<Store, "runs" | "settings">, runId: string, launchCapUsd: number, entries: readonly EntryLike[]): Promise<number | null>;
57
+ /** What run `runId`'s cap leaves at its end (auditRoomOf over its journal read now): what a check on its own key shares
58
+ * among its replay runs (runner/promotion.ts keyedCapOf). Null when its spend is unknown. */
59
+ export declare function roomAtEndOf(store: Store, runId: string, launchCapUsd: number): Promise<number | null>;
53
60
  /** What capped run `runId` has spent under its cap, as every gate of the run reads it: its sessions' booking as the kernel
54
- * cap counts it (metrics.ts bookedCapSpend over `entries`, its journal) and what its audit's shadow took beside it
55
- * (shadowBesideOf). Null when either is unknown.
61
+ * cap counts it (metrics.ts bookedCapSpend over `entries`, its journal) and what its learning work took beside it
62
+ * (childrenBesideOf). Null when either is unknown.
56
63
  *
57
64
  * The rule for a cost no one knows (a request answered with no price of its own, one cut short or lost): under a cap it
58
65
  * counts at the figure the cap held it at when it was admitted (its worst case at the model's price, and a lost one's
@@ -61,7 +68,7 @@ export declare function auditRoomOf(store: Pick<Store, "runs">, runId: string, l
61
68
  * unknown (a held figure is the cap's, never a charge). Only a request held at no figure (none is, under a cap) leaves
62
69
  * the spend itself unknown: then nothing more is sent under the cap, and the words say the spend is unknown, as the
63
70
  * kernel's unknownSpend refusal does, never "no room". */
64
- export declare function capSpendOf(store: Pick<Store, "runs">, runId: string, entries: readonly EntryLike[]): Promise<number | null>;
71
+ export declare function capSpendOf(store: Pick<Store, "runs" | "settings">, runId: string, entries: readonly EntryLike[]): Promise<number | null>;
65
72
  /**
66
73
  * A run's merge on the agent's learning, written by the runner directly (learn/commit.ts learningCommit, one save): its
67
74
  * compiled draft's files and its owner's correction, saved by `change.runId`. A file changed since the run's seed (or a
@@ -43,6 +43,7 @@ import { said, seedStopped } from "../learning-words.js";
43
43
  import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
44
44
  import { FINAL_STATES } from "../store/store.js";
45
45
  import { shadowRunId } from "../learn/audit.js";
46
+ import { keyedBesideOf, noteLearningDeadline } from "../learning-work.js";
46
47
  import { getMcpServer } from "../mcp-store.js";
47
48
  import { readApprovers } from "../server-approvers.js";
48
49
  import { isCliRecord, runEntries, runTimeline, withoutFeedbackRounds } from "../store-reads/journal.js";
@@ -109,6 +110,7 @@ export function learningEndOfRun(launch, deps) {
109
110
  ...(start.noWorkflows ? {} : {
110
111
  compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, ...(launch.sdk ? { sdkTask: sdkInputText(launch) } : {}), seedWorkflows: start.workflows?.length ?? 0, corrections: start.section }),
111
112
  compileFailed: (input) => recordDraftFailed(deps, input),
113
+ compileStarts: ({ runId, until }) => noteLearningDeadline(deps.store.settings, runId, until),
112
114
  }),
113
115
  // The run's secrets, what the claim handed it, every secret the server keeps sealed, and the sign-in pointers it was
114
116
  // handed (each at least MIN_SECRET long, as every cut takes them); `unreadable` when those can't be read back, or the
@@ -166,13 +168,22 @@ export function learningEndOfRun(launch, deps) {
166
168
  return hookFor(start.seed, prior ? prior.round + 1 : 1, mustHold)(input);
167
169
  };
168
170
  }
169
- /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): its
170
- * audit's shadow run (shadowBesideOf), for a capped run with a learning start, the only run whose end may start one;
171
- * none for any other, whose gates read only its own sessions. */
171
+ /** What every cap gate of run `runId` reads as spent beside it on its behalf (adapter-loop.ts RunCapConfig.beside): the
172
+ * learning work it started (childrenBesideOf), for a capped run with a learning start, the only run whose claims may
173
+ * start any; none for any other, whose gates read only its own sessions. */
172
174
  export function spentBesideOf(launch, store, runId) {
173
175
  if (launch.maxCostUsd === undefined || !learningStartOf(launch))
174
176
  return undefined;
175
- return () => shadowBesideOf(store, runId);
177
+ return () => childrenBesideOf(store, runId);
178
+ }
179
+ /** What run `runId`'s learning work took beside it under its cap: its audit's shadow run (shadowBesideOf) and the replay
180
+ * runs of a check on its own key (learning-work.ts keyedBesideOf; in a run's own process, its runner's read of them,
181
+ * Held.keyedBeside, as the process's store reads no other run's row). Null when either is unknown. */
182
+ export async function childrenBesideOf(store, runId) {
183
+ const shadow = await shadowBesideOf(store, runId);
184
+ const runner = held();
185
+ const keyed = shadow === null ? null : runner ? await runner.keyedBeside() : await keyedBesideOf(store, runId);
186
+ return shadow === null || keyed === null ? null : shadow + keyed;
176
187
  }
177
188
  /** What run `runId`'s audit's shadow run took beside it (runner/audit.ts, started at its end with what its cap left): at
178
189
  * its cost once it ended, at its own cap while it has not (the most it may take) or when it ended at a cost not known,
@@ -196,9 +207,14 @@ export async function auditRoomOf(store, runId, launchCapUsd, entries) {
196
207
  const spent = await capSpendOf(store, runId, entries);
197
208
  return spent === null ? null : capUsd - spent;
198
209
  }
210
+ /** What run `runId`'s cap leaves at its end (auditRoomOf over its journal read now): what a check on its own key shares
211
+ * among its replay runs (runner/promotion.ts keyedCapOf). Null when its spend is unknown. */
212
+ export async function roomAtEndOf(store, runId, launchCapUsd) {
213
+ return auditRoomOf(store, runId, launchCapUsd, await runEntries(store, runId, BACKGROUND_CONTEXT));
214
+ }
199
215
  /** What capped run `runId` has spent under its cap, as every gate of the run reads it: its sessions' booking as the kernel
200
- * cap counts it (metrics.ts bookedCapSpend over `entries`, its journal) and what its audit's shadow took beside it
201
- * (shadowBesideOf). Null when either is unknown.
216
+ * cap counts it (metrics.ts bookedCapSpend over `entries`, its journal) and what its learning work took beside it
217
+ * (childrenBesideOf). Null when either is unknown.
202
218
  *
203
219
  * The rule for a cost no one knows (a request answered with no price of its own, one cut short or lost): under a cap it
204
220
  * counts at the figure the cap held it at when it was admitted (its worst case at the model's price, and a lost one's
@@ -211,7 +227,7 @@ export async function capSpendOf(store, runId, entries) {
211
227
  const spent = bookedCapSpend(entries);
212
228
  if (spent === null)
213
229
  return null;
214
- const beside = await shadowBesideOf(store, runId);
230
+ const beside = await childrenBesideOf(store, runId);
215
231
  return beside === null ? null : spent + beside;
216
232
  }
217
233
  /**
@@ -174,6 +174,10 @@ export interface LoopDeps {
174
174
  flush(): Promise<void>;
175
175
  /** Aborted on claim loss, self-stop or shutdown: in-flight model and tool calls are cut at once. */
176
176
  signal: AbortSignal;
177
+ /** A learning child's (a check's replay run, an audit's shadow run): aborted at its deadline (runner.ts
178
+ * cancelOverdue), after which its loop sends no model request; the runner's cancel then stops it. Absent for any other
179
+ * run. */
180
+ pastDeadline?: AbortSignal;
177
181
  /** Resolves once the claim's first delivery has handed every untaken row it read to command() (each call returned),
178
182
  * or at once when there were none: a resumed ask with no answer row waits for it before it parks again, so an
179
183
  * approve already on its way is never raced. Never rejects. */
@@ -548,6 +548,8 @@ function said(name, event) {
548
548
  return `Runner ${name} released ${event.runId} (${event.end})`;
549
549
  if (event.type === "started" || event.type === "ended")
550
550
  return runLine(event);
551
+ if (event.type === "learning-deadline")
552
+ return `Runner ${name} cancels ${event.runId}: a learning run at its deadline`;
551
553
  return troubleLine(name, event);
552
554
  }
553
555
  /** The line of a runner's trouble, in its name: a claim it lost, and an error (a renew or a stop that failed), which
@@ -62,6 +62,10 @@ export interface ModelRoute {
62
62
  readonly thinkingLevelMap?: ThinkingLevelMap;
63
63
  readonly translatedChatCompletions?: boolean;
64
64
  };
65
+ /** The model's context window in tokens, from the catalog entry (an Ollama model's, its num_ctx), on every wire: the
66
+ * session's window (SessionSpec.contextWindow), which each tool result is held to its share of. Absent when the
67
+ * catalog names none. */
68
+ readonly contextWindow?: number;
65
69
  /** A request's price from its usage (the proxy's booking reads it): pi-ai's calculateCost, tiers included. */
66
70
  readonly price?: (model: string, usage: RouteUsage) => number | null;
67
71
  /** The upstream fetch: the route's own, for a model that does not speak Messages. Absent: the network. */
@@ -50,7 +50,7 @@ export async function routeOf(model, env = process.env, tier = "default", wires
50
50
  // The settings serve registered for a gateway model, carried on either wire, so pi's session reads the same model whether
51
51
  // it speaks Messages or Responses to the gateway.
52
52
  const settings = { ...sees, ...(target.reasoning !== undefined ? { reasoning: target.reasoning } : {}), ...(target.contextWindow ? { contextWindow: target.contextWindow } : {}), ...(target.maxTokens ? { maxTokens: target.maxTokens } : {}), ...(target.thinkingLevelMap ? { thinkingLevelMap: target.thinkingLevelMap } : {}) };
53
- const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, ...(unpriced.has(chosen.model.modelId) ? { unpriced: true } : {}), outputCeiling: target.maxTokens ?? null, like: sees };
53
+ const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, ...(unpriced.has(chosen.model.modelId) ? { unpriced: true } : {}), outputCeiling: target.maxTokens ?? null, ...(target.contextWindow ? { contextWindow: target.contextWindow } : {}), like: sees };
54
54
  // An Anthropic model speaks Messages itself: the network, at its catalog origin, its key read by name per request.
55
55
  // Its requests name the claim's run, turn and attempt only where that origin is serve's own gateway (gatewayHeadersAt).
56
56
  if (chosen.model.provider === "anthropic") {
@@ -61,6 +61,18 @@ export declare function prCheckoutForClaim(deps: Pick<AdapterSpecDeps, "store" |
61
61
  }, signal?: AbortSignal, held?: (part: {
62
62
  end(): Promise<void>;
63
63
  }) => void, kind?: Checkout): Promise<PrCheckout>;
64
+ /** A claim's checkout on a Mode 2 server whose Archil region `region` has no serverless exec (archil-settings.ts
65
+ * noExecRegionOf), where the disk runs no command (its every exec answers "Exec is not enabled"): made as
66
+ * prCheckoutForClaim makes it, the same script and the token on its stdin, in the run's computer through its own exec,
67
+ * once it has mounted the run's folder (`mounted`: the run's Workspace attached to it, run-tools.ts RunTools.workspace
68
+ * where the run's shell is the computer's). The mount holds the disk's write delegation, and the fetch writes through
69
+ * it. With no computer that mounts the folder, none is made: the run is told why, and `say` puts the fix (a sandbox
70
+ * computer) on its timeline. */
71
+ export declare function checkoutWhereNoExec(deps: Parameters<typeof prCheckoutForClaim>[0], mounted: Workspace | undefined, region: string, launch: Parameters<typeof prCheckoutForClaim>[2], redact: {
72
+ hold(values: readonly string[]): void;
73
+ }, signal: AbortSignal | undefined, held: (part: {
74
+ end(): Promise<void>;
75
+ }) => void, kind: Checkout, say?: (words: string) => void): Promise<PrCheckout>;
64
76
  /** The file in the checkout's .git that lists its files, one path a line (git ls-tree), so an agent with `read` and no
65
77
  * shell can still find what to open. */
66
78
  export declare const FILE_LIST = "agentrun-files";
@@ -2,14 +2,17 @@
2
2
  // definition says `checkout: pull_request` (a template's manifest sets it). The agent then starts with the repository at
3
3
  // the pull request's head in `repo/` of its folder, its base and their merge base fetched beside it, and never holds a
4
4
  // GitHub token: the fetch is the server's own, one exec on the run's Workspace (Mode 1 a process on this machine, Mode 2
5
- // Archil's serverless exec over the run's folder), never a command of the agent's.
5
+ // Archil's serverless exec over the run's folder), never a command of the agent's. On an Archil region with no serverless
6
+ // exec (archil-settings.ts noExecRegionOf) the disk runs no command: the fetch runs in the run's computer, through its
7
+ // own exec, once it has mounted the run's folder (checkoutWhereNoExec), and a run with no such computer has none.
6
8
  //
7
9
  // What it reads of the run: its first message's payload tag alone (github.ts githubPullOf), which the server wrote from a
8
10
  // signed GitHub delivery: the repository, the pull request's number, its head and its base. Nothing else names a
9
11
  // repository to fetch.
10
12
  //
11
13
  // The credential: an installation token of the server's GitHub App, minted for that one repository with
12
- // {contents: "read"} alone, handed to the exec on its stdin (Archil's: a spill file deleted on every path), turned there
14
+ // {contents: "read"} alone, handed to the exec on its stdin (Archil's: a spill file deleted on every path; a computer's:
15
+ // process.write to the process's stdin), turned there
13
16
  // into an Authorization header in git's environment (GIT_CONFIG_COUNT), scoped to GitHub's site. It is never in argv,
14
17
  // .git/config, the remote's URL, the run's folder, an env the agent's commands get, or the log (it joins the run's
15
18
  // redactor). No App, or one not installed on the repository: the fetch is anonymous, which a public repository answers.
@@ -22,6 +25,7 @@
22
25
  // tools can read the change instead. The checkout is removed when the claim lets go (spec-holds.ts), and made again by
23
26
  // the next claim of the same run.
24
27
  import { randomUUID } from "node:crypto";
28
+ import { noExecWords } from "../archil-settings.js";
25
29
  import { GITHUB_WEB, githubPullOf, githubTargetOf } from "../github.js";
26
30
  import { isObject } from "../validate.js";
27
31
  import { COMMAND_MAX_MS } from "../workspace/archil-exec.js";
@@ -178,6 +182,21 @@ export async function prCheckoutForClaim(deps, workspace, launch, redact, signal
178
182
  return repoCheckout({ ...common, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
179
183
  return prCheckout(common);
180
184
  }
185
+ /** A claim's checkout on a Mode 2 server whose Archil region `region` has no serverless exec (archil-settings.ts
186
+ * noExecRegionOf), where the disk runs no command (its every exec answers "Exec is not enabled"): made as
187
+ * prCheckoutForClaim makes it, the same script and the token on its stdin, in the run's computer through its own exec,
188
+ * once it has mounted the run's folder (`mounted`: the run's Workspace attached to it, run-tools.ts RunTools.workspace
189
+ * where the run's shell is the computer's). The mount holds the disk's write delegation, and the fetch writes through
190
+ * it. With no computer that mounts the folder, none is made: the run is told why, and `say` puts the fix (a sandbox
191
+ * computer) on its timeline. */
192
+ export async function checkoutWhereNoExec(deps, mounted, region, launch, redact, signal, held, kind, say) {
193
+ if (mounted)
194
+ return prCheckoutForClaim(deps, mounted, launch, redact, signal, held, kind);
195
+ const why = `${noExecWords(region)}, so the server checks a repository out only in a computer that mounts the run's folder`;
196
+ say?.(`No checkout in repo/: ${why}, and this run has none. Give the agent a sandbox computer (a box) to get its checkout.`);
197
+ const instead = kind === "pull_request" ? "Read the change through the GitHub tools if you have them." : "Read it through the GitHub tools if you have them, else say that you could not read it.";
198
+ return noCheckout(`No checkout was made, so there is no ${CHECKOUT_DIR}/ folder: ${why}, and this run has none. ${instead}`);
199
+ }
181
200
  /** The file in the checkout's .git that lists its files, one path a line (git ls-tree), so an agent with `read` and no
182
201
  * shell can still find what to open. */
183
202
  export const FILE_LIST = "agentrun-files";
@@ -3,6 +3,7 @@ import type { Context } from "@earendil-works/chord/context";
3
3
  import type { LearnedWorkflow } from "../learning.js";
4
4
  import { type RunLaunch } from "../run-launch.js";
5
5
  import { type Store } from "../store/store.js";
6
+ import { type AtRunEnd } from "../learning-work.js";
6
7
  import { type Recorded, type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
7
8
  import { type Json } from "../validate.js";
8
9
  import { type CheckBar, type CheckRecord, type CheckTurns, type Compared, type PromotionRecord, recordPromotion, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
@@ -17,9 +18,15 @@ export declare const REPLAY_LAUNCH_GRACE_MS: number;
17
18
  export interface PromotionDeps {
18
19
  readonly store: Store;
19
20
  readonly admitAuxiliary?: AuxiliaryAdmitter;
20
- /** Why model spend beside the claimed run is skipped (claim-secrets.ts claimSpendOff): a replay check starts runs with
21
- * no caller's key. Absent: it runs. */
21
+ /** Why model spend beside the claimed run is skipped (claim-secrets.ts claimSpendOff). Absent: it runs. */
22
22
  readonly spendOff?: (what: string) => string | undefined;
23
+ /** Whether the claim holds its run's own model key now (claim-secrets.ts keyedNow): its check's replay runs then spend
24
+ * on that key, started at the run's end (`atEnd`) out of what its cap leaves. Absent: never. */
25
+ readonly keyed?: () => boolean;
26
+ /** Where the claim queues what starts at its run's end (learning-work.ts atRunEnd). */
27
+ readonly atEnd?: AtRunEnd;
28
+ /** Set on a check started from `atEnd`: it is not queued again. */
29
+ readonly ending?: true;
23
30
  readonly agentId: string;
24
31
  /** The run being claimed: never one of its own check's inputs. Absent: no run is claimed (a person's replay, and its
25
32
  * read): no run served first to keep, none whose per_run MCP credentials a replay is handed. */