fix(hookify): add read event type for Read/Glob/Grep/LS tools #18438
+17
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add a dedicated
readevent type for Read/Glob/Grep/LS tools to prevent file-editing rules from incorrectly triggering on read operations.Problem
Currently, Read/Glob/Grep/LS tools have no event mapping (
event = None), which causes ALL rules to load regardless of their event field. This is problematic:Rules with
event: file(designed for Edit/Write) incorrectly fire when simply reading files.Related: #17246
PR #17246 addresses the same issue but maps Read →
fileevent. This approach has a UX problem: file-editing rules like "no console.log in production" would still trigger when reading files.This PR proposes a better solution: a dedicated
readevent type.Solution
Add
readas a new event type:This gives users precise control:
event: file→ Only Edit/Write/MultiEdit (actual modifications)event: read→ Only Read/Glob/Grep/LS (read operations)event: all→ EverythingFiles Changed
hooks/pretooluse.pyhooks/posttooluse.pyREADME.mdskills/writing-rules/SKILL.mdUsage Example
Why
readis Better Than Reusingfilefile(#17246)read(this PR)Test Plan