@parcha/agentrun-serve 0.1.0-beta.32 → 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 (444) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/README.md +343 -246
  3. package/dist/adapters.d.ts +0 -7
  4. package/dist/adapters.js +11 -22
  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 +14 -0
  14. package/dist/api-only.js +33 -0
  15. package/dist/archil-routes.d.ts +1 -1
  16. package/dist/bash-read-only.d.ts +22 -0
  17. package/dist/bash-read-only.js +701 -0
  18. package/dist/box-egress-vm.d.ts +0 -8
  19. package/dist/box-egress-vm.js +0 -10
  20. package/dist/box-egress.d.ts +0 -4
  21. package/dist/box-egress.js +1 -16
  22. package/dist/box-paths.d.ts +25 -2
  23. package/dist/box-paths.js +79 -11
  24. package/dist/box-relay.d.ts +0 -11
  25. package/dist/box-relay.js +0 -20
  26. package/dist/box-settings.d.ts +26 -0
  27. package/dist/box-settings.js +63 -0
  28. package/dist/boxes.d.ts +21 -1
  29. package/dist/boxes.js +27 -20
  30. package/dist/browser-commands.d.ts +5 -2
  31. package/dist/browser-commands.js +4 -4
  32. package/dist/browser-computer.d.ts +5 -0
  33. package/dist/browser-computer.js +21 -0
  34. package/dist/browser-cost.d.ts +9 -6
  35. package/dist/browser-cost.js +94 -51
  36. package/dist/browser-live.d.ts +7 -20
  37. package/dist/browser-live.js +15 -93
  38. package/dist/browser-person.d.ts +18 -53
  39. package/dist/browser-person.js +94 -279
  40. package/dist/budget.d.ts +0 -4
  41. package/dist/budget.js +0 -7
  42. package/dist/cap.d.ts +8 -12
  43. package/dist/cap.js +12 -27
  44. package/dist/cli.js +61 -20
  45. package/dist/closed-pipes.d.ts +2 -0
  46. package/dist/closed-pipes.js +13 -0
  47. package/dist/computer-commands.d.ts +2 -0
  48. package/dist/computer-commands.js +2 -0
  49. package/dist/computer-keys.js +5 -2
  50. package/dist/computer-setting.d.ts +20 -4
  51. package/dist/computer-setting.js +25 -5
  52. package/dist/computers.d.ts +31 -3
  53. package/dist/computers.js +70 -11
  54. package/dist/confine.d.ts +120 -0
  55. package/dist/confine.js +436 -0
  56. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  57. package/dist/console/assets/index-opTN5Naq.css +1 -0
  58. package/dist/console/index.html +2 -2
  59. package/dist/daytona-api.d.ts +0 -11
  60. package/dist/daytona-api.js +1 -82
  61. package/dist/decision-rows.d.ts +1 -1
  62. package/dist/decision-rows.js +1 -1
  63. package/dist/docker-daemon.d.ts +31 -0
  64. package/dist/docker-daemon.js +56 -0
  65. package/dist/docker-host-addresses.d.ts +37 -0
  66. package/dist/docker-host-addresses.js +110 -0
  67. package/dist/effort-guidance.js +4 -3
  68. package/dist/environment.d.ts +0 -3
  69. package/dist/environment.js +3 -5
  70. package/dist/errors.d.ts +0 -2
  71. package/dist/errors.js +6 -9
  72. package/dist/filed-answer.d.ts +32 -0
  73. package/dist/filed-answer.js +160 -0
  74. package/dist/files.d.ts +1 -11
  75. package/dist/files.js +2 -21
  76. package/dist/github-connection.d.ts +2 -2
  77. package/dist/github-connection.js +1 -1
  78. package/dist/graph-view.d.ts +3 -5
  79. package/dist/graph-view.js +4 -14
  80. package/dist/handed-values.d.ts +9 -0
  81. package/dist/handed-values.js +26 -0
  82. package/dist/harness-install.d.ts +22 -5
  83. package/dist/harness-install.js +98 -20
  84. package/dist/harness-opencode/adapter.d.ts +7 -0
  85. package/dist/harness-opencode/adapter.js +23 -6
  86. package/dist/harness-opencode/index.d.ts +1 -1
  87. package/dist/harness-opencode/index.js +1 -1
  88. package/dist/harness-opencode/verify.d.ts +17 -0
  89. package/dist/harness-opencode/verify.js +30 -10
  90. package/dist/harness-table.js +6 -1
  91. package/dist/harness.d.ts +4 -3
  92. package/dist/harness.js +16 -1
  93. package/dist/heard.js +1 -1
  94. package/dist/held-fd.d.ts +5 -0
  95. package/dist/held-fd.js +14 -0
  96. package/dist/host-calls.d.ts +20 -0
  97. package/dist/host-calls.js +12 -0
  98. package/dist/host-tools.d.ts +4 -21
  99. package/dist/host-tools.js +4 -61
  100. package/dist/host.d.ts +2 -4
  101. package/dist/host.js +2 -7
  102. package/dist/import-summary.d.ts +1 -5
  103. package/dist/import-summary.js +0 -21
  104. package/dist/import.d.ts +6 -6
  105. package/dist/import.js +62 -24
  106. package/dist/key-refusal.d.ts +5 -1
  107. package/dist/key-refusal.js +19 -4
  108. package/dist/learn/check.d.ts +6 -2
  109. package/dist/learn/check.js +83 -29
  110. package/dist/learn/folder.d.ts +5 -1
  111. package/dist/learn/folder.js +10 -3
  112. package/dist/learn/grade.d.ts +14 -0
  113. package/dist/learn/grade.js +68 -12
  114. package/dist/learn/index.d.ts +4 -4
  115. package/dist/learn/index.js +4 -4
  116. package/dist/learn/reflect.d.ts +31 -2
  117. package/dist/learn/reflect.js +79 -4
  118. package/dist/learn/relevance.d.ts +24 -0
  119. package/dist/learn/relevance.js +91 -0
  120. package/dist/learn/secrets.d.ts +8 -1
  121. package/dist/learn/secrets.js +95 -15
  122. package/dist/learn/skills.d.ts +112 -14
  123. package/dist/learn/skills.js +556 -52
  124. package/dist/learned-workflow.d.ts +37 -5
  125. package/dist/learned-workflow.js +106 -12
  126. package/dist/learning-routes.d.ts +16 -49
  127. package/dist/learning-routes.js +46 -36
  128. package/dist/learning-run.d.ts +6 -250
  129. package/dist/learning-run.js +11 -665
  130. package/dist/learning-words.d.ts +12 -5
  131. package/dist/learning-words.js +18 -9
  132. package/dist/learning.d.ts +93 -77
  133. package/dist/learning.js +176 -304
  134. package/dist/live/stream.js +1 -1
  135. package/dist/live/translate.js +13 -3
  136. package/dist/local-models.d.ts +11 -5
  137. package/dist/local-models.js +13 -8
  138. package/dist/mcp-gateway.d.ts +11 -52
  139. package/dist/mcp-gateway.js +44 -148
  140. package/dist/mcp-oauth.d.ts +10 -14
  141. package/dist/mcp-oauth.js +14 -32
  142. package/dist/mcp-probe.d.ts +0 -7
  143. package/dist/mcp-probe.js +4 -10
  144. package/dist/mcp-servers-store.d.ts +6 -6
  145. package/dist/mcp-servers-store.js +13 -15
  146. package/dist/mcp-store.js +3 -4
  147. package/dist/mcp.js +4 -3
  148. package/dist/model.d.ts +6 -7
  149. package/dist/model.js +43 -27
  150. package/dist/monid.d.ts +0 -2
  151. package/dist/monid.js +3 -6
  152. package/dist/openapi.d.ts +8 -1
  153. package/dist/openapi.js +124 -50
  154. package/dist/page.d.ts +1 -3
  155. package/dist/page.js +9 -19
  156. package/dist/paid-calls.d.ts +21 -27
  157. package/dist/paid-calls.js +28 -62
  158. package/dist/pause.d.ts +0 -2
  159. package/dist/pause.js +1 -8
  160. package/dist/place.d.ts +0 -5
  161. package/dist/place.js +0 -10
  162. package/dist/print.d.ts +2 -1
  163. package/dist/print.js +4 -2
  164. package/dist/propose.js +83 -39
  165. package/dist/push-handler.d.ts +1 -1
  166. package/dist/reflect-range.d.ts +25 -0
  167. package/dist/reflect-range.js +30 -0
  168. package/dist/refusal-words.d.ts +5 -1
  169. package/dist/refusal-words.js +5 -1
  170. package/dist/rows.d.ts +1 -1
  171. package/dist/run-cut.d.ts +0 -6
  172. package/dist/run-cut.js +0 -6
  173. package/dist/run-db.d.ts +2 -13
  174. package/dist/run-db.js +2 -41
  175. package/dist/run-launch.d.ts +19 -2
  176. package/dist/run-launch.js +13 -5
  177. package/dist/run-learning-served.d.ts +46 -2
  178. package/dist/run-learning-served.js +26 -7
  179. package/dist/run-reads-over-store.d.ts +1 -1
  180. package/dist/run-reads-over-store.js +15 -6
  181. package/dist/run-secrets.d.ts +33 -0
  182. package/dist/run-secrets.js +53 -0
  183. package/dist/run-timeline-served.d.ts +5 -1
  184. package/dist/run-timeline-served.js +19 -5
  185. package/dist/run-view.d.ts +12 -17
  186. package/dist/run-view.js +29 -28
  187. package/dist/runnable.d.ts +18 -10
  188. package/dist/runnable.js +21 -10
  189. package/dist/runner/adapter-loop.d.ts +14 -3
  190. package/dist/runner/adapter-loop.js +464 -62
  191. package/dist/runner/adapter-run-spec.d.ts +29 -8
  192. package/dist/runner/adapter-run-spec.js +96 -37
  193. package/dist/runner/adapters/index.js +11 -1
  194. package/dist/runner/adapters/pi.d.ts +15 -1
  195. package/dist/runner/adapters/pi.js +19 -5
  196. package/dist/runner/beside.d.ts +30 -3
  197. package/dist/runner/beside.js +54 -12
  198. package/dist/runner/claim-secrets.d.ts +10 -1
  199. package/dist/runner/claim-secrets.js +49 -15
  200. package/dist/runner/cli-run-spec.d.ts +2 -0
  201. package/dist/runner/cli-run-spec.js +60 -17
  202. package/dist/runner/commands.js +1 -1
  203. package/dist/runner/computer-journal.d.ts +15 -2
  204. package/dist/runner/computer-journal.js +41 -5
  205. package/dist/runner/conformance/harness.js +118 -8
  206. package/dist/runner/conformance/subject.d.ts +4 -1
  207. package/dist/runner/dispatch.d.ts +8 -1
  208. package/dist/runner/dispatch.js +81 -7
  209. package/dist/runner/end-of-run.d.ts +8 -2
  210. package/dist/runner/end-of-run.js +10 -4
  211. package/dist/runner/github-app.js +1 -1
  212. package/dist/runner/harness-loops.d.ts +9 -1
  213. package/dist/runner/harness-loops.js +15 -2
  214. package/dist/runner/journal-kinds.d.ts +30 -6
  215. package/dist/runner/journal-kinds.js +20 -5
  216. package/dist/runner/journal-reader.d.ts +1 -1
  217. package/dist/runner/journal-reader.js +2 -2
  218. package/dist/runner/learning-ask.d.ts +4 -0
  219. package/dist/runner/learning-ask.js +15 -1
  220. package/dist/runner/learning-end.d.ts +18 -3
  221. package/dist/runner/learning-end.js +113 -11
  222. package/dist/runner/learning-loop.d.ts +5 -0
  223. package/dist/runner/learning-loop.js +26 -6
  224. package/dist/runner/live-ticker.d.ts +1 -1
  225. package/dist/runner/live-ticker.js +28 -4
  226. package/dist/runner/loop-contract.d.ts +3 -2
  227. package/dist/runner/main.d.ts +64 -10
  228. package/dist/runner/main.js +165 -27
  229. package/dist/runner/mcp-claim.d.ts +1 -1
  230. package/dist/runner/mcp-claim.js +2 -3
  231. package/dist/runner/mcp-run.d.ts +2 -0
  232. package/dist/runner/mcp-run.js +15 -5
  233. package/dist/runner/memory-claim.d.ts +9 -0
  234. package/dist/runner/memory-claim.js +25 -0
  235. package/dist/runner/metrics.d.ts +33 -1
  236. package/dist/runner/metrics.js +85 -1
  237. package/dist/runner/model-route.d.ts +13 -0
  238. package/dist/runner/model-route.js +154 -11
  239. package/dist/runner/redact.d.ts +8 -2
  240. package/dist/runner/redact.js +11 -2
  241. package/dist/runner/reflect-hook.d.ts +12 -1
  242. package/dist/runner/reflect-hook.js +33 -3
  243. package/dist/runner/runner.d.ts +20 -0
  244. package/dist/runner/runner.js +56 -10
  245. package/dist/runner/store-port.d.ts +1 -1
  246. package/dist/runner/store-secrets.d.ts +3 -3
  247. package/dist/runner/store-secrets.js +8 -12
  248. package/dist/runner/text-tools.d.ts +44 -0
  249. package/dist/runner/text-tools.js +237 -0
  250. package/dist/runner/workflow-loop.d.ts +6 -0
  251. package/dist/runner/workflow-loop.js +6 -4
  252. package/dist/runner/workflow-spec.d.ts +18 -0
  253. package/dist/runner/workflow-spec.js +68 -26
  254. package/dist/runs-over-store.d.ts +8 -3
  255. package/dist/runs-over-store.js +76 -19
  256. package/dist/seal-key.d.ts +54 -15
  257. package/dist/seal-key.js +232 -82
  258. package/dist/sealed-settings-store.d.ts +19 -4
  259. package/dist/sealed-settings-store.js +9 -9
  260. package/dist/sealing.d.ts +4 -0
  261. package/dist/sealing.js +20 -0
  262. package/dist/secret-cut.d.ts +1 -1
  263. package/dist/secret-cut.js +1 -1
  264. package/dist/secret-name.d.ts +9 -0
  265. package/dist/secret-name.js +15 -0
  266. package/dist/secret-writes.d.ts +0 -1
  267. package/dist/secret-writes.js +0 -1
  268. package/dist/secrets.d.ts +2 -10
  269. package/dist/secrets.js +21 -17
  270. package/dist/server-fs.d.ts +4 -0
  271. package/dist/server-fs.js +8 -2
  272. package/dist/server-lock.d.ts +0 -24
  273. package/dist/server-lock.js +1 -80
  274. package/dist/server-secrets-store.d.ts +4 -4
  275. package/dist/server-secrets-store.js +10 -32
  276. package/dist/server-secrets.d.ts +4 -9
  277. package/dist/server-secrets.js +12 -33
  278. package/dist/server.d.ts +26 -44
  279. package/dist/server.js +229 -142
  280. package/dist/sign-ins-store.d.ts +34 -36
  281. package/dist/sign-ins-store.js +27 -38
  282. package/dist/sign-ins.d.ts +2 -119
  283. package/dist/sign-ins.js +5 -311
  284. package/dist/standard-webhooks.d.ts +1 -1
  285. package/dist/standard-webhooks.js +1 -1
  286. package/dist/stats.d.ts +3 -2
  287. package/dist/stats.js +1 -1
  288. package/dist/store/agent-body.d.ts +8 -2
  289. package/dist/store/agent-body.js +16 -4
  290. package/dist/store/index.d.ts +3 -3
  291. package/dist/store/index.js +3 -3
  292. package/dist/store/open.d.ts +18 -5
  293. package/dist/store/open.js +23 -3
  294. package/dist/store/postgres/connection.d.ts +18 -2
  295. package/dist/store/postgres/connection.js +156 -32
  296. package/dist/store/postgres/migrate.d.ts +4 -0
  297. package/dist/store/postgres/migrate.js +27 -3
  298. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  299. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  300. package/dist/store/postgres/store.d.ts +9 -2
  301. package/dist/store/postgres/store.js +9 -0
  302. package/dist/store/schema.js +1 -1
  303. package/dist/store/seal.js +2 -2
  304. package/dist/store/sqlite/connection.js +49 -5
  305. package/dist/store/sqlite/run-patch.d.ts +3 -0
  306. package/dist/store/sqlite/run-patch.js +3 -0
  307. package/dist/store/sqlite/store.js +64 -20
  308. package/dist/store/store.d.ts +38 -6
  309. package/dist/store/store.js +12 -2
  310. package/dist/store-reads/cap.d.ts +1 -1
  311. package/dist/store-reads/cap.js +22 -4
  312. package/dist/store-reads/journal.d.ts +25 -6
  313. package/dist/store-reads/journal.js +173 -21
  314. package/dist/store-reads/learning.d.ts +26 -8
  315. package/dist/store-reads/learning.js +12 -4
  316. package/dist/store-reads/workflow.d.ts +1 -1
  317. package/dist/store-reads/workflow.js +1 -1
  318. package/dist/store-view.d.ts +5 -1
  319. package/dist/store-view.js +91 -23
  320. package/dist/template-eval.d.ts +60 -4
  321. package/dist/template-eval.js +120 -54
  322. package/dist/templates.d.ts +24 -10
  323. package/dist/templates.js +69 -38
  324. package/dist/timeline/group.d.ts +33 -0
  325. package/dist/timeline/group.js +77 -0
  326. package/dist/timeline/index.d.ts +7 -0
  327. package/dist/timeline/index.js +7 -0
  328. package/dist/timeline/labels.d.ts +79 -0
  329. package/dist/timeline/labels.js +150 -0
  330. package/dist/timeline/origin.d.ts +56 -0
  331. package/dist/timeline/origin.js +92 -0
  332. package/dist/timeline/render-text.d.ts +11 -0
  333. package/dist/timeline/render-text.js +62 -0
  334. package/dist/timeline/timeline.d.ts +274 -0
  335. package/dist/timeline/timeline.js +1308 -0
  336. package/dist/timeline/util.d.ts +17 -0
  337. package/dist/timeline/util.js +49 -0
  338. package/dist/tool-gate.d.ts +41 -216
  339. package/dist/tool-gate.js +79 -540
  340. package/dist/tool-keys-store.d.ts +11 -12
  341. package/dist/tool-keys-store.js +24 -31
  342. package/dist/tool-keys.d.ts +9 -104
  343. package/dist/tool-keys.js +15 -271
  344. package/dist/tool-plane.d.ts +14 -42
  345. package/dist/tool-plane.js +23 -81
  346. package/dist/tool-settings-store.d.ts +1 -2
  347. package/dist/tool-settings-store.js +5 -8
  348. package/dist/tools.d.ts +31 -19
  349. package/dist/tools.js +101 -108
  350. package/dist/trigger-adapter.d.ts +2 -2
  351. package/dist/trigger-schedule.js +2 -1
  352. package/dist/trigger-secrets-shown.js +5 -1
  353. package/dist/trigger-targets.d.ts +13 -1
  354. package/dist/trigger-targets.js +31 -1
  355. package/dist/triggers.d.ts +2 -2
  356. package/dist/triggers.js +3 -3
  357. package/dist/turn-end.d.ts +1 -1
  358. package/dist/turn-end.js +1 -1
  359. package/dist/turns.d.ts +0 -6
  360. package/dist/turns.js +0 -19
  361. package/dist/uploads.js +1 -1
  362. package/dist/usage.d.ts +0 -2
  363. package/dist/usage.js +0 -2
  364. package/dist/validate.d.ts +2 -0
  365. package/dist/validate.js +23 -14
  366. package/dist/webhooks.d.ts +102 -76
  367. package/dist/webhooks.js +266 -233
  368. package/dist/workflow-run.d.ts +114 -0
  369. package/dist/workflow-run.js +144 -0
  370. package/dist/workspace/beneath.d.ts +19 -0
  371. package/dist/workspace/beneath.js +106 -0
  372. package/dist/workspace/computer-deps.d.ts +52 -5
  373. package/dist/workspace/computer-deps.js +154 -19
  374. package/dist/workspace/computer-for-claim.d.ts +19 -14
  375. package/dist/workspace/computer-for-claim.js +77 -16
  376. package/dist/workspace/computer-hold.d.ts +6 -1
  377. package/dist/workspace/computer-hold.js +6 -1
  378. package/dist/workspace/computer-janitor.d.ts +47 -0
  379. package/dist/workspace/computer-janitor.js +182 -0
  380. package/dist/workspace/computer-providers.d.ts +6 -2
  381. package/dist/workspace/computer-providers.js +1 -1
  382. package/dist/workspace/grep-worker.d.ts +5 -0
  383. package/dist/workspace/grep-worker.js +9 -6
  384. package/dist/workspace/index.d.ts +4 -3
  385. package/dist/workspace/index.js +4 -4
  386. package/dist/workspace/local.d.ts +11 -2
  387. package/dist/workspace/local.js +161 -43
  388. package/dist/workspace/resolve-computer.d.ts +50 -10
  389. package/dist/workspace/resolve-computer.js +46 -11
  390. package/dist/workspace/run-tools.d.ts +13 -31
  391. package/dist/workspace/run-tools.js +10 -27
  392. package/dist/workspace-paths.d.ts +0 -17
  393. package/dist/workspace-paths.js +1 -41
  394. package/dist/workspace.d.ts +0 -17
  395. package/dist/workspace.js +3 -99
  396. package/launcher/agentrun-serve +6 -33
  397. package/package.json +14 -14
  398. package/templates/README.md +9 -3
  399. package/templates/inbound-lead/agent.md +1 -1
  400. package/templates/kyb/agent.md +1 -1
  401. package/templates/market-monitor/agent.md +2 -2
  402. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  403. package/dist/app.d.ts +0 -5
  404. package/dist/app.js +0 -514
  405. package/dist/bound-files.d.ts +0 -4
  406. package/dist/bound-files.js +0 -164
  407. package/dist/bounds.d.ts +0 -26
  408. package/dist/bounds.js +0 -137
  409. package/dist/coding-tools.d.ts +0 -47
  410. package/dist/coding-tools.js +0 -189
  411. package/dist/computer-adb.d.ts +0 -12
  412. package/dist/computer-adb.js +0 -14
  413. package/dist/console/assets/index-35-7aeIZ.js +0 -519
  414. package/dist/console/assets/index-Cejbov-Y.css +0 -1
  415. package/dist/content-filter.d.ts +0 -7
  416. package/dist/content-filter.js +0 -23
  417. package/dist/disk.d.ts +0 -33
  418. package/dist/disk.js +0 -85
  419. package/dist/door-line.d.ts +0 -23
  420. package/dist/door-line.js +0 -83
  421. package/dist/grade.d.ts +0 -63
  422. package/dist/grade.js +0 -150
  423. package/dist/harness-app.d.ts +0 -69
  424. package/dist/harness-app.js +0 -1162
  425. package/dist/mcp-servers.d.ts +0 -269
  426. package/dist/mcp-servers.js +0 -456
  427. package/dist/packs.d.ts +0 -71
  428. package/dist/packs.js +0 -180
  429. package/dist/request-start.d.ts +0 -27
  430. package/dist/request-start.js +0 -381
  431. package/dist/run-box.d.ts +0 -205
  432. package/dist/run-box.js +0 -661
  433. package/dist/run-holder.d.ts +0 -52
  434. package/dist/run-holder.js +0 -139
  435. package/dist/runs.d.ts +0 -1200
  436. package/dist/runs.js +0 -4103
  437. package/dist/sealed-settings.d.ts +0 -60
  438. package/dist/sealed-settings.js +0 -178
  439. package/dist/served-only.d.ts +0 -5
  440. package/dist/served-only.js +0 -12
  441. package/dist/sessions.d.ts +0 -6
  442. package/dist/sessions.js +0 -109
  443. package/dist/workspace/computer-serves.d.ts +0 -12
  444. package/dist/workspace/computer-serves.js +0 -15
