@tangle-network/agent-runtime 0.70.1 → 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/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/{chunk-CRAH5EY2.js → chunk-4KGQHS7U.js} +2 -2
- package/dist/{chunk-YFOPWG74.js → chunk-5ISW5JUF.js} +275 -145
- package/dist/chunk-5ISW5JUF.js.map +1 -0
- package/dist/{chunk-LJZ5GC6C.js → chunk-74UAWZXE.js} +4 -4
- package/dist/{chunk-HY4YOQM2.js → chunk-INXDNX2W.js} +2 -2
- package/dist/{chunk-BGOLR66M.js → chunk-K3RM4MPM.js} +3 -3
- package/dist/{chunk-G3RGMA7C.js → chunk-VMNEQHJR.js} +6 -1
- package/dist/chunk-VMNEQHJR.js.map +1 -0
- package/dist/{coordination-C7WxwHXq.d.ts → coordination-BPQmuwv8.d.ts} +280 -2
- package/dist/{delegates-DqAgo32T.d.ts → delegates-CsXJPZDH.d.ts} +48 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/intelligence.d.ts +1 -1
- package/dist/intelligence.js +1 -1
- package/dist/{loop-runner-bin-a8bu4O5-.d.ts → loop-runner-bin-DLM_bVQO.d.ts} +3 -3
- package/dist/loop-runner-bin.d.ts +4 -4
- package/dist/loop-runner-bin.js +4 -4
- package/dist/loops.d.ts +120 -241
- package/dist/loops.js +6 -2
- package/dist/mcp/bin.js +51 -12
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -6
- package/dist/mcp/index.js +15 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/{openai-tools-DPx9Gzvn.d.ts → openai-tools-kdCS-T12.d.ts} +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-BYa2ZOAx.d.ts → types-CdnEAE3U.d.ts} +1 -1
- package/dist/{worktree-fanout-gNfl0Byj.d.ts → worktree-fanout-CK2ypmEm.d.ts} +3 -45
- package/package.json +1 -1
- package/dist/chunk-G3RGMA7C.js.map +0 -1
- package/dist/chunk-YFOPWG74.js.map +0 -1
- /package/dist/{chunk-CRAH5EY2.js.map → chunk-4KGQHS7U.js.map} +0 -0
- /package/dist/{chunk-LJZ5GC6C.js.map → chunk-74UAWZXE.js.map} +0 -0
- /package/dist/{chunk-HY4YOQM2.js.map → chunk-INXDNX2W.js.map} +0 -0
- /package/dist/{chunk-BGOLR66M.js.map → chunk-K3RM4MPM.js.map} +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createFleetWorkspaceExecutor,
|
|
3
3
|
createSiblingSandboxExecutor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-INXDNX2W.js";
|
|
5
5
|
import {
|
|
6
6
|
runWorktreeHarness
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5ISW5JUF.js";
|
|
8
8
|
import {
|
|
9
9
|
buildLoopOtelSpans,
|
|
10
10
|
createOtelExporter
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-VMNEQHJR.js";
|
|
12
12
|
|
|
13
13
|
// src/mcp/in-process-executor.ts
|
|
14
14
|
import { randomUUID } from "crypto";
|
|
@@ -275,4 +275,4 @@ export {
|
|
|
275
275
|
createPropagatingTraceEmitter,
|
|
276
276
|
traceContextToEnv
|
|
277
277
|
};
|
|
278
|
-
//# sourceMappingURL=chunk-
|
|
278
|
+
//# sourceMappingURL=chunk-74UAWZXE.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
runDetachedTurn,
|
|
8
8
|
runLoop,
|
|
9
9
|
selectValidWinner
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-5ISW5JUF.js";
|
|
11
11
|
import {
|
|
12
12
|
coderProfile,
|
|
13
13
|
coderTaskToPrompt
|
|
@@ -472,4 +472,4 @@ export {
|
|
|
472
472
|
coderTaskFromArgs,
|
|
473
473
|
settleDetachedCoderTurn
|
|
474
474
|
};
|
|
475
|
-
//# sourceMappingURL=chunk-
|
|
475
|
+
//# sourceMappingURL=chunk-INXDNX2W.js.map
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
} from "./chunk-FNMGYYSS.js";
|
|
7
7
|
import {
|
|
8
8
|
detachedSessionDelegate
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-INXDNX2W.js";
|
|
10
10
|
import {
|
|
11
11
|
createExecutorRegistry,
|
|
12
12
|
definePersona,
|
|
13
13
|
runPersonified,
|
|
14
14
|
worktreeFanout
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5ISW5JUF.js";
|
|
16
16
|
import {
|
|
17
17
|
ConfigError
|
|
18
18
|
} from "./chunk-VLF5RHEQ.js";
|
|
@@ -211,4 +211,4 @@ export {
|
|
|
211
211
|
runLoopRunnerCli,
|
|
212
212
|
parseLoopRunnerArgv
|
|
213
213
|
};
|
|
214
|
-
//# sourceMappingURL=chunk-
|
|
214
|
+
//# sourceMappingURL=chunk-K3RM4MPM.js.map
|
|
@@ -138,10 +138,15 @@ function buildLoopSpanNodes(events) {
|
|
|
138
138
|
const rootAttrs = {
|
|
139
139
|
[GEN_AI.operation]: "invoke_workflow",
|
|
140
140
|
[GEN_AI.conversationId]: runId,
|
|
141
|
+
// Explicit run identity under the tangle namespace so a consuming system of
|
|
142
|
+
// record (Tangle Intelligence's run spine) maps this span tree to one run
|
|
143
|
+
// deterministically, instead of inferring it from the conversation id.
|
|
144
|
+
"tangle.run.id": runId,
|
|
141
145
|
"tangle.loop.driver": str(sp.driver) ?? "driver"
|
|
142
146
|
};
|
|
143
147
|
if (Array.isArray(sp.agentRunNames) && sp.agentRunNames.length > 0) {
|
|
144
148
|
rootAttrs["tangle.loop.agents"] = sp.agentRunNames.map(String).join(",");
|
|
149
|
+
rootAttrs["tangle.subject.key"] = String(sp.agentRunNames[0]);
|
|
145
150
|
}
|
|
146
151
|
if (ended) {
|
|
147
152
|
const ep = rec(ended.payload);
|
|
@@ -358,4 +363,4 @@ export {
|
|
|
358
363
|
INTELLIGENCE_WIRE_VERSION,
|
|
359
364
|
exportEvalRuns
|
|
360
365
|
};
|
|
361
|
-
//# sourceMappingURL=chunk-
|
|
366
|
+
//# sourceMappingURL=chunk-VMNEQHJR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/otel-export.ts"],"sourcesContent":["/**\n * OTEL span exporter — streams LoopTraceEvents to an OTLP/HTTP collector.\n *\n * Reads OTEL_EXPORTER_OTLP_ENDPOINT + OTEL_EXPORTER_OTLP_HEADERS from env\n * when no explicit config is given. Keeps the runtime dep-free from\n * @opentelemetry/sdk-trace-base — minimal OTLP/JSON serializer.\n *\n * The exporter accepts both raw OtelSpan objects and LoopTraceEvents\n * (which get converted to OTLP spans automatically).\n */\n\nexport interface OtelExportConfig {\n /** OTLP endpoint. Reads OTEL_EXPORTER_OTLP_ENDPOINT env by default. */\n endpoint?: string\n /** OTLP headers. Reads OTEL_EXPORTER_OTLP_HEADERS env by default. */\n headers?: Record<string, string>\n /** Batch size before flush. Default 64. */\n batchSize?: number\n /** Flush interval ms. Default 5000. */\n flushIntervalMs?: number\n /** Resource attributes stamped on every export. */\n resourceAttributes?: Record<string, string | number | boolean>\n /** Service name. Default 'agent-runtime'. */\n serviceName?: string\n}\n\nexport interface OtelExporter {\n /** Export a span. */\n exportSpan(span: OtelSpan): void\n /** Force flush pending spans. */\n flush(): Promise<void>\n /** Shutdown cleanly. */\n shutdown(): Promise<void>\n}\n\nexport interface OtelSpan {\n traceId: string\n spanId: string\n parentSpanId?: string\n name: string\n kind?: number\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: OtelAttribute[]\n status?: { code: number; message?: string }\n}\n\nexport interface OtelAttribute {\n key: string\n value: { stringValue?: string; intValue?: string; doubleValue?: number; boolValue?: boolean }\n}\n\ninterface OtlpResourceSpans {\n resource: { attributes: OtelAttribute[] }\n scopeSpans: Array<{ scope: { name: string; version: string }; spans: OtelSpan[] }>\n}\n\ninterface OtlpExport {\n resourceSpans: OtlpResourceSpans[]\n}\n\nconst SCOPE = { name: '@tangle-network/agent-runtime', version: '0.33.0' }\n\n/**\n * Current (non-deprecated) OpenTelemetry GenAI semantic-convention keys.\n * Registry: https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/\n * NB: `gen_ai.system` / `gen_ai.usage.prompt_tokens` / `completion_tokens` are\n * DEPRECATED — do not emit them. We use `provider.name` + `input/output_tokens`.\n */\nconst GEN_AI = {\n operation: 'gen_ai.operation.name',\n agentName: 'gen_ai.agent.name',\n conversationId: 'gen_ai.conversation.id',\n inputTokens: 'gen_ai.usage.input_tokens',\n outputTokens: 'gen_ai.usage.output_tokens',\n} as const\n\n/**\n * Create an OTEL exporter. Returns undefined when no endpoint is configured.\n */\nexport function createOtelExporter(config?: OtelExportConfig): OtelExporter | undefined {\n const resolvedEndpoint =\n config?.endpoint ??\n (typeof process !== 'undefined' ? process.env.OTEL_EXPORTER_OTLP_ENDPOINT : undefined)\n if (!resolvedEndpoint) return undefined\n const endpoint: string = resolvedEndpoint\n\n const headers = config?.headers ?? parseHeadersFromEnv()\n const batchSize = config?.batchSize ?? 64\n const flushIntervalMs = config?.flushIntervalMs ?? 5000\n const serviceName = config?.serviceName ?? 'agent-runtime'\n const resourceAttrs = config?.resourceAttributes ?? {}\n\n const pending: OtelSpan[] = []\n let timer: ReturnType<typeof setInterval> | undefined\n let stopped = false\n\n const exporter: OtelExporter = {\n exportSpan(span: OtelSpan): void {\n if (stopped) return\n pending.push(span)\n if (pending.length >= batchSize) {\n void doFlush()\n }\n },\n\n async flush(): Promise<void> {\n await doFlush()\n },\n\n async shutdown(): Promise<void> {\n stopped = true\n if (timer !== undefined) {\n clearInterval(timer)\n timer = undefined\n }\n await doFlush()\n },\n }\n\n timer = setInterval(() => {\n if (pending.length > 0) void doFlush()\n }, flushIntervalMs)\n if (typeof timer === 'object' && 'unref' in timer) {\n ;(timer as NodeJS.Timeout).unref()\n }\n\n async function doFlush(): Promise<void> {\n if (pending.length === 0) return\n const batch = pending.splice(0)\n const body: OtlpExport = {\n resourceSpans: [\n {\n resource: {\n attributes: toAttributes({\n 'service.name': serviceName,\n ...resourceAttrs,\n }),\n },\n scopeSpans: [{ scope: SCOPE, spans: batch }],\n },\n ],\n }\n const url = `${endpoint.replace(/\\/+$/, '')}/v1/traces`\n try {\n await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json', ...headers },\n body: JSON.stringify(body),\n })\n } catch {\n // Best-effort — telemetry export must not crash the runtime.\n }\n }\n\n return exporter\n}\n\n/**\n * Convert a LoopTraceEvent into an OtelSpan for export.\n */\nexport function loopEventToOtelSpan(\n event: {\n kind: string\n runId: string\n timestamp: number\n payload: object\n },\n traceId: string,\n parentSpanId?: string,\n): OtelSpan {\n const spanId = generateSpanId()\n const attrs: Record<string, string | number | boolean> = {\n 'loop.event_kind': event.kind,\n 'loop.run_id': event.runId,\n }\n for (const [k, v] of Object.entries(event.payload)) {\n if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') {\n attrs[`loop.${k}`] = v\n }\n }\n const ts = msToNs(event.timestamp)\n return {\n traceId: padTraceId(traceId),\n spanId,\n parentSpanId: parentSpanId ? padSpanId(parentSpanId) : undefined,\n name: event.kind,\n kind: 1,\n startTimeUnixNano: ts,\n endTimeUnixNano: ts,\n attributes: toAttributes(attrs),\n status: { code: 1 },\n }\n}\n\n/**\n * Sink-neutral node in a reconstructed loop span tree. The root node's\n * `parentSpanId` is `undefined` — sinks decide how to parent it (the OTEL\n * mapper attaches the inherited delegation span; the delegation journal\n * leaves it as the tree root).\n */\nexport interface LoopSpanNode {\n spanId: string\n parentSpanId?: string\n /** `'loop'` | `'loop.round'` | `'loop.iteration'`. */\n name: string\n /** Topology level: loop root, plan round, or iteration branch. */\n kind: 'loop' | 'round' | 'branch'\n startMs: number\n endMs: number\n attrs: Record<string, string | number | boolean>\n /** True when the iteration carried an error — maps to OTEL status code 2. */\n error: boolean\n}\n\n/**\n * Build a nested, real-duration OTLP span tree for ONE loop run from its full\n * ordered `LoopTraceEvent` stream. Unlike `loopEventToOtelSpan` (one flat,\n * zero-duration span per event), this reconstructs the topology hierarchy a\n * GenAI trace viewer renders natively:\n *\n * loop (invoke_workflow)\n * └─ loop.round[k] (invoke_workflow) ← tangle.loop.move.{kind,width,rationale}\n * ├─ loop.iteration[i] (invoke_agent) ← gen_ai.agent.name + usage + verdict + placement\n * └─ …\n *\n * Attributes follow the current GenAI semconv (`gen_ai.*`) where they apply and\n * a namespaced `tangle.loop.*` / `tangle.cost.usd` extension for topology /\n * verdict / placement / cost (not yet standardized). Pure: feed it a buffered\n * per-runId event array (e.g. flushed on `loop.ended`) and export the result.\n */\nexport function buildLoopOtelSpans(\n events: ReadonlyArray<{ kind: string; runId: string; timestamp: number; payload: object }>,\n traceId: string,\n rootParentSpanId?: string,\n): OtelSpan[] {\n const tid = padTraceId(traceId)\n return buildLoopSpanNodes(events).map((node) => ({\n traceId: tid,\n spanId: node.spanId,\n parentSpanId: node.parentSpanId\n ? padSpanId(node.parentSpanId)\n : rootParentSpanId\n ? padSpanId(rootParentSpanId)\n : undefined,\n name: node.name,\n kind: 1,\n startTimeUnixNano: msToNs(node.startMs),\n endTimeUnixNano: msToNs(node.endMs),\n attributes: toAttributes(node.attrs),\n status: { code: node.error ? 2 : 1 },\n }))\n}\n\n/**\n * Sink-neutral core behind {@link buildLoopOtelSpans}: reconstruct the\n * loop → round → branch span tree from one run's ordered `LoopTraceEvent`\n * stream. Consumed by the OTEL mapper above and by the MCP delegation\n * journal's compact trace tee — one topology reconstruction, two sinks.\n * Tolerates partial streams (a run that never reached `loop.ended` closes\n * at the last observed event's timestamp).\n */\nexport function buildLoopSpanNodes(\n events: ReadonlyArray<{ kind: string; runId: string; timestamp: number; payload: object }>,\n): LoopSpanNode[] {\n if (events.length === 0) return []\n const out: LoopSpanNode[] = []\n const num = (v: unknown): number | undefined =>\n typeof v === 'number' && Number.isFinite(v) ? v : undefined\n const str = (v: unknown): string | undefined =>\n typeof v === 'string' && v.length > 0 ? v : undefined\n const rec = (v: unknown): Record<string, unknown> =>\n v && typeof v === 'object' ? (v as Record<string, unknown>) : {}\n\n const started = events.find((e) => e.kind === 'loop.started')\n const ended = events.find((e) => e.kind === 'loop.ended')\n const runId = events[0]?.runId ?? ''\n const rootStart = started?.timestamp ?? events[0]!.timestamp\n const rootEnd = ended?.timestamp ?? events[events.length - 1]!.timestamp\n const rootId = generateSpanId()\n\n const make = (\n spanId: string,\n parentSpanId: string | undefined,\n name: string,\n kind: LoopSpanNode['kind'],\n startMs: number,\n endMs: number,\n attrs: Record<string, string | number | boolean>,\n error = false,\n ): LoopSpanNode => ({\n spanId,\n parentSpanId,\n name,\n kind,\n startMs,\n endMs,\n attrs,\n error,\n })\n\n // root\n const sp = rec(started?.payload)\n const rootAttrs: Record<string, string | number | boolean> = {\n [GEN_AI.operation]: 'invoke_workflow',\n [GEN_AI.conversationId]: runId,\n // Explicit run identity under the tangle namespace so a consuming system of\n // record (Tangle Intelligence's run spine) maps this span tree to one run\n // deterministically, instead of inferring it from the conversation id.\n 'tangle.run.id': runId,\n 'tangle.loop.driver': str(sp.driver) ?? 'driver',\n }\n if (Array.isArray(sp.agentRunNames) && sp.agentRunNames.length > 0) {\n rootAttrs['tangle.loop.agents'] = sp.agentRunNames.map(String).join(',')\n // Subject grain: the primary agent/profile this run drove. Lets the spine\n // group runs under the thing being worked on rather than one service-wide\n // bucket. `agentRunNames[0]` is the lead agent on a fan-out.\n rootAttrs['tangle.subject.key'] = String(sp.agentRunNames[0])\n }\n if (ended) {\n const ep = rec(ended.payload)\n const win = num(ep.winnerIterationIndex)\n if (win !== undefined) rootAttrs['tangle.loop.winner.iteration_index'] = win\n const cost = num(ep.totalCostUsd)\n if (cost !== undefined) rootAttrs['tangle.cost.usd'] = cost\n const dur = num(ep.durationMs)\n if (dur !== undefined) rootAttrs['tangle.loop.duration_ms'] = dur\n const iters = num(ep.iterations)\n if (iters !== undefined) rootAttrs['tangle.loop.iterations'] = iters\n }\n out.push(make(rootId, undefined, 'loop', 'loop', rootStart, rootEnd, rootAttrs))\n\n // rounds + iterations\n const iterStartTs = new Map<number, number>()\n const placementByIdx = new Map<number, Record<string, string>>()\n let currentRoundId: string | undefined\n let pendingRound:\n | { id: string; start: number; attrs: Record<string, string | number | boolean> }\n | undefined\n const flushRound = (endMs: number) => {\n if (!pendingRound) return\n out.push(\n make(\n pendingRound.id,\n rootId,\n 'loop.round',\n 'round',\n pendingRound.start,\n endMs,\n pendingRound.attrs,\n ),\n )\n pendingRound = undefined\n }\n\n for (const e of events) {\n const p = rec(e.payload)\n switch (e.kind) {\n case 'loop.plan': {\n flushRound(e.timestamp)\n const id = generateSpanId()\n const roundIdx = num(p.roundIndex) ?? 0\n const attrs: Record<string, string | number | boolean> = {\n [GEN_AI.operation]: 'invoke_workflow',\n 'tangle.loop.round.index': roundIdx,\n 'tangle.loop.move.kind': str(p.moveKind) ?? 'unknown',\n 'tangle.loop.move.round': roundIdx,\n 'tangle.loop.move.width': num(p.plannedCount) ?? 0,\n }\n const r = str(p.rationale)\n if (r) attrs['tangle.loop.move.rationale'] = r\n const parent = num(p.parentIndex)\n if (parent !== undefined) attrs['tangle.loop.move.parent_index'] = parent\n if (Array.isArray(p.childIndices) && p.childIndices.length > 0) {\n attrs['tangle.loop.move.child_indices'] = p.childIndices.map(String).join(',')\n }\n pendingRound = { id, start: e.timestamp, attrs }\n currentRoundId = id\n break\n }\n case 'loop.iteration.started': {\n const idx = num(p.iterationIndex)\n if (idx !== undefined) iterStartTs.set(idx, e.timestamp)\n break\n }\n case 'loop.iteration.dispatch': {\n const idx = num(p.iterationIndex)\n if (idx === undefined) break\n const place: Record<string, string> = {}\n const kind = str(p.placement)\n if (kind) place['tangle.loop.placement.kind'] = kind\n const sid = str(p.sandboxId)\n if (sid) place['tangle.sandbox.id'] = sid\n const fid = str(p.fleetId)\n if (fid) place['tangle.fleet.id'] = fid\n const mid = str(p.machineId)\n if (mid) place['tangle.machine.id'] = mid\n placementByIdx.set(idx, place)\n break\n }\n case 'loop.iteration.ended': {\n const idx = num(p.iterationIndex) ?? 0\n const start = iterStartTs.get(idx) ?? e.timestamp\n const err = str(p.error)\n const attrs: Record<string, string | number | boolean> = {\n [GEN_AI.operation]: 'invoke_agent',\n 'tangle.loop.iteration.index': idx,\n }\n const agent = str(p.agentRunName)\n if (agent) attrs[GEN_AI.agentName] = agent\n const tu = rec(p.tokenUsage)\n const inTok = num(tu.input)\n if (inTok !== undefined) attrs[GEN_AI.inputTokens] = inTok\n const outTok = num(tu.output)\n if (outTok !== undefined) attrs[GEN_AI.outputTokens] = outTok\n const cost = num(p.costUsd)\n if (cost !== undefined) attrs['tangle.cost.usd'] = cost\n const verdict = rec(p.verdict)\n if (typeof verdict.valid === 'boolean') attrs['tangle.loop.verdict.valid'] = verdict.valid\n const score = num(verdict.score)\n if (score !== undefined) attrs['tangle.loop.verdict.score'] = score\n if (err) attrs['tangle.loop.error'] = err\n const gid = num(p.groupId)\n if (gid !== undefined) attrs['tangle.loop.iteration.group_id'] = gid\n const par = num(p.parentIndex)\n if (par !== undefined) attrs['tangle.loop.iteration.parent_index'] = par\n const dur = num(p.durationMs)\n if (dur !== undefined) attrs['tangle.loop.iteration.duration_ms'] = dur\n const preview = str(p.outputPreview)\n if (preview) attrs['tangle.loop.iteration.output_preview'] = preview\n Object.assign(attrs, placementByIdx.get(idx) ?? {})\n out.push(\n make(\n generateSpanId(),\n currentRoundId ?? rootId,\n 'loop.iteration',\n 'branch',\n start,\n e.timestamp,\n attrs,\n err !== undefined,\n ),\n )\n break\n }\n case 'loop.decision': {\n if (pendingRound) {\n const dec = str(p.decision)\n if (dec) pendingRound.attrs['tangle.loop.decision'] = dec\n flushRound(e.timestamp)\n }\n currentRoundId = undefined\n break\n }\n }\n }\n flushRound(rootEnd)\n return out\n}\n\nfunction parseHeadersFromEnv(): Record<string, string> {\n if (typeof process === 'undefined') return {}\n const raw = process.env.OTEL_EXPORTER_OTLP_HEADERS\n if (!raw) return {}\n const out: Record<string, string> = {}\n for (const pair of raw.split(',')) {\n const eq = pair.indexOf('=')\n if (eq < 0) continue\n const key = pair.slice(0, eq).trim()\n const value = pair.slice(eq + 1).trim()\n if (key) out[key] = value\n }\n return out\n}\n\nfunction toAttributes(record: Record<string, string | number | boolean>): OtelAttribute[] {\n return Object.entries(record).map(([key, value]) => ({\n key,\n value:\n typeof value === 'number'\n ? Number.isInteger(value)\n ? { intValue: value.toString() }\n : { doubleValue: value }\n : typeof value === 'boolean'\n ? { boolValue: value }\n : { stringValue: value },\n }))\n}\n\nfunction msToNs(ms: number): string {\n return (BigInt(Math.floor(ms)) * 1_000_000n).toString()\n}\n\nfunction padSpanId(id: string): string {\n const cleaned = id.replace(/-/g, '')\n return cleaned.slice(0, 16).padEnd(16, '0')\n}\n\nfunction padTraceId(id: string): string {\n const cleaned = id.replace(/-/g, '')\n return cleaned.slice(0, 32).padEnd(32, '0')\n}\n\nfunction generateSpanId(): string {\n const bytes = new Uint8Array(8)\n if (typeof globalThis.crypto?.getRandomValues === 'function') {\n globalThis.crypto.getRandomValues(bytes)\n } else {\n for (let i = 0; i < 8; 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\n// ─── Eval-run ingest (self-improvement provenance) ───────────────────────────\n//\n// Tangle Intelligence has a first-class, non-trace record for self-improvement\n// runs: POST /v1/ingest/eval-runs (\"Mode D\"). Each generation carries a\n// `surfaceHash` (the proposed-change identity) + arbitrary `surface` provenance;\n// a later `gate-decided` event re-emits the same `runId` (idempotent upsert) with\n// a real `gateDecision` + `holdoutLift`, so proposal→verdict is one diffable\n// record. This is how a consumer's RSI loop records WHAT it changed, WHY, from\n// which evidence — the audit trail behind agentic self-improvement.\n\n/** Wire version the eval-runs ingest enforces (X-Tangle-Wire-Version + body). */\nexport const INTELLIGENCE_WIRE_VERSION = '2026-05-26.v1'\n\nexport interface EvalRunGeneration {\n /** 0-based ordinal of this generation within the run (required by ingest). */\n index: number\n /** Identity of the proposed surface change (content-addressed hash). */\n surfaceHash: string\n /** Arbitrary provenance for this generation (rationale, evidence, source). */\n surface?: unknown\n /** Per-scenario results; empty until the generation is measured. */\n cells?: unknown[]\n /** Mean composite score (0 when unmeasured — pair with labels.measured). */\n compositeMean: number\n costUsd: number\n durationMs: number\n}\n\nexport interface EvalRunEvent {\n runId: string\n runDir: string\n /** ISO timestamp. */\n timestamp: string\n status:\n | 'started'\n | 'baseline-complete'\n | 'generation-complete'\n | 'gate-decided'\n | 'finished'\n | 'errored'\n labels?: Record<string, string>\n baseline?: EvalRunGeneration\n generations?: EvalRunGeneration[]\n gateDecision?: 'ship' | 'hold' | 'need_more_work' | 'model_ceiling' | 'arch_ceiling'\n holdoutLift?: number\n totalCostUsd: number\n totalDurationMs: number\n errorMessage?: string\n}\n\nexport interface EvalRunsExportConfig {\n /** Bearer key — tenant is resolved server-side from it. Reads TANGLE_API_KEY. */\n apiKey?: string\n /** Intelligence base. Reads INTELLIGENCE_BASE env, else prod. */\n base?: string\n /** Idempotency-Key header (e.g. the runId) — safe retries + upsert. */\n idempotencyKey?: string\n}\n\nexport interface EvalRunsExportResult {\n ok: boolean\n status: number\n accepted: number\n rejected: Array<{ index: number; reason: string }>\n}\n\nconst DEFAULT_INTELLIGENCE_BASE = 'https://intelligence.tangle.tools'\n\n/**\n * Ship self-improvement eval-run events to Tangle Intelligence. Unlike the\n * best-effort span exporter, this RESOLVES with the ingest verdict (accepted /\n * rejected per event) so a consumer's loop can assert its provenance landed.\n * Throws only on a missing key or network failure.\n */\nexport async function exportEvalRuns(\n events: EvalRunEvent[],\n config?: EvalRunsExportConfig,\n): Promise<EvalRunsExportResult> {\n if (events.length === 0) return { ok: true, status: 0, accepted: 0, rejected: [] }\n const apiKey =\n config?.apiKey ?? (typeof process !== 'undefined' ? process.env.TANGLE_API_KEY : undefined)\n if (!apiKey)\n throw new Error('exportEvalRuns: apiKey required (pass config.apiKey or set TANGLE_API_KEY)')\n const base =\n config?.base ??\n (typeof process !== 'undefined' ? process.env.INTELLIGENCE_BASE : undefined) ??\n DEFAULT_INTELLIGENCE_BASE\n const url = `${base.replace(/\\/+$/, '')}/v1/ingest/eval-runs`\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n authorization: `Bearer ${apiKey}`,\n 'X-Tangle-Wire-Version': INTELLIGENCE_WIRE_VERSION,\n ...(config?.idempotencyKey ? { 'Idempotency-Key': config.idempotencyKey } : {}),\n },\n body: JSON.stringify({ wireVersion: INTELLIGENCE_WIRE_VERSION, events }),\n })\n let parsed: { accepted?: number; rejected?: Array<{ index: number; reason: string }> } = {}\n try {\n parsed = (await res.json()) as typeof parsed\n } catch {\n // non-JSON body (e.g. 5xx HTML) — leave parsed empty\n }\n return {\n ok: res.ok,\n status: res.status,\n accepted: parsed.accepted ?? (res.ok ? events.length : 0),\n rejected: parsed.rejected ?? [],\n }\n}\n"],"mappings":";AA6DA,IAAM,QAAQ,EAAE,MAAM,iCAAiC,SAAS,SAAS;AAQzE,IAAM,SAAS;AAAA,EACb,WAAW;AAAA,EACX,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,cAAc;AAChB;AAKO,SAAS,mBAAmB,QAAqD;AACtF,QAAM,mBACJ,QAAQ,aACP,OAAO,YAAY,cAAc,QAAQ,IAAI,8BAA8B;AAC9E,MAAI,CAAC,iBAAkB,QAAO;AAC9B,QAAM,WAAmB;AAEzB,QAAM,UAAU,QAAQ,WAAW,oBAAoB;AACvD,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,kBAAkB,QAAQ,mBAAmB;AACnD,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,gBAAgB,QAAQ,sBAAsB,CAAC;AAErD,QAAM,UAAsB,C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 -1,4 +1,7 @@
|
|
|
1
|
-
import { c as DelegateFeedbackArgs, d as DelegationFeedbackSnapshot, e as
|
|
1
|
+
import { c as DelegateFeedbackArgs, d as DelegationFeedbackSnapshot, L as LocalHarness, E as ExecutorFactory, e as ExecutorRegistry, f as DeliverableSpec, S as Spend, g as DelegationTaskQueue, h as CoderDelegate, R as ResearcherDelegate, U as UiAuditorDelegate, T as TraceContext, A as Agent, i as Scope, j as ResultBlobStore, B as Budget } from './delegates-CsXJPZDH.js';
|
|
2
|
+
import { T as ToolSpec, R as RouterConfig } from './router-client-C7kp_ECN.js';
|
|
3
|
+
import { BackendType } from '@tangle-network/sandbox';
|
|
4
|
+
import { S as SandboxClient, E as ExecCtx } from './types-CdnEAE3U.js';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* @experimental
|
|
@@ -124,6 +127,274 @@ declare class InMemoryFeedbackStore implements FeedbackStore {
|
|
|
124
127
|
*/
|
|
125
128
|
declare function eventToSnapshot(event: FeedbackEvent): DelegationFeedbackSnapshot;
|
|
126
129
|
|
|
130
|
+
/**
|
|
131
|
+
* @experimental
|
|
132
|
+
*
|
|
133
|
+
* The leaf runtime — the built-in `Executor` IMPLEMENTATIONS behind the ONE
|
|
134
|
+
* open interface frozen in `./types`, plus the open resolver/registry that maps
|
|
135
|
+
* an `AgentSpec` to one of them OR accepts a bring-your-own executor verbatim.
|
|
136
|
+
*
|
|
137
|
+
* The interface is the extension point, not a closed `inline|sandbox|cli` union:
|
|
138
|
+
* - router/inline : a direct OpenAI-compatible Router call, no box (one-shot).
|
|
139
|
+
* - sandbox : COMPOSES the existing `runLoop` kernel as a single-task
|
|
140
|
+
* leaf and surfaces its token/cost usage as `UsageEvent`s;
|
|
141
|
+
* forwards PR #150's optional `lineage` passthrough WITHOUT
|
|
142
|
+
* reinventing checkpoint/fork (streaming).
|
|
143
|
+
* - cli : a Halo/RLM subprocess; `budgetExempt` (no token accounting),
|
|
144
|
+
* excluded from the equal-k arms by construction (streaming).
|
|
145
|
+
* Every metered runtime reports through the SAME normalized `UsageEvent` channel
|
|
146
|
+
* so the conserved budget pool meters them identically. A user's own agent is
|
|
147
|
+
* first-class the moment it implements `Executor` — register it by name or
|
|
148
|
+
* pass it as `AgentSpec.executor`.
|
|
149
|
+
*
|
|
150
|
+
* Layering: `estimateCost`/`isModelPriced` are substrate primitives from
|
|
151
|
+
* `@tangle-network/agent-eval`; `runLoop`/`acquireSandbox` are runtime kernels
|
|
152
|
+
* from this package. No per-vendor adapters live here.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Router/inline connection seam. A direct OpenAI-compatible Router endpoint —
|
|
157
|
+
* the cheapest leaf, no box, no tools. `model` overrides the profile's model
|
|
158
|
+
* hint when present; otherwise the profile's `model.default` is required.
|
|
159
|
+
*/
|
|
160
|
+
interface RouterSeam {
|
|
161
|
+
routerBaseUrl: string;
|
|
162
|
+
routerKey: string;
|
|
163
|
+
model?: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Sandbox executor seam. The `sandboxClient` the composed `runLoop` creates
|
|
167
|
+
* boxes through, plus the optional trace/run/lineage wiring forwarded into the
|
|
168
|
+
* loop. `lineage` is opaque here (PR #150's `RunLoopOptions.lineage`): forwarded
|
|
169
|
+
* forward-compatibly, never inspected — this executor does NOT reinvent
|
|
170
|
+
* checkpoint/fork.
|
|
171
|
+
*/
|
|
172
|
+
interface SandboxSeam {
|
|
173
|
+
sandboxClient: SandboxClient;
|
|
174
|
+
/** Forwarded into the composed `runLoop`'s `ctx` (trace emitter, run handle, etc.). */
|
|
175
|
+
loopCtx?: Partial<Omit<ExecCtx, 'sandboxClient' | 'signal'>>;
|
|
176
|
+
/** PR #150 `RunLoopOptions.lineage` passthrough — opaque; forwarded, not parsed. */
|
|
177
|
+
lineage?: unknown;
|
|
178
|
+
/** Hard cap on the composed loop's iterations. The budget pool reserves against
|
|
179
|
+
* the spawn `Budget.maxIterations`; this is the leaf's own ceiling. Default 1. */
|
|
180
|
+
maxIterations?: number;
|
|
181
|
+
}
|
|
182
|
+
/** CLI subprocess seam. `bin` + `args` describe the Halo/RLM process to spawn. */
|
|
183
|
+
interface CliSeam {
|
|
184
|
+
bin: string;
|
|
185
|
+
args?: string[];
|
|
186
|
+
/** Extra environment for the subprocess (merged over `process.env`). */
|
|
187
|
+
env?: Record<string, string>;
|
|
188
|
+
/** Working directory for the subprocess. */
|
|
189
|
+
cwd?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* cli-worktree seam. A supervisor-authored `AgentProfile` driving a local coding-harness CLI
|
|
193
|
+
* (claude / codex / opencode) on its own git worktree — the leaf `createWorktreeCliExecutor`
|
|
194
|
+
* named as data. `harness` + `repoRoot` + `taskPrompt` are required; the authored
|
|
195
|
+
* `profile.prompt.systemPrompt` + `profile.model.default` reach the harness via the §1.5
|
|
196
|
+
* `harnessInvocation` mapper. Everything else mirrors `WorktreeCliExecutorOptions`.
|
|
197
|
+
*/
|
|
198
|
+
interface CliWorktreeSeam {
|
|
199
|
+
repoRoot: string;
|
|
200
|
+
harness: LocalHarness;
|
|
201
|
+
taskPrompt: string;
|
|
202
|
+
runId?: string;
|
|
203
|
+
baseRef?: string;
|
|
204
|
+
harnessTimeoutMs?: number;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* cli-bridge seam. A local OpenAI-compatible bridge that fronts harness CLIs
|
|
208
|
+
* (claude-code / opencode / kimi / pi) behind one HTTP surface; `model` doubles
|
|
209
|
+
* as the harness selector (e.g. `claude-code/sonnet`, `opencode/<provider>/<model>`).
|
|
210
|
+
* `agentProfile` is the bridge-dialect profile (metadata.disallowedTools, mcp)
|
|
211
|
+
* forwarded verbatim per request — how an arm disables native tools or injects
|
|
212
|
+
* a provider search MCP.
|
|
213
|
+
*
|
|
214
|
+
* The executor opens a RESUMABLE cli-bridge session — structurally identical to the
|
|
215
|
+
* sandbox executor's persistent box, just local. `sessionId` is the stable
|
|
216
|
+
* caller-owned id cli-bridge maps to the harness's internal conversation id; a
|
|
217
|
+
* follow-up steer/resume on the SAME id continues the SAME harness session (opencode
|
|
218
|
+
* `-s`, claude `--resume`, …). Omit it and the executor mints a stable one per spawn.
|
|
219
|
+
*/
|
|
220
|
+
interface BridgeSeam {
|
|
221
|
+
bridgeUrl: string;
|
|
222
|
+
bridgeBearer: string;
|
|
223
|
+
model: string;
|
|
224
|
+
agentProfile?: Record<string, unknown>;
|
|
225
|
+
timeoutMs?: number;
|
|
226
|
+
/** Stable, caller-owned cli-bridge session id for harness-side resume. Defaults
|
|
227
|
+
* to a freshly minted per-spawn id so each worker is its own resumable session. */
|
|
228
|
+
sessionId?: string;
|
|
229
|
+
/** Per-resume-turn inference cap before the worker settles on its last output.
|
|
230
|
+
* Mirrors `routerToolsInlineExecutor.maxTurns`; default 200 (runaway backstop). */
|
|
231
|
+
maxTurns?: number;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Router seam WITH tool use — the tool-using router backend. Same direct
|
|
235
|
+
* OpenAI-compatible endpoint as `RouterSeam`, but each turn passes `tools`; when
|
|
236
|
+
* the model emits tool_calls they run via `executeToolCall` ON THIS HOST and the
|
|
237
|
+
* results fold back as `tool` messages, repeating until the model answers without
|
|
238
|
+
* a tool or `maxTurns` is hit. A real agentic loop, OFF-BOX — no sandbox, so it
|
|
239
|
+
* is unaffected by a box's egress allowlist. One turn = one completion = the
|
|
240
|
+
* equal-compute unit. `executeToolCall` receives the task so per-task tool
|
|
241
|
+
* surfaces (e.g. a gym keyed by task) can dispatch correctly.
|
|
242
|
+
*/
|
|
243
|
+
interface RouterToolsSeam {
|
|
244
|
+
routerBaseUrl: string;
|
|
245
|
+
routerKey: string;
|
|
246
|
+
model?: string;
|
|
247
|
+
tools: ReadonlyArray<ToolSpec>;
|
|
248
|
+
executeToolCall: (name: string, args: Record<string, unknown>, task: unknown) => Promise<string>;
|
|
249
|
+
/** Online observer of each tool step — the seam a `DetectorMonitor` taps to watch the live pipe
|
|
250
|
+
* (raise a `finding` when the worker loops/errors). Called after every tool call resolves, with
|
|
251
|
+
* real per-call wall-clock (`startedAt`/`endedAt`/`durationMs`) so a push `TraceSource` can carry
|
|
252
|
+
* non-zero span durations onto the unified timeline. */
|
|
253
|
+
onToolStep?: (step: {
|
|
254
|
+
toolName: string;
|
|
255
|
+
args: Record<string, unknown>;
|
|
256
|
+
status: 'ok' | 'error';
|
|
257
|
+
startedAt?: number;
|
|
258
|
+
endedAt?: number;
|
|
259
|
+
durationMs?: number;
|
|
260
|
+
}) => void;
|
|
261
|
+
/** Max inference turns. Default 200 (runaway backstop — set far above any
|
|
262
|
+
* legitimate workflow). For tighter per-workflow limits use a cost budget
|
|
263
|
+
* or wall-clock deadline at the call site. */
|
|
264
|
+
maxTurns?: number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The leaf `createWorktreeCliExecutor` as a backend-as-data factory: a supervisor-authored
|
|
268
|
+
* `AgentProfile` driving claude / codex / opencode on its own worktree. `budgetExempt` like
|
|
269
|
+
* the other CLI leaves; the authored systemPrompt + model reach the harness via §1.5.
|
|
270
|
+
*/
|
|
271
|
+
declare const cliWorktreeExecutor: ExecutorFactory<unknown>;
|
|
272
|
+
/**
|
|
273
|
+
* Config for {@link createExecutor}: the backend is DATA — the cost dial a profile,
|
|
274
|
+
* an experiment config, or a replay journal can name — not an import choice. Each
|
|
275
|
+
* variant carries its backend's seam (router/router-tools/bridge/cli/cli-worktree/sandbox).
|
|
276
|
+
*/
|
|
277
|
+
type ExecutorConfig = ({
|
|
278
|
+
backend: 'router';
|
|
279
|
+
} & RouterSeam) | ({
|
|
280
|
+
backend: 'router-tools';
|
|
281
|
+
} & RouterToolsSeam) | ({
|
|
282
|
+
backend: 'bridge';
|
|
283
|
+
} & BridgeSeam) | ({
|
|
284
|
+
backend: 'cli';
|
|
285
|
+
} & CliSeam) | ({
|
|
286
|
+
backend: 'cli-worktree';
|
|
287
|
+
} & CliWorktreeSeam) | ({
|
|
288
|
+
backend: 'sandbox';
|
|
289
|
+
harness?: BackendType;
|
|
290
|
+
} & SandboxSeam);
|
|
291
|
+
/**
|
|
292
|
+
* The single built-in executor factory. Picks a leaf backend by data (`config.backend`),
|
|
293
|
+
* injects the matching seam, and delegates to that backend's built-in implementation.
|
|
294
|
+
* The `Executor` port stays OPEN: bring-your-own agents implement `Executor` directly
|
|
295
|
+
* and never pass through here. Use this (or `createExecutorRegistry`) instead of a
|
|
296
|
+
* per-vendor adapter or a closed `inline|sandbox|cli` switch — those bypass the
|
|
297
|
+
* `UsageEvent` reporting channel.
|
|
298
|
+
*/
|
|
299
|
+
declare function createExecutor(config: ExecutorConfig): ExecutorFactory<unknown>;
|
|
300
|
+
/**
|
|
301
|
+
* The open resolver/registry. Pre-registers the three built-ins under their
|
|
302
|
+
* runtime tags (`'router'`, `'sandbox'`, `'cli'`) and accepts `register(name,
|
|
303
|
+
* factory)` for any additional runtime — and a BYO `AgentSpec.executor` resolves
|
|
304
|
+
* without touching the registry at all. NOT a closed switch; registration + BYO
|
|
305
|
+
* ARE the extension points.
|
|
306
|
+
*
|
|
307
|
+
* `resolve` precedence (frozen in `ExecutorRegistry`): a BYO `spec.executor` →
|
|
308
|
+
* `harness === null` → the `'router'` factory; else a registered factory for the
|
|
309
|
+
* harness-derived runtime (`'sandbox'` for any `BackendType`); else fail loud.
|
|
310
|
+
*/
|
|
311
|
+
declare function createExecutorRegistry(): ExecutorRegistry;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* @experimental
|
|
315
|
+
*
|
|
316
|
+
* `delegate` MCP tool — the ONE generic delegation verb, the agent-facing front door to
|
|
317
|
+
* `delegate()` / `supervise()`. The agent hands it an INTENT (what it wants done); a default
|
|
318
|
+
* authoring supervisor decomposes the intent and AUTHORS the worker profile it needs — there is no
|
|
319
|
+
* hardcoded coder/researcher profile. It is the generic replacement for `delegate_code` /
|
|
320
|
+
* `delegate_research`.
|
|
321
|
+
*
|
|
322
|
+
* Unlike those async, queue-backed tools (kick off → return a taskId → poll `delegation_status`),
|
|
323
|
+
* `delegate` is SYNCHRONOUS: it awaits the full supervised run and returns the delivered output
|
|
324
|
+
* TOGETHER WITH `spentTotal` — the conserved cost of the whole delegation (`iterations` / `tokens` /
|
|
325
|
+
* `usd` / `ms`). Returning the real spend is the whole reason `delegate` beats `delegate_code`,
|
|
326
|
+
* which has no cost channel.
|
|
327
|
+
*
|
|
328
|
+
* The supervisor's substrate (its brain `router`, the worker `backend`, the completion `deliverable`)
|
|
329
|
+
* is INJECTED at server construction — never an agent-supplied arg — exactly as `delegate_code`
|
|
330
|
+
* injects its `CoderDelegate`. The agent supplies only the intent (+ an optional per-call `model` /
|
|
331
|
+
* `runId`).
|
|
332
|
+
*/
|
|
333
|
+
|
|
334
|
+
/** @experimental */
|
|
335
|
+
declare const DELEGATE_TOOL_NAME = "delegate";
|
|
336
|
+
/** @experimental */
|
|
337
|
+
declare const DELEGATE_DESCRIPTION: string;
|
|
338
|
+
/** @experimental */
|
|
339
|
+
declare const DELEGATE_INPUT_SCHEMA: {
|
|
340
|
+
readonly type: "object";
|
|
341
|
+
readonly properties: {
|
|
342
|
+
readonly intent: {
|
|
343
|
+
readonly type: "string";
|
|
344
|
+
readonly description: "What you want accomplished, as an outcome. The supervisor authors the worker.";
|
|
345
|
+
};
|
|
346
|
+
readonly model: {
|
|
347
|
+
readonly type: "string";
|
|
348
|
+
readonly description: "Optional per-call override for the supervisor brain model.";
|
|
349
|
+
};
|
|
350
|
+
readonly runId: {
|
|
351
|
+
readonly type: "string";
|
|
352
|
+
readonly description: "Optional trace-correlation id for this delegation.";
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
readonly required: readonly ["intent"];
|
|
356
|
+
readonly additionalProperties: false;
|
|
357
|
+
};
|
|
358
|
+
/** Parsed `delegate` tool arguments. */
|
|
359
|
+
interface DelegateArgs {
|
|
360
|
+
intent: string;
|
|
361
|
+
model?: string;
|
|
362
|
+
runId?: string;
|
|
363
|
+
}
|
|
364
|
+
/** @experimental */
|
|
365
|
+
declare function validateDelegateArgs(raw: unknown): DelegateArgs;
|
|
366
|
+
/** The synchronous result the `delegate` tool returns to the calling agent: the delivered output (or
|
|
367
|
+
* the no-winner reason) PLUS the conserved spend of the whole delegation. */
|
|
368
|
+
type DelegateResult = {
|
|
369
|
+
status: 'winner';
|
|
370
|
+
out: unknown;
|
|
371
|
+
outRef: string;
|
|
372
|
+
spentTotal: Spend;
|
|
373
|
+
} | {
|
|
374
|
+
status: 'no-winner';
|
|
375
|
+
reason: string;
|
|
376
|
+
spentTotal: Spend;
|
|
377
|
+
};
|
|
378
|
+
/** @experimental */
|
|
379
|
+
interface DelegateHandlerOptions {
|
|
380
|
+
/** The supervisor brain's router substrate (REQUIRED — the default supervisor is router-brained). */
|
|
381
|
+
router: RouterConfig;
|
|
382
|
+
/** WHERE the authored workers run. Required for `supervise()` to spawn anything. */
|
|
383
|
+
backend: ExecutorConfig;
|
|
384
|
+
/** The completion oracle the authored workers settle against (settled ⟺ delivered). */
|
|
385
|
+
deliverable?: DeliverableSpec;
|
|
386
|
+
/** Default supervisor brain model when a call omits `model`. */
|
|
387
|
+
model?: string;
|
|
388
|
+
/** Restrict the run to this subset of models. */
|
|
389
|
+
allowedModels?: readonly string[];
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Build the `delegate` tool handler. Closes over the injected supervisor substrate (`router` /
|
|
393
|
+
* `backend` / `deliverable`); each call routes the agent's intent to `delegate()` and returns the
|
|
394
|
+
* delivered output with its conserved cost.
|
|
395
|
+
*/
|
|
396
|
+
declare function createDelegateHandler(options: DelegateHandlerOptions): (raw: unknown) => Promise<DelegateResult>;
|
|
397
|
+
|
|
127
398
|
/**
|
|
128
399
|
* @experimental
|
|
129
400
|
*
|
|
@@ -144,6 +415,13 @@ declare function eventToSnapshot(event: FeedbackEvent): DelegationFeedbackSnapsh
|
|
|
144
415
|
|
|
145
416
|
/** @experimental */
|
|
146
417
|
interface McpServerOptions {
|
|
418
|
+
/**
|
|
419
|
+
* Required to enable `delegate` — the ONE generic delegation verb (the replacement for
|
|
420
|
+
* delegate_code / delegate_research). Inject the supervisor substrate: its brain `router`, the
|
|
421
|
+
* worker `backend`, and the completion `deliverable`. The supervisor AUTHORS its own worker from
|
|
422
|
+
* the agent's intent, so there is no worker profile to wire here.
|
|
423
|
+
*/
|
|
424
|
+
delegateSupervisor?: DelegateHandlerOptions;
|
|
147
425
|
/** Required to enable delegate_code. */
|
|
148
426
|
coderDelegate?: CoderDelegate;
|
|
149
427
|
/**
|
|
@@ -385,4 +663,4 @@ interface CoordinationTools {
|
|
|
385
663
|
/** Build the driver's MCP tools over a live scope. */
|
|
386
664
|
declare function createCoordinationTools(opts: CoordinationToolsOptions): CoordinationTools;
|
|
387
665
|
|
|
388
|
-
export { type AnalystRegistry as A, type BusEvent as B, type CoordinationEvent as C, type
|
|
666
|
+
export { type AnalystRegistry as A, type BusEvent as B, type CoordinationEvent as C, DELEGATE_DESCRIPTION as D, type ExecutorConfig as E, type FeedbackStore as F, createEventBus as G, createExecutor as H, InMemoryFeedbackStore as I, type JsonRpcMessage as J, createExecutorRegistry as K, type MakeWorkerAgent as M, type PublishOptions as P, type Question as Q, type SettledWorker as S, type CoordinationTools as a, type CoordinationToolsOptions as b, DELEGATE_INPUT_SCHEMA as c, DELEGATE_TOOL_NAME as d, type DelegateArgs as e, type DelegateHandlerOptions as f, type DelegateResult as g, type FeedbackEvent as h, type JsonRpcResponse as i, type McpServer as j, type McpServerOptions as k, type McpToolDescriptor as l, type McpTransport as m, type QuestionDecision as n, type QuestionPolicy as o, type QuestionRecord as p, createCoordinationTools as q, createDelegateHandler as r, createInProcessTransport as s, createMcpServer as t, eventToSnapshot as u, validateDelegateArgs as v, type BusRecord as w, type BusStats as x, type EventBus as y, cliWorktreeExecutor as z };
|
|
@@ -2,7 +2,7 @@ import { ChildProcess } from 'node:child_process';
|
|
|
2
2
|
import { DefaultVerdict, AgentEvalError } from '@tangle-network/agent-eval';
|
|
3
3
|
import { AgentProfile } from '@tangle-network/agent-interface';
|
|
4
4
|
import { BackendType, SandboxEvent, SandboxInstance } from '@tangle-network/sandbox';
|
|
5
|
-
import { d as LoopTokenUsage, b as RuntimeHooks, e as LoopTraceEmitter, L as LoopTraceEvent, S as SandboxClient, A as AgentRunSpec } from './types-
|
|
5
|
+
import { d as LoopTokenUsage, b as RuntimeHooks, e as LoopTraceEmitter, L as LoopTraceEvent, S as SandboxClient, A as AgentRunSpec } from './types-CdnEAE3U.js';
|
|
6
6
|
import { a as UiLens, U as UiFinding, C as CoderTask } from './substrate-BoRXgvka.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -535,6 +535,10 @@ type SupervisedResult<Out> = {
|
|
|
535
535
|
reason: 'all-children-down' | 'budget-exhausted' | 'aborted';
|
|
536
536
|
tree: TreeView;
|
|
537
537
|
downCount: number;
|
|
538
|
+
/** The conserved spend incurred before the run failed — real cost is paid even when no
|
|
539
|
+
* worker delivers, so the caller always learns what the delegation actually spent. Summed
|
|
540
|
+
* off the same journal the `winner` path reads. */
|
|
541
|
+
spentTotal: Spend;
|
|
538
542
|
};
|
|
539
543
|
/** Live root handle — the substrate a chat/pi-viz client attaches to (Q2). `signal`
|
|
540
544
|
* delivers an out-of-band message to the running root; `view()` materializes the tree. */
|
|
@@ -1656,6 +1660,48 @@ declare class DelegationTaskQueue {
|
|
|
1656
1660
|
*/
|
|
1657
1661
|
declare function hashIdempotencyInput(value: unknown): string;
|
|
1658
1662
|
|
|
1663
|
+
/**
|
|
1664
|
+
* @experimental
|
|
1665
|
+
*
|
|
1666
|
+
* The completion-oracle: **settled ⟺ DELIVERED.**
|
|
1667
|
+
*
|
|
1668
|
+
* Foreman's one hard lesson (0/18 self-improvement deliverables) — "done" must mean a check
|
|
1669
|
+
* PASSED, not the agent's say-so. `gateOnDeliverable` wraps an `Executor` so its settlement
|
|
1670
|
+
* is `valid` ONLY when the deliverable check passes. The child still RUNS and settles (its
|
|
1671
|
+
* spend is conserved into the pool either way), but a child that ran WITHOUT delivering
|
|
1672
|
+
* settles `valid:false` — so a keep-best driver never counts it as done, and a gate never
|
|
1673
|
+
* inflates with self-judged wins.
|
|
1674
|
+
*
|
|
1675
|
+
* Dual-purpose by construction:
|
|
1676
|
+
* - product: the agent fleet only advances on real, checked deliverables.
|
|
1677
|
+
* - proof: the gate's `valid` is the honest settle — equal-k comparisons can't be gamed by an
|
|
1678
|
+
* arm that "ran" without producing the artifact.
|
|
1679
|
+
*
|
|
1680
|
+
* The check is a DEPLOYABLE oracle — a test command, a state verifier, the commit0 judge —
|
|
1681
|
+
* read off the child's output, never the model judging itself. A throwing check is
|
|
1682
|
+
* fail-closed (not delivered), never a crash.
|
|
1683
|
+
*/
|
|
1684
|
+
|
|
1685
|
+
/**
|
|
1686
|
+
* The deployable completion oracle passed to {@link gateOnDeliverable}: a `check` that
|
|
1687
|
+
* decides DELIVERED (settles `valid` ⟺ it resolves true) plus an optional `describe` of
|
|
1688
|
+
* what the spawn was supposed to produce. The check reads the child's output — never the
|
|
1689
|
+
* model judging itself.
|
|
1690
|
+
*/
|
|
1691
|
+
interface DeliverableSpec<Out = unknown> {
|
|
1692
|
+
/** The deployable check that decides DELIVERED. `settled.valid ⟺ this resolves true`. */
|
|
1693
|
+
check: (out: Out) => boolean | Promise<boolean>;
|
|
1694
|
+
/** What the spawn was supposed to produce — surfaced in traces/reports. */
|
|
1695
|
+
describe?: string;
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Wrap an `Executor` so its settlement `valid` reflects the deliverable check, not the
|
|
1699
|
+
* inner verdict. Handles both `execute` shapes (one-shot `Promise<ExecutorResult>` and
|
|
1700
|
+
* streaming `AsyncIterable<UsageEvent>` + `resultArtifact()`); the check runs once the inner
|
|
1701
|
+
* executor has produced its output. The inner `score` is preserved; only `valid` is gated.
|
|
1702
|
+
*/
|
|
1703
|
+
declare function gateOnDeliverable<Out>(inner: Executor<Out>, deliverable: DeliverableSpec<Out>): Executor<Out>;
|
|
1704
|
+
|
|
1659
1705
|
/**
|
|
1660
1706
|
* @experimental
|
|
1661
1707
|
*
|
|
@@ -2239,4 +2285,4 @@ interface SettleDetachedCoderTurnOptions {
|
|
|
2239
2285
|
*/
|
|
2240
2286
|
declare function settleDetachedCoderTurn(turn: DetachedTurn, options: SettleDetachedCoderTurnOptions): Promise<CoderOutput>;
|
|
2241
2287
|
|
|
2242
|
-
export { type
|
|
2288
|
+
export { type DelegationHistoryEntry as $, type Agent as A, type Budget as B, type CoderReviewer as C, type DelegateCodeArgs as D, type ExecutorFactory as E, type FleetHandle as F, type GitRunner as G, type DelegationHistoryArgs as H, type DelegationStatusResult as I, type DelegationStatusArgs as J, type CappedDelegationTrace as K, type LocalHarness as L, type CoderReview as M, type NodeId as N, type CreateWorktreeOptions as O, DELEGATION_TRACE_MAX_BYTES as P, DELEGATION_TRACE_MAX_SPANS as Q, type ResearcherDelegate as R, type Spend as S, type TraceContext as T, type UiAuditorDelegate as U, type DelegateCodeConfig as V, type DelegateResearchConfig as W, type DelegateRunCtx as X, type DelegateUiAuditConfig as Y, type DelegateUiAuditRoute as Z, type DelegationError as _, type DetachedWinnerSelection as a, type EvalRunGeneration as a$, DelegationPersistenceError as a0, type DelegationProfile as a1, type DelegationProgress as a2, type DelegationRecord as a3, type DelegationResultPayload as a4, type DelegationResumeContext as a5, type DelegationResumeDriver as a6, type DelegationResumeTick as a7, type DelegationRunContext as a8, DelegationStateCorruptError as a9, type SiblingSandboxExecutorOptions as aA, type SubmitInput as aB, type SubmitOutput as aC, type UiAuditorDelegationOutput as aD, type WorktreeHandle as aE, buildDelegationTraceSpans as aF, capDelegationTrace as aG, captureWorktreeDiff as aH, coderTaskFromArgs as aI, composeLoopTraceEmitters as aJ, createDelegationTraceCollector as aK, createDetachedTurnResumeDriver as aL, createFleetWorkspaceExecutor as aM, createPropagatingTraceEmitter as aN, createSiblingSandboxExecutor as aO, createWorktree as aP, detachedSessionDelegate as aQ, detachedTurnEvents as aR, formatDetachedSessionRef as aS, hashIdempotencyInput as aT, parseDetachedSessionRef as aU, readTraceContextFromEnv as aV, removeWorktree as aW, runDetachedTurn as aX, settleDetachedCoderTurn as aY, traceContextToEnv as aZ, type EvalRunEvent as a_, type DelegationStatus as aa, type DelegationStore as ab, type DelegationTaskQueueOptions as ac, type DelegationTraceCaps as ad, type DelegationTraceCollector as ae, type DelegationTraceSpan as af, type DetachedSessionDelegateOptions as ag, type DetachedSessionRefParts as ah, type DetachedTurn as ai, type DetachedTurnResumeDriverOptions as aj, type DiffOptions as ak, type DiffResult as al, type DriveTurnCapableBox as am, type DriveTurnTick as an, type FeedbackRating as ao, type FeedbackRefersTo as ap, FileDelegationStore as aq, type FileDelegationStoreOptions as ar, type FleetWorkspaceExecutorOptions as as, InMemoryDelegationStore as at, type LocalHarnessResult as au, type RemoveWorktreeOptions as av, type ResearchOutputShape as aw, type RunDetachedTurnOptions as ax, type RunLocalHarnessOptions as ay, type SettleDetachedCoderTurnOptions as az, type CoderOutput as b, type EvalRunsExportConfig as b0, type EvalRunsExportResult as b1, INTELLIGENCE_WIRE_VERSION as b2, type LoopSpanNode as b3, type OtelAttribute as b4, type OtelExportConfig as b5, type OtelExporter as b6, type OtelSpan as b7, buildLoopOtelSpans as b8, buildLoopSpanNodes as b9, createOtelExporter as ba, exportEvalRuns as bb, loopEventToOtelSpan as bc, type SpawnEvent as bd, type UsageEvent as be, type Supervisor as bf, type ExecutorContext as bg, type ExecutorResult as bh, type SupervisorOpts as bi, type TreeView as bj, type WidenGate as bk, gateOnDeliverable as bl, type DelegateFeedbackArgs as c, type DelegationFeedbackSnapshot as d, type ExecutorRegistry as e, type DeliverableSpec as f, DelegationTaskQueue as g, type CoderDelegate as h, type Scope as i, type ResultBlobStore as j, type AgentSpec as k, type SpawnJournal as l, type RootHandle as m, type SupervisedResult as n, type Settled as o, type Executor as p, type DelegationExecutor as q, runLocalHarness as r, type DelegateCodeResult as s, type DelegateFeedbackResult as t, type ResearchSource as u, type DelegateResearchArgs as v, type DelegateResearchResult as w, type DelegateUiAuditArgs as x, type DelegateUiAuditResult as y, type DelegationHistoryResult as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { AgentProfile, AgentEvalError, AnalystFinding, KnowledgeReadinessReport, RunRecord, ControlEvalResult, KnowledgeRequirement } from '@tangle-network/agent-eval';
|
|
2
2
|
export { AgentEvalError, AgentEvalErrorCode, ConfigError, ControlBudget, ControlDecision, ControlEvalResult, ControlRunResult, ControlStep, DataAcquisitionPlan, JudgeError, KnowledgeReadinessReport, KnowledgeRequirement, NotFoundError, RunRecord, ValidationError } from '@tangle-network/agent-eval';
|
|
3
|
-
import { f as AgentBackendInput, g as AgentExecutionBackend, O as OpenAIChatTool, h as OpenAIChatToolChoice, i as AgentBackendContext, R as RuntimeStreamEvent, K as KnowledgeReadinessDecision, j as RunAgentTaskOptions, k as AgentTaskRunResult, l as RunAgentTaskStreamOptions, m as AgentRuntimeEvent, n as AgentTaskStatus, o as RuntimeSessionStore, p as RuntimeSession, b as RuntimeHooks } from './types-
|
|
4
|
-
export { q as AgentAdapter, r as AgentKnowledgeProvider, s as AgentRuntimeEventSink, t as AgentTaskContext, u as AgentTaskSpec, B as BackendErrorDetail, v as RuntimeDecisionEvidenceRef, w as RuntimeDecisionKind, x as RuntimeDecisionPoint, y as RuntimeHookContext, z as RuntimeHookErrorContext, C as RuntimeHookEvent, D as RuntimeHookPhase,
|
|
3
|
+
import { f as AgentBackendInput, g as AgentExecutionBackend, O as OpenAIChatTool, h as OpenAIChatToolChoice, i as AgentBackendContext, R as RuntimeStreamEvent, K as KnowledgeReadinessDecision, j as RunAgentTaskOptions, k as AgentTaskRunResult, l as RunAgentTaskStreamOptions, m as AgentRuntimeEvent, n as AgentTaskStatus, o as RuntimeSessionStore, p as RuntimeSession, b as RuntimeHooks } from './types-CdnEAE3U.js';
|
|
4
|
+
export { q as AgentAdapter, r as AgentKnowledgeProvider, s as AgentRuntimeEventSink, t as AgentTaskContext, u as AgentTaskSpec, B as BackendErrorDetail, v as RuntimeDecisionEvidenceRef, w as RuntimeDecisionKind, x as RuntimeDecisionPoint, y as RuntimeHookContext, z as RuntimeHookErrorContext, C as RuntimeHookEvent, D as RuntimeHookPhase, F as RuntimeHookTarget, G as RuntimeRunHandle, H as RuntimeRunPersistenceAdapter, J as RuntimeRunRow, M as composeRuntimeHooks, N as defineRuntimeHooks, P as notifyRuntimeDecisionPoint, Q as notifyRuntimeHookEvent, T as startRuntimeRun } from './types-CdnEAE3U.js';
|
|
5
5
|
import { AgentProfile as AgentProfile$1 } from '@tangle-network/agent-interface';
|
|
6
6
|
import { Scenario, ProfileDispatchFn, LabeledScenarioStore, WorktreeAdapter, SurfaceProposer } from '@tangle-network/agent-eval/campaign';
|
|
7
|
-
import { L as LocalHarness, r as runLocalHarness } from './delegates-
|
|
8
|
-
export {
|
|
7
|
+
import { L as LocalHarness, r as runLocalHarness } from './delegates-CsXJPZDH.js';
|
|
8
|
+
export { a_ as EvalRunEvent, a$ as EvalRunGeneration, b0 as EvalRunsExportConfig, b1 as EvalRunsExportResult, b2 as INTELLIGENCE_WIRE_VERSION, b3 as LoopSpanNode, b4 as OtelAttribute, b5 as OtelExportConfig, b6 as OtelExporter, b7 as OtelSpan, b8 as buildLoopOtelSpans, b9 as buildLoopSpanNodes, ba as createOtelExporter, bb as exportEvalRuns, bc as loopEventToOtelSpan } from './delegates-CsXJPZDH.js';
|
|
9
9
|
import { Scenario as Scenario$1, SurfaceProposer as SurfaceProposer$1, JudgeConfig, MutableSurface, DispatchContext, SelfImproveBudget, SelfImproveLlm, SelfImproveResult } from '@tangle-network/agent-eval/contract';
|
|
10
10
|
import { S as SurfaceImprovementEdit } from './improvement-adapter-CioiEE2z.js';
|
|
11
11
|
import { I as ImprovementAdapter } from './types-BC3bZpH0.js';
|
|
12
|
-
export { C as CoderLoopRunnerOptions, D as DELEGATED_LOOP_MODES, a as DelegatedLoopMode, b as DelegatedLoopRegistry, c as DelegatedLoopResult, d as DelegatedLoopRunner, L as LoopRunnerCliArgs, e as LoopRunnerCliResult, R as ResearchLoopResult, f as ResearchLoopRunnerOptions, g as RunDelegatedLoopOptions, V as VetoedFact, W as WorktreeLoopRunnerOptions, h as auditLoopRunner, i as coderLoopRunner, j as isDelegatedLoopMode, p as parseLoopRunnerArgv, r as researchLoopRunner, k as runDelegatedLoop, l as runLoopRunnerCli, s as selfImproveLoopRunner, w as worktreeLoopRunner } from './loop-runner-bin-
|
|
13
|
-
export { m as mcpToolsForRuntimeMcp, a as mcpToolsForRuntimeMcpSubset } from './openai-tools-
|
|
12
|
+
export { C as CoderLoopRunnerOptions, D as DELEGATED_LOOP_MODES, a as DelegatedLoopMode, b as DelegatedLoopRegistry, c as DelegatedLoopResult, d as DelegatedLoopRunner, L as LoopRunnerCliArgs, e as LoopRunnerCliResult, R as ResearchLoopResult, f as ResearchLoopRunnerOptions, g as RunDelegatedLoopOptions, V as VetoedFact, W as WorktreeLoopRunnerOptions, h as auditLoopRunner, i as coderLoopRunner, j as isDelegatedLoopMode, p as parseLoopRunnerArgv, r as researchLoopRunner, k as runDelegatedLoop, l as runLoopRunnerCli, s as selfImproveLoopRunner, w as worktreeLoopRunner } from './loop-runner-bin-DLM_bVQO.js';
|
|
13
|
+
export { m as mcpToolsForRuntimeMcp, a as mcpToolsForRuntimeMcpSubset } from './openai-tools-kdCS-T12.js';
|
|
14
14
|
import '@tangle-network/sandbox';
|
|
15
15
|
import 'node:child_process';
|
|
16
16
|
import './substrate-BoRXgvka.js';
|
|
17
17
|
import './kb-gate-CuzMYGYM.js';
|
|
18
|
-
import './worktree-fanout-
|
|
18
|
+
import './worktree-fanout-CK2ypmEm.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @stable
|
package/dist/index.js
CHANGED
|
@@ -17,14 +17,14 @@ import {
|
|
|
17
17
|
runLoopRunnerCli,
|
|
18
18
|
selfImproveLoopRunner,
|
|
19
19
|
worktreeLoopRunner
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-K3RM4MPM.js";
|
|
21
21
|
import "./chunk-P5OKDSLB.js";
|
|
22
22
|
import {
|
|
23
23
|
mcpToolsForRuntimeMcp,
|
|
24
24
|
mcpToolsForRuntimeMcpSubset
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-4KGQHS7U.js";
|
|
26
26
|
import "./chunk-FNMGYYSS.js";
|
|
27
|
-
import "./chunk-
|
|
27
|
+
import "./chunk-INXDNX2W.js";
|
|
28
28
|
import {
|
|
29
29
|
assertModelAllowed,
|
|
30
30
|
composeRuntimeHooks,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
notifyRuntimeDecisionPoint,
|
|
33
33
|
notifyRuntimeHookEvent,
|
|
34
34
|
runLocalHarness
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-5ISW5JUF.js";
|
|
36
36
|
import {
|
|
37
37
|
INTELLIGENCE_WIRE_VERSION,
|
|
38
38
|
buildLoopOtelSpans,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
createOtelExporter,
|
|
41
41
|
exportEvalRuns,
|
|
42
42
|
loopEventToOtelSpan
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-VMNEQHJR.js";
|
|
44
44
|
import {
|
|
45
45
|
AgentEvalError,
|
|
46
46
|
BackendTransportError,
|
package/dist/intelligence.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LoopTraceEvent } from './types-
|
|
1
|
+
import { L as LoopTraceEvent } from './types-CdnEAE3U.js';
|
|
2
2
|
import { AgentProfileMcpServer } from '@tangle-network/agent-interface';
|
|
3
3
|
import { T as ToolSpec } from './router-client-C7kp_ECN.js';
|
|
4
4
|
import '@tangle-network/agent-eval';
|