/**
 * Runtime Adapter Layer
 *
 * Provides a unified, pluggable interface for managing AI runtime sessions.
 * Each adapter encapsulates the full lifecycle of a specific runtime (Claude Code,
 * Gemini CLI, Codex): starting a session, writing input, reading output, and stopping.
 *
 * This replaces the need to coordinate between ISessionBackend, SessionCommandHelper,
 * and RuntimeAgentService manually — the adapter handles it all.
 *
 * @module services/runtime-adapter
 */
import { type RuntimeType } from '../constants.js';
import { RuntimeAgentService } from './agent/runtime-agent.service.abstract.js';
import { type ISessionBackend, type SessionCommandHelper } from './session/index.js';
/**
 * Configuration for starting a new agent session via a runtime adapter.
 *
 * @example
 * ```typescript
 * const config: RuntimeAdapterConfig = {
 *   sessionName: 'dev-agent-1',
 *   projectPath: '/home/user/my-project',
 *   runtimeFlags: ['--chrome'],
 *   promptFilePath: '/tmp/prompt.md',
 * };
 * ```
 */
export interface RuntimeAdapterConfig {
    /** Unique name for the PTY session */
    sessionName: string;
    /** Working directory for the agent */
    projectPath: string;
    /** Optional CLI flags injected before --dangerously-skip-permissions */
    runtimeFlags?: string[];
    /** Optional path to a system prompt file */
    promptFilePath?: string;
    /** Optional environment variables to set in the session shell */
    env?: Record<string, string>;
}
/**
 * Unified interface for AI runtime adapters.
 *
 * Each implementation wraps a specific runtime CLI (Claude Code, Gemini CLI, Codex)
 * and provides a consistent API for managing agent sessions. Adapters handle the
 * full lifecycle: session creation, runtime initialization, I/O, and teardown.
 *
 * @example
 * ```typescript
 * const adapter = getRuntimeAdapter('claude-code');
 *
 * await adapter.start({ sessionName: 'agent-1', projectPath: '/project' });
 * await adapter.write('agent-1', 'Hello, build a REST API');
 * const output = await adapter.getOutput('agent-1');
 * await adapter.stop('agent-1');
 * ```
 */
export interface RuntimeAdapter {
    /** The runtime type this adapter handles */
    readonly runtimeType: RuntimeType;
    /** Human-readable display name for this runtime */
    readonly displayName: string;
    /**
     * Start a new agent session.
     *
     * Creates a PTY session, sets environment variables, and launches the
     * runtime CLI with the specified configuration.
     *
     * @param config - Session configuration
     * @throws Error if session creation or runtime initialization fails
     */
    start(config: RuntimeAdapterConfig): Promise<void>;
    /**
     * Stop an agent session and clean up resources.
     *
     * @param sessionName - Name of the session to stop
     * @throws Error if session does not exist
     */
    stop(sessionName: string): Promise<void>;
    /**
     * Write data to an agent session's stdin.
     *
     * @param sessionName - Name of the target session
     * @param data - Data to write (sent via the session's shell)
     * @throws Error if session does not exist
     */
    write(sessionName: string, data: string): Promise<void>;
    /**
     * Get recent output from an agent session.
     *
     * @param sessionName - Name of the target session
     * @param lines - Number of recent lines to capture (default: 50)
     * @returns Captured terminal output as a string
     * @throws Error if session does not exist
     */
    getOutput(sessionName: string, lines?: number): Promise<string>;
    /**
     * Check if a session is currently running.
     *
     * @param sessionName - Name of the session to check
     * @returns True if the session exists and is active
     */
    isRunning(sessionName: string): boolean;
    /**
     * Wait for the runtime CLI to become ready after initialization.
     *
     * Polls the session output for runtime-specific ready patterns.
     *
     * @param sessionName - Name of the session to monitor
     * @param timeout - Maximum wait time in milliseconds (default: 60000)
     * @returns True if runtime became ready within timeout, false otherwise
     */
    waitForReady(sessionName: string, timeout?: number): Promise<boolean>;
    /**
     * Detect if the runtime CLI is currently active in a session.
     *
     * Uses runtime-specific detection strategies (e.g., sending '/' to trigger
     * a command palette and checking for output changes).
     *
     * @param sessionName - Name of the session to check
     * @returns True if the runtime is detected as running
     */
    detectRuntime(sessionName: string): Promise<boolean>;
    /**
     * Trigger context window compaction for a session.
     *
     * Sends the runtime-specific compact/compress command to reduce context usage.
     * Each runtime handles this differently:
     * - Claude Code: `/compact` — LLM-based summarization
     * - Gemini CLI: `/compress` — summarizer persona with context snapshots
     * - Codex CLI: `/compact` — server-side opaque compaction
     *
     * @param sessionName - Name of the session to compact
     * @returns True if the compact command was sent successfully
     */
    compact(sessionName: string): Promise<boolean>;
}
/**
 * Base adapter that delegates to the existing RuntimeAgentService and ISessionBackend.
 *
 * Concrete adapters extend this class and provide their runtime type.
 * The base handles all common operations — subclasses only need to override
 * behavior that differs from the default.
 */
