@tangle-network/agent-runtime 0.337.2 → 0.338.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 (112) hide show
  1. package/dist/{activation-DRHM55Oo.d.ts → activation-CsbNax2X.d.ts} +92 -4
  2. package/dist/activation-kbkAuSmY.js +889 -0
  3. package/dist/activation-kbkAuSmY.js.map +1 -0
  4. package/dist/agent.d.ts +1 -1
  5. package/dist/agent.js +3 -6
  6. package/dist/agent.js.map +1 -1
  7. package/dist/{bundle-BPGjESee.js → bundle-DM60AI2B.js} +2 -2
  8. package/dist/{bundle-BPGjESee.js.map → bundle-DM60AI2B.js.map} +1 -1
  9. package/dist/candidate-execution/index.d.ts +2 -2
  10. package/dist/candidate-execution/index.js +4 -5
  11. package/dist/candidate-execution/index.js.map +1 -1
  12. package/dist/content-digest-sBTLujlK.js +9 -0
  13. package/dist/content-digest-sBTLujlK.js.map +1 -0
  14. package/dist/{delegate-B-T_ZB50.js → delegate-Se1YZKMb.js} +2 -2
  15. package/dist/{delegate-B-T_ZB50.js.map → delegate-Se1YZKMb.js.map} +1 -1
  16. package/dist/{coordination-driver-BHkFVqIq.js → driver-control-acknowledgers-T2a1Ouay.js} +4514 -4440
  17. package/dist/driver-control-acknowledgers-T2a1Ouay.js.map +1 -0
  18. package/dist/durable.d.ts +1 -1
  19. package/dist/durable.js +223 -227
  20. package/dist/durable.js.map +1 -1
  21. package/dist/{graph-C4RFlWAJ.js → graph-CY0wH838.js} +65 -18
  22. package/dist/graph-CY0wH838.js.map +1 -0
  23. package/dist/{graph-registry-DAI6KNXB.js → graph-registry-By0tUj4S.js} +16 -15
  24. package/dist/graph-registry-By0tUj4S.js.map +1 -0
  25. package/dist/{improvement-cycle-D1I4hQvf.js → improve-CWGBT13K.js} +75 -1220
  26. package/dist/improve-CWGBT13K.js.map +1 -0
  27. package/dist/index.d.ts +6 -6
  28. package/dist/index.js +10 -13
  29. package/dist/index.js.map +1 -1
  30. package/dist/{integrations-DopfCC2a.d.ts → integrations-6xttbPi9.d.ts} +3 -3
  31. package/dist/integrations-dFi-ALk7.js.map +1 -1
  32. package/dist/intelligence.d.ts +7 -94
  33. package/dist/intelligence.js +505 -13
  34. package/dist/intelligence.js.map +1 -1
  35. package/dist/kernel.d.ts +2 -2
  36. package/dist/kernel.js +13 -12
  37. package/dist/{loop-runner-bin-DOuBIJ2O.d.ts → loop-runner-bin-CFnrAHpl.d.ts} +2 -2
  38. package/dist/{loop-runner-bin-Dv5QvYDH.js → loop-runner-bin-CdPlhy9g.js} +3 -3
  39. package/dist/{loop-runner-bin-Dv5QvYDH.js.map → loop-runner-bin-CdPlhy9g.js.map} +1 -1
  40. package/dist/loop-runner-bin.d.ts +1 -1
  41. package/dist/loop-runner-bin.js +1 -1
  42. package/dist/mcp/bin.js +3 -3
  43. package/dist/mcp/bin.js.map +1 -1
  44. package/dist/mcp/index.d.ts +7 -3
  45. package/dist/mcp/index.js +6 -8
  46. package/dist/mcp/index.js.map +1 -1
  47. package/dist/{openai-tools-Oxk4KQrY.d.ts → openai-tools-zh2I_uD7.d.ts} +2 -2
  48. package/dist/platform.d.ts +7 -2
  49. package/dist/platform.js +16 -8
  50. package/dist/platform.js.map +1 -1
  51. package/dist/{prepare-CER-ZkPp.js → prepare-Bt0IouPq.js} +1241 -586
  52. package/dist/prepare-Bt0IouPq.js.map +1 -0
  53. package/dist/{profile-gNUsHNIJ.js → profile-Do-5xO_D.js} +89 -3
  54. package/dist/profile-Do-5xO_D.js.map +1 -0
  55. package/dist/profiles.d.ts +1 -1
  56. package/dist/profiles.js +1 -3
  57. package/dist/profiles.js.map +1 -1
  58. package/dist/{protected-model-port-BhpQRTw-.d.ts → protected-model-port-DGxQ8_YM.d.ts} +3 -3
  59. package/dist/{provision-supervisor-DGegCUH4.js → provision-supervisor-0jMufp4h.js} +12 -9
  60. package/dist/provision-supervisor-0jMufp4h.js.map +1 -0
  61. package/dist/record-value-B6bwJxLa.js +12 -0
  62. package/dist/record-value-B6bwJxLa.js.map +1 -0
  63. package/dist/{run-layout-Cu8H7aeh.js → run-cancellation-BoW5Sg9Y.js} +174 -95
  64. package/dist/run-cancellation-BoW5Sg9Y.js.map +1 -0
  65. package/dist/{runtime-BOGpotnH.js → runtime-D37zRSs7.js} +431 -621
  66. package/dist/runtime-D37zRSs7.js.map +1 -0
  67. package/dist/{sandbox-profile-compat-QTkLe1Z6.js → sandbox-profile-compat-xSoVtdWw.js} +690 -697
  68. package/dist/sandbox-profile-compat-xSoVtdWw.js.map +1 -0
  69. package/dist/search-executor-DmgUm5p7.js +1916 -0
  70. package/dist/search-executor-DmgUm5p7.js.map +1 -0
  71. package/dist/{server-hZWM-G8w.js → server-DQHJszfk.js} +4 -4
  72. package/dist/server-DQHJszfk.js.map +1 -0
  73. package/dist/{search-executor-Cm1WZmL-.js → structural-rollout-DAvIE8mw.js} +2261 -3984
  74. package/dist/structural-rollout-DAvIE8mw.js.map +1 -0
  75. package/dist/{supervise-CvAKVfue.js → supervise-WuPAwfPh.js} +7793 -5338
  76. package/dist/supervise-WuPAwfPh.js.map +1 -0
  77. package/dist/{supervisor-Rz8AGpYb.js → supervisor-CPG1I9UN.js} +26590 -27196
  78. package/dist/supervisor-CPG1I9UN.js.map +1 -0
  79. package/dist/testing.d.ts +226 -1
  80. package/dist/testing.js +13 -14
  81. package/dist/testing.js.map +1 -1
  82. package/dist/{top-app-BaMw1W2z.js → top-app-C55Wa7uy.js} +339 -337
  83. package/dist/top-app-C55Wa7uy.js.map +1 -0
  84. package/dist/tui/bin.js +1 -1
  85. package/dist/tui/index.d.ts +17 -15
  86. package/dist/tui/index.js +2 -2
  87. package/dist/{types-Dl5L4r8Z.d.ts → types-CrNWif8-.d.ts} +17410 -17173
  88. package/dist/{workspace-streams-JLjh5DC6.d.ts → workspace-streams-BZZds1Fw.d.ts} +18 -16
  89. package/package.json +2 -2
  90. package/skills/agent-graphs/SKILL.md +10 -3
  91. package/skills/agent-graphs/references/authoring.md +17 -0
  92. package/skills/profile-authoring/SKILL.md +3 -3
  93. package/skills/supervise/SKILL.md +2 -2
  94. package/dist/activation-BDP6Eivv.js +0 -234
  95. package/dist/activation-BDP6Eivv.js.map +0 -1
  96. package/dist/coordination-driver-BHkFVqIq.js.map +0 -1
  97. package/dist/graph-C4RFlWAJ.js.map +0 -1
  98. package/dist/graph-registry-DAI6KNXB.js.map +0 -1
  99. package/dist/improvement-cycle-D1I4hQvf.js.map +0 -1
  100. package/dist/prepare-CER-ZkPp.js.map +0 -1
  101. package/dist/profile-gNUsHNIJ.js.map +0 -1
  102. package/dist/protected-model-port-BuRsviSL.js +0 -766
  103. package/dist/protected-model-port-BuRsviSL.js.map +0 -1
  104. package/dist/provision-supervisor-DGegCUH4.js.map +0 -1
  105. package/dist/run-layout-Cu8H7aeh.js.map +0 -1
  106. package/dist/runtime-BOGpotnH.js.map +0 -1
  107. package/dist/sandbox-profile-compat-QTkLe1Z6.js.map +0 -1
  108. package/dist/search-executor-Cm1WZmL-.js.map +0 -1
  109. package/dist/server-hZWM-G8w.js.map +0 -1
  110. package/dist/supervise-CvAKVfue.js.map +0 -1
  111. package/dist/supervisor-Rz8AGpYb.js.map +0 -1
  112. package/dist/top-app-BaMw1W2z.js.map +0 -1
