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

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 (404) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/README.md +393 -118
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/api-only.d.ts +2 -4
  11. package/dist/api-only.js +2 -4
  12. package/dist/attach-conformance.js +5 -4
  13. package/dist/box-paths.d.ts +7 -5
  14. package/dist/box-paths.js +12 -8
  15. package/dist/browser-computer.d.ts +3 -8
  16. package/dist/browser-computer.js +12 -35
  17. package/dist/browser-cost.js +94 -20
  18. package/dist/capacity.d.ts +1 -1
  19. package/dist/capacity.js +3 -3
  20. package/dist/chatgpt-plan.d.ts +5 -0
  21. package/dist/chatgpt-plan.js +25 -11
  22. package/dist/claude-login-token.d.ts +121 -0
  23. package/dist/claude-login-token.js +797 -0
  24. package/dist/claude-login.d.ts +119 -34
  25. package/dist/claude-login.js +551 -79
  26. package/dist/claude-sign-in.d.ts +3 -0
  27. package/dist/claude-sign-in.js +10 -1
  28. package/dist/cli.js +325 -328
  29. package/dist/composio-made.d.ts +1 -6
  30. package/dist/composio-made.js +1 -6
  31. package/dist/composio-owners.d.ts +26 -0
  32. package/dist/composio-owners.js +36 -0
  33. package/dist/composio-preset.d.ts +56 -23
  34. package/dist/composio-preset.js +173 -77
  35. package/dist/composio-triggers.d.ts +4 -4
  36. package/dist/composio-triggers.js +6 -7
  37. package/dist/compute-cost.js +11 -2
  38. package/dist/computer-attach.d.ts +40 -19
  39. package/dist/computer-attach.js +326 -62
  40. package/dist/computer-held-routes.d.ts +1 -1
  41. package/dist/computer-held-routes.js +9 -4
  42. package/dist/computer-keys.d.ts +11 -1
  43. package/dist/computer-keys.js +26 -1
  44. package/dist/computer-record.js +3 -1
  45. package/dist/computer-view.d.ts +5 -3
  46. package/dist/computer-view.js +10 -6
  47. package/dist/computer-viewer.js +36 -7
  48. package/dist/computers.d.ts +12 -11
  49. package/dist/computers.js +11 -8
  50. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  51. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  52. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  53. package/dist/console/assets/share-L84tlUDW.js +6 -0
  54. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  55. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  56. package/dist/console/index.html +4 -3
  57. package/dist/console/share.html +17 -0
  58. package/dist/decisions.d.ts +17 -7
  59. package/dist/decisions.js +41 -15
  60. package/dist/dial-relay.d.ts +25 -4
  61. package/dist/dial-relay.js +139 -5
  62. package/dist/docker-daemon.js +4 -5
  63. package/dist/docker-host-addresses.js +29 -11
  64. package/dist/email/account.d.ts +6 -0
  65. package/dist/email/account.js +6 -0
  66. package/dist/email/authentication.d.ts +21 -0
  67. package/dist/email/authentication.js +106 -0
  68. package/dist/email/email-faux.d.ts +11 -2
  69. package/dist/email/email-faux.js +21 -5
  70. package/dist/email/mail.d.ts +25 -0
  71. package/dist/email/mail.js +58 -2
  72. package/dist/email/names.js +2 -2
  73. package/dist/email/tools.d.ts +9 -4
  74. package/dist/email/tools.js +95 -13
  75. package/dist/env-switch.d.ts +13 -5
  76. package/dist/env-switch.js +24 -6
  77. package/dist/errors.d.ts +1 -0
  78. package/dist/errors.js +2 -0
  79. package/dist/fal-price.d.ts +12 -4
  80. package/dist/fal-price.js +110 -26
  81. package/dist/faux-computers.js +1 -1
  82. package/dist/filed-answer.d.ts +2 -2
  83. package/dist/filed-answer.js +2 -2
  84. package/dist/graph-served.d.ts +10 -5
  85. package/dist/graph-served.js +40 -10
  86. package/dist/handed-values.js +1 -2
  87. package/dist/harness-check.d.ts +2 -1
  88. package/dist/harness-check.js +45 -12
  89. package/dist/harness-keys.js +9 -6
  90. package/dist/harness-opencode/facts.js +2 -0
  91. package/dist/harness-recipe-entry.d.ts +9 -3
  92. package/dist/harness-recipe-entry.js +18 -9
  93. package/dist/harness-recipe.d.ts +21 -0
  94. package/dist/harness-recipe.js +25 -3
  95. package/dist/harness-table.d.ts +8 -0
  96. package/dist/harness-table.js +17 -6
  97. package/dist/helper-env.d.ts +4 -1
  98. package/dist/helper-env.js +4 -1
  99. package/dist/host-check.d.ts +2 -3
  100. package/dist/host-check.js +13 -7
  101. package/dist/hosted-search.js +1 -1
  102. package/dist/import.d.ts +11 -8
  103. package/dist/import.js +437 -186
  104. package/dist/key-refusal.d.ts +9 -2
  105. package/dist/key-refusal.js +86 -32
  106. package/dist/learn/audit.d.ts +8 -5
  107. package/dist/learn/audit.js +15 -7
  108. package/dist/learn/compile.d.ts +5 -2
  109. package/dist/learn/compile.js +45 -21
  110. package/dist/learn/field-check.d.ts +111 -0
  111. package/dist/learn/field-check.js +174 -0
  112. package/dist/learn/ledger.d.ts +173 -0
  113. package/dist/learn/ledger.js +225 -0
  114. package/dist/learn/promote.d.ts +82 -39
  115. package/dist/learn/promote.js +61 -66
  116. package/dist/learn/secrets.d.ts +4 -0
  117. package/dist/learn/secrets.js +12 -0
  118. package/dist/learned-nodes.d.ts +8 -5
  119. package/dist/learned-nodes.js +8 -5
  120. package/dist/learned-workflow.d.ts +2 -1
  121. package/dist/learned-workflow.js +13 -10
  122. package/dist/learning-cost.d.ts +40 -21
  123. package/dist/learning-cost.js +30 -21
  124. package/dist/learning-setting.d.ts +6 -0
  125. package/dist/learning-setting.js +11 -1
  126. package/dist/listen-first.d.ts +5 -4
  127. package/dist/listen-first.js +4 -5
  128. package/dist/live-reach.d.ts +9 -0
  129. package/dist/live-reach.js +9 -0
  130. package/dist/mcp-api-only-origins.d.ts +23 -3
  131. package/dist/mcp-api-only-origins.js +57 -17
  132. package/dist/mcp-gateway.d.ts +16 -2
  133. package/dist/mcp-gateway.js +41 -3
  134. package/dist/mcp-oauth.d.ts +1 -1
  135. package/dist/mcp-oauth.js +3 -2
  136. package/dist/mcp-probe.d.ts +3 -0
  137. package/dist/mcp-probe.js +3 -0
  138. package/dist/mcp-secret-writes.d.ts +24 -2
  139. package/dist/mcp-secret-writes.js +30 -2
  140. package/dist/mcp-servers-store.d.ts +52 -14
  141. package/dist/mcp-servers-store.js +165 -61
  142. package/dist/mcp-sources.d.ts +1 -2
  143. package/dist/mcp-sources.js +1 -2
  144. package/dist/mcp-store.d.ts +5 -5
  145. package/dist/mcp-store.js +3 -3
  146. package/dist/mcp.js +1 -1
  147. package/dist/micro.d.ts +2 -0
  148. package/dist/micro.js +2 -0
  149. package/dist/model-gateway.d.ts +1 -1
  150. package/dist/model-gateway.js +20 -36
  151. package/dist/model.d.ts +5 -4
  152. package/dist/model.js +7 -6
  153. package/dist/monid.d.ts +14 -1
  154. package/dist/monid.js +103 -26
  155. package/dist/ollama-provider.d.ts +23 -9
  156. package/dist/ollama-provider.js +49 -20
  157. package/dist/openapi.js +234 -61
  158. package/dist/otel/genai.d.ts +83 -7
  159. package/dist/otel/genai.js +69 -9
  160. package/dist/otel/tracer.d.ts +42 -13
  161. package/dist/otel/tracer.js +241 -56
  162. package/dist/page.d.ts +7 -1
  163. package/dist/page.js +76 -22
  164. package/dist/paid-calls.d.ts +6 -4
  165. package/dist/paid-calls.js +15 -7
  166. package/dist/place-offers.d.ts +59 -34
  167. package/dist/place-offers.js +100 -58
  168. package/dist/place.d.ts +13 -14
  169. package/dist/place.js +56 -41
  170. package/dist/print.js +1 -1
  171. package/dist/provider.d.ts +5 -4
  172. package/dist/provider.js +26 -13
  173. package/dist/redact/match.d.ts +27 -9
  174. package/dist/redact/match.js +266 -57
  175. package/dist/run-census.d.ts +1 -1
  176. package/dist/run-census.js +4 -5
  177. package/dist/run-cut.js +4 -5
  178. package/dist/run-export-store.d.ts +15 -0
  179. package/dist/run-export-store.js +30 -0
  180. package/dist/run-export.d.ts +139 -0
  181. package/dist/run-export.js +379 -0
  182. package/dist/run-file-cut.d.ts +5 -0
  183. package/dist/run-file-cut.js +13 -0
  184. package/dist/run-launch.js +16 -3
  185. package/dist/run-learning-served.d.ts +2 -2
  186. package/dist/run-model-key.d.ts +15 -6
  187. package/dist/run-model-key.js +30 -31
  188. package/dist/run-reads-over-store.js +4 -4
  189. package/dist/run-secrets.js +3 -5
  190. package/dist/run-timeline-served.js +3 -1
  191. package/dist/run-view.d.ts +1 -2
  192. package/dist/run-view.js +2 -1
  193. package/dist/runnable.js +2 -2
  194. package/dist/runner/adapter-loop.d.ts +35 -18
  195. package/dist/runner/adapter-loop.js +97 -63
  196. package/dist/runner/adapter-run-spec.d.ts +34 -14
  197. package/dist/runner/adapter-run-spec.js +120 -75
  198. package/dist/runner/adapters/pi.js +4 -2
  199. package/dist/runner/audit.d.ts +8 -5
  200. package/dist/runner/audit.js +37 -17
  201. package/dist/runner/beside.d.ts +9 -2
  202. package/dist/runner/beside.js +29 -13
  203. package/dist/runner/claim-secrets.d.ts +27 -18
  204. package/dist/runner/claim-secrets.js +61 -47
  205. package/dist/runner/cli-run-spec.d.ts +18 -0
  206. package/dist/runner/cli-run-spec.js +93 -46
  207. package/dist/runner/compare-end.d.ts +2 -1
  208. package/dist/runner/compare-end.js +25 -10
  209. package/dist/runner/conformance/harness.js +2 -3
  210. package/dist/runner/conformance/subject.d.ts +4 -1
  211. package/dist/runner/harness-loops.js +3 -3
  212. package/dist/runner/held.d.ts +19 -4
  213. package/dist/runner/journal-kinds.d.ts +4 -1
  214. package/dist/runner/journal-kinds.js +22 -4
  215. package/dist/runner/learned-first.js +20 -4
  216. package/dist/runner/learning-end.d.ts +2 -8
  217. package/dist/runner/learning-end.js +11 -19
  218. package/dist/runner/live-ticker.js +7 -5
  219. package/dist/runner/loop-contract.d.ts +0 -2
  220. package/dist/runner/loop.d.ts +7 -0
  221. package/dist/runner/loop.js +1 -0
  222. package/dist/runner/main.d.ts +11 -6
  223. package/dist/runner/main.js +24 -18
  224. package/dist/runner/mcp-claim.js +24 -7
  225. package/dist/runner/mcp-run.d.ts +3 -6
  226. package/dist/runner/mcp-run.js +3 -4
  227. package/dist/runner/meta-tools.js +3 -2
  228. package/dist/runner/metrics.d.ts +7 -0
  229. package/dist/runner/metrics.js +19 -0
  230. package/dist/runner/model-route.d.ts +10 -7
  231. package/dist/runner/model-route.js +79 -15
  232. package/dist/runner/native-loop.js +10 -8
  233. package/dist/runner/presence.d.ts +11 -4
  234. package/dist/runner/presence.js +11 -6
  235. package/dist/runner/promotion.d.ts +25 -13
  236. package/dist/runner/promotion.js +125 -50
  237. package/dist/runner/redact.d.ts +3 -1
  238. package/dist/runner/redact.js +5 -3
  239. package/dist/runner/reflect-hook.js +1 -1
  240. package/dist/runner/responses-fetch.d.ts +36 -0
  241. package/dist/runner/responses-fetch.js +511 -0
  242. package/dist/runner/run-child-host.d.ts +38 -12
  243. package/dist/runner/run-child-host.js +231 -83
  244. package/dist/runner/run-child.js +11 -4
  245. package/dist/runner/runner-check.js +5 -1
  246. package/dist/runner/runner.d.ts +5 -3
  247. package/dist/runner/runner.js +14 -10
  248. package/dist/runner/save-slots.js +2 -1
  249. package/dist/runner/sdk-loop.js +8 -8
  250. package/dist/runner/spec-holds.d.ts +8 -1
  251. package/dist/runner/spec-holds.js +9 -4
  252. package/dist/runner/subagent.d.ts +11 -0
  253. package/dist/runner/subagent.js +17 -3
  254. package/dist/runner/workflow-calls.d.ts +9 -0
  255. package/dist/runner/workflow-calls.js +150 -0
  256. package/dist/runner/workflow-first.d.ts +138 -37
  257. package/dist/runner/workflow-first.js +230 -99
  258. package/dist/runner/workflow-spec.js +2 -2
  259. package/dist/runs-over-store.js +8 -7
  260. package/dist/save-once.d.ts +14 -0
  261. package/dist/save-once.js +31 -0
  262. package/dist/scrub-command.d.ts +34 -31
  263. package/dist/scrub-command.js +116 -147
  264. package/dist/sdk/runs.d.ts +6 -0
  265. package/dist/sdk/runs.js +89 -10
  266. package/dist/seal-key.js +4 -4
  267. package/dist/secret-cut.d.ts +3 -0
  268. package/dist/secret-cut.js +7 -1
  269. package/dist/secret-rules.d.ts +8 -1
  270. package/dist/secret-rules.js +482 -53
  271. package/dist/secrets.d.ts +51 -9
  272. package/dist/secrets.js +311 -21
  273. package/dist/server-keys.d.ts +4 -3
  274. package/dist/server-keys.js +4 -3
  275. package/dist/server-secrets-store.js +2 -4
  276. package/dist/server.d.ts +33 -10
  277. package/dist/server.js +454 -136
  278. package/dist/share-context.d.ts +22 -0
  279. package/dist/share-context.js +76 -0
  280. package/dist/shell-lex.d.ts +105 -0
  281. package/dist/shell-lex.js +646 -0
  282. package/dist/sign-ins-store.d.ts +5 -7
  283. package/dist/sign-ins-store.js +12 -16
  284. package/dist/sign-ins.d.ts +7 -11
  285. package/dist/sign-ins.js +40 -41
  286. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  287. package/dist/slots.d.ts +9 -0
  288. package/dist/slots.js +45 -0
  289. package/dist/start-switches.d.ts +6 -5
  290. package/dist/start-switches.js +8 -4
  291. package/dist/stats.d.ts +5 -1
  292. package/dist/stats.js +1 -1
  293. package/dist/store/agent-body.js +2 -2
  294. package/dist/store/dialect.d.ts +4 -0
  295. package/dist/store/dialect.js +1 -0
  296. package/dist/store/index.d.ts +2 -2
  297. package/dist/store/index.js +1 -1
  298. package/dist/store/mcp-record-keys.d.ts +10 -0
  299. package/dist/store/mcp-record-keys.js +13 -0
  300. package/dist/store/postgres/dialect.js +2 -0
  301. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  302. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  303. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  304. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  305. package/dist/store/postgres/store.js +4 -0
  306. package/dist/store/schema.d.ts +44 -4
  307. package/dist/store/schema.js +111 -11
  308. package/dist/store/seal.d.ts +4 -1
  309. package/dist/store/sqlite/run-launch.d.ts +3 -10
  310. package/dist/store/sqlite/run-launch.js +12 -23
  311. package/dist/store/sqlite/run-patch.d.ts +19 -2
  312. package/dist/store/sqlite/run-patch.js +67 -2
  313. package/dist/store/sqlite/store.d.ts +3 -0
  314. package/dist/store/sqlite/store.js +177 -32
  315. package/dist/store/store-schema.js +3 -4
  316. package/dist/store/store.d.ts +74 -25
  317. package/dist/store/store.js +14 -11
  318. package/dist/store-reads/analytics.d.ts +2 -1
  319. package/dist/store-reads/analytics.js +7 -5
  320. package/dist/store-reads/learning.d.ts +102 -136
  321. package/dist/store-reads/learning.js +251 -302
  322. package/dist/store-reads/stats.d.ts +2 -2
  323. package/dist/store-reads/stats.js +13 -7
  324. package/dist/store-view.js +10 -7
  325. package/dist/suggestions.d.ts +1 -1
  326. package/dist/suggestions.js +29 -13
  327. package/dist/template-eval.d.ts +91 -9
  328. package/dist/template-eval.js +448 -105
  329. package/dist/template-import.d.ts +0 -10
  330. package/dist/template-import.js +5 -10
  331. package/dist/timeline/labels.d.ts +1 -1
  332. package/dist/timeline/labels.js +4 -3
  333. package/dist/timeline/timeline.d.ts +23 -11
  334. package/dist/timeline/timeline.js +115 -31
  335. package/dist/timeline/web-calls.d.ts +14 -14
  336. package/dist/timeline/web-calls.js +18 -30
  337. package/dist/tool-gate.d.ts +13 -1
  338. package/dist/tool-gate.js +43 -3
  339. package/dist/tool-keys-store.js +2 -4
  340. package/dist/tool-keys.d.ts +11 -0
  341. package/dist/tool-keys.js +16 -0
  342. package/dist/tool-plane.d.ts +50 -11
  343. package/dist/tool-plane.js +94 -30
  344. package/dist/tools.d.ts +5 -1
  345. package/dist/tools.js +7 -7
  346. package/dist/trigger-email.js +12 -6
  347. package/dist/triggers.d.ts +15 -34
  348. package/dist/triggers.js +119 -126
  349. package/dist/validate.d.ts +8 -1
  350. package/dist/validate.js +163 -23
  351. package/dist/web-fake.d.ts +2 -1
  352. package/dist/web-fake.js +8 -6
  353. package/dist/web-fetch.d.ts +8 -6
  354. package/dist/web-fetch.js +13 -11
  355. package/dist/web-holds.d.ts +32 -0
  356. package/dist/web-holds.js +86 -0
  357. package/dist/web-run.d.ts +32 -5
  358. package/dist/web-run.js +75 -28
  359. package/dist/web-save.d.ts +4 -9
  360. package/dist/web-save.js +27 -55
  361. package/dist/web-search.js +14 -25
  362. package/dist/wires.d.ts +4 -3
  363. package/dist/wires.js +5 -4
  364. package/dist/workspace/archil-claim.d.ts +12 -5
  365. package/dist/workspace/archil-claim.js +45 -5
  366. package/dist/workspace/attach.js +52 -19
  367. package/dist/workspace/attached-computers.d.ts +38 -11
  368. package/dist/workspace/attached-computers.js +81 -16
  369. package/dist/workspace/computer-deps.d.ts +29 -7
  370. package/dist/workspace/computer-deps.js +36 -18
  371. package/dist/workspace/computer-for-claim.d.ts +21 -4
  372. package/dist/workspace/computer-for-claim.js +166 -57
  373. package/dist/workspace/computer-intervals.d.ts +2 -0
  374. package/dist/workspace/computer-intervals.js +1 -1
  375. package/dist/workspace/computer-janitor.d.ts +48 -14
  376. package/dist/workspace/computer-janitor.js +153 -44
  377. package/dist/workspace/computer-kept.d.ts +158 -32
  378. package/dist/workspace/computer-kept.js +288 -63
  379. package/dist/workspace/computer-providers.d.ts +8 -3
  380. package/dist/workspace/computer-providers.js +12 -5
  381. package/dist/workspace/index.d.ts +1 -1
  382. package/dist/workspace/index.js +1 -1
  383. package/dist/workspace/local.js +41 -1
  384. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  385. package/dist/workspace/mount-revoke-left.js +72 -0
  386. package/dist/workspace/paired-route.d.ts +91 -0
  387. package/dist/workspace/paired-route.js +152 -0
  388. package/dist/workspace/resolve-computer.d.ts +5 -2
  389. package/dist/workspace/resolve-computer.js +9 -3
  390. package/dist/workspace/run-end-computers.d.ts +11 -5
  391. package/dist/workspace/run-end-computers.js +153 -28
  392. package/dist/workspace/run-tools.d.ts +22 -3
  393. package/dist/workspace/run-tools.js +17 -5
  394. package/dist/workspace/run-workspace.d.ts +14 -1
  395. package/dist/workspace/run-workspace.js +34 -1
  396. package/dist/workspace/workspace.d.ts +6 -0
  397. package/dist/wrapped.d.ts +8 -2
  398. package/dist/wrapped.js +21 -6
  399. package/package.json +12 -13
  400. package/skills/agentrun-serve/SKILL.md +5 -2
  401. package/templates/README.md +25 -9
  402. package/dist/console/assets/backend-DVhHzJX2.js +0 -166
  403. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  404. package/dist/console/assets/index-okP-y8PK.js +0 -747
