/**
 * Chat History Persistence — Persist completed chat messages to local disk
 *
 * Design:
 * - ~/.adhdev/history/{agentType}/YYYY-MM-DD.jsonl
 * - JSONL format (one line = one message, append-friendly)
 * - Track only new messages (hash comparison with previous)
 * - Auto-rotation (delete files older than 30 days)
 * - Async/non-blocking (no impact on chat collection)
 */
import type { ProviderCanonicalHistoryConfig, ProviderHistoryBehavior } from '../providers/contracts.js';
export declare const SAVED_HISTORY_ROLLUP_THRESHOLD_BYTES: number;
interface HistoryMessage {
    ts: string;
    receivedAt: number;
    role: 'user' | 'assistant' | 'system';
    content: string;
    kind?: string;
    senderName?: string;
    agent: string;
    instanceId?: string;
    historySessionId?: string;
    sessionTitle?: string;
    workspace?: string;
}
export interface SavedHistorySessionSummary {
    historySessionId: string;
    sessionTitle?: string;
    messageCount: number;
    firstMessageAt: number;
    lastMessageAt: number;
    preview?: string;
    workspace?: string;
    source?: 'adhdev-mirror' | 'provider-native';
    sourcePath?: string;
    sourceMtimeMs?: number;
}
export declare function shouldScheduleSavedHistoryRollup(totalBytes: number): boolean;
export declare class ChatHistoryWriter {
    /** Last seen message count per agent (deduplication) */
    private lastSeenCounts;
    /** Last seen message hash per agent (deduplication) */
    private lastSeenHashes;
    /** Last appended normalized message signature per agent/session */
    private lastSeenSignatures;
    /** Last appended normalized non-system turn signature per agent/session */
    private lastSeenTurnSignatures;
    private rotated;
    /**
    * Append new messages to history
    *
    * @param agentType agent type (e.g. 'antigravity', 'cursor')
    * @param messages Message array received from readChat
    * @param sessionTitle Current session title
    * @param instanceId IDE instance UUID (distinguishes windows of the same agent)
    */
    appendNewMessages(agentType: string, messages: Array<{
        role: string;
        content: string;
        receivedAt?: number;
        kind?: string;
        senderName?: string;
        historyDedupKey?: string;
    }>, sessionTitle?: string, instanceId?: string, historySessionId?: string): void;
    seedSessionHistory(agentType: string, messages?: Array<{
        role: string;
        content: string;
        receivedAt?: number;
        kind?: string;
        historyDedupKey?: string;
    }>, historySessionId?: string, instanceId?: string): void;
    appendSystemMarker(agentType: string, content: string, options?: {
        sessionTitle?: string;
        instanceId?: string;
        historySessionId?: string;
        dedupKey?: string;
        receivedAt?: number;
        senderName?: string;
    }): void;
    writeSessionStart(agentType: string, historySessionId: string, workspace: string, instanceId?: string): void;
    promoteHistorySession(agentType: string, previousHistorySessionId: string, nextHistorySessionId: string): void;
    compactHistorySession(agentType: string, historySessionId: string, historyBehavior?: ProviderHistoryBehavior): void;
    /** Called when agent session is explicitly changed */
    onSessionChange(agentType: string): void;
    /** Delete history files older than 30 days */
    private rotateOldFiles;
    /** Allow only filename-safe characters */
    private sanitize;
}
export declare function readChatHistory(agentType: string, offset?: number, limit?: number, historySessionId?: string, excludeRecentCount?: number, historyBehavior?: ProviderHistoryBehavior): {
    messages: HistoryMessage[];
    hasMore: boolean;
};
export declare function listSavedHistorySessions(agentType: string, options?: {
    offset?: number;
    limit?: number;
}, historyBehavior?: ProviderHistoryBehavior): {
    sessions: SavedHistorySessionSummary[];
    hasMore: boolean;
};
export type ProviderNativeHistoryScripts = Record<string, ((input: any) => any) | undefined>;
export declare function materializeProviderNativeHistory(agentType: string, canonicalHistory: ProviderCanonicalHistoryConfig | undefined, historySessionId: string, workspace?: string, scripts?: ProviderNativeHistoryScripts): boolean;
export declare function isNativeSourceCanonicalHistory(canonicalHistory?: ProviderCanonicalHistoryConfig): boolean;
export declare function readProviderChatHistory(agentType: string, options?: {
    canonicalHistory?: ProviderCanonicalHistoryConfig;
    historySessionId?: string;
    workspace?: string;
    offset?: number;
    limit?: number;
    excludeRecentCount?: number;
    historyBehavior?: ProviderHistoryBehavior;
    scripts?: ProviderNativeHistoryScripts;
    excludeInProgressTurn?: boolean;
    sessionStartedAtMs?: number;
    envOverrides?: Record<string, string>;
    forceRefresh?: boolean;
    instanceId?: string;
}): {
    messages: HistoryMessage[];
    hasMore: boolean;
    source: 'provider-native' | 'adhdev-mirror' | 'native-unavailable';
    sourcePath?: string;
    sourceMtimeMs?: number;
    providerSessionId?: string;
    workspace?: string;
    nativeHistoryCoverage?: string;
    partialReason?: string;
    unavailableReason?: string;
    ownerConfirmed?: boolean;
};
export declare function listProviderHistorySessions(agentType: string, options?: {
    canonicalHistory?: ProviderCanonicalHistoryConfig;
    offset?: number;
    limit?: number;
    historyBehavior?: ProviderHistoryBehavior;
    scripts?: ProviderNativeHistoryScripts;
}): {
    sessions: SavedHistorySessionSummary[];
    hasMore: boolean;
    source: 'provider-native' | 'adhdev-mirror';
};
export {};
