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

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 (450) hide show
  1. package/CHANGELOG.md +263 -0
  2. package/README.md +339 -179
  3. package/dist/adapters.d.ts +15 -2
  4. package/dist/adapters.js +34 -2
  5. package/dist/agent-rows.d.ts +3 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +25 -5
  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 +90 -8
  13. package/dist/archil-settings.js +150 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/bash-read-only.d.ts +13 -0
  19. package/dist/bash-read-only.js +77 -0
  20. package/dist/box-image.d.ts +1 -97
  21. package/dist/box-image.js +4 -284
  22. package/dist/box-paths.d.ts +2 -7
  23. package/dist/box-paths.js +7 -13
  24. package/dist/box-settings.d.ts +0 -11
  25. package/dist/box-settings.js +4 -29
  26. package/dist/browser-commands.js +1 -1
  27. package/dist/browser-computer.d.ts +47 -3
  28. package/dist/browser-computer.js +286 -18
  29. package/dist/browser-cost.d.ts +2 -2
  30. package/dist/browser-cost.js +6 -4
  31. package/dist/browser-person.d.ts +19 -2
  32. package/dist/browser-person.js +55 -6
  33. package/dist/browser-wait-ended.d.ts +23 -0
  34. package/dist/browser-wait-ended.js +42 -0
  35. package/dist/cap.d.ts +19 -44
  36. package/dist/cap.js +31 -77
  37. package/dist/cli.js +36 -27
  38. package/dist/computer-keys.d.ts +20 -10
  39. package/dist/computer-keys.js +36 -57
  40. package/dist/computer-routes.d.ts +1 -4
  41. package/dist/computer-routes.js +3 -5
  42. package/dist/computer-setting.d.ts +8 -5
  43. package/dist/computer-setting.js +91 -26
  44. package/dist/computer-view.d.ts +11 -2
  45. package/dist/computer-view.js +2 -1
  46. package/dist/computers.d.ts +54 -8
  47. package/dist/computers.js +101 -22
  48. package/dist/console/assets/index-BI4Byidu.js +550 -0
  49. package/dist/console/assets/index-C19gUF2n.css +1 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/content-filter.d.ts +7 -0
  52. package/dist/content-filter.js +23 -0
  53. package/dist/decision-cap.d.ts +7 -29
  54. package/dist/decision-cap.js +3 -94
  55. package/dist/docker-daemon.d.ts +2 -2
  56. package/dist/docker-daemon.js +2 -2
  57. package/dist/errors.d.ts +1 -0
  58. package/dist/errors.js +8 -5
  59. package/dist/explain.js +3 -1
  60. package/dist/faux-computers.js +4 -0
  61. package/dist/files.d.ts +1 -9
  62. package/dist/files.js +1 -9
  63. package/dist/github-connection.js +25 -7
  64. package/dist/github-faux.d.ts +26 -0
  65. package/dist/github-faux.js +76 -0
  66. package/dist/github.d.ts +28 -4
  67. package/dist/github.js +46 -10
  68. package/dist/gpu-words.d.ts +14 -0
  69. package/dist/gpu-words.js +21 -0
  70. package/dist/graph-served.d.ts +5 -3
  71. package/dist/graph-served.js +14 -6
  72. package/dist/graph-view.d.ts +2 -0
  73. package/dist/graph-view.js +29 -2
  74. package/dist/handed-values.d.ts +1 -1
  75. package/dist/handed-values.js +1 -1
  76. package/dist/harness-install.d.ts +60 -3
  77. package/dist/harness-install.js +322 -34
  78. package/dist/harness-opencode/harness.js +0 -1
  79. package/dist/harness-opencode/host/policy.js +2 -2
  80. package/dist/harness.js +1 -1
  81. package/dist/host-tools.d.ts +8 -9
  82. package/dist/host-tools.js +7 -7
  83. package/dist/index.d.ts +2 -3
  84. package/dist/index.js +2 -2
  85. package/dist/key-refusal.d.ts +1 -1
  86. package/dist/key-refusal.js +2 -2
  87. package/dist/learn/check.d.ts +10 -2
  88. package/dist/learn/check.js +126 -8
  89. package/dist/learn/commit.d.ts +40 -6
  90. package/dist/learn/commit.js +164 -20
  91. package/dist/learn/folder.d.ts +11 -3
  92. package/dist/learn/folder.js +40 -16
  93. package/dist/learn/grade.d.ts +22 -2
  94. package/dist/learn/grade.js +127 -19
  95. package/dist/learn/index.d.ts +2 -2
  96. package/dist/learn/index.js +2 -2
  97. package/dist/learn/learning.sh +11 -13
  98. package/dist/learn/notes.d.ts +17 -3
  99. package/dist/learn/notes.js +19 -6
  100. package/dist/learn/reflect.d.ts +5 -2
  101. package/dist/learn/reflect.js +48 -32
  102. package/dist/learn/skills.d.ts +52 -5
  103. package/dist/learn/skills.js +104 -21
  104. package/dist/learned-nodes.d.ts +18 -0
  105. package/dist/learned-nodes.js +8 -0
  106. package/dist/learned-workflow.d.ts +27 -13
  107. package/dist/learned-workflow.js +110 -38
  108. package/dist/learning-cost.d.ts +79 -0
  109. package/dist/learning-cost.js +69 -0
  110. package/dist/learning-routes.d.ts +48 -2
  111. package/dist/learning-routes.js +99 -28
  112. package/dist/learning-run.d.ts +7 -5
  113. package/dist/learning-run.js +9 -6
  114. package/dist/learning-words.d.ts +3 -0
  115. package/dist/learning-words.js +6 -2
  116. package/dist/learning.d.ts +13 -28
  117. package/dist/learning.js +4 -18
  118. package/dist/llm.d.ts +4 -1
  119. package/dist/llm.js +4 -2
  120. package/dist/mcp-gateway.d.ts +6 -0
  121. package/dist/mcp-gateway.js +11 -1
  122. package/dist/mcp-probe.d.ts +8 -1
  123. package/dist/mcp-probe.js +62 -20
  124. package/dist/mcp-secret-writes.js +4 -0
  125. package/dist/mcp-servers-store.d.ts +12 -12
  126. package/dist/mcp-servers-store.js +8 -3
  127. package/dist/model.d.ts +8 -5
  128. package/dist/model.js +14 -6
  129. package/dist/openapi.d.ts +2 -0
  130. package/dist/openapi.js +236 -55
  131. package/dist/owner.d.ts +0 -1
  132. package/dist/owner.js +0 -2
  133. package/dist/pause.d.ts +2 -19
  134. package/dist/pause.js +5 -74
  135. package/dist/place-offers.d.ts +97 -0
  136. package/dist/place-offers.js +206 -0
  137. package/dist/place.d.ts +9 -13
  138. package/dist/place.js +22 -32
  139. package/dist/port-models.d.ts +12 -4
  140. package/dist/port-models.js +31 -9
  141. package/dist/print.d.ts +1 -8
  142. package/dist/print.js +1 -14
  143. package/dist/propose.d.ts +3 -0
  144. package/dist/propose.js +25 -19
  145. package/dist/run-cut.d.ts +5 -0
  146. package/dist/run-cut.js +19 -0
  147. package/dist/run-db.js +3 -3
  148. package/dist/run-launch.d.ts +18 -3
  149. package/dist/run-launch.js +11 -5
  150. package/dist/run-learning-served.d.ts +12 -1
  151. package/dist/run-manifest.d.ts +2 -2
  152. package/dist/run-manifest.js +2 -2
  153. package/dist/run-reads-over-store.d.ts +4 -2
  154. package/dist/run-reads-over-store.js +10 -8
  155. package/dist/run-secrets.js +3 -3
  156. package/dist/run-timeline-served.js +60 -38
  157. package/dist/run-view.d.ts +35 -16
  158. package/dist/run-view.js +64 -35
  159. package/dist/runnable.d.ts +6 -3
  160. package/dist/runnable.js +20 -4
  161. package/dist/runner/adapter-loop.d.ts +46 -5
  162. package/dist/runner/adapter-loop.js +381 -56
  163. package/dist/runner/adapter-run-spec.d.ts +46 -4
  164. package/dist/runner/adapter-run-spec.js +200 -45
  165. package/dist/runner/adapters/pi.d.ts +39 -3
  166. package/dist/runner/adapters/pi.js +124 -29
  167. package/dist/runner/beside.d.ts +8 -0
  168. package/dist/runner/beside.js +24 -2
  169. package/dist/runner/claim-secrets.d.ts +6 -0
  170. package/dist/runner/claim-secrets.js +15 -1
  171. package/dist/runner/cli-run-spec.d.ts +10 -0
  172. package/dist/runner/cli-run-spec.js +207 -64
  173. package/dist/runner/commands.d.ts +5 -1
  174. package/dist/runner/commands.js +3 -3
  175. package/dist/runner/conformance/harness.d.ts +1 -1
  176. package/dist/runner/conformance/harness.js +13 -10
  177. package/dist/runner/github-app.d.ts +7 -2
  178. package/dist/runner/github-app.js +46 -15
  179. package/dist/runner/harness-loops.d.ts +6 -1
  180. package/dist/runner/harness-loops.js +24 -1
  181. package/dist/runner/journal-kinds.d.ts +53 -7
  182. package/dist/runner/journal-kinds.js +29 -1
  183. package/dist/runner/learning-end.d.ts +15 -0
  184. package/dist/runner/learning-end.js +113 -20
  185. package/dist/runner/learning-factory.js +6 -2
  186. package/dist/runner/learning-loop.d.ts +75 -1
  187. package/dist/runner/learning-loop.js +215 -22
  188. package/dist/runner/learning-seed.d.ts +8 -0
  189. package/dist/runner/learning-seed.js +7 -1
  190. package/dist/runner/loop-contract.d.ts +12 -0
  191. package/dist/runner/loop-contract.js +6 -0
  192. package/dist/runner/loop.d.ts +5 -1
  193. package/dist/runner/loop.js +20 -0
  194. package/dist/runner/main.d.ts +9 -4
  195. package/dist/runner/main.js +38 -13
  196. package/dist/runner/mcp-claim.d.ts +7 -0
  197. package/dist/runner/mcp-claim.js +35 -2
  198. package/dist/runner/mcp-github.d.ts +15 -4
  199. package/dist/runner/mcp-github.js +55 -11
  200. package/dist/runner/mcp-run.d.ts +2 -0
  201. package/dist/runner/mcp-run.js +2 -0
  202. package/dist/runner/metrics.d.ts +18 -1
  203. package/dist/runner/metrics.js +81 -1
  204. package/dist/runner/model-route.d.ts +6 -0
  205. package/dist/runner/model-route.js +5 -2
  206. package/dist/runner/pr-checkout.d.ts +59 -0
  207. package/dist/runner/pr-checkout.js +176 -0
  208. package/dist/runner/reflect-hook.d.ts +1 -0
  209. package/dist/runner/reflect-hook.js +3 -3
  210. package/dist/runner/runner.js +136 -19
  211. package/dist/runner/spec-holds.d.ts +13 -3
  212. package/dist/runner/spec-holds.js +13 -10
  213. package/dist/runner/store-port.d.ts +4 -1
  214. package/dist/runner/store-secrets.js +17 -1
  215. package/dist/runner/subagent.d.ts +44 -0
  216. package/dist/runner/subagent.js +188 -0
  217. package/dist/runner/workflow-host.d.ts +25 -4
  218. package/dist/runner/workflow-host.js +26 -4
  219. package/dist/runner/workflow-loop.d.ts +9 -3
  220. package/dist/runner/workflow-loop.js +17 -10
  221. package/dist/runner/workflow-spec.d.ts +28 -13
  222. package/dist/runner/workflow-spec.js +247 -102
  223. package/dist/runs-over-store.d.ts +18 -7
  224. package/dist/runs-over-store.js +149 -31
  225. package/dist/seal-key.d.ts +0 -2
  226. package/dist/seal-key.js +0 -2
  227. package/dist/sealing.js +1 -2
  228. package/dist/secret-cut.d.ts +1 -1
  229. package/dist/secret-cut.js +1 -1
  230. package/dist/server-lock.js +4 -5
  231. package/dist/server.d.ts +49 -63
  232. package/dist/server.js +429 -230
  233. package/dist/stop-signals.d.ts +4 -2
  234. package/dist/stop-signals.js +5 -3
  235. package/dist/store/agent-body.d.ts +14 -3
  236. package/dist/store/agent-body.js +22 -8
  237. package/dist/store/deadline.d.ts +18 -0
  238. package/dist/store/deadline.js +49 -0
  239. package/dist/store/index.d.ts +3 -3
  240. package/dist/store/index.js +2 -2
  241. package/dist/store/journal/storage.js +2 -1
  242. package/dist/store/postgres/connection.d.ts +4 -0
  243. package/dist/store/postgres/connection.js +64 -13
  244. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  245. package/dist/store/schema.d.ts +2 -1
  246. package/dist/store/schema.js +11 -8
  247. package/dist/store/seal.d.ts +13 -0
  248. package/dist/store/seal.js +19 -0
  249. package/dist/store/sqlite/connection.d.ts +5 -0
  250. package/dist/store/sqlite/connection.js +88 -82
  251. package/dist/store/sqlite/run-patch.d.ts +18 -2
  252. package/dist/store/sqlite/run-patch.js +31 -2
  253. package/dist/store/sqlite/store.js +65 -11
  254. package/dist/store/store.d.ts +62 -12
  255. package/dist/store/store.js +22 -1
  256. package/dist/store-reads/analytics.js +3 -2
  257. package/dist/store-reads/cap.d.ts +1 -3
  258. package/dist/store-reads/cap.js +8 -6
  259. package/dist/store-reads/decisions.d.ts +2 -2
  260. package/dist/store-reads/decisions.js +3 -6
  261. package/dist/store-reads/journal.js +83 -15
  262. package/dist/store-reads/learning.d.ts +73 -3
  263. package/dist/store-reads/learning.js +232 -9
  264. package/dist/store-reads/runs.d.ts +6 -4
  265. package/dist/store-reads/runs.js +17 -10
  266. package/dist/store-reads/stats.js +5 -1
  267. package/dist/store-view.d.ts +15 -1
  268. package/dist/store-view.js +88 -29
  269. package/dist/template-eval.js +2 -1
  270. package/dist/templates.d.ts +73 -4
  271. package/dist/templates.js +113 -23
  272. package/dist/timeline/timeline.d.ts +11 -1
  273. package/dist/timeline/timeline.js +19 -4
  274. package/dist/tool-blurbs.js +1 -0
  275. package/dist/tool-budget.d.ts +26 -0
  276. package/dist/tool-budget.js +56 -0
  277. package/dist/tool-gate.d.ts +13 -3
  278. package/dist/tool-gate.js +15 -7
  279. package/dist/tool-plane.d.ts +42 -29
  280. package/dist/tool-plane.js +64 -27
  281. package/dist/tools.d.ts +53 -39
  282. package/dist/tools.js +174 -79
  283. package/dist/trigger-signatures.d.ts +1 -0
  284. package/dist/trigger-signatures.js +3 -1
  285. package/dist/triggers.d.ts +3 -3
  286. package/dist/triggers.js +2 -2
  287. package/dist/turn-end.d.ts +0 -3
  288. package/dist/turn-end.js +0 -3
  289. package/dist/uploads.d.ts +28 -5
  290. package/dist/uploads.js +82 -9
  291. package/dist/usage-lines.d.ts +1 -1
  292. package/dist/usage.d.ts +1 -47
  293. package/dist/usage.js +3 -82
  294. package/dist/validate.d.ts +8 -0
  295. package/dist/validate.js +40 -3
  296. package/dist/webhooks.d.ts +2 -1
  297. package/dist/webhooks.js +5 -2
  298. package/dist/workflow/decision-recovery.d.ts +23 -0
  299. package/dist/workflow/decision-recovery.js +80 -0
  300. package/dist/workflow/decisions.d.ts +134 -0
  301. package/dist/workflow/decisions.js +46 -0
  302. package/dist/workflow/host-session.d.ts +5 -0
  303. package/dist/workflow/host-session.js +85 -0
  304. package/dist/workflow/host-tools.d.ts +3 -0
  305. package/dist/workflow/host-tools.js +3 -0
  306. package/dist/workflow/node-runner.d.ts +112 -0
  307. package/dist/workflow/node-runner.js +270 -0
  308. package/dist/workflow/node.d.ts +88 -0
  309. package/dist/workflow/node.js +99 -0
  310. package/dist/workflow/operator-error.d.ts +4 -0
  311. package/dist/workflow/operator-error.js +4 -0
  312. package/dist/workflow/pi-versions.d.ts +9 -0
  313. package/dist/workflow/pi-versions.js +8 -0
  314. package/dist/workflow/readers.d.ts +36 -0
  315. package/dist/workflow/readers.js +145 -0
  316. package/dist/workflow/record-file.d.ts +10 -0
  317. package/dist/workflow/record-file.js +56 -0
  318. package/dist/workflow/record-tool.d.ts +76 -0
  319. package/dist/workflow/record-tool.js +126 -0
  320. package/dist/workflow/record.d.ts +151 -0
  321. package/dist/workflow/record.js +401 -0
  322. package/dist/workflow/run-error.d.ts +16 -0
  323. package/dist/workflow/run-error.js +26 -0
  324. package/dist/workflow/runner.d.ts +6 -0
  325. package/dist/workflow/runner.js +240 -0
  326. package/dist/workflow/store.d.ts +23 -0
  327. package/dist/workflow/store.js +242 -0
  328. package/dist/workflow/task.d.ts +133 -0
  329. package/dist/workflow/task.js +411 -0
  330. package/dist/workflow/thinking.d.ts +3 -0
  331. package/dist/workflow/thinking.js +7 -0
  332. package/dist/workflow/tool-context.d.ts +21 -0
  333. package/dist/workflow/tool-context.js +13 -0
  334. package/dist/workflow/types.d.ts +126 -0
  335. package/dist/workflow/types.js +1 -0
  336. package/dist/workflow/wal.d.ts +11 -0
  337. package/dist/workflow/wal.js +106 -0
  338. package/dist/workflow-run.d.ts +1 -1
  339. package/dist/workspace/agent-computer.d.ts +137 -0
  340. package/dist/workspace/agent-computer.js +292 -0
  341. package/dist/workspace/archil-claim.d.ts +13 -2
  342. package/dist/workspace/archil-claim.js +22 -13
  343. package/dist/workspace/archil-disk.d.ts +10 -1
  344. package/dist/workspace/archil-disk.js +4 -0
  345. package/dist/workspace/archil-disks.d.ts +49 -0
  346. package/dist/workspace/archil-disks.js +185 -0
  347. package/dist/workspace/archil-exec.d.ts +12 -2
  348. package/dist/workspace/archil-exec.js +18 -3
  349. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  350. package/dist/workspace/archil-mount-credential.js +13 -4
  351. package/dist/workspace/archil.d.ts +2 -2
  352. package/dist/workspace/archil.js +25 -5
  353. package/dist/workspace/attach.js +2 -0
  354. package/dist/workspace/computer-deps.d.ts +18 -11
  355. package/dist/workspace/computer-deps.js +64 -40
  356. package/dist/workspace/computer-for-claim.d.ts +47 -9
  357. package/dist/workspace/computer-for-claim.js +236 -24
  358. package/dist/workspace/computer-janitor.d.ts +3 -2
  359. package/dist/workspace/computer-janitor.js +43 -9
  360. package/dist/workspace/computer-ledger.d.ts +3 -8
  361. package/dist/workspace/computer-ledger.js +7 -3
  362. package/dist/workspace/computer-providers.d.ts +5 -3
  363. package/dist/workspace/computer-providers.js +11 -9
  364. package/dist/workspace/hands.d.ts +5 -2
  365. package/dist/workspace/hands.js +4 -3
  366. package/dist/workspace/index.d.ts +5 -4
  367. package/dist/workspace/index.js +2 -1
  368. package/dist/workspace/local.d.ts +3 -0
  369. package/dist/workspace/local.js +9 -0
  370. package/dist/workspace/paths.js +3 -2
  371. package/dist/workspace/pi-env.d.ts +4 -0
  372. package/dist/workspace/pi-env.js +3 -2
  373. package/dist/workspace/resolve-computer.d.ts +48 -12
  374. package/dist/workspace/resolve-computer.js +88 -19
  375. package/dist/workspace/run-disk.d.ts +34 -0
  376. package/dist/workspace/run-disk.js +91 -0
  377. package/dist/workspace/run-tools.d.ts +6 -4
  378. package/dist/workspace/run-tools.js +17 -9
  379. package/dist/workspace/server-run-workspace.d.ts +3 -2
  380. package/dist/workspace/server-run-workspace.js +17 -4
  381. package/dist/workspace/workspace.d.ts +5 -0
  382. package/dist/workspace.d.ts +0 -3
  383. package/dist/workspace.js +2 -15
  384. package/package.json +11 -16
  385. package/skills/agentrun-serve/SKILL.md +1 -1
  386. package/templates/README.md +11 -8
  387. package/templates/code-review/agent.md +27 -11
  388. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  389. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  390. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  391. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  392. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  393. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  394. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  395. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  396. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  397. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  398. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  399. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  400. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  401. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  402. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  404. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  405. package/templates/code-review/evals/re-review/prompt.md +1 -1
  406. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  407. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  408. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  409. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  410. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  411. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  412. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  413. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  414. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  415. package/templates/code-review/findings.schema.json +131 -27
  416. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  417. package/templates/code-review/skills/review/DEEP.md +130 -0
  418. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  419. package/templates/code-review/skills/review/SKILL.md +104 -154
  420. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  421. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  422. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  423. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  424. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  425. package/templates/release-notes/agent.md +11 -0
  426. package/dist/box/record.d.ts +0 -6
  427. package/dist/box/record.js +0 -41
  428. package/dist/box/sweep.d.ts +0 -53
  429. package/dist/box/sweep.js +0 -193
  430. package/dist/box-egress-vm.d.ts +0 -118
  431. package/dist/box-egress-vm.js +0 -354
  432. package/dist/box-egress.d.ts +0 -105
  433. package/dist/box-egress.js +0 -256
  434. package/dist/box-relay-vm.d.ts +0 -84
  435. package/dist/box-relay-vm.js +0 -437
  436. package/dist/box-relay.d.ts +0 -36
  437. package/dist/box-relay.js +0 -207
  438. package/dist/boxes.d.ts +0 -109
  439. package/dist/boxes.js +0 -249
  440. package/dist/budget.d.ts +0 -76
  441. package/dist/budget.js +0 -204
  442. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  443. package/dist/console/assets/index-opTN5Naq.css +0 -1
  444. package/dist/daytona-api.d.ts +0 -10
  445. package/dist/daytona-api.js +0 -20
  446. package/dist/egress-proxy.d.ts +0 -45
  447. package/dist/egress-proxy.js +0 -416
  448. package/dist/egress-table.d.ts +0 -24
  449. package/dist/egress-table.js +0 -165
  450. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -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
  }
