@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.58

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 (312) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/README.md +246 -66
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +15 -5
  11. package/dist/api-only.js +32 -8
  12. package/dist/box-paths.d.ts +4 -3
  13. package/dist/box-paths.js +7 -4
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/chatgpt-plan.d.ts +18 -8
  19. package/dist/chatgpt-plan.js +91 -34
  20. package/dist/claude-login-token.d.ts +117 -0
  21. package/dist/claude-login-token.js +737 -0
  22. package/dist/claude-login.d.ts +120 -22
  23. package/dist/claude-login.js +347 -63
  24. package/dist/claude-sign-in.d.ts +17 -6
  25. package/dist/claude-sign-in.js +42 -39
  26. package/dist/cli.js +33 -10
  27. package/dist/composio-made.d.ts +4 -0
  28. package/dist/composio-made.js +4 -0
  29. package/dist/composio-preset.d.ts +43 -2
  30. package/dist/composio-preset.js +92 -4
  31. package/dist/computer-attach.d.ts +35 -17
  32. package/dist/computer-attach.js +301 -49
  33. package/dist/computer-held-routes.d.ts +5 -4
  34. package/dist/computer-held-routes.js +29 -8
  35. package/dist/computer-held.d.ts +6 -1
  36. package/dist/computer-held.js +14 -0
  37. package/dist/computer-record.js +4 -2
  38. package/dist/computer-viewer.js +4 -1
  39. package/dist/computers.d.ts +10 -10
  40. package/dist/computers.js +5 -5
  41. package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
  42. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  43. package/dist/console/assets/index-DPh29cyz.js +747 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/decisions.d.ts +1 -1
  46. package/dist/decisions.js +1 -1
  47. package/dist/dial-relay.d.ts +25 -4
  48. package/dist/dial-relay.js +129 -1
  49. package/dist/docker-host-addresses.d.ts +22 -11
  50. package/dist/docker-host-addresses.js +38 -26
  51. package/dist/env-switch.d.ts +8 -0
  52. package/dist/env-switch.js +31 -2
  53. package/dist/errors.d.ts +1 -0
  54. package/dist/errors.js +2 -0
  55. package/dist/fal-price.d.ts +56 -20
  56. package/dist/fal-price.js +400 -90
  57. package/dist/handed-values.d.ts +43 -1
  58. package/dist/handed-values.js +119 -2
  59. package/dist/harness-archive.d.ts +13 -10
  60. package/dist/harness-archive.js +60 -34
  61. package/dist/harness-check.d.ts +3 -1
  62. package/dist/harness-check.js +25 -46
  63. package/dist/harness-keys.d.ts +73 -27
  64. package/dist/harness-keys.js +194 -61
  65. package/dist/harness-recipe-entry.d.ts +8 -7
  66. package/dist/harness-recipe-entry.js +21 -32
  67. package/dist/harness-recipe.d.ts +38 -25
  68. package/dist/harness-recipe.js +49 -36
  69. package/dist/harness-sign-in.js +12 -23
  70. package/dist/harness-table.d.ts +10 -3
  71. package/dist/harness-table.js +26 -21
  72. package/dist/harness.d.ts +1 -0
  73. package/dist/harness.js +17 -5
  74. package/dist/hosted-search.d.ts +1 -1
  75. package/dist/hosted-search.js +1 -2
  76. package/dist/import-worker.d.ts +4 -2
  77. package/dist/import-worker.js +9 -2
  78. package/dist/in-flight.d.ts +26 -0
  79. package/dist/in-flight.js +52 -0
  80. package/dist/key-refusal.d.ts +9 -4
  81. package/dist/key-refusal.js +107 -25
  82. package/dist/learn/ledger.d.ts +170 -0
  83. package/dist/learn/ledger.js +218 -0
  84. package/dist/learn/promote.d.ts +3 -3
  85. package/dist/learn/promote.js +1 -1
  86. package/dist/learn/secrets.d.ts +13 -3
  87. package/dist/learn/secrets.js +118 -17
  88. package/dist/learning-cost.d.ts +28 -23
  89. package/dist/learning-cost.js +19 -23
  90. package/dist/link-check.js +1 -1
  91. package/dist/live-reach.d.ts +2 -0
  92. package/dist/live-reach.js +2 -0
  93. package/dist/llms.txt +1 -1
  94. package/dist/marketplace.d.ts +77 -0
  95. package/dist/marketplace.js +224 -0
  96. package/dist/mcp-api-only-origins.d.ts +35 -0
  97. package/dist/mcp-api-only-origins.js +57 -0
  98. package/dist/mcp-gateway.d.ts +7 -5
  99. package/dist/mcp-gateway.js +9 -12
  100. package/dist/mcp-secret-writes.js +5 -3
  101. package/dist/mcp-servers-store.d.ts +28 -6
  102. package/dist/mcp-servers-store.js +53 -4
  103. package/dist/media-duration.d.ts +3 -0
  104. package/dist/media-duration.js +90 -9
  105. package/dist/micro.d.ts +2 -0
  106. package/dist/micro.js +2 -0
  107. package/dist/model-form.d.ts +5 -4
  108. package/dist/model-form.js +11 -7
  109. package/dist/model.d.ts +10 -6
  110. package/dist/model.js +16 -11
  111. package/dist/monid.d.ts +14 -1
  112. package/dist/monid.js +103 -26
  113. package/dist/ollama-provider.d.ts +7 -1
  114. package/dist/ollama-provider.js +14 -2
  115. package/dist/openapi.js +210 -37
  116. package/dist/otel/genai.d.ts +65 -0
  117. package/dist/otel/genai.js +116 -0
  118. package/dist/otel/tracer.d.ts +55 -0
  119. package/dist/otel/tracer.js +308 -0
  120. package/dist/page.d.ts +2 -0
  121. package/dist/page.js +3 -1
  122. package/dist/paid-calls.d.ts +1 -32
  123. package/dist/paid-calls.js +4 -39
  124. package/dist/place-offers.d.ts +4 -0
  125. package/dist/place-offers.js +7 -4
  126. package/dist/provider.d.ts +11 -2
  127. package/dist/provider.js +59 -8
  128. package/dist/redact/match.d.ts +30 -3
  129. package/dist/redact/match.js +422 -41
  130. package/dist/refusal-words.d.ts +11 -0
  131. package/dist/refusal-words.js +11 -0
  132. package/dist/run-census.d.ts +67 -0
  133. package/dist/run-census.js +240 -0
  134. package/dist/run-computer.d.ts +6 -3
  135. package/dist/run-computer.js +4 -1
  136. package/dist/run-cut.d.ts +15 -6
  137. package/dist/run-cut.js +30 -9
  138. package/dist/run-files.d.ts +3 -0
  139. package/dist/run-files.js +3 -0
  140. package/dist/run-launch.d.ts +12 -1
  141. package/dist/run-launch.js +9 -10
  142. package/dist/run-learning-served.d.ts +4 -2
  143. package/dist/run-model-key.d.ts +8 -0
  144. package/dist/run-model-key.js +31 -1
  145. package/dist/run-reads-over-store.d.ts +24 -6
  146. package/dist/run-reads-over-store.js +67 -23
  147. package/dist/run-recordings.d.ts +5 -1
  148. package/dist/run-recordings.js +39 -14
  149. package/dist/run-timeline-served.d.ts +2 -0
  150. package/dist/run-timeline-served.js +2 -2
  151. package/dist/run-usage.d.ts +1 -0
  152. package/dist/run-view.d.ts +1 -2
  153. package/dist/run-view.js +2 -1
  154. package/dist/runnable.d.ts +10 -1
  155. package/dist/runnable.js +20 -8
  156. package/dist/runner/adapter-loop.d.ts +11 -0
  157. package/dist/runner/adapter-loop.js +58 -26
  158. package/dist/runner/adapter-run-spec.d.ts +55 -11
  159. package/dist/runner/adapter-run-spec.js +183 -52
  160. package/dist/runner/adapters/pi.js +25 -3
  161. package/dist/runner/beside.d.ts +9 -2
  162. package/dist/runner/beside.js +27 -9
  163. package/dist/runner/big-writes.js +1 -10
  164. package/dist/runner/claim-secrets.d.ts +27 -10
  165. package/dist/runner/claim-secrets.js +49 -22
  166. package/dist/runner/cli-run-spec.d.ts +6 -0
  167. package/dist/runner/cli-run-spec.js +97 -38
  168. package/dist/runner/computer-journal.d.ts +9 -1
  169. package/dist/runner/computer-journal.js +26 -0
  170. package/dist/runner/conformance/harness.js +1 -1
  171. package/dist/runner/feedback-round.js +3 -0
  172. package/dist/runner/harness-loops.d.ts +6 -5
  173. package/dist/runner/harness-loops.js +7 -7
  174. package/dist/runner/held.d.ts +24 -6
  175. package/dist/runner/journal-kinds.d.ts +5 -0
  176. package/dist/runner/journal-kinds.js +5 -0
  177. package/dist/runner/main.d.ts +11 -6
  178. package/dist/runner/main.js +19 -9
  179. package/dist/runner/mcp-claim.js +31 -3
  180. package/dist/runner/mcp-run.d.ts +9 -0
  181. package/dist/runner/mcp-run.js +11 -5
  182. package/dist/runner/model-route.d.ts +17 -0
  183. package/dist/runner/model-route.js +120 -2
  184. package/dist/runner/presence.d.ts +11 -1
  185. package/dist/runner/presence.js +7 -0
  186. package/dist/runner/reflect-hook.js +1 -1
  187. package/dist/runner/run-child-host.d.ts +22 -8
  188. package/dist/runner/run-child-host.js +128 -41
  189. package/dist/runner/run-child.js +5 -2
  190. package/dist/runner/runner.d.ts +17 -3
  191. package/dist/runner/runner.js +130 -34
  192. package/dist/runner/save-slots.js +2 -1
  193. package/dist/runner/store-port.d.ts +1 -1
  194. package/dist/runner/store-secrets.d.ts +6 -0
  195. package/dist/runner/store-secrets.js +49 -7
  196. package/dist/runner/subagent.d.ts +11 -0
  197. package/dist/runner/subagent.js +16 -38
  198. package/dist/runner/workflow-first.d.ts +35 -15
  199. package/dist/runner/workflow-first.js +38 -25
  200. package/dist/runner/workflow-spec.js +4 -3
  201. package/dist/runs-over-store.d.ts +15 -6
  202. package/dist/runs-over-store.js +33 -21
  203. package/dist/scrub-command.d.ts +73 -0
  204. package/dist/scrub-command.js +307 -0
  205. package/dist/secret-cut.d.ts +73 -0
  206. package/dist/secret-cut.js +291 -4
  207. package/dist/secret-rules.d.ts +143 -0
  208. package/dist/secret-rules.js +2564 -0
  209. package/dist/secrets.d.ts +7 -0
  210. package/dist/secrets.js +20 -0
  211. package/dist/server-keys.d.ts +20 -0
  212. package/dist/server-keys.js +25 -6
  213. package/dist/server.d.ts +65 -13
  214. package/dist/server.js +470 -157
  215. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  216. package/dist/slots.d.ts +9 -0
  217. package/dist/slots.js +45 -0
  218. package/dist/store/index.d.ts +1 -1
  219. package/dist/store/index.js +1 -1
  220. package/dist/store/journal/storage.js +1 -1
  221. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  222. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  223. package/dist/store/schema.d.ts +23 -0
  224. package/dist/store/schema.js +58 -2
  225. package/dist/store/seal.d.ts +6 -1
  226. package/dist/store/seal.js +5 -3
  227. package/dist/store/sqlite/run-launch.d.ts +9 -1
  228. package/dist/store/sqlite/run-launch.js +24 -13
  229. package/dist/store/sqlite/run-patch.d.ts +12 -2
  230. package/dist/store/sqlite/run-patch.js +42 -5
  231. package/dist/store/sqlite/store.js +105 -12
  232. package/dist/store/store.d.ts +57 -2
  233. package/dist/store/store.js +20 -0
  234. package/dist/store-reads/learning.d.ts +84 -124
  235. package/dist/store-reads/learning.js +210 -274
  236. package/dist/store-view.d.ts +3 -0
  237. package/dist/store-view.js +3 -3
  238. package/dist/suggestions.js +3 -2
  239. package/dist/template-eval.d.ts +39 -9
  240. package/dist/template-eval.js +191 -60
  241. package/dist/template-import.js +6 -2
  242. package/dist/templates.d.ts +10 -2
  243. package/dist/templates.js +28 -8
  244. package/dist/timeline/labels.d.ts +6 -4
  245. package/dist/timeline/labels.js +18 -6
  246. package/dist/timeline/timeline.d.ts +5 -0
  247. package/dist/timeline/timeline.js +14 -8
  248. package/dist/timeline/util.js +1 -1
  249. package/dist/timeline/web-calls.d.ts +22 -7
  250. package/dist/timeline/web-calls.js +106 -35
  251. package/dist/tool-gate.d.ts +42 -3
  252. package/dist/tool-gate.js +66 -5
  253. package/dist/tool-keys-store.d.ts +2 -4
  254. package/dist/tool-keys-store.js +5 -21
  255. package/dist/tool-keys.d.ts +2 -2
  256. package/dist/tool-keys.js +2 -2
  257. package/dist/tool-list.js +1 -1
  258. package/dist/tool-plane.d.ts +2 -2
  259. package/dist/tool-plane.js +35 -33
  260. package/dist/tools.js +13 -7
  261. package/dist/trigger-targets.d.ts +4 -0
  262. package/dist/trigger-targets.js +9 -2
  263. package/dist/triggers.d.ts +67 -4
  264. package/dist/triggers.js +171 -22
  265. package/dist/until.d.ts +3 -0
  266. package/dist/until.js +11 -0
  267. package/dist/web-fake.d.ts +1 -3
  268. package/dist/web-fake.js +7 -18
  269. package/dist/web-fetch.d.ts +6 -72
  270. package/dist/web-fetch.js +11 -265
  271. package/dist/web-run.d.ts +31 -0
  272. package/dist/web-run.js +90 -0
  273. package/dist/web-save.d.ts +10 -13
  274. package/dist/web-save.js +13 -55
  275. package/dist/web-search.d.ts +9 -127
  276. package/dist/web-search.js +23 -259
  277. package/dist/wires.d.ts +13 -0
  278. package/dist/wires.js +11 -0
  279. package/dist/workflow-run.d.ts +5 -4
  280. package/dist/workflow-run.js +5 -4
  281. package/dist/workspace/attached-computers.d.ts +32 -9
  282. package/dist/workspace/attached-computers.js +77 -13
  283. package/dist/workspace/computer-deps.d.ts +8 -2
  284. package/dist/workspace/computer-deps.js +10 -3
  285. package/dist/workspace/computer-for-claim.d.ts +12 -1
  286. package/dist/workspace/computer-for-claim.js +83 -11
  287. package/dist/workspace/computer-kept.d.ts +3 -0
  288. package/dist/workspace/computer-kept.js +11 -2
  289. package/dist/workspace/index.d.ts +1 -1
  290. package/dist/workspace/index.js +1 -1
  291. package/dist/workspace/kind-skills.d.ts +4 -0
  292. package/dist/workspace/kind-skills.js +9 -0
  293. package/dist/workspace/paired-route.d.ts +91 -0
  294. package/dist/workspace/paired-route.js +153 -0
  295. package/dist/workspace/synced-folder.js +3 -4
  296. package/dist/wrapped.d.ts +20 -6
  297. package/dist/wrapped.js +66 -25
  298. package/package.json +17 -11
  299. package/skills/agentrun-serve/SKILL.md +4 -0
  300. package/templates/README.md +32 -10
  301. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  302. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  303. package/dist/exa-keyless.d.ts +0 -34
  304. package/dist/exa-keyless.js +0 -118
  305. package/dist/firecrawl-keyless.d.ts +0 -41
  306. package/dist/firecrawl-keyless.js +0 -152
  307. package/dist/keyless-mcp.d.ts +0 -36
  308. package/dist/keyless-mcp.js +0 -127
  309. package/dist/text-urls.d.ts +0 -38
  310. package/dist/text-urls.js +0 -170
  311. package/dist/web-fetch-direct.d.ts +0 -119
  312. package/dist/web-fetch-direct.js +0 -190
