// storage/hash-snapshot-store.ts — Persistence for spec hash snapshots
// Stores snapshots in data/projects/{hash}/spec-hashes/{specId}.json
// Append-only: old snapshots are archived, not deleted.
import { projectDataDir, readJson, writeJson } from './base-store.js';
import { withFileLock } from './file-mutex.js';
/**
 * Get the file path for a spec's hash snapshot.
 */
function snapshotPath(projectId, specId) {
    return `${projectDataDir(projectId)}/spec-hashes/${specId}.json`;
}
/**
 * Get the file path for a spec's reconcile log.
 */
function reconcileLogPath(projectId, specId) {
    return `${projectDataDir(projectId)}/spec-hashes/${specId}-reconcile-log.json`;
}
/**
 * Load a spec's hash snapshot. Returns null if not found.
 */
export async function getSnapshot(projectId, specId) {
    return readJson(snapshotPath(projectId, specId), null);
}
/**
 * Save a spec's hash snapshot.
 */
export async function saveSnapshot(projectId, specId, snapshot) {
    const path = snapshotPath(projectId, specId);
    await withFileLock(path, async () => {
        await writeJson(path, snapshot);
    });
}
/**
 * Load reconcile log entries for a spec.
 */
export async function getReconcileLog(projectId, specId) {
    return readJson(reconcileLogPath(projectId, specId), []);
}
/**
 * Append entries to the reconcile log for a spec.
 */
export async function appendReconcileLog(projectId, specId, entries) {
    const path = reconcileLogPath(projectId, specId);
    await withFileLock(path, async () => {
        const existing = await readJson(path, []);
        existing.push(...entries);
        await writeJson(path, existing);
    });
}
//# sourceMappingURL=hash-snapshot-store.js.map