@tangle-network/agent-runtime 0.68.0 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +81 -13
  2. package/dist/agent.d.ts +4 -5
  3. package/dist/agent.js +3 -6
  4. package/dist/agent.js.map +1 -1
  5. package/dist/chunk-BYZCXQHF.js +474 -0
  6. package/dist/chunk-BYZCXQHF.js.map +1 -0
  7. package/dist/{chunk-OYU5LR4T.js → chunk-EDCVUZZC.js} +2 -2
  8. package/dist/{chunk-QNUEFNU7.js → chunk-L5ZFBVT6.js} +6 -6
  9. package/dist/chunk-L5ZFBVT6.js.map +1 -0
  10. package/dist/{chunk-VKUHUFX7.js → chunk-QXWGSDAQ.js} +914 -590
  11. package/dist/chunk-QXWGSDAQ.js.map +1 -0
  12. package/dist/{chunk-LTEF2LYD.js → chunk-ZNQVMMR5.js} +3 -3
  13. package/dist/{coordination-Curpzeyc.d.ts → coordination-C7WxwHXq.d.ts} +8 -1
  14. package/dist/{delegates-CLFNAKyi.d.ts → delegates-DqAgo32T.d.ts} +105 -10
  15. package/dist/{improvement-adapter-BC4HhuAR.d.ts → improvement-adapter-BVuMragr.d.ts} +1 -1
  16. package/dist/index.d.ts +439 -100
  17. package/dist/index.js +583 -125
  18. package/dist/index.js.map +1 -1
  19. package/dist/intelligence.d.ts +2 -3
  20. package/dist/{loop-runner-bin-B6dzNZC8.d.ts → loop-runner-bin-B0NeLTRd.d.ts} +4 -4
  21. package/dist/loop-runner-bin.d.ts +7 -10
  22. package/dist/loop-runner-bin.js +4 -7
  23. package/dist/loops.d.ts +3149 -16
  24. package/dist/loops.js +34 -63
  25. package/dist/mcp/bin.js +14 -16
  26. package/dist/mcp/bin.js.map +1 -1
  27. package/dist/mcp/index.d.ts +8 -12
  28. package/dist/mcp/index.js +16 -19
  29. package/dist/mcp/index.js.map +1 -1
  30. package/dist/{openai-tools-CA2N3-Ak.d.ts → openai-tools-DPx9Gzvn.d.ts} +1 -1
  31. package/dist/profiles.d.ts +94 -6
  32. package/dist/profiles.js +320 -9
  33. package/dist/profiles.js.map +1 -1
  34. package/dist/{router-client-30Y_pca8.d.ts → router-client-C7kp_ECN.d.ts} +37 -1
  35. package/dist/{substrate-CUgk7F7s.d.ts → substrate-BoRXgvka.d.ts} +52 -1
  36. package/dist/{types-Crxftafi.d.ts → types-BYa2ZOAx.d.ts} +83 -2
  37. package/dist/{types-p8dWBIXL.d.ts → types-DJu6TBGp.d.ts} +2 -16
  38. package/dist/{worktree-fanout-DUiKPApb.d.ts → worktree-fanout-gNfl0Byj.d.ts} +9 -37
  39. package/package.json +9 -39
  40. package/dist/analyst-loop.d.ts +0 -52
  41. package/dist/analyst-loop.js +0 -11
  42. package/dist/analyst-loop.js.map +0 -1
  43. package/dist/audit.d.ts +0 -93
  44. package/dist/audit.js +0 -312
  45. package/dist/audit.js.map +0 -1
  46. package/dist/chunk-4B6U4CVQ.js +0 -15
  47. package/dist/chunk-4B6U4CVQ.js.map +0 -1
  48. package/dist/chunk-FCIPUALH.js +0 -214
  49. package/dist/chunk-FCIPUALH.js.map +0 -1
  50. package/dist/chunk-O2UPHN7X.js +0 -114
  51. package/dist/chunk-O2UPHN7X.js.map +0 -1
  52. package/dist/chunk-P5OKDSLB.js +0 -580
  53. package/dist/chunk-P5OKDSLB.js.map +0 -1
  54. package/dist/chunk-QNUEFNU7.js.map +0 -1
  55. package/dist/chunk-VKUHUFX7.js.map +0 -1
  56. package/dist/chunk-VLF5RHEQ.js +0 -143
  57. package/dist/chunk-VLF5RHEQ.js.map +0 -1
  58. package/dist/coder-2leJPOvC.d.ts +0 -52
  59. package/dist/improvement.d.ts +0 -208
  60. package/dist/improvement.js +0 -343
  61. package/dist/improvement.js.map +0 -1
  62. package/dist/local-harness-BE_h8szs.d.ts +0 -93
  63. package/dist/platform.d.ts +0 -255
  64. package/dist/platform.js +0 -229
  65. package/dist/platform.js.map +0 -1
  66. package/dist/run-loop-D3PwlG7J.d.ts +0 -112
  67. package/dist/runtime-hooks-C7JwKb9E.d.ts +0 -70
  68. package/dist/runtime.d.ts +0 -3108
  69. package/dist/runtime.js +0 -263
  70. package/dist/runtime.js.map +0 -1
  71. package/dist/topology.d.ts +0 -126
  72. package/dist/topology.js +0 -333
  73. package/dist/topology.js.map +0 -1
  74. package/dist/workflow.d.ts +0 -551
  75. package/dist/workflow.js +0 -1781
  76. package/dist/workflow.js.map +0 -1
  77. /package/dist/{chunk-OYU5LR4T.js.map → chunk-EDCVUZZC.js.map} +0 -0
  78. /package/dist/{chunk-LTEF2LYD.js.map → chunk-ZNQVMMR5.js.map} +0 -0
