@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
@@ -1,11 +1,11 @@
1
- import { AgentCandidateBundle, AgentProfile, Sha256Digest, AgentProfileDiff, AgentProfileMcpServer } from '@tangle-network/agent-interface';
1
+ import { AgentProfile, AgentCandidateBundle, Sha256Digest, AgentProfileDiff, AgentProfileMcpServer } from '@tangle-network/agent-interface';
2
2
  import { g as LoopTraceEvent, b as RuntimeStreamEvent } from './types-B00NtbCs.js';
3
3
  import { b as ToolSpec, c as RuntimeTelemetryOptions } from './sanitize-C9go6tXj.js';
4
4
  import { AnalystFinding } from '@tangle-network/agent-eval/analyst';
5
5
  import { Scenario, SelfImproveResult } from '@tangle-network/agent-eval/contract';
6
6
  import { R as RunAnalystLoopOpts, a as RunAnalystLoopResult } from './types-BC3bZpH0.js';
7
- import { A as AgentCandidateTaskExecution, a as AgentCandidateExecutionPorts, P as PrepareAgentCandidateExecutionOptions, E as ExecutePreparedAgentCandidateOptions, b as AgentCandidateRunFinalization } from './prepare-Z08a4heC.js';
8
- import { I as ImproveSurface, a as ImproveOptions, b as ImproveResult } from './improve-CUVCq7xg.js';
7
+ import { A as AgentCandidateTaskExecution, a as AgentCandidateExecutionPorts, P as PrepareAgentCandidateExecutionOptions, E as ExecutePreparedAgentCandidateOptions, b as AgentCandidateRunFinalization, c as AgentCandidateBundleInput } from './prepare-DiVGKcwS.js';
8
+ import { I as ImproveSurface, a as ImproveOptions, b as ImproveResult } from './improve-DDhQaaJT.js';
9
9
  import '@tangle-network/agent-eval';
10
10
  import '@tangle-network/sandbox';
11
11
  import './local-harness-dcD5WTTr.js';
@@ -126,8 +126,6 @@ interface EffortOverridesCompiled {
126
126
  */
127
127
  declare function compileEffort(settings: EffortSettings): EffortOverridesCompiled;
128
128
 
129
- type AgentCandidateBundleInput = Omit<AgentCandidateBundle, 'digest'>;
130
-
131
129
  type AgentImprovementEvaluation<TScenario extends Scenario, TArtifact> = Pick<SelfImproveResult<TScenario, TArtifact>, 'baseline' | 'winner' | 'lift' | 'diff' | 'provenance' | 'gateDecision' | 'generationsExplored' | 'durationMs' | 'totalCostUsd' | 'insight' | 'power'>;
132
130
  interface AgentImprovementProposal<TScenario extends Scenario = Scenario, TArtifact = unknown> {
133
131
  schemaVersion: 1;
@@ -173,13 +171,13 @@ interface ProposeAgentImprovementOptions<TScenario extends Scenario, TArtifact>
173
171
  improvement: ImproveOptions<TScenario, TArtifact>;
174
172
  /**
175
173
  * Optional environment adapter that freezes an executable bundle after the
176
- * measured comparison recommends the candidate. Runtime validates and
177
- * computes the bundle digest; adapters never implement hashing themselves.
174
+ * measured comparison recommends the candidate. Return the sealed output of
175
+ * `buildAgentCandidateBundle` directly, or a low-level digest-free input.
178
176
  */
179
177
  buildCandidate?: (input: {
180
178
  analysis: RunAnalystLoopResult;
181
179
  improvement: ImproveResult<TScenario, TArtifact>;
182
- }) => AgentCandidateBundleInput | Promise<AgentCandidateBundleInput>;
180
+ }) => AgentCandidateBundleInput | AgentCandidateBundle | Promise<AgentCandidateBundleInput | AgentCandidateBundle>;
183
181
  now?: () => Date;
184
182
  }
185
183
  interface ProposeAgentImprovementResult<TScenario extends Scenario, TArtifact> {
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  improve
3
- } from "./chunk-RSWM2ZKM.js";
3
+ } from "./chunk-VMHKMNEU.js";
4
4
  import {
5
- canonicalCandidateBytes,
5
+ assertCandidateProfileBinding,
6
6
  canonicalCandidateDigest,
7
7
  canonicalCandidateDocument,
8
8
  executePreparedAgentCandidate,
9
9
  immutableCandidateValue,
10
10
  omitTopLevelDigest,
11
+ parseExactAgentProfile,
11
12
  prepareAgentCandidateExecution,
13
+ sealAgentCandidateBundle,
12
14
  verifyAgentCandidateBundle
13
- } from "./chunk-A62TP7SK.js";
14
- import "./chunk-3BE7KTMU.js";
15
+ } from "./chunk-26WCEARH.js";
16
+ import "./chunk-FDJ7AHXG.js";
15
17
  import {
16
18
  runAnalystLoop
17
19
  } from "./chunk-ZQZX77MM.js";
