@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
@@ -40,12 +40,15 @@ export declare const CODEX_STANDIN_ENV = "AGENTRUN_SERVE_CODEX_STANDIN";
40
40
  /** For tests: a JSON `{command, args?, env?}` that speaks `opencode serve`'s HTTP API in place of OpenCode. The OpenCode
41
41
  * adapter (src/harness-opencode) takes it only under its own guard (AGENTRUN_OPENCODE_STANDIN=1, under a test runner). */
42
42
  export declare const OPENCODE_STANDIN_ENV = "AGENTRUN_SERVE_OPENCODE_STANDIN";
43
+ /** Whether a test's stand-in runs in place of harness `id`'s own CLI in `env` (CODEX_STANDIN_ENV, OPENCODE_STANDIN_ENV):
44
+ * its adapter then loads nothing installed, so a run of it needs no first-use install. */
45
+ export declare const standsIn: (id: string, env: NodeJS.ProcessEnv) => boolean;
43
46
  /** The event of a harness's own lines in the run's log (its model proxy's refusals and failures): a failed run's message
44
47
  * is never taken from one (runs.ts lastLogLine). */
45
48
  export declare const HARNESS_LOG_EVENT = "harness";
46
49
  /**
47
50
  * A harness's log, into the run's log: the run process's stderr, which serve opens on the run's process.log. One JSON
48
- * line per call, as pi-durable-disk writes them (`{at, event, message, ...}`). A request's path loses its query string,
51
+ * line per call (`{at, event, message, ...}`). A request's path loses its query string,
49
52
  * and every value of the environment's key-shaped variables is cut out of the line, so a key a client sent in either
50
53
  * place, or one serve holds, never reaches the log.
51
54
  */
@@ -59,7 +62,7 @@ type ModelCost = {
59
62
  cacheRead: number;
60
63
  cacheWrite: number;
61
64
  };
