@tangle-network/agent-runtime 0.88.0 → 0.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -18
- package/dist/agent.d.ts +53 -2
- package/dist/agent.js +166 -4
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/{chunk-22HPUH77.js → chunk-4IBAMGBE.js} +170 -269
- package/dist/chunk-4IBAMGBE.js.map +1 -0
- package/dist/chunk-5QOB7H74.js +387 -0
- package/dist/chunk-5QOB7H74.js.map +1 -0
- package/dist/chunk-74SBMDTO.js +214 -0
- package/dist/chunk-74SBMDTO.js.map +1 -0
- package/dist/{chunk-HBE77SWV.js → chunk-MHK62APK.js} +5 -5
- package/dist/{chunk-LRNRPJAV.js → chunk-QSNSMJSZ.js} +2622 -2842
- package/dist/chunk-QSNSMJSZ.js.map +1 -0
- package/dist/{chunk-VNOOH22O.js → chunk-XMOU4WEY.js} +74 -3
- package/dist/chunk-XMOU4WEY.js.map +1 -0
- package/dist/{chunk-JHULWWQD.js → chunk-XQEISTK2.js} +2 -2
- package/dist/{worktree-harness-CX_McRLp.d.ts → completion-gate-BDaBP8dd.d.ts} +44 -44
- package/dist/{coordination-CuDLO8wj.d.ts → coordination-DxHduZg7.d.ts} +414 -226
- package/dist/environment-provider.d.ts +3 -3
- package/dist/index.d.ts +156 -13
- package/dist/index.js +316 -70
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +2 -2
- package/dist/knowledge.d.ts +120 -0
- package/dist/knowledge.js +28 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/lifecycle.js +1 -1
- package/dist/{loop-runner-bin-hQDUL8Ld.d.ts → loop-runner-bin-D3GmB2Ru.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +5 -5
- package/dist/loop-runner-bin.js +5 -5
- package/dist/loops.d.ts +46 -324
- package/dist/loops.js +3 -15
- package/dist/mcp/bin.js +2 -2
- package/dist/mcp/index.d.ts +8 -9
- package/dist/mcp/index.js +7 -7
- package/dist/{openai-tools-BnrOmGjN.d.ts → openai-tools-D0xmzo0y.d.ts} +1 -1
- package/dist/profiles.d.ts +196 -5
- package/dist/profiles.js +8 -0
- package/dist/profiles.js.map +1 -1
- package/dist/{router-client-r8y_VFVM.d.ts → router-client-DJImUDlm.d.ts} +1 -1
- package/dist/supervise-BpCdssu0.d.ts +131 -0
- package/dist/{types-Driepl87.d.ts → types-DAJQRIUD.d.ts} +2 -2
- package/dist/{types-ESeMOj94.d.ts → types-Dnk189QA.d.ts} +1 -1
- package/dist/{worktree-fanout-D6xR2CIA.d.ts → worktree-fanout-CfRXYmgV.d.ts} +3 -3
- package/package.json +12 -4
- package/skills/agent-runtime-adoption/SKILL.md +74 -24
- package/skills/build-with-agent-runtime/SKILL.md +3 -9
- package/skills/loop-writer/SKILL.md +6 -78
- package/skills/supervise/SKILL.md +2 -2
- package/dist/chunk-22HPUH77.js.map +0 -1
- package/dist/chunk-LRNRPJAV.js.map +0 -1
- package/dist/chunk-VNOOH22O.js.map +0 -1
- package/dist/otel-export-BKmNwiCb.d.ts +0 -180
- /package/dist/{chunk-HBE77SWV.js.map → chunk-MHK62APK.js.map} +0 -0
- /package/dist/{chunk-JHULWWQD.js.map → chunk-XQEISTK2.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/improvement/agentic-generator.ts","../src/improvement/build-prompts.ts","../src/improvement/mcp-serve-verifier.ts"],"sourcesContent":["/**\n *\n * `agenticGenerator` — the full-agentic `CandidateGenerator`: the\n * `shots=N, sandbox=on` setting of the one `improvementDriver`. It runs a real\n * coding harness (claude / codex / opencode) inside the candidate worktree the\n * driver already created, letting the agent read the codebase + the research\n * report and make the change in place. The driver then commits the worktree\n * into a `CodeSurface`.\n *\n * Mechanism: identical to the proven Phase-2.8 in-process executor — spawn the\n * harness as a subprocess with `cwd` = the worktree, on the same filesystem,\n * so edits land in place (no sandbox-mount round-trip). `runLocalHarness` is\n * the verified primitive. The OUTER sandbox is the improvement loop's own\n * execution context; the generator does not nest a second sandbox per\n * candidate (which would reintroduce a host↔sandbox worktree-transport\n * problem that does not need solving here).\n *\n * `maxShots` is the DEPTH dial — a multi-shot verify-in-session loop, NOT the\n * kernel `runLoop`. Each shot runs one full harness session in the (persistent)\n * worktree; between shots the loop refines based on what the last shot produced:\n * - empty tree → \"you changed nothing, make the edits\" → retry\n * - dirty + `verify` fails → feed the verifier's failure into the next shot\n * (the worktree persists, so the harness RESUMES atop its own failing\n * edits with the error in hand — no `--resume` session plumbing needed,\n * and harness-agnostic across claude/codex/opencode)\n * - dirty + `verify` ok (or no verifier configured) → return the candidate\n * A candidate that never verifies within `maxShots` is discarded (`applied:\n * false`), never shipped — if you configured a verifier, a non-passing tree is\n * not a candidate. With no verifier the legacy behavior holds: first dirty shot\n * is the candidate.\n *\n * @experimental\n */\n\nimport { spawnSync } from 'node:child_process'\nimport type { AnalystFinding } from '@tangle-network/agent-eval'\nimport { type LocalHarness, runLocalHarness } from '../mcp/local-harness'\nimport type { CandidateGenerator } from './improvement-driver'\n\n/** Outcome of verifying a candidate worktree. `feedback` (compiler errors,\n * failing test output) is fed into the next shot when `ok` is false. */\nexport interface VerifyResult {\n ok: boolean\n feedback?: string\n}\n\n/** Verifies the edited worktree. Sync or async; throws only on a setup fault\n * (a candidate that fails verification returns `{ok:false}`, it does not\n * throw). */\nexport type Verifier = (worktreePath: string) => Promise<VerifyResult> | VerifyResult\n\nexport interface AgenticGeneratorOptions {\n /** Local coding harness to run in the worktree. Default `claude`. */\n harness?: LocalHarness\n /** Per-shot wall-clock timeout (ms). Default = `runLocalHarness` default (5m). */\n timeoutMs?: number\n /** Build the harness task prompt from the report + findings. Override for\n * domain phrasing; the default turns findings into a concrete coder task. */\n buildPrompt?: (args: { report: unknown; findings: AnalystFinding[] }) => string\n /** Verify the worktree after each dirtying shot. When set, a candidate that\n * fails verification is NOT returned — the failure feeds the next shot\n * (verify-in-session), up to `maxShots`; a candidate that never verifies is\n * discarded (`applied:false`), never shipped. Omitted ⇒ legacy behavior:\n * the first dirty shot is the candidate. See `commandVerifier`. */\n verify?: Verifier\n /** Test seam — inject the harness runner (defaults to `runLocalHarness`). */\n runHarness?: typeof runLocalHarness\n /** Test seam — inject the worktree-dirty check (defaults to `git status`). */\n isDirty?: (worktreePath: string) => boolean\n}\n\n/** Full-agentic `CandidateGenerator` (the `shots=N, sandbox=on` setting): run a real coding harness inside the candidate worktree so the agent makes the change in place. */\nexport function agenticGenerator(opts: AgenticGeneratorOptions = {}): CandidateGenerator {\n const harness = opts.harness ?? 'claude'\n const buildPrompt = opts.buildPrompt ?? defaultBuildPrompt\n const run = opts.runHarness ?? runLocalHarness\n const dirty = opts.isDirty ?? worktreeDirty\n const verify = opts.verify\n\n return {\n kind: `agentic:${harness}`,\n async generate({ worktreePath, report, findings, maxShots, signal }) {\n const basePrompt = buildPrompt({ report, findings })\n const shots = Math.max(1, maxShots)\n // Feedback appended to the base prompt for the NEXT shot — empty on shot 0.\n let attemptNote = ''\n\n for (let shot = 0; shot < shots; shot++) {\n if (signal.aborted) break\n await run({\n harness,\n cwd: worktreePath,\n taskPrompt: attemptNote ? `${basePrompt}\\n\\n${attemptNote}` : basePrompt,\n timeoutMs: opts.timeoutMs,\n signal,\n })\n\n // The worktree IS the signal: no edits ⇒ tell the next shot to act.\n if (!dirty(worktreePath)) {\n attemptNote = EMPTY_TREE_NOTE\n continue\n }\n\n // Dirty: with no verifier the diff IS the candidate (we trust the diff,\n // not the harness's stdout). With a verifier the candidate must pass it.\n if (!verify) {\n return { applied: true, summary: summarize(findings) }\n }\n const result = await verify(worktreePath)\n if (result.ok) {\n return { applied: true, summary: summarize(findings) }\n }\n // Dirty but failing — resume next shot atop these edits with the error.\n attemptNote = failureNote(result.feedback)\n }\n\n // Shots exhausted: no verified candidate (or, sans verifier, no edits).\n return { applied: false, summary: '' }\n },\n }\n}\n\n/** Turn the analyst's findings (+ optional report) into a concrete coder task. */\nfunction defaultBuildPrompt(args: { report: unknown; findings: AnalystFinding[] }): string {\n const lines: string[] = [\n 'You are improving this codebase based on an evaluation analysis.',\n 'Make the smallest set of edits that addresses the findings below, then stop.',\n 'Do not change unrelated code. Do not commit — leave changes in the working tree.',\n '',\n 'Findings:',\n ]\n for (const f of args.findings) {\n const where = f.subject ? ` [${f.subject}]` : ''\n lines.push(`- (${f.severity})${where} ${f.claim}`)\n if (f.recommended_action) lines.push(` → ${f.recommended_action}`)\n }\n return lines.join('\\n')\n}\n\nconst EMPTY_TREE_NOTE =\n 'NOTE: your previous attempt left the working tree unchanged. Make the concrete file edits now.'\n\n/** Next-shot feedback when the worktree is dirty but failed verification. The\n * edits persist on disk, so the harness resumes atop them — tell it to fix in\n * place, not start over. Verifier detail is truncated to keep the prompt bounded. */\nfunction failureNote(feedback?: string): string {\n const detail = feedback?.trim()\n return [\n 'NOTE: your edits are in the working tree but verification FAILED.',\n 'Fix the problem in place — build on your existing edits, do not revert them.',\n detail ? `Verifier output:\\n${truncate(detail, 4000)}` : 'No verifier detail was captured.',\n ].join('\\n')\n}\n\n/** A `Verifier` that runs a command in the worktree: exit 0 ⇒ ok, any other\n * exit ⇒ failed with stdout+stderr as feedback. The common case — verify by\n * `tsc --noEmit`, `pnpm build`, or a test command. A timeout is treated as a\n * FAILED candidate (a change that hangs the build is a bad change); a missing\n * binary or spawn fault throws (a setup bug, not a failed candidate — no\n * silent fallback). */\nexport function commandVerifier(\n command: string,\n args: string[] = [],\n timeoutMs = 300_000,\n): Verifier {\n return (worktreePath: string): VerifyResult => {\n const result = spawnSync(command, args, {\n cwd: worktreePath,\n encoding: 'utf-8',\n timeout: timeoutMs,\n })\n if (result.signal) {\n return {\n ok: false,\n feedback: `verifier '${command}' killed by ${result.signal} (likely timeout after ${timeoutMs}ms)`,\n }\n }\n if (result.error) {\n const code = (result.error as NodeJS.ErrnoException).code\n if (code === 'ENOENT') {\n throw new Error(\n `commandVerifier: '${command}' not found in PATH (setup bug, not a failed candidate)`,\n )\n }\n throw new Error(`commandVerifier: '${command}' failed to spawn: ${result.error.message}`)\n }\n if (result.status === 0) return { ok: true }\n const out = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim()\n return { ok: false, feedback: out.length > 0 ? out : `exit ${result.status}` }\n }\n}\n\n/** A one-line summary for the commit message, derived from the findings. */\nfunction summarize(findings: AnalystFinding[]): string {\n if (findings.length === 0) return 'agentic improvement'\n if (findings.length === 1) return `agentic: ${truncate(findings[0]!.claim, 64)}`\n return `agentic: ${findings.length} findings addressed`\n}\n\nfunction truncate(s: string, n: number): string {\n return s.length <= n ? s : `${s.slice(0, n - 1)}…`\n}\n\n/** Non-empty `git status --porcelain` ⇒ the harness changed the worktree.\n * Fails loud: the worktree is a fresh checkout, so a git error here means\n * something is genuinely broken (git missing, corrupt index, killed mid-run).\n * Folding that into `false` would silently discard a candidate and mask the\n * real failure — forbidden by the no-silent-fallbacks doctrine. */\nfunction worktreeDirty(worktreePath: string): boolean {\n const result = spawnSync('git', ['status', '--porcelain'], {\n cwd: worktreePath,\n encoding: 'utf-8',\n })\n if (result.error) {\n throw new Error(\n `agenticGenerator: git status failed to spawn in ${worktreePath}: ${result.error.message}`,\n )\n }\n if (result.status !== 0) {\n throw new Error(\n `agenticGenerator: git status exited ${result.status} in ${worktreePath}: ${result.stderr.trim()}`,\n )\n }\n return result.stdout.trim().length > 0\n}\n","/**\n * Build-prompt starting points for the two buildable artifact types. There is\n * NO `toolGenerator`/`mcpGenerator` wrapper — the factory is `agenticGenerator`\n * + a verifier (docs/artifact-lifecycle-frontier.md), so a tool or an MCP\n * server is built by composing the pieces directly:\n *\n * // a tool:\n * agenticGenerator({ buildPrompt: toolBuildPrompt, verify: commandVerifier('pnpm', ['test']) })\n * // an MCP server:\n * agenticGenerator({ buildPrompt: mcpBuildPrompt, verify: mcpServeVerifier({ command: 'node', args: ['server.mjs'] }) })\n *\n * These are the only type-specific bit (the phrasing that points the agent at a\n * tool vs. an MCP); the worktree, resume-on-failure loop, and improvement-loop\n * wrapper are shared. MCP is the load-bearing target — it is how a harness\n * acquires tools; raw tools matter where we control the loader.\n */\n\nimport type { AnalystFinding } from '@tangle-network/agent-eval'\n\ntype FindingsArg = { report: unknown; findings: AnalystFinding[] }\n\nfunction findingLines(findings: AnalystFinding[]): string[] {\n return findings.map((f) => {\n const where = f.subject ? ` [${f.subject}]` : ''\n const action = f.recommended_action ? ` → ${f.recommended_action}` : ''\n return `- (${f.severity})${where} ${f.claim}${action}`\n })\n}\n\n/** Build the starting instruction for a coder agent tasked with implementing a new tool. */\nexport function toolBuildPrompt(args: FindingsArg): string {\n return [\n 'You are building a new TOOL for this codebase to address the gaps below.',\n 'Write the tool as a small, self-contained module PLUS tests that exercise it.',\n 'The tool must compile and its tests must pass — they will be run automatically;',\n 'if verification fails you will get the error and another attempt. Do not commit;',\n 'leave the changes in the working tree.',\n '',\n 'Gaps the tool should close:',\n ...findingLines(args.findings),\n ].join('\\n')\n}\n\n/** Build the starting instruction for a coder agent tasked with implementing a new MCP server. */\nexport function mcpBuildPrompt(args: FindingsArg): string {\n return [\n 'You are building a new MCP SERVER (Model Context Protocol) that exposes',\n 'tool(s) addressing the gaps below, so any harness can mount it.',\n 'Requirements that WILL be checked by booting the server:',\n '- it starts over stdio and answers the MCP `initialize` handshake,',\n '- `tools/list` returns at least one tool with a valid input schema.',\n 'Newline-delimited JSON-RPC 2.0, protocol version 2024-11-05. Include a start',\n 'command (e.g. a package.json `start` script or a clear entrypoint). If the',\n 'boot-and-probe fails you will get the error and another attempt. Do not',\n 'commit; leave the changes in the working tree.',\n '',\n 'Capabilities the server should provide:',\n ...findingLines(args.findings),\n ].join('\\n')\n}\n","/**\n * `mcpServeVerifier` — the intrinsic verifier for a built MCP server: the\n * boot-and-probe checker named in docs/artifact-lifecycle-frontier.md. A\n * generated MCP server is only a candidate if it actually *serves* — so this\n * boots it over stdio (the default local MCP transport) and runs the real\n * handshake: `initialize` → `notifications/initialized` → `tools/list`, and\n * asserts the server answers with at least `minTools` tools.\n *\n * Outcomes follow the `Verifier` contract: a server that fails to start, exits\n * early, errors the handshake, times out, or exposes no tools is a FAILED\n * candidate (`{ok:false}`, fed back into the next generation shot); a missing\n * start binary or spawn fault THROWS (a setup bug, never a silent fallback).\n *\n * Protocol matches the runtime's own stdio MCP server (src/mcp/server.ts):\n * newline-delimited JSON-RPC 2.0, protocol version 2024-11-05.\n */\n\nimport { spawn } from 'node:child_process'\nimport { createInterface } from 'node:readline'\nimport type { Verifier, VerifyResult } from './agentic-generator'\n\nconst PROTOCOL_VERSION = '2024-11-05'\n\nexport interface McpServeSpec {\n /** Command that starts the built MCP server in the worktree (stdio transport). */\n command: string\n args?: string[]\n /** Extra env for the server process (merged over `process.env`). */\n env?: Record<string, string>\n /** Handshake timeout (ms). Default 30s. */\n timeoutMs?: number\n /** Minimum tools the server must expose to pass. Default 1. */\n minTools?: number\n}\n\ninterface JsonRpcResponse {\n jsonrpc?: string\n id?: number | string | null\n result?: unknown\n error?: { code: number; message: string }\n}\n\n/** Build a `Verifier` that boots a generated MCP server over stdio and checks it exposes tools. */\nexport function mcpServeVerifier(spec: McpServeSpec): Verifier {\n const timeoutMs = spec.timeoutMs ?? 30_000\n const minTools = spec.minTools ?? 1\n\n return (worktreePath: string): Promise<VerifyResult> =>\n new Promise<VerifyResult>((resolve, reject) => {\n const child = spawn(spec.command, spec.args ?? [], {\n cwd: worktreePath,\n stdio: ['pipe', 'pipe', 'pipe'],\n env: { ...process.env, ...spec.env },\n })\n\n const stderr: string[] = []\n let settled = false\n let nextId = 1\n const initId = nextId++\n let listId = -1\n\n const settle = (fn: () => void) => {\n if (settled) return\n settled = true\n clearTimeout(timer)\n rl.close()\n child.kill('SIGKILL')\n fn()\n }\n const withStderr = (msg: string) =>\n stderr.length > 0 ? `${msg}\\nstderr:\\n${stderr.join('').slice(-2000)}` : msg\n const pass = () => settle(() => resolve({ ok: true }))\n const failCandidate = (msg: string) =>\n settle(() => resolve({ ok: false, feedback: withStderr(msg) }))\n const setupFault = (err: Error) => settle(() => reject(err))\n\n const send = (msg: Record<string, unknown>): boolean => {\n try {\n child.stdin.write(`${JSON.stringify(msg)}\\n`)\n return true\n } catch (err) {\n // EPIPE: the server died mid-handshake — a failed candidate, not a fault.\n failCandidate(`writing to MCP server stdin failed: ${(err as Error).message}`)\n return false\n }\n }\n\n child.on('error', (err) => {\n const code = (err as NodeJS.ErrnoException).code\n setupFault(\n code === 'ENOENT'\n ? new Error(\n `mcpServeVerifier: '${spec.command}' not found in PATH (setup bug, not a failed candidate)`,\n )\n : new Error(`mcpServeVerifier: '${spec.command}' failed to spawn: ${err.message}`),\n )\n })\n child.on('exit', (code, signal) => {\n // An exit before the handshake completes is a failed candidate (the\n // server crashed on boot); after we settle, our own SIGKILL fires here.\n failCandidate(`MCP server exited (code ${code}, signal ${signal}) before serving`)\n })\n child.stderr.on('data', (d) => stderr.push(String(d)))\n\n const rl = createInterface({ input: child.stdout })\n rl.on('line', (line) => {\n let msg: JsonRpcResponse | undefined\n try {\n msg = JSON.parse(line) as JsonRpcResponse\n } catch {\n return // servers log to stdout too; skip non-JSON lines\n }\n if (!msg || typeof msg !== 'object') return\n\n if (msg.id === initId) {\n if (msg.error) return failCandidate(`initialize errored: ${JSON.stringify(msg.error)}`)\n if (!send({ jsonrpc: '2.0', method: 'notifications/initialized' })) return\n listId = nextId++\n send({ jsonrpc: '2.0', id: listId, method: 'tools/list' })\n return\n }\n if (msg.id === listId) {\n if (msg.error) return failCandidate(`tools/list errored: ${JSON.stringify(msg.error)}`)\n const tools = (msg.result as { tools?: unknown[] } | undefined)?.tools\n if (!Array.isArray(tools)) return failCandidate('tools/list result has no tools array')\n if (tools.length < minTools) {\n return failCandidate(`tools/list returned ${tools.length} tool(s), need >= ${minTools}`)\n }\n return pass()\n }\n })\n\n const timer = setTimeout(\n () => failCandidate(`MCP server did not complete the handshake within ${timeoutMs}ms`),\n timeoutMs,\n )\n\n send({\n jsonrpc: '2.0',\n id: initId,\n method: 'initialize',\n params: {\n protocolVersion: PROTOCOL_VERSION,\n capabilities: {},\n clientInfo: { name: 'agent-runtime-mcp-verify', version: '0' },\n },\n })\n })\n}\n"],"mappings":";;;;;AAkCA,SAAS,iBAAiB;AAsCnB,SAAS,iBAAiB,OAAgC,CAAC,GAAuB;AACvF,QAAM,UAAU,KAAK,WAAW;AAChC,QAAM,cAAc,KAAK,eAAe;AACxC,QAAM,MAAM,KAAK,cAAc;AAC/B,QAAM,QAAQ,KAAK,WAAW;AAC9B,QAAM,SAAS,KAAK;AAEpB,SAAO;AAAA,IACL,MAAM,WAAW,OAAO;AAAA,IACxB,MAAM,SAAS,EAAE,cAAc,QAAQ,UAAU,UAAU,OAAO,GAAG;AACnE,YAAM,aAAa,YAAY,EAAE,QAAQ,SAAS,CAAC;AACnD,YAAM,QAAQ,KAAK,IAAI,GAAG,QAAQ;AAElC,UAAI,cAAc;AAElB,eAAS,OAAO,GAAG,OAAO,OAAO,QAAQ;AACvC,YAAI,OAAO,QAAS;AACpB,cAAM,IAAI;AAAA,UACR;AAAA,UACA,KAAK;AAAA,UACL,YAAY,cAAc,GAAG,UAAU;AAAA;AAAA,EAAO,WAAW,KAAK;AAAA,UAC9D,WAAW,KAAK;AAAA,UAChB;AAAA,QACF,CAAC;AAGD,YAAI,CAAC,MAAM,YAAY,GAAG;AACxB,wBAAc;AACd;AAAA,QACF;AAIA,YAAI,CAAC,QAAQ;AACX,iBAAO,EAAE,SAAS,MAAM,SAAS,UAAU,QAAQ,EAAE;AAAA,QACvD;AACA,cAAM,SAAS,MAAM,OAAO,YAAY;AACxC,YAAI,OAAO,IAAI;AACb,iBAAO,EAAE,SAAS,MAAM,SAAS,UAAU,QAAQ,EAAE;AAAA,QACvD;AAEA,sBAAc,YAAY,OAAO,QAAQ;AAAA,MAC3C;AAGA,aAAO,EAAE,SAAS,OAAO,SAAS,GAAG;AAAA,IACvC;AAAA,EACF;AACF;AAGA,SAAS,mBAAmB,MAA+D;AACzF,QA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AA,MACF;AACA,UAAI,IAAI,OAAO,QAAQ;AACrB,YAAI,IAAI,MAAO,QAAO,cAAc,uBAAuB,KAAK,UAAU,IAAI,KAAK,CAAC,EAAE;AACtF,cAAM,QAAS,IAAI,QAA8C;AACjE,YAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,cAAc,sCAAsC;AACtF,YAAI,MAAM,SAAS,UAAU;AAC3B,iBAAO,cAAc,uBAAuB,MAAM,MAAM,qBAAqB,QAAQ,EAAE;AAAA,QACzF;AACA,eAAO,KAAK;AAAA,MACd;AAAA,IACF,CAAC;AAED,UAAM,QAAQ;AAAA,MACZ,MAAM,cAAc,oDAAoD,SAAS,IAAI;AAAA,MACrF;AAAA,IACF;AAEA,SAAK;AAAA,MACH,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,QAAQ;AAAA,QACN,iBAAiB;AAAA,QACjB,cAAc,CAAC;AAAA,QACf,YAAY,EAAE,MAAM,4BAA4B,SAAS,IAAI;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACL;","names":[]}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OTEL span exporter — streams LoopTraceEvents to an OTLP/HTTP collector.
|
|
3
|
-
*
|
|
4
|
-
* Reads OTEL_EXPORTER_OTLP_ENDPOINT + OTEL_EXPORTER_OTLP_HEADERS from env
|
|
5
|
-
* when no explicit config is given. Keeps the runtime dep-free from
|
|
6
|
-
* @opentelemetry/sdk-trace-base — minimal OTLP/JSON serializer.
|
|
7
|
-
*
|
|
8
|
-
* The exporter accepts both raw OtelSpan objects and LoopTraceEvents
|
|
9
|
-
* (which get converted to OTLP spans automatically).
|
|
10
|
-
*/
|
|
11
|
-
interface OtelExportConfig {
|
|
12
|
-
/** OTLP endpoint. Reads OTEL_EXPORTER_OTLP_ENDPOINT env by default. */
|
|
13
|
-
endpoint?: string;
|
|
14
|
-
/** OTLP headers. Reads OTEL_EXPORTER_OTLP_HEADERS env by default. */
|
|
15
|
-
headers?: Record<string, string>;
|
|
16
|
-
/** Batch size before flush. Default 64. */
|
|
17
|
-
batchSize?: number;
|
|
18
|
-
/** Flush interval ms. Default 5000. */
|
|
19
|
-
flushIntervalMs?: number;
|
|
20
|
-
/** Resource attributes stamped on every export. */
|
|
21
|
-
resourceAttributes?: Record<string, string | number | boolean>;
|
|
22
|
-
/** Service name. Default 'agent-runtime'. */
|
|
23
|
-
serviceName?: string;
|
|
24
|
-
}
|
|
25
|
-
interface OtelExporter {
|
|
26
|
-
/** Export a span. */
|
|
27
|
-
exportSpan(span: OtelSpan): void;
|
|
28
|
-
/** Force flush pending spans. */
|
|
29
|
-
flush(): Promise<void>;
|
|
30
|
-
/** Shutdown cleanly. */
|
|
31
|
-
shutdown(): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
interface OtelSpan {
|
|
34
|
-
traceId: string;
|
|
35
|
-
spanId: string;
|
|
36
|
-
parentSpanId?: string;
|
|
37
|
-
name: string;
|
|
38
|
-
kind?: number;
|
|
39
|
-
startTimeUnixNano: string;
|
|
40
|
-
endTimeUnixNano: string;
|
|
41
|
-
attributes?: OtelAttribute[];
|
|
42
|
-
status?: {
|
|
43
|
-
code: number;
|
|
44
|
-
message?: string;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
interface OtelAttribute {
|
|
48
|
-
key: string;
|
|
49
|
-
value: {
|
|
50
|
-
stringValue?: string;
|
|
51
|
-
intValue?: string;
|
|
52
|
-
doubleValue?: number;
|
|
53
|
-
boolValue?: boolean;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Create an OTEL exporter. Returns undefined when no endpoint is configured.
|
|
58
|
-
*/
|
|
59
|
-
declare function createOtelExporter(config?: OtelExportConfig): OtelExporter | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* Convert a LoopTraceEvent into an OtelSpan for export.
|
|
62
|
-
*/
|
|
63
|
-
declare function loopEventToOtelSpan(event: {
|
|
64
|
-
kind: string;
|
|
65
|
-
runId: string;
|
|
66
|
-
timestamp: number;
|
|
67
|
-
payload: object;
|
|
68
|
-
}, traceId: string, parentSpanId?: string): OtelSpan;
|
|
69
|
-
/**
|
|
70
|
-
* Sink-neutral node in a reconstructed loop span tree. The root node's
|
|
71
|
-
* `parentSpanId` is `undefined` — sinks decide how to parent it (the OTEL
|
|
72
|
-
* mapper attaches the inherited delegation span; the delegation journal
|
|
73
|
-
* leaves it as the tree root).
|
|
74
|
-
*/
|
|
75
|
-
interface LoopSpanNode {
|
|
76
|
-
spanId: string;
|
|
77
|
-
parentSpanId?: string;
|
|
78
|
-
/** `'loop'` | `'loop.round'` | `'loop.iteration'`. */
|
|
79
|
-
name: string;
|
|
80
|
-
/** Topology level: loop root, plan round, or iteration branch. */
|
|
81
|
-
kind: 'loop' | 'round' | 'branch';
|
|
82
|
-
startMs: number;
|
|
83
|
-
endMs: number;
|
|
84
|
-
attrs: Record<string, string | number | boolean>;
|
|
85
|
-
/** True when the iteration carried an error — maps to OTEL status code 2. */
|
|
86
|
-
error: boolean;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Build a nested, real-duration OTLP span tree for ONE loop run from its full
|
|
90
|
-
* ordered `LoopTraceEvent` stream. Unlike `loopEventToOtelSpan` (one flat,
|
|
91
|
-
* zero-duration span per event), this reconstructs the topology hierarchy a
|
|
92
|
-
* GenAI trace viewer renders natively:
|
|
93
|
-
*
|
|
94
|
-
* loop (invoke_workflow)
|
|
95
|
-
* └─ loop.round[k] (invoke_workflow) ← tangle.loop.move.{kind,width,rationale}
|
|
96
|
-
* ├─ loop.iteration[i] (invoke_agent) ← gen_ai.agent.name + usage + verdict + placement
|
|
97
|
-
* └─ …
|
|
98
|
-
*
|
|
99
|
-
* Attributes follow the current GenAI semconv (`gen_ai.*`) where they apply and
|
|
100
|
-
* a namespaced `tangle.loop.*` / `tangle.cost.usd` extension for topology /
|
|
101
|
-
* verdict / placement / cost (not yet standardized). Pure: feed it a buffered
|
|
102
|
-
* per-runId event array (e.g. flushed on `loop.ended`) and export the result.
|
|
103
|
-
*/
|
|
104
|
-
declare function buildLoopOtelSpans(events: ReadonlyArray<{
|
|
105
|
-
kind: string;
|
|
106
|
-
runId: string;
|
|
107
|
-
timestamp: number;
|
|
108
|
-
payload: object;
|
|
109
|
-
}>, traceId: string, rootParentSpanId?: string): OtelSpan[];
|
|
110
|
-
/**
|
|
111
|
-
* Sink-neutral core behind {@link buildLoopOtelSpans}: reconstruct the
|
|
112
|
-
* loop → round → branch span tree from one run's ordered `LoopTraceEvent`
|
|
113
|
-
* stream. Consumed by the OTEL mapper above and by the MCP delegation
|
|
114
|
-
* journal's compact trace tee — one topology reconstruction, two sinks.
|
|
115
|
-
* Tolerates partial streams (a run that never reached `loop.ended` closes
|
|
116
|
-
* at the last observed event's timestamp).
|
|
117
|
-
*/
|
|
118
|
-
declare function buildLoopSpanNodes(events: ReadonlyArray<{
|
|
119
|
-
kind: string;
|
|
120
|
-
runId: string;
|
|
121
|
-
timestamp: number;
|
|
122
|
-
payload: object;
|
|
123
|
-
}>): LoopSpanNode[];
|
|
124
|
-
/** Wire version the eval-runs ingest enforces (X-Tangle-Wire-Version + body). */
|
|
125
|
-
declare const INTELLIGENCE_WIRE_VERSION = "2026-05-26.v1";
|
|
126
|
-
interface EvalRunGeneration {
|
|
127
|
-
/** 0-based ordinal of this generation within the run (required by ingest). */
|
|
128
|
-
index: number;
|
|
129
|
-
/** Identity of the proposed surface change (content-addressed hash). */
|
|
130
|
-
surfaceHash: string;
|
|
131
|
-
/** Arbitrary provenance for this generation (rationale, evidence, source). */
|
|
132
|
-
surface?: unknown;
|
|
133
|
-
/** Per-scenario results; empty until the generation is measured. */
|
|
134
|
-
cells?: unknown[];
|
|
135
|
-
/** Mean composite score (0 when unmeasured — pair with labels.measured). */
|
|
136
|
-
compositeMean: number;
|
|
137
|
-
costUsd: number;
|
|
138
|
-
durationMs: number;
|
|
139
|
-
}
|
|
140
|
-
interface EvalRunEvent {
|
|
141
|
-
runId: string;
|
|
142
|
-
runDir: string;
|
|
143
|
-
/** ISO timestamp. */
|
|
144
|
-
timestamp: string;
|
|
145
|
-
status: 'started' | 'baseline-complete' | 'generation-complete' | 'gate-decided' | 'finished' | 'errored';
|
|
146
|
-
labels?: Record<string, string>;
|
|
147
|
-
baseline?: EvalRunGeneration;
|
|
148
|
-
generations?: EvalRunGeneration[];
|
|
149
|
-
gateDecision?: 'ship' | 'hold' | 'need_more_work' | 'model_ceiling' | 'arch_ceiling';
|
|
150
|
-
holdoutLift?: number;
|
|
151
|
-
totalCostUsd: number;
|
|
152
|
-
totalDurationMs: number;
|
|
153
|
-
errorMessage?: string;
|
|
154
|
-
}
|
|
155
|
-
interface EvalRunsExportConfig {
|
|
156
|
-
/** Bearer key — tenant is resolved server-side from it. Reads TANGLE_API_KEY. */
|
|
157
|
-
apiKey?: string;
|
|
158
|
-
/** Intelligence base. Reads INTELLIGENCE_BASE env, else prod. */
|
|
159
|
-
base?: string;
|
|
160
|
-
/** Idempotency-Key header (e.g. the runId) — safe retries + upsert. */
|
|
161
|
-
idempotencyKey?: string;
|
|
162
|
-
}
|
|
163
|
-
interface EvalRunsExportResult {
|
|
164
|
-
ok: boolean;
|
|
165
|
-
status: number;
|
|
166
|
-
accepted: number;
|
|
167
|
-
rejected: Array<{
|
|
168
|
-
index: number;
|
|
169
|
-
reason: string;
|
|
170
|
-
}>;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Ship self-improvement eval-run events to Tangle Intelligence. Unlike the
|
|
174
|
-
* best-effort span exporter, this RESOLVES with the ingest verdict (accepted /
|
|
175
|
-
* rejected per event) so a consumer's loop can assert its provenance landed.
|
|
176
|
-
* Throws only on a missing key or network failure.
|
|
177
|
-
*/
|
|
178
|
-
declare function exportEvalRuns(events: EvalRunEvent[], config?: EvalRunsExportConfig): Promise<EvalRunsExportResult>;
|
|
179
|
-
|
|
180
|
-
export { type EvalRunEvent as E, INTELLIGENCE_WIRE_VERSION as I, type LoopSpanNode as L, type OtelExporter as O, type EvalRunGeneration as a, type EvalRunsExportConfig as b, type EvalRunsExportResult as c, type OtelAttribute as d, type OtelExportConfig as e, type OtelSpan as f, buildLoopOtelSpans as g, buildLoopSpanNodes as h, createOtelExporter as i, exportEvalRuns as j, loopEventToOtelSpan as l };
|
|
File without changes
|
|
File without changes
|