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

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 (522) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +417 -219
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-conformance-cli.d.ts +1 -0
  15. package/dist/attach-conformance-cli.js +18 -0
  16. package/dist/attach-conformance.d.ts +25 -0
  17. package/dist/attach-conformance.js +343 -0
  18. package/dist/attach-images.d.ts +15 -0
  19. package/dist/attach-images.js +59 -0
  20. package/dist/background.d.ts +0 -6
  21. package/dist/background.js +0 -28
  22. package/dist/box-image.d.ts +1 -97
  23. package/dist/box-image.js +4 -284
  24. package/dist/box-paths.d.ts +2 -7
  25. package/dist/box-paths.js +7 -13
  26. package/dist/box-settings.d.ts +0 -11
  27. package/dist/box-settings.js +4 -29
  28. package/dist/browser-commands.js +1 -1
  29. package/dist/browser-computer.d.ts +47 -3
  30. package/dist/browser-computer.js +286 -18
  31. package/dist/browser-cost.d.ts +1 -1
  32. package/dist/browser-live.d.ts +20 -8
  33. package/dist/browser-live.js +50 -27
  34. package/dist/browser-person.d.ts +19 -2
  35. package/dist/browser-person.js +55 -6
  36. package/dist/browser-wait-ended.d.ts +23 -0
  37. package/dist/browser-wait-ended.js +42 -0
  38. package/dist/cap.d.ts +12 -57
  39. package/dist/cap.js +20 -160
  40. package/dist/catalog.d.ts +1 -12
  41. package/dist/catalog.js +3 -33
  42. package/dist/cli.js +17 -26
  43. package/dist/composio-preset.d.ts +36 -0
  44. package/dist/composio-preset.js +179 -0
  45. package/dist/computer-attach.d.ts +125 -0
  46. package/dist/computer-attach.js +330 -0
  47. package/dist/computer-calls.d.ts +48 -0
  48. package/dist/computer-calls.js +126 -0
  49. package/dist/computer-channel.d.ts +57 -0
  50. package/dist/computer-channel.js +115 -0
  51. package/dist/computer-commands.d.ts +1 -1
  52. package/dist/computer-held-routes.d.ts +35 -0
  53. package/dist/computer-held-routes.js +106 -0
  54. package/dist/computer-held.d.ts +48 -0
  55. package/dist/computer-held.js +87 -0
  56. package/dist/computer-keys.d.ts +21 -1
  57. package/dist/computer-keys.js +53 -11
  58. package/dist/computer-live.d.ts +160 -0
  59. package/dist/computer-live.js +643 -0
  60. package/dist/computer-routes.d.ts +1 -4
  61. package/dist/computer-routes.js +3 -5
  62. package/dist/computer-setting.d.ts +2 -0
  63. package/dist/computer-setting.js +38 -1
  64. package/dist/computer-view.d.ts +24 -2
  65. package/dist/computer-view.js +51 -3
  66. package/dist/computer-viewer.d.ts +6 -0
  67. package/dist/computer-viewer.js +297 -0
  68. package/dist/computers.d.ts +79 -12
  69. package/dist/computers.js +147 -28
  70. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  71. package/dist/console/assets/index-DRN62V5v.css +1 -0
  72. package/dist/console/index.html +2 -2
  73. package/dist/docker-daemon.d.ts +2 -2
  74. package/dist/docker-daemon.js +2 -2
  75. package/dist/errors.js +5 -5
  76. package/dist/faux-computers.d.ts +9 -20
  77. package/dist/faux-computers.js +56 -24
  78. package/dist/files.d.ts +1 -9
  79. package/dist/files.js +1 -9
  80. package/dist/github-connection.d.ts +10 -2
  81. package/dist/github-connection.js +65 -2
  82. package/dist/github-faux.js +1 -1
  83. package/dist/github.d.ts +22 -2
  84. package/dist/github.js +42 -8
  85. package/dist/gpu-words.d.ts +14 -0
  86. package/dist/gpu-words.js +21 -0
  87. package/dist/graph-view.d.ts +3 -1
  88. package/dist/graph-view.js +25 -1
  89. package/dist/handed-values.d.ts +1 -1
  90. package/dist/handed-values.js +1 -1
  91. package/dist/harness-install.d.ts +60 -3
  92. package/dist/harness-install.js +322 -34
  93. package/dist/harness.d.ts +1 -0
  94. package/dist/harness.js +36 -2
  95. package/dist/host-tools.d.ts +9 -10
  96. package/dist/host-tools.js +7 -7
  97. package/dist/hosted-search.d.ts +5 -4
  98. package/dist/hosted-search.js +2 -7
  99. package/dist/import-sources.d.ts +10 -0
  100. package/dist/import-sources.js +44 -2
  101. package/dist/import.d.ts +3 -3
  102. package/dist/import.js +37 -6
  103. package/dist/index.d.ts +1 -3
  104. package/dist/index.js +1 -2
  105. package/dist/key-refusal.d.ts +1 -1
  106. package/dist/key-refusal.js +2 -2
  107. package/dist/learn/check.d.ts +11 -2
  108. package/dist/learn/check.js +124 -6
  109. package/dist/learn/commit.d.ts +43 -7
  110. package/dist/learn/commit.js +166 -22
  111. package/dist/learn/folder.d.ts +11 -0
  112. package/dist/learn/folder.js +37 -1
  113. package/dist/learn/general.d.ts +66 -0
  114. package/dist/learn/general.js +73 -0
  115. package/dist/learn/grade.d.ts +22 -1
  116. package/dist/learn/grade.js +107 -16
  117. package/dist/learn/index.d.ts +1 -1
  118. package/dist/learn/index.js +1 -1
  119. package/dist/learn/learning.sh +12 -1
  120. package/dist/learn/notes.d.ts +3 -0
  121. package/dist/learn/notes.js +3 -0
  122. package/dist/learn/reflect.d.ts +14 -2
  123. package/dist/learn/reflect.js +54 -30
  124. package/dist/learn/skills.d.ts +37 -5
  125. package/dist/learn/skills.js +60 -7
  126. package/dist/learned-nodes.d.ts +6 -2
  127. package/dist/learned-workflow.d.ts +43 -9
  128. package/dist/learned-workflow.js +128 -37
  129. package/dist/learning-batch.d.ts +283 -0
  130. package/dist/learning-batch.js +574 -0
  131. package/dist/learning-cost.d.ts +79 -0
  132. package/dist/learning-cost.js +69 -0
  133. package/dist/learning-evals.d.ts +33 -0
  134. package/dist/learning-evals.js +98 -0
  135. package/dist/learning-routes.d.ts +32 -4
  136. package/dist/learning-routes.js +48 -12
  137. package/dist/learning-words.d.ts +9 -0
  138. package/dist/learning-words.js +12 -2
  139. package/dist/learning.d.ts +39 -19
  140. package/dist/learning.js +88 -46
  141. package/dist/live/stream.js +6 -3
  142. package/dist/live/translate.d.ts +4 -3
  143. package/dist/live/translate.js +8 -4
  144. package/dist/live-reach.d.ts +37 -0
  145. package/dist/live-reach.js +62 -0
  146. package/dist/mcp-gateway.d.ts +9 -0
  147. package/dist/mcp-gateway.js +60 -11
  148. package/dist/mcp-oauth.d.ts +57 -7
  149. package/dist/mcp-oauth.js +133 -18
  150. package/dist/mcp-private-hosts.d.ts +4 -4
  151. package/dist/mcp-private-hosts.js +20 -12
  152. package/dist/mcp-probe.d.ts +27 -3
  153. package/dist/mcp-probe.js +106 -29
  154. package/dist/mcp-secret-writes.js +8 -0
  155. package/dist/mcp-servers-store.d.ts +38 -15
  156. package/dist/mcp-servers-store.js +120 -23
  157. package/dist/mcp-store.d.ts +10 -4
  158. package/dist/mcp-store.js +17 -6
  159. package/dist/model-form.d.ts +26 -0
  160. package/dist/model-form.js +80 -0
  161. package/dist/model.d.ts +5 -5
  162. package/dist/model.js +29 -16
  163. package/dist/openapi.d.ts +2 -0
  164. package/dist/openapi.js +586 -64
  165. package/dist/owner.d.ts +0 -1
  166. package/dist/owner.js +0 -2
  167. package/dist/page.d.ts +18 -0
  168. package/dist/page.js +48 -20
  169. package/dist/paid-calls.d.ts +1 -1
  170. package/dist/paid-calls.js +1 -1
  171. package/dist/place-offers.d.ts +96 -0
  172. package/dist/place-offers.js +202 -0
  173. package/dist/place.d.ts +9 -13
  174. package/dist/place.js +21 -32
  175. package/dist/port-models.d.ts +2 -1
  176. package/dist/port-models.js +5 -3
  177. package/dist/print.d.ts +16 -9
  178. package/dist/print.js +15 -17
  179. package/dist/propose.d.ts +4 -0
  180. package/dist/propose.js +34 -11
  181. package/dist/provider.js +3 -2
  182. package/dist/reflect-range.d.ts +8 -1
  183. package/dist/reflect-range.js +1 -1
  184. package/dist/run-cut.d.ts +5 -0
  185. package/dist/run-cut.js +19 -0
  186. package/dist/run-launch.d.ts +28 -3
  187. package/dist/run-launch.js +14 -4
  188. package/dist/run-learning-served.d.ts +2 -2
  189. package/dist/run-manifest.d.ts +2 -2
  190. package/dist/run-manifest.js +2 -2
  191. package/dist/run-reads-over-store.d.ts +1 -1
  192. package/dist/run-repo.d.ts +20 -0
  193. package/dist/run-repo.js +63 -0
  194. package/dist/run-secrets.js +3 -3
  195. package/dist/run-timeline-served.d.ts +1 -1
  196. package/dist/run-timeline-served.js +56 -44
  197. package/dist/run-view.d.ts +8 -5
  198. package/dist/run-view.js +18 -10
  199. package/dist/runnable.d.ts +2 -2
  200. package/dist/runnable.js +6 -2
  201. package/dist/runner/adapter-loop.d.ts +39 -8
  202. package/dist/runner/adapter-loop.js +770 -83
  203. package/dist/runner/adapter-run-spec.d.ts +36 -7
  204. package/dist/runner/adapter-run-spec.js +171 -37
  205. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  206. package/dist/runner/adapters/pi-computer.js +43 -0
  207. package/dist/runner/adapters/pi.d.ts +20 -7
  208. package/dist/runner/adapters/pi.js +111 -26
  209. package/dist/runner/beside.d.ts +7 -3
  210. package/dist/runner/beside.js +26 -12
  211. package/dist/runner/claim-secrets.d.ts +4 -0
  212. package/dist/runner/claim-secrets.js +6 -1
  213. package/dist/runner/cli-run-spec.d.ts +27 -3
  214. package/dist/runner/cli-run-spec.js +198 -74
  215. package/dist/runner/commands.d.ts +8 -2
  216. package/dist/runner/commands.js +31 -6
  217. package/dist/runner/computer-channel.d.ts +34 -0
  218. package/dist/runner/computer-channel.js +61 -0
  219. package/dist/runner/conformance/harness.d.ts +0 -1
  220. package/dist/runner/conformance/harness.js +87 -18
  221. package/dist/runner/conformance/subject.d.ts +1 -1
  222. package/dist/runner/dispatch.js +3 -0
  223. package/dist/runner/end-of-run.d.ts +22 -12
  224. package/dist/runner/end-of-run.js +38 -16
  225. package/dist/runner/github-app.d.ts +2 -1
  226. package/dist/runner/github-app.js +6 -4
  227. package/dist/runner/harness-loops.js +16 -2
  228. package/dist/runner/held-run.d.ts +65 -0
  229. package/dist/runner/held-run.js +158 -0
  230. package/dist/runner/journal-kinds.d.ts +35 -6
  231. package/dist/runner/journal-kinds.js +20 -1
  232. package/dist/runner/journal-reader.d.ts +5 -4
  233. package/dist/runner/journal-reader.js +12 -10
  234. package/dist/runner/learning-ask.d.ts +7 -1
  235. package/dist/runner/learning-ask.js +21 -6
  236. package/dist/runner/learning-dispatch.d.ts +22 -0
  237. package/dist/runner/learning-dispatch.js +77 -10
  238. package/dist/runner/learning-end.d.ts +37 -1
  239. package/dist/runner/learning-end.js +115 -14
  240. package/dist/runner/learning-factory.d.ts +1 -1
  241. package/dist/runner/learning-factory.js +15 -5
  242. package/dist/runner/learning-loop.d.ts +139 -7
  243. package/dist/runner/learning-loop.js +369 -32
  244. package/dist/runner/learning-seed.d.ts +9 -0
  245. package/dist/runner/learning-seed.js +14 -1
  246. package/dist/runner/live-ticker.js +1 -0
  247. package/dist/runner/loop-contract.d.ts +16 -1
  248. package/dist/runner/loop-contract.js +6 -0
  249. package/dist/runner/loop.d.ts +10 -2
  250. package/dist/runner/loop.js +22 -1
  251. package/dist/runner/main.d.ts +13 -1
  252. package/dist/runner/main.js +38 -6
  253. package/dist/runner/mcp-claim.d.ts +11 -4
  254. package/dist/runner/mcp-claim.js +140 -23
  255. package/dist/runner/mcp-github.d.ts +4 -2
  256. package/dist/runner/mcp-github.js +1 -8
  257. package/dist/runner/mcp-run.d.ts +6 -4
  258. package/dist/runner/mcp-run.js +16 -3
  259. package/dist/runner/metrics.d.ts +15 -2
  260. package/dist/runner/metrics.js +21 -2
  261. package/dist/runner/model-route.d.ts +3 -0
  262. package/dist/runner/model-route.js +5 -2
  263. package/dist/runner/pr-checkout.d.ts +60 -0
  264. package/dist/runner/pr-checkout.js +176 -0
  265. package/dist/runner/reflect-hook.d.ts +19 -0
  266. package/dist/runner/reflect-hook.js +20 -8
  267. package/dist/runner/runner.d.ts +26 -0
  268. package/dist/runner/runner.js +231 -27
  269. package/dist/runner/scratch-sweep.d.ts +13 -0
  270. package/dist/runner/scratch-sweep.js +62 -0
  271. package/dist/runner/sessions.d.ts +1 -1
  272. package/dist/runner/spec-holds.d.ts +8 -3
  273. package/dist/runner/spec-holds.js +12 -10
  274. package/dist/runner/store-port.d.ts +7 -2
  275. package/dist/runner/store-secrets.js +21 -4
  276. package/dist/runner/subagent.d.ts +44 -0
  277. package/dist/runner/subagent.js +190 -0
  278. package/dist/runner/workflow-host.d.ts +24 -3
  279. package/dist/runner/workflow-host.js +24 -4
  280. package/dist/runner/workflow-loop.d.ts +6 -3
  281. package/dist/runner/workflow-loop.js +9 -8
  282. package/dist/runner/workflow-spec.d.ts +39 -15
  283. package/dist/runner/workflow-spec.js +143 -40
  284. package/dist/runs-over-store.d.ts +16 -6
  285. package/dist/runs-over-store.js +145 -29
  286. package/dist/seal-key.js +3 -3
  287. package/dist/sealed-settings-store.d.ts +5 -2
  288. package/dist/sealed-settings-store.js +10 -4
  289. package/dist/sealing.js +1 -2
  290. package/dist/secret-cut.d.ts +1 -1
  291. package/dist/secret-cut.js +1 -1
  292. package/dist/secret-writes.d.ts +5 -4
  293. package/dist/secret-writes.js +5 -4
  294. package/dist/server-secrets-store.d.ts +4 -3
  295. package/dist/server-secrets-store.js +15 -9
  296. package/dist/server-secrets.js +3 -2
  297. package/dist/server.d.ts +75 -63
  298. package/dist/server.js +712 -316
  299. package/dist/settings-wake.d.ts +21 -0
  300. package/dist/settings-wake.js +59 -0
  301. package/dist/standard-webhooks.d.ts +4 -1
  302. package/dist/standard-webhooks.js +8 -4
  303. package/dist/store/agent-body.d.ts +9 -2
  304. package/dist/store/agent-body.js +16 -8
  305. package/dist/store/command-wake.d.ts +12 -0
  306. package/dist/store/command-wake.js +37 -0
  307. package/dist/store/deadline.js +9 -5
  308. package/dist/store/dialect.d.ts +6 -0
  309. package/dist/store/dialect.js +5 -0
  310. package/dist/store/index.d.ts +4 -4
  311. package/dist/store/index.js +2 -2
  312. package/dist/store/journal/storage.d.ts +3 -2
  313. package/dist/store/journal/storage.js +15 -6
  314. package/dist/store/postgres/connection.js +9 -4
  315. package/dist/store/postgres/dialect.js +4 -0
  316. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  317. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  318. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  319. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  320. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  321. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  322. package/dist/store/schema.d.ts +2 -1
  323. package/dist/store/schema.js +85 -13
  324. package/dist/store/seal.d.ts +13 -0
  325. package/dist/store/seal.js +19 -0
  326. package/dist/store/sqlite/connection.d.ts +5 -0
  327. package/dist/store/sqlite/connection.js +88 -47
  328. package/dist/store/sqlite/run-patch.d.ts +25 -7
  329. package/dist/store/sqlite/run-patch.js +58 -14
  330. package/dist/store/sqlite/store.js +331 -59
  331. package/dist/store/store.d.ts +330 -21
  332. package/dist/store/store.js +34 -2
  333. package/dist/store-reads/analytics.js +3 -2
  334. package/dist/store-reads/cap.d.ts +2 -4
  335. package/dist/store-reads/cap.js +16 -7
  336. package/dist/store-reads/decisions.d.ts +3 -3
  337. package/dist/store-reads/decisions.js +3 -6
  338. package/dist/store-reads/import-summary.d.ts +1 -1
  339. package/dist/store-reads/journal.d.ts +5 -4
  340. package/dist/store-reads/journal.js +118 -27
  341. package/dist/store-reads/learning.d.ts +34 -4
  342. package/dist/store-reads/learning.js +137 -23
  343. package/dist/store-reads/runs.d.ts +7 -5
  344. package/dist/store-reads/runs.js +17 -10
  345. package/dist/store-reads/stats.js +5 -1
  346. package/dist/store-reads/workflow.d.ts +1 -1
  347. package/dist/store-view.d.ts +5 -0
  348. package/dist/store-view.js +70 -29
  349. package/dist/template-eval.js +8 -5
  350. package/dist/template-github-permissions.d.ts +22 -8
  351. package/dist/template-github-permissions.js +35 -15
  352. package/dist/templates.d.ts +64 -0
  353. package/dist/templates.js +101 -16
  354. package/dist/timeline/timeline.d.ts +30 -1
  355. package/dist/timeline/timeline.js +29 -13
  356. package/dist/timeline/util.d.ts +4 -0
  357. package/dist/timeline/util.js +14 -0
  358. package/dist/tool-blurbs.js +1 -0
  359. package/dist/tool-budget.d.ts +27 -7
  360. package/dist/tool-budget.js +21 -9
  361. package/dist/tool-gate.d.ts +23 -10
  362. package/dist/tool-gate.js +60 -44
  363. package/dist/tool-plane.d.ts +46 -28
  364. package/dist/tool-plane.js +73 -31
  365. package/dist/tools.d.ts +31 -38
  366. package/dist/tools.js +117 -74
  367. package/dist/trigger-adapter.d.ts +4 -0
  368. package/dist/trigger-secrets-shown.d.ts +2 -2
  369. package/dist/trigger-secrets-shown.js +1 -1
  370. package/dist/trigger-signatures.d.ts +26 -6
  371. package/dist/trigger-signatures.js +44 -8
  372. package/dist/trigger-targets.d.ts +2 -0
  373. package/dist/trigger-targets.js +1 -0
  374. package/dist/trigger-webhook.js +5 -2
  375. package/dist/triggers.d.ts +10 -6
  376. package/dist/triggers.js +37 -7
  377. package/dist/turn-end.d.ts +0 -3
  378. package/dist/turn-end.js +0 -3
  379. package/dist/turns.js +16 -1
  380. package/dist/usage-lines.d.ts +1 -1
  381. package/dist/validate.d.ts +6 -0
  382. package/dist/validate.js +41 -4
  383. package/dist/web-fetch.d.ts +1 -1
  384. package/dist/web-search.d.ts +10 -5
  385. package/dist/web-search.js +7 -6
  386. package/dist/webhooks.d.ts +147 -103
  387. package/dist/webhooks.js +564 -324
  388. package/dist/workflow/decision-recovery.d.ts +23 -0
  389. package/dist/workflow/decision-recovery.js +80 -0
  390. package/dist/workflow/decisions.d.ts +134 -0
  391. package/dist/workflow/decisions.js +46 -0
  392. package/dist/workflow/host-session.d.ts +5 -0
  393. package/dist/workflow/host-session.js +85 -0
  394. package/dist/workflow/host-tools.d.ts +3 -0
  395. package/dist/workflow/host-tools.js +3 -0
  396. package/dist/workflow/node-runner.d.ts +113 -0
  397. package/dist/workflow/node-runner.js +270 -0
  398. package/dist/workflow/node.d.ts +89 -0
  399. package/dist/workflow/node.js +101 -0
  400. package/dist/workflow/operator-error.d.ts +4 -0
  401. package/dist/workflow/operator-error.js +4 -0
  402. package/dist/workflow/pi-versions.d.ts +32 -0
  403. package/dist/workflow/pi-versions.js +65 -0
  404. package/dist/workflow/record-file.d.ts +10 -0
  405. package/dist/workflow/record-file.js +56 -0
  406. package/dist/workflow/record-tool.d.ts +77 -0
  407. package/dist/workflow/record-tool.js +126 -0
  408. package/dist/workflow/record.d.ts +151 -0
  409. package/dist/workflow/record.js +401 -0
  410. package/dist/workflow/run-error.d.ts +16 -0
  411. package/dist/workflow/run-error.js +26 -0
  412. package/dist/workflow/runner.d.ts +6 -0
  413. package/dist/workflow/runner.js +240 -0
  414. package/dist/workflow/store.d.ts +23 -0
  415. package/dist/workflow/store.js +242 -0
  416. package/dist/workflow/task.d.ts +133 -0
  417. package/dist/workflow/task.js +412 -0
  418. package/dist/workflow/thinking.d.ts +3 -0
  419. package/dist/workflow/thinking.js +7 -0
  420. package/dist/workflow/tool-context.d.ts +21 -0
  421. package/dist/workflow/tool-context.js +13 -0
  422. package/dist/workflow/types.d.ts +126 -0
  423. package/dist/workflow/types.js +1 -0
  424. package/dist/workflow-run.d.ts +2 -2
  425. package/dist/workspace/agent-computer.d.ts +137 -0
  426. package/dist/workspace/agent-computer.js +292 -0
  427. package/dist/workspace/archil-claim.d.ts +11 -0
  428. package/dist/workspace/archil-claim.js +18 -10
  429. package/dist/workspace/archil-disks.d.ts +49 -0
  430. package/dist/workspace/archil-disks.js +185 -0
  431. package/dist/workspace/archil-exec.js +2 -3
  432. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  433. package/dist/workspace/archil-mount-credential.js +13 -4
  434. package/dist/workspace/attached-computers.d.ts +41 -0
  435. package/dist/workspace/attached-computers.js +114 -0
  436. package/dist/workspace/computer-deps.d.ts +32 -17
  437. package/dist/workspace/computer-deps.js +37 -14
  438. package/dist/workspace/computer-for-claim.d.ts +58 -13
  439. package/dist/workspace/computer-for-claim.js +267 -26
  440. package/dist/workspace/computer-hold.d.ts +11 -27
  441. package/dist/workspace/computer-hold.js +36 -56
  442. package/dist/workspace/computer-janitor.d.ts +3 -2
  443. package/dist/workspace/computer-janitor.js +43 -9
  444. package/dist/workspace/computer-ledger.d.ts +5 -1
  445. package/dist/workspace/computer-ledger.js +11 -0
  446. package/dist/workspace/computer-mcp.d.ts +25 -0
  447. package/dist/workspace/computer-mcp.js +41 -0
  448. package/dist/workspace/computer-ports.d.ts +4 -13
  449. package/dist/workspace/computer-ports.js +4 -107
  450. package/dist/workspace/computer-script.d.ts +37 -0
  451. package/dist/workspace/computer-script.js +138 -0
  452. package/dist/workspace/executors.d.ts +1 -1
  453. package/dist/workspace/index.d.ts +7 -4
  454. package/dist/workspace/index.js +4 -1
  455. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  456. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  457. package/dist/workspace/resolve-computer.d.ts +45 -11
  458. package/dist/workspace/resolve-computer.js +72 -14
  459. package/dist/workspace/run-disk.d.ts +34 -0
  460. package/dist/workspace/run-disk.js +91 -0
  461. package/dist/workspace/run-tools.d.ts +35 -18
  462. package/dist/workspace/run-tools.js +24 -29
  463. package/dist/workspace/server-run-workspace.d.ts +3 -2
  464. package/dist/workspace/server-run-workspace.js +17 -4
  465. package/dist/workspace.js +1 -1
  466. package/package.json +19 -21
  467. package/templates/README.md +9 -6
  468. package/templates/code-review/agent.md +27 -11
  469. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  470. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  471. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  472. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  473. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  474. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  475. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  476. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  477. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  478. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  479. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  480. package/templates/code-review/evals/re-review/prompt.md +1 -1
  481. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  482. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  483. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  484. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  485. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  486. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  487. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  488. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  489. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  490. package/templates/code-review/findings.schema.json +131 -27
  491. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  492. package/templates/code-review/skills/review/DEEP.md +130 -0
  493. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  494. package/templates/code-review/skills/review/SKILL.md +104 -154
  495. package/templates/market-monitor/agent.md +1 -1
  496. package/dist/box/record.d.ts +0 -6
  497. package/dist/box/record.js +0 -41
  498. package/dist/box/sweep.d.ts +0 -53
  499. package/dist/box/sweep.js +0 -193
  500. package/dist/box-egress-vm.d.ts +0 -118
  501. package/dist/box-egress-vm.js +0 -354
  502. package/dist/box-egress.d.ts +0 -105
  503. package/dist/box-egress.js +0 -256
  504. package/dist/box-relay-vm.d.ts +0 -84
  505. package/dist/box-relay-vm.js +0 -437
  506. package/dist/box-relay.d.ts +0 -36
  507. package/dist/box-relay.js +0 -207
  508. package/dist/boxes.d.ts +0 -109
  509. package/dist/boxes.js +0 -249
  510. package/dist/budget.d.ts +0 -71
  511. package/dist/budget.js +0 -199
  512. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  513. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  514. package/dist/daytona-api.d.ts +0 -10
  515. package/dist/daytona-api.js +0 -20
  516. package/dist/egress-proxy.d.ts +0 -45
  517. package/dist/egress-proxy.js +0 -416
  518. package/dist/egress-table.d.ts +0 -24
  519. package/dist/egress-table.js +0 -165
  520. package/dist/run-db.d.ts +0 -53
  521. package/dist/run-db.js +0 -116
  522. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -0,0 +1,57 @@
1
+ -- The store's schema on Postgres, version 6: the run-change feed (Runs.changedSince), each channel post's tries (the
2
+ -- outbound webhook's deliveries log) and the claim a post's try settles under, as SQLite's schema version 8 has them.
3
+ --
4
+ -- A change is a run reaching a final state, or let go by its runner (parked, or running with none), written by the
5
+ -- trigger below in the transaction of the write that made it. Postgres has many writers, so a sequence alone does not
6
+ -- number changes in commit order: the trigger takes one transaction-scoped advisory lock before it inserts, so two
7
+ -- transactions that each write a change commit them in seq order, and a reader that has read seq n has every change at
8
+ -- or below it. The trigger is deferred to the commit, so the lock is held only while the change is numbered and the
9
+ -- transaction commits: a run's end write and the statements after it never wait on another run's, which would make a
10
+ -- runner of many loops end its runs one at a time.
11
+ CREATE TABLE IF NOT EXISTS run_changes (
12
+ seq BIGSERIAL PRIMARY KEY,
13
+ run_id TEXT COLLATE "C" NOT NULL,
14
+ state TEXT COLLATE "C" NOT NULL,
15
+ ended_at BIGINT,
16
+ epoch BIGINT NOT NULL,
17
+ runner TEXT COLLATE "C"
18
+ );
19
+
20
+ CREATE OR REPLACE FUNCTION run_changed() RETURNS trigger LANGUAGE plpgsql AS $$
21
+ BEGIN
22
+ PERFORM pg_advisory_xact_lock(hashtext(TG_TABLE_SCHEMA || '.run_changes'));
23
+ EXECUTE format('INSERT INTO %I.run_changes (run_id, state, ended_at, epoch, runner) VALUES ($1, $2, $3, $4, $5)', TG_TABLE_SCHEMA)
24
+ USING NEW.id, NEW.state, NEW.ended_at, NEW.epoch, NEW.runner;
25
+ RETURN NULL;
26
+ END
27
+ $$;
28
+
29
+ DROP TRIGGER IF EXISTS runs_changed ON runs;
30
+ CREATE CONSTRAINT TRIGGER runs_changed AFTER UPDATE OF state, runner ON runs
31
+ DEFERRABLE INITIALLY DEFERRED
32
+ FOR EACH ROW
33
+ WHEN ((OLD.state IS DISTINCT FROM NEW.state OR OLD.runner IS DISTINCT FROM NEW.runner)
34
+ AND (NEW.state IN ('ended', 'stopped', 'failed', 'parked') OR (NEW.state = 'running' AND NEW.runner IS NULL)))
35
+ EXECUTE FUNCTION run_changed();
36
+
37
+ -- A post's try settles under the claim that made it (Channels.settle's fence): the claim's token, kept on the post until
38
+ -- a newer claim or a write outside every claim takes it.
39
+ ALTER TABLE channel_posts ADD COLUMN IF NOT EXISTS claim TEXT COLLATE "C";
40
+
41
+ -- Each try once, by its id: a settle written again (its outcome unknown) logs it once.
42
+ CREATE TABLE IF NOT EXISTS channel_attempts (
43
+ seq BIGSERIAL PRIMARY KEY,
44
+ try_id TEXT COLLATE "C" NOT NULL UNIQUE,
45
+ channel TEXT COLLATE "C" NOT NULL,
46
+ post_id TEXT COLLATE "C" NOT NULL,
47
+ moment TEXT COLLATE "C" NOT NULL,
48
+ at BIGINT NOT NULL,
49
+ status_code BIGINT,
50
+ latency_ms BIGINT NOT NULL,
51
+ error TEXT COLLATE "C",
52
+ retry_at BIGINT,
53
+ redelivery BIGINT NOT NULL CHECK (redelivery IN (0, 1))
54
+ );
55
+ CREATE INDEX IF NOT EXISTS channel_attempts_by_channel ON channel_attempts (channel, seq);
56
+
57
+ UPDATE store_meta SET schema_version = 6 WHERE singleton = 1;
@@ -0,0 +1,11 @@
1
+ -- The store's schema on Postgres, version 7: where a live viewer answers when its runner is on another host than the
2
+ -- server (live-reach.ts), as store/schema.ts keeps it on SQLite (version 9). Applied once, after 0006, inside the transaction
3
+ -- migrate.ts opens. Never edit this file once applied: a change is a new file.
4
+ --
5
+ -- computer_viewers.host: the runner's live host (AGENTRUN_RUNNER_LIVE_HOST); null, the server's own machine (loopback).
6
+ -- IF NOT EXISTS: applied again over a store that has it (the migration-0003 repair re-runs every migration after 0002),
7
+ -- it changes nothing.
8
+
9
+ ALTER TABLE computer_viewers ADD COLUMN IF NOT EXISTS host TEXT COLLATE "C";
10
+
11
+ UPDATE store_meta SET schema_version = 7 WHERE singleton = 1;
@@ -0,0 +1,30 @@
1
+ -- The store's schema on Postgres, version 8: a person's own computer paired with this server (spec/computer/attach.md),
2
+ -- and the codes that pair one, as store/schema.ts keeps them on SQLite (version 10). Applied once, after 0007, inside the transaction
3
+ -- migrate.ts opens. Never edit this file once applied: a change is a new file.
4
+ --
5
+ -- paired_computers: the token's SHA-256 alone is kept (hex); revoked_at marks a removed computer, whose token dials no more.
6
+ -- pairing_codes: a code's SHA-256 alone (hex), good once until expires_at; a used one is deleted as it pairs. Its id names
7
+ -- the pairing and is kept on the computer it made (paired_computers.pairing_id), so the console that made the code can
8
+ -- tell its own code was used, and by which computer.
9
+ -- Each table is made only where it is missing, so a store whose record of this file was lost applies it again unharmed.
10
+
11
+ CREATE TABLE IF NOT EXISTS paired_computers (
12
+ id TEXT COLLATE "C" PRIMARY KEY,
13
+ name TEXT COLLATE "C" NOT NULL,
14
+ hello TEXT COLLATE "C" NOT NULL CHECK (hello::json IS NOT NULL),
15
+ driver TEXT COLLATE "C" NOT NULL,
16
+ labels TEXT COLLATE "C" NOT NULL CHECK (labels::json IS NOT NULL),
17
+ token_sha256 TEXT COLLATE "C" NOT NULL UNIQUE,
18
+ pairing_id TEXT COLLATE "C" NOT NULL UNIQUE,
19
+ created_at BIGINT NOT NULL,
20
+ seen_at BIGINT,
21
+ revoked_at BIGINT
22
+ );
23
+
24
+ CREATE TABLE IF NOT EXISTS pairing_codes (
25
+ id TEXT COLLATE "C" NOT NULL UNIQUE,
26
+ code_sha256 TEXT COLLATE "C" PRIMARY KEY,
27
+ expires_at BIGINT NOT NULL
28
+ );
29
+
30
+ UPDATE store_meta SET schema_version = 8 WHERE singleton = 1;
@@ -0,0 +1,10 @@
1
+ -- The store's schema on Postgres, version 9: a command keeps its answer, as store/schema.ts keeps it on SQLite
2
+ -- (version 11, commands.answer). The runner writes it with the commit that takes the row; the server reads it once and clears it
3
+ -- (Store.answerOf). Applied once, after 0008, inside the transaction migrate.ts opens. Never edit this file once applied: a
4
+ -- change is a new file.
5
+ --
6
+ -- answer: JSON text, NULL until a take writes one and again once it is read.
7
+
8
+ ALTER TABLE commands ADD COLUMN answer TEXT COLLATE "C" CHECK (answer IS NULL OR answer::json IS NOT NULL);
9
+
10
+ UPDATE store_meta SET schema_version = 9 WHERE singleton = 1;
@@ -1,9 +1,10 @@
1
- export declare const SCHEMA_VERSION = 5;
1
+ export declare const SCHEMA_VERSION = 11;
2
2
  /** One answer per approval of a run: a second approve or deny command naming the same approval is refused
3
3
  * (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
4
4
  * (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
5
5
  /** One unrefused answer per approval of a run: an answer the runner refused (its run could not resume) holds no place, so
6
6
  * the person can answer again. */
7
+ export declare const ONE_ANSWER_INDEX = "commands_one_answer";
7
8
  export declare const COMMANDS_ONE_ANSWER = "CREATE UNIQUE INDEX IF NOT EXISTS commands_one_answer ON commands (run_id, json_extract(body, '$.approval')) WHERE kind IN ('approve', 'deny') AND refused IS NULL";
8
9
  export declare const STORE_DDL: readonly string[];
9
10
  /** pi-durable's journal tables (its SqliteStorage schema, version 2, the `sleeping` task status included; MIT, see NOTICE),
@@ -1,8 +1,14 @@
1
- // The store's one schema, version 5 (design 2.1). Nothing migrates into it: the rewrite replaces the old stores, and a store
1
+ // The store's one schema, version 11 (design 2.1). Nothing migrates into it: the rewrite replaces the old stores, and a store
2
2
  // an older build made is refused as a version this build does not know. The server sets it up once at its start (a
3
3
  // store_meta row holds the version); a runner refuses a version it does not know. Version 2 adds the computer ledger;
4
4
  // version 3 numbers each save of a sign-in (sign_ins.save); version 4 stamps an MCP token's end (mcp_servers.token_until);
5
- // version 5 maps an externally owned agent (agents.external_ref, revisions.external_version).
5
+ // version 5 maps an externally owned agent (agents.external_ref, revisions.external_version); version 6 tells a person's
6
+ // stop from a cancel (runs.outcome 'stopped' or 'cancelled'); version 7 keeps a run's learning by round
7
+ // (learning_proposals.round: a follow-up to a run that ended looks back again, a round of its own); version 8 adds the
8
+ // run-change feed (run_changes), each channel post's tries (channel_attempts) and the claim a post's try settles under
9
+ // (channel_posts.claim); version 9 adds where a live viewer answers (computer_viewers.host, a runner's live host,
10
+ // live-reach.ts); version 10 pairs a person's own computer (paired_computers, pairing_codes); version 11 keeps a command's answer
11
+ // (commands.answer).
6
12
  // Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
7
13
  // sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
8
14
  // in the clear. Foreign keys are on (the connection's pragma).
@@ -13,13 +19,14 @@
13
19
  // learning state, the MCP registry, pending MCP sign-ins, each run's MCP pin, and the computer ledger. PI_DDL is pi-durable's
14
20
  // journal tables, keyed by run_id (store/journal): one schema for every run's journal, so a query joins runs and their
15
21
  // journals.
16
- export const SCHEMA_VERSION = 5;
22
+ export const SCHEMA_VERSION = 11;
17
23
  /** One answer per approval of a run: a second approve or deny command naming the same approval is refused
18
24
  * (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
19
25
  * (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
20
26
  /** One unrefused answer per approval of a run: an answer the runner refused (its run could not resume) holds no place, so
21
27
  * the person can answer again. */