@@ -1,21 +1,55 @@
1
+ import type { InputIssue } from "./errors.js";
2
+ import { type KeyEnv } from "./key-meta.js";
1
3
  import type { Settings } from "./store/index.js";
2
- /** The settings key the Archil disk's configuration lives under in store.settings. */
4
+ /** The settings key the Archil configuration lives under in store.settings. */
3
5
  export declare const ARCHIL_SETTINGS_KEY = "archil";
4
6
  /** The sealed-key row of the Archil account key (the file API and exec), saved through server-keys.ts. Named *_ROW: a
5
7
  * constant named like a key holding a string reads as a literal credential to the source export. */
6
8
  export declare const ARCHIL_API_KEY_ROW = "archil.api_key";
9
+ /** The exec image a Mode 2 server runs commands in when the owner saved none: Docker's official
10
+ * `buildpack-deps:trixie-scm` (Debian 13 with git 2.47.3, GNU coreutils, perl-base, grep, sed, mawk, diffutils and
11
+ * findutils; no ripgrep), pinned to the multi-arch index digest Docker Hub served for that tag on 2026-11-11. Archil's
12
+ * own default exec image has git 2.34.1, and a shell under a bash policy runs git only at 2.43 or later (bash-read-only.ts
13
+ * POLICY_GIT_FLOOR), so a read-only agent there would get no git. Its git was read from the top layer's
14
+ * /var/lib/dpkg/status for amd64 and arm64 alike (`git 1:2.47.3-0+deb13u1`). To move it, read the tag's index digest
15
+ * again (an anonymous pull token from auth.docker.io for `repository:library/buildpack-deps:pull`, then a HEAD of
16
+ * registry-1.docker.io/v2/library/buildpack-deps/manifests/trixie-scm accepting an OCI index: its
17
+ * `docker-content-digest`), check the git its layers hold, and put it here. An image the owner saved replaces it. */
18
+ export declare const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d673fdb65371de9f88bdd32c4e30152fe692b35604aef5c0b3c0e6da10";
7
19
  export interface ArchilSettings {
8
- readonly diskId: string;
20
+ /** The account key's region: the control plane every disk is made, read and minted on. */
9
21
  readonly region: string;
22
+ /** The region's S3 endpoint (the disks' file API). */
10
23
  readonly s3Url: string;
11
- /** A pinned image for the disk's exec, when the owner set one; absent, Archil's default image. */
24
+ /** A pinned image for the disk's exec, when the owner set one; absent, DEFAULT_ARCHIL_EXEC_IMAGE. */
12
25
  readonly image?: string;
13
26
  }
