/** * Indexing Service for MCP Server * * Provides reusable indexing logic for: * - File indexing with chunking and embeddings * - Knowledge graph building * - Incremental updates * * This service reuses the same indexing logic as the CLI init command. */ export interface IndexingProgress { phase: 'scanning' | 'indexing' | 'graph' | 'raptor' | 'complete'; filesTotal: number; filesProcessed: number; chunksCreated: number; nodesCreated: number; edgesCreated: number; /** Warning message when file limits are reached */ limitWarning?: string; /** Current scanning status (during scan phase) */ scanningStatus?: { foldersScanned: number; filesFound: number; currentFolder?: string; percentage: number; }; } export interface IndexingResult { success: boolean; filesIndexed: number; chunksCreated: number; nodesCreated: number; edgesCreated: number; durationMs: number; errors: string[]; /** Warning messages about limits or recommendations */ warnings: string[]; } export declare class IndexingService { private logger; private embeddingService; private readonly parsers; private readonly extensionToParser; private readonly SUPPORTED_EXTENSIONS; private readonly IGNORE_DIRS; private readonly SENSITIVE_FILE_PATTERNS; private readonly MAX_FILE_SIZE_BYTES; constructor(); /** * Safely read a file with encoding detection * Returns null if file cannot be read (binary, unknown encoding, etc.) * * Detection strategy: * 1. Check for BOM (Byte Order Mark) to detect UTF-16/UTF-32 * 2. Check for null bytes (likely binary file) * 3. Try UTF-8 decoding * 4. Fall back to latin1 for legacy Windows files */ private safeReadFile; /** * Check if buffer has valid UTF-8 structure (heuristic) * Checks for proper multi-byte sequences */ private hasValidUtf8Structure; /** * Index a project directory * Creates vector embeddings and knowledge graph nodes/edges */ indexProject(projectPath: string, projectId: string, onProgress?: (progress: IndexingProgress) => void): Promise; /** * Index a single file (for incremental updates) * Uses two-stage change detection for maximum speed: * 1. mtime check (~0.1ms) - if file not modified since indexing, skip * 2. hash check (~1-5ms) - if mtime changed but content same, skip * 3. reindex (~100-500ms) - only if content actually changed */ indexSingleFile(projectPath: string, relativePath: string, projectId: string, options?: { forceReindex?: boolean; }): Promise<{ success: boolean; chunksCreated: number; nodesCreated?: number; skipped?: boolean; skipReason?: string; }>; /** * Index a single file to the knowledge graph */ private indexFileToGraph; /** * Delete a file from the index */ deleteFile(projectId: string, relativePath: string): Promise<{ success: boolean; deleted: number; }>; private readonly FILE_LIMITS; /** * Load user-defined exclusions from .codeseeker/exclusions.json */ private loadUserExclusions; /** * Check if a file matches any user exclusion pattern */ private matchesUserExclusion; /** * Check if a file matches sensitive file patterns (should never be indexed) */ private isSensitiveFile; /** * Scan for indexable files in a directory * Reports progress during scanning via callback * Respects user-defined exclusions from .codeseeker/exclusions.json */ private scanForFiles; /** * Index a single file with chunking and embeddings */ private indexFile; /** * Build knowledge graph for the project */ private buildKnowledgeGraph; /** * Extract code elements (classes, functions) from file content * Uses language-specific parsers for C#, Go, Python, Java * Falls back to generic regex for JS/TS */ private extractCodeElementsAsync; /** * Regex-based extraction for JS/TS and fallback * Also handles C# with specialized regex patterns */ private extractCodeElementsRegex; /** * Extract import relationships from file content * Supports: JS/TS imports, require(), C# using statements */ private extractImports; /** * Build a map of namespace -> files for C# projects * This is cached per indexing run for performance */ private namespaceMapCache; private buildNamespaceMap; /** * Delete embeddings for a specific file */ private deleteFileEmbeddings; /** * Delete graph nodes for a specific file * Uses the deleteByFilePaths method for incremental deletion */ private deleteFileGraphNodes; } //# sourceMappingURL=indexing-service.d.ts.map