Skip to content

fix(hooks): match real file extension in Read|Glob hook (.astro miss, .json false-fire) - #1464

Closed
marketechniks wants to merge 1 commit into
Graphify-Labs:v8from
marketechniks:fix/read-hook-extension-match
Closed

marketechniks wants to merge 1 commit into
Graphify-Labs:v8from
marketechniks:fix/read-hook-extension-match

Conversation

@marketechniks

Copy link
Copy Markdown
Contributor

Fixes #1463.

Problem

The Read|Glob PreToolUse hook (_READ_SETTINGS_HOOK in graphify/__main__.py, used by both the Claude and CodeBuddy installers) decided whether to nudge by substring-scanning the joined file_path + pattern + path for known extensions:

s = (file_path + ' ' + pattern + ' ' + path).lower().replace('\\','/')
hit = 'graphify-out/' not in s and any(e in s for e in exts)

Two opposite failures fall out of that:

  • False negative — .astro / .vue / .svelte never nudge. They weren't in exts, so on Astro/Vue/Svelte projects (where they're the primary source type) reading or globbing a component never surfaced the graph. Only the Bash/grep hook covered those repos.
  • False positive — .json matches .js. '.js' is a substring of '.json', so reading package.json, tsconfig.json, etc. spuriously fired the "run graphify first" nudge. Any path containing a listed ext as a substring over-fires.

Fix

Compare each value's real trailing extension (segment after the last /, then after the last .) against exts, and add the framework extensions:

vals  = [file_path, pattern, path]
j     = ' '.join(vals).lower().replace('\\','/')
tails = [('.'+x.rsplit('.',1)[-1])
         for v in vals if v
         for x in [v.lower().replace('\\','/').rsplit('/',1)[-1]] if '.' in x]
hit   = 'graphify-out/' not in j and any(t in exts for t in tails)

package.json → tail .json (not in exts, silent); **/*.astro → tail .astro (matched, fires). The graphify-out/ suppression and the fail-open behaviour are unchanged.

Tests

Added regression tests in tests/test_read_hook.py:

  • test_nudges_on_framework_source — .astro / .vue / .svelte reads nudge
  • test_astro_glob_nudges — **/*.astro glob nudges
  • test_silent_on_json_config — package.json / tsconfig.json / data.geojson stay silent

All existing cases still pass:

pytest tests/test_read_hook.py tests/test_install_strings.py tests/test_codebuddy.py
42 passed

…s#1463)

The Read|Glob PreToolUse hook tested extensions with a substring scan
(any(e in s for e in exts)) over the joined file_path/pattern/path. That
had two opposite failures:

- false negative: .astro/.vue/.svelte were absent from exts, so Read/Glob
  on framework components never nudged toward the graph.
- false positive: '.json' contains the substring '.js', so reading
  package.json, tsconfig.json, etc. spuriously fired the nudge.

Compare each value's real trailing extension (segment after the last '/'
then after the last '.') against exts instead, and add .astro/.vue/.svelte.
Preserves the graphify-out/ suppression and fail-open behaviour.

Adds regression tests: framework-source nudges, **/*.astro glob nudge,
and .json/.geojson config silence. Full hook + install-string + codebuddy
suites pass (42).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
safishamsi pushed a commit that referenced this pull request Jun 25, 2026
The Read|Glob PreToolUse hook (the "run graphify first" nudge, shared by the
Claude Code and CodeBuddy installers via _READ_SETTINGS_HOOK) decided whether to
nudge by substring-scanning the joined file_path/pattern/path for known
extensions. That had two opposite failures: '.js' is a substring of '.json' so
package.json / tsconfig.json spuriously fired, and .astro/.vue/.svelte weren't in
the set so Astro/Vue/Svelte projects never nudged on their primary source type.

The hook now compares each value's real trailing extension (segment after the
last '/', then after the last '.') against the set, and adds .astro/.vue/.svelte.
package.json -> tail .json (silent); **/*.astro -> tail .astro (fires); an
extension on a directory component (my.ts/file) correctly stays silent. The
graphify-out/ suppression and fail-open behavior are unchanged.

Ported from PR #1464 by @marketechniks onto current v8. Added three regression
tests on top of the PR's (multi-dot a.test.tsx / foo.min.js, a Windows backslash
path, and the directory-extension trap) to pin the trickiest parts of the new
segment-split logic.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Thanks @marketechniks — clean diagnosis and the right fix. Substring-matching the path was the root of both failures (the .js⊂.json false-fire and the missing .astro/.vue/.svelte), and comparing the real trailing extension (last / segment, then last .) is exactly the correct fix — it even handles the directory-extension trap (my.ts/file stays silent) for free.

Landed on v8 in 9b583a0 with your authorship preserved. I added three regression tests on top of yours to pin the trickiest parts of the segment-split logic (multi-dot a.test.tsx/foo.min.js, a Windows backslash path, and the directory-extension case).

Verified end-to-end by running the actual hook command the way Claude Code invokes it (sh -c + stdin JSON): package.json/tsconfig.json/data.geojson stay silent, .astro/.vue/.svelte and **/*.astro fire, normal source still fires, and graphify-out/ stays suppressed. Full suite 2424 passed. Closing as merged-by-port — thanks for the contribution.

@safishamsi safishamsi closed this Jun 25, 2026
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…hify-Labs#1463)

The Read|Glob PreToolUse hook (the "run graphify first" nudge, shared by the
Claude Code and CodeBuddy installers via _READ_SETTINGS_HOOK) decided whether to
nudge by substring-scanning the joined file_path/pattern/path for known
extensions. That had two opposite failures: '.js' is a substring of '.json' so
package.json / tsconfig.json spuriously fired, and .astro/.vue/.svelte weren't in
the set so Astro/Vue/Svelte projects never nudged on their primary source type.

The hook now compares each value's real trailing extension (segment after the
last '/', then after the last '.') against the set, and adds .astro/.vue/.svelte.
package.json -> tail .json (silent); **/*.astro -> tail .astro (fires); an
extension on a directory component (my.ts/file) correctly stays silent. The
graphify-out/ suppression and fail-open behavior are unchanged.

Ported from PR Graphify-Labs#1464 by @marketechniks onto current v8. Added three regression
tests on top of the PR's (multi-dot a.test.tsx / foo.min.js, a Windows backslash
path, and the directory-extension trap) to pin the trickiest parts of the new
segment-split logic.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read/Glob PreToolUse hook: substring ext match misses .astro and false-fires on .json

2 participants