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

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 (381) hide show
  1. package/CHANGELOG.md +233 -0
  2. package/README.md +266 -201
  3. package/dist/adapters.d.ts +0 -4
  4. package/dist/adapters.js +11 -15
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/bash-read-only.d.ts +22 -0
  16. package/dist/bash-read-only.js +701 -0
  17. package/dist/box-settings.d.ts +3 -23
  18. package/dist/box-settings.js +7 -51
  19. package/dist/boxes.d.ts +17 -0
  20. package/dist/boxes.js +27 -20
  21. package/dist/browser-commands.d.ts +5 -2
  22. package/dist/browser-commands.js +4 -4
  23. package/dist/browser-computer.d.ts +5 -0
  24. package/dist/browser-computer.js +21 -0
  25. package/dist/browser-cost.d.ts +9 -6
  26. package/dist/browser-cost.js +92 -50
  27. package/dist/browser-live.d.ts +7 -20
  28. package/dist/browser-live.js +15 -93
  29. package/dist/browser-person.d.ts +18 -51
  30. package/dist/browser-person.js +94 -277
  31. package/dist/cap.d.ts +8 -5
  32. package/dist/cap.js +12 -5
  33. package/dist/cli.js +39 -13
  34. package/dist/closed-pipes.d.ts +2 -0
  35. package/dist/closed-pipes.js +13 -0
  36. package/dist/computer-commands.d.ts +2 -0
  37. package/dist/computer-commands.js +2 -0
  38. package/dist/computer-keys.js +5 -2
  39. package/dist/computer-setting.d.ts +20 -4
  40. package/dist/computer-setting.js +25 -5
  41. package/dist/computers.d.ts +30 -2
  42. package/dist/computers.js +70 -11
  43. package/dist/confine.d.ts +120 -0
  44. package/dist/confine.js +436 -0
  45. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  46. package/dist/console/assets/index-opTN5Naq.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decision-rows.d.ts +1 -1
  49. package/dist/decision-rows.js +1 -1
  50. package/dist/docker-daemon.d.ts +31 -0
  51. package/dist/docker-daemon.js +56 -0
  52. package/dist/effort-guidance.js +4 -3
  53. package/dist/environment.d.ts +0 -3
  54. package/dist/environment.js +3 -5
  55. package/dist/errors.d.ts +0 -2
  56. package/dist/errors.js +6 -9
  57. package/dist/filed-answer.d.ts +32 -0
  58. package/dist/filed-answer.js +160 -0
  59. package/dist/files.d.ts +1 -3
  60. package/dist/files.js +2 -4
  61. package/dist/github-connection.d.ts +1 -1
  62. package/dist/graph-view.d.ts +3 -5
  63. package/dist/graph-view.js +4 -14
  64. package/dist/handed-values.d.ts +9 -0
  65. package/dist/handed-values.js +26 -0
  66. package/dist/harness-install.d.ts +1 -7
  67. package/dist/harness-install.js +1 -18
  68. package/dist/harness-opencode/adapter.d.ts +7 -0
  69. package/dist/harness-opencode/adapter.js +23 -6
  70. package/dist/harness-opencode/index.d.ts +1 -1
  71. package/dist/harness-opencode/index.js +1 -1
  72. package/dist/harness-opencode/verify.d.ts +17 -0
  73. package/dist/harness-opencode/verify.js +30 -10
  74. package/dist/harness-table.js +6 -1
  75. package/dist/heard.js +1 -1
  76. package/dist/held-fd.d.ts +5 -0
  77. package/dist/held-fd.js +14 -0
  78. package/dist/host-calls.d.ts +20 -0
  79. package/dist/host-calls.js +12 -0
  80. package/dist/host-tools.d.ts +4 -21
  81. package/dist/host-tools.js +4 -61
  82. package/dist/host.d.ts +2 -4
  83. package/dist/host.js +2 -7
  84. package/dist/import-summary.d.ts +1 -5
  85. package/dist/import-summary.js +0 -21
  86. package/dist/import.d.ts +6 -6
  87. package/dist/import.js +14 -15
  88. package/dist/key-refusal.d.ts +5 -1
  89. package/dist/key-refusal.js +19 -4
  90. package/dist/learn/check.d.ts +6 -2
  91. package/dist/learn/check.js +83 -29
  92. package/dist/learn/folder.d.ts +5 -1
  93. package/dist/learn/folder.js +10 -3
  94. package/dist/learn/grade.d.ts +14 -0
  95. package/dist/learn/grade.js +68 -12
  96. package/dist/learn/index.d.ts +4 -4
  97. package/dist/learn/index.js +4 -4
  98. package/dist/learn/reflect.d.ts +31 -2
  99. package/dist/learn/reflect.js +79 -4
  100. package/dist/learn/relevance.d.ts +24 -0
  101. package/dist/learn/relevance.js +91 -0
  102. package/dist/learn/secrets.d.ts +7 -1
  103. package/dist/learn/secrets.js +86 -19
  104. package/dist/learn/skills.d.ts +112 -14
  105. package/dist/learn/skills.js +556 -52
  106. package/dist/learned-workflow.d.ts +32 -1
  107. package/dist/learned-workflow.js +100 -9
  108. package/dist/learning-routes.d.ts +8 -4
  109. package/dist/learning-routes.js +23 -9
  110. package/dist/learning-run.d.ts +9 -26
  111. package/dist/learning-run.js +22 -32
  112. package/dist/learning-words.d.ts +12 -5
  113. package/dist/learning-words.js +18 -9
  114. package/dist/learning.d.ts +93 -77
  115. package/dist/learning.js +176 -304
  116. package/dist/live/stream.js +1 -1
  117. package/dist/live/translate.js +12 -2
  118. package/dist/local-models.d.ts +11 -5
  119. package/dist/local-models.js +13 -8
  120. package/dist/mcp-gateway.d.ts +11 -49
  121. package/dist/mcp-gateway.js +44 -135
  122. package/dist/mcp-oauth.d.ts +10 -14
  123. package/dist/mcp-oauth.js +14 -32
  124. package/dist/mcp-probe.d.ts +0 -7
  125. package/dist/mcp-probe.js +4 -10
  126. package/dist/mcp-servers-store.d.ts +6 -6
  127. package/dist/mcp-servers-store.js +12 -14
  128. package/dist/mcp-store.js +3 -4
  129. package/dist/mcp.js +4 -3
  130. package/dist/model.d.ts +6 -7
  131. package/dist/model.js +43 -27
  132. package/dist/monid.d.ts +0 -2
  133. package/dist/monid.js +3 -6
  134. package/dist/openapi.d.ts +8 -1
  135. package/dist/openapi.js +121 -47
  136. package/dist/page.d.ts +1 -3
  137. package/dist/page.js +6 -18
  138. package/dist/paid-calls.d.ts +21 -27
  139. package/dist/paid-calls.js +25 -60
  140. package/dist/propose.js +83 -39
  141. package/dist/push-handler.d.ts +1 -1
  142. package/dist/reflect-range.d.ts +25 -0
  143. package/dist/reflect-range.js +30 -0
  144. package/dist/refusal-words.d.ts +5 -1
  145. package/dist/refusal-words.js +5 -1
  146. package/dist/rows.d.ts +1 -1
  147. package/dist/run-cut.d.ts +0 -6
  148. package/dist/run-cut.js +0 -6
  149. package/dist/run-db.d.ts +2 -11
  150. package/dist/run-db.js +2 -37
  151. package/dist/run-launch.d.ts +19 -2
  152. package/dist/run-launch.js +13 -5
  153. package/dist/run-learning-served.d.ts +10 -4
  154. package/dist/run-learning-served.js +23 -13
  155. package/dist/run-reads-over-store.d.ts +1 -1
  156. package/dist/run-reads-over-store.js +15 -6
  157. package/dist/run-secrets.d.ts +1 -1
  158. package/dist/run-timeline-served.d.ts +5 -1
  159. package/dist/run-timeline-served.js +15 -4
  160. package/dist/run-view.d.ts +7 -8
  161. package/dist/run-view.js +26 -7
  162. package/dist/runnable.d.ts +18 -10
  163. package/dist/runnable.js +21 -10
  164. package/dist/runner/adapter-loop.d.ts +6 -1
  165. package/dist/runner/adapter-loop.js +423 -53
  166. package/dist/runner/adapter-run-spec.d.ts +21 -8
  167. package/dist/runner/adapter-run-spec.js +90 -32
  168. package/dist/runner/adapters/index.js +11 -1
  169. package/dist/runner/adapters/pi.d.ts +12 -2
  170. package/dist/runner/adapters/pi.js +16 -5
  171. package/dist/runner/beside.d.ts +30 -3
  172. package/dist/runner/beside.js +36 -5
  173. package/dist/runner/claim-secrets.d.ts +10 -1
  174. package/dist/runner/claim-secrets.js +48 -14
  175. package/dist/runner/cli-run-spec.d.ts +2 -0
  176. package/dist/runner/cli-run-spec.js +45 -16
  177. package/dist/runner/commands.js +1 -1
  178. package/dist/runner/computer-journal.d.ts +15 -2
  179. package/dist/runner/computer-journal.js +41 -5
  180. package/dist/runner/conformance/harness.js +118 -8
  181. package/dist/runner/conformance/subject.d.ts +4 -1
  182. package/dist/runner/dispatch.d.ts +8 -1
  183. package/dist/runner/dispatch.js +81 -7
  184. package/dist/runner/end-of-run.d.ts +8 -2
  185. package/dist/runner/end-of-run.js +10 -4
  186. package/dist/runner/github-app.js +1 -1
  187. package/dist/runner/harness-loops.d.ts +9 -1
  188. package/dist/runner/harness-loops.js +15 -2
  189. package/dist/runner/journal-kinds.d.ts +24 -6
  190. package/dist/runner/journal-kinds.js +20 -5
  191. package/dist/runner/journal-reader.d.ts +1 -1
  192. package/dist/runner/journal-reader.js +2 -2
  193. package/dist/runner/learning-ask.d.ts +4 -0
  194. package/dist/runner/learning-ask.js +15 -1
  195. package/dist/runner/learning-end.d.ts +18 -3
  196. package/dist/runner/learning-end.js +113 -11
  197. package/dist/runner/learning-loop.d.ts +5 -0
  198. package/dist/runner/learning-loop.js +26 -6
  199. package/dist/runner/main.d.ts +56 -9
  200. package/dist/runner/main.js +127 -18
  201. package/dist/runner/mcp-claim.js +1 -2
  202. package/dist/runner/mcp-run.d.ts +2 -0
  203. package/dist/runner/mcp-run.js +15 -5
  204. package/dist/runner/memory-claim.d.ts +9 -0
  205. package/dist/runner/memory-claim.js +25 -0
  206. package/dist/runner/metrics.d.ts +33 -1
  207. package/dist/runner/metrics.js +85 -1
  208. package/dist/runner/model-route.d.ts +13 -0
  209. package/dist/runner/model-route.js +133 -9
  210. package/dist/runner/reflect-hook.d.ts +12 -1
  211. package/dist/runner/reflect-hook.js +33 -3
  212. package/dist/runner/runner.d.ts +20 -0
  213. package/dist/runner/runner.js +56 -10
  214. package/dist/runner/store-port.d.ts +1 -1
  215. package/dist/runner/store-secrets.d.ts +3 -3
  216. package/dist/runner/store-secrets.js +8 -12
  217. package/dist/runner/text-tools.d.ts +44 -0
  218. package/dist/runner/text-tools.js +237 -0
  219. package/dist/runner/workflow-loop.d.ts +6 -0
  220. package/dist/runner/workflow-loop.js +6 -4
  221. package/dist/runner/workflow-spec.d.ts +18 -0
  222. package/dist/runner/workflow-spec.js +63 -17
  223. package/dist/runs-over-store.d.ts +7 -2
  224. package/dist/runs-over-store.js +60 -14
  225. package/dist/seal-key.js +5 -43
  226. package/dist/sealed-settings-store.d.ts +19 -4
  227. package/dist/sealed-settings-store.js +9 -9
  228. package/dist/sealing.d.ts +4 -0
  229. package/dist/sealing.js +20 -0
  230. package/dist/secret-cut.d.ts +1 -1
  231. package/dist/secret-cut.js +1 -1
  232. package/dist/secret-name.d.ts +9 -0
  233. package/dist/secret-name.js +15 -0
  234. package/dist/secret-writes.d.ts +0 -1
  235. package/dist/secret-writes.js +0 -1
  236. package/dist/server-fs.d.ts +4 -0
  237. package/dist/server-fs.js +8 -2
  238. package/dist/server-lock.d.ts +0 -24
  239. package/dist/server-lock.js +1 -80
  240. package/dist/server-secrets-store.d.ts +4 -4
  241. package/dist/server-secrets-store.js +9 -31
  242. package/dist/server-secrets.d.ts +4 -9
  243. package/dist/server-secrets.js +12 -36
  244. package/dist/server.d.ts +16 -38
  245. package/dist/server.js +145 -106
  246. package/dist/sign-ins-store.d.ts +34 -36
  247. package/dist/sign-ins-store.js +27 -38
  248. package/dist/sign-ins.d.ts +2 -119
  249. package/dist/sign-ins.js +5 -311
  250. package/dist/standard-webhooks.d.ts +1 -1
  251. package/dist/standard-webhooks.js +1 -1
  252. package/dist/stats.d.ts +3 -2
  253. package/dist/stats.js +1 -1
  254. package/dist/store/agent-body.d.ts +8 -2
  255. package/dist/store/agent-body.js +16 -4
  256. package/dist/store/index.d.ts +2 -2
  257. package/dist/store/index.js +2 -2
  258. package/dist/store/open.d.ts +6 -3
  259. package/dist/store/open.js +2 -2
  260. package/dist/store/postgres/connection.d.ts +18 -2
  261. package/dist/store/postgres/connection.js +156 -32
  262. package/dist/store/postgres/migrate.d.ts +4 -0
  263. package/dist/store/postgres/migrate.js +9 -2
  264. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  265. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  266. package/dist/store/postgres/store.d.ts +9 -2
  267. package/dist/store/postgres/store.js +9 -0
  268. package/dist/store/schema.js +1 -1
  269. package/dist/store/seal.js +2 -2
  270. package/dist/store/sqlite/connection.js +49 -5
  271. package/dist/store/sqlite/run-patch.d.ts +3 -0
  272. package/dist/store/sqlite/run-patch.js +3 -0
  273. package/dist/store/sqlite/store.js +41 -12
  274. package/dist/store/store.d.ts +35 -6
  275. package/dist/store/store.js +12 -2
  276. package/dist/store-reads/cap.d.ts +1 -1
  277. package/dist/store-reads/cap.js +22 -4
  278. package/dist/store-reads/journal.d.ts +9 -6
  279. package/dist/store-reads/journal.js +93 -17
  280. package/dist/store-reads/learning.d.ts +26 -8
  281. package/dist/store-reads/learning.js +12 -4
  282. package/dist/store-reads/workflow.d.ts +1 -1
  283. package/dist/store-reads/workflow.js +1 -1
  284. package/dist/store-view.d.ts +5 -1
  285. package/dist/store-view.js +53 -18
  286. package/dist/template-eval.d.ts +60 -4
  287. package/dist/template-eval.js +120 -54
  288. package/dist/templates.d.ts +24 -10
  289. package/dist/templates.js +69 -38
  290. package/dist/timeline/group.d.ts +33 -0
  291. package/dist/timeline/group.js +77 -0
  292. package/dist/timeline/index.d.ts +7 -0
  293. package/dist/timeline/index.js +7 -0
  294. package/dist/timeline/labels.d.ts +79 -0
  295. package/dist/timeline/labels.js +150 -0
  296. package/dist/timeline/origin.d.ts +56 -0
  297. package/dist/timeline/origin.js +92 -0
  298. package/dist/timeline/render-text.d.ts +11 -0
  299. package/dist/timeline/render-text.js +62 -0
  300. package/dist/timeline/timeline.d.ts +274 -0
  301. package/dist/timeline/timeline.js +1308 -0
  302. package/dist/timeline/util.d.ts +17 -0
  303. package/dist/timeline/util.js +49 -0
  304. package/dist/tool-gate.d.ts +41 -216
  305. package/dist/tool-gate.js +79 -540
  306. package/dist/tool-keys-store.d.ts +11 -12
  307. package/dist/tool-keys-store.js +24 -31
  308. package/dist/tool-keys.d.ts +5 -101
  309. package/dist/tool-keys.js +8 -267
  310. package/dist/tool-plane.d.ts +14 -42
  311. package/dist/tool-plane.js +23 -81
  312. package/dist/tool-settings-store.d.ts +1 -2
  313. package/dist/tool-settings-store.js +5 -8
  314. package/dist/tools.d.ts +30 -18
  315. package/dist/tools.js +97 -107
  316. package/dist/trigger-adapter.d.ts +2 -2
  317. package/dist/trigger-targets.d.ts +13 -1
  318. package/dist/trigger-targets.js +31 -1
  319. package/dist/triggers.d.ts +2 -2
  320. package/dist/triggers.js +3 -3
  321. package/dist/turn-end.d.ts +1 -1
  322. package/dist/turn-end.js +1 -1
  323. package/dist/turns.d.ts +0 -6
  324. package/dist/turns.js +0 -19
  325. package/dist/uploads.js +1 -1
  326. package/dist/usage.d.ts +0 -2
  327. package/dist/usage.js +0 -2
  328. package/dist/validate.d.ts +2 -0
  329. package/dist/validate.js +23 -14
  330. package/dist/webhooks.d.ts +102 -76
  331. package/dist/webhooks.js +266 -233
  332. package/dist/workflow-run.d.ts +114 -0
  333. package/dist/workflow-run.js +144 -0
  334. package/dist/workspace/beneath.d.ts +19 -0
  335. package/dist/workspace/beneath.js +106 -0
  336. package/dist/workspace/computer-deps.d.ts +24 -6
  337. package/dist/workspace/computer-deps.js +108 -20
  338. package/dist/workspace/computer-for-claim.d.ts +12 -11
  339. package/dist/workspace/computer-for-claim.js +76 -15
  340. package/dist/workspace/computer-hold.d.ts +6 -1
  341. package/dist/workspace/computer-hold.js +6 -1
  342. package/dist/workspace/computer-janitor.d.ts +47 -0
  343. package/dist/workspace/computer-janitor.js +182 -0
  344. package/dist/workspace/grep-worker.d.ts +5 -0
  345. package/dist/workspace/grep-worker.js +9 -6
  346. package/dist/workspace/index.d.ts +3 -2
  347. package/dist/workspace/index.js +3 -3
  348. package/dist/workspace/local.d.ts +11 -2
  349. package/dist/workspace/local.js +161 -43
  350. package/dist/workspace/resolve-computer.d.ts +50 -10
  351. package/dist/workspace/resolve-computer.js +46 -11
  352. package/dist/workspace/run-tools.d.ts +13 -31
  353. package/dist/workspace/run-tools.js +10 -27
  354. package/dist/workspace-paths.d.ts +0 -17
  355. package/dist/workspace-paths.js +1 -41
  356. package/dist/workspace.d.ts +0 -14
  357. package/dist/workspace.js +3 -96
  358. package/package.json +13 -13
  359. package/templates/README.md +9 -3
  360. package/templates/market-monitor/agent.md +2 -2
  361. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  362. package/dist/bound-files.d.ts +0 -4
  363. package/dist/bound-files.js +0 -164
  364. package/dist/coding-tools.d.ts +0 -47
  365. package/dist/coding-tools.js +0 -189
  366. package/dist/computer-adb.d.ts +0 -12
  367. package/dist/computer-adb.js +0 -14
  368. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  369. package/dist/console/assets/index-DvW6Aled.css +0 -1
  370. package/dist/grade.d.ts +0 -63
  371. package/dist/grade.js +0 -150
  372. package/dist/mcp-servers.d.ts +0 -269
  373. package/dist/mcp-servers.js +0 -456
  374. package/dist/packs.d.ts +0 -71
  375. package/dist/packs.js +0 -180
  376. package/dist/sealed-settings.d.ts +0 -60
  377. package/dist/sealed-settings.js +0 -171
  378. package/dist/sessions.d.ts +0 -6
  379. package/dist/sessions.js +0 -109
  380. package/dist/workspace/computer-serves.d.ts +0 -12
  381. package/dist/workspace/computer-serves.js +0 -15
