@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.57

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 (275) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +201 -52
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +17 -5
  11. package/dist/api-only.js +34 -8
  12. package/dist/browser-hold.d.ts +23 -0
  13. package/dist/browser-hold.js +48 -0
  14. package/dist/browser-person.d.ts +3 -0
  15. package/dist/browser-person.js +4 -1
  16. package/dist/chatgpt-plan.d.ts +18 -8
  17. package/dist/chatgpt-plan.js +91 -34
  18. package/dist/claude-login.d.ts +74 -16
  19. package/dist/claude-login.js +215 -56
  20. package/dist/claude-sign-in.d.ts +17 -6
  21. package/dist/claude-sign-in.js +42 -39
  22. package/dist/cli.js +63 -6
  23. package/dist/composio-made.d.ts +4 -0
  24. package/dist/composio-made.js +4 -0
  25. package/dist/composio-preset.d.ts +43 -2
  26. package/dist/composio-preset.js +92 -4
  27. package/dist/computer-held-routes.d.ts +5 -4
  28. package/dist/computer-held-routes.js +29 -8
  29. package/dist/computer-held.d.ts +6 -1
  30. package/dist/computer-held.js +14 -0
  31. package/dist/computer-record.js +4 -2
  32. package/dist/computer-viewer.js +4 -1
  33. package/dist/console/assets/{backend-Boh7tC4i.js → backend-DVhHzJX2.js} +19 -19
  34. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  35. package/dist/console/assets/index-okP-y8PK.js +747 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/decisions.d.ts +1 -1
  38. package/dist/decisions.js +1 -1
  39. package/dist/docker-host-addresses.d.ts +22 -11
  40. package/dist/docker-host-addresses.js +38 -26
  41. package/dist/env-switch.d.ts +10 -0
  42. package/dist/env-switch.js +33 -2
  43. package/dist/errors.d.ts +1 -0
  44. package/dist/errors.js +2 -0
  45. package/dist/fal-price.d.ts +58 -20
  46. package/dist/fal-price.js +341 -82
  47. package/dist/handed-values.d.ts +43 -1
  48. package/dist/handed-values.js +119 -2
  49. package/dist/harness-archive.d.ts +13 -10
  50. package/dist/harness-archive.js +60 -34
  51. package/dist/harness-check.d.ts +3 -1
  52. package/dist/harness-check.js +25 -46
  53. package/dist/harness-keys.d.ts +73 -27
  54. package/dist/harness-keys.js +194 -61
  55. package/dist/harness-recipe-entry.d.ts +8 -7
  56. package/dist/harness-recipe-entry.js +21 -32
  57. package/dist/harness-recipe.d.ts +38 -25
  58. package/dist/harness-recipe.js +49 -36
  59. package/dist/harness-sign-in.js +12 -23
  60. package/dist/harness-table.d.ts +10 -3
  61. package/dist/harness-table.js +26 -21
  62. package/dist/harness.d.ts +1 -0
  63. package/dist/harness.js +17 -5
  64. package/dist/hosted-search.d.ts +1 -1
  65. package/dist/hosted-search.js +1 -2
  66. package/dist/import-worker.d.ts +4 -2
  67. package/dist/import-worker.js +9 -2
  68. package/dist/in-flight.d.ts +26 -0
  69. package/dist/in-flight.js +52 -0
  70. package/dist/key-refusal.d.ts +9 -4
  71. package/dist/key-refusal.js +107 -25
  72. package/dist/learn/secrets.d.ts +13 -3
  73. package/dist/learn/secrets.js +118 -17
  74. package/dist/learning-cost.d.ts +6 -3
  75. package/dist/learning-cost.js +4 -2
  76. package/dist/link-check.js +1 -1
  77. package/dist/llms.txt +1 -1
  78. package/dist/marketplace.d.ts +77 -0
  79. package/dist/marketplace.js +224 -0
  80. package/dist/mcp-api-only-origins.d.ts +30 -0
  81. package/dist/mcp-api-only-origins.js +57 -0
  82. package/dist/mcp-gateway.d.ts +7 -5
  83. package/dist/mcp-gateway.js +9 -12
  84. package/dist/mcp-secret-writes.js +5 -3
  85. package/dist/mcp-servers-store.d.ts +28 -6
  86. package/dist/mcp-servers-store.js +53 -4
  87. package/dist/media-duration.d.ts +3 -0
  88. package/dist/media-duration.js +90 -9
  89. package/dist/model-form.d.ts +5 -4
  90. package/dist/model-form.js +11 -7
  91. package/dist/model.d.ts +5 -2
  92. package/dist/model.js +9 -5
  93. package/dist/ollama-provider.d.ts +7 -1
  94. package/dist/ollama-provider.js +14 -2
  95. package/dist/openapi.js +178 -27
  96. package/dist/otel/genai.d.ts +65 -0
  97. package/dist/otel/genai.js +116 -0
  98. package/dist/otel/tracer.d.ts +55 -0
  99. package/dist/otel/tracer.js +308 -0
  100. package/dist/page.d.ts +2 -0
  101. package/dist/page.js +3 -1
  102. package/dist/paid-calls.d.ts +1 -32
  103. package/dist/paid-calls.js +4 -39
  104. package/dist/provider.d.ts +9 -0
  105. package/dist/provider.js +50 -3
  106. package/dist/redact/match.d.ts +30 -3
  107. package/dist/redact/match.js +422 -41
  108. package/dist/refusal-words.d.ts +11 -0
  109. package/dist/refusal-words.js +11 -0
  110. package/dist/run-census.d.ts +67 -0
  111. package/dist/run-census.js +240 -0
  112. package/dist/run-computer.d.ts +6 -3
  113. package/dist/run-computer.js +4 -1
  114. package/dist/run-cut.d.ts +15 -6
  115. package/dist/run-cut.js +30 -9
  116. package/dist/run-files.d.ts +3 -0
  117. package/dist/run-files.js +3 -0
  118. package/dist/run-launch.d.ts +12 -1
  119. package/dist/run-launch.js +9 -10
  120. package/dist/run-learning-served.d.ts +2 -0
  121. package/dist/run-model-key.d.ts +8 -0
  122. package/dist/run-model-key.js +31 -1
  123. package/dist/run-reads-over-store.d.ts +24 -6
  124. package/dist/run-reads-over-store.js +67 -23
  125. package/dist/run-recordings.d.ts +5 -1
  126. package/dist/run-recordings.js +39 -14
  127. package/dist/run-timeline-served.d.ts +2 -0
  128. package/dist/run-timeline-served.js +2 -2
  129. package/dist/run-usage.d.ts +1 -0
  130. package/dist/runnable.d.ts +10 -1
  131. package/dist/runnable.js +20 -8
  132. package/dist/runner/adapter-loop.d.ts +11 -0
  133. package/dist/runner/adapter-loop.js +55 -10
  134. package/dist/runner/adapter-run-spec.d.ts +45 -8
  135. package/dist/runner/adapter-run-spec.js +150 -28
  136. package/dist/runner/adapters/pi.js +25 -3
  137. package/dist/runner/beside.js +4 -3
  138. package/dist/runner/big-writes.js +1 -10
  139. package/dist/runner/claim-secrets.d.ts +18 -3
  140. package/dist/runner/claim-secrets.js +35 -6
  141. package/dist/runner/cli-run-spec.d.ts +6 -0
  142. package/dist/runner/cli-run-spec.js +82 -35
  143. package/dist/runner/computer-journal.d.ts +9 -1
  144. package/dist/runner/computer-journal.js +26 -0
  145. package/dist/runner/conformance/harness.js +1 -1
  146. package/dist/runner/feedback-round.js +3 -0
  147. package/dist/runner/harness-loops.d.ts +6 -5
  148. package/dist/runner/harness-loops.js +7 -7
  149. package/dist/runner/held.d.ts +11 -5
  150. package/dist/runner/journal-kinds.d.ts +5 -0
  151. package/dist/runner/journal-kinds.js +5 -0
  152. package/dist/runner/main.js +7 -2
  153. package/dist/runner/mcp-claim.js +30 -3
  154. package/dist/runner/mcp-run.d.ts +12 -0
  155. package/dist/runner/mcp-run.js +12 -5
  156. package/dist/runner/model-route.d.ts +17 -0
  157. package/dist/runner/model-route.js +120 -2
  158. package/dist/runner/run-child-host.d.ts +3 -0
  159. package/dist/runner/run-child-host.js +69 -28
  160. package/dist/runner/run-child.js +5 -2
  161. package/dist/runner/runner.d.ts +14 -3
  162. package/dist/runner/runner.js +129 -33
  163. package/dist/runner/store-port.d.ts +1 -1
  164. package/dist/runner/store-secrets.d.ts +6 -0
  165. package/dist/runner/store-secrets.js +49 -7
  166. package/dist/runner/subagent.js +4 -40
  167. package/dist/runner/workflow-first.d.ts +11 -4
  168. package/dist/runner/workflow-first.js +14 -8
  169. package/dist/runner/workflow-spec.js +3 -2
  170. package/dist/runs-over-store.d.ts +15 -6
  171. package/dist/runs-over-store.js +33 -21
  172. package/dist/scrub-command.d.ts +73 -0
  173. package/dist/scrub-command.js +307 -0
  174. package/dist/secret-cut.d.ts +73 -0
  175. package/dist/secret-cut.js +291 -4
  176. package/dist/secret-rules.d.ts +143 -0
  177. package/dist/secret-rules.js +2564 -0
  178. package/dist/secrets.d.ts +7 -0
  179. package/dist/secrets.js +20 -0
  180. package/dist/server-keys.d.ts +20 -0
  181. package/dist/server-keys.js +25 -6
  182. package/dist/server.d.ts +52 -11
  183. package/dist/server.js +345 -118
  184. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  185. package/dist/store/index.d.ts +1 -1
  186. package/dist/store/index.js +1 -1
  187. package/dist/store/journal/storage.js +1 -1
  188. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  189. package/dist/store/schema.d.ts +6 -0
  190. package/dist/store/schema.js +11 -1
  191. package/dist/store/seal.d.ts +6 -1
  192. package/dist/store/seal.js +5 -3
  193. package/dist/store/sqlite/run-launch.d.ts +9 -1
  194. package/dist/store/sqlite/run-launch.js +24 -13
  195. package/dist/store/sqlite/run-patch.d.ts +1 -1
  196. package/dist/store/sqlite/run-patch.js +13 -4
  197. package/dist/store/sqlite/store.js +34 -4
  198. package/dist/store/store.d.ts +43 -2
  199. package/dist/store/store.js +20 -0
  200. package/dist/store-reads/learning.d.ts +6 -3
  201. package/dist/store-reads/learning.js +22 -7
  202. package/dist/store-view.d.ts +3 -0
  203. package/dist/store-view.js +3 -3
  204. package/dist/suggestions.js +3 -2
  205. package/dist/template-eval.d.ts +20 -9
  206. package/dist/template-eval.js +115 -33
  207. package/dist/template-import.d.ts +10 -0
  208. package/dist/template-import.js +16 -7
  209. package/dist/templates.d.ts +10 -2
  210. package/dist/templates.js +28 -8
  211. package/dist/timeline/labels.d.ts +6 -4
  212. package/dist/timeline/labels.js +18 -6
  213. package/dist/timeline/timeline.d.ts +5 -0
  214. package/dist/timeline/timeline.js +14 -8
  215. package/dist/timeline/util.js +1 -1
  216. package/dist/timeline/web-calls.d.ts +26 -9
  217. package/dist/timeline/web-calls.js +124 -37
  218. package/dist/tool-gate.d.ts +42 -3
  219. package/dist/tool-gate.js +66 -5
  220. package/dist/tool-keys-store.d.ts +2 -4
  221. package/dist/tool-keys-store.js +5 -21
  222. package/dist/tool-keys.d.ts +2 -2
  223. package/dist/tool-keys.js +2 -2
  224. package/dist/tool-list.js +1 -1
  225. package/dist/tool-plane.d.ts +2 -2
  226. package/dist/tool-plane.js +35 -33
  227. package/dist/tools.js +13 -7
  228. package/dist/trigger-targets.d.ts +4 -0
  229. package/dist/trigger-targets.js +9 -2
  230. package/dist/triggers.d.ts +67 -4
  231. package/dist/triggers.js +171 -22
  232. package/dist/until.d.ts +3 -0
  233. package/dist/until.js +11 -0
  234. package/dist/web-fake.d.ts +1 -3
  235. package/dist/web-fake.js +7 -18
  236. package/dist/web-fetch.d.ts +6 -72
  237. package/dist/web-fetch.js +11 -265
  238. package/dist/web-run.d.ts +31 -0
  239. package/dist/web-run.js +90 -0
  240. package/dist/web-save.d.ts +6 -4
  241. package/dist/web-save.js +9 -12
  242. package/dist/web-search.d.ts +9 -127
  243. package/dist/web-search.js +23 -259
  244. package/dist/wires.d.ts +13 -0
  245. package/dist/wires.js +11 -0
  246. package/dist/workflow-run.d.ts +5 -4
  247. package/dist/workflow-run.js +5 -4
  248. package/dist/workspace/computer-deps.d.ts +2 -1
  249. package/dist/workspace/computer-deps.js +9 -2
  250. package/dist/workspace/computer-for-claim.d.ts +12 -1
  251. package/dist/workspace/computer-for-claim.js +77 -8
  252. package/dist/workspace/computer-kept.d.ts +3 -0
  253. package/dist/workspace/computer-kept.js +11 -2
  254. package/dist/workspace/index.d.ts +1 -1
  255. package/dist/workspace/index.js +1 -1
  256. package/dist/workspace/kind-skills.d.ts +4 -0
  257. package/dist/workspace/kind-skills.js +9 -0
  258. package/dist/workspace/synced-folder.js +3 -4
  259. package/dist/wrapped.d.ts +13 -5
  260. package/dist/wrapped.js +52 -26
  261. package/package.json +17 -11
  262. package/skills/agentrun-serve/SKILL.md +4 -0
  263. package/templates/README.md +30 -8
  264. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  265. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  266. package/dist/exa-keyless.d.ts +0 -34
  267. package/dist/exa-keyless.js +0 -118
  268. package/dist/firecrawl-keyless.d.ts +0 -41
  269. package/dist/firecrawl-keyless.js +0 -152
  270. package/dist/keyless-mcp.d.ts +0 -36
  271. package/dist/keyless-mcp.js +0 -127
  272. package/dist/text-urls.d.ts +0 -38
  273. package/dist/text-urls.js +0 -170
  274. package/dist/web-fetch-direct.d.ts +0 -119
  275. package/dist/web-fetch-direct.js +0 -190
