
Guarding Destructive Operations
Add and review preconditions on operations that delete, overwrite, rewrite history, or...
Install
npx skills add kajisho5/ffmpeg-skill --skill guarding-destructive-operations -g -a claude-code -y- Repository
- kajisho5/ffmpeg-skill4.3k
- Category
- Testing
- Updated
- 4d ago
- License
- MIT
- Context cost
- Mediumabout 2,451 tokens
- Runs scripts
- No, instructions only
What it does
Add and review preconditions on operations that delete, overwrite, rewrite history, or resolve a caller-supplied name to a filesystem path, refusing instead of warning, placing the guard ahead of the first mutation, structural classification rather than string-prefix matching, name validation plus resolved-path containment as two independent checks, why a guard on the destructive path is invisible to the dry-run, and mutation-testing each half separately. Use when writing or reviewing a `--rebuild`/`--reset`/`--purge` command, a bulk delete, a history rewrite, an `rm -rf`-shaped step, or any code that turns an argument into a file path.
Guarding Destructive Operations
Some operations have no undo: an orphan-branch rewrite, a recursive delete of
every tracked file, an overwrite of a stored artifact, a DROP/purge path. The
implementation is usually short and usually correct for the setup its author had
in mind. The bug is never the deletion itself, it is that nothing checked
whether the target was the thing the author imagined.
Two shapes recur, and they take the same fix:
- Blast radius. The operation is correct only in a dedicated, single-purpose target and is catastrophic in a mixed one.
- Boundary escape. A caller-supplied name is joined onto a base directory and lands outside it.
Refuse; don't warn, and don't add an override
A destructive operation that discovers its precondition is violated should return
an error and change nothing. A warning is read by nobody, and a --force escape
hatch turns the guard into documentation.
// A rebuild that recreates history does `checkout --orphan` then
// `rm -rf --ignore-unmatch .`, keeping only the state files it rewrites.
// That is correct in a dedicated mirror repository whose ONLY tracked content
// is `.state/`. Run it where source code also lives and the new branch loses
// the source code.
func (e *Engine) rebuild() error {
if err := e.ensureDedicatedRepo(); err != nil {
return err // nothing mutated yet
}
...
}
The honest justification for having no override flag: there is no situation where the operator wants this command to delete unrelated tracked files. If a real one appears later, that is a separate, differently-named command, not a boolean on this one.


