@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
@@ -91,6 +91,8 @@ function cardOf(tool, shown, args) {
91
91
  const COMMAND_REQUEST_PREFIX = commandRequest(0).replace(/0$/, "");
92
92
  /** What a CLI's request held at a cut turn (TurnCut) is refused with: the turn ended at the person's question. */
93
93
  const TURN_CUT_AT_QUESTION = "the turn ended at its question to the person";
94
+ /** What a learning child's request after its deadline (LoopDeps.pastDeadline) is refused with, once its cancel stopped it. */
95
+ const PAST_LEARNING_DEADLINE = "this learning run reached its deadline: nothing more is sent";
94
96
  /** What a run that waits on no one (AdapterRunSpec.neverWaits) would have waited on, by its park's cause: its end says so. */
95
97
  const WAITS_ON = {
96
98
  approval: "a person's approval of a tool call",
@@ -359,8 +361,12 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
359
361
  let text = "";
360
362
  /** A model message was written at a request's start (flushSaid) and no other flush has come since. */
361
363
  let flushedAtRequest = false;
362
- /** The end-of-run turn's answer while that turn runs (answering), else undefined. */
364
+ /** The end-of-run turn's answer while that turn runs (answering), else undefined: its last message, as pi's answer is,
365
+ * the text since the turn's last message boundary. */
363
366
  let answer;
367
+ /** A message boundary (text_end, a call) came in the end-of-run turn: its next text starts the answer anew. A partial
368
+ * stream the CLI asked again for whole is never read with the whole answer after it. */
369
+ let answerCut = false;
364
370
  // One write at a time, in the order they were asked for, a failed one never stopping the next.
365
371
  let chain = Promise.resolve();
366
372
  const inTurn = (work) => (chain = chain.then(work, work));
@@ -387,11 +393,18 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
387
393
  if (event.type === "text") {
388
394
  if (answer === undefined)
389
395
  text += event.delta;
390
- else
396
+ else {
397
+ if (answerCut)
398
+ answer = "";
399
+ answerCut = false;
391
400
  answer += event.delta;
401
+ }
392
402
  }
393
- else if (event.type === "tool_start" || event.type === "text_end")
403
+ else if (event.type === "tool_start" || event.type === "text_end") {
404
+ if (answer !== undefined)
405
+ answerCut = true;
394
406
  void flushText().catch(() => undefined);
407
+ }
395
408
  else if (event.type === "turn_end")
396
409
  void flushText(event).catch(() => undefined);
397
410
  else if (event.type === "notice") {
@@ -535,6 +548,7 @@ async function openCliRecord(harness, journal, context, now, cwd, endsItsCalls =
535
548
  }),
536
549
  answering: async (requestId, prompt, keep) => {
537
550
  answer = "";
551
+ answerCut = false;
538
552
  await inTurn(async () => {
539
553
  if (askedAt.has(requestId))
540
554
  return;
@@ -700,8 +714,9 @@ function adapterLoop(specOf, options, deps) {
700
714
  * The agent is asked no turn of the job's: the run goes to its end-of-run turn, told the grade first (feedbackAsk). */
701
715
  let feedbackNow;
702
716
  /** A reopen of a run whose session is still new (a person stopped it before its first input was sent): resolved once the
703
- * person's message is placed as that first input. The claim waits on it, never sending the input they stopped, however
704
- * late the runner hands the message over. */
717
+ * person's message is placed as that first input, or once the reopen's own message was answered unplaced (command):
718
+ * then no message places it, and the claim ends the run on the end it had before, sending nothing. The claim waits on
719
+ * it, never sending the input they stopped, however late the runner hands the message over. */
705
720
  let firstInputPlaced;
706
721
  /** Resolved once a pass of this claim has sent what its session starts on (the run's input, a follow-up, a recovery),
707
722
  * or found nothing to send: a message handed over while the session is still new waits for it, so it lands after the
@@ -1079,12 +1094,19 @@ function adapterLoop(specOf, options, deps) {
1079
1094
  // the run's next turn, on a claim that lists them: the run's end opens it again with the message (as for a message
1080
1095
  // that comes while the run ends), and a park's resume takes it. Every message after it waits the same way, whatever
1081
1096
  // the credentials say at its own check (a later message may hand them no longer), so none runs before it. Said once
1082
- // on the timeline, since the API answered the message as steered.
1097
+ // on the timeline, since the API answered the message as steered. A reopen's own message (the claim's turn, not yet
1098
+ // sent; never a wait's answer) came before the claim opened, so whatever it handed, the claim opened with: a
1099
+ // credential handed since is a later message's, and this one is still the claim's turn. Held, a reopen of a session
1100
+ // still new would wait for a first input that never comes. It is the first message to reach here while the reopen
1101
+ // is unsent (`by`): one after it, though that message was refused or left, is no reopen's and is checked.
1083
1102
  if (leftForNextTurn)
1084
1103
  return { later: "a message before this one runs as the run's next turn: this one runs after it" };
1085
1104
  const claimMcp = mcp;
1086
1105
  const leftOut = claimMcp?.leftOut;
1087
- if (claimMcp && leftOut?.length) {
1106
+ const claimTurn = reopen !== undefined && !reopen.sent && reopen !== waitTurn ? reopen : undefined;
1107
+ if (claimTurn)
1108
+ claimTurn.by ??= command.id;
1109
+ if (claimMcp && leftOut?.length && claimTurn?.by !== command.id) {
1088
1110
  const still = new Set(await claimMcp.fresh());
1089
1111
  const handed = leftOut.filter((server) => !still.has(server));
1090
1112
  if (handed.length) {
@@ -1109,8 +1131,9 @@ function adapterLoop(specOf, options, deps) {
1109
1131
  // and a person's stop or cancel (the stop that cuts the workflow's call, its spend and custody), a raise or a hand-back
1110
1132
  // would never reach the run. `taken` here means its take rides on the commit that places it once the input is sent; a
1111
1133
  // claim that ends first (a stop, a park, the workflow's answer) leaves the row untaken, for the run's end or its next
1112
- // claim to settle, as any message the run's end finds untaken.
1113
- if (waitingFirst > 0 || (!reopen && session.state === "new") || servingFirst) {
1134
+ // claim to settle, as any message the run's end finds untaken. Once the claim sends nothing more (turnsOver), nothing
1135
+ // waits: the message is the run's next claim's.
1136
+ if (!turnsOver && (waitingFirst > 0 || (!reopen && session.state === "new") || servingFirst)) {
1114
1137
  waitingFirst += 1;
1115
1138
  const placing = afterFirst.then(() => placeSteer(command));
1116
1139
  afterFirst = placing.then(() => void (waitingFirst -= 1), (error) => {
@@ -1727,6 +1750,14 @@ function adapterLoop(specOf, options, deps) {
1727
1750
  return { ...pending, refuse: text, figures };
1728
1751
  };
1729
1752
  const beforeRequest = async (request) => {
1753
+ // A learning child past its deadline (LoopDeps.pastDeadline) sends nothing more on its run's key: the request
1754
+ // waits here, unsent, for the cancel its runner hands the loop at that deadline, and leaves refused at that stop.
1755
+ if (deps.pastDeadline?.aborted) {
1756
+ const stop = AbortSignal.any([deps.signal, stopAbort.signal]);
1757
+ if (!stop.aborted)
1758
+ await new Promise((resolve) => stop.addEventListener("abort", () => resolve(), { once: true }));
1759
+ return { refuse: PAST_LEARNING_DEADLINE, forGood: true };
1760
+ }
1730
1761
  // A run whose booked spend passed its cap sends nothing more: it ends in the cap's words (overCap), never paused,
1731
1762
  // whatever else would pause it (a paid call's refusal, pendingPause). One a paid call stopped for good
1732
1763
  // (paid-calls.ts stopRun) ends in that call's words, which say why, past its cap too.
@@ -2340,7 +2371,7 @@ function adapterLoop(specOf, options, deps) {
2340
2371
  const traced = specNow?.trace;
2341
2372
  const routed = request.route === undefined ? traced?.model : traced?.routes?.get(request.route)?.model;
2342
2373
  const known = (asked) => asked === traced?.model || [...(traced?.routes?.values() ?? [])].some((via) => via.model === asked) || specNow?.runCap.modelOf(asked)?.id === asked;
2343
- const model = tracedModel(request.model, { known, ...(routed ? { routed } : {}), ...(deps.redact ? { redact: deps.redact } : {}) });
2374
+ const model = tracedModel(request.model, { known, ...(routed ? { routed } : {}), redact: deps.redact });
2344
2375
  chats.set(ticket.turn, trace.request(model, request.route));
2345
2376
  }
2346
2377
  // The conversation that asked, as its client named it (pi's, one of several asking at once): whose answer reads
@@ -2493,10 +2524,12 @@ function adapterLoop(specOf, options, deps) {
2493
2524
  // go is marked first (LEARNED_ALLOWED), committed before the tool runs: a call issued again after a crash cut it may
2494
2525
  // have run nodes and spent on such an attempt, so its refusal is then no proof it ran nothing, and it is kept
2495
2526
  // `failed`, never `refused`, priced from what its call id booked (failedRecord). The newest of the call's marks and
2496
- // records says which (learned-nodes.ts learnedCallRan): its bridge can't alone (a tool that nests is asked alike on
2497
- // every attempt: process/tools.ts runNesting), nor can the call's start on the CLI record, which a refusal writes
2498
- // too. With neither, the bridge's `replayed` stands in: a run begun before the marks existed has none. Whatever is
2499
- // kept, a refusal reads `failed` once anything was booked under the call id (workflow-calls.ts workflowCallsOf).
2527
+ // records says which (learned-nodes.ts learnedCallRan): its bridge can't alone (a tool that nests is asked as
2528
+ // `replayed` only once an earlier attempt fixed a value or nested a call: process/tools.ts runNesting), nor can the
2529
+ // call's start on the CLI record, which a refusal writes too. With neither, the bridge's `replayed` stands in: a
2530
+ // run begun before the marks existed has none. Whatever is
2531
+ // kept, a refusal reads `failed` once anything was booked under the call id, or while an attempt let go was closed
2532
+ // by no refusal (workflow-calls.ts workflowCallsOf).
2500
2533
  const learnedEntry = async (call, answer) => {
2501
2534
  const named = call.tool === LEARNED_WORKFLOW_TOOL ? spec.gate?.learnedOf?.(call.args) : undefined;
2502
2535
  const [journalOf, rootOf] = [harness, root];
@@ -2543,7 +2576,7 @@ function adapterLoop(specOf, options, deps) {
2543
2576
  // Every harness's events reach its trace first (its tool calls, a plan harness's turns), with a record or without.
2544
2577
  const recorded = record ? onEvent(record) : undefined;
2545
2578
  const traceAnd = (event) => {
2546
- trace?.event(tracedEvent(event, { mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined, ...(deps.redact ? { redact: deps.redact } : {}) }));
2579
+ trace?.event(tracedEvent(event, { mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined, redact: deps.redact }));
2547
2580
  recorded?.(event);
2548
2581
  };
2549
2582
  const io = { writer, models: counted, signal: deps.signal, onEvent: traceAnd, gate: sessionGate, ...(permission ? { permission } : {}), hostTool: hosted, ...(ownCalls ? { ownCalls } : {}), bookedCost, keepCalls, ...(record ? {} : { nestedEnded }) };
@@ -2723,8 +2756,18 @@ function adapterLoop(specOf, options, deps) {
2723
2756
  }
2724
2757
  const paused = raising.budget;
2725
2758
  const resumes = raising.resumes;
2759
+ // Parking again from here (no raise of this claim resumed it, or no follow-up can be sent), decided on what the
2760
+ // claim read before its raise entry's commit: a raise row that reaches it from now on, that commit's wait
2761
+ // included, waits for the run's next claim (raise), never taken by a claim that is parking, which would leave the
2762
+ // run parked with nothing to wake it.
2763
+ if (paused && (!resumes || raising.capUsd === undefined || !spec.cap?.followUpOf))
2764
+ pausing = true;
2726
2765
  await takeRaises();
2727
2766
  if (paused) {
2767
+ // No raise resumed it (each refused, or a retry of one before): its pause stands as it was, its budget entry
2768
+ // unanswered, so it parks again on that entry with nothing written, never a second entry at the same cap.
2769
+ if (!resumes && (await raiseStateOf()).pause !== undefined)
2770
+ return await parkAgain(harness, gate);
2728
2771
  if (!resumes || raising.capUsd === undefined || !spec.cap?.followUpOf)
2729
2772
  return await parkAtCap(harness, root, gate, paused, "cap");
2730
2773
  // The server's words, shown as its row ("AgentRun: …"), never as the person's; under the id a raise's answer named.
@@ -2760,7 +2803,18 @@ function adapterLoop(specOf, options, deps) {
2760
2803
  // runner reads on a later poll is waited for (or the run's stop, park or loss).
2761
2804
  if (firstInputPlaced && !reopen.sent) {
2762
2805
  const lost = new Promise((resolve) => (deps.signal.aborted ? resolve() : deps.signal.addEventListener("abort", () => resolve(), { once: true })));
2763
- await Promise.race([firstInputPlaced, stopping, parking, harness.closed.then(() => undefined, () => undefined), lost]);
2806
+ const woke = await Promise.race([firstInputPlaced.then(() => true), stopping.then(() => false), parking.then(() => false), harness.closed.then(() => false, () => false), lost.then(() => false)]);
2807
+ // Woken with nothing placed (the reopen's own message refused or left): the claim sends nothing into the
2808
+ // session that never started, asks nothing of it, and ends the run on the end it had before (a stop's, or its
2809
+ // learned workflow's answer). A message handed over from here on is the run's next claim's (`later`), never
2810
+ // queued for a first input that is never sent.
2811
+ if (woke && !reopen.sent) {
2812
+ turnsOver = true;
2813
+ reopen = undefined;
2814
+ inputSent();
2815
+ const { projectCheckpoint: _, ...before } = foundEntries.findLast((entry) => entry.kind === KINDS.end).data;
2816
+ return await writeEnd(harness, root, gate, before, []);
2817
+ }
2764
2818
  }
2765
2819
  const sent = reopen.sent;
2766
2820
  const fed = reopen.feedback;
@@ -3784,16 +3838,16 @@ function adapterLoop(specOf, options, deps) {
3784
3838
  finish("lapsed");
3785
3839
  }, () => undefined);
3786
3840
  // So does a message left for the run's next turn (steer), the same way; one left while the wait was starting ends it
3787
- // as soon as it holds.
3788
- if (waitTurn === mine) {
3789
- endWaitNow = () => {
3790
- cut = true;
3791
- if (!mine.sent)
3792
- finish("lapsed");
3793
- };
3794
- if (leftForNextTurn)
3795
- endWaitNow();
3796
- }
3841
+ // as soon as it holds. One left while an answer is placed (a message that waited for the run's first input is placed
3842
+ // off the runner's delivery, so the next row can arrive meanwhile) ends it once that answer is refused: no message
3843
+ // reaches the wait after it.
3844
+ endWaitNow = () => {
3845
+ cut = true;
3846
+ if (!mine.sent)
3847
+ finish("lapsed");
3848
+ };
3849
+ if (leftForNextTurn)
3850
+ endWaitNow();
3797
3851
  void (async () => {
3798
3852
  for (;;) {
3799
3853
  await placing;
@@ -4052,6 +4106,12 @@ function adapterLoop(specOf, options, deps) {
4052
4106
  await pauseAtCap(on, conversation, theGate, data);
4053
4107
  return parkClaim(on, theGate, cause);
4054
4108
  }
4109
+ /** The run parked again at the pause it was woken from, which no raise of this claim answered: nothing is written (its
4110
+ * budget entry and the row's words stand), and the release parks the row again (LoopEnd `again`). */
4111
+ async function parkAgain(on, theGate) {
4112
+ const end = await parkClaim(on, theGate, "cap");
4113
+ return end.state === "parked" ? { ...end, again: true } : end;
4114
+ }
4055
4115
  /** Waits, at most the spec's parkSiblingsMs (PARK_SIBLINGS_MS), until no call pi started beside a parked one is still
4056
4116
  * running: a model call of the same answer (its assistant entry) past its stored intent. Each one's result is then on the
4057
4117
  * journal before the park seals it, and the resume hands it to the model with the parked call's answer, never as a call
@@ -4340,8 +4400,15 @@ function adapterLoop(specOf, options, deps) {
4340
4400
  // never runs the message on the key held before it.
4341
4401
  await specNow?.modelKey?.fresh();
4342
4402
  }
4343
- if (command.kind === "steer")
4344
- return steer(command);
4403
+ if (command.kind === "steer") {
4404
+ const outcome = await steer(command);
4405
+ // The reopen's own message refused or left (a trigger's in a session on its owner's sign-in): no message is the
4406
+ // claim's turn now, and a message after it is checked as any other, so a reopen of a session still new stops
4407
+ // waiting for its first input (firstInputPlaced); a message left meanwhile reopens the run on its next claim.
4408
+ if (!("taken" in outcome) && reopen !== undefined && reopen !== waitTurn && !reopen.sent && reopen.by === command.id)
4409
+ reopen.placed?.();
4410
+ return outcome;
4411
+ }
4345
4412
  if (command.kind === "approve" || command.kind === "deny") {
4346
4413
  // An answer names its approval: the asked call's id. One that names no call waiting for its answer (an old
4347
4414
  // approval, another run's) is refused, never applied to the call that waits now.
@@ -76,12 +76,15 @@ export interface ClaimComputer {
76
76
  export type ComputerForClaim = typeof claimComputer;
77
77
  /** The wires pi speaks on the runner: main's pi's (provider.ts), Anthropic's Messages and OpenAI's Responses. */
78
78
  export declare const PI_WIRES: readonly Wire[];
79
+ /** The browser's catalog name (tools.ts TOOLS.browser). */
80
+ export declare const BROWSER_TOOL = "browser";
79
81
  /** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
80
- * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
82
+ * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations); on
83
+ * another harness, its extension in the same Harness and its tools host tools (browserHostTools). */
81
84
  export declare const BROWSER_ON_RUNNER = true;
82
85
  /** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
83
- * (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
84
- * booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
86
+ * (host.browserComputer), fail closed: only where the runner offers it (BROWSER_ON_RUNNER), and only with the run's
87
+ * ledger booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
85
88
  export declare const browserListed: (host: Pick<ToolHost, "ledger" | "browserComputer">, granted: readonly string[]) => boolean;
86
89
  /** What the runner hands the spec builder, beside the claim and the loop's own Harness (the AdapterRun): the store (its
87
90
  * agent and run reads, and the live-viewer seam the browser tool writes through), the data directory a Mode 1 run folder
@@ -95,6 +98,10 @@ export interface AdapterSpecDeps {
95
98
  readonly journal: (claim: Claim) => Journal;
96
99
  /** The one store: `runs` and `agents` for the run's revision, and the live-viewer seam for the browser tool. */
97
100
  readonly store: Store & LiveViewerStore;
101
+ /** The plane the claim's runner capped (run-child-host.ts, by underServerCeilings) and chose the run's keys by, handed to
102
+ * the run's own process (run-child.ts): taken as it is there, never capped again on settings read later, so the run's
103
+ * tools and the keys it was handed are of one reading. Absent: the claim caps its launch itself. */
104
+ readonly claimedPlane?: RunLaunch["plane"];
98
105
  /** The key the store's sealed values are opened under (store/seal.ts): the runner's. Undefined in a run's own process
99
106
  * (run-child.ts), which never holds it: what a claim opens with it is asked of the runner there (held.ts). */
100
107
  readonly sealKey: Buffer | undefined;
@@ -295,7 +302,8 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
295
302
  readonly learn: (flows: readonly LearnedWorkflow[]) => void;
296
303
  readonly askedOn: (host: ToolHost) => void;
297
304
  readonly computerOff: () => boolean; /** Whether the run can write a file now, as its gate decides a save_as (RunGate.writeBar): what its files note and computer_screenshot's save_as are offered by. */
298
- readonly writes: () => boolean;
305
+ readonly writes: () => boolean; /** The computer ops the gate refuses whatever their arguments (RunGate.opsRefused: not given, denied, or an ask no one can approve): what computer_op and a script's `computer` leave out. */
306
+ readonly opsRefused: () => readonly string[];
299
307
  }>;
300
308
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
301
309
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
@@ -420,6 +428,14 @@ export declare function claimLiveAt(deps: Pick<AdapterSpecDeps, "env" | "sealKey
420
428
  * CLI spec share. Each runs under the adapter loop's one gate (spec.gate) on the claim's keys (host.env), and books its
421
429
  * paid requests on the run's one ledger itself (bookedIn): they carry no settle of their own. */
422
430
  export declare function webHostTools(host: ToolHost, granted: readonly string[], ctx: HostToolCtx): Promise<HostTool[]>;
431
+ /** The browser on a harness other than pi (the CLI spec): tools.ts's own binding on this run's ToolHost, as pi's native
432
+ * route binds it (its store, claim and seal key, its live viewers, its money on host.ledger, its computer the claim's),
433
+ * its durable extension installed in the run's registry (host.install), so its documents and its release and hand-over
434
+ * tasks are the run's Harness's, and its reconcile, release and drain on the host's lifecycle (the spec's `lifecycle`).
435
+ * Each of its registrations is a host tool (host-tools.ts hostToolOf, RUNS_ONCE: a call a crash cut off is answered
436
+ * interrupted, its session left to the next claim's reconcile), under the adapter loop's one gate (spec.gate), which
437
+ * holds each to the table's `browser` (tool-gate.ts BROWSER_REGISTRATIONS). None unless browserListed. */
438
+ export declare function browserHostTools(host: ToolHost, granted: readonly string[], plane: RunLaunch["plane"], ctx: HostToolCtx): Promise<HostTool[]>;
423
439
  /** What a claim's MCP servers and calendar_events may reach on loopback (mcpForClaim's and buildToolHost's `loopback` and
424
440
  * `own`): nothing unless mcpLoopback; else loopback, never at mcpOwn's ports nor mcpOwnOf's, read now. Read once per
425
441
  * claim. */
@@ -29,7 +29,7 @@ import { deniedText, noApproverText, runGate } from "../tool-gate.js";
29
29
  import { DECISION_PROVIDER_KEYS, loadToolSettings, recheckPlane, TOOL_PLANE_ENV } from "../tool-plane.js";
30
30
  import { readApprovers } from "../server-approvers.js";
31
31
  import { ASK_TOOL, askPerson, toolOf, webAnswerCut } from "../tools.js";
32
- import { hostToolOf } from "../host-tools.js";
32
+ import { hostToolOf, RUNS_ONCE } from "../host-tools.js";
33
33
  import { WEB_SEARCH_TOOL } from "../web-search.js";
34
34
  import { environmentLine, runZone } from "../environment.js";
35
35
  import { effortGuidance } from "../effort-guidance.js";
@@ -49,7 +49,8 @@ import { filesToCopy, placeRunInputs } from "../uploads.js";
49
49
  import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
50
50
  import { UNREADABLE_SIGN_IN } from "../run-view.js";
51
51
  import { durableWait } from "../workflow/pi-versions.js";
52
- import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, subagentTierKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
52
+ import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, keyedNow, hostDecisionKeys, learnedDecisionKeys, subagentTierKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
53
+ import { atRunEnd } from "../learning-work.js";
53
54
  import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
54
55
  import { agreeOnOf } from "../learning-setting.js";
55
56
  import { catalogSessionNames, claimMetering, mcpWhereHeld } from "./mcp-run.js";
@@ -70,7 +71,7 @@ import { AUDIT_PARKED, withAudit } from "./audit.js";
70
71
  import { runPathMetricsOverStore } from "../store-reads/learning.js";
71
72
  import { specBuilt } from "./spec-holds.js";
72
73
  import { archilWhereHeld, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
73
- import { loadArchilSettings } from "../archil-settings.js";
74
+ import { loadArchilSettings, noExecRegionOf } from "../archil-settings.js";
74
75
  import { settingOfDefinition } from "../computer-setting.js";
75
76
  import { computerFilesNote, computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
76
77
  import { computerTurnedOff, hadComputer, recordComputerOff } from "./computer-journal.js";
@@ -79,7 +80,7 @@ import { planBeforeRun, PLAN_PROVIDER } from "../chatgpt-plan.js";
79
80
  import { heldSpecOf } from "./held-run.js";
80
81
  import { loopComputerOf } from "./computer-channel.js";
81
82
  import { githubAppAccess } from "./github-app.js";
82
- import { prCheckoutForClaim } from "./pr-checkout.js";
83
+ import { checkoutWhereNoExec, prCheckoutForClaim } from "./pr-checkout.js";
83
84
  import { holdStored, storeSecrets } from "./store-secrets.js";
84
85
  import { bashPolicyOf } from "../bash-read-only.js";
85
86
  import { monidForClaim, withMonid } from "./monid-run.js";
@@ -90,13 +91,14 @@ import { agentOfRun, routeTrace } from "../otel/genai.js";
90
91
  /** The wires pi speaks on the runner: main's pi's (provider.ts), Anthropic's Messages and OpenAI's Responses. */
91
92
  export const PI_WIRES = Object.freeze(["anthropic-messages", "openai-responses"]);
92
93
  /** The browser's catalog name (tools.ts TOOLS.browser). */
93
- const BROWSER_TOOL = "browser";
94
+ export const BROWSER_TOOL = "browser";
94
95
  /** Whether the runner offers the browser at all: on pi's native route (PiAdapterOptions.extensions), where pi-browser's
95
- * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations). */
96
+ * durable extension runs in the claim's Harness, its tools pi's own tool tasks (their memo, task and conversations); on
97
+ * another harness, its extension in the same Harness and its tools host tools (browserHostTools). */
96
98
  export const BROWSER_ON_RUNNER = true;
97
99
  /** Whether the runner installs the browser for a run whose revision grants `granted`, or whose computer is a browser
98
- * (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
99
- * booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
100
+ * (host.browserComputer), fail closed: only where the runner offers it (BROWSER_ON_RUNNER), and only with the run's
101
+ * ledger booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
100
102
  export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && (granted.includes(BROWSER_TOOL) || host.browserComputer !== undefined);
101
103
  /** A template eval case's files (EvalFakes.files) written into the run's work folder at its claim, after its inputs and
102
104
  * before its computer and its first turn, so they reach a computer's /workspace as its uploads do. Each one the folder
@@ -353,7 +355,7 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
353
355
  current = await storeSettings(store);
354
356
  return current.unreadable ? "deny" : gate.policy(tool);
355
357
  };
356
- return Object.assign(decide, { askedAs: (tool, args) => gate.askedAs(tool, args), permissions, permission, learnedOf, learn: (flows) => void (learned = flows), askedOn: (made) => void (host = made), computerOff: () => gate.computerOff !== undefined, writes: () => gate.writeBar() === undefined });
358
+ return Object.assign(decide, { askedAs: (tool, args) => gate.askedAs(tool, args), permissions, permission, learnedOf, learn: (flows) => void (learned = flows), askedOn: (made) => void (host = made), computerOff: () => gate.computerOff !== undefined, writes: () => gate.writeBar() === undefined, opsRefused: () => gate.opsRefused() });
357
359
  }
358
360
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
359
361
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */
@@ -402,6 +404,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
402
404
  // claim's memory only); else Mode 1, the run's local folder. The same for the pi and the CLI spec.
403
405
  const archilSettings = await loadArchilSettings(deps.store, deps.env);
404
406
  const mode = archilSettings === undefined ? 1 : 2;
407
+ // Its region with no serverless exec, where it has none: a run with no computer that mounts its folder has no shell.
408
+ const noExec = noExecRegionOf(archilSettings);
405
409
  const archil = archilSettings === undefined
406
410
  ? undefined
407
411
  // The run's mount credential is minted per run the first time a computer's mount asks (archil-mount-credential.ts), on
@@ -434,8 +438,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
434
438
  // The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
435
439
  // turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
436
440
  // there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
437
- // person's stop ends the fetch at once (run.stopped).
438
- const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
441
+ // person's stop ends the fetch at once (run.stopped). On an Archil region with no serverless exec (noExec) the disk runs
442
+ // no command: the checkout waits for the run's computer (below, checkoutWhereNoExec).
443
+ 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;
439
444
  holds.hold({ checkout });
440
445
  // The run's skills and its learning seed, laid in its folder through the run's Workspace now, before its computer
441
446
  // exists: on Archil the computer's mount of the folder takes the disk's write delegation, and from then on every write
@@ -473,7 +478,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
473
478
  // and a call reaches it only through the session this spec returns, after `tools` is made.
474
479
  let filedIn;
475
480
  const hold = (values) => cut.hold(values);
476
- 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), ...claimMetering(deps, fakes?.web, launch) });
481
+ 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: cut, 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), ...claimMetering(deps, fakes?.web, launch) });
477
482
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
478
483
  holds.hold({ passed: mcp });
479
484
  // The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
@@ -497,7 +502,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
497
502
  // row names the disk that credential is on (mountDisk), asked only at the park: a run's own process hands its claim to
498
503
  // its runner, whose computerForClaim asks its own Archil claim. A recording of its screen (computer.record) goes in
499
504
  // the run's recordings folder, beside its folder, said on its timeline.
500
- { ...deps.computerDeps, mode, 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) } : {}) });
505
+ { ...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) } : {}) });
501
506
  // The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
