import type { AgentRuntime } from '@coralai/claude-code-agent';
import type { CompletionJudge } from './completion-judge.js';
import type { ProcessSupervisor } from './supervisor.js';
import type { InspectQuery, RecoveryContext, RecoveryResult, TaskCancelRequest, TaskConfirmRequest, TaskInputRequest, TaskResumeRequest, TaskRunRequest, TaskRunResponse, WorkerEventHandler, WorkerManager, WorkerSnapshot } from './worker-manager.js';
export interface WorkerManagerDeps {
    supervisor: ProcessSupervisor;
    completionJudge: CompletionJudge;
    agentRuntime: AgentRuntime | null;
    stateFile: string;
    maxWorkers: number;
}
export declare class WorkerManagerImpl implements WorkerManager {
    private readonly supervisor;
    private readonly completionJudge;
    private readonly agentRuntime;
    private readonly stateFile;
    private readonly maxWorkers;
    private readonly eventHandlers;
    private readonly taskSlotMap;
    private readonly timeouts;
    /** Abort controllers for ACP completion monitors keyed by slot name. */
    private readonly acpMonitorAborts;
    constructor(deps: WorkerManagerDeps);
    run(request: TaskRunRequest): Promise<TaskRunResponse>;
    resume(request: TaskResumeRequest): Promise<TaskRunResponse>;
    cancel(request: TaskCancelRequest): Promise<void>;
    inspect(query: InspectQuery): WorkerSnapshot[];
    onEvent(handler: WorkerEventHandler): void;
    sendInput(request: TaskInputRequest): Promise<void>;
    confirm(request: TaskConfirmRequest): Promise<void>;
    recover(contexts: RecoveryContext[]): Promise<RecoveryResult>;
    private acquireAndSpawn;
    private handleExit;
    /**
     * Poll ACP session until run reaches terminal state, then emit event.
     *
     * ACP protocol provides authoritative completion status:
     *   - completed → trust directly, emit run.completed (skip CompletionJudge)
     *   - failed/cancelled → trust directly, emit run.failed
     *   - lost (process died) → fall back to CompletionJudge (check git evidence)
     *   - timeout → fall back to CompletionJudge
     *
     * This avoids the old pattern of converting everything to exitCode and
     * letting CompletionJudge guess from git artifacts.
     */
    private monitorAcpCompletion;
    /**
     * Finalize an ACP worker with a known status — emit event and release resources.
     * Bypasses CompletionJudge since ACP protocol provides authoritative status.
     */
    private finalizeAcpWorker;
    /** Clear currentRun in session state so the slot can be reused for next task. */
    private clearAcpSessionRun;
    /**
     * R1: Worker PID is still alive — re-attach orphan monitoring.
     */
    private recoverAliveWorker;
    /**
     * Decision matrix for dead workers (R2-R7).
     * Returns a WorkerEvent for completed/failed, or null if slot was released.
     */
    private judgeDeadWorker;
    /**
     * Create a WorkerEvent for recovery results.
     */
    private makeRecoveryEvent;
    /**
     * Try to push unpushed commits from a worktree as a rescue operation.
     */
    private rescuePush;
    /**
     * Check if a process is still alive by sending signal 0.
     */
    private isPidAlive;
    private rd;
    private wr;
    private findIdleSlot;
    private claimSlot;
    private releaseSlotInState;
    private mapWorkerState;
    private requireAgentSlot;
    private startTimeout;
    private clearTimeoutForTask;
    private emitEvent;
    cleanup(): void;
    private reject;
    private log;
    /**
     * Atomically write the per-slot "current card" marker file that hook scripts
     * consult to know which card is currently being worked on. Delegates to the
     * shared markerFile utility; reports non-fatal write errors to the logger.
     */
    private writeCurrentCardFile;
    /**
     * Merge sessionId + pid into the existing marker file after a successful
     * spawn. Non-fatal: if the marker was deleted or patching fails, the base
     * info (cardId/stage) from the first write is still there so hooks work.
     */
    private patchCurrentCardFile;
}
//# sourceMappingURL=worker-manager-impl.d.ts.map