/** * NEXUS Symbol Context Augmentation * * FTS5-backed BM25 search against nexus_nodes for PreToolUse hook injection. * Returns top 5 symbols with callers/callees/community metadata. * * Search path: FTS5 MATCH (BM25 ranked) with fallback to LIKE scan when the * FTS5 table is absent (e.g., nexus.db predates T1839 and ensureNexusFts5 * has not yet run). * * Used by: packages/cleo-os/src/hooks/nexus-augment.sh (PreToolUse handler) * * @task T1061 * @task T1765 — fix wrong column names + operator precedence bug + community_id type * @task T1839 — FTS5 BM25 search replacing O(n) LIKE scan (p50 target < 50ms) * @epic T1042 */ import { type EngineResult } from '../engine-result.js'; /** * Result of augmenting a symbol with context */ export interface AugmentResult { id: string; label: string; kind: string; filePath?: string; startLine?: number; endLine?: number; callersCount: number; calleesCount: number; /** Community identifier string (e.g. "comm_3"). Text in nexus_nodes.community_id. */ communityId?: string; communitySize?: number; } /** * Escape a user-supplied search pattern for use in an FTS5 MATCH expression. * * FTS5 MATCH syntax reserves `"`, `*`, `^`, `(`, `)`, `:`, and whitespace as * special characters. This escaper wraps each whitespace-separated token in * double-quotes so the query is treated as a sequence of literal prefix tokens. * A trailing `*` is appended to each token to enable prefix matching so that * "loadC" still matches "loadConfig". * * @param pattern - Raw user pattern (e.g. "loadConfig") * @returns FTS5 MATCH argument string (e.g. `"loadConfig"*`) */ export declare function escapeFts5Pattern(pattern: string): string; /** * Search nexus_nodes for symbols matching pattern. * * Primary path (T1839): uses FTS5 MATCH with BM25 ranking against the * nexus_symbols_fts virtual table when available (p50 target < 50ms). * Fallback path: LIKE scan for databases that predate T1839. * * Restricts to callable symbols (function, method, constructor, class, * interface, type_alias) to maximise relevance for code intelligence contexts. * Exported symbols are ranked above unexported ones within the same kind tier. * * Community sizes are resolved in a single batched query rather than N+1 * individual look-ups. * * Fixes (T1765): * - Wrong column names in callers/callees subqueries: * `target_node_id`/`source_node_id`/`relation_type` * → `target_id`/`source_id`/`type` * - Operator precedence bug: `WHERE label LIKE ? OR file_path LIKE ? AND kind IN (...)` * parsed as `label LIKE ? OR (file_path LIKE ? AND kind IN (...))` because AND * binds tighter than OR. Fixed with explicit parentheses. * - `community_id` typed as `number | null` but the schema stores text (e.g. "comm_3"). * Corrected to `string | null`. * * @param pattern - Search pattern (function name, filename fragment, etc.) * @param limit - Max results (default 5) * @returns Array of augmented symbol results, or empty if nexus.db absent */ export declare function augmentSymbol(pattern: string, limit?: number): AugmentResult[]; /** * Format augmented results as plain text for hook injection. * * Output sent to stderr in PreToolUse hook handler so it doesn't * interfere with tool output parsing. * * @param results - Array of augment results * @returns Plain text formatted for stderr injection */ export declare function formatAugmentResults(results: AugmentResult[]): string; export declare function nexusAugment(pattern: string, limit?: number): Promise>; export declare function nexusSearchCode(pattern: string, limit: number): Promise>; //# sourceMappingURL=augment.d.ts.map