const REVISIONS_KEPT_PER_ENTITY = 20;
export async function phasePruneRevisions(ctx) {
    const start = Date.now();
    const { accountId, session } = ctx;
    const result = await session.run(`MATCH (e)-[:HAS_REVISION]->(r:CompiledTruthRevision)
     WHERE e.accountId = $accountId AND r.accountId = $accountId
     WITH e, r ORDER BY r.writtenAt DESC
     WITH e, collect(r) AS revs
     WHERE size(revs) > $keep
     UNWIND revs[$keep..] AS old
     DETACH DELETE old
     RETURN count(old) AS pruned`, { accountId, keep: REVISIONS_KEPT_PER_ENTITY });
    const pruned = Number(result.records[0]?.get("pruned") ?? 0);
    const durationSec = Math.round((Date.now() - start) / 1000);
    process.stderr.write(`[dream-cycle:phase-5] durationSec=${durationSec} proposed=${pruned} applied=${pruned} deferred=0\n`);
    return {
        phase: 5,
        name: "prune-revisions",
        durationSec,
        proposed: pruned,
        applied: pruned,
        deferred: 0,
        extra: { keptPerEntity: REVISIONS_KEPT_PER_ENTITY },
    };
}
export { REVISIONS_KEPT_PER_ENTITY };
//# sourceMappingURL=phase-prune-revisions.js.map