/**
 * Cross-Session Pipeline Resume Flow
 *
 * Enables automated cross-session pipeline resume using the SQLite lifecycle schema.
 * Integrates with session initialization to check for and present resumable work.
 *
 * @task T4805 - Implement SQLite-backed Cross-Session Resume Flow
 * @epic T4798 - Lifecycle persistence improvements
 * @ref T4801 - SQLite schema with lifecycle tables
 * @ref T4800 - Pipeline state machine
 * @ref T4804 - Gate/evidence recording stubs
 * @ref T4798 - RCASD-IVTR+C lifecycle
 *
 * Functions:
 * - findResumablePipelines(): Query active pipelines from SQLite
 * - loadPipelineContext(): Load stage context via SQL JOINs
 * - resumeStage(): Resume a specific stage
 * - autoResume(): Auto-detect where to resume
 *
 * Usage:
 * ```typescript
 * import { findResumablePipelines, autoResume } from './resume.js';
 *
 * // Check for resumable work on session start
 * const resumable = await findResumablePipelines();
 * if (resumable.length > 0) {
 *   console.log(`Found ${resumable.length} resumable pipelines`);
 * }
 *
 * // Auto-detect resume point
 * const resumePoint = await autoResume();
 * if (resumePoint.canResume) {
 *   await resumeStage(resumePoint.taskId, resumePoint.stage);
 * }
 * ```
 */
import type { Stage } from './stages.js';
import type { StageStatus as DbStageStatus, PipelineStatus } from '@cleocode/contracts';
/**
 * Resumable pipeline information returned to callers.
 *
 * @task T4805
 * @ref T4798
 */
export interface ResumablePipeline {
    /** Task ID (e.g., T4805) */
    taskId: string;
    /** Pipeline ID */
    pipelineId: string;
    /** Current stage in the pipeline */
    currentStage: Stage;
    /** Pipeline status */
    status: PipelineStatus;
    /** When the pipeline started */
    startedAt: Date;
    /** When the pipeline was last updated */
    updatedAt: Date;
    /** Task title */
    taskTitle: string;
    /** Current stage status */
    stageStatus: DbStageStatus;
    /** Stage started at (if active) */
    stageStartedAt?: Date;
    /** Block reason if blocked */
    blockReason?: string;
    /** Previous session ID if known */
    previousSessionId?: string;
    /** Resume priority (lower = higher priority) */
    resumePriority: number;
}
/**
 * Pipeline context for session resume.
 *
 * @task T4805
 */
export interface PipelineContext {
    /** Task ID */
    taskId: string;
    /** Pipeline ID */
    pipelineId: string;
    /** Current stage */
    currentStage: Stage;
    /** All stages with their status */
    stages: StageContext[];
    /** Gate results for current stage */
    gateResults: GateResultContext[];
    /** Evidence linked to current stage */
    evidence: EvidenceContext[];
    /** Recent transitions */
    recentTransitions: TransitionContext[];
    /** Task details */
    task: TaskContext;
}
/**
 * Stage context within a pipeline.
 *
 * @task T4805
 */
export interface StageContext {
    /** Stage name */
    stage: Stage;
    /** Stage status */
    status: DbStageStatus;
    /** Sequence order */
    sequence: number;
    /** When started */
    startedAt?: Date;
    /** When completed */
    completedAt?: Date;
    /** Block information */
    blockedAt?: Date;
    blockReason?: string;
    /** Skip information */
    skippedAt?: Date;
    skipReason?: string;
    /** Stage notes */
    notes: string[];
    /** Stage metadata */
    metadata: Record<string, unknown>;
}
/**
 * Gate result context.
 *
 * @task T4805
 * @ref T4804
 */
export interface GateResultContext {
    /** Gate name */
    gateName: string;
    /** Result status */
    result: 'pass' | 'fail' | 'warn';
    /** When checked */
    checkedAt: Date;
    /** Who checked */
    checkedBy: string;
    /** Details */
    details?: string;
    /** Reason if failed */
    reason?: string;
}
/**
 * Evidence context.
 *
 * @task T4805
 * @ref T4804
 */
export interface EvidenceContext {
    /** Evidence ID */
    id: string;
    /** URI to evidence */
    uri: string;
    /** Evidence type */
    type: 'file' | 'url' | 'manifest';
    /** When recorded */
    recordedAt: Date;
    /** Who recorded */
    recordedBy?: string;
    /** Description */
    description?: string;
}
/**
 * Transition context.
 *
 * @task T4805
 */
export interface TransitionContext {
    /** From stage */
    fromStage: string;
    /** To stage */
    toStage: string;
    /** When transitioned */
    transitionedAt: Date;
    /** Who initiated */
    transitionedBy: string;
    /** Reason */
    reason?: string;
}
/**
 * Task context.
 *
 * @task T4805
 */
