@parcha/agentrun-serve 0.1.0-beta.35 → 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 (372) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +260 -168
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-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/box-image.d.ts +1 -97
  19. package/dist/box-image.js +4 -284
  20. package/dist/box-paths.d.ts +2 -7
  21. package/dist/box-paths.js +7 -13
  22. package/dist/box-settings.d.ts +0 -11
  23. package/dist/box-settings.js +4 -29
  24. package/dist/browser-commands.js +1 -1
  25. package/dist/browser-computer.d.ts +47 -3
  26. package/dist/browser-computer.js +286 -18
  27. package/dist/browser-person.d.ts +19 -2
  28. package/dist/browser-person.js +55 -6
  29. package/dist/browser-wait-ended.d.ts +23 -0
  30. package/dist/browser-wait-ended.js +42 -0
  31. package/dist/cap.d.ts +13 -41
  32. package/dist/cap.js +24 -73
  33. package/dist/cli.js +4 -22
  34. package/dist/computer-routes.d.ts +1 -4
  35. package/dist/computer-routes.js +3 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +38 -1
  38. package/dist/computer-view.d.ts +11 -2
  39. package/dist/computer-view.js +2 -1
  40. package/dist/computers.d.ts +48 -7
  41. package/dist/computers.js +100 -23
  42. package/dist/console/assets/index-BI4Byidu.js +550 -0
  43. package/dist/console/assets/index-C19gUF2n.css +1 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/docker-daemon.d.ts +2 -2
  46. package/dist/docker-daemon.js +2 -2
  47. package/dist/errors.js +5 -5
  48. package/dist/faux-computers.js +4 -0
  49. package/dist/files.d.ts +1 -9
  50. package/dist/files.js +1 -9
  51. package/dist/github.d.ts +22 -2
  52. package/dist/github.js +42 -8
  53. package/dist/gpu-words.d.ts +14 -0
  54. package/dist/gpu-words.js +21 -0
  55. package/dist/graph-view.d.ts +2 -0
  56. package/dist/graph-view.js +25 -1
  57. package/dist/handed-values.d.ts +1 -1
  58. package/dist/handed-values.js +1 -1
  59. package/dist/harness-install.d.ts +60 -3
  60. package/dist/harness-install.js +322 -34
  61. package/dist/harness.js +1 -1
  62. package/dist/host-tools.d.ts +8 -9
  63. package/dist/host-tools.js +7 -7
  64. package/dist/index.d.ts +1 -3
  65. package/dist/index.js +1 -2
  66. package/dist/key-refusal.d.ts +1 -1
  67. package/dist/key-refusal.js +2 -2
  68. package/dist/learn/check.d.ts +7 -1
  69. package/dist/learn/check.js +123 -5
  70. package/dist/learn/commit.d.ts +40 -6
  71. package/dist/learn/commit.js +164 -20
  72. package/dist/learn/folder.d.ts +5 -0
  73. package/dist/learn/folder.js +33 -0
  74. package/dist/learn/grade.d.ts +18 -1
  75. package/dist/learn/grade.js +86 -16
  76. package/dist/learn/index.d.ts +1 -1
  77. package/dist/learn/index.js +1 -1
  78. package/dist/learn/learning.sh +12 -1
  79. package/dist/learn/notes.d.ts +3 -0
  80. package/dist/learn/notes.js +3 -0
  81. package/dist/learn/reflect.d.ts +5 -2
  82. package/dist/learn/reflect.js +43 -29
  83. package/dist/learn/skills.d.ts +4 -0
  84. package/dist/learn/skills.js +7 -0
  85. package/dist/learned-nodes.d.ts +6 -2
  86. package/dist/learned-workflow.d.ts +19 -9
  87. package/dist/learned-workflow.js +62 -34
  88. package/dist/learning-cost.d.ts +79 -0
  89. package/dist/learning-cost.js +69 -0
  90. package/dist/learning-routes.d.ts +8 -3
  91. package/dist/learning-routes.js +9 -6
  92. package/dist/learning-words.d.ts +3 -0
  93. package/dist/learning-words.js +6 -2
  94. package/dist/learning.d.ts +13 -6
  95. package/dist/learning.js +4 -2
  96. package/dist/mcp-probe.d.ts +8 -1
  97. package/dist/mcp-probe.js +62 -20
  98. package/dist/mcp-secret-writes.js +4 -0
  99. package/dist/mcp-servers-store.js +8 -3
  100. package/dist/model.d.ts +5 -5
  101. package/dist/model.js +6 -6
  102. package/dist/openapi.d.ts +2 -0
  103. package/dist/openapi.js +204 -47
  104. package/dist/owner.d.ts +0 -1
  105. package/dist/owner.js +0 -2
  106. package/dist/paid-calls.js +1 -1
  107. package/dist/place-offers.d.ts +97 -0
  108. package/dist/place-offers.js +206 -0
  109. package/dist/place.d.ts +9 -13
  110. package/dist/place.js +22 -32
  111. package/dist/port-models.d.ts +2 -1
  112. package/dist/port-models.js +5 -3
  113. package/dist/print.d.ts +1 -8
  114. package/dist/print.js +1 -14
  115. package/dist/propose.d.ts +1 -0
  116. package/dist/propose.js +25 -10
  117. package/dist/run-cut.d.ts +5 -0
  118. package/dist/run-cut.js +19 -0
  119. package/dist/run-db.js +3 -3
  120. package/dist/run-launch.d.ts +14 -1
  121. package/dist/run-launch.js +7 -2
  122. package/dist/run-learning-served.d.ts +1 -1
  123. package/dist/run-manifest.d.ts +2 -2
  124. package/dist/run-manifest.js +2 -2
  125. package/dist/run-secrets.js +3 -3
  126. package/dist/run-timeline-served.js +56 -44
  127. package/dist/run-view.d.ts +5 -2
  128. package/dist/run-view.js +4 -3
  129. package/dist/runnable.d.ts +2 -2
  130. package/dist/runnable.js +6 -2
  131. package/dist/runner/adapter-loop.d.ts +16 -1
  132. package/dist/runner/adapter-loop.js +131 -30
  133. package/dist/runner/adapter-run-spec.d.ts +25 -4
  134. package/dist/runner/adapter-run-spec.js +103 -24
  135. package/dist/runner/adapters/pi.d.ts +11 -3
  136. package/dist/runner/adapters/pi.js +35 -12
  137. package/dist/runner/beside.js +6 -2
  138. package/dist/runner/cli-run-spec.d.ts +7 -0
  139. package/dist/runner/cli-run-spec.js +92 -38
  140. package/dist/runner/commands.d.ts +5 -1
  141. package/dist/runner/commands.js +3 -3
  142. package/dist/runner/conformance/harness.d.ts +0 -1
  143. package/dist/runner/conformance/harness.js +8 -5
  144. package/dist/runner/github-app.js +2 -2
  145. package/dist/runner/harness-loops.js +1 -1
  146. package/dist/runner/journal-kinds.d.ts +15 -5
  147. package/dist/runner/journal-kinds.js +6 -1
  148. package/dist/runner/learning-end.d.ts +15 -0
  149. package/dist/runner/learning-end.js +26 -5
  150. package/dist/runner/learning-factory.js +6 -2
  151. package/dist/runner/learning-loop.d.ts +73 -1
  152. package/dist/runner/learning-loop.js +203 -18
  153. package/dist/runner/learning-seed.d.ts +2 -0
  154. package/dist/runner/learning-seed.js +1 -1
  155. package/dist/runner/loop-contract.d.ts +8 -0
  156. package/dist/runner/loop-contract.js +6 -0
  157. package/dist/runner/loop.d.ts +5 -1
  158. package/dist/runner/loop.js +20 -0
  159. package/dist/runner/main.js +12 -2
  160. package/dist/runner/mcp-claim.d.ts +4 -0
  161. package/dist/runner/mcp-claim.js +29 -1
  162. package/dist/runner/mcp-github.d.ts +4 -2
  163. package/dist/runner/mcp-github.js +0 -7
  164. package/dist/runner/mcp-run.d.ts +2 -0
  165. package/dist/runner/mcp-run.js +1 -0
  166. package/dist/runner/metrics.d.ts +4 -0
  167. package/dist/runner/metrics.js +9 -0
  168. package/dist/runner/model-route.d.ts +3 -0
  169. package/dist/runner/model-route.js +5 -2
  170. package/dist/runner/pr-checkout.d.ts +59 -0
  171. package/dist/runner/pr-checkout.js +176 -0
  172. package/dist/runner/reflect-hook.d.ts +1 -0
  173. package/dist/runner/reflect-hook.js +3 -3
  174. package/dist/runner/runner.js +47 -12
  175. package/dist/runner/spec-holds.d.ts +8 -3
  176. package/dist/runner/spec-holds.js +12 -10
  177. package/dist/runner/store-port.d.ts +4 -1
  178. package/dist/runner/store-secrets.js +17 -1
  179. package/dist/runner/subagent.d.ts +44 -0
  180. package/dist/runner/subagent.js +188 -0
  181. package/dist/runner/workflow-host.d.ts +18 -2
  182. package/dist/runner/workflow-host.js +23 -3
  183. package/dist/runner/workflow-loop.d.ts +5 -2
  184. package/dist/runner/workflow-loop.js +9 -8
  185. package/dist/runner/workflow-spec.d.ts +26 -14
  186. package/dist/runner/workflow-spec.js +97 -30
  187. package/dist/runs-over-store.d.ts +11 -6
  188. package/dist/runs-over-store.js +111 -24
  189. package/dist/sealing.js +1 -2
  190. package/dist/secret-cut.d.ts +1 -1
  191. package/dist/secret-cut.js +1 -1
  192. package/dist/server.d.ts +32 -49
  193. package/dist/server.js +249 -199
  194. package/dist/store/agent-body.d.ts +9 -2
  195. package/dist/store/agent-body.js +16 -8
  196. package/dist/store/deadline.js +9 -5
  197. package/dist/store/index.d.ts +3 -3
  198. package/dist/store/index.js +2 -2
  199. package/dist/store/journal/storage.js +2 -1
  200. package/dist/store/postgres/connection.js +9 -4
  201. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  202. package/dist/store/schema.d.ts +2 -1
  203. package/dist/store/schema.js +11 -8
  204. package/dist/store/seal.d.ts +13 -0
  205. package/dist/store/seal.js +19 -0
  206. package/dist/store/sqlite/connection.d.ts +5 -0
  207. package/dist/store/sqlite/connection.js +88 -47
  208. package/dist/store/sqlite/run-patch.d.ts +18 -2
  209. package/dist/store/sqlite/run-patch.js +31 -2
  210. package/dist/store/sqlite/store.js +65 -11
  211. package/dist/store/store.d.ts +62 -12
  212. package/dist/store/store.js +22 -1
  213. package/dist/store-reads/analytics.js +3 -2
  214. package/dist/store-reads/cap.d.ts +1 -3
  215. package/dist/store-reads/cap.js +8 -6
  216. package/dist/store-reads/decisions.d.ts +2 -2
  217. package/dist/store-reads/decisions.js +3 -6
  218. package/dist/store-reads/journal.js +45 -12
  219. package/dist/store-reads/learning.d.ts +15 -1
  220. package/dist/store-reads/learning.js +68 -10
  221. package/dist/store-reads/runs.d.ts +6 -4
  222. package/dist/store-reads/runs.js +17 -10
  223. package/dist/store-reads/stats.js +5 -1
  224. package/dist/store-view.js +45 -19
  225. package/dist/template-eval.js +2 -1
  226. package/dist/templates.d.ts +64 -0
  227. package/dist/templates.js +101 -16
  228. package/dist/timeline/timeline.d.ts +3 -1
  229. package/dist/timeline/timeline.js +19 -4
  230. package/dist/tool-blurbs.js +1 -0
  231. package/dist/tool-budget.d.ts +8 -0
  232. package/dist/tool-budget.js +7 -1
  233. package/dist/tool-gate.d.ts +7 -1
  234. package/dist/tool-gate.js +7 -2
  235. package/dist/tool-plane.d.ts +33 -19
  236. package/dist/tool-plane.js +64 -27
  237. package/dist/tools.d.ts +18 -34
  238. package/dist/tools.js +104 -70
  239. package/dist/trigger-signatures.d.ts +1 -0
  240. package/dist/trigger-signatures.js +3 -1
  241. package/dist/triggers.d.ts +3 -3
  242. package/dist/triggers.js +2 -2
  243. package/dist/turn-end.d.ts +0 -3
  244. package/dist/turn-end.js +0 -3
  245. package/dist/usage-lines.d.ts +1 -1
  246. package/dist/validate.d.ts +6 -0
  247. package/dist/validate.js +30 -3
  248. package/dist/webhooks.d.ts +2 -1
  249. package/dist/webhooks.js +5 -2
  250. package/dist/workflow/decision-recovery.d.ts +23 -0
  251. package/dist/workflow/decision-recovery.js +80 -0
  252. package/dist/workflow/decisions.d.ts +134 -0
  253. package/dist/workflow/decisions.js +46 -0
  254. package/dist/workflow/host-session.d.ts +5 -0
  255. package/dist/workflow/host-session.js +85 -0
  256. package/dist/workflow/host-tools.d.ts +3 -0
  257. package/dist/workflow/host-tools.js +3 -0
  258. package/dist/workflow/node-runner.d.ts +112 -0
  259. package/dist/workflow/node-runner.js +270 -0
  260. package/dist/workflow/node.d.ts +88 -0
  261. package/dist/workflow/node.js +99 -0
  262. package/dist/workflow/operator-error.d.ts +4 -0
  263. package/dist/workflow/operator-error.js +4 -0
  264. package/dist/workflow/pi-versions.d.ts +9 -0
  265. package/dist/workflow/pi-versions.js +8 -0
  266. package/dist/workflow/readers.d.ts +36 -0
  267. package/dist/workflow/readers.js +145 -0
  268. package/dist/workflow/record-file.d.ts +10 -0
  269. package/dist/workflow/record-file.js +56 -0
  270. package/dist/workflow/record-tool.d.ts +76 -0
  271. package/dist/workflow/record-tool.js +126 -0
  272. package/dist/workflow/record.d.ts +151 -0
  273. package/dist/workflow/record.js +401 -0
  274. package/dist/workflow/run-error.d.ts +16 -0
  275. package/dist/workflow/run-error.js +26 -0
  276. package/dist/workflow/runner.d.ts +6 -0
  277. package/dist/workflow/runner.js +240 -0
  278. package/dist/workflow/store.d.ts +23 -0
  279. package/dist/workflow/store.js +242 -0
  280. package/dist/workflow/task.d.ts +133 -0
  281. package/dist/workflow/task.js +411 -0
  282. package/dist/workflow/thinking.d.ts +3 -0
  283. package/dist/workflow/thinking.js +7 -0
  284. package/dist/workflow/tool-context.d.ts +21 -0
  285. package/dist/workflow/tool-context.js +13 -0
  286. package/dist/workflow/types.d.ts +126 -0
  287. package/dist/workflow/types.js +1 -0
  288. package/dist/workflow/wal.d.ts +11 -0
  289. package/dist/workflow/wal.js +106 -0
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/agent-computer.d.ts +137 -0
  292. package/dist/workspace/agent-computer.js +292 -0
  293. package/dist/workspace/archil-claim.d.ts +11 -0
  294. package/dist/workspace/archil-claim.js +18 -10
  295. package/dist/workspace/archil-disks.d.ts +49 -0
  296. package/dist/workspace/archil-disks.js +185 -0
  297. package/dist/workspace/archil-exec.js +2 -3
  298. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  299. package/dist/workspace/archil-mount-credential.js +13 -4
  300. package/dist/workspace/computer-deps.d.ts +16 -8
  301. package/dist/workspace/computer-deps.js +18 -7
  302. package/dist/workspace/computer-for-claim.d.ts +42 -6
  303. package/dist/workspace/computer-for-claim.js +209 -9
  304. package/dist/workspace/computer-janitor.d.ts +3 -2
  305. package/dist/workspace/computer-janitor.js +43 -9
  306. package/dist/workspace/computer-ledger.d.ts +3 -1
  307. package/dist/workspace/computer-ledger.js +7 -0
  308. package/dist/workspace/index.d.ts +3 -2
  309. package/dist/workspace/index.js +1 -0
  310. package/dist/workspace/resolve-computer.d.ts +42 -11
  311. package/dist/workspace/resolve-computer.js +65 -13
  312. package/dist/workspace/run-disk.d.ts +34 -0
  313. package/dist/workspace/run-disk.js +91 -0
  314. package/dist/workspace/run-tools.d.ts +4 -4
  315. package/dist/workspace/run-tools.js +8 -6
  316. package/dist/workspace/server-run-workspace.d.ts +3 -2
  317. package/dist/workspace/server-run-workspace.js +17 -4
  318. package/dist/workspace.js +1 -1
  319. package/package.json +10 -15
  320. package/templates/README.md +9 -6
  321. package/templates/code-review/agent.md +27 -11
  322. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  323. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  324. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  325. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  326. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  327. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  328. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  329. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  330. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  331. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  332. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  333. package/templates/code-review/evals/re-review/prompt.md +1 -1
  334. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  335. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  336. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  337. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  338. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  339. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  340. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  341. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  342. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  343. package/templates/code-review/findings.schema.json +131 -27
  344. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  345. package/templates/code-review/skills/review/DEEP.md +130 -0
  346. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  347. package/templates/code-review/skills/review/SKILL.md +104 -154
  348. package/dist/box/record.d.ts +0 -6
  349. package/dist/box/record.js +0 -41
  350. package/dist/box/sweep.d.ts +0 -53
  351. package/dist/box/sweep.js +0 -193
  352. package/dist/box-egress-vm.d.ts +0 -118
  353. package/dist/box-egress-vm.js +0 -354
  354. package/dist/box-egress.d.ts +0 -105
  355. package/dist/box-egress.js +0 -256
  356. package/dist/box-relay-vm.d.ts +0 -84
  357. package/dist/box-relay-vm.js +0 -437
  358. package/dist/box-relay.d.ts +0 -36
  359. package/dist/box-relay.js +0 -207
  360. package/dist/boxes.d.ts +0 -109
  361. package/dist/boxes.js +0 -249
  362. package/dist/budget.d.ts +0 -71
  363. package/dist/budget.js +0 -199
  364. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  365. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  366. package/dist/daytona-api.d.ts +0 -10
  367. package/dist/daytona-api.js +0 -20
  368. package/dist/egress-proxy.d.ts +0 -45
  369. package/dist/egress-proxy.js +0 -416
  370. package/dist/egress-table.d.ts +0 -24
  371. package/dist/egress-table.js +0 -165
  372. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -1,5 +1,7 @@
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. */
@@ -15,17 +17,39 @@ export declare const ARCHIL_API_KEY_ROW = "archil.api_key";
15
17
  * `docker-content-digest`), check the git its layers hold, and put it here. An image the owner saved replaces it. */