14
- /** The Archil settings the owner saved, or undefined when none is (Mode 1). A row that is not the expected shape reads as
15
- * undefined, never a half-configured Mode 2. */
27
+ /** The environment variable that sets each field, for a server whose operator sets Mode 2 where it is started (a headless
28
+ * deploy, where no owner's session can save it). The region and S3 URL are both set or neither; the image is optional. */
29
+ export declare const ARCHIL_SETTINGS_ENV: {
30
+ readonly region: "AGENTRUN_ARCHIL_REGION";
31
+ readonly s3Url: "AGENTRUN_ARCHIL_S3_URL";
32
+ readonly image: "AGENTRUN_ARCHIL_IMAGE";
33
+ };
34
+ /** The Archil settings in the server's environment are not whole or not right: the start stops, in these words. */
35
+ export declare class ArchilSettingsEnvInvalid extends Error {
36
+ readonly name = "ArchilSettingsEnvInvalid";
37
+ }
38
+ /** What is wrong with each settings field given, by the one rule the PUT and the environment share: a region, an https
39
+ * S3 URL, and an image, when given, pinned by digest. Empty when every field is right. */
40
+ export declare function archilSettingsIssues(given: Readonly<Record<string, unknown>>): InputIssue[];
41
+ /** The settings of fields archilSettingsIssues found right. */
42
+ export declare const archilSettingsOf: (given: Readonly<Record<string, unknown>>) => ArchilSettings;
43
+ /** The Archil settings the server's environment sets, or undefined when it sets none of ARCHIL_SETTINGS_ENV. One required
44
+ * variable without the other, or a value the PUT would refuse, is ArchilSettingsEnvInvalid naming each variable, never a
45
+ * half-configured Mode 2. The environment is passed in: process.env is never read here. */
46
+ export declare function archilSettingsFromEnv(env: KeyEnv): ArchilSettings | undefined;
47
+ /** The Archil settings in force, or undefined when there are none (Mode 1): the server's environment's (`env`), else the
48
+ * row the owner saved. A row that is not the expected shape reads as undefined, never a half-configured Mode 2; a field
49
+ * it no longer keeps (an old row's `diskId`) is dropped. */
16
50
  export declare function loadArchilSettings(store: {
17
51
  settings: Pick<Settings, "get">;
18
- }): Promise<ArchilSettings | undefined>;
52
+ }, env?: KeyEnv): Promise<ArchilSettings | undefined>;
19
53
  /** Saves the Archil settings (Mode 2), replacing any kept. */
