@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
@@ -160,7 +160,7 @@ export function workflowSpecOf(deps) {
160
160
  // models, its decisions, its call nodes' effects and its model nodes' tools all run on these, never on another run's
161
161
  // keys or on this process's whole environment.
162
162
  // Held by the runner's one redactor before anything can echo one (holding: run.redact), as the decision keys were.
163
- const claimedEnv = await holding(claimSecrets({ store: deps.store, sealKey: deps.sealKey, ...(deps.env ? { env: deps.env } : {}) }, claimed.revision, { plane: claimed.plane }));
163
+ const claimedEnv = await holding(claimSecrets({ store: deps.store, sealKey: deps.sealKey, ...(deps.env ? { env: deps.env } : {}), redact: run?.redact }, claimed.revision, { plane: claimed.plane }, claim.runId));
164
164
  // The run's models resolve the one way the runner resolves any (routeProviderOf over routeOf), unless a test gives its
165
165
  // own: each tier's key from the runner's environment, else the one the claim opened (a key saved in
166
166
  // Settings → Model keys runs the next run with no restart).
@@ -1,3 +1,4 @@
1
+ import type { SourceIOReceipt } from "./source-sync/io.js";
1
2
  import type { Revision } from "./agent-rows.js";
2
3
  import type { MessageOrigin } from "./timeline/index.js";
3
4
  import { type AgentEntry, type ExternalRef } from "./agents-store.js";
@@ -88,8 +89,6 @@ export declare function raiseCap(store: RunsStore, moment: RunMoment, cap: numbe
88
89
  * each write or lose to the store's one-answer index, and the one that loses reads the one that won. The note is the
89
90
  * person's words, carried on the command for the run's gate. */
90
91
  export declare function approve(store: RunsStore, moment: RunMoment, id: string, decision: "allow" | "deny", note?: string, confirmed?: boolean): Promise<void>;
91
- /** A UUIDv7 run id: time-ordered, so a listing by start time is stable, and unique per run. */
92
- export declare function uuidv7(now?: number): string;
93
92
  /** The revision's body fields a start reads: its default cap, its place, and (agentic) its tools, for the place
94
93
  * fallback. Read with the shapes the old start read them with. */
95
94
  type StartBody = {
@@ -124,9 +123,11 @@ export interface StartDeps {
124
123
  explainRun(issues: InputIssue[], body: Json, revision: Revision | null | undefined): Promise<InputIssue[]>;
125
124
  /** Marks an input refusal as told from a revision (server.ts told). */
126
125
  told(error: ApiError): ApiError;
127
- /** Refuses a revision this host cannot run, by field (server.ts runnable). */
126
+ /** Refuses a revision this host cannot run, by field (server.ts runnable), each tool key the run carries (`carried`, by
127
+ * name) read as one the host holds. */
128
128
  runnable(revision: Revision, place: Place, options: {
129
129
  capped: boolean;
130
+ carried?: readonly string[];
130
131
  }): Promise<void>;
131
132
  /** The revision a run starts on, its MCP tools pinned: one that grants an MCP tool and was saved with no pin (before
132
133
  * pins were made at save, or an inline agent's version stored then) is pinned once, at its first run (server.ts
@@ -148,6 +149,26 @@ export interface StartDeps {
148
149
  undo(): Promise<void>;
149
150
  } | undefined>;
150
151
  };
152
+ /** Complete a moved project's placement before admission. Upload placement has already pinned its destination disk.
153
+ * `undo` may remove only this exclusively prepared run and must await outstanding writes. The caller invokes it only
154
+ * after a definite admission refusal; unknown admission keeps the preparation for explicit reconciliation. */
155
+ readonly project?: {
156
+ hold?(input: {
157
+ runId: string;
158
+ agentId: string;
159
+ }): Promise<SourceIOReceipt>;
160
+ place(input: {
161
+ hold?: SourceIOReceipt;
162
+ runId: string;
163
+ agentId: string;
164
+ revision: Pick<NewRevision, "id" | "kind" | "body">;
165
+ launch: RunLaunch;
166
+ }): Promise<{
167
+ readonly launch: RunLaunch;
168
+ undo(): Promise<void>;
169
+ admitted?(): Promise<void>;
170
+ } | undefined>;
171
+ };
151
172
  /** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
152
173
  fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
153
174
  /** The Archil disk the run's launch record keeps (server.ts launchDiskOf): the one its body's `archil_disk` names, else
@@ -206,6 +227,8 @@ export interface StartOptions {
206
227
  readonly origin?: RunOrigin;
207
228
  readonly capped?: boolean;
208
229
  readonly from?: MessageOrigin;
230
+ /** The names of the tool keys the run carries (`keys`, run-keys.ts; their values go only into `sealed`). */
231
+ readonly keys?: readonly string[];
209
232
  }
210
233
  /** The run's learning start: undefined when the run does not learn (the server's learning off, a workflow revision, or
211
234
  * its revision does not say learning), else the seed sha it starts from, its # Learned text (its owner's corrections,
@@ -227,7 +250,12 @@ export declare function learningStartFor(deps: StartDeps, entry: AgentEntry, rev
227
250
  * (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
228
251
  * runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
229
252
  * starts a second. */
230
- export declare function startRun(store: Pick<Store, "runs" | "runOfOrigin">, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed }?: StartOptions): Promise<RunRow>;
253
+ export declare function startRun(store: Store, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed, keys }?: StartOptions): Promise<RunRow>;
254
+ /** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
255
+ * hold that fails part way, a write that fails, or one that answers another run (an origin key's run started before),
256
+ * lets go of the hold. In Mode 2 they are placed in the run's folder instead (StartDeps.files.place), and the run is
257
+ * written with the launch that says so; the same failures undo the placing. */
258
+ export declare function withHeldFiles(store: Pick<Store, "runs">, deps: Pick<StartDeps, "files" | "project">, runId: string, agentId: string, revision: Pick<NewRevision, "id" | "kind" | "body">, launch: RunLaunch, write: (launch: RunLaunch) => Promise<RunRow>): Promise<RunRow>;
231
259
  /** An agent given inline (POST /runs): its reference in its source with the version, its name and description, and the
232
260
  * revision its checked definition makes (agents-store makeRevision), not yet stored. */
233
261
  export interface InlineAgent {
@@ -249,14 +277,14 @@ export interface InlineAgent {
249
277
  * agent already mapped to the reference is the run's (its id, its learning), so a run of a later version learns from the
250
278
  * earlier ones. A different definition under a version already run is 409 external_body_conflict, nothing written; under
251
279
  * `origin`, a key that already started a run gets that run, as startRun's. */
252
- export declare function startInline(store: Pick<Store, "runs" | "runOfOrigin" | "agents">, deps: StartDeps, inline: InlineAgent, body: Json, options?: Pick<StartOptions, "origin" | "sealed">): Promise<RunRow>;
280
+ export declare function startInline(store: Pick<Store, "runs" | "runOfOrigin" | "agents">, deps: StartDeps, inline: InlineAgent, body: Json, options?: Pick<StartOptions, "origin" | "sealed" | "keys">): Promise<RunRow>;
253
281
  /** A run's launch from its create body, with every check the old start made before a run started, in the same order and
254
282
  * words: the body's fields, the revision it pins, the input against its schema, the cap rules, the plane this host
255
283
  * resolves, whether the revision can run here; then its title, plane, model and learning start. Nothing is written: the
256
284
  * caller INSERTs the run with it (startRun; an inline agent's run, which writes its agent and revision in the same
257
285
  * transaction). `revision`: the revision the run starts on, given (an inline agent's, not yet stored), in place of the
258
286
  * one the body pins or the agent's current (deps.pinnedOf). */
259
- export declare function prepareLaunch(deps: StartDeps, entry: AgentEntry, body: Json, { trigger, capped, from, title: given, revision: onRevision }?: Omit<StartOptions, "origin"> & {
287
+ export declare function prepareLaunch(deps: StartDeps, entry: AgentEntry, body: Json, { trigger, capped, from, title: given, revision: onRevision, keys }?: Omit<StartOptions, "origin"> & {
260
288
  readonly revision?: Revision;
261
289
  }): Promise<{
262
290
  launch: RunLaunch;
@@ -1,3 +1,5 @@
1
+ import { reconcileProjectCheckpoints } from "./source-sync/checkpoints.js";
2
+ import { requireSavedProject } from "./source-sync/checkpoint-gate.js";
1
3
  import { NATIVE_RUN_OVERRIDES_UNSUPPORTED, nativeOf, nativeRunOverrides } from "./native/binding.js";
2
4
  import { launchNative } from "./native/connection.js";
3
5
  // The write half of the run's server cut (design 2.1, "the runner takes every run"): the functions the v2 routes call to
@@ -12,29 +14,32 @@ import { launchNative } from "./native/connection.js";
12
14
  // is the run view's to read from the journal (the server's view layer, run-view.ts). These writers take it as `RunMoment`
13
15
  // and never recompute it; the coarse facts a row already holds (its state, its launch cap) they read from the store.
14
16
  import { randomBytes } from "node:crypto";
15
- import { externalKey, getAgent } from "./agents-store.js";
17
+ import { externalKey, getAgent, ownedElsewhere } from "./agents-store.js";
16
18
  import { CAP_TOLERANCE, money } from "./cap.js";
17
19
  import { holdOf } from "./computer-held.js";
18
20
  import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
19
21
  import { ApiError, invalid, unsupported } from "./errors.js";
20
22
  import { labelsOf } from "./run-labels.js";
21
23
  import { harnessOfBody } from "./harness.js";
24
+ import { uuidv7 } from "./ids.js";
22
25
  import { redacted, redactedOutput } from "./key-refusal.js";
23
26
  import { chooseWorkflows, learnedSection, learnsOf, RUN_LEARNING_USE } from "./learning.js";
24
27
  import { thinkingLevel } from "./model.js";
25
28
  import { resolvePlace } from "./place.js";
26
29
  import { githubTargetOf } from "./github.js";
27
30
  import { repoOf } from "./run-repo.js";
28
- import { launchBody } from "./run-launch.js";
31
+ import { launchBody, sourceProjectOf } from "./run-launch.js";
29
32
  import { learningDiskOf } from "./learn/learning-of.js";
30
33
  import { modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
31
34
  import { raiseFollowUpId } from "./run-view.js";
32
35
  import { sendCommand } from "./runner/commands.js";
33
36
  import { refuseWhileNoRunner } from "./runner/presence.js";
34
- import { AgentDeleting, AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
37
+ import { RevisionMoved, AgentDeleting, AgentPurged, AgentArchived, AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
35
38
  import { canonical } from "./store/agent-body.js";
39
+ import { sourceSyncOf } from "./source-sync/types.js";
36
40
  import { toolingOf } from "./tools.js";
37
41
  import { planeFor } from "./tool-plane.js";
42
+ import { declaredKeys, undeclaredKeys, withCarried } from "./run-keys.js";
38
43
  import { clip } from "./web-fetch-direct.js";
39
44
  import { isObject } from "./validate.js";
40
45
  /** Why a message that may not answer a person's question is not sent (runs.ts WAITS_ON_A_PERSON). */
@@ -175,7 +180,8 @@ export async function message(store, moment, content, { requestId, answers = tru
175
180
  throw new ApiError("input_invalid", "Native jobs do not support in-session steering or follow-up messages. Start a new native run.");
176
181
  // Archiving closes a run: it, or a run of its archived agent, takes no message, said as archived (never as finished). Another
177
182
  // system's agent is archived only by its delete: said so, as every run of it is refused (AgentDeleting).
178
- if (moment.archived === "agent" && (await store.agents.get(moment.agentId))?.externalRef != null)
183
+ const archivedAgent = moment.archived === "agent" ? await store.agents.get(moment.agentId) : null;
184
+ if (archivedAgent && ownedElsewhere(archivedAgent))
179
185
  throw new AgentDeleting(moment.agentId);
180
186
  if (moment.archived !== undefined)
181
187
  throw archivedRefusal(moment);
@@ -397,16 +403,6 @@ export async function approve(store, moment, id, decision, note, confirmed = fal
397
403
  throw alreadyAnswered(id, end.decision);
398
404
  }
399
405
  }
400
- // ---- start -----------------------------------------------------------------------------------------------------------
401
- /** A UUIDv7 run id: time-ordered, so a listing by start time is stable, and unique per run. */
402
- export function uuidv7(now = Date.now()) {
403
- const bytes = randomBytes(16);
404
- bytes.writeUIntBE(now, 0, 6);
405
- bytes[6] = (bytes[6] & 0x0f) | 0x70;
406
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
407
- const hex = bytes.toString("hex");
408
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
409
- }
410
406
  /** A no-op redactor, when the server gives none: no secret is cut (the switch wires the real shown for a learning run). */
411
407
  const noShown = { text: (text) => text, name: (name) => name, holds: () => false };
412
408
  /** The run's learning start: undefined when the run does not learn (the server's learning off, a workflow revision, or
@@ -448,19 +444,37 @@ export async function learningStartFor(deps, entry, revision, rbody, { use = fal
448
444
  * (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
449
445
  * runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
450
446
  * starts a second. */
451
- export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed } = {}) {
447
+ export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed, keys } = {}) {
448
+ if (sourceSyncOf(entry.revision?.body)) {
449
+ // Re-delivery of a firing that already admitted a run is not a new start and needs no new project preparation.
450
+ if (origin) {
451
+ const found = await store.runOfOrigin(origin.key);
452
+ const existing = found && found.fingerprint === (origin.fingerprint ?? null) ? await store.runs.get(found.runId) : undefined;
453
+ if (existing?.agentId === entry.agent.id)
454
+ return existing;
455
+ }
456
+ await reconcileProjectCheckpoints(store, entry.agent.id);
457
+ const current = await getAgent(store, entry.agent.id);
458
+ if (!current)
459
+ throw new ApiError("not_found", "The agent no longer exists.");
460
+ // The body still pins any explicitly requested revision; refresh the current pointer used by admission's CAS.
461
+ entry = current;
462
+ await requireSavedProject(store, entry.agent.id);
463
+ }
452
464
  if (entry.revision?.body?.cli_learning)
453
465
  throw new ApiError("agent_not_runnable", "Start the next prompt in your existing CLI session. AgentRun records its learning; it does not launch this connection.");
454
466
  if (entry.revision?.body?.sdk)
455
467
  throw new ApiError("agent_not_runnable", "This agent runs in your backend SDK. Start it through its SDK learning wrapper; AgentRun does not launch its tools or credentials.");
456
- const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
468
+ const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}), ...(keys ? { keys } : {}) });
457
469
  keyedOrRefused(deps, launch, revision.kind, sealed);
458
470
  const runId = (deps.newRunId ?? uuidv7)();
459
471
  try {
460
472
  const labels = labelsOf(body.labels);
461
- return await withHeldFiles(deps, runId, entry.agent.id, launch, (launch) => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, revision.kind) } : {}) }));
473
+ return await withHeldFiles(store, deps, runId, entry.agent.id, revision, launch, (launch) => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, expectedCurrent: entry.agent.currentRevision, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, revision.kind) } : {}) }));
462
474
  }