16
18
  export declare const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d673fdb65371de9f88bdd32c4e30152fe692b35604aef5c0b3c0e6da10";
17
19
  export interface ArchilSettings {
18
- readonly diskId: string;
20
+ /** The account key's region: the control plane every disk is made, read and minted on. */
19
21
  readonly region: string;
22
+ /** The region's S3 endpoint (the disks' file API). */
20
23
  readonly s3Url: string;
21
24
  /** A pinned image for the disk's exec, when the owner set one; absent, DEFAULT_ARCHIL_EXEC_IMAGE. */
22
25
  readonly image?: string;
23
26
  }
24
- /** The Archil settings the owner saved, or undefined when none is (Mode 1). A row that is not the expected shape reads as
25
- * 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. */
26
50
  export declare function loadArchilSettings(store: {
27
51
  settings: Pick<Settings, "get">;
28
- }): Promise<ArchilSettings | undefined>;
52
+ }, env?: KeyEnv): Promise<ArchilSettings | undefined>;
29
53
  /** Saves the Archil settings (Mode 2), replacing any kept. */
30
54
  export declare function saveArchilSettings(store: {
31
55
  settings: Pick<Settings, "put">;
@@ -34,7 +58,55 @@ export declare function saveArchilSettings(store: {
34
58
  export declare function clearArchilSettings(store: {
35
59
  settings: Pick<Settings, "remove">;
36
60
  }): Promise<void>;
37
- /** 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). */
38
62
  export declare function inArchilMode(store: {
39
63
  settings: Pick<Settings, "get">;
40
- }): 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,4 +1,18 @@
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. */
@@ -13,16 +27,78 @@ export const ARCHIL_API_KEY_ROW = "archil.api_key";
13
27
  * registry-1.docker.io/v2/library/buildpack-deps/manifests/trixie-scm accepting an OCI index: its
14
28
  * `docker-content-digest`), check the git its layers hold, and put it here. An image the owner saved replaces it. */
15
29
  export const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d673fdb65371de9f88bdd32c4e30152fe692b35604aef5c0b3c0e6da10";
16
- /** The Archil settings the owner saved, or undefined when none is (Mode 1). A row that is not the expected shape reads as
17
- * undefined, never a half-configured Mode 2. */
18
- export async function loadArchilSettings(store) {
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;
19
91
  const read = await store.settings.get(ARCHIL_SETTINGS_KEY);
20
- 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 } : {}) };
21
98
  }
