@tangle-network/agent-runtime 0.142.3 → 0.153.1

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 (117) hide show
  1. package/README.md +32 -0
  2. package/dist/{activation-o7JKmtxi.js → activation-DKxQsHiO.js} +3 -3
  3. package/dist/{activation-o7JKmtxi.js.map → activation-DKxQsHiO.js.map} +1 -1
  4. package/dist/agent.d.ts +2 -2
  5. package/dist/agent.js +3 -3
  6. package/dist/{analyst-loop-GcX0BY75.js → analyst-loop-B2kTHKNh.js} +2 -2
  7. package/dist/{analyst-loop-GcX0BY75.js.map → analyst-loop-B2kTHKNh.js.map} +1 -1
  8. package/dist/analyst-loop.d.ts +1 -1
  9. package/dist/analyst-loop.js +1 -1
  10. package/dist/{authoring-Bm1WlGPv.js → authoring-Tk2xFys0.js} +2 -2
  11. package/dist/{authoring-Bm1WlGPv.js.map → authoring-Tk2xFys0.js.map} +1 -1
  12. package/dist/candidate-execution/index.js +4 -4
  13. package/dist/{candidate-execution-CD5PoNmC.js → candidate-execution-CB9RJbbJ.js} +4 -4
  14. package/dist/{candidate-execution-CD5PoNmC.js.map → candidate-execution-CB9RJbbJ.js.map} +1 -1
  15. package/dist/{conversation-DXKJHyqB.js → conversation-D64WyWrK.js} +4 -4
  16. package/dist/{conversation-DXKJHyqB.js.map → conversation-D64WyWrK.js.map} +1 -1
  17. package/dist/conversation.d.ts +1 -1
  18. package/dist/conversation.js +1 -1
  19. package/dist/durable.d.ts +102 -4
  20. package/dist/durable.js +259 -10
  21. package/dist/durable.js.map +1 -1
  22. package/dist/{environment-provider-BicwCDK5.d.ts → environment-provider-DJG0yIYl.d.ts} +3 -3
  23. package/dist/{environment-provider-DCEACNt9.js → environment-provider-D_MXw3jK.js} +88 -9
  24. package/dist/environment-provider-D_MXw3jK.js.map +1 -0
  25. package/dist/environment-provider.d.ts +1 -1
  26. package/dist/environment-provider.js +1 -1
  27. package/dist/executable-spec-BUcUcEPk.js +73 -0
  28. package/dist/executable-spec-BUcUcEPk.js.map +1 -0
  29. package/dist/{graph-DhrLuLOS.js → graph-M0Qr4863.js} +4 -4
  30. package/dist/{graph-DhrLuLOS.js.map → graph-M0Qr4863.js.map} +1 -1
  31. package/dist/{improvement-cycle-lcwlR6E2.js → improvement-cycle-CDxlGQGE.js} +7 -7
  32. package/dist/{improvement-cycle-lcwlR6E2.js.map → improvement-cycle-CDxlGQGE.js.map} +1 -1
  33. package/dist/{index-Bx3-tqG-.d.ts → index-BihHgUAI.d.ts} +4 -4
  34. package/dist/{index-D_aH0F4C.d.ts → index-Dlz7ejRx.d.ts} +342 -521
  35. package/dist/{index-CV1xRWy2.d.ts → index-LQfgFJoX.d.ts} +3 -3
  36. package/dist/index.d.ts +9 -9
  37. package/dist/index.js +13 -13
  38. package/dist/intelligence.d.ts +5 -5
  39. package/dist/intelligence.js +6 -6
  40. package/dist/kernel.d.ts +7 -7
  41. package/dist/kernel.js +13 -13
  42. package/dist/{knowledge-C9LlSJAR.js → knowledge-DM-i40b9.js} +10 -7
  43. package/dist/{knowledge-C9LlSJAR.js.map → knowledge-DM-i40b9.js.map} +1 -1
  44. package/dist/knowledge.d.ts +1 -1
  45. package/dist/knowledge.js +1 -1
  46. package/dist/{loop-runner-bin-CctBy5-X.d.ts → loop-runner-bin-D-BW51yr.d.ts} +3 -3
  47. package/dist/{loop-runner-bin-DFo6Ss-1.js → loop-runner-bin-pD5WJuqJ.js} +4 -4
  48. package/dist/{loop-runner-bin-DFo6Ss-1.js.map → loop-runner-bin-pD5WJuqJ.js.map} +1 -1
  49. package/dist/loop-runner-bin.d.ts +1 -1
  50. package/dist/loop-runner-bin.js +1 -1
  51. package/dist/{materialization-CrdcfWXp.js → materialization-Bo6j3Hg9.js} +261 -24
  52. package/dist/materialization-Bo6j3Hg9.js.map +1 -0
  53. package/dist/mcp/bin.js +3 -3
  54. package/dist/mcp/index.d.ts +5 -5
  55. package/dist/mcp/index.js +6 -6
  56. package/dist/{model-policy-DgRJIJse.js → model-policy-Sw4ywhtL.js} +68 -6
  57. package/dist/model-policy-Sw4ywhtL.js.map +1 -0
  58. package/dist/{openai-tools-CSm460sC.js → openai-tools-CWBywy-e.js} +2 -2
  59. package/dist/{openai-tools-CSm460sC.js.map → openai-tools-CWBywy-e.js.map} +1 -1
  60. package/dist/{openai-tools-t5-6h5bj.d.ts → openai-tools-z-whdYNC.d.ts} +2 -2
  61. package/dist/{prepare-D3n7cA39.js → prepare-C3eFd3UA.js} +2 -2
  62. package/dist/{prepare-D3n7cA39.js.map → prepare-C3eFd3UA.js.map} +1 -1
  63. package/dist/primeintellect/index.d.ts +1 -1
  64. package/dist/profiles.d.ts +1 -1
  65. package/dist/profiles.js +1 -1
  66. package/dist/{protected-model-port-bq6bD9YX.js → protected-model-port-Dn2b6peS.js} +2 -2
  67. package/dist/{protected-model-port-bq6bD9YX.js.map → protected-model-port-Dn2b6peS.js.map} +1 -1
  68. package/dist/{redact-B0gDSTZO.d.ts → redact-NAptmqKw.d.ts} +3 -3
  69. package/dist/{researcher-CiSY6Wzb.js → researcher-BMFFPwKb.js} +2 -2
  70. package/dist/{researcher-CiSY6Wzb.js.map → researcher-BMFFPwKb.js.map} +1 -1
  71. package/dist/{run-layout-Be_Z0dF8.js → run-layout-C2jgwsCq.js} +111 -6
  72. package/dist/run-layout-C2jgwsCq.js.map +1 -0
  73. package/dist/{runtime-htqI3fKL.d.ts → runtime-B-5dp5Iz.d.ts} +223 -11
  74. package/dist/{runtime-DQs5xHdt.js → runtime-RY_rvv7t.js} +93 -84
  75. package/dist/runtime-RY_rvv7t.js.map +1 -0
  76. package/dist/{sandbox-events-BK-g19wx.js → sandbox-events-DMijDq2p.js} +53 -49
  77. package/dist/sandbox-events-DMijDq2p.js.map +1 -0
  78. package/dist/{spawn-journal-D2HKUImC.js → spawn-journal-CLguaA2A.js} +8 -43
  79. package/dist/spawn-journal-CLguaA2A.js.map +1 -0
  80. package/dist/{stream-agent-turn-Dfy12OjG.d.ts → stream-agent-turn-BGyszuPH.d.ts} +6 -3
  81. package/dist/{stream-agent-turn-BMHUIuQS.js → stream-agent-turn-D6HoaRPV.js} +140 -23
  82. package/dist/stream-agent-turn-D6HoaRPV.js.map +1 -0
  83. package/dist/{structural-rollout-CzZKDkmA.js → structural-rollout-P1YxFRfl.js} +11 -8
  84. package/dist/structural-rollout-P1YxFRfl.js.map +1 -0
  85. package/dist/{supervise-BEs5MB91.js → supervise-BezbzKiJ.js} +1550 -1186
  86. package/dist/supervise-BezbzKiJ.js.map +1 -0
  87. package/dist/{supervisor-B_0ISTFG.js → supervisor-DBVlPONC.js} +697 -230
  88. package/dist/supervisor-DBVlPONC.js.map +1 -0
  89. package/dist/testing.d.ts +2 -2
  90. package/dist/testing.js +12 -12
  91. package/dist/{top-app-BMOSKK06.js → top-app-tKo9OrON.js} +189 -86
  92. package/dist/top-app-tKo9OrON.js.map +1 -0
  93. package/dist/tui/bin.js +1 -1
  94. package/dist/tui/index.d.ts +32 -4
  95. package/dist/tui/index.js +1 -1
  96. package/dist/{types-_7w24mMg.d.ts → types-BPQhQRrC.d.ts} +508 -11
  97. package/dist/{types-DZrBoBpN.d.ts → types-DeX8ibLc.d.ts} +4 -1
  98. package/dist/{util-C1bv6yog.js → util-Bncw0o_F.js} +41 -2
  99. package/dist/util-Bncw0o_F.js.map +1 -0
  100. package/dist/{workspace-archive-C52LjkeN.js → workspace-archive-Dm73lTfB.js} +2 -2
  101. package/dist/{workspace-archive-C52LjkeN.js.map → workspace-archive-Dm73lTfB.js.map} +1 -1
  102. package/package.json +6 -6
  103. package/dist/environment-provider-DCEACNt9.js.map +0 -1
  104. package/dist/materialization-CrdcfWXp.js.map +0 -1
  105. package/dist/model-policy-DgRJIJse.js.map +0 -1
  106. package/dist/retained-run-binding-Dp2e8xne.js +0 -268
  107. package/dist/retained-run-binding-Dp2e8xne.js.map +0 -1
  108. package/dist/run-layout-Be_Z0dF8.js.map +0 -1
  109. package/dist/runtime-DQs5xHdt.js.map +0 -1
  110. package/dist/sandbox-events-BK-g19wx.js.map +0 -1
  111. package/dist/spawn-journal-D2HKUImC.js.map +0 -1
  112. package/dist/stream-agent-turn-BMHUIuQS.js.map +0 -1
  113. package/dist/structural-rollout-CzZKDkmA.js.map +0 -1
  114. package/dist/supervise-BEs5MB91.js.map +0 -1
  115. package/dist/supervisor-B_0ISTFG.js.map +0 -1
  116. package/dist/top-app-BMOSKK06.js.map +0 -1
  117. package/dist/util-C1bv6yog.js.map +0 -1
