@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37

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 (325) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +158 -52
  3. package/dist/attach-conformance-cli.d.ts +1 -0
  4. package/dist/attach-conformance-cli.js +18 -0
  5. package/dist/attach-conformance.d.ts +25 -0
  6. package/dist/attach-conformance.js +343 -0
  7. package/dist/browser-cost.d.ts +1 -1
  8. package/dist/browser-live.d.ts +20 -8
  9. package/dist/browser-live.js +50 -27
  10. package/dist/cap.d.ts +0 -17
  11. package/dist/cap.js +0 -91
  12. package/dist/catalog.d.ts +1 -12
  13. package/dist/catalog.js +3 -33
  14. package/dist/cli.js +13 -4
  15. package/dist/composio-preset.d.ts +36 -0
  16. package/dist/composio-preset.js +179 -0
  17. package/dist/computer-attach.d.ts +125 -0
  18. package/dist/computer-attach.js +330 -0
  19. package/dist/computer-calls.d.ts +48 -0
  20. package/dist/computer-calls.js +126 -0
  21. package/dist/computer-channel.d.ts +57 -0
  22. package/dist/computer-channel.js +115 -0
  23. package/dist/computer-commands.d.ts +1 -1
  24. package/dist/computer-held-routes.d.ts +35 -0
  25. package/dist/computer-held-routes.js +106 -0
  26. package/dist/computer-held.d.ts +48 -0
  27. package/dist/computer-held.js +87 -0
  28. package/dist/computer-keys.d.ts +21 -1
  29. package/dist/computer-keys.js +53 -11
  30. package/dist/computer-live.d.ts +160 -0
  31. package/dist/computer-live.js +643 -0
  32. package/dist/computer-view.d.ts +13 -0
  33. package/dist/computer-view.js +50 -3
  34. package/dist/computer-viewer.d.ts +6 -0
  35. package/dist/computer-viewer.js +297 -0
  36. package/dist/computers.d.ts +33 -7
  37. package/dist/computers.js +50 -8
  38. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  39. package/dist/console/assets/index-DRN62V5v.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/faux-computers.d.ts +9 -20
  42. package/dist/faux-computers.js +53 -25
  43. package/dist/github-connection.d.ts +10 -2
  44. package/dist/github-connection.js +65 -2
  45. package/dist/github-faux.js +1 -1
  46. package/dist/graph-view.d.ts +1 -1
  47. package/dist/harness.d.ts +1 -0
  48. package/dist/harness.js +35 -1
  49. package/dist/host-tools.d.ts +1 -1
  50. package/dist/hosted-search.d.ts +5 -4
  51. package/dist/hosted-search.js +2 -7
  52. package/dist/import-sources.d.ts +10 -0
  53. package/dist/import-sources.js +44 -2
  54. package/dist/import.d.ts +3 -3
  55. package/dist/import.js +37 -6
  56. package/dist/learn/check.d.ts +4 -1
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +4 -2
  59. package/dist/learn/commit.js +5 -5
  60. package/dist/learn/folder.d.ts +6 -0
  61. package/dist/learn/folder.js +4 -1
  62. package/dist/learn/general.d.ts +66 -0
  63. package/dist/learn/general.js +73 -0
  64. package/dist/learn/grade.d.ts +4 -0
  65. package/dist/learn/grade.js +22 -1
  66. package/dist/learn/reflect.d.ts +10 -1
  67. package/dist/learn/reflect.js +14 -4
  68. package/dist/learn/skills.d.ts +33 -5
  69. package/dist/learn/skills.js +53 -7
  70. package/dist/learned-workflow.d.ts +24 -0
  71. package/dist/learned-workflow.js +66 -3
  72. package/dist/learning-batch.d.ts +283 -0
  73. package/dist/learning-batch.js +574 -0
  74. package/dist/learning-evals.d.ts +33 -0
  75. package/dist/learning-evals.js +98 -0
  76. package/dist/learning-routes.d.ts +25 -2
  77. package/dist/learning-routes.js +39 -6
  78. package/dist/learning-words.d.ts +6 -0
  79. package/dist/learning-words.js +6 -0
  80. package/dist/learning.d.ts +28 -15
  81. package/dist/learning.js +84 -44
  82. package/dist/live/stream.js +6 -3
  83. package/dist/live/translate.d.ts +4 -3
  84. package/dist/live/translate.js +8 -4
  85. package/dist/live-reach.d.ts +37 -0
  86. package/dist/live-reach.js +62 -0
  87. package/dist/mcp-gateway.d.ts +9 -0
  88. package/dist/mcp-gateway.js +60 -11
  89. package/dist/mcp-oauth.d.ts +57 -7
  90. package/dist/mcp-oauth.js +133 -18
  91. package/dist/mcp-private-hosts.d.ts +4 -4
  92. package/dist/mcp-private-hosts.js +20 -12
  93. package/dist/mcp-probe.d.ts +19 -2
  94. package/dist/mcp-probe.js +44 -9
  95. package/dist/mcp-secret-writes.js +4 -0
  96. package/dist/mcp-servers-store.d.ts +38 -15
  97. package/dist/mcp-servers-store.js +112 -20
  98. package/dist/mcp-store.d.ts +10 -4
  99. package/dist/mcp-store.js +17 -6
  100. package/dist/model-form.d.ts +26 -0
  101. package/dist/model-form.js +80 -0
  102. package/dist/model.js +23 -10
  103. package/dist/openapi.js +386 -21
  104. package/dist/page.d.ts +18 -0
  105. package/dist/page.js +48 -20
  106. package/dist/paid-calls.d.ts +1 -1
  107. package/dist/place-offers.d.ts +2 -3
  108. package/dist/place-offers.js +3 -7
  109. package/dist/place.js +1 -2
  110. package/dist/print.d.ts +15 -1
  111. package/dist/print.js +14 -3
  112. package/dist/propose.d.ts +3 -0
  113. package/dist/propose.js +13 -5
  114. package/dist/provider.js +3 -2
  115. package/dist/reflect-range.d.ts +8 -1
  116. package/dist/reflect-range.js +1 -1
  117. package/dist/run-launch.d.ts +14 -2
  118. package/dist/run-launch.js +9 -4
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-reads-over-store.d.ts +1 -1
  121. package/dist/run-repo.d.ts +20 -0
  122. package/dist/run-repo.js +63 -0
  123. package/dist/run-timeline-served.d.ts +1 -1
  124. package/dist/run-view.d.ts +3 -3
  125. package/dist/run-view.js +14 -7
  126. package/dist/runner/adapter-loop.d.ts +23 -7
  127. package/dist/runner/adapter-loop.js +648 -62
  128. package/dist/runner/adapter-run-spec.d.ts +11 -3
  129. package/dist/runner/adapter-run-spec.js +77 -22
  130. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  131. package/dist/runner/adapters/pi-computer.js +43 -0
  132. package/dist/runner/adapters/pi.d.ts +9 -4
  133. package/dist/runner/adapters/pi.js +76 -14
  134. package/dist/runner/beside.d.ts +7 -3
  135. package/dist/runner/beside.js +21 -11
  136. package/dist/runner/claim-secrets.d.ts +4 -0
  137. package/dist/runner/claim-secrets.js +6 -1
  138. package/dist/runner/cli-run-spec.d.ts +20 -3
  139. package/dist/runner/cli-run-spec.js +113 -43
  140. package/dist/runner/commands.d.ts +3 -1
  141. package/dist/runner/commands.js +28 -3
  142. package/dist/runner/computer-channel.d.ts +34 -0
  143. package/dist/runner/computer-channel.js +61 -0
  144. package/dist/runner/conformance/harness.js +80 -14
  145. package/dist/runner/conformance/subject.d.ts +1 -1
  146. package/dist/runner/dispatch.js +3 -0
  147. package/dist/runner/end-of-run.d.ts +22 -12
  148. package/dist/runner/end-of-run.js +38 -16
  149. package/dist/runner/github-app.d.ts +2 -1
  150. package/dist/runner/github-app.js +4 -2
  151. package/dist/runner/harness-loops.js +15 -1
  152. package/dist/runner/held-run.d.ts +65 -0
  153. package/dist/runner/held-run.js +158 -0
  154. package/dist/runner/journal-kinds.d.ts +20 -1
  155. package/dist/runner/journal-kinds.js +14 -0
  156. package/dist/runner/journal-reader.d.ts +5 -4
  157. package/dist/runner/journal-reader.js +12 -10
  158. package/dist/runner/learning-ask.d.ts +7 -1
  159. package/dist/runner/learning-ask.js +21 -6
  160. package/dist/runner/learning-dispatch.d.ts +22 -0
  161. package/dist/runner/learning-dispatch.js +77 -10
  162. package/dist/runner/learning-end.d.ts +22 -1
  163. package/dist/runner/learning-end.js +92 -12
  164. package/dist/runner/learning-factory.d.ts +1 -1
  165. package/dist/runner/learning-factory.js +11 -5
  166. package/dist/runner/learning-loop.d.ts +67 -7
  167. package/dist/runner/learning-loop.js +173 -21
  168. package/dist/runner/learning-seed.d.ts +7 -0
  169. package/dist/runner/learning-seed.js +13 -0
  170. package/dist/runner/live-ticker.js +1 -0
  171. package/dist/runner/loop-contract.d.ts +8 -1
  172. package/dist/runner/loop.d.ts +5 -1
  173. package/dist/runner/loop.js +2 -1
  174. package/dist/runner/main.d.ts +13 -1
  175. package/dist/runner/main.js +27 -5
  176. package/dist/runner/mcp-claim.d.ts +10 -7
  177. package/dist/runner/mcp-claim.js +113 -24
  178. package/dist/runner/mcp-github.js +1 -1
  179. package/dist/runner/mcp-run.d.ts +5 -5
  180. package/dist/runner/mcp-run.js +15 -3
  181. package/dist/runner/metrics.d.ts +11 -2
  182. package/dist/runner/metrics.js +12 -2
  183. package/dist/runner/pr-checkout.d.ts +1 -0
  184. package/dist/runner/pr-checkout.js +1 -1
  185. package/dist/runner/reflect-hook.d.ts +18 -0
  186. package/dist/runner/reflect-hook.js +20 -8
  187. package/dist/runner/runner.d.ts +26 -0
  188. package/dist/runner/runner.js +184 -15
  189. package/dist/runner/scratch-sweep.d.ts +13 -0
  190. package/dist/runner/scratch-sweep.js +62 -0
  191. package/dist/runner/sessions.d.ts +1 -1
  192. package/dist/runner/store-port.d.ts +4 -2
  193. package/dist/runner/store-secrets.js +4 -3
  194. package/dist/runner/subagent.js +3 -1
  195. package/dist/runner/workflow-host.d.ts +6 -1
  196. package/dist/runner/workflow-host.js +1 -1
  197. package/dist/runner/workflow-loop.d.ts +1 -1
  198. package/dist/runner/workflow-spec.d.ts +14 -2
  199. package/dist/runner/workflow-spec.js +56 -20
  200. package/dist/runs-over-store.d.ts +6 -1
  201. package/dist/runs-over-store.js +38 -9
  202. package/dist/seal-key.js +3 -3
  203. package/dist/sealed-settings-store.d.ts +5 -2
  204. package/dist/sealed-settings-store.js +10 -4
  205. package/dist/secret-writes.d.ts +5 -4
  206. package/dist/secret-writes.js +5 -4
  207. package/dist/server-secrets-store.d.ts +4 -3
  208. package/dist/server-secrets-store.js +15 -9
  209. package/dist/server-secrets.js +3 -2
  210. package/dist/server.d.ts +43 -14
  211. package/dist/server.js +472 -126
  212. package/dist/settings-wake.d.ts +21 -0
  213. package/dist/settings-wake.js +59 -0
  214. package/dist/standard-webhooks.d.ts +4 -1
  215. package/dist/standard-webhooks.js +8 -4
  216. package/dist/store/command-wake.d.ts +12 -0
  217. package/dist/store/command-wake.js +37 -0
  218. package/dist/store/dialect.d.ts +6 -0
  219. package/dist/store/dialect.js +5 -0
  220. package/dist/store/index.d.ts +1 -1
  221. package/dist/store/journal/storage.d.ts +3 -2
  222. package/dist/store/journal/storage.js +13 -5
  223. package/dist/store/postgres/dialect.js +4 -0
  224. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  225. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  226. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  227. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  228. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  229. package/dist/store/schema.d.ts +1 -1
  230. package/dist/store/schema.js +77 -8
  231. package/dist/store/sqlite/run-patch.d.ts +7 -5
  232. package/dist/store/sqlite/run-patch.js +28 -13
  233. package/dist/store/sqlite/store.js +272 -54
  234. package/dist/store/store.d.ts +268 -9
  235. package/dist/store/store.js +12 -1
  236. package/dist/store-reads/cap.d.ts +1 -1
  237. package/dist/store-reads/cap.js +8 -1
  238. package/dist/store-reads/decisions.d.ts +2 -2
  239. package/dist/store-reads/decisions.js +1 -1
  240. package/dist/store-reads/import-summary.d.ts +1 -1
  241. package/dist/store-reads/journal.d.ts +5 -4
  242. package/dist/store-reads/journal.js +73 -15
  243. package/dist/store-reads/learning.d.ts +20 -4
  244. package/dist/store-reads/learning.js +74 -18
  245. package/dist/store-reads/runs.d.ts +1 -1
  246. package/dist/store-reads/workflow.d.ts +1 -1
  247. package/dist/store-view.d.ts +5 -0
  248. package/dist/store-view.js +26 -11
  249. package/dist/template-eval.js +6 -4
  250. package/dist/template-github-permissions.d.ts +22 -8
  251. package/dist/template-github-permissions.js +35 -15
  252. package/dist/timeline/timeline.d.ts +27 -0
  253. package/dist/timeline/timeline.js +10 -9
  254. package/dist/timeline/util.d.ts +4 -0
  255. package/dist/timeline/util.js +14 -0
  256. package/dist/tool-budget.d.ts +19 -7
  257. package/dist/tool-budget.js +14 -8
  258. package/dist/tool-gate.d.ts +16 -9
  259. package/dist/tool-gate.js +53 -42
  260. package/dist/tool-plane.d.ts +16 -12
  261. package/dist/tool-plane.js +9 -4
  262. package/dist/tools.d.ts +13 -4
  263. package/dist/tools.js +13 -4
  264. package/dist/trigger-adapter.d.ts +4 -0
  265. package/dist/trigger-secrets-shown.d.ts +2 -2
  266. package/dist/trigger-secrets-shown.js +1 -1
  267. package/dist/trigger-signatures.d.ts +25 -6
  268. package/dist/trigger-signatures.js +41 -7
  269. package/dist/trigger-targets.d.ts +2 -0
  270. package/dist/trigger-targets.js +1 -0
  271. package/dist/trigger-webhook.js +5 -2
  272. package/dist/triggers.d.ts +7 -3
  273. package/dist/triggers.js +35 -5
  274. package/dist/turns.js +16 -1
  275. package/dist/validate.js +11 -1
  276. package/dist/web-fetch.d.ts +1 -1
  277. package/dist/web-search.d.ts +10 -5
  278. package/dist/web-search.js +7 -6
  279. package/dist/webhooks.d.ts +145 -102
  280. package/dist/webhooks.js +559 -322
  281. package/dist/workflow/decisions.d.ts +1 -1
  282. package/dist/workflow/node-runner.d.ts +2 -1
  283. package/dist/workflow/node.d.ts +2 -1
  284. package/dist/workflow/node.js +3 -1
  285. package/dist/workflow/pi-versions.d.ts +23 -0
  286. package/dist/workflow/pi-versions.js +57 -0
  287. package/dist/workflow/record-tool.d.ts +2 -1
  288. package/dist/workflow/store.d.ts +1 -1
  289. package/dist/workflow/task.js +3 -2
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/attached-computers.d.ts +41 -0
  292. package/dist/workspace/attached-computers.js +114 -0
  293. package/dist/workspace/computer-deps.d.ts +16 -9
  294. package/dist/workspace/computer-deps.js +19 -7
  295. package/dist/workspace/computer-for-claim.d.ts +17 -8
  296. package/dist/workspace/computer-for-claim.js +62 -21
  297. package/dist/workspace/computer-hold.d.ts +11 -27
  298. package/dist/workspace/computer-hold.js +36 -56
  299. package/dist/workspace/computer-ledger.d.ts +3 -1
  300. package/dist/workspace/computer-ledger.js +4 -0
  301. package/dist/workspace/computer-mcp.d.ts +25 -0
  302. package/dist/workspace/computer-mcp.js +41 -0
  303. package/dist/workspace/computer-ports.d.ts +4 -13
  304. package/dist/workspace/computer-ports.js +4 -107
  305. package/dist/workspace/computer-script.d.ts +37 -0
  306. package/dist/workspace/computer-script.js +138 -0
  307. package/dist/workspace/executors.d.ts +1 -1
  308. package/dist/workspace/index.d.ts +4 -2
  309. package/dist/workspace/index.js +3 -1
  310. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  311. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  312. package/dist/workspace/resolve-computer.d.ts +3 -0
  313. package/dist/workspace/resolve-computer.js +8 -2
  314. package/dist/workspace/run-tools.d.ts +32 -15
  315. package/dist/workspace/run-tools.js +23 -30
  316. package/package.json +19 -16
  317. package/templates/market-monitor/agent.md +1 -1
  318. package/dist/console/assets/index-BI4Byidu.js +0 -550
  319. package/dist/console/assets/index-C19gUF2n.css +0 -1
  320. package/dist/run-db.d.ts +0 -53
  321. package/dist/run-db.js +0 -116
  322. package/dist/workflow/readers.d.ts +0 -36
  323. package/dist/workflow/readers.js +0 -145
  324. package/dist/workflow/wal.d.ts +0 -11
  325. package/dist/workflow/wal.js +0 -106
