@tangle-network/agent-runtime 0.71.0 → 0.71.1
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.
- package/dist/mcp/bin.js +47 -8
- package/dist/mcp/bin.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp/bin.js
CHANGED
|
@@ -35,10 +35,43 @@ import {
|
|
|
35
35
|
import "../chunk-WIR4HOOJ.js";
|
|
36
36
|
import "../chunk-DGUM43GV.js";
|
|
37
37
|
|
|
38
|
+
// src/mcp/delegate-supervisor-provisioning.ts
|
|
39
|
+
var DEFAULT_SUPERVISOR_MODEL = "moonshotai/kimi-k2.6";
|
|
40
|
+
var DEFAULT_WORKER_HARNESS = "opencode";
|
|
41
|
+
function trimmed(value) {
|
|
42
|
+
const v = value?.trim();
|
|
43
|
+
return v ? v : void 0;
|
|
44
|
+
}
|
|
45
|
+
function delegateEnabled(env = process.env) {
|
|
46
|
+
return env.MCP_ENABLE_DELEGATE === "1";
|
|
47
|
+
}
|
|
48
|
+
function resolveRouter(env) {
|
|
49
|
+
const routerKey = trimmed(env.MCP_SUPERVISOR_ROUTER_KEY) ?? trimmed(env.TANGLE_API_KEY) ?? "";
|
|
50
|
+
const base = trimmed(env.MCP_SUPERVISOR_ROUTER_BASE_URL) ?? resolveRouterBaseUrl(env);
|
|
51
|
+
const routerBaseUrl = /\/v\d+\/?$/.test(base) ? base.replace(/\/$/, "") : `${base.replace(/\/$/, "")}/v1`;
|
|
52
|
+
const model = trimmed(env.MCP_SUPERVISOR_MODEL) ?? trimmed(env.MCP_WORKER_MODEL) ?? trimmed(env.WORKER_MODEL) ?? DEFAULT_SUPERVISOR_MODEL;
|
|
53
|
+
return { routerBaseUrl, routerKey, model };
|
|
54
|
+
}
|
|
55
|
+
function resolveDelegateSupervisor(sandboxClient, env = process.env) {
|
|
56
|
+
if (!delegateEnabled(env)) return void 0;
|
|
57
|
+
const router = resolveRouter(env);
|
|
58
|
+
const harness = trimmed(env.MCP_DELEGATE_WORKER_HARNESS) ?? DEFAULT_WORKER_HARNESS;
|
|
59
|
+
const backend = {
|
|
60
|
+
backend: "sandbox",
|
|
61
|
+
harness,
|
|
62
|
+
sandboxClient
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
router,
|
|
66
|
+
backend,
|
|
67
|
+
model: router.model
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
38
71
|
// src/mcp/researcher-provisioning.ts
|
|
39
72
|
var DEFAULT_HARNESS = "opencode";
|
|
40
73
|
var DEFAULT_MODEL = "moonshotai/kimi-k2.6";
|
|
41
|
-
function
|
|
74
|
+
function trimmed2(value) {
|
|
42
75
|
const t = value?.trim();
|
|
43
76
|
return t ? t : void 0;
|
|
44
77
|
}
|
|
@@ -47,10 +80,10 @@ function csv(value) {
|
|
|
47
80
|
return list && list.length > 0 ? list : void 0;
|
|
48
81
|
}
|
|
49
82
|
function resolveResearcherProvisioning(env = process.env) {
|
|
50
|
-
const harness =
|
|
51
|
-
const model =
|
|
52
|
-
const routerKey =
|
|
53
|
-
const base =
|
|
83
|
+
const harness = trimmed2(env.MCP_RESEARCHER_HARNESS) ?? DEFAULT_HARNESS;
|
|
84
|
+
const model = trimmed2(env.MCP_RESEARCHER_MODEL) ?? trimmed2(env.MCP_WORKER_MODEL) ?? trimmed2(env.WORKER_MODEL) ?? DEFAULT_MODEL;
|
|
85
|
+
const routerKey = trimmed2(env.MCP_RESEARCHER_ROUTER_KEY) ?? trimmed2(env.TANGLE_API_KEY);
|
|
86
|
+
const base = trimmed2(env.MCP_RESEARCHER_ROUTER_BASE_URL) ?? resolveRouterBaseUrl(env);
|
|
54
87
|
const routerBaseUrl = /\/v\d+\/?$/.test(base) ? base.replace(/\/$/, "") : `${base.replace(/\/$/, "")}/v1`;
|
|
55
88
|
const fanoutHarnesses = csv(env.MCP_RESEARCHER_FANOUT_HARNESSES);
|
|
56
89
|
const fanoutModels = csv(env.MCP_RESEARCHER_FANOUT_MODELS);
|
|
@@ -81,8 +114,9 @@ async function main() {
|
|
|
81
114
|
const maxConcurrency = parseConcurrency(process.env.MCP_MAX_CONCURRENT_SANDBOXES);
|
|
82
115
|
const wantCoder = !process.env.MCP_DISABLE_CODER;
|
|
83
116
|
const wantResearcher = !process.env.MCP_DISABLE_RESEARCHER;
|
|
117
|
+
const wantDelegate = delegateEnabled(process.env);
|
|
84
118
|
const fleetId = parseFleetId(process.env.TANGLE_FLEET_ID);
|
|
85
|
-
const needsSandbox = wantCoder || wantResearcher;
|
|
119
|
+
const needsSandbox = wantCoder || wantResearcher || wantDelegate;
|
|
86
120
|
let sandboxClient;
|
|
87
121
|
let executor;
|
|
88
122
|
if (needsSandbox) {
|
|
@@ -130,10 +164,15 @@ async function main() {
|
|
|
130
164
|
);
|
|
131
165
|
}
|
|
132
166
|
const resumeDriver = detachedDispatch && sandboxClient ? buildResumeDriver({ sandboxClient, researcherResume: researcherSupport?.resume }) : void 0;
|
|
167
|
+
const delegateSupervisor = wantDelegate && sandboxClient ? resolveDelegateSupervisor(sandboxClient) : void 0;
|
|
168
|
+
if (wantDelegate && delegateSupervisor) {
|
|
169
|
+
process.stderr.write("agent-runtime-mcp: delegate enabled \u2014 generic authoring supervisor\n");
|
|
170
|
+
}
|
|
133
171
|
const durableQueue = await buildDurableQueueFromEnv(resumeDriver, traceContext);
|
|
134
172
|
const server = createMcpServer({
|
|
135
173
|
coderDelegate,
|
|
136
174
|
researcherDelegate: researcherSupport?.delegate,
|
|
175
|
+
...delegateSupervisor ? { delegateSupervisor } : {},
|
|
137
176
|
detachedDispatch,
|
|
138
177
|
traceContext,
|
|
139
178
|
...durableQueue ? { queue: durableQueue } : {}
|
|
@@ -419,8 +458,8 @@ function parseHarnesses(raw) {
|
|
|
419
458
|
}
|
|
420
459
|
function parseFleetId(raw) {
|
|
421
460
|
if (typeof raw !== "string") return void 0;
|
|
422
|
-
const
|
|
423
|
-
return
|
|
461
|
+
const trimmed3 = raw.trim();
|
|
462
|
+
return trimmed3.length > 0 ? trimmed3 : void 0;
|
|
424
463
|
}
|
|
425
464
|
function parseConcurrency(raw) {
|
|
426
465
|
if (!raw) return 4;
|
package/dist/mcp/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mcp/researcher-provisioning.ts","../../src/mcp/bin.ts"],"sourcesContent":["/**\n * Researcher delegate provisioning — resolves the worker harness, model, and router\n * credentials for `delegate_research`, and injects the OpenAI-compatible router creds\n * into a sandbox agent-run spec.\n *\n * Why this exists: the agent-knowledge researcher profile defaults to a harness\n * (`opencode/zai-coding-plan/glm-5.1`) that isn't broadly provisionable, and the sandbox\n * SDK does not wire `backend.model.apiKey` into the in-box agent's OpenAI-compatible\n * provider. So the MCP server picks a provisionable harness + model and passes the router\n * creds as box env. Everything is env-overridable and reuses the repo's router resolution.\n */\nimport { type RouterEnv, resolveRouterBaseUrl } from '../model-resolution.js'\n\nexport interface ResearcherProvisioning {\n harness: string\n /** Worker model id (router-served). */\n model: string\n /** OpenAI-compatible router key for the in-box provider; undefined disables injection. */\n routerKey?: string\n /** OpenAI-compatible router base, always ending in a `/vN` segment. */\n routerBaseUrl: string\n /** Explicit fanout harness list (MCP_RESEARCHER_FANOUT_HARNESSES); undefined ⇒ caller defaults. */\n fanoutHarnesses?: string[]\n /** Per-harness fanout model overrides (MCP_RESEARCHER_FANOUT_MODELS), index-aligned. */\n fanoutModels?: string[]\n}\n\n/** A sandbox agent-run spec whose box env can be overridden. */\nexport interface ProvisionableSpec {\n sandboxOverrides?: { env?: Record<string, string> } & Record<string, unknown>\n}\n\nconst DEFAULT_HARNESS = 'opencode'\nconst DEFAULT_MODEL = 'moonshotai/kimi-k2.6'\n\nfunction trimmed(value: string | undefined): string | undefined {\n const t = value?.trim()\n return t ? t : undefined\n}\n\nfunction csv(value: string | undefined): string[] | undefined {\n const list = value\n ?.split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n return list && list.length > 0 ? list : undefined\n}\n\n/**\n * Resolve harness/model/router from env. Model falls back through the repo's\n * `WORKER_MODEL` convention; router base reuses `resolveRouterBaseUrl` (TANGLE_ROUTER_URL\n * / TANGLE_ROUTER_BASE_URL) and is normalized to an OpenAI-compatible `/v1` endpoint.\n */\nexport function resolveResearcherProvisioning(\n env: NodeJS.ProcessEnv = process.env,\n): ResearcherProvisioning {\n const harness = trimmed(env.MCP_RESEARCHER_HARNESS) ?? DEFAULT_HARNESS\n const model =\n trimmed(env.MCP_RESEARCHER_MODEL) ??\n trimmed(env.MCP_WORKER_MODEL) ??\n trimmed(env.WORKER_MODEL) ??\n DEFAULT_MODEL\n const routerKey = trimmed(env.MCP_RESEARCHER_ROUTER_KEY) ?? trimmed(env.TANGLE_API_KEY)\n const base = trimmed(env.MCP_RESEARCHER_ROUTER_BASE_URL) ?? resolveRouterBaseUrl(env as RouterEnv)\n const routerBaseUrl = /\\/v\\d+\\/?$/.test(base)\n ? base.replace(/\\/$/, '')\n : `${base.replace(/\\/$/, '')}/v1`\n const fanoutHarnesses = csv(env.MCP_RESEARCHER_FANOUT_HARNESSES)\n const fanoutModels = csv(env.MCP_RESEARCHER_FANOUT_MODELS)\n return {\n harness,\n model,\n ...(routerKey ? { routerKey } : {}),\n routerBaseUrl,\n ...(fanoutHarnesses ? { fanoutHarnesses } : {}),\n ...(fanoutModels ? { fanoutModels } : {}),\n }\n}\n\n/**\n * Overlay the router creds onto a spec's box env (in place): preserve every env var the\n * preset already supplied and set OPENAI_API_KEY / OPENAI_BASE_URL on top (these two are\n * intentionally authoritative — they point the in-box provider at the router). No-op when\n * there is no router key.\n */\nexport function applyRouterEnv(\n spec: ProvisionableSpec,\n routerKey: string | undefined,\n routerBaseUrl: string,\n): void {\n if (!routerKey) return\n spec.sandboxOverrides = {\n ...(spec.sandboxOverrides ?? {}),\n env: {\n ...(spec.sandboxOverrides?.env ?? {}),\n OPENAI_API_KEY: routerKey,\n OPENAI_BASE_URL: routerBaseUrl,\n },\n }\n}\n","#!/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 * MCP_RESEARCHER_HARNESS researcher worker harness (default `opencode`)\n * MCP_RESEARCHER_MODEL researcher worker model id (falls back to\n * MCP_WORKER_MODEL, then WORKER_MODEL, then a default)\n * MCP_RESEARCHER_FANOUT_HARNESSES comma-separated harnesses for researcher variants > 1\n * MCP_RESEARCHER_FANOUT_MODELS comma-separated per-harness models, index-aligned\n * MCP_RESEARCHER_ROUTER_KEY OpenAI-compatible router key for the in-box agent\n * (defaults to TANGLE_API_KEY)\n * MCP_RESEARCHER_ROUTER_BASE_URL router base for the in-box agent (defaults to the\n * repo's resolveRouterBaseUrl, normalized to `/v1`)\n * AGENT_RUNTIME_DELEGATION_STATE_FILE\n * optional — absolute path of a JSON state\n * file. When set, delegation records persist\n * across MCP restarts (FileDelegationStore):\n * status/history survive and idempotency keys\n * dedupe across processes. Single-variant\n * coder/researcher delegations additionally\n * dispatch DETACHED (driveTurn ticks against a\n * deterministic session id) on session-backed\n * placements, so restored in-flight records\n * resume against their still-running sandbox\n * sessions; non-detached in-flight records\n * settle as failed with a truthful\n * driver-restart error.\n * AGENT_RUNTIME_DELEGATION_DETACHED\n * set to `0` to keep every delegation on the\n * streaming path even when the state file is\n * configured (disables detached dispatch +\n * resume).\n * AGENT_RUNTIME_DELEGATION_STATE_RECOVER\n * set to `1` to archive a corrupt state file\n * (`<file>.corrupt-<ts>`) and start empty\n * instead of refusing to boot.\n * AGENT_RUNTIME_DELEGATION_RETAIN_TERMINAL\n * optional — positive integer cap on retained\n * terminal records. Unset = keep forever.\n */\n\nimport type { SandboxInstance } from '@tangle-network/sandbox'\nimport { coderTaskToPrompt } from '../profiles/coder'\nimport type { AgentRunSpec, LoopTraceEmitter, SandboxClient } from '../runtime'\nimport { runLoop } from '../runtime'\nimport { detectExecutor } from './bin-helpers'\nimport {\n coderTaskFromArgs,\n detachedSessionDelegate,\n type ResearcherDelegate,\n settleDetachedCoderTurn,\n} from './delegates'\nimport { DEFAULT_SANDBOX_BASE_URL } from './delegation-profile'\nimport { FileDelegationStore } from './delegation-store'\nimport { composeLoopTraceEmitters } from './delegation-trace'\nimport {\n createDetachedTurnResumeDriver,\n type DetachedTurn,\n type DriveTurnCapableBox,\n detachedTurnEvents,\n formatDetachedSessionRef,\n parseDetachedSessionRef,\n runDetachedTurn,\n} from './detached-turn'\nimport type { DelegationExecutor } from './executor'\nimport {\n applyRouterEnv,\n type ProvisionableSpec,\n resolveResearcherProvisioning,\n} from './researcher-provisioning'\nimport { createMcpServer } from './server'\nimport { type DelegationResumeDriver, DelegationTaskQueue } from './task-queue'\nimport {\n createPropagatingTraceEmitter,\n readTraceContextFromEnv,\n type TraceContext,\n} from './trace-propagation'\nimport type { DelegateCodeArgs, DelegateResearchArgs, 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: SandboxClient | 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 // The same context is stamped onto every delegation record (traceId /\n // parentSpanId) so journal consumers join records into the caller's trace.\n const traceContext = readTraceContextFromEnv()\n const { emitter: traceEmitter, exporter: traceExporter } =\n createPropagatingTraceEmitter(traceContext)\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 ? detachedSessionDelegate({\n executor,\n fanoutHarnesses,\n maxConcurrency,\n traceEmitter,\n })\n : undefined\n\n const researcherSupport =\n wantResearcher && executor\n ? await loadResearcherSupport(executor, maxConcurrency, traceEmitter)\n : undefined\n\n // Detached dispatch + resume is QUARANTINED behind MCP_ENABLE_DETACHED_RESUME (default off): the\n // recursive Scope/worktree-CLI leaf has no durable detached-resume equivalent yet, so the\n // sandbox-session resume path is kept but opt-in. It additionally requires the durable store and\n // a session-backed placement with real credentials: in-process placement has no sandbox session\n // to detach, and the diagnostic no-key stub cannot resolve boxes.\n // AGENT_RUNTIME_DELEGATION_DETACHED=0 keeps everything on the streaming path even when enabled.\n const detachedDispatch =\n process.env.MCP_ENABLE_DETACHED_RESUME === '1' &&\n Boolean(process.env.AGENT_RUNTIME_DELEGATION_STATE_FILE?.trim()) &&\n process.env.AGENT_RUNTIME_DELEGATION_DETACHED !== '0' &&\n Boolean(process.env.TANGLE_API_KEY) &&\n (executor?.placement === 'sibling' || executor?.placement === 'fleet')\n if (detachedDispatch) {\n process.stderr.write(\n 'agent-runtime-mcp: detached dispatch enabled — single-variant delegations resume across restarts\\n',\n )\n }\n const resumeDriver =\n detachedDispatch && sandboxClient\n ? buildResumeDriver({ sandboxClient, researcherResume: researcherSupport?.resume })\n : undefined\n\n const durableQueue = await buildDurableQueueFromEnv(resumeDriver, traceContext)\n const server = createMcpServer({\n coderDelegate,\n researcherDelegate: researcherSupport?.delegate,\n detachedDispatch,\n traceContext,\n ...(durableQueue ? { queue: durableQueue } : {}),\n })\n\n const shutdown = () => {\n server.stop()\n const pending: Promise<unknown>[] = []\n if (traceExporter) pending.push(traceExporter.shutdown())\n // Drain journal writes so the state file reflects the final record\n // states before the process exits. A persist failure already routed\n // through onPersistError; swallow the duplicate rejection here.\n if (durableQueue) pending.push(durableQueue.flush().catch(() => {}))\n if (pending.length === 0) {\n process.exit(0)\n return\n }\n void Promise.allSettled(pending).finally(() => process.exit(0))\n }\n process.on('SIGINT', shutdown)\n process.on('SIGTERM', shutdown)\n\n await server.serve()\n}\n\nasync function buildDurableQueueFromEnv(\n resumeDriver: DelegationResumeDriver | undefined,\n traceContext: TraceContext,\n): Promise<DelegationTaskQueue | undefined> {\n const stateFile = process.env.AGENT_RUNTIME_DELEGATION_STATE_FILE?.trim()\n if (!stateFile) return undefined\n const store = new FileDelegationStore({\n filePath: stateFile,\n recoverCorrupt: process.env.AGENT_RUNTIME_DELEGATION_STATE_RECOVER === '1',\n })\n const maxTerminalRecords = parseRetention(process.env.AGENT_RUNTIME_DELEGATION_RETAIN_TERMINAL)\n // With a resume driver, restored in-flight records that carry a\n // detachedSessionRef re-attach to their still-running sandbox sessions;\n // without one (detached dispatch disabled / no credentials) they settle as\n // failed with a truthful driver-restart error.\n const queue = await DelegationTaskQueue.restore({\n store,\n traceContext,\n ...(resumeDriver ? { resumeDelegate: resumeDriver } : {}),\n ...(maxTerminalRecords !== undefined ? { maxTerminalRecords } : {}),\n onPersistError: (error) => {\n // Durable mode that can no longer write is a broken contract: crash\n // loud instead of degrading to memory-only behind the caller's back.\n process.stderr.write(`agent-runtime-mcp: ${error.message}\\n`)\n process.exit(1)\n },\n })\n process.stderr.write(`agent-runtime-mcp: durable delegation state → ${stateFile}\\n`)\n return queue\n}\n\ninterface ResearcherResumeSupport {\n message(args: DelegateResearchArgs): string\n settle(\n turn: DetachedTurn,\n args: DelegateResearchArgs,\n signal: AbortSignal,\n ): Promise<ResearchOutputShape>\n}\n\n/**\n * Compose the `driveTurn`-backed resume driver over the real sandbox client.\n * Profile dispatch: coder records settle through the same parse + validate\n * gate the delegate applies; researcher records settle through the\n * agent-knowledge preset when the peer is installed. Profiles without resume\n * support (ui-auditor, researcher-without-peer) fail loud — the record settles\n * as failed with the reason instead of fabricating an output.\n */\nfunction buildResumeDriver(args: {\n sandboxClient: SandboxClient\n researcherResume: ResearcherResumeSupport | undefined\n}): DelegationResumeDriver {\n const client = args.sandboxClient as SandboxClient & {\n get?: (id: string) => Promise<SandboxInstance | null>\n }\n return createDetachedTurnResumeDriver({\n async resolveSandbox(sandboxId) {\n if (typeof client.get !== 'function') {\n throw new Error(\n 'agent-runtime-mcp: the sandbox client exposes no get(sandboxId); upgrade @tangle-network/sandbox to >= 0.6 to resume detached delegations',\n )\n }\n const box = await client.get(sandboxId)\n if (!box) {\n throw new Error(\n `agent-runtime-mcp: sandbox ${sandboxId} no longer exists — the detached run cannot be resumed`,\n )\n }\n return box as unknown as DriveTurnCapableBox\n },\n buildMessage(record) {\n if (record.profile === 'coder') {\n const task = coderTaskFromArgs(record.args as DelegateCodeArgs)\n return coderTaskToPrompt(task)\n }\n if (record.profile === 'researcher' && args.researcherResume) {\n return args.researcherResume.message(record.args as DelegateResearchArgs)\n }\n throw new Error(\n `agent-runtime-mcp: no detached resume support for profile \"${record.profile}\"`,\n )\n },\n async settleOutput(turn, record, ctx) {\n if (record.profile === 'coder') {\n if (!record.detachedSessionRef) {\n throw new Error(\n `agent-runtime-mcp: record ${record.taskId} reached the resume settle without a detachedSessionRef`,\n )\n }\n return settleDetachedCoderTurn(turn, {\n task: coderTaskFromArgs(record.args as DelegateCodeArgs),\n sessionId: parseDetachedSessionRef(record.detachedSessionRef).sessionId,\n signal: ctx.signal,\n })\n }\n if (record.profile === 'researcher' && args.researcherResume) {\n return args.researcherResume.settle(turn, record.args as DelegateResearchArgs, ctx.signal)\n }\n throw new Error(\n `agent-runtime-mcp: no detached resume support for profile \"${record.profile}\"`,\n )\n },\n })\n}\n\nfunction parseRetention(raw: string | undefined): number | undefined {\n if (raw === undefined || raw.trim() === '') return undefined\n const n = Number(raw)\n if (!Number.isInteger(n) || n < 1) {\n process.stderr.write(\n `agent-runtime-mcp: AGENT_RUNTIME_DELEGATION_RETAIN_TERMINAL must be a positive integer, got \"${raw}\"\\n`,\n )\n process.exit(2)\n }\n return n\n}\n\nasync function loadSandboxClient(apiKey: string | undefined): Promise<SandboxClient> {\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 SandboxClient\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) => SandboxClient }).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 // @tangle-network/sandbox ≥0.6 makes baseUrl required; default it so the MCP server\n // starts without forcing every caller to set SANDBOX_BASE_URL. Treat empty/whitespace as\n // unset (|| not ??) so `SANDBOX_BASE_URL=` still resolves to the default.\n const baseUrl = process.env.SANDBOX_BASE_URL?.trim() || DEFAULT_SANDBOX_BASE_URL\n return new SandboxCtor({ apiKey, baseUrl })\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\ninterface ResearcherSupport {\n delegate: ResearcherDelegate\n resume: ResearcherResumeSupport\n}\n\nasync function loadResearcherSupport(\n executor: DelegationExecutor,\n maxConcurrency: number,\n traceEmitter?: LoopTraceEmitter,\n): Promise<ResearcherSupport | undefined> {\n const sandboxClient = executor.client\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: {\n task: unknown\n harness?: string\n model?: string\n }) => ResearcherProfilePreset\n type FanoutFactory = (opts: {\n task: unknown\n harnesses?: string[]\n models?: (string | undefined)[]\n }) => 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 // Worker harness + model + provider auth. Two reasons a researcher run otherwise makes\n // zero LLM calls and \"produces no winner\" on a successful box: (1) the profile's default\n // harness (opencode/zai-coding-plan/glm-5.1) is not broadly provisionable; (2) the\n // sandbox SDK does not wire backend.model.apiKey into the in-box agent's OpenAI-compatible\n // provider. resolveResearcherProvisioning picks a provisionable harness + model and the\n // router creds (all env-overridable); applyRouterEnv injects them as box env. Applied to\n // BOTH the single-variant path and every fanout agent-run so variants > 1 work too.\n const {\n harness,\n model,\n routerKey,\n routerBaseUrl,\n fanoutHarnesses: cfgFanoutHarnesses,\n fanoutModels,\n } = resolveResearcherProvisioning()\n const buildPreset = (task: unknown): ResearcherProfilePreset => {\n const preset = singleFactory({ task, harness, model })\n applyRouterEnv(preset.agentRunSpec as ProvisionableSpec, routerKey, routerBaseUrl)\n return preset\n }\n\n const settleSingle = async (\n turn: DetachedTurn,\n args: DelegateResearchArgs,\n sessionId: string,\n signal: AbortSignal,\n ): Promise<ResearchOutputShape> => {\n const task = buildResearchTask(args)\n const preset = buildPreset(task)\n if (!preset.validator) {\n throw new Error('agent-runtime-mcp: researcher preset exposes no validator; cannot settle')\n }\n const parsed = preset.output.parse(detachedTurnEvents(sessionId, turn))\n const verdict = await preset.validator.validate(parsed, { iteration: 0, signal })\n if ((verdict as { valid?: boolean }).valid !== true) {\n throw new Error('researcher delegate produced no winner')\n }\n return parsed as ResearchOutputShape\n }\n\n const delegate: ResearcherDelegate = async (args, ctx) => {\n const task = buildResearchTask(args)\n const variants = Math.max(1, Math.trunc(args.variants ?? 1))\n const loopEmitter = composeLoopTraceEmitters(traceEmitter, ctx.traceEmitter)\n ctx.report({ iteration: 0, phase: 'starting' })\n if (variants <= 1) {\n const preset = buildPreset(task)\n // Detached dispatch — same contract as the coder delegate: one session\n // on one box, driveTurn ticks, resume key bound to the sandbox id.\n if (ctx.detachedSessionRef !== undefined && ctx.updateDetachedSessionRef) {\n const { sessionId } = parseDetachedSessionRef(ctx.detachedSessionRef)\n const rebind = ctx.updateDetachedSessionRef\n const spec = preset.agentRunSpec as AgentRunSpec<unknown>\n const turn = await runDetachedTurn({\n client: sandboxClient,\n spec,\n prompt: spec.taskToPrompt(task),\n sessionId,\n bindSandbox: (sandboxId) => rebind(formatDetachedSessionRef({ sandboxId, sessionId })),\n signal: ctx.signal,\n report: ctx.report,\n ...(loopEmitter ? { traceEmitter: loopEmitter } : {}),\n ...(executor.placement === 'fleet' ? { placement: 'fleet' as const } : {}),\n })\n const output = await settleSingle(turn, args, sessionId, ctx.signal)\n ctx.report({ iteration: 1, phase: 'completed' })\n return output\n }\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: {\n sandboxClient,\n signal: ctx.signal,\n ...(loopEmitter ? { traceEmitter: loopEmitter } : {}),\n },\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 // Match the single-variant fix: use a provisionable harness/model and inject router\n // creds into every fanout agent-run, else variants > 1 makes zero LLM calls. Default to\n // `variants` copies of the working harness; MCP_RESEARCHER_FANOUT_HARNESSES overrides for\n // diversity (with optional per-harness MCP_RESEARCHER_FANOUT_MODELS).\n const fanoutHarnesses = cfgFanoutHarnesses ?? Array.from({ length: variants }, () => harness)\n const fanout = fanoutFactory({\n task,\n harnesses: fanoutHarnesses,\n models: fanoutHarnesses.map((_, i) => fanoutModels?.[i] ?? model),\n })\n for (const spec of fanout.agentRuns) {\n applyRouterEnv(spec as ProvisionableSpec, routerKey, routerBaseUrl)\n }\n // The harness list may be shorter than `variants` (misconfig) — never claim more\n // iterations than there are runs.\n const runs = fanout.agentRuns.slice(0, variants)\n const effectiveVariants = Math.max(1, runs.length)\n const result = await runLoop({\n driver: fanout.driver,\n agentRuns: runs,\n output: fanout.output,\n validator: fanout.validator,\n task,\n ctx: {\n sandboxClient,\n signal: ctx.signal,\n ...(loopEmitter ? { traceEmitter: loopEmitter } : {}),\n },\n maxIterations: effectiveVariants,\n maxConcurrency: Math.min(maxConcurrency, effectiveVariants),\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 return {\n delegate,\n resume: {\n message(args) {\n const task = buildResearchTask(args)\n // Use the same preset construction as dispatch so the displayed prompt can't drift.\n const spec = buildPreset(task).agentRunSpec as AgentRunSpec<unknown>\n return spec.taskToPrompt(task)\n },\n async settle(turn, args, signal) {\n // The session id is only the synthesized event's id — the parser reads\n // data.result / data.text, never the id.\n return settleSingle(turn, args, 'resumed-detached-turn', signal)\n },\n },\n }\n}\n\nfunction buildResearchTask(args: DelegateResearchArgs): unknown {\n return {\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}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,kBAAkB;AACxB,IAAM,gBAAgB;AAEtB,SAAS,QAAQ,OAA+C;AAC9D,QAAM,IAAI,OAAO,KAAK;AACtB,SAAO,IAAI,IAAI;AACjB;AAEA,SAAS,IAAI,OAAiD;AAC5D,QAAM,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AS,kBAAkB,MAAqC;AAC9D,SAAO;AAAA,IACL,UAAU,KAAK;AAAA,IACf,oBAAoB,KAAK;AAAA,IACzB,OAAO,KAAK;AAAA,IACZ,SAAS,KAAK;AAAA,IACd,eAAe,KAAK,QAAQ,gBACxB;AAAA,MACE,OAAO,KAAK,OAAO,cAAc,QAC7B,IAAI,KAAK,KAAK,OAAO,cAAc,KAAK,IACxC;AAAA,MACJ,OAAO,KAAK,OAAO,cAAc,QAC7B,IAAI,KAAK,KAAK,OAAO,cAAc,KAAK,IACxC;AAAA,IACN,IACA;AAAA,IACJ,UAAU,KAAK,QAAQ;AAAA,IACvB,eAAe,KAAK,QAAQ;AAAA,EAC9B;AACF;AAEA,SAAS,eAAe,KAA+C;AACrE,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,OAAO,IACV,MAAM,GAAG,EACT,IAAI,CAAC,UAAU,MAAM,KAAK,CAAC,EAC3B,OAAO,OAAO;AACjB,SAAO,KAAK,SAAS,IAAI,OAAO;AAClC;AAEA,SAAS,aAAa,KAA6C;AACjE,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAME,WAAU,IAAI,KAAK;AACzB,SAAOA,SAAQ,SAAS,IAAIA,WAAU;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":["output","result","trimmed"]}
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/delegate-supervisor-provisioning.ts","../../src/mcp/researcher-provisioning.ts","../../src/mcp/bin.ts"],"sourcesContent":["/**\n * @experimental\n *\n * Resolve the `delegate` supervisor substrate (router brain + worker backend) from env, so the\n * `agent-runtime-mcp` bin can serve the ONE generic `delegate` verb the same way it serves\n * `delegate_code` — by env, over the SAME stdio invocation a consumer already mounts.\n *\n * `delegate` is wired into `createMcpServer` via `McpServerOptions.delegateSupervisor`, which needs a\n * router (the supervisor brain's substrate) and a backend (WHERE the authored workers run). Inside a\n * sandbox child the natural backend is `sandbox`: authored workers run as sub-sandboxes through the\n * SAME `SandboxClient` the bin already loads from `TANGLE_API_KEY` — the deployment shape\n * `delegate_code` used. The brain's router reuses the repo's `resolveRouterBaseUrl` convention\n * (`TANGLE_ROUTER_URL` / `TANGLE_ROUTER_BASE_URL`), normalised to an OpenAI-compatible `/v1` endpoint,\n * keyed by `TANGLE_API_KEY`.\n */\n\nimport type { BackendType } from '@tangle-network/sandbox'\nimport { type RouterEnv, resolveRouterBaseUrl } from '../model-resolution.js'\nimport type { SandboxClient } from '../runtime'\nimport type { RouterConfig } from '../runtime/router-client'\nimport type { ExecutorConfig } from '../runtime/supervise/runtime'\nimport type { DelegateHandlerOptions } from './tools/delegate'\n\nconst DEFAULT_SUPERVISOR_MODEL = 'moonshotai/kimi-k2.6'\nconst DEFAULT_WORKER_HARNESS = 'opencode'\n\nfunction trimmed(value: string | undefined): string | undefined {\n const v = value?.trim()\n return v ? v : undefined\n}\n\n/** True when the operator opted the generic `delegate` verb in (`MCP_ENABLE_DELEGATE=1`). Default off:\n * the wiring is additive, so existing `delegate_code` / `delegate_research` consumers are unaffected. */\nexport function delegateEnabled(env: NodeJS.ProcessEnv = process.env): boolean {\n return env.MCP_ENABLE_DELEGATE === '1'\n}\n\n/** Resolve the supervisor brain's router substrate from env. The key falls back through the platform\n * key the bin already requires; the base reuses `resolveRouterBaseUrl`, normalised to `/v1`. */\nfunction resolveRouter(env: NodeJS.ProcessEnv): RouterConfig {\n const routerKey = trimmed(env.MCP_SUPERVISOR_ROUTER_KEY) ?? trimmed(env.TANGLE_API_KEY) ?? ''\n const base = trimmed(env.MCP_SUPERVISOR_ROUTER_BASE_URL) ?? resolveRouterBaseUrl(env as RouterEnv)\n const routerBaseUrl = /\\/v\\d+\\/?$/.test(base)\n ? base.replace(/\\/$/, '')\n : `${base.replace(/\\/$/, '')}/v1`\n const model =\n trimmed(env.MCP_SUPERVISOR_MODEL) ??\n trimmed(env.MCP_WORKER_MODEL) ??\n trimmed(env.WORKER_MODEL) ??\n DEFAULT_SUPERVISOR_MODEL\n return { routerBaseUrl, routerKey, model }\n}\n\n/**\n * Build the `delegateSupervisor` substrate for `createMcpServer` from env + the bin's loaded\n * `SandboxClient`. Returns `undefined` when `delegate` is not opted in, so the caller mounts it only\n * when asked. The worker backend is `sandbox` (authored workers run as sub-sandboxes via the same\n * client) on the harness named by `MCP_DELEGATE_WORKER_HARNESS` (default `opencode`).\n */\nexport function resolveDelegateSupervisor(\n sandboxClient: SandboxClient,\n env: NodeJS.ProcessEnv = process.env,\n): DelegateHandlerOptions | undefined {\n if (!delegateEnabled(env)) return undefined\n const router = resolveRouter(env)\n const harness = (trimmed(env.MCP_DELEGATE_WORKER_HARNESS) ??\n DEFAULT_WORKER_HARNESS) as BackendType\n const backend: ExecutorConfig = {\n backend: 'sandbox',\n harness,\n sandboxClient,\n }\n return {\n router,\n backend,\n model: router.model,\n }\n}\n","/**\n * Researcher delegate provisioning — resolves the worker harness, model, and router\n * credentials for `delegate_research`, and injects the OpenAI-compatible router creds\n * into a sandbox agent-run spec.\n *\n * Why this exists: the agent-knowledge researcher profile defaults to a harness\n * (`opencode/zai-coding-plan/glm-5.1`) that isn't broadly provisionable, and the sandbox\n * SDK does not wire `backend.model.apiKey` into the in-box agent's OpenAI-compatible\n * provider. So the MCP server picks a provisionable harness + model and passes the router\n * creds as box env. Everything is env-overridable and reuses the repo's router resolution.\n */\nimport { type RouterEnv, resolveRouterBaseUrl } from '../model-resolution.js'\n\nexport interface ResearcherProvisioning {\n harness: string\n /** Worker model id (router-served). */\n model: string\n /** OpenAI-compatible router key for the in-box provider; undefined disables injection. */\n routerKey?: string\n /** OpenAI-compatible router base, always ending in a `/vN` segment. */\n routerBaseUrl: string\n /** Explicit fanout harness list (MCP_RESEARCHER_FANOUT_HARNESSES); undefined ⇒ caller defaults. */\n fanoutHarnesses?: string[]\n /** Per-harness fanout model overrides (MCP_RESEARCHER_FANOUT_MODELS), index-aligned. */\n fanoutModels?: string[]\n}\n\n/** A sandbox agent-run spec whose box env can be overridden. */\nexport interface ProvisionableSpec {\n sandboxOverrides?: { env?: Record<string, string> } & Record<string, unknown>\n}\n\nconst DEFAULT_HARNESS = 'opencode'\nconst DEFAULT_MODEL = 'moonshotai/kimi-k2.6'\n\nfunction trimmed(value: string | undefined): string | undefined {\n const t = value?.trim()\n return t ? t : undefined\n}\n\nfunction csv(value: string | undefined): string[] | undefined {\n const list = value\n ?.split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n return list && list.length > 0 ? list : undefined\n}\n\n/**\n * Resolve harness/model/router from env. Model falls back through the repo's\n * `WORKER_MODEL` convention; router base reuses `resolveRouterBaseUrl` (TANGLE_ROUTER_URL\n * / TANGLE_ROUTER_BASE_URL) and is normalized to an OpenAI-compatible `/v1` endpoint.\n */\nexport function resolveResearcherProvisioning(\n env: NodeJS.ProcessEnv = process.env,\n): ResearcherProvisioning {\n const harness = trimmed(env.MCP_RESEARCHER_HARNESS) ?? DEFAULT_HARNESS\n const model =\n trimmed(env.MCP_RESEARCHER_MODEL) ??\n trimmed(env.MCP_WORKER_MODEL) ??\n trimmed(env.WORKER_MODEL) ??\n DEFAULT_MODEL\n const routerKey = trimmed(env.MCP_RESEARCHER_ROUTER_KEY) ?? trimmed(env.TANGLE_API_KEY)\n const base = trimmed(env.MCP_RESEARCHER_ROUTER_BASE_URL) ?? resolveRouterBaseUrl(env as RouterEnv)\n const routerBaseUrl = /\\/v\\d+\\/?$/.test(base)\n ? base.replace(/\\/$/, '')\n : `${base.replace(/\\/$/, '')}/v1`\n const fanoutHarnesses = csv(env.MCP_RESEARCHER_FANOUT_HARNESSES)\n const fanoutModels = csv(env.MCP_RESEARCHER_FANOUT_MODELS)\n return {\n harness,\n model,\n ...(routerKey ? { routerKey } : {}),\n routerBaseUrl,\n ...(fanoutHarnesses ? { fanoutHarnesses } : {}),\n ...(fanoutModels ? { fanoutModels } : {}),\n }\n}\n\n/**\n * Overlay the router creds onto a spec's box env (in place): preserve every env var the\n * preset already supplied and set OPENAI_API_KEY / OPENAI_BASE_URL on top (these two are\n * intentionally authoritative — they point the in-box provider at the router). No-op when\n * there is no router key.\n */\nexport function applyRouterEnv(\n spec: ProvisionableSpec,\n routerKey: string | undefined,\n routerBaseUrl: string,\n): void {\n if (!routerKey) return\n spec.sandboxOverrides = {\n ...(spec.sandboxOverrides ?? {}),\n env: {\n ...(spec.sandboxOverrides?.env ?? {}),\n OPENAI_API_KEY: routerKey,\n OPENAI_BASE_URL: routerBaseUrl,\n },\n }\n}\n","#!/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 * MCP_ENABLE_DELEGATE set to `1` to serve the ONE generic `delegate` verb (the\n * replacement for delegate_code / delegate_research). Its authoring\n * supervisor runs the brain on the router and spawns authored\n * workers as sub-sandboxes via the same client; needs TANGLE_API_KEY.\n * MCP_SUPERVISOR_MODEL supervisor brain model id (falls back to MCP_WORKER_MODEL, then\n * WORKER_MODEL, then a default). Must be a tool-calling model.\n * MCP_SUPERVISOR_ROUTER_KEY router key for the supervisor brain (defaults to TANGLE_API_KEY)\n * MCP_SUPERVISOR_ROUTER_BASE_URL router base for the supervisor brain (defaults to the repo's\n * resolveRouterBaseUrl, normalized to `/v1`)\n * MCP_DELEGATE_WORKER_HARNESS harness the authored workers run on (default `opencode`)\n * MCP_RESEARCHER_HARNESS researcher worker harness (default `opencode`)\n * MCP_RESEARCHER_MODEL researcher worker model id (falls back to\n * MCP_WORKER_MODEL, then WORKER_MODEL, then a default)\n * MCP_RESEARCHER_FANOUT_HARNESSES comma-separated harnesses for researcher variants > 1\n * MCP_RESEARCHER_FANOUT_MODELS comma-separated per-harness models, index-aligned\n * MCP_RESEARCHER_ROUTER_KEY OpenAI-compatible router key for the in-box agent\n * (defaults to TANGLE_API_KEY)\n * MCP_RESEARCHER_ROUTER_BASE_URL router base for the in-box agent (defaults to the\n * repo's resolveRouterBaseUrl, normalized to `/v1`)\n * AGENT_RUNTIME_DELEGATION_STATE_FILE\n * optional — absolute path of a JSON state\n * file. When set, delegation records persist\n * across MCP restarts (FileDelegationStore):\n * status/history survive and idempotency keys\n * dedupe across processes. Single-variant\n * coder/researcher delegations additionally\n * dispatch DETACHED (driveTurn ticks against a\n * deterministic session id) on session-backed\n * placements, so restored in-flight records\n * resume against their still-running sandbox\n * sessions; non-detached in-flight records\n * settle as failed with a truthful\n * driver-restart error.\n * AGENT_RUNTIME_DELEGATION_DETACHED\n * set to `0` to keep every delegation on the\n * streaming path even when the state file is\n * configured (disables detached dispatch +\n * resume).\n * AGENT_RUNTIME_DELEGATION_STATE_RECOVER\n * set to `1` to archive a corrupt state file\n * (`<file>.corrupt-<ts>`) and start empty\n * instead of refusing to boot.\n * AGENT_RUNTIME_DELEGATION_RETAIN_TERMINAL\n * optional — positive integer cap on retained\n * terminal records. Unset = keep forever.\n */\n\nimport type { SandboxInstance } from '@tangle-network/sandbox'\nimport { coderTaskToPrompt } from '../profiles/coder'\nimport type { AgentRunSpec, LoopTraceEmitter, SandboxClient } from '../runtime'\nimport { runLoop } from '../runtime'\nimport { detectExecutor } from './bin-helpers'\nimport { delegateEnabled, resolveDelegateSupervisor } from './delegate-supervisor-provisioning'\nimport {\n coderTaskFromArgs,\n detachedSessionDelegate,\n type ResearcherDelegate,\n settleDetachedCoderTurn,\n} from './delegates'\nimport { DEFAULT_SANDBOX_BASE_URL } from './delegation-profile'\nimport { FileDelegationStore } from './delegation-store'\nimport { composeLoopTraceEmitters } from './delegation-trace'\nimport {\n createDetachedTurnResumeDriver,\n type DetachedTurn,\n type DriveTurnCapableBox,\n detachedTurnEvents,\n formatDetachedSessionRef,\n parseDetachedSessionRef,\n runDetachedTurn,\n} from './detached-turn'\nimport type { DelegationExecutor } from './executor'\nimport {\n applyRouterEnv,\n type ProvisionableSpec,\n resolveResearcherProvisioning,\n} from './researcher-provisioning'\nimport { createMcpServer } from './server'\nimport { type DelegationResumeDriver, DelegationTaskQueue } from './task-queue'\nimport {\n createPropagatingTraceEmitter,\n readTraceContextFromEnv,\n type TraceContext,\n} from './trace-propagation'\nimport type { DelegateCodeArgs, DelegateResearchArgs, 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 wantDelegate = delegateEnabled(process.env)\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. The generic `delegate` verb needs the client too: its\n // authored workers run as sub-sandboxes (the `sandbox` backend).\n const needsSandbox = wantCoder || wantResearcher || wantDelegate\n let sandboxClient: SandboxClient | 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 // The same context is stamped onto every delegation record (traceId /\n // parentSpanId) so journal consumers join records into the caller's trace.\n const traceContext = readTraceContextFromEnv()\n const { emitter: traceEmitter, exporter: traceExporter } =\n createPropagatingTraceEmitter(traceContext)\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 ? detachedSessionDelegate({\n executor,\n fanoutHarnesses,\n maxConcurrency,\n traceEmitter,\n })\n : undefined\n\n const researcherSupport =\n wantResearcher && executor\n ? await loadResearcherSupport(executor, maxConcurrency, traceEmitter)\n : undefined\n\n // Detached dispatch + resume is QUARANTINED behind MCP_ENABLE_DETACHED_RESUME (default off): the\n // recursive Scope/worktree-CLI leaf has no durable detached-resume equivalent yet, so the\n // sandbox-session resume path is kept but opt-in. It additionally requires the durable store and\n // a session-backed placement with real credentials: in-process placement has no sandbox session\n // to detach, and the diagnostic no-key stub cannot resolve boxes.\n // AGENT_RUNTIME_DELEGATION_DETACHED=0 keeps everything on the streaming path even when enabled.\n const detachedDispatch =\n process.env.MCP_ENABLE_DETACHED_RESUME === '1' &&\n Boolean(process.env.AGENT_RUNTIME_DELEGATION_STATE_FILE?.trim()) &&\n process.env.AGENT_RUNTIME_DELEGATION_DETACHED !== '0' &&\n Boolean(process.env.TANGLE_API_KEY) &&\n (executor?.placement === 'sibling' || executor?.placement === 'fleet')\n if (detachedDispatch) {\n process.stderr.write(\n 'agent-runtime-mcp: detached dispatch enabled — single-variant delegations resume across restarts\\n',\n )\n }\n const resumeDriver =\n detachedDispatch && sandboxClient\n ? buildResumeDriver({ sandboxClient, researcherResume: researcherSupport?.resume })\n : undefined\n\n // The ONE generic `delegate` verb — opt-in via MCP_ENABLE_DELEGATE=1. Its authoring supervisor\n // runs the brain on the router and spawns authored workers as sub-sandboxes through the SAME\n // client, so it needs the loaded `sandboxClient`. Gated on the client resolving (no key → no\n // delegate, matching the coder/researcher fail-closed posture).\n const delegateSupervisor =\n wantDelegate && sandboxClient ? resolveDelegateSupervisor(sandboxClient) : undefined\n if (wantDelegate && delegateSupervisor) {\n process.stderr.write('agent-runtime-mcp: delegate enabled — generic authoring supervisor\\n')\n }\n\n const durableQueue = await buildDurableQueueFromEnv(resumeDriver, traceContext)\n const server = createMcpServer({\n coderDelegate,\n researcherDelegate: researcherSupport?.delegate,\n ...(delegateSupervisor ? { delegateSupervisor } : {}),\n detachedDispatch,\n traceContext,\n ...(durableQueue ? { queue: durableQueue } : {}),\n })\n\n const shutdown = () => {\n server.stop()\n const pending: Promise<unknown>[] = []\n if (traceExporter) pending.push(traceExporter.shutdown())\n // Drain journal writes so the state file reflects the final record\n // states before the process exits. A persist failure already routed\n // through onPersistError; swallow the duplicate rejection here.\n if (durableQueue) pending.push(durableQueue.flush().catch(() => {}))\n if (pending.length === 0) {\n process.exit(0)\n return\n }\n void Promise.allSettled(pending).finally(() => process.exit(0))\n }\n process.on('SIGINT', shutdown)\n process.on('SIGTERM', shutdown)\n\n await server.serve()\n}\n\nasync function buildDurableQueueFromEnv(\n resumeDriver: DelegationResumeDriver | undefined,\n traceContext: TraceContext,\n): Promise<DelegationTaskQueue | undefined> {\n const stateFile = process.env.AGENT_RUNTIME_DELEGATION_STATE_FILE?.trim()\n if (!stateFile) return undefined\n const store = new FileDelegationStore({\n filePath: stateFile,\n recoverCorrupt: process.env.AGENT_RUNTIME_DELEGATION_STATE_RECOVER === '1',\n })\n const maxTerminalRecords = parseRetention(process.env.AGENT_RUNTIME_DELEGATION_RETAIN_TERMINAL)\n // With a resume driver, restored in-flight records that carry a\n // detachedSessionRef re-attach to their still-running sandbox sessions;\n // without one (detached dispatch disabled / no credentials) they settle as\n // failed with a truthful driver-restart error.\n const queue = await DelegationTaskQueue.restore({\n store,\n traceContext,\n ...(resumeDriver ? { resumeDelegate: resumeDriver } : {}),\n ...(maxTerminalRecords !== undefined ? { maxTerminalRecords } : {}),\n onPersistError: (error) => {\n // Durable mode that can no longer write is a broken contract: crash\n // loud instead of degrading to memory-only behind the caller's back.\n process.stderr.write(`agent-runtime-mcp: ${error.message}\\n`)\n process.exit(1)\n },\n })\n process.stderr.write(`agent-runtime-mcp: durable delegation state → ${stateFile}\\n`)\n return queue\n}\n\ninterface ResearcherResumeSupport {\n message(args: DelegateResearchArgs): string\n settle(\n turn: DetachedTurn,\n args: DelegateResearchArgs,\n signal: AbortSignal,\n ): Promise<ResearchOutputShape>\n}\n\n/**\n * Compose the `driveTurn`-backed resume driver over the real sandbox client.\n * Profile dispatch: coder records settle through the same parse + validate\n * gate the delegate applies; researcher records settle through the\n * agent-knowledge preset when the peer is installed. Profiles without resume\n * support (ui-auditor, researcher-without-peer) fail loud — the record settles\n * as failed with the reason instead of fabricating an output.\n */\nfunction buildResumeDriver(args: {\n sandboxClient: SandboxClient\n researcherResume: ResearcherResumeSupport | undefined\n}): DelegationResumeDriver {\n const client = args.sandboxClient as SandboxClient & {\n get?: (id: string) => Promise<SandboxInstance | null>\n }\n return createDetachedTurnResumeDriver({\n async resolveSandbox(sandboxId) {\n if (typeof client.get !== 'function') {\n throw new Error(\n 'agent-runtime-mcp: the sandbox client exposes no get(sandboxId); upgrade @tangle-network/sandbox to >= 0.6 to resume detached delegations',\n )\n }\n const box = await client.get(sandboxId)\n if (!box) {\n throw new Error(\n `agent-runtime-mcp: sandbox ${sandboxId} no longer exists — the detached run cannot be resumed`,\n )\n }\n return box as unknown as DriveTurnCapableBox\n },\n buildMessage(record) {\n if (record.profile === 'coder') {\n const task = coderTaskFromArgs(record.args as DelegateCodeArgs)\n return coderTaskToPrompt(task)\n }\n if (record.profile === 'researcher' && args.researcherResume) {\n return args.researcherResume.message(record.args as DelegateResearchArgs)\n }\n throw new Error(\n `agent-runtime-mcp: no detached resume support for profile \"${record.profile}\"`,\n )\n },\n async settleOutput(turn, record, ctx) {\n if (record.profile === 'coder') {\n if (!record.detachedSessionRef) {\n throw new Error(\n `agent-runtime-mcp: record ${record.taskId} reached the resume settle without a detachedSessionRef`,\n )\n }\n return settleDetachedCoderTurn(turn, {\n task: coderTaskFromArgs(record.args as DelegateCodeArgs),\n sessionId: parseDetachedSessionRef(record.detachedSessionRef).sessionId,\n signal: ctx.signal,\n })\n }\n if (record.profile === 'researcher' && args.researcherResume) {\n return args.researcherResume.settle(turn, record.args as DelegateResearchArgs, ctx.signal)\n }\n throw new Error(\n `agent-runtime-mcp: no detached resume support for profile \"${record.profile}\"`,\n )\n },\n })\n}\n\nfunction parseRetention(raw: string | undefined): number | undefined {\n if (raw === undefined || raw.trim() === '') return undefined\n const n = Number(raw)\n if (!Number.isInteger(n) || n < 1) {\n process.stderr.write(\n `agent-runtime-mcp: AGENT_RUNTIME_DELEGATION_RETAIN_TERMINAL must be a positive integer, got \"${raw}\"\\n`,\n )\n process.exit(2)\n }\n return n\n}\n\nasync function loadSandboxClient(apiKey: string | undefined): Promise<SandboxClient> {\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 SandboxClient\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) => SandboxClient }).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 // @tangle-network/sandbox ≥0.6 makes baseUrl required; default it so the MCP server\n // starts without forcing every caller to set SANDBOX_BASE_URL. Treat empty/whitespace as\n // unset (|| not ??) so `SANDBOX_BASE_URL=` still resolves to the default.\n const baseUrl = process.env.SANDBOX_BASE_URL?.trim() || DEFAULT_SANDBOX_BASE_URL\n return new SandboxCtor({ apiKey, baseUrl })\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\ninterface ResearcherSupport {\n delegate: ResearcherDelegate\n resume: ResearcherResumeSupport\n}\n\nasync function loadResearcherSupport(\n executor: DelegationExecutor,\n maxConcurrency: number,\n traceEmitter?: LoopTraceEmitter,\n): Promise<ResearcherSupport | undefined> {\n const sandboxClient = executor.client\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: {\n task: unknown\n harness?: string\n model?: string\n }) => ResearcherProfilePreset\n type FanoutFactory = (opts: {\n task: unknown\n harnesses?: string[]\n models?: (string | undefined)[]\n }) => 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 // Worker harness + model + provider auth. Two reasons a researcher run otherwise makes\n // zero LLM calls and \"produces no winner\" on a successful box: (1) the profile's default\n // harness (opencode/zai-coding-plan/glm-5.1) is not broadly provisionable; (2) the\n // sandbox SDK does not wire backend.model.apiKey into the in-box agent's OpenAI-compatible\n // provider. resolveResearcherProvisioning picks a provisionable harness + model and the\n // router creds (all env-overridable); applyRouterEnv injects them as box env. Applied to\n // BOTH the single-variant path and every fanout agent-run so variants > 1 work too.\n const {\n harness,\n model,\n routerKey,\n routerBaseUrl,\n fanoutHarnesses: cfgFanoutHarnesses,\n fanoutModels,\n } = resolveResearcherProvisioning()\n const buildPreset = (task: unknown): ResearcherProfilePreset => {\n const preset = singleFactory({ task, harness, model })\n applyRouterEnv(preset.agentRunSpec as ProvisionableSpec, routerKey, routerBaseUrl)\n return preset\n }\n\n const settleSingle = async (\n turn: DetachedTurn,\n args: DelegateResearchArgs,\n sessionId: string,\n signal: AbortSignal,\n ): Promise<ResearchOutputShape> => {\n const task = buildResearchTask(args)\n const preset = buildPreset(task)\n if (!preset.validator) {\n throw new Error('agent-runtime-mcp: researcher preset exposes no validator; cannot settle')\n }\n const parsed = preset.output.parse(detachedTurnEvents(sessionId, turn))\n const verdict = await preset.validator.validate(parsed, { iteration: 0, signal })\n if ((verdict as { valid?: boolean }).valid !== true) {\n throw new Error('researcher delegate produced no winner')\n }\n return parsed as ResearchOutputShape\n }\n\n const delegate: ResearcherDelegate = async (args, ctx) => {\n const task = buildResearchTask(args)\n const variants = Math.max(1, Math.trunc(args.variants ?? 1))\n const loopEmitter = composeLoopTraceEmitters(traceEmitter, ctx.traceEmitter)\n ctx.report({ iteration: 0, phase: 'starting' })\n if (variants <= 1) {\n const preset = buildPreset(task)\n // Detached dispatch — same contract as the coder delegate: one session\n // on one box, driveTurn ticks, resume key bound to the sandbox id.\n if (ctx.detachedSessionRef !== undefined && ctx.updateDetachedSessionRef) {\n const { sessionId } = parseDetachedSessionRef(ctx.detachedSessionRef)\n const rebind = ctx.updateDetachedSessionRef\n const spec = preset.agentRunSpec as AgentRunSpec<unknown>\n const turn = await runDetachedTurn({\n client: sandboxClient,\n spec,\n prompt: spec.taskToPrompt(task),\n sessionId,\n bindSandbox: (sandboxId) => rebind(formatDetachedSessionRef({ sandboxId, sessionId })),\n signal: ctx.signal,\n report: ctx.report,\n ...(loopEmitter ? { traceEmitter: loopEmitter } : {}),\n ...(executor.placement === 'fleet' ? { placement: 'fleet' as const } : {}),\n })\n const output = await settleSingle(turn, args, sessionId, ctx.signal)\n ctx.report({ iteration: 1, phase: 'completed' })\n return output\n }\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: {\n sandboxClient,\n signal: ctx.signal,\n ...(loopEmitter ? { traceEmitter: loopEmitter } : {}),\n },\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 // Match the single-variant fix: use a provisionable harness/model and inject router\n // creds into every fanout agent-run, else variants > 1 makes zero LLM calls. Default to\n // `variants` copies of the working harness; MCP_RESEARCHER_FANOUT_HARNESSES overrides for\n // diversity (with optional per-harness MCP_RESEARCHER_FANOUT_MODELS).\n const fanoutHarnesses = cfgFanoutHarnesses ?? Array.from({ length: variants }, () => harness)\n const fanout = fanoutFactory({\n task,\n harnesses: fanoutHarnesses,\n models: fanoutHarnesses.map((_, i) => fanoutModels?.[i] ?? model),\n })\n for (const spec of fanout.agentRuns) {\n applyRouterEnv(spec as ProvisionableSpec, routerKey, routerBaseUrl)\n }\n // The harness list may be shorter than `variants` (misconfig) — never claim more\n // iterations than there are runs.\n const runs = fanout.agentRuns.slice(0, variants)\n const effectiveVariants = Math.max(1, runs.length)\n const result = await runLoop({\n driver: fanout.driver,\n agentRuns: runs,\n output: fanout.output,\n validator: fanout.validator,\n task,\n ctx: {\n sandboxClient,\n signal: ctx.signal,\n ...(loopEmitter ? { traceEmitter: loopEmitter } : {}),\n },\n maxIterations: effectiveVariants,\n maxConcurrency: Math.min(maxConcurrency, effectiveVariants),\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 return {\n delegate,\n resume: {\n message(args) {\n const task = buildResearchTask(args)\n // Use the same preset construction as dispatch so the displayed prompt can't drift.\n const spec = buildPreset(task).agentRunSpec as AgentRunSpec<unknown>\n return spec.taskToPrompt(task)\n },\n async settle(turn, args, signal) {\n // The session id is only the synthesized event's id — the parser reads\n // data.result / data.text, never the id.\n return settleSingle(turn, args, 'resumed-detached-turn', signal)\n },\n },\n }\n}\n\nfunction buildResearchTask(args: DelegateResearchArgs): unknown {\n return {\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}\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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C;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":["trimmed","output","result","trimmed"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-runtime",
|
|
3
|
-
"version": "0.71.
|
|
3
|
+
"version": "0.71.1",
|
|
4
4
|
"description": "Shared task-lifecycle skeleton for agents: a recursive loop kernel for chat turns, one-shot tasks, and multi-attempt loops, with trace capture and eval-gated self-improvement. Domain behavior lives in adapters; scoring and ship-gates in @tangle-network/agent-eval.",
|
|
5
5
|
"homepage": "https://github.com/tangle-network/agent-runtime#readme",
|
|
6
6
|
"repository": {
|