@parcha/agentrun-serve 0.1.0-beta.35 → 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 (522) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +417 -219
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-conformance-cli.d.ts +1 -0
  15. package/dist/attach-conformance-cli.js +18 -0
  16. package/dist/attach-conformance.d.ts +25 -0
  17. package/dist/attach-conformance.js +343 -0
  18. package/dist/attach-images.d.ts +15 -0
  19. package/dist/attach-images.js +59 -0
  20. package/dist/background.d.ts +0 -6
  21. package/dist/background.js +0 -28
  22. package/dist/box-image.d.ts +1 -97
  23. package/dist/box-image.js +4 -284
  24. package/dist/box-paths.d.ts +2 -7
  25. package/dist/box-paths.js +7 -13
  26. package/dist/box-settings.d.ts +0 -11
  27. package/dist/box-settings.js +4 -29
  28. package/dist/browser-commands.js +1 -1
  29. package/dist/browser-computer.d.ts +47 -3
  30. package/dist/browser-computer.js +286 -18
  31. package/dist/browser-cost.d.ts +1 -1
  32. package/dist/browser-live.d.ts +20 -8
  33. package/dist/browser-live.js +50 -27
  34. package/dist/browser-person.d.ts +19 -2
  35. package/dist/browser-person.js +55 -6
  36. package/dist/browser-wait-ended.d.ts +23 -0
  37. package/dist/browser-wait-ended.js +42 -0
  38. package/dist/cap.d.ts +12 -57
  39. package/dist/cap.js +20 -160
  40. package/dist/catalog.d.ts +1 -12
  41. package/dist/catalog.js +3 -33
  42. package/dist/cli.js +17 -26
  43. package/dist/composio-preset.d.ts +36 -0
  44. package/dist/composio-preset.js +179 -0
  45. package/dist/computer-attach.d.ts +125 -0
  46. package/dist/computer-attach.js +330 -0
  47. package/dist/computer-calls.d.ts +48 -0
  48. package/dist/computer-calls.js +126 -0
  49. package/dist/computer-channel.d.ts +57 -0
  50. package/dist/computer-channel.js +115 -0
  51. package/dist/computer-commands.d.ts +1 -1
  52. package/dist/computer-held-routes.d.ts +35 -0
  53. package/dist/computer-held-routes.js +106 -0
  54. package/dist/computer-held.d.ts +48 -0
  55. package/dist/computer-held.js +87 -0
  56. package/dist/computer-keys.d.ts +21 -1
  57. package/dist/computer-keys.js +53 -11
  58. package/dist/computer-live.d.ts +160 -0
  59. package/dist/computer-live.js +643 -0
  60. package/dist/computer-routes.d.ts +1 -4
  61. package/dist/computer-routes.js +3 -5
  62. package/dist/computer-setting.d.ts +2 -0
  63. package/dist/computer-setting.js +38 -1
  64. package/dist/computer-view.d.ts +24 -2
  65. package/dist/computer-view.js +51 -3
  66. package/dist/computer-viewer.d.ts +6 -0
  67. package/dist/computer-viewer.js +297 -0
  68. package/dist/computers.d.ts +79 -12
  69. package/dist/computers.js +147 -28
  70. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  71. package/dist/console/assets/index-DRN62V5v.css +1 -0
  72. package/dist/console/index.html +2 -2
  73. package/dist/docker-daemon.d.ts +2 -2
  74. package/dist/docker-daemon.js +2 -2
  75. package/dist/errors.js +5 -5
  76. package/dist/faux-computers.d.ts +9 -20
  77. package/dist/faux-computers.js +56 -24
  78. package/dist/files.d.ts +1 -9
  79. package/dist/files.js +1 -9
  80. package/dist/github-connection.d.ts +10 -2
  81. package/dist/github-connection.js +65 -2
  82. package/dist/github-faux.js +1 -1
  83. package/dist/github.d.ts +22 -2
  84. package/dist/github.js +42 -8
  85. package/dist/gpu-words.d.ts +14 -0
  86. package/dist/gpu-words.js +21 -0
  87. package/dist/graph-view.d.ts +3 -1
  88. package/dist/graph-view.js +25 -1
  89. package/dist/handed-values.d.ts +1 -1
  90. package/dist/handed-values.js +1 -1
  91. package/dist/harness-install.d.ts +60 -3
  92. package/dist/harness-install.js +322 -34
  93. package/dist/harness.d.ts +1 -0
  94. package/dist/harness.js +36 -2
  95. package/dist/host-tools.d.ts +9 -10
  96. package/dist/host-tools.js +7 -7
  97. package/dist/hosted-search.d.ts +5 -4
  98. package/dist/hosted-search.js +2 -7
  99. package/dist/import-sources.d.ts +10 -0
  100. package/dist/import-sources.js +44 -2
  101. package/dist/import.d.ts +3 -3
  102. package/dist/import.js +37 -6
  103. package/dist/index.d.ts +1 -3
  104. package/dist/index.js +1 -2
  105. package/dist/key-refusal.d.ts +1 -1
  106. package/dist/key-refusal.js +2 -2
  107. package/dist/learn/check.d.ts +11 -2
  108. package/dist/learn/check.js +124 -6
  109. package/dist/learn/commit.d.ts +43 -7
  110. package/dist/learn/commit.js +166 -22
  111. package/dist/learn/folder.d.ts +11 -0
  112. package/dist/learn/folder.js +37 -1
  113. package/dist/learn/general.d.ts +66 -0
  114. package/dist/learn/general.js +73 -0
  115. package/dist/learn/grade.d.ts +22 -1
  116. package/dist/learn/grade.js +107 -16
  117. package/dist/learn/index.d.ts +1 -1
  118. package/dist/learn/index.js +1 -1
  119. package/dist/learn/learning.sh +12 -1
  120. package/dist/learn/notes.d.ts +3 -0
  121. package/dist/learn/notes.js +3 -0
  122. package/dist/learn/reflect.d.ts +14 -2
  123. package/dist/learn/reflect.js +54 -30
  124. package/dist/learn/skills.d.ts +37 -5
  125. package/dist/learn/skills.js +60 -7
  126. package/dist/learned-nodes.d.ts +6 -2
  127. package/dist/learned-workflow.d.ts +43 -9
  128. package/dist/learned-workflow.js +128 -37
  129. package/dist/learning-batch.d.ts +283 -0
  130. package/dist/learning-batch.js +574 -0
  131. package/dist/learning-cost.d.ts +79 -0
  132. package/dist/learning-cost.js +69 -0
  133. package/dist/learning-evals.d.ts +33 -0
  134. package/dist/learning-evals.js +98 -0
  135. package/dist/learning-routes.d.ts +32 -4
  136. package/dist/learning-routes.js +48 -12
  137. package/dist/learning-words.d.ts +9 -0
  138. package/dist/learning-words.js +12 -2
  139. package/dist/learning.d.ts +39 -19
  140. package/dist/learning.js +88 -46
  141. package/dist/live/stream.js +6 -3
  142. package/dist/live/translate.d.ts +4 -3
  143. package/dist/live/translate.js +8 -4
  144. package/dist/live-reach.d.ts +37 -0
  145. package/dist/live-reach.js +62 -0
  146. package/dist/mcp-gateway.d.ts +9 -0
  147. package/dist/mcp-gateway.js +60 -11
  148. package/dist/mcp-oauth.d.ts +57 -7
  149. package/dist/mcp-oauth.js +133 -18
  150. package/dist/mcp-private-hosts.d.ts +4 -4
  151. package/dist/mcp-private-hosts.js +20 -12
  152. package/dist/mcp-probe.d.ts +27 -3
  153. package/dist/mcp-probe.js +106 -29
  154. package/dist/mcp-secret-writes.js +8 -0
  155. package/dist/mcp-servers-store.d.ts +38 -15
  156. package/dist/mcp-servers-store.js +120 -23
  157. package/dist/mcp-store.d.ts +10 -4
  158. package/dist/mcp-store.js +17 -6
  159. package/dist/model-form.d.ts +26 -0
  160. package/dist/model-form.js +80 -0
  161. package/dist/model.d.ts +5 -5
  162. package/dist/model.js +29 -16
  163. package/dist/openapi.d.ts +2 -0
  164. package/dist/openapi.js +586 -64
  165. package/dist/owner.d.ts +0 -1
  166. package/dist/owner.js +0 -2
  167. package/dist/page.d.ts +18 -0
  168. package/dist/page.js +48 -20
  169. package/dist/paid-calls.d.ts +1 -1
  170. package/dist/paid-calls.js +1 -1
  171. package/dist/place-offers.d.ts +96 -0
  172. package/dist/place-offers.js +202 -0
  173. package/dist/place.d.ts +9 -13
  174. package/dist/place.js +21 -32
  175. package/dist/port-models.d.ts +2 -1
  176. package/dist/port-models.js +5 -3
  177. package/dist/print.d.ts +16 -9
  178. package/dist/print.js +15 -17
  179. package/dist/propose.d.ts +4 -0
  180. package/dist/propose.js +34 -11
  181. package/dist/provider.js +3 -2
  182. package/dist/reflect-range.d.ts +8 -1
  183. package/dist/reflect-range.js +1 -1
  184. package/dist/run-cut.d.ts +5 -0
  185. package/dist/run-cut.js +19 -0
  186. package/dist/run-launch.d.ts +28 -3
  187. package/dist/run-launch.js +14 -4
  188. package/dist/run-learning-served.d.ts +2 -2
  189. package/dist/run-manifest.d.ts +2 -2
  190. package/dist/run-manifest.js +2 -2
  191. package/dist/run-reads-over-store.d.ts +1 -1
  192. package/dist/run-repo.d.ts +20 -0
  193. package/dist/run-repo.js +63 -0
  194. package/dist/run-secrets.js +3 -3
  195. package/dist/run-timeline-served.d.ts +1 -1
  196. package/dist/run-timeline-served.js +56 -44
  197. package/dist/run-view.d.ts +8 -5
  198. package/dist/run-view.js +18 -10
  199. package/dist/runnable.d.ts +2 -2
  200. package/dist/runnable.js +6 -2
  201. package/dist/runner/adapter-loop.d.ts +39 -8
  202. package/dist/runner/adapter-loop.js +770 -83
  203. package/dist/runner/adapter-run-spec.d.ts +36 -7
  204. package/dist/runner/adapter-run-spec.js +171 -37
  205. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  206. package/dist/runner/adapters/pi-computer.js +43 -0
  207. package/dist/runner/adapters/pi.d.ts +20 -7
  208. package/dist/runner/adapters/pi.js +111 -26
  209. package/dist/runner/beside.d.ts +7 -3
  210. package/dist/runner/beside.js +26 -12
  211. package/dist/runner/claim-secrets.d.ts +4 -0
  212. package/dist/runner/claim-secrets.js +6 -1
  213. package/dist/runner/cli-run-spec.d.ts +27 -3
  214. package/dist/runner/cli-run-spec.js +198 -74
  215. package/dist/runner/commands.d.ts +8 -2
  216. package/dist/runner/commands.js +31 -6
  217. package/dist/runner/computer-channel.d.ts +34 -0
  218. package/dist/runner/computer-channel.js +61 -0
  219. package/dist/runner/conformance/harness.d.ts +0 -1
  220. package/dist/runner/conformance/harness.js +87 -18
  221. package/dist/runner/conformance/subject.d.ts +1 -1
  222. package/dist/runner/dispatch.js +3 -0
  223. package/dist/runner/end-of-run.d.ts +22 -12
  224. package/dist/runner/end-of-run.js +38 -16
  225. package/dist/runner/github-app.d.ts +2 -1
  226. package/dist/runner/github-app.js +6 -4
  227. package/dist/runner/harness-loops.js +16 -2
  228. package/dist/runner/held-run.d.ts +65 -0
  229. package/dist/runner/held-run.js +158 -0
  230. package/dist/runner/journal-kinds.d.ts +35 -6
  231. package/dist/runner/journal-kinds.js +20 -1
  232. package/dist/runner/journal-reader.d.ts +5 -4
  233. package/dist/runner/journal-reader.js +12 -10
  234. package/dist/runner/learning-ask.d.ts +7 -1
  235. package/dist/runner/learning-ask.js +21 -6
  236. package/dist/runner/learning-dispatch.d.ts +22 -0
  237. package/dist/runner/learning-dispatch.js +77 -10
  238. package/dist/runner/learning-end.d.ts +37 -1
  239. package/dist/runner/learning-end.js +115 -14
  240. package/dist/runner/learning-factory.d.ts +1 -1
  241. package/dist/runner/learning-factory.js +15 -5
  242. package/dist/runner/learning-loop.d.ts +139 -7
  243. package/dist/runner/learning-loop.js +369 -32
  244. package/dist/runner/learning-seed.d.ts +9 -0
  245. package/dist/runner/learning-seed.js +14 -1
  246. package/dist/runner/live-ticker.js +1 -0
  247. package/dist/runner/loop-contract.d.ts +16 -1
  248. package/dist/runner/loop-contract.js +6 -0
  249. package/dist/runner/loop.d.ts +10 -2
  250. package/dist/runner/loop.js +22 -1
  251. package/dist/runner/main.d.ts +13 -1
  252. package/dist/runner/main.js +38 -6
  253. package/dist/runner/mcp-claim.d.ts +11 -4
  254. package/dist/runner/mcp-claim.js +140 -23
  255. package/dist/runner/mcp-github.d.ts +4 -2
  256. package/dist/runner/mcp-github.js +1 -8
  257. package/dist/runner/mcp-run.d.ts +6 -4
  258. package/dist/runner/mcp-run.js +16 -3
  259. package/dist/runner/metrics.d.ts +15 -2
  260. package/dist/runner/metrics.js +21 -2
  261. package/dist/runner/model-route.d.ts +3 -0
  262. package/dist/runner/model-route.js +5 -2
  263. package/dist/runner/pr-checkout.d.ts +60 -0
  264. package/dist/runner/pr-checkout.js +176 -0
  265. package/dist/runner/reflect-hook.d.ts +19 -0
  266. package/dist/runner/reflect-hook.js +20 -8
  267. package/dist/runner/runner.d.ts +26 -0
  268. package/dist/runner/runner.js +231 -27
  269. package/dist/runner/scratch-sweep.d.ts +13 -0
  270. package/dist/runner/scratch-sweep.js +62 -0
  271. package/dist/runner/sessions.d.ts +1 -1
  272. package/dist/runner/spec-holds.d.ts +8 -3
  273. package/dist/runner/spec-holds.js +12 -10
  274. package/dist/runner/store-port.d.ts +7 -2
  275. package/dist/runner/store-secrets.js +21 -4
  276. package/dist/runner/subagent.d.ts +44 -0
  277. package/dist/runner/subagent.js +190 -0
  278. package/dist/runner/workflow-host.d.ts +24 -3
  279. package/dist/runner/workflow-host.js +24 -4
  280. package/dist/runner/workflow-loop.d.ts +6 -3
  281. package/dist/runner/workflow-loop.js +9 -8
  282. package/dist/runner/workflow-spec.d.ts +39 -15
  283. package/dist/runner/workflow-spec.js +143 -40
  284. package/dist/runs-over-store.d.ts +16 -6
  285. package/dist/runs-over-store.js +145 -29
  286. package/dist/seal-key.js +3 -3
  287. package/dist/sealed-settings-store.d.ts +5 -2
  288. package/dist/sealed-settings-store.js +10 -4
  289. package/dist/sealing.js +1 -2
  290. package/dist/secret-cut.d.ts +1 -1
  291. package/dist/secret-cut.js +1 -1
  292. package/dist/secret-writes.d.ts +5 -4
  293. package/dist/secret-writes.js +5 -4
  294. package/dist/server-secrets-store.d.ts +4 -3
  295. package/dist/server-secrets-store.js +15 -9
  296. package/dist/server-secrets.js +3 -2
  297. package/dist/server.d.ts +75 -63
  298. package/dist/server.js +712 -316
  299. package/dist/settings-wake.d.ts +21 -0
  300. package/dist/settings-wake.js +59 -0
  301. package/dist/standard-webhooks.d.ts +4 -1
  302. package/dist/standard-webhooks.js +8 -4
  303. package/dist/store/agent-body.d.ts +9 -2
  304. package/dist/store/agent-body.js +16 -8
  305. package/dist/store/command-wake.d.ts +12 -0
  306. package/dist/store/command-wake.js +37 -0
  307. package/dist/store/deadline.js +9 -5
  308. package/dist/store/dialect.d.ts +6 -0
  309. package/dist/store/dialect.js +5 -0
  310. package/dist/store/index.d.ts +4 -4
  311. package/dist/store/index.js +2 -2
  312. package/dist/store/journal/storage.d.ts +3 -2
  313. package/dist/store/journal/storage.js +15 -6
  314. package/dist/store/postgres/connection.js +9 -4
  315. package/dist/store/postgres/dialect.js +4 -0
  316. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  317. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  318. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  319. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  320. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  321. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  322. package/dist/store/schema.d.ts +2 -1
  323. package/dist/store/schema.js +85 -13
  324. package/dist/store/seal.d.ts +13 -0
  325. package/dist/store/seal.js +19 -0
  326. package/dist/store/sqlite/connection.d.ts +5 -0
  327. package/dist/store/sqlite/connection.js +88 -47
  328. package/dist/store/sqlite/run-patch.d.ts +25 -7
  329. package/dist/store/sqlite/run-patch.js +58 -14
  330. package/dist/store/sqlite/store.js +331 -59
  331. package/dist/store/store.d.ts +330 -21
  332. package/dist/store/store.js +34 -2
  333. package/dist/store-reads/analytics.js +3 -2
  334. package/dist/store-reads/cap.d.ts +2 -4
  335. package/dist/store-reads/cap.js +16 -7
  336. package/dist/store-reads/decisions.d.ts +3 -3
  337. package/dist/store-reads/decisions.js +3 -6
  338. package/dist/store-reads/import-summary.d.ts +1 -1
  339. package/dist/store-reads/journal.d.ts +5 -4
  340. package/dist/store-reads/journal.js +118 -27
  341. package/dist/store-reads/learning.d.ts +34 -4
  342. package/dist/store-reads/learning.js +137 -23
  343. package/dist/store-reads/runs.d.ts +7 -5
  344. package/dist/store-reads/runs.js +17 -10
  345. package/dist/store-reads/stats.js +5 -1
  346. package/dist/store-reads/workflow.d.ts +1 -1
  347. package/dist/store-view.d.ts +5 -0
  348. package/dist/store-view.js +70 -29
  349. package/dist/template-eval.js +8 -5
  350. package/dist/template-github-permissions.d.ts +22 -8
  351. package/dist/template-github-permissions.js +35 -15
  352. package/dist/templates.d.ts +64 -0
  353. package/dist/templates.js +101 -16
  354. package/dist/timeline/timeline.d.ts +30 -1
  355. package/dist/timeline/timeline.js +29 -13
  356. package/dist/timeline/util.d.ts +4 -0
  357. package/dist/timeline/util.js +14 -0
  358. package/dist/tool-blurbs.js +1 -0
  359. package/dist/tool-budget.d.ts +27 -7
  360. package/dist/tool-budget.js +21 -9
  361. package/dist/tool-gate.d.ts +23 -10
  362. package/dist/tool-gate.js +60 -44
  363. package/dist/tool-plane.d.ts +46 -28
  364. package/dist/tool-plane.js +73 -31
  365. package/dist/tools.d.ts +31 -38
  366. package/dist/tools.js +117 -74
  367. package/dist/trigger-adapter.d.ts +4 -0
  368. package/dist/trigger-secrets-shown.d.ts +2 -2
  369. package/dist/trigger-secrets-shown.js +1 -1
  370. package/dist/trigger-signatures.d.ts +26 -6
  371. package/dist/trigger-signatures.js +44 -8
  372. package/dist/trigger-targets.d.ts +2 -0
  373. package/dist/trigger-targets.js +1 -0
  374. package/dist/trigger-webhook.js +5 -2
  375. package/dist/triggers.d.ts +10 -6
  376. package/dist/triggers.js +37 -7
  377. package/dist/turn-end.d.ts +0 -3
  378. package/dist/turn-end.js +0 -3
  379. package/dist/turns.js +16 -1
  380. package/dist/usage-lines.d.ts +1 -1
  381. package/dist/validate.d.ts +6 -0
  382. package/dist/validate.js +41 -4
  383. package/dist/web-fetch.d.ts +1 -1
  384. package/dist/web-search.d.ts +10 -5
  385. package/dist/web-search.js +7 -6
  386. package/dist/webhooks.d.ts +147 -103
  387. package/dist/webhooks.js +564 -324
  388. package/dist/workflow/decision-recovery.d.ts +23 -0
  389. package/dist/workflow/decision-recovery.js +80 -0
  390. package/dist/workflow/decisions.d.ts +134 -0
  391. package/dist/workflow/decisions.js +46 -0
  392. package/dist/workflow/host-session.d.ts +5 -0
  393. package/dist/workflow/host-session.js +85 -0
  394. package/dist/workflow/host-tools.d.ts +3 -0
  395. package/dist/workflow/host-tools.js +3 -0
  396. package/dist/workflow/node-runner.d.ts +113 -0
  397. package/dist/workflow/node-runner.js +270 -0
  398. package/dist/workflow/node.d.ts +89 -0
  399. package/dist/workflow/node.js +101 -0
  400. package/dist/workflow/operator-error.d.ts +4 -0
  401. package/dist/workflow/operator-error.js +4 -0
  402. package/dist/workflow/pi-versions.d.ts +32 -0
  403. package/dist/workflow/pi-versions.js +65 -0
  404. package/dist/workflow/record-file.d.ts +10 -0
  405. package/dist/workflow/record-file.js +56 -0
  406. package/dist/workflow/record-tool.d.ts +77 -0
  407. package/dist/workflow/record-tool.js +126 -0
  408. package/dist/workflow/record.d.ts +151 -0
  409. package/dist/workflow/record.js +401 -0
  410. package/dist/workflow/run-error.d.ts +16 -0
  411. package/dist/workflow/run-error.js +26 -0
  412. package/dist/workflow/runner.d.ts +6 -0
  413. package/dist/workflow/runner.js +240 -0
  414. package/dist/workflow/store.d.ts +23 -0
  415. package/dist/workflow/store.js +242 -0
  416. package/dist/workflow/task.d.ts +133 -0
  417. package/dist/workflow/task.js +412 -0
  418. package/dist/workflow/thinking.d.ts +3 -0
  419. package/dist/workflow/thinking.js +7 -0
  420. package/dist/workflow/tool-context.d.ts +21 -0
  421. package/dist/workflow/tool-context.js +13 -0
  422. package/dist/workflow/types.d.ts +126 -0
  423. package/dist/workflow/types.js +1 -0
  424. package/dist/workflow-run.d.ts +2 -2
  425. package/dist/workspace/agent-computer.d.ts +137 -0
  426. package/dist/workspace/agent-computer.js +292 -0
  427. package/dist/workspace/archil-claim.d.ts +11 -0
  428. package/dist/workspace/archil-claim.js +18 -10
  429. package/dist/workspace/archil-disks.d.ts +49 -0
  430. package/dist/workspace/archil-disks.js +185 -0
  431. package/dist/workspace/archil-exec.js +2 -3
  432. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  433. package/dist/workspace/archil-mount-credential.js +13 -4
  434. package/dist/workspace/attached-computers.d.ts +41 -0
  435. package/dist/workspace/attached-computers.js +114 -0
  436. package/dist/workspace/computer-deps.d.ts +32 -17
  437. package/dist/workspace/computer-deps.js +37 -14
  438. package/dist/workspace/computer-for-claim.d.ts +58 -13
  439. package/dist/workspace/computer-for-claim.js +267 -26
  440. package/dist/workspace/computer-hold.d.ts +11 -27
  441. package/dist/workspace/computer-hold.js +36 -56
  442. package/dist/workspace/computer-janitor.d.ts +3 -2
  443. package/dist/workspace/computer-janitor.js +43 -9
  444. package/dist/workspace/computer-ledger.d.ts +5 -1
  445. package/dist/workspace/computer-ledger.js +11 -0
  446. package/dist/workspace/computer-mcp.d.ts +25 -0
  447. package/dist/workspace/computer-mcp.js +41 -0
  448. package/dist/workspace/computer-ports.d.ts +4 -13
  449. package/dist/workspace/computer-ports.js +4 -107
  450. package/dist/workspace/computer-script.d.ts +37 -0
  451. package/dist/workspace/computer-script.js +138 -0
  452. package/dist/workspace/executors.d.ts +1 -1
  453. package/dist/workspace/index.d.ts +7 -4
  454. package/dist/workspace/index.js +4 -1
  455. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  456. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  457. package/dist/workspace/resolve-computer.d.ts +45 -11
  458. package/dist/workspace/resolve-computer.js +72 -14
  459. package/dist/workspace/run-disk.d.ts +34 -0
  460. package/dist/workspace/run-disk.js +91 -0
  461. package/dist/workspace/run-tools.d.ts +35 -18
  462. package/dist/workspace/run-tools.js +24 -29
  463. package/dist/workspace/server-run-workspace.d.ts +3 -2
  464. package/dist/workspace/server-run-workspace.js +17 -4
  465. package/dist/workspace.js +1 -1
  466. package/package.json +19 -21
  467. package/templates/README.md +9 -6
  468. package/templates/code-review/agent.md +27 -11
  469. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  470. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  471. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  472. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  473. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  474. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  475. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  476. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  477. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  478. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  479. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  480. package/templates/code-review/evals/re-review/prompt.md +1 -1
  481. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  482. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  483. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  484. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  485. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  486. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  487. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  488. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  489. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  490. package/templates/code-review/findings.schema.json +131 -27
  491. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  492. package/templates/code-review/skills/review/DEEP.md +130 -0
  493. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  494. package/templates/code-review/skills/review/SKILL.md +104 -154
  495. package/templates/market-monitor/agent.md +1 -1
  496. package/dist/box/record.d.ts +0 -6
  497. package/dist/box/record.js +0 -41
  498. package/dist/box/sweep.d.ts +0 -53
  499. package/dist/box/sweep.js +0 -193
  500. package/dist/box-egress-vm.d.ts +0 -118
  501. package/dist/box-egress-vm.js +0 -354
  502. package/dist/box-egress.d.ts +0 -105
  503. package/dist/box-egress.js +0 -256
  504. package/dist/box-relay-vm.d.ts +0 -84
  505. package/dist/box-relay-vm.js +0 -437
  506. package/dist/box-relay.d.ts +0 -36
  507. package/dist/box-relay.js +0 -207
  508. package/dist/boxes.d.ts +0 -109
  509. package/dist/boxes.js +0 -249
  510. package/dist/budget.d.ts +0 -71
  511. package/dist/budget.js +0 -199
  512. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  513. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  514. package/dist/daytona-api.d.ts +0 -10
  515. package/dist/daytona-api.js +0 -20
  516. package/dist/egress-proxy.d.ts +0 -45
  517. package/dist/egress-proxy.js +0 -416
  518. package/dist/egress-table.d.ts +0 -24
  519. package/dist/egress-table.js +0 -165
  520. package/dist/run-db.d.ts +0 -53
  521. package/dist/run-db.js +0 -116
  522. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -0,0 +1,43 @@
