@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45

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 (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -19,6 +19,7 @@
19
19
  // as stmt, or as step (one statement, its changes and rows, its `expect` checked)
20
20
  // in between
21
21
  // close
22
+ import { chmodSync, closeSync, openSync } from "node:fs";
22
23
  import { parentPort } from "node:worker_threads";
23
24
  import { DatabaseSync } from "node:sqlite";
24
25
  import { inMemory } from "./memory.js";
@@ -171,15 +172,39 @@ function takeOwnerLock(file) {
171
172
  }
172
173
  owner = lock;
173
174
  }
175
+ /** The store's files, the server's alone (0600) whatever the umask: a run's process, a user of its own that may cross the
176
+ * data directory to its folders, opens none of them. The file is made 0600 before SQLite opens it, and SQLite makes its
177
+ * WAL and shared-memory files with the database file's mode; each one already there is set again (a store an earlier
178
+ * start made 0644). A file this process does not own (a runner's on the server's store) is left as it is. */
179
+ function keepPrivate(file, made) {
180
+ if (inMemory(file))
181
+ return;
182
+ if (made) {
183
+ try {
184
+ closeSync(openSync(file, "a", 0o600));
185
+ }
186
+ catch { }
187
+ }
188
+ for (const each of [file, `${file}-wal`, `${file}-shm`, `${file}.owner`, `${file}.owner-journal`]) {
189
+ try {
190
+ chmodSync(each, 0o600);
191
+ }
192
+ catch { }
193
+ }
194
+ }
174
195
  function handle(request) {
175
196
  switch (request.op) {
176
197
  case "open": {
198
+ if (request.owner)
199
+ keepPrivate(request.file, true);
177
200
  if (request.owner)
178
201
  takeOwnerLock(request.file);
179
202
  db = new DatabaseSync(request.file);
180
203
  busyTimeout = Math.max(0, Math.floor(request.busyTimeoutMs));
181
204
  db.exec(`PRAGMA busy_timeout = ${busyTimeout}`);
182
205
  db.exec("PRAGMA journal_mode = WAL");
206
+ if (request.owner)
207
+ keepPrivate(request.file, false);
183
208
  db.exec(NORMAL);
184
209
  db.exec("PRAGMA foreign_keys = ON");
185
210
  return null;
@@ -58,6 +58,10 @@ export interface TemplatePackage {
58
58
  readonly id: string;
59
59
  readonly version: string;
60
60
  readonly sha: string | null;
61
+ /** A keyed digest of the parameters the apply was given, as it checked them (seal-key.ts parametersDigest), never the
62
+ * parameters, one of which may be a credential: a later fresh apply of the same package whose parameters give the same
63
+ * digest warns of this agent. Absent on a revision applied before it was kept. */
64
+ readonly parameters_digest?: string;
61
65
  }
62
66
  export interface NewRevision {
63
67
  readonly id: string;
@@ -104,9 +108,53 @@ export interface RevisionRow {
104
108
  * statusOf reads a stopped run, and a person's message reopens it), 'cancelled' when it was cancelled (over for good). A
105
109
  * failed run says so in its state. */
106
110
  export type RunOutcome = "completed" | "escalated" | "stopped" | "cancelled";
111
+ /** A runs list's filter (Runs.listed). */
112
+ export interface ListedFilter {
113
+ readonly agentId?: string;
114
+ readonly revisionId?: string;
115
+ readonly labels?: RunLabels;
116
+ readonly archived: boolean;
117
+ readonly status?: string;
118
+ /** Only runs still going (no settled status on the row) whose listing is behind. */
119
+ readonly going?: boolean;
120
+ /** Only rows after this one in the list's order (started earlier, or at the same time with a smaller id): a scan's
121
+ * place, which rows that leave the set between its reads (a listing built meanwhile) never shift, as they shift an
122
+ * offset. */
123
+ readonly after?: {
124
+ readonly startedAt: number;
125
+ readonly id: string;
126
+ };
127
+ readonly limit: number;
128
+ readonly offset?: number;
129
+ }
130
+ /** A run as a list reads it (Runs.listed): its row, its agent's archive time, and its listing as kept (null: none built). */
131
+ export interface ListedRun {
132
+ readonly row: RunRow;
133
+ readonly agentArchivedAt: number | null;
134
+ readonly listing: {
135
+ readonly item: Record<string, unknown>;
136
+ readonly cut: string;
137
+ } | null;
138
+ readonly listStatus: string | null;
139
+ /** The run's list_mark now: the mark a listing built from here is written at. */
140
+ readonly listMark: number;
141
+ /** The listing is behind now (Runs.behind's three ways): a list builds it before it shows it. */
142
+ readonly behind: boolean;
143
+ }
107
144
  /** Whether `run`, of a revision of `kind`, was stopped by a person and waits for them (state 'stopped', outcome 'stopped',
108
145
  * an agentic run started here): its turn is over, the run is not. A workflow's stop, a cancel and an imported run's stop
109
146
  * are over for good. */
147
+ /** A run's listing as the server writes it (Runs.putListing): its list item (`item`), its status, whether a runner held the
148
+ * run when it was built, when it goes stale by the clock alone (null: never), and what outside the run it read (flags). */
149
+ export interface RunListing {
150
+ readonly item: Record<string, unknown>;
151
+ /** The digest of the server's secrets the item was cut of. */
152
+ readonly cut: string;
153
+ readonly status: string;
154
+ readonly live: boolean;
155
+ readonly until: number | null;
156
+ readonly flags: number;
157
+ }
110
158
  export declare function stoppedByPerson(run: Pick<RunRow, "state" | "outcome" | "importedFrom">, kind: string): boolean;
111
159
  /** The harness an imported run came from. */
112
160
  export type ImportSource = "claude-code" | "codex" | "pi";
@@ -207,9 +255,13 @@ export interface RunLaunchRow {
207
255
  readonly createdAt: number;
208
256
  }
209
257
  /** A message's new launch secrets (runs.command, runs.reopen): `launchSealed` replaces the run's launch `sealed` in the
210
- * command's own transaction, so the runner that takes the command reads them, and a run already final takes neither. */
258
+ * command's own transaction, so the runner that takes the command reads them, and a run already final takes neither.
259
+ * Given as a function, it is called inside that transaction with the sealed bytes the launch holds then (null when none:
260
+ * a run whose end erased them), and its answer is written (null erases): a message that hands one secret keeps the
261
+ * others the run holds, with no read outside the write that could bring back what an end erased. */
262
+ export type LaunchSealed = Uint8Array | ((current: Uint8Array | null) => Uint8Array | null);
211
263
  export interface LaunchSealedWrite {
212
- readonly launchSealed?: Uint8Array;
264
+ readonly launchSealed?: LaunchSealed;
213
265
  }
214
266
  /** A run imported from another harness's session: an ended run with where it came from, its launch (built from the
215
267
  * session), its cost and metrics, and its transcript as journal batches — the whole thing written in one transaction.
@@ -252,8 +304,8 @@ export type AlsoRow = {
252
304
  marker: string;
253
305
  };
254
306
  }
255
- /** What the run's end-of-run turn kept: the turn and the proposal checked from it (the run's agent is the row's), and
256
- * its `round` (absent: 1): the run's first end is round 1, each end after a follow-up opened it again the next. */
307
+ /** What the run's end-of-run step kept: the turn and how its learning ended (the run's agent is the row's), and its
308
+ * `round` (absent: 1): the run's first end is round 1, each end after a follow-up opened it again the next. */
257
309
  | {
258
310
  readonly table: "learning_proposals";
259
311
  readonly row: {
@@ -261,21 +313,6 @@ export type AlsoRow = {
261
313
  proposal: unknown;
262
314
  round?: number;
263
315
  };
264
- }
265
- /** The learning run that grades and merges the kept proposal: a queued run `id` of the run's agent and revision. Started
266
- * once: the same id staged again (an end replayed after a crash) adds nothing. */
267
- /** `model`: the grade model (gradeModelOf, as the server resolves it), on the learning run's launch; none, the agent's own.
268
- * `round`: the round it grades (absent: 1), named in its launch. `capUsd`: what the run's cap leaves once everything it
269
- * spent is counted (learning-end.ts gradeCapOf), the learning run's own cap (its launch's max_cost_usd), so its grade
270
- * never takes the run past its cap; absent for an uncapped run, whose grade is capped by nothing. */
271
- | {
272
- readonly table: "learning_run";
273
- readonly row: {
274
- id: string;
275
- model?: string;
276
- round?: number;
277
- capUsd?: number;
278
- };
279
316
  };
280
317
  /** A run's kept learning (learning_proposals): what its end-of-run turn asked and answered, and the proposal checked from it. */
281
318
  export interface LearningProposal {
@@ -297,9 +334,6 @@ export interface Learning {
297
334
  proposals(agentId: string, options?: {
298
335
  limit?: number;
299
336
  }): Promise<LearningProposal[]>;
300
- /** The agent's kept proposals whose learning run (its grade) has not ended: queued, running or parked. Every one of
301
- * them, however many proposals were kept since, newest first. */
302
- grading(agentId: string): Promise<LearningProposal[]>;
303
337
  /** Everything agent `agentId`'s runs' learning kept, in two reads whatever the number of its runs: every round of every
304
338
  * run's kept proposal (oldest round first within a run), and the rows of the learning runs they name (as runs.get
305
339
  * reads one; a learning run named and never written has none). An agent-wide read's, never a read a run. */
@@ -315,14 +349,6 @@ export interface Learning {
315
349
  from: number;
316
350
  to: number;
317
351
  }): Promise<LearningSpend[]>;
318
- /** What was spent beside run `runId` on its behalf, the one figure every cap gate of the run reads with its own
319
- * sessions (and its grade's cap, learning-end.ts gradeCapOf): each learning run its rounds queued (`beforeRound`: only
320
- * those of the rounds before it), one that ended at its cost, one not ended at its own cap (the most its grade may
321
- * take), and one that ended at an unknown cost at that cap too, the most it could have taken. Null: unknown (one with
322
- * neither). 0 for a run that queued none. */
323
- spentBeside(runId: string, options?: {
324
- beforeRound?: number;
325
- }): Promise<number | null>;
326
352
  }
327
353
  /** One run's learning end as GET /usage's learning meter counts it (Learning.spend). */
328
354
  export interface LearningSpend {
@@ -503,6 +529,10 @@ export interface TriggerRow {
503
529
  readonly maxActiveRuns: number | null;
504
530
  readonly createdAt: number;
505
531
  readonly updatedAt: number;
532
+ /** Its package mark: the id of the template package whose apply made it or last kept it in place, which a later update
533
+ * of that package may remove once the package no longer lists it; null for one a person made, one a PATCH moved to
534
+ * another agent, and one made before the mark was kept. Written by the apply alone, never from an API body. */
535
+ readonly templateId: string | null;
506
536
  }
507
537
  /** A trigger's firing that starts a run. */
508
538
  export interface Firing {
@@ -565,10 +595,22 @@ export interface NewTrigger {
565
595
  readonly nextAt: number | null;
566
596
  readonly catchupWindowS: number;
567
597
  readonly maxActiveRuns?: number | null;
598
+ /** The package mark (TriggerRow.templateId) a template apply makes it with; none for a person's. */
599
+ readonly templateId?: string | null;
568
600
  }
569
601
  /** A trigger's fields changed; the ones absent stay. */
570
602
  /** `agentId`: the agent it belongs to, which follows its target (a PATCH may aim it at another agent's run or agent). */
571
- export type TriggerPatch = Partial<Pick<TriggerRow, "agentId" | "name" | "enabled" | "source" | "target" | "nextAt" | "catchupWindowS" | "failuresInARow" | "disabled" | "maxActiveRuns">>;
603
+ /** A trigger update's options: a compare-and-set, written only while the row is still the read the patch was made from,
604
+ * undefined otherwise, as when there is no such trigger. `ifUpdatedAt`: the row's updatedAt is still this one.
605
+ * `ifSource`: its source is still this one, as the store keeps it; two writes in one millisecond share an updatedAt, so a
606
+ * write that must never land over another source write (a seal, an edit) gives both. */
607
+ /** `ifAgent`: it is still that agent's (a PATCH may move it to another meanwhile). */
608
+ export type TriggerUpdateOptions = {
609
+ readonly ifUpdatedAt?: number;
610
+ readonly ifSource?: unknown;
611
+ readonly ifAgent?: string;
612
+ };
613
+ export type TriggerPatch = Partial<Pick<TriggerRow, "agentId" | "name" | "enabled" | "source" | "target" | "nextAt" | "catchupWindowS" | "failuresInARow" | "disabled" | "maxActiveRuns" | "templateId">>;
572
614
  /** A firing's new state. Out of due, a firing keeps no retry, wait, payload nor the reason its last try gave (unless given). */
573
615
  export interface FiringChange {
574
616
  readonly status?: FiringStatus;
@@ -604,6 +646,24 @@ export declare class AgentArchived extends Error {
604
646
  name: string;
605
647
  constructor(agentId: string);
606
648
  }
649
+ /** A run of an agent being deleted, or a follow-up that would open one of its runs again: refused, nothing written. An
650
+ * agent another system owns is never archived here (its archive route is refused), so its archive time is the mark its
651
+ * delete leaves (DELETE /agents/{id}, agent-delete.ts): from that commit runs.create, runs.createInline, runs.reopen and
652
+ * triggers.fire refuse it, each in the transaction that would start the run, and a restart keeps the mark. */
653
+ export declare class AgentDeleting extends Error {
654
+ readonly agentId: string;
655
+ name: string;
656
+ constructor(agentId: string);
657
+ }
658
+ /** An agent's removal refused while a trigger of it is left (Agents.remove): a trigger keeps things outside its row (its
659
+ * registration upstream, its adapter settings) that only the trigger engine removes, so its row never goes with the
660
+ * agent's. Nothing written. */
661
+ export declare class TriggersLeft extends Error {
662
+ readonly agentId: string;
663
+ readonly triggerIds: readonly string[];
664
+ name: string;
665
+ constructor(agentId: string, triggerIds: readonly string[]);
666
+ }
607
667
  /** An inline-agent run whose body differs from the one already stored for its external reference and version: refused,
608
668
  * nothing written (Runs.createInline). A version's body is immutable; a changed body needs a new version. */
609
669
  export declare class ExternalBodyConflict extends Error {
@@ -660,6 +720,11 @@ export interface Agents {
660
720
  * the revision still has none, and the pin it has then is the answer, so two first runs at once agree on one. Null when
661
721
  * there is no such revision. */
662
722
  pinOnce(revisionId: string, pin: unknown): Promise<unknown>;
723
+ /** The agent's own rows gone, in one transaction (the last write of DELETE /agents/{id}, agent-delete.ts): its learning
724
+ * rows and kept proposals, its sign-ins and their tombstones, its revisions and the agent. Only once it has no run and
725
+ * no trigger left (runs.remove and the trigger engine's remove each first): refused while a run is (StoreConstraint)
726
+ * or a trigger is (TriggersLeft), read under the agent row's lock, nothing written. An agent with no row is no write. */
727
+ remove(agentId: string): Promise<void>;
663
728
  }
664
729
  export interface Templates {
665
730
  /** A template applied: the agent, its first revision (with the package) and its triggers, in one transaction, all or
@@ -687,14 +752,18 @@ export interface Triggers {
687
752
  all(): Promise<TriggerRow[]>;
688
753
  /** The trigger and, while it is enabled, its scope rows (`scopes`), in one transaction: a scope another enabled trigger
689
754
  * holds is refused (StoreConstraint on trigger_scopes), nothing written; one made on for an archived agent too
690
- * (AgentArchived). */
755
+ * (AgentArchived), and one made at all, off too, for an agent being deleted (AgentDeleting). */
691
756
  create(trigger: NewTrigger, scopes?: readonly TriggerScope[]): Promise<TriggerRow>;
692
757
  /** The fields given changed, `updatedAt` set: undefined when there is no such trigger. With `scopes`, its scope rows
693
758
  * rewritten in the same transaction (none while it is off); a patch that turns it off drops them. One that leaves it
694
- * on for an archived agent, turned on or moved there, is refused (AgentArchived), nothing written. */
695
- update(id: string, patch: TriggerPatch, scopes?: readonly TriggerScope[]): Promise<TriggerRow | undefined>;
696
- /** The trigger, its scope rows and its firings gone. */
697
- remove(id: string): Promise<void>;
759
+ * on for an archived agent, turned on or moved there, is refused (AgentArchived), nothing written; one that turns it
760
+ * on, or moves it at all, to an agent being deleted, too (AgentDeleting). */
761
+ update(id: string, patch: TriggerPatch, scopes?: readonly TriggerScope[], options?: TriggerUpdateOptions): Promise<TriggerRow | undefined>;
762
+ /** The trigger, its scope rows and its firings gone: whether there was one to remove. With `ifAgent`, only while it is
763
+ * still that agent's, compared in the same statement: one moved to another agent is left, and the answer is false. */
764
+ remove(id: string, options?: {
765
+ readonly ifAgent?: string;
766
+ }): Promise<boolean>;
698
767
  /** Enables the trigger and writes its scope rows, in one transaction; refused for an archived agent's (AgentArchived). */
699
768
  enable(triggerId: string, scopes: readonly TriggerScope[]): Promise<void>;
700
769
  /** Disables the trigger (with why, JSON) and deletes its scope rows, in one transaction. */
@@ -836,8 +905,64 @@ export interface Runs {
836
905
  labels?: RunLabels;
837
906
  limit?: number;
838
907
  }): Promise<RunRow[]>;
908
+ /** A page of a runs list, in one read: newest first, `offset` rows on, at most `limit`, and whether more follow (`more`).
909
+ * Each with its listing as its row keeps it (RUN_LISTING_COLUMNS: null while none has been built), whether that is
910
+ * behind, and its agent's archive time. `archived` filters on the run's archive or its agent's (true: either; false:
911
+ * neither); `status` on the row's status (`list_status`: a settled run's from its row, in the write that settled it;
912
+ * another's from its listing); `going` keeps only runs still going whose listing is behind. A built-in learning run and
913
+ * an audit's shadow run are never listed. */
914
+ listed(filter: ListedFilter): Promise<{
915
+ readonly rows: readonly ListedRun[];
916
+ readonly more: boolean;
917
+ }>;
918
+ /** Agent `agentId`'s runs counted in one read (an agent's view): every run it has (`count`), and those still going
919
+ * (`live`: queued, running or parked, or an agentic run a person stopped, which a message continues). A built-in learning
920
+ * run and an audit's shadow run are none of them. */
921
+ counts(agentId: string): Promise<{
922
+ readonly count: number;
923
+ readonly live: number;
924
+ }>;
925
+ /** Up to `limit` runs whose listing is behind, the runs no runner holds first, then newest first: built never, or before
926
+ * the latest write that moved what the run's view shows (listing_mark < list_mark), or built while a runner held it and
927
+ * that claim has run out on the store's clock, or past the time it goes stale by the clock (listing_until). `mark`:
928
+ * the run's list_mark now, the mark its listing is built at. `held`: a runner holds its claim now. `offset`: that many
929
+ * of them passed over first (those the caller chose not to build yet). */
930
+ behind(options: {
931
+ limit: number;
932
+ offset?: number;
933
+ }): Promise<{
934
+ readonly id: string;
935
+ readonly mark: number;
936
+ readonly held: boolean;
937
+ }[]>;
938
+ /** Writes run `runId`'s listing as built at `mark` (behind's or listed's, read before the build read the view): only
939
+ * while the row's list_mark is still `mark`. A write that moved the mark meanwhile (a run settled, its list_status set
940
+ * by that write) keeps the row as that write left it, behind, so the next build writes what the run shows now. True
941
+ * when it was written. */
942
+ putListing(runId: string, mark: number, listing: RunListing): Promise<boolean>;
943
+ /** Run `runId`'s list_mark now (the mark a build of its listing starts from), or undefined when there is no such run. */
944
+ listMark(runId: string): Promise<number | undefined>;
945
+ /** Moves the mark of every run whose listing read something outside the run (`flags`, RUN_LISTING_COLUMNS' listing_flags),
946
+ * of agent `agentId` when given: the server's keys changed, or an agent's learning folder did. The number of runs moved. */
947
+ relist(options: {
948
+ flags: number;
949
+ agentId?: string;
950
+ }): Promise<number>;
839
951
  /** Archives the run (its own archive time), or unarchives it: idempotent. */
840
952
  archive(runId: string, archived: boolean): Promise<void>;
953
+ /** Every run of agent `agentId` with its state, oldest first, its built-in learning runs included (which list leaves
954
+ * out): what deleting the agent stops and removes. */
955
+ every(agentId: string): Promise<{
956
+ id: string;
957
+ state: RunState;
958
+ }[]>;
959
+ /** The run's rows gone, in one transaction: its journal, commands, origin, launch, live view and viewers, its channel
960
+ * posts with their tries and what each channel was told of it, its kept learning, its changes in the run-change feed,
961
+ * a trigger's conversation that names it, and the run (a firing or trigger that names it keeps no run: ON DELETE SET
962
+ * NULL). Only a final run: one that is not is refused (StoreConstraint), nothing written, so no runner's claim is ever
963
+ * on a run that goes. A run with no row is no write. From then a late write under an old claim of it is Fenced and
964
+ * writes nothing (its row is gone), and a command for it is RunFinal. */
965
+ remove(runId: string): Promise<void>;
841
966
  /** A person's follow-up to a run that ended completed, or that a person stopped: in one transaction, the run goes back to running with no runner
842
967
  * (released, so a runner claims it at once by the claimable rule's released branch), its end's own fields cleared
843
968
  * (ended_at, summary, outcome, its waits) and everything it did kept (its epoch, its journal, its cost and metrics,
@@ -1263,19 +1388,61 @@ export interface MintedTokenRow {
1263
1388
  /** When it was revoked (the machine's delete); null while it is good. */
1264
1389
  readonly revokedAt: number | null;
1265
1390
  readonly createdAt: number;
1391
+ /** The runner in a process of its own that minted it, whose attach listener takes the machine's socket (dial-relay.ts),
1392
+ * and that runner's incarnation then; both null for a token the server's own process minted. */
1393
+ readonly runner: string | null;
1394
+ readonly incarnation: string | null;
1395
+ /** The run the machine works for, as its create named it: what the words about its dial say. Null for a machine of
1396
+ * no run. */
1397
+ readonly run: string | null;
1398
+ /** Why the server refused to relay this token's dial to the runner that minted it (computer-attach.ts relayDial), in
1399
+ * the words its 503 said, which name the run and the machine and never the token; null while none was refused. The
1400
+ * runner's create reads it (MachineTokens.refused) and ends its wait in these words. */
1401
+ readonly refused: string | null;
1266
1402
  }
1267
1403
  /** The tokens minted for hosted machines that dial this server (a dial provider's create, spec/computer/attach.md). */
1268
1404
  export interface MintedTokens {
1269
- /** Keeps the token's SHA-256 for `machine`, replacing one minted for it before. Rows past their end go in the same write. */
1405
+ /** Keeps the token's SHA-256 for `machine`, replacing one minted for it before. Rows past their end go in the same write.
1406
+ * `runner` and `incarnation`: a runner in a process of its own minting it (dial-relay.ts); `run`: the run its machine
1407
+ * works for. */
1270
1408
  mint(token: Pick<MintedTokenRow, "machine" | "kind" | "os" | "arch" | "expiresAt"> & {
1271
1409
  readonly tokenSha256: string;
1272
- }): Promise<void>;
1273
- /** The row whose token has this SHA-256, while it is good: neither revoked nor past its end. */
1410
+ readonly runner?: string;
1411
+ readonly incarnation?: string;
1412
+ readonly run?: string;
1413
+ }): Promise<void>; /** The row whose token has this SHA-256, while it is good: neither revoked nor past its end. */
1274
1414
  byToken(tokenSha256: string): Promise<MintedTokenRow | undefined>;
1275
1415
  /** The machine's row, good or not; undefined when it has none (never minted, or gone past its end). */
1276
1416
  get(machine: string): Promise<MintedTokenRow | undefined>;
1277
1417
  /** Revokes the machine's token. False when it had none good. */
1278
1418
  revoke(machine: string): Promise<boolean>;
1419
+ /** Keeps `words` as why the dial of the token with this SHA-256 was refused (its row's `refused`); a mint again for
1420
+ * its machine clears it. Nothing when no row has that token. */
1421
+ refuse(tokenSha256: string, words: string): Promise<void>;
1422
+ }
1423
+ /** Where a runner in a process of its own takes the dials relayed to it (store schema `runner_relays`, dial-relay.ts): its
1424
+ * attach listener's host and port, under the runner's name and its incarnation (its process since its start), and when
1425
+ * it last said it was there. */
1426
+ export interface RunnerRelayRow {
1427
+ readonly runner: string;
1428
+ readonly incarnation: string;
1429
+ /** The host the server reaches it at: loopback, or the runner's live host (live-reach.ts). */
1430
+ readonly host: string;
1431
+ readonly port: number;
1432
+ readonly seenAt: number;
1433
+ }
1434
+ /** The runners' attach listeners (dial-relay.ts). */
1435
+ export interface RunnerRelays {
1436
+ /** Keeps `row` for its runner, replacing any earlier incarnation's, seen now. */
1437
+ put(row: Omit<RunnerRelayRow, "seenAt">): Promise<void>;
1438
+ /** Marks the runner's row seen now, while it is still this incarnation's. False when it is not. */
1439
+ seen(runner: string, incarnation: string): Promise<boolean>;
1440
+ /** The runner's row, whichever incarnation's, or undefined. */
1441
+ get(runner: string): Promise<RunnerRelayRow | undefined>;
1442
+ /** Every runner's row. */
1443
+ list(): Promise<RunnerRelayRow[]>;
1444
+ /** The runner's row gone, while it is still this incarnation's. */
1445
+ remove(runner: string, incarnation: string): Promise<void>;
1279
1446
  }
1280
1447
  /** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
1281
1448
  * (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
@@ -1491,6 +1658,21 @@ export interface LiveViewers {
1491
1658
  /** Who opens the store. The server sets the schema up at its start and holds the store's owner lock (one server per
1492
1659
  * store); a runner never sets anything up, and refuses a schema version it does not know. */
1493
1660
  export type StoreRole = "server" | "runner";
1661
+ /** What Store.secureRewrite did: how many rows `work` rewrote and, when old bytes may still be in the store's files (the
1662
+ * marker kept for the next start), why: "busy", a reader in another connection held the log back from the checkpoint, or
1663
+ * a write of another connection held the VACUUM off through its busy wait and its one retry; "failed", the VACUUM or
1664
+ * the checkpoint failed otherwise; "deferred", the rewrite was asked with no VACUUM (a server already serving), so the
1665
+ * next start's scrub finishes it. */
1666
+ export interface SecureRewrite {
1667
+ readonly rewritten: number;
1668
+ readonly left?: "busy" | "failed" | "deferred";
1669
+ }
1670
+ /** secureRewrite's options: `vacuum: false` rewrites with secure_delete on and leaves the marker, with no VACUUM or
1671
+ * checkpoint: for a server already serving, where a VACUUM would hold every store call (and another process's writes)
1672
+ * while it rebuilds the whole file, and needs about its size again on disk. The next start's scrub runs it. */
1673
+ export type SecureRewriteOptions = {
1674
+ readonly vacuum?: boolean;
1675
+ };
1494
1676
  export interface Store {
1495
1677
  /** Where this store's data is, as an identity two instances over the same data share and two over different data never
1496
1678
  * do: "sqlite:" and the database file's real path, or "sqlite:memory:<n>" for an in-memory one (each its own data);
@@ -1515,6 +1697,8 @@ export interface Store {
1515
1697
  readonly pairedComputers: PairedComputers;
1516
1698
  /** The tokens minted for hosted machines that dial this server, each kept as its SHA-256. */
1517
1699
  readonly mintedTokens: MintedTokens;
1700
+ /** Where each runner in a process of its own takes the dials relayed to it. */
1701
+ readonly runnerRelays: RunnerRelays;
1518
1702
  /** The template packages imported from GitHub, their files kept as read. */
1519
1703
  readonly importedTemplates: ImportedTemplates;
1520
1704
  /** Each trigger source's sealed settings (design 2.1): a value per adapter, scope and field. */
@@ -1528,6 +1712,14 @@ export interface Store {
1528
1712
  readonly signIns: SignIns;
1529
1713
  /** Every sealed value the store keeps, across all its planes, in one read (a runner's redaction set at each claim). */
1530
1714
  readonly sealedSecrets: SealedSecrets;
1715
+ /** Runs `work`, writes that replace a secret the store kept in the clear (it answers how many rows it rewrote), so the
1716
+ * bytes they replace are not left in the store's files. SQLite: a marker file beside the database is written first;
1717
+ * secure_delete is on while `work` runs (a rewritten row's old bytes zeroed in its page); then, when a row was rewritten
1718
+ * or an earlier start left the marker, a VACUUM (no free page or free block keeps a copy an earlier, ordinary update
1719
+ * left) and a WAL checkpoint (TRUNCATE: the log keeps no older frame). The marker is removed once the checkpoint is
1720
+ * done; `left` says why it was kept, for the next start to finish. Postgres: `work` alone (a replaced row version is
1721
+ * the database's until its vacuum). */
1722
+ secureRewrite?(work: () => Promise<number>, options?: SecureRewriteOptions): Promise<SecureRewrite>;
1531
1723
  /** Claims the run for `runner` until now + `leaseMs`: the run's epoch + 1 when it is claimable (runs.claimable); null when
1532
1724
  * another claim holds it, or it is final, or parked with nothing to wake it. A queued or parked run becomes running. */
1533
1725
  claim(runId: string, runner: string, options?: {
@@ -5,9 +5,6 @@ export function endedReason(state) {
5
5
  const how = state === "ended" ? "ended" : state === "stopped" ? "was stopped" : "failed";
6
6
  return `the run ${how} before this command was taken`;
7
7
  }
8
- /** Whether `run`, of a revision of `kind`, was stopped by a person and waits for them (state 'stopped', outcome 'stopped',
9
- * an agentic run started here): its turn is over, the run is not. A workflow's stop, a cancel and an imported run's stop
10
- * are over for good. */
11
8
  export function stoppedByPerson(run, kind) {
12
9
  return run.state === "stopped" && run.outcome === "stopped" && kind === "agentic" && run.importedFrom === null;
13
10
  }
@@ -31,6 +28,31 @@ export class AgentArchived extends Error {
31
28
  this.agentId = agentId;
32
29
  }
33
30
  }
31
+ /** A run of an agent being deleted, or a follow-up that would open one of its runs again: refused, nothing written. An
32
+ * agent another system owns is never archived here (its archive route is refused), so its archive time is the mark its
33
+ * delete leaves (DELETE /agents/{id}, agent-delete.ts): from that commit runs.create, runs.createInline, runs.reopen and
34
+ * triggers.fire refuse it, each in the transaction that would start the run, and a restart keeps the mark. */
35
+ export class AgentDeleting extends Error {
36
+ agentId;
37
+ name = "AgentDeleting";
38
+ constructor(agentId) {
39
+ super(`the agent ${agentId} is being deleted`);
40
+ this.agentId = agentId;
41
+ }
42
+ }
43
+ /** An agent's removal refused while a trigger of it is left (Agents.remove): a trigger keeps things outside its row (its
44
+ * registration upstream, its adapter settings) that only the trigger engine removes, so its row never goes with the
45
+ * agent's. Nothing written. */
46
+ export class TriggersLeft extends Error {
47
+ agentId;
48
+ triggerIds;
49
+ name = "TriggersLeft";
50
+ constructor(agentId, triggerIds) {
51
+ super(`agent ${agentId} still has triggers (${triggerIds.join(", ")}): each is removed first, by the trigger engine`);
52
+ this.agentId = agentId;
53
+ this.triggerIds = triggerIds;
54
+ }
55
+ }
34
56
  /** An inline-agent run whose body differs from the one already stored for its external reference and version: refused,
35
57
  * nothing written (Runs.createInline). A version's body is immutable; a changed body needs a new version. */
36
58
  export class ExternalBodyConflict extends Error {
@@ -6,6 +6,7 @@
6
6
  import { sdkOf } from "../sdk/runs.js";
7
7
  import { DEFAULT_HARNESS } from "../harness.js";
8
8
  import { runReadState } from "./runs.js";
9
+ import { isShadowRun, shadowRunId } from "../learn/audit.js";
9
10
  const PENDING_ENDS = new Set(["completed", "escalated", "failed", "stopped"]);
10
11
  const num = (value) => (typeof value === "number" && Number.isFinite(value) ? value : 0);
11
12
  const metricsOf = (run) => (run.metrics !== null && typeof run.metrics === "object" && !Array.isArray(run.metrics) ? run.metrics : null);
@@ -24,7 +25,11 @@ export async function analytics(store, filter = {}) {
24
25
  const agentArchived = new Map();
25
26
  const harnessOf = new Map();
26
27
  const facts = [];
28
+ // Each audit's shadow run by id: its cost is the run it audits' (shadowUsd).
29
+ const shadows = new Map(runs.filter((run) => isShadowRun(run.id)).map((run) => [run.id, run]));
27
30
  for (const run of runs) {
31
+ if (isShadowRun(run.id))
32
+ continue;
28
33
  if (!agentArchived.has(run.agentId))
29
34
  agentArchived.set(run.agentId, (await store.agents.get(run.agentId))?.archivedAt ?? null);
30
35
  if (run.archivedAt !== null || agentArchived.get(run.agentId) !== null)
@@ -42,6 +47,8 @@ export async function analytics(store, filter = {}) {
42
47
  const isPending = running && pending[run.id] !== undefined;
43
48
  const metered = !running && metricsOf(run) !== null;
44
49
  const metrics = metered ? metricsOf(run) : null;
50
+ const shadow = shadows.get(shadowRunId(run.id));
51
+ const shadowUsd = shadow && runReadState(shadow, "agentic") !== "running" && shadow.costUsd !== null ? shadow.costUsd : 0;
45
52
  facts.push({
46
53
  startedMs: run.startedAt,
47
54
  endedMs: run.endedAt,
@@ -54,12 +61,15 @@ export async function analytics(store, filter = {}) {
54
61
  harness: harnessOf.get(run.revisionId),
55
62
  source: run.importedFrom?.source ?? "live",
56
63
  effort: metered ? (metrics?.effort ?? null) : null,
64
+ shadowUsd,
57
65
  });
58
66
  }
59
67
  const counted = (group) => {
60
68
  let unknownTokens = false;
61
69
  let runsN = 0, completed = 0, needsReview = 0, failed = 0, metered = 0, tokens = 0, costUsd = 0, known = 0, pend = 0;
70
+ let shadowUsd = 0;
62
71
  for (const f of group) {
72
+ shadowUsd += f.shadowUsd;
63
73
  runsN += 1;
64
74
  if (f.state === "completed" || f.state === "escalated")
65
75
  completed += 1;
@@ -78,7 +88,7 @@ export async function analytics(store, filter = {}) {
78
88
  if (f.pending)
79
89
  pend += 1;
80
90
  }
81
- return { runs: runsN, completed, needsReview, failed, runsWithMetrics: metered, tokens: unknownTokens ? null : tokens, costUsd: known > 0 ? costUsd : null, unknownCostRuns: runsN - known - pend };
91
+ return { runs: runsN, completed, needsReview, failed, runsWithMetrics: metered, tokens: unknownTokens ? null : tokens, costUsd: known > 0 || shadowUsd > 0 ? costUsd + shadowUsd : null, unknownCostRuns: runsN - known - pend };
82
92
  };
83
93
  // Totals over the whole scope: the group counts, the token sums, and the time figures.
84
94
  let input = 0, cacheRead = 0, cacheWrite = 0, output = 0, requests = 0, unmetered = 0;