@parcha/agentrun-serve 0.1.0-beta.44 → 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 (346) hide show
  1. package/CHANGELOG.md +131 -5
  2. package/README.md +371 -300
  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 +52 -16
  28. package/dist/composio-preset.js +69 -7
  29. package/dist/composio-triggers.d.ts +14 -0
  30. package/dist/composio-triggers.js +79 -15
  31. package/dist/computer-attach.d.ts +40 -5
  32. package/dist/computer-attach.js +130 -15
  33. package/dist/computer-keys.d.ts +3 -0
  34. package/dist/computer-keys.js +7 -1
  35. package/dist/computer-live.js +3 -2
  36. package/dist/computers.d.ts +21 -10
  37. package/dist/computers.js +39 -28
  38. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  39. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/decisions.d.ts +1 -1
  42. package/dist/dial-relay.d.ts +29 -0
  43. package/dist/dial-relay.js +94 -0
  44. package/dist/email/tools.js +10 -5
  45. package/dist/env-proxy.d.ts +2 -0
  46. package/dist/env-proxy.js +35 -0
  47. package/dist/errors.d.ts +3 -1
  48. package/dist/errors.js +7 -4
  49. package/dist/faux-computers.d.ts +8 -2
  50. package/dist/faux-computers.js +83 -6
  51. package/dist/harness-archive.d.ts +67 -0
  52. package/dist/harness-archive.js +177 -0
  53. package/dist/harness-goose.d.ts +34 -0
  54. package/dist/harness-goose.js +87 -0
  55. package/dist/harness-install.d.ts +21 -0
  56. package/dist/harness-install.js +24 -11
  57. package/dist/harness-opencode/adapter.js +1 -1
  58. package/dist/harness-table.d.ts +9 -1
  59. package/dist/harness-table.js +20 -3
  60. package/dist/harness.d.ts +1 -2
  61. package/dist/harness.js +3 -4
  62. package/dist/host.js +2 -1
  63. package/dist/key-check.js +3 -0
  64. package/dist/learn/audit.d.ts +6 -6
  65. package/dist/learn/audit.js +3 -7
  66. package/dist/learn/check.d.ts +23 -89
  67. package/dist/learn/check.js +57 -335
  68. package/dist/learn/commit.d.ts +63 -90
  69. package/dist/learn/commit.js +124 -316
  70. package/dist/learn/compile.d.ts +53 -50
  71. package/dist/learn/compile.js +87 -102
  72. package/dist/learn/corrections.d.ts +13 -0
  73. package/dist/learn/corrections.js +23 -0
  74. package/dist/learn/delete.d.ts +5 -5
  75. package/dist/learn/delete.js +8 -10
  76. package/dist/learn/folder.d.ts +35 -47
  77. package/dist/learn/folder.js +118 -134
  78. package/dist/learn/index.d.ts +3 -5
  79. package/dist/learn/index.js +6 -9
  80. package/dist/learn/learning.sh +45 -15
  81. package/dist/learn/promote.d.ts +13 -1
  82. package/dist/learn/promote.js +9 -0
  83. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
  84. package/dist/learn/{skills.js → workflow-draft.js} +48 -58
  85. package/dist/learn/workflow-nodes.js +1 -1
  86. package/dist/learned-workflow.js +2 -2
  87. package/dist/learning-cost.d.ts +38 -24
  88. package/dist/learning-cost.js +41 -24
  89. package/dist/learning-routes.d.ts +91 -170
  90. package/dist/learning-routes.js +183 -421
  91. package/dist/learning-run.d.ts +19 -40
  92. package/dist/learning-run.js +23 -93
  93. package/dist/learning-setting.d.ts +4 -4
  94. package/dist/learning-setting.js +6 -6
  95. package/dist/learning-words.d.ts +28 -74
  96. package/dist/learning-words.js +64 -162
  97. package/dist/learning.d.ts +61 -392
  98. package/dist/learning.js +101 -651
  99. package/dist/live-reach.d.ts +25 -2
  100. package/dist/live-reach.js +46 -4
  101. package/dist/llms.txt +1 -1
  102. package/dist/local-models.d.ts +3 -11
  103. package/dist/local-models.js +5 -6
  104. package/dist/mcp-servers-store.d.ts +4 -4
  105. package/dist/model-form.js +6 -5
  106. package/dist/model.d.ts +4 -0
  107. package/dist/model.js +26 -9
  108. package/dist/native/binding.js +1 -1
  109. package/dist/native/connection.js +1 -1
  110. package/dist/native/discovery.js +1 -1
  111. package/dist/native/instructions.d.ts +3 -0
  112. package/dist/native/instructions.js +5 -3
  113. package/dist/native/remote-worker-bridge.js +9 -43
  114. package/dist/native/remote.d.ts +8 -15
  115. package/dist/native/remote.js +3 -3
  116. package/dist/native/schema.js +1 -1
  117. package/dist/native/types.d.ts +2 -2
  118. package/dist/openapi.js +268 -316
  119. package/dist/paid-calls.d.ts +8 -0
  120. package/dist/paid-calls.js +20 -0
  121. package/dist/particle-provider.d.ts +11 -0
  122. package/dist/particle-provider.js +135 -0
  123. package/dist/port-models.d.ts +12 -4
  124. package/dist/port-models.js +28 -11
  125. package/dist/print.d.ts +27 -0
  126. package/dist/print.js +21 -0
  127. package/dist/provider.d.ts +7 -0
  128. package/dist/provider.js +15 -1
  129. package/dist/reflect-range.js +2 -3
  130. package/dist/run-launch.d.ts +14 -28
  131. package/dist/run-launch.js +9 -12
  132. package/dist/run-learning-served.d.ts +15 -89
  133. package/dist/run-listing.d.ts +34 -0
  134. package/dist/run-listing.js +128 -0
  135. package/dist/run-model-key.js +1 -1
  136. package/dist/run-timeline-served.js +5 -3
  137. package/dist/run-trace.d.ts +97 -0
  138. package/dist/run-trace.js +253 -0
  139. package/dist/run-view.d.ts +15 -0
  140. package/dist/run-view.js +9 -0
  141. package/dist/runnable.js +2 -1
  142. package/dist/runner/adapter-loop.d.ts +8 -6
  143. package/dist/runner/adapter-loop.js +16 -12
  144. package/dist/runner/adapter-run-spec.d.ts +16 -4
  145. package/dist/runner/adapter-run-spec.js +64 -58
  146. package/dist/runner/adapters/index.js +22 -0
  147. package/dist/runner/adapters/pi.d.ts +4 -12
  148. package/dist/runner/adapters/pi.js +2 -2
  149. package/dist/runner/audit.d.ts +1 -1
  150. package/dist/runner/audit.js +16 -8
  151. package/dist/runner/beside.d.ts +6 -2
  152. package/dist/runner/beside.js +38 -9
  153. package/dist/runner/claim-secrets.d.ts +18 -2
  154. package/dist/runner/claim-secrets.js +42 -18
  155. package/dist/runner/cli-run-spec.js +55 -51
  156. package/dist/runner/conformance/harness.d.ts +6 -0
  157. package/dist/runner/conformance/harness.js +16 -5
  158. package/dist/runner/dispatch.d.ts +2 -2
  159. package/dist/runner/end-of-run.d.ts +6 -14
  160. package/dist/runner/end-of-run.js +8 -33
  161. package/dist/runner/feedback-round.d.ts +2 -2
  162. package/dist/runner/feedback-round.js +7 -7
  163. package/dist/runner/github-app.js +3 -1
  164. package/dist/runner/harness-loops.d.ts +0 -8
  165. package/dist/runner/harness-loops.js +11 -59
  166. package/dist/runner/held.d.ts +170 -0
  167. package/dist/runner/held.js +57 -0
  168. package/dist/runner/journal-kinds.d.ts +2 -3
  169. package/dist/runner/journal-kinds.js +2 -3
  170. package/dist/runner/learned-first.d.ts +40 -0
  171. package/dist/runner/learned-first.js +32 -0
  172. package/dist/runner/learning-end.d.ts +77 -69
  173. package/dist/runner/learning-end.js +250 -303
  174. package/dist/runner/learning-seed.d.ts +15 -33
  175. package/dist/runner/learning-seed.js +24 -45
  176. package/dist/runner/loop-contract.d.ts +2 -3
  177. package/dist/runner/main.d.ts +17 -9
  178. package/dist/runner/main.js +63 -20
  179. package/dist/runner/mcp-run.d.ts +11 -0
  180. package/dist/runner/mcp-run.js +67 -0
  181. package/dist/runner/memory-claim.d.ts +10 -5
  182. package/dist/runner/memory-claim.js +12 -6
  183. package/dist/runner/model-route.d.ts +7 -4
  184. package/dist/runner/model-route.js +22 -10
  185. package/dist/runner/native-loop.d.ts +0 -7
  186. package/dist/runner/native-loop.js +9 -101
  187. package/dist/runner/promotion.d.ts +8 -6
  188. package/dist/runner/promotion.js +19 -12
  189. package/dist/runner/reflect-hook.d.ts +64 -95
  190. package/dist/runner/reflect-hook.js +112 -225
  191. package/dist/runner/run-channel.d.ts +43 -0
  192. package/dist/runner/run-channel.js +467 -0
  193. package/dist/runner/run-child-host.d.ts +169 -0
  194. package/dist/runner/run-child-host.js +1222 -0
  195. package/dist/runner/run-child.d.ts +1 -0
  196. package/dist/runner/run-child.js +254 -0
  197. package/dist/runner/run-errors.d.ts +2 -0
  198. package/dist/runner/run-errors.js +20 -0
  199. package/dist/runner/runner.js +1 -5
  200. package/dist/runner/sdk-ask.d.ts +78 -0
  201. package/dist/runner/sdk-ask.js +158 -0
  202. package/dist/runner/sdk-loop.d.ts +2 -4
  203. package/dist/runner/sdk-loop.js +29 -49
  204. package/dist/runner/store-secrets.d.ts +5 -3
  205. package/dist/runner/store-secrets.js +5 -1
  206. package/dist/runner/workflow-first.d.ts +5 -0
  207. package/dist/runner/workflow-first.js +4 -0
  208. package/dist/runner/workflow-spec.js +7 -2
  209. package/dist/runs-over-store.d.ts +16 -28
  210. package/dist/runs-over-store.js +31 -38
  211. package/dist/sdk/runs.d.ts +6 -11
  212. package/dist/sdk/runs.js +20 -41
  213. package/dist/sdk/schema.js +3 -4
  214. package/dist/seal-key.d.ts +5 -0
  215. package/dist/seal-key.js +7 -0
  216. package/dist/secrets.d.ts +3 -0
  217. package/dist/secrets.js +16 -3
  218. package/dist/server.d.ts +55 -33
  219. package/dist/server.js +685 -320
  220. package/dist/sign-ins-store.d.ts +8 -0
  221. package/dist/sign-ins-store.js +36 -1
  222. package/dist/skills.js +1 -1
  223. package/dist/store/index.d.ts +2 -2
  224. package/dist/store/index.js +1 -1
  225. package/dist/store/journal/storage.js +3 -0
  226. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  227. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  228. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  229. package/dist/store/schema.d.ts +53 -4
  230. package/dist/store/schema.js +137 -6
  231. package/dist/store/sqlite/connection.d.ts +2 -0
  232. package/dist/store/sqlite/connection.js +3 -1
  233. package/dist/store/sqlite/run-patch.d.ts +0 -17
  234. package/dist/store/sqlite/run-patch.js +4 -33
  235. package/dist/store/sqlite/store.js +246 -63
  236. package/dist/store/sqlite/worker.js +25 -0
  237. package/dist/store/store.d.ts +193 -36
  238. package/dist/store/store.js +25 -3
  239. package/dist/store-reads/learning.d.ts +102 -204
  240. package/dist/store-reads/learning.js +159 -321
  241. package/dist/store-reads/loop.d.ts +0 -1
  242. package/dist/store-reads/loop.js +1 -1
  243. package/dist/store-view.d.ts +29 -1
  244. package/dist/store-view.js +97 -31
  245. package/dist/template-eval.d.ts +3 -6
  246. package/dist/template-eval.js +22 -36
  247. package/dist/templates.d.ts +2 -1
  248. package/dist/templates.js +6 -3
  249. package/dist/timeline/index.d.ts +1 -1
  250. package/dist/timeline/index.js +1 -1
  251. package/dist/timeline/timeline.d.ts +5 -1
  252. package/dist/timeline/timeline.js +16 -0
  253. package/dist/tool-gate.d.ts +0 -7
  254. package/dist/tool-gate.js +1 -15
  255. package/dist/tool-keys-store.d.ts +1 -1
  256. package/dist/tool-keys.d.ts +6 -4
  257. package/dist/tool-keys.js +12 -6
  258. package/dist/tools.d.ts +2 -2
  259. package/dist/tools.js +11 -4
  260. package/dist/triggers.d.ts +60 -5
  261. package/dist/triggers.js +123 -18
  262. package/dist/validate.js +1 -1
  263. package/dist/webhooks.d.ts +4 -1
  264. package/dist/webhooks.js +11 -4
  265. package/dist/workspace/agent-computer.d.ts +2 -0
  266. package/dist/workspace/agent-computer.js +2 -0
  267. package/dist/workspace/archil-claim.d.ts +7 -0
  268. package/dist/workspace/archil-claim.js +29 -0
  269. package/dist/workspace/archil.d.ts +9 -1
  270. package/dist/workspace/archil.js +165 -3
  271. package/dist/workspace/attach.d.ts +3 -1
  272. package/dist/workspace/attach.js +2 -0
  273. package/dist/workspace/attached-computers.d.ts +16 -5
  274. package/dist/workspace/attached-computers.js +25 -9
  275. package/dist/workspace/computer-deps.js +1 -1
  276. package/dist/workspace/computer-for-claim.d.ts +7 -3
  277. package/dist/workspace/computer-for-claim.js +119 -22
  278. package/dist/workspace/computer-hold.js +2 -1
  279. package/dist/workspace/computer-kept.d.ts +11 -1
  280. package/dist/workspace/computer-kept.js +24 -3
  281. package/dist/workspace/resolve-computer.d.ts +33 -19
  282. package/dist/workspace/resolve-computer.js +172 -64
  283. package/dist/workspace/revision-skills.d.ts +1 -2
  284. package/dist/workspace/revision-skills.js +3 -4
  285. package/dist/workspace/run-workspace.d.ts +1 -1
  286. package/dist/workspace/run-workspace.js +5 -0
  287. package/dist/workspace/synced-folder.d.ts +85 -0
  288. package/dist/workspace/synced-folder.js +230 -0
  289. package/dist/workspace/workspace.d.ts +4 -0
  290. package/launcher/agentrun-serve +1 -1
  291. package/package.json +10 -10
  292. package/templates/README.md +7 -7
  293. package/templates/inbound-lead/agent.md +3 -3
  294. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  295. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  296. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  297. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  298. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  299. package/templates/inbound-lead/lead.schema.json +6 -5
  300. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  301. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  302. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  303. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  304. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  305. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  306. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  307. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  308. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  309. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  310. package/dist/console/assets/index-BUktRvS-.css +0 -1
  311. package/dist/console/assets/index-nB9kTfIN.js +0 -711
  312. package/dist/learn/grade.d.ts +0 -138
  313. package/dist/learn/grade.js +0 -682
  314. package/dist/learn/notes.d.ts +0 -81
  315. package/dist/learn/notes.js +0 -178
  316. package/dist/learn/reflect.d.ts +0 -77
  317. package/dist/learn/reflect.js +0 -228
  318. package/dist/learn/relevance.d.ts +0 -24
  319. package/dist/learn/relevance.js +0 -91
  320. package/dist/learn/seed-check.d.ts +0 -74
  321. package/dist/learn/seed-check.js +0 -103
  322. package/dist/learning-batch.d.ts +0 -291
  323. package/dist/learning-batch.js +0 -600
  324. package/dist/learning-evals.d.ts +0 -35
  325. package/dist/learning-evals.js +0 -99
  326. package/dist/native/context.d.ts +0 -6
  327. package/dist/native/context.js +0 -22
  328. package/dist/propose.d.ts +0 -52
  329. package/dist/propose.js +0 -224
  330. package/dist/runner/learning-ask.d.ts +0 -47
  331. package/dist/runner/learning-ask.js +0 -128
  332. package/dist/runner/learning-dispatch.d.ts +0 -45
  333. package/dist/runner/learning-dispatch.js +0 -99
  334. package/dist/runner/learning-factory.d.ts +0 -16
  335. package/dist/runner/learning-factory.js +0 -50
  336. package/dist/runner/learning-loop.d.ts +0 -273
  337. package/dist/runner/learning-loop.js +0 -521
  338. package/dist/usage.d.ts +0 -11
  339. package/dist/usage.js +0 -11
  340. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  341. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  342. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  343. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  344. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  345. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  346. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -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";
