@tangle-network/agent-runtime 0.92.0 → 0.93.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 (45) hide show
  1. package/README.md +14 -4
  2. package/dist/agent.js +47 -45
  3. package/dist/agent.js.map +1 -1
  4. package/dist/candidate-execution/index.d.ts +48 -4
  5. package/dist/candidate-execution/index.js +6 -2
  6. package/dist/{chunk-A62TP7SK.js → chunk-26WCEARH.js} +295 -40
  7. package/dist/chunk-26WCEARH.js.map +1 -0
  8. package/dist/{chunk-PH65PR4F.js → chunk-3VU2OWOY.js} +106 -2
  9. package/dist/chunk-3VU2OWOY.js.map +1 -0
  10. package/dist/{chunk-I7WVPJBZ.js → chunk-BVVRQ4YC.js} +4 -4
  11. package/dist/{chunk-3BE7KTMU.js → chunk-FDJ7AHXG.js} +2 -2
  12. package/dist/{chunk-APVPRF4Y.js → chunk-J2K6WIG6.js} +13 -7
  13. package/dist/{chunk-APVPRF4Y.js.map → chunk-J2K6WIG6.js.map} +1 -1
  14. package/dist/{chunk-7VJJJ2T2.js → chunk-LQQPGRKT.js} +2 -2
  15. package/dist/{chunk-IGGZGKJD.js → chunk-P6B3Z7PR.js} +3 -3
  16. package/dist/{chunk-GDAQUFG6.js → chunk-R5GWDTM3.js} +2 -2
  17. package/dist/{chunk-AUEIDTR3.js → chunk-TKJ3Q6CQ.js} +2 -2
  18. package/dist/{chunk-6O5USWVH.js → chunk-UO2L5VTP.js} +2 -2
  19. package/dist/{chunk-RSWM2ZKM.js → chunk-VMHKMNEU.js} +40 -11
  20. package/dist/chunk-VMHKMNEU.js.map +1 -0
  21. package/dist/{improve-CUVCq7xg.d.ts → improve-DDhQaaJT.d.ts} +17 -5
  22. package/dist/index.d.ts +3 -3
  23. package/dist/index.js +14 -10
  24. package/dist/index.js.map +1 -1
  25. package/dist/intelligence.d.ts +6 -8
  26. package/dist/intelligence.js +25 -134
  27. package/dist/intelligence.js.map +1 -1
  28. package/dist/knowledge.js +3 -3
  29. package/dist/loop-runner-bin.js +5 -5
  30. package/dist/loops.js +4 -4
  31. package/dist/mcp/bin.js +3 -3
  32. package/dist/mcp/index.js +6 -6
  33. package/dist/{prepare-Z08a4heC.d.ts → prepare-DiVGKcwS.d.ts} +7 -2
  34. package/package.json +33 -19
  35. package/skills/build-with-agent-runtime/SKILL.md +2 -1
  36. package/dist/chunk-A62TP7SK.js.map +0 -1
  37. package/dist/chunk-PH65PR4F.js.map +0 -1
  38. package/dist/chunk-RSWM2ZKM.js.map +0 -1
  39. /package/dist/{chunk-I7WVPJBZ.js.map → chunk-BVVRQ4YC.js.map} +0 -0
  40. /package/dist/{chunk-3BE7KTMU.js.map → chunk-FDJ7AHXG.js.map} +0 -0
  41. /package/dist/{chunk-7VJJJ2T2.js.map → chunk-LQQPGRKT.js.map} +0 -0
  42. /package/dist/{chunk-IGGZGKJD.js.map → chunk-P6B3Z7PR.js.map} +0 -0
  43. /package/dist/{chunk-GDAQUFG6.js.map → chunk-R5GWDTM3.js.map} +0 -0
  44. /package/dist/{chunk-AUEIDTR3.js.map → chunk-TKJ3Q6CQ.js.map} +0 -0
  45. /package/dist/{chunk-6O5USWVH.js.map → chunk-UO2L5VTP.js.map} +0 -0