@@ -12,9 +12,10 @@
12
12
  // is one sample; a revision is asked only of a workflow its promotion holds), and never keeps the workflow from serving.
13
13
  // One money rule does (costLineOf): a workflow
14
14
  // serves while its all-in cost a run over its last COST_WINDOW served runs at its digest stays under the agent's by-hand
15
- // cost (its `agent` runs' mean all-in cost; with none, its runs before the workflow's first). Both sides read one all-in
16
- // cost a run, the cost page's (store-reads/learning.ts allInOf): its booked cost (the workflow and any handback's agent
17
- // work together) and every learning round booked for it (its look-backs, its grades, a follow-up's rounds). A run whose
15
+ // cost (its `agent` runs' mean all-in cost; with none, its runs before the workflow's first). Each run is read at its
16
+ // all-in (store-reads/learning.ts moneyAllInOf): its booked cost (the workflow and any handback's agent work together)
17
+ // and every learning round booked for it (its look-backs, its grades, a follow-up's rounds), less, on the by-hand side,
18
+ // its compile turns, which the run view charges to the revision they drafted. A run whose
18
19
  // all-in is unknown anywhere is left out of its side's mean and counted, never read as 0. Over that line it stops running
19
20
  // first: the agent takes the run, the run's journal keeps why with the two numbers (WORKFLOW_FIRST, outcome
