@tangle-network/agent-runtime 0.337.2 → 0.339.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 (155) hide show
  1. package/dist/{activation-DRHM55Oo.d.ts → activation-CJIIl_Ey.d.ts} +90 -22
  2. package/dist/activation-CVSFxis9.js +876 -0
  3. package/dist/activation-CVSFxis9.js.map +1 -0
  4. package/dist/agent.d.ts +4 -4
  5. package/dist/agent.js +4 -7
  6. package/dist/agent.js.map +1 -1
  7. package/dist/{bundle-BPGjESee.js → bundle-DVOhBTic.js} +2 -2
  8. package/dist/{bundle-BPGjESee.js.map → bundle-DVOhBTic.js.map} +1 -1
  9. package/dist/candidate-execution/index.d.ts +4 -63
  10. package/dist/candidate-execution/index.js +6 -146
  11. package/dist/candidate-execution/index.js.map +1 -1
  12. package/dist/content-digest-sBTLujlK.js +9 -0
  13. package/dist/content-digest-sBTLujlK.js.map +1 -0
  14. package/dist/{delegate-B-T_ZB50.js → delegate-CCWE_AkU.js} +2 -2
  15. package/dist/{delegate-B-T_ZB50.js.map → delegate-CCWE_AkU.js.map} +1 -1
  16. package/dist/{coordination-driver-BHkFVqIq.js → driver-control-acknowledgers-C53ggdJ6.js} +4520 -4442
  17. package/dist/driver-control-acknowledgers-C53ggdJ6.js.map +1 -0
  18. package/dist/{durable-file-B_eJr6Mb.js → durable-file-gNI9ILAn.js} +1 -3
  19. package/dist/durable-file-gNI9ILAn.js.map +1 -0
  20. package/dist/durable.d.ts +3 -35
  21. package/dist/durable.js +225 -229
  22. package/dist/durable.js.map +1 -1
  23. package/dist/{graph-C4RFlWAJ.js → graph-CI9JXKqO.js} +65 -18
  24. package/dist/graph-CI9JXKqO.js.map +1 -0
  25. package/dist/{graph-registry-DAI6KNXB.js → graph-registry-BnO64cn8.js} +18 -17
  26. package/dist/graph-registry-BnO64cn8.js.map +1 -0
  27. package/dist/{improvement-cycle-D1I4hQvf.js → improve-BOXTLWJ3.js} +76 -1248
  28. package/dist/improve-BOXTLWJ3.js.map +1 -0
  29. package/dist/{improvement-adapter-D5gwwoXQ.d.ts → improvement-adapter-HUt_-cWA.d.ts} +2 -20
  30. package/dist/index.d.ts +10 -207
  31. package/dist/index.js +91 -305
  32. package/dist/index.js.map +1 -1
  33. package/dist/intelligence.d.ts +10 -229
  34. package/dist/intelligence.js +506 -88
  35. package/dist/intelligence.js.map +1 -1
  36. package/dist/{jsonl-file-DBv31uPi.js → jsonl-file-C9Kde_0Z.js} +2 -2
  37. package/dist/{jsonl-file-DBv31uPi.js.map → jsonl-file-C9Kde_0Z.js.map} +1 -1
  38. package/dist/kernel.d.ts +4 -3
  39. package/dist/kernel.js +12 -13
  40. package/dist/loop-runner-CWzG1bH4.d.ts +32 -0
  41. package/dist/loop-runner-bin.d.ts +32 -2
  42. package/dist/loop-runner-bin.js +93 -1
  43. package/dist/loop-runner-bin.js.map +1 -0
  44. package/dist/loop-runner-pmPIHFVY.js +59 -0
  45. package/dist/loop-runner-pmPIHFVY.js.map +1 -0
  46. package/dist/mcp/bin.js +3 -3
  47. package/dist/mcp/bin.js.map +1 -1
  48. package/dist/mcp/index.d.ts +101 -416
  49. package/dist/mcp/index.js +122 -206
  50. package/dist/mcp/index.js.map +1 -1
  51. package/dist/mcp/memory-bin.js +231 -1
  52. package/dist/mcp/memory-bin.js.map +1 -1
  53. package/dist/model-policy-CyCUwHed.js.map +1 -1
  54. package/dist/placement.d.ts +2 -9
  55. package/dist/placement.js +1 -1
  56. package/dist/placement.js.map +1 -1
  57. package/dist/platform.d.ts +194 -2
  58. package/dist/platform.js +145 -9
  59. package/dist/platform.js.map +1 -1
  60. package/dist/{prepare-CER-ZkPp.js → prepare-bXkvPMJA.js} +1213 -710
  61. package/dist/prepare-bXkvPMJA.js.map +1 -0
  62. package/dist/{profile-gNUsHNIJ.js → profile-Dpei_Sq0.js} +89 -3
  63. package/dist/profile-Dpei_Sq0.js.map +1 -0
  64. package/dist/{profile-materialization-BnoEf1co.d.ts → profile-materialization-B1wm2SPT.d.ts} +3 -5
  65. package/dist/profiles.d.ts +2 -2
  66. package/dist/profiles.js +4 -43
  67. package/dist/profiles.js.map +1 -1
  68. package/dist/{protected-model-port-BhpQRTw-.d.ts → protected-model-port-BGgpy2r9.d.ts} +4 -30
  69. package/dist/protected-redaction-DFCeo4vg.js.map +1 -1
  70. package/dist/{provision-supervisor-DGegCUH4.js → provision-supervisor-CJ6Zz6dz.js} +13 -10
  71. package/dist/provision-supervisor-CJ6Zz6dz.js.map +1 -0
  72. package/dist/record-value-B6bwJxLa.js +12 -0
  73. package/dist/record-value-B6bwJxLa.js.map +1 -0
  74. package/dist/{run-layout-Cu8H7aeh.js → run-cancellation-C9oL62sW.js} +175 -100
  75. package/dist/run-cancellation-C9oL62sW.js.map +1 -0
  76. package/dist/{runtime-BOGpotnH.js → runtime-B2fjL9Oi.js} +2639 -3187
  77. package/dist/runtime-B2fjL9Oi.js.map +1 -0
  78. package/dist/{runtime-hooks-Bj6wJHlH.d.ts → runtime-hooks-nsqxSUFL.d.ts} +2 -6
  79. package/dist/{sandbox-profile-compat-QTkLe1Z6.js → sandbox-profile-compat-BzVBFqrz.js} +690 -699
  80. package/dist/sandbox-profile-compat-BzVBFqrz.js.map +1 -0
  81. package/dist/search-executor-zMumiak_.js +1916 -0
  82. package/dist/search-executor-zMumiak_.js.map +1 -0
  83. package/dist/{server-hZWM-G8w.js → server-_4voDNrl.js} +362 -67
  84. package/dist/server-_4voDNrl.js.map +1 -0
  85. package/dist/{search-executor-Cm1WZmL-.js → structural-rollout-DpLCXzaL.js} +1680 -3403
  86. package/dist/structural-rollout-DpLCXzaL.js.map +1 -0
  87. package/dist/{substrate-B0TYNrXn.js → substrate-CGDFTSRh.js} +2 -9
  88. package/dist/substrate-CGDFTSRh.js.map +1 -0
  89. package/dist/{supervise-CvAKVfue.js → supervise-qAwXmPtD.js} +7768 -5360
  90. package/dist/supervise-qAwXmPtD.js.map +1 -0
  91. package/dist/{supervisor-Rz8AGpYb.js → supervisor-DHrUJhEZ.js} +26301 -26964
  92. package/dist/supervisor-DHrUJhEZ.js.map +1 -0
  93. package/dist/testing.d.ts +227 -2
  94. package/dist/testing.js +13 -14
  95. package/dist/testing.js.map +1 -1
  96. package/dist/tool-loop.d.ts +1 -1
  97. package/dist/{tool-server-Dqer2M4_.js → tool-server-XV4aJwoQ.js} +2 -2
  98. package/dist/tool-server-XV4aJwoQ.js.map +1 -0
  99. package/dist/top-snapshot-CbZE1JsU.js +502 -0
  100. package/dist/top-snapshot-CbZE1JsU.js.map +1 -0
  101. package/dist/tui/bin.js +711 -1
  102. package/dist/tui/bin.js.map +1 -1
  103. package/dist/tui/index.d.ts +5 -71
  104. package/dist/tui/index.js +3 -3
  105. package/dist/{types-Dl5L4r8Z.d.ts → types-CaOXqRTq.d.ts} +16230 -17376
  106. package/dist/workspace-store/index.d.ts +2 -27
  107. package/dist/workspace-store/index.js +2 -2
  108. package/dist/workspace-store/index.js.map +1 -1
  109. package/dist/{workspace-streams-JLjh5DC6.d.ts → workspace-streams-BiS4ABah.d.ts} +19 -32
  110. package/package.json +2 -2
  111. package/skills/agent-graphs/SKILL.md +10 -3
  112. package/skills/agent-graphs/references/authoring.md +18 -0
  113. package/skills/profile-authoring/SKILL.md +3 -3
  114. package/skills/supervise/SKILL.md +2 -2
  115. package/dist/activation-BDP6Eivv.js +0 -234
  116. package/dist/activation-BDP6Eivv.js.map +0 -1
  117. package/dist/coder-yhVWbdWc.js +0 -40
  118. package/dist/coder-yhVWbdWc.js.map +0 -1
  119. package/dist/coordination-driver-BHkFVqIq.js.map +0 -1
  120. package/dist/delegation-status-CF4D0NZ_.js +0 -358
  121. package/dist/delegation-status-CF4D0NZ_.js.map +0 -1
  122. package/dist/durable-file-B_eJr6Mb.js.map +0 -1
  123. package/dist/graph-C4RFlWAJ.js.map +0 -1
  124. package/dist/graph-registry-DAI6KNXB.js.map +0 -1
  125. package/dist/improvement-cycle-D1I4hQvf.js.map +0 -1
  126. package/dist/integrations-DopfCC2a.d.ts +0 -190
  127. package/dist/integrations-dFi-ALk7.js +0 -132
  128. package/dist/integrations-dFi-ALk7.js.map +0 -1
  129. package/dist/kb-gate-C8z2juK8.d.ts +0 -80
  130. package/dist/kb-gate-DpaSwXVx.js +0 -80
  131. package/dist/kb-gate-DpaSwXVx.js.map +0 -1
  132. package/dist/loop-runner-bin-DOuBIJ2O.d.ts +0 -164
  133. package/dist/loop-runner-bin-Dv5QvYDH.js +0 -246
  134. package/dist/loop-runner-bin-Dv5QvYDH.js.map +0 -1
  135. package/dist/memory-server-DXQ8IxGR.js +0 -234
  136. package/dist/memory-server-DXQ8IxGR.js.map +0 -1
  137. package/dist/openai-tools-DoQ32vpe.js +0 -44
  138. package/dist/openai-tools-DoQ32vpe.js.map +0 -1
  139. package/dist/openai-tools-Oxk4KQrY.d.ts +0 -24
  140. package/dist/prepare-CER-ZkPp.js.map +0 -1
  141. package/dist/profile-gNUsHNIJ.js.map +0 -1
  142. package/dist/protected-model-port-BuRsviSL.js +0 -766
  143. package/dist/protected-model-port-BuRsviSL.js.map +0 -1
  144. package/dist/provision-supervisor-DGegCUH4.js.map +0 -1
  145. package/dist/run-layout-Cu8H7aeh.js.map +0 -1
  146. package/dist/runtime-BOGpotnH.js.map +0 -1
  147. package/dist/sandbox-profile-compat-QTkLe1Z6.js.map +0 -1
  148. package/dist/search-executor-Cm1WZmL-.js.map +0 -1
  149. package/dist/server-hZWM-G8w.js.map +0 -1
  150. package/dist/substrate-B0TYNrXn.js.map +0 -1
  151. package/dist/supervise-CvAKVfue.js.map +0 -1
  152. package/dist/supervisor-Rz8AGpYb.js.map +0 -1
  153. package/dist/tool-server-Dqer2M4_.js.map +0 -1
  154. package/dist/top-app-BaMw1W2z.js +0 -1212
  155. package/dist/top-app-BaMw1W2z.js.map +0 -1
