@parcha/agentrun-serve 0.1.0-beta.61 → 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 (228) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +128 -20
  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/api-only.d.ts +4 -0
  7. package/dist/api-only.js +5 -1
  8. package/dist/archil-settings.d.ts +9 -0
  9. package/dist/archil-settings.js +8 -1
  10. package/dist/bash-read-only.d.ts +3 -0
  11. package/dist/bash-read-only.js +6 -3
  12. package/dist/chatgpt-plan.d.ts +33 -8
  13. package/dist/chatgpt-plan.js +141 -24
  14. package/dist/claude-login.d.ts +12 -5
  15. package/dist/claude-login.js +28 -3
  16. package/dist/cli.js +19 -8
  17. package/dist/composio-triggers.d.ts +9 -3
  18. package/dist/computers.d.ts +3 -0
  19. package/dist/computers.js +2 -1
  20. package/dist/console/assets/{backend-C9ffXUR5.js → backend-BxQ2G1M0.js} +2 -2
  21. package/dist/console/assets/index-C8Y5Zl8x.js +639 -0
  22. package/dist/console/assets/share-CjBJ_rxP.js +6 -0
  23. package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
  24. package/dist/console/index.html +3 -3
  25. package/dist/console/share.html +3 -3
  26. package/dist/cut-pool.d.ts +14 -0
  27. package/dist/cut-pool.js +98 -0
  28. package/dist/cut-worker.d.ts +14 -0
  29. package/dist/cut-worker.js +16 -0
  30. package/dist/decisions.d.ts +4 -0
  31. package/dist/decisions.js +9 -1
  32. package/dist/env-switch.d.ts +3 -0
  33. package/dist/env-switch.js +3 -0
  34. package/dist/harness-opencode/adapter.d.ts +3 -1
  35. package/dist/harness-opencode/adapter.js +6 -2
  36. package/dist/harness-opencode/harness.d.ts +4 -0
  37. package/dist/harness-opencode/harness.js +6 -1
  38. package/dist/harness-table.d.ts +7 -0
  39. package/dist/harness-table.js +6 -3
  40. package/dist/host-tools.d.ts +18 -3
  41. package/dist/host-tools.js +27 -4
  42. package/dist/import.d.ts +8 -1
  43. package/dist/import.js +36 -5
  44. package/dist/key-check.js +22 -8
  45. package/dist/learn/ledger.d.ts +37 -16
  46. package/dist/learn/ledger.js +56 -24
  47. package/dist/learn/promote.d.ts +4 -1
  48. package/dist/learned-nodes.d.ts +2 -1
  49. package/dist/learned-nodes.js +2 -1
  50. package/dist/learning-cost.d.ts +5 -3
  51. package/dist/learning-model.js +7 -5
  52. package/dist/learning-work.d.ts +69 -0
  53. package/dist/learning-work.js +148 -0
  54. package/dist/mcp-gateway.d.ts +24 -0
  55. package/dist/mcp-gateway.js +97 -8
  56. package/dist/mcp-servers-store.d.ts +7 -10
  57. package/dist/mcp-servers-store.js +15 -9
  58. package/dist/native/cli.js +5 -1
  59. package/dist/ollama-provider.d.ts +10 -3
  60. package/dist/ollama-provider.js +17 -7
  61. package/dist/openapi.js +51 -20
  62. package/dist/otel/tracer.d.ts +6 -3
  63. package/dist/otel/tracer.js +24 -6
  64. package/dist/page.d.ts +7 -0
  65. package/dist/page.js +17 -4
  66. package/dist/place.d.ts +25 -9
  67. package/dist/place.js +37 -11
  68. package/dist/print.d.ts +3 -2
  69. package/dist/print.js +8 -6
  70. package/dist/run-export.js +7 -4
  71. package/dist/run-launch.d.ts +6 -1
  72. package/dist/run-launch.js +26 -6
  73. package/dist/run-model-key.d.ts +2 -1
  74. package/dist/run-model-key.js +2 -1
  75. package/dist/run-reads-over-store.d.ts +7 -0
  76. package/dist/run-reads-over-store.js +32 -4
  77. package/dist/run-view.js +9 -3
  78. package/dist/runnable.d.ts +6 -3
  79. package/dist/runnable.js +21 -11
  80. package/dist/runner/adapter-loop.js +95 -28
  81. package/dist/runner/adapter-run-spec.d.ts +20 -4
  82. package/dist/runner/adapter-run-spec.js +64 -30
  83. package/dist/runner/adapters/index.d.ts +6 -0
  84. package/dist/runner/adapters/index.js +5 -1
  85. package/dist/runner/adapters/pi.d.ts +42 -3
  86. package/dist/runner/adapters/pi.js +114 -13
  87. package/dist/runner/audit.d.ts +8 -2
  88. package/dist/runner/audit.js +34 -18
  89. package/dist/runner/book-cut.d.ts +6 -0
  90. package/dist/runner/book-cut.js +38 -0
  91. package/dist/runner/claim-secrets.d.ts +12 -5
  92. package/dist/runner/claim-secrets.js +28 -12
  93. package/dist/runner/cli-run-spec.d.ts +0 -2
  94. package/dist/runner/cli-run-spec.js +54 -25
  95. package/dist/runner/dispatch.js +2 -0
  96. package/dist/runner/harness-loops.d.ts +5 -0
  97. package/dist/runner/harness-loops.js +4 -1
  98. package/dist/runner/held.d.ts +6 -3
  99. package/dist/runner/learned-first.d.ts +5 -0
  100. package/dist/runner/learned-first.js +1 -1
  101. package/dist/runner/learning-end.d.ts +15 -8
  102. package/dist/runner/learning-end.js +23 -7
  103. package/dist/runner/live-ticker.js +3 -1
  104. package/dist/runner/loop-contract.d.ts +8 -1
  105. package/dist/runner/main.js +2 -0
  106. package/dist/runner/mcp-run.d.ts +5 -0
  107. package/dist/runner/mcp-run.js +18 -0
  108. package/dist/runner/meta-tools.js +4 -4
  109. package/dist/runner/metrics.d.ts +4 -2
  110. package/dist/runner/metrics.js +5 -3
  111. package/dist/runner/model-route.d.ts +4 -0
  112. package/dist/runner/model-route.js +1 -1
  113. package/dist/runner/native-loop.js +2 -2
  114. package/dist/runner/pr-checkout.d.ts +12 -0
  115. package/dist/runner/pr-checkout.js +21 -2
  116. package/dist/runner/promotion.d.ts +9 -2
  117. package/dist/runner/promotion.js +79 -28
  118. package/dist/runner/reflect-hook.d.ts +7 -0
  119. package/dist/runner/reflect-hook.js +2 -1
  120. package/dist/runner/run-child-host.d.ts +10 -6
  121. package/dist/runner/run-child-host.js +65 -41
  122. package/dist/runner/run-child.js +2 -0
  123. package/dist/runner/runner.d.ts +9 -0
  124. package/dist/runner/runner.js +158 -25
  125. package/dist/runner/store-port.d.ts +4 -1
  126. package/dist/runner/workflow-calls.d.ts +4 -3
  127. package/dist/runner/workflow-calls.js +41 -12
  128. package/dist/runner/workflow-first.js +4 -3
  129. package/dist/runner/workflow-loop.js +13 -1
  130. package/dist/runner/workflow-spec.js +1 -1
  131. package/dist/secret-cut.d.ts +4 -0
  132. package/dist/secret-cut.js +1 -1
  133. package/dist/secret-rules.d.ts +2 -1
  134. package/dist/secret-rules.js +88 -24
  135. package/dist/server.d.ts +10 -1
  136. package/dist/server.js +131 -44
  137. package/dist/share-host.d.ts +111 -0
  138. package/dist/share-host.js +669 -0
  139. package/dist/store/schema.d.ts +4 -3
  140. package/dist/store/schema.js +4 -3
  141. package/dist/store/seal.d.ts +8 -2
  142. package/dist/store/seal.js +13 -2
  143. package/dist/store/sqlite/learning-rows.js +2 -1
  144. package/dist/store/sqlite/run-patch.js +4 -4
  145. package/dist/store/sqlite/store.js +28 -4
  146. package/dist/store/store.d.ts +5 -0
  147. package/dist/store-reads/analytics.d.ts +15 -0
  148. package/dist/store-reads/analytics.js +17 -0
  149. package/dist/store-reads/journal.d.ts +2 -0
  150. package/dist/store-reads/journal.js +1 -1
  151. package/dist/store-reads/learning.d.ts +4 -3
  152. package/dist/store-reads/learning.js +62 -18
  153. package/dist/store-view.d.ts +3 -0
  154. package/dist/store-view.js +18 -1
  155. package/dist/suggestions.js +32 -3
  156. package/dist/templates.d.ts +3 -1
  157. package/dist/templates.js +7 -3
  158. package/dist/tool-gate.d.ts +25 -9
  159. package/dist/tool-gate.js +58 -19
  160. package/dist/tool-list.d.ts +4 -0
  161. package/dist/tool-list.js +4 -0
  162. package/dist/tool-plane.d.ts +1 -0
  163. package/dist/tool-plane.js +6 -2
  164. package/dist/tools.js +2 -2
  165. package/dist/trigger-composio.js +1 -1
  166. package/dist/webhooks.d.ts +3 -0
  167. package/dist/webhooks.js +5 -0
  168. package/dist/workspace/archil-claim.d.ts +7 -3
  169. package/dist/workspace/archil-claim.js +13 -5
  170. package/dist/workspace/archil-mount-credential.d.ts +6 -0
  171. package/dist/workspace/archil-mount-credential.js +11 -0
  172. package/dist/workspace/attach.js +22 -5
  173. package/dist/workspace/computer-deps.d.ts +5 -3
  174. package/dist/workspace/computer-deps.js +11 -9
  175. package/dist/workspace/computer-for-claim.d.ts +6 -2
  176. package/dist/workspace/computer-for-claim.js +43 -12
  177. package/dist/workspace/computer-janitor.d.ts +7 -4
  178. package/dist/workspace/computer-janitor.js +7 -4
  179. package/dist/workspace/computer-kept.d.ts +7 -1
  180. package/dist/workspace/computer-kept.js +7 -1
  181. package/dist/workspace/kind-skills/desktop/SKILL.md +17 -4
  182. package/dist/workspace/mount-revoke-left.d.ts +16 -4
  183. package/dist/workspace/mount-revoke-left.js +42 -22
  184. package/dist/workspace/resolve-computer.d.ts +11 -5
  185. package/dist/workspace/resolve-computer.js +22 -13
  186. package/dist/workspace/run-end-computers.js +1 -1
  187. package/dist/workspace/run-tools.d.ts +10 -3
  188. package/dist/workspace/run-tools.js +5 -4
  189. package/dist/wrapped.d.ts +29 -2
  190. package/dist/wrapped.js +20 -3
  191. package/launcher/agentrun-serve +1 -1
  192. package/package.json +12 -12
  193. package/templates/kyb/agent.md +7 -1
  194. package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
  195. package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
  196. package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
  197. package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
  198. package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
  199. package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
  200. package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
  201. package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
  202. package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
  203. package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
  204. package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
  205. package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
  206. package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
  207. package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
  208. package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
  209. package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
  210. package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
  211. package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
  212. package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
  213. package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
  214. package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
  215. package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
  216. package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
  217. package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
  218. package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
  219. package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
  220. package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
  221. package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
  222. package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
  223. package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
  224. package/templates/kyb/kyb.schema.json +2 -2
  225. package/templates/kyb/rules/SANCTIONS.md +82 -13
  226. package/dist/console/assets/index-BnZV3lvW.js +0 -639
  227. package/dist/console/assets/share-B1o5mJ56.js +0 -6
  228. /package/dist/console/assets/{styles-D_znYrHR.js → styles-BGZxYkky.js} +0 -0