62
- /** A child's command under the run's confinement (pi-durable-disk's confinePrefix): only added in front. */
65
+ /** A child's command under the run's confinement (noNewPrivsPrefix): only added in front. */
63
66
  export type ConfineChild = (child: Readonly<{
64
67
  command: string;
65
68
  args: string[];
@@ -84,6 +87,13 @@ export type AdapterNeeds = {
84
87
  /** The ConfineChild that starts a child under `prefix` (the argv pi's commands start under, ending in "--"); none when
85
88
  * the run confines nothing (macOS), since an adapter refuses a confinement that adds nothing. */
86
89
  export declare function confineOf(prefix: readonly string[]): ConfineChild | undefined;
90
+ /** The argv a CLI run's process starts under for no_new_privs: `setpriv --no-new-privs --` on Linux, nothing on macOS
91
+ * (which has no no_new_privs). Where setpriv is not usable it throws (code `SETPRIV_UNAVAILABLE`), so the run is refused,
92
+ * never started unconfined. */
93
+ export declare function noNewPrivsPrefix(options?: {
94
+ noNewPrivs?: boolean;
95
+ setprivPath?: string;
96
+ }): string[];
87
97
  /** The model key a run on `harness` (one on an adapter, by its wire's route) of `model` (the revision's; none, the host's default for the
88
98
  * harness) takes: the one its requests carry on the route its provider below takes, as key-refusal.ts' runKeyOf names
89
99
  * it. codex: the gateway's when AGENT_MODEL_BASE_URL is set, else OpenAI's, or OpenRouter's on OpenRouter's route;
package/dist/adapters.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // Claude Agent SDK and codex's Codex are installed on first use into the data's harnesses directory and loaded from there
5
5
  // alone (harness-install.ts); opencode's pinned CLI that is missing says so with the one line that installs it: an npm
6
6
  // install beside serve, or, when serve runs from npx, the npx line that runs it with the missing package.
7
- import { existsSync, readFileSync } from "node:fs";
7
+ import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
8
8
  import { dirname, join, resolve, sep } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
@@ -97,12 +97,15 @@ export const CODEX_STANDIN_ENV = "AGENTRUN_SERVE_CODEX_STANDIN";
97
97
  /** For tests: a JSON `{command, args?, env?}` that speaks `opencode serve`'s HTTP API in place of OpenCode. The OpenCode
98
98
  * adapter (src/harness-opencode) takes it only under its own guard (AGENTRUN_OPENCODE_STANDIN=1, under a test runner). */
99
99
  export const OPENCODE_STANDIN_ENV = "AGENTRUN_SERVE_OPENCODE_STANDIN";
100
+ /** Whether a test's stand-in runs in place of harness `id`'s own CLI in `env` (CODEX_STANDIN_ENV, OPENCODE_STANDIN_ENV):
101
+ * its adapter then loads nothing installed, so a run of it needs no first-use install. */
102
+ export const standsIn = (id, env) => (id === codexFacts.id && Boolean(env[CODEX_STANDIN_ENV])) || (id === openCodeFacts.id && Boolean(env[OPENCODE_STANDIN_ENV]));
100
103
  /** The event of a harness's own lines in the run's log (its model proxy's refusals and failures): a failed run's message
101
104
  * is never taken from one (runs.ts lastLogLine). */
102
105
  export const HARNESS_LOG_EVENT = "harness";
103
106
  /**
104
107
  * A harness's log, into the run's log: the run process's stderr, which serve opens on the run's process.log. One JSON
105
- * line per call, as pi-durable-disk writes them (`{at, event, message, ...}`). A request's path loses its query string,
108
+ * line per call (`{at, event, message, ...}`). A request's path loses its query string,
106
109
  * and every value of the environment's key-shaped variables is cut out of the line, so a key a client sent in either
107
110
  * place, or one serve holds, never reaches the log.
108
111
  */
@@ -166,6 +169,28 @@ export function confineOf(prefix) {
166
169
  return undefined;
167
170
  return (child) => ({ command: prefix[0], args: [...prefix.slice(1), child.command, ...child.args] });
168
171
  }
172
+ /** The util-linux `setpriv` a CLI run's process starts under. */
173
+ const SETPRIV = "/usr/bin/setpriv";
174
+ /** The argv a CLI run's process starts under for no_new_privs: `setpriv --no-new-privs --` on Linux, nothing on macOS
175
+ * (which has no no_new_privs). Where setpriv is not usable it throws (code `SETPRIV_UNAVAILABLE`), so the run is refused,
176
+ * never started unconfined. */
177
+ export function noNewPrivsPrefix(options = {}) {
178
+ const noNewPrivs = options.noNewPrivs ?? process.platform !== "darwin";
179
+ if (!noNewPrivs)
180
+ return [];
181
+ const path = options.setprivPath ?? SETPRIV;
182
+ try {
183
+ if (!statSync(path).isFile())
184
+ throw new Error("not a file");
185
+ accessSync(path, constants.X_OK);
186
+ }
187
+ catch (cause) {
188
+ const reason = cause instanceof Error ? cause.message : String(cause);
189
+ throw Object.assign(new Error(`commands run under no_new_privs (and as runAs) through setpriv (util-linux), which is not usable at ${path}: ${reason}. ` +
190
+ "Install util-linux, point setprivPath at it, or pass noNewPrivs: false on a host that already confines commands.", { cause }), { code: "SETPRIV_UNAVAILABLE" });
191
+ }
192
+ return [path, "--no-new-privs", "--"];
193
+ }
169
194
  /** The model key a run on `harness` (one on an adapter, by its wire's route) of `model` (the revision's; none, the host's default for the
170
195
  * harness) takes: the one its requests carry on the route its provider below takes, as key-refusal.ts' runKeyOf names
171
196
  * it. codex: the gateway's when AGENT_MODEL_BASE_URL is set, else OpenAI's, or OpenRouter's on OpenRouter's route;
@@ -36,13 +36,14 @@ export type AgenticBody = {
36
36
  harness?: string;
37
37
  place?: RevisionPlace;
38
38
  computer?: RevisionComputer;
39
- learning?: boolean;
39
+ learning?: boolean | "notes";
40
40
  toolSettings?: Record<string, Record<string, string>>;
41
41
  approvals?: "never";
42
42
  maxCostUsd?: number;
43
43
  capMode?: string;
44
44
  outputSchema?: Record<string, unknown>;
45
45
  maxToolCalls?: number;
46
+ checkout?: "pull_request";
46
47
  };
47
48
  export type WorkflowBody = {
48
49
  workflow: Workflow;
@@ -103,6 +103,7 @@ export declare function agentView(entry: AgentEntry, origin: string, extra?: {
103
103
  count: number;
104
104
  live: number;
105
105
  };
106
+ ownComputer?: Record<string, unknown> | null;
106
107
  }): {
107
108
  created_at: string;
108
109
  updated_at: string;
@@ -124,6 +125,7 @@ export declare function agentView(entry: AgentEntry, origin: string, extra?: {
124
125
  count: number;
125
126
  live: number;
126
127
  };
128
+ own_computer: Record<string, unknown> | null;
127
129
  region: string;
128
130
  home_etag: string;
129
131
  archived_at: string | null;
@@ -1,5 +1,4 @@
1
- // The agents this server holds, over the one store (store.agents); pi-durable-agent's agent-store.ts bodyOf and revisionOf
2
- // are folded into store/agent-body.ts. An agent is a
1
+ // The agents this server holds, over the one store (store.agents); the body check is store/agent-body.ts. An agent is a
3
2
  // row with revisions written once; a definition is one revision; an edit commits the next and makes it current. A
4
3
  // revision's body is checked by store/agent-body.ts before anything is written; its skill texts ride on the revision's row.
5
4
  // The one server per store (the owner lock) is the sole writer of agents and revisions, so a read-then-write here is not
@@ -106,14 +105,16 @@ function revisionInputOf(definition, files) {
106
105
  // permissionOf with the revision's approvals): a call node on a tool set to ask runs under never, as on main.
107
106
  if (isObject(definition.workflow))
108
107
  return { kind: "workflow", workflow: definition.workflow, ...(definition.approvals === "never" ? { approvals: "never" } : {}), ...common, ...capped };
109
- const learning = typeof definition.learning === "boolean" ? { learning: definition.learning } : {};
108
+ const learning = typeof definition.learning === "boolean" || definition.learning === "notes" ? { learning: definition.learning } : {};
110
109
  return {
111
110
  kind: "agentic",
112
111
  instructions: definition.instructions,
113
112
  ...(typeof definition.model === "string" ? { model: definition.model } : {}),
113
+ ...(isObject(definition.model_tiers) ? { modelTiers: definition.model_tiers } : {}),
114
114
  ...(typeof definition.thinking === "string" ? { thinking: definition.thinking } : {}),
115
115
  ...(definition.approvals === "ask" || definition.approvals === "never" ? { approvals: definition.approvals } : {}),
116
116
  ...(isObject(definition.output_schema) ? { outputSchema: definition.output_schema } : {}),
117
+ ...(definition.checkout === "pull_request" ? { checkout: "pull_request" } : {}),
117
118
  // The tool-call budget (tool-budget.ts): 0 keeps none.
118
119
  ...(typeof definition.max_tool_calls === "number" && definition.max_tool_calls > 0 ? { maxToolCalls: definition.max_tool_calls } : {}),
119
120
  ...common,
@@ -303,6 +304,8 @@ function editOn(entry, definition, skills, note) {
303
304
  ...(definition.cap_mode === undefined && currentBody.capMode !== undefined ? { cap_mode: currentBody.capMode } : {}),
304
305
  // The structured answer's schema is the agent's contract with its callers: an edit that leaves it out keeps it.
305
306
  ...(definition.output_schema === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.outputSchema !== undefined ? { output_schema: currentBody.outputSchema } : {}),
307
+ // So is the checkout its runs start in (none clears it).
308
+ ...(definition.checkout === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.checkout !== undefined ? { checkout: currentBody.checkout } : {}),
306
309
  }
307
310
  : {};
308
311
  return makeRevision({ ...definition, ...carried }, files, note);
@@ -346,7 +349,7 @@ export function definitionOf(agent, revision, version) {
346
349
  ...(body.capMode !== undefined ? { cap_mode: body.capMode } : {}),
347
350
  };
348
351
  const kindBody = revision.kind === "agentic"
349
- ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(body.learning !== undefined ? { learning: body.learning } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.maxToolCalls !== undefined ? { max_tool_calls: body.maxToolCalls } : {}), ...common }
352
+ ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.modelTiers ? { model_tiers: body.modelTiers } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(body.learning !== undefined ? { learning: body.learning } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.maxToolCalls !== undefined ? { max_tool_calls: body.maxToolCalls } : {}), ...(body.checkout !== undefined ? { checkout: body.checkout } : {}), ...common }
350
353
  : { workflow: body.workflow, ...common };
351
354
  return {
352
355
  id: agent.id,
@@ -384,6 +387,8 @@ export function agentView(entry, origin, extra = {}) {
384
387
  skills: Object.entries(body.skills ?? {}).map(([path, sha]) => ({ path, sha256: sha, size_bytes: entry.sizes.get(sha) ?? null })),
385
388
  sign_ins: extra.signIns ?? [],
386
389
  runs: extra.runs ?? { count: 0, live: 0 },
390
+ // Its own computer, kept between runs where its setting is persistent: the provider, the computer and its state.
391
+ own_computer: extra.ownComputer ?? null,
387
392
  region: "local",
388
393
  home_etag: etagOf(entry),
389
394
  archived_at: agent.archivedAt == null ? null : new Date(agent.archivedAt).toISOString(),
@@ -2,7 +2,8 @@ import type { Route } from "./server.js";
2
2
  /** The variable that turns the profile on. */
3
3
  export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
4
4
  /** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
5
- * stop, cancel and cap raise; its files and the uploads a launch names; capabilities, health and usage. */
5
+ * stop, cancel and cap raise; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
6
+ * agent layer of a run's disk, archil-routes.ts); capabilities, health and usage. */
6
7
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
7
8
  /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
8
9
  * words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */
package/dist/api-only.js CHANGED
@@ -1,9 +1,11 @@
1
1
  /** The variable that turns the profile on. */
2
2
  export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
3
3
  /** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
4
- * stop, cancel and cap raise; its files and the uploads a launch names; capabilities, health and usage. */
4
+ * stop, cancel and cap raise; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
5
+ * agent layer of a run's disk, archil-routes.ts); capabilities, health and usage. */
5
6
  export const API_ONLY_ROUTES = new Set([
6
7
  "createRun", "createInlineRun",
8
+ "getAgentArchil", "deleteAgentArchil",
7
9
  "getRun", "listRuns", "listAllRuns", "getTimeline",
8
10
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap",
9
11
  "listRunFiles", "readRunFile",
@@ -1,14 +1,14 @@
1
1
  import { type KeyEnv, type KeyMeta } from "./key-meta.js";
2
2
  import type { Store } from "./store/index.js";
3
- import { type ArchilDisk, type ArchilDiskOptions } from "./workspace/archil-disk.js";
4
3
  /** The routes, by their operation names. */
5
4
  export declare const ARCHIL_ROUTES: ReadonlySet<string>;
6
5
  /** The key names the Archil settings take, as the document names them. */
7
6
  export declare const ARCHIL_KEY_NAMES: readonly string[];
8
- /** The Archil settings as the owner reads them: the account key as `secret`, its SecretMeta, never a value. */
7
+ /** The Archil settings as the owner reads them, with `source` while on (the server's environment, or saved through the
8
+ * PUT, "console"): the account key as `secret`, its SecretMeta, never a value. */
9
9
  export type ArchilView = {
10
10
  on: boolean;
11
- diskId?: string;
11
+ source?: "env" | "console";
12
12
  region?: string;
13
13
  s3Url?: string;
14
14
  image?: string;
@@ -21,14 +21,38 @@ export type ArchilTest = {
21
21
  ok: false;
22
22
  why: string;
23
23
  };
24
+ /** An agent's disk as GET /v2/agents/{id}/archil answers it: the one agentrun made for it (diskNameOf:
25
+ * agentrun-<server id>-i-<agent id>), or none until its first run that uses it. */
26
+ export type AgentArchilView = {
27
+ on: boolean;
28
+ archil_disk: {
29
+ disk_id: string;
30
+ } | null;
31
+ };
32
+ /** The agent an agent's Archil route acts on, as the dispatch reads it: whether it is archived, whether its source
33
+ * manages it (an inline run's agent), and how many live runs, of any agent, are on a disk (liveRunsOnDisk). */
34
+ export type RemovingAgent = {
35
+ readonly id: string;
36
+ readonly archived: boolean;
37
+ readonly external: boolean;
38
+ readonly liveOn: (diskId: string) => Promise<number>;
39
+ };
40
+ /** How many live runs, of any agent, are on agent `agentId`'s disk `diskId`: a run whose launch names that disk (a run of
41
+ * another agent may name it in its archil_disk), or a run of the agent whose launch names none (its claim takes the
42
+ * agent's disk). A live run whose launch can't be read is counted: the disk is kept while a run might be on it. */
43
+ export declare function liveRunsOnDisk(runs: Pick<Store["runs"], "list" | "launch">, agentId: string, diskId: string): Promise<number>;
24
44
  export interface ArchilRoutesOptions {
25
45
  /** The server's one store: its settings and sealed keys. */
26
46
  readonly store: Pick<Store, "settings" | "sealedKeys">;
27
47
  /** The server's seal key: there is always one (seal-key.ts bootSealKey, at the start). */
28
48
  readonly sealKey: Buffer;
29
- /** Makes the disk for the test (default archilDisk): a test's fake. */
30
- readonly makeDisk?: (options: ArchilDiskOptions) => ArchilDisk;
31
- /** The server's environment: an ARCHIL_API_KEY variable overrides the saved key (source "env"). */
49
+ /** Another control plane than the region's, and its fetch: a test's fake. */
50
+ readonly control?: {
51
+ readonly baseUrl?: string;
52
+ readonly fetch?: typeof fetch;
53
+ };
54
+ /** The server's environment: an ARCHIL_API_KEY variable overrides the saved key, and ARCHIL_SETTINGS_ENV the saved
55
+ * settings (source "env"). */
32
56
  readonly env?: KeyEnv;
33
57
  }
34
58
  export declare function createArchilRoutes(options: ArchilRoutesOptions): {
@@ -36,10 +60,19 @@ export declare function createArchilRoutes(options: ArchilRoutesOptions): {
36
60
  save: (body: unknown) => Promise<ArchilView>;
37
61
  off: () => Promise<ArchilView>;
38
62
  test: (signal?: AbortSignal) => Promise<ArchilTest>;
63
+ agentView: (agentId: string) => Promise<AgentArchilView>;
64
+ removeAgentDisk: (agent: RemovingAgent, signal?: AbortSignal) => Promise<AgentArchilView & {
65
+ removed: {
66
+ disk_id: string;
67
+ } | null;
68
+ }>;
69
+ checkLaunchDisk: (diskId: string, signal?: AbortSignal) => Promise<void>;
39
70
  };
40
71
  export type ArchilRoutes = ReturnType<typeof createArchilRoutes>;
41
- /** One of the owner's Archil routes at its handler: its answer (sent 200), or an ApiError (sent with its status). */
72
+ /** One of the owner's Archil routes at its handler: its answer (sent 200), or an ApiError (sent with its status). An
73
+ * agent's route takes the agent as the dispatch read it. */
42
74
  export declare function archilRoute(routes: ArchilRoutes, name: string, request: {
43
75
  readonly body?: unknown;
44
76
  readonly signal?: AbortSignal;
77
+ readonly agent?: RemovingAgent;
45
78
  }): Promise<unknown>;
@@ -1,30 +1,43 @@
1
- // The owner's Archil routes: what turns Mode 2 on and off. Mode 2 is the Archil settings row present (archil-settings.ts);
2
- // the disk's one kept credential is the account key, sealed under the claim's row name ("archil.api_key"). No disk token
3
- // is kept: a computer's mount credential is minted per run from the account key.
4
- // GET /v2/workspace/archil on or off, the settings, and the account key as the shared secret shape: set or not,
5
- // where from, when changed (never a value)
1
+ // The owner's Archil routes: what turns Mode 2 on and off, and each agent's disk. Mode 2 is the Archil settings row
2
+ // present (archil-settings.ts): the account key's region, its S3 URL and an optional exec image. There is no server-wide
3
+ // disk: each agent has its own, made on its first run that needs one (workspace/run-disk.ts), and a run's launch may
4
+ // name another. The one kept credential is the account key, sealed under the claim's row name ("archil.api_key"). No
5
+ // disk token is kept: a computer's mount credential is minted per run from the account key.
6
+ // GET /v2/workspace/archil on or off, the settings and where from (the server's environment, else saved), and
7
+ // the account key as the shared secret shape: set or not, where from, when changed
8
+ // (never a value)
6
9
  // PUT /v2/workspace/archil the settings row replaced, and the account key sealed when given (null removes it);
7
10
  // the exec image, when given, pinned by digest
8
11
  // DELETE /v2/workspace/archil off (the settings row removed; the key is kept, for turning it on again)
9
- // POST /v2/workspace/archil/test one listing of the disk's root through its file API, with the account key opened
10
- // as a claim opens it (archilClaim): { ok, detail } or { ok: false, why }
12
+ // POST /v2/workspace/archil/test one listing of the account's disks at the region's control plane, with the
13
+ // account key opened as a claim opens it: { ok, detail } or { ok: false, why }
14
+ // GET /v2/agents/{id}/archil the agent's disk: its id, or none yet
15
+ // DELETE /v2/agents/{id}/archil an archived agent's (or an agent its source manages): its disk removed at Archil and
16
+ // forgotten, with no live run of any agent on it; a disk a launch named is a
17
+ // customer's and never touched here
18
+ // And a launch's archil_disk is read here once before its run is made (checkLaunchDisk).
19
+ // While the server's environment sets the settings (ARCHIL_SETTINGS_ENV), PUT and DELETE /v2/workspace/archil are 409
20
+ // key_set_by_server: they are changed where the server is started, as a tool key its launcher sets is, never saved here
21
+ // to no effect.
11
22
  // archilRoute holds the routes' rules, so serve's dispatch only calls it and sends the answer, or the ApiError's status.
12
- import { ARCHIL_API_KEY_ROW, clearArchilSettings, loadArchilSettings, saveArchilSettings } from "./archil-settings.js";
23
+ import { agentDiskOf, ARCHIL_API_KEY_ROW, ARCHIL_SETTINGS_ENV, archilSettingsFromEnv, archilSettingsIssues, archilSettingsOf, clearArchilSettings, forgetAgentDisk, loadArchilSettings, saveArchilSettings, storeAgentDisk } from "./archil-settings.js";
13
24
  import { ApiError, invalid } from "./errors.js";
14
- import { keyMetaOf } from "./key-meta.js";
25
+ import { envValue, keyMetaOf } from "./key-meta.js";
15
26
  import { registerNotSecretWrite, registerSecretWrite, secretName } from "./secret-writes.js";
27
+ import { readLaunchBody } from "./run-launch.js";
16
28
  import { putSealedKey, removeSealedKey } from "./server-keys.js";
17
29
  import { unknownFields } from "./validate.js";
18
30
  import { ArchilClaimRefused } from "./workspace/archil-claim.js";
31
+ import { deleteDisk, listOneDisk } from "./workspace/archil-disks.js";
19
32
  import { ARCHIL_API_KEY_ENV, archilApiKey } from "./workspace/archil-key.js";
20
- import { archilDisk, pinnedImage } from "./workspace/archil-disk.js";
33
+ import { launchDiskProblem } from "./workspace/run-disk.js";
21
34
  /** The routes, by their operation names. */
22
- export const ARCHIL_ROUTES = new Set(["getWorkspaceArchil", "putWorkspaceArchil", "deleteWorkspaceArchil", "testWorkspaceArchil"]);
35
+ export const ARCHIL_ROUTES = new Set(["getWorkspaceArchil", "putWorkspaceArchil", "deleteWorkspaceArchil", "testWorkspaceArchil", "getAgentArchil", "deleteAgentArchil"]);
23
36
  /** The key the owner gives, by the name the API takes, and the sealed-key row it is kept in. */
24
37
  const KEYS = [{ name: ARCHIL_API_KEY_ENV, row: ARCHIL_API_KEY_ROW }];
25
38
  /** The key names the Archil settings take, as the document names them. */
26
39
  export const ARCHIL_KEY_NAMES = KEYS.map((key) => key.name);
27
- // Every PUT of the Archil settings is a secret write (secret-writes.ts), whatever its body: the account key, and the disk,
40
+ // Every PUT of the Archil settings is a secret write (secret-writes.ts), whatever its body: the account key, and the
28
41
  // region and S3 URL too, which say where every run's files go, so a token never re-points them. The server's one dispatch
29
42
  // check keeps it to the owner's session. Turning Archil off keeps the key, so it is not registered.
30
43
  registerSecretWrite("putWorkspaceArchil", () => true);
@@ -32,7 +45,24 @@ registerNotSecretWrite("deleteWorkspaceArchil", "Turning Archil off keeps its ke
32
45
  registerNotSecretWrite("testWorkspaceArchil", "A connection test reads the saved key and writes none.");
33
46
  /** The account key as its one SecretMeta: named "workspace:archil", set by ARCHIL_API_KEY or its sealed row. */
34
47
  const SECRET = { secret: secretName("workspace", "archil"), env: ARCHIL_API_KEY_ENV, row: ARCHIL_API_KEY_ROW };
35
- const OFF = "Archil is off on this server: save its disk, region and S3 URL (PUT /v2/workspace/archil)";
48
+ /** The states of a run that may still mount its disk: every one but the final ones. */
49
+ const LIVE = ["queued", "running", "parked"];
50
+ /** How many live runs, of any agent, are on agent `agentId`'s disk `diskId`: a run whose launch names that disk (a run of
51
+ * another agent may name it in its archil_disk), or a run of the agent whose launch names none (its claim takes the
52
+ * agent's disk). A live run whose launch can't be read is counted: the disk is kept while a run might be on it. */
53
+ export async function liveRunsOnDisk(runs, agentId, diskId) {
54
+ let count = 0;
55
+ // One read of every run, so a run that changes state meanwhile (parked to running) cannot fall between two reads.
56
+ for (const run of await runs.list({})) {
57
+ if (!LIVE.includes(run.state))
58
+ continue;
59
+ const read = await runs.launch(run.id).then((row) => ({ disk: readLaunchBody(row.body)?.archilDisk }), () => undefined);
60
+ if (read === undefined || (read.disk === undefined ? run.agentId === agentId : read.disk.diskId === diskId))
61
+ count += 1;
62
+ }
63
+ return count;
64
+ }
65
+ const OFF = `Archil is off on this server: save its region, S3 URL and account key (PUT /v2/workspace/archil), or start the server with ${ARCHIL_SETTINGS_ENV.region}, ${ARCHIL_SETTINGS_ENV.s3Url} and ARCHIL_API_KEY`;
36
66
  const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
37
67
  const describe = (error) => String(error?.message ?? error).replace(/\s+/g, " ").slice(0, 300);
38
68
  const statusOf = (error) => {
@@ -41,29 +71,29 @@ const statusOf = (error) => {
41
71
  };
42
72
  export function createArchilRoutes(options) {
43
73
  const { store, sealKey, env = {} } = options;
74
+ const control = (settings, key) => ({ region: settings.region, key: () => key, ...(options.control?.baseUrl ? { baseUrl: options.control.baseUrl } : {}), ...(options.control?.fetch ? { fetch: options.control.fetch } : {}) });
75
+ /** Each agent's disk removal in flight, settled either way: the next one of that agent waits for it. */
76
+ const removals = new Map();
44
77
  async function view() {
45
- const settings = await loadArchilSettings(store);
46
- return { on: settings !== undefined, ...(settings ?? {}), secret: (await keyMetaOf(store, [SECRET], env))[0] };
78
+ const settings = await loadArchilSettings(store, env);
79
+ const shown = settings === undefined ? {} : { source: archilSettingsFromEnv(env) ? "env" : "console", region: settings.region, s3Url: settings.s3Url, ...(settings.image !== undefined ? { image: settings.image } : {}) };
80
+ return { on: settings !== undefined, ...shown, secret: (await keyMetaOf(store, [SECRET], env))[0] };
81
+ }
82
+ /** A change refused while the server's environment sets the settings: nothing saved would take effect. */
83
+ function refuseWhileEnv() {
84
+ if (archilSettingsFromEnv(env) === undefined)
85
+ return;
86
+ const held = Object.values(ARCHIL_SETTINGS_ENV).filter((name) => envValue(env, name) !== undefined);
87
+ throw new ApiError("key_set_by_server", `This server is started with ${held.join(", ")}: its Archil settings are changed where the server is started, not here.`, { details: { fields: held } });
47
88
  }
48
89
  /** The settings row replaced and the keys given sealed, once every field is right; nothing is saved when one is not. */
49
90
  async function save(body) {
91
+ refuseWhileEnv();
50
92
  if (typeof body !== "object" || body === null || Array.isArray(body))
51
- throw new ApiError("input_invalid", "the body is a JSON object: { diskId, region, s3Url, image?, keys? }");
93
+ throw new ApiError("input_invalid", "the body is a JSON object: { region, s3Url, image?, keys? }");
52
94
  const given = body;
53
- const issues = unknownFields(given, ["diskId", "region", "s3Url", "image", "keys"]);
54
- for (const field of ["diskId", "region"])
55
- if (!nonEmpty(given[field]))
56
- issues.push({ field, reason: "required", message: `${field} is a non-empty string` });
57
- if (!nonEmpty(given.s3Url) || !URL.canParse(given.s3Url) || new URL(given.s3Url).protocol !== "https:")
58
- issues.push({ field: "s3Url", reason: "invalid", message: "s3Url is the disk's S3 endpoint, an https URL" });
59
- if (given.image !== undefined) {
60
- try {
61
- pinnedImage({ baseImage: given.image });
62
- }
63
- catch {
64
- issues.push({ field: "image", reason: "invalid", message: "image is pinned by digest: <name>@sha256:<64 hex>" });
65
- }
66
- }
95
+ const issues = unknownFields(given, ["region", "s3Url", "image", "keys"]).map((issue) => issue.field === "diskId" ? { ...issue, message: "There is no server-wide disk: each agent has its own, made on its first run, and a run may name another (archil_disk on its start)." } : issue);
96
+ issues.push(...archilSettingsIssues(given));
67
97
  const keys = given.keys ?? {};
68
98
  if (typeof keys !== "object" || keys === null || Array.isArray(keys))
69
99
  issues.push({ field: "keys", reason: "wrong_type", message: "keys is an object of ARCHIL_API_KEY" });
@@ -76,7 +106,7 @@ export function createArchilRoutes(options) {
76
106
  }
77
107
  if (issues.length)
78
108
  throw invalid(issues);
79
- const settings = { diskId: given.diskId.trim(), region: given.region.trim(), s3Url: given.s3Url, ...(given.image !== undefined ? { image: given.image } : {}) };
109
+ const settings = archilSettingsOf(given);
80
110
  for (const [name, value] of entries) {
81
111
  const row = KEYS.find((key) => key.name === name).row;
82
112
  if (value === null)
@@ -88,55 +118,132 @@ export function createArchilRoutes(options) {
88
118
  return view();
89
119
  }
90
120
  async function off() {
121
+ refuseWhileEnv();
91
122
  await clearArchilSettings(store);
92
123
  return view();
93
124
  }
94
- /** One listing of the disk's root, with the account key by the one resolver (archil-key.ts: the environment's, else
95
- * the sealed row) and the disk made as the claim makes it; no exec image, as nothing runs. The key is dropped after. */
125
+ /** One listing of the account's disks at the region's control plane, with the account key by the one resolver
126
+ * (archil-key.ts: the environment's, else the sealed row). The key is dropped after. */
96
127
  async function test(signal) {
97
- const settings = await loadArchilSettings(store);
128
+ const settings = await loadArchilSettings(store, env);
98
129
  if (settings === undefined)
99
130
  return { ok: false, why: OFF };
100
131
  let key;
101
- let disk;
102
132
  try {
103
133
  key = (await archilApiKey({ env, keys: store.sealedKeys, sealKey })).value;
104
- const held = key;
105
- disk = (options.makeDisk ?? archilDisk)({ disk: settings.diskId, region: settings.region, s3BaseUrl: settings.s3Url, key: () => {
106
- if (key === undefined)
107
- throw new Error("the test's Archil key was released once the test was done");
108
- return held;
109
- } });
110
134
  }
111
135
  catch (error) {
112
136
  if (error instanceof ArchilClaimRefused)
113
137
  return { ok: false, why: error.message };
114
- const words = key ? describe(error).split(key).join("[the key]") : describe(error);
115
- return { ok: false, why: `This server's Archil settings can't make its disk: ${words}` };
138
+ return { ok: false, why: `This server's Archil key can't be read: ${describe(error)}` };
116
139
  }
117
- const secret = key;
118
- const scrub = (text) => text.split(secret).join("[the key]");
140
+ const scrub = (text) => text.split(key).join("[the key]");
119
141
  try {
120
142
  if (signal?.aborted)
121
143
  return { ok: false, why: "The test of Archil was cancelled." };
122
- await disk.listPage("", { recursive: false });
123
- return { ok: true, detail: `the disk ${settings.diskId} answered its root listing` };
144
+ const count = await listOneDisk(control(settings, key), signal ? { signal } : {});
145
+ return { ok: true, detail: `Archil's ${settings.region} control plane listed the account's disks (${count} so far)` };
124
146
  }
125
147
  catch (error) {
126
148
  const status = statusOf(error);
127
149
  if (status === 401 || status === 403)
128
150
  return { ok: false, why: `Archil refused the key: check ARCHIL_API_KEY in the server's Archil settings, then test again. (Archil said: ${scrub(describe(error))})` };
129
- if (status === 404)
130
- return { ok: false, why: `Archil has no disk ${settings.diskId} in ${settings.region}: check the disk and region, then test again.` };
131
- return { ok: false, why: `Archil could not be reached: check the S3 URL and the network, then test again. (${scrub(describe(error))})` };
151
+ return { ok: false, why: `Archil could not be reached: check the region and the network, then test again. (${scrub(describe(error))})` };
152
+ }
153
+ }
154
+ /** Agent `agentId`'s disk: none until its first run that uses it. */
155
+ async function agentView(agentId) {
156
+ const on = (await loadArchilSettings(store, env)) !== undefined;
157
+ const disk = on ? await agentDiskOf(store, agentId) : undefined;
158
+ return { on, archil_disk: disk ? { disk_id: disk.diskId } : null };
159
+ }
160
+ /** The account key, opened now, or an ApiError `code` naming what to save (never a value). */
161
+ async function keyOr(code, what) {
162
+ try {
163
+ return (await archilApiKey({ env, keys: store.sealedKeys, sealKey })).value;
164
+ }
165
+ catch (error) {
166
+ if (code === "input_invalid")
167
+ throw invalid([{ field: "archil_disk", reason: "not_set_up_here", message: `${what}: ${describe(error)}` }]);
168
+ throw new ApiError(code, `${what}: ${describe(error)}`);
169
+ }
170
+ }
171
+ /** Agent `agentId`'s disk removed, with no live run of any agent on it (its folders, home and learning go with the
172
+ * disk), deleted at Archil, then forgotten: its next run makes a new one. An agent of this server must be archived
173
+ * first; an agent its source manages (an inline run's, which is never archived here) needs no archive, since its source
174
+ * decides when it is done. A launch's disk is never stored on the agent, so it is never reached here.
175
+ * The disk is marked removing before its live runs are counted: from then on no launch takes it and no claim mounts it
176
+ * (server.ts launchDiskOf, run-disk.ts runDiskOf), so a run launched while the count runs is refused, never started on
177
+ * a disk being deleted. A refusal, or a delete Archil does not do, leaves the disk the agent's as it was.
178
+ * One agent's removals are taken in turn, and each changes the agent's stored row only while it still names the disk
179
+ * that removal is deleting, so a disk a run stored since is never forgotten. */
180
+ function removeAgentDisk(agent, signal) {
181
+ const before = removals.get(agent.id) ?? Promise.resolve();
182
+ const turn = before.then(() => removeAgentDiskNow(agent, signal));
183
+ const settled = turn.then(() => undefined, () => undefined);
184
+ removals.set(agent.id, settled);
185
+ void settled.then(() => {
186
+ if (removals.get(agent.id) === settled)
187
+ removals.delete(agent.id);
188
+ });
189
+ return turn;
190
+ }
191
+ /** The disk row put back as the agent's, when it is still this removal's (marked removing, naming `diskId`). */
192
+ async function giveBack(agentId, diskId, pending) {
193
+ const now = await agentDiskOf(store, agentId);
194
+ if (now?.diskId === diskId && now.removing)
195
+ await storeAgentDisk(store, agentId, { diskId, ...(pending ? { pending: true } : {}) });
196
+ }
197
+ async function removeAgentDiskNow(agent, signal) {
198
+ const settings = await loadArchilSettings(store, env);
199
+ const disk = settings === undefined ? undefined : await agentDiskOf(store, agent.id);
200
+ if (settings === undefined || disk === undefined)
201
+ return { ...(await agentView(agent.id)), removed: null };
202
+ if (!agent.archived && !agent.external)
203
+ throw new ApiError("precondition_failed", `the agent ${agent.id} is not archived: archive it first (POST /v2/agents/${agent.id}/archive), then remove its disk`);
204
+ await storeAgentDisk(store, agent.id, { diskId: disk.diskId, removing: true, ...(disk.pending ? { pending: true } : {}) });
205
+ try {
206
+ const live = await agent.liveOn(disk.diskId);
207
+ if (live > 0)
208
+ throw new ApiError("precondition_failed", `${live} live run${live === 1 ? " is" : "s are"} on the agent ${agent.id}'s disk ${disk.diskId}: stop ${live === 1 ? "it" : "them"} first`);
209
+ const key = await keyOr("unavailable", `the agent's disk ${disk.diskId} can't be removed`);
210
+ try {
211
+ await deleteDisk(control(settings, key), disk.diskId, signal ? { signal } : {});
212
+ }
213
+ catch (error) {
214
+ throw new ApiError("upstream_failed", `Archil did not remove the agent's disk ${disk.diskId}: ${describe(error).split(key).join("[the key]")}`);
215
+ }
132
216
  }
133
- finally {
134
- key = undefined;
217
+ catch (error) {
218
+ await giveBack(agent.id, disk.diskId, disk.pending === true);
219
+ throw error;
220
+ }
221
+ await forgetAgentDisk(store, agent.id, disk.diskId);
222
+ return { ...(await agentView(agent.id)), removed: { disk_id: disk.diskId } };
223
+ }
224
+ /** A launch's `archil_disk`, read once at Archil before the run is made (run-disk.ts launchDiskProblem): a disk that is
225
+ * not there, or not in the key's region, is 422 at `archil_disk.disk_id` in words naming the region; Mode 1, or no key,
226
+ * is 422 at `archil_disk`; Archil not reached (or refusing the key) is 503. The claim reads it again, for a disk
227
+ * removed in between. */
228
+ async function checkLaunchDisk(diskId, signal) {
229
+ const settings = await loadArchilSettings(store, env);
230
+ if (settings === undefined)
231
+ throw invalid([{ field: "archil_disk", reason: "not_allowed", message: "This server keeps run folders on its own disk (Mode 1): a run names an Archil disk only in Archil mode (PUT /v2/workspace/archil).", fix: "Remove archil_disk." }]);
232
+ const key = await keyOr("input_invalid", "This server's Archil key can't be read to check the run's disk");
233
+ let problem;
234
+ try {
235
+ problem = await launchDiskProblem(control(settings, key), diskId, signal ? { signal } : {});
236
+ }
237
+ catch (error) {
238
+ throw new ApiError("unavailable", `Archil could not be asked about the disk ${diskId}: ${describe(error).split(key).join("[the key]")}`);
135
239
  }
240
+ if (problem !== undefined)
241
+ throw invalid([{ field: "archil_disk.disk_id", reason: "not_an_option", message: problem }]);
136
242
  }
137
- return { view, save, off, test };
243
+ return { view, save, off, test, agentView, removeAgentDisk, checkLaunchDisk };
138
244
  }
139
- /** One of the owner's Archil routes at its handler: its answer (sent 200), or an ApiError (sent with its status). */
245
+ /** One of the owner's Archil routes at its handler: its answer (sent 200), or an ApiError (sent with its status). An
246
+ * agent's route takes the agent as the dispatch read it. */
140
247
  export async function archilRoute(routes, name, request) {
141
248
  if (name === "getWorkspaceArchil")
142
249
  return routes.view();
@@ -146,5 +253,11 @@ export async function archilRoute(routes, name, request) {
146
253
  return routes.off();
147
254
  if (name === "testWorkspaceArchil")
148
255
  return routes.test(request.signal);
256
+ if ((name === "getAgentArchil" || name === "deleteAgentArchil") && request.agent === undefined)
257
+ throw new ApiError("not_found", "no agent");
258
+ if (name === "getAgentArchil")
259
+ return routes.agentView(request.agent.id);
260
+ if (name === "deleteAgentArchil")
261
+ return routes.removeAgentDisk(request.agent, request.signal);
149
262
  throw new ApiError("not_found", `no Archil route ${name}`);
150
263
  }