@@ -27,14 +27,14 @@ export function besideStopping(server, held, drainMs) {
27
27
  * adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
28
28
  * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
29
29
  * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
30
- * too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
31
- * closes its store. */
32
- export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {}) {
30
+ * too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
31
+ * holds each paired computer's socket in this process, so a run here takes one. Returns the runner and a close() that
32
+ * stops both and closes its store. */
33
+ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub, mcpLoopback, onLine } = {}) {
33
34
  const { startRunner } = await import("./runner.js");
34
35
  const { dispatchRunner } = await import("./harness-loops.js");
35
36
  const { routeOf } = await import("./model-route.js");
36
- const { openRunnerStore, runEnv } = await import("./main.js");
37
- const { computerDepsFrom } = await import("../workspace/index.js");
37
+ const { openRunnerStore, runEnv, runnerComputers } = await import("./main.js");
38
38
  // The server's store, the runner's one way in (main.ts openRunnerStore, store/open.ts): Postgres when this process's
39
39
  // AGENTRUN_STORE_URL secret names one, else SQLite in the data directory; a schema it does not know is RunnerRefused.
40
40
  const { store } = await openRunnerStore(dataDir, process.env, (message) => void process.stderr.write(`agentrun-serve runner: ${message}\n`), undefined);
@@ -53,18 +53,28 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor } = {
53
53
  }
