Skip to content

Hook Guard Command-Coverage Structural Enforcement#1985

Merged
Trecek merged 2 commits into
developfrom
unsafe-install-guard-bash-tool-coverage-gap-allows-worktree/1980
May 6, 2026
Merged

Hook Guard Command-Coverage Structural Enforcement#1985
Trecek merged 2 commits into
developfrom
unsafe-install-guard-bash-tool-coverage-gap-allows-worktree/1980

Conversation

@Trecek
Copy link
Copy Markdown
Collaborator

@Trecek Trecek commented May 6, 2026

Summary

The hook guard system lacks structural enforcement that command-inspecting guards must cover all tool variants that execute shell commands. Guards are written independently with ad-hoc extraction of command text, and the test suite validates each guard only against the tool format it was designed for — not against all tools it should logically intercept. The fix adds a structural meta-test that makes it impossible to register a command-inspecting guard without covering both the Bash native tool and run_cmd MCP tool, plus a parametrized test helper that forces every such guard to prove it blocks dangerous commands through either tool pathway.

This closes a gap where unsafe_install_guard.py and pr_create_guard.py only read tool_input.cmd (from run_cmd) but ignore tool_input.command (from Bash), allowing headless agents to bypass these guards entirely when using the native Bash tool instead of the MCP wrapper.

Closes #1980

Implementation Plan

Plan file: .autoskillit/temp/rectify/rectify_unsafe-install-guard-bash-tool-coverage-gap_2026-05-05_223500.md

🤖 Generated with Claude Code via AutoSkillit

Token Usage Summary

Step count uncached output cache_read peak_ctx turns cache_write time
rectify 1 4.3k 9.3k 388.6k 49.6k 136 42.0k 7m 59s
dry_walkthrough 1 46 17.4k 1.6M 77.3k 108 64.2k 10m 6s
implement 1 1.6M 15.0k 1.3M 51.4k 128 67.5k 6m 50s
prepare_pr 1 43.6k 3.7k 317.1k 0 23 0 2m 53s
compose_pr 1 38.2k 1.9k 354.5k 0 24 0 2m 6s
review_pr 1 53 28.1k 801.6k 79.6k 37 67.8k 7m 38s
Total 1.7M 75.5k 4.8M 79.6k 241.4k 37m 33s

Token Efficiency

Step LoC Changed cache_read/LoC cache_write/LoC output/LoC
rectify 0
dry_walkthrough 0
implement 291 4400.0 231.8 51.6
prepare_pr 0
compose_pr 0
review_pr 0
Total 291 16348.0 829.6 259.3

Trecek and others added 2 commits May 5, 2026 22:54
Structural meta-test added: test_command_guard_completeness.py auto-discovers
command-inspecting guards and asserts their matchers cover both "Bash" and
"mcp__autoskillit__local__autoskillit__run_cmd", and that their source reads
both "command" and "cmd" keys from tool_input.

Fixes:
- hook_registry.py: matcher for unsafe_install_guard and pr_create_guard now
  includes "Bash" alongside the run_cmd pattern
- unsafe_install_guard.py: reads tool_input.get("command", "") or tool_input.get("cmd", "")
  following the pattern from planner_gh_discovery_guard.py
- pr_create_guard.py: same dual-key extraction fix
- unsafe_install_guard.py: extends _UNSAFE_PATTERNS with "maturin develop"
- unsafe_install_guard.py: adds _SYSTEM_FLAG_PATTERN and _is_system_install()
  to block --system installs from worktrees
- Taskfile.yml line 224: uses .venv/bin/python --version instead of ambient python
  to avoid false diagnostics when ambient python differs from venv python

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Regenerated registry.sha256 after matcher change in hook_registry.py.
Shortened docstring in test_command_guard_completeness.py to satisfy
ruff E501 (100 > 99 chars).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator Author

@Trecek Trecek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AutoSkillit review passed. No blocking issues found.

@Trecek Trecek added this pull request to the merge queue May 6, 2026
Merged via the queue into develop with commit 67f14b1 May 6, 2026
2 checks passed
@Trecek Trecek deleted the unsafe-install-guard-bash-tool-coverage-gap-allows-worktree/1980 branch May 6, 2026 06:24
Trecek added a commit that referenced this pull request May 8, 2026
## Summary

The hook guard system lacks structural enforcement that
command-inspecting guards must cover all tool variants that execute
shell commands. Guards are written independently with ad-hoc extraction
of command text, and the test suite validates each guard only against
the tool format it was designed for — not against all tools it should
logically intercept. The fix adds a structural meta-test that makes it
impossible to register a command-inspecting guard without covering both
the `Bash` native tool and `run_cmd` MCP tool, plus a parametrized test
helper that forces every such guard to prove it blocks dangerous
commands through either tool pathway.

This closes a gap where `unsafe_install_guard.py` and
`pr_create_guard.py` only read `tool_input.cmd` (from `run_cmd`) but
ignore `tool_input.command` (from `Bash`), allowing headless agents to
bypass these guards entirely when using the native Bash tool instead of
the MCP wrapper.

Closes #1980

## Implementation Plan

Plan file:
`.autoskillit/temp/rectify/rectify_unsafe-install-guard-bash-tool-coverage-gap_2026-05-05_223500.md`

🤖 Generated with [Claude Code](https://claude.com/claude-code) via
AutoSkillit
<!-- autoskillit:pipeline-signature
steps=prepare_pr,run_arch_lenses,compose_pr,annotate_pr_diff,review_pr
-->

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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