feat(graph): U5 prune graphify backups (keep N, default 3)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Зарубин Филипп
2026-06-18 16:18:52 +03:00
co-authored by Claude Opus 4.8
parent b61dd0bb4a
commit dc909f4bc5
+17
View File
@@ -182,6 +182,22 @@ async function restoreBackup(backupDir) {
await copyDir(backupDir, GRAPHIFY_OUT) 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() { async function writeNeedsUpdate() {
await ensureGraphifyOut() await ensureGraphifyOut()
await fs.writeFile(NEEDS_UPDATE_PATH, '1', 'utf8') await fs.writeFile(NEEDS_UPDATE_PATH, '1', 'utf8')
@@ -426,6 +442,7 @@ async function mergeSemanticGraph(semanticGraphPath) {
async function semanticRefresh({ baseline }) { async function semanticRefresh({ baseline }) {
const backupDir = path.join(VAULT, `graphify-out-backup-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)}`) const backupDir = path.join(VAULT, `graphify-out-backup-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)}`)
await copyDir(GRAPHIFY_OUT, backupDir) await copyDir(GRAPHIFY_OUT, backupDir)
await pruneBackups()
const selected = await pickSemanticModel() const selected = await pickSemanticModel()
if (!selected.ok) { if (!selected.ok) {