@parcha/agentrun-serve 0.1.0-beta.60 → 0.1.0-beta.62

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 (179) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +139 -22
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/api-only.d.ts +23 -1
  5. package/dist/api-only.js +43 -4
  6. package/dist/archil-settings.d.ts +9 -0
  7. package/dist/archil-settings.js +8 -1
  8. package/dist/bash-read-only.d.ts +3 -0
  9. package/dist/bash-read-only.js +6 -3
  10. package/dist/browser-person.d.ts +1 -1
  11. package/dist/browser-person.js +1 -1
  12. package/dist/calendar/tools.js +1 -1
  13. package/dist/chatgpt-plan.d.ts +26 -8
  14. package/dist/chatgpt-plan.js +89 -21
  15. package/dist/claude-login.d.ts +12 -5
  16. package/dist/claude-login.js +28 -3
  17. package/dist/cli.js +61 -18
  18. package/dist/composio-triggers.d.ts +9 -3
  19. package/dist/computers.d.ts +3 -0
  20. package/dist/computers.js +2 -1
  21. package/dist/console/assets/{backend-QnwGVBeU.js → backend-DEgVn5lC.js} +1 -1
  22. package/dist/console/assets/index-CG5tELph.js +639 -0
  23. package/dist/console/assets/share-CIeFK2Oe.js +6 -0
  24. package/dist/console/assets/{styles-CcceGcu2.js → styles-BGZxYkky.js} +2 -2
  25. package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
  26. package/dist/console/index.html +3 -3
  27. package/dist/console/share.html +3 -3
  28. package/dist/cut-pool.d.ts +14 -0
  29. package/dist/cut-pool.js +98 -0
  30. package/dist/cut-worker.d.ts +14 -0
  31. package/dist/cut-worker.js +16 -0
  32. package/dist/decisions.d.ts +4 -0
  33. package/dist/decisions.js +9 -1
  34. package/dist/env-switch.d.ts +3 -0
  35. package/dist/env-switch.js +3 -0
  36. package/dist/errors.d.ts +1 -0
  37. package/dist/errors.js +2 -0
  38. package/dist/harness-check.js +2 -1
  39. package/dist/harness-recipe.d.ts +13 -2
  40. package/dist/harness-recipe.js +30 -7
  41. package/dist/harness-sign-in.js +2 -1
  42. package/dist/harness-table.d.ts +12 -3
  43. package/dist/harness-table.js +13 -8
  44. package/dist/import.d.ts +8 -1
  45. package/dist/import.js +36 -5
  46. package/dist/key-check.js +22 -8
  47. package/dist/key-refusal.js +6 -4
  48. package/dist/learn/secrets.d.ts +2 -1
  49. package/dist/learn/secrets.js +2 -2
  50. package/dist/learned-nodes.d.ts +37 -0
  51. package/dist/learned-nodes.js +24 -0
  52. package/dist/local-model.d.ts +144 -0
  53. package/dist/local-model.js +214 -0
  54. package/dist/mcp-gateway.d.ts +24 -0
  55. package/dist/mcp-gateway.js +97 -8
  56. package/dist/mcp-probe.d.ts +7 -0
  57. package/dist/mcp-probe.js +7 -0
  58. package/dist/mcp-servers-store.d.ts +7 -10
  59. package/dist/mcp-servers-store.js +15 -9
  60. package/dist/native/cli.js +5 -1
  61. package/dist/ollama-provider.d.ts +42 -0
  62. package/dist/ollama-provider.js +118 -2
  63. package/dist/openapi.js +85 -16
  64. package/dist/otel/tracer.d.ts +6 -3
  65. package/dist/otel/tracer.js +24 -6
  66. package/dist/page.d.ts +7 -0
  67. package/dist/page.js +17 -4
  68. package/dist/place.d.ts +28 -11
  69. package/dist/place.js +43 -14
  70. package/dist/print.d.ts +3 -2
  71. package/dist/print.js +8 -6
  72. package/dist/redact/match.d.ts +17 -4
  73. package/dist/redact/match.js +57 -15
  74. package/dist/run-export.js +4 -2
  75. package/dist/run-launch.js +16 -3
  76. package/dist/run-model-key.d.ts +2 -1
  77. package/dist/run-model-key.js +2 -1
  78. package/dist/run-reads-over-store.d.ts +7 -0
  79. package/dist/run-reads-over-store.js +32 -4
  80. package/dist/run-usage.js +3 -2
  81. package/dist/runnable.d.ts +6 -3
  82. package/dist/runnable.js +16 -6
  83. package/dist/runner/adapter-loop.d.ts +8 -1
  84. package/dist/runner/adapter-loop.js +148 -29
  85. package/dist/runner/adapter-run-spec.d.ts +9 -6
  86. package/dist/runner/adapter-run-spec.js +38 -52
  87. package/dist/runner/adapters/index.d.ts +4 -0
  88. package/dist/runner/adapters/index.js +2 -1
  89. package/dist/runner/adapters/pi.d.ts +3 -2
  90. package/dist/runner/adapters/pi.js +3 -1
  91. package/dist/runner/audit.d.ts +1 -1
  92. package/dist/runner/claim-secrets.d.ts +3 -1
  93. package/dist/runner/claim-secrets.js +18 -7
  94. package/dist/runner/cli-run-spec.js +24 -17
  95. package/dist/runner/compare-end.d.ts +1 -1
  96. package/dist/runner/dispatch.js +4 -2
  97. package/dist/runner/harness-loops.d.ts +14 -0
  98. package/dist/runner/harness-loops.js +51 -5
  99. package/dist/runner/held.d.ts +4 -1
  100. package/dist/runner/live-ticker.js +5 -4
  101. package/dist/runner/loop-contract.d.ts +4 -1
  102. package/dist/runner/mcp-claim.js +3 -2
  103. package/dist/runner/mcp-run.d.ts +24 -4
  104. package/dist/runner/mcp-run.js +47 -2
  105. package/dist/runner/meta-tools.js +4 -4
  106. package/dist/runner/metrics.d.ts +6 -0
  107. package/dist/runner/metrics.js +12 -4
  108. package/dist/runner/monid-run.js +3 -1
  109. package/dist/runner/native-loop.js +3 -3
  110. package/dist/runner/redact.d.ts +3 -0
  111. package/dist/runner/redact.js +7 -0
  112. package/dist/runner/run-child-host.d.ts +10 -6
  113. package/dist/runner/run-child-host.js +44 -29
  114. package/dist/runner/run-child.js +1 -0
  115. package/dist/runner/runner.js +2 -0
  116. package/dist/runner/sdk-loop.js +5 -3
  117. package/dist/runner/workflow-calls.d.ts +5 -1
  118. package/dist/runner/workflow-calls.js +65 -19
  119. package/dist/runner/workflow-loop.d.ts +1 -1
  120. package/dist/runner/workflow-loop.js +3 -1
  121. package/dist/runner/workflow-spec.d.ts +4 -0
  122. package/dist/runner/workflow-spec.js +18 -13
  123. package/dist/runs-over-store.d.ts +2 -2
  124. package/dist/runs-over-store.js +1 -1
  125. package/dist/secret-cut.js +7 -4
  126. package/dist/secret-rules.d.ts +0 -1
  127. package/dist/secret-rules.js +122 -88
  128. package/dist/server.d.ts +17 -1
  129. package/dist/server.js +208 -69
  130. package/dist/share-host.d.ts +111 -0
  131. package/dist/share-host.js +666 -0
  132. package/dist/slack.js +2 -1
  133. package/dist/store/postgres/migrate.js +3 -1
  134. package/dist/store-reads/analytics.d.ts +15 -0
  135. package/dist/store-reads/analytics.js +17 -0
  136. package/dist/store-reads/learning.d.ts +5 -4
  137. package/dist/store-reads/learning.js +7 -4
  138. package/dist/suggestions.js +32 -3
  139. package/dist/templates.d.ts +3 -1
  140. package/dist/templates.js +7 -3
  141. package/dist/tool-gate.d.ts +25 -9
  142. package/dist/tool-gate.js +58 -19
  143. package/dist/tool-plane.d.ts +24 -1
  144. package/dist/tool-plane.js +75 -3
  145. package/dist/tools.d.ts +12 -2
  146. package/dist/tools.js +42 -7
  147. package/dist/trigger-composio.js +1 -1
  148. package/dist/trigger-launch-hook.d.ts +2 -2
  149. package/dist/trigger-launch-hook.js +1 -1
  150. package/dist/triggers.d.ts +7 -4
  151. package/dist/triggers.js +4 -4
  152. package/dist/webhooks.d.ts +3 -0
  153. package/dist/webhooks.js +5 -0
  154. package/dist/workspace/archil-claim.d.ts +7 -3
  155. package/dist/workspace/archil-claim.js +13 -5
  156. package/dist/workspace/archil-mount-credential.d.ts +6 -0
  157. package/dist/workspace/archil-mount-credential.js +11 -0
  158. package/dist/workspace/computer-deps.d.ts +5 -3
  159. package/dist/workspace/computer-deps.js +11 -9
  160. package/dist/workspace/computer-for-claim.d.ts +6 -2
  161. package/dist/workspace/computer-for-claim.js +43 -12
  162. package/dist/workspace/computer-janitor.d.ts +7 -4
  163. package/dist/workspace/computer-janitor.js +7 -4
  164. package/dist/workspace/computer-kept.d.ts +7 -1
  165. package/dist/workspace/computer-kept.js +7 -1
  166. package/dist/workspace/kind-skills/desktop/SKILL.md +12 -3
  167. package/dist/workspace/mount-revoke-left.d.ts +16 -4
  168. package/dist/workspace/mount-revoke-left.js +42 -22
  169. package/dist/workspace/resolve-computer.d.ts +11 -5
  170. package/dist/workspace/resolve-computer.js +22 -13
  171. package/dist/workspace/run-end-computers.js +1 -1
  172. package/dist/workspace/run-tools.d.ts +10 -3
  173. package/dist/workspace/run-tools.js +5 -4
  174. package/dist/wrapped.d.ts +29 -2
  175. package/dist/wrapped.js +20 -3
  176. package/launcher/agentrun-serve +1 -1
  177. package/package.json +12 -12
  178. package/dist/console/assets/index-DZi-muIj.js +0 -629
  179. package/dist/console/assets/share-pz61zIn9.js +0 -6
