@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.57

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 (296) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +228 -45
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +18 -5
  5. package/dist/adapters.js +23 -9
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-keys.d.ts +76 -0
  11. package/dist/api-keys.js +217 -0
  12. package/dist/api-only.d.ts +17 -5
  13. package/dist/api-only.js +36 -8
  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/calendar/tools.js +3 -2
  19. package/dist/chatgpt-plan.d.ts +28 -3
  20. package/dist/chatgpt-plan.js +182 -21
  21. package/dist/claude-login.d.ts +101 -14
  22. package/dist/claude-login.js +232 -49
  23. package/dist/claude-sign-in.d.ts +46 -0
  24. package/dist/claude-sign-in.js +93 -0
  25. package/dist/cli.js +63 -6
  26. package/dist/composio-made.d.ts +4 -0
  27. package/dist/composio-made.js +4 -0
  28. package/dist/composio-preset.d.ts +43 -2
  29. package/dist/composio-preset.js +92 -4
  30. package/dist/computer-held-routes.d.ts +5 -4
  31. package/dist/computer-held-routes.js +29 -8
  32. package/dist/computer-held.d.ts +6 -1
  33. package/dist/computer-held.js +14 -0
  34. package/dist/computer-record.js +4 -2
  35. package/dist/computer-viewer.js +4 -1
  36. package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
  37. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  38. package/dist/console/assets/index-okP-y8PK.js +747 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/decisions.d.ts +1 -1
  41. package/dist/decisions.js +1 -1
  42. package/dist/docker-host-addresses.d.ts +22 -11
  43. package/dist/docker-host-addresses.js +38 -26
  44. package/dist/env-switch.d.ts +10 -0
  45. package/dist/env-switch.js +33 -2
  46. package/dist/errors.d.ts +1 -0
  47. package/dist/errors.js +2 -0
  48. package/dist/fal-price.d.ts +58 -20
  49. package/dist/fal-price.js +341 -82
  50. package/dist/handed-values.d.ts +43 -1
  51. package/dist/handed-values.js +119 -2
  52. package/dist/harness-archive.d.ts +13 -10
  53. package/dist/harness-archive.js +60 -34
  54. package/dist/harness-check.d.ts +3 -1
  55. package/dist/harness-check.js +25 -46
  56. package/dist/harness-keys.d.ts +73 -27
  57. package/dist/harness-keys.js +194 -61
  58. package/dist/harness-recipe-entry.d.ts +8 -7
  59. package/dist/harness-recipe-entry.js +21 -32
  60. package/dist/harness-recipe.d.ts +38 -25
  61. package/dist/harness-recipe.js +49 -36
  62. package/dist/harness-sign-in.js +12 -23
  63. package/dist/harness-table.d.ts +10 -3
  64. package/dist/harness-table.js +26 -21
  65. package/dist/harness.d.ts +1 -0
  66. package/dist/harness.js +17 -5
  67. package/dist/host-check.d.ts +4 -0
  68. package/dist/host-check.js +4 -0
  69. package/dist/hosted-search.d.ts +1 -1
  70. package/dist/hosted-search.js +1 -2
  71. package/dist/import-worker.d.ts +4 -2
  72. package/dist/import-worker.js +9 -2
  73. package/dist/in-flight.d.ts +26 -0
  74. package/dist/in-flight.js +52 -0
  75. package/dist/key-refusal.d.ts +26 -5
  76. package/dist/key-refusal.js +313 -37
  77. package/dist/learn/secrets.d.ts +31 -11
  78. package/dist/learn/secrets.js +152 -191
  79. package/dist/learning-cost.d.ts +6 -3
  80. package/dist/learning-cost.js +4 -2
  81. package/dist/link-check.js +1 -1
  82. package/dist/llms.txt +2 -2
  83. package/dist/marketplace.d.ts +77 -0
  84. package/dist/marketplace.js +224 -0
  85. package/dist/mcp-api-only-origins.d.ts +30 -0
  86. package/dist/mcp-api-only-origins.js +57 -0
  87. package/dist/mcp-gateway.d.ts +7 -5
  88. package/dist/mcp-gateway.js +9 -12
  89. package/dist/mcp-secret-writes.js +5 -3
  90. package/dist/mcp-servers-store.d.ts +28 -6
  91. package/dist/mcp-servers-store.js +53 -4
  92. package/dist/media-duration.d.ts +3 -0
  93. package/dist/media-duration.js +90 -9
  94. package/dist/model-form.d.ts +5 -4
  95. package/dist/model-form.js +11 -7
  96. package/dist/model.d.ts +5 -2
  97. package/dist/model.js +9 -5
  98. package/dist/ollama-provider.d.ts +7 -1
  99. package/dist/ollama-provider.js +14 -2
  100. package/dist/openapi.d.ts +3 -3
  101. package/dist/openapi.js +245 -42
  102. package/dist/otel/genai.d.ts +65 -0
  103. package/dist/otel/genai.js +116 -0
  104. package/dist/otel/tracer.d.ts +55 -0
  105. package/dist/otel/tracer.js +308 -0
  106. package/dist/page.d.ts +2 -0
  107. package/dist/page.js +3 -1
  108. package/dist/paid-calls.d.ts +1 -32
  109. package/dist/paid-calls.js +4 -39
  110. package/dist/place-offers.d.ts +14 -6
  111. package/dist/place-offers.js +26 -13
  112. package/dist/provider.d.ts +9 -0
  113. package/dist/provider.js +50 -3
  114. package/dist/redact/match.d.ts +101 -0
  115. package/dist/redact/match.js +1152 -0
  116. package/dist/refusal-words.d.ts +11 -0
  117. package/dist/refusal-words.js +11 -0
  118. package/dist/run-census.d.ts +67 -0
  119. package/dist/run-census.js +240 -0
  120. package/dist/run-computer.d.ts +6 -3
  121. package/dist/run-computer.js +4 -1
  122. package/dist/run-cut.d.ts +15 -6
  123. package/dist/run-cut.js +30 -9
  124. package/dist/run-files.d.ts +3 -0
  125. package/dist/run-files.js +3 -0
  126. package/dist/run-launch.d.ts +12 -1
  127. package/dist/run-launch.js +9 -10
  128. package/dist/run-learning-served.d.ts +2 -0
  129. package/dist/run-model-key.d.ts +8 -0
  130. package/dist/run-model-key.js +31 -1
  131. package/dist/run-reads-over-store.d.ts +24 -6
  132. package/dist/run-reads-over-store.js +67 -23
  133. package/dist/run-recordings.d.ts +5 -1
  134. package/dist/run-recordings.js +39 -14
  135. package/dist/run-timeline-served.d.ts +3 -1
  136. package/dist/run-timeline-served.js +4 -4
  137. package/dist/run-usage.d.ts +1 -0
  138. package/dist/runnable.d.ts +10 -1
  139. package/dist/runnable.js +20 -8
  140. package/dist/runner/adapter-loop.d.ts +14 -0
  141. package/dist/runner/adapter-loop.js +56 -11
  142. package/dist/runner/adapter-run-spec.d.ts +45 -8
  143. package/dist/runner/adapter-run-spec.js +154 -29
  144. package/dist/runner/adapters/pi.js +25 -3
  145. package/dist/runner/beside.js +11 -6
  146. package/dist/runner/big-writes.js +1 -10
  147. package/dist/runner/claim-secrets.d.ts +18 -3
  148. package/dist/runner/claim-secrets.js +35 -6
  149. package/dist/runner/cli-run-spec.d.ts +6 -0
  150. package/dist/runner/cli-run-spec.js +85 -36
  151. package/dist/runner/computer-journal.d.ts +9 -1
  152. package/dist/runner/computer-journal.js +26 -0
  153. package/dist/runner/conformance/harness.js +1 -1
  154. package/dist/runner/feedback-round.js +3 -0
  155. package/dist/runner/harness-loops.d.ts +6 -5
  156. package/dist/runner/harness-loops.js +7 -7
  157. package/dist/runner/held.d.ts +11 -5
  158. package/dist/runner/journal-kinds.d.ts +5 -0
  159. package/dist/runner/journal-kinds.js +5 -0
  160. package/dist/runner/loop-contract.d.ts +4 -0
  161. package/dist/runner/main.js +15 -6
  162. package/dist/runner/mcp-claim.js +30 -3
  163. package/dist/runner/mcp-run.d.ts +12 -0
  164. package/dist/runner/mcp-run.js +12 -5
  165. package/dist/runner/model-route.d.ts +17 -0
  166. package/dist/runner/model-route.js +120 -2
  167. package/dist/runner/presence.d.ts +4 -3
  168. package/dist/runner/presence.js +4 -2
  169. package/dist/runner/run-child-host.d.ts +5 -0
  170. package/dist/runner/run-child-host.js +71 -30
  171. package/dist/runner/run-child.js +5 -2
  172. package/dist/runner/runner.d.ts +18 -3
  173. package/dist/runner/runner.js +162 -36
  174. package/dist/runner/store-port.d.ts +1 -1
  175. package/dist/runner/store-secrets.d.ts +6 -0
  176. package/dist/runner/store-secrets.js +49 -7
  177. package/dist/runner/subagent.js +4 -40
  178. package/dist/runner/workflow-first.d.ts +11 -4
  179. package/dist/runner/workflow-first.js +14 -8
  180. package/dist/runner/workflow-spec.js +3 -2
  181. package/dist/runs-over-store.d.ts +15 -6
  182. package/dist/runs-over-store.js +33 -21
  183. package/dist/scrub-command.d.ts +73 -0
  184. package/dist/scrub-command.js +307 -0
  185. package/dist/secret-cut.d.ts +73 -0
  186. package/dist/secret-cut.js +291 -4
  187. package/dist/secret-rules.d.ts +143 -0
  188. package/dist/secret-rules.js +2564 -0
  189. package/dist/secrets.d.ts +7 -0
  190. package/dist/secrets.js +20 -0
  191. package/dist/server-keys.d.ts +20 -0
  192. package/dist/server-keys.js +25 -6
  193. package/dist/server.d.ts +57 -13
  194. package/dist/server.js +371 -113
  195. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  196. package/dist/store/dialect.d.ts +3 -0
  197. package/dist/store/dialect.js +1 -0
  198. package/dist/store/index.d.ts +1 -1
  199. package/dist/store/index.js +1 -1
  200. package/dist/store/journal/storage.js +1 -1
  201. package/dist/store/postgres/dialect.js +3 -0
  202. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  203. package/dist/store/schema.d.ts +6 -0
  204. package/dist/store/schema.js +11 -1
  205. package/dist/store/seal.d.ts +6 -1
  206. package/dist/store/seal.js +5 -3
  207. package/dist/store/sqlite/run-launch.d.ts +9 -1
  208. package/dist/store/sqlite/run-launch.js +24 -13
  209. package/dist/store/sqlite/run-patch.d.ts +1 -1
  210. package/dist/store/sqlite/run-patch.js +13 -4
  211. package/dist/store/sqlite/store.js +76 -16
  212. package/dist/store/store.d.ts +53 -3
  213. package/dist/store/store.js +27 -0
  214. package/dist/store-reads/learning.d.ts +6 -3
  215. package/dist/store-reads/learning.js +22 -7
  216. package/dist/store-view.d.ts +3 -0
  217. package/dist/store-view.js +4 -4
  218. package/dist/suggestions.js +3 -2
  219. package/dist/template-eval.d.ts +22 -11
  220. package/dist/template-eval.js +124 -41
  221. package/dist/template-import.d.ts +10 -0
  222. package/dist/template-import.js +16 -7
  223. package/dist/templates.d.ts +10 -2
  224. package/dist/templates.js +28 -8
  225. package/dist/timeline/index.d.ts +1 -1
  226. package/dist/timeline/index.js +1 -1
  227. package/dist/timeline/labels.d.ts +6 -4
  228. package/dist/timeline/labels.js +18 -6
  229. package/dist/timeline/timeline.d.ts +17 -7
  230. package/dist/timeline/timeline.js +28 -14
  231. package/dist/timeline/util.js +1 -1
  232. package/dist/timeline/web-calls.d.ts +26 -9
  233. package/dist/timeline/web-calls.js +124 -37
  234. package/dist/tool-gate.d.ts +42 -3
  235. package/dist/tool-gate.js +69 -6
  236. package/dist/tool-keys-store.d.ts +2 -4
  237. package/dist/tool-keys-store.js +5 -21
  238. package/dist/tool-keys.d.ts +2 -2
  239. package/dist/tool-keys.js +2 -2
  240. package/dist/tool-list.js +1 -1
  241. package/dist/tool-plane.d.ts +2 -2
  242. package/dist/tool-plane.js +35 -33
  243. package/dist/tools.js +13 -7
  244. package/dist/trigger-targets.d.ts +4 -0
  245. package/dist/trigger-targets.js +9 -2
  246. package/dist/triggers.d.ts +67 -4
  247. package/dist/triggers.js +171 -22
  248. package/dist/until.d.ts +3 -0
  249. package/dist/until.js +11 -0
  250. package/dist/validate.js +1 -1
  251. package/dist/web-fake.d.ts +1 -3
  252. package/dist/web-fake.js +7 -18
  253. package/dist/web-fetch.d.ts +6 -72
  254. package/dist/web-fetch.js +11 -265
  255. package/dist/web-run.d.ts +31 -0
  256. package/dist/web-run.js +90 -0
  257. package/dist/web-save.d.ts +6 -4
  258. package/dist/web-save.js +9 -12
  259. package/dist/web-search.d.ts +9 -127
  260. package/dist/web-search.js +23 -259
  261. package/dist/wires.d.ts +13 -0
  262. package/dist/wires.js +11 -0
  263. package/dist/workflow-run.d.ts +5 -4
  264. package/dist/workflow-run.js +5 -4
  265. package/dist/workspace/computer-deps.d.ts +3 -1
  266. package/dist/workspace/computer-deps.js +12 -4
  267. package/dist/workspace/computer-for-claim.d.ts +19 -2
  268. package/dist/workspace/computer-for-claim.js +101 -13
  269. package/dist/workspace/computer-janitor.d.ts +15 -7
  270. package/dist/workspace/computer-janitor.js +33 -8
  271. package/dist/workspace/computer-kept.d.ts +55 -4
  272. package/dist/workspace/computer-kept.js +129 -8
  273. package/dist/workspace/index.d.ts +1 -1
  274. package/dist/workspace/index.js +1 -1
  275. package/dist/workspace/kind-skills.d.ts +4 -0
  276. package/dist/workspace/kind-skills.js +9 -0
  277. package/dist/workspace/run-end-computers.d.ts +5 -1
  278. package/dist/workspace/run-end-computers.js +27 -1
  279. package/dist/workspace/synced-folder.js +3 -4
  280. package/dist/wrapped.d.ts +65 -0
  281. package/dist/wrapped.js +77 -0
  282. package/package.json +17 -11
  283. package/skills/agentrun-serve/SKILL.md +4 -0
  284. package/templates/README.md +38 -15
  285. package/dist/console/assets/index-DUYLaqiR.js +0 -746
  286. package/dist/console/assets/index-DYhU4adm.css +0 -1
  287. package/dist/exa-keyless.d.ts +0 -34
  288. package/dist/exa-keyless.js +0 -118
  289. package/dist/firecrawl-keyless.d.ts +0 -41
  290. package/dist/firecrawl-keyless.js +0 -152
  291. package/dist/keyless-mcp.d.ts +0 -36
  292. package/dist/keyless-mcp.js +0 -127
  293. package/dist/text-urls.d.ts +0 -38
  294. package/dist/text-urls.js +0 -170
  295. package/dist/web-fetch-direct.d.ts +0 -119
  296. 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,10 +52,10 @@ 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, keysOver, learnedDecisionKeys, savedModelKeys, 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";
