@tangle-network/agent-runtime 10.0.22 → 10.0.24

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 (82) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{activation-D_J9qCzU.js → activation-DLbBM2S0.js} +2 -2
  3. package/dist/{activation-D_J9qCzU.js.map → activation-DLbBM2S0.js.map} +1 -1
  4. package/dist/{activation-BSRRW51N.d.ts → activation-DUYtmQH_.d.ts} +22 -4
  5. package/dist/agent.d.ts +1 -1
  6. package/dist/agent.js +3 -3
  7. package/dist/{delegate-DCZPcYy8.js → delegate-Cz2GF_z7.js} +2 -2
  8. package/dist/{delegate-DCZPcYy8.js.map → delegate-Cz2GF_z7.js.map} +1 -1
  9. package/dist/{driver-control-acknowledgers-CgGt3NcX.js → driver-control-acknowledgers-pDEPMuML.js} +7 -7
  10. package/dist/{driver-control-acknowledgers-CgGt3NcX.js.map → driver-control-acknowledgers-pDEPMuML.js.map} +1 -1
  11. package/dist/durable-writer-thread.js +2 -2
  12. package/dist/durable.d.ts +1 -1
  13. package/dist/durable.js +14 -13
  14. package/dist/durable.js.map +1 -1
  15. package/dist/{graph-B3pBmvnf.js → graph-D-LVPqrm.js} +7 -6
  16. package/dist/{graph-B3pBmvnf.js.map → graph-D-LVPqrm.js.map} +1 -1
  17. package/dist/{improve-BjKhfQ_b.js → improve-BJW9OcEn.js} +189 -63
  18. package/dist/improve-BJW9OcEn.js.map +1 -0
  19. package/dist/index.d.ts +41 -6
  20. package/dist/index.js +88 -41
  21. package/dist/index.js.map +1 -1
  22. package/dist/intelligence.d.ts +2 -2
  23. package/dist/intelligence.js +4 -4
  24. package/dist/kernel.d.ts +1 -1
  25. package/dist/kernel.js +15 -15
  26. package/dist/{loop-runner-L594gDYR.js → loop-runner-BZWObfqa.js} +2 -2
  27. package/dist/{loop-runner-L594gDYR.js.map → loop-runner-BZWObfqa.js.map} +1 -1
  28. package/dist/{loop-runner-Dk5NO0Sz.d.ts → loop-runner-ClANio8o.d.ts} +2 -2
  29. package/dist/loop-runner-bin.d.ts +1 -1
  30. package/dist/loop-runner-bin.js +1 -1
  31. package/dist/mcp/bin.js +3 -3
  32. package/dist/mcp/index.d.ts +1 -1
  33. package/dist/mcp/index.js +6 -6
  34. package/dist/mcp/memory-bin.js +1 -1
  35. package/dist/profiles.d.ts +1 -1
  36. package/dist/{provision-supervisor-Be-6HBsX.js → provision-supervisor-ChGKJz8s.js} +5 -5
  37. package/dist/{provision-supervisor-Be-6HBsX.js.map → provision-supervisor-ChGKJz8s.js.map} +1 -1
  38. package/dist/{result-blob-store-CJjp44Mz.js → result-blob-store-BZwRmrFF.js} +2 -2
  39. package/dist/{result-blob-store-CJjp44Mz.js.map → result-blob-store-BZwRmrFF.js.map} +1 -1
  40. package/dist/{run-cancellation-BNBmsY3a.js → run-cancellation-uCwV2Ra7.js} +2 -2
  41. package/dist/{run-cancellation-BNBmsY3a.js.map → run-cancellation-uCwV2Ra7.js.map} +1 -1
  42. package/dist/{run-reopen-Cr2SHmYa.js → run-reopen-YJwUAmv6.js} +6 -6
  43. package/dist/{run-reopen-Cr2SHmYa.js.map → run-reopen-YJwUAmv6.js.map} +1 -1
  44. package/dist/{run-state-Bko0BF0_.js → run-state-6jJzk6gB.js} +5 -5
  45. package/dist/{run-state-Bko0BF0_.js.map → run-state-6jJzk6gB.js.map} +1 -1
  46. package/dist/{runtime-Dfwc9cjt.js → runtime-Ddkn1wRr.js} +15 -15
  47. package/dist/{runtime-Dfwc9cjt.js.map → runtime-Ddkn1wRr.js.map} +1 -1
  48. package/dist/{search-executor-DnWnh4kj.js → search-executor-D9E9q-Pv.js} +4 -4
  49. package/dist/{search-executor-DnWnh4kj.js.map → search-executor-D9E9q-Pv.js.map} +1 -1
  50. package/dist/{server-RCsa_gyH.js → server-BhXz3JyW.js} +4 -4
  51. package/dist/{server-RCsa_gyH.js.map → server-BhXz3JyW.js.map} +1 -1
  52. package/dist/{settle-record-BlIw2MU1.js → settle-record-DWae7fwV.js} +2 -2
  53. package/dist/{settle-record-BlIw2MU1.js.map → settle-record-DWae7fwV.js.map} +1 -1
  54. package/dist/{structural-rollout-BLflx9cs.js → structural-rollout-BL8KLLw8.js} +4 -4
  55. package/dist/{structural-rollout-BLflx9cs.js.map → structural-rollout-BL8KLLw8.js.map} +1 -1
  56. package/dist/{supervise-037R-zl1.js → supervise-C7mDlK7S.js} +10 -7
  57. package/dist/supervise-C7mDlK7S.js.map +1 -0
  58. package/dist/{supervise-identity-CtxWEk1I.js → supervise-identity-DLPzZTp3.js} +2 -2
  59. package/dist/{supervise-identity-CtxWEk1I.js.map → supervise-identity-DLPzZTp3.js.map} +1 -1
  60. package/dist/{supervision-discovery-DKxqbnHf.js → supervision-discovery-8XnVtdOD.js} +3 -3
  61. package/dist/{supervision-discovery-DKxqbnHf.js.map → supervision-discovery-8XnVtdOD.js.map} +1 -1
  62. package/dist/{supervisor-DL4hO7UW.js → supervisor-BQwg_3T0.js} +494 -28
  63. package/dist/supervisor-BQwg_3T0.js.map +1 -0
  64. package/dist/{supervisor-accounting-DlDUl58C.js → supervisor-accounting-B0ofgTZX.js} +91 -14
  65. package/dist/supervisor-accounting-B0ofgTZX.js.map +1 -0
  66. package/dist/{supervisor-root-contract-BCbu1A4n.js → supervisor-root-contract-N7rW4Ynu.js} +3 -3
  67. package/dist/{supervisor-root-contract-BCbu1A4n.js.map → supervisor-root-contract-N7rW4Ynu.js.map} +1 -1
  68. package/dist/testing.d.ts +1 -1
  69. package/dist/testing.js +11 -11
  70. package/dist/{tool-server-n4XYpCok.js → tool-server-I63dnHZC.js} +39 -3
  71. package/dist/{tool-server-n4XYpCok.js.map → tool-server-I63dnHZC.js.map} +1 -1
  72. package/dist/{top-web-B-sHmI3g.js → top-web-BZM3es-m.js} +7 -7
  73. package/dist/{top-web-B-sHmI3g.js.map → top-web-BZM3es-m.js.map} +1 -1
  74. package/dist/tui/bin.js +3 -3
  75. package/dist/tui/index.d.ts +1 -1
  76. package/dist/tui/index.js +2 -2
  77. package/dist/{types-3p2eAICm.d.ts → types-CByvdC7k.d.ts} +23 -8
  78. package/package.json +1 -1
  79. package/dist/improve-BjKhfQ_b.js.map +0 -1
  80. package/dist/supervise-037R-zl1.js.map +0 -1
  81. package/dist/supervisor-DL4hO7UW.js.map +0 -1
  82. package/dist/supervisor-accounting-DlDUl58C.js.map +0 -1