502
507
  // (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
503
508
  // A desktop's or a phone's hold (the person's take-over) wraps its ports: a call made while the person holds it waits,
@@ -510,10 +515,16 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
510
515
  // The computer's tools are the run's own host tools, as on every harness: the host's codemode (meta-tools.ts) calls them
511
516
  // as `tools.<name>`, each a nested call, gated and recorded as the model's own call is. A computer that replaced an
512
517
  // earlier claim's holds its acts to what it showed.
513
- const tools = await runTools(ws.workspace, computer.computer, { mode, context, ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
518
+ const tools = await runTools(ws.workspace, computer.computer, { mode, noExec, context, ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
514
519
  filedIn = tools.workspace;
515
520
  let remoteProjectCapture = false;
516
521
  holds.hold({ tools: { end: () => remoteProjectCapture ? Promise.resolve() : tools.end() } });
522
+ // On an Archil region with no serverless exec, the checkout now: in the computer that mounts the run's folder, through
523
+ // its own exec, writing through its mount; with none, the run is told why there is none (pr-checkout.ts).
524
+ if (body.checkout && noExec !== undefined) {
525
+ 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));
526
+ holds.hold({ checkout });
527
+ }
517
528
  // The run's model route: its model through routeOf (NEVER re-resolved — the launch's model, pinned at start), the catalog
518
529
  // price with tiers for the cap, and the proxy's price (pi-ai calculateCost, tiered).
519
530
  // pi speaks both of main's wires: an OpenAI-family model's route is OpenAI's Responses itself.
@@ -580,8 +591,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
580
591
  // The run's adapter is its runner's (runner/adapters/index.ts RunnerHarness: pi's, or the one a harness module's entry
581
592
  // brings), made from the run's launch on its route. Its private files, where it keeps any, go in this claim's folder of
582
593
  // the run's scratch (the CLI spec's layout), swept at the claim's end with the earlier claims' and any parent left empty.
583
- // pi's own options (its extensions, tools, redactor, the model's catalog entry, hosted search, tiers, and the route's
584
- // whole provider) are the harness's own options (`extra`), passed on as given.
594
+ // The run's one redactor is the launch's (HarnessLaunch.redact). pi's own options (its extensions, tools, the model's
595
+ // catalog entry, hosted search, tiers, and the route's whole provider) are the harness's own (`extra`), passed on as given.
585
596
  const scratch = scratchFolder(deps.data, runRow.agentId, claim.runId);
586
597
  const harnesses = join(scratch, "harness");
587
598
  holds.hold({ scratch: { sweep: async () => (await import("./cli-run-spec.js")).sweepScratch(harnesses, claim.epoch, [harnesses, scratch, dirname(scratch)]) } });
@@ -592,12 +603,13 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
592
603
  ...(route.price ? { price: route.price } : {}),
593
604
  sessionsDir: join(harnesses, String(claim.epoch)),
594
605
  ...(route.fetch ? { fetch: route.fetch } : {}),
606
+ ...(route.local ? { local: true } : {}),
607
+ redact: cut,
595
608
  }, {
596
609
  // Read when the session opens (pi.ts), so the browser's extension pushed by bindNonHandTools below is in it.
597
610
  extensions: native,
598
611
  tools: piTools,
599
612
  provider: route.provider,
600
- redact: cut,
601
613
  ...(route.like ? { like: route.like } : {}),
602
614
  // The run's web_search is its provider's hosted search (the launch's plane, as its start resolved it): the session's
603
615
  // proxy admits that search's one request (it goes through the session's port: buildToolHost's `search`) and books it
@@ -673,12 +685,13 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
673
685
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
674
686
  const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
675
687
  // None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
676
- 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;
688
+ // A claim on the run's own key runs its learning work on that key (keyed), its check at the run's end (atEnd).
689
+ 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;
677
690
  // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
678
691
  // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
679
692
  // running takes none of them: it settles no audit and starts no replay run, starts on no workflow, and its tool runs
680
693
  // none (so no learned tier is routed, below).
681
- 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: [] };
694
+ 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: [] };
682
695
  const firstChoice = learned.choice;
