@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,7 +1,9 @@
1
1
  // The Archil claim step: once per claim in Mode 2, before the run's loop starts, the claim's Archil disk is made from the
2
- // server's Archil settings (archil-settings.ts, the store's one settings row) and its keys come from the store's
2
+ // server's Archil settings (archil-settings.ts, the store's one settings row) on the run's own disk (run-disk.ts: the one
3
+ // its launch names, else its agent's, made on its first run), and its keys come from the store's
3
4
  // sealed_keys rows under archil-settings.ts's names, opened with the runner's seal key. A saved exec image must be pinned
4
- // by digest (`<name>@sha256:<64 hex>`): any other refuses the claim before a key is read.
5
+ // by digest (`<name>@sha256:<64 hex>`): any other refuses the claim before a key is read. With none saved, the exec runs
6
+ // in DEFAULT_ARCHIL_EXEC_IMAGE, never Archil's own default (its git is older than a bash policy's floor).
5
7
  //
6
8
  // One row: "archil.api_key", the account API key the disk's file API and serverless exec take (archil-disk.ts asks for
7
9
  // it on every call, and gets it from this step's memory). The disk token a computer's mount takes
@@ -14,11 +16,12 @@
14
16
  // refused. A row that is missing, or that does not open under the seal key (sealed under another key, or for another
15
17
  // row), refuses in words that name the row and never hold a value. Nothing here reads the environment: the settings,
16
18
  // the store's sealed keys and the seal key are handed in.
17
- import { ARCHIL_API_KEY_ROW } from "../archil-settings.js";
19
+ import { ARCHIL_API_KEY_ROW, DEFAULT_ARCHIL_EXEC_IMAGE } from "../archil-settings.js";
18
20
  import { archilApiKey } from "./archil-key.js";
19
21
  import { archilDisk, pinnedImage } from "./archil-disk.js";
20
22
  import { mintMountToken, nicknameOf, removeMountToken, removeOlderMountTokens, removeRunMountTokens } from "./archil-mount-credential.js";
21
23
  import { COMPUTER_LIFETIME_MS } from "./computer-deps.js";
24
+ import { runDiskOf } from "./run-disk.js";
22
25
  export { ARCHIL_API_KEY_ROW };
23
26
  /** A claim this step refused, in words a person reads: no Archil call was made. */
