superdesign_cleanup
Remove outdated design files by age and quantity limits to maintain organized workspaces and optimize storage space.
Instructions
Clean up old design files based on age and count limits
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace_path | No | Workspace path (defaults to current directory) | |
| max_age_days | No | Delete designs older than X days (default: 30) | |
| max_count | No | Keep only the latest X designs (default: 50) | |
| dry_run | No | Show what would be deleted without actually deleting |
Implementation Reference
- dist/index.js:2251-2297 (handler)MCP tool handler for 'superdesign_cleanup' that parses input arguments using CleanupSchema, calls performCleanup, formats and returns the results including deleted/kept files and settings.case "superdesign_cleanup": { const { workspace_path, max_age_days, max_count, dry_run } = CleanupSchema.parse(args); try { const superdesignDir = getSuperdeignDirectory(workspace_path); const result = performCleanup(superdesignDir, max_age_days, max_count, dry_run || false); let response = `CLEANUP RESULTS:\n\n`; if (dry_run) { response += `DRY RUN - No files were actually deleted\n\n`; } if (result.deleted.length > 0) { response += `Files ${dry_run ? 'to be deleted' : 'deleted'} (${result.deleted.length}):\n`; result.deleted.forEach(file => { response += ` - ${file}\n`; }); response += `\n`; } if (result.kept.length > 0) { response += `Files kept (${result.kept.length}):\n`; result.kept.forEach(file => { response += ` - ${file}\n`; }); response += `\n`; } if (result.errors.length > 0) { response += `Errors (${result.errors.length}):\n`; result.errors.forEach(error => { response += ` - ${error}\n`; }); response += `\n`; } if (result.deleted.length === 0 && result.errors.length === 0) { response += `No files needed cleanup.\n`; } const settings = getCleanupSettings(superdesignDir); response += `\nCleanup settings:\n`; response += ` - Max age: ${max_age_days || settings.maxAgeDays} days\n`; response += ` - Max count: ${max_count || settings.maxCount} files\n`; response += ` - Enabled: ${settings.enabled}\n`; return { content: [{ type: "text", text: response }], }; } catch (error) { return { content: [{ type: "text", text: `Error during cleanup: ${error.message}` }], }; }
- dist/index.js:181-224 (helper)Core helper function that performs the cleanup logic: sorts designs by age, determines which to delete based on max_count and max_age_days, deletes files and updates metadata (or simulates in dry_run mode).function performCleanup(superdesignDir, maxAgeDays, maxCount, dryRun = false) { const settings = getCleanupSettings(superdesignDir); const actualMaxAge = maxAgeDays ?? settings.maxAgeDays; const actualMaxCount = maxCount ?? settings.maxCount; const metadata = getDesignMetadata(superdesignDir); const now = new Date(); const cutoffDate = new Date(now.getTime() - (actualMaxAge * 24 * 60 * 60 * 1000)); // Sort by creation date (newest first) const sortedMetadata = metadata.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()); const deleted = []; const kept = []; const errors = []; for (let i = 0; i < sortedMetadata.length; i++) { const design = sortedMetadata[i]; const createdAt = new Date(design.createdAt); const shouldDelete = i >= actualMaxCount || createdAt < cutoffDate; if (shouldDelete) { if (!dryRun) { try { const designIterationsDir = path.join(superdesignDir, 'design_iterations'); const filePath = path.join(designIterationsDir, design.fileName); if (existsSync(filePath)) { unlinkSync(filePath); // Remove from metadata const allMetadata = loadMetadata(superdesignDir); const filteredMetadata = allMetadata.filter(m => m.fileName !== design.fileName); saveMetadata(superdesignDir, filteredMetadata); } deleted.push(design.fileName); } catch (error) { errors.push(`Failed to delete ${design.fileName}: ${error.message}`); } } else { deleted.push(design.fileName); } } else { kept.push(design.fileName); } } return { deleted, kept, errors }; }
- dist/index.js:40-45 (schema)Zod schema defining the input parameters for the superdesign_cleanup tool.const CleanupSchema = z.object({ workspace_path: z.string().optional().describe("Workspace path (defaults to current directory)"), max_age_days: z.number().optional().describe("Delete designs older than X days (default: 30)"), max_count: z.number().optional().describe("Keep only the latest X designs (default: 50)"), dry_run: z.boolean().optional().describe("Show what would be deleted without actually deleting") });
- dist/index.js:1909-1921 (registration)Registration of the superdesign_cleanup tool in the listTools response, including name, description, and inputSchema.{ name: "superdesign_cleanup", description: "Clean up old design files based on age and count limits", inputSchema: { type: "object", properties: { workspace_path: { type: "string", description: "Workspace path (defaults to current directory)" }, max_age_days: { type: "number", description: "Delete designs older than X days (default: 30)" }, max_count: { type: "number", description: "Keep only the latest X designs (default: 50)" }, dry_run: { type: "boolean", description: "Show what would be deleted without actually deleting" } }, }, },
- dist/index.js:150-169 (helper)Helper function to load or create cleanup settings from JSON file, providing defaults for maxAgeDays and maxCount.function getCleanupSettings(superdesignDir) { const settingsPath = path.join(superdesignDir, 'cleanup-settings.json'); const defaultSettings = { maxAgeDays: 30, maxCount: 50, enabled: true }; if (!existsSync(settingsPath)) { writeFileSync(settingsPath, JSON.stringify(defaultSettings, null, 2), 'utf8'); return defaultSettings; } try { const data = readFileSync(settingsPath, 'utf8'); return { ...defaultSettings, ...JSON.parse(data) }; } catch (error) { console.error('Error loading cleanup settings:', error); return defaultSettings; } }