@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
@@ -9,7 +9,7 @@ export declare const GRADER = "grader";
9
9
  export type CompareEndDeps = {
10
10
  readonly store: Store;
11
11
  readonly log: (line: string) => void;
12
- readonly redact?: (text: string) => string;
12
+ readonly redact: (text: string) => string;
13
13
  };
14
14
  /** The end-of-run step of a replay run or an audit's shadow (its callers pass no other run): its comparison (above),
15
15
  * asked only when the run completed, was not cut, has a grader (its route exists only for a revision that names no
@@ -9,6 +9,7 @@
9
9
  // be read, fails the run in words (the dispatch's start() throws, which the runner records as the run failing).
10
10
  import { harnessOfBody } from "../harness.js";
11
11
  import { launchOnItsDisk, readLaunchBody } from "../run-launch.js";
12
+ import { mustHold } from "./redact.js";
12
13
  /** A launch naming a harness this runner does not run. */
13
14
  export class UnknownHarness extends Error {
14
15
  harness;
@@ -39,6 +40,7 @@ export function createDispatchLoop(deps) {
39
40
  return (loopDeps) => dispatchLoop(deps, loopDeps);
40
41
  }
41
42
  function dispatchLoop(deps, loopDeps) {
43
+ mustHold(loopDeps.redact, "A dispatch loop");
42
44
  /** The harness's loop, once the launch read has chosen it. */
43
45
  let inner;
44
46
  /** Commands handed over before the inner loop was chosen: replayed through it once it is. */
@@ -85,7 +87,7 @@ function dispatchLoop(deps, loopDeps) {
85
87
  if (earlyStop) {
86
88
  inner.stop(earlyStop).catch((error) => {
87
89
  const text = error?.message ?? String(error);
88
- console.warn(`[runner] run ${claim.runId}: its stop failed: ${loopDeps.redact ? loopDeps.redact(text) : text}`);
90
+ console.warn(`[runner] run ${claim.runId}: its stop failed: ${loopDeps.redact(text)}`);
89
91
  });
90
92
  }
91
93
  return end;
@@ -110,7 +112,7 @@ function dispatchLoop(deps, loopDeps) {
110
112
  // What went wrong, cut of the values the run holds (LoopDeps.redact), as the log may not show them.
111
113
  const why = () => {
112
114
  const text = lastError?.message ?? String(lastError);
113
- return loopDeps.redact ? loopDeps.redact(text) : text;
115
+ return loopDeps.redact(text);
114
116
  };
115
117
  const failed = [];
116
118
  try {
@@ -3,6 +3,7 @@ import type { SealedKeys, Settings } from "../store/index.js";
3
3
  import { type RunLaunch } from "../run-launch.js";
4
4
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
5
5
  import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
6
+ import type { Revision } from "../agent-rows.js";
6
7
  /** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
7
8
  * refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
8
9
  export declare class NeverFits extends ClaimRefused {
@@ -29,6 +30,19 @@ export declare function refuseRecipeTriggerRun(deps: {
29
30
  export declare function resolveRunnerLoop(given: AdapterSpecDeps, options?: {
30
31
  readonly keysCounted?: boolean;
31
32
  }): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
33
+ /** `made` with the saved gateway's key, as this claim read it, held by the run's one redactor before the loop starts: the
34
+ * key stays off the claim's tool keys (claimSecrets), and a later scan of the store (holdStored) would find only a key
35
+ * saved since, so a gateway reply that echoes this one is cut in the run's records and logs all the same. `made` itself
36
+ * where the gateway is not the saved one. */
37
+ export declare function holdingGatewayKey(made: LoopFactory, env: NodeJS.ProcessEnv | undefined): LoopFactory;
38
+ /** `launch` as this claim runs it: its plane, resolved at the run's start, under the server's tool settings now
39
+ * (tool-plane.ts claimPlane), so a resume, a follow-up or a reclaim after the server set web_fetch to kernel, or
40
+ * web_search to native or off, sends nothing past that setting, whatever its agent picked. Settings that could not be
41
+ * read fail closed: a capability kept on a keyless third party or on Parallel runs nothing (SETTINGS_NOT_READ), and
42
+ * the gate refuses every tool besides (storeSettings). It resolves on the run's pinned model (the launch's, chosen at
43
+ * its start), never the host's default in this environment, which holds no key saved on the server (claim-secrets.ts
44
+ * opens those later), and with the saved keys' names (savedNamesOver) for the route its model requests take. */
45
+ export declare function underServerCeilings(deps: AdapterSpecDeps, launch: RunLaunch, revision: Revision): Promise<RunLaunch>;
32
46
  /** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
33
47
  * dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
34
48
  * start and the test server pass this to startRunner. */
@@ -1,6 +1,6 @@
1
1
  import { envGatewayInForce, readSavedGateway, savedGatewayIn, savedGatewayMarked, SAVED_GATEWAY_ENV, withSavedGateway } from "../model-gateway.js";
2
2
  import { GATEWAY_KEY_ENV } from "../model.js";
3
- import { heldRedactor } from "./redact.js";
3
+ import { mustHold } from "./redact.js";
4
4
  import { envValue } from "../key-meta.js";
5
5
  import { createSdkLoop } from "./sdk-loop.js";
6
6
  import { createNativeLoop } from "./native-loop.js";
@@ -29,6 +29,11 @@ import { askRouteOf } from "./sdk-ask.js";
29
29
  import { ClaimRefused } from "./loop-contract.js";
30
30
  import { createWorkflowLoop, isWorkflowRevision } from "./workflow-loop.js";
31
31
  import { workflowSpecOf } from "./workflow-spec.js";
32
+ import { storeSettings } from "./adapter-run-spec.js";
33
+ import { claimPlane, overCeilings } from "../tool-plane.js";
34
+ import { SECRET_NAMES } from "../secrets.js";
35
+ import { sealedKeyNames } from "../server-keys.js";
36
+ import { toolingOf } from "../tools.js";
32
37
  /** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
33
38
  * refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
34
39
  export class NeverFits extends ClaimRefused {
@@ -68,28 +73,69 @@ export function resolveRunnerLoop(given, options = {}) {
68
73
  * key stays off the claim's tool keys (claimSecrets), and a later scan of the store (holdStored) would find only a key
69
74
  * saved since, so a gateway reply that echoes this one is cut in the run's records and logs all the same. `made` itself
70
75
  * where the gateway is not the saved one. */
71
- function holdingGatewayKey(made, env) {
76
+ export function holdingGatewayKey(made, env) {
72
77
  const key = env && savedGatewayIn(env) ? env[GATEWAY_KEY_ENV] : undefined;
73
78
  if (!key)
74
79
  return made;
75
80
  return (loopDeps) => {
76
- if (loopDeps.redact)
77
- heldRedactor(loopDeps.redact).hold([key]);
81
+ mustHold(loopDeps.redact, "A loop over the saved gateway").hold([key]);
78
82
  return made(loopDeps);
79
83
  };
80
84
  }
85
+ /** `launch` as this claim runs it: its plane, resolved at the run's start, under the server's tool settings now
86
+ * (tool-plane.ts claimPlane), so a resume, a follow-up or a reclaim after the server set web_fetch to kernel, or
87
+ * web_search to native or off, sends nothing past that setting, whatever its agent picked. Settings that could not be
88
+ * read fail closed: a capability kept on a keyless third party or on Parallel runs nothing (SETTINGS_NOT_READ), and
89
+ * the gate refuses every tool besides (storeSettings). It resolves on the run's pinned model (the launch's, chosen at
90
+ * its start), never the host's default in this environment, which holds no key saved on the server (claim-secrets.ts
91
+ * opens those later), and with the saved keys' names (savedNamesOver) for the route its model requests take. */
92
+ export async function underServerCeilings(deps, launch, revision) {
93
+ if (!launch.plane)
94
+ return launch;
95
+ // A run's own process takes the plane its runner capped, the one its keys were chosen by (AdapterSpecDeps.claimedPlane).
96
+ if (deps.claimedPlane)
97
+ return { ...launch, plane: deps.claimedPlane };
98
+ const { settings, unreadable } = await storeSettings(deps.store);
99
+ const unread = unreadable === true;
100
+ const tooling = await toolingOf(revision);
101
+ if (!overCeilings(launch.plane, tooling, settings, { unread }))
102
+ return launch;
103
+ const model = launch.model ? `${launch.model.provider}/${launch.model.modelId}` : undefined;
104
+ const plane = claimPlane(launch.plane, unread ? deps.env ?? process.env : await savedNamesOver(deps), tooling, settings, { capped: launch.maxCostUsd !== undefined, unread, ...(model ? { model } : {}) });
105
+ return { ...launch, plane };
106
+ }
107
+ /** `deps.env` where a key saved on the server, not set in it, is present by name: its row read, never opened (its value
108
+ * a stand-in only a resolution's presence checks read), for a plane resolved in it alone, never handed on. A runner
109
+ * holds the seal key and reads the store's rows; a run's own process (no seal key) was handed its claim's keys, which
110
+ * its environment already holds. */
111
+ async function savedNamesOver(deps) {
112
+ const env = deps.env ?? process.env;
113
+ if (!deps.sealKey)
114
+ return env;
115
+ const names = (await sealedKeyNames(deps.store)).filter((name) => SECRET_NAMES.includes(name) && !env[name]);
116
+ if (!names.length)
117
+ return env;
118
+ // Over `env` (its prototype), so its own secrets and marks (non-enumerable, or symbols) still read.
119
+ const out = Object.create(env);
120
+ for (const name of names)
121
+ Object.defineProperty(out, name, { value: "saved", enumerable: false });
122
+ return out;
123
+ }
81
124
  /** The loop a claimed run runs on, over `deps` (the saved gateway laid over its environment). */
82
125
  async function loopOn(deps, harness, launch, runId) {
83
126
  // A workflow revision runs on the workflow loop whatever the harness its body names (its default is pi): read the
84
127
  // revision to tell it apart from an agentic pi run.
85
128
  const run = await deps.store.runs.get(runId);
86
129
  const revision = run ? await deps.store.agents.revision(run.revisionId) : undefined;
130
+ // The plane this claim hands every reader (the secrets, the tools, the run's process), read once here, before any binds.
131
+ if (revision)
132
+ launch = await underServerCeilings(deps, launch, revision);
87
133
  if (revision && isWorkflowRevision(revision)) {
88
134
  // A workflow run on the workflow loop: its claim-time spec (workflow-spec.ts) resolves each tier's model the one way
89
135
  // the runner resolves any (routeProviderOf over the route, the default when no providerOf is given).
90
136
  // The runner's seal key and data directory go with it: a claim's sealed secrets are read with them (claim-secrets.ts,
91
137
  // store-secrets.ts), and every one the server keeps is held by the run's one redactor.
92
- return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}) }));
138
+ return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}), ...(launch.plane ? { plane: launch.plane } : {}) }));
93
139
  }
94
140
  // A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
95
141
  // start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
@@ -34,7 +34,10 @@ export interface HeldMcpTool {
34
34
  /** The claim's MCP as the runner holds it: its tools, and its credentials' refresh and release. */
35
35
  export interface HeldMcp {
36
36
  readonly tools: readonly HeldMcpTool[];
37
- fresh(): Promise<void>;
37
+ /** The servers left out of `tools` for want of the run's credential (mcp-run.ts ClaimMcp.unconnected). */
38
+ readonly unconnected?: readonly string[];
39
+ /** ClaimMcp.fresh: the servers still handed no credential. */
40
+ fresh(): Promise<readonly string[]>;
38
41
  release(): Promise<void>;
39
42
  }
40
43
  /** What the run's process gives mcpForClaim on the runner: its grants and harness are its revision's, which the runner
@@ -1,4 +1,5 @@
1
1
  import { redactedAnswer, redactedLive, redactedOutputWhole } from "../key-refusal.js";
2
+ import { mustHold } from "./redact.js";
2
3
  /** A run's held state as the live view keeps it, under `values`, every secret value the run's one redactor holds. A
3
4
  * running tool's id and name are cut whole (redactedAnswer). Its args by a workflow output's rule (redactedOutputWhole):
4
5
  * read whole first, so a held value split across two of its fields withholds them as "[redacted]", as a call's arguments
@@ -54,6 +55,7 @@ export function withLiveTicker(store, createLoop, options = {}) {
54
55
  timer.unref?.();
55
56
  return {
56
57
  createLoop: (deps) => {
58
+ const redact = mustHold(deps.redact, "A loop the live ticker wraps");
57
59
  let claim;
58
60
  // The claim's signal aborts when its claim is lost (or the runner shuts down past its drain): from then the loop's
59
61
  // held state is neither taken nor written, though the loop still reports while it stops. The store fences a write
@@ -65,10 +67,9 @@ export function withLiveTicker(store, createLoop, options = {}) {
65
67
  };
66
68
  deps.signal.addEventListener("abort", onAbort, { once: true });
67
69
  // The run's one redactor: a running tool's args and output and a partial answer can quote a secret the runner holds
68
- // (a key its claim opened), and the live view is read by people and consoles. A loop given none (never one the runner
69
- // makes) has no live view: its held state is never written uncut. Nor has a loop whose redactor does not know its
70
- // values (a bare function): a value still streaming, a number or an object's names cannot be cut by text alone.
71
- const values = deps.redact?.heldValues;
70
+ // (a key its claim opened), and the live view is read by people and consoles. A loop whose redactor does not know its
71
+ // values has no live view: a value still streaming, a number or an object's names cannot be cut by text alone.
72
+ const values = redact.heldValues;
72
73
  const loop = createLoop({
73
74
  ...deps,
74
75
  live: (read) => {
@@ -96,10 +96,13 @@ export type LoopEnd = {
96
96
  };
97
97
  }
98
98
  /** Parked on a person (an approval, a raise): the runner flushes and releases; a command row (or `wakeAt`, ms since
99
- * the epoch) makes the run claimable again, and the next claim's start() resumes it from the journal. */
99
+ * the epoch) makes the run claimable again, and the next claim's start() resumes it from the journal. `again`: parked
100
+ * where it stood with nothing written (a run woken at its cap by raises that were all refused), so the release itself
101
+ * parks the row again; else the loop's last commit parked it. */
100
102
  | {
101
103
  readonly state: "parked";
102
104
  readonly wakeAt?: number;
105
+ readonly again?: true;
103
106
  };
104
107
  export type StopReason =
105
108
  /** A stop or cancel row: the loop stages that row's take in the commit that ends the run as stopped (`cancel`: a cancel
@@ -22,8 +22,9 @@
22
22
  //
23
23
  // A per_run server keeps no credential: the run's caller hands one with the run or a message (mcp_auth), sealed in the
24
24
  // run's launch row for the run's life (store/seal.ts sealRunMcpAuth) and erased by the write that ends it. Each fresh()
25
- // opens it again, so a message's new credential reaches the run's next model request; a run handed none gets its calls
26
- // refused unsent (UNUSABLE.perRunMissing).
25
+ // opens it again, so a message's new credential reaches the run's next model request; a run handed none has the server's
26
+ // tools left out of its own (mcp-run.ts mcpForClaim), and a call that still names it is refused unsent
27
+ // (UNUSABLE.perRunMissing).
27
28
  //
28
29
  // A per-run Composio server (composio-made.ts composioPerRun) is bound by each run's caller ({composio_user_id,
29
30
  // connected_account_id?} in mcp_auth, sealed in its launch): its entry carries them as `query` (mcp-gateway.ts). Each
@@ -1,3 +1,4 @@
1
+ import { type HeldRedact } from "./redact.js";
1
2
  import type { HostTool } from "@parcha/agentrun-kernel";
2
3
  import type { Harness } from "@earendil-works/pi-durable";
3
4
  import { type McpGatewayOptions } from "../mcp-gateway.js";
@@ -73,6 +74,10 @@ export interface McpForClaimOptions {
73
74
  };
74
75
  /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
75
76
  readonly hold?: (values: string[]) => void;
77
+ /** The run's redactor, after each call's own scrub on every text its gateway answers or files (mcp-gateway.ts
78
+ * McpGatewayOptions.redact). Required, and one that holds keys (heldRedactor): a claim's MCP given none throws before
79
+ * it opens or mints anything, and never answers past the run's redactor. */
80
+ readonly redact: HeldRedact;
76
81
  /** The run's revision's own tool settings (body.toolSettings), where a tool's file setting is read (filed-tool.ts
77
82
  * filedBy): each answer of such a tool is filed whole in the run's files and the tool's result is its summary. A run's
78
83
  * own process passes none: its runner reads them from the revision it reads itself (run-child-host.ts). */
