import { EventEmitter } from 'events';
import { Project } from './types';
type RawBroadcastFn = (data: string) => void;
declare class TerminalManager extends EventEmitter {
    private terminals;
    /** Pending auto-restart timers, keyed by projectId. Tracked separately so stop() can cancel them. */
    private restartTimers;
    /** Consecutive crash count per project for exponential backoff */
    private crashCounts;
    /** Set of projects where the "no resumable session → drop --continue" one-shot
     *  fallback has already fired. Without this guard, the auto-restart timer
     *  unconditionally re-spawns with --continue + startTerminal resets
     *  crashCounts, so handleExit would see (crashes0=0, continueSession=true)
     *  again and fall back forever, never exhausting MAX_RESTART_RETRIES. Cleared
     *  on stop() / killForUpdate() / switchCliTool() — i.e. only when the project's
     *  PTY lifecycle restarts cleanly. */
    private continueFallbackDone;
    /** Throttle activity emissions to max once per 500ms per project */
    private activityThrottles;
    constructor();
    getOrCreate(project: Project, rawBroadcast?: RawBroadcastFn, continueSession?: boolean): void;
    updateBroadcast(projectId: string, rawBroadcast: RawBroadcastFn): void;
    /**
     * Write raw keystrokes directly to the PTY.
     * RED LINE: do NOT log `data` — see top-of-file comment.
     */
    writeRaw(projectId: string, data: string): void;
    /** Resize the PTY to match the browser terminal. */
    resize(projectId: string, cols: number, rows: number): void;
    stop(projectId: string): void;
    /**
     * Tear down the existing PTY (if any) and spawn a new one with the project's
     * current cliTool. Preserves the registered rawBroadcast so live WS clients
     * keep receiving output without reconnecting. Caller is responsible for
     * persisting `updatedProject.cliTool` to disk before calling.
     *
     * Emits a `cli-tool-switched` event so server bookkeeping (e.g. broadcasting
     * a `terminal_reset` WS message that asks browsers to clear their xterm
     * scrollback) can fire without reaching into projectClients from this file.
     */
    switchCliTool(updatedProject: Project, continueSession: boolean): void;
    /** Kill PTY without changing project status — used during update so resumeAll can restart with --continue. */
    killForUpdate(projectId: string): void;
    hasTerminal(projectId: string): boolean;
    /** Return an opaque identity for the current PTY instance, or null if
     *  none. Callers can cache this across an `await` and compare later to
     *  detect `stop()` + `start()` cycles that happened during the wait. */
    getTerminalRef(projectId: string): object | null;
    /** Return the accumulated raw scrollback for a project (for replay on reconnect). */
    getScrollback(projectId: string): string;
    /** Return epoch ms of last PTY data, or null if no terminal / never had data. */
    getLastActivityAt(projectId: string): number | null;
    /** Derive project status from in-memory state (not disk). Source of truth for running/restarting. */
    getProjectStatus(projectId: string): 'running' | 'restarting' | 'stopped';
    /** Return activity map for all running terminals: projectId → lastActivityAt ms. */
    getAllActivity(): Record<string, number>;
    /** Return IDs of all projects that have a terminal (including those with no output yet). */
    getAllRunningIds(): string[];
    resumeAll(): void;
    private startTerminal;
    private handleExit;
}
export declare const terminalManager: TerminalManager;
export {};
//# sourceMappingURL=terminal-manager.d.ts.map