export interface TaskContext {
    /** Task ID */
    id: string;
    /** Task title */
    title: string;
    /** Task description */
    description?: string;
    /** Task status */
    status: string;
    /** Task priority */
    priority: string;
    /** Parent task ID */
    parentId?: string;
}
/**
 * Result of a resume operation.
 *
 * @task T4805
 */
export interface ResumeResult {
    /** Whether resume was successful */
    success: boolean;
    /** Task ID */
    taskId: string;
    /** Stage resumed */
    stage: Stage;
    /** Previous status */
    previousStatus: DbStageStatus;
    /** New status */
    newStatus: DbStageStatus;
    /** Resume timestamp */
    resumedAt: Date;
    /** Message for user */
    message: string;
    /** Any warnings */
    warnings: string[];
}
/**
 * Auto-resume detection result.
 *
 * @task T4805
 */
export interface AutoResumeResult {
    /** Whether auto-resume is possible */
    canResume: boolean;
    /** Task ID to resume */
    taskId?: string;
    /** Stage to resume */
    stage?: Stage;
    /** Pipeline context if available */
    context?: PipelineContext;
    /** Resume options if multiple */
    options?: ResumablePipeline[];
    /** Recommended action */
    recommendation: 'resume' | 'choose' | 'none';
    /** Message for user */
    message: string;
}
/**
 * Options for finding resumable pipelines.
 *
 * @task T4805
 */
export interface FindResumableOptions {
    /** Filter by specific task IDs */
    taskIds?: string[];
    /** Filter by stages */
    stages?: Stage[];
    /** Include blocked pipelines */
    includeBlocked?: boolean;
    /** Include aborted pipelines */
    includeAborted?: boolean;
    /** Maximum results */
    limit?: number;
    /** Minimum priority (tasks with priority >= this) */
    minPriority?: 'critical' | 'high' | 'medium' | 'low';
}
/**
 * Query active pipelines that can be resumed.
 *
 * Searches the lifecycle_pipelines table for pipelines with status 'active'
 * and joins with lifecycle_stages to determine current stage status.
 * Also joins with tasks table to get task metadata.
 *
 * @param options - Query options for filtering
 * @param cwd - Working directory for database
 * @returns Promise resolving to array of resumable pipelines
 *
 * @example
 * ```typescript
 * // Find all active pipelines
 * const resumable = await findResumablePipelines();
 *
 * // Find specific tasks
 * const specific = await findResumablePipelines({
 *   taskIds: ['T4805', 'T4806']
 * });
 *
 * // Include blocked pipelines
 * const withBlocked = await findResumablePipelines({
 *   includeBlocked: true
 * });
 * ```
 *
 * @task T4805
 * @ref T4801 - Uses lifecycle_pipelines, lifecycle_stages tables
 */
export declare function findResumablePipelines(options?: FindResumableOptions, cwd?: string): Promise<ResumablePipeline[]>;
/**
 * Load complete pipeline context for session resume.
 *
 * Uses SQL JOINs to efficiently load all related data:
 * - Pipeline and current stage
 * - All stages with their status
 * - Gate results for current stage
 * - Evidence linked to current stage
 * - Recent transitions
 * - Task details
 *
 * @param taskId - The task ID to load context for
 * @param cwd - Working directory for database
 * @returns Promise resolving to pipeline context
 *
 * @example
 * ```typescript
 * const context = await loadPipelineContext('T4805');
 * console.log(`Current stage: ${context.currentStage}`);
 * console.log(`Stage status: ${context.stages.find(s => s.stage === context.currentStage)?.status}`);
 * ```
 *
 * @task T4805
 * @ref T4801 - Uses lifecycle_pipelines, lifecycle_stages, lifecycle_gate_results, lifecycle_evidence tables
 * @ref T4804 - Loads gate results and evidence
 */
export declare function loadPipelineContext(taskId: string, cwd?: string): Promise<PipelineContext>;
/**
 * Resume a specific stage in a pipeline.
 *
 * Updates the stage status from 'blocked' or 'not_started' to 'in_progress',
 * records the transition, and returns the resume result.
 *
 * @param taskId - The task ID
 * @param targetStage - The stage to resume
 * @param options - Resume options
 * @param cwd - Working directory for database
 * @returns Promise resolving to resume result
 *
 * @example
 * ```typescript
 * const result = await resumeStage('T4805', 'implement');
 * if (result.success) {
 *   console.log(`Resumed ${result.taskId} at ${result.stage}`);
 * }
 * ```
 *
 * @task T4805
 * @ref T4801 - Updates lifecycle_stages table
 * @ref T4800 - Integrates with pipeline state machine
 */
