Disk Cleaner - AI-Assisted Disk Space Management
You have access to diskclean.sh, a disk scanning and cleaning tool. Install it by copying diskclean.sh to a location on your PATH, or run it directly from this skill's directory.
Setup
CODEBLOCK0
Commands
CODEBLOCK1
How to Use This Skill
When the user asks to scan or clean disk space:
- 1. Run a scan first: Always start with INLINECODE2
- Summarize findings conversationally: Group items by category, show top offenders by size, report total reclaimable space
- Explain the tiers clearly:
-
Safe tier (auto-deletable): Items matching a strict whitelist AND older than the age gate (7-14 days). These are regenerable artifacts like
node_modules,
__pycache__, build caches, package manager caches.
-
Suggest tier (needs approval): Everything else:Docker, downloads, venvs, trash. Present these as recommendations and ask the user what they want to do.
- 4. For safe-tier cleanup: Run
diskclean.sh clean --dry first to show what would be deleted, then diskclean.sh clean --confirm only after user approves - For suggest-tier items: Present them individually or grouped by category. If the user approves specific items, delete them manually with
rm -rf (after confirming the path is under $HOME)
Presentation Format
When presenting scan results, use this structure:
CODEBLOCK2
Safety Rules
- - Never delete anything outside $HOME
- Never delete .git directories
- Never delete source code, documents, photos, or config files
- Never run
clean --confirm without showing the user clean --dry output first - Never delete suggest-tier items without explicit user approval per item or category
- Always verify a path exists before attempting deletion
How It Works
Tiered Safety Model
Safe tier = whitelisted category + age gate met. Auto-deletable with --confirm.
Suggest tier = everything else. Requires explicit user approval.
Categories Scanned
| Category | What | Safe Tier | Age Gate |
|---|
| nodemodules | Node.js dependencies (with package.json sibling) | Yes | 7 days |
| pythoncache |
__pycache__,
.pytest_cache | Yes | 7 days |
| python_venv |
.venv/,
venv/ | No |:|
| build_output |
build/,
dist/,
.next/,
target/ | Yes | 7 days |
| go_cache | Go module + build cache | Yes | 14 days |
| homebrew_cache | Homebrew download cache | Yes | 14 days |
| npm
yarnpnpm_cache | npm/yarn/pnpm caches | Yes | 14 days |
| pip_cache | pip download cache | Yes | 14 days |
| xcode_derived | Xcode DerivedData | Yes | 7 days |
| docker | Docker images, volumes, build cache | No |:|
| large_download | Files >100MB in Downloads | No |:|
| installer_archive | .dmg/.pkg/.zip/.iso in Downloads | No |:|
| logs | macOS logs (>50MB) | Yes | 30 days |
| crash_reports | Diagnostic reports (>10MB) | Yes | 30 days |
| ds
store | .DSStore files | Yes | 0 days |
| trash | ~/.Trash contents | No |:|
Guardrails
- - Only scans under
$HOME (plus /tmp user files) - INLINECODE21 only deleted if a
package.json exists alongside (proof it's regenerable) - Dry-run is the default:must pass
--confirm to actually delete - Every deletion is logged to INLINECODE24
- All scan reports stored in INLINECODE25
Data Storage
- - Scan reports: INLINECODE26
- Latest scan: INLINECODE27
- Deletion log: INLINECODE28
磁盘清理工具 - AI辅助磁盘空间管理
您可以使用diskclean.sh,这是一个磁盘扫描和清理工具。将其安装到PATH路径中,或直接从本技能目录运行。
安装
bash
赋予执行权限(如未设置)
chmod +x diskclean.sh
可选:创建符号链接到PATH
ln -sf $(pwd)/diskclean.sh /usr/local/bin/diskclean
命令
bash
完整扫描:返回包含所有可回收项目的JSON数据
./diskclean.sh scan
预览安全级别的自动删除(试运行,默认模式)
./diskclean.sh clean --dry
执行安全级别的删除
./diskclean.sh clean --confirm
显示上次扫描结果
./diskclean.sh report
显示历史扫描记录
./diskclean.sh history
如何使用本技能
当用户要求扫描或清理磁盘空间时:
- 1. 首先运行扫描:始终以diskclean.sh scan开始
- 以对话方式总结发现:按类别分组项目,按大小显示主要占用者,报告总可回收空间
- 清晰解释安全级别:
-
安全级别(可自动删除):符合严格白名单且超过时间门槛(7-14天)的项目。这些是可重新生成的工件,如node_modules、
pycache、构建缓存、包管理器缓存。
-
建议级别(需批准):其他所有项目:Docker、下载文件、虚拟环境、废纸篓。将这些作为建议呈现,并询问用户如何处理。
- 4. 对于安全级别清理:先运行diskclean.sh clean --dry显示将要删除的内容,仅在用户批准后运行diskclean.sh clean --confirm
- 对于建议级别项目:单独或按类别分组呈现。如果用户批准特定项目,使用rm -rf手动删除(确认路径在$HOME下后)
呈现格式
呈现扫描结果时,使用以下结构:
磁盘扫描结果
总计可回收:X.X GB
- - 安全级别(可自动清理):X.X GB
- 需要您审核:X.X GB
可安全自动清理
需要您审核
安全规则
- - 绝不删除$HOME之外的任何内容
- 绝不删除.git目录
- 绝不删除源代码、文档、照片或配置文件
- 未向用户展示clean --dry输出前,绝不运行clean --confirm
- 未经用户按项目或类别明确批准,绝不删除建议级别的项目
- 尝试删除前始终验证路径是否存在
工作原理
分级安全模型
安全级别 = 白名单类别 + 满足时间门槛。可通过--confirm自动删除。
建议级别 = 其他所有内容。需要用户明确批准。
扫描类别
| 类别 | 内容 | 安全级别 | 时间门槛 |
|---|
| nodemodules | Node.js依赖(同级有package.json) | 是 | 7天 |
| pythoncache |
pycache、.pytest_cache | 是 | 7天 |
| python_venv | .venv/、venv/ | 否 |:|
| build_output | build/、dist/、.next/、target/ | 是 | 7天 |
| go_cache | Go模块+构建缓存 | 是 | 14天 |
| homebrew_cache | Homebrew下载缓存 | 是 | 14天 |
| npm
yarnpnpm_cache | npm/yarn/pnpm缓存 | 是 | 14天 |
| pip_cache | pip下载缓存 | 是 | 14天 |
| xcode_derived | Xcode DerivedData | 是 | 7天 |
| docker | Docker镜像、卷、构建缓存 | 否 |:|
| large_download | 下载文件夹中>100MB的文件 | 否 |:|
| installer_archive | 下载文件夹中的.dmg/.pkg/.zip/.iso | 否 |:|
| logs | macOS日志(>50MB) | 是 | 30天 |
| crash_reports | 诊断报告(>10MB) | 是 | 30天 |
| ds
store | .DSStore文件 | 是 | 0天 |
| trash | ~/.Trash内容 | 否 |:|
安全护栏
- - 仅扫描$HOME下(加上/tmp用户文件)
- 仅当node_modules同级存在package.json时才删除(证明可重新生成)
- 试运行是默认模式:必须传递--confirm才能实际删除
- 每次删除记录到~/.openclaw/diskclean/deletion-log.jsonl
- 所有扫描报告存储在~/.openclaw/diskclean/scans/
数据存储
- - 扫描报告:~/.openclaw/diskclean/scans/scan-YYYYMMDD-HHMMSS.json
- 最新扫描:~/.openclaw/diskclean/latest-scan.json
- 删除日志:~/.openclaw/diskclean/deletion-log.jsonl