@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
@@ -22,7 +22,7 @@ import { putLiveViewer, dropLiveViewer } from "../browser-live.js";
22
22
  import { CALENDAR_EVENTS } from "../calendar/names.js";
23
23
  import { openCalendar } from "../calendar/address.js";
24
24
  import { openAccount } from "../email/account.js";
25
- import { harnessOf } from "../harness-table.js";
25
+ import { harnessOf, recipeHarness } from "../harness-table.js";
26
26
  import { installDirOf, installForClaim, shareInstall } from "../harness-install.js";
27
27
  import { loadArchilSettings } from "../archil-settings.js";
28
28
  import { planOf } from "../chatgpt-plan.js";
@@ -31,7 +31,7 @@ import { vendorsOver } from "../sign-ins.js";
31
31
  import { decisionProvidersIn, fauxFetch } from "../decisions.js";
32
32
  import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
33
33
  import { learningEndOfRun } from "./learning-end.js";
34
- import { runnerSecrets } from "./redact.js";
34
+ import { cutDeep, heldRedactor, runnerSecrets } from "./redact.js";
35
35
  import { storeSecrets } from "./store-secrets.js";
36
36
  import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
37
37
  import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
@@ -58,10 +58,10 @@ import { withAudit } from "./audit.js";
58
58
  import { compareEndOfRun } from "./compare-end.js";
59
59
  import { learnedFirst } from "./learned-first.js";
60
60
  import { workflowsAt } from "./learning-seed.js";
61
- import { heldMcpOf, mcpForClaim, mediaForClaim } from "./mcp-run.js";
61
+ import { heldMcpOf, mcpForClaim } from "./mcp-run.js";
62
62
  import { learnedTiers, learnsWorkflows, mcpReachOf } from "./adapter-run-spec.js";
63
63
  import { createDispatchLoop } from "./dispatch.js";
64
- import { resolveRunnerLoop, withSavedGatewayDeps } from "./harness-loops.js";
64
+ import { refuseRecipeTriggerRun, resolveRunnerLoop, withSavedGatewayDeps } from "./harness-loops.js";
65
65
  import { isWorkflowRevision } from "./workflow-loop.js";
66
66
  import { loginForRun } from "../claude-login.js";
67
67
  import { heardComputerHold } from "./computer-journal.js";
@@ -73,6 +73,12 @@ import { runBigWrites } from "./big-writes.js";
73
73
  import { SERVER_SLOTS } from "../web-save.js";
74
74
  import { launchOnItsDisk, readLaunchBody } from "../run-launch.js";
75
75
  import { SUBAGENT_TOOL } from "./subagent.js";
76
+ import { sourceSyncOf } from "../source-sync/types.js";
77
+ import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
78
+ import { beginSourceIO } from "../source-sync/io.js";
79
+ import { runTools } from "../workspace/run-tools.js";
80
+ import { ProjectHostGate } from "./project-host.js";
81
+ import { runProjectCheckpoint } from "./project-checkpoint.js";
76
82
  /** The image's helper that starts a run's process as its slot's uid (packages/serve/runas). */
77
83
  export const RUNAS_HELPER = "/usr/local/bin/agentrun-runas";
78
84
  /** `same`: every run runs as the runner's own user, the helper unused, said in the runner's log. */
@@ -106,6 +112,9 @@ const execText = (file, args, timeoutMs) => new Promise((resolve) => {
106
112
  resolve({ code: -1, stdout: "", stderr: error?.message ?? String(error) });
107
113
  }
108
114
  });
115
+ /** Whether runIsolationOf gives `env` on this host `process` (every run as the runner's own user), told before it is
116
+ * asked: `same`, or no helper and not `slot`. A helper that is there but cannot switch refuses the runner instead. */
117
+ export const runsAsOwnUser = (env, helper = RUNAS_HELPER) => env[RUN_USER_ENV] === "same" || (!existsSync(helper) && env[RUN_USER_ENV] !== "slot");
109
118
  /** This host's isolation for `loops` runs at once, by `env` and the helper: the helper's own check that it can switch
110
119
  * (its effective set holds what it needs) decides `uid`; none installed (a local install), `process`; `same`, `process`
111
120
  * said in the log. A helper that cannot switch is refused in words naming the setting, never a quiet fall back. `loops`
@@ -363,24 +372,6 @@ export function dataOnly(value, seen = new Set()) {
363
372
  seen.delete(value);
364
373
  }
365
374
  }
366
- /** Every string inside `value` cut by `cut`: what the run's process writes, as the runner's redactor would cut it in a
367
- * loop of its own (rule three: no secret the runner holds is written). */
368
- export function cutDeep(value, cut) {
369
- if (typeof value === "string")
370
- return cut(value);
371
- if (value === null || typeof value !== "object")
372
- return value;
373
- if (ArrayBuffer.isView(value) || value instanceof Date || value instanceof RegExp || value instanceof ArrayBuffer)
374
- return value;
375
- if (Array.isArray(value))
376
- return value.map((item) => cutDeep(item, cut));
377
- if (value instanceof Map)
378
- return new Map([...value].map(([k, v]) => [k, cutDeep(v, cut)]));
379
- const out = {};
380
- for (const key of Object.keys(value))
381
- Object.defineProperty(out, key, { value: cutDeep(value[key], cut), enumerable: true, writable: true, configurable: true });
382
- return out;
383
- }
384
375
  const ownRun = (args, bound) => args[0] === bound.claim.runId;
385
376
  /** The claim's run, or its own audit's shadow run, whose spend its cap gates read beside it (learning-end.ts besideOf). */
