@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +260 -168
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/box-image.d.ts +1 -97
  19. package/dist/box-image.js +4 -284
  20. package/dist/box-paths.d.ts +2 -7
  21. package/dist/box-paths.js +7 -13
  22. package/dist/box-settings.d.ts +0 -11
  23. package/dist/box-settings.js +4 -29
  24. package/dist/browser-commands.js +1 -1
  25. package/dist/browser-computer.d.ts +47 -3
  26. package/dist/browser-computer.js +286 -18
  27. package/dist/browser-person.d.ts +19 -2
  28. package/dist/browser-person.js +55 -6
  29. package/dist/browser-wait-ended.d.ts +23 -0
  30. package/dist/browser-wait-ended.js +42 -0
  31. package/dist/cap.d.ts +13 -41
  32. package/dist/cap.js +24 -73
  33. package/dist/cli.js +4 -22
  34. package/dist/computer-routes.d.ts +1 -4
  35. package/dist/computer-routes.js +3 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +38 -1
  38. package/dist/computer-view.d.ts +11 -2
  39. package/dist/computer-view.js +2 -1
  40. package/dist/computers.d.ts +48 -7
  41. package/dist/computers.js +100 -23
  42. package/dist/console/assets/index-BI4Byidu.js +550 -0
  43. package/dist/console/assets/index-C19gUF2n.css +1 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/docker-daemon.d.ts +2 -2
  46. package/dist/docker-daemon.js +2 -2
  47. package/dist/errors.js +5 -5
  48. package/dist/faux-computers.js +4 -0
  49. package/dist/files.d.ts +1 -9
  50. package/dist/files.js +1 -9
  51. package/dist/github.d.ts +22 -2
  52. package/dist/github.js +42 -8
  53. package/dist/gpu-words.d.ts +14 -0
  54. package/dist/gpu-words.js +21 -0
  55. package/dist/graph-view.d.ts +2 -0
  56. package/dist/graph-view.js +25 -1
  57. package/dist/handed-values.d.ts +1 -1
  58. package/dist/handed-values.js +1 -1
  59. package/dist/harness-install.d.ts +60 -3
  60. package/dist/harness-install.js +322 -34
  61. package/dist/harness.js +1 -1
  62. package/dist/host-tools.d.ts +8 -9
  63. package/dist/host-tools.js +7 -7
  64. package/dist/index.d.ts +1 -3
  65. package/dist/index.js +1 -2
  66. package/dist/key-refusal.d.ts +1 -1
  67. package/dist/key-refusal.js +2 -2
  68. package/dist/learn/check.d.ts +7 -1
  69. package/dist/learn/check.js +123 -5
  70. package/dist/learn/commit.d.ts +40 -6
  71. package/dist/learn/commit.js +164 -20
  72. package/dist/learn/folder.d.ts +5 -0
  73. package/dist/learn/folder.js +33 -0
  74. package/dist/learn/grade.d.ts +18 -1
  75. package/dist/learn/grade.js +86 -16
  76. package/dist/learn/index.d.ts +1 -1
  77. package/dist/learn/index.js +1 -1
  78. package/dist/learn/learning.sh +12 -1
  79. package/dist/learn/notes.d.ts +3 -0
  80. package/dist/learn/notes.js +3 -0
  81. package/dist/learn/reflect.d.ts +5 -2
  82. package/dist/learn/reflect.js +43 -29
  83. package/dist/learn/skills.d.ts +4 -0
  84. package/dist/learn/skills.js +7 -0
  85. package/dist/learned-nodes.d.ts +6 -2
  86. package/dist/learned-workflow.d.ts +19 -9
  87. package/dist/learned-workflow.js +62 -34
  88. package/dist/learning-cost.d.ts +79 -0
  89. package/dist/learning-cost.js +69 -0
  90. package/dist/learning-routes.d.ts +8 -3
  91. package/dist/learning-routes.js +9 -6
  92. package/dist/learning-words.d.ts +3 -0
  93. package/dist/learning-words.js +6 -2
  94. package/dist/learning.d.ts +13 -6
  95. package/dist/learning.js +4 -2
  96. package/dist/mcp-probe.d.ts +8 -1
  97. package/dist/mcp-probe.js +62 -20
  98. package/dist/mcp-secret-writes.js +4 -0
  99. package/dist/mcp-servers-store.js +8 -3
  100. package/dist/model.d.ts +5 -5
  101. package/dist/model.js +6 -6
  102. package/dist/openapi.d.ts +2 -0
  103. package/dist/openapi.js +204 -47
  104. package/dist/owner.d.ts +0 -1
  105. package/dist/owner.js +0 -2
  106. package/dist/paid-calls.js +1 -1
  107. package/dist/place-offers.d.ts +97 -0
  108. package/dist/place-offers.js +206 -0
  109. package/dist/place.d.ts +9 -13
  110. package/dist/place.js +22 -32
  111. package/dist/port-models.d.ts +2 -1
  112. package/dist/port-models.js +5 -3
  113. package/dist/print.d.ts +1 -8
  114. package/dist/print.js +1 -14
  115. package/dist/propose.d.ts +1 -0
  116. package/dist/propose.js +25 -10
  117. package/dist/run-cut.d.ts +5 -0
  118. package/dist/run-cut.js +19 -0
  119. package/dist/run-db.js +3 -3
  120. package/dist/run-launch.d.ts +14 -1
  121. package/dist/run-launch.js +7 -2
  122. package/dist/run-learning-served.d.ts +1 -1
  123. package/dist/run-manifest.d.ts +2 -2
  124. package/dist/run-manifest.js +2 -2
  125. package/dist/run-secrets.js +3 -3
  126. package/dist/run-timeline-served.js +56 -44
  127. package/dist/run-view.d.ts +5 -2
  128. package/dist/run-view.js +4 -3
  129. package/dist/runnable.d.ts +2 -2
  130. package/dist/runnable.js +6 -2
  131. package/dist/runner/adapter-loop.d.ts +16 -1
  132. package/dist/runner/adapter-loop.js +131 -30
  133. package/dist/runner/adapter-run-spec.d.ts +25 -4
  134. package/dist/runner/adapter-run-spec.js +103 -24
  135. package/dist/runner/adapters/pi.d.ts +11 -3
  136. package/dist/runner/adapters/pi.js +35 -12
  137. package/dist/runner/beside.js +6 -2
  138. package/dist/runner/cli-run-spec.d.ts +7 -0
  139. package/dist/runner/cli-run-spec.js +92 -38
  140. package/dist/runner/commands.d.ts +5 -1
  141. package/dist/runner/commands.js +3 -3
  142. package/dist/runner/conformance/harness.d.ts +0 -1
  143. package/dist/runner/conformance/harness.js +8 -5
  144. package/dist/runner/github-app.js +2 -2
  145. package/dist/runner/harness-loops.js +1 -1
  146. package/dist/runner/journal-kinds.d.ts +15 -5
  147. package/dist/runner/journal-kinds.js +6 -1
  148. package/dist/runner/learning-end.d.ts +15 -0
  149. package/dist/runner/learning-end.js +26 -5
  150. package/dist/runner/learning-factory.js +6 -2
  151. package/dist/runner/learning-loop.d.ts +73 -1
  152. package/dist/runner/learning-loop.js +203 -18
  153. package/dist/runner/learning-seed.d.ts +2 -0
  154. package/dist/runner/learning-seed.js +1 -1
  155. package/dist/runner/loop-contract.d.ts +8 -0
  156. package/dist/runner/loop-contract.js +6 -0
  157. package/dist/runner/loop.d.ts +5 -1
  158. package/dist/runner/loop.js +20 -0
  159. package/dist/runner/main.js +12 -2
  160. package/dist/runner/mcp-claim.d.ts +4 -0
  161. package/dist/runner/mcp-claim.js +29 -1
  162. package/dist/runner/mcp-github.d.ts +4 -2
  163. package/dist/runner/mcp-github.js +0 -7
  164. package/dist/runner/mcp-run.d.ts +2 -0
  165. package/dist/runner/mcp-run.js +1 -0
  166. package/dist/runner/metrics.d.ts +4 -0
  167. package/dist/runner/metrics.js +9 -0
  168. package/dist/runner/model-route.d.ts +3 -0
  169. package/dist/runner/model-route.js +5 -2
  170. package/dist/runner/pr-checkout.d.ts +59 -0
  171. package/dist/runner/pr-checkout.js +176 -0
  172. package/dist/runner/reflect-hook.d.ts +1 -0
  173. package/dist/runner/reflect-hook.js +3 -3
  174. package/dist/runner/runner.js +47 -12
  175. package/dist/runner/spec-holds.d.ts +8 -3
  176. package/dist/runner/spec-holds.js +12 -10
  177. package/dist/runner/store-port.d.ts +4 -1
  178. package/dist/runner/store-secrets.js +17 -1
  179. package/dist/runner/subagent.d.ts +44 -0
  180. package/dist/runner/subagent.js +188 -0
  181. package/dist/runner/workflow-host.d.ts +18 -2
  182. package/dist/runner/workflow-host.js +23 -3
  183. package/dist/runner/workflow-loop.d.ts +5 -2
  184. package/dist/runner/workflow-loop.js +9 -8
  185. package/dist/runner/workflow-spec.d.ts +26 -14
  186. package/dist/runner/workflow-spec.js +97 -30
  187. package/dist/runs-over-store.d.ts +11 -6
  188. package/dist/runs-over-store.js +111 -24
  189. package/dist/sealing.js +1 -2
  190. package/dist/secret-cut.d.ts +1 -1
  191. package/dist/secret-cut.js +1 -1
  192. package/dist/server.d.ts +32 -49
  193. package/dist/server.js +249 -199
  194. package/dist/store/agent-body.d.ts +9 -2
  195. package/dist/store/agent-body.js +16 -8
  196. package/dist/store/deadline.js +9 -5
  197. package/dist/store/index.d.ts +3 -3
  198. package/dist/store/index.js +2 -2
  199. package/dist/store/journal/storage.js +2 -1
  200. package/dist/store/postgres/connection.js +9 -4
  201. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  202. package/dist/store/schema.d.ts +2 -1
  203. package/dist/store/schema.js +11 -8
  204. package/dist/store/seal.d.ts +13 -0
  205. package/dist/store/seal.js +19 -0
  206. package/dist/store/sqlite/connection.d.ts +5 -0
  207. package/dist/store/sqlite/connection.js +88 -47
  208. package/dist/store/sqlite/run-patch.d.ts +18 -2
  209. package/dist/store/sqlite/run-patch.js +31 -2
  210. package/dist/store/sqlite/store.js +65 -11
  211. package/dist/store/store.d.ts +62 -12
  212. package/dist/store/store.js +22 -1
  213. package/dist/store-reads/analytics.js +3 -2
  214. package/dist/store-reads/cap.d.ts +1 -3
  215. package/dist/store-reads/cap.js +8 -6
  216. package/dist/store-reads/decisions.d.ts +2 -2
  217. package/dist/store-reads/decisions.js +3 -6
  218. package/dist/store-reads/journal.js +45 -12
  219. package/dist/store-reads/learning.d.ts +15 -1
  220. package/dist/store-reads/learning.js +68 -10
  221. package/dist/store-reads/runs.d.ts +6 -4
  222. package/dist/store-reads/runs.js +17 -10
  223. package/dist/store-reads/stats.js +5 -1
  224. package/dist/store-view.js +45 -19
  225. package/dist/template-eval.js +2 -1
  226. package/dist/templates.d.ts +64 -0
  227. package/dist/templates.js +101 -16
  228. package/dist/timeline/timeline.d.ts +3 -1
  229. package/dist/timeline/timeline.js +19 -4
  230. package/dist/tool-blurbs.js +1 -0
  231. package/dist/tool-budget.d.ts +8 -0
  232. package/dist/tool-budget.js +7 -1
  233. package/dist/tool-gate.d.ts +7 -1
  234. package/dist/tool-gate.js +7 -2
  235. package/dist/tool-plane.d.ts +33 -19
  236. package/dist/tool-plane.js +64 -27
  237. package/dist/tools.d.ts +18 -34
  238. package/dist/tools.js +104 -70
  239. package/dist/trigger-signatures.d.ts +1 -0
  240. package/dist/trigger-signatures.js +3 -1
  241. package/dist/triggers.d.ts +3 -3
  242. package/dist/triggers.js +2 -2
  243. package/dist/turn-end.d.ts +0 -3
  244. package/dist/turn-end.js +0 -3
  245. package/dist/usage-lines.d.ts +1 -1
  246. package/dist/validate.d.ts +6 -0
  247. package/dist/validate.js +30 -3
  248. package/dist/webhooks.d.ts +2 -1
  249. package/dist/webhooks.js +5 -2
  250. package/dist/workflow/decision-recovery.d.ts +23 -0
  251. package/dist/workflow/decision-recovery.js +80 -0
  252. package/dist/workflow/decisions.d.ts +134 -0
  253. package/dist/workflow/decisions.js +46 -0
  254. package/dist/workflow/host-session.d.ts +5 -0
  255. package/dist/workflow/host-session.js +85 -0
  256. package/dist/workflow/host-tools.d.ts +3 -0
  257. package/dist/workflow/host-tools.js +3 -0
  258. package/dist/workflow/node-runner.d.ts +112 -0
  259. package/dist/workflow/node-runner.js +270 -0
  260. package/dist/workflow/node.d.ts +88 -0
  261. package/dist/workflow/node.js +99 -0
  262. package/dist/workflow/operator-error.d.ts +4 -0
  263. package/dist/workflow/operator-error.js +4 -0
  264. package/dist/workflow/pi-versions.d.ts +9 -0
  265. package/dist/workflow/pi-versions.js +8 -0
  266. package/dist/workflow/readers.d.ts +36 -0
  267. package/dist/workflow/readers.js +145 -0
  268. package/dist/workflow/record-file.d.ts +10 -0
  269. package/dist/workflow/record-file.js +56 -0
  270. package/dist/workflow/record-tool.d.ts +76 -0
  271. package/dist/workflow/record-tool.js +126 -0
  272. package/dist/workflow/record.d.ts +151 -0
  273. package/dist/workflow/record.js +401 -0
  274. package/dist/workflow/run-error.d.ts +16 -0
  275. package/dist/workflow/run-error.js +26 -0
  276. package/dist/workflow/runner.d.ts +6 -0
  277. package/dist/workflow/runner.js +240 -0
  278. package/dist/workflow/store.d.ts +23 -0
  279. package/dist/workflow/store.js +242 -0
  280. package/dist/workflow/task.d.ts +133 -0
  281. package/dist/workflow/task.js +411 -0
  282. package/dist/workflow/thinking.d.ts +3 -0
  283. package/dist/workflow/thinking.js +7 -0
  284. package/dist/workflow/tool-context.d.ts +21 -0
  285. package/dist/workflow/tool-context.js +13 -0
  286. package/dist/workflow/types.d.ts +126 -0
  287. package/dist/workflow/types.js +1 -0
  288. package/dist/workflow/wal.d.ts +11 -0
  289. package/dist/workflow/wal.js +106 -0
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/agent-computer.d.ts +137 -0
  292. package/dist/workspace/agent-computer.js +292 -0
  293. package/dist/workspace/archil-claim.d.ts +11 -0
  294. package/dist/workspace/archil-claim.js +18 -10
  295. package/dist/workspace/archil-disks.d.ts +49 -0
  296. package/dist/workspace/archil-disks.js +185 -0
  297. package/dist/workspace/archil-exec.js +2 -3
  298. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  299. package/dist/workspace/archil-mount-credential.js +13 -4
  300. package/dist/workspace/computer-deps.d.ts +16 -8
  301. package/dist/workspace/computer-deps.js +18 -7
  302. package/dist/workspace/computer-for-claim.d.ts +42 -6
  303. package/dist/workspace/computer-for-claim.js +209 -9
  304. package/dist/workspace/computer-janitor.d.ts +3 -2
  305. package/dist/workspace/computer-janitor.js +43 -9
  306. package/dist/workspace/computer-ledger.d.ts +3 -1
  307. package/dist/workspace/computer-ledger.js +7 -0
  308. package/dist/workspace/index.d.ts +3 -2
  309. package/dist/workspace/index.js +1 -0
  310. package/dist/workspace/resolve-computer.d.ts +42 -11
  311. package/dist/workspace/resolve-computer.js +65 -13
  312. package/dist/workspace/run-disk.d.ts +34 -0
  313. package/dist/workspace/run-disk.js +91 -0
  314. package/dist/workspace/run-tools.d.ts +4 -4
  315. package/dist/workspace/run-tools.js +8 -6
  316. package/dist/workspace/server-run-workspace.d.ts +3 -2
  317. package/dist/workspace/server-run-workspace.js +17 -4
  318. package/dist/workspace.js +1 -1
  319. package/package.json +10 -15
  320. package/templates/README.md +9 -6
  321. package/templates/code-review/agent.md +27 -11
  322. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  323. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  324. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  325. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  326. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  327. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  328. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  329. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  330. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  331. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  332. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  333. package/templates/code-review/evals/re-review/prompt.md +1 -1
  334. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  335. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  336. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  337. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  338. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  339. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  340. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  341. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  342. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  343. package/templates/code-review/findings.schema.json +131 -27
  344. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  345. package/templates/code-review/skills/review/DEEP.md +130 -0
  346. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  347. package/templates/code-review/skills/review/SKILL.md +104 -154
  348. package/dist/box/record.d.ts +0 -6
  349. package/dist/box/record.js +0 -41
  350. package/dist/box/sweep.d.ts +0 -53
  351. package/dist/box/sweep.js +0 -193
  352. package/dist/box-egress-vm.d.ts +0 -118
  353. package/dist/box-egress-vm.js +0 -354
  354. package/dist/box-egress.d.ts +0 -105
  355. package/dist/box-egress.js +0 -256
  356. package/dist/box-relay-vm.d.ts +0 -84
  357. package/dist/box-relay-vm.js +0 -437
  358. package/dist/box-relay.d.ts +0 -36
  359. package/dist/box-relay.js +0 -207
  360. package/dist/boxes.d.ts +0 -109
  361. package/dist/boxes.js +0 -249
  362. package/dist/budget.d.ts +0 -71
  363. package/dist/budget.js +0 -199
  364. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  365. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  366. package/dist/daytona-api.d.ts +0 -10
  367. package/dist/daytona-api.js +0 -20
  368. package/dist/egress-proxy.d.ts +0 -45
  369. package/dist/egress-proxy.js +0 -416
  370. package/dist/egress-table.d.ts +0 -24
  371. package/dist/egress-table.js +0 -165
  372. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -1,7 +1,8 @@