463
475
  catch (error) {
476
+ if (error instanceof RevisionMoved)
477
+ throw new ApiError("precondition_failed", "The agent changed while this run was prepared. Start again using its current setup.");
464
478
  // Only another writer of the store got here first under the same origin key: its run is the one asked for.
465
479
  if (origin && error instanceof StoreConstraint) {
466
480
  const existing = await store.runOfOrigin(origin.key);
@@ -482,7 +496,95 @@ function keyedOrRefused(deps, launch, kind, sealed) {
482
496
  * hold that fails part way, a write that fails, or one that answers another run (an origin key's run started before),
483
497
  * lets go of the hold. In Mode 2 they are placed in the run's folder instead (StartDeps.files.place), and the run is
484
498
  * written with the launch that says so; the same failures undo the placing. */
485
- async function withHeldFiles(deps, runId, agentId, launch, write) {
499
+ export async function withHeldFiles(store, deps, runId, agentId, revision, launch, write) {
500
+ const source = sourceSyncOf(revision.body);
501
+ if (!source)
502
+ return withUploads(deps, runId, agentId, launch, write);
503
+ if (!deps.project)
504
+ throw new ApiError("agent_not_runnable", "This project must be prepared before its run can start.");
505
+ const ownership = await deps.project.hold?.({ runId, agentId });
506
+ let projectSettled = false;
507
+ const preparationOwnership = ownership ? { settled: async () => { projectSettled = true; } } : undefined;
508
+ const undos = [];
509
+ const undo = async (settled = false) => {
510
+ let complete = true;
511
+ for (const release of [...undos].reverse())
512
+ try {
513
+ await release();
514
+ }
515
+ catch {
516
+ complete = false;
517
+ }
518
+ if ((settled || projectSettled) && complete)
519
+ await ownership?.settled();
520
+ };
521
+ let prepared = launch, admitted;
522
+ try {
523
+ const ids = launch.files ?? [];
524
+ if (ids.length && deps.files) {
525
+ const uploaded = await deps.files.place?.(runId, agentId, prepared);
526
+ if (uploaded) {
527
+ prepared = uploaded.launch;
528
+ undos.push(() => uploaded.undo());
529
+ }
530
+ else {
531
+ undos.push(() => deps.files.release(runId));
532
+ await deps.files.hold(runId, ids);
533
+ }
534
+ }
535
+ const placed = await deps.project.place({ runId, agentId, revision, launch: prepared, ...(preparationOwnership ? { hold: preparationOwnership } : {}) });
536
+ if (!placed)
537
+ throw new ApiError("agent_not_runnable", "This project has no completed placement for its run.");
538
+ undos.push(() => placed.undo());
539
+ admitted = placed.admitted;
540
+ prepared = placed.launch;
541
+ const receipt = sourceProjectOf(prepared.sourceProject);
542
+ if (!receipt || receipt.sourceId !== source.id || receipt.digest !== source.project || receipt.baselineRevision !== revision.id)
543
+ throw new ApiError("agent_not_runnable", "The prepared project does not match this run's pinned revision.");
544
+ }
545
+ catch (error) {
546
+ await undo();
547
+ throw error;
548
+ }
549
+ try {
550
+ const row = await write(prepared);
551
+ if (row.id !== runId)
552
+ await undo(true);
553
+ else {
554
+ if (ownership)
555
+ await ownership.settled();
556
+ else
557
+ await admitted?.();
558
+ }
559
+ return row;
560
+ }
561
+ catch (error) {
562
+ // A transport/COMMIT answer can be lost after admission. Never erase a runner's files on that evidence. Even a
563
+ // successful absent-row read does not prove an in-flight commit cannot land later: unknown admissions stay retained.
564
+ let knownAbsent = false;
565
+ try {
566
+ const row = await store.runs.get(runId);
567
+ if (row) {
568
+ const kept = await store.runs.launch(runId);
569
+ if (row.agentId === agentId && row.revisionId === revision.id && kept && canonical(kept.body) === canonical(launchBody(prepared))) {
570
+ if (ownership)
571
+ await ownership.settled();
572
+ else
573
+ await admitted?.();
574
+ return row;
575
+ }
576
+ }
577
+ else
578
+ knownAbsent = true;
579
+ }
580
+ catch { /* preserve preparation until the admission can be resolved */ }
581
+ if (knownAbsent && (error instanceof StoreConstraint || error instanceof RevisionMoved || error instanceof AgentDeleting
582
+ || error instanceof AgentPurged || error instanceof AgentArchived || error instanceof ExternalBodyConflict || error instanceof ApiError))
583
+ await undo(true);
584
+ throw error;
585
+ }
586
+ }
587
+ async function withUploads(deps, runId, agentId, launch, write) {
486
588
  const ids = launch.files ?? [];
487
589
  if (!ids.length || !deps.files)
488
590
  return await write(launch);
@@ -546,7 +648,7 @@ export async function startInline(store, deps, inline, body, options = {}) {
546
648
  }
547
649
  /** The agent id each reference's first starts in progress share, and a failed first start's kept (startInline). */
548
650
  const tentativeAgents = new Map();
549
- async function startInlineOnce(store, deps, inline, body, { origin, sealed }, newAgentId) {
651
+ async function startInlineOnce(store, deps, inline, body, { origin, sealed, keys }, newAgentId) {
550
652
  const { external, revision, stored: storedRevision } = inline;
551
653
  const ref = externalKey(external);
552
654
  // A version's body never changes here: a different one is refused before anything else is read or written.
@@ -570,12 +672,12 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed }, ne
570
672
  };
571
673
  // A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
572
674
  // one across.
573
- const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision) });
675
+ const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision), ...(keys ? { keys } : {}) });
574
676
  keyedOrRefused(deps, launch, (storedRevision ?? revision).kind, sealed);