20
21
  // needs_revision), and the agent's cost per run shows it stopped. The stop asks for no compile. A new revision of it (a
@@ -230,17 +231,22 @@ export async function workflowFirstOf(kind, workflows, launch, log, past, promot
230
231
  }
231
232
  /** What a run's workflow-first step did, from its root entries (the WORKFLOW_FIRST entry): the workflow, its digest, the
232
233
  * promotion it served under (WorkflowFirst.promotion), and whether it answered or handed back; undefined when it served
233
- * none. The run's path is the run-end classifier's (store-reads/learning.ts runPathOverStore), which reads this first. */
234
+ * none. `cut` on a hand-back the workflow never made itself: its call's end (WORKFLOW_FIRST_CALL) is `interrupted`, a
235
+ * crash or a lost runner cut it and the next claim ended it, never running it again (adapter-loop.ts serveFirst). The
236
+ * run's path is the run-end classifier's (store-reads/learning.ts runPathOverStore), which reads this first. */
234
237
  export function servedOf(entries) {
235
238
  const served = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && (entry.data?.outcome === "answered" || entry.data?.outcome === "handed_back"))?.data;
236
239
  if (!served || typeof served.workflow !== "string")
237
240
  return undefined;
238
- return { outcome: served.outcome, workflow: served.workflow, ...(typeof served.digest === "string" ? { digest: served.digest } : {}), ...(typeof served.promotion === "number" ? { promotion: served.promotion } : {}) };
241
+ const end = entries.findLast((entry) => entry.kind === KINDS.callEnd && entry.data?.callId === WORKFLOW_FIRST_CALL)?.data;
242
+ const cut = served.outcome === "handed_back" && end?.status === "interrupted";
243
+ return { outcome: served.outcome, workflow: served.workflow, ...(typeof served.digest === "string" ? { digest: served.digest } : {}), ...(typeof served.promotion === "number" ? { promotion: served.promotion } : {}), ...(cut ? { cut: true } : {}) };
239
244
  }
