@tangle-network/agent-runtime 0.73.0 → 0.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/agent.d.ts +34 -2
  2. package/dist/agent.js +3 -2
  3. package/dist/agent.js.map +1 -1
  4. package/dist/analyst-loop.d.ts +1 -1
  5. package/dist/chunk-JPURCA2O.js +266 -0
  6. package/dist/chunk-JPURCA2O.js.map +1 -0
  7. package/dist/{chunk-7ODB76J5.js → chunk-MRWXCFV5.js} +2 -2
  8. package/dist/chunk-O2UPHN7X.js +114 -0
  9. package/dist/chunk-O2UPHN7X.js.map +1 -0
  10. package/dist/{chunk-U56XGKVY.js → chunk-QKNBYHMK.js} +3 -3
  11. package/dist/{chunk-HPYWEFVY.js → chunk-SA5GCF2X.js} +2 -2
  12. package/dist/{chunk-NCH4XUZ7.js → chunk-ZKMOIEOB.js} +13 -119
  13. package/dist/chunk-ZKMOIEOB.js.map +1 -0
  14. package/dist/{coordination-DU0saWeg.d.ts → coordination-DEVknvQo.d.ts} +3 -2
  15. package/dist/generator-YkAQrOoD.d.ts +382 -0
  16. package/dist/index.d.ts +13 -167
  17. package/dist/index.js +15 -262
  18. package/dist/index.js.map +1 -1
  19. package/dist/intelligence.d.ts +1 -1
  20. package/dist/lifecycle.d.ts +787 -200
  21. package/dist/lifecycle.js +814 -9
  22. package/dist/lifecycle.js.map +1 -1
  23. package/dist/local-harness-BE_h8szs.d.ts +93 -0
  24. package/dist/{loop-runner-bin-eD3m0rHW.d.ts → loop-runner-bin-BPthX22l.d.ts} +2 -2
  25. package/dist/loop-runner-bin.d.ts +6 -5
  26. package/dist/loop-runner-bin.js +4 -3
  27. package/dist/loops.d.ts +10 -9
  28. package/dist/loops.js +3 -2
  29. package/dist/mcp/bin.js +2 -1
  30. package/dist/mcp/bin.js.map +1 -1
  31. package/dist/mcp/index.d.ts +8 -6
  32. package/dist/mcp/index.js +6 -4
  33. package/dist/mcp/index.js.map +1 -1
  34. package/dist/mcp-serve-verifier-CT1KLTG_.d.ts +162 -0
  35. package/dist/{openai-tools-CBurv8Cu.d.ts → openai-tools-D-VCAEmw.d.ts} +1 -1
  36. package/dist/profiles.d.ts +1 -1
  37. package/dist/{types-JufmXF2a.d.ts → types-YimN9PQP.d.ts} +1 -1
  38. package/dist/{worktree-DaxOvw-C.d.ts → worktree-CtuEQ7bZ.d.ts} +2 -93
  39. package/dist/{worktree-fanout-DIffZohV.d.ts → worktree-fanout-Cdez8GR7.d.ts} +3 -2
  40. package/package.json +1 -1
  41. package/dist/chunk-NCH4XUZ7.js.map +0 -1
  42. /package/dist/{chunk-7ODB76J5.js.map → chunk-MRWXCFV5.js.map} +0 -0
  43. /package/dist/{chunk-U56XGKVY.js.map → chunk-QKNBYHMK.js.map} +0 -0
  44. /package/dist/{chunk-HPYWEFVY.js.map → chunk-SA5GCF2X.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  mcpToolsForRuntimeMcp,
3
3
  mcpToolsForRuntimeMcpSubset
4
- } from "./chunk-7ODB76J5.js";
4
+ } from "./chunk-MRWXCFV5.js";
5
5
  import {
6
6
  DEFAULT_ROUTER_BASE_URL,
7
7
  cleanModelId,
@@ -20,17 +20,16 @@ import {
20
20
  runLoopRunnerCli,
21
21
  selfImproveLoopRunner,
22
22
  worktreeLoopRunner
23
- } from "./chunk-U56XGKVY.js";
23
+ } from "./chunk-QKNBYHMK.js";
24
24
  import "./chunk-FNMGYYSS.js";