@@ -21,7 +23,7 @@ import {
21
23
  buildRuntimeEventOtelSpans,
22
24
  createOtelExporter,
23
25
  flatOtelSpan
24
- } from "./chunk-APVPRF4Y.js";
26
+ } from "./chunk-J2K6WIG6.js";
25
27
  import "./chunk-3D2RHC4K.js";
26
28
  import "./chunk-3MDZX7YU.js";
27
29
  import "./chunk-FVJ7M3DA.js";
@@ -414,24 +416,13 @@ function isJsonSchema(v) {
414
416
 
415
417
  // src/intelligence/improvement-cycle.ts
416
418
  import { assertNoJudgeVerdict } from "@tangle-network/agent-eval/analyst";
417
- import { agentCandidateBundleSchema as agentCandidateBundleSchema2, agentProfileSchema } from "@tangle-network/agent-interface";
418
-
419
- // src/candidate-execution/bundle.ts
420
419
  import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
421
- function sealAgentCandidateBundle(input) {
422
- const digest = canonicalCandidateDigest(input);
423
- const parsed = agentCandidateBundleSchema.parse({ ...input, digest });
424
- const parsedDigest = canonicalCandidateDigest(omitTopLevelDigest(parsed));
425
- if (parsedDigest !== digest) {
426
- throw new Error("candidate bundle changed while validating its canonical wire shape");
427
- }
428
- return immutableCandidateValue(parsed);
429
- }
430
-
431
- // src/intelligence/improvement-cycle.ts
432
420
  async function proposeAgentImprovement(options) {
433
- if (options.improvement.skills?.writeBack) {
434
- throw new Error("proposeAgentImprovement cannot write a skill before human approval");
421
+ const writeBackSurface = options.improvement.skills?.writeBack ? "skill" : options.improvement.memory?.writeBack ? "memory" : null;
422
+ if (writeBackSurface) {
423
+ throw new Error(
424
+ `proposeAgentImprovement cannot write ${writeBackSurface} before human approval`
425
+ );
435
426
  }
436
427
  const analysis = await runAnalystLoop({
437
428
  ...options.analysis,
@@ -442,7 +433,7 @@ async function proposeAgentImprovement(options) {
442
433
  "proposeAgentImprovement findings"
443
434
  );
444
435
  const improvement = await improve(options.profile, [...findings], options.improvement);
445
- const candidateBundle = improvement.shipped && options.buildCandidate ? sealAgentCandidateBundle(await options.buildCandidate({ analysis, improvement })) : void 0;
436
+ const candidateBundle = improvement.shipped && options.buildCandidate ? sealBuiltCandidate(await options.buildCandidate({ analysis, improvement })) : void 0;
446
437
  if (candidateBundle) assertCandidateProfileBinding(improvement.profile, candidateBundle.profile);
447
438
  const surface = options.improvement.surface ?? "prompt";
448
439
  const evaluation = canonicalJsonValue(improvementEvaluation(improvement.raw));
@@ -530,14 +521,17 @@ function verifyAgentImprovementProposal(input) {
530
521
  throw new Error("invalid agent improvement proposal");
531
522
  }
532
523
  const proposal = input;
533
- const parsedProfile = parseExactAgentProfile(proposal.candidateProfile);
524
+ const parsedProfile = parseExactAgentProfile(
525
+ proposal.candidateProfile,
526
+ "proposal candidate profile"
527
+ );
534
528
  if (proposal.candidateProfileHash !== canonicalCandidateDigest(parsedProfile)) {
535
529
  throw new Error("proposal candidateProfileHash does not match candidateProfile");
536
530
  }
537
531
  if (!Array.isArray(proposal.findings)) throw new Error("proposal findings must be an array");
538
532
  if (!isSha256Digest(proposal.digest)) throw new Error("proposal digest is invalid");
539
533
  if (proposal.candidateBundle) {
540
- const parsedBundle = agentCandidateBundleSchema2.parse(proposal.candidateBundle);
534
+ const parsedBundle = agentCandidateBundleSchema.parse(proposal.candidateBundle);
541
535
  const sealed = sealAgentCandidateBundle(omitTopLevelDigest(parsedBundle));
542
536
  if (sealed.digest !== parsedBundle.digest)
543
537
  throw new Error("proposal candidate bundle digest is invalid");
@@ -548,116 +542,14 @@ function verifyAgentImprovementProposal(input) {
548
542
  throw new Error("agent improvement proposal digest does not match");
549
543
  return immutableCandidateValue(proposal);
550
544
  }
551
- function parseExactAgentProfile(input) {
552
- const parsed = agentProfileSchema.parse(input);
553
- if (!Buffer.from(canonicalCandidateBytes(input)).equals(
554
- Buffer.from(canonicalCandidateBytes(parsed))
555
- )) {
556
- throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
557
- }
558
- return parsed;
559
- }
560
- function assertCandidateProfileBinding(measuredInput, bundled) {
561
- const measured = parseExactAgentProfile(measuredInput);
562
- if (measured.connections || measured.metadata || measured.extensions) {
563
- throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
564
- }
565
- const normalized = candidateProfileAsAgentProfile(bundled);
566
- if (canonicalCandidateDigest(measured) !== canonicalCandidateDigest(normalized)) {
567
- throw new Error("proposal candidateProfile does not match candidateBundle.profile");
568
- }
569
- }
570
- function candidateProfileAsAgentProfile(candidate) {
571
- const value = candidate;
572
- const output = {};
573
- for (const key of [
574
- "name",
575
- "description",
576
- "version",
577
- "tags",
578
- "prompt",
579
- "harness",
580
- "permissions",
581
- "tools",
582
- "confidential"
583
- ]) {
584
- if (value[key] !== void 0) output[key] = value[key];
585
- }
586
- if (candidate.model) output.model = { ...candidate.model };
587
- if (candidate.mcp) {
588
- output.mcp = Object.fromEntries(
589
- Object.entries(candidate.mcp).map(([name, server]) => [
590
- name,
591
- {
592
- ...server,
593
- ...server.args ? { args: server.args.map(publicValue) } : {},
594
- ...server.env ? { env: mapPublicValues(server.env) } : {}
595
- }
596
- ])
597
- );
598
- }
599
- if (candidate.subagents) output.subagents = mapRecord(candidate.subagents);
600
- if (candidate.modes) output.modes = mapRecord(candidate.modes);
601
- if (candidate.hooks) {
602
- output.hooks = Object.fromEntries(
603
- Object.entries(candidate.hooks).map(([event, hooks]) => [
604
- event,
605
- hooks.map((hook) => ({
606
- ...hook,
607
- command: [hook.executable, ...(hook.args ?? []).map(publicValue)].map(shellQuote).join(" "),
608
- ...hook.env ? { env: mapPublicValues(hook.env) } : {}
609
- }))
610
- ])
611
- );
612
- }
613
- if (candidate.resources) {
614
- if (candidate.resources.failOnError !== true) {
615
- throw new Error("proposal candidate profile contains fields unsupported by sealed candidates");
616
- }
617
- output.resources = {
618
- failOnError: true,
619
- ...candidate.resources.files ? {
620
- files: candidate.resources.files.map((file) => ({
621
- ...file,
622
- resource: publicResource(file.resource)
623
- }))
624
- } : {},
625
- ...candidate.resources.tools ? { tools: candidate.resources.tools.map(publicResource) } : {},
626
- ...candidate.resources.skills ? { skills: candidate.resources.skills.map(publicResource) } : {},
627
- ...candidate.resources.agents ? { agents: candidate.resources.agents.map(publicResource) } : {},
628
- ...candidate.resources.commands ? { commands: candidate.resources.commands.map(publicResource) } : {},
629
- ...candidate.resources.instructions !== void 0 ? {
630
- instructions: typeof candidate.resources.instructions === "string" ? candidate.resources.instructions : publicResource(candidate.resources.instructions)
631
- } : {}
632
- };
633
- }
634
- return output;
635
- }
636
- function publicResource(resource) {
637
- if (resource.kind === "inline") {
638
- return { kind: "inline", name: resource.name, content: resource.content };
545
+ function sealBuiltCandidate(input) {
546
+ if (!("digest" in input)) return sealAgentCandidateBundle(input);
547
+ const parsed = agentCandidateBundleSchema.parse(input);
548
+ const sealed = sealAgentCandidateBundle(omitTopLevelDigest(parsed));
549
+ if (sealed.digest !== parsed.digest) {
550
+ throw new Error("built candidate bundle digest is invalid");
639
551
  }
640
- return {
641
- kind: "github",
642
- repository: `${resource.repository.owner}/${resource.repository.repo}`,
643
- path: resource.path,
644
- ref: resource.commit,
645
- ...resource.name ? { name: resource.name } : {}
646
- };
647
- }
648
- function publicValue(value) {
649
- return value.value;
650
- }
651
- function mapPublicValues(values) {
652
- return Object.fromEntries(Object.entries(values).map(([key, value]) => [key, publicValue(value)]));
653
- }
654
- function mapRecord(values) {
655
- return Object.fromEntries(
656
- Object.entries(values).map(([key, value]) => [key, { ...value }])
657
- );
658
- }
659
- function shellQuote(value) {
660
- return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
552
+ return sealed;
661
553
  }
662
554
  function verifyAgentImprovementReview(input) {
663
555
  if (!isRecord(input) || input.kind !== "agent-improvement-review" || input.schemaVersion !== 1) {
@@ -1383,7 +1275,6 @@ function createIntelligenceClient(config) {
1383
1275
  redactor(record.profile),
1384
1276
  includeFullPayload
1385
1277
  );
1386
- labels["tangle.agent.profile_hash"] = contentHash(record.profile);
1387
1278
  if (record.profile.name) labels["gen_ai.agent.name"] = record.profile.name;
1388
1279
  }
1389
1280
  const redactedInput = record.input !== void 0 ? redactor(record.input) : void 0;