Repository navigation
Share One Registration Helper Between the Agent-Safety Installer's Hooks - #3518
Conversation
The installer carried two copies of the PreToolUse registration check, one per hook, and three copies of the strip-then-register block. A fix to either had to be made in each copy. `register_hook` now strips a hook from every group of an event and registers it in the one group a selector picks, for the gh-write-guard, model-tier-guard, and SessionEnd sweep alike. `registration_problems` checks both PreToolUse hooks through one nested helper. Every reported message is unchanged. Closes #3517 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
A recorded local strict-review pass covers head |
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review issues were identified, and the refactor preserves existing behavior.
No open issues 🎉
What changed in this PR
This pull request refactors the Claude agent-safety installer to share hook registration and PreToolUse validation logic while preserving existing behavior and generated settings.
Changes:
- Adds
register_hookto deduplicate and place all three hooks in the appropriate event groups. - Consolidates validation for the two PreToolUse hooks.
- Preserves the SessionEnd hook’s matcherless registration and existing diagnostics.
| File | Description |
|---|---|
host-setup/agent-safety/claude/install.py |
Adds shared hook registration and PreToolUse validation helpers while preserving existing settings and behavior. |
Review effort: Lite
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3518 +/- ##
==========================================
Coverage ? 81.53%
==========================================
Files ? 26
Lines ? 8964
Branches ? 0
==========================================
Hits ? 7309
Misses ? 1655
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ain (#3521) ## Summary This promotes three changes to `main`: - [#3516](#3516) maps model tiers in one config, `spec/model-tiers.json`, carries the "Model Tiers" rule into the skills that dispatch, and adds a guard that refuses a highest-tier dispatch the maintainer did not allow. - [#3518](#3518) has the agent-safety installer's hooks share one registration helper. - [#3520](#3520) has those hooks share one registration-check loop. It also carries the fixes for this promotion's own review findings, each landed on `develop` first: - [#3522](#3522) requires a non-empty model name per tier and names both edits a model release makes. - [#3523](#3523) states what the highest-tier allowance covers and where the guard stops. - [#3524](#3524) rejects a tier sharing the maintainer-only model and states the allowance as conduct. - [#3525](#3525) matches the guard's alias boundaries regardless of case. - [#3526](#3526) mirrors the guard's CI self-tests in the local runbook. - [#3527](#3527) rejects a repeated tier name and names every hook the installer registers. Closes #3517 Closes #3519 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
host-setup/agent-safety/claude/install.pyregistered three hooks: gh-write-guard and model-tier-guard under PreToolUse, and the stray-process sweep under SessionEnd. It carried a separate copy of the registration logic for each, so a later fix to that logic had to be made in every copy.register_hookis a new module-level helper. It strips every entry naming a hook from an event's groups, then registers that hook once in the group a selector picks, or in a new group carrying the given matcher.mainnow calls it for all three hooks.registration_problemsnow checks both PreToolUse hooks through one nestedcheck_pre_tool_hook, which takes the hook's name, the tools its matcher must see, and the wording of its messages.This is a pure refactor. Every message string, its order, and its deduplication are unchanged, and so is every settings.json shape the installer writes. That includes the SessionEnd group, which is still created with no
matcherkey.The
commentslabel is set because the counting comment moved into the shared helper (re-indented and reworded for both hooks), and the tool-coverage comment now covers one tool or several.Verification
python3 -m unittest discover -s host-setup/agent-safety/claude -p 'test_*.py': 184 tests, OKuvx ruff@latest checkandformat --checkonhost-setup/agent-safety/claude: cleanuvx mypy host-setup/agent-safety/claude/install.py: no issuesPre-existing findings, filed
host-setup/agent-safety/claude/install.py, the SessionEnd check loop inregistration_problems, design. It still hand-rolls the count loop thatcheck_pre_tool_hooknow shares. It is left out because Share One Registration Helper Between the Agent-Safety Installer's PreToolUse Hooks #3517 scopes the shared check to the two PreToolUse loops, and the SessionEnd loop differs in substance: it checks the timeout, and its matcher note does not exclude the entry from the count. Filed as Share One Registration-Check Skeleton Between the Installer's PreToolUse and SessionEnd Hooks #3519 once the history showed every cross-copy fix landing on the shared skeleton.Closes #3517
🤖 Generated with Claude Code