@@ -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,12 +163,27 @@ 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);
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
+ /** The model a replay run's or an audit shadow's grader runs on (graderRouteOf): the revision's modelTiers.fast, else
174
+ * `env`'s fast tier (AGENT_MODEL_FAST); undefined when there is neither, or the revision names agree_on (no grader). */
175
+ export function graderModelOf(body, env) {
176
+ if (agreeOnOf(body.learning)?.length)
177
+ return undefined;
178
+ return body.modelTiers?.fast ?? tierModelOf(env, "fast");
179
+ }
131
180
  /** A replay run's or an audit shadow's grader route (runner/compare-end.ts): its fast model (the revision's
132
181
  * modelTiers.fast, else AGENT_MODEL_FAST) when its revision names no agree_on, on pi's wires. A fast model may be another
133
182
  * 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). */
183
+ * holds (savedModelKeys) as a subagent's tier does, held by the run's redactor, on the route's env alone; in a run's own
184
+ * process its runner hands it the fast model's provider's keys alone (run-child-host.ts savedModelKeys, graderModelOf). A
185
+ * run with its own model key carries that key, and no saved key is read. Undefined when there is no fast model, the
186
+ * revision names agree_on, or no route can be made (logged: the pair is then compared whole). */
137
187
  export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, holds = [cut], claim) {
138
188
  if (agreeOnOf(body.learning)?.length)
139
189
  return undefined;
@@ -141,8 +191,9 @@ export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps
141
191
  for (const redact of new Set(holds))
142
192
  holdClaimed(redact, savedKeys);
143
193
  // 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)
194
+ // keysOver, never a spread: the claim's model keys are not enumerable (claimSecrets).
195
+ const env = claimModelEnv(deps.env, keysOver(savedKeys, claimed), runKey, claim);
196
+ if (graderModelOf(body, env) === undefined)
146
197
  return undefined;
147
198
  try {
148
199
  return await deps.routeOf(body.modelTiers?.fast, env, "fast", PI_WIRES, undefined, cut);
@@ -169,6 +220,11 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
169
220
  // An MCP tool's effect as the run's pin marks it (ClaimMcp.effectOf): what "allow reads" lifts an ask by.
170
221
  const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}), facts: options.facts };
