/** * SpecForge Autopilot Type Definitions * * Types for the autonomous ticket implementation engine. */ import type { Ticket, Epic, Specification, TicketStatus } from '../types/index.js'; import type { Blueprint } from '../cli/commands/blueprints.types.js'; import type { ReadinessConfig } from './readiness/types.js'; import type { PreflightResult } from './readiness/preflight.js'; /** * Overall autopilot run status */ export type AutopilotStatus = 'idle' | 'running' | 'paused' | 'completed' | 'failed' | 'aborted' | 'rate_limited' | 'cost_limit_reached'; /** * Worker status */ export type WorkerStatus = 'idle' | 'implementing' | 'validating' | 'committing' | 'failed' | 'paused'; /** * Ticket implementation result */ export type TicketResult = 'success' | 'failed' | 'skipped' | 'rate_limited' | 'timeout'; /** * Main autopilot state tracking */ export interface AutopilotState { /** Unique run ID */ runId: string; /** Current status */ status: AutopilotStatus; /** Specification being processed */ specificationId: string; /** Project ID */ projectId: string; /** When run started */ startedAt: Date; /** When run ended */ endedAt?: Date; /** When paused */ pausedAt?: Date; /** Active worker sessions */ workers: WorkerSession[]; /** Total number of tickets to process */ totalTickets?: number; /** Completed tickets */ completedTickets: string[]; /** Failed tickets */ failedTickets: FailedTicket[]; /** Skipped tickets (blocked or dependencies failed) */ skippedTickets: string[]; /** Current epic being processed (ID) */ currentEpicId?: string; /** Current epic title for display */ currentEpic?: string; /** Total estimated cost so far */ totalCostUsd: number; /** Total tokens used */ totalTokens: TokenUsage; /** Rate limit info if rate limited */ rateLimitInfo?: RateLimitInfo; /** Pause reason if paused */ pauseReason?: string; /** Error message if aborted */ errorMessage?: string; } /** * Token usage tracking */ export interface TokenUsage { inputTokens: number; outputTokens: number; } /** * Rate limit information */ export interface RateLimitInfo { hitAt: Date; message: string; estimatedResumeAt?: Date; } /** * Failed ticket information */ export interface FailedTicket { ticketId: string; error: string; attempts: number; retryCount: number; lastAttemptAt: Date; } /** * Worker session state */ export interface WorkerSession { /** Worker ID (0-indexed) */ workerId: number; /** Current status */ status: WorkerStatus; /** Current ticket being processed */ currentTicketId?: string; /** Git worktree path */ worktreePath: string; /** Branch name for this worker */ branchName: string; /** Tickets completed by this worker */ completedCount: number; /** Tickets failed by this worker */ failedCount: number; /** Total cost incurred by this worker */ costUsd: number; /** Token usage for current ticket */ currentTokens?: TokenUsage; /** When started processing current ticket */ ticketStartedAt?: Date; /** Last error message */ lastError?: string; /** Number of retries on current ticket */ retryCount: number; } /** * File pattern matcher */ export interface FileMatcher { /** Glob patterns to match */ patterns: string[]; /** Patterns to exclude */ exclude?: string[]; } /** * Tag matcher for profile selection */ export interface ProfileTagMatcher { /** Tags that must be present (AND) */ required?: string[]; /** Tags where any match triggers selection (OR) */ anyOf?: string[]; /** Tags that exclude this profile */ exclude?: string[]; } /** * Validation command configuration */ export interface ValidationCommand { /** Command name for display */ name: string; /** The command to run */ command: string; /** Whether the command must pass for success */ required: boolean; /** Timeout in ms */ timeoutMs?: number; /** Working directory (relative to worktree) */ cwd?: string; } /** * Agent profile for specialized implementations */ export interface AgentProfile { /** Profile ID */ id: string; /** Display name */ name: string; /** Description */ description: string; /** File patterns this profile handles */ fileMatchers: FileMatcher[]; /** Tag matchers for selection */ tagMatchers?: ProfileTagMatcher; /** Default model to use */ model?: string; /** System prompt additions */ systemPromptAdditions?: string; /** Validation commands to run after implementation */ validationCommands?: ValidationCommand[]; /** Maximum timeout for this profile (ms) */ timeoutMs?: number; /** Profile priority (higher = more specific) */ priority?: number; } /** * AI Provider configuration for autopilot */ export interface AutopilotAIProviderConfig { /** Provider mode (always claude_code for autopilot) */ mode: 'claude_code'; /** Maximum parallel Claude processes */ maxParallelProcesses: number; /** Request timeout in seconds */ requestTimeoutSeconds: number; /** Maximum retries per request */ maxRetries: number; } /** * Branch strategy options */ export type BranchStrategy = 'per-epic' | 'per-ticket' | 'single'; /** * Autopilot configuration */ export interface AutopilotConfig { /** Maximum parallel workers (worktrees) */ maxParallelWorkers: number; /** Maximum total cost before pausing (USD) */ maxTotalCostUsd: number; /** Branch strategy */ branchStrategy: BranchStrategy; /** Auto-commit after each ticket */ autoCommit: boolean; /** Auto-push after commits */ autoPush: boolean; /** AI Provider configuration */ aiProvider: AutopilotAIProviderConfig; /** Per-ticket timeout (ms) */ ticketTimeoutMs: number; /** Maximum retries per ticket */ maxTicketRetries: number; /** Pause at 80% of timeout */ warnAtTimeoutPercent: number; /** API sync interval (ms) */ syncIntervalMs: number; /** Log file path */ logPath?: string; /** Agent profiles */ agentProfiles?: AgentProfile[]; /** Readiness threshold configuration */ readiness?: ReadinessConfig; } /** * Default autopilot configuration */ export declare const DEFAULT_AUTOPILOT_CONFIG: AutopilotConfig; /** * Ticket queue item with dependency info */ export interface QueuedTicket { ticketId: string; epicId: string; /** Tickets that must complete before this one */ dependsOn: string[]; /** Whether dependencies are satisfied */ ready: boolean; /** Priority (lower is higher priority) */ priority: number; /** Complexity estimate */ complexity: 'small' | 'medium' | 'large' | 'xlarge'; /** Readiness score for priority boost (higher = more ready) */ readinessScore?: number | null; } /** * Dependency graph node */ export interface DependencyNode { ticketId: string; status: TicketStatus; dependsOn: string[]; blockedBy: string[]; /** True if all dependencies are completed */ ready: boolean; } /** * Autopilot event types */ export interface AutopilotEventMap { 'state:changed': AutopilotState; 'worker:started': { workerId: number; ticketId: string; }; 'worker:completed': { workerId: number; ticketId: string; result: TicketResult; }; 'worker:failed': { workerId: number; ticketId: string; error: string; }; 'ticket:started': { ticketId: string; workerId: number; }; 'ticket:completed': { ticketId: string; result: TicketResult; costUsd: number; }; 'ticket:failed': { ticketId: string; error: string; retryable: boolean; }; 'ticket:rescored': { ticketId: string; previousScore: number | null; newScore: number; delta: number; level: string; }; 'epic:started': { epicId: string; }; 'epic:completed': { epicId: string; completedTickets: number; failedTickets: number; }; 'rate_limit:hit': { message: string; }; 'rate_limit:cleared': void; 'cost:warning': { currentCost: number; maxCost: number; }; 'cost:exceeded': { currentCost: number; maxCost: number; }; 'timeout:warning': { ticketId: string; percentUsed: number; }; 'timeout:exceeded': { ticketId: string; }; 'paused': { reason: string; }; 'resumed': void; 'aborted': { reason: string; }; 'completed': { summary: RunSummary; }; 'readiness:preflight': { result: PreflightResult; }; } /** * Summary of an autopilot run */ export interface RunSummary { runId: string; specificationId: string; projectId: string; status: AutopilotStatus; startedAt: Date; endedAt: Date; durationMs: number; totalTickets: number; completedTickets: number; failedTickets: number; skippedTickets: number; totalCostUsd: number; totalTokens: TokenUsage; epicsProcessed: number; workerCount: number; averageTicketTimeMs: number; errors: string[]; /** Readiness score improvement across completed tickets */ readinessImprovement?: { avgBefore: number; avgAfter: number; ticketsImproved: number; }; } /** * Ticket with full context for implementation */ export interface TicketContext { ticket: Ticket; epic: Epic; specification: Specification; dependencies: { blockedBy: Array<{ id: string; title: string; status: TicketStatus; }>; blocks: Array<{ id: string; title: string; status: TicketStatus; }>; }; patterns?: Record; blueprints?: Array<{ blueprint: Blueprint; context?: string; section?: string; }>; readiness?: { score: number; level: string; missing: string[]; evolve: string[]; }; } /** * Implementation result from agent */ export interface ImplementationResult { success: boolean; output?: string; error?: string; filesModified?: string[]; filesCreated?: string[]; filesDeleted?: string[]; testsPassed?: boolean; tokensUsed?: TokenUsage; costUsd?: number; durationMs?: number; /** Model used for implementation */ modelUsed?: 'sonnet' | 'opus'; /** Commit SHA if auto-commit was performed */ commitSha?: string; /** Discoveries parsed from AI output */ discoveries?: ParsedDiscovery[]; /** Session ID for linking to Claude Code JSONL logs */ sessionId?: string; } /** * Discovery parsed from AI output using explicit markers */ export interface ParsedDiscovery { type: DiscoveryType; severity: DiscoverySeverity; title: string; description: string; } /** * Discovery types */ export type DiscoveryType = 'bug' | 'technical_debt' | 'new_requirement' | 'question' | 'blocker' | 'improvement'; /** * Discovery severity levels */ export type DiscoverySeverity = 'low' | 'medium' | 'high' | 'critical'; /** * Audit log entry types */ export type AuditEventType = 'run_started' | 'run_completed' | 'run_aborted' | 'run_paused' | 'run_resumed' | 'ticket_started' | 'ticket_completed' | 'ticket_failed' | 'ticket_skipped' | 'epic_started' | 'epic_completed' | 'rate_limit_hit' | 'rate_limit_cleared' | 'cost_warning' | 'cost_exceeded' | 'worker_spawned' | 'worker_terminated' | 'worktree_created' | 'worktree_removed' | 'branch_created' | 'branch_merged' | 'commit_created' | 'sync_completed' | 'sync_failed'; /** * Audit log entry */ export interface AuditLogEntry { timestamp: Date; runId: string; event: AuditEventType; data: Record; workerId?: number; ticketId?: string; epicId?: string; error?: string; } /** * Progress information for display */ export interface ProgressInfo { status: AutopilotStatus; currentEpic?: { id: string; title: string; progress: number; ticketsDone: number; ticketsTotal: number; }; workers: Array<{ id: number; status: WorkerStatus; currentTicket?: string; progress?: number; }>; overall: { ticketsDone: number; ticketsTotal: number; ticketsFailed: number; ticketsSkipped: number; progress: number; costUsd: number; elapsedMs: number; estimatedRemainingMs?: number; }; rateLimited?: boolean; rateLimitMessage?: string; } //# sourceMappingURL=types.d.ts.map