import { Splitter } from './splitter'; import { Embedding } from './embedding'; import { VectorDatabase } from './vectordb'; import { SemanticSearchResult } from './types'; import { FileSynchronizer } from './sync/synchronizer'; /** * Thrown by indexCodebase / processFileList when an AbortSignal fires * mid-indexing. Callers (e.g. the MCP server's clear_index handler) use * this to detect a cooperative cancel vs. a real failure. */ export declare class IndexAbortError extends Error { constructor(message?: string); } /** * Thrown when the embedding API fails (quota exhausted, auth failure, * network error, etc.). Propagates through processFileList so callers * can distinguish a critical embedding failure from a per-file skip. * * Unlike a per-file read/parse error (which is logged and skipped), * an EmbeddingError is always re-thrown so that the entire indexing * pipeline stops. This prevents silent partial indexing: Milvus would * otherwise receive zero vectors while the snapshot marks files as done. */ export declare class EmbeddingError extends Error { constructor(message: string); } export interface ContextConfig { embedding?: Embedding; vectorDatabase?: VectorDatabase; codeSplitter?: Splitter; supportedExtensions?: string[]; ignorePatterns?: string[]; customExtensions?: string[]; customIgnorePatterns?: string[]; collectionNameOverride?: string; } export declare class Context { private static readonly MAX_COLLECTION_NAME_LENGTH; private embedding; private vectorDatabase; private codeSplitter; private supportedExtensions; private baseIgnorePatterns; private ignorePatterns; private collectionNameOverride?; private warnedOverrideSanitization; private synchronizers; constructor(config?: ContextConfig); /** * Get embedding instance */ getEmbedding(): Embedding; /** * Get vector database instance */ getVectorDatabase(): VectorDatabase; /** * Get code splitter instance */ getCodeSplitter(): Splitter; /** * Get supported extensions */ getSupportedExtensions(): string[]; /** * Get supported extensions for the current operation without mutating * the Context's persistent extension list. */ getEffectiveSupportedExtensions(additionalExtensions?: string[]): string[]; /** * Get ignore patterns */ getIgnorePatterns(): string[]; /** * Get synchronizers map */ getSynchronizers(): Map; /** * Set synchronizer for a collection */ setSynchronizer(collectionName: string, synchronizer: FileSynchronizer): void; /** * Public wrapper for loadIgnorePatterns private method */ getLoadedIgnorePatterns(codebasePath: string): Promise; /** * Get the effective ignore patterns for a codebase without relying on * codebase-specific patterns already stored on this Context instance. */ getEffectiveIgnorePatterns(codebasePath: string, additionalIgnorePatterns?: string[]): Promise; /** * Public wrapper for prepareCollection private method */ getPreparedCollection(codebasePath: string): Promise; /** * Get isHybrid setting from environment variable with default true */ private getIsHybrid; /** * Generate collection name based on codebase path and hybrid mode */ getCollectionName(codebasePath: string): string; private getValidOverrideValue; private sanitizeCollectionNameSuffix; /** * Index a codebase for semantic search * @param codebasePath Codebase root path * @param progressCallback Optional progress callback function * @param forceReindex Whether to recreate the collection even if it exists * @param additionalIgnorePatterns Request-scoped ignore patterns * @param additionalSupportedExtensions Request-scoped file extensions * @param requestSplitter Request-scoped splitter for this indexing run * @returns Indexing statistics */ indexCodebase(codebasePath: string, progressCallback?: (progress: { phase: string; current: number; total: number; percentage: number; }) => void, forceReindex?: boolean, additionalIgnorePatterns?: string[], additionalSupportedExtensions?: string[], requestSplitter?: Splitter, signal?: AbortSignal): Promise<{ indexedFiles: number; totalChunks: number; status: 'completed' | 'limit_reached'; }>; reindexByChange(codebasePath: string, progressCallback?: (progress: { phase: string; current: number; total: number; percentage: number; }) => void, additionalIgnorePatterns?: string[], additionalSupportedExtensions?: string[], requestSplitter?: Splitter): Promise<{ added: number; removed: number; modified: number; }>; private deleteFileChunks; /** * Semantic search with unified implementation * @param codebasePath Codebase path to search in * @param query Search query * @param topK Number of results to return * @param threshold Similarity threshold */ semanticSearch(codebasePath: string, query: string, topK?: number, threshold?: number, filterExpr?: string): Promise; /** * Deduplicate search results by file + line range overlap. * Keeps higher-scored result when two results from the same file overlap >50%. */ private deduplicateResults; /** * Check if index exists for codebase * @param codebasePath Codebase path to check * @returns Whether index exists */ hasIndex(codebasePath: string): Promise; /** * Clear index * @param codebasePath Codebase path to clear index for * @param progressCallback Optional progress callback function */ clearIndex(codebasePath: string, progressCallback?: (progress: { phase: string; current: number; total: number; percentage: number; }) => void): Promise; /** * Update ignore patterns (merges with default patterns and existing patterns) * @param ignorePatterns Array of ignore patterns to add to defaults */ updateIgnorePatterns(ignorePatterns: string[]): void; /** * Add custom ignore patterns (from MCP or other sources) without replacing existing ones * @param customPatterns Array of custom ignore patterns to add */ addCustomIgnorePatterns(customPatterns: string[]): void; /** * Reset ignore patterns to defaults only */ resetIgnorePatternsToDefaults(): void; /** * Update embedding instance * @param embedding New embedding instance */ updateEmbedding(embedding: Embedding): void; /** * Update vector database instance * @param vectorDatabase New vector database instance */ updateVectorDatabase(vectorDatabase: VectorDatabase): void; /** * Update splitter instance * @param splitter New splitter instance */ updateSplitter(splitter: Splitter): void; /** * Prepare vector collection */ private prepareCollection; /** * Recursively get all code files in the codebase */ private getCodeFiles; /** * Process a list of files with streaming chunk processing * @param filePaths Array of file paths to process * @param codebasePath Base path for the codebase * @param onFileProcessed Callback called when each file is processed * @returns Object with processed file count and total chunk count */ private processFileList; /** * Process accumulated chunk buffer */ private processChunkBuffer; /** * Process a batch of chunks */ private processChunkBatch; /** * Validate that the embedding batch response is well-formed before writing * any vectors to Milvus. Throwing EmbeddingError here aborts the entire * indexing run so that no partial / empty vectors are persisted. * * @param embeddings - Array of embedding vectors returned by the API. * @param expectedCount - Number of chunks submitted in the batch request. * @throws EmbeddingError if the response is missing, mismatched, or contains * any empty vector. * @returns void */ private validateEmbeddings; /** * Get programming language based on file extension */ private getLanguageFromExtension; /** * Generate unique ID based on chunk content and location * @param relativePath Relative path to the file * @param startLine Start line number * @param endLine End line number * @param content Chunk content * @returns Hash-based unique ID */ private generateId; /** * Read ignore patterns from file (e.g., .gitignore) * @param filePath Path to the ignore file * @returns Array of ignore patterns */ static getIgnorePatternsFromFile(filePath: string): Promise; /** * Load ignore patterns from various ignore files in the codebase. * Returns the effective patterns for the current codebase/request without * allowing file-based patterns from previous codebases to leak forward. * @param codebasePath Path to the codebase * @param additionalIgnorePatterns Ignore patterns for the current request */ private loadIgnorePatterns; /** * Find all .xxxignore files in the codebase directory * @param codebasePath Path to the codebase * @returns Array of ignore file paths */ private findIgnoreFiles; /** * Load global ignore file from ~/.context/.contextignore * @returns Array of ignore patterns */ private loadGlobalIgnoreFile; /** * Load ignore patterns from a specific ignore file * @param filePath Path to the ignore file * @param fileName Display name for logging * @returns Array of ignore patterns */ private loadIgnoreFile; private dedupePatterns; /** * Get custom extensions from environment variables * Supports CUSTOM_EXTENSIONS as comma-separated list * @returns Array of custom extensions */ private getCustomExtensionsFromEnv; /** * Get custom ignore patterns from environment variables * Supports CUSTOM_IGNORE_PATTERNS as comma-separated list * @returns Array of custom ignore patterns */ private getCustomIgnorePatternsFromEnv; private normalizeExtensions; /** * Add custom extensions (from MCP or other sources) without replacing existing ones * @param customExtensions Array of custom extensions to add */ addCustomExtensions(customExtensions: string[]): void; /** * Get current splitter information */ getSplitterInfo(): { type: string; hasBuiltinFallback: boolean; supportedLanguages?: string[]; }; /** * Check if current splitter supports a specific language * @param language Programming language */ isLanguageSupported(language: string): boolean; /** * Get which strategy would be used for a specific language * @param language Programming language */ getSplitterStrategyForLanguage(language: string): { strategy: 'ast' | 'langchain'; reason: string; }; } //# sourceMappingURL=context.d.ts.map