/** * Read Claude Code session history from ~/.claude/projects//.jsonl * * Claude stores sessions as JSONL files organized by project directory. * Path-to-folder mapping: `/foo/bar` → `-foo-bar`, `C:\foo\bar` → `C--foo-bar` */ import { pathToProjectFolder, type HistoryMessage } from './history-message-transform.js'; import { FileCache } from './file-cache.js'; export { pathToProjectFolder }; export type { HistoryMessage }; export interface SessionInfo { sessionId: string; title: string; customTitle?: string; preview: string; lastModified: number; } export interface SessionListPage { sessions: SessionInfo[]; hasMore: boolean; nextCursor?: string; } export interface GlobalSessionInfo { sessionId: string; projectPath: string; projectFolder: string; stableIdentity?: string; title: string; firstPrompt: string; lastModified: number; gitBranch?: string; } export interface GlobalSessionListPage { sessions: GlobalSessionInfo[]; hasMore: boolean; nextCursor?: string; indexState: 'ready'; } interface ParsedSessionMetadata { sessionId: string; title: string; customTitle?: string; preview: string; firstPrompt: string; lastModified: number; projectPath?: string; gitBranch?: string; } export declare const DEFAULT_SESSION_LIST_LIMIT = 150; export declare const LEGACY_SESSION_LIST_CAP = 5000; /** Test-only hook for proving long scans yield and in-flight scans coalesce. */ export declare function _setHistoryScanYieldHookForTests(hook: (() => void | Promise) | null): void; /** Test-only hook to reset cache state between specs. */ export declare function _resetSessionCache(): void; /** Diagnostic snapshot. Used by handleListSessions for periodic logging. */ export declare function getSessionCacheStats(): Readonly['stats']>>; /** * List sessions for a given working directory by scanning JSONL files. * Returns sessions sorted by lastModified descending. * * Per-file parse results are cached in `sessionJsonlCache` keyed by absolute * path; only files whose (mtime, size) changed get re-parsed. The directory * listing itself is always done fresh (cheap readdir + per-file stat). */ export declare function listSessions(workDir: string): SessionInfo[]; export declare function listSessionsPage(workDir: string, options?: { limit?: number; cursor?: string; }): SessionListPage; export declare function listSessionsPageAsync(workDir: string, options?: { limit?: number; cursor?: string; }): Promise; /** * Read the message history from a session's JSONL file. * Returns user messages and assistant text/tool_use blocks as a flat list. */ export declare function readSessionMessages(workDir: string, sessionId: string): HistoryMessage[]; /** * Delete a session's JSONL file. * Returns true if the file was deleted, false if it didn't exist. */ export declare function deleteSession(workDir: string, sessionId: string): boolean; export declare function moveSession(fromWorkDir: string, toWorkDir: string, sessionId: string): boolean; /** * Read lightweight conversation context from a session's JSONL file. * Extracts only user/assistant text from the last compact point (summary) onward, * stripping all tool_use/tool_result blocks. Used by BTW side questions to provide * conversation context without the full session history overhead. * * Returns null if the JSONL file doesn't exist or has no extractable content. */ export declare const CONTEXT_MAX_CHARS = 100000; export declare function readConversationContext(workDir: string, sessionId: string): string | null; /** * Rename a session by appending a custom-title entry to its JSONL file. * This matches what Claude CLI's /rename command does. */ export declare function renameSession(workDir: string, sessionId: string, newTitle: string): boolean; /** * List the most recent sessions across ALL working directories. * Scans all project folders under ~/.claude/projects/ and returns sessions * sorted by lastModified descending. * * @param limit - Maximum number of sessions to return (default 20) * @param perProjectLimit - Optional max files to scan per project folder */ export declare function listAllRecentSessions(limit?: number, perProjectLimit?: number): Promise; export declare function listAllRecentSessionsPage(options?: { limit?: number; cursor?: string; perProjectLimit?: number; }): Promise;