386
377
  const ownRunOrShadow = (args, bound) => args[0] === bound.claim.runId || args[0] === shadowRunId(bound.claim.runId);
@@ -569,8 +560,52 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
569
560
  const sealKey = deps.sealKey;
570
561
  const store = deps.store;
571
562
  const granted = revision.body.tools ?? [];
563
+ const admitAuxiliary = sourceAuxiliaryAdmitter(store, { data: deps.data, sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
572
564
  const keys = { store, sealKey, env: deps.env };
573
565
  const releases = [() => bigs.close()];
566
+ const source = sourceSyncOf(revision.body), placed = launch.sourceProject;
567
+ const moved = !!source && !!placed && source.id === placed.sourceId && source.project === placed.digest && placed.baselineRevision === run.revisionId;
568
+ const projectGate = moved ? new ProjectHostGate() : undefined;
569
+ const projectStop = new AbortController();
570
+ const projectSignal = reads.signal ? AbortSignal.any([reads.signal, projectStop.signal]) : projectStop.signal;
571
+ let projectIO, projectCapture;
572
+ let projectComputer, projectWorkspace, projectMode = 1;
573
+ let projectFailed = false, projectReleased = false, projectClosing = false, projectCaptureDone = false;
574
+ let projectRelease;
575
+ let projectCleanup;
576
+ const projectOwns = async (settlingAudit = false) => {
577
+ projectSignal.throwIfAborted();
578
+ const row = await store.runs.get(claim.runId);
579
+ // A never-waiting audit journals its Ask/cap as parked before terminalizing under this same claim. Only its
580
+ // checkpoint may finish from that state; ordinary held calls still require running, and claim identity is exact.
581
+ const settlingParkedAudit = settlingAudit && launch.audit !== undefined && row?.state === "parked";
582
+ if (!row || row.agentId !== run.agentId || row.revisionId !== run.revisionId || row.epoch !== claim.epoch || row.runner !== claim.runner || row.state !== "running" && !settlingParkedAudit)
583
+ throw new ClaimRefused("This project checkpoint no longer holds its original run claim.");
584
+ };
585
+ const ownProject = async (settlingAudit = false) => {
586
+ if (!projectGate)
587
+ return;
588
+ await projectOwns(settlingAudit);
589
+ await (projectIO ??= beginSourceIO(store, run.agentId, "snapshot"));
590
+ };
591
+ const projectCall = (work) => projectGate ? projectGate.run(async () => { await ownProject(); return work(); }) : work();
592
+ const projectWorkSettled = async () => { await projectCapture; await projectGate?.drain(); };
593
+ const projectSettled = async () => { await projectWorkSettled(); await projectCleanup?.catch(() => undefined); };
594
+ /** Cleanup closes capture admission synchronously. A capture already admitted finishes first; one arriving later
595
+ * cannot use resources being relinquished. Cleanup itself remains owned and is awaited by the host's release. */
596
+ const cleanProject = (work) => {
597
+ if (!projectGate)
598
+ return work();
599
+ if (projectReleased)
600
+ return Promise.reject(new ClaimRefused("This claim's project resources have already been released."));
601
+ projectClosing = true;
602
+ projectGate.close();
603
+ const previous = projectCleanup;
604
+ const pending = (async () => { await previous?.catch(() => undefined); await projectWorkSettled(); return work(); })();
605
+ projectCleanup = pending;
606
+ void pending.catch(() => { projectFailed = true; });
607
+ return pending;
608
+ };
574
609
  const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
575
610
  const github = () => githubAppAccess(store, sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
576
611
  /** Mode 2's Archil claim, made once for the claim on the runner, its folder the run's. */
@@ -603,6 +638,62 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
603
638
  /** The claim's one learned first choice: its promotion's writes are made once, however often the process asks. */
604
639
  let chosen;
605
640
  const held = {
641
+ projectCheckpoint: (...args) => {
642
+ if (args.length > 1 || args[0] !== undefined && !(args[0] instanceof AbortSignal))
643
+ throw new ClaimRefused("A project checkpoint accepts only its cancellation signal.");
644
+ if (!projectGate || !placed || !source)
645
+ throw new ClaimRefused("This claim has no matching placed source project.");
646
+ if (projectReleased)
647
+ throw new ClaimRefused("This claim's project resources have already been released.");
648
+ if (projectCapture)
649
+ return projectCapture;
650
+ if (projectClosing)
651
+ throw new ClaimRefused("This claim's project resources are closing for cleanup.");
652
+ projectGate.close();
653
+ const signal = args[0] ? AbortSignal.any([projectSignal, args[0], AbortSignal.timeout(60_000)]) : AbortSignal.any([projectSignal, AbortSignal.timeout(60_000)]);
654
+ const uncertain = () => ({ version: 1, status: "uncertain", sourceId: source.id, runId: claim.runId, epoch: claim.epoch, reason: "project_not_settled", stage: "drain" });
655
+ projectCapture = (async () => {
656
+ let checkpoint;
657
+ let tools;
658
+ let result;
659
+ try {
660
+ await projectGate.drain();
661
+ await ownProject(true);
662
+ signal.throwIfAborted();
663
+ await projectOwns(true);
664
+ if (projectGate.uncertain)
665
+ throw new ClaimRefused("An earlier project operation has an unresolved outcome.");
666
+ if (!projectComputer || !projectWorkspace)
667
+ throw new ClaimRefused("The project's held execution resources are unavailable.");
668
+ checkpoint = runProjectCheckpoint({ store, agentId: run.agentId, claim, launch, computer: projectComputer, ioHeld: true,
669
+ tools: { get workspace() { if (!tools)
670
+ throw new ClaimRefused("Project settlement has not opened its workspace."); return tools.workspace; },
671
+ settleProject: async () => { tools = await runTools(projectWorkspace, projectComputer.computer, { mode: projectMode, context: BACKGROUND_CONTEXT }); return tools.settleProject(); } },
672
+ workspace: { data: deps.data, sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } },
673
+ secrets: async () => runnerSecrets(deps.env, [...runnerSecrets(claimed), ...await storeSecrets(store, sealKey, deps.data)]), });
674
+ result = await checkpoint.capture(signal);
675
+ signal.throwIfAborted();
676
+ await projectOwns(true);
677
+ if (result.status !== "candidate" && result.status !== "discarded" && !checkpoint.refusalSettled())
678
+ projectFailed = true;
679
+ }
680
+ catch {
681
+ projectFailed = true;
682
+ result = checkpoint?.uncertain() ?? uncertain();
683
+ }
684
+ finally {
685
+ try {
686
+ await tools?.end();
687
+ }
688
+ catch {
689
+ projectFailed = true;
690
+ result = { ...uncertain(), reason: "project_capture_failed", stage: "cleanup" };
691
+ }
692
+ }
693
+ return result;
694
+ })().finally(() => { projectCaptureDone = true; });
695
+ return projectCapture;
696
+ },
606
697
  plan: async () => {
607
698
  const plan = planOf(claimed);
608
699
  if (!plan)
@@ -615,15 +706,16 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
615
706
  return runSignIn(store, sealKey, claim, String(resolution), { vendors: vendorsOver(() => claimed, vendorFetch), log });
616
707
  },
617
708
  verifySignIn: (kept, at) => verifyRunSignIn(store, sealKey, claim, kept, Number(at)),
618
- mcp: async (ask) => {
709
+ mcp: (ask) => projectCall(async () => {
619
710
  const reach = await mcpReachOf(deps);
620
711
  const harness = { commit: (change) => change({ appendEntry: async (_conversation, entry) => void (await ask.appendRoot(dataOnly(entry))) }) };
621
- const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: () => launch.maxCostUsd !== undefined, media: mediaForClaim(deps.env, deps.evalFakes?.(run.agentId)?.web, deps.saveSlots) });
712
+ const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(run.agentId)?.web, slots: deps.saveSlots } });
622
713
  if (!made)
623
714
  return undefined;
624
715
  releases.push(() => made.release());
625
- return heldMcpOf(made, cut);
626
- },
716
+ const exposed = heldMcpOf(made, cut);
717
+ return projectGate ? projectGate.capability(exposed) : exposed;
718
+ }),
627
719
  githubAppAccess: async () => {
628
720
  // A run's process mints for one thing alone: its revision's pull-request checkout (pr-checkout.ts), of the pull
629
721
  // request its launch's payload names, contents read. Its MCP mints on the runner (mcp above). So the mint handed
@@ -702,7 +794,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
702
794
  // install from before installs were shared too.
703
795
  await shareInstall(installDirOf(deps.data, harness));
704
796
  },