@@ -46,19 +46,20 @@ import { withoutKindSkill } from "../workspace/kind-skills.js";
46
46
  import { layOwnSkills } from "../workspace/revision-skills.js";
47
47
  import { runTools, withKindTools } from "../workspace/run-tools.js";
48
48
  import { archilWhereHeld, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
49
- import { loadArchilSettings } from "../archil-settings.js";
49
+ import { loadArchilSettings, noExecRegionOf } from "../archil-settings.js";
50
50
  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. */
@@ -380,6 +387,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
380
387
  // this claim's memory only, dropped at the release); else Mode 1, the run's local folder.
381
388
  const archilSettings = await loadArchilSettings(deps.store, deps.env);
382
389
  const mode = archilSettings === undefined ? 1 : 2;
390
+ // Its region with no serverless exec, where it has none: a run with no computer that mounts its folder has no shell.
391
+ const noExec = noExecRegionOf(archilSettings);
383
392
  const archil = archilSettings === undefined
384
393
  ? undefined
385
394
  // The run's mount credential, minted per run (account key from the server's environment first, then the sealed row),
@@ -416,11 +425,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
416
425
  let filedIn;
417
426
  const hold = (values) => { for (const redact of [run.redact, cut])
418
427
  redact.hold(values); };
419
- 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, 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) });
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) });
420
429
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
421
430
  holds.hold({ passed: mcp });