171
222
  const gate = runGate({ ...where, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
223
+ if (options.turnedOff)
224
+ gate.turnOff();
225
+ // Whether the run's journal has the computer off already (an earlier claim's, or this claim's first deny's): written once.
226
+ let offSaid = options.turnedOff === true;
227
+ const { onComputerOff } = options;
172
228
  // The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
173
229
  let learned = [];
174
230
  // The host the run's tools bind through, once the spec has made it (askedOn): a tool's own ask reads it.
@@ -198,9 +254,29 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
198
254
  asking.set(call.tool, turn.catch(() => undefined));
199
255
  return turn;
200
256
  };
257
+ // The computer off, written to the run's journal once. A write that fails (a fenced claim, a journal error) never fails
258
+ // the call, whose refusal stands: the claim's next refusal of the computer's tools writes it again.
259
+ const sayOff = async () => {
260
+ const turnedOff = offSaid ? undefined : gate.computerOff;
261
+ if (!turnedOff)
262
+ return;
263
+ offSaid = true;
264
+ try {
265
+ await onComputerOff?.(turnedOff);
266
+ }
267
+ catch {
268
+ offSaid = false;
269
+ }
270
+ };
201
271
  const decide = async (call, options = {}) => {
272
+ const off = gate.offRefusal(call.tool, options);
273
+ if (off) {
274
+ await sayOff();
275
+ return off;
276
+ }
202
277
  current = await storeSettings(store);
203
278
  const decision = await gate.decide(call.tool, call.args, options);
279
+ await sayOff();
204
280
  // A call its setting allows that its tool asks about itself (ToolEntry.asks: email_send past its cap, or to someone
205
281
  // outside the run's thread): put to a person with the tool's reason on its card, whatever the setting; where no one
206
282
  // can approve, refused in those words. No tool's name is read here: the reason is the tool's.
@@ -316,6 +392,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
316
392
  // the process started (run-child-host.ts), as the server's held uploads are never the run's to read.
317
393
  if (!(deps.sealKey === undefined && runnerSeam()))
318
394
  await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
395
+ await seedEvalFiles(ws.workspace, deps.evalFakes?.(runRow.agentId)?.files);
319
396
  // The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
320
397
  // 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
398
  // there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
@@ -351,14 +428,20 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
351
428
  // words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
352
429
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
353
430
  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 } });
