Skip to content

Share One Registration Helper Between the Agent-Safety Installer's Hooks - #3518

Merged
ptr727 merged 2 commits into
developfrom
refactor/shared-hook-registration
Oct 27, 2026
Merged

ptr727 merged 2 commits into
developfrom
refactor/shared-hook-registration

Conversation

@ptr727

@ptr727 ptr727 commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

host-setup/agent-safety/claude/install.py registered 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_hook is 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. main now calls it for all three hooks.
  • registration_problems now checks both PreToolUse hooks through one nested check_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 matcher key.

The comments label 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, OK
  • uvx ruff@latest check and format --check on host-setup/agent-safety/claude: clean
  • uvx mypy host-setup/agent-safety/claude/install.py: no issues
  • Local strict review (frontier tier), two passes. The first raised one wording finding on the moved comment, fixed in 208d4a7, and the second pass raised none.

Pre-existing findings, filed

Closes #3517

🤖 Generated with Claude Code

ptr727 and others added 2 commits October 27, 2026 10:26
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>
Copilot AI lite review requested due to automatic review settings October 27, 2026 17:29
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ptr727

ptr727 commented Oct 27, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 208d4a7b805d469db3d3bd0367df1e7c61088a4d, the content this pull request carries at that commit against develop, and it recorded 0 findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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_hook to 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

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@cb82cda). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #3518   +/-   ##
==========================================
  Coverage           ?   81.53%           
==========================================
  Files              ?       26           
  Lines              ?     8964           
  Branches           ?        0           
==========================================
  Hits               ?     7309           
  Misses             ?     1655           
  Partials           ?        0           
Flag Coverage Δ
python-3.13 81.53% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727
ptr727 merged commit e713a5f into develop Oct 27, 2026
14 checks passed
@ptr727
ptr727 deleted the refactor/shared-hook-registration branch October 27, 2026 17:41
ptr727 added a commit that referenced this pull request Oct 27, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants