/**
 * Session Management Service - JSONL Format Implementation
 *
 * OPTIMIZED IMPLEMENTATION (Phase 6 Complete):
 * - Filename-based session type identification
 * - Minimal file I/O for metadata extraction
 * - Eliminated metadata headers for cleaner session files
 * - Backward compatible with existing session files
 * - 8-10x performance improvement in session listing operations
 *
 * Key Features:
 * - Session creation without metadata headers
 * - Subagent sessions identified by filename prefix
 * - Performance-optimized session listing
 * - Full backward compatibility maintained
 */
import type { Message } from "../types/index.js";
export interface SessionData {
    id: string;
    rootSessionId?: string;
    parentSessionId?: string;
    messages: Message[];
    metadata: {
        workdir: string;
        lastActiveAt: string;
        latestTotalTokens: number;
    };
}
export interface SessionMetadata {
    id: string;
    rootSessionId?: string;
    parentSessionId?: string;
    sessionType: "main" | "subagent";
    subagentType?: string;
    workdir: string;
    lastActiveAt: Date;
    latestTotalTokens: number;
    firstMessage?: string;
}
export interface SessionIndex {
    sessions: Record<string, Omit<SessionMetadata, "id" | "lastActiveAt"> & {
        lastActiveAt: string;
    }>;
    lastUpdated: string;
}
/**
 * Generate a new session ID using Node.js native crypto.randomUUID()
 * @returns UUID string for session identification
 */
export declare function generateSessionId(): string;
/**
 * Generate filename for subagent sessions
 * @param sessionId - UUID session identifier
 * @returns Filename with subagent prefix for subagent sessions
 */
export declare function generateSubagentFilename(sessionId: string): string;
export declare const SESSION_DIR: string;
/**
 * Ensure session directory exists
 */
export declare function ensureSessionDir(): Promise<void>;
/**
 * Generate session file path without creating directories
 * @param sessionId - UUID session identifier
 * @param workdir - Working directory for the session
 * @param sessionType - Type of session ("main" or "subagent", defaults to "main")
 * @returns Promise resolving to full file path for the session JSONL file
 */
export declare function generateSessionFilePath(sessionId: string, workdir: string, sessionType?: "main" | "subagent"): Promise<string>;
/**
 * Generate session file path using project-based directory structure
 * @param sessionId - UUID session identifier
 * @param workdir - Working directory for the session
 * @param sessionType - Type of session ("main" or "subagent", defaults to "main")
 * @returns Promise resolving to full file path for the session JSONL file
 */
export declare function getSessionFilePath(sessionId: string, workdir: string, sessionType?: "main" | "subagent"): Promise<string>;
/**
 * Create a new session
 * @param sessionId - UUID session identifier
 * @param workdir - Working directory for the session
 * @param sessionType - Type of session ("main" or "subagent", defaults to "main")
 */
export declare function createSession(sessionId: string, workdir: string, sessionType?: "main" | "subagent"): Promise<void>;
/**
 * Append messages to session using JSONL format (new approach)
 *
 * @param sessionId - UUID session identifier
 * @param newMessages - Array of messages to append
 * @param workdir - Working directory for the session
 * @param sessionType - Type of session ("main" or "subagent", defaults to "main")
 */
export declare function appendMessages(sessionId: string, newMessages: Message[], workdir: string, sessionType?: "main" | "subagent", rootSessionId?: string, parentSessionId?: string): Promise<void>;
/**
 * Load session data from JSONL file (new approach)
 *
 * @param sessionId - UUID session identifier
 * @param workdir - Working directory for the session
 * @param sessionType - Type of session ("main" or "subagent", defaults to "main")
 * @returns Promise that resolves to session data or null if session doesn't exist
 */
export declare function loadSessionFromJsonl(sessionId: string, workdir: string, sessionType?: "main" | "subagent"): Promise<SessionData | null>;
/**
 * Get the most recently active session for a specific working directory (new JSONL approach)
 * Only returns main sessions, skips subagent sessions
 * Uses listSessionsFromJsonl which already sorts sessions by last active time (most recent first)
 *
 * @param workdir - Working directory to find the most recently active session for
 * @returns Promise that resolves to the most recently active session data or null if no sessions exist
 */
