@tangle-network/agent-runtime 0.277.0 → 0.280.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.
- package/dist/{activation-CbxhVtVV.js → activation-C97Cq4Q_.js} +2 -2
- package/dist/{activation-CbxhVtVV.js.map → activation-C97Cq4Q_.js.map} +1 -1
- package/dist/{activation-puw9_ahP.d.ts → activation-y-60DXF4.d.ts} +140 -105
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +2 -2
- package/dist/{coordination-driver-ZfUf-H4H.js → coordination-driver-CraAV-22.js} +2 -2
- package/dist/{coordination-driver-ZfUf-H4H.js.map → coordination-driver-CraAV-22.js.map} +1 -1
- package/dist/{delegate-DXOyzIq0.js → delegate-W1Ws_Wp0.js} +2 -2
- package/dist/{delegate-DXOyzIq0.js.map → delegate-W1Ws_Wp0.js.map} +1 -1
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +2 -2
- package/dist/{graph-sGWwXC6E.js → graph-DlL_X4HX.js} +4 -4
- package/dist/{graph-sGWwXC6E.js.map → graph-DlL_X4HX.js.map} +1 -1
- package/dist/{improvement-cycle-DQyN0__A.js → improvement-cycle-DXMU-2Y4.js} +649 -213
- package/dist/improvement-cycle-DXMU-2Y4.js.map +1 -0
- package/dist/{index-CmAFFnsd.d.ts → index-Dm8SHDGW.d.ts} +9 -7
- package/dist/index.d.ts +9 -9
- package/dist/index.js +55 -14
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +3 -3
- package/dist/intelligence.js +3 -3
- package/dist/kernel.d.ts +4 -4
- package/dist/kernel.js +8 -8
- package/dist/{loop-runner-bin-BTnEDWj3.js → loop-runner-bin-CT_-jSSg.js} +3 -3
- package/dist/{loop-runner-bin-BTnEDWj3.js.map → loop-runner-bin-CT_-jSSg.js.map} +1 -1
- package/dist/{loop-runner-bin-DGUASE9O.d.ts → loop-runner-bin-D6khQtoC.d.ts} +3 -3
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/index.js +4 -4
- package/dist/{openai-tools-Gc8p4PBq.d.ts → openai-tools-H8QPhTVE.d.ts} +2 -2
- package/dist/platform.d.ts +91 -1
- package/dist/platform.js +162 -6
- package/dist/platform.js.map +1 -1
- package/dist/profiles.d.ts +2 -2
- package/dist/{provision-supervisor-BgjtrTlv.js → provision-supervisor-BEmE95Mt.js} +3 -3
- package/dist/{provision-supervisor-BgjtrTlv.js.map → provision-supervisor-BEmE95Mt.js.map} +1 -1
- package/dist/{runtime-DoFvrisL.js → runtime-Du7j-nDD.js} +8 -8
- package/dist/{runtime-DoFvrisL.js.map → runtime-Du7j-nDD.js.map} +1 -1
- package/dist/{server-D2d83_iS.js → server-DZvGznAn.js} +3 -3
- package/dist/{server-D2d83_iS.js.map → server-DZvGznAn.js.map} +1 -1
- package/dist/{stream-agent-turn-BqU5Sfbw.d.ts → stream-agent-turn-Bk79CnTw.d.ts} +2 -2
- package/dist/{structural-rollout-VR-j5t9d.js → structural-rollout-Cl4TvomY.js} +2 -2
- package/dist/{structural-rollout-VR-j5t9d.js.map → structural-rollout-Cl4TvomY.js.map} +1 -1
- package/dist/{substrate-CfE3oUB9.d.ts → substrate-CHQ5GYnU.d.ts} +2 -2
- package/dist/{supervise-BoCOUAmr.js → supervise-CWrLq2-F.js} +25 -11
- package/dist/supervise-CWrLq2-F.js.map +1 -0
- package/dist/{supervisor-CjNbOcLO.js → supervisor-BXXjVCbW.js} +378 -110
- package/dist/supervisor-BXXjVCbW.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +12 -12
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/dist/{types-CI7ve2sA.d.ts → types-D56jQad-.d.ts} +70 -59
- package/package.json +10 -7
- package/dist/improvement-cycle-DQyN0__A.js.map +0 -1
- package/dist/supervise-BoCOUAmr.js.map +0 -1
- package/dist/supervisor-CjNbOcLO.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as verifyCanonicalCandidateDocument, C as canonicalCandidateDigest$1, D as immutableCandidateValue, w as canonicalCandidateDocument } from "./workspace-archive-C9lgf77y.js";
|
|
2
|
-
import { A as agentImprovementTargetInput, M as agentProfileImprovementStateDigest, c as requireSealedCandidateExperiment, d as verifyAgentImprovementActivation, f as verifyAgentImprovementProposal, k as agentImprovementTargetDigest } from "./improvement-cycle-
|
|
2
|
+
import { A as agentImprovementTargetInput, M as agentProfileImprovementStateDigest, c as requireSealedCandidateExperiment, d as verifyAgentImprovementActivation, f as verifyAgentImprovementProposal, k as agentImprovementTargetDigest } from "./improvement-cycle-DXMU-2Y4.js";
|
|
3
3
|
import { agentImprovementActivationResultSchema, agentImprovementActivationSchema, agentProfileImprovementExperimentSchema } from "@tangle-network/agent-interface";
|
|
4
4
|
//#region src/runtime-usage.ts
|
|
5
5
|
function createRuntimeUsageTotals() {
|
|
@@ -231,4 +231,4 @@ function targetIdentity(target) {
|
|
|
231
231
|
//#endregion
|
|
232
232
|
export { createRuntimeUsageTotals as a, addRuntimeUsage as i, executeAgentImprovementActivation as n, isUsageAmount as o, verifyAgentImprovementActivationResult as r, createAgentImprovementActivationResult as t };
|
|
233
233
|
|
|
234
|
-
//# sourceMappingURL=activation-
|
|
234
|
+
//# sourceMappingURL=activation-C97Cq4Q_.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activation-CbxhVtVV.js","names":["canonicalCandidateDigest"],"sources":["../src/runtime-usage.ts","../src/intelligence/activation.ts"],"sourcesContent":["import type { RuntimeStreamEvent } from './types'\n\n/** Observed subtotals, with missing measurements kept separate from measured zeroes. */\nexport interface RuntimeUsageTotals {\n /** Observed input tokens across normalized per-call events. */\n tokensIn: number\n /** Observed output tokens across normalized per-call events. */\n tokensOut: number\n /** Observed dollar subtotal; incomplete when `usdKnown` is false. */\n costUsd: number\n /** Number of observed model calls, including unpriced or incompletely metered calls. */\n llmCalls: number\n /** False when any observed call has incomplete token usage. */\n tokensKnown?: false\n /** False when any observed call lacks complete provider-billed cost. */\n usdKnown?: false\n /** Sum of reported external estimates; never included in `costUsd` or proof of complete cost. */\n estimatedCostUsd?: number\n}\n\nexport function createRuntimeUsageTotals(): RuntimeUsageTotals {\n return { tokensIn: 0, tokensOut: 0, costUsd: 0, llmCalls: 0 }\n}\n\nexport function isUsageAmount(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n}\n\n/** Fold normalized per-call events. Backend adapters own cumulative receipt reconciliation. */\nexport function addRuntimeUsage(\n totals: RuntimeUsageTotals,\n event: Extract<RuntimeStreamEvent, { type: 'llm_call' }>,\n): void {\n totals.llmCalls += 1\n for (const key of ['tokensIn', 'tokensOut', 'costUsd'] as const) {\n const value = event[key]\n if (isUsageAmount(value)) totals[key] += value\n else if (key === 'costUsd') totals.usdKnown = false\n else totals.tokensKnown = false\n }\n if (event.tokensKnown === false) totals.tokensKnown = false\n if (event.usdKnown === false) totals.usdKnown = false\n if (isUsageAmount(event.estimatedCostUsd)) {\n totals.estimatedCostUsd = (totals.estimatedCostUsd ?? 0) + event.estimatedCostUsd\n }\n}\n","import type {\n AgentCandidateBundle,\n AgentCandidateExperiment,\n AgentImprovementActivation,\n AgentImprovementActivationOutcome,\n AgentImprovementActivationResult,\n AgentImprovementActivationTarget,\n AgentImprovementProposal,\n AgentImprovementReview,\n AgentImprovementSurface,\n AgentProfileImprovementChange,\n AgentProfileImprovementExperiment,\n Sha256Digest,\n} from '@tangle-network/agent-interface'\nimport {\n agentImprovementActivationResultSchema,\n agentImprovementActivationSchema,\n agentProfileImprovementExperimentSchema,\n} from '@tangle-network/agent-interface'\n\nimport {\n canonicalCandidateDigest,\n canonicalCandidateDocument,\n immutableCandidateValue,\n verifyCanonicalCandidateDocument,\n} from '../candidate-execution/digest'\nimport {\n requireSealedCandidateExperiment,\n verifyAgentImprovementActivation,\n verifyAgentImprovementProposal,\n} from './improvement-cycle'\nimport {\n agentImprovementTargetDigest,\n agentImprovementTargetInput,\n agentProfileImprovementStateDigest,\n} from './improvement-surfaces'\n\nexport interface CreateAgentImprovementActivationResultOptions {\n completedAt: string\n outcome: AgentImprovementActivationOutcome\n}\n\nexport interface AgentImprovementActivationTargetPlan extends AgentImprovementActivationTarget {\n desiredDigest: Sha256Digest\n /**\n * Exact measured input the product must apply to reach `desiredDigest`.\n * Transition surfaces such as code and knowledge are applied operations, so\n * their resulting state digest is not the digest of this input document.\n */\n desiredInput: unknown\n}\n\nexport type AgentProfileImprovementActivationOperation =\n | {\n kind: 'apply-change'\n changes: AgentProfileImprovementChange\n }\n | {\n /** The product must load its own saved state at `desiredStateDigest`. */\n kind: 'restore-state'\n }\n\nexport interface AgentProfileImprovementActivationTargetPlan\n extends AgentImprovementActivationTarget {\n desiredDigest: Sha256Digest\n desiredInput: AgentProfileImprovementActivationOperation\n}\n\nexport interface SealedCandidateActivationTransitionInput {\n kind: 'sealed-candidate'\n activation: AgentImprovementActivation\n candidateBundle: AgentCandidateBundle\n bundle: AgentCandidateBundle\n targets: [AgentImprovementActivationTargetPlan, ...AgentImprovementActivationTargetPlan[]]\n attemptedAt: string\n expired: boolean\n}\n\n/**\n * A measured profile change without raw profile bytes.\n * The product owns the private state lookup and atomic write.\n */\nexport interface ProfileImprovementActivationTransitionInput {\n kind: 'profile-improvement'\n activation: AgentImprovementActivation\n experiment: AgentProfileImprovementExperiment\n sourceStateDigest: Sha256Digest\n desiredStateDigest: Sha256Digest\n operation: AgentProfileImprovementActivationOperation\n targets: [\n AgentProfileImprovementActivationTargetPlan,\n ...AgentProfileImprovementActivationTargetPlan[],\n ]\n attemptedAt: string\n expired: boolean\n}\n\nexport type AgentImprovementActivationTransitionInput =\n | SealedCandidateActivationTransitionInput\n | ProfileImprovementActivationTransitionInput\n\nexport interface AgentImprovementActivationResultStore {\n load(idempotencyKey: Sha256Digest): Promise<unknown | undefined>\n putIfAbsent(result: AgentImprovementActivationResult): Promise<unknown>\n}\n\n/**\n * Product-owned or Runtime-composed transition.\n *\n * Implementations resolve a stored result for `activation.digest`, compare\n * every target, and make the write durably idempotent. Co-located targets store\n * the all-or-none write with its result. Other targets throw when result\n * storage fails so a retry can reconcile it. Runtime never invokes this write\n * function after authorization expires.\n */\nexport type AgentImprovementActivationTransition = (\n input: AgentImprovementActivationTransitionInput,\n) => Promise<unknown>\n\n/**\n * Target-read-only check for a prior exact write.\n * It may persist recovered result metadata, but must not change an activation target.\n * Return undefined only when no target write can have committed.\n */\nexport type AgentImprovementActivationReconciliation = (\n input: AgentImprovementActivationTransitionInput,\n) => Promise<unknown | undefined>\n\nexport interface ExecuteAgentImprovementActivationInput {\n proposal: AgentImprovementProposal\n review: AgentImprovementReview\n activation: AgentImprovementActivation\n}\n\nexport interface ExecuteAgentImprovementActivationOptions {\n transition: AgentImprovementActivationTransition\n reconcile?: AgentImprovementActivationReconciliation\n now?: () => Date\n}\n\n/** Create the exact result a product stores in the same transaction as its target write. */\nexport function createAgentImprovementActivationResult(\n transition: AgentImprovementActivationTransitionInput,\n options: CreateAgentImprovementActivationResultOptions,\n): AgentImprovementActivationResult {\n const activation = verifyCanonicalCandidateDocument(\n agentImprovementActivationSchema.parse(transition.activation),\n 'agent improvement activation',\n )\n assertTransitionInput(activation, transition)\n const result = agentImprovementActivationResultSchema.parse(\n canonicalCandidateDocument<AgentImprovementActivationResult>({\n kind: 'agent-improvement-activation-result',\n idempotencyKey: activation.digest,\n attemptedAt: transition.attemptedAt,\n completedAt: options.completedAt,\n outcome: options.outcome,\n }).value,\n )\n assertResultAgainstActivation(activation, result)\n assertOutcomeDesiredState(\n activation,\n result,\n new Map(transition.targets.map((target) => [targetIdentity(target), target.desiredDigest])),\n )\n return immutableCandidateValue(result)\n}\n\n/**\n * Recompute one historical activation result against the exact measured proposal and authority.\n * The result records that attempt; it is not a query of the target's current state.\n */\nexport function verifyAgentImprovementActivationResult(input: {\n proposal: unknown\n review: unknown\n activation: unknown\n result: unknown\n}): AgentImprovementActivationResult {\n const proposal = verifyAgentImprovementProposal(input.proposal)\n const activation = verifyAgentImprovementActivation(input)\n const result = verifyCanonicalCandidateDocument(\n agentImprovementActivationResultSchema.parse(input.result),\n 'agent improvement activation result',\n )\n assertResultAgainstActivation(activation, result)\n assertResultDesiredState(proposal, activation, result)\n return result\n}\n\n/** Validate and execute one product-owned activation transition. */\nexport async function executeAgentImprovementActivation(\n input: ExecuteAgentImprovementActivationInput,\n options: ExecuteAgentImprovementActivationOptions,\n): Promise<AgentImprovementActivationResult> {\n const proposal = verifyAgentImprovementProposal(input.proposal)\n const activation = verifyAgentImprovementActivation(input)\n const observedAt = (options.now ?? (() => new Date()))().toISOString()\n const attemptedAt =\n Date.parse(observedAt) < Date.parse(activation.authorizedAt)\n ? activation.authorizedAt\n : observedAt\n const expired = Date.parse(attemptedAt) >= Date.parse(activation.expiresAt)\n const transition = immutableCandidateValue<AgentImprovementActivationTransitionInput>(\n proposal.evaluation.kind === 'agent-improvement-measured-comparison'\n ? sealedCandidateTransition(proposal.evaluation.experiment, activation, attemptedAt, expired)\n : profileImprovementTransition(\n proposal.evaluation.experiment,\n activation,\n attemptedAt,\n expired,\n ),\n )\n\n if (transition.expired) {\n if (!options.reconcile) {\n return uncertainActivationResult(transition, 'RECONCILIATION_UNAVAILABLE')\n }\n let reconciled: unknown\n try {\n reconciled = await options.reconcile(transition)\n } catch {\n return uncertainActivationResult(transition, 'RECONCILIATION_THROW')\n }\n if (reconciled === undefined) {\n return createAgentImprovementActivationResult(transition, {\n completedAt: transition.attemptedAt,\n outcome: { status: 'expired' },\n })\n }\n try {\n return verifyAgentImprovementActivationResult({ ...input, result: reconciled })\n } catch {\n return uncertainActivationResult(transition, 'INVALID_RECONCILIATION')\n }\n }\n\n let rawResult: unknown\n try {\n rawResult = await options.transition(transition)\n } catch {\n return uncertainActivationResult(transition, 'TRANSITION_THROW')\n }\n try {\n return verifyAgentImprovementActivationResult({ ...input, result: rawResult })\n } catch {\n return uncertainActivationResult(transition, 'INVALID_RESULT')\n }\n}\n\nfunction sealedCandidateTransition(\n experiment: AgentCandidateExperiment,\n activation: AgentImprovementActivation,\n attemptedAt: string,\n expired: boolean,\n): SealedCandidateActivationTransitionInput {\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n return {\n kind: 'sealed-candidate',\n activation,\n candidateBundle: experiment.candidate,\n bundle: experiment[targetArm],\n targets: activation.targets.map((target) => ({\n ...target,\n desiredDigest: agentImprovementTargetDigest(experiment, targetArm, target.surface),\n desiredInput: agentImprovementTargetInput(experiment[targetArm], target.surface),\n })) as SealedCandidateActivationTransitionInput['targets'],\n attemptedAt,\n expired,\n }\n}\n\nfunction profileImprovementTransition(\n experiment: AgentProfileImprovementExperiment,\n activation: AgentImprovementActivation,\n attemptedAt: string,\n expired: boolean,\n): ProfileImprovementActivationTransitionInput {\n const sourceArm = activation.intent === 'activate-candidate' ? 'baseline' : 'candidate'\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n const operation = profileImprovementOperation(experiment, activation.intent)\n return {\n kind: 'profile-improvement',\n activation,\n experiment,\n sourceStateDigest: agentProfileImprovementStateDigest(experiment, sourceArm),\n desiredStateDigest: agentProfileImprovementStateDigest(experiment, targetArm),\n operation,\n targets: activation.targets.map((target) => ({\n ...target,\n desiredDigest: agentProfileImprovementStateDigest(experiment, targetArm),\n desiredInput: operation,\n })) as ProfileImprovementActivationTransitionInput['targets'],\n attemptedAt,\n expired,\n }\n}\n\nfunction profileImprovementOperation(\n experiment: AgentProfileImprovementExperiment,\n intent: AgentImprovementActivation['intent'],\n): AgentProfileImprovementActivationOperation {\n return intent === 'activate-candidate'\n ? { kind: 'apply-change', changes: experiment.change }\n : { kind: 'restore-state' }\n}\n\nfunction uncertainActivationResult(\n transition: AgentImprovementActivationTransitionInput,\n code: string,\n): AgentImprovementActivationResult {\n return createAgentImprovementActivationResult(transition, {\n completedAt: transition.attemptedAt,\n outcome: {\n status: 'indeterminate',\n code,\n message: 'The product transition did not return a trustworthy commit result.',\n },\n })\n}\n\nfunction assertTransitionInput(\n activation: AgentImprovementActivation,\n transition: AgentImprovementActivationTransitionInput,\n): void {\n if (transition.kind === 'sealed-candidate') {\n assertSealedCandidateTransitionInput(activation, transition)\n return\n }\n assertProfileImprovementTransitionInput(activation, transition)\n}\n\nfunction assertSealedCandidateTransitionInput(\n activation: AgentImprovementActivation,\n transition: SealedCandidateActivationTransitionInput,\n): void {\n assertAuthorizedTransitionTargets(activation, transition.targets)\n const desiredInputsMatch = transition.targets.every(\n (target) =>\n canonicalCandidateDigest(target.desiredInput) ===\n canonicalCandidateDigest(agentImprovementTargetInput(transition.bundle, target.surface)),\n )\n if (\n transition.expired !== Date.parse(transition.attemptedAt) >= Date.parse(activation.expiresAt) ||\n transition.candidateBundle.digest !== activation.candidateDigest ||\n !desiredInputsMatch ||\n (activation.intent === 'activate-candidate' &&\n transition.bundle.digest !== transition.candidateBundle.digest)\n ) {\n throw new Error('activation transition does not match its authorization')\n }\n}\n\nfunction assertProfileImprovementTransitionInput(\n activation: AgentImprovementActivation,\n transition: ProfileImprovementActivationTransitionInput,\n): void {\n assertAuthorizedTransitionTargets(activation, transition.targets)\n const targetsAgentProfile = activation.targets.some(\n (target) => target.surface === 'agent-profile',\n )\n const experiment = agentProfileImprovementExperimentSchema.parse(transition.experiment)\n const sourceArm = activation.intent === 'activate-candidate' ? 'baseline' : 'candidate'\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n const sourceStateDigest = agentProfileImprovementStateDigest(experiment, sourceArm)\n const desiredStateDigest = agentProfileImprovementStateDigest(experiment, targetArm)\n const operation = profileImprovementOperation(experiment, activation.intent)\n const targetsMatch = transition.targets.every(\n (target) =>\n target.expectedBaseDigest === sourceStateDigest &&\n target.desiredDigest === desiredStateDigest &&\n canonicalCandidateDigest(target.desiredInput) === canonicalCandidateDigest(operation),\n )\n if (\n transition.expired !== Date.parse(transition.attemptedAt) >= Date.parse(activation.expiresAt) ||\n experiment.digest !== activation.experimentDigest ||\n experiment.candidate.stateDigest !== activation.candidateDigest ||\n (targetsAgentProfile &&\n (activation.executionRef === undefined ||\n canonicalCandidateDigest(activation.executionRef) !==\n canonicalCandidateDigest(experiment.executionRef))) ||\n transition.sourceStateDigest !== sourceStateDigest ||\n transition.desiredStateDigest !== desiredStateDigest ||\n canonicalCandidateDigest(transition.operation) !== canonicalCandidateDigest(operation) ||\n !targetsMatch\n ) {\n throw new Error('activation transition does not match its authorization')\n }\n}\n\nfunction assertAuthorizedTransitionTargets(\n activation: AgentImprovementActivation,\n targets: readonly AgentImprovementActivationTargetPlan[],\n): void {\n const authorized = targetMap(activation.targets)\n const planned = targetMap(targets)\n if (\n authorized.size !== planned.size ||\n [...authorized.entries()].some(\n ([identity, target]) =>\n planned.get(identity)?.expectedBaseDigest !== target.expectedBaseDigest,\n )\n ) {\n throw new Error('activation transition does not match its authorization')\n }\n}\n\nfunction assertResultAgainstActivation(\n activation: AgentImprovementActivation,\n result: AgentImprovementActivationResult,\n): void {\n const attemptedAt = Date.parse(result.attemptedAt)\n const completedAt = Date.parse(result.completedAt)\n const expiresAt = Date.parse(activation.expiresAt)\n if (\n result.idempotencyKey !== activation.digest ||\n attemptedAt < Date.parse(activation.authorizedAt) ||\n completedAt < attemptedAt\n ) {\n throw new Error('activation result does not bind its authorization')\n }\n const expired = attemptedAt >= expiresAt\n if (\n (result.outcome.status === 'expired' && !expired) ||\n (expired && !['expired', 'indeterminate', 'already-applied'].includes(result.outcome.status))\n ) {\n throw new Error('activation result does not honor its authorization expiry')\n }\n if (!('targets' in result.outcome)) return\n const authorized = targetMap(activation.targets)\n const observed = new Set(result.outcome.targets.map(targetIdentity))\n if (\n authorized.size !== observed.size ||\n [...authorized.keys()].some((identity) => !observed.has(identity))\n ) {\n throw new Error('activation result must cover every authorized target exactly once')\n }\n if (\n result.outcome.status === 'applied' &&\n result.outcome.targets.some(\n (target) =>\n target.beforeDigest !== authorized.get(targetIdentity(target))?.expectedBaseDigest,\n )\n ) {\n throw new Error('applied activation did not start from its authorized base state')\n }\n}\n\nfunction assertResultDesiredState(\n proposal: AgentImprovementProposal,\n activation: AgentImprovementActivation,\n result: AgentImprovementActivationResult,\n): void {\n if (!('targets' in result.outcome)) return\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n const desiredStateDigest =\n proposal.evaluation.kind === 'agent-profile-improvement-measured-comparison'\n ? agentProfileImprovementStateDigest(proposal.evaluation.experiment, targetArm)\n : undefined\n const desired = new Map(\n activation.targets.map((target) => [\n targetIdentity(target),\n desiredStateDigest ??\n agentImprovementTargetDigest(\n requireSealedCandidateExperiment(proposal),\n targetArm,\n target.surface,\n ),\n ]),\n )\n assertOutcomeDesiredState(activation, result, desired)\n}\n\nfunction assertOutcomeDesiredState(\n activation: AgentImprovementActivation,\n result: AgentImprovementActivationResult,\n desired: ReadonlyMap<string, Sha256Digest>,\n): void {\n if (!('targets' in result.outcome)) return\n if (result.outcome.status === 'applied') {\n if (\n result.outcome.targets.some(\n (target) => target.afterDigest !== desired.get(targetIdentity(target)),\n )\n ) {\n throw new Error('applied activation does not match the requested bundle')\n }\n return\n }\n const allDesired = result.outcome.targets.every(\n (target) => target.currentDigest === desired.get(targetIdentity(target)),\n )\n if (result.outcome.status === 'already-applied') {\n if (!allDesired) throw new Error('already-applied activation is not at the requested state')\n return\n }\n const authorized = targetMap(activation.targets)\n const hasStaleTarget = result.outcome.targets.some(\n (target) => target.currentDigest !== authorized.get(targetIdentity(target))?.expectedBaseDigest,\n )\n if (allDesired || !hasStaleTarget) {\n throw new Error('activation conflict does not identify stale target state')\n }\n}\n\nfunction targetMap<T extends { surface: AgentImprovementSurface; identity: string }>(\n targets: readonly T[],\n): Map<string, T> {\n return new Map(targets.map((target) => [targetIdentity(target), target]))\n}\n\nfunction targetIdentity(target: { surface: AgentImprovementSurface; identity: string }): string {\n return `${target.surface}\\u0000${target.identity}`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icalCandidateDigest"],"sources":["../src/runtime-usage.ts","../src/intelligence/activation.ts"],"sourcesContent":["import type { RuntimeStreamEvent } from './types'\n\n/** Observed subtotals, with missing measurements kept separate from measured zeroes. */\nexport interface RuntimeUsageTotals {\n /** Observed input tokens across normalized per-call events. */\n tokensIn: number\n /** Observed output tokens across normalized per-call events. */\n tokensOut: number\n /** Observed dollar subtotal; incomplete when `usdKnown` is false. */\n costUsd: number\n /** Number of observed model calls, including unpriced or incompletely metered calls. */\n llmCalls: number\n /** False when any observed call has incomplete token usage. */\n tokensKnown?: false\n /** False when any observed call lacks complete provider-billed cost. */\n usdKnown?: false\n /** Sum of reported external estimates; never included in `costUsd` or proof of complete cost. */\n estimatedCostUsd?: number\n}\n\nexport function createRuntimeUsageTotals(): RuntimeUsageTotals {\n return { tokensIn: 0, tokensOut: 0, costUsd: 0, llmCalls: 0 }\n}\n\nexport function isUsageAmount(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n}\n\n/** Fold normalized per-call events. Backend adapters own cumulative receipt reconciliation. */\nexport function addRuntimeUsage(\n totals: RuntimeUsageTotals,\n event: Extract<RuntimeStreamEvent, { type: 'llm_call' }>,\n): void {\n totals.llmCalls += 1\n for (const key of ['tokensIn', 'tokensOut', 'costUsd'] as const) {\n const value = event[key]\n if (isUsageAmount(value)) totals[key] += value\n else if (key === 'costUsd') totals.usdKnown = false\n else totals.tokensKnown = false\n }\n if (event.tokensKnown === false) totals.tokensKnown = false\n if (event.usdKnown === false) totals.usdKnown = false\n if (isUsageAmount(event.estimatedCostUsd)) {\n totals.estimatedCostUsd = (totals.estimatedCostUsd ?? 0) + event.estimatedCostUsd\n }\n}\n","import type {\n AgentCandidateBundle,\n AgentCandidateExperiment,\n AgentImprovementActivation,\n AgentImprovementActivationOutcome,\n AgentImprovementActivationResult,\n AgentImprovementActivationTarget,\n AgentImprovementProposal,\n AgentImprovementReview,\n AgentImprovementSurface,\n AgentProfileImprovementChange,\n AgentProfileImprovementExperiment,\n Sha256Digest,\n} from '@tangle-network/agent-interface'\nimport {\n agentImprovementActivationResultSchema,\n agentImprovementActivationSchema,\n agentProfileImprovementExperimentSchema,\n} from '@tangle-network/agent-interface'\n\nimport {\n canonicalCandidateDigest,\n canonicalCandidateDocument,\n immutableCandidateValue,\n verifyCanonicalCandidateDocument,\n} from '../candidate-execution/digest'\nimport {\n requireSealedCandidateExperiment,\n verifyAgentImprovementActivation,\n verifyAgentImprovementProposal,\n} from './improvement-cycle'\nimport {\n agentImprovementTargetDigest,\n agentImprovementTargetInput,\n agentProfileImprovementStateDigest,\n} from './improvement-surfaces'\n\nexport interface CreateAgentImprovementActivationResultOptions {\n completedAt: string\n outcome: AgentImprovementActivationOutcome\n}\n\nexport interface AgentImprovementActivationTargetPlan extends AgentImprovementActivationTarget {\n desiredDigest: Sha256Digest\n /**\n * Exact measured input the product must apply to reach `desiredDigest`.\n * Transition surfaces such as code and knowledge are applied operations, so\n * their resulting state digest is not the digest of this input document.\n */\n desiredInput: unknown\n}\n\nexport type AgentProfileImprovementActivationOperation =\n | {\n kind: 'apply-change'\n changes: AgentProfileImprovementChange\n }\n | {\n /** The product must load its own saved state at `desiredStateDigest`. */\n kind: 'restore-state'\n }\n\nexport interface AgentProfileImprovementActivationTargetPlan\n extends AgentImprovementActivationTarget {\n desiredDigest: Sha256Digest\n desiredInput: AgentProfileImprovementActivationOperation\n}\n\nexport interface SealedCandidateActivationTransitionInput {\n kind: 'sealed-candidate'\n activation: AgentImprovementActivation\n candidateBundle: AgentCandidateBundle\n bundle: AgentCandidateBundle\n targets: [AgentImprovementActivationTargetPlan, ...AgentImprovementActivationTargetPlan[]]\n attemptedAt: string\n expired: boolean\n}\n\n/**\n * A measured profile change without raw profile bytes.\n * The product owns the private state lookup and atomic write.\n */\nexport interface ProfileImprovementActivationTransitionInput {\n kind: 'profile-improvement'\n activation: AgentImprovementActivation\n experiment: AgentProfileImprovementExperiment\n sourceStateDigest: Sha256Digest\n desiredStateDigest: Sha256Digest\n operation: AgentProfileImprovementActivationOperation\n targets: [\n AgentProfileImprovementActivationTargetPlan,\n ...AgentProfileImprovementActivationTargetPlan[],\n ]\n attemptedAt: string\n expired: boolean\n}\n\nexport type AgentImprovementActivationTransitionInput =\n | SealedCandidateActivationTransitionInput\n | ProfileImprovementActivationTransitionInput\n\nexport interface AgentImprovementActivationResultStore {\n load(idempotencyKey: Sha256Digest): Promise<unknown | undefined>\n putIfAbsent(result: AgentImprovementActivationResult): Promise<unknown>\n}\n\n/**\n * Product-owned or Runtime-composed transition.\n *\n * Implementations resolve a stored result for `activation.digest`, compare\n * every target, and make the write durably idempotent. Co-located targets store\n * the all-or-none write with its result. Other targets throw when result\n * storage fails so a retry can reconcile it. Runtime never invokes this write\n * function after authorization expires.\n */\nexport type AgentImprovementActivationTransition = (\n input: AgentImprovementActivationTransitionInput,\n) => Promise<unknown>\n\n/**\n * Target-read-only check for a prior exact write.\n * It may persist recovered result metadata, but must not change an activation target.\n * Return undefined only when no target write can have committed.\n */\nexport type AgentImprovementActivationReconciliation = (\n input: AgentImprovementActivationTransitionInput,\n) => Promise<unknown | undefined>\n\nexport interface ExecuteAgentImprovementActivationInput {\n proposal: AgentImprovementProposal\n review: AgentImprovementReview\n activation: AgentImprovementActivation\n}\n\nexport interface ExecuteAgentImprovementActivationOptions {\n transition: AgentImprovementActivationTransition\n reconcile?: AgentImprovementActivationReconciliation\n now?: () => Date\n}\n\n/** Create the exact result a product stores in the same transaction as its target write. */\nexport function createAgentImprovementActivationResult(\n transition: AgentImprovementActivationTransitionInput,\n options: CreateAgentImprovementActivationResultOptions,\n): AgentImprovementActivationResult {\n const activation = verifyCanonicalCandidateDocument(\n agentImprovementActivationSchema.parse(transition.activation),\n 'agent improvement activation',\n )\n assertTransitionInput(activation, transition)\n const result = agentImprovementActivationResultSchema.parse(\n canonicalCandidateDocument<AgentImprovementActivationResult>({\n kind: 'agent-improvement-activation-result',\n idempotencyKey: activation.digest,\n attemptedAt: transition.attemptedAt,\n completedAt: options.completedAt,\n outcome: options.outcome,\n }).value,\n )\n assertResultAgainstActivation(activation, result)\n assertOutcomeDesiredState(\n activation,\n result,\n new Map(transition.targets.map((target) => [targetIdentity(target), target.desiredDigest])),\n )\n return immutableCandidateValue(result)\n}\n\n/**\n * Recompute one historical activation result against the exact measured proposal and authority.\n * The result records that attempt; it is not a query of the target's current state.\n */\nexport function verifyAgentImprovementActivationResult(input: {\n proposal: unknown\n review: unknown\n activation: unknown\n result: unknown\n}): AgentImprovementActivationResult {\n const proposal = verifyAgentImprovementProposal(input.proposal)\n const activation = verifyAgentImprovementActivation(input)\n const result = verifyCanonicalCandidateDocument(\n agentImprovementActivationResultSchema.parse(input.result),\n 'agent improvement activation result',\n )\n assertResultAgainstActivation(activation, result)\n assertResultDesiredState(proposal, activation, result)\n return result\n}\n\n/** Validate and execute one product-owned activation transition. */\nexport async function executeAgentImprovementActivation(\n input: ExecuteAgentImprovementActivationInput,\n options: ExecuteAgentImprovementActivationOptions,\n): Promise<AgentImprovementActivationResult> {\n const proposal = verifyAgentImprovementProposal(input.proposal)\n const activation = verifyAgentImprovementActivation(input)\n const observedAt = (options.now ?? (() => new Date()))().toISOString()\n const attemptedAt =\n Date.parse(observedAt) < Date.parse(activation.authorizedAt)\n ? activation.authorizedAt\n : observedAt\n const expired = Date.parse(attemptedAt) >= Date.parse(activation.expiresAt)\n const transition = immutableCandidateValue<AgentImprovementActivationTransitionInput>(\n proposal.evaluation.kind === 'agent-improvement-measured-comparison'\n ? sealedCandidateTransition(proposal.evaluation.experiment, activation, attemptedAt, expired)\n : profileImprovementTransition(\n proposal.evaluation.experiment,\n activation,\n attemptedAt,\n expired,\n ),\n )\n\n if (transition.expired) {\n if (!options.reconcile) {\n return uncertainActivationResult(transition, 'RECONCILIATION_UNAVAILABLE')\n }\n let reconciled: unknown\n try {\n reconciled = await options.reconcile(transition)\n } catch {\n return uncertainActivationResult(transition, 'RECONCILIATION_THROW')\n }\n if (reconciled === undefined) {\n return createAgentImprovementActivationResult(transition, {\n completedAt: transition.attemptedAt,\n outcome: { status: 'expired' },\n })\n }\n try {\n return verifyAgentImprovementActivationResult({ ...input, result: reconciled })\n } catch {\n return uncertainActivationResult(transition, 'INVALID_RECONCILIATION')\n }\n }\n\n let rawResult: unknown\n try {\n rawResult = await options.transition(transition)\n } catch {\n return uncertainActivationResult(transition, 'TRANSITION_THROW')\n }\n try {\n return verifyAgentImprovementActivationResult({ ...input, result: rawResult })\n } catch {\n return uncertainActivationResult(transition, 'INVALID_RESULT')\n }\n}\n\nfunction sealedCandidateTransition(\n experiment: AgentCandidateExperiment,\n activation: AgentImprovementActivation,\n attemptedAt: string,\n expired: boolean,\n): SealedCandidateActivationTransitionInput {\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n return {\n kind: 'sealed-candidate',\n activation,\n candidateBundle: experiment.candidate,\n bundle: experiment[targetArm],\n targets: activation.targets.map((target) => ({\n ...target,\n desiredDigest: agentImprovementTargetDigest(experiment, targetArm, target.surface),\n desiredInput: agentImprovementTargetInput(experiment[targetArm], target.surface),\n })) as SealedCandidateActivationTransitionInput['targets'],\n attemptedAt,\n expired,\n }\n}\n\nfunction profileImprovementTransition(\n experiment: AgentProfileImprovementExperiment,\n activation: AgentImprovementActivation,\n attemptedAt: string,\n expired: boolean,\n): ProfileImprovementActivationTransitionInput {\n const sourceArm = activation.intent === 'activate-candidate' ? 'baseline' : 'candidate'\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n const operation = profileImprovementOperation(experiment, activation.intent)\n return {\n kind: 'profile-improvement',\n activation,\n experiment,\n sourceStateDigest: agentProfileImprovementStateDigest(experiment, sourceArm),\n desiredStateDigest: agentProfileImprovementStateDigest(experiment, targetArm),\n operation,\n targets: activation.targets.map((target) => ({\n ...target,\n desiredDigest: agentProfileImprovementStateDigest(experiment, targetArm),\n desiredInput: operation,\n })) as ProfileImprovementActivationTransitionInput['targets'],\n attemptedAt,\n expired,\n }\n}\n\nfunction profileImprovementOperation(\n experiment: AgentProfileImprovementExperiment,\n intent: AgentImprovementActivation['intent'],\n): AgentProfileImprovementActivationOperation {\n return intent === 'activate-candidate'\n ? { kind: 'apply-change', changes: experiment.change }\n : { kind: 'restore-state' }\n}\n\nfunction uncertainActivationResult(\n transition: AgentImprovementActivationTransitionInput,\n code: string,\n): AgentImprovementActivationResult {\n return createAgentImprovementActivationResult(transition, {\n completedAt: transition.attemptedAt,\n outcome: {\n status: 'indeterminate',\n code,\n message: 'The product transition did not return a trustworthy commit result.',\n },\n })\n}\n\nfunction assertTransitionInput(\n activation: AgentImprovementActivation,\n transition: AgentImprovementActivationTransitionInput,\n): void {\n if (transition.kind === 'sealed-candidate') {\n assertSealedCandidateTransitionInput(activation, transition)\n return\n }\n assertProfileImprovementTransitionInput(activation, transition)\n}\n\nfunction assertSealedCandidateTransitionInput(\n activation: AgentImprovementActivation,\n transition: SealedCandidateActivationTransitionInput,\n): void {\n assertAuthorizedTransitionTargets(activation, transition.targets)\n const desiredInputsMatch = transition.targets.every(\n (target) =>\n canonicalCandidateDigest(target.desiredInput) ===\n canonicalCandidateDigest(agentImprovementTargetInput(transition.bundle, target.surface)),\n )\n if (\n transition.expired !== Date.parse(transition.attemptedAt) >= Date.parse(activation.expiresAt) ||\n transition.candidateBundle.digest !== activation.candidateDigest ||\n !desiredInputsMatch ||\n (activation.intent === 'activate-candidate' &&\n transition.bundle.digest !== transition.candidateBundle.digest)\n ) {\n throw new Error('activation transition does not match its authorization')\n }\n}\n\nfunction assertProfileImprovementTransitionInput(\n activation: AgentImprovementActivation,\n transition: ProfileImprovementActivationTransitionInput,\n): void {\n assertAuthorizedTransitionTargets(activation, transition.targets)\n const targetsAgentProfile = activation.targets.some(\n (target) => target.surface === 'agent-profile',\n )\n const experiment = agentProfileImprovementExperimentSchema.parse(transition.experiment)\n const sourceArm = activation.intent === 'activate-candidate' ? 'baseline' : 'candidate'\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n const sourceStateDigest = agentProfileImprovementStateDigest(experiment, sourceArm)\n const desiredStateDigest = agentProfileImprovementStateDigest(experiment, targetArm)\n const operation = profileImprovementOperation(experiment, activation.intent)\n const targetsMatch = transition.targets.every(\n (target) =>\n target.expectedBaseDigest === sourceStateDigest &&\n target.desiredDigest === desiredStateDigest &&\n canonicalCandidateDigest(target.desiredInput) === canonicalCandidateDigest(operation),\n )\n if (\n transition.expired !== Date.parse(transition.attemptedAt) >= Date.parse(activation.expiresAt) ||\n experiment.digest !== activation.experimentDigest ||\n experiment.candidate.stateDigest !== activation.candidateDigest ||\n (targetsAgentProfile &&\n (activation.executionRef === undefined ||\n canonicalCandidateDigest(activation.executionRef) !==\n canonicalCandidateDigest(experiment.executionRef))) ||\n transition.sourceStateDigest !== sourceStateDigest ||\n transition.desiredStateDigest !== desiredStateDigest ||\n canonicalCandidateDigest(transition.operation) !== canonicalCandidateDigest(operation) ||\n !targetsMatch\n ) {\n throw new Error('activation transition does not match its authorization')\n }\n}\n\nfunction assertAuthorizedTransitionTargets(\n activation: AgentImprovementActivation,\n targets: readonly AgentImprovementActivationTargetPlan[],\n): void {\n const authorized = targetMap(activation.targets)\n const planned = targetMap(targets)\n if (\n authorized.size !== planned.size ||\n [...authorized.entries()].some(\n ([identity, target]) =>\n planned.get(identity)?.expectedBaseDigest !== target.expectedBaseDigest,\n )\n ) {\n throw new Error('activation transition does not match its authorization')\n }\n}\n\nfunction assertResultAgainstActivation(\n activation: AgentImprovementActivation,\n result: AgentImprovementActivationResult,\n): void {\n const attemptedAt = Date.parse(result.attemptedAt)\n const completedAt = Date.parse(result.completedAt)\n const expiresAt = Date.parse(activation.expiresAt)\n if (\n result.idempotencyKey !== activation.digest ||\n attemptedAt < Date.parse(activation.authorizedAt) ||\n completedAt < attemptedAt\n ) {\n throw new Error('activation result does not bind its authorization')\n }\n const expired = attemptedAt >= expiresAt\n if (\n (result.outcome.status === 'expired' && !expired) ||\n (expired && !['expired', 'indeterminate', 'already-applied'].includes(result.outcome.status))\n ) {\n throw new Error('activation result does not honor its authorization expiry')\n }\n if (!('targets' in result.outcome)) return\n const authorized = targetMap(activation.targets)\n const observed = new Set(result.outcome.targets.map(targetIdentity))\n if (\n authorized.size !== observed.size ||\n [...authorized.keys()].some((identity) => !observed.has(identity))\n ) {\n throw new Error('activation result must cover every authorized target exactly once')\n }\n if (\n result.outcome.status === 'applied' &&\n result.outcome.targets.some(\n (target) =>\n target.beforeDigest !== authorized.get(targetIdentity(target))?.expectedBaseDigest,\n )\n ) {\n throw new Error('applied activation did not start from its authorized base state')\n }\n}\n\nfunction assertResultDesiredState(\n proposal: AgentImprovementProposal,\n activation: AgentImprovementActivation,\n result: AgentImprovementActivationResult,\n): void {\n if (!('targets' in result.outcome)) return\n const targetArm = activation.intent === 'activate-candidate' ? 'candidate' : 'baseline'\n const desiredStateDigest =\n proposal.evaluation.kind === 'agent-profile-improvement-measured-comparison'\n ? agentProfileImprovementStateDigest(proposal.evaluation.experiment, targetArm)\n : undefined\n const desired = new Map(\n activation.targets.map((target) => [\n targetIdentity(target),\n desiredStateDigest ??\n agentImprovementTargetDigest(\n requireSealedCandidateExperiment(proposal),\n targetArm,\n target.surface,\n ),\n ]),\n )\n assertOutcomeDesiredState(activation, result, desired)\n}\n\nfunction assertOutcomeDesiredState(\n activation: AgentImprovementActivation,\n result: AgentImprovementActivationResult,\n desired: ReadonlyMap<string, Sha256Digest>,\n): void {\n if (!('targets' in result.outcome)) return\n if (result.outcome.status === 'applied') {\n if (\n result.outcome.targets.some(\n (target) => target.afterDigest !== desired.get(targetIdentity(target)),\n )\n ) {\n throw new Error('applied activation does not match the requested bundle')\n }\n return\n }\n const allDesired = result.outcome.targets.every(\n (target) => target.currentDigest === desired.get(targetIdentity(target)),\n )\n if (result.outcome.status === 'already-applied') {\n if (!allDesired) throw new Error('already-applied activation is not at the requested state')\n return\n }\n const authorized = targetMap(activation.targets)\n const hasStaleTarget = result.outcome.targets.some(\n (target) => target.currentDigest !== authorized.get(targetIdentity(target))?.expectedBaseDigest,\n )\n if (allDesired || !hasStaleTarget) {\n throw new Error('activation conflict does not identify stale target state')\n }\n}\n\nfunction targetMap<T extends { surface: AgentImprovementSurface; identity: string }>(\n targets: readonly T[],\n): Map<string, T> {\n return new Map(targets.map((target) => [targetIdentity(target), target]))\n}\n\nfunction targetIdentity(target: { surface: AgentImprovementSurface; identity: string }): string {\n return `${target.surface}\\u0000${target.identity}`\n}\n"],"mappings":";;;;AAoBA,SAAgB,2BAA+C;CAC7D,OAAO;EAAE,UAAU;EAAG,WAAW;EAAG,SAAS;EAAG,UAAU;CAAE;AAC9D;AAEA,SAAgB,cAAc,OAAiC;CAC7D,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,KAAK,SAAS;AACzE;;AAGA,SAAgB,gBACd,QACA,OACM;CACN,OAAO,YAAY;CACnB,KAAK,MAAM,OAAO;EAAC;EAAY;EAAa;CAAS,GAAY;EAC/D,MAAM,QAAQ,MAAM;EACpB,IAAI,cAAc,KAAK,GAAG,OAAO,QAAQ;OACpC,IAAI,QAAQ,WAAW,OAAO,WAAW;OACzC,OAAO,cAAc;CAC5B;CACA,IAAI,MAAM,gBAAgB,OAAO,OAAO,cAAc;CACtD,IAAI,MAAM,aAAa,OAAO,OAAO,WAAW;CAChD,IAAI,cAAc,MAAM,gBAAgB,GACtC,OAAO,oBAAoB,OAAO,oBAAoB,KAAK,MAAM;AAErE;;;;ACgGA,SAAgB,uCACd,YACA,SACkC;CAClC,MAAM,aAAa,iCACjB,iCAAiC,MAAM,WAAW,UAAU,GAC5D,8BACF;CACA,sBAAsB,YAAY,UAAU;CAC5C,MAAM,SAAS,uCAAuC,MACpD,2BAA6D;EAC3D,MAAM;EACN,gBAAgB,WAAW;EAC3B,aAAa,WAAW;EACxB,aAAa,QAAQ;EACrB,SAAS,QAAQ;CACnB,CAAC,CAAC,CAAC,KACL;CACA,8BAA8B,YAAY,MAAM;CAChD,0BACE,YACA,QACA,IAAI,IAAI,WA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AI,MAAM,0DAA0D;AAE9E;AAEA,SAAS,UACP,SACgB;CAChB,OAAO,IAAI,IAAI,QAAQ,KAAK,WAAW,CAAC,eAAe,MAAM,GAAG,MAAM,CAAC,CAAC;AAC1E;AAEA,SAAS,eAAe,QAAwE;CAC9F,OAAO,GAAG,OAAO,QAAQ,QAAQ,OAAO;AAC1C"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { f as ExecutorConfig, i as CollectedAgentTurn, r as AgentTurnUsage } from "./stream-agent-turn-
|
|
2
|
-
import { AgentCandidateBundle, AgentImprovementActivation, AgentImprovementActivationOutcome, AgentImprovementActivationResult, AgentImprovementActivationTarget, AgentImprovementProposal, AgentImprovementReview, AgentImprovementSurface, AgentProfile,
|
|
1
|
+
import { f as ExecutorConfig, i as CollectedAgentTurn, r as AgentTurnUsage } from "./stream-agent-turn-Bk79CnTw.js";
|
|
2
|
+
import { AgentCandidateBundle, AgentImprovementActivation, AgentImprovementActivationOutcome, AgentImprovementActivationResult, AgentImprovementActivationTarget, AgentImprovementProposal, AgentImprovementReview, AgentImprovementSurface, AgentProfile, AgentProfileImprovementChange, AgentProfileImprovementExperiment, AgentTrainingReceipt, AgentTrainingTask, HarnessType, ReasoningEffort, Sha256Digest } from "@tangle-network/agent-interface";
|
|
3
3
|
import { CostLedgerHandle, MaximumCharge, ProposalFinding } from "@tangle-network/agent-eval";
|
|
4
|
-
import { CampaignScenarioIdentity, CompareOptimizationMethodsOptions, OptimizationMethod, OptimizationMethodComparison, WorktreeAdapter } from "@tangle-network/agent-eval/campaign";
|
|
4
|
+
import { CampaignScenarioIdentity, CompareOptimizationMethodsOptions, OptimizationMethod, OptimizationMethodComparison, Scenario, SearchAllocator, SearchClaim, SearchClaimVerification, SearchHistoryReceipt, SearchModelIdentity, SearchPolicy, SearchSourceRef, SurfaceProposer, WorktreeAdapter } from "@tangle-network/agent-eval/campaign";
|
|
5
5
|
import { MutableSurface, Scenario as Scenario$1, SelfImproveBudget, SelfImproveOptions, SelfImproveProposerResult } from "@tangle-network/agent-eval/contract";
|
|
6
|
+
import { EvaluationClaim } from "@tangle-network/agent-eval/experiment";
|
|
6
7
|
//#region src/improvement/improvement-driver.d.ts
|
|
7
8
|
/** The byte-producing path that differs between the cheap
|
|
8
9
|
* reflective path and the full agentic path. A generator makes (uncommitted)
|
|
@@ -237,6 +238,20 @@ interface ImproveMethodContext {
|
|
|
237
238
|
readonly baselineValue: unknown;
|
|
238
239
|
/** Findings produced before this search, if any. */
|
|
239
240
|
readonly findings: ReadonlyArray<ProposalFinding>;
|
|
241
|
+
/** Identities the method's search ledger records. */
|
|
242
|
+
readonly searchIdentity: ImproveSearchIdentity;
|
|
243
|
+
}
|
|
244
|
+
/** What a search ledger records about an improvement and cannot infer: what is
|
|
245
|
+
* improved, the agent harness around the profile, the judges and the model. */
|
|
246
|
+
interface ImproveSearchIdentity {
|
|
247
|
+
/** What the search improves, for example `vb/coder`. */
|
|
248
|
+
readonly subject: string;
|
|
249
|
+
/** `executionRef`: the agent callback, materializer, models, tools and closures. */
|
|
250
|
+
readonly agent: SearchSourceRef;
|
|
251
|
+
/** Digest of every judge's name, dimensions, declared version and code. */
|
|
252
|
+
readonly judge: SearchSourceRef;
|
|
253
|
+
/** The profile's model hint; each cell records the model it resolved. */
|
|
254
|
+
readonly model: SearchModelIdentity;
|
|
240
255
|
}
|
|
241
256
|
/** Build a complete method after trace findings are available. */
|
|
242
257
|
type ImproveMethodFactory<TScenario extends Scenario$1, TArtifact> = (context: ImproveMethodContext) => OptimizationMethod<TScenario, TArtifact>;
|
|
@@ -255,7 +270,7 @@ interface ImproveCandidateValidationInput {
|
|
|
255
270
|
type ImproveCandidateValidator = (input: ImproveCandidateValidationInput) => void;
|
|
256
271
|
type ImproveOptimizationRunOptions<TScenario extends Scenario$1, TArtifact> = Omit<NonNullable<CompareOptimizationMethodsOptions<TScenario, TArtifact>['optimizationRunOptions']>, 'dispatchRef'>;
|
|
257
272
|
/** Complete-method configuration for every non-code profile surface. */
|
|
258
|
-
type ImproveMethodOptions<TScenario extends Scenario$1, TArtifact> = Omit<CompareOptimizationMethodsOptions<TScenario, TArtifact>, 'baselineSurface' | 'dispatchRef' | 'dispatchWithSurface' | 'methods' | 'optimizationConcurrency' | 'optimizationRunOptions'> & {
|
|
273
|
+
type ImproveMethodOptions<TScenario extends Scenario$1, TArtifact> = Omit<CompareOptimizationMethodsOptions<TScenario, TArtifact>, 'baselineSurface' | 'dispatchRef' | 'dispatchWithSurface' | 'methods' | 'optimizationConcurrency' | 'optimizationRunOptions' | 'searchHistoryPolicy' | 'searchHistoryVerification'> & {
|
|
259
274
|
/** Exact profile coordinate optimized by `method`. Default `'prompt'`. */
|
|
260
275
|
surface?: ImproveProfileSurface;
|
|
261
276
|
/**
|
|
@@ -282,6 +297,47 @@ type ImproveMethodOptions<TScenario extends Scenario$1, TArtifact> = Omit<Compar
|
|
|
282
297
|
optimizationRunOptions?: ImproveOptimizationRunOptions<TScenario, TArtifact>;
|
|
283
298
|
/** Additional lift floor on Eval's deciding interval. Eval must also permit promotion. Default `0`. */
|
|
284
299
|
minimumLift?: number;
|
|
300
|
+
/** What the search improves, recorded as the ledger's subject, for example
|
|
301
|
+
* `vb/coder`. Default: the profile's name, else `agent-profile`. */
|
|
302
|
+
subject?: string;
|
|
303
|
+
};
|
|
304
|
+
/** Runtime's native search: a policy, an allocator and a proposer on Eval's
|
|
305
|
+
* search kernel, with no Python bridge. Build it with `searchMethod`. */
|
|
306
|
+
interface ImproveSearchMethod {
|
|
307
|
+
readonly kind: 'search';
|
|
308
|
+
/** Recorded as the ledger's process name and the result's method. */
|
|
309
|
+
readonly name: string;
|
|
310
|
+
readonly policy: SearchPolicy;
|
|
311
|
+
readonly allocation: SearchAllocator;
|
|
312
|
+
readonly proposer: SurfaceProposer<ProposalFinding>;
|
|
313
|
+
/** Proposals the search may make. */
|
|
314
|
+
readonly maxExpansions: number;
|
|
315
|
+
/** Children one proposal asks for. */
|
|
316
|
+
readonly childrenPerProposal: number;
|
|
317
|
+
/** Cells that run at once, in process. */
|
|
318
|
+
readonly concurrency: number;
|
|
319
|
+
/** Prior cost of one cell, held as its estimate reservation until 20 cells settle. */
|
|
320
|
+
readonly cellUsd: number;
|
|
321
|
+
/** Dollars held from the start for the claim's test cells; at least the
|
|
322
|
+
* root and 3 finalists on every test task at `cellUsd` a cell. */
|
|
323
|
+
readonly claimReserveUsd: number | null;
|
|
324
|
+
/** ISO time after which the search stops expanding and claims. */
|
|
325
|
+
readonly deadline: string | null;
|
|
326
|
+
/** Attempts per cell for retryable environment errors. */
|
|
327
|
+
readonly maxAttempts: number;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Improve a profile with `searchMethod`. The search runs on all three splits:
|
|
331
|
+
* it expands and ranks on train and selection, then claims once on the sealed
|
|
332
|
+
* test split, and the claim decides. Runtime ships a statistical `ship` only
|
|
333
|
+
* with complete cost accounting and a test lower bound above `minimumLift`.
|
|
334
|
+
*/
|
|
335
|
+
type ImproveSearchOptions<TScenario extends Scenario$1, TArtifact> = Omit<ImproveMethodOptions<TScenario, TArtifact>, 'method' | 'claim' | 'confidence' | 'evidence' | 'finalEvidence' | 'resamples' | 'reps' | 'maxConcurrency' | 'optimizationRunOptions'> & {
|
|
336
|
+
method: ImproveSearchMethod;
|
|
337
|
+
/** The claim the sealed test split decides. `independentUnit` names each
|
|
338
|
+
* scenario's unit and `minimumEffect` is the improvement the power check
|
|
339
|
+
* must resolve; both are required. */
|
|
340
|
+
claim: EvaluationClaim;
|
|
285
341
|
};
|
|
286
342
|
/** Runtime-owned code search in isolated git worktrees. */
|
|
287
343
|
type ImproveCodeRunOptions<TScenario extends Scenario$1, TArtifact> = Omit<SelfImproveOptions<TScenario, TArtifact>, 'analyzeGeneration' | 'baselineSurface' | 'budget' | 'findings' | 'gate' | 'llm' | 'method' | 'mutationPrimitives' | 'proposer' | 'proposerTarget' | 'selectionScenarios'> & {
|
|
@@ -307,7 +363,7 @@ type ImproveCodeRunOptions<TScenario extends Scenario$1, TArtifact> = Omit<SelfI
|
|
|
307
363
|
promotionGate?: SelfImproveOptions<TScenario, TArtifact>['gate'];
|
|
308
364
|
};
|
|
309
365
|
/** The canonical improvement API: complete methods for profiles, worktrees for code. */
|
|
310
|
-
type ImproveOptions<TScenario extends Scenario$1, TArtifact> = ImproveMethodOptions<TScenario, TArtifact> | ImproveCodeRunOptions<TScenario, TArtifact>;
|
|
366
|
+
type ImproveOptions<TScenario extends Scenario$1, TArtifact> = ImproveMethodOptions<TScenario, TArtifact> | ImproveSearchOptions<TScenario, TArtifact> | ImproveCodeRunOptions<TScenario, TArtifact>;
|
|
311
367
|
interface ImproveSkillsOptions {
|
|
312
368
|
/** `name` of one inline entry in `profile.resources.skills`. */
|
|
313
369
|
resourceName: string;
|
|
@@ -368,101 +424,6 @@ interface ImprovementProfileCandidate {
|
|
|
368
424
|
/** Exact complete profile instance measured on the final cases. */
|
|
369
425
|
profile: ReadonlyAgentProfile;
|
|
370
426
|
}
|
|
371
|
-
/** Digest-addressed Eval artifact. */
|
|
372
|
-
interface ImprovementProfilePopulationArtifactSource {
|
|
373
|
-
path: string;
|
|
374
|
-
sha256: Sha256Digest;
|
|
375
|
-
}
|
|
376
|
-
/** Exact callback observation that introduced one optimizer candidate. */
|
|
377
|
-
interface ImprovementProfilePopulationObservationSource {
|
|
378
|
-
/** One-based JSONL line sequence in the verified observation artifact. */
|
|
379
|
-
proposalSequence: number;
|
|
380
|
-
artifact: ImprovementProfilePopulationArtifactSource;
|
|
381
|
-
}
|
|
382
|
-
/** One exact node from GEPA's accepted candidate graph. */
|
|
383
|
-
interface ImprovementProfilePopulationLineageNode {
|
|
384
|
-
index: number;
|
|
385
|
-
parentIndices: readonly (number | null)[];
|
|
386
|
-
aggregateScore: number | null;
|
|
387
|
-
selectionScores: readonly {
|
|
388
|
-
scenarioId: string;
|
|
389
|
-
score: number;
|
|
390
|
-
}[];
|
|
391
|
-
discoveryEvaluationCount: number;
|
|
392
|
-
}
|
|
393
|
-
type ImprovementProfilePopulationLineage = {
|
|
394
|
-
status: 'available';
|
|
395
|
-
artifact: ImprovementProfilePopulationArtifactSource;
|
|
396
|
-
nodes: readonly ImprovementProfilePopulationLineageNode[];
|
|
397
|
-
} | {
|
|
398
|
-
status: 'unavailable';
|
|
399
|
-
reason: 'optimizer-did-not-report-candidate-lineage';
|
|
400
|
-
};
|
|
401
|
-
/** Every verified source associated with one unique optimizer candidate. */
|
|
402
|
-
interface ImprovementProfilePopulationCandidateSource {
|
|
403
|
-
/** Eval identity of the external text or component candidate. */
|
|
404
|
-
candidateDigest: Sha256Digest;
|
|
405
|
-
/** Present when the candidate crossed the evaluation callback. */
|
|
406
|
-
observation?: ImprovementProfilePopulationObservationSource;
|
|
407
|
-
/** Exact GEPA parents and scores, or an explicit statement that none were reported. */
|
|
408
|
-
lineage: ImprovementProfilePopulationLineage;
|
|
409
|
-
}
|
|
410
|
-
/** A verified optimizer candidate that Runtime can express as an exact profile. */
|
|
411
|
-
interface ImprovementMaterializedProfilePopulationCandidate {
|
|
412
|
-
status: 'materialized';
|
|
413
|
-
source: ImprovementProfilePopulationCandidateSource;
|
|
414
|
-
/** Exact optimizer surface decoded by Eval. */
|
|
415
|
-
value: MutableSurface;
|
|
416
|
-
/** Interface identity of `value`. */
|
|
417
|
-
surfaceDigest: Sha256Digest;
|
|
418
|
-
/** Exact complete profile produced by Runtime's configured materializer. */
|
|
419
|
-
profile: ReadonlyAgentProfile;
|
|
420
|
-
/** `canonicalAgentProfileDigest(profile)`: the one AgentProfile identity Runtime records. */
|
|
421
|
-
profileDigest: Sha256Digest;
|
|
422
|
-
/** Ordered Interface diffs that reproduce `profile` from the baseline. */
|
|
423
|
-
diffs: readonly AgentProfileDiff[];
|
|
424
|
-
/** Interface identity of each entry in `diffs`. */
|
|
425
|
-
diffDigests: readonly Sha256Digest[];
|
|
426
|
-
}
|
|
427
|
-
/** A verified optimizer candidate that Runtime refused to materialize. */
|
|
428
|
-
interface ImprovementRefusedProfilePopulationCandidate {
|
|
429
|
-
status: 'refused';
|
|
430
|
-
source: ImprovementProfilePopulationCandidateSource;
|
|
431
|
-
/** Exact optimizer surface decoded by Eval. */
|
|
432
|
-
value: MutableSurface;
|
|
433
|
-
/** Interface identity of `value`. */
|
|
434
|
-
surfaceDigest: Sha256Digest;
|
|
435
|
-
error: {
|
|
436
|
-
name: string;
|
|
437
|
-
message: string;
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
type ImprovementProfilePopulationCandidate = ImprovementMaterializedProfilePopulationCandidate | ImprovementRefusedProfilePopulationCandidate;
|
|
441
|
-
/** Complete verified population reported by one optimizer run. */
|
|
442
|
-
interface ImprovementProfileCandidatePopulationAvailable {
|
|
443
|
-
status: 'available';
|
|
444
|
-
source: {
|
|
445
|
-
observations?: ImprovementProfilePopulationArtifactSource;
|
|
446
|
-
gepaCandidateGraph?: ImprovementProfilePopulationArtifactSource & {
|
|
447
|
-
bestIndex: number;
|
|
448
|
-
};
|
|
449
|
-
};
|
|
450
|
-
/** Distinct candidate surfaces across all verified source artifacts. */
|
|
451
|
-
uniqueCandidates: number;
|
|
452
|
-
/** Distinct candidate surfaces submitted through the evaluation callback. */
|
|
453
|
-
observedCandidates: number;
|
|
454
|
-
/** Exact GEPA graph nodes. Multiple nodes can have the same candidate surface. */
|
|
455
|
-
gepaCandidateNodes: number;
|
|
456
|
-
materializedCandidates: number;
|
|
457
|
-
refusedCandidates: number;
|
|
458
|
-
candidates: readonly ImprovementProfilePopulationCandidate[];
|
|
459
|
-
}
|
|
460
|
-
/** Explicit absence for methods that do not report candidate population evidence. */
|
|
461
|
-
interface ImprovementProfileCandidatePopulationUnavailable {
|
|
462
|
-
status: 'unavailable';
|
|
463
|
-
reason: 'method-did-not-report-candidate-population';
|
|
464
|
-
}
|
|
465
|
-
type ImprovementProfileCandidatePopulation = ImprovementProfileCandidatePopulationAvailable | ImprovementProfileCandidatePopulationUnavailable;
|
|
466
427
|
interface ImprovementCodeCandidate {
|
|
467
428
|
surface: 'code';
|
|
468
429
|
value: MutableSurface;
|
|
@@ -543,15 +504,41 @@ interface ImproveMethodResult extends ImproveResultBase<ImprovementProfileCandid
|
|
|
543
504
|
low: number;
|
|
544
505
|
high: number;
|
|
545
506
|
};
|
|
546
|
-
/**
|
|
547
|
-
|
|
507
|
+
/** The optimizer's search ledger, closed and verified from its bytes: every
|
|
508
|
+
* candidate it measured as a node, its parents as edges where the optimizer
|
|
509
|
+
* reports them, and every evaluation as a cell. `officialGepa` and
|
|
510
|
+
* `officialSkillOpt` always record one; `null` means the method recorded
|
|
511
|
+
* none, so its lineage is unknown. */
|
|
512
|
+
searchHistory: SearchHistoryReceipt | null;
|
|
548
513
|
raw: OptimizationMethodComparison;
|
|
549
514
|
}
|
|
515
|
+
interface ImproveSearchResult extends ImproveResultBase<ImprovementProfileCandidate> {
|
|
516
|
+
mode: 'search';
|
|
517
|
+
method: string;
|
|
518
|
+
lineage: ImproveMethodLineage;
|
|
519
|
+
/** `ship` only when the claim shipped, its verification re-derived it, the
|
|
520
|
+
* cost accounting is complete, and the test lower bound exceeds `minimumLift`. */
|
|
521
|
+
decision: 'ship' | 'hold';
|
|
522
|
+
/** Why: the claim's reason, or the Runtime rule that held a statistical ship. */
|
|
523
|
+
reason: string;
|
|
524
|
+
/** The claim made once on the sealed test split. */
|
|
525
|
+
claim: SearchClaim;
|
|
526
|
+
/** The claim re-derived from the closed ledger alone. */
|
|
527
|
+
claimVerification: SearchClaimVerification;
|
|
528
|
+
/** The kept candidate's test delta against the baseline, when the claim tested it. */
|
|
529
|
+
lift?: number;
|
|
530
|
+
liftInterval?: {
|
|
531
|
+
low: number;
|
|
532
|
+
high: number;
|
|
533
|
+
};
|
|
534
|
+
/** The search ledger, closed and verified from its bytes. */
|
|
535
|
+
searchHistory: SearchHistoryReceipt;
|
|
536
|
+
}
|
|
550
537
|
interface ImproveCodeResult<TScenario extends Scenario$1, TArtifact> extends ImproveResultBase<ImprovementCodeCandidate> {
|
|
551
538
|
mode: 'code';
|
|
552
539
|
raw: SelfImproveProposerResult<TScenario, TArtifact>;
|
|
553
540
|
}
|
|
554
|
-
type ImproveResult<TScenario extends Scenario$1, TArtifact> = ImproveMethodResult | ImproveCodeResult<TScenario, TArtifact>;
|
|
541
|
+
type ImproveResult<TScenario extends Scenario$1, TArtifact> = ImproveMethodResult | ImproveSearchResult | ImproveCodeResult<TScenario, TArtifact>;
|
|
555
542
|
//#endregion
|
|
556
543
|
//#region src/improvement/training.d.ts
|
|
557
544
|
interface TrainingDatasetDocument {
|
|
@@ -660,13 +647,61 @@ interface ControlledTrainingCommand {
|
|
|
660
647
|
/** Execute one pinned command without a shell, in the runtime-owned job directory. POSIX only. */
|
|
661
648
|
declare function createCommandProfileTrainer(input: ControlledTrainingCommand): ProfileTrainer;
|
|
662
649
|
//#endregion
|
|
650
|
+
//#region src/improvement/search-method.d.ts
|
|
651
|
+
interface SearchMethodOptions {
|
|
652
|
+
/** Writes each child surface from the parents the policy chose. It reads the
|
|
653
|
+
* train split only (`ProposeContext.train` and `summary`); `history` is empty. */
|
|
654
|
+
proposer: SurfaceProposer<ProposalFinding>;
|
|
655
|
+
/** Proposals the search may make. */
|
|
656
|
+
maxExpansions: number;
|
|
657
|
+
/** Which node each proposal extends, and which node the search keeps.
|
|
658
|
+
* Default `aide()`: drafts from the baseline, debugs a node whose cells
|
|
659
|
+
* fail as defects, and otherwise improves a parent drawn by Thompson
|
|
660
|
+
* sampling over each node's posterior, forking from the best node when a
|
|
661
|
+
* lineage stalls. `beam({ width })` expands the top nodes in turn;
|
|
662
|
+
* `incumbent()` is the hill climb, which needs `uniform()`. */
|
|
663
|
+
policy?: SearchPolicy;
|
|
664
|
+
/** Where cells go. Default `asha()`: successive halving over one seeded
|
|
665
|
+
* permutation of the selection units. Each node is screened on 6 selection
|
|
666
|
+
* units and 2 train units, and the top third of each rung advances to twice
|
|
667
|
+
* the units. `uniform()` runs every node on every train and selection task.
|
|
668
|
+
* The allocator's `reps` are every split's repeats, the claim's included. */
|
|
669
|
+
allocation?: SearchAllocator;
|
|
670
|
+
/** Children one proposal asks for. Default 1. */
|
|
671
|
+
childrenPerProposal?: number;
|
|
672
|
+
/** Cells that run at once. Default 2. */
|
|
673
|
+
concurrency?: number;
|
|
674
|
+
/** Prior cost of one cell in dollars, held for each cell until 20 cells
|
|
675
|
+
* settle and the lane's own costs set the hold. Default 0. */
|
|
676
|
+
cellUsd?: number;
|
|
677
|
+
/** Dollars held for the claim from the start. Default: the root and 3
|
|
678
|
+
* finalists on every test task at `cellUsd` a cell. */
|
|
679
|
+
claimReserveUsd?: number;
|
|
680
|
+
/** ISO time after which the search stops expanding and claims. */
|
|
681
|
+
deadline?: string;
|
|
682
|
+
/** Attempts per cell for retryable environment errors. Default 3. */
|
|
683
|
+
maxAttempts?: number;
|
|
684
|
+
/** Recorded as the ledger's process name. Default `search`. */
|
|
685
|
+
name?: string;
|
|
686
|
+
}
|
|
687
|
+
/** Build Runtime's native search for `improve(profile, { method })`. */
|
|
688
|
+
declare function searchMethod(options: SearchMethodOptions): ImproveSearchMethod;
|
|
689
|
+
//#endregion
|
|
663
690
|
//#region src/improvement/improve.d.ts
|
|
664
691
|
/** Train and serve a checkpoint without implying that it improved held-out quality. */
|
|
665
692
|
declare function improve(profile: ReadonlyAgentProfile, opts: ImproveTrainingOptions): Promise<ImproveTrainingResult>;
|
|
693
|
+
/**
|
|
694
|
+
* Search one exact profile surface with Runtime's native search
|
|
695
|
+
* (`method: searchMethod(...)`): the kernel expands, allocates and claims on
|
|
696
|
+
* the sealed test split, and the claim decides.
|
|
697
|
+
*/
|
|
698
|
+
declare function improve<TScenario extends Scenario$1, TArtifact>(profile: ReadonlyAgentProfile, opts: ImproveSearchOptions<TScenario, TArtifact>): Promise<ImproveSearchResult>;
|
|
666
699
|
/**
|
|
667
700
|
* Optimize one exact profile surface with a complete method.
|
|
668
701
|
*/
|
|
669
702
|
declare function improve<TScenario extends Scenario$1, TArtifact>(profile: ReadonlyAgentProfile, opts: ImproveMethodOptions<TScenario, TArtifact>): Promise<ImproveMethodResult>;
|
|
703
|
+
/** Optimize one exact profile surface with a complete method or a search. */
|
|
704
|
+
declare function improve<TScenario extends Scenario$1, TArtifact>(profile: ReadonlyAgentProfile, opts: ImproveMethodOptions<TScenario, TArtifact> | ImproveSearchOptions<TScenario, TArtifact>): Promise<ImproveMethodResult | ImproveSearchResult>;
|
|
670
705
|
/**
|
|
671
706
|
* Optimize repository code through Runtime's isolated worktree path.
|
|
672
707
|
*/
|
|
@@ -767,5 +802,5 @@ declare function verifyAgentImprovementActivationResult(input: {
|
|
|
767
802
|
/** Validate and execute one product-owned activation transition. */
|
|
768
803
|
declare function executeAgentImprovementActivation(input: ExecuteAgentImprovementActivationInput, options: ExecuteAgentImprovementActivationOptions): Promise<AgentImprovementActivationResult>;
|
|
769
804
|
//#endregion
|
|
770
|
-
export {
|
|
771
|
-
//# sourceMappingURL=activation-
|
|
805
|
+
export { ImproveSearchOptions as $, ImproveCodeBaseOptions as A, ImproveMethodOptions as B, ProfileTrainer as C, createCommandProfileTrainer as D, TrainingDatasetDocument as E, ImproveCustomCodeGeneratorOptions as F, ImproveProfileAgent as G, ImproveMethodSource as H, ImproveLineage as I, ImproveResult as J, ImproveProfileComponents as K, ImproveMethodContext as L, ImproveCodeResult as M, ImproveCodeRunOptions as N, ImproveCandidateValidationInput as O, ImproveCost as P, ImproveSearchMethod as Q, ImproveMethodFactory as R, ImproveTrainingResult as S, TrainingBoundaryResult as T, ImproveOptimizationRunOptions as U, ImproveMethodResult as V, ImproveOptions as W, ImproveScenarioPartitions as X, ImproveRuntimeCodeGeneratorOptions as Y, ImproveSearchIdentity as Z, SearchMethodOptions as _, defaultBuildPrompt as _t, AgentImprovementActivationTransitionInput as a, ImprovementProfileCandidate as at, ControlledTrainingCommand as b, CreateAgentImprovementActivationResultOptions as c, AgenticGeneratorExecutorForWorktree as ct, ProfileImprovementActivationTransitionInput as d, AgenticGeneratorShotExecution as dt, ImproveSearchResult as et, SealedCandidateActivationTransitionInput as f, AgenticGeneratorShotReceipt as ft, improve as g, commandVerifier as gt, verifyAgentImprovementActivationResult as h, agenticGenerator as ht, AgentImprovementActivationTransition as i, ImprovementCodeCandidate as it, ImproveCodeOptions as j, ImproveCandidateValidator as k, ExecuteAgentImprovementActivationInput as l, AgenticGeneratorOptions as lt, executeAgentImprovementActivation as m, VerifyResult as mt, AgentImprovementActivationResultStore as n, ImproveSurface as nt, AgentProfileImprovementActivationOperation as o, DeepReadonly as ot, createAgentImprovementActivationResult as p, Verifier as pt, ImproveProfileSurface as q, AgentImprovementActivationTargetPlan as r, ImprovementCandidate as rt, AgentProfileImprovementActivationTargetPlan as s, ReadonlyAgentProfile as st, AgentImprovementActivationReconciliation as t, ImproveSkillsOptions as tt, ExecuteAgentImprovementActivationOptions as u, AgenticGeneratorShotDisposition as ut, searchMethod as v, CandidateGenerator as vt, ProfileTrainerRequest as w, ImproveTrainingOptions as x, CheckpointServingPort as y, ImproveMethodLineage as z };
|
|
806
|
+
//# sourceMappingURL=activation-y-60DXF4.d.ts.map
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $a as RuntimeStreamEvent, Yi as AgentRunSpec, ba as SandboxClient, va as OutputAdapter } from "./types-D56jQad-.js";
|
|
2
2
|
import { a as createSurfaceImprovementProposer, c as SurfaceValidationIssue, d as validateSurfaces, i as SurfaceImprovementEdit, l as renderSurfaceIssues, n as DraftPatchInput, o as AgentSurfaces, r as DraftPatchOutput, s as ResolvedSurface, t as CreateSurfaceImprovementProposerOptions, u as resolveSubjectPath } from "./improvement-adapter-D5gwwoXQ.js";
|
|
3
|
-
import { $h as ProfileMaterializationIssue, Jh as AssertProfileMaterializationOptions, Kh as AGENT_PROFILE_MATERIALIZATION_AXES, Qh as ProfileMaterializationContract, Xh as DefineProfileMaterializationContractOptions, Yh as CanonicalAgentProfileMaterializationAxis, Zh as KnownAgentProfileMaterializationAxis, ag as profileMaterializationAxes, cg as promptOnlyProfileMaterialization, dg as sandboxActProfileMaterialization, eg as ValidateProfileMaterializationOptions, fg as validateProfileMaterialization, ig as fullProfileMaterialization, lg as promptResourceProfileMaterialization, ng as controlProfileMaterialization, og as promptControlProfileMaterialization, pg as worktreeCliProfileMaterialization, qh as AgentProfileMaterializationAxis, rg as defineProfileMaterializationContract, sg as promptModelProfileMaterialization, tg as assertProfileMaterialization, ug as renderProfileMaterializationIssues } from "./index-
|
|
3
|
+
import { $h as ProfileMaterializationIssue, Jh as AssertProfileMaterializationOptions, Kh as AGENT_PROFILE_MATERIALIZATION_AXES, Qh as ProfileMaterializationContract, Xh as DefineProfileMaterializationContractOptions, Yh as CanonicalAgentProfileMaterializationAxis, Zh as KnownAgentProfileMaterializationAxis, ag as profileMaterializationAxes, cg as promptOnlyProfileMaterialization, dg as sandboxActProfileMaterialization, eg as ValidateProfileMaterializationOptions, fg as validateProfileMaterialization, ig as fullProfileMaterialization, lg as promptResourceProfileMaterialization, ng as controlProfileMaterialization, og as promptControlProfileMaterialization, pg as worktreeCliProfileMaterialization, qh as AgentProfileMaterializationAxis, rg as defineProfileMaterializationContract, sg as promptModelProfileMaterialization, tg as assertProfileMaterialization, ug as renderProfileMaterializationIssues } from "./index-Dm8SHDGW.js";
|
|
4
4
|
import { AgentProfile, AgentProfileFileMount, AgentProfileMcpServer } from "@tangle-network/agent-interface";
|
|
5
5
|
import { TraceAnalystDefinition } from "@tangle-network/agent-eval";
|
|
6
6
|
import { SandboxEvent } from "@tangle-network/sandbox";
|
package/dist/agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Ci as sandboxActProfileMaterialization, Ei as worktreeCliProfileMaterialization,
|
|
2
|
-
import "./runtime-
|
|
1
|
+
import { Ci as sandboxActProfileMaterialization, Ei as worktreeCliProfileMaterialization, Ti as validateProfileMaterialization, _i as promptControlProfileMaterialization, bi as promptResourceProfileMaterialization, ca as mapSandboxEvent, di as AGENT_PROFILE_MATERIALIZATION_AXES, fi as assertProfileMaterialization, gi as profileMaterializationAxes, hi as fullProfileMaterialization, mi as defineProfileMaterializationContract, pi as controlProfileMaterialization, vi as promptModelProfileMaterialization, xi as renderProfileMaterializationIssues, yi as promptOnlyProfileMaterialization, zn as createSandboxForSpec } from "./supervisor-BXXjVCbW.js";
|
|
2
|
+
import "./runtime-Du7j-nDD.js";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
5
5
|
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ai as readCommittedJsonLines, Bi as providerAttemptEvidence,
|
|
1
|
+
import { $t as parseWorkerToolTraceArtifact, Ai as readCommittedJsonLines, Bi as providerAttemptEvidence, Bt as InMemoryResultBlobStore, Cn as createPeerMailbox, Dn as isLiveNodeStatus, E as failedItems, Ea as unmeteredSpend, Fr as resolveRedactor, It as createRouterTranscript, M as withDriverExecutor, On as isTerminalNodeStatus, Qi as detachedFrozen, Rt as FileResultBlobStore, Vt as InMemorySpawnJournal, Yn as runBrainLoop, _ as CheckUnavailableError, ba as promptCacheTokenClasses, c as runTree, en as workerTraceAnalysisStore, fr as errMessage, ft as resolveSpawnResourcePaths, ha as chargedTokens, i as bestDelivered, ja as withBudgetResources, ji as writeAllBytes, jt as createExecutorRegistry, ka as addResourceSpend, ki as prepareJsonlAppend, o as pickBestDelivered, ot as scopeRetainedOwnerResourceReader, rn as assertValidBudget, s as runFinalizer, vn as createInbox, x as checkVerdictOf, z as meterRuntimeOwnedProviderAttempt, zt as FileSpawnJournal } from "./supervisor-BXXjVCbW.js";
|
|
2
2
|
import { f as RuntimeRunStateError, m as ValidationError } from "./errors-DodWX-cb.js";
|
|
3
3
|
import { A as writeWorkerCancellation, M as writeWorkerSteerAcknowledgement, b as workerCancellationsDir, c as readWorkerCancelRequests, d as readWorkerSteerRequests, k as writeRunCancellation, l as readWorkerCancellation, o as readRunCancelRequest, r as claimWorkerSteerDelivery, s as readRunCancellation, u as readWorkerSteerAcknowledgement } from "./run-layout-vwd4SwX_.js";
|
|
4
4
|
import { agentProfileSchema, canonicalCandidateDigest } from "@tangle-network/agent-interface";
|
|
@@ -4563,4 +4563,4 @@ function safeJson(v) {
|
|
|
4563
4563
|
//#endregion
|
|
4564
4564
|
export { createCoordinationTools as A, applyRunCancellation as C, analystToolGroupNames as D, DEFAULT_AWAIT_EVENT_TIMEOUT_MS as E, questionEscalationTargets as F, createEventBus as I, defaultToolDetectors as L, downMessageRefusalReasons as M, normalizeAnalyzeOnSettle as N, canonicalFindingEvent as O, parseAuthoredAnalystDefinition as P, watchTrace as R, foldCoordinationRecords as S, ANALYST_DEFINITION_BOUNDS as T, renderAnytimeTable as _, allOf as a, withRunContext as b, createProgressTracker as c, progressStop as d, sampleFromSettled as f, plateauLength as g, bestSoFar as h, finalizeBestDelivered as i, createCoordinationToolsForManager as j, coordinationVerbNames as k, noProgressFor as l, areaUnderCurve as m, createSteerAcknowledger as n, allWorkersStalled as o, anytimeReport as p, driverAgent as r, anyOf as s, createCancelAcknowledger as t, plateau as u, createFileRunContext as v, watchRunCancellation as w, FileCoordinationLog as x, createInMemoryRunContext as y };
|
|
4565
4565
|
|
|
4566
|
-
//# sourceMappingURL=coordination-driver-
|
|
4566
|
+
//# sourceMappingURL=coordination-driver-CraAV-22.js.map
|