Initial commit
This commit is contained in:
11
.claude-plugin/plugin.json
Normal file
11
.claude-plugin/plugin.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# sys-maint
|
||||
|
||||
System maintenance and cleanup utilities for Docker, disk space, and developer environments
|
||||
386
commands/disk-analyze.md
Normal file
386
commands/disk-analyze.md
Normal file
@@ -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 <<EOF
|
||||
Disk Analysis Report
|
||||
Generated: $(date)
|
||||
|
||||
[Include all analysis findings]
|
||||
EOF
|
||||
```
|
||||
|
||||
Tell user: "Report saved to ~/disk-analysis-report.txt"
|
||||
|
||||
### Option 4: Cancel
|
||||
|
||||
Respond: "Disk analysis complete. No changes were made."
|
||||
|
||||
## Step 5: Final Report
|
||||
|
||||
After any cleanup operations:
|
||||
|
||||
1. **Run final disk check**:
|
||||
```bash
|
||||
df -h
|
||||
```
|
||||
|
||||
2. **Calculate space freed**:
|
||||
- Compare before/after disk usage
|
||||
- Show specific space reclaimed
|
||||
|
||||
3. **Present final report**:
|
||||
|
||||
```
|
||||
Disk Cleanup Complete!
|
||||
======================
|
||||
|
||||
Space Reclaimed: X.XX GB
|
||||
|
||||
Current Disk Status:
|
||||
- Total: X.XX GB
|
||||
- Used: X.XX GB (XX%)
|
||||
- Available: X.XX GB
|
||||
|
||||
Items Cleaned:
|
||||
✓ [Item 1] - X.XX GB freed
|
||||
✓ [Item 2] - X.XX GB freed
|
||||
...
|
||||
|
||||
Next Steps:
|
||||
- Run this command monthly to maintain disk space
|
||||
- Consider removing large unused applications
|
||||
- Review Downloads folder regularly
|
||||
- For more aggressive cleanup, consider:
|
||||
- `docker system prune -a` (if using Docker)
|
||||
- Clearing Xcode derived data (if using Xcode)
|
||||
- Clearing Homebrew cache: `brew cleanup`
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
If commands fail:
|
||||
|
||||
1. **Permission errors**:
|
||||
- "Permission denied error occurred"
|
||||
- "Some operations may require administrator access"
|
||||
- "Try running specific commands with 'sudo' if needed"
|
||||
|
||||
2. **File not found**:
|
||||
- Skip that item gracefully
|
||||
- Continue with other cleanup operations
|
||||
- Note in final report which items were skipped
|
||||
|
||||
3. **Disk full**:
|
||||
- "Disk is critically low on space"
|
||||
- "Recommend starting with Trash and Downloads cleanup"
|
||||
- "Consider moving large files to external storage"
|
||||
|
||||
If critical commands fail:
|
||||
- Show the error message
|
||||
- Suggest manual alternatives
|
||||
- Provide command examples user can run directly
|
||||
|
||||
## Validation Criteria
|
||||
|
||||
Success indicators:
|
||||
- Disk usage analysis completes successfully
|
||||
- Recommendations are clear and categorized by risk
|
||||
- Space savings estimates are accurate
|
||||
- User receives explicit confirmation prompts
|
||||
- Final report shows actual space freed
|
||||
|
||||
Safety checks:
|
||||
- Never delete files without explicit confirmation
|
||||
- Show preview of files before deletion
|
||||
- Categorize operations by risk level
|
||||
- Provide undo suggestions where possible
|
||||
- Only delete from known safe locations (Trash, tmp, caches)
|
||||
|
||||
## Additional Tips for User
|
||||
|
||||
Include in final output:
|
||||
|
||||
```
|
||||
Pro Tips for Disk Management:
|
||||
- Use `du -sh * | sort -hr | head -20` to find large items in any directory
|
||||
- macOS Storage Management: System Settings > 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`
|
||||
```
|
||||
203
commands/docker-cleanup.md
Normal file
203
commands/docker-cleanup.md
Normal file
@@ -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
|
||||
49
plugin.lock.json
Normal file
49
plugin.lock.json
Normal file
@@ -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": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user