25
- import "./chunk-HPYWEFVY.js";
25
+ import "./chunk-SA5GCF2X.js";
26
26
  import {
27
27
  assertModelAllowed,
28
28
  composeRuntimeHooks,
29
29
  defineRuntimeHooks,
30
30
  notifyRuntimeDecisionPoint,
31
- notifyRuntimeHookEvent,
32
- runLocalHarness
33
- } from "./chunk-NCH4XUZ7.js";
31
+ notifyRuntimeHookEvent
32
+ } from "./chunk-ZKMOIEOB.js";
34
33
  import {
35
34
  INTELLIGENCE_WIRE_VERSION,
36
35
  buildLoopOtelSpans,
@@ -41,6 +40,14 @@ import {
41
40
  } from "./chunk-VMNEQHJR.js";
42
41
  import "./chunk-IODKUOBA.js";
43
42
  import "./chunk-T2HVQVB4.js";
43
+ import {
44
+ agenticGenerator,
45
+ commandVerifier,
46
+ mcpBuildPrompt,
47
+ mcpServeVerifier,
48
+ toolBuildPrompt
49
+ } from "./chunk-JPURCA2O.js";
50
+ import "./chunk-O2UPHN7X.js";
44
51
  import {
45
52
  AgentEvalError,
46
53
  BackendTransportError,
@@ -1899,163 +1906,6 @@ function deriveExecutionId(input) {
1899
1906
  return `${input.projectId}:${input.sessionId}:${input.turnIndex}`;
1900
1907
  }
1901
1908
 
1902
- // src/improvement/agentic-generator.ts
1903
- import { spawnSync } from "child_process";
1904
- function agenticGenerator(opts = {}) {
1905
- const harness = opts.harness ?? "claude";
1906
- const buildPrompt = opts.buildPrompt ?? defaultBuildPrompt;
1907
- const run = opts.runHarness ?? runLocalHarness;
1908
- const dirty = opts.isDirty ?? worktreeDirty;
1909
- const verify = opts.verify;
1910
- return {
1911
- kind: `agentic:${harness}`,
1912
- async generate({ worktreePath, report, findings, maxShots, signal }) {
1913
- const basePrompt = buildPrompt({ report, findings });
1914
- const shots = Math.max(1, maxShots);
1915
- let attemptNote = "";
1916
- for (let shot = 0; shot < shots; shot++) {
1917
- if (signal.aborted) break;
1918
- await run({
1919
- harness,
1920
- cwd: worktreePath,
1921
- taskPrompt: attemptNote ? `${basePrompt}
1922
-
1923
- ${attemptNote}` : basePrompt,
1924
- timeoutMs: opts.timeoutMs,
1925
- signal
1926
- });
1927
- if (!dirty(worktreePath)) {
1928
- attemptNote = EMPTY_TREE_NOTE;
1929
- continue;
1930
- }
1931
- if (!verify) {
1932
- return { applied: true, summary: summarize(findings) };
1933
- }
1934
- const result = await verify(worktreePath);
1935
- if (result.ok) {
1936
- return { applied: true, summary: summarize(findings) };
1937
- }
1938
- attemptNote = failureNote(result.feedback);
1939
- }
1940
- return { applied: false, summary: "" };
1941
- }
1942
- };
1943
- }
1944
- function defaultBuildPrompt(args) {
1945
- const lines = [
1946
- "You are improving this codebase based on an evaluation analysis.",
1947
- "Make the smallest set of edits that addresses the findings below, then stop.",
1948
- "Do not change unrelated code. Do not commit \u2014 leave changes in the working tree.",
1949
- "",
1950
- "Findings:"
1951
- ];
1952
- for (const f of args.findings) {
1953
- const where = f.subject ? ` [${f.subject}]` : "";
1954
- lines.push(`- (${f.severity})${where} ${f.claim}`);
1955
- if (f.recommended_action) lines.push(` \u2192 ${f.recommended_action}`);
1956
- }
1957
- return lines.join("\n");
1958
- }
1959
- var EMPTY_TREE_NOTE = "NOTE: your previous attempt left the working tree unchanged. Make the concrete file edits now.";
1960
- function failureNote(feedback) {
1961
- const detail = feedback?.trim();
1962
- return [
1963
- "NOTE: your edits are in the working tree but verification FAILED.",
1964
- "Fix the problem in place \u2014 build on your existing edits, do not revert them.",
1965
- detail ? `Verifier output:
1966
- ${truncate(detail, 4e3)}` : "No verifier detail was captured."
1967
- ].join("\n");
1968
- }
1969
- function commandVerifier(command, args = [], timeoutMs = 3e5) {
1970
- return (worktreePath) => {
1971
- const result = spawnSync(command, args, {
1972
- cwd: worktreePath,
1973
- encoding: "utf-8",
1974
- timeout: timeoutMs
1975
- });
1976
- if (result.signal) {
1977
- return {
1978
- ok: false,
1979
- feedback: `verifier '${command}' killed by ${result.signal} (likely timeout after ${timeoutMs}ms)`
1980
- };
1981
- }
1982
- if (result.error) {
1983
- const code = result.error.code;
1984
- if (code === "ENOENT") {
1985
- throw new Error(
1986
- `commandVerifier: '${command}' not found in PATH (setup bug, not a failed candidate)`
1987
- );
1988
- }
1989
- throw new Error(`commandVerifier: '${command}' failed to spawn: ${result.error.message}`);
1990
- }
1991
- if (result.status === 0) return { ok: true };
1992
- const out = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
1993
- return { ok: false, feedback: out.length > 0 ? out : `exit ${result.status}` };
1994
- };
1995
- }
1996
- function summarize(findings) {
1997
- if (findings.length === 0) return "agentic improvement";
1998
- if (findings.length === 1) return `agentic: ${truncate(findings[0].claim, 64)}`;
1999
- return `agentic: ${findings.length} findings addressed`;
2000
- }
2001
- function truncate(s, n) {
2002
- return s.length <= n ? s : `${s.slice(0, n - 1)}\u2026`;
2003
- }
2004
- function worktreeDirty(worktreePath) {
2005
- const result = spawnSync("git", ["status", "--porcelain"], {
2006
- cwd: worktreePath,
2007
- encoding: "utf-8"
2008
- });
2009
- if (result.error) {
2010
- throw new Error(
2011
- `agenticGenerator: git status failed to spawn in ${worktreePath}: ${result.error.message}`
2012
- );
2013
- }
2014
- if (result.status !== 0) {
2015
- throw new Error(
2016
- `agenticGenerator: git status exited ${result.status} in ${worktreePath}: ${result.stderr.trim()}`
2017
- );
2018
- }
2019
- return result.stdout.trim().length > 0;
2020
- }
2021
-
2022
- // src/improvement/build-prompts.ts
2023
- function findingLines(findings) {
2024
- return findings.map((f) => {
2025
- const where = f.subject ? ` [${f.subject}]` : "";
2026
- const action = f.recommended_action ? ` \u2192 ${f.recommended_action}` : "";
2027
- return `- (${f.severity})${where} ${f.claim}${action}`;
2028
- });
2029
- }
2030
- function toolBuildPrompt(args) {
2031
- return [
2032
- "You are building a new TOOL for this codebase to address the gaps below.",
2033
- "Write the tool as a small, self-contained module PLUS tests that exercise it.",
2034
- "The tool must compile and its tests must pass \u2014 they will be run automatically;",
2035
- "if verification fails you will get the error and another attempt. Do not commit;",
2036
- "leave the changes in the working tree.",
2037
- "",
2038
- "Gaps the tool should close:",
2039
- ...findingLines(args.findings)
2040
- ].join("\n");
2041
- }
2042
- function mcpBuildPrompt(args) {
2043
- return [
2044
- "You are building a new MCP SERVER (Model Context Protocol) that exposes",
2045
- "tool(s) addressing the gaps below, so any harness can mount it.",
2046
- "Requirements that WILL be checked by booting the server:",
2047
- "- it starts over stdio and answers the MCP `initialize` handshake,",
2048
- "- `tools/list` returns at least one tool with a valid input schema.",
2049
- "Newline-delimited JSON-RPC 2.0, protocol version 2024-11-05. Include a start",
2050
- "command (e.g. a package.json `start` script or a clear entrypoint). If the",
2051
- "boot-and-probe fails you will get the error and another attempt. Do not",
2052
- "commit; leave the changes in the working tree.",
2053
- "",
2054
- "Capabilities the server should provide:",
2055
- ...findingLines(args.findings)
2056
- ].join("\n");
2057
- }
2058
-
2059
1909
  // src/improvement/improve.ts
2060
1910
  import { skillOptProposer } from "@tangle-network/agent-eval/campaign";
2061
1911
  import {
@@ -2196,105 +2046,8 @@ function resolveFindings(ctx) {
2196
2046
  return ctx.findings;
2197
2047
  }
2198
2048
 
2199
- // src/improvement/mcp-serve-verifier.ts
2200
- import { spawn } from "child_process";
2201
- import { createInterface } from "readline";
2202
- var PROTOCOL_VERSION = "2024-11-05";
2203
- function mcpServeVerifier(spec) {
2204
- const timeoutMs = spec.timeoutMs ?? 3e4;
2205
- const minTools = spec.minTools ?? 1;
2206
- return (worktreePath) => new Promise((resolve, reject) => {
2207
- const child = spawn(spec.command, spec.args ?? [], {
2208
- cwd: worktreePath,
2209
- stdio: ["pipe", "pipe", "pipe"],
2210
- env: { ...process.env, ...spec.env }
2211
- });
2212
- const stderr = [];
2213
- let settled = false;
2214
- let nextId = 1;
2215
- const initId = nextId++;
2216
- let listId = -1;
2217
- const settle = (fn) => {
2218
- if (settled) return;
2219
- settled = true;
2220
- clearTimeout(timer);
2221
- rl.close();
2222
- child.kill("SIGKILL");
2223
- fn();
2224
- };
2225
- const withStderr = (msg) => stderr.length > 0 ? `${msg}
2226
- stderr:
2227
- ${stderr.join("").slice(-2e3)}` : msg;
2228
- const pass = () => settle(() => resolve({ ok: true }));
2229
- const failCandidate = (msg) => settle(() => resolve({ ok: false, feedback: withStderr(msg) }));
2230
- const setupFault = (err) => settle(() => reject(err));
2231
- const send = (msg) => {
2232
- try {
2233
- child.stdin.write(`${JSON.stringify(msg)}
2234
- `);
2235
- return true;
2236
- } catch (err) {
2237
- failCandidate(`writing to MCP server stdin failed: ${err.message}`);
2238
- return false;
2239
- }
2240
- };
2241
- child.on("error", (err) => {
2242
- const code = err.code;
2243
- setupFault(
2244
- code === "ENOENT" ? new Error(
2245
- `mcpServeVerifier: '${spec.command}' not found in PATH (setup bug, not a failed candidate)`
2246
- ) : new Error(`mcpServeVerifier: '${spec.command}' failed to spawn: ${err.message}`)
2247
- );
2248
- });
2249
- child.on("exit", (code, signal) => {
2250
- failCandidate(`MCP server exited (code ${code}, signal ${signal}) before serving`);
2251
- });
2252
- child.stderr.on("data", (d) => stderr.push(String(d)));
2253
- const rl = createInterface({ input: child.stdout });
2254
- rl.on("line", (line) => {
2255
- let msg;
2256
- try {
2257
- msg = JSON.parse(line);
2258
- } catch {
2259
- return;
2260
- }
2261
- if (!msg || typeof msg !== "object") return;
2262
- if (msg.id === initId) {
2263
- if (msg.error) return failCandidate(`initialize errored: ${JSON.stringify(msg.error)}`);
2264
- if (!send({ jsonrpc: "2.0", method: "notifications/initialized" })) return;
2265
- listId = nextId++;
2266
- send({ jsonrpc: "2.0", id: listId, method: "tools/list" });
2267
- return;
2268
- }
2269
- if (msg.id === listId) {
2270
- if (msg.error) return failCandidate(`tools/list errored: ${JSON.stringify(msg.error)}`);
2271
- const tools = msg.result?.tools;
2272
- if (!Array.isArray(tools)) return failCandidate("tools/list result has no tools array");
2273
- if (tools.length < minTools) {
2274
- return failCandidate(`tools/list returned ${tools.length} tool(s), need >= ${minTools}`);
2275
- }
2276
- return pass();
2277
- }
2278
- });
2279
- const timer = setTimeout(
2280
- () => failCandidate(`MCP server did not complete the handshake within ${timeoutMs}ms`),
2281
- timeoutMs
2282
- );
2283
- send({
2284
- jsonrpc: "2.0",
2285
- id: initId,
2286
- method: "initialize",
2287
- params: {
2288
- protocolVersion: PROTOCOL_VERSION,
2289
- capabilities: {},
2290
- clientInfo: { name: "agent-runtime-mcp-verify", version: "0" }
2291
- }
2292
- });
2293
- });
2294
- }
2295
-
2296
2049
  // src/improvement/reflective-generator.ts
2297
- import { spawnSync as spawnSync2 } from "child_process";
2050
+ import { spawnSync } from "child_process";
2298
2051
  function reflectiveGenerator(opts) {
2299
2052
  return {
2300
2053
  kind: "reflective",
@@ -2312,7 +2065,7 @@ function reflectiveGenerator(opts) {
2312
2065
  };
2313
2066
  }
2314
2067
  function applyPatch(patch, cwd) {
2315
- const result = spawnSync2("git", ["apply", "--whitespace=fix", "-p0", "-"], {
2068
+ const result = spawnSync("git", ["apply", "--whitespace=fix", "-p0", "-"], {
2316
2069
  cwd,
2317
2070
  input: patch,
2318
2071
  encoding: "utf-8"