@@ -1,20 +1,20 @@
1
- import { Da as defaultRedactor, Pn as resolveAgentEnvironmentProvider, Tr as toOtelAttributes, _r as buildRuntimeEventOtelSpans, br as flatOtelSpan, hr as buildLoopOtelSpans, ka as resolveRedactor, ui as authoredAgentIdentity, yr as createOtelExporter } from "./supervisor-Rz8AGpYb.js";
2
- import { F as canonicalCandidateDigest$1, z as immutableCandidateValue } from "./sandbox-profile-compat-QTkLe1Z6.js";
3
- import { a as createRuntimeUsageTotals, i as addRuntimeUsage, n as executeAgentImprovementActivation, o as isUsageAmount, r as verifyAgentImprovementActivationResult, t as createAgentImprovementActivationResult } from "./activation-BDP6Eivv.js";
4
- 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, V as assertProfileTrainingIsHeldOut, _ 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-D1I4hQvf.js";
5
- import { a as AGENT_CANDIDATE_EXECUTION_SUPPORT } from "./prepare-CER-ZkPp.js";
6
- import { d as omitUndefinedObjectFields, f as parseAgentCandidateProfileActivation, i as applyExactAgentProfileDiff, p as parseExactAgentProfile } from "./profile-gNUsHNIJ.js";
7
- import { n as exactProcessProviderAsCandidateExecutor, t as createProtectedAgentCandidateModelPort } from "./protected-model-port-BuRsviSL.js";
8
- import { agentImprovementSourceSchema, agentProfileImprovementArmSchema, applyAgentProfileDiff } from "@tangle-network/agent-interface";
9
- import { contentHash } from "@tangle-network/agent-eval";
1
+ import { Ii as defaultRedactor, Kr as authoredAgentIdentity, Nt as resolveAgentEnvironmentProvider, Ri as resolveRedactor, an as buildRuntimeEventOtelSpans, cn as flatOtelSpan, pn as toOtelAttributes, rn as buildLoopOtelSpans, sn as createOtelExporter } from "./supervisor-DHrUJhEZ.js";
2
+ import { B as omitTopLevelDigest, F as canonicalCandidateDigest$1, H as verifyCanonicalCandidateDocument, I as canonicalCandidateDocument, P as canonicalCandidateBytes$1, z as immutableCandidateValue } from "./sandbox-profile-compat-BzVBFqrz.js";
3
+ import { a as assertProfileTrainingIsHeldOut, f as addRuntimeUsage, l as rethrowAfterCleanup, m as isUsageAmount, p as createRuntimeUsageTotals, t as improve } from "./improve-BOXTLWJ3.js";
4
+ import { _ as agentImprovementTargetProfileDiffs, a as reviewAgentImprovementProposal, b as isAgentProfileMeasuredSurface, c as verifyAgentImprovementProposal, d as attachOptimizationActivationReceipt, f as createOptimizationActivationReceipt, g as agentImprovementProfileSurfaceInput, h as agentImprovementProfileSurfaceDigest, i as executeAgentImprovementActivation, l as verifyAgentImprovementReview, m as agentImprovementProfileDiffs, n as createAgentImprovementActivationResult, o as verifyAgentImprovementActivation, p as optimizationActivationReceiptFromMetadata, r as createAgentImprovementProposal, s as verifyAgentImprovementActivationResult, t as createAgentImprovementActivation, u as assertNoCallerOptimizationReceipt, v as assertProfileImprovementTargetsShareIdentity, y as isAgentImprovementProfileSurface } from "./activation-CVSFxis9.js";
5
+ import { _ as parseAgentCandidateProfileActivation, a as applyExactAgentProfileDiff, d as createAgentCandidateProfileActivation, g as omitUndefinedObjectFields, m as materializeAgentCandidateProfilePlan, o as assertCandidateProfileBinding, v as parseExactAgentProfile } from "./profile-Dpei_Sq0.js";
6
+ import { t as runAnalystLoop } from "./analyst-loop-DZw5QWT9.js";
7
+ import { C as verifiedResourceTextByDigest, S as AGENT_CANDIDATE_EXECUTION_SUPPORT, n as executePreparedAgentCandidate, t as prepareAgentCandidateExecution, w as verifyAgentCandidateBundle, x as exactProcessProviderAsCandidateExecutor, y as createProtectedAgentCandidateModelPort } from "./prepare-bXkvPMJA.js";
8
+ import { AGENT_IMPROVEMENT_SOURCE_METADATA_KEY, agentCandidateMaterializationReceiptSchema, agentCandidateRunReceiptSchema, agentImprovementSourceMetadata, agentImprovementSourceSchema, agentProfileImprovementArmSchema, applyAgentProfileDiff, candidateExecutionEvidenceSchema, numbersApproximatelyEqual } from "@tangle-network/agent-interface";
9
+ import { CostLedger, contentHash } from "@tangle-network/agent-eval";
10
10
  import { ATTR, agentIdentityAttributes } from "@tangle-network/agent-trace-contract";
