/** * Fingerprints Manager Module * * Provides file fingerprint tracking for delta detection during incremental indexing: * - Maps relative file paths to SHA256 content hashes * - Detects which files have changed since last index * - Supports atomic saves to prevent corruption * - Optimized batch operations for large projects */ /** * Fingerprints map type * * Maps relative file paths (forward-slash separated) to SHA256 content hashes. * - Key: relative path (e.g., "src/index.ts") * - Value: SHA256 hash of file content (64 hex characters) */ export type Fingerprints = Map; /** * Result of delta calculation between stored and current fingerprints */ export interface DeltaResult { /** Files that exist in current but not in stored fingerprints */ added: string[]; /** Files that exist in both but have different hashes */ modified: string[]; /** Files that exist in stored but not in current fingerprints */ removed: string[]; /** Files that exist in both with the same hash */ unchanged: string[]; } /** Current fingerprints file version */ export declare const FINGERPRINTS_VERSION = "1.0.0"; /** * Load fingerprints from an index path * * Loads fingerprints.json from the index directory. * Returns an empty Map if file doesn't exist. * * @param indexPath - Absolute path to the index directory * @returns Fingerprints map (empty if file doesn't exist) * @throws MCPError if fingerprints file is corrupt * * @example * ```typescript * const fingerprints = await loadFingerprints('/home/user/.mcp/search/indexes/abc123'); * console.log(fingerprints.size); // Number of tracked files * ``` */ export declare function loadFingerprints(indexPath: string): Promise; /** * Save fingerprints to an index path * * Saves the fingerprints to fingerprints.json with atomic write (temp + rename). * This prevents partial writes on crash. * * @param indexPath - Absolute path to the index directory * @param fingerprints - Fingerprints map to save * * @example * ```typescript * const fingerprints = new Map([['src/index.ts', 'abc123...']]); * await saveFingerprints('/path/to/index', fingerprints); * ``` */ export declare function saveFingerprints(indexPath: string, fingerprints: Fingerprints): Promise; /** * Calculate delta between stored fingerprints and current files * * Hashes current files and compares with stored fingerprints to detect: * - Added files (in current but not in stored) * - Modified files (different hash) * - Removed files (in stored but not in current) * - Unchanged files (same hash) * * @param stored - Previously stored fingerprints * @param currentFiles - List of relative paths for current files * @param projectPath - Absolute path to project root (for file access) * @returns Delta result with categorized files * * @example * ```typescript * const stored = await loadFingerprints(indexPath); * const currentFiles = ['src/index.ts', 'src/utils.ts']; * const delta = await calculateDelta(stored, currentFiles, projectPath); * console.log(`Added: ${delta.added.length}, Modified: ${delta.modified.length}`); * ``` */ export declare function calculateDelta(stored: Fingerprints, currentFiles: string[], projectPath: string): Promise; /** * Fingerprints Manager class for managing file fingerprints * * Provides: * - Loading and caching fingerprints * - Saving fingerprints with atomic writes * - Single file operations (get, set, delete) * - Batch delta calculation and updates * * @example * ```typescript * const manager = new FingerprintsManager('/path/to/index', '/path/to/project'); * await manager.load(); * * // Check for changes * const delta = await manager.calculateDelta(['src/index.ts', 'src/utils.ts']); * console.log(`Files to reindex: ${delta.added.length + delta.modified.length}`); * * // Update fingerprints after indexing * const newHashes = new Map([['src/index.ts', 'abc123...']]); * manager.updateFromDelta(delta, newHashes); * await manager.save(); * ``` */ export declare class FingerprintsManager { private readonly indexPath; private readonly projectPath; private cachedFingerprints; private lastLoadedAt; private isDirty; /** * Create a new FingerprintsManager instance * * @param indexPath - Absolute path to the index directory * @param projectPath - Absolute path to the project root */ constructor(indexPath: string, projectPath: string); /** * Load fingerprints from disk * * Always reads from disk, updating the cache. */ load(): Promise; /** * Save fingerprints to disk * * Uses atomic write to prevent corruption. * Only saves if there are cached fingerprints. */ save(): Promise; /** * Get the hash for a file path * * @param relativePath - Forward-slash separated relative path * @returns Hash string or undefined if not found */ get(relativePath: string): string | undefined; /** * Set the hash for a file path * * @param relativePath - Forward-slash separated relative path * @param hash - SHA256 hash of file content */ set(relativePath: string, hash: string): void; /** * Delete a file from fingerprints * * @param relativePath - Forward-slash separated relative path * @returns true if the file was deleted, false if it didn't exist */ delete(relativePath: string): boolean; /** * Check if a file exists in fingerprints * * @param relativePath - Forward-slash separated relative path * @returns true if the file exists in fingerprints */ has(relativePath: string): boolean; /** * Calculate delta between stored and current files * * Compares stored fingerprints with current file list to detect changes. * * @param currentFiles - List of relative paths for current files * @returns Delta result with categorized files */ calculateDelta(currentFiles: string[]): Promise; /** * Update fingerprints after indexing based on delta * * - Removes deleted files from fingerprints * - Updates added/modified files with new hashes * * @param delta - Delta result from calculateDelta * @param newHashes - Map of relative paths to new hashes for added/modified files */ updateFromDelta(delta: DeltaResult, newHashes: Map): void; /** * Clear all fingerprints * * Useful when doing a full reindex. */ clear(): void; /** * Set all fingerprints from a map * * Replaces all existing fingerprints. * Useful for full indexing. * * @param fingerprints - New fingerprints map */ setAll(fingerprints: Fingerprints): void; /** * Get all fingerprints * * Returns a copy of the fingerprints map. * * @returns Copy of the fingerprints map */ getAll(): Fingerprints; /** * Get the number of tracked files * * @returns Number of files in fingerprints */ count(): number; /** * Check if fingerprints have been loaded */ isLoaded(): boolean; /** * Check if there are unsaved changes */ hasUnsavedChanges(): boolean; /** * Get the timestamp of the last load operation */ getLastLoadedAt(): number; /** * Get the path to the fingerprints file */ getFingerprintsPath(): string; /** * Get the index path this manager is associated with */ getIndexPath(): string; /** * Get the project path this manager is associated with */ getProjectPath(): string; /** * Ensure fingerprints are loaded, throw if not */ private ensureLoaded; } //# sourceMappingURL=fingerprints.d.ts.map