54
54
  // The beside-runner sees the server's environment as a separate runner would (runEnv, not withoutFaux): so an API run on
55
55
  // a --faux server reaches the faux gateway and its computers. The run's claim-time computer is composed once, the one way
56
- // (workspace/computer-deps.ts computerDepsFrom), from that same environment; a Docker computer's mounts by where this
57
- // process's Docker has the data directory (box-paths.ts), read once.
56
+ // (main.ts runnerComputers, a desktop's or a phone's live view with it), from that same environment; a Docker computer's
57
+ // mounts by where this process's Docker has the data directory (box-paths.ts), read once.
58
58
  const runs = env ?? runEnv(process.env);
59
59
  const { dockerPathsForRuns } = await import("../box-paths.js");
60
60
  const { hostAddressesOnce } = await import("../docker-host-addresses.js");
61
61
  const { PROVIDERS } = await import("@parcha/agentrun-computer");
62
62
  const { hostCommandRefusals } = await import("../computers.js");
63
- const computers = computerDepsFrom({ env: runs, store, sealKey: seal.key, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
64
- const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps });
63
+ const computers = runnerComputers(store, runs, seal.key, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(hub ? { hub } : {}) });
64
+ // `mcpLoopback`: the server beside it is a local install (Serve.localInstall), so its runs may reach an MCP server on
65
+ // loopback; any other runner's runs never do. A run's log lines (a learning run's skipped generality check) go to
66
+ // stderr with the runner's other lines.
67
+ const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps, ...(mcpLoopback ? { mcpLoopback: true } : {}), log: (line) => console.error(`agentrun-serve runner: ${line}`) });
65
68
  // It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
