mpfaffenberger / mpfaffenberger/code_puppy

hook_engine: surprising &&/|| precedence, over-eager file-path heuristic, duplicated snake_case converters and event-type lists

Open
#442 0 comments 0 reactions 0 assignees View on GitHub

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)

  1. matcher.py operator precedence is undocumented and surprising (matches(), lines 31-38): || is split before &&, so A && B || C parses as A && (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 like Edit|Write, which _is_regex_pattern otherwise supports) cannot contain || without being split. At minimum document the precedence in the docstring; better, note that regex alternation | works and recommend it.

  2. _looks_like_file_path over-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_path that 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.

  3. Duplicated CamelCase->snake_case converter: registry.py:_to_attr() (~line 86) and models.py:HookRegistry._normalize_event_type() (~line 173) are the same two-regex implementation copy-pasted. Also registry.py:SUPPORTED_EVENT_TYPES duplicates the attribute list hard-coded in HookRegistry.count_hooks(). One source of truth: derive both from a single EVENT_TYPES mapping in models.py.

  4. engine.py:process_event result misalignment risk: for hook, result in zip(matching_hooks, results) - with execute_hooks_sequential(stop_on_block=True), results can be shorter than matching_hooks; zip truncates correctly today, but only by accident of ordering. A comment or strict=False intent 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.