@tangle-network/agent-runtime 0.40.0 → 0.42.0

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 (44) hide show
  1. package/dist/agent.d.ts +57 -2
  2. package/dist/agent.js +54 -0
  3. package/dist/agent.js.map +1 -1
  4. package/dist/chunk-7JITYN6T.js +72 -0
  5. package/dist/chunk-7JITYN6T.js.map +1 -0
  6. package/dist/{chunk-3WQJRSUJ.js → chunk-BDGYYO7K.js} +3 -3
  7. package/dist/{chunk-6HI3QUJD.js → chunk-HCL2ZG5L.js} +51 -5
  8. package/dist/chunk-HCL2ZG5L.js.map +1 -0
  9. package/dist/{chunk-HSX6PFZR.js → chunk-HVYOHJHK.js} +338 -2
  10. package/dist/chunk-HVYOHJHK.js.map +1 -0
  11. package/dist/{chunk-OISRXLWI.js → chunk-IFG6GX6A.js} +64 -40
  12. package/dist/chunk-IFG6GX6A.js.map +1 -0
  13. package/dist/chunk-NRZOXCJK.js +64 -0
  14. package/dist/chunk-NRZOXCJK.js.map +1 -0
  15. package/dist/{chunk-VFKBIZTY.js → chunk-WMBYQPYM.js} +5 -4
  16. package/dist/chunk-WMBYQPYM.js.map +1 -0
  17. package/dist/delegation-profile-1GbW5yA3.d.ts +73 -0
  18. package/dist/{dynamic-BT9Ji3jE.d.ts → dynamic-B_7GgCwu.d.ts} +1 -1
  19. package/dist/index.d.ts +7 -8
  20. package/dist/index.js +9 -8
  21. package/dist/index.js.map +1 -1
  22. package/dist/{kb-gate-C4tho31v.d.ts → kb-gate-DTBum3vH.d.ts} +9 -1
  23. package/dist/{loop-runner-bin-C1MuoT8c.d.ts → loop-runner-bin-CVoCBmYk.d.ts} +3 -3
  24. package/dist/loop-runner-bin.d.ts +4 -5
  25. package/dist/loop-runner-bin.js +3 -3
  26. package/dist/loops.d.ts +65 -7
  27. package/dist/loops.js +7 -1
  28. package/dist/mcp/bin.js +28 -17
  29. package/dist/mcp/bin.js.map +1 -1
  30. package/dist/mcp/index.d.ts +6 -6
  31. package/dist/mcp/index.js +17 -49
  32. package/dist/mcp/index.js.map +1 -1
  33. package/dist/{otel-export-xgf4J6bo.d.ts → otel-export-BzvF1Ela.d.ts} +1 -1
  34. package/dist/profiles.d.ts +1 -2
  35. package/dist/{types-CNs7_1R3.d.ts → types-Bcp071Jg.d.ts} +488 -3
  36. package/package.json +11 -22
  37. package/dist/chunk-6HI3QUJD.js.map +0 -1
  38. package/dist/chunk-7ZECSZ3C.js +0 -400
  39. package/dist/chunk-7ZECSZ3C.js.map +0 -1
  40. package/dist/chunk-HSX6PFZR.js.map +0 -1
  41. package/dist/chunk-OISRXLWI.js.map +0 -1
  42. package/dist/chunk-VFKBIZTY.js.map +0 -1
  43. package/dist/types-CsCCryln.d.ts +0 -489
  44. /package/dist/{chunk-3WQJRSUJ.js.map → chunk-BDGYYO7K.js.map} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { CoderOutput, CoderTask } from './profiles.js';
2
- import { L as LoopSandboxClient } from './types-CNs7_1R3.js';
2
+ import { L as LoopSandboxClient, c as LoopTraceEmitter } from './types-Bcp071Jg.js';
3
3
  import { SandboxInstance } from '@tangle-network/sandbox';
4
4
 
5
5
  /**
@@ -350,6 +350,14 @@ interface CreateDefaultCoderDelegateOptions {
350
350
  reviewer?: CoderReviewer;
351
351
  /** Winner-selection strategy among eligible candidates. Default `highest-score`. */
352
352
  winnerSelection?: CoderWinnerSelection;
353
+ /**
354
+ * Loop trace emitter forwarded into every delegated `runLoop`. Wire
355
+ * `createPropagatingTraceEmitter(readTraceContextFromEnv())` here (the bin
356
+ * does) so delegated build-loops export their topology spans to the OTLP /
357
+ * Tangle Intelligence sink when `OTEL_EXPORTER_OTLP_ENDPOINT` is set — and
358
+ * are a cheap no-op when it isn't. Configurable by construction.
359
+ */
360
+ traceEmitter?: LoopTraceEmitter;
353
361
  }
354
362
  /**
355
363
  * Build a coder delegate that drives `runLoop` against the project's
@@ -1,9 +1,9 @@
1
1
  import { Scenario } from '@tangle-network/agent-eval/campaign';
2
2
  import { R as RunAnalystLoopOpts, a as RunAnalystLoopResult } from './types-p8dWBIXL.js';
3
3
  import { O as OptimizePromptOptions, a as OptimizePromptResult } from './optimize-prompt-D-urF2wW.js';
4
- import { T as TopologyPlanner, D as DynamicDecision } from './dynamic-BT9Ji3jE.js';
5
- import { L as LoopSandboxClient, O as OutputAdapter, V as Validator, A as AgentRunSpec, a as LoopResult } from './types-CNs7_1R3.js';
6
- import { D as DelegateCodeArgs, C as CoderReviewer, a as CoderWinnerSelection, F as FactCandidate, b as CreateKbGateOptions } from './kb-gate-C4tho31v.js';
4
+ import { T as TopologyPlanner, D as DynamicDecision } from './dynamic-B_7GgCwu.js';
5
+ import { L as LoopSandboxClient, a as OutputAdapter, V as Validator, A as AgentRunSpec, b as LoopResult } from './types-Bcp071Jg.js';
6
+ import { D as DelegateCodeArgs, C as CoderReviewer, a as CoderWinnerSelection, F as FactCandidate, b as CreateKbGateOptions } from './kb-gate-DTBum3vH.js';
7
7
  import { CoderOutput } from './profiles.js';
8
8
 
9
9
  /**
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env node
2
- export { L as LoopRunnerCliArgs, f as LoopRunnerCliResult, p as parseLoopRunnerArgv, o as runLoopRunnerCli } from './loop-runner-bin-C1MuoT8c.js';
2
+ export { L as LoopRunnerCliArgs, f as LoopRunnerCliResult, p as parseLoopRunnerArgv, o as runLoopRunnerCli } from './loop-runner-bin-CVoCBmYk.js';
3
3
  import '@tangle-network/agent-eval/campaign';
4
4
  import './types-p8dWBIXL.js';
5
5
  import '@tangle-network/agent-eval';
6
6
  import './optimize-prompt-D-urF2wW.js';
7
- import './dynamic-BT9Ji3jE.js';
8
- import './types-CNs7_1R3.js';
7
+ import './dynamic-B_7GgCwu.js';
8
+ import './types-Bcp071Jg.js';
9
9
  import '@tangle-network/sandbox';
10
- import './types-CsCCryln.js';
11
- import './kb-gate-C4tho31v.js';
10
+ import './kb-gate-DTBum3vH.js';
12
11
  import './profiles.js';
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  parseLoopRunnerArgv,
4
4
  runLoopRunnerCli
5
- } from "./chunk-3WQJRSUJ.js";
5
+ } from "./chunk-BDGYYO7K.js";
6
6
  import "./chunk-XBUG326M.js";
7
7
  import "./chunk-VOX6Z3II.js";
8
8
  import "./chunk-FNMGYYSS.js";
9
- import "./chunk-VFKBIZTY.js";
10
- import "./chunk-OISRXLWI.js";
9
+ import "./chunk-WMBYQPYM.js";
10
+ import "./chunk-IFG6GX6A.js";
11
11
  import "./chunk-3HMHSN22.js";
12
12
  import "./chunk-PY6NMZYX.js";
13
13
  import "./chunk-SQSCRJ7U.js";
package/dist/loops.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import { AgentProfile, SandboxEvent } from '@tangle-network/sandbox';
1
+ import { AgentProfile, SandboxEvent, SandboxInstance } from '@tangle-network/sandbox';
2
2
  export { AgentProfile, CreateSandboxOptions, SandboxEvent, SandboxInstance } from '@tangle-network/sandbox';
3
- import { P as PlannerContext, T as TopologyPlanner } from './dynamic-BT9Ji3jE.js';
4
- export { C as CreateDynamicDriverOptions, D as DynamicDecision, a as TopologyMove, c as createDynamicDriver, s as summarizeHistory } from './dynamic-BT9Ji3jE.js';
5
- import { D as Driver, I as Iteration, L as LoopSandboxClient, A as AgentRunSpec, O as OutputAdapter, V as Validator, E as ExecCtx, b as LoopWinner, a as LoopResult } from './types-CNs7_1R3.js';
6
- export { c as LoopDecisionPayload, d as LoopEndedPayload, e as LoopIterationDispatchPayload, f as LoopIterationEndedPayload, g as LoopIterationStartedPayload, h as LoopPlanDescription, i as LoopPlanPayload, j as LoopSandboxPlacement, k as LoopStartedPayload, l as LoopTokenUsage, m as LoopTraceEmitter, n as LoopTraceEvent, o as ValidationCtx } from './types-CNs7_1R3.js';
3
+ import { P as PlannerContext, T as TopologyPlanner } from './dynamic-B_7GgCwu.js';
4
+ export { C as CreateDynamicDriverOptions, D as DynamicDecision, a as TopologyMove, c as createDynamicDriver, s as summarizeHistory } from './dynamic-B_7GgCwu.js';
5
+ import { D as Driver, I as Iteration, L as LoopSandboxClient, A as AgentRunSpec, a as OutputAdapter, V as Validator, E as ExecCtx, d as LoopWinner, b as LoopResult, R as RuntimeStreamEvent } from './types-Bcp071Jg.js';
6
+ export { e as LoopDecisionPayload, f as LoopEndedPayload, g as LoopIterationDispatchPayload, h as LoopIterationEndedPayload, i as LoopIterationStartedPayload, j as LoopPlanDescription, k as LoopPlanPayload, l as LoopSandboxPlacement, m as LoopStartedPayload, n as LoopTokenUsage, c as LoopTraceEmitter, o as LoopTraceEvent, p as ValidationCtx } from './types-Bcp071Jg.js';
7
7
  import { DefaultVerdict, AgentProfile as AgentProfile$1 } from '@tangle-network/agent-eval';
8
8
  export { DefaultVerdict } from '@tangle-network/agent-eval';
9
9
  import { Scenario, DispatchFn, ProfileDispatchFn } from '@tangle-network/agent-eval/campaign';
10
- import './types-CsCCryln.js';
11
10
 
12
11
  /**
13
12
  * @experimental
@@ -213,6 +212,13 @@ interface RunLoopOptions<Task, Output, Decision> {
213
212
  }
214
213
  /** @experimental */
215
214
  declare function runLoop<Task, Output, Decision>(options: RunLoopOptions<Task, Output, Decision>): Promise<LoopResult<Task, Output, Decision>>;
215
+ /**
216
+ * Instantiate a sandbox for an `AgentRunSpec`: sets `backend.profile` to the
217
+ * spec's profile (inferring the backend type when the spec doesn't override
218
+ * it) and merges `sandboxOverrides`. Shared by the loop kernel and the
219
+ * `AgentRuntime.act` sandbox bridge so both boot the sandbox identically.
220
+ */
221
+ declare function createSandboxForSpec<Task>(client: LoopSandboxClient, spec: AgentRunSpec<Task>, signal: AbortSignal): Promise<SandboxInstance>;
216
222
 
217
223
  /**
218
224
  * `loopDispatch` — turn `runLoop` into an agent-eval campaign dispatch.
@@ -312,4 +318,56 @@ interface UsageSink {
312
318
  */
313
319
  declare function reportLoopUsage<Task, Output, Decision>(cost: UsageSink, result: Pick<LoopResult<Task, Output, Decision>, 'costUsd' | 'tokenUsage'>, source?: string): void;
314
320
 
315
- export { AgentRunSpec, type CreateFanoutVoteDriverOptions, type CreateRefineDriverOptions, type CreateSandboxPlannerOptions, Driver, ExecCtx, type FanoutVoteDecision, type FanoutVoteScored, Iteration, type LoopDispatchOptions, type LoopOptionsForDispatch, LoopResult, LoopSandboxClient, LoopWinner, OutputAdapter, PlannerContext, type RefineDecision, type RunLoopOptions, type TopologyMoveEnvelope, TopologyPlanner, type UsageSink, Validator, createFanoutVoteDriver, createRefineDriver, createSandboxPlanner, loopCampaignDispatch, loopDispatch, refineWinnerIndex, reportLoopUsage, runLoop, scoreFanoutVoteIterations };
321
+ /**
322
+ * Sandbox-event → runtime-event mapping.
323
+ *
324
+ * The sandbox SDK emits a polymorphic `SandboxEvent = { type, data, id? }`
325
+ * whose `type` vocabulary is backend-determined (opencode, etc.) rather than
326
+ * enumerated by the SDK. Two consumers project it:
327
+ * - the loop kernel's cost ledger (`extractLlmCallEvent`) — sums usage off
328
+ * every cost-bearing event, regardless of stream shape;
329
+ * - the `AgentRuntime.act` streaming contract (`mapSandboxEvent`) — projects
330
+ * incremental events to the `RuntimeStreamEvent` chat-UX vocabulary.
331
+ *
332
+ * Both live here so the empirically-observed `type` vocabulary has one home.
333
+ */
334
+
335
+ /**
336
+ * Extract a `RuntimeStreamEvent`-shaped `llm_call` from a sandbox event when
337
+ * the event carries usage/cost data. Returns `undefined` for non-cost events
338
+ * so the kernel can iterate the full stream without branching.
339
+ *
340
+ * Canonical cost-carrying types observed in the wild:
341
+ * - `llm_call` — `data: { model, tokensIn, tokensOut, costUsd, ... }`
342
+ * - `message.completed` / `result` — `data: { usage: { inputTokens,
343
+ * outputTokens, totalCostUsd? } }`
344
+ * - `cost.usage` / `usage` — same shape under a dedicated type
345
+ *
346
+ * Numeric coercion is strict: `Number.isFinite` gates every accumulator write
347
+ * so a sentinel `NaN` from a misbehaving backend cannot poison the ledger.
348
+ */
349
+ declare function extractLlmCallEvent(event: SandboxEvent, agentRunName: string): (RuntimeStreamEvent & {
350
+ type: 'llm_call';
351
+ }) | undefined;
352
+ /**
353
+ * Project one `SandboxEvent` onto the `RuntimeStreamEvent` chat-UX vocabulary,
354
+ * for runtimes that bridge a sandbox `streamPrompt` into the
355
+ * `AgentRuntime.act` streaming contract. Returns `undefined` for events that
356
+ * have no faithful projection — the raw stream is preserved separately for the
357
+ * `OutputAdapter`, so an unmapped event never loses data.
358
+ *
359
+ * Mapped (the task-optional incremental variants — no synthesized task
360
+ * lifecycle, no guessed tool-part shapes):
361
+ * - `message.part.updated` text part → `text_delta`
362
+ * - `message.part.updated` reasoning/thinking part → `reasoning_delta`
363
+ * - cost-bearing events → `llm_call` (shared with the ledger extractor)
364
+ *
365
+ * The opencode backend emits incremental text as
366
+ * `{ type: 'message.part.updated', data: { part: { type, text }, delta } }`;
367
+ * `delta` is the increment, `part.text` the running accumulation.
368
+ */
369
+ declare function mapSandboxEvent(event: SandboxEvent, opts?: {
370
+ agentRunName?: string;
371
+ }): RuntimeStreamEvent | undefined;
372
+
373
+ export { AgentRunSpec, type CreateFanoutVoteDriverOptions, type CreateRefineDriverOptions, type CreateSandboxPlannerOptions, Driver, ExecCtx, type FanoutVoteDecision, type FanoutVoteScored, Iteration, type LoopDispatchOptions, type LoopOptionsForDispatch, LoopResult, LoopSandboxClient, LoopWinner, OutputAdapter, PlannerContext, type RefineDecision, type RunLoopOptions, type TopologyMoveEnvelope, TopologyPlanner, type UsageSink, Validator, createFanoutVoteDriver, createRefineDriver, createSandboxForSpec, createSandboxPlanner, extractLlmCallEvent, loopCampaignDispatch, loopDispatch, mapSandboxEvent, refineWinnerIndex, reportLoopUsage, runLoop, scoreFanoutVoteIterations };
package/dist/loops.js CHANGED
@@ -1,14 +1,17 @@
1
1
  import {
2
2
  createDynamicDriver,
3
3
  createRefineDriver,
4
+ createSandboxForSpec,
4
5
  createSandboxPlanner,
6
+ extractLlmCallEvent,
5
7
  loopCampaignDispatch,
6
8
  loopDispatch,
9
+ mapSandboxEvent,
7
10
  refineWinnerIndex,
8
11
  reportLoopUsage,
9
12
  runLoop,
10
13
  summarizeHistory
11
- } from "./chunk-OISRXLWI.js";
14
+ } from "./chunk-IFG6GX6A.js";
12
15
  import {
13
16
  createFanoutVoteDriver,
14
17
  scoreFanoutVoteIterations
@@ -19,9 +22,12 @@ export {
19
22
  createDynamicDriver,
20
23
  createFanoutVoteDriver,
21
24
  createRefineDriver,
25
+ createSandboxForSpec,
22
26
  createSandboxPlanner,
27
+ extractLlmCallEvent,
23
28
  loopCampaignDispatch,
24
29
  loopDispatch,
30
+ mapSandboxEvent,
25
31
  refineWinnerIndex,
26
32
  reportLoopUsage,
27
33
  runLoop,
package/dist/mcp/bin.js CHANGED
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createMcpServer,
4
- detectExecutor
5
- } from "../chunk-6HI3QUJD.js";
6
- import "../chunk-HSX6PFZR.js";
4
+ createPropagatingTraceEmitter,
5
+ detectExecutor,
6
+ readTraceContextFromEnv
7
+ } from "../chunk-HCL2ZG5L.js";
8
+ import "../chunk-HVYOHJHK.js";
7
9
  import {
8
10
  createDefaultCoderDelegate
9
- } from "../chunk-VFKBIZTY.js";
11
+ } from "../chunk-WMBYQPYM.js";
10
12
  import "../chunk-GLR25NG7.js";
