From b26e9e8cbbd9a82d6835dc4438d4182c30bfa83d Mon Sep 17 00:00:00 2001 From: Vishwaspatel2401 Date: Tue, 5 May 2026 00:52:36 -0700 Subject: [PATCH] fix: prune old manifest backups after discover runs Keep only the 5 most recent manifest.backup-*.json files after each discover run to prevent unbounded disk growth on long-running systems. Closes #4 Co-Authored-By: Claude --- src/commands/discover.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/commands/discover.js b/src/commands/discover.js index f752bde..aebe7b8 100644 --- a/src/commands/discover.js +++ b/src/commands/discover.js @@ -197,6 +197,19 @@ async function discover(options = {}) { console.log(format.warn(' Could not write backup — proceeding anyway.')); } + // Prune old backups — keep only the 5 most recent + try { + const backups = fs.readdirSync(skitHome) + .filter(f => f.startsWith('manifest.backup-') && f.endsWith('.json')) + .sort(); + const toDelete = backups.slice(0, -5); + for (const f of toDelete) { + fs.unlinkSync(path.join(skitHome, f)); + } + } catch { + // non-critical — ignore cleanup errors + } + // Register selected skills (compatible with install schema) const skills = manifest.skills || {}; for (const entry of selected) {