Skip to content

fix: wire destructive_command_guard plugin into hook engine (#316)#2

Closed
thomwebb wants to merge 1 commit intomainfrom
fix/destructive-command-guard-wiring
Closed

fix: wire destructive_command_guard plugin into hook engine (#316)#2
thomwebb wants to merge 1 commit intomainfrom
fix/destructive-command-guard-wiring

Conversation

@thomwebb
Copy link
Copy Markdown
Owner

@thomwebb thomwebb commented May 6, 2026

Problem

The destructive_command_guard plugin (mpfaffenberger#316) is silently dead code. The plugin loader at code_puppy/plugins/__init__.py:29 requires every built-in plugin to have a register_callbacks.py. This plugin didn't have one — it shipped only detector.py + __init__.py + a passing test suite. The detection patterns were defined, tested, and never wired.

Compare to force_push_guard/ (mpfaffenberger#310): that plugin has detector.py plus register_callbacks.py that calls register_callback("run_shell_command", ...). That's why mpfaffenberger#310 actually works and mpfaffenberger#316 doesn't.

Fix

Added register_callbacks.py to destructive_command_guard/, following the exact same pattern as force_push_guard:

  • Hooks into the run_shell_command phase
  • Interactive TTY: shows an approval prompt via get_user_approval_async with a Rich panel (pattern name, description, full command)
  • Non-interactive (CI/piped/sub-agent): hard-blocks with {"blocked": True} and a descriptive error message
  • Auto-registers on import

Verification

  • All 72 existing detector tests pass
  • Callback confirmed registered in the run_shell_command hook chain
  • Safe commands (git status) → None (allowed)
  • Destructive commands (rm -rf /) → blocked with reasoning
  • Ruff lint + format + isort all pass

Fixes mpfaffenberger#316

- Register a run_shell_command hook that detects destructive shell commands before they execute
- Prompt for confirmation in interactive terminals so risky commands can still be run intentionally
- Hard-block destructive commands in non-interactive contexts to prevent accidental data loss in automation and agents
- Return structured rejection details and user-facing warnings to make failures explicit and actionable
@thomwebb thomwebb closed this May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant