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

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 (93) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +42 -14
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/api-only.d.ts +19 -1
  5. package/dist/api-only.js +38 -3
  6. package/dist/browser-person.d.ts +1 -1
  7. package/dist/browser-person.js +1 -1
  8. package/dist/calendar/tools.js +1 -1
  9. package/dist/cli.js +42 -10
  10. package/dist/console/assets/{backend-QnwGVBeU.js → backend-C9ffXUR5.js} +1 -1
  11. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  12. package/dist/console/assets/{share-pz61zIn9.js → share-B1o5mJ56.js} +2 -2
  13. package/dist/console/assets/{styles-CcceGcu2.js → styles-D_znYrHR.js} +2 -2
  14. package/dist/console/index.html +2 -2
  15. package/dist/console/share.html +2 -2
  16. package/dist/errors.d.ts +1 -0
  17. package/dist/errors.js +2 -0
  18. package/dist/harness-check.js +2 -1
  19. package/dist/harness-recipe.d.ts +13 -2
  20. package/dist/harness-recipe.js +30 -7
  21. package/dist/harness-sign-in.js +2 -1
  22. package/dist/harness-table.d.ts +5 -3
  23. package/dist/harness-table.js +7 -5
  24. package/dist/key-refusal.js +6 -4
  25. package/dist/learn/secrets.d.ts +2 -1
  26. package/dist/learn/secrets.js +2 -2
  27. package/dist/learned-nodes.d.ts +36 -0
  28. package/dist/learned-nodes.js +23 -0
  29. package/dist/local-model.d.ts +144 -0
  30. package/dist/local-model.js +214 -0
  31. package/dist/mcp-probe.d.ts +7 -0
  32. package/dist/mcp-probe.js +7 -0
  33. package/dist/ollama-provider.d.ts +35 -0
  34. package/dist/ollama-provider.js +108 -2
  35. package/dist/openapi.js +59 -7
  36. package/dist/place.d.ts +7 -6
  37. package/dist/place.js +13 -10
  38. package/dist/print.js +1 -1
  39. package/dist/redact/match.d.ts +17 -4
  40. package/dist/redact/match.js +57 -15
  41. package/dist/run-export.js +4 -2
  42. package/dist/run-usage.js +3 -2
  43. package/dist/runner/adapter-loop.d.ts +8 -1
  44. package/dist/runner/adapter-loop.js +100 -20
  45. package/dist/runner/adapter-run-spec.d.ts +3 -5
  46. package/dist/runner/adapter-run-spec.js +26 -43
  47. package/dist/runner/adapters/pi.d.ts +3 -2
  48. package/dist/runner/adapters/pi.js +3 -1
  49. package/dist/runner/audit.d.ts +1 -1
  50. package/dist/runner/cli-run-spec.js +13 -10
  51. package/dist/runner/compare-end.d.ts +1 -1
  52. package/dist/runner/dispatch.js +2 -2
  53. package/dist/runner/harness-loops.d.ts +9 -0
  54. package/dist/runner/harness-loops.js +47 -4
  55. package/dist/runner/held.d.ts +4 -1
  56. package/dist/runner/live-ticker.js +3 -4
  57. package/dist/runner/mcp-claim.js +3 -2
  58. package/dist/runner/mcp-run.d.ts +19 -4
  59. package/dist/runner/mcp-run.js +29 -2
  60. package/dist/runner/metrics.d.ts +4 -0
  61. package/dist/runner/metrics.js +9 -3
  62. package/dist/runner/monid-run.js +3 -1
  63. package/dist/runner/native-loop.js +1 -1
  64. package/dist/runner/redact.d.ts +3 -0
  65. package/dist/runner/redact.js +7 -0
  66. package/dist/runner/run-child-host.js +1 -1
  67. package/dist/runner/sdk-loop.js +5 -3
  68. package/dist/runner/workflow-calls.d.ts +4 -1
  69. package/dist/runner/workflow-calls.js +35 -18
  70. package/dist/runner/workflow-loop.d.ts +1 -1
  71. package/dist/runner/workflow-loop.js +3 -1
  72. package/dist/runner/workflow-spec.d.ts +4 -0
  73. package/dist/runner/workflow-spec.js +18 -13
  74. package/dist/runs-over-store.d.ts +2 -2
  75. package/dist/runs-over-store.js +1 -1
  76. package/dist/secret-cut.js +7 -4
  77. package/dist/secret-rules.js +97 -83
  78. package/dist/server.d.ts +7 -0
  79. package/dist/server.js +97 -34
  80. package/dist/slack.js +2 -1
  81. package/dist/store/postgres/migrate.js +3 -1
  82. package/dist/store-reads/learning.d.ts +5 -4
  83. package/dist/store-reads/learning.js +7 -4
  84. package/dist/tool-plane.d.ts +23 -1
  85. package/dist/tool-plane.js +70 -2
  86. package/dist/tools.d.ts +12 -2
  87. package/dist/tools.js +42 -7
  88. package/dist/trigger-launch-hook.d.ts +2 -2
  89. package/dist/trigger-launch-hook.js +1 -1
  90. package/dist/triggers.d.ts +7 -4
  91. package/dist/triggers.js +4 -4
  92. package/package.json +12 -12
  93. package/dist/console/assets/index-DZi-muIj.js +0 -629