@@ -2,39 +2,8 @@ import {
2
2
  contentAddress
3
3
  } from "./chunk-3D2RHC4K.js";
4
4
 
5
- // src/candidate-execution/types.ts
6
- var verifiedCandidateBrand = /* @__PURE__ */ Symbol("verifiedAgentCandidate");
7
- var preparedCandidateBrand = /* @__PURE__ */ Symbol("preparedAgentCandidate");
8
- var verifiedTaskOutcomeBrand = /* @__PURE__ */ Symbol("verifiedTaskOutcome");
9
- var CANDIDATE_TRACE_TAGS = {
10
- executionId: "tangle.candidate.execution_id",
11
- bundleDigest: "tangle.candidate.bundle_digest",
12
- executionPlanDigest: "tangle.candidate.execution_plan_digest",
13
- materializationReceiptDigest: "tangle.candidate.materialization_receipt_digest"
14
- };
15
- var CANDIDATE_TRACE_ENV = {
16
- executionId: "TANGLE_CANDIDATE_EXECUTION_ID",
17
- bundleDigest: "TANGLE_CANDIDATE_BUNDLE_DIGEST",
18
- executionPlanDigest: "TANGLE_CANDIDATE_EXECUTION_PLAN_DIGEST",
19
- materializationReceiptDigest: "TANGLE_CANDIDATE_MATERIALIZATION_RECEIPT_DIGEST",
20
- traceRunId: "TANGLE_TRACE_RUN_ID"
21
- };
22
-
23
- // src/candidate-execution/claim.ts
24
- import { createHash as createHash2, randomBytes, timingSafeEqual } from "crypto";
25
- import { readFile } from "fs/promises";
26
- import {
27
- agentCandidateResolvedModelSchema
28
- } from "@tangle-network/agent-interface";
29
-
30
- // src/candidate-execution/claim-file-formats.ts
31
- var CLAIM_FORMAT_VERSION = 7;
32
- var PENDING_FORMAT_VERSION = 1;
33
- var TERMINAL_FORMAT_VERSION = 3;
34
- var PHASE_FORMAT_VERSION = 1;
35
-
36
- // src/candidate-execution/claim-terminal.ts
37
- import { agentCandidateArtifactRefSchema } from "@tangle-network/agent-interface";
5
+ // src/candidate-execution/bundle.ts
6
+ import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
38
7
 
39
8
  // src/candidate-execution/digest.ts
40
9
  import { createHash } from "crypto";
@@ -92,6 +61,51 @@ function deepFreezeCandidate(value, seen = /* @__PURE__ */ new Set()) {
92
61
  return Object.freeze(value);
93
62
  }
94
63
 
