@tangle-network/agent-runtime 0.323.0 → 0.324.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-D4hHi27J.d.ts → activation-CB2npL7F.d.ts} +2 -2
- package/dist/{activation-DpipXGti.js → activation-CmWGOW1x.js} +3 -3
- package/dist/{activation-DpipXGti.js.map → activation-CmWGOW1x.js.map} +1 -1
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +2 -2
- package/dist/{bundle-Cw-QdGmH.js → bundle-BJJmfEsw.js} +2 -2
- package/dist/{bundle-Cw-QdGmH.js.map → bundle-BJJmfEsw.js.map} +1 -1
- package/dist/candidate-execution/index.js +5 -5
- package/dist/{coordination-driver-COSL19sL.js → coordination-driver-CNEeqMoh.js} +31 -19
- package/dist/coordination-driver-CNEeqMoh.js.map +1 -0
- package/dist/{delegate-silSKPSB.js → delegate-C6oOTFB6.js} +2 -2
- package/dist/{delegate-silSKPSB.js.map → delegate-C6oOTFB6.js.map} +1 -1
- package/dist/{durable-file-DWQA4ooo.js → durable-file-B_eJr6Mb.js} +40 -8
- package/dist/durable-file-B_eJr6Mb.js.map +1 -0
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +12 -21
- package/dist/durable.js.map +1 -1
- package/dist/{graph-DbQ-BXKr.js → graph-BKmo7d42.js} +5 -5
- package/dist/{graph-DbQ-BXKr.js.map → graph-BKmo7d42.js.map} +1 -1
- package/dist/{graph-registry-BuJbzTzF.js → graph-registry-DAI6KNXB.js} +19 -34
- package/dist/graph-registry-DAI6KNXB.js.map +1 -0
- package/dist/{improvement-cycle-BeN9wahG.js → improvement-cycle-U74a-YKi.js} +10 -10
- package/dist/{improvement-cycle-BeN9wahG.js.map → improvement-cycle-U74a-YKi.js.map} +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +18 -15
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +3 -3
- package/dist/intelligence.js +7 -7
- package/dist/jsonl-file-DBv31uPi.js +206 -0
- package/dist/jsonl-file-DBv31uPi.js.map +1 -0
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +13 -13
- package/dist/{loop-runner-bin-DkhIbFBp.js → loop-runner-bin-BfcTX4-n.js} +3 -3
- package/dist/{loop-runner-bin-DkhIbFBp.js.map → loop-runner-bin-BfcTX4-n.js.map} +1 -1
- package/dist/{loop-runner-bin-Bsux_MGx.d.ts → loop-runner-bin-CkchKbaB.d.ts} +2 -2
- 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 +3 -3
- package/dist/mcp/index.js +6 -6
- package/dist/{model-policy-CNe257pB.js → model-policy-CyCUwHed.js} +2 -2
- package/dist/model-policy-CyCUwHed.js.map +1 -0
- package/dist/{openai-tools-e02ABKl0.d.ts → openai-tools-BR3rRmmC.d.ts} +2 -2
- package/dist/{prepare-CFQLx9e3.js → prepare-DpavgJT8.js} +4 -4
- package/dist/{prepare-CFQLx9e3.js.map → prepare-DpavgJT8.js.map} +1 -1
- package/dist/{profile-BTbpdL9h.js → profile-ZS7_KLwK.js} +2 -2
- package/dist/{profile-BTbpdL9h.js.map → profile-ZS7_KLwK.js.map} +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/profiles.js +1 -1
- package/dist/{protected-model-port-f1N2f0Uq.js → protected-model-port-BLyyfL3l.js} +4 -4
- package/dist/{protected-model-port-f1N2f0Uq.js.map → protected-model-port-BLyyfL3l.js.map} +1 -1
- package/dist/{protected-redaction-DylCC_ot.js → protected-redaction-DFCeo4vg.js} +2 -2
- package/dist/{protected-redaction-DylCC_ot.js.map → protected-redaction-DFCeo4vg.js.map} +1 -1
- package/dist/{provision-supervisor-DdWu6mqu.js → provision-supervisor-DhPJqazM.js} +7 -7
- package/dist/{provision-supervisor-DdWu6mqu.js.map → provision-supervisor-DhPJqazM.js.map} +1 -1
- package/dist/{run-layout-DSCWdbX2.js → run-layout-Cu8H7aeh.js} +2 -2
- package/dist/{run-layout-DSCWdbX2.js.map → run-layout-Cu8H7aeh.js.map} +1 -1
- package/dist/{runtime-DhPIc7XV.js → runtime-B9-ZiYFa.js} +84 -80
- package/dist/runtime-B9-ZiYFa.js.map +1 -0
- package/dist/{search-executor-BS-WJpti.js → search-executor-CtNb_lIB.js} +13 -5
- package/dist/search-executor-CtNb_lIB.js.map +1 -0
- package/dist/{server-CEDOUOdz.js → server-BLYiq6fK.js} +4 -4
- package/dist/{server-CEDOUOdz.js.map → server-BLYiq6fK.js.map} +1 -1
- package/dist/{supervise-CwWI7kIk.js → supervise-FOCAUADN.js} +8 -7
- package/dist/{supervise-CwWI7kIk.js.map → supervise-FOCAUADN.js.map} +1 -1
- package/dist/{supervisor-CSKkm-e1.js → supervisor-DnKhkhKc.js} +10908 -10772
- package/dist/supervisor-DnKhkhKc.js.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +14 -14
- package/dist/{top-app-DaiR4LXM.js → top-app-BaMw1W2z.js} +2 -2
- package/dist/{top-app-DaiR4LXM.js.map → top-app-BaMw1W2z.js.map} +1 -1
- package/dist/tui/bin.js +1 -1
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/{index-7h7-L6Tk.d.ts → types-ytkoP4VV.d.ts} +17362 -17273
- package/dist/{workspace-streams-DFAhW7hF.js → workspace-streams-CcoARX4v.js} +2 -2
- package/dist/{workspace-streams-DFAhW7hF.js.map → workspace-streams-CcoARX4v.js.map} +1 -1
- package/package.json +3 -3
- package/dist/coordination-driver-COSL19sL.js.map +0 -1
- package/dist/durable-file-DWQA4ooo.js.map +0 -1
- package/dist/graph-registry-BuJbzTzF.js.map +0 -1
- package/dist/model-policy-CNe257pB.js.map +0 -1
- package/dist/runtime-DhPIc7XV.js.map +0 -1
- package/dist/search-executor-BS-WJpti.js.map +0 -1
- package/dist/supervisor-CSKkm-e1.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cc as CollectedAgentTurn, Dw as BudgetPool, Gg as SharedBoxPlacement, Kg as SharedBoxPlacementOptions, Mh as ExecutorConfig, Sc as AgentTurnUsage, Tw as WorkerSlots, zS as OtelExportConfig } from "./types-ytkoP4VV.js";
|
|
2
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, CostReceiptInput, MaximumCharge, PairedPromotionDecision, PendingCostCallView, ProposalFinding, RunRecord } from "@tangle-network/agent-eval";
|
|
4
4
|
import { CampaignCellResult, CampaignScenarioIdentity, CampaignStorage, CompareOptimizationMethodsOptions, OptimizationMethod, OptimizationMethodComparison, Scenario, SearchAllocator, SearchCellResult, SearchCellStage, SearchClaim, SearchClaimVerification, SearchHistoryReceipt, SearchLane, SearchModelIdentity, SearchPolicy, SearchSourceRef, SearchSplit, SearchStateView, SurfaceProposer, WorktreeAdapter } from "@tangle-network/agent-eval/campaign";
|
|
@@ -1013,4 +1013,4 @@ declare function verifyAgentImprovementActivationResult(input: {
|
|
|
1013
1013
|
declare function executeAgentImprovementActivation(input: ExecuteAgentImprovementActivationInput, options: ExecuteAgentImprovementActivationOptions): Promise<AgentImprovementActivationResult>;
|
|
1014
1014
|
//#endregion
|
|
1015
1015
|
export { ImproveScenarioPartitions as $, createCommandProfileTrainer as A, AgenticGeneratorShotReceipt as At, ImproveMethodContext as B, ControlledTrainingCommand as C, subscriptionLane as Ct, ProfileTrainerRequest as D, AgenticGeneratorOptions as Dt, ProfileTrainer as E, AgenticGeneratorExecutorForWorktree as Et, ImproveCodeResult as F, defaultBuildPrompt as Ft, ImproveMethodSource as G, ImproveMethodLineage as H, ImproveCodeRunOptions as I, CandidateGenerator as It, ImproveProfileAgent as J, ImproveOptimizationRunOptions as K, ImproveCost as L, ImproveCandidateValidator as M, VerifyResult as Mt, ImproveCodeBaseOptions as N, agenticGenerator as Nt, TrainingBoundaryResult as O, AgenticGeneratorShotDisposition as Ot, ImproveCodeOptions as P, commandVerifier as Pt, ImproveRuntimeCodeGeneratorOptions as Q, ImproveCustomCodeGeneratorOptions as R, CheckpointServingPort as S, sharedBoxLane as St, ImproveTrainingResult as T, ReadonlyAgentProfile as Tt, ImproveMethodOptions as U, ImproveMethodFactory as V, ImproveMethodResult as W, ImproveProfileSurface as X, ImproveProfileComponents as Y, ImproveResult as Z, SearchMethodOptions as _, SearchTraceOptions as _t, AgentImprovementActivationTransitionInput as a, ImproveSkillsOptions as at, SearchImprovementDecision as b, isSearchEnvironmentFault as bt, CreateAgentImprovementActivationResultOptions as c, ImprovementCodeCandidate as ct, ProfileImprovementActivationTransitionInput as d, SearchPromotion as dt, ImproveSearchAgent as et, SealedCandidateActivationTransitionInput as f, SearchCellContext as ft, improve as g, SearchLaneOptions as gt, verifyAgentImprovementActivationResult as h, SearchLaneKind as ht, AgentImprovementActivationTransition as i, ImproveSearchResult as it, ImproveCandidateValidationInput as j, Verifier as jt, TrainingDatasetDocument as k, AgenticGeneratorShotExecution as kt, ExecuteAgentImprovementActivationInput as l, ImprovementProfileCandidate as lt, executeAgentImprovementActivation as m, SearchLane$1 as mt, AgentImprovementActivationResultStore as n, ImproveSearchMethod as nt, AgentProfileImprovementActivationOperation as o, ImproveSurface as ot, createAgentImprovementActivationResult as p, SearchEnvironmentFault as pt, ImproveOptions as q, AgentImprovementActivationTargetPlan as r, ImproveSearchOptions as rt, AgentProfileImprovementActivationTargetPlan as s, ImprovementCandidate as st, AgentImprovementActivationReconciliation as t, ImproveSearchIdentity as tt, ExecuteAgentImprovementActivationOptions as u, SearchDispatchContext as ut, searchMethod as v, SharedBoxSearchLane as vt, ImproveTrainingOptions as w, DeepReadonly as wt, decideSearchImprovement as x, routerLane as xt, DecideSearchImprovementOptions as y, dedicatedLane as yt, ImproveLineage as z };
|
|
1016
|
-
//# sourceMappingURL=activation-
|
|
1016
|
+
//# sourceMappingURL=activation-CB2npL7F.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as verifyCanonicalCandidateDocument, L as immutableCandidateValue, N as canonicalCandidateDigest$1, P as canonicalCandidateDocument } from "./workspace-streams-
|
|
2
|
-
import { A as agentImprovementTargetInput, M as agentProfileImprovementStateDigest, c as requireSealedCandidateExperiment, d as verifyAgentImprovementActivation, f as verifyAgentImprovementProposal, k as agentImprovementTargetDigest } from "./improvement-cycle-
|
|
1
|
+
import { B as verifyCanonicalCandidateDocument, L as immutableCandidateValue, N as canonicalCandidateDigest$1, P as canonicalCandidateDocument } from "./workspace-streams-CcoARX4v.js";
|
|
2
|
+
import { A as agentImprovementTargetInput, M as agentProfileImprovementStateDigest, c as requireSealedCandidateExperiment, d as verifyAgentImprovementActivation, f as verifyAgentImprovementProposal, k as agentImprovementTargetDigest } from "./improvement-cycle-U74a-YKi.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-CmWGOW1x.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activation-DpipXGti.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}`\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,WAAW,QAAQ,KAAK,WAAW,CAAC,eAAe,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S,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
|
+
{"version":3,"file":"activation-CmWGOW1x.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}`\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,Y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,MAAM,IAAI,MAAM,0DAA0D;EAC3F;CACF;CACA,MAAM,aAAa,UAAU,WAAW,OAAO;CAC/C,MAAM,iBAAiB,OAAO,QAAQ,QAAQ,MAC3C,WAAW,OAAO,kBAAkB,WAAW,IAAI,eAAe,MAAM,CAAC,CAAC,EAAE,kBAC/E;CACA,IAAI,cAAc,CAAC,gBACjB,MAAM,IAAI,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"}
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
1
|
+
import { Hw as AgentRunSpec, S as RuntimeStreamEvent, dT as OutputAdapter, pT as SandboxClient } from "./types-ytkoP4VV.js";
|
|
3
2
|
import { C as worktreeCliProfileMaterialization, S as validateProfileMaterialization, _ as promptModelProfileMaterialization, a as DefineProfileMaterializationContractOptions, b as renderProfileMaterializationIssues, c as ProfileMaterializationIssue, d as assertProfileMaterializes, f as controlProfileMaterialization, g as promptControlProfileMaterialization, h as profileMaterializationAxes, i as CanonicalAgentProfileMaterializationAxis, l as ValidateProfileMaterializationOptions, m as fullProfileMaterialization, n as AgentProfileMaterializationAxis, o as KnownAgentProfileMaterializationAxis, p as defineProfileMaterializationContract, r as AssertProfileMaterializationOptions, s as ProfileMaterializationContract, t as AGENT_PROFILE_MATERIALIZATION_AXES, u as assertProfileMaterialization, v as promptOnlyProfileMaterialization, x as sandboxActProfileMaterialization, y as promptResourceProfileMaterialization } from "./profile-materialization-C5-t3HJ7.js";
|
|
3
|
+
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";
|
|
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 {
|
|
2
|
-
import "./runtime-
|
|
1
|
+
import { $r as sandboxActProfileMaterialization, Br as AGENT_PROFILE_MATERIALIZATION_AXES, Gr as fullProfileMaterialization, Hi as mapSandboxEvent, Hr as assertProfileMaterializes, Jr as promptModelProfileMaterialization, Kr as profileMaterializationAxes, Ur as controlProfileMaterialization, Vr as assertProfileMaterialization, Wr as defineProfileMaterializationContract, Xr as promptResourceProfileMaterialization, Yr as promptOnlyProfileMaterialization, Zr as renderProfileMaterializationIssues, mn as createSandboxForSpec, ni as worktreeCliProfileMaterialization, qr as promptControlProfileMaterialization, ti as validateProfileMaterialization } from "./supervisor-DnKhkhKc.js";
|
|
2
|
+
import "./runtime-B9-ZiYFa.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 { L as immutableCandidateValue, N as canonicalCandidateDigest$1, R as omitTopLevelDigest } from "./workspace-streams-
|
|
1
|
+
import { L as immutableCandidateValue, N as canonicalCandidateDigest$1, R as omitTopLevelDigest } from "./workspace-streams-CcoARX4v.js";
|
|
2
2
|
import { agentCandidateBundleSchema } from "@tangle-network/agent-interface";
|
|
3
3
|
//#region src/candidate-execution/bundle.ts
|
|
4
4
|
/** Validate and content-address a candidate bundle before it crosses an approval boundary. */
|
|
@@ -14,4 +14,4 @@ function sealAgentCandidateBundle(input) {
|
|
|
14
14
|
//#endregion
|
|
15
15
|
export { sealAgentCandidateBundle as t };
|
|
16
16
|
|
|
17
|
-
//# sourceMappingURL=bundle-
|
|
17
|
+
//# sourceMappingURL=bundle-BJJmfEsw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-
|
|
1
|
+
{"version":3,"file":"bundle-BJJmfEsw.js","names":["canonicalCandidateDigest"],"sources":["../src/candidate-execution/bundle.ts"],"sourcesContent":["import type { AgentCandidateBundle } from '@tangle-network/agent-interface'\nimport { agentCandidateBundleSchema } from '@tangle-network/agent-interface'\n\nimport { canonicalCandidateDigest, immutableCandidateValue, omitTopLevelDigest } from './digest'\n\n/** Exact candidate wire shape before the runtime computes its canonical digest. */\nexport type AgentCandidateBundleInput = Omit<AgentCandidateBundle, 'digest'>\n\n/** Validate and content-address a candidate bundle before it crosses an approval boundary. */\nexport function sealAgentCandidateBundle(input: AgentCandidateBundleInput): AgentCandidateBundle {\n const digest = canonicalCandidateDigest(input)\n const parsed = agentCandidateBundleSchema.parse({ ...input, digest })\n const parsedDigest = canonicalCandidateDigest(omitTopLevelDigest(parsed))\n if (parsedDigest !== digest) {\n throw new Error('candidate bundle changed while validating its canonical wire shape')\n }\n return immutableCandidateValue(parsed)\n}\n"],"mappings":";;;;AASA,SAAgB,yBAAyB,OAAwD;CAC/F,MAAM,SAASA,2BAAyB,KAAK;CAC7C,MAAM,SAAS,2BAA2B,MAAM;EAAE,GAAG;EAAO;CAAO,CAAC;CAEpE,IADqBA,2BAAyB,mBAAmB,MAAM,CACxD,MAAM,QACnB,MAAM,IAAI,MAAM,oEAAoE;CAEtF,OAAO,wBAAwB,MAAM;AACvC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { F as deepFreezeCandidate, I as embeddedCandidateArtifact, M as canonicalCandidateBytes$1, O as verifyMaterializedWorkspace, T as scanMaterializedWorkspaceManifest, a as verifyAgentCandidateWorkspaceArtifacts, c as captureAgentCandidateWorkspaceFiles, d as workspaceLimits, f as persistCandidateOutputArtifact, j as verifiedArtifactChunks, l as createAgentCandidateWorkspacePort, n as captureAgentCandidateWorkspaceTreeToArtifacts, o as verifyAgentCandidateWorkspaceTree, r as materializeAgentCandidateWorkspaceFromArtifacts, s as captureAgentCandidateWorkspace, t as captureAgentCandidateWorkspaceToArtifacts, w as readVerifiedArtifact, x as candidateWorkspaceManifest } from "../workspace-streams-
|
|
2
|
-
import { A as recoveredTerminalRecord, C as candidateCleanupDeadline, D as assertTerminalAllowedInPhase, E as assertRecoveryMatchesStaged, F as terminalRecord, M as rejectedStage, N as requireStagedTerminal, O as assertTerminalMatchesClaim, P as sealTerminalDigest, S as candidateClaimFileInternals, T as withinCandidateCleanupDeadline, _ as consumePreparedCandidateExecution, a as AGENT_CANDIDATE_EXECUTION_SUPPORT, c as executePreparedAgentCandidate, d as sealAgentCandidateModelSettlement, g as beginPreparedCandidateDisposal, h as assertPreparedCandidateIntegrity, i as candidateKnowledgeExecutionPaths, j as rejectedFinish, k as assertTerminalMatchesStaged, l as RecoveryAgentCandidateTraceStore, m as candidateExecutionClaim, n as CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV, p as sealAgentCandidateExecutorStopAcknowledgement, r as CANDIDATE_KNOWLEDGE_ROOT_ENV, s as verifyAgentCandidateBundle, t as prepareAgentCandidateExecution, u as persistCandidateModelSettlementEvidence, v as CANDIDATE_TRACE_ENV, w as candidateCleanupTimeout, x as InMemoryAgentCandidateExecutionClaimStore, y as CANDIDATE_TRACE_TAGS } from "../prepare-
|
|
3
|
-
import { a as assertCandidateProfileBinding, d as omitUndefinedObjectFields, h as parseExactCandidateProfile, i as applyExactAgentProfileDiff, l as freezeGenericAgentCandidateProfile, m as parseExactAgentProfileDiff, p as parseExactAgentProfile, r as agentCandidateProfileAsAgentProfile } from "../profile-
|
|
4
|
-
import { t as sealAgentCandidateBundle } from "../bundle-
|
|
5
|
-
import { n as exactProcessProviderAsCandidateExecutor, t as createProtectedAgentCandidateModelPort } from "../protected-model-port-
|
|
1
|
+
import { F as deepFreezeCandidate, I as embeddedCandidateArtifact, M as canonicalCandidateBytes$1, O as verifyMaterializedWorkspace, T as scanMaterializedWorkspaceManifest, a as verifyAgentCandidateWorkspaceArtifacts, c as captureAgentCandidateWorkspaceFiles, d as workspaceLimits, f as persistCandidateOutputArtifact, j as verifiedArtifactChunks, l as createAgentCandidateWorkspacePort, n as captureAgentCandidateWorkspaceTreeToArtifacts, o as verifyAgentCandidateWorkspaceTree, r as materializeAgentCandidateWorkspaceFromArtifacts, s as captureAgentCandidateWorkspace, t as captureAgentCandidateWorkspaceToArtifacts, w as readVerifiedArtifact, x as candidateWorkspaceManifest } from "../workspace-streams-CcoARX4v.js";
|
|
2
|
+
import { A as recoveredTerminalRecord, C as candidateCleanupDeadline, D as assertTerminalAllowedInPhase, E as assertRecoveryMatchesStaged, F as terminalRecord, M as rejectedStage, N as requireStagedTerminal, O as assertTerminalMatchesClaim, P as sealTerminalDigest, S as candidateClaimFileInternals, T as withinCandidateCleanupDeadline, _ as consumePreparedCandidateExecution, a as AGENT_CANDIDATE_EXECUTION_SUPPORT, c as executePreparedAgentCandidate, d as sealAgentCandidateModelSettlement, g as beginPreparedCandidateDisposal, h as assertPreparedCandidateIntegrity, i as candidateKnowledgeExecutionPaths, j as rejectedFinish, k as assertTerminalMatchesStaged, l as RecoveryAgentCandidateTraceStore, m as candidateExecutionClaim, n as CANDIDATE_KNOWLEDGE_RETRIEVAL_CONFIG_ENV, p as sealAgentCandidateExecutorStopAcknowledgement, r as CANDIDATE_KNOWLEDGE_ROOT_ENV, s as verifyAgentCandidateBundle, t as prepareAgentCandidateExecution, u as persistCandidateModelSettlementEvidence, v as CANDIDATE_TRACE_ENV, w as candidateCleanupTimeout, x as InMemoryAgentCandidateExecutionClaimStore, y as CANDIDATE_TRACE_TAGS } from "../prepare-DpavgJT8.js";
|
|
3
|
+
import { a as assertCandidateProfileBinding, d as omitUndefinedObjectFields, h as parseExactCandidateProfile, i as applyExactAgentProfileDiff, l as freezeGenericAgentCandidateProfile, m as parseExactAgentProfileDiff, p as parseExactAgentProfile, r as agentCandidateProfileAsAgentProfile } from "../profile-ZS7_KLwK.js";
|
|
4
|
+
import { t as sealAgentCandidateBundle } from "../bundle-BJJmfEsw.js";
|
|
5
|
+
import { n as exactProcessProviderAsCandidateExecutor, t as createProtectedAgentCandidateModelPort } from "../protected-model-port-BLyyfL3l.js";
|
|
6
6
|
import { agentCandidateArtifactRefSchema, agentCandidateExecutionPlanMaterialSchema, agentCandidateMaterializationReceiptSchema, agentCandidateWorkspaceManifestMaterialSchema, agentCandidateWorkspaceSnapshotEvidenceSchema } from "@tangle-network/agent-interface";
|
|
7
7
|
import { createHash, randomUUID } from "node:crypto";
|
|
8
8
|
import { constants, linkSync } from "node:fs";
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ca as resolveRedactor, Et as failedItems, J as scopeRetainedOwnerResourceReader, Pt as createExecutorRegistry, Qi as InMemorySpawnJournal, St as checkVerdictOf, T as meterRuntimeOwnedProviderAttempt, Tn as runBrainLoop, Xi as FileSpawnJournal, Xt as createInbox, Yi as FileResultBlobStore, Zi as InMemoryResultBlobStore, an as isLiveNodeStatus, c as runTree, ca as contentAddress, fa as errMessage, fi as providerAttemptEvidence, ha as assertValidBudget, i as bestDelivered, ki as settlementFailureCause, la as detachedFrozen, o as pickBestDelivered, oa as parseWorkerToolTraceArtifact, on as isTerminalNodeStatus, s as runFinalizer, sa as workerTraceAnalysisStore, tn as createPeerMailbox, tt as resolveSpawnResourcePaths, v as withDriverExecutor, vt as CheckUnavailableError, w as meterRuntimeOwnedAccounting, zt as createRouterTranscript } from "./supervisor-DnKhkhKc.js";
|
|
2
2
|
import { f as RuntimeRunStateError, m as ValidationError } from "./errors-DodWX-cb.js";
|
|
3
|
-
import { $ as promptCacheTokenClasses, U as chargedTokens, dt as addResourceSpend, mt as withBudgetResources, st as unmeteredSpend } from "./workspace-streams-
|
|
4
|
-
import {
|
|
3
|
+
import { $ as promptCacheTokenClasses, U as chargedTokens, dt as addResourceSpend, mt as withBudgetResources, st as unmeteredSpend } from "./workspace-streams-CcoARX4v.js";
|
|
4
|
+
import { a as readCommittedJsonLines, t as appendCommittedJsonLine } from "./jsonl-file-DBv31uPi.js";
|
|
5
|
+
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-Cu8H7aeh.js";
|
|
5
6
|
import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest } from "@tangle-network/agent-interface";
|
|
6
7
|
import { argHash, errorStreakDetector, observeAll, repeatedActionDetector } from "@tangle-network/agent-eval";
|
|
8
|
+
import { registry } from "zod";
|
|
7
9
|
import { randomUUID } from "node:crypto";
|
|
8
10
|
import { mkdirSync, readFileSync, watch } from "node:fs";
|
|
9
11
|
import { join } from "node:path";
|
|
10
|
-
import { registry } from "zod";
|
|
11
12
|
//#region src/runtime/supervise/detector-monitor.ts
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
@@ -873,7 +874,8 @@ function createCoordinationToolsForManager(opts, lifetime) {
|
|
|
873
874
|
status: "down",
|
|
874
875
|
...settled.outRef === void 0 ? {} : { outRef: settled.outRef },
|
|
875
876
|
...node?.spent === void 0 ? {} : { spent: node.spent },
|
|
876
|
-
reason: settled.reason
|
|
877
|
+
reason: settled.reason,
|
|
878
|
+
failure: settlementFailureCause(settled)
|
|
877
879
|
});
|
|
878
880
|
};
|
|
879
881
|
const analysisRoutes = (opts.analyzeOnSettle ?? []).map(normalizeAnalyzeOnSettle);
|
|
@@ -1294,6 +1296,11 @@ function createCoordinationToolsForManager(opts, lifetime) {
|
|
|
1294
1296
|
}, { analyst: route.kind });
|
|
1295
1297
|
} catch {}
|
|
1296
1298
|
};
|
|
1299
|
+
const analystRunContext = (kind, sourceWorker) => ({ charge: (spend) => meterRuntimeOwnedAccounting(opts.scope, spend, {
|
|
1300
|
+
role: "analyst",
|
|
1301
|
+
analyst: kind,
|
|
1302
|
+
sourceWorker
|
|
1303
|
+
}, { alreadySpent: true }) });
|
|
1297
1304
|
let flushing = 0;
|
|
1298
1305
|
const flushPendingSettlement = async () => {
|
|
1299
1306
|
flushing += 1;
|
|
@@ -1327,9 +1334,21 @@ function createCoordinationToolsForManager(opts, lifetime) {
|
|
|
1327
1334
|
const lensRoutes = applicable.filter((route) => route.agent === void 0);
|
|
1328
1335
|
const agentRoutes = applicable.filter((route) => route.agent !== void 0);
|
|
1329
1336
|
if (lensRoutes.length > 0 && opts.analysts && pending.worker.trace.status === "available") {
|
|
1330
|
-
|
|
1337
|
+
let trace;
|
|
1338
|
+
let traceFailure;
|
|
1339
|
+
try {
|
|
1340
|
+
trace = await workerTraceAnalysisStore(pending.worker.trace, opts.blobs);
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
traceFailure = error;
|
|
1343
|
+
}
|
|
1331
1344
|
for (const route of lensRoutes) {
|
|
1332
|
-
|
|
1345
|
+
let findings;
|
|
1346
|
+
try {
|
|
1347
|
+
if (trace === void 0) throw traceFailure;
|
|
1348
|
+
findings = await opts.analysts.run(route.kind, trace, analystRunContext(route.kind, pending.worker.id));
|
|
1349
|
+
} catch (error) {
|
|
1350
|
+
findings = { analystRunFailed: errMessage(error) };
|
|
1351
|
+
}
|
|
1333
1352
|
await bus.publish({
|
|
1334
1353
|
type: "finding",
|
|
1335
1354
|
finding: canonicalFindingEvent({
|
|
@@ -3067,7 +3086,7 @@ function createCoordinationToolsForManager(opts, lifetime) {
|
|
|
3067
3086
|
error: "unknown-analyst",
|
|
3068
3087
|
reason: `no lens named ${JSON.stringify(kind)} is on this manager's menu; call list_analysts to see what you may run`
|
|
3069
3088
|
};
|
|
3070
|
-
return { findings: await opts.analysts?.run(kind, store) };
|
|
3089
|
+
return { findings: await opts.analysts?.run(kind, store, analystRunContext(kind, id)) };
|
|
3071
3090
|
}
|
|
3072
3091
|
});
|
|
3073
3092
|
if (opts.analysts.register) tools.push({
|
|
@@ -3498,21 +3517,14 @@ var FileCoordinationLog = class {
|
|
|
3498
3517
|
}
|
|
3499
3518
|
async appendRecord(runId, busRecord, ownerId) {
|
|
3500
3519
|
const fs = await import("node:fs/promises");
|
|
3501
|
-
const
|
|
3502
|
-
await fs.mkdir(
|
|
3520
|
+
const { dirname } = await import("node:path");
|
|
3521
|
+
await fs.mkdir(dirname(this.path), { recursive: true });
|
|
3503
3522
|
const record = {
|
|
3504
3523
|
runId,
|
|
3505
3524
|
...ownerId !== void 0 ? { ownerId } : {},
|
|
3506
3525
|
...busRecord
|
|
3507
3526
|
};
|
|
3508
|
-
|
|
3509
|
-
const fh = await fs.open(this.path, "a");
|
|
3510
|
-
try {
|
|
3511
|
-
await writeAllBytes(fh, `${needsSeparator ? "\n" : ""}${JSON.stringify(record)}\n`);
|
|
3512
|
-
await fh.sync();
|
|
3513
|
-
} finally {
|
|
3514
|
-
await fh.close();
|
|
3515
|
-
}
|
|
3527
|
+
await appendCommittedJsonLine(this.path, record);
|
|
3516
3528
|
}
|
|
3517
3529
|
async load(runId, ownerId) {
|
|
3518
3530
|
return foldCoordinationRecords(readCommittedJsonLines(this.path, { allowMissing: true }), runId, ownerId);
|
|
@@ -4996,4 +5008,4 @@ function safeJson(v) {
|
|
|
4996
5008
|
//#endregion
|
|
4997
5009
|
export { ANALYST_DEFINITION_BOUNDS as A, createEventBus as B, createFileRunContext as C, foldCoordinationRecords as D, FileCoordinationLog as E, createCoordinationToolsForManager as F, watchTrace as H, downMessageRefusalReasons as I, normalizeAnalyzeOnSettle as L, canonicalFindingEvent as M, coordinationVerbNames as N, applyRunCancellation as O, createCoordinationTools as P, parseAuthoredAnalystDefinition as R, renderAnytimeTable as S, withRunContext as T, defaultToolDetectors as V, sampleFromSettled as _, DEFAULT_DEADLINE_WARNING_MS as a, bestSoFar as b, refreshedWake as c, allWorkersStalled as d, anyOf as f, progressStop as g, plateau as h, finalizeBestDelivered as i, analystToolGroupNames as j, watchRunCancellation as k, resolveWakePolicy as l, noProgressFor as m, createSteerAcknowledger as n, composeWakeInput as o, createProgressTracker as p, driverAgent as r, deadlineWarningAt as s, createCancelAcknowledger as t, allOf as u, anytimeReport as v, createInMemoryRunContext as w, plateauLength as x, areaUnderCurve as y, questionEscalationTargets as z };
|
|
4998
5010
|
|
|
4999
|
-
//# sourceMappingURL=coordination-driver-
|
|
5011
|
+
//# sourceMappingURL=coordination-driver-CNEeqMoh.js.map
|