66
69
  const { runnerMemory } = await import("./memory-claim.js");
67
- const runner = startRunner({ store, createLoop, memory: runnerMemory(store), ...(loops !== undefined ? { loops } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
70
+ // Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts).
71
+ const { sweepEndedScratch } = await import("./scratch-sweep.js");
72
+ await sweepEndedScratch(store, dataDir, { log: (line) => console.error(`agentrun-serve runner: ${line}`) });
73
+ // Its run start and end lines go where the server's lines do (print.ts runLine), the one stdout; `onLine` is where a
74
+ // launcher in this process (a test) reads them instead.
75
+ const { runLine } = await import("../print.js");
76
+ const runner = startRunner({ store, createLoop, memory: runnerMemory(store), onEvent: (event) => { const line = runLine(event); if (line)
77
+ (onLine ?? console.log)(line); }, ...(loops !== undefined ? { loops } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
68
78
  // The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
69
79
  // runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
70
80
  const { startJanitor } = await import("../workspace/computer-janitor.js");
@@ -83,7 +93,7 @@ export async function serveWithRunner(options) {
83
93
  const { besideRunEnv } = await import("./main.js");
84
94
  const { loops, drainMs } = besideRunnerOptions(options, process.env);
85
95
  const serve = await startServe(options);
86
- const beside = await runnerBeside(options.data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)) }).catch(async (error) => {
96
+ const beside = await runnerBeside(options.data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), hub: serve.attachHub, mcpLoopback: serve.localInstall, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
87
97
  await serve.close();
88
98
  throw error;
89
99
  });
@@ -25,6 +25,10 @@ export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision,
25
25
  * workflow that does not parse or inspect names no provider: the tool refuses it before any node runs. No workflow, or
26
26
  * no provider left, reads nothing. A fresh object per call, so no run's keys reach another's. */
27
27
  export declare function learnedDecisionKeys(deps: ClaimSecretsDeps, workflows: readonly Pick<LearnedWorkflow, "workflow">[], allowed: (provider: string) => boolean): Promise<Record<string, string>>;
28
+ /** The host's keys of the decision providers `providers` (bare ids), read as claimSecrets reads its keys and scoped by
29
+ * decisionKeysFor; none for none. learnedDecisionKeys hands them to a run; a learning end (LS-07) builds its check's
30
+ * providers on them, host-side, never handed to the run. A fresh object per call. */
31
+ export declare function hostDecisionKeys(deps: ClaimSecretsDeps, providers: readonly string[]): Promise<Record<string, string>>;
28
32
  /** The model keys the host's models of `tiers` need (model.ts modelKeys: each one's provider's, or the gateway's), read as
29
33
  * claimSecrets reads a run's (the runner's environment first, then the key saved in Settings → Model keys), for a run's
30
34
  * learned workflow nodes of those tiers (adapter-run-spec.ts learnedTierRoutes): claimSecrets opens only the run's own
@@ -73,7 +73,12 @@ export async function learnedDecisionKeys(deps, workflows, allowed) {
73
73
  for (const id of providersNamed(nodes))
74
74
  named.add(id);
75
75
  }
76
- const providers = [...named].filter((id) => allowed(id));
76
+ return hostDecisionKeys(deps, [...named].filter((id) => allowed(id)));
77
+ }
78
+ /** The host's keys of the decision providers `providers` (bare ids), read as claimSecrets reads its keys and scoped by
79
+ * decisionKeysFor; none for none. learnedDecisionKeys hands them to a run; a learning end (LS-07) builds its check's
80
+ * providers on them, host-side, never handed to the run. A fresh object per call. */
81
+ export async function hostDecisionKeys(deps, providers) {
77
82
  if (!providers.length)
78
83
  return {};
79
84
  return decisionKeysFor(await workingEnv(deps), { providers, parallelWeb: false });
@@ -9,6 +9,18 @@ export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./
9
9
  export type CliSpecDeps = AdapterSpecDeps;
10
10
  /** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
11
11
  export declare const cliRefusesKind: (kind: string) => string | undefined;
12
+ /** A CLI run's environment: the runner's run environment (`env`, runner/main.ts runEnv), built from it itself and never
13
+ * a spread of it, with the model keys the claim opened (`claimed`, withModelKeys) and the server's data directory named
14
+ * (DATA_ENV). The run environment's secrets, and the keys added, are readable by name and never enumerable: the
15
+ * harness's model route finds the key its requests carry (model.ts, `env[row.field]`) while a program spawned with this
16
+ * environment carries none. A spread would drop every secret the launcher handed the runner, and the route would send no
17
+ * key. The data directory is a plain variable, which a spawn carries. So is the run's resolved tool plane (`plane`,
18
+ * TOOL_PLANE_ENV, not a secret), as main hands its per-run process: the adapter reads web_search's there (adapters.ts
19
+ * nativeOptions: claude-agent's WebSearch, codex's live search, admitted by its proxy's policy and priced with it), so a
20
+ * run whose plane resolves it to native gets the harness's own search (#2458), this run's alone; whatever the runner's
21
+ * own environment says of a plane is never the run's. Whether each search runs is the tool's setting at that search
22
+ * (SessionIO.permission, the gate), never this plane, which is frozen when the run is made. */
23
+ export declare function cliRunEnv(env: NodeJS.ProcessEnv | undefined, data: string, claimed?: NodeJS.ProcessEnv, plane?: RunLaunch["plane"]): NodeJS.ProcessEnv;
12
24
  /** `tools` in the order the agent grants them (`granted`, catalog names; a tool is listed by its catalog name's wire
13
25
  * name), as main listed a CLI run's tools to its harness: each granted tool where its grant is, and a tool the grant
14
26
  * does not name (one a granted tool or the run's computer brings beside it) right after the tool listed before it. Ties
@@ -16,9 +28,14 @@ export declare const cliRefusesKind: (kind: string) => string | undefined;
16
28
  export declare function inGrantOrder<T extends {
17
29
  readonly name: string;
18
30
  }>(tools: readonly T[], granted: readonly string[]): T[];
19
- /** A claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
20
- * laid things in since (a follow-up's) stays, with what is in it. */
21
- export declare function sweepScratch(dir: string, parents: readonly string[]): Promise<void>;
31
+ /** Every earlier claim's private folder of the run (`<harnesses>/<n>`, n below `epoch`) removed: what a claim whose runner
32
+ * died left (its release never ran), or a sweep of its own cut off partway. A claim at `epoch` or later (a live one, or a
33
+ * next claim's while this one lets go late) is never touched. Each removal is whole or is finished by the next sweep. */
34
+ export declare function sweepEarlier(harnesses: string, epoch: number): Promise<void>;
35
+ /** A claim's end: every earlier claim's folder of the run (sweepEarlier) and the claim's own (`<harnesses>/<epoch>`)
36
+ * removed, then each of `parents` in order while it is empty: one another claim of the run has laid things in since (a
37
+ * follow-up's) stays, with what is in it. Run again over what a cut-off sweep left, it finishes it. */
38
+ export declare function sweepScratch(harnesses: string, epoch: number, parents: readonly string[]): Promise<void>;
22
39
  /**
23
40
  * One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
24
41
  *
@@ -13,8 +13,8 @@
13
13
  // Shared with the pi spec: the run's Workspace and its uploaded files, a sandbox run's computer, the kernel registry's
14
14
  // hands on them (runTools), the gate from the store's tool settings, the system prompt (environment line, instructions
15
15
  // with what the agent learned and its skills, effort guidance), the first message, the end's metrics and the release.
16
- import { mkdir, rm, rmdir } from "node:fs/promises";
17
- import { join } from "node:path";
16
+ import { mkdir, readdir, rm, rmdir } from "node:fs/promises";
17
+ import { dirname, join } from "node:path";
18
18
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
19
19
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
20
20
  import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
@@ -28,7 +28,7 @@ import { harnessOf } from "../harness-table.js";
28
28
  import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
29
29
  import { laidOf, layLearningSeed } from "./learning-seed.js";
30
30
  import { learningWorkspace } from "../learn/folder.js";
31
- import { learningEndOfRun } from "./learning-end.js";
31
+ import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
32
32
  import { providerModels, runModels } from "../model.js";
33
33
  import { firstMessage } from "../run-manifest.js";
34
34
  import { learningStartOf, seedFailed } from "../run-launch.js";
@@ -48,15 +48,18 @@ import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRout
48
48
  import { openTierProxies } from "./adapters/pi.js";
49
49
  import { signInReads } from "../sign-ins-store.js";
50
50
  import { mcpServersOf } from "../tool-gate.js";
51
- import { claimSecrets, learnedDecisionKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
51
+ import { claimSecrets, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
52
52
  import { mcpForClaim } from "./mcp-run.js";
53
- import { TOOL_PLANE_ENV } from "../tool-plane.js";
53
+ import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
54
+ import { decisionProvidersIn } from "../decisions.js";
54
55
  import { resolveHarness } from "./adapters/index.js";
55
56
  import { entriesOf } from "./loop.js";
56
- import { bookedSpend, cliModelWorked, cliRunMetrics } from "./metrics.js";
57
+ import { bookedSpend, cliModelWorked, cliRunMetrics, runEndCost } from "./metrics.js";
57
58
  import { journalEntries } from "./journal-reader.js";
58
59
  import { specBuilt } from "./spec-holds.js";
59
60
  import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
61
+ import { heldSpecOf } from "./held-run.js";
62
+ import { loopComputerOf } from "./computer-channel.js";
60
63
  import { githubAppAccess } from "./github-app.js";
61
64
  import { prCheckoutForClaim } from "./pr-checkout.js";
62
65
  import { holdStored, storeSecrets } from "./store-secrets.js";
@@ -101,10 +104,18 @@ function capModelOf(id, wire, listed, unpriced) {
101
104
  * (DATA_ENV). The run environment's secrets, and the keys added, are readable by name and never enumerable: the
102
105
  * harness's model route finds the key its requests carry (model.ts, `env[row.field]`) while a program spawned with this
103
106
  * environment carries none. A spread would drop every secret the launcher handed the runner, and the route would send no
104
- * key. The data directory is a plain variable, which a spawn carries. */
105
- function cliRunEnv(env, data, claimed = {}) {
107
+ * key. The data directory is a plain variable, which a spawn carries. So is the run's resolved tool plane (`plane`,
108
+ * TOOL_PLANE_ENV, not a secret), as main hands its per-run process: the adapter reads web_search's there (adapters.ts
109
+ * nativeOptions: claude-agent's WebSearch, codex's live search, admitted by its proxy's policy and priced with it), so a
110
+ * run whose plane resolves it to native gets the harness's own search (#2458), this run's alone; whatever the runner's
111
+ * own environment says of a plane is never the run's. Whether each search runs is the tool's setting at that search
112
+ * (SessionIO.permission, the gate), never this plane, which is frozen when the run is made. */
113
+ export function cliRunEnv(env, data, claimed = {}, plane) {
106
114
  const out = withModelKeys(env ?? {}, claimed);
107
115
  Object.defineProperty(out, DATA_ENV, { value: data, enumerable: true, writable: true, configurable: true });
116
+ delete out[TOOL_PLANE_ENV];
117
+ if (plane && Object.keys(plane).length)
118
+ Object.defineProperty(out, TOOL_PLANE_ENV, { value: JSON.stringify(plane), enumerable: true, writable: true, configurable: true });
108
119
  return out;
109
120
  }
110
121
  /** `tools` in the order the agent grants them (`granted`, catalog names; a tool is listed by its catalog name's wire
@@ -122,19 +133,54 @@ export function inGrantOrder(tools, granted) {
122
133
  });
123
134
  return keyed.sort((a, b) => a.key - b.key || a.given - b.given).map(({ tool }) => tool);
124
135
  }
125
- /** A claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
126
- * laid things in since (a follow-up's) stays, with what is in it. */
127
- export async function sweepScratch(dir, parents) {
128
- await rm(dir, { recursive: true, force: true });
136
+ /** Every earlier claim's private folder of the run (`<harnesses>/<n>`, n below `epoch`) removed: what a claim whose runner
137
+ * died left (its release never ran), or a sweep of its own cut off partway. A claim at `epoch` or later (a live one, or a
138
+ * next claim's while this one lets go late) is never touched. Each removal is whole or is finished by the next sweep. */
139
+ export async function sweepEarlier(harnesses, epoch) {
140
+ let names;
141
+ try {
142
+ names = await readdir(harnesses);
143
+ }
144
+ catch (error) {
145
+ if (error.code === "ENOENT")
146
+ return;
147
+ throw error;
148
+ }
149
+ for (const name of names) {
150
+ if (/^\d+$/.test(name) && Number(name) < epoch)
151
+ await rm(join(harnesses, name), { recursive: true, force: true });
152
+ }
153
+ }
154
+ /** A claim's end: every earlier claim's folder of the run (sweepEarlier) and the claim's own (`<harnesses>/<epoch>`)
155
+ * removed, then each of `parents` in order while it is empty: one another claim of the run has laid things in since (a
156
+ * follow-up's) stays, with what is in it. Run again over what a cut-off sweep left, it finishes it. */
157
+ export async function sweepScratch(harnesses, epoch, parents) {
158
+ // An earlier folder that cannot be swept never keeps this claim's own folder: its removal is attempted anyway, and the
159
+ // earlier failure is thrown after it (with this one's, when both fail).
160
+ const failures = [];
161
+ await sweepEarlier(harnesses, epoch).catch((error) => { failures.push(error); });
162
+ await rm(join(harnesses, String(epoch)), { recursive: true, force: true }).catch((error) => { failures.push(error); });
163
+ if (failures.length === 0)
164
+ await rmEmptyParents(parents);
165
+ else
166
+ await rmEmptyParents(parents).catch((error) => { failures.push(error); });
167
+ if (failures.length === 1)
168
+ throw failures[0];
169
+ if (failures.length > 1)
170
+ throw new AggregateError(failures, failures.map((error) => error?.message ?? String(error)).join("; "));
171
+ }
172
+ async function rmEmptyParents(parents) {
129
173
  for (const parent of parents) {
130
174
  try {
131
175
  await rmdir(parent);
132
176
  }
133
177
  catch (error) {
134
178
  const code = error.code;
135
- if (code === "ENOTEMPTY" || code === "EEXIST" || code === "ENOENT")
179
+ if (code === "ENOTEMPTY" || code === "EEXIST")
136
180
  return;
137
- throw error;
181
+ // Already gone (a sweep cut off after it, or never made): the folder above it may still be left empty.
182
+ if (code !== "ENOENT")
183
+ throw error;
138
184
  }
139
185
  }
140
186
  }
@@ -160,6 +206,18 @@ async function cliSpec(launch, run, deps, claim, holds) {
160
206
  const runRow = await deps.store.runs.get(claim.runId);
161
207
  if (!runRow)
162
208
  throw new Error(`run ${claim.runId}: its row is gone from the store`);
209
+ // The claim's private folder is swept at the spec's release, the claim's end, then the scratch folder if nothing else is
210
+ // in it, then the agent's: the next claim, here or on another runner, lays its own, its harness's session coming back from
211
+ // the run's journal. Its own per claim (by the claim's epoch), so a run reopened while this claim still lets go (its
212
+ // release follows the run's end commit) never has the next claim's folder swept from under it. A claim whose runner died
213
+ // never ran its release: every claim sweeps the earlier claims' folders of its run at its start and again at its end, so
214
+ // a killed CLI's home and session state never outlive the run. Held here, before any step that can fail (the install, the
215
+ // MCP claim, the computer): a claim that fails in its setup still sweeps what the earlier claims left, as specBuilt lets
216
+ // go what was held when the build throws.
217
+ const scratch = scratchFolder(deps.data, runRow.agentId, claim.runId);
218
+ const harnesses = join(scratch, "harness");
219
+ const dir = join(harnesses, String(claim.epoch));
220
+ holds.hold({ scratch: { sweep: () => sweepScratch(harnesses, claim.epoch, [harnesses, scratch, dirname(scratch)]) } });
163
221
  // Every secret the server keeps sealed (store-secrets.ts) held by the runner's one redactor (the loop's) and this spec's
164
222
  // log cut, before any of the run's text is written: a run's text may quote one it was never handed.
165
223
  for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
@@ -219,10 +277,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
219
277
  // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin made at the first claim or read as written, its
220
278
  // credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
221
279
  // Before the session opens: a refusal (a pin that cannot be made, a pinned meta tool) ends the run in its words.
222
- // A credential the claim opens mid-run (a GitHub App token, a per_run server's handed one) joins the run's redactors.
280
+ // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
223
281
  const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
224
282
  redact.hold(values); };
225
- const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), 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 }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}) });
283
+ const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), 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.mcpLoopback ? { loopback: true } : {}) });
226
284
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
227
285
  holds.hold({ passed: mcp });
