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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/CHANGELOG.md +376 -0
  2. package/README.md +393 -118
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/api-only.d.ts +2 -4
  11. package/dist/api-only.js +2 -4
  12. package/dist/attach-conformance.js +5 -4
  13. package/dist/box-paths.d.ts +7 -5
  14. package/dist/box-paths.js +12 -8
  15. package/dist/browser-computer.d.ts +3 -8
  16. package/dist/browser-computer.js +12 -35
  17. package/dist/browser-cost.js +94 -20
  18. package/dist/capacity.d.ts +1 -1
  19. package/dist/capacity.js +3 -3
  20. package/dist/chatgpt-plan.d.ts +5 -0
  21. package/dist/chatgpt-plan.js +25 -11
  22. package/dist/claude-login-token.d.ts +121 -0
  23. package/dist/claude-login-token.js +797 -0
  24. package/dist/claude-login.d.ts +119 -34
  25. package/dist/claude-login.js +551 -79
  26. package/dist/claude-sign-in.d.ts +3 -0
  27. package/dist/claude-sign-in.js +10 -1
  28. package/dist/cli.js +325 -328
  29. package/dist/composio-made.d.ts +1 -6
  30. package/dist/composio-made.js +1 -6
  31. package/dist/composio-owners.d.ts +26 -0
  32. package/dist/composio-owners.js +36 -0
  33. package/dist/composio-preset.d.ts +56 -23
  34. package/dist/composio-preset.js +173 -77
  35. package/dist/composio-triggers.d.ts +4 -4
  36. package/dist/composio-triggers.js +6 -7
  37. package/dist/compute-cost.js +11 -2
  38. package/dist/computer-attach.d.ts +40 -19
  39. package/dist/computer-attach.js +326 -62
  40. package/dist/computer-held-routes.d.ts +1 -1
  41. package/dist/computer-held-routes.js +9 -4
  42. package/dist/computer-keys.d.ts +11 -1
  43. package/dist/computer-keys.js +26 -1
  44. package/dist/computer-record.js +3 -1
  45. package/dist/computer-view.d.ts +5 -3
  46. package/dist/computer-view.js +10 -6
  47. package/dist/computer-viewer.js +36 -7
  48. package/dist/computers.d.ts +12 -11
  49. package/dist/computers.js +11 -8
  50. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  51. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  52. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  53. package/dist/console/assets/share-L84tlUDW.js +6 -0
  54. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  55. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  56. package/dist/console/index.html +4 -3
  57. package/dist/console/share.html +17 -0
  58. package/dist/decisions.d.ts +17 -7
  59. package/dist/decisions.js +41 -15
  60. package/dist/dial-relay.d.ts +25 -4
  61. package/dist/dial-relay.js +139 -5
  62. package/dist/docker-daemon.js +4 -5
  63. package/dist/docker-host-addresses.js +29 -11
  64. package/dist/email/account.d.ts +6 -0
  65. package/dist/email/account.js +6 -0
  66. package/dist/email/authentication.d.ts +21 -0
  67. package/dist/email/authentication.js +106 -0
  68. package/dist/email/email-faux.d.ts +11 -2
  69. package/dist/email/email-faux.js +21 -5
  70. package/dist/email/mail.d.ts +25 -0
  71. package/dist/email/mail.js +58 -2
  72. package/dist/email/names.js +2 -2
  73. package/dist/email/tools.d.ts +9 -4
  74. package/dist/email/tools.js +95 -13
  75. package/dist/env-switch.d.ts +13 -5
  76. package/dist/env-switch.js +24 -6
  77. package/dist/errors.d.ts +1 -0
  78. package/dist/errors.js +2 -0
  79. package/dist/fal-price.d.ts +12 -4
  80. package/dist/fal-price.js +110 -26
  81. package/dist/faux-computers.js +1 -1
  82. package/dist/filed-answer.d.ts +2 -2
  83. package/dist/filed-answer.js +2 -2
  84. package/dist/graph-served.d.ts +10 -5
  85. package/dist/graph-served.js +40 -10
  86. package/dist/handed-values.js +1 -2
  87. package/dist/harness-check.d.ts +2 -1
  88. package/dist/harness-check.js +45 -12
  89. package/dist/harness-keys.js +9 -6
  90. package/dist/harness-opencode/facts.js +2 -0
  91. package/dist/harness-recipe-entry.d.ts +9 -3
  92. package/dist/harness-recipe-entry.js +18 -9
  93. package/dist/harness-recipe.d.ts +21 -0
  94. package/dist/harness-recipe.js +25 -3
  95. package/dist/harness-table.d.ts +8 -0
  96. package/dist/harness-table.js +17 -6
  97. package/dist/helper-env.d.ts +4 -1
  98. package/dist/helper-env.js +4 -1
  99. package/dist/host-check.d.ts +2 -3
  100. package/dist/host-check.js +13 -7
  101. package/dist/hosted-search.js +1 -1
  102. package/dist/import.d.ts +11 -8
  103. package/dist/import.js +437 -186
  104. package/dist/key-refusal.d.ts +9 -2
  105. package/dist/key-refusal.js +86 -32
  106. package/dist/learn/audit.d.ts +8 -5
  107. package/dist/learn/audit.js +15 -7
  108. package/dist/learn/compile.d.ts +5 -2
  109. package/dist/learn/compile.js +45 -21
  110. package/dist/learn/field-check.d.ts +111 -0
  111. package/dist/learn/field-check.js +174 -0
  112. package/dist/learn/ledger.d.ts +173 -0
  113. package/dist/learn/ledger.js +225 -0
  114. package/dist/learn/promote.d.ts +82 -39
  115. package/dist/learn/promote.js +61 -66
  116. package/dist/learn/secrets.d.ts +4 -0
  117. package/dist/learn/secrets.js +12 -0
  118. package/dist/learned-nodes.d.ts +8 -5
  119. package/dist/learned-nodes.js +8 -5
  120. package/dist/learned-workflow.d.ts +2 -1
  121. package/dist/learned-workflow.js +13 -10
  122. package/dist/learning-cost.d.ts +40 -21
  123. package/dist/learning-cost.js +30 -21
  124. package/dist/learning-setting.d.ts +6 -0
  125. package/dist/learning-setting.js +11 -1
  126. package/dist/listen-first.d.ts +5 -4
  127. package/dist/listen-first.js +4 -5
  128. package/dist/live-reach.d.ts +9 -0
  129. package/dist/live-reach.js +9 -0
  130. package/dist/mcp-api-only-origins.d.ts +23 -3
  131. package/dist/mcp-api-only-origins.js +57 -17
  132. package/dist/mcp-gateway.d.ts +16 -2
  133. package/dist/mcp-gateway.js +41 -3
  134. package/dist/mcp-oauth.d.ts +1 -1
  135. package/dist/mcp-oauth.js +3 -2
  136. package/dist/mcp-probe.d.ts +3 -0
  137. package/dist/mcp-probe.js +3 -0
  138. package/dist/mcp-secret-writes.d.ts +24 -2
  139. package/dist/mcp-secret-writes.js +30 -2
  140. package/dist/mcp-servers-store.d.ts +52 -14
  141. package/dist/mcp-servers-store.js +165 -61
  142. package/dist/mcp-sources.d.ts +1 -2
  143. package/dist/mcp-sources.js +1 -2
  144. package/dist/mcp-store.d.ts +5 -5
  145. package/dist/mcp-store.js +3 -3
  146. package/dist/mcp.js +1 -1
  147. package/dist/micro.d.ts +2 -0
  148. package/dist/micro.js +2 -0
  149. package/dist/model-gateway.d.ts +1 -1
  150. package/dist/model-gateway.js +20 -36
  151. package/dist/model.d.ts +5 -4
  152. package/dist/model.js +7 -6
  153. package/dist/monid.d.ts +14 -1
  154. package/dist/monid.js +103 -26
  155. package/dist/ollama-provider.d.ts +23 -9
  156. package/dist/ollama-provider.js +49 -20
  157. package/dist/openapi.js +234 -61
  158. package/dist/otel/genai.d.ts +83 -7
  159. package/dist/otel/genai.js +69 -9
  160. package/dist/otel/tracer.d.ts +42 -13
  161. package/dist/otel/tracer.js +241 -56
  162. package/dist/page.d.ts +7 -1
  163. package/dist/page.js +76 -22
  164. package/dist/paid-calls.d.ts +6 -4
  165. package/dist/paid-calls.js +15 -7
  166. package/dist/place-offers.d.ts +59 -34
  167. package/dist/place-offers.js +100 -58
  168. package/dist/place.d.ts +13 -14
  169. package/dist/place.js +56 -41
  170. package/dist/print.js +1 -1
  171. package/dist/provider.d.ts +5 -4
  172. package/dist/provider.js +26 -13
  173. package/dist/redact/match.d.ts +27 -9
  174. package/dist/redact/match.js +266 -57
  175. package/dist/run-census.d.ts +1 -1
  176. package/dist/run-census.js +4 -5
  177. package/dist/run-cut.js +4 -5
  178. package/dist/run-export-store.d.ts +15 -0
  179. package/dist/run-export-store.js +30 -0
  180. package/dist/run-export.d.ts +139 -0
  181. package/dist/run-export.js +379 -0
  182. package/dist/run-file-cut.d.ts +5 -0
  183. package/dist/run-file-cut.js +13 -0
  184. package/dist/run-launch.js +16 -3
  185. package/dist/run-learning-served.d.ts +2 -2
  186. package/dist/run-model-key.d.ts +15 -6
  187. package/dist/run-model-key.js +30 -31
  188. package/dist/run-reads-over-store.js +4 -4
  189. package/dist/run-secrets.js +3 -5
  190. package/dist/run-timeline-served.js +3 -1
  191. package/dist/run-view.d.ts +1 -2
  192. package/dist/run-view.js +2 -1
  193. package/dist/runnable.js +2 -2
  194. package/dist/runner/adapter-loop.d.ts +35 -18
  195. package/dist/runner/adapter-loop.js +97 -63
  196. package/dist/runner/adapter-run-spec.d.ts +34 -14
  197. package/dist/runner/adapter-run-spec.js +120 -75
  198. package/dist/runner/adapters/pi.js +4 -2
  199. package/dist/runner/audit.d.ts +8 -5
  200. package/dist/runner/audit.js +37 -17
  201. package/dist/runner/beside.d.ts +9 -2
  202. package/dist/runner/beside.js +29 -13
  203. package/dist/runner/claim-secrets.d.ts +27 -18
  204. package/dist/runner/claim-secrets.js +61 -47
  205. package/dist/runner/cli-run-spec.d.ts +18 -0
  206. package/dist/runner/cli-run-spec.js +93 -46
  207. package/dist/runner/compare-end.d.ts +2 -1
  208. package/dist/runner/compare-end.js +25 -10
  209. package/dist/runner/conformance/harness.js +2 -3
  210. package/dist/runner/conformance/subject.d.ts +4 -1
  211. package/dist/runner/harness-loops.js +3 -3
  212. package/dist/runner/held.d.ts +19 -4
  213. package/dist/runner/journal-kinds.d.ts +4 -1
  214. package/dist/runner/journal-kinds.js +22 -4
  215. package/dist/runner/learned-first.js +20 -4
  216. package/dist/runner/learning-end.d.ts +2 -8
  217. package/dist/runner/learning-end.js +11 -19
  218. package/dist/runner/live-ticker.js +7 -5
  219. package/dist/runner/loop-contract.d.ts +0 -2
  220. package/dist/runner/loop.d.ts +7 -0
  221. package/dist/runner/loop.js +1 -0
  222. package/dist/runner/main.d.ts +11 -6
  223. package/dist/runner/main.js +24 -18
  224. package/dist/runner/mcp-claim.js +24 -7
  225. package/dist/runner/mcp-run.d.ts +3 -6
  226. package/dist/runner/mcp-run.js +3 -4
  227. package/dist/runner/meta-tools.js +3 -2
  228. package/dist/runner/metrics.d.ts +7 -0
  229. package/dist/runner/metrics.js +19 -0
  230. package/dist/runner/model-route.d.ts +10 -7
  231. package/dist/runner/model-route.js +79 -15
  232. package/dist/runner/native-loop.js +10 -8
  233. package/dist/runner/presence.d.ts +11 -4
  234. package/dist/runner/presence.js +11 -6
  235. package/dist/runner/promotion.d.ts +25 -13
  236. package/dist/runner/promotion.js +125 -50
  237. package/dist/runner/redact.d.ts +3 -1
  238. package/dist/runner/redact.js +5 -3
  239. package/dist/runner/reflect-hook.js +1 -1
  240. package/dist/runner/responses-fetch.d.ts +36 -0
  241. package/dist/runner/responses-fetch.js +511 -0
  242. package/dist/runner/run-child-host.d.ts +38 -12
  243. package/dist/runner/run-child-host.js +231 -83
  244. package/dist/runner/run-child.js +11 -4
  245. package/dist/runner/runner-check.js +5 -1
  246. package/dist/runner/runner.d.ts +5 -3
  247. package/dist/runner/runner.js +14 -10
  248. package/dist/runner/save-slots.js +2 -1
  249. package/dist/runner/sdk-loop.js +8 -8
  250. package/dist/runner/spec-holds.d.ts +8 -1
  251. package/dist/runner/spec-holds.js +9 -4
  252. package/dist/runner/subagent.d.ts +11 -0
  253. package/dist/runner/subagent.js +17 -3
  254. package/dist/runner/workflow-calls.d.ts +9 -0
  255. package/dist/runner/workflow-calls.js +150 -0
  256. package/dist/runner/workflow-first.d.ts +138 -37
  257. package/dist/runner/workflow-first.js +230 -99
  258. package/dist/runner/workflow-spec.js +2 -2
  259. package/dist/runs-over-store.js +8 -7
  260. package/dist/save-once.d.ts +14 -0
  261. package/dist/save-once.js +31 -0
  262. package/dist/scrub-command.d.ts +34 -31
  263. package/dist/scrub-command.js +116 -147
  264. package/dist/sdk/runs.d.ts +6 -0
  265. package/dist/sdk/runs.js +89 -10
  266. package/dist/seal-key.js +4 -4
  267. package/dist/secret-cut.d.ts +3 -0
  268. package/dist/secret-cut.js +7 -1
  269. package/dist/secret-rules.d.ts +8 -1
  270. package/dist/secret-rules.js +482 -53
  271. package/dist/secrets.d.ts +51 -9
  272. package/dist/secrets.js +311 -21
  273. package/dist/server-keys.d.ts +4 -3
  274. package/dist/server-keys.js +4 -3
  275. package/dist/server-secrets-store.js +2 -4
  276. package/dist/server.d.ts +33 -10
  277. package/dist/server.js +454 -136
  278. package/dist/share-context.d.ts +22 -0
  279. package/dist/share-context.js +76 -0
  280. package/dist/shell-lex.d.ts +105 -0
  281. package/dist/shell-lex.js +646 -0
  282. package/dist/sign-ins-store.d.ts +5 -7
  283. package/dist/sign-ins-store.js +12 -16
  284. package/dist/sign-ins.d.ts +7 -11
  285. package/dist/sign-ins.js +40 -41
  286. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  287. package/dist/slots.d.ts +9 -0
  288. package/dist/slots.js +45 -0
  289. package/dist/start-switches.d.ts +6 -5
  290. package/dist/start-switches.js +8 -4
  291. package/dist/stats.d.ts +5 -1
  292. package/dist/stats.js +1 -1
  293. package/dist/store/agent-body.js +2 -2
  294. package/dist/store/dialect.d.ts +4 -0
  295. package/dist/store/dialect.js +1 -0
  296. package/dist/store/index.d.ts +2 -2
  297. package/dist/store/index.js +1 -1
  298. package/dist/store/mcp-record-keys.d.ts +10 -0
  299. package/dist/store/mcp-record-keys.js +13 -0
  300. package/dist/store/postgres/dialect.js +2 -0
  301. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  302. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  303. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  304. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  305. package/dist/store/postgres/store.js +4 -0
  306. package/dist/store/schema.d.ts +44 -4
  307. package/dist/store/schema.js +111 -11
  308. package/dist/store/seal.d.ts +4 -1
  309. package/dist/store/sqlite/run-launch.d.ts +3 -10
  310. package/dist/store/sqlite/run-launch.js +12 -23
  311. package/dist/store/sqlite/run-patch.d.ts +19 -2
  312. package/dist/store/sqlite/run-patch.js +67 -2
  313. package/dist/store/sqlite/store.d.ts +3 -0
  314. package/dist/store/sqlite/store.js +177 -32
  315. package/dist/store/store-schema.js +3 -4
  316. package/dist/store/store.d.ts +74 -25
  317. package/dist/store/store.js +14 -11
  318. package/dist/store-reads/analytics.d.ts +2 -1
  319. package/dist/store-reads/analytics.js +7 -5
  320. package/dist/store-reads/learning.d.ts +102 -136
  321. package/dist/store-reads/learning.js +251 -302
  322. package/dist/store-reads/stats.d.ts +2 -2
  323. package/dist/store-reads/stats.js +13 -7
  324. package/dist/store-view.js +10 -7
  325. package/dist/suggestions.d.ts +1 -1
  326. package/dist/suggestions.js +29 -13
  327. package/dist/template-eval.d.ts +91 -9
  328. package/dist/template-eval.js +448 -105
  329. package/dist/template-import.d.ts +0 -10
  330. package/dist/template-import.js +5 -10
  331. package/dist/timeline/labels.d.ts +1 -1
  332. package/dist/timeline/labels.js +4 -3
  333. package/dist/timeline/timeline.d.ts +23 -11
  334. package/dist/timeline/timeline.js +115 -31
  335. package/dist/timeline/web-calls.d.ts +14 -14
  336. package/dist/timeline/web-calls.js +18 -30
  337. package/dist/tool-gate.d.ts +13 -1
  338. package/dist/tool-gate.js +43 -3
  339. package/dist/tool-keys-store.js +2 -4
  340. package/dist/tool-keys.d.ts +11 -0
  341. package/dist/tool-keys.js +16 -0
  342. package/dist/tool-plane.d.ts +50 -11
  343. package/dist/tool-plane.js +94 -30
  344. package/dist/tools.d.ts +5 -1
  345. package/dist/tools.js +7 -7
  346. package/dist/trigger-email.js +12 -6
  347. package/dist/triggers.d.ts +15 -34
  348. package/dist/triggers.js +119 -126
  349. package/dist/validate.d.ts +8 -1
  350. package/dist/validate.js +163 -23
  351. package/dist/web-fake.d.ts +2 -1
  352. package/dist/web-fake.js +8 -6
  353. package/dist/web-fetch.d.ts +8 -6
  354. package/dist/web-fetch.js +13 -11
  355. package/dist/web-holds.d.ts +32 -0
  356. package/dist/web-holds.js +86 -0
  357. package/dist/web-run.d.ts +32 -5
  358. package/dist/web-run.js +75 -28
  359. package/dist/web-save.d.ts +4 -9
  360. package/dist/web-save.js +27 -55
  361. package/dist/web-search.js +14 -25
  362. package/dist/wires.d.ts +4 -3
  363. package/dist/wires.js +5 -4
  364. package/dist/workspace/archil-claim.d.ts +12 -5
  365. package/dist/workspace/archil-claim.js +45 -5
  366. package/dist/workspace/attach.js +52 -19
  367. package/dist/workspace/attached-computers.d.ts +38 -11
  368. package/dist/workspace/attached-computers.js +81 -16
  369. package/dist/workspace/computer-deps.d.ts +29 -7
  370. package/dist/workspace/computer-deps.js +36 -18
  371. package/dist/workspace/computer-for-claim.d.ts +21 -4
  372. package/dist/workspace/computer-for-claim.js +166 -57
  373. package/dist/workspace/computer-intervals.d.ts +2 -0
  374. package/dist/workspace/computer-intervals.js +1 -1
  375. package/dist/workspace/computer-janitor.d.ts +48 -14
  376. package/dist/workspace/computer-janitor.js +153 -44
  377. package/dist/workspace/computer-kept.d.ts +158 -32
  378. package/dist/workspace/computer-kept.js +288 -63
  379. package/dist/workspace/computer-providers.d.ts +8 -3
  380. package/dist/workspace/computer-providers.js +12 -5
  381. package/dist/workspace/index.d.ts +1 -1
  382. package/dist/workspace/index.js +1 -1
  383. package/dist/workspace/local.js +41 -1
  384. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  385. package/dist/workspace/mount-revoke-left.js +72 -0
  386. package/dist/workspace/paired-route.d.ts +91 -0
  387. package/dist/workspace/paired-route.js +152 -0
  388. package/dist/workspace/resolve-computer.d.ts +5 -2
  389. package/dist/workspace/resolve-computer.js +9 -3
  390. package/dist/workspace/run-end-computers.d.ts +11 -5
  391. package/dist/workspace/run-end-computers.js +153 -28
  392. package/dist/workspace/run-tools.d.ts +22 -3
  393. package/dist/workspace/run-tools.js +17 -5
  394. package/dist/workspace/run-workspace.d.ts +14 -1
  395. package/dist/workspace/run-workspace.js +34 -1
  396. package/dist/workspace/workspace.d.ts +6 -0
  397. package/dist/wrapped.d.ts +8 -2
  398. package/dist/wrapped.js +21 -6
  399. package/package.json +12 -13
  400. package/skills/agentrun-serve/SKILL.md +5 -2
  401. package/templates/README.md +25 -9
  402. package/dist/console/assets/backend-DVhHzJX2.js +0 -166
  403. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  404. package/dist/console/assets/index-okP-y8PK.js +0 -747
