@tangle-network/agent-runtime 0.51.0 → 0.53.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 (51) hide show
  1. package/dist/agent.d.ts +2 -2
  2. package/dist/agent.js +2 -2
  3. package/dist/analyst-loop.d.ts +1 -1
  4. package/dist/{chunk-HAA4KZUD.js → chunk-5M2WDWBI.js} +3 -3
  5. package/dist/{chunk-HYG4ISNS.js → chunk-AYRQZRDV.js} +2 -2
  6. package/dist/{chunk-47SWANFA.js → chunk-FO4DCM7R.js} +2 -2
  7. package/dist/{chunk-7JITYN6T.js → chunk-JFIYKDXF.js} +17 -2
  8. package/dist/chunk-JFIYKDXF.js.map +1 -0
  9. package/dist/{chunk-XEI7AIHU.js → chunk-K5M3SHEU.js} +3 -3
  10. package/dist/{chunk-FQH33M5N.js → chunk-K6WP7PYW.js} +67 -61
  11. package/dist/chunk-K6WP7PYW.js.map +1 -0
  12. package/dist/{chunk-FKHNHUXP.js → chunk-P4QNEXFC.js} +2 -2
  13. package/dist/{coder-_YCf3BAK.d.ts → coder-LKm3Mczw.d.ts} +1 -1
  14. package/dist/{delegation-profile-1GbW5yA3.d.ts → delegation-profile-Bvfro2m1.d.ts} +28 -2
  15. package/dist/{driver-DLI1io57.d.ts → driver-B2RKkVJW.d.ts} +1 -1
  16. package/dist/index.d.ts +121 -11
  17. package/dist/index.js +143 -16
  18. package/dist/index.js.map +1 -1
  19. package/dist/intelligence.d.ts +475 -5
  20. package/dist/intelligence.js +547 -3
  21. package/dist/intelligence.js.map +1 -1
  22. package/dist/{kb-gate-CHAyt4aI.d.ts → kb-gate-CKfykcYQ.d.ts} +2 -2
  23. package/dist/{loop-runner-bin-DFUNgpeK.d.ts → loop-runner-bin-D4Ir7b00.d.ts} +4 -4
  24. package/dist/loop-runner-bin.d.ts +5 -5
  25. package/dist/loop-runner-bin.js +3 -3
  26. package/dist/loops.d.ts +7 -5
  27. package/dist/loops.js +3 -1
  28. package/dist/mcp/bin.js +4 -4
  29. package/dist/mcp/index.d.ts +7 -7
  30. package/dist/mcp/index.js +6 -6
  31. package/dist/{openai-tools-D4HLDWgw.d.ts → openai-tools-CKfR3EMh.d.ts} +1 -1
  32. package/dist/profiles.d.ts +2 -2
  33. package/dist/router-client-B0Qi1NiN.d.ts +120 -0
  34. package/dist/{run-loop-BIineL1T.d.ts → run-loop-DgVhucoR.d.ts} +1 -1
  35. package/dist/runtime.d.ts +62 -126
  36. package/dist/runtime.js +3 -1
  37. package/dist/{types-5MGt5KTY.d.ts → types-CNDJCL_0.d.ts} +1 -1
  38. package/dist/{types-BEQsBhOE.d.ts → types-CklkW4Eh.d.ts} +2 -1
  39. package/dist/workflow.d.ts +2 -2
  40. package/dist/workflow.js +1 -1
  41. package/package.json +1 -1
  42. package/skills/agent-runtime-adoption/SKILL.md +41 -26
  43. package/skills/build-with-agent-runtime/SKILL.md +143 -0
  44. package/skills/loop-writer/SKILL.md +6 -7
  45. package/dist/chunk-7JITYN6T.js.map +0 -1
  46. package/dist/chunk-FQH33M5N.js.map +0 -1
  47. /package/dist/{chunk-HAA4KZUD.js.map → chunk-5M2WDWBI.js.map} +0 -0
  48. /package/dist/{chunk-HYG4ISNS.js.map → chunk-AYRQZRDV.js.map} +0 -0
  49. /package/dist/{chunk-47SWANFA.js.map → chunk-FO4DCM7R.js.map} +0 -0
  50. /package/dist/{chunk-XEI7AIHU.js.map → chunk-K5M3SHEU.js.map} +0 -0
  51. /package/dist/{chunk-FKHNHUXP.js.map → chunk-P4QNEXFC.js.map} +0 -0