@@ -27,14 +27,14 @@ import { openAccount } from "../email/account.js";
27
27
  import { harnessOf, planRecipeOf, recipeHarness } from "../harness-table.js";
28
28
  import { openHarnessKeys } from "../harness-keys.js";
29
29
  import { installDirOf, installForClaim, shareInstall } from "../harness-install.js";
30
- import { loadArchilSettings } from "../archil-settings.js";
30
+ import { loadArchilSettings, noExecRegionOf } from "../archil-settings.js";
31
31
  import { planOf } from "../chatgpt-plan.js";
32
32
  import { forgottenSignIns, handedSignInReadsBack, peekSignIn, runSignIn, signInReads, verifyRunSignIn } from "../sign-ins-store.js";
33
33
  import { vendorsOver } from "../sign-ins.js";
34
34
  import { decisionProvidersIn, fauxFetch } from "../decisions.js";
35
35
  import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
36
36
  import { learningEndOfRun } from "./learning-end.js";
37
- import { cutDeep, runnerSecrets } from "./redact.js";
37
+ import { cutDeep, mustHold, runnerSecrets } from "./redact.js";
38
38
  import { storeSecrets } from "./store-secrets.js";
39
39
  import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
40
40
  import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
@@ -66,7 +66,7 @@ import { workflowsAt } from "./learning-seed.js";
66
66
  import { claimMetering, heldMcpOf, mcpForClaim } from "./mcp-run.js";
67
67
  import { learnedTiers, learnsWorkflows, mcpReachOf } from "./adapter-run-spec.js";
68
68
  import { createDispatchLoop } from "./dispatch.js";
69
- import { refuseRecipeTriggerRun, resolveRunnerLoop, withSavedGatewayDeps } from "./harness-loops.js";
69
+ import { refuseRecipeTriggerRun, resolveRunnerLoop, underServerCeilings, withSavedGatewayDeps } from "./harness-loops.js";
70
70
  import { isWorkflowRevision } from "./workflow-loop.js";
71
71
  import { loginForRun } from "../claude-login.js";
72
72
  import { harnessOfBody } from "../harness.js";
@@ -622,7 +622,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
622
622
  const projectStop = new AbortController();
623
623
  const projectSignal = reads.signal ? AbortSignal.any([reads.signal, projectStop.signal]) : projectStop.signal;
624
624
  let projectIO, projectCapture;
625
- let projectComputer, projectWorkspace, projectMode = 1;
625
+ let projectComputer, projectWorkspace, projectMode = 1, projectNoExec;
626
626
  let projectFailed = false, projectReleased = false, projectClosing = false, projectCaptureDone = false;
627
627
  let projectRelease;
628
628
  let projectCleanup;
@@ -660,7 +660,9 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
660
660
  return pending;
661
661
  };
662
662
  const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