11
13
  import {
12
14
  runLoop
13
- } from "../chunk-OISRXLWI.js";
15
+ } from "../chunk-IFG6GX6A.js";
14
16
  import "../chunk-3HMHSN22.js";
15
17
  import "../chunk-PY6NMZYX.js";
16
18
  import "../chunk-SQSCRJ7U.js";
@@ -49,21 +51,30 @@ async function main() {
49
51
  process.stderr.write(`agent-runtime-mcp: delegation placement \u2192 ${executor.describe()}
50
52
  `);
51
53
  }
54
+ const { emitter: traceEmitter, exporter: traceExporter } = createPropagatingTraceEmitter(
55
+ readTraceContextFromEnv()
56
+ );
57
+ if (process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
58
+ process.stderr.write(
59
+ `agent-runtime-mcp: exporting loop topology \u2192 ${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}
60
+ `
61
+ );
62
+ }
52
63
  const coderDelegate = wantCoder && executor ? createDefaultCoderDelegate({
53
64
  executor,
54
65
  fanoutHarnesses,
55
- maxConcurrency
66
+ maxConcurrency,
67
+ traceEmitter
56
68
  }) : void 0;
57
- const researcherDelegate = wantResearcher && executor ? await loadResearcherDelegate(executor.client, maxConcurrency) : void 0;
69
+ const researcherDelegate = wantResearcher && executor ? await loadResearcherDelegate(executor.client, maxConcurrency, traceEmitter) : void 0;
58
70
  const server = createMcpServer({ coderDelegate, researcherDelegate });
59
- process.on("SIGINT", () => {
71
+ const shutdown = () => {
60
72
  server.stop();
61
- process.exit(0);
62
- });
63
- process.on("SIGTERM", () => {
64
- server.stop();
65
- process.exit(0);
66
- });
73
+ void traceExporter?.shutdown().finally(() => process.exit(0));
74
+ if (!traceExporter) process.exit(0);
75
+ };
76
+ process.on("SIGINT", shutdown);
77
+ process.on("SIGTERM", shutdown);
67
78
  await server.serve();
68
79
  }
69
80
  async function loadSandboxClient(apiKey) {
@@ -96,7 +107,7 @@ async function loadSandboxClient(apiKey) {
96
107
  ...baseUrl ? { baseUrl } : {}
97
108
  });
98
109
  }