240
245
  /** The run-record fields a learning run's metrics carry, from the run-end classifier's `classified` path
241
246
  * (runPathOverStore): the path it took, the learned revision it ran on, the learned workflow it ran (served first, or
242
247
  * called by its agent) and, for one served first, its digest and the promotion it served under (`workflow_promotion`,
243
- * which its grade keeps), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
248
+ * which its grade keeps), `workflow_cut` on a hand-back a restart cut (servedOf `cut`: the workflow handed nothing back
249
+ * itself), and `not_auditable` when a trigger started it (never audited); and from its root `entries`,
244
250
  * each loop's exit (`loops`, loopsOf: a quote re-pick is a loop's second pass), when one ran. learning-cost reads path
245
251
  * and workflow from here. None for a run that does not learn. */
246
252
  export function pathMetrics(launch, classified, entries = []) {
@@ -252,7 +258,7 @@ export function pathMetrics(launch, classified, entries = []) {
252
258
  return { path: "audit", audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest, ...verdict } };
253
259
  if (!launch.learning)
254
260
  return {};
255
- const { path, workflow, digest, promotion } = classified ?? { path: "agent", workflow: null };
261
+ const { path, workflow, digest, promotion, cut } = classified ?? { path: "agent", workflow: null };
256
262
  const loops = loopsOf(entries);
257
263
  const rows = loops.length ? { loops } : {};
258
264
  if (launch.replay) {
@@ -269,7 +275,7 @@ export function pathMetrics(launch, classified, entries = []) {
269
275
  }
270
276
  // A served run a trigger started (learn/audit.ts auditableLaunch) is never audited: counted on the promotions read.
271
277
  const notAuditable = SERVED_PATHS.includes(path) && !auditableLaunch(launch);
272
- return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...(notAuditable ? { not_auditable: true } : {}), ...rows };
278
+ return { path, ...(launch.learning.seed ? { learned_revision: launch.learning.seed } : {}), ...(workflow ? { workflow } : {}), ...(digest ? { workflow_digest: digest } : {}), ...(promotion !== undefined ? { workflow_promotion: promotion } : {}), ...(cut && path === "handed_back" ? { workflow_cut: true } : {}), ...(notAuditable ? { not_auditable: true } : {}), ...rows };
273
279
  }
