/** * Warns while a session's context is growing expensive, rather than after the * fact (`usage_report` finds the same waste in hindsight). * * This service deliberately has no database, no sync and no pricing: it runs in * a prompt hook that must answer in tens of milliseconds, and the context size * is a gauge of the moment, not a record anyone keeps. `UsageService` exposes it * for the status line; the hook uses it directly because opening the database * is exactly the cost the hook cannot pay. */ export interface ContextLimits { /** From here the size is a heads-up (yellow). */ warnAt: number; /** From here compacting is advised (red; the hook speaks up). */ compactAt: number; } export type ContextLevel = 'ok' | 'warn' | 'compact'; export interface ContextReading extends ContextLimits { /** Tokens the next message will re-read: input + cache read + cache write of the last turn. */ tokens: number; level: ContextLevel; } export declare const DEFAULT_CONTEXT_LIMITS: ContextLimits; /** * `150k`, `1.5m` or `150000` as a token count; undefined for anything else, so * each caller decides whether that is a usage error (a flag) or ignorable (the * environment). */ export declare function parseTokenCount(raw: string): number | undefined; /** * Flag, then `AI_USAGE_CTX_WARN` / `AI_USAGE_CTX_LIMIT`, then the defaults. * * A warn threshold above the compact limit would make the yellow band * unreachable, so it is pulled down to the limit instead of being honoured. * Throwing is not an option here: this runs in a hook that must never fail. */ export declare function resolveContextLimits(flags?: { warn?: number | undefined; limit?: number | undefined; }, env?: NodeJS.ProcessEnv): ContextLimits; export declare function contextLevel(tokens: number, limits: ContextLimits): ContextLevel; export declare class ContextService { /** * The session's current context against the limits, or undefined when it is * unknown: no transcript path, an unreadable file, no turn yet, or a compact * that no new turn has measured. Never throws. */ read(transcriptPath: string | undefined, limits: ContextLimits): ContextReading | undefined; /** `read`, for the raw JSON a Claude Code hook receives on stdin. Garbage is no data. */ readHookPayload(raw: string, limits: ContextLimits): ContextReading | undefined; }