@@ -256,8 +304,8 @@ export type AlsoRow = {
256
304
  marker: string;
257
305
  };
258
306
  }
259
- /** 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
260
- * 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. */
261
309
  | {
262
310
  readonly table: "learning_proposals";
263
311
  readonly row: {
@@ -265,21 +313,6 @@ export type AlsoRow = {
265
313
  proposal: unknown;
266
314
  round?: number;
267
315
  };
268
- }
269
- /** The learning run that grades and merges the kept proposal: a queued run `id` of the run's agent and revision. Started
270
- * once: the same id staged again (an end replayed after a crash) adds nothing. */
271
- /** `model`: the grade model (gradeModelOf, as the server resolves it), on the learning run's launch; none, the agent's own.
272
- * `round`: the round it grades (absent: 1), named in its launch. `capUsd`: what the run's cap leaves once everything it
273
- * spent is counted (learning-end.ts gradeCapOf), the learning run's own cap (its launch's max_cost_usd), so its grade
274
- * never takes the run past its cap; absent for an uncapped run, whose grade is capped by nothing. */
275
- | {
276
- readonly table: "learning_run";
277
- readonly row: {
278
- id: string;
279
- model?: string;
280
- round?: number;
281
- capUsd?: number;
282
- };
283
316
  };
284
317
  /** A run's kept learning (learning_proposals): what its end-of-run turn asked and answered, and the proposal checked from it. */
285
318
  export interface LearningProposal {
@@ -301,9 +334,6 @@ export interface Learning {
301
334
  proposals(agentId: string, options?: {
302
335
  limit?: number;
303
336
  }): Promise<LearningProposal[]>;
304
- /** The agent's kept proposals whose learning run (its grade) has not ended: queued, running or parked. Every one of
305
- * them, however many proposals were kept since, newest first. */
306
- grading(agentId: string): Promise<LearningProposal[]>;
307
337
  /** Everything agent `agentId`'s runs' learning kept, in two reads whatever the number of its runs: every round of every
308
338
  * run's kept proposal (oldest round first within a run), and the rows of the learning runs they name (as runs.get
309
339
  * reads one; a learning run named and never written has none). An agent-wide read's, never a read a run. */
@@ -319,14 +349,6 @@ export interface Learning {
319
349
  from: number;
320
350
  to: number;
321
351
  }): Promise<LearningSpend[]>;
322
- /** What was spent beside run `runId` on its behalf, the one figure every cap gate of the run reads with its own
323
- * sessions (and its grade's cap, learning-end.ts gradeCapOf): each learning run its rounds queued (`beforeRound`: only
324
- * those of the rounds before it), one that ended at its cost, one not ended at its own cap (the most its grade may
325
- * take), and one that ended at an unknown cost at that cap too, the most it could have taken. Null: unknown (one with
326
- * neither). 0 for a run that queued none. */
327
- spentBeside(runId: string, options?: {
328
- beforeRound?: number;
329
- }): Promise<number | null>;
330
352
  }
331
353
  /** One run's learning end as GET /usage's learning meter counts it (Learning.spend). */
332
354
  export interface LearningSpend {
@@ -507,6 +529,10 @@ export interface TriggerRow {
507
529
  readonly maxActiveRuns: number | null;
508
530
  readonly createdAt: number;
509
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;
510
536
  }
511
537
  /** A trigger's firing that starts a run. */
512
538
  export interface Firing {
@@ -569,6 +595,8 @@ export interface NewTrigger {
569
595
  readonly nextAt: number | null;
570
596
  readonly catchupWindowS: number;
571
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;
572
600
  }
573
601
  /** A trigger's fields changed; the ones absent stay. */
574
602
  /** `agentId`: the agent it belongs to, which follows its target (a PATCH may aim it at another agent's run or agent). */
@@ -576,11 +604,13 @@ export interface NewTrigger {
576
604
  * undefined otherwise, as when there is no such trigger. `ifUpdatedAt`: the row's updatedAt is still this one.
577
605
  * `ifSource`: its source is still this one, as the store keeps it; two writes in one millisecond share an updatedAt, so a
578
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). */
579
608
  export type TriggerUpdateOptions = {
580
609
  readonly ifUpdatedAt?: number;
581
610
  readonly ifSource?: unknown;
611
+ readonly ifAgent?: string;
582
612
  };
583
- export type TriggerPatch = Partial<Pick<TriggerRow, "agentId" | "name" | "enabled" | "source" | "target" | "nextAt" | "catchupWindowS" | "failuresInARow" | "disabled" | "maxActiveRuns">>;
613
+ export type TriggerPatch = Partial<Pick<TriggerRow, "agentId" | "name" | "enabled" | "source" | "target" | "nextAt" | "catchupWindowS" | "failuresInARow" | "disabled" | "maxActiveRuns" | "templateId">>;
584
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). */
585
615
  export interface FiringChange {
586
616
  readonly status?: FiringStatus;
@@ -616,6 +646,24 @@ export declare class AgentArchived extends Error {
616
646
  name: string;
617
647
  constructor(agentId: string);
618
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
+ }
619
667
  /** An inline-agent run whose body differs from the one already stored for its external reference and version: refused,
620
668
  * nothing written (Runs.createInline). A version's body is immutable; a changed body needs a new version. */
621
669
  export declare class ExternalBodyConflict extends Error {
@@ -672,6 +720,11 @@ export interface Agents {
672
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
673
721
  * there is no such revision. */
674
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>;
675
728
  }
676
729
  export interface Templates {
677
730
  /** A template applied: the agent, its first revision (with the package) and its triggers, in one transaction, all or
@@ -699,14 +752,18 @@ export interface Triggers {
699
752
  all(): Promise<TriggerRow[]>;
700
753
  /** The trigger and, while it is enabled, its scope rows (`scopes`), in one transaction: a scope another enabled trigger
701
754
  * holds is refused (StoreConstraint on trigger_scopes), nothing written; one made on for an archived agent too
702
- * (AgentArchived). */
755
+ * (AgentArchived), and one made at all, off too, for an agent being deleted (AgentDeleting). */
703
756
  create(trigger: NewTrigger, scopes?: readonly TriggerScope[]): Promise<TriggerRow>;
704
757
  /** The fields given changed, `updatedAt` set: undefined when there is no such trigger. With `scopes`, its scope rows
705
758
  * rewritten in the same transaction (none while it is off); a patch that turns it off drops them. One that leaves it
706
- * on for an archived agent, turned on or moved there, is refused (AgentArchived), nothing written. */
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). */
707
761
  update(id: string, patch: TriggerPatch, scopes?: readonly TriggerScope[], options?: TriggerUpdateOptions): Promise<TriggerRow | undefined>;
708
- /** The trigger, its scope rows and its firings gone. */
709
- remove(id: string): Promise<void>;
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>;
710
767
  /** Enables the trigger and writes its scope rows, in one transaction; refused for an archived agent's (AgentArchived). */
711
768
  enable(triggerId: string, scopes: readonly TriggerScope[]): Promise<void>;
712
769
  /** Disables the trigger (with why, JSON) and deletes its scope rows, in one transaction. */
@@ -848,8 +905,64 @@ export interface Runs {
848
905
  labels?: RunLabels;
849
906
  limit?: number;
850
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>;
851
951
  /** Archives the run (its own archive time), or unarchives it: idempotent. */
852
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>;
853
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
854
967
  * (released, so a runner claims it at once by the claimable rule's released branch), its end's own fields cleared
855
968
  * (ended_at, summary, outcome, its waits) and everything it did kept (its epoch, its journal, its cost and metrics,
@@ -1275,19 +1388,61 @@ export interface MintedTokenRow {
1275
1388
  /** When it was revoked (the machine's delete); null while it is good. */
1276
1389
  readonly revokedAt: number | null;
1277
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;
1278
1402
  }
1279
1403
  /** The tokens minted for hosted machines that dial this server (a dial provider's create, spec/computer/attach.md). */
1280
1404
  export interface MintedTokens {
1281
- /** 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. */
1282
1408
  mint(token: Pick<MintedTokenRow, "machine" | "kind" | "os" | "arch" | "expiresAt"> & {
1283
1409
  readonly tokenSha256: string;
1284
- }): Promise<void>;
1285
- /** 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. */
1286
1414
  byToken(tokenSha256: string): Promise<MintedTokenRow | undefined>;
1287
1415
  /** The machine's row, good or not; undefined when it has none (never minted, or gone past its end). */
1288
1416
  get(machine: string): Promise<MintedTokenRow | undefined>;
1289
1417
  /** Revokes the machine's token. False when it had none good. */
1290
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>;
1291
1446
  }
1292
1447
  /** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
1293
1448
  * (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
@@ -1542,6 +1697,8 @@ export interface Store {
1542
1697
  readonly pairedComputers: PairedComputers;
1543
1698
  /** The tokens minted for hosted machines that dial this server, each kept as its SHA-256. */
1544
1699
  readonly mintedTokens: MintedTokens;
1700
+ /** Where each runner in a process of its own takes the dials relayed to it. */
1701
+ readonly runnerRelays: RunnerRelays;
1545
1702
  /** The template packages imported from GitHub, their files kept as read. */
1546
1703
  readonly importedTemplates: ImportedTemplates;
1547
1704
  /** Each trigger source's sealed settings (design 2.1): a value per adapter, scope and field. */
@@ -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 {