@@ -75,7 +75,7 @@ import { AUDIT_PARKED, withAudit } from "./audit.js";
75
75
  import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
76
76
  import { runPathMetricsOverStore } from "../store-reads/learning.js";
77
77
  import { specBuilt } from "./spec-holds.js";
78
- import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
78
+ import { heldRedactor, holdClaimed, mustHold, runnerSecrets, secretRedactor } from "./redact.js";
79
79
  import { planBeforeRun, PLAN_PROVIDER } from "../chatgpt-plan.js";
80
80
  import { CLAUDE_LOGIN_PROVIDER, loginBeforeRun, loginByToken, loginCli, loginForRun, withClaudeLogin } from "../claude-login.js";
81
81
  import { heldTokenLogin } from "../claude-login-token.js";
@@ -288,6 +288,7 @@ export function cliRunSpecFromLaunch(launch, run, deps, claim) {
288
288
  return specBuilt((holds) => cliSpec(launch, run, deps, claim, holds));
289
289
  }
290
290
  async function cliSpec(launch, run, deps, claim, holds) {
291
+ mustHold(run.redact, "A CLI run's spec");
291
292
  const context = BACKGROUND_CONTEXT;
292
293
  // What this claim may reach on loopback, read once for its MCP servers and its calendar_events alike (mcpReachOf).
293
294
  const reach = await mcpReachOf(deps);
@@ -319,7 +320,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
319
320
  holds.hold({ scratch: { sweep: () => sweepScratch(harnesses, claim.epoch, [harnesses, scratch, dirname(scratch)]) } });
320
321
  // Every secret the server keeps sealed (store-secrets.ts) held by the runner's one redactor (the loop's) and this spec's
321
322
  // log cut, before any of the run's text is written: a run's text may quote one it was never handed.
322
- for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
323
+ for (const redact of [run.redact, cut])
323
324
  await holdStored(redact, deps.store, deps.sealKey, deps.data);
324
325
  const revisionRow = await deps.store.agents.revision(runRow.revisionId);
325
326
  if (!revisionRow)
@@ -400,7 +401,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
400
401
  // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
401
402
  // credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
402
403
  // Before the session opens: a refusal (a granted tool its pin does not hold, a pinned meta tool) ends the run in its words.
403
- // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
404
+ // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors. A
405
+ // per_run server the run was handed no credential for is left out of its tools, and its timeline says so; not on a
406
+ // harness whose tools are fixed at its thread's start (AdapterFacts.toolsFixedAtStart), where it would never come back.
404
407
  // A held run its model kept from running at its create (hold.refused) opens none: nothing can call one.
405
408
  const heldRefusal = launch.hold?.refused?.message;
406
409
  // What its gateway files (a long answer, a server's results) goes in the run's own files. In Mode 1 that is the run's
@@ -411,9 +414,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
411
414
  // and a call reaches it only through the session this spec returns, after `tools` is made. After the run's Workspace,
412
415
  // as the pi spec makes it: a refusal lets the Workspace and the Archil claim go (holds above).
413
416
  let filedIn;
414
- const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
417
+ const hold = (values) => { for (const redact of [run.redact, cut])
415
418
  redact.hold(values); };
416
- const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, toolSettings: body.toolSettings, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, web, launch) });
419
+ const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, toolSettings: body.toolSettings, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, say: (words) => run.phase?.(words), ...(facts.toolsFixedAtStart ? { toolsFixedAtStart: true } : {}), ...claimMetering(deps, web, launch) });
417
420
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
418
421
  holds.hold({ passed: mcp });