@@ -17,8 +17,9 @@ import { existsSync } from "node:fs";
17
17
  import { chmod, mkdir, rm } from "node:fs/promises";
18
18
  import { dirname, join } from "node:path";
19
19
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
20
- import { encode, OTEL_PAIR, SECRET_NAMES, SECRETS_FD_ENV, SECRETS_LEN_ENV, withoutSecrets } from "../secrets.js";
21
- import { otelSettings } from "../otel/tracer.js";
20
+ import { encode, SECRET_NAMES, SECRETS_FD_ENV, SECRETS_LEN_ENV, withoutSecrets } from "../secrets.js";
21
+ import { genAiTracing, tracePosts } from "../otel/tracer.js";
22
+ import { agentOfRun } from "../otel/genai.js";
22
23
  import { putLiveViewer, dropLiveViewer } from "../browser-live.js";
23
24
  import { CALENDAR_EVENTS } from "../calendar/names.js";
24
25
  import { openCalendar } from "../calendar/address.js";
@@ -35,7 +36,7 @@ import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
35
36
  import { learningEndOfRun } from "./learning-end.js";
36
37
  import { cutDeep, runnerSecrets } from "./redact.js";
37
38
  import { storeSecrets } from "./store-secrets.js";
38
- import { FAUX_ENV, FAUX_PROVIDER, GATEWAY_KEY_ENV } from "../model.js";
39
+ import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
39
40
  import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