package/dist/durable.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $d as assertPursuitVersions, Cf as ObserverRecord, Ef as verifyObserverRecords, Gd as NextPursuitVersion, Jd as PursuitVersionStop, Kd as NextPursuitVersionInput, Qd as VersionVerdict, Sf as ObserverJournal, Tf as observerRecordDigest, Wd as JudgedPursuitVersion, Xd as SettledPursuitVersion, Yd as PursuitVersions, Z as ExecutorProgressEvent, Zd as VersionJudge, _f as PursuitRunProjection, af as supervisePursuit, bf as projectPursuit, cf as PursuitObserverDelivery, df as PursuitNodePlacement, dt as NodeId, ef as SuperviseGraphPursuitOptions, ff as PursuitNodePlatform, gf as PursuitProjection, hf as PursuitNodeUsage, if as superviseGraphPursuit, jt as RootStreamReceipt, lf as PursuitCostProvenance, mf as PursuitNodeTiming, nf as SupervisePursuitOptions, of as PursuitFork, pf as PursuitNodeProjection, qd as PursuitVersionChain, qt as SupervisedResult, rf as SupervisedPursuitResult, sf as RUN_FORK_CORRELATION_KEYS, tf as SupervisePursuitError, uf as PursuitNodeCost, vf as PursuitRunTotals, wf as ObserverRecordKind, xf as FileObserverJournal, yf as PursuitStatus } from "./types-Dl5L4r8Z.js";
1
+ import { $u as PursuitNodeCost, Bu as VersionJudge, Fu as NextPursuitVersionInput, Gu as SupervisePursuitOptions, Hu as assertPursuitVersions, Iu as PursuitVersionChain, Ju as supervisePursuit, Ku as SupervisedPursuitResult, Lu as PursuitVersionStop, Nu as JudgedPursuitVersion, Pu as NextPursuitVersion, Qu as PursuitCostProvenance, Ru as PursuitVersions, Uu as SuperviseGraphPursuitOptions, Vu as VersionVerdict, W as NodeId, Wu as SupervisePursuitError, Xu as RUN_FORK_CORRELATION_KEYS, Yu as PursuitFork, Zu as PursuitObserverDelivery, ad as PursuitProjection, cd as PursuitStatus, dd as ObserverJournal, ed as PursuitNodePlacement, fd as ObserverRecord, hd as verifyObserverRecords, id as PursuitNodeUsage, ld as projectPursuit, md as observerRecordDigest, nd as PursuitNodeProjection, od as PursuitRunProjection, ot as RootStreamReceipt, pT as ExecutorProgressEvent, pd as ObserverRecordKind, qu as superviseGraphPursuit, rd as PursuitNodeTiming, sd as PursuitRunTotals, st as SupervisedResult, td as PursuitNodePlatform, ud as FileObserverJournal, zu as SettledPursuitVersion } from "./types-CrNWif8-.js";
2
2
  //#region src/runtime/supervise/root-stream.d.ts