431
+ 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, runRow.agentId, launch) });
355
432
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
356
433
  holds.hold({ passed: mcp });
357
434
  // The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
358
435
  // Docker container for a sandbox, under the claim's epoch (the one fence). It throws computer_unavailable (nothing made)
359
436
  // when the computer cannot be had: the run fails in its words.
360
437
  const claimSignal = run.stopped ?? run.signal;
361
- const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place }, deps.store,
438
+ // An earlier claim's deny turned the run's computer off for the run (computerTurnedOff): this claim starts none, and
439
+ // ends the one a park kept, its mount with it, before the run's tools touch its folder (turnedOff).
440
+ const offAlready = await computerTurnedOff(deps.journal(claim), context);
441
+ const computer = await deps.computerForClaim(
442
+ // The runner holding the claim (its name, its presence incarnation): a computer a park keeps that only it can reach
443
+ // again is pinned to it.
444
+ { runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(run.incarnation ? { holder: { runner: claim.runner, incarnation: run.incarnation } } : {}) }, deps.store,
362
445
  // revokeMount removes the run's Archil mount credential when the computer is released (and if a start fails after a mint);
363
446
  // the run's end revokes it too (below), so it goes on every outcome even when no computer is made. Idempotent. What
364
447
  // became of the agent's own computer (a persistent setting) is said on the run's timeline.
@@ -367,7 +450,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
367
450
  // claim's is a new one whatever ended the earlier claim (a lost runner, a server's stop, a park past its keep). The
368
451
  // computer a park kept, attached again, brings its mount credential with it (inheritMount): none is minted. A
369
452
  // recording of its screen (computer.record) goes in the run's recordings folder, beside its folder, said on its timeline.
370
- { ...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) } : {}) });
453
+ { ...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) } : {}) });
371
454
  // The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
