Skip to content

Phase 7 cleanup uses rm -rf which conflicts with destructive-action policies on hardened hosts #301

@dtmsyi

Description

@dtmsyi

What

/understand's Phase 7 step 4 (skills/understand/SKILL.md) cleans up its scratch directories with:

rm -rf $PROJECT_ROOT/.understand-anything/intermediate
rm -rf $PROJECT_ROOT/.understand-anything/tmp

On hosts with destructive-action safety policies (mine: 2-hour freshness window, three-search-angle verification, mandatory audit delegation before any rm/mv -f/unlink/etc.), this trips because the directories were created moments earlier by the same skill. My advisory hook fires; my blocking guard doesn't (low-risk classification); the command goes through but doctrine compliance failed.

No data is lost in practice — those dirs are skill-internal scratch already merged into knowledge-graph.json. The conflict is about the shape of the action, not the outcome.

Repro

  1. Install a PreToolUse hook on the Claude Code / Codex host that gates rm -rf against a freshness window (e.g., refuse to delete files modified within the last 2h without an explicit auditor approval).
  2. Run /understand . on any repo.
  3. Phase 7 step 4 fires rm -rf .understand-anything/intermediate; the hook either blocks (forcing user to retry with override) or fires an advisory warning that the user is responsible for resolving.

Fix candidate

Replace the destructive rm -rf with a reversible mv to a timestamped trash dir, then opportunistically purge old trash on next run:

TRASH=$PROJECT_ROOT/.understand-anything/.trash-$(date +%s)
mv $PROJECT_ROOT/.understand-anything/intermediate $TRASH/ 2>/dev/null
mv $PROJECT_ROOT/.understand-anything/tmp $TRASH/ 2>/dev/null

# At Phase 0 of subsequent runs, purge .trash-* dirs older than 7 days:
find $PROJECT_ROOT/.understand-anything/ -maxdepth 1 -type d -name '.trash-*' -mtime +7 -exec rm -rf {} +

Benefits:

  • mv is reversible (file metadata preserved), so destructive-action gates that require a freshness check let it through cleanly.
  • The 7-day delayed purge gives the user time to recover from a botched run.
  • Same end-state for the user (clean .understand-anything/ after a few runs) without the doctrine conflict.

Additional context

Happy to PR if the mv.trash/ pattern looks right; would also be a tiny doc nit to add "destructive-action safety" to the failure modes the skill recipe acknowledges.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions