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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) hide show
  1. package/CHANGELOG.md +263 -0
  2. package/README.md +339 -179
  3. package/dist/adapters.d.ts +15 -2
  4. package/dist/adapters.js +34 -2
  5. package/dist/agent-rows.d.ts +3 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +25 -5
  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 +90 -8
  13. package/dist/archil-settings.js +150 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/bash-read-only.d.ts +13 -0
  19. package/dist/bash-read-only.js +77 -0
  20. package/dist/box-image.d.ts +1 -97
  21. package/dist/box-image.js +4 -284
  22. package/dist/box-paths.d.ts +2 -7
  23. package/dist/box-paths.js +7 -13
  24. package/dist/box-settings.d.ts +0 -11
  25. package/dist/box-settings.js +4 -29
  26. package/dist/browser-commands.js +1 -1
  27. package/dist/browser-computer.d.ts +47 -3
  28. package/dist/browser-computer.js +286 -18
  29. package/dist/browser-cost.d.ts +2 -2
  30. package/dist/browser-cost.js +6 -4
  31. package/dist/browser-person.d.ts +19 -2
  32. package/dist/browser-person.js +55 -6
  33. package/dist/browser-wait-ended.d.ts +23 -0
  34. package/dist/browser-wait-ended.js +42 -0
  35. package/dist/cap.d.ts +19 -44
  36. package/dist/cap.js +31 -77
  37. package/dist/cli.js +36 -27
  38. package/dist/computer-keys.d.ts +20 -10
  39. package/dist/computer-keys.js +36 -57
  40. package/dist/computer-routes.d.ts +1 -4
  41. package/dist/computer-routes.js +3 -5
  42. package/dist/computer-setting.d.ts +8 -5
  43. package/dist/computer-setting.js +91 -26
  44. package/dist/computer-view.d.ts +11 -2
  45. package/dist/computer-view.js +2 -1
  46. package/dist/computers.d.ts +54 -8
  47. package/dist/computers.js +101 -22
  48. package/dist/console/assets/index-BI4Byidu.js +550 -0
  49. package/dist/console/assets/index-C19gUF2n.css +1 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/content-filter.d.ts +7 -0
  52. package/dist/content-filter.js +23 -0
  53. package/dist/decision-cap.d.ts +7 -29
  54. package/dist/decision-cap.js +3 -94
  55. package/dist/docker-daemon.d.ts +2 -2
  56. package/dist/docker-daemon.js +2 -2
  57. package/dist/errors.d.ts +1 -0
  58. package/dist/errors.js +8 -5
  59. package/dist/explain.js +3 -1
  60. package/dist/faux-computers.js +4 -0
  61. package/dist/files.d.ts +1 -9
  62. package/dist/files.js +1 -9
  63. package/dist/github-connection.js +25 -7
  64. package/dist/github-faux.d.ts +26 -0
  65. package/dist/github-faux.js +76 -0
  66. package/dist/github.d.ts +28 -4
  67. package/dist/github.js +46 -10
  68. package/dist/gpu-words.d.ts +14 -0
  69. package/dist/gpu-words.js +21 -0
  70. package/dist/graph-served.d.ts +5 -3
  71. package/dist/graph-served.js +14 -6
  72. package/dist/graph-view.d.ts +2 -0
  73. package/dist/graph-view.js +29 -2
  74. package/dist/handed-values.d.ts +1 -1
  75. package/dist/handed-values.js +1 -1
  76. package/dist/harness-install.d.ts +60 -3
  77. package/dist/harness-install.js +322 -34
  78. package/dist/harness-opencode/harness.js +0 -1
  79. package/dist/harness-opencode/host/policy.js +2 -2
  80. package/dist/harness.js +1 -1
  81. package/dist/host-tools.d.ts +8 -9
  82. package/dist/host-tools.js +7 -7
  83. package/dist/index.d.ts +2 -3
  84. package/dist/index.js +2 -2
  85. package/dist/key-refusal.d.ts +1 -1
  86. package/dist/key-refusal.js +2 -2
  87. package/dist/learn/check.d.ts +10 -2
  88. package/dist/learn/check.js +126 -8
  89. package/dist/learn/commit.d.ts +40 -6
  90. package/dist/learn/commit.js +164 -20
  91. package/dist/learn/folder.d.ts +11 -3
  92. package/dist/learn/folder.js +40 -16
  93. package/dist/learn/grade.d.ts +22 -2
  94. package/dist/learn/grade.js +127 -19
  95. package/dist/learn/index.d.ts +2 -2
  96. package/dist/learn/index.js +2 -2
  97. package/dist/learn/learning.sh +11 -13
  98. package/dist/learn/notes.d.ts +17 -3
  99. package/dist/learn/notes.js +19 -6
  100. package/dist/learn/reflect.d.ts +5 -2
  101. package/dist/learn/reflect.js +48 -32
  102. package/dist/learn/skills.d.ts +52 -5
  103. package/dist/learn/skills.js +104 -21
  104. package/dist/learned-nodes.d.ts +18 -0
  105. package/dist/learned-nodes.js +8 -0
  106. package/dist/learned-workflow.d.ts +27 -13
  107. package/dist/learned-workflow.js +110 -38
  108. package/dist/learning-cost.d.ts +79 -0
  109. package/dist/learning-cost.js +69 -0
  110. package/dist/learning-routes.d.ts +48 -2
  111. package/dist/learning-routes.js +99 -28
  112. package/dist/learning-run.d.ts +7 -5
  113. package/dist/learning-run.js +9 -6
  114. package/dist/learning-words.d.ts +3 -0
  115. package/dist/learning-words.js +6 -2
  116. package/dist/learning.d.ts +13 -28
  117. package/dist/learning.js +4 -18
  118. package/dist/llm.d.ts +4 -1
  119. package/dist/llm.js +4 -2
  120. package/dist/mcp-gateway.d.ts +6 -0
  121. package/dist/mcp-gateway.js +11 -1
  122. package/dist/mcp-probe.d.ts +8 -1
  123. package/dist/mcp-probe.js +62 -20
  124. package/dist/mcp-secret-writes.js +4 -0
  125. package/dist/mcp-servers-store.d.ts +12 -12
  126. package/dist/mcp-servers-store.js +8 -3
  127. package/dist/model.d.ts +8 -5
  128. package/dist/model.js +14 -6
  129. package/dist/openapi.d.ts +2 -0
  130. package/dist/openapi.js +236 -55
  131. package/dist/owner.d.ts +0 -1
  132. package/dist/owner.js +0 -2
  133. package/dist/pause.d.ts +2 -19
  134. package/dist/pause.js +5 -74
  135. package/dist/place-offers.d.ts +97 -0
  136. package/dist/place-offers.js +206 -0
  137. package/dist/place.d.ts +9 -13
  138. package/dist/place.js +22 -32
  139. package/dist/port-models.d.ts +12 -4
  140. package/dist/port-models.js +31 -9
  141. package/dist/print.d.ts +1 -8
  142. package/dist/print.js +1 -14
  143. package/dist/propose.d.ts +3 -0
  144. package/dist/propose.js +25 -19
  145. package/dist/run-cut.d.ts +5 -0
  146. package/dist/run-cut.js +19 -0
  147. package/dist/run-db.js +3 -3
  148. package/dist/run-launch.d.ts +18 -3
  149. package/dist/run-launch.js +11 -5
  150. package/dist/run-learning-served.d.ts +12 -1
  151. package/dist/run-manifest.d.ts +2 -2
  152. package/dist/run-manifest.js +2 -2
  153. package/dist/run-reads-over-store.d.ts +4 -2
  154. package/dist/run-reads-over-store.js +10 -8
  155. package/dist/run-secrets.js +3 -3
  156. package/dist/run-timeline-served.js +60 -38
  157. package/dist/run-view.d.ts +35 -16
  158. package/dist/run-view.js +64 -35
  159. package/dist/runnable.d.ts +6 -3
  160. package/dist/runnable.js +20 -4
  161. package/dist/runner/adapter-loop.d.ts +46 -5
  162. package/dist/runner/adapter-loop.js +381 -56
  163. package/dist/runner/adapter-run-spec.d.ts +46 -4
  164. package/dist/runner/adapter-run-spec.js +200 -45
  165. package/dist/runner/adapters/pi.d.ts +39 -3
  166. package/dist/runner/adapters/pi.js +124 -29
  167. package/dist/runner/beside.d.ts +8 -0
  168. package/dist/runner/beside.js +24 -2
  169. package/dist/runner/claim-secrets.d.ts +6 -0
  170. package/dist/runner/claim-secrets.js +15 -1
  171. package/dist/runner/cli-run-spec.d.ts +10 -0
  172. package/dist/runner/cli-run-spec.js +207 -64
  173. package/dist/runner/commands.d.ts +5 -1
  174. package/dist/runner/commands.js +3 -3
  175. package/dist/runner/conformance/harness.d.ts +1 -1
  176. package/dist/runner/conformance/harness.js +13 -10
  177. package/dist/runner/github-app.d.ts +7 -2
  178. package/dist/runner/github-app.js +46 -15
  179. package/dist/runner/harness-loops.d.ts +6 -1
  180. package/dist/runner/harness-loops.js +24 -1
  181. package/dist/runner/journal-kinds.d.ts +53 -7
  182. package/dist/runner/journal-kinds.js +29 -1
  183. package/dist/runner/learning-end.d.ts +15 -0
  184. package/dist/runner/learning-end.js +113 -20
  185. package/dist/runner/learning-factory.js +6 -2
  186. package/dist/runner/learning-loop.d.ts +75 -1
  187. package/dist/runner/learning-loop.js +215 -22
  188. package/dist/runner/learning-seed.d.ts +8 -0
  189. package/dist/runner/learning-seed.js +7 -1
  190. package/dist/runner/loop-contract.d.ts +12 -0
  191. package/dist/runner/loop-contract.js +6 -0
  192. package/dist/runner/loop.d.ts +5 -1
  193. package/dist/runner/loop.js +20 -0
  194. package/dist/runner/main.d.ts +9 -4
  195. package/dist/runner/main.js +38 -13
  196. package/dist/runner/mcp-claim.d.ts +7 -0
  197. package/dist/runner/mcp-claim.js +35 -2
  198. package/dist/runner/mcp-github.d.ts +15 -4
  199. package/dist/runner/mcp-github.js +55 -11
  200. package/dist/runner/mcp-run.d.ts +2 -0
  201. package/dist/runner/mcp-run.js +2 -0
  202. package/dist/runner/metrics.d.ts +18 -1
  203. package/dist/runner/metrics.js +81 -1
  204. package/dist/runner/model-route.d.ts +6 -0
  205. package/dist/runner/model-route.js +5 -2
  206. package/dist/runner/pr-checkout.d.ts +59 -0
  207. package/dist/runner/pr-checkout.js +176 -0
  208. package/dist/runner/reflect-hook.d.ts +1 -0
  209. package/dist/runner/reflect-hook.js +3 -3
  210. package/dist/runner/runner.js +136 -19
  211. package/dist/runner/spec-holds.d.ts +13 -3
  212. package/dist/runner/spec-holds.js +13 -10
  213. package/dist/runner/store-port.d.ts +4 -1
  214. package/dist/runner/store-secrets.js +17 -1
  215. package/dist/runner/subagent.d.ts +44 -0
  216. package/dist/runner/subagent.js +188 -0
  217. package/dist/runner/workflow-host.d.ts +25 -4
  218. package/dist/runner/workflow-host.js +26 -4
  219. package/dist/runner/workflow-loop.d.ts +9 -3
  220. package/dist/runner/workflow-loop.js +17 -10
  221. package/dist/runner/workflow-spec.d.ts +28 -13
  222. package/dist/runner/workflow-spec.js +247 -102
  223. package/dist/runs-over-store.d.ts +18 -7
  224. package/dist/runs-over-store.js +149 -31
  225. package/dist/seal-key.d.ts +0 -2
  226. package/dist/seal-key.js +0 -2
  227. package/dist/sealing.js +1 -2
  228. package/dist/secret-cut.d.ts +1 -1
  229. package/dist/secret-cut.js +1 -1
  230. package/dist/server-lock.js +4 -5
  231. package/dist/server.d.ts +49 -63
  232. package/dist/server.js +429 -230
  233. package/dist/stop-signals.d.ts +4 -2
  234. package/dist/stop-signals.js +5 -3
  235. package/dist/store/agent-body.d.ts +14 -3
  236. package/dist/store/agent-body.js +22 -8
  237. package/dist/store/deadline.d.ts +18 -0
  238. package/dist/store/deadline.js +49 -0
  239. package/dist/store/index.d.ts +3 -3
  240. package/dist/store/index.js +2 -2
  241. package/dist/store/journal/storage.js +2 -1
  242. package/dist/store/postgres/connection.d.ts +4 -0
  243. package/dist/store/postgres/connection.js +64 -13
  244. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  245. package/dist/store/schema.d.ts +2 -1
  246. package/dist/store/schema.js +11 -8
  247. package/dist/store/seal.d.ts +13 -0
  248. package/dist/store/seal.js +19 -0
  249. package/dist/store/sqlite/connection.d.ts +5 -0
  250. package/dist/store/sqlite/connection.js +88 -82
  251. package/dist/store/sqlite/run-patch.d.ts +18 -2
  252. package/dist/store/sqlite/run-patch.js +31 -2
  253. package/dist/store/sqlite/store.js +65 -11
  254. package/dist/store/store.d.ts +62 -12
  255. package/dist/store/store.js +22 -1
  256. package/dist/store-reads/analytics.js +3 -2
  257. package/dist/store-reads/cap.d.ts +1 -3
  258. package/dist/store-reads/cap.js +8 -6
  259. package/dist/store-reads/decisions.d.ts +2 -2
  260. package/dist/store-reads/decisions.js +3 -6
  261. package/dist/store-reads/journal.js +83 -15
  262. package/dist/store-reads/learning.d.ts +73 -3
  263. package/dist/store-reads/learning.js +232 -9
  264. package/dist/store-reads/runs.d.ts +6 -4
  265. package/dist/store-reads/runs.js +17 -10
  266. package/dist/store-reads/stats.js +5 -1
  267. package/dist/store-view.d.ts +15 -1
  268. package/dist/store-view.js +88 -29
  269. package/dist/template-eval.js +2 -1
  270. package/dist/templates.d.ts +73 -4
  271. package/dist/templates.js +113 -23
  272. package/dist/timeline/timeline.d.ts +11 -1
  273. package/dist/timeline/timeline.js +19 -4
  274. package/dist/tool-blurbs.js +1 -0
  275. package/dist/tool-budget.d.ts +26 -0
  276. package/dist/tool-budget.js +56 -0
  277. package/dist/tool-gate.d.ts +13 -3
  278. package/dist/tool-gate.js +15 -7
  279. package/dist/tool-plane.d.ts +42 -29
  280. package/dist/tool-plane.js +64 -27
  281. package/dist/tools.d.ts +53 -39
  282. package/dist/tools.js +174 -79
  283. package/dist/trigger-signatures.d.ts +1 -0
  284. package/dist/trigger-signatures.js +3 -1
  285. package/dist/triggers.d.ts +3 -3
  286. package/dist/triggers.js +2 -2
  287. package/dist/turn-end.d.ts +0 -3
  288. package/dist/turn-end.js +0 -3
  289. package/dist/uploads.d.ts +28 -5
  290. package/dist/uploads.js +82 -9
  291. package/dist/usage-lines.d.ts +1 -1
  292. package/dist/usage.d.ts +1 -47
  293. package/dist/usage.js +3 -82
  294. package/dist/validate.d.ts +8 -0
  295. package/dist/validate.js +40 -3
  296. package/dist/webhooks.d.ts +2 -1
  297. package/dist/webhooks.js +5 -2
  298. package/dist/workflow/decision-recovery.d.ts +23 -0
  299. package/dist/workflow/decision-recovery.js +80 -0
  300. package/dist/workflow/decisions.d.ts +134 -0
  301. package/dist/workflow/decisions.js +46 -0
  302. package/dist/workflow/host-session.d.ts +5 -0
  303. package/dist/workflow/host-session.js +85 -0
  304. package/dist/workflow/host-tools.d.ts +3 -0
  305. package/dist/workflow/host-tools.js +3 -0
  306. package/dist/workflow/node-runner.d.ts +112 -0
  307. package/dist/workflow/node-runner.js +270 -0
  308. package/dist/workflow/node.d.ts +88 -0
  309. package/dist/workflow/node.js +99 -0
  310. package/dist/workflow/operator-error.d.ts +4 -0
  311. package/dist/workflow/operator-error.js +4 -0
  312. package/dist/workflow/pi-versions.d.ts +9 -0
  313. package/dist/workflow/pi-versions.js +8 -0
  314. package/dist/workflow/readers.d.ts +36 -0
  315. package/dist/workflow/readers.js +145 -0
  316. package/dist/workflow/record-file.d.ts +10 -0
  317. package/dist/workflow/record-file.js +56 -0
  318. package/dist/workflow/record-tool.d.ts +76 -0
  319. package/dist/workflow/record-tool.js +126 -0
  320. package/dist/workflow/record.d.ts +151 -0
  321. package/dist/workflow/record.js +401 -0
  322. package/dist/workflow/run-error.d.ts +16 -0
  323. package/dist/workflow/run-error.js +26 -0
  324. package/dist/workflow/runner.d.ts +6 -0
  325. package/dist/workflow/runner.js +240 -0
  326. package/dist/workflow/store.d.ts +23 -0
  327. package/dist/workflow/store.js +242 -0
  328. package/dist/workflow/task.d.ts +133 -0
  329. package/dist/workflow/task.js +411 -0
  330. package/dist/workflow/thinking.d.ts +3 -0
  331. package/dist/workflow/thinking.js +7 -0
  332. package/dist/workflow/tool-context.d.ts +21 -0
  333. package/dist/workflow/tool-context.js +13 -0
  334. package/dist/workflow/types.d.ts +126 -0
  335. package/dist/workflow/types.js +1 -0
  336. package/dist/workflow/wal.d.ts +11 -0
  337. package/dist/workflow/wal.js +106 -0
  338. package/dist/workflow-run.d.ts +1 -1
  339. package/dist/workspace/agent-computer.d.ts +137 -0
  340. package/dist/workspace/agent-computer.js +292 -0
  341. package/dist/workspace/archil-claim.d.ts +13 -2
  342. package/dist/workspace/archil-claim.js +22 -13
  343. package/dist/workspace/archil-disk.d.ts +10 -1
  344. package/dist/workspace/archil-disk.js +4 -0
  345. package/dist/workspace/archil-disks.d.ts +49 -0
  346. package/dist/workspace/archil-disks.js +185 -0
  347. package/dist/workspace/archil-exec.d.ts +12 -2
  348. package/dist/workspace/archil-exec.js +18 -3
  349. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  350. package/dist/workspace/archil-mount-credential.js +13 -4
  351. package/dist/workspace/archil.d.ts +2 -2
  352. package/dist/workspace/archil.js +25 -5
  353. package/dist/workspace/attach.js +2 -0
  354. package/dist/workspace/computer-deps.d.ts +18 -11
  355. package/dist/workspace/computer-deps.js +64 -40
  356. package/dist/workspace/computer-for-claim.d.ts +47 -9
  357. package/dist/workspace/computer-for-claim.js +236 -24
  358. package/dist/workspace/computer-janitor.d.ts +3 -2
  359. package/dist/workspace/computer-janitor.js +43 -9
  360. package/dist/workspace/computer-ledger.d.ts +3 -8
  361. package/dist/workspace/computer-ledger.js +7 -3
  362. package/dist/workspace/computer-providers.d.ts +5 -3
  363. package/dist/workspace/computer-providers.js +11 -9
  364. package/dist/workspace/hands.d.ts +5 -2
  365. package/dist/workspace/hands.js +4 -3
  366. package/dist/workspace/index.d.ts +5 -4
  367. package/dist/workspace/index.js +2 -1
  368. package/dist/workspace/local.d.ts +3 -0
  369. package/dist/workspace/local.js +9 -0
  370. package/dist/workspace/paths.js +3 -2
  371. package/dist/workspace/pi-env.d.ts +4 -0
  372. package/dist/workspace/pi-env.js +3 -2
  373. package/dist/workspace/resolve-computer.d.ts +48 -12
  374. package/dist/workspace/resolve-computer.js +88 -19
  375. package/dist/workspace/run-disk.d.ts +34 -0
  376. package/dist/workspace/run-disk.js +91 -0
  377. package/dist/workspace/run-tools.d.ts +6 -4
  378. package/dist/workspace/run-tools.js +17 -9
  379. package/dist/workspace/server-run-workspace.d.ts +3 -2
  380. package/dist/workspace/server-run-workspace.js +17 -4
  381. package/dist/workspace/workspace.d.ts +5 -0
  382. package/dist/workspace.d.ts +0 -3
  383. package/dist/workspace.js +2 -15
  384. package/package.json +11 -16
  385. package/skills/agentrun-serve/SKILL.md +1 -1
  386. package/templates/README.md +11 -8
  387. package/templates/code-review/agent.md +27 -11
  388. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  389. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  390. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  391. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  392. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  393. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  394. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  395. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  396. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  397. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  398. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  399. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  400. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  401. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  402. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  404. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  405. package/templates/code-review/evals/re-review/prompt.md +1 -1
  406. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  407. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  408. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  409. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  410. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  411. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  412. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  413. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  414. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  415. package/templates/code-review/findings.schema.json +131 -27
  416. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  417. package/templates/code-review/skills/review/DEEP.md +130 -0
  418. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  419. package/templates/code-review/skills/review/SKILL.md +104 -154
  420. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  421. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  422. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  423. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  424. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  425. package/templates/release-notes/agent.md +11 -0
  426. package/dist/box/record.d.ts +0 -6
  427. package/dist/box/record.js +0 -41
  428. package/dist/box/sweep.d.ts +0 -53
  429. package/dist/box/sweep.js +0 -193
  430. package/dist/box-egress-vm.d.ts +0 -118
  431. package/dist/box-egress-vm.js +0 -354
  432. package/dist/box-egress.d.ts +0 -105
  433. package/dist/box-egress.js +0 -256
  434. package/dist/box-relay-vm.d.ts +0 -84
  435. package/dist/box-relay-vm.js +0 -437
  436. package/dist/box-relay.d.ts +0 -36
  437. package/dist/box-relay.js +0 -207
  438. package/dist/boxes.d.ts +0 -109
  439. package/dist/boxes.js +0 -249
  440. package/dist/budget.d.ts +0 -76
  441. package/dist/budget.js +0 -204
  442. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  443. package/dist/console/assets/index-opTN5Naq.css +0 -1
  444. package/dist/daytona-api.d.ts +0 -10
  445. package/dist/daytona-api.js +0 -20
  446. package/dist/egress-proxy.d.ts +0 -45
  447. package/dist/egress-proxy.js +0 -416
  448. package/dist/egress-table.d.ts +0 -24
  449. package/dist/egress-table.js +0 -165
  450. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -15,8 +15,10 @@ export type StopDeps = {
15
15
  export declare const REPEAT_MS = 1000;
16
16
  /** How long past its runs' drain bound a stop may take before it stops at once. */
17
17
  export declare const DEADLINE_MARGIN_MS = 15000;
18
- /** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once. */
18
+ /** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once. `askedAt`: when
19
+ * the stop was asked, when earlier than this call (a signal during the start, cli.ts), so a second signal is timed from
20
+ * the first. */
19
21
  export declare function stopOnSignals(deps: StopDeps, { repeatMs, marginMs }?: {
20
22
  repeatMs?: number | undefined;
21
23
  marginMs?: number | undefined;
22
- }): () => void;
24
+ }): (askedAt?: number) => void;
@@ -7,7 +7,9 @@
7
7
  export const REPEAT_MS = 1_000;
8
8
  /** How long past its runs' drain bound a stop may take before it stops at once. */
9
9
  export const DEADLINE_MARGIN_MS = 15_000;
10
- /** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once. */
10
+ /** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once. `askedAt`: when
11
+ * the stop was asked, when earlier than this call (a signal during the start, cli.ts), so a second signal is timed from
12
+ * the first. */
11
13
  export function stopOnSignals(deps, { repeatMs = REPEAT_MS, marginMs = DEADLINE_MARGIN_MS } = {}) {
12
14
  const now = deps.now ?? Date.now;
13
15
  const setTimer = deps.setTimer ?? ((run, ms) => void setTimeout(run, ms).unref());
@@ -25,13 +27,13 @@ export function stopOnSignals(deps, { repeatMs = REPEAT_MS, marginMs = DEADLINE_
25
27
  const { runs } = deps.stopping();
26
28
  end(130, `${why}; runs resume on the next start${runs > 0 ? ` (${runs} ${runs === 1 ? "was" : "were"} running)` : ""}`);
27
29
  };
28
- return () => {
30
+ return (askedAt) => {
29
31
  if (stopAt !== undefined) {
30
32
  if (now() - stopAt >= repeatMs)
31
33
  stopNow("stopping now");
32
34
  return;
33
35
  }
34
- stopAt = now();
36
+ stopAt = askedAt ?? now();
35
37
  setTimer(() => stopNow("the stop passed its deadline, stopping now"), deps.stopping().boundMs + marginMs);
36
38
  void deps.close().then(() => end(0));
37
39
  };
@@ -27,35 +27,43 @@ export type RevisionPlace = {
27
27
  box?: string;
28
28
  };
29
29
  /** A revision's computer (computer-setting.ts): its kind and the provider that serves it, ids its host knows, and a
30
- * sandbox's GPUs, a type its provider names and how many; `place` is its v2 view. */
30
+ * sandbox's GPUs, a type its provider names and how many; `place` is its v2 view. `image`: one the provider offers for
31
+ * the kind, absent for its default. */
31
32
  export type RevisionComputer = {
32
33
  kind: string;
33
34
  provider?: string;
35
+ image?: string;
34
36
  gpu?: {
35
37
  type: string;
36
38
  count: number;
37
39
  };
40
+ persistent?: boolean;
38
41
  };
39
42
  /** A revision's tool settings as its body keeps them: a map of a tool's key to its settings ({provider?, permission?,
40
43
  * pin?}), checked and made canonical by the caller (agents-store.ts, through tool-plane's settingsIssues +
41
44
  * canonicalToolSettings, the one copy). The store body holds it as it is given; this validator never reimplements it. */
42
45
  export type ToolSettings = Record<string, unknown>;
46
+ /** The model of each tier an agentic revision names (its definition's `model_tiers`: fast, strong), each "provider/model-id". */
47
+ export type ModelTiers = Partial<Record<"fast" | "strong", string>>;
43
48
  export type AgenticBody = {
44
49
  instructions: string;
45
50
  skills: Record<string, string>;
46
51
  tools: string[];
47
52
  model?: string;
53
+ modelTiers?: ModelTiers;
48
54
  thinking?: string;
49
55
  prompts?: Record<string, PromptVariant>;
50
56
  harness?: string;
51
57
  place?: RevisionPlace;
52
58
  computer?: RevisionComputer;
53
- learning?: boolean;
59
+ learning?: boolean | "notes";
54
60
  toolSettings?: ToolSettings;
55
61
  maxCostUsd?: number;
56
62
  capMode?: string;
57
63
  approvals?: "ask" | "never";
58
64
  outputSchema?: Record<string, unknown>;
65
+ maxToolCalls?: number;
66
+ checkout?: "pull_request";
59
67
  };
60
68
  export type WorkflowBody = {
61
69
  workflow: Record<string, unknown>;
@@ -77,17 +85,20 @@ export type RevisionBodyInput = {
77
85
  skills?: Record<string, string>;
78
86
  tools?: string[];
79
87
  model?: string;
88
+ modelTiers?: ModelTiers;
80
89
  thinking?: string;
81
90
  prompts?: Record<string, PromptVariant>;
82
91
  harness?: string;
83
92
  place?: unknown;
84
93
  computer?: unknown;
85
- learning?: boolean;
94
+ learning?: boolean | "notes";
86
95
  toolSettings?: ToolSettings;
87
96
  maxCostUsd?: number;
88
97
  capMode?: string;
89
98
  approvals?: "ask" | "never";
90
99
  outputSchema?: Record<string, unknown>;
100
+ maxToolCalls?: number;
101
+ checkout?: "pull_request";
91
102
  } | {
92
103
  kind: "workflow";
93
104
  workflow: unknown;
@@ -1,4 +1,4 @@
1
- // The agent body validator (the P4 fold of pi-durable-agent's agent-store.ts bodyOf, with kinds.ts's canonical JSON): what
1
+ // The agent body validator (with canonical JSON): what
2
2
  // a revision's stored body may be, checked before anything is written, so a refusal makes no agent and no revision. It is
3
3
  // the one check the control plane runs over a revision's body, kept with the store (A) it writes into. The body keeps a
4
4
  // skill path to its text's SHA-256 (two revisions with the same files are one body); the texts ride beside it on the
@@ -44,18 +44,21 @@ function placeOf(place) {
44
44
  }
45
45
  /** A GPU type as a body keeps it: the vendor's own name ("T4", "A100-80GB", "RTX-PRO-6000"). */
46
46
  const GPU_TYPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
47
- /** A computer as a body keeps it: `{kind, provider?, gpu?}`, nothing else: kind and provider ids, and gpu `{type, count}`,
48
- * a GPU type name and a whole count from 1. */
47
+ /** A computer as a body keeps it: `{kind, provider?, image?, gpu?, persistent?}`, nothing else: kind and provider ids,
48
+ * image a name with no spaces around it, gpu `{type, count}`, a GPU type name and a whole count from 1, and persistent a
49
+ * boolean. */
49
50
  function computerOf(computer) {
50
- if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || Object.keys(computer).some((key) => key !== "kind" && key !== "provider" && key !== "gpu"))
51
- invalid("the computer is not {kind, provider?, gpu?}, kind and provider each an id (lowercase letters, digits and dashes)");
51
+ const image = isObject(computer) ? computer.image : undefined;
52
+ const named = (value) => typeof value === "string" && value !== "" && value === value.trim();
53
+ if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || (computer.persistent !== undefined && typeof computer.persistent !== "boolean") || Object.keys(computer).some((key) => key !== "kind" && key !== "provider" && key !== "image" && key !== "gpu" && key !== "persistent"))
54
+ invalid("the computer is not {kind, provider?, image?, gpu?, persistent?}, kind and provider each an id (lowercase letters, digits and dashes), image a name, persistent a boolean");
52
55
  const ok = computer;
53
56
  const gpu = ok.gpu;
54
57
  if (gpu !== undefined && (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count") || typeof gpu.type !== "string" || !GPU_TYPE.test(gpu.type) || !Number.isSafeInteger(gpu.count) || gpu.count < 1)) {
55
58
  invalid("the computer's gpu is not {type, count}: a GPU type name (letters, digits, dots, underscores and dashes) and a whole count from 1");
56
59
  }
57
60
  const kept = gpu;
58
- return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}) };
61
+ return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(ok.image !== undefined ? { image: ok.image } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}), ...(ok.persistent !== undefined ? { persistent: ok.persistent } : {}) };
59
62
  }
60
63
  /** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
61
64
  * write. The body keeps each skill path to its text's SHA-256; `skills` is the texts, for the revision's row. */
@@ -107,21 +110,32 @@ export function bodyOf(input) {
107
110
  for (const field of ["model", "thinking"])
108
111
  if (input[field] !== undefined && (typeof input[field] !== "string" || input[field] === ""))
109
112
  invalid(`the ${field} is not a non-empty string`);
110
- if (input.learning !== undefined && typeof input.learning !== "boolean")
111
- invalid("learning is not true or false");
113
+ if (input.learning !== undefined && typeof input.learning !== "boolean" && input.learning !== "notes")
114
+ invalid("learning is not true, false or \"notes\"");
112
115
  if (input.outputSchema !== undefined && !isObject(input.outputSchema))
113
116
  invalid("the outputSchema is not a JSON object");
117
+ if (input.checkout !== undefined && input.checkout !== "pull_request")
118
+ invalid("the checkout is not pull_request");
119
+ if (input.modelTiers !== undefined && !(isObject(input.modelTiers) && Object.keys(input.modelTiers).length && Object.entries(input.modelTiers).every(([tier, ref]) => (tier === "fast" || tier === "strong") && typeof ref === "string" && ref !== "")))
120
+ invalid("the modelTiers are not fast and strong to a non-empty model");
121
+ if (input.maxToolCalls !== undefined && !(Number.isSafeInteger(input.maxToolCalls) && input.maxToolCalls > 0))
122
+ invalid("the maxToolCalls is not a whole number above 0");
114
123
  const body = {
115
124
  instructions: input.instructions,
116
125
  skills: skillShas,
117
126
  tools: [...tools],
118
127
  ...(input.model !== undefined ? { model: input.model } : {}),
128
+ ...(input.modelTiers !== undefined ? { modelTiers: Object.fromEntries(Object.entries(input.modelTiers).sort(([a], [b]) => a.localeCompare(b))) } : {}),
119
129
  ...(input.thinking !== undefined ? { thinking: input.thinking } : {}),
120
130
  ...(input.prompts !== undefined ? { prompts: structuredClone(input.prompts) } : {}),
121
131
  ...host,
122
132
  ...(input.learning !== undefined ? { learning: input.learning } : {}),
123
133
  // The JSON Schema its final answer's structured part meets (definition.output_schema): a completed run's result.output.
124
134
  ...(input.outputSchema !== undefined ? { outputSchema: structuredClone(input.outputSchema) } : {}),
135
+ // What the server checks out in each run's folder before its first turn (runner/pr-checkout.ts).
136
+ ...(input.checkout !== undefined ? { checkout: input.checkout } : {}),
137
+ // The tool calls each conversation of its runs may make (tool-budget.ts).
138
+ ...(input.maxToolCalls !== undefined ? { maxToolCalls: input.maxToolCalls } : {}),
125
139
  // The agent's unattended policy (PR #2003): the runner's gate reads it from the revision body at claim (`unattended`
126
140
  // below: "never" alone is kept).
127
141
  ...capped,
@@ -0,0 +1,18 @@
1
+ /** How often an open transaction's deadline looks at the process's event loop, and how far past its look a look may
2
+ * come before the gap counts as the process held up (runnableDeadline). */
3
+ export declare const TICK_MS = 50;
4
+ export declare const STALL_MS = 50;
5
+ /** A running deadline: `clear()` stops it; `held()` is the time it gave back so far, the process held up, so a bound
6
+ * reckoned from the deadline's due time (a Postgres commit's) moves with it. A hold that ended since the last look is
7
+ * counted as `held()` reads it, never left for a look that would come after the bound was reckoned. */
8
+ export type RunnableDeadline = {
9
+ clear(): void;
10
+ held(): number;
11
+ };
12
+ /** Calls `expire` once `ms` of the time this process could run have passed, counted from now on the monotonic clock
13
+ * (performance.now: the host's clock set forward or back is never counted). A look every TICK_MS measures the event
14
+ * loop: a gap more than STALL_MS past its look was the process held up by other work (a harness binary hashed, a
15
+ * command run synchronously, the machine holding the process), wherever in the transaction it fell, before its
16
+ * deadline or across it, and is not counted. A wait of the transaction's own (a call awaited inside it) leaves the
17
+ * loop free, so it counts in full and is refused on time. */
18
+ export declare function runnableDeadline(ms: number, expire: () => void): RunnableDeadline;
@@ -0,0 +1,49 @@
1
+ // A store transaction's deadline counted from its begin, the one rule both connections keep (sqlite/connection.ts,
2
+ // postgres/connection.ts): only the time this process could run counts. One counted from its call (a lease's renew, a
3
+ // fromCall transaction) stays each connection's wall-clock timer.
4
+ /** How often an open transaction's deadline looks at the process's event loop, and how far past its look a look may
5
+ * come before the gap counts as the process held up (runnableDeadline). */
6
+ export const TICK_MS = 50;
7
+ export const STALL_MS = 50;
8
+ /** Calls `expire` once `ms` of the time this process could run have passed, counted from now on the monotonic clock
9
+ * (performance.now: the host's clock set forward or back is never counted). A look every TICK_MS measures the event
10
+ * loop: a gap more than STALL_MS past its look was the process held up by other work (a harness binary hashed, a
11
+ * command run synchronously, the machine holding the process), wherever in the transaction it fell, before its
12
+ * deadline or across it, and is not counted. A wait of the transaction's own (a call awaited inside it) leaves the
13
+ * loop free, so it counts in full and is refused on time. */
14
+ export function runnableDeadline(ms, expire) {
15
+ // Cleared with the functions they were set with: a caller that swaps the global timers while a transaction is open
16
+ // (node:test's mocked timers, enabled mid-run) would otherwise clear nothing, and the look's interval would hold the
17
+ // process open for good.
18
+ const [after, every, cancel, stop] = [setTimeout, setInterval, clearTimeout, clearInterval];
19
+ const start = performance.now();
20
+ let last = start;
21
+ let held = 0;
22
+ const look = () => {
23
+ const now = performance.now();
24
+ const gap = now - last - TICK_MS;
25
+ if (gap > STALL_MS)
26
+ held += gap;
27
+ last = now;
28
+ return now;
29
+ };
30
+ const ticks = every(look, TICK_MS);
31
+ let timer;
32
+ const check = () => {
33
+ const left = ms - (look() - start - held);
34
+ if (left <= 0)
35
+ return expire();
36
+ timer = after(check, Math.ceil(left));
37
+ };
38
+ timer = after(check, ms);
39
+ return {
40
+ clear: () => {
41
+ stop(ticks);
42
+ cancel(timer);
43
+ },
44
+ held: () => {
45
+ look();
46
+ return held;
47
+ },
48
+ };
49
+ }
@@ -1,7 +1,7 @@
1
- export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
1
+ export { AgentArchived, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull } from "./store.js";
2
2
  export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerWrite, NewFiring, NewRevision, NewTrigger, ReleasedState, RevisionRow, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
3
- export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, sealColumn, type SealedAt, sealedAt, sealMcpCredential, unsealColumn } from "./seal.js";
4
- export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
3
+ export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunMcpAuth, type RunMcpAuth, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunMcpAuth, unsealColumn } from "./seal.js";
4
+ export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type ModelTiers, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
5
5
  export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
6
6
  export { DDL, PI_DDL, PI_TABLE, PI_TABLES, SCHEMA_VERSION, STORE_DDL } from "./schema.js";
7
7
  export { RunStorage } from "./journal/storage.js";
@@ -1,6 +1,6 @@
1
1
  // The one store (design 2.1), for the cutover: nothing on main imports it until then.
2
- export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
3
- export { aadOf, openMcpCredential, sealColumn, sealedAt, sealMcpCredential, unsealColumn } from "./seal.js";
2
+ export { AgentArchived, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull } from "./store.js";
3
+ export { aadOf, openMcpCredential, openRunMcpAuth, sealColumn, sealedAt, sealMcpCredential, sealRunMcpAuth, unsealColumn } from "./seal.js";
4
4
  export { AgentBodyInvalid, bodyOf, canonical, isObject, isSkillPath, sha256, } from "./agent-body.js";
5
5
  export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
6
6
  export { DDL, PI_DDL, PI_TABLE, PI_TABLES, SCHEMA_VERSION, STORE_DDL } from "./schema.js";
@@ -315,8 +315,9 @@ export class RunStorage {
315
315
  }
316
316
  }
317
317
  // A run patch that made the run final: its other untaken rows are refused in this commit, after its own takes.
318
+ // A person's message that came while it was ending opens a completed run again instead (refuseLeftovers).
318
319
  if (patching)