@@ -1,6 +1,8 @@
1
1
  // The computer janitor of this server: at the runner's start, then every JANITOR_EVERY_MS, each computer this server made
2
2
  // that is past its deadline is ended. A run's release ends its computer; the janitor is for the ones a crashed runner
3
- // left, on a provider whose vendor never ends them itself (capabilities().lifetime "janitor": Docker, Orgo).
3
+ // left, on every provider of the registry whose vendor never ends them itself: each whose capabilities().lifetime is
4
+ // "janitor", read off its built provider at every sweep (sweepServerComputers). One whose lifetime is "vendor" is
5
+ // skipped: its vendor ends its machines at their lifetime.
4
6
  //
5
7
  // Which computers it may end:
6
8
  // - a provider's whose keys this server has (saved, or in its environment); Docker takes none, so it is always asked;
@@ -13,14 +15,22 @@
13
15
  // - past its deadline, by the computer package's sweep (janitor.ts): the deadline label, or over the provider's cap; or
14
16
  // its run is over (final in the store), whatever its deadline: the run's end lets go of every claim's computer
15
17
  // (run-end-computers.ts), and this is for one a server that stopped before then left.
16
- // What a computer leaves outside itself (Docker's egress parts) goes with its release; the provider's sweepLeftovers is
17
- // not asked, since it reads labels alone and can't tell this server's parts from another's.
18
+ // What a computer leaves outside itself (Docker's egress proxy and volume) goes with its release. One a release never
19
+ // took (a server that stopped partway through a teardown) is the provider's sweepLeftovers', asked for this server's
20
+ // alone (leftoverMine): one whose agentrun.run label (or its hash) names a run in this store, or whose owner names this
21
+ // server, by the same labels the computers go by. Another server's on the same Docker host is never touched; it goes at
22
+ // that server's own next sweep.
18
23
  //
