export interface SessionCap { tasks?: number; tokens?: number; } export type CapReason = 'tasks' | 'tokens'; export interface PendingRotation { reason: CapReason; cap: number; /** What the generation that just ended had processed. */ previous: { tasks: number; tokens: number; }; overshoot: number; } export interface GenerationState { generation: number; tasks: string[]; tokens: number; /** Rotations in a row after which no further task was done (R22). */ stalled_rotations: number; done_at_last_rotation: number; usage_missing: number; started_at: number; /** Set at rotation, cleared once the new generation's first message carries the digest. */ pending_rotation?: PendingRotation; } /** Which threshold the generation has reached, if any. With `incoming` (the * task ids the next message carries) the tasks cap fires only for a message * that brings a task the generation lacks: a reminder about a task already in * it, or untagged mail, adds no task and so is no reason to rotate. The tokens * cap does not look at the message. */ export declare function capReached(s: Pick, cap: SessionCap | undefined, incoming?: readonly string[]): { reason: CapReason; value: number; cap: number; } | undefined; export declare function loadCounters(runDir: string, role: string, key: string): GenerationState; export declare function saveCounters(runDir: string, role: string, key: string, state: GenerationState): void; export declare class SessionCounters { private readonly runDir; private readonly role; private readonly key; constructor(runDir: string, role: string, key: string); /** The persisted state, read fresh. */ get state(): GenerationState; private update; /** A message was admitted; each task id it names is added once. */ admit(taskIds: readonly string[]): void; addTokens(n: number): void; /** A turn reported no usage. Returns how many have in this generation. */ noteUsageMissing(): number; /** End the generation: the next one starts empty, with a digest owed to its first message. */ rotate(hit: { reason: CapReason; cap: number; }, doneTasks: number): { from: GenerationState; overshoot: number; }; clearPendingRotation(): void; } //# sourceMappingURL=session-cap.d.ts.map