/** * Storage Module v3 * * Handles file snapshot storage using git blobs and working log management. * Uses git's native object store for snapshots (deduplication, compression, gc-managed). * * Storage locations: * - .git/agentblame/agentblame.db - SQLite database * - .git/agentblame/working/{base_sha}/snapshots.jsonl - Snapshot chain * - .git/agentblame/working/{base_sha}/INITIAL - Uncommitted attributions * - .git/objects/ - Git blob storage (via git hash-object) */ import type { SnapshotEntry, InitialFile, Snapshot } from "./types"; /** * Store content as a git blob and return its SHA * Uses git hash-object -w --stdin for native storage */ export declare function storeSnapshot(repoRoot: string, content: string): Promise; /** * Load content from a git blob by SHA * Uses git cat-file blob */ export declare function loadSnapshot(repoRoot: string, blobSha: string): Promise; /** * Batch load multiple blobs in a single git process * Uses git cat-file --batch for efficiency * Returns a Map of blobSha -> content */ export declare function loadSnapshotsBatch(repoRoot: string, blobShas: string[]): Promise>; /** * Check if a blob exists in the git object store */ export declare function blobExists(repoRoot: string, blobSha: string): Promise; /** * Get the agentblame directory inside .git */ export declare function getAgentBlameGitDir(repoRoot: string): string; /** * Get the working directory for a specific base SHA */ export declare function getWorkingDir(repoRoot: string, baseSha: string): string; /** * Get the snapshots.jsonl path for a base SHA */ export declare function getSnapshotsPath(repoRoot: string, baseSha: string): string; /** * Get the INITIAL file path for a base SHA */ export declare function getInitialPath(repoRoot: string, baseSha: string): string; /** * Get the database path */ export declare function getDatabasePath(repoRoot: string): string; /** * Ensure the agentblame directory structure exists */ export declare function ensureAgentBlameDirs(repoRoot: string): void; /** * Ensure working directory for a base SHA exists */ export declare function ensureWorkingDir(repoRoot: string, baseSha: string): void; /** * Append an entry to the working log */ export declare function appendToWorkingLog(repoRoot: string, baseSha: string, entry: SnapshotEntry): void; /** * Read all entries from the working log */ export declare function readWorkingLog(repoRoot: string, baseSha: string): SnapshotEntry[]; /** * Read entries from the working log filtered by file path * More efficient than readWorkingLog + filter for single file queries */ export declare function readWorkingLogForFile(repoRoot: string, baseSha: string, filePath: string): SnapshotEntry[]; /** * Get the last snapshot entry for a file (for dedup checking) */ export declare function getLastSnapshotForFile(repoRoot: string, baseSha: string, filePath: string): SnapshotEntry | null; /** * Get the snapshot chain for a specific file * Returns snapshots in chronological order (oldest first) * Prepends the original git content (baseSha) as the first entry with sessionId: null */ export declare function getSnapshotChainForFile(repoRoot: string, baseSha: string, filePath: string): Promise; /** * Get all files that have been modified since base SHA */ export declare function getModifiedFiles(repoRoot: string, baseSha: string): string[]; /** * Clear the working log for a base SHA */ export declare function clearWorkingLog(repoRoot: string, baseSha: string): void; /** * Read the INITIAL file */ export declare function readInitialFile(repoRoot: string, baseSha: string): InitialFile | null; /** * Write the INITIAL file */ export declare function writeInitialFile(repoRoot: string, baseSha: string, data: InitialFile): void; /** * Update INITIAL file with new attribution */ export declare function updateInitialFile(repoRoot: string, baseSha: string, filePath: string, blobSha: string, sessionId: string, lines: [number, number]): void; /** * Clear the INITIAL file */ export declare function clearInitialFile(repoRoot: string, baseSha: string): void; /** * Clean up working directory for a base SHA (after commit) */ export declare function cleanupWorkingDir(repoRoot: string, baseSha: string): void; /** * Get all base SHAs that have working directories */ export declare function getActiveBaseShas(repoRoot: string): string[]; /** * Smart cleanup of old working directories. * Only cleans up if: * 1. The commit is an ancestor of HEAD (we've moved past it) * 2. The commit has git notes (deltas were processed) * * This preserves deltas for: * - Current HEAD (uncommitted changes) * - Reset/recommit scenarios * - Stashed changes */ export declare function cleanupProcessedWorkingDirs(repoRoot: string, currentBaseSha: string): Promise; /** * Clean up stale working directories (for commits that no longer exist) */ export declare function cleanupStaleWorkingDirs(repoRoot: string): Promise<{ cleaned: string[]; kept: string[]; }>; /** * Get the current HEAD commit SHA */ export declare function getGitHead(repoRoot: string): Promise; /** * Get the parent commit SHA */ export declare function getParentCommit(repoRoot: string, commitSha: string): Promise; /** * Get file content at a specific commit */ export declare function getFileAtCommit(repoRoot: string, commitSha: string, filePath: string): Promise; /** * Get the root commit (first commit in repository) */ export declare function getRootCommit(repoRoot: string): Promise; /** * Read current file content from working directory */ export declare function readFileContent(filePath: string): string | null; /** * Check if file exists */ export declare function fileExists(filePath: string): boolean; /** * Store file content as snapshot and update working log */ export declare function captureFileSnapshot(repoRoot: string, baseSha: string, filePath: string, content: string, sessionId: string | null, type: "ai_edit" | "human_edit"): Promise;