22
- export const COMMANDS_ONE_ANSWER = `CREATE UNIQUE INDEX IF NOT EXISTS commands_one_answer ON commands (run_id, json_extract(body, '$.approval')) WHERE kind IN ('approve', 'deny') AND refused IS NULL`;
28
+ export const ONE_ANSWER_INDEX = "commands_one_answer";
29
+ export const COMMANDS_ONE_ANSWER = `CREATE UNIQUE INDEX IF NOT EXISTS ${ONE_ANSWER_INDEX} ON commands (run_id, json_extract(body, '$.approval')) WHERE kind IN ('approve', 'deny') AND refused IS NULL`;
23
30
  const json = (column, nullable = false) => `${column} TEXT${nullable ? "" : " NOT NULL"} CHECK (${column} IS NULL OR json_valid(${column}))`;
24
31
  export const STORE_DDL = [
25
32
  `CREATE TABLE IF NOT EXISTS store_meta (
@@ -80,10 +87,11 @@ export const STORE_DDL = [
80
87
  cost_usd REAL,
81
88
  ${json("metrics", true)},
82
89
  summary TEXT,
83
- -- How an ended run (state 'ended') ended apart from being done: 'escalated' (it finished its work and waits for a
84
- -- person, which v2 reads as completed with a review) or 'completed'; null is a plain completion. A failed or stopped
85
- -- run says so in its state and needs none. Written in the run's end commit (RunPatch.outcome).
86
- outcome TEXT CHECK (outcome IS NULL OR outcome IN ('completed', 'escalated')),
90
+ -- How the run ended beside its state (RunOutcome). An ended run: 'escalated' (it finished its work and waits for a
91
+ -- person, which v2 reads as completed with a review) or 'completed'; null is a plain completion. A stopped run:
92
+ -- 'stopped' when a person stopped it (its turn is over, not the run: a message reopens it) or 'cancelled' (over for
93
+ -- good). A failed run says so in its state and needs none. Written in the run's end commit (RunPatch.outcome).
94
+ outcome TEXT CHECK (outcome IS NULL OR outcome IN ('completed', 'escalated', 'stopped', 'cancelled')),
87
95
  -- When the run itself was archived (its agent's archive is the agent row's): hidden from the default lists, kept.
88
96
  archived_at INTEGER,
89
97
  -- The session an imported run came from ({source, session}), written by Store.importRun; null for a run started here.
@@ -104,6 +112,25 @@ export const STORE_DDL = [
104
112
  `CREATE INDEX IF NOT EXISTS runs_by_agent ON runs (agent_id, started_at)`,
105
113
  `CREATE INDEX IF NOT EXISTS runs_by_revision ON runs (revision_id, started_at)`,
106
114
  `CREATE INDEX IF NOT EXISTS runs_claimable ON runs (state, started_at)`,
115
+ // The run-change feed (Runs.changedSince): a row for each run reaching a final state or let go by its runner (parked, or
116
+ // running with no runner), written by the trigger below in the transaction of the write that made it, so no writer of a
117
+ // run's state or runner can miss it and none lands without its write. `seq` numbers them in commit order (one writer).
118
+ `CREATE TABLE IF NOT EXISTS run_changes (
119
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
120
+ run_id TEXT NOT NULL,
121
+ state TEXT NOT NULL,
122
+ ended_at INTEGER,
123
+ epoch INTEGER NOT NULL,
124
+ runner TEXT
125
+ ) STRICT`,
126
+ // A change is a move of the state or the runner into a final state, parked, or running with none: a fence's touch of
127
+ // the row (epoch = epoch), a claim, a renew and a cost or summary write are none.
128
+ `CREATE TRIGGER IF NOT EXISTS runs_changed AFTER UPDATE OF state, runner ON runs
129
+ WHEN (OLD.state IS NOT NEW.state OR OLD.runner IS NOT NEW.runner)
130
+ AND (NEW.state IN ('ended', 'stopped', 'failed', 'parked') OR (NEW.state = 'running' AND NEW.runner IS NULL))
131
+ BEGIN
132
+ INSERT INTO run_changes (run_id, state, ended_at, epoch, runner) VALUES (NEW.id, NEW.state, NEW.ended_at, NEW.epoch, NEW.runner);
133
+ END`,
107
134
  // One run per imported session: Store.importRun is refused a session it already imported (as the old store's
108
135
  // UNIQUE (source, session) did).
109
136
  `CREATE UNIQUE INDEX IF NOT EXISTS runs_import ON runs (json_extract(imported_from, '$.source'), json_extract(imported_from, '$.session')) WHERE imported_from IS NOT NULL`,
@@ -116,7 +143,8 @@ export const STORE_DDL = [
116
143
  created_at INTEGER NOT NULL,
117
144
  taken_at INTEGER,
118
145
  refused TEXT,
119
- tries INTEGER NOT NULL DEFAULT 0
146
+ tries INTEGER NOT NULL DEFAULT 0,
147
+ ${json("answer", true)}
120
148
  ) STRICT`,
121
149
  `CREATE INDEX IF NOT EXISTS commands_by_run ON commands (run_id, id)`,
122
150
  `CREATE INDEX IF NOT EXISTS commands_untaken ON commands (run_id) WHERE taken_at IS NULL`,
@@ -220,6 +248,7 @@ export const STORE_DDL = [
220
248
  attempts INTEGER NOT NULL DEFAULT 0,
221
249
  next_at INTEGER NOT NULL,
222
250
  claimed_until INTEGER,
251
+ claim TEXT,
223
252
  state TEXT NOT NULL CHECK (state IN ('queued', 'sending', 'sent', 'dropped')),
224
253
  reason TEXT,
225
254
  created_at INTEGER NOT NULL
@@ -233,6 +262,22 @@ export const STORE_DDL = [
233
262
  at INTEGER NOT NULL,
234
263
  PRIMARY KEY (channel, run_id, marker)
235
264
  ) STRICT`,
265
+ // Each try of a channel's post (the outbound webhook's deliveries log): kept to the newest few per channel, each once by
266
+ // its try's id.
267
+ `CREATE TABLE IF NOT EXISTS channel_attempts (
268
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
269
+ try_id TEXT NOT NULL UNIQUE,
270
+ channel TEXT NOT NULL,
271
+ post_id TEXT NOT NULL,
272
+ moment TEXT NOT NULL,
273
+ at INTEGER NOT NULL,
274
+ status_code INTEGER,
275
+ latency_ms INTEGER NOT NULL,
276
+ error TEXT,
277
+ retry_at INTEGER,
278
+ redelivery INTEGER NOT NULL CHECK (redelivery IN (0, 1))
279
+ ) STRICT`,
280
+ `CREATE INDEX IF NOT EXISTS channel_attempts_by_channel ON channel_attempts (channel, seq)`,
236
281
  // A code review's ledger, per head and firing.
237
282
  `CREATE TABLE IF NOT EXISTS review_ledger (
238
283
  repo TEXT NOT NULL,
@@ -265,6 +310,29 @@ export const STORE_DDL = [
265
310
  ${json("detail")},
266
311
  updated_at INTEGER NOT NULL,
267
312
  PRIMARY KEY (provider, session_id)
313
+ ) STRICT`,
314
+ // A person's own machine paired with this server (spec/computer/attach.md): its driver dials the attach socket with the
315
+ // token pairing gave it, of which only the SHA-256 is kept (hex). `hello`: the driver's hello at pairing, what it paired
316
+ // as; `driver`: the build its last hello named. `seen_at`: its last socket's hello; `revoked_at`: when it was removed,
317
+ // after which its token dials no more (the row stays, so a run that names it is told it was removed).
318
+ `CREATE TABLE IF NOT EXISTS paired_computers (
319
+ id TEXT PRIMARY KEY,
320
+ name TEXT NOT NULL,
321
+ ${json("hello")},
322
+ driver TEXT NOT NULL,
323
+ ${json("labels")},
324
+ token_sha256 TEXT NOT NULL UNIQUE,
325
+ pairing_id TEXT NOT NULL UNIQUE,
326
+ created_at INTEGER NOT NULL,
327
+ seen_at INTEGER,
328
+ revoked_at INTEGER
329
+ ) STRICT`,
330
+ // A pairing code, by its SHA-256 alone (hex): good once, until expires_at. A used one is deleted as it pairs. `id` names
331
+ // the pairing (not the code): the console that made it reads it back on the computer the code made (paired_computers.pairing_id).
332
+ `CREATE TABLE IF NOT EXISTS pairing_codes (
333
+ id TEXT NOT NULL UNIQUE,
334
+ code_sha256 TEXT PRIMARY KEY,
335
+ expires_at INTEGER NOT NULL
268
336
  ) STRICT`,
269
337
  `CREATE TABLE IF NOT EXISTS learning (
270
338
  agent_id TEXT NOT NULL REFERENCES agents (id),
@@ -379,19 +447,23 @@ export const STORE_DDL = [
379
447
  at INTEGER NOT NULL,
380
448
  runner TEXT NOT NULL,
381
449
  epoch INTEGER NOT NULL,
450
+ host TEXT,
382
451
  PRIMARY KEY (run_id, kind, tag)
383
452
  ) STRICT`,
384
453
  // Learning on the runner: what a run's end-of-run turn kept (the turn it asked and answered, and the proposal checked from
385
454
  // it), written in the same commit as the run's end, beside the learning run that grades and merges it (learning_run_id,
386
- // none for a learning dropped before it was proposed). Read by the learning routes (the pre-merge view), by the
387
- // learning run, and by the reader of a run's learning end (store-reads/learning.ts).
455
+ // none for a learning dropped before it was proposed). One row a round: a run's first end is round 1, and each end
456
+ // after a follow-up opened it again is the next. Read by the learning routes (the pre-merge view), by the learning run,
457
+ // and by the reader of a run's learning end (store-reads/learning.ts), which reads the newest round.
388
458
  `CREATE TABLE IF NOT EXISTS learning_proposals (
389
- run_id TEXT PRIMARY KEY REFERENCES runs (id),
459
+ run_id TEXT NOT NULL REFERENCES runs (id),
460
+ round INTEGER NOT NULL CHECK (round >= 1),
390
461
  agent_id TEXT NOT NULL REFERENCES agents (id),
391
462
  ${json("turn")},
392
463
  ${json("proposal")},
393
464
  learning_run_id TEXT,
394
- created_at INTEGER NOT NULL
465
+ created_at INTEGER NOT NULL,
466
+ PRIMARY KEY (run_id, round)
395
467
  ) STRICT`,
396
468
  `CREATE INDEX IF NOT EXISTS learning_proposals_by_agent ON learning_proposals (agent_id, created_at DESC)`,
397
469
  ];
@@ -13,6 +13,8 @@ export declare const sealedAt: {
13
13
  signIn: (agentId: string, provider: string) => SealedAt;
14
14
  /** A run's computer session's live viewer token (browser-live.ts): one row per run, computer kind and session tag. */
15
15
  liveViewer: (runId: string, kind: string, tag: string) => SealedAt;
16
+ /** A run's launch secrets: the MCP credentials its caller handed it for its `per_run` servers (mcp_auth). */
17
+ runLaunch: (runId: string) => SealedAt;
16
18
  };
17
19
  /** The AAD a value at `at` is sealed under. A part with the separator in it is refused: no two places share an AAD. */
18
20
  export declare function aadOf(at: SealedAt): string;
@@ -46,3 +48,14 @@ export declare function openMcpCredential(key: Buffer, row: {
46
48
  readonly url: string;
47
49
  readonly sealed: Uint8Array | null;
48
50
  }): OpenedMcpCredential;
51
+ /** The MCP credentials a run's caller handed it (`mcp_auth` at its start or with a message), by server name: each one's
52
+ * headers and the origin of the server's url when it was handed, so a server moved since never receives them. */
53
+ export type RunMcpAuth = Readonly<Record<string, {
54
+ readonly headers: Readonly<Record<string, string>>;
55
+ readonly origin: string;
56
+ }>>;
57
+ /** Seals a run's handed MCP credentials as its launch's sealed column (AAD run_launch|<run_id>|sealed). */
58
+ export declare function sealRunMcpAuth(key: Buffer, runId: string, auth: RunMcpAuth): Uint8Array;
59
+ /** A run's handed MCP credentials, opened: none when its launch holds none; undefined when the bytes do not open under
60
+ * `key` for this run (sealed for another run, or under another key). */
61
+ export declare function openRunMcpAuth(key: Buffer, runId: string, sealed: Uint8Array | null): RunMcpAuth | undefined;
@@ -25,6 +25,8 @@ export const sealedAt = {
25
25
  },
26
26
  /** A run's computer session's live viewer token (browser-live.ts): one row per run, computer kind and session tag. */
27
27
  liveViewer: (runId, kind, tag) => ({ table: "computer_viewers", row: `${runId}/${kind}:${tag}`, column: "sealed" }),
28
+ /** A run's launch secrets: the MCP credentials its caller handed it for its `per_run` servers (mcp_auth). */
29
+ runLaunch: (runId) => ({ table: "run_launch", row: runId, column: "sealed" }),
28
30
  };
29
31
  /** The AAD a value at `at` is sealed under. A part with the separator in it is refused: no two places share an AAD. */
30
32
  export function aadOf(at) {
@@ -67,3 +69,20 @@ export function openMcpCredential(key, row) {
67
69
  }
68
70
  return { credential: credential };
69
71
  }
72
+ /** Seals a run's handed MCP credentials as its launch's sealed column (AAD run_launch|<run_id>|sealed). */
73
+ export function sealRunMcpAuth(key, runId, auth) {
74
+ return sealColumn(key, sealedAt.runLaunch(runId), JSON.stringify({ mcp: auth }));
75
+ }
76
+ /** A run's handed MCP credentials, opened: none when its launch holds none; undefined when the bytes do not open under
77
+ * `key` for this run (sealed for another run, or under another key). */
78
+ export function openRunMcpAuth(key, runId, sealed) {
79
+ if (sealed === null)
80
+ return {};
81
+ try {
82
+ const opened = JSON.parse(unsealColumn(key, sealedAt.runLaunch(runId), sealed).toString("utf8"));
83
+ return opened.mcp ?? {};
84
+ }
85
+ catch {
86
+ return undefined;
87
+ }
88
+ }
@@ -4,6 +4,11 @@ import type { Statement, StatementResult } from "./worker.js";
4
4
  export type { Params, Statement, StatementResult } from "./worker.js";
5
5
  /** How long a transaction may stay open (it holds every other call of the process) before it is rolled back. */
6
6
  export declare const DEFAULT_TRANSACTION_DEADLINE_MS = 10000;
7
+ /** `error` with its stack naming who held the store: `opened` (its own transaction's opener, when it has one), and every
8
+ * other transaction open in this process with its age. */
9
+ export declare function holderNamed<E extends Error>(error: E, { opened }?: {
10
+ opened?: Error;
11
+ }): E;
7
12
  /** A value SQLite takes or gives back (Chord's SqliteValue). */
8
13
  export type SqliteValue = null | number | bigint | string | Uint8Array;
9
14
  /** Chord's SqliteExecutor: what a database and a transaction handle both do. */
@@ -8,20 +8,46 @@ import { Worker } from "node:worker_threads";
8
8
  import { runnableDeadline } from "../deadline.js";
9
9
  import { cleanText, SQLITE } from "../dialect.js";
10
10
  import { inMemory } from "./memory.js";
11
- import { Fenced, RunFinal, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreOwned, StoreWorkerLost } from "../store.js";
11
+ import { ONE_ANSWER_INDEX } from "../schema.js";
12
+ import { AnswerTaken, Fenced, RunFinal, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreOwned, StoreWorkerLost } from "../store.js";
12
13
  /** How long a transaction may stay open (it holds every other call of the process) before it is rolled back. */
13
14
  export const DEFAULT_TRANSACTION_DEADLINE_MS = 10_000;
15
+ /** The interactive transactions open in this process, on any of its connections: each with where it was opened and when
16
+ * it began. A transaction's StoreDeadline, and a begin's StoreBusy, name them in their stack (never their message, which
17
+ * an answer may carry), so a log says who held the store: the deadline's own transaction, or another of this process's
18
+ * (an in-process runner's) holding the lock a begin waited on. */
19
+ const OPEN = new Set();
20
+ /** `opened`'s frames: where a transaction was asked for, without the Error line itself. */
21
+ const framesOf = (opened) => (opened.stack ?? "").split("\n").slice(1).join("\n");
22
+ /** `error` with its stack naming who held the store: `opened` (its own transaction's opener, when it has one), and every
23
+ * other transaction open in this process with its age. */
24
+ export function holderNamed(error, { opened } = {}) {
25
+ const lines = [];
26
+ if (opened)
27
+ lines.push(` the transaction was opened at:\n${framesOf(opened)}`);
28
+ const now = Date.now();
29
+ const others = [...OPEN].filter((open) => open.opened !== opened);
30
+ if (others.length)
31
+ lines.push(` other transactions open in this process:\n${others.map((open) => ` open ${now - open.began} ms, opened at:\n${framesOf(open.opened)}`).join("\n")}`);
32
+ if (lines.length)
33
+ error.stack = `${error.stack ?? `${error.name}: ${error.message}`}\n${lines.join("\n")}`;
34
+ return error;
35
+ }
14
36
  /** A statement's text parameters as the store writes text (dialect.ts cleanText: no NUL), on both stores alike. */
15
37
  const cleaned = (params) => (params ?? []).map((value) => (typeof value === "string" ? cleanText(value) : value));
16
38
  const cleanStatement = (statement) => ({ ...statement, params: cleaned(statement.params) });
17
39
  /** SQLite's extended constraint codes, by the rule they name. */
18
40
  const RULES = { 275: "check", 2067: "unique", 1555: "unique", 787: "foreign_key", 1299: "not_null" };
19
41
  /** Which rule refused a row, from SQLite's extended code; for a duplicate, its table and columns, which SQLite reports
20
- * only in its message ("UNIQUE constraint failed: t.a, t.b"): read here, in the SQLite adapter alone. */
42
+ * only in its message ("UNIQUE constraint failed: t.a, t.b"), or the index's name for an index on an expression
43
+ * ("UNIQUE constraint failed: index 'commands_one_answer'"): read here, in the SQLite adapter alone. */
21
44
  function constraintOf(errcode, message) {
22
45
  const rule = RULES[errcode];
23
46
  if (rule !== "unique")
24
47
  return rule ? { rule } : {};
48
+ const index = /UNIQUE constraint failed: index '([^']+)'$/.exec(message)?.[1];
49
+ if (index)
50
+ return { rule, index };
25
51
  const named = /UNIQUE constraint failed: (.+)$/.exec(message)?.[1]?.split(", ").map((part) => part.split("."));
26
52
  if (!named?.length || named.some((part) => part.length !== 2) || new Set(named.map(([table]) => table)).size !== 1)
27
53
  return { rule };
@@ -33,8 +59,13 @@ function typed(error) {
33
59
  return error.miss.kind === "fenced" ? new Fenced(error.miss.runId, error.miss.epoch) : new RunFinal(error.miss.runId);
34
60
  case "busy":
35
61
  return new StoreBusy(`the store stayed locked past its busy wait: ${error.message}`);
36
- case "constraint":
37
- return new StoreConstraint(error.message, constraintOf(error.errcode, error.message));
62
+ case "constraint": {
63
+ const refused = constraintOf(error.errcode, error.message);
64
+ // A second answer to one approval (the one-answer index): the answer written first stands.
65
+ if (refused.rule === "unique" && refused.index === ONE_ANSWER_INDEX)
66
+ return new AnswerTaken(error.message, refused.index);
67
+ return new StoreConstraint(error.message, refused);
68
+ }
38
69
  case "closed":
39
70
  return new StoreClosed();
40
71
  case "owned":
@@ -215,6 +246,8 @@ export class Connection {
215
246
  transaction(callback, { full = false, read = false, deadlineMs = DEFAULT_TRANSACTION_DEADLINE_MS, fromCall = false } = {}) {
216
247
  // `fromCall`: the deadline's end, counted from now (the queue's wait inside it); else counted from the begin.
217
248
  const until = fromCall ? Date.now() + deadlineMs : undefined;
249
+ // Where it was asked for: a deadline or a busy begin names it (holderNamed).
250
+ const opened = new Error("a store transaction");
218
251
  // Set when its deadline ran out while it still waited in the queue: its turn then begins nothing.
219
252
  let gaveUp = false;
220
253
  let started = false;
@@ -222,7 +255,7 @@ export class Connection {
222
255
  const run = this.#queued(async () => {
223
256
  started = true;
224
257
  if (gaveUp || (until !== undefined && Date.now() >= until))
225
- throw new StoreDeadline(deadlineMs);
258
+ throw holderNamed(new StoreDeadline(deadlineMs), { opened });
226
259
  // Its wait for the database's lock (another process's write) bounded by what the deadline leaves: a lock still held
227
260
  // when that runs out is the deadline's end, not the connection's own busy wait.
228
261
  const busyMs = until !== undefined ? Math.max(0, until - Date.now()) : undefined;
@@ -231,55 +264,63 @@ export class Connection {
231
264
  }
232
265
  catch (error) {
233
266
  if (error instanceof StoreBusy && busyMs !== undefined && busyMs < this.#busyTimeoutMs)
234
- throw new StoreDeadline(deadlineMs);
235
- throw error;
267
+ throw holderNamed(new StoreDeadline(deadlineMs), { opened });
268
+ throw error instanceof StoreBusy ? holderNamed(error, { opened }) : error;
236
269
  }
237
- let live = true;
238
- let clear = () => { };
239
- const deadline = new Promise((_, reject) => {
240
- const expire = () => reject(new StoreDeadline(deadlineMs));
241
- // Counted from its call (a lease's), the deadline stays the wall clock's: MCP_REFRESH_LEASE_MS is reckoned from
242
- // it. Counted from its begin, it is the time this process could run (store/deadline.ts runnableDeadline): while other work held
243
- // the event loop, a statement answered meanwhile waited behind it, and that time was no statement's.
244
- if (until !== undefined) {
245
- const timer = setTimeout(expire, Math.max(0, until - Date.now()));
246
- clear = () => clearTimeout(timer);
247
- }
248
- else
249
- clear = runnableDeadline(deadlineMs, expire).clear;
250
- });
251
- let value;
270
+ const open = { opened, began: Date.now() };
271
+ OPEN.add(open);
252
272
  try {
253
- // The worker answers in order: a statement already sent finishes before the rollback a deadline sends after it.
254
- const running = callback(this.#executor(() => live));
255
- // Past the deadline the callback's own end is nobody's: its refused next statement must not surface as an
256
- // unhandled rejection.
257
- running.catch(() => undefined);
258
- value = await Promise.race([running, deadline]);
259
- }
260
- catch (error) {
273
+ let live = true;
274
+ let clear = () => { };
275
+ const deadline = new Promise((_, reject) => {
276
+ const expire = () => reject(holderNamed(new StoreDeadline(deadlineMs), { opened }));
277
+ // Counted from its call (a lease's), the deadline stays the wall clock's: MCP_REFRESH_LEASE_MS is reckoned from
278
+ // it. Counted from its begin, it is the time this process could run (store/deadline.ts runnableDeadline): while other work held
279
+ // the event loop, a statement answered meanwhile waited behind it, and that time was no statement's.
280
+ if (until !== undefined) {
281
+ const timer = setTimeout(expire, Math.max(0, until - Date.now()));
282
+ clear = () => clearTimeout(timer);
283
+ }
284
+ else
285
+ clear = runnableDeadline(deadlineMs, expire).clear;
286
+ });
287
+ let value;
288
+ try {
289
+ // The worker answers in order: a statement already sent finishes before the rollback a deadline sends after it.
290
+ const running = callback(this.#executor(() => live));
291
+ // Past the deadline the callback's own end is nobody's: its refused next statement must not surface as an
292
+ // unhandled rejection.
293
+ running.catch(() => undefined);
294
+ value = await Promise.race([running, deadline]);
295
+ }
296
+ catch (error) {
297
+ live = false;
298
+ clear();
299
+ try {
300
+ await this.#send({ op: "rollback" });
301
+ }
302
+ catch (rollback) {
303
+ // A worker lost mid-transaction failed both: its loss is the one error, as every later call's.
304
+ if (this.#lost)
305
+ throw this.#lost;
306
+ throw new AggregateError([error, rollback], "the store's transaction failed, and so did its rollback");
307
+ }
308
+ throw error;
309
+ }
261
310
  live = false;
262
311
  clear();
263
- try {
312
+ // Counted from its call, a deadline reached by now is never committed past: rolled back, nothing written.
313
+ if (until !== undefined && Date.now() >= until) {
264
314
  await this.#send({ op: "rollback" });
315
+ throw holderNamed(new StoreDeadline(deadlineMs), { opened });
265
316
  }
266
- catch (rollback) {
267
- // A worker lost mid-transaction failed both: its loss is the one error, as every later call's.
268
- if (this.#lost)
269
- throw this.#lost;
270
- throw new AggregateError([error, rollback], "the store's transaction failed, and so did its rollback");
271
- }
272
- throw error;
317
+ await this.#send({ op: "commit" });
318
+ return value;
273
319
  }
274
- live = false;
275
- clear();
276
- // Counted from its call, a deadline reached by now is never committed past: rolled back, nothing written.
277
- if (until !== undefined && Date.now() >= until) {
278
- await this.#send({ op: "rollback" });
279
- throw new StoreDeadline(deadlineMs);
320
+ finally {
321
+ // Kept until the worker has answered the commit or rollback: until then this transaction still holds the lock.
322
+ OPEN.delete(open);
280
323
  }
281
- await this.#send({ op: "commit" });
282
- return value;
283
324
  });
284
325
  if (until === undefined)
285
326
  return run;
@@ -291,7 +332,7 @@ export class Connection {
291
332
  if (started)
292
333
  return;
293
334
  gaveUp = true;
294
- reject(new StoreDeadline(deadlineMs));
335
+ reject(holderNamed(new StoreDeadline(deadlineMs), { opened }));
295
336
  }, deadlineMs);
296
337
  });
297
338
  return Promise.race([run, queuedPast]).finally(() => clearTimeout(waitTimer));
@@ -2,17 +2,19 @@ import { type AlsoRow, type Claim, type RunPatch, type RunRow, type RunState } f
2
2
  import { type Dialect } from "../dialect.js";
3
3
  import type { SqliteExecutor } from "./connection.js";
4
4
  import { type StoreNow } from "../fence.js";
5
- /** A learning run's launch body: the learning harness, the run that learned as its input, and where it runs (on the
6
- * runner, no box: its only writes are the learning folder's one script). */
7
- /** A learning run's launch: harness "learning", its input the run that learned, and `model`, the grade model when one is
8
- * named (gradeModelOf; none: the agent's own grades it, as main's). No cap: main caps no grade. */
9
5
  /** A WHERE condition on `runs`: the run is no built-in learning run (one a kept learning names, queued with it), which no
10
6
  * list of runs names. */
11
7
  export declare const NOT_A_LEARNING_RUN = "id NOT IN (SELECT learning_run_id FROM learning_proposals WHERE learning_run_id IS NOT NULL)";
12
- export declare const learningLaunchOf: (runId: string, model?: string) => {
8
+ /** A learning run's launch: harness "learning", its input the run that learned (and the round it grades, past the first),
9
+ * where it runs (on the runner, no box: its only writes are the learning folder's one script), `model`, the grade model
10
+ * when one is named (gradeModelOf; none: the agent's own grades it, as main's), and `max_cost_usd`, what the run's cap
11
+ * left for its grade (`capUsd`: a figure that is not one is no room, $0, never no cap; none for an uncapped run). */
12
+ export declare const learningLaunchOf: (runId: string, model?: string, round?: number, capUsd?: number) => {
13
+ max_cost_usd?: number | undefined;
13
14
  model?: string | undefined;
14
15
  harness: string;
15
16
  input: {
17
+ round?: number | undefined;
16
18
  runId: string;
17
19
  };
18
20
  title: string;
@@ -51,7 +53,23 @@ export declare const runOf: (r: RunRecord) => RunRow;
51
53
  * run in the same statement. `dialect`: the connection's (store/dialect.ts), SQLite's by default. `clock`: the deadlines'
52
54
  * clock (fence.ts storeNow) the fence and left_running_at read; `now` bound by default. */
53
55
  export declare function applyRunPatch(tx: Pick<SqliteExecutor, "run" | "get">, claim: Pick<Claim, "runId" | "epoch">, patch: RunPatch, also: readonly AlsoRow[], now: number, dialect?: Dialect, clock?: StoreNow): Promise<RunRow>;
56
+ /** The one reopen a run that ended may take (runs.reopen, and a run's end with a person's message waiting): back to running
57
+ * with no runner (released: a runner claims it at once), its end's own fields cleared, its epoch, journal, cost and
58
+ * metrics kept. `where` holds only for an agentic run that ended completed or that a person stopped (state 'stopped',
59
+ * outcome 'stopped': its turn ended, never the run, as main's stop leaves one), not imported and not a learning run. A
60
+ * cancelled run, a failed one and a workflow run are over for good. */
61
+ export declare const REOPEN_SET = "state = 'running', runner = NULL, claimed_until = NULL, wake_at = NULL, backoff_until = NULL, ended_at = NULL, summary = NULL, outcome = NULL";
62
+ export declare const reopenableWhere: (d: Dialect) => string;
54
63
  /** After a write that made the run final has taken its own rows: every command row of the run still untaken is refused
55
64
  * with the end's reason, in that same transaction. The store takes no new row on a final run (RunFinal), so a row the
56
- * end left untaken would stay so for good, as it would if the runner died right after the end. */
57
- export declare function refuseLeftovers(tx: Pick<SqliteExecutor, "run">, runId: string, state: RunState | undefined, now: number): Promise<void>;
65
+ * end left untaken would stay so for good, as it would if the runner died right after the end.
66
+ * But a person's message (a steer row) that came while the run was ending, after its turn's answer (its end-of-run turn,
67
+ * or before its end: the adapter loop leaves it untaken), opens a run that ended completed again, in this same
68
+ * transaction, as main answers such a message once the end is in (runs.ts message: a completed run opens again, its
69
+ * message the next turn): the run is back to running and released (REOPEN_SET), the message waits untaken for the next
70
+ * claim, which runs it as a new turn, and only the run's other rows are refused. Every message so lands on one path: in
71
+ * before the end, it opens the run here; after it, the store refuses a new row (RunFinal) and runs.reopen takes it.
72
+ * A person's stop is the same (reopenableWhere): a message waiting at it is the run's next turn, as main's stop leaves a
73
+ * message submitted before it to run; a cancel's refuses it. A run left final here has its launch secrets erased (its
74
+ * launch row's `sealed`); a run opened again keeps the ones its waiting message wrote. */
75
+ export declare function refuseLeftovers(tx: Pick<SqliteExecutor, "run" | "get">, runId: string, state: RunState | undefined, now: number, dialect?: Dialect): Promise<void>;