@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.59

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 (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
@@ -54,10 +54,10 @@ export declare function booking<T extends ToolRegistration>(tool: T): T;
54
54
  export declare const bookedIn: <T>(ledger: Ledger | undefined, work: () => Promise<T>) => Promise<T>;
55
55
  /** `send`, one request to a paid provider at `fee`, on the run's one ledger under the call it runs in (Ledger.paid):
56
56
  * admitted at the fee's price, then sent, then settled at what it may have charged (its price on a 2xx, a 408 or a 5xx
57
- * or when it threw after it was sent; $0 on another 4xx); a settle that cannot be written leaves it at its hold, never
58
- * less. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
57
+ * or when it threw after it was sent, or what `charged` says it cost, never above its price; $0 on another 4xx); a
58
+ * settle that cannot be written leaves it at its hold, never less, and `settled` hears which. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
59
59
  * or when the call has no run's ledger, and then nothing is sent. A request that throws throws, settled at its price. */
60
- export declare function paidRequest(fee: Fee, send: () => Promise<Response>): Promise<Response>;
60
+ export declare function paidRequest(fee: Fee, send: () => Promise<Response>, charged?: () => number, settled?: (booked: boolean) => void): Promise<Response>;
61
61
  /** paidStep's chargeOf for a step that charged nothing and is given back: its mark settled with no charge row. */
62
62
  export declare const GIVEN_BACK = "given back";
63
63
  /** Whether the current work runs inside a call's ledger (bookedIn): a host tool call of the run's, or a workflow call
@@ -85,7 +85,8 @@ export declare const stopRunWith: (pause: NonNullable<Ledger["pause"]>) => (word
85
85
  * or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold; GIVEN_BACK:
86
86
  * given back, nothing charged, as a hold-only step's: a request its provider refused unrun leaves no charge row). One refused
87
87
  * for room pauses the run through `pause`, else through the ledger of the call it runs in (bookedIn's), as main's
88
- * paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. */
88
+ * paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. A settle
89
+ * that could not be written leaves the step at its hold, and its result says so (`unsettled`). */
89
90
  export declare function paidStep<T>(paid: PaidBooking, call: string | undefined, fee: {
90
91
  name: string;
91
92
  holdUsd: number;
@@ -105,4 +106,5 @@ export declare function paidStep<T>(paid: PaidBooking, call: string | undefined,
105
106
  refused: string;
106
107
  } | {
107
108
  result: T;
109
+ unsettled?: true;
108
110
  }>;
@@ -56,16 +56,23 @@ export const bookedIn = (ledger, work) => (ledger ? ledgers.run(ledger, work) :
56
56
  const billed = (status) => (status >= 200 && status < 300) || status === 408 || status >= 500;
57
57
  /** `send`, one request to a paid provider at `fee`, on the run's one ledger under the call it runs in (Ledger.paid):
58
58
  * admitted at the fee's price, then sent, then settled at what it may have charged (its price on a 2xx, a 408 or a 5xx
59
- * or when it threw after it was sent; $0 on another 4xx); a settle that cannot be written leaves it at its hold, never
60
- * less. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
59
+ * or when it threw after it was sent, or what `charged` says it cost, never above its price; $0 on another 4xx); a
60
+ * settle that cannot be written leaves it at its hold, never less, and `settled` hears which. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
61
61
  * or when the call has no run's ledger, and then nothing is sent. A request that throws throws, settled at its price. */
62
- export async function paidRequest(fee, send) {
62
+ export async function paidRequest(fee, send, charged, settled) {
63
63
  const ledger = ledgers.getStore();
64
64
  if (!ledger?.paid)
65
65
  throw new PaidRefused(unbookedRefusal(fee.name));
66
- const stepped = await paidStep(ledger.paid, ledger.call, { name: fee.name, holdUsd: fee.usd, basis: fee.basis, by: fee.by }, send, (outcome) => ("thrown" in outcome || billed(outcome.result.status) ? fee.usd : 0));
66
+ const said = () => {
67
+ // `charged` may be the provider's estimate (Jev's, where it reports no cost): booked on purpose, as nearer the real
68
+ // charge than the hold, and never above the hold (Math.min below).
69
+ const usd = charged?.();
70
+ return typeof usd === "number" && Number.isFinite(usd) && usd >= 0 ? Math.min(usd, fee.usd) : fee.usd;
71
+ };
72
+ const stepped = await paidStep(ledger.paid, ledger.call, { name: fee.name, holdUsd: fee.usd, basis: fee.basis, by: fee.by }, send, (outcome) => ("thrown" in outcome ? fee.usd : billed(outcome.result.status) ? said() : 0));
67
73
  if ("refused" in stepped)
68
74
  throw new PaidRefused(stepped.refused);
75
+ settled?.(stepped.unsettled !== true);
69
76
  return stepped.result;
70
77
  }
71
78
  /** paidStep's chargeOf for a step that charged nothing and is given back: its mark settled with no charge row. */
@@ -115,7 +122,8 @@ export const stopRunWith = (pause) => async (words) => {
115
122
  * or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold; GIVEN_BACK:
116
123
  * given back, nothing charged, as a hold-only step's: a request its provider refused unrun leaves no charge row). One refused
117
124
  * for room pauses the run through `pause`, else through the ledger of the call it runs in (bookedIn's), as main's
118
- * paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. */
125
+ * paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. A settle
126
+ * that could not be written leaves the step at its hold, and its result says so (`unsettled`). */
119
127
  export async function paidStep(paid, call, fee, run, chargeOf, pause) {
120
128
  const id = `${call ?? fee.ref ?? fee.name}#${(paidSeq += 1)}`;
121
129
  let admitted;
@@ -138,8 +146,8 @@ export async function paidStep(paid, call, fee, run, chargeOf, pause) {
138
146
  }
139
147
  // A hold-only step (`hold`) is given back, never a charge: its money is booked by its own charges' steps.
140
148
  const charge = fee.hold ? GIVEN_BACK : chargeOf(outcome);
141
- await (charge === GIVEN_BACK ? paid.settle(id, 0, { givenBack: true }) : paid.settle(id, charge)).catch(() => undefined);
149
+ const landed = await (charge === GIVEN_BACK ? paid.settle(id, 0, { givenBack: true }) : paid.settle(id, charge)).then(() => true, () => false);
142
150
  if ("thrown" in outcome)
143
151
  throw outcome.thrown;
144
- return outcome;
152
+ return landed ? outcome : { ...outcome, unsettled: true };
145
153
  }
@@ -1,13 +1,33 @@
1
- /** Every box a place may name, in the order capabilities lists them. */
2
- export declare const BOX_IDS: readonly ["docker", "modal", "daytona"];
3
- export type BoxId = (typeof BOX_IDS)[number];
1
+ import { type ProviderEntry } from "@parcha/agentrun-computer";
2
+ /**
3
+ * Whether a computer provider can be a box, read from its descriptor's facts (PROVIDERS' entry). A place names a box
4
+ * alone, no kind, image or network, so a run in it gets a sandbox computer on that provider with no image named
5
+ * (computer-setting.ts computerOfPlace), resolved and started by the claim as any computer setting is
6
+ * (workspace/resolve-computer.ts, computer-deps.ts computerSpecOf), and it needs:
7
+ * - a Linux shell with files and processes, for bash and the background tools: the provider serves the sandbox kind;
8
+ * - the run's folder in that shell: it takes a bind, an Archil mount or a synced folder (its derived mounts; a provider
9
+ * whose machines keep their own disk where the folder would be takes none);
10
+ * - an image with none named: its default sandbox image, or the one its prepareImage() makes;
11
+ * - what places.allow says: its computers keep to a host list, or reach nothing (its network forms hold allow or none).
12
+ * One that reaches only its vendor's own network can't be held to the list.
13
+ * Which mode's folder it takes (a bind in Mode 1, Archil or a synced one in Mode 2) is the run's start's check, as for
14
+ * any computer setting: the mode can change while the server runs.
15
+ */
16
+ export declare const isBox: (entry: ProviderEntry) => boolean;
17
+ /** Every box a place may name, in the order capabilities lists them (Settings' order of providers). */
18
+ export declare const BOX_IDS: readonly string[];
19
+ /** The boxes on this machine's container engine (their descriptor's `local`: Docker's), the boxes a server sets up when
20
+ * AGENTRUN_BOXES is not set at all. Their engine is Docker, so a local box is probed at the start with `docker
21
+ * version` (probeDocker), its computers mount this server's paths (box-paths.ts) and keep out the Docker host's own
22
+ * addresses (docker-host-addresses.ts). */
23
+ export declare const LOCAL_BOXES: readonly string[];
4
24
  /** A box as capabilities show it: whether this server has it, and why when not (or how it was checked); `state`, which
5
25
  * capabilities derive from it (place.ts stated). `network`: what an available box reaches (BOX_NETWORKS), with
6
26
  * `network_reason` when it is available and has none for a cause of its own (a daemon elsewhere). `host_addresses`: for Docker from a container (compose.yaml), the Docker host's own addresses
7
27
  * its computers' egress proxy refuses as the host's (docker-host-addresses.ts: the read through the socket and
8
28
  * AGENTRUN_DOCKER_HOST_ADDRESSES). */
9
29
  export type BoxOffer = {
10
- id: BoxId;
30
+ id: string;
11
31
  available: boolean;
12
32
  state?: BoxState;
13
33
  reason?: string;
@@ -21,47 +41,45 @@ export type BoxNetwork = (typeof BOX_NETWORKS)[number];
21
41
  /** A box's state in capabilities: ready (available) or unavailable. */
22
42
  export declare const BOX_STATES: readonly ["ready", "unavailable"];
23
43
  export type BoxState = (typeof BOX_STATES)[number];
24
- /** The remote boxes' keys: secrets the server holds and its computer providers read, which no run is handed
25
- * (run-secrets.ts SERVER_ONLY). */
26
- export declare const BOX_KEYS: readonly string[];
27
44
  /** The setting that lists the boxes to set up: a comma list of box ids, empty or `none` for no box. */
28
45
  export declare const BOXES_ENV = "AGENTRUN_BOXES";
29
- /** The boxes a server sets up when AGENTRUN_BOXES is not set at all: Docker, probed as if listed. */
30
- export declare const DEFAULT_BOXES: readonly BoxId[];
31
- /** Whether `env` leaves the boxes to this server's default (DEFAULT_BOXES): AGENTRUN_BOXES is not set at all. */
46
+ /** Whether `env` leaves the boxes to this server's default (LOCAL_BOXES): AGENTRUN_BOXES is not set at all. */
32
47
  export declare const boxesByDefault: (env: NodeJS.ProcessEnv) => boolean;
33
- /** The boxes `env` lists in AGENTRUN_BOXES, DEFAULT_BOXES when it is not set, none when it is empty or `none`; a name
48
+ /** The boxes `env` lists in AGENTRUN_BOXES, LOCAL_BOXES when it is not set, none when it is empty or `none`; a name
34
49
  * that is no box throws, naming it, and so does `none` with another. */
35
- export declare function enabledBoxes(env: NodeJS.ProcessEnv): Set<BoxId>;
50
+ export declare function enabledBoxes(env: NodeJS.ProcessEnv): Set<string>;
36
51
  /** The start's log line: the boxes available, the rest, and why each box AGENTRUN_BOXES lists (`listed`) is not available. */
37
- export declare function boxesLog(offers: readonly BoxOffer[], listed: ReadonlySet<BoxId>): Record<string, string>;
52
+ export declare function boxesLog(offers: readonly BoxOffer[], listed: ReadonlySet<string>): Record<string, string>;
38
53
  /** Why docker is unavailable when its daemon refuses this server's process its socket (EACCES on /var/run/docker.sock)
39
54
  * and the group file lists this user in the docker group: this process started before the user joined it (a systemd
40
55
  * user manager that has run since, kept by linger), so a restart of that manager, or a new login, gives it the group. */
41
56
  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";
42
57
  /** The same, when the group file does not list this user in the docker group (or cannot say): joining comes first. */
43
58
  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";
44
- /** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: the one-container `docker run`,
45
- * deploy/'s compose file and a Kubernetes pod give it none, so it asks a daemon that is not there. Starting Docker or
46
- * joining its group would not help: compose.yaml at the repository's root mounts the host's socket, which is root on
47
- * that host (compose.yaml's own header says so), so the words say that too. */
48
- export declare const DOCKER_NO_SOCKET = "This server runs in a container with no Docker socket, so its agents get file tools and web_fetch but no shell: for a shell in Docker sandboxes, give it the host's Docker socket, as `docker compose up -d` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root";
59
+ /** No Docker daemon for this server, as Settings → Computers says it (docker-daemon.ts noDockerWords). */
60
+ export declare const NO_DOCKER_HERE = "No Docker on this server: Render and most hosted services run none.";
61
+ /** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: a hosted service (Fly.io, Render,
62
+ * a Kubernetes pod), the one-container `docker run` and deploy/'s compose file give it none, so it asks a daemon that is
63
+ * not there. Starting Docker or joining its group would not help. Hosted, there is no host socket to give, so the way is
64
+ * a vendor's computer, as Settings → Computers says (its opening sentence is the same); on a machine the person runs,
65
+ * compose.yaml at the repository's root mounts the host's socket, which is root on that host (compose.yaml's own header
66
+ * says so), so the words say that too. */
67
+ export declare const DOCKER_NO_SOCKET = "No Docker on this server: Render and most hosted services run none. Its agents get file tools and web_fetch but no shell. For a shell, use a vendor computer (Settings \u2192 Computers); or, on a machine you run, give this server the host's Docker socket, as `docker compose up -d` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root";
49
68
  /** The same, for a container given the socket and refused it: the group compose.yaml adds (DOCKER_GID) is not the
50
69
  * socket's. usermod in the container would not last past its restart. */
51
70
  export declare const DOCKER_SOCKET_GROUP = "This server's container may not use the Docker socket: set DOCKER_GID in .env to the socket's group, as compose.yaml says, then run `docker compose up -d` again";
52
- /** Whether this server runs in a container, whether it is AgentRun's own image (IMAGE_ENV), and how it tells whether a
53
- * path is there (`exists`: the socket a failed probe names). What a failed probe says to do. */
71
+ /** Where this server runs: on a host, in AgentRun's own image (IMAGE_ENV), or in some other container; and how it tells
72
+ * whether a path is there (`exists`: the socket a failed probe names). What a failed probe says to do. */
54
73
  export type ContainerFacts = {
55
- inside: boolean;
56
- image?: boolean;
74
+ where: "host" | "image" | "other";
57
75
  exists?: (path: string) => boolean;
58
76
  };
59
77
  /** Set by AgentRun's image (packages/serve/docker/Dockerfile): the socket advice (DOCKER_NO_SOCKET, DOCKER_SOCKET_GROUP)
60
78
  * is for it alone, and Kubernetes and other containerd runtimes, which write no mark of their own, run it too. */
61
79
  export declare const IMAGE_ENV = "AGENTRUN_IN_IMAGE";
62
- /** A container: AgentRun's image (IMAGE_ENV), or a runtime's mark (/.dockerenv, Podman's /run/.containerenv), which alone
63
- * is some other container (a dev container). */
64
- export declare const containerOf: (env: NodeJS.ProcessEnv, exists?: (path: string) => boolean) => ContainerFacts;
80
+ /** A container: AgentRun's image (IMAGE_ENV), or any other that computer's containerSigns sees under `root` (the
81
+ * filesystem's root; the tests' seam): a runtime's mark or a container's cgroup, such as a Kubernetes pod's. */
82
+ export declare const containerOf: (env: NodeJS.ProcessEnv, root?: string) => ContainerFacts;
65
83
  /** How long Docker's probe may take. */
66
84
  export declare const PROBE_TIMEOUT_MS = 5000;
67
85
  /** What `docker version` says of this machine's Docker daemon: it answers (`up`), or why not. `absent`: no daemon
@@ -97,23 +115,26 @@ export type PlaceOffersOptions = {
97
115
  /** Whether this server runs in a container, and how a path is checked, which say a failed probe's fix (containerReason);
98
116
  * default this process's. */
99
117
  container?: ContainerFacts;
100
- /** Under --faux only: Docker answers, whatever AGENTRUN_BOXES lists, and nothing asks it. */
118
+ /** Under --faux only: the local box answers, whatever AGENTRUN_BOXES lists, and nothing asks Docker. */
101
119
  fauxDocker?: boolean;
102
120
  /** Told the architecture of the Docker daemon the probe found (amd64, arm64), when Docker answers and names it: the
103
121
  * server's check that a Docker computer's daemon is built for it (box-paths.ts dockerComputerRefusal) asks Docker
104
122
  * nothing more. */
105
123
  dockerArch?: (arch: string) => void;
106
124
  };
107
- /** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box AGENTRUN_BOXES does not list is not enabled; docker by its probe (or `fauxDocker`); daytona
108
- * 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. */
125
+ /** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box
126
+ * AGENTRUN_BOXES does not list is not enabled; a local box by Docker's probe (or `fauxDocker`); a vendor's by its
127
+ * provider's required keys. Rejects only for a name in AGENTRUN_BOXES that is no box. No reason holds a key or an
128
+ * answer's body. */
109
129
  export declare function placeOffers(env: NodeJS.ProcessEnv, options?: PlaceOffersOptions): Promise<BoxOffer[]>;
110
- /** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf): Docker's
130
+ /** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf). A local box's
111
131
  * computers through their egress proxy (an allowlist), with the Docker host's own addresses it refuses when the server
112
- * runs in a container (`hostAddresses`), or unavailable where `dockerRefused` says Docker can't run a computer here
113
- * (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses); Daytona's and Modal's through the
114
- * egress proxy their computer's init starts (an allowlist too: @parcha/agentrun-computer's hosted/network.ts). With
115
- * `allow` none, none has a network. */
116
- export declare function withNetworks(offers: readonly BoxOffer[], allow: readonly string[] | "none", docker?: {
132
+ * runs in a container (`local.hostAddresses`), or unavailable where `local.refused` says Docker can't run a computer
133
+ * here (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses). A vendor's box as its provider's
134
+ * network forms say: the list where its computers keep to one, through the egress proxy their init starts
135
+ * (@parcha/agentrun-computer's hosted/network.ts); nothing where they make no network but none, as the claim narrows
136
+ * them (computer-deps.ts networkOf), saying so. With `allow` none, none has a network. */
137
+ export declare function withNetworks(offers: readonly BoxOffer[], allow: readonly string[] | "none", local?: {
117
138
  refused?: string;
118
139
  hostAddresses?: readonly string[];
119
140
  faux?: boolean;
@@ -1,42 +1,65 @@
1
1
  // The boxes a place may name, as capabilities show them (places.boxes), read from the computers runs execute on: a
2
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.
3
+ // starts (workspace/). Which providers are boxes is their descriptors' facts (isBox), never a list of names. Read once,
4
+ // at the server's start: each fix takes a restart.
4
5
  //
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.
6
+ // AGENTRUN_BOXES lists the boxes to set up. Not set at all, it is the boxes on this machine's container engine alone
7
+ // (LOCAL_BOXES, Docker's): a plain start probes Docker and offers it when Docker answers, so a new agent lands in its box
8
+ // (place.ts); every other box is the operator's to list. Set, it wins: a box it does not list is never probed and is
9
+ // unavailable, its reason naming the setting that lists it, an empty value or `none` sets up no box, and a name in it
10
+ // that is no box refuses the start. Every reason says what to do next. A local box is probed (`docker version`); a
11
+ // vendor's box is offered when the keys its computer provider requires are set (the server's environment, else saved in
12
+ // Settings → Computers), and is not asked anything at the start: a key the vendor refuses fails the run's computer
13
+ // start, in the vendor's words.
12
14
  import { execFile } from "node:child_process";
13
15
  import { existsSync } from "node:fs";
14
16
  import { readFile } from "node:fs/promises";
15
17
  import { userInfo } from "node:os";
16
- import { PROVIDERS } from "@parcha/agentrun-computer";
18
+ import { containerSigns, PROVIDERS } from "@parcha/agentrun-computer";
19
+ import { BOX_ALLOW_ENV } from "./box-settings.js";
17
20
  import { withoutSecrets } from "./secrets.js";
18
- /** Every box a place may name, in the order capabilities lists them. */
19
- export const BOX_IDS = ["docker", "modal", "daytona"];
21
+ /**
22
+ * Whether a computer provider can be a box, read from its descriptor's facts (PROVIDERS' entry). A place names a box
23
+ * alone, no kind, image or network, so a run in it gets a sandbox computer on that provider with no image named
24
+ * (computer-setting.ts computerOfPlace), resolved and started by the claim as any computer setting is
25
+ * (workspace/resolve-computer.ts, computer-deps.ts computerSpecOf), and it needs:
26
+ * - a Linux shell with files and processes, for bash and the background tools: the provider serves the sandbox kind;
27
+ * - the run's folder in that shell: it takes a bind, an Archil mount or a synced folder (its derived mounts; a provider
28
+ * whose machines keep their own disk where the folder would be takes none);
29
+ * - an image with none named: its default sandbox image, or the one its prepareImage() makes;
30
+ * - what places.allow says: its computers keep to a host list, or reach nothing (its network forms hold allow or none).
31
+ * One that reaches only its vendor's own network can't be held to the list.
32
+ * Which mode's folder it takes (a bind in Mode 1, Archil or a synced one in Mode 2) is the run's start's check, as for
33
+ * any computer setting: the mode can change while the server runs.
34
+ */
35
+ export const isBox = (entry) => entry.kinds.includes("sandbox") &&
36
+ entry.mounts.length > 0 &&
37
+ (entry.defaultImage?.sandbox !== undefined || entry.prepareImage === true) &&
38
+ (entry.network.includes("allow") || entry.network.includes("none"));
39
+ /** Every box a place may name, in the order capabilities lists them (Settings' order of providers). */
40
+ export const BOX_IDS = PROVIDERS.filter(isBox).map((entry) => entry.id);
41
+ /** The provider entry of box `id`. */
42
+ const boxEntry = (id) => PROVIDERS.find((entry) => entry.id === id);
43
+ /** The boxes on this machine's container engine (their descriptor's `local`: Docker's), the boxes a server sets up when
44
+ * AGENTRUN_BOXES is not set at all. Their engine is Docker, so a local box is probed at the start with `docker
45
+ * version` (probeDocker), its computers mount this server's paths (box-paths.ts) and keep out the Docker host's own
46
+ * addresses (docker-host-addresses.ts). */
47
+ export const LOCAL_BOXES = BOX_IDS.filter((id) => boxEntry(id).local === true);
20
48
  /** What an available box reaches: the hosts of `places.allow` (`allowlist`), or nothing (`none`). */
21
49
  export const BOX_NETWORKS = ["allowlist", "none"];
22
50
  /** A box's state in capabilities: ready (available) or unavailable. */
23
51
  export const BOX_STATES = ["ready", "unavailable"];
24
- /** The remote boxes' keys: secrets the server holds and its computer providers read, which no run is handed
25
- * (run-secrets.ts SERVER_ONLY). */
26
- export const BOX_KEYS = ["DAYTONA_API_KEY", "MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET"];
27
52
  /** The setting that lists the boxes to set up: a comma list of box ids, empty or `none` for no box. */
28
53
  export const BOXES_ENV = "AGENTRUN_BOXES";
29
- /** The boxes a server sets up when AGENTRUN_BOXES is not set at all: Docker, probed as if listed. */
30
- export const DEFAULT_BOXES = ["docker"];
31
54
  /** The AGENTRUN_BOXES that sets up no box, as an empty one does. */
32
55
  const NO_BOXES = "none";
33
- /** Whether `env` leaves the boxes to this server's default (DEFAULT_BOXES): AGENTRUN_BOXES is not set at all. */
56
+ /** Whether `env` leaves the boxes to this server's default (LOCAL_BOXES): AGENTRUN_BOXES is not set at all. */
34
57
  export const boxesByDefault = (env) => env[BOXES_ENV] === undefined;
35
- /** The boxes `env` lists in AGENTRUN_BOXES, DEFAULT_BOXES when it is not set, none when it is empty or `none`; a name
58
+ /** The boxes `env` lists in AGENTRUN_BOXES, LOCAL_BOXES when it is not set, none when it is empty or `none`; a name
36
59
  * that is no box throws, naming it, and so does `none` with another. */
37
60
  export function enabledBoxes(env) {
38
61
  if (boxesByDefault(env))
39
- return new Set(DEFAULT_BOXES);
62
+ return new Set(LOCAL_BOXES);
40
63
  const names = env[BOXES_ENV].split(",").map((name) => name.trim()).filter(Boolean);
41
64
  if (names.includes(NO_BOXES)) {
42
65
  if (names.length > 1)
@@ -82,26 +105,29 @@ const ownGroups = () => {
82
105
  catch { }
83
106
  return { file: "/etc/group", user, ids: process.getgroups?.() ?? [] };
84
107
  };
85
- /** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: the one-container `docker run`,
86
- * deploy/'s compose file and a Kubernetes pod give it none, so it asks a daemon that is not there. Starting Docker or
87
- * joining its group would not help: compose.yaml at the repository's root mounts the host's socket, which is root on
88
- * that host (compose.yaml's own header says so), so the words say that too. */
89
- export const DOCKER_NO_SOCKET = "This server runs in a container with no Docker socket, so its agents get file tools and web_fetch but no shell: for a shell in Docker sandboxes, give it the host's Docker socket, as `docker compose up -d` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root";
108
+ /** No Docker daemon for this server, as Settings → Computers says it (docker-daemon.ts noDockerWords). */
109
+ export const NO_DOCKER_HERE = "No Docker on this server: Render and most hosted services run none.";
110
+ /** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: a hosted service (Fly.io, Render,
111
+ * a Kubernetes pod), the one-container `docker run` and deploy/'s compose file give it none, so it asks a daemon that is
112
+ * not there. Starting Docker or joining its group would not help. Hosted, there is no host socket to give, so the way is
113
+ * a vendor's computer, as Settings → Computers says (its opening sentence is the same); on a machine the person runs,
114
+ * compose.yaml at the repository's root mounts the host's socket, which is root on that host (compose.yaml's own header
115
+ * says so), so the words say that too. */
116
+ export const DOCKER_NO_SOCKET = `${NO_DOCKER_HERE} Its agents get file tools and web_fetch but no shell. For a shell, use a vendor computer (Settings → Computers); or, on a machine you run, give this server the host's Docker socket, as \`docker compose up -d\` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root`;
90
117
  /** The same, for a container given the socket and refused it: the group compose.yaml adds (DOCKER_GID) is not the
91
118
  * socket's. usermod in the container would not last past its restart. */
92
119
  export const DOCKER_SOCKET_GROUP = "This server's container may not use the Docker socket: set DOCKER_GID in .env to the socket's group, as compose.yaml says, then run `docker compose up -d` again";
93
120
  /** Set by AgentRun's image (packages/serve/docker/Dockerfile): the socket advice (DOCKER_NO_SOCKET, DOCKER_SOCKET_GROUP)
94
121
  * is for it alone, and Kubernetes and other containerd runtimes, which write no mark of their own, run it too. */
95
122
  export const IMAGE_ENV = "AGENTRUN_IN_IMAGE";
96
- /** A container: AgentRun's image (IMAGE_ENV), or a runtime's mark (/.dockerenv, Podman's /run/.containerenv), which alone
97
- * is some other container (a dev container). */
98
- export const containerOf = (env, exists = existsSync) => {
99
- const image = env[IMAGE_ENV] === "1";
100
- return { inside: image || exists("/.dockerenv") || exists("/run/.containerenv"), image };
101
- };
123
+ /** A container: AgentRun's image (IMAGE_ENV), or any other that computer's containerSigns sees under `root` (the
124
+ * filesystem's root; the tests' seam): a runtime's mark or a container's cgroup, such as a Kubernetes pod's. */
125
+ export const containerOf = (env, root = "/") => ({
126
+ where: env[IMAGE_ENV] === "1" ? "image" : containerSigns(root) !== undefined ? "other" : "host",
127
+ });
102
128
  /** A reason in a container that is not AgentRun's image: the host's words, said to be the container's (its own Docker, its
103
129
  * own docker group), never compose.yaml's, which is not there to use. */
104
- const inOtherContainer = (container, reason) => (container.inside && !container.image ? `This server runs in a container. ${reason}` : reason);
130
+ const inOtherContainer = (container, reason) => (container.where === "other" ? `This server runs in a container. ${reason}` : reason);
105
131
  /** The daemon address docker names when it cannot connect ("Cannot connect to the Docker daemon at unix:///….sock."):
106
132
  * the one its DOCKER_HOST or current context resolved to. Matched, never shown. */
107
133
  const DAEMON_AT = /docker daemon at ([a-z]+:\/\/\S+?)\.?(?:\s|$)/i;
@@ -117,7 +143,7 @@ function socketThere(endpoint, env, exists) {
117
143
  * a host and in another container (inOtherContainer), and for a socket that is there and whose daemon does not answer
118
144
  * (the host's Docker is down). */
119
145
  const containerReason = (answer, env, container) => {
120
- if (!container.inside || !container.image || answer.failed === undefined)
146
+ if (container.where !== "image" || answer.failed === undefined)
121
147
  return undefined;
122
148
  if (answer.denied)
123
149
  return DOCKER_SOCKET_GROUP;
@@ -149,13 +175,16 @@ export async function askDockerDaemon(env, signal, groups = ownGroups(), contain
149
175
  const code = error?.code;
150
176
  resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}), ...endpointIn(stderr) } : {}), out: String(stdout) });
151
177
  }));
152
- const absent = (reason) => ({ up: false, absent: true, reason: inOtherContainer(container, reason) });
178
+ // An absent daemon's reason is read by no one: Settings → Computers and a run's start say noDockerWords instead
179
+ // (computers.ts, resolve-computer.ts), so only a refused socket's words are said to be another container's.
180
+ const absent = (reason) => ({ up: false, absent: true, reason });
153
181
  // 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
154
182
  // first-time user's first read: what is wrong in plain words, what the probe saw, then what to do.
155
- // In a container, the fix is its socket or that socket's group (containerReason), never the host's.
156
- const inside = containerReason(answer, env, container);
183
+ // In AgentRun's image, a socket that refused this process is that socket's group's to fix (containerReason), never the
184
+ // host's; a socket that is not there is no daemon, which every reader words as none (noDockerWords).
185
+ const inside = answer.denied ? containerReason(answer, env, container) : undefined;
157
186
  if (inside !== undefined)
158
- return { up: false, absent: !answer.denied, reason: inside };
187
+ return { up: false, absent: false, reason: inside };
159
188
  if (answer.failed === "ENOENT")
160
189
  return absent("Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
161
190
  // Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
@@ -202,10 +231,10 @@ async function probeDocker(env, timeoutMs, groups, container, arch) {
202
231
  arch?.(named);
203
232
  return { id: "docker", available: true };
204
233
  }
205
- /** A remote box's offer: available when every key its computer provider requires is set, read as a run's claim reads
234
+ /** A vendor's box's offer: available when every key its computer provider requires is set, read as a run's claim reads
206
235
  * it (`keyOf`: the server's environment, else the key saved in Settings → Computers); nothing is asked of the vendor. */
207
236
  async function remoteOffer(id, keyOf) {
208
- const required = (PROVIDERS.find((entry) => entry.id === id)?.keys ?? []).filter((key) => key.required).map((key) => key.name);
237
+ const required = boxEntry(id).keys.filter((key) => key.required).map((key) => key.name);
209
238
  const missing = [];
210
239
  for (const name of required)
211
240
  if ((await keyOf(name)) === undefined)
@@ -214,41 +243,51 @@ async function remoteOffer(id, keyOf) {
214
243
  return { id, available: false, reason: `needs ${missing.join(" and ")}` };
215
244
  return { id, available: true, reason: "configured; not probed at start" };
216
245
  }
217
- /** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box AGENTRUN_BOXES does not list is not enabled; docker by its probe (or `fauxDocker`); daytona
218
- * 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. */
246
+ /** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box
247
+ * AGENTRUN_BOXES does not list is not enabled; a local box by Docker's probe (or `fauxDocker`); a vendor's by its
248
+ * provider's required keys. Rejects only for a name in AGENTRUN_BOXES that is no box. No reason holds a key or an
249
+ * answer's body. */
219
250
  export async function placeOffers(env, options = {}) {
220
251
  const enabled = enabledBoxes(env);
221
252
  const keyOf = options.keyOf ?? (async (name) => env[name] || undefined);
222
253
  return Promise.all(BOX_IDS.map(async (id) => {
254
+ const local = LOCAL_BOXES.includes(id);
223
255
  // The tests' faux docker stands in whatever AGENTRUN_BOXES lists, as the old faux box did.
224
- if (id === "docker" && options.fauxDocker)
256
+ if (local && options.fauxDocker)
225
257
  return { id, available: true, reason: "a faux docker (tests)" };
226
258
  if (!enabled.has(id))
227
259
  return { id, available: false, reason: notEnabled(id, enabled) };
228
- if (id === "docker")
260
+ // A local box's engine is Docker (LOCAL_BOXES), so its probe is Docker's own, which answers as the docker box.
261
+ if (local)
229
262
  return probeDocker(env, options.timeoutMs ?? PROBE_TIMEOUT_MS, options.groups ?? ownGroups(), options.container ?? containerOf(env), options.dockerArch);
230
263
  return remoteOffer(id, keyOf);
231
264
  }));
232
265
  }
233
- /** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf): Docker's
266
+ /** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf). A local box's
234
267
  * computers through their egress proxy (an allowlist), with the Docker host's own addresses it refuses when the server
235
- * runs in a container (`hostAddresses`), or unavailable where `dockerRefused` says Docker can't run a computer here
236
- * (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses); Daytona's and Modal's through the
237
- * egress proxy their computer's init starts (an allowlist too: @parcha/agentrun-computer's hosted/network.ts). With
238
- * `allow` none, none has a network. */
239
- export function withNetworks(offers, allow, docker = {}) {
268
+ * runs in a container (`local.hostAddresses`), or unavailable where `local.refused` says Docker can't run a computer
269
+ * here (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses). A vendor's box as its provider's
270
+ * network forms say: the list where its computers keep to one, through the egress proxy their init starts
271
+ * (@parcha/agentrun-computer's hosted/network.ts); nothing where they make no network but none, as the claim narrows
272
+ * them (computer-deps.ts networkOf), saying so. With `allow` none, none has a network. */
273
+ export function withNetworks(offers, allow, local = {}) {
240
274
  return offers.map((offer) => {
241
275
  if (!offer.available)
242
276
  return offer;
243
- if (offer.id === "docker") {
244
- if (docker.refused !== undefined)
245
- return { id: offer.id, available: false, state: "unavailable", reason: docker.refused };
246
- if (docker.faux)
277
+ if (LOCAL_BOXES.includes(offer.id)) {
278
+ if (local.refused !== undefined)
279
+ return { id: offer.id, available: false, state: "unavailable", reason: local.refused };
280
+ if (local.faux)
247
281
  return { ...offer, network: "none", network_reason: "a faux docker (tests)" };
248
282
  if (allow === "none")
249
283
  return { ...offer, network: "none", network_reason: "AGENTRUN_BOX_ALLOW is none" };
250
- return { ...offer, network: "allowlist", ...(docker.hostAddresses?.length ? { host_addresses: [...docker.hostAddresses] } : {}) };
284
+ return { ...offer, network: "allowlist", ...(local.hostAddresses?.length ? { host_addresses: [...local.hostAddresses] } : {}) };
251
285
  }
252
- return { ...offer, network: allow === "none" ? "none" : "allowlist" };
286
+ if (allow === "none")
287
+ return { ...offer, network: "none" };
288
+ const entry = boxEntry(offer.id);
289
+ if (entry.network.includes("allow"))
290
+ return { ...offer, network: "allowlist" };
291
+ return { ...offer, network: "none", network_reason: `${entry.label}'s computers run with no network, whatever ${BOX_ALLOW_ENV} lists` };
253
292
  });
254
293
  }
package/dist/place.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type BoxId, type BoxOffer } from "./place-offers.js";
1
+ import { 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];
@@ -6,15 +6,13 @@ export type Place = {
6
6
  mode: "runner";
7
7
  } | {
8
8
  mode: "sandbox";
9
- box: BoxId;
9
+ box: string;
10
10
  };
11
- /** The boxes runs execute in: the sandbox computers of Docker, Daytona and Modal. */
12
- export declare const RUN_BOXES: readonly BoxId[];
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. */
11
+ /** Every box, from what this server found at its start (place-offers.ts): one it did not find is not set up. */
15
12
  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; else none, so the agent runs on the runner as it did before, with
17
- * `reason` saying why, in docker's own words. A workflow is never given one. */
13
+ /** The place a new agentic definition that names none is saved with: the local box (Docker's) where this server has it;
14
+ * else none, so the agent runs on the runner as it did before, with `reason` saying why, in its probe's own words. A
15
+ * workflow is never given one. */
18
16
  export declare function newAgentPlace(registry: readonly BoxOffer[]): {
19
17
  place: Place;
20
18
  } | {
@@ -35,13 +33,14 @@ export declare function defaultPlaceOf(kind: "agentic" | "workflow", tools: read
35
33
  * this list to; written out here, since background.ts reads this module). A definition that names its tools, an empty
36
34
  * list included, keeps exactly those. */
37
35
  export declare const NEW_AGENT_TOOLS: readonly string[];
38
- /** Why a sandbox-only tool (bash) cannot run on this server: no box runs execute in is available, each with its reason.
39
- * Undefined when one is. */
40
- export declare function noBoxReason(registry: readonly BoxOffer[]): string | undefined;
36
+ /** Why a sandbox-only tool (bash) cannot run on this server: no box is available, each box AGENTRUN_BOXES lists
37
+ * (`listed`) with its reason, then the boxes it does not list. Undefined when one is. */
38
+ export declare function noBoxReason(registry: readonly BoxOffer[], listed: ReadonlySet<string>): string | undefined;
41
39
  /** The start banner's words on the boxes: which are ready for a sandbox agent's tools, then why each box is not that
42
- * AGENTRUN_BOXES lists (`listed`), or, when none is ready, each box runs execute in, with what to do.
43
- * `byDefault`, with AGENTRUN_BOXES not set at all: short, docker alone, said to be on by default, or why it is not. */
44
- export declare function boxesLine(registry: readonly BoxOffer[], listed: ReadonlySet<BoxId>, allow?: readonly string[] | "none", byDefault?: boolean): string;
40
+ * AGENTRUN_BOXES lists (`listed`), and, when none is ready, the boxes it does not list, with what to do.
41
+ * `byDefault`, with AGENTRUN_BOXES not set at all: short, the local box alone, said to be on by default, or why it is
42
+ * not. */
43
+ export declare function boxesLine(registry: readonly BoxOffer[], listed: ReadonlySet<string>, allow?: readonly string[] | "none", byDefault?: boolean): string;
45
44
  /** `places` in capabilities: the modes a revision may name, the place a new agent is saved with and a revision that
46
45
  * names none runs in (`default_place`, with `default_reason` when it is the runner), each box, and the hosts a box whose
47
46
  * `network` is `allowlist` reaches (`allow`, box-settings.ts boxAllowOf; empty for `none`). */