@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.53

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 (322) hide show
  1. package/CHANGELOG.md +160 -1
  2. package/README.md +306 -36
  3. package/dist/adapters.js +1 -1
  4. package/dist/agent-delete.d.ts +14 -4
  5. package/dist/agent-delete.js +30 -58
  6. package/dist/agent-package.d.ts +71 -0
  7. package/dist/agent-package.js +345 -0
  8. package/dist/agents-store.d.ts +28 -18
  9. package/dist/agents-store.js +48 -34
  10. package/dist/api-only.d.ts +30 -8
  11. package/dist/api-only.js +40 -16
  12. package/dist/archil-routes.d.ts +1 -0
  13. package/dist/archil-routes.js +28 -2
  14. package/dist/claude-login.d.ts +1 -0
  15. package/dist/claude-login.js +1 -1
  16. package/dist/cli-learning/cli.d.ts +3 -0
  17. package/dist/cli-learning/cli.js +17 -3
  18. package/dist/cli-learning/connections.js +3 -2
  19. package/dist/cli-learning/schema.js +2 -1
  20. package/dist/cli.js +70 -7
  21. package/dist/composio-preset.d.ts +2 -1
  22. package/dist/composio-preset.js +4 -3
  23. package/dist/composio-triggers.d.ts +4 -0
  24. package/dist/composio-triggers.js +4 -1
  25. package/dist/computer-needs.d.ts +32 -0
  26. package/dist/computer-needs.js +80 -0
  27. package/dist/computer-setting.d.ts +9 -0
  28. package/dist/computer-setting.js +19 -1
  29. package/dist/computers.d.ts +6 -2
  30. package/dist/computers.js +2 -2
  31. package/dist/console/assets/index-BFgyZzF_.js +734 -0
  32. package/dist/console/assets/index-DbilxljH.css +1 -0
  33. package/dist/console/index.html +2 -2
  34. package/dist/console-links.d.ts +1 -0
  35. package/dist/console-links.js +2 -0
  36. package/dist/env-switch.d.ts +14 -0
  37. package/dist/env-switch.js +23 -0
  38. package/dist/errors.d.ts +1 -0
  39. package/dist/errors.js +3 -0
  40. package/dist/eval-previous.js +4 -3
  41. package/dist/fal-price.d.ts +76 -0
  42. package/dist/fal-price.js +365 -0
  43. package/dist/handed-secret.d.ts +4 -0
  44. package/dist/handed-secret.js +10 -0
  45. package/dist/harness-archive.d.ts +15 -5
  46. package/dist/harness-archive.js +71 -34
  47. package/dist/harness-check.d.ts +2 -1
  48. package/dist/harness-check.js +36 -95
  49. package/dist/harness-egress.d.ts +23 -0
  50. package/dist/harness-egress.js +69 -0
  51. package/dist/harness-recipe-entry.d.ts +71 -0
  52. package/dist/harness-recipe-entry.js +184 -0
  53. package/dist/harness-recipe.d.ts +73 -6
  54. package/dist/harness-recipe.js +185 -31
  55. package/dist/harness-sign-in.d.ts +29 -0
  56. package/dist/harness-sign-in.js +122 -0
  57. package/dist/harness-table.d.ts +21 -0
  58. package/dist/harness-table.js +58 -3
  59. package/dist/harness-zip.d.ts +6 -0
  60. package/dist/harness-zip.js +203 -0
  61. package/dist/ids.d.ts +11 -0
  62. package/dist/ids.js +36 -0
  63. package/dist/learn/commit.d.ts +19 -1
  64. package/dist/learn/commit.js +160 -2
  65. package/dist/learn/compile.d.ts +13 -5
  66. package/dist/learn/compile.js +46 -15
  67. package/dist/learn/delete.d.ts +12 -6
  68. package/dist/learn/delete.js +17 -11
  69. package/dist/learn/folder.d.ts +16 -0
  70. package/dist/learn/folder.js +30 -4
  71. package/dist/learn/learning-of.d.ts +8 -0
  72. package/dist/learn/learning-of.js +8 -0
  73. package/dist/learn/learning.sh +29 -4
  74. package/dist/learn/promote.d.ts +51 -7
  75. package/dist/learn/promote.js +51 -8
  76. package/dist/learn/secrets.js +30 -7
  77. package/dist/learning-reset.d.ts +18 -0
  78. package/dist/learning-reset.js +115 -0
  79. package/dist/learning-routes.d.ts +23 -11
  80. package/dist/learning-routes.js +110 -20
  81. package/dist/learning-words.d.ts +5 -0
  82. package/dist/learning-words.js +5 -0
  83. package/dist/learning.d.ts +15 -10
  84. package/dist/learning.js +14 -8
  85. package/dist/llms.txt +1 -0
  86. package/dist/mcp-gateway.d.ts +39 -2
  87. package/dist/mcp-gateway.js +56 -12
  88. package/dist/mcp-pin-first.js +1 -1
  89. package/dist/mcp-probe.d.ts +3 -0
  90. package/dist/mcp-probe.js +7 -2
  91. package/dist/mcp-resources.d.ts +44 -0
  92. package/dist/mcp-resources.js +100 -0
  93. package/dist/mcp-servers-store.d.ts +17 -12
  94. package/dist/mcp-servers-store.js +2 -1
  95. package/dist/media-duration.d.ts +2 -0
  96. package/dist/media-duration.js +136 -0
  97. package/dist/model.d.ts +4 -4
  98. package/dist/model.js +6 -6
  99. package/dist/native/cli.js +9 -2
  100. package/dist/native/connection.d.ts +2 -2
  101. package/dist/native/connection.js +5 -2
  102. package/dist/native/discovery.d.ts +2 -0
  103. package/dist/native/discovery.js +10 -6
  104. package/dist/native/remote-worker-bridge.js +36 -4
  105. package/dist/native/remote.d.ts +18 -1
  106. package/dist/native/remote.js +126 -37
  107. package/dist/native/schema.d.ts +6 -0
  108. package/dist/native/schema.js +31 -6
  109. package/dist/native/source-account.d.ts +13 -0
  110. package/dist/native/source-account.js +114 -0
  111. package/dist/native/source-capture-hooks.d.ts +5 -0
  112. package/dist/native/source-capture-hooks.js +102 -0
  113. package/dist/native/source-mcp-selection.d.ts +13 -0
  114. package/dist/native/source-mcp-selection.js +72 -0
  115. package/dist/native/source-runtime-tools.d.ts +19 -0
  116. package/dist/native/source-runtime-tools.js +103 -0
  117. package/dist/native/source-snapshot-types.d.ts +138 -0
  118. package/dist/native/source-snapshot-types.js +12 -0
  119. package/dist/native/source-snapshot.d.ts +8 -0
  120. package/dist/native/source-snapshot.js +1201 -0
  121. package/dist/observation/learning.js +3 -2
  122. package/dist/openapi.js +211 -47
  123. package/dist/print.js +1 -1
  124. package/dist/provider.d.ts +8 -0
  125. package/dist/provider.js +14 -2
  126. package/dist/purged-workflow.d.ts +12 -0
  127. package/dist/purged-workflow.js +43 -0
  128. package/dist/refusal-words.d.ts +0 -3
  129. package/dist/refusal-words.js +0 -3
  130. package/dist/request-metadata.d.ts +20 -0
  131. package/dist/request-metadata.js +24 -0
  132. package/dist/run-keys.d.ts +46 -0
  133. package/dist/run-keys.js +109 -0
  134. package/dist/run-launch.d.ts +29 -5
  135. package/dist/run-launch.js +44 -4
  136. package/dist/run-learning-served.d.ts +2 -2
  137. package/dist/run-model-key.d.ts +2 -2
  138. package/dist/run-model-key.js +5 -5
  139. package/dist/run-secrets.d.ts +2 -0
  140. package/dist/run-secrets.js +7 -4
  141. package/dist/run-usage.d.ts +48 -4
  142. package/dist/run-usage.js +156 -39
  143. package/dist/run-view.d.ts +18 -1
  144. package/dist/run-view.js +28 -8
  145. package/dist/runner/adapter-loop.d.ts +14 -4
  146. package/dist/runner/adapter-loop.js +150 -31
  147. package/dist/runner/adapter-run-spec.d.ts +1 -1
  148. package/dist/runner/adapter-run-spec.js +35 -22
  149. package/dist/runner/audit.d.ts +10 -3
  150. package/dist/runner/audit.js +30 -7
  151. package/dist/runner/beside.js +2 -1
  152. package/dist/runner/claim-secrets.d.ts +31 -4
  153. package/dist/runner/claim-secrets.js +43 -7
  154. package/dist/runner/cli-run-spec.d.ts +1 -1
  155. package/dist/runner/cli-run-spec.js +32 -20
  156. package/dist/runner/conformance/harness.js +4 -2
  157. package/dist/runner/dispatch.js +4 -2
  158. package/dist/runner/harness-loops.d.ts +6 -0
  159. package/dist/runner/harness-loops.js +16 -3
  160. package/dist/runner/held.d.ts +4 -0
  161. package/dist/runner/journal-kinds.d.ts +5 -0
  162. package/dist/runner/learned-first.d.ts +2 -0
  163. package/dist/runner/learned-first.js +1 -1
  164. package/dist/runner/learning-end.d.ts +9 -3
  165. package/dist/runner/learning-end.js +66 -29
  166. package/dist/runner/learning-seed.d.ts +9 -3
  167. package/dist/runner/learning-seed.js +2 -2
  168. package/dist/runner/main.d.ts +1 -0
  169. package/dist/runner/main.js +20 -13
  170. package/dist/runner/mcp-claim.js +7 -2
  171. package/dist/runner/mcp-run.d.ts +12 -0
  172. package/dist/runner/mcp-run.js +14 -1
  173. package/dist/runner/model-route.js +7 -4
  174. package/dist/runner/monid-run.js +9 -11
  175. package/dist/runner/project-checkpoint.d.ts +35 -0
  176. package/dist/runner/project-checkpoint.js +116 -0
  177. package/dist/runner/project-drain.d.ts +8 -0
  178. package/dist/runner/project-drain.js +25 -0
  179. package/dist/runner/project-host.d.ts +10 -0
  180. package/dist/runner/project-host.js +52 -0
  181. package/dist/runner/promotion.d.ts +51 -24
  182. package/dist/runner/promotion.js +206 -78
  183. package/dist/runner/redact.d.ts +13 -0
  184. package/dist/runner/redact.js +67 -1
  185. package/dist/runner/run-channel.d.ts +9 -0
  186. package/dist/runner/run-channel.js +15 -2
  187. package/dist/runner/run-child-host.d.ts +8 -4
  188. package/dist/runner/run-child-host.js +174 -42
  189. package/dist/runner/run-errors.js +2 -2
  190. package/dist/runner/runner-check.js +5 -2
  191. package/dist/runner/runner.js +41 -12
  192. package/dist/runner/sdk-loop.d.ts +2 -2
  193. package/dist/runner/sdk-loop.js +3 -3
  194. package/dist/runner/store-port.d.ts +3 -0
  195. package/dist/runner/store-secrets.js +7 -3
  196. package/dist/runner/workflow-first.d.ts +4 -0
  197. package/dist/runner/workflow-first.js +13 -0
  198. package/dist/runner/workflow-loop.d.ts +2 -1
  199. package/dist/runner/workflow-loop.js +2 -1
  200. package/dist/runner/workflow-spec.js +4 -4
  201. package/dist/runs-over-store.d.ts +39 -8
  202. package/dist/runs-over-store.js +147 -32
  203. package/dist/sdk/check.d.ts +6 -5
  204. package/dist/sdk/check.js +17 -16
  205. package/dist/sdk/runs.d.ts +11 -1
  206. package/dist/sdk/runs.js +185 -78
  207. package/dist/sdk/schema.js +12 -2
  208. package/dist/sdk/workflows.d.ts +1 -1
  209. package/dist/server.d.ts +68 -32
  210. package/dist/server.js +678 -124
  211. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  212. package/dist/source-sync/adoption.d.ts +15 -0
  213. package/dist/source-sync/adoption.js +36 -0
  214. package/dist/source-sync/auxiliary.d.ts +23 -0
  215. package/dist/source-sync/auxiliary.js +64 -0
  216. package/dist/source-sync/capture-git.d.ts +5 -0
  217. package/dist/source-sync/capture-git.js +272 -0
  218. package/dist/source-sync/capture-project.d.ts +53 -0
  219. package/dist/source-sync/capture-project.js +206 -0
  220. package/dist/source-sync/capture-refusal.d.ts +7 -0
  221. package/dist/source-sync/capture-refusal.js +16 -0
  222. package/dist/source-sync/capture.d.ts +11 -0
  223. package/dist/source-sync/capture.js +22 -0
  224. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  225. package/dist/source-sync/checkpoint-gate.js +52 -0
  226. package/dist/source-sync/checkpoints.d.ts +66 -0
  227. package/dist/source-sync/checkpoints.js +168 -0
  228. package/dist/source-sync/claim.d.ts +11 -0
  229. package/dist/source-sync/claim.js +48 -0
  230. package/dist/source-sync/destination.d.ts +47 -0
  231. package/dist/source-sync/destination.js +239 -0
  232. package/dist/source-sync/io.d.ts +15 -0
  233. package/dist/source-sync/io.js +52 -0
  234. package/dist/source-sync/local.d.ts +43 -0
  235. package/dist/source-sync/local.js +229 -0
  236. package/dist/source-sync/prepare.d.ts +59 -0
  237. package/dist/source-sync/prepare.js +93 -0
  238. package/dist/source-sync/projects.d.ts +61 -0
  239. package/dist/source-sync/projects.js +130 -0
  240. package/dist/source-sync/registry.d.ts +95 -0
  241. package/dist/source-sync/registry.js +226 -0
  242. package/dist/source-sync/service.d.ts +33 -0
  243. package/dist/source-sync/service.js +118 -0
  244. package/dist/source-sync/skill-edits.d.ts +12 -0
  245. package/dist/source-sync/skill-edits.js +122 -0
  246. package/dist/source-sync/snapshots.d.ts +48 -0
  247. package/dist/source-sync/snapshots.js +448 -0
  248. package/dist/source-sync/types.d.ts +9 -0
  249. package/dist/source-sync/types.js +14 -0
  250. package/dist/source-sync/workspace.d.ts +66 -0
  251. package/dist/source-sync/workspace.js +273 -0
  252. package/dist/store/agent-body.d.ts +8 -0
  253. package/dist/store/agent-body.js +20 -6
  254. package/dist/store/index.d.ts +2 -2
  255. package/dist/store/index.js +1 -1
  256. package/dist/store/journal/storage.d.ts +2 -0
  257. package/dist/store/journal/storage.js +2 -1
  258. package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
  259. package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
  260. package/dist/store/schema.d.ts +15 -1
  261. package/dist/store/schema.js +43 -4
  262. package/dist/store/seal.d.ts +5 -1
  263. package/dist/store/seal.js +12 -3
  264. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  265. package/dist/store/sqlite/project-checkpoints.js +70 -0
  266. package/dist/store/sqlite/run-launch.d.ts +14 -0
  267. package/dist/store/sqlite/run-launch.js +58 -7
  268. package/dist/store/sqlite/run-patch.d.ts +2 -1
  269. package/dist/store/sqlite/run-patch.js +4 -3
  270. package/dist/store/sqlite/store.js +319 -153
  271. package/dist/store/store-schema.js +2 -2
  272. package/dist/store/store.d.ts +173 -33
  273. package/dist/store/store.js +14 -1
  274. package/dist/store-reads/learning.d.ts +12 -8
  275. package/dist/store-reads/learning.js +33 -24
  276. package/dist/store-reads/loop.d.ts +4 -3
  277. package/dist/store-reads/loop.js +7 -5
  278. package/dist/store-view.d.ts +3 -1
  279. package/dist/store-view.js +17 -5
  280. package/dist/template-eval.js +4 -4
  281. package/dist/template-import.d.ts +10 -2
  282. package/dist/template-import.js +116 -13
  283. package/dist/templates.d.ts +29 -5
  284. package/dist/templates.js +68 -14
  285. package/dist/timeline/index.d.ts +1 -1
  286. package/dist/timeline/index.js +1 -1
  287. package/dist/timeline/labels.js +1 -1
  288. package/dist/timeline/timeline.d.ts +5 -0
  289. package/dist/timeline/timeline.js +8 -0
  290. package/dist/tool-plane.d.ts +12 -12
  291. package/dist/tools.d.ts +8 -8
  292. package/dist/tools.js +1 -1
  293. package/dist/trigger-launch-hook.d.ts +47 -0
  294. package/dist/trigger-launch-hook.js +90 -0
  295. package/dist/trigger-targets.d.ts +14 -1
  296. package/dist/trigger-targets.js +20 -0
  297. package/dist/triggers.d.ts +54 -5
  298. package/dist/triggers.js +143 -8
  299. package/dist/uploads-archil.js +2 -1
  300. package/dist/uploads.d.ts +0 -3
  301. package/dist/uploads.js +2 -11
  302. package/dist/validate.js +4 -1
  303. package/dist/web-save.d.ts +3 -0
  304. package/dist/web-save.js +17 -2
  305. package/dist/workspace/archil-exec.js +1 -1
  306. package/dist/workspace/archil.js +1 -1
  307. package/dist/workspace/computer-for-claim.d.ts +2 -0
  308. package/dist/workspace/computer-for-claim.js +43 -0
  309. package/dist/workspace/paths.d.ts +6 -0
  310. package/dist/workspace/paths.js +6 -0
  311. package/dist/workspace/resolve-computer.d.ts +1 -0
  312. package/dist/workspace/revision-skills.js +24 -11
  313. package/dist/workspace/run-tools.d.ts +2 -0
  314. package/dist/workspace/run-tools.js +8 -0
  315. package/dist/workspace/synced-folder.d.ts +3 -3
  316. package/dist/workspace/synced-folder.js +7 -6
  317. package/launcher/agentrun-serve +1 -1
  318. package/package.json +10 -10
  319. package/skills/agentrun-serve/SKILL.md +2 -1
  320. package/templates/README.md +5 -2
  321. package/dist/console/assets/index-Bt1B51b7.js +0 -733
  322. package/dist/console/assets/index-sVftE9Ht.css +0 -1