705
- computer: async (ask) => {
797
+ computer: (ask) => projectCall(async () => {
706
798
  const made = await archilOf();
707
799
  const mode = made === undefined ? 1 : 2;
708
800
  const ws = made === undefined
@@ -726,17 +818,27 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
726
818
  const claimed = got;
727
819
  if (typeof claimed?.release === "function")
728
820
  releases.push(() => claimed.release("ended"));
821
+ if (projectGate) {
822
+ projectComputer = got;
823
+ projectWorkspace = ws.workspace;
824
+ projectMode = mode;
825
+ const { syncProject: _sync, ...exposed } = got;
826
+ return { ...exposed, ...(exposed.computer ? { computer: projectGate.capability(exposed.computer) } : {}),
827
+ release: (...args) => cleanProject(() => exposed.release(...args)),
828
+ ...(exposed.park ? { park: (...args) => cleanProject(() => exposed.park(...args)) } : {}) };
829
+ }
729
830
  return got;
730
- },
731
- archil: async () => {
831
+ }),
832
+ archil: () => projectCall(async () => {
732
833
  const made = await archilOf();
733
834
  if (made === undefined)
734
835
  return undefined;
735
836
  const ws = await openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: made, log });
736
837
  releases.push(() => ws.end());
737
838
  // A write bigger than the channel's frame is pulled in pieces and written here, on this Workspace (big-writes.ts).
738
- return { workspace: ws.workspace, pieces: bigs.pieces(ws.workspace), revoke: () => made.revoke(), inherit: async () => made.inherit(), release: async () => { } };
739
- },
839
+ return { workspace: projectGate ? projectGate.capability(ws.workspace) : ws.workspace, pieces: projectGate ? projectGate.capability(bigs.pieces(ws.workspace)) : bigs.pieces(ws.workspace),
840
+ revoke: () => cleanProject(() => made.revoke()), inherit: () => projectCall(async () => made.inherit()), release: async () => { } };
841
+ }),
740
842
  endOfRun: async (input) => {
741
843
  // The step as the run's spec builds it in a runner (adapter-run-spec.ts), over the runner's reads of the claim: what
742
844
  // the run must never learn is every secret this runner holds, the keys its claim handed it, every secret the server
@@ -767,7 +869,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
767
869
  log,
768
870
  decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys(keys, DECISION_PROVIDER_KEYS)) }),
769
871
  learningFolder: made === undefined ? (agentId) => learningFolderOf(deps.data, agentId) : (agentId) => learningWorkspace({ mode: "archil", agentId, archil: made }),