19
24
  // A desktop or a phone kept at a run's park (computer-kept.ts) goes by its own row, on any provider: each sweep ends one
20
- // past its time or whose run ended, and the janitor wakes again at the earliest time still ahead. One pinned to another
21
- // runner still there is that runner's (computer-kept.ts heldElsewhere): the kept pass leaves its row, and the provider
22
- // sweep leaves its machine out of every list by the same rule (sparedKept), so a run that ended on this runner never has
23
- // this janitor end a machine another runner keeps.
25
+ // past its time or whose run ended, with the mount credential of a run folder it held on Archil, and the janitor wakes
26
+ // again at the earliest time still ahead. One pinned to another runner still there is that runner's (computer-kept.ts
27
+ // heldElsewhere): the kept pass leaves its row, its credential with it. The provider sweep ends only a machine past its
28
+ // deadline or whose run is final, which no one uses. Its row is marked ending before that delete (endingKeptMachine), so
29
+ // a follow-up never takes the machine back mid-delete, and ended once the delete took it (finishedKept), so the run's
30
+ // next park writes its own keep; a row a claim is taking back is left, and the machine with it, said as a failed delete.
31
+ // A machine kept on Archil has its park's mount credential removed before its row is marked ended, as the kept pass
32
+ // removes it: no pass removes a credential for an ended row. A remove that fails leaves the row ending, and the kept pass
33
+ // that then ends it removes the credential.
24
34
  //
25
35
  // A provider whose sweep fails is logged, once per distinct failure, and the others are swept. It runs only where its
26
36
  // start asks for it (the CLI's runner and the runner subcommand), never under --faux, and never two sweeps at once. Its
@@ -30,13 +40,18 @@
30
40
  // An agent's own computer (a persistent setting, agent-computer.ts) is this server's when its owner names this server's
31
41
  // id, never by its run: it goes only when its agent no longer wants it (ownerGoneOf: gone, archived, or no longer
32
42
  // persistent on that provider), never by a deadline. Without the store's settings and agents, none is this server's.