@@ -92,6 +97,12 @@ export interface ClaimMcp {
92
97
  /** One host tool per pinned tool, under its wire name, on every harness. Each reaches the gateway only as the loop
93
98
  * wraps it, behind the run's one gate (the gate before the intent); nothing else does. */
94
99
  readonly tools: readonly HostTool[];
100
+ /** The pinned servers whose credential comes from each run (a per_run server, a per-run Composio server) that this run
101
+ * was handed none for (UNUSABLE.perRunMissing) when the claim opened them: every call of their tools is refused
102
+ * unsent. mcpWhereHeld leaves their tools out where the harness takes its tools again at each claim. */
103
+ readonly unconnected: readonly string[];
104
+ /** The servers whose tools mcpWhereHeld left out of `tools` (of `unconnected`); none where it left none out. */
105
+ readonly leftOut?: readonly string[];
95
106
  /** A pinned tool's catalog name (`mcp:<server>/<tool>`) by its wire name; undefined for any other tool. */
96
107
  catalogOf(tool: string): string | undefined;
97
108
  /** The top-level arguments a pinned tool's listing declares (its inputSchema's `properties`, as the run's pin holds it
@@ -105,9 +116,10 @@ export interface ClaimMcp {
105
116
  /** A pinned tool's effect (`mcp:<server>/<tool>`), by its annotations as the pin holds them (tool-gate.ts toolEffect):
106
117
  * what the gate's "allow reads" and a destructive call's card read; never a later listing. Undefined for any other. */
107
118
  effectOf(name: string): ToolEffect | undefined;
108
- /** The claim step's credentials opened again on the same pin (an expired OAuth token refreshed), then the claim
109
- * confirmed: before a resumed loop's next model request. */
110
- fresh(): Promise<void>;
119
+ /** The claim step's credentials opened again on the same pin (an expired OAuth token refreshed, a per_run one a
120
+ * message handed), then the claim confirmed: before a resumed loop's next model request. Answers the servers still
121
+ * handed no credential, as `unconnected` reads at the claim. */
122
+ fresh(): Promise<readonly string[]>;
111
123
  /** Drops every credential held: the pass ended, the claim is lost, or its signal aborted. */
112
124
  release(): void;
113
125
  }
@@ -124,7 +136,15 @@ export declare function heldMcpOf(mcp: ClaimMcp, cut: (text: string) => string):
124
136
  /** The claim's MCP in the run's own process (run-child.ts), from what its runner holds (heldMcpOf). */
125
137
  export declare function claimMcpOfHeld(held: HeldMcp): ClaimMcp;