export declare function resumeStage(taskId: string, targetStage: Stage, options?: {
    reason?: string;
    agent?: string;
    force?: boolean;
}, cwd?: string): Promise<ResumeResult>;
/**
 * Auto-detect where to resume across all active pipelines.
 *
 * Finds the best candidate for resuming work based on:
 * 1. Active stages (currently in progress)
 * 2. Blocked stages (can be unblocked)
 * 3. Failed stages (can be retried)
 * 4. Priority ordering
 *
 * @param cwd - Working directory for database
 * @returns Promise resolving to auto-resume result
 *
 * @example
 * ```typescript
 * const result = await autoResume();
 * if (result.canResume) {
 *   console.log(`Recommended: Resume ${result.taskId} at ${result.stage}`);
 * } else if (result.options && result.options.length > 0) {
 *   console.log('Multiple options available:', result.options);
 * }
 * ```
 *
 * @task T4805
 * @ref T4801 - Queries lifecycle_pipelines, lifecycle_stages tables
 * @ref T4798 - Implements RCASD-IVTR+C resume logic
 */
export declare function autoResume(cwd?: string): Promise<AutoResumeResult>;
/**
 * Options for session start with resume check.
 *
 * @task T4805
 */
export interface SessionResumeCheckOptions {
    /** Whether to auto-resume if only one candidate */
    autoResume?: boolean;
    /** Scope to filter resumable pipelines */
    scope?: {
        type: 'epic' | 'global';
        epicId?: string;
    };
    /** Minimum priority to consider */
    minPriority?: 'critical' | 'high' | 'medium' | 'low';
    /** Whether to include blocked pipelines */
    includeBlocked?: boolean;
}
/**
 * Result of session resume check.
 *
 * @task T4805
 */
export interface SessionResumeCheckResult {
    /** Whether resume was performed */
    didResume: boolean;
    /** Resumed task ID if auto-resumed */
    resumedTaskId?: string;
    /** Resumed stage if auto-resumed */
    resumedStage?: Stage;
    /** Available resume options if not auto-resumed */
    options?: ResumablePipeline[];
    /** Message for user */
    message: string;
    /** Whether user action is required */
    requiresUserChoice: boolean;
}
/**
 * Check for resumable work on session start.
 *
 * Integrates with session initialization to check for active pipelines
 * and present resumable work to the user. Can auto-resume if there's
 * a clear single candidate.
 *
 * @param options - Resume check options
 * @param cwd - Working directory for database
 * @returns Promise resolving to resume check result
 *
 * @example
 * ```typescript
 * // On session start
 * const resumeCheck = await checkSessionResume({ autoResume: true });
 * if (resumeCheck.didResume) {
 *   console.log(`Auto-resumed ${resumeCheck.resumedTaskId}`);
 * } else if (resumeCheck.requiresUserChoice) {
 *   console.log('Multiple options:', resumeCheck.options);
 * }
 * ```
 *
 * @task T4805
 * @integration Session Start Hook
 */
export declare function checkSessionResume(options?: SessionResumeCheckOptions, cwd?: string): Promise<SessionResumeCheckResult>;
/**
 * Get resume summary for display to user.
 *
 * Formats resumable pipelines into a human-readable summary.
 *
 * @param pipelines - Resumable pipelines
 * @returns Formatted summary string
 *
 * @task T4805
 */
export declare function formatResumeSummary(pipelines: ResumablePipeline[]): string;
/**
 * Handle completed stage edge case.
 *
 * If the current stage is completed, suggests advancing to next stage.
 *
 * @param context - Pipeline context
 * @returns Recommendation for handling completed stage
 *
 * @task T4805
 */
export declare function handleCompletedStage(context: PipelineContext): {
    action: 'advance' | 'stay' | 'review';
    message: string;
    nextStage?: Stage;
};
/**
 * Handle blocked stage edge case.
 *
 * Provides information about why a stage is blocked and potential resolutions.
 *
 * @param context - Pipeline context
 * @returns Block analysis and resolution hints
 *
 * @task T4805
 */
export declare function handleBlockedStage(context: PipelineContext): {
    isBlocked: boolean;
    blockReason?: string;
    blockedSince?: Date;
    resolutions: string[];
    canUnblock: boolean;
};
/**
 * Handle blocked stage edge case - async version with database lookup.
 *
 * @param taskId - Task ID to check
 * @param cwd - Working directory
 * @returns Block analysis with prerequisite details
 *
 * @task T4805
 */
export declare function checkBlockedStageDetails(taskId: string, cwd?: string): Promise<{
    isBlocked: boolean;
    blockReason?: string;
    blockedSince?: Date;
    resolutions: string[];
    canUnblock: boolean;
    prerequisites?: {
        stage: Stage;
        status: DbStageStatus;
        completed: boolean;
    }[];
}>;
//# sourceMappingURL=resume.d.ts.map