372
455
  // (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
373
456
  // 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,
@@ -406,7 +489,12 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
406
489
  // The route reads its model's key from the runner's environment, else the one the claim opened from the store: a key
407
490
  // saved in Settings → Model keys runs the next run with no restart (withModelKeys). A run with its own key: that key.
408
491
  const modelEnv = claimModelEnv(deps.env, toolEnv, runKey, claim);
409
- const route = await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
492
+ // A held run its model kept from running at its create is never routed (heldRefusedRoute): its model's route chooses no
493
+ // 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
494
+ // of the run lays (its tools', a key handed with it: claimSecrets lays it no model key), routes no subagent tier and
495
+ // takes no learning step (below).
496
+ const heldRefusal = launch.hold?.refused?.message;
497
+ const route = heldRefusal !== undefined ? heldRefusedRoute(heldModelOf(body.model), heldRefusal) : await deps.routeOf(modelAskOf(launch.model, body.model), modelEnv, "default", PI_WIRES, undefined, cut);
410
498
  await planBeforeRun(modelEnv, route.provider.plan ? { provider: PLAN_PROVIDER } : undefined);
411
499
  // The run's models of other tiers, for its learned workflows' nodes of a tier (learnedTierRoutes, filled once the seed's
412
500
  // lay chose the workflows, below): read when the session opens (pi.ts options.tiers), each on a proxy of its own.
@@ -431,13 +519,14 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
431
519
  // credential, never the run's tools (toolEnv).
432
520
  // Each is in tierRoutes under its own key (subagentRoute: never a learned workflow's tier, whose nodes keep their own
433
521
  // routes and fallback), on a proxy of its own that names that key on each request, so the cap prices a child's
434
- // requests as that route books them.
522
+ // requests as that route books them. A held run its model kept from running routes none: its subagent's calls run on
523
+ // the stand-in, refused in its create's words.
435
524
  const tierWhy = new Map();
436
- if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL)) {
525
+ if (revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL) && heldRefusal === undefined) {
437
526
  // A run with its own model key: its subagents' models carry that key too, and no saved key is read.
438
527
  const savedKeys = keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env });
439
528
  holdClaimed(cut, savedKeys);
440
- const tierEnv = claimModelEnv(deps.env, { ...savedKeys, ...toolEnv }, runKey, claim);
529
+ const tierEnv = claimModelEnv(deps.env, keysOver(savedKeys, toolEnv), runKey, claim);
441
530
  for (const tier of SUBAGENT_TIERS) {
442
531
  if (body.modelTiers?.[tier] === undefined && tierModelOf(tierEnv, tier) === undefined)
443
532
  continue;
@@ -486,7 +575,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
486
575
  // A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's facts
487
576
  // 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.
488
577
  const facts = factsOf(deps.env, revision.body.harness);
489
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts });
578
+ // 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.
579
+ 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) });
490
580
  // The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
491
581
  // uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
492
582
  // launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
@@ -540,14 +630,14 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
540
630
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
541
631
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
542
632
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
543
- // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
544
- // are skipped, in words, where the run brought its own key or the server holds none.
545
- const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
546
633
  const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
547
- const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff, admitAuxiliary };
634
+ // None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
635
+ 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;
548
636
  // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
549
- // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
550
- 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 ?? []);
637
+ // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
638
+ // running takes none of them: it settles no audit and starts no replay run, starts on no workflow, and its tool runs
639
+ // none (so no learned tier is routed, below).
640
+ 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: [] };
551
641
  const firstChoice = learned.choice;
552
642
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
553
643
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -565,7 +655,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
565
655
  // A run with its own model key: its learned nodes' tiers carry that key too, and no saved key is read.
566
656
  const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
567
657
  holdClaimed(cut, tierKeys);