3
3
  /** The root stream: one JSONL line per progress event the root's executor observed. */
4
4
  declare const ROOT_STREAM_FILE = "root-stream.jsonl";
package/dist/durable.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import { i as publishExclusiveDurableFile, o as writeAtomicDurableFile } from "./durable-file-B_eJr6Mb.js";
2
- import { cn as failedItems, di as authoredProfileDigest, ga as detachedSnapshot, ma as contentAddress, na as FileSpawnJournal, oa as loadSpawnForest } from "./supervisor-Rz8AGpYb.js";
2
+ import { D as FileSpawnJournal, Dr as failedItems, Oi as authoredProfileDigest, ca as contentAddress, dt as loadSpawnForest, kr as isFiniteNumber, sa as detachedSnapshot } from "./supervisor-CPG1I9UN.js";
3
3
  import { f as RuntimeRunStateError, m as ValidationError } from "./errors-DodWX-cb.js";
4
- import { K as cloneSpend, U as addSpend, Y as errorMessage$1, dt as zeroSpend } from "./sandbox-profile-compat-QTkLe1Z6.js";
5
- import { a as readCommittedJsonLines, n as isNoEntError, t as appendCommittedJsonLine } from "./jsonl-file-DBv31uPi.js";
4
+ import { t as isRecord } from "./record-value-B6bwJxLa.js";
5
+ import { G as addSpend, J as cloneSpend, Z as errorMessage, pt as zeroSpend } from "./sandbox-profile-compat-xSoVtdWw.js";
6
6
  import { a as withPursuitContext, t as composeRuntimeHooks } from "./runtime-hooks-tXpAarhW.js";
7
- import { i as applyExactAgentProfileDiff } from "./profile-gNUsHNIJ.js";
8
- import { _ as readRootStream, a as superviseRootProfile, g as ROOT_STREAM_FILE, r as supervise, v as readRootStreamReceipt } from "./supervise-CvAKVfue.js";
9
- import { h as supervisorRunDir } from "./run-layout-Cu8H7aeh.js";
10
- import { i as superviseAgentGraph } from "./graph-C4RFlWAJ.js";
7
+ import { a as readCommittedJsonLines, n as isNoEntError, t as appendCommittedJsonLine } from "./jsonl-file-DBv31uPi.js";
8
+ import { a as superviseRootProfile, et as ROOT_STREAM_FILE, nt as readRootStreamReceipt, t as supervise, tt as readRootStream } from "./supervise-WuPAwfPh.js";
9
+ import { a as applyExactAgentProfileDiff } from "./profile-Do-5xO_D.js";
10
+ import { v as supervisorRunDir } from "./run-cancellation-BoW5Sg9Y.js";
11
+ import { i as superviseAgentGraph } from "./graph-CY0wH838.js";
11
12
  import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, canonicalCandidateJson, sha256Bytes } from "@tangle-network/agent-interface";
12
13
  import { createHash } from "node:crypto";