663
- const github = () => githubAppAccess(store, sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
663
+ // Each credential the claim opens, refreshes or mints here (its MCP's, its GitHub App tokens) joins the runner's redactor.
664
+ const hold = (values) => cut.hold(values);
665
+ const github = () => githubAppAccess(store, sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
664
666
  /** The run's folder as the computer this claim made mounts it (Mode 2), where the claim's MCP files once it is made. */
665
667
  let mountedFolder;
666
668
  /** Mode 2's Archil claim, made once for the claim on the runner, its folder the run's. */
@@ -724,7 +726,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
724
726
  checkpoint = runProjectCheckpoint({ store, agentId: run.agentId, claim, launch, computer: projectComputer, ioHeld: true,
725
727
  tools: { get workspace() { if (!tools)
726
728
  throw new ClaimRefused("Project settlement has not opened its workspace."); return tools.workspace; },
727
- settleProject: async () => { tools = await runTools(projectWorkspace, projectComputer.computer, { mode: projectMode, context: BACKGROUND_CONTEXT }); return tools.settleProject(); } },
729
+ settleProject: async () => { tools = await runTools(projectWorkspace, projectComputer.computer, { mode: projectMode, noExec: projectNoExec, context: BACKGROUND_CONTEXT }); return tools.settleProject(); } },
728
730
  workspace: { data: deps.data, sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } },
729
731
  secrets: async () => runnerSecrets(deps.env, [...runnerSecrets(claimed), ...await storeSecrets(store, sealKey, deps.data)]), });
730
732
  result = await checkpoint.capture(signal);
@@ -757,24 +759,24 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
757
759
  return { state: plan.state, models: [...plan.models], token: () => plan.token(), refused: (sent) => plan.refused(sent), watch: (listener) => plan.watch(listener) };
758
760
  },
759
761
  // The claim's own login, as this runner reads the claim (its harness, its place, no model key of its own), whatever
760
- // the process names: its access token alone, read again at each ask and renewed here when it must be (near its end,
761
- // or refused); never its folder or its refresh token. Each token is carried into the runner's redactor for this run
762
- // (redact.ts carry) before it is handed, a renewed one too: model text that repeats it is cut from the run's journal
763
- // as the runner writes it (runner.ts fenced), from what it stages and from its rows, as the run's own tool keys are.
764
- // This answer is the one decision whether the run goes on the login: none, it does not. Its claim read the setting
765
- // (staysInRunner); a claim that read it off is never put on it, whatever the setting says now. A claim that read it on
766
- // has it read again here, at the start, with the claim's settings, data folder, harness and place. Its environment is
767
- // the claim's (the process's, when the runner was given none) with a saved gateway laid over it (withSavedGatewayDeps),
768
- // not always the very one the claim read with; that
769
- // difference can only refuse the start, never hand another folder, since the login is handed only when both reads name
770
- // the same folder: a turn-off, or a move to another folder,
771
- // between the claim and the start refuses the start in LOGIN_CHANGED_SINCE_CLAIM's fixed words (no folder in them),
772
- // never a start on a login the setting no longer names nor a fall to a model key the run was not claimed on. Nothing
773
- // else of the claim is read again. A run with a model key of its own, and a login other than AgentRun's own folder,
774
- // were each decided at the claim (staysInRunner: no login read for the one, LOGIN_MACHINE_NEEDS_SERVER_USER for the
775
- // other), so neither reaches here on a login. The process reads no setting or machine id.
776
- // None for a run that sends no model key (keyless: a held run, any run on a --faux runner, a faux-pinned one), whatever
777
- // its claim read: the login is a model credential like any key.
762
+ // the process names: its access token alone, read again at each ask and renewed here when it must be (near its end, or
763
+ // refused); never its folder or its refresh token. Each token is carried into the runner's redactor for this run
764
+ // (redact.ts carry) before it is handed, a renewed one too: model text that repeats it is cut from the run's journal as
765
+ // the runner writes it (runner.ts fenced), from what it stages and from its rows, as the run's own tool keys are.
766
+ // This answer is the one decision whether the run goes on the login: none, it does not. A run that sends no model key
767
+ // (keyless: a held run, any run on a --faux runner, a faux-pinned one) gets none, whatever its claim read, and no read
768
+ // of the claim's login or the setting for it: the login is a model credential like any key. Any other claim read the
769
+ // setting (staysInRunner): one that read it off is never put on it, whatever the setting says now; one that read it on
770
+ // has it read again here, at the start, with the claim's
771
+ // settings, data folder, harness and place. That read's environment is the claim's (the process's, when the runner was
772
+ // given none) with a saved gateway laid over it (withSavedGatewayDeps), not always the very one the claim read with;
773
+ // the difference can only refuse the start, never hand another folder, since the login is handed only when both reads
774
+ // name the same folder. A turn-off, or a move to another folder, between the claim and the start refuses the start in
775
+ // LOGIN_CHANGED_SINCE_CLAIM's fixed words (no folder in them), never a start on a login the setting no longer names nor
776
+ // a fall to a model key the run was not claimed on. Nothing else of the claim is read again. A keyless run, a run with
777
+ // a model key of its own and a login other than AgentRun's own folder were each decided at the claim (staysInRunner:
778
+ // no login read for the first two, LOGIN_MACHINE_NEEDS_SERVER_USER for the last), so none reaches here on a login. The
779
+ // process reads no setting or machine id.
778
780
  claudeLogin: async () => {
779
781
  if (keyless)
780
782
  return undefined;
@@ -825,7 +827,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
825
827
  const overTheDisk = disk === undefined ? undefined : openedAtUse(() => openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: disk, sweep: false, log }));
826
828
  if (overTheDisk)
827
829
  releases.push(() => overTheDisk.end());
828
- const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, toolSettings: revision.body.toolSettings, work: () => (overTheDisk === undefined ? runFolder(deps.data, run.agentId, claim.runId) : mountedFolder ?? overTheDisk.workspace()), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, undefined, launch) });
830
+ const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, toolSettings: revision.body.toolSettings, work: () => (overTheDisk === undefined ? runFolder(deps.data, run.agentId, claim.runId) : mountedFolder ?? overTheDisk.workspace()), launchInput: launch.input, hold, redact: cut, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, undefined, launch) });
829
831
  if (!made)
830
832
  return undefined;
831
833
  releases.push(() => made.release());
@@ -939,12 +941,13 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
939
941
  computer: (ask) => projectCall(async () => {
940
942
  const made = await archilOf();
941
943
  const mode = made === undefined ? 1 : 2;
944
+ const noExec = noExecRegionOf(made);
942
945
  const ws = made === undefined
943
946
  ? await openRunWorkspace({ mode: 1, agentId: run.agentId, runId: claim.runId, data: deps.data, log })
944
947
  : await openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: made, log });
945
948
  const say = typeof ask.say === "function" ? ask.say : undefined;
