@tangle-network/agent-runtime 0.101.0 → 0.102.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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/agent.js +4 -3
  3. package/dist/agent.js.map +1 -1
  4. package/dist/candidate-execution/index.d.ts +13 -2
  5. package/dist/candidate-execution/index.js +7 -3
  6. package/dist/{chunk-LV6WCT43.js → chunk-23Z7N5IG.js} +5 -5
  7. package/dist/chunk-2VZYRB55.js +834 -0
  8. package/dist/chunk-2VZYRB55.js.map +1 -0
  9. package/dist/{chunk-VOPHC4LB.js → chunk-4AMAFNUD.js} +32 -192
  10. package/dist/chunk-4AMAFNUD.js.map +1 -0
  11. package/dist/{chunk-BXZ7GPL4.js → chunk-AIBIRAJ6.js} +2 -2
  12. package/dist/{chunk-Y3SRWZMP.js → chunk-AYU35OTU.js} +2 -2
  13. package/dist/{chunk-U4PRAATQ.js → chunk-DA7YL6I4.js} +3 -3
  14. package/dist/{chunk-HZDEXTSL.js → chunk-IKGCKPDX.js} +2 -833
  15. package/dist/chunk-IKGCKPDX.js.map +1 -0
  16. package/dist/{chunk-WYC2XJF2.js → chunk-KSBUSEUA.js} +2 -2
  17. package/dist/{chunk-UQ6PNNXM.js → chunk-KVJQV342.js} +5 -3
  18. package/dist/{chunk-UQ6PNNXM.js.map → chunk-KVJQV342.js.map} +1 -1
  19. package/dist/chunk-LKKIM5QD.js +200 -0
  20. package/dist/chunk-LKKIM5QD.js.map +1 -0
  21. package/dist/{chunk-FXF2OL34.js → chunk-MAONWP4R.js} +2 -2
  22. package/dist/{chunk-SGQ4YIQW.js → chunk-N2CEE5Q3.js} +3 -3
  23. package/dist/chunk-SPCD4IQQ.js +578 -0
  24. package/dist/chunk-SPCD4IQQ.js.map +1 -0
  25. package/dist/{chunk-HGSHPVJ6.js → chunk-TGDHHHH4.js} +189 -189
  26. package/dist/{chunk-HGSHPVJ6.js.map → chunk-TGDHHHH4.js.map} +1 -1
  27. package/dist/{improve-g75IE2Cx.d.ts → improve-CIml6hT3.d.ts} +7 -0
  28. package/dist/index.d.ts +4 -4
  29. package/dist/index.js +16 -10
  30. package/dist/index.js.map +1 -1
  31. package/dist/intelligence.d.ts +60 -59
  32. package/dist/intelligence.js +65 -473
  33. package/dist/intelligence.js.map +1 -1
  34. package/dist/knowledge.js +8 -6
  35. package/dist/loop-runner-bin.js +5 -4
  36. package/dist/loops.js +4 -3
  37. package/dist/mcp/bin.js +4 -3
  38. package/dist/mcp/bin.js.map +1 -1
  39. package/dist/mcp/index.js +6 -5
  40. package/dist/mcp/index.js.map +1 -1
  41. package/dist/testing.d.ts +6 -0
  42. package/dist/testing.js +2638 -0
  43. package/dist/testing.js.map +1 -0
  44. package/package.json +11 -4
  45. package/dist/chunk-HZDEXTSL.js.map +0 -1
  46. package/dist/chunk-VOPHC4LB.js.map +0 -1
  47. /package/dist/{chunk-LV6WCT43.js.map → chunk-23Z7N5IG.js.map} +0 -0
  48. /package/dist/{chunk-BXZ7GPL4.js.map → chunk-AIBIRAJ6.js.map} +0 -0
  49. /package/dist/{chunk-Y3SRWZMP.js.map → chunk-AYU35OTU.js.map} +0 -0
  50. /package/dist/{chunk-U4PRAATQ.js.map → chunk-DA7YL6I4.js.map} +0 -0
  51. /package/dist/{chunk-WYC2XJF2.js.map → chunk-KSBUSEUA.js.map} +0 -0
  52. /package/dist/{chunk-FXF2OL34.js.map → chunk-MAONWP4R.js.map} +0 -0
  53. /package/dist/{chunk-SGQ4YIQW.js.map → chunk-N2CEE5Q3.js.map} +0 -0
