@tangle-network/agent-runtime 0.97.0 → 0.99.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.
@@ -6,6 +6,12 @@ interface CreateAgentImprovementActivationResultOptions {
6
6
  }
7
7
  interface AgentImprovementActivationTargetPlan extends AgentImprovementActivationTarget {
8
8
  desiredDigest: Sha256Digest;
9
+ /**
10
+ * Exact measured input the product must apply to reach `desiredDigest`.
11
+ * Transition surfaces such as code and knowledge are applied operations, so
12
+ * their resulting state digest is not the digest of this input document.
13
+ */
14
+ desiredInput: unknown;
9
15
  }
10
16
  interface AgentImprovementActivationTransitionInput {
11
17
  activation: AgentImprovementActivation;
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-BLQIYRVR.js";
8
8
  import {
9
9
  createAgentImprovementActivationResult
10
- } from "./chunk-PSOCBNM3.js";
10
+ } from "./chunk-JSPW2Y3P.js";
11
11
  import {
12
12
  canonicalCandidateBytes,
13
13
  embeddedCandidateArtifact,
@@ -471,4 +471,4 @@ export {
471
471
  runKnowledgeImprovementJob,
472
472
  buildKnowledgeImprovementExperimentBundles
473
473
  };
474
- //# sourceMappingURL=chunk-3XKSBI2U.js.map
474
+ //# sourceMappingURL=chunk-6WSFXKQU.js.map
@@ -1340,6 +1340,11 @@ async function improve(profile, findings, opts) {
1340
1340
  }
1341
1341
 
1342
1342
  // src/intelligence/improvement-surfaces.ts
1343
+ import {
1344
+ agentProfileDiffSchema,
1345
+ agentProfileSchema as agentProfileSchema2,
1346
+ defineAgentProfileDiff
1347
+ } from "@tangle-network/agent-interface";
1343
1348
  var changedSurfaceOrder = [
1344
1349
  "prompt",
1345
1350
  "skills",
@@ -1352,6 +1357,14 @@ var changedSurfaceOrder = [
1352
1357
  "code",
1353
1358
  "knowledge"
1354
1359
  ];
1360
+ var AGENT_IMPROVEMENT_PROFILE_SURFACES = [
1361
+ "prompt",
1362
+ "skills",
1363
+ "tools",
1364
+ "mcp",
1365
+ "hooks",
1366
+ "subagents"
1367
+ ];
1355
1368
  function deriveChangedSurfaces(baselineBundle, candidateBundle) {
1356
1369
  if (baselineBundle.knowledge || candidateBundle.knowledge) {
1357
1370
  assertKnowledgeCandidatePair(baselineBundle, candidateBundle);
@@ -1392,6 +1405,116 @@ function agentImprovementTargetDigest(experiment, arm, surface) {
1392
1405
  if (surface === "code") assertCodeCandidatePair(experiment.baseline, experiment.candidate);
1393
1406
  return canonicalCandidateDigest(improvementSurfaceValues(experiment[arm])[surface]);
1394
1407
  }
1408
+ function agentImprovementTargetInput(bundle, surface) {
1409
+ return improvementSurfaceValues(bundle)[surface];
1410
+ }
1411
+ function isAgentImprovementProfileSurface(surface) {
1412
+ return AGENT_IMPROVEMENT_PROFILE_SURFACES.includes(surface);
1413
+ }
1414
+ function agentImprovementTargetProfileDiffs(target, options) {
1415
+ const { remove, set } = improvementSurfaceReplacement(target);
1416
+ const common = {
1417
+ kind: "agent-profile-diff",
1418
+ ...options.source ? { source: options.source } : {},
1419
+ metadata: {
1420
+ ...options.metadata ?? {},
1421
+ surface: target.surface
1422
+ }
1423
+ };
1424
+ const reset = agentProfileDiffSchema.parse(
1425
+ defineAgentProfileDiff({
1426
+ ...common,
1427
+ id: `${options.id}:${target.surface}:reset`,
1428
+ title: `Replace active ${target.surface}`,
1429
+ remove
1430
+ })
1431
+ );
1432
+ if (!set) return [reset];
1433
+ const replacement = agentProfileDiffSchema.parse(
1434
+ defineAgentProfileDiff({
1435
+ ...common,
1436
+ id: `${options.id}:${target.surface}:set`,
1437
+ title: `Activate measured ${target.surface}`,
1438
+ set
1439
+ })
1440
+ );
1441
+ return [reset, replacement];
1442
+ }
1443
+ function improvementSurfaceReplacement(target) {
1444
+ const value = target.desiredInput;
1445
+ switch (target.surface) {
1446
+ case "prompt": {
1447
+ const prompt = exactObject(value, ["prompt"], "prompt activation input").prompt;
1448
+ assertDefined(prompt, "prompt activation input.prompt");
1449
+ return {
1450
+ remove: { prompt: true },
1451
+ ...prompt === null ? {} : { set: parseProfileSet({ prompt }) }
1452
+ };
1453
+ }
1454
+ case "skills":
1455
+ assertDefined(value, "skills activation input");
1456
+ return {
1457
+ remove: { resources: { skills: true } },
1458
+ ...value === null ? {} : { set: parseProfileSet({ resources: { skills: value } }) }
1459
+ };
1460
+ case "tools": {
1461
+ const parsed = exactObject(value, ["tools", "resources"], "tools activation input");
1462
+ assertDefined(parsed.tools, "tools activation input.tools");
1463
+ assertDefined(parsed.resources, "tools activation input.resources");
1464
+ const set = {
1465
+ ...parsed.tools === null ? {} : { tools: parsed.tools },
1466
+ ...parsed.resources === null ? {} : { resources: { tools: parsed.resources } }
1467
+ };
1468
+ return {
1469
+ remove: { tools: true, resources: { tools: true } },
1470
+ ...Object.keys(set).length === 0 ? {} : { set: parseProfileSet(set) }
1471
+ };
1472
+ }
1473
+ case "mcp":
1474
+ assertDefined(value, "mcp activation input");
1475
+ return {
1476
+ remove: { mcp: true },
1477
+ ...value === null ? {} : { set: parseProfileSet({ mcp: value }) }
1478
+ };
1479
+ case "hooks":
1480
+ assertDefined(value, "hooks activation input");
1481
+ return {
1482
+ remove: { hooks: true },
1483
+ ...value === null ? {} : { set: parseProfileSet({ hooks: value }) }
1484
+ };
1485
+ case "subagents": {
1486
+ const parsed = exactObject(value, ["subagents", "resources"], "subagents activation input");
1487
+ assertDefined(parsed.subagents, "subagents activation input.subagents");
1488
+ assertDefined(parsed.resources, "subagents activation input.resources");
1489
+ const set = {
1490
+ ...parsed.subagents === null ? {} : { subagents: parsed.subagents },
1491
+ ...parsed.resources === null ? {} : { resources: { agents: parsed.resources } }
1492
+ };
1493
+ return {
1494
+ remove: { subagents: true, resources: { agents: true } },
1495
+ ...Object.keys(set).length === 0 ? {} : { set: parseProfileSet(set) }
1496
+ };
1497
+ }
1498
+ }
1499
+ }
1500
+ function assertDefined(value, label) {
1501
+ if (value === void 0) throw new Error(`${label} must not be undefined`);
1502
+ }
1503
+ function exactObject(value, keys, label) {
1504
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1505
+ throw new Error(`${label} must be an object`);
1506
+ }
1507
+ const record = value;
1508
+ const actual = Object.keys(record).sort();
1509
+ const expected = [...keys].sort();
1510
+ if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
1511
+ throw new Error(`${label} must contain exactly: ${expected.join(", ")}`);
1512
+ }
1513
+ return record;
1514
+ }
1515
+ function parseProfileSet(value) {
1516
+ return agentProfileSchema2.parse(value);
1517
+ }
1395
1518
  function assertKnowledgeCandidatePair(baselineBundle, candidateBundle) {
1396
1519
  const baseline = baselineBundle.knowledge;
1397
1520
  const candidate = candidateBundle.knowledge;
@@ -1917,7 +2040,8 @@ async function executeAgentImprovementActivation(input, options) {
1917
2040
  bundle: experiment[targetArm],
1918
2041
  targets: activation.targets.map((target) => ({
1919
2042
  ...target,
1920
- desiredDigest: agentImprovementTargetDigest(experiment, targetArm, target.surface)
2043
+ desiredDigest: agentImprovementTargetDigest(experiment, targetArm, target.surface),
2044
+ desiredInput: agentImprovementTargetInput(experiment[targetArm], target.surface)
1921
2045
  })),
1922
2046
  attemptedAt,
1923
2047
  expired: Date.parse(attemptedAt) >= Date.parse(activation.expiresAt)
@@ -1969,9 +2093,12 @@ function uncertainActivationResult(transition, code) {
1969
2093
  function assertTransitionInput(activation, transition) {
1970
2094
  const authorized = targetMap(activation.targets);
1971
2095
  const planned = targetMap(transition.targets);
2096
+ const desiredInputsMatch = transition.targets.every(
2097
+ (target) => canonicalCandidateDigest(target.desiredInput) === canonicalCandidateDigest(agentImprovementTargetInput(transition.bundle, target.surface))
2098
+ );
1972
2099
  if (authorized.size !== planned.size || [...authorized.entries()].some(
1973
2100
  ([identity, target]) => planned.get(identity)?.expectedBaseDigest !== target.expectedBaseDigest
1974
- ) || transition.expired !== Date.parse(transition.attemptedAt) >= Date.parse(activation.expiresAt) || transition.candidateBundle.digest !== activation.candidateBundleDigest || activation.intent === "activate-candidate" && transition.bundle.digest !== transition.candidateBundle.digest) {
2101
+ ) || transition.expired !== Date.parse(transition.attemptedAt) >= Date.parse(activation.expiresAt) || transition.candidateBundle.digest !== activation.candidateBundleDigest || !desiredInputsMatch || activation.intent === "activate-candidate" && transition.bundle.digest !== transition.candidateBundle.digest) {
1975
2102
  throw new Error("activation transition does not match its authorization");
1976
2103
  }
1977
2104
  }
@@ -2049,7 +2176,10 @@ export {
2049
2176
  improvementDriver,
2050
2177
  rawTraceDistiller,
2051
2178
  improve,
2179
+ AGENT_IMPROVEMENT_PROFILE_SURFACES,
2052
2180
  buildAgentImprovementActivationTargets,
2181
+ isAgentImprovementProfileSurface,
2182
+ agentImprovementTargetProfileDiffs,
2053
2183
  AgentCandidateExperimentCellExecutionError,
2054
2184
  runAgentCandidateExperiment,
2055
2185
  executeAgentCandidateExperimentCell,
@@ -2066,4 +2196,4 @@ export {
2066
2196
  verifyAgentImprovementActivationResult,
2067
2197
  executeAgentImprovementActivation
2068
2198
  };
2069
- //# sourceMappingURL=chunk-PSOCBNM3.js.map
2199
+ //# sourceMappingURL=chunk-JSPW2Y3P.js.map