@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
@@ -18,9 +18,14 @@
18
18
  // start asks for it (the CLI's runner and the runner subcommand), never under --faux, and never two sweeps at once. Its
19
19
  // close cuts a sweep under way and waits for it on a bound of its own (JANITOR_CLOSE_MS), so a stuck vendor call never
20
20
  // holds up the runner's stop.
21
- import { epochOf, ok, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
21
+ //
22
+ // An agent's own computer (a persistent setting, agent-computer.ts) is this server's when its owner names this server's
23
+ // id, never by its run: it goes only when its agent no longer wants it (ownerGoneOf: gone, archived, or no longer
24
+ // persistent on that provider), never by a deadline. Without the store's settings and agents, none is this server's.
25
+ import { epochOf, ok, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
22
26
  import { KEY_TABLE, providerOptions } from "../computer-keys.js";
23
27
  import { FAUX_ENV } from "../model.js";
28
+ import { deleteUnderHold, ownerGoneOf, serverIdOf, wantsOn } from "./agent-computer.js";
24
29
  import { storeLedger } from "./computer-ledger.js";
25
30
  import { providerKeys } from "./resolve-computer.js";
26
31
  /** How often the janitor sweeps after its first sweep at the runner's start. */
@@ -35,8 +40,15 @@ const runsByHash = (store) => {
35
40
  return () => (read ??= store.runs.list({}).then((rows) => new Map(rows.map((row) => [runHash(row.id), row.id]))));
36
41
  };
37
42
  /** Whether a listed computer is this server's and no claim holds it: its run (by its label, or its hash's) is in this
38
- * store, and no claim holds the run now (by the store's clock), or one holds it at a later epoch than the computer's. */
39
- async function sweepable(store, labels, byHash) {
43
+ * store, and no claim holds the run now (by the store's clock), or one holds it at a later epoch than the computer's.
44
+ * An agent's own computer (owned, or an owner label, readable or not) is this server's when its owner names
45
+ * `serverId`, whatever its run: the sweep's ownerGone then decides. */
46
+ async function sweepable(store, info, byHash, serverId) {
47
+ const { labels } = info;
48
+ const label = ownerOf(labels);
49
+ const owner = info.owner ?? (label.ok ? label.value : undefined);
50
+ if (info.owned === true || owner !== undefined || !label.ok)
51
+ return serverId !== undefined && owner?.server === serverId;
40
52
  const named = labels[RUN_LABEL];
41
53
  const hash = labels[RUN_HASH_LABEL];
42
54
  const runId = typeof named === "string" && named !== "" ? named : typeof hash === "string" && hash !== "" ? (await byHash()).get(hash) : undefined;
@@ -55,7 +67,11 @@ async function sweepable(store, labels, byHash) {
55
67
  }
56
68
  /** `provider` as the sweep sees it: its list cut to this server's computers that no claim holds, and no leftovers pass.
57
69
  * Each call goes to the provider itself, so its own state is used as it is. */
58
- function thisServers(provider, store, byHash) {
70
+ function thisServers(provider, store, byHash, serverId) {
71
+ // The agents' own computers the list kept, by id: their delete goes under the agent's hold (deleteUnderHold), which
72
+ // also clears the agent's record of it, so its view no longer shows it deleting.
73
+ const ownedBy = new Map();
74
+ const { settings, agents } = store;
59
75
  return {
60
76
  id: provider.id,
61
77
  version: provider.version,
@@ -65,15 +81,29 @@ function thisServers(provider, store, byHash) {
65
81
  attach: (target, context) => provider.attach(target, context),
66
82
  network: (ref, policy, context) => provider.network(ref, policy, context),
67
83
  connect: (ref) => provider.connect(ref),
68
- release: (ref, how) => provider.release(ref, how),
84
+ release(ref, how, context) {
85
+ const agent = ownedBy.get(ref.id);
86
+ if (how !== "delete" || agent === undefined || settings === undefined)
87
+ return provider.release(ref, how, context);
88
+ // Asked again under the hold: the agent may want it back since ownerGone was read (this server's owners carry no
89
+ // idle TTL, so that is the one reason the sweep deletes one).
90
+ const due = async () => !agents || !(await wantsOn({ agents }, agent, provider.id));
91
+ return deleteUnderHold({ settings, runs: store.runs }, agent, ref.id, due, () => provider.release(ref, how, context));
92
+ },
69
93
  async list(labels, context) {
70
94
  const listed = await provider.list(labels, context);
71
95
  if (!listed.ok)
72
96
  return listed;
73
97
  const kept = [];
74
- for (const info of listed.value)
75
- if (await sweepable(store, info.labels, byHash))
76
- kept.push(info);
98
+ for (const info of listed.value) {
99
+ if (!(await sweepable(store, info, byHash, serverId)))
100
+ continue;
101
+ const label = ownerOf(info.labels);
102
+ const owner = info.owner ?? (label.ok ? label.value : undefined);
103
+ if (owner !== undefined)
104
+ ownedBy.set(info.ref.id, owner.agent);
105
+ kept.push(info);
106
+ }
77
107
  return ok(kept);
78
108
  },
79
109
  };
@@ -103,6 +133,9 @@ export async function sweepServerComputers(deps, signal) {
103
133
  const at = (deps.now ?? Date.now)();
104
134
  const keysOf = providerKeys(computers.kinds, computers.keyOf ?? (async () => undefined));
105
135
  const byHash = runsByHash(store);
136
+ // This server's id and its agents: its agents' own computers are swept by their owner (ownerGoneOf).
137
+ const { settings, agents } = store;
138
+ const serverId = settings && agents ? await serverIdOf({ settings }) : undefined;
106
139
  const out = [];
107
140
  for (const entry of computers.kinds.PROVIDERS) {
108
141
  if (signal?.aborted)
@@ -120,7 +153,8 @@ export async function sweepServerComputers(deps, signal) {
120
153
  // A vendor that ends its own computers needs no janitor.
121
154
  if (provider.capabilities().lifetime !== "janitor")
122
155
  continue;
123
- out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash), { now: new Date(at), signal: cut })) });
156
+ const ownerGone = serverId !== undefined && settings && agents ? ownerGoneOf({ agents, settings, runs: store.runs }, serverId, entry.id) : undefined;
157
+ out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash, serverId), { now: new Date(at), signal: cut, ...(ownerGone ? { ownerGone } : {}) })) });
124
158
  }