40
41
  import { FAUX_VENDOR_API_ENV } from "../tools.js";
41
42
  import { withinCarried } from "../paid-calls.js";
@@ -43,11 +44,14 @@ import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
43
44
  import { runZone } from "../environment.js";
44
45
  import { shadowRunId } from "../learn/audit.js";
45
46
  import { LEARNING_SCRIPT, learningWorkspace } from "../learn/folder.js";
46
- import { openRunWorkspace } from "../workspace/run-workspace.js";
47
+ import { agreeOnOf } from "../learning-setting.js";
48
+ import { openedAtUse, openRunWorkspace } from "../workspace/run-workspace.js";
47
49
  import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
48
50
  import { agentDirName, recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
49
51
  import { keptKeyOf } from "../workspace/computer-kept.js";
50
- import { claimModelKey, claimSecrets, claimSpendOff, hostDecisionKeys, learnedDecisionKeys, openRunModelKey, routeModelKeys, savedModelKeys, serverKeyless, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
52
+ import { waitEndedKey } from "../browser-wait-ended.js";
53
+ import { browserHoldKey } from "../browser-hold.js";
54
+ import { claimModelKey, claimSecrets, claimSpendOff, hostDecisionKeys, learnedDecisionKeys, openRunModelKey, savedModelKeys, sendsNoModelKey, serverKeyless, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
51
55
  import { githubAppAccess } from "./github-app.js";
52
56
  import { githubPullOf, githubTargetOf } from "../github.js";
53
57
  import { isObject } from "../validate.js";
@@ -61,11 +65,14 @@ import { compareEndOfRun } from "./compare-end.js";
61
65
  import { learnedFirst } from "./learned-first.js";
62
66
  import { workflowsAt } from "./learning-seed.js";
63
67
  import { claimMetering, heldMcpOf, mcpForClaim } from "./mcp-run.js";
64
- import { graderModelOf, learnedTiers, learnsWorkflows, mcpReachOf } from "./adapter-run-spec.js";
68
+ import { learnedTiers, learnsWorkflows, mcpReachOf } from "./adapter-run-spec.js";
65
69
  import { createDispatchLoop } from "./dispatch.js";
66
70
  import { refuseRecipeTriggerRun, resolveRunnerLoop, withSavedGatewayDeps } from "./harness-loops.js";
67
71
  import { isWorkflowRevision } from "./workflow-loop.js";
68
72
  import { loginForRun } from "../claude-login.js";
73
+ import { harnessOfBody } from "../harness.js";
74
+ import { agentRunLogin, LOGIN_CHANGED_SINCE_CLAIM, loginRunnerInProcess, loginTokensFor } from "../claude-login-token.js";
75
+ import { logLine } from "../print.js";
69
76
  import { heardComputerHold } from "./computer-journal.js";
70
77
  import { ClaimRefused } from "./loop-contract.js";
71
78
  import { Channel, ChannelClosed } from "./run-channel.js";
@@ -73,12 +80,13 @@ import { registerRunErrors } from "./run-errors.js";
73
80
  import { exposeSaveSlots } from "./save-slots.js";
74
81
  import { runBigWrites } from "./big-writes.js";
75
82
  import { SERVER_SLOTS } from "../web-save.js";
83
+ import { holdsEnv, noteHold } from "../web-holds.js";
76
84
  import { launchOnItsDisk, readLaunchBody } from "../run-launch.js";
77
- import { SUBAGENT_TOOL } from "./subagent.js";
85
+ import { routedSubagentTiers, SUBAGENT_TOOL } from "./subagent.js";
78
86
  import { sourceSyncOf } from "../source-sync/types.js";
79
87
  import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
80
88
  import { beginSourceIO } from "../source-sync/io.js";
81
- import { runTools } from "../workspace/run-tools.js";
89
+ import { attachedIn, runTools } from "../workspace/run-tools.js";
82
90
  import { ProjectHostGate } from "./project-host.js";
83
91
  import { runProjectCheckpoint } from "./project-checkpoint.js";
84
92
  /** The image's helper that starts a run's process as its slot's uid (packages/serve/runas). */
@@ -390,20 +398,59 @@ const always = () => true;
390
398
  /** The settings a run's process may read, the server's own configuration its loop and tools read: its tool settings,
391
399
  * its Archil settings (no credential), its MCP hosts and server names, its Claude-login mode and its approvers. */
392
400
  const SHARED_SETTINGS = new Set(["tool-settings", "archil", "mcp.private_oauth_hosts", "mcp.server_own", "claude_login", "approvers"]);
401
+ /** The rows of the claim's own run that its process writes, and removes, itself, each with its string fields (beside the
402
+ * claim's epoch): its browser's wait that ended (browser-wait-ended.ts) and its browser's take (browser-hold.ts), each
403
+ * the run's process's report of its own browser to the server's reads. No other row is its to write. */
404
+ const ownWrittenSettings = (bound) => new Map([
405
+ [waitEndedKey(bound.claim.runId), ["at", "why"]],
406
+ [browserHoldKey(bound.claim.runId), ["session", "at"]],
407
+ ]);
408
+ /** The most one of those rows may take, as JSON bytes: a session's tag, a time and a timeline row's words fit many times
409
+ * over, and the server parses the row on every read of the run and every Screen poll. */
410
+ const OWN_ROW_MAX_BYTES = 4096;
393
411
  /** The settings of the claim's own run and agent a run's process may read: its run's Archil disk, SDK record, kept
394
- * computer and browser wait, and its agent's Archil disk and promotions. Every other row (another run's or agent's) is
395
- * not its to read. */
412
+ * computer, browser wait and browser take, and its agent's Archil disk and promotions. Every other row (another run's
413
+ * or agent's) is not its to read. */
396
414
  const ownSettings = (bound) => new Set([
397
415
  `archil.run.${bound.claim.runId}`,
398
416
  `sdk-run:${bound.claim.runId}`,
399
417
  keptKeyOf(bound.claim.runId),
400
- `browser_wait_ended:${bound.claim.runId}`,
418
+ ...ownWrittenSettings(bound).keys(),
401
419
  `archil.agent.${bound.agentId}`,
402
420
  `learning.promotions.${bound.agentId}`,
403
421
  ]);
404
422
  /** Whether a run's process may read setting `key`. */
405
423
  export const settingReadable = (key, bound) => typeof key === "string" && (SHARED_SETTINGS.has(key) || ownSettings(bound).has(key));
406
424
  const readableSetting = (args, bound) => settingReadable(args[0], bound);
425
+ /** Whether a run's process may remove setting `key`: only its own run's browser rows (ownWrittenSettings), and only one no
426
+ * later claim wrote (removeOwnRow, which reads the row). */
427
+ const removableSetting = (args, bound) => typeof args[0] === "string" && ownWrittenSettings(bound).has(args[0]);
428
+ /** The remove of one of the claim's own browser rows (removableSetting): a row a later claim of the run wrote stays, as
429
+ * a write takes only the claim's own epoch (writableSetting), so a claim still closing never clears the take or the
430
+ * ended wait of the claim that holds the run now. The row goes only while it is the one read (Settings.removeIf), so a
431
+ * later claim's write that lands between the read and the remove stays too. A key with no row is left as it is. */
432
+ async function removeOwnRow(settings, key, bound, log) {
433
+ const row = await settings.get(key);
434
+ if (row === undefined)
435
+ return;
436
+ const epoch = typeof row === "object" && row !== null ? row.epoch : undefined;
437
+ if (typeof epoch === "number" && epoch > bound.claim.epoch) {
438
+ log(`run ${bound.claim.runId}: its process asked the store for settings.remove of ${key}, which a later claim (epoch ${epoch}) wrote and a run's process may not remove`);
439
+ throw new ClaimRefused("a run's process may not call the store's settings.remove of a row a later claim wrote");
440
+ }
441
+ await settings.removeIf(key, row);
442
+ }
443
+ /** Whether a run's process may write `value` to setting `key`: one of its own run's browser rows, with that row's fields
444
+ * alone, each a string, the claim's own epoch, and at most OWN_ROW_MAX_BYTES. A row with a later epoch would be kept by
445
+ * every clear of this claim (browser-hold.ts), so a later claim would read a take nobody holds. */
446
+ const writableSetting = ([key, value], bound) => {
447
+ const fields = typeof key === "string" ? ownWrittenSettings(bound).get(key) : undefined;
448
+ if (!fields || typeof value !== "object" || value === null || Array.isArray(value))
449
+ return false;
450
+ const row = value;
451
+ return Object.keys(row).length === fields.length + 1 && row.epoch === bound.claim.epoch && fields.every((field) => typeof row[field] === "string")
452
+ && Buffer.byteLength(JSON.stringify(row)) <= OWN_ROW_MAX_BYTES;
453
+ };
407
454
  /** The store's methods a run's loop calls, each with what binds it to the claim. A method not here is refused, and the
408
455
  * refusal is said on the runner's log. Reads of the claim's run, its launch, its commands and its agent's revisions;
409
456
  * of what was spent beside it (its learning grades, its own audit's shadow run's row and launch, which its cap gates
@@ -426,6 +473,8 @@ const STORE_CALLS = new Map([
426
473
  ["agents.revision", always],
427
474
  ["agents.revisions", ownAgent],
428
475
  ["settings.get", readableSetting],
476
+ ["settings.put", writableSetting],
477
+ ["settings.remove", removableSetting],
429
478
  // Its rows filtered to the readable ones (storeCall).
430
479
  ["settings.all", always],
431
480
  ["mcp.pin", ownRun],
@@ -454,6 +503,8 @@ export async function storeCall(store, method, args, bound, log) {
454
503
  }
455
504
  if (method === "readJournal")
456
505
  return journalRead(store, args);
506
+ if (method === "settings.remove")
507
+ return removeOwnRow(store.settings, args[0], bound, log);
457
508
  const path = method.split(".");
458
509
  let target = store;
459
510
  for (const part of path.slice(0, -1))
@@ -610,6 +661,8 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
610
661
  };
611
662
  const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
612
663
  const github = () => githubAppAccess(store, sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
664
+ /** The run's folder as the computer this claim made mounts it (Mode 2), where the claim's MCP files once it is made. */
665
+ let mountedFolder;
613
666
  /** Mode 2's Archil claim, made once for the claim on the runner, its folder the run's. */
614
667
  let archil;
615
668
  const archilOf = () => (archil ??= (async () => {
@@ -624,9 +677,14 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
624
677
  * handed none of the server's (claim-secrets.ts keyedAtClaim, held here for the runner's answers). */
625
678
  const runKeyed = async () => (await openRunModelKey(keys, claim.runId)) !== undefined;
626
679
  /** Whether the claim's run is held, its model kept from running at its create (hold.refused): it routes no model, so
627
- * whatever its process asks, the runner hands it no model key, answers it keyless and refuses it a learning step (its
628
- * learned workflows and its end-of-run step), as its spec asks for none of them (adapter-run-spec.ts, cli-run-spec.ts). */
680
+ * whatever its process asks, the runner hands it no model key (keyless, below), answers it keyless, opens it no harness
681
+ * key and no MCP, and refuses it a learning step (its learned workflows and its end-of-run step), as its spec asks for
682
+ * none of them (adapter-run-spec.ts, cli-run-spec.ts). */
629
683
  const modelRefused = launch.hold?.refused !== undefined;
684
+ /** Whether the claim's run sends no model key (claim-secrets.ts sendsNoModelKey: a held run as above, any run on a --faux
685
+ * runner, a faux-pinned one; `deps.env` is the claim's environment): the runner answers its process no tier's model key.
686
+ * A faux run still runs its learned steps on the faux model: only modelRefused refuses them. */
687
+ const keyless = sendsNoModelKey(launch, deps.env ?? {});
630
688
  const refusedSpend = () => new ClaimRefused("a held run its model kept from running asks its runner for no model spend: it routes no model and takes no learning step");
631
689
  const learningFolder = async () => {
632
690
  const made = await archilOf();
@@ -707,16 +765,76 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
707
765
  return undefined;
708
766
  return { state: plan.state, models: [...plan.models], token: () => plan.token(), refused: (sent) => plan.refused(sent), watch: (listener) => plan.watch(listener) };
709
767
  },
768
+ // The claim's own login, as this runner reads the claim (its harness, its place, no model key of its own), whatever
769
+ // the process names: its access token alone, read again at each ask and renewed here when it must be (near its end,
770
+ // or refused); never its folder or its refresh token. Each token is carried into the runner's redactor for this run
771
+ // (redact.ts carry) before it is handed, a renewed one too: model text that repeats it is cut from the run's journal
772
+ // as the runner writes it (runner.ts fenced), from what it stages and from its rows, as the run's own tool keys are.
773
+ // This answer is the one decision whether the run goes on the login: none, it does not. Its claim read the setting
774
+ // (staysInRunner); a claim that read it off is never put on it, whatever the setting says now. A claim that read it on
775
+ // has it read again here, at the start, with the claim's settings, data folder, harness and place. Its environment is
776
+ // the claim's (the process's, when the runner was given none) with a saved gateway laid over it (withSavedGatewayDeps),
777
+ // not always the very one the claim read with; that
778
+ // difference can only refuse the start, never hand another folder, since the login is handed only when both reads name
779
+ // the same folder: a turn-off, or a move to another folder,
780
+ // between the claim and the start refuses the start in LOGIN_CHANGED_SINCE_CLAIM's fixed words (no folder in them),
781
+ // never a start on a login the setting no longer names nor a fall to a model key the run was not claimed on. Nothing
782
+ // else of the claim is read again. A run with a model key of its own, and a login other than AgentRun's own folder,
783
+ // were each decided at the claim (staysInRunner: no login read for the one, LOGIN_MACHINE_NEEDS_SERVER_USER for the
784
+ // other), so neither reaches here on a login. The process reads no setting or machine id.
785
+ // None for a run that sends no model key (keyless: a held run, any run on a --faux runner, a faux-pinned one), whatever
786
+ // its claim read: the login is a model credential like any key.
787
+ claudeLogin: async () => {
788
+ if (keyless)
789
+ return undefined;
790
+ const at = reads.login;
791
+ if (!at)
792
+ return undefined;
793
+ const now = await loginForRun(store.settings, deps.data, deps.env ?? {}, harnessOfBody(launch), launch.place);
794
+ if (now?.dir !== at.dir)
795
+ throw new ClaimRefused(LOGIN_CHANGED_SINCE_CLAIM);
796
+ const carry = cut.carry;
797
+ if (!carry)
798
+ throw new ClaimRefused("This runner has no redactor that can cut the login's token from what its run writes, so it hands none.");
799
+ // Each renewal's outcome on the runner's log, in the server's line (print.ts logLine) under event claude_login:
800
+ // fixed words, a status and an OAuth error code, never a token.
801
+ const tokens = loginTokensFor(at, (fields) => log(logLine("claude_login", fields)));
802
+ return {
803
+ token: async () => {
804
+ const token = await tokens.token();
805
+ carry.call(cut, claim.runId, [token]);
806
+ return token;
807
+ },
808
+ refused: (sent) => tokens.refused(sent),
809
+ };
810
+ },
710
811
  signInReadsBack: () => handedSignInReadsBack(store, sealKey, run),
711
812
  runSignIn: (resolution) => {
712
813
  const vendorFetch = async () => (claimed[FAUX_ENV] ? fauxFetch(claimed, FAUX_VENDOR_API_ENV) : fetch);
713
814
  return runSignIn(store, sealKey, claim, String(resolution), { vendors: vendorsOver(() => claimed, vendorFetch), log });
714
815
  },
715
816
  verifySignIn: (kept, at) => verifyRunSignIn(store, sealKey, claim, kept, Number(at)),
817
+ // None for a held run its model kept from running: nothing can call it, so no credential of it is opened.
716
818
  mcp: (ask) => projectCall(async () => {
819
+ if (modelRefused)
820
+ return undefined;
717
821
  const reach = await mcpReachOf(deps);
718
822
  const harness = { commit: (change) => change({ appendEntry: async (_conversation, entry) => void (await ask.appendRoot(dataOnly(entry))) }) };
719
- const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, run.agentId, launch) });
823
+ // What the gateway files goes in the run's own files. In Mode 1 that is the run's folder on this machine. In Mode 2
824
+ // it is the run's disk: through the computer this claim made once it mounts the folder (mountedFolder, the computer
825
+ // answer's), since the mount holds the disk's write delegation; over the disk's file API when no computer mounts it.
826
+ // That Workspace is opened at the first answer that files something, not at the claim: a claim whose MCP files
827
+ // nothing opens none (an open lists the run's folder, and makes it when it is missing). It only writes files over the
828
+ // disk's file API and runs no command, so it sweeps no exec spill folder, at its open or at its end (sweep: false): it
829
+ // opens mid-run, beside the archil answer's Workspace, whose commands may still be reading their spill files there.
830
+ // Opened once, and let go at the claim's release; an open that failed is tried again at the next answer. Its release is
831
+ // registered here, before any open, so an open still running at the release is ended too, and a filing after it opens
832
+ // nothing (openedAtUse). work() is read only when a call's answer files something (mcp-gateway.ts textOf, fileResults).
833
+ const disk = await archilOf();
834
+ const overTheDisk = disk === undefined ? undefined : openedAtUse(() => openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: disk, sweep: false, log }));
835
+ if (overTheDisk)
836
+ releases.push(() => overTheDisk.end());
837
+ const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => (overTheDisk === undefined ? runFolder(deps.data, run.agentId, claim.runId) : mountedFolder ?? overTheDisk.workspace()), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, undefined, launch) });
720
838
  if (!made)
