缓存清理 / Cache Cleaner for DSH
DSH 桌面版与网页版的一个界面插件,用来清掉 DSH 留在系统临时目录里的孤儿工作区快照。
为什么会有这些快照
DSH 的 dsh-workspace-changes 插件为了给出「本轮改了哪些文件」的对比,会给每个会话在系统临时目录下建一个 dsh-workspace-changes-XXXXXX 目录,把工作区里未跟踪、未被忽略的文件压进对象库。
正常结束会话时 DSH 会自己删掉它。但会话被强杀、DSH 进程异常退出、或机器直接关机时,这个目录就留在原地成为孤儿。如果工作区里有几百 MB 以上的大文件,一个孤儿目录就能占几十 GB。
它怎么清
侧边栏底部、余额挂件的下面有一行「缓存」,显示当前占用和一条进度条,点开是清理面板。
删除前必须同时满足五条:
- 解析成绝对路径后,必须是系统临时目录的直接子目录。临时目录用系统接口取,不写死路径。
- 目录名完整匹配
^dsh-workspace-changes-[A-Za-z0-9]{6}$。 - 不是重解析点。符号链接和目录联接一律跳过。
- 最后写入时间超过保留时长,默认 72 小时,界面上可改。
- 目录里每个文件都能以独占方式打开一次。有一个打不开就整个跳过,绝不做部分删除。
另外,目录内部有符号链接也跳过;代码里还硬编码了一份禁止删除清单(.pg0、.dsh、.hindsight、模型缓存、WSL、OneDrive、Documents、Desktop 等),任何情况下都不会进入。
删除是两步的。先点「试运行删除」,只写待删清单、不删任何东西;看清「将删除几个、共多少 GB」之后再点「确认正式删除」。
安装
从插件市场安装,或者:
dsh plugin --profile <profile> add dsh-temp-snapshot-cleaner
也可以直接从 GitHub 装:
dsh plugin --profile <profile> add github:b9p79rgh6f-sudo/dsh-temp-snapshot-cleaner
装完刷新页面(宿主页有改动时重启 DSH)。
留下的记录
- 待删清单和结果清单:
~/.dsh/plugin-data/temp-snapshot-cleaner/manifests/ - 运行日志:
~/.dsh/logs/temp-snapshot-cleaner.log - 设置:
~/.dsh/plugin-data/temp-snapshot-cleaner/settings.json
开发
node tools/test-core.mjs # 五条判定、试运行、正式删除、清单落地
node tools/test-client-render.mjs # 侧边栏入口与面板渲染
test-core.mjs 会在系统临时目录里造几个假目录(4 天前的、1 小时前的、名字不合法的、文件被独占打开的、指向用户文档的目录联接),跑完自己清掉。
和源头的关系
这个插件清的是已经漏出来的东西。真正的源头是工作区里的大文件被反复整体快照。给工作区所在仓库加一条 .gitignore(例如忽略数据库文件和计算临时文件),新产生的快照体积才会降下来,两者配合才是完整的。
Cache Cleaner for DSH
A DSH Web/Desktop UI plugin that removes orphaned dsh-workspace-changes-* directories from the system temp folder.
DSH's dsh-workspace-changes plugin snapshots each workspace into the temp folder so it can show which files changed in a turn. Sessions normally remove their snapshot when released; killed sessions and crashed hosts leave them behind, and a workspace with large untracked files can turn one orphan into tens of gigabytes.
The plugin adds a 「缓存」 row at the sidebar foot with the current footprint and a progress bar. Deleting requires all five checks to pass: direct child of the system temp folder, exact name pattern, not a reparse point, older than the retention window (72 hours by default), and every file opens exclusively once. A hardcoded deny list covers .pg0, .dsh, .hindsight, model caches, WSL, OneDrive, Documents and Desktop.
Deletion is two-step: a dry run writes a manifest and reports what would be deleted, then an explicit confirmation performs it. Manifests and logs are kept under ~/.dsh/plugin-data/temp-snapshot-cleaner/ and ~/.dsh/logs/.
MIT licensed.
No comments yet. Be the first to write one.