125
159
  catch (error) {
126
160
  out.push({ provider: entry.id, swept: { ok: false, error: { code: "refused", message: error instanceof Error ? error.message : String(error) } } });
@@ -4,12 +4,16 @@ export interface LedgerEntry {
4
4
  id: string;
5
5
  labels: Record<string, string>;
6
6
  }
7
- /** One provider's ledger, in the shape a descriptor's `ledger` option takes: put, get, list and remove of its entries. */
7
+ /** One provider's ledger, in the shape a descriptor's `ledger` option takes: put, claim, get, list, remove and swap of its entries. */
8
8
  export interface ProviderLedger<E extends LedgerEntry = LedgerEntry> {
9
9
  put(entry: E): Promise<void>;
10
+ /** entry put only while none is kept under its id, in one statement: whether it was put. */
11
+ claim(entry: E): Promise<boolean>;
10
12
  get(id: string): Promise<E | undefined>;
11
13
  list(): Promise<E[]>;
12
14
  remove(id: string): Promise<void>;
15
+ /** entry put in place of `was` only while the kept entry is still `was` as read, in one statement: whether it was put. */
16
+ swap(was: E, entry: E): Promise<boolean>;
13
17
  }
14
18
  /** `provider`'s ledger over the store's computer ledger. */
15
19
  export declare function storeLedger<E extends LedgerEntry = LedgerEntry>(ledger: ComputerLedger, provider: string): ProviderLedger<E>;
@@ -6,11 +6,22 @@ export function storeLedger(ledger, provider) {
6
6
  const { id, labels, ...detail } = entry;
7
7
  await ledger.put(provider, id, labels, detail);
8
8
  },
9
+ claim: (entry) => {
10
+ const { id, labels, ...detail } = entry;
11
+ return ledger.claim(provider, id, labels, detail);
12
+ },
9
13
  get: async (id) => {
10
14
  const row = await ledger.get(provider, id);
11
15
  return row === undefined ? undefined : entryOf(row);
12
16
  },
13
17
  list: async () => (await ledger.list(provider)).map((row) => entryOf(row)),
14
18
  remove: (id) => ledger.remove(provider, id),
19
+ swap: async (was, entry) => {
20
+ const { id: _wasId, labels: wasLabels, ...wasDetail } = was;
21
+ const { id, labels, ...detail } = entry;
22
+ if (was.id !== id)
23
+ return false;
24
+ return ledger.swap(provider, id, { labels: wasLabels, detail: wasDetail }, labels, detail);
25
+ },
15
26
  };
16
27
  }