274
280
  /** What run `entries` (its root's) say its learned workflow answered alone: the workflow and its answer (the model's
275
281
  * message written just before the WORKFLOW_FIRST entry, in its commit); undefined for a run it did not answer. A follow-up that opens such a
@@ -30,8 +30,9 @@ import { runGate } from "../tool-gate.js";
30
30
  import { callNodeAskText, deniedText, modelNodeAskText } from "../refusal-words.js";
31
31
  import { planeOf, TOOL_PLANE_ENV } from "../tool-plane.js";
32
32
  import { AsyncLocalStorage } from "node:async_hooks";
33
- import { bookedIn, parallelExtractFee, parallelSearchFee } from "../paid-calls.js";
34
- import { searchArgs, WEB_SEARCH_TOOL } from "../web-search.js";
33
+ import { parallelExtractFee, parallelSearchFee, searchArgs } from "@parcha/agentrun-web";
34
+ import { bookedIn } from "../paid-calls.js";
35
+ import { WEB_SEARCH_TOOL } from "../web-search.js";
35
36
  import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
36
37
  import { claimModelEnv, claimModelKey, claimSecrets, holdRunKey, keyedAtClaim, withoutModelKeys } from "./claim-secrets.js";
37
38
  import { routeOf } from "./model-route.js";
@@ -6,7 +6,8 @@ import { ApiError, type InputIssue } from "./errors.js";
6
6
  import { type LearningMode, type Seed, type Shown } from "./learning.js";
7
7
  import { type Place } from "./place.js";
8
8
  import { type RepoBinding } from "./run-repo.js";
9
- import { type LaunchDisk, type RunLaunch } from "./run-launch.js";
9
+ import { type HeldRefusal, type LaunchDisk, type RunLaunch } from "./run-launch.js";
10
+ import { type ModelKeyTarget } from "./run-model-key.js";
10
11
  import { type ApprovalDecision, type RunMoment } from "./run-view.js";
11
12
  import { type LaunchSealed, type NewRevision, type RevisionRow, type RunOrigin, type RunRow, type Store } from "./store/index.js";
12
13
  import { type ToolSettingsMap } from "./tool-plane.js";
@@ -124,11 +125,13 @@ export interface StartDeps {
124
125
  /** Marks an input refusal as told from a revision (server.ts told). */
125
126
  told(error: ApiError): ApiError;
126
127
  /** 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
+ * name) read as one the host holds. `held`: the run holds its computer (hold: true), so a refusal for its model alone
129
+ * is returned for its launch instead of thrown (computer-held.ts). */
128
130
  runnable(revision: Revision, place: Place, options: {
129
131
  capped: boolean;
130
132
  carried?: readonly string[];
131
- }): Promise<void>;
133
+ held?: boolean;
134
+ }): Promise<HeldRefusal | undefined>;
132
135
  /** The revision a run starts on, its MCP tools pinned: one that grants an MCP tool and was saved with no pin (before
133
136
  * pins were made at save, or an inline agent's version stored then) is pinned once, at its first run (server.ts
134
137
  * pinFirst); any other as it is. */
