@tangle-network/agent-runtime 0.277.0 → 0.279.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 (59) hide show
  1. package/dist/{activation-puw9_ahP.d.ts → activation-B5NExoOz.d.ts} +137 -105
  2. package/dist/{activation-CbxhVtVV.js → activation-BkUdrvqh.js} +2 -2
  3. package/dist/{activation-CbxhVtVV.js.map → activation-BkUdrvqh.js.map} +1 -1
  4. package/dist/agent.d.ts +2 -2
  5. package/dist/agent.js +2 -2
  6. package/dist/{coordination-driver-ZfUf-H4H.js → coordination-driver-BBL_OgRw.js} +2 -2
  7. package/dist/{coordination-driver-ZfUf-H4H.js.map → coordination-driver-BBL_OgRw.js.map} +1 -1
  8. package/dist/{delegate-DXOyzIq0.js → delegate-CZc7B-Tl.js} +2 -2
  9. package/dist/{delegate-DXOyzIq0.js.map → delegate-CZc7B-Tl.js.map} +1 -1
  10. package/dist/durable.d.ts +2 -2
  11. package/dist/durable.js +2 -2
  12. package/dist/{graph-sGWwXC6E.js → graph-Ci8Ufs_f.js} +4 -4
  13. package/dist/{graph-sGWwXC6E.js.map → graph-Ci8Ufs_f.js.map} +1 -1
  14. package/dist/{improvement-cycle-DQyN0__A.js → improvement-cycle-Bi43xCVa.js} +649 -213
  15. package/dist/improvement-cycle-Bi43xCVa.js.map +1 -0
  16. package/dist/{index-CmAFFnsd.d.ts → index-Dm8SHDGW.d.ts} +9 -7
  17. package/dist/index.d.ts +9 -9
  18. package/dist/index.js +55 -14
  19. package/dist/index.js.map +1 -1
  20. package/dist/intelligence.d.ts +3 -3
  21. package/dist/intelligence.js +3 -3
  22. package/dist/kernel.d.ts +4 -4
  23. package/dist/kernel.js +8 -8
  24. package/dist/{loop-runner-bin-BTnEDWj3.js → loop-runner-bin-C9FJshTP.js} +3 -3
  25. package/dist/{loop-runner-bin-BTnEDWj3.js.map → loop-runner-bin-C9FJshTP.js.map} +1 -1
  26. package/dist/{loop-runner-bin-DGUASE9O.d.ts → loop-runner-bin-D6khQtoC.d.ts} +3 -3
  27. package/dist/loop-runner-bin.d.ts +1 -1
  28. package/dist/loop-runner-bin.js +1 -1
  29. package/dist/mcp/bin.js +3 -3
  30. package/dist/mcp/index.d.ts +5 -5
  31. package/dist/mcp/index.js +4 -4
  32. package/dist/{openai-tools-Gc8p4PBq.d.ts → openai-tools-H8QPhTVE.d.ts} +2 -2
  33. package/dist/platform.d.ts +91 -1
  34. package/dist/platform.js +162 -6
  35. package/dist/platform.js.map +1 -1
  36. package/dist/profiles.d.ts +2 -2
  37. package/dist/{provision-supervisor-BgjtrTlv.js → provision-supervisor-BvnihiyB.js} +3 -3
  38. package/dist/{provision-supervisor-BgjtrTlv.js.map → provision-supervisor-BvnihiyB.js.map} +1 -1
  39. package/dist/{runtime-DoFvrisL.js → runtime-DsAHXig2.js} +8 -8
  40. package/dist/{runtime-DoFvrisL.js.map → runtime-DsAHXig2.js.map} +1 -1
  41. package/dist/{server-D2d83_iS.js → server-Dyc1zvug.js} +3 -3
  42. package/dist/{server-D2d83_iS.js.map → server-Dyc1zvug.js.map} +1 -1
  43. package/dist/{stream-agent-turn-BqU5Sfbw.d.ts → stream-agent-turn-Bk79CnTw.d.ts} +2 -2
  44. package/dist/{structural-rollout-VR-j5t9d.js → structural-rollout-D-0X6lsU.js} +2 -2
  45. package/dist/{structural-rollout-VR-j5t9d.js.map → structural-rollout-D-0X6lsU.js.map} +1 -1
  46. package/dist/{substrate-CfE3oUB9.d.ts → substrate-CHQ5GYnU.d.ts} +2 -2
  47. package/dist/{supervise-BoCOUAmr.js → supervise-DBQdrp7H.js} +25 -11
  48. package/dist/supervise-DBQdrp7H.js.map +1 -0
  49. package/dist/{supervisor-CjNbOcLO.js → supervisor-DtlPj9me.js} +339 -72
  50. package/dist/supervisor-DtlPj9me.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/dist/{types-CI7ve2sA.d.ts → types-D56jQad-.d.ts} +70 -59
  56. package/package.json +10 -7
  57. package/dist/improvement-cycle-DQyN0__A.js.map +0 -1
  58. package/dist/supervise-BoCOUAmr.js.map +0 -1
  59. package/dist/supervisor-CjNbOcLO.js.map +0 -1
@@ -1,6 +1,6 @@
1
- import { $i as detachedSnapshot, Ia as armDeadlineTimer, Ot as createExecutor, Qr as runSettledCommand, br as linkAbort, ui as terminateProcessTreeAndConfirm, xr as runAbortable } from "./supervisor-CjNbOcLO.js";
1
+ import { $i as detachedSnapshot, At as createExecutor, Cr as runAbortable, Ia as armDeadlineTimer, Qr as runSettledCommand, Sr as linkAbort, ui as terminateProcessTreeAndConfirm } from "./supervisor-DtlPj9me.js";
2
2
  import { i as ConfigError } from "./errors-DodWX-cb.js";
3
- import { A as collectAgentTurn, O as optimizerMethod, a as defaultStructuralRolloutPolicy, j as streamAgentTurn } from "./structural-rollout-VR-j5t9d.js";
3
+ import { A as collectAgentTurn, O as optimizerMethod, a as defaultStructuralRolloutPolicy, j as streamAgentTurn } from "./structural-rollout-D-0X6lsU.js";
4
4
  import { a as concreteProfileModel, t as assertExecutableAgentProfile } from "./model-policy-BbSCSak0.js";
5
5
  import { A as verifyCanonicalCandidateDocument, C as canonicalCandidateDigest$1, D as immutableCandidateValue, O as omitTopLevelDigest, S as canonicalCandidateBytes$1, k as sha256Bytes$1, w as canonicalCandidateDocument } from "./workspace-archive-C9lgf77y.js";
6
6
  import { i as syncDurableDirectory, r as publishExclusiveDurableFile } from "./durable-file-DWQA4ooo.js";
