/** * Local SQLite store (node:sqlite, no native dependency). * * Two reasons this exists rather than reading transcripts on demand: * * - Claude Code purges transcripts after 30 days by default. Derived analysis has to * outlive its source or the "does this agent keep making the same mistake" question * can never be asked. * - Re-analysing every session on every page load doesn't scale past a few hundred runs. * * Nothing leaves the machine. The file is a plain SQLite database you can delete. */ import type { Analysis } from "./analyze/index.js"; import { type Label, type Run } from "./model.js"; import type { Postmortem } from "./postmortem.js"; export interface RunSummary { run_id: string; source: string; session_id: string; segment: number; project_path: string | null; git_branch: string | null; started_at: string | null; ended_at: string | null; duration_s: number | null; goal: string | null; label: Label; label_reason: string; max_severity: string; verification_status: string; files_changed: number; lines_added: number; lines_removed: number; total_tokens: number; cost_usd: number | null; cost_known: number; n_findings: number; n_events: number; trivial: number; synthetic: number; } export interface StoredRun extends RunSummary { trace: Run; analysis: Analysis; postmortem: Postmortem; source_file: string | null; content_hash: string; ingested_at: string; } export declare function defaultDbPath(): string; export declare class Store { readonly path: string; private readonly db; constructor(path?: string); /** * `CREATE TABLE IF NOT EXISTS` never adds columns, so a database written by * an older build keeps its old shape. Add anything missing rather than * asking the user to delete and re-ingest — the store is an archive, and * transcripts it was built from may already have been purged. */ private migrate; close(): void; upsert(run: Run, analysis: Analysis, pm: Postmortem): void; /** * Runs matching a deletion request, with enough detail to show the user what * they are about to lose. Every filter given must match — they narrow, not widen. * * Separate from `listRuns` because that one caps at 200 for display, and a * deletion that silently stopped at 200 would be the worst possible bug here. */ findForDeletion(opts: { ids?: string[]; project?: string | null; before?: string | null; synthetic?: boolean; }): Array<{ run_id: string; started_at: string | null; label: Label; project_path: string | null; goal: string | null; }>; /** * Delete runs and their findings. Returns how many rows went from `runs`. * * `ingest_log` is deliberately left alone. Its rows are what stop `ingest` from * re-reading a file, so keeping them means a deleted run stays deleted on the * next plain `ingest` — which is what someone removing sensitive data expects. * `ingest --force` re-reads regardless and will bring the run back if the * transcript still exists; deleting the transcript is the only way to prevent * that, and this tool never touches transcripts. */ deleteRuns(ids: string[]): number; /** * Flag runs as synthetic. Set by `seedDemo` after it stores them. * * Not a parameter on `upsert`: a re-ingest of real data must never be able to * clear or set this by accident, and `upsert` is on the hot path for both. */ markSynthetic(ids: string[]): void; noteIngest(path: string, mtime: number, size: number, runsFound: number): void; /** * True when re-reading this file would produce nothing new: the file itself has * not changed *and* the runs already stored from it were graded by the analyzer * we are running now. * * The analyzer half matters because a release that changes grading changes the * answer for a transcript that has not changed at all. Comparing only mtime and * size meant an upgrade silently kept the old verdicts and left the CLI telling * the user to fix it by hand with `--force`. The version lives on `runs` already, * so this needs no column of its own — a file whose stored runs disagree with the * current version is treated as changed and re-analysed. * * A file that produced no runs has nothing to regrade, so it stays skipped. */ isUnchanged(path: string, mtime: number, size: number, analyzerVersion: string | null): boolean; listRuns(opts?: { limit?: number; project?: string | null; label?: string | null; source?: string | null; includeTrivial?: boolean; /** * Synthetic runs are included by default, because `demo` exists to put them * in front of you. `corpus` is the one caller that opts out: its job is * measuring real behaviour, and fixtures in that number make it a lie. */ includeSynthetic?: boolean; }): RunSummary[]; /** * Every run id with the analyzer version that graded it, oldest first and with no * limit — `listRuns` caps at 200 and is for display. * * This exists because `ingest` can only regrade transcripts that are still on * disk, and Claude Code purges them after about thirty days. The stored trace is * then the only copy, so regrading has to be able to work from the store alone. */ runsToRegrade(analyzerVersion: string | null): string[]; getRun(runId: string): StoredRun | null; projects(): Array<{ project_path: string; n: number; last: string; }>; stats(): Record; }