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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
@@ -12,7 +12,7 @@ import { watchCommandsAt, wakeCommands } from "../command-wake.js";
12
12
  import { claimFence, storeNow } from "../fence.js";
13
13
  import { JOURNAL_FIRST_ID, RunStorage } from "../journal/storage.js";
14
14
  import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
15
- import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, LEARNING_LEDGER, LEARNING_LEDGER_AGENT, LEARNING_SPEND, LEARNING_SPEND_AGENT, LEARNING_SPEND_OF_RUN, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUN_LAUNCH_CENSUS, RUN_LAUNCH_CENSUS_PENDING, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, TRIGGERS_TEMPLATE_ID } from "../schema.js";
15
+ import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, LEARNING_LEDGER, LEARNING_LEDGER_ADDED, LEARNING_LEDGER_AGENT, LEARNING_LEDGER_BY_HAND, LEARNING_SPEND, LEARNING_SPEND_AGENT, LEARNING_SPEND_OF_RUN, ledgerUpgrade, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUN_LAUNCH_CENSUS, RUN_LAUNCH_CENSUS_ERASED, RUN_LAUNCH_CENSUS_ERASED_MADE, RUN_LAUNCH_CENSUS_SETTLE, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, STORE_META_LEDGER_BACKFILLED, TRIGGERS_TEMPLATE_ID } from "../schema.js";
16
16
  import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, FiringMoved, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
17
17
  /** The run a launch body is made from (Runs.madeFrom): the run whose input it replays (`replay.of`) or audits (`audit.of`). */