1
+ import { CodemodeSandbox } from "@earendil-works/pi-codemode";
2
+ import { CODEMODE_TOOL_NAME, createCodemodeExtension } from "@earendil-works/pi-durable/codemode";
3
+ import { COMPUTER_CALL_GLOBAL, scriptPrelude } from "@parcha/agentrun-computer/surface";
4
+ import { SCRIPT_MAX_MS } from "../../workspace/index.js";
5
+ /** The code mode tool's name, as the model calls it and the gate reads it. */
6
+ export const PI_CODEMODE_TOOL = CODEMODE_TOOL_NAME;
7
+ const MEMORY_BYTES = 256 * 1024 * 1024;
8
+ /** A sandbox whose every script starts with `prelude`: one line, so the script's own line numbers hold. A rerun after a
9
+ * restart starts from the same code, so its replay is the first run's. */
10
+ class PreludedSandbox extends CodemodeSandbox {
11
+ #prelude;
12
+ constructor(prelude, options) {
13
+ super(options);
14
+ this.#prelude = prelude;
15
+ }
16
+ execute(code, options) {
17
+ return super.execute(`${this.#prelude}\n${code}`, options);
18
+ }
19
+ start(code, options) {
20
+ return super.start(`${this.#prelude}\n${code}`, options);
21
+ }
22
+ }
23
+ /** pi's code mode extension with `computer` bound to `computer`'s surface: install it among the run's pi-native
24
+ * extensions (PiAdapterOptions.extensions). No `models.*` in scripts: a script's paid work is the run's own tools. */
25
+ export function computerCodemode(computer) {
26
+ const sandbox = new PreludedSandbox(scriptPrelude(computer.card), { timeoutMs: SCRIPT_MAX_MS, memoryLimitBytes: MEMORY_BYTES });
27
+ return createCodemodeExtension({
28
+ sandbox,
29
+ models: false,
30
+ // No tool listed again in the system prompt's codemode section: every tool is offered as itself (code mode "on"),
31
+ // computer_script's description declares `computer` once, and a script finds any other with searchTools().
32
+ inlineBudget: 0,
33
+ globals: [{
34
+ name: COMPUTER_CALL_GLOBAL,
35
+ spread: true,
36
+ // The value whole, images and all: a script shows one with image(...).
37
+ execute: async (given, _api, context) => {
38
+ const [op, args] = given;
39
+ return (await computer.guard.call(String(op), args, (sent) => computer.port.call(String(op), sent ?? {}, context.abortSignal)));
40
+ },
41
+ }],
42
+ });
43
+ }
@@ -1,8 +1,8 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import type { Models } from "@earendil-works/pi-ai";
3
- import { type Extension, type Harness, type Registry } from "@earendil-works/pi-durable";
3
+ import { type Extension, type Harness, type Registry, type ToolRegistration } from "@earendil-works/pi-durable";
4
4
  import { type AgentAdapter, type SessionIO, type SessionPort, type Wire } from "@parcha/agentrun-kernel";