228
286
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
@@ -253,7 +311,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
253
311
  await copyRunFiles(deps.data, claim.runId, ws.workspace, launch.files);
254
312
  // The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
255
313
  // It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
256
- const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
314
+ const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
257
315
  // revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
258
316
  // run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does, with
259
317
  // what became of the agent's own computer said on the run's timeline.
@@ -261,24 +319,24 @@ async function cliSpec(launch, run, deps, claim, holds) {
261
319
  // whose computer is a browser is refused in words at its claim, before anything is made.
262
320
  { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
263
321
  holds.hold({ computer });
322
+ const loopComputer = loopComputerOf(computer.computer, computer.held);
323
+ const heldComputer = heldSpecOf(launch, loopComputer);
264
324
  // The CLI works in the run's scratch folder on this machine (its working directory), its own files (home, state, the
265
325
  // skills laid for it) in this claim's private folder inside it, never on the run's disk. The scratch is an alias of the
266
326
  // run's folder for the run's file tools: a path the CLI builds from its working directory lands in the run's folder, and
267
327
  // any other absolute path is refused (workspace/paths.ts portPath).
268
- // The private folder is swept at the spec's release, the claim's end, then the scratch folder if nothing else is in it:
269
- // the next claim, here or on another runner, lays its own, its harness's session coming back from the run's journal.
270
- // Its own per claim (by the claim's epoch), so a run reopened while this claim still lets go (its release follows the
271
- // run's end commit) never has the next claim's folder swept from under it.
272
- const scratch = scratchFolder(deps.data, runRow.agentId, claim.runId);
273
- const harnesses = join(scratch, "harness");
274
- const dir = join(harnesses, String(claim.epoch));
275
- holds.hold({ scratch: { sweep: () => sweepScratch(dir, [harnesses, scratch]) } });
276
- // Made again once if a parent went as it was made (the last claim's sweep removing the then empty scratch folder).
277
- await mkdir(dir, { recursive: true, mode: 0o700 }).catch(async (error) => {
278
- if (error.code !== "ENOENT")
279
- throw error;
280
- await mkdir(dir, { recursive: true, mode: 0o700 });
281
- });
328
+ // Made again if a parent went as it was made (another claim's sweep removing the then empty scratch or agent folder).
329
+ for (let tries = 1;; tries += 1) {
330
+ try {
331
+ await mkdir(dir, { recursive: true, mode: 0o700 });
332
+ break;
333
+ }
334
+ catch (error) {
335
+ if (error.code !== "ENOENT" || tries === 3)
336
+ throw error;
337
+ }
338
+ }
339
+ await sweepEarlier(harnesses, claim.epoch).catch((error) => log(`an earlier claim's scratch folder could not be swept: ${error?.message ?? String(error)}`));
282
340
  // The run's shell is its computer's (600 s) where one mounts its folder; with none, Archil's serverless exec in Mode 2
283
341
  // (295 s), and in Mode 1 none at all: no bash family, its folder being one of this server's own (run-tools.ts).
284
342
  // Under the agent's bash policy, its shell's environment is the policy's too (bash-read-only.ts policyEnv), as the pi spec does.
@@ -292,7 +350,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
292
350
  // those it would refuse, and is handed the rest), then the effort guidance.
293
351
  const start = learningStartOf(launch);
294
352
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
295
- const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
353
+ const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
296
354
  const check = await entry.skillCheck?.();
297
355
  // The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts).
298
356
  await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: launch.computer?.kind });
