@tangle-network/agent-runtime 0.199.0 → 0.200.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 (61) hide show
  1. package/dist/{activation-c3um4SY1.d.ts → activation-BPxs-Iu2.d.ts} +2 -2
  2. package/dist/{activation-zQWmiiPg.js → activation-Ct-BTTzF.js} +2 -2
  3. package/dist/{activation-zQWmiiPg.js.map → activation-Ct-BTTzF.js.map} +1 -1
  4. package/dist/agent.d.ts +1 -1
  5. package/dist/agent.js +2 -3
  6. package/dist/agent.js.map +1 -1
  7. package/dist/analyst-loop-DZw5QWT9.js +176 -0
  8. package/dist/analyst-loop-DZw5QWT9.js.map +1 -0
  9. package/dist/analyst-loop.d.ts +1 -11
  10. package/dist/analyst-loop.js +2 -2
  11. package/dist/{coordination-driver-vWb7kViA.js → coordination-driver-qdAwriPV.js} +8 -5
  12. package/dist/{coordination-driver-vWb7kViA.js.map → coordination-driver-qdAwriPV.js.map} +1 -1
  13. package/dist/{delegate-Ch93bpH5.js → delegate-BWHG-zZW.js} +2 -2
  14. package/dist/{delegate-Ch93bpH5.js.map → delegate-BWHG-zZW.js.map} +1 -1
  15. package/dist/durable.d.ts +2 -2
  16. package/dist/durable.js +2 -2
  17. package/dist/{graph-C6pT08K-.js → graph-cCqKhLqz.js} +3 -3
  18. package/dist/{graph-C6pT08K-.js.map → graph-cCqKhLqz.js.map} +1 -1
  19. package/dist/{improvement-cycle-CxZKIbLD.js → improvement-cycle-yia1ST3c.js} +4 -4
  20. package/dist/{improvement-cycle-CxZKIbLD.js.map → improvement-cycle-yia1ST3c.js.map} +1 -1
  21. package/dist/{index-CMTUgh-T.d.ts → index-Br191WbE.d.ts} +190 -142
  22. package/dist/index.d.ts +4 -4
  23. package/dist/index.js +20 -46
  24. package/dist/index.js.map +1 -1
  25. package/dist/intelligence.d.ts +13 -104
  26. package/dist/intelligence.js +7 -406
  27. package/dist/intelligence.js.map +1 -1
  28. package/dist/kernel.d.ts +3 -3
  29. package/dist/kernel.js +8 -9
  30. package/dist/{loop-runner-bin-CAf1OQot.d.ts → loop-runner-bin-BNRdsDOn.d.ts} +3 -3
  31. package/dist/{loop-runner-bin-SNrh585k.js → loop-runner-bin-jQ8hXO9J.js} +4 -4
  32. package/dist/{loop-runner-bin-SNrh585k.js.map → loop-runner-bin-jQ8hXO9J.js.map} +1 -1
  33. package/dist/loop-runner-bin.d.ts +1 -1
  34. package/dist/loop-runner-bin.js +1 -1
  35. package/dist/mcp/bin.js +3 -3
  36. package/dist/mcp/index.d.ts +2 -2
  37. package/dist/mcp/index.js +4 -4
  38. package/dist/{provision-supervisor-D5YSCDVD.js → provision-supervisor-BA2-GPth.js} +3 -3
  39. package/dist/{provision-supervisor-D5YSCDVD.js.map → provision-supervisor-BA2-GPth.js.map} +1 -1
  40. package/dist/{redact-Dv8WcCKy.js → redact-h-oaw11Q.js} +13093 -11221
  41. package/dist/redact-h-oaw11Q.js.map +1 -0
  42. package/dist/{runtime-BN16GbTA.js → runtime-DeqdBVeC.js} +8 -9
  43. package/dist/{runtime-BN16GbTA.js.map → runtime-DeqdBVeC.js.map} +1 -1
  44. package/dist/{server-CbNb_N1x.js → server-U_k9NUbk.js} +3 -3
  45. package/dist/{server-CbNb_N1x.js.map → server-U_k9NUbk.js.map} +1 -1
  46. package/dist/{stream-agent-turn-CLOQr497.d.ts → stream-agent-turn-CJWthifS.d.ts} +42 -13
  47. package/dist/{structural-rollout-DANCelu6.js → structural-rollout-BcMmrpv4.js} +2 -3
  48. package/dist/{structural-rollout-DANCelu6.js.map → structural-rollout-BcMmrpv4.js.map} +1 -1
  49. package/dist/{supervise-BGNXB8No.js → supervise-DmFO50N6.js} +497 -90
  50. package/dist/supervise-DmFO50N6.js.map +1 -0
  51. package/dist/testing.d.ts +2 -2
  52. package/dist/testing.js +12 -12
  53. package/dist/tui/index.d.ts +1 -1
  54. package/dist/tui/index.js +1 -1
  55. package/package.json +3 -3
  56. package/dist/analyst-loop-BknOQUW5.js +0 -546
  57. package/dist/analyst-loop-BknOQUW5.js.map +0 -1
  58. package/dist/redact-Dv8WcCKy.js.map +0 -1
  59. package/dist/sandbox-events-DbC2WKKS.js +0 -929
  60. package/dist/sandbox-events-DbC2WKKS.js.map +0 -1
  61. package/dist/supervise-BGNXB8No.js.map +0 -1
@@ -1,10 +1,10 @@
1
- import { Gn as createOtelExporter, Un as buildRuntimeEventOtelSpans, Vn as buildLoopOtelSpans, mn as resolveAgentEnvironmentProvider, qn as flatOtelSpan, r as resolveRedactor, t as defaultRedactor } from "./redact-Dv8WcCKy.js";
2
- import { C as optimizationActivationReceiptFromMetadata, D as agentImprovementProfileSurfaceDigest, E as agentImprovementProfileDiffs, F as isAgentImprovementProfileSurface, I as isAgentProfileMeasuredSurface, N as assertProfileImprovementTargetsShareIdentity, O as agentImprovementProfileSurfaceInput, P as buildAgentImprovementActivationTargets, S as createOptimizationActivationReceipt, T as AGENT_PROFILE_MEASURED_SURFACES, _ as profilePolicyWithBudget, a as executeAgentCandidateExperimentCell, b as profileTaskScenarioIdentity, d as verifyAgentImprovementActivation, f as verifyAgentImprovementProposal, g as profileImprovementMetadata, h as createProfileImprovementCostLedger, i as createAgentImprovementProposal, j as agentImprovementTargetProfileDiffs, l as reviewAgentImprovementProposal, m as verifyCandidateExecutionEvidence, n as createAgentImprovementActivation, o as proposeAgentImprovement, p as verifyAgentImprovementReview, r as createAgentImprovementMeasuredComparison, s as proposeAgentProfileImprovement, t as AgentCandidateExperimentCellExecutionError, u as runAgentCandidateExperiment, v as profilePreparationAccounting, w as AGENT_IMPROVEMENT_PROFILE_SURFACES, x as sealProfileImprovementBenchmark, y as profileStateDigest$1 } from "./improvement-cycle-CxZKIbLD.js";
1
+ import { $n as buildRuntimeEventOtelSpans, Zn as buildLoopOtelSpans, _n as resolveAgentEnvironmentProvider, r as resolveRedactor, rr as flatOtelSpan, t as defaultRedactor, tr as createOtelExporter } from "./redact-h-oaw11Q.js";
2
+ import { C as optimizationActivationReceiptFromMetadata, D as agentImprovementProfileSurfaceDigest, E as agentImprovementProfileDiffs, F as isAgentImprovementProfileSurface, I as isAgentProfileMeasuredSurface, N as assertProfileImprovementTargetsShareIdentity, O as agentImprovementProfileSurfaceInput, P as buildAgentImprovementActivationTargets, S as createOptimizationActivationReceipt, T as AGENT_PROFILE_MEASURED_SURFACES, _ as profilePolicyWithBudget, a as executeAgentCandidateExperimentCell, b as profileTaskScenarioIdentity, d as verifyAgentImprovementActivation, f as verifyAgentImprovementProposal, g as profileImprovementMetadata, h as createProfileImprovementCostLedger, i as createAgentImprovementProposal, j as agentImprovementTargetProfileDiffs, l as reviewAgentImprovementProposal, m as verifyCandidateExecutionEvidence, n as createAgentImprovementActivation, o as proposeAgentImprovement, p as verifyAgentImprovementReview, r as createAgentImprovementMeasuredComparison, s as proposeAgentProfileImprovement, t as AgentCandidateExperimentCellExecutionError, u as runAgentCandidateExperiment, v as profilePreparationAccounting, w as AGENT_IMPROVEMENT_PROFILE_SURFACES, x as sealProfileImprovementBenchmark, y as profileStateDigest$1 } from "./improvement-cycle-yia1ST3c.js";
3
3
  import { o as canonicalCandidateDigest$1, u as immutableCandidateValue } from "./protected-redaction-wGo44k2K.js";
4
4
  import { A as omitUndefinedObjectFields, M as parseExactAgentProfile, a as AGENT_CANDIDATE_EXECUTION_SUPPORT, j as parseAgentCandidateProfileActivation, w as applyExactAgentProfileDiff } from "./prepare-CAO1yXov.js";