package/dist/agent.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as _tangle_network_agent_eval from '@tangle-network/agent-eval';
2
2
  import { TraceAnalystKindSpec, AnalystFinding } from '@tangle-network/agent-eval';
3
- import { R as RuntimeStreamEvent, S as SandboxClient, O as OutputAdapter, A as AgentRunSpec } from './types-BEQsBhOE.js';
3
+ import { R as RuntimeStreamEvent, S as SandboxClient, O as OutputAdapter, A as AgentRunSpec } from './types-CklkW4Eh.js';
4
4
  import { A as AgentSurfaces } from './improvement-adapter-BC4HhuAR.js';
5
5
  export { C as CreateSurfaceImprovementAdapterOpts, D as DraftPatchInput, a as DraftPatchOutput, R as ResolvedSurface, S as SurfaceImprovementEdit, b as SurfaceValidationIssue, c as createSurfaceImprovementAdapter, r as renderSurfaceIssues, d as resolveSubjectPath, v as validateSurfaces } from './improvement-adapter-BC4HhuAR.js';
6
6
  import { K as KnowledgeAdapter, a as RunAnalystLoopResult } from './types-p8dWBIXL.js';
7
7
  import { AgentProfile, SandboxEvent } from '@tangle-network/sandbox';
8
- import { C as ComposeProductionAgentProfileOptions } from './delegation-profile-1GbW5yA3.js';
8
+ import { C as ComposeProductionAgentProfileOptions } from './delegation-profile-Bvfro2m1.js';
9
9
  import './runtime-hooks-C7JwKb9E.js';
10
10
 