@@ -307,6 +365,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
307
365
  shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
308
366
  log,
309
367
  ...(start.notesOnly ? { workflows: false } : {}),
368
+ ...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
310
369
  })
311
370
  : undefined;
312
371
  const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, check, { onDemand: readsFiles(granted) });
@@ -321,7 +380,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
321
380
  const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, revisionRow, launch);
322
381
  for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
323
382
  holdClaimed(redact, claimed);
324
- const env = cliRunEnv(deps.env, deps.data, claimed);
383
+ const env = cliRunEnv(deps.env, deps.data, claimed, launch.plane);
325
384
  const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
326
385
  // The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
327
386
  // (adapters.ts' noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
@@ -378,6 +437,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
378
437
  // The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
379
438
  // uncapped), the model that bills this CLI run priced WITH tiers, strict where the launch says. The loop builds the
380
439
  // kernel runCap from these over the run's own sessions; the spec carries no beforeRequest of its own.
440
+ const besideOf = spentBesideOf(launch, deps.store, claim.runId);
381
441
  const runCap = {
382
442
  capUsd: () => launch.maxCostUsd,
383
443
  // One model per CLI session: every request it sends is the run's model, whatever id its provider names it by. A
@@ -390,6 +450,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
390
450
  return tierRoute && tierRoute.model === id ? capModelOfRoute(tierRoute) : undefined;
391
451
  },