64
+ // src/candidate-execution/bundle.ts
65
+ function sealAgentCandidateBundle(input) {
66
+ const digest = canonicalCandidateDigest(input);
67
+ const parsed = agentCandidateBundleSchema.parse({ ...input, digest });
68
+ const parsedDigest = canonicalCandidateDigest(omitTopLevelDigest(parsed));
69
+ if (parsedDigest !== digest) {
70
+ throw new Error("candidate bundle changed while validating its canonical wire shape");
71
+ }
72
+ return immutableCandidateValue(parsed);
73
+ }
74
+
75
+ // src/candidate-execution/types.ts
76
+ var verifiedCandidateBrand = /* @__PURE__ */ Symbol("verifiedAgentCandidate");
77
+ var preparedCandidateBrand = /* @__PURE__ */ Symbol("preparedAgentCandidate");
78
+ var verifiedTaskOutcomeBrand = /* @__PURE__ */ Symbol("verifiedTaskOutcome");
79
+ var CANDIDATE_TRACE_TAGS = {
80
+ executionId: "tangle.candidate.execution_id",
81
+ bundleDigest: "tangle.candidate.bundle_digest",
82
+ executionPlanDigest: "tangle.candidate.execution_plan_digest",
83
+ materializationReceiptDigest: "tangle.candidate.materialization_receipt_digest"
84
+ };
85
+ var CANDIDATE_TRACE_ENV = {
86
+ executionId: "TANGLE_CANDIDATE_EXECUTION_ID",
87
+ bundleDigest: "TANGLE_CANDIDATE_BUNDLE_DIGEST",
88
+ executionPlanDigest: "TANGLE_CANDIDATE_EXECUTION_PLAN_DIGEST",
89
+ materializationReceiptDigest: "TANGLE_CANDIDATE_MATERIALIZATION_RECEIPT_DIGEST",
90
+ traceRunId: "TANGLE_TRACE_RUN_ID"
91
+ };
92
+
93
+ // src/candidate-execution/claim.ts
94
+ import { createHash as createHash2, randomBytes, timingSafeEqual } from "crypto";
95
+ import { readFile } from "fs/promises";
96
+ import {
97
+ agentCandidateResolvedModelSchema
98
+ } from "@tangle-network/agent-interface";
99
+
100
+ // src/candidate-execution/claim-file-formats.ts
101
+ var CLAIM_FORMAT_VERSION = 7;
102
+ var PENDING_FORMAT_VERSION = 1;
103
+ var TERMINAL_FORMAT_VERSION = 3;
104
+ var PHASE_FORMAT_VERSION = 1;
105
+
106
+ // src/candidate-execution/claim-terminal.ts
107
+ import { agentCandidateArtifactRefSchema } from "@tangle-network/agent-interface";
108
+
95
109
  // src/candidate-execution/exact-object.ts