@@ -15,10 +15,11 @@ import { constants, existsSync, mkdtempSync, readFileSync, readdirSync, realpath
15
15
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
16
16
  import { chmod, mkdir, mkdtemp, open, realpath, rm, writeFile } from "node:fs/promises";
17
17
  import { tmpdir } from "node:os";
18
- import { isDeepStrictEqual } from "node:util";
18
+ import { redact } from "@tangle-network/agent-eval/traces";
19
19
  import { assertProposalFindings } from "@tangle-network/agent-eval/analyst";
20
- import { campaignScenarioIdentity, campaignSplitDigestFromIdentities, compareOptimizationMethods, decodeExternalTextCandidate, gitWorktreeAdapter, readExternalOptimizerObservationArtifact, readGepaCandidatePopulationArtifact, verifyCodeSurface } from "@tangle-network/agent-eval/campaign";
20
+ import { SearchRecorder, campaignCellSearchResult, campaignScenarioIdentity, campaignSplitDigestFromIdentities, compareOptimizationMethods, createRunCostLedger, fsCampaignStorage, gitWorktreeAdapter, incumbent, isProposedCandidate, openSearchLedger, renderSearchSummary, resolveRunDir, runCampaign, runSearch, searchClaimReserveUsd, searchProposalExecution, searchProposerView, searchReceiptAccounting, uniform, verifyCodeSurface, verifySearchHistoryArtifact } from "@tangle-network/agent-eval/campaign";
21
21
  import { measuredComparisonFromAgentProfileImprovementExperiment, measuredComparisonFromCandidateExperiment, runAgentProfileImprovementExperiment, runCandidateExperiment, sealAgentProfileImprovementExperiment, sealAgentProfileImprovementSuite, sealAgentProfileImprovementTask, sealCandidateExperiment, selfImprove, verifyAgentProfileImprovementExperimentComparison, verifyCandidateExperiment, verifyCandidateExperimentComparison } from "@tangle-network/agent-eval/contract";
22
+ import { defineEvaluationClaim, summarizeEvaluationUnits } from "@tangle-network/agent-eval/experiment";
22
23
  //#region src/improvement/worktree-tree.ts
23
24
  /**
24
25
  * The exact content of a candidate worktree, as a Git tree object.
@@ -1585,37 +1586,6 @@ async function runCodeImprovement(opts) {
1585
1586
  };
1586
1587
  }
1587
1588
  //#endregion
1588
- //#region src/improvement/candidate-validation.ts
1589
- /** One spelling of the execution-identity rule for optimization, training, and the harness. */
1590
- function parseExecutionRef(value, label) {
1591
- const parsed = sha256DigestSchema.safeParse(value);
1592
- if (!parsed.success) throw new ConfigError(`${label}: executionRef must be a lowercase sha256:<64 hex> digest`);
1593
- return parsed.data;
1594
- }
1595
- /** Validate the callback itself before any optimizer, trainer, or candidate work starts. */
1596
- function assertCandidateValidator(validator) {
1597
- if (validator !== void 0 && typeof validator !== "function") throw new ConfigError("validateCandidate must be a function when present");
1598
- }
1599
- /** A validator accepts synchronously by returning void, or rejects by throwing. */
1600
- function validateProfileCandidate(validator, input) {
1601
- assertCandidateValidator(validator);
1602
- const result = validator?.(Object.freeze(input));
1603
- if (result !== void 0) {
1604
- Promise.resolve(result).catch(() => {});
1605
- throw new ConfigError("candidate validators must return void synchronously or throw");
1606
- }
1607
- }
1608
- /**
1609
- * Refuse exact held-out content digests already declared in this profile's training lineage.
1610
- * Both training and trainer-visible validation rows are exposure. This is an exact
1611
- * provenance check, not fuzzy decontamination or proof that undeclared training was fresh.
1612
- */
1613
- function assertProfileTrainingIsHeldOut(profile, heldOutDigests) {
1614
- const training = profile.metadata?.training;
1615
- if (!training) return;
1616
- for (const receipt of [training.receipt, ...training.ancestors]) if (receipt.dataset.tasks.some((task) => heldOutDigests.has(task.contentDigest))) throw new ConfigError("known training exposure overlaps held-out evaluation");
1617
- }
1618
- //#endregion
1619
1589
  //#region src/improvement/method-controls.ts
1620
1590
  const methodRuntimeControls = Symbol("agent-runtime.improvement.method-runtime-controls");
1621
1591
  function withMethodRuntimeControls(method, controls) {
@@ -1711,6 +1681,49 @@ function methodHistoricalReceipts(ledger, optimizerRun, invocationId) {
1711
1681
  return ledger.list({ tags: { optimizerRun } }).filter((receipt) => receipt.tags?.[INVOCATION_TAG] !== invocationId);
1712
1682
  }
1713
1683
  //#endregion
1684
+ //#region src/improvement/candidate-validation.ts
1685
+ /** One spelling of the execution-identity rule for optimization, training, and the harness. */
1686
+ function parseExecutionRef(value, label) {
1687
+ const parsed = sha256DigestSchema.safeParse(value);
1688
+ if (!parsed.success) throw new ConfigError(`${label}: executionRef must be a lowercase sha256:<64 hex> digest`);
1689
+ return parsed.data;
1690
+ }
1691
+ /** Validate the callback itself before any optimizer, trainer, or candidate work starts. */
1692
+ function assertCandidateValidator(validator) {
1693
+ if (validator !== void 0 && typeof validator !== "function") throw new ConfigError("validateCandidate must be a function when present");
1694
+ }
1695
+ /** A validator accepts synchronously by returning void, or rejects by throwing. */
1696
+ function validateProfileCandidate(validator, input) {
1697
+ assertCandidateValidator(validator);
1698
+ const result = validator?.(Object.freeze(input));
1699
+ if (result !== void 0) {
1700
+ Promise.resolve(result).catch(() => {});
1701
+ throw new ConfigError("candidate validators must return void synchronously or throw");
1702
+ }
1703
+ }
1704
+ /**
1705
+ * Refuse exact held-out content digests already declared in this profile's training lineage.
1706
+ * Both training and trainer-visible validation rows are exposure. This is an exact
1707
+ * provenance check, not fuzzy decontamination or proof that undeclared training was fresh.
1708
+ */
1709
+ function assertProfileTrainingIsHeldOut(profile, heldOutDigests) {
1710
+ const training = profile.metadata?.training;
1711
+ if (!training) return;
1712
+ for (const receipt of [training.receipt, ...training.ancestors]) if (receipt.dataset.tasks.some((task) => heldOutDigests.has(task.contentDigest))) throw new ConfigError("known training exposure overlaps held-out evaluation");
1713
+ }
1714
+ /**
1715
+ * JSON paths of credential and private values in candidate content, found by
1716
+ * the redaction core, which names each value it would change. A candidate that
1717
+ * leaves Runtime (an external optimizer, a search ledger) is refused on any.
1718
+ */
1719
+ function privateValuePaths(values) {
1720
+ return [...new Set(values.flatMap((value) => redact(value).report.findings.map((finding) => jsonPathOf(finding.path))))];
1721
+ }
1722
+ /** `/remote/url` or `/tools/0/env` as `$.remote.url` or `$.tools[0].env`. */
1723
+ function jsonPathOf(pointer) {
1724
+ return pointer.split("/").slice(1).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).reduce((path, segment) => /^\d+$/.test(segment) ? `${path}[${segment}]` : `${path}.${segment}`, "$");
1725
+ }
1726
+ //#endregion
1714
1727
  //#region src/improvement/method-identity.ts
1715
1728
  function buildMethodEvaluationIdentity(input) {
1716
1729
  const optimizationReps = input.optimizationRunOptions?.reps ?? 1;
@@ -1777,150 +1790,23 @@ function judgeDescriptor(judge) {
1777
1790
  };
1778
1791
  }
1779
1792
  //#endregion
1780
- //#region src/improvement/method-execution.ts
1781
- function resolveOptimizationMethod(source, context) {
1782
- const method = typeof source === "function" ? source(context) : source;
1783
- if (!method || typeof method !== "object" || typeof method.name !== "string" || method.name.trim() !== method.name || method.name.length === 0 || typeof method.optimize !== "function") throw new ConfigError("improve(): method must be a complete OptimizationMethod with a trimmed name and optimize(input)");
1784
- return method;
1785
- }
1786
- function materializationError(error) {
1787
- if (error instanceof Error) return {
1788
- name: error.name,
1789
- message: error.message
1790
- };
1791
- return {
1792
- name: "Error",
1793
- message: typeof error === "string" ? error : "candidate materialization threw a non-Error value"
1794
- };
1795
- }
1796
- function profileCandidatePopulation(provenance, baselineProfile, materializeProfile, winnerSurface, storage) {
1797
- const observationSummary = provenance?.observations;
1798
- const graphSummary = provenance?.gepaCandidatePopulation;
1799
- if (!observationSummary && !graphSummary) return Object.freeze({
1800
- status: "unavailable",
1801
- reason: "method-did-not-report-candidate-population"
1802
- });
1803
- const observations = observationSummary ? readExternalOptimizerObservationArtifact({
1804
- summary: observationSummary,
1805
- ...storage ? { storage } : {}
1806
- }) : void 0;
1807
- const graph = graphSummary ? readGepaCandidatePopulationArtifact({ summary: graphSummary }) : void 0;
1808
- if (!graph && (observations?.candidates.length ?? 0) === 0) return Object.freeze({
1809
- status: "unavailable",
1810
- reason: "method-did-not-report-candidate-population"
1811
- });
1812
- const entries = /* @__PURE__ */ new Map();
1813
- const entryFor = (candidateDigest, value) => {
1814
- const existing = entries.get(candidateDigest);
1815
- if (existing) {
1816
- if (!isDeepStrictEqual(existing.value, value)) throw new ConfigError(`improve(): optimizer artifacts disagree on candidate ${candidateDigest}`);
1817
- return existing;
1818
- }
1819
- const entry = {
1820
- candidateDigest,
1821
- value: immutableCandidateValue(value),
1822
- lineageNodes: []
1823
- };
1824
- entries.set(candidateDigest, entry);
1825
- return entry;
1826
- };
1827
- for (const submitted of observations?.candidates ?? []) {
1828
- const entry = entryFor(submitted.candidateDigest, decodeExternalTextCandidate(submitted.candidate));
1829
- entry.observation = {
1830
- proposalSequence: submitted.proposalSequence,
1831
- artifact: {
1832
- path: submitted.provenance.path,
1833
- sha256: submitted.provenance.sha256
1834
- }
1835
- };
1836
- }
1837
- for (const graphCandidate of graph?.candidates ?? []) entryFor(graphCandidate.candidateDigest, decodeExternalTextCandidate(graphCandidate.candidate)).lineageNodes.push({
1838
- index: graphCandidate.index,
1839
- parentIndices: [...graphCandidate.parentIndices],
1840
- aggregateScore: graphCandidate.aggregateScore,
1841
- selectionScores: graphCandidate.selectionScores.map((score) => ({ ...score })),
1842
- discoveryEvaluationCount: graphCandidate.discoveryEvaluationCount
1843
- });
1844
- if (graph) {
1845
- const best = graph.candidates.find((candidate) => candidate.index === graph.bestIndex);
1846
- if (!best) throw new ConfigError(`improve(): GEPA candidate population has no bestIndex node ${graph.bestIndex}`);
1847
- if (!isDeepStrictEqual(decodeExternalTextCandidate(best.candidate), winnerSurface)) throw new ConfigError("improve(): method winner does not equal the verified GEPA bestIndex candidate");
1848
- } else if (![...entries.values()].some((entry) => isDeepStrictEqual(entry.value, winnerSurface))) throw new ConfigError("improve(): method winner does not appear in the verified optimizer observations");
1849
- let materializedCandidates = 0;
1850
- let refusedCandidates = 0;
1851
- const candidates = [...entries.values()].map((entry) => {
1852
- const source = {
1853
- candidateDigest: entry.candidateDigest,
1854
- ...entry.observation ? { observation: entry.observation } : {},
1855
- lineage: entry.lineageNodes.length > 0 && graph ? {
1856
- status: "available",
1857
- artifact: {
1858
- path: graph.summary.path,
1859
- sha256: graph.summary.sha256
1860
- },
1861
- nodes: entry.lineageNodes
1862
- } : {
1863
- status: "unavailable",
1864
- reason: "optimizer-did-not-report-candidate-lineage"
1865
- }
1866
- };
1867
- const surfaceDigest = canonicalCandidateDigest$1(entry.value);
1868
- let candidateProfile;
1869
- try {
1870
- candidateProfile = materializeProfile(entry.value);
1871
- } catch (error) {
1872
- refusedCandidates += 1;
1873
- return {
1874
- status: "refused",
1875
- source,
1876
- value: entry.value,
1877
- surfaceDigest,
1878
- error: materializationError(error)
1879
- };
1880
- }
1881
- const profileDigest = canonicalAgentProfileDigest(candidateProfile);
1882
- const diffs = diffAgentProfiles(baselineProfile, candidateProfile);
1883
- if (canonicalAgentProfileDigest(diffs.reduce(applyAgentProfileDiff, baselineProfile)) !== profileDigest) throw new ConfigError(`improve(): Interface profile diffs do not reproduce optimizer candidate ${entry.candidateDigest}`);
1884
- materializedCandidates += 1;
1885
- return {
1886
- status: "materialized",
1887
- source,
1888
- value: entry.value,
1889
- surfaceDigest,
1890
- profile: candidateProfile,
1891
- profileDigest,
1892
- diffs,
1893
- diffDigests: diffs.map(canonicalCandidateDigest$1)
1894
- };
1895
- });
1896
- return immutableCandidateValue({
1897
- status: "available",
1898
- source: {
1899
- ...observations ? { observations: {
1900
- path: observations.summary.path,
1901
- sha256: observations.summary.sha256
1902
- } } : {},
1903
- ...graph ? { gepaCandidateGraph: {
1904
- path: graph.summary.path,
1905
- sha256: graph.summary.sha256,
1906
- bestIndex: graph.bestIndex
1907
- } } : {}
1908
- },
1909
- uniqueCandidates: entries.size,
1910
- observedCandidates: observations?.candidates.length ?? 0,
1911
- gepaCandidateNodes: graph?.candidates.length ?? 0,
1912
- materializedCandidates,
1913
- refusedCandidates,
1914
- candidates
1915
- });
1916
- }
1917
- async function runMethodImprovement(profile, opts) {
1918
- const { surface = "prompt", executionRef: inputExecutionRef, method: methodSource, agent, validateCandidate, findings: inputFindings = [], skills, profileComponents, optimizationRunOptions, minimumLift = 0, ...comparisonOptions } = opts;
1793
+ //#region src/improvement/profile-improvement.ts
1794
+ /**
1795
+ * What every profile improvement prepares before any optimizer or search runs:
1796
+ * the exact surface and its baseline, the evaluation identity, identified
1797
+ * judges, the identities a search ledger records, and one materializer that
1798
+ * admits a candidate only after the held-out and caller checks. `improve()`
1799
+ * with an external method and with `searchMethod` share it, so a candidate is
1800
+ * materialized and admitted the same way on both paths.
1801
+ */
1802
+ function prepareProfileImprovement(profile, input) {
1803
+ const { surface = "prompt", validateCandidate, skills, profileComponents, minimumLift = 0 } = input;
1919
1804
  assertCandidateValidator(validateCandidate);
1920
1805
  if (!Number.isFinite(minimumLift) || minimumLift < 0) throw new ConfigError("improve(): minimumLift must be a finite number greater than or equal to 0");
1921
1806
  if (profileComponents && surface !== "agent-profile") throw new ConfigError("improve(): profileComponents is valid only with surface 'agent-profile'");
1922
- const executionRef = parseExecutionRef(inputExecutionRef, "improve()");
1923
- const findings = immutableCandidateValue([...assertProposalFindings(inputFindings, "improve() method findings")]);
1807
+ if (input.subject !== void 0 && (typeof input.subject !== "string" || !input.subject.trim() || input.subject !== input.subject.trim())) throw new ConfigError("improve(): subject must be a trimmed non-empty string");
1808
+ const executionRef = parseExecutionRef(input.executionRef, "improve()");
1809
+ const findings = immutableCandidateValue([...assertProposalFindings(input.findings ?? [], "improve() method findings")]);
1924
1810
  const preparedSurface = prepareProfileSurface(profile, surface, skills, profileComponents);
1925
1811
  const baselineSurface = preparedSurface.surface;
1926
1812
  const baselineValue = immutableCandidateValue(preparedSurface.value);
@@ -1933,28 +1819,25 @@ async function runMethodImprovement(profile, opts) {
1933
1819
  skills,
1934
1820
  validateCandidate,
1935
1821
  findings,
1936
- trainScenarios: comparisonOptions.trainScenarios,
1937
- selectionScenarios: comparisonOptions.selectionScenarios,
1938
- testScenarios: comparisonOptions.testScenarios,
1939
- judges: comparisonOptions.judges,
1940
- seed: comparisonOptions.seed,
1941
- reps: comparisonOptions.reps,
1942
- costCeiling: comparisonOptions.costCeiling,
1943
- optimizationRunOptions
1822
+ trainScenarios: input.trainScenarios,
1823
+ selectionScenarios: input.selectionScenarios,
1824
+ testScenarios: input.testScenarios,
1825
+ judges: input.judges,
1826
+ seed: input.seed,
1827
+ reps: input.reps,
1828
+ costCeiling: input.costCeiling,
1829
+ optimizationRunOptions: input.optimizationRunOptions
1944
1830
  });
1945
- const { evaluationRef, developmentSplitDigest, finalTestSplitDigest, scenarioPartitions } = identity;
1946
- const dispatchRef = `improve:${evaluationRef}`;
1947
- const identifiedJudges = comparisonOptions.judges.map((judge, index) => Object.freeze({
1831
+ const judges = input.judges.map((judge, index) => Object.freeze({
1948
1832
  ...judge,
1949
1833
  judgeVersion: canonicalCandidateDigest$1({
1950
- evaluationRef,
1834
+ evaluationRef: identity.evaluationRef,
1951
1835
  descriptor: identity.judgeDescriptors[index]
1952
1836
  })
1953
1837
  }));
1954
1838
  const rawMaterializeProfile = createProfileCandidateMaterializer(profile, surface, baselineSurface, skills, profileComponents);
1955
- const runtimeInvocationId = `runtime-optimization:${randomUUID()}`;
1956
1839
  const baselineSurfaceDigest = canonicalCandidateDigest$1(baselineSurface);
1957
- const heldOutDigests = new Set(scenarioPartitions.finalTest.map((task) => task.scenarioDigest));
1840
+ const heldOutDigests = new Set(identity.scenarioPartitions.finalTest.map((task) => task.scenarioDigest));
1958
1841
  const validatedCandidates = /* @__PURE__ */ new Set();
1959
1842
  const validateMaterialized = (validator, candidate, candidateSurface, isBaseline) => {
1960
1843
  const prepared = prepareProfileSurface(candidate, surface, skills, profileComponents);
@@ -1966,28 +1849,96 @@ async function runMethodImprovement(profile, opts) {
1966
1849
  isBaseline
1967
1850
  });
1968
1851
  };
1852
+ const admitCandidate = (candidate, candidateSurface) => {
1853
+ const candidateDigest = canonicalCandidateDigest$1(candidateSurface);
1854
+ if (validatedCandidates.has(candidateDigest)) return;
1855
+ assertProfileTrainingIsHeldOut(candidate, heldOutDigests);
1856
+ validateMaterialized(validateCandidate, candidate, immutableCandidateValue(candidateSurface), candidateDigest === baselineSurfaceDigest);
1857
+ validatedCandidates.add(candidateDigest);
1858
+ };
1969
1859
  const materializeProfile = (candidateSurface) => {
1970
1860
  const candidate = rawMaterializeProfile(candidateSurface);
1971
- const candidateDigest = canonicalCandidateDigest$1(candidateSurface);
1972
- if (!validatedCandidates.has(candidateDigest)) {
1973
- assertProfileTrainingIsHeldOut(candidate, heldOutDigests);
1974
- validateMaterialized(validateCandidate, candidate, immutableCandidateValue(candidateSurface), candidateDigest === baselineSurfaceDigest);
1975
- validatedCandidates.add(candidateDigest);
1976
- }
1861
+ admitCandidate(candidate, candidateSurface);
1977
1862
  return candidate;
1978
1863
  };
1979
1864
  materializeProfile(baselineSurface);
1865
+ return {
1866
+ profile,
1867
+ surface,
1868
+ executionRef,
1869
+ findings,
1870
+ minimumLift,
1871
+ baselineSurface,
1872
+ baselineValue,
1873
+ baselineProfileDigest,
1874
+ identity,
1875
+ invocationId: `runtime-optimization:${randomUUID()}`,
1876
+ judges,
1877
+ searchIdentity: Object.freeze({
1878
+ subject: input.subject ?? profile.name ?? "agent-profile",
1879
+ agent: {
1880
+ uri: "agent-runtime:improve-execution-ref",
1881
+ revision: executionRef
1882
+ },
1883
+ judge: {
1884
+ uri: "agent-runtime:improve-judges",
1885
+ revision: canonicalCandidateDigest$1(identity.judgeDescriptors)
1886
+ },
1887
+ model: profileModel(profile)
1888
+ }),
1889
+ surfaceOf: (candidate) => prepareProfileSurface(candidate, surface, skills, profileComponents).surface,
1890
+ materializeCandidate: rawMaterializeProfile,
1891
+ admitCandidate,
1892
+ materializeProfile,
1893
+ validateMaterialized
1894
+ };
1895
+ }
1896
+ /** The profile's model hint as a moving alias; each cell records what it resolved. */
1897
+ function profileModel(profile) {
1898
+ const hint = profile.model?.default;
1899
+ if (!hint) return {
1900
+ provider: "unspecified",
1901
+ alias: "unspecified",
1902
+ unknown: "the profile names no model; each cell records the model it resolved"
1903
+ };
1904
+ return {
1905
+ provider: profile.model?.provider ?? "unspecified",
1906
+ alias: hint,
1907
+ unknown: "the profile names a model hint, not a snapshot; each cell records the model it resolved"
1908
+ };
1909
+ }
1910
+ //#endregion
1911
+ //#region src/improvement/method-execution.ts
1912
+ function resolveOptimizationMethod(source, context) {
1913
+ const method = typeof source === "function" ? source(context) : source;
1914
+ if (!method || typeof method !== "object" || typeof method.name !== "string" || method.name.trim() !== method.name || method.name.length === 0 || typeof method.optimize !== "function") throw new ConfigError("improve(): method must be a complete OptimizationMethod with a trimmed name and optimize(input)");
1915
+ return method;
1916
+ }
1917
+ /**
1918
+ * Run one complete method, then compare its winner with the baseline on the
1919
+ * held-out test split. A method that records its search (GEPA and SkillOpt do
1920
+ * through `officialGepa` and `officialSkillOpt`) must close its ledger; Runtime
1921
+ * replays the bytes and returns the receipt. A method that records none
1922
+ * returns `searchHistory: null`: its lineage is unknown, not empty.
1923
+ */
1924
+ async function runMethodImprovement(profile, opts) {
1925
+ const { surface: _surface, executionRef: _executionRef, method: methodSource, agent, validateCandidate: _validateCandidate, findings: _findings, skills: _skills, profileComponents: _profileComponents, optimizationRunOptions, minimumLift: _minimumLift, subject: _subject, ...comparisonOptions } = opts;
1926
+ const prepared = prepareProfileImprovement(profile, opts);
1927
+ const { surface, identity, invocationId, baselineSurface, materializeProfile, validateMaterialized, minimumLift } = prepared;
1928
+ const { evaluationRef, developmentSplitDigest, finalTestSplitDigest, scenarioPartitions } = identity;
1929
+ const dispatchRef = `improve:${evaluationRef}`;
1980
1930
  const method = resolveOptimizationMethod(methodSource, {
1981
1931
  profile,
1982
1932
  evaluationRef,
1983
1933
  surface,
1984
1934
  baselineSurface,
1985
- baselineValue,
1986
- findings
1935
+ baselineValue: prepared.baselineValue,
1936
+ findings: prepared.findings,
1937
+ searchIdentity: prepared.searchIdentity
1987
1938
  });
1988
1939
  const costScope = {
1989
- evaluationRef,
1990
- invocationId: runtimeInvocationId
1940
+ evaluationRef: identity.evaluationRef,
1941
+ invocationId
1991
1942
  };
1992
1943
  const invoke = async (current, input) => {
1993
1944
  const controls = methodRuntimeControlsOf(current);
@@ -2025,7 +1976,7 @@ async function runMethodImprovement(profile, opts) {
2025
1976
  }));
2026
1977
  check(result.winnerSurface);
2027
1978
  assertMethodCostRecorded(current.name, result, scopedInput.costLedger, invocationLedger, comparisonOptions.costCeiling, children > 0 ? "invocation" : controls?.costAttribution, [...historical.values()]);
2028
- if (controls?.costAttribution === "optimizer-run" && result.provenance?.runId) for (const receipt of methodHistoricalReceipts(scopedInput.costLedger, result.provenance.runId, runtimeInvocationId)) historical.set(receipt.callId, receipt);
1979
+ if (controls?.costAttribution === "optimizer-run" && result.provenance?.runId) for (const receipt of methodHistoricalReceipts(scopedInput.costLedger, result.provenance.runId, invocationId)) historical.set(receipt.callId, receipt);
2029
1980
  return {
2030
1981
  result,
2031
1982
  historical: [...historical.values()]
@@ -2038,13 +1989,15 @@ async function runMethodImprovement(profile, opts) {
2038
1989
  return (await invoke(method, scopedInput)).result;
2039
1990
  }
2040
1991
  };
1992
+ const methodStorage = optimizationRunOptions?.storage ?? comparisonOptions.storage ?? fsCampaignStorage();
2041
1993
  const startedAt = Date.now();
2042
1994
  const raw = await compareOptimizationMethods({
2043
1995
  ...comparisonOptions,
2044
- judges: identifiedJudges,
1996
+ judges: prepared.judges,
2045
1997
  dispatchRef,
2046
1998
  optimizationRunOptions: {
2047
1999
  ...optimizationRunOptions ?? {},
2000
+ storage: methodStorage,
2048
2001
  dispatchRef
2049
2002
  },
2050
2003
  methods: [measuredMethod],
@@ -2052,16 +2005,19 @@ async function runMethodImprovement(profile, opts) {
2052
2005
  dispatchWithSurface: (candidateSurface, scenario, ctx) => agent(materializeProfile(candidateSurface), scenario, ctx)
2053
2006
  });
2054
2007
  if (comparisonOptions.costCeiling !== void 0 && raw.totalCost.totalCostUsd > comparisonOptions.costCeiling) throw new ConfigError(`improve(): reported total cost $${raw.totalCost.totalCostUsd} exceeds costCeiling $${comparisonOptions.costCeiling}`);
2008
+ const searchHistory = raw.searchHistory.producers[0]?.receipt ?? null;
2009
+ if (searchHistory) {
2010
+ if (!searchHistory.complete) throw new ConfigError(`improve(): method '${method.name}' returned an open search ledger: ${searchHistory.incompleteReasons.join("; ")}`);
2011
+ verifySearchHistoryArtifact(searchHistory, methodStorage);
2012
+ }
2055
2013
  const score = raw.best;
2056
2014
  const winnerSurface = immutableCandidateValue(score.winnerSurface);
2057
2015
  assertCandidateSurfaceKind(surface, baselineSurface, winnerSurface);
2058
- const candidateProfile = materializeProfile(winnerSurface);
2059
2016
  const candidate = Object.freeze({
2060
2017
  surface,
2061
2018
  value: winnerSurface,
2062
- profile: candidateProfile
2019
+ profile: materializeProfile(winnerSurface)
2063
2020
  });
2064
- const candidatePopulation = profileCandidatePopulation(score.provenance, profile, materializeProfile, winnerSurface, optimizationRunOptions?.storage);
2065
2021
  const cost = copyImproveCost(raw.totalCost);
2066
2022
  return {
2067
2023
  mode: "method",
@@ -2071,23 +2027,501 @@ async function runMethodImprovement(profile, opts) {
2071
2027
  decision: cost.accountingComplete && score.decision.promote && score.decision.low > minimumLift ? "ship" : "hold",
2072
2028
  lift: score.lift,
2073
2029
  liftInterval: { ...score.liftCi },
2074
- candidatePopulation,
2030
+ searchHistory,
2075
2031
  cost,
2076
2032
  durationMs: Date.now() - startedAt,
2077
2033
  lineage: Object.freeze({
2078
- invocationId: runtimeInvocationId,
2079
- runId: score.provenance?.runId ?? runtimeInvocationId,
2034
+ invocationId,
2035
+ runId: score.provenance?.runId ?? invocationId,
2080
2036
  developmentSplitDigest,
2081
2037
  finalTestSplitDigest,
2082
2038
  scenarioPartitions,
2083
- executionRef,
2084
- baselineProfileDigest
2039
+ executionRef: prepared.executionRef,
2040
+ baselineProfileDigest: prepared.baselineProfileDigest
2085
2041
  }),
2086
2042
  raw,
2087
2043
  async dispose() {}
2088
2044
  };
2089
2045
  }
2090
2046
  //#endregion
2047
+ //#region src/improvement/search-method.ts
2048
+ /** Build Runtime's native search for `improve(profile, { method })`. */
2049
+ function searchMethod(options) {
2050
+ if (!options || typeof options !== "object") throw new ConfigError("searchMethod(): options are required");
2051
+ const { proposer } = options;
2052
+ if (!proposer || typeof proposer.kind !== "string" || typeof proposer.propose !== "function") throw new ConfigError("searchMethod(): proposer must be a SurfaceProposer");
2053
+ const count = (name, value, fallback, min) => {
2054
+ const resolved = value ?? fallback;
2055
+ if (!Number.isSafeInteger(resolved) || resolved < min) throw new ConfigError(`searchMethod(): ${name} must be an integer of at least ${min}`);
2056
+ return resolved;
2057
+ };
2058
+ const dollars = (name, value) => {
2059
+ if (value === void 0) return null;
2060
+ if (!Number.isFinite(value) || value < 0) throw new ConfigError(`searchMethod(): ${name} must be a finite non-negative number`);
2061
+ return value;
2062
+ };
2063
+ if (options.deadline !== void 0 && !Number.isFinite(Date.parse(options.deadline))) throw new ConfigError("searchMethod(): deadline must be an ISO time");
2064
+ const name = options.name ?? "search";
2065
+ if (!name.trim() || name.trim() !== name) throw new ConfigError("searchMethod(): name must be a trimmed non-empty string");
2066
+ return Object.freeze({
2067
+ kind: "search",
2068
+ name,
2069
+ policy: options.policy ?? incumbent(),
2070
+ allocation: options.allocation ?? uniform(),
2071
+ proposer,
2072
+ maxExpansions: count("maxExpansions", options.maxExpansions, NaN, 0),
2073
+ childrenPerProposal: count("childrenPerProposal", options.childrenPerProposal, 1, 1),
2074
+ concurrency: count("concurrency", options.concurrency, 2, 1),
2075
+ cellUsd: dollars("cellUsd", options.cellUsd) ?? 0,
2076
+ claimReserveUsd: dollars("claimReserveUsd", options.claimReserveUsd),
2077
+ deadline: options.deadline === void 0 ? null : new Date(options.deadline).toISOString(),
2078
+ maxAttempts: count("maxAttempts", options.maxAttempts, 3, 1)
2079
+ });
2080
+ }
2081
+ function isImproveSearchMethod(value) {
2082
+ return typeof value === "object" && value !== null && value.kind === "search";
2083
+ }
2084
+ const SEARCH_METHOD_SOURCE = {
2085
+ uri: "npm:@tangle-network/agent-runtime#searchMethod",
2086
+ revision: canonicalCandidateDigest$1({
2087
+ name: "agent-runtime.search-method.2026-09",
2088
+ node: "an exact AgentProfile materialized from the baseline and one surface, content-addressed by canonicalAgentProfileDigest; a surface that does not materialize is a node addressed by its surface and refused",
2089
+ edge: "the Interface diffs from the parent profile to the child, stored when they reproduce the child digest",
2090
+ admission: "a candidate is refused when it does not materialize, declares training on a test task, fails the caller validator, or carries a credential or private value",
2091
+ cell: "a one-cell runCampaign of the materialized profile in a directory addressed by its digest; a cached cell is read back, not run again",
2092
+ proposer: "a SurfaceProposer reads the parents, the train view and the train summary; paid calls it makes are its operation accounting",
2093
+ ship: "the claim shipped, re-derives from the ledger, cost accounting is complete, and the shipped finalist test lower bound exceeds minimumLift"
2094
+ })
2095
+ };
2096
+ async function runSearchImprovement(profile, opts) {
2097
+ const { method, claim: inputClaim, agent, trainScenarios, selectionScenarios, testScenarios, judges: _judges, surface: _surface, executionRef: _executionRef, validateCandidate: _validateCandidate, findings: _findings, skills: _skills, profileComponents: _profileComponents, minimumLift: _minimumLift, subject: _subject, costCeiling, costLedger: inputCostLedger, seed = 42, signal, ...campaignOptions } = opts;
2098
+ if (!isImproveSearchMethod(method)) throw new ConfigError("improve(): a search needs method: searchMethod(...)");
2099
+ const claim = defineEvaluationClaim(inputClaim);
2100
+ if (claim.minimumEffect === void 0) throw new ConfigError("improve(): a search claim needs minimumEffect for its power check");
2101
+ for (const [name, split] of [
2102
+ ["trainScenarios", trainScenarios],
2103
+ ["selectionScenarios", selectionScenarios],
2104
+ ["testScenarios", testScenarios]
2105
+ ]) if (!Array.isArray(split) || split.length === 0) throw new ConfigError(`improve(): a search needs at least one of ${name}`);
2106
+ const { allocation, policy } = method;
2107
+ const reps = allocation.reps;
2108
+ const prepared = prepareProfileImprovement(profile, {
2109
+ ...opts,
2110
+ seed,
2111
+ reps,
2112
+ optimizationRunOptions: {
2113
+ reps,
2114
+ maxConcurrency: method.concurrency
2115
+ }
2116
+ });
2117
+ const { evaluationRef } = prepared.identity;
2118
+ const storage = campaignOptions.storage ?? fsCampaignStorage();
2119
+ const runDir = resolveRunDir(campaignOptions.runDir, campaignOptions.repo);
2120
+ const searchId = `improve-${canonicalCandidateDigest$1({
2121
+ evaluationRef,
2122
+ process: SEARCH_METHOD_SOURCE,
2123
+ method: searchMethodDescriptor(method)
2124
+ }).slice(7, 31)}`;
2125
+ const searchDir = `${runDir}/search/${searchId}`;
2126
+ const costLedger = inputCostLedger ?? createRunCostLedger({
2127
+ storage,
2128
+ runDir: searchDir,
2129
+ costCeilingUsd: costCeiling
2130
+ });
2131
+ const unitOf = (scenario) => summarizeEvaluationUnits(claim, [scenario]).units[0].id;
2132
+ const tasks = (scenarios) => scenarios.map((scenario) => ({
2133
+ taskId: scenario.id,
2134
+ unitId: unitOf(scenario),
2135
+ source: {
2136
+ uri: `scenario://${scenario.id}`,
2137
+ revision: canonicalCandidateDigest$1(scenario)
2138
+ }
2139
+ }));
2140
+ const splits = {
2141
+ train: tasks(trainScenarios),
2142
+ selection: tasks(selectionScenarios),
2143
+ test: tasks(testScenarios)
2144
+ };
2145
+ const developmentUnits = new Set([...splits.train, ...splits.selection].map((task) => task.unitId));
2146
+ const execution = {
2147
+ model: prepared.searchIdentity.model,
2148
+ agent: prepared.searchIdentity.agent,
2149
+ benchmark: {
2150
+ uri: "agent-runtime:improve-splits",
2151
+ revision: canonicalCandidateDigest$1({
2152
+ development: prepared.identity.developmentSplitDigest,
2153
+ test: prepared.identity.finalTestSplitDigest
2154
+ })
2155
+ }
2156
+ };
2157
+ const reservedClaimUsd = Math.max(method.claimReserveUsd ?? 0, searchClaimReserveUsd({
2158
+ testTasks: splits.test.length,
2159
+ reps,
2160
+ cellUsd: method.cellUsd
2161
+ }));
2162
+ const recorder = await SearchRecorder.open({
2163
+ ledger: storage.kind === "filesystem" ? openSearchLedger({
2164
+ path: `${searchDir}/ledger.jsonl`,
2165
+ searchId
2166
+ }) : openSearchLedger({
2167
+ path: `${searchDir}/ledger.jsonl`,
2168
+ searchId,
2169
+ store: storage
2170
+ }),
2171
+ storage
2172
+ }, {
2173
+ subject: prepared.searchIdentity.subject,
2174
+ process: {
2175
+ name: method.name,
2176
+ executionRef: SEARCH_METHOD_SOURCE
2177
+ },
2178
+ artifactKind: "agent-profile",
2179
+ objective: {
2180
+ metric: "composite",
2181
+ direction: "maximize",
2182
+ judge: prepared.searchIdentity.judge,
2183
+ claim
2184
+ },
2185
+ splits: {
2186
+ ...splits,
2187
+ heldOutUnits: splits.test.every((task) => !developmentUnits.has(task.unitId))
2188
+ },
2189
+ policy: {
2190
+ expansion: policy.name,
2191
+ allocation: allocation.name,
2192
+ seed
2193
+ },
2194
+ budget: {
2195
+ maxUsd: costCeiling ?? null,
2196
+ maxCells: null,
2197
+ maxNodes: 1 + method.maxExpansions * method.childrenPerProposal,
2198
+ deadline: method.deadline,
2199
+ maxConcurrency: method.concurrency,
2200
+ reservedClaimUsd: costCeiling === void 0 ? 0 : reservedClaimUsd
2201
+ },
2202
+ containment: null,
2203
+ derivedFrom: null,
2204
+ identity: execution
2205
+ });
2206
+ const nodeOf = (candidateSurface) => {
2207
+ const surface = immutableCandidateValue(candidateSurface);
2208
+ try {
2209
+ return {
2210
+ surface,
2211
+ profile: prepared.materializeCandidate(surface),
2212
+ refusal: null
2213
+ };
2214
+ } catch (error) {
2215
+ return {
2216
+ surface,
2217
+ profile: null,
2218
+ refusal: refusalText(error)
2219
+ };
2220
+ }
2221
+ };
2222
+ const codec = profileCodec(prepared);
2223
+ const scenarios = [
2224
+ ...trainScenarios,
2225
+ ...selectionScenarios,
2226
+ ...testScenarios
2227
+ ];
2228
+ const scenarioIds = /* @__PURE__ */ new Set();
2229
+ for (const scenario of scenarios) {
2230
+ if (scenarioIds.has(scenario.id)) throw new ConfigError(`improve(): scenario '${scenario.id}' appears in more than one split`);
2231
+ scenarioIds.add(scenario.id);
2232
+ }
2233
+ const lane = "in-process";
2234
+ const executor = {
2235
+ lanes: () => [{
2236
+ name: lane,
2237
+ capacity: method.concurrency,
2238
+ costCap: "estimate",
2239
+ cellUsd: method.cellUsd
2240
+ }],
2241
+ place: () => lane,
2242
+ adopt: async () => null,
2243
+ async run(work) {
2244
+ const nodeProfile = work.artifact.profile;
2245
+ if (!nodeProfile) throw new Error(`improve(): refused node ${work.nodeId} was given a cell`);
2246
+ const profileDigest = canonicalAgentProfileDigest(nodeProfile);
2247
+ const cell = (await runCampaign({
2248
+ ...campaignOptions,
2249
+ scenarios,
2250
+ judges: prepared.judges,
2251
+ seed,
2252
+ reps,
2253
+ storage,
2254
+ runDir: `${searchDir}/nodes/${profileDigest.slice(7)}`,
2255
+ dispatchRef: `improve:${evaluationRef}:${profileDigest}`,
2256
+ dispatch: (scenario, ctx) => agent(nodeProfile, scenario, ctx),
2257
+ cellFilter: ({ scenario, rep }) => scenario.id === work.taskId && rep === work.rep,
2258
+ resumable: true,
2259
+ maxConcurrency: 1,
2260
+ costLedger,
2261
+ costPhase: `search.${work.stage}`,
2262
+ signal: work.signal
2263
+ })).cells[0];
2264
+ if (!cell) throw new Error(`improve(): cell ${work.cellId} produced no campaign cell`);
2265
+ return campaignCellSearchResult(cell, {
2266
+ execution,
2267
+ lane: work.lane
2268
+ });
2269
+ }
2270
+ };
2271
+ const { proposer } = method;
2272
+ const proposerSource = {
2273
+ uri: `proposer:${proposer.kind}`,
2274
+ revision: canonicalCandidateDigest$1({
2275
+ kind: proposer.kind,
2276
+ propose: Function.prototype.toString.call(proposer.propose),
2277
+ decide: proposer.decide ? Function.prototype.toString.call(proposer.decide) : null
2278
+ })
2279
+ };
2280
+ const proposalPhase = "search.proposal";
2281
+ const port = {
2282
+ name: proposer.kind,
2283
+ kind: "optimizer",
2284
+ source: proposerSource,
2285
+ execution: {
2286
+ kind: "deterministic",
2287
+ source: proposerSource
2288
+ },
2289
+ childrenPerProposal: method.childrenPerProposal,
2290
+ async propose(request) {
2291
+ const before = new Set(costLedger.list({ phase: proposalPhase }).map((r) => r.callId));
2292
+ const state = await recorder.state();
2293
+ const parents = request.parents.map(({ nodeId, artifact }) => ({
2294
+ nodeId,
2295
+ artifact: artifact.surface
2296
+ }));
2297
+ const context = Object.freeze({
2298
+ currentSurface: parents[0]?.artifact ?? prepared.baselineSurface,
2299
+ operator: request.operator,
2300
+ parents,
2301
+ train: searchProposerView(state),
2302
+ summary: renderSearchSummary(state, { split: "train" }),
2303
+ history: [],
2304
+ findings: prepared.findings,
2305
+ populationSize: method.childrenPerProposal,
2306
+ generation: request.expansion,
2307
+ signal: request.signal,
2308
+ costLedger,
2309
+ costPhase: proposalPhase
2310
+ });
2311
+ const decision = proposer.decide?.({ history: [] });
2312
+ const proposed = decision?.stop ? [] : await proposer.propose(context);
2313
+ if (!Array.isArray(proposed)) throw new ConfigError("improve(): the search proposer must return an array");
2314
+ const fresh = costLedger.list({ phase: proposalPhase }).filter((receipt) => !before.has(receipt.callId));
2315
+ return {
2316
+ children: proposed.slice(0, method.childrenPerProposal).map((child) => isProposedCandidate(child) ? {
2317
+ artifact: nodeOf(child.surface),
2318
+ label: child.label,
2319
+ rationale: child.rationale,
2320
+ ...child.attribution ? { attribution: child.attribution } : {}
2321
+ } : {
2322
+ artifact: nodeOf(child),
2323
+ label: "",
2324
+ rationale: ""
2325
+ }),
2326
+ ...decision?.stop ? { stop: decision.reason ?? "the proposer decided to stop" } : {},
2327
+ accounting: searchReceiptAccounting(fresh),
2328
+ execution: searchProposalExecution(fresh, prepared.searchIdentity.model.provider, proposerSource)
2329
+ };
2330
+ }
2331
+ };
2332
+ const admit = (node) => {
2333
+ if (node.refusal !== null || node.profile === null) return node.refusal;
2334
+ try {
2335
+ prepared.admitCandidate(node.profile, node.surface);
2336
+ } catch (error) {
2337
+ return refusalText(error);
2338
+ }
2339
+ const paths = privateValuePaths([node.surface]);
2340
+ return paths.length === 0 ? null : `the surface carries a credential or private value at ${paths.slice(0, 8).join(", ")}`;
2341
+ };
2342
+ const startedAt = Date.now();
2343
+ const result = await runSearch({
2344
+ recorder,
2345
+ root: nodeOf(prepared.baselineSurface),
2346
+ codec,
2347
+ policy,
2348
+ allocation,
2349
+ proposer: port,
2350
+ executor,
2351
+ admit,
2352
+ maxExpansions: method.maxExpansions,
2353
+ maxAttempts: method.maxAttempts,
2354
+ ...signal ? { signal } : {}
2355
+ });
2356
+ const { state } = result;
2357
+ const claimResult = result.claim;
2358
+ if (!claimResult || !result.claimVerification) throw new Error(`improve(): search ${searchId} closed without a claim`);
2359
+ const kept = codec.load(recorder, state.node(result.leader));
2360
+ if (!kept.profile) throw new Error(`improve(): search ${searchId} kept a refused node`);
2361
+ const candidate = Object.freeze({
2362
+ surface: prepared.surface,
2363
+ value: kept.surface,
2364
+ profile: kept.profile
2365
+ });
2366
+ const cost = copyImproveCost(costLedger.summary());
2367
+ const shipped = claimResult.finalists.find((finalist) => finalist.nodeId === claimResult.selected && finalist.test !== null);
2368
+ const { decision, reason } = runtimeShipDecision({
2369
+ claim: claimResult,
2370
+ verified: result.claimVerification.status === "verified",
2371
+ accountingComplete: cost.accountingComplete,
2372
+ lowerBound: shipped?.test?.interval[0] ?? null,
2373
+ minimumLift: prepared.minimumLift
2374
+ });
2375
+ return {
2376
+ mode: "search",
2377
+ method: method.name,
2378
+ candidate,
2379
+ decision,
2380
+ reason,
2381
+ claim: claimResult,
2382
+ claimVerification: result.claimVerification,
2383
+ ...shipped?.test ? {
2384
+ lift: shipped.test.delta,
2385
+ liftInterval: {
2386
+ low: shipped.test.interval[0],
2387
+ high: shipped.test.interval[1]
2388
+ }
2389
+ } : {},
2390
+ searchHistory: recorder.receipt({
2391
+ producerId: method.name,
2392
+ runId: searchId
2393
+ }),
2394
+ cost,
2395
+ durationMs: Date.now() - startedAt,
2396
+ lineage: Object.freeze({
2397
+ invocationId: prepared.invocationId,
2398
+ runId: searchId,
2399
+ developmentSplitDigest: prepared.identity.developmentSplitDigest,
2400
+ finalTestSplitDigest: prepared.identity.finalTestSplitDigest,
2401
+ scenarioPartitions: prepared.identity.scenarioPartitions,
2402
+ executionRef: prepared.executionRef,
2403
+ baselineProfileDigest: prepared.baselineProfileDigest
2404
+ }),
2405
+ async dispose() {}
2406
+ };
2407
+ }
2408
+ /** Runtime's ship rule over the kernel's statistical claim (design §6.5 step 5). */
2409
+ function runtimeShipDecision(input) {
2410
+ const { claim } = input;
2411
+ if (claim.decision !== "ship") return {
2412
+ decision: "hold",
2413
+ reason: claim.reason
2414
+ };
2415
+ if (!input.verified) return {
2416
+ decision: "hold",
2417
+ reason: "the claim shipped, but it does not re-derive from the ledger under this rule revision"
2418
+ };
2419
+ if (!input.accountingComplete) return {
2420
+ decision: "hold",
2421
+ reason: "the claim shipped, but the search cost accounting is incomplete"
2422
+ };
2423
+ if (input.lowerBound === null || !(input.lowerBound > input.minimumLift)) return {
2424
+ decision: "hold",
2425
+ reason: `the claim shipped, but its test lower bound ${input.lowerBound} does not exceed minimumLift ${input.minimumLift}`
2426
+ };
2427
+ return {
2428
+ decision: "ship",
2429
+ reason: claim.reason
2430
+ };
2431
+ }
2432
+ /** Profiles as search artifacts: nodes by profile digest, edges by profile diffs. */
2433
+ function profileCodec(prepared) {
2434
+ const surfaceId = prepared.surface;
2435
+ return {
2436
+ node(recorder, node) {
2437
+ if (node.profile) {
2438
+ const artifact = recorder.blob("agent-profile", {
2439
+ kind: "agent-profile",
2440
+ profile: node.profile
2441
+ });
2442
+ return {
2443
+ artifactDigest: canonicalAgentProfileDigest(node.profile),
2444
+ artifact,
2445
+ surfaces: [{
2446
+ surfaceId,
2447
+ kind: "agent-profile",
2448
+ artifact
2449
+ }]
2450
+ };
2451
+ }
2452
+ const artifact = recorder.blob("surface", {
2453
+ kind: "unmaterialized-surface",
2454
+ surface: node.surface,
2455
+ refusal: node.refusal
2456
+ });
2457
+ return {
2458
+ artifactDigest: canonicalCandidateDigest$1({
2459
+ kind: "unmaterialized-surface",
2460
+ surface: node.surface
2461
+ }),
2462
+ artifact,
2463
+ surfaces: [{
2464
+ surfaceId,
2465
+ kind: "agent-profile",
2466
+ artifact
2467
+ }]
2468
+ };
2469
+ },
2470
+ diff(recorder, parent, child) {
2471
+ if (!parent.profile || !child.profile) return { unknown: "a surface that does not materialize has no profile to diff" };
2472
+ const diffs = diffAgentProfiles(parent.profile, child.profile);
2473
+ const to = canonicalAgentProfileDigest(child.profile);
2474
+ if (canonicalAgentProfileDigest(diffs.reduce(applyAgentProfileDiff, parent.profile)) !== to) return { unknown: "the Interface profile diffs do not reproduce the child profile" };
2475
+ return recorder.blob("diff", {
2476
+ kind: "agent-profile-diff",
2477
+ from: canonicalAgentProfileDigest(parent.profile),
2478
+ to,
2479
+ diffs
2480
+ });
2481
+ },
2482
+ load(recorder, node) {
2483
+ const stored = recorder.readBlob(node.artifact);
2484
+ if (stored.kind === "agent-profile") {
2485
+ const parsed = agentProfileSchema.safeParse(stored.profile);
2486
+ if (!parsed.success) throw new Error(`improve(): node ${node.nodeId} holds an invalid AgentProfile`);
2487
+ const loaded = immutableCandidateValue(parsed.data);
2488
+ return {
2489
+ surface: prepared.surfaceOf(loaded),
2490
+ profile: loaded,
2491
+ refusal: null
2492
+ };
2493
+ }
2494
+ if (stored.kind === "unmaterialized-surface" && stored.surface !== void 0) return {
2495
+ surface: stored.surface,
2496
+ profile: null,
2497
+ refusal: stored.refusal ?? null
2498
+ };
2499
+ throw new Error(`improve(): node ${node.nodeId} holds no profile search artifact`);
2500
+ }
2501
+ };
2502
+ }
2503
+ /** Everything that decides which search a call continues. */
2504
+ function searchMethodDescriptor(method) {
2505
+ return {
2506
+ name: method.name,
2507
+ policy: method.policy.name,
2508
+ allocation: method.allocation.name,
2509
+ reps: method.allocation.reps,
2510
+ proposer: method.proposer.kind,
2511
+ maxExpansions: method.maxExpansions,
2512
+ childrenPerProposal: method.childrenPerProposal,
2513
+ concurrency: method.concurrency,
2514
+ cellUsd: method.cellUsd,
2515
+ claimReserveUsd: method.claimReserveUsd,
2516
+ deadline: method.deadline,
2517
+ maxAttempts: method.maxAttempts
2518
+ };
2519
+ }
2520
+ /** A refusal as the ledger stores it: redacted with the share profile. */
2521
+ function refusalText(error) {
2522
+ return redact(error instanceof Error ? error.message : String(error), { profile: "share" }).value;
2523
+ }
2524
+ //#endregion
2091
2525
  //#region src/improvement/training.ts
2092
2526
  function positiveLimit(value, label) {
2093
2527
  if (!Number.isSafeInteger(value) || value <= 0) throw new Error(`invalid ${label}`);
@@ -2472,7 +2906,9 @@ async function improve(profileOrCode, opts) {
2472
2906
  if (opts.surface === "code") throw new ConfigError("improve(): code takes one argument: improve({ surface: 'code', ... })");
2473
2907
  const parsedProfile = agentProfileSchema.safeParse(profileOrCode);
2474
2908
  if (!parsedProfile.success) throw new ConfigError(`improve(): input is not a valid AgentProfile: ${parsedProfile.error.message}`);
2475
- return runMethodImprovement(immutableCandidateValue(parsedProfile.data), opts);
2909
+ const exact = immutableCandidateValue(parsedProfile.data);
2910
+ if (isImproveSearchMethod(opts.method)) return runSearchImprovement(exact, opts);
2911
+ return runMethodImprovement(exact, opts);
2476
2912
  }
2477
2913
  //#endregion
2478
2914
  //#region src/intelligence/improvement-surfaces.ts
@@ -3704,6 +4140,6 @@ function sameOrderedValues(left, right) {
3704
4140
  return left.length === right.length && left.every((value, index) => value === right[index]);
3705
4141
  }
3706
4142
  //#endregion
3707
- export { agentImprovementTargetInput as A, assertCandidateValidator as B, optimizationActivationReceiptFromMetadata as C, agentImprovementProfileSurfaceDigest as D, agentImprovementProfileDiffs as E, isAgentImprovementProfileSurface as F, applyRolloutPolicyToProfile as G, parseExecutionRef as H, isAgentProfileMeasuredSurface as I, serializeRolloutPolicy as J, normalizeRolloutPolicy as K, improve as L, agentProfileImprovementStateDigest as M, assertProfileImprovementTargetsShareIdentity as N, agentImprovementProfileSurfaceInput as O, buildAgentImprovementActivationTargets as P, defaultBuildPrompt as Q, createCommandProfileTrainer as R, createOptimizationActivationReceipt as S, AGENT_PROFILE_MEASURED_SURFACES as T, rawTraceDistiller as U, assertProfileTrainingIsHeldOut as V, ROLLOUT_POLICY_EXTENSION as W, agenticGenerator as X, structuralRolloutPolicyFromProfile as Y, commandVerifier as Z, profilePolicyWithBudget as _, executeAgentCandidateExperimentCell as a, profileTaskScenarioIdentity as b, requireSealedCandidateExperiment as c, verifyAgentImprovementActivation as d, verifyAgentImprovementProposal as f, profileImprovementMetadata as g, createProfileImprovementCostLedger as h, createAgentImprovementProposal as i, agentImprovementTargetProfileDiffs as j, agentImprovementTargetDigest as k, reviewAgentImprovementProposal as l, verifyCandidateExecutionEvidence as m, createAgentImprovementActivation as n, proposeAgentImprovement as o, verifyAgentImprovementReview as p, parseRolloutPolicy as q, createAgentImprovementMeasuredComparison as r, proposeAgentProfileImprovement as s, AgentCandidateExperimentCellExecutionError as t, runAgentCandidateExperiment as u, profilePreparationAccounting as v, AGENT_IMPROVEMENT_PROFILE_SURFACES as w, sealProfileImprovementBenchmark as x, profileStateDigest as y, withMethodRuntimeControls as z };
4143
+ export { commandVerifier as $, agentImprovementTargetInput as A, assertCandidateValidator as B, optimizationActivationReceiptFromMetadata as C, agentImprovementProfileSurfaceDigest as D, agentImprovementProfileDiffs as E, isAgentImprovementProfileSurface as F, rawTraceDistiller as G, parseExecutionRef as H, isAgentProfileMeasuredSurface as I, normalizeRolloutPolicy as J, ROLLOUT_POLICY_EXTENSION as K, improve as L, agentProfileImprovementStateDigest as M, assertProfileImprovementTargetsShareIdentity as N, agentImprovementProfileSurfaceInput as O, buildAgentImprovementActivationTargets as P, agenticGenerator as Q, createCommandProfileTrainer as R, createOptimizationActivationReceipt as S, AGENT_PROFILE_MEASURED_SURFACES as T, privateValuePaths as U, assertProfileTrainingIsHeldOut as V, withMethodRuntimeControls as W, serializeRolloutPolicy as X, parseRolloutPolicy as Y, structuralRolloutPolicyFromProfile as Z, profilePolicyWithBudget as _, executeAgentCandidateExperimentCell as a, profileTaskScenarioIdentity as b, requireSealedCandidateExperiment as c, verifyAgentImprovementActivation as d, defaultBuildPrompt as et, verifyAgentImprovementProposal as f, profileImprovementMetadata as g, createProfileImprovementCostLedger as h, createAgentImprovementProposal as i, agentImprovementTargetProfileDiffs as j, agentImprovementTargetDigest as k, reviewAgentImprovementProposal as l, verifyCandidateExecutionEvidence as m, createAgentImprovementActivation as n, proposeAgentImprovement as o, verifyAgentImprovementReview as p, applyRolloutPolicyToProfile as q, createAgentImprovementMeasuredComparison as r, proposeAgentProfileImprovement as s, AgentCandidateExperimentCellExecutionError as t, runAgentCandidateExperiment as u, profilePreparationAccounting as v, AGENT_IMPROVEMENT_PROFILE_SURFACES as w, sealProfileImprovementBenchmark as x, profileStateDigest as y, searchMethod as z };
3708
4144
 
3709
- //# sourceMappingURL=improvement-cycle-DQyN0__A.js.map
4145
+ //# sourceMappingURL=improvement-cycle-Bi43xCVa.js.map