11
11
  /**
package/dist/agent.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  composeProductionAgentProfile
3
- } from "./chunk-7JITYN6T.js";
3
+ } from "./chunk-JFIYKDXF.js";
4
4
  import {
5
5
  createSandboxForSpec
6
- } from "./chunk-FQH33M5N.js";
6
+ } from "./chunk-K6WP7PYW.js";
7
7
  import {
8
8
  mapSandboxEvent
9
9
  } from "./chunk-GSUO5QS6.js";
@@ -1,5 +1,5 @@
1
1
  import { TraceAnalystByteBudgets, TraceAnalysisStore } from '@tangle-network/agent-eval';
2
- import { I as Iteration } from './types-BEQsBhOE.js';
2
+ import { I as Iteration } from './types-CklkW4Eh.js';
3
3
  import { R as RunAnalystLoopOpts, a as RunAnalystLoopResult } from './types-p8dWBIXL.js';
4
4
  export { A as AnalystLoopEvent, b as AnalystRegistryLike, c as AnalystRegistryStreamingLike, d as AutoApplyPolicy, F as FindingsStoreLike, I as ImprovementAdapter, e as ImprovementEditBatch, f as ImprovementReport, K as KnowledgeAdapter, g as KnowledgeProposalBatch, h as KnowledgeReport } from './types-p8dWBIXL.js';
5
5
  import '@tangle-network/sandbox';
@@ -25,11 +25,11 @@ import {
25
25
  createDelegationHistoryHandler,
26
26
  createDelegationStatusHandler,
27
27
  hashIdempotencyInput
28
- } from "./chunk-47SWANFA.js";
28
+ } from "./chunk-FO4DCM7R.js";
29
29
  import {
30
30
  createFleetWorkspaceExecutor,
31
31
  createSiblingSandboxExecutor
32
- } from "./chunk-HYG4ISNS.js";
32
+ } from "./chunk-AYRQZRDV.js";
33
33
  import {
34
34
  runLocalHarness
35
35
  } from "./chunk-GLR25NG7.js";
@@ -905,4 +905,4 @@ export {
905
905
  createPropagatingTraceEmitter,
906
906
  traceContextToEnv
907
907
  };
908
- //# sourceMappingURL=chunk-HAA4KZUD.js.map
908
+ //# sourceMappingURL=chunk-5M2WDWBI.js.map
@@ -12,7 +12,7 @@ import {
12
12
  sleep,
13
13
  throwAbort,
14
14
  throwIfAborted
15
- } from "./chunk-FQH33M5N.js";
15
+ } from "./chunk-K6WP7PYW.js";
16
16
  import {
17
17
  ValidationError
18
18
  } from "./chunk-GSUO5QS6.js";
@@ -620,4 +620,4 @@ export {
620
620
  coderTaskFromArgs,
621
621
  settleDetachedCoderTurn
622
622
  };
623
- //# sourceMappingURL=chunk-HYG4ISNS.js.map
623
+ //# sourceMappingURL=chunk-AYRQZRDV.js.map
@@ -3,7 +3,7 @@ import {
3
3
  createDelegationTraceCollector,
4
4
  formatDetachedSessionRef,
5
5
  generateDelegationSpanId
6
- } from "./chunk-HYG4ISNS.js";
6
+ } from "./chunk-AYRQZRDV.js";
7
7
  import {
8
8
  AgentEvalError,
9
9
  NotFoundError,
@@ -1353,4 +1353,4 @@ export {
1353
1353
  validateDelegationStatusArgs,
1354
1354
  createDelegationStatusHandler
1355
1355
  };
1356
- //# sourceMappingURL=chunk-47SWANFA.js.map
1356
+ //# sourceMappingURL=chunk-FO4DCM7R.js.map
@@ -48,14 +48,21 @@ function composeProductionAgentProfile(baseProfile, options = {}) {
48
48
  env: options.env
49
49
  });
50
50
  const baseMcp = baseProfile.mcp ?? {};
51
- const mergedMcp = delegationMcp ? { ...baseMcp, ...delegationMcp } : { ...baseMcp };
51
+ const withInjected = options.mcpConnections ? { ...baseMcp, ...options.mcpConnections } : { ...baseMcp };
52
+ const mergedMcp = delegationMcp ? { ...withInjected, ...delegationMcp } : withInjected;
52
53
  const baseFiles = baseProfile.resources?.files ?? [];
53
54
  const mergedFiles = options.extraFiles?.length ? [...baseFiles, ...options.extraFiles] : [...baseFiles];
54
55
  const prompt = options.systemPrompt ? { ...baseProfile.prompt, systemPrompt: options.systemPrompt } : baseProfile.prompt;
56
+ const mergedTools = options.tools ? { ...baseProfile.tools ?? {}, ...options.tools } : baseProfile.tools;
57
+ const mergedHooks = mergeHooks(baseProfile.hooks, options.hooks);
58
+ const mergedSubagents = options.subagents ? { ...baseProfile.subagents ?? {}, ...options.subagents } : baseProfile.subagents;
55
59
  return {
56
60
  ...baseProfile,
57
61
  name: options.name ?? baseProfile.name,
58
62
  prompt,
63
+ ...mergedTools ? { tools: mergedTools } : {},
64
+ ...mergedHooks ? { hooks: mergedHooks } : {},
65
+ ...mergedSubagents ? { subagents: mergedSubagents } : {},
59
66
  mcp: mergedMcp,
60
67
  resources: {
61
68
  ...baseProfile.resources,
@@ -63,10 +70,18 @@ function composeProductionAgentProfile(baseProfile, options = {}) {
63
70
  }
64
71
  };
65
72
  }
73
+ function mergeHooks(base, overlay) {
74
+ if (!overlay) return base;
75
+ const merged = { ...base ?? {} };
76
+ for (const [event, commands] of Object.entries(overlay)) {
77
+ merged[event] = [...merged[event] ?? [], ...commands];
78
+ }
79
+ return merged;
80
+ }
66
81
 
67
82
  export {
68
83
  DELEGATION_MCP_SERVER_KEY,
69
84
  buildDelegationMcpServer,
70
85
  composeProductionAgentProfile
71
86
  };
72
- //# sourceMappingURL=chunk-7JITYN6T.js.map
87
+ //# sourceMappingURL=chunk-JFIYKDXF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp/delegation-profile.ts"],"sourcesContent":["/**\n * Production-profile composition for the agent-runtime delegation MCP.\n *\n * A product agent's sandbox loads the delegation tools (`delegate_code`,\n * `delegate_research`, `delegate_feedback`, `delegation_status`,\n * `delegation_history`) by mounting the `agent-runtime-mcp` stdio server as\n * an MCP entry in its `AgentProfile`. This module is the single composer for\n * that wiring, so every consumer — the fleet agents and agent-builder's\n * generated agents — shares one implementation instead of copying it.\n *\n * The load-bearing invariant: the delegation MCP entry is only ever emitted\n * when a sandbox API key is present. Without the key the kernel's\n * coder/researcher delegate cannot construct an authenticated sandbox client,\n * so we omit the entry rather than ship an MCP child that fails to\n * authenticate on startup. No static profile entry, ever.\n */\n\nimport type {\n AgentProfile,\n AgentProfileFileMount,\n AgentProfileMcpServer,\n AgentSubagentProfile,\n} from '@tangle-network/sandbox'\n\n/** One hook command entry. The SDK declares `AgentProfile.hooks` as\n * `Record<string, AgentProfileHookCommand[]>` but does not re-export the element\n * type from the package entry, so derive it from `AgentProfile` by indexed\n * access — the single source of truth, no drift from the SDK shape. */\ntype AgentProfileHookCommand = NonNullable<AgentProfile['hooks']>[string][number]\n\n/** MCP server key under which the agent-runtime delegation tools mount. */\nexport const DELEGATION_MCP_SERVER_KEY = 'agent-runtime-delegation'\n\n/**\n * Env vars forwarded into the delegation MCP child so its delegated\n * build/research loops export topology spans to the configured OTLP /\n * Tangle Intelligence sink. Each is forwarded only when present, so the\n * child is a no-op exporter until `OTEL_EXPORTER_OTLP_ENDPOINT` is set in the\n * parent env — never a hardcoded endpoint.\n */\nconst OTEL_FORWARD_KEYS = [\n 'OTEL_EXPORTER_OTLP_ENDPOINT',\n 'OTEL_EXPORTER_OTLP_HEADERS',\n 'TRACE_ID',\n 'PARENT_SPAN_ID',\n] as const\n\nconst DEFAULT_SANDBOX_BASE_URL = 'https://sandbox.tangle.tools'\n\nexport interface BuildDelegationMcpServerOptions {\n /** Sandbox API key forwarded as `TANGLE_API_KEY` to the MCP child. The\n * agent-runtime MCP bin reads `TANGLE_API_KEY` and passes it straight to\n * `new Sandbox({ apiKey })`. Defaults to `env.TANGLE_API_KEY`. */\n sandboxApiKey?: string\n /** Sandbox base URL forwarded as `SANDBOX_BASE_URL`. Defaults to\n * `env.SANDBOX_BASE_URL`, then `env.SANDBOX_API_URL`, then the public\n * sandbox endpoint. */\n sandboxBaseUrl?: string\n /** Environment source for key + OTEL resolution. Defaults to `process.env`;\n * injectable for tests and non-process callers. */\n env?: Record<string, string | undefined>\n}\n\n/**\n * Build the delegation MCP entry the sandbox-side agent loads on startup.\n * Returns `undefined` when no sandbox API key is resolvable — callers merge\n * the result into a profile's `mcp` map only when defined.\n */\nexport function buildDelegationMcpServer(\n options: BuildDelegationMcpServerOptions = {},\n): Record<string, AgentProfileMcpServer> | undefined {\n const env = options.env ?? process.env\n const sandboxApiKey = options.sandboxApiKey ?? env.TANGLE_API_KEY\n if (!sandboxApiKey) return undefined\n const baseUrl =\n options.sandboxBaseUrl ??\n env.SANDBOX_BASE_URL ??\n env.SANDBOX_API_URL ??\n DEFAULT_SANDBOX_BASE_URL\n\n const otelEnv: Record<string, string> = {}\n for (const key of OTEL_FORWARD_KEYS) {\n const value = env[key]\n if (value) otelEnv[key] = value\n }\n\n return {\n [DELEGATION_MCP_SERVER_KEY]: {\n transport: 'stdio',\n command: 'npx',\n args: ['-y', '@tangle-network/agent-runtime', 'mcp'],\n env: {\n TANGLE_API_KEY: sandboxApiKey,\n SANDBOX_BASE_URL: baseUrl,\n ...otelEnv,\n },\n enabled: true,\n metadata: {\n surface: 'delegation:dispatch',\n tools: [\n 'delegate_code',\n 'delegate_research',\n 'delegate_feedback',\n 'delegation_status',\n 'delegation_history',\n ],\n },\n },\n }\n}\n\nexport interface ComposeProductionAgentProfileOptions {\n /** Sandbox API key forwarded to the delegation MCP child. Defaults to\n * `env.TANGLE_API_KEY`. When unset, the delegation MCP entry is omitted. */\n sandboxApiKey?: string\n /** Sandbox base URL forwarded as `SANDBOX_BASE_URL` to the MCP child. */\n sandboxBaseUrl?: string\n /** Replace the base profile's system prompt. Used by per-turn calls that\n * swap in workspace-augmented prompts (board summary, learned style). */\n systemPrompt?: string\n /** Extra file mounts layered after the base profile's `resources.files`. */\n extraFiles?: AgentProfileFileMount[]\n /** Override the profile `name`. Defaults to the base profile's name. */\n name?: string\n /** Environment source for key + OTEL resolution. Defaults to `process.env`. */\n env?: Record<string, string | undefined>\n /** Box built-in tool ON/OFF flags merged over the base profile's `tools`\n * (overlay wins per key). The sandbox-seam mapping of a certified surface's\n * tool grants — `AgentProfile.tools` is `Record<string, boolean>` box flags,\n * so it carries grants, not arbitrary tool defs. */\n tools?: Record<string, boolean>\n /** Per-event hook commands merged over the base profile's `hooks`. An event\n * present in both has the extra commands appended after the base ones. */\n hooks?: Record<string, AgentProfileHookCommand[]>\n /** Subagent definitions merged over the base profile's `subagents` (overlay\n * wins per key). */\n subagents?: Record<string, AgentSubagentProfile>\n /** Resolved certified MCP connections injected into `AgentProfile.mcp` — the\n * sandbox-seam delivery of a `ResolvedSurface.mcpConnections`. Merged after\n * the base map and before the delegation entry, so a base/delegation key is\n * never silently shadowed by an injected one. */\n mcpConnections?: Record<string, AgentProfileMcpServer>\n}\n\n/**\n * Compose the production `AgentProfile`: the canonical base profile with the\n * delegation MCP merged into `mcp`. Used by every call site that boots a\n * sandbox or runs a chat turn through the sandbox path, and by eval wiring so\n * the scorecard profile hash reflects the actual production profile.\n *\n * Merge rules:\n * - `mcp`: base map preserved; `options.mcpConnections` (resolved certified\n * servers) merged over it; the delegation entry is appended last under\n * {@link DELEGATION_MCP_SERVER_KEY}, and omitted entirely when no sandbox\n * API key resolves.\n * - `tools`: base box-flags map preserved; `options.tools` overlaid per key.\n * - `hooks`: per event, base commands preserved; `options.hooks[event]`\n * appended after the base ones.\n * - `subagents`: base map preserved; `options.subagents` overlaid per key.\n * - `prompt.systemPrompt`: replaced when `options.systemPrompt` is set.\n * - `resources.files`: `options.extraFiles` concatenated after base files.\n * - `name`: replaced when `options.name` is set.\n */\nexport function composeProductionAgentProfile(\n baseProfile: AgentProfile,\n options: ComposeProductionAgentProfileOptions = {},\n): AgentProfile {\n const delegationMcp = buildDelegationMcpServer({\n sandboxApiKey: options.sandboxApiKey,\n sandboxBaseUrl: options.sandboxBaseUrl,\n env: options.env,\n })\n\n const baseMcp = baseProfile.mcp ?? {}\n const withInjected: Record<string, AgentProfileMcpServer> = options.mcpConnections\n ? { ...baseMcp, ...options.mcpConnections }\n : { ...baseMcp }\n const mergedMcp: Record<string, AgentProfileMcpServer> = delegationMcp\n ? { ...withInjected, ...delegationMcp }\n : withInjected\n\n const baseFiles = baseProfile.resources?.files ?? []\n const mergedFiles: AgentProfileFileMount[] = options.extraFiles?.length\n ? [...baseFiles, ...options.extraFiles]\n : [...baseFiles]\n\n const prompt = options.systemPrompt\n ? { ...baseProfile.prompt, systemPrompt: options.systemPrompt }\n : baseProfile.prompt\n\n const mergedTools = options.tools\n ? { ...(baseProfile.tools ?? {}), ...options.tools }\n : baseProfile.tools\n\n const mergedHooks = mergeHooks(baseProfile.hooks, options.hooks)\n\n const mergedSubagents = options.subagents\n ? { ...(baseProfile.subagents ?? {}), ...options.subagents }\n : baseProfile.subagents\n\n return {\n ...baseProfile,\n name: options.name ?? baseProfile.name,\n prompt,\n ...(mergedTools ? { tools: mergedTools } : {}),\n ...(mergedHooks ? { hooks: mergedHooks } : {}),\n ...(mergedSubagents ? { subagents: mergedSubagents } : {}),\n mcp: mergedMcp,\n resources: {\n ...baseProfile.resources,\n files: mergedFiles,\n },\n }\n}\n\n/** Merge per-event hook command lists: base commands first, overlay commands\n * appended after. Returns the base map unchanged when no overlay is given. */\nfunction mergeHooks(\n base: Record<string, AgentProfileHookCommand[]> | undefined,\n overlay: Record<string, AgentProfileHookCommand[]> | undefined,\n): Record<string, AgentProfileHookCommand[]> | undefined {\n if (!overlay) return base\n const merged: Record<string, AgentProfileHookCommand[]> = { ...(base ?? {}) }\n for (const [event, commands] of Object.entries(overlay)) {\n merged[event] = [...(merged[event] ?? []), ...commands]\n }\n return merged\n}\n"],"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
7
7
  import {
8
8
  runAnalystLoop
9
9
  } from "./chunk-HNUXAZIJ.js";