419
422
  // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
@@ -514,7 +517,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
514
517
  const keyed = keyedAtClaim(runKey);
515
518
  if (keyed)
516
519
  withoutModelKeys(claimed);
517
- for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut]) {
520
+ for (const redact of [run.redact, cut]) {
518
521
  holdClaimed(redact, claimed);
519
522
  if (runKey)
520
523
  holdRunKey(redact, runKey);
@@ -681,7 +684,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
681
684
  const ctx = hostToolCtxOf(run, context, results, root);
682
685
  // The runner's one redactor (the loop's), else this spec's log cut: the claim's keys join it, and the answers of the tools
683
686
  // that run on them pass it.
684
- const held = run.redact ? heldRedactor(run.redact) : cut;
687
+ const held = run.redact;
685
688
  // The run's monid endpoints (monid-run.ts), one host tool each from its revision's pin, on the claim's keys and beside
686
689
  // its MCP tools in the loop's one catalog seam; their answers pass the redactors as the web tools' do.
687
690
  const monid = monidForClaim(revisionRow.monidPin ?? undefined, { ...claimed }, () => ws.workspace, claim.runId, () => launch.maxCostUsd !== undefined, fakes?.monid);
@@ -805,7 +808,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
805
808
  // A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
806
809
  // withAudit): at its end, so the shadow's cap is what the run's own left.
807
810
  // A held run (no audits) takes none, as on pi.
808
- const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
811
+ const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, log, redact: run.redact }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
809
812
  store: deps.store,
810
813
  data: deps.data,
811
814
  ...(deps.env ? { env: deps.env } : {}),
@@ -818,7 +821,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
818
821
  log,
819
822
  // A workflow draft's decision nodes are checked against the host's decision providers, on its keys (LS-07).
820
823
  decisionProviders: async () => decisionProvidersIn({ ...(deps.env ?? {}), ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, DECISION_PROVIDER_KEYS)) }),