20
54
  export declare function saveArchilSettings(store: {
21
55
  settings: Pick<Settings, "put">;
@@ -24,7 +58,55 @@ export declare function saveArchilSettings(store: {
24
58
  export declare function clearArchilSettings(store: {
25
59
  settings: Pick<Settings, "remove">;
26
60
  }): Promise<void>;
27
- /** Whether the server is in Mode 2 (the Archil disk is configured). */
61
+ /** Whether the server is in Mode 2 (the Archil settings are set, in `env` or saved). */
28
62
  export declare function inArchilMode(store: {
29
63
  settings: Pick<Settings, "get">;
30
- }): Promise<boolean>;
64
+ }, env?: KeyEnv): Promise<boolean>;
65
+ /** An Archil disk id as Archil's API returns and addresses them: dsk-<16 hex digits>. */
66
+ export declare const ARCHIL_DISK_ID: RegExp;
67
+ /** The disk agentrun made for an agent, stored on the agent (never its revision: a rollback moves no files). `removing`:
68
+ * DELETE /v2/agents/{id}/archil has begun removing it, so no launch takes it and no claim mounts it. */
69
+ export interface AgentDisk {
70
+ readonly diskId: string;
71
+ readonly removing?: true;
72
+ /** Made, and not yet read `available` at Archil: a claim that finds it waits for it before it mounts. */
73
+ readonly pending?: true;
74
+ }
75
+ /** The settings key agent `agentId`'s disk is stored under. */
76
+ export declare const agentDiskKey: (agentId: string) => string;
77
+ /** The disk stored on agent `agentId`, or undefined when it has none yet (made on its first run that uses it). */
78
+ export declare function agentDiskOf(store: {
79
+ settings: Pick<Settings, "get">;
80
+ }, agentId: string): Promise<AgentDisk | undefined>;
81
+ /** Stores `disk` on agent `agentId`, as removing when it says so. */
82
+ export declare function storeAgentDisk(store: {
83
+ settings: Pick<Settings, "put">;
84
+ }, agentId: string, disk: AgentDisk): Promise<void>;
85
+ /** The settings key of the agent disk run `runId` first resolved to (its launch record is written once, before any disk). */
86
+ export declare const runDiskKey: (runId: string) => string;
87
+ /** The agent disk run `runId` first resolved to, or undefined when none is kept: a later claim of the same run (a reopened
88
+ * one) uses that disk or is refused, never another. */
89
+ export declare function runDiskKept(store: {
90
+ settings: Pick<Settings, "get">;
91
+ }, runId: string): Promise<string | undefined>;
92
+ /** Keeps disk `diskId` as the one run `runId` mounts. */
93
+ export declare function keepRunDisk(store: {
94
+ settings: Pick<Settings, "put">;
95
+ }, runId: string, diskId: string): Promise<void>;
96
+ /** Forgets agent `agentId`'s disk `diskId`, only while the agent's stored disk is still that one: its next run that uses
97
+ * it makes a new one, and a disk stored since (a run's, after an earlier removal) is kept. */
98
+ export declare function forgetAgentDisk(store: {
99
+ settings: Pick<Settings, "get" | "remove">;
100
+ }, agentId: string, diskId: string): Promise<void>;
101
+ /** The settings key of this server's id. */
102
+ export declare const SERVER_ID_KEY = "server_id";
103
+ /** This server's id: 12 hex digits, made once and kept in its store (the first writer wins a race), so its agents' disk
104
+ * names stay the same across restarts and tell its disks from another server's on one Archil account. */
105
+ export declare function serverIdOf(store: {
106
+ settings: Pick<Settings, "putIfAbsent">;
107
+ }): Promise<string>;
108
+ /** The name of agent `agentId`'s own disk on server `serverId`: agentrun-<server id>-<part>, its part at most 48
109
+ * characters. Archil takes letters, digits, dashes and underscores. An id of those alone, at most 46 of them, is
110
+ * `i-<id>`; any other (a dot, or longer) is `h-<its first 21 such characters>-<24 hex digits of its SHA-256>`. The two
111
+ * forms start with different letters, so no id's name is another's. */
112
+ export declare function diskNameOf(serverId: string, agentId: string): string;
@@ -1,18 +1,104 @@
1
- /** The settings key the Archil disk's configuration lives under in store.settings. */
1
+ // Archil mode (Mode 2) as the owner configured it: the account key's region, the region's S3 URL and an optional pinned
2
+ // exec image (absent: DEFAULT_ARCHIL_EXEC_IMAGE), kept as one row in store.settings. The one kept credential is the account key (the file API, exec and the
3
+ // control plane), a sealed key (server-keys.ts) under the name below. No disk token is kept: a computer's mount
4
+ // credential is minted per run from the account key. Mode 2 = these settings present; absent, the server is in Mode 1 (a
5
+ // local folder). The owner sets them through the Archil routes (archil-routes.ts), or the operator in the server's
6
+ // environment (ARCHIL_SETTINGS_ENV), which wins over a saved row as ARCHIL_API_KEY wins over the saved key, and is never
7
+ // written to the store: unset again, the saved row (or Mode 1) is back.
8
+ //
9
+ // There is no server-wide disk: every agent has its own (agentDiskOf), made on its first run that needs it, and a run's
10
+ // launch may name another (a disk per customer: run-launch.ts archilDisk). A row saved before that still names a
11
+ // `diskId`: it is dropped on read, and no agent uses that disk.
12
+ import { createHash, randomBytes } from "node:crypto";
13
+ import { envValue } from "./key-meta.js";
14
+ import { pinnedImage } from "./workspace/archil-disk.js";
15
+ /** The settings key the Archil configuration lives under in store.settings. */
2
16
  export const ARCHIL_SETTINGS_KEY = "archil";
3
17
  /** The sealed-key row of the Archil account key (the file API and exec), saved through server-keys.ts. Named *_ROW: a
4
18
  * constant named like a key holding a string reads as a literal credential to the source export. */
5
19
  export const ARCHIL_API_KEY_ROW = "archil.api_key";
6
- /** The Archil settings the owner saved, or undefined when none is (Mode 1). A row that is not the expected shape reads as
7
- * undefined, never a half-configured Mode 2. */
8
- export async function loadArchilSettings(store) {
20
+ /** The exec image a Mode 2 server runs commands in when the owner saved none: Docker's official
21
+ * `buildpack-deps:trixie-scm` (Debian 13 with git 2.47.3, GNU coreutils, perl-base, grep, sed, mawk, diffutils and
22
+ * findutils; no ripgrep), pinned to the multi-arch index digest Docker Hub served for that tag on 2026-11-11. Archil's
23
+ * own default exec image has git 2.34.1, and a shell under a bash policy runs git only at 2.43 or later (bash-read-only.ts
24
+ * POLICY_GIT_FLOOR), so a read-only agent there would get no git. Its git was read from the top layer's
25
+ * /var/lib/dpkg/status for amd64 and arm64 alike (`git 1:2.47.3-0+deb13u1`). To move it, read the tag's index digest
26
+ * again (an anonymous pull token from auth.docker.io for `repository:library/buildpack-deps:pull`, then a HEAD of
27
+ * registry-1.docker.io/v2/library/buildpack-deps/manifests/trixie-scm accepting an OCI index: its
28
+ * `docker-content-digest`), check the git its layers hold, and put it here. An image the owner saved replaces it. */
29
+ export const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d673fdb65371de9f88bdd32c4e30152fe692b35604aef5c0b3c0e6da10";
30
+ /** The environment variable that sets each field, for a server whose operator sets Mode 2 where it is started (a headless
31
+ * deploy, where no owner's session can save it). The region and S3 URL are both set or neither; the image is optional. */
32
+ export const ARCHIL_SETTINGS_ENV = { region: "AGENTRUN_ARCHIL_REGION", s3Url: "AGENTRUN_ARCHIL_S3_URL", image: "AGENTRUN_ARCHIL_IMAGE" };
33
+ const REQUIRED = ["region", "s3Url"];
34
+ /** The Archil settings in the server's environment are not whole or not right: the start stops, in these words. */
35
+ export class ArchilSettingsEnvInvalid extends Error {
36
+ name = "ArchilSettingsEnvInvalid";
37
+ }
38
+ const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
39
+ /** What is wrong with each settings field given, by the one rule the PUT and the environment share: a region, an https
40
+ * S3 URL, and an image, when given, pinned by digest. Empty when every field is right. */
41
+ export function archilSettingsIssues(given) {
42
+ const issues = [];
43
+ if (!nonEmpty(given.region))
44
+ issues.push({ field: "region", reason: "required", message: "region is the account key's Archil region, a non-empty string" });
45
+ if (!nonEmpty(given.s3Url) || !URL.canParse(given.s3Url) || new URL(given.s3Url).protocol !== "https:")
46
+ issues.push({ field: "s3Url", reason: "invalid", message: "s3Url is the region's S3 endpoint, an https URL" });
47
+ if (given.image !== undefined) {
48
+ try {
49
+ pinnedImage({ baseImage: given.image });
50
+ }
51
+ catch {
52
+ issues.push({ field: "image", reason: "invalid", message: "image is pinned by digest: <name>@sha256:<64 hex>" });
53
+ }
54
+ }
55
+ return issues;
56
+ }
57
+ /** The settings of fields archilSettingsIssues found right. */
58
+ export const archilSettingsOf = (given) => ({
59
+ region: given.region.trim(), s3Url: given.s3Url,
60
+ ...(given.image !== undefined ? { image: given.image } : {}),
61
+ });
62
+ /** The Archil settings the server's environment sets, or undefined when it sets none of ARCHIL_SETTINGS_ENV. One required
63
+ * variable without the other, or a value the PUT would refuse, is ArchilSettingsEnvInvalid naming each variable, never a
64
+ * half-configured Mode 2. The environment is passed in: process.env is never read here. */
65
+ export function archilSettingsFromEnv(env) {
66
+ const given = {};
67
+ for (const [field, name] of Object.entries(ARCHIL_SETTINGS_ENV)) {
68
+ const value = envValue(env, name);
69
+ if (value !== undefined)
70
+ given[field] = value.trim();
71
+ }
72
+ const set = Object.keys(given);
73
+ if (set.length === 0)
74
+ return undefined;
75
+ const missing = REQUIRED.filter((field) => given[field] === undefined).map((field) => ARCHIL_SETTINGS_ENV[field]);
76
+ const named = set.map((field) => ARCHIL_SETTINGS_ENV[field]);
77
+ if (missing.length)
78
+ throw new ArchilSettingsEnvInvalid(`This server is started with ${named.join(", ")} but not ${missing.join(", ")}: set ${REQUIRED.map((field) => ARCHIL_SETTINGS_ENV[field]).join(" and ")} together to keep run folders on Archil (Mode 2), or none of them.`);
79
+ const issues = archilSettingsIssues(given);
80
+ if (issues.length)
81
+ throw new ArchilSettingsEnvInvalid(`This server's Archil settings in its environment are not right: ${issues.map((issue) => issue.message.replace(/^\w+/, ARCHIL_SETTINGS_ENV[issue.field])).join("; ")}.`);
82
+ return archilSettingsOf(given);
83
+ }
84
+ /** The Archil settings in force, or undefined when there are none (Mode 1): the server's environment's (`env`), else the
85
+ * row the owner saved. A row that is not the expected shape reads as undefined, never a half-configured Mode 2; a field
86
+ * it no longer keeps (an old row's `diskId`) is dropped. */
87
+ export async function loadArchilSettings(store, env = {}) {
88
+ const fromEnv = archilSettingsFromEnv(env);
89
+ if (fromEnv !== undefined)
90
+ return fromEnv;
9
91
  const read = await store.settings.get(ARCHIL_SETTINGS_KEY);
10
- return isArchilSettings(read) ? read : undefined;
92
+ if (typeof read !== "object" || read === null)
93
+ return undefined;
94
+ const { region, s3Url, image } = read;
95
+ if (typeof region !== "string" || typeof s3Url !== "string" || (image !== undefined && typeof image !== "string"))
96
+ return undefined;
97
+ return { region, s3Url, ...(image !== undefined ? { image } : {}) };
11
98
  }
12
99
  /** Saves the Archil settings (Mode 2), replacing any kept. */
13
100
  export async function saveArchilSettings(store, settings) {
14
101
  await store.settings.put(ARCHIL_SETTINGS_KEY, {
15
- diskId: settings.diskId,
16
102
  region: settings.region,
17
103
  s3Url: settings.s3Url,
18
104
  ...(settings.image !== undefined ? { image: settings.image } : {}),
@@ -22,13 +108,63 @@ export async function saveArchilSettings(store, settings) {
22
108
  export async function clearArchilSettings(store) {
23
109
  await store.settings.remove(ARCHIL_SETTINGS_KEY);
24
110
  }
25
- /** Whether the server is in Mode 2 (the Archil disk is configured). */
26
- export async function inArchilMode(store) {
27
- return (await loadArchilSettings(store)) !== undefined;
111
+ /** Whether the server is in Mode 2 (the Archil settings are set, in `env` or saved). */
112
+ export async function inArchilMode(store, env = {}) {
113
+ return (await loadArchilSettings(store, env)) !== undefined;
114
+ }
115
+ // ---- the agent's own disk -----------------------------------------------------------------------------------------
116
+ /** An Archil disk id as Archil's API returns and addresses them: dsk-<16 hex digits>. */
117
+ export const ARCHIL_DISK_ID = /^dsk-[0-9a-f]{16}$/;
118
+ /** The settings key agent `agentId`'s disk is stored under. */
119
+ export const agentDiskKey = (agentId) => `${ARCHIL_SETTINGS_KEY}.agent.${agentId}`;
120
+ /** The disk stored on agent `agentId`, or undefined when it has none yet (made on its first run that uses it). */
121
+ export async function agentDiskOf(store, agentId) {
122
+ const read = await store.settings.get(agentDiskKey(agentId));
123
+ const row = typeof read === "object" && read !== null ? read : {};
124
+ if (typeof row.diskId !== "string" || !ARCHIL_DISK_ID.test(row.diskId))
125
+ return undefined;
126
+ return { diskId: row.diskId, ...(row.removing === true ? { removing: true } : {}), ...(row.pending === true ? { pending: true } : {}) };
127
+ }
128
+ /** Stores `disk` on agent `agentId`, as removing when it says so. */
129
+ export async function storeAgentDisk(store, agentId, disk) {
130
+ await store.settings.put(agentDiskKey(agentId), { diskId: disk.diskId, ...(disk.removing ? { removing: true } : {}), ...(disk.pending ? { pending: true } : {}) });
131
+ }
132
+ /** The settings key of the agent disk run `runId` first resolved to (its launch record is written once, before any disk). */
133
+ export const runDiskKey = (runId) => `${ARCHIL_SETTINGS_KEY}.run.${runId}`;
134
+ /** The agent disk run `runId` first resolved to, or undefined when none is kept: a later claim of the same run (a reopened
135
+ * one) uses that disk or is refused, never another. */
136
+ export async function runDiskKept(store, runId) {
137
+ const read = await store.settings.get(runDiskKey(runId));
138
+ const id = typeof read === "object" && read !== null ? read.diskId : undefined;
139
+ return typeof id === "string" && ARCHIL_DISK_ID.test(id) ? id : undefined;
140
+ }
141
+ /** Keeps disk `diskId` as the one run `runId` mounts. */
142
+ export async function keepRunDisk(store, runId, diskId) {
143
+ await store.settings.put(runDiskKey(runId), { diskId });
144
+ }
145
+ /** Forgets agent `agentId`'s disk `diskId`, only while the agent's stored disk is still that one: its next run that uses
146
+ * it makes a new one, and a disk stored since (a run's, after an earlier removal) is kept. */
147
+ export async function forgetAgentDisk(store, agentId, diskId) {
148
+ if ((await agentDiskOf(store, agentId))?.diskId === diskId)
149
+ await store.settings.remove(agentDiskKey(agentId));
150
+ }
151
+ /** The settings key of this server's id. */
152
+ export const SERVER_ID_KEY = "server_id";
153
+ /** This server's id: 12 hex digits, made once and kept in its store (the first writer wins a race), so its agents' disk
154
+ * names stay the same across restarts and tell its disks from another server's on one Archil account. */
155
+ export async function serverIdOf(store) {
156
+ const kept = await store.settings.putIfAbsent(SERVER_ID_KEY, { v: 1, id: randomBytes(6).toString("hex") });
157
+ const id = kept?.id;
158
+ if (typeof id !== "string" || !/^[0-9a-f]{12}$/.test(id))
159
+ throw new Error(`this server's store keeps a ${SERVER_ID_KEY} that does not read as one`);
160
+ return id;
28
161
  }
29
- function isArchilSettings(value) {
30
- if (typeof value !== "object" || value === null)
31
- return false;
32
- const v = value;
33
- return typeof v.diskId === "string" && typeof v.region === "string" && typeof v.s3Url === "string" && (v.image === undefined || typeof v.image === "string");
162
+ /** The name of agent `agentId`'s own disk on server `serverId`: agentrun-<server id>-<part>, its part at most 48
163
+ * characters. Archil takes letters, digits, dashes and underscores. An id of those alone, at most 46 of them, is
164
+ * `i-<id>`; any other (a dot, or longer) is `h-<its first 21 such characters>-<24 hex digits of its SHA-256>`. The two
165
+ * forms start with different letters, so no id's name is another's. */
166
+ export function diskNameOf(serverId, agentId) {
167
+ const plain = /^[A-Za-z0-9_-]{1,46}$/.test(agentId);
168
+ const part = plain ? `i-${agentId}` : `h-${agentId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 21)}-${createHash("sha256").update(agentId).digest("hex").slice(0, 24)}`;
169
+ return `agentrun-${serverId}-${part}`;
34
170
  }