770
- }), { store, agentId: run.agentId, revisionId: run.revisionId, context: BACKGROUND_CONTEXT, folder: await folderNow(), shown, log, sealKey, spendOff, launch, redact: cut });
872
+ }), { store, agentId: run.agentId, revisionId: run.revisionId, context: BACKGROUND_CONTEXT, folder: await folderNow(), shown, log, sealKey, spendOff, launch, redact: cut, admitAuxiliary });
771
873
  if (!step)
772
874
  return undefined;
773
875
  // keptOf is the run's process's, asked over the channel: read once, for the round learningEndOfRun reads (the
@@ -795,10 +897,10 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
795
897
  // workflows).
796
898
  const start = learningStartOf(launch);
797
899
  const folder = await folderNow();
798
- const laid = ask?.laid === true && start && !seedFailed(start) && !start.noWorkflows ? await workflowsAt({ folder, shown }, start.seed).catch(() => []) : [];
900
+ const laid = ask?.laid === true && start && !seedFailed(start) && !start.noWorkflows ? await workflowsAt({ folder, store, shown }, start.seed).catch(() => []) : [];
799
901
  const spendOff = await claimSpendOff(keys, await claimModelKey(keys, claim.runId));
800
902
  const outputSchema = revision.body.outputSchema;
801
- const got = await learnedFirst({ store, sealKey, agentId: run.agentId, runId: claim.runId, revisionId: run.revisionId, kind: revision.kind, ...(outputSchema !== undefined ? { outputSchema } : {}), launch, context: BACKGROUND_CONTEXT, log, folder, shown, spendOff }, laid);
903
+ const got = await learnedFirst({ store, sealKey, agentId: run.agentId, runId: claim.runId, revisionId: run.revisionId, kind: revision.kind, ...(outputSchema !== undefined ? { outputSchema } : {}), launch, context: BACKGROUND_CONTEXT, log, folder, shown, spendOff, admitAuxiliary }, laid);
802
904
  learnedFlows = got.workflows;
803
905
  return cutDeep(dataOnly(got), cut);
804
906
  })()),
@@ -812,7 +914,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
812
914
  };
813
915
  return {
814
916
  held,
815
- inputs: async () => {
917
+ inputs: () => projectCall(async () => {
816
918
  // The run's uploads and its opening message (uploads.ts placeRunInputs), placed by this runner before the run's
817
919
  // process starts: their hold is the server's alone.
818
920
  const made = await archilOf();
@@ -825,11 +927,24 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
825
927
  finally {
826
928
  await ws.end();
827
929
  }
828
- },
829
- release: async () => {
930
+ }),
931
+ release: () => projectRelease ??= (async () => {
932
+ projectReleased = true;
933
+ projectGate?.close();
934
+ await projectSettled();
935
+ let failed = false;
830
936
  for (const release of releases.reverse())
831
- await Promise.resolve(release()).catch((error) => log(`run ${claim.runId}: a release on its runner failed: ${error?.message ?? error}`));
832
- },
937
+ await Promise.resolve(release()).catch((error) => { failed = true; log(`run ${claim.runId}: a release on its runner failed: ${error?.message ?? error}`); });
938
+ if (projectIO && !failed && !projectFailed && !projectGate?.uncertain && !projectSignal.aborted)
939
+ await (await projectIO).settled();
940
+ })(),
941
+ ...(projectGate ? { projectEnd: async () => {
942
+ if (projectCapture && !projectCaptureDone)
943
+ projectStop.abort(new Error("The project host is ending."));
944
+ projectReleased = true;
945
+ projectGate.close();
946
+ await projectSettled();
947
+ } } : {}),
833
948
  };
834
949
  }
835
950
  /** `env`'s string values. */