@@ -23,7 +23,7 @@ import { storePlace, storeTarget } from "./open.js";
23
23
  import { SCHEMA_VERSION } from "./schema.js";
24
24
  import { earlierVersionIn, runnerWaitsFor, STORE_FILE } from "./sqlite/store.js";
25
25
  /** The SQLite store's versions the server upgrades in place (sqlite/store.ts openSqliteStore). */
26
- const SQLITE_UPGRADES = new Set([11, 12, 13]);
26
+ const SQLITE_UPGRADES = new Set([11, 12, 13, 14]);
27
27
  /** What a build that knows `build` does with a store at `state`, on `kind`. `earlier`: the data directory holds an earlier
28
28
  * version's files (SQLite only), which this build's server refuses to start beside (StoreFromEarlierVersion). `awaits`:
29
29
  * on SQLite at this build's version, a column this build's runner needs that the file lacks (SQLITE_RUNNER_NEEDS), which
@@ -34,7 +34,7 @@ export function storeSchemaReport(target, state, build, earlier = false, awaits
34
34
  ? "refuses"
35
35
  : version === null ? "sets up" : version === build ? "opens" : version > build ? "refuses" : target.kind === "postgres" || SQLITE_UPGRADES.has(version) ? "migrates" : "refuses";
36
36
  // A SQLite runner opens only its own version: its floor is the version (sqlite/store.ts schemaState).
37
- // On SQLite a runner waits only for a version its server upgrades in place (11-13), and refuses any other earlier one.
37
+ // On SQLite a runner waits only for a version its server upgrades in place (11-14), and refuses any other earlier one.
38
38
  const runner = target.kind === "sqlite" && version !== null && version < build && !SQLITE_UPGRADES.has(version)
39
39
  ? "refused"
40
40
  : awaits && version === build ? "waits" : runnerOn(target.kind === "sqlite" ? { version, runnerFloor: version } : state, build);
@@ -26,6 +26,48 @@ export interface Claim {
26
26
  readonly lost?: {
27
27
  readonly runner: string;
28
28
  };
29
+ /** Which turn of the run this claim works and which attempt at it (run_attempts, RunAttemptRow): set by the claim that
30
+ * took the run, absent on a claim read back (claimsOf) and on a store that keeps none (a test's). */
31
+ readonly turn?: number;
32
+ readonly attempt?: number;
33
+ }
34
+ /** Why a claim let its run go while the run was still at work, so another claim does that work again: `drain`, its
35
+ * runner closed (a deploy, a scale-down) and handed the run back; `retry`, its loop ended interrupted on its own (or its
36
+ * end was refused) and the run was released to be tried again; `lease_lapse`, its runner was there but could not renew
37
+ * the claim before it ran out; `crash`, the claim's lease ran out with nothing said of it (its runner died). */
38
+ export type AttemptCause = "drain" | "crash" | "lease_lapse" | "retry";
39
+ /** One claim of a run (store schema `run_attempts`), written by the claim itself: the turn it works and its attempt at
40
+ * it. A turn is the work one claim starts afresh: the run's first, a follow-up's, a resume after a park. A claim that
41
+ * takes over a turn another claim was cut from (its run still running, and that claim let it go for `cut`, or its lease
42
+ * ran out) works the same turn again: its attempt is one more, and `cause` says why the one before was cut. Infra's
43
+ * work, not the run's: every request the cut attempt made is made again. `journalFrom`: the first journal entry id this
44
+ * claim could write (the run's next id when it claimed), so each entry of the run's journal is read as its claim's. */
45
+ export interface RunAttemptRow {
46
+ readonly runId: string;
47
+ readonly epoch: number;
48
+ readonly turn: number;
49
+ readonly attempt: number;
50
+ /** Why the attempt before was cut; null on a turn's first attempt. */
51
+ readonly cause: AttemptCause | null;
52
+ /** Why this claim let the run go with its turn unfinished (`drain`, `retry`, `lease_lapse`); null while it holds the
53
+ * run, and when it ended the turn (an answer, a park, the run's end) or died without a word. */
54
+ readonly cut: Exclude<AttemptCause, "crash"> | null;
55
+ readonly runner: string;
56
+ readonly from: RunState;
57
+ readonly journalFrom: number;
58
+ /** When the claim took the run, on the store's clock (ms). */
59
+ readonly claimedAt: number;
60
+ }
61
+ /** Each claim of a run, its turn and attempt (RunAttemptRow): written in the claim's own transaction, its `cut` in its
62
+ * release's. The source-project recovery read also uses the actual claim identity and journal boundary to report a
63
+ * terminal attempt with no checkpoint; it never infers a completed capture or retries work from these rows. */
64
+ export interface RunAttempts {
65
+ /** The claim at `epoch` lost its lease while its runner was there (runner.ts loseClaim): its cut, and the cause of the
66
+ * claim that took the run over from it if that one was read as a crash. Unfenced and idempotent: a cut already said, or
67
+ * a claim with no row, is left as it is. */
68
+ lapsed(runId: string, epoch: number): Promise<void>;
69
+ /** The run's claims, by epoch. */
70
+ forRun(runId: string): Promise<RunAttemptRow[]>;
29
71
  }