11
11
  import { assertProposalFindings } from "@tangle-network/agent-eval/analyst";
12
- import { measuredComparisonFromAgentProfileImprovementExperiment, runAgentProfileImprovementExperiment, sealAgentProfileImprovementExperiment, verifyAgentProfileImprovementExperimentComparison } from "@tangle-network/agent-eval/contract";
12
+ import { campaignSplitDigestFromIdentities } from "@tangle-network/agent-eval/campaign";
13
+ import { measuredComparisonFromAgentProfileImprovementExperiment, measuredComparisonFromCandidateExperiment, runAgentProfileImprovementExperiment, runCandidateExperiment, sealAgentProfileImprovementExperiment, sealAgentProfileImprovementSuite, sealAgentProfileImprovementTask, sealCandidateExperiment, verifyAgentProfileImprovementExperimentComparison, verifyCandidateExperiment, verifyCandidateExperimentComparison } from "@tangle-network/agent-eval/contract";
13
14
  //#region src/intelligence/delivery.ts
14
15
  const defaultPlaneBaseUrl = "https://intelligence.tangle.tools";
15
16
  const defaultRefreshMs = 3e5;
16
17
  const defaultPlaneRequestTimeoutMs = 1e4;
17
- const maxPlaneErrorTextLength = 200;
18
18
  /** Resolve the ONE Intelligence base URL — the single knob both the send and
19
19
  * receive paths derive from. Env fallback: `TANGLE_INTELLIGENCE_URL`. */
