import { type CacheHealthSummary } from './cache-health-core.js'; export { readSessionJsonl, summariseCacheHealth } from './cache-health-core.js'; export type { CacheHealthSummary } from './cache-health-core.js'; export { extractFlushTurns } from './cache-health-flush.js'; export type { FlushEvent } from './cache-health-flush.js'; /** * Options for {@link loadActiveSessionHealth}. */ interface LoadHealthOptions { /** Absolute path to `~/.claude/projects` (or equivalent). Default: `~/.claude/projects`. */ claudeProjectsDir?: string; /** Working directory of the target project. Default: `process.cwd()`. */ projectCwd?: string; /** Clock source. Defaults to `Date.now`. Injectable for TTL testing without real timers. */ now?: () => number; } /** * High-level glue that wires together: * 1. `findActiveSessionJsonl` (path resolution) * 2. `readSessionJsonl` + `summariseCacheHealth` (read + compute) * 3. A 1-second in-process TTL cache (keyed by resolved JSONL path) * * Cache key is the resolved path of the JSONL file, so switching between two * different session files in the same process correctly busts the cache. * (Single-slot design: A→B→A re-reads on every switch; acceptable given TTL=1s.) * * @returns `CacheHealthSummary` on success, or `null` when no active session is found. */ export declare function loadActiveSessionHealth(opts?: LoadHealthOptions): CacheHealthSummary | null; /** * Encode a filesystem path to the directory name used by Claude Code under * `~/.claude/projects/`. * * Schema (verified empirically from `~/.claude/projects/` on macOS, 2026-05): * Every character that is NOT an ASCII alphanumeric or a hyphen is replaced * with a hyphen (`-`). In practice this means: * - `/` → `-` (path separators become hyphens) * - `.` → `-` (dot in dir/file names becomes hyphen) * - any other non-alphanum-non-hyphen (spaces, braces, quotes, …) → `-` * The leading `/` therefore produces the leading `-` that all entries share. * * Known limitation — collisions for non-alphanum-non-hyphen chars: * The aggressive `[^a-zA-Z0-9-]` collapse means paths that differ only by * `.` vs `_` vs `-` vs ` ` vs `/` map to the same encoded directory. For * example `my-project`, `my_project`, `my.project` all encode identically. * In that case `findActiveSessionJsonl` returns the latest JSONL across all * colliding projects — the cache-health badge could show data from a * sibling project rather than the current cwd. This was deemed acceptable * because (a) the encoding matches Claude Code's own observed behavior on * real `~/.claude/projects/` dirs and (b) the cache-health surfaces are * diagnostic, not part of the auth/billing critical path. If Claude Code * ever changes its encoding (preserving `_` for example), update both this * regex and the verifying tests in `test/cache-health.test.ts`. * * @example * encodeProjectPath('/foo/bar') // '-foo-bar' * encodeProjectPath('/Users/me/.x') // '-Users-me--x' */ export declare function encodeProjectPath(projectCwd: string): string; /** * Find the most-recently-modified `*.jsonl` file inside the Claude Code * project directory that corresponds to `projectCwd`. * * Claude Code stores session JSONL files at: * `//.jsonl` * * Steps: * 1. Encode `projectCwd` via {@link encodeProjectPath}. * 2. Build the candidate directory path. * 3. Return `null` if the directory does not exist. * 4. List all `*.jsonl` files; return `null` if there are none. * 5. Return the path of the file with the highest `mtime`. * * @param claudeProjectsDir - Absolute path to `~/.claude/projects` (or equivalent). * @param projectCwd - Absolute path to the project working directory * (typically `process.cwd()`). * @returns Absolute path to the newest JSONL file, or `null`. */ export declare function findActiveSessionJsonl(claudeProjectsDir: string, projectCwd: string): string | null;