/** * Autopilot Dispatcher * * Main orchestrator for epics, ticket queue, and worker assignment. */ import { EventEmitter } from 'events'; import type { Epic, Ticket } from '../../types/index.js'; import type { AutopilotConfig, AutopilotState, RunSummary, ImplementationResult } from '../types.js'; import { StateManager } from './state-manager.js'; import { DependencyResolver } from './dependency-resolver.js'; import type { AutopilotApiClient } from '../api/autopilot-api-client.js'; import { type PreflightResult } from '../readiness/preflight.js'; /** * Resume options for handling previously failed tickets */ export interface ResumeOptions { skipFailed?: boolean; retryFailed?: boolean; previousState?: AutopilotState; } /** * Dispatcher configuration */ export interface DispatcherOptions { config: AutopilotConfig; apiClient: AutopilotApiClient; specificationId: string; projectId: string; workingDirectory: string; epicId?: string; resumeOptions?: ResumeOptions; onImplementTicket?: (ticket: Ticket, workerId: number, worktreePath: string) => Promise; } /** * Dispatcher Events */ export interface DispatcherEvents { 'started': void; 'paused': { reason: string; }; 'resumed': void; 'completed': RunSummary; 'aborted': { reason: string; }; 'state:changed': AutopilotState; 'epic:started': { epic: Epic; }; 'epic:completed': { epic: Epic; stats: { completed: number; failed: number; }; }; 'ticket:assigned': { ticketId: string; workerId: number; }; 'ticket:completed': { ticketId: string; workerId: number; }; 'ticket:failed': { ticketId: string; workerId: number; error: string; }; 'worker:idle': { workerId: number; }; 'cost:warning': { current: number; max: number; }; 'cost:exceeded': { current: number; max: number; }; 'rate_limit:paused': void; 'rate_limit:resumed': void; } /** * Autopilot Dispatcher * * Orchestrates the entire autopilot run. */ export declare class Dispatcher extends EventEmitter { private config; private apiClient; private stateManager; private dependencyResolver; private timeoutManager; private failureHandler; private rateLimitHandler; private workingDirectory; private onImplementTicket?; private epicIdFilter?; private resumeOptions?; private specification?; private epics; private currentEpicIndex; private ticketQueue; private activeWorkers; private isRunning; private isPaused; private shouldStop; private scoreDeltas; private preflightResult?; constructor(options: DispatcherOptions); /** * Set up internal event handlers */ private setupEventHandlers; /** * Start the autopilot run */ start(): Promise; /** * Load specification and epics from API */ private loadSpecification; /** * Collect readiness data for all tickets across loaded epics. * Uses the API client to fetch tickets and maps to TicketReadinessData. */ private collectTicketReadinessData; /** * Run pre-flight readiness check and emit result. * Throws if mode is 'block' and the check fails. */ private runPreflightReadinessCheck; /** * Apply resume options to handle previously failed tickets */ private applyResumeOptions; /** * Initialize worker sessions */ private initializeWorkers; /** * Process all epics */ private processEpics; /** * Process a single epic */ private processEpic; /** * Assign tickets to idle workers */ private assignTicketsToWorkers; /** * Process a single ticket */ private processTicket; /** * Handle successful ticket completion */ private handleTicketSuccess; /** * Handle ticket failure */ private handleTicketFailure; /** * Handle ticket timeout */ private handleTicketTimeout; /** * Refresh ticket queue for epic */ private refreshQueue; /** * Wait for at least one worker to complete */ private waitForWorkerCompletion; /** * Wait for all workers to complete */ private waitForAllWorkers; /** * Wait for resume from pause */ private waitForResume; /** * Wait for rate limit to clear */ private waitForRateLimitClear; /** * Check cost limits */ private checkCostLimits; /** * Estimate cost from tokens */ private estimateCost; /** * Pause the run */ pause(reason: string): void; /** * Resume the run */ resume(): void; /** * Complete the run */ private complete; /** * Abort the run */ abort(reason: string): RunSummary; /** * Build readiness improvement summary from accumulated score deltas */ private buildReadinessImprovement; /** * Cleanup resources */ private cleanup; /** * Get current state */ getState(): AutopilotState; /** * Get state manager */ getStateManager(): StateManager; /** * Get dependency resolver */ getDependencyResolver(): DependencyResolver; /** * Check if running */ isActive(): boolean; /** * Check if paused */ isPausedState(): boolean; /** * Get pre-flight result (available after start or runPreflight) */ getPreflightResult(): PreflightResult | undefined; /** * Run only the pre-flight check without starting the full run. * Used by --dry-run to display readiness information. */ runPreflight(): Promise; } /** * Create a dispatcher */ export declare function createDispatcher(options: DispatcherOptions): Dispatcher; //# sourceMappingURL=dispatcher.d.ts.map