package/dist/cli.js CHANGED
@@ -16,14 +16,18 @@ import { canOpen } from "./host.js";
16
16
  import { resetPassword } from "./owner.js";
17
17
  import { banner, boxImageLine } from "./print.js";
18
18
  import { DEFAULT_PORT, fauxEnvOf, startServe } from "./server.js";
19
- import { runnerBeside } from "./runner/beside.js";
19
+ import { besideRunnerOptions, besideStopping, runnerBeside } from "./runner/beside.js";
20
20
  import { apiOnlyFrom } from "./api-only.js";
21
+ import { surviveClosedPipes } from "./closed-pipes.js";
22
+ // A stdout or stderr its reader closed loses the lines written after, never the process (closed-pipes.ts): for every
23
+ // command, the server and the runner alike.
24
+ surviveClosedPipes();
21
25
  const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL] [--no-runner]
22
26
  agentrun-serve reset-password [--data DIR]
23
27
  agentrun-serve validate-template DIR
24
28
  agentrun-serve eval-template DIR [--case NAME ...] [--runs N] [--server URL] [--grader-model PROVIDER/MODEL] [--report FILE] [--faux MODULE]
25
29
  agentrun-serve import [--data DIR] [--from claude-code,codex,pi] [--dry-run] [--include-deleted] [--all] [--verbose] [--port N]
