@parcha/agentrun-serve 0.1.0-beta.52 → 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 (261) hide show
  1. package/CHANGELOG.md +122 -1
  2. package/README.md +213 -24
  3. package/dist/agent-delete.d.ts +5 -6
  4. package/dist/agent-delete.js +30 -67
  5. package/dist/agent-package.d.ts +71 -0
  6. package/dist/agent-package.js +345 -0
  7. package/dist/agents-store.d.ts +26 -20
  8. package/dist/agents-store.js +41 -33
  9. package/dist/api-only.d.ts +26 -6
  10. package/dist/api-only.js +35 -13
  11. package/dist/claude-login.d.ts +1 -0
  12. package/dist/claude-login.js +1 -1
  13. package/dist/cli-learning/cli.d.ts +3 -0
  14. package/dist/cli-learning/cli.js +17 -3
  15. package/dist/cli-learning/connections.js +3 -2
  16. package/dist/cli-learning/schema.js +2 -1
  17. package/dist/cli.js +70 -7
  18. package/dist/composio-preset.d.ts +2 -1
  19. package/dist/composio-preset.js +4 -3
  20. package/dist/composio-triggers.d.ts +4 -0
  21. package/dist/composio-triggers.js +4 -1
  22. package/dist/computer-needs.d.ts +32 -0
  23. package/dist/computer-needs.js +80 -0
  24. package/dist/computer-setting.d.ts +1 -0
  25. package/dist/computer-setting.js +8 -1
  26. package/dist/console/assets/index-BFgyZzF_.js +734 -0
  27. package/dist/console/assets/index-DbilxljH.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/console-links.d.ts +1 -0
  30. package/dist/console-links.js +2 -0
  31. package/dist/env-switch.d.ts +14 -0
  32. package/dist/env-switch.js +23 -0
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +3 -0
  35. package/dist/eval-previous.js +4 -3
  36. package/dist/fal-price.js +10 -13
  37. package/dist/handed-secret.d.ts +4 -0
  38. package/dist/handed-secret.js +10 -0
  39. package/dist/harness-archive.d.ts +15 -5
  40. package/dist/harness-archive.js +71 -34
  41. package/dist/harness-check.d.ts +2 -1
  42. package/dist/harness-check.js +36 -95
  43. package/dist/harness-egress.d.ts +23 -0
  44. package/dist/harness-egress.js +69 -0
  45. package/dist/harness-recipe-entry.d.ts +71 -0
  46. package/dist/harness-recipe-entry.js +184 -0
  47. package/dist/harness-recipe.d.ts +73 -6
  48. package/dist/harness-recipe.js +185 -31
  49. package/dist/harness-sign-in.d.ts +29 -0
  50. package/dist/harness-sign-in.js +122 -0
  51. package/dist/harness-table.d.ts +21 -0
  52. package/dist/harness-table.js +58 -3
  53. package/dist/harness-zip.d.ts +6 -0
  54. package/dist/harness-zip.js +203 -0
  55. package/dist/ids.d.ts +11 -0
  56. package/dist/ids.js +36 -0
  57. package/dist/learn/commit.d.ts +14 -1
  58. package/dist/learn/commit.js +156 -1
  59. package/dist/learn/compile.js +22 -8
  60. package/dist/learn/folder.d.ts +5 -0
  61. package/dist/learn/folder.js +10 -1
  62. package/dist/learn/learning.sh +15 -3
  63. package/dist/learn/promote.d.ts +2 -2
  64. package/dist/learn/secrets.js +30 -7
  65. package/dist/learning-routes.d.ts +23 -11
  66. package/dist/learning-routes.js +110 -20
  67. package/dist/learning.d.ts +9 -6
  68. package/dist/learning.js +9 -4
  69. package/dist/mcp-gateway.js +15 -2
  70. package/dist/mcp-probe.d.ts +3 -0
  71. package/dist/mcp-probe.js +7 -2
  72. package/dist/mcp-resources.d.ts +44 -0
  73. package/dist/mcp-resources.js +100 -0
  74. package/dist/mcp-servers-store.d.ts +16 -12
  75. package/dist/model.d.ts +4 -4
  76. package/dist/model.js +6 -6
  77. package/dist/native/cli.js +9 -2
  78. package/dist/native/connection.d.ts +2 -2
  79. package/dist/native/connection.js +5 -2
  80. package/dist/native/discovery.d.ts +2 -0
  81. package/dist/native/discovery.js +10 -6
  82. package/dist/native/remote-worker-bridge.js +36 -4
  83. package/dist/native/remote.d.ts +18 -1
  84. package/dist/native/remote.js +126 -37
  85. package/dist/native/schema.d.ts +6 -0
  86. package/dist/native/schema.js +31 -6
  87. package/dist/native/source-account.d.ts +13 -0
  88. package/dist/native/source-account.js +114 -0
  89. package/dist/native/source-capture-hooks.d.ts +5 -0
  90. package/dist/native/source-capture-hooks.js +102 -0
  91. package/dist/native/source-mcp-selection.d.ts +13 -0
  92. package/dist/native/source-mcp-selection.js +72 -0
  93. package/dist/native/source-runtime-tools.d.ts +19 -0
  94. package/dist/native/source-runtime-tools.js +103 -0
  95. package/dist/native/source-snapshot-types.d.ts +138 -0
  96. package/dist/native/source-snapshot-types.js +12 -0
  97. package/dist/native/source-snapshot.d.ts +8 -0
  98. package/dist/native/source-snapshot.js +1201 -0
  99. package/dist/observation/learning.js +3 -2
  100. package/dist/openapi.js +167 -36
  101. package/dist/print.js +1 -1
  102. package/dist/purged-workflow.d.ts +12 -0
  103. package/dist/purged-workflow.js +43 -0
  104. package/dist/run-keys.d.ts +46 -0
  105. package/dist/run-keys.js +109 -0
  106. package/dist/run-launch.d.ts +16 -1
  107. package/dist/run-launch.js +30 -1
  108. package/dist/run-learning-served.d.ts +2 -2
  109. package/dist/run-model-key.d.ts +2 -2
  110. package/dist/run-model-key.js +5 -5
  111. package/dist/run-secrets.d.ts +2 -0
  112. package/dist/run-secrets.js +7 -4
  113. package/dist/run-view.d.ts +17 -0
  114. package/dist/run-view.js +25 -1
  115. package/dist/runner/adapter-loop.d.ts +11 -3
  116. package/dist/runner/adapter-loop.js +138 -22
  117. package/dist/runner/adapter-run-spec.js +25 -12
  118. package/dist/runner/audit.d.ts +2 -0
  119. package/dist/runner/audit.js +9 -1
  120. package/dist/runner/beside.js +2 -1
  121. package/dist/runner/claim-secrets.d.ts +29 -3
  122. package/dist/runner/claim-secrets.js +38 -4
  123. package/dist/runner/cli-run-spec.js +23 -12
  124. package/dist/runner/harness-loops.d.ts +6 -0
  125. package/dist/runner/harness-loops.js +11 -1
  126. package/dist/runner/held.d.ts +4 -0
  127. package/dist/runner/journal-kinds.d.ts +2 -0
  128. package/dist/runner/learned-first.d.ts +2 -0
  129. package/dist/runner/learned-first.js +1 -1
  130. package/dist/runner/learning-end.d.ts +7 -2
  131. package/dist/runner/learning-end.js +22 -10
  132. package/dist/runner/learning-seed.d.ts +9 -3
  133. package/dist/runner/learning-seed.js +2 -2
  134. package/dist/runner/main.d.ts +1 -0
  135. package/dist/runner/main.js +20 -13
  136. package/dist/runner/mcp-claim.js +6 -1
  137. package/dist/runner/mcp-run.d.ts +10 -7
  138. package/dist/runner/mcp-run.js +3 -5
  139. package/dist/runner/monid-run.js +9 -11
  140. package/dist/runner/project-checkpoint.d.ts +35 -0
  141. package/dist/runner/project-checkpoint.js +116 -0
  142. package/dist/runner/project-drain.d.ts +8 -0
  143. package/dist/runner/project-drain.js +25 -0
  144. package/dist/runner/project-host.d.ts +10 -0
  145. package/dist/runner/project-host.js +52 -0
  146. package/dist/runner/promotion.d.ts +14 -6
  147. package/dist/runner/promotion.js +98 -41
  148. package/dist/runner/redact.d.ts +13 -0
  149. package/dist/runner/redact.js +67 -1
  150. package/dist/runner/run-channel.d.ts +9 -0
  151. package/dist/runner/run-channel.js +15 -2
  152. package/dist/runner/run-child-host.d.ts +8 -4
  153. package/dist/runner/run-child-host.js +171 -41
  154. package/dist/runner/run-errors.js +2 -2
  155. package/dist/runner/runner-check.js +5 -2
  156. package/dist/runner/runner.js +26 -9
  157. package/dist/runner/store-secrets.js +7 -3
  158. package/dist/runner/workflow-first.d.ts +4 -0
  159. package/dist/runner/workflow-first.js +13 -0
  160. package/dist/runner/workflow-loop.d.ts +2 -1
  161. package/dist/runner/workflow-loop.js +2 -1
  162. package/dist/runner/workflow-spec.js +1 -1
  163. package/dist/runs-over-store.d.ts +34 -6
  164. package/dist/runs-over-store.js +133 -25
  165. package/dist/sdk/runs.d.ts +11 -1
  166. package/dist/sdk/runs.js +117 -26
  167. package/dist/sdk/schema.js +12 -2
  168. package/dist/sdk/workflows.d.ts +1 -1
  169. package/dist/server.d.ts +68 -32
  170. package/dist/server.js +600 -110
  171. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  172. package/dist/source-sync/adoption.d.ts +15 -0
  173. package/dist/source-sync/adoption.js +36 -0
  174. package/dist/source-sync/auxiliary.d.ts +23 -0
  175. package/dist/source-sync/auxiliary.js +64 -0
  176. package/dist/source-sync/capture-git.d.ts +5 -0
  177. package/dist/source-sync/capture-git.js +272 -0
  178. package/dist/source-sync/capture-project.d.ts +53 -0
  179. package/dist/source-sync/capture-project.js +206 -0
  180. package/dist/source-sync/capture-refusal.d.ts +7 -0
  181. package/dist/source-sync/capture-refusal.js +16 -0
  182. package/dist/source-sync/capture.d.ts +11 -0
  183. package/dist/source-sync/capture.js +22 -0
  184. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  185. package/dist/source-sync/checkpoint-gate.js +52 -0
  186. package/dist/source-sync/checkpoints.d.ts +66 -0
  187. package/dist/source-sync/checkpoints.js +168 -0
  188. package/dist/source-sync/claim.d.ts +11 -0
  189. package/dist/source-sync/claim.js +48 -0
  190. package/dist/source-sync/destination.d.ts +47 -0
  191. package/dist/source-sync/destination.js +239 -0
  192. package/dist/source-sync/io.d.ts +15 -0
  193. package/dist/source-sync/io.js +52 -0
  194. package/dist/source-sync/local.d.ts +43 -0
  195. package/dist/source-sync/local.js +229 -0
  196. package/dist/source-sync/prepare.d.ts +59 -0
  197. package/dist/source-sync/prepare.js +93 -0
  198. package/dist/source-sync/projects.d.ts +61 -0
  199. package/dist/source-sync/projects.js +130 -0
  200. package/dist/source-sync/registry.d.ts +95 -0
  201. package/dist/source-sync/registry.js +226 -0
  202. package/dist/source-sync/service.d.ts +33 -0
  203. package/dist/source-sync/service.js +118 -0
  204. package/dist/source-sync/skill-edits.d.ts +12 -0
  205. package/dist/source-sync/skill-edits.js +122 -0
  206. package/dist/source-sync/snapshots.d.ts +48 -0
  207. package/dist/source-sync/snapshots.js +448 -0
  208. package/dist/source-sync/types.d.ts +9 -0
  209. package/dist/source-sync/types.js +14 -0
  210. package/dist/source-sync/workspace.d.ts +66 -0
  211. package/dist/source-sync/workspace.js +273 -0
  212. package/dist/store/agent-body.d.ts +4 -0
  213. package/dist/store/agent-body.js +16 -5
  214. package/dist/store/index.d.ts +2 -2
  215. package/dist/store/index.js +1 -1
  216. package/dist/store/schema.d.ts +2 -1
  217. package/dist/store/schema.js +2 -1
  218. package/dist/store/seal.d.ts +5 -1
  219. package/dist/store/seal.js +12 -3
  220. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  221. package/dist/store/sqlite/project-checkpoints.js +70 -0
  222. package/dist/store/sqlite/run-launch.d.ts +4 -12
  223. package/dist/store/sqlite/run-launch.js +5 -19
  224. package/dist/store/sqlite/store.js +224 -170
  225. package/dist/store/store.d.ts +116 -39
  226. package/dist/store/store.js +14 -1
  227. package/dist/store-reads/learning.d.ts +2 -2
  228. package/dist/store-view.d.ts +3 -1
  229. package/dist/store-view.js +17 -5
  230. package/dist/template-import.d.ts +10 -2
  231. package/dist/template-import.js +116 -13
  232. package/dist/templates.d.ts +26 -5
  233. package/dist/templates.js +62 -10
  234. package/dist/timeline/index.d.ts +1 -1
  235. package/dist/timeline/index.js +1 -1
  236. package/dist/timeline/timeline.d.ts +5 -0
  237. package/dist/timeline/timeline.js +8 -0
  238. package/dist/tool-plane.d.ts +12 -12
  239. package/dist/tools.d.ts +8 -8
  240. package/dist/trigger-launch-hook.d.ts +47 -0
  241. package/dist/trigger-launch-hook.js +90 -0
  242. package/dist/trigger-targets.d.ts +14 -1
  243. package/dist/trigger-targets.js +20 -0
  244. package/dist/triggers.d.ts +54 -5
  245. package/dist/triggers.js +143 -8
  246. package/dist/uploads-archil.js +1 -1
  247. package/dist/uploads.js +1 -1
  248. package/dist/validate.js +1 -2
  249. package/dist/workspace/computer-for-claim.d.ts +2 -0
  250. package/dist/workspace/computer-for-claim.js +43 -0
  251. package/dist/workspace/paths.d.ts +6 -0
  252. package/dist/workspace/paths.js +6 -0
  253. package/dist/workspace/resolve-computer.d.ts +1 -0
  254. package/dist/workspace/run-tools.d.ts +2 -0
  255. package/dist/workspace/run-tools.js +8 -0
  256. package/launcher/agentrun-serve +1 -1
  257. package/package.json +10 -10
  258. package/skills/agentrun-serve/SKILL.md +2 -1
  259. package/templates/README.md +5 -2
  260. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  261. package/dist/console/assets/index-DlQepP2J.css +0 -1