1
- import { releaseOlder, runLabels } from "@parcha/agentrun-computer";
1
+ import { isBrowserProvider, ownerFilter, releaseOlder, RUN_LABEL, runLabels } from "@parcha/agentrun-computer";
2
2
  import { computerOfPlace } from "../computer-setting.js";
3
3
  import { KEY_TABLE, providerOptions } from "../computer-keys.js";
4
4
  import { getSealedKey } from "../server-keys.js";
5
+ import { agentComputerOf, forgetAgentComputer, holdAgentComputer, keepAgentComputer, liveHolderOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
5
6
  import { computerHold, heldHands } from "./computer-hold.js";
6
7
  import { storeLedger } from "./computer-ledger.js";
7
8
  import { providerKeys, resolveComputer } from "./resolve-computer.js";
@@ -62,13 +63,19 @@ const labelValue = (value) => value.replace(/[^A-Za-z0-9_.:-]+/g, "_").slice(0,
62
63
  /** A provider failure as an error with the provider's words and code. */
63
64
  const failed = (error) => Object.assign(new Error(error.message), { code: error.code });
64
65
  /** A browser computer's provider as the run's browser tool opens its sessions through it (ClaimBrowser): nothing is made
65
- * at the claim. A session's computer is made at the tool's call, under the run's labels (`spec`'s) and the tool's tag;
66
- * its release lets go of every one the tool left open. */
67
- function claimBrowser(provider, spec) {
66
+ * at the claim. A session's computer is made at the tool's call, under the run's labels (`spec`'s) and the tool's tag,
67
+ * with the session's own options (spec.browser) where the provider declares them (capabilities().browser); its release
68
+ * lets go of every one the tool left open. The claim's browser (the agent's computer) and the tool plane's vendor's
69
+ * (browser-computer.ts planeBrowser) are each one of these. */
70
+ export function claimBrowser(provider, spec) {
68
71
  // A run's browser: the claim's spec always carries its lifetime (computerSpecOf); an agent's computer (owner) has none.
69
72
  const lifetime = spec.lifetimeMs;
70
73
  if (lifetime === undefined)
71
74
  throw new TypeError("a run's browser needs lifetimeMs: the claim's spec carries none");
75
+ // A provider of kind browser that declares no session features is opened as one that ends its sessions on a wall clock
76
+ // and takes no option but a viewport.
77
+ const features = provider.capabilities().browser ?? { timeout: "wall-clock" };
78
+ const kept = isBrowserProvider(provider) ? provider.downloads : undefined;
72
79
  const open = new Set();
73
80
  const release = async (id) => {
74
81
  const released = await provider.release({ id, name: id }, "delete");
@@ -76,13 +83,20 @@ function claimBrowser(provider, spec) {
76
83
  throw failed(released.error);
77
84
  open.delete(id);
78
85
  };
86
+ const valueOf = async (result) => {
87
+ const answered = await result;
88
+ if (!answered.ok)
89
+ throw failed(answered.error);
90
+ return answered.value;
91
+ };
79
92
  return {
80
93
  browser: {
81
94
  provider: provider.id,
82
95
  maxLifetimeS: Math.floor(lifetime / 1000),
83
- async open(tag, lifetimeS, signal) {
96
+ features: structuredClone(features),
97
+ async open(tag, lifetimeS, browser, signal) {
84
98
  const lifetimeMs = Math.min(lifetime, Math.max(1, Math.round(lifetimeS)) * 1000);
85
- const created = await provider.create({ ...spec, lifetimeMs, labels: { ...spec.labels, [SESSION_TAG]: labelValue(tag) } }, signal ? { signal } : {});
99
+ const created = await provider.create({ ...spec, lifetimeMs, labels: { ...spec.labels, [SESSION_TAG]: labelValue(tag) }, ...(browser ? { browser } : {}) }, signal ? { signal } : {});
86
100
  if (!created.ok)
87
101
  throw failed(created.error);
88
102
  open.add(created.value.id);
@@ -94,8 +108,24 @@ function claimBrowser(provider, spec) {
94
108
  throw failed(listed.error);
95
109
  return listed.value.map((one) => one.ref.id);
96
110
  },
111
+ async running(id, signal) {
112
+ const found = await provider.attach({ id }, signal ? { signal } : {});
113
+ if (found.ok)
114
+ return true;
115
+ if (found.error.code === "not_found" || found.error.code === "gone")
116
+ return false;
117
+ throw failed(found.error);
118
+ },
97
119
  url: (id) => cdpUrlOf(provider, { id, name: id }),
98
120
  close: release,
121
+ ...(kept && features.downloads
122
+ ? {
123
+ downloads: {
124
+ list: (id) => valueOf(kept.list({ id, name: id })),
125
+ read: (id, name, maxBytes) => valueOf(kept.read({ id, name: id }, name, maxBytes)),
126
+ },
127
+ }
128
+ : {}),
99
129
  },
100
130
  async release() {
101
131
  for (const id of [...open])
@@ -130,6 +160,7 @@ async function providerLaunch(provider, claim, spec, signal) {
130
160
  groups: hello.groups,
131
161
  // What the machine says it is (a phone's android or ios): its live view's input platform.
132
162
  machine: hello.kind,
163
+ hello,
133
164
  client,
134
165
  async readBack() {
135
166
  const attached = await provider.attach({ id: ref.id });
@@ -145,9 +176,150 @@ async function providerLaunch(provider, claim, spec, signal) {
145
176
  },
146
177
  };
147
178
  }
179
+ /** A run state in which the run still holds what it claimed. */
180
+ const LIVE_RUN = new Set(["queued", "running", "parked"]);
181
+ /**
182
+ * The agent's own computer for this claim (a persistent setting): the one its owner's listing finds, attached under this
183
+ * claim, else one made with `spec` (its owner, no lifetime). The record this server keeps names it, held by this run. A
184
+ * computer whose listing names another run that is still going is refused in words naming that run; one a run that ended
185
+ * left running is taken over. Its release detaches it (Orgo's suspend, say), keeping its state for the agent's next run;
186
+ * then the agent's record is reconciled, so an agent that was archived or turned persistent off while the run went has
187
+ * its computer deleted.
188
+ */
189
+ async function ownedLaunch(provider, claim, spec, context, signal) {
190
+ const { store, agentId } = context;
191
+ // One run at a time, taken in the store before anything is listed or made (agent-computer.ts holdAgentComputer): two
192
+ // runs of the agent that claim at once never both make a computer. With no run rows to read, a holder is still going.
193
+ // The hold is this claim's (its epoch): a later claim of the run takes it over, and this one's end then does nothing.
194
+ const hold = await holdAgentComputer(store, agentId, claim.runId, liveHolderOf(store), { epoch: claim.epoch });
195
+ let launched;
196
+ try {
197
+ launched = await ownedStart(provider, claim, spec, context, hold, signal);
198
+ }
199
+ catch (error) {
200
+ await hold.letGo().catch(() => undefined);
201
+ throw error;
202
+ }
203
+ return {
204
+ ...launched,
205
+ async release() {
206
+ try {
207
+ await launched.release();
208
+ }
209
+ finally {
210
+ await hold.letGo();
211
+ }
212
+ },
213
+ };
214
+ }
215
+ /** The owned launch once the run holds the agent's computer (ownedLaunch): found and attached, or made; connected. */
216
+ async function ownedStart(provider, claim, spec, context, hold, signal) {
217
+ const call = signal ? { signal } : {};
218
+ const { store, agentId, note } = context;
219
+ const older = await releaseOlder(provider, claim.runId, claim.epoch, call);
220
+ if (!older.ok)
221
+ throw new Error(older.error.message);
222
+ const listed = await provider.list(ownerFilter(context.owner), call);
223
+ if (!listed.ok)
224
+ throw new Error(listed.error.message);
225
+ const record = await agentComputerOf(store, agentId);
226
+ const found = listed.value.find((info) => info.ref.id === record?.id) ?? listed.value[0];
227
+ let ref;
228
+ /** Whether this claim made the computer, or attached the one the agent had. */
229
+ let made;
230
+ if (found) {
231
+ const holder = found.labels[RUN_LABEL];
232
+ if (found.state === "running" && holder !== undefined && holder !== claim.runId) {
233
+ const row = store.runs ? await store.runs.get(holder) : undefined;
234
+ // With no run rows to read, a holder is taken as still going: never two runs on one agent's computer.
235
+ if (!store.runs || (row !== undefined && LIVE_RUN.has(row.state))) {
236
+ throw new Error(`this agent's computer ${found.ref.name} is held by run ${holder}, which is still ${row?.state ?? "going"}: an agent's own computer serves one run at a time. Start this run again once that one ends`);
237
+ }
238
+ }
239
+ const attached = await provider.attach({ id: found.ref.id }, { claim: { run: claim.runId, epoch: claim.epoch }, ...call });
240
+ if (!attached.ok)
241
+ throw new Error(attached.error.message);
242
+ ref = { id: found.ref.id, name: found.ref.name };
243
+ made = false;
244
+ note(`Attached this agent's computer ${ref.name}, kept from its last run.`);
245
+ }
246
+ else {
247
+ const created = await provider.create(spec, call);
248
+ if (!created.ok)
249
+ throw new Error(created.error.message);
250
+ ref = { id: created.value.id, name: created.value.name };
251
+ made = true;
252
+ note(record
253
+ ? `This agent's computer ${record.name} is gone (deleted outside this server): made a new one, ${ref.name}, which later runs get back.`
254
+ : `Made this agent's own computer ${ref.name}: later runs get it back.`);
255
+ }
256
+ // The computer is acquired: its cleanup is in place before anything else is awaited, and whatever fails from here (the
257
+ // hold lost to a later claim included) lets go of exactly what this claim acquired.
258
+ const computer = { provider: context.provider, image: context.image, ...ref };
259
+ // The hold is marked letting go first, so no claim takes it over while the computer is detached. A claim that took it
260
+ // over since (a later claim of this run, resumed, or another run once this one's row ended) has the computer now: it
261
+ // is left as it is.
262
+ const detach = async () => {
263
+ if (!(await hold.releasing()))
264
+ return;
265
+ const released = await provider.release(ref, "detach");
266
+ if (!released.ok)
267
+ throw new Error(released.error.message);
268
+ await keepAgentComputer(store, agentId, computer, "detached");
269
+ await reconcileAgentComputer(store, agentId, async () => provider, hold);
270
+ };
271
+ // A launch that fails: a computer this claim made is deleted under its claim, so one a later claim has taken since (a
272
+ // resume whose owner's listing found it) is left to that claim, and the record goes where it names it; one it attached
273
+ // is detached as at the run's end, where the hold is still this claim's. Throws `error`, with what was let go.
274
+ const abandon = async (error) => {
275
+ const words = error instanceof Error ? error.message : String(error);
276
+ if (!made) {
277
+ const undone = await detach().then(() => undefined, (failed) => (failed instanceof Error ? failed.message : String(failed)));
278
+ throw new Error(undone === undefined ? words : `${words}; and ${ref.name} could not be detached: ${undone}`);
279
+ }
280
+ const deleted = await provider.release(ref, "delete", { claim: { run: claim.runId, epoch: claim.epoch } });
281
+ if (deleted.ok)
282
+ await forgetAgentComputer(store, agentId, ref.id).catch(() => undefined);
283
+ throw new Error(`${words}; ${ref.name}, which this claim made, ${deleted.ok ? "was deleted" : `was not deleted (${deleted.error.message})`}`);
284
+ };
285
+ let connected;
286
+ try {
287
+ // A later claim of this run (or another run, this one's row ended) that took the hold over while this one attached
288
+ // or made the computer has it now: its record is that claim's to write.
289
+ if (!(await hold.holds()))
290
+ throw new Error(`fenced: this agent's computer ${ref.name} was taken over by a later claim while run ${claim.runId}'s claim at epoch ${claim.epoch} ${made ? "made" : "attached"} it; it is left to that claim`);
291
+ await keepAgentComputer(store, agentId, computer, "held", { run: claim.runId });
292
+ const opened = await provider.connect(ref);
293
+ if (!opened.ok)
294
+ throw new Error(opened.error.message);
295
+ connected = opened.value;
296
+ }
297
+ catch (error) {
298
+ return abandon(error);
299
+ }
300
+ const { client, hello } = connected;
301
+ return {
302
+ id: ref.id,
303
+ groups: hello.groups,
304
+ machine: hello.kind,
305
+ hello,
306
+ client,
307
+ // An agent's own computer mounts no run's folder (resolve-computer.ts refuses one that would).
308
+ async readBack() {
309
+ return { ok: false, error: { code: "not_found", message: "an agent's own computer mounts no run's folder" } };
310
+ },
311
+ ...(watching(provider) ? { watch: (signal) => watching(provider).watch(ref, { signal }) } : {}),
312
+ async release() {
313
+ await connected.close().catch(() => undefined);
314
+ await detach();
315
+ },
316
+ };
317
+ }
148
318
  /** The run's computer for this claim, started and registered; `{ computer: undefined }` for none. Throws with code
149
319
  * computer_unavailable and the server's words when the agent's computer cannot be had here. */
150
- export async function computerForClaim(launch, store, deps) {
320
+ export async function computerForClaim(launch,
321
+ // `settings` and `runs`: the agent's own computer's record and its holder's run row, for a persistent setting alone.
322
+ store, deps) {
151
323
  const table = deps.keyTable ?? KEY_TABLE;
152
324
  /** The computer this claim started (one per claim): its ref id tags its live view, and its watch feeds it. */
153
325
  let made;
@@ -157,7 +329,10 @@ export async function computerForClaim(launch, store, deps) {
157
329
  keysOf: providerKeys(deps.kinds, deps.keyOf ?? (async (name) => (deps.sealKey ? await getSealedKey(store, deps.sealKey, name) : undefined))),
158
330
  answers: deps.answers ?? (async () => false),
159
331
  ...(deps.daemon ? { daemon: deps.daemon } : {}),
160
- async launch(entry, { kind, keys, configuration, mount, gpu, signal }) {
332
+ async launch(entry, { kind, keys, configuration, mount, gpu, persistent, signal }) {
333
+ // An agent's own computer needs its agent and the store's record of it; the server's launch (--faux) keeps none.
334
+ if (persistent && (deps.launch || launch.agentId === undefined || store.settings === undefined))
335
+ throw new Error("this run can't keep its agent's own computer here: start it again with persistent off");
161
336
  if (deps.launch) {
162
337
  const own = await deps.launch(entry, { kind, keys, configuration, ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}), ...(signal ? { signal } : {}) });
163
338
  const ownWatch = own.watch;
@@ -201,9 +376,27 @@ export async function computerForClaim(launch, store, deps) {
201
376
  madeBy = entry;
202
377
  return { id: entry.id, groups: ["cdp"], browser: opened.browser, release: opened.release };
203
378
  }
204
- const launched = await providerLaunch(provider, launch, spec, signal);
379
+ let launched;
380
+ if (persistent) {
381
+ // The agent's own: its owner (this server and the agent), and no run deadline (it outlives the run).
382
+ const owner = { agent: launch.agentId, server: await serverIdOf({ settings: store.settings }) };
383
+ const { lifetimeMs: _, ...owned } = spec;
384
+ launched = await ownedLaunch(provider, launch, { ...owned, owner }, {
385
+ store: { settings: store.settings, agents: store.agents, ...(store.runs ? { runs: store.runs } : {}) },
386
+ agentId: launch.agentId,
387
+ owner,
388
+ provider: entry.id,
389
+ image: configuration.image,
390
+ note: deps.onComputerNote ?? (() => { }),
391
+ }, signal);
392
+ }
393
+ else {
394
+ launched = await providerLaunch(provider, launch, spec, signal);
395
+ }
205
396
  made = { id: launched.id, machine: launched.machine, ...(launched.watch ? { watch: launched.watch } : {}) };
206
397
  madeBy = entry;
398
+ const { os, osVersion, arch } = launched.hello;
399
+ deps.onConnected?.({ provider: entry.label, kind: kind, hello: { os, ...(osVersion ? { osVersion } : {}), arch } });
207
400
  return launched;
208
401
  },
209
402
  };
@@ -215,6 +408,10 @@ export async function computerForClaim(launch, store, deps) {
215
408
  const refusedKind = deps.refuseKind?.(resolved.kind);
216
409
  if (refusedKind)
217
410
  throw unavailable(refusedKind);
411
+ // The program its provider runs on this machine (the phone's adb) is checked before anything is rented.
412
+ const hostRefusal = resolved.provider ? deps.hostWhy?.(resolved.provider) : undefined;
413
+ if (hostRefusal)
414
+ throw unavailable(`This agent's computer is a ${resolved.kind} on ${resolved.provider}, and this runner cannot run it: ${hostRefusal.replace(/[.!?]+$/, "")}.`);
218
415
  // The run's mount credential (Mode 2), minted when the mount was made: removed with the computer, or at once when the
219
416
  // start fails after it was minted.
220
417
  const revoke = async () => { await deps.revokeMount?.(); };
@@ -232,6 +429,7 @@ export async function computerForClaim(launch, store, deps) {
232
429
  // vendor's URL reaches a person), opened under this claim. A fenced open is a lost claim. The release ends the hold.
233
430
  let endHold = () => { };
234
431
  let hold;
432
+ let held;
235
433
  let view;
236
434
  if (computer && (computer.kind === "desktop" || computer.kind === "phone")) {
237
435
  const theHold = computerHold();
@@ -252,11 +450,13 @@ export async function computerForClaim(launch, store, deps) {
252
450
  // goes; the composer's `ended` ViewEnd maps onto it), the agent's open ask is let go at once, and nothing is taken after.
253
451
  endHold = () => theHold.close();
254
452
  hold = (ports) => heldHands(ports, theHold);
453
+ held = { kind: computer.kind, hold: theHold };
255
454
  }
256
455
  let released;
257
456
  return {
258
457
  ...(computer ? { computer } : {}),
259
458
  ...(hold ? { hold } : {}),
459
+ ...(held ? { held } : {}),
260
460
  release: (why = "released") => (released ??= (async () => {
261
461
  await Promise.resolve(view?.close(why)).catch(() => undefined);
262
462
  endHold();
@@ -10,8 +10,9 @@ export declare const JANITOR_CLOSE_MS = 5000;
10
10
  * is swept, so a stuck vendor (a Docker command has no timeout of its own) never stops the others or later sweeps. */
11
11
  export declare const JANITOR_PROVIDER_MS: number;
12
12
  export interface JanitorDeps {
13
- /** The store: whose runs a computer's run label names, and the phone provider's ledger. */
14
- readonly store: Pick<Store, "runs" | "computerLedger">;
13
+ /** The store: whose runs a computer's run label names, and the phone provider's ledger; with `settings` and `agents`,
14
+ * this server's id and its agents, whose own computers it then sweeps by their owner. */
15
+ readonly store: Pick<Store, "runs" | "computerLedger"> & Partial<Pick<Store, "settings" | "agents">>;
15
16
  /** The run's computers as the runner composed them (computer-deps.ts computerDepsFrom): the registry, the provider
16
17
  * makers and the key reader. */
17
18
  readonly computers: Pick<ComputerDeps, "kinds" | "providers" | "keyOf"> & {
@@ -18,9 +18,14 @@
18
18
  // start asks for it (the CLI's runner and the runner subcommand), never under --faux, and never two sweeps at once. Its
19
19
  // close cuts a sweep under way and waits for it on a bound of its own (JANITOR_CLOSE_MS), so a stuck vendor call never
20
20
  // holds up the runner's stop.
21
- import { epochOf, ok, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
21
+ //
22
+ // An agent's own computer (a persistent setting, agent-computer.ts) is this server's when its owner names this server's
23
+ // id, never by its run: it goes only when its agent no longer wants it (ownerGoneOf: gone, archived, or no longer
24
+ // persistent on that provider), never by a deadline. Without the store's settings and agents, none is this server's.
25
+ import { epochOf, ok, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
22
26
  import { KEY_TABLE, providerOptions } from "../computer-keys.js";
23
27
  import { FAUX_ENV } from "../model.js";
28
+ import { deleteUnderHold, ownerGoneOf, serverIdOf, wantsOn } from "./agent-computer.js";
24
29
  import { storeLedger } from "./computer-ledger.js";
25
30
  import { providerKeys } from "./resolve-computer.js";
26
31
  /** How often the janitor sweeps after its first sweep at the runner's start. */
@@ -35,8 +40,15 @@ const runsByHash = (store) => {
35
40
  return () => (read ??= store.runs.list({}).then((rows) => new Map(rows.map((row) => [runHash(row.id), row.id]))));
36
41
  };
37
42
  /** Whether a listed computer is this server's and no claim holds it: its run (by its label, or its hash's) is in this
38
- * store, and no claim holds the run now (by the store's clock), or one holds it at a later epoch than the computer's. */
39
- async function sweepable(store, labels, byHash) {
43
+ * store, and no claim holds the run now (by the store's clock), or one holds it at a later epoch than the computer's.
44
+ * An agent's own computer (owned, or an owner label, readable or not) is this server's when its owner names
45
+ * `serverId`, whatever its run: the sweep's ownerGone then decides. */
46
+ async function sweepable(store, info, byHash, serverId) {
47
+ const { labels } = info;
48
+ const label = ownerOf(labels);
49
+ const owner = info.owner ?? (label.ok ? label.value : undefined);
50
+ if (info.owned === true || owner !== undefined || !label.ok)
51
+ return serverId !== undefined && owner?.server === serverId;
40
52
  const named = labels[RUN_LABEL];
41
53
  const hash = labels[RUN_HASH_LABEL];
42
54
  const runId = typeof named === "string" && named !== "" ? named : typeof hash === "string" && hash !== "" ? (await byHash()).get(hash) : undefined;
@@ -55,7 +67,11 @@ async function sweepable(store, labels, byHash) {
55
67
  }
56
68
  /** `provider` as the sweep sees it: its list cut to this server's computers that no claim holds, and no leftovers pass.
57
69
  * Each call goes to the provider itself, so its own state is used as it is. */
58
- function thisServers(provider, store, byHash) {
70
+ function thisServers(provider, store, byHash, serverId) {
71
+ // The agents' own computers the list kept, by id: their delete goes under the agent's hold (deleteUnderHold), which
72
+ // also clears the agent's record of it, so its view no longer shows it deleting.
73
+ const ownedBy = new Map();
74
+ const { settings, agents } = store;
59
75
  return {
60
76
  id: provider.id,
61
77
  version: provider.version,
@@ -65,15 +81,29 @@ function thisServers(provider, store, byHash) {
65
81
  attach: (target, context) => provider.attach(target, context),
66
82
  network: (ref, policy, context) => provider.network(ref, policy, context),
67
83
  connect: (ref) => provider.connect(ref),
68
- release: (ref, how) => provider.release(ref, how),
84
+ release(ref, how, context) {
85
+ const agent = ownedBy.get(ref.id);
86
+ if (how !== "delete" || agent === undefined || settings === undefined)
87
+ return provider.release(ref, how, context);
88
+ // Asked again under the hold: the agent may want it back since ownerGone was read (this server's owners carry no
89
+ // idle TTL, so that is the one reason the sweep deletes one).
90
+ const due = async () => !agents || !(await wantsOn({ agents }, agent, provider.id));
91
+ return deleteUnderHold({ settings, runs: store.runs }, agent, ref.id, due, () => provider.release(ref, how, context));
92
+ },
69
93
  async list(labels, context) {
70
94
  const listed = await provider.list(labels, context);
71
95
  if (!listed.ok)
72
96
  return listed;
73
97
  const kept = [];
74
- for (const info of listed.value)
75
- if (await sweepable(store, info.labels, byHash))
76
- kept.push(info);
98
+ for (const info of listed.value) {
99
+ if (!(await sweepable(store, info, byHash, serverId)))
100
+ continue;
101
+ const label = ownerOf(info.labels);
102
+ const owner = info.owner ?? (label.ok ? label.value : undefined);
103
+ if (owner !== undefined)
104
+ ownedBy.set(info.ref.id, owner.agent);
105
+ kept.push(info);
106
+ }
77
107
  return ok(kept);
78
108
  },
79
109
  };
@@ -103,6 +133,9 @@ export async function sweepServerComputers(deps, signal) {
103
133
  const at = (deps.now ?? Date.now)();
104
134
  const keysOf = providerKeys(computers.kinds, computers.keyOf ?? (async () => undefined));
105
135
  const byHash = runsByHash(store);
136
+ // This server's id and its agents: its agents' own computers are swept by their owner (ownerGoneOf).
137
+ const { settings, agents } = store;
138
+ const serverId = settings && agents ? await serverIdOf({ settings }) : undefined;
106
139
  const out = [];
107
140
  for (const entry of computers.kinds.PROVIDERS) {
108
141
  if (signal?.aborted)
@@ -120,7 +153,8 @@ export async function sweepServerComputers(deps, signal) {
120
153
  // A vendor that ends its own computers needs no janitor.
121
154
  if (provider.capabilities().lifetime !== "janitor")
122
155
  continue;
123
- out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash), { now: new Date(at), signal: cut })) });
156
+ const ownerGone = serverId !== undefined && settings && agents ? ownerGoneOf({ agents, settings, runs: store.runs }, serverId, entry.id) : undefined;
157
+ out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash, serverId), { now: new Date(at), signal: cut, ...(ownerGone ? { ownerGone } : {}) })) });
124
158
  }
125
159
  catch (error) {
126
160
  out.push({ provider: entry.id, swept: { ok: false, error: { code: "refused", message: error instanceof Error ? error.message : String(error) } } });
@@ -4,12 +4,14 @@ export interface LedgerEntry {
4
4
  id: string;
5
5
  labels: Record<string, string>;
6
6
  }
7
- /** One provider's ledger, in the shape a descriptor's `ledger` option takes: put, get, list and remove of its entries. */
7
+ /** One provider's ledger, in the shape a descriptor's `ledger` option takes: put, get, list, remove and swap of its entries. */
8
8
  export interface ProviderLedger<E extends LedgerEntry = LedgerEntry> {
9
9
  put(entry: E): Promise<void>;
10
10
  get(id: string): Promise<E | undefined>;
11
11
  list(): Promise<E[]>;
12
12
  remove(id: string): Promise<void>;
13
+ /** entry put in place of `was` only while the kept entry is still `was` as read, in one statement: whether it was put. */
14
+ swap(was: E, entry: E): Promise<boolean>;
13
15
  }
14
16
  /** `provider`'s ledger over the store's computer ledger. */
15
17
  export declare function storeLedger<E extends LedgerEntry = LedgerEntry>(ledger: ComputerLedger, provider: string): ProviderLedger<E>;
@@ -12,5 +12,12 @@ export function storeLedger(ledger, provider) {
12
12
  },
13
13
  list: async () => (await ledger.list(provider)).map((row) => entryOf(row)),
14
14
  remove: (id) => ledger.remove(provider, id),
15
+ swap: async (was, entry) => {
16
+ const { id: _wasId, labels: wasLabels, ...wasDetail } = was;
17
+ const { id, labels, ...detail } = entry;
18
+ if (was.id !== id)
19
+ return false;
20
+ return ledger.swap(provider, id, { labels: wasLabels, detail: wasDetail }, labels, detail);
21
+ },
15
22
  };
16
23
  }
@@ -15,10 +15,11 @@ export { type LearningPlace, type LearningWorkspace, learningWorkspace, type Lea
15
15
  export { ARCHIL_MAX_EXEC_S, handsOf, MAX_EXEC_S, processesOf, shellEnv } from "./hands.js";
16
16
  export { type RunComputer, type RunHold, runTools, type RunTools, withKindTools } from "./run-tools.js";
17
17
  export { inputOf, phoneOf, screenOf } from "./computer-ports.js";
18
- export { type ClaimSide, computerReadiness, type ComputerSetting, type KindRegistry, type LaunchedComputer, type Port, resolveComputer, type ResolvedComputer, runShellOf, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
18
+ export { type ClaimSide, computerReadiness, type ComputerSetting, type KindRegistry, type LaunchedComputer, type Port, resolveComputer, type ResolvedComputer, runShellOf, type ShellPlace, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
19
19
  export { computerProviderFactories, computerProviderMakers, type ProviderLoad } from "./computer-providers.js";
20
20
  export { claimComputer, claimKinds, type ComputerDeps, computerDepsFrom, type ComputerDepsOptions, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, type DockerComputerOptions, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
21
- export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ImageWait, type OpenComputerView, type ProviderMakers, type ViewEnd } from "./computer-for-claim.js";
21
+ export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ComputerSaid, type ImageWait, type OpenComputerView, type ProviderMakers, type ViewEnd } from "./computer-for-claim.js";
22
22
  export { JANITOR_EVERY_MS, type JanitorDeps, type ProviderSweep, startJanitor, sweepServerComputers } from "./computer-janitor.js";
23
+ export { agentComputerOf, agentComputerView, ownerGoneOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
23
24
  export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
24
25
  export { KIND_SKILLS, type KindSkill, kindSkillOf, type SkillKind } from "./kind-skills.js";
@@ -21,5 +21,6 @@ export { computerProviderFactories, computerProviderMakers } from "./computer-pr
21
21
  export { claimComputer, claimKinds, computerDepsFrom, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
22
22
  export { computerForClaim } from "./computer-for-claim.js";
23
23
  export { JANITOR_EVERY_MS, startJanitor, sweepServerComputers } from "./computer-janitor.js";
24
+ export { agentComputerOf, agentComputerView, ownerGoneOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
24
25
  export { layOwnSkills, RUN_SKILLS_DIR } from "./revision-skills.js";
25
26
  export { KIND_SKILLS, kindSkillOf } from "./kind-skills.js";
@@ -1,5 +1,5 @@
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";
1
+ import { type ShellPlace } from "@parcha/agentrun-kernel/kernel";
2
+ import { type BrowserFeatures, type BrowserFile, type BrowserSpec, type ComputerClient, type ComputerSettingKind, type GpuSpec, type Group, type HelloResult, type KindCapabilities, type MountReadBack, type MountSpec, type ProviderEntry, type Result } from "@parcha/agentrun-computer";
3
3
  import { type DockerDaemon } from "../docker-daemon.js";
4
4
  import type { MountCheck } from "./attach.js";
5
5
  import type { RunComputer } from "./run-tools.js";
@@ -8,12 +8,13 @@ import type { Workspace } from "./workspace.js";
8
8
  * provider of the kind registry: the computer module's own types. Where a run's shell is: the kernel registry's. */
9
9
  export type { ComputerSettingKind, KindCapabilities, ProviderEntry, ShellPlace };
10
10
  /** An agent's computer setting. `image`: the one of the provider's configurations it selects; absent, the default. A
11
- * sandbox's may ask for GPUs. */
11
+ * sandbox's may ask for GPUs. `persistent`: the agent keeps its own computer between runs (agent-computer.ts). */
12
12
  export type ComputerSetting = {
13
13
  readonly kind: string;
14
14
  readonly provider?: string | null;
15
15
  readonly image?: string;
16
16
  readonly gpu?: GpuSpec;
17
+ readonly persistent?: boolean;
17
18
  };
18
19
  /** The computer module's kind registry (src/kinds.ts), by its own names: the setting kinds, why a machine does not serve
19
20
  * one (servingRefusals, whose words a refusal here carries), and the providers. */
@@ -23,13 +24,15 @@ export type KindRegistry = {
23
24
  readonly PROVIDERS: readonly ProviderEntry[];
24
25
  };
25
26
  /** A computer a provider started for the run: its ref, its computerd client and what it offers (sandbox, desktop,
26
- * phone), the read-back of its mount (when mounted), and its release. A browser is started by none: the claim gives
27
- * the run's browser tool its provider (`browser`), which opens each session at the tool's first call, and the release
28
- * lets go of any the tool left open. */
27
+ * phone), the hello it answered when the claim connected it (a desktop's or a phone's ports read its groups), the
28
+ * read-back of its mount (when mounted), and its release. A browser is started by none: the claim gives the run's
29
+ * browser tool its provider (`browser`), which opens each session at the tool's first call, and the release lets go
30
+ * of any the tool left open. */
29
31
  export type LaunchedComputer = {
30
32
  readonly id: string;
31
33
  readonly groups: readonly (Group | string)[];
32
34
  readonly client?: ComputerClient;
35
+ readonly hello?: HelloResult;
33
36
  readBack?(): Promise<Result<MountReadBack>>;
34
37
  readonly browser?: ClaimBrowser;
35
38
  release(): Promise<void>;
@@ -44,14 +47,24 @@ export type ClaimBrowser = {
44
47
  readonly provider: string;
45
48
  /** The longest a session lives, in seconds. */
46
49
  readonly maxLifetimeS: number;
47
- /** Makes a session for `tag`, to live at most `lifetimeS`: its computer's id. */
48
- open(tag: string, lifetimeS: number, signal?: AbortSignal): Promise<string>;
50
+ /** What its sessions offer beyond the protocol (the provider's capabilities().browser), which `open` may ask for. */
51
+ readonly features: BrowserFeatures;
52
+ /** Makes a session for `tag`, to live at most `lifetimeS`, with its own options (spec.browser): its computer's id. */
53
+ open(tag: string, lifetimeS: number, browser?: BrowserSpec, signal?: AbortSignal): Promise<string>;
49
54
  /** The sessions made for `tag`, by id. */
50
55
  find(tag: string, signal?: AbortSignal): Promise<string[]>;
56
+ /** Whether the session runs: false once it has ended or its provider no longer knows it. */
57
+ running(id: string, signal?: AbortSignal): Promise<boolean>;
51
58
  /** The session's CDP URL now. */
52
59
  url(id: string): Promise<string>;
53
60
  /** Ends the session; one already gone is ended. */
54
61
  close(id: string): Promise<void>;
62
+ /** The files a session downloaded, kept by the provider: where its features declare downloads. */
63
+ readonly downloads?: {
64
+ list(id: string): Promise<BrowserFile[]>;
65
+ /** The file's bytes, streamed; the stream fails in words once it passes maxBytes. */
66
+ read(id: string, name: string, maxBytes: number): Promise<AsyncIterable<Uint8Array>>;
67
+ };
55
68
  };
56
69
  /** The claim's side: the keys saved for a provider (Settings → Computers; values, never shown), and the launch of one
57
70
  * computer of the kind, with the run's folder as its mount when it mounts it. A launch that fails throws its words. */
@@ -63,13 +76,15 @@ export type ClaimSide = {
63
76
  * the one wording a run's start and Settings → Computers say (noDockerWords). Absent: the launch's own words. */
64
77
  daemon?(provider: string): Promise<DockerDaemon>;
65
78
  /** `configuration`: the provider's configuration the setting selected; its options go to the provider with the keys,
66
- * and its image, when it names one, is the computer's. `gpu`: a sandbox's GPUs, held to that configuration. */
79
+ * and its image, when it names one, is the computer's. `gpu`: a sandbox's GPUs, held to that configuration.
80
+ * `persistent`: the agent's own computer, which that configuration keeps (and which mounts no run's folder). */
67
81
  launch(entry: ProviderEntry, spec: {
68
82
  readonly kind: ComputerSettingKind;
69
83
  readonly keys: Readonly<Record<string, string>>;
70
84
  readonly configuration: KindCapabilities;
71
85
  readonly mount?: MountSpec;
72
86
  readonly gpu?: GpuSpec;
87
+ readonly persistent?: true;
73
88
  readonly signal?: AbortSignal;
74
89
  }): Promise<LaunchedComputer>;
75
90
  };
@@ -99,8 +114,11 @@ export declare const noNetworkRefusal: (label: string, kind: string) => string;
99
114
  * claim launches it, and asks only once its launch fails (ClaimSide.daemon). Absent: not asked.
100
115
  *
101
116
  * `boxAllow`: this server's allow setting (box-settings.ts boxAllowOf). Under "none", a computer whose provider makes no
102
- * "none" is refused (noNetworkRefusal), as the claim refuses it. Absent: not asked. */
103
- 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<{
117
+ * "none" is refused (noNetworkRefusal), as the claim refuses it. Absent: not asked.
118
+ *
119
+ * `hostWhy`: why this machine cannot run a provider's computers, in words that say how to fix it (computers.ts
120
+ * hostCommandRefusals, read at the server's start: the phone's adb not on PATH), or undefined. Absent: not asked. */
121
+ 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", hostWhy?: (provider: string) => string | undefined): Promise<{
104
122
  readonly ok: true;
105
123
  } | {
106
124
  readonly refused: string;
@@ -144,6 +162,19 @@ export declare function shellPlaceOf(mounts: boolean, mode: 1 | 2): ShellPlace;
144
162
  * runs nothing: "none". The setting is the agent's as saved; where it has none, the caller gives the server's default.
145
163
  */
146
164
  export declare function runShellOf(setting: ComputerSetting, mode: 1 | 2, registry: Pick<KindRegistry, "SETTING_KINDS" | "servingRefusals" | "PROVIDERS">): ShellPlace;
165
+ /** What a choice of computer leaves out of the shell, in plain words: shown beside it (GET /v2/computers shell_note) and
166
+ * said by the save's refusal of a tool it leaves out. A computer that mounts the folder leaves nothing out. */
167
+ export declare const SHELL_NOTES: Readonly<Record<Exclude<ShellPlace, "computer">, string>>;
168
+ /** The host tools a run with its shell at `shell` gets, by name: the kernel registry's own list (hostToolDefs), never a
169
+ * second one: the file tools always, bash with a shell, the five background tools on a computer. */
170
+ export declare const hostToolsOf: (shell: ShellPlace) => string[];
171
+ /** A computer choice as an agent's settings show it: where its runs have their shell (runShellOf), the host tools that
172
+ * gives, and what it leaves out, in words (none for a computer that mounts the folder). */
173
+ export declare function shellChoiceOf(setting: ComputerSetting, mode: 1 | 2, registry: Pick<KindRegistry, "SETTING_KINDS" | "servingRefusals" | "PROVIDERS">): {
174
+ shell: ShellPlace;
175
+ host_tools: string[];
176
+ shell_note?: string;
177
+ };
147
178
  /** The setting resolved for `mode` (none given: the server's default), or a refusal in words that name the setting. A
148
179
  * workflow runs with no computer: its caller gives kind none. */
149
180
  export declare function resolveComputer(given: ComputerSetting | undefined, mode: 1 | 2, registry: KindRegistry, side: ClaimSide): Promise<ResolvedComputer | {