26
- agentrun-serve runner --data DIR [--loops N] [--name NAME]
30
+ agentrun-serve runner --data DIR [--loops N] [--drain-timeout D] [--name NAME]
27
31
  agentrun-serve runner --check --data DIR [--name NAME]
28
32
 
29
33
  --data DIR the agent store and its runs (default ~/.local/share/agentrun/agents); the token is DIR/.token, mode 0600
@@ -37,14 +41,16 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
37
41
  with --faux only: the browser tool's provider and driver from MODULE's default export (a fake
38
42
  browser, no vendor, no key), for the console's real-browser tests
39
43
  --allow-host NAME another Host name to accept (repeatable)
40
- --max-runs N the most runs at once (default AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory
41
- holds); each run also reserves its harness's memory, and over either a new run is 429
44
+ --max-runs N the most runs the runner beside the server holds at once, the rest waiting queued (default
45
+ AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory holds); the capabilities'
46
+ max_concurrent_runs says the same
42
47
  --documents DIR a read-only directory of documents a workflow's pdf_pages calls read by file name (default
43
48
  AGENTRUN_SERVE_DOCUMENTS)
44
49
  --allow-code-nodes run workflows' code nodes, in the run's process with no sandbox (default off, or
45
50
  AGENTRUN_SERVE_CODE_NODES=1); off, a workflow with one saves with a warning and its runs are refused