392
452
  ...(launch.capMode === "strict" ? { mode: "strict" } : {}),
453
+ // What its learning runs' grades took beside it, read by every gate with its own sessions (none: it queues none).
454
+ ...(besideOf ? { beside: besideOf } : {}),
393
455
  };
394
456
  const cap = capUsd === undefined
395
457
  ? undefined
@@ -405,6 +467,11 @@ async function cliSpec(launch, run, deps, claim, holds) {
405
467
  // refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's. The run's MCP servers
406
468
  // (mcpServersOf its grants) hold a harness's own name for an MCP tool to that tool's settings.
407
469
  const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcpServersOf(granted));
470
+ // What a script's shell and files are held to: this gate, so a denied bash or write holds inside computer_script too.
471
+ tools.computer?.guard.install(async (tool, args) => {
472
+ await gate.permissions.refresh();
473
+ return gate.permissions.decide(tool, args);
474
+ });
408
475
  // The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
409
476
  // (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
410
477
  // (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
@@ -471,7 +538,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
471
538
  // The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate); they run through the run's
472
539
  // own MCP as the loop wraps it. Its model nodes run on the session's one model: what each node's trace says it ran on.
473
540
  gate.learn(workflows);
474
- learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(mcp ? { mcp } : {}), modelName: () => chosen.model.modelId });
541
+ learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(mcp ? { mcp } : {}), workspace: ws.workspace, modelName: () => chosen.model.modelId });
475
542
  }
476
543
  }
477
544
  const session = {
@@ -499,6 +566,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
499
566
  signIns: signInReads(deps.store, deps.sealKey),
500
567
  handed: handedKeys,
501
568
  stored: () => storeSecrets(deps.store, deps.sealKey, deps.data),
569
+ // A workflow draft's decision nodes are checked against the host's decision providers, on its keys (LS-07).
570
+ decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, DECISION_PROVIDER_KEYS)) }),
502
571
  learningFolder: archil === undefined
503
572
  ? (agentId) => learningFolderOf(deps.data, agentId)
504
573
  : (agentId) => learningWorkspace({ mode: "archil", agentId, archil }),
@@ -521,8 +590,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
521
590
  // The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
522
591
  ...(life ? { lifecycle: life } : {}),
523
592
  agentId: runRow.agentId,
524
- // The run's desktop or phone and the person's hold on it, as the claim made them (as the pi spec gives them).
525
- ...(computer.held ? { computer: computer.held } : {}),
593
+ // The run's computer and the person's hold on a desktop or phone, as the claim made them (as the pi spec gives them).
594
+ ...(loopComputer ? { computer: loopComputer } : {}),
526
595
  workRoot: root,
527
596
  // Where the CLI works (its working directory, the run's folder to its file tools): what its absolute paths are read
528
597
  // against on the run's rows.