422
- // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
423
- 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;
424
434
  holds.hold({ checkout });
425
435
  // A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
426
436
  if (!(deps.sealKey === undefined && runnerSeam()))
@@ -453,14 +463,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
453
463
  // revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
454
464
  // run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does, with
455
465
  // what became of the agent's own computer said on the run's timeline.
456
- // A browser computer is driven by the browser tool, which runs on pi's native route alone: a CLI's run of an agent
457
- // 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.
458
467
  // A person's stop ends the claim's waits at once: a first image pull or registration (Agent37's runs minutes) among them.
459
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
460
469
  // spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount); a park's
461
470
  // row names the disk that credential is on (mountDisk). Its screen's recording (computer.record) goes in the run's
462
471
  // recordings folder, as the pi spec's does.
463
- { ...deps.computerDeps, mode, 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) } : {}) });
464
473
  holds.hold({ computer });
465
474
  const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
466
475
  const heldComputer = heldSpecOf(launch, loopComputer);
@@ -485,10 +494,15 @@ async function cliSpec(launch, run, deps, claim, holds) {
485
494
  // Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv), as the pi spec does.
486
495
  const bashPolicy = bashPolicyOf(body.toolSettings);
487
496
  // A computer that replaced an earlier claim's holds its acts to what it showed, as the pi spec's does.
488
- const tools = await runTools(ws.workspace, computer.computer, { mode, context, aliases: [scratch], ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
497
+ const tools = await runTools(ws.workspace, computer.computer, { mode, noExec, context, aliases: [scratch], ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
489
498
  filedIn = tools.workspace;
490
499
  let remoteProjectCapture = false;
491
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
+ }
492
506
  const root = runFolder(deps.data, runRow.agentId, claim.runId);
493
507
  // The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
494
508
  // learned laid in (learning.ts laidLearned, from the launch's learning start, so the runner reads no learning rows), its
@@ -522,7 +536,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
522
536
  if (runKey)
523
537
  holdRunKey(redact, runKey);
524
538
  }
525
- const login = await runLoginOf(deps, keyed, name, launch.place, hold);
539
+ // A held run its model kept from running asks for no login, here or of its runner: its agent never starts.
540
+ const login = heldRefusal !== undefined ? undefined : await runLoginOf(deps, keyed, name, launch.place, hold);
526
541
  const env = withClaudeLogin(cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey, claim), login);
527
542
  // A plan-billed recipe's keys saved for its harness alone (harness-keys.ts), opened at each claim for this run's harness
528
543
  // and no other (a run's own process asks its runner, which opens its claim's own: held.ts harnessKeys), held by the
@@ -562,6 +577,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
562
577
  // no key saved for its harness, above) and takes no learning step (below), so it holds the computer on a host with no
563
578
  // key for its model, and a key saved since runs a new run, never this one.
564
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;
565
582
  if (heldRefusal === undefined) {
566
583
  await planBeforeRun(env, chosen.model);
567
584
  if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
@@ -678,8 +695,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
678
695
  // session's proxied models (learnedWorkflowHostTool), each node a request on the run's one route labelled
679
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
680
697
  // scoped keys (claim-secrets.ts), the run's plane threaded for the web tools. Each call goes through the run's gate
681
- // (spec.gate), and a web tool books its paid requests on the run's one ledger itself (bookedIn). The browser is pi's
682
- // 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.
683
701
  const results = new Map();
684
702
  const ctx = hostToolCtxOf(run, context, results, root);
685
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
@@ -693,8 +711,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
693
711
  // live search) is not handed the host's web_search beside it.
694
712
  const webGranted = ownSearchRuns(ownerFacts, launch.plane) ? granted.filter((name) => name !== "web_search") : granted;
695
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;
696
717
  let learnedTool;
697
718
  let webTools = [];
719
+ let browserTools = [];
698
720
  let life;
699
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
700
722
  // cost holds it: the release that deletes them comes after the end.
@@ -714,7 +736,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
714
736
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
715
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 } : {}) } });
716
738
  // None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