@@ -220,8 +223,9 @@ export interface StartDeps {
220
223
  export interface StartOptions {
221
224
  readonly trigger?: RunTrigger;
222
225
  /** The run's launch secrets, sealed for its id once it has one (the create body's mcp_auth and model_key, server.ts),
223
- * given the launch the start prepared, which the sealer may refuse (a model key where the run's model takes none). */
224
- readonly sealed?: (runId: string, launch: RunLaunch, kind: Revision["kind"]) => Uint8Array | null;
226
+ * given the launch the start prepared and where its model requests go (run-model-key.ts keyTargetOf), which the sealer
227
+ * may refuse (a model key where the run's model takes none). */
228
+ readonly sealed?: (runId: string, launch: RunLaunch, target: ModelKeyTarget) => Uint8Array | null;
225
229
  /** The run's title when its starter names one (a trigger's: "<Source> <name>"), else it is made from its input. */
226
230
  readonly title?: string;
227
231
  readonly origin?: RunOrigin;
@@ -229,6 +233,11 @@ export interface StartOptions {
229
233
  readonly from?: MessageOrigin;
230
234
  /** The names of the tool keys the run carries (`keys`, run-keys.ts; their values go only into `sealed`). */
231
235
  readonly keys?: readonly string[];
236
+ /** The firing the run starts, in the run's own write (store.runs.create `firing`): a launch hook's host's start. */
237
+ readonly firing?: {
238
+ triggerId: string;
239
+ key: string;
240
+ };
232
241
  }
233
242
  /** The run's learning start: undefined when the run does not learn (the server's learning off, a workflow revision, or
234
243
  * its revision does not say learning), else the seed sha it starts from, its # Learned text (its owner's corrections,
@@ -250,7 +259,7 @@ export declare function learningStartFor(deps: StartDeps, entry: AgentEntry, rev
250
259
  * (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
251
260
  * 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
252
261
  * starts a second. */
253
- export declare function startRun(store: Store, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed, keys }?: StartOptions): Promise<RunRow>;
262
+ export declare function startRun(store: Store, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed, keys, firing }?: StartOptions): Promise<RunRow>;
254
263
  /** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
255
264
  * hold that fails part way, a write that fails, or one that answers another run (an origin key's run started before),
256
265
  * lets go of the hold. In Mode 2 they are placed in the run's folder instead (StartDeps.files.place), and the run is
@@ -16,7 +16,7 @@ import { launchNative } from "./native/connection.js";
16
16
  import { randomBytes } from "node:crypto";
17
17
  import { externalKey, getAgent, ownedElsewhere } from "./agents-store.js";
18
18
  import { CAP_TOLERANCE, money } from "./cap.js";
19
- import { holdOf } from "./computer-held.js";
19
+ import { heldRefused, holdOf } from "./computer-held.js";
20
20
  import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
21
21
  import { ApiError, invalid, unsupported } from "./errors.js";
22
22
  import { labelsOf } from "./run-labels.js";
@@ -28,19 +28,19 @@ import { thinkingLevel } from "./model.js";
28
28
  import { resolvePlace } from "./place.js";
29
29
  import { githubTargetOf } from "./github.js";
30
30
  import { repoOf } from "./run-repo.js";
31
- import { launchBody, sourceProjectOf } from "./run-launch.js";
31
+ import { launchBody, readLaunchBody, sourceProjectOf } from "./run-launch.js";
32
32
  import { learningDiskOf } from "./learn/learning-of.js";
33
- import { modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
33
+ import { keyTargetOf, modelKeyRequired, serverKeyMissing } from "./run-model-key.js";
34
34
  import { raiseFollowUpId } from "./run-view.js";
35
35
  import { sendCommand } from "./runner/commands.js";
36
36
  import { refuseWhileNoRunner } from "./runner/presence.js";
37
- import { RevisionMoved, AgentDeleting, AgentPurged, AgentArchived, AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
37
+ import { RevisionMoved, AgentDeleting, AgentPurged, AgentArchived, AnswerTaken, ExternalBodyConflict, FiringMoved, RunFinal, StoreConstraint, StoreLaunchMissing } from "./store/index.js";
38
38
  import { canonical } from "./store/agent-body.js";
39
39
  import { sourceSyncOf } from "./source-sync/types.js";
40
40
  import { toolingOf } from "./tools.js";
41
41
  import { planeFor } from "./tool-plane.js";
42
42
  import { declaredKeys, undeclaredKeys, withCarried } from "./run-keys.js";
43
- import { clip } from "./web-fetch-direct.js";
43
+ import { clip } from "@parcha/agentrun-web";
44
44
  import { isObject } from "./validate.js";
45
45
  /** Why a message that may not answer a person's question is not sent (runs.ts WAITS_ON_A_PERSON). */
46
46
  export const WAITS_ON_A_PERSON = "The run is waiting on a person.";
@@ -178,6 +178,11 @@ export async function message(store, moment, content, { requestId, answers = tru
178
178
  throw new ApiError("not_continuable", "Backend SDK runs are single-task sessions. Start a new SDK call for another task.");
179
179
  if (nativeOf(launchBody))
180
180
  throw new ApiError("input_invalid", "Native jobs do not support in-session steering or follow-up messages. Start a new native run.");
181
+ // A held run its model kept from running at its create never runs its agent: a message would be its first turn (taken at
182
+ // a start, or opening it again once it ended), so it is refused as its start is (computer-held.ts).
183
+ const heldModel = readLaunchBody(launchBody)?.hold?.refused;
184
+ if (heldModel)
185
+ throw heldRefused(heldModel);
181
186
  // Archiving closes a run: it, or a run of its archived agent, takes no message, said as archived (never as finished). Another
182
187
  // system's agent is archived only by its delete: said so, as every run of it is refused (AgentDeleting).
183
188
  const archivedAgent = moment.archived === "agent" ? await store.agents.get(moment.agentId) : null;
@@ -444,7 +449,7 @@ export async function learningStartFor(deps, entry, revision, rbody, { use = fal
444
449
  * (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
445
450
  * 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
446
451
  * starts a second. */
447
- export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed, keys } = {}) {
452
+ export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed, keys, firing } = {}) {
448
453
  if (sourceSyncOf(entry.revision?.body)) {
449
454
  // Re-delivery of a firing that already admitted a run is not a new start and needs no new project preparation.
450
455
  if (origin) {
@@ -466,11 +471,12 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
466
471
  if (entry.revision?.body?.sdk)
467
472
  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.");
468
473
  const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}), ...(keys ? { keys } : {}) });
469
- keyedOrRefused(deps, launch, revision.kind, sealed);
474
+ const target = keyTargetOf(deps.planeEnv(), launch, revision);
475
+ keyedOrRefused(deps, target, sealed);
470
476
  const runId = (deps.newRunId ?? uuidv7)();
471
477
  try {
472
478
  const labels = labelsOf(body.labels);
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) } : {}) }));
479
+ 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 } : {}), ...(firing ? { firing } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, target) } : {}) }));
474
480
  }
475
481
  catch (error) {
476
482
  if (error instanceof RevisionMoved)
@@ -487,9 +493,10 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
487
493
  }
