commit d090f2f7905320091c9a8e932663148e3cb19f78 Author: Zhongwei Li Date: Sat Nov 29 18:48:33 2025 +0800 Initial commit diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..0871cdf --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,11 @@ +{ + "name": "sys-maint", + "description": "System maintenance and cleanup utilities for Docker, disk space, and developer environments", + "version": "1.0.0", + "author": { + "name": "irfansofyana" + }, + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7b3f178 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# sys-maint + +System maintenance and cleanup utilities for Docker, disk space, and developer environments diff --git a/commands/disk-analyze.md b/commands/disk-analyze.md new file mode 100644 index 0000000..9e6d632 --- /dev/null +++ b/commands/disk-analyze.md @@ -0,0 +1,386 @@ +--- +description: Analyze disk usage, identify space hogs, and provide cleanup recommendations with optional execution (macOS only) +allowed-tools: Bash(df:*), Bash(du:*), Bash(find:*), Bash(ls:*) +--- + +# Disk Analysis and Cleanup Command + +**IMPORTANT**: This command is designed and tested for macOS only. It uses macOS-specific paths and utilities. + +Your task is to help the user analyze disk usage, identify large files and directories consuming space, provide categorized cleanup recommendations, and optionally execute approved cleanup operations. + +## Context: Current Disk Status + +First, check the current disk usage: + +!`df -h` + +This shows the overall disk space availability on all mounted filesystems. + +## Step 1: System Analysis + +Perform a comprehensive disk analysis: + +### 1.1 Overall Disk Usage + +Parse the `df -h` output and identify: +- The main disk (usually `/` or `/System/Volumes/Data` on macOS) +- Total capacity +- Used space +- Available space +- Percentage used + +Present this information clearly: + +``` +Disk Usage Summary +================== +Main Disk: [name] +Capacity: X.XX GB +Used: X.XX GB (XX%) +Available: X.XX GB +``` + +### 1.2 Find Largest Directories + +Run these commands to identify space hogs: + +1. **Top 10 largest directories in home folder**: + ```bash + du -h -d 1 ~ 2>/dev/null | sort -hr | head -10 + ``` + +2. **Large directories in common locations**: + ```bash + du -h -d 1 ~/Library 2>/dev/null | sort -hr | head -10 + du -h -d 1 ~/Downloads 2>/dev/null | sort -hr | head -5 + ``` + +Present the findings: + +``` +Largest Directories +=================== + +Home Directory (~): +1. [directory] - X.XX GB +2. [directory] - X.XX GB +... + +Library (~Library): +1. [directory] - X.XX GB +2. [directory] - X.XX GB +... +``` + +### 1.3 Identify Specific Cleanup Targets + +Check common space hogs: + +1. **Old Downloads** (files older than 30 days): + ```bash + find ~/Downloads -type f -mtime +30 -exec ls -lh {} \; 2>/dev/null | head -20 + ``` + Count and calculate total size + +2. **Application Caches**: + ```bash + du -sh ~/Library/Caches 2>/dev/null + ``` + +3. **System Logs**: + ```bash + du -sh ~/Library/Logs 2>/dev/null + ``` + +4. **Trash**: + ```bash + du -sh ~/.Trash 2>/dev/null + ``` + +5. **Temporary files**: + ```bash + du -sh /tmp 2>/dev/null + ``` + +## Step 2: Provide Cleanup Recommendations + +Based on the analysis, present categorized recommendations: + +``` +Cleanup Recommendations +======================= + +SAFE (Low Risk) +--------------- +These operations are generally safe and reversible: + +1. Empty Trash (~/.Trash) + Estimated space: X.XX GB + Risk: Low - items can be restored before emptying + +2. Old Downloads (files >30 days old) + Estimated space: X.XX GB + Risk: Low - review list before deletion + +3. Clear temporary files (/tmp) + Estimated space: X.XX MB + Risk: Low - system recreates as needed + + +MODERATE (Medium Risk) +---------------------- +These require some review before deletion: + +4. Application Caches (~/Library/Caches) + Estimated space: X.XX GB + Risk: Medium - apps will rebuild caches, may slow down temporarily + +5. System Logs (~/Library/Logs) + Estimated space: X.XX MB + Risk: Medium - useful for troubleshooting recent issues + + +CAREFUL (Higher Risk) +--------------------- +These require careful review and may affect functionality: + +6. Large files in specific directories + [List specific large files found] + Risk: Varies - requires manual review +``` + +## Step 3: Ask for User Confirmation + +Present cleanup options: + +``` +What would you like to do? + +1. Review and clean specific items + - I'll show you each category and you can approve individually + +2. Quick clean (Safe items only) + - Empty Trash + - Clear temporary files + - Estimated space freed: X.XX GB + +3. Generate detailed report only + - No cleanup, just save findings to a file + +4. Cancel + - Exit without making changes +``` + +**Ask the user**: "Which option would you like? (Enter 1, 2, 3, or 4)" + +Wait for the user's response. + +## Step 4: Cleanup Phase (if approved) + +### Option 1: Review and Clean Specific Items + +For each recommendation, ask the user: + +**For Trash:** +```bash +ls -lh ~/.Trash | head -10 +``` +Show first 10 items, then ask: "Empty trash (~/.Trash)? This will permanently delete X.XX GB. (y/n)" + +If yes: +```bash +rm -rf ~/.Trash/* +``` + +**For Old Downloads:** +```bash +find ~/Downloads -type f -mtime +30 -exec ls -lh {} \; +``` +Show the list and ask: "Delete these files from Downloads? (y/n)" + +If yes: +```bash +find ~/Downloads -type f -mtime +30 -delete +``` + +**For Application Caches:** +Show size and ask: "Clear application caches (~/Library/Caches)? Apps will rebuild as needed. (y/n)" + +If yes: +```bash +rm -rf ~/Library/Caches/* +``` + +**For System Logs:** +Ask: "Clear system logs (~/Library/Logs)? (y/n)" + +If yes: +```bash +rm -rf ~/Library/Logs/* +``` + +**For Temporary Files:** +Ask: "Clear temporary files (/tmp)? (y/n)" + +If yes: +```bash +sudo rm -rf /tmp/* +``` + +### Option 2: Quick Clean (Safe Items Only) + +First, show the user what will be cleaned: + +``` +Quick Clean Summary +=================== +The following items will be deleted: + +1. Trash (~/.Trash) + - Size: X.XX GB + +2. Temporary files (/tmp) + - Size: X.XX MB + +Total Space to be Freed: X.XX GB +``` + +**Ask for final confirmation**: "Proceed with quick clean? This will permanently delete the items listed above. (y/n)" + +Wait for user response. + +**If user confirms (y):** + +Execute these commands in sequence: + +1. **Empty Trash**: + ```bash + rm -rf ~/.Trash/* + ``` + Report: "✓ Emptied Trash" + +2. **Clear temporary files**: + ```bash + sudo rm -rf /tmp/* + ``` + Report: "✓ Cleared temporary files" + +Report total space freed. + +**If user declines (n):** + +Respond: "Quick clean cancelled. No changes were made." + +### Option 3: Generate Detailed Report + +Create a report file: + +```bash +cat > ~/disk-analysis-report.txt < General > Storage +- Consider cloud storage for large media files +- Regular maintenance prevents critical low-disk situations +- Check for large files: `find ~ -type f -size +1G 2>/dev/null` +``` diff --git a/commands/docker-cleanup.md b/commands/docker-cleanup.md new file mode 100644 index 0000000..663361f --- /dev/null +++ b/commands/docker-cleanup.md @@ -0,0 +1,203 @@ +--- +description: Analyze Docker resource usage and clean up containers, images, volumes, and build cache with preview and confirmation (macOS only) +allowed-tools: Bash(docker:*) +--- + +# Docker Cleanup Command + +**IMPORTANT**: This command is designed and tested for macOS only. It requires Docker to be installed and running. + +Your task is to help the user clean up Docker resources safely by analyzing current usage, showing a preview of what will be removed, getting explicit confirmation, and then executing the cleanup operations. + +## Context: Current Docker Status + +First, gather the current Docker resource usage by running: + +!`docker system df -v` + +This will show you disk usage for images, containers, volumes, and build cache. + +## Step 1: Analysis Phase + +Analyze the Docker system and present a clear summary to the user: + +1. **Parse the output** from `docker system df -v` to extract: + - Total space used by images + - Total space used by containers + - Total space used by volumes + - Total space used by build cache + - Amount of reclaimable space + +2. **Run additional analysis commands**: + - Count stopped containers: `docker ps -a -f status=exited -q | wc -l` + - Count dangling images: `docker images -f dangling=true -q | wc -l` + - List unused volumes: `docker volume ls -f dangling=true -q | wc -l` + +3. **Present the analysis** to the user in a clear, formatted table: + +``` +Docker Resource Analysis +======================== + +Resource Type | Total Size | Reclaimable | Count +--------------------|------------|-------------|------- +Images | X.XX GB | X.XX GB | X items +Containers | X.XX GB | X.XX GB | X stopped +Volumes | X.XX GB | X.XX GB | X unused +Build Cache | X.XX GB | X.XX GB | - + +Total Reclaimable Space: X.XX GB +``` + +## Step 2: Preview Phase + +Show the user exactly what will be removed: + +1. **List stopped containers** (if any): + - Run: `docker ps -a -f status=exited --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"` + - Show the first 10 (if more, indicate "... and X more") + +2. **List dangling images** (if any): + - Run: `docker images -f dangling=true --format "table {{.ID}}\t{{.Repository}}\t{{.Size}}"` + - Show the first 10 (if more, indicate "... and X more") + +3. **List unused volumes** (if any): + - Run: `docker volume ls -f dangling=true --format "table {{.Name}}\t{{.Driver}}"` + - Show the first 10 (if more, indicate "... and X more") + +4. **Show build cache details**: + - Run: `docker buildx du --verbose` (or indicate that build cache will be cleared) + +## Step 3: Confirmation + +Present cleanup options to the user: + +``` +What would you like to clean up? + +1. Clean All (Recommended) + - Remove all stopped containers + - Remove all dangling images + - Remove all unused volumes + - Clear build cache + - Estimated space freed: X.XX GB + +2. Selective Cleanup + - Choose specific resource types to clean + +3. Cancel + - Exit without making changes +``` + +**Ask the user explicitly**: "Which option would you like? (Enter 1, 2, or 3)" + +Wait for the user's response before proceeding. + +## Step 4: Cleanup Phase + +Based on the user's choice: + +### If user chose "Clean All" (Option 1): + +Execute these commands in sequence, showing progress for each: + +1. **Remove stopped containers**: + ```bash + docker container prune -f + ``` + Report: "✓ Removed stopped containers" + +2. **Remove dangling images**: + ```bash + docker image prune -f + ``` + Report: "✓ Removed dangling images" + +3. **Remove unused volumes**: + ```bash + docker volume prune -f + ``` + Report: "✓ Removed unused volumes" + +4. **Clear build cache**: + ```bash + docker builder prune -f + ``` + Report: "✓ Cleared build cache" + +### If user chose "Selective Cleanup" (Option 2): + +Ask the user which resource types to clean: +- "Clean stopped containers? (y/n)" +- "Clean dangling images? (y/n)" +- "Clean unused volumes? (y/n)" +- "Clear build cache? (y/n)" + +Then execute only the selected cleanup commands. + +### If user chose "Cancel" (Option 3): + +Respond with: "Docker cleanup cancelled. No changes were made." + +## Step 5: Report Results + +After cleanup completes: + +1. **Run final analysis**: + ```bash + docker system df + ``` + +2. **Calculate and show space freed**: + - Compare before/after disk usage + - Show total space reclaimed + +3. **Present final report**: + +``` +Docker Cleanup Complete! +======================== + +Space Reclaimed: X.XX GB + +Current Docker Disk Usage: +- Images: X.XX GB +- Containers: X.XX GB +- Volumes: X.XX GB +- Build Cache: X.XX GB + +Next Steps: +- Run this command periodically to maintain disk space +- Consider removing unused images: `docker image prune -a` (removes all unused images, not just dangling) +- Monitor with: `docker system df` +``` + +## Error Handling + +If any command fails: + +1. **Capture the error message** +2. **Continue with remaining cleanup operations** (don't stop the entire process) +3. **Report which operations failed** at the end +4. **Suggest recovery actions**: + - "Error removing containers: [error message]" + - "You may need to manually stop running containers first" + - "Try: `docker ps` to see running containers" + +If Docker is not installed or not running: +- "Docker does not appear to be installed or running on your system" +- "Please start Docker or install it to use this command" + +## Validation Criteria + +Success indicators: +- Commands execute without errors +- Disk space is reclaimed (shown in final report) +- User receives clear confirmation of what was cleaned +- No running containers or tagged images are affected + +Safety checks: +- Never remove running containers +- Never remove tagged/used images (only dangling ones in default mode) +- Always show preview before deletion +- Require explicit user confirmation diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..f61c279 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,49 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:irfansofyana/my-claude-code-marketplace:plugins/03-sys-maint", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "9ef41e1d1782c8311fa0ecaf4ee5b08fff3ecd00", + "treeHash": "9006e2be2a17664ede14321947335d2658e840199b0d2ee677958cb783e4d226", + "generatedAt": "2025-11-28T10:17:41.174531Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "sys-maint", + "description": "System maintenance and cleanup utilities for Docker, disk space, and developer environments", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "b1e492b370bbb1d9e707fe0449bb3ced0a316229f07f17110d35c513be1df808" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "4419a8ae1267dae9c898b3dd4452c12b89cec038369e25f9519f7dea0d7f7ab6" + }, + { + "path": "commands/disk-analyze.md", + "sha256": "d68bd98e6df95d1ce892c53f71c546db8f6e89e87374384e2f9c52a9e8a097a5" + }, + { + "path": "commands/docker-cleanup.md", + "sha256": "b4b22882381d54f545bc266801bbc5f2b00702564ccb3339c9b4814e4168ef98" + } + ], + "dirSha256": "9006e2be2a17664ede14321947335d2658e840199b0d2ee677958cb783e4d226" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file