126
138
  /** The claim's MCP where the run is: mcpForClaim with the runner's seal key, else its runner's (held.ts), the gateway's
127
- * record of each call appended to the run's root through this process's own harness. */
139
+ * record of each call appended to the run's root through this process's own harness.
140
+ * The tools of a server the run was handed no credential for (ClaimMcp.unconnected) are left out, so the model is never
141
+ * offered a tool every call of which would be refused, and each such server is said once a claim, by `say` (the spec's
142
+ * AdapterRun.phase: a row of the run's timeline); a message that hands the credential brings them back at the run's
143
+ * next claim (the loop holds one that comes while a turn is going for the run's next turn, adapter-loop steer). Not for a harness whose tools are fixed at its thread's start (`toolsFixedAtStart`, AdapterFacts): left
144
+ * out there, they would never come back, so they stay listed and their calls are refused unsent until the credential
145
+ * comes. */
128
146
  export declare function mcpWhereHeld(options: Omit<McpForClaimOptions, "sealKey"> & {
129
147
  readonly sealKey: Buffer | undefined;
148
+ readonly say?: (words: string) => void;
149
+ readonly toolsFixedAtStart?: boolean;
130
150
  }): Promise<ClaimMcp | undefined>;
@@ -1,3 +1,19 @@
1
+ // A claimed run's remote MCP servers on the runner (tl-mcp's note, sections 4 to 6). A spec builder calls mcpForClaim once
2
+ // per claim, inside the adapter loop's spec step: after the loop's Gate and Harness are open, before its session. It runs
3
+ // the claim step (mcp-claim.ts: the pin its revision's save made, read and checked against the meta tools known now, the
4
+ // pinned servers' credentials opened into this claim's memory) and builds ONE gateway (mcp-gateway.ts) for the
5
+ // claim, never shared with another, reading those credentials live. The builder puts what it returns in its spec
6
+ // (AdapterRunSpec.mcp); the loop does the rest:
7
+ // - one host tool per pinned tool (`tools`), under its wire name with the pinned description and schema, for every
8
+ // harness: the loop hands them to the session as it hands every host tool (pi's registry, the CLIs' own channel for
9
+ // host tools), on its path for every host tool: the gate before the intent (allow, ask and park, deny), the flush, the
10
+ // record, the run's one ledger for a priced call.
11
+ // - a command row handed to the running loop makes the credentials fresh again (`fresh`, on the same pin) before its
12
+ // next model request; the loop calls `release` when its pass ends, the claim is lost or its signal aborts.
13
+ // The gateway holds no gate here (the loop's is the run's one gate) and keeps the rest as it is: the meta refusal, the
14
+ // unopened refusal, the URL check per call, the scrub of each call's credentials held only while that call is out, prices
15
+ // on the run's one ledger and the not-metered booking on the run's root.
16
+ import { mustHold } from "./redact.js";
1
17
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
18
  import { wireName } from "../catalog.js";
3
19
  import { mcpGateway } from "../mcp-gateway.js";
@@ -8,6 +24,7 @@ import { fakeSaveOptions } from "../web-fake.js";
8
24
  import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
9
25
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
10
26
  import { mcpNameOf } from "../tool-names.js";
27
+ import { UNUSABLE, unconnectedWords } from "../mcp-probe.js";
11
28
  import { mcpToolName, permissionKeys, pinnedEffect } from "../tool-gate.js";
12
29
  import { mcpClaim } from "./mcp-claim.js";
13
30
  import { registryListing } from "../mcp-pin-first.js";
@@ -30,6 +47,7 @@ export function catalogSessionNames(catalog, grant) {
30
47
  * claim lost while a refresh was awaited: the loop ends interrupted). A builder calls it before it takes anything it
31
48
  * would have to let go, since a throw here leaves its spec unbuilt and its release uncalled. */
32
49
  export async function mcpForClaim(options) {
50
+ const redact = mustHold(options.redact, "A claim's MCP");
33
51
  // The step's own signal: aborted by release(), which the loop calls when its pass ends, the claim is lost or its
34
52
  // signal aborts.
35
53
  const held = new AbortController();
@@ -89,11 +107,16 @@ export async function mcpForClaim(options) {
89
107
  ...(options.callBounds ? { bounds: options.callBounds } : {}),
90
108
  capped: options.capped !== false,
91
109
  ...(options.toolSettings !== undefined ? { filed: filedBy(options.toolSettings) } : {}),
110
+ redact,
92
111
  ...(media ? { media: publicMedia(async () => (media.web ? fakeSaveOptions(media.web) : fetchOptions(media.env, FAUX_ENV)), media.slots) } : {}),
93
112
  });
94
113
  const catalog = new Map();
95
114
  const declared = new Map();
96
115
  const tools = [];
116
+ // A server the run was handed no credential for: the gateway refuses every call of it unsent, in those words, until a
117
+ // message hands one. Its tools are still listed here; mcpWhereHeld leaves them out where that is safe.
118
+ const unconnectedNow = () => Object.keys(pin).filter((server) => step.credentials[server]?.unopened === UNUSABLE.perRunMissing);
119
+ const unconnected = unconnectedNow();
97
120
  for (const [server, pinned] of Object.entries(pin)) {
98
121
  for (const tool of pinned.tools) {
99
122
  const name = mcpToolName(server, tool.name);
@@ -117,6 +140,7 @@ export async function mcpForClaim(options) {
117
140
  }
118
141
  return {
119
142
  tools,
143
+ unconnected,
120
144
  catalogOf: (tool) => catalog.get(tool),
121
145
  argumentsOf: (name) => declared.get(name),
122
146
  priceOf(name) {
@@ -130,7 +154,10 @@ export async function mcpForClaim(options) {
130
154
  return meterNamed(pinned.url, pinned.meter) && falBills(parsed.tool) ? "priced by usage" : "not metered";
131
155
  },
132
156
  effectOf: (name) => pinnedEffect(pin, name),
133
- fresh: () => step.fresh(),
157
+ fresh: async () => {
158
+ await step.fresh();
159
+ return unconnectedNow();
160
+ },
134
161
  release: () => held.abort(),
135
162
  };
136
163
  }
@@ -162,6 +189,7 @@ export function heldMcpOf(mcp, cut) {
162
189
  },
163
190
  };
164
191
  }),
192
+ unconnected: [...mcp.unconnected],
165
193
  fresh: () => mcp.fresh(),
166
194
  release: async () => mcp.release(),
167
195
  };
@@ -178,6 +206,7 @@ export function claimMcpOfHeld(held) {
178
206
  replay: "never",
179
207
  call: (args, context) => tool.call(args, { ...(context.signal ? { signal: context.signal } : {}), ...(context.callId ? { callId: context.callId } : {}) }),
180
208
  })),
209
+ unconnected: held.unconnected ?? [],
181
210
  catalogOf: (tool) => byWire.get(tool)?.catalog,
182
211
  argumentsOf: (name) => {
183
212
  const declared = byCatalog.get(name)?.arguments;
@@ -190,8 +219,24 @@ export function claimMcpOfHeld(held) {
190
219
  };
191
220
  }
