Skip to content

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

Merged
mpfaffenberger merged 1 commit intompfaffenberger:mainfrom
thomwebb:main
May 6, 2026
Merged

fix: wire destructive_command_guard plugin into hook engine (#316)#320
mpfaffenberger merged 1 commit intompfaffenberger:mainfrom
thomwebb:main

Conversation

@thomwebb
Copy link
Copy Markdown
Contributor

@thomwebb thomwebb commented May 6, 2026

Problem

The destructive_command_guard plugin (#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/ (#310): that plugin has detector.py plus register_callbacks.py that calls register_callback("run_shell_command", ...). That's why #310 actually works and #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 #316

…fault

- Register a run_shell_command callback that inspects every shell invocation for destructive patterns
- Prompt interactive users for explicit approval before allowing risky commands to proceed
- Hard-block destructive commands in non-interactive contexts to prevent accidental data loss in CI and automation
- Return structured block responses with clear reasoning and user-facing error messages for safer handling
@mpfaffenberger mpfaffenberger merged commit 395e712 into mpfaffenberger:main May 6, 2026
2 checks passed
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.

2 participants