@@ -1,14 +1,15 @@
1
1
  import { i as ConfigError } from "./errors-DG8yufqX.js";
2
- import { F as collectAgentTurn, I as streamAgentTurn } from "./structural-rollout-BLflx9cs.js";
2
+ import { F as collectAgentTurn, I as streamAgentTurn } from "./structural-rollout-BL8KLLw8.js";
3
3
  import { C as linkAbort, w as runAbortable, y as sha256 } from "./jsonl-file-B2ESMrTh.js";
4
4
  import { o as armDeadlineTimer } from "./deadline-CySmJ_0S.js";
5
+ import { t as runTaskQueue } from "./task-queue-DbpZAp6C.js";
5
6
  import { n as detachedSnapshot } from "./snapshot-BKLziJ5K.js";
6
- import { Et as terminateProcessTreeAndConfirm, St as runSettledCommand, w as createExecutor } from "./supervisor-DL4hO7UW.js";
7
+ import { Et as terminateProcessTreeAndConfirm, St as runSettledCommand, w as createExecutor } from "./supervisor-BQwg_3T0.js";
7
8
  import { a as concreteProfileModel, t as assertExecutableAgentProfile } from "./model-policy-DFuhCC0-.js";
8
9
  import { l as syncDurableDirectory, o as publishExclusiveDurableFile } from "./durable-file-pao7FijS.js";