@@ -533,23 +602,24 @@ async function cliSpec(launch, run, deps, claim, holds) {
533
602
  // session of its journal), as a pi run's are at its answers' costs and tokens.
534
603
  endPatch: async () => {
535
604
  const entries = await entriesOf(deps.journal(claim), ROOT_CONVERSATION_ID, context);
536
- // Its tokens and model requests, and its model requests' cost, from one read of its booking (cliRunMetrics); its
537
- // decisions (a learned workflow's) at what they were booked at too.
605
+ // Its tokens and model requests, and its model requests' cost, from one read of its booking (cliRunMetrics). Its
606
+ // model requests and its decisions (a learned workflow's, LS-07) at what they were booked at (bookedSpend), and its
607
+ // paid tool calls (a Parallel extract or search, a monid call), booked on the run's one ledger in their own session,
608
+ // are the run's cost (runEndCost: unknown when any part is), as the pi spec's.
538
609
  const all = (await journalEntries(deps.journal(claim), context));
539
610
  const booked = bookedSpend(all, "model");
540
611
  const metrics = cliRunMetrics(entries, booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}` });
541
612
  // A run whose model answered or called a tool with no request booked (its requests went past its model proxy) spent
542
613
  // what no booking read: unknown, never the $0 an empty booking sums to.
543
614
  const model = booked.requests === 0 && cliModelWorked(entries) ? null : booked.usd;
544
- const decisions = bookedSpend(all, "decisions").usd;
545
- const costUsd = model === null || decisions === null ? null : model + decisions;
546
615
  // Its paid tool calls (a Parallel extract or search, a monid call), booked on the run's one ledger in their own
547
- // session, are the run's cost too, as the pi spec's.
548
- const paid = run.ledger?.paid ? run.ledger.paid.spentUsd() : 0;
549
- const total = costUsd === null || paid === null ? null : costUsd + paid;
616
+ // session, and its decisions (a learned workflow's decision nodes) are the run's cost too, as the pi spec's.
617
+ const total = runEndCost({ model, paid: run.ledger?.paid ? run.ledger.paid.spentUsd() : 0, decisions: bookedSpend(all, "decisions").usd });
550
618
  // An unknown cost is written as null, never left out: a follow-up's end clears the cost an earlier end stored.
551
619
  return { costUsd: total, metrics };
552
620
  },
621
+ // A run started with hold: true holds its computer for its owner (computer-held.ts), as the pi spec's.
622
+ ...(heldComputer ? { held: heldComputer } : {}),
553
623
  // The run's Archil mount credential is revoked at its end on every outcome, even with no computer (idempotent with
554
624
  // the computer's release). A run that minted none revokes nothing.
555
625
  release: () => holds.release(),
@@ -2,7 +2,9 @@ import type { Command } from "./loop-contract.js";
2
2
  /** stop and cancel both end the run, stopped: a cancel's end says it was cancelled, as main's cancel ends a run for good.
3
3
  * browser_hand_back is a person's answer to the agent's browser hand-over (runner/hand-back.ts). computer_take_over and
4
4
  * computer_hand_back are a person's turn with the run's desktop or phone (computer-commands.ts, runner/computer-journal.ts).
5
- * pause and resume are a workflow run's (runs.ts pause). */
5
+ * computer_call is the computer call channel's: one protocol call on the run's computer (computer-channel.ts,
6
+ * runner/computer-channel.ts). computer_start and computer_release are the owner's, for a computer the run holds
7
+ * (computer-held.ts, runner/held-run.ts). pause and resume are a workflow run's (runs.ts pause). */
6
8
  export declare const COMMAND_KINDS: ReadonlySet<string>;
7
9
  export interface CommandInput {
8
10
  readonly kind: string;
@@ -5,9 +5,23 @@ import { originOf } from "../timeline/index.js";
5
5
  /** stop and cancel both end the run, stopped: a cancel's end says it was cancelled, as main's cancel ends a run for good.
6
6
  * browser_hand_back is a person's answer to the agent's browser hand-over (runner/hand-back.ts). computer_take_over and
7
7
  * computer_hand_back are a person's turn with the run's desktop or phone (computer-commands.ts, runner/computer-journal.ts).
8
- * pause and resume are a workflow run's (runs.ts pause). */
9
- export const COMMAND_KINDS = new Set(["stop", "cancel", "steer", "approve", "deny", "raise", "browser_hand_back", "computer_take_over", "computer_hand_back", "pause", "resume"]);
8
+ * computer_call is the computer call channel's: one protocol call on the run's computer (computer-channel.ts,
9
+ * runner/computer-channel.ts). computer_start and computer_release are the owner's, for a computer the run holds
10
+ * (computer-held.ts, runner/held-run.ts). pause and resume are a workflow run's (runs.ts pause). */
11
+ export const COMMAND_KINDS = new Set(["stop", "cancel", "steer", "approve", "deny", "raise", "browser_hand_back", "computer_take_over", "computer_hand_back", "computer_start", "computer_call", "computer_release", "pause", "resume"]);
10
12
  const text = (value) => typeof value === "string" && value.trim() !== "";
13
+ /** Whether `value` is the JSON text of an object (not an array, not null). */
14
+ const objectText = (value) => {
15
+ if (typeof value !== "string")
16
+ return false;
17
+ try {
18
+ const parsed = JSON.parse(value);
19
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ };
11
25
  /** Why a command's body is wrong for its kind, or undefined when it is right. */
12
26
  function bodyProblem(kind, body) {
13
27
  switch (kind) {
@@ -42,9 +56,20 @@ function bodyProblem(kind, body) {
42
56
  if (!text(body.ask))
43
57
  return "a computer hand-back names the take it ends (take) or the ask it answers (ask)";
44
58
  return body.outcome === "done" || body.outcome === "cancelled" ? undefined : "a computer hand-back's outcome is done or cancelled";
59
+ case "computer_call":
60
+ if (!text(body.method))
61
+ return "a computer call names its protocol method";
62
+ // A call answers no park (answers: false), so a row written as its run parks never wakes it.
63
+ if (body.answers !== false)
64
+ return "a computer call answers no park (answers: false)";
65
+ // Its params as one JSON text (computer-channel.ts callComputer), so a settle's jsonb never decodes what was typed.
66
+ return body.params === undefined || objectText(body.params) ? undefined : "a computer call's params are a JSON object's text";
67
+ case "computer_start":
68
+ case "computer_release":
45
69
  case "pause":
46
70
  case "resume":
47
- // A workflow run's pause or resume (POST /runs/{id}/pause, /resume): the run's runner takes it; it carries nothing.
71
+ // A held run's start or release (POST /runs/{id}/start, /computer/release), or a workflow run's pause or resume
72
+ // (POST /runs/{id}/pause, /resume): the run's runner takes it; it carries nothing.
48
73
  return Object.keys(body).length === 0 ? undefined : `a ${kind} carries nothing`;
49
74
  default:
50
75
  return undefined;
@@ -0,0 +1,34 @@
1
+ import type { ComputerClient, HelloResult } from "@parcha/agentrun-computer";
2
+ import { type ComputerCallRecord } from "../computer-calls.js";
3
+ import { type ComputerAnswer, type ComputerCall } from "../computer-channel.js";
4
+ import type { ComputerHold, HeldComputer } from "../workspace/computer-hold.js";
5
+ import type { RunComputer } from "../workspace/run-tools.js";
6
+ import type { Command } from "./loop-contract.js";
7
+ /** The run's computer as the loop drives it: its kind, the client of the computer its claim made and the hello it
8
+ * connected with, and, on a desktop or a phone, the person's hold on it (workspace/computer-hold.ts). A browser is none:
9
+ * it speaks CDP, not the protocol. */
10
+ export type LoopComputer = {
11
+ readonly kind: "sandbox" | "desktop" | "phone";
12
+ readonly client: ComputerClient;
13
+ readonly hello?: HelloResult;
14
+ readonly hold?: ComputerHold;
15
+ };
16
+ /** The loop's computer for a claim's (computerForClaim's `computer` and `held`): none for no computer or a browser. */
17
+ export declare function loopComputerOf(computer: RunComputer | undefined, held: HeldComputer | undefined): LoopComputer | undefined;
18
+ /** A computer_call row's call, or why it is refused (a row the server wrote is always one; a hand-made one may not be). */
19
+ export declare function channelCallOf(command: Pick<Command, "body">): ComputerCall | {
20
+ readonly refused: string;
21
+ };
22
+ /** What one call came to: the computer's answer, the call's record, and when it ended (ms). */
23
+ export type ChannelAnswer = {
24
+ readonly answer: ComputerAnswer;
25
+ readonly record: ComputerCallRecord;
26
+ readonly at: number;
27
+ };
28
+ /**
29
+ * Runs `call` on `computer` and answers what came of it; never throws. While a person holds the computer the call waits,
30
+ * as the agent's calls do, and counts as in flight once it runs, so a take asked meanwhile waits for it. `signal` bounds
31
+ * the whole of it (the loop's: CALL_MS, and the claim's): a wait or a call it cuts answers `timeout`, a call whose client
32
+ * failed answers `gone`. The call is no tool call's, so it is recorded on none.
33
+ */
34
+ export declare function runChannelCall(computer: LoopComputer, call: ComputerCall, signal: AbortSignal, now?: () => number): Promise<ChannelAnswer>;