@@ -6,8 +6,18 @@
6
6
  // a folder swapped for a link after the walk is never followed: the read, write, rename, unlink, readdir, mkdir and
7
7
  // exec's working directory all go through the handle. The last part is opened with O_NOFOLLOW, or acted on by a call
8
8
  // that does not follow it (rename, unlink, rmdir), after an lstat refuses a link there. A recursive remove walks the
9
- // tree by handles too, and removes a link it meets, never what it points at. Elsewhere (macOS) the walk is the same, but
10
- // later calls resolve the path again, so a swap between the walk and the call can be followed.
9
+ // tree by handles too, and removes a link it meets, never what it points at.
10
+ //
11
+ // Elsewhere (macOS: Docker Desktop binds the run's folder, so a box process can swap a folder in it for a link) there
12
+ // is no /proc/self/fd, and node has no openat, so later calls resolve the path again. There every open (each folder the
13
+ // walk holds, and each file a read, write, append or grep opens) refuses a link anywhere below the root, not only at
14
+ // the end (beneath.ts: macOS's O_NOFOLLOW_ANY): a folder swapped for a link before or during the open is ELOOP, so
15
+ // ESCAPE, and what the handle holds was reached through real folders of the root's at the open itself. Nothing is
16
+ // resolved again after it, so a swap after the open, or one that comes and goes, changes nothing a read returns. A
17
+ // call that acts on a name instead (unlink, rmdir, rename, readdir, lstat, mkdir, exec's cwd) checks, just before,
18
+ // that its folder's path opens the same way to the folder held: a link swapped in by then is ESCAPE. What remains is
19
+ // the gap between that check and the call itself, which only an unlinkat or a fchdir closes. The path-resolving branch
20
+ // is chosen by `procFd`, so a test runs it on Linux too.
11
21
  //
