/** session (0.2.5 plan 025 Task 1 split). Moved verbatim from agent-session.ts; public surface unchanged behind the barrel. */ import { ActiveDurableRun, ActiveDurableRunExtras } from "../agent-approval.js"; import type { PendingToolCall, PersistedGuardrailPacks, StoredAgentRunState } from "../agent-run-state.js"; import { type AttentionFoldLedger, type AttentionStickyFrontier, type PersistedAttentionFoldLedger, type PersistedAttentionStickyFrontier } from "../attention-compiler.js"; import type { Agent, AgentEvent, AgentRunResult, AgentRunState, AgentRunStateOptions, AgentSession, AgentSessionConfig, AIProvider, CompactionOptions, CompactionResult, ContextMeter, ErrorInfo, GuardrailPackRef, Guardrails, Message, OwnershipScope, PendingDecision, PromptVersionRef, ProviderRequest, RunDecision, RunOptions, SessionEntry, Skill, SteerOptions, SubscribeOptions, ToolCallSummary, ToolDefinition, ToolEffectStore, Usage } from "../contracts.js"; import type { AgentIdentity } from "../identity.js"; import type { AgentInput } from "../input.js"; import type { RunLimitTracker } from "../run-limits.js"; import type { SessionContextSnapshot } from "../session-stores.js"; import type { LoadedSkillBodiesEntry } from "../skill-load.js"; export declare class RuntimeAgentSession implements AgentSession { readonly id: string; private readonly agent; private readonly metadata?; private readonly store; private readonly subscribers; /** Plan 106 R2: `session_start` is dispatched at the first run start, once per runtime session. */ private sessionOpened; /** Plan 106 R2: `close()` dispatches `session_shutdown` and closes subscribers exactly once. */ private closed; private currentLeafId?; private history; private activeRun?; private activeRunId?; private activeProviderTurnAbort?; pendingSoftInterrupt: boolean; private pendingSteers; private pendingSteerBytes; private activeRedactor?; activeProvider?: AIProvider; private activeLedger?; activeEffectStore?: ToolEffectStore; private activeOwnership?; activeIdentity?: AgentIdentity; private activeIdempotencyKey?; private activeGuardrails?; /** Plan 092 Task 2: guardrail packs compiled once in the constructor; merged into every run's `activeGuardrails`. */ packGuardrails?: Guardrails; /** Plan 104 Task 3: `ask` rules as the durable charge-time gate (a match records `interrupt`). */ packAskGate?: Guardrails; /** Plan 104 Task 3: the same `ask` rules as plain blocks for a run that cannot suspend. */ packAskBlocks?: Guardrails; /** Original pack refs, carried into `fork()`/`clone()` so a branch cannot silently lose its policy. */ private packRefs?; /** Plan 104 Task 2: compiled refs + live pack state, replaced by `restoreGuardrailPacks` on resume. */ private compiledGuardrailPacks?; activeMetadata?: Readonly>; activePromptVersion?: PromptVersionRef; activeLimits?: RunLimitTracker; /** Plan 091 T2: input tokens of the latest provider turn plus whether the provider reported * them; set by the usage seam, read by `contextMeter()`. */ activeInputMeter?: { readonly tokens: number; readonly source: "reported" | "estimated"; }; /** Bounded last-N tool-call summaries of the active run (plan 087 T2): ids, names, arg hashes. */ activeRecentToolCalls?: ToolCallSummary[]; activeLimitOutputBuffer: boolean; activeDurable?: ActiveDurableRun; activeLoop?: import("../contracts.js").AgentLoopStrategy; /** Gated calls of the current tool round awaiting one collected suspension. */ activeGatedRound?: Map; activeLoopTurn: number; private readonly loadedSkills; /** Run-owned only: loaded bodies and URI resources retain first insertion order within one provider loop. */ readonly tailSegments: Map; /** Tools activated via `search_tools` this session (plan 041); names-only in persistence. */ readonly activatedTools: import("../tool-search.js").ActiveToolSet; /** Plan 018 Task 6 (closeout `checkpoint-bodies`): persisted exact instructions, registry-independent. */ restoredSkillBodies: readonly LoadedSkillBodiesEntry[]; /** Skills of the current run (for the bodies snapshot); replaced at each run start. */ activeRunSkills: readonly import("../contracts.js").Skill[]; /** Per-run tool allow-list (Task 21); undefined means the full registered set. */ activeToolNames?: readonly string[]; /** Sticky frontier for this session (plan 074 C10); created on first use, so a session whose * agents never enable the compiler allocates nothing. Mutations stay applied once made, so a * later under-ratio turn re-applies them instead of rewriting the prompt-cache prefix. */ private attentionSticky?; attentionStickyFor(): AttentionStickyFrontier; /** Plan 074 P3: bounded snapshot for a durable checkpoint; `undefined` when the session never * mutated anything, so a compiler-off (or never-over-ratio) session persists nothing extra. */ serializedAttentionSticky(): PersistedAttentionStickyFrontier | undefined; /** Plan 074 P3: restore a frontier validated at checkpoint load, so a resumed run keeps its * stubs instead of re-deciding its first turn from the ratio. */ restoreAttentionSticky(persisted: PersistedAttentionStickyFrontier): void; /** Session-owned folded bodies (plan 086 T3); created on first use like the frontier, so a * compiler-off session allocates nothing. */ private attentionFold?; /** Set per run from the resolved compiler: `durable: true` opts the fold ledger and its * frontier into checkpoints even when `persistSessionState` is off. */ attentionDurable: boolean; attentionFoldFor(): AttentionFoldLedger; /** Plan 086 T3: bounded ledger snapshot for a durable checkpoint; `undefined` before any fold. */ serializedAttentionFold(): PersistedAttentionFoldLedger | undefined; /** Plan 086 T3: adopt a ledger validated at checkpoint load, so a resumed fold is byte-identical. */ restoreAttentionFold(ledger: AttentionFoldLedger): void; /** Plan 015 Task 4: re-add persisted loaded-skill names (names only; bodies re-resolve on demand). */ restoreLoadedSkills(names: readonly string[]): void; /** Plan 041: re-add persisted activated-tool names (names only; inert for absent tools). */ restoreActivatedTools(names: readonly string[]): void; /** Plan 041: host reset of search-activated tools. */ clearActivatedTools(): void; /** Plan 018 Task 6: restore persisted loaded-skill bodies (already validated fail-closed at load). */ restoreLoadedSkillBodies(bodies: readonly LoadedSkillBodiesEntry[]): void; /** Plan 104 T2: the refs this session actually enforces (restored ones after a resume). */ get guardrailPackRefs(): readonly GuardrailPackRef[] | undefined; /** Plan 104 T2: pack refs + live pack-owned state for a durable checkpoint (opt-in with `persistSessionState`). */ serializedGuardrailPackState(): PersistedGuardrailPacks | undefined; /** * Plan 104 T2: recompile checkpoint packs before the resumed run's first turn. `state` present * (even empty) marks a restore, so unknown ids, version mismatches, and codec-less state fail * closed as `AgentRunStateError` — never a session that silently enforces less than it did. */ restoreGuardrailPacks(refs: readonly GuardrailPackRef[], state?: Readonly>): void; private ledgerChain; private ledgerFailure; private snapshotGeneration; private snapshotCache?; private readonly snapshotCacheTtlMs; /** * Plan 103 T4: identity-keyed meter cache. Holds only the last public meter value * plus the identity of everything the cold read consumed (`snapshotGeneration`, * leaf, active meter/limits, and the history array reference + length, which catches * in-place `history.push` during a run) — never history content, never an estimator. */ private meterCache?; constructor(config: AgentSessionConfig & { readonly agent: Agent; }); get leafId(): string | undefined; /** * Context-fill read (plan 091 T2): the latest provider turn's input tokens — * provider-reported when it reported, else a labeled estimate — plus the * per-request cap and cumulative run input budget, resolved exactly as * `provider_turn_finished.budgets` resolves them. Before any provider turn in * this session it estimates stored history, so a non-reporting model still * shows a working meter instead of zero. Never billing; estimates are labeled. * * Plan 103 T4: reads are cached until the history generation, leaf, history * length, or active-run identity changes, so a per-frame poll pays one estimate * per mutation instead of one per read. The cached value is frozen and is * identical (`===`) to the previous read while nothing changed. */ contextMeter(): ContextMeter; /** Cold path of `contextMeter()`: one estimate over stored history plus cap/budget resolution. */ private measureContextMeter; /** * Live events for this session. A run-scoped subscriber (the default) is closed when the run ends, * suspends, or is denied; `SubscribeOptions.acrossRuns: true` keeps one subscriber open across runs * of the same session until the host closes it, the session tears it down, or its bounded queue * overflows under the default policy. Subscribe before `run()`; the consumer loop and `run()` must * run concurrently, since events are only emitted during a live run. */ subscribe(options?: SubscribeOptions): AsyncIterable; private createSubscriber; run(input: AgentInput, options?: RunOptions): Promise; steer(input: AgentInput, options?: SteerOptions): void; resumeDurable(state: StoredAgentRunState, runState: AgentRunStateOptions, ownership?: OwnershipScope, signal?: AbortSignal, decisions?: ReadonlyMap, extras?: ActiveDurableRunExtras): Promise; recordDurableResumption(runId: string, interruption: import("../contracts.js").AgentRunInterruption, version: number, ownership?: OwnershipScope): Promise; recordDurableDenial(runId: string, interruption: import("../contracts.js").AgentRunInterruption, version: number, ownership?: OwnershipScope): Promise; private runInternal; /** * Plan 106 R2: dispatch `session_start` once per session, at its first run start (including the * first run of a session rebuilt from a durable checkpoint). The run assembler awaits it right * after `agent_started`/`agent_resumed`, so session-scoped provisioning is done before the first * turn while the runtime's synchronous emit burst stays intact. Middleware error policy decides * whether a failure surfaces or becomes an `extension_error` event. */ openSession(runId: string): Promise; /** * Plan 106 R2: session teardown. Dispatches `session_shutdown` middleware once (idempotent) and * then closes every subscriber, run-scoped and `acrossRuns` alike. Call it after the active run * settles; `closeSubscribers()` remains the subscriber-only seam. */ close(): Promise; prompt(input: string, options?: RunOptions): Promise; stream(input: AgentInput, options?: RunOptions & SubscribeOptions): AsyncGenerator; buildRunResult(input: { readonly runId: string; readonly status: AgentRunResult["status"]; readonly usage?: Usage; readonly limit?: import("../contracts.js").RunLimitBreach; readonly error?: ErrorInfo; readonly abortReason?: string; readonly stopReason?: import("../contracts.js").AgentFinishReason; readonly stopDetail?: string; readonly runState?: AgentRunState; readonly interruption?: import("../contracts.js").AgentRunInterruption; }): AgentRunResult; compact(options?: CompactionOptions): Promise; abort(reason?: unknown): void; entries(): Promise; checkout(leafId?: string): Promise; fork(options?: { readonly leafId?: string; }): AgentSession; clone(options?: { readonly id?: string; readonly leafId?: string; }): Promise; private branchReader; resolveRunProvider(options: RunOptions): void; resolveRunSkills(options: RunOptions, tools: readonly ToolDefinition[]): readonly Skill[]; emit(event: AgentEvent): void; /** * Run end (finish, suspension, or denial): closes the run-scoped subscribers only. Subscribers that * opted into `SubscribeOptions.acrossRuns` stay open for the next run of this session. */ closeRunSubscribers(): void; closeSubscribers(): void; drainLedger(): Promise; applyPendingSteers(runId: string, metadata: Readonly>, signal: AbortSignal): Promise; applyProviderRequestPolicies(request: ProviderRequest, runId: string, options: RunOptions, metadata: Readonly>, signal: AbortSignal): Promise; appendMessage(message: Message, runId: string): Promise; autoCompact(runId: string, options: RunOptions, signal: AbortSignal, inputMessages: readonly Message[]): Promise; private compactBranch; appendEntry(entry: SessionEntry): Promise; invalidateSnapshot(): void; redact(value: T): T; redactProviderRequest(request: ProviderRequest): ProviderRequest; rebuildHistory(): Promise; snapshot(): Promise; }