721
839
  return undefined;
722
840
  releases.push(() => made.release());
@@ -748,29 +866,32 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
748
866
  };
749
867
  return { api: access.api, target: bound, mint, ...(access.revoke ? { revoke: access.revoke } : {}), ...(access.same ? { same: access.same } : {}) };
750
868
  },
751
- savedModelKeys: async () => {
752
- // Only a run whose routes have no revision to scope their keys by: a subagent's tiers, a learning run's grade, an SDK
753
- // run's grade. And never for a run that holds a key of its own (its launch's, read now): the server's keys are not
754
- // its to spend, whatever its process asks; nor for a held run its model kept from running, which routes no model.
755
- const reads = !modelRefused && (granted.includes(SUBAGENT_TOOL) || launch.harness === "learning" || launch.sdk !== undefined);
756
- // A replay's or an audit's grade (adapter-run-spec.ts graderRouteOf): its fast model may be another provider's than
757
- // its agent's, its key saved alone, which the claim's own keys never hold. Least privilege: the agent's tools run in
758
- // this process tree, so only that one provider's saved keys (a gateway route's: the gateway's key alone) cross the
759
- // pipe, filtered here, never the rest; none when the revision has no fast model, and none for a held run its model
760
- // kept from running, which grades nothing.
761
- const grades = !modelRefused && (launch.replay !== undefined || launch.audit !== undefined);
762
- const keyed = await runKeyed();
763
- if (!reads && !grades)
869
+ subagentTierKeys: async () => {
870
+ // A subagent's tiers alone: an agentic run granted the subagent tool routes each tier its revision's modelTiers or
871
+ // the host's tier variable names, and no other (adapter-run-spec.ts), so its process is handed those tiers' models'
872
+ // keys (tierModelKeys, the revision's model of a tier over the host's): never a provider's no tier of it reaches, nor
873
+ // a key for a tier it routes no model on. A replay's or an audit's grade (adapter-run-spec.ts graderRouteOf) routes
874
+ // the fast tier of that same answer, whose model may be another provider's than its agent's: its process is handed
875
+ // that tier's model's key alone (through a gateway, the gateway's), none when the revision names agree_on (no
876
+ // grader). A learning run's grade and an SDK run's compile turn stay in the runner (runsInRunner): their process
877
+ // never asks, and gets none. And never for a run that holds a key of its own (its launch's, read now): the server's
878
+ // keys are not its to spend, whatever its process asks; nor for a run that sends no model key (keyless: a held run,
879
+ // which routes no model and grades nothing, or a faux one, whose model sends none).
880
+ const subagent = !keyless && revision.kind === "agentic" && granted.includes(SUBAGENT_TOOL);
881
+ const grades = !keyless && (launch.replay !== undefined || launch.audit !== undefined) && !agreeOnOf(revision.body.learning)?.length;
882
+ if (!subagent && !grades)
764
883
  return {};
765
- const saved = stringsOf(keyed ? {} : await savedModelKeys(keys));
766
- return reads ? saved : stringsOf(routeModelKeys(saved, keys.env ?? {}, graderModelOf(revision.body, keys.env ?? {})));
884
+ const { tiers, refs } = routedSubagentTiers(revision.body, keys.env ?? {});
885
+ const keyed = await runKeyed();
886
+ return stringsOf(keyed ? {} : await tierModelKeys(keys, subagent ? tiers : tiers.filter((tier) => tier === "fast"), refs));
767
887
  },
768
888
  tierModelKeys: async (tiers) => {
769
889
  // The tiers the claim's learned workflows name (learnedTiers), as this runner chose them (learnedFirst below): a
770
890
  // tier the process names beyond them gets no key, and none before the choice (a held run its model kept from running
771
- // makes none: its learnedFirst is refused).
891
+ // makes none: its learnedFirst is refused), nor to a run that sends no model key (keyless: a faux one's tiers run on
892
+ // the faux model).
772
893
  const asked = new Set(tiers.filter((tier) => typeof tier === "string"));
773
- const named = !modelRefused && learnsWorkflows(revision.kind, learnedFlows) ? learnedTiers(learnedFlows).filter((tier) => asked.has(tier)) : [];
894
+ const named = !keyless && learnsWorkflows(revision.kind, learnedFlows) ? learnedTiers(learnedFlows).filter((tier) => asked.has(tier)) : [];
774
895
  const keyed = await runKeyed();
775
896
  const got = keyed ? {} : await tierModelKeys(keys, named);
776
897
  const plan = planOf(got);
@@ -792,9 +913,10 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
792
913
  // harness is a plan-billed recipe on this runner's table, and never another harness's. Opened for the recipe file
793
914
  // the process loaded (`digest`), never the one this runner's table read at its start: a file swapped for another
794
915
  // vendor's under the same id since then runs its own binary, and a key bound to the first file never opens for it.
916
+ // None for a held run its model kept from running: its agent never starts.
795
917
  harnessKeys: async (digest) => {
796
918
  const harness = launch.harness ?? revision.body.harness;
797
- const recipe = harness === undefined ? undefined : planRecipeOf(deps.env, harness);
919
+ const recipe = harness === undefined || modelRefused ? undefined : planRecipeOf(deps.env, harness);
798
920
  return recipe?.keys.length && typeof digest === "string" ? openHarnessKeys(store, sealKey, { ...recipe, digest }) : {};
799
921
  },
800
922
  liveViewerPut: (handover) => putLiveViewer(store, sealKey, claim, handover),
@@ -837,13 +959,21 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
837
959
  hadComputer: async () => (await ask.hadComputer()) === true,
838
960
  ...(typeof ask.turnedOff === "string" ? { turnedOff: ask.turnedOff } : {}),
839
961
  ...(ask.signal instanceof AbortSignal ? { signal: ask.signal } : {}),
840
- ...(made ? { revokeMount: () => made.revoke(), inheritMount: () => made.inherit() } : {}),
962
+ ...(made ? { revokeMount: () => made.revoke(), inheritMount: () => made.inherit(), mountDisk: () => made.disk.id } : {}),
841
963
  ...(typeof ask.onImageWait === "function" ? { onImageWait: ask.onImageWait } : {}),
842
964
  ...(typeof ask.onStarting === "function" ? { onStarting: ask.onStarting } : {}),
843
965
  ...(typeof ask.onConnected === "function" ? { onConnected: ask.onConnected } : {}),
844
966
  ...(typeof ask.onComputerNote === "function" ? { onComputerNote: ask.onComputerNote } : {}),
845
967
  });
