/** * Codebase indexer service * Uses chunk-level indexing for better search granularity */ import type { EmbeddingProvider } from './embeddings.js'; import { type Storage } from './storage.js'; import { type SearchIndex } from './tfidf.js'; import { type FileMetadata } from './utils.js'; import { VectorStorage } from './vector-storage.js'; export interface IndexerOptions { codebaseRoot?: string; maxFileSize?: number; storage?: Storage; onProgress?: (current: number, total: number, file: string) => void; watch?: boolean; onFileChange?: (event: FileChangeEvent) => void; embeddingProvider?: EmbeddingProvider; vectorBatchSize?: number; indexingBatchSize?: number; lowMemoryMode?: boolean; } export interface FileChangeEvent { type: 'add' | 'change' | 'unlink'; path: string; timestamp: number; } export interface IndexingStatus { isIndexing: boolean; progress: number; totalFiles: number; processedFiles: number; totalChunks: number; indexedChunks: number; currentFile?: string; } /** * Result of comparing filesystem with database */ export interface FileDiff { added: FileMetadata[]; changed: FileMetadata[]; deleted: string[]; unchanged: number; } export declare class CodebaseIndexer { private codebaseRoot; private maxFileSize; private storage; private searchIndex; private incrementalEngine; private pendingFileChanges; private searchCache; private watcher; private isWatching; private onFileChangeCallback?; private pendingUpdates; private ignoreFilter; private status; private vectorStorage?; private embeddingProvider?; private vectorBatchSize; private indexingBatchSize; private lowMemoryMode; constructor(options?: IndexerOptions); /** * Get current indexing status */ getStatus(): IndexingStatus; /** * Compare filesystem with database to find changes * Used for incremental updates after long periods of inactivity */ private diffFilesystem; /** * Process incremental changes (add, update, delete files) * Uses chunk-level indexing with SQL-based updates */ private processIncrementalChanges; /** * Get search index */ getSearchIndex(): SearchIndex | null; /** * Index the codebase */ index(options?: IndexerOptions): Promise; /** * Start watching for file changes * Uses @parcel/watcher which provides native FSEvents on macOS */ startWatch(): Promise; /** * Check if a file should be ignored */ private shouldIgnore; /** * Stop watching for file changes */ stopWatch(): Promise; /** * Close indexer and release all resources * Should be called when the indexer is no longer needed */ close(): Promise; /** * Handle file change events with debouncing */ private handleFileChange; /** * Process file change and update index */ private processFileChange; /** * Rebuild search index from current storage * Uses incremental update when possible for performance */ private rebuildSearchIndex; /** * Full rebuild of search index (fallback when incremental not possible) * For persistent storage, this rebuilds the chunk-level index */ private fullRebuildSearchIndex; /** * Persist search index to storage * NOTE: For PersistentStorage, chunk-based indexing happens inline during index() * This method is only used for in-memory storage fallback */ private persistSearchIndex; /** * Check if currently watching for changes */ isWatchEnabled(): boolean; /** * Search the codebase * Returns chunk-level results when using persistent storage (SQL-based search) */ search(query: string, options?: { limit?: number; includeContent?: boolean; fileExtensions?: string[]; pathFilter?: string; excludePaths?: string[]; contextLines?: number; maxSnippetChars?: number; maxSnippetBlocks?: number; }): Promise; /** * Chunk-based search with BM25 scoring * Returns chunk content directly (no separate snippet extraction needed) */ private searchChunks; /** * Extract code block snippets from content around matched terms * * Returns the most relevant code blocks (not just lines) with context. * Blocks are ranked by term density (more matched terms = higher score). */ private extractSnippet; /** * Get file content */ getFileContent(filePath: string): Promise; /** * Get total indexed files count */ getIndexedCount(): Promise; /** * Get vector storage (for hybrid search) */ getVectorStorage(): VectorStorage | undefined; /** * Get embedding provider (for hybrid search) */ getEmbeddingProvider(): EmbeddingProvider | undefined; /** * Build vector index from file metadata (Memory optimization) * Generates embeddings per CHUNK, not per file */ private buildVectorIndexFromMetadata; /** * Update vectors for a single file (chunk-level) * Deletes old chunks and adds new ones */ private updateFileVector; /** * Delete vectors for a file (all chunks) */ private deleteFileVector; } export interface ScoreComponent { term: string; termFrequency: number; documentFrequency: number; idf: number; bm25: number; } export interface SearchResult { path: string; score: number; matchedTerms: string[]; scoreComponents?: ScoreComponent[]; language?: string; size: number; snippet?: string; chunkType?: string; startLine?: number; endLine?: number; } //# sourceMappingURL=indexer.d.ts.map