/** * Query layer for `find_by_intent` — the architectural decisions * land in ADR-09. In brief: * * - Substrate: SQLite FTS5 virtual table `claims_fts` * - Ranking: built-in BM25 (negative scores, best = most-negative) * - Query: `"exact phrase" OR tok1 OR tok2 ...` — lets BM25 do * phrase-vs-scatter weighting in one pass * - Response: one record per linked symbol, top-scoring claim * surfaced as `matchedIntent`. No `relevance` score on the wire. * * User input is always sanitized before it hits FTS5. Operators, * quotes, and MATCH syntax cannot come through directly — a * `raw_query` escape hatch is a post-MVP conversation (see ADR-09's * "post-v0.1 extensions" section). */ import type { DatabaseInstance } from "../storage/db.js"; import type { Severity, SymbolKind } from "../types.js"; export interface FindByIntentMatch { symbolId: string; name: string; path: string; line: number; kind: SymbolKind; signature?: string; matchedIntent: { source: string; severity: Severity; claim: string; rationale?: string; excerpt?: string; }; } export interface FindByIntentOptions { query: string; /** Caller-provided cap. The function also clamps to a hard max. */ limit: number; } /** Absolute ceiling regardless of what the caller passes. */ export declare const MAX_LIMIT = 50; /** * Strip non-letter / non-digit / non-whitespace, normalize whitespace * runs to single spaces, trim. Unicode letters/digits are preserved * via `\p{L}` / `\p{N}` so non-ASCII claim text doesn't get garbled. * * Underscore (`_`) and hyphen (`-`) are also preserved so that * identifier-shaped query terms — `narrow_attribution`, * `find-by-intent` — survive as single tokens. The FTS5 tokenizer * (ADR-17) is configured with these as token characters; a sanitizer * that stripped them would defeat that, splitting the query before * it reached the index. * * Exported for direct unit testing; callers typically go through * {@link findByIntent}. */ export declare function sanitizeQuery(input: string): { cleaned: string; tokens: string[]; }; /** * Build the FTS5 MATCH string from a token list. Returns null when * there are no tokens — callers treat that as "empty query, zero * matches," not as an error. * * Shape: `"exact phrase" OR tok1 OR tok2 ...`. The quoted prefix * lets BM25 boost contiguous occurrences; the OR-joined suffix * catches scattered-token matches. One MATCH call, BM25 handles * the ordering. * * Tokens containing `-` are individually quoted so FTS5's NOT * operator doesn't swallow them (see {@link escapeForMatch}). */ export declare function buildMatchQuery(tokens: readonly string[]): string | null; /** * Run the find_by_intent query against the given DB. Returns * ranked matches up to `limit` (clamped to MAX_LIMIT). */ export declare function findByIntent(db: DatabaseInstance, options: FindByIntentOptions): FindByIntentMatch[]; //# sourceMappingURL=find-by-intent.d.ts.map