946
949
  const got = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: run.agentId, revisionId: run.revisionId, place: launch.place, ...(reads.incarnation ? { holder: { runner: claim.runner, incarnation: reads.incarnation } } : {}) }, store, {
947
- ...deps.computerDeps, mode, workspace: ws.workspace, sealKey,
950
+ ...deps.computerDeps, mode, noExec, workspace: ws.workspace, sealKey,
948
951
  recordings: { folder: recordingsFolder(deps.data, run.agentId, claim.runId), say: (words) => say?.(cut(words)) },
949
952
  hadComputer: async () => (await ask.hadComputer()) === true,
950
953
  ...(typeof ask.turnedOff === "string" ? { turnedOff: ask.turnedOff } : {}),
@@ -973,6 +976,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
973
976
  projectComputer = got;
974
977
  projectWorkspace = ws.workspace;
975
978
  projectMode = mode;
979
+ projectNoExec = noExec;
976
980
  const { syncProject: _sync, ...exposed } = got;
977
981
  return { ...exposed, ...(exposed.computer ? { computer: projectGate.capability(exposed.computer) } : {}),
978
982
  release: (...args) => cleanProject(() => exposed.release(...args)),
@@ -1141,6 +1145,11 @@ export async function staysInRunner(deps, harness, launch, runId, isolation) {
1141
1145
  if (revision && isWorkflowRevision(revision))
1142
1146
  return STAYS;
1143
1147
  }
1148
+ // A run that sends no model key (claim-secrets.ts sendsNoModelKey) is handed no login (heldFor claudeLogin), so its claim
1149
+ // reads none: it is never refused for a login it would never be handed. A held run its model kept from running holds its
1150
+ // computer so, whatever login this machine has on.
1151
+ if (sendsNoModelKey(launch, deps.env ?? {}))
1152
+ return OFF_LOGIN;
1144
1153
  const login = await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, harness, launch.place);
1145
1154
  if (login === undefined)
1146
1155
  return OFF_LOGIN;
@@ -1206,9 +1215,9 @@ export function runChannel(socket, onClose, gate = SERVER_SLOTS, more = {}) {
1206
1215
  return channel;
1207
1216
  }
1208
1217
  /** `login`: the Claude login this run's claim read (staysInRunner), the one its runner hands the run (ClaimReads). */
1209
- function childLoop(options, slots, loopDeps, login) {
1218
+ export function childLoop(options, slots, loopDeps, login) {
1219
+ const cut = mustHold(loopDeps.redact, "A run's own process's loop");
1210
1220
  const { deps, isolation } = options;
1211
- const cut = loopDeps.redact ?? ((text) => text);
1212
1221
  const log = (line) => options.log(cut(line));
1213
1222
  let channel;
1214
1223
  let child;
@@ -1291,7 +1300,10 @@ function childLoop(options, slots, loopDeps, login) {
1291
1300
  // host's default's now, where its revision names no model and a key saved since moved that default. On a --faux
1292
1301
  // runner, or pinned to the faux model, a run sends no model key (claim-secrets.ts sendsNoModelKey): its process is
1293
1302
  // handed none, not even its revision's model's.
1294
- const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, launch, claim.runId);
1303
+ // Its keys are its capped plane's (harness-loops.ts underServerCeilings), as the run's own loop reads that plane: a
1304
+ // run kept on Parallel and claimed after the server set kernel or native is handed no Parallel key.
1305
+ const capped = await underServerCeilings(claimDeps, launch, revisionRow);
1306
+ const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, capped, claim.runId);
1295
1307
  // A run that holds a model key of its own (model_key, its launch's) spends that key alone: its process is handed
1296
1308
  // none of the server's model keys, as its spec drops them from its tools' (claim-secrets.ts withoutModelKeys).
1297
1309
  // Copies: the runner's own reads (heldFor's `claimed`: what the run's learning must never keep) stay whole.
@@ -1413,6 +1425,9 @@ function childLoop(options, slots, loopDeps, login) {
1413
1425
  const reach = await mcpReachOf(deps);
1414
1426
  const init = {
1415
1427
  claim, data: deps.data, signal: loopDeps.signal, where: deps.store.where, ...(traced ? { traced: true } : {}),
1428
+ // The plane its keys were chosen by (`capped`): the process runs its tools on it, never on a later read of the
1429
+ // server's settings, which may have moved since.
1430
+ ...(capped.plane ? { plane: capped.plane } : {}),
1416
1431
  ...(reach.loopback ? { mcpLoopback: true, mcpOwn: reach.own ?? [] } : {}),
1417
1432
  ...(deps.githubApi ? { githubApi: deps.githubApi } : {}),
1418
1433
  ...(deps.githubWeb ? { githubWeb: deps.githubWeb } : {}),
@@ -189,6 +189,7 @@ function childDeps(init, store, journal, held) {
189
189
  installForClaim: heldInstall,
190
190
  // web_save's download slots are the runner's, shared by all its runs (save-slots.ts).
191
191
  saveSlots: remoteSaveSlots(channel),
192
+ ...(init.plane ? { claimedPlane: init.plane } : {}),
192
193
  ...(init.githubApi ? { githubApi: init.githubApi } : {}),
193
194
  ...(init.githubWeb ? { githubWeb: init.githubWeb } : {}),
194
195
  ...(init.githubMcpOrigin ? { githubMcpOrigin: init.githubMcpOrigin } : {}),
@@ -744,6 +744,8 @@ export function startRunner(options) {
744
744
  // loop ended interrupted on its own and the run is tried again. The next claim works its turn again.
745
745
  const cut = end.state !== "interrupted" ? undefined : closedItself ? "retry" : held.stoppedFor === "shutdown" ? "drain" : undefined;
746
746
  await release(claim, {
747
+ // Parked again with nothing written (LoopEnd `again`): the release parks the row, its words left as they stood.
748
+ ...(end.state === "parked" && end.again ? { state: "parked" } : {}),
747
749
  ...(end.state === "parked" && end.wakeAt !== undefined ? { wakeAt: end.wakeAt }
748
750
  : inARow > 0 ? { backoffUntil: now() + interruptBackoffMs * 2 ** Math.min(inARow - 1, 6) }
749
751
  : {}),
@@ -18,12 +18,14 @@ import { capNowOf, KINDS } from "./journal-kinds.js";
18
18
  import { bookedSpend } from "./metrics.js";
19
19
  import { stopEnd } from "./loop-contract.js";
20
20
  import { END_PATCH_MS, END_PATCH_UNKNOWN, REAL_TIMER } from "./loop.js";
21
+ import { mustHold } from "./redact.js";
21
22
  import { storeSecrets } from "./store-secrets.js";
22
23
  const ROOT = ROOT_CONVERSATION_ID;
23
24
  export function createSdkLoop(launch, host, route) {
24
25
  const execution = launch.cli_learning ?? launch.sdk;
25
26
  const MARK = launch.cli_learning ? "agentrun.cli" : "agentrun.sdk";
26
27
  return (deps) => {
28
+ mustHold(deps.redact, "An SDK loop");
27
29
  let stopped;
28
30
  const abort = new AbortController(), signal = AbortSignal.any([deps.signal, abort.signal]);
29
31
  let settled;
@@ -78,7 +80,7 @@ export function createSdkLoop(launch, host, route) {
78
80
  });
79
81
  return asked?.data?.kept;
80
82
  };
81
- const redacted = (value) => deps.redact?.(value) ?? value;
83
+ const redacted = (value) => deps.redact(value);
82
84
  let also;
83
85
  const droppedLearning = (cancelled) => launch.learning && !launch.learning.use ? [{
84
86
  table: "learning_proposals",
@@ -403,7 +405,7 @@ export function createSdkLoop(launch, host, route) {
403
405
  const spend = bookedSpend(entries.map(({ kind, conversationId, data }) => ({ kind, conversationId, data })), "model");
404
406
  const turns = entries.filter((entry) => entry.kind === "runner.turn").map((entry) => entry.data).filter((turn) => !turn.givenBack && !turn.unsent);
405
407
  const tokens = (key) => spend.unmetered || turns.some((turn) => typeof turn.usage?.[key] !== "number") ? null : spend.tokens[key];
406
- const path = completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch) : {};
408
+ const path = completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch, { redact: deps.redact }) : {};
407
409
  return {
408
410
  costUsd: spend.usd,
409
411
  metrics: { ...metrics, input: tokens("input"), output: tokens("output"), cacheRead: tokens("cacheRead"), cacheWrite: tokens("cacheWrite"), ...path },
@@ -422,7 +424,7 @@ export function createSdkLoop(launch, host, route) {
422
424
  also = droppedLearning(cancelled);
423
425
  const patch = await patchOf(async () => ({
424
426
  costUsd: usage?.cost_usd ?? null,
425
- metrics: { ...metrics, ...(completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch) : {}) },
427
+ metrics: { ...metrics, ...(completeEvidence ? await runPathMetricsOverStore(host.store, claim.runId, launch, { redact: deps.redact }) : {}) },
426
428
  }));
427
429
  await append([
428
430
  {
@@ -5,5 +5,9 @@ import type { EntryLike } from "../timeline/index.js";
5
5
  * crash keeps one each time: learnedCallEntries): its workflow, digest and caller, how it ended, and what it booked (callUsdOf). The
6
6
  * platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
7
7
  * crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
8
- * before any node ran (`refused`) is `refused`, whoever called it. A record that names no digest or caller is left out. */
8
+ * before any node ran (`refused`) is `refused`, whoever called it, and booked $0, while nothing was booked under its
9
+ * call id (bookedUnder) and every attempt of it its gate let go was closed by a refusal (openAttempts); one an attempt
10
+ * ran or spent under (a crash cut it, and its rerun was refused: at its gate, at runLearned's check of its call nodes'
11
+ * tools, or the platform's at serveFirst) is `failed`, at what it booked (callUsdOf: null on a shared or unpriced
12
+ * window, and null for an attempt cut past its record). A record that names no digest or caller is left out. */
9
13
  export declare function workflowCallsOf(entries: readonly EntryLike[]): WorkflowCall[];
@@ -5,9 +5,9 @@
5
5
  // read: a run the platform served first counts on that workflow's served side alone, one only the agent called on the
6
6
  // side of each workflow it ran (workflow-first.ts costLineOf), and a call refused before any node ran on none.
7
7
  import { WORKFLOW_CALLERS } from "../learning-cost.js";
8
- import { learnedCallEntries } from "../learned-nodes.js";
8
+ import { LEARNED_ALLOWED, LEARNED_NODES, learnedCallEntries } from "../learned-nodes.js";
9
9
  import { KINDS } from "./journal-kinds.js";
10
- import { callCostOf } from "./metrics.js";
10
+ import { callCostOf, callTurnsOf } from "./metrics.js";
11
11
  import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
12
12
  const dataOf = (entry) => (entry.data ?? {});
13
13
  const callIdOf = (entry) => {
@@ -82,24 +82,23 @@ function piShared(entries, from, to) {
82
82
  }
83
83
  return false;
84
84
  }
85
- /** What call `callId` booked (runner/metrics.ts callCostOf), over the window from its start (its call start entry, or on
86
- * pi the answer that asked for it) to the later of its end (its call end, or pi's tool result) and its record
87
- * (`recordAt`); null when the window is not its alone: no start, a pi answer that asked for another call beside it,
88
- * another conversation's tool at work in it on pi (piShared: a sibling subagent's), or another call (none of its own)
89
- * started within it or still open at its start (a nesting tool's, or the call it runs inside, is its own). Never a
90
- * guess: a cost that can't be told apart is unknown. */
91
- function callUsdOf(entries, callId, recordAt) {
85
+ /** Call `callId`'s window in `entries`, from its start (its call start entry, or on pi the answer that asked for it) to
86
+ * the later of its end (its call end, or pi's tool result) and its record (`recordAt`); none when the window is not its
87
+ * alone: no start, a pi answer that asked for another call beside it, another conversation's tool at work in it on pi
88
+ * (piShared: a sibling subagent's), or another call (none of its own) started within it or still open at its start (a
89
+ * nesting tool's, or the call it runs inside, is its own). */
90
+ function callWindowOf(entries, callId, recordAt) {
92
91
  const started = entries.findIndex((entry) => entry.kind === KINDS.callStart && callIdOf(entry) === callId);
93
92
  const asked = started < 0 ? entries.findIndex((entry) => piCallsOf(entry).includes(callId)) : -1;
94
93
  const from = started >= 0 ? started : asked;
95
94
  if (from < 0 || from > recordAt)
96
- return null;
95
+ return undefined;
97
96
  if (asked >= 0 && piCallsOf(entries[asked]).length > 1)
98
- return null;
97
+ return undefined;
99
98
  const start = (started >= 0 ? entries[from].data : {});
100
99
  const to = Math.max(recordAt, entries.findLastIndex((entry) => (entry.kind === KINDS.callEnd && callIdOf(entry) === callId) || piResultOf(entry) === callId));
101
100
  if (asked >= 0 && piShared(entries, from, to))
102
- return null;
101
+ return undefined;
103
102
  // A call that holds this one (a nesting tool's: its id a prefix of this one's, or the harness's own call it runs in).
104
103
  const holds = (id) => callId.startsWith(`${id}/`) || start.parent === id || start.parentCallId === id;
105
104
  const open = new Set();
@@ -114,21 +113,61 @@ function callUsdOf(entries, callId, recordAt) {
114
113
  open.delete(id);
115
114
  }
116
115
  if ([...open].some((id) => !holds(id)))
117
- return null;
116
+ return undefined;
118
117
  for (let at = from + 1; at <= to; at++) {
119
118
  const entry = entries[at];
120
119
  const id = callIdOf(entry);
121
120
  if (entry.kind === KINDS.callStart && id !== undefined && !within(id, callId))
122
- return null;
121
+ return undefined;
122
+ }
123
+ return { from, to };
124
+ }
125
+ /** What call `callId` booked (runner/metrics.ts callCostOf) over its window (callWindowOf); null with none. Never a
126
+ * guess: a cost that can't be told apart is unknown. */
127
+ function callUsdOf(entries, callId, recordAt) {
128
+ const window = callWindowOf(entries, callId, recordAt);
129
+ return window ? callCostOf(entries, callId, window.from, window.to) : null;
130
+ }
131
+ /** Whether anything was booked under call `callId` (runner/metrics.ts callTurnsOf, as proof): a request named under it,
132
+ * or one of host work in its window while that window is its alone, never the harness's own side request there. */
133
+ function bookedUnder(entries, callId, recordAt) {
134
+ const window = callWindowOf(entries, callId, recordAt);
135
+ return callTurnsOf(entries, callId, window?.from ?? -1, window?.to ?? -1, true).size > 0;
136
+ }
137
+ /** The attempts of an agent's learned_workflow call `callId` its gate let go (each allow mark, LEARNED_ALLOWED) that no
138
+ * refused record of it closed. A mark is closed by the call's next record before its next mark when that record is
139
+ * `refused` (refused at runLearned's check: it ran nothing); a record that says it ran, a next mark first (a crash cut
140
+ * the attempt before it kept a record) or none at all leaves it open: that attempt may have run and spent. `open`:
141
+ * any is. `cut`: the newest is open with no record after it, so what it spent lies past every record's window. The
142
+ * marks need no window, so this holds where a sibling call shares the call's window and its model nodes' spend, booked
143
+ * under a host label and no call id, can't be told for its own. */
144
+ function openAttempts(entries, callId) {
145
+ let open = false;
146
+ let pending = false;
147
+ for (const entry of entries) {
148
+ if (dataOf(entry).call !== callId)
149
+ continue;
150
+ if (entry.kind === LEARNED_ALLOWED) {
151
+ open ||= pending;
152
+ pending = true;
153
+ }
154
+ else if (entry.kind === LEARNED_NODES && pending) {
155
+ open ||= dataOf(entry).refused !== true;
156
+ pending = false;
157
+ }
123
158
  }
124
- return callCostOf(entries, callId, from, to);
159
+ return { open: open || pending, cut: pending };
125
160
  }
126
161
  /** Each learned workflow call run `entries` show (every conversation's, in log order: store-reads/journal.ts runEntries),
127
162
  * in the order the calls first kept a record, from the record that counts for each (a call run again after a park or a
128
163
  * crash keeps one each time: learnedCallEntries): its workflow, digest and caller, how it ended, and what it booked (callUsdOf). The
129
164
  * platform's call ends as the run's WORKFLOW_FIRST entry says (its answer shaped, or taken back to the agent); one a
130
165
  * crash cut before its record was kept is that entry's alone, its cost unknown. A call its record says was refused
131
- * before any node ran (`refused`) is `refused`, whoever called it. A record that names no digest or caller is left out. */
166
+ * before any node ran (`refused`) is `refused`, whoever called it, and booked $0, while nothing was booked under its
167
+ * call id (bookedUnder) and every attempt of it its gate let go was closed by a refusal (openAttempts); one an attempt
168
+ * ran or spent under (a crash cut it, and its rerun was refused: at its gate, at runLearned's check of its call nodes'
169
+ * tools, or the platform's at serveFirst) is `failed`, at what it booked (callUsdOf: null on a shared or unpriced
170
+ * window, and null for an attempt cut past its record). A record that names no digest or caller is left out. */
132
171
  export function workflowCallsOf(entries) {
133
172
  // The record that counts for each call (learned-nodes.ts learnedCallEntries): a rerun refused before any node ran leaves
134
173
  // the attempt that ran standing, as the call's timeline row does.
@@ -139,9 +178,16 @@ export function workflowCallsOf(entries) {
139
178
  const served = entries.findLast((entry) => entry.kind === WORKFLOW_FIRST && ["answered", "handed_back"].includes(String(entry.data?.outcome)))?.data;
140
179
  const calls = [...newest].map(([call, at]) => {
141
180
  const data = dataOf(entries[at]);
142
- // Refused before any node ran (its record's `refused`): it ran nothing, whatever the run did after.
143
- const outcome = data.refused === true ? "refused" : call === WORKFLOW_FIRST_CALL && served ? served.outcome : outcomeOf(data.ended);
144
- return { workflow: data.workflow, digest: data.digest, caller: data.caller, outcome, usd: callUsdOf(entries, call, at) };
181
+ // Refused before any node ran (its record's `refused`) with nothing booked under its id and every attempt its gate let
182
+ // go closed by a refusal: it ran nothing, whatever the run did after. Refused with something booked, or with an
183
+ // attempt left open (openAttempts): that attempt ran and may have spent, so it failed.
184
+ const attempts = data.refused === true ? openAttempts(entries, call) : { open: false, cut: false };
185
+ const refused = data.refused === true && !bookedUnder(entries, call, at) && !attempts.open;
186
+ const outcome = refused ? "refused" : data.refused === true ? "failed" : call === WORKFLOW_FIRST_CALL && served ? served.outcome : outcomeOf(data.ended);
187
+ // A refused call ran nothing: its $ is 0, never a shared window's unknown (two denied calls in one pi answer). One an
188
+ // attempt cut past its record failed at a cost its record's window can't hold: unknown.
189
+ const usd = refused ? 0 : attempts.cut ? null : callUsdOf(entries, call, at);
190
+ return { workflow: data.workflow, digest: data.digest, caller: data.caller, outcome, usd };
145
191
  });
146
192
  if (served && !newest.has(WORKFLOW_FIRST_CALL) && typeof served.workflow === "string" && typeof served.digest === "string") {
147
193
  calls.unshift({ workflow: served.workflow, digest: served.digest, caller: "platform", outcome: served.outcome, usd: null });
@@ -5,7 +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
+ import { type HeldRedact } from "./redact.js";
9
9
  /** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
10
10
  * via the spec, so flat or tiered pricing is the cap's, not this loop's). */
11
11
  /** `node`: the label of the workflow node whose step the cap held (a model node's request, a call node's call, a
@@ -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 { mustHold } 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.";
@@ -34,6 +35,7 @@ export function createWorkflowLoop(specOf) {
34
35
  return (deps) => workflowLoop(specOf, deps);
35
36
  }
36
37
  function workflowLoop(specOf, deps) {
38
+ mustHold(deps.redact, "A workflow loop");
37
39
  let harness;
38
40
  let workflows;
39
41
  let runId;
@@ -193,7 +195,7 @@ function workflowLoop(specOf, deps) {
193
195
  const patch = await readAgain(() => endPatch(data), late, (error, tries, last) => {
194
196
  // Cut of every secret the runner holds (LoopDeps.redact): an error's text may echo one.
195
197
  const text = error?.message ?? String(error);
196
- const cut = deps.redact ? deps.redact(text) : text;
198
+ const cut = deps.redact(text);
197
199
  console.warn(last ? `[runner] ${runId}: its end's patch failed ${tries} times, last: ${cut}; the end is written with its cost and metrics unknown` : `[runner] ${runId}: its end's patch failed: ${cut}; read again`);
198
200
  });
199
201
  if (patch === "late") {
@@ -3,6 +3,7 @@ import { type DecisionProvider, type LoadImage, type Workflow } from "@parcha/ag
3
3
  import { type BeforeRequest, type Wire } from "@parcha/agentrun-kernel";
4
4
  import { type ProviderPolicy, type ProxyUsage } from "@parcha/agentrun-kernel/host";
5
5
  import { type CapModel, type RunDecisions } from "@parcha/agentrun-kernel/kernel/cap";
6
+ import type { RunLaunch } from "../run-launch.js";
6
7
  import { type Tier } from "../model.js";
7
8
  import { deniedText } from "../refusal-words.js";
8
9
  import { type PaidBooking } from "../paid-calls.js";
@@ -61,6 +62,9 @@ export interface WorkflowSpecDeps {
61
62
  readonly sealKey?: Buffer;
62
63
  /** The runner's data directory: what the server keeps sealed beside the store is read from it (store-secrets.ts). */
63
64
  readonly data?: string;
65
+ /** The claim's plane as the runner hands it (harness-loops.ts: the launch's, under the server's settings now), over the
66
+ * launch's own. */
67
+ readonly plane?: RunLaunch["plane"];
64
68
  /** Resolves the provider and cap model for each tier the workflow names (byTier's model, its provider, its price).
65
69
  * Absent: the runner's model route (routeProviderOf), so a workflow and a pi run resolve models one way; a test gives a
66
70
  * scripted one. */
@@ -23,7 +23,7 @@ import { askedBefore, catalogPrice, JEV_INPUT_USD, PARALLEL_DECISION_USD } from
23
23
  import { decisionProvidersIn } from "../decisions.js";
24
24
  import { imageLoader } from "../pdf-pages.js";
25
25
  import { llmTiers, nodeTiers, workflowNodes } from "../model.js";
26
- import { CALL_TOOLS, toolOf, workflowTools } from "../tools.js";
26
+ import { answersCutInside, CALL_TOOLS, toolOf, workflowTools } from "../tools.js";
27
27
  import { forModel } from "../result.js";
28
28
  import { WEB_FETCH_TOOL } from "../web-fetch.js";
29
29
  import { runGate } from "../tool-gate.js";
@@ -44,7 +44,7 @@ import { KINDS, NODE_LOG_SESSION, WORKFLOW_SESSION } from "./journal-kinds.js";
44
44
  import { cutStrings } from "../key-refusal.js";
45
45
  import { CLOSE_MS } from "./loop.js";
46
46
  import { PAUSED_WORDS } from "./workflow-loop.js";
47
- import { holdClaimed } from "./redact.js";
47
+ import { holdClaimed, mustHold } from "./redact.js";
48
48
  import { holdStored } from "./store-secrets.js";
49
49
  import { workflowHost } from "./workflow-host.js";
50
50
  import { SUBMIT_TOOL } from "../workflow/host-tools.js";
@@ -137,11 +137,11 @@ export function workflowSpecOf(deps) {
137
137
  }
138
138
  };
139
139
  async function claimSpec(claim, run, proxies) {
140
+ const redact = mustHold(run?.redact, "A workflow run's spec");
140
141
  /** The keys a claim opens, held by the runner's one redactor (run.redact) before a decision can echo one. */
141
142
  const holding = async (opening) => {
142
143
  const opened = await opening;
143
- if (run?.redact)
144
- holdClaimed(run.redact, opened);
144
+ holdClaimed(redact, opened);
145
145
  return opened;
146
146
  };
147
147
  const claimed = await readClaim(deps, claim.runId);
@@ -153,15 +153,15 @@ export function workflowSpecOf(deps) {
153
153
  if (unbound !== undefined)
154
154
  throw new Error(nodeToolUnboundText(unbound));
155
155
  // Every secret the server keeps sealed (store-secrets.ts) held by the runner's one redactor before the workflow runs.
156
- if (run?.redact && deps.sealKey)
157
- await holdStored(run.redact, deps.store, deps.sealKey, deps.data);
156
+ if (deps.sealKey)
157
+ await holdStored(redact, deps.store, deps.sealKey, deps.data);
158
158
  const tiers = tiersOf(claimed.workflow);
159
159
  // The run's own keys, as the server's runnable check reads them: each by its name from the runner's environment first,
160
160
  // then the store's sealed value (claim-secrets.ts; the environment wins, rule 4), scoped to what the run needs. Its
161
161
  // models, its decisions, its call nodes' effects and its model nodes' tools all run on these, never on another run's
162
162
  // keys or on this process's whole environment.
163
163
  // Held by the runner's one redactor before anything can echo one (holding: run.redact), as the decision keys were.
164
- const claimedEnv = await holding(claimSecrets({ store: deps.store, sealKey: deps.sealKey, ...(deps.env ? { env: deps.env } : {}), redact: run?.redact }, claimed.revision, { plane: claimed.plane }, claim.runId));
164
+ const claimedEnv = await holding(claimSecrets({ store: deps.store, sealKey: deps.sealKey, ...(deps.env ? { env: deps.env } : {}), redact }, claimed.revision, { plane: claimed.plane }, claim.runId));
165
165
  // The run's models resolve the one way the runner resolves any (routeProviderOf over routeOf), unless a test gives its
166
166
  // own: each tier's key from the runner's environment, else the one the claim opened (a key saved in
167
167
  // Settings → Model keys runs the next run with no restart).
@@ -171,8 +171,8 @@ export function workflowSpecOf(deps) {
171
171
  const runKey = await claimModelKey({ store: deps.store, sealKey: deps.sealKey, env: deps.env ?? process.env }, claim.runId);
172
172
  if (keyedAtClaim(runKey))
173
173
  withoutModelKeys(claimedEnv);
174
- if (runKey && run?.redact)
175
- holdRunKey(run.redact, runKey);
174
+ if (runKey)
175
+ holdRunKey(redact, runKey);
176
176
  const providerOf = deps.providerOf ?? routeProviderOf(claimModelEnv(deps.env ?? process.env, [claimedEnv], runKey, claim));
177
177
  // Each tier's provider and cap model, resolved once; the proxies start here (before the Harness opens, since the models
178
178
  // catalog the Harness takes points at them), their hooks deferred to the booking wired at harnessReady.
@@ -265,6 +265,7 @@ export function workflowSpecOf(deps) {
265
265
  const nodeHost = {
266
266
  where: { root: claimed.workRoot, work: claimed.workRoot, ref: { id: claim.runId } },
267
267
  env: callEnv,
268
+ redact,
268
269
  install: (extension) => void installed.push(extension),
269
270
  onConversation: () => { },
270
271
  beforeResume: () => { },
@@ -272,11 +273,15 @@ export function workflowSpecOf(deps) {
272
273
  };
273
274
  const nodeBindings = await bindNodeTools(nodeNames, nodeHost);
274
275
  // Each node tool as the node gets it and the registry holds it: booked on the run's one ledger (bookedNodeTools), in an
275
- // extension of its own; the binding's raw extension (installed through `installed`) is never put in the registry.
276
+ // extension of its own; the binding's raw extension (installed through `installed`) is never put in the registry. Its
277
+ // answer, and a throw's words, pass the run's one redactor (tools.ts answersCutInside) before the node's model or the
278
+ // journal sees them, as an agentic run's tools do (adapter-run-spec.ts answersCut): a page or a search result can
279
+ // echo a key the run holds.
276
280
  const nodeTools = new Map();
277
281
  for (const [name, binding] of nodeBindings) {
278
282
  const booked = bookedNodeTools(binding, () => paidTools, parkAt);
279
- nodeTools.set(name, { tools: booked.tools, extensions: [defineExtension({ name: `node-tool-${name}`, tools: booked.tools })] });
283
+ const tools = booked.tools.map((tool) => answersCutInside(tool, redact));
284
+ nodeTools.set(name, { tools, extensions: [defineExtension({ name: `node-tool-${name}`, tools: tools })] });
280
285
  }
281
286
  const nodePolicy = callPolicyOf(deps.store, claim.runId, claimed);
282
287
  const tierModel = (tier) => (providers.get(tier ?? "default") ?? providers.get("default"))?.capModel;
@@ -310,7 +315,7 @@ export function workflowSpecOf(deps) {
310
315
  // would book beside the run's ledger), and the run's gate over them by name (main's registry.install).
311
316
  sharedExtensions: [nodeToolGate(nodeNames, nodePolicy), ...[...nodeTools.values()].flatMap((binding) => binding.extensions)],
312
317
  nodeTool: (name) => nodeTools.get(name),
313
- runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools, (line) => nodeLog?.append([{ kind: KINDS.nodeEffect, data: (run?.redact ? cutStrings(line, run.redact) : line) }]) ?? Promise.resolve()),
318
+ runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools, (line) => nodeLog?.append([{ kind: KINDS.nodeEffect, data: cutStrings(line, redact) }]) ?? Promise.resolve()),
314
319
  workRoot: claimed.workRoot,
315
320
  flush: () => deps.store.flush(),
316
321
  // A decision node books through the run's one cap (admitted and settled as main holds it); a cap refusal for room
@@ -1049,6 +1054,6 @@ async function readClaim(deps, runId) {
1049
1054
  const input = launch && typeof launch.input === "object" && launch.input !== null ? launch.input : {};
1050
1055
  const capUsd = typeof launch?.max_cost_usd === "number" ? launch.max_cost_usd : undefined;
1051
1056
  const workRoot = typeof launch?.documents === "string" ? launch.documents : "/tmp";
1052
- return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd, workRoot, plane: launch?.plane };
1057
+ return { agentId: run.agentId, revisionId: run.revisionId, revision: revision, workflow: revision.body.workflow, input, capUsd, workRoot, plane: deps.plane ?? launch?.plane };
1053
1058
  }
1054
1059
  export { BACKGROUND_CONTEXT };
@@ -172,8 +172,8 @@ export interface StartDeps {
172
172
  admitted?(): Promise<void>;
173
173
  } | undefined>;
174
174
  };
175
- /** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
176
- fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
175
+ /** Where a revision naming these tools and no place runs here, in the folder mode of now (server.ts fallbackPlace). */
176
+ fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Promise<Place>;
177
177
  /** The Archil disk the run's launch record keeps (server.ts launchDiskOf): the one its body's `archil_disk` names, else
178
178
  * its agent's when it has one now; undefined for neither, or in Mode 1. A disk named in Mode 1 is refused. Absent, no
179
179
  * disk is kept. */
@@ -756,7 +756,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
756
756
  const refused = await deps.runnersRefused?.();
757
757
  if (refused !== undefined)
758
758
  throw new ApiError("runner_refused", refused);
759
- const place = resolvePlace(rbody.place, deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
759
+ const place = resolvePlace(rbody.place, await deps.fallbackPlace(revision.kind, revision.kind === "agentic" ? (rbody.tools ?? []) : []));
760
760
  // A held computer (computer-held.ts): only one that speaks the protocol, its kind as the claim reads it (the
761
761
  // revision's computer, else its place's). Read before the run's check, which defers a held run's model refusal.
762
762
  const hold = holdOf(body, (settingOfDefinition(rbody)?.computer ?? computerOfPlace(place)).kind);
@@ -10,6 +10,7 @@ secretLintProfiler.setEnabled(false);
10
10
  import { keyShaped } from "./secret-name.js";
11
11
  import { secretValues } from "./api-token.js";
12
12
  import { MIN_SECRET, valueMatcher } from "./learn/secrets.js";
13
+ import { SEPARATOR } from "./redact/match.js";
13
14
  import { userInfo } from "node:os";
14
15
  import { commandReadPath, decodedTimes, inputSpan, isPlaceholder, KEY_RUN_MAX, lineBounds, lineCount, RESTORABLE, SCRUB_RULES, shapeOf, viewsOf } from "./secret-rules.js";
15
16
  export { isPlaceholder, RESTORABLE, RULE_PATTERNS, SCRUB_RULES, viewsOf } from "./secret-rules.js";
@@ -378,7 +379,9 @@ function contextOf(view, opts) {
378
379
  /** Whether a cut text holds nothing the scrub must cut: no known format the format rules still find in any view of any
379
380
  * chunk of it (each marker read as a blank, so a marker is never one), and no held value in any form (valueMatcher:
380
381
  * split by whitespace, partly encoded) in the text as written or in any decoding of it, each marker read as a
381
- * character no form holds. The time budget holds here too (a throw). */
382
+ * character no form holds and every view keeps (SEPARATOR, read with valueMatcher's `separated`: a NUL would not do,
383
+ * as the views drop control characters). A U+FFFF the text brought is read as a NUL first, nothing to the views, so
384
+ * only a marker separates. The time budget holds here too (a throw). */
382
385
  async function clean(rules, out, opts, run) {
383
386
  const blanked = out.replace(MARKER, (found) => " ".repeat(found.length));
384
387
  const formats = rules.filter((rule) => rule.kind === "format");
@@ -395,9 +398,9 @@ async function clean(rules, out, opts, run) {
395
398
  const held = heldOf(opts);
396
399
  if (!held.length)
397
400
  return true;
398
- const matches = valueMatcher(held);
399
- for (const view of viewsOf(out.replace(MARKER, "\u0000"))) {
400
- if (matches(view.source))
401
+ const matches = valueMatcher(held, { separated: true });
402
+ for (const view of viewsOf(out)) {
403
+ if (matches(view.source.replaceAll(SEPARATOR, "\u0000").replace(MARKER, SEPARATOR)))
401
404
  return false;
402
405
  inTime(run);
403
406
  }