/**
 * Background command monitor.
 *
 * When the agent starts a long-running shell command in "background" mode
 * (e.g. `execute` / `terminal.run` with `isBackground: true` for a test run,
 * build, or one-shot task), the tool returns immediately so the agent can end
 * its turn. This monitor watches the persistent terminal for the OSC 633
 * shell-integration "command done" marker and, when the command finishes,
 * invokes a completion handler so the agent can be automatically re-triggered
 * to react to the result — instead of the user having to type "continue".
 *
 * Never-ending processes (servers, watchers) simply never emit the done marker,
 * so they never fire the handler (and are dropped after `maxWatchMs`).
 */
/** Minimal terminal-surface contract the monitor needs (satisfied by TerminalSurface). */
export interface MonitorableSurface {
    addOutputListener(listener: (data: string) => void): void;
    removeOutputListener(listener: (data: string) => void): void;
}
export interface BackgroundCommandResult {
    sessionId: string;
    terminalId: string;
    command: string;
    /** Exit code from OSC 633;D, or null when unavailable. */
    exitCode: number | null;
    /** Cleaned command output (OSC/ANSI stripped, echoed command removed, tail-truncated). */
    output: string;
    durationMs: number;
}
export type BackgroundCompletionHandler = (result: BackgroundCommandResult) => void | Promise<void>;
export interface TrackBackgroundCommandOptions {
    sessionId: string;
    terminalId: string;
    command: string;
    surface: MonitorableSurface;
    /** Optional sentinel printed by the terminal tool when shell integration is unavailable. */
    completionToken?: string;
    /**
     * Stop watching after this long. Guards against never-ending processes
     * (servers/watchers) leaking listeners forever. Default 30 minutes.
     */
    maxWatchMs?: number;
}
/** Strip OSC 633 + ANSI, drop the echoed command line, and tail-truncate. */
export declare function extractCompletionOutput(raw: string, command: string): string;
declare class BackgroundCommandMonitor {
    private handler;
    private readonly active;
    /**
     * Register the (single) handler invoked when a tracked background command
     * finishes. Returns an unregister function. A later call replaces the
     * previous handler.
     */
    setCompletionHandler(handler: BackgroundCompletionHandler): () => void;
    /** Number of commands currently being watched (for tests/introspection). */
    get activeCount(): number;
    /**
     * Begin watching a background command for completion. Non-blocking: attaches
     * an output listener to the terminal surface and returns immediately.
     */
    track(options: TrackBackgroundCommandOptions): void;
    /** Stop watching every background command for a session (e.g. on session close). */
    stopForSession(sessionId: string): void;
    clearForTests(): void;
}
/** Process-wide singleton, mirroring `interventionRunResumeRegistry`. */
export declare const backgroundCommandMonitor: BackgroundCommandMonitor;
export {};
//# sourceMappingURL=background-command-monitor.d.ts.map