/** * runTagHygieneBackfill — FEAT-403 core (DB-only, CLI-independent so it's * directly unit-testable without spawning the daemon). * * Candidate selection (`WHERE repo blank OR project blank`) is what makes * this idempotent by construction (AC-3): a fully-tagged row is never * selected on a re-run, so re-running on a fully-tagged corpus is always a * pure no-op scan with zero mutation. * * Tier-1 (session cwd/project_id) and tier-2 (prompt-assisted, confidence- * gated) are applied per-row; tier-2 only runs when tier-1 found nothing at * all for that row (never mixes a tier-1 partial fill with a tier-2 guess in * the same row — keeps the mis-tag blast radius per row to one tier). * * Mutations run outside a single wrapping transaction, one UPDATE per * applied row: tier-2 calls an LLM per candidate (async), and better-sqlite3 * transactions must be synchronous. This is also a deliberately resumable * shape (durability principle) — if the process is interrupted mid-run, a * re-run picks up exactly where it left off via the same WHERE clause. */ import type { DB } from '../storage/db.js'; import type { Tier2InferFn } from './tier2-infer.js'; export interface BackfillOptions { dryRun: boolean; limit?: number; tier2Enabled: boolean; /** Minimum tier-2 confidence required to apply an inferred tag (AC-4). */ confidenceThreshold: number; } export interface BackfillCandidate { id: string; currentRepo: string | null; currentProject: string | null; proposedRepo: string | null; proposedProject: string | null; /** null when the memory was left untagged (no signal, or tier-2 confidence too low). */ tier: 1 | 2 | null; /** Only set when tier-2 ran for this row. */ confidence?: number; applied: boolean; } export interface BackfillResult { scanned: number; tier1Applied: number; tier2Applied: number; leftUntagged: number; dryRun: boolean; candidates: BackfillCandidate[]; } export declare function runTagHygieneBackfill(db: DB, opts: BackfillOptions, tier2Infer?: Tier2InferFn): Promise;