9
10
  import { b as sha256Bytes$1, m as canonicalCandidateDigest$1, v as immutableCandidateValue } from "./output-artifacts-AqkZ8lO2.js";
10
- import { C as serializeRolloutPolicy, S as normalizeRolloutPolicy, w as structuralRolloutPolicyFromProfile, x as applyRolloutPolicyToProfile } from "./activation-D_J9qCzU.js";
11
- import { a as reconcileInterruptedSearchCalls, b as improveSearchCost, c as searchExecutor, d as taggedLedger, i as isSearchEnvironmentFault, n as assertSearchLanes, s as searchCallTags, v as decideClosedSearch } from "./search-executor-DnWnh4kj.js";
11
+ import { C as serializeRolloutPolicy, S as normalizeRolloutPolicy, w as structuralRolloutPolicyFromProfile, x as applyRolloutPolicyToProfile } from "./activation-DLbBM2S0.js";
12
+ import { a as reconcileInterruptedSearchCalls, b as improveSearchCost, c as searchExecutor, d as taggedLedger, i as isSearchEnvironmentFault, n as assertSearchLanes, s as searchCallTags, v as decideClosedSearch } from "./search-executor-D9E9q-Pv.js";
12
13
  import { agentProfileEnvironmentSchema, agentProfileSchema, agentProfileTrainingSchema, agentTrainingDatasetIdentitySchema, agentTrainingParametersSchema, agentTrainingReceiptSchema, agentTrainingTaskKey, agentTrainingTaskSchema, applyAgentProfileDiff, canonicalAgentProfileDigest, canonicalCandidateBytes, diffAgentProfiles, sha256DigestSchema, snapshotAgentProfile, trainedModelIdForArtifact } from "@tangle-network/agent-interface";
13
14
  import { canonicalJson, makeProposalFinding } from "@tangle-network/agent-eval";
14
15
  import { redact } from "@tangle-network/agent-eval/traces";
@@ -18,8 +19,9 @@ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
18
19
  import { spawn, spawnSync } from "node:child_process";
19
20
  import { chmod, mkdir, mkdtemp, open, realpath, rm, writeFile } from "node:fs/promises";
20
21
  import { tmpdir } from "node:os";
22
+ import { fileURLToPath } from "node:url";
21
23
  import { assertProposalFindings } from "@tangle-network/agent-eval/analyst";
22
- import { SearchRecorder, aide, asha, campaignCellSearchResult, campaignScenarioIdentity, campaignSplitDigestFromIdentities, captureFinalEvidencePolicy, compareOptimizationMethods, createRunCostLedger, fsCampaignStorage, gitWorktreeAdapter, isProposedCandidate, openSearchLedger, prepareSearchFinalEvidence, renderSearchSummary, resolveRunDir, runCampaign, runSearch, searchClaimReserveUsd, searchNodeId, searchProposalExecution, searchProposerView, searchReceiptAccounting, verifyCodeSurface, verifySearchHistoryArtifact } from "@tangle-network/agent-eval/campaign";
24
+ import { SearchRecorder, aide, asha, campaignCellSearchResult, campaignScenarioIdentity, campaignSplitDigestFromIdentities, captureFinalEvidencePolicy, compareOptimizationMethods, createRunCostLedger, estimateNode, fsCampaignStorage, gitWorktreeAdapter, isProposedCandidate, openSearchLedger, prepareSearchFinalEvidence, renderSearchSummary, replaySearchLedgerText, resolveRunDir, runCampaign, runSearch, searchClaimReserveUsd, searchNodeId, searchProposalExecution, searchProposerView, searchReceiptAccounting, verifyCodeSurface, verifySearchHistoryArtifact, verifySearchHistoryReceipt } from "@tangle-network/agent-eval/campaign";
23
25
  import { selfImprove } from "@tangle-network/agent-eval/contract";