568
- const tierEnv = claimModelEnv(deps.env, { ...toolEnv, ...tierKeys }, runKey, claim);
658
+ const tierEnv = claimModelEnv(deps.env, keysOver(toolEnv, tierKeys), runKey, claim);
569
659
  for (const [tier, routed] of await learnedTierRoutes(workflows, tierEnv, (tier) => deps.routeOf(undefined, tierEnv, tier, PI_WIRES, undefined, cut))) {
570
660
  if ("why" in routed)
571
661
  tierUnreachable.set(tier, routed.why);
@@ -577,8 +667,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
577
667
  underClaimed(toolEnv, learnedKeys);
578
668
  }
579
669
  // 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
580
- // session's booking under the run's one cap. None: the pair is compared whole, in words saying so.
581
- const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, toolEnv, cut, log, deps, [cut], claim) : undefined;
670
+ // session's booking under the run's one cap. None: the pair is compared whole, in words saying so. None for a held run
671
+ // its model kept from running, whose model runs nowhere.
672
+ const graderRoute = (launch.replay || launch.audit) && heldRefusal === undefined ? await graderRouteOf(body, keyed, runKey, toolEnv, cut, log, deps, [cut], claim) : undefined;
582
673
  if (graderRoute)
583
674
  tierRoutes.set(GRADER, graderRoute);
584
675
  // The tool host's install lifecycle: what a binding registers to run in each conversation's creating commit, once the
@@ -621,7 +712,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
621
712
  // The one path for every harness.
622
713
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
623
714
  const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
624
- const instructions = await promptOf(laid, currentSkills, ws.workspace, { onDemand: movedProject || readsFiles(granted) });
715
+ // 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.
716
+ const skills = computer.off ? withoutKindSkill(currentSkills, body.skills ?? {}, settingOfDefinition(body)?.computer.kind) : currentSkills;
717
+ const instructions = await promptOf(laid, skills, ws.workspace, { onDemand: movedProject || readsFiles(granted) });
625
718
  const guidance = effortGuidance(launch.effort);
626
719
  // The run's clock: a template eval case's (EvalFakes.now), else the real one.
627
720
  const now = fakes?.now;
@@ -678,7 +771,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
678
771
  // from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
679
772
  // A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
680
773
  // withAudit): at its end, so the shadow's cap is what the run's own left.