717
- 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;
718
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
719
742
  // is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
720
743
  // None for a held run its model kept from running, whose model runs nowhere.
@@ -725,7 +748,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
725
748
  // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
726
749
  // running takes none of them, as on pi: it settles no audit and starts no replay run, starts on no workflow, and its
727
750
  // tool runs none (so no learned tier is routed, below).
728
- 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: [] };
729
752
  const firstChoice = learned.choice;
730
753
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
731
754
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -734,7 +757,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
734
757
  // The tool runs what serves, never a revision not promoted (runner/promotion.ts toolFlowsFor).
735
758
  const workflows = learned.workflows;
736
759
  const learns = learnsWorkflows(revision.kind, workflows);
737
- if (webNames.length || learns) {
760
+ if (webNames.length || browsing || learns) {
738
761
  // The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below: its tool and
739
762
  // decision keys alone, since its model keys are not enumerable (claimSecrets), so no spread or spawn of it carries one.
740
763
  const toolEnv = { ...claimed };
@@ -753,12 +776,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
753
776
  delete toolEnv[TOOL_PLANE_ENV];
754
777
  if (launch.plane && Object.keys(launch.plane).length)
755
778
  toolEnv[TOOL_PLANE_ENV] = JSON.stringify(launch.plane);
756
- if (webNames.length) {
779
+ if (webNames.length || browsing) {
757
780
  life ??= hostLifecycle();
758
781
  const liveAt = await claimLiveAt(deps, claim.runId);
759
- 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 } : {}) };
760
783
  gate.askedOn(host);
761
784
  webTools = await webHostTools(host, webGranted, ctx);
785
+ browserTools = await browserHostTools(host, granted, launch.plane, ctx);
762
786
  }