24
26
  import { defineEvaluationClaim, summarizeEvaluationUnits } from "@tangle-network/agent-eval/experiment";
25
27
  // src/runtime-usage.ts
@@ -724,69 +726,95 @@ function copyImproveCost(cost) {
724
726
  /** Build the code-only proposer used internally by `improve({ surface: 'code' })`. */
725
727
  function improvementDriver(opts) {
726
728
  const baseRef = opts.baseRef ?? "main";
729
+ const concurrency = opts.candidateConcurrency ?? 1;
730
+ if (!Number.isSafeInteger(concurrency) || concurrency < 1) throw new ConfigError("improve(): candidateConcurrency must be a positive safe integer");
727
731
  const owned = /* @__PURE__ */ new Map();
732
+ async function discardWhere(predicate) {
733
+ const errors = [];
734
+ for (const [worktree, ref] of owned) {
735
+ if (!predicate(worktree, ref)) continue;
736
+ try {
737
+ await opts.worktree.discard(worktree);
738
+ owned.delete(worktree);
739
+ } catch (cause) {
740
+ errors.push(cause);
741
+ }
742
+ }
743
+ if (errors.length > 0) throw new AggregateError(errors, "improvementDriver: failed to discard candidate worktrees");
744
+ }
728
745
  return {
729
746
  kind: `improvement:${opts.generator.kind}`,
730
747
  async propose(ctx) {
731
748
  const findings = ctx.findings;
732
- if (findings.length === 0 && !opts.generator.proposesWithoutFindings) return [];
749
+ if (ctx.signal.aborted || findings.length === 0 && !opts.generator.proposesWithoutFindings) return [];
733
750
  const surfaces = [];
734
751
  const incumbent = verifiedCodeIncumbent(ctx.currentSurface);
735
752
  const proposalBaseRef = incumbent?.baseCommit ?? baseRef;
736
- for (let i = 0; i < ctx.populationSize; i++) {
737
- if (ctx.signal.aborted) break;
738
- const wt = await opts.worktree.create({
739
- baseRef: proposalBaseRef,
740
- label: `${opts.generator.kind}-gen${ctx.generation}-cand${i}`
741
- });
742
- owned.set(wt.path, wt);
743
- try {
744
- if (incumbent) advanceToIncumbent(wt, incumbent);
745
- const { applied, summary, label, rationale } = await opts.generator.generate({
746
- worktreePath: wt.path,
747
- findings,
748
- maxShots: ctx.maxImprovementShots ?? 1,
749
- signal: ctx.signal,
750
- generation: ctx.generation,
751
- candidateIndex: i,
752
- ...ctx.costLedger ? { costLedger: ctx.costLedger } : {},
753
- ...ctx.costPhase ? { costPhase: ctx.costPhase } : {}
754
- });
755
- if (!applied) {
756
- await opts.worktree.discard(wt);
757
- owned.delete(wt.path);
758
- continue;
753
+ const batch = /* @__PURE__ */ new Set();
754
+ const stop = new AbortController();
755
+ const signal = AbortSignal.any([ctx.signal, stop.signal]);
756
+ let next = 0;
757
+ try {
758
+ for await (const result of runTaskQueue({
759
+ concurrency,
760
+ take() {
761
+ if (signal.aborted || next >= ctx.populationSize) return void 0;
762
+ const index = next++;
763
+ return {
764
+ id: String(index),
765
+ value: index
766
+ };
767
+ },
768
+ async execute({ value: index }) {
769
+ signal.throwIfAborted();
770
+ const worktree = await opts.worktree.create({
771
+ baseRef: proposalBaseRef,
772
+ label: `${opts.generator.kind}-gen${ctx.generation}-cand${index}`
773
+ });
774
+ batch.add(worktree);
775
+ owned.set(worktree, worktree.path);
776
+ signal.throwIfAborted();
777
+ if (incumbent) advanceToIncumbent(worktree, incumbent);
778
+ const { applied, summary, label, rationale } = await opts.generator.generate({
779
+ worktreePath: worktree.path,
780
+ findings,
781
+ maxShots: ctx.maxImprovementShots ?? 1,
782
+ signal,
783
+ generation: ctx.generation,
784
+ candidateIndex: index,
785
+ ...ctx.costLedger ? { costLedger: ctx.costLedger } : {},
786
+ ...ctx.costPhase ? { costPhase: ctx.costPhase } : {}
787
+ });
788
+ signal.throwIfAborted();
789
+ if (!applied) {
790
+ await opts.worktree.discard(worktree);
791
+ owned.delete(worktree);
792
+ return;
793
+ }
794
+ const surface = await opts.worktree.finalize(worktree, summary);
795
+ owned.set(worktree, surface.worktreeRef);
796
+ return label || rationale ? {
797
+ surface,
798
+ label: label ?? "",
799
+ rationale: rationale ?? ""
800
+ } : surface;
801
+ }
802
+ })) {
803
+ if (result.status === "rejected") {
804
+ stop.abort(result.reason);
805
+ throw result.reason;
759
806
  }
760
- const surface = await opts.worktree.finalize(wt, summary);
761
- surfaces.push(label || rationale ? {
762
- surface,
763
- label: label ?? "",
764
- rationale: rationale ?? ""
765
- } : surface);
766
- owned.delete(wt.path);
767
- owned.set(surface.worktreeRef, wt);
768
- } catch (err) {
769
- return rethrowAfterCleanup(err, async () => {
770
- await opts.worktree.discard(wt);
771
- owned.delete(wt.path);
772
- }, `improvementDriver: ${err instanceof Error ? err.message : String(err)}`);
807
+ if (result.value) surfaces[result.task.value] = result.value;
773
808
  }
809
+ ctx.signal.throwIfAborted();
810
+ return surfaces.filter(Boolean);
811
+ } catch (cause) {
812
+ return rethrowAfterCleanup(cause, () => discardWhere((worktree) => batch.has(worktree)), `improvementDriver: ${cause instanceof Error ? cause.message : String(cause)}`);
774
813
  }
775
- return surfaces;
776
814
  },
777
815
  async cleanup(retainWorktreeRefs = []) {
778
816
  const retained = new Set(retainWorktreeRefs);
779
- const errors = [];
780
- for (const [worktreeRef, worktree] of owned) {
781
- if (retained.has(worktreeRef)) continue;
782
- try {
783
- await opts.worktree.discard(worktree);
784
- owned.delete(worktreeRef);
785
- } catch (cause) {
786
- errors.push(cause);
787
- }
788
- }
789
- if (errors.length > 0) throw new AggregateError(errors, "improvementDriver: failed to discard candidate worktrees");
817
+ await discardWhere((_worktree, ref) => !retained.has(ref));
790
818
  }
791
819
  };
792
820
  }
@@ -1405,7 +1433,7 @@ async function realRoot(path) {
1405
1433
  }
1406
1434
  }
1407
1435
  /** Create a clean incumbent checkout and the candidate producer for a code run. */
1408
- async function prepareCodeRun(code) {
1436
+ async function prepareCodeRun(code, candidateConcurrency) {
1409
1437
  const authorProfile = agentProfileSchema.parse(code.profile);
1410
1438
  assertExecutableAgentProfile(authorProfile, "improve(code) author");
1411
1439
  const baseRef = code.baseRef ?? "main";
@@ -1430,7 +1458,8 @@ async function prepareCodeRun(code) {
1430
1458
  ...code.timeoutMs !== void 0 ? { timeoutMs: code.timeoutMs } : {},
1431
1459
  ...code.maximumCharge ? { maximumCharge: code.maximumCharge } : {}
1432
1460
  }),
1433
- baseRef
1461
+ baseRef,
1462
+ ...candidateConcurrency === void 0 ? {} : { candidateConcurrency }
1434
1463
  });
1435
1464
  return {
1436
1465
  baseline,
@@ -1476,7 +1505,7 @@ function idempotentDispose(dispose) {
1476
1505
  async function runCodeImprovement(opts) {
1477
1506
  const { gate = "holdout", findings: inputFindings = [], rawTraceContext: _rawTraceContext, code, promotionGate, analyzeGeneration, surface: _surface, ...sharedOptions } = opts;
1478
1507
  const findings = immutableCandidateValue([...assertProposalFindings(inputFindings, "improve() code findings")]);
1479
- const preparedCode = await prepareCodeRun(code);
1508
+ const preparedCode = await prepareCodeRun(code, sharedOptions.budget?.candidateConcurrency);
1480
1509
  const budget = gate === "none" ? {
1481
1510
  ...sharedOptions.budget,
1482
1511
  generations: 0
@@ -2020,6 +2049,86 @@ async function runMethodImprovement(profile, opts) {
2020
2049
  async dispose() {}
2021
2050
  };
2022
2051
  }
2052
+ // src/improvement/search-improvement-memory.ts
2053
+ function captureSearchImprovementMemory(options) {
2054
+ const maxAttempts = options.maxAttempts ?? 8;
2055
+ if (!Number.isSafeInteger(maxAttempts) || maxAttempts < 1) throw new ConfigError("searchMethod(): memory.maxAttempts must be a positive safe integer");
2056
+ if (options.notAfter !== void 0 && !Number.isSafeInteger(options.notAfter)) throw new ConfigError("searchMethod(): memory.notAfter must be integer epoch milliseconds");
2057
+ const receipts = immutableCandidateValue(options.receipts);
2058
+ for (const receipt of receipts) {
2059
+ verifySearchHistoryReceipt(receipt);
2060
+ if (!receipt.complete) throw new ConfigError("searchMethod(): memory requires closed search history receipts");
2061
+ }
2062
+ if (receipts.length === 0 || new Set(receipts.map((row) => row.receiptDigest)).size !== receipts.length) throw new ConfigError("searchMethod(): memory requires distinct search history receipts");
2063
+ return Object.freeze({
2064
+ receipts,
2065
+ maxAttempts,
2066
+ ...options.notAfter !== void 0 ? { notAfter: options.notAfter } : {},
2067
+ ...options.storage ? { storage: options.storage } : {}
2068
+ });
2069
+ }
2070
+ /** A retained search exposes only proposal identity and paired training evidence. */
2071
+ function readSearchImprovementMemory(input) {
2072
+ const { memory } = input;
2073
+ const storage = memory.storage ?? input.storage;
2074
+ const rows = [];
2075
+ for (const receipt of [...memory.receipts].reverse()) {
2076
+ const path = receipt.ledger.uri.startsWith("file:") ? fileURLToPath(receipt.ledger.uri) : receipt.ledger.uri;
2077
+ const text = storage.read(path);
2078
+ if (text === void 0) throw new ConfigError(`Search memory ledger is unavailable: ${path}`);
2079
+ verifySearchHistoryArtifact(receipt, { read: () => text });
2080
+ const state = replaySearchLedgerText(text, receipt.summary.searchId, path);
2081
+ if (memory.notAfter !== void 0 && Date.parse(state.lastOccurredAt) > memory.notAfter) throw new ConfigError(`Search memory ledger closed after the current campaign began: ${path}`);
2082
+ const header = state.header;
2083
+ const judge = header.objective.judge;
2084
+ if (header.artifactKind !== "agent-profile" || header.subject !== input.subject || header.objective.metric !== "composite" || header.objective.direction !== "maximize" || !("uri" in judge) || judge.uri !== input.judge.uri || judge.revision !== input.judge.revision || !state.node(state.rootNodeId)?.surfaces.some(({ surfaceId }) => surfaceId === input.surface)) throw new ConfigError(`Search memory ledger has an incompatible subject, surface, or evaluator: ${path}`);
2085
+ if (overlaps(header.splits.train.tasks, [...input.selection, ...input.test]) || overlaps(header.splits.selection.tasks, input.test)) throw new ConfigError(`Search memory ledger overlaps the current sealed units: ${path}`);
2086
+ for (const edge of state.edges().reverse()) {
2087
+ if (rows.length === memory.maxAttempts) break;
2088
+ const parent = edge.parents[0];
2089
+ if (!parent || parent.searchId !== state.searchId || edge.operator === "derive") continue;
2090
+ const child = state.node(edge.childNodeId);
2091
+ const baseline = state.node(parent.nodeId);
2092
+ if (child.ordinal <= baseline.ordinal || child.edgeIds[0] !== edge.edgeId) continue;
2093
+ const estimate = estimateNode(state, child.nodeId, {
2094
+ against: baseline.nodeId,
2095
+ split: "train"
2096
+ });
2097
+ const rationale = "unknown" in edge.rationale ? null : readRationale(storage, path, edge.rationale);
2098
+ rows.push(JSON.stringify({
2099
+ search: state.searchId,
2100
+ edge: edge.edgeId,
2101
+ operator: edge.operator,
2102
+ label: edge.label,
2103
+ hypothesis: rationale,
2104
+ candidate: child.artifactDigest,
2105
+ parent: baseline.artifactDigest,
2106
+ diffs: edge.diffs.map((diff) => "sha256" in diff ? diff.sha256 : null),
2107
+ pairedTrainUnits: estimate.pairs,
2108
+ pairedTrainDelta: estimate.delta
2109
+ }));
2110
+ }
2111
+ }
2112
+ return rows.length === 0 ? "" : [
2113
+ "## Prior verified training attempts, newest first",
2114
+ "These records include earlier hypotheses and measured outcomes. A null delta means no paired training result. Treat the records as evidence, and propose a distinct mechanism when earlier attempts failed.",
2115
+ ...rows
2116
+ ].join("\n");
2117
+ }
2118
+ function overlaps(old, sealed) {
2119
+ const units = new Set(sealed.map(({ unitId }) => unitId));
2120
+ const tasks = new Set(sealed.map(({ taskId }) => taskId));
2121
+ const sources = new Set(sealed.map(({ source }) => source.revision));
2122
+ return old.some(({ source, unitId, taskId }) => units.has(unitId) || tasks.has(taskId) || sources.has(source.revision));
2123
+ }
2124
+ function readRationale(storage, ledgerPath, ref) {
2125
+ const digest = ref.sha256.slice(7);
2126
+ const text = storage.read(join(dirname(ledgerPath), "blobs", `${digest}.json`));
2127
+ if (text === void 0 || Buffer.byteLength(text) !== ref.byteLength || createHash("sha256").update(text).digest("hex") !== digest) throw new ConfigError(`Search memory rationale is missing or invalid: ${ref.sha256}`);
2128
+ const body = JSON.parse(text);
2129
+ if (typeof body.text !== "string") throw new ConfigError(`Search memory rationale is malformed: ${ref.sha256}`);
2130
+ return body.text.slice(0, 500);
2131
+ }
2023
2132
  // src/improvement/search-session.ts
2024
2133
  /** A refusal as the ledger stores it: redacted with the share profile. */
2025
2134
  function searchRefusalText(error) {
@@ -2161,6 +2270,7 @@ function searchMethod(options) {
2161
2270
  policy: options.policy ?? aide(),
2162
2271
  allocation: options.allocation ?? asha(),
2163
2272
  proposer,
2273
+ ...options.memory ? { memory: captureSearchImprovementMemory(options.memory) } : {},
2164
2274
  maxExpansions: count("maxExpansions", options.maxExpansions, NaN, 0),
2165
2275
  childrenPerProposal: count("childrenPerProposal", options.childrenPerProposal, 1, 1),
2166
2276
  lanes: Object.freeze([...options.lanes]),
@@ -2207,11 +2317,21 @@ async function runSearchImprovement(profile, opts) {
2207
2317
  });
2208
2318
  const { evaluationRef } = prepared.identity;
2209
2319
  const storage = campaignOptions.storage ?? fsCampaignStorage();
2320
+ const splits = searchSplits(claim, splitScenarios);
2321
+ const memorySummary = method.memory ? readSearchImprovementMemory({
2322
+ memory: method.memory,
2323
+ storage,
2324
+ subject: prepared.searchIdentity.subject,
2325
+ judge: prepared.searchIdentity.judge,
2326
+ surface: prepared.surface,
2327
+ selection: splits.selection,
2328
+ test: splits.test
2329
+ }) : "";
2210
2330
  const runDir = resolveRunDir(campaignOptions.runDir, campaignOptions.repo);
2211
2331
  const searchId = `improve-${canonicalCandidateDigest$1({
2212
2332
  evaluationRef,
2213
2333
  process: SEARCH_METHOD_SOURCE,
2214
- method: searchMethodDescriptor(method),
2334
+ method: searchMethodDescriptor(method, memorySummary),
2215
2335
  ...finalEvidencePolicy ? { finalEvidence: {
2216
2336
  requestId: finalEvidencePolicy.requestId,
2217
2337
  evaluatorDigest: finalEvidencePolicy.evaluatorDigest
@@ -2228,7 +2348,7 @@ async function runSearchImprovement(profile, opts) {
2228
2348
  method,
2229
2349
  prepared,
2230
2350
  claim,
2231
- splits: searchSplits(claim, splitScenarios),
2351
+ splits,
2232
2352
  storage,
2233
2353
  searchId,
2234
2354
  searchDir,
@@ -2249,7 +2369,8 @@ async function runSearchImprovement(profile, opts) {
2249
2369
  prepared,
2250
2370
  searchId,
2251
2371
  costLedger,
2252
- recorder
2372
+ recorder,
2373
+ memorySummary
2253
2374
  };
2254
2375
  const profiles = /* @__PURE__ */ new Map();
2255
2376
  const codec = registeringProfileCodec(prepared, searchId, profiles);
@@ -2493,13 +2614,18 @@ async function decideSearchResult(input) {
2493
2614
  };
2494
2615
  }
2495
2616
  /** Everything that decides which search a call continues. */
2496
- function searchMethodDescriptor(method) {
2617
+ function searchMethodDescriptor(method, memorySummary) {
2497
2618
  return {
2498
2619
  name: method.name,
2499
2620
  policy: method.policy.name,
2500
2621
  allocation: method.allocation.name,
2501
2622
  reps: method.allocation.reps,
2502
2623
  proposer: method.proposer.kind,
2624
+ ...method.memory ? { memory: {
2625
+ receipts: method.memory.receipts.map(({ receiptDigest }) => receiptDigest),
2626
+ maxAttempts: method.memory.maxAttempts,
2627
+ digest: canonicalCandidateDigest$1(memorySummary)
2628
+ } } : {},
2503
2629
  maxExpansions: method.maxExpansions,
2504
2630
  childrenPerProposal: method.childrenPerProposal,
2505
2631
  lanes: method.lanes.map(({ name, kind, capacity, costCap, cellUsd }) => ({
@@ -2547,7 +2673,7 @@ function searchProposerPort(session) {
2547
2673
  operator: request.operator,
2548
2674
  parents,
2549
2675
  train: searchProposerView(state),
2550
- summary: renderSearchSummary(state, { split: "train" }),
2676
+ summary: [renderSearchSummary(state, { split: "train" }), session.memorySummary].filter(Boolean).join("\n\n"),
2551
2677
  history: [],
2552
2678
  findings: prepared.findings,
2553
2679
  populationSize: method.childrenPerProposal,
@@ -3062,4 +3188,4 @@ async function improve(profileOrCode, opts) {
3062
3188
  }
3063
3189
  export { assertProfileTrainingIsHeldOut as a, assertNoCallerArtifactDescriptor as c, agenticGenerator as d, commandVerifier as f, isUsageAmount as h, assertCandidateValidator as i, withMethodRuntimeControls as l, createRuntimeUsageTotals as m, createCommandProfileTrainer as n, parseExecutionRef as o, addRuntimeUsage as p, searchMethod as r, privateValuePaths as s, improve as t, rethrowAfterCleanup as u };
3064
3190
 
3065
- //# sourceMappingURL=improve-BjKhfQ_b.js.map
3191
+ //# sourceMappingURL=improve-BJW9OcEn.js.map