/**
 * CLI History Store - SQLite Storage Backend
 * Provides persistent storage for CLI execution history with efficient queries
 */
import { type ParsedSession } from './session-content-parser.js';
import type { CliOutputUnit } from './cli-output-converter.js';
export interface ConversationTurn {
    turn: number;
    timestamp: string;
    prompt: string;
    duration_ms: number;
    status: 'success' | 'error' | 'timeout';
    exit_code: number | null;
    output: {
        stdout: string;
        stderr: string;
        truncated: boolean;
        cached?: boolean;
        stdout_full?: string;
        stderr_full?: string;
        structured?: CliOutputUnit[];
    };
}
export type ExecutionCategory = 'user' | 'internal' | 'insight';
export interface ConversationRecord {
    id: string;
    created_at: string;
    updated_at: string;
    tool: string;
    model: string;
    mode: string;
    category: ExecutionCategory;
    total_duration_ms: number;
    turn_count: number;
    latest_status: 'success' | 'error' | 'timeout';
    turns: ConversationTurn[];
    parent_execution_id?: string;
}
export interface HistoryQueryOptions {
    limit?: number;
    offset?: number;
    tool?: string | null;
    status?: string | null;
    category?: ExecutionCategory | null;
    search?: string | null;
    startDate?: string | null;
    endDate?: string | null;
}
export interface HistoryIndexEntry {
    id: string;
    timestamp: string;
    updated_at?: string;
    tool: string;
    status: string;
    category?: ExecutionCategory;
    duration_ms: number;
    turn_count?: number;
    prompt_preview: string;
    sourceDir?: string;
}
export interface NativeSessionMapping {
    ccw_id: string;
    tool: string;
    native_session_id: string;
    native_session_path?: string;
    project_hash?: string;
    created_at: string;
}
export type ReviewStatus = 'pending' | 'approved' | 'rejected' | 'changes_requested';
export interface ReviewRecord {
    id?: number;
    execution_id: string;
    status: ReviewStatus;
    rating?: number;
    comments?: string;
    reviewer?: string;
    created_at: string;
    updated_at: string;
}
/**
 * CLI History Store using SQLite
 */