846
968
  releases.push(() => ws.end());
969
+ // A Mode 2 computer that mounts the run's folder holds the disk's write delegation: what the claim's MCP files then
970
+ // goes through it, attached here as the run's process attaches it. A failed attach leaves the MCP on the disk's file
971
+ // API, which says in its answer that the file could not be saved.
972
+ if (mode === 2)
973
+ mountedFolder = await attachedIn(ws.workspace, got?.computer).catch((error) => {
974
+ log(`the run's folder could not be attached for the MCP's files: ${error?.message ?? String(error)}`);
975
+ return undefined;
976
+ });
847
977
  // The computer let go by this runner at the claim's release too, before its folder: a process that crashed or broke
848
978
  // its channel never calls its release. Idempotent with the process's own release and with its park (which keeps it).
849
979
  const claimed = got;
@@ -856,7 +986,10 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
856
986
  const { syncProject: _sync, ...exposed } = got;
857
987
  return { ...exposed, ...(exposed.computer ? { computer: projectGate.capability(exposed.computer) } : {}),
858
988
  release: (...args) => cleanProject(() => exposed.release(...args)),
859
- ...(exposed.park ? { park: (...args) => cleanProject(() => exposed.park(...args)) } : {}) };
989
+ ...(exposed.park ? { park: (...args) => cleanProject(() => exposed.park(...args)) } : {}),
990
+ // The park's keep written ahead of it lands the folder's delta first, so it waits for the project's work as the
991
+ // park does.
992
+ ...(exposed.keepRow ? { keepRow: () => cleanProject(() => exposed.keepRow()) } : {}) };
860
993
  }
