storage-analyzer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStorage Analyzer
Storage Analyzer
对 macOS 做一次只读存储分析,产出交互式 HTML 报告。流程:扫描 → 分析分级 → 生成网页 → 打开。
Perform a read-only storage analysis on macOS and generate an interactive HTML report. Process: Scan → Analyze and categorize → Generate webpage → Open.
铁律
Iron Rules
- 全程只读。 只能跑扫描/统计/列目录/读元信息(df、du、diskutil、stat、ls)。绝对禁止 rm、mv、rmdir、清空回收站、改权限等任何写操作。
- 删除命令只展示,不执行。 报告里给出的清理命令是供用户自己在终端确认后运行的。即使用户在对话里说"帮我删",也要先停下确认(命中全局红线:删除文件必须先问),不要直接代跑。
- 估算标注清楚。 涉及"可释放空间"一律说明是估算值。
- 路径、命令保留原文不翻译。
- Read-only throughout. Only run scanning/statistics/directory listing/metadata reading (df, du, diskutil, stat, ls). Strictly prohibit any write operations such as rm, mv, rmdir, emptying the recycle bin, changing permissions, etc.
- Only display deletion commands, do not execute them. The cleanup commands provided in the report are for users to run in the terminal after confirmation. Even if the user says "help me delete" in the conversation, stop to confirm first (hit global red line: must ask before deleting files), do not run the command directly.
- Clearly mark estimates. Always indicate that "releasable space" is an estimated value.
- Keep paths and commands in original language without translation.
执行流程
Execution Process
Step 1 扫描(只读)
Step 1 Scan (Read-only)
bash
python3 scripts/scan.py > /tmp/storage_scan.jsonscan.pysys.platform- macOS:扫 home、library、caches、containers、group_containers、app_support、applications、downloads、dev_caches,用 算大小。
du - Windows:扫 user_profile、appdata_local、appdata_roaming、temp、downloads、program_files(_x86)、dev_caches,用 算大小;
os.scandir含所有盘符。system.disks
输出 JSON:(系统/磁盘信息,含 主盘名 + 全部盘)+ (各组子目录大小,已降序、过滤 50MB 以下)。扫描较慢,耐心等。读不到的目录标 ,需在报告里列出并提示遗漏体量。
systemdisk_namedisksgroupsdeniedbash
python3 scripts/scan.py > /tmp/storage_scan.jsonscan.pysys.platform- macOS: Scans home, library, caches, containers, group_containers, app_support, applications, downloads, dev_caches, calculates sizes using .
du - Windows: Scans user_profile, appdata_local, appdata_roaming, temp, downloads, program_files(_x86), dev_caches, calculates sizes using ;
os.scandirincludes all drive letters.system.disks
Output JSON: (system/disk information, including main disk name + all disks) + (subdirectory sizes of each group, sorted in descending order, filtered to exclude items below 50MB). Scanning is slow, please be patient. Directories that cannot be read are marked , and the missed volume should be listed in the report with a prompt.
systemdisk_namedisksgroupsdeniedStep 2 分析与分级
Step 2 Analysis and Categorization
先看 判断系统,读对应的数据布局参考:macOS 读 references/macos.md,Windows 读 references/windows.md(讲该系统东西存哪、怎么辨认、归哪一级)。然后读 做这几件事:
system.os/tmp/storage_scan.json- 挑 Top 5 占用大户,判定类型(系统资产/应用本体/应用数据/应用缓存/开发缓存/用户文件/媒体内容/下载内容/虚拟机镜像/回收站/其他)。
- 识别"神秘大目录":UUID 命名的 Container、不明的隐藏目录,要追查它属于哪个 App、装的是什么(例如某 97GB 的 UUID Container 实为 Bilibili 离线视频缓存)。必要时 /
ls深入一层看清楚,但仍只读。du - 三级分类 = 清理决策清单,不是全盘点。 只把"存在'要不要动它'这个决策"的项放进三灯;日常在用的正常应用、操作系统本身、海量零碎小文件没有清理决策,不进三灯,它们落在磁盘条的蓝色"系统及其他"里。判定标准:
- 🟢 可自动清理:纯缓存、临时文件、安装包残留、明确可再生且不影响功能、不丢用户数据(pip/uv/npm/Xcode DerivedData 等开发缓存、浏览器缓存)。
- 🟡 需人工判断:含用户数据或有判断成本(离线视频、文档、项目代码 node_modules、聊天记录、设计稿)。给内容画像 + 至少 3 句处置路径(应用内清理 / 系统工具 / 文件管理器手动审查,三选最合适)+ 风险提示。所有橙灯项在服务模式下自动有「在访达/资源管理器打开」按钮(跳过去自己审查删);如果该项有一个核实过、删了不破坏 App 的安全子路径(如 B站离线视频的 目录、旧备份目录),给它
.Downloads→ 网页出现「移到废纸篓」按钮(橙灯只准移废纸篓、可逆,绝不给"直接删除")。App 托管又无安全子路径的(Chrome/微信)只给打开按钮、不给 trash_paths。按钮下方会自动写明注意事项(打开只查看不删、移废纸篓可逆需清空才释放等);如果某项在文件管理器里是 App 内部格式、不方便手动挑选,给它一个trash_paths字段做客观说明(会显示在注意事项里)。口吻要中性、像产品说明:直接描述"这里是什么结构、为什么不好手动删、想精细操作该去哪",不要写成"我发现/提醒注意/看着像没视频"这种暴露开发者踩坑视角的话。open_note - 🔴 谨慎清理(有决策但不建议手删):你可能想动、但建议别手删的具体项——重复安装的应用、想卸载的大应用、运行中应用的核心数据等。给"为什么不建议手删" + 写具体卸载步骤(自带卸载器 / 启动台长按 / 右键移废纸篓 / AppCleaner 清残留 / App Store 可重装等,要可照做不是空话)。应用项给
indirect_release(真实app_paths绝对路径数组)→ 网页出现「在文件管理器打开(去卸载)」按钮,定位到 App 让用户自己正规卸载。红灯不给删除/卸载按钮(应用在系统目录、可能要管理员密码、可能有自带卸载器和残留,后台代删不稳妥)。纯系统文件、APFS 快照不要单独列红卡(没有清理决策),归蓝色即可;系统层面的释放技巧(重启释 swap、Time Machine 快照策略、可清除空间自动回收)写进.app长期建议。summary.long_term
每个 🟢 项要给:预估释放空间、清理前需关闭的进程、可一键复制的清理命令(用移到废纸篓或 App 自身清理入口的安全方式,谨慎用 ;如用 必须是明确的缓存子目录)。
rmrm大小字段写干净: / 用"约 14 GB""合计约 8.6 GB"即可——"约"已表示估算,不要再加"(估算)",重复且不专业(模板也会自动去掉这种冗余括号)。可再生属性已由分级标题和按钮说明覆盖,别塞进大小字段。
sizesize_estimateFirst, determine the system using , and read the corresponding data layout reference: for macOS, read references/macos.md, for Windows, read references/windows.md (explains where things are stored in the system, how to identify them, and which category they belong to). Then read to do the following:
system.os/tmp/storage_scan.json- Select Top 5 space hogs, determine their types (system assets, application installations, application data, application caches, development caches, user files, media content, downloaded content, virtual machine images, recycle bin, others).
- Identify "mysterious large directories": UUID-named Containers, unknown hidden directories. Trace which App they belong to and what they contain (e.g., a 97GB UUID Container is actually Bilibili offline video cache). If necessary, use /
lsto look one level deeper, but remain read-only.du - Three-level classification = cleanup decision list, not a full inventory. Only include items that require a "should I move it" decision in the three-color categories. Regular daily applications, the operating system itself, and massive small files without cleanup decisions are not included in the three-color categories; they fall into the blue "System and Others" section of the disk bar. Judgment criteria:
- 🟢 Auto-cleanable: Pure cache, temporary files, installation package residues, clearly regenerable without affecting functionality or losing user data (development caches like pip/uv/npm/Xcode DerivedData, browser caches).
- 🟡 Manual judgment required: Contains user data or requires judgment (offline videos, documents, project code node_modules, chat records, design drafts). Provide content profiling + at least 3 disposal paths (in-app cleanup / system tools / manual review via file manager, choose the most suitable three) + risk warnings. All yellow items automatically have an "Open in Finder/File Explorer" button in service mode (jump to review and delete manually); if the item has a verified safe subpath that can be deleted without damaging the App (e.g., directory for Bilibili offline videos, old backup directories), assign it
.Downloads→ a "Move to Trash" button appears on the webpage (yellow items can only be moved to trash, reversible, never allow "direct deletion"). Apps hosted without safe subpaths (Chrome/WeChat) only provide an open button, notrash_paths. Notes are automatically displayed below the buttons (open only for viewing not deletion, moving to trash is reversible and requires emptying to release space, etc.); if an item is in an App-internal format that is inconvenient to manually select in the file manager, add antrash_pathsfield for objective explanation (will be displayed in the notes). Tone should be neutral, like product instructions: Directly describe "what structure this is, why it's not easy to delete manually, where to go for fine-grained operations", do not write from a developer's perspective like "I found/remind you/it looks like no videos".open_note - 🔴 Clean with caution (decision needed but not recommended to delete manually): Specific items you might want to move but are advised not to delete manually—duplicate applications, large apps you want to uninstall, core data of running apps, etc. Provide "why manual deletion is not recommended" + with specific uninstall steps (built-in uninstaller / long press in Launchpad / right-click to move to trash / AppCleaner to clear residues / reinstall via App Store, etc., must be actionable not empty words). For app items, assign
indirect_release(array of realapp_pathsabsolute paths) → an "Open in File Manager (to uninstall)" button appears on the webpage, locating the App for users to uninstall formally. Red items do not have delete/uninstall buttons (apps are in system directories, may require administrator password, may have built-in uninstallers and residues, background deletion is unstable). Pure system files, APFS snapshots should not be listed separately as red cards (no cleanup decision), they belong to the blue section; system-level release techniques (restart to release swap, Time Machine snapshot strategy, automatic recovery of freeable space) are written into.applong-term suggestions.summary.long_term
Each 🟢 item must include: estimated releasable space, processes to close before cleanup, one-click copyable cleanup commands (use safe methods like moving to trash or App's own cleanup entry, use cautiously; if using , it must be a clear cache subdirectory).
rmrmKeep size fields clean: / should be written as "~14 GB" "total 8.6 GB"—the "" already indicates an estimate, do not add "(estimated)" which is redundant and unprofessional (the template will automatically remove such redundant parentheses). The regenerable attribute is covered by the category title and button descriptions, do not include it in the size field.
sizesize_estimateStep 3 生成交互报告
Step 3 Generate Interactive Report
把分析结果写成 analysis JSON(schema 见 顶部注释)。
scripts/build_report.py🟢 项必须带 (具体可删的绝对路径数组,区别于人类可读的 展示字段)——这是网页删除按钮的前提,漏了按钮就不出现。
trash_pathspath默认用一键删除模式()打开报告,因为这个 skill 的核心价值就是网页上能直接清理:
server.pybash
python3 scripts/server.py /tmp/storage_analysis.json # 自动开浏览器,Ctrl+C 停server.pyrmtrash_pathstrashtrash_pathsopenpath仅当用户明确只想要一份可分享/留存的只读文件时,才用静态模式(无删除按钮,因为 打开的页面碰不到文件系统):
file://bash
python3 scripts/build_report.py /tmp/storage_analysis.json ~/Desktop/storage-report.html && open ~/Desktop/storage-report.html排障:网页上没有删除/移废纸篓按钮 = 要么开的是静态报告(改用 ),要么 🟢 项漏了 (补上重启服务)。
server.pytrash_paths报告阅读流(固定顺序):磁盘总览卡片(容量 + 进度条 + 三色容量 pills + 系统信息,纯数据)→ 占用排行 Top5 → 执行建议 → 🟢🟡🔴 三级可折叠卡片(命令一键复制)→ 长期优化建议。即"现状 → 诊断 → 处方 → 操作 → 预防"。
注意 要写成一句话洞察(直接说最大占用是什么、能释放多少),不要重复总/已用/可用数字——那些已在卡片大数字里显示。overview 渲染在"执行建议"小节开头作引子(普通文字),紧接着是 优先级清单。
summary.overviewsummary.priority磁盘进度条把"已用"拆成分段:绿(可自动清)+橙(需手动)+红(已识别的不建议动项)+蓝(系统及其他,自动取 已用−绿−橙−红 的余量),余下为可用(灰底)。 的 green / yellow / red 三个值都要以可解析的 GB 数字开头(如 "约 27.8 GB"),脚本从中取数算分段;蓝色段和"系统及其他"pill 由模板自动算余量。
summary.tier_statspills 只渲染解析出的纯数字(如"约 5.5 GB"),不显示数据里的附注,所以 tier_stats 三个值写干净的数字即可,别加"仅已识别项/系统未计"这类道歉式说明——系统文件本来就归在蓝色段,红色只放你能量化的 🔴 项(重复应用、可卸载大应用等),量不准的系统文件/快照自然落到蓝色。
Write the analysis results into an analysis JSON (schema see top comments of ).
scripts/build_report.py🟢 items must include (array of specific deletable absolute paths, different from the human-readable display field)—this is the prerequisite for the webpage delete button; if missing, the button will not appear.
trash_pathspathBy default, open the report in one-click delete mode (), because the core value of this skill is direct cleanup via the webpage:
server.pybash
python3 scripts/server.py /tmp/storage_analysis.json # Automatically opens browser, Ctrl+C to stopserver.pyrmtrash_pathstrashtrash_pathsopenpathOnly when the user explicitly wants a shareable/savable read-only file, use static mode (no delete buttons, because pages opened via cannot access the file system):
file://bash
python3 scripts/build_report.py /tmp/storage_analysis.json ~/Desktop/storage-report.html && open ~/Desktop/storage-report.htmlTroubleshooting: No delete/move to trash buttons on the webpage = either the static report is opened (switch to ), or is missing for 🟢 items (add it and restart the service).
server.pytrash_pathsReport reading flow (fixed order): Disk overview card (capacity + progress bar + three-color capacity pills + system information, pure data) → Top5 space usage ranking → Execution suggestions → 🟢🟡🔴 collapsible three-level cards (one-click copy commands) → Long-term optimization suggestions. That is "Current Status → Diagnosis → Prescription → Operation → Prevention".
Note that should be written as a one-sentence insight (directly state what the largest space usage is and how much can be released), do not repeat total/used/available numbers—those are already displayed in the large numbers of the card. The overview is rendered as an introduction in plain text at the beginning of the "Execution Suggestions" section, followed by the priority list.
summary.overviewsummary.priorityThe disk progress bar splits "used" into segments: green (auto-cleanable) + orange (manual required) + red (identified items not recommended to move) + blue (system and others, automatically calculated as used - green - orange - red), with the remaining space as available (gray background). The green / yellow / red values in must start with parsable GB numbers (e.g., "~27.8 GB"), and the script extracts numbers from them to calculate segments; the blue segment and "System and Others" pill are automatically calculated by the template using the remaining amount.
summary.tier_statsPills only render parsed pure numbers (e.g., "~5.5 GB"), do not display notes in the data, so the three values in tier_stats should be clean numbers, do not add apologetic notes like "only identified items/system not included"—system files are already in the blue section, red only includes quantifiable 🔴 items (duplicate apps, large apps to uninstall, etc.), system files/snapshots with inaccurate volume naturally fall into the blue section.
Step 4 对话里给摘要
Step 4 Provide Summary in Conversation
报告生成后,在对话里用一段话给结论先行的摘要:总可释放估算、最该先清的 2-3 项、风险最高的一项。细节让用户看网页。
After generating the report, provide a conclusion-first summary in the conversation: estimated total releasable space, 2-3 top priority items to clean up, and the highest-risk item. Let users check the webpage for details.
依赖与运行前提
Dependencies and Prerequisites
- 全部脚本是 Python 3 标准库,零第三方依赖(不用 pip install)。
- macOS 自带 python3、、
du、diskutil,开箱即用。osascript - Windows 默认没装 Python——需先装 Python 3,且命令多为 或
python(不是py -3)。本 skill 命令示例写的是python3,在 Windows 上自动改用python3/python。py -3 - 本 skill 是 agent 驱动:扫描出数据后由 agent(Claude)做分级分析,不是双击即用的独立 App。
- All scripts use Python 3 standard library, zero third-party dependencies (no need for pip install).
- macOS comes with python3, ,
du,diskutilout of the box.osascript - Windows does not have Python installed by default—need to install Python 3 first, and commands are often or
python(notpy -3). This skill usespython3in command examples, which will automatically switch topython3/pythonon Windows.py -3 - This skill is agent-driven: After scanning data, the agent (Claude) performs classification analysis, it is not a double-click-to-run independent App.
平台状态
Platform Status
- macOS:完整实现并实测(扫描 / 报告 / 一键删除全验证过)。
- Windows:代码已写(的
scan.py、scan_windows的server.py走_trash_windows),但未在真实 Windows 上实测。首次在 Windows 跑要核对:目标目录路径、SHFileOperationW大小、回收站删除是否正常。多盘符已支持(主盘分段条 + 其他盘列表)。os.scandir
- macOS: Fully implemented and tested (scanning / report / one-click deletion fully verified).
- Windows: Code is written (in
scan_windows,scan.pyin_trash_windowsusesserver.py), but not tested on real Windows. When running on Windows for the first time, verify: target directory paths,SHFileOperationWsize, recycle bin deletion functionality. Multi-drive support is already implemented (main disk progress bar + other disk list).os.scandir
长期优化建议素材(写进报告 summary.long_term)
Long-term Optimization Suggestions Material (write into report summary.long_term)
- 定期清理:、Xcode DerivedData、浏览器缓存
brew cleanup - 可视化工具:DaisyDisk、GrandPerspective、OmniDiskSweeper
- 大文件归档到外置盘 / iCloud / NAS;macOS「系统设置 > 通用 > 储存空间」的优化选项
- Regular cleanup: , Xcode DerivedData, browser caches
brew cleanup - Visualization tools: DaisyDisk, GrandPerspective, OmniDiskSweeper
- Archive large files to external drive / iCloud / NAS; macOS "System Settings > General > Storage" optimization options