99
- async function loadResearcherDelegate(sandboxClient, maxConcurrency) {
110
+ async function loadResearcherDelegate(sandboxClient, maxConcurrency, traceEmitter) {
100
111
  const profilesSpecifier = "@tangle-network/agent-knowledge/profiles";
101
112
  const mod = await import(profilesSpecifier).catch(() => void 0);
102
113
  if (!mod) return void 0;
@@ -134,7 +145,7 @@ async function loadResearcherDelegate(sandboxClient, maxConcurrency) {
134
145
  output: preset.output,
135
146
  validator: preset.validator,
136
147
  task,
137
- ctx: { sandboxClient, signal: ctx.signal },
148
+ ctx: { sandboxClient, signal: ctx.signal, ...traceEmitter ? { traceEmitter } : {} },
138
149
  maxIterations: 1,
139
150
  maxConcurrency
140
151
  });
@@ -150,7 +161,7 @@ async function loadResearcherDelegate(sandboxClient, maxConcurrency) {
150
161
  output: fanout.output,
151
162
  validator: fanout.validator,
152
163
  task,
153
- ctx: { sandboxClient, signal: ctx.signal },
164
+ ctx: { sandboxClient, signal: ctx.signal, ...traceEmitter ? { traceEmitter } : {} },
154
165
  maxIterations: variants,
155
166
  maxConcurrency: Math.min(maxConcurrency, variants)
156
167
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mcp/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * @experimental\n *\n * `agent-runtime-mcp` — stdio MCP server entry point.\n *\n * Spins up a server with the default coder delegate (wired against the\n * real `@tangle-network/sandbox` client) and, when the optional\n * `@tangle-network/agent-knowledge` peer is installed, a researcher\n * delegate against `multiHarnessResearcherFanout`.\n *\n * Environment variables:\n * TANGLE_API_KEY required — passed to `new Sandbox({ apiKey })`\n * SANDBOX_BASE_URL optional — sandbox-SDK base URL override\n * TANGLE_FLEET_ID optional — when set, delegations dispatch\n * INTO this fleet's shared workspace instead\n * of creating sibling sandboxes. Set by the\n * parent sandbox when launching this MCP\n * server so worker diffs land on the caller's\n * filesystem with no cross-sandbox boundary.\n * TANGLE_FLEET_EXCLUDE_MACHINES optional — comma-separated machine ids to\n * skip during fleet-mode round-robin\n * (typically the coordinator machine this\n * MCP server is running on).\n * MCP_MAX_CONCURRENT_SANDBOXES default 4 — kernel maxConcurrency cap\n * MCP_CODER_FANOUT_HARNESSES comma-separated harness ids to use for variants > 1\n * MCP_DISABLE_CODER set to `1` to omit `delegate_code`\n * MCP_DISABLE_RESEARCHER set to `1` to omit `delegate_research` even when peer is present\n */\n\nimport type { LoopSandboxClient } from '../loops'\nimport { runLoop } from '../loops'\nimport { detectExecutor } from './bin-helpers'\nimport { createDefaultCoderDelegate, type ResearcherDelegate } from './delegates'\nimport type { DelegationExecutor } from './executor'\nimport { createMcpServer } from './server'\nimport type { ResearchOutputShape } from './types'\n\nasync function main(): Promise<void> {\n const fanoutHarnesses = parseHarnesses(process.env.MCP_CODER_FANOUT_HARNESSES)\n const maxConcurrency = parseConcurrency(process.env.MCP_MAX_CONCURRENT_SANDBOXES)\n const wantCoder = !process.env.MCP_DISABLE_CODER\n const wantResearcher = !process.env.MCP_DISABLE_RESEARCHER\n const fleetId = parseFleetId(process.env.TANGLE_FLEET_ID)\n\n // Skip the sandbox client load entirely when no profile delegate needs it —\n // the feedback + status + history tools are queue-bound and require no\n // sandbox. Useful for tooling that mounts the MCP server purely for\n // self-introspection.\n const needsSandbox = wantCoder || wantResearcher\n let sandboxClient: LoopSandboxClient | undefined\n let executor: DelegationExecutor | undefined\n if (needsSandbox) {\n const apiKey = process.env.TANGLE_API_KEY\n if (!apiKey && !process.env.AGENT_RUNTIME_MCP_ALLOW_NO_KEY) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_API_KEY is required. Set AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 to run without it for diagnostics, or MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to run the queue-only subset.\\n',\n )\n process.exit(2)\n }\n // Fleet mode against a diagnostic stub is meaningless — the stub can't\n // resolve a real fleet handle. Refuse rather than silently degrading,\n // otherwise a fleet-mounted MCP would behave differently than configured.\n if (fleetId && !apiKey) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_FLEET_ID was set but TANGLE_API_KEY is missing; cannot resolve fleet handle. Provide an api key or unset TANGLE_FLEET_ID.\\n',\n )\n process.exit(2)\n }\n sandboxClient = await loadSandboxClient(apiKey)\n executor = await detectExecutor({ sandboxClient })\n if (fleetId) {\n process.stderr.write(`agent-runtime-mcp: fleet-aware delegation: fleetId=${fleetId}\\n`)\n }\n process.stderr.write(`agent-runtime-mcp: delegation placement → ${executor.describe()}\\n`)\n }\n\n const coderDelegate =\n wantCoder && executor\n ? createDefaultCoderDelegate({\n executor,\n fanoutHarnesses,\n maxConcurrency,\n })\n : undefined\n\n const researcherDelegate =\n wantResearcher && executor\n ? await loadResearcherDelegate(executor.client, maxConcurrency)\n : undefined\n\n const server = createMcpServer({ coderDelegate, researcherDelegate })\n\n process.on('SIGINT', () => {\n server.stop()\n process.exit(0)\n })\n process.on('SIGTERM', () => {\n server.stop()\n process.exit(0)\n })\n\n await server.serve()\n}\n\nasync function loadSandboxClient(apiKey: string | undefined): Promise<LoopSandboxClient> {\n // Diagnostic mode: AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 enables tools/list + the\n // queue-bound tools (status / history / feedback) without sandbox creds.\n // Coder + researcher delegations require a real client; the stub fails loud\n // at create() so the agent observes the cause instead of silent success.\n if (!apiKey) {\n return {\n async create() {\n throw new Error(\n 'agent-runtime-mcp: TANGLE_API_KEY is unset; coder/researcher delegations are disabled in diagnostic mode. Set TANGLE_API_KEY or use MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to remove the unsupported tools from the tool list.',\n )\n },\n } satisfies LoopSandboxClient\n }\n // Dynamic import keeps the bin importable in environments that haven't\n // installed `@tangle-network/sandbox` yet (the runtime package lists it\n // as a peer dep, not a hard dep).\n const mod = await import('@tangle-network/sandbox').catch((err) => {\n process.stderr.write(\n `agent-runtime-mcp: failed to load @tangle-network/sandbox (${err.message}); install the peer dependency\\n`,\n )\n process.exit(2)\n })\n const SandboxCtor = (mod as { Sandbox?: new (config: unknown) => LoopSandboxClient }).Sandbox\n if (!SandboxCtor) {\n process.stderr.write(\n 'agent-runtime-mcp: @tangle-network/sandbox does not export Sandbox; cannot construct client\\n',\n )\n process.exit(2)\n }\n const baseUrl = process.env.SANDBOX_BASE_URL\n return new SandboxCtor({\n apiKey,\n ...(baseUrl ? { baseUrl } : {}),\n })\n}\n\ninterface ResearcherProfilePreset {\n agentRunSpec: Parameters<typeof runLoop>[0]['agentRun'] extends infer T ? NonNullable<T> : never\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n}\n\ninterface ResearcherFanoutPreset {\n agentRuns: NonNullable<Parameters<typeof runLoop>[0]['agentRuns']>\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n driver: Parameters<typeof runLoop>[0]['driver']\n}\n\nasync function loadResearcherDelegate(\n sandboxClient: LoopSandboxClient,\n maxConcurrency: number,\n): Promise<ResearcherDelegate | undefined> {\n // Optional peer — when `@tangle-network/agent-knowledge` isn't installed,\n // we silently omit the researcher tool from the advertisement. The\n // dynamic-import path is resolved at runtime; TypeScript cannot see the\n // peer, so we type the module structurally rather than via its own\n // declaration file.\n const profilesSpecifier = '@tangle-network/agent-knowledge/profiles'\n const mod = await import(profilesSpecifier).catch(() => undefined)\n if (!mod) return undefined\n type SingleFactory = (opts: { task: unknown }) => ResearcherProfilePreset\n type FanoutFactory = (opts: { task: unknown }) => ResearcherFanoutPreset\n const fanoutFactory = (mod as { multiHarnessResearcherFanout?: FanoutFactory })\n .multiHarnessResearcherFanout\n const singleFactory = (mod as { researcherProfile?: SingleFactory }).researcherProfile\n if (!fanoutFactory || !singleFactory) return undefined\n\n return async (args, ctx) => {\n const task = {\n question: args.question,\n knowledgeNamespace: args.namespace,\n scope: args.scope,\n sources: args.sources,\n recencyWindow: args.config?.recencyWindow\n ? {\n since: args.config.recencyWindow.since\n ? new Date(args.config.recencyWindow.since)\n : undefined,\n until: args.config.recencyWindow.until\n ? new Date(args.config.recencyWindow.until)\n : undefined,\n }\n : undefined,\n maxItems: args.config?.maxItems,\n minConfidence: args.config?.minConfidence,\n }\n const variants = Math.max(1, Math.trunc(args.variants ?? 1))\n ctx.report({ iteration: 0, phase: 'starting' })\n if (variants <= 1) {\n const preset = singleFactory({ task })\n const result = await runLoop({\n driver: {\n name: 'mcp-researcher-single',\n async plan(t, history) {\n return history.length === 0 ? [t] : []\n },\n decide(history) {\n return history.length > 0 ? 'pick-winner' : 'fail'\n },\n },\n agentRun: preset.agentRunSpec,\n output: preset.output,\n validator: preset.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal },\n maxIterations: 1,\n maxConcurrency,\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate produced no winner')\n ctx.report({ iteration: 1, phase: 'completed' })\n return output as ResearchOutputShape\n }\n const fanout = fanoutFactory({ task })\n const result = await runLoop({\n driver: fanout.driver,\n agentRuns: fanout.agentRuns.slice(0, variants),\n output: fanout.output,\n validator: fanout.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal },\n maxIterations: variants,\n maxConcurrency: Math.min(maxConcurrency, variants),\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate fanout produced no winner')\n ctx.report({ iteration: result.iterations.length, phase: 'completed' })\n return output as ResearchOutputShape\n }\n}\n\nfunction parseHarnesses(raw: string | undefined): string[] | undefined {\n if (!raw) return undefined\n const list = raw\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n return list.length > 0 ? list : undefined\n}\n\nfunction parseFleetId(raw: string | undefined): string | undefined {\n if (typeof raw !== 'string') return undefined\n const trimmed = raw.trim()\n return trimmed.length > 0 ? trimmed : undefined\n}\n\nfunction parseConcurrency(raw: string | undefined): number {\n if (!raw) return 4\n const n = Number(raw)\n if (!Number.isFinite(n) || n < 1) return 4\n return Math.min(Math.trunc(n), 32)\n}\n\nmain().catch((err) => {\n process.stderr.write(`agent-runtime-mcp: ${err instanceof Error ? err.stack : String(err)}\\n`)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuCA,eAAe,OAAsB;AACnC,QAAM,kBAAkB,eAAe,QAAQ,IAAI,0BAA0B;AAC7E,QAAM,iBAAiB,iBAAiB,QAAQ,IAAI,4BAA4B;AAChF,QAAM,YAAY,CAAC,QAAQ,IAAI;AAC/B,QAAM,iBAAiB,CAAC,QAAQ,IAAI;AACpC,QAAM,UAAU,aAAa,QAAQ,IAAI,eAAe;AAMxD,QAAM,eAAe,aAAa;AAClC,MAAI;AACJ,MAAI;AACJ,MAAI,cAAc;AAChB,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,CAAC,UAAU,CAAC,QAAQ,IAAI,gCAAgC;AAC1D,cAAQ,OAAO;AAAA,QAC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IAAI,KAAK;AACzB,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,SAAS,iBAAiB,KAAiC;AACzD,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,IAAI,OAAO,GAAG;AACpB,MAAI,CAAC,OAAO,SAAS,CAAC,KAAK,IAAI,EAAG,QAAO;AACzC,SAAO,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE;AACnC;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,OAAO,MAAM,sBAAsB,eAAe,QAAQ,IAAI,QAAQ,OAAO,GAAG,CAAC;AAAA,CAAI;AAC7F,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["result","output"]}
1
+ {"version":3,"sources":["../../src/mcp/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * @experimental\n *\n * `agent-runtime-mcp` — stdio MCP server entry point.\n *\n * Spins up a server with the default coder delegate (wired against the\n * real `@tangle-network/sandbox` client) and, when the optional\n * `@tangle-network/agent-knowledge` peer is installed, a researcher\n * delegate against `multiHarnessResearcherFanout`.\n *\n * Environment variables:\n * TANGLE_API_KEY required — passed to `new Sandbox({ apiKey })`\n * SANDBOX_BASE_URL optional — sandbox-SDK base URL override\n * TANGLE_FLEET_ID optional — when set, delegations dispatch\n * INTO this fleet's shared workspace instead\n * of creating sibling sandboxes. Set by the\n * parent sandbox when launching this MCP\n * server so worker diffs land on the caller's\n * filesystem with no cross-sandbox boundary.\n * TANGLE_FLEET_EXCLUDE_MACHINES optional — comma-separated machine ids to\n * skip during fleet-mode round-robin\n * (typically the coordinator machine this\n * MCP server is running on).\n * MCP_MAX_CONCURRENT_SANDBOXES default 4 — kernel maxConcurrency cap\n * MCP_CODER_FANOUT_HARNESSES comma-separated harness ids to use for variants > 1\n * MCP_DISABLE_CODER set to `1` to omit `delegate_code`\n * MCP_DISABLE_RESEARCHER set to `1` to omit `delegate_research` even when peer is present\n */\n\nimport type { LoopSandboxClient, LoopTraceEmitter } from '../loops'\nimport { runLoop } from '../loops'\nimport { detectExecutor } from './bin-helpers'\nimport { createDefaultCoderDelegate, type ResearcherDelegate } from './delegates'\nimport type { DelegationExecutor } from './executor'\nimport { createMcpServer } from './server'\nimport { createPropagatingTraceEmitter, readTraceContextFromEnv } from './trace-propagation'\nimport type { ResearchOutputShape } from './types'\n\nasync function main(): Promise<void> {\n const fanoutHarnesses = parseHarnesses(process.env.MCP_CODER_FANOUT_HARNESSES)\n const maxConcurrency = parseConcurrency(process.env.MCP_MAX_CONCURRENT_SANDBOXES)\n const wantCoder = !process.env.MCP_DISABLE_CODER\n const wantResearcher = !process.env.MCP_DISABLE_RESEARCHER\n const fleetId = parseFleetId(process.env.TANGLE_FLEET_ID)\n\n // Skip the sandbox client load entirely when no profile delegate needs it —\n // the feedback + status + history tools are queue-bound and require no\n // sandbox. Useful for tooling that mounts the MCP server purely for\n // self-introspection.\n const needsSandbox = wantCoder || wantResearcher\n let sandboxClient: LoopSandboxClient | undefined\n let executor: DelegationExecutor | undefined\n if (needsSandbox) {\n const apiKey = process.env.TANGLE_API_KEY\n if (!apiKey && !process.env.AGENT_RUNTIME_MCP_ALLOW_NO_KEY) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_API_KEY is required. Set AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 to run without it for diagnostics, or MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to run the queue-only subset.\\n',\n )\n process.exit(2)\n }\n // Fleet mode against a diagnostic stub is meaningless — the stub can't\n // resolve a real fleet handle. Refuse rather than silently degrading,\n // otherwise a fleet-mounted MCP would behave differently than configured.\n if (fleetId && !apiKey) {\n process.stderr.write(\n 'agent-runtime-mcp: TANGLE_FLEET_ID was set but TANGLE_API_KEY is missing; cannot resolve fleet handle. Provide an api key or unset TANGLE_FLEET_ID.\\n',\n )\n process.exit(2)\n }\n sandboxClient = await loadSandboxClient(apiKey)\n executor = await detectExecutor({ sandboxClient })\n if (fleetId) {\n process.stderr.write(`agent-runtime-mcp: fleet-aware delegation: fleetId=${fleetId}\\n`)\n }\n process.stderr.write(`agent-runtime-mcp: delegation placement → ${executor.describe()}\\n`)\n }\n\n // Export delegated-loop topology spans to the OTLP / Tangle Intelligence sink\n // when OTEL_EXPORTER_OTLP_ENDPOINT is set (+ TRACE_ID / PARENT_SPAN_ID for\n // correlation with the caller's trace). A cheap no-op when the endpoint is\n // unset — the fleet forwards the env into this MCP's process to turn it on.\n const { emitter: traceEmitter, exporter: traceExporter } = createPropagatingTraceEmitter(\n readTraceContextFromEnv(),\n )\n if (process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {\n process.stderr.write(\n `agent-runtime-mcp: exporting loop topology → ${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}\\n`,\n )\n }\n\n const coderDelegate =\n wantCoder && executor\n ? createDefaultCoderDelegate({\n executor,\n fanoutHarnesses,\n maxConcurrency,\n traceEmitter,\n })\n : undefined\n\n const researcherDelegate =\n wantResearcher && executor\n ? await loadResearcherDelegate(executor.client, maxConcurrency, traceEmitter)\n : undefined\n\n const server = createMcpServer({ coderDelegate, researcherDelegate })\n\n const shutdown = () => {\n server.stop()\n void traceExporter?.shutdown().finally(() => process.exit(0))\n if (!traceExporter) process.exit(0)\n }\n process.on('SIGINT', shutdown)\n process.on('SIGTERM', shutdown)\n\n await server.serve()\n}\n\nasync function loadSandboxClient(apiKey: string | undefined): Promise<LoopSandboxClient> {\n // Diagnostic mode: AGENT_RUNTIME_MCP_ALLOW_NO_KEY=1 enables tools/list + the\n // queue-bound tools (status / history / feedback) without sandbox creds.\n // Coder + researcher delegations require a real client; the stub fails loud\n // at create() so the agent observes the cause instead of silent success.\n if (!apiKey) {\n return {\n async create() {\n throw new Error(\n 'agent-runtime-mcp: TANGLE_API_KEY is unset; coder/researcher delegations are disabled in diagnostic mode. Set TANGLE_API_KEY or use MCP_DISABLE_CODER=1 MCP_DISABLE_RESEARCHER=1 to remove the unsupported tools from the tool list.',\n )\n },\n } satisfies LoopSandboxClient\n }\n // Dynamic import keeps the bin importable in environments that haven't\n // installed `@tangle-network/sandbox` yet (the runtime package lists it\n // as a peer dep, not a hard dep).\n const mod = await import('@tangle-network/sandbox').catch((err) => {\n process.stderr.write(\n `agent-runtime-mcp: failed to load @tangle-network/sandbox (${err.message}); install the peer dependency\\n`,\n )\n process.exit(2)\n })\n const SandboxCtor = (mod as { Sandbox?: new (config: unknown) => LoopSandboxClient }).Sandbox\n if (!SandboxCtor) {\n process.stderr.write(\n 'agent-runtime-mcp: @tangle-network/sandbox does not export Sandbox; cannot construct client\\n',\n )\n process.exit(2)\n }\n const baseUrl = process.env.SANDBOX_BASE_URL\n return new SandboxCtor({\n apiKey,\n ...(baseUrl ? { baseUrl } : {}),\n })\n}\n\ninterface ResearcherProfilePreset {\n agentRunSpec: Parameters<typeof runLoop>[0]['agentRun'] extends infer T ? NonNullable<T> : never\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n}\n\ninterface ResearcherFanoutPreset {\n agentRuns: NonNullable<Parameters<typeof runLoop>[0]['agentRuns']>\n output: Parameters<typeof runLoop>[0]['output']\n validator: Parameters<typeof runLoop>[0]['validator']\n driver: Parameters<typeof runLoop>[0]['driver']\n}\n\nasync function loadResearcherDelegate(\n sandboxClient: LoopSandboxClient,\n maxConcurrency: number,\n traceEmitter?: LoopTraceEmitter,\n): Promise<ResearcherDelegate | undefined> {\n // Optional peer — when `@tangle-network/agent-knowledge` isn't installed,\n // we silently omit the researcher tool from the advertisement. The\n // dynamic-import path is resolved at runtime; TypeScript cannot see the\n // peer, so we type the module structurally rather than via its own\n // declaration file.\n const profilesSpecifier = '@tangle-network/agent-knowledge/profiles'\n const mod = await import(profilesSpecifier).catch(() => undefined)\n if (!mod) return undefined\n type SingleFactory = (opts: { task: unknown }) => ResearcherProfilePreset\n type FanoutFactory = (opts: { task: unknown }) => ResearcherFanoutPreset\n const fanoutFactory = (mod as { multiHarnessResearcherFanout?: FanoutFactory })\n .multiHarnessResearcherFanout\n const singleFactory = (mod as { researcherProfile?: SingleFactory }).researcherProfile\n if (!fanoutFactory || !singleFactory) return undefined\n\n return async (args, ctx) => {\n const task = {\n question: args.question,\n knowledgeNamespace: args.namespace,\n scope: args.scope,\n sources: args.sources,\n recencyWindow: args.config?.recencyWindow\n ? {\n since: args.config.recencyWindow.since\n ? new Date(args.config.recencyWindow.since)\n : undefined,\n until: args.config.recencyWindow.until\n ? new Date(args.config.recencyWindow.until)\n : undefined,\n }\n : undefined,\n maxItems: args.config?.maxItems,\n minConfidence: args.config?.minConfidence,\n }\n const variants = Math.max(1, Math.trunc(args.variants ?? 1))\n ctx.report({ iteration: 0, phase: 'starting' })\n if (variants <= 1) {\n const preset = singleFactory({ task })\n const result = await runLoop({\n driver: {\n name: 'mcp-researcher-single',\n async plan(t, history) {\n return history.length === 0 ? [t] : []\n },\n decide(history) {\n return history.length > 0 ? 'pick-winner' : 'fail'\n },\n },\n agentRun: preset.agentRunSpec,\n output: preset.output,\n validator: preset.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal, ...(traceEmitter ? { traceEmitter } : {}) },\n maxIterations: 1,\n maxConcurrency,\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate produced no winner')\n ctx.report({ iteration: 1, phase: 'completed' })\n return output as ResearchOutputShape\n }\n const fanout = fanoutFactory({ task })\n const result = await runLoop({\n driver: fanout.driver,\n agentRuns: fanout.agentRuns.slice(0, variants),\n output: fanout.output,\n validator: fanout.validator,\n task,\n ctx: { sandboxClient, signal: ctx.signal, ...(traceEmitter ? { traceEmitter } : {}) },\n maxIterations: variants,\n maxConcurrency: Math.min(maxConcurrency, variants),\n })\n const output = result.winner?.output\n if (!output) throw new Error('researcher delegate fanout produced no winner')\n ctx.report({ iteration: result.iterations.length, phase: 'completed' })\n return output as ResearchOutputShape\n }\n}\n\nfunction parseHarnesses(raw: string | undefined): string[] | undefined {\n if (!raw) return undefined\n const list = raw\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n return list.length > 0 ? list : undefined\n}\n\nfunction parseFleetId(raw: string | undefined): string | undefined {\n if (typeof raw !== 'string') return undefined\n const trimmed = raw.trim()\n return trimmed.length > 0 ? trimmed : undefined\n}\n\nfunction parseConcurrency(raw: string | undefined): number {\n if (!raw) return 4\n const n = Number(raw)\n if (!Number.isFinite(n) || n < 1) return 4\n return Math.min(Math.trunc(n), 32)\n}\n\nmain().catch((err) => {\n process.stderr.write(`agent-runtime-mcp: ${err instanceof Error ? err.stack : String(err)}\\n`)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwCA,eAAe,OAAsB;AACnC,QAAM,kBAAkB,eAAe,QAAQ,IAAI,0BAA0B;AAC7E,QAAM,iBAAiB,iBAAiB,QAAQ,IAAI,4BAA4B;AAChF,QAAM,YAAY,CAAC,QAAQ,IAAI;AAC/B,QAAM,iBAAiB,CAAC,QAAQ,IAAI;AACpC,QAAM,UAAU,aAAa,QAAQ,IAAI,eAAe;AAMxD,QAAM,eAAe,aAAa;AAClC,MAAI;AACJ,MAAI;AACJ,MAAI,cAAc;AAChB,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,CAAC,UAAU,CAAC,QAAQ,IAAI,gCAAgC;AAC1D,cAAQ,OAAO;AAAA,QACb;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAIA,QAAI,WAAW,CAAC,QAAQ;AACtB,cAAQ,OAAO;AAAA,QACb;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,oBAAgB,MAAM,kBAAkB,MAAM;AAC9C,eAAW,MAAM,eAAe,EAAE,cAAc,CAAC;AACjD,QAAI,SAAS;AACX,cAAQ,OAAO,MAAM,sDAAsD,OAAO;AAAA,CAAI;AAAA,IACxF;AACA,YAAQ,OAAO,MAAM,kDAA6C,SAAS,SAAS,CAAC;AAAA,CAAI;AAAA,EAC3F;AAMA,QAAM,EAAE,SAAS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AACxC;AAEA,SAAS,iBAAiB,KAAiC;AACzD,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,IAAI,OAAO,GAAG;AACpB,MAAI,CAAC,OAAO,SAAS,CAAC,KAAK,IAAI,EAAG,QAAO;AACzC,SAAO,KAAK,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE;AACnC;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,OAAO,MAAM,sBAAsB,eAAe,QAAQ,IAAI,QAAQ,OAAO,GAAG,CAAC;AAAA,CAAI;AAC7F,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["result","output"]}
@@ -1,13 +1,13 @@
1
- import { L as LoopSandboxClient, j as LoopSandboxPlacement, m as LoopTraceEmitter } from '../types-CNs7_1R3.js';
2
- import { c as FleetHandle, d as DelegationExecutor, e as DelegateFeedbackArgs, f as DelegationFeedbackSnapshot, g as DelegationProfile, D as DelegateCodeArgs, h as DelegateResearchArgs, i as DelegationStatus, j as DelegationProgress, k as DelegationResultPayload, l as DelegationError, m as DelegationStatusResult, n as DelegationHistoryArgs, o as DelegationHistoryEntry, p as CoderDelegate, R as ResearcherDelegate, q as DelegateCodeResult, r as DelegateFeedbackResult, s as ResearchSource, t as DelegateResearchResult, u as DelegationHistoryResult, v as DelegationStatusArgs } from '../kb-gate-C4tho31v.js';
3
- export { w as CoderReview, C as CoderReviewer, a as CoderWinnerSelection, x as CreateDefaultCoderDelegateOptions, b as CreateKbGateOptions, y as DelegateCodeConfig, z as DelegateResearchConfig, A as DelegateRunCtx, F as FactCandidate, B as FactJudge, E as FactJudgeVerdict, G as FeedbackRating, H as FeedbackRefersTo, I as FleetWorkspaceExecutorOptions, K as KbGateResult, J as ResearchOutputShape, S as SiblingSandboxExecutorOptions, L as createDefaultCoderDelegate, M as createFleetWorkspaceExecutor, N as createKbGate, O as createSiblingSandboxExecutor } from '../kb-gate-C4tho31v.js';
1
+ import { L as LoopSandboxClient, l as LoopSandboxPlacement, c as LoopTraceEmitter } from '../types-Bcp071Jg.js';
2
+ import { c as FleetHandle, d as DelegationExecutor, e as DelegateFeedbackArgs, f as DelegationFeedbackSnapshot, g as DelegationProfile, D as DelegateCodeArgs, h as DelegateResearchArgs, i as DelegationStatus, j as DelegationProgress, k as DelegationResultPayload, l as DelegationError, m as DelegationStatusResult, n as DelegationHistoryArgs, o as DelegationHistoryEntry, p as CoderDelegate, R as ResearcherDelegate, q as DelegateCodeResult, r as DelegateFeedbackResult, s as ResearchSource, t as DelegateResearchResult, u as DelegationHistoryResult, v as DelegationStatusArgs } from '../kb-gate-DTBum3vH.js';
3
+ export { w as CoderReview, C as CoderReviewer, a as CoderWinnerSelection, x as CreateDefaultCoderDelegateOptions, b as CreateKbGateOptions, y as DelegateCodeConfig, z as DelegateResearchConfig, A as DelegateRunCtx, F as FactCandidate, B as FactJudge, E as FactJudgeVerdict, G as FeedbackRating, H as FeedbackRefersTo, I as FleetWorkspaceExecutorOptions, K as KbGateResult, J as ResearchOutputShape, S as SiblingSandboxExecutorOptions, L as createDefaultCoderDelegate, M as createFleetWorkspaceExecutor, N as createKbGate, O as createSiblingSandboxExecutor } from '../kb-gate-DTBum3vH.js';
4
+ export { B as BuildDelegationMcpServerOptions, C as ComposeProductionAgentProfileOptions, D as DELEGATION_MCP_SERVER_KEY, b as buildDelegationMcpServer, c as composeProductionAgentProfile } from '../delegation-profile-1GbW5yA3.js';
4
5
  import { L as LocalHarness, r as runLocalHarness } from '../local-harness-KrdFTY5R.js';
5
6
  export { a as LocalHarnessResult, R as RunLocalHarnessOptions } from '../local-harness-KrdFTY5R.js';
6
- import { O as OtelExporter } from '../otel-export-xgf4J6bo.js';
7
- export { m as mcpToolsForRuntimeMcp, a as mcpToolsForRuntimeMcpSubset } from '../otel-export-xgf4J6bo.js';
7
+ import { O as OtelExporter } from '../otel-export-BzvF1Ela.js';
8
+ export { m as mcpToolsForRuntimeMcp, a as mcpToolsForRuntimeMcpSubset } from '../otel-export-BzvF1Ela.js';
8
9
  import '@tangle-network/agent-eval';
9
10
  import '@tangle-network/sandbox';
10
- import '../types-CsCCryln.js';
11
11
  import '../profiles.js';
12
12
  import 'node:child_process';
13
13
 
package/dist/mcp/index.js CHANGED
@@ -3,16 +3,17 @@ import {
3
3
  createInProcessExecutor,
4
4
  createInProcessTransport,
5
5
  createMcpServer,
6
+ createPropagatingTraceEmitter,
6
7
  createWorktree,
7
8
  detectExecutor,
8
- removeWorktree
9
- } from "../chunk-6HI3QUJD.js";
9
+ readTraceContextFromEnv,
10
+ removeWorktree,
11
+ traceContextToEnv
12
+ } from "../chunk-HCL2ZG5L.js";
10
13
  import {
11
- buildLoopOtelSpans,
12
- createOtelExporter,
13
14
  mcpToolsForRuntimeMcp,
14
15
  mcpToolsForRuntimeMcpSubset
15
- } from "../chunk-7ZECSZ3C.js";
16
+ } from "../chunk-NRZOXCJK.js";
16
17
  import {
17
18
  DELEGATE_CODE_DESCRIPTION,
18
19
  DELEGATE_CODE_INPUT_SCHEMA,
@@ -43,7 +44,7 @@ import {
43
44
  validateDelegateResearchArgs,
44
45
  validateDelegationHistoryArgs,
45
46
  validateDelegationStatusArgs
46
- } from "../chunk-HSX6PFZR.js";
47
+ } from "../chunk-HVYOHJHK.js";
47
48
  import {
48
49
  createKbGate
49
50
  } from "../chunk-FNMGYYSS.js";
@@ -51,56 +52,20 @@ import {
51
52
  createDefaultCoderDelegate,
52
53
  createFleetWorkspaceExecutor,
53
54
  createSiblingSandboxExecutor
54
- } from "../chunk-VFKBIZTY.js";
55
+ } from "../chunk-WMBYQPYM.js";
55
56
  import {
56
57
  runLocalHarness
57
58
  } from "../chunk-GLR25NG7.js";
58
- import "../chunk-OISRXLWI.js";
59
+ import {
60
+ DELEGATION_MCP_SERVER_KEY,
61
+ buildDelegationMcpServer,
62
+ composeProductionAgentProfile
63
+ } from "../chunk-7JITYN6T.js";
64
+ import "../chunk-IFG6GX6A.js";
59
65
  import "../chunk-3HMHSN22.js";
60
66
  import "../chunk-PY6NMZYX.js";
61
67
  import "../chunk-SQSCRJ7U.js";
62
68
  import "../chunk-DGUM43GV.js";
63
-
64
- // src/mcp/trace-propagation.ts
65
- function readTraceContextFromEnv() {
66
- const traceId = process.env.TRACE_ID || generateTraceId();
67
- const parentSpanId = process.env.PARENT_SPAN_ID || void 0;
68
- return { traceId, parentSpanId };
69
- }
70
- function createPropagatingTraceEmitter(ctx) {
71
- const exporter = createOtelExporter();
72
- const buffers = /* @__PURE__ */ new Map();
73
- const emitter = {
74
- emit(event) {
75
- if (!exporter) return;
76
- const buf = buffers.get(event.runId);
77
- if (buf) buf.push(event);
78
- else buffers.set(event.runId, [event]);
79
- if (event.kind === "loop.ended") {
80
- const events = buffers.get(event.runId) ?? [event];
81
- buffers.delete(event.runId);
82
- for (const span of buildLoopOtelSpans(events, ctx.traceId, ctx.parentSpanId)) {
83
- exporter.exportSpan(span);
84
- }
85
- }
86
- }
87
- };
88
- return { emitter, exporter, context: ctx };
89
- }
90
- function traceContextToEnv(ctx) {
91
- const env = { TRACE_ID: ctx.traceId };
92
- if (ctx.parentSpanId) env.PARENT_SPAN_ID = ctx.parentSpanId;
93
- return env;
94
- }
95
- function generateTraceId() {
96
- const bytes = new Uint8Array(16);
97
- if (typeof globalThis.crypto?.getRandomValues === "function") {
98
- globalThis.crypto.getRandomValues(bytes);
99
- } else {
100
- for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
101
- }
102
- return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
103
- }
104
69
  export {
105
70
  DELEGATE_CODE_DESCRIPTION,
106
71
  DELEGATE_CODE_INPUT_SCHEMA,
@@ -114,12 +79,15 @@ export {
114
79
  DELEGATION_HISTORY_DESCRIPTION,
115
80
  DELEGATION_HISTORY_INPUT_SCHEMA,
116
81
  DELEGATION_HISTORY_TOOL_NAME,
82
+ DELEGATION_MCP_SERVER_KEY,
117
83
  DELEGATION_STATUS_DESCRIPTION,
118
84
  DELEGATION_STATUS_INPUT_SCHEMA,
119
85
  DELEGATION_STATUS_TOOL_NAME,
120
86
  DelegationTaskQueue,
121
87
  InMemoryFeedbackStore,
88
+ buildDelegationMcpServer,
122
89
  captureWorktreeDiff,
90
+ composeProductionAgentProfile,
123
91
  createDefaultCoderDelegate,
124
92
  createDelegateCodeHandler,
125
93
  createDelegateFeedbackHandler,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mcp/trace-propagation.ts"],"sourcesContent":["/**\n * @experimental\n *\n * Trace context propagation for MCP subprocess.\n *\n * When the MCP server is launched as a child process by a sandbox harness,\n * the parent passes trace context via environment variables:\n *\n * TRACE_ID=<current-run-trace-id>\n * PARENT_SPAN_ID=<span-that-dispatched-the-delegation>\n *\n * The MCP server reads these at startup and uses them as the root of its\n * internal trace tree. All spans emitted by `runLoop` invocations inside\n * the MCP are children of the parent's delegation span.\n *\n * When these env vars are absent, the MCP generates a fresh trace root —\n * the server operates standalone without trace joining.\n */\n\nimport type { LoopTraceEmitter, LoopTraceEvent } from '../loops/types'\nimport type { OtelExporter } from '../otel-export'\nimport { buildLoopOtelSpans, createOtelExporter } from '../otel-export'\n\nexport interface TraceContext {\n /** Trace id inherited from the parent process, or a fresh one. */\n traceId: string\n /** Parent span id from the delegation that launched this MCP server. */\n parentSpanId?: string\n}\n\n/**\n * Read trace context from the process environment.\n * Returns a context with inherited ids or a freshly generated root.\n */\nexport function readTraceContextFromEnv(): TraceContext {\n const traceId = process.env.TRACE_ID || generateTraceId()\n const parentSpanId = process.env.PARENT_SPAN_ID || undefined\n return { traceId, parentSpanId }\n}\n\n/**\n * Create a LoopTraceEmitter that:\n * 1. Parents all spans under the inherited PARENT_SPAN_ID.\n * 2. Exports spans to OTEL when OTEL_EXPORTER_OTLP_ENDPOINT is set.\n *\n * Returns both the emitter and the optional exporter handle for shutdown.\n */\nexport function createPropagatingTraceEmitter(ctx: TraceContext): {\n emitter: LoopTraceEmitter\n exporter: OtelExporter | undefined\n context: TraceContext\n} {\n const exporter = createOtelExporter()\n\n // Buffer events per loop run, then emit the full nested span tree on\n // `loop.ended` so the topology hierarchy (loop → round → branch) reaches the\n // OTLP collector — not a flat list of zero-duration point spans. A run that\n // never reaches `loop.ended` (hard abort) drops its buffer; acceptable for\n // the short-lived MCP subprocess.\n const buffers = new Map<string, LoopTraceEvent[]>()\n\n const emitter: LoopTraceEmitter = {\n emit(event: LoopTraceEvent) {\n if (!exporter) return\n const buf = buffers.get(event.runId)\n if (buf) buf.push(event)\n else buffers.set(event.runId, [event])\n if (event.kind === 'loop.ended') {\n const events = buffers.get(event.runId) ?? [event]\n buffers.delete(event.runId)\n for (const span of buildLoopOtelSpans(events, ctx.traceId, ctx.parentSpanId)) {\n exporter.exportSpan(span)\n }\n }\n },\n }\n\n return { emitter, exporter, context: ctx }\n}\n\n/**\n * Build env vars to pass to a child MCP subprocess so it inherits the\n * current trace context.\n */\nexport function traceContextToEnv(ctx: TraceContext): Record<string, string> {\n const env: Record<string, string> = { TRACE_ID: ctx.traceId }\n if (ctx.parentSpanId) env.PARENT_SPAN_ID = ctx.parentSpanId\n return env\n}\n\nfunction generateTraceId(): string {\n const bytes = new Uint8Array(16)\n if (typeof globalThis.crypto?.getRandomValues === 'function') {\n globalThis.crypto.getRandomValues(bytes)\n } else {\n for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256)\n }\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCO,SAAS,0BAAwC;AACtD,QAAM,UAAU,QAAQ,IAAI,YAAY,gBAAgB;AACxD,QAAM,eAAe,QAAQ,IAAI,kBAAkB;AACnD,SAAO,EAAE,SAAS,aAAa;AACjC;AASO,SAAS,8BAA8B,KAI5C;AACA,QAAM,WAAW,mBAAmB;AAOpC,QAAM,UAAU,oBAAI,IAA8B;AAElD,QAAM,UAA4B;AAAA,IAChC,KAAK,OAAuB;AAC1B,UAAI,CAAC,SAAU;AACf,YAAM,MAAM,QAAQ,IAAI,MAAM,KAAK;AACnC,UAAI,IAAK,KAAI,KAAK,KAAK;AAAA,UAClB,SAAQ,IAAI,MAAM,OAAO,CAAC,KAAK,CAAC;AACrC,UAAI,MAAM,SAAS,cAAc;AAC/B,cAAM,SAAS,QAAQ,IAAI,MAAM,KAAK,KAAK,CAAC,KAAK;AACjD,gBAAQ,OAAO,MAAM,KAAK;AAC1B,mBAAW,QAAQ,mBAAmB,QAAQ,IAAI,SAAS,IAAI,YAAY,GAAG;AAC5E,mBAAS,WAAW,IAAI;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,UAAU,SAAS,IAAI;AAC3C;AAMO,SAAS,kBAAkB,KAA2C;AAC3E,QAAM,MAA8B,EAAE,UAAU,IAAI,QAAQ;AAC5D,MAAI,IAAI,aAAc,KAAI,iBAAiB,IAAI;AAC/C,SAAO;AACT;AAEA,SAAS,kBAA0B;AACjC,QAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,MAAI,OAAO,WAAW,QAAQ,oBAAoB,YAAY;AAC5D,eAAW,OAAO,gBAAgB,KAAK;AAAA,EACzC,OAAO;AACL,aAAS,IAAI,GAAG,IAAI,IAAI,IAAK,OAAM,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AAAA,EACxE;AACA,SAAO,MAAM,KAAK,KAAK,EACpB,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAC1C,KAAK,EAAE;AACZ;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,4 +1,4 @@
1
- import { O as OpenAIChatTool } from './types-CsCCryln.js';
1
+ import { O as OpenAIChatTool } from './types-Bcp071Jg.js';
2
2
 
3
3
  /**
4
4
  * @experimental
@@ -1,7 +1,6 @@
1
1
  import { AgentProfile } from '@tangle-network/sandbox';
2
- import { O as OutputAdapter, V as Validator, A as AgentRunSpec, D as Driver } from './types-CNs7_1R3.js';
2
+ import { a as OutputAdapter, V as Validator, A as AgentRunSpec, D as Driver } from './types-Bcp071Jg.js';
3
3
  import '@tangle-network/agent-eval';
4
- import './types-CsCCryln.js';
5
4
 
6
5
  /**
7
6
  * @experimental