export declare class CliHistoryStore {
    private db;
    private dbPath;
    private projectPath;
    constructor(baseDir: string);
    /**
     * Initialize database schema
     */
    private initSchema;
    /**
     * Migrate schema for existing databases
     */
    private migrateSchema;
    /**
     * Migrate existing JSON files to SQLite
     */
    private migrateFromJson;
    /**
     * Normalize legacy record to ConversationRecord format
     */
    private normalizeRecord;
    /**
     * Save or update a conversation
     */
    saveConversation(conversation: ConversationRecord): void;
    /**
     * Get conversation by ID
     */
    getConversation(id: string): ConversationRecord | null;
    /**
     * Get conversation with native session info
     */
    getConversationWithNativeInfo(id: string): (ConversationRecord & {
        hasNativeSession: boolean;
        nativeSessionId?: string;
        nativeSessionPath?: string;
    }) | null;
    /**
     * Get paginated cached output for a conversation turn
     * @param conversationId - Conversation ID
     * @param turnNumber - Turn number (default: latest turn)
     * @param options - Pagination options
     */
    getCachedOutput(conversationId: string, turnNumber?: number, options?: {
        offset?: number;
        limit?: number;
        outputType?: 'stdout' | 'stderr' | 'both';
    }): {
        conversationId: string;
        turnNumber: number;
        stdout?: {
            content: string;
            totalBytes: number;
            offset: number;
            hasMore: boolean;
        };
        stderr?: {
            content: string;
            totalBytes: number;
            offset: number;
            hasMore: boolean;
        };
        cached: boolean;
        prompt: string;
        status: string;
        timestamp: string;
    } | null;
    /**
     * Query execution history
     */
    getHistory(options?: HistoryQueryOptions): {
        total: number;
        count: number;
        executions: HistoryIndexEntry[];
    };
    /**
     * Delete a conversation
     */
    deleteConversation(id: string): {
        success: boolean;
        error?: string;
    };
    /**
     * Batch delete conversations
     */
    batchDelete(ids: string[]): {
        success: boolean;
        deleted: number;
        errors?: string[];
    };
    /**
     * Delete conversations by tool
     */
    deleteByTool(tool: string): {
        success: boolean;
        deleted: number;
    };
    /**
     * Delete all conversations
     */
    deleteAll(): {
        success: boolean;
        deleted: number;
    };
    /**
     * Get statistics
     */
    getStats(): {
        total: number;
        byTool: Record<string, number>;
        byStatus: Record<string, number>;
        totalDuration: number;
    };
    /**
     * Save or update native session mapping
     */
    saveNativeSessionMapping(mapping: NativeSessionMapping): void;
    /**
     * Get native session ID by CCW ID
     */
    getNativeSessionId(ccwId: string): string | null;
    /**
     * Get CCW ID by native session ID
     */
    getCcwIdByNativeSession(tool: string, nativeSessionId: string): string | null;
    /**
     * Get full mapping by CCW ID
     */
    getNativeSessionMapping(ccwId: string): NativeSessionMapping | null;
    /**
     * Get latest native session mapping for a tool
     */
    getLatestNativeMapping(tool: string): NativeSessionMapping | null;
    /**
     * Delete native session mapping
     */
    deleteNativeSessionMapping(ccwId: string): boolean;
    /**
     * Check if CCW ID has native session mapping
     */
    hasNativeSession(ccwId: string): boolean;
    /**
     * Get parsed native session content by CCW ID
     * Returns full conversation with all turns from native session file
     */
    getNativeSessionContent(ccwId: string): ParsedSession | null;
    /**
     * Get formatted conversation text from native session
     */
    getFormattedNativeConversation(ccwId: string, options?: {
        includeThoughts?: boolean;
        includeToolCalls?: boolean;
        includeTokens?: boolean;
        maxContentLength?: number;
    }): string | null;
    /**
     * Get conversation pairs (user prompt + assistant response) from native session
     */
    getNativeConversationPairs(ccwId: string): Array<{
        turn: number;
        userPrompt: string;
        assistantResponse: string;
        timestamp: string;
    }> | null;
    /**
     * Get conversation with enriched native session data
     * Merges CCW history with native session content
     */
    getEnrichedConversation(ccwId: string): {
        ccw: ConversationRecord | null;
        native: ParsedSession | null;
        merged: Array<{
            turn: number;
            timestamp: string;
            ccwPrompt?: string;
            ccwOutput?: string;
            nativeUserContent?: string;
            nativeAssistantContent?: string;
            nativeThoughts?: string[];
            nativeToolCalls?: Array<{
                name: string;
                arguments?: string;
                output?: string;
            }>;
        }>;
    } | null;
    /**
     * List all conversations with native session info
     */
    getHistoryWithNativeInfo(options?: HistoryQueryOptions): {
        total: number;
        count: number;
        executions: Array<HistoryIndexEntry & {
            hasNativeSession: boolean;
            nativeSessionId?: string;
            nativeSessionPath?: string;
        }>;
    };
    /**
     * Save an insights analysis result
     */
    saveInsight(insight: {
        id: string;
        tool: string;
        promptCount: number;
        patterns: any[];
        suggestions: any[];
        rawOutput?: string;
        executionId?: string;
        lang?: string;
    }): void;
    /**
     * Get insights history
     */
    getInsights(options?: {
        limit?: number;
        tool?: string;
    }): {
        id: string;
        created_at: string;
        tool: string;
        prompt_count: number;
        patterns: any[];
        suggestions: any[];
        execution_id: string | null;
        lang: string;
    }[];
    /**
     * Get a single insight by ID
     */
    getInsight(id: string): {
        id: string;
        created_at: string;
        tool: string;
        prompt_count: number;
        patterns: any[];
        suggestions: any[];
        raw_output: string | null;
        execution_id: string | null;
        lang: string;
    } | null;
    /**
     * Delete an insight
     */
    deleteInsight(id: string): boolean;
    /**
     * Save or update a review for an execution
     */
    saveReview(review: Omit<ReviewRecord, 'id' | 'created_at' | 'updated_at'> & {
        created_at?: string;
        updated_at?: string;
    }): ReviewRecord;
    /**
     * Get review for an execution
     */
    getReview(executionId: string): ReviewRecord | null;
    /**
     * Get reviews with optional filtering
     */
    getReviews(options?: {
        status?: ReviewStatus;
        limit?: number;
    }): ReviewRecord[];
    /**
     * Delete a review
     */
    deleteReview(executionId: string): boolean;
    /**
     * Close database connection
     */
    close(): void;
}
/**
 * Get or create a store instance for a directory
 * Uses normalized project ID as cache key to handle path casing differences
 */
export declare function getHistoryStore(baseDir: string): CliHistoryStore;
/**
 * Close all store instances
 */
export declare function closeAllStores(): void;
export type { ParsedSession, ParsedTurn } from './session-content-parser.js';
//# sourceMappingURL=cli-history-store.d.ts.map