33
- import { epochOf, ok, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
43
+ import { epochOf, fail, ok, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
44
+ import { loadArchilSettings } from "../archil-settings.js";
34
45
  import { KEY_TABLE, providerOptions } from "../computer-keys.js";
35
46
  import { FAUX_ENV } from "../model.js";
36
47
  import { FINAL_STATES } from "../store/index.js";
37
48
  import { deleteUnderHold, ownerGoneOf, serverIdOf, wantsOn } from "./agent-computer.js";
38
- import { sparedKept, sweepKept } from "./computer-kept.js";
49
+ import { archilApiKey } from "./archil-key.js";
50
+ import { removeRunMountTokens } from "./archil-mount-credential.js";
51
+ import { endingKeptMachine, finishedKept, readKept, sweepKept } from "./computer-kept.js";
52
+ import { MOUNT_TTL_MS } from "./archil-claim.js";
39
53
  import { storeLedger } from "./computer-ledger.js";
54
+ import { sweepMountRevokes } from "./mount-revoke-left.js";
40
55
  import { providerKeys } from "./resolve-computer.js";
41
56
  import { intervalWrites } from "./computer-intervals.js";
42
57
  /** How often the janitor sweeps after its first sweep at the runner's start. */
@@ -50,6 +65,12 @@ const runsByHash = (store) => {
50
65
  let read;
51
66
  return () => (read ??= store.runs.list({}).then((rows) => new Map(rows.map((row) => [runHash(row.id), row.id]))));
52
67
  };
68
+ /** The run a computer's labels name: by its run label, or its hash's (runsByHash); undefined for none of this store's. */
69
+ async function runOf(labels, byHash) {
70
+ const named = labels[RUN_LABEL];
71
+ const hash = labels[RUN_HASH_LABEL];
72
+ return typeof named === "string" && named !== "" ? named : typeof hash === "string" && hash !== "" ? (await byHash()).get(hash) : undefined;
73
+ }
53
74
  /** 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
54
75
  * 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.
55
76
  * "over" for one of these whose run is over (final in the store): no claim of the run will use it again. An agent's own
@@ -61,9 +82,7 @@ async function sweepable(store, info, byHash, serverId) {
61
82
  const owner = info.owner ?? (label.ok ? label.value : undefined);
62
83
  if (info.owned === true || owner !== undefined || !label.ok)
63
84
  return serverId !== undefined && owner?.server === serverId;
64
- const named = labels[RUN_LABEL];
65
- const hash = labels[RUN_HASH_LABEL];
66
- const runId = typeof named === "string" && named !== "" ? named : typeof hash === "string" && hash !== "" ? (await byHash()).get(hash) : undefined;
85
+ const runId = await runOf(labels, byHash);
67
86
  if (runId === undefined)
68
87
  return false;
69
88
  const run = await store.runs.get(runId);
@@ -77,16 +96,40 @@ async function sweepable(store, info, byHash, serverId) {
77
96
  return false;
78
97
  return FINAL_STATES.includes(run.state) ? "over" : true;
79
98
  }
80
- /** `provider` as the sweep sees it: its list cut to this server's computers that no claim holds, and no leftovers pass.
99
+ /** Whether a leftover with these labels is this server's to remove: an agent's (an owner label) when its owner names
100
+ * `serverId`; otherwise when its run (by its label, or its hash's) is in this store and no claim holds it now
101
+ * (runs.heldAt, by the store's clock). A held run's runner may be making the computer this part belongs to: create
102
+ * makes the proxy before the computer. The provider reads the computer after this answer (Docker's sweepLeftovers),
103
+ * and that read is final: a computer is made only under a held claim, its name is its claim's (runId#epoch), so once
104
+ * none holds the run, no create at that claim is left, and a later claim's computer has another name. */
105
+ async function leftoverMine(store, labels, byHash, serverId) {
106
+ const label = ownerOf(labels);
107
+ if (!label.ok || label.value !== undefined)
108
+ return label.ok && serverId !== undefined && label.value?.server === serverId;
109
+ const named = labels[RUN_LABEL];
110
+ const hash = labels[RUN_HASH_LABEL];
111
+ const runId = typeof named === "string" && named !== "" ? named : typeof hash === "string" && hash !== "" ? (await byHash()).get(hash) : undefined;
112
+ if (runId === undefined || (await store.runs.get(runId)) === undefined)
113
+ return false;
114
+ return (await store.runs.heldAt(runId)) === undefined;
115
+ }
116
+ /** `provider` as the sweep sees it: its list cut to this server's computers that no claim holds, and its leftovers pass
117
+ * (where it has one) cut to this server's (leftoverMine).
81
118
  * A computer of a run that is over is listed past its deadline (the run's end is its deadline), so the sweep ends it
82
119
  * now: a server that stopped before its run's end let go of an earlier claim's computer (run-end-computers.ts) leaves
83
120
  * it for this sweep, never for its day-long deadline. Each call goes to the provider itself, so its own state is used
84
121
  * as it is. */
85
- function thisServers(provider, store, byHash, serverId, at, ended, spared) {
122
+ function thisServers(provider, store, byHash, serverId, at, ended, keeps) {
86
123
  // The agents' own computers the list kept, by id: their delete goes under the agent's hold (deleteUnderHold), which
87
124
  // also clears the agent's record of it, so its view no longer shows it deleting.
88
125
  const ownedBy = new Map();
126
+ // The machines the list kept that their run's park row keeps, by id, each that run: the row is marked ending before
127
+ // the delete (endingKeptMachine), and a row a claim has is left with its machine. A machine whose run's row could not
128
+ // be read is left too, in the store's words: it may be kept, and a delete unmarked could go under a claim's attach.
129
+ const keptRun = new Map();
130
+ const unread = new Map();
89
131
  const { settings, agents } = store;
132
+ const leftovers = provider.sweepLeftovers?.bind(provider);
90
133
  return {
91
134
  id: provider.id,
92
135
  version: provider.version,
@@ -96,13 +139,33 @@ function thisServers(provider, store, byHash, serverId, at, ended, spared) {
96
139
  attach: (target, context) => provider.attach(target, context),
97
140
  network: (ref, policy, context) => provider.network(ref, policy, context),
98
141
  connect: (ref) => provider.connect(ref),
142
+ ...(leftovers === undefined ? {} : { sweepLeftovers: (context) => leftovers({ ...context, mine: (labels) => leftoverMine(store, labels, byHash, serverId) }) }),
99
143
  async release(ref, how, context) {
144
+ const why = how === "delete" ? unread.get(ref.id) : undefined;
145
+ if (why !== undefined)
146
+ return fail("refused", `its run's kept row could not be read (${why}), so it was left`);
147
+ const run = how === "delete" ? keptRun.get(ref.id) : undefined;
148
+ /** The machine's row as marked ending here: ended once the delete took it, a credential on Archil removed first
149
+ * (finishedKept). */
150
+ let finished;
151
+ if (run !== undefined && keeps) {
152
+ const marked = await endingKeptMachine(keeps.settings, run, { provider: keeps.entry, id: ref.id });
153
+ if (marked.kind === "left")
154
+ return fail("refused", `it is kept at run ${run}'s park and a claim is taking it back or has it, so it was left`);
155
+ if (marked.kind === "unmarked")
156
+ return fail("refused", `it is kept at run ${run}'s park and its row could not be marked ending (${marked.why}), so it was left for the row's time`);
157
+ const kept = marked.kept;
158
+ if (kept && kept.provider === keeps.entry && kept.id === ref.id)
159
+ finished = () => finishedKept(keeps.settings, run, kept, keeps.revokeMount);
160
+ }
100
161
  const agent = ownedBy.get(ref.id);
101
162
  if (how !== "delete" || agent === undefined || settings === undefined) {
102
163
  const released = await provider.release(ref, how, context);
103
164
  // A run's computer the sweep deleted: its interval ends (computer-intervals.ts), on the provider's ok alone.
104
- if (released.ok && how === "delete")
165
+ if (released.ok && how === "delete") {
105
166
  await ended(ref.id);
167
+ await finished?.();
168
+ }
106
169
  return released;
107
170
  }
108
171
  // Asked again under the hold: the agent may want it back since ownerGone was read (this server's owners carry no
@@ -116,12 +179,21 @@ function thisServers(provider, store, byHash, serverId, at, ended, spared) {
116
179
  return listed;
117
180
  const kept = [];
118
181
  for (const info of listed.value) {
119
- // A machine kept at a park for another runner still there (sparedKept): that runner's to end, never this sweep's.
120
- if (spared(info.ref.id))
121
- continue;
122
182
  const mine = await sweepable(store, info, byHash, serverId);
123
183
  if (!mine)
124
184
  continue;
185
+ // Its run's kept row, read before any delete: whether it keeps this machine.
186
+ const runId = keeps ? await runOf(info.labels, byHash) : undefined;
187
+ if (keeps && runId !== undefined) {
188
+ try {
189
+ const row = await readKept(keeps.settings, runId);
190
+ if (row && !row.ended && row.provider === keeps.entry && row.id === info.ref.id)
191
+ keptRun.set(info.ref.id, runId);
192
+ }
193
+ catch (error) {
194
+ unread.set(info.ref.id, error instanceof Error ? error.message : String(error));
195
+ }
196
+ }
125
197
  const label = ownerOf(info.labels);
126
198
  const owner = info.owner ?? (label.ok ? label.value : undefined);
127
199
  if (owner !== undefined)
@@ -150,11 +222,8 @@ async function bounded(ms, signal, work) {
150
222
  }
151
223
  }
152
224
  /** One sweep of every provider this server can list: each provider whose keys it has and whose computers the janitor
153
- * ends, its computers past their deadline that are this server's and unheld ended. A computer kept at a park pinned to
154
- * another runner still there is left out of every list (computer-kept.ts sparedKept, by the kept pass's own rule): a
155
- * provider both runners list (a dial vendor's account, a shared Docker engine) would otherwise end, once its run is
156
- * over, a machine the kept pass left to its runner. Where the kept rows can't be read, each provider is answered as not
157
- * swept this pass. A provider that fails is answered in its words; nothing throws. */
225
+ * ends, its computers past their deadline that are this server's and unheld ended. A provider that fails is answered
226
+ * in its words; nothing throws. */
158
227
  export async function sweepServerComputers(deps, signal) {
159
228
  const { store, computers } = deps;
160
229
  const writes = intervalWrites(store, deps.log, deps.now);
@@ -163,16 +232,10 @@ export async function sweepServerComputers(deps, signal) {
163
232
  const byHash = runsByHash(store);
164
233
  // This server's id and its agents: its agents' own computers are swept by their owner (ownerGoneOf).
165
234
  const { settings, agents } = store;
166
- // The kept machines this sweep leaves, read once for every provider; with no settings, nothing is kept.
167
- let spared = () => false;
168
- if (settings) {
169
- try {
170
- spared = await sparedKept({ settings, ...(store.runners ? { runners: store.runners } : {}), ...(deps.self ? { self: deps.self } : {}) });
171
- }
172
- catch (error) {
173
- spared = { unread: `the computers kept at a park could not be read, so none of its computers is swept this pass: ${error instanceof Error ? error.message : String(error)}` };
174
- }
175
- }
235
+ // A kept machine on Archil this sweep deletes has its park's mount credential removed before its row is marked ended,
236
+ // its ttl judged on the store's clock, as the kept pass judges it. Without the runs' environment, its row is left
237
+ // ending for the kept pass.
238
+ const revokeMount = settings && deps.env ? keptMountRevoke({ settings, sealedKeys: store.sealedKeys, env: deps.env, sealKey: deps.sealKey, ...(deps.mountControl ? { mountControl: deps.mountControl } : {}) }, () => store.sealedKeys.clock()) : undefined;
176
239
  const serverId = settings && agents ? await serverIdOf({ settings }) : undefined;
177
240
  const out = [];
178
241
  for (const entry of computers.kinds.PROVIDERS) {
@@ -191,13 +254,8 @@ export async function sweepServerComputers(deps, signal) {
191
254
  // A vendor that ends its own computers needs no janitor.
192
255
  if (provider.capabilities().lifetime !== "janitor")
193
256
  continue;
194
- if (typeof spared !== "function") {
195
- out.push({ provider: entry.id, swept: { ok: false, error: { code: "unreachable", message: spared.unread } } });
196
- continue;
197
- }
198
- const leaves = spared;
199
257
  const ownerGone = serverId !== undefined && settings && agents ? ownerGoneOf({ agents, settings, runs: store.runs }, serverId, entry.id) : undefined;
200
- out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash, serverId, at, (id) => writes.ended(entry.id, id), (id) => leaves(entry.id, id)), { now: new Date(at), signal: cut, ...(ownerGone ? { ownerGone } : {}) })) });
258
+ out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash, serverId, at, (id) => writes.ended(entry.id, id), settings ? { settings, entry: entry.id, ...(revokeMount ? { revokeMount } : {}) } : undefined), { now: new Date(at), signal: cut, ...(ownerGone ? { ownerGone } : {}) })) });
201
259
  }
202
260
  catch (error) {
203
261
  out.push({ provider: entry.id, swept: { ok: false, error: { code: "refused", message: error instanceof Error ? error.message : String(error) } } });
@@ -205,15 +263,54 @@ export async function sweepServerComputers(deps, signal) {
205
263
  }
206
264
  return out;
207
265
  }
266
+ /** The remove of a kept row's Archil mount credential (computer-kept.ts KeptMountRevoke), as every end of a row kept on
267
+ * Archil asks it (the kept pass, the provider sweep, a run's end): the run's credentials up to the row's epoch removed,
268
+ * by name, on the disk its row names (the park's), with this server's Archil key read as the claims read it
269
+ * (archil-key.ts): no run lookup, so a run deleted since, or an agent whose disk changed, still has it removed. A row
270
+ * that names no disk has none removed, said on `log`, and its credential ends at its ttl. Past its keep's time plus
271
+ * MOUNT_TTL_MS, by `now` (the store's clock, the one `until` was stamped on), no remove is asked: the credential was
272
+ * minted before the park, so it has ended at its ttl. `signal` cuts its calls to Archil (the janitor's bound passed).
273
+ * Throws where the remove failed, or this server's Archil settings are gone. */
274
+ export function keptMountRevoke(deps, now) {
275
+ return async (runId, kept, signal) => {
276
+ const { disk } = kept;
277
+ if (disk === undefined) {
278
+ deps.log?.(`the computer janitor removed no mount credential of run ${runId}: its kept computer held the run's folder on Archil, but its row names no disk, so the credential lapses at its ttl`);
279
+ return;
280
+ }
281
+ if ((await now()) >= kept.until + MOUNT_TTL_MS)
282
+ return;
283
+ const archil = await loadArchilSettings({ settings: deps.settings }, deps.env);
284
+ if (!archil)
285
+ throw new Error("its mount credential was not removed: this server's Archil settings are gone");
286
+ const { value } = await archilApiKey({ env: deps.env, keys: deps.sealedKeys, sealKey: deps.sealKey });
287
+ await removeRunMountTokens({ region: archil.region, key: () => value, disk, ...deps.mountControl }, runId, kept.epoch, signal ? { signal } : {});
288
+ };
289
+ }
208
290
  /** The pass over the desktops and phones kept at a run's park (computer-kept.ts sweepKept): one past its time, or whose
209
291
  * run ended, is ended through its provider, made with this server's keys, whatever its lifetime (a vendor's own end is
210
- * hours away); one pinned to another runner still there (the store's runners) is left to that runner. Undefined without
211
- * the store's settings, where none is kept. Never throws. */
292
+ * hours away); one pinned to another runner still there (the store's runners) is left to that runner. One that held the
293
+ * run's folder on Archil has the run's mount credentials up to its epoch removed (keptMountRevoke). Past its keep's time
294
+ * plus MOUNT_TTL_MS no remove is asked, so a remove that can never succeed (Archil turned off, its key gone, a refusal
295
+ * for good) no longer keeps the row ending and said at every pass. The removes a claim that kept nothing left at its
296
+ * end (mount-revoke-left.ts) are asked the same way, each bounded by `deleteMs` and its row removed once its remove
297
+ * answers. Undefined without the store's settings, where none is kept. Never throws. */
212
298
  export async function sweepKeptComputers(deps) {
213
299
  const { store, computers } = deps;
214
300
  const writes = intervalWrites(store, deps.log, deps.now);
215
- if (!store.settings)
301
+ const { settings } = store;
302
+ if (!settings)
216
303
  return undefined;
304
+ // Each row's `until` was stamped on the store's clock (computer-kept.ts Kept.until), so it is judged on it: its end and
305
+ // the give-up of its credential's remove (past `until` plus MOUNT_TTL_MS) alike.
306
+ let now;
307
+ try {
308
+ now = await store.sealedKeys.clock();
309
+ }
310
+ catch (error) {
311
+ return { ended: [], failed: [`the store's clock could not be read, so no kept computer's time could be judged this pass: ${error instanceof Error ? error.message : String(error)}`] };
312
+ }
313
+ const revokeMount = keptMountRevoke({ settings, sealedKeys: store.sealedKeys, env: deps.env, sealKey: deps.sealKey, ...(deps.mountControl ? { mountControl: deps.mountControl } : {}), ...(deps.log ? { log: deps.log } : {}) }, async () => now);
217
314
  const keysOf = providerKeys(computers.kinds, computers.keyOf ?? (async () => undefined));
218
315
  const providerOf = async (id) => {
219
316
  const make = Object.hasOwn(computers.providers, id) ? computers.providers[id] : undefined;
@@ -222,7 +319,12 @@ export async function sweepKeptComputers(deps) {
222
319
  const options = providerOptions(id, await keysOf(id), computers.settings ?? {}, computers.keyTable ?? KEY_TABLE);
223
320
  return options.ok ? make(options.options, { ledger: storeLedger(store.computerLedger, id) }) : undefined;
224
321
  };
225
- return sweepKept({ settings: store.settings, runs: store.runs, now: (deps.now ?? Date.now)(), providerOf, deleted: (provider, id) => writes.ended(provider, id), ...(store.runners ? { runners: store.runners } : {}), ...(deps.self ? { self: deps.self } : {}) });
322
+ const bound = deps.deleteMs === undefined ? {} : { deleteMs: deps.deleteMs };
323
+ const kept = await sweepKept({ settings, runs: store.runs, now, providerOf, deleted: (provider, id) => writes.ended(provider, id), revokeMount, ...bound, ...(store.runners ? { runners: store.runners } : {}), ...(deps.self ? { self: deps.self } : {}) });
324
+ // The removes a claim that kept nothing left at its end (mount-revoke-left.ts), by the same remove, its give-up and its
325
+ // bound, so one Archil does not answer never holds the pass from its provider sweep and its next wake.
326
+ const left = await sweepMountRevokes({ settings, revoke: revokeMount, ...bound });
327
+ return left.failed.length === 0 ? kept : { ...kept, failed: [...kept.failed, ...left.failed] };
226
328
  }
227
329
  /** The janitor: one sweep now, then one every `everyMs`, never two at once, and a kept pass at the earliest time a kept
228
330
  * computer is due (sweepKeptComputers; each delete bounded, KEPT_DELETE_MS), so a park's keep ends on time though the
@@ -251,6 +353,11 @@ export function startJanitor(deps) {
251
353
  wake = undefined;
252
354
  if (kept.next === undefined)
253
355
  return;
356
+ // `next` is on the store's clock, so the wait is reckoned from it. Unread: no wake, and the next sweep (everyMs)
357
+ // passes over the rows again.
358
+ const at = await deps.store.sealedKeys.clock().catch(() => undefined);
359
+ if (at === undefined || cut.signal.aborted)
360
+ return;
254
361
  wake = setTimeout(() => {
255
362
  if (cut.signal.aborted)
256
363
  return;
@@ -258,7 +365,7 @@ export function startJanitor(deps) {
258
365
  missed = true;
259
366
  else
260
367
  void alone(keptPass);
261
- }, Math.max(0, kept.next - (deps.now ?? Date.now)()) + 1_000);
368
+ }, Math.max(0, kept.next - at) + 1_000);
262
369
  wake.unref();
263
370
  };
264
371
  /** `work` as the one sweep under way; a wake missed meanwhile runs the kept pass once it is done. */
@@ -294,6 +401,8 @@ export function startJanitor(deps) {
294
401
  said.delete(provider);
295
402
  if (swept.value.deleted.length > 0)
296
403
  deps.log(`the computer janitor ended ${provider}'s computers past their deadline: ${swept.value.deleted.join(", ")}`);
404
+ if ((swept.value.leftovers ?? []).length > 0)
405
+ deps.log(`the computer janitor removed what ${provider}'s computers left behind: ${(swept.value.leftovers ?? []).join(", ")}`);
297
406
  }
298
407
  });
