export interface SessionRoleLimits { maxDbReadsPerSession: number | null; maxDbWritesPerSession: number | null; maxDbDeletesPerSession: number | null; maxDbRowsPerSession: number | null; maxFileReadsPerSession: number | null; maxFileWritesPerSession: number | null; maxFileDeletesPerSession: number | null; maxFileMbPerSession: number | null; maxResponseMbPerSession: number | null; } /** Normalize a raw bundle limits object (new or legacy keys) into the split shape. */ export declare function normalizeSessionLimits(raw: Record | undefined | null): SessionRoleLimits; export interface SessionUsage { sessionId: string; dbReads: number; dbWrites: number; dbDeletes: number; /** Cumulative rows returned by database tools. */ dbRows: number; fileReads: number; fileWrites: number; fileDeletes: number; /** Cumulative bytes moved by file tools. */ fileBytes: number; /** Cumulative bytes of ALL tool responses, any target. */ responseBytes: number; updatedAt: string; } export interface SessionLimitViolation { limit: keyof SessionRoleLimits; configured: number; actual: number; /** Human sentence for block messages and console events. */ description: string; } export type SessionOpClass = 'read' | 'write' | 'delete'; export type SessionOpTarget = 'db' | 'file' | 'other'; export declare function getSessionUsage(sessionId: string): SessionUsage; /** Record one classified operation against its target; returns the updated running totals. */ export declare function recordSessionOp(sessionId: string, target: SessionOpTarget, opClass: SessionOpClass): SessionUsage; /** * Record tool-response volume (MCP gateway). Bytes always count toward the * overall cap; rows count toward the DB budget only for DB-target calls, and * bytes toward the file budget only for file-target calls. */ export declare function recordSessionResponse(sessionId: string, input: { bytes: number; rows: number; target: SessionOpTarget; }): SessionUsage; /** * Classify an engine-inferred operation into a counter class AND target. * The engine's context is the discriminator: SQL detection sets `query`, * file-path detection sets `path`. Without context, provenance decides * (SQL-only verbs are uppercase, file/shell verbs lowercase); HTTP methods * land in 'other' (covered only by the overall response-volume cap). * MUST mirror backend/src/modules/policies/roles.ts `classifyOpForLimits` — * the two sides count the same ops or the console's numbers lie. */ export declare function classifyOpForLimits(operation: string, context?: Record): { target: SessionOpTarget; opClass: SessionOpClass; } | undefined; /** Limits that meter RESPONSE volume (checked after the tool ran, response withheld). */ export declare const RESPONSE_VOLUME_LIMITS: ReadonlySet; /** First exceeded limit for the given usage, or undefined when within bounds. */ export declare function checkSessionLimits(usage: SessionUsage, limits: SessionRoleLimits): SessionLimitViolation | undefined; /** * Estimate how many rows/records a tool response text carries. * JSON: total element count across arrays (a page of DB rows = its length). * Non-JSON: non-empty line count (CSV / table / psql output ≈ one row per line). * Deterministic heuristic — used only for cumulative volume limits, never * for per-item decisions, so approximate is fine. */ export declare function countResponseRows(text: string): number;