763
787
  if (learns) {
764
788
  // A tier the learned workflows name that the host has a model of, routed as pi's are (learnedTierRoutes: the run's
@@ -795,9 +819,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
795
819
  system: [environmentLine(now, zone), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line)),
796
820
  // The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
797
821
  // redactor, as pi's do. Listed in the order the agent grants them, as main lists a CLI run's tools.
798
- tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), { results, writes: gate.writes() }), ...[...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),
799
823
  context: "fresh",
800
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 } : {}),
801
828
  };
802
829
  // A typed input's other fields follow its content as one json block (inputMessage).
803
830
  const input = await firstMessage(inputMessage(launch.input), ws.workspace);
@@ -848,7 +875,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
848
875
  ...(start ? { learningLaid: laidOf(seedLaid) } : {}),
849
876
  ...(workflowFirst ? { workflowFirst } : {}),
850
877
  ...(workflowRevise ? { workflowRevise } : {}),
851
- // 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).
852
880
  ...(life ? { lifecycle: life } : {}),
853
881
  agentId: runRow.agentId,
854
882
  // An audit's shadow run waits on no one, as the pi spec's (runner/audit.ts AUDIT_PARKED).
@@ -857,8 +885,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
857
885
  ...(personOnly ? { personOnly } : {}),
858
886
  // The run's computer and the person's hold on a desktop or phone, as the claim made them (as the pi spec gives them).
859
887
  ...(loopComputer ? { computer: loopComputer } : {}),
860
- // A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.
861
- ...(tools.computer ? { scriptComputer: tools.computer } : {}),
888
+ // A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools, its
889
+ // declarations without the ops the gate refuses whatever their arguments.
890
+ ...(tools.computer ? { scriptComputer: { ...tools.computer, opsRefused: gate.opsRefused() } } : {}),
862
891
  // A computer that replaced an earlier claim's: the model is told once, on its next request (the loop's computer note).
863
892
  ...(computer.replaced ? { computerNote: computerReplacedNote(computer.replaced) } : {}),
864
893
  // A desktop or a phone that holds none of the run's files: the model is told once in the run where they are, or, where
