/**
 * Extension runner - executes extensions and manages their lifecycle.
 */
import type { ImageContent } from '../../ai/types.js';
import type { AgentModelRegistry } from '../../contracts/agent-model.js';
import type { AgentMessage } from '../../core/core-types.js';
import type { SessionState } from '../../core/session-state.js';
import type { ResourceDiagnostic } from '../resources/diagnostics.js';
import type { BeforeAgentStartEvent, BeforeAgentStartEventResult, ContextEvent, Extension, ExtensionActions, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionRuntime, ExtensionSessionSetupStore, ExtensionSessionView, ExtensionUIContext, InputEvent, InputEventResult, InputSource, PostTurnHandler, RegisteredCommand, RegisteredTool, ResourcesDiscoverEvent, SessionBeforeCompactResult, SessionBeforeSwitchResult, StopHook, ToolCallEvent, ToolCallEventResult, ToolResultEvent, ToolResultEventResult, UserBashEvent, UserBashEventResult } from './types.js';
/** Combined result from all before_agent_start handlers */
interface BeforeAgentStartCombinedResult {
    messages?: NonNullable<BeforeAgentStartEventResult['message']>[];
    systemPrompt?: string;
}
/**
 * Events handled by the generic emit() method.
 * Events with dedicated emitXxx() methods are excluded for stronger type safety.
 */
export type RunnerEmitEvent = Exclude<ExtensionEvent, ToolCallEvent | ToolResultEvent | UserBashEvent | ContextEvent | BeforeAgentStartEvent | ResourcesDiscoverEvent | InputEvent>;
type RunnerEmitResult<TEvent extends RunnerEmitEvent> = TEvent extends {
    type: 'session_before_switch';
} ? SessionBeforeSwitchResult | undefined : TEvent extends {
    type: 'session_before_compact';
} ? SessionBeforeCompactResult | undefined : undefined;
export type ExtensionErrorListener = (error: ExtensionError) => void;
export type NewSessionHandler = (options?: {
    parentSession?: string;
    setup?: (sessionManager: ExtensionSessionSetupStore) => Promise<void>;
}) => Promise<{
    cancelled: boolean;
}>;
export type ForkHandler = (entryId: string) => Promise<{
    cancelled: boolean;
}>;
export type NavigateTreeHandler = (targetId: string, options?: {
    label?: string;
}) => Promise<{
    cancelled: boolean;
}>;
export type SwitchSessionHandler = (sessionPath: string) => Promise<{
    cancelled: boolean;
}>;
export type ReloadHandler = () => Promise<void>;
export type ShutdownHandler = () => void;
export declare class ExtensionRunner {
    private extensions;
    private runtime;
    private uiContext;
    private cwd;
    private sessionManager;
    private modelRegistry;
    private errorListeners;
    private getModel;
    private isIdleFn;
    private waitForIdleFn;
    private abortFn;
    private hasPendingMessagesFn;
    private getContextUsageFn;
    private compactFn;
    private getSystemPromptFn;
    private deductChildUsageFn;
    private getMessagesFn;
    private getToolsFn;
    private getPermissionPolicyFn;
    private newSessionHandler;
    private forkHandler;
    private navigateTreeHandler;
    private switchSessionHandler;
    private reloadHandler;
    private shutdownHandler;
    private commandDiagnostics;
    private sessionState?;
    constructor(extensions: Extension[], runtime: ExtensionRuntime, cwd: string, sessionManager: ExtensionSessionView, modelRegistry: AgentModelRegistry, sessionState?: SessionState);
    bindCore(actions: ExtensionActions, contextActions: ExtensionContextActions): void;
    bindCommandContext(actions?: ExtensionCommandContextActions): void;
    setUIContext(uiContext?: ExtensionUIContext): void;
    getUIContext(): ExtensionUIContext;
    hasUI(): boolean;
    getExtensionPaths(): string[];
    /** Get all registered tools from all extensions (first registration per name wins). */
    getAllRegisteredTools(): RegisteredTool[];
    /** Get a tool definition by name. Returns undefined if not found. */
    getToolDefinition(toolName: string): RegisteredTool['definition'] | undefined;
    /** Get all stop hooks from all extensions, sorted by priority (lower first). */
    getStopHooks(): StopHook[];
    onError(listener: ExtensionErrorListener): () => void;
    emitError(error: ExtensionError): void;
    hasHandlers(eventType: string): boolean;
    getRegisteredCommands(reserved?: Set<string>): RegisteredCommand[];
    getCommandDiagnostics(): ResourceDiagnostic[];
    getRegisteredCommandsWithPaths(): Array<{
        command: RegisteredCommand;
        extensionPath: string;
    }>;
    getCommand(name: string): RegisteredCommand | undefined;
    /** Collect post-turn handlers from all extensions, sorted by priority. */
    getPostTurnHandlers(): PostTurnHandler[];
    /**
     * Run all registered post-turn handlers after a turn_end event.
     *
     * Creates a PostTurnContext from the turn data, then delegates to the
     * post-turn queue which handles priority, sequential execution, and cancellation.
     *
     * @returns The number of handlers that executed.
     */
    runPostTurnHandlers(turnIndex: number, message: AgentMessage, toolResults: import('../../ai/types.js').ToolResultMessage[]): Promise<number>;
    /**
     * Request a graceful shutdown. Called by extension tools and event handlers.
     * The actual shutdown behavior is provided by the mode via bindExtensions().
     */
    shutdown(): void;
    /**
     * Create an ExtensionContext for use in event handlers and tool execution.
     * Context values are resolved at call time, so changes via bindCore/bindUI are reflected.
     */
    createContext(): ExtensionContext;
    createCommandContext(): ExtensionCommandContext;
    private isSessionBeforeEvent;
    emit<TEvent extends RunnerEmitEvent>(event: TEvent): Promise<RunnerEmitResult<TEvent>>;
    emitToolResult(event: ToolResultEvent): Promise<ToolResultEventResult | undefined>;
    emitToolCall(event: ToolCallEvent): Promise<ToolCallEventResult | undefined>;
    emitUserBash(event: UserBashEvent): Promise<UserBashEventResult | undefined>;
    emitContext(messages: AgentMessage[]): Promise<AgentMessage[]>;
    emitBeforeAgentStart(prompt: string, images: ImageContent[] | undefined, systemPrompt: string): Promise<BeforeAgentStartCombinedResult | undefined>;
    emitResourcesDiscover(cwd: string, reason: ResourcesDiscoverEvent['reason']): Promise<{
        skillPaths: Array<{
            path: string;
            extensionPath: string;
        }>;
        promptPaths: Array<{
            path: string;
            extensionPath: string;
        }>;
        themePaths: Array<{
            path: string;
            extensionPath: string;
        }>;
        agentPaths: Array<{
            path: string;
            extensionPath: string;
        }>;
    }>;
    /** Emit input event. Transforms chain, "handled" short-circuits. */
    emitInput(text: string, images: ImageContent[] | undefined, source: InputSource): Promise<InputEventResult>;
}
export {};
//# sourceMappingURL=runner.d.ts.map