interface AssistantTurn { cache_read: number; cache_creation: number; input_tokens: number; } export interface CacheHealthSummary { turns: number; totalCacheRead: number; totalCacheCreation: number; totalInput: number; /** Fraction of total tokens that were cache hits. Bounded [0, 1]. */ hitRatio: number; /** Number of turns detected as cache flushes (turn_index > 0, cache_creation > 5000, cache_read < 1000). */ flushCount: number; /** * Effective cost in "input token equivalent" units: * cache_read × 0.1 + cache_creation × 1.25 + input × 1.0 */ effectiveInputTokens: number; /** Turn index (0-based) of the last detected flush, or null if none. */ lastFlushAt: number | null; } /** Shape returned after extracting the assistant entry — always has usage. */ interface AssistantEntryNormalised { usage: Record; } /** * Type guard / extractor for assistant JSONL entries (DoD #3: `isAssistantEntry` equivalent). * * Returns a normalised `{ usage }` object when the entry is a valid assistant * turn, or null otherwise. A classic `v is X` predicate could not be used here * because the union type produced by the nested-vs-flat duality prevents TS from * narrowing `usage` after the guard (TS7053 — hence this extract-and-return pattern). * * Accepts both forms observed in production: * (a) Nested: { type:"assistant", message:{ role:"assistant", usage:{...} } } * (b) Flat (defensive fallback): { role:"assistant", usage:{...} } * * Returns null when: * - the entry is not an object * - `role` is not "assistant" * - `usage` is absent or not an object (DoD: missing usage → skip) */ export declare function extractAssistantEntry(v: unknown): AssistantEntryNormalised | null; /** Extract a non-negative integer from an unknown value, defaulting to 0. */ export declare function extractTokenCount(v: unknown): number; /** * Read a Claude Code session JSONL file and return one `AssistantTurn` per * assistant message that has a valid `usage` object. * * Parsing rules: * - Lines are read via `fs.readFileSync` + split on `\n`, empty lines filtered. * - Malformed JSON lines are skipped silently (no throw). * - Only entries with `role === 'assistant'` and a present usage object are included. * - Missing token count fields fall back to 0. */ export declare function readSessionJsonl(filePath: string): AssistantTurn[]; /** Minimum cache_creation value (exclusive) to consider a turn a cache flush. */ export declare const FLUSH_CREATION_THRESHOLD = 5000; /** Maximum cache_read value (exclusive) that can coexist with a flush. */ export declare const FLUSH_READ_THRESHOLD = 1000; /** * Compute cache health metrics from a list of `AssistantTurn` entries. * * Flush detection heuristic (turn_index > 0 required — initial creation is expected): * `cache_creation > FLUSH_CREATION_THRESHOLD && cache_read < FLUSH_READ_THRESHOLD` * * Pricing constants for `effectiveInputTokens`: * `cache_read × 0.1 + cache_creation × 1.25 + input × 1.0` */ export declare function summariseCacheHealth(entries: AssistantTurn[], _opts?: Record): CacheHealthSummary; export {};