24
27
  export class ArchilClaimRefused extends Error {
@@ -35,11 +38,11 @@ const LOST_MINT_REREAD_MS = 2_000;
35
38
  export async function archilClaim(options) {
36
39
  const { settings, sealKey } = options;
37
40
  if (settings === undefined) {
38
- throw new ArchilClaimRefused("This server's Archil disk is not set up (its disk, region and S3 endpoint): Mode 2 keeps a run's folder on it, so the run can't start.");
41
+ throw new ArchilClaimRefused("This server's Archil disk is not set up (its key's region and S3 endpoint): Mode 2 keeps a run's folder on an Archil disk, so the run can't start.");
39
42
  }
40
43
  let image;
41
44
  try {
42
- image = settings.image === undefined ? undefined : pinnedImage({ baseImage: settings.image });
45
+ image = pinnedImage({ baseImage: settings.image ?? DEFAULT_ARCHIL_EXEC_IMAGE });
43
46
  }
44
47
  catch (error) {
45
48
  throw new ArchilClaimRefused(`This server's Archil exec image ${JSON.stringify(settings.image)} can't be used: ${error.message}`, { cause: error });
@@ -50,10 +53,21 @@ export async function archilClaim(options) {
50
53
  let released = false;
51
54
  const apiKey = (await archilApiKey({ ...(options.env ? { env: options.env } : {}), keys: options.keys, sealKey })).value;
52
55
  held.add(apiKey);
56
+ // The run's disk first (run-disk.ts): its launch's, else its agent's, made now when it has none; every call below is on
57
+ // it alone, the run's mount credential minted, revoked and reclaimed there.
58
+ const control = { region: settings.region, key: () => apiKey, ...(options.mount?.baseUrl ? { baseUrl: options.mount.baseUrl } : {}), ...(options.mount?.fetch ? { fetch: options.mount.fetch } : {}) };
59
+ let chosen;
60
+ try {
61
+ chosen = await runDiskOf({ store: options.run.store, agentId: options.run.agentId, ...(options.mount ? { runId: options.mount.runId } : {}), ...(options.run.launch ? { launch: options.run.launch } : {}), control, signal: options.signal });
62
+ }
63
+ catch (error) {
64
+ held.clear();
65
+ throw error;
66
+ }
53
67
  let disk;
54
68
  try {
55
69
  disk = (options.makeDisk ?? archilDisk)({
56
- disk: settings.diskId,
70
+ disk: chosen.diskId,
57
71
  region: settings.region,
58
72
  s3BaseUrl: settings.s3Url,
59
73
  key: () => {
@@ -67,13 +81,7 @@ export async function archilClaim(options) {
67
81
  held.clear();
68
82
  throw new ArchilClaimRefused(`This server's Archil settings can't make its disk: ${error.message}`, { cause: error });
69
83
  }
70
- const credentialOptions = {
71
- disk: settings.diskId,
72
- region: settings.region,
73
- key: () => apiKey,
74
- ...(options.mount?.baseUrl ? { baseUrl: options.mount.baseUrl } : {}),
75
- ...(options.mount?.fetch ? { fetch: options.mount.fetch } : {}),
76
- };
84
+ const credentialOptions = { ...control, disk: chosen.diskId };
77
85
  let minted;
78
86
  /** A mint was asked for since the last revoke: its user may stand at Archil though no answer said so. */
79
87
  let asked = false;
@@ -121,6 +129,7 @@ export async function archilClaim(options) {
121
129
  lost();
122
130
  return {
123
131
  disk,
132
+ diskKind: chosen.kind,
124
133
  region: settings.region,
125
134
  image,
126
135
  secrets: held,
@@ -37,14 +37,23 @@ export type ArchilImage = {
37
37
  };
38
38
  /** `image` checked as an ArchilImage pinned by digest, and copied: only its own fields, nothing else it carries. */
39
39
  export declare function pinnedImage(image: unknown): ArchilImage;
40
+ /** An exec's network: its egress denied, so the container reaches nothing but the disk's own mounts. */
41
+ export type ArchilExecNetwork = {
42
+ readonly egress: {
43
+ readonly default: "deny";
44
+ };
45
+ };
46
+ /** The one network an exec is given: no egress. */
47
+ export declare const DENY_EGRESS: ArchilExecNetwork;
40
48
  /** One exec: `command` runs with each folder of `mounts` (mount name → folder of the disk), and nothing else of the
41
49
  * disk, at /mnt/archil/<name>, each held for the line (waiting up to queueMs for another client's hold), in `image` or
42
- * Archil's default. */
50
+ * Archil's default, with `network` (absent: Archil's default, egress open). */
43
51
  export type ArchilExecRequest = {
44
52
  readonly mounts: Readonly<Record<string, string>>;
45
53
  readonly queueMs: number;
46
54
  readonly command: string;
47
55
  readonly image?: ArchilImage;
56
+ readonly network?: ArchilExecNetwork;
48
57
  };
49
58
  export type ArchilExecAnswer = {
50
59
  readonly exitCode: number;
@@ -14,6 +14,8 @@ export function pinnedImage(image) {
14
14
  return refuse();
15
15
  return { imageId, digest };
16
16
  }
17
+ /** The one network an exec is given: no egress. */
18
+ export const DENY_EGRESS = Object.freeze({ egress: Object.freeze({ default: "deny" }) });
17
19
  const LOOPBACK = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule names loopback hosts to allow plain http only to them, in tests
18
20
  /** The S3 endpoint, checked: https on an Archil host whose name carries the region ("aws-us-east-1" → "…​.us-east-1.aws.
19
21
  * …archil.com"), or, when the control plane is a loopback one too (a test), http(s) to this machine's loopback. */
@@ -244,6 +246,8 @@ class SdkArchilDisk {
244
246
  }
245
247
  const answer = await client.exec({
246
248
  ...(image === undefined ? {} : "baseImage" in image ? { baseImage: image.baseImage } : { imageId: image.imageId }),
249
+ // The network's one field, picked by name, as the image's are.
250
+ ...(request.network === undefined ? {} : { network: { egress: { default: request.network.egress.default } } }),
247
251
  command: request.command,
248
252
  disks: Object.fromEntries(Object.entries(request.mounts).map(([name, subdirectory]) => [name, { disk: this.id, subdirectory, queueMs: request.queueMs }])),
249
253
  });
@@ -0,0 +1,49 @@
1
+ import { type ArchilControlOptions } from "./archil-mount-credential.js";
2
+ /** A call to Archil's disks refused or not answered, in words with no secret in them. */
3
+ export declare class ArchilDiskError extends Error {
4
+ name: string;
5
+ readonly status: number | undefined;
6
+ readonly code: string | undefined;
7
+ constructor(message: string, status?: number, code?: string);
8
+ }
9
+ /** The plan's disk limit reached: `limit` when Archil's words say how many disks it allows. */
10
+ export declare class ArchilDiskLimit extends ArchilDiskError {
11
+ name: string;
12
+ readonly limit: number | undefined;
13
+ constructor(message: string, limit: number | undefined);
14
+ }
15
+ /** A disk as Archil reads it back. */
16
+ export interface ArchilDiskInfo {
17
+ readonly id: string;
18
+ readonly name: string;
19
+ readonly region: string;
20
+ readonly status: string;
21
+ }
22
+ type Context = {
23
+ readonly signal?: AbortSignal;
24
+ };
25
+ /** Disk `id` as Archil reads it, or undefined when the account has none of that id (404). */
26
+ export declare function getDisk(options: ArchilControlOptions, id: string, context?: Context): Promise<ArchilDiskInfo | undefined>;
27
+ /** The account's disk named `name`, or undefined when there is none. */
28
+ export declare function diskNamed(options: ArchilControlOptions, name: string, context?: Context): Promise<ArchilDiskInfo | undefined>;
29
+ /** How many disks a plan allows, when Archil's words for its refusal say. */
30
+ export declare function limitOf(words: string): number | undefined;
31
+ /** Makes the disk `name` (Archil-managed storage, the control plane's region), or finds it when it is there already: its
32
+ * id, and whether this call made it. A disk this call made has its default token user removed before it is answered; a
33
+ * disk found there already has every token user that is not a run's removed (an earlier call's default token, when its
34
+ * removal failed). The plan's limit is an ArchilDiskLimit. */
35
+ export declare function ensureDisk(options: ArchilControlOptions, name: string, context?: Context): Promise<{
36
+ readonly id: string;
37
+ readonly made: boolean;
38
+ }>;
39
+ /** Waits until disk `id` reads `available` (a disk just made reads `creating` for a while), up to `timeoutMs`. */
40
+ export declare function availableDisk(options: ArchilControlOptions, id: string, { timeoutMs, everyMs, signal }?: {
41
+ timeoutMs?: number;
42
+ everyMs?: number;
43
+ signal?: AbortSignal;
44
+ }): Promise<ArchilDiskInfo>;
45
+ /** Removes disk `id` and everything on it. Idempotent: one already gone (404) is removed. */
46
+ export declare function deleteDisk(options: ArchilControlOptions, id: string, context?: Context): Promise<void>;
47
+ /** One page of the account's disks, at most one: what the Archil settings' test reads to know the key works. */
48
+ export declare function listOneDisk(options: ArchilControlOptions, context?: Context): Promise<number>;
49
+ export {};
@@ -0,0 +1,185 @@
1
+ // The account's disks at Archil's control plane: what makes each agent's own disk, reads a disk a launch names, and
2
+ // removes an agent's own disk. With the account API key as `Authorization: Bearer <key>`, on the region's control plane
3
+ // (archil-mount-credential.ts controlOf), as Archil's API (`@archildata/api-types` 0.0.81) has them:
4
+ // - create: POST {control}/api/disks {"name"}: Archil-managed storage (no mounts), in the control plane's region. 201
5
+ // made it; 200 when a disk of that name is there already with this configuration (idempotent); 409 when one
6
+ // of that name is there with another, which is found by listing that name; 403 `disk_limit_reached` when the
7
+ // plan's per-region disk limit is reached (`organization_plan_required`: a free organization makes none). A
8
+ // made disk comes with a default token user, which is removed at once: no standing token is kept anywhere. A
9
+ // disk found there already (200, 409) loses every token user that is not a run's, so a default token whose
10
+ // removal failed on an earlier try is removed on the next.
11
+ // - read: GET {control}/api/disks/{id}: its name, region and status; 404 when the account has none of that id.
12
+ // - list: GET {control}/api/disks?name=<name>: the disks of that exact name.
13
+ // - remove: DELETE {control}/api/disks/{id}: the disk and everything on it. Idempotent: a 404 is already gone.
14
+ // Neither the key nor a token is ever in an error: an error carries the status and Archil's own words, scrubbed.
15
+ import { controlOf, errorOf, isRunNickname, listTokenUsers, scrub } from "./archil-mount-credential.js";
16
+ /** A call to Archil's disks refused or not answered, in words with no secret in them. */
17
+ export class ArchilDiskError extends Error {
18
+ name = "ArchilDiskError";
19
+ status;
20
+ code;
21
+ constructor(message, status, code) {
22
+ super(message);
23
+ this.status = status;
24
+ this.code = code;
25
+ }
26
+ }
27
+ /** The plan's disk limit reached: `limit` when Archil's words say how many disks it allows. */
28
+ export class ArchilDiskLimit extends ArchilDiskError {
29
+ name = "ArchilDiskLimit";
30
+ limit;
31
+ constructor(message, limit) {
32
+ super(message, 403, "disk_limit_reached");
33
+ this.limit = limit;
34
+ }
35
+ }
36
+ /** One call to the control plane: its answer, or an ArchilDiskError naming `what` when it could not be reached. */
37
+ async function call(options, method, path, what, context, body) {
38
+ const key = await options.key();
39
+ try {
40
+ const response = await (options.fetch ?? fetch)(`${controlOf(options)}${path}`, {
41
+ method,
42
+ headers: { Authorization: `Bearer ${key}`, ...(body !== undefined ? { "Content-Type": "application/json" } : {}) },
43
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
44
+ redirect: "error",
45
+ ...(context.signal ? { signal: context.signal } : {}),
46
+ });
47
+ return { response, key };
48
+ }
49
+ catch (error) {
50
+ throw new ArchilDiskError(`Archil's control plane could not be reached to ${what}: ${scrub(error instanceof Error ? error.message : String(error), [key])}`);
51
+ }
52
+ }
53
+ /** A refusal as an ArchilDiskError, Archil's words and code in it. */
54
+ async function refused(response, key, what) {
55
+ const { words, code } = await errorOf(response, [key]);
56
+ return new ArchilDiskError(`Archil refused to ${what} (${response.status}): ${words}`, response.status, code);
57
+ }
58
+ const infoOf = (value) => {
59
+ const disk = value;
60
+ return typeof disk?.id === "string" ? { id: disk.id, name: typeof disk.name === "string" ? disk.name : "", region: typeof disk.region === "string" ? disk.region : "", status: typeof disk.status === "string" ? disk.status : "" } : undefined;
61
+ };
62
+ /** Disk `id` as Archil reads it, or undefined when the account has none of that id (404). */
63
+ export async function getDisk(options, id, context = {}) {
64
+ const { response, key } = await call(options, "GET", `/api/disks/${encodeURIComponent(id)}`, `read the disk ${id}`, context);
65
+ if (response.status === 404) {
66
+ await response.body?.cancel().catch(() => undefined);
67
+ return undefined;
68
+ }
69
+ if (!response.ok)
70
+ throw await refused(response, key, `read the disk ${id}`);
71
+ const disk = infoOf((await response.json().catch(() => undefined))?.data);
72
+ if (disk === undefined)
73
+ throw new ArchilDiskError(`Archil answered the read of the disk ${id} with no disk`);
74
+ return disk;
75
+ }
76
+ /** The account's disk named `name`, or undefined when there is none. */
77
+ export async function diskNamed(options, name, context = {}) {
78
+ const { response, key } = await call(options, "GET", `/api/disks?name=${encodeURIComponent(name)}`, `find the disk ${name}`, context);
79
+ if (!response.ok)
80
+ throw await refused(response, key, `find the disk ${name}`);
81
+ const data = (await response.json().catch(() => undefined))?.data;
82
+ return (Array.isArray(data) ? data : []).map(infoOf).find((disk) => disk?.name === name);
83
+ }
84
+ /** How many disks a plan allows, when Archil's words for its refusal say. */
85
+ export function limitOf(words) {
86
+ const match = /\b(?:limit(?:\s+of)?|allows?|maximum(?:\s+of)?|max(?:imum)?)\s+(\d+)\b/i.exec(words) ?? /\b(\d+)\s+disks?\b/i.exec(words);
87
+ return match ? Number(match[1]) : undefined;
88
+ }
89
+ /** Removes token user `identifier` of disk `diskId`. Idempotent: one already gone (404) is removed. */
90
+ async function removeToken(options, diskId, identifier, what, context) {
91
+ const removed = await call(options, "DELETE", `/api/disks/${encodeURIComponent(diskId)}/users/token?identifier=${encodeURIComponent(identifier)}`, what, context);
92
+ if (!removed.response.ok && removed.response.status !== 404)
93
+ throw await refused(removed.response, removed.key, what);
94
+ await removed.response.body?.cancel().catch(() => undefined);
95
+ }
96
+ /** Removes every token user of disk `diskId` that is not a run's (isRunNickname): the default one Archil made with it,
97
+ * left standing when an earlier call's removal failed or its answer was lost. A run's token is the run's to revoke. */
98
+ async function removeStrayTokens(options, diskId, name, context) {
99
+ const what = `remove the disk ${name}'s default token`;
100
+ let users;
101
+ try {
102
+ users = await listTokenUsers({ ...options, disk: diskId }, context);
103
+ }
104
+ catch (error) {
105
+ throw new ArchilDiskError(`Archil's token users of the disk ${name} could not be read to ${what}: ${error.message}`, error.status);
106
+ }
107
+ for (const user of users)
108
+ if (!isRunNickname(user.nickname))
109
+ await removeToken(options, diskId, user.identifier, what, context);
110
+ }
111
+ /** Makes the disk `name` (Archil-managed storage, the control plane's region), or finds it when it is there already: its
112
+ * id, and whether this call made it. A disk this call made has its default token user removed before it is answered; a
113
+ * disk found there already has every token user that is not a run's removed (an earlier call's default token, when its
114
+ * removal failed). The plan's limit is an ArchilDiskLimit. */
115
+ export async function ensureDisk(options, name, context = {}) {
116
+ const { response, key } = await call(options, "POST", "/api/disks", `make the disk ${name}`, context, { name });
117
+ if (response.status === 409) {
118
+ await response.body?.cancel().catch(() => undefined);
119
+ const there = await diskNamed(options, name, context);
120
+ if (there === undefined)
121
+ throw new ArchilDiskError(`Archil said a disk named ${name} is there with another configuration, and no disk of that name is listed`, 409);
122
+ await removeStrayTokens(options, there.id, name, context);
123
+ return { id: there.id, made: false };
124
+ }
125
+ if (response.status === 403) {
126
+ const { words, code } = await errorOf(response, [key]);
127
+ if (code === "disk_limit_reached")
128
+ throw new ArchilDiskLimit(`Archil refused to make the disk ${name}: ${words}`, limitOf(words));
129
+ throw new ArchilDiskError(`Archil refused to make the disk ${name} (403): ${words}`, 403, code);
130
+ }
131
+ if (!response.ok)
132
+ throw await refused(response, key, `make the disk ${name}`);
133
+ const data = (await response.json().catch(() => undefined))?.data;
134
+ if (typeof data?.diskId !== "string" || data.diskId === "")
135
+ throw new ArchilDiskError(`Archil answered the making of the disk ${name} with no disk id`);
136
+ const made = response.status === 201;
137
+ if (made) {
138
+ // The default token user Archil makes with a disk: no one holds it, and none is kept standing.
139
+ const users = Array.isArray(data.authorizedUsers) ? data.authorizedUsers : [];
140
+ for (const user of users) {
141
+ if (user?.type !== "token" || typeof user.identifier !== "string")
142
+ continue;
143
+ await removeToken(options, data.diskId, user.identifier, `remove the new disk ${name}'s default token`, context);
144
+ }
145
+ }
146
+ else {
147
+ await removeStrayTokens(options, data.diskId, name, context);
148
+ }
149
+ return { id: data.diskId, made };
150
+ }
151
+ /** Waits until disk `id` reads `available` (a disk just made reads `creating` for a while), up to `timeoutMs`. */
152
+ export async function availableDisk(options, id, { timeoutMs = 120_000, everyMs = 1_000, signal } = {}) {
153
+ const until = Date.now() + timeoutMs;
154
+ for (;;) {
155
+ // Each read is bounded by the time left, so a stalled response cannot outwait the deadline.
156
+ const left = AbortSignal.timeout(Math.max(1, until - Date.now()));
157
+ const disk = await getDisk(options, id, { signal: signal ? AbortSignal.any([signal, left]) : left });
158
+ if (disk === undefined)
159
+ throw new ArchilDiskError(`Archil has no disk ${id} in ${options.region}`, 404);
160
+ if (disk.status === "available")
161
+ return disk;
162
+ if (disk.status === "failed" || disk.status === "deleting" || disk.status === "deleted")
163
+ throw new ArchilDiskError(`the disk ${id} is ${disk.status} at Archil`);
164
+ if (Date.now() >= until)
165
+ throw new ArchilDiskError(`the disk ${id} was still ${disk.status || "not ready"} at Archil after ${Math.round(timeoutMs / 1000)} s`);
166
+ await new Promise((done) => setTimeout(done, everyMs));
167
+ }
168
+ }
169
+ /** Removes disk `id` and everything on it. Idempotent: one already gone (404) is removed. */
170
+ export async function deleteDisk(options, id, context = {}) {
171
+ const { response, key } = await call(options, "DELETE", `/api/disks/${encodeURIComponent(id)}`, `remove the disk ${id}`, context);
172
+ if (response.ok || response.status === 404) {
173
+ await response.body?.cancel().catch(() => undefined);
174
+ return;
175
+ }
176
+ throw await refused(response, key, `remove the disk ${id}`);
177
+ }
178
+ /** One page of the account's disks, at most one: what the Archil settings' test reads to know the key works. */
179
+ export async function listOneDisk(options, context = {}) {
180
+ const { response, key } = await call(options, "GET", "/api/disks?short=true&limit=1", "list the account's disks", context);
181
+ if (!response.ok)
182
+ throw await refused(response, key, "list the account's disks");
183
+ const body = (await response.json().catch(() => undefined));
184
+ return typeof body?.total === "number" ? body.total : Array.isArray(body?.data) ? body.data.length : 0;
185
+ }
@@ -1,5 +1,5 @@
1
- import type { ArchilDisk, ArchilImage } from "./archil-disk.js";
2
- import { type ExecResult } from "./workspace.js";
1
+ import type { ArchilDisk, ArchilExecNetwork, ArchilImage } from "./archil-disk.js";
2
+ import { type ExecResult, WorkspaceError } from "./workspace.js";
3
3
  /** Archil cuts an exec call at 300 s. */
4
4
  export declare const MAX_EXEC_MS = 300000;
5
5
  /** The longest deadline a command may ask for: 5 s of the 300 are the line's own (its walk, its drains, its answer).
@@ -38,7 +38,17 @@ export type ExecJob = {
38
38
  readonly maxOutput: number;
39
39
  readonly queueMs: number;
40
40
  readonly image?: ArchilImage;
41
+ /** The container's network (DENY_EGRESS); absent, Archil's default, egress open. */
42
+ readonly network?: ArchilExecNetwork;
41
43
  };
44
+ /** Archil refused an exec's network policy (a plan without network policies): nothing ran. The words are Archil's. */
45
+ export declare class ArchilEgressRefused extends WorkspaceError {
46
+ name: string;
47
+ }
48
+ /** Whether `error`, from an exec that asked for a network policy, is Archil refusing the policy itself: a 402 or a 403
49
+ * whose code or words name the network (`network_plan_required`). Archil's exact answer is not measured; a 403 that
50
+ * names no network (a refused key, the exec allowance spent) stays what it is. */
51
+ export declare function refusesNetwork(error: unknown): boolean;
42
52
  /** The shell line one exec call runs (POSIX sh; GNU timeout, perl, mkfifo, head and mktemp in the image). `mark` is
43
53
  * this call's marker: the line's answer is found by it, whatever else the call's stdout holds. */
44
54
  export declare function execLine(job: ExecJob, mark: string): string;
@@ -1,7 +1,6 @@
1
1
  // Workspace exec on an Archil disk: one serverless exec call (archil-disk.ts) that mounts the workspace's folder and
2
- // its exec spill folder, and nothing else of the disk. Taken from pi-transport's box/archil-exec.ts, which has no
3
- // caller: the call, its 300 s cut, the hold on the folder with a queue, and the mapping of the exit and of the deadline.
4
- // The rest (boxes, records, sweeps) is not.
2
+ // its exec spill folder, and nothing else of the disk: the call, its 300 s cut, the hold on the folder with a queue, and
3
+ // the mapping of the exit and of the deadline.
5
4
  //
6
5
  // Archil runs one shell line in a fresh container with two folders of the disk, each a mount's `subdirectory`, held for
7
6
  // the line (no other client writes in them meanwhile; a second one waits up to queueMs):
@@ -55,6 +54,17 @@ export const quote = (text) => `'${text.replace(/'/g, `'\\''`)}'`;
55
54
  export const spillName = () => `x${randomBytes(8).toString("hex")}`;
56
55
  /** The keys of one exec's files, in spill folder `folder`. */
57
56
  export const spillKeys = (folder, name) => ({ in: `${folder}/${name}.in`, out: `${folder}/${name}.out`, err: `${folder}/${name}.err` });
57
+ /** Archil refused an exec's network policy (a plan without network policies): nothing ran. The words are Archil's. */
58
+ export class ArchilEgressRefused extends WorkspaceError {
59
+ name = "ArchilEgressRefused";
60
+ }
61
+ /** Whether `error`, from an exec that asked for a network policy, is Archil refusing the policy itself: a 402 or a 403
62
+ * whose code or words name the network (`network_plan_required`). Archil's exact answer is not measured; a 403 that
63
+ * names no network (a refused key, the exec allowance spent) stays what it is. */
64
+ export function refusesNetwork(error) {
65
+ const { status, code, message } = (error ?? {});
66
+ return (status === 402 || status === 403) && /network|egress/i.test(`${typeof code === "string" ? code : ""} ${typeof message === "string" ? message : ""}`);
67
+ }
58
68
  /** The program's runner: stderr to the file in its first argument, the program run, its raw wait status written to the
59
69
  * file in its second, and the same exit a shell would give. No single quote in it: it rides in one. */
60
70
  const RUNNER = [
@@ -158,6 +168,7 @@ export async function archilExec(disk, job) {
158
168
  const request = {
159
169
  mounts: { [EXEC_MOUNT]: job.root, [SPILL_MOUNT]: job.spill }, queueMs: job.queueMs, command: execLine(job, mark),
160
170
  ...(job.image === undefined ? {} : { image: job.image }),
171
+ ...(job.network === undefined ? {} : { network: job.network }),
161
172
  };
162
173
  answer = await Promise.race([disk.exec(request), gaveUp]);
163
174
  }
@@ -165,6 +176,10 @@ export async function archilExec(disk, job) {
165
176
  if (error instanceof WorkspaceError)
166
177
  throw error;
167
178
  const status = error?.status;
179
+ if (job.network !== undefined && refusesNetwork(error)) {
180
+ const code = error.code;
181
+ throw new ArchilEgressRefused("REFUSED", `Archil refused the exec's network policy (${status}${typeof code === "string" ? ` ${code}` : ""}): ${describe(error)}`, { path, cause: error });
182
+ }
168
183
  // A 400 is a mount Archil refused (a folder missing, or held by another client past the queue's wait): its own
169
184
  // words say which.
170
185
  const why = status === 400 ? "Archil refused to mount the exec's folders"
@@ -1,9 +1,8 @@
1
1
  /** The control plane of each Archil region, as Archil's SDK (`disk` 1.12.0, src/regions.ts) names them. */
2
2
  export declare const ARCHIL_CONTROL_URLS: Readonly<Record<string, string>>;
3
- export interface ArchilMountCredentialOptions {
4
- /** The disk's id, dsk-<16 hex digits>. */
5
- readonly disk: string;
6
- /** Its region: it names the control plane. */
3
+ /** Archil's control plane, for the account's calls (archil-disks.ts) as for a disk's. */
4
+ export interface ArchilControlOptions {
5
+ /** The region: it names the control plane. */
7
6
  readonly region: string;
8
7
  /** The account API key, asked for on each call. */
9
8
  readonly key: () => string | Promise<string>;
@@ -12,6 +11,10 @@ export interface ArchilMountCredentialOptions {
12
11
  /** The fetch to call it with (default the global one). */
13
12
  readonly fetch?: typeof fetch;
14
13
  }
14
+ export interface ArchilMountCredentialOptions extends ArchilControlOptions {
15
+ /** The disk's id, dsk-<16 hex digits>. */
16
+ readonly disk: string;
17
+ }
15
18
  /** A minted mount credential: the token a computer's mount takes, and the identifier it is removed by. */
16
19
  export interface MountCredential {
17
20
  readonly token: string;
@@ -23,11 +26,24 @@ export declare class ArchilMountCredentialError extends Error {
23
26
  readonly status: number | undefined;
24
27
  constructor(message: string, status?: number);
25
28
  }
29
+ /** The control plane's base URL: the region's, or the loopback one given. */
30
+ export declare function controlOf(options: ArchilControlOptions): string;
26
31
  /** A ttl as Archil reads it (a Go duration): whole seconds, at least one, at most Archil's 365 days. */
27
32
  export declare const ttlOf: (ms: number) => string;
28
33
  /** The nickname of run `run`'s token user under claim epoch `epoch`: the run and the epoch, so a later claim finds an
29
34
  * earlier one's (its runner died before removing it). */
30
35
  export declare const nicknameOf: (run: string, epoch: number) => string;
36
+ /** Whether a token user's nickname is a run's (nicknameOf): every token this server mints is one. */
37
+ export declare const isRunNickname: (nickname: unknown) => boolean;
38
+ /** `text` with each secret replaced. */
39
+ export declare const scrub: (text: string, secrets: readonly string[]) => string;
40
+ /** Archil's words for a failed call, from its error envelope ({error, code}), cut short and scrubbed. */
41
+ export declare function wordsOf(response: Response, secrets: readonly string[]): Promise<string>;
42
+ /** Archil's error envelope ({error, code}): its words, cut short and scrubbed, and its code when it gives one. */
43
+ export declare function errorOf(response: Response, secrets: readonly string[]): Promise<{
44
+ words: string;
45
+ code?: string;
46
+ }>;
31
47
  /** Mints the run's mount credential on the disk: a token user named `nickname`, which Archil ends after `ttlMs`. */
32
48
  export declare function mintMountToken(options: ArchilMountCredentialOptions, run: {
33
49
  readonly nickname: string;
@@ -28,7 +28,7 @@ export class ArchilMountCredentialError extends Error {
28
28
  }
29
29
  }
30
30
  /** The control plane's base URL: the region's, or the loopback one given. */
31
- function controlOf(options) {
31
+ export function controlOf(options) {
32
32
  if (options.baseUrl !== undefined) {
33
33
  const url = new URL(options.baseUrl);
34
34
  if (url.protocol !== "https:" && !(url.protocol === "http:" && LOOPBACK.test(url.hostname)))
@@ -54,20 +54,29 @@ function claimOfNickname(nickname) {
54
54
  const match = /^agentrun:(.+):(0|[1-9][0-9]*)$/.exec(nickname);
55
55
  return match ? { run: match[1], epoch: Number(match[2]) } : undefined;
56
56
  }
57
+ /** Whether a token user's nickname is a run's (nicknameOf): every token this server mints is one. */
58
+ export const isRunNickname = (nickname) => claimOfNickname(nickname) !== undefined;
57
59
  /** `text` with each secret replaced. */
58
- const scrub = (text, secrets) => secrets.filter((one) => one.length >= 4).reduce((out, one) => out.split(one).join("[redacted]"), text);
60
+ export const scrub = (text, secrets) => secrets.filter((one) => one.length >= 4).reduce((out, one) => out.split(one).join("[redacted]"), text);
59
61
  /** Archil's words for a failed call, from its error envelope ({error, code}), cut short and scrubbed. */
60
- async function wordsOf(response, secrets) {
62
+ export async function wordsOf(response, secrets) {
63
+ return (await errorOf(response, secrets)).words;
64
+ }
65
+ /** Archil's error envelope ({error, code}): its words, cut short and scrubbed, and its code when it gives one. */
66
+ export async function errorOf(response, secrets) {
61
67
  const text = await response.text().catch(() => "");
62
68
  let said = text;
69
+ let code;
63
70
  try {
64
71
  const body = JSON.parse(text);
65
72
  said = typeof body.error === "string" ? body.error : typeof body.message === "string" ? body.message : text;
73
+ if (typeof body.code === "string")
74
+ code = body.code;
66
75
  }
67
76
  catch {
68
77
  // not JSON: its text
69
78
  }
70
- return scrub(said.trim().slice(0, 300), secrets);
79
+ return { words: scrub(said.trim().slice(0, 300), secrets), ...(code !== undefined ? { code } : {}) };
71
80
  }
72
81
  /** Mints the run's mount credential on the disk: a token user named `nickname`, which Archil ends after `ttlMs`. */
73
82
  export async function mintMountToken(options, run) {
@@ -9,8 +9,8 @@ export type ArchilWorkspaceOptions = {
9
9
  readonly queueMs?: number;
10
10
  /** The image every exec runs in, the same for every workspace serve makes (a run's or a learning folder's), pinned by
11
11
  * digest (an image given without one is refused): a public image `<name>@sha256:…`, or one built through Archil's
12
- * images API with its digest. With none, Archil's default exec image, whose git (2.34.1, measured) is older than
13
- * learning's floor. */
12
+ * images API with its digest. With none, Archil's default exec image, whose git (2.34.1, measured) is older than a
13
+ * bash policy's floor; serve's claim always names one (archil-settings.ts DEFAULT_ARCHIL_EXEC_IMAGE). */
14
14
  readonly image?: ArchilImage;
15
15
  /** Told when an exec's cleanup leaves spill files behind (a failed delete, tried twice), with the keys and why; the
16
16
  * exec's own result stands. Default: a process warning. */
@@ -1,5 +1,5 @@
1
- import { pinnedImage } from "./archil-disk.js";
2
- import { archilExec, COMMAND_MAX_MS, DEFAULT_QUEUE_MS, MAX_EXEC_MS, spillKeys, spillName } from "./archil-exec.js";
1
+ import { DENY_EGRESS, pinnedImage } from "./archil-disk.js";
2
+ import { ArchilEgressRefused, archilExec, COMMAND_MAX_MS, DEFAULT_QUEUE_MS, MAX_EXEC_MS, spillKeys, spillName } from "./archil-exec.js";
3
3
  import { attachedWorkspace, checkReadBack, noProcesses } from "./attach.js";
4
4
  import { globRegex } from "./glob.js";
5
5
  import { relativeSegments } from "./paths.js";
@@ -64,6 +64,8 @@ class ArchilWorkspace {
64
64
  #mountToken;
65
65
  /** The last exec asked for, settled either way: the next exec, and every write, starts after it. */
66
66
  #execs = Promise.resolve();
67
+ /** Why Archil refused an exec's network policy, once it has: an exec asking for no network then runs with it open. */
68
+ #egressOpen;
67
69
  #rooted = false;
68
70
  constructor(disk, root, options = {}) {
69
71
  if (relativeSegments(root).length === 0)
@@ -551,13 +553,31 @@ class ArchilWorkspace {
551
553
  const stdin = options.stdin;
552
554
  await this.#settle("", () => this.#disk.putObject(files.in, stdin)).catch((error) => { throw failed(error, "", "exec's stdin"); });
553
555
  }
554
- const read = await archilExec(this.#disk, {
556
+ const job = {
555
557
  root: this.#root, spill: this.#spill, name, cwd, argv, env, timeoutMs, maxOutput: readBack, queueMs: this.#queueMs,
556
558
  stdin: options.stdin !== undefined, ...(this.#image === undefined ? {} : { image: this.#image }),
557
- });
559
+ };
560
+ const deny = options.network === "deny";
561
+ let read;
562
+ if (deny && this.#egressOpen === undefined) {
563
+ try {
564
+ read = await archilExec(this.#disk, { ...job, network: DENY_EGRESS });
565
+ }
566
+ catch (error) {
567
+ // Archil's plan takes no network policy: nothing ran, so the command runs again with the network open.
568
+ if (!(error instanceof ArchilEgressRefused))
569
+ throw error;
570
+ this.#egressOpen = error.message;
571
+ // The caller gave up while Archil answered: the command it no longer waits for is not started now.
572
+ if (signal?.aborted)
573
+ throw abortError(signal);
574
+ }
575
+ }
576
+ read ??= await archilExec(this.#disk, job);
558
577
  // Archil answers once the command has ended: each stream once, whole. An error the caller's callback throws is
559
578
  // not the call's.
560
- const stderr = Buffer.from(read.stderr, "utf8");
579
+ const warning = deny && this.#egressOpen !== undefined ? `agentrun: this command ran with the network open. ${this.#egressOpen}\n` : "";
580
+ const stderr = Buffer.from(`${warning}${read.stderr}`, "utf8");
561
581
  for (const chunk of [{ stream: "stdout", data: read.stdout }, { stream: "stderr", data: stderr }]) {
562
582
  try {
563
583
  options.onOutput?.(chunk);
@@ -339,6 +339,8 @@ export function attachedWorkspace(base, computer, options = {}) {
339
339
  async exec(argv, options) {
340
340
  if (options.stdin !== undefined)
341
341
  throw new WorkspaceError("REFUSED", "exec with stdin runs on the run's folder, not in a computer: a computer's exec takes no stdin");
342
+ if (options.network !== undefined)
343
+ throw new WorkspaceError("REFUSED", "a command in a computer has the computer's own network: its exec takes no network of its own, and nothing ran");
342
344
  const { timeoutMs, signal } = options;
343
345
  if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
344
346
  throw new WorkspaceError("REFUSED", "exec's timeoutMs is a number above 0");