@@ -0,0 +1,25 @@
1
+ import type { HostTool } from "@parcha/agentrun-kernel";
2
+ /** The MCP server's name and version, as a client's initialize reads them. */
3
+ export declare const COMPUTER_MCP_NAME = "agentrun-computer";
4
+ type Block = {
5
+ type: "text";
6
+ text: string;
7
+ } | {
8
+ type: "image";
9
+ data: string;
10
+ mimeType: string;
11
+ };
12
+ /** One tool's answer as MCP's CallToolResult. */
13
+ export type ComputerMcpAnswer = {
14
+ content: Block[];
15
+ isError?: true;
16
+ structuredContent?: unknown;
17
+ };
18
+ /** `tool`'s answer to `args` as an MCP client reads it: the same call a harness's session makes. */
19
+ export declare function mcpAnswerOf(tool: HostTool, args: unknown, signal: AbortSignal, callId: string): Promise<ComputerMcpAnswer>;
20
+ /** The MCP handler over `tools` (a claim's computer tools, bound to its run): `fetch` answers one Streamable HTTP
21
+ * request (POST of JSON-RPC; GET and DELETE as the SDK answers them statelessly). */
22
+ export declare function computerMcp(tools: readonly HostTool[]): {
23
+ fetch(request: Request): Promise<Response>;
24
+ };
25
+ export {};
@@ -0,0 +1,41 @@
1
+ // A claim's computer as an MCP server: the computer's tools (computer_observe, computer_act, computer_screenshot,
2
+ // computer_script, the hand-over, as its groups offer them) for a harness that speaks MCP and nothing of ours. The tools
3
+ // are the run's own bound ones (run-tools.ts RunTools.hostTools over its kindTools): the kernel registry's definitions,
4
+ // words and executors, on the run's held port, so an answer here is byte for byte the per-step tool's and the script's.
5
+ // Each answer is the tool's text, then its images as image blocks, and, when it did not fail, its value as
6
+ // structuredContent (the SDK wraps a value that is not an object as the client's protocol needs).
7
+ //
8
+ // Stateless Streamable HTTP through the official SDK: one McpServer per request (createMcpHandler), so nothing of one
9
+ // request is kept for the next. The route that serves it decides who may call it (the claim's own token) and goes
10
+ // through the run's gate before it hands a request here: this module checks nothing.
11
+ import { createMcpHandler, fromJsonSchema, McpServer } from "@modelcontextprotocol/server";
12
+ /** The MCP server's name and version, as a client's initialize reads them. */
13
+ export const COMPUTER_MCP_NAME = "agentrun-computer";
14
+ const VERSION = "1.0.0";
15
+ /** `tool`'s answer to `args` as an MCP client reads it: the same call a harness's session makes. */
16
+ export async function mcpAnswerOf(tool, args, signal, callId) {
17
+ let given;
18
+ try {
19
+ given = await tool.call(args ?? {}, { callId, signal });
20
+ }
21
+ catch (error) {
22
+ return { content: [{ type: "text", text: error?.message ?? String(error) }], isError: true };
23
+ }
24
+ const content = [{ type: "text", text: given.text }, ...(given.images ?? []).map((image) => ({ type: "image", data: image.data, mimeType: image.mimeType }))];
25
+ if (given.isError)
26
+ return { content, isError: true };
27
+ return { content, ...(given.structured !== undefined ? { structuredContent: given.structured } : {}) };
28
+ }
29
+ /** The MCP handler over `tools` (a claim's computer tools, bound to its run): `fetch` answers one Streamable HTTP
30
+ * request (POST of JSON-RPC; GET and DELETE as the SDK answers them statelessly). */
31
+ export function computerMcp(tools) {
32
+ let calls = 0;
33
+ const handler = createMcpHandler(() => {
34
+ const server = new McpServer({ name: COMPUTER_MCP_NAME, version: VERSION });
35
+ for (const tool of tools) {
36
+ server.registerTool(tool.name, { description: tool.description, inputSchema: fromJsonSchema(tool.inputSchema) }, (args, ctx) => mcpAnswerOf(tool, args, ctx.mcpReq.signal, `mcp-${tool.name}-${++calls}`));
37
+ }
38
+ return server;
39
+ });
40
+ return { fetch: (request) => handler.fetch(request) };
41
+ }
@@ -1,13 +1,4 @@
1
- import type { ComputerClient } from "@parcha/agentrun-computer";
2
- import type { Input, Phone, Screen } from "@parcha/agentrun-kernel/kernel";
3
- /** A desktop's screen: screen.shot, the whole screen or a region of it in the whole screen's pixels. */
4
- export declare const screenOf: (client: ComputerClient) => Screen;
5
- /** A desktop's input: input.actions, the batch as the kernel's port gives it (computerd's own actions). */
6
- export declare const inputOf: (client: ComputerClient) => Input;
7
- /** A phone: its screen's shot and structure (apps.ui_tree), a tap, a swipe, typing and its keys as input.actions, its apps.
8
- * `offers`: whether the phone declares its structure (apps.ui_tree) and its keys (input.keys); one it does not declare
9
- * is no method of the port (an iPhone offers neither until a live run proves them). Default both. */
10
- export declare const phoneOf: (client: ComputerClient, offers?: {
11
- readonly tree?: boolean;
12
- readonly keys?: boolean;
13
- }) => Phone;
1
+ import type { Surface } from "@parcha/agentrun-computer/surface";
2
+ import type { ComputerPort } from "@parcha/agentrun-kernel/kernel";
3
+ /** The port of a computer's surface. */
4
+ export declare const portOf: (surface: Surface) => ComputerPort;
@@ -1,108 +1,5 @@
1
- /** A computer call's value, or its refusal thrown with the computer's code and words. */
2
- async function valueOf(call) {
3
- const result = await call;
4
- if (result.ok)
5
- return result.value;
6
- throw Object.assign(new Error(result.error.message), { code: result.error.code });
7
- }
8
- /** The screen's shot: its first piece, then screen.read from where it ends until the end. */
9
- async function shotOf(client, region) {
10
- const first = await valueOf(client.call("screen.shot", region ? { region: [...region] } : {}));
11
- const pieces = [Buffer.from(first.data, "base64")];
12
- let offset = pieces[0].length;
13
- for (let eof = first.eof; !eof;) {
14
- const next = await valueOf(client.call("screen.read", { id: first.id, offset }));
15
- const piece = Buffer.from(next.data, "base64");
16
- if (piece.length === 0 && !next.eof)
17
- throw Object.assign(new Error(`the computer's screenshot stopped at byte ${offset} of ${first.size}`), { code: "invalid" });
18
- pieces.push(piece);
19
- offset += piece.length;
20
- eof = next.eof;
21
- }
22
- return { png: Buffer.concat(pieces), width: first.width, height: first.height };
23
- }
24
- /** input.actions: a batch that failed partway throws the computer's code and words, and how many ran. */
25
- async function act(client, actions) {
26
- const ran = await valueOf(client.call("input.actions", { actions: [...actions] }));
27
- if (!ran.failed)
28
- return;
29
- const words = ran.done > 0 ? `${ran.failed.message} (${ran.done} of ${actions.length} actions ran)` : ran.failed.message;
30
- throw Object.assign(new Error(words), { code: ran.failed.kind });
31
- }
32
- /** A desktop's screen: screen.shot, the whole screen or a region of it in the whole screen's pixels. */
33
- export const screenOf = (client) => ({
34
- shot: (options) => shotOf(client, options?.region ? [options.region.x, options.region.y, options.region.w, options.region.h] : undefined),
35
- });
36
- /** A desktop's input: input.actions, the batch as the kernel's port gives it (computerd's own actions). */
37
- export const inputOf = (client) => ({
38
- actions: (list) => act(client, list),
39
- });
40
- /** A node's platform class a model types into: Android's EditText (and its subclasses), iOS's text fields and views. */
41
- const EDITABLE = /(?:EditText|AutoCompleteTextView)$|^XCUIElementType(?:Secure)?Text(?:Field|View)$|^XCUIElementTypeSearchField$/;
42
- /** The first text among `node`'s descendants, in document order, else their first label: the name of a node that has
43
- * none of its own (an Android list row: a clickable layout whose title sits on a child TextView). */
44
- function innerName(node) {
45
- let label;
46
- const stack = [...(node.children ?? [])].reverse();
47
- while (stack.length) {
48
- const next = stack.pop();
49
- if (next.text)
50
- return next.text;
51
- label ??= next.label || undefined;
52
- for (const child of [...(next.children ?? [])].reverse())
53
- stack.push(child);
54
- }
55
- return label;
56
- }
57
- /** The screen's structure (apps.ui_tree), flattened in document order, each node with whether a model can tap it or type
58
- * into it; a node the phone says is not enabled is neither. A clickable node with no text or label of its own is named
59
- * by its first inner text (else label), as phone_tree shows it, marked so. */
60
- function flattened(root) {
61
- const out = [];
62
- const walk = (node) => {
63
- const [x, y, w, h] = node.bounds;
64
- const editable = node.enabled && EDITABLE.test(node.role);
65
- const clickable = node.enabled && node.clickable === true;
66
- const inner = clickable && !node.text && !node.label ? innerName(node) : undefined;
67
- out.push({
68
- role: node.role,
69
- ...(node.id ? { id: node.id } : {}),
70
- ...(node.text ? { text: node.text } : {}),
71
- ...(node.label ? { label: node.label } : {}),
72
- bounds: { x, y, w, h },
73
- clickable,
74
- editable,
75
- ...(node.focused ? { focused: true } : {}),
76
- ...(inner ? { inner } : {}),
77
- });
78
- for (const child of node.children ?? [])
79
- walk(child);
80
- };
81
- walk(root);
82
- return out;
83
- }
84
- /** The keys a phone presses: back and home are its buttons (input.touch's button action), enter a key of the key table. */
85
- const keyAction = (name) => (name === "enter" ? { type: "key", keys: ["enter"] } : { type: "button", name });
86
- /** A phone: its screen's shot and structure (apps.ui_tree), a tap, a swipe, typing and its keys as input.actions, its apps.
87
- * `offers`: whether the phone declares its structure (apps.ui_tree) and its keys (input.keys); one it does not declare
88
- * is no method of the port (an iPhone offers neither until a live run proves them). Default both. */
89
- export const phoneOf = (client, offers = {}) => ({
90
- shot: () => shotOf(client),
91
- ...(offers.tree !== false ? {
92
- async tree() {
93
- const tree = await valueOf(client.call("apps.ui_tree", {}));
94
- return { nodes: flattened(tree.root), total: tree.nodes, truncated: tree.truncated };
95
- },
96
- } : {}),
97
- tap: (at) => act(client, [{ type: "tap", at: [at.x, at.y] }]),
98
- swipe: ({ from, to, durationMs }) => act(client, [{ type: "swipe", path: [[from.x, from.y], [to.x, to.y]], ms: durationMs }]),
99
- type: (text) => act(client, [{ type: "type", text }]),
100
- ...(offers.keys !== false ? { key: (name) => act(client, [keyAction(name)]) } : {}),
101
- apps: {
102
- async list() {
103
- const listed = await valueOf(client.call("apps.list", {}));
104
- return { apps: listed.apps.map((app) => (app.name === undefined ? { id: app.id } : { id: app.id, name: app.name })), foreground: listed.foreground };
105
- },
106
- open: async (id) => void (await valueOf(client.call("apps.launch", { id }))),
107
- },
1
+ /** The port of a computer's surface. */
2
+ export const portOf = (surface) => ({
3
+ groups: surface.card.groups,
4
+ call: (op, args, signal) => surface.call(op, args, signal ? { signal } : {}),
108
5
  });
@@ -0,0 +1,37 @@
1
+ import { type Card } from "@parcha/agentrun-computer/surface";
2
+ import type { Executor } from "@parcha/agentrun-kernel/kernel";
3
+ /** A script's longest run by default, and at most, in ms. */
4
+ export declare const SCRIPT_DEFAULT_MS = 120000;
5
+ export declare const SCRIPT_MAX_MS = 600000;
6
+ /** The run's tool gate's decision of one call, as a script's computer call is held to it (RunPermissions.decide). */
7
+ export type ScriptDecide = (tool: string, args: unknown) => Promise<"allow" | "ask" | {
8
+ deny: string;
9
+ }>;
10
+ /** What a script's `computer.shell` and `computer.files` are held to: the run's gate, which a person's settings (a denied
11
+ * bash, a read-only bash policy, a denied write) reach through the one decision the run's own tools get. A script can't
12
+ * stop to ask, so a call the gate would ask about is refused in words that send the model to the tool itself. Until a
13
+ * gate is installed (the spec installs it once built) every one of those calls is refused. */
14
+ export declare class ScriptGuard {
15
+ #private;
16
+ private readonly shell;
17
+ /** `shell`: what the run's bash adds under its bash policy (bash-read-only.ts policyEnv, policyPrelude): the environment
18
+ * that locks git's config down, set over any a script gives, and the line that runs git only at the floor version. */
19
+ constructor(shell?: {
20
+ readonly env: Readonly<Record<string, string>>;
21
+ readonly prelude: string;
22
+ });
23
+ /** `op`'s arguments as the computer is sent them: a script's shell command with the policy's safeguards, as the bash
24
+ * tool's own command has them, which no option of the script's overrides. */
25
+ shaped(op: string, args: unknown): unknown;
26
+ install(decide: ScriptDecide): void;
27
+ /** Why `op` with `args` may not run now, or undefined when the gate lets it. */
28
+ refusal(op: string, args: unknown): Promise<string | undefined>;
29
+ /** `call` of the computer's port with a script's computer call held to the gate first: the refusal throws in the
30
+ * script, where its `await` is. */
31
+ call(op: string, args: unknown, send: (args: unknown) => Promise<{
32
+ value?: unknown;
33
+ }>): Promise<unknown>;
34
+ }
35
+ /** computer_script's executor for a computer that is `card`: each script in its own isolate, its computer calls through
36
+ * the call's hands, the shell's and the files' held to `guard`. */
37
+ export declare function computerScriptExecutor(card: Card, guard: ScriptGuard): Executor;
@@ -0,0 +1,138 @@
1
+ // computer_script's run: the model's JavaScript in a QuickJS isolate here in serve (pi-codemode's CodemodeSandbox, a
2
+ // worker thread per script), whose only binding is the claim's computer. The script sees `computer` (the surface's
3
+ // script prelude builds it inside the isolate over one host function, __computerCall) and pi-codemode's output helpers
4
+ // (text, image, console); no network, no keys, no timers, no modules, no file of this machine. Each call of the computer
5
+ // goes through the run's hands (Hands.computer), so a person's hold parks and refuses it as it does a per-step tool's.
6
+ //
7
+ // The answer: the script's text and images in the order it made them, then its returned value as JSON (its images'
8
+ // data left out: they are the answer's images); `structured` is the value. A script that threw answers its words, with
9
+ // what it showed before.
10
+ import { CodemodeSandbox } from "@earendil-works/pi-codemode";
11
+ import { COMPUTER_CALL_GLOBAL, scriptPrelude, withoutImageData } from "@parcha/agentrun-computer/surface";
12
+ /** A script's longest run by default, and at most, in ms. */
13
+ export const SCRIPT_DEFAULT_MS = 120_000;
14
+ export const SCRIPT_MAX_MS = 600_000;
15
+ /** The isolate's memory. */
16
+ const SCRIPT_MEMORY_BYTES = 256 * 1024 * 1024;
17
+ /** The settings key a script's computer call is held to, as the run's own tool of that name is: the shell is bash's, a
18
+ * file's write is write's, a file's read, listing or stat is read's. The other ops (looking, acting) are the computer
19
+ * kind's, which the call of computer_script or codemode was already held to. */
20
+ const HELD_AS = Object.freeze({ "shell.run": "bash", "files.write": "write", "files.read": "read", "files.list": "read", "files.stat": "read" });
21
+ /** What a script's `computer.shell` and `computer.files` are held to: the run's gate, which a person's settings (a denied
22
+ * bash, a read-only bash policy, a denied write) reach through the one decision the run's own tools get. A script can't
23
+ * stop to ask, so a call the gate would ask about is refused in words that send the model to the tool itself. Until a
24
+ * gate is installed (the spec installs it once built) every one of those calls is refused. */
25
+ export class ScriptGuard {
26
+ shell;
27
+ #decide;
28
+ /** `shell`: what the run's bash adds under its bash policy (bash-read-only.ts policyEnv, policyPrelude): the environment
29
+ * that locks git's config down, set over any a script gives, and the line that runs git only at the floor version. */
30
+ constructor(shell = { env: {}, prelude: "" }) {
31
+ this.shell = shell;
32
+ }
33
+ /** `op`'s arguments as the computer is sent them: a script's shell command with the policy's safeguards, as the bash
34
+ * tool's own command has them, which no option of the script's overrides. */
35
+ shaped(op, args) {
36
+ if (op !== "shell.run")
37
+ return args;
38
+ const given = (args ?? {});
39
+ const env = { ...(given.env ?? {}), ...this.shell.env };
40
+ return { ...given, ...(Object.keys(env).length > 0 ? { env } : {}), ...(this.shell.prelude !== "" && typeof given.command === "string" ? { command: `${this.shell.prelude}${given.command}` } : {}) };
41
+ }
42
+ install(decide) {
43
+ this.#decide = decide;
44
+ }
45
+ /** Why `op` with `args` may not run now, or undefined when the gate lets it. */
46
+ async refusal(op, args) {
47
+ const tool = HELD_AS[op];
48
+ if (tool === undefined)
49
+ return undefined;
50
+ if (!this.#decide)
51
+ return `computer call ${op} was not run: this run's tool settings are not attached to its scripts yet`;
52
+ const given = (args ?? {});
53
+ const decision = await this.#decide(tool, tool === "bash" ? { command: given.command, ...(given.cwd !== undefined ? { cwd: given.cwd } : {}) } : { path: given.path });
54
+ if (decision === "allow")
55
+ return undefined;
56
+ if (decision === "ask")
57
+ return `computer call ${op} was not run: this agent's ${tool} setting asks a person first, and a script can't wait for one. Call the ${tool} tool itself, or ask for the setting to be allow.`;
58
+ return `computer call ${op} was not run: ${decision.deny}`;
59
+ }
60
+ /** `call` of the computer's port with a script's computer call held to the gate first: the refusal throws in the
61
+ * script, where its `await` is. */
62
+ async call(op, args, send) {
63
+ const refused = await this.refusal(op, args);
64
+ if (refused !== undefined)
65
+ throw new Error(refused);
66
+ return (await send(this.shaped(op, args ?? {}))).value ?? null;
67
+ }
68
+ }
69
+ /** Every image in `value` (`{ type: "image", data }`), in the order withImageData puts data back into them. */
70
+ function imagesIn(value) {
71
+ if (Array.isArray(value))
72
+ return value.flatMap(imagesIn);
73
+ if (value === null || typeof value !== "object")
74
+ return [];
75
+ const record = value;
76
+ if (record.type === "image" && typeof record.data === "string")
77
+ return [{ data: record.data, mimeType: typeof record.mimeType === "string" ? record.mimeType : "image/png" }];
78
+ return Object.values(record).flatMap(imagesIn);
79
+ }
80
+ /** The script's own output and its value, as the model reads them. The images come as the structured value wants them
81
+ * back (withImageData fills its data-less image objects in order): the returned value's own first, then the ones the
82
+ * script showed with image(...), so a returned image keeps its own pixels whatever was shown. */
83
+ function answerOf(output, value) {
84
+ const words = [];
85
+ const shown = [];
86
+ for (const item of output) {
87
+ if (item.type === "text")
88
+ words.push(item.text);
89
+ else
90
+ shown.push({ data: item.data, mimeType: item.mimeType });
91
+ }
92
+ if (value !== undefined)
93
+ words.push(typeof value === "string" ? value : JSON.stringify(withoutImageData(value)));
94
+ return { text: words.join("\n") || "(the script returned nothing and showed nothing)", images: [...imagesIn(value), ...shown] };
95
+ }
96
+ /** computer_script's executor for a computer that is `card`: each script in its own isolate, its computer calls through
97
+ * the call's hands, the shell's and the files' held to `guard`. */
98
+ export function computerScriptExecutor(card, guard) {
99
+ const prelude = scriptPrelude(card);
100
+ return async (args, call) => {
101
+ const { code, timeoutMs } = (args ?? {});
102
+ if (typeof code !== "string" || code.trim() === "")
103
+ return { text: "", error: "computer_script needs code: the body of an async function, with `computer` bound" };
104
+ const port = call.hands.computer;
105
+ if (!port)
106
+ return { text: "", error: "computer_script needs a desktop or a phone computer: this run has none" };
107
+ const limit = typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0 ? Math.min(timeoutMs, SCRIPT_MAX_MS) : SCRIPT_DEFAULT_MS;
108
+ const sandbox = new CodemodeSandbox({
109
+ timeoutMs: limit,
110
+ memoryLimitBytes: SCRIPT_MEMORY_BYTES,
111
+ globals: [{
112
+ name: COMPUTER_CALL_GLOBAL,
113
+ spread: true,
114
+ // The value whole, images and all: a script shows one with image(...). The JSON round trip is the isolate's.
115
+ execute: async (given, context) => {
116
+ const [op, opArgs] = given;
117
+ return (await guard.call(String(op), opArgs, (sent) => port.call(String(op), sent ?? {}, AbortSignal.any([context.signal, ...(call.signal ? [call.signal] : [])]))));
118
+ },
119
+ }],
120
+ });
121
+ try {
122
+ // The prelude is one line, so the script's own line numbers hold.
123
+ const result = await sandbox.execute(`${prelude}\n${code}`, call.signal ? { signal: call.signal } : {});
124
+ if (!result.ok) {
125
+ if (result.error.kind === "aborted" && call.signal?.aborted)
126
+ throw call.signal.reason ?? new Error(result.error.message);
127
+ const shown = answerOf(result.output, undefined);
128
+ const why = result.error.kind === "timeout" ? `the script ran past its ${limit} ms: ${result.error.message}` : result.error.message;
129
+ return { text: result.output.length > 0 ? shown.text : "", error: why, ...(shown.images.length > 0 ? { images: shown.images } : {}) };
130
+ }
131
+ const shown = answerOf(result.output, result.value);
132
+ return { text: shown.text, ...(shown.images.length > 0 ? { images: shown.images } : {}), ...(result.value === undefined ? {} : { structured: withoutImageData(result.value) }) };
133
+ }
134
+ finally {
135
+ await sandbox.close();
136
+ }
137
+ };
138
+ }
@@ -1,4 +1,4 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import type { ToolRegistration } from "@earendil-works/pi-durable";
3
3
  import type { ExecutionEnv } from "@earendil-works/pi-durable/env";
4
4
  import type { ToolAnswer, ToolCall } from "@parcha/agentrun-kernel/kernel";
@@ -13,12 +13,15 @@ export { readOnlyWorkspace, SERVER_READS_ONLY, serverRunWorkspace, type ServerRu
13
13
  export { type LedgerEntry, type ProviderLedger, storeLedger } from "./computer-ledger.js";
14
14
  export { type LearningPlace, type LearningWorkspace, learningWorkspace, type LearningWorkspaceOptions } from "./learning-workspace.js";
15
15
  export { ARCHIL_MAX_EXEC_S, handsOf, MAX_EXEC_S, processesOf, shellEnv } from "./hands.js";
16
- export { type RunComputer, type RunHold, runTools, type RunTools, withKindTools } from "./run-tools.js";
17
- export { inputOf, phoneOf, screenOf } from "./computer-ports.js";
18
- export { type ClaimSide, computerReadiness, type ComputerSetting, type KindRegistry, type LaunchedComputer, type Port, resolveComputer, type ResolvedComputer, runShellOf, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
16
+ export { type RunComputer, type RunHold, runTools, type RunTools, type ScriptComputer, withKindTools } from "./run-tools.js";
17
+ export { portOf } from "./computer-ports.js";
18
+ export { computerScriptExecutor, SCRIPT_DEFAULT_MS, SCRIPT_MAX_MS, ScriptGuard, type ScriptDecide } from "./computer-script.js";
19
+ export { COMPUTER_MCP_NAME, computerMcp, type ComputerMcpAnswer, mcpAnswerOf } from "./computer-mcp.js";
20
+ export { type ClaimSide, computerReadiness, type ComputerSetting, type KindRegistry, type LaunchedComputer, type Port, resolveComputer, type ResolvedComputer, runShellOf, type ShellPlace, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
19
21
  export { computerProviderFactories, computerProviderMakers, type ProviderLoad } from "./computer-providers.js";
20
22
  export { claimComputer, claimKinds, type ComputerDeps, computerDepsFrom, type ComputerDepsOptions, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, type DockerComputerOptions, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
21
- export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ImageWait, type OpenComputerView, type ProviderMakers, type ViewEnd } from "./computer-for-claim.js";
23
+ export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ComputerSaid, type ImageWait, type OpenComputerView, type ProviderMakers, type ViewEnd } from "./computer-for-claim.js";
22
24
  export { JANITOR_EVERY_MS, type JanitorDeps, type ProviderSweep, startJanitor, sweepServerComputers } from "./computer-janitor.js";
25
+ export { agentComputerOf, agentComputerView, ownerGoneOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
23
26
  export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
24
27
  export { KIND_SKILLS, type KindSkill, kindSkillOf, type SkillKind } from "./kind-skills.js";
@@ -15,11 +15,14 @@ export { storeLedger } from "./computer-ledger.js";
15
15
  export { learningWorkspace } from "./learning-workspace.js";
16
16
  export { ARCHIL_MAX_EXEC_S, handsOf, MAX_EXEC_S, processesOf, shellEnv } from "./hands.js";
17
17
  export { runTools, withKindTools } from "./run-tools.js";
18
- export { inputOf, phoneOf, screenOf } from "./computer-ports.js";
18
+ export { portOf } from "./computer-ports.js";
19
+ export { computerScriptExecutor, SCRIPT_DEFAULT_MS, SCRIPT_MAX_MS, ScriptGuard } from "./computer-script.js";
20
+ export { COMPUTER_MCP_NAME, computerMcp, mcpAnswerOf } from "./computer-mcp.js";
19
21
  export { computerReadiness, resolveComputer, runShellOf, shellPlaceOf, } from "./resolve-computer.js";
20
22
  export { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
21
23
  export { claimComputer, claimKinds, computerDepsFrom, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
22
24
  export { computerForClaim } from "./computer-for-claim.js";
23
25
  export { JANITOR_EVERY_MS, startJanitor, sweepServerComputers } from "./computer-janitor.js";
26
+ export { agentComputerOf, agentComputerView, ownerGoneOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
24
27
  export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
25
28
  export { KIND_SKILLS, kindSkillOf } from "./kind-skills.js";