@@ -9,6 +9,7 @@
9
9
  // be read, fails the run in words (the dispatch's start() throws, which the runner records as the run failing).
10
10
  import { harnessOfBody } from "../harness.js";
11
11
  import { launchOnItsDisk, readLaunchBody } from "../run-launch.js";
12
+ import { mustHold } from "./redact.js";
12
13
  /** A launch naming a harness this runner does not run. */
13
14
  export class UnknownHarness extends Error {
14
15
  harness;
@@ -39,6 +40,7 @@ export function createDispatchLoop(deps) {
39
40
  return (loopDeps) => dispatchLoop(deps, loopDeps);
40
41
  }
41
42
  function dispatchLoop(deps, loopDeps) {
43
+ mustHold(loopDeps.redact, "A dispatch loop");
42
44
  /** The harness's loop, once the launch read has chosen it. */
43
45
  let inner;
44
46
  /** Commands handed over before the inner loop was chosen: replayed through it once it is. */
@@ -30,6 +30,11 @@ export declare function refuseRecipeTriggerRun(deps: {
30
30
  export declare function resolveRunnerLoop(given: AdapterSpecDeps, options?: {
31
31
  readonly keysCounted?: boolean;
32
32
  }): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
33
+ /** `made` with the saved gateway's key, as this claim read it, held by the run's one redactor before the loop starts: the
34
+ * key stays off the claim's tool keys (claimSecrets), and a later scan of the store (holdStored) would find only a key
35
+ * saved since, so a gateway reply that echoes this one is cut in the run's records and logs all the same. `made` itself
36
+ * where the gateway is not the saved one. */
37
+ export declare function holdingGatewayKey(made: LoopFactory, env: NodeJS.ProcessEnv | undefined): LoopFactory;
33
38
  /** `launch` as this claim runs it: its plane, resolved at the run's start, under the server's tool settings now
34
39
  * (tool-plane.ts claimPlane), so a resume, a follow-up or a reclaim after the server set web_fetch to kernel, or
35
40
  * web_search to native or off, sends nothing past that setting, whatever its agent picked. Settings that could not be
@@ -73,7 +73,7 @@ export function resolveRunnerLoop(given, options = {}) {
73
73
  * key stays off the claim's tool keys (claimSecrets), and a later scan of the store (holdStored) would find only a key
74
74
  * saved since, so a gateway reply that echoes this one is cut in the run's records and logs all the same. `made` itself
75
75
  * where the gateway is not the saved one. */
76
- function holdingGatewayKey(made, env) {
76
+ export function holdingGatewayKey(made, env) {
77
77
  const key = env && savedGatewayIn(env) ? env[GATEWAY_KEY_ENV] : undefined;
78
78
  if (!key)
79
79
  return made;
@@ -92,6 +92,9 @@ function holdingGatewayKey(made, env) {
92
92
  export async function underServerCeilings(deps, launch, revision) {
93
93
  if (!launch.plane)
94
94
  return launch;
95
+ // A run's own process takes the plane its runner capped, the one its keys were chosen by (AdapterSpecDeps.claimedPlane).
96
+ if (deps.claimedPlane)
97
+ return { ...launch, plane: deps.claimedPlane };
95
98
  const { settings, unreadable } = await storeSettings(deps.store);
96
99
  const unread = unreadable === true;
97
100
  const tooling = await toolingOf(revision);
@@ -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
  /**
@@ -1,4 +1,5 @@
1
1
  import { redactedAnswer, redactedLive, redactedOutputWhole } from "../key-refusal.js";
2
+ import { mustHold } from "./redact.js";
2
3
  /** A run's held state as the live view keeps it, under `values`, every secret value the run's one redactor holds. A
3
4
  * running tool's id and name are cut whole (redactedAnswer). Its args by a workflow output's rule (redactedOutputWhole):
4
5
  * read whole first, so a held value split across two of its fields withholds them as "[redacted]", as a call's arguments
@@ -54,6 +55,7 @@ export function withLiveTicker(store, createLoop, options = {}) {
54
55
  timer.unref?.();
55
56
  return {
56
57
  createLoop: (deps) => {
58
+ const redact = mustHold(deps.redact, "A loop the live ticker wraps");
57
59
  let claim;
58
60
  // The claim's signal aborts when its claim is lost (or the runner shuts down past its drain): from then the loop's
59
61
  // held state is neither taken nor written, though the loop still reports while it stops. The store fences a write
@@ -67,7 +69,7 @@ export function withLiveTicker(store, createLoop, options = {}) {
67
69
  // The run's one redactor: a running tool's args and output and a partial answer can quote a secret the runner holds
68
70
  // (a key its claim opened), and the live view is read by people and consoles. A loop whose redactor does not know its
69
71
  // values has no live view: a value still streaming, a number or an object's names cannot be cut by text alone.
70
- const values = deps.redact.heldValues;
72
+ const values = redact.heldValues;
71
73
  const loop = createLoop({
72
74
  ...deps,
73
75
  live: (read) => {
@@ -96,10 +96,13 @@ export type LoopEnd = {
96
96
  };
97
97
  }
98
98
  /** Parked on a person (an approval, a raise): the runner flushes and releases; a command row (or `wakeAt`, ms since
99
- * the epoch) makes the run claimable again, and the next claim's start() resumes it from the journal. */
99
+ * the epoch) makes the run claimable again, and the next claim's start() resumes it from the journal. `again`: parked
100
+ * where it stood with nothing written (a run woken at its cap by raises that were all refused), so the release itself
101
+ * parks the row again; else the loop's last commit parked it. */
100
102
  | {
101
103
  readonly state: "parked";
102
104
  readonly wakeAt?: number;
105
+ readonly again?: true;
103
106
  };
104
107
  export type StopReason =
105
108
  /** A stop or cancel row: the loop stages that row's take in the commit that ends the run as stopped (`cancel`: a cancel
@@ -171,6 +174,10 @@ export interface LoopDeps {
171
174
  flush(): Promise<void>;
172
175
  /** Aborted on claim loss, self-stop or shutdown: in-flight model and tool calls are cut at once. */
173
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;
174
181
  /** Resolves once the claim's first delivery has handed every untaken row it read to command() (each call returned),
175
182
  * or at once when there were none: a resumed ask with no answer row waits for it before it parks again, so an
176
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
@@ -1,3 +1,4 @@
1
+ import { type HeldRedact } from "./redact.js";
1
2
  import type { HostTool } from "@parcha/agentrun-kernel";
2
3
  import type { Harness } from "@earendil-works/pi-durable";
3
4
  import { type McpGatewayOptions } from "../mcp-gateway.js";
@@ -73,6 +74,10 @@ export interface McpForClaimOptions {
73
74
  };
74
75
  /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
75
76
  readonly hold?: (values: string[]) => void;
77
+ /** The run's redactor, after each call's own scrub on every text its gateway answers or files (mcp-gateway.ts
78
+ * McpGatewayOptions.redact). Required, and one that holds keys (heldRedactor): a claim's MCP given none throws before
79
+ * it opens or mints anything, and never answers past the run's redactor. */
80
+ readonly redact: HeldRedact;
76
81
  /** The run's revision's own tool settings (body.toolSettings), where a tool's file setting is read (filed-tool.ts
77
82
  * filedBy): each answer of such a tool is filed whole in the run's files and the tool's result is its summary. A run's
78
83
  * own process passes none: its runner reads them from the revision it reads itself (run-child-host.ts). */
@@ -1,3 +1,19 @@
1
+ // A claimed run's remote MCP servers on the runner (tl-mcp's note, sections 4 to 6). A spec builder calls mcpForClaim once
2
+ // per claim, inside the adapter loop's spec step: after the loop's Gate and Harness are open, before its session. It runs
3
+ // the claim step (mcp-claim.ts: the pin its revision's save made, read and checked against the meta tools known now, the
4
+ // pinned servers' credentials opened into this claim's memory) and builds ONE gateway (mcp-gateway.ts) for the
5
+ // claim, never shared with another, reading those credentials live. The builder puts what it returns in its spec
6
+ // (AdapterRunSpec.mcp); the loop does the rest:
7
+ // - one host tool per pinned tool (`tools`), under its wire name with the pinned description and schema, for every
8
+ // harness: the loop hands them to the session as it hands every host tool (pi's registry, the CLIs' own channel for
9
+ // host tools), on its path for every host tool: the gate before the intent (allow, ask and park, deny), the flush, the
10
+ // record, the run's one ledger for a priced call.
11
+ // - a command row handed to the running loop makes the credentials fresh again (`fresh`, on the same pin) before its
12
+ // next model request; the loop calls `release` when its pass ends, the claim is lost or its signal aborts.
13
+ // The gateway holds no gate here (the loop's is the run's one gate) and keeps the rest as it is: the meta refusal, the
14
+ // unopened refusal, the URL check per call, the scrub of each call's credentials held only while that call is out, prices
15
+ // on the run's one ledger and the not-metered booking on the run's root.
16
+ import { mustHold } from "./redact.js";
1
17
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
18
  import { wireName } from "../catalog.js";
3
19
  import { mcpGateway } from "../mcp-gateway.js";
@@ -31,6 +47,7 @@ export function catalogSessionNames(catalog, grant) {
31
47
  * claim lost while a refresh was awaited: the loop ends interrupted). A builder calls it before it takes anything it
32
48
  * would have to let go, since a throw here leaves its spec unbuilt and its release uncalled. */
33
49
  export async function mcpForClaim(options) {
50
+ const redact = mustHold(options.redact, "A claim's MCP");
34
51
  // The step's own signal: aborted by release(), which the loop calls when its pass ends, the claim is lost or its
35
52
  // signal aborts.
36
53
  const held = new AbortController();
@@ -90,6 +107,7 @@ export async function mcpForClaim(options) {
90
107
  ...(options.callBounds ? { bounds: options.callBounds } : {}),
91
108
  capped: options.capped !== false,
92
109
  ...(options.toolSettings !== undefined ? { filed: filedBy(options.toolSettings) } : {}),
110
+ redact,
93
111
  ...(media ? { media: publicMedia(async () => (media.web ? fakeSaveOptions(media.web) : fetchOptions(media.env, FAUX_ENV)), media.slots) } : {}),
94
112
  });
95
113
  const catalog = new Map();
@@ -20,7 +20,7 @@
20
20
  import { randomBytes } from "node:crypto";
21
21
  import { CodemodeSandbox, toCodemodeIdentifier } from "@earendil-works/pi-codemode";
22
22
  import { computerOver, withoutImageData } from "@parcha/agentrun-computer/surface";
23
- import { COMPUTER_OP_TOOL, computerDeclarations, STEP_TOOL_OPS } from "@parcha/agentrun-kernel/kernel";
23
+ import { COMPUTER_OP_TOOL, computerDeclarations, GUI_REACH, STEP_TOOL_OPS } from "@parcha/agentrun-kernel/kernel";
24
24
  import { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH } from "../meta-tool-names.js";
25
25
  import { NO_PROGRAMS_WORDS } from "../workspace/computer-ports.js";
26
26
  export { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH };
@@ -83,11 +83,11 @@ function scriptComputer(computer, tools) {
83
83
  return `new Proxy(${bound}, { get(target, key, receiver) { if (key === "shell" || key === "processes") throw new Error(${JSON.stringify(NO_PROGRAMS_WORDS)}); return Reflect.get(target, key, receiver); } })`;
84
84
  }
85
85
  /** What codemode's description adds for a run with a computer: the script's `computer`, and the declarations of what its
86
- * card offers. */
86
+ * card offers, less the ops the run's gate refuses whatever their arguments (opsRefused). */
87
87
  function computerWords(computer) {
88
88
  return [
89
- `The script has this run's computer as \`computer\`, typed by the declarations below. Each of its calls is a call of the run's own computer tools, asked about and recorded as that tool's: a command it runs is held to bash's setting, a file it writes to write's, a file it reads, lists or stats to read's.`,
90
- computerDeclarations(computer.card.groups),
89
+ `The script has this run's computer as \`computer\`, typed by the declarations below. Each of its calls is a call of the run's own computer tools, asked about and recorded as that tool's: a command it runs is held to bash's setting; a file it writes needs write among this agent's tools, and a file it reads, lists or stats needs read among this agent's tools, each then held to that tool's setting. ${GUI_REACH}`,
90
+ computerDeclarations(computer.card.groups, computer.opsRefused),
91
91
  ].join("\n");
92
92
  }
93
93
  /** The three tools for a session: each `nests` (but the search, which calls nothing). */