/** * Streaming corpus scanner. * * Requirements this design answers, in order of importance: * - one malformed message must never stop a run, so every failure becomes a row * - bounded memory, so files are streamed and results are flushed in batches * - resumable, so an interrupted run skips what it already recorded * - deterministic, so the same seed always produces the same sample * - no message content in any log line * * Backpressure is driven from here rather than inside the pool: the scanner keeps a bounded window * of in flight tasks and awaits a completion before dispatching more. That keeps peak memory * proportional to the window size rather than to the corpus size. */ import { type RunStatus } from './store'; export interface ScanOptions { root: string; dbPath: string; /** Number of worker threads. Defaults to cores minus two, minimum one. */ concurrency?: number; /** Deterministic sample size. Zero or undefined scans everything. */ sample?: number; /** Seed for deterministic sampling. */ seed?: string; /** Skip files already recorded by this processing version. Default true. */ resume?: boolean; /** Files larger than this are recorded as oversize and not parsed. Default 32 MiB. */ maxFileBytes?: number; /** Decoded text retained per part. Default 1 MiB. */ maxTextPartBytes?: number; /** Per file timeout in milliseconds. Default 30000. */ timeoutMs?: number; /** Rows buffered before a database write. Default 500. */ batchSize?: number; /** Filename filter. Default matches .eml case insensitively. */ pattern?: RegExp; /** Called with progress updates. */ onProgress?: (progress: ScanProgress) => void; /** Progress callback interval in milliseconds. Default 1000. */ progressIntervalMs?: number; } export interface ScanProgress { seen: number; total: number; processed: number; failed: number; skipped: number; elapsedMs: number; filesPerSecond: number; etaMs: number | null; rssBytes: number; } export interface ScanSummary extends ScanProgress { runId: number; /** * How the run ended. Only `completed` may be consumed as a baseline. * * `aborted` is a signal or a worker crash loop; `failed` is a database or write error. Both * leave partial output that looks exactly like a small corpus, which is why the state is * recorded explicitly rather than inferred from the row count. */ status: RunStatus; } interface Candidate { relPath: string; size: number; mtime: number; } /** * Walk a directory tree and yield candidate files. * * Uses opendir so that a directory with 320k entries is streamed rather than materialised as one * large array by readdir. Unreadable entries are skipped silently: a permission error on one file * is not a reason to abort a corpus walk. */ export declare function walkFiles(root: string, pattern: RegExp): AsyncGenerator; /** * Select a deterministic sample. * * Each path is mapped to a uniform value by hashing it with the seed, and the lowest `count` values * win. The result depends only on the path set and the seed, never on iteration order, so a sample * is reproducible across machines and across partial runs. */ export declare function selectSample(candidates: readonly Candidate[], count: number, seed: string): Candidate[]; export declare function scanCorpus(options: ScanOptions): Promise; export {}; //# sourceMappingURL=scanner.d.ts.map