export declare function getLatestSessionFromJsonl(workdir: string): Promise<SessionData | null>;
/**
 * List all sessions for a specific working directory (convenience wrapper)
 * Only returns main sessions, skips subagent sessions
 *
 * @param workdir - Working directory to filter sessions by
 * @returns Promise that resolves to array of session metadata objects
 */
export declare function listSessions(workdir: string): Promise<SessionMetadata[]>;
/**
 * List all sessions for a specific working directory using JSONL format (optimized approach)
 *
 * PERFORMANCE OPTIMIZATION:
 * - Uses filename parsing exclusively for session metadata
 * - Only reads last message for timestamps and token counts
 * - Eliminates O(n*2) file operations, achieving O(n) performance
 * - Returns simplified session metadata objects
 * - Only includes main sessions, excludes subagent sessions
 *
 * @param workdir - Working directory to filter sessions by
 * @returns Promise that resolves to array of session metadata objects
 */
export declare function listSessionsFromJsonl(workdir: string): Promise<SessionMetadata[]>;
/**
 * List all sessions across all project directories
 *
 * @returns Promise that resolves to array of session metadata objects
 */
export declare function listAllSessions(): Promise<SessionMetadata[]>;
/**
 * Clean up expired sessions older than 14 days based on file modification time
 *
 * @param workdir - Working directory to clean up sessions for
 * @returns Promise that resolves to the number of sessions that were deleted
 */
export declare function cleanupExpiredSessionsFromJsonl(workdir: string): Promise<number>;
/**
 * Clean up empty project directories in the session directory
 */
export declare function cleanupEmptyProjectDirectories(): Promise<void>;
/**
 * Check if a session exists in JSONL storage (new approach)
 *
 * @param sessionId - UUID session identifier
 * @param workdir - Working directory for the session
 * @param sessionType - Type of session ("main" or "subagent"). If not provided, checks both types.
 * @returns Promise that resolves to true if session exists, false otherwise
 */
export declare function sessionExistsInJsonl(sessionId: string, workdir: string, sessionType?: "main" | "subagent"): Promise<boolean>;
/**
 * Get the content of the first message in a session
 * For user role: get text block content
 * For assistant role: get compress block content
 * @param sessionId - Session ID to get first message from
 * @param workdir - Working directory for session operations
 * @returns Promise that resolves to the first message content or null if not found
 */
export declare function getFirstMessageContent(sessionId: string, workdir: string): Promise<string | null>;
/**
 * Delete a session
 * @param sessionId - UUID session identifier
 * @param workdir - Working directory for the session
 * @param sessionType - Type of session ("main" or "subagent", defaults to "main")
 */
export declare function deleteSession(sessionId: string, workdir: string, sessionType?: "main" | "subagent"): Promise<void>;
/**
 * Truncate content to a maximum length, adding ellipsis if truncated.
 * Also replaces real newlines with the literal string "\n".
 * @param content - The content to truncate
 * @param maxLength - Maximum length before truncation (default: 100)
 * @returns Truncated content with ellipsis if needed
 */
export declare function truncateContent(content: string, maxLength?: number): string;
/**
 * Handle session restoration logic
 * @param restoreSessionId - Specific session ID to restore
 * @param continueLastSession - Whether to continue the most recent session
 * @param workdir - Working directory for session restoration
 * @returns Promise that resolves to session data or undefined
 */
export declare function handleSessionRestoration(restoreSessionId?: string, continueLastSession?: boolean, workdir?: string): Promise<SessionData | undefined>;
/**
 * Load the full message thread by following parentSessionId links
 * @param currentSessionId - The ID of the current session
 * @param workdir - Working directory for the session
 * @returns Promise that resolves to an array of all messages in the thread
 */
export declare function loadFullMessageThread(currentSessionId: string, workdir: string): Promise<{
    messages: Message[];
    sessionIds: string[];
}>;
//# sourceMappingURL=session.d.ts.map