488
494
  /** A start with no launch secrets (`sealed`: a trigger's firing, a learning batch's row) whose route goes to the model
489
495
  * gateway, on a server that holds no key for it (run-model-key.ts serverKeyMissing): 422 model_key_required, nothing
490
- * written, never a failure at its first model call. A start with them (the API's) is the sealer's to check. */
491
- function keyedOrRefused(deps, launch, kind, sealed) {
492
- if (!sealed && serverKeyMissing(deps.planeEnv(), { kind, model: launch.model, native: Boolean(launch.native) }))
496
+ * written, never a failure at its first model call. A start with them (the API's) is the sealer's to check. `target`:
497
+ * the run's (run-model-key.ts keyTargetOf), a held run's whose model was refused at its create among them. */
498
+ function keyedOrRefused(deps, target, sealed) {
499
+ if (!sealed && serverKeyMissing(deps.planeEnv(), target))
493
500
  throw modelKeyRequired(false);
494
501
  }
495
502
  /** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
@@ -578,8 +585,10 @@ export async function withHeldFiles(store, deps, runId, agentId, revision, launc
578
585
  knownAbsent = true;
579
586
  }
580
587
  catch { /* preserve preparation until the admission can be resolved */ }
588
+ // A refusal the store gave in the run's own transaction (a host start whose firing was released meanwhile: FiringMoved)
589
+ // wrote nothing, so the run never exists and its preparation goes.
581
590
  if (knownAbsent && (error instanceof StoreConstraint || error instanceof RevisionMoved || error instanceof AgentDeleting
582
- || error instanceof AgentPurged || error instanceof AgentArchived || error instanceof ExternalBodyConflict || error instanceof ApiError))
591
+ || error instanceof AgentPurged || error instanceof AgentArchived || error instanceof ExternalBodyConflict || error instanceof FiringMoved || error instanceof ApiError))
583
592
  await undo(true);
584
593
  throw error;
585
594
  }
@@ -673,7 +682,8 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed, keys
673
682
  // A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
674
683
  // one across.
675
684
  const { launch } = await prepareLaunch(deps, entry, body, { revision: (storedRevision ?? revision), ...(keys ? { keys } : {}) });
676
- keyedOrRefused(deps, launch, (storedRevision ?? revision).kind, sealed);
685
+ const target = keyTargetOf(deps.planeEnv(), launch, storedRevision ?? revision);
686
+ keyedOrRefused(deps, target, sealed);
677
687
  const runId = (deps.newRunId ?? uuidv7)();
678
688
  const labels = labelsOf(body.labels);
679
689
  try {
@@ -681,7 +691,7 @@ async function startInlineOnce(store, deps, inline, body, { origin, sealed, keys
681
691
  agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
682
692
  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 } : {}) },
683
693
  run: { id: runId, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) },
684
- launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, (storedRevision ?? revision).kind) } : {}) },
694
+ launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, target) } : {}) },
685
695
  }));
686
696
  }
687
697
  catch (error) {
@@ -747,17 +757,18 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
747
757
  if (refused !== undefined)
748
758
  throw new ApiError("runner_refused", refused);
749
759
  const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
750
- // Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
751
- // its server could not be listed, is refused with the rest (runnable).
752
- await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined, carried });
753
760
  // A held computer (computer-held.ts): only one that speaks the protocol, its kind as the claim reads it (the
754
- // revision's computer, else its place's).
761
+ // revision's computer, else its place's). Read before the run's check, which defers a held run's model refusal.
755
762
  const hold = holdOf(body, (settingOfDefinition(rbody)?.computer ?? computerOfPlace(place)).kind);
756
763
  if (hold !== undefined && "field" in hold)
757
764
  throw invalid([hold]);
758
765
  // A workflow's loop opens no held computer and takes no start or release: its run holds nothing.
759
766
  if (hold !== undefined && revision.kind === "workflow")
760
767
  throw invalid([{ field: "hold", reason: "not_an_option", message: "hold is for an agent's run: a workflow run does not hold its computer for its owner." }]);
768
+ // Checked as pinned: an earlier revision with no pin is pinned now, once (StartDeps.pinFirst); one that could not be, as
769
+ // its server could not be listed, is refused with the rest (runnable). A held run kept from running by its model alone
770
+ // is not refused: those words ride its hold, for its start to answer (computer-held.ts).
771
+ const modelRefused = await deps.runnable(deps.pinFirst ? await deps.pinFirst(revision) : revision, place, { capped: cap !== undefined, carried, held: hold !== undefined });
761
772
  // The title shows on the run's page, the runs list and Mission Control: built from its input as shown, each held value
762
773
  // redacted before a long one is cut (a cut key could no longer be found).
763
774
  const shown = redactedOutput(input, deps.serverSecrets());
@@ -768,8 +779,9 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
768
779
  // the run carries resolves a tool as one the host holds would.
769
780
  const tooling = await toolingOf(revision);
770
781
  const plane = tooling ? planeFor(withCarried(deps.planeEnv(), carried), tooling, deps.toolSettings(), { capped: cap !== undefined, run: true }) : {};
771
- // The run's model, resolved once, at start (the runner reads launch.model only).
772
- const model = await deps.modelOf(entry, revision);
782
+ // The run's model, resolved once, at start (the runner reads launch.model only). None for a held run whose model was
783
+ // refused: resolving it would throw those words, and its claim takes the stand-in on its revision's model (computer-held.ts).
784
+ const model = modelRefused ? undefined : await deps.modelOf(entry, revision);
773
785
  // The run's Archil disk, chosen now and kept in its launch (run-launch.ts archilDisk): the one the body names (a disk per
774
786
  // customer), else its agent's when it has one; with neither, its claim makes the agent's.
775
787
  const named = isObject(body.archil_disk) && typeof body.archil_disk.disk_id === "string" ? body.archil_disk.disk_id : undefined;
@@ -815,7 +827,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
815
827
  ...(from ? { inputOrigin: from } : {}),