@@ -1,31 +1,32 @@
1
- import { C as sameControlCoordinates, S as isTerminalSessionStatus, _ as exactSession, a as assertEventBinding, b as freezeControlRef, c as assertSequence, d as awaitAbortable, f as cancellationRequest, g as exactControlRef, h as exactContinuedControlRef, i as assertCanonicalEventBinding, l as assertStableText, m as delay, n as abortError, o as assertInteractionBinding, p as copyControlRef, r as assertBoundaryBinding, s as assertResultBinding, t as RetainedRunProviderContractError, u as assertWaitDuration, v as exactSessionCancel, w as freshTurnInput, x as hasDurableCancel, y as exactSessionResult } from "./retained-run-binding-Dp2e8xne.js";
1
+ import { A as assertInteractionBinding, B as exactControlRef, D as assertBoundaryBinding, E as abortError, F as awaitAbortable, G as hasDurableCancel, H as exactSessionCancel, I as cancellationRequest, J as freshTurnInput, K as isTerminalSessionStatus, L as copyControlRef, M as assertSequence, N as assertStableText, O as assertCanonicalEventBinding, P as assertWaitDuration, R as delay, T as RetainedRunProviderContractError, U as exactSessionResult, V as exactSession, W as freezeControlRef, j as assertResultBinding, k as assertEventBinding, q as sameControlCoordinates, z as exactContinuedControlRef } from "./materialization-Bo6j3Hg9.js";
2
2
  import { c as RetainedInteractiveAdmissionError, d as RetainedRunDispatchBindingError, l as RetainedInteractiveBindingError, m as ValidationError, n as AnalystError, s as PlannerError, u as RetainedRunAdmissionError } from "./errors-CDZ8XsVj.js";
