/** * AgentSession - Core abstraction for agent lifecycle and session management. * * The historical import path is preserved here as a facade. Responsibilities are * implemented in sibling modules by lifecycle area so each authored source file * stays focused. */ import type { Api, AssistantMessage, Model } from "@bastani/pi-ai/compat"; import type { Agent, AgentMessage, AgentTool, ThinkingLevel } from "@earendil-works/pi-agent-core"; import type { AgentSessionInternalSurface, AgentSessionPublicSurface } from "./agent-session-methods.ts"; import type { PendingPostToolCompactionGuard } from "./agent-session-post-tool-compaction.ts"; import { type SessionSummaryRun } from "./agent-session-summary.ts"; import type { AgentSessionConfig, AgentSessionEventListener, InterruptQueueHold, ToolDefinitionEntry } from "./agent-session-types.js"; import type { VerbatimCompactionResult } from "./compaction/index.ts"; import type { AgentActivityOutcome, ExtensionCommandContextActions, ExtensionErrorListener, ExtensionMode, ExtensionRunner, ExtensionUIContext, OrchestrationContext, SessionStartEvent, SubagentChildPolicy, ToolDefinition } from "./extensions/index.js"; import type { BashExecutionMessage, CustomMessage } from "./messages.ts"; import type { ModelRuntime } from "./model-runtime.js"; import type { ResourceLoader } from "./resource-loader.ts"; import type { SessionManager } from "./session-manager.ts"; import type { SettingsManager } from "./settings-manager.ts"; import type { NormalizedBuildSystemPromptOptions } from "./system-prompt.ts"; import { ChildTaskWaits } from "./tasks/child-command-owner.js"; import { type ProtectedPathLease } from "./tools/session-temp-dir.ts"; import { ToolExecutionScheduler } from "./tools/tool-concurrency.ts"; import { WorkflowStageAdmissionBoundary } from "./workflow-stage-admission.ts"; export type { SessionCompactOptions } from "./agent-session-methods.ts"; export type { ParsedSkillBlock } from "./agent-session-skill-block.ts"; export { parseSkillBlock } from "./agent-session-skill-block.ts"; export type { AgentSessionConfig, AgentSessionEvent, AgentSessionEventListener, CompactionReason, ExtensionBindings, ModelCycleResult, PromptDisposition, PromptOptions, QueuedInputDisposition, SessionRecoveryReport, SessionStats, } from "./agent-session-types.js"; declare class AgentSessionBase { readonly agent: Agent; readonly sessionManager: SessionManager; readonly settingsManager: SettingsManager; protected _scopedModels: Array<{ model: Model; thinkingLevel?: ThinkingLevel; }>; protected _fallbackModels: string[]; protected _isFallbackModelAllowed?: (model: Model, effort: string | undefined) => boolean; protected _fallbackAttemptedKeys: Set; /** Models condemned for this turn by a failure retrying them cannot repair. */ protected _fallbackBlockedModels: Array>; protected _fallbackOriginModel: Model | undefined; protected _fallbackOriginThinkingLevel: ThinkingLevel | undefined; protected _fallbackScopeGeneration: number; protected _fallbackOriginGeneration: number | undefined; protected _fallbackRestoreError: string | undefined; protected _unsubscribeAgent?: () => void; protected _eventListeners: AgentSessionEventListener[]; protected _agentEventQueue: Promise; protected _steeringMessages: string[]; protected _followUpMessages: string[]; protected _interruptDeliveryQueue: Promise; protected _pendingInterruptDeliveries: number; protected _activeInterruptQueueHold: InterruptQueueHold | undefined; protected _queuedMessagesPaused: boolean; protected _queuedMessagesPauseAbortBoundary: Promise | undefined; /** * Text of a queued steering/follow-up message the agent loop already admitted * into the transcript and that has not received an assistant reply yet. The * pause hold cannot reach such a message, so an interrupt would otherwise * strand it (issue #2362). */ protected _admittedQueuedMessageAwaitingReply: string | undefined; /** * Settlement boundary for the recovery turn that answers an already-admitted * queued message. It starts after the pause abort boundary resolves, so the * resume path must wait for it too or an ordinary submission made while it * streams is rejected by the streaming guard (issue #2362). */ protected _admittedRecoveryTurn: Promise | undefined; protected _workflowStageDeliveryForwardTarget: AgentSessionInternalSurface | undefined; protected _activeInterruptAbortMessage: string | undefined; /** Priority input cancels the native operation, not the host-owned task. */ protected _priorityInterruptPending: boolean; protected _activePromptCount: number; protected _isPreparingRun: false | "user" | "custom"; protected _agentRunAbortRequested: boolean; protected _pendingNextTurnMessages: CustomMessage[]; /** Context-only custom messages queued during a run, flushed after the current turn's tool results. */ protected _pendingCustomMessages: CustomMessage[]; protected _protectedStreamingCustomMessages: Array<{ message: CustomMessage; delivery: "steer" | "followUp"; phase: "queued" | "consumed-unpersisted" | "persistence-failed"; }>; protected _compactionAbortController: AbortController | undefined; protected _compactionReason: import("./agent-session-types.js").CompactionReason | undefined; protected _manualCompactionPromise: Promise | undefined; protected _autoCompactionAbortController: AbortController | undefined; /** Resolves when the current automatic compaction has settled. */ protected _autoCompactionCompletion: Promise | undefined; protected _overflowRecoveryAttempted: boolean; protected _recoverableLengthRecoveryAttempted: boolean; /** Set when compaction cannot recover a context overflow on the current model. */ protected _contextOverflowUnresolved: boolean; protected _pendingPostCompactionContinuation: Promise | undefined; protected _postCompactionContinuationToken: number; protected _lengthContinuationAttempts: number; protected _outputBudgetErrorContinuationAttempts: number; protected _postToolCompactionPreflightError: string | undefined; protected _pendingPostToolCompactionGuard: PendingPostToolCompactionGuard | undefined; protected _terminatingToolCallIds: Set; /** A positive stop callback keeps queued work pending until an explicit new run. */ protected _stopAfterTurnBlockedContinuation: boolean; protected _disposed: boolean; protected _branchSummaryAbortController: AbortController | undefined; /** Settles after the currently active branch-summary navigation finishes cleanup. */ protected _branchSummaryCompletion: Promise | undefined; protected _sessionSummaryAbortController: AbortController | undefined; protected _sessionSummaryToken: number; /** The summary request currently in flight, published so a later launch can join it. */ protected _sessionSummaryRun: SessionSummaryRun | undefined; protected _lastSummarizedMessageId: string | undefined; protected _retryAbortController: AbortController | undefined; protected _retryAttempt: number; protected _retryPromise: Promise | undefined; protected _retryResolve: (() => void) | undefined; protected _bashAbortControllers: Map>; protected _pendingBashMessages: BashExecutionMessage[]; protected _extensionRunner: ExtensionRunner; protected _turnIndex: number; /** Source entry IDs for projected messages, so boundaries and omissions resolve provenance. */ protected readonly _entryIdsByMessage: WeakMap; /** Assistant messages whose actionable turn_end already ran from finishTurn. */ protected readonly _boundaryDispatchedMessages: WeakSet; protected readonly _messagesAwaitingPersistence: WeakSet; protected _lastAssistantToolResults: AgentMessage[]; protected _lastActivityOutcome: AgentActivityOutcome; protected _isBeforeSettle: boolean; protected _abortDuringBeforeSettle: boolean; protected _isEmittingAgentSettled: boolean; protected readonly _deferredSettledActions: Array<() => Promise>; /** Set when a caller's prepareNextTurnWithContext replaced the next request's context. */ protected _callerReplacedNextRequestContext: boolean; protected _resourceLoader: ResourceLoader; protected _customTools: ToolDefinition[]; protected _baseToolDefinitions: Map; protected _cwd: string; protected _extensionRunnerRef?: { current?: ExtensionRunner; }; protected _initialActiveToolNames?: string[]; protected _pendingToolNames: Set; protected _usesDefaultTools: boolean; protected _defaultToolModifiers: string[]; /** Resolved defaults last applied here, independent of shared settings publication. */ protected _appliedDefaultTools: Set; protected _subagentPolicy?: SubagentChildPolicy; protected _allowedToolNames?: Set; protected _excludedToolNames?: Set; protected _allowedTools?: (name: string) => boolean; protected _excludedTools?: (name: string) => boolean; protected _childSessionOptions?: import("./child-session-options.ts").ChildSessionOptionsResolver; protected _workflowJournal?: import("./storage/provider.js").RunJournalOption; protected _storageAgentDir?: string; protected _baseToolsOverride?: Record; protected _sessionStartEvent: SessionStartEvent; protected _orchestrationContext?: OrchestrationContext; protected _extensionUIContext?: ExtensionUIContext; protected _extensionHumanInput?: import("./extensions/host-input.js").HostInput | null; protected _extensionDiagnosticListener?: (diagnostic: import("./extensions/host-input.js").HostDiagnostic) => void; protected _extensionMode: ExtensionMode; protected _extensionCommandContextActions?: ExtensionCommandContextActions; protected _extensionShutdownHandler?: () => void; protected _extensionErrorListener?: ExtensionErrorListener; protected _extensionErrorUnsubscriber?: () => void; protected _modelRuntime: ModelRuntime; protected _extensionProviderIds: Set; protected _toolRegistry: Map; protected readonly _toolExecutionScheduler: ToolExecutionScheduler; protected _toolDefinitions: Map; protected _toolPromptSnippets: Map; protected _toolPromptGuidelines: Map; protected _baseSystemPromptOptions: NormalizedBuildSystemPromptOptions; protected _systemPromptTransform?: (prompt: string) => string; protected _contextProjectionTransform?: (messages: AgentMessage[]) => AgentMessage[]; protected _runSystemPromptOptions?: NormalizedBuildSystemPromptOptions; protected _lastAssistantMessage: AssistantMessage | undefined; /** Protection claim on this session's temp tree and tool-results directory. */ protected _tempStorageLease: ProtectedPathLease | undefined; protected _workflowStageAdmission: WorkflowStageAdmissionBoundary | undefined; protected _subagentMessageAdmission: WorkflowStageAdmissionBoundary | undefined; protected _agentTaskHost: import("./tasks/agent-adapter.js").AgentTaskHost | undefined; protected _parentCommandTaskOwner: import("./tasks/child-command-owner.js").ChildCommandTaskOwner | undefined; protected _resourceAdmission: import("./sdk-types.ts").ResourceAdmission | undefined; protected _childTaskWaits: ChildTaskWaits; protected _taskCompletionOutbox: import("./tasks/completion.js").TaskCompletionOutbox | undefined; protected _taskAdmission: WorkflowStageAdmissionBoundary | undefined; protected _cacheWarmer?: import("./cache-warmer.ts").CacheWarmer; get cacheWarmingStatus(): import("./cache-warmer.ts").CacheWarmingStatus | undefined; setCacheWarmingMode(mode: import("./settings-manager.ts").CacheWarmingMode): void; constructor(config: AgentSessionConfig); } export interface AgentSession extends AgentSessionBase, AgentSessionPublicSurface { } export declare const AgentSession: { new (config: AgentSessionConfig): AgentSession; readonly prototype: AgentSession; }; //# sourceMappingURL=agent-session.d.ts.map