declare abstract class BaseRuntimeAdapter implements RuntimeAdapter {
    abstract readonly runtimeType: RuntimeType;
    abstract readonly displayName: string;
    protected sessionBackend: ISessionBackend;
    protected sessionHelper: SessionCommandHelper;
    protected runtimeService: RuntimeAgentService;
    constructor(sessionBackend: ISessionBackend, sessionHelper: SessionCommandHelper, runtimeService: RuntimeAgentService);
    /**
     * Start a new agent session with the runtime CLI.
     *
     * Creates a PTY shell, sets environment variables, and executes the
     * runtime initialization script.
     *
     * @param config - Session start configuration
     */
    start(config: RuntimeAdapterConfig): Promise<void>;
    /** @inheritdoc */
    stop(sessionName: string): Promise<void>;
    /** @inheritdoc */
    write(sessionName: string, data: string): Promise<void>;
    /** @inheritdoc */
    getOutput(sessionName: string, lines?: number): Promise<string>;
    /** @inheritdoc */
    isRunning(sessionName: string): boolean;
    /** @inheritdoc */
    waitForReady(sessionName: string, timeout?: number): Promise<boolean>;
    /** @inheritdoc */
    detectRuntime(sessionName: string): Promise<boolean>;
    /**
     * Send the runtime-specific compact command to the session.
     *
     * @param sessionName - Name of the session to compact
     * @returns True if the compact command was sent successfully
     */
    compact(sessionName: string): Promise<boolean>;
}
/**
 * Adapter for Anthropic's Claude Code CLI.
 *
 * Full implementation — Claude Code is the default runtime.
 * Handles Claude-specific initialization, detection (slash command palette),
 * and MCP configuration.
 */
export declare class ClaudeCodeAdapter extends BaseRuntimeAdapter {
    readonly runtimeType: "claude-code";
    readonly displayName = "Claude Code";
    /**
     * Start a Claude Code session.
     *
     * Extends the base start with Claude-specific post-initialization
     * (MCP server configuration).
     *
     * @param config - Session start configuration
     */
    start(config: RuntimeAdapterConfig): Promise<void>;
}
/**
 * Adapter for Google's Gemini CLI.
 *
 * Stub implementation — basic structure in place for future development.
 * Uses the base adapter behavior which delegates to GeminiRuntimeService.
 */
export declare class GeminiCliAdapter extends BaseRuntimeAdapter {
    readonly runtimeType: "gemini-cli";
    readonly displayName = "Gemini CLI";
}
/**
 * Adapter for OpenAI's Codex CLI.
 *
 * Stub implementation — basic structure in place for future development.
 * Uses the base adapter behavior which delegates to CodexRuntimeService.
 */
export declare class CodexAdapter extends BaseRuntimeAdapter {
    readonly runtimeType: "codex-cli";
    readonly displayName = "OpenAI Codex";
}
/**
 * Creates a RuntimeAdapter for the specified runtime type.
 *
 * Uses the existing RuntimeServiceFactory and session backend to construct
 * the appropriate adapter. Requires the session backend to be initialized
 * first (via createSessionBackend()).
 *
 * @param runtimeType - The runtime type ('claude-code', 'gemini-cli', 'codex-cli')
 * @param projectRoot - The project root directory (for runtime config resolution)
 * @returns A RuntimeAdapter instance for the specified runtime
 * @throws Error if session backend is not initialized or runtime type is unknown
 *
 * @example
 * ```typescript
 * const adapter = getRuntimeAdapter('claude-code', '/home/user/project');
 * await adapter.start({ sessionName: 'agent-1', projectPath: '/project' });
 * ```
 */
export declare function getRuntimeAdapter(runtimeType: RuntimeType, projectRoot: string): RuntimeAdapter;
/**
 * Returns the list of all supported runtime types.
 *
 * @returns Array of RuntimeType values
 */
export declare function getSupportedRuntimeTypes(): RuntimeType[];
/**
 * Checks whether a given string is a supported runtime type.
 *
 * @param value - The string to check
 * @returns True if the value is a valid RuntimeType
 */
export declare function isSupportedRuntime(value: string): value is RuntimeType;
export {};
//# sourceMappingURL=runtime-adapter.d.ts.map