@tangle-network/agent-runtime 0.95.0 → 0.97.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 (86) hide show
  1. package/README.md +64 -15
  2. package/dist/activation-B0ZD7nfX.d.ts +63 -0
  3. package/dist/agent.d.ts +5 -169
  4. package/dist/agent.js +8 -229
  5. package/dist/agent.js.map +1 -1
  6. package/dist/analyst-loop.d.ts +6 -9
  7. package/dist/analyst-loop.js +1 -2
  8. package/dist/candidate-execution/index.js +6 -7
  9. package/dist/chunk-3XKSBI2U.js +474 -0
  10. package/dist/chunk-3XKSBI2U.js.map +1 -0
  11. package/dist/{chunk-6YBA64Z2.js → chunk-6XKPVJAZ.js} +5 -18
  12. package/dist/chunk-6XKPVJAZ.js.map +1 -0
  13. package/dist/{chunk-MKGRLDWB.js → chunk-BLQIYRVR.js} +17 -2
  14. package/dist/chunk-BLQIYRVR.js.map +1 -0
  15. package/dist/{chunk-QDSOD7RC.js → chunk-FD2MBMOH.js} +13 -101
  16. package/dist/chunk-FD2MBMOH.js.map +1 -0
  17. package/dist/{chunk-YLUOTX6U.js → chunk-FXF2OL34.js} +7 -7
  18. package/dist/{chunk-EP6RVHMX.js → chunk-HZDEXTSL.js} +848 -2
  19. package/dist/chunk-HZDEXTSL.js.map +1 -0
  20. package/dist/chunk-PSOCBNM3.js +2069 -0
  21. package/dist/chunk-PSOCBNM3.js.map +1 -0
  22. package/dist/{chunk-BPGXIKK7.js → chunk-SGQ4YIQW.js} +4 -4
  23. package/dist/{chunk-IADLKE7I.js → chunk-UQ6PNNXM.js} +5 -7
  24. package/dist/{chunk-IADLKE7I.js.map → chunk-UQ6PNNXM.js.map} +1 -1
  25. package/dist/{chunk-Z5I642SY.js → chunk-WYC2XJF2.js} +2 -2
  26. package/dist/{chunk-ZEYAT33L.js → chunk-Y3SRWZMP.js} +2 -2
  27. package/dist/{chunk-WTZ37EQY.js → chunk-YOLKCWRV.js} +197 -90
  28. package/dist/chunk-YOLKCWRV.js.map +1 -0
  29. package/dist/conversation.js +0 -1
  30. package/dist/environment-provider.js +0 -1
  31. package/dist/{agentic-generator-hCaQRAes.d.ts → improve-g75IE2Cx.d.ts} +152 -3
  32. package/dist/{improvement-adapter-BieWeK5J.d.ts → improvement-adapter-HAZz-7vK.d.ts} +8 -31
  33. package/dist/index.d.ts +41 -11
  34. package/dist/index.js +180 -51
  35. package/dist/index.js.map +1 -1
  36. package/dist/intelligence.d.ts +16 -9
  37. package/dist/intelligence.js +13 -8
  38. package/dist/intelligence.js.map +1 -1
  39. package/dist/knowledge.d.ts +30 -13
  40. package/dist/knowledge.js +11 -10
  41. package/dist/{loop-runner-bin-BIQldFS8.d.ts → loop-runner-bin-Cn1N2rRo.d.ts} +1 -1
  42. package/dist/loop-runner-bin.d.ts +2 -2
  43. package/dist/loop-runner-bin.js +6 -8
  44. package/dist/loops.d.ts +1 -1
  45. package/dist/loops.js +4 -6
  46. package/dist/mcp/bin.js +3 -5
  47. package/dist/mcp/bin.js.map +1 -1
  48. package/dist/mcp/index.js +10 -12
  49. package/dist/mcp/index.js.map +1 -1
  50. package/dist/platform.js +0 -2
  51. package/dist/platform.js.map +1 -1
  52. package/dist/primeintellect/index.js +0 -1
  53. package/dist/primeintellect/index.js.map +1 -1
  54. package/dist/profiles.js +0 -1
  55. package/dist/profiles.js.map +1 -1
  56. package/dist/{types-BC3bZpH0.d.ts → types-CmYCMbFT.d.ts} +12 -54
  57. package/package.json +8 -13
  58. package/skills/build-with-agent-runtime/SKILL.md +122 -213
  59. package/dist/chunk-6O73TRHW.js +0 -142
  60. package/dist/chunk-6O73TRHW.js.map +0 -1
  61. package/dist/chunk-6YBA64Z2.js.map +0 -1
  62. package/dist/chunk-AP7CPGMZ.js +0 -334
  63. package/dist/chunk-AP7CPGMZ.js.map +0 -1
  64. package/dist/chunk-DGUM43GV.js +0 -11
  65. package/dist/chunk-DGUM43GV.js.map +0 -1
  66. package/dist/chunk-DHCHL6OG.js +0 -625
  67. package/dist/chunk-DHCHL6OG.js.map +0 -1
  68. package/dist/chunk-EP6RVHMX.js.map +0 -1
  69. package/dist/chunk-G55QE4IQ.js +0 -1137
  70. package/dist/chunk-G55QE4IQ.js.map +0 -1
  71. package/dist/chunk-ISTDY47H.js +0 -849
  72. package/dist/chunk-ISTDY47H.js.map +0 -1
  73. package/dist/chunk-MKGRLDWB.js.map +0 -1
  74. package/dist/chunk-QDSOD7RC.js.map +0 -1
  75. package/dist/chunk-WTZ37EQY.js.map +0 -1
  76. package/dist/generator-YkAQrOoD.d.ts +0 -382
  77. package/dist/improve-B-UYaEH5.d.ts +0 -172
  78. package/dist/lifecycle.d.ts +0 -870
  79. package/dist/lifecycle.js +0 -981
  80. package/dist/lifecycle.js.map +0 -1
  81. package/dist/mcp-serve-verifier-Bs_n0xPc.d.ts +0 -34
  82. package/skills/agent-runtime-adoption/SKILL.md +0 -246
  83. /package/dist/{chunk-YLUOTX6U.js.map → chunk-FXF2OL34.js.map} +0 -0
  84. /package/dist/{chunk-BPGXIKK7.js.map → chunk-SGQ4YIQW.js.map} +0 -0
  85. /package/dist/{chunk-Z5I642SY.js.map → chunk-WYC2XJF2.js.map} +0 -0
  86. /package/dist/{chunk-ZEYAT33L.js.map → chunk-Y3SRWZMP.js.map} +0 -0