683
696
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
684
697
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -732,7 +745,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
732
745
  // The run's tools. The hands (read/write/edit/bash and the background tools) are the kernel registry's over the run's
733
746
  // Workspace and computer (runTools.hostTools); the gate is the adapter loop's own (spec.gate), so they run as asked.
734
747
  const results = new Map();
735
- const handTools = tools.hostTools(withKindTools(granted, tools), { results, writes: gate.writes() });
748
+ const handTools = tools.hostTools(withKindTools(granted, tools), { results, writes: gate.writes(), opsRefused: gate.opsRefused() });
736
749
  // The non-hand tools run on the claim's keys (host.env), so a vendor's error may echo one: each answer, and a throw's
737
750
  // words, pass the run's one redactor before the harness, the model or the record has them.
738
751
  const tiers = new Map([...[...tierRoutes].filter(([tier]) => !isSubagentRoute(tier) && tier !== GRADER).map(([tier, { model }]) => [tier, { model }]), ...[...tierUnreachable].map(([tier, why]) => [tier, { why }])]);
@@ -797,6 +810,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
797
810
  tools: sessionTools,
798
811
  context: "fresh",
799
812
  ...(thinking ? { thinking: thinking } : {}),
813
+ // The run's model's window, from its route's catalog entry: pi holds every tool result to its share (boundPiResult).
814
+ ...(route.contextWindow ? { contextWindow: route.contextWindow } : {}),
800
815
  };