3
- import "./stream-agent-turn-BMHUIuQS.js";
3
+ import "./stream-agent-turn-D6HoaRPV.js";
4
4
  import { t as detachedSnapshot } from "./snapshot-cK9K420n.js";
5
- import { S as contentAddress, i as InMemorySpawnJournal, r as InMemoryResultBlobStore, y as isTraceAnalysisStore } from "./spawn-journal-D2HKUImC.js";
6
- import { _ as zeroTokenUsage, a as hasCompleteCacheBreakdown, d as sleep, f as stringifySafe, h as usdEstimatedOf, l as randomSuffix, n as chargedTokens, o as isAbortError, r as cloneTokenUsage, t as addTokenUsage } from "./util-C1bv6yog.js";
5
+ import { S as contentAddress, i as InMemorySpawnJournal, r as InMemoryResultBlobStore, y as isTraceAnalysisStore } from "./spawn-journal-CLguaA2A.js";
6
+ import { c as isAbortError, d as randomSuffix, i as cloneSpend, m as stringifySafe, p as sleep, r as chargedTokens, s as hasCompleteCacheBreakdown, t as addSpend, v as zeroSpend } from "./util-Bncw0o_F.js";
7
7
  import { i as redactProtectedValue, r as redactProtectedReason } from "./protected-redaction--F3v1oo8.js";
8
- import { c as notifySandboxEventObserver, f as extractTransportEventIdentity, p as parseCanonicalTransportEvent } from "./sandbox-events-BK-g19wx.js";
9
- import { c as profileProviderModel, i as concreteModelId, s as profileModelExecutionSettings, t as assertExecutableAgentProfile } from "./model-policy-DgRJIJse.js";
10
- import { E as executableAgentSpecSnapshot, T as executableAgentProfileSnapshot } from "./materialization-CrdcfWXp.js";
11
- import { E as rollingDispatch, I as createExecutor, L as createExecutorRegistry, _t as runBrainLoop, ft as runAgentRounds, g as settledToIteration, gt as routerBrain, l as withDriverExecutor, mt as probeSandboxCapabilities, n as createSupervisor, pt as createSandboxLineage, q as createPushTraceSource, ut as defaultSelectWinner, vt as canonicalObservedModel, z as createWorktreeCliExecutor } from "./supervisor-B_0ISTFG.js";
12
- import "./environment-provider-DCEACNt9.js";
8
+ import { d as extractTransportEventIdentity, f as parseCanonicalTransportEvent, s as notifySandboxEventObserver } from "./sandbox-events-DMijDq2p.js";
9
+ import { n as executableAgentSpecSnapshot, t as executableAgentProfileSnapshot } from "./executable-spec-BUcUcEPk.js";
10
+ import { c as profileModelExecutionSettings, i as concreteModelId, l as profileProviderModel, o as enforceTokenLimits, t as assertExecutableAgentProfile } from "./model-policy-Sw4ywhtL.js";
11
+ import { B as createExecutorRegistry, E as rollingDispatch, H as createWorktreeCliExecutor, X as createPushTraceSource, _t as probeSandboxCapabilities, bt as runBrainLoop, g as settledToIteration, gt as createSandboxLineage, ht as runAgentRounds, l as withDriverExecutor, n as createSupervisor, pt as defaultSelectWinner, xt as canonicalObservedModel, yt as routerBrain, z as createExecutor } from "./supervisor-DBVlPONC.js";
12
+ import "./environment-provider-D_MXw3jK.js";
13
13
  import { i as notifyRuntimeHookEvent } from "./runtime-hooks-tXpAarhW.js";