192
221
  /** The claim's MCP where the run is: mcpForClaim with the runner's seal key, else its runner's (held.ts), the gateway's
193
- * record of each call appended to the run's root through this process's own harness. */
222
+ * record of each call appended to the run's root through this process's own harness.
223
+ * The tools of a server the run was handed no credential for (ClaimMcp.unconnected) are left out, so the model is never
224
+ * offered a tool every call of which would be refused, and each such server is said once a claim, by `say` (the spec's
225
+ * AdapterRun.phase: a row of the run's timeline); a message that hands the credential brings them back at the run's
226
+ * next claim (the loop holds one that comes while a turn is going for the run's next turn, adapter-loop steer). Not for a harness whose tools are fixed at its thread's start (`toolsFixedAtStart`, AdapterFacts): left
227
+ * out there, they would never come back, so they stay listed and their calls are refused unsent until the credential
228
+ * comes. */
194
229
  export async function mcpWhereHeld(options) {
230
+ const { say, toolsFixedAtStart, ...rest } = options;
231
+ const mcp = await mcpHeld(rest);
232
+ if (!mcp || mcp.unconnected.length === 0 || toolsFixedAtStart)
233
+ return mcp;
234
+ const out = new Set(mcp.unconnected);
235
+ for (const server of mcp.unconnected)
236
+ say?.(unconnectedWords(server));
237
+ return { ...mcp, leftOut: mcp.unconnected, tools: mcp.tools.filter((tool) => !out.has(mcpNameOf(mcp.catalogOf(tool.name) ?? "")?.server ?? "")) };
238
+ }
239
+ async function mcpHeld(options) {
195
240
  if (options.sealKey)
196
241
  return mcpForClaim({ ...options, sealKey: options.sealKey });
197
242
  const at = heldOrThrow("a run's MCP");
@@ -20,7 +20,7 @@
20
20
  import { randomBytes } from "node:crypto";
21
21
  import { CodemodeSandbox, toCodemodeIdentifier } from "@earendil-works/pi-codemode";
22
22
  import { computerOver, withoutImageData } from "@parcha/agentrun-computer/surface";
23
- import { COMPUTER_OP_TOOL, computerDeclarations, STEP_TOOL_OPS } from "@parcha/agentrun-kernel/kernel";
23
+ import { COMPUTER_OP_TOOL, computerDeclarations, GUI_REACH, STEP_TOOL_OPS } from "@parcha/agentrun-kernel/kernel";
24
24
  import { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH } from "../meta-tool-names.js";
25
25
  import { NO_PROGRAMS_WORDS } from "../workspace/computer-ports.js";
26
26
  export { CODEMODE, META_TOOLS, TOOLS_CALL, TOOLS_SEARCH };
@@ -83,11 +83,11 @@ function scriptComputer(computer, tools) {
83
83
  return `new Proxy(${bound}, { get(target, key, receiver) { if (key === "shell" || key === "processes") throw new Error(${JSON.stringify(NO_PROGRAMS_WORDS)}); return Reflect.get(target, key, receiver); } })`;
84
84
  }
85
85
  /** What codemode's description adds for a run with a computer: the script's `computer`, and the declarations of what its
86
- * card offers. */
86
+ * card offers, less the ops the run's gate refuses whatever their arguments (opsRefused). */
87
87
  function computerWords(computer) {
88
88
  return [
89
- `The script has this run's computer as \`computer\`, typed by the declarations below. Each of its calls is a call of the run's own computer tools, asked about and recorded as that tool's: a command it runs is held to bash's setting, a file it writes to write's, a file it reads, lists or stats to read's.`,
90
- computerDeclarations(computer.card.groups),
89
+ `The script has this run's computer as \`computer\`, typed by the declarations below. Each of its calls is a call of the run's own computer tools, asked about and recorded as that tool's: a command it runs is held to bash's setting; a file it writes needs write among this agent's tools, and a file it reads, lists or stats needs read among this agent's tools, each then held to that tool's setting. ${GUI_REACH}`,
90
+ computerDeclarations(computer.card.groups, computer.opsRefused),
91
91
  ].join("\n");
92
92
  }
93
93
  /** The three tools for a session: each `nests` (but the search, which calls nothing). */
@@ -81,6 +81,12 @@ export declare function bookedDecisionsOf(entries: readonly EntryLike[], ids: Re
81
81
  * call (runner/workflow-calls.ts). $0 for none; null once one has no known cost, or one a crash cut is counted at its
82
82
  * hold (`atMost`: the most it can cost, never what it cost). */
83
83
  export declare function callCostOf(entries: readonly EntryLike[], callId: string, from: number, to: number): number | null;
84
+ /** The turns of the requests call `callId` booked, by callCostOf's rule: each request whose record names it or one nested
85
+ * in it, and each of host work admitted in its window (`from` < at <= `to`; -1 for both: no window, those named alone).
86
+ * None: nothing was booked under the call. `proof`: the turns that prove the call spent (workflow-calls.ts bookedUnder),
87
+ * not its price: a harness's own side request (`side` with no host label: a CLI's request on another model, its title or
88
+ * summary helper, proxy.ts) is left out, as it is never the call's. */
89
+ export declare function callTurnsOf(entries: readonly EntryLike[], callId: string, from: number, to: number, proof?: boolean): Set<unknown>;
84
90
  /** A cost of charges as a usage row or a run's cost block says it (costsofar/1, cutathold/1), by the kernel's one rule
85
91
  * (costOfParts) over `parts`, its float noise rounded off (floatNoiseOff): `usd` their sum, `upper_bound` when it counts
86
92
  * a cut request at its hold, with `so_far_usd` the charges' own figures alone and `unpriced` how many it counts at their
@@ -176,17 +176,25 @@ export function bookedDecisionsOf(entries, ids) {
176
176
  * call (runner/workflow-calls.ts). $0 for none; null once one has no known cost, or one a crash cut is counted at its
177
177
  * hold (`atMost`: the most it can cost, never what it cost). */
178
178
  export function callCostOf(entries, callId, from, to) {
179
+ const kept = callTurnsOf(entries, callId, from, to);
180
+ const cost = runCostOf(entries.filter((e) => !(e.kind === RUNNER_RECORDS.request || e.kind === RUNNER_RECORDS.turn) || kept.has(turnOf(e))));
181
+ return cost.atMost > 0 ? null : cost.usd;
182
+ }
183
+ /** The turns of the requests call `callId` booked, by callCostOf's rule: each request whose record names it or one nested
184
+ * in it, and each of host work admitted in its window (`from` < at <= `to`; -1 for both: no window, those named alone).
185
+ * None: nothing was booked under the call. `proof`: the turns that prove the call spent (workflow-calls.ts bookedUnder),
186
+ * not its price: a harness's own side request (`side` with no host label: a CLI's request on another model, its title or
187
+ * summary helper, proxy.ts) is left out, as it is never the call's. */
188
+ export function callTurnsOf(entries, callId, from, to, proof = false) {
179
189
  const keyed = sessionConversations(entries);
180
190
  const hosted = new Set([keyed.get(TOOL_SESSION), keyed.get(DECISION_SESSION)].filter((one) => one !== undefined));
181
191
  const ours = (e, at) => {
182
192
  const d = (e.data ?? {});
183
193
  if (typeof d.call === "string" && (d.call === callId || d.call.startsWith(`${callId}/`)))
184
194
  return true;
185
- return at > from && at <= to && (typeof d.host === "string" || d.side === true || hosted.has(Number(e.conversationId)));
195
+ return at > from && at <= to && (typeof d.host === "string" || (d.side === true && !proof) || hosted.has(Number(e.conversationId)));
186
196
  };
187
- const kept = new Set(entries.flatMap((e, at) => (e.kind === RUNNER_RECORDS.request && ours(e, at) ? [turnOf(e)] : [])));
188
- const cost = runCostOf(entries.filter((e) => !(e.kind === RUNNER_RECORDS.request || e.kind === RUNNER_RECORDS.turn) || kept.has(turnOf(e))));
189
- return cost.atMost > 0 ? null : cost.usd;
197
+ return new Set(entries.flatMap((e, at) => (e.kind === RUNNER_RECORDS.request && ours(e, at) ? [turnOf(e)] : [])));
190
198
  }
191
199
  /** A sum of charges with its float noise rounded off, nothing more (as the decisions row rounds, decision-rows.ts): a
192
200
  * decision costs millionths of a dollar, so a sum rounded to the millionth would lose it. */
@@ -158,11 +158,13 @@ export function withMonid(mcp, monid) {
158
158
  return mcp;
159
159
  return {
160
160
  tools: [...(mcp?.tools ?? []), ...monid.tools],
161
+ unconnected: mcp?.unconnected ?? [],
162
+ ...(mcp?.leftOut ? { leftOut: mcp.leftOut } : {}),
161
163
  catalogOf: (tool) => mcp?.catalogOf(tool) ?? monid.catalogOf(tool),
162
164
  argumentsOf: (name) => mcp?.argumentsOf(name),
163
165
  effectOf: (name) => mcp?.effectOf(name),
164
166
  priceOf: (name) => mcp?.priceOf(name) ?? monid.priceOf(name),
165
- fresh: async () => mcp?.fresh(),
167
+ fresh: async () => (await mcp?.fresh()) ?? [],
166
168
  release: () => mcp?.release(),
167
169
  };
168
170
  }
@@ -24,7 +24,7 @@ import { bookedSpend, cliRunMetrics } from './metrics.js';
24
24
  import { stopEnd } from './loop-contract.js';
25
25
  import { END_PATCH_MS, END_PATCH_UNKNOWN, REAL_TIMER } from './loop.js';
26
26
  import { storeSecrets } from './store-secrets.js';
27
- import { runnerSecrets, heldRedactor, processSecretRedactor } from './redact.js';
27
+ import { runnerSecrets, mustHold } from './redact.js';
28
28
  import { secretRedactor } from './redact.js';
29
29
  const ROOT = ROOT_CONVERSATION_ID;
30
30
  const MARK = 'agentrun.native';
@@ -64,7 +64,7 @@ async function lockProject(data, target, runId) {
64
64
  }
65
65
  export function createNativeLoop(launch, host) {
66
66
  return deps => {
67
- const held = heldRedactor(deps.redact ?? processSecretRedactor());
67
+ const held = mustHold(deps.redact, 'A native loop');
68
68
  let stopped;
69
69
  const abort = new AbortController();
70
70
  let session;
@@ -196,7 +196,7 @@ export function createNativeLoop(launch, host) {
196
196
  const entries = await journalEntries(journal, ctx);
197
197
  const spend = bookedSpend(entries, 'model');
198
198
  // Its path by the one writer every harness's end calls: a native task never calls a learned workflow, so `agent`.
199
- const path = await runPathMetricsOverStore(host.store, claim.runId, launch);
199
+ const path = await runPathMetricsOverStore(host.store, claim.runId, launch, { redact });
200
200
  return { costUsd: spend.usd, metrics: { ...nativeMetrics(entries, spend, model, turn, path, runtime), native_session_id: nativeSessionId, ...(usage ? { native_usage: usage } : {}) } };
201
201
  };
202
202
  endPatch = await Promise.race([read(), late]);
@@ -35,6 +35,9 @@ export interface HeldRedact extends Redact {
35
35
  * values stay held (`hold`). */
36
36
  dropCarried(runId: string): void;
37
37
  }
38
+ /** `redact` when it is a held redactor (heldRedactor), else a throw naming `where` (a loop or a run's spec): one given
39
+ * none fails before it opens a key, and never runs with the keys it opens unheld. For a caller the types don't reach. */
40
+ export declare function mustHold(redact: HeldRedact | undefined, where: string): HeldRedact;
38
41
  /** `base`, then every value held since (`hold`). One that holds already is itself: wrapped once, the one instance. */
39
42
  export declare function heldRedactor(base: Redact): HeldRedact;
40
43
  /** Every string inside `value` cut by `cut`: what the run's process writes, as the runner's redactor would cut it in a
@@ -36,6 +36,13 @@ export function secretRedactor(values) {
36
36
  * redactor reads the environment; runner.ts reads no environment or argv itself. */
37
37
  export const processSecretRedactor = () => secretRedactor(runnerSecrets(process.env));
38
38
  const isHeld = (redact) => typeof redact.hold === "function";
39
+ /** `redact` when it is a held redactor (heldRedactor), else a throw naming `where` (a loop or a run's spec): one given
40
+ * none fails before it opens a key, and never runs with the keys it opens unheld. For a caller the types don't reach. */
41
+ export function mustHold(redact, where) {
42
+ if (typeof redact !== "function" || !isHeld(redact))
43
+ throw new TypeError(`${where} was given no redactor that holds keys (heldRedactor), so it does not run: a key it opened would reach the run's record uncut`);
44
+ return redact;
45
+ }
39
46
  /** `base`, then every value held since (`hold`). One that holds already is itself: wrapped once, the one instance. */
40
47
  export function heldRedactor(base) {
41
48
  if (isHeld(base))
@@ -1,10 +1,10 @@
1
1
  import type { Duplex } from "node:stream";
2
2
  import { type GenAiTracing } from "../otel/tracer.js";
3
- import { type HeldRedact, type Redact } from "./redact.js";
3
+ import { type HeldRedact } from "./redact.js";
4
4
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
5
5
  import type { ClaudeAgentLogin } from "@parcha/agentrun-harness-claude";
6
6
  import type { Held } from "./held.js";
7
- import { type Claim, type LoopFactory } from "./loop-contract.js";
7
+ import { type Claim, type Loop, type LoopDeps, type LoopFactory } from "./loop-contract.js";
8
8
  import { Channel } from "./run-channel.js";
9
9
  import { type RunBigWrites } from "./big-writes.js";
10
10
  import { type SaveSlots } from "../web-save.js";
@@ -126,9 +126,10 @@ interface ClaimReads {
126
126
  * run's start (claudeLogin), handing it only when both reads name the same folder. */
127
127
  readonly login: ClaudeAgentLogin | undefined;
128
128
  }
129
- /** The runner's redactor as the host side of a run's process holds it (LoopDeps.redact): its cut, and the carry of a
130
- * value into what it cuts from the run's journal, which a token the runner hands the run needs (claudeLogin). */
131
- export type RunnerCut = Redact & Partial<Pick<HeldRedact, "carry">>;
129
+ /** The runner's redactor as the host side of a run's process holds it (LoopDeps.redact): its cut, the carry of a value
130
+ * into what it cuts from the run's journal, which a token the runner hands the run needs (claudeLogin), and the hold of
131
+ * each credential the claim opens, refreshes or mints for the run, which its MCP will not start without (mustHold). */
132
+ export type RunnerCut = HeldRedact;
132
133
  /** Held (held.ts) for one claim, on the runner: each answer the claim's own, read with the runner's seal key from the
133
134
  * runner's own reads of the claim; every argument from the run's process is checked or ignored. `bigs`: the run's pieced
134
135
  * writes (big-writes.ts), let go at the claim's release and, by the caller, when the run's channel ends. */
@@ -185,7 +186,8 @@ export { RECIPE_SIGN_IN_PERSON_ONLY } from "./harness-loops.js";
185
186
  * own like any other. A run that is a process of its own is handed the login this claim read (`login`, ClaimReads): a
186
187
  * claim that read it off is never put on it, so a turn-on landing after it never puts the run on a login whose refusals
187
188
  * here it was never checked against; a claim that read it on has its runner read the setting again at the start
188
- * (heldFor claudeLogin), and is refused there, in fixed words, when that read names none or another folder. */
189
+ * (heldFor claudeLogin), and is refused there, in fixed words, when that read names none or another folder. A run that
190
+ * sends no model key (sendsNoModelKey) reads no login at its claim: it is never handed one, so never refused for one. */
189
191
  export type ClaimPlace = {
190
192
  readonly stays: true;
191
193
  } | {
@@ -204,3 +206,5 @@ export declare function runChannel(socket: Duplex, onClose: (why: Error) => void
204
206
  readonly bigs?: RunBigWrites;
205
207
  readonly maxFrame?: number;
206
208
  }): Channel;
209
+ /** `login`: the Claude login this run's claim read (staysInRunner), the one its runner hands the run (ClaimReads). */
210
+ export declare function childLoop(options: ChildLoopsOptions, slots: Slots | undefined, loopDeps: LoopDeps, login: ClaudeAgentLogin | undefined): Loop;