10
10
  import {
11
11
  createDriver,
12
12
  runLoop
13
- } from "./chunk-FQH33M5N.js";
13
+ } from "./chunk-K6WP7PYW.js";
14
14
  import {
15
15
  ConfigError
16
16
  } from "./chunk-GSUO5QS6.js";
@@ -200,4 +200,4 @@ export {
200
200
  runLoopRunnerCli,
201
201
  parseLoopRunnerArgv
202
202
  };
203
- //# sourceMappingURL=chunk-XEI7AIHU.js.map
203
+ //# sourceMappingURL=chunk-K5M3SHEU.js.map
@@ -710,6 +710,17 @@ function readAnalystFindings(settled) {
710
710
  }
711
711
  return out;
712
712
  }
713
+ function registryScopeAnalyst(registry, buildInputs) {
714
+ return {
715
+ async analyze(input) {
716
+ const projection = buildInputs(input);
717
+ const result = await registry.run(projection.runId, projection.inputs, projection.opts);
718
+ const findings = result.findings;
719
+ assertTraceDerivedFindings(findings);
720
+ return findings;
721
+ }
722
+ };
723
+ }
713
724
  function buildSteerContext(findings, settledSoFar) {
714
725
  assertTraceDerivedFindings(findings);
715
726
  const lastValidScore = observedBestScore(settledSoFar);
@@ -2691,6 +2702,7 @@ function loopUntil(seed, spec) {
2691
2702
  async act(task, scope) {
2692
2703
  let state = { round: 0, value: seed };
2693
2704
  const blockers = [];
2705
+ const settledSoFar = [];
2694
2706
  for (; ; ) {
2695
2707
  const label = spec.label ? spec.label(state.round) : `step:${state.round}`;
2696
2708
  const child = ctx.spawnChild(label, ctx.persona.root);
@@ -2704,8 +2716,10 @@ function loopUntil(seed, spec) {
2704
2716
  }
2705
2717
  const settled = await drainOne(scope, label);
2706
2718
  if (settled.kind === "down") blockers.push(blockerFromDown(settled));
2719
+ settledSoFar.push(settled);
2707
2720
  state = spec.fold(state, settled);
2708
- const reached = spec.until(state, []);
2721
+ const findings = ctx.analyst ? await ctx.analyst.analyze({ task, settledSoFar, nodeId: scope.view.root }) : [];
2722
+ const reached = spec.until(state, findings);
2709
2723
  if (reached) return reached;
2710
2724
  state = { round: state.round + 1, value: state.value };
2711
2725
  }
@@ -2817,7 +2831,12 @@ function widen(spec) {
2817
2831
  let widenIndex = 0;
2818
2832
  for (let s = await scope.next(); s !== null; s = await scope.next()) {
2819
2833
  gathered.push(s);
2820
- const decision = spec.gate.decide(s, [], scope.budget);
2834
+ const findings = ctx.analyst ? await ctx.analyst.analyze({
2835
+ task: _task,
2836
+ settledSoFar: gathered,
2837
+ nodeId: scope.view.root
2838
+ }) : [];
2839
+ const decision = spec.gate.decide(s, findings, scope.budget);
2821
2840
  if (decision.kind !== "widen") continue;
2822
2841
  const label = `widen:${widenIndex}`;
2823
2842
  widenIndex += 1;
@@ -3175,7 +3194,8 @@ async function routerChatWithTools(cfg, messages, tools, opts) {
3175
3194
  messages,
3176
3195
  tools,
3177
3196
  tool_choice: opts?.toolChoice ?? "auto",
3178
- temperature: opts?.temperature ?? 0.3
3197
+ temperature: opts?.temperature ?? 0.3,
3198
+ ...opts?.maxTokens ? { max_tokens: opts.maxTokens } : {}
3179
3199
  }),
3180
3200
  ...opts?.signal ? { signal: opts.signal } : {}
3181
3201
  });
@@ -3199,7 +3219,7 @@ async function routerChatWithTools(cfg, messages, tools, opts) {
3199
3219
  }
3200
3220
  async function routerToolLoop(cfg, system, user, tools, execute, opts) {
3201
3221
  const maxTurns = opts?.maxTurns ?? 4;
3202
- const messages = [
3222
+ const messages = opts?.initialMessages ? [...opts.initialMessages] : [
3203
3223
  { role: "system", content: system },
3204
3224
  { role: "user", content: user }
3205
3225
  ];
@@ -3210,6 +3230,7 @@ async function routerToolLoop(cfg, system, user, tools, execute, opts) {
3210
3230
  for (let turn = 1; turn <= maxTurns; turn += 1) {
3211
3231
  const r = await routerChatWithTools(cfg, messages, tools, {
3212
3232
  ...opts?.temperature !== void 0 ? { temperature: opts.temperature } : {},
3233
+ ...opts?.maxTokens ? { maxTokens: opts.maxTokens } : {},
3213
3234
  ...opts?.signal ? { signal: opts.signal } : {}
3214
3235
  });
3215
3236
  if (r.usage) {
@@ -3218,7 +3239,7 @@ async function routerToolLoop(cfg, system, user, tools, execute, opts) {
3218
3239
  }
3219
3240
  if (r.content) lastText = r.content;
3220
3241
  if (r.toolCalls.length === 0)
3221
- return { final: lastText, turns: turn, toolCalls, toolTrace, usage };
3242
+ return { final: lastText, turns: turn, toolCalls, toolTrace, usage, messages };
3222
3243
  messages.push({
3223
3244
  role: "assistant",
3224
3245
  content: r.content ?? "",
@@ -3246,7 +3267,7 @@ async function routerToolLoop(cfg, system, user, tools, execute, opts) {
3246
3267
  toolTrace.push({ name: tc.name, args: tc.arguments, result: out });
3247
3268
  }
3248
3269
  }
3249
- return { final: lastText, turns: maxTurns, toolCalls, toolTrace, usage };
3270
+ return { final: lastText, turns: maxTurns, toolCalls, toolTrace, usage, messages };
3250
3271
  }
3251
3272
 
3252
3273
  // src/runtime/supervise/runtime.ts
@@ -4215,10 +4236,11 @@ function definePersona(input) {
4215
4236
  ...input.extensions ? { extensions: input.extensions } : {}
4216
4237
  });
4217
4238
  }
4218
- function createShapeContext(persona, budget) {
4239
+ function createShapeContext(persona, budget, analyst) {
4219
4240
  return {
4220
4241
  persona,
4221
4242
  budget,
4243
+ ...analyst ? { analyst } : {},
4222
4244
  spawnChild(name, spec) {
4223
4245
  const agent = {
4224
4246
  name,
@@ -4244,7 +4266,7 @@ async function runPersonified(options) {
4244
4266
  const { persona } = options;
4245
4267
  const shape = resolveShape(options.shape);
4246
4268
  const shapeBudget = resolveShapeBudget(options.budget, options.shapeBudget);
4247
- const ctx = createShapeContext(persona, shapeBudget);
4269
+ const ctx = createShapeContext(persona, shapeBudget, options.analyst);
4248
4270
  const rootAgent = shape(ctx);
4249
4271
  const executors = personaRegistry(persona);
4250
4272
  const supervisor = createSupervisor();
@@ -4259,7 +4281,8 @@ async function runPersonified(options) {
4259
4281
  ...options.maxRestarts !== void 0 ? { maxRestarts: options.maxRestarts } : {},
4260
4282
  ...options.withinMs !== void 0 ? { withinMs: options.withinMs } : {},
4261
4283
  ...options.now ? { now: options.now } : {},
4262
- ...options.signal ? { signal: options.signal } : {}
4284
+ ...options.signal ? { signal: options.signal } : {},
4285
+ ...options.hooks ? { hooks: options.hooks } : {}
4263
4286
  };
4264
4287
  return supervisor.run(rootAgent, options.task, supervisorOpts);
4265
4288
  }
@@ -4662,59 +4685,41 @@ import { pairedBootstrap, paretoFrontier } from "@tangle-network/agent-eval";
4662
4685
  import { createChatClient, estimateCost as estimateCost3, isModelPriced as isModelPriced3 } from "@tangle-network/agent-eval";
4663
4686
  var taskNudge = "Use the available tools to bring the artifact to the required final state. Address EVERY distinct change the request implies. After each tool result, check what remains and continue. Re-read the values you set to confirm they took. Reply DONE only once every required change is made and verified.";
4664
4687
  async function runShot(surface, _task, handle, tools, messages, opts, modelOverride) {
4665
- const innerTurns = opts.innerTurns ?? 4;
4666
- let completions = 0;
4667
- let toolCalls = 0;
4668
4688
  let toolErrors = 0;
4669
- const tokens = { input: 0, output: 0 };
4670
- for (let t = 0; t < innerTurns; t += 1) {
4671
- const res = await fetch(`${opts.routerBaseUrl.replace(/\/$/, "")}/chat/completions`, {
4672
- method: "POST",
4673
- headers: { "content-type": "application/json", authorization: `Bearer ${opts.routerKey}` },
4674
- body: JSON.stringify({
4675
- model: modelOverride ?? opts.model,
4676
- messages,
4677
- tools,
4678
- tool_choice: "auto",
4679
- temperature: opts.temperature ?? 0.7,
4680
- ...opts.maxTokens ? { max_tokens: opts.maxTokens } : {}
4681
- })
4682
- });
4683
- if (!res.ok) throw new Error(`router ${res.status}: ${(await res.text()).slice(0, 200)}`);
4684
- completions += 1;
4685
- const data = await res.json();
4686
- if (typeof data.usage?.prompt_tokens === "number") tokens.input += data.usage.prompt_tokens;
4687
- if (typeof data.usage?.completion_tokens === "number")
4688
- tokens.output += data.usage.completion_tokens;
4689
- const msg = data.choices?.[0]?.message;
4690
- if (!msg) break;
4691
- const calls = msg.tool_calls ?? [];
4692
- messages.push({
4693
- role: "assistant",
4694
- content: msg.content ?? "",
4695
- ...calls.length ? { tool_calls: calls } : {}
4696
- });
4697
- if (calls.length === 0) break;
4698
- for (const call of calls) {
4699
- toolCalls += 1;
4700
- let args = {};
4701
- try {
4702
- args = JSON.parse(call.function.arguments || "{}");
4703
- } catch {
4704
- toolErrors += 1;
4705
- }
4706
- let out;
4707
- try {
4708
- out = await surface.call(handle, call.function.name, args);
4709
- if (out.startsWith("ERROR:")) toolErrors += 1;
4710
- } catch (e) {
4711
- toolErrors += 1;
4712
- out = `ERROR: ${e instanceof Error ? e.message : String(e)}`;
4713
- }
4714
- messages.push({ role: "tool", tool_call_id: call.id, content: out });
4689
+ const execute = async (name, args) => {
4690
+ try {
4691
+ const out = await surface.call(handle, name, args);
4692
+ if (out.startsWith("ERROR:")) toolErrors += 1;
4693
+ return out;
4694
+ } catch (e) {
4695
+ toolErrors += 1;
4696
+ return `ERROR: ${e instanceof Error ? e.message : String(e)}`;
4715
4697
  }
4716
- }
4717
- return { messages, completions, toolCalls, toolErrors, tokens };
4698
+ };
4699
+ const r = await routerToolLoop(
4700
+ {
4701
+ routerBaseUrl: opts.routerBaseUrl,
4702
+ routerKey: opts.routerKey,
4703
+ model: modelOverride ?? opts.model
4704
+ },
4705
+ "",
4706
+ "",
4707
+ tools,
4708
+ execute,
4709
+ {
4710
+ maxTurns: opts.innerTurns ?? 4,
4711
+ temperature: opts.temperature ?? 0.7,
4712
+ initialMessages: messages,
4713
+ ...opts.maxTokens ? { maxTokens: opts.maxTokens } : {}
4714
+ }
4715
+ );
4716
+ return {
4717
+ messages: r.messages,
4718
+ completions: r.turns,
4719
+ toolCalls: r.toolCalls,
4720
+ toolErrors,
4721
+ tokens: r.usage
4722
+ };
4718
4723
  }
4719
4724
  function compactTrajectory(messages) {
4720
4725
  return messages.filter((m) => m.role === "assistant" || m.role === "tool").map((m) => {
@@ -6453,6 +6458,7 @@ export {
6453
6458
  deterministicCompletion,
6454
6459
  assertTraceDerivedFindings,
6455
6460
  createScopeAnalyst,
6461
+ registryScopeAnalyst,
6456
6462
  buildSteerContext,
6457
6463
  createDriver,
6458
6464
  renderAnalyses,
@@ -6528,4 +6534,4 @@ export {
6528
6534
  gitWorkspace,
6529
6535
  jjWorkspace
6530
6536
  };
6531
- //# sourceMappingURL=chunk-FQH33M5N.js.map
6537
+ //# sourceMappingURL=chunk-K6WP7PYW.js.map