@@ -2531,6 +2531,182 @@ function retryLineageDigest(prepared, resultTimeoutMs) {
2531
2531
  });
2532
2532
  }
2533
2533
 
2534
+ // src/candidate-execution/verify.ts
2535
+ import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
2536
+ var verifiedCandidateState = /* @__PURE__ */ new WeakMap();
2537
+ var AGENT_CANDIDATE_EXECUTION_SUPPORT = Object.freeze({
2538
+ outcomes: Object.freeze(["workspace", "output"]),
2539
+ code: Object.freeze(["disabled", "no-op", "git-patch"]),
2540
+ memory: Object.freeze(["disabled", "isolated"]),
2541
+ knowledge: true,
2542
+ profile: Object.freeze({
2543
+ mcpTransports: Object.freeze(["stdio"]),
2544
+ remoteMcp: false,
2545
+ tools: false,
2546
+ permissions: false,
2547
+ modes: false,
2548
+ confidential: false
2549
+ })
2550
+ });
2551
+ async function verifyAgentCandidateBundle(input, ports) {
2552
+ const parsed = agentCandidateBundleSchema.parse(input);
2553
+ const withoutDigest = omitTopLevelDigest(parsed);
2554
+ const actualDigest = canonicalCandidateDigest(withoutDigest);
2555
+ if (actualDigest !== parsed.digest) {
2556
+ throw new Error(`candidate bundle digest ${parsed.digest} does not match ${actualDigest}`);
2557
+ }
2558
+ const canonicalBytes = canonicalCandidateBytes(withoutDigest);
2559
+ verifyBytes(canonicalBytes, parsed.digest, canonicalBytes.byteLength, "candidate bundle");
2560
+ assertCandidateProfileExecutionSupport(parsed.profile);
2561
+ const artifactBytes = /* @__PURE__ */ new Map();
2562
+ const readArtifact = async (artifact) => {
2563
+ const key = artifactCacheKey(artifact);
2564
+ const existing = artifactBytes.get(key);
2565
+ if (existing) return Uint8Array.from(existing);
2566
+ const bytes = await readVerifiedArtifact(artifact, ports.artifacts);
2567
+ artifactBytes.set(key, Uint8Array.from(bytes));
2568
+ return bytes;
2569
+ };
2570
+ let patchBytes;
2571
+ if (parsed.code.kind === "git-patch") {
2572
+ patchBytes = await readArtifact(parsed.code.patch.artifact);
2573
+ }
2574
+ const materializedTree = await verifyCandidateCode(parsed.code, ports.repositories, patchBytes);
2575
+ const resourceBytes = /* @__PURE__ */ new Map();
2576
+ for (const resource of candidateResources(parsed)) {
2577
+ const bytes = resource.kind === "inline" ? Buffer.from(resource.content, "utf8") : await readCandidateGitHubResource(resource, ports.repositories);
2578
+ verifyBytes(
2579
+ bytes,
2580
+ resource.sha256,
2581
+ resource.byteLength,
2582
+ `candidate resource ${resource.name ?? (resource.kind === "github" ? resource.path : "<unnamed>")}`
2583
+ );
2584
+ resourceBytes.set(resourceKey(resource), Uint8Array.from(bytes));
2585
+ resourceBytes.set(resource.sha256, Uint8Array.from(bytes));
2586
+ }
2587
+ if (parsed.execution.workspace) {
2588
+ const workspace = await verifyWorkspaceSnapshotArtifacts(
2589
+ parsed.execution.workspace,
2590
+ ports.artifacts
2591
+ );
2592
+ artifactBytes.set(artifactCacheKey(parsed.execution.workspace.manifest), workspace.manifest);
2593
+ artifactBytes.set(artifactCacheKey(parsed.execution.workspace.archive), workspace.archive);
2594
+ }
2595
+ if (parsed.knowledge) {
2596
+ const knowledge = await verifyWorkspaceSnapshotArtifacts(
2597
+ parsed.knowledge.snapshot,
2598
+ ports.artifacts
2599
+ );
2600
+ artifactBytes.set(artifactCacheKey(parsed.knowledge.snapshot.manifest), knowledge.manifest);
2601
+ artifactBytes.set(artifactCacheKey(parsed.knowledge.snapshot.archive), knowledge.archive);
2602
+ if (parsed.knowledge.retrievalConfig) await readArtifact(parsed.knowledge.retrievalConfig);
2603
+ await readArtifact(parsed.knowledge.evaluation);
2604
+ }
2605
+ if (parsed.memory.mode === "isolated" && parsed.memory.seed)
2606
+ await readArtifact(parsed.memory.seed);
2607
+ deepFreezeCandidate(parsed);
2608
+ const verified = Object.freeze({
2609
+ bundle: parsed,
2610
+ ...materializedTree === void 0 ? {} : { materializedTree },
2611
+ [verifiedCandidateBrand]: true
2612
+ });
2613
+ verifiedCandidateState.set(verified, { ports, artifactBytes, resourceBytes });
2614
+ return verified;
2615
+ }
2616
+ function getVerifiedCandidateState(candidate) {
2617
+ const state = verifiedCandidateState.get(candidate);
2618
+ if (!state || candidate[verifiedCandidateBrand] !== true) {
2619
+ throw new Error("candidate must come from verifyAgentCandidateBundle");
2620
+ }
2621
+ return state;
2622
+ }
2623
+ async function verifiedArtifactBytes(candidate, artifact) {
2624
+ const state = getVerifiedCandidateState(candidate);
2625
+ const key = artifactCacheKey(artifact);
2626
+ const existing = state.artifactBytes.get(key);
2627
+ if (existing) return Uint8Array.from(existing);
2628
+ const bytes = await readVerifiedArtifact(artifact, state.ports.artifacts);
2629
+ state.artifactBytes.set(key, Uint8Array.from(bytes));
2630
+ return bytes;
2631
+ }
2632
+ function verifiedResourceTextByDigest(candidate) {
2633
+ const output = /* @__PURE__ */ new Map();
2634
+ for (const resource of candidateResources(candidate.bundle)) {
2635
+ const bytes = getVerifiedCandidateState(candidate).resourceBytes.get(resource.sha256);
2636
+ if (!bytes) throw new Error(`candidate resource digest was not verified: ${resource.sha256}`);
2637
+ output.set(resource.sha256, new TextDecoder("utf-8", { fatal: true }).decode(bytes));
2638
+ }
2639
+ return output;
2640
+ }
2641
+ function candidateResources(bundle) {
2642
+ const resources = bundle.profile.resources;
2643
+ if (!resources) return [];
2644
+ const output = [];
2645
+ for (const mount of resources.files ?? []) output.push(mount.resource);
2646
+ output.push(...resources.tools ?? []);
2647
+ output.push(...resources.skills ?? []);
2648
+ output.push(...resources.agents ?? []);
2649
+ output.push(...resources.commands ?? []);
2650
+ if (typeof resources.instructions === "object") output.push(resources.instructions);
2651
+ return output;
2652
+ }
2653
+ function resourceKey(resource) {
2654
+ return canonicalCandidateDigest(resource);
2655
+ }
2656
+
2657
+ // src/candidate-execution/knowledge.ts
2658
+ import { mkdtemp as mkdtemp2, rm as rm2 } from "fs/promises";
2659
+ import { tmpdir as tmpdir2 } from "os";
2660
+ import { join as join2, posix } from "path";
2661
+ import { hashKnowledgeBase } from "@tangle-network/agent-knowledge";
2662
+ var CANDIDATE_KNOWLEDGE_ROOT_ENV = "TANGLE_CANDIDATE_KNOWLEDGE_ROOT";
2663
+ var CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV = "TANGLE_CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG";
2664
+ function candidateKnowledgeExecutionPaths(taskRoot, hasRetrievalConfig) {
2665
+ if (!posix.isAbsolute(taskRoot) || posix.normalize(taskRoot) !== taskRoot) {
2666
+ throw new Error("candidate knowledge requires a normalized absolute task root");
2667
+ }
2668
+ const parent = posix.join(taskRoot, ".tangle");
2669
+ return {
2670
+ root: posix.join(parent, "knowledge"),
2671
+ ...hasRetrievalConfig ? { retrievalConfig: posix.join(parent, "knowledge-retrieval-config.json") } : {}
2672
+ };
2673
+ }
2674
+ async function prepareAgentCandidateKnowledge(candidate, ports, arm) {
2675
+ const knowledge = candidate.bundle.knowledge;
2676
+ if (!knowledge) return void 0;
2677
+ const archive = await verifiedArtifactBytes(candidate, knowledge.snapshot.archive);
2678
+ const retrievalConfig = knowledge.retrievalConfig ? await verifiedArtifactBytes(candidate, knowledge.retrievalConfig) : void 0;
2679
+ const root = await mkdtemp2(join2(tmpdir2(), "agent-candidate-knowledge-"));
2680
+ try {
2681
+ await ports.workspaces.materialize({
2682
+ role: "knowledge",
2683
+ snapshot: knowledge.snapshot,
2684
+ archive,
2685
+ destination: root
2686
+ });
2687
+ const expectedHash = arm === "baseline" ? knowledge.candidate.baseHash : knowledge.candidate.candidateHash;
2688
+ const actualHash = `sha256:${await hashKnowledgeBase(root)}`;
2689
+ if (actualHash !== expectedHash) {
2690
+ throw new Error(
2691
+ `materialized ${arm} knowledge does not match its measured content: expected ${expectedHash}, got ${actualHash}`
2692
+ );
2693
+ }
2694
+ const files = await readMaterializedWorkspaceFiles(root, knowledge.snapshot.material);
2695
+ return Object.freeze({
2696
+ candidate: knowledge.candidate,
2697
+ snapshot: knowledge.snapshot,
2698
+ files: Object.freeze(
2699
+ files.map(
2700
+ (file) => Object.freeze({ path: file.path, mode: file.mode, bytes: Uint8Array.from(file.bytes) })
2701
+ )
2702
+ ),
2703
+ ...retrievalConfig ? { retrievalConfig: Uint8Array.from(retrievalConfig) } : {}
2704
+ });
2705
+ } finally {
2706
+ await rm2(root, { recursive: true, force: true });
2707
+ }
2708
+ }
2709
+
2534
2710
  // src/candidate-execution/output-artifacts.ts