299
408
  const first = once();
@@ -1,5 +1,5 @@
1
1
  import { type ComputerProvider, type MountKind, type ProviderEntry } from "@parcha/agentrun-computer";
2
- import { type Runners, type Settings, type Store } from "../store/index.js";
2
+ import { type Claim, type Runners, type Settings, type Store } from "../store/index.js";
3
3
  /** How long a park keeps the run's computer for its resume: 10 minutes. */
4
4
  export declare const KEEP_MS: number;
5
5
  /** KEEP_MS in words. */
@@ -7,7 +7,8 @@ export declare const KEEP_WORDS = "10 minutes";
7
7
  /** What a run parked for: a tool's approval, an answer to its question (ask_person), a raise of its spend cap, its turn
8
8
  * ended at a refusal of the cap's (paused there), or its learned workflow's call's approval. */
9
9
  export type ParkCause = "approval" | "answer" | "cap" | "refusal" | "workflow";
10
- /** The live view's end at a park: why it parked, and the time its computer is kept until (ms). */
10
+ /** The live view's end at a park: why it parked, and the time its computer is kept until (ms), on the parking process's
11
+ * own clock (the viewer counts down from it there), not the row's store-clock `until`. */
11
12
  export type ParkedEnd = {
12
13
  readonly parked: ParkCause;
13
14
  readonly until: number;
@@ -21,15 +22,27 @@ export declare const computerLapsedWords: (kind: string) => string;
21
22
  * (pinnedOf), that runner was gone by the resume, and the claiming runner could not reach it. Never names the runner:
22
23
  * a runner's name carries its host's. */
23
24
  export declare const computerLostWords: (kind: string) => string;
25
+ /** Why the run's computer at its resume is a new one: the one kept at its park was pinned to the runner that kept it,
26
+ * that runner was still there but could not take the run back (refusing claims, or its word late), and the claiming
27
+ * runner could not reach the machine, so it went on on a new one and that runner ends the kept one (restoreKept). Never
28
+ * names the runner. */
29
+ export declare const computerHeldWords: (kind: string) => string;
24
30
  /** The live view's words once the kept computer's time passed, the run still parked. */
25
31
  export declare const lapsedWords: (kind: string) => string;
26
- /** The settings key prefix of the kept computers, one row per run (the store's, which its claim rule reads). */
27
- export declare const KEPT_PREFIX = "computer_kept:";
28
- /** The settings key of `runId`'s kept computer. */
32
+ /** The live view's words, the run still parked, for a kept computer whose end began before its time: a claim that could
33
+ * not reach it went on without it (restoreKept), or a later park kept nothing beside another runner's row (keepKept).
34
+ * Its time did not pass, and nothing happens at it for this run, so no reason is given. */
35
+ export declare const unkeptWords: (kind: string) => string;
36
+ /** The settings key of `runId`'s kept computer (the store's KEPT_PREFIX, which its claim rule reads). */
29
37
  export declare const keptKeyOf: (runId: string) => string;
30
38
  /** A computer kept at a park: its provider (by id), its kind, its ref, the claim epoch its labels carry (a later claim
31
- * reads its mount back under that epoch), and the time it is kept until (ms). `ending`: its delete has begun and may
32
- * not have finished; `ended`: it is gone. Either way no claim takes it. */
39
+ * reads its mount back under that epoch), and the time it is kept until (ms). `until` is on the store's clock (the
40
+ * deadlines': the database's on Postgres, Store.sealedKeys.clock), stamped from it at the park, and every reader judges
41
+ * it on that clock: the claim rule's pin (in SQL), a claim's take-back, the janitor's pass, the run's computer view and
42
+ * the run read's `computer.released` (computer-held-routes.ts releasedAtPark).
43
+ * The parking runner's own timer counts KEEP_MS from the stamp on its own clock. `ending`: its delete has begun and may
44
+ * not have finished, or a later claim went on without it and left it to its runner to end (restoreKept, keepKept);
45
+ * `ended`: it is gone. Either way no claim takes it. */
33
46
  export type Kept = {
34
47
  readonly provider: string;
35
48
  readonly kind: "desktop" | "phone" | "sandbox";
@@ -40,10 +53,18 @@ export type Kept = {
40
53
  /** The kind of the run's folder it holds (a bind, an Archil mount or a synced folder); none: it holds none. A claim
41
54
  * takes it back only to hold the folder the same way (computer-for-claim.ts reattach). */
42
55
  readonly folder?: MountKind;
56
+ /** The Archil disk the run's mount credential is on, where `folder` is archil: the janitor that ends the row removes
57
+ * the credential there, whatever became of the run's row or its agent's disk since. Absent: none is removed, and the
58
+ * credential ends at its ttl. */
59
+ readonly disk?: string;
43
60
  /** The runner that kept it and that runner's process (its presence incarnation), where only that runner can reach it
44
61
  * again (pinnedOf): both or neither. Absent: any runner takes it back. */
45
62
  readonly runner?: string;
46
63
  readonly incarnation?: string;
64
+ /** The epoch of the claim taking it back (takeKept): that claim is reaching it, or could not write what came of that.
65
+ * No claim takes it, no park writes over it, and at its time it is ended as any row (endKept, sweepKept), so a
66
+ * take-back that never wrote its end (its process died, the store failed it) leaves the machine a row to end it. */
67
+ readonly taking?: number;
47
68
  readonly ending?: true;
48
69
  readonly ended?: true;
49
70
  };
@@ -66,39 +87,136 @@ export type KeptHolders = {
66
87
  readonly runners?: Pick<Runners, "live">;
67
88
  readonly self?: KeptHolder;
68
89
  };
69
- /** The one rule both janitor sweeps leave a kept machine by (sweepKept, and the provider sweep through sparedKept): its
70
- * row is pinned to a runner other than `self` that is still there under the row's incarnation (seen within
71
- * PRESENCE_STALE_MS). Only that runner's engine or hub has the machine, so a delete from here either finds nothing (and
72
- * marks the row ended, leaking it) or, where both runners list it (a dial vendor's account, a shared Docker engine),
73
- * ends a machine its runner still keeps. The runners are read once per maker's call. A read that fails counts every
74
- * pinned row as held elsewhere: ending another runner's machine blind would leak it or take it. */
90
+ /** The one rule the janitor's kept pass leaves a kept row by (sweepKept), a park leaves another's row by (keepKept), and a
91
+ * claim gives a row back by (computer-for-claim.ts reattach): its row is pinned to a runner other than `self` that is
92
+ * still there under the row's incarnation (seen within RUNNER_STALE_MS, refusing claims or not: store KEPT_PREFIX
93
+ * states the one meaning, and why the claim rule alone also asks that it claims). Only that runner's engine or hub has
94
+ * the machine, so a delete from here either finds nothing (and marks the row ended, leaking it) or, where both runners
95
+ * list it (a dial vendor's account, a shared Docker engine), ends a machine its runner still keeps. The provider sweep
96
+ * asks nothing of this: it ends only a machine past its deadline or whose run is final, which has no user. The runners
97
+ * are read once per maker's call. A read that fails counts every pinned row as held elsewhere: ending another runner's
98
+ * machine blind would leak it or take it. */
75
99
  export declare function heldElsewhere(holders: KeptHolders): (kept: Pick<Kept, "runner" | "incarnation">) => Promise<boolean>;
76
- /** The kept machines a provider sweep leaves this pass, by provider id and computer id: each row not yet ended whose
77
- * machine is held elsewhere (heldElsewhere, the kept pass's own rule). Throws when the rows can't be read: the sweep
78
- * then can't tell which machines are kept, and must not guess. */
79
- export declare function sparedKept(deps: KeptHolders & {
80
- readonly settings: Pick<KeptSettings, "all">;
81
- }): Promise<(provider: string, id: string) => boolean>;
82
100
  /** How long one delete of a kept computer may take at the janitor's pass: past it the pass goes on, the row is left
83
101
  * ending, and the next pass deletes it again (a Docker command has no timeout of its own). */
84
102
  export declare const KEPT_DELETE_MS = 60000;
85
103
  /** The settings the kept rows live in. */
86
- export type KeptSettings = Pick<Settings, "get" | "put" | "replaceIf" | "removeIf" | "remove" | "all">;
104
+ export type KeptSettings = Pick<Settings, "get" | "put" | "putIfAbsent" | "replaceIf" | "removeIf" | "remove" | "all">;
87
105
  /** A row's value as a Kept, or undefined for anything else. */
88
106
  export declare function keptOf(value: unknown): Kept | undefined;
89
107
  /** `runId`'s kept computer, as its row reads now; undefined when there is none. */
90
108
  export declare function readKept(settings: Pick<KeptSettings, "get">, runId: string): Promise<Kept | undefined>;
91
- /** Writes `kept` as `runId`'s kept computer: the claim that parks. Its fields in one order, so a later compare-and-set
92
- * reads the same text. */
109
+ /** Writes `kept` as `runId`'s kept computer, whatever the row held. Its fields in one order, so a later compare-and-set
110
+ * reads the same text. A park writes through keepKept. */
93
111
  export declare function writeKept(settings: Pick<KeptSettings, "put">, runId: string, kept: Kept): Promise<Kept>;
94
- /** Takes `kept` off its row for the claim that resumes in time: true when this call took it, false when its end (or
95
- * another claim) had it first. */
96
- export declare function takeKept(settings: Pick<KeptSettings, "removeIf">, runId: string, kept: Kept): Promise<boolean>;
97
- /** Ends a kept computer at its time: its row marked ending, only while it still reads `kept` (a claim that took it since
98
- * has it), then `end` (its delete), then the row marked ended. A row already ending (a process that died mid-way, a
99
- * delete that failed) is deleted again. A delete that fails leaves the row ending, for the janitor's next pass, and
100
- * throws its words. True when this call ended it. */
101
- export declare function endKept(settings: Pick<KeptSettings, "replaceIf">, runId: string, kept: Kept, end: () => Promise<void>): Promise<boolean>;
112
+ /**
113
+ * Writes `kept` as `runId`'s kept computer at the claim's park, by compare-and-set: from no row (putIfAbsent), or from the
114
+ * row as read (replaceIf). Its row as written, or undefined when the park keeps nothing.
115
+ *
116
+ * A row not yet ended that is pinned to another runner still there (`holders`, heldElsewhere: store KEPT_PREFIX's one
117
+ * meaning of there), that a claim is taking back (Kept.taking: it may be reaching the machine, or could not write what
118
+ * came of that), or that reads ending (its end begun, a claim that gave it back, a stop: whoever kept it, there or not)
119
+ * is never written over. Its end at its time (endKept) compares the row with the one its park wrote, and a janitor ends
120
+ * an ending row of a runner gone, so a row written over would leave its machine running with nothing to end it. The park
121
+ * keeps nothing then. Its row is marked ending where it is not yet: this claim went on without that machine, so no claim
122
+ * may take it back as the run's (a claim still reaching it then never uses it), and its end still finishes a row so
123
+ * marked. Any other row is replaced, as before: no runner, this claim's own runner, a runner gone (its row as its park
124
+ * wrote it), or one ended. A write that lost reads again, up to KEEP_TRIES times; past them the park keeps nothing.
125
+ * Throws where the store throws.
126
+ *
127
+ * Every write is under `claim`, the parking claim (Settings.putIfAbsent's and replaceIf's claim: the fence checked in the
128
+ * write's own transaction). A park runs before its claim's park commit, so a claim that lost the run by then (its lease
129
+ * ran out, and another claim may have parked and kept since) is refused (Fenced, thrown) and writes and marks nothing:
130
+ * the row the run's current claim wrote stays as it wrote it.
131
+ */
132
+ export declare function keepKept(settings: Pick<KeptSettings, "get" | "putIfAbsent" | "replaceIf">, runId: string, kept: Kept, holders: KeptHolders, claim?: Claim): Promise<Kept | undefined>;
133
+ /** What came of marking a kept row ending before its machine's delete (endingKept): `marked`, the row reads ending or
134
+ * ended now (or holds no keep the delete could take from a claim), so the delete may go on, and `kept` is the row as it
135
+ * reads ending, for finishedKept once that delete took its machine; `left`, the row is a later claim's keep, or a claim
136
+ * is taking it back, so its machine `id` is that claim's and is not deleted; `unmarked`, no try marked it (`why`), so
137
+ * its machine `id`, where the row was read, is not deleted either: it is left for the row's own time (its keeper's end,
138
+ * or a janitor's pass). */
139
+ export type KeptEnding = {
140
+ readonly kind: "marked";
141
+ readonly kept?: Kept;
142
+ } | {
143
+ readonly kind: "left";
144
+ readonly id?: string;
145
+ } | {
146
+ readonly kind: "unmarked";
147
+ readonly id?: string;
148
+ readonly why: string;
149
+ };
150
+ /** Marks `runId`'s kept row ending at the run's end (run-end-computers.ts), for the claim at `epoch` that ended the run:
151
+ * the run is final, so a machine kept at or before that claim has no user, whichever runner kept it or older claim is
152
+ * taking it back. No claim takes it back after, so the run's end deleting it and its keeper's end agree; the keeper's
153
+ * end at its time, or any janitor's pass, finishes the row. A row of a later claim (its machine made at a later epoch,
154
+ * or a later claim taking it back: a follow-up that queued the run again while this end waited on the store) is left
155
+ * as that claim wrote it, and so is its machine (`left`). A store that fails the mark is asked again (markEnding);
156
+ * `unmarked` past every try, and the run's end then deletes no machine the row names. */
157
+ export declare function endingKept(settings: Pick<KeptSettings, "get" | "replaceIf">, runId: string, epoch: number): Promise<KeptEnding>;
158
+ /** Marks `runId`'s kept row ending before a janitor's provider sweep deletes `machine`, the one the row kept when the
159
+ * sweep listed it (computer-janitor.ts thisServers). The sweep ends only a machine past its deadline or whose run is final, but the row's
160
+ * runner may still be there and its row unmarked (that runner died before its run's end ran, or the end could not mark
161
+ * it): marked first, no claim takes the machine back mid-delete. A row a claim is taking back, or one gone since the
162
+ * read (a claim took it), is a claim's: `left`, and the sweep leaves the machine. A row that keeps another machine
163
+ * now, or already reads ending or ended, needs no mark. */
164
+ export declare function endingKeptMachine(settings: Pick<KeptSettings, "get" | "replaceIf">, runId: string, machine: {
165
+ readonly provider: string;
166
+ readonly id: string;
167
+ }): Promise<KeptEnding>;
168
+ /** Takes `row` off `runId`'s row, only while it still reads so: a keep written for a park that never followed. */
169
+ export declare function dropKept(settings: Pick<KeptSettings, "removeIf">, runId: string, row: Kept): Promise<boolean>;
170
+ /** Marks `kept` taking on its row for the claim at `epoch` that resumes in time (Kept.taking), under `claim` (the store's
171
+ * fence: a claim that lost the run takes nothing): the row as marked when this call took it, undefined when its end (or
172
+ * another claim) had it first. The row stays while the claim reaches the machine: it holds it once keptTaken takes the
173
+ * mark off, and goes on without it through restoreKept. */
174
+ export declare function takeKept(settings: Pick<KeptSettings, "replaceIf">, runId: string, kept: Kept, epoch: number, claim?: Claim): Promise<Kept | undefined>;
175
+ /** The claim that marked `taking` (takeKept) reached its machine: the row taken off, only while it still reads so. True
176
+ * when the machine is the claim's; false when the row changed since (its end began at its time, a park or a stop marked
177
+ * it ending), and the claim must not use it. A write the store fails is tried again; past GIVE_BACK_TRIES it throws. */
178
+ export declare function keptTaken(settings: Pick<KeptSettings, "removeIf">, runId: string, taking: Kept): Promise<boolean>;
179
+ /** The claim that marked `taking` (takeKept) goes on without its machine (it could not reach it, or could not say it
180
+ * holds it): the row turned ending, whoever kept it and whether that runner is there or not, so no claim takes that
181
+ * machine back as the run's (nor does the claim rule pin the run to it). Its runner's end at its time (endKept, which
182
+ * finishes a row its park wrote that reads ending) or its janitor's next pass deletes it; once it is gone, or where any
183
+ * runner reaches it, any janitor's pass does. A row this claim took the mark off (it reached the machine, then failed
184
+ * before it could use it) is put back so, only while the key has none. A write the store fails is tried again. True when
185
+ * the row reads ending (or ended) after; false when it does not (the store failed every try, and the row is left marked
186
+ * taking, which is ended at its time all the same). */
187
+ export declare function restoreKept(settings: Pick<KeptSettings, "get" | "putIfAbsent" | "replaceIf">, runId: string, taking: Kept): Promise<boolean>;
188
+ /** Ends a kept computer at its time: its row marked ending, only while it still reads `kept`, or `kept` marked taking by
189
+ * a claim (one that is reaching it, or could not write what came of that: its time is over all the same, and the claim
190
+ * never uses it once the mark is gone, keptTaken), then `end` (its delete), then the row marked ended. A claim that took
191
+ * it since (the row gone) or a park that wrote another has it. A row already ending (a process that died mid-way, a
192
+ * delete that failed, a claim that gave it back, a park that kept nothing else or a stop: restoreKept, keepKept,
193
+ * endingKept) is deleted again. A delete that fails leaves the row ending, for the janitor's next pass, and throws its
194
+ * words. True when this call ended it. */
195
+ export declare function endKept(settings: Pick<KeptSettings, "get" | "replaceIf">, runId: string, kept: Kept, end: () => Promise<void>): Promise<boolean>;
196
+ /** Marks `runId`'s kept row ended once a delete that marked it ending (a run's end, a janitor's provider sweep: the
197
+ * `kept` of KeptEnding's `marked`) took its machine: only while the row still reads that ending row, so a row changed
198
+ * since is left. A row left ending refuses every later park of the run (keepKept) until a janitor's pass ends it, so a
199
+ * follow-up to a stopped run would keep nothing; ended, the next park writes over it. The delete's caller says only
200
+ * where its provider answered ok for that very machine, so a machine its list never showed (another runner's engine)
201
+ * keeps its row ending for its keeper to end. A row whose machine held the run's folder on Archil, its credential's
202
+ * disk named (Kept.disk), is marked ended only once `revokeMount` removed that credential: an ended row is one no
203
+ * janitor pass removes a credential for, so one marked ended first would leave it valid for its ttl with no machine.
204
+ * Without `revokeMount`, or with one that throws, the row is left ending, and the janitor's kept pass (sweepKept)
205
+ * removes the credential and ends it. Never throws: a row left ending is still ended at its time. */
206
+ export declare function finishedKept(settings: Pick<KeptSettings, "replaceIf">, runId: string, kept: Kept, revokeMount?: KeptMountRevoke): Promise<boolean>;
207
+ /** Removes `runId`'s kept row at the run's end (run-end-computers.ts: the claim at `epoch` ended the run), after its
208
+ * deletes answered or its bound passed: one read of the row, then a remove only while it still reads as read. Removed
209
+ * only where it reads ended (its machine gone: this end's delete marked it so, finishedKept, or its keeper's end at its
210
+ * time or a janitor's pass did before) and was kept at or before `epoch`. Whoever ended it, the run is final, so no
211
+ * resume of this run is left to read it and say why its computer is new; removed, a follow-up that queues the run again
212
+ * reads no keep and never says that lapse. A row that reads ending (a delete not done or not proven), none, and a later
213
+ * claim's keep are left. True when removed; false when left, or when the read or the remove failed. Never throws. */
214
+ export declare function forgetEnded(settings: Pick<KeptSettings, "get" | "removeIf">, runId: string, epoch: number): Promise<boolean>;
215
+ /** Removes run `runId`'s Archil mount credentials of `kept`'s claim epoch and earlier, by their names, on the disk its
216
+ * row names (computer-janitor.ts keptMountRevoke): what every end of a row kept on Archil asks before it marks the row
217
+ * ended (sweepKept, finishedKept). Throws where the remove failed. `signal`: aborted to cut its calls to Archil (the
218
+ * janitor's bound passed). */
219
+ export type KeptMountRevoke = (runId: string, kept: Kept, signal?: AbortSignal) => Promise<void>;
102
220
  /** What the janitor's pass over the kept computers did: the names it ended, the failures in words, and the earliest
103
221
  * time still ahead (its next wake), if any. */
104
222
  export type KeptSweep = {
@@ -109,16 +227,18 @@ export type KeptSweep = {
109
227
  /**
110
228
  * The janitor's pass over every kept row: one whose run is final in the store, or no longer there, has its computer
111
229
  * deleted (unless its time already ended it) and the row removed; one past its time, or left ending, is ended (endKept),
112
- * each delete bounded by `deleteMs` (KEPT_DELETE_MS). The rest are left, the earliest of their times answered as `next`.
230
+ * each delete bounded by `deleteMs` (KEPT_DELETE_MS), and one on Archil has its mount credentials removed (`revokeMount`).
231
+ * The rest are left, the earliest of their times answered as `next`.
113
232
  * `providerOf`: the provider a row names, made with this server's keys, or undefined when this server can't make it (its
114
233
  * keys gone): that row is left and said. A row pinned to a runner other than this one (`self`) that is still there under
115
- * the row's incarnation (`runners`, seen within PRESENCE_STALE_MS) is left whatever its time or its run: only that
234
+ * the row's incarnation (`runners`, seen within RUNNER_STALE_MS) is left whatever its time or its run: only that
116
235
  * runner's engine or hub has its machine, so a delete from here would find nothing, mark it ended and leak the machine.
117
236
  * That runner's own timer, or its janitor, ends it; once it is gone the row is ended here as any other. Never throws.
118
237
  */
119
238
  export declare function sweepKept(deps: {
120
239
  readonly settings: KeptSettings;
121
240
  readonly runs: Pick<Store["runs"], "get">;
241
+ /** Now on the store's clock, the one each row's `until` is stamped on (Kept.until). */
122
242
  readonly now: number;
123
243
  readonly providerOf: (id: string) => Promise<ComputerProvider | undefined>;
124
244
  readonly deleteMs?: number;
@@ -130,6 +250,12 @@ export declare function sweepKept(deps: {
130
250
  readonly runners?: Pick<Runners, "live">;
131
251
  /** The runner this sweep runs in (its name and presence incarnation): the rows pinned to it are its own to end. */
132
252
  readonly self?: KeptHolder;
253
+ /** Removes run `runId`'s Archil mount credentials of the row's claim epoch and earlier, by their names: asked after
254
+ * the delete of a row whose computer held the run's folder on Archil, within the same bound. No claim removes that
255
+ * credential once the janitor ends the row (a stop takes no row; a resume that starts no computer never reads it).
256
+ * One that throws leaves the row ending, for the next pass. Handed a signal aborted once that bound passes, cutting its
257
+ * calls to Archil. */
258
+ readonly revokeMount?: KeptMountRevoke;
133
259
  }): Promise<KeptSweep>;
134
260
  /** Deletes the kept computer through its provider; one already gone (its run's end let it go, run-end-computers.ts, or
135
261
  * its vendor ended it) is as good as deleted. Throws the provider's words on any other failure. True when the