dsh-turn-cleanup

Blocks the end of a turn while temporary files from that turn are still lying around: it registers a listener on the serial agent/turn-stopping hook and, if anything is left, hands the model the file list plus two ways out — delete them, or justify each one and move it somewhere deliberate. Candidates come from two narrow temp-file sources, plus a backup-retention channel that is on by default and flags excess .bak copies of files touched this turn. The first is the .agent-tmp/ convention directory under the session cwd: whatever is left in it is reported outright, because that directory exists only for throwaway files. The second is the paths this turn actually wrote, captured through the fs/write-intent, fs/edit-intent and fs/delete-intent hooks; those are reported only when they sit under that cwd (compared after realpath normalisation), fall outside .git, node_modules, out, dist, build, target, vendor, .venv and the Python bytecode cache directory, match a temp-file pattern that requires a separator after the prefix so checkout.js and benchmark.ts are not taken for scratch files, and the file is still present — which keeps junk already sitting in the workspace from being resurrected as a complaint about this turn. One gate per turn, subagent sessions skipped, nothing deleted unless the backup mode is explicitly set to prune, and the injected wording follows the host locale instead of assuming a Chinese one.

Overview

Blocks the end of a turn while temporary files from that turn are still lying around: it registers a listener on the serial agent/turn-stopping hook and, if anything is left, hands the model the file list plus two ways out — delete them, or justify each one and move it somewhere deliberate. Candidates come from two narrow temp-file sources, plus a backup-retention channel that is on by default and flags excess .bak copies of files touched this turn. The first is the .agent-tmp/ convention directory under the session cwd: whatever is left in it is reported outright, because that directory exists only for throwaway files. The second is the paths this turn actually wrote, captured through the fs/write-intent, fs/edit-intent and fs/delete-intent hooks; those are reported only when they sit under that cwd (compared after realpath normalisation), fall outside .git, node_modules, out, dist, build, target, vendor, .venv and the Python bytecode cache directory, match a temp-file pattern that requires a separator after the prefix so checkout.js and benchmark.ts are not taken for scratch files, and the file is still present — which keeps junk already sitting in the workspace from being resurrected as a complaint about this turn. One gate per turn, subagent sessions skipped, nothing deleted unless the backup mode is explicitly set to prune, and the injected wording follows the host locale instead of assuming a Chinese one.

Installation

Install from GitHub

dsh plugin --profile web add github:Leonlee114514/dsh-turn-cleanup

Installing from GitHub runs the project's build script, which pnpm blocks until you allowlist it — run the command once and pnpm prints the exact key to add under `allowBuilds` in ~/.dsh/profiles/web/pnpm-workspace.yaml.

Version compatibility

Compatibility is unconfirmed. Check the project documentation for supported versions.