821
- }), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
824
+ }), { ...audits, launch, redact: run.redact });
822
825
  return {
823
826
  adapter,
824
827
  facts: factsOn(ownerFacts, chosen.model),
@@ -888,7 +891,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
888
891
  const metrics = cliRunMetrics(piShaped(entries), booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}`, catalog: await hashedMcpOf(deps.store, claim.runId) });
889
892
  // Its cost is endCost's, read apart (an unknown one written as null, never left out: a follow-up's end clears the
890
893
  // cost an earlier end stored).
891
- return { metrics: { ...metrics, ...(await runPathMetricsOverStore(deps.store, claim.runId, launch, { ...(run.redact ? { redact: run.redact } : {}), choice: firstChoice.reason })), costBasis: costBasisOf(booked) } };
894
+ return { metrics: { ...metrics, ...(await runPathMetricsOverStore(deps.store, claim.runId, launch, { redact: run.redact, choice: firstChoice.reason })), costBasis: costBasisOf(booked) } };
892
895
  },
893
896
  // A run started with hold: true holds its computer for its owner (computer-held.ts), as the pi spec's.
894
897
  ...(heldComputer ? { held: heldComputer } : {}),
@@ -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
@@ -85,7 +85,7 @@ function dispatchLoop(deps, loopDeps) {
85
85
  if (earlyStop) {
86
86
  inner.stop(earlyStop).catch((error) => {
87
87
  const text = error?.message ?? String(error);
88
- console.warn(`[runner] run ${claim.runId}: its stop failed: ${loopDeps.redact ? loopDeps.redact(text) : text}`);
88
+ console.warn(`[runner] run ${claim.runId}: its stop failed: ${loopDeps.redact(text)}`);
89
89
  });
90
90
  }
91
91
  return end;
@@ -110,7 +110,7 @@ function dispatchLoop(deps, loopDeps) {
110
110
  // What went wrong, cut of the values the run holds (LoopDeps.redact), as the log may not show them.
111
111
  const why = () => {
112
112
  const text = lastError?.message ?? String(lastError);
113
- return loopDeps.redact ? loopDeps.redact(text) : text;
113
+ return loopDeps.redact(text);
114
114
  };
115
115
  const failed = [];
116
116
  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,14 @@ 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
+ /** `launch` as this claim runs it: its plane, resolved at the run's start, under the server's tool settings now
34
+ * (tool-plane.ts claimPlane), so a resume, a follow-up or a reclaim after the server set web_fetch to kernel, or
35
+ * web_search to native or off, sends nothing past that setting, whatever its agent picked. Settings that could not be
36
+ * read fail closed: a capability kept on a keyless third party or on Parallel runs nothing (SETTINGS_NOT_READ), and
37
+ * the gate refuses every tool besides (storeSettings). It resolves on the run's pinned model (the launch's, chosen at
38
+ * its start), never the host's default in this environment, which holds no key saved on the server (claim-secrets.ts
39
+ * opens those later), and with the saved keys' names (savedNamesOver) for the route its model requests take. */
40
+ export declare function underServerCeilings(deps: AdapterSpecDeps, launch: RunLaunch, revision: Revision): Promise<RunLaunch>;
32
41
  /** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
33
42
  * dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
34
43
  * 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 {
@@ -73,23 +78,61 @@ function holdingGatewayKey(made, env) {
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
+ const { settings, unreadable } = await storeSettings(deps.store);
96
+ const unread = unreadable === true;
97
+ const tooling = await toolingOf(revision);
98
+ if (!overCeilings(launch.plane, tooling, settings, { unread }))
99
+ return launch;
100
+ const model = launch.model ? `${launch.model.provider}/${launch.model.modelId}` : undefined;
101
+ const plane = claimPlane(launch.plane, unread ? deps.env ?? process.env : await savedNamesOver(deps), tooling, settings, { capped: launch.maxCostUsd !== undefined, unread, ...(model ? { model } : {}) });
102
+ return { ...launch, plane };
103
+ }
104
+ /** `deps.env` where a key saved on the server, not set in it, is present by name: its row read, never opened (its value
105
+ * a stand-in only a resolution's presence checks read), for a plane resolved in it alone, never handed on. A runner
106
+ * 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
107
+ * its environment already holds. */
108
+ async function savedNamesOver(deps) {
109
+ const env = deps.env ?? process.env;
110
+ if (!deps.sealKey)
111
+ return env;
112
+ const names = (await sealedKeyNames(deps.store)).filter((name) => SECRET_NAMES.includes(name) && !env[name]);
113
+ if (!names.length)
114
+ return env;
115
+ // Over `env` (its prototype), so its own secrets and marks (non-enumerable, or symbols) still read.
116
+ const out = Object.create(env);
117
+ for (const name of names)
118
+ Object.defineProperty(out, name, { value: "saved", enumerable: false });
119
+ return out;
120
+ }
81
121
  /** The loop a claimed run runs on, over `deps` (the saved gateway laid over its environment). */
82
122
  async function loopOn(deps, harness, launch, runId) {
83
123
  // A workflow revision runs on the workflow loop whatever the harness its body names (its default is pi): read the
84
124
  // revision to tell it apart from an agentic pi run.
85
125
  const run = await deps.store.runs.get(runId);
86
126
  const revision = run ? await deps.store.agents.revision(run.revisionId) : undefined;
127
+ // The plane this claim hands every reader (the secrets, the tools, the run's process), read once here, before any binds.
128
+ if (revision)
129
+ launch = await underServerCeilings(deps, launch, revision);
87
130
  if (revision && isWorkflowRevision(revision)) {
88
131
  // A workflow run on the workflow loop: its claim-time spec (workflow-spec.ts) resolves each tier's model the one way
89
132
  // the runner resolves any (routeProviderOf over the route, the default when no providerOf is given).
90
133
  // The runner's seal key and data directory go with it: a claim's sealed secrets are read with them (claim-secrets.ts,
91
134
  // 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 } : {}) }));
135
+ return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}), ...(launch.plane ? { plane: launch.plane } : {}) }));
93
136
  }
94
137
  // 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
138
  // 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
@@ -65,10 +65,9 @@ export function withLiveTicker(store, createLoop, options = {}) {
65
65
  };
66
66
  deps.signal.addEventListener("abort", onAbort, { once: true });
67
67
  // 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;
68
+ // (a key its claim opened), and the live view is read by people and consoles. A loop whose redactor does not know its
69
+ // values has no live view: a value still streaming, a number or an object's names cannot be cut by text alone.
70
+ const values = deps.redact.heldValues;
72
71
  const loop = createLoop({
73
72
  ...deps,
74
73
  live: (read) => {
@@ -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
@@ -92,6 +92,12 @@ export interface ClaimMcp {
92
92
  /** One host tool per pinned tool, under its wire name, on every harness. Each reaches the gateway only as the loop
93
93
  * wraps it, behind the run's one gate (the gate before the intent); nothing else does. */
94
94
  readonly tools: readonly HostTool[];
95
+ /** The pinned servers whose credential comes from each run (a per_run server, a per-run Composio server) that this run
96
+ * was handed none for (UNUSABLE.perRunMissing) when the claim opened them: every call of their tools is refused
97
+ * unsent. mcpWhereHeld leaves their tools out where the harness takes its tools again at each claim. */
98
+ readonly unconnected: readonly string[];
99
+ /** The servers whose tools mcpWhereHeld left out of `tools` (of `unconnected`); none where it left none out. */
100
+ readonly leftOut?: readonly string[];
95
101
  /** A pinned tool's catalog name (`mcp:<server>/<tool>`) by its wire name; undefined for any other tool. */
96
102
  catalogOf(tool: string): string | undefined;
97
103
  /** The top-level arguments a pinned tool's listing declares (its inputSchema's `properties`, as the run's pin holds it
@@ -105,9 +111,10 @@ export interface ClaimMcp {
105
111
  /** A pinned tool's effect (`mcp:<server>/<tool>`), by its annotations as the pin holds them (tool-gate.ts toolEffect):
106
112
  * what the gate's "allow reads" and a destructive call's card read; never a later listing. Undefined for any other. */
107
113
  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>;
114
+ /** The claim step's credentials opened again on the same pin (an expired OAuth token refreshed, a per_run one a
115
+ * message handed), then the claim confirmed: before a resumed loop's next model request. Answers the servers still
116
+ * handed no credential, as `unconnected` reads at the claim. */
117
+ fresh(): Promise<readonly string[]>;
111
118
  /** Drops every credential held: the pass ended, the claim is lost, or its signal aborted. */
112
119
  release(): void;
113
120
  }
@@ -124,7 +131,15 @@ export declare function heldMcpOf(mcp: ClaimMcp, cut: (text: string) => string):
124
131
  /** The claim's MCP in the run's own process (run-child.ts), from what its runner holds (heldMcpOf). */
125
132
  export declare function claimMcpOfHeld(held: HeldMcp): ClaimMcp;
126
133
  /** 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. */
134
+ * record of each call appended to the run's root through this process's own harness.
135
+ * The tools of a server the run was handed no credential for (ClaimMcp.unconnected) are left out, so the model is never
136
+ * offered a tool every call of which would be refused, and each such server is said once a claim, by `say` (the spec's
137
+ * AdapterRun.phase: a row of the run's timeline); a message that hands the credential brings them back at the run's
138
+ * 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
139
+ * out there, they would never come back, so they stay listed and their calls are refused unsent until the credential
140
+ * comes. */
128
141
  export declare function mcpWhereHeld(options: Omit<McpForClaimOptions, "sealKey"> & {
129
142
  readonly sealKey: Buffer | undefined;
143
+ readonly say?: (words: string) => void;
144
+ readonly toolsFixedAtStart?: boolean;
130
145
  }): Promise<ClaimMcp | undefined>;
@@ -8,6 +8,7 @@ import { fakeSaveOptions } from "../web-fake.js";
8
8
  import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
9
9
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
10
10
  import { mcpNameOf } from "../tool-names.js";
11
+ import { UNUSABLE, unconnectedWords } from "../mcp-probe.js";
11
12
  import { mcpToolName, permissionKeys, pinnedEffect } from "../tool-gate.js";
12
13
  import { mcpClaim } from "./mcp-claim.js";
13
14
  import { registryListing } from "../mcp-pin-first.js";
@@ -94,6 +95,10 @@ export async function mcpForClaim(options) {
94
95
  const catalog = new Map();
95
96
  const declared = new Map();
96
97
  const tools = [];
98
+ // A server the run was handed no credential for: the gateway refuses every call of it unsent, in those words, until a
99
+ // message hands one. Its tools are still listed here; mcpWhereHeld leaves them out where that is safe.
100
+ const unconnectedNow = () => Object.keys(pin).filter((server) => step.credentials[server]?.unopened === UNUSABLE.perRunMissing);
101
+ const unconnected = unconnectedNow();
97
102
  for (const [server, pinned] of Object.entries(pin)) {
98
103
  for (const tool of pinned.tools) {
99
104
  const name = mcpToolName(server, tool.name);
@@ -117,6 +122,7 @@ export async function mcpForClaim(options) {
117
122
  }
118
123
  return {
119
124
  tools,
125
+ unconnected,
120
126
  catalogOf: (tool) => catalog.get(tool),
121
127
  argumentsOf: (name) => declared.get(name),
122
128
  priceOf(name) {
@@ -130,7 +136,10 @@ export async function mcpForClaim(options) {
130
136
  return meterNamed(pinned.url, pinned.meter) && falBills(parsed.tool) ? "priced by usage" : "not metered";
131
137
  },
132
138
  effectOf: (name) => pinnedEffect(pin, name),
133
- fresh: () => step.fresh(),
139
+ fresh: async () => {
140
+ await step.fresh();
141
+ return unconnectedNow();
142
+ },
134
143
  release: () => held.abort(),
135
144
  };
136
145
  }
@@ -162,6 +171,7 @@ export function heldMcpOf(mcp, cut) {
162
171
  },
163
172
  };
164
173
  }),
174
+ unconnected: [...mcp.unconnected],
165
175
  fresh: () => mcp.fresh(),
166
176
  release: async () => mcp.release(),
167
177
  };
@@ -178,6 +188,7 @@ export function claimMcpOfHeld(held) {
178
188
  replay: "never",
179
189
  call: (args, context) => tool.call(args, { ...(context.signal ? { signal: context.signal } : {}), ...(context.callId ? { callId: context.callId } : {}) }),
180
190
  })),
191
+ unconnected: held.unconnected ?? [],
181
192
  catalogOf: (tool) => byWire.get(tool)?.catalog,
182
193
  argumentsOf: (name) => {
183
194
  const declared = byCatalog.get(name)?.arguments;
@@ -190,8 +201,24 @@ export function claimMcpOfHeld(held) {
190
201
  };
191
202
  }
192
203
  /** 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. */
204
+ * record of each call appended to the run's root through this process's own harness.
205
+ * The tools of a server the run was handed no credential for (ClaimMcp.unconnected) are left out, so the model is never
206
+ * offered a tool every call of which would be refused, and each such server is said once a claim, by `say` (the spec's
207
+ * AdapterRun.phase: a row of the run's timeline); a message that hands the credential brings them back at the run's
208
+ * 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
209
+ * out there, they would never come back, so they stay listed and their calls are refused unsent until the credential
210
+ * comes. */
194
211
  export async function mcpWhereHeld(options) {
212
+ const { say, toolsFixedAtStart, ...rest } = options;
213
+ const mcp = await mcpHeld(rest);
214
+ if (!mcp || mcp.unconnected.length === 0 || toolsFixedAtStart)
215
+ return mcp;
216
+ const out = new Set(mcp.unconnected);
217
+ for (const server of mcp.unconnected)
218
+ say?.(unconnectedWords(server));
219
+ return { ...mcp, leftOut: mcp.unconnected, tools: mcp.tools.filter((tool) => !out.has(mcpNameOf(mcp.catalogOf(tool.name) ?? "")?.server ?? "")) };
220
+ }
221
+ async function mcpHeld(options) {
195
222
  if (options.sealKey)
196
223
  return mcpForClaim({ ...options, sealKey: options.sealKey });
197
224
  const at = heldOrThrow("a run's MCP");
@@ -81,6 +81,10 @@ 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. */
87
+ export declare function callTurnsOf(entries: readonly EntryLike[], callId: string, from: number, to: number): Set<unknown>;
84
88
  /** 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
89
  * (costOfParts) over `parts`, its float noise rounded off (floatNoiseOff): `usd` their sum, `upper_bound` when it counts
86
90
  * a cut request at its hold, with `so_far_usd` the charges' own figures alone and `unpriced` how many it counts at their
@@ -176,6 +176,14 @@ 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. */
186
+ export function callTurnsOf(entries, callId, from, to) {
179
187
  const keyed = sessionConversations(entries);
180
188
  const hosted = new Set([keyed.get(TOOL_SESSION), keyed.get(DECISION_SESSION)].filter((one) => one !== undefined));
181
189
  const ours = (e, at) => {
@@ -184,9 +192,7 @@ export function callCostOf(entries, callId, from, to) {
184
192
  return true;
185
193
  return at > from && at <= to && (typeof d.host === "string" || d.side === true || hosted.has(Number(e.conversationId)));
186
194
  };
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;
195
+ return new Set(entries.flatMap((e, at) => (e.kind === RUNNER_RECORDS.request && ours(e, at) ? [turnOf(e)] : [])));
190
196
  }
191
197
  /** A sum of charges with its float noise rounded off, nothing more (as the decisions row rounds, decision-rows.ts): a
192
198
  * 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
  }
@@ -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))
@@ -1208,7 +1208,7 @@ export function runChannel(socket, onClose, gate = SERVER_SLOTS, more = {}) {
1208
1208
  /** `login`: the Claude login this run's claim read (staysInRunner), the one its runner hands the run (ClaimReads). */
1209
1209
  function childLoop(options, slots, loopDeps, login) {
1210
1210
  const { deps, isolation } = options;
1211
- const cut = loopDeps.redact ?? ((text) => text);
1211
+ const cut = loopDeps.redact;
1212
1212
  const log = (line) => options.log(cut(line));
1213
1213
  let channel;
1214
1214
  let child;
@@ -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,8 @@ 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); one an earlier attempt spent under (a crash cut it, and its rerun was refused: at its gate, at
10
+ * runLearned's check of its call nodes' tools, or the platform's at serveFirst) is `failed`, at what it booked. A
11
+ * record that names no digest or caller is left out. */
9
12
  export declare function workflowCallsOf(entries: readonly EntryLike[]): WorkflowCall[];