2535
2711
  import {
2536
2712
  agentCandidateArtifactRefSchema as agentCandidateArtifactRefSchema3
@@ -3348,9 +3524,9 @@ function compareStrings(a, b) {
3348
3524
  }
3349
3525
 
3350
3526
  // src/candidate-execution/outcome-evidence.ts
3351
- import { mkdtemp as mkdtemp2, rm as rm2 } from "fs/promises";
3352
- import { tmpdir as tmpdir2 } from "os";
3353
- import { join as join2 } from "path";
3527
+ import { mkdtemp as mkdtemp3, rm as rm3 } from "fs/promises";
3528
+ import { tmpdir as tmpdir3 } from "os";
3529
+ import { join as join3 } from "path";
3354
3530
  import {
3355
3531
  agentCandidateBenchmarkResultEvidenceSchema,
3356
3532
  agentCandidateModelSettlementEvidenceSchema,
@@ -3846,7 +4022,7 @@ async function persistCandidateBenchmarkResult(state, termination, outcome, grad
3846
4022
  );
3847
4023
  }
3848
4024
  async function verifyTaskOutcomeArchive(state, snapshot, archive, protectedValues) {
3849
- const root = await mkdtemp2(join2(tmpdir2(), "agent-candidate-task-archive-"));
4025
+ const root = await mkdtemp3(join3(tmpdir3(), "agent-candidate-task-archive-"));
3850
4026
  try {
3851
4027
  await state.ports.workspaces.materialize({
3852
4028
  role: "task",
@@ -3857,7 +4033,7 @@ async function verifyTaskOutcomeArchive(state, snapshot, archive, protectedValue
3857
4033
  const files = await readMaterializedWorkspaceFiles(root, snapshot.material);
3858
4034
  for (const file of files) assertNoProtectedBytes(file.bytes, protectedValues);
3859
4035
  } finally {
3860
- await rm2(root, { recursive: true, force: true });
4036
+ await rm3(root, { recursive: true, force: true });
3861
4037
  }
3862
4038
  }
3863
4039
  async function verifyMemoryCapture(state, capture, protectedValues, signal) {
@@ -3878,7 +4054,7 @@ async function verifyMemoryCapture(state, capture, protectedValues, signal) {
3878
4054
  manifest: embeddedCandidateArtifact(manifestBytes),
3879
4055
  archive: embeddedCandidateArtifact(memory.archive)
3880
4056
  });
3881
- const root = await mkdtemp2(join2(tmpdir2(), "agent-candidate-memory-after-"));
4057
+ const root = await mkdtemp3(join3(tmpdir3(), "agent-candidate-memory-after-"));
3882
4058
  try {
3883
4059
  await state.ports.workspaces.materialize({
3884
4060
  role: "memory",
@@ -3890,7 +4066,7 @@ async function verifyMemoryCapture(state, capture, protectedValues, signal) {
3890
4066
  for (const file of files) assertNoProtectedBytes(file.bytes, protectedValues);
3891
4067
  signal?.throwIfAborted();
3892
4068
  } finally {
3893
- await rm2(root, { recursive: true, force: true });
4069
+ await rm3(root, { recursive: true, force: true });
3894
4070
  }
3895
4071
  }
3896
4072
  function normalizeEvaluation(evaluation, termination) {
@@ -4794,182 +4970,6 @@ var CandidateExecutionDeadlineError = class extends Error {
4794
4970
  }
4795
4971
  };
4796
4972
 
4797
- // src/candidate-execution/verify.ts
4798
- import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
4799
- var verifiedCandidateState = /* @__PURE__ */ new WeakMap();
4800
- var AGENT_CANDIDATE_EXECUTION_SUPPORT = Object.freeze({
4801
- outcomes: Object.freeze(["workspace", "output"]),
4802
- code: Object.freeze(["disabled", "no-op", "git-patch"]),
4803
- memory: Object.freeze(["disabled", "isolated"]),
4804
- knowledge: true,
4805
- profile: Object.freeze({
4806
- mcpTransports: Object.freeze(["stdio"]),
4807
- remoteMcp: false,
4808
- tools: false,
4809
- permissions: false,
4810
- modes: false,
4811
- confidential: false
4812
- })
4813
- });
4814
- async function verifyAgentCandidateBundle(input, ports) {
4815
- const parsed = agentCandidateBundleSchema.parse(input);
4816
- const withoutDigest = omitTopLevelDigest(parsed);
4817
- const actualDigest = canonicalCandidateDigest(withoutDigest);
4818
- if (actualDigest !== parsed.digest) {
4819
- throw new Error(`candidate bundle digest ${parsed.digest} does not match ${actualDigest}`);
4820
- }
4821
- const canonicalBytes = canonicalCandidateBytes(withoutDigest);
4822
- verifyBytes(canonicalBytes, parsed.digest, canonicalBytes.byteLength, "candidate bundle");
4823
- assertCandidateProfileExecutionSupport(parsed.profile);
4824
- const artifactBytes = /* @__PURE__ */ new Map();
4825
- const readArtifact = async (artifact) => {
4826
- const key = artifactCacheKey(artifact);
4827
- const existing = artifactBytes.get(key);
4828
- if (existing) return Uint8Array.from(existing);
4829
- const bytes = await readVerifiedArtifact(artifact, ports.artifacts);
4830
- artifactBytes.set(key, Uint8Array.from(bytes));
4831
- return bytes;
4832
- };
4833
- let patchBytes;
4834
- if (parsed.code.kind === "git-patch") {
4835
- patchBytes = await readArtifact(parsed.code.patch.artifact);
4836
- }
4837
- const materializedTree = await verifyCandidateCode(parsed.code, ports.repositories, patchBytes);
4838
- const resourceBytes = /* @__PURE__ */ new Map();
4839
- for (const resource of candidateResources(parsed)) {
4840
- const bytes = resource.kind === "inline" ? Buffer.from(resource.content, "utf8") : await readCandidateGitHubResource(resource, ports.repositories);
4841
- verifyBytes(
4842
- bytes,
4843
- resource.sha256,
4844
- resource.byteLength,
4845
- `candidate resource ${resource.name ?? (resource.kind === "github" ? resource.path : "<unnamed>")}`
4846
- );
4847
- resourceBytes.set(resourceKey(resource), Uint8Array.from(bytes));
4848
- resourceBytes.set(resource.sha256, Uint8Array.from(bytes));
4849
- }
4850
- if (parsed.execution.workspace) {
4851
- const workspace = await verifyWorkspaceSnapshotArtifacts(
4852
- parsed.execution.workspace,
4853
- ports.artifacts
4854
- );
4855
- artifactBytes.set(artifactCacheKey(parsed.execution.workspace.manifest), workspace.manifest);
4856
- artifactBytes.set(artifactCacheKey(parsed.execution.workspace.archive), workspace.archive);
4857
- }
4858
- if (parsed.knowledge) {
4859
- const knowledge = await verifyWorkspaceSnapshotArtifacts(
4860
- parsed.knowledge.snapshot,
4861
- ports.artifacts
4862
- );
4863
- artifactBytes.set(artifactCacheKey(parsed.knowledge.snapshot.manifest), knowledge.manifest);
4864
- artifactBytes.set(artifactCacheKey(parsed.knowledge.snapshot.archive), knowledge.archive);
4865
- if (parsed.knowledge.retrievalConfig) await readArtifact(parsed.knowledge.retrievalConfig);
4866
- await readArtifact(parsed.knowledge.evaluation);
4867
- }
4868
- if (parsed.memory.mode === "isolated" && parsed.memory.seed)
4869
- await readArtifact(parsed.memory.seed);
4870
- deepFreezeCandidate(parsed);
4871
- const verified = Object.freeze({
4872
- bundle: parsed,
4873
- ...materializedTree === void 0 ? {} : { materializedTree },
4874
- [verifiedCandidateBrand]: true
4875
- });
4876
- verifiedCandidateState.set(verified, { ports, artifactBytes, resourceBytes });
4877
- return verified;
4878
- }
4879
- function getVerifiedCandidateState(candidate) {
4880
- const state = verifiedCandidateState.get(candidate);
4881
- if (!state || candidate[verifiedCandidateBrand] !== true) {
4882
- throw new Error("candidate must come from verifyAgentCandidateBundle");
4883
- }
4884
- return state;
4885
- }
4886
- async function verifiedArtifactBytes(candidate, artifact) {
4887
- const state = getVerifiedCandidateState(candidate);
4888
- const key = artifactCacheKey(artifact);
4889
- const existing = state.artifactBytes.get(key);
4890
- if (existing) return Uint8Array.from(existing);
4891
- const bytes = await readVerifiedArtifact(artifact, state.ports.artifacts);
4892
- state.artifactBytes.set(key, Uint8Array.from(bytes));
4893
- return bytes;
4894
- }
4895
- function verifiedResourceTextByDigest(candidate) {
4896
- const output = /* @__PURE__ */ new Map();
4897
- for (const resource of candidateResources(candidate.bundle)) {
4898
- const bytes = getVerifiedCandidateState(candidate).resourceBytes.get(resource.sha256);
4899
- if (!bytes) throw new Error(`candidate resource digest was not verified: ${resource.sha256}`);
4900
- output.set(resource.sha256, new TextDecoder("utf-8", { fatal: true }).decode(bytes));
4901
- }
4902
- return output;
4903
- }
4904
- function candidateResources(bundle) {
4905
- const resources = bundle.profile.resources;
4906
- if (!resources) return [];
4907
- const output = [];
4908
- for (const mount of resources.files ?? []) output.push(mount.resource);
4909
- output.push(...resources.tools ?? []);
4910
- output.push(...resources.skills ?? []);
4911
- output.push(...resources.agents ?? []);
4912
- output.push(...resources.commands ?? []);
4913
- if (typeof resources.instructions === "object") output.push(resources.instructions);
4914
- return output;
4915
- }
4916
- function resourceKey(resource) {
4917
- return canonicalCandidateDigest(resource);
4918
- }
4919
-
4920
- // src/candidate-execution/knowledge.ts
4921
- import { mkdtemp as mkdtemp3, rm as rm3 } from "fs/promises";
4922
- import { tmpdir as tmpdir3 } from "os";
4923
- import { join as join3, posix } from "path";
4924
- import { hashKnowledgeBase } from "@tangle-network/agent-knowledge";
4925
- var CANDIDATE_KNOWLEDGE_ROOT_ENV = "TANGLE_CANDIDATE_KNOWLEDGE_ROOT";
4926
- var CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV = "TANGLE_CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG";
4927
- function candidateKnowledgeExecutionPaths(taskRoot, hasRetrievalConfig) {
4928
- if (!posix.isAbsolute(taskRoot) || posix.normalize(taskRoot) !== taskRoot) {
4929
- throw new Error("candidate knowledge requires a normalized absolute task root");
4930
- }
4931
- const parent = posix.join(taskRoot, ".tangle");
4932
- return {
4933
- root: posix.join(parent, "knowledge"),
4934
- ...hasRetrievalConfig ? { retrievalConfig: posix.join(parent, "knowledge-retrieval-config.json") } : {}
4935
- };
4936
- }
4937
- async function prepareAgentCandidateKnowledge(candidate, ports, arm) {
4938
- const knowledge = candidate.bundle.knowledge;
4939
- if (!knowledge) return void 0;
4940
- const archive = await verifiedArtifactBytes(candidate, knowledge.snapshot.archive);
4941
- const retrievalConfig = knowledge.retrievalConfig ? await verifiedArtifactBytes(candidate, knowledge.retrievalConfig) : void 0;
4942
- const root = await mkdtemp3(join3(tmpdir3(), "agent-candidate-knowledge-"));
4943
- try {
4944
- await ports.workspaces.materialize({
4945
- role: "knowledge",
4946
- snapshot: knowledge.snapshot,
4947
- archive,
4948
- destination: root
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
- }
4957
- const files = await readMaterializedWorkspaceFiles(root, knowledge.snapshot.material);
4958
- return Object.freeze({
4959
- candidate: knowledge.candidate,
4960
- snapshot: knowledge.snapshot,
4961
- files: Object.freeze(
4962
- files.map(
4963
- (file) => Object.freeze({ path: file.path, mode: file.mode, bytes: Uint8Array.from(file.bytes) })
4964
- )
4965
- ),
4966
- ...retrievalConfig ? { retrievalConfig: Uint8Array.from(retrievalConfig) } : {}
4967
- });
4968
- } finally {
4969
- await rm3(root, { recursive: true, force: true });
4970
- }
4971
- }
4972
-
4973
4973
  // src/candidate-execution/prepare.ts
4974
4974
  import { randomBytes as randomBytes3 } from "crypto";
4975
4975
  import { lstat as lstat2, readdir as readdir2 } from "fs/promises";
@@ -5802,17 +5802,17 @@ export {
5802
5802
  candidateClaimFileInternals,
5803
5803
  sealAgentCandidateModelSettlement,
5804
5804
  usdToNanos,
5805
- sealAgentCandidateExecutorStopAcknowledgement,
5806
- persistCandidateOutputArtifact,
5807
- persistCandidateModelSettlementEvidence,
5808
- RecoveryAgentCandidateTraceStore,
5809
- executePreparedAgentCandidate,
5810
5805
  AGENT_CANDIDATE_EXECUTION_SUPPORT,
5811
5806
  verifyAgentCandidateBundle,
5812
5807
  verifiedResourceTextByDigest,
5813
5808
  CANDIDATE_KNOWLEDGE_ROOT_ENV,
5814
5809
  CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV,
5815
5810
  candidateKnowledgeExecutionPaths,
5811
+ sealAgentCandidateExecutorStopAcknowledgement,
5812
+ persistCandidateOutputArtifact,
5813
+ persistCandidateModelSettlementEvidence,
5814
+ RecoveryAgentCandidateTraceStore,
5815
+ executePreparedAgentCandidate,
5816
5816
  prepareAgentCandidateExecution
5817
5817
  };
5818
- //# sourceMappingURL=chunk-HGSHPVJ6.js.map
5818
+ //# sourceMappingURL=chunk-TGDHHHH4.js.map