14
- import { C as observe, O as strategyAuthorMethod, T as profileChatClient, b as sample, v as refine, x as sampleThenRefine, y as runAgentic } from "./structural-rollout-CzZKDkmA.js";
15
- import { It as gateOnDeliverable, Lt as mapExecutorResult, n as supervise } from "./supervise-BEs5MB91.js";
16
- import "./authoring-Bm1WlGPv.js";
17
- import "./graph-DhrLuLOS.js";
14
+ import { C as observe, O as strategyAuthorMethod, T as profileChatClient, b as sample, v as refine, x as sampleThenRefine, y as runAgentic } from "./structural-rollout-P1YxFRfl.js";
15
+ import { At as mapExecutorResult, kt as gateOnDeliverable, n as supervise } from "./supervise-BezbzKiJ.js";
16
+ import "./authoring-Tk2xFys0.js";
17
+ import "./graph-M0Qr4863.js";
18
18
  import { AgentEnvironmentCapabilitiesSchema, AgentExactRunControlRefSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStatusSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentNativeContextContinuationResultSchema, AgentTurnResultSchema, InteractionAcknowledgementSchema, InteractionResponseCommandSchema, NativeContextBoundaryProofSchema, NativeContextContinuationRequestSchema, RuntimeEventEnvelopeSchema, TerminalReplayWindowSchema, TerminalSessionRefSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimRequestDigest, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentNativeContextContinuationResultMatchesRequest, agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, exactAgentInteractiveSessionStart, nativeContextContinuationTurnDigest, validateAgentProfileSecurity } from "@tangle-network/agent-interface";
19
- import { CODING_HARNESSES, InMemoryTraceStore, OUTPUT_VALUE, benjaminiHochberg, buildTrajectory, computeFindingId as computeFindingId$1, confidenceInterval, expandProfileAxes, makeFinding as makeFinding$1, pairedBootstrap, paretoFrontier, wilcoxonSignedRank, wilson } from "@tangle-network/agent-eval";
19
+ import { CODING_HARNESSES, DEFAULT_TRACE_ANALYST_KINDS, InMemoryTraceStore, OUTPUT_VALUE, benjaminiHochberg, buildTrajectory, computeFindingId as computeFindingId$1, confidenceInterval, expandProfileAxes, makeFinding as makeFinding$1, pairedBootstrap, paretoFrontier, wilcoxonSignedRank, wilson } from "@tangle-network/agent-eval";
20
20
  import { heldoutSignificance, runProfileMatrix } from "@tangle-network/agent-eval/campaign";
21
- import { createHash } from "node:crypto";
21
+ import { createHash, randomUUID } from "node:crypto";
22
22
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
23
23
  import { mkdir, readFile, realpath, writeFile } from "node:fs/promises";