30
72
  /** A command the server wrote for a run (stop, cancel, steer, approve, deny, raise): one row, read by the run's runner in id order
31
73
  * and marked taken, or refused with why. `body` is JSON. */
@@ -65,6 +107,11 @@ export interface TemplatePackage {
65
107
  * parameters, one of which may be a credential: a later fresh apply of the same package whose parameters give the same
66
108
  * digest warns of this agent. Absent on a revision applied before it was kept. */
67
109
  readonly parameters_digest?: string;
110
+ /** The names of the keys the package declared (its `secrets`, and those of the model choice the apply took), sorted,
111
+ * never their values: what an export of the agent names, whatever version of the package the server holds later, and
112
+ * the tool keys a run of the revision may carry (run-keys.ts; under the run-keys setting one that does not is refused).
113
+ * Absent on a revision applied before it was kept. */
114
+ readonly secrets?: readonly string[];
68
115
  }
69
116
  export interface NewRevision {
70
117
  readonly id: string;
@@ -216,6 +263,10 @@ export interface RunRow {
216
263
  readonly signInHanded: readonly string[] | null;
217
264
  /** The caller's labels, given at its start (RunLabels): opaque to the server, kept as given, {} when none. */
218
265
  readonly labels: RunLabels;
266
+ /** The disk the run's launch named as its own (a customer's Archil disk: the launch body's `archil_disk` of kind "launch"),
267
+ * by its id, written once with the queued run; null for a run on the default disk (its launch named none, or its agent's
268
+ * own). A run on a named disk learns nothing, so learning reads only runs with none (learn/learning-of.ts). */
269
+ readonly disk: string | null;
219
270
  readonly startedAt: number;
220
271
  readonly endedAt: number | null;
221
272
  /** When the run was purged (Runs.purge): its row is then a tombstone, its cost and times kept, everything else of it
@@ -297,6 +348,12 @@ export type LaunchSealed = Uint8Array | ((current: Uint8Array | null) => Uint8Ar
297
348
  export interface LaunchSealedWrite {
298
349
  readonly launchSealed?: LaunchSealed;
299
350
  }
351
+ /** Internal authorization fence: lock this settings row and compare its named JSON fields before a guarded write.
352
+ * All guards are locked in key order before the agent row; a missing row or changed field refuses the whole write. */
353
+ export interface SettingsGuard {
354
+ readonly key: string;
355
+ readonly fields: Readonly<Record<string, unknown>>;
356
+ }
300
357
  /** A run imported from another harness's session: an ended run with where it came from, its launch (built from the
301
358
  * session), its cost and metrics, and its transcript as journal batches — the whole thing written in one transaction.
302
359
  * `transcript` is the session as pi-durable write batches (a root conversation and its entries), each batch a commit. */
@@ -318,14 +375,21 @@ export interface ImportRunInput {
318
375
  /** Internal authorization fences for an outbound historical import. These settings rows are locked and their
319
376
  * named fields checked in the same transaction as the terminal run and journal, so a completed revocation or
320
377
  * disconnect cannot be followed by another imported run. Ordinary local imports leave this absent. */
321
- readonly settingsGuards?: readonly {
322
- readonly key: string;
323
- readonly fields: Readonly<Record<string, unknown>>;
324
- }[];
378
+ readonly settingsGuards?: readonly SettingsGuard[];
325
379
  /** Remote history is admitted only while its agent remains active. Lock and check the agent in the import's
326
380
  * transaction, ordering the write against archive; ordinary local imports leave this guard absent. */
327
381
  readonly requireActiveAgent?: true;
328
382
  }
383
+ /** Private preparation fence for the MCP registry. Sealed bytes are compared in memory, never persisted in a revision
384
+ * or exposed to its readers. Exact bytes distinguish credential replacement within the same clock millisecond. */
385
+ export interface McpGuard {
386
+ readonly name: string;
387
+ readonly url: string;
388
+ readonly auth: string;
389
+ readonly credentialChangedAt: number | null;
390
+ readonly tools: unknown;
391
+ readonly sealed: Uint8Array | null;
392
+ }
329
393
  /** Rows written in the same commit as a run's update (runs.update, or a journal commit's staged patch): a channel post the
330
394
  * run's moment owes (the outbox), what a channel was told. A command consumed is Staged.take, refused when not untaken. */
331
395
  export type AlsoRow = {
@@ -579,7 +643,9 @@ export interface Firing {
579
643
  }
580
644
  export type FiringStatus = "due" | "started" | "sent" | "skipped" | "failed" | "missed" | "ignored";
581
645
  /** A trigger's firing as its row keeps it. `shown`: in the trigger's history (the newest HISTORY_KEPT); false, kept only
582
- * for its key's day. `retryAt`: a due firing's next try; `waitsOn`: the run whose turn end wakes a due firing. */
646
+ * for its key's day. `retryAt`: a due firing's next try; `waitsOn`: the run whose turn end wakes a due firing.
647
+ * `startBy`: a firing its launch hook's host took with no run (sent), the time until which the host may still start
648
+ * its run (triggers.ts handedStart); null on any other. */
583
649
  export interface FiringRow {
584
650
  readonly triggerId: string;
585
651
  readonly key: string;
@@ -596,6 +662,7 @@ export interface FiringRow {
596
662
  readonly count: number | null;
597
663
  readonly attempts: number;
598
664
  readonly retryAt: number | null;
665
+ readonly startBy: number | null;
599
666
  readonly payload: string | null;
600
667
  readonly attrs: unknown;
601
668
  readonly notified: boolean;
@@ -645,7 +712,8 @@ export type TriggerUpdateOptions = {
645
712
  readonly ifAgent?: string;
646
713
  };
647
714
  export type TriggerPatch = Partial<Pick<TriggerRow, "agentId" | "name" | "enabled" | "source" | "target" | "nextAt" | "catchupWindowS" | "failuresInARow" | "disabled" | "maxActiveRuns" | "templateId">>;
648
- /** A firing's new state. Out of due, a firing keeps no retry, wait, payload nor the reason its last try gave (unless given). */
715
+ /** A firing's new state. Out of due, a firing keeps no retry, wait, payload, attrs (unless `keepAttrs`) nor the reason its
716
+ * last try gave (unless given), and no time but a sent firing's `startBy`. */
649
717
  export interface FiringChange {
650
718
  readonly status?: FiringStatus;
651
719
  readonly runId?: string;
@@ -658,6 +726,13 @@ export interface FiringChange {
658
726
  readonly retryAt?: number | null;
659
727
  readonly waitsOn?: string | null;
660
728
  readonly notified?: boolean;
729
+ /** Settled, the firing keeps its attrs: one its launch hook's host took with no run yet, whose run, started late
730
+ * (triggers.ts handedStart), is tagged and titled from them as one started first is. */
731
+ readonly keepAttrs?: boolean;
732
+ /** Settled `sent`: the time until which its launch hook's host may still start its run (FiringRow.startBy). It is kept
733
+ * in the firing's retry_at column, which only a due firing holds otherwise, and is never read back as a retry. Any
734
+ * other status keeps none. */
735
+ readonly startBy?: number;
661
736
  }
662
737
  /** What a settle does to the firing's trigger besides: `reset` its failure streak (a run started, a message sent), or
663
738
  * count a `failure` toward it, turning it off at `pauseAt` in a row (auto-pause, the firing marked paused). */
@@ -757,11 +832,18 @@ export interface Agents {
757
832
  * none), only while that is still the agent's current revision, compared in the same transaction under the agent row's
758
833
  * lock: RevisionMoved, and nothing written, when another writer (this server's, or another server's on the same store)
759
834
  * moved it first. `description` (a string, or null for none), when given, is the agent's new description, written in the
760
- * same commit: a revision refused by `ifCurrent` leaves it as it was. Absent, the description stays. */
835
+ * same commit: a refused revision leaves it as it was. Absent, the description stays. `advance: false` appends a
836
+ * revision whose parent is current without moving current; the same guards and optional description still apply.
837
+ * `ifNoActiveRuns` refuses with ActiveRuns while any queued, running or parked run exists, checked under the agent
838
+ * lock. `settingsGuards` are locked first, then sorted `mcpGuards` registry rows, then the agent. Every guard must match before any revision or description is written. */
761
839
  addRevision(revision: NewRevision & {
762
840
  agentId: string;
763
841
  ifCurrent?: string | null;
764
842
  description?: string | null;
843
+ advance?: false;
844
+ ifNoActiveRuns?: true;
845
+ settingsGuards?: readonly SettingsGuard[];
846
+ mcpGuards?: readonly McpGuard[];
765
847
  }): Promise<void>;
766
848
  /** Makes `revisionId`, one of the agent's own, its current one. StoreConstraint when it is not a revision of `agentId`. */
767
849
  setCurrent(agentId: string, revisionId: string): Promise<void>;
@@ -781,8 +863,12 @@ export interface Agents {
781
863
  * apply kept naming it, its revisions' content (body, skills, package, note, pins) and its own name and description
782
864
  * blanked, and its purge time set last. Only once each of its runs is purged (Runs.purge) and no trigger is left:
783
865
  * refused while a run is not (StoreConstraint) or a trigger is (TriggersLeft), nothing written. Its row and its
784
- * revisions' ids stay, so its runs' tombstones and every total over them read as before. An agent with no row, or one
785
- * purged already, is no write. On SQLite, once it commits, a WAL checkpoint (Runs.purge). */
866
+ * revisions' ids stay, so its runs' tombstones and every total over them read as before. In the same write, each
867
+ * uploaded package (`upload:<name>`, imported_templates) a revision of it was applied from is removed when no revision
868
+ * of another agent not purged (an archived one too) was, each read and removed holding its id; a package imported from
869
+ * GitHub stays. The server stops serving what it removed (template-import.ts dropRemovedUploads). An agent with no
870
+ * row, or one purged already, is no write. On SQLite, the scrub's marker first and a WAL checkpoint once it commits
871
+ * (Runs.purge). */
786
872
  purge(agentId: string): Promise<void>;
787
873
  }
788
874
  export interface Templates {
@@ -830,11 +916,15 @@ export interface Triggers {
830
916
  /** The firing starts a run: the queued run, the `started` firing that names it (the due firing's row, or a new one) and
831
917
  * the trigger's last_run_id, with its failure streak reset, in one transaction; with `launch`, the run's launch row in
832
918
  * that same transaction (the store's one writeLaunch). A run of an archived agent is refused in it (AgentArchived),
833
- * nothing written: a firing claimed before the archive committed starts no run after it. */
919
+ * nothing written: a firing claimed before the archive committed starts no run after it. Settings guards are locked
920
+ * before the agent, then the trigger. The locked trigger must still belong to the prepared run's agent.
921
+ * `expectedCurrent` is checked under the agent lock (RevisionMoved on mismatch), independently of revisionId. */
834
922
  fire(firing: Firing, run: {
835
923
  id: string;
836
924
  agentId: string;
837
925
  revisionId: string;
926
+ expectedCurrent?: string | null;
927
+ settingsGuards?: readonly SettingsGuard[];
838
928
  }, options?: {
839
929
  launch?: RunLaunchInput;
840
930
  }): Promise<RunRow>;
@@ -892,12 +982,14 @@ export interface Triggers {
892
982
  activeRuns(triggerId: string): Promise<number>;
893
983
  /** The history kept to `history` shown firings: older ones a sender's key names (manual, pushed) are kept for their day
894
984
  * (shown 0), others removed; shown-0 rows past `dayMs` removed, then the oldest past `kept` of them. Never a due
895
- * firing, a failure not yet told, nor a started firing whose run has not ended. Answers how many went past `kept`. */
985
+ * firing, a failure not yet told, a started firing whose run has not ended, nor a sent one whose startBy is not before
986
+ * `now` (the triggers' clock, which stamped it). Answers how many went past `kept`. */
896
987
  prune(triggerId: string, options: {
897
988
  history: number;
898
989
  dayMs: number;
899
990
  keepByKey: (by: string) => boolean;
900
991
  kept?: number;
992
+ now: number;
901
993
  }): Promise<number>;
902
994
  }
903
995
  export interface Runs {
@@ -905,13 +997,20 @@ export interface Runs {
905
997
  * in the same transaction, so a retry under the same key finds this run (runOfOrigin); a key already used is refused
906
998
  * (StoreConstraint), and nothing is written. With `launch`, its launch row is written in the same transaction too (all
907
999
  * or nothing). A launch made from another run (its body's `replay.of`, `audit.of`) takes that run's row lock and
908
- * reads it in the same transaction: made from a purged run, it is refused (RunPurged), nothing written. */
1000
+ * reads it in the same transaction: made from a purged run, it is refused (RunPurged), nothing written.
1001
+ * `expectedCurrent` checks the agent's current revision under its lock (RevisionMoved on mismatch); this is separate
1002
+ * from the pinned revisionId. Settings guards are locked before the agent. Refusal writes no run, origin or launch.
1003
+ * `startedAt` (ms) is when the run began, for one reported after it began elsewhere (a backend SDK run's
1004
+ * `started_at`); absent, now. */
909
1005
  create(run: {
910
1006
  id: string;
911
1007
  agentId: string;
912
1008
  revisionId: string;
913
1009
  origin?: RunOrigin;
914
1010
  labels?: RunLabels;
1011
+ expectedCurrent?: string | null;
1012
+ settingsGuards?: readonly SettingsGuard[];
1013
+ startedAt?: number;
915
1014
  }, launch?: RunLaunchInput): Promise<RunRow>;
916
1015
  /** A run whose agent is given inline and mapped to a source system by `agent.ref` and `revision.version`. In one
917
1016
  * transaction: the agent (one per `ref`, written on its first run, its name and description brought up to the version
@@ -958,6 +1057,25 @@ export interface Runs {
958
1057
  cli: Readonly<Record<string, unknown>>;
959
1058
  completionUsage?: unknown;
960
1059
  } | undefined>;
1060
+ /** Source-project recovery fields in run/id order: committed terminal root entries, including an absent checkpoint
1061
+ * for a placed run. A terminal placed run's latest actual claim with no terminal root entry follows its real rows
1062
+ * with entryId:null and attemptEpoch, never an invented journal ID. Active/queued/parked and unclaimed runs gain no
1063
+ * synthetic row. A real row's optional attemptEpoch is its owning claim, derived from persisted journal boundaries,
1064
+ * never trusted from its receipt; absent attempt metadata cannot prove a placed receipt. A run may have reopened
1065
+ * since an earlier terminal receipt; its immutable candidate remains discoverable and cannot conceal a later claimed
1066
+ * attempt lacking its end. Purged content is excluded.
1067
+ * Projects only named checkpoint fields; no model output, replay, input or sealed launch content. Ordinary-store
1068
+ * scope: the PostgreSQL Unicode compatibility fallback cannot run inside an already failed snapshot transaction. */
1069
+ projectCheckpoints(filter: {
1070
+ agentId: string;
1071
+ runId?: string;
1072
+ }): Promise<{
1073
+ runId: string;
1074
+ revisionId: string;
1075
+ entryId: number | null;
1076
+ attemptEpoch?: number;
1077
+ checkpoint: unknown;
1078
+ }[]>;
961
1079
  /** The learning start (the launch body's `learning` member, as stored: undefined when the body names none) of every run of
962
1080
  * agent `agentId` (no built-in learning run's) that has a launch row, in one read: what an agent-wide read (its cost per
963
1081
  * run, its learning view) needs of its runs at once, never a read a run. Only that member is read: no run's input, no
@@ -966,8 +1084,13 @@ export interface Runs {
966
1084
  runId: string;
967
1085
  learning: unknown;
968
1086
  }[]>;
1087
+ /** The ids of agent `agentId`'s runs started after `at` whose learning seed was read at or before it (the launch body's
1088
+ * `learning.seededAt`): a reset's watermark (learn/compile.ts sinceReset). Reads that one number of the runs started
1089
+ * after `at` alone. */
1090
+ seededBefore(agentId: string, at: number): Promise<string[]>;
969
1091
  /** Newest first, at most `limit` (no limit: all). `archived` filters on the run's own archive time (true: archived,
970
1092
  * false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. `labels`: only runs holding every one of these labels, key and value.
1093
+ * `disk`: only the runs on that disk (RunRow.disk), null for the default disk's; not given, every disk's.
971
1094
  * A purged run (Runs.purge) only with `purged`: the readers of money and counts (usage, stats, analytics) and an
972
1095
  * import's read of the sessions it holds, never a reader of a run's content. */
973
1096
  list(filter: {
@@ -976,6 +1099,7 @@ export interface Runs {
976
1099
  state?: RunState;
977
1100
  archived?: boolean;
978
1101
  labels?: RunLabels;
1102
+ disk?: string | null;
979
1103
  limit?: number;
980
1104
  purged?: boolean;
981
1105
  }): Promise<RunRow[]>;
@@ -1044,32 +1168,31 @@ export interface Runs {
1044
1168
  }): Promise<string[]>;
1045
1169
  /** Archives the run (its own archive time), or unarchives it: idempotent. */
1046
1170
  archive(runId: string, archived: boolean): Promise<void>;
1047
- /** Every run of agent `agentId` with its state, oldest first, its built-in learning runs included (which list leaves
1048
- * out): what deleting the agent stops and removes, with the runner that holds each (null: none) and its purge time. */
1171
+ /** Every run of agent `agentId` with its state, oldest first, its built-in learning runs and purged runs included
1172
+ * (which list leaves out): what deleting the agent stops and removes, with the runner that holds each (null: none),
1173
+ * its purge time and its disk (RunRow.disk: where a learning folder of the agent may be, learn/learning-of.ts namedDisksOf). */
1049
1174
  every(agentId: string): Promise<{
1050
1175
  id: string;
1051
1176
  state: RunState;
1052
1177
  runner: string | null;
1053
1178
  purgedAt: number | null;
1179
+ disk: string | null;
1054
1180
  }[]>;
1055
1181
  /** The runs made from run `runId` that hold what it was given or did, by id: each run whose launch replays its input
1056
1182
  * (the launch body's `replay.of`) or audits it (`audit.of`: its audit's shadow run), and each learning run its kept
1057
1183
  * learning names (learning_proposals' learning_run_id). What purging the run purges with it. */
1058
1184
  madeFrom(runId: string): Promise<string[]>;
1059
- /** A run purged, in one transaction under its row's lock (DELETE /runs/{id}, agent-delete.ts): its journal, commands,
1060
- * origin, launch, live view and viewers, its channel posts with their tries and what each channel was told of it, a
1061
- * trigger's conversation that names it and its changes in the run-change feed gone; a trigger's last run, a firing's run
1062
- * or wait and a machine's token that name it let go (null); its kept learning's content blanked, each row kept with its
1063
- * proposal's state alone, as the learning meter and the list of learning runs read it; its row's content blanked
1064
- * (summary, labels, handed sign-ins, listing) with `kept` folded into its metrics (`purged`), and its purge time set
1065
- * last. Its id, agent, revision, state, outcome, times, cost and metrics stay: a tombstone, which every total sums as
1066
- * before. Only a run that is final and that no runner holds: one that is not is refused (StoreConstraint), nothing
1067
- * written; so is one a run made from it (madeFrom's replays and shadow) not purged names (RunsMadeFromLeft): each is
1068
- * purged first, and Runs.create, under the same row lock, makes none once it is purged. A run with no row, or one
1069
- * purged already, is no write. On SQLite, once it commits, a WAL checkpoint (TRUNCATE): with secure_delete on in every
1070
- * connection, neither the file nor its WAL keeps the purged bytes after it. A checkpoint another connection holds back
1071
- * is retried once, then told to the store's `warn`; it never fails the purge. Postgres: the old row versions are the
1072
- * database's until its VACUUM. */
1185
+ /** A run purged, in one transaction under its row's lock (DELETE /runs/{id}, agent-delete.ts): every row of its content
1186
+ * gone or blanked, what names it let go, and its kept learning's rows kept with their proposal's state alone. Its row
1187
+ * stays as a tombstone (id, agent, revision, state, outcome, times, cost, metrics with `kept` folded in), its purge
1188
+ * time set last, which every total sums as before. Refused (StoreConstraint), nothing written, while it is not final
1189
+ * or a runner holds it, and while a run made from it is not purged (RunsMadeFromLeft); Runs.create makes none under
1190
+ * the same lock once it is purged. A run with no row, or purged already, is no write. On SQLite the scrub's marker
1191
+ * comes first (one that can't be written, a full disk, throws with nothing purged), and a WAL checkpoint (TRUNCATE)
1192
+ * follows the commit, so with secure_delete neither the file nor its WAL keeps the bytes; a checkpoint another
1193
+ * connection holds back keeps the marker for the next start's scrub. Postgres keeps old row versions until its
1194
+ * VACUUM. The run's text in its agent's learning folder is the server's to take off (agent-delete.ts forgetCopies),
1195
+ * and the purge time set here is what the folder's history reads skip its merges by. */
1073
1196
  purge(runId: string, kept: PurgeKept): Promise<void>;
1074
1197
  /** The run's rows gone, in one transaction: its journal, commands, origin, launch, live view and viewers, its channel
1075
1198
  * posts with their tries and what each channel was told of it, its kept learning, its changes in the run-change feed,
@@ -1362,8 +1485,10 @@ export interface Settings {
1362
1485
  /** Saves `value` under `key` only while its row still holds `was` (as get read it), in one statement: a compare-and-set,
1363
1486
  * so of two writers that read one row only one replaces it. True when it was replaced; false, with nothing written,
1364
1487
  * when the row changed since or is gone. With `claim`, holds the run's shared row lock and checks its epoch/lease in
1365
- * the same transaction as the setting update; a stale claim throws Fenced without changing the setting. */
1366
- replaceIf(key: string, was: unknown, value: unknown, claim?: Claim): Promise<boolean>;
1488
+ * the same transaction as the setting update; a stale claim throws Fenced without changing the setting.
1489
+ * With source guards, lock their keys and this destination key in sorted order, compare the guards, then perform
1490
+ * the same CAS. A changed/missing guard refuses the transaction; a stale destination still answers false. */
1491
+ replaceIf(key: string, was: unknown, value: unknown, claim?: Claim, guards?: readonly SettingsGuard[]): Promise<boolean>;
1367
1492
  /** The key's row goes only while it still holds `was`, in one statement: true when it went. */
1368
1493
  removeIf(key: string, was: unknown): Promise<boolean>;
1369
1494
  /** The key's row goes; a key with no row is left as it is. */
@@ -1648,10 +1773,14 @@ export interface Runners {
1648
1773
  /** The runs waiting for a runner and held by one, and the hand-backs within the last `windowMs` (RunCapacity). */
1649
1774
  capacity(windowMs: number): Promise<RunCapacity>;
1650
1775
  }
1776
+ /** The id prefix of a package uploaded whole (POST /v2/templates/import {files}): `upload:<name>`. */
1777
+ export declare const UPLOAD_PREFIX = "upload:";
1651
1778
  /** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
1652
1779
  * (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
1653
- * its files as they were read, by path, base64. The server checks them again (templates.ts readPackage) as it loads them
1654
- * at its start, so a package this build no longer takes is never served. */
1780
+ * its files as they were read, by path, base64. An uploaded one's id and source are `upload:<name>`, its sha the
1781
+ * package's sha256, its publisher empty; it goes with the last agent applied from it (Agents.purge). The server checks
1782
+ * them again (templates.ts readPackage) as it loads them at its start, so a package this build no longer takes is never
1783
+ * served. */
1655
1784
  export interface ImportedTemplateRow {
1656
1785
  readonly id: string;
1657
1786
  readonly source: string;
@@ -1664,6 +1793,8 @@ export interface ImportedTemplateRow {
1664
1793
  export interface ImportedTemplates {
1665
1794
  /** Every imported package, by id. */
1666
1795
  list(): Promise<ImportedTemplateRow[]>;
1796
+ /** Every imported package's id, sorted, with none of its files read. */
1797
+ ids(): Promise<string[]>;
1667
1798
  /** Keeps the package under its id, in place of the one there (a re-import at a new SHA replaces it). */
1668
1799
  put(row: Omit<ImportedTemplateRow, "importedAt">): Promise<void>;
1669
1800
  /** Removes the package: false when none had that id. */
@@ -1899,6 +2030,8 @@ export interface Store {
1899
2030
  readonly computerLedger: ComputerLedger;
1900
2031
  /** Each computer a run made, from its create to its proven delete. */
1901
2032
  readonly computerIntervals: ComputerIntervals;
2033
+ /** Each claim of a run: the turn it works and its attempt at it, and why it let the run go unfinished. */
2034
+ readonly runAttempts: RunAttempts;
1902
2035
  /** The people's own machines paired with this server, and the codes that pair them (spec/computer/attach.md). */
1903
2036
  readonly pairedComputers: PairedComputers;
1904
2037
  /** The tokens minted for hosted machines that dial this server, each kept as its SHA-256. */
@@ -1950,6 +2083,7 @@ export interface Store {
1950
2083
  state?: ReleasedState;
1951
2084
  wakeAt?: number | null;
1952
2085
  backoffUntil?: number | null;
2086
+ cut?: "drain" | "retry";
1953
2087
  }): Promise<void>;
1954
2088
  /** The run's journal: pi-durable's Storage for this one run, every commit fenced by the claim (store/journal). Its commit
1955
2089
  * holds the store's one connection while it runs, so it awaits nothing but its own statements, under a deadline. */
@@ -2146,13 +2280,19 @@ export declare class RunPurged extends Error {
2146
2280
  readonly made: string;
2147
2281
  constructor(runId: string, made: string);
2148
2282
  }
2149
- /** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
2283
+ /** An agent's current revision is not the one a conditional revision or run admission expected: another write
2150
2284
  * moved it first. `current` is the agent's current revision now. Nothing was written. */
2151
2285
  export declare class RevisionMoved extends Error {
2152
2286
  readonly agentId: string;
2153
2287
  readonly current: string | null;
2154
2288
  constructor(agentId: string, current: string | null);
2155
2289
  }
2290
+ /** A conditional revision refused while the agent has queued, running or parked runs. Nothing was written. */
2291
+ export declare class ActiveRuns extends Error {
2292
+ readonly agentId: string;
2293
+ readonly runIds: readonly string[];
2294
+ constructor(agentId: string, runIds: readonly string[]);
2295
+ }
2156
2296
  /** Forgetting a sign-in a running run was handed: refused, nothing written. `runId` is the run that holds it. */
2157
2297
  export declare class SignInHandedTo extends Error {
2158
2298
  readonly runId: string;
@@ -119,6 +119,8 @@ export const MCP_REFRESH_LEASE_MS = MCP_REFRESH_CALL_MS + STORE_WRITE_DEADLINE_M
119
119
  /** How long a runner's row is kept once it stopped saying it is there (a runner that died without its close): its next
120
120
  * put removes every row older than this. */
121
121
  export const RUNNER_ROWS_KEPT_MS = 24 * 60 * 60_000;
122
+ /** The id prefix of a package uploaded whole (POST /v2/templates/import {files}): `upload:<name>`. */
123
+ export const UPLOAD_PREFIX = "upload:";
122
124
  /** A write under a claim whose epoch is no longer the run's: refused, and nothing written. */
123
125
  export class Fenced extends Error {
124
126
  runId;
@@ -311,7 +313,7 @@ export class RunPurged extends Error {
311
313
  this.name = "RunPurged";
312
314
  }
313
315
  }
314
- /** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
316
+ /** An agent's current revision is not the one a conditional revision or run admission expected: another write
315
317
  * moved it first. `current` is the agent's current revision now. Nothing was written. */
316
318
  export class RevisionMoved extends Error {
317
319
  agentId;
@@ -323,6 +325,17 @@ export class RevisionMoved extends Error {
323
325
  this.name = "RevisionMoved";
324
326
  }
325
327
  }
328
+ /** A conditional revision refused while the agent has queued, running or parked runs. Nothing was written. */
329
+ export class ActiveRuns extends Error {
330
+ agentId;
331
+ runIds;
332
+ constructor(agentId, runIds) {
333
+ super(`agent ${agentId} has active runs (${runIds.join(", ")})`);
334
+ this.agentId = agentId;
335
+ this.runIds = runIds;
336
+ this.name = "ActiveRuns";
337
+ }
338
+ }
326
339
  /** Forgetting a sign-in a running run was handed: refused, nothing written. `runId` is the run that holds it. */
327
340
  export class SignInHandedTo extends Error {
328
341
  runId;
@@ -6,7 +6,7 @@ import { type PastRun, workflowCostsOf } from "../runner/workflow-first.js";
6
6
  import { type Reflect } from "../reflect-range.js";
7
7
  import type { EntryLike, TimelineEvent } from "../timeline/index.js";
8
8
  import type { AnalyticsFilter } from "./analytics.js";
9
- import { type PromotionRecord } from "../learn/promote.js";
9
+ import { type PromotionRecord, type ResetRevision } from "../learn/promote.js";
10
10
  import type { LearningProposal, Store } from "../store/store.js";
11
11
  /** A run's learning end: the Learning fields its end sets. */
12
12
  export type RunLearningEnd = Learning;
@@ -120,8 +120,10 @@ export type CompileSpend = {
120
120
  * its own) and its check (the replay runs that ran it: metrics.path `replay` of its workflow at its digest); unknown
121
121
  * once a part's cost is (null, or only a bound). A compile whose drafts all failed drafted none: no revision carries it
122
122
  * (the bill's unattributed does). It is spread over its first K served runs (`workflow` or `handed_back` of its workflow
123
- * at its digest), K its check's compile_after; `state` from its newest record. */
124
- export declare function revisionLedgerOf(records: readonly PromotionRecord[], rows: readonly LedgerRow[], compiles?: readonly CompileSpend[]): ReturnType<typeof amortize>;
123
+ * at its digest), K its check's compile_after; `state` from its newest record. A revision an earlier reset of the agent's
124
+ * learning deleted (`reset`, learn/promote.ts keepResetLedger) is one too, first, stopped, at the K it was kept with,
125
+ * unless the records name it again. */
126
+ export declare function revisionLedgerOf(records: readonly PromotionRecord[], rows: readonly LedgerRow[], compiles?: readonly CompileSpend[], reset?: readonly ResetRevision[]): ReturnType<typeof amortize>;
125
127
  /** Run `runId`'s path and its costs as GET /runs/{id} shows them (A8): `path` its record's (metrics.path, RUN_PATHS:
126
128
  * `agent` for a run that does not learn; null while it has not ended, for a workflow revision's run, and for a run that
127
129
  * learns whose end named none); `usd` its own spend, the job's (runCostOf's `cost_usd`: its row's cost, `rowUsd` when
@@ -177,9 +179,11 @@ export declare function costRunOf(store: RunRecords, run: RunRecord, n: number |
177
179
  workflow: string | null;
178
180
  }): Promise<Omit<CostRun, "took_over">>;
179
181
  /** The runs the money rule reads for agent `agentId` (runner/workflow-first.ts costLineOf), one set for the run's launch
180
- * and the cost page: of its newest PAST_RUNS runs, each that ended (ended, stopped or failed), is neither imported nor
181
- * archived nor a workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id
182
- * (the cost page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
182
+ * and the cost page: of its newest PAST_RUNS runs on no named disk (learn/learning-of.ts: one on a named disk learns
183
+ * nothing), each that ended (ended, stopped or failed) since its learning's reset (learn/compile.ts sinceReset: a
184
+ * workflow before it is not the one it learned after, whatever its name), is neither imported nor archived nor a
185
+ * workflow revision's run, with its all-in cost (allInOf). `known`: all-in costs already read, by run id (the cost
186
+ * page's series), read again for no run; `records`, where any other's rows are read (the store's by default). */
183
187
  export declare function pastRunsOverStore(store: Store, agentId: string, known?: ReadonlyMap<string, number | null>, records?: RunRecords): Promise<PastRun[]>;
184
188
  /** The money rule's decision for agent `agentId` (runner/workflow-first.ts costStopOf) over the runs a run's launch reads
185
189
  * (pastRunsOverStore), as the launch reads them: runs that can't be read now stop nothing (workflowFirstOf serves). What
@@ -273,7 +277,7 @@ export declare function usedOnly(started: NonNullable<RunLaunch["learning"]>, te
273
277
  export declare function runLearningOverStore(store: Store, runId: string, shown: Shown, secrets: readonly string[], statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>): Promise<{
274
278
  run: string;
275
279
  state: "dropped" | "merged" | "seeded" | "reflecting";
276
- reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
280
+ reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
277
281
  detail: string | null;
278
282
  at: string;
279
283
  workflows: import("../learning.js").LearnedFile[];
@@ -316,7 +320,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
316
320
  };
317
321
  run: string;
318
322
  state: "dropped" | "merged" | "seeded" | "reflecting";
319
- reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
323
+ reason: "cancelled" | "reset" | "use" | "empty" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_failed" | "checker" | null;
320
324
  detail: string | null;
321
325
  at: string;
322
326
  workflows: import("../learning.js").LearnedFile[];