Metadata pre-filter for query_rule_chunks / fts_search. Each field is
optional and acts as an AND clause: when set, rows must match the
given value. repo_scope is exact when present; callers that inject
rules into agents should pass the current repo/project and avoid
unscoped fallback.
FTS5 keyword search. Returns (chunk_id, rank) pairs ordered by BM25
rank (smaller = better in SQLite FTS5). top_k caps the result size
BEFORE the metadata filter is applied — we fetch top_k * 4 raw
candidates from FTS then post-filter in Rust so rules that fail the
metadata check don’t eat into the keyword budget.
Variant of gather_embedding_diagnostics that additionally consults
the activity stream: if the static profile comparison did not already
flag degradation but a recent embed call fell back to local SHA1, the
lane is reported as provider_fallback (a query-time regression the
persisted profile cannot see). Best-effort — a missing activity log is
simply ignored.
Resolve the per-project pool for the current working directory. Convenience
wrapper that determines the project root, hashes it, and calls
get_pool_for_project. Callers that already hold a hash should call
get_pool_for_project directly.
Get or lazily create the index_db pool for a project. Pool creation is
serialised on the cache mutex so two tool calls racing on the same
project produce exactly one pool.
Load chunks from the index DB applying the metadata pre-filter at the
SQL layer. filter.language matches exact equality when set;
filter.repo_scope matches exact equality when set. NULL repo scope is
unattributed metadata and must not be widened into another repo at runtime.