/** * Codebase map cache read/write utilities * * Handles reading and writing the .scampi/cache/map.json file which stores * metadata about analyzed files including their hashes, summaries, exports, * and dependencies for incremental codebase mapping. */ /** * Current schema version for the cache file * Increment when making breaking changes to the schema */ export declare const CACHE_VERSION = 1; /** * Metadata for a single cached file entry */ export interface FileCacheEntry { /** * Last modification time as Unix timestamp (seconds) * Used for quick change detection before computing hash */ modified: number; /** * SHA256 hash of the file content with prefix * Format: "sha256:hexstring" */ hash: string; /** * LLM-generated summary of the file's purpose and contents * May be empty if not yet summarized */ summary: string; /** * List of exported symbols (functions, classes, variables, types) * Empty array if no exports or not yet analyzed */ exports: string[]; /** * List of relative paths to files this file depends on * Dependencies are within the same project */ dependencies: string[]; } /** * Complete codebase map cache structure */ export interface CodebaseMap { /** * Schema version for forward compatibility */ version: number; /** * Absolute path to the project root directory */ root: string; /** * ISO 8601 timestamp when the cache was last generated */ generated_at: string; /** * Map of relative file paths to their cache entries * Keys are relative paths from project root (e.g., "src/auth/login.ts") */ files: Record; /** * HMAC-SHA256 signature for integrity verification * Protects against tampering with cache data */ signature?: string; } /** * Get the absolute path to the cache directory for a project * * @param projectDir - Absolute path to the project root directory * @returns Absolute path to .scampi/cache/ directory */ export declare function getCacheDir(projectDir: string): string; /** * Get the absolute path to the cache file for a project * * @param projectDir - Absolute path to the project root directory * @returns Absolute path to .scampi/cache/map.json */ export declare function getCachePath(projectDir: string): string; /** * Load the codebase map cache from disk * * @param projectDir - Absolute path to the project root directory * @returns The loaded CodebaseMap or null if: * - Cache file doesn't exist * - Cache file is corrupt/invalid JSON * - Cache schema version is incompatible * * @example * ```typescript * const cache = loadCache('/path/to/project'); * if (cache) { * console.log(`Cache has ${Object.keys(cache.files).length} files`); * } else { * console.log('No valid cache found'); * } * ``` */ export declare function loadCache(projectDir: string): CodebaseMap | null; /** * Save the codebase map cache to disk atomically * * Uses atomic write pattern: writes to a temporary file first, then renames. * This prevents corruption if the process is interrupted during write. * * @param projectDir - Absolute path to the project root directory * @param cache - The CodebaseMap to save * @throws Error if the cache directory cannot be created or write fails * * @example * ```typescript * const cache = createEmptyCache('/path/to/project'); * cache.files['src/index.ts'] = { * modified: Date.now() / 1000, * hash: 'sha256:abc123...', * summary: 'Main entry point', * exports: ['main'], * dependencies: ['./utils.ts'] * }; * saveCache('/path/to/project', cache); * ``` */ export declare function saveCache(projectDir: string, cache: CodebaseMap): void; /** * Create an empty codebase map cache for a project * * @param projectDir - Absolute path to the project root directory * @returns A new CodebaseMap with no file entries * * @example * ```typescript * const cache = createEmptyCache('/path/to/project'); * console.log(cache.version); // 1 * console.log(cache.root); // '/path/to/project' * console.log(Object.keys(cache.files).length); // 0 * ``` */ export declare function createEmptyCache(projectDir: string): CodebaseMap; /** * Create a file cache entry with default values * * Convenience function for creating new file entries. * The summary will be empty and should be populated by the LLM. * * @param modified - Last modification time as Unix timestamp (seconds) * @param hash - SHA256 hash with "sha256:" prefix * @returns A new FileCacheEntry with empty summary, exports, and dependencies * * @example * ```typescript * const entry = createFileCacheEntry(1706400000, 'sha256:abc123...'); * entry.summary = 'Handles user authentication'; * entry.exports = ['login', 'logout']; * entry.dependencies = ['./db.ts']; * ``` */ export declare function createFileCacheEntry(modified: number, hash: string): FileCacheEntry; //# sourceMappingURL=map.d.ts.map