@@ -8,7 +8,7 @@ import {
8
8
  DELEGATION_STATUS_DESCRIPTION,
9
9
  DELEGATION_STATUS_INPUT_SCHEMA,
10
10
  DELEGATION_STATUS_TOOL_NAME
11
- } from "./chunk-IADLKE7I.js";
11
+ } from "./chunk-UQ6PNNXM.js";
12
12
 
13
13
  // src/mcp/openai-tools.ts
14
14
  function buildTool(name, description, parameters) {
@@ -45,4 +45,4 @@ export {
45
45
  mcpToolsForRuntimeMcp,
46
46
  mcpToolsForRuntimeMcpSubset
47
47
  };
48
- //# sourceMappingURL=chunk-Z5I642SY.js.map
48
+ //# sourceMappingURL=chunk-WYC2XJF2.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildLoopOtelSpans,
3
3
  createOtelExporter
4
- } from "./chunk-ISTDY47H.js";
4
+ } from "./chunk-HZDEXTSL.js";
5
5
 
6
6
  // src/mcp/trace-propagation.ts
7
7
  function readTraceContextFromEnv() {
@@ -49,4 +49,4 @@ export {
49
49
  createPropagatingTraceEmitter,
50
50
  traceContextToEnv
51
51
  };
52
- //# sourceMappingURL=chunk-ZEYAT33L.js.map
52
+ //# sourceMappingURL=chunk-Y3SRWZMP.js.map
@@ -2892,11 +2892,60 @@ function safeAdd(left, right, label) {
2892
2892
  }
2893
2893
 
2894
2894
  // src/candidate-execution/protected-redaction.ts
2895
+ import { createHmac, randomBytes as randomBytes2 } from "crypto";
2895
2896
  import {
2896
2897
  DEFAULT_REDACTION_RULES,
2897
2898
  REDACTION_VERSION,
2898
2899
  redactString
2899
2900
  } from "@tangle-network/agent-eval";
2901
+ function createProtectedRecordRedactor(protectedValues) {
2902
+ const identityKey = randomBytes2(32);
2903
+ const aggregate = {
2904
+ version: REDACTION_VERSION,
2905
+ redactionCount: 0,
2906
+ byRule: {}
2907
+ };
2908
+ const mergeReport = (report) => {
2909
+ aggregate.version = report.version;
2910
+ aggregate.redactionCount += report.redactionCount;
2911
+ for (const [rule, count] of Object.entries(report.byRule)) {
2912
+ aggregate.byRule[rule] = (aggregate.byRule[rule] ?? 0) + count;
2913
+ }
2914
+ };
2915
+ const redactScalar = (value, record) => {
2916
+ const redacted = redactProtectedValue(value, protectedValues);
2917
+ if (record) mergeReport(redacted.report);
2918
+ return redacted.value;
2919
+ };
2920
+ const identifier = (value, record) => {
2921
+ const redacted = redactScalar(value, record);
2922
+ if (redacted === value) return value;
2923
+ const digest = createHmac("sha256", identityKey).update(value).digest("hex");
2924
+ return `${redacted}:hmac-sha256:${digest}`;
2925
+ };
2926
+ const transform = (value, record) => {
2927
+ const transformed = transformProtectedRecord(
2928
+ value,
2929
+ void 0,
2930
+ record,
2931
+ redactScalar,
2932
+ identifier
2933
+ );
2934
+ assertNoProtectedEvidence(transformed, protectedValues);
2935
+ return transformed;
2936
+ };
2937
+ return Object.freeze({
2938
+ record: (value) => transform(value, true),
2939
+ query: (value) => transform(value, false),
2940
+ identifier: (value) => identifier(value, false),
2941
+ traceIdentity: (trace) => transform(trace, false),
2942
+ report: () => ({
2943
+ version: aggregate.version,
2944
+ redactionCount: aggregate.redactionCount,
2945
+ byRule: { ...aggregate.byRule }
2946
+ })
2947
+ });
2948
+ }
2900
2949
  function redactProtectedValue(value, protectedValues) {
2901
2950
  const report = {
2902
2951
  version: REDACTION_VERSION,
@@ -2984,6 +3033,65 @@ function redactNode(value, protectedValues, rules, report) {
2984
3033
  }
2985
3034
  return value;
2986
3035
  }
3036
+ function transformProtectedRecord(value, fieldName, record, redactScalar, redactIdentifier) {
3037
+ if (value instanceof Uint8Array) return redactScalar(value, record);
3038
+ if (typeof value === "string") {
3039
+ return fieldName && isIdentifierFieldName(fieldName) ? redactIdentifier(value, record) : redactScalar(value, record);
3040
+ }
3041
+ if (Array.isArray(value)) {
3042
+ return value.map(
3043
+ (entry) => transformProtectedRecord(entry, fieldName, record, redactScalar, redactIdentifier)
3044
+ );
3045
+ }
3046
+ if (!value || typeof value !== "object") return value;
3047
+ if (fieldName === "tags") {
3048
+ return transformTagMap(value, record, redactScalar, redactIdentifier);
3049
+ }
3050
+ if (fieldName === "tag") {
3051
+ return transformTagFilter(value, record, redactScalar, redactIdentifier);
3052
+ }
3053
+ const entries = [];
3054
+ const seenKeys = /* @__PURE__ */ new Set();
3055
+ for (const [key, entry] of Object.entries(value)) {
3056
+ const redactedKey = redactScalar(key, record);
3057
+ if (seenKeys.has(redactedKey)) {
3058
+ throw new Error("protected evidence redaction produced an ambiguous object key");
3059
+ }
3060
+ seenKeys.add(redactedKey);
3061
+ entries.push([
3062
+ redactedKey,
3063
+ transformProtectedRecord(entry, key, record, redactScalar, redactIdentifier)
3064
+ ]);
3065
+ }
3066
+ return Object.fromEntries(entries);
3067
+ }
3068
+ function transformTagMap(value, record, redactScalar, redactIdentifier) {
3069
+ const entries = [];
3070
+ const seenKeys = /* @__PURE__ */ new Set();
3071
+ for (const [key, entry] of Object.entries(value)) {
3072
+ const redactedKey = redactIdentifier(key, record);
3073
+ if (seenKeys.has(redactedKey)) {
3074
+ throw new Error("protected evidence redaction produced an ambiguous trace tag");
3075
+ }
3076
+ seenKeys.add(redactedKey);
3077
+ entries.push([
3078
+ redactedKey,
3079
+ typeof entry === "string" ? redactIdentifier(entry, record) : transformProtectedRecord(entry, key, record, redactScalar, redactIdentifier)
3080
+ ]);
3081
+ }
3082
+ return Object.fromEntries(entries);
3083
+ }
3084
+ function transformTagFilter(value, record, redactScalar, redactIdentifier) {
3085
+ const output = {};
3086
+ for (const [key, entry] of Object.entries(value)) {
3087
+ const redactedKey = redactScalar(key, record);
3088
+ output[redactedKey] = (key === "key" || key === "value") && typeof entry === "string" ? redactIdentifier(entry, record) : transformProtectedRecord(entry, key, record, redactScalar, redactIdentifier);
3089
+ }
3090
+ return output;
3091
+ }
3092
+ function isIdentifierFieldName(name) {
3093
+ return /ids?$/i.test(name);
3094
+ }
2987
3095
  function protectedRedactionRules(protectedValues) {
2988
3096
  const exactRules = protectedValueVariants(protectedValues).sort((left, right) => right.length - left.length || left.localeCompare(right)).map((value, index) => ({
2989
3097
  id: `candidate-access-${index}`,
@@ -3031,7 +3139,7 @@ function escapeRegularExpression(value) {
3031
3139
  }
3032
3140
 
3033
3141
  // src/candidate-execution/finalize.ts
3034
- async function finalizeAgentCandidateRun(state, capture, traceStore, settlement, evidence, protectedValues, writeRedactionReport, signal) {
3142
+ async function finalizeAgentCandidateRun(state, capture, traceStore, traceIdentity, settlement, evidence, protectedValues, writeRedactionReport, signal) {
3035
3143
  let termination;
3036
3144
  try {
3037
3145
  signal?.throwIfAborted();
@@ -3042,12 +3150,12 @@ async function finalizeAgentCandidateRun(state, capture, traceStore, settlement,
3042
3150
  if (termination.kind === "timeout" && termination.timeoutMs !== state.executionPlan.value.material.limits.timeoutMs) {
3043
3151
  throw new Error("timeout termination does not match the frozen execution limit");
3044
3152
  }
3045
- const run = await traceStore.getRun(state.trace.runId);
3046
- if (!run) throw new Error(`protected trace run is missing: ${state.trace.runId}`);
3153
+ const run = await traceStore.getRun(traceIdentity.runId);
3154
+ if (!run) throw new Error(`protected trace run is missing: ${traceIdentity.runId}`);
3047
3155
  if (run.status === "running" || run.endedAt === void 0) {
3048
3156
  throw new Error("protected trace run is not terminal");
3049
3157
  }
3050
- assertTraceBindings(run.tags, state);
3158
+ assertTraceBindings(run.tags, traceIdentity.tags);
3051
3159
  const [spans, events, budget, artifacts] = await Promise.all([
3052
3160
  traceStore.spans({ runId: run.runId }),
3053
3161
  traceStore.events({ runId: run.runId }),
@@ -3163,8 +3271,7 @@ async function finalizeAgentCandidateRun(state, capture, traceStore, settlement,
3163
3271
  };
3164
3272
  }
3165
3273
  }
3166
- function assertTraceBindings(tags, state) {
3167
- const expected = state.trace.tags;
3274
+ function assertTraceBindings(tags, expected) {
3168
3275
  for (const name of Object.values(CANDIDATE_TRACE_TAGS)) {
3169
3276
  if (tags?.[name] !== expected[name]) {
3170
3277
  throw new Error(`protected trace is not bound to prepared execution tag ${name}`);
@@ -3815,81 +3922,60 @@ function assertUnitScore(value, label) {
3815
3922
  }
3816
3923
 
3817
3924
  // src/candidate-execution/protected-trace-store.ts
3818
- import { REDACTION_VERSION as REDACTION_VERSION3 } from "@tangle-network/agent-eval";
3819
- var ProtectedAgentCandidateTraceStore = class {
3820
- constructor(inner, protectedValues) {
3821
- this.inner = inner;
3822
- this.protectedValues = protectedValues;
3823
- }
3824
- inner;
3825
- protectedValues;
3826
- aggregate = {
3827
- version: REDACTION_VERSION3,
3828
- redactionCount: 0,
3829
- byRule: {}
3830
- };
3831
- report() {
3832
- return {
3833
- version: this.aggregate.version,
3834
- redactionCount: this.aggregate.redactionCount,
3835
- byRule: { ...this.aggregate.byRule }
3836
- };
3837
- }
3838
- async appendRun(run) {
3839
- await this.inner.appendRun(this.redact(run));
3840
- }
3841
- async updateRun(runId, patch) {
3842
- await this.inner.updateRun(this.redact(runId), this.redact(patch));
3843
- }
3844
- async appendSpan(span) {
3845
- if (span.kind === "llm") {
3846
- throw new Error("candidate executors cannot author protected model spans");
3847
- }
3848
- await this.inner.appendSpan(this.redact(span));
3849
- }
3850
- async updateSpan(spanId, patch) {
3851
- if (patch.kind === "llm") {
3852
- throw new Error("candidate executors cannot author protected model spans");
3925
+ function createProtectedAgentCandidateTraceAccess(inner, protectedValues) {
3926
+ const redactor = createProtectedRecordRedactor(protectedValues);
3927
+ const pendingWrites = /* @__PURE__ */ new Set();
3928
+ let acceptsWrites = true;
3929
+ const write = (operation) => {
3930
+ if (!acceptsWrites) {
3931
+ return Promise.reject(new Error("candidate trace writes are closed"));
3853
3932
  }
3854
- await this.inner.updateSpan(this.redact(spanId), this.redact(patch));
3855
- }
3856
- async appendEvent(event) {
3857
- await this.inner.appendEvent(this.redact(event));
3858
- }
3859
- async appendArtifact(artifact) {
3860
- await this.inner.appendArtifact(this.redact(artifact));
3861
- }
3862
- async appendBudgetEntry(entry) {
3863
- await this.inner.appendBudgetEntry(this.redact(entry));
3864
- }
3865
- getRun(...args) {
3866
- return this.inner.getRun(...args);
3867
- }
3868
- listRuns(...args) {
3869
- return this.inner.listRuns(...args);
3870
- }
3871
- spans(...args) {
3872
- return this.inner.spans(...args);
3873
- }
3874
- events(...args) {
3875
- return this.inner.events(...args);
3876
- }
3877
- budget(...args) {
3878
- return this.inner.budget(...args);
3879
- }
3880
- artifacts(...args) {
3881
- return this.inner.artifacts(...args);
3882
- }
3883
- redact(value) {
3884
- const redacted = redactProtectedValue(value, this.protectedValues);
3885
- this.aggregate.version = redacted.report.version;
3886
- this.aggregate.redactionCount += redacted.report.redactionCount;
3887
- for (const [rule, count] of Object.entries(redacted.report.byRule)) {
3888
- this.aggregate.byRule[rule] = (this.aggregate.byRule[rule] ?? 0) + count;
3933
+ let started;
3934
+ try {
3935
+ started = operation();
3936
+ } catch (error) {
3937
+ return Promise.reject(error);
3889
3938
  }
3890
- return redacted.value;
3891
- }
3892
- };
3939
+ let tracked;
3940
+ tracked = started.finally(() => pendingWrites.delete(tracked));
3941
+ pendingWrites.add(tracked);
3942
+ return tracked;
3943
+ };
3944
+ const store = Object.freeze({
3945
+ appendRun: (run) => write(() => inner.appendRun(redactor.record(run))),
3946
+ updateRun: (runId, patch) => write(() => inner.updateRun(redactor.identifier(runId), redactor.record(patch))),
3947
+ appendSpan: (span) => write(async () => {
3948
+ if (span.kind === "llm") {
3949
+ throw new Error("candidate executors cannot author protected model spans");
3950
+ }
3951
+ await inner.appendSpan(redactor.record(span));
3952
+ }),
3953
+ updateSpan: (spanId, patch) => write(async () => {
3954
+ if (patch.kind === "llm") {
3955
+ throw new Error("candidate executors cannot author protected model spans");
3956
+ }
3957
+ await inner.updateSpan(redactor.identifier(spanId), redactor.record(patch));
3958
+ }),
3959
+ appendEvent: (event) => write(() => inner.appendEvent(redactor.record(event))),
3960
+ appendArtifact: (artifact) => write(() => inner.appendArtifact(redactor.record(artifact))),
3961
+ appendBudgetEntry: (entry) => write(() => inner.appendBudgetEntry(redactor.record(entry))),
3962
+ getRun: async (runId) => inner.getRun(redactor.identifier(runId)),
3963
+ listRuns: async (filter) => inner.listRuns(filter ? redactor.query(filter) : void 0),
3964
+ spans: async (filter) => inner.spans(filter ? redactor.query(filter) : void 0),
3965
+ events: async (filter) => inner.events(filter ? redactor.query(filter) : void 0),
3966
+ budget: async (runId) => inner.budget(redactor.identifier(runId)),
3967
+ artifacts: async (runId) => inner.artifacts(redactor.identifier(runId))
3968
+ });
3969
+ return Object.freeze({
3970
+ store,
3971
+ closeWrites: async () => {
3972
+ acceptsWrites = false;
3973
+ await Promise.all([...pendingWrites]);
3974
+ },
3975
+ identity: (trace) => redactor.traceIdentity(trace),
3976
+ report: () => redactor.report()
3977
+ });
3978
+ }
3893
3979
  var RecoveryAgentCandidateTraceStore = class {
3894
3980
  constructor(inner) {
3895
3981
  this.inner = inner;
@@ -4133,26 +4219,36 @@ async function executePreparedAgentCandidate(prepared, options) {
4133
4219
  );
4134
4220
  }
4135
4221
  const protectedValues = protectedEnvironmentValues(activation, memoryActivation);
4136
- const protectedTraceStore = new ProtectedAgentCandidateTraceStore(
4222
+ const protectedTrace = createProtectedAgentCandidateTraceAccess(
4137
4223
  options.traceStore,
4138
4224
  protectedValues
4139
4225
  );
4226
+ const persistedTrace = protectedTrace.identity(state.trace);
4140
4227
  const execution = await runAndStopExecutor(
4141
4228
  options.executor,
4142
4229
  request,
4143
4230
  state.benchmarkTask.outcome,
4144
- protectedTraceStore,
4231
+ protectedTrace.store,
4145
4232
  deadlineAtMs,
4146
4233
  cleanupTimeoutMs
4147
4234
  );
4148
4235
  beginPreparedCandidateSettlement(prepared);
4149
4236
  const cleanupDeadlineAtMs = candidateCleanupDeadline(cleanupTimeoutMs);
4150
4237
  const accessReason = execution.kind === "timeout" || execution.termination?.kind === "timeout" ? "timeout" : execution.kind === "capture" ? "completed" : "failed";
4151
- const [memoryClose, settlementResult] = await Promise.all([
4238
+ const traceClosure = withinCandidateCleanupDeadline(
4239
+ () => protectedTrace.closeWrites(),
4240
+ cleanupDeadlineAtMs,
4241
+ "candidate trace write closure"
4242
+ ).then(
4243
+ () => ({ closed: true, error: void 0 }),
4244
+ (error) => ({ closed: false, error })
4245
+ );
4246
+ const [traceClose, memoryClose, settlementResult] = await Promise.all([
4247
+ traceClosure,
4152
4248
  closeMemoryAccess(state, accessReason, cleanupDeadlineAtMs),
4153
4249
  settleModelGrant(state, accessReason, cleanupDeadlineAtMs)
4154
4250
  ]);
4155
- if (!execution.processStopped || !settlementResult.settlement || !memoryClose.closed) {
4251
+ if (!execution.processStopped || !traceClose.closed || !settlementResult.settlement || !memoryClose.closed) {
4156
4252
  consumePreparedCandidateExecution(prepared, "failed");
4157
4253
  return failedAgentCandidateRun(
4158
4254
  state,
@@ -4160,6 +4256,7 @@ async function executePreparedAgentCandidate(prepared, options) {
4160
4256
  joinErrors(
4161
4257
  execution.error,
4162
4258
  !execution.processStopped ? new Error("candidate process termination is not proven") : void 0,
4259
+ traceClose.error,
4163
4260
  memoryClose.error,
4164
4261
  settlementResult.error ?? (!settlementResult.settlement ? new Error("model settlement failed") : void 0),
4165
4262
  new Error("candidate claim remains recoverable until protected cleanup is proven")
@@ -4226,7 +4323,7 @@ async function executePreparedAgentCandidate(prepared, options) {
4226
4323
  async (signal) => {
4227
4324
  await appendAuthoritativeModelSettlementSpans(
4228
4325
  options.traceStore,
4229
- state.trace.runId,
4326
+ persistedTrace.runId,
4230
4327
  settlementResult.settlement
4231
4328
  );
4232
4329
  const { persistedCapture, taskOutcome } = await persistVerifiedAgentCandidateExecutorCapture(
@@ -4249,6 +4346,7 @@ async function executePreparedAgentCandidate(prepared, options) {
4249
4346
  state,
4250
4347
  capture,
4251
4348
  options.traceStore,
4349
+ persistedTrace,
4252
4350
  settlementResult.settlement,
4253
4351
  {
4254
4352
  finalCapture: execution.finalCapture,
@@ -4259,7 +4357,7 @@ async function executePreparedAgentCandidate(prepared, options) {
4259
4357
  outputArtifacts: options.outputArtifacts
4260
4358
  },
4261
4359
  protectedValues,
4262
- protectedTraceStore.report(),
4360
+ protectedTrace.report(),
4263
4361
  signal
4264
4362
  );
4265
4363
  },
@@ -4823,6 +4921,7 @@ function resourceKey(resource) {
4823
4921
  import { mkdtemp as mkdtemp3, rm as rm3 } from "fs/promises";
4824
4922
  import { tmpdir as tmpdir3 } from "os";
4825
4923
  import { join as join3, posix } from "path";
4924
+ import { hashKnowledgeBase } from "@tangle-network/agent-knowledge";
4826
4925
  var CANDIDATE_KNOWLEDGE_ROOT_ENV = "TANGLE_CANDIDATE_KNOWLEDGE_ROOT";
4827
4926
  var CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV = "TANGLE_CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG";
4828
4927
  function candidateKnowledgeExecutionPaths(taskRoot, hasRetrievalConfig) {
@@ -4835,7 +4934,7 @@ function candidateKnowledgeExecutionPaths(taskRoot, hasRetrievalConfig) {
4835
4934
  ...hasRetrievalConfig ? { retrievalConfig: posix.join(parent, "knowledge-retrieval-config.json") } : {}
4836
4935
  };
4837
4936
  }
4838
- async function prepareAgentCandidateKnowledge(candidate, ports) {
4937
+ async function prepareAgentCandidateKnowledge(candidate, ports, arm) {
4839
4938
  const knowledge = candidate.bundle.knowledge;
4840
4939
  if (!knowledge) return void 0;
4841
4940
  const archive = await verifiedArtifactBytes(candidate, knowledge.snapshot.archive);
@@ -4848,6 +4947,13 @@ async function prepareAgentCandidateKnowledge(candidate, ports) {
4848
4947
  archive,
4849
4948
  destination: root
4850
4949
  });
4950
+ const expectedHash = arm === "baseline" ? knowledge.candidate.baseHash : knowledge.candidate.candidateHash;
4951
+ const actualHash = `sha256:${await hashKnowledgeBase(root)}`;
4952
+ if (actualHash !== expectedHash) {
4953
+ throw new Error(
4954
+ `materialized ${arm} knowledge does not match its measured content: expected ${expectedHash}, got ${actualHash}`
4955
+ );
4956
+ }
4851
4957
  const files = await readMaterializedWorkspaceFiles(root, knowledge.snapshot.material);
4852
4958
  return Object.freeze({
4853
4959
  candidate: knowledge.candidate,
@@ -4865,7 +4971,7 @@ async function prepareAgentCandidateKnowledge(candidate, ports) {
4865
4971
  }
4866
4972
 
4867
4973
  // src/candidate-execution/prepare.ts
4868
- import { randomBytes as randomBytes2 } from "crypto";
4974
+ import { randomBytes as randomBytes3 } from "crypto";
4869
4975
  import { lstat as lstat2, readdir as readdir2 } from "fs/promises";
4870
4976
  import { isAbsolute, posix as posix2, relative as relative2, resolve as resolveHostPath } from "path";
4871
4977
  import {
@@ -4991,7 +5097,7 @@ async function prepareAgentCandidateExecution(candidate, task, ports, options =
4991
5097
  const profileActivation = profileApplication.profileActivation;
4992
5098
  const container = await resolveContainer(candidate, task, ports);
4993
5099
  const resolvedModel = await resolveModel(candidate, task, ports);
4994
- const preparationId = `candidate-preparation.${randomBytes2(32).toString("base64url")}`;
5100
+ const preparationId = `candidate-preparation.${randomBytes3(32).toString("base64url")}`;
4995
5101
  const reservationExpiresAtMs = Date.now() + Math.max(MIN_RESERVATION_TTL_MS, reservationWindowMs);
4996
5102
  const modelReservation = await withinCandidateCleanupDeadline(
4997
5103
  () => ports.models.reserveGrant({
@@ -5023,7 +5129,7 @@ async function prepareAgentCandidateExecution(candidate, task, ports, options =
5023
5129
  cleanupTimeoutMs
5024
5130
  );
5025
5131
  const memory = preparedMemory.value;
5026
- const knowledge = await prepareAgentCandidateKnowledge(candidate, ports);
5132
+ const knowledge = await prepareAgentCandidateKnowledge(candidate, ports, task.runCell.arm);
5027
5133
  const knowledgePaths = knowledge ? candidateKnowledgeExecutionPaths(
5028
5134
  task.executionRoots.taskRoot,
5029
5135
  knowledge.retrievalConfig !== void 0
@@ -5657,6 +5763,7 @@ export {
5657
5763
  createAgentCandidateProfileActivation,
5658
5764
  parseAgentCandidateProfileActivation,
5659
5765
  freezeGenericAgentCandidateProfile,
5766
+ assertCandidateProfileBinding,
5660
5767
  parseExactAgentProfile,
5661
5768
  parseExactAgentProfileDiff,
5662
5769
  applyExactAgentProfileDiff,
@@ -5707,4 +5814,4 @@ export {
5707
5814
  candidateKnowledgeExecutionPaths,
5708
5815
  prepareAgentCandidateExecution
5709
5816
  };
5710
- //# sourceMappingURL=chunk-WTZ37EQY.js.map
5817
+ //# sourceMappingURL=chunk-YOLKCWRV.js.map