22
99
  /** Saves the Archil settings (Mode 2), replacing any kept. */
23
100
  export async function saveArchilSettings(store, settings) {
24
101
  await store.settings.put(ARCHIL_SETTINGS_KEY, {
25
- diskId: settings.diskId,
26
102
  region: settings.region,
27
103
  s3Url: settings.s3Url,
28
104
  ...(settings.image !== undefined ? { image: settings.image } : {}),
@@ -32,13 +108,63 @@ export async function saveArchilSettings(store, settings) {
32
108
  export async function clearArchilSettings(store) {
33
109
  await store.settings.remove(ARCHIL_SETTINGS_KEY);
34
110
  }
35
- /** Whether the server is in Mode 2 (the Archil disk is configured). */
36
- export async function inArchilMode(store) {
37
- 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;
38
161
  }
39
- function isArchilSettings(value) {
40
- if (typeof value !== "object" || value === null)
41
- return false;
42
- const v = value;
43
- 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}`;
44
170
  }
@@ -0,0 +1,15 @@
1
+ import type { ProviderStreams } from "@earendil-works/pi-ai";
2
+ /** Why `image` (pi-ai's image part) cannot be attached to a model request; undefined when it can. */
3
+ export declare function unattachable(image: {
4
+ readonly data?: unknown;
5
+ readonly mimeType?: unknown;
6
+ }): string | undefined;
7
+ /** The text a model is sent in place of an image that cannot be attached. */
8
+ export declare const notAttached: (why: string) => string;
9
+ /** `context` with each image part that cannot be attached (unattachable) replaced by a text saying why; `context` itself
10
+ * when every image can be. */
11
+ export declare function attachableImages<C extends {
12
+ readonly messages: readonly unknown[];
13
+ }>(context: C): C;
14
+ /** `api` whose every request is sent with its images checked (attachableImages). */
15
+ export declare function attachingImages(api: ProviderStreams): ProviderStreams;
@@ -0,0 +1,59 @@
1
+ import { imageSizeOf } from "@parcha/agentrun-kernel/host";
2
+ /** The first bytes of each image type every provider takes, by its MIME type. */
3
+ const SIGNATURES = {
4
+ "image/png": (head) => head.length >= 8 && head.readUInt32BE(0) === 0x89504e47 && head.readUInt32BE(4) === 0x0d0a1a0a,
5
+ "image/jpeg": (head) => head.length >= 3 && head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff,
6
+ "image/gif": (head) => head.toString("latin1", 0, 4) === "GIF8",
7
+ "image/webp": (head) => head.toString("latin1", 0, 4) === "RIFF" && head.toString("latin1", 8, 12) === "WEBP",
8
+ };
9
+ const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
10
+ /** Why `image` (pi-ai's image part) cannot be attached to a model request; undefined when it can. */
11
+ export function unattachable(image) {
12
+ const { data, mimeType } = image;
13
+ if (typeof mimeType !== "string" || !Object.hasOwn(SIGNATURES, mimeType))
14
+ return `its type ${JSON.stringify(mimeType ?? null)} is not PNG, JPEG, GIF or WebP`;
15
+ if (typeof data !== "string" || data.length === 0)
16
+ return "it is empty";
17
+ if (data.length % 4 !== 0 || !BASE64.test(data))
18
+ return "its data is not base64";
19
+ if (!SIGNATURES[mimeType](Buffer.from(data.slice(0, 16), "base64")))
20
+ return `its bytes are not a ${mimeType}`;
21
+ if (!imageSizeOf(data))
22
+ return `its ${mimeType} header does not say its size`;
23
+ return undefined;
24
+ }
25
+ /** The text a model is sent in place of an image that cannot be attached. */
26
+ export const notAttached = (why) => `[the image could not be attached: ${why}]`;
27
+ /** `context` with each image part that cannot be attached (unattachable) replaced by a text saying why; `context` itself
28
+ * when every image can be. */
29
+ export function attachableImages(context) {
30
+ let changed = false;
31
+ const messages = context.messages.map((message) => {
32
+ const content = message.content;
33
+ if (!Array.isArray(content))
34
+ return message;
35
+ let replaced = false;
36
+ const parts = content.map((part) => {
37
+ if (!part || typeof part !== "object" || part.type !== "image")
38
+ return part;
39
+ const why = unattachable(part);
40
+ if (why === undefined)
41
+ return part;
42
+ replaced = true;
43
+ return { type: "text", text: notAttached(why) };
44
+ });
45
+ if (!replaced)
46
+ return message;
47
+ changed = true;
48
+ return { ...message, content: parts };
49
+ });
50
+ return changed ? { ...context, messages } : context;
51
+ }
52
+ /** `api` whose every request is sent with its images checked (attachableImages). */
53
+ export function attachingImages(api) {
54
+ return {
55
+ ...api,
56
+ stream: (model, context, options) => api.stream(model, attachableImages(context), options),
57
+ streamSimple: (model, context, options) => api.streamSimple(model, attachableImages(context), options),
58
+ };
59
+ }
@@ -1,6 +1,4 @@
1
- import type { Context } from "@earendil-works/chord";
2
1
  import { type ToolRegistration } from "@earendil-works/pi-durable";
3
- import type { BoxProvider } from "@parcha/pi-transport";
4
2
  /** The most background processes that run at once in one run's box. */
5
3
  export declare const BACKGROUND_MAX = 8;
6
4
  /** The most bytes of output one background process's log keeps: later output is dropped, and the process runs on. */
@@ -23,7 +21,3 @@ export declare const BACKGROUND_TOOLS: readonly ["bash_background", "bash_output
23
21
  export declare const SHELL_TOOLS: readonly string[];
24
22
  /** The background tools, each run on the environment its call gives (the box's, coding-tools.ts). */
25
23
  export declare const backgroundTools: () => ToolRegistration[];
26
- /** The run's end: every background process still running in run `runId`'s box (found by `label`) is sent TERM, then
27
- * KILL after 3 s, and marked as ended at the run's end, so its runner writes its exit code and its log is whole before
28
- * the box is pulled and destroyed. How many it ended; a run with no box ends none. */
29
- export declare function endBackground(boxes: BoxProvider, label: Record<string, string>, context: Context): Promise<number>;
@@ -386,31 +386,3 @@ const bashList = defineTool({
386
386
  });
387
387
  /** The background tools, each run on the environment its call gives (the box's, coding-tools.ts). */
388
388
  export const backgroundTools = () => [bashBackground, bashOutput, bashInput, bashSignal, bashList];
389
- /** The run's end: every background process still running in run `runId`'s box (found by `label`) is sent TERM, then
390
- * KILL after 3 s, and marked as ended at the run's end, so its runner writes its exit code and its log is whole before
391
- * the box is pulled and destroyed. How many it ended; a run with no box ends none. */
392
- export async function endBackground(boxes, label, context) {
393
- const { finish } = await import("@parcha/pi-transport");
394
- const listed = await boxes.list(label, context);
395
- if (!listed.ok)
396
- throw listed.error;
397
- let ended = 0;
398
- for (const ref of listed.value) {
399
- const attached = await boxes.attach(ref.id, context);
400
- if (!attached.ok)
401
- throw attached.error;
402
- if (!attached.value)
403
- continue;
404
- const started = await attached.value.exec(["sh", "-c", SCRIPT, "agentrun-background", BOX_WORK, "end"], { timeoutMs: 20_000 }, context);
405
- if (!started.ok)
406
- throw started.error;
407
- const done = await finish(started.value);
408
- if (!done.ok)
409
- throw done.error;
410
- const said = new TextDecoder().decode(done.value.stdout).trim();
411
- if (done.value.exitCode !== 0)
412
- throw new Error(`ending the box's background processes failed (exit code ${done.value.exitCode}): ${done.value.stderr.trim().slice(0, 300)}`);
413
- ended += Number(/^ended (\d+)/.exec(said)?.[1] ?? 0);
414
- }
415
- return ended;
416
- }
@@ -1,98 +1,2 @@
1
- import type { Context } from "@earendil-works/chord";
2
- import { type BoxOffer } from "./boxes.js";
3
- /** The setting that names another image for Docker boxes than this server's own. */
1
+ /** The setting that names another image for Docker computers than the computer package's own. */
4
2
  export declare const DOCKER_IMAGE_ENV = "AGENTRUN_DOCKER_IMAGE";
5
- /** What the default image has, in words. */
6
- export declare const RECIPE_HAS = "python, git, curl, node, npm, rg";
7
- /** The base the default image builds from: `python:3.12-slim`, pinned to the multi-arch index digest Docker Hub served
8
- * for that tag on 2026-11-03, so a build gets the same base wherever it runs. To move it, read the tag's index digest
9
- * again (an anonymous pull token from auth.docker.io for `repository:library/python:pull`, then a HEAD of
10
- * registry-1.docker.io/v2/library/python/manifests/3.12-slim accepting an OCI index or a manifest list: its
11
- * `docker-content-digest`), and put it here. The recipe's hash changes with it, and so does the image's tag
12
- * (DEFAULT_DOCKER_IMAGE), so every server builds the new one at its next start. */
13
- export declare const BOX_BASE = "python:3.12-slim@sha256:b18b261e1b4974b4f321451ad5251ded85abb22c2b8b262da527dda1d031ab30";
14
- /** The default image's recipe: a Dockerfile that needs no other file, written alone into a private context directory for
15
- * each build (buildContext). Its hash names the image. */
16
- export declare const BOX_RECIPE: string;
17
- /** The label the built image carries: its recipe's sha256. */
18
- export declare const RECIPE_LABEL = "agentrun.box-image";
19
- export declare const RECIPE_HASH: string;
20
- /** The default image: this server's own, built from BOX_RECIPE, its tag the recipe's hash. */
21
- export declare const DEFAULT_DOCKER_IMAGE: string;
22
- /** The image a Docker box starts from on a server or a run with `env`. */
23
- export declare const boxImageOf: (env: NodeJS.ProcessEnv) => string;
24
- /** Where the image's state is kept for the run's processes, in the data directory. */
25
- export declare const IMAGE_STATE_FILE = "box-image.json";
26
- /** How long the start's pull, or build, may take; past it, it is stopped and docker is unavailable. */
27
- export declare const PULL_TIMEOUT_MS: number;
28
- export declare const BUILD_TIMEOUT_MS: number;
29
- /** How long Docker may take to say whether it has the image. */
30
- export declare const INSPECT_TIMEOUT_MS = 5000;
31
- /** How long past the pull's deadline a run still waits on a file that says preparing: the server's own timer ends the
32
- * pull at the deadline, so only a server that is gone leaves the file saying preparing after it. */
33
- export declare const STALE_AFTER_MS = 30000;
34
- /** How long after a failed build or pull it is tried once more. */
35
- export declare const RETRY_AFTER_MS = 5000;
36
- /** How long the server's close waits for the image's last record to be saved, so a docker that hangs cannot hold it. */
37
- export declare const CLOSE_WAIT_MS = 5000;
38
- /** The image's state: `ready`; `preparing` while the server pulls it; `unavailable`, with why. */
39
- export type ImageState = {
40
- state: "ready";
41
- } | {
42
- state: "preparing";
43
- reason: string;
44
- } | {
45
- state: "unavailable";
46
- reason: string;
47
- };
48
- /** The file's record: the image, its state, and while it is coming, the time it is stopped by (`until`, epoch ms) and
49
- * the timeline row a run that waits for it writes (`row`). `writer`: the server that wrote it, its pid and start time,
50
- * where /proc gives that. */
51
- export type ImageRecord = {
52
- image: string;
53
- state: ImageState["state"];
54
- reason?: string;
55
- until?: number;
56
- row?: string;
57
- writer?: {
58
- pid: number;
59
- startTime: string;
60
- };
61
- };
62
- export type DockerImage = {
63
- readonly image: string;
64
- /** The state now. */
65
- state(): ImageState;
66
- /** Settles with the state once it is ready or unavailable. */
67
- readonly settled: Promise<ImageState>;
68
- /** Stops a build or pull in progress and waits, at most CLOSE_WAIT_MS, for its last record to be saved: the server's
69
- * close (and a start that failed) calls it before the data directory's lock goes, so no record of this server lands
70
- * after the next one took the lock. */
71
- close(): Promise<void>;
72
- };
73
- /** Removes the record: this server has no Docker box, so no run waits on its image. */
74
- export declare const clearImage: (data: string) => Promise<void>;
75
- /**
76
- * The image's readiness on this server: asked of Docker now (within INSPECT_TIMEOUT_MS), and when Docker has none (or,
77
- * for the default, has one of another recipe), built from BOX_RECIPE or pulled, in the background, within its bound; a
78
- * try that fails, but not for want of time, is made once more, `retryAfterMs` later. `onChange` is told each state after
79
- * the first. The record in the data directory follows the state.
80
- */
81
- export declare function dockerImage(env: NodeJS.ProcessEnv, data: string, image: string, options?: {
82
- pullTimeoutMs?: number;
83
- buildTimeoutMs?: number;
84
- inspectTimeoutMs?: number;
85
- retryAfterMs?: number;
86
- onChange?: (state: ImageState, ms: number) => void;
87
- warn?: (message: string) => void;
88
- }): Promise<DockerImage>;
89
- /** Docker's offer with the image's state on it: available while it is ready or preparing, else unavailable with why. */
90
- export declare function withImage(offer: BoxOffer, image: ImageState): BoxOffer;
91
- /**
92
- * Before a run's box is made from `image`: returns once the server's record says the image is ready, or says nothing
93
- * of it (no record, another image); waits while it says the image is being built or pulled, telling `note` once, as the
94
- * run's timeline row; and throws, with the server's reason, when that failed, and saying to restart the server when the
95
- * server that was making it is gone (its writer, or where that cannot be told, its deadline). A cancel of `context`
96
- * ends the wait.
97
- */
98
- export declare function awaitImage(data: string, image: string, context: Context, note: (summary: string) => Promise<void> | void): Promise<void>;