/**
 * StopGateDb — SQLite persistence for the UnjustifiedStopGate.
 *
 * Spec: docs/specs/context-death-pitfall-prevention.md § (d)
 *
 * Tables (per spec § (d), lines 373-377):
 *   - sessions(session_id, agent_id, started_at)
 *   - session_continue_counts(session_id, count, updated_at)
 *   - session_stuck_state(session_id, last_ceiling_hit_at)
 *   - agent_eval_aggregate(agent_id, day_key, triggered_count,
 *     shadow_count, continue_count, ...)    — hourly rollup
 *   - annotations(event_id, operator, verdict, rationale, dwell_ms,
 *     created_at)                           — operator review tool
 *   - events(event_id, session_id, ts, mode, decision, rule,
 *     invalidKind, evidence_pointer_json, latency_ms, reason_preview)
 *     — decision log
 *
 * Storage: `~/.instar/<agent-id>/server-data/stop-gate.db` per spec §
 * P0.8 (outside project tree, chmod 600). For in-process tests we
 * support `:memory:`.
 *
 * Threat model: drift-correction, not security boundary. Session tampering
 * with the DB file is out of scope.
 */
import type { Database as BetterSqliteDatabase } from 'better-sqlite3';
export type EvalMode = 'off' | 'shadow' | 'enforce';
export type Decision = 'continue' | 'allow' | 'escalate' | 'force_allow';
export type InvalidKind = null | 'timeout' | 'malformed' | 'invalidRule' | 'invalidEvidence' | 'missingPointer' | 'llmUnavailable' | 'breakerOpen' | 'queue_shed_overload' | 'staleCompaction';
export interface EvalEvent {
    eventId: string;
    sessionId: string;
    ts: number;
    mode: EvalMode;
    decision: Decision | null;
    rule: string | null;
    invalidKind: InvalidKind;
    evidencePointerJson: string | null;
    latencyMs: number;
    reasonPreview: string;
    agentId: string;
}
export interface Annotation {
    eventId: string;
    operator: string;
    verdict: 'correct' | 'incorrect' | 'unclear';
    rationale: string;
    dwellMs: number;
    createdAt: number;
}
export interface ContinueCountState {
    sessionId: string;
    count: number;
    updatedAt: number;
}
export declare class StopGateDb {
    private db;
    private stmts;
    constructor(opts: {
        dbPath: string;
    } | {
        db: BetterSqliteDatabase;
    });
    private _unregisterSqlite?;
    private _closed;
    private prepareStatements;
    recordEvent(event: EvalEvent): void;
    addAnnotation(ann: Annotation): void;
    recentEvents(limit?: number): EvalEvent[];
    eventById(eventId: string): EvalEvent | null;
    annotationsFor(eventId: string): Annotation[];
    /** Increment the continue-count for a session. Returns the new value. */
    incrementContinueCount(sessionId: string, now?: number): number;
    getContinueCount(sessionId: string): ContinueCountState | null;
    setStuck(sessionId: string, ts?: number): void;
    isStuck(sessionId: string): boolean;
    recordSessionStart(sessionId: string, agentId: string, startedAt?: number): void;
    getSessionStartedAt(sessionId: string): number | null;
    rollupAggregate(opts: {
        agentId: string;
        dayKey: string;
        triggeredDelta?: number;
        shadowDelta?: number;
        continueDelta?: number;
        allowDelta?: number;
        escalateDelta?: number;
        failureDelta?: number;
    }): void;
    getAggregate(agentId: string, dayKey: string): {
        triggered: number;
        shadow: number;
        continueCount: number;
        allowCount: number;
        escalateCount: number;
        failureCount: number;
    } | null;
    close(): void;
}
export declare function dayKeyFor(ts?: number): string;
//# sourceMappingURL=StopGateDb.d.ts.map