@@ -1,143 +0,0 @@
1
- // src/errors.ts
2
- import { AgentEvalError } from "@tangle-network/agent-eval";
3
- import {
4
- AgentEvalError as AgentEvalError2,
5
- ConfigError,
6
- JudgeError,
7
- NotFoundError,
8
- ValidationError
9
- } from "@tangle-network/agent-eval";
10
- var SessionMismatchError = class extends AgentEvalError {
11
- sessionBackend;
12
- requestedBackend;
13
- constructor(sessionBackend, requestedBackend, options) {
14
- super(
15
- "validation",
16
- `Cannot resume ${sessionBackend} session with ${requestedBackend} backend`,
17
- options
18
- );
19
- this.sessionBackend = sessionBackend;
20
- this.requestedBackend = requestedBackend;
21
- }
22
- };
23
- var BackendTransportError = class extends AgentEvalError {
24
- backend;
25
- status;
26
- /**
27
- * Truncated upstream response body (≤2 KiB) when available. Diagnostic
28
- * only — surfaces in `backend_error.error.body` and `final.error.body`
29
- * so operators can see "free_tier_limit", "invalid_api_key", etc. without
30
- * cracking the log line open.
31
- */
32
- body;
33
- constructor(backend, message, options) {
34
- super("config", message, options);
35
- this.backend = backend;
36
- this.status = options?.status;
37
- this.body = options?.body;
38
- }
39
- };
40
- var RuntimeRunStateError = class extends AgentEvalError {
41
- constructor(message, options) {
42
- super("validation", message, options);
43
- }
44
- };
45
- var PlannerError = class extends AgentEvalError {
46
- constructor(message, options) {
47
- super("validation", message, options);
48
- }
49
- };
50
- var AnalystError = class extends AgentEvalError {
51
- constructor(message, options) {
52
- super("validation", message, options);
53
- }
54
- };
55
-
56
- // src/runtime/sandbox-events.ts
57
- function extractLlmCallEvent(event, agentRunName) {
58
- if (!event || typeof event !== "object") return void 0;
59
- const type = String(event.type ?? "");
60
- const data = event.data && typeof event.data === "object" ? event.data : {};
61
- if (type === "llm_call" || type === "cost.usage" || type === "usage") {
62
- return buildLlmCall(data, agentRunName);
63
- }
64
- if (type === "message.completed" || type === "result" || type === "final") {
65
- const usage = data.usage;
66
- if (!usage || typeof usage !== "object") return void 0;
67
- return buildLlmCall({ ...usage, model: data.model ?? usage.model }, agentRunName);
68
- }
69
- if (type === "done") {
70
- const usage = data.tokenUsage;
71
- if (!usage || typeof usage !== "object") return void 0;
72
- const out = pickFiniteNumber(usage, ["outputTokens", "completion_tokens", "tokensOut"]);
73
- const reasoning = pickFiniteNumber(usage, ["reasoningTokens"]);
74
- const mergedOut = out !== void 0 || reasoning !== void 0 ? (out ?? 0) + (reasoning ?? 0) : void 0;
75
- return buildLlmCall(
76
- {
77
- inputTokens: usage.inputTokens,
78
- outputTokens: mergedOut,
79
- totalCostUsd: data.totalCostUsd,
80
- model: data.model ?? usage.model
81
- },
82
- agentRunName
83
- );
84
- }
85
- return void 0;
86
- }
87
- function buildLlmCall(data, agentRunName) {
88
- const tokensIn = pickFiniteNumber(data, ["tokensIn", "inputTokens", "prompt_tokens"]);
89
- const tokensOut = pickFiniteNumber(data, ["tokensOut", "outputTokens", "completion_tokens"]);
90
- const costUsd = pickFiniteNumber(data, ["costUsd", "totalCostUsd", "cost_usd", "cost"]);
91
- if (tokensIn === void 0 && tokensOut === void 0 && costUsd === void 0) {
92
- return void 0;
93
- }
94
- const model = typeof data.model === "string" && data.model.length > 0 ? data.model : agentRunName;
95
- const event = {
96
- type: "llm_call",
97
- model
98
- };
99
- if (tokensIn !== void 0) event.tokensIn = tokensIn;
100
- if (tokensOut !== void 0) event.tokensOut = tokensOut;
101
- if (costUsd !== void 0) event.costUsd = costUsd;
102
- return event;
103
- }
104
- function pickFiniteNumber(data, keys) {
105
- for (const key of keys) {
106
- const value = data[key];
107
- if (typeof value === "number" && Number.isFinite(value)) return value;
108
- }
109
- return void 0;
110
- }
111
- function mapSandboxEvent(event, opts = {}) {
112
- if (!event || typeof event !== "object") return void 0;
113
- const type = String(event.type ?? "");
114
- const data = event.data && typeof event.data === "object" ? event.data : {};
115
- if (type === "message.part.updated") {
116
- const part = data.part && typeof data.part === "object" ? data.part : {};
117
- const partType = String(part.type ?? "");
118
- const delta = typeof data.delta === "string" ? data.delta : void 0;
119
- const text = delta ?? (typeof part.text === "string" ? part.text : void 0);
120
- if (text === void 0) return void 0;
121
- if (partType === "text") return { type: "text_delta", text };
122
- if (partType === "reasoning" || partType === "thinking")
123
- return { type: "reasoning_delta", text };
124
- return void 0;
125
- }
126
- return extractLlmCallEvent(event, opts.agentRunName ?? "agent");
127
- }
128
-
129
- export {
130
- SessionMismatchError,
131
- BackendTransportError,
132
- RuntimeRunStateError,
133
- PlannerError,
134
- AnalystError,
135
- AgentEvalError2 as AgentEvalError,
136
- ConfigError,
137
- JudgeError,
138
- NotFoundError,
139
- ValidationError,
140
- extractLlmCallEvent,
141
- mapSandboxEvent
142
- };
143
- //# sourceMappingURL=chunk-VLF5RHEQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/runtime/sandbox-events.ts"],"sourcesContent":["/**\n * @stable\n *\n * Error taxonomy for `@tangle-network/agent-runtime`.\n *\n * Public contract: every error this package throws as part of its consumer-\n * facing API either extends `AgentEvalError` (re-exported here for ergonomic\n * `instanceof` checks at the runtime boundary) or extends one of the\n * runtime-specific subclasses below.\n *\n * Internal invariant guards (`throw new Error('this should never happen')`)\n * remain plain `Error` — they are programmer-mistake assertions, not\n * consumer-catchable contract failures.\n *\n * Subclassing strategy: where a runtime-specific failure maps cleanly to an\n * agent-eval code (validation, config, not_found), we re-use the agent-eval\n * subclass. Runtime-only failure modes (session resume against the wrong\n * backend, backend transport errors) get fresh subclasses that still carry an\n * `AgentEvalErrorCode` so cross-package handlers can pattern-match without\n * importing the runtime.\n */\n\nimport { AgentEvalError } from '@tangle-network/agent-eval'\n\nexport {\n AgentEvalError,\n type AgentEvalErrorCode,\n ConfigError,\n JudgeError,\n NotFoundError,\n ValidationError,\n} from '@tangle-network/agent-eval'\n\n/**\n * @stable\n *\n * Caller asked to resume a session against a backend whose `kind` does not\n * match the session's recorded backend. This is a routing bug — the same\n * session id was reused across two different backend implementations — and\n * is not retryable without picking the right backend.\n */\nexport class SessionMismatchError extends AgentEvalError {\n readonly sessionBackend: string\n readonly requestedBackend: string\n\n constructor(sessionBackend: string, requestedBackend: string, options?: { cause?: unknown }) {\n super(\n 'validation',\n `Cannot resume ${sessionBackend} session with ${requestedBackend} backend`,\n options,\n )\n this.sessionBackend = sessionBackend\n this.requestedBackend = requestedBackend\n }\n}\n\n/**\n * @stable\n *\n * A backend transport call (HTTP, gRPC, sidecar IPC) failed with a non-success\n * status. Distinct from `JudgeError` (which is structural / unrecoverable)\n * because backend failures are sometimes retryable and consumers may want to\n * branch on the upstream status code.\n */\nexport class BackendTransportError extends AgentEvalError {\n readonly backend: string\n readonly status?: number\n /**\n * Truncated upstream response body (≤2 KiB) when available. Diagnostic\n * only — surfaces in `backend_error.error.body` and `final.error.body`\n * so operators can see \"free_tier_limit\", \"invalid_api_key\", etc. without\n * cracking the log line open.\n */\n readonly body?: string\n\n constructor(\n backend: string,\n message: string,\n options?: { cause?: unknown; status?: number; body?: string },\n ) {\n super('config', message, options)\n this.backend = backend\n this.status = options?.status\n this.body = options?.body\n }\n}\n\n/**\n * @stable\n *\n * A runtime-run lifecycle method was called in an order the state machine does\n * not allow: `persist()` before `complete()`, `complete()` twice, etc.\n */\nexport class RuntimeRunStateError extends AgentEvalError {\n constructor(message: string, options?: { cause?: unknown }) {\n super('validation', message, options)\n }\n}\n\n/**\n * @stable\n *\n * The dynamic-loop planner returned an unusable topology move — the LLM emitted\n * no parseable envelope, an unknown `kind`, or a structurally-invalid move\n * (e.g. a fanout with zero tasks). This is a structural failure of the\n * agent-authored topology, not a config mistake: the planner ran but its output\n * cannot drive the kernel. Carries `validation` so cross-package handlers can\n * pattern-match without importing the runtime. Fail loud — never substitute a\n * default move, or the loop silently runs a topology nobody chose.\n */\nexport class PlannerError extends AgentEvalError {\n constructor(message: string, options?: { cause?: unknown }) {\n super('validation', message, options)\n }\n}\n\n/**\n * The analyst loop could not read or run over a round's trace — e.g. an empty round\n * (no iterations to analyze) or a malformed trace projection. Fail loud: a silent empty\n * store would mask a broken capture path and the driver would steer on nothing.\n */\nexport class AnalystError extends AgentEvalError {\n constructor(message: string, options?: { cause?: unknown }) {\n super('validation', message, options)\n }\n}\n","/**\n * Sandbox-event → runtime-event mapping.\n *\n * The sandbox SDK emits a polymorphic `SandboxEvent = { type, data, id? }`\n * whose `type` vocabulary is backend-determined (opencode, etc.) rather than\n * enumerated by the SDK. Two consumers project it:\n * - the loop kernel's cost ledger (`extractLlmCallEvent`) — sums usage off\n * every cost-bearing event, regardless of stream shape;\n * - the `AgentRuntime.act` streaming contract (`mapSandboxEvent`) — projects\n * incremental events to the `RuntimeStreamEvent` chat-UX vocabulary.\n *\n * Both live here so the empirically-observed `type` vocabulary has one home.\n */\n\nimport type { SandboxEvent } from '@tangle-network/sandbox'\nimport type { RuntimeStreamEvent } from '../types'\n\n/**\n * Extract a `RuntimeStreamEvent`-shaped `llm_call` from a sandbox event when\n * the event carries usage/cost data. Returns `undefined` for non-cost events\n * so the kernel can iterate the full stream without branching.\n *\n * Canonical cost-carrying types observed in the wild:\n * - `llm_call` — `data: { model, tokensIn, tokensOut, costUsd, ... }`\n * - `message.completed` / `result` — `data: { usage: { inputTokens,\n * outputTokens, totalCostUsd? } }`\n * - `cost.usage` / `usage` — same shape under a dedicated type\n *\n * Numeric coercion is strict: `Number.isFinite` gates every accumulator write\n * so a sentinel `NaN` from a misbehaving backend cannot poison the ledger.\n */\nexport function extractLlmCallEvent(\n event: SandboxEvent,\n agentRunName: string,\n): (RuntimeStreamEvent & { type: 'llm_call' }) | undefined {\n if (!event || typeof event !== 'object') return undefined\n const type = String(event.type ?? '')\n const data =\n event.data && typeof event.data === 'object'\n ? (event.data as Record<string, unknown>)\n : ({} as Record<string, unknown>)\n\n if (type === 'llm_call' || type === 'cost.usage' || type === 'usage') {\n return buildLlmCall(data, agentRunName)\n }\n if (type === 'message.completed' || type === 'result' || type === 'final') {\n const usage = data.usage as Record<string, unknown> | undefined\n if (!usage || typeof usage !== 'object') return undefined\n return buildLlmCall({ ...usage, model: data.model ?? usage.model }, agentRunName)\n }\n // sandbox 0.4.0 terminal event: `data = { tokenUsage: { inputTokens, outputTokens,\n // reasoningTokens, cacheReadInputTokens }, totalCostUsd }`. Usage lives under\n // `tokenUsage` (not `usage`) and the cost is top-level — neither matched the\n // branches above, so an in-process loopDispatch run reported {0,0} and the\n // backend-integrity guard misread a real run as a stub. Reasoning tokens are\n // billed output (reasoning models), so they fold into the output count.\n if (type === 'done') {\n const usage = data.tokenUsage as Record<string, unknown> | undefined\n if (!usage || typeof usage !== 'object') return undefined\n const out = pickFiniteNumber(usage, ['outputTokens', 'completion_tokens', 'tokensOut'])\n const reasoning = pickFiniteNumber(usage, ['reasoningTokens'])\n const mergedOut =\n out !== undefined || reasoning !== undefined ? (out ?? 0) + (reasoning ?? 0) : undefined\n return buildLlmCall(\n {\n inputTokens: usage.inputTokens,\n outputTokens: mergedOut,\n totalCostUsd: data.totalCostUsd,\n model: data.model ?? usage.model,\n },\n agentRunName,\n )\n }\n return undefined\n}\n\nfunction buildLlmCall(\n data: Record<string, unknown>,\n agentRunName: string,\n): (RuntimeStreamEvent & { type: 'llm_call' }) | undefined {\n const tokensIn = pickFiniteNumber(data, ['tokensIn', 'inputTokens', 'prompt_tokens'])\n const tokensOut = pickFiniteNumber(data, ['tokensOut', 'outputTokens', 'completion_tokens'])\n const costUsd = pickFiniteNumber(data, ['costUsd', 'totalCostUsd', 'cost_usd', 'cost'])\n if (tokensIn === undefined && tokensOut === undefined && costUsd === undefined) {\n return undefined\n }\n const model = typeof data.model === 'string' && data.model.length > 0 ? data.model : agentRunName\n const event: RuntimeStreamEvent & { type: 'llm_call' } = {\n type: 'llm_call',\n model,\n }\n if (tokensIn !== undefined) event.tokensIn = tokensIn\n if (tokensOut !== undefined) event.tokensOut = tokensOut\n if (costUsd !== undefined) event.costUsd = costUsd\n return event\n}\n\nfunction pickFiniteNumber(data: Record<string, unknown>, keys: string[]): number | undefined {\n for (const key of keys) {\n const value = data[key]\n if (typeof value === 'number' && Number.isFinite(value)) return value\n }\n return undefined\n}\n\n/**\n * Project one `SandboxEvent` onto the `RuntimeStreamEvent` chat-UX vocabulary,\n * for runtimes that bridge a sandbox `streamPrompt` into the\n * `AgentRuntime.act` streaming contract. Returns `undefined` for events that\n * have no faithful projection — the raw stream is preserved separately for the\n * `OutputAdapter`, so an unmapped event never loses data.\n *\n * Mapped (the task-optional incremental variants — no synthesized task\n * lifecycle, no guessed tool-part shapes):\n * - `message.part.updated` text part → `text_delta`\n * - `message.part.updated` reasoning/thinking part → `reasoning_delta`\n * - cost-bearing events → `llm_call` (shared with the ledger extractor)\n *\n * The opencode backend emits incremental text as\n * `{ type: 'message.part.updated', data: { part: { type, text }, delta } }`;\n * `delta` is the increment, `part.text` the running accumulation.\n */\nexport function mapSandboxEvent(\n event: SandboxEvent,\n opts: { agentRunName?: string } = {},\n): RuntimeStreamEvent | undefined {\n if (!event || typeof event !== 'object') return undefined\n const type = String(event.type ?? '')\n const data =\n event.data && typeof event.data === 'object'\n ? (event.data as Record<string, unknown>)\n : ({} as Record<string, unknown>)\n\n if (type === 'message.part.updated') {\n const part =\n data.part && typeof data.part === 'object' ? (data.part as Record<string, unknown>) : {}\n const partType = String(part.type ?? '')\n const delta = typeof data.delta === 'string' ? data.delta : undefined\n const text = delta ?? (typeof part.text === 'string' ? part.text : undefined)\n if (text === undefined) return undefined\n if (partType === 'text') return { type: 'text_delta', text }\n if (partType === 'reasoning' || partType === 'thinking')\n return { type: 'reasoning_delta', text }\n return undefined\n }\n\n return extractLlmCallEvent(event, opts.agentRunName ?? 'agent')\n}\n"],"mappings":"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","names":["AgentEvalError"]}
@@ -1,52 +0,0 @@
1
- import { AgentProfile } from '@tangle-network/agent-interface';
2
-
3
- /**
4
- * @experimental
5
- *
6
- * `coderProfile` — the §1.5 author-the-profile DATA for code-modification tasks: an `AgentProfile`
7
- * constant (the agent IS its profile) plus a pure `coderTaskToPrompt` formatter that renders a
8
- * `CoderTask` into the per-task instruction. There is no factory, output adapter, or validator
9
- * here — a domain customizes the worker by authoring a profile + handing it to a leaf executor
10
- * (`createWorktreeCliExecutor`) or a fanout (`worktreeFanout`), and "is it delivered" is a
11
- * `DeliverableSpec` (`patchDelivered`), not a bundled validator.
12
- *
13
- * The standing instruction tells the agent to work on a fresh branch, keep the patch minimal,
14
- * avoid forbidden paths, and run the test + typecheck commands before declaring done.
15
- */
16
-
17
- /** @experimental The per-task inputs `coderTaskToPrompt` renders + the worktree gate enforces. */
18
- interface CoderTask {
19
- /** What the agent must accomplish. Free-form prose. */
20
- goal: string;
21
- /** Absolute path inside the sandbox where the repo lives. */
22
- repoRoot: string;
23
- /** Default `main`. The branch the agent diffs against. */
24
- baseBranch?: string;
25
- /** Default `pnpm test --run`. */
26
- testCmd?: string;
27
- /** Default `pnpm typecheck`. */
28
- typecheckCmd?: string;
29
- /** Files the agent may inspect for context. Surfaced verbatim in the prompt. */
30
- contextFiles?: string[];
31
- /**
32
- * Paths the agent must not touch. The mechanical gate hard-fails on any match.
33
- * Use glob-free literal path prefixes for unambiguous enforcement.
34
- */
35
- forbiddenPaths?: string[];
36
- /** Default 400. Hard cap; the gate hard-fails when exceeded. */
37
- maxDiffLines?: number;
38
- }
39
- /** @experimental The coder agent's standing instruction (its body lives in `coderProfile.prompt`). */
40
- declare const DEFAULT_CODER_SYSTEM_PROMPT: string;
41
- /**
42
- * @experimental
43
- *
44
- * The coder `AgentProfile` — the §1.5 DATA the substrate materializes into a harness invocation.
45
- * Stateless and harness-agnostic: a consumer overrides `model`/`metadata.backendType` by spreading
46
- * a copy, never by a factory. `worktreeFanout` authors one such profile per harness leaf.
47
- */
48
- declare const coderProfile: AgentProfile;
49
- /** @experimental Render a `CoderTask` into the per-task instruction handed to the coder profile. */
50
- declare function coderTaskToPrompt(task: CoderTask): string;
51
-
52
- export { type CoderTask as C, DEFAULT_CODER_SYSTEM_PROMPT as D, coderTaskToPrompt as a, coderProfile as c };
@@ -1,208 +0,0 @@
1
- import { AnalystFinding } from '@tangle-network/agent-eval';
2
- import { L as LocalHarness, r as runLocalHarness } from './local-harness-BE_h8szs.js';
3
- import { LabeledScenarioStore, WorktreeAdapter, ImprovementDriver } from '@tangle-network/agent-eval/campaign';
4
- import { S as SurfaceImprovementEdit } from './improvement-adapter-BC4HhuAR.js';
5
- import { I as ImprovementAdapter } from './types-p8dWBIXL.js';
6
- import 'node:child_process';
7
-
8
- /**
9
- * @experimental
10
- *
11
- * `improvementDriver` — the ONE reflective/agentic improvement driver for
12
- * agent-eval's improvement loop. It implements `ImprovementDriver` and owns
13
- * the candidate lifecycle (worktree create → generate → finalize/discard,
14
- * × populationSize); it delegates the only thing that genuinely varies — HOW
15
- * a candidate change is produced — to a pluggable `CandidateGenerator`.
16
- *
17
- * There is no separate "analyst driver" vs "autoresearch driver": those are
18
- * the SAME driver at two settings of a dial.
19
- * - cheap reflective path → `reflectiveGenerator` (shots=1, no sandbox;
20
- * applies pre-drafted patches)
21
- * - full agentic path → `agenticGenerator` (shots=N, multi-shot
22
- * verify-in-session loop; an agent reads code +
23
- * report, edits, and re-tries on verifier failure)
24
- * Both emit changes into a worktree the driver finalizes into a
25
- * `CodeSurface{ worktreeRef }` the loop measures on the holdout. See
26
- * agent-eval's `docs/design/self-improvement-engine.md`.
27
- */
28
-
29
- /** The byte-producing seam — the ONE thing that differs between the cheap
30
- * reflective path and the full agentic path. A generator makes (uncommitted)
31
- * changes inside `worktreePath`; the driver commits them via the worktree
32
- * adapter's `finalize`. */
33
- interface CandidateGenerator {
34
- kind: string;
35
- generate(args: {
36
- /** The candidate worktree — a fresh checkout of baseRef. Write changes here. */
37
- worktreePath: string;
38
- /** Phase-2 research report (analyst findings + diff), opaque. */
39
- report: unknown;
40
- /** Findings resolved from the report or the loop context. */
41
- findings: AnalystFinding[];
42
- /** Handle to all captured data, to ground the change. */
43
- dataset?: LabeledScenarioStore;
44
- /** DEPTH: max iterations the generator may take (agentic uses this; the
45
- * reflective generator ignores it). */
46
- maxShots: number;
47
- signal: AbortSignal;
48
- }): Promise<{
49
- applied: boolean;
50
- summary: string;
51
- }>;
52
- }
53
- interface ImprovementDriverOptions {
54
- worktree: WorktreeAdapter;
55
- generator: CandidateGenerator;
56
- /** Base ref candidate worktrees fork from. Default `main`. */
57
- baseRef?: string;
58
- }
59
- declare function improvementDriver(opts: ImprovementDriverOptions): ImprovementDriver<AnalystFinding>;
60
-
61
- /**
62
- * @experimental
63
- *
64
- * `agenticGenerator` — the full-agentic `CandidateGenerator`: the
65
- * `shots=N, sandbox=on` setting of the one `improvementDriver`. It runs a real
66
- * coding harness (claude / codex / opencode) inside the candidate worktree the
67
- * driver already created, letting the agent read the codebase + the research
68
- * report and make the change in place. The driver then commits the worktree
69
- * into a `CodeSurface`.
70
- *
71
- * Mechanism: identical to the proven Phase-2.8 in-process executor — spawn the
72
- * harness as a subprocess with `cwd` = the worktree, on the same filesystem,
73
- * so edits land in place (no sandbox-mount round-trip). `runLocalHarness` is
74
- * the verified primitive. The OUTER sandbox is the improvement loop's own
75
- * execution context; the generator does not nest a second sandbox per
76
- * candidate (which would reintroduce a host↔sandbox worktree-transport
77
- * problem that does not need solving here).
78
- *
79
- * `maxShots` is the DEPTH dial — a multi-shot verify-in-session loop, NOT the
80
- * kernel `runLoop`. Each shot runs one full harness session in the (persistent)
81
- * worktree; between shots the loop refines based on what the last shot produced:
82
- * - empty tree → "you changed nothing, make the edits" → retry
83
- * - dirty + `verify` fails → feed the verifier's failure into the next shot
84
- * (the worktree persists, so the harness RESUMES atop its own failing
85
- * edits with the error in hand — no `--resume` session plumbing needed,
86
- * and harness-agnostic across claude/codex/opencode)
87
- * - dirty + `verify` ok (or no verifier configured) → return the candidate
88
- * A candidate that never verifies within `maxShots` is discarded (`applied:
89
- * false`), never shipped — if you configured a verifier, a non-passing tree is
90
- * not a candidate. With no verifier the legacy behavior holds: first dirty shot
91
- * is the candidate.
92
- */
93
-
94
- /** Outcome of verifying a candidate worktree. `feedback` (compiler errors,
95
- * failing test output) is fed into the next shot when `ok` is false. */
96
- interface VerifyResult {
97
- ok: boolean;
98
- feedback?: string;
99
- }
100
- /** Verifies the edited worktree. Sync or async; throws only on a setup fault
101
- * (a candidate that fails verification returns `{ok:false}`, it does not
102
- * throw). */
103
- type Verifier = (worktreePath: string) => Promise<VerifyResult> | VerifyResult;
104
- interface AgenticGeneratorOptions {
105
- /** Local coding harness to run in the worktree. Default `claude`. */
106
- harness?: LocalHarness;
107
- /** Per-shot wall-clock timeout (ms). Default = `runLocalHarness` default (5m). */
108
- timeoutMs?: number;
109
- /** Build the harness task prompt from the report + findings. Override for
110
- * domain phrasing; the default turns findings into a concrete coder task. */
111
- buildPrompt?: (args: {
112
- report: unknown;
113
- findings: AnalystFinding[];
114
- }) => string;
115
- /** Verify the worktree after each dirtying shot. When set, a candidate that
116
- * fails verification is NOT returned — the failure feeds the next shot
117
- * (verify-in-session), up to `maxShots`; a candidate that never verifies is
118
- * discarded (`applied:false`), never shipped. Omitted ⇒ legacy behavior:
119
- * the first dirty shot is the candidate. See `commandVerifier`. */
120
- verify?: Verifier;
121
- /** Test seam — inject the harness runner (defaults to `runLocalHarness`). */
122
- runHarness?: typeof runLocalHarness;
123
- /** Test seam — inject the worktree-dirty check (defaults to `git status`). */
124
- isDirty?: (worktreePath: string) => boolean;
125
- }
126
- declare function agenticGenerator(opts?: AgenticGeneratorOptions): CandidateGenerator;
127
- /** A `Verifier` that runs a command in the worktree: exit 0 ⇒ ok, any other
128
- * exit ⇒ failed with stdout+stderr as feedback. The common case — verify by
129
- * `tsc --noEmit`, `pnpm build`, or a test command. A timeout is treated as a
130
- * FAILED candidate (a change that hangs the build is a bad change); a missing
131
- * binary or spawn fault throws (a setup bug, not a failed candidate — no
132
- * silent fallback). */
133
- declare function commandVerifier(command: string, args?: string[], timeoutMs?: number): Verifier;
134
-
135
- /**
136
- * Build-prompt starting points for the two buildable artifact types. There is
137
- * NO `toolGenerator`/`mcpGenerator` wrapper — the factory is `agenticGenerator`
138
- * + a verifier (docs/artifact-lifecycle-frontier.md), so a tool or an MCP
139
- * server is built by composing the pieces directly:
140
- *
141
- * // a tool:
142
- * agenticGenerator({ buildPrompt: toolBuildPrompt, verify: commandVerifier('pnpm', ['test']) })
143
- * // an MCP server:
144
- * agenticGenerator({ buildPrompt: mcpBuildPrompt, verify: mcpServeVerifier({ command: 'node', args: ['server.mjs'] }) })
145
- *
146
- * These are the only type-specific bit (the phrasing that points the agent at a
147
- * tool vs. an MCP); the worktree, resume-on-failure loop, and improvement-loop
148
- * wrapper are shared. MCP is the load-bearing target — it is how a harness
149
- * acquires tools; raw tools matter where we control the loader.
150
- */
151
-
152
- type FindingsArg = {
153
- report: unknown;
154
- findings: AnalystFinding[];
155
- };
156
- declare function toolBuildPrompt(args: FindingsArg): string;
157
- declare function mcpBuildPrompt(args: FindingsArg): string;
158
-
159
- /**
160
- * `mcpServeVerifier` — the intrinsic verifier for a built MCP server: the
161
- * boot-and-probe checker named in docs/artifact-lifecycle-frontier.md. A
162
- * generated MCP server is only a candidate if it actually *serves* — so this
163
- * boots it over stdio (the default local MCP transport) and runs the real
164
- * handshake: `initialize` → `notifications/initialized` → `tools/list`, and
165
- * asserts the server answers with at least `minTools` tools.
166
- *
167
- * Outcomes follow the `Verifier` contract: a server that fails to start, exits
168
- * early, errors the handshake, times out, or exposes no tools is a FAILED
169
- * candidate (`{ok:false}`, fed back into the next generation shot); a missing
170
- * start binary or spawn fault THROWS (a setup bug, never a silent fallback).
171
- *
172
- * Protocol matches the runtime's own stdio MCP server (src/mcp/server.ts):
173
- * newline-delimited JSON-RPC 2.0, protocol version 2024-11-05.
174
- */
175
-
176
- interface McpServeSpec {
177
- /** Command that starts the built MCP server in the worktree (stdio transport). */
178
- command: string;
179
- args?: string[];
180
- /** Extra env for the server process (merged over `process.env`). */
181
- env?: Record<string, string>;
182
- /** Handshake timeout (ms). Default 30s. */
183
- timeoutMs?: number;
184
- /** Minimum tools the server must expose to pass. Default 1. */
185
- minTools?: number;
186
- }
187
- declare function mcpServeVerifier(spec: McpServeSpec): Verifier;
188
-
189
- /**
190
- * @experimental
191
- *
192
- * `reflectiveGenerator` — the cheap, no-sandbox `CandidateGenerator`. It drafts
193
- * surface edits via the existing improvement adapter (`proposeFromFindings`,
194
- * one LLM patch per finding) and applies them as ONE coherent improvement into
195
- * the candidate worktree. `maxShots` is ignored — reflection is single-shot by
196
- * construction (the patches are already drafted).
197
- *
198
- * This is the `shots=1, sandbox=off` setting of the one improvement driver.
199
- * The `agenticGenerator` (a multi-shot verify-in-session loop) is the
200
- * `shots=N` setting — both plug into the same `improvementDriver`.
201
- */
202
-
203
- interface ReflectiveGeneratorOptions {
204
- improvementAdapter: ImprovementAdapter<SurfaceImprovementEdit>;
205
- }
206
- declare function reflectiveGenerator(opts: ReflectiveGeneratorOptions): CandidateGenerator;
207
-
208
- export { type AgenticGeneratorOptions, type CandidateGenerator, type ImprovementDriverOptions, type McpServeSpec, type ReflectiveGeneratorOptions, type Verifier, type VerifyResult, agenticGenerator, commandVerifier, improvementDriver, mcpBuildPrompt, mcpServeVerifier, reflectiveGenerator, toolBuildPrompt };