816
828
  ...(model ? { model } : {}),
817
829
  ...(archilDisk ? { archilDisk } : {}),
818
- ...(hold ? { hold } : {}),
830
+ ...(hold ? { hold: modelRefused ? { ...hold, refused: modelRefused } : hold } : {}),
819
831
  };
820
832
  return { launch, revision };
821
833
  }
@@ -0,0 +1,73 @@
1
+ import type { SignInReader } from "./run-view.js";
2
+ import { type Store } from "./store/index.js";
3
+ /** The kinds of cut, in the order they are printed (secret-rules.ts CutKind). */
4
+ export declare const CUT_KINDS: readonly ["format", "held", "dump", "label", "personal", "jev"];
5
+ type Kind = (typeof CUT_KINDS)[number];
6
+ /** The run view's fields a share carries (share-design §1, the `run` allowlist, store-view.ts viewOfRun); every other
7
+ * field is dropped. `imported_from` carries its `source` alone. */
8
+ export declare const SHARE_RUN_FIELDS: readonly ["kind", "status", "state", "title", "created_at", "ended_at", "result", "error", "review", "cost", "stopped_for", "budget_refused_calls", "effort", "approvals"];
9
+ /** The reads a share's text is gathered by: the run's one cut (run-cut.ts runCutValues) and what serves under it. */
10
+ export interface ShareTextDeps {
11
+ readonly serverSecrets: () => string[];
12
+ readonly signIns?: SignInReader;
13
+ /** The store's seal key, undefined when it has none: the run's sealed launch values are read under it (run-cut.ts). */
14
+ readonly sealKey: Buffer | undefined;
15
+ readonly keyEnv: () => NodeJS.ProcessEnv;
16
+ }
17
+ /** Every string in a JSON value, its object keys included (a key can hold a value: a header's name a tool printed, a
18
+ * map keyed by a command line). */
19
+ export declare function stringsOf(value: unknown): string[];
20
+ /** A tool's output with its call's context (ruling LVI): the file the call read whole (`path`) or the shell command it
21
+ * ran (`command`), so the scrubber reads a credential file's or a dump command's output as the dump it is, though the
22
+ * output stands alone in its result's field. A share's export reads the same (secret-cut.ts ScrubOptions). */
23
+ export interface ShareText {
24
+ readonly text: string;
25
+ readonly path?: string;
26
+ readonly command?: string;
27
+ }
28
+ /** What a share of run `runId` would carry, as strings (object keys included: stringsOf), a tool's output with its
29
+ * call's context (ShareText), with the run's cut set read after them (the cut only grows, so the last read holds every
30
+ * value an earlier read cut); `unknown` for a run the store does not hold, `withheld` when its cut can't be read here. */
31
+ export declare function shareTexts(store: Store, runId: string, deps: ShareTextDeps): Promise<{
32
+ kind: string;
33
+ texts: (string | ShareText)[];
34
+ held: string[];
35
+ } | "unknown" | "withheld">;
36
+ /** One rule's line of the count. */
37
+ export interface RuleCount {
38
+ readonly rule: string;
39
+ readonly kind: string;
40
+ readonly restorable: boolean;
41
+ readonly count: number;
42
+ }
43
+ /** The count `scrub` prints: by rule, by kind, the cuts a share would make and how many of them could be restored, and
44
+ * how many `[redacted]` marks the served text holds already (known key formats and held values the server's own cut takes
45
+ * out where it serves the run, run-view.ts shownOf, or keys an import took out before). */
46
+ export interface ShareCount {
47
+ readonly run_id: string;
48
+ readonly kind: string;
49
+ readonly strings: number;
50
+ readonly rules: RuleCount[];
51
+ readonly by_kind: Record<Kind, number>;
52
+ readonly cuts: number;
53
+ readonly restorable: number;
54
+ readonly already_redacted: number;
55
+ /** Whether a share would be refused: cut mode fails closed on one of the strings (its final check finds a held value or
56
+ * a format left once cut), so no share of this run is made until a rule cuts it. */
57
+ readonly blocked: boolean;
58
+ }
59
+ /** The scrubber's count over `texts` with `held` as its held values, a ShareText with its call's context: each cut's
60
+ * rule, kind and whether it can be restored, never its value, shape or offsets. */
61
+ export declare function countCuts(runId: string, kind: string, texts: readonly (string | ShareText)[], held: readonly string[]): Promise<ShareCount>;
62
+ /** The count as a table: one line per rule, totals by kind, and the line that says what a share would cut. */
63
+ export declare function countTable(count: ShareCount): string;
64
+ /** The line that says a run could not be counted: the error's own words, cut by the scrubber first with `held` as its
65
+ * held values (a store's error could quote what it read, a held value among it), else withheld. */
66
+ export declare function couldNotCount(runId: string, error: unknown, held: readonly string[]): Promise<string>;
67
+ /** `agentrun-serve scrub RUN [--data DIR] [--json]`: the exit code (the file's head). Output goes to `out`, words about
68
+ * why nothing was counted to `err`. */
69
+ export declare function scrubMain(argv: readonly string[], usage: string, io?: {
70
+ out: (line: string) => void;
71
+ err: (line: string) => void;
72
+ }): Promise<number>;
73
+ export {};