801
816
  // The person's first message: the start body's content, with the run's file manifest beside it (run-manifest.ts), read
802
817
  // through the run's Workspace (Mode 2: its inputs/ on the disk, never a folder of this machine).
@@ -867,8 +882,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
867
882
  // The run's computer as the claim made it, with the person's hold on a desktop or phone: the loop shows the hold up,
868
883
  // applies a take-over and a hand-back to it, and answers the computer call channel's rows on it.
869
884
  ...(loopComputer ? { computer: loopComputer } : {}),
870
- // A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.
871
- ...(tools.computer ? { scriptComputer: tools.computer } : {}),
885
+ // A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools, its
886
+ // declarations without the ops the gate refuses whatever their arguments.
887
+ ...(tools.computer ? { scriptComputer: { ...tools.computer, opsRefused: gate.opsRefused() } } : {}),
872
888
  // A computer that replaced an earlier claim's: the model is told once, on its next request (the loop's computer note).
873
889
  ...(computer.replaced ? { computerNote: computerReplacedNote(computer.replaced) } : {}),
874
890
  // 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
@@ -1168,6 +1184,30 @@ export async function webHostTools(host, granted, ctx) {
1168
1184
  }
1169
1185
  return tools;
1170
1186
  }
1187
+ /** `host` for the browser's binding: its vendor the launch's plane (resolved when the run was created, runs-over-store.ts
1188
+ * planeFor) checked again against the keys this claim read from the store (recheckPlane, which keeps the plane's Jev
1189
+ * off), as both specs bind it. */
1190
+ function browserHostOf(host, plane) {
1191
+ const checked = plane ? recheckPlane(plane, host.env) : {};
1192
+ const env = { ...host.env };
1193
+ delete env[TOOL_PLANE_ENV];
1194
+ if (Object.keys(checked).length)
1195
+ env[TOOL_PLANE_ENV] = JSON.stringify(checked);
1196
+ return { ...host, env };
1197
+ }
1198
+ /** The browser on a harness other than pi (the CLI spec): tools.ts's own binding on this run's ToolHost, as pi's native
1199
+ * route binds it (its store, claim and seal key, its live viewers, its money on host.ledger, its computer the claim's),
1200
+ * its durable extension installed in the run's registry (host.install), so its documents and its release and hand-over
1201
+ * tasks are the run's Harness's, and its reconcile, release and drain on the host's lifecycle (the spec's `lifecycle`).
1202
+ * Each of its registrations is a host tool (host-tools.ts hostToolOf, RUNS_ONCE: a call a crash cut off is answered
1203
+ * interrupted, its session left to the next claim's reconcile), under the adapter loop's one gate (spec.gate), which
1204
+ * holds each to the table's `browser` (tool-gate.ts BROWSER_REGISTRATIONS). None unless browserListed. */
1205
+ export async function browserHostTools(host, granted, plane, ctx) {
1206
+ if (!browserListed(host, granted))
1207
+ return [];
1208
+ const binding = await toolOf(BROWSER_TOOL).bind(browserHostOf(host, plane));
1209
+ return binding.tools.flatMap((registration) => hostToolOf(BROWSER_TOOL, registration, ctx, RUNS_ONCE) ?? []);
1210
+ }
1171
1211
  async function bindNonHandTools(host, kind, granted, run, context, results, root, plane, workflows, native, permissions, tiers, mcp, modelName, replay) {
1172
1212
  // Fail closed (browserListed): the browser binds only on the native route (BROWSER_ON_RUNNER) and with the claim's
1173
1213
  // one-ledger booking on its ToolHost (host.ledger.paid); otherwise its extension is not installed. learned_workflow
@@ -1190,14 +1230,8 @@ async function bindNonHandTools(host, kind, granted, run, context, results, root
1190
1230
  // claim read from the store (recheckPlane, which keeps the plane's Jev off). Its durable extension goes to piAdapter
1191
1231
  // (`native`), never wrapped as a HostTool and never installed here too (piAdapter installs it once); its lifecycle (the
1192
1232
  // Config per conversation, reconcile, the release drain) through the host's hooks into the spec's lifecycle.
1193
- if (browser) {
1194
- const checked = plane ? recheckPlane(plane, host.env) : {};
1195
- const env = { ...host.env };
1196
- delete env[TOOL_PLANE_ENV];
1197
- if (Object.keys(checked).length)
1198
- env[TOOL_PLANE_ENV] = JSON.stringify(checked);
1199
- await toolOf(BROWSER_TOOL).bind({ ...host, env, install: (extension) => void native.push(extension) });
1200
- }
1233
+ if (browser)
1234
+ await toolOf(BROWSER_TOOL).bind({ ...browserHostOf(host, plane), install: (extension) => void native.push(extension) });
1201
1235
  // TODO (decisions, option (a)): a pi run's decision tools book on the run's ONE cap (runCap's run.decisions), which the
1202
1236
  // adapter loop makes from its own sessions and hands the spec at open — the loop passes { decisions, models } the same way
1203
1237
  // it passes spec.lifecycle. The decision providers come from the claim's secrets (claim-secrets.ts). Wired against that
@@ -1,5 +1,6 @@
1
1
  import type { AgentAdapter, Wire } from "@parcha/agentrun-kernel";
2
2
  import type { AdapterRun } from "../adapter-loop.js";
3
+ import type { HeldRedact } from "../redact.js";
3
4
  /** What every adapter is given for one claim, from the run's launch. */
4
5
  export interface HarnessLaunch {
5
6
  /** The claim's run: its Harness on the run's journal (pi adds its turns to it). */
@@ -22,6 +23,11 @@ export interface HarnessLaunch {
22
23
  readonly sessionsDir: string;
23
24
  /** The proxy's upstream fetch (a test's scripted origin). */
24
25
  readonly fetch?: typeof fetch;
26
+ /** The model runs on this machine (the route's `local`: an Ollama model): a CLI waits longer on its silent stream. */
27
+ readonly local?: boolean;
28
+ /** The runner's one redactor (LoopDeps.redact), holding the keys the claim opens: pi's session proxy cuts a provider's
29
+ * error with it before pi has it. */
30
+ readonly redact: HeldRedact;
25
31
  }
26
32
  /** A harness the runner runs. */
27
33
  export interface RunnerHarness {
@@ -9,7 +9,7 @@ const CODEX_PACKAGE = "@parcha/agentrun-harness-codex";
9
9
  export const RUNNER_HARNESSES = {
10
10
  pi: {
11
11
  // `extra`: pi's own options (PiAdapterOptions), as the run's spec gives them (adapter-run-spec.ts): its extensions,
12
- // tools, redactor, tiers, and the route's whole provider over the launch's.
12
+ // tools, tiers, and the route's whole provider over the launch's. Its redactor is the launch's, typed.
13
13
  adapter: async (launch, extra = {}) => piAdapter({
14
14
  run: launch.run,
15
15
  model: launch.model,
@@ -17,6 +17,7 @@ export const RUNNER_HARNESSES = {
17
17
  ...(launch.price ? { price: launch.price } : {}),
18
18
  ...(launch.fetch ? { fetch: launch.fetch } : {}),
19
19
  ...extra,
20
+ redact: launch.redact,
20
21
  }),
21
22
  },
22
23
  [claudeFacts.id]: {
@@ -32,6 +33,9 @@ export const RUNNER_HARNESSES = {
32
33
  provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}) },
33
34
  ...(launch.price ? { price: launch.price } : {}),
34
35
  ...(launch.fetch ? { fetch: launch.fetch } : {}),
36
+ // A local model says nothing while it loads, reads its prompt or thinks: the CLI waits it out. A paid route's hung
37
+ // stream keeps the CLI's own limit, so it holds the run's slot and its cap no longer than that.
38
+ ...(launch.local ? { streamIdleMs: claude.LOCAL_STREAM_IDLE_MS } : {}),
35
39
  sessionsDir: launch.sessionsDir,
36
40
  ...extra,
37
41
  });