12
22
  // Durability. write is a temporary file in the same folder (O_EXCL), its bytes, fsync, rename over the name, then fsync
13
23
  // of the folder. append is O_APPEND, its bytes, fdatasync, and the folder's fsync when it made the file. mkdir fsyncs
@@ -28,6 +38,7 @@ import { access, lstat, mkdir as makeDir, open, readdir, realpath, rename, rmdir
28
38
  import { join } from "node:path";
29
39
  import { Worker } from "node:worker_threads";
30
40
  import { attachedWorkspace, checkReadBack, noProcesses } from "./attach.js";
41
+ import { openBeneath } from "./beneath.js";
31
42
  import { relativeSegments } from "./paths.js";
32
43
  import { abortError, EXEC_OUTPUT_MAX, GREP_FILE_MAX, GREP_LINE_MAX, GREP_MAX, GREP_TIME_MS, READ_MAX, WorkspaceError, } from "./workspace.js";
33
44
  const { O_APPEND, O_CREAT, O_DIRECTORY, O_EXCL, O_NOFOLLOW, O_NONBLOCK, O_RDONLY, O_RDWR, O_WRONLY } = constants;
@@ -72,64 +83,151 @@ const bytesOf = (data) => {
72
83
  throw new WorkspaceError("REFUSED", "data is bytes (a Uint8Array) or a string");
73
84
  };
74
85
  const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
86
+ /** A link swapped in on the way to `path` since it was walked: ESCAPE. */
87
+ const swapped = (path) => new WorkspaceError("ESCAPE", `${show(path)} runs through a symbolic link swapped in on the way, and a workspace follows none`, { path });
75
88
  /** A folder held open. On Linux a name in it resolves through /proc/self/fd/<fd>, inside the folder the handle holds,
76
- * never through the folder's path again; elsewhere through its path. */
89
+ * never through the folder's path again; elsewhere through its path: opened through no link (open), and each other
90
+ * act checked first (confirm). */
77
91
  class Held {
78
92
  handle;
79
93
  abs;
80
- constructor(handle, abs) {
94
+ reach;
95
+ constructor(handle, abs, reach) {
81
96
  this.handle = handle;
82
97
  this.abs = abs;
98
+ this.reach = reach;
99
+ }
100
+ /** The folder's path below the root ("" for the root). */
101
+ get below() {
102
+ return this.abs === this.reach.root ? "" : this.abs.slice(this.reach.root.length + 1);
83
103
  }
84
104
  /** The folder itself, as a path a call (or exec's cwd) can take. */
85
105
  get self() {
86
- return LINUX ? `/proc/self/fd/${this.handle.fd}` : this.abs;
106
+ return this.reach.procFd ? `/proc/self/fd/${this.handle.fd}` : this.abs;
87
107
  }
88
108
  /** Entry `name` of the folder. */
89
109
  at(name) {
90
- return LINUX ? `/proc/self/fd/${this.handle.fd}/${name}` : join(this.abs, name);
110
+ return this.reach.procFd ? `/proc/self/fd/${this.handle.fd}/${name}` : join(this.abs, name);
111
+ }
112
+ /** Entry `name` opened with `flags`. Off /proc/self/fd through no link anywhere below the root (beneath.ts): a link
113
+ * on the way, a folder swapped for one, fails ELOOP, so what opens is under the root. */
114
+ open(name, flags, mode) {
115
+ if (this.reach.procFd)
116
+ return open(this.at(name), flags, mode);
117
+ return openBeneath(this.reach.root, this.below === "" ? name : `${this.below}/${name}`, flags, mode);
118
+ }
119
+ /** Off /proc/self/fd, that this folder's path still opens, through no link, to the folder held (dev and inode), else
120
+ * ESCAPE (NOT_FOUND when it is gone): run just before each call that resolves a name in it again. On Linux there is
121
+ * nothing to check. */
122
+ async confirm(path) {
123
+ if (this.reach.procFd)
124
+ return;
125
+ let there;
126
+ try {
127
+ there = await openBeneath(this.reach.root, this.below, DIR_FLAGS);
128
+ }
129
+ catch (error) {
130
+ if (errno(error) === "ELOOP")
131
+ throw swapped(path);
132
+ throw failed(error, path);
133
+ }
134
+ try {
135
+ const [held, now] = await Promise.all([this.handle.stat(), there.stat()]);
136
+ if (now.dev !== held.dev || now.ino !== held.ino)
137
+ throw swapped(path);
138
+ }
139
+ finally {
140
+ await there.close();
141
+ }
142
+ }
143
+ /** Makes entry `name`, the file `made` just made by `open`, durable: syncs the folder it was made in. On Linux that is
144
+ * the folder held. Elsewhere `open` went by the folder's path, which may name another folder under the root by now
145
+ * (one put in its place), so the folder the path opens now, through no link, is synced, once its `name` is that very
146
+ * file (dev and inode); else ESCAPE, as for any swap. */
147
+ async syncMade(name, made, path) {
148
+ if (this.reach.procFd)
149
+ return this.handle.sync();
150
+ let parent;
151
+ let entry;
152
+ try {
153
+ parent = await openBeneath(this.reach.root, this.below, DIR_FLAGS);
154
+ entry = await openBeneath(this.reach.root, this.below === "" ? name : `${this.below}/${name}`, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
155
+ const now = await entry.stat();
156
+ if (now.dev !== made.dev || now.ino !== made.ino)
157
+ throw swapped(path);
158
+ await parent.sync();
159
+ }
160
+ catch (error) {
161
+ throw errno(error) === "ELOOP" ? swapped(path) : error;
162
+ }
163
+ finally {
164
+ await entry?.close();
165
+ await parent?.close();
166
+ }
167
+ }
168
+ /** `fn`, its folder confirmed before and after: what it read was read in the folder held. */
169
+ async confirmed(path, fn) {
170
+ await this.confirm(path);
171
+ const result = await fn();
172
+ await this.confirm(path);
173
+ return result;
174
+ }
175
+ /** Folder `name` of this one, just opened as `handle` (by `open`), held. The caller still owns the handle (it closes
176
+ * it, whether this resolves or not). */
177
+ async hold(handle, name) {
178
+ const next = new Held(handle, join(this.abs, name), this.reach);
179
+ await this.reach.onHeld?.(next.abs);
180
+ return next;
91
181
  }
92
182
  }
93
- /** Everything in held folder `dir` removed, folders by handle: a link is removed, never followed. */
94
- async function emptyTree(dir) {
95
- for (const name of await readdir(dir.self)) {
183
+ /** Everything in held folder `dir` removed, folders by handle: a link is removed, never followed. Off /proc/self/fd,
184
+ * each name is acted on only once its folder is confirmed (Held.confirm), and each folder is entered by Held.open. */
185
+ async function emptyTree(dir, path) {
186
+ for (const name of await dir.confirmed(path, () => readdir(dir.self))) {
187
+ await dir.confirm(path);
96
188
  const stats = await lstatOrNot(dir.at(name));
97
189
  if (stats === undefined)
98
190
  continue;
99
191
  if (!stats.isDirectory()) {
192
+ // Not a folder (a file, or a link: unlink removes the link itself, never what it points at).
193
+ await dir.confirm(path);
100
194
  await unlink(dir.at(name));
101
195
  continue;
102
196
  }
103
197
  let handle;
104
198
  try {
105
- handle = await open(dir.at(name), DIR_FLAGS);
199
+ handle = await dir.open(name, DIR_FLAGS);
106
200
  }
107
201
  catch (error) {
108
202
  if (errno(error) !== "ENOTDIR" && errno(error) !== "ELOOP")
109
203
  throw error;
204
+ await dir.confirm(path);
110
205
  await unlink(dir.at(name));
111
206
  continue;
112
207
  }
113
208
  try {
114
- await emptyTree(new Held(handle, join(dir.abs, name)));
209
+ await emptyTree(await dir.hold(handle, name), path);
115
210
  }
116
211
  finally {
117
212
  await handle.close();
118
213
  }
214
+ await dir.confirm(path);
119
215
  await rmdir(dir.at(name));
120
216
  }
121
217
  }
122
218
  class LocalWorkspace {
123
219
  #root;
124
- #real;
125
- constructor(root) {
220
+ #options;
221
+ #reach;
222
+ constructor(root, options) {
126
223
  this.#root = root;
224
+ this.#options = options;
127
225
  }
128
226
  /** The root, its links resolved once (the root itself is trusted; nothing below it is), held open. */
129
227
  async #openRoot() {
130
228
  try {
131
- this.#real ??= await realpath(this.#root);
132
- return new Held(await open(this.#real, DIR_FLAGS), this.#real);
229
+ this.#reach ??= { root: await realpath(this.#root), procFd: this.#options.procFd ?? LINUX, ...(this.#options.onHeld ? { onHeld: this.#options.onHeld } : {}) };
230
+ return new Held(await open(this.#reach.root, DIR_FLAGS), this.#reach.root, this.#reach);
133
231
  }
134
232
  catch (error) {
135
233
  throw new WorkspaceError("UNAVAILABLE", `the workspace's folder ${this.#root} is not there`, { cause: error });
@@ -157,13 +255,14 @@ class LocalWorkspace {
157
255
  let handle;
158
256
  for (let made = false; handle === undefined;) {
159
257
  try {
160
- handle = await open(dir.at(name), DIR_FLAGS);
258
+ handle = await dir.open(name, DIR_FLAGS);
161
259
  }
162
260
  catch (error) {
163
261
  const code = errno(error);
164
262
  if (code === "ENOENT" && options.make && !made) {
165
263
  made = true;
166
264
  try {
265
+ await dir.confirm(path);
167
266
  await makeDir(dir.at(name), 0o777);
168
267
  await dir.handle.sync();
169
268
  }
@@ -183,7 +282,14 @@ class LocalWorkspace {
183
282
  throw new WorkspaceError(options.make ? "EXISTS" : i === count - 1 ? options.notDir ?? "NOT_FOUND" : "NOT_FOUND", `${show(part)} is not a directory`, { path });
184
283
  }
185
284
  }
186
- const next = new Held(handle, join(dir.abs, name));
285
+ let next;
286
+ try {
287
+ next = await dir.hold(handle, name);
288
+ }
289
+ catch (error) {
290
+ await handle.close().catch(() => undefined);
291
+ throw error;
292
+ }
187
293
  await dir.handle.close();
188
294
  dir = next;
189
295
  }
@@ -205,7 +311,7 @@ class LocalWorkspace {
205
311
  return this.#in(path, segments, segments.length - 1, async (dir) => {
206
312
  let handle;
207
313
  try {
208
- handle = await open(dir.at(segments.at(-1)), O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
314
+ handle = await dir.open(segments.at(-1), O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
209
315
  }
210
316
  catch (error) {
211
317
  throw failed(error, path);
@@ -241,19 +347,20 @@ class LocalWorkspace {
241
347
  const name = segments.at(-1);
242
348
  await this.#in(path, segments, segments.length - 1, async (dir) => {
243
349
  try {
244
- const existing = await lstatOrNot(dir.at(name));
350
+ const existing = await dir.confirmed(path, () => lstatOrNot(dir.at(name)));
245
351
  if (existing?.isSymbolicLink())
246
352
  throw escape(path, path);
247
353
  if (existing !== undefined && !existing.isFile())
248
354
  throw new WorkspaceError("REFUSED", `${show(path)} is ${existing.isDirectory() ? "a directory" : "not a file"}`, { path });
249
355
  const temp = `.workspace-${randomBytes(8).toString("hex")}.tmp`;
250
- const handle = await open(dir.at(temp), O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
356
+ const handle = await dir.open(temp, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
251
357
  try {
252
358
  if (existing !== undefined)
253
359
  await handle.chmod(existing.mode & 0o777);
254
360
  await handle.writeFile(bytes);
255
361
  await handle.sync();
256
362
  await handle.close();
363
+ await dir.confirm(path);
257
364
  await rename(dir.at(temp), dir.at(name));
258
365
  }
259
366
  catch (error) {
@@ -277,23 +384,25 @@ class LocalWorkspace {
277
384
  let made = false;
278
385
  let handle;
279
386
  try {
280
- handle = await open(dir.at(target), O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
387
+ handle = await dir.open(target, O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
281
388
  }
282
389
  catch (error) {
283
390
  if (errno(error) !== "ENOENT")
284
391
  throw error;
285
392
  try {
286
- handle = await open(dir.at(target), O_RDWR | O_APPEND | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
393
+ handle = await dir.open(target, O_RDWR | O_APPEND | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
287
394
  made = true;
288
395
  }
289
396
  catch (again) {
290
397
  if (errno(again) !== "EEXIST")
291
398
  throw again;
292
- handle = await open(dir.at(target), O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
399
+ handle = await dir.open(target, O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
293
400
  }
294
401
  }
402
+ let stats;
295
403
  try {
296
- if (!(await handle.stat()).isFile())
404
+ stats = await handle.stat();
405
+ if (!stats.isFile())
297
406
  throw new WorkspaceError("REFUSED", `${show(path)} is not a file`, { path });
298
407
  await handle.writeFile(bytes);
299
408
  await handle.datasync();
@@ -302,7 +411,7 @@ class LocalWorkspace {
302
411
  await handle.close();
303
412
  }
304
413
  if (made)
305
- await dir.handle.sync();
414
+ await dir.syncMade(target, stats, path);
306
415
  }
307
416
  catch (error) {
308
417
  throw failed(error, path);
@@ -321,7 +430,7 @@ class LocalWorkspace {
321
430
  try {
322
431
  return await this.#in(path, segments, segments.length - 1, async (dir) => {
323
432
  try {
324
- const stats = await lstatOrNot(dir.at(segments.at(-1)));
433
+ const stats = await dir.confirmed(path, () => lstatOrNot(dir.at(segments.at(-1))));
325
434
  return stats === undefined ? undefined : of(stats);
326
435
  }
327
436
  catch (error) {
@@ -340,7 +449,8 @@ class LocalWorkspace {
340
449
  const segments = relativeSegments(dir);
341
450
  return this.#in(dir, segments, segments.length, async (held) => {
342
451
  try {
343
- const entries = await Promise.all((await readdir(held.self)).map(async (name) => {
452
+ // Off /proc/self/fd the folder is confirmed before and after: a listing of a folder swapped in is ESCAPE.
453
+ const entries = await held.confirmed(dir, async () => Promise.all((await readdir(held.self)).map(async (name) => {
344
454
  const stats = await lstatOrNot(held.at(name));
345
455
  if (stats?.isDirectory())
346
456
  return { name, kind: "dir", size: 0, mtimeMs: stats.mtimeMs };
@@ -349,7 +459,7 @@ class LocalWorkspace {
349
459
  // Only a flag for the listing: the read itself is what refuses (REFUSED, permission denied).
350
460
  const readable = await access(held.at(name), constants.R_OK).then(() => true, () => false);
351
461
  return { name, kind: "file", size: stats.size, mtimeMs: stats.mtimeMs, ...(readable ? {} : { unreadable: true }) };
352
- }));
462
+ })));
353
463
  return entries.filter((entry) => entry !== undefined).sort((a, b) => byName(a.name, b.name));
354
464
  }
355
465
  catch (error) {
@@ -377,12 +487,16 @@ class LocalWorkspace {
377
487
  const from = options.path ?? "";
378
488
  const segments = relativeSegments(from);
379
489
  const job = { pattern, glob: options.glob, limit: Math.min(max, GREP_MAX), fileMax: GREP_FILE_MAX, lineMax: GREP_LINE_MAX, probe: BINARY_PROBE };
380
- const search = (dir, rel, only) => LocalWorkspace.#searchIn({ ...job, dir: dir.self, rel, ...(only === undefined ? {} : { only }) }, Math.min(timeMs, GREP_TIME_MS));
490
+ // Off /proc/self/fd the worker opens each entry through no link below the root, as a read does (grep-worker.ts).
491
+ const search = async (dir, rel, only) => {
492
+ await dir.confirm(from);
493
+ return LocalWorkspace.#searchIn({ ...job, dir: dir.self, rel, procFd: dir.reach.procFd, root: dir.reach.root, ...(only === undefined ? {} : { only }) }, Math.min(timeMs, GREP_TIME_MS));
494
+ };
381
495
  if (segments.length === 0)
382
496
  return this.#in(from, segments, 0, (root) => search(root, ""));
383
497
  return this.#in(from, segments, segments.length - 1, async (parent) => {
384
498
  const name = segments.at(-1);
385
- const stats = await lstatOrNot(parent.at(name)).catch((error) => { throw failed(error, from); });
499
+ const stats = await parent.confirmed(from, () => lstatOrNot(parent.at(name))).catch((error) => { throw failed(error, from); });
386
500
  if (stats === undefined)
387
501
  throw new WorkspaceError("NOT_FOUND", `${show(from)} is not there`, { path: from });
388
502
  if (stats.isSymbolicLink())
@@ -391,9 +505,9 @@ class LocalWorkspace {
391
505
  return search(parent, segments.join("/"), name);
392
506
  if (!stats.isDirectory())
393
507
  throw new WorkspaceError("REFUSED", `${show(from)} is neither a file nor a directory`, { path: from });
394
- const handle = await open(parent.at(name), DIR_FLAGS).catch((error) => { throw failed(error, from); });
508
+ const handle = await parent.open(name, DIR_FLAGS).catch((error) => { throw failed(error, from); });
395
509
  try {
396
- return await search(new Held(handle, join(parent.abs, name)), segments.join("/"));
510
+ return await search(await parent.hold(handle, name), segments.join("/"));
397
511
  }
398
512
  finally {
399
513
  await handle.close();
@@ -438,23 +552,26 @@ class LocalWorkspace {
438
552
  try {
439
553
  await this.#in(path, segments, segments.length - 1, async (dir) => {
440
554
  try {
441
- const stats = await lstatOrNot(dir.at(name));
555
+ const stats = await dir.confirmed(path, () => lstatOrNot(dir.at(name)));
442
556
  if (stats === undefined)
443
557
  throw new WorkspaceError("NOT_FOUND", `${show(path)} is not there`, { path });
444
558
  if (stats.isSymbolicLink())
445
559
  throw escape(path, path);
446
- if (!stats.isDirectory())
560
+ if (!stats.isDirectory()) {
561
+ await dir.confirm(path);
447
562
  await unlink(dir.at(name));
563
+ }
448
564
  else {
449
565
  if (options.recursive) {
450
- const handle = await open(dir.at(name), DIR_FLAGS);
566
+ const handle = await dir.open(name, DIR_FLAGS);
451
567
  try {
452
- await emptyTree(new Held(handle, join(dir.abs, name)));
568
+ await emptyTree(await dir.hold(handle, name), path);
453
569
  }
454
570
  finally {
455
571
  await handle.close();
456
572
  }
457
573
  }
574
+ await dir.confirm(path);
458
575
  await rmdir(dir.at(name));
459
576
  }
460
577
  await dir.handle.sync();
@@ -489,8 +606,9 @@ class LocalWorkspace {
489
606
  const { signal } = options;
490
607
  if (signal?.aborted)
491
608
  throw abortError(signal);
492
- // The child starts in the held folder itself (/proc/self/fd/<fd> on Linux), held until the child is done.
493
- return this.#in(cwd, segments, segments.length, (dir) => new Promise((resolve, reject) => {
609
+ // The child starts in the held folder itself (/proc/self/fd/<fd> on Linux), held until the child is done. Off
610
+ // /proc/self/fd its path is confirmed just before the spawn.
611
+ return this.#in(cwd, segments, segments.length, (dir) => dir.confirm(cwd).then(() => new Promise((resolve, reject) => {
494
612
  if (signal?.aborted)
495
613
  return reject(abortError(signal));
496
614
  const child = spawn(argv[0], argv.slice(1), {
@@ -574,7 +692,7 @@ class LocalWorkspace {
574
692
  child.stdin.on("error", () => undefined);
575
693
  child.stdin.end(Buffer.from(options.stdin.buffer, options.stdin.byteOffset, options.stdin.byteLength));
576
694
  }
577
- }), { notDir: "REFUSED" });
695
+ })), { notDir: "REFUSED" });
578
696
  }
579
697
  /** No computer: every background call is refused in words. */
580
698
  process = noProcesses;
@@ -596,11 +714,10 @@ class LocalWorkspace {
596
714
  async #syncUp(path, only) {
597
715
  const segments = relativeSegments(path);
598
716
  const entry = await this.#in(path, segments, segments.length - 1, async (dir) => {
599
- const at = dir.at(segments.at(-1));
600
717
  for (const flags of [O_RDONLY, O_WRONLY]) {
601
718
  let handle;
602
719
  try {
603
- handle = await open(at, flags | O_NOFOLLOW | O_NONBLOCK);
720
+ handle = await dir.open(segments.at(-1), flags | O_NOFOLLOW | O_NONBLOCK);
604
721
  }
605
722
  catch (error) {
606
723
  if (errno(error) === "ENOENT" || errno(error) === "ELOOP")
@@ -625,8 +742,9 @@ class LocalWorkspace {
625
742
  return entry;
626
743
  }
627
744
  }
628
- /** A Workspace on folder `root` of this machine. The folder must be there when it is first used (else UNAVAILABLE). */
629
- export const localWorkspace = (root) => new LocalWorkspace(root);
745
+ /** A Workspace on folder `root` of this machine. The folder must be there when it is first used (else UNAVAILABLE).
746
+ * `options` are a test's: the path-resolving branch forced, and a hook where a swap would land. */
747
+ export const localWorkspace = (root, options = {}) => new LocalWorkspace(root, options);
630
748
  /** `work` as a Workspace: a folder of this machine, by its path, becomes its LocalWorkspace. For the callers that still
631
749
  * hand a run's folder by its path (the run's start and its process), until they hand the run's Workspace. */
632
750
  export const workspaceAt = (work) => (typeof work === "string" ? localWorkspace(work) : work);
@@ -1,15 +1,17 @@
1
- import type { CdpSession, ShellPlace } from "@parcha/agentrun-kernel/kernel";
2
- import type { ComputerClient, ComputerSettingKind, Group, KindCapabilities, MountReadBack, MountSpec, ProviderEntry, Result } from "@parcha/agentrun-computer";
1
+ import type { ShellPlace } from "@parcha/agentrun-kernel/kernel";
2
+ import { type ComputerClient, type ComputerSettingKind, type GpuSpec, type Group, type KindCapabilities, type MountReadBack, type MountSpec, type ProviderEntry, type Result } from "@parcha/agentrun-computer";
3
+ import { type DockerDaemon } from "../docker-daemon.js";
3
4
  import type { MountCheck } from "./attach.js";
4
5
  import type { RunComputer } from "./run-tools.js";
5
6
  import type { Workspace } from "./workspace.js";
6
7
  /** The setting kind (what an agent is given, not a computer's capabilities().kind), a machine's kind and groups, and one
7
8
  * provider of the kind registry: the computer module's own types. Where a run's shell is: the kernel registry's. */
8
9
  export type { ComputerSettingKind, KindCapabilities, ProviderEntry, ShellPlace };
9
- /** An agent's computer setting. */
10
+ /** An agent's computer setting: a sandbox's may ask for GPUs. */
10
11
  export type ComputerSetting = {
11
12
  readonly kind: string;
12
13
  readonly provider?: string | null;
14
+ readonly gpu?: GpuSpec;
13
15
  };
14
16
  /** The computer module's kind registry (src/kinds.ts), by its own names: the setting kinds, why a machine does not serve
15
17
  * one (servingRefusals, whose words a refusal here carries), and the providers. */
@@ -19,25 +21,50 @@ export type KindRegistry = {
19
21
  readonly PROVIDERS: readonly ProviderEntry[];
20
22
  };
21
23
  /** A computer a provider started for the run: its ref, its computerd client and what it offers (sandbox, desktop,
22
- * phone), the read-back of its mount (when mounted), its CDP connect (browser), and its release. */
24
+ * phone), the read-back of its mount (when mounted), and its release. A browser is started by none: the claim gives
25
+ * the run's browser tool its provider (`browser`), which opens each session at the tool's first call, and the release
26
+ * lets go of any the tool left open. */
23
27
  export type LaunchedComputer = {
24
28
  readonly id: string;
25
29
  readonly groups: readonly (Group | string)[];
26
30
  readonly client?: ComputerClient;
27
31
  readBack?(): Promise<Result<MountReadBack>>;
28
- connect?(): Promise<CdpSession>;
32
+ readonly browser?: ClaimBrowser;
29
33
  release(): Promise<void>;
30
34
  };
35
+ /** A browser computer's provider as the run's browser tool opens its sessions through it: each session one computer of
36
+ * the provider's, made under the run's labels and the tool's tag (so a create whose answer was lost is found again),
37
+ * its CDP URL read through the provider's connect at each attach (a secret: it goes only to the driver), and released
38
+ * when the tool lets it go. Errors carry the provider's words, and its code. So the session's time is the time the
39
+ * tool holds it, which is what the run's spend books. */
40
+ export type ClaimBrowser = {
41
+ /** The provider's id: the session's price and its name. */
42
+ readonly provider: string;
43
+ /** The longest a session lives, in seconds. */
44
+ readonly maxLifetimeS: number;
45
+ /** Makes a session for `tag`, to live at most `lifetimeS`: its computer's id. */
46
+ open(tag: string, lifetimeS: number, signal?: AbortSignal): Promise<string>;
47
+ /** The sessions made for `tag`, by id. */
48
+ find(tag: string, signal?: AbortSignal): Promise<string[]>;
49
+ /** The session's CDP URL now. */
50
+ url(id: string): Promise<string>;
51
+ /** Ends the session; one already gone is ended. */
52
+ close(id: string): Promise<void>;
53
+ };
31
54
  /** The claim's side: the keys saved for a provider (Settings → Computers; values, never shown), and the launch of one
32
55
  * computer of the kind, with the run's folder as its mount when it mounts it. A launch that fails throws its words. */
33
56
  export type ClaimSide = {
34
57
  keysOf(provider: string): Promise<Readonly<Record<string, string>>>;
35
58
  /** Whether a provider that binds a folder of this machine (Docker) answers here now: the Mode 1 default asks it. */
36
59
  answers(provider: string): Promise<boolean>;
60
+ /** Its daemon's answer (docker-daemon.ts), asked when a launch on such a provider fails: none answering is refused in
61
+ * the one wording a run's start and Settings → Computers say (noDockerWords). Absent: the launch's own words. */
62
+ daemon?(provider: string): Promise<DockerDaemon>;
37
63
  launch(entry: ProviderEntry, spec: {
38
64
  readonly kind: ComputerSettingKind;
39
65
  readonly keys: Readonly<Record<string, string>>;
40
66
  readonly mount?: MountSpec;
67
+ readonly gpu?: GpuSpec;
41
68
  readonly signal?: AbortSignal;
42
69
  }): Promise<LaunchedComputer>;
43
70
  };
@@ -47,15 +74,28 @@ export type Port = "files" | "exec" | "processes" | "screen" | "input" | "phone"
47
74
  /** A provider's keys as the claim reads them: each key its registry entry declares, by `keyOf` (the server's reader:
48
75
  * key-meta.ts keyReader, the environment's value, else the saved one); a key with no value is left out. */
49
76
  export declare const providerKeys: (registry: Pick<KindRegistry, "PROVIDERS">, keyOf: (name: string) => Promise<string | undefined>) => ClaimSide["keysOf"];
77
+ /** Whether a provider's computers run only on the vendor's own network: the network forms it declares (its module's
78
+ * NETWORK, its capabilities().network) are "open" alone, as a cloud phone's and a hosted browser's are. */
79
+ export declare const vendorNetworkOnly: (network: readonly string[] | undefined) => boolean;
80
+ /** Whether a provider's computers can't have no network: it declares its network forms and "none" isn't one (a cloud
81
+ * phone, a hosted browser, Local Chrome). */
82
+ export declare const needsNetwork: (network: readonly string[] | undefined) => boolean;
83
+ /** Why a computer that needs a network is refused where this server's AGENTRUN_BOX_ALLOW is none, in words that name the
84
+ * fix: the operator said no network at all, and the computer can't run without one. */
85
+ export declare const noNetworkRefusal: (label: string, kind: string) => string;
50
86
  /** Whether an agent's computer `setting` can be had in `mode` now, by the answers the claim gives (resolveComputer: the
51
87
  * kind, the provider and what it serves, the mode's mount, the provider's keys by `keyOf`): ok, or its refusal in words
52
88
  * that name the fix. Nothing starts. A run's start asks it before the run is made (runnable.ts).
53
89
  *
54
- * `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not, in words
55
- * that say how to fix it (the server's start-time probe of it). A Mode 1 sandbox on such a provider is refused in those
56
- * words here, at the start, where the claim would only fail to launch it. Asked here, not in resolveComputer: the claim
57
- * has no such answer and launches it. Absent: not asked. */
58
- export declare function computerReadiness(setting: ComputerSetting, mode: 1 | 2, registry: KindRegistry, keyOf: (name: string) => Promise<string | undefined>, answers?: (provider: string) => true | string): Promise<{
90
+ * `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's
91
+ * daemon check, docker-daemon.ts). Any computer on such a provider, a sandbox or a desktop in either mode, is refused
92
+ * here, at the start, where the claim would only fail to launch it: no daemon at all in the one wording Settings →
93
+ * Computers and the claim say (noDockerWords), another reason in its own words. Asked here, not in resolveComputer: the
94
+ * claim launches it, and asks only once its launch fails (ClaimSide.daemon). Absent: not asked.
95
+ *
96
+ * `boxAllow`: this server's allow setting (box-settings.ts boxAllowOf). Under "none", a computer whose provider makes no
97
+ * "none" is refused (noNetworkRefusal), as the claim refuses it. Absent: not asked. */
98
+ export declare function computerReadiness(setting: ComputerSetting, mode: 1 | 2, registry: KindRegistry, keyOf: (name: string) => Promise<string | undefined>, answers?: (provider: string) => DockerDaemon | Promise<DockerDaemon>, boxAllow?: readonly string[] | "none"): Promise<{
59
99
  readonly ok: true;
60
100
  } | {
61
101
  readonly refused: string;