681
- 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, {
774
+ // A held run (no audits) takes none, and its runner refuses one too (run-child-host.ts heldFor).
775
+ 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, {
682
776
  store: deps.store,
683
777
  data: deps.data,
684
778
  ...(deps.env ? { env: deps.env } : {}),
@@ -712,6 +806,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
712
806
  // The answer's schema: a miss is asked again once (adapter-loop.ts, the output contract's retry).
713
807
  ...(body.outputSchema !== undefined ? { outputSchema: body.outputSchema } : {}),
714
808
  ...(cap ? { cap } : {}),
809
+ // Its routes, as its GenAI trace names them (otel/genai.ts): the session's, and each tier's by its name.
810
+ trace: {
811
+ ...traceOfRoute(route),
812
+ routes: new Map([...tierRoutes].map(([tier, routed]) => [tier, traceOfRoute(routed)])),
813
+ },
715
814
  // The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
716
815
  // the catalog tools the session mounts; absent when none.
717
816
  ...(catalog ? { mcp: catalog } : {}),
@@ -923,14 +1022,28 @@ export function liveViewersOf(store, sealKey, claim, cut) {
923
1022
  }
924
1023
  /** `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
925
1024
  * string by string inside its JSON (timeline/web-calls.ts webCut), so what the harness stores still parses and keeps
926
- * its links whole for a grader's link check. */
1025
+ * its links whole for a grader's link check; one whose strings, read joined, hold a held value no cut in place takes (a
1026
+ * value split across two of them) is "[redacted]" (webHeld). The join is read against the values `cut` holds
1027
+ * (key-refusal.ts withheldWhole), or through `cut` itself when it does not know them (joinCut). Each string is cut once
1028
+ * in a call, for the join's read and the answer both. */
927
1029
  export function answersCut(tool, cut) {
928
1030
  return {
929
1031
  ...tool,
930
1032
  call: async (args, context) => {
931
1033
  try {
932
1034
  const answer = await tool.call(args, context);
933
- return { ...answer, text: webCut(tool.name, answer.text, cut) ?? cut(answer.text) };
1035
+ const seen = new Map();
1036
+ const once = (text) => {
1037
+ let out = seen.get(text);
1038
+ if (out === undefined)
1039
+ seen.set(text, (out = cut(text)));
1040
+ return out;
1041
+ };
1042
+ const holds = (joined, parts) => {
1043
+ const values = cut.heldValues?.();
1044
+ return values ? withheldWhole(joined, values) : joinCut(joined, parts, once);
1045
+ };
1046
+ return { ...answer, text: webCut(tool.name, answer.text, once, holds) ?? cut(answer.text) };
934
1047
  }
935
1048
  catch (error) {
936
1049
  if (error instanceof Error) {
@@ -944,6 +1057,18 @@ export function answersCut(tool, cut) {
944
1057
  },
945
1058
  };
946
1059
  }
1060
+ /** Whether `cut`, a redactor that does not know its values, takes from `joined` (`parts` joined by line breaks) what it
1061
+ * does not take from the parts each read alone: a held value split across two parts. Its cut of the join whole being
1062
+ * "[redacted]" is not enough: it reads a text longer than a piece in pieces of 8,192 characters (key-refusal.ts
1063
+ * redactedAnswer), and a value split inside one piece withholds only that piece, the rest of the join served. So the
1064
+ * join's cut is set beside the parts' cuts joined: no value split across parts is in any part to cut, so the two differ
1065
+ * wherever the join holds one, in one piece or across two. Where nothing spans two parts they are the same: every piece
1066
+ * ends at whitespace or inside a run of more than a piece (the same run in a part as in the join, cut at the same
1067
+ * places), and a line break ends each part. */
1068
+ function joinCut(joined, parts, cut) {
1069
+ const whole = cut(joined);
1070
+ return whole === "[redacted]" || whole !== parts.map(cut).join("\n");
1071
+ }
947
1072
  /** 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
948
1073
  * the claim's environment (claim-secrets.ts: the run's keys from the store, its plane set), the run's registry for an
949
1074
  * 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,
@@ -71,8 +71,8 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
71
71
  // `mcpLoopback`: the server beside it is a local install (Serve.localInstall), so its runs may reach an MCP server on
72
72
  // loopback; a runner in its own process does only as its own environment says (main.ts runnerLoopback). `mcpOwn`: that server's own addresses (Serve.own), whose ports a run's
73
73
  // loopback read never goes to. A run's log lines (a sweep that failed) go to
74
- // stderr with the runner's other lines. `evalFakes`: the template eval's fakes (EvalFakes: a case's web, now, monid and
75
- // email), by the agent each of its runs is of; only the eval, in its own process, hands them. `harnessInstall`: what a
74
+ // stderr with the runner's other lines. `evalFakes`: the template eval's fakes (EvalFakes: a case's web, now, monid,
75
+ // email and files), by the agent each of its runs is of; only the eval, in its own process, hands them. `harnessInstall`: what a
76
76
  // claim's first-use install installs with (the eval's sharedInstaller, which the server beside it takes too).
77
77
  const { installForClaim } = await import("../harness-install.js");
78
78
  const deps = { env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps, ...(mcpLoopback ? { mcpLoopback: true } : {}), ...(mcpOwn ? { mcpOwn } : {}), ...(evalFakes ? { evalFakes } : {}), ...(harnessInstall ? { installForClaim: ((entry, dir, pins, given) => installForClaim(entry, dir, pins, { ...given, install: harnessInstall })) } : {}), log: (line) => console.error(`agentrun-serve runner: ${line}`) };
@@ -120,15 +120,20 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
120
120
  if (event.type === "ended")
121
121
  onRunEnded?.(event.status);
122
122
  };
123
- // A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts).
123
+ // A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts), as
124
+ // the runner beside it (read at each end, once it has started): a computer kept pinned to another runner is that one's.
124
125
  const { runEndComputers } = await import("../workspace/run-end-computers.js");
125
126
  const { projectRunEnded } = await import("../source-sync/checkpoints.js");
126
- const runEnded = projectRunEnded(store, runEndComputers({ store, computers: computers.computerDeps, log: (line) => console.error(`agentrun-serve runner: ${line}`) }));
127
- const runner = startRunner({ store, name, createLoop, memory: runnerMemory(store, undefined, runs, isolation ? RUN_PROCESS_MIB : 0), onEvent: said, runEnded, ...(held !== undefined ? { loops: held } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
127
+ const { runCensus } = await import("../run-census.js");
128
+ const self = () => (runner.incarnation ? { runner: name, incarnation: runner.incarnation } : undefined);
129
+ const runEnded = projectRunEnded(store, runEndComputers({ store, computers: computers.computerDeps, log: (line) => console.error(`agentrun-serve runner: ${line}`), self }));
130
+ const runner = startRunner({ store, name, createLoop, census: runCensus(store, { data: dataDir, sealKey: seal.key, env: runs }), memory: runnerMemory(store, undefined, runs, isolation ? RUN_PROCESS_MIB : 0), onEvent: said, runEnded, ...(held !== undefined ? { loops: held } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
128
131
  // The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
129
132
  // runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
130
133
  const { startJanitor } = await import("../workspace/computer-janitor.js");
131
- const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
134
+ // As the runner beside it (its name and its presence's incarnation): a kept computer pinned to another runner still
135
+ // there is that runner's to end (computer-kept.ts sweepKept).
136
+ const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`), ...(runner.incarnation ? { self: { runner: name, incarnation: runner.incarnation } } : {}) }) : undefined;
132
137
  // Its close waits for any first-use install its claims let go of to stop (its npm ended) before it lets go of the data.
133
138
  const { claimInstallsStopped } = await import("../harness-install.js");
134
139
  // The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
@@ -14,6 +14,7 @@
14
14
  // runner only copies bytes and calls the Workspace: it reads nothing of them and dials nothing.
15
15
  import { ClaimRefused } from "./loop-contract.js";
16
16
  import { ChannelClosed } from "./run-channel.js";
17
+ import { until } from "../until.js";
17
18
  import { saveSlots, SAVE_MAX_BYTES } from "../web-save.js";
18
19
  import { WorkspaceError } from "../workspace/workspace.js";
19
20
  export { piecedWorkspace } from "../workspace/pieced.js";
@@ -31,16 +32,6 @@ export const BIG_WRITES = 4;
31
32
  export const BIG_WRITES_PER_RUN = 8;
32
33
  /** The runner's one gate for pieced writes. */
33
34
  export const BIG_WRITE_SLOTS = saveSlots(BIG_WRITES);
34
- /** `work`'s answer, or `signal`'s reason as soon as it aborts. */
35
- function until(work, signal) {
36
- if (signal.aborted)
37
- return Promise.reject(signal.reason);
38
- return new Promise((resolve, reject) => {
39
- const abort = () => reject(signal.reason);
40
- signal.addEventListener("abort", abort, { once: true });
41
- work.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
42
- });
43
- }
44
35
  export function runBigWrites(options = {}) {
45
36
  const gate = options.gate ?? BIG_WRITE_SLOTS;
46
37
  const piece = options.piece ?? PIECE_BYTES;
@@ -30,12 +30,19 @@ type RunLaunchReader = {
30
30
  /** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
31
31
  * revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
32
32
  * decision provider keys — and, for claim `runId`, the run's own tool keys its revision declares (run-keys.ts) over the
33
- * server's by the same name. A fresh object per claim, so no run's keys reach another's. `redact`: the runner's one
33
+ * server's by the same name. Its model keys are readable by name and never enumerable (MODEL_KEY_NAMES): its model
34
+ * routes read them by name (claimModelEnv), and a spread or a spawn of the tools' environment carries none. A fresh
35
+ * object per claim, so no run's keys reach another's. `redact`: the runner's one
34
36
  * redactor, which the run's own tool keys are carried into before they are laid, so its journal is cut of them as it is
35
- * written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. */
37
+ * written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. A held run
38
+ * its model kept from running at its create (hold.refused) is laid no model key and no plan sign-in: its model runs
39
+ * nowhere. Its tools' keys, its decision keys and its own tool keys are laid as any run's. The one tool key row that names
40
+ * a model key's name, TypeSafe's (key-words.ts; model.ts PROVIDER_KEYS typesafe), is a decision key (secrets.ts
41
+ * DECISION_KEYS): keysFor never names one, so the model key filter below never sees it, and decisionKeysFor lays it
42
+ * apart, as it lays OpenRouter's for a decision node that runs on it. */
36
43
  export declare function claimSecrets(deps: ClaimSecretsDeps & {
37
44
  readonly redact: HeldRedact;
38
- }, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">, runId?: string): Promise<NodeJS.ProcessEnv>;
45
+ }, revision: Revision, launch: Pick<RunLaunch, "plane" | "model" | "hold">, runId?: string): Promise<NodeJS.ProcessEnv>;
39
46
  /** `keys` (learnedDecisionKeys') laid onto `env`, a claim's environment, where it holds no value of that name: what the
40
47
  * claim laid stays, a run's own tool key over the server's above all. A name both read holds the same server key. */
41
48
  export declare function underClaimed(env: NodeJS.ProcessEnv, keys: Readonly<Record<string, string>>): void;
@@ -69,6 +76,11 @@ export declare function withModelKeys(env: NodeJS.ProcessEnv, opened: NodeJS.Pro
69
76
  /** Every model key the server holds, for a model route with no revision to scope it by (an SDK run's compile turn): each
70
77
  * by its name from `deps.env` first, then the store's sealed value, as claimSecrets reads them. */
71
78
  export declare function savedModelKeys(deps: ClaimSecretsDeps): Promise<NodeJS.ProcessEnv>;
79
+ /** Of `saved` (savedModelKeys'), the keys a route to `model` (`provider/model-id`) reads and no other: its provider's
80
+ * (PROVIDER_KEYS), or through a gateway (`env`'s AGENT_MODEL_BASE_URL, as modelKeys reads it) the gateway's key alone.
81
+ * None for no model, or one whose provider names no key. What a runner hands a run's process for one route of its
82
+ * (run-child-host.ts savedModelKeys): never every key the server holds. */
83
+ export declare function routeModelKeys(saved: NodeJS.ProcessEnv, env: NodeJS.ProcessEnv, model: string | undefined): NodeJS.ProcessEnv;
72
84
  /** A run's own model key, held by its claim (run-model-key.ts): `fresh()` opens it from the run's launch again (a message's
73
85
  * new key replaces it, or a run that started on the server's key takes its first); `everHeld()`, whether the claim ever
74
86
  * held one, so spend after the turn never falls to the server's key for a run that brought its own. */
@@ -137,4 +149,7 @@ export declare function claimModelEnv(env: NodeJS.ProcessEnv, opened: NodeJS.Pro
137
149
  * run's model routes do not send. The decision providers' keys stay (DECISION_KEY_NAMES): a keyed workflow's judge,
138
150
  * pick, sift, route and ask nodes run on them as any run's do. */
139
151
  export declare function withoutModelKeys(toolEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
152
+ /** `under` and `over` as one set of opened keys for claimModelEnv, `over`'s value winning by name: every property as it
153
+ * is, so a claim's model keys (claimSecrets: never enumerable), which a spread would drop, reach the route. */
154
+ export declare function keysOver(under: NodeJS.ProcessEnv, over: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
140
155
  export {};