@@ -21,6 +21,7 @@ import { decisionProvidersIn } from "../decisions.js";
21
21
  import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
22
22
  import { liveForRun, runnerLiveOf } from "../live-reach.js";
23
23
  import { llmTiers, nodeTiers, thinkingLevel, TIERS, tierModelOf, workflowNodes } from "../model.js";
24
+ import { heldRefusedProvider } from "../provider.js";
24
25
  import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
25
26
  import { learningStartOf, seedFailed } from "../run-launch.js";
26
27
  import { isWebHostTool } from "../tool-list.js";
@@ -31,6 +32,7 @@ import { ASK_TOOL, askPerson, toolOf } from "../tools.js";
31
32
  import { hostToolOf } from "../host-tools.js";
32
33
  import { WEB_SEARCH_TOOL } from "../web-search.js";
33
34
  import { webCut } from "../timeline/web-calls.js";
35
+ import { withheldWhole } from "../key-refusal.js";
34
36
  import { environmentLine, runZone } from "../environment.js";
35
37
  import { effortGuidance } from "../effort-guidance.js";
36
38
  import { outputContract } from "../answer-json.js";
@@ -42,6 +44,7 @@ import { learnedAskShown, LEARNED_WORKFLOW_TOOL, learnedMcpCalls, learnedWorkflo
42
44
  import { PORT_PROVIDER, tieredModels, tierProvider } from "../port-models.js";
43
45
  import { promptOf, readsFiles } from "../skills.js";
44
46
  import { openRunWorkspace } from "../workspace/run-workspace.js";
47
+ import { withoutKindSkill } from "../workspace/kind-skills.js";
45
48
  import { layOwnSkills } from "../workspace/revision-skills.js";
46
49
  import { COMPUTER_ROOT, recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
47
50
  import { runTools, withKindTools } from "../workspace/run-tools.js";
@@ -49,16 +52,16 @@ import { filesToCopy, placeRunInputs } from "../uploads.js";
49
52
  import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
50
53
  import { UNREADABLE_SIGN_IN } from "../run-view.js";
51
54
  import { durableWait } from "../workflow/pi-versions.js";
52
- import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
55
+ import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, subagentTierKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
53
56
  import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
54
57
  import { agreeOnOf } from "../learning-setting.js";
55
- import { catalogSessionNames, mcpWhereHeld } from "./mcp-run.js";
58
+ import { catalogSessionNames, claimMetering, mcpWhereHeld } from "./mcp-run.js";
56
59
  import { held as runnerSeam, heldOrThrow, heldSignInReads } from "./held.js";
57
60
  import { hostLifecycle } from "./adapter-loop.js";
58
61
  import { RUNNER_HARNESSES } from "./adapters/index.js";
59
62
  import { DEFAULT_HARNESS } from "../harness.js";
60
63
  import { agentEntriesOf } from "./loop.js";
61
- import { SUBAGENT_TIERS, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
64
+ import { routedSubagentTiers, SUBAGENT_TOOL, subagentTool } from "./subagent.js";
62
65
  import { ClaimRefused } from "./loop-contract.js";
63
66
  import { bookedSpend, cliRunMetrics, costBasisOf, endCostOf, runCostOf, runMetrics } from "./metrics.js";
64
67
  import { journalEntries } from "./journal-reader.js";
@@ -73,7 +76,7 @@ import { archilWhereHeld, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
73
76
  import { loadArchilSettings } from "../archil-settings.js";
74
77
  import { settingOfDefinition } from "../computer-setting.js";
75
78
  import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
76
- import { hadComputer } from "./computer-journal.js";
79
+ import { computerTurnedOff, hadComputer, recordComputerOff } from "./computer-journal.js";
77
80
  import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
78
81
  import { planBeforeRun, PLAN_PROVIDER } from "../chatgpt-plan.js";
79
82
  import { heldSpecOf } from "./held-run.js";
@@ -86,6 +89,7 @@ import { monidForClaim, withMonid } from "./monid-run.js";
86
89
  import { verifyPlacedProject, movedSkillFiles } from "../source-sync/claim.js";
87
90
  import { projectCheckpointForRun } from "./project-checkpoint.js";
88
91
  import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
92
+ import { routeTrace } from "../otel/genai.js";
89
93
  /** The wires pi speaks on the runner: main's pi's (provider.ts), Anthropic's Messages and OpenAI's Responses. */
90
94
  export const PI_WIRES = Object.freeze(["anthropic-messages", "openai-responses"]);
91
95
  /** The browser's catalog name (tools.ts TOOLS.browser). */
@@ -97,6 +101,22 @@ export const BROWSER_ON_RUNNER = true;
97
101
  * (host.browserComputer), fail closed: only on the native route (BROWSER_ON_RUNNER), and only with the run's ledger
98
102
  * booking on its ToolHost (host.ledger.paid), so no browser call is held on this process's own spend. */
99
103
  export const browserListed = (host, granted) => BROWSER_ON_RUNNER && host.ledger?.paid !== undefined && (granted.includes(BROWSER_TOOL) || host.browserComputer !== undefined);
104
+ /** A template eval case's files (EvalFakes.files) written into the run's work folder at its claim, after its inputs and
105
+ * before its computer and its first turn, so they reach a computer's /workspace as its uploads do. Each one the folder
106
+ * does not hold yet: a claim that resumes the run keeps what the run made of it. A write that fails ends the run failed,
107
+ * saying which file. */
108
+ export async function seedEvalFiles(workspace, files) {
109
+ for (const [path, text] of Object.entries(files ?? {})) {
110
+ if (await workspace.stat(path))
111
+ continue;
112
+ try {
113
+ await workspace.write(path, text);
114
+ }
115
+ catch (error) {
116
+ throw new Error(`The eval case's file ${path} could not be written in the run's work folder: ${error.message}`, { cause: error });
117
+ }
118
+ }
119
+ }
100
120
  /** A model as the cap prices it, from the route's catalog cost: its price WITH TIERS (the money rule — a request past a
101
121
  * model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
102
122
  * overhead its provider adds; the output ceiling is the route's when it carries one, else none. */
@@ -118,6 +138,21 @@ export function capModelOf(route) {
118
138
  // The cap reads a request's provider overhead by the route's own wire (providerInputOverhead).
119
139
  return { id: route.model, api: route.provider.api, price, outputCeiling: route.outputCeiling ?? null, ...(route.local ? { local: true } : {}) };
120
140
  }
141
+ /** The model of a held run its model kept from running at its create (run-launch.ts hold.refused): as its revision names
142
+ * it (`provider/model-id`). Its launch pins none (runs-over-store.ts skips modelOf for it). Nothing chooses it and
143
+ * nothing prices it. */
144
+ export function heldModelOf(ref) {
145
+ const at = ref?.indexOf("/") ?? -1;
146
+ return ref && at > 0 ? { provider: ref.slice(0, at), modelId: ref.slice(at + 1) } : { provider: "none", modelId: ref ?? "none" };
147
+ }
148
+ /** The route of a held run its model kept from running at its create (run-launch.ts hold.refused): its provider is the
149
+ * stand-in (provider.ts heldRefusedProvider), so a host with no key for its model still opens its claim and holds its
150
+ * computer. Its agent never starts (its start and every message are refused in `why`, its create's words:
151
+ * computer-held.ts), and a request that reached its proxy anyway is refused in them too, and never sent. */
152
+ export function heldRefusedRoute(model, why) {
153
+ const { origin, credential } = heldRefusedProvider(model, why);
154
+ return { model: model.modelId, named: `${model.provider}/${model.modelId}`, provider: { api: "anthropic-messages", origin, credential }, price: () => null, unpriced: true, outputCeiling: null };
155
+ }
121
156
  /** Particle requests are never automatically replayed after an uncertain failure. Retry is a harness-wide setting,
122
157
  * so a claim with any Particle route disables it for all its conversations, including subagents on other tiers. */
123
158
  export function modelRetryOf(routes) {
@@ -128,30 +163,63 @@ export function modelRetryOf(routes) {
128
163
  const SUBAGENT_ROUTE = "subagent-";
129
164
  const subagentRoute = (tier) => `${SUBAGENT_ROUTE}${tier}`;
130
165
  const isSubagentRoute = (key) => key.startsWith(SUBAGENT_ROUTE);
131
- /** A replay run's or an audit shadow's grader route (runner/compare-end.ts): its fast model (the revision's
132
- * modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
133
- * provider's than the run's own, whose key claimSecrets never opened: so its route reads every model key the server
134
- * holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone. A run with its
135
- * own model key carries that key, and no saved key is read. Undefined when there is no fast model, the revision names
136
- * agree_on, or no route can be made (logged: the pair is then compared whole). */
166
+ /** A model route as the run's GenAI trace names it: its provider, the host its requests go to, its model. A route that
167
+ * translates its model's requests (its own `fetch`) is named by its upstream's host (ModelRoute.upstreamOrigin), never
168
+ * its proxy's placeholder origin; one whose upstream is unknown names no host. */
169
+ export const traceOfRoute = (route) => {
170
+ const origin = route.fetch ? route.upstreamOrigin : route.provider.origin;
171
+ return routeTrace({ ...(route.named ? { named: route.named } : {}), ...(origin ? { origin } : {}), model: route.model });
172
+ };
173
+ /** A replay run's or an audit shadow's grader route (runner/compare-end.ts): on the fast tier routedSubagentTiers names
174
+ * (the revision's modelTiers.fast, else AGENT_MODEL_FAST), on pi's wires, when its revision names no agree_on. Its route
175
+ * reads the saved key of that tier's model alone (subagentTierKeys), held by the run's redactors, on the route's env
176
+ * alone; in a run's own process its runner hands it that tier's model's key (run-child-host.ts subagentTierKeys). A run
177
+ * with its own model key carries that key, and no saved key is read. Undefined, with nothing read, when
178
+ * there is no fast tier or the revision names agree_on; undefined when no route can be made (logged: the pair is then
179
+ * compared whole). */
137
180
  export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, holds = [cut], claim) {
138
181
  if (agreeOnOf(body.learning)?.length)
139
182
  return undefined;
140
- const savedKeys = keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
183
+ const { tiers, refs } = routedSubagentTiers(body, deps.env ?? {});
184
+ if (!tiers.includes("fast"))
185
+ return undefined;
186
+ const savedKeys = keyed ? {} : await subagentTierKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, ["fast"], refs);
141
187
  for (const redact of new Set(holds))
142
188
  holdClaimed(redact, savedKeys);
143
189
  // The claim's run, turn and attempt on its grader's requests too (request-metadata.ts): they spend on the run's cap.
144
- const env = claimModelEnv(deps.env, { ...savedKeys, ...claimed }, runKey, claim);
145
- if (body.modelTiers?.fast === undefined && tierModelOf(env, "fast") === undefined)
146
- return undefined;
190
+ const env = claimModelEnv(deps.env, [claimed, savedKeys], runKey, claim);
147
191
  try {
148
- return await deps.routeOf(body.modelTiers?.fast, env, "fast", PI_WIRES, undefined, cut);
192
+ return await deps.routeOf(refs.fast, env, "fast", PI_WIRES, undefined, cut);
149
193
  }
150
194
  catch (error) {
151
195
  log(`learning: no grader route (${error instanceof Error ? error.message : String(error)}): the answers are compared whole`);
152
196
  return undefined;
153
197
  }
154
198
  }
199
+ /** A subagent run's tier routes (runner/subagent.ts): each tier routedSubagentTiers names, on its model (the revision's
200
+ * modelTiers, else the host's tier variable), under its own key (subagentRoute), on a route of its own. A tier's model may
201
+ * be another provider's than the run's own, whose key claimSecrets never opened (it scopes the claim's keys to the run's
202
+ * model): so the routes read the saved model keys of those tiers' models alone (subagentTierKeys), held by the run's
203
+ * redactor, on the routes' env alone, never the run's tools (toolEnv). A run with its own model key carries that key,
204
+ * and no saved key is read. A tier no route can be made for here is in `why`, cut, and no failure of the run: a call on
205
+ * it answers why. */
206
+ export async function subagentTierRoutes(body, keyed, runKey, toolEnv, cut, deps, claim) {
207
+ const routes = new Map();
208
+ const why = new Map();
209
+ const { tiers, refs } = routedSubagentTiers(body, deps.env ?? {});
210
+ const savedKeys = keyed ? {} : await subagentTierKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, tiers, refs);
211
+ holdClaimed(cut, savedKeys);
212
+ const tierEnv = claimModelEnv(deps.env, [toolEnv, savedKeys], runKey, claim);
213
+ for (const tier of tiers) {
214
+ try {
215
+ routes.set(subagentRoute(tier), await deps.routeOf(refs[tier], tierEnv, tier, PI_WIRES, undefined, cut));
216
+ }
217
+ catch (error) {
218
+ why.set(tier, cut(error instanceof Error ? error.message : String(error)));
219
+ }
220
+ }
221
+ return { routes, why };
222
+ }
155
223
  /** What the runner routes a claimed run on: the launch's model as its start pinned it, sent as pinned, with the
156
224
  * revision's own ref beside it (main prices a gateway's id by the provider that ref names); the revision's ref alone
157
225
  * when the start pinned none. Never the pin's provider and id joined into a ref: a gateway refuses the joined id, and
@@ -169,6 +237,11 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
169
237
  // An MCP tool's effect as the run's pin marks it (ClaimMcp.effectOf): what "allow reads" lifts an ask by.
170
238
  const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}), facts: options.facts };
171
239
  const gate = runGate({ ...where, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
240
+ if (options.turnedOff)
241
+ gate.turnOff();
242
+ // Whether the run's journal has the computer off already (an earlier claim's, or this claim's first deny's): written once.
243
+ let offSaid = options.turnedOff === true;
244
+ const { onComputerOff } = options;
172
245
  // The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
173
246
  let learned = [];
174
247
  // The host the run's tools bind through, once the spec has made it (askedOn): a tool's own ask reads it.
@@ -198,9 +271,29 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
198
271
  asking.set(call.tool, turn.catch(() => undefined));
199
272
  return turn;
200
273
  };
274
+ // The computer off, written to the run's journal once. A write that fails (a fenced claim, a journal error) never fails
275
+ // the call, whose refusal stands: the claim's next refusal of the computer's tools writes it again.
276
+ const sayOff = async () => {
277
+ const turnedOff = offSaid ? undefined : gate.computerOff;
278
+ if (!turnedOff)
279
+ return;
280
+ offSaid = true;
281
+ try {
282
+ await onComputerOff?.(turnedOff);
283
+ }
284
+ catch {
285
+ offSaid = false;
286
+ }
287
+ };
201
288
  const decide = async (call, options = {}) => {
289
+ const off = gate.offRefusal(call.tool, options);
290
+ if (off) {
291
+ await sayOff();
292
+ return off;
293
+ }
202
294
  current = await storeSettings(store);
203
295
  const decision = await gate.decide(call.tool, call.args, options);
296
+ await sayOff();
204
297
  // A call its setting allows that its tool asks about itself (ToolEntry.asks: email_send past its cap, or to someone
205
298
  // outside the run's thread): put to a person with the tool's reason on its card, whatever the setting; where no one
206
299
  // can approve, refused in those words. No tool's name is read here: the reason is the tool's.
@@ -316,6 +409,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
316
409
  // the process started (run-child-host.ts), as the server's held uploads are never the run's to read.
317
410
  if (!(deps.sealKey === undefined && runnerSeam()))
318
411
  await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
412
+ // The run's template eval fakes (AdapterSpecDeps.evalFakes), read once: its files, its metered jobs' media and its tools.
413
+ const fakes = deps.evalFakes?.(runRow.agentId);
414
+ await seedEvalFiles(ws.workspace, fakes?.files);
319
415
  // The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
320
416
  // turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
321
417
  // there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
@@ -351,13 +447,16 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
351
447
  // words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
352
448
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
353
449
  const hold = (values) => cut.hold(values);
354
- const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => 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, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(runRow.agentId)?.web, slots: deps.saveSlots } });
450
+ const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => 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, ...claimMetering(deps, fakes?.web, launch) });
355
451
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
356
452
  holds.hold({ passed: mcp });
357
453
  // The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
358
454
  // Docker container for a sandbox, under the claim's epoch (the one fence). It throws computer_unavailable (nothing made)
359
455
  // when the computer cannot be had: the run fails in its words.
360
456
  const claimSignal = run.stopped ?? run.signal;
457
+ // An earlier claim's deny turned the run's computer off for the run (computerTurnedOff): this claim starts none, and
458
+ // ends the one a park kept, its mount with it, before the run's tools touch its folder (turnedOff).
459
+ const offAlready = await computerTurnedOff(deps.journal(claim), context);
361
460
  const computer = await deps.computerForClaim(
362
461
  // The runner holding the claim (its name, its presence incarnation): a computer a park keeps that only it can reach
363
462
  // again is pinned to it.
@@ -370,7 +469,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
370
469
  // claim's is a new one whatever ended the earlier claim (a lost runner, a server's stop, a park past its keep). The
371
470
  // computer a park kept, attached again, brings its mount credential with it (inheritMount): none is minted. A
372
471
  // recording of its screen (computer.record) goes in the run's recordings folder, beside its folder, said on its timeline.
373
- { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, 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() } : {}), ...(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, 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() } : {}), ...(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) } : {}) });
374
473
  // The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
375
474
  // (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
376
475
  // 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,
@@ -408,8 +507,13 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
408
507
  holdClaimed(cut, toolEnv);
409
508
  // The route reads its model's key from the runner's environment, else the one the claim opened from the store: a key
410
509
  // saved in Settings → Model keys runs the next run with no restart (withModelKeys). A run with its own key: that key.
411
- const modelEnv = claimModelEnv(deps.env, toolEnv, runKey, claim);
412
- const route = await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
510
+ const modelEnv = claimModelEnv(deps.env, [toolEnv], runKey, claim);
511
+ // A held run its model kept from running at its create is never routed (heldRefusedRoute): its model's route chooses no
512
+ // model and reads no key, so a key saved since runs a new run, never this one. Its claim lays only the keys any claim
513
+ // of the run lays (its tools', a key handed with it: claimSecrets lays it no model key), routes no subagent tier and
514
+ // takes no learning step (below).
515
+ const heldRefusal = launch.hold?.refused?.message;
516
+ const route = heldRefusal !== undefined ? heldRefusedRoute(heldModelOf(body.model), heldRefusal) : await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
413
517
  await planBeforeRun(modelEnv, route.provider.plan ? { provider: PLAN_PROVIDER } : undefined);
414
518
  // The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
415
519
  // lay chose the workflows, below): read when the session opens (pi.ts options.tiers), each on a proxy of its own.
@@ -429,28 +533,21 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
429
533
  // host's for the tier (AGENT_MODEL_FAST, AGENT_MODEL_STRONG), each on a route of its own (its proxy on the session's
430
534
  // booking, adapters/pi.ts tiers). A tier with neither is the agent's own model, as a learned workflow's node of it runs
431
535
  // on the run's. A tier no route can be made for here is no failure of the run: a call on it answers why. A tier's model may be another
432
- // provider's than the run's own, whose key claimSecrets never opened (it scopes the claim's keys to the run's model): so
433
- // its route reads every model key the server holds (savedModelKeys). Those reach the tier's proxy alone, as its
434
- // credential, never the run's tools (toolEnv).
536
+ // provider's than the run's own, whose key claimSecrets never opened: so its route reads the saved model keys of its
537
+ // tiers' models alone (subagentTierRoutes). Those reach the tier's proxy alone, as its credential, never the run's tools
538
+ // (toolEnv).
435
539
  // Each is in tierRoutes under its own key (subagentRoute: never a learned workflow's tier, whose nodes keep their own
436
540
  // routes and fallback), on a proxy of its own that names that key on each request, so the cap prices a child's
437
- // requests as that route books them.
541
+ // requests as that route books them. A held run its model kept from running routes none: its subagent's calls run on
542
+ // the stand-in, refused in its create's words.
438
543
  const tierWhy = new Map();
439
- if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL)) {
544
+ if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL) && heldRefusal === undefined) {
440
545
  // A run with its own model key: its subagents' models carry that key too, and no saved key is read.
441
- const savedKeys = keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
442
- holdClaimed(cut, savedKeys);
443
- const tierEnv = claimModelEnv(deps.env, { ...savedKeys, ...toolEnv }, runKey, claim);
444
- for (const tier of SUBAGENT_TIERS) {
445
- if (body.modelTiers?.[tier] === undefined && tierModelOf(tierEnv, tier) === undefined)
446
- continue;
447
- try {
448
- tierRoutes.set(subagentRoute(tier), await deps.routeOf(body.modelTiers?.[tier], tierEnv, tier, PI_WIRES, undefined, cut));
449
- }
450
- catch (error) {
451
- tierWhy.set(tier, cut(error instanceof Error ? error.message : String(error)));
452
- }
453
- }
546
+ const subagent = await subagentTierRoutes(body, keyed, runKey, toolEnv, cut, deps, claim);
547
+ for (const [key, at] of subagent.routes)
548
+ tierRoutes.set(key, at);
549
+ for (const [tier, why] of subagent.why)
550
+ tierWhy.set(tier, why);
454
551
  }
455
552
  // The run's adapter is its runner's (runner/adapters/index.ts RunnerHarness: pi's, or the one a harness module's entry
456
553
  // brings), made from the run's launch on its route. Its private files, where it keeps any, go in this claim's folder of
@@ -489,7 +586,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
489
586
  // A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's facts
490
587
  // are its entry's on the owner's table (factsOf): none for pi, nor for a module's harness on a runner of its own.
491
588
  const facts = factsOf(deps.env, revision.body.harness);
492
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts });
589
+ // The run's computer off for the run (its first deny's, this claim's or an earlier one's) is on the run's journal.
590
+ const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts, turnedOff: offAlready !== undefined, onComputerOff: (kind) => recordComputerOff(run.harness, kind) });
493
591
  // The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
494
592
  // uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
495
593
  // launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
@@ -543,14 +641,14 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
543
641
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
544
642
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
545
643
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
546
- // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
547
- // are skipped, in words, where the run brought its own key or the server holds none.
548
- const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
549
644
  const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
550
- const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff, admitAuxiliary };
645
+ // None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
646
+ const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff: await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey), admitAuxiliary } : undefined;
551
647
  // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
552
- // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
553
- const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff, admitAuxiliary }, seedLaid?.workflows ?? []);
648
+ // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
649
+ // running takes none of them: it settles no audit and starts no replay run, starts on no workflow, and its tool runs
650
+ // none (so no learned tier is routed, below).
651
+ 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, folder: learningFolder, shown, spendOff: audits.spendOff, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: {}, workflows: [] };
554
652
  const firstChoice = learned.choice;
555
653
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
556
654
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -568,7 +666,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
568
666
  // A run with its own model key: its learned nodes' tiers carry that key too, and no saved key is read.
569
667
  const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
570
668
  holdClaimed(cut, tierKeys);
571
- const tierEnv = claimModelEnv(deps.env, { ...toolEnv, ...tierKeys }, runKey, claim);
669
+ const tierEnv = claimModelEnv(deps.env, [tierKeys, toolEnv], runKey, claim);
572
670
  for (const [tier, routed] of await learnedTierRoutes(workflows, tierEnv, (tier) => deps.routeOf(undefined, tierEnv, tier, PI_WIRES, undefined, cut))) {
573
671
  if ("why" in routed)
574
672
  tierUnreachable.set(tier, routed.why);
@@ -580,8 +678,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
580
678
  underClaimed(toolEnv, learnedKeys);
581
679
  }
582
680
  // A replay run's or a shadow's grader (runner/compare-end.ts), on a route of its own beside the session's, on the
583
- // session's booking under the run's one cap. None: the pair is compared whole, in words saying so.
584
- const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, toolEnv, cut, log, deps, [cut], claim) : undefined;
681
+ // session's booking under the run's one cap. None: the pair is compared whole, in words saying so. None for a held run
682
+ // its model kept from running, whose model runs nowhere.
683
+ const graderRoute = (launch.replay || launch.audit) && heldRefusal === undefined ? await graderRouteOf(body, keyed, runKey, toolEnv, cut, log, deps, [cut], claim) : undefined;
585
684
  if (graderRoute)
586
685
  tierRoutes.set(GRADER, graderRoute);
587
686
  // The tool host's install lifecycle: what a binding registers to run in each conversation's creating commit, once the
@@ -597,7 +696,6 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
597
696
  // spec builds too), on the claim's keys and the run's one ledger and redactor.
598
697
  // An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
599
698
  const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
600
- const fakes = deps.evalFakes?.(runRow.agentId);
601
699
  const liveAt = await claimLiveAt(deps, claim.runId);
602
700
  const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}), ...(deps.saveSlots ? { saveSlots: deps.saveSlots } : {}) }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
603
701
  gate.askedOn(host);
@@ -624,7 +722,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
624
722
  // The one path for every harness.
625
723
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
626
724
  const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
627
- const instructions = await promptOf(laid, currentSkills, ws.workspace, { onDemand: movedProject || readsFiles(granted) });
725
+ // A computer the claim did not start (every tool of it set to deny: ClaimComputer.off) has its kind's skill named to no one.
726
+ const skills = computer.off ? withoutKindSkill(currentSkills, body.skills ?? {}, settingOfDefinition(body)?.computer.kind) : currentSkills;
727
+ const instructions = await promptOf(laid, skills, ws.workspace, { onDemand: movedProject || readsFiles(granted) });
628
728
  const guidance = effortGuidance(launch.effort);
629
729
  // The run's clock: a template eval case's (EvalFakes.now), else the real one.
630
730
  const now = fakes?.now;
@@ -681,7 +781,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
681
781
  // from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
682
782
  // A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
683
783
  // withAudit): at its end, so the shadow's cap is what the run's own left.
684
- const endOfRun = launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, folder: learningFolder, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
784
+ // A held run (no audits) takes none, and its runner refuses one too (run-child-host.ts heldFor).
785
+ const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, folder: learningFolder, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
685
786
  store: deps.store,
686
787
  data: deps.data,
687
788
  ...(deps.env ? { env: deps.env } : {}),
@@ -715,6 +816,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
715
816
  // The answer's schema: a miss is asked again once (adapter-loop.ts, the output contract's retry).
716
817
  ...(body.outputSchema !== undefined ? { outputSchema: body.outputSchema } : {}),
717
818
  ...(cap ? { cap } : {}),
819
+ // Its routes, as its GenAI trace names them (otel/genai.ts): the session's, and each tier's by its name.
820
+ trace: {
821
+ ...traceOfRoute(route),
822
+ routes: new Map([...tierRoutes].map(([tier, routed]) => [tier, traceOfRoute(routed)])),
823
+ },
718
824
  // The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
719
825
  // the catalog tools the session mounts; absent when none.
720
826
  ...(catalog ? { mcp: catalog } : {}),
@@ -926,14 +1032,28 @@ export function liveViewersOf(store, sealKey, claim, cut) {
926
1032
  }
927
1033
  /** `tool` with its answer's text, and a throw's message, cut by `cut` (the run's one redactor). A web call's answer is cut
928
1034
  * string by string inside its JSON (timeline/web-calls.ts webCut), so what the harness stores still parses and keeps
929
- * its links whole for a grader's link check. */
1035
+ * its links whole for a grader's link check; one whose strings, read joined, hold a held value no cut in place takes (a
1036
+ * value split across two of them) is "[redacted]" (webHeld). The join is read against the values `cut` holds
1037
+ * (key-refusal.ts withheldWhole), or through `cut` itself when it does not know them (joinCut). Each string is cut once
1038
+ * in a call, for the join's read and the answer both. */
930
1039
  export function answersCut(tool, cut) {
931
1040
  return {
932
1041
  ...tool,
933
1042
  call: async (args, context) => {
934
1043
  try {
935
1044
  const answer = await tool.call(args, context);
936
- return { ...answer, text: webCut(tool.name, answer.text, cut) ?? cut(answer.text) };
1045
+ const seen = new Map();
1046
+ const once = (text) => {
1047
+ let out = seen.get(text);
1048
+ if (out === undefined)
1049
+ seen.set(text, (out = cut(text)));
1050
+ return out;
1051
+ };
1052
+ const holds = (joined, parts) => {
1053
+ const values = cut.heldValues?.();
1054
+ return values ? withheldWhole(joined, values) : joinCut(joined, parts, once);
1055
+ };
1056
+ return { ...answer, text: webCut(tool.name, answer.text, once, holds) ?? cut(answer.text) };
937
1057
  }
938
1058
  catch (error) {
939
1059
  if (error instanceof Error) {
@@ -947,6 +1067,17 @@ export function answersCut(tool, cut) {
947
1067
  },
948
1068
  };
949
1069
  }
1070
+ /** Whether `cut`, a redactor that does not know its values, takes from `joined` (`parts` joined by line breaks) what it
1071
+ * does not take from the parts each read alone: a held value split across two parts. Its cut of the join whole being
1072
+ * "[redacted]" is not enough: it reads a text longer than a piece in pieces of 8,192 characters (key-refusal.ts
1073
+ * redactedAnswer), and a value split inside one piece withholds only that piece, the rest of the join served. It misses
1074
+ * nothing: no value split across parts is in a part to cut, so the join's cut and the parts' differ wherever the join
1075
+ * holds one; where nothing spans two parts they are the same, as every piece ends at whitespace or inside a run longer
1076
+ * than a piece, and a line break ends each part. */
1077
+ function joinCut(joined, parts, cut) {
1078
+ const whole = cut(joined);
1079
+ return whole === "[redacted]" || whole !== parts.map(cut).join("\n");
1080
+ }
950
1081
  /** The ToolHost a run's non-hand tools bind through, the one both the pi spec and the CLI spec build: the run's folder and
951
1082
  * the claim's environment (claim-secrets.ts: the run's keys from the store, its plane set), the run's registry for an
952
1083
  * extension a binding installs, the install lifecycle (`life`, run by the adapter loop from the spec's `lifecycle`), the
@@ -28,6 +28,28 @@ function recordingExtension(extension, keep) {
28
28
  })),
29
29
  };
30
30
  }
31
+ /** A pi-native tool (options.tools, an extension's: ask_person, subagent, the browser's) whose calls the session reports
32
+ * as piTool reports a host tool's: its start before it runs, its end (an error when it says so or throws) after, with no
33
+ * result text. A host tool is never one of these (piTool reports its own), so no call is reported twice. */
34
+ function announcing(tool, io) {
35
+ return {
36
+ ...tool,
37
+ execute: async (args, api, context) => {
38
+ io.onEvent({ type: "tool_start", callId: api.callId, name: tool.name, args });
39
+ let failed = true;
40
+ try {
41
+ const result = await tool.execute(args, api, context);
42
+ failed = Boolean(result?.isError);
43
+ return result;
44
+ }
45
+ finally {
46
+ io.onEvent({ type: "tool_end", callId: api.callId, name: tool.name, isError: failed });
47
+ }
48
+ },
49
+ };
50
+ }
51
+ /** `extension` with each of its tools announcing (announcing). */
52
+ const announcingExtension = (extension, io) => extension.tools?.length ? { ...extension, tools: extension.tools.map((tool) => announcing(tool, io)) } : extension;
31
53
  const PROVIDER = "agentrun-session";
32
54
  /** The input tokens pi (the @earendil-works/pi-* 1.5.2 packages serve pins) sends in a run's first model request before
33
55
  * the agent's own prompt: pi writes no system prompt of its own, so it is serve's (the environment line and the wrapper
@@ -269,7 +291,7 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
269
291
  const touched = new Set();
270
292
  // A refused nested call's words, by its id (pi's nested result keeps none of a refused call's output).
271
293
  const nestedRefusals = new Map();
272
- const tools = [...spec.tools.filter((tool) => !owned.has(tool.name)).map((tool) => piTool(tool, io, (callId) => (io.gate ? (passed.has(callId) ? 0 : 1) : undefined), touched, nestedRefusals)), ...(options.tools ?? [])];
294
+ const tools = [...spec.tools.filter((tool) => !owned.has(tool.name)).map((tool) => piTool(tool, io, (callId) => (io.gate ? (passed.has(callId) ? 0 : 1) : undefined), touched, nestedRefusals)), ...(options.tools ?? []).map((tool) => announcing(tool, io))];
273
295
  // A refused call's words (the gate's deny, main's), by call: its result is those words alone, as main gives them.
274
296
  const refusals = refusalWords();
275
297
  const extension = defineExtension({
@@ -327,8 +349,8 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
327
349
  });
328
350
  run.registry.install(extension);
329
351
  // The run's pi-native extensions (options.extensions), in the claim's registry beside the session's: each tool's computer
330
- // calls recorded on its row (io.keepCalls), as the loop records its host tools'.
331
- const native = (options.extensions ?? []).map((each) => (io.keepCalls ? recordingExtension(each, io.keepCalls) : each));
352
+ // calls recorded on its row (io.keepCalls), as the loop records its host tools', and each call's start and end reported.
353
+ const native = (options.extensions ?? []).map((each) => announcingExtension(io.keepCalls ? recordingExtension(each, io.keepCalls) : each, io));
332
354
  for (const each of native)
333
355
  run.registry.install(each);
334
356
  // The root conversation may exist already (the loop's session records live beside it, under it): its agent is set here,
@@ -29,11 +29,14 @@ export declare function besideStopping(server: {
29
29
  * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
30
30
  * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
31
31
  * too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
32
- * holds each paired computer's socket in this process, so a run here takes one. `dial`: the server's (Serve.dial), which
32
+ * holds each paired computer's socket in this process, so a run here takes one; with it `beside`, the name and
33
+ * incarnation the server gave this runner (Serve.beside), which it runs under and its run's route of a paired box names
34
+ * (dial-relay.ts pairedRelayOn over the server's hub), so a runner apart's take for another run is refused while the
35
+ * hold lasts and the server keeps the box in its hub. `dial`: the server's (Serve.dial), which
33
36
  * a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
34
37
  * and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
35
38
  * isolation a number past the helper's slots is refused rather than cut. */
36
- export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded }?: {
39
+ export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, beside, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded }?: {
37
40
  loops?: number;
38
41
  loopsTold?: boolean;
39
42
  drainMs?: number;
@@ -42,6 +45,10 @@ export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainM
42
45
  janitor?: boolean;
43
46
  ownProcesses?: boolean;
44
47
  hub?: import("@parcha/agentrun-computer").AttachHub;
48
+ beside?: {
49
+ readonly runner: string;
50
+ readonly incarnation: string;
51
+ };
45
52
  dial?: import("@parcha/agentrun-computer").HostedDial;
46
53
  mcpLoopback?: boolean;
47
54
  mcpOwn?: readonly string[];