5
- import { n as executeAgentImprovementActivation, r as verifyAgentImprovementActivationResult, t as createAgentImprovementActivationResult } from "./activation-zQWmiiPg.js";
5
+ import { n as executeAgentImprovementActivation, r as verifyAgentImprovementActivationResult, t as createAgentImprovementActivationResult } from "./activation-Ct-BTTzF.js";
6
6
  import { n as exactProcessProviderAsCandidateExecutor, t as createProtectedAgentCandidateModelPort } from "./protected-model-port-B5avcRiQ.js";
7
- import { agentImprovementSourceSchema, agentProfileImprovementArmSchema, applyAgentProfileDiff, defineAgentProfilePublicConfig } from "@tangle-network/agent-interface";
7
+ import { agentImprovementSourceSchema, agentProfileImprovementArmSchema, applyAgentProfileDiff } from "@tangle-network/agent-interface";
8
8
  import { contentHash } from "@tangle-network/agent-eval";
9
9
  import { assertProposalFindings } from "@tangle-network/agent-eval/analyst";
10
10
  import { measuredComparisonFromAgentProfileImprovementExperiment, runAgentProfileImprovementExperiment, sealAgentProfileImprovementExperiment, verifyAgentProfileImprovementExperimentComparison } from "@tangle-network/agent-eval/contract";
