mpfaffenberger / mpfaffenberger/code_puppy
hook_engine: surprising &&/|| precedence, over-eager file-path heuristic, duplicated snake_case converters and event-type lists
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
File: code_puppy/hook_engine/ (matcher.py, registry.py, models.py, engine.py)
Severity: Low-Medium (correctness / Zen)
-
matcher.pyoperator precedence is undocumented and surprising (matches(), lines 31-38):||is split before&&, soA && B || Cparses asA && (B || C)- the opposite of conventional precedence (where&&binds tighter:(A && B) || C). No parentheses support, no escaping; a matcher whose pattern legitimately contains|characters (regex alternation likeEdit|Write, which_is_regex_patternotherwise supports) cannot contain||without being split. At minimum document the precedence in the docstring; better, note that regex alternation|works and recommend it. -
_looks_like_file_pathover-matches (matcher.py ~line 108): any string containing a dot with a short alnum suffix counts as a file path -"example.com","v1.2", a sentence ending "...see notes.txt" all qualify. Combined with the fallback loop in_extract_file_paththat scans all tool args, extension matchers (.py) can fire on non-path args. Refuse the temptation to guess: restrict the fallback scan to known key names or require a path separator. -
Duplicated CamelCase->snake_case converter:
registry.py:_to_attr()(~line 86) andmodels.py:HookRegistry._normalize_event_type()(~line 173) are the same two-regex implementation copy-pasted. Alsoregistry.py:SUPPORTED_EVENT_TYPESduplicates the attribute list hard-coded inHookRegistry.count_hooks(). One source of truth: derive both from a singleEVENT_TYPESmapping in models.py. -
engine.py:process_eventresult misalignment risk:for hook, result in zip(matching_hooks, results)- withexecute_hooks_sequential(stop_on_block=True),resultscan be shorter thanmatching_hooks; zip truncates correctly today, but only by accident of ordering. A comment orstrict=Falseintent note would prevent a future "fix" from breaking it.
Filed by Zen Reviewer B (code-puppy-60635a)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in code_puppy/hook_engine/matcher.py at matches(), _looks_like_file_path(), and _extract_file_path(); then compare the duplicated converters and event-type definitions in registry.py and models.py. Inspect engine.py:process_event for the sequential result behavior. Done means matcher semantics and path detection are addressed, event types have one source of truth, and result-to-hook handling remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100