import { PluginConfig, TranscriptEntry, Checkpoint } from './types.js';
import { SessionIntegrityReport } from './session-integrity.js';
import './index-1qIcnbG1.js';

/**
 * Manages conversation transcript storage, checkpointing, and recall formatting.
 *
 * Transcripts are stored as JSONL files in a hierarchical structure:
 *   transcripts/{channelType}/{channelId}.jsonl
 *
 * Channel types are extracted from sessionKey (discord, slack, cron, main, etc.)
 * Checkpoints are used to preserve conversation context across compaction events.
 */
declare class TranscriptManager {
    private transcriptsDir;
    private checkpointPath;
    private stateDir;
    private toolUsageDir;
    private config;
    private sessionFootprintCache;
    /** Default checkpoint TTL in hours */
    private static readonly DEFAULT_CHECKPOINT_TTL_HOURS;
    /** Approximate characters per token for rough estimation */
    private static readonly CHARS_PER_TOKEN;
    constructor(config: PluginConfig);
    /**
     * Parse a sessionKey to extract channel type and ID.
     *
     * SessionKey patterns:
     *   - agent:<agent-id>:main → type="main", id="default"
     *   - agent:<agent-id>:discord:channel:<channel-id> → type="discord", id="<channel-id>"
     *   - agent:<agent-id>:cron:<job-id> → type="cron", id="<job-id>"
     *   - agent:<agent-id>:slack:channel:<channel-id> → type="slack", id="<channel-id>"
     *
     * @returns Object with dir (channel type/channel id) and file (YYYY-MM-DD.jsonl)
     */
    getTranscriptPath(sessionKey: string): {
        dir: string;
        file: string;
    };
    /**
     * Initialize the transcript manager by ensuring directories exist.
     */
    initialize(): Promise<void>;
    /**
     * Best-effort list of sessionKeys that have transcript files on disk.
     * This is used by cron-style tooling (hourly summaries, conversation indexing)
     * to iterate across "active" sessions.
     */
    listSessionKeys(): Promise<string[]>;
    getToolUsagePath(sessionKey: string): {
        dir: string;
        file: string;
    };
    appendToolUse(entry: {
        timestamp: string;
        sessionKey: string;
        tool: string;
    }): Promise<void>;
    readToolUse(sessionKey: string, startTime: Date, endTime: Date): Promise<Array<{
        timestamp: string;
        sessionKey: string;
        tool: string;
    }>>;
    estimateSessionFootprint(sessionKey: string): Promise<{
        bytes: number;
        tokens: number;
    }>;
    private estimateSessionBytesInFile;
    /**
     * Check if a file is a legacy flat transcript file (YYYY-MM-DD.jsonl format).
     */
    private isLegacyTranscriptFile;
    /**
     * Append a turn to the appropriate transcript file.
     * Files are stored hierarchically: transcripts/{channelType}/{channelId}.jsonl
     *
     * Skips channel types in config.transcriptSkipChannelTypes (e.g., "cron").
     */
    append(entry: TranscriptEntry): Promise<void>;
    /**
     * Get all transcript files from the hierarchical directory structure.
     * Recursively finds all .jsonl files in transcripts/{channelType}/{channelId}/ subdirectories.
     */
    private getAllTranscriptFiles;
    /**
     * Read transcript entries for a date range.
     * Returns entries within the time range, optionally filtered by sessionKey.
     * Reads from all channel subdirectories in the hierarchical structure.
     */
    readRange(startTime: string, endTime: string, sessionKey?: string): Promise<TranscriptEntry[]>;
    /**
     * Read the last N hours of transcript.
     *
     * Fast path: when sessionKey is given, reads only the 1-2 daily files for that
     * specific channel instead of scanning all 95+ transcript files across all channels.
     */
    readRecent(hours: number, sessionKey?: string): Promise<TranscriptEntry[]>;
    /**
     * Optimized read for a specific session: only looks in that session's channel
     * directory and only reads files whose date falls within the lookback window.
     */
    private readRecentForSession;
    /**
     * Cleanup old transcript entries that are older than retentionDays.
     * For hierarchical structure, reads each file and rewrites without old entries.
     * Legacy flat files are deleted if their date is older than retentionDays.
     * Returns the number of files processed (cleaned or deleted).
     */
    cleanup(retentionDays: number): Promise<number>;
    /**
     * Clean up old entries from a single transcript file.
     * Reads the file, filters out entries older than cutoff, and rewrites if needed.
     * Returns true if the file was processed (cleaned or deleted).
     */
    private cleanupTranscriptFile;
    /**
     * Save a checkpoint to preserve conversation context.
     * Called when compaction is detected.
     */
    saveCheckpoint(checkpoint: Checkpoint): Promise<void>;
    /**
     * Load a checkpoint if one exists and is not expired.
     * Returns null if no checkpoint exists or if it has expired.
     */
    loadCheckpoint(sessionKey?: string): Promise<Checkpoint | null>;
    /**
     * Clear (delete) the checkpoint file.
     * Called after successful injection of checkpoint context.
     */
    clearCheckpoint(): Promise<void>;
    /**
     * Format entries for recall injection.
     * Returns a formatted string suitable for injecting into agent context.
     *
     * Format:
     * ## Recent Conversation (last X hours)
     * [10:32] User: message content
     * [10:33] Assistant: response content
     *
     * Content is trimmed to approximately maxTokens.
     */
    formatForRecall(entries: TranscriptEntry[], maxTokens: number): string;
    /**
     * Create a checkpoint from the current buffer state.
     * Helper method for creating checkpoints before compaction.
     */
    createCheckpoint(sessionKey: string, turns: TranscriptEntry[], ttlHours?: number): Checkpoint;
    /**
     * Get statistics about stored transcripts.
     * Returns counts from the hierarchical directory structure.
     */
    getStats(): Promise<{
        totalFiles: number;
        totalEntries: number;
        oldestFile: string | null;
        newestFile: string | null;
        channelTypes: Record<string, number>;
    }>;
    analyzeIntegrity(): Promise<SessionIntegrityReport>;
    getRecoverySummary(sessionKey?: string): Promise<{
        generatedAt: string;
        sessionKey?: string;
        healthy: boolean;
        issueCount: number;
        incompleteTurns: number;
        brokenChains: number;
        checkpointHealthy: boolean;
    }>;
}

export { TranscriptManager };
