From dc909f4bc5fecfe62e50b8ae2287a745aa61973a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=80=D1=83=D0=B1=D0=B8=D0=BD=20=D0=A4=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BF=D0=BF?= <289370046+zarubinphil@users.noreply.github.com> Date: Thu, 18 Jun 2026 16:18:52 +0300 Subject: [PATCH] feat(graph): U5 prune graphify backups (keep N, default 3) Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/mnemazine-refresh-graphify.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/mnemazine-refresh-graphify.mjs b/scripts/mnemazine-refresh-graphify.mjs index d1e9deb..0e232a4 100644 --- a/scripts/mnemazine-refresh-graphify.mjs +++ b/scripts/mnemazine-refresh-graphify.mjs @@ -182,6 +182,22 @@ async function restoreBackup(backupDir) { await copyDir(backupDir, GRAPHIFY_OUT) } +// Keep only the newest GRAPHIFY_BACKUPS_KEEP graphify-out-backup-* dirs. +// Names are ISO timestamps, so lexical sort == chronological. Without this the +// backups accumulate forever inside the vault (10 dirs x ~60MB observed). +// ponytail: keep `keep` to allow restore/rollback; tune via env, never 0. +const GRAPHIFY_BACKUPS_KEEP = Math.max(1, Number(process.env.MNEMAZINE_GRAPHIFY_BACKUPS_KEEP || '3')) +async function pruneBackups(keep = GRAPHIFY_BACKUPS_KEEP) { + const entries = await fs.readdir(VAULT, { withFileTypes: true }).catch(() => []) + const backups = entries + .filter(entry => entry.isDirectory() && entry.name.startsWith('graphify-out-backup-')) + .map(entry => entry.name) + .sort() + for (const name of backups.slice(0, Math.max(0, backups.length - keep))) { + await removeIfExists(path.join(VAULT, name)) + } +} + async function writeNeedsUpdate() { await ensureGraphifyOut() await fs.writeFile(NEEDS_UPDATE_PATH, '1', 'utf8') @@ -426,6 +442,7 @@ async function mergeSemanticGraph(semanticGraphPath) { async function semanticRefresh({ baseline }) { const backupDir = path.join(VAULT, `graphify-out-backup-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)}`) await copyDir(GRAPHIFY_OUT, backupDir) + await pruneBackups() const selected = await pickSemanticModel() if (!selected.ok) {