/**
 * @fileoverview Ralph Loop - Autonomous task execution engine.
 *
 * Orchestrates autonomous Claude sessions by:
 * - Polling for available tasks from the task queue
 * - Assigning tasks to idle sessions
 * - Monitoring completion and handling failures
 * - Auto-generating follow-up tasks when min duration not reached
 *
 * Key exports:
 * - `RalphLoop` class — the loop engine, extends EventEmitter
 * - `RalphLoopEvents` interface — typed event map
 * - `RalphLoopOptions` interface — configuration options
 *
 * Lifecycle: `start()` → poll loop → `stop()` (when all tasks done + min duration met)
 *
 * @dependencies session-manager (session lifecycle), task-queue (task FIFO),
 *   state-store (persistence), session (PTY execution), task (task model)
 * @consumedby web/server (ralph routes, SSE)
 * @emits started, stopped, taskAssigned, taskCompleted, taskFailed, error
 * @persistence Ralph loop state saved to `~/.codeman/state.json` (ralphLoop key)
 *
 * @module ralph-loop
 */
import { EventEmitter } from 'node:events';
import { RalphLoopStatus } from './types.js';
/**
 * Events emitted by RalphLoop
 */
/**
 * Configuration options for RalphLoop
 */
interface RalphLoopOptions {
    /** How often to check for new tasks (default from config) */
    pollIntervalMs?: number;
    /** Minimum time to run before stopping (null = no minimum) */
    minDurationMs?: number;
    /** Auto-generate follow-up tasks when queue is empty */
    autoGenerateTasks?: boolean;
}
/**
 * Autonomous task execution loop.
 *
 * @description
 * Manages the lifecycle of task execution:
 * 1. Start: Begin polling and task assignment
 * 2. Run: Assign tasks to idle sessions, monitor completion
 * 3. Stop: When all tasks done and min duration reached
 *
 * Supports time-aware loops that continue generating tasks
 * until a minimum duration is reached.
 *
 * @extends EventEmitter
 */
export declare class RalphLoop extends EventEmitter {
    private sessionManager;
    private taskQueue;
    private store;
    private pollIntervalMs;
    private minDurationMs;
    private autoGenerateTasks;
    private loopTimer;
    private _status;
    private startedAt;
    private tasksCompleted;
    private tasksGenerated;
    /** Bound event handlers for cleanup (prevents memory leaks) */
    private sessionEventHandlers;
    constructor(options?: RalphLoopOptions);
    private setupEventHandlers;
    /** Remove event listeners to prevent memory leaks */
    private cleanupEventHandlers;
    get status(): RalphLoopStatus;
    isRunning(): boolean;
    getElapsedMs(): number;
    getElapsedHours(): number;
    isMinDurationReached(): boolean;
    getStats(): {
        activeSessions: number;
        idleSessions: number;
        busySessions: number;
        total: number;
        pending: number;
        running: number;
        completed: number;
        failed: number;
        status: RalphLoopStatus;
        elapsedMs: number;
        elapsedHours: number;
        minDurationMs: number | null;
        minDurationReached: boolean;
        tasksCompleted: number;
        tasksGenerated: number;
    };
    /** Starts the task execution loop. */
    start(): Promise<void>;
    /** Stops the task execution loop. */
    stop(): void;
    /** Pauses the loop (can be resumed). */
    pause(): void;
    /** Resumes a paused loop. */
    resume(): void;
    private runLoop;
    private tick;
    private assignTasks;
    private assignTaskToSession;
    private checkTimeouts;
    private handleSessionCompletion;
    private handleSessionError;
    private handleSessionStopped;
    private handleSessionTaskError;
    private shouldGenerateTasks;
    private generateFollowUpTasks;
    private shouldStop;
    /** Sets the minimum duration in hours before the loop can stop. */
    setMinDuration(hours: number): void;
    /**
     * Destroys the loop and cleans up all resources.
     * Use this for complete cleanup (e.g., in tests or before creating a new instance).
     * After calling destroy(), the instance should not be reused.
     */
    destroy(): void;
}
/** Gets or creates the singleton RalphLoop instance. */
export declare function getRalphLoop(options?: RalphLoopOptions): RalphLoop;
export {};
//# sourceMappingURL=ralph-loop.d.ts.map