13
14
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
@@ -948,13 +949,13 @@ function jsonValue(result) {
948
949
  function settleRecordJson(result) {
949
950
  return canonicalCandidateJson(jsonValue(result));
950
951
  }
951
- /** Publish `runDir/result.json` once. Throws when a record is already there. */
952
+ /** Publish `result.json` in the run directory once. Throws when a record is already there. */
952
953
  async function writeSettleRecord(runDir, result) {
953
954
  const path = resolve(runDir, SETTLE_RECORD_FILE);
954
955
  if (!publishExclusiveDurableFile(path, settleRecordJson(result))) throw new Error(`supervisePursuit: ${path} already exists; a settle record is written once`);
955
956
  return path;
956
957
  }
957
- /** Replace `runDir/failure.json` with the most recent throw. */
958
+ /** Replace `failure.json` in the run directory with the most recent throw. */
958
959
  async function writeFailureRecord(runDir, record) {
959
960
  const path = resolve(runDir, FAILURE_RECORD_FILE);
960
961
  writeAtomicDurableFile(path, `${JSON.stringify(record, null, 2)}\n`);
@@ -1008,6 +1009,214 @@ async function readFailureRecord(runDir) {
1008
1009
  return parsed;
1009
1010
  }
1010
1011
  //#endregion
1012
+ //#region src/durable/pursuit-version-evidence.ts
1013
+ /** The chain's directory beside the first version's: the ledger and its content blobs. */
1014
+ function pursuitVersionsLedgerPath(runDir) {
1015
+ return resolve(`${resolve(runDir.trim())}.search`, "ledger.jsonl");
1016
+ }
1017
+ /** The bytes of a version's sealed `result.json` and the record they hold, parsed from the same
1018
+ * bytes that are hashed. */
1019
+ async function readSealed(runDir, version) {
1020
+ const path = resolve(runDir, SETTLE_RECORD_FILE);
1021
+ let bytes;
1022
+ try {
1023
+ bytes = await readFile(path);
1024
+ } catch (error) {
1025
+ if (!isNoEntError(error)) throw error;
1026
+ throw new RuntimeRunStateError(`supervisePursuit versions: version ${version} has no settle record in ${runDir}`);
1027
+ }
1028
+ return {
1029
+ bytes,
1030
+ result: parseSettleRecord(Buffer.from(bytes).toString("utf8"), path)
1031
+ };
1032
+ }
1033
+ /** A profile as the JSON the ledger stores: validated, with undefined entries absent. */
1034
+ function jsonProfile(profile) {
1035
+ canonicalAgentProfileDigest(profile);
1036
+ return JSON.parse(JSON.stringify(agentProfileSchema.parse(profile)));
1037
+ }
1038
+ function loadNode(store, node) {
1039
+ const stored = store.readBlob(node.artifact);
1040
+ if (stored.kind === "agent-profile") {
1041
+ const parsed = agentProfileSchema.safeParse(stored.profile);
1042
+ if (!parsed.success) throw new RuntimeRunStateError(`version node ${node.nodeId} holds an invalid AgentProfile`);
1043
+ return {
1044
+ profile: parsed.data,
1045
+ refusal: null
1046
+ };
1047
+ }
1048
+ if (stored.kind === "unapplied-change") return {
1049
+ profile: null,
1050
+ ...stored.change ? { change: stored.change } : {},
1051
+ ...stored.parentDigest ? { parentDigest: stored.parentDigest } : {},
1052
+ refusal: stored.refusal ?? "the change did not apply"
1053
+ };
1054
+ throw new RuntimeRunStateError(`version node ${node.nodeId} holds no version artifact`);
1055
+ }
1056
+ /** The `<runDir>.v<n>` directory and `<runId>.v<n>` id of version `n`, beside the first. */
1057
+ function versionRun(runDir, runId, version) {
1058
+ return version === 1 ? {
1059
+ runDir,
1060
+ runId
1061
+ } : {
1062
+ runDir: `${runDir}.v${version}`,
1063
+ runId: `${runId}.v${version}`
1064
+ };
1065
+ }
1066
+ /** A version's settled spend as the ledger's accounting. Unknown dollars carry the part a
1067
+ * provider is known to have billed as their floor. */
1068
+ function versionAccounting(spent) {
1069
+ const tokensKnown = spent !== void 0 && spent.tokensKnown !== false && spent.tokens?.tokensKnown !== false && Number.isSafeInteger(spent.tokens?.input) && Number.isSafeInteger(spent.tokens?.output) && Number.isSafeInteger(spent.tokens?.cacheRead);
1070
+ const usdKnown = spent !== void 0 && spent.usdKnown !== false && isFiniteNumber(spent.usd);
1071
+ return {
1072
+ tokens: tokensKnown ? {
1073
+ status: "known",
1074
+ inputTokens: spent.tokens.input,
1075
+ outputTokens: spent.tokens.output,
1076
+ cachedTokens: spent.tokens.cacheRead
1077
+ } : {
1078
+ status: "unknown",
1079
+ reason: `the version's settled spend reports no complete token count with its cache split (input ${spent?.tokens?.input ?? "none"}, output ${spent?.tokens?.output ?? "none"})`
1080
+ },
1081
+ cost: usdKnown ? {
1082
+ status: "known",
1083
+ usd: spent.usd,
1084
+ source: "provider"
1085
+ } : {
1086
+ status: "unknown",
1087
+ knownLowerBoundUsd: Math.max(0, isFiniteNumber(spent?.usd) ? spent.usd - (spent.usdEstimated ?? 0) : 0),
1088
+ reason: "the version's settled spend names unpriced or unreported work"
1089
+ }
1090
+ };
1091
+ }
1092
+ /** How long a version that settled before its chain opened ran, from its settle record. */
1093
+ function settledElapsed(settled) {
1094
+ const elapsed = settled?.spentTotal?.ms;
1095
+ return isFiniteNumber(elapsed) ? elapsed : 0;
1096
+ }
1097
+ const FREE = {
1098
+ tokens: {
1099
+ status: "known",
1100
+ inputTokens: 0,
1101
+ outputTokens: 0,
1102
+ cachedTokens: 0
1103
+ },
1104
+ cost: {
1105
+ status: "known",
1106
+ usd: 0,
1107
+ source: "free"
1108
+ }
1109
+ };
1110
+ /**
1111
+ * What a version that did no work failed with: a driver error, by its name and its message with
1112
+ * the parts that differ between runs (digits, hex runs, absolute paths) normalized, or an unscored
1113
+ * verdict. Null for a version that ran, won or not.
1114
+ */
1115
+ function versionFailure(version) {
1116
+ if (version.verdict.score === null) return "unscored by the judge";
1117
+ const { result } = version;
1118
+ if (result.kind !== "no-winner" || result.reason !== "driver-failed") return null;
1119
+ const message = result.error.message.replace(/(?:\/[\w.@~+-]+){2,}/gu, "<path>").replace(/\b[0-9a-f]{8,}\b/giu, "<hex>").replace(/\d+/gu, "<n>").slice(0, 500);
1120
+ return `driver-failed: ${result.error.name}: ${message}`;
1121
+ }
1122
+ function pursuitValueDigest(value, name) {
1123
+ try {
1124
+ return canonicalCandidateDigest(value);
1125
+ } catch (error) {
1126
+ throw new ValidationError(`supervisePursuit versions: the ${name} must be canonical JSON to pin the chain: ${errorMessage(error)}`);
1127
+ }
1128
+ }
1129
+ async function exists(path) {
1130
+ try {
1131
+ await access(path);
1132
+ return true;
1133
+ } catch (error) {
1134
+ if (isNoEntError(error)) return false;
1135
+ throw error;
1136
+ }
1137
+ }
1138
+ function isSha256(value) {
1139
+ return typeof value === "string" && /^sha256:[0-9a-f]{64}$/u.test(value);
1140
+ }
1141
+ //#endregion
1142
+ //#region src/durable/pursuit-version-review.ts
1143
+ /** Where `'review-of-best'` mounts a review: `inputs/review/version-<n>.md`. One review lives in
1144
+ * a profile at a time. */
1145
+ const REVIEW_DIR = "inputs/review/";
1146
+ /**
1147
+ * `'review-of-best'`: fork from the kept version with its check's verdict mounted under
1148
+ * {@link REVIEW_DIR} and the profile's review words as one instruction. The previous review's
1149
+ * mount and instruction are removed, so a profile carries one review.
1150
+ */
1151
+ function reviewOfBest(runId, words) {
1152
+ return ({ best, versions }) => {
1153
+ const n = versions.length + 1;
1154
+ const verdict = best.verdict.check;
1155
+ const path = `${REVIEW_DIR}version-${best.version}.md`;
1156
+ const instruction = words.replaceAll("{version}", String(best.version)).replaceAll("{path}", path).replaceAll("{score}", best.verdict.score === null ? "none" : String(best.verdict.score)).trim();
1157
+ const page = reviewPage(best.version, best.verdict.score, verdict);
1158
+ const earlier = best.change?.set?.prompt?.instructions ?? [];
1159
+ const earlierInstructions = earlier.filter((text) => text !== instruction);
1160
+ const earlierMounts = (best.profile.resources?.files ?? []).map((file) => file.path).filter((mounted) => mounted.startsWith("inputs/review/") && mounted !== path);
1161
+ return {
1162
+ kind: "agent-profile-diff",
1163
+ id: `${runId}-v${n}-review-of-v${best.version}`,
1164
+ title: `Version ${n}: review of version ${best.version}`,
1165
+ source: {
1166
+ kind: "optimizer",
1167
+ notes: [`review-of-best: version ${best.version}`, `judge ${best.verdict.judgeDigest}`]
1168
+ },
1169
+ set: {
1170
+ ...earlier.includes(instruction) ? {} : { prompt: { instructions: [instruction] } },
1171
+ resources: { files: [{
1172
+ path,
1173
+ resource: {
1174
+ kind: "inline",
1175
+ name: path,
1176
+ content: page
1177
+ }
1178
+ }] }
1179
+ },
1180
+ ...earlierInstructions.length > 0 || earlierMounts.length > 0 ? { remove: {
1181
+ ...earlierInstructions.length > 0 ? { prompt: { instructions: [...earlierInstructions] } } : {},
1182
+ ...earlierMounts.length > 0 ? { resources: { files: earlierMounts } } : {}
1183
+ } } : {}
1184
+ };
1185
+ };
1186
+ }
1187
+ /** The review page: facts only, in the check's own lines. */
1188
+ function reviewPage(version, score, verdict) {
1189
+ if (verdict === void 0) return [
1190
+ `# Version ${version}`,
1191
+ "",
1192
+ `Score: ${score ?? "none"}. The judge reported no per-item verdict.`,
1193
+ ""
1194
+ ].join("\n");
1195
+ const failing = failedItems(verdict);
1196
+ return [
1197
+ `# Version ${version}`,
1198
+ "",
1199
+ `Score: ${score ?? "none"}.${verdict.threshold === void 0 ? "" : ` The check passes at ${verdict.threshold}.`}`,
1200
+ "",
1201
+ "## Items",
1202
+ "",
1203
+ ...Object.entries(verdict.items ?? {}).map(([item, value]) => `- ${item}: ${value >= 1 ? "passes" : `fails (${value})`}`),
1204
+ "",
1205
+ ...failing.length === 0 ? [] : [
1206
+ "## Failures",
1207
+ "",
1208
+ ...verdict.failures ?? [],
1209
+ ""
1210
+ ],
1211
+ ...verdict.review === void 0 ? [] : [
1212
+ "## The check's review",
1213
+ "",
1214
+ verdict.review,
1215
+ ""
1216
+ ]
1217
+ ].join("\n");
1218
+ }
1219
+ //#endregion
1011
1220
  //#region src/durable/pursuit-versions.ts
1012
1221
  /**
1013
1222
  * The pursuit version chain, on Eval's search kernel (`runSearch`).
@@ -1020,13 +1229,6 @@ async function readFailureRecord(runDir) {
1020
1229
  * at `<runDir>.search/ledger.jsonl` is the chain's only record and its only checkpoint: a call on
1021
1230
  * a closed chain reads it back, and a call on an open chain continues it.
1022
1231
  */
1023
- /** Where `'review-of-best'` mounts a review: `inputs/review/version-<n>.md`. One review lives in
1024
- * a profile at a time. */
1025
- const REVIEW_DIR = "inputs/review/";
1026
- /** The chain's directory beside the first version's: the ledger and its content blobs. */
1027
- function pursuitVersionsLedgerPath(runDir) {
1028
- return resolve(`${resolve(runDir.trim())}.search`, "ledger.jsonl");
1029
- }
1030
1232
  /**
1031
1233
  * Validate a `versions` option before any compute. The same check runs inside `supervisePursuit`;
1032
1234
  * a caller that records the option as data can run it at preflight.
@@ -1108,7 +1310,7 @@ async function runPursuitVersions(profile, task, opts, runOne) {
1108
1310
  const retired = resolve(`${runDir}.versions`, "versions.jsonl");
1109
1311
  if (await exists(retired)) throw new ValidationError(`supervisePursuit versions: ${retired} holds a chain in the retired versions.jsonl format; finish it on the agent-runtime release that wrote it, or start a new chain in another runDir`);
1110
1312
  const firstProfile = jsonProfile(firstFork === void 0 ? profile : applyExactAgentProfileDiff(profile, firstFork.change, "supervisePursuit versions"));
1111
- const taskRevision = digestOf(task, "task");
1313
+ const taskRevision = pursuitValueDigest(task, "task");
1112
1314
  const identity = (nodeProfile) => ({
1113
1315
  model: {
1114
1316
  provider: "agent-runtime",
@@ -1606,99 +1808,6 @@ async function runPursuitVersions(profile, task, opts, runOne) {
1606
1808
  return chain;
1607
1809
  }
1608
1810
  }
1609
- /** The bytes of a version's sealed `result.json` and the record they hold, parsed from the same
1610
- * bytes that are hashed. */
1611
- async function readSealed(runDir, version) {
1612
- const path = resolve(runDir, SETTLE_RECORD_FILE);
1613
- let bytes;
1614
- try {
1615
- bytes = await readFile(path);
1616
- } catch (error) {
1617
- if (!isNoEntError(error)) throw error;
1618
- throw new RuntimeRunStateError(`supervisePursuit versions: version ${version} has no settle record in ${runDir}`);
1619
- }
1620
- return {
1621
- bytes,
1622
- result: parseSettleRecord(Buffer.from(bytes).toString("utf8"), path)
1623
- };
1624
- }
1625
- /** A profile as the JSON the ledger stores: validated, with undefined entries absent. */
1626
- function jsonProfile(profile) {
1627
- canonicalAgentProfileDigest(profile);
1628
- return JSON.parse(JSON.stringify(agentProfileSchema.parse(profile)));
1629
- }
1630
- function loadNode(store, node) {
1631
- const stored = store.readBlob(node.artifact);
1632
- if (stored.kind === "agent-profile") {
1633
- const parsed = agentProfileSchema.safeParse(stored.profile);
1634
- if (!parsed.success) throw new RuntimeRunStateError(`version node ${node.nodeId} holds an invalid AgentProfile`);
1635
- return {
1636
- profile: parsed.data,
1637
- refusal: null
1638
- };
1639
- }
1640
- if (stored.kind === "unapplied-change") return {
1641
- profile: null,
1642
- ...stored.change ? { change: stored.change } : {},
1643
- ...stored.parentDigest ? { parentDigest: stored.parentDigest } : {},
1644
- refusal: stored.refusal ?? "the change did not apply"
1645
- };
1646
- throw new RuntimeRunStateError(`version node ${node.nodeId} holds no version artifact`);
1647
- }
1648
- /** The `<runDir>.v<n>` directory and `<runId>.v<n>` id of version `n`, beside the first. */
1649
- function versionRun(runDir, runId, version) {
1650
- return version === 1 ? {
1651
- runDir,
1652
- runId
1653
- } : {
1654
- runDir: `${runDir}.v${version}`,
1655
- runId: `${runId}.v${version}`
1656
- };
1657
- }
1658
- /** A version's settled spend as the ledger's accounting. Unknown dollars carry the part a
1659
- * provider is known to have billed as their floor. */
1660
- function versionAccounting(spent) {
1661
- const tokensKnown = spent !== void 0 && spent.tokensKnown !== false && spent.tokens?.tokensKnown !== false && Number.isSafeInteger(spent.tokens?.input) && Number.isSafeInteger(spent.tokens?.output) && Number.isSafeInteger(spent.tokens?.cacheRead);
1662
- const usdKnown = spent !== void 0 && spent.usdKnown !== false && isFiniteNumber(spent.usd);
1663
- return {
1664
- tokens: tokensKnown ? {
1665
- status: "known",
1666
- inputTokens: spent.tokens.input,
1667
- outputTokens: spent.tokens.output,
1668
- cachedTokens: spent.tokens.cacheRead
1669
- } : {
1670
- status: "unknown",
1671
- reason: `the version's settled spend reports no complete token count with its cache split (input ${spent?.tokens?.input ?? "none"}, output ${spent?.tokens?.output ?? "none"})`
1672
- },
1673
- cost: usdKnown ? {
1674
- status: "known",
1675
- usd: spent.usd,
1676
- source: "provider"
1677
- } : {
1678
- status: "unknown",
1679
- knownLowerBoundUsd: Math.max(0, isFiniteNumber(spent?.usd) ? spent.usd - (spent.usdEstimated ?? 0) : 0),
1680
- reason: "the version's settled spend names unpriced or unreported work"
1681
- }
1682
- };
1683
- }
1684
- /** How long a version that settled before its chain opened ran, from its settle record. */
1685
- function settledElapsed(settled) {
1686
- const elapsed = settled?.spentTotal?.ms;
1687
- return isFiniteNumber(elapsed) ? elapsed : 0;
1688
- }
1689
- const FREE = {
1690
- tokens: {
1691
- status: "known",
1692
- inputTokens: 0,
1693
- outputTokens: 0,
1694
- cachedTokens: 0
1695
- },
1696
- cost: {
1697
- status: "known",
1698
- usd: 0,
1699
- source: "free"
1700
- }
1701
- };
1702
1811
  function canonicalStop(stop) {
1703
1812
  return {
1704
1813
  patience: stop.patience,
@@ -1710,18 +1819,6 @@ function canonicalStop(stop) {
1710
1819
  };
1711
1820
  }
1712
1821
  const DEFAULT_IDENTICAL_FAILURES = 3;
1713
- /**
1714
- * What a version that did no work failed with: a driver error, by its name and its message with
1715
- * the parts that differ between runs (digits, hex runs, absolute paths) normalized, or an unscored
1716
- * verdict. Null for a version that ran, won or not.
1717
- */
1718
- function versionFailure(version) {
1719
- if (version.verdict.score === null) return "unscored by the judge";
1720
- const { result } = version;
1721
- if (result.kind !== "no-winner" || result.reason !== "driver-failed") return null;
1722
- const message = result.error.message.replace(/(?:\/[\w.@~+-]+){2,}/gu, "<path>").replace(/\b[0-9a-f]{8,}\b/giu, "<hex>").replace(/\d+/gu, "<n>").slice(0, 500);
1723
- return `driver-failed: ${result.error.name}: ${message}`;
1724
- }
1725
1822
  /** The failure the last `count` judged versions share, or null when they do not all share one. */
1726
1823
  function identicalFailureStreak(versions, count) {
1727
1824
  if (versions.length < count) return null;
@@ -1729,104 +1826,6 @@ function identicalFailureStreak(versions, count) {
1729
1826
  const [first] = failures;
1730
1827
  return first !== null && first !== void 0 && failures.every((failure) => failure === first) ? first : null;
1731
1828
  }
1732
- /**
1733
- * `'review-of-best'`: fork from the kept version with its check's verdict mounted under
1734
- * {@link REVIEW_DIR} and the profile's review words as one instruction. The previous review's
1735
- * mount and instruction are removed, so a profile carries one review.
1736
- */
1737
- function reviewOfBest(runId, words) {
1738
- return ({ best, versions }) => {
1739
- const n = versions.length + 1;
1740
- const verdict = best.verdict.check;
1741
- const path = `${REVIEW_DIR}version-${best.version}.md`;
1742
- const instruction = words.replaceAll("{version}", String(best.version)).replaceAll("{path}", path).replaceAll("{score}", best.verdict.score === null ? "none" : String(best.verdict.score)).trim();
1743
- const page = reviewPage(best.version, best.verdict.score, verdict);
1744
- const earlier = best.change?.set?.prompt?.instructions ?? [];
1745
- const earlierInstructions = earlier.filter((text) => text !== instruction);
1746
- const earlierMounts = (best.profile.resources?.files ?? []).map((file) => file.path).filter((mounted) => mounted.startsWith("inputs/review/") && mounted !== path);
1747
- return {
1748
- kind: "agent-profile-diff",
1749
- id: `${runId}-v${n}-review-of-v${best.version}`,
1750
- title: `Version ${n}: review of version ${best.version}`,
1751
- source: {
1752
- kind: "optimizer",
1753
- notes: [`review-of-best: version ${best.version}`, `judge ${best.verdict.judgeDigest}`]
1754
- },
1755
- set: {
1756
- ...earlier.includes(instruction) ? {} : { prompt: { instructions: [instruction] } },
1757
- resources: { files: [{
1758
- path,
1759
- resource: {
1760
- kind: "inline",
1761
- name: path,
1762
- content: page
1763
- }
1764
- }] }
1765
- },
1766
- ...earlierInstructions.length > 0 || earlierMounts.length > 0 ? { remove: {
1767
- ...earlierInstructions.length > 0 ? { prompt: { instructions: [...earlierInstructions] } } : {},
1768
- ...earlierMounts.length > 0 ? { resources: { files: earlierMounts } } : {}
1769
- } } : {}
1770
- };
1771
- };
1772
- }
1773
- /** The review page: facts only, in the check's own lines. */
1774
- function reviewPage(version, score, verdict) {
1775
- if (verdict === void 0) return [
1776
- `# Version ${version}`,
1777
- "",
1778
- `Score: ${score ?? "none"}. The judge reported no per-item verdict.`,
1779
- ""
1780
- ].join("\n");
1781
- const failing = failedItems(verdict);
1782
- return [
1783
- `# Version ${version}`,
1784
- "",
1785
- `Score: ${score ?? "none"}.${verdict.threshold === void 0 ? "" : ` The check passes at ${verdict.threshold}.`}`,
1786
- "",
1787
- "## Items",
1788
- "",
1789
- ...Object.entries(verdict.items ?? {}).map(([item, value]) => `- ${item}: ${value >= 1 ? "passes" : `fails (${value})`}`),
1790
- "",
1791
- ...failing.length === 0 ? [] : [
1792
- "## Failures",
1793
- "",
1794
- ...verdict.failures ?? [],
1795
- ""
1796
- ],
1797
- ...verdict.review === void 0 ? [] : [
1798
- "## The check's review",
1799
- "",
1800
- verdict.review,
1801
- ""
1802
- ]
1803
- ].join("\n");
1804
- }
1805
- function digestOf(value, name) {
1806
- try {
1807
- return canonicalCandidateDigest(value);
1808
- } catch (error) {
1809
- throw new ValidationError(`supervisePursuit versions: the ${name} must be canonical JSON to pin the chain: ${errorMessage(error)}`);
1810
- }
1811
- }
1812
- async function exists(path) {
1813
- try {
1814
- await access(path);
1815
- return true;
1816
- } catch (error) {
1817
- if (isNoEntError(error)) return false;
1818
- throw error;
1819
- }
1820
- }
1821
- function isSha256(value) {
1822
- return typeof value === "string" && /^sha256:[0-9a-f]{64}$/u.test(value);
1823
- }
1824
- function isFiniteNumber(value) {
1825
- return typeof value === "number" && Number.isFinite(value);
1826
- }
1827
- function errorMessage(error) {
1828
- return error instanceof Error ? error.message : String(error);
1829
- }
1830
1829
  //#endregion
1831
1830
  //#region src/durable/run-fork.ts
1832
1831
  /**
@@ -2235,10 +2234,10 @@ function startPursuitObserverDelivery(delivery, read, warn = (message) => consol
2235
2234
  var SupervisePursuitError = class extends Error {
2236
2235
  pursuit;
2237
2236
  observerPath;
2238
- /** `runDir/failure.json`: the record of this throw. */
2237
+ /** `failure.json` in the run directory: the record of this throw. */
2239
2238
  failurePath;
2240
2239
  constructor(cause, pursuit, observerPath, failurePath) {
2241
- super(`supervisePursuit: ${errorMessage$1(cause)}`, { cause });
2240
+ super(`supervisePursuit: ${errorMessage(cause)}`, { cause });
2242
2241
  this.name = "SupervisePursuitError";
2243
2242
  this.pursuit = pursuit;
2244
2243
  this.observerPath = observerPath;
@@ -2341,7 +2340,7 @@ async function runDurablePursuit(opts, execute, settled) {
2341
2340
  try {
2342
2341
  await observer.journal.appendEvent(rootEvent(pursuitId, runId, "error", now(), {
2343
2342
  status: "failed",
2344
- error: errorMessage$1(error)
2343
+ error: errorMessage(error)
2345
2344
  }));
2346
2345
  pursuit = projectPursuit(await observer.journal.read());
2347
2346
  } catch (failure) {
@@ -2356,7 +2355,7 @@ async function runDurablePursuit(opts, execute, settled) {
2356
2355
  at: new Date(now()).toISOString(),
2357
2356
  error: {
2358
2357
  name: errorName(error),
2359
- message: errorMessage$1(error)
2358
+ message: errorMessage(error)
2360
2359
  },
2361
2360
  ...rootStream === void 0 ? {} : { rootStream }
2362
2361
  });
@@ -2461,9 +2460,6 @@ async function discoverDurableSupervisionRun(runDir) {
2461
2460
  coordinationStreams: Object.freeze(coordinationStreams)
2462
2461
  });
2463
2462
  }
2464
- function isRecord(value) {
2465
- return typeof value === "object" && value !== null && !Array.isArray(value);
2466
- }
2467
2463
  function compareText(left, right) {
2468
2464
  return left < right ? -1 : left > right ? 1 : 0;
2469
2465
  }