20
20
  function resolveIntelligenceBaseUrl(baseUrl) {
@@ -65,9 +65,6 @@ async function requestPlane(input) {
65
65
  function asRecord(value) {
66
66
  return value && typeof value === "object" ? value : {};
67
67
  }
68
- function capPlaneErrorText(value) {
69
- return value.slice(0, maxPlaneErrorTextLength);
70
- }
71
68
  function toDiffProvenance(value) {
72
69
  const p = asRecord(value);
73
70
  return {
@@ -146,76 +143,6 @@ async function pullCertified(opts) {
146
143
  };
147
144
  }
148
145
  }
149
- /**
150
- * Submit a completed Runtime proposal to Intelligence for product-side review.
151
- * This never runs an experiment, approves a proposal, or applies a candidate.
152
- * A 4xx response is a confirmed `rejected` request. Network failures, timeouts,
153
- * 5xx responses, and invalid success responses are `unconfirmed`, so callers
154
- * can retry the same digest because Intelligence stores proposals idempotently.
155
- */
156
- async function submitAgentImprovementProposal(opts) {
157
- let proposal;
158
- try {
159
- proposal = verifyAgentImprovementProposal(opts.proposal);
160
- } catch (err) {
161
- return {
162
- succeeded: false,
163
- submission: "not-sent",
164
- error: `proposal validation failed: ${err instanceof Error ? err.message : String(err)}`
165
- };
166
- }
167
- const request = await requestPlane({
168
- ...opts,
169
- path: "/v1/improvements/proposals",
170
- method: "POST",
171
- headers: { "content-type": "application/json" },
172
- body: JSON.stringify({ proposal })
173
- });
174
- if (!request.succeeded) return {
175
- succeeded: false,
176
- submission: request.attempted ? "unconfirmed" : "not-sent",
177
- error: request.attempted ? `proposal submission request failed: ${request.error}` : request.error
178
- };
179
- const res = request.response;
180
- if (!res.ok) {
181
- const body = await res.text().catch(() => "");
182
- let code;
183
- let message = capPlaneErrorText(body);
184
- try {
185
- const parsed = asRecord(JSON.parse(body));
186
- if (typeof parsed.error === "string") code = capPlaneErrorText(parsed.error);
187
- if (typeof parsed.message === "string") message = capPlaneErrorText(parsed.message);
188
- } catch {}
189
- return {
190
- succeeded: false,
191
- submission: res.status >= 400 && res.status < 500 ? "rejected" : "unconfirmed",
192
- error: `proposal submission ${res.status}: ${message}`,
193
- status: res.status,
194
- ...code === void 0 ? {} : { code }
195
- };
196
- }
197
- try {
198
- const recorded = verifyAgentImprovementProposal(asRecord(await res.json()).proposal);
199
- if (recorded.digest !== proposal.digest) return {
200
- succeeded: false,
201
- submission: "unconfirmed",
202
- error: "proposal submission returned a different proposal digest",
203
- status: res.status
204
- };
205
- return {
206
- succeeded: true,
207
- value: recorded,
208
- status: res.status
209
- };
210
- } catch (err) {
211
- return {
212
- succeeded: false,
213
- submission: "unconfirmed",
214
- error: `proposal submission response parse failed: ${capPlaneErrorText(err instanceof Error ? err.message : String(err))}`,
215
- status: res.status
216
- };
217
- }
218
- }
219
146
  /** Artifact-type buckets that fold into the system prompt, in fold order. A
220
147
  * certified `context` capability whose content is free text (`instructions`)
221
148
  * is delivered here so it actually reaches the agent — never bucketed into a
@@ -404,6 +331,70 @@ function normalizeReportedUsage(usage, intelligenceOff = false) {
404
331
  };
405
332
  }
406
333
  //#endregion
334
+ //#region src/intelligence/profile-improvement-experiment.ts
335
+ function createProfileImprovementCostLedger(budgetUsd, context = "profile improvement") {
336
+ if (!Number.isFinite(budgetUsd) || budgetUsd < 0) throw new Error(`${context} budgetUsd must be a non-negative finite number`);
337
+ return new CostLedger({ costCeilingUsd: budgetUsd });
338
+ }
339
+ function profilePolicyWithBudget(policy, budgetUsd, context = "profile improvement") {
340
+ if (policy.budgetUsd !== void 0 && !numbersApproximatelyEqual(policy.budgetUsd, budgetUsd)) throw new Error(`${context} policy budgetUsd must equal the run budgetUsd`);
341
+ return {
342
+ ...policy,
343
+ budgetUsd
344
+ };
345
+ }
346
+ function profilePreparationAccounting(costLedger, startedAt) {
347
+ const summary = costLedger.summary();
348
+ if (!summary.accountingComplete || summary.costProvenance.kind === "uncaptured") throw new Error("profile improvement preparation cost is incomplete");
349
+ return {
350
+ wallDurationMs: Math.max(0, performance.now() - startedAt),
351
+ cost: {
352
+ usd: summary.costProvenance.usd,
353
+ provenance: summary.costProvenance.kind
354
+ }
355
+ };
356
+ }
357
+ function profileStateDigest$1(stateDigest, identity, profile) {
358
+ return agentProfileImprovementArmSchema.parse({ stateDigest: stateDigest({
359
+ identity,
360
+ profile
361
+ }) }).stateDigest;
362
+ }
363
+ function sealProfileImprovementBenchmark(input) {
364
+ const tasks = input.tasks.map((task) => sealAgentProfileImprovementTask(task));
365
+ return sealAgentProfileImprovementSuite({
366
+ splitDigest: campaignSplitDigestFromIdentities(tasks.map(profileTaskScenarioIdentity), input.reps),
367
+ tasks,
368
+ reps: input.reps,
369
+ seeds: input.seeds
370
+ });
371
+ }
372
+ function profileTaskScenarioIdentity(task) {
373
+ return {
374
+ id: task.scenario.id,
375
+ kind: task.scenario.kind,
376
+ scenarioDigest: task.scenario.digest
377
+ };
378
+ }
379
+ function profileImprovementMetadata(metadata, source, optimizationReceipt) {
380
+ assertNoCallerOptimizationReceipt(metadata);
381
+ if (metadata && Object.hasOwn(metadata, AGENT_IMPROVEMENT_SOURCE_METADATA_KEY)) throw new Error(`candidate metadata reserves '${AGENT_IMPROVEMENT_SOURCE_METADATA_KEY}' for Runtime`);
382
+ const merged = {
383
+ ...metadata ?? {},
384
+ ...agentImprovementSourceMetadata(source)
385
+ };
386
+ return optimizationReceipt ? attachOptimizationActivationReceipt(merged, optimizationReceipt) : immutableCandidateValue(merged);
387
+ }
388
+ function completeImprovementSearchAccounting(analysis, improvement) {
389
+ if (!improvement.cost.accountingComplete) throw new Error(`agent improvement optimization cost is incomplete: ${improvement.cost.incompleteReasons.join(", ") || "unspecified"}`);
390
+ if (!Number.isFinite(improvement.cost.totalCostUsd) || improvement.cost.totalCostUsd < 0) throw new Error("agent improvement optimization cost must be finite and non-negative");
391
+ if (!Number.isFinite(improvement.durationMs) || improvement.durationMs < 0) throw new Error("agent improvement optimization duration must be finite and non-negative");
392
+ return {
393
+ searchCostUsd: analysis.costUsd + improvement.cost.totalCostUsd,
394
+ searchDurationMs: analysis.durationMs + improvement.durationMs
395
+ };
396
+ }
397
+ //#endregion
407
398
  //#region src/intelligence/authored-profile-improvement.ts
408
399
  /**
409
400
  * Put a complete authored/imported profile through the canonical profile
@@ -686,6 +677,433 @@ function isJsonSchema(v) {
686
677
  return typeof v === "object" && v !== null && !Array.isArray(v);
687
678
  }
688
679
  //#endregion
680
+ //#region src/intelligence/improvement-cycle.ts
681
+ /** A failed baseline or candidate cell with its complete Runtime failure result. */
682
+ var AgentCandidateExperimentCellExecutionError = class extends Error {
683
+ finalization;
684
+ constructor(finalization) {
685
+ super(`candidate experiment cell failed: ${finalization.reason}`);
686
+ this.name = "AgentCandidateExperimentCellExecutionError";
687
+ this.finalization = finalization;
688
+ }
689
+ };
690
+ function sealAgentImprovementExperiment(material, improvement) {
691
+ assertRuntimeOwnedExperimentFieldsAbsent(material);
692
+ const candidateLineage = {
693
+ source: "optimizer",
694
+ parentDigests: [material.baseline.digest],
695
+ runIds: [improvement.lineage.runId],
696
+ developmentSplitDigest: improvement.lineage.developmentSplitDigest
697
+ };
698
+ const experiment = sealCandidateExperiment({
699
+ ...material,
700
+ candidateLineage
701
+ });
702
+ assertCandidateReleaseWorkIsFresh(experiment, improvement);
703
+ return experiment;
704
+ }
705
+ function assertRuntimeOwnedExperimentFieldsAbsent(material) {
706
+ if (material === null || typeof material !== "object" || Array.isArray(material)) throw new Error("agent improvement experiment material must be an object");
707
+ const supplied = ["candidateLineage", "digest"].filter((field) => Object.hasOwn(material, field));
708
+ if (supplied.length > 0) throw new Error(`agent improvement experiment material must not supply Runtime-owned fields: ${supplied.join(", ")}`);
709
+ }
710
+ /** Execute both arms of one immutable experiment and derive its paired result. */
711
+ async function runAgentCandidateExperiment(options) {
712
+ const experiment = verifyCandidateExperiment(options.experiment);
713
+ const preparation = options.preparation ?? {
714
+ wallDurationMs: 0,
715
+ cost: {
716
+ usd: 0,
717
+ provenance: "observed"
718
+ }
719
+ };
720
+ const costLedger = options.costLedger ?? (experiment.policy.budgetUsd === void 0 ? void 0 : new CostLedger({ costCeilingUsd: experiment.policy.budgetUsd }));
721
+ const run = await runCandidateExperiment({
722
+ experiment,
723
+ ...options.maxConcurrency === void 0 ? {} : { maxConcurrency: options.maxConcurrency },
724
+ ...costLedger ? { costLedger } : {},
725
+ ...options.signal ? { signal: options.signal } : {},
726
+ execute: async (input) => {
727
+ const placement = await options.placeCell(input);
728
+ return await executeAgentCandidateExperimentCell({
729
+ ...input,
730
+ ...placement
731
+ });
732
+ }
733
+ });
734
+ const evaluation = createAgentImprovementMeasuredComparison({
735
+ experiment,
736
+ measurements: run.measurements,
737
+ preparation,
738
+ measurement: run.measurement,
739
+ runId: options.runId,
740
+ ...options.candidate ? { candidate: options.candidate } : {},
741
+ ...options.generationsExplored === void 0 ? {} : { generationsExplored: options.generationsExplored },
742
+ ...options.metadata ? { metadata: options.metadata } : {}
743
+ });
744
+ return {
745
+ experiment,
746
+ measurements: run.measurements,
747
+ evaluation
748
+ };
749
+ }
750
+ /** Execute one exact arm, task, repetition, seed, and attempt through Runtime. */
751
+ async function executeAgentCandidateExperimentCell(options) {
752
+ const experiment = verifyCandidateExperiment(options.experiment);
753
+ const bundle = experiment[options.arm];
754
+ assertExactExperimentInput(options, experiment, bundle);
755
+ const attempt = options.attempt ?? 1;
756
+ if (attempt > options.task.attempt.maxAttempts) throw new Error("candidate experiment attempt exceeds the signed task policy");
757
+ const runCell = canonicalCandidateDocument({
758
+ kind: "agent-candidate-run-cell",
759
+ experimentDigest: experiment.digest,
760
+ arm: options.arm,
761
+ bundleDigest: bundle.digest,
762
+ suiteDigest: options.benchmarkCell.suiteDigest,
763
+ taskDigest: options.task.digest,
764
+ taskIndex: options.benchmarkCell.taskIndex,
765
+ repetition: options.benchmarkCell.repetition,
766
+ seed: options.seed,
767
+ attempt
768
+ }).value;
769
+ const verified = await verifyAgentCandidateBundle(bundle, options.ports);
770
+ const prepared = await prepareAgentCandidateExecution(verified, {
771
+ executionId: options.executionId,
772
+ runCell,
773
+ benchmarkSuite: experiment.benchmark.suite,
774
+ task: options.task,
775
+ executionRoots: options.executionRoots,
776
+ stagingRoots: options.stagingRoots
777
+ }, options.ports, options.preparation);
778
+ const finalization = await executePreparedAgentCandidate(prepared, options.execution);
779
+ if (!finalization.succeeded) throw new AgentCandidateExperimentCellExecutionError(finalization);
780
+ const evidence = canonicalCandidateDocument({
781
+ kind: "agent-candidate-execution-evidence",
782
+ materializationReceipt: prepared.materializationReceipt.value,
783
+ receipt: finalization.receipt.value
784
+ }).value;
785
+ return verifyCandidateExecutionEvidence(evidence, {
786
+ experiment,
787
+ arm: options.arm,
788
+ benchmarkCell: options.benchmarkCell,
789
+ seed: options.seed,
790
+ attempt,
791
+ resolvedResources: verifiedResourceTextByDigest(verified)
792
+ });
793
+ }
794
+ /** Delegate all statistics and promotion checks to agent-eval's receipt-based comparison. */
795
+ function createAgentImprovementMeasuredComparison(options) {
796
+ return verifyCandidateExperimentComparison(measuredComparisonFromCandidateExperiment(options));
797
+ }
798
+ async function analyzeAgentImprovement(runId, options, costLedger, signal) {
799
+ assertMeasuredAnalysisOptions(options);
800
+ const analysis = await runAnalystLoop({
801
+ ...options,
802
+ runId,
803
+ ...costLedger ? {
804
+ costLedger,
805
+ costPhase: "profile-improvement-analysis"
806
+ } : {},
807
+ ...signal ? { signal } : {}
808
+ });
809
+ if (costLedger) assertAnalysisCostRecorded(analysis, costLedger);
810
+ const judgeDerived = analysis.analystResult.findings.filter((finding) => finding.derived_from_judge === true);
811
+ if (judgeDerived.length > 0) throw new Error(`agent improvement analysis must not produce judge-derived findings: [${judgeDerived.map((finding) => finding.finding_id).join(", ")}]`);
812
+ return {
813
+ analysis,
814
+ findings: [...assertProposalFindings(analysis.analystResult.findings.map((finding) => ({
815
+ ...finding,
816
+ proposal_origin: "production"
817
+ })), "agent improvement findings")]
818
+ };
819
+ }
820
+ function assertMeasuredAnalysisOptions(options) {
821
+ const rawOptions = options;
822
+ if (rawOptions.knowledgeProposalSource !== void 0 || rawOptions.improvementProposalSource !== void 0) throw new Error("measured agent improvement analysis must not run proposal sources");
823
+ if (rawOptions.onEvent !== void 0 || rawOptions.log !== void 0) throw new Error("measured agent improvement analysis must not run callbacks");
824
+ if (rawOptions.inputs.judgeInput !== void 0) throw new Error("measured agent improvement analysis must not receive judge input");
825
+ }
826
+ function completeAnalysisAccounting(analysis) {
827
+ const analysisCost = analysis.analystResult.total_cost_provenance;
828
+ if (!analysisCost || analysisCost.kind === "uncaptured") throw new Error("agent improvement analysis cost is uncaptured");
829
+ if (!Number.isFinite(analysis.analystResult.total_cost_usd) || analysis.analystResult.total_cost_usd < 0) throw new Error("agent improvement analysis cost must be finite and non-negative");
830
+ if (analysisCost.usd !== analysis.analystResult.total_cost_usd) throw new Error("agent improvement analysis cost does not match its provenance");
831
+ if (!Number.isFinite(analysis.durationMs) || analysis.durationMs < 0) throw new Error("agent improvement analysis duration must be finite and non-negative");
832
+ return {
833
+ costUsd: analysis.analystResult.total_cost_usd,
834
+ durationMs: analysis.durationMs
835
+ };
836
+ }
837
+ function assertAnalysisCostRecorded(analysis, costLedger) {
838
+ const reported = completeAnalysisAccounting(analysis);
839
+ const summary = costLedger.summary();
840
+ if (!summary.accountingComplete || summary.costProvenance.kind === "uncaptured") throw new Error("agent improvement analysis cost is incomplete in the shared account");
841
+ const analysisCost = analysis.analystResult.total_cost_provenance;
842
+ if (!analysisCost || analysisCost.kind === "uncaptured") throw new Error("agent improvement analysis cost is uncaptured");
843
+ if (!numbersApproximatelyEqual(summary.totalCostUsd, reported.costUsd) || summary.costProvenance.kind !== analysisCost.kind) throw new Error("agent improvement analysis cost does not match the shared account");
844
+ }
845
+ function assertReleaseSplitIsFresh(heldOutSplitDigest, improvement) {
846
+ const consumedSplits = [improvement.lineage.developmentSplitDigest];
847
+ if (improvement.mode === "method") {
848
+ const finalTestSplitDigest = improvement.lineage.finalTestSplitDigest;
849
+ if (!finalTestSplitDigest) throw new Error("method improvement does not retain its final-test split digest");
850
+ consumedSplits.push(finalTestSplitDigest);
851
+ }
852
+ if (consumedSplits.includes(heldOutSplitDigest)) throw new Error("release benchmark reuses an optimizer development or final-test split");
853
+ }
854
+ function assertReleaseScenariosAreFresh(improvement, heldOutScenarios) {
855
+ const optimizerScenarios = /* @__PURE__ */ new Map();
856
+ for (const [partition, scenarios] of [
857
+ ["train", improvement.lineage.scenarioPartitions.train],
858
+ ["selection", improvement.lineage.scenarioPartitions.selection],
859
+ ["final-test", improvement.lineage.scenarioPartitions.finalTest]
860
+ ]) for (const scenario of scenarios) optimizerScenarios.set(canonicalCandidateDigest$1(scenario), partition);
861
+ const reused = heldOutScenarios.filter((scenario) => optimizerScenarios.has(canonicalCandidateDigest$1(scenario))).map((scenario) => `${scenario.id} (${optimizerScenarios.get(canonicalCandidateDigest$1(scenario))})`);
862
+ if (reused.length > 0) throw new Error(`release benchmark reuses optimizer scenario(s): [${reused.join(", ")}]`);
863
+ }
864
+ function assertCandidateReleaseWorkIsFresh(experiment, improvement) {
865
+ for (const splitDigest of new Set(experiment.benchmark.tasks.map((task) => task.benchmark.splitDigest))) assertReleaseSplitIsFresh(splitDigest, improvement);
866
+ if (improvement.mode !== "method") return;
867
+ assertReleaseScenariosAreFresh(improvement, experiment.benchmark.tasks.map((task) => task.scenario));
868
+ }
869
+ function assertProfileReleaseWorkIsFresh(benchmark, improvement) {
870
+ assertReleaseSplitIsFresh(benchmark.suite.splitDigest, improvement);
871
+ assertReleaseScenariosAreFresh(improvement, benchmark.tasks.map(profileTaskScenarioIdentity));
872
+ }
873
+ /**
874
+ * Analyze a product-owned profile, search one profile surface, then run the
875
+ * exact baseline and candidate through the product executor before proposing.
876
+ */
877
+ async function proposeAgentProfileImprovement(options) {
878
+ const source = agentImprovementSourceSchema.parse(options.source);
879
+ if (!isAgentProfileMeasuredSurface(options.improvement.surface ?? "prompt")) throw new Error("measured profile improvement supports profile surfaces or a complete agent profile; use the sealed-candidate path for this surface");
880
+ assertMeasuredAnalysisOptions(options.analysis);
881
+ const inputFindings = assertProposalFindings(options.improvement.findings ?? [], "profile improvement input findings");
882
+ const costLedger = createProfileImprovementCostLedger(options.budgetUsd);
883
+ const preparationStartedAt = performance.now();
884
+ const profile = parseExactAgentProfile(options.profile, "profile improvement source");
885
+ const baselineStateDigest = profileStateDigest$1(options.stateDigest, source.sourceIdentity, profile);
886
+ if (baselineStateDigest !== source.sourceDigest) throw new Error("profile improvement source digest does not match the measured profile state");
887
+ const policy = profilePolicyWithBudget(options.benchmark.policy, options.budgetUsd);
888
+ const benchmark = sealProfileImprovementBenchmark({
889
+ ...options.benchmark,
890
+ policy
891
+ });
892
+ const heldOutDigests = new Set(benchmark.tasks.map((task) => task.scenario.digest));
893
+ assertProfileTrainingIsHeldOut(profile, heldOutDigests);
894
+ if (options.improvement.costCeiling !== void 0 && !numbersApproximatelyEqual(options.improvement.costCeiling, options.budgetUsd)) throw new Error("profile improvement costCeiling must equal the run budgetUsd");
895
+ const { analysis, findings } = await analyzeAgentImprovement(options.runId, options.analysis, costLedger, options.signal);
896
+ const proposalFindings = immutableCandidateValue([...inputFindings, ...findings]);
897
+ const improvement = await improve(profile, {
898
+ ...options.improvement,
899
+ executionRef: options.executor.executionRef.digest,
900
+ agent: options.executor.optimize,
901
+ costLedger,
902
+ costCeiling: options.budgetUsd,
903
+ findings: proposalFindings
904
+ });
905
+ try {
906
+ if (improvement.decision !== "ship") throw new Error("agent profile improvement search did not produce a promotable candidate");
907
+ const candidateProfile = parseExactAgentProfile(improvement.candidate.profile, "profile improvement candidate");
908
+ const candidateStateDigest = profileStateDigest$1(options.stateDigest, source.sourceIdentity, candidateProfile);
909
+ if (candidateStateDigest === baselineStateDigest) throw new Error("profile improvement candidate state digest matches the baseline");
910
+ const change = agentImprovementProfileDiffs(profile, candidateProfile, {
911
+ id: `profile-improvement:${candidateStateDigest}`,
912
+ metadata: {
913
+ sourceIdentity: source.sourceIdentity,
914
+ sourceRevision: source.sourceRevision
915
+ }
916
+ });
917
+ const profileDiffIds = change.map((step) => {
918
+ if (!step.id) throw new Error("profile improvement change requires an exact diff id");
919
+ return step.id;
920
+ });
921
+ assertProfileTrainingIsHeldOut(candidateProfile, heldOutDigests);
922
+ assertProfileReleaseWorkIsFresh(benchmark, improvement);
923
+ const experiment = sealAgentProfileImprovementExperiment({
924
+ kind: "agent-profile-improvement-experiment",
925
+ digestAlgorithm: "rfc8785-sha256",
926
+ source,
927
+ executionRef: options.executor.executionRef,
928
+ baseline: { stateDigest: baselineStateDigest },
929
+ candidate: { stateDigest: candidateStateDigest },
930
+ change,
931
+ candidateLineage: {
932
+ source: "optimizer",
933
+ parentDigests: [source.sourceDigest],
934
+ runIds: [improvement.lineage.runId],
935
+ profileDiffIds,
936
+ developmentSplitDigest: improvement.lineage.developmentSplitDigest
937
+ },
938
+ benchmark,
939
+ policy
940
+ });
941
+ const profilesByStateDigest = /* @__PURE__ */ new Map([[baselineStateDigest, profile], [candidateStateDigest, candidateProfile]]);
942
+ const preparation = profilePreparationAccounting(costLedger, preparationStartedAt);
943
+ const run = await runAgentProfileImprovementExperiment({
944
+ experiment,
945
+ ...options.maxConcurrency === void 0 ? {} : { maxConcurrency: options.maxConcurrency },
946
+ costLedger,
947
+ ...options.signal ? { signal: options.signal } : {},
948
+ execute: async (input) => {
949
+ const measuredProfile = profilesByStateDigest.get(input.stateDigest);
950
+ if (!measuredProfile) throw new Error("profile improvement execution requested an unknown profile state");
951
+ return options.executor.measure({
952
+ ...input,
953
+ profile: measuredProfile
954
+ });
955
+ }
956
+ });
957
+ const optimizationReceipt = createOptimizationActivationReceipt(improvement);
958
+ const evaluation = verifyAgentProfileImprovementExperimentComparison(measuredComparisonFromAgentProfileImprovementExperiment({
959
+ experiment,
960
+ measurements: run.measurements,
961
+ runId: options.runId,
962
+ ...options.candidate ? { candidate: options.candidate } : {},
963
+ generationsExplored: improvement.generationsExplored ?? 0,
964
+ preparation,
965
+ measurement: run.measurement,
966
+ metadata: profileImprovementMetadata(options.metadata, source, optimizationReceipt)
967
+ }));
968
+ const proposal = createAgentImprovementProposal({
969
+ runId: options.runId,
970
+ findings: proposalFindings,
971
+ evaluation,
972
+ ...options.now ? { now: options.now } : {}
973
+ });
974
+ return {
975
+ analysis,
976
+ improvement,
977
+ experiment,
978
+ measurements: run.measurements,
979
+ proposal
980
+ };
981
+ } catch (cause) {
982
+ return rethrowAfterCleanup(cause, () => improvement.dispose(), "proposeAgentProfileImprovement failed");
983
+ }
984
+ }
985
+ /** Analyze, search, then remeasure the resulting exact candidate before proposing it. */
986
+ async function proposeAgentImprovement(options) {
987
+ assertNoCallerOptimizationReceipt(options.metadata);
988
+ assertMeasuredAnalysisOptions(options.analysis);
989
+ const inputFindings = assertProposalFindings(options.improvement.findings ?? [], "agent improvement input findings");
990
+ const { analysis, findings } = await analyzeAgentImprovement(options.runId, options.analysis);
991
+ const analysisAccounting = completeAnalysisAccounting(analysis);
992
+ const proposalFindings = immutableCandidateValue([...inputFindings, ...findings]);
993
+ const improvementInput = {
994
+ ...options.improvement,
995
+ findings: proposalFindings
996
+ };
997
+ const improvement = improvementInput.surface === "code" ? await improve(improvementInput) : await improve(options.profile, improvementInput);
998
+ try {
999
+ if (improvement.decision !== "ship") throw new Error("agent improvement search did not produce a promotable candidate");
1000
+ const searchAccounting = completeImprovementSearchAccounting(analysisAccounting, improvement);
1001
+ const preparation = {
1002
+ wallDurationMs: searchAccounting.searchDurationMs,
1003
+ cost: {
1004
+ usd: searchAccounting.searchCostUsd,
1005
+ provenance: "estimated"
1006
+ }
1007
+ };
1008
+ const optimizationReceipt = improvement.mode === "method" ? createOptimizationActivationReceipt(improvement) : void 0;
1009
+ const experiment = sealAgentImprovementExperiment(await options.buildExperiment({
1010
+ analysis,
1011
+ improvement
1012
+ }), improvement);
1013
+ assertCandidateProfileBinding(options.profile, experiment.baseline.profile);
1014
+ assertImprovementCandidateBinding(improvement, experiment);
1015
+ const measured = await runAgentCandidateExperiment({
1016
+ experiment,
1017
+ runId: options.runId,
1018
+ placeCell: options.placeCell,
1019
+ ...options.maxConcurrency === void 0 ? {} : { maxConcurrency: options.maxConcurrency },
1020
+ ...options.signal ? { signal: options.signal } : {},
1021
+ ...options.candidate ? { candidate: options.candidate } : {},
1022
+ ...optimizationReceipt ? { metadata: attachOptimizationActivationReceipt(options.metadata, optimizationReceipt) } : options.metadata ? { metadata: options.metadata } : {},
1023
+ ...improvement.generationsExplored === void 0 ? {} : { generationsExplored: improvement.generationsExplored },
1024
+ preparation
1025
+ });
1026
+ const proposal = createAgentImprovementProposal({
1027
+ runId: options.runId,
1028
+ findings: proposalFindings,
1029
+ evaluation: measured.evaluation,
1030
+ ...options.now ? { now: options.now } : {}
1031
+ });
1032
+ return {
1033
+ analysis,
1034
+ improvement,
1035
+ experiment,
1036
+ measurements: measured.measurements,
1037
+ proposal
1038
+ };
1039
+ } catch (cause) {
1040
+ return rethrowAfterCleanup(cause, () => improvement.dispose(), "proposeAgentImprovement failed");
1041
+ }
1042
+ }
1043
+ function assertImprovementCandidateBinding(improvement, experiment) {
1044
+ const candidate = improvement.candidate;
1045
+ if (candidate.surface !== "code") {
1046
+ try {
1047
+ assertCandidateProfileBinding(candidate.profile, experiment.candidate.profile);
1048
+ } catch (cause) {
1049
+ throw new Error("candidate experiment does not contain the improvement winner", { cause });
1050
+ }
1051
+ return;
1052
+ }
1053
+ const surface = candidate.value;
1054
+ const code = experiment.candidate.code;
1055
+ if (typeof surface !== "object" || surface === null || surface.kind !== "code" || code.kind !== "git-patch" || code.baseCommit !== surface.baseCommit || code.baseTree !== surface.baseTree || code.candidateTree !== surface.candidateTree || code.patch.artifact.sha256 !== surface.patch.sha256 || code.patch.artifact.byteLength !== surface.patch.byteLength) throw new Error("candidate experiment does not contain the improvement winner");
1056
+ if (canonicalCandidateDigest$1(experiment.baseline.profile) !== canonicalCandidateDigest$1(experiment.candidate.profile)) throw new Error("code improvement candidate changed the agent profile");
1057
+ }
1058
+ /** Recheck one Runtime receipt against its exact signed experiment cell. */
1059
+ function verifyCandidateExecutionEvidence(input, options) {
1060
+ const experiment = verifyCandidateExperiment(options.experiment);
1061
+ const bundle = experiment[options.arm];
1062
+ const task = experiment.benchmark.tasks[options.benchmarkCell.taskIndex];
1063
+ const index = options.benchmarkCell.taskIndex * experiment.benchmark.suite.reps + options.benchmarkCell.repetition;
1064
+ if (!task || options.benchmarkCell.suiteDigest !== experiment.benchmark.suite.digest || options.seed !== experiment.benchmark.suite.seeds[index]) throw new Error("candidate execution evidence points outside its signed experiment");
1065
+ const evidence = verifyCanonicalCandidateDocument(candidateExecutionEvidenceSchema.parse(input), "candidate execution evidence");
1066
+ const materialization = verifyCanonicalCandidateDocument(agentCandidateMaterializationReceiptSchema.parse(evidence.materializationReceipt), "candidate materialization receipt");
1067
+ const receipt = verifyCanonicalCandidateDocument(agentCandidateRunReceiptSchema.parse(evidence.receipt), "candidate run receipt");
1068
+ const plan = materialization.executionPlan;
1069
+ const cell = plan.material.runCell;
1070
+ const attempt = options.attempt ?? 1;
1071
+ if (cell.experimentDigest !== experiment.digest || cell.arm !== options.arm || cell.bundleDigest !== bundle.digest || cell.suiteDigest !== experiment.benchmark.suite.digest || cell.taskDigest !== task.digest || cell.taskIndex !== options.benchmarkCell.taskIndex || cell.repetition !== options.benchmarkCell.repetition || cell.seed !== options.seed || cell.attempt !== attempt || canonicalCandidateDigest$1(omitTopLevelDigest(cell)) !== cell.digest) throw new Error("candidate execution receipt substituted its signed experiment cell");
1072
+ assertCapturedInput(materialization.benchmark.suite, experiment.benchmark.suite, "benchmark suite");
1073
+ assertCapturedInput(materialization.benchmark.task, task, "benchmark task");
1074
+ assertEvidenceMaterialDigest(plan, "candidate execution plan");
1075
+ assertEvidenceMaterialDigest(materialization.profileActivation.profilePlan, "candidate profile plan");
1076
+ const expectedProfilePlan = materializeAgentCandidateProfilePlan({
1077
+ profile: bundle.profile,
1078
+ harness: bundle.execution.harness,
1079
+ launch: bundle.execution.launch,
1080
+ workspace: bundle.execution.cwd.workspace,
1081
+ workspaces: plan.material.workspaces,
1082
+ resolvedResources: options.resolvedResources
1083
+ });
1084
+ const activation = parseAgentCandidateProfileActivation(materialization.profileActivation, materialization.profileActivation.profilePlan.digest);
1085
+ const regeneratedActivation = createAgentCandidateProfileActivation(expectedProfilePlan, materialization.profileActivation.profilePlan);
1086
+ if (activation.digest !== regeneratedActivation.digest) throw new Error("candidate profile activation does not match the experiment bundle");
1087
+ if (materialization.bundleDigest !== bundle.digest || receipt.bundleDigest !== bundle.digest || receipt.runCellDigest !== cell.digest || receipt.materializationReceiptDigest !== materialization.digest || receipt.executionPlanDigest !== plan.digest) throw new Error("candidate execution evidence does not bind one exact Runtime run");
1088
+ assertEvidenceMaterialDigest(receipt.modelSettlement, "candidate model settlement");
1089
+ assertEvidenceMaterialDigest(receipt.taskOutcome, "candidate task outcome");
1090
+ assertEvidenceMaterialDigest(receipt.benchmarkResult, "candidate benchmark result");
1091
+ return immutableCandidateValue(evidence);
1092
+ }
1093
+ function assertExactExperimentInput(input, experiment, bundle) {
1094
+ const task = experiment.benchmark.tasks[input.benchmarkCell.taskIndex];
1095
+ const index = input.benchmarkCell.taskIndex * experiment.benchmark.suite.reps + input.benchmarkCell.repetition;
1096
+ if (input.experiment.digest !== experiment.digest || input.bundle.digest !== bundle.digest || !task || input.task.digest !== task.digest || input.benchmarkCell.suiteDigest !== experiment.benchmark.suite.digest || input.seed !== experiment.benchmark.suite.seeds[index]) throw new Error("Runtime received a substituted candidate experiment cell");
1097
+ }
1098
+ function assertCapturedInput(captured, expected, label) {
1099
+ const bytes = canonicalCandidateBytes$1(omitTopLevelDigest(expected));
1100
+ if (captured.digest !== expected.digest || captured.material.sha256 !== expected.digest || captured.material.byteLength !== bytes.byteLength) throw new Error(`candidate materialization substituted its ${label}`);
1101
+ }
1102
+ function assertEvidenceMaterialDigest(evidence, label) {
1103
+ const bytes = canonicalCandidateBytes$1(evidence.material);
1104
+ if (canonicalCandidateDigest$1(evidence.material) !== evidence.digest || evidence.artifact.sha256 !== evidence.digest || evidence.artifact.byteLength !== bytes.byteLength) throw new Error(`${label} digest does not match its canonical material`);
1105
+ }
1106
+ //#endregion
689
1107
  //#region src/intelligence/exact-process-candidate.ts
690
1108
  /** Candidate surfaces implemented by the neutral exact-process executor. */
691
1109
  const exactProcessCandidateExperimentExecutionSupport = Object.freeze({
@@ -1104,9 +1522,9 @@ function withIntelligence(agent, config) {
1104
1522
  * Tangle Intelligence SDK — trace capture plus reviewable improvement.
1105
1523
  *
1106
1524
  * The client keeps live-agent trace delivery best-effort. The separate
1107
- * improvement-cycle exports analyze completed traces, run a signed baseline
1108
- * versus candidate experiment, bind review to its result, and activate only
1109
- * the exact measured candidate.
1525
+ * improvement-cycle exports analyze completed traces and run a signed baseline
1526
+ * versus candidate experiment. Activation exports bind review to its result
1527
+ * and activate only the exact measured candidate.
1110
1528
  *
1111
1529
  * 1. OBSERVE — wrap a generic agent and export one trace span per call to
1112
1530
  * Tangle Intelligence, swallowing every export failure so a live agent
@@ -1398,6 +1816,6 @@ function withMissingAttributes(span, attributes) {
1398
1816
  };
1399
1817
  }
1400
1818
  //#endregion
1401
- 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 };
1819
+ export { CapabilityNotAdmittedError, agentImprovementProfileDiffs, agentImprovementProfileSurfaceDigest, agentImprovementProfileSurfaceInput, agentImprovementTargetProfileDiffs, compileEffort, composeCertifiedPrompt, createAgentImprovementActivation, createAgentImprovementActivationResult, createAgentImprovementProposal, createCertifiedPromptSource, createExactProcessCandidateExperimentExecutor, createIntelligenceClient, createOptimizationActivationReceipt, createProtectedExactProcessCandidateExperimentExecutor, defaultRedactor, exactProcessCandidateExperimentExecutionSupport, executeAgentCandidateExperimentCell, executeAgentImprovementActivation, isAgentImprovementProfileSurface, isAgentProfileMeasuredSurface, isIntelligenceOff, manifestFromProfile, optimizationActivationReceiptFromMetadata, parseAgentCandidateProfileActivation as parseCandidateProfileMaterialization, prepareAgentImprovementProfileActivation, proposeAgentImprovement, proposeAgentProfileImprovement, proposeAuthoredAgentProfileImprovement, pullCertified, resolveEffort, reviewAgentImprovementProposal, runAgentCandidateExperiment, verifyAgentImprovementActivation, verifyAgentImprovementActivationResult, verifyAgentImprovementProposal, verifyAgentImprovementReview, verifyCandidateExecutionEvidence, withIntelligence };
1402
1820
 
1403
1821
  //# sourceMappingURL=intelligence.js.map