import { type CrashEvent } from "@gajae-code/utils"; export declare const CRASH_INDEX_VERSION = 1; /** Per-entry message preview cap. */ export declare const CRASH_INDEX_MESSAGE_MAX_BYTES = 512; /** Per-entry serialized cap. */ export declare const CRASH_INDEX_ENTRY_MAX_BYTES = 1024; /** Whole-index serialized cap. */ export declare const CRASH_INDEX_MAX_BYTES: number; /** Entry-count cap; with the per-entry cap this keeps the file under the byte cap. */ export declare const CRASH_INDEX_MAX_SIGNATURES = 128; /** How many `.corrupt-*` siblings are kept before the oldest are deleted. */ export declare const CRASH_INDEX_MAX_QUARANTINE = 3; export interface CrashSignatureEntry { fpv: number; errorName: string; messageClass: string; /** Occurrences ever journaled for this signature. Never decreases. */ lifetimeCount: number; /** Occurrences whose record is still present in the current crash log. */ retainedCount: number; firstSeen: number; lastSeen: number; lastRecordId: string; /** Journal-append-order occurrence id, independent of display-time `lastSeen`. */ lastAppendRecordId?: string; reportedAt?: number; reportedIssueUrl?: string; acknowledgedAt?: number; /** Epoch ms this signature was last accepted by the configured upstream. */ relayedAt?: number; /** Occurrence record represented by the durable upstream watermark. */ relayedRecordId?: string; /** Refusal marker for the exact record and sanitizer contract. */ relayRefusedRecordId?: string; relayRefusedVersion?: string; /** Issues this install already "+1"ed, so re-invocations cannot spam comments. */ commentedIssues?: string[]; } export interface CrashIndex { version: number; updatedAt: number; /** Epoch ms of the last startup nudge, or 0. */ lastNudgedAt: number; /** True when a new signature could not be stored because nothing was evictable. */ overflow: boolean; recentEventIds: string[]; recentJournalDigests: string[]; /** Log-recovered occurrence ids awaiting a possibly delayed journal event. */ recoveredRecordIds: string[]; /** Reported or acknowledged signatures evicted from the index; never recovered from the log. */ retiredFingerprints: string[]; signatures: Record; } export interface CrashStatePaths { index: string; events: string; crashLog: string; } export declare function resolveCrashStatePaths(agentDir?: string): CrashStatePaths; export declare function emptyCrashIndex(): CrashIndex; /** * Strict index parse. Any deviation — unknown key, wrong alphabet, control * character, out-of-range timestamp, count overflow — rejects the whole file so * it is quarantined and rebuilt from the journal rather than trusted. */ export declare function parseCrashIndex(raw: string, now?: number): CrashIndex | undefined; /** Apply one journal event to the in-memory index. Returns whether it changed anything. */ export declare function applyCrashEvent(index: CrashIndex, event: CrashEvent, now: number): boolean; export interface CompactCrashIndexOptions { paths?: CrashStatePaths; now?: number; } /** * Merge journal events into the index under the cross-process file lock. * * Bounded and idempotent: the journal is rotated aside before it is read (so a * concurrent fatal append lands in a fresh file rather than being lost to a * truncate), occurrence ids are deduped, and a crashed compaction's leftover * file is picked up by the next run. */ export declare function compactCrashIndex(options?: CompactCrashIndexOptions): Promise; /** Read the index without compacting. Missing or invalid files read as empty. */ export declare function readCrashIndex(paths?: CrashStatePaths): Promise; /** * Record a state change through the journal, then compact. * * Writing through the journal (rather than editing the index directly) is what * makes concurrent writers safe: two processes stamping `reportedAt` at the * same moment both land an event, and the compactor merges them. */ export declare function recordCrashStateEvent(event: CrashEvent, options?: CompactCrashIndexOptions): Promise; export interface CrashSignatureView extends CrashSignatureEntry { fingerprint: string; } /** Signatures newest-first, which is the order both the CLI and the nudge use. */ export declare function listCrashSignatures(index: CrashIndex): CrashSignatureView[];