feat(hook-augment): augment Bash tool searches via graph - #1337
Open
abendrothj wants to merge 2 commits into
Open
feat(hook-augment): augment Bash tool searches via graph#1337abendrothj wants to merge 2 commits into
abendrothj wants to merge 2 commits into
Conversation
abendrothj
force-pushed
the
bash-tool-hook-augment
branch
2 times, most recently
from
July 29, 2026 23:15
20a8cc1 to
f126bf7
Compare
Bash-based searches (rg, grep, ag, ack, ugrep, git grep) bypass hook-augment because the PreToolUse matcher only covers Grep/Glob. Detection lives in hook_augment itself, reusing the existing search_graph path without duplicating the resolver. - ha_tokenize: minimal shell tokenizer (quote/backslash handling, no evaluation) - ha_parse_bash_search_pattern: strips VAR=val prefixes and wrappers (env, nice, time, command, rtk, tokf run), identifies the binary, walks flags, bails on -f/--file and multiple -e, handles rtk grep -l <N> as value-taking - ha_tool_event_supported: Bash added alongside Grep/Glob for PreToolUse in HA_DIALECT_EVENT - ha_process: Bash branch routes tool_input.command through the extractor before the shared ha_extract_token + search_graph path Binaries covered: grep/egrep/fgrep, rg, ag, ack, ugrep/ug, git grep Wrappers covered: env, nice, time, command, rtk, tokf run Closes DeusData#1082 Signed-off-by: Jake Abendroth <contact@jakea.net>
Signed-off-by: Jake Abendroth <contact@jakea.net>
abendrothj
force-pushed
the
bash-tool-hook-augment
branch
from
July 29, 2026 23:16
dbbd5d9 to
eb12d6d
Compare
Author
|
The cppcheck failure is pre-existing in src/main.c lines 283 and 2049; introduced by a recent merge to main, not by this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1082.
What
Claude Code frequently runs searches through the
Bashtool (rg -n Foo .,grep -rn Foo ., etc.) rather than the nativeGrep/Globtools. Becausehook-augment'sPreToolUsematcher only coveredGrepandGlob, these searches silently bypassed graph augmentation.This PR adds detection directly in
hook_augmentitself (Q1 from my earlier comment — I went with the former approach since it reuses the existingsearch_graphpath without duplicating resolver logic). Pattern extraction happens via a small shell tokenizer and flag parser; the result feeds into the sameha_extract_token→search_graphpath Grep already uses.Approach
ha_tokenize— minimal shell tokenizer: whitespace split with'…'/"…"quoting and backslash handling. No evaluation, no expansion.ha_parse_bash_search_pattern— pure string parser, never touches the command:VAR=valueenv assignmentsenv,nice,time,command,rtk,tokf rungrep/egrep/fgrep,rg,ag,ack,ugrep/ug,git grep)-f/--file(pattern file), bails on multiple-e, handles embedded (-ePATTERN) and space-separated (-e PATTERN) formsgrep -A 5 PATTERNcorrectly skips5rtk grep -l <N>: treats-las value-taking (consumesN, arrives atPATTERN)ha_tool_event_supported—Bashadded alongsideGrep/GlobforPreToolUseinHA_DIALECT_EVENT.ha_process— Bash branch extracts pattern fromtool_input.command; everything after is identical to the Grep path.Scope (Q2)
grep/egrep/fgrep, rg, ag, ack, ugrep/ug, git grep — plus the wrapper handling dergachoff noted in the thread.
Testing
cli_hook_augment_bash_pattern_extractorintests/test_cli.ccovers: common invocation forms, value-taking flag skipping, env-var prefixes, all wrappers, thertk grep -l <N>case, bail-out cases (-f, multiple-e, non-search binary, empty/NULL), and--end-of-flags. Verified clean compile and production binary build on macOS; full test run blocked by an ASan/dyld hang on macOS 26 pre-release — CI should cover it.