575
677
  const runId = (deps.newRunId ?? uuidv7)();
576
678
  const labels = labelsOf(body.labels);
577
679
  try {
578
- return await withHeldFiles(deps, runId, entry.agent.id, launch, (launch) => store.runs.createInline({
680
+ return await withHeldFiles(store, deps, runId, entry.agent.id, revision, launch, (launch) => store.runs.createInline({
579
681
  agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
580
682
  revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
581
683
  run: { id: runId, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) },
@@ -600,7 +702,7 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed }, ne
600
702
  * caller INSERTs the run with it (startRun; an inline agent's run, which writes its agent and revision in the same
601
703
  * transaction). `revision`: the revision the run starts on, given (an inline agent's, not yet stored), in place of the
602
704
  * one the body pins or the agent's current (deps.pinnedOf). */
603
- export async function prepareLaunch(deps, entry, body, { trigger, capped = false, from, title: given, revision: onRevision } = {}) {
705
+ export async function prepareLaunch(deps, entry, body, { trigger, capped = false, from, title: given, revision: onRevision, keys } = {}) {
604
706
  const pinnedOf = onRevision ? async () => ({ revision: onRevision, version: entry.version }) : () => deps.pinnedOf(entry, body);
605
707
  const issues = deps.runBodyIssues(body);
606
708
  if (issues.length) {
@@ -630,6 +732,11 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
630
732
  const wrong = await deps.inputIssuesOf(revision, input);
631
733
  if (wrong.length)
632
734
  throw deps.told(invalid(await deps.explainRun(wrong, body, revision)));
735
+ // The tool keys the run carries (run-keys.ts), by name: each one a tool of its revision reads, or its template declared.
736
+ const carried = keys ?? [];
737
+ const undeclared = carried.length ? undeclaredKeys(carried, await declaredKeys(revision)) : [];
738
+ if (undeclared.length)
739
+ throw invalid(undeclared);
633
740
  // The run's own cap, else the agent's default: the caller chose its own.
634
741
  const cap = typeof body.max_cost_usd === "number" ? body.max_cost_usd : rbody.maxCostUsd;
635
742
  if (capped && cap === undefined)
@@ -642,7 +749,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
642
749
  const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
643
750
  // Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
644
751
  // its server could not be listed, is refused with the rest (runnable).
645
- await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined });
752
+ await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined, carried });
646
753
  // A held computer (computer-held.ts): only one that speaks the protocol, its kind as the claim reads it (the
647
754
  // revision's computer, else its place's).
648
755
  const hold = holdOf(body, (settingOfDefinition(rbody)?.computer ?? computerOfPlace(place)).kind);
@@ -657,9 +764,10 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
657
764
  // A starter's title (a trigger's "<Source> <name>") is shown words too: cut as the input is, then as every title is below.
658
765
  const title = given !== undefined ? String(redactedOutput(given, deps.serverSecrets())) : revision.kind === "workflow" ? deps.workflowTitle(entry.agent.name || entry.agent.id, isObject(shown) ? shown : {}) : typeof input.content === "string" ? input.content : (Object.values(input).find((v) => typeof v === "string") ?? JSON.stringify(input));
659
766
  // Its tools' providers, resolved before the run exists (tool-plane.ts) and kept in its launch body, so a claim reads them
660
- // back, never the settings of that moment. (The old start wrote them to serve.json; now they ride the launch row.)
767
+ // back, never the settings of that moment. (The old start wrote them to serve.json; now they ride the launch row.) A key
768
+ // the run carries resolves a tool as one the host holds would.
661
769
  const tooling = await toolingOf(revision);
662
- const plane = tooling ? planeFor(deps.planeEnv(), tooling, deps.toolSettings(), { capped: cap !== undefined, run: true }) : {};
770
+ const plane = tooling ? planeFor(withCarried(deps.planeEnv(), carried), tooling, deps.toolSettings(), { capped: cap !== undefined, run: true }) : {};
663
771
  // The run's model, resolved once, at start (the runner reads launch.model only).
664
772
  const model = await deps.modelOf(entry, revision);
665
773
  // The run's Archil disk, chosen now and kept in its launch (run-launch.ts archilDisk): the one the body names (a disk per
@@ -64,6 +64,9 @@ export type SdkInbox = {
64
64
  }[];
65
65
  /** Exact promoted executable workflows delivered by the start receipt. */
66
66
  learning_workflows?: LearnedWorkflow[];
67
+ /** The learning commit each of learning_workflows was read at, by name (its seed's, or its champion record's): where
68
+ * the receipt asks whether a purged run wrote it (receipt). */
69
+ learning_commits?: Record<string, string>;
67
70
  /** A compiled draft reserved for a shadow check, never supplied to the native agent. */
68
71
  learning_check?: SdkWorkflowCheck;
69
72
  /** Server cleaning changed evidence: two different secret-bearing answers must never agree by their placeholder. */
@@ -76,10 +79,12 @@ export type SdkInbox = {
76
79
  };
77
80
  /** The settings key an SDK run's record is kept under (the run's delete with its agent's: agent-delete.ts). */
78
81
  export declare const sdkRunKey: (id: string) => string;
82
+ export declare const SDK_MAX_OPEN_MS = 86400000;
79
83
  export declare const sdkOf: (body: unknown) => SdkBinding | undefined;
80
84
  export declare function sdkInbox(store: Pick<Store, "settings">, runId: string): Promise<SdkInbox>;
81
85
  /** Completion and closure compete on the same inbox. A stale runner cannot close it, and a completion that won
82
- * remains available to the next claim even if this one cannot read or journal it. No external SDK call is replayed. */
86
+ * remains available to the next claim even if this one cannot read or journal it. No external SDK call is replayed.
87
+ * An expiry is checked against the row it replaces: an events batch that moved the deadline keeps the inbox open. */
83
88
  export declare function closeSdkInbox(store: Pick<Store, "settings">, claim: Claim, reason: NonNullable<SdkInbox["closed"]>): Promise<SdkInbox>;
84
89
  /** The key a server signs its SDK runs' credentials with: derived from its seal key (seal-key.ts), which stays the
85
90
  * store's for its life, so adding, reordering or removing an API token (api-token.ts) never changes a run's credential. */
@@ -126,6 +131,11 @@ export declare class SdkRuns {
126
131
  workflows: LearnedWorkflow[];
127
132
  };
128
133
  }>;
134
+ /** The purged run (purged-workflow.ts) that wrote a workflow of `pinned`, each read at the learning commit a start took
135
+ * its text from. One read-only exec per commit. */
136
+ private purgedPinned;
137
+ /** The workflows a start delivers and the learning commit each was read at (`commits`: the seed's, or its champion
138
+ * record's), and the drafts a check may take. */
129
139
  private selectedWorkflows;
130
140
  private modify;
131
141
  private writable;