@@ -889,6 +1004,9 @@ export const childArgv = () => [process.execPath, "--import", new URL("../secret
889
1004
  export const runsInRunner = (harness, launch) => harness === "learning" || Boolean(launch.sdk) || Boolean(launch.native) || Boolean(launch.cli_learning);
890
1005
  /** The words a run on Claude Code's login on this machine is refused in where each run is a user of its own. */
891
1006
  export const LOGIN_NEEDS_SERVER_USER = `A run on Claude Code's login on this machine needs runs under the server's own user, and this runner runs each run as a user of its own: set ${RUN_USER_ENV}=same, or give the run a model_key.`;
1007
+ /** The words a run on a harness recipe is refused in where each run is a user of its own (harness-table.ts recipeHarness). */
1008
+ export const RECIPE_NEEDS_SERVER_USER = `A run on a harness recipe needs runs under the server's own user, since its install, its check and its owner's sign-in are that user's alone, and this runner runs each run as a user of its own: set ${RUN_USER_ENV}=same on this runner.`;
1009
+ export { RECIPE_SIGN_IN_PERSON_ONLY } from "./harness-loops.js";
892
1010
  /** Whether run `runId` stays in its runner's process: runsInRunner's, and a workflow run on a server with a documents
893
1011
  * directory (launch.documents), whose reads and writes (a pdf_pages call's pages) are rooted in a folder the server's
894
1012
  * user holds and no slot's user is given; its nodes run the server's own tools alone, no agent's code. A run on Claude
@@ -898,6 +1016,12 @@ export const LOGIN_NEEDS_SERVER_USER = `A run on Claude Code's login on this mac
898
1016
  * the server's user. A run its caller handed a model key (model_key) runs on that key and never on the login
899
1017
  * (cli-run-spec.ts), so it is a process of its own like any other. */
900
1018
  export async function staysInRunner(deps, harness, launch, runId, isolation) {
1019
+ // A recipe's harness reads its install, its check's note and its owner's sign-in, each the server user's alone: never
1020
+ // opened to a slot's user (the sign-in least of all), so where each run is a user of its own it is refused here. And a
1021
+ // plan-billed one's run that no person started (a schedule's, a trigger's) never runs on its owner's sign-in.
1022
+ if (isolation.kind === "uid" && recipeHarness(deps.env ?? {}, harness))
1023
+ throw new ClaimRefused(RECIPE_NEEDS_SERVER_USER);
1024
+ refuseRecipeTriggerRun(deps.env ?? {}, harness, launch);
901
1025
  if (runsInRunner(harness, launch))
902
1026
  return true;
903
1027
  if (launch.documents !== undefined) {
@@ -1031,9 +1155,14 @@ function childLoop(options, slots, loopDeps) {
1031
1155
  // in this process has it laid (harness-loops.ts): the run's process reads no store row of it and holds no seal key.
1032
1156
  const claimDeps = await withSavedGatewayDeps(deps);
1033
1157
  const claimEnv = claimDeps.env ?? {};
1158
+ // Refuse before taking a slot: even a slot's final reap normalizes modes in its run folders.
1159
+ if (launch.sourceProject && isolation.kind === "uid" && !await loadArchilSettings(deps.store, claimEnv)) {
1160
+ ready();
1161
+ throw new ClaimRefused("project_mode_fidelity: This runner rewrites local project file permissions for per-user isolation. A moved project needs a destination that preserves its original permissions.");
1162
+ }
1034
1163
  const savedGateway = savedGatewayIn(claimEnv);
1035
1164
  // The run's own keys: those its claim opens (claim-secrets.ts), the one list its loop in this process read.
1036
- const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, launch);
1165
+ const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact ? heldRedactor(loopDeps.redact) : undefined }, revisionRow, launch, claim.runId);
1037
1166
  // With them, its revision's own model's (a launch pinned at its start to another model, a --faux start's, is still
1038
1167
  // handed its agent's model's key, as a run's own process was handed it before: run-secrets.ts secretsFor).
1039
1168
  const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
@@ -1072,7 +1201,7 @@ function childLoop(options, slots, loopDeps) {
1072
1201
  const tops = runTops(deps.data, runRow.agentId, claim.runId);
1073
1202
  // The run's pieced writes (big-writes.ts): let go when its channel ends, or at the claim's release.
1074
1203
  const bigs = runBigWrites();
1075
- const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed }, cut, log, bigs);
1204
+ const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed, signal: loopDeps.signal }, cut, log, bigs);
1076
1205
  try {
1077
1206
  let extra = {};
1078
1207
  let argv = [...(options.argv ?? childArgv())];
@@ -1167,6 +1296,7 @@ function childLoop(options, slots, loopDeps) {
1167
1296
  }
1168
1297
  finally {
1169
1298
  ready();
1299
+ await heldSide.projectEnd?.();
1170
1300
  const reaped = await end(slot, tops).catch((error) => {
1171
1301
  log(`run ${claim.runId}: its process's end failed: ${error?.message ?? error}`);
1172
1302
  return false;
@@ -9,7 +9,7 @@ import { LaunchUnreadable, UnknownHarness } from "./dispatch.js";
9
9
  import { NeverFits } from "./harness-loops.js";
10
10
  import { ClaimRefused } from "./loop-contract.js";
11
11
  import { McpClaimRefused } from "./mcp-claim.js";
12
- import { registerErrors } from "./run-channel.js";
12
+ import { FrameTooLarge, registerErrors } from "./run-channel.js";
13
13
  import { ClaimLost } from "./runner.js";
14
14
  /** Registers every error class a run's process and its runner hand each other (run-channel.ts registerErrors). */
15
15
  export function registerRunErrors() {
@@ -17,6 +17,6 @@ export function registerRunErrors() {
17
17
  ClaimRefused, NeverFits, McpClaimRefused, ClaimLost, UnknownHarness, LaunchUnreadable,
18
18
  Fenced, CommandTaken, RunFinal, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreLaunchMissing, StoreWorkerLost, Unanswered,
19
19
  ConversationBusy, ConversationIdle, ReadAfterWrite, ReadOnlySession, SessionFailed, StorageRequestError,
20
- WorkspaceError,
20
+ WorkspaceError, FrameTooLarge,
21
21
  });
22
22
  }
@@ -21,20 +21,21 @@ import { ARCHIL_SETTINGS_ENV } from "../archil-settings.js";
21
21
  import { BOX_ALLOW_ENV } from "../box-settings.js";
22
22
  import { TOOL_KEY_ROWS } from "../key-words.js";
23
23
  import { PRIVATE_HOSTS_ENV } from "../mcp-private-hosts.js";
24
- import { HARNESS_MODULES_SETTING } from "../harness-table.js";
24
+ import { HARNESS_MODULES_SETTING, HARNESS_RECIPES_SETTING } from "../harness-table.js";
25
25
  import { GATEWAY_IDS_ENV } from "../model-gateway.js";
26
26
  import { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV, MCP_ALLOW_LOOPBACK_ENV } from "../start-switches.js";
27
27
  import { DOCKER_IMAGE_ENV } from "../box-image.js";
28
28
  import { bootSealKey } from "../seal-key.js";
29
29
  import { SECRET_NAMES } from "../secrets.js";
30
30
  import { SEAL_KEY_ENV } from "../tool-keys.js";
31
+ import { LAUNCH_HOOK_SECRET_ENV } from "../trigger-launch-hook.js";
31
32
  /** The store.settings key a server keeps the names of its run-facing environment under at each start: `{ v: 1, names }`. */
32
33
  export const RUN_ENV_KEY = "server.run_env";
33
34
  export const STORE_URL_ENV = "AGENTRUN_STORE_URL";
34
35
  /** The most connections a Postgres store holds at once; its start refuses a value that is no size (store/open.ts). */
35
36
  const POOL_SIZE_ENV = "AGENTRUN_STORE_POOL_SIZE";
36
37
  /** The server's own secrets: never a runner's (runner/main.ts RUNNER_ONLY keeps them from its runs, too). */
37
- const SERVER_ONLY = ["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY"];
38
+ const SERVER_ONLY = ["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY", LAUNCH_HOOK_SECRET_ENV];
38
39
  /** Names that are neither the server's run-facing environment nor the runner's: its own store and key (checked on their
39
40
  * own), the server's secrets, and a client's address of the server. */
40
41
  const NOT_RUN_FACING = new Set([...SERVER_ONLY, STORE_URL_ENV, SEAL_KEY_ENV, "AGENTRUN_BASE_URL"]);
@@ -61,6 +62,8 @@ const FIXED = new Set([
61
62
  // The harness modules a server loads (harness-table.ts): a runner without them claims their runs and has no harness to
62
63
  // run them on.
63
64
  HARNESS_MODULES_SETTING,
65
+ // And the harness recipes it runs (harness-table.ts), for the same reason.
66
+ HARNESS_RECIPES_SETTING,
64
67
  // A Docker computer's image and size (box-image.ts, workspace/computer-deps.ts dockerLimitsOf): read where the run's
65
68
  // computer starts, the runner.
66
69
  DOCKER_IMAGE_ENV,
@@ -18,11 +18,12 @@ import { HAND_BACK } from "./hand-back.js";
18
18
  import { KINDS, withdrawnAnswers } from "./journal-kinds.js";
19
19
  import { journalEntries } from "./journal-reader.js";
20
20
  import { ClaimRefused, stopEnd } from "./loop-contract.js";
21
+ import { FrameTooLarge } from "./run-channel.js";
21
22
  import { isFenced } from "./store-port.js";
22
23
  import { FINAL_STATES } from "../store/store.js";
23
24
  import { Unanswered } from "../store/postgres/connection.js";
24
25
  import { clearWaitEnded } from "../browser-wait-ended.js";
25
- import { heldRedactor, processSecretRedactor } from "./redact.js";
26
+ import { cutDeep, heldRedactor, processSecretRedactor } from "./redact.js";
26
27
  import { withLiveTicker } from "./live-ticker.js";
27
28
  import { keepPresence } from "./presence.js";
28
29
  /** Tries of the re-read after a claim or release commit was answered Unanswered (the commit may have landed). */
@@ -49,6 +50,9 @@ export const RUNNER_RENEW_EVERY_MS = 10_000;
49
50
  export const runnerName = () => `${hostname()}:${process.pid}:${randomUUID().slice(0, 8)}`;
50
51
  /** A failed end's code when the claim was refused for good before any loop started (loop-contract's ClaimRefused). */
51
52
  const CLAIM_REFUSED = "claim-refused";
53
+ /** A failed end's code when the run's records no longer cross the channel to its process (run-channel's FrameTooLarge):
54
+ * every try reads the same records, so none can go on. */
55
+ const TOO_LARGE = "frame-too-large";
52
56
  /** The untaken row a run ends on when no loop can: a cancel before a stop (it ends the run for good, in its words). */
53
57
  const endingRow = (untaken) => untaken.find((row) => row.kind === "cancel") ?? untaken.find((row) => row.kind === "stop");
54
58
  /** A commit by a loop whose claim this runner gave up: refused before it reaches the store. */
@@ -166,10 +170,16 @@ export function startRunner(options) {
166
170
  * then the run is ending, before the loop's teardown, so a renew answered Fenced by that end's epoch is never a lost
167
171
  * claim. The patch lands exactly when the batch that writes its effect (the record it is staged with) is stored
168
172
  * (RunStorage.commit): a group commit stores its batches in order up to the first it refuses, so the end's batch can
169
- * land while a later sibling is refused, and an end whose own batch is refused has not landed. */
173
+ * land while a later sibling is refused, and an end whose own batch is refused has not landed. What it writes and
174
+ * stages is cut of the run's own tool keys (redact.ts carry), its names too: they are erased at its turn's end, so no
175
+ * read could. */
170
176
  const fenced = (journal, fence, runId, ended) => {
171
177
  /** The effect of the final patch staged and not yet landed, as the store keeps it until a commit stores it. */
172
178
  let finalEffect;
179
+ const carriedOut = (given) => {
180
+ const carried = redact.carried(runId);
181
+ return carried ? cutDeep(given, carried, true) : given;
182
+ };
173
183
  return new Proxy(journal, {
174
184
  get(target, property) {
175
185
  const value = Reflect.get(target, property, target);
@@ -177,7 +187,7 @@ export function startRunner(options) {
177
187
  return value;
178
188
  if (property === "stage") {
179
189
  return (staged, ...rest) => {
180
- const result = value.call(target, staged, ...rest);
190
+ const result = value.call(target, carriedOut(staged), ...rest);
181
191
  // As the store keeps it: a run patch or rows staged again replace the one staged before.
182
192
  if (staged?.run !== undefined || staged?.also !== undefined)
183
193
  finalEffect = FINAL.has(staged.run?.state ?? "") ? Number(staged.effect) : undefined;
@@ -194,7 +204,7 @@ export function startRunner(options) {
194
204
  const effect = finalEffect;
195
205
  const batches = (Array.isArray(args[0]) ? args[0] : [args[0]]);
196
206
  const at = effect === undefined ? -1 : batches.findIndex((batch) => (Array.isArray(batch) ? batch : [batch]).some((write) => Number(write?.value?.id) === effect));
197
- return value.apply(target, args).then((result) => {
207
+ return value.apply(target, [carriedOut(args[0]), ...args.slice(1)]).then((result) => {
198
208
  if (at >= 0 && at < (result?.stored ?? 0) && finalEffect === effect) {
199
209
  finalEffect = undefined;
200
210
  ended();
@@ -576,8 +586,10 @@ export function startRunner(options) {
576
586
  // with why, and a person can raise again or stop it (#1944-5). A claim its spec refuses (ClaimRefused: a handed
577
587
  // sign-in that won't read back, an MCP pin refused) never comes here: the loop writes that end itself, final, the run
578
588
  // failed in the refusal's words.
579
- // A claim refused for good (CLAIM_REFUSED) is no resume to try again: it fails the run below, parked or not.
580
- if (threw && end.state === "failed" && claim.from === "parked" && end.error.code !== CLAIM_REFUSED)
589
+ // A claim refused for good (CLAIM_REFUSED), or a run whose records no longer cross to its process (TOO_LARGE), is no
590
+ // resume to try again: it fails the run below, parked or not, and the row that woke it (an approval already answered
591
+ // 204) is refused as a failed run's, never left to wait.
592
+ if (threw && end.state === "failed" && claim.from === "parked" && end.error.code !== CLAIM_REFUSED && end.error.code !== TOO_LARGE)
581
593
  return await resumeFailed(held, end.error.message);
582
594
  if (threw && end.state === "failed") {
583
595
  // A loop that failed with no end written: a person's stop waiting now is the run's end (stopped, its row taken),
@@ -634,9 +646,12 @@ export function startRunner(options) {
634
646
  emit({ type: "error", runId: claim.runId, step: isFenced(error) ? "release (fenced)" : "release", message: message(error) });
635
647
  }
636
648
  finally {
637
- // Only its own entry: a run this runner lost and claimed again holds a new one under the same id.
638
- if (runs.get(claim.runId) === held)
649
+ // Only its own entry: a run this runner lost and claimed again holds a new one under the same id. Its own keys go
650
+ // with it: a next claim opens them again.
651
+ if (runs.get(claim.runId) === held) {
639
652
  runs.delete(claim.runId);
653
+ redact.dropCarried(claim.runId);
654
+ }
640
655
  }
641
656
  };
642
657
  /** A parked run's resume that threw: one more try on the row that woke it, released parked with a backoff; after
@@ -718,7 +733,9 @@ export function startRunner(options) {
718
733
  threw = true;
719
734
  // A claim refused before any loop could start (the dispatch's ClaimRefused: a harness this host never holds) is
720
735
  // for good: the run fails in its words, whatever woke it.
721
- end = { state: "failed", error: { code: error instanceof ClaimRefused ? CLAIM_REFUSED : "loop-threw", message: message(error) } };
736
+ end = error instanceof FrameTooLarge
737
+ ? { state: "failed", error: { code: TOO_LARGE, message: `the run's records no longer fit the channel to its process (${error.message}), so it cannot go on` } }
738
+ : { state: "failed", error: { code: error instanceof ClaimRefused ? CLAIM_REFUSED : "loop-threw", message: message(error) } };
722
739
  }
723
740
  await finish(held, end, threw);
724
741
  })();
@@ -7,7 +7,7 @@
7
7
  // flight (mcp_oauth_pending); each trigger source's settings, a webhook trigger's signing secret and the GitHub App's key
8
8
  // and webhook secret among them, the outbound webhook's signing secret and Slack's incoming-webhook URL (whole and its
9
9
  // token alone, slack-url.ts), each it held before too (trigger_settings), but a field its source marks public; browser sign-in pointers, live and forgotten; live viewer tokens; a launch's sealed
10
- // part (a run's handed MCP credentials and its own model key). Beside the store, what the data directory keeps where the runner shares it (server-secrets.ts besideTheStore: the
10
+ // part (a run's handed MCP credentials, its own model key and its own tool keys). Beside the store, what the data directory keeps where the runner shares it (server-secrets.ts besideTheStore: the
11
11
  // owner's API token and the sign-in session secret). Each value in every spelling the server's list has
12
12
  // (standard-webhooks.ts secretForms), a PEM key whole and line by line. A value that does not open under the runner's key
13
13
  // is left out: the store never holds one in the clear, and nothing of this runner can be handed it.
@@ -59,8 +59,8 @@ function jsonSecrets(text) {
59
59
  }
60
60
  /** A launch's sealed JSON: its own listed values (jsonSecrets), each handed MCP credential's headers (store/seal.ts
61
61
  * sealRunLaunch: `{"mcp": {"<server>": {"headers": {...}}}}`), as a saved server's are listed, each per-run Composio
62
- * binding's user and account (`{"mcp": {"<server>": {"composio": {"user_id", "connected_account_id"}}}}`), and the run's
63
- * own model key (`{"model": {"key": "..."}}`). */
62
+ * binding's user and account (`{"mcp": {"<server>": {"composio": {"user_id", "connected_account_id"}}}}`), the run's
63
+ * own model key (`{"model": {"key": "..."}}`) and each of its own tool keys (`{"keys": {"<NAME>": "..."}}`). */
64
64
  function launchSecrets(text) {
65
65
  const out = jsonSecrets(text);
66
66
  let opened;
@@ -82,6 +82,10 @@ function launchSecrets(text) {
82
82
  }
83
83
  if (typeof opened?.model?.key === "string")
84
84
  out.push(opened.model.key);
85
+ if (opened?.keys && typeof opened.keys === "object")
86
+ for (const value of Object.values(opened.keys))
87
+ if (typeof value === "string")
88
+ out.push(value);
85
89
  return out;
86
90
  }
87
91
  /** The ChatGPT sign-in's sealed row (chatgpt-plan.ts): its access and refresh tokens, each alone, as a renewal in any
@@ -135,6 +135,10 @@ declare function inputSchemaOf(text: string, resolve: (doc: {
135
135
  }, schema: Record<string, unknown>) => Record<string, unknown>): Record<string, unknown> | undefined;
136
136
  /** Whether `workflow` takes `input` as it is: a schema with a required field, which the input passes at its top level. */
137
137
  export declare function fits(workflow: LearnedWorkflow, input: unknown, resolve: Parameters<typeof inputSchemaOf>[1]): boolean;
138
+ /** Whether a connected agent's turn on `task` (the text its start was given) is an input of `workflow`: a JSON object
139
+ * task is the input, so it must fit (fits, the managed rule); a prose task's input is resolved by the client from the
140
+ * turn's recorded tool inputs or the host's resolveCheckInput, so any workflow may take it. */
141
+ export declare function sdkTakes(workflow: LearnedWorkflow, task: string, resolve: Parameters<typeof inputSchemaOf>[1]): boolean;
138
142
  /** A learned workflow's digest: the first 16 hex of its text's sha256. A new revision of it is a new digest. */
139
143
  export declare const workflowDigest: (workflow: Pick<LearnedWorkflow, "workflow">) => string;
140
144
  /** The workflow a run serves first (`serve`), or the one the money rule stopped (`revise`), or neither: the run is
@@ -123,6 +123,19 @@ export function fits(workflow, input, resolve) {
123
123
  const required = Array.isArray(schema?.required) ? schema.required.filter((key) => typeof key === "string") : [];
124
124
  return schema !== undefined && required.length > 0 && inputIssues(input, schema).length === 0;
125
125
  }
126
+ /** Whether a connected agent's turn on `task` (the text its start was given) is an input of `workflow`: a JSON object
127
+ * task is the input, so it must fit (fits, the managed rule); a prose task's input is resolved by the client from the
128
+ * turn's recorded tool inputs or the host's resolveCheckInput, so any workflow may take it. */
129
+ export function sdkTakes(workflow, task, resolve) {
130
+ let parsed;
131
+ try {
132
+ parsed = JSON.parse(task);
133
+ }
134
+ catch {
135
+ return true;
136
+ }
137
+ return !isObject(parsed) || fits(workflow, parsed, resolve);
138
+ }
126
139
  /** A learned workflow's digest: the first 16 hex of its text's sha256. A new revision of it is a new digest. */
127
140
  export const workflowDigest = (workflow) => createHash("sha256").update(workflow.workflow).digest("hex").slice(0, 16);
128
141
  /** The workflow a run serves first (`serve`), or the one the money rule stopped (`revise`), or neither: the run is
@@ -5,6 +5,7 @@ import type { Workflow } from "@parcha/agentrun-dsl";
5
5
  import { type WorkflowTaskHost } from "../workflow/task.js";
6
6
  import { type BudgetData, type EndData } from "./journal-kinds.js";
7
7
  import { type Claim, type Journal, type LoopFactory } from "./loop-contract.js";
8
+ import { type HeldRedact } from "./redact.js";
8
9
  /** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
9
10
  * via the spec, so flat or tiered pricing is the cap's, not this loop's). */
10
11
  /** `node`: the label of the workflow node whose step the cap held (a model node's request, a call node's call, a
@@ -129,7 +130,7 @@ export declare const isWorkflowRevision: (revision: {
129
130
  /** What a claim's spec is built from beside the claim: the runner's one redactor (LoopDeps.redact), which holds the keys
130
131
  * the claim opens from the store (redact.ts holdClaimed). */
131
132
  export interface WorkflowSpecRun {
132
- readonly redact?: (text: string) => string;
133
+ readonly redact?: HeldRedact;
133
134
  /** A fresh journal of the claim, for what the spec reads from the run's records at its end (its decisions' booked
134
135
  * cost): a fresh one, since the Harness closes its own before the end is written. */
135
136
  readonly journal?: () => Journal;
@@ -23,6 +23,7 @@ import { createWorkflowExtension } from "../workflow/task.js";
23
23
  import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "../workflow-run.js";
24
24
  import { KINDS } from "./journal-kinds.js";
25
25
  import { stopEnd } from "./loop-contract.js";
26
+ import { heldRedactor } from "./redact.js";
26
27
  import { END_PATCH_MS, END_PATCH_UNKNOWN, readAgain } from "./loop.js";
27
28
  /** A paused run's words, its row's summary while it waits for a resume. */
28
29
  export const PAUSED_WORDS = "Paused.";
@@ -217,7 +218,7 @@ function workflowLoop(specOf, deps) {
217
218
  const parkController = new AbortController();
218
219
  let heldRefusal;
219
220
  const context = withAbortSignal(AbortSignal.any([deps.signal, parkController.signal]), BACKGROUND_CONTEXT);
220
- spec = await specOf(claim, { ...(deps.redact ? { redact: deps.redact } : {}), journal: () => deps.journal(claim) });
221
+ spec = await specOf(claim, { ...(deps.redact ? { redact: heldRedactor(deps.redact) } : {}), journal: () => deps.journal(claim) });
221
222
  claimNow = claim;
222
223
  specReady();
223
224
  const revision = { id: spec.revisionId, kind: "workflow", body: { workflow: spec.workflow, tools: [...spec.tools] } };