@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
package/dist/owner.d.ts CHANGED
@@ -40,7 +40,6 @@ export declare class SignInLimit {
40
40
  allow(address: string): SignInAllowed;
41
41
  }
42
42
  export declare class Owner {
43
- private readonly dir;
44
43
  readonly openSetup: boolean;
45
44
  private readonly say;
46
45
  private readonly file;
package/dist/owner.js CHANGED
@@ -114,7 +114,6 @@ export class SignInLimit {
114
114
  }
115
115
  }
116
116
  export class Owner {
117
- dir;
118
117
  openSetup;
119
118
  say;
120
119
  file;
@@ -127,7 +126,6 @@ export class Owner {
127
126
  settingUp = false;
128
127
  /** `openSetup`: no setup code; the first visit sets the password (no public address). `say` prints a setup code. */
129
128
  constructor(dir, openSetup, say = () => { }, addresses = SIGN_IN_PEERS) {
130
- this.dir = dir;
131
129
  this.openSetup = openSetup;
132
130
  this.say = say;
133
131
  this.signIns = new SignInLimit(addresses);
@@ -175,7 +175,7 @@ export async function paidStep(paid, call, fee, run, chargeOf, pause) {
175
175
  async function paidOn(paid, call, fee, send, chargeOf) {
176
176
  const id = `${call}#${(paidSeq += 1)}`;
177
177
  try {
178
- await paid.admit({ id, name: fee.name, tool: fee.tool, holdUsd: fee.usd, basis: fee.basis, call, chargedBy: fee.by });
178
+ await paid.admit({ id, name: fee.name, holdUsd: fee.usd, basis: fee.basis, call, chargedBy: fee.by });
179
179
  }
180
180
  catch (error) {
181
181
  await pauseOn(error);
@@ -0,0 +1,97 @@
1
+ /** Why a remote box (Daytona's, Modal's) has no network, said in capabilities whenever the server's host list is set:
2
+ * its computer is made with no network (Daytona) or no network or an open one (Modal), never with a host list, so a
3
+ * list is narrowed to none (workspace/computer-deps.ts networkOf). */
4
+ export declare const remoteNoList: (id: "daytona" | "modal") => string;
5
+ /** Every box a place may name, in the order capabilities lists them. */
6
+ export declare const BOX_IDS: readonly ["bwrap", "docker", "modal", "daytona"];
7
+ export type BoxId = (typeof BOX_IDS)[number];
8
+ /** A box as capabilities show it: whether this server has it, and why when not (or how it was checked); `state`, which
9
+ * capabilities derive from it (place.ts stated). `network`: what an available box reaches (BOX_NETWORKS), with
10
+ * `network_reason` when it is available and has none for a cause of its own (a daemon elsewhere; a remote box, whose
11
+ * computer is never made with a host list). `host_addresses`: for Docker from a container (compose.yaml), the Docker host's own addresses
12
+ * its computers' egress proxy refuses as the host's (docker-host-addresses.ts: the read through the socket and
13
+ * AGENTRUN_DOCKER_HOST_ADDRESSES). */
14
+ export type BoxOffer = {
15
+ id: BoxId;
16
+ available: boolean;
17
+ state?: BoxState;
18
+ reason?: string;
19
+ network?: BoxNetwork;
20
+ network_reason?: string;
21
+ host_addresses?: string[];
22
+ };
23
+ /** What an available box reaches: the hosts of `places.allow` (`allowlist`), or nothing (`none`). */
24
+ export declare const BOX_NETWORKS: readonly ["allowlist", "none"];
25
+ export type BoxNetwork = (typeof BOX_NETWORKS)[number];
26
+ /** A box's state in capabilities: ready (available) or unavailable. */
27
+ export declare const BOX_STATES: readonly ["ready", "unavailable"];
28
+ export type BoxState = (typeof BOX_STATES)[number];
29
+ /** The remote boxes' keys: secrets the server holds and its computer providers read, which no run is handed
30
+ * (run-secrets.ts SERVER_ONLY). */
31
+ export declare const BOX_KEYS: readonly string[];
32
+ /** The setting that lists the boxes to set up: a comma list of box ids, empty or `none` for no box. */
33
+ export declare const BOXES_ENV = "AGENTRUN_BOXES";
34
+ /** The boxes a server sets up when AGENTRUN_BOXES is not set at all: Docker, probed as if listed. */
35
+ export declare const DEFAULT_BOXES: readonly BoxId[];
36
+ /** Whether `env` leaves the boxes to this server's default (DEFAULT_BOXES): AGENTRUN_BOXES is not set at all. */
37
+ export declare const boxesByDefault: (env: NodeJS.ProcessEnv) => boolean;
38
+ /** The boxes `env` lists in AGENTRUN_BOXES, DEFAULT_BOXES when it is not set, none when it is empty or `none`; a name
39
+ * that is no box throws, naming it, and so does `none` with another. */
40
+ export declare function enabledBoxes(env: NodeJS.ProcessEnv): Set<BoxId>;
41
+ /** The start's log line: the boxes available, the rest, and why each box AGENTRUN_BOXES lists (`listed`) is not available. */
42
+ export declare function boxesLog(offers: readonly BoxOffer[], listed: ReadonlySet<BoxId>): Record<string, string>;
43
+ /** Why docker is unavailable when its daemon refuses this server's process its socket (EACCES on /var/run/docker.sock)
44
+ * and the group file lists this user in the docker group: this process started before the user joined it (a systemd
45
+ * user manager that has run since, kept by linger), so a restart of that manager, or a new login, gives it the group. */
46
+ export declare const DOCKER_NOT_IN_GROUP = "This server's process isn't in the docker group: restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
47
+ /** The same, when the group file does not list this user in the docker group (or cannot say): joining comes first. */
48
+ export declare const DOCKER_JOIN_GROUP = "This server's process isn't in the docker group: add this user to it with `sudo usermod -aG docker $USER`, then restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
49
+ /** How long Docker's probe may take. */
50
+ export declare const PROBE_TIMEOUT_MS = 5000;
51
+ /** What `docker version` says of this machine's Docker daemon: it answers (`up`), or why not. `absent`: no daemon
52
+ * answers this process (no docker command, a call that fails, or one that names no daemon); not absent: one is there,
53
+ * and its socket refuses this process (the group it lacks). */
54
+ export type DockerDaemon = {
55
+ readonly up: true;
56
+ } | {
57
+ readonly up: false;
58
+ readonly absent: boolean;
59
+ readonly reason: string;
60
+ };
61
+ /** Asks this machine's Docker daemon its version (`docker version`), as the Docker computer's check (docker-daemon.ts)
62
+ * does: the CLI is on PATH and its daemon answers this user. `signal` bounds it. */
63
+ export declare function askDockerDaemon(env: NodeJS.ProcessEnv, signal: AbortSignal, groups?: {
64
+ file: string;
65
+ user: string;
66
+ ids: readonly number[];
67
+ }): Promise<DockerDaemon>;
68
+ /** What placeOffers takes beyond the environment. */
69
+ export type PlaceOffersOptions = {
70
+ /** A provider key's value as a run's claim reads it (key-meta.ts keyReader); default `env`'s alone. */
71
+ keyOf?: (name: string) => Promise<string | undefined>;
72
+ /** Docker's probe's bound (PROBE_TIMEOUT_MS). */
73
+ timeoutMs?: number;
74
+ /** The group file and this process's user and groups, which say whether a refused docker socket is a membership
75
+ * granted since this process started; default the system's. */
76
+ groups?: {
77
+ file: string;
78
+ user: string;
79
+ ids: readonly number[];
80
+ };
81
+ /** Under --faux only: Docker answers, whatever AGENTRUN_BOXES lists, and nothing asks it. */
82
+ fauxDocker?: boolean;
83
+ };
84
+ /** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): bwrap
85
+ * is in no release; a box AGENTRUN_BOXES does not list is not enabled; docker by its probe (or `fauxDocker`); daytona
86
+ * and modal by their keys. Rejects only for a name in AGENTRUN_BOXES that is no box. No reason holds a key or an answer's body. */
87
+ export declare function placeOffers(env: NodeJS.ProcessEnv, options?: PlaceOffersOptions): Promise<BoxOffer[]>;
88
+ /** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf): Docker's
89
+ * computers through their egress proxy (an allowlist), with the Docker host's own addresses it refuses when the server
90
+ * runs in a container (`hostAddresses`), or unavailable where `dockerRefused` says Docker can't run a computer here
91
+ * (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses); Daytona's and Modal's none
92
+ * (remoteNoList). With `allow` none, none has a network. */
93
+ export declare function withNetworks(offers: readonly BoxOffer[], allow: readonly string[] | "none", docker?: {
94
+ refused?: string;
95
+ hostAddresses?: readonly string[];
96
+ faux?: boolean;
97
+ }): BoxOffer[];
@@ -0,0 +1,206 @@
1
+ // The boxes a place may name, as capabilities show them (places.boxes), read from the computers runs execute on: a
2
+ // sandbox place on box X is a sandbox computer on provider X (computer-setting.ts computerOfPlace), which a run's claim
3
+ // starts (workspace/). Read once, at the server's start: each fix takes a restart.
4
+ //
5
+ // AGENTRUN_BOXES lists the boxes to set up. Not set at all, it is docker alone (DEFAULT_BOXES): a plain start probes
6
+ // Docker and offers it when Docker answers, so a new agent lands in its box (place.ts); every other box is the operator's
7
+ // to list. Set, it wins: a box it does not list is never probed and is unavailable, its reason naming the setting that
8
+ // lists it, an empty value or `none` sets up no box, and a name in it that is no box refuses the start. Every reason says
9
+ // what to do next. Docker is probed (`docker version`); Daytona and Modal are offered when the keys their computer
10
+ // provider requires are set (the server's environment, else saved in Settings → Computers), and are not asked anything
11
+ // at the start: a key the vendor refuses fails the run's computer start, in the vendor's words. bwrap is in no release.
12
+ import { execFile } from "node:child_process";
13
+ import { readFile } from "node:fs/promises";
14
+ import { userInfo } from "node:os";
15
+ import { PROVIDERS } from "@parcha/agentrun-computer";
16
+ import { withoutSecrets } from "./secrets.js";
17
+ /** Why a remote box (Daytona's, Modal's) has no network, said in capabilities whenever the server's host list is set:
18
+ * its computer is made with no network (Daytona) or no network or an open one (Modal), never with a host list, so a
19
+ * list is narrowed to none (workspace/computer-deps.ts networkOf). */
20
+ export const remoteNoList = (id) => `a ${id === "daytona" ? "Daytona" : "Modal"} computer is never made with a host list, so a ${id} box has no network`;
21
+ /** Every box a place may name, in the order capabilities lists them. */
22
+ export const BOX_IDS = ["bwrap", "docker", "modal", "daytona"];
23
+ /** What an available box reaches: the hosts of `places.allow` (`allowlist`), or nothing (`none`). */
24
+ export const BOX_NETWORKS = ["allowlist", "none"];
25
+ /** A box's state in capabilities: ready (available) or unavailable. */
26
+ export const BOX_STATES = ["ready", "unavailable"];
27
+ /** The remote boxes' keys: secrets the server holds and its computer providers read, which no run is handed
28
+ * (run-secrets.ts SERVER_ONLY). */
29
+ export const BOX_KEYS = ["DAYTONA_API_KEY", "MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET"];
30
+ /** The setting that lists the boxes to set up: a comma list of box ids, empty or `none` for no box. */
31
+ export const BOXES_ENV = "AGENTRUN_BOXES";
32
+ /** The boxes a server sets up when AGENTRUN_BOXES is not set at all: Docker, probed as if listed. */
33
+ export const DEFAULT_BOXES = ["docker"];
34
+ /** The AGENTRUN_BOXES that sets up no box, as an empty one does. */
35
+ const NO_BOXES = "none";
36
+ /** Whether `env` leaves the boxes to this server's default (DEFAULT_BOXES): AGENTRUN_BOXES is not set at all. */
37
+ export const boxesByDefault = (env) => env[BOXES_ENV] === undefined;
38
+ /** The boxes `env` lists in AGENTRUN_BOXES, DEFAULT_BOXES when it is not set, none when it is empty or `none`; a name
39
+ * that is no box throws, naming it, and so does `none` with another. */
40
+ export function enabledBoxes(env) {
41
+ if (boxesByDefault(env))
42
+ return new Set(DEFAULT_BOXES);
43
+ const names = env[BOXES_ENV].split(",").map((name) => name.trim()).filter(Boolean);
44
+ if (names.includes(NO_BOXES)) {
45
+ if (names.length > 1)
46
+ throw new Error(`${BOXES_ENV}=${NO_BOXES} sets up no box, so it names no other: list the boxes to set up, or ${NO_BOXES} alone`);
47
+ return new Set();
48
+ }
49
+ const unknown = names.filter((name) => !BOX_IDS.includes(name));
50
+ if (unknown.length)
51
+ throw new Error(`${BOXES_ENV} names ${unknown.join(", ")}, which ${unknown.length === 1 ? "is not a box" : "are not boxes"}: list any of ${BOX_IDS.join(", ")}`);
52
+ return new Set(names);
53
+ }
54
+ /** Why box `id` is unavailable when AGENTRUN_BOXES does not list it: the setting that does, keeping what it lists now. */
55
+ const notEnabled = (id, enabled) => `not enabled on this server: start AgentRun with ${BOXES_ENV}=${BOX_IDS.filter((box) => box === id || enabled.has(box)).join(",")}`;
56
+ /** The start's log line: the boxes available, the rest, and why each box AGENTRUN_BOXES lists (`listed`) is not available. */
57
+ export function boxesLog(offers, listed) {
58
+ const ids = (yes) => offers.filter((offer) => offer.available === yes).map((offer) => offer.id).join(",") || "none";
59
+ const why = offers.filter((offer) => !offer.available && listed.has(offer.id));
60
+ return { available: ids(true), unavailable: ids(false), ...Object.fromEntries(why.map((offer) => [offer.id, offer.reason ?? ""])) };
61
+ }
62
+ /** Why docker is unavailable when its daemon refuses this server's process its socket (EACCES on /var/run/docker.sock)
63
+ * and the group file lists this user in the docker group: this process started before the user joined it (a systemd
64
+ * user manager that has run since, kept by linger), so a restart of that manager, or a new login, gives it the group. */
65
+ export const DOCKER_NOT_IN_GROUP = "This server's process isn't in the docker group: restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
66
+ /** The same, when the group file does not list this user in the docker group (or cannot say): joining comes first. */
67
+ export const DOCKER_JOIN_GROUP = "This server's process isn't in the docker group: add this user to it with `sudo usermod -aG docker $USER`, then restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
68
+ /** Whether the group file lists `user` in the docker group while this process's groups (`ids`) lack that group: a
69
+ * membership granted after this process started. False when it cannot say (no file, no docker group, users listed
70
+ * elsewhere, as a directory service lists them). */
71
+ async function joinedSince(groups) {
72
+ const line = (await readFile(groups.file, "utf8").catch(() => "")).split("\n").find((entry) => entry.startsWith("docker:"));
73
+ if (!line)
74
+ return false;
75
+ const [, , gid, members = ""] = line.split(":");
76
+ return groups.user !== "" && members.split(",").map((name) => name.trim()).includes(groups.user) && !groups.ids.includes(Number(gid));
77
+ }
78
+ /** This process's user and groups, read from the system's group file: the probe's default for `groups`. A user with no
79
+ * name (a numeric uid with no passwd entry, as in a container) is none: membership cannot be checked, so joining is said. */
80
+ const ownGroups = () => {
81
+ let user = "";
82
+ try {
83
+ user = userInfo().username;
84
+ }
85
+ catch { }
86
+ return { file: "/etc/group", user, ids: process.getgroups?.() ?? [] };
87
+ };
88
+ /** docker's own words for a socket that refused this process (the CLI's, or the connect's EACCES). Matched, never shown. */
89
+ const SOCKET_DENIED = /permission denied while trying to connect to the docker daemon socket|docker\.sock: connect: permission denied/i;
90
+ /** How long Docker's probe may take. */
91
+ export const PROBE_TIMEOUT_MS = 5_000;
92
+ /** What kind of error, never its message: a message can hold an answer's body, a path or a key. */
93
+ function errorName(error) {
94
+ const code = error?.code;
95
+ if (typeof code === "string" && /^[A-Z][A-Z0-9_]*$/.test(code))
96
+ return code;
97
+ return error instanceof Error ? error.name : "not an error";
98
+ }
99
+ /** Asks this machine's Docker daemon its version (`docker version`), as the Docker computer's check (docker-daemon.ts)
100
+ * does: the CLI is on PATH and its daemon answers this user. `signal` bounds it. */
101
+ export async function askDockerDaemon(env, signal, groups = ownGroups()) {
102
+ // Its environment is the server's through the cut a run's takes (withoutSecrets): no box key, no other secret, no
103
+ // name shaped like a key.
104
+ const dockerEnv = withoutSecrets(env);
105
+ const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, signal, maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
106
+ const code = error?.code;
107
+ resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}) } : {}), out: String(stdout) });
108
+ }));
109
+ const absent = (reason) => ({ up: false, absent: true, reason });
110
+ // The box's probe runs once, at the start: each fix takes a restart. Docker is on by default, so its reason is often a
111
+ // first-time user's first read: what is wrong in plain words, what the probe saw, then what to do.
112
+ if (answer.failed === "ENOENT")
113
+ return absent("Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
114
+ // Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
115
+ // a restart alone where the group file already lists this user, else joining it first.
116
+ if (answer.denied)
117
+ return { up: false, absent: false, reason: (await joinedSince(groups)) ? DOCKER_NOT_IN_GROUP : DOCKER_JOIN_GROUP };
118
+ if (answer.failed)
119
+ return absent(`Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
120
+ if (!answer.out.trim())
121
+ return absent("Docker isn't running on this machine (docker version named no daemon): start Docker, then restart AgentRun");
122
+ return { up: true };
123
+ }
124
+ /** Docker's offer: `docker version` names the daemon's version, so the CLI is on PATH and its daemon answers this user.
125
+ * Bounded by `timeoutMs`; never rejects. */
126
+ async function probeDocker(env, timeoutMs, groups) {
127
+ const no = (reason) => ({ id: "docker", available: false, reason });
128
+ // Its environment is the server's through the cut a run's takes (withoutSecrets): no box key, no other secret, no
129
+ // name shaped like a key.
130
+ const dockerEnv = withoutSecrets(env);
131
+ const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
132
+ const failed = error;
133
+ const code = failed?.code;
134
+ resolve({ ...(failed ? { failed: typeof code === "number" ? `exit ${code}` : errorName(failed), ...(failed.killed ? { late: true } : {}), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}) } : {}), out: String(stdout) });
135
+ }));
136
+ // Docker is on by default, so its reason is often a first-time user's first read: what is wrong in plain words, what
137
+ // the probe saw, then what to do.
138
+ if (answer.late)
139
+ return no(`Docker isn't answering on this machine (docker version took over ${timeoutMs} ms): start Docker, then restart AgentRun`);
140
+ if (answer.failed === "ENOENT")
141
+ return no("Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
142
+ // Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
143
+ // a restart alone where the group file already lists this user, else joining it first.
144
+ if (answer.denied)
145
+ return no((await joinedSince(groups)) ? DOCKER_NOT_IN_GROUP : DOCKER_JOIN_GROUP);
146
+ if (answer.failed)
147
+ return no(`Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
148
+ if (!answer.out.trim())
149
+ return no("Docker isn't running on this machine (docker version named no daemon): start Docker, then restart AgentRun");
150
+ return { id: "docker", available: true };
151
+ }
152
+ /** A remote box's offer: available when every key its computer provider requires is set, read as a run's claim reads
153
+ * it (`keyOf`: the server's environment, else the key saved in Settings → Computers); nothing is asked of the vendor. */
154
+ async function remoteOffer(id, keyOf) {
155
+ const required = (PROVIDERS.find((entry) => entry.id === id)?.keys ?? []).filter((key) => key.required).map((key) => key.name);
156
+ const missing = [];
157
+ for (const name of required)
158
+ if ((await keyOf(name)) === undefined)
159
+ missing.push(name);
160
+ if (missing.length)
161
+ return { id, available: false, reason: `needs ${missing.join(" and ")}` };
162
+ return { id, available: true, reason: "configured; not probed at start" };
163
+ }
164
+ /** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): bwrap
165
+ * is in no release; a box AGENTRUN_BOXES does not list is not enabled; docker by its probe (or `fauxDocker`); daytona
166
+ * and modal by their keys. Rejects only for a name in AGENTRUN_BOXES that is no box. No reason holds a key or an answer's body. */
167
+ export async function placeOffers(env, options = {}) {
168
+ const enabled = enabledBoxes(env);
169
+ const keyOf = options.keyOf ?? (async (name) => env[name] || undefined);
170
+ return Promise.all(BOX_IDS.map(async (id) => {
171
+ if (id === "bwrap")
172
+ return { id, available: false, reason: NOT_YET };
173
+ // The tests' faux docker stands in whatever AGENTRUN_BOXES lists, as the old faux box did.
174
+ if (id === "docker" && options.fauxDocker)
175
+ return { id, available: true, reason: "a faux docker (tests)" };
176
+ if (!enabled.has(id))
177
+ return { id, available: false, reason: notEnabled(id, enabled) };
178
+ if (id === "docker")
179
+ return probeDocker(env, options.timeoutMs ?? PROBE_TIMEOUT_MS, options.groups ?? ownGroups());
180
+ return remoteOffer(id, keyOf);
181
+ }));
182
+ }
183
+ const NOT_YET = "the bwrap box is not in this release yet: use the docker box";
184
+ /** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf): Docker's
185
+ * computers through their egress proxy (an allowlist), with the Docker host's own addresses it refuses when the server
186
+ * runs in a container (`hostAddresses`), or unavailable where `dockerRefused` says Docker can't run a computer here
187
+ * (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses); Daytona's and Modal's none
188
+ * (remoteNoList). With `allow` none, none has a network. */
189
+ export function withNetworks(offers, allow, docker = {}) {
190
+ return offers.map((offer) => {
191
+ if (!offer.available)
192
+ return offer;
193
+ if (offer.id === "docker") {
194
+ if (docker.refused !== undefined)
195
+ return { id: offer.id, available: false, state: "unavailable", reason: docker.refused };
196
+ if (docker.faux)
197
+ return { ...offer, network: "none", network_reason: "a faux docker (tests)" };
198
+ if (allow === "none")
199
+ return { ...offer, network: "none", network_reason: "AGENTRUN_BOX_ALLOW is none" };
200
+ return { ...offer, network: "allowlist", ...(docker.hostAddresses?.length ? { host_addresses: [...docker.hostAddresses] } : {}) };
201
+ }
202
+ if (allow === "none" || (offer.id !== "daytona" && offer.id !== "modal"))
203
+ return { ...offer, network: "none" };
204
+ return { ...offer, network: "none", network_reason: remoteNoList(offer.id) };
205
+ });
206
+ }
package/dist/place.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type BoxId, type BoxOffer } from "./boxes.js";
1
+ import { type BoxId, type BoxOffer } from "./place-offers.js";
2
2
  import { type InputIssue } from "./errors.js";
3
3
  export declare const PLACE_MODES: readonly ["runner", "sandbox"];
4
4
  export type PlaceMode = (typeof PLACE_MODES)[number];
@@ -8,18 +8,18 @@ export type Place = {
8
8
  mode: "sandbox";
9
9
  box: BoxId;
10
10
  };
11
- /** The boxes runs execute in so far: Docker, Daytona and the VM box. */
11
+ /** The boxes runs execute in: the sandbox computers of Docker, Daytona and Modal. */
12
12
  export declare const RUN_BOXES: readonly BoxId[];
13
- /** The boxes this server gives runs, from what its registry set up at its start (boxes.ts): a box runs execute in
14
- * that the registry has, and no other. */
13
+ /** The boxes this server gives runs, from what it found at its start (place-offers.ts): a box runs execute in that it
14
+ * has, and no other. */
15
15
  export declare function boxAvailability(registry: readonly BoxOffer[]): BoxOffer[];
16
- /** The place a new agentic definition that names none is saved with: the Docker box where this server has it, ready or
17
- * preparing (its first run waits for the image); else none, so the agent runs on the runner as it did before, with
16
+ /** The place a new agentic definition that names none is saved with: the Docker box where this server has it; else none, so the agent runs on the runner as it did before, with
18
17
  * `reason` saying why, in docker's own words. A workflow is never given one. */
19
18
  export declare function newAgentPlace(registry: readonly BoxOffer[]): {
20
19
  place: Place;
21
20
  } | {
22
21
  reason: string;
22
+ why: string;
23
23
  };
24
24
  /** The place a revision that names none resolves to, at its create and at each run alike: this server's default place
25
25
  * (newAgentPlace) for an agentic revision; the runner for a workflow, which is never given a box, and for one that names
@@ -33,14 +33,13 @@ export declare const NEW_AGENT_TOOLS: readonly string[];
33
33
  /** Why a sandbox-only tool (bash) cannot run on this server: no box runs execute in is available, each with its reason.
34
34
  * Undefined when one is. */
35
35
  export declare function noBoxReason(registry: readonly BoxOffer[]): string | undefined;
36
- /** The start banner's words on the boxes: which are ready for a sandbox agent's tools, which are still preparing (an
37
- * available box whose `state` says so, with its reason: what it is pulling), then why each box is not that
38
- * AGENTRUN_BOXES lists (`listed`), or, when none is ready or preparing, each box runs execute in, with what to do.
36
+ /** The start banner's words on the boxes: which are ready for a sandbox agent's tools, then why each box is not that
37
+ * AGENTRUN_BOXES lists (`listed`), or, when none is ready, each box runs execute in, with what to do.
39
38
  * `byDefault`, with AGENTRUN_BOXES not set at all: short, docker alone, said to be on by default, or why it is not. */
40
39
  export declare function boxesLine(registry: readonly BoxOffer[], listed: ReadonlySet<BoxId>, allow?: readonly string[] | "none", byDefault?: boolean): string;
41
40
  /** `places` in capabilities: the modes a revision may name, the place a new agent is saved with and a revision that
42
41
  * names none runs in (`default_place`, with `default_reason` when it is the runner), each box, and the hosts a box whose
43
- * `network` is `allowlist` reaches (`allow`, run-box.ts boxAllowOf; empty for `none`). */
42
+ * `network` is `allowlist` reaches (`allow`, box-settings.ts boxAllowOf; empty for `none`). */
44
43
  export declare const placesOf: (registry: readonly BoxOffer[], allow?: readonly string[] | "none") => {
45
44
  boxes: BoxOffer[];
46
45
  allow: string[];
@@ -57,9 +56,6 @@ export declare const placesOf: (registry: readonly BoxOffer[], allow?: readonly
57
56
  export declare const resolvePlace: (revision: Place | undefined, fallback: Place) => Place;
58
57
  /** Where a box has the run's work/ (bound, or seeded), and where its tools start: the same in every box. */
59
58
  export declare const BOX_WORK = "/workspace";
60
- /** The boxes that cannot bind a run's work/, being on another machine: its work/ is seeded at the box's making and
61
- * pulled back (run-box.ts). */
62
- export declare const REMOTE_BOXES: readonly BoxId[];
63
59
  /** `place` as a definition writes it, to copy: `"place": {"mode": "sandbox", "box": "docker"}`. */
64
60
  export declare const placeFix: (place: Place) => string;
65
61
  /** What is wrong with `place` as a definition gives it, as issues at `field`. Each names its fix: the field to remove,
package/dist/place.js CHANGED
@@ -3,22 +3,23 @@
3
3
  // explicit runner included, since the default is this host's; one that names none keeps none, so a revision written
4
4
  // before this field keeps its id. Which boxes this server has is said in capabilities, and a revision whose box it does
5
5
  // not have saves with a warning and is refused at run time. A run runs in its revision's place, else this host's
6
- // default, and keeps the place it resolved to: a run request names none. Runs execute in Docker and in Daytona, for
7
- // now: every other box says it does not run yet. A harness's own tools in the box, when they come, are an option of
8
- // sandbox, never a third mode.
6
+ // default, and keeps the place it resolved to: a run request names none. A sandbox place on a box is a sandbox computer
7
+ // of that provider (computer-setting.ts computerOfPlace), which the run's claim starts: Docker, Daytona or Modal; bwrap
8
+ // says it does not run yet. A harness's own tools in the box, when they come, are an option of sandbox, never a third
9
+ // mode.
9
10
  //
10
11
  // The box is a new agent's default machine: an agentic definition that names no place is saved, at its create, with the
11
- // Docker box as its place wherever this server has docker (ready, or preparing), and with bash when it names no tools
12
+ // Docker box as its place wherever this server has docker, and with bash when it names no tools
12
13
  // (newAgentPlace). A revision that names no place resolves the same way at each run (defaultPlaceOf): this server's
13
14
  // default_place, so where docker is there now it runs in the Docker box, and the runner where it is not. A workflow, and a
14
15
  // revision with a tool the box refuses, run on the runner.
15
- import { BOX_IDS, BOXES_ENV, VM_PROVIDER } from "./boxes.js";
16
+ import { BOX_IDS, BOXES_ENV } from "./place-offers.js";
16
17
  import { sentence } from "./errors.js";
17
18
  export const PLACE_MODES = ["runner", "sandbox"];
18
- /** The boxes runs execute in so far: Docker, Daytona and the VM box. */
19
- export const RUN_BOXES = ["docker", "daytona", VM_PROVIDER.id];
20
- /** The boxes this server gives runs, from what its registry set up at its start (boxes.ts): a box runs execute in
21
- * that the registry has, and no other. */
19
+ /** The boxes runs execute in: the sandbox computers of Docker, Daytona and Modal. */
20
+ export const RUN_BOXES = ["docker", "daytona", "modal"];
21
+ /** The boxes this server gives runs, from what it found at its start (place-offers.ts): a box runs execute in that it
22
+ * has, and no other. */
22
23
  export function boxAvailability(registry) {
23
24
  return BOX_IDS.map((id) => {
24
25
  const offer = registry.find((o) => o.id === id);
@@ -29,14 +30,14 @@ export function boxAvailability(registry) {
29
30
  return { id, available: false, reason: `runs in the ${id} box are not available yet: use the ${RUN_BOXES.join(" or ")} box` };
30
31
  });
31
32
  }
32
- /** The place a new agentic definition that names none is saved with: the Docker box where this server has it, ready or
33
- * preparing (its first run waits for the image); else none, so the agent runs on the runner as it did before, with
33
+ /** The place a new agentic definition that names none is saved with: the Docker box where this server has it; else none, so the agent runs on the runner as it did before, with
34
34
  * `reason` saying why, in docker's own words. A workflow is never given one. */
35
35
  export function newAgentPlace(registry) {
36
36
  const docker = boxAvailability(registry).find((box) => box.id === "docker");
37
37
  if (docker?.available)
38
38
  return { place: { mode: "sandbox", box: "docker" } };
39
- return { reason: `new agents run on the runner, because the docker box is unavailable here: ${docker?.reason ?? "it is not set up"}` };
39
+ const why = docker?.reason ?? "it is not set up";
40
+ return { reason: `new agents run on the runner, because the docker box is unavailable here: ${why}`, why };
40
41
  }
41
42
  /** The place a revision that names none resolves to, at its create and at each run alike: this server's default place
42
43
  * (newAgentPlace) for an agentic revision; the runner for a workflow, which is never given a box, and for one that names
@@ -60,19 +61,13 @@ export function noBoxReason(registry) {
60
61
  return undefined;
61
62
  return `no box is set up on this server: ${boxes.map((box) => `${box.id} is unavailable (${box.reason ?? "no reason given"})`).join("; ")}`;
62
63
  }
63
- /** The start banner's words on the boxes: which are ready for a sandbox agent's tools, which are still preparing (an
64
- * available box whose `state` says so, with its reason: what it is pulling), then why each box is not that
65
- * AGENTRUN_BOXES lists (`listed`), or, when none is ready or preparing, each box runs execute in, with what to do.
64
+ /** The start banner's words on the boxes: which are ready for a sandbox agent's tools, then why each box is not that
65
+ * AGENTRUN_BOXES lists (`listed`), or, when none is ready, each box runs execute in, with what to do.
66
66
  * `byDefault`, with AGENTRUN_BOXES not set at all: short, docker alone, said to be on by default, or why it is not. */
67
67
  export function boxesLine(registry, listed, allow = "none", byDefault = false) {
68
68
  const boxes = boxAvailability(registry);
69
- const preparing = (box) => box.state === "preparing";
70
- const ready = boxes.filter((box) => box.available && !preparing(box)).map((box) => box.id);
71
- const coming = boxes.filter((box) => box.available && preparing(box));
72
- const said = [
73
- ...(ready.length ? [`${new Intl.ListFormat("en", { type: "conjunction" }).format(ready)} ${ready.length === 1 ? "is" : "are"} ready, so sandbox agents run their tools there.`] : []),
74
- ...coming.map((box) => sentence(`${box.id} is preparing${box.reason ? ` (${box.reason})` : ""}`)),
75
- ];
69
+ const ready = boxes.filter((box) => box.available).map((box) => box.id);
70
+ const said = ready.length ? [`${new Intl.ListFormat("en", { type: "conjunction" }).format(ready)} ${ready.length === 1 ? "is" : "are"} ready, so sandbox agents run their tools there.`] : [];
76
71
  const none = !said.length;
77
72
  const why = boxes.filter((box) => !box.available && (listed.has(box.id) || (none && RUN_BOXES.includes(box.id))));
78
73
  // What an available box's programs reach, as capabilities say (`network`, `network_reason`, `places.allow`).
@@ -82,24 +77,22 @@ export function boxesLine(registry, listed, allow = "none", byDefault = false) {
82
77
  const docker = boxes.find((box) => box.id === "docker");
83
78
  if (!docker?.available)
84
79
  return `Boxes: none, so new agents run on the runner. ${sentence(docker?.reason ?? "Docker is not set up")}`;
85
- const coming = preparing(docker) ? ` docker is preparing${docker.reason ? ` (${docker.reason})` : ""}.` : "";
86
- return [`Boxes: docker (on by default; set ${BOXES_ENV} to change).${coming}`, ...reach].join(" ");
80
+ return [`Boxes: docker (on by default; set ${BOXES_ENV} to change).`, ...reach].join(" ");
87
81
  }
88
82
  return ["Boxes:", ...(none ? ["none is ready, so sandbox agents do not run here."] : said), ...reach, ...why.map((box) => sentence(`${box.id}: ${box.reason ?? "not available"}`))].join(" ");
89
83
  }
90
84
  /** `places` in capabilities: the modes a revision may name, the place a new agent is saved with and a revision that
91
85
  * names none runs in (`default_place`, with `default_reason` when it is the runner), each box, and the hosts a box whose
92
- * `network` is `allowlist` reaches (`allow`, run-box.ts boxAllowOf; empty for `none`). */
86
+ * `network` is `allowlist` reaches (`allow`, box-settings.ts boxAllowOf; empty for `none`). */
93
87
  export const placesOf = (registry, allow = "none") => {
94
88
  const fresh = newAgentPlace(registry);
95
89
  return { modes: [...PLACE_MODES], ...("place" in fresh ? { default_place: fresh.place } : { default_place: { mode: "runner" }, default_reason: fresh.reason }), boxes: boxAvailability(registry).map(stated), allow: allow === "none" ? [] : [...allow] };
96
90
  };
97
- /** A box with its state: what the server set (a Docker box whose image is coming is `preparing`), else `ready` when it
98
- * is available and `unavailable` when not; and, on an available box, its network as the server set it, with
91
+ /** A box with its state, `ready` when it is available and `unavailable` when not; and, on an available box, its network as the server set it, with
99
92
  * `network_reason` when it is none for a cause of its own. */
100
- const stated = ({ state, network, network_reason, ...offer }) => ({
93
+ const stated = ({ state: _state, network, network_reason, ...offer }) => ({
101
94
  ...offer,
102
- state: offer.available ? (state ?? "ready") : "unavailable",
95
+ state: offer.available ? "ready" : "unavailable",
103
96
  ...(offer.available && network ? { network } : {}),
104
97
  ...(offer.available && network === "none" && network_reason ? { network_reason } : {}),
105
98
  });
@@ -107,9 +100,6 @@ const stated = ({ state, network, network_reason, ...offer }) => ({
107
100
  export const resolvePlace = (revision, fallback) => revision ?? fallback;
108
101
  /** Where a box has the run's work/ (bound, or seeded), and where its tools start: the same in every box. */
109
102
  export const BOX_WORK = "/workspace";
110
- /** The boxes that cannot bind a run's work/, being on another machine: its work/ is seeded at the box's making and
111
- * pulled back (run-box.ts). */
112
- export const REMOTE_BOXES = ["daytona", VM_PROVIDER.id];
113
103
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
114
104
  const listed = (options, value) => typeof value === "string" && options.includes(value);
115
105
  /** `place` as a definition writes it, to copy: `"place": {"mode": "sandbox", "box": "docker"}`. */
@@ -33,7 +33,8 @@ export declare function sessionModel(api: SessionPort["api"], url: string, model
33
33
  * credential (named `keyName`). The proxy knows a request by `authorization: Bearer <key>`: on Messages that header is set
34
34
  * on the model, since pi-ai's Anthropic client sends its key as x-api-key, which the proxy does not forward; on Responses
35
35
  * pi-ai sends the key as that bearer token itself. The one client every runner caller of a session proxy builds: pi's
36
- * sessions, the learning grader, a workflow's model nodes. */
36
+ * sessions, the learning grader, a workflow's model nodes. Each request's images are checked as they are attached
37
+ * (attach-images.ts): one a provider would refuse goes as a text saying why. */
37
38
  export declare function sessionProvider(api: SessionPort["api"], proxy: {
38
39
  readonly url: string;
39
40
  readonly key: string;
@@ -1,6 +1,7 @@
1
1
  import { anthropicMessagesApi } from "@earendil-works/pi-ai/api/anthropic-messages.lazy";
2
2
  import { openAIResponsesApi } from "@earendil-works/pi-ai/api/openai-responses.lazy";
3
3
  import { createProvider } from "@earendil-works/pi-ai/models";
4
+ import { attachingImages } from "./attach-images.js";
4
5
  /** The provider id the port's one model is listed under. */
5
6
  export const PORT_PROVIDER = "agentrun-session";
6
7
  /** The provider id a tier's port model is listed under (tieredModels): the run's model of that tier, on a proxy of its
@@ -35,14 +36,15 @@ export function sessionModel(api, url, model, options) {
35
36
  * credential (named `keyName`). The proxy knows a request by `authorization: Bearer <key>`: on Messages that header is set
36
37
  * on the model, since pi-ai's Anthropic client sends its key as x-api-key, which the proxy does not forward; on Responses
37
38
  * pi-ai sends the key as that bearer token itself. The one client every runner caller of a session proxy builds: pi's
38
- * sessions, the learning grader, a workflow's model nodes. */
39
+ * sessions, the learning grader, a workflow's model nodes. Each request's images are checked as they are attached
40
+ * (attach-images.ts): one a provider would refuse goes as a text saying why. */
39
41
  export function sessionProvider(api, proxy, model, options) {
40
42
  return createProvider({
41
43
  id: options.provider,
42
44
  baseUrl: sessionBaseUrl(api, proxy.url),
43
45
  auth: { apiKey: { name: options.keyName, resolve: async () => ({ auth: { apiKey: proxy.key }, source: "session" }) } },
44
46
  models: [sessionModel(api, proxy.url, model, { provider: options.provider, ...(api === "anthropic-messages" ? { headers: { authorization: `Bearer ${proxy.key}` } } : {}), ...(options.like ? { like: options.like } : {}), reasoning: options.reasoning })],
45
- api: api === "anthropic-messages" ? anthropicMessagesApi() : openAIResponsesApi(),
47
+ api: attachingImages(api === "anthropic-messages" ? anthropicMessagesApi() : openAIResponsesApi()),
46
48
  });
47
49
  }
48
50
  /** Models over `port` (the session's, read at each request: undefined until a drive has attached a proxy, and anew for
@@ -73,7 +75,7 @@ export async function portModels(port, like, provider = PORT_PROVIDER) {
73
75
  id: provider, baseUrl,
74
76
  auth: { apiKey: { name: "the session's side key", resolve: async () => ({ auth: { apiKey: now.key }, source: "session" }) } },
75
77
  models: [model],
76
- api: now.api === "anthropic-messages" ? anthropicMessagesApi() : openAIResponsesApi(),
78
+ api: attachingImages(now.api === "anthropic-messages" ? anthropicMessagesApi() : openAIResponsesApi()),
77
79
  }));
78
80
  built = { at, models, model: models.getModel(provider, now.model) };
79
81
  return built;
package/dist/print.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- import type { ImageState } from "./box-image.js";
2
- /** The line said as the Docker box image's first build (or pull) starts: it takes minutes, and nothing waits on it but
3
- * a sandbox run's first box. */
4
- export declare const IMAGE_PREPARING = "Preparing the Docker box image (first start only, a few minutes); agents can be made now, and their first run waits for it.";
5
- /** The line for the Docker box image's state `state`, said once as its build starts and once as it ends (`started`: the
6
- * start was said); undefined for any other, an image Docker already had among them. */
7
- export declare function boxImageLine(state: ImageState, started: boolean): string | undefined;
8
1
  /** Where the token came from: made at this start (printed this once), kept in DIR/.token, or the environment's. */
9
2
  export type TokenSource = "made" | "file" | "env";
10
3
  /** The banner's lines. The token is printed only when this start made it; else where it is. `publicUrl` is the address
@@ -24,5 +17,5 @@ export declare function banner(o: {
24
17
  }): string[];
25
18
  /** One log line. */
26
19
  export declare const logLine: (event: string, fields?: Record<string, string | number>) => string;
27
- /** A duration as pi-durable-disk's --drain-timeout takes it ("8s", "500ms", "1m"), in milliseconds; undefined when it is not one. */
20
+ /** A duration as --drain-timeout takes it ("8s", "500ms", "1m"), in milliseconds; undefined when it is not one. */
28
21
  export declare function durationMs(text: string): number | undefined;
package/dist/print.js CHANGED
@@ -1,19 +1,6 @@
1
1
  // What the server prints on stdout: its banner at start, and one line per request, per run start and end, and per
2
2
  // refused credential (logfmt: `at=<time> event=<name> key=value ...`). No line holds a token or any part of one.
3
3
  import { join } from "node:path";
4
- import { sentence } from "./errors.js";
5
- /** The line said as the Docker box image's first build (or pull) starts: it takes minutes, and nothing waits on it but
6
- * a sandbox run's first box. */
7
- export const IMAGE_PREPARING = "Preparing the Docker box image (first start only, a few minutes); agents can be made now, and their first run waits for it.";
8
- /** The line for the Docker box image's state `state`, said once as its build starts and once as it ends (`started`: the
9
- * start was said); undefined for any other, an image Docker already had among them. */
10
- export function boxImageLine(state, started) {
11
- if (state.state === "preparing")
12
- return started ? undefined : IMAGE_PREPARING;
13
- if (!started)
14
- return undefined;
15
- return state.state === "ready" ? "The Docker box image is ready." : `The Docker box image failed: ${sentence(state.reason)}`;
16
- }
17
4
  /** The banner's lines. The token is printed only when this start made it; else where it is. `publicUrl` is the address
18
5
  * people open (AGENTRUN_PUBLIC_URL), which the base URL and the link use. With `accounts` the page is the owner's
19
6
  * password, so its link holds no token. `apiOnly`: no console to open, so the line says what is served instead. `boxes`: which boxes are ready, in words (Serve's boxesLine), last. */
@@ -37,7 +24,7 @@ const value = (v) => {
37
24
  };
38
25
  /** One log line. */
39
26
  export const logLine = (event, fields = {}) => [`at=${new Date().toISOString()}`, `event=${event}`, ...Object.entries(fields).map(([k, v]) => `${k}=${value(v)}`)].join(" ");
40
- /** A duration as pi-durable-disk's --drain-timeout takes it ("8s", "500ms", "1m"), in milliseconds; undefined when it is not one. */
27
+ /** A duration as --drain-timeout takes it ("8s", "500ms", "1m"), in milliseconds; undefined when it is not one. */
41
28
  export function durationMs(text) {
42
29
  const m = /^(\d+(?:\.\d+)?)(ms|s|m)$/.exec(text.trim());
43
30
  return m ? Math.round(Number(m[1]) * { ms: 1, s: 1_000, m: 60_000 }[m[2]]) : undefined;