46
- --drain-timeout D how long a busy run may finish its turn when the server stops (default 30s; the image's is 6s, inside
47
- Docker's 10 s grace); a run cut off resumes at the next start
51
+ --drain-timeout D how long the runner beside the server lets each busy run finish its turn when the server stops
52
+ (default 30s; the image's is 6s, inside Docker's 10 s grace); a run still busy then is stopped and
53
+ resumes at the next start
48
54
  --learning on|off whether runs learn (default on, or AGENTRUN_SERVE_LEARNING): on, a run of an agent whose definition
49
55
  says learning: true starts from what that agent learned and adds to it; off, no run does
50
56
  --learning-budget BYTES how much of what an agent learned its run's instructions hold (default
@@ -53,7 +59,10 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
53
59
  --grade-model MODEL the model that grades what a run proposes to learn (default AGENTRUN_SERVE_GRADE_MODEL, else the
54
60
  strong tier, AGENT_MODEL_STRONG, else each run's own model), named as the strong tier takes one
55
61
  --no-runner run the server alone, with no runner beside it (default: one runner beside the server); start one or
56
- more \`agentrun-serve runner --data DIR\` processes on the same data directory to claim and run runs
62
+ more \`agentrun-serve runner --data DIR\` processes on the same data directory to claim and run runs;
63
+ each holds at most --loops N runs (default AGENTRUN_MAX_RUNS, else as many pi runs as its host's
64
+ memory holds; the rest wait queued) and on SIGTERM lets each busy run finish its turn for up to
65
+ --drain-timeout D (default AGENTRUN_DRAIN_TIMEOUT, else 6s), then hands the rest back to resume
57
66
 
58
67
  Without --faux, a revision's model ("provider/model-id", or AGENT_MODEL when it names none; a workflow node's tier maps
59
68
  to AGENT_MODEL_FAST or AGENT_MODEL_STRONG, each falling back to AGENT_MODEL) is served by pi-ai's providers with their
@@ -289,8 +298,6 @@ if (budget !== undefined && !/^\d+$/.test(budget)) {
289
298
  }
290
299
  const data = values.data ?? defaultData();
291
300
  const given = secret("AGENTRUN_TOKEN") || undefined;
292
- // A stdout its reader closed (a pipe left behind) loses the log lines, never the server.
293
- process.stdout.on("error", () => undefined);
294
301
  // AGENTRUN_API_ONLY=1: the run routes alone (api-only.ts), and no owner; a value that is neither on nor off stops here.
295
302
  let apiOnly;
296
303
  try {
@@ -324,6 +331,12 @@ const trustedProxies = (process.env.AGENTRUN_TRUSTED_PROXIES ?? "").split(",").m
324
331
  try {
325
332
  serve = await startServe(serveOptions = {
326
333
  onBoxImage,
334
+ // The owner lock on a Postgres store lost for good: this server can serve nothing more, so it exits non-zero and its
335
+ // platform starts it again, rather than answer 503 for as long as it runs.
336
+ onStoreLost: (error) => {
337
+ console.error(`agentrun-serve: ${error.message}`);
338
+ process.exit(1);
339
+ },
327
340
  data, port, ...(values.port === undefined ? { nextFreePort: true } : {}), ...(values.listen ? { host: values.listen } : {}), ...(given ? { token: given } : {}), ...(values.faux ? { faux: values.faux } : {}), ...(values["faux-browser"] ? { fauxBrowser: values["faux-browser"] } : {}), allowHosts: values["allow-host"],
328
341
  ...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
329
342
  ...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), ...(values["grade-model"] ? { gradeModel: values["grade-model"] } : {}), ...(budget !== undefined ? { learningBudget: Number(budget) } : {}), log: (line) => void process.stdout.write(`${line}\n`),
@@ -340,8 +353,11 @@ catch (error) {
340
353
  }
341
354
  // The start launches one runner beside the server on the same data dir (design: "server and runner"): it claims and runs
342
355
  // every run, sharing only the store. With --no-runner the server runs alone, so the operator starts one or more separate
343
- // `agentrun runner --data DIR` processes on the same data directory instead.
356
+ // `agentrun runner --data DIR` processes on the same data directory instead. The runner holds what the server's flags say
357
+ // (besideRunnerOptions): at most --max-runs runs at once, the rest waiting queued, and on the stop each busy run finishes
358
+ // its turn for up to --drain-timeout.
344
359
  let runnerProc;
360
+ const { loops, drainMs } = besideRunnerOptions(serveOptions, process.env);
345
361
  if (!values["no-runner"]) {
346
362
  try {
347
363
  // The beside-runner sees the server's test switches (server.ts fauxEnvOf: --faux and its modules), which the CLI hands
@@ -349,7 +365,8 @@ if (!values["no-runner"]) {
349
365
  // model up in pi-ai's own catalog and every run fails on its first request. A test switch this process inherited from
350
366
  // its shell is taken out first, as the server's own environment drops it (runner/main.ts besideRunEnv).
351
367
  const { besideRunEnv } = await import("./runner/main.js");
352
- runnerProc = await runnerBeside(data, { env: besideRunEnv(process.env, fauxEnvOf(serveOptions)) });
368
+ // With the computer janitor: what a crashed runner of this server left is ended (never under --faux).
369
+ runnerProc = await runnerBeside(data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true });
353
370
  }
354
371
  catch (error) {
355
372
  console.error(`agentrun-serve: the runner could not start: ${error.message}`);
@@ -379,8 +396,17 @@ const record = join(resolve(data), SERVER_FILE);
379
396
  // (stop-signals.ts). The stop is in place before the record is written: a SIGTERM sent the moment the record appears is
380
397
  // a clean stop that removes it, never the default end by signal that leaves it behind.
381
398
  const stop = stopOnSignals({
382
- close: () => (removeOwnRecord(record), Promise.all([runnerProc?.close() ?? Promise.resolve(), serve.close()]).then(() => undefined)),
383
- stopping: () => serve.stopping(),
399
+ close: () => {
400
+ removeOwnRecord(record);
401
+ // A drain that has runs to wait on says so, as a run's own process did on the server's stop.
402
+ const busy = runnerProc?.runner.held().length ?? 0;
403
+ if (busy > 0 && drainMs > 0)
404
+ console.error(`agentrun-serve: stopping: waiting up to ${Math.ceil(drainMs / 1000)} s for ${busy} ${busy === 1 ? "run" : "runs"} to finish ${busy === 1 ? "its turn" : "their turns"}`);
405
+ return Promise.all([runnerProc?.close() ?? Promise.resolve(), serve.close()]).then(() => undefined);
406
+ },
407
+ // The stop's deadline waits out the runner's whole close: its drain, then the stop of the loops left, so a run's end
408
+ // and release are never cut short (besideStopping).
409
+ stopping: () => (runnerProc ? besideStopping(serve.stopping(), runnerProc.runner.held().length, drainMs) : serve.stopping()),
384
410
  done: (code) => (removeOwnRecord(record), process.exit(code)),
385
411
  say: (line) => console.error(line),
386
412
  });
@@ -0,0 +1,2 @@
1
+ /** Keeps this process alive when its stdout or stderr reader has gone: EPIPE on either is dropped. */
2
+ export declare function surviveClosedPipes(streams?: readonly NodeJS.WriteStream[]): void;
@@ -0,0 +1,13 @@
1
+ // A stdout or stderr its reader closed (a terminal piped to `head`, a launcher that went away) loses the lines written
2
+ // after it, never the process. Without this, a write to it fails with EPIPE, emitted as an 'error' on the stream with no
3
+ // listener, which ends the server or a runner at its next line, console or raw write alike. Any other error on them is
4
+ // still thrown. cli.ts calls it first, for every command.
5
+ /** Keeps this process alive when its stdout or stderr reader has gone: EPIPE on either is dropped. */
6
+ export function surviveClosedPipes(streams = [process.stdout, process.stderr]) {
7
+ for (const stream of streams) {
8
+ stream.on("error", (error) => {
9
+ if (error.code !== "EPIPE")
10
+ throw error;
11
+ });
12
+ }
13
+ }
@@ -13,6 +13,8 @@ export declare const COMPUTER_HAND_BACK = "computer_hand_back";
13
13
  export declare const holdWords: (computer: ViewedKind) => {
14
14
  taken: string;
15
15
  ended: Record<Exclude<HoldEnd, "answered">, string>;
16
+ /** The agent is done while the person holds the computer: the run's end waits for the hand-back (#2134). */
17
+ ending: string;
16
18
  waiting: (instruction: string) => string;
17
19
  answered: Record<AskOutcome, string>;
18
20
  };
@@ -20,6 +20,8 @@ export const holdWords = (computer) => ({
20
20
  away: `The ${computer} went back to the agent: the live view was closed`,
21
21
  released: `The ${computer}'s session ended while you had it`,
22
22
  },
23
+ /** The agent is done while the person holds the computer: the run's end waits for the hand-back (#2134). */
24
+ ending: `The agent is done. The run ends when you hand the ${computer} back, or after ${HOLD_IDLE_MS / 60_000} minutes with no input from you`,
23
25
  waiting: (instruction) => `Waiting for you: ${instruction}`,
24
26
  answered: {
25
27
  done: "Done: the owner answered the agent's request.",
@@ -5,8 +5,8 @@
5
5
  // The map from a key's name to the option it fills is serve's, and lives here: E2B_API_KEY is E2B's apiKey, the Modal
6
6
  // token pair is the Modal client's tokenId and tokenSecret, and so on. A name a provider does not declare is never passed
7
7
  // on; an empty optional key is left out; a required one not saved refuses in words naming what to save, before anything
8
- // is made. The provider modules themselves (each one's create()) are passed in, as the rest of the computer package is
9
- // until the cutover makes it serve's dependency: a provider with no module here answers that its test is not available.
8
+ // is made. The provider modules themselves (each one's create()) are passed in (workspace/computer-providers.ts makes the
9
+ // computer package's; a test gives stand-ins): a provider with no module here answers that its test is not available.
10
10
  // No key is ever in an answer: each value is scrubbed from the provider's words, and the words this module adds name keys
11
11
  // only by their names.
12
12
  /** Each provider's keys, by the registry's names, and the option each fills. Docker takes none (its host is local). */
@@ -29,6 +29,8 @@ export const PROVIDER_KEYS = {
29
29
  { name: "BROWSERBASE_PROJECT_ID", option: "projectId", required: true },
30
30
  ],
31
31
  kernel: [{ name: "KERNEL_API_KEY", option: "apiKey", required: true }],
32
+ // This machine's Chrome: no key.
33
+ local: [],
32
34
  };
33
35
  /** Each provider's name in words (the registry's labels). */
34
36
  const LABELS = {
@@ -40,6 +42,7 @@ const LABELS = {
40
42
  "phone-harness": "Phone harness",
41
43
  browserbase: "Browserbase",
42
44
  kernel: "Kernel",
45
+ local: "Local Chrome",
43
46
  };
44
47
  /** The Modal app a server's computers live in when its settings name none (serve's box app until now). */
45
48
  export const DEFAULT_MODAL_APP = "agentrun";
@@ -2,13 +2,27 @@ import type { InputIssue } from "./errors.js";
2
2
  /** The kinds of computer an agent can be given. */
3
3
  export declare const COMPUTER_KINDS: readonly ["none", "sandbox", "desktop", "phone", "browser"];
4
4
  export type ComputerKind = (typeof COMPUTER_KINDS)[number];
5
- /** The setting as a revision keeps it. */
5
+ /** A sandbox's GPUs: a type its provider declares (GET /v2/computers lists each provider's) and how many. */
6
+ export type GpuSetting = {
7
+ readonly type: string;
8
+ readonly count: number;
9
+ };
10
+ /** The setting as a revision keeps it. A sandbox may ask for GPUs; whether its provider gives them is the claim's check. */
6
11
  export type ComputerSetting = {
7
12
  readonly kind: "none";
8
13
  } | {
9
- readonly kind: Exclude<ComputerKind, "none">;
14
+ readonly kind: "sandbox";
15
+ readonly provider: string;
16
+ readonly gpu?: GpuSetting;
17
+ } | {
18
+ readonly kind: Exclude<ComputerKind, "none" | "sandbox">;
10
19
  readonly provider: string;
11
20
  };
21
+ /** The GPUs a setting asks for, or undefined. */
22
+ export declare const gpuOf: (computer: {
23
+ readonly kind: string;
24
+ readonly gpu?: GpuSetting;
25
+ }) => GpuSetting | undefined;
12
26
  /** A place as the v2 API names it. */
13
27
  export type PlaceView = {
14
28
  mode: "runner";
@@ -20,9 +34,11 @@ export type PlaceView = {
20
34
  export declare const placeOfComputer: (computer: ComputerSetting) => PlaceView;
21
35
  /** The setting a place says: runner is no computer, a sandbox place a sandbox on its box. */
22
36
  export declare const computerOfPlace: (place: PlaceView) => ComputerSetting;
23
- /** Whether two settings are the one setting. */
37
+ /** Whether two settings are the one setting: the kind and the provider (a place says no GPUs, so they are not compared). */
24
38
  export declare const sameComputer: (a: ComputerSetting, b: ComputerSetting) => boolean;
25
- /** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). */
39
+ /** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). A
40
+ * sandbox's gpu is { type, count } in the words the computer package's checkGpu uses; whether its provider offers that
41
+ * type and count is the readiness check's and the claim's (resolve-computer.ts), in checkGpu's own words. */
26
42
  export declare function computerIssues(value: unknown, field: string): InputIssue[];
27
43
  /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
28
44
  * it says neither. Each is checked already (computerIssues, placeIssues). */
@@ -1,26 +1,46 @@
1
1
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2
2
  /** The kinds of computer an agent can be given. */
3
3
  export const COMPUTER_KINDS = ["none", "sandbox", "desktop", "phone", "browser"];
4
+ /** A GPU type's name as a setting keeps it: the vendor's own ("T4", "A100-80GB", "RTX-PRO-6000"); store/agent-body.ts
5
+ * keeps the same. */
6
+ const GPU_TYPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
7
+ /** The GPUs a setting asks for, or undefined. */
8
+ export const gpuOf = (computer) => (computer.kind === "sandbox" ? computer.gpu : undefined);
4
9
  /** The place the setting reads as: sandbox on its provider, else the runner (no computer holds the run's folder). */
5
10
  export const placeOfComputer = (computer) => (computer.kind === "sandbox" ? { mode: "sandbox", box: computer.provider } : { mode: "runner" });
6
11
  /** The setting a place says: runner is no computer, a sandbox place a sandbox on its box. */
7
12
  export const computerOfPlace = (place) => (place.mode === "sandbox" ? { kind: "sandbox", provider: place.box } : { kind: "none" });
8
- /** Whether two settings are the one setting. */
13
+ /** Whether two settings are the one setting: the kind and the provider (a place says no GPUs, so they are not compared). */
9
14
  export const sameComputer = (a, b) => a.kind === b.kind && (a.kind === "none" || a.provider === b.provider);
10
- /** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). */
15
+ /** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). A
16
+ * sandbox's gpu is { type, count } in the words the computer package's checkGpu uses; whether its provider offers that
17
+ * type and count is the readiness check's and the claim's (resolve-computer.ts), in checkGpu's own words. */
11
18
  export function computerIssues(value, field) {
12
19
  const bad = (reason, message, fix) => [{ field, reason, message, ...(fix ? { fix } : {}) }];
13
20
  if (!isObject(value))
14
- return bad("wrong_type", `${field} is an object: {kind}, or {kind, provider}`);
15
- const extra = Object.keys(value).filter((key) => key !== "kind" && key !== "provider");
21
+ return bad("wrong_type", `${field} is an object: {kind}, or {kind, provider}, and a sandbox's optional gpu`);
22
+ const extra = Object.keys(value).filter((key) => key !== "kind" && key !== "provider" && key !== "gpu");
16
23
  if (extra.length)
17
- return bad("not_allowed", `${field} keeps only kind and provider, not ${extra.join(" or ")}`, `Remove ${extra.map((key) => `${field}.${key}`).join(" and ")}.`);
24
+ return bad("not_allowed", `${field} keeps only kind, provider and a sandbox's gpu, not ${extra.join(" or ")}`, `Remove ${extra.map((key) => `${field}.${key}`).join(" and ")}.`);
18
25
  if (typeof value.kind !== "string" || !COMPUTER_KINDS.includes(value.kind))
19
26
  return bad(value.kind === undefined ? "missing" : "not_an_option", `${field}.kind is one of ${COMPUTER_KINDS.join(", ")}`);
27
+ if (value.gpu !== undefined && value.kind !== "sandbox")
28
+ return bad("not_allowed", `only a sandbox computer takes a gpu, not a ${value.kind} one`, `Remove ${field}.gpu.`);
20
29
  if (value.kind === "none")
21
30
  return value.provider === undefined ? [] : bad("not_allowed", "no computer names no provider", `Remove ${field}.provider.`);
22
31
  if (typeof value.provider !== "string" || value.provider === "")
23
32
  return bad("missing", `a ${value.kind} computer names its provider (Settings → Computers lists them)`);
33
+ if (value.gpu !== undefined) {
34
+ const gpu = value.gpu;
35
+ if (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count"))
36
+ return [{ field: `${field}.gpu`, reason: "wrong_type", message: "gpu is { type, count }: a GPU type this provider declares, and how many" }];
37
+ if (typeof gpu.type !== "string" || gpu.type === "")
38
+ return [{ field: `${field}.gpu.type`, reason: "missing", message: "gpu.type is a GPU type the provider declares (GET /v2/computers lists each provider's)" }];
39
+ if (!GPU_TYPE.test(gpu.type))
40
+ return [{ field: `${field}.gpu.type`, reason: "wrong_type", message: `gpu.type ${JSON.stringify(gpu.type)} is not a GPU type name: letters, digits, dots, underscores and dashes, as GET /v2/computers lists each provider's` }];
41
+ if (!Number.isSafeInteger(gpu.count) || gpu.count < 1)
42
+ return [{ field: `${field}.gpu.count`, reason: "wrong_type", message: `gpu.count ${JSON.stringify(gpu.count)} is not a whole number from 1` }];
43
+ }
24
44
  return [];
25
45
  }
26
46
  /** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
@@ -1,5 +1,7 @@
1
+ import { type GpuCapability } from "@parcha/agentrun-computer";
1
2
  import { type KeyTable, type OptionsAnswer, type ProviderFactories, type ProviderSettings } from "./computer-keys.js";
2
3
  import { type ComputerKind, type ComputerSetting } from "./computer-setting.js";
4
+ import { type DockerDaemon } from "./docker-daemon.js";
3
5
  import { type KeyEnv, type KeyMeta } from "./key-meta.js";
4
6
  import type { Store } from "./store/index.js";
5
7
  /** A setting kind as the kind registry's SETTING_KINDS gives it. */
@@ -8,10 +10,12 @@ export interface SettingKindSpec {
8
10
  readonly required: readonly string[];
9
11
  readonly optional: readonly string[];
10
12
  }
11
- /** A provider configuration's machine kind and groups, as the kind registry gives them. */
13
+ /** A provider configuration's machine kind and groups, and the GPUs it gives where it declares them, as the kind
14
+ * registry gives them. */
12
15
  export type KindCapabilities = {
13
16
  readonly kind: string;
14
17
  readonly groups: readonly string[];
18
+ readonly gpu?: GpuCapability;
15
19
  };
16
20
  /** A provider as the kind registry's PROVIDERS gives it. */
17
21
  export interface ProviderEntry {
@@ -24,6 +28,9 @@ export interface ProviderEntry {
24
28
  }[];
25
29
  /** The mounts its computers take; none means it cannot mount the run's folder. */
26
30
  readonly mounts: readonly string[];
31
+ /** The network forms its computers make ("none", "open", "allow"), as its module's NETWORK declares them. Absent (a
32
+ * test's fixture): nothing is said of its network. */
33
+ readonly network?: readonly string[];
27
34
  readonly metered: boolean;
28
35
  readonly capabilities: readonly KindCapabilities[];
29
36
  }
@@ -54,10 +61,13 @@ export interface ComputerRoutesOptions {
54
61
  readonly mode: FolderMode | (() => FolderMode | Promise<FolderMode>);
55
62
  /** The server's environment: a variable named as a provider's key overrides the saved one (source "env"). */
56
63
  readonly env?: KeyEnv;
64
+ /** Whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's daemon
65
+ * check, docker-daemon.ts, which keeps its answer a while). Absent: taken as answering. */
66
+ readonly answers?: (provider: string) => Promise<DockerDaemon>;
57
67
  }
58
68
  /** A provider as Settings shows it: `metered` straight from the kind registry (its computers are billed by the vendor);
59
69
  * its keys as SecretMeta under `secrets`, each named "computer:<provider>:<KEY>", and `required`, the names of the ones
60
- * it needs. */
70
+ * it needs. `network`: what this server's allow-list means for a vendor-hosted computer, in words (networkWords). */
61
71
  export type ProviderView = {
62
72
  id: string;
63
73
  name: string;
@@ -66,7 +76,25 @@ export type ProviderView = {
66
76
  required: string[];
67
77
  ready: boolean;
68
78
  why?: string;
79
+ network?: string;
80
+ gpu?: GpuView;
69
81
  };
82
+ /** A sandbox provider's GPUs as Settings shows them: what its configuration declares (the types an agent's
83
+ * `computer.gpu.type` names, the most one computer gets, and the limits it states), and why a run here cannot have
84
+ * them, when it cannot: a GPU computer of it that takes no mount of this server's folder mode. */
85
+ export type GpuView = GpuCapability & {
86
+ why?: string;
87
+ };
88
+ /** A computer with no network: its programs run in a network of their own, so a run's allow-list is never offered it. */
89
+ export declare const NO_NETWORK_WORDS = "no network, so this server's allow-list isn't offered";
90
+ /** A computer on the vendor's own network: open, which this server's allow-list doesn't reach. */
91
+ export declare const VENDOR_NETWORK_WORDS = "the vendor's own network; this server's allow-list doesn't apply";
92
+ /** A browser behind its own egress proxy (Local Chrome): every public host, unless the operator set a list. */
93
+ export declare const OPERATOR_LIST_WORDS = "open unless this server sets AGENTRUN_BOX_ALLOW; then only those hosts";
94
+ /** What this server's allow-list means for a provider's computers, by the network forms it declares: words for one that
95
+ * makes "none" alone, "open" alone, or "open" and "allow" but no "none" (a browser behind its own proxy); none where
96
+ * the allow-list applies as it is (Docker), or nothing is declared. */
97
+ export declare function networkWords(network: readonly string[] | undefined): string | undefined;
70
98
  export type KindView = {
71
99
  kind: ComputerKind;
72
100
  offered: boolean;
package/dist/computers.js CHANGED
@@ -6,10 +6,13 @@
6
6
  // their names only: a provider declares them, Settings takes only those, and the store keeps each sealed under the
7
7
  // server's seal key (server-keys.ts); a provider is handed its keys only at the claim, or for its test, both through
8
8
  // computer-keys.ts (providerOptions, testConnection), which maps a key's name onto the option it fills.
9
+ import { checkGpu } from "@parcha/agentrun-computer";
9
10
  import { KEY_TABLE, providerOptions, testConnection } from "./computer-keys.js";
10
- import { COMPUTER_KINDS } from "./computer-setting.js";
11
+ import { COMPUTER_KINDS, gpuOf } from "./computer-setting.js";
11
12
  import { inArchilMode } from "./archil-settings.js";
13
+ import { daemonUp, noDockerWords } from "./docker-daemon.js";
12
14
  import { ApiError, invalid } from "./errors.js";
15
+ import { redacted } from "./key-refusal.js";
13
16
  import { keyMetaOf, envValue } from "./key-meta.js";
14
17
  import { registerNotSecretWrite, registerSecretWrite, secretName } from "./secret-writes.js";
15
18
  import { getSealedKey, putSealedKey, removeSealedKey, sealedKeyNames } from "./server-keys.js";
@@ -18,6 +21,24 @@ import { getSealedKey, putSealedKey, removeSealedKey, sealedKeyNames } from "./s
18
21
  // is looked up, so a token learns nothing of which providers exist. The view and the connection test write none.
19
22
  registerSecretWrite("saveComputerKeys", () => true);
20
23
  registerNotSecretWrite("testComputer", "A connection test reads the saved keys and writes none.");
24
+ /** A computer with no network: its programs run in a network of their own, so a run's allow-list is never offered it. */
25
+ export const NO_NETWORK_WORDS = "no network, so this server's allow-list isn't offered";
26
+ /** A computer on the vendor's own network: open, which this server's allow-list doesn't reach. */
27
+ export const VENDOR_NETWORK_WORDS = "the vendor's own network; this server's allow-list doesn't apply";
28
+ /** A browser behind its own egress proxy (Local Chrome): every public host, unless the operator set a list. */
29
+ export const OPERATOR_LIST_WORDS = "open unless this server sets AGENTRUN_BOX_ALLOW; then only those hosts";
30
+ /** What this server's allow-list means for a provider's computers, by the network forms it declares: words for one that
31
+ * makes "none" alone, "open" alone, or "open" and "allow" but no "none" (a browser behind its own proxy); none where
32
+ * the allow-list applies as it is (Docker), or nothing is declared. */
33
+ export function networkWords(network) {
34
+ if (network?.length === 1 && network[0] === "none")
35
+ return NO_NETWORK_WORDS;
36
+ if (network?.length === 1 && network[0] === "open")
37
+ return VENDOR_NETWORK_WORDS;
38
+ if (network?.length === 2 && network.includes("open") && network.includes("allow"))
39
+ return OPERATOR_LIST_WORDS;
40
+ return undefined;
41
+ }
21
42
  /** Why a key save is refused, before anything is saved: a name the provider does not declare, or a value that is not text. */
22
43
  export class KeysRefused extends Error {
23
44
  fields;
@@ -43,16 +64,43 @@ export function modeRefusal(kind, provider, mode) {
43
64
  return `${provider.label} can't mount the owner's disk this server keeps run folders on: set this agent's computer to a sandbox that mounts it, or none (Settings → Computers)`;
44
65
  return undefined;
45
66
  }
67
+ /** The GPUs a sandbox of `provider` gives, as its configuration that serves a sandbox declares them, or undefined. */
68
+ const sandboxGpu = (kinds, provider) => provider.capabilities.find((one) => one.gpu !== undefined && kinds.servingRefusals(one, "sandbox").length === 0)?.gpu;
69
+ /** The mount a sandbox takes in `mode`: the run's folder, a bind of this machine or the owner's Archil disk. */
70
+ const folderMount = (mode) => ({ kind: mode === "local" ? "bind" : "archil" });
71
+ /** A sandbox provider's GPUs as Settings shows them, with why a run here cannot have them (checkGpu's words for its
72
+ * smallest ask, one of its first type, with this mode's mount). */
73
+ function gpuView(gpu, mode) {
74
+ const [refusal] = gpu.types.length ? checkGpu({ type: gpu.types[0], count: 1 }, { gpu }, folderMount(mode)) : [];
75
+ return { ...structuredClone(gpu), ...(refusal ? { why: refusal.message } : {}) };
76
+ }
77
+ /** Why `computer`'s GPUs cannot be had on `provider` in `mode`, in checkGpu's words; undefined when they can, or it asks
78
+ * for none (only a sandbox does). */
79
+ function gpuRefusal(kinds, computer, provider, mode) {
80
+ const asked = gpuOf(computer);
81
+ if (!asked)
82
+ return undefined;
83
+ const gpu = sandboxGpu(kinds, provider);
84
+ const [refusal] = checkGpu(asked, gpu ? { gpu } : {}, folderMount(mode));
85
+ return refusal ? `${provider.label} can't give this agent's computer its GPUs: ${refusal.message} (Settings → Computers)` : undefined;
86
+ }
46
87
  /** The required keys `provider` has no saved value for, by name. */
47
88
  const missingKeys = (provider, saved) => provider.keys.filter((key) => key.required && !saved.has(key.name)).map((key) => key.name);
48
- /** Why a provider with keys missing is not ready, naming the setting to fill. */
49
- const keysWhy = (provider, missing) => `${provider.label} needs ${missing.join(" and ")} saved: save ${missing.length > 1 ? "them" : "it"} in Settings → Computers (PUT /v2/computers/${provider.id}/keys)`;
89
+ /** Why a provider with keys missing is not ready, naming the setting to fill: a person reads it (the view, the test), so
90
+ * it ends at the setting. A caller's refusal (the claim's) adds the route that saves them (`route`). */
91
+ const keysWhy = (provider, missing, route = false) => `${provider.label} needs ${missing.join(" and ")} saved: save ${missing.length > 1 ? "them" : "it"} in Settings → Computers${route ? ` (PUT /v2/computers/${provider.id}/keys)` : ""}`;
92
+ /** Whether `provider` binds a folder of this machine, so its computers need this machine's Docker daemon. */
93
+ const local = (provider) => provider.mounts.includes("bind");
50
94
  /** The routes' work over the server's store: GET /v2/computers (view), PUT /v2/computers/{provider}/keys (saveKeys), POST
51
95
  * /v2/computers/{provider}/test (test), and the claim's refusal (claimRefusal). */
52
96
  export function createComputerRoutes(options) {
53
- const { store, sealKey, kinds, factories, settings = {}, keyTable = KEY_TABLE, tools, env = {} } = options;
97
+ const { store, sealKey, kinds, factories, settings = {}, keyTable = KEY_TABLE, tools, env = {}, answers = daemonUp } = options;
54
98
  const providerOf = (id) => kinds.PROVIDERS.find((one) => one.id === id);
55
99
  const modeNow = async () => (typeof options.mode === "function" ? options.mode() : options.mode);
100
+ /** Why a computer of `kind` on `provider` can't be had for its daemon (a provider that binds a folder of this machine,
101
+ * `said` its answer, in folder `mode`): none answering is the one wording (docker-daemon.ts noDockerWords); else its
102
+ * reason. */
103
+ const daemonWhy = (kind, said, mode) => said.up ? undefined : said.absent ? noDockerWords(kind, kinds.PROVIDERS, mode === "disk" ? 2 : 1) : said.reason;
56
104
  /** Each kind, whether this server offers it and why not, the capability groups and tools it brings, and each provider
57
105
  * that serves it, with its keys (saved or not, never a value) and whether a run could have it now. */
58
106
  async function view() {
@@ -62,14 +110,20 @@ export function createComputerRoutes(options) {
62
110
  const slots = kinds.PROVIDERS.flatMap((provider) => provider.keys.map((key) => ({ secret: secretName("computer", provider.id, key.name), env: key.name, row: key.name })));
63
111
  const metas = new Map((await keyMetaOf(store, slots, env)).map((meta) => [meta.name, meta]));
64
112
  const saved = new Set(slots.filter((slot) => metas.get(slot.secret).set).map((slot) => slot.env));
113
+ // Each provider that binds a folder of this machine asked once for the view: its daemon answers, or why not.
114
+ const daemons = new Map(await Promise.all(kinds.PROVIDERS.filter(local).map(async (provider) => [provider.id, await answers(provider.id)])));
65
115
  return {
66
116
  kinds: COMPUTER_KINDS.map((kind) => {
67
117
  const spec = kinds.SETTING_KINDS[kind];
68
118
  const serving = kinds.PROVIDERS.filter((provider) => provider.kinds.includes(kind));
69
119
  const providers = serving.map((provider) => {
70
120
  const missing = missingKeys(provider, saved);
71
- const why = modeRefusal(kind, provider, mode) ?? (missing.length ? keysWhy(provider, missing) : undefined);
72
- return { id: provider.id, name: provider.label, metered: provider.metered, secrets: provider.keys.map((key) => metas.get(secretName("computer", provider.id, key.name))), required: provider.keys.filter((key) => key.required).map((key) => secretName("computer", provider.id, key.name)), ready: why === undefined, ...(why ? { why } : {}) };
121
+ const daemon = daemons.get(provider.id);
122
+ const why = modeRefusal(kind, provider, mode) ?? (daemon ? daemonWhy(kind, daemon, mode) : undefined) ?? (missing.length ? keysWhy(provider, missing) : undefined);
123
+ const network = networkWords(provider.network);
124
+ // A sandbox's GPUs: only a sandbox takes them (computer-setting.ts computerIssues).
125
+ const gpu = kind === "sandbox" ? sandboxGpu(kinds, provider) : undefined;
126
+ return { id: provider.id, name: provider.label, metered: provider.metered, secrets: provider.keys.map((key) => metas.get(secretName("computer", provider.id, key.name))), required: provider.keys.filter((key) => key.required).map((key) => secretName("computer", provider.id, key.name)), ready: why === undefined, ...(why ? { why } : {}), ...(network ? { network } : {}), ...(gpu ? { gpu: gpuView(gpu, mode) } : {}) };
73
127
  });
74
128
  const offered = kind === "none" || serving.some((provider) => modeRefusal(kind, provider, mode) === undefined);
75
129
  const why = offered ? undefined : serving.length ? `no provider of a ${kind} computer can reach this server's run folders` : `no provider serves a ${kind} computer`;
@@ -109,7 +163,9 @@ export function createComputerRoutes(options) {
109
163
  return keys;
110
164
  }
111
165
  /** The account test of a provider with its saved keys (computer-keys.ts testConnection): one account-level read, never a
112
- * create. Its words are the answer's why. Undefined for a provider this server does not have. */
166
+ * create. Its words are the answer's why. Undefined for a provider this server does not have. What the provider said
167
+ * passes serve's one redactor (key-refusal.ts redacted) over the keys this test used: a vendor's error can quote a key
168
+ * in a form testConnection's plain cut misses (base64 in an Authorization header, JSON-escaped, percent-encoded). */
113
169
  async function test(providerId, signal) {
114
170
  const provider = providerOf(providerId);
115
171
  if (!provider)
@@ -119,11 +175,13 @@ export function createComputerRoutes(options) {
119
175
  if (missing.length)
120
176
  return { ok: false, why: keysWhy(provider, missing) };
121
177
  const answer = await testConnection(providerId, { keys, ...(signal ? { signal } : {}) }, factories, settings, keyTable);
122
- return answer.ok ? { ok: true, detail: answer.value.detail } : { ok: false, why: answer.error.message };
178
+ const cut = (text) => redacted(text, Object.values(keys));
179
+ return answer.ok ? { ok: true, detail: cut(answer.value.detail) } : { ok: false, why: cut(answer.error.message) };
123
180
  }
124
181
  /** Why a run of an agent whose computer is `computer` cannot have it here, in words naming the setting to fill;
125
182
  * undefined when it can. Checked at the claim: the provider must serve the kind (servingRefusals' words), fit this
126
- * server's folder mode, and have every required key saved. */
183
+ * server's folder mode, give a sandbox the GPUs it asks for (checkGpu's words), have its daemon answer where it binds
184
+ * a folder of this machine (Docker), and have every required key saved; a key refusal names the route that saves them. */
127
185
  async function claimRefusal(computer) {
128
186
  if (computer.kind === "none")
129
187
  return undefined;
@@ -134,11 +192,12 @@ export function createComputerRoutes(options) {
134
192
  const words = [...new Set(provider.capabilities.flatMap((capabilities) => kinds.servingRefusals(capabilities, computer.kind)))];
135
193
  return `${provider.label} does not serve a ${computer.kind} computer${words.length ? ` (${words.join("; ")})` : ""}: set this agent's computer to one it serves (Settings → Computers)`;
136
194
  }
137
- const refused = modeRefusal(computer.kind, provider, await modeNow());
195
+ const mode = await modeNow();
196
+ const refused = modeRefusal(computer.kind, provider, mode) ?? gpuRefusal(kinds, computer, provider, mode) ?? (local(provider) ? daemonWhy(computer.kind, await answers(provider.id), mode) : undefined);
138
197
  if (refused)
139
198
  return refused;
140
199
  const missing = missingKeys(provider, new Set([...(await sealedKeyNames(store)), ...provider.keys.filter((key) => envValue(env, key.name) !== undefined).map((key) => key.name)]));
141
- return missing.length ? keysWhy(provider, missing) : undefined;
200
+ return missing.length ? keysWhy(provider, missing, true) : undefined;
142
201
  }
143
202
  /** What the claim makes a run's computer with: the options its provider's create() takes, from its saved keys and the
144
203
  * server's settings (computer-keys.ts providerOptions); refused with computer_unavailable and claimRefusal's words when