5
- import { type ProviderPolicy } from "@parcha/agentrun-kernel/host";
5
+ import { type ModelProxy, type ProviderPolicy } from "@parcha/agentrun-kernel/host";
6
6
  import { CALL_REFUSED } from "../../timeline/index.js";
7
7
  /** What the adapter loop lends pi for one claim: the run's Harness, its registry, and where pi's models go. */
8
8
  export interface PiRun {
@@ -22,6 +22,8 @@ export interface PreIntentCall {
22
22
  /** The tool calls the call's conversation made before it, at most `upTo`, read from its committed entries (tool-budget.ts
23
23
  * countCalls), for the gate's tool-call budget: pi's model-issued calls only, never a nested call or a CLI's. */
24
24
  readonly callsBefore?: (upTo: number) => Promise<number>;
25
+ /** The call's conversation's own tool-call budget (tool-budget.ts ConversationToolBudget, a subagent's), if it has one. */
26
+ readonly ownBudget?: () => Promise<number | undefined>;
25
27
  /** A call a running tool made (pi's nested call), part of a call already let through: the cap's wrap-up never refuses
26
28
  * one (tool-budget.ts), so a tool in flight is never cut short. */
27
29
  readonly nested?: true;
@@ -75,6 +77,14 @@ export interface PiAdapterOptions {
75
77
  * claim's Harness. Their tools pass the session's gate (its beforeTool hook), and every conversation they open takes
76
78
  * its model from the root's agent, through this session's proxy and its booking. */
77
79
  readonly extensions?: readonly Extension[];
80
+ /** The run's web_search is its provider's own hosted search (its plane resolves it "native", hosted-search.ts): the
81
+ * session's policy admits that hosted tool, a request carrying it held at its search allowance, and the proxy prices
82
+ * each search the provider reports at its fee, so the search's one request is booked once with its searches. */
83
+ readonly webSearch?: boolean;
84
+ /** pi-native tools the session's own extension carries beside its host tools (the subagent tool: runner/subagent.ts):
85
+ * pi's own tool tasks, under the session's gate like every call. Read when the session opens. A conversation one of
86
+ * them opens keeps the session's extension, so its calls pass the same gate; its own `tools` say which it is offered. */
87
+ readonly tools?: readonly ToolRegistration[];
78
88
  /** The run's models of other tiers than its own (a learned workflow's node of a tier: AGENT_MODEL_FAST,
79
89
  * AGENT_MODEL_STRONG), by tier, each a model route as the session's is: read when the session opens, each on a proxy of
80
90
  * its own beside the session's (its origin, credential, price and fetch), on the session's booking (io.models), so its
@@ -88,6 +98,8 @@ export type TierModel = Pick<PiAdapterOptions, "provider" | "model" | "like" | "
88
98
  /** The tier proxies a session holds (openTierProxies): each tier's port for a side request under `label`, and their close. */
89
99
  export interface TierProxies {
90
100
  port(label: string, tier: string): SessionPort | undefined;
101
+ /** Each tier, its route and its proxy: a subagent's child on the tier is sent there on the proxy's own key. */
102
+ readonly each: readonly (readonly [string, TierModel, ModelProxy])[];
91
103
  close(): Promise<void>;
92
104
  }
93
105
  /** A run's models of other tiers than its own (a learned workflow's node of a tier: AGENT_MODEL_FAST, AGENT_MODEL_STRONG),
@@ -96,18 +108,19 @@ export interface TierProxies {
96
108
  * keys, AdapterSession.port's `tier`), sent by pi-ai's client of the tier model's own wire (port-models.ts), so a tier
97
109
  * proxy speaks its model's route (model-route.ts routeOf, its translation fetch for a model of neither wire), never the
98
110
  * harness's. One that fails to start closes those started. */
99
- export declare function openTierProxies(tiers: ReadonlyMap<string, TierModel>, hooks: SessionIO["models"], redact?: (text: string) => string): Promise<TierProxies>;
111
+ export declare function openTierProxies(tiers: ReadonlyMap<string, TierModel>, hooks: SessionIO["models"], redact?: (text: string) => string, tools?: readonly string[]): Promise<TierProxies>;
100
112
  /** The session proxy's policy on Messages: claude-agent's (no fork), with pi's tools, the host's own names (`tools`), as
101
113
  * the names its client offers by themselves (its builtins). The CLI's own `mcp__hands__` prefix is not pi's: under it
102
114
  * every one of pi's tool definitions would be dropped and the model offered none. Every other tool definition is
103
115
  * dropped, and a request that offers the session's tools is the turn's answer request. `auth`: how the provider takes
104
116
  * its credential (default x-api-key). */
105
- export declare function piPolicy(model: string, tools: readonly string[], auth?: "bearer" | "x-api-key"): ProviderPolicy;
117
+ export declare function piPolicy(model: string, tools: readonly string[], auth?: "bearer" | "x-api-key", webSearch?: boolean): ProviderPolicy;
106
118
  /** The policy of the session's wire, the one each CLI harness of that wire applies (no fork of either): Anthropic's
107
119
  * Messages as claude-agent's (piPolicy), OpenAI's Responses as codex's, which takes pi's tools as the session's own by
108
120
  * name. Either way every other tool definition is dropped and the request that offers them is the turn's answer
109
- * request. */
110
- export declare function policyFor(provider: PiAdapterOptions["provider"], model: string, tools: readonly string[]): Promise<ProviderPolicy>;
121
+ * request. `webSearch`: the run's web_search is the provider's hosted search, whose one tool each wire's policy admits
122
+ * as its CLI's own search (claude-agent's on Messages, codex's live search on Responses). */
123
+ export declare function policyFor(provider: PiAdapterOptions["provider"], model: string, tools: readonly string[], webSearch?: boolean): Promise<ProviderPolicy>;
111
124
  /** A refused call's words by call (the gate's deny, main's words), held from the refusal (beforeTool's block) to the
112
125
  * call's result (afterTool): a blocked result becomes those words alone, an error, as main gives a refused call's
113
126
  * result, never pi's framing of a blocked call. Every other result is pi's own. `held`: the words still held. */
@@ -1,15 +1,17 @@
1
1
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
2
2
  import { createModels } from "@earendil-works/pi-ai/models";
3
3
  import { defineExtension, defineTool, GenerationTask, hook, ToolTask } from "@earendil-works/pi-durable";
4
- import { anthropicPolicy } from "@parcha/agentrun-harness-claude";
4
+ import { anthropicPolicy, CLAUDE_WEB_SEARCH_USD, withWebSearches } from "@parcha/agentrun-harness-claude";
5
5
  import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
6
6
  import { startModelProxy } from "@parcha/agentrun-kernel/host";
7
7
  import { randomBytes } from "node:crypto";
8
8
  import { DEFAULT_HARNESS } from "../../harness.js";
9
- import { sessionProvider } from "../../port-models.js";
9
+ import { durableWait } from "../../workflow/pi-versions.js";
10
+ import { HOSTED_SEARCH_ALLOWANCE_TOKENS } from "../../hosted-search.js";
11
+ import { sessionProvider, tierProvider } from "../../port-models.js";
10
12
  import { KINDS } from "../journal-kinds.js";
11
13
  import { CALL_REFUSED } from "../../timeline/index.js";
12
- import { countCalls } from "../../tool-budget.js";
14
+ import { ConversationToolBudget, countCalls } from "../../tool-budget.js";
13
15
  const PROVIDER = "agentrun-session";
14
16
  const INPUT_REQUEST = "agentrun:input";
15
17
  /** pi as an AgentAdapter for one claim's run. */
@@ -22,21 +24,22 @@ export function piAdapter(options) {
22
24
  open: (spec, io) => openPi(options, spec, io),
23
25
  };
24
26
  }
25
- /** The names of the run's pi-native extensions' tools (options.extensions): the model is offered them beside the session's
27
+ /** The names of the run's pi-native tools (options.extensions' and options.tools): the model is offered them beside the session's
26
28
  * own (so it may call one), and pi runs it. Offered and run by one mechanism; sessionOn never also piTool-wraps a session
27
29
  * tool a native extension already owns, so the name is in the request's tools exactly once. */
28
- const nativeToolNames = (options) => (options.extensions ?? []).flatMap((extension) => extension.tools ?? []).map((tool) => tool.name);
30
+ const nativeToolNames = (options) => [...(options.extensions ?? []).flatMap((extension) => extension.tools ?? []), ...(options.tools ?? [])].map((tool) => tool.name);
29
31
  async function openPi(options, spec, io) {
30
- const { model } = options;
31
32
  const context = withAbortSignal(io.signal, BACKGROUND_CONTEXT);
32
33
  // The session's route: pi-ai's requests reach the provider only through this proxy, which admits and books each one
33
34
  // through the runner's booking (io.models).
34
- const proxy = await routeProxy(options, io.models, [...spec.tools.map((tool) => tool.name), ...nativeToolNames(options)], options.redact);
35
+ // Its web_search native (options.webSearch): the session's own proxy admits the hosted search and prices its searches.
36
+ const proxy = await routeProxy(options, io.models, [...spec.tools.map((tool) => tool.name), ...nativeToolNames(options)], options.redact, undefined, options.webSearch === true);
35
37
  // An open that fails from here (the claim lost while the session opened) closes the proxies: their servers would hold
36
38
  // the runner's process open.
37
39
  let tiers;
38
40
  try {
39
- tiers = await openTierProxies(options.tiers ?? new Map(), io.models, options.redact);
41
+ // A tier's proxy admits the session's tools too: a subagent's child on the tier offers them (runner/subagent.ts).
42
+ tiers = await openTierProxies(options.tiers ?? new Map(), io.models, options.redact, [...spec.tools.map((tool) => tool.name), ...nativeToolNames(options)]);
40
43
  return await sessionOn(proxy, options, spec, io, context, tiers);
41
44
  }
42
45
  catch (error) {
@@ -47,17 +50,19 @@ async function openPi(options, spec, io) {
47
50
  }
48
51
  /** A proxy on `hooks` (the session's booking: its requests are the run's, under its one cap) for `route`'s model, with its
49
52
  * origin, credential, price and fetch, its provider's errors through `redact`. `tools`: the tool names its policy admits
50
- * by name on a request of the session's own key (none for a tier's: only side keys reach it). */
51
- async function routeProxy(route, hooks, tools, redact, tier) {
53
+ * by name on a request of the session's own key (none for a tier's: only side keys reach it). `webSearch`: the session's
54
+ * own proxy admits its provider's hosted search and prices each search it ran (policyFor, withSearches). */
55
+ async function routeProxy(route, hooks, tools, redact, tier, webSearch = false) {
56
+ const price = route.price && webSearch ? await withSearches(route.provider.api, route.price) : route.price;
52
57
  return startModelProxy({
53
58
  // A tier's proxy names its tier on each request (ModelRequest.route), so the run's cap prices it as this route books it.
54
59
  ...(tier === undefined ? {} : { route: tier }),
55
- policy: await policyFor(route.provider, route.model, tools),
60
+ policy: await policyFor(route.provider, route.model, tools, webSearch),
56
61
  hooks,
57
62
  model: route.model,
58
63
  origin: route.provider.origin,
59
64
  credential: async () => (await route.provider.credential()) ?? "",
60
- ...(route.price ? { price: route.price } : {}),
65
+ ...(price ? { price: price } : {}),
61
66
  ...(route.provider.headers ? { headers: route.provider.headers } : {}),
62
67
  ...(route.fetch ? { fetch: route.fetch } : {}),
63
68
  ...(redact ? { redact } : {}),
@@ -69,7 +74,7 @@ async function routeProxy(route, hooks, tools, redact, tier) {
69
74
  * keys, AdapterSession.port's `tier`), sent by pi-ai's client of the tier model's own wire (port-models.ts), so a tier
70
75
  * proxy speaks its model's route (model-route.ts routeOf, its translation fetch for a model of neither wire), never the
71
76
  * harness's. One that fails to start closes those started. */
72
- export async function openTierProxies(tiers, hooks, redact) {
77
+ export async function openTierProxies(tiers, hooks, redact, tools = []) {
73
78
  const open = new Map();
74
79
  const close = async () => {
75
80
  for (const { proxy } of open.values())
@@ -77,7 +82,7 @@ export async function openTierProxies(tiers, hooks, redact) {
77
82
  };
78
83
  try {
79
84
  for (const [tier, route] of tiers)
80
- open.set(tier, { proxy: await routeProxy(route, hooks, [], redact, tier), route });
85
+ open.set(tier, { proxy: await routeProxy(route, hooks, tools, redact, tier), route });
81
86
  }
82
87
  catch (error) {
83
88
  await close();
@@ -88,6 +93,7 @@ export async function openTierProxies(tiers, hooks, redact) {
88
93
  const at = open.get(tier);
89
94
  return at ? { url: at.proxy.url, key: at.proxy.sideKey(label), model: at.route.model, api: at.route.provider.api } : undefined;
90
95
  },
96
+ each: [...open].map(([tier, { proxy, route }]) => [tier, route, proxy]),
91
97
  close,
92
98
  };
93
99
  }
@@ -96,19 +102,74 @@ export async function openTierProxies(tiers, hooks, redact) {
96
102
  * every one of pi's tool definitions would be dropped and the model offered none. Every other tool definition is
97
103
  * dropped, and a request that offers the session's tools is the turn's answer request. `auth`: how the provider takes
98
104
  * its credential (default x-api-key). */
99
- export function piPolicy(model, tools, auth) {
100
- return anthropicPolicy({ model, tools: [], builtins: tools, ...(auth ? { auth } : {}) });
105
+ export function piPolicy(model, tools, auth, webSearch = false) {
106
+ const policy = anthropicPolicy({ model, tools: [], builtins: tools, ...(auth ? { auth } : {}), ...(webSearch ? { webSearch: true, webSearchAllowance: HOSTED_SEARCH_ALLOWANCE_TOKENS } : {}) });
107
+ if (!webSearch)
108
+ return policy;
109
+ // The hosted search's fees held with its tokens: each use its tool's max_uses allows, at the search's fee. One with no
110
+ // max_uses has no bound, and its worst case is unknown (the proxy's feeMaxUsd).
111
+ return { ...policy, feeMaxUsd: (body) => searchesAllowed(body, (tool) => typeof tool.type === "string" && tool.type.startsWith("web_search_"), "max_uses") * CLAUDE_WEB_SEARCH_USD };
112
+ }
113
+ /** The most searches `body` allows its hosted search tool (the one `isSearch` picks): its `limit` (the tool's own key, or
114
+ * the body's on Responses), Infinity when it states none, 0 when the body offers no search. */
115
+ function searchesAllowed(body, isSearch, limit, bodyLimit = false) {
116
+ const search = Array.isArray(body.tools) ? body.tools.find((tool) => typeof tool === "object" && tool !== null && isSearch(tool)) : undefined;
117
+ if (!search)
118
+ return 0;
119
+ const most = bodyLimit ? body[limit] : search[limit];
120
+ return typeof most === "number" && Number.isInteger(most) && most >= 0 ? most : Infinity;
101
121
  }
102
122
  /** The policy of the session's wire, the one each CLI harness of that wire applies (no fork of either): Anthropic's
103
123
  * Messages as claude-agent's (piPolicy), OpenAI's Responses as codex's, which takes pi's tools as the session's own by
104
124
  * name. Either way every other tool definition is dropped and the request that offers them is the turn's answer
105
- * request. */
106
- export async function policyFor(provider, model, tools) {
125
+ * request. `webSearch`: the run's web_search is the provider's hosted search, whose one tool each wire's policy admits
126
+ * as its CLI's own search (claude-agent's on Messages, codex's live search on Responses). */
127
+ export async function policyFor(provider, model, tools, webSearch = false) {
107
128
  if (provider.api === "anthropic-messages")
108
- return piPolicy(model, tools, provider.auth);
129
+ return piPolicy(model, tools, provider.auth, webSearch);
109
130
  // Loaded when a session of its wire opens, as the runner loads the codex harness.
110
- const { codexPolicy } = (await import("@parcha/agentrun-harness-codex"));
111
- return codexPolicy({ model, tools });
131
+ const { codexPolicy, webSearchUsd } = (await import("@parcha/agentrun-harness-codex"));
132
+ if (!webSearch)
133
+ return codexPolicy({ model, tools });
134
+ return searchOnce(codexPolicy({ model, tools, webSearch: "live" }), codexPolicy({ model, tools }), webSearchUsd(model));
135
+ }
136
+ /** Codex's live-search policy (`live`) as pi's session takes it. The Codex CLI offers its search on every request; pi
137
+ * offers it on one request alone, its web_search's hosted search (hosted-search.ts), so two of its rules are pi's here:
138
+ * - a request that offered no search ran none (0), read from the request's body, where codex's reads every answer that
139
+ * does not state its count as unknown; the search's own request is read as codex reads it;
140
+ * - the hosted search's request has an input bound, its body's (`plain`, the policy with no search) plus the input
141
+ * HOSTED_SEARCH_ALLOWANCE_TOKENS allows its at most HOSTED_MAX_USES searches, as claude-agent's policy bounds Claude's
142
+ * search, so a capped run holds it and does not refuse it as unmeasured; and its fees are held with its tokens, each
143
+ * call its `max_tool_calls` allows at `searchUsd`, the model's price of one (none known: its worst case is unknown). */
144
+ function searchOnce(live, plain, searchUsd) {
145
+ const offersSearch = (body) => Array.isArray(body.tools) && body.tools.some((tool) => typeof tool === "object" && tool !== null && tool.type === "web_search");
146
+ return {
147
+ ...live,
148
+ usageOf: (text, body) => {
149
+ if (!body || offersSearch(body))
150
+ return live.usageOf(text, body);
151
+ const usage = plain.usageOf(text, body);
152
+ return usage && { ...usage, webSearches: 0 };
153
+ },
154
+ feeMaxUsd: (body) => {
155
+ const most = searchesAllowed(body, (tool) => tool.type === "web_search", "max_tool_calls", true);
156
+ return most === 0 ? 0 : most * (searchUsd ?? Number.NaN);
157
+ },
158
+ serverInputOverhead: (body) => {
159
+ if (!offersSearch(body))
160
+ return live.serverInputOverhead?.(body);
161
+ const base = plain.serverInputOverhead?.({ ...body, tools: body.tools.filter((tool) => !(typeof tool === "object" && tool !== null && tool.type === "web_search")) });
162
+ return base === undefined ? undefined : base + HOSTED_SEARCH_ALLOWANCE_TOKENS;
163
+ },
164
+ };
165
+ }
166
+ /** `price` with each web search a response reports added at its provider's fee, as the wire's CLI prices its own search
167
+ * (claude-agent's flat fee on Messages, codex's per model on Responses). */
168
+ async function withSearches(api, price) {
169
+ if (api === "anthropic-messages")
170
+ return withWebSearches(price);
171
+ const codex = (await import("@parcha/agentrun-harness-codex"));
172
+ return codex.withWebSearches(price);
112
173
  }
113
174
  /** The session on its proxy: pi's models through it, the host's tools and the gate as pi's extension, the root's state. */
114
175
  async function sessionOn(proxy, options, spec, io, context, tiers) {
@@ -119,7 +180,22 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
119
180
  // proxy's booking does), so the model's cost stays $0. Image input on either wire (sessionModel): a host tool's images
120
181
  // (a screenshot) reach the model in its tool result.
121
182
  models.setProvider(sessionProvider(api, proxy, model, { provider: PROVIDER, keyName: "AGENTRUN_SESSION_KEY", ...(like ? { like } : {}), reasoning: false }));
122
- run.setModels(models);
183
+ // Each tier's model at its own proxy, under its own provider id (tierProvider): a conversation whose agent names it
184
+ // (a subagent's) is sent there, and booked as the session's own requests are.
185
+ for (const [tier, route, at] of tiers.each)
186
+ models.setProvider(sessionProvider(route.provider.api, at, route.model, { provider: tierProvider(tier), keyName: "AGENTRUN_SESSION_KEY", ...(route.like ? { like: route.like } : {}), reasoning: false }));
187
+ // A child made on an earlier claim keeps the tier's model it was made on; when the tier's model has changed since (the
188
+ // server's AGENT_MODEL_STRONG, say), that one is not here, and the child resumes on the tier's model now, as a new call
189
+ // on the tier would run.
190
+ const tierModel = new Map(tiers.each.map(([tier, route]) => [tierProvider(tier), route.model]));
191
+ run.setModels(tierModel.size === 0 ? models : new Proxy(models, {
192
+ get(target, key) {
193
+ if (key === "getModel")
194
+ return (provider, id) => target.getModel(provider, id) ?? (tierModel.has(provider) ? target.getModel(provider, tierModel.get(provider)) : undefined);
195
+ const value = Reflect.get(target, key, target);
196
+ return typeof value === "function" ? value.bind(target) : value;
197
+ },
198
+ }));
123
199
  // A session tool whose name a native extension already owns is run by that extension (pi's own tool task), so it is not
124
200
  // piTool-wrapped here too: one tool by that name on the agent, offered once.
125
201
  const owned = new Set(nativeToolNames(options));
@@ -127,7 +203,7 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
127
203
  // intent: a call it runs with no pass here is one it reruns after a crash (a replay-safe call whose intent an earlier
128
204
  // attempt stored), told to the host tool as an attempt above 0, so the loop asks the gate about it again.
129
205
  const passed = new Set();
130
- const tools = spec.tools.filter((tool) => !owned.has(tool.name)).map((tool) => piTool(tool, io, (callId) => (io.gate ? (passed.has(callId) ? 0 : 1) : undefined)));
206
+ const tools = [...spec.tools.filter((tool) => !owned.has(tool.name)).map((tool) => piTool(tool, io, (callId) => (io.gate ? (passed.has(callId) ? 0 : 1) : undefined))), ...(options.tools ?? [])];
131
207
  // A refused call's words (the gate's deny, main's), by call: its result is those words alone, as main gives them.
132
208
  const refusals = refusalWords();
133
209
  const extension = defineExtension({
@@ -140,7 +216,7 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
140
216
  return undefined;
141
217
  // A model-issued call's count, read only when the gate holds a budget: a nested call (one a tool made) is its
142
218
  // parent's part, and is marked so (the cap's wrap-up lets it through).
143
- const counted = call.parent === undefined ? { callsBefore: (upTo) => callsBefore(api, call.id, upTo, hookContext) } : { nested: true };
219
+ const counted = call.parent === undefined ? { callsBefore: (upTo) => callsBefore(api, call.id, upTo, hookContext), ownBudget: async () => (await api.snapshot(ConversationToolBudget, api.conversationId, hookContext))?.toolCalls } : { nested: true };
144
220
  const answer = await io.gate({ callId: call.id, tool: call.name, args: (call.arguments ?? {}), ...counted }, hookContext);
145
221
  if (answer === "allow") {
146
222
  passed.add(call.id);
@@ -201,10 +277,19 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
201
277
  const existing = await run.harness.commit((tx) => tx.submissionByRequest(root.id, INPUT_REQUEST), context);
202
278
  if (existing)
203
279
  input = await run.harness.submission(existing.id, context);
204
- let state = existing === undefined ? "new" : existing.status === "done" ? "idle" : "open_turn";
280
+ // Once that first input is settled, a later input of the root still in flight (a follow-up a reopen sent, its turn cut by
281
+ // a lost claim or a drain) is the turn the session is in: its end is the one recover() reads, never the first input's.
282
+ const later = existing && (existing.status === "done" || existing.status === "unanswered")
283
+ ? (await run.harness.inspect(context)).submissions.filter((one) => one.conversationId === root.id && one.type === "input").at(-1)
284
+ : undefined;
285
+ if (later)
286
+ input = await run.harness.submission(later.id, context);
287
+ let state = existing === undefined ? "new" : later ? "open_turn" : existing.status === "done" ? "idle" : "open_turn";
205
288
  let running;
206
289
  const watch = (submission) => {
207
- running = submission.wait(context).then((record) => {
290
+ // Its wait never holds the claim's signal (durableWait): an abort while it registers (a close, a lost claim, as a
291
+ // resumed loop opens) ends the turn interrupted here, never as a rejection nothing handles, which ends the process.
292
+ running = durableWait((at) => submission.wait(at), context).then((record) => {
208
293
  state = "idle";
209
294
  const status = record.status === "done" ? "completed" : "failed";
210
295
  io.onEvent({ type: "turn_end", status });
@@ -26,13 +26,17 @@ export declare function besideStopping(server: {
26
26
  * adapter loop, a learning run on the learning loop. `env`: the runs' environment (runEnv of this process's, unless a
27
27
  * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
28
28
  * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
29
- * too (workspace/computer-janitor.ts), as the CLI's start asks. Returns the runner and a close() that stops both and
30
- * closes its store. */
31
- export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor }?: {
29
+ * too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
30
+ * holds each paired computer's socket in this process, so a run here takes one. Returns the runner and a close() that
31
+ * stops both and closes its store. */
32
+ export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor, hub, mcpLoopback, onLine }?: {
32
33
  loops?: number;
33
34
  drainMs?: number;
34
35
  env?: NodeJS.ProcessEnv;
35
36
  janitor?: boolean;
37
+ hub?: import("@parcha/agentrun-computer").AttachHub;
38
+ mcpLoopback?: boolean;
39
+ onLine?: (line: string) => void;
36
40
  }): Promise<{
37
41
  runner: Awaited<ReturnType<typeof import("./runner.js")["startRunner"]>>;
38
42
  close: () => Promise<void>;
@@ -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,22 +53,36 @@ 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
- const computers = computerDepsFrom({ env: runs, store, sealKey: seal.key, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs) });
62
- const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps });
61
+ const { PROVIDERS } = await import("@parcha/agentrun-computer");
62
+ const { hostCommandRefusals } = await import("../computers.js");
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}`) });
63
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.
64
69
  const { runnerMemory } = await import("./memory-claim.js");
65
- 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 } : {}) });
66
78
  // The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
67
79
  // runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
68
80
  const { startJanitor } = await import("../workspace/computer-janitor.js");
69
81
  const swept = janitor ? startJanitor({ store, computers: computers.computerDeps, env: runs, log: (line) => console.error(`agentrun-serve runner: ${line}`) }) : undefined;
82
+ // Its close waits for any first-use install its claims let go of to stop (its npm ended) before it lets go of the data.
83
+ const { claimInstallsStopped } = await import("../harness-install.js");
70
84
  // The janitor's sweep is cut and waited for on a bound of its own, beside the runner's close, never before it.
71
- return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await store.close(); seal.release(); } };
85
+ return { runner, close: async () => { await Promise.all([swept?.close(), runner.close()]); await claimInstallsStopped(); await store.close(); seal.release(); } };
72
86
  }
73
87
  /** A server and one runner beside it, both in this process, as the CLI's start composes them (cli.ts): the runner holds
74
88
  * what the server's options say (besideRunnerOptions) and sees the server's test switches (fauxEnvOf), so a --faux
@@ -79,7 +93,7 @@ export async function serveWithRunner(options) {
79
93
  const { besideRunEnv } = await import("./main.js");
80
94
  const { loops, drainMs } = besideRunnerOptions(options, process.env);
81
95
  const serve = await startServe(options);
82
- 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) => {
83
97
  await serve.close();
84
98
  throw error;
85
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,9 +9,33 @@ 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 claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
13
- * laid things in since (a follow-up's) stays, with what is in it. */
14
- export declare function sweepScratch(dir: string, parents: readonly string[]): Promise<void>;
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;
24
+ /** `tools` in the order the agent grants them (`granted`, catalog names; a tool is listed by its catalog name's wire
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
26
+ * does not name (one a granted tool or the run's computer brings beside it) right after the tool listed before it. Ties
27
+ * keep the order given. */
28
+ export declare function inGrantOrder<T extends {
29
+ readonly name: string;
30
+ }>(tools: readonly T[], granted: readonly string[]): T[];
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>;
15
39
  /**
16
40
  * One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
17
41
  *