@@ -59,7 +59,8 @@ export interface RunAttemptRow {
59
59
  readonly claimedAt: number;
60
60
  }
61
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. Data only: nothing reads it to decide what a run does. */
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. */
63
64
  export interface RunAttempts {
64
65
  /** The claim at `epoch` lost its lease while its runner was there (runner.ts loseClaim): its cut, and the cause of the
65
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
@@ -106,6 +107,11 @@ export interface TemplatePackage {
106
107
  * parameters, one of which may be a credential: a later fresh apply of the same package whose parameters give the same
107
108
  * digest warns of this agent. Absent on a revision applied before it was kept. */
108
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[];
109
115
  }
110
116
  export interface NewRevision {
111
117
  readonly id: string;
@@ -342,6 +348,12 @@ export type LaunchSealed = Uint8Array | ((current: Uint8Array | null) => Uint8Ar
342
348
  export interface LaunchSealedWrite {
343
349
  readonly launchSealed?: LaunchSealed;
344
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
+ }
345
357
  /** A run imported from another harness's session: an ended run with where it came from, its launch (built from the
346
358
  * session), its cost and metrics, and its transcript as journal batches — the whole thing written in one transaction.
347
359
  * `transcript` is the session as pi-durable write batches (a root conversation and its entries), each batch a commit. */
@@ -363,14 +375,21 @@ export interface ImportRunInput {
363
375
  /** Internal authorization fences for an outbound historical import. These settings rows are locked and their
364
376
  * named fields checked in the same transaction as the terminal run and journal, so a completed revocation or
365
377
  * disconnect cannot be followed by another imported run. Ordinary local imports leave this absent. */
366
- readonly settingsGuards?: readonly {
367
- readonly key: string;
368
- readonly fields: Readonly<Record<string, unknown>>;
369
- }[];
378
+ readonly settingsGuards?: readonly SettingsGuard[];
370
379
  /** Remote history is admitted only while its agent remains active. Lock and check the agent in the import's
371
380
  * transaction, ordering the write against archive; ordinary local imports leave this guard absent. */
372
381
  readonly requireActiveAgent?: true;
373
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
+ }
374
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
375
394
  * run's moment owes (the outbox), what a channel was told. A command consumed is Staged.take, refused when not untaken. */
376
395
  export type AlsoRow = {
@@ -624,7 +643,9 @@ export interface Firing {
624
643
  }
625
644
  export type FiringStatus = "due" | "started" | "sent" | "skipped" | "failed" | "missed" | "ignored";
626
645
  /** A trigger's firing as its row keeps it. `shown`: in the trigger's history (the newest HISTORY_KEPT); false, kept only
627
- * 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. */
628
649
  export interface FiringRow {
629
650
  readonly triggerId: string;
630
651
  readonly key: string;
@@ -641,6 +662,7 @@ export interface FiringRow {
641
662
  readonly count: number | null;
642
663
  readonly attempts: number;
643
664
  readonly retryAt: number | null;
665
+ readonly startBy: number | null;
644
666
  readonly payload: string | null;
645
667
  readonly attrs: unknown;
646
668
  readonly notified: boolean;
@@ -690,7 +712,8 @@ export type TriggerUpdateOptions = {
690
712
  readonly ifAgent?: string;
691
713
  };
692
714
  export type TriggerPatch = Partial<Pick<TriggerRow, "agentId" | "name" | "enabled" | "source" | "target" | "nextAt" | "catchupWindowS" | "failuresInARow" | "disabled" | "maxActiveRuns" | "templateId">>;
693
- /** 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`. */
694
717
  export interface FiringChange {
695
718
  readonly status?: FiringStatus;
696
719
  readonly runId?: string;
@@ -703,6 +726,13 @@ export interface FiringChange {
703
726
  readonly retryAt?: number | null;
704
727
  readonly waitsOn?: string | null;
705
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;
706
736
  }
707
737
  /** What a settle does to the firing's trigger besides: `reset` its failure streak (a run started, a message sent), or
708
738
  * count a `failure` toward it, turning it off at `pauseAt` in a row (auto-pause, the firing marked paused). */
@@ -802,11 +832,18 @@ export interface Agents {
802
832
  * none), only while that is still the agent's current revision, compared in the same transaction under the agent row's
803
833
  * lock: RevisionMoved, and nothing written, when another writer (this server's, or another server's on the same store)
804
834
  * moved it first. `description` (a string, or null for none), when given, is the agent's new description, written in the
805
- * 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. */
806
839
  addRevision(revision: NewRevision & {
807
840
  agentId: string;
808
841
  ifCurrent?: string | null;
809
842
  description?: string | null;
843
+ advance?: false;
844
+ ifNoActiveRuns?: true;
845
+ settingsGuards?: readonly SettingsGuard[];
846
+ mcpGuards?: readonly McpGuard[];
810
847
  }): Promise<void>;
811
848
  /** Makes `revisionId`, one of the agent's own, its current one. StoreConstraint when it is not a revision of `agentId`. */
812
849
  setCurrent(agentId: string, revisionId: string): Promise<void>;
@@ -826,8 +863,12 @@ export interface Agents {
826
863
  * apply kept naming it, its revisions' content (body, skills, package, note, pins) and its own name and description
827
864
  * blanked, and its purge time set last. Only once each of its runs is purged (Runs.purge) and no trigger is left:
828
865
  * refused while a run is not (StoreConstraint) or a trigger is (TriggersLeft), nothing written. Its row and its
829
- * revisions' ids stay, so its runs' tombstones and every total over them read as before. An agent with no row, or one
830
- * 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). */
831
872
  purge(agentId: string): Promise<void>;
832
873
  }
833
874
  export interface Templates {
@@ -875,11 +916,15 @@ export interface Triggers {
875
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
876
917
  * the trigger's last_run_id, with its failure streak reset, in one transaction; with `launch`, the run's launch row in
877
918
  * that same transaction (the store's one writeLaunch). A run of an archived agent is refused in it (AgentArchived),
878
- * 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. */
879
922
  fire(firing: Firing, run: {
880
923
  id: string;
881
924
  agentId: string;
882
925
  revisionId: string;
926
+ expectedCurrent?: string | null;
927
+ settingsGuards?: readonly SettingsGuard[];
883
928
  }, options?: {
884
929
  launch?: RunLaunchInput;
885
930
  }): Promise<RunRow>;
@@ -937,12 +982,14 @@ export interface Triggers {
937
982
  activeRuns(triggerId: string): Promise<number>;
938
983
  /** The history kept to `history` shown firings: older ones a sender's key names (manual, pushed) are kept for their day
939
984
  * (shown 0), others removed; shown-0 rows past `dayMs` removed, then the oldest past `kept` of them. Never a due
940
- * 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`. */
941
987
  prune(triggerId: string, options: {
942
988
  history: number;
943
989
  dayMs: number;
944
990
  keepByKey: (by: string) => boolean;
945
991
  kept?: number;
992
+ now: number;
946
993
  }): Promise<number>;
947
994
  }
948
995
  export interface Runs {
@@ -950,13 +997,20 @@ export interface Runs {
950
997
  * in the same transaction, so a retry under the same key finds this run (runOfOrigin); a key already used is refused
951
998
  * (StoreConstraint), and nothing is written. With `launch`, its launch row is written in the same transaction too (all
952
999
  * or nothing). A launch made from another run (its body's `replay.of`, `audit.of`) takes that run's row lock and
953
- * 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. */
954
1005
  create(run: {
955
1006
  id: string;
956
1007
  agentId: string;
957
1008
  revisionId: string;
958
1009
  origin?: RunOrigin;
959
1010
  labels?: RunLabels;
1011
+ expectedCurrent?: string | null;
1012
+ settingsGuards?: readonly SettingsGuard[];
1013
+ startedAt?: number;
960
1014
  }, launch?: RunLaunchInput): Promise<RunRow>;
961
1015
  /** A run whose agent is given inline and mapped to a source system by `agent.ref` and `revision.version`. In one
962
1016
  * transaction: the agent (one per `ref`, written on its first run, its name and description brought up to the version
@@ -1003,6 +1057,25 @@ export interface Runs {
1003
1057
  cli: Readonly<Record<string, unknown>>;
1004
1058
  completionUsage?: unknown;
1005
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
+ }[]>;
1006
1079
  /** The learning start (the launch body's `learning` member, as stored: undefined when the body names none) of every run of
1007
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
1008
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
@@ -1109,21 +1182,17 @@ export interface Runs {
1109
1182
  * (the launch body's `replay.of`) or audits it (`audit.of`: its audit's shadow run), and each learning run its kept
1110
1183
  * learning names (learning_proposals' learning_run_id). What purging the run purges with it. */
1111
1184
  madeFrom(runId: string): Promise<string[]>;
1112
- /** A run purged, in one transaction under its row's lock (DELETE /runs/{id}, agent-delete.ts): its journal, commands,
1113
- * origin, launch, live view and viewers, its channel posts with their tries and what each channel was told of it, a
1114
- * trigger's conversation that names it and its changes in the run-change feed gone; a trigger's last run, a firing's run
1115
- * or wait and a machine's token that name it let go (null); its kept learning's content blanked, each row kept with its
1116
- * proposal's state alone, as the learning meter and the list of learning runs read it; its row's content blanked
1117
- * (summary, labels, handed sign-ins, listing) with `kept` folded into its metrics (`purged`), and its purge time set
1118
- * last. Its id, agent, revision, state, outcome, times, cost and metrics stay: a tombstone, which every total sums as
1119
- * before. Only a run that is final and that no runner holds: one that is not is refused (StoreConstraint), nothing
1120
- * written; so is one a run made from it (madeFrom's replays and shadow) not purged names (RunsMadeFromLeft): each is
1121
- * purged first, and Runs.create, under the same row lock, makes none once it is purged. A run with no row, or one
1122
- * purged already, is no write. On SQLite, once it commits, a WAL checkpoint (TRUNCATE): with secure_delete on in every
1123
- * connection, neither the file nor its WAL keeps the purged bytes after it. A checkpoint another connection holds back
1124
- * leaves the scrub's marker, for the next start's scrub; a marker that cannot be written throws, the purge committed,
1125
- * and the retried DELETE arranges it again (Store.purgeScrub). Postgres: the old row versions are the database's until
1126
- * 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. */
1127
1196
  purge(runId: string, kept: PurgeKept): Promise<void>;
1128
1197
  /** The run's rows gone, in one transaction: its journal, commands, origin, launch, live view and viewers, its channel
1129
1198
  * posts with their tries and what each channel was told of it, its kept learning, its changes in the run-change feed,
@@ -1416,8 +1485,10 @@ export interface Settings {
1416
1485
  /** Saves `value` under `key` only while its row still holds `was` (as get read it), in one statement: a compare-and-set,
1417
1486
  * so of two writers that read one row only one replaces it. True when it was replaced; false, with nothing written,
1418
1487
  * when the row changed since or is gone. With `claim`, holds the run's shared row lock and checks its epoch/lease in
1419
- * the same transaction as the setting update; a stale claim throws Fenced without changing the setting. */
1420
- 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>;
1421
1492
  /** The key's row goes only while it still holds `was`, in one statement: true when it went. */
1422
1493
  removeIf(key: string, was: unknown): Promise<boolean>;
1423
1494
  /** The key's row goes; a key with no row is left as it is. */
@@ -1702,10 +1773,14 @@ export interface Runners {
1702
1773
  /** The runs waiting for a runner and held by one, and the hand-backs within the last `windowMs` (RunCapacity). */
1703
1774
  capacity(windowMs: number): Promise<RunCapacity>;
1704
1775
  }
1776
+ /** The id prefix of a package uploaded whole (POST /v2/templates/import {files}): `upload:<name>`. */
1777
+ export declare const UPLOAD_PREFIX = "upload:";
1705
1778
  /** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
1706
1779
  * (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
1707
- * its files as they were read, by path, base64. The server checks them again (templates.ts readPackage) as it loads them
1708
- * 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. */
1709
1784
  export interface ImportedTemplateRow {
1710
1785
  readonly id: string;
1711
1786
  readonly source: string;
@@ -1718,6 +1793,8 @@ export interface ImportedTemplateRow {
1718
1793
  export interface ImportedTemplates {
1719
1794
  /** Every imported package, by id. */
1720
1795
  list(): Promise<ImportedTemplateRow[]>;
1796
+ /** Every imported package's id, sorted, with none of its files read. */
1797
+ ids(): Promise<string[]>;
1721
1798
  /** Keeps the package under its id, in place of the one there (a re-import at a new SHA replaces it). */
1722
1799
  put(row: Omit<ImportedTemplateRow, "importedAt">): Promise<void>;
1723
1800
  /** Removes the package: false when none had that id. */
@@ -1982,12 +2059,6 @@ export interface Store {
1982
2059
  * done; `left` says why it was kept, for the next start to finish. Postgres: `work` alone (a replaced row version is
1983
2060
  * the database's until its vacuum). */
1984
2061
  secureRewrite?(work: () => Promise<number>, options?: SecureRewriteOptions): Promise<SecureRewrite>;
1985
- /** A DELETE of a run or agent already purged (agent-delete.ts): a purge can commit and then fail to write the scrub's
1986
- * marker (Runs.purge), and its retry finds the row purged. SQLite with a file, when no marker is there: the purge's
1987
- * WAL checkpoint again, and the marker when another connection still holds the log back; with the marker there, no
1988
- * write, but the marker is the purge's too, so a rewrite under way that wrote it removes it only after a checkpoint
1989
- * that truncates the log. Postgres and a store with no file: nothing. */
1990
- purgeScrub(): Promise<void>;
1991
2062
  /** Reads the store's schema version and its runner floor now, without a lock or a write: a runner reads it at each
1992
2063
  * renewal (runner/main.ts), and stops once the floor is above the version its build knows. */
1993
2064
  schemaState?(): Promise<StoreSchemaState>;
@@ -2209,13 +2280,19 @@ export declare class RunPurged extends Error {
2209
2280
  readonly made: string;
2210
2281
  constructor(runId: string, made: string);
2211
2282
  }
2212
- /** 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
2213
2284
  * moved it first. `current` is the agent's current revision now. Nothing was written. */
2214
2285
  export declare class RevisionMoved extends Error {
2215
2286
  readonly agentId: string;
2216
2287
  readonly current: string | null;
2217
2288
  constructor(agentId: string, current: string | null);
2218
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
+ }
2219
2296
  /** Forgetting a sign-in a running run was handed: refused, nothing written. `runId` is the run that holds it. */
2220
2297
  export declare class SignInHandedTo extends Error {
2221
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;
@@ -277,7 +277,7 @@ export declare function usedOnly(started: NonNullable<RunLaunch["learning"]>, te
277
277
  export declare function runLearningOverStore(store: Store, runId: string, shown: Shown, secrets: readonly string[], statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>): Promise<{
278
278
  run: string;
279
279
  state: "dropped" | "merged" | "seeded" | "reflecting";
280
- reason: "cancelled" | "reset" | "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;
281
281
  detail: string | null;
282
282
  at: string;
283
283
  workflows: import("../learning.js").LearnedFile[];
@@ -320,7 +320,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
320
320
  };
321
321
  run: string;
322
322
  state: "dropped" | "merged" | "seeded" | "reflecting";
323
- reason: "cancelled" | "reset" | "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;
324
324
  detail: string | null;
325
325
  at: string;
326
326
  workflows: import("../learning.js").LearnedFile[];
@@ -1,7 +1,7 @@
1
1
  import { type TimelineEvent } from "./timeline/index.js";
2
2
  import { type ItemStatus, type Learning } from "./learning.js";
3
3
  import { type RunLaunch } from "./run-launch.js";
4
- import { type Pending, type RunMoment, type RunView, type SignInReader, type Status, type ComputerAsk } from "./run-view.js";
4
+ import { type Pending, type RunMoment, type RunView, type SignInReader, type Status, type ComputerAsk, windDownOf } from "./run-view.js";
5
5
  import { type BookedSpend, type RunCost } from "./runner/metrics.js";
6
6
  import { type EndData } from "./runner/journal-kinds.js";
7
7
  import { type RunReadState, readRun } from "./store-reads/runs.js";
@@ -77,6 +77,8 @@ interface StoreRun {
77
77
  /** The budget card the run shows while it stands parked at its cap (pending, kind budget), or undefined when it is not
78
78
  * parked there. Also the source of the `budgetWaiting` fact. */
79
79
  readonly budget: Pending | undefined;
80
+ /** How the run wound down for its cap (run-view.ts windDownOf): its `stopped_for` and `budget_refused_calls`. */
81
+ readonly windDown: ReturnType<typeof windDownOf>;
80
82
  /** Whether a workflow run stands paused in its process now (pausedOf): the source of the `paused` fact. */
81
83
  readonly paused: boolean;
82
84
  /** The browser hand-over the run's agent waits on (the newest ask still waiting), or undefined. Also the `browserAsk`
@@ -18,7 +18,7 @@ import { COMPUTER_UNAVAILABLE_CODE, lostEndMessage } from "./computer-lost.js";
18
18
  import { refusedEndMessage, RUNNER_REFUSED_CODE } from "./runner/presence.js";
19
19
  import { launchOf } from "./handed-values.js";
20
20
  import { learningStartOf, seedFailed } from "./run-launch.js";
21
- import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, stopAsked, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
21
+ import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, stopAsked, usersOf, withAsks, withApprovalRows, windDownOf, } from "./run-view.js";
22
22
  import { reflects } from "./reflect-range.js";
23
23
  import { freeCeilingMessage, overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
24
24
  import { booksDecisions, decisionsOverStore, parallelChargedDecisions } from "./store-reads/decisions.js";
@@ -344,6 +344,10 @@ async function storeRunIn(store, runId, deps, cut, since) {
344
344
  // The budget card the run shows while it stands parked at its cap, from its journal's agentrun.budget park (none once a
345
345
  // raise clears it). Read over the same meta cap and rows the card's figures and time come from.
346
346
  const budget = budgetOf(records.entries, { meta, rows, updatedAt: iso(updatedAtMs) });
347
+ // How it wound down for its cap (run-view.ts windDownOf), under the cap it has now; its end-of-run turns' entries are
348
+ // learning's, never the job's.
349
+ const reflectTurns = reflectRanges(records.submissions ?? [], records.entries);
350
+ const windDown = windDownOf(records.entries, capUsd, (id) => inReflect(reflectTurns, id));
347
351
  const pause = activePauseOf(records.entries);
348
352
  // Whether a workflow run stands paused in its process now (its parked row with the pause's words, its newest pause not
349
353
  // resumed), the `paused` fact the status table reads for a paused workflow.
@@ -418,7 +422,7 @@ async function storeRunIn(store, runId, deps, cut, since) {
418
422
  const endSaidCost = endCost && !lookingBack ? endSaid !== undefined : false;
419
423
  const endUnread = !lookingBack && bookedCost !== undefined && !endCost && endSaid === null;
420
424
  const heal = lookingBack ? undefined : healOf(endCost, runRow);
421
- return { ...(cli_learning ? { cli_learning } : {}), ...(sdk ? { sdk } : {}), ...(native ? { native } : {}), row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions, plan, model, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}) };
425
+ return { ...(cli_learning ? { cli_learning } : {}), ...(sdk ? { sdk } : {}), ...(native ? { native } : {}), row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions, plan, model, windDown, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}) };
422
426
  }
423
427
  /** Run read `read` (a run still going, as the store holds it) as the end `ended` keeps (its state, summary and end time:
424
428
  * the end a run looking back keeps), its cost as read. */
@@ -675,6 +679,11 @@ async function viewOfRun(store, runId, deps, run, read) {
675
679
  pending,
676
680
  // Its own spend: an audit's shadow run of it is learning (GET /runs/{id}'s cost.learning_usd), never its cost.usd.
677
681
  cost: costOfView(run),
682
+ // Why a completed run stopped: `budget` when it wound down to stay under its cap (its model told to wrap up, or its
683
+ // tool calls refused, under the cap it has now: windDownOf), else null; and how many tool calls the cap's wrap-up
684
+ // refused (stoppedfor/1). A run paused at its cap (pending budget) or failed for it (spend_cap_reached) says so there.
685
+ stopped_for: status === "completed" && run.windDown.woundDown ? "budget" : null,
686
+ budget_refused_calls: run.windDown.refusedCalls,
678
687
  // The run an audit's shadow run audits (launch.audit, runner/audit.ts); null for any other run.
679
688
  audit_of: launch?.audit?.of ?? null,
680
689
  // The path it took and the learned workflow that served it, as its record keeps them: the read the cost per run makes
@@ -705,14 +714,14 @@ export async function summaryOverStore(store, runId, deps) {
705
714
  }
706
715
  /** What a list shows of a run's view (summaryOverStore). */
707
716
  export function summaryOfView(view) {
708
- const { run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title, effort, created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger, labels, learning } = view;
717
+ const { run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title, effort, created_at, ended_at, error, review, pending, cost, stopped_for, budget_refused_calls, archived_at, imported_from, trigger, labels, learning } = view;
709
718
  return {
710
719
  run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title,
711
720
  ...(view.cli_learning ? { cli_learning: view.cli_learning } : {}),
712
721
  ...(view.sdk ? { sdk: view.sdk } : {}),
713
722
  ...(view.native ? { native: view.native } : {}),
714
723
  ...(effort ? { effort } : {}),
715
- created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger, labels,
724
+ created_at, ended_at, error, review, pending, cost, stopped_for, budget_refused_calls, archived_at, imported_from, trigger, labels,
716
725
  learning: learning ? shortOf(learning) : null,
717
726
  // Read off the run's record, so a list carries it with no read of the run's journal.
718
727
  path: view.path, workflow: view.workflow,
@@ -751,8 +760,11 @@ export async function listingOverStore(store, runId, deps) {
751
760
  * (server.ts runsPage): the run's view cuts a value whole where it holds a secret (a note's name reads [redacted]), which
752
761
  * cutting the built item again could not do. */
753
762
  export function builtOfNow(listing, serverSecrets) {
754
- return listing.cut === secretsDigest(serverSecrets);
763
+ return listing.cut === secretsDigest(serverSecrets) && LISTING_SINCE.every((field) => field in listing.item);
755
764
  }
765
+ /** List item fields an earlier server's listing was built without: a listing that lacks one is built again, once, so
766
+ * every list item carries them (stoppedfor/1). */
767
+ const LISTING_SINCE = ["stopped_for", "budget_refused_calls"];
756
768
  /** A listing's list item as a list serves it (listingOverStore): its console link at `origin`, its archive time now
757
769
  * (`archivedAt`, ms, the run's or its agent's), and, when the server's secrets moved between its build and this (within
758
770
  * one list), every string in it cut again of them (redactedOutput), so a secret saved since never shows. */
@@ -1,13 +1,17 @@
1
- import type { Store } from "./store/index.js";
1
+ import { type Store, UPLOAD_PREFIX } from "./store/index.js";
2
2
  import { type GithubReach } from "./template-source.js";
3
3
  import { type Package, type TemplateRegistry } from "./templates.js";
4
4
  /** The settings key that holds the GitHub accounts this server's owner trusts as publishers, lower-cased. */
5
5
  export declare const TRUSTED_PUBLISHERS = "templates.trusted_publishers";
6
+ /** An uploaded package's id is this and its manifest's name: the next upload of that name replaces it. */
7
+ export { UPLOAD_PREFIX };
6
8
  export type TemplateImportDeps = {
7
9
  registry: TemplateRegistry;
8
10
  store: Pick<Store, "importedTemplates" | "settings">;
9
11
  /** Where GitHub is read (template-source.ts GithubReach): GitHub's hosts and this server's App token when it has one. */
10
12
  reach: (signal: AbortSignal) => Promise<GithubReach>;
13
+ /** The API-only profile: an upload is taken, a GitHub source refused (its backend sends the package). */
14
+ apiOnly?: boolean;
11
15
  };
12
16
  /** An imported package read from its files, checked whole, with its id and origin: PackageError when it does not check. */
13
17
  export declare function importedPackage(id: string, origin: {
@@ -18,8 +22,12 @@ export declare function importedPackage(id: string, origin: {
18
22
  /** The packages the store keeps, put in the registry beside the bundled ones; one this build no longer takes is left out,
19
23
  * said through `skipped`, never a stop of the start. */
20
24
  export declare function loadImported(deps: Pick<TemplateImportDeps, "registry" | "store">, skipped: (id: string, why: string) => void): Promise<void>;
25
+ /** The uploads served here whose row the store no longer keeps (an agent's purge removed it: Agents.purge), no longer
26
+ * served. Only the package read before the store is removed, so an upload put in meanwhile stays served. */
27
+ export declare function dropRemovedUploads(deps: Pick<TemplateImportDeps, "registry" | "store">): Promise<void>;
21
28
  /** POST /v2/templates/import: the package read at its source's commit and checked; a dry run answers it, storing nothing;
22
- * else it is stored and served (201), in place of the one under its id. `signal` ends the read (the request's). */
29
+ * else it is stored and served (201), in place of the one under its id. `signal` ends the read (the request's). An
30
+ * upload ({files}) is uploadTemplate's. */
23
31
  export declare function importTemplate(deps: TemplateImportDeps, raw: unknown, signal: AbortSignal): Promise<{
24
32
  status: 200 | 201;
25
33
  pkg: Package;