@@ -475,10 +475,7 @@ function assertDirectCandidateReleaseWorkIsFresh(benchmark, lineage, development
475
475
  //#endregion
476
476
  //#region src/intelligence/capability.ts
477
477
  /**
478
- * A binding kind whose resolver case is typed but not yet admitted (rag-index,
479
- * memory-store, wasm, a2a). Thrown by the resolver — NEVER faked into a working
480
- * surface. The TYPE arms exist so the union is closed against the spec; the
481
- * resolver grows them later behind their lifecycle + admission gate.
478
+ * A consumer rejected a binding that its executor does not admit.
482
479
  */
483
480
  var CapabilityNotAdmittedError = class extends Error {
484
481
  kind;
@@ -602,7 +599,7 @@ function inferCapability(type, a) {
602
599
  * `prompt-surface`/`skill` artifacts → `context`/inline capabilities (the
603
600
  * shipped fold, generalized); any other artifact type → best-effort binding
604
601
  * inference. `promptSurface` is carried through so
605
- * the resolver folds it first, exactly as `composeCertifiedPrompt` does today.
602
+ * `composeCertifiedPrompt` folds it before other prompt artifacts.
606
603
  * This delivers the spine against today's wire before the plane changes.
607
604
  */
608
605
  function manifestFromProfile(profile) {
@@ -886,402 +883,6 @@ function assertUniqueProfileTargets(targets) {
886
883
  if (new Set(targetKeys).size !== targetKeys.length) throw new Error("agent profile activation repeats a target");
887
884
  }
888
885
  //#endregion
889
- //#region src/intelligence/resolver.ts
890
- /**
891
- *
892
- * The capability resolver — the ONLY place that knows binding kinds. It lowers a
893
- * `CapabilityManifest` into a uniform `ResolvedSurface` consumed identically by
894
- * the in-process seam (`RouterToolsSeam.{tools, executeToolCall}` + a folded
895
- * prompt) and the sandbox seam (`AgentProfile`).
896
- *
897
- * The spine (zero new infra) resolves inline/file, mcp-stdio/mcp-remote, and
898
- * http tools for BOTH seams, reusing shipped primitives:
899
- * - inline/context → `composeCertifiedPrompt` (delivery.ts) — byte-stable order;
900
- * - http → a `ToolSpec` + a host-side fetch `execute`;
901
- * - mcp-stdio/remote → an `AgentProfileMcpServer` (the strict union widens to
902
- * the SDK's flat shape — an always-valid lowering).
903
- *
904
- * The ladder rungs that need infra are INJECTED capabilities of the resolve
905
- * context (`runSandboxCode`, `provisionHost`), so the substrate-free caller wires
906
- * only what it can host — a binding that needs an absent provider throws loudly,
907
- * it is NEVER faked into a working surface. The not-yet-admitted arms (rag-index,
908
- * memory-store, wasm, a2a) throw {@link CapabilityNotAdmittedError}.
909
- *
910
- * Fail-closed by construction (mirroring `pullCertified`): a `null` manifest
911
- * returns the base surface only; a per-capability resolve failure DROPS that
912
- * capability (never a half-wired tool); a post-resolve drift check drops any tool
913
- * whose live names diverge from the certified interface.
914
- *
915
- * @stable
916
- */
917
- function emptyAccumulator() {
918
- return {
919
- tools: [],
920
- executors: /* @__PURE__ */ new Map(),
921
- mcpConnections: {},
922
- contextArtifacts: {},
923
- files: [],
924
- retrieval: [],
925
- hooks: [],
926
- subagents: [],
927
- teardowns: [],
928
- toolCapabilityId: /* @__PURE__ */ new Map(),
929
- mcpCapability: /* @__PURE__ */ new Map()
930
- };
931
- }
932
- /**
933
- * Compose a certified profile into a uniform `ResolvedSurface`. Additive over
934
- * `composeCertifiedPrompt`: the inline/context fold is delegated to
935
- * `composeCertifiedPrompt` so the byte-stable ordering (prompt surface first,
936
- * then type alphabetic, then path locale-compare) is reused EXACTLY — the
937
- * prompt-only path is a strict subset of this.
938
- *
939
- * Fail-closed: a `null` manifest returns the base surface only.
940
- */
941
- async function composeCertifiedProfile(base, manifest, ctx = {}) {
942
- if (!manifest || manifest.capabilities.length === 0) return baseSurface(base.systemPrompt, manifest?.promptSurface ?? null);
943
- const acc = emptyAccumulator();
944
- for (const cap of manifest.capabilities) try {
945
- await resolveCapability(cap, ctx, acc);
946
- } catch (err) {
947
- if (err instanceof CapabilityNotAdmittedError) throw err;
948
- ctx.onDrop?.(cap.id, err instanceof Error ? err : new Error(String(err)));
949
- }
950
- await driftDropTools(acc, ctx);
951
- const promptAdditions = collectPromptAdditions(manifest.promptSurface, acc.contextArtifacts);
952
- const systemPrompt = composeCertifiedPrompt(base.systemPrompt, {
953
- promptSurface: manifest.promptSurface,
954
- artifacts: acc.contextArtifacts
955
- });
956
- const teardowns = acc.teardowns;
957
- return {
958
- tools: acc.tools,
959
- async execute(name, args, task) {
960
- const fn = acc.executors.get(name);
961
- if (!fn) throw new Error(`composeCertifiedProfile.execute: unknown tool '${name}'`);
962
- return fn(args, task);
963
- },
964
- mcpConnections: acc.mcpConnections,
965
- promptAdditions,
966
- files: acc.files,
967
- retrieval: acc.retrieval,
968
- hooks: acc.hooks,
969
- subagents: acc.subagents,
970
- systemPrompt,
971
- async dispose() {
972
- for (let i = teardowns.length - 1; i >= 0; i -= 1) {
973
- const teardown = teardowns[i];
974
- if (teardown) await teardown();
975
- }
976
- }
977
- };
978
- }
979
- function baseSurface(systemPrompt, promptSurface) {
980
- const folded = composeCertifiedPrompt(systemPrompt, {
981
- promptSurface,
982
- artifacts: {}
983
- });
984
- return {
985
- tools: [],
986
- async execute(name) {
987
- throw new Error(`composeCertifiedProfile.execute: unknown tool '${name}'`);
988
- },
989
- mcpConnections: {},
990
- promptAdditions: collectPromptAdditions(promptSurface, {}),
991
- files: [],
992
- retrieval: [],
993
- hooks: [],
994
- subagents: [],
995
- systemPrompt: folded,
996
- async dispose() {}
997
- };
998
- }
999
- /** The byte-stable prompt additions a viewer/debugger can inspect — the same
1000
- * parts `composeCertifiedPrompt` joins into the folded prompt, in the same fold
1001
- * order (`promptFoldTypes`). */
1002
- function collectPromptAdditions(promptSurface, contextArtifacts) {
1003
- const parts = [];
1004
- if (promptSurface?.surface.trim()) parts.push(promptSurface.surface.trim());
1005
- for (const type of promptFoldTypes) {
1006
- const bucket = contextArtifacts[type] ?? [];
1007
- for (const a of [...bucket].sort((x, y) => (x.path ?? "").localeCompare(y.path ?? ""))) if (a.content.trim()) parts.push(a.content.trim());
1008
- }
1009
- return parts;
1010
- }
1011
- async function resolveCapability(cap, ctx, acc) {
1012
- await resolveBinding(cap, cap.binding, ctx, acc);
1013
- }
1014
- async function resolveBinding(cap, binding, ctx, acc) {
1015
- switch (binding.kind) {
1016
- case "inline":
1017
- resolveInline(cap, binding, acc);
1018
- return;
1019
- case "file":
1020
- resolveFile(cap, binding, acc);
1021
- return;
1022
- case "http":
1023
- resolveHttp(cap, binding, ctx, acc);
1024
- return;
1025
- case "mcp-stdio":
1026
- case "mcp-remote":
1027
- resolveMcp(cap, binding, acc);
1028
- return;
1029
- case "sandbox-code":
1030
- resolveSandboxCode(cap, binding, ctx, acc);
1031
- return;
1032
- case "process-on-infra":
1033
- await resolveProcessOnInfra(cap, binding, ctx, acc, /* @__PURE__ */ new Set());
1034
- return;
1035
- case "rag-index": throw new CapabilityNotAdmittedError(binding.kind, cap.id, "rag retrieval lift must clear the E3 score-superiority admission bar before a store is trusted (memory/e3-certified-memory-verdict)");
1036
- case "memory-store": throw new CapabilityNotAdmittedError(binding.kind, cap.id, "memory-store admission is gated on the E3 score-superiority bar (memory/e3-certified-memory-verdict)");
1037
- case "wasm": throw new CapabilityNotAdmittedError(binding.kind, cap.id, "wasm is an extension-point arm, not yet admitted");
1038
- case "a2a": throw new CapabilityNotAdmittedError(binding.kind, cap.id, "a2a is an extension-point arm, not yet admitted");
1039
- }
1040
- }
1041
- /** inline → a context artifact (prompt-surface/skill folded) or an inline tool
1042
- * def. Context capabilities feed the byte-stable prompt fold; an inline `tool`
1043
- * interface registers a host-side tool whose body is the inlined JSON spec. */
1044
- function resolveInline(cap, binding, acc) {
1045
- const content = inlineContent(cap, binding.content);
1046
- if (cap.iface.surface === "context") {
1047
- pushContextArtifact(acc, cap, content);
1048
- return;
1049
- }
1050
- if (cap.iface.surface === "tool") {
1051
- registerInlineTool(cap, content, acc);
1052
- return;
1053
- }
1054
- pushContextArtifact(acc, cap, content);
1055
- }
1056
- /** An inline `tool` interface registers a host-side `ToolSpec` whose body is the
1057
- * static inlined content (a fixed response / canned handler). Its `execute`
1058
- * returns the content verbatim — the agent calls it like any other tool. */
1059
- function registerInlineTool(cap, content, acc) {
1060
- if (cap.iface.surface !== "tool") return;
1061
- const iface = cap.iface;
1062
- acc.tools.push({
1063
- type: "function",
1064
- function: {
1065
- name: iface.name,
1066
- ...iface.description ? { description: iface.description } : {},
1067
- parameters: iface.parameters
1068
- }
1069
- });
1070
- acc.toolCapabilityId.set(iface.name, cap.id);
1071
- acc.executors.set(iface.name, async () => content);
1072
- }
1073
- /** file → a workspace file mount (+ a prompt fold when the file is context). */
1074
- function resolveFile(cap, binding, acc) {
1075
- const content = inlineContent(cap, binding.content);
1076
- acc.files.push({
1077
- path: binding.path,
1078
- content,
1079
- ...binding.executable ? { executable: true } : {}
1080
- });
1081
- if (cap.iface.surface === "context") pushContextArtifact(acc, cap, content);
1082
- }
1083
- /** mcp-stdio/mcp-remote → an `AgentProfileMcpServer`. The strict discriminated
1084
- * union widens to the SDK's flat shape — an always-valid lowering, no translation. */
1085
- function resolveMcp(cap, binding, acc) {
1086
- const serverName = cap.iface.surface === "mcp" ? cap.iface.serverName : cap.id;
1087
- acc.mcpConnections[serverName] = mcpServerFromBinding(binding, cap);
1088
- acc.mcpCapability.set(serverName, {
1089
- capabilityId: cap.id,
1090
- certifiedNames: cap.iface.surface === "mcp" ? cap.iface.toolset ?? [] : []
1091
- });
1092
- }
1093
- function mcpServerFromBinding(binding, cap) {
1094
- const metadata = { capabilityId: cap.id };
1095
- if (cap.iface.surface === "mcp" && cap.iface.toolset) metadata.tools = cap.iface.toolset;
1096
- if (binding.kind === "mcp-stdio") return {
1097
- transport: "stdio",
1098
- command: binding.command,
1099
- ...binding.args ? { args: binding.args.map(defineAgentProfilePublicConfig) } : {},
1100
- ...binding.env ? { env: publicConfigRecord(binding.env) } : {},
1101
- ...binding.cwd ? { cwd: binding.cwd } : {},
1102
- enabled: true,
1103
- metadata
1104
- };
1105
- return {
1106
- transport: binding.transport,
1107
- url: binding.url,
1108
- ...binding.headers ? { headers: publicConfigRecord(binding.headers) } : {},
1109
- enabled: true,
1110
- metadata
1111
- };
1112
- }
1113
- function publicConfigRecord(values) {
1114
- return Object.fromEntries(Object.entries(values).map(([name, value]) => [name, defineAgentProfilePublicConfig(value)]));
1115
- }
1116
- /** http → a `ToolSpec` + a host-side fetch `execute`. THE host seam: an http
1117
- * tool is callable in-process, never injected into a sandbox profile. */
1118
- function resolveHttp(cap, binding, ctx, acc) {
1119
- if (cap.iface.surface !== "tool") throw new Error(`capability '${cap.id}': http binding requires a 'tool' interface`);
1120
- const iface = cap.iface;
1121
- acc.tools.push({
1122
- type: "function",
1123
- function: {
1124
- name: iface.name,
1125
- ...iface.description ? { description: iface.description } : {},
1126
- parameters: iface.parameters
1127
- }
1128
- });
1129
- acc.toolCapabilityId.set(iface.name, cap.id);
1130
- const method = binding.method ?? "POST";
1131
- const auth = binding.auth ?? cap.auth;
1132
- acc.executors.set(iface.name, async (args) => {
1133
- const doFetch = ctx.fetchImpl ?? globalThis.fetch;
1134
- if (!doFetch) throw new Error(`capability '${cap.id}': no fetch implementation for http tool`);
1135
- const headers = { "content-type": "application/json" };
1136
- if (auth.mode !== "none") {
1137
- if (!ctx.resolveSecret) throw new Error(`capability '${cap.id}': http auth '${auth.mode}' requires ResolveCtx.resolveSecret`);
1138
- const secret = await ctx.resolveSecret(auth, ctx.tenant);
1139
- if (!secret.succeeded) throw new Error(`capability '${cap.id}': secret resolution failed — ${secret.error}`);
1140
- headers.authorization = `Bearer ${secret.value}`;
1141
- }
1142
- const res = await doFetch(binding.url, {
1143
- method,
1144
- headers,
1145
- ...method === "GET" ? {} : { body: JSON.stringify(args) }
1146
- });
1147
- if (!res.ok) {
1148
- const body = await res.text().catch(() => "");
1149
- throw new Error(`capability '${cap.id}': http ${res.status}: ${body.slice(0, 200)}`);
1150
- }
1151
- return res.text();
1152
- });
1153
- }
1154
- /** sandbox-code → a host-side tool whose body runs per-call in a box, via the
1155
- * injected `runSandboxCode` (the host owns the sandbox client). */
1156
- function resolveSandboxCode(cap, binding, ctx, acc) {
1157
- if (cap.iface.surface !== "tool") throw new Error(`capability '${cap.id}': sandbox-code binding requires a 'tool' interface`);
1158
- const iface = cap.iface;
1159
- acc.tools.push({
1160
- type: "function",
1161
- function: {
1162
- name: iface.name,
1163
- ...iface.description ? { description: iface.description } : {},
1164
- parameters: iface.parameters
1165
- }
1166
- });
1167
- acc.toolCapabilityId.set(iface.name, cap.id);
1168
- acc.executors.set(iface.name, async (args, task) => {
1169
- if (!ctx.runSandboxCode) throw new Error(`capability '${cap.id}': sandbox-code binding requires ResolveCtx.runSandboxCode`);
1170
- return ctx.runSandboxCode(binding.code, binding.entry, args, task);
1171
- });
1172
- }
1173
- /**
1174
- * process-on-infra → provision the host FIRST (depth-first), then resolve the
1175
- * inner binding inside it. The injected `provisionHost` owns `createExecutor`;
1176
- * this resolver wires the returned connection + teardown (reverse dep order) and
1177
- * the cost tag. A `visited` set guards against a self-referential host cycle.
1178
- */
1179
- async function resolveProcessOnInfra(cap, binding, ctx, acc, visited) {
1180
- if (visited.has(binding)) throw new Error(`capability '${cap.id}': process-on-infra cycle detected`);
1181
- visited.add(binding);
1182
- if (!ctx.provisionHost) throw new Error(`capability '${cap.id}': process-on-infra binding requires ResolveCtx.provisionHost`);
1183
- if (binding.inner.kind === "process-on-infra") {
1184
- const outer = await ctx.provisionHost(binding.host, binding.inner, hostCostTag(cap, binding.host));
1185
- acc.teardowns.push(() => outer.teardown());
1186
- await resolveProcessOnInfra(cap, binding.inner, ctx, acc, visited);
1187
- return;
1188
- }
1189
- const provisioned = await ctx.provisionHost(binding.host, binding.inner, hostCostTag(cap, binding.host));
1190
- acc.teardowns.push(() => provisioned.teardown());
1191
- if (provisioned.mcpConnection) {
1192
- const serverName = cap.iface.surface === "mcp" ? cap.iface.serverName : cap.id;
1193
- acc.mcpConnections[serverName] = provisioned.mcpConnection;
1194
- acc.mcpCapability.set(serverName, {
1195
- capabilityId: cap.id,
1196
- certifiedNames: cap.iface.surface === "mcp" ? cap.iface.toolset ?? [] : []
1197
- });
1198
- }
1199
- }
1200
- function hostCostTag(cap, host) {
1201
- return host.costTag ?? `capability/${cap.id}`;
1202
- }
1203
- /**
1204
- * Post-resolve drift check (fail-closed): a resolved surface's LIVE tool names
1205
- * must equal the certified interface — mismatch → drop. The only callable tools
1206
- * are gate-blessed ones. Two enforcement layers:
1207
- * 1. host-side parity — every registered tool keeps a matching executor and
1208
- * vice-versa (a half-wired tool, e.g. one whose provision failed, is
1209
- * removed rather than exposed);
1210
- * 2. live-name equality (when `ctx.probeLiveToolNames` is wired) — for each
1211
- * host tool the live name must contain the certified name; for each mcp
1212
- * server the live `tools/list` must equal the certified `toolset`.
1213
- * A drop removes BOTH the tool spec and its executor (host) or the connection
1214
- * (mcp); a capability that lost its drift check never reaches the agent.
1215
- */
1216
- async function driftDropTools(acc, ctx) {
1217
- const specNames = new Set(acc.tools.map((t) => t.function.name));
1218
- for (const name of acc.executors.keys()) if (!specNames.has(name)) acc.executors.delete(name);
1219
- acc.tools = acc.tools.filter((t) => acc.executors.has(t.function.name));
1220
- if (!ctx.probeLiveToolNames) return;
1221
- const droppedTools = /* @__PURE__ */ new Set();
1222
- for (const tool of acc.tools) {
1223
- const capId = acc.toolCapabilityId.get(tool.function.name);
1224
- if (!capId) continue;
1225
- if (!(await ctx.probeLiveToolNames(capId)).includes(tool.function.name)) droppedTools.add(tool.function.name);
1226
- }
1227
- for (const name of droppedTools) acc.executors.delete(name);
1228
- acc.tools = acc.tools.filter((t) => !droppedTools.has(t.function.name));
1229
- for (const [serverName, info] of acc.mcpCapability) {
1230
- if (info.certifiedNames.length === 0) continue;
1231
- const live = await ctx.probeLiveToolNames(info.capabilityId);
1232
- if (!setsEqual(new Set(live), new Set(info.certifiedNames))) {
1233
- delete acc.mcpConnections[serverName];
1234
- acc.mcpCapability.delete(serverName);
1235
- }
1236
- }
1237
- }
1238
- function setsEqual(a, b) {
1239
- if (a.size !== b.size) return false;
1240
- for (const x of a) if (!b.has(x)) return false;
1241
- return true;
1242
- }
1243
- function inlineContent(cap, ref) {
1244
- if (ref.kind === "inline") return ref.content;
1245
- throw new Error(`capability '${cap.id}': content ref '${ref.kind}' is not inline — wire a content fetcher to resolve it`);
1246
- }
1247
- function pushContextArtifact(acc, cap, content) {
1248
- const type = contextArtifactType(cap);
1249
- const bucket = acc.contextArtifacts[type] ?? [];
1250
- acc.contextArtifacts[type] = bucket;
1251
- bucket.push({
1252
- path: contextArtifactPath(cap),
1253
- content,
1254
- contentHash: cap.provenance.contentHash,
1255
- version: cap.provenance.version,
1256
- lift: cap.provenance.lift,
1257
- promotedAt: cap.provenance.promotedAt
1258
- });
1259
- }
1260
- /** Map a context capability onto the artifact-type bucket `composeCertifiedPrompt`
1261
- * folds. The `prompt-surface`/`skill`/`instructions` buckets all fold into the
1262
- * prompt (see `promptFoldTypes`), so context bytes always reach the agent; a
1263
- * non-context surface lowered here as the fail-safe folds as `instructions`. */
1264
- function contextArtifactType(cap) {
1265
- if (cap.iface.surface === "context") return cap.iface.kind === "instructions" ? "instructions" : cap.iface.kind;
1266
- return "instructions";
1267
- }
1268
- /** The artifact's byte-stable fold sort key — the ORIGINAL source path,
1269
- * including `null`, round-tripped through provenance. The resolver folds in
1270
- * `composeCertifiedPrompt` order (sort by `path ?? ''`), so `null` is
1271
- * load-bearing and must survive the manifest→resolve→fold trip unchanged. This
1272
- * is deliberately NOT `iface.name` (display only) — conflating the two flips
1273
- * the fold order against the gate-certified reference. */
1274
- function contextArtifactPath(cap) {
1275
- return cap.provenance.sourcePath;
1276
- }
1277
- /** Lower a plane `CertifiedProfile` straight into a `ResolvedSurface` via
1278
- * `manifestFromProfile` — the convenience the shipped pull lane calls when it
1279
- * already holds a `CertifiedProfile` (today's wire) rather than a manifest. */
1280
- async function composeCertifiedProfileFromWire(base, profile, ctx = {}) {
1281
- if (!profile) return composeCertifiedProfile(base, null, ctx);
1282
- return composeCertifiedProfile(base, manifestFromProfile(profile), ctx);
1283
- }
1284
- //#endregion
1285
886
  //#region src/intelligence/with-intelligence.ts
1286
887
  function summarizeRuntimeEvents(events) {
1287
888
  const summary = {
@@ -1715,6 +1316,6 @@ function createIntelligenceClient(config) {
1715
1316
  };
1716
1317
  }
1717
1318
  //#endregion
1718
- export { AGENT_IMPROVEMENT_PROFILE_SURFACES, AGENT_PROFILE_MEASURED_SURFACES, AgentCandidateExperimentCellExecutionError, CapabilityNotAdmittedError, agentImprovementProfileDiffs, agentImprovementProfileSurfaceDigest, agentImprovementProfileSurfaceInput, agentImprovementTargetProfileDiffs, buildAgentImprovementActivationTargets, compileEffort, composeCertifiedProfile, composeCertifiedProfileFromWire, composeCertifiedPrompt, createAgentImprovementActivation, createAgentImprovementActivationResult, createAgentImprovementMeasuredComparison, createAgentImprovementProposal, createCertifiedPromptSource, createExactProcessCandidateExperimentExecutor, createIntelligenceClient, createOptimizationActivationReceipt, createProtectedExactProcessCandidateExperimentExecutor, defaultEffortTier, defaultRedactor, exactProcessCandidateExperimentExecutionSupport, executeAgentCandidateExperimentCell, executeAgentImprovementActivation, isAgentImprovementProfileSurface, isAgentProfileMeasuredSurface, isIntelligenceOff, manifestFromProfile, normalizeCertifiedProfile, optimizationActivationReceiptFromMetadata, parseAgentCandidateProfileActivation as parseCandidateProfileMaterialization, prepareAgentImprovementProfileActivation, proposeAgentImprovement, proposeAgentProfileImprovement, proposeAuthoredAgentProfileImprovement, pullCertified, resolveEffort, resolveIntelligenceBaseUrl, resolveRedactor, reviewAgentImprovementProposal, runAgentCandidateExperiment, submitAgentImprovementProposal, verifyAgentImprovementActivation, verifyAgentImprovementActivationResult, verifyAgentImprovementProposal, verifyAgentImprovementReview, verifyCandidateExecutionEvidence, withIntelligence };
1319
+ export { AGENT_IMPROVEMENT_PROFILE_SURFACES, AGENT_PROFILE_MEASURED_SURFACES, AgentCandidateExperimentCellExecutionError, CapabilityNotAdmittedError, agentImprovementProfileDiffs, agentImprovementProfileSurfaceDigest, agentImprovementProfileSurfaceInput, agentImprovementTargetProfileDiffs, buildAgentImprovementActivationTargets, compileEffort, composeCertifiedPrompt, createAgentImprovementActivation, createAgentImprovementActivationResult, createAgentImprovementMeasuredComparison, createAgentImprovementProposal, createCertifiedPromptSource, createExactProcessCandidateExperimentExecutor, createIntelligenceClient, createOptimizationActivationReceipt, createProtectedExactProcessCandidateExperimentExecutor, defaultEffortTier, defaultRedactor, exactProcessCandidateExperimentExecutionSupport, executeAgentCandidateExperimentCell, executeAgentImprovementActivation, isAgentImprovementProfileSurface, isAgentProfileMeasuredSurface, isIntelligenceOff, manifestFromProfile, normalizeCertifiedProfile, optimizationActivationReceiptFromMetadata, parseAgentCandidateProfileActivation as parseCandidateProfileMaterialization, prepareAgentImprovementProfileActivation, proposeAgentImprovement, proposeAgentProfileImprovement, proposeAuthoredAgentProfileImprovement, pullCertified, resolveEffort, resolveIntelligenceBaseUrl, resolveRedactor, reviewAgentImprovementProposal, runAgentCandidateExperiment, submitAgentImprovementProposal, verifyAgentImprovementActivation, verifyAgentImprovementActivationResult, verifyAgentImprovementProposal, verifyAgentImprovementReview, verifyCandidateExecutionEvidence, withIntelligence };
1719
1320
 
1720
1321
  //# sourceMappingURL=intelligence.js.map