24
24
  import { appendFileSync, chmodSync, constants, copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readlinkSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
25
25
  import { execFileSync, spawn, spawnSync } from "node:child_process";
26
26
  import { tmpdir } from "node:os";
27
- import { createInterface } from "node:readline";
27
+ import { createAgentRunOutcomeTracker } from "@tangle-network/sandbox/runtime";
28
28
  import { collectAgentResponseText } from "@tangle-network/sandbox";
29
+ import { createInterface } from "node:readline";
29
30
  import { gzipSync } from "node:zlib";
30
31
  import { stuckLoopView, toolWasteView } from "@tangle-network/agent-eval/pipelines";
31
32
  //#region src/runtime/key-provider.ts
@@ -1389,7 +1390,7 @@ function localSandboxClient(opts) {
1389
1390
  routerKey: router.key,
1390
1391
  model,
1391
1392
  ...settings.retry !== void 0 ? { retry: settings.retry } : {},
1392
- ...settings.maxTokens !== void 0 ? { maxTokens: settings.maxTokens } : {},
1393
+ ...enforceTokenLimits(settings.tokenLimits, "router", "localSandboxClient").applied,
1393
1394
  ...settings.stream !== void 0 ? { stream: settings.stream } : {}
1394
1395
  }, {
1395
1396
  ...settings.temperature !== void 0 ? { temperature: settings.temperature } : {},
@@ -3073,7 +3074,7 @@ async function trajectoryReport(journal, blobs, root, options = {}) {
3073
3074
  const events = await journal.loadTree(root);
3074
3075
  if (events === void 0) throw new Error(`trajectoryReport: no journaled tree for root '${root}'`);
3075
3076
  const spawns = events.filter(isNodeCreation).sort(bySeq);
3076
- const closes = events.filter((ev) => ev.kind !== "spawned" && ev.kind !== "waiting" && ev.kind !== "metered" && ev.kind !== "materialized" && ev.kind !== "execution-bound" && ev.kind !== "edge" && ev.kind !== "trace-unpropagated").sort(bySeq);
3077
+ const closes = events.filter((ev) => ev.kind !== "spawned" && ev.kind !== "waiting" && ev.kind !== "metered" && ev.kind !== "materialized" && ev.kind !== "execution-bound" && ev.kind !== "edge" && ev.kind !== "teardown-unconfirmed" && ev.kind !== "trace-unpropagated").sort(bySeq);
3077
3078
  const nodes = /* @__PURE__ */ new Map();
3078
3079
  for (const ev of spawns) nodes.set(ev.id, {
3079
3080
  id: ev.id,
@@ -3103,7 +3104,7 @@ async function trajectoryReport(journal, blobs, root, options = {}) {
3103
3104
  for (const ev of events) {
3104
3105
  if (ev.kind !== "metered") continue;
3105
3106
  const node = requireNode(nodes, ev.id, root);
3106
- node.ownSpend = addNodeSpend(node.ownSpend, ev.spend);
3107
+ node.ownSpend = addSpend(node.ownSpend, ev.spend);
3107
3108
  }
3108
3109
  if (!nodes.has(root)) throw new Error(`trajectoryReport: root '${root}' has no spawned event in its journaled tree (corrupted log)`);
3109
3110
  for (const ev of spawns) {
@@ -3180,8 +3181,8 @@ function rollUpSpend(nodes, root) {
3180
3181
  });
3181
3182
  continue;
3182
3183
  }
3183
- const sum = cloneSpend(node.ownSpend);
3184
- for (const child of node.children) addSpend(sum, requireSpend(rolled, child, root));
3184
+ let sum = cloneSpend(node.ownSpend);
3185
+ for (const child of node.children) sum = addSpend(sum, requireSpend(rolled, child, root));
3185
3186
  rolled.set(frame.id, sum);
3186
3187
  }
3187
3188
  return rolled;
@@ -3225,51 +3226,6 @@ function countStatuses(reported) {
3225
3226
  for (const node of reported) counts[node.status] += 1;
3226
3227
  return counts;
3227
3228
  }
3228
- function zeroSpend() {
3229
- return {
3230
- iterations: 0,
3231
- tokens: zeroTokenUsage(),
3232
- usd: 0,
3233
- ms: 0
3234
- };
3235
- }
3236
- /** Add a `metered` event's spend onto a node's accumulated ownSpend (per channel). */
3237
- function addNodeSpend(a, b) {
3238
- return {
3239
- iterations: a.iterations + b.iterations,
3240
- tokens: (() => {
3241
- const tokens = cloneTokenUsage(a.tokens);
3242
- addTokenUsage(tokens, b.tokens);
3243
- return tokens;
3244
- })(),
3245
- ...a.tokensKnown === false || b.tokensKnown === false ? { tokensKnown: false } : {},
3246
- usd: a.usd + b.usd,
3247
- ...a.usdKnown === false || b.usdKnown === false ? { usdKnown: false } : {},
3248
- ...usdEstimatedOf(a, b),
3249
- ms: a.ms + b.ms
3250
- };
3251
- }
3252
- function cloneSpend(spend) {
3253
- return {
3254
- iterations: spend.iterations,
3255
- tokens: cloneTokenUsage(spend.tokens),
3256
- ...spend.tokensKnown === false ? { tokensKnown: false } : {},
3257
- usd: spend.usd,
3258
- ...spend.usdKnown === false ? { usdKnown: false } : {},
3259
- ...spend.usdEstimated !== void 0 ? { usdEstimated: spend.usdEstimated } : {},
3260
- ms: spend.ms
3261
- };
3262
- }
3263
- /** Add `delta` into `acc` in place across every conserved channel. */
3264
- function addSpend(acc, delta) {
3265
- acc.iterations += delta.iterations;
3266
- addTokenUsage(acc.tokens, delta.tokens);
3267
- if (delta.tokensKnown === false) acc.tokensKnown = false;
3268
- acc.usd += delta.usd;
3269
- if (delta.usdKnown === false) acc.usdKnown = false;
3270
- if (delta.usdEstimated !== void 0) acc.usdEstimated = (acc.usdEstimated ?? 0) + delta.usdEstimated;
3271
- acc.ms += delta.ms;
3272
- }
3273
3229
  function spreadOf(values) {
3274
3230
  if (values.length === 0) return 0;
3275
3231
  return Math.max(...values) - Math.min(...values);
@@ -4068,11 +4024,26 @@ async function dispatchRetainedRun(options) {
4068
4024
  sessionId: identity.sessionId,
4069
4025
  executionId: identity.executionId
4070
4026
  });
4071
- const reference = await environment.dispatch(freshTurnInput(options.turn, {
4072
- turnId: options.turn.turnId,
4073
- detach: true,
4074
- ...identity
4075
- }));
4027
+ const destroyIfCreated = async (cause) => {
4028
+ if (environment.creation !== "created") throw cause;
4029
+ try {
4030
+ await environment.destroy?.();
4031
+ } catch (cleanupError) {
4032
+ throw new AggregateError([cause, cleanupError], "retained run dispatch failed and the environment it created could not be destroyed");
4033
+ }
4034
+ throw cause;
4035
+ };
4036
+ let reference;
4037
+ try {
4038
+ reference = await environment.dispatch(freshTurnInput(options.turn, {
4039
+ turnId: options.turn.turnId,
4040
+ detach: true,
4041
+ ...identity
4042
+ }));
4043
+ } catch (error) {
4044
+ await destroyIfCreated(error);
4045
+ throw error;
4046
+ }
4076
4047
  let exact;
4077
4048
  try {
4078
4049
  if (reference.provider !== void 0 && reference.provider !== options.provider.name) throw new Error("provider dispatch returned a session reference for another provider");
@@ -4085,7 +4056,7 @@ async function dispatchRetainedRun(options) {
4085
4056
  if (controlRef.executionId !== identity.executionId) throw new Error("provider bound another execution than the requested identity");
4086
4057
  exact = exactSession(environment, controlRef);
4087
4058
  } catch (error) {
4088
- throw new RetainedRunDispatchBindingError({
4059
+ const bindingError = new RetainedRunDispatchBindingError({
4089
4060
  provider: options.provider.name,
4090
4061
  environmentId: environment.id,
4091
4062
  sessionId: identity.sessionId,
@@ -4095,6 +4066,8 @@ async function dispatchRetainedRun(options) {
4095
4066
  ...reference.provider === void 0 ? {} : { provider: reference.provider },
4096
4067
  ...reference.controlRef === void 0 ? {} : { controlRef: reference.controlRef }
4097
4068
  }, { cause: error });
4069
+ await destroyIfCreated(bindingError);
4070
+ throw bindingError;
4098
4071
  }
4099
4072
  await admitDurably(options.onAdmission, {
4100
4073
  phase: "dispatched",
@@ -4675,13 +4648,13 @@ async function runBenchmark(cfg) {
4675
4648
  resolved: false,
4676
4649
  progression: [],
4677
4650
  usd: 0,
4678
- usdKnown: true,
4651
+ usdKnown: false,
4679
4652
  ms: 0,
4680
4653
  tokens: {
4681
4654
  input: 0,
4682
4655
  output: 0
4683
4656
  },
4684
- tokensKnown: true
4657
+ tokensKnown: false
4685
4658
  };
4686
4659
  }
4687
4660
  row = {
@@ -4884,9 +4857,11 @@ async function openSandboxRun(client, options, deliverable) {
4884
4857
  });
4885
4858
  async function settle(box, events, turnIndex, turnKind) {
4886
4859
  const collected = [];
4860
+ const outcomeTracker = createAgentRunOutcomeTracker();
4887
4861
  try {
4888
4862
  for await (const ev of events) {
4889
4863
  collected.push(ev);
4864
+ outcomeTracker.observe(ev);
4890
4865
  notifySandboxEventObserver(ev, options.onSandboxEvent, {
4891
4866
  turnIndex,
4892
4867
  turnKind,
@@ -4897,9 +4872,11 @@ async function openSandboxRun(client, options, deliverable) {
4897
4872
  if (isAbortError(err)) throw new SandboxRunAbortError(collected);
4898
4873
  throw err;
4899
4874
  }
4875
+ const outcome = outcomeTracker.finish();
4900
4876
  if (deliverable.kind === "events") return {
4901
4877
  out: deliverable.fromEvents(collected),
4902
- events: collected
4878
+ events: collected,
4879
+ outcome
4903
4880
  };
4904
4881
  if (options.signal.aborted) throw new SandboxRunAbortError(collected);
4905
4882
  const attempted = await readBoxPathWithRetry(box.fs.read.bind(box.fs), deliverable.path, {
@@ -4915,6 +4892,7 @@ async function openSandboxRun(client, options, deliverable) {
4915
4892
  return {
4916
4893
  out: deliverable.fromArtifact(raw, collected),
4917
4894
  events: collected,
4895
+ outcome,
4918
4896
  ...readError !== void 0 ? { readError } : {}
4919
4897
  };
4920
4898
  }
@@ -6285,6 +6263,43 @@ function traceSurfaceCalls(base) {
6285
6263
  traceSource: trace.source
6286
6264
  };
6287
6265
  }
6266
+ /**
6267
+ * Adapt an `agent-eval` `AnalystRegistry` into the lens shape `supervise({ analysts })` takes.
6268
+ *
6269
+ * The two registries were never structurally compatible: eval's class exposes `list()` and
6270
+ * `run(runId, inputs, opts)` and returns an `AnalystRunResult`, while `supervise` wants `kinds`
6271
+ * and `run(kindId, trace)`. So `'kinds' in buildDefaultAnalystRegistry()` is `false` and the five
6272
+ * calibrated lenses in `DEFAULT_TRACE_ANALYST_KINDS` were unreachable from any supervised run —
6273
+ * every consumer hand-rolled a lens instead (#630).
6274
+ *
6275
+ * The adapter lives HERE, not in eval, for one reason: eval must never import runtime, and runtime
6276
+ * already owns both shapes — it consumes `AnalystFinding` / `AnalystRunResult` from eval for its
6277
+ * analyst loop and defines the supervise lens itself. Writing it in eval would mean eval declaring
6278
+ * a duck-typed copy of a type this package already exports.
6279
+ *
6280
+ * `kinds` is the DEFINITION list, not `registry.list()`, because `Analyst` carries no `area` while
6281
+ * `TraceAnalystDefinition` does — `list()` cannot supply the field the lens shape requires. Every
6282
+ * id must be registered: an unknown kind throws at adapt time rather than returning nothing at run
6283
+ * time, when the driver would read the silence as "no findings".
6284
+ */
6285
+ function analystsFromRegistry(registry, kinds = DEFAULT_TRACE_ANALYST_KINDS, opts) {
6286
+ const registered = new Set(registry.list().map((analyst) => analyst.id));
6287
+ const missing = kinds.map((kind) => kind.id).filter((id) => !registered.has(id));
6288
+ if (missing.length > 0) throw new ValidationError(`analystsFromRegistry: ${missing.map((id) => JSON.stringify(id)).join(", ")} ${missing.length === 1 ? "is" : "are"} not registered; the registry has ${[...registered].map((id) => JSON.stringify(id)).join(", ") || "<none>"}`);
6289
+ return {
6290
+ kinds: kinds.map((kind) => ({
6291
+ id: kind.id,
6292
+ description: kind.description,
6293
+ area: kind.area
6294
+ })),
6295
+ run: async (kindId, trace) => {
6296
+ return (await registry.run(`supervise-analyst-${kindId}-${randomUUID()}`, { traceStore: trace }, {
6297
+ ...opts?.runOpts,
6298
+ only: [kindId]
6299
+ })).findings;
6300
+ }
6301
+ };
6302
+ }
6288
6303
  /** The default self-improvement LENS — authored content, not a code path. On each settled worker it hands
6289
6304
  * the driver the still-FAILING tests (not just a score), so the next spawn targets the persistently-hard
6290
6305
  * cases. Swap `analysts` to change what the driver improves from — that's the one knob. */
@@ -6425,7 +6440,7 @@ async function superviseSurface(profile, task, opts) {
6425
6440
  maxIterations: (innerTurns + 2) * 5 + 16,
6426
6441
  maxTokens: 1e9
6427
6442
  };
6428
- const workerMaxTokens = profileMaxTokens(opts.worker.profile) ?? Math.max(1, Math.floor(budget.maxTokens / 8));
6443
+ const workerMaxTokens = Math.max(1, Math.floor(budget.maxTokens / 8));
6429
6444
  const makeWorkerAgent = (rawProfile) => {
6430
6445
  const p = rawProfile ?? {};
6431
6446
  return {
@@ -6470,12 +6485,6 @@ async function superviseSurface(profile, task, opts) {
6470
6485
  completions: sp.iterations
6471
6486
  };
6472
6487
  }
6473
- function profileMaxTokens(profile) {
6474
- const value = profile.model?.metadata?.maxTokens;
6475
- if (value === void 0) return void 0;
6476
- if (!Number.isSafeInteger(value) || value < 1) throw new Error("superviseSurface: AgentProfile.model.metadata.maxTokens must be a positive safe integer");
6477
- return value;
6478
- }
6479
6488
  //#endregion
6480
6489
  //#region src/runtime/surface-diff.ts
6481
6490
  /**
@@ -7089,6 +7098,6 @@ function tail(s) {
7089
7098
  return s.slice(-400);
7090
7099
  }
7091
7100
  //#endregion
7092
- export { runPersonified as $, pickChampion as A, stopSentinel as At, runBenchmark as B, connectStdioMcp as Bt, analyzeTrace as C, inlineSandboxClient as Ct, chatWorkerSeam as D, completionAuthorizes as Dt, chatTransportExecutor as E, superviseDispatch as Et, strategyAuthorContract as F, renderLeaderboardSvg as Ft, reconnectRetainedRun as G, mcpSecretEnvMetadataKey as Gt, reconnectRetainedInteractiveRun as H, createMcpEnvironment as Ht, strategyAuthorSystemPrompt as I, renderPairwiseMarkdown as It, startRetainedRunInEnvironment as J, secretEnvOfMcpServer as Jt, recoverRetainedRun as K, resolveMcpServerLaunch as Kt, SandboxRunAbortError as L, auditIntent as Lt, selectChampion as M, pairwiseSignificance as Mt, assertStrategyContract as N, renderLeaderboardHtml as Nt, createChatSessionStore as O, deterministicCompletion as Ot, authorStrategy as P, renderLeaderboardMarkdown as Pt, definePersona as Q, openSandboxRun as R, defaultAuditorInstruction as Rt, withUntrackedArtifacts as S, localSandboxClient as St, runCoderChecks as T, loopDispatch as Tt, recoverRetainedInteractiveRun as U, sanitizeMcpToolSchema as Ut, claimRetainedInteractiveControl as V, materializeLocalMcp as Vt, startRetainedInteractiveRun as W, envKeyProvider as Wt, equalKOnCost as X, promotionGate as Y, trajectoryReport as Z, VERIFY_TAIL_CHARS as _, registryScopeAnalyst as _t, localShell as a, renderCorpusToInstructions as at, settledWorkerOut as b, defineLeaderboard as bt, createVerifierEnvironment as c, loopUntil as ct, harvestSurfaceDiffs as d, selectValidWinner as dt, builtinShapes as et, failuresAnalyst as f, verify as ft, NOTE_MAX_CHARS as g, createScopeAnalyst as gt, EVIDENCE_MAX_CHARS as h, buildSteerContext as ht, jjWorkspace as i, InMemoryCorpus as it, runStrategyEvolution as j, leaderboard as jt, discriminatingMeans as k, sentinelCompletion as kt, boxSurfaceReader as l, panel as lt, worktreeFanout as m, assertTraceDerivedFindings as mt, makeFinding$1 as n, registerShape as nt, runInWorkspace as o, fanout as ot, superviseSurface as p, widen as pt, startRetainedRun as q, resolveSecretEnv as qt, gitWorkspace as r, FileCorpus as rt, createWaterfallCollector as s, flatWidenGate as st, computeFindingId$1 as t, createShapeRegistry as tt, fsSurfaceReader as u, pipeline as ut, closingWorkerNote as v, inProcessSandboxClient as vt, patchDelivered as w, loopCampaignDispatch as wt, copyUntrackedIntoClone as x, resolveSandboxClient as xt, composeWorkerEvidence as y, harvestCorpus as yt, printBenchmarkReport as z, McpSpawnFault as zt };
7101
+ export { definePersona as $, discriminatingMeans as A, sentinelCompletion as At, printBenchmarkReport as B, McpSpawnFault as Bt, withUntrackedArtifacts as C, localSandboxClient as Ct, chatTransportExecutor as D, superviseDispatch as Dt, runCoderChecks as E, loopDispatch as Et, authorStrategy as F, renderLeaderboardMarkdown as Ft, startRetainedInteractiveRun as G, envKeyProvider as Gt, claimRetainedInteractiveControl as H, materializeLocalMcp as Ht, strategyAuthorContract as I, renderLeaderboardSvg as It, startRetainedRun as J, resolveSecretEnv as Jt, reconnectRetainedRun as K, mcpSecretEnvMetadataKey as Kt, strategyAuthorSystemPrompt as L, renderPairwiseMarkdown as Lt, runStrategyEvolution as M, leaderboard as Mt, selectChampion as N, pairwiseSignificance as Nt, chatWorkerSeam as O, completionAuthorizes as Ot, assertStrategyContract as P, renderLeaderboardHtml as Pt, trajectoryReport as Q, SandboxRunAbortError as R, auditIntent as Rt, copyUntrackedIntoClone as S, resolveSandboxClient as St, patchDelivered as T, loopCampaignDispatch as Tt, reconnectRetainedInteractiveRun as U, createMcpEnvironment as Ut, runBenchmark as V, connectStdioMcp as Vt, recoverRetainedInteractiveRun as W, sanitizeMcpToolSchema as Wt, promotionGate as X, startRetainedRunInEnvironment as Y, secretEnvOfMcpServer as Yt, equalKOnCost as Z, NOTE_MAX_CHARS as _, createScopeAnalyst as _t, localShell as a, InMemoryCorpus as at, composeWorkerEvidence as b, harvestCorpus as bt, createVerifierEnvironment as c, flatWidenGate as ct, harvestSurfaceDiffs as d, pipeline as dt, runPersonified as et, analystsFromRegistry as f, selectValidWinner as ft, EVIDENCE_MAX_CHARS as g, buildSteerContext as gt, worktreeFanout as h, assertTraceDerivedFindings as ht, jjWorkspace as i, FileCorpus as it, pickChampion as j, stopSentinel as jt, createChatSessionStore as k, deterministicCompletion as kt, boxSurfaceReader as l, loopUntil as lt, superviseSurface as m, widen as mt, makeFinding$1 as n, createShapeRegistry as nt, runInWorkspace as o, renderCorpusToInstructions as ot, failuresAnalyst as p, verify as pt, recoverRetainedRun as q, resolveMcpServerLaunch as qt, gitWorkspace as r, registerShape as rt, createWaterfallCollector as s, fanout as st, computeFindingId$1 as t, builtinShapes as tt, fsSurfaceReader as u, panel as ut, VERIFY_TAIL_CHARS as v, registryScopeAnalyst as vt, analyzeTrace as w, inlineSandboxClient as wt, settledWorkerOut as x, defineLeaderboard as xt, closingWorkerNote as y, inProcessSandboxClient as yt, openSandboxRun as z, defaultAuditorInstruction as zt };
7093
7102
 
7094
- //# sourceMappingURL=runtime-DQs5xHdt.js.map
7103
+ //# sourceMappingURL=runtime-RY_rvv7t.js.map