96
110
  function assertExactObjectKeys(value, required, label, optional = []) {
97
111
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
@@ -3898,10 +3912,10 @@ var CandidateExecutionDeadlineError = class extends Error {
3898
3912
  };
3899
3913
 
3900
3914
  // src/candidate-execution/verify.ts
3901
- import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
3915
+ import { agentCandidateBundleSchema as agentCandidateBundleSchema2 } from "@tangle-network/agent-interface";
3902
3916
  var verifiedCandidateState = /* @__PURE__ */ new WeakMap();
3903
3917
  async function verifyAgentCandidateBundle(input, ports) {
3904
- const parsed = agentCandidateBundleSchema.parse(input);
3918
+ const parsed = agentCandidateBundleSchema2.parse(input);
3905
3919
  const withoutDigest = omitTopLevelDigest(parsed);
3906
3920
  const actualDigest = canonicalCandidateDigest(withoutDigest);
3907
3921
  if (actualDigest !== parsed.digest) {
@@ -4739,16 +4753,257 @@ function errorMessage2(error) {
4739
4753
  return error instanceof Error ? error.message : String(error);
4740
4754
  }
4741
4755
 
4756
+ // src/candidate-execution/profile.ts
4757
+ import { agentCandidateProfileSchema, agentProfileSchema } from "@tangle-network/agent-interface";
4758
+ var CANDIDATE_PROFILE_DIRECT_FIELDS = [
4759
+ "name",
4760
+ "description",
4761
+ "version",
4762
+ "tags",
4763
+ "prompt",
4764
+ "harness",
4765
+ "permissions",
4766
+ "tools",
4767
+ "confidential"
4768
+ ];
4769
+ function freezeGenericAgentCandidateProfile(input) {
4770
+ const profile = parseExactAgentProfile(input, "profile");
4771
+ if (profile.connections !== void 0) unsupportedProfileField("connections");
4772
+ if (profile.metadata !== void 0) unsupportedProfileField("metadata");
4773
+ if (profile.extensions !== void 0) unsupportedProfileField("extensions");
4774
+ if (profile.model?.metadata !== void 0) unsupportedProfileField("model.metadata");
4775
+ const candidate = {};
4776
+ copyDirectProfileFields(candidate, profile);
4777
+ if (profile.model) {
4778
+ const { metadata: _metadata, ...model } = profile.model;
4779
+ candidate.model = model;
4780
+ }
4781
+ if (profile.mcp) candidate.mcp = freezeMcpServers(profile.mcp);
4782
+ if (profile.subagents) {
4783
+ candidate.subagents = Object.fromEntries(
4784
+ Object.entries(profile.subagents).map(([name, subagent]) => {
4785
+ if (subagent.metadata !== void 0) unsupportedProfileField(`subagents.${name}.metadata`);
4786
+ const { metadata: _metadata, ...value } = subagent;
4787
+ return [name, value];
4788
+ })
4789
+ );
4790
+ }
4791
+ if (profile.resources) candidate.resources = freezeResources(profile.resources);
4792
+ if (profile.hooks && Object.values(profile.hooks).some((commands) => commands.length > 0)) {
4793
+ throw new Error(
4794
+ "generic AgentProfile hooks cannot be safely tokenized; use a candidate-profile source with executable/args"
4795
+ );
4796
+ }
4797
+ if (profile.hooks) candidate.hooks = profile.hooks;
4798
+ if (profile.modes) {
4799
+ candidate.modes = Object.fromEntries(
4800
+ Object.entries(profile.modes).map(([name, mode]) => {
4801
+ if (mode.metadata !== void 0) unsupportedProfileField(`modes.${name}.metadata`);
4802
+ const { metadata: _metadata, ...value } = mode;
4803
+ return [name, value];
4804
+ })
4805
+ );
4806
+ }
4807
+ const parsed = parseExactCandidateProfile(candidate);
4808
+ assertCandidateProfileBinding(profile, parsed);
4809
+ return parsed;
4810
+ }
4811
+ function assertCandidateProfileBinding(measuredInput, bundled) {
4812
+ const measured = parseExactAgentProfile(measuredInput, "proposal candidate profile");
4813
+ if (measured.connections || measured.metadata || measured.extensions) {
4814
+ throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
4815
+ }
4816
+ const normalized = candidateProfileAsAgentProfile(bundled);
4817
+ if (canonicalCandidateDigest(measured) !== canonicalCandidateDigest(normalized)) {
4818
+ throw new Error("proposal candidateProfile does not match candidateBundle.profile");
4819
+ }
4820
+ }
4821
+ function parseExactAgentProfile(input, label) {
4822
+ const parsed = agentProfileSchema.parse(input);
4823
+ assertCanonicalParse(input, parsed, label);
4824
+ return parsed;
4825
+ }
4826
+ function parseExactCandidateProfile(input) {
4827
+ const parsed = agentCandidateProfileSchema.parse(input);
4828
+ assertCanonicalParse(input, parsed, "candidate profile");
4829
+ return parsed;
4830
+ }
4831
+ function candidateProfileAsAgentProfile(candidate) {
4832
+ const output = {};
4833
+ copyDirectProfileFields(output, candidate);
4834
+ if (candidate.model) output.model = { ...candidate.model };
4835
+ if (candidate.mcp) {
4836
+ output.mcp = Object.fromEntries(
4837
+ Object.entries(candidate.mcp).map(([name, server]) => [
4838
+ name,
4839
+ {
4840
+ ...server,
4841
+ ...server.args ? { args: server.args.map(publicValue) } : {},
4842
+ ...server.env ? { env: mapPublicValues(server.env) } : {}
4843
+ }
4844
+ ])
4845
+ );
4846
+ }
4847
+ if (candidate.subagents) output.subagents = cloneRecord(candidate.subagents);
4848
+ if (candidate.modes) output.modes = cloneRecord(candidate.modes);
4849
+ if (candidate.hooks) {
4850
+ output.hooks = Object.fromEntries(
4851
+ Object.entries(candidate.hooks).map(([event, hooks]) => [
4852
+ event,
4853
+ hooks.map(({ executable, args, env, ...hook }) => ({
4854
+ ...hook,
4855
+ command: [executable, ...(args ?? []).map(publicValue)].map(shellQuote).join(" "),
4856
+ ...env ? { env: mapPublicValues(env) } : {}
4857
+ }))
4858
+ ])
4859
+ );
4860
+ }
4861
+ if (candidate.resources) {
4862
+ if (candidate.resources.failOnError !== true) {
4863
+ throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
4864
+ }
4865
+ output.resources = {
4866
+ failOnError: true,
4867
+ ...candidate.resources.files ? {
4868
+ files: candidate.resources.files.map((file) => ({
4869
+ ...file,
4870
+ resource: publicResource(file.resource)
4871
+ }))
4872
+ } : {},
4873
+ ...candidate.resources.tools ? { tools: candidate.resources.tools.map(publicResource) } : {},
4874
+ ...candidate.resources.skills ? { skills: candidate.resources.skills.map(publicResource) } : {},
4875
+ ...candidate.resources.agents ? { agents: candidate.resources.agents.map(publicResource) } : {},
4876
+ ...candidate.resources.commands ? { commands: candidate.resources.commands.map(publicResource) } : {},
4877
+ ...candidate.resources.instructions !== void 0 ? {
4878
+ instructions: typeof candidate.resources.instructions === "string" ? candidate.resources.instructions : publicResource(candidate.resources.instructions)
4879
+ } : {}
4880
+ };
4881
+ }
4882
+ return output;
4883
+ }
4884
+ function freezeMcpServers(servers) {
4885
+ return Object.fromEntries(
4886
+ Object.entries(servers).map(([name, server]) => {
4887
+ if (server.transport !== void 0 && server.transport !== "stdio") {
4888
+ unsupportedProfileField(`mcp.${name}.transport=${server.transport}`);
4889
+ }
4890
+ if (server.url !== void 0) unsupportedProfileField(`mcp.${name}.url`);
4891
+ if (server.headers !== void 0) unsupportedProfileField(`mcp.${name}.headers`);
4892
+ if (server.metadata !== void 0) unsupportedProfileField(`mcp.${name}.metadata`);
4893
+ return [
4894
+ name,
4895
+ {
4896
+ ...server.transport ? { transport: server.transport } : {},
4897
+ ...server.command ? { command: server.command } : {},
4898
+ ...server.args ? { args: server.args.map(candidatePublicValue) } : {},
4899
+ ...server.env ? { env: mapCandidatePublicValues(server.env) } : {},
4900
+ ...server.cwd ? { cwd: server.cwd } : {},
4901
+ ...server.enabled === void 0 ? {} : { enabled: server.enabled }
4902
+ }
4903
+ ];
4904
+ })
4905
+ );
4906
+ }
4907
+ function freezeResources(resources) {
4908
+ if (resources.failOnError !== true) {
4909
+ throw new Error("candidate profile resources require failOnError: true");
4910
+ }
4911
+ return {
4912
+ failOnError: true,
4913
+ ...resources.files ? {
4914
+ files: resources.files.map((file) => ({
4915
+ ...file,
4916
+ resource: freezeResource(file.resource)
4917
+ }))
4918
+ } : {},
4919
+ ...resources.tools ? { tools: resources.tools.map(freezeResource) } : {},
4920
+ ...resources.skills ? { skills: resources.skills.map(freezeResource) } : {},
4921
+ ...resources.agents ? { agents: resources.agents.map(freezeResource) } : {},
4922
+ ...resources.commands ? { commands: resources.commands.map(freezeResource) } : {},
4923
+ ...resources.instructions === void 0 ? {} : {
4924
+ instructions: typeof resources.instructions === "string" ? resources.instructions : freezeResource(resources.instructions)
4925
+ }
4926
+ };
4927
+ }
4928
+ function freezeResource(resource) {
4929
+ if (resource.kind === "github") {
4930
+ throw new Error(
4931
+ "generic GitHub profile resources do not carry byte identity; use a candidate-profile source with a pinned commit, digest, and byte length"
4932
+ );
4933
+ }
4934
+ const bytes = Buffer.from(resource.content, "utf8");
4935
+ return {
4936
+ ...resource,
4937
+ sha256: embeddedCandidateArtifact(bytes).sha256,
4938
+ byteLength: bytes.byteLength
4939
+ };
4940
+ }
4941
+ function copyDirectProfileFields(target, source) {
4942
+ for (const key of CANDIDATE_PROFILE_DIRECT_FIELDS) {
4943
+ if (source[key] !== void 0) target[key] = source[key];
4944
+ }
4945
+ }
4946
+ function assertCanonicalParse(input, parsed, label) {
4947
+ if (!Buffer.from(canonicalCandidateBytes(input)).equals(canonicalCandidateBytes(parsed))) {
4948
+ throw new Error(`${label} contains unsupported or non-canonical fields`);
4949
+ }
4950
+ }
4951
+ function publicResource(resource) {
4952
+ if (resource.kind === "inline") {
4953
+ return { kind: "inline", name: resource.name, content: resource.content };
4954
+ }
4955
+ return {
4956
+ kind: "github",
4957
+ repository: `${resource.repository.owner}/${resource.repository.repo}`,
4958
+ path: resource.path,
4959
+ ref: resource.commit,
4960
+ ...resource.name ? { name: resource.name } : {}
4961
+ };
4962
+ }
4963
+ function candidatePublicValue(value) {
4964
+ return { kind: "public", value };
4965
+ }
4966
+ function mapCandidatePublicValues(values) {
4967
+ return Object.fromEntries(
4968
+ Object.entries(values).map(([name, value]) => [name, candidatePublicValue(value)])
4969
+ );
4970
+ }
4971
+ function publicValue(value) {
4972
+ return value.value;
4973
+ }
4974
+ function mapPublicValues(values) {
4975
+ return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, publicValue(value)]));
4976
+ }
4977
+ function cloneRecord(values) {
4978
+ return Object.fromEntries(
4979
+ Object.entries(values).map(([key, value]) => [key, { ...value }])
4980
+ );
4981
+ }
4982
+ function shellQuote(value) {
4983
+ return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
4984
+ }
4985
+ function unsupportedProfileField(path) {
4986
+ throw new Error(
4987
+ `generic AgentProfile field ${path} is not representable in a sealed candidate profile`
4988
+ );
4989
+ }
4990
+
4742
4991
  export {
4743
- CLAIM_FORMAT_VERSION,
4744
- PENDING_FORMAT_VERSION,
4745
- TERMINAL_FORMAT_VERSION,
4746
- PHASE_FORMAT_VERSION,
4747
4992
  canonicalCandidateBytes,
4748
4993
  canonicalCandidateDigest,
4749
4994
  immutableCandidateValue,
4750
4995
  canonicalCandidateDocument,
4996
+ embeddedCandidateArtifact,
4751
4997
  omitTopLevelDigest,
4998
+ sealAgentCandidateBundle,
4999
+ freezeGenericAgentCandidateProfile,
5000
+ assertCandidateProfileBinding,
5001
+ parseExactAgentProfile,
5002
+ parseExactCandidateProfile,
5003
+ CLAIM_FORMAT_VERSION,
5004
+ PENDING_FORMAT_VERSION,
5005
+ TERMINAL_FORMAT_VERSION,
5006
+ PHASE_FORMAT_VERSION,
4752
5007
  assertExactObjectKeys,
4753
5008
  terminalRecord,
4754
5009
  recoveredTerminalRecord,
@@ -4781,4 +5036,4 @@ export {
4781
5036
  verifyAgentCandidateBundle,
4782
5037
  prepareAgentCandidateExecution
4783
5038
  };
4784
- //# sourceMappingURL=chunk-A62TP7SK.js.map
5039
+ //# sourceMappingURL=chunk-26WCEARH.js.map