861
994
  return got;
862
995
  }),
@@ -1038,19 +1171,16 @@ export const childArgv = () => [process.execPath, "--import", new URL("../secret
1038
1171
  * A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
1039
1172
  * connectors, whose rows are the server's. */
1040
1173
  export const runsInRunner = (harness, launch) => harness === "learning" || Boolean(launch.sdk) || Boolean(launch.native) || Boolean(launch.cli_learning);
1041
- /** The words a run on Claude Code's login on this machine is refused in where each run is a user of its own. */
1042
- export const LOGIN_NEEDS_SERVER_USER = `A run on Claude Code's login on this machine needs runs under the server's own user, and this runner runs each run as a user of its own: set ${RUN_USER_ENV}=same, or give the run a model_key.`;
1174
+ /** The words a run on this machine's own Claude Code login (the `machine` place: claude-login.ts machineFolder, ~/.claude
1175
+ * or the server's CLAUDE_CONFIG_DIR) is refused in where each run is a user of its own: only AgentRun's own login folder
1176
+ * is handed to such a run, as its access token. */
1177
+ export const LOGIN_MACHINE_NEEDS_SERVER_USER = `A run on this machine's own Claude Code login (~/.claude, or the CLAUDE_CONFIG_DIR AgentRun was started with) needs runs under the server's own user, and this runner runs each run as a user of its own: switch to AgentRun's own login folder under Settings → Model keys, set ${RUN_USER_ENV}=same, or give the run a model_key.`;
1178
+ /** The words a run on the login is refused in where each run is a user of its own while runner `other`, on the same data
1179
+ * folder, runs its runs on the login in its own process, whose CLI renews the login in that folder itself. */
1180
+ export const loginRunnerInProcessWords = (other) => `This runner runs each run as a user of its own, and runner ${other} on the same data folder runs Claude Code's login runs in its own process, whose CLI renews that login itself: stop ${other}, set ${RUN_USER_ENV}=same on this runner too, or give the run a model_key.`;
1043
1181
  /** The words a run on a harness recipe is refused in where each run is a user of its own (harness-table.ts recipeHarness). */
1044
1182
  export const RECIPE_NEEDS_SERVER_USER = `A run on a harness recipe needs runs under the server's own user, since its install, its check and its owner's sign-in are that user's alone, and this runner runs each run as a user of its own: set ${RUN_USER_ENV}=same on this runner.`;
1045
1183
  export { RECIPE_SIGN_IN_PERSON_ONLY } from "./harness-loops.js";
1046
- /** Whether run `runId` stays in its runner's process: runsInRunner's, and a workflow run on a server with a documents
1047
- * directory (launch.documents), whose reads and writes (a pdf_pages call's pages) are rooted in a folder the server's
1048
- * user holds and no slot's user is given; its nodes run the server's own tools alone, no agent's code. A run on Claude
1049
- * Code's login on this machine (claude-login.ts loginForRun) needs the login in the server's own folder, which its CLI
1050
- * reads and refreshes: where runs are the runner's own user (`process`) it stays in the runner; where each run is a user
1051
- * of its own (`uid`) it is refused at its claim (ClaimRefused, the run failed in words naming the setting), never run as
1052
- * the server's user. A run its caller handed a model key (model_key) runs on that key and never on the login
1053
- * (cli-run-spec.ts), so it is a process of its own like any other. */
1054
1184
  export async function staysInRunner(deps, harness, launch, runId, isolation) {
1055
1185
  // A recipe's harness reads its install, its check's note and its owner's sign-in, each the server user's alone: never
1056
1186
  // opened to a slot's user (the sign-in least of all), so where each run is a user of its own it is refused here. And a
@@ -1060,32 +1190,45 @@ export async function staysInRunner(deps, harness, launch, runId, isolation) {
1060
1190
  throw new ClaimRefused(RECIPE_NEEDS_SERVER_USER);
1061
1191
  await refuseRecipeTriggerRun(deps, harness, launch);
1062
1192
  if (runsInRunner(harness, launch))
1063
- return true;
1193
+ return STAYS;
1064
1194
  if (launch.documents !== undefined) {
1065
1195
  const run = await deps.store.runs.get(runId);
1066
1196
  const revision = run ? await deps.store.agents.revision(run.revisionId) : undefined;
1067
1197
  if (revision && isWorkflowRevision(revision))
1068
- return true;
1198
+ return STAYS;
1069
1199
  }
1070
- if ((await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, harness, launch.place)) === undefined)
1071
- return false;
1200
+ const login = await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, harness, launch.place);
1201
+ if (login === undefined)
1202
+ return OFF_LOGIN;
1072
1203
  if ((await openRunModelKey({ store: deps.store, sealKey: deps.sealKey }, runId)) !== undefined)
1073
- return false;
1074
- if (isolation.kind === "uid")
1075
- throw new ClaimRefused(LOGIN_NEEDS_SERVER_USER);
1076
- return true;
1204
+ return OFF_LOGIN;
1205
+ if (isolation.kind !== "uid")
1206
+ return STAYS;
1207
+ if (!agentRunLogin(login, deps.data))
1208
+ throw new ClaimRefused(LOGIN_MACHINE_NEEDS_SERVER_USER);
1209
+ const other = await loginRunnerInProcess(deps.data, deps.store.runners);
1210
+ if (other !== undefined)
1211
+ throw new ClaimRefused(loginRunnerInProcessWords(other));
1212
+ return { stays: false, login };
1077
1213
  }
1214
+ const STAYS = { stays: true };
1215
+ const OFF_LOGIN = { stays: false, login: undefined };
1078
1216
  /** The runner's loop factory where each run is a process of its own: a ChildLoop per claim, but for a run that stays in
1079
1217
  * the runner (staysInRunner). */
1080
1218
  export function childLoops(options) {
1081
1219
  // Each slot locked on the data directory too: another runner on it whose range overlaps this one's never runs a run
1082
1220
  // on a slot this one holds.
1083
1221
  const slots = options.isolation.kind === "uid" ? new Slots(options.isolation.first, options.isolation.slots, slotLocks(options.deps.data)) : undefined;
1084
- const own = (loopDeps) => childLoop(options, slots, loopDeps);
1085
1222
  const here = resolveRunnerLoop(options.deps);
1086
1223
  return createDispatchLoop({
1087
1224
  launchOf: (runId) => options.deps.store.runs.launch(runId),
1088
- resolve: async (harness, launch, runId) => ((await staysInRunner(options.deps, harness, launch, runId, options.isolation)) ? here(harness, launch, runId) : own),
1225
+ resolve: async (harness, launch, runId) => {
1226
+ const place = await staysInRunner(options.deps, harness, launch, runId, options.isolation);
1227
+ if (place.stays)
1228
+ return here(harness, launch, runId);
1229
+ const own = (loopDeps) => childLoop(options, slots, loopDeps, place.login);
1230
+ return own;
1231
+ },
1089
1232
  });
1090
1233
  }
1091
1234
  registerRunErrors();
@@ -1096,12 +1239,6 @@ function withGatewayKey(claimed, key) {
1096
1239
  Object.defineProperty(out, GATEWAY_KEY_ENV, { value: key, enumerable: false, writable: false, configurable: false });
1097
1240
  return out;
1098
1241
  }
1099
- /** The pair a run's process is handed this runner's OpenTelemetry settings in (secrets.ts OTEL_PAIR): none when it has
1100
- * none. */
1101
- export const otelPair = (env = process.env) => {
1102
- const settings = otelSettings(env);
1103
- return Object.keys(settings).length ? [[OTEL_PAIR, JSON.stringify(settings)]] : [];
1104
- };
1105
1242
  /** The environment a run's process starts with: the runner's run environment's plain values (runEnv: its secrets are
1106
1243
  * not enumerable, so none is here), no key-shaped name, and where its keys come from. */
1107
1244
  function childEnv(base, keys, extra) {
@@ -1124,7 +1261,8 @@ export function runChannel(socket, onClose, gate = SERVER_SLOTS, more = {}) {
1124
1261
  saves = exposeSaveSlots(channel, gate);
1125
1262
  return channel;
1126
1263
  }
1127
- function childLoop(options, slots, loopDeps) {
1264
+ /** `login`: the Claude login this run's claim read (staysInRunner), the one its runner hands the run (ClaimReads). */
1265
+ function childLoop(options, slots, loopDeps, login) {
1128
1266
  const { deps, isolation } = options;
1129
1267
  const cut = loopDeps.redact ?? ((text) => text);
1130
1268
  const log = (line) => options.log(cut(line));
@@ -1206,33 +1344,26 @@ function childLoop(options, slots, loopDeps) {
1206
1344
  const savedGateway = savedGatewayIn(claimEnv);
1207
1345
  // The run's own keys: those its claim opens (claim-secrets.ts), the one list its loop in this process read. Its model
1208
1346
  // keys are its pinned model's (claimSecrets scopes them by the launch's model), the one its route sends: never the
1209
- // host's default's now, where its revision names no model and a key saved since moved that default.
1347
+ // host's default's now, where its revision names no model and a key saved since moved that default. On a --faux
1348
+ // runner, or pinned to the faux model, a run sends no model key (claim-secrets.ts sendsNoModelKey): its process is
1349
+ // handed none, not even its revision's model's.
1210
1350
  const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, launch, claim.runId);
1211
- // A --faux start alone is pinned to the faux model (model.ts chooseModel), which stands in for its revision's and
1212
- // sends no key: its process is handed its revision's model's key with them, as a run of that model is handed it. A
1213
- // held run its model kept from running at its create (hold.refused) is laid no model key here either: its model runs
1214
- // nowhere.
1215
- const ofRevision = launch.model?.provider === FAUX_PROVIDER ? await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}), ...(launch.hold ? { hold: launch.hold } : {}) }) : {};
1216
1351
  // A run that holds a model key of its own (model_key, its launch's) spends that key alone: its process is handed