319
- await refuseLeftovers(tx, this.#runId, staged?.run?.state, now);
320
+ await refuseLeftovers(tx, this.#runId, staged?.run?.state, now, this.#dialect);
320
321
  }
321
322
  });
322
323
  this.#nextId = Math.max(this.#nextId, candidateNextId);
@@ -58,6 +58,10 @@ export declare class Unanswered extends Error {
58
58
  * (a runner's 35 s graceful stop, the server's own) instead of exiting, and a lost lock is never a 503 forever. */
59
59
  export declare const OWNER_WAIT_MS = 120000;
60
60
  export declare function numberParams(sql: string): string;
61
+ /** A Postgres error as the store's own: a refused row StoreConstraint, a lock or a conflict StoreBusy. */
62
+ /** Whether `error` says the database ended the session (its idle-in-transaction timeout, SQLSTATE 25P03), or that the
63
+ * connection is gone and takes no more statements: a transaction's work on it was rolled back by the database. */
64
+ export declare function sessionEnded(error: unknown): boolean;
61
65
  export declare class PgConnection implements StoreConnection {
62
66
  #private;
63
67
  readonly dialect: Dialect;
@@ -5,8 +5,10 @@
5
5
  // no row rolls its transaction back with the typed error, as SQLite's worker does. A server's connection also holds the
6
6
  // store's owner lock (one server per schema): a session advisory lock on a client of its own, held until close.
7
7
  import pg from "pg";
8
+ import { runnableDeadline } from "../deadline.js";
8
9
  import { cleanText } from "../dialect.js";
9
- import { Fenced, RunFinal, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreOwned } from "../store.js";
10
+ import { ONE_ANSWER_INDEX } from "../schema.js";
11
+ import { AnswerTaken, Fenced, RunFinal, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreOwned } from "../store.js";
10
12
  import { DEFAULT_TRANSACTION_DEADLINE_MS } from "../sqlite/connection.js";
11
13
  import { postgresDialect } from "./dialect.js";
12
14
  /** Which store this is, as two opens of the same data agree on it (StoreConnection.where): "postgres:" and the URL's host
@@ -207,16 +209,29 @@ function bound(value) {
207
209
  const returnsRows = (sql) => /^\s*(?:SELECT|WITH)\b/i.test(sql) || /\bRETURNING\b/i.test(sql);
208
210
  /** Postgres's integrity SQLSTATEs, by the rule they name. */
209
211
  const RULES = { "23514": "check", "23505": "unique", "23503": "foreign_key", "23502": "not_null" };
210
- /** A unique violation's table and columns: the table Postgres names, and the columns of the index it names (a UNIQUE's or
211
- * a primary key's is an index of the same name), read from the catalog by `columnsOf`. Any other error as it is. */
212
+ /** A unique violation's table, columns and index: the table and the index (or constraint) Postgres names, and that
213
+ * index's columns (a UNIQUE's or a primary key's is an index of the same name), read from the catalog by `columnsOf`.
214
+ * A violation of the one-answer index (an answer to an approval answered already) is AnswerTaken. Any other error as it
215
+ * is. */
212
216
  async function withUnique(error, cause, columnsOf) {
213
217
  const e = cause;
214
218
  if (!(error instanceof StoreConstraint) || error.rule !== "unique" || !e?.table || !e.constraint)
215
219
  return error;
220
+ if (e.constraint === ONE_ANSWER_INDEX)
221
+ return new AnswerTaken(error.message, e.constraint);
216
222
  const columns = await columnsOf(e.constraint).catch(() => []);
217
- return columns.length ? new StoreConstraint(error.message, { rule: "unique", unique: { table: e.table, columns } }) : error;
223
+ return new StoreConstraint(error.message, { rule: "unique", index: e.constraint, ...(columns.length ? { unique: { table: e.table, columns } } : {}) });
218
224
  }
219
225
  /** A Postgres error as the store's own: a refused row StoreConstraint, a lock or a conflict StoreBusy. */
226
+ /** Whether `error` says the database ended the session (its idle-in-transaction timeout, SQLSTATE 25P03), or that the
227
+ * connection is gone and takes no more statements: a transaction's work on it was rolled back by the database. */
228
+ export function sessionEnded(error) {
229
+ const e = error;
230
+ if (e?.code === "25P03")
231
+ return true;
232
+ const message = typeof e?.message === "string" ? e.message : "";
233
+ return /not queryable|Connection terminated/i.test(message);
234
+ }
220
235
  function typed(error, deadlineMs) {
221
236
  // Already the store's own (a failed statement's error, met again at the commit of a callback that caught it).
222
237
  if (error instanceof Fenced || error instanceof RunFinal || error instanceof StoreClosed || error instanceof StoreDeadline || error instanceof StoreConstraint || error instanceof StoreBusy || error instanceof Unanswered)
@@ -518,6 +533,15 @@ export class PgConnection {
518
533
  }
519
534
  let live = true;
520
535
  let broken;
536
+ // The database may end the session while the transaction waits between statements (its idle-in-transaction timeout:
537
+ // this process held up past the deadline and its slack): heard here, a statement or the commit after it answers
538
+ // StoreDeadline (home_busy, retryable), since the database rolled the transaction back and nothing of it was written.
539
+ let ended;
540
+ const onEnded = (error) => {
541
+ ended ??= error;
542
+ };
543
+ client.on("error", onEnded);
544
+ const lost = (error) => (ended !== undefined || sessionEnded(error) ? new StoreDeadline(deadlineMs) : undefined);
521
545
  const check = () => {
522
546
  if (!live)
523
547
  throw new Error("the store's transaction is over: its handle takes no more statements");
@@ -541,9 +565,11 @@ export class PgConnection {
541
565
  return await step(client, statement, columnsOf, deadlineMs);
542
566
  }
543
567
  catch (error) {
544
- // A statement that failed has aborted the transaction: no later statement of it runs.
545
- broken ??= error;
546
- throw error;
568
+ // A statement that failed has aborted the transaction: no later statement of it runs. On a session the database
569
+ // ended, it is the transaction's deadline.
570
+ const failure = lost(error) ?? error;
571
+ broken ??= failure;
572
+ throw failure;
547
573
  }
548
574
  };
549
575
  const tx = {
@@ -560,15 +586,26 @@ export class PgConnection {
560
586
  // drop, a failover) is bounded from its first statement on, not only once BEGIN has answered. Past it the client is
561
587
  // let go with the error, which destroys its socket (Postgres rolls a dead session's transaction back), never
562
588
  // waiting on a ROLLBACK that a silent connection would never answer.
589
+ // Counted from its begin, the deadline is the time this process could run (store/deadline.ts runnableDeadline, the
590
+ // rule SQLite's keeps): a statement answered while other work held the event loop waited behind it, and that time
591
+ // was no statement's, so a write that was fine is never rolled back for it. Counted from its call (a lease's), it is
592
+ // the wall clock's.
563
593
  let timer;
564
- const deadlineAt = Date.now() + ms;
594
+ const deadlineAt = performance.now() + ms;
565
595
  const deadline = new Promise((_, reject) => {
566
- timer = setTimeout(() => reject(new StoreDeadline(deadlineMs)), ms);
596
+ const expire = () => reject(new StoreDeadline(deadlineMs));
597
+ if (fromCall) {
598
+ const wall = setTimeout(expire, ms);
599
+ timer = { clear: () => clearTimeout(wall), held: () => 0 };
600
+ }
601
+ else
602
+ timer = runnableDeadline(ms, expire);
567
603
  });
568
604
  deadline.catch(() => undefined);
569
605
  const abandon = (error) => {
570
606
  live = false;
571
- clearTimeout(timer);
607
+ timer?.clear();
608
+ client.off("error", onEnded);
572
609
  // Its socket destroyed here: with no query in flight (a deadline between statements) pg's own end would send a
573
610
  // Terminate and wait for a FIN a silent connection never answers.
574
611
  client.connection?.stream?.destroy();
@@ -596,19 +633,32 @@ export class PgConnection {
596
633
  throw error;
597
634
  }
598
635
  live = false;
599
- clearTimeout(timer);
636
+ timer?.clear();
637
+ client.off("error", onEnded);
600
638
  await rollBackAndRelease(client);
601
639
  throw error;
602
640
  }
603
641
  live = false;
604
- clearTimeout(timer);
642
+ timer?.clear();
643
+ // Ended before its commit is sent: nothing of it was written, and the commit is never sent on a gone session.
644
+ const endedBefore = ended;
605
645
  try {
646
+ if (endedBefore)
647
+ throw endedBefore;
606
648
  // A callback that caught a failed statement's error and went on still rolls back: Postgres aborted the transaction.
607
649
  if (broken)
608
650
  throw broken;
609
- await answered(client.query("COMMIT"), Math.max(COMMIT_FLOOR_MS, deadlineAt - Date.now()), "its commit");
651
+ await answered(client.query("COMMIT"), Math.max(COMMIT_FLOOR_MS, deadlineAt + (timer?.held() ?? 0) - performance.now()), "its commit");
610
652
  }
611
653
  catch (error) {
654
+ if (endedBefore !== undefined || error?.code === "25P03") {
655
+ client.off("error", onEnded);
656
+ client.release(error);
657
+ if (read)
658
+ return value;
659
+ throw new StoreDeadline(deadlineMs);
660
+ }
661
+ client.off("error", onEnded);
612
662
  if (error instanceof Unanswered) {
613
663
  client.release(error);
614
664
  // A read's snapshot has nothing to land: what it read stands.
@@ -619,6 +669,7 @@ export class PgConnection {
619
669
  await rollBackAndRelease(client);
620
670
  throw typed(error, deadlineMs);
621
671
  }
672
+ client.off("error", onEnded);
622
673
  client.release();
623
674
  return value;
624
675
  });
@@ -0,0 +1,11 @@
1
+ -- The store's schema on Postgres, version 4: a stopped run says which stop it was in its outcome, as store/schema.ts keeps
2
+ -- it on SQLite: 'stopped' when a person stopped it (its turn is over, not the run: a message reopens it) or 'cancelled'
3
+ -- (over for good), beside an ended run's 'completed' and 'escalated'. Applied once, after 0003, inside the transaction
4
+ -- migrate.ts opens. Never edit this file once applied: a change is a new file.
5
+ --
6
+ -- runs_outcome_check is Postgres's name for 0001's column check on runs.outcome.
7
+
8
+ ALTER TABLE runs DROP CONSTRAINT runs_outcome_check;
9
+ ALTER TABLE runs ADD CONSTRAINT runs_outcome_check CHECK (outcome IS NULL OR outcome IN ('completed', 'escalated', 'stopped', 'cancelled'));
10
+
11
+ UPDATE store_meta SET schema_version = 4 WHERE singleton = 1;
@@ -1,9 +1,10 @@
1
- export declare const SCHEMA_VERSION = 5;
1
+ export declare const SCHEMA_VERSION = 6;
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,9 @@
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 6 (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').
6
7
  // Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
7
8
  // sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
8
9
  // in the clear. Foreign keys are on (the connection's pragma).
@@ -13,13 +14,14 @@
13
14
  // 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
15
  // journal tables, keyed by run_id (store/journal): one schema for every run's journal, so a query joins runs and their
15
16
  // journals.
16
- export const SCHEMA_VERSION = 5;
17
+ export const SCHEMA_VERSION = 6;
17
18
  /** One answer per approval of a run: a second approve or deny command naming the same approval is refused
18
19
  * (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
19
20
  * (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
21
  /** One unrefused answer per approval of a run: an answer the runner refused (its run could not resume) holds no place, so
21
22
  * 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`;
23
+ export const ONE_ANSWER_INDEX = "commands_one_answer";
24
+ 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
25
  const json = (column, nullable = false) => `${column} TEXT${nullable ? "" : " NOT NULL"} CHECK (${column} IS NULL OR json_valid(${column}))`;
24
26
  export const STORE_DDL = [
25
27
  `CREATE TABLE IF NOT EXISTS store_meta (
@@ -80,10 +82,11 @@ export const STORE_DDL = [
80
82
  cost_usd REAL,
81
83
  ${json("metrics", true)},
82
84
  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')),
85
+ -- How the run ended beside its state (RunOutcome). An ended run: 'escalated' (it finished its work and waits for a
86
+ -- person, which v2 reads as completed with a review) or 'completed'; null is a plain completion. A stopped run:
87
+ -- 'stopped' when a person stopped it (its turn is over, not the run: a message reopens it) or 'cancelled' (over for
88
+ -- good). A failed run says so in its state and needs none. Written in the run's end commit (RunPatch.outcome).
89
+ outcome TEXT CHECK (outcome IS NULL OR outcome IN ('completed', 'escalated', 'stopped', 'cancelled')),
87
90
  -- When the run itself was archived (its agent's archive is the agent row's): hidden from the default lists, kept.
88
91
  archived_at INTEGER,
89
92
  -- The session an imported run came from ({source, session}), written by Store.importRun; null for a run started here.
@@ -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. */