/**
 * PTY Session Backend Module
 *
 * Implements the ISessionBackend interface using node-pty and @xterm/headless.
 * Provides a full terminal emulation backend with memory-bounded output buffers.
 *
 * @module pty-session-backend
 */
import type { ISessionBackend, ISession, SessionOptions } from '../session-backend.interface.js';
import { PtyTerminalBuffer } from './pty-terminal-buffer.js';
/**
 * PTY Session Backend implementation.
 *
 * Manages terminal sessions using node-pty for process spawning and
 * @xterm/headless for terminal emulation and output buffering.
 *
 * Features:
 * - In-memory session management via Map
 * - Terminal emulation with xterm.js headless
 * - Memory-bounded output buffers (max 10MB)
 * - Proper cleanup on session termination
 *
 * @example
 * ```typescript
 * const backend = new PtySessionBackend();
 *
 * // Create a session
 * const session = await backend.createSession('dev', {
 *   cwd: '/home/user/project',
 *   command: '/bin/bash',
 * });
 *
 * // Capture output
 * const output = backend.captureOutput('dev', 50);
 *
 * // Cleanup
 * await backend.destroy();
 * ```
 */
export declare class PtySessionBackend implements ISessionBackend {
    /**
     * Map of session names to PtySession instances
     */
    private sessions;
    /**
     * Map of session names to PtyTerminalBuffer instances
     */
    private terminalBuffers;
    /**
     * Map of session names to cumulative output bytes since last compact
     */
    private cumulativeOutputBytes;
    /**
     * Map of session names to writable file streams for persistent session logs
     */
    private sessionLogStreams;
    /**
     * Directory for persistent session log files
     */
    private sessionLogsDir;
    /**
     * Logger for this backend
     */
    private logger;
    /**
     * Regex patterns for stripping ANSI escape codes from terminal output
     */
    private static readonly ANSI_STRIP_PATTERNS;
    /**
     * Create a new PTY session backend.
     */
    constructor();
    /**
     * Create a new terminal session.
     *
     * @param name - Unique name for the session
     * @param options - Session configuration options
     * @returns Promise resolving to the created session
     * @throws Error if session name already exists
     *
     * @example
     * ```typescript
     * const session = await backend.createSession('my-session', {
     *   cwd: '/home/user',
     *   command: '/bin/bash',
     *   args: ['--login'],
     *   env: { NODE_ENV: 'development' },
     *   cols: 120,
     *   rows: 40,
     * });
     * ```
     */
    createSession(name: string, options: SessionOptions): Promise<ISession>;
    /**
     * Get an existing session by name.
     *
     * @param name - Name of the session to retrieve
     * @returns The session if found, undefined otherwise
     *
     * @example
     * ```typescript
     * const session = backend.getSession('my-session');
     * if (session) {
     *   session.write('echo hello\n');
     * }
     * ```
     */
    getSession(name: string): ISession | undefined;
    /**
     * Kill a session by name.
     *
     * @param name - Name of the session to kill
     * @returns Promise that resolves when the session is killed
     *
     * @example
     * ```typescript
     * await backend.killSession('my-session');
     * ```
     */
    killSession(name: string): Promise<void>;
    /**
     * List all active session names.
     *
     * @returns Array of session names
     *
     * @example
     * ```typescript
     * const sessions = backend.listSessions();
     * console.log('Active sessions:', sessions);
     * ```
     */
    listSessions(): string[];
    /**
     * Check if a session exists by name.
     *
     * @param name - Name of the session to check
     * @returns true if the session exists, false otherwise
     *
     * @example
     * ```typescript
     * if (backend.sessionExists('my-session')) {
     *   console.log('Session is running');
     * }
     * ```
     */
    sessionExists(name: string): boolean;
    /**
     * Get the cumulative output bytes for a session since last reset.
     * Used by ContextWindowMonitorService for proactive compaction.
     *
     * @param name - Name of the session
     * @returns Cumulative output bytes, or 0 if session not tracked
     */
    getCumulativeOutputBytes(name: string): number;
    /**
     * Reset the cumulative output byte counter for a session.
     * Called after a proactive compact is triggered.
     *
     * @param name - Name of the session
     */
    resetCumulativeOutput(name: string): void;
    /**
     * Capture recent output from a session.
     *
     * @param name - Name of the session
     * @param lines - Number of lines to capture (default: 100)
     * @returns Captured output as a string
     *
     * @example
     * ```typescript
     * const output = backend.captureOutput('my-session', 50);
     * console.log('Recent output:', output);
     * ```
     */
    captureOutput(name: string, lines?: number): string;
    /**
     * Get the full terminal buffer content for a session.
     *
     * @param name - Name of the session
     * @returns Full buffer content as a string
     *
     * @example
     * ```typescript
     * const buffer = backend.getTerminalBuffer('my-session');
     * console.log('Full buffer:', buffer);
     * ```
     */
    getTerminalBuffer(name: string): string;
    /**
     * Get raw output history with ANSI escape codes preserved.
     *
     * @param name - Name of the session
     * @returns Raw output history as a string with ANSI codes
     *
     * @example
     * ```typescript
     * const rawHistory = backend.getRawHistory('my-session');
     * terminal.write(rawHistory);
     * ```
     */
    getRawHistory(name: string): string;
    /**
     * Get the serialized visual state of the terminal as plain text.
     *
     * Unlike getRawHistory() which returns raw bytes including cursor movement
     * sequences that cause corruption when replayed at different terminal
     * dimensions, this returns the rendered visual state — the final text after
     * all cursor movements and erases have been processed by the headless terminal.
     *
     * Flushes pending terminal writes before reading to ensure completeness.
     *
     * @param name - Name of the session
     * @returns Promise resolving to serialized terminal state safe for any dimensions
     */
    getSerializedState(name: string): Promise<string>;
    /**
     * Get the PIDs of all active sessions.
     *
     * @returns Array of process IDs for all active sessions
     *
     * @example
     * ```typescript
     * const pids = backend.getAllSessionPids();
     * console.log('Active PIDs:', pids);
     * ```
     */
    getAllSessionPids(): number[];
    /**
     * Destroy the backend and clean up all resources.
     *
     * @returns Promise that resolves when cleanup is complete
     *
     * @example
     * ```typescript
     * await backend.destroy();
     * ```
     */
    destroy(): Promise<void>;
    /**
     * Forcefully destroy all sessions with SIGTERM → SIGKILL escalation.
     *
     * This method is designed for shutdown scenarios where child processes
     * (Claude Code, Gemini CLI) may catch or ignore SIGHUP/SIGTERM.
     * It collects all PIDs upfront, sends SIGTERM, waits, then SIGKILLs
     * each process and its process group.
     *
     * @returns Promise that resolves after the force-kill sequence completes
     *
     * @example
     * ```typescript
     * await backend.forceDestroyAll();
     * ```
     */
    forceDestroyAll(): Promise<void>;
    /**
     * Check if a child process is alive inside a session's PTY shell.
     *
     * Delegates to PtySession.isChildProcessAlive() to detect whether
     * the runtime (e.g. Claude Code) is still running inside the shell.
     *
     * @param name - Name of the session to check
     * @returns true if the session exists and has a living child process
     */
    isChildProcessAlive(name: string): boolean;
    /**
     * Get the number of active sessions.
     *
     * @returns Number of active sessions
     */
    getSessionCount(): number;
    /**
     * Resize a session's terminal.
     *
     * @param name - Name of the session
     * @param cols - Number of columns
     * @param rows - Number of rows
     * @throws Error if session does not exist
     */
    resizeSession(name: string, cols: number, rows: number): void;
    /**
     * Get the raw output history for a session.
     *
     * This returns the raw bytes written to the terminal, including ANSI
     * sequences. Useful for replaying the session.
     *
     * @param name - Name of the session
     * @returns Raw output history as a string
     *
     * @example
     * ```typescript
     * const history = backend.getSessionHistory('my-session');
     * ```
     */
    getSessionHistory(name: string): string;
    /**
     * Get the terminal buffer instance for a session.
     *
     * @param name - Name of the session
     * @returns The PtyTerminalBuffer instance if found, undefined otherwise
     */
    getTerminalBufferInstance(name: string): PtyTerminalBuffer | undefined;
    /**
     * Get the file path for a session's persistent log file.
     *
     * @param sessionName - Name of the session
     * @returns Absolute path to the session log file
     */
    getSessionLogPath(sessionName: string): string;
    /**
     * Open a writable file stream for a session log.
     * If a log file already exists (from a previous run), appends a restart separator.
     *
     * @param sessionName - Name of the session
     */
    private openSessionLogStream;
    /**
     * Write ANSI-stripped terminal data to a session's persistent log file.
     *
     * @param sessionName - Name of the session
     * @param data - Raw terminal data (with ANSI codes)
     */
    private writeToSessionLog;
    /**
     * Close and remove the file stream for a session log.
     *
     * @param sessionName - Name of the session
     */
    private closeSessionLogStream;
}
//# sourceMappingURL=pty-session-backend.d.ts.map