18
18
  const madeOf = (body) => {
@@ -32,9 +32,11 @@ const seqOf = (cursor) => {
32
32
  import { cleanText, settledBody } from "../dialect.js";
33
33
  import { inMemory } from "./memory.js";
34
34
  import { Connection, DEFAULT_BUSY_TIMEOUT_MS } from "./connection.js";
35
- import { applyRunPatch, EXACT_COST_USD, NOT_A_LEARNING_RUN, recordLedger, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
35
+ import { applyRunPatch, backfillLedger, BY_HAND_BEFORE, EXACT_COST_USD, NOT_A_LEARNING_RUN, recordLedger, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
36
36
  import { launchDiskOf, readableJson, readLaunch, readLearningStarts, readSeededBefore, readUsageMetadata, writeLaunch, writeLaunchSealed } from "./run-launch.js";
37
37
  import { canonical } from "../agent-body.js";
38
+ import { mcpRecordKeys } from "../mcp-record-keys.js";
39
+ import { workflowCallsIn } from "../../learning-cost.js";
38
40
  import { readProjectCheckpoints } from "./project-checkpoints.js";
39
41
  import { aadOf, sealedAt } from "../seal.js";
40
42
  /** Registry writers UPDATE/DELETE this same row, so a prepared cutover and a credential/catalog edit serialize. */
@@ -72,6 +74,10 @@ export const STORE_FILE = "store.sqlite";
72
74
  /** No audit's shadow run (learn/audit.ts SHADOW_PREFIX "audit."): the prefix compared as it is, which LIKE does not on
73
75
  * SQLite (it folds case). */
74
76
  const NOT_A_SHADOW_RUN = "substr(runs.id, 1, 6) <> 'audit.'";
77
+ /** A runs list's `model` (ListedFilter.model, `provider/model`) as SQL taking the model as its one `?`: the runs that sent at
78
+ * least one request to it, a key of the requests their metrics count per model (metrics.models), exactly (no prefix, no case
79
+ * folding). A run with no metrics yet sent none. */
80
+ const runUsedModel = (d) => d.jsonObjectHasKey("runs.metrics", ["models"]);
75
81
  /** A runner holds the run's claim at `now` (SQL), and the run is not over. */
76
82
  const heldAt = (now) => `(runs.runner IS NOT NULL AND runs.claimed_until >= ${now} AND runs.state NOT IN ('ended', 'stopped', 'failed'))`;
77
83
  /** The run's listing is behind at `now` (SQL; its parameters twice, `params`): built before the latest write that moved
@@ -154,8 +160,9 @@ const claimableIn = (d, n, claimer) => {
154
160
  };
155
161
  };
156
162
  /** The run's computer is kept at its park (its KEPT_PREFIX row) pinned to a runner other than `claimer` that is still
157
- * there under the incarnation the row names, at the deadlines' clock `n`: its runners row seen within RUNNER_STALE_MS,
158
- * claiming (refused NULL); the keep neither ending nor ended, and its `until` ahead. That runner's Docker engine or
163
+ * there (KEPT_PREFIX says what that means: its runners row seen within RUNNER_STALE_MS at the deadlines' clock `n`,
164
+ * under the incarnation the row names) and claiming (refused NULL); the keep neither ending nor ended, and its `until`
165
+ * ahead, on the same clock it was stamped on. That runner's Docker engine or
159
166
  * attach hub holds the machine, so only it can take it back (workspace/computer-kept.ts pinnedOf); once any of these
160
167
  * stops holding, any runner claims the run. Read in the claim's own statement, so no check-then-act gap. A row with no
161
168
  * runner (a computer any runner reaches: an exec vendor's, a phone; or one an earlier build kept) pins nothing. */
@@ -267,6 +274,9 @@ async function versionOf(db) {
267
274
  * (webhook.json, webhook-outbox.json) do not refuse the directory either: nothing reads them, and the webhook, now in
268
275
  * the store, is set again. */
269
276
  const EARLIER_ROOT_FILES = ["mcp-servers.json", "triggers.json", "tool-keys.json", "trigger-secrets.json", ".door-token"];
277
+ /** The store's earlier versions the server upgrades in place at its open (openSqliteStore), which a runner waits for
278
+ * (StoreAwaitsServer); store-schema reports from the same set. */
279
+ export const SQLITE_UPGRADES = new Set([11, 12, 13, 14, 15]);
270
280
  /** The columns a runner of this build needs that an earlier build of this same version may not have: the server adds each
271
281
  * at its start (openSqliteStore), and a runner on a file without one waits for that server (StoreAwaitsServer, in `why`'s
272
282
  * words; exit 3). store-schema reads the same list, so its report says "waits" where the runner would. */
@@ -282,7 +292,7 @@ export const SQLITE_RUNNER_NEEDS = [
282
292
  { table: "hand_backs", columns: ["run_id"], why: "keep each runner's version and slots, and each hand-back (runners.version, runners.slots, hand_backs)" },
283
293
  { table: "run_attempts", columns: ["run_id"], why: "keep each claim's turn and attempt (run_attempts)" },
284
294
  // A run's end writes its ledger row and spend rows (run-patch.ts applyRunPatch) in its own transaction.
285
- { table: "learning_ledger", columns: ["run_id"], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
295
+ { table: "learning_ledger", columns: ["run_id", ...Object.keys(LEARNING_LEDGER_ADDED)], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
286
296
  { table: "learning_spend", columns: ["run_id"], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
287
297
  ];
288
298
  /** What a runner of this build waits for on a file of this version (SQLITE_RUNNER_NEEDS' first missing column's `why`),
@@ -420,8 +430,10 @@ export async function openSqliteStore(options) {
420
430
  // it. Version 12 names no minting runner on a machine's token and keeps no runner's relay: the server adds them
421
431
  // (schema.ts relayUpgrade). Version 13 keeps no purge time on a run or an agent: the server adds them (schema.ts
422
432
  // purgeUpgrade). Version 14 keeps no disk on a run: the server adds it and writes each run's from its launch (schema.ts
423
- // diskUpgrade). A runner refuses 11 to 14 until that server has.
424
- const upgrading = found === 11 || found === 12 || found === 13 || found === 14;
433
+ // diskUpgrade). Version 15 keeps each ledger row's epoch: the server repairs the rows that release could leave wrong
434
+ // and drops it (the ledger's step below, then ledgerUpgrade). A runner refuses 11 to 15 until that server has, and a
435
+ // runner of 15, whose end writes the epoch, refuses 16 (SchemaVersionUnknown), or stops at its next floor read.
436
+ const upgrading = found !== null && SQLITE_UPGRADES.has(found);
425
437
  if (upgrading && role === "runner")
426
438
  throw new StoreAwaitsServer(`bring this store from version ${found} to ${SCHEMA_VERSION}`);
427
439
  if (found !== SCHEMA_VERSION && !upgrading)
@@ -458,12 +470,20 @@ export async function openSqliteStore(options) {
458
470
  await connection.write([{ sql: RUNS_LABELS }], { full: true });
459
471
  }
460
472
  // An earlier build of this version kept no census on a run's launch (schema.ts RUN_LAUNCH_CENSUS): the server adds the
461
- // column, nullable, every run ended before reading as never handed a secret, and marks each launch that holds one now
462
- // as pending (store.ts CENSUS_PENDING). A runner writes it at each end, so it waits for that server.
473
+ // column, nullable: every run ended before reads as never handed a secret, and a launch that holds one now as not yet
474
+ // counted (its end counts it). A runner writes it at each end, so it waits for that server.
463
475
  if (!(await connection.all("SELECT name FROM pragma_table_info('run_launch')")).some((column) => column.name === "census")) {
464
476
  if (role === "runner")
465
477
  throw new StoreAwaitsServer("add each run's census");
466
- await connection.write([{ sql: RUN_LAUNCH_CENSUS }, { sql: RUN_LAUNCH_CENSUS_PENDING }], { full: true });
478
+ await connection.write([{ sql: RUN_LAUNCH_CENSUS }], { full: true });
479
+ }
480
+ // A store no server of this build opened yet holds no RUN_LAUNCH_CENSUS_ERASED (an end that erases sealed bytes with
481
+ // no census, as an earlier runner's does, writes "unscanned"). The server makes it, and in the same write settles each
482
+ // "pending" 0.1.0-beta.57 left (RUN_LAUNCH_CENSUS_SETTLE), so a run live at the upgrade is counted at its end. Every
483
+ // later open reads only that the trigger is there. A runner leaves both: an end over a "pending" writes the marker,
484
+ // and its files are withheld, never read uncut.
485
+ if (role === "server" && (await connection.all(RUN_LAUNCH_CENSUS_ERASED_MADE)).length === 0) {
486
+ await connection.write([{ sql: RUN_LAUNCH_CENSUS_SETTLE }, { sql: RUN_LAUNCH_CENSUS_ERASED }], { full: true });
467
487
  }
468
488
  // An earlier build of this version kept no package mark on a trigger (schema.ts TRIGGERS_TEMPLATE_ID): the server adds
469
489
  // the column, nullable, every trigger made before reading as no package's. A runner reads each trigger through it, so
@@ -491,8 +511,12 @@ export async function openSqliteStore(options) {
491
511
  throw new StoreAwaitsServer("keep each claim's turn and attempt (run_attempts)");
492
512
  }
493
513
  // A run's end writes its ledger row and spend rows (schema.ts LEARNING_LEDGER, LEARNING_SPEND) in its own transaction:
494
- // a runner waits for the server that adds the tables (STORE_DDL at its start).
495
- if (role === "runner" && (await connection.all("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name IN ('learning_ledger', 'learning_spend')")).length < 2) {
514
+ // a runner waits for the server that adds the tables (STORE_DDL at its start) and their columns (LEARNING_LEDGER_ADDED).
515
+ // The `epoch` version 15 kept on the ledger, which this build's end does not write, is the version's: a runner
516
+ // refuses 15 above.
517
+ const metaColumns = new Set((await connection.all("SELECT name FROM pragma_table_info('store_meta')")).map((column) => column.name));
518
+ const ledgerColumns = new Set((await connection.all("SELECT name FROM pragma_table_info('learning_ledger')")).map((column) => column.name));
519
+ if (role === "runner" && ((await connection.all("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name IN ('learning_ledger', 'learning_spend')")).length < 2 || Object.keys(LEARNING_LEDGER_ADDED).some((column) => !ledgerColumns.has(column)))) {
496
520
  throw new StoreAwaitsServer("write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)");
497
521
  }
498
522
  // The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
@@ -531,10 +555,13 @@ export async function openSqliteStore(options) {
531
555
  { sql: COMPUTER_INTERVALS_RUN },
532
556
  // Nor any claim's turn and attempt (schema.ts RUN_ATTEMPTS): a claim made before it has no row.
533
557
  { sql: RUN_ATTEMPTS },
534
- // Nor any learning ledger (schema.ts LEARNING_LEDGER, LEARNING_SPEND): a run that ended before it has no row, and
535
- // its reader records it from its run row.
558
+ // Nor any learning ledger (schema.ts LEARNING_LEDGER, LEARNING_SPEND; version 15's, with each row's `epoch`, is
559
+ // repaired and its epoch dropped by ledgerUpgrade below). Nor the mark that every ended run has its row
560
+ // (STORE_META_LEDGER_BACKFILLED), nor the by-hand index (LEARNING_LEDGER_BY_HAND).
561
+ ...(metaColumns.has("ledger_backfilled") ? [] : [{ sql: STORE_META_LEDGER_BACKFILLED }]),
536
562
  { sql: LEARNING_LEDGER },
537
563
  { sql: LEARNING_LEDGER_AGENT },
564
+ { sql: LEARNING_LEDGER_BY_HAND },
538
565
  { sql: LEARNING_SPEND },
539
566
  { sql: LEARNING_SPEND_AGENT },
540
567
  { sql: LEARNING_SPEND_OF_RUN },
@@ -552,6 +579,13 @@ export async function openSqliteStore(options) {
552
579
  const runnersMissing = Object.entries(RUNNERS_ADDED).filter(([column]) => !runnersNow.has(column)).map(([, sql]) => ({ sql }));
553
580
  if (runnersMissing.length > 0)
554
581
  await connection.write(runnersMissing, { full: true });
582
+ // A learning_ledger an earlier build of this version made keeps no calls (schema.ts LEARNING_LEDGER_ADDED): added
583
+ // where missing, its rows' calls none until their run's next end. Before the open's backfill (backfillLedger below),
584
+ // whose rows recordLedger writes with their calls.
585
+ const ledgerNow = new Set((await connection.all("SELECT name FROM pragma_table_info('learning_ledger')")).map((column) => column.name));
586
+ const ledgerMissing = Object.entries(LEARNING_LEDGER_ADDED).filter(([column]) => !ledgerNow.has(column)).map(([, sql]) => ({ sql }));
587
+ if (ledgerMissing.length > 0)
588
+ await connection.write(ledgerMissing, { full: true });
555
589
  await backfillNativeCommandOwners(connection);
556
590
  if (found === 11) {
557
591
  const present = new Set((await connection.all("SELECT name FROM pragma_table_info('runs')")).map((column) => column.name));
@@ -561,12 +595,16 @@ export async function openSqliteStore(options) {
561
595
  const minted = new Set((await connection.all("SELECT name FROM pragma_table_info('minted_tokens')")).map((column) => column.name));
562
596
  await connection.write(relayUpgrade(minted).map((sql) => ({ sql })), { full: true });
563
597
  }
564
- if (upgrading) {
598
+ if (upgrading && found !== null) {
565
599
  const named = async (table) => new Set((await connection.all(`SELECT name FROM pragma_table_info('${table}')`)).map((column) => column.name));
566
- if (found !== 14)
600
+ if (found <= 13)
567
601
  await connection.write(purgeUpgrade(await named("runs"), await named("agents")).map((sql) => ({ sql })), { full: true });
568
- await connection.write(diskUpgrade(await named("runs")).map((sql) => ({ sql })), { full: true });
602
+ if (found <= 14)
603
+ await connection.write(diskUpgrade(await named("runs")).map((sql) => ({ sql })), { full: true });
604
+ await connection.write(ledgerUpgrade(await named("learning_ledger")).map((sql) => ({ sql })), { full: true });
569
605
  }
606
+ // Every run an earlier build ended gets its ledger row once, here, on the schema this build reads.
607
+ await backfillLedger(connection, options.now ?? Date.now);
570
608
  }
571
609
  }
572
610
  catch (error) {
@@ -1406,7 +1444,7 @@ class SqliteStore {
1406
1444
  },
1407
1445
  // A list's page from the rows alone: filtered, ordered and cut to the page in the query, one read whatever the number
1408
1446
  // of runs, each row with its listing (schema.ts RUN_LISTING_COLUMNS) and its agent's archive time.
1409
- listed: async ({ agentId, revisionId, labels, source, archived, status, going, after, limit, offset = 0 }) => {
1447
+ listed: async ({ agentId, revisionId, labels, source, startedFrom, startedBefore, model, archived, status, going, after, limit, offset = 0 }) => {
1410
1448
  const n = clock();
1411
1449
  const behind = listingBehind(n.sql);
1412
1450
  // Neither a built-in learning run nor an audit's shadow run (learn/audit.ts SHADOW_PREFIX, matched as it is, case and all).
@@ -1422,6 +1460,13 @@ class SqliteStore {
1422
1460
  where.push("runs.imported_from IS NULL");
1423
1461
  else if (source !== undefined)
1424
1462
  (where.push(`${d.jsonText("runs.imported_from", ["source"])} = ?`), params.push(source));
1463
+ // The window [startedFrom, startedBefore): a run started at its start is in it, one started at its end is not.
1464
+ if (startedFrom !== undefined)
1465
+ (where.push("runs.started_at >= ?"), params.push(startedFrom));
1466
+ if (startedBefore !== undefined)
1467
+ (where.push("runs.started_at < ?"), params.push(startedBefore));
1468
+ if (model !== undefined)
1469
+ (where.push(runUsedModel(d)), params.push(model));
1425
1470
  where.push(`COALESCE(runs.archived_at, agents.archived_at) IS ${archived ? "NOT NULL" : "NULL"}`, "runs.purged_at IS NULL");
1426
1471
  if (status !== undefined)
1427
1472
  (where.push("runs.list_status = ?"), params.push(status));
@@ -1711,6 +1756,10 @@ class SqliteStore {
1711
1756
  * writes or removes the row, so an owner's save, which drops the mark in the transaction that writes its row
1712
1757
  * (dropTokensMark), never lands in between. */
1713
1758
  const recordJson = readableJson(d, "settings.value");
1759
+ /** A new row's created_at, its two `?` now and three the name's record keys (mcpRecordKeys) then now again: now, or past
1760
+ * every `of` the name's records still hold, even within its millisecond or on a clock stepped back. created_at is the
1761
+ * row's identity (the `of` its records name): a record about an earlier row of the name is never a later row's. */
1762
+ const madeAfterRecords = `${d.greatest}(${d.bigintParam}, COALESCE((SELECT MAX(${d.jsonNumber(recordJson, ["of"])}) FROM settings WHERE settings.key IN (?, ?, ?)), ${d.bigintParam} - 1) + 1)`;
1714
1763
  const tokensMarked = `EXISTS (SELECT 1 FROM settings WHERE settings.key = ? AND ${d.jsonText(recordJson, ["by"])} = 'token' AND ${d.jsonValue(recordJson, ["of"])} = CAST(mcp_servers.created_at AS TEXT))`;
1715
1764
  /** A write of the saved server `name` that the token's mark decides (McpTokensMark, McpOwnersMark): one transaction that
1716
1765
  * first holds the server's lock. SQLite's one writer holds it already; on Postgres it makes the token's statement wait
@@ -1745,7 +1794,8 @@ class SqliteStore {
1745
1794
  const left = sealed !== null && typeof tokenLeftMs === "number" && Number.isFinite(tokenLeftMs) ? tokenLeftMs : null;
1746
1795
  const stamp = clock();
1747
1796
  // updated_at defaults to now (a save or a sign-in); a refresh passes the kept one so it is not read as an edit.
1748
- // listed_at is the tools' listing time, now unless given.
1797
+ // listed_at is the tools' listing time, now unless given. A save's moves past the row's own, in the statement that
1798
+ // writes it (lastEdit), even within its millisecond: a refresh that read the row compares it, and must see the save.
1749
1799
  const updated = updatedAt ?? at;
1750
1800
  const listed = listedAt ?? at;
1751
1801
  // The credential's own time: now for a put that writes one, unless the caller says it kept the sealed one (its
@@ -1757,25 +1807,29 @@ class SqliteStore {
1757
1807
  const statement = expected !== undefined && expected !== null
1758
1808
  ? {
1759
1809
  sql: `UPDATE mcp_servers SET url = ?, auth = ?, protocol = ?, tools = ?, prices = ?, server_info = ?, instructions = ?, sealed = ?, refresh_holder = NULL, refresh_until = NULL,
1760
- updated_at = ?, listed_at = ?, credential_changed_at = ?, token_until = ${stamp.sql} + ${d.bigintParam}
1810
+ updated_at = ${lastEdit(updatedAt, "?")}, listed_at = ?, credential_changed_at = ?, token_until = ${stamp.sql} + ${d.bigintParam}
1761
1811
  WHERE name = ? AND auth = ? AND sealed IS ${expected.sealed ? "NOT NULL" : "NULL"} AND ${expected.changedAt === null ? "credential_changed_at IS NULL" : "credential_changed_at = ?"}${tokens ? ` AND ${tokensMarked}` : ""}
1762
1812
  RETURNING ${mcpServerColumnsAt(stamp)}`,
1763
1813
  params: [...values, updated, listed, credentialAt, ...stamp.params, left, name, expected.auth, ...(expected.changedAt === null ? [] : [expected.changedAt]), ...(tokens ? [tokens.record] : []), ...stamp.params],
1764
1814
  }
1765
1815
  : {
1766
- sql: `INSERT INTO mcp_servers (name, url, auth, protocol, tools, prices, server_info, instructions, sealed, created_at, updated_at, listed_at, credential_changed_at, token_until) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ${stamp.sql} + ${d.bigintParam})
1816
+ sql: `INSERT INTO mcp_servers (name, url, auth, protocol, tools, prices, server_info, instructions, sealed, created_at, updated_at, listed_at, credential_changed_at, token_until) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ${madeAfterRecords}, ?, ?, ?, ${stamp.sql} + ${d.bigintParam})
1767
1817
  ON CONFLICT (name) DO UPDATE SET url = excluded.url, auth = excluded.auth, protocol = excluded.protocol, tools = excluded.tools,
1768
- prices = excluded.prices, server_info = excluded.server_info, instructions = excluded.instructions, sealed = excluded.sealed, refresh_holder = NULL, refresh_until = NULL, updated_at = excluded.updated_at, listed_at = excluded.listed_at, credential_changed_at = excluded.credential_changed_at, token_until = excluded.token_until
1818
+ prices = excluded.prices, server_info = excluded.server_info, instructions = excluded.instructions, sealed = excluded.sealed, refresh_holder = NULL, refresh_until = NULL, updated_at = ${lastEdit(updatedAt, "excluded.updated_at")}, listed_at = excluded.listed_at, credential_changed_at = excluded.credential_changed_at, token_until = excluded.token_until
1769
1819
  ${expected === null ? "WHERE 1 = 0" : ""}
1770
1820
  RETURNING ${mcpServerColumnsAt(stamp)}`,
1771
- params: [name, ...values, at, updated, listed, credentialAt, ...stamp.params, left, ...stamp.params],
1821
+ params: [name, ...values, at, ...mcpRecordKeys(name), at, updated, listed, credentialAt, ...stamp.params, left, ...stamp.params],
1772
1822
  };
1773
1823
  const written = await writeMcpRow(name, statement, tokens, owns);
1774
1824
  return written && mcpServerOf(written);
1775
1825
  };
1826
+ /** A server row's updated_at as a write sets it to `value` (SQL): kept as given when the caller passes the one it read
1827
+ * (`given`, a refresh: not an edit), else past the row's own (mcp_servers.updated_at, the row before the write) by at
1828
+ * least 1 ms, so two saves in one millisecond are still two edits a compare-and-set tells apart. */
1829
+ const lastEdit = (given, value) => (given === undefined ? `${d.greatest}(${value}, mcp_servers.updated_at + 1)` : value);
1776
1830
  /** `statement`, the write of server `name`'s row, answering the row it wrote (RETURNING): alone, or, when the token's mark
1777
1831
  * decides it (`tokens`, `owns`), in one transaction under the server's lock (underMcpLock), the owner's dropping the
1778
- * mark once its row is written and only then. */
1832
+ * mark once its row is written and only then, the token's first save writing its record (`tokens.made`) there too. */
1779
1833
  const writeMcpRow = async (name, statement, tokens, owns) => {
1780
1834
  if (!tokens && !owns)
1781
1835
  return (await db.write([statement]))[0].rows[0];
@@ -1783,6 +1837,10 @@ class SqliteStore {
1783
1837
  const row = (await tx.step(statement)).rows[0];
1784
1838
  if (row && owns)
1785
1839
  await dropTokensMark(tx, owns, mcpServerOf(row).createdAt);
1840
+ if (row && tokens?.made) {
1841
+ const encoded = json(tokens.made(mcpServerOf(row)));
1842
+ await tx.run("INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value, connector_id = excluded.connector_id, updated_at = excluded.updated_at", tokens.record, encoded, nativeCommandOwner(tokens.record, encoded), now());
1843
+ }
1786
1844
  return row;
1787
1845
  });
1788
1846
  };
@@ -1794,16 +1852,19 @@ class SqliteStore {
1794
1852
  this.mcp = {
1795
1853
  put: async (row) => (await putServer(row, undefined)),
1796
1854
  putIfCredential: (row, expected, tokens, owns) => putServer(row, expected, tokens, owns),
1797
- // One statement compares the credential and writes, as keepRefreshed: no read between, so a refresh's keep never lands
1798
- // in a gap and is then written over. The credential's columns and the refresh lease are not in its SET.
1855
+ // One statement compares the row as read (its credential, address, auth type and last edit) and writes, as
1856
+ // keepRefreshed: no read between, so a refresh's keep never lands in a gap and is then written over, and a save with no
1857
+ // credential (the sealed column the same after it), whether it moved the row or only repriced it, is never written
1858
+ // back over: every save moves updated_at, past the row's own even within its millisecond (lastEdit). The credential's
1859
+ // columns and the refresh lease are not in its SET.
1799
1860
  rewrite: async ({ name, url, auth, protocol = null, tools, prices = null, serverInfo = null, instructions = null, listedAt, updatedAt }, seen, owns) => {
1800
1861
  const at = now();
1801
1862
  const stamp = clock();
1802
1863
  const row = await writeMcpRow(name, {
1803
- sql: `UPDATE mcp_servers SET url = ?, auth = ?, protocol = ?, tools = ?, prices = ?, server_info = ?, instructions = ?, updated_at = ?, listed_at = ?
1804
- WHERE name = ? AND ${d.nullSafeEquals("sealed")}
1864
+ sql: `UPDATE mcp_servers SET url = ?, auth = ?, protocol = ?, tools = ?, prices = ?, server_info = ?, instructions = ?, updated_at = ${lastEdit(updatedAt, "?")}, listed_at = ?
1865
+ WHERE name = ? AND ${d.nullSafeEquals("sealed")} AND url = ? AND auth = ? AND updated_at = ?
1805
1866
  RETURNING ${mcpServerColumnsAt(stamp)}`,
1806
- params: [url, auth, protocol, json(tools), json(prices), serverInfo === null ? null : json(serverInfo), instructions, updatedAt ?? at, listedAt ?? at, name, seen, ...stamp.params],
1867
+ params: [url, auth, protocol, json(tools), json(prices), serverInfo === null ? null : json(serverInfo), instructions, updatedAt ?? at, listedAt ?? at, name, seen.sealed, seen.url, seen.auth, seen.updatedAt, ...stamp.params],
1807
1868
  }, undefined, owns);
1808
1869
  return row && mcpServerOf(row);
1809
1870
  },
@@ -1972,15 +2033,17 @@ class SqliteStore {
1972
2033
  const rowsOf = runIds === undefined ? { sql: "", params: [] } : { sql: ` AND run_id IN (${list})`, params: [...runIds] };
1973
2034
  const spendOf = runIds === undefined ? { sql: "", params: [] } : { sql: ` AND (run_id IN (${list}) OR of_run IN (${list}))`, params: [...runIds, ...runIds] };
1974
2035
  const text = "CAST(NULL AS TEXT)", whole = "CAST(NULL AS BIGINT)", usd = "CAST(NULL AS DOUBLE PRECISION)";
1975
- const parts = await db.all(`SELECT 'row' AS part, run_id, agent_id, started_at, path, workflow, digest, not_served, job_usd, look_back_usd, cost, epoch, ${text} AS kind, ${whole} AS round, ${text} AS of_run, ${usd} AS usd
2036
+ const parts = await db.all(`SELECT 'row' AS part, run_id, agent_id, started_at, path, workflow, digest, not_served, job_usd, look_back_usd, cost, workflow_calls, ${text} AS kind, ${whole} AS round, ${text} AS of_run, ${usd} AS usd
1976
2037
  FROM learning_ledger WHERE agent_id = ?${rowsOf.sql}
1977
2038
  UNION ALL
1978
- SELECT 'spend' AS part, run_id, agent_id, ${whole}, ${text}, workflow, digest, ${text}, ${usd}, ${usd}, ${text}, ${whole}, kind, round, of_run, usd
2039
+ SELECT 'spend' AS part, run_id, agent_id, ${whole}, ${text}, workflow, digest, ${text}, ${usd}, ${usd}, ${text}, ${text}, kind, round, of_run, usd
1979
2040
  FROM learning_spend WHERE agent_id = ?${spendOf.sql}`, agentId, ...rowsOf.params, agentId, ...spendOf.params);
1980
2041
  const usdOf = (value) => (value === null ? null : Number(value));
1981
2042
  const rows = parts.filter((one) => one.part === "row").map((row) => ({
1982
2043
  runId: row.run_id, agentId: row.agent_id, startedAt: Number(row.started_at), path: row.path, workflow: row.workflow, digest: row.digest,
1983
- notServed: row.not_served, jobUsd: usdOf(row.job_usd), lookBackUsd: usdOf(row.look_back_usd), cost: row.cost, epoch: Number(row.epoch),
2044
+ notServed: row.not_served, jobUsd: usdOf(row.job_usd), lookBackUsd: usdOf(row.look_back_usd), cost: row.cost,
2045
+ // Its calls as its end wrote them (record), each checked again as read.
2046
+ workflowCalls: workflowCallsIn({ workflow_calls: JSON.parse(row.workflow_calls ?? "[]") }),
1984
2047
  }));
1985
2048
  const spend = parts.filter((one) => one.part === "spend").map((row) => ({
1986
2049
  runId: row.run_id, round: Number(row.round), agentId: row.agent_id, kind: row.kind, ofRun: row.of_run, workflow: row.workflow, digest: row.digest, usd: usdOf(row.usd),
@@ -1991,6 +2054,10 @@ class SqliteStore {
1991
2054
  spend: spend.sort((a, b) => byText(a.runId, b.runId) || byText(a.kind, b.kind) || a.round - b.round),
1992
2055
  };
1993
2056
  },
2057
+ byHandBefore: async (agentId, before, limit) => {
2058
+ const rows = await db.all(BY_HAND_BEFORE, agentId, before.startedAt, before.id, limit);
2059
+ return rows.map((row) => ({ id: row.run_id, startedAt: Number(row.started_at), jobUsd: Number(row.job_usd) }));
2060
+ },
1994
2061
  };
1995
2062
  this.settings = {
1996
2063
  get: async (key) => {
@@ -2001,7 +2068,7 @@ class SqliteStore {
2001
2068
  const encoded = json(value);
2002
2069
  await db.write([{ sql: "INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value, connector_id = excluded.connector_id, updated_at = excluded.updated_at", params: [key, encoded, nativeCommandOwner(key, encoded), now()] }]);
2003
2070
  },
2004
- putIfAbsent: async (key, value, capacity) => {
2071
+ putIfAbsent: async (key, value, capacity, claim) => {
2005
2072
  const encoded = json(value);
2006
2073
  if (capacity !== undefined) {
2007
2074
  if (typeof capacity.prefix !== "string" || !capacity.prefix || capacity.prefix.includes("\0") || !key.startsWith(capacity.prefix) || !Number.isSafeInteger(capacity.limit) || capacity.limit < 1)
@@ -2010,6 +2077,9 @@ class SqliteStore {
2010
2077
  // SQLite holds its writer lock already; Postgres holds this schema's prefix lock until commit. The count
2011
2078
  // and insertion cannot interleave with another bounded insertion, even through an independent store handle.
2012
2079
  await d.lockKey(tx, `settings.capacity:${capacity.prefix}`);
2080
+ // Settings precede the run's claim lock, as in replaceIf.
2081
+ if (claim)
2082
+ await underClaim(tx, claim, now);
2013
2083
  const existing = await tx.get("SELECT value FROM settings WHERE key = ?", key);
2014
2084
  if (existing !== undefined)
2015
2085
  return JSON.parse(existing.value);
@@ -2031,6 +2101,14 @@ class SqliteStore {
2031
2101
  return saved === undefined ? undefined : JSON.parse(saved.value);
2032
2102
  });
2033
2103
  }
2104
+ // Under a claim: the claim's fence and the insert in one transaction, so a claim that lost the run writes nothing.
2105
+ if (claim)
2106
+ return db.transaction(async (tx) => {
2107
+ const at = await underClaim(tx, claim, now);
2108
+ await tx.run("INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO NOTHING", key, encoded, nativeCommandOwner(key, encoded), at);
2109
+ const saved = await tx.get("SELECT value FROM settings WHERE key = ?", key);
2110
+ return saved === undefined ? undefined : JSON.parse(saved.value);
2111
+ });
2034
2112
  await db.write([{ sql: "INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO NOTHING", params: [key, encoded, nativeCommandOwner(key, encoded), now()] }]);
2035
2113
  const row = await db.get("SELECT value FROM settings WHERE key = ?", key);
2036
2114
  return row === undefined ? undefined : JSON.parse(row.value);
@@ -2860,7 +2938,11 @@ class SqliteStore {
2860
2938
  VALUES (?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING ${this.#db.dialect.insertedRow} AS inserted_rowid, ${RUN_COLUMNS}`, run.id, run.agentId, run.revisionId, state, run.costUsd ?? null, run.metrics === undefined || run.metrics === null ? null : json(run.metrics), run.summary ?? null, run.outcome ?? null, JSON.stringify(run.importedFrom), launchDiskOf(run.launch), run.startedAt, run.endedAt ?? at);
2861
2939
  await writeLaunch(tx, run.id, run.launch, at);
2862
2940
  await new RunStorage(this.#db, { runId: run.id, epoch: 0 }, this.#now).applyIn(tx, run.transcript, row.inserted_rowid ?? "this-transaction");
2863
- return runOf(row);
2941
+ // Its ledger row, as an end writes one (applyRunPatch), in this same commit.
2942
+ const imported = runOf(row);
2943
+ if (FINAL_STATES.includes(imported.state))
2944
+ await recordLedger(tx, imported, at);
2945
+ return imported;
2864
2946
  });
2865
2947
  }
2866
2948
  async take(claim, commandId, outcome = "taken", reason) {
@@ -21,9 +21,7 @@ import { migrationsIn, runnerFloorOf, runnerOn } from "./postgres/migrate.js";
21
21
  import { STORE_CONNECT_TIMEOUT_MS } from "./postgres/connection.js";
22
22
  import { storePlace, storeTarget } from "./open.js";
23
23
  import { SCHEMA_VERSION } from "./schema.js";
24
- import { earlierVersionIn, runnerWaitsFor, STORE_FILE } from "./sqlite/store.js";
25
- /** The SQLite store's versions the server upgrades in place (sqlite/store.ts openSqliteStore). */
26
- const SQLITE_UPGRADES = new Set([11, 12, 13, 14]);
24
+ import { earlierVersionIn, runnerWaitsFor, SQLITE_UPGRADES, STORE_FILE } from "./sqlite/store.js";
27
25
  /** What a build that knows `build` does with a store at `state`, on `kind`. `earlier`: the data directory holds an earlier
28
26
  * version's files (SQLite only), which this build's server refuses to start beside (StoreFromEarlierVersion). `awaits`:
29
27
  * on SQLite at this build's version, a column this build's runner needs that the file lacks (SQLITE_RUNNER_NEEDS), which
@@ -34,7 +32,8 @@ export function storeSchemaReport(target, state, build, earlier = false, awaits
34
32
  ? "refuses"
35
33
  : version === null ? "sets up" : version === build ? "opens" : version > build ? "refuses" : target.kind === "postgres" || SQLITE_UPGRADES.has(version) ? "migrates" : "refuses";
36
34
  // A SQLite runner opens only its own version: its floor is the version (sqlite/store.ts schemaState).
37
- // On SQLite a runner waits only for a version its server upgrades in place (11-14), and refuses any other earlier one.
35
+ // On SQLite a runner waits only for a version its server upgrades in place (SQLITE_UPGRADES), and refuses any other
36
+ // earlier one.
38
37
  const runner = target.kind === "sqlite" && version !== null && version < build && !SQLITE_UPGRADES.has(version)
39
38
  ? "refused"
40
39
  : awaits && version === build ? "waits" : runnerOn(target.kind === "sqlite" ? { version, runnerFloor: version } : state, build);
@@ -1,5 +1,6 @@
1
1
  import type { Context } from "@earendil-works/chord/context";
2
2
  import type { Storage, StorageWrite } from "@earendil-works/pi-durable";
3
+ import type { Source } from "@parcha/agentrun-import";
3
4
  import type { JournalPage } from "./journal/storage.js";
4
5
  import type { MonidPinBody } from "./agent-body.js";
5
6
  import type { LedgerRow, SpendRow } from "../learn/ledger.js";
@@ -166,6 +167,11 @@ export interface ListedFilter {
166
167
  readonly labels?: RunLabels;
167
168
  /** Only runs imported from this source (imported_from.source), or with "live" the runs not imported. */
168
169
  readonly source?: string;
170
+ /** Only runs started at or after this time (ms), and before `startedBefore` (ms): the window [startedFrom, startedBefore). */
171
+ readonly startedFrom?: number;
172
+ readonly startedBefore?: number;
173
+ /** Only runs that sent at least one request to this model (`provider/model`), a key of their metrics' `models`, exactly. */
174
+ readonly model?: string;
169
175
  readonly archived: boolean;
170
176
  readonly status?: string;
171
177
  /** Only runs still going (no settled status on the row) whose listing is behind. */
@@ -212,7 +218,7 @@ export interface RunListing {
212
218
  }
213
219
  export declare function stoppedByPerson(run: Pick<RunRow, "state" | "outcome" | "importedFrom">, kind: string): boolean;
214
220
  /** The harness an imported run came from. */
215
- export type ImportSource = "claude-code" | "codex" | "pi";
221
+ export type ImportSource = Source;
216
222
  /** Where an imported run came from: the harness that ran it, and its own session id. `file` is the server's own record of
217
223
  * the session file an import read whole (the sha-256 of its path, never the path, with its size and mtime), so a later
218
224
  * import does not read an unchanged file again; it is internal and never shown on an answer. The unique import index keys
@@ -341,19 +347,12 @@ export interface RunLaunchInput {
341
347
  readonly body: unknown;
342
348
  readonly sealed?: Uint8Array | null;
343
349
  }
344
- /** The census a launch takes when sealed bytes are first written on it (RunLaunchRow.census): it holds secrets its caller
345
- * handed it, and no end has counted where they sit. An end erases them and writes its census in its place; an end that
346
- * wrote none (a runner from before the census, during a rolling deploy) leaves it, and an ended run's files under it are
347
- * withheld from a cut read, as under CENSUS_UNSCANNED. */
348
- export declare const CENSUS_PENDING: string;
349
- /** The census an end that erased a launch's sealed bytes writes when it has none made under them (RunLaunchRow.census), and
350
- * a message's seal writes over CENSUS_PENDING left by such an end: what the run was handed may be in its files, and
351
- * nothing says where. */
350
+ /** The census an end that erased a launch's sealed bytes writes when it has none made under them (RunLaunchRow.census): what
351
+ * the run was handed may be in its files, and nothing says where. */
352
352
  export declare const CENSUS_UNSCANNED: string;
353
353
  /** A run's launch as the store holds it: the body the runner reads at its claim, and its sealed bytes, which the store never
354
- * opens. `census`: null when its launch never held sealed bytes (none handed, or a run ended before the census was kept);
355
- * CENSUS_PENDING from when they were first written until an end counted them; then the JSON text the last end that
356
- * erased them wrote (RunPatch.census, run-census.ts), or CENSUS_UNSCANNED when that end had none made under them. */
354
+ * opens. `census`: null until an end erased its sealed bytes (none handed, none erased yet, or a run ended before the census
355
+ * was kept); then the JSON text the last end that erased them wrote (RunPatch.census, run-census.ts), or CENSUS_UNSCANNED when that end had none made under them. */
357
356
  export interface RunLaunchRow {
358
357
  readonly runId: string;
359
358
  readonly body: unknown;
@@ -470,16 +469,24 @@ export interface Learning {
470
469
  to: number;
471
470
  }): Promise<LearningSpend[]>;
472
471
  /** Agent `agentId`'s ledger (learn/ledger.ts), in one read (one snapshot of both tables): every run's row its end
473
- * recorded, oldest first, each with the end it was recorded for (`epoch`, its run's epoch then), and every spend row.
474
- * With `runIds`, those runs' rows alone and the spend rows they booked or that audit them (none for none). Written
475
- * only beside a run's end and a heal of its cost (run-patch.ts recordLedger); a purge or a delete of the run takes its
476
- * row and its spend. */
472
+ * recorded, oldest first, and every spend row. With `runIds`, those runs' rows alone and the spend rows they booked or
473
+ * that audit them (none for none). Written only beside a run's end and a heal of its cost (run-patch.ts recordLedger);
474
+ * a purge or a delete of the run takes its row and its spend. */
477
475
  ledger(agentId: string, runIds?: readonly string[]): Promise<{
478
- rows: (LedgerRow & {
479
- readonly epoch: number;
480
- })[];
476
+ rows: LedgerRow[];
481
477
  spend: SpendRow[];
482
478
  }>;
479
+ /** Agent `agentId`'s newest `limit` ledger rows on the `agent` path at a known cost, of runs before run `before` in
480
+ * runs.list's order (started_at, then id), on no named disk, neither imported nor archived, newest first: the money
481
+ * rule's by-hand side read past its window (store-reads/learning.ts pastRunsRead). One read. */
482
+ byHandBefore(agentId: string, before: {
483
+ readonly id: string;
484
+ readonly startedAt: number;
485
+ }, limit: number): Promise<{
486
+ readonly id: string;
487
+ readonly startedAt: number;
488
+ readonly jobUsd: number;
489
+ }[]>;
483
490
  }
484
491
  /** One run's learning end as GET /usage's learning meter counts it (Learning.spend). */
485
492
  export interface LearningSpend {
@@ -1459,9 +1466,13 @@ export type McpServerWrite = {
1459
1466
  * `of` is the row's created_at). An owner's save drops the mark in the transaction that writes its row (McpOwnersMark),
1460
1467
  * so a write that needs the mark never lands over the owner's save, whenever that save lands. The write that needs it
1461
1468
  * takes the server's lock first, so on Postgres its statement reads the record as the owner's committed transaction left
1462
- * it. */
1469
+ * it. `made`: the token's first save of the name, whose record (`made` of the row written) is written at `record` in the
1470
+ * transaction that writes the row, so no reader ever finds the token's new row without its mark. */
1463
1471
  export type McpTokensMark = {
1464
1472
  readonly record: string;
1473
+ readonly made?: (row: {
1474
+ createdAt: number;
1475
+ }) => unknown;
1465
1476
  };
1466
1477
  /** The owner's write over a saved server's row: in the transaction that writes the row, and only once the row is written,
1467
1478
  * the setting at `record` (the server's source record) loses the API token's mark (`by`) when it still says the token
@@ -1470,6 +1481,17 @@ export type McpTokensMark = {
1470
1481
  export type McpOwnersMark = {
1471
1482
  readonly record: string;
1472
1483
  };
1484
+ /** A row as a rewrite read it (Mcp.rewrite): its sealed credential, its address, its auth type and its last edit
1485
+ * (updatedAt). The rewrite lands only while the row still has all four, so it never writes back anything it read (an
1486
+ * address, an auth type, prices) over a save made since, even one that kept the address, auth type and credential. Every
1487
+ * save moves updatedAt past the row's own, even within its millisecond; a write that passes updatedAt (a refresh) keeps
1488
+ * the one it read. */
1489
+ export type McpRewriteSeen = {
1490
+ readonly sealed: Uint8Array | null;
1491
+ readonly url: string;
1492
+ readonly auth: string;
1493
+ readonly updatedAt: number;
1494
+ };
1473
1495
  export interface Mcp {
1474
1496
  /** The server's write: the server's row, inserted or replaced by name (its first save's time kept). An owner's save
1475
1497
  * clears any refresh lease and changes the credential, so a refresh in flight is dropped (keepRefreshed's `kept: false`)
@@ -1482,13 +1504,15 @@ export interface Mcp {
1482
1504
  * token's mark (McpTokensMark), in the same statement. `owns`: the owner's write, which drops the token's mark in the
1483
1505
  * same transaction once the row is written (McpOwnersMark). */
1484
1506
  putIfCredential(server: McpServerWrite, expected: McpCredentialMark, tokens?: McpTokensMark, owns?: McpOwnersMark): Promise<McpServerRow | undefined>;
1485
- /** An owner's rewrite of a row it read, its credential kept as it is (a tools refresh, a save that sends no new
1486
- * credential): the listing, prices, url and times written by a compare-and-set on the CREDENTIAL, iff the row is still
1487
- * saved and its sealed value is still `seen` (the one the owner read). The credential's columns (sealed, token_until,
1507
+ /** A rewrite of a row it read, its credential kept as it is (a tools refresh, a save that sends no new credential): the
1508
+ * listing, prices, url and times written by a compare-and-set on the row as `seen` (McpRewriteSeen), iff the row is
1509
+ * still saved, its sealed value is still the one read, it is still at the address and of the auth type read, and no
1510
+ * save has edited it since (its updated_at the one read). The credential's columns (sealed, token_until,
1488
1511
  * credential_changed_at) and any refresh lease are left as they are, so a runner's refresh in flight still keeps its
1489
- * set. undefined, writing nothing, when the credential changed meanwhile (a refresh kept a rotated set) or the row went:
1490
- * the caller reads it again and re-applies its change onto the fresh row, a bounded few times. `owns`: as
1491
- * putIfCredential's, the token's mark dropped in the same transaction once the row is written. */
1512
+ * set. undefined, writing nothing, when the credential changed meanwhile (a refresh kept a rotated set), a save landed
1513
+ * (one with no credential leaves the sealed column as it was, and may keep the address and auth type too), or the row
1514
+ * went: the caller reads it again and re-applies its change onto the fresh row while it still holds, a bounded few
1515
+ * times. `owns`: as putIfCredential's, the token's mark dropped in the same transaction once the row is written. */
1492
1516
  rewrite(server: {
1493
1517
  name: string;
1494
1518
  url: string;
@@ -1500,7 +1524,7 @@ export interface Mcp {
1500
1524
  instructions?: string | null;
1501
1525
  listedAt?: number;
1502
1526
  updatedAt?: number;
1503
- }, seen: Uint8Array | null, owns?: McpOwnersMark): Promise<McpServerRow | undefined>;
1527
+ }, seen: McpRewriteSeen, owns?: McpOwnersMark): Promise<McpServerRow | undefined>;
1504
1528
  /** Deletes the row, answering what it held as it went (McpRemoved); undefined when there was none. */
1505
1529
  remove(name: string): Promise<McpRemoved | undefined>;
1506
1530
  /** remove(), only while the server's credential is still `expected` (its mark as the remover read it), compared and
@@ -1563,11 +1587,13 @@ export interface Settings {
1563
1587
  /** Saves `value` under `key` only when the key has no row yet; the value saved after (this one, or the one there before).
1564
1588
  * With `capacity`, count and insert share a namespace lock and transaction across store handles. Every raw key under
1565
1589
  * the exact prefix counts, without decoding values. An existing key wins even at capacity; undefined means a new key
1566
- * was refused. The nonempty prefix must contain the key, and limit must be a positive safe integer. */
1590
+ * was refused. The nonempty prefix must contain the key, and limit must be a positive safe integer. With `claim`,
1591
+ * holds the run's shared row lock and checks its epoch/lease in the same transaction as the insert, as replaceIf
1592
+ * does: a stale claim throws Fenced and nothing is written. */
1567
1593
  putIfAbsent(key: string, value: unknown, capacity?: {
1568
1594
  readonly prefix: string;
1569
1595
  readonly limit: number;
1570
- }): Promise<unknown>;
1596
+ }, claim?: Claim): Promise<unknown>;
1571
1597
  /** Saves `value` under `key` only while its row still holds `was` (as get read it), in one statement: a compare-and-set,
1572
1598
  * so of two writers that read one row only one replaces it. True when it was replaced; false, with nothing written,
1573
1599
  * when the row changed since or is gone. With `claim`, holds the run's shared row lock and checks its epoch/lease in
@@ -1828,12 +1854,21 @@ export interface RunCapacity {
1828
1854
  /** How long a runner's row is kept once it stopped saying it is there (a runner that died without its close): its next
1829
1855
  * put removes every row older than this. */
1830
1856
  export declare const RUNNER_ROWS_KEPT_MS: number;
1831
- /** How old a runner's row can be and still count as there, on the store's clock (runner/presence.ts PRESENCE_STALE_MS:
1832
- * three renewals missed). The claim rule reads it for a kept computer's pin. */
1857
+ /** How old a runner's row can be and still count as there, on the store's clock: three of its renewals missed
1858
+ * (runner/presence.ts PRESENCE_RENEW_MS). Every reader of who is there uses it, the claim rule's kept computer pin
1859
+ * included. */
1833
1860
  export declare const RUNNER_STALE_MS = 30000;
1834
1861
  /** The settings key prefix of the computers kept at a run's park, one row per run (workspace/computer-kept.ts). A row
1835
1862
  * whose computer is pinned to the runner that kept it (its `runner` and `incarnation`) holds the run for that runner in
1836
- * the claim rule, while that runner is there under that incarnation and the keep lasts. */
1863
+ * the claim rule, while that runner is there under that incarnation and the keep lasts.
1864
+ *
1865
+ * "There", for a pinned row's runner, means one thing everywhere: its runners row seen within RUNNER_STALE_MS on the
1866
+ * store's clock, under the incarnation the row names, refusing claims or not. That runner holds the machine: no other
1867
+ * runner's janitor ends its row (computer-kept.ts heldElsewhere, in sweepKept), and a claim that took the row and could
1868
+ * not reach the machine puts the row back (computer-for-claim.ts reattach), so that runner's own end finds it.
1869
+ * The claim rule (sqlite/store.ts keptElsewhere) alone asks one thing more, that it is claiming (`refused` null): a
1870
+ * refusing runner would make the answer wait the whole keep for nothing, and its row is given back marked ending, so it
1871
+ * still ends its machine. */
1837
1872
  export declare const KEPT_PREFIX = "computer_kept:";
1838
1873
  /** Every runner's word that it is there (runner/presence.ts). */
1839
1874
  export interface Runners {