1217
1352
  // none of the server's model keys, as its spec drops them from its tools' (claim-secrets.ts withoutModelKeys).
1218
1353
  // Copies: the runner's own reads (heldFor's `claimed`: what the run's learning must never keep) stay whole.
1219
1354
  const keyed = (await openRunModelKey({ store: deps.store, sealKey: deps.sealKey }, claim.runId)) !== undefined;
1220
- const toProcess = keyed ? [withoutModelKeys({ ...claimed }), withoutModelKeys({ ...ofRevision })] : [claimed, ofRevision];
1355
+ const toProcess = keyed ? withoutModelKeys({ ...claimed }) : claimed;
1221
1356
  // The saved gateway's key, kept off the claim's tool keys (claimSecrets), is handed for the run's model routes alone,
1222
1357
  // read as the server's model keys are (savedModelKeys, over the claim's environment the gateway was laid over), as a
1223
1358
  // run in this process reads it from its environment by name; none to a run that brings its own key, and none to a
1224
- // held run its model kept from running, which routes no model.
1225
- const gatewayKey = savedGateway && !launch.hold?.refused ? (keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }))[GATEWAY_KEY_ENV] || undefined : undefined;
1226
- const handed = (name) => (name === GATEWAY_KEY_ENV && savedGateway ? gatewayKey : toProcess.map((from) => from[name]).find((value) => typeof value === "string" && value !== ""));
1227
- const keys = encode([
1228
- ...SECRET_NAMES.flatMap((name) => {
1229
- const value = handed(name);
1230
- return value === undefined ? [] : [[name, value]];
1231
- }),
1232
- // The runner's OpenTelemetry settings, so the run's process exports its trace as this one would: on the pipe,
1233
- // since no run's environment has them (runEnv), never in the process's environment.
1234
- ...otelPair(),
1235
- ]);
1359
+ // run whose model sends no key (sendsNoModelKey: a held run its model kept from running, any run on a --faux runner,
1360
+ // a faux-pinned one).
1361
+ const gatewayKey = savedGateway && !sendsNoModelKey(launch, claimEnv) ? (keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }))[GATEWAY_KEY_ENV] || undefined : undefined;
1362
+ const handed = (name) => (name === GATEWAY_KEY_ENV && savedGateway ? gatewayKey : toProcess[name] || undefined);
1363
+ const keys = encode(SECRET_NAMES.flatMap((name) => {
1364
+ const value = handed(name);
1365
+ return value === undefined ? [] : [[name, value]];
1366
+ }));
1236
1367
  const slot = await slots?.take();
1237
1368
  if (slots && slot === undefined) {
1238
1369
  // Every free slot of this runner is held by another runner on the data directory (ranges that overlap): the run
@@ -1254,8 +1385,17 @@ function childLoop(options, slots, loopDeps) {
1254
1385
  const tops = runTops(deps.data, runRow.agentId, claim.runId);
1255
1386
  // The run's pieced writes (big-writes.ts): let go when its channel ends, or at the claim's release.
1256
1387
  const bigs = runBigWrites();
1257
- const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed, signal: loopDeps.signal, ...(loopDeps.incarnation ? { incarnation: loopDeps.incarnation } : {}) }, cut, log, bigs);
1388
+ const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed, signal: loopDeps.signal, login, ...(loopDeps.incarnation ? { incarnation: loopDeps.incarnation } : {}) }, cut, log, bigs);
1389
+ // The run's trace: its process posts each call of it (tracer.ts postedTracing), and this runner's tracing makes the
1390
+ // spans and exports them in the background. No exporter, flush or OTLP setting is ever the process's, so neither
1391
+ // its exit nor this claim's release waits on a collector. Made inside the claim's cleanup, so nothing it waits on
1392
+ // can keep the slot.
1393
+ let traced;
1258
1394
  try {
1395
+ const tracing = await (options.tracing ?? genAiTracing()).catch(() => undefined);
1396
+ // Its agent is the one this runner reads from the store, never one the process posts; a read that fails is the
1397
+ // agent's id alone (agentOfRun).
1398
+ traced = tracing ? tracePosts(tracing, claim.runId, cut, await agentOfRun(deps.store.agents, runRow.agentId)) : undefined;
1259
1399
  let extra = {};
1260
1400
  let argv = [...(options.argv ?? childArgv())];
1261
1401
  // A claim that resumes a run whose last runner ended before giving its folders back finds them its last slot's,
@@ -1274,7 +1414,8 @@ function childLoop(options, slots, loopDeps) {
1274
1414
  argv = [isolation.helper, "run", String(slot), "--keep-fd", "3", "--keep-fd", "4", "--", ...argv];
1275
1415
  }
1276
1416
  // The saved gateway's address and models go as plain variables (childEnv), and its mark says they are the saved one.
1277
- const env = childEnv(claimEnv, keys, savedGateway ? { ...extra, [SAVED_GATEWAY_ENV]: "1" } : extra);
1417
+ // The server's keyless holds now (web-holds.ts), so the run's Web starts with them: hold data alone.
1418
+ const env = childEnv(claimEnv, keys, { ...extra, ...holdsEnv(), ...(savedGateway ? { [SAVED_GATEWAY_ENV]: "1" } : {}) });
1278
1419
  const [program, ...rest] = argv;
1279
1420
  child = spawn(program, rest, { stdio: ["ignore", "inherit", "inherit", "pipe", "pipe"], env, detached: true });
1280
1421
  exited = new Promise((resolve) => {
@@ -1294,6 +1435,9 @@ function childLoop(options, slots, loopDeps) {
1294
1435
  const bound = { claim, agentId: runRow.agentId, revisionId: runRow.revisionId };
1295
1436
  channel.expose("store", (method, args) => storeCall(deps.store, method, args, bound, log));
1296
1437
  channel.expose("journal", journalTarget(loopDeps.journal(claim), cut));
1438
+ const posts = traced;
1439
+ if (posts)
1440
+ channel.expose("trace", (method, args) => posts.post(method, args));
1297
1441
  channel.expose("held", (method, args) => {
1298
1442
  // Its own members alone: a name of Object's prototype (constructor, toString) is no call of Held.
1299
1443
  const fn = Object.hasOwn(heldSide.held, method) ? heldSide.held[method] : undefined;
@@ -1315,6 +1459,8 @@ function childLoop(options, slots, loopDeps) {
1315
1459
  return undefined;
1316
1460
  case "log":
1317
1461
  return void log(String(args[0]));
1462
+ case "webHold":
1463
+ return void noteHold(args[0]);
1318
1464
  default:
1319
1465
  throw new ClaimRefused(`the runner has no ${method} for a run`);
1320
1466
  }
@@ -1322,7 +1468,7 @@ function childLoop(options, slots, loopDeps) {
1322
1468
  loopDeps.live?.(() => latest);
1323
1469
  const reach = await mcpReachOf(deps);
1324
1470
  const init = {
1325
- claim, data: deps.data, signal: loopDeps.signal, where: deps.store.where,
1471
+ claim, data: deps.data, signal: loopDeps.signal, where: deps.store.where, ...(traced ? { traced: true } : {}),
1326
1472
  ...(reach.loopback ? { mcpLoopback: true, mcpOwn: reach.own ?? [] } : {}),
1327
1473
  ...(deps.githubApi ? { githubApi: deps.githubApi } : {}),
1328
1474
  ...(deps.githubWeb ? { githubWeb: deps.githubWeb } : {}),
@@ -1350,6 +1496,8 @@ function childLoop(options, slots, loopDeps) {
1350
1496
  }
1351
1497
  finally {
1352
1498
  ready();
1499
+ // A process gone before it ended its trace: its spans end with the claim (after its own end, a no-op).
1500
+ await traced?.end("run-error");
1353
1501
  await heldSide.projectEnd?.();
1354
1502
  const reaped = await end(slot, tops).catch((error) => {
1355
1503
  log(`run ${claim.runId}: its process's end failed: ${error?.message ?? error}`);