bash_rewrite: stop the grep footer firing on single-file, external, and fresh targets - #176
Draft
iceteaSA wants to merge 1 commit into
Draft
bash_rewrite: stop the grep footer firing on single-file, external, and fresh targets#176iceteaSA wants to merge 1 commit into
iceteaSA wants to merge 1 commit into
Conversation
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.
The "DO NOT search code by running grep/rg in bash" footer is unconditional, so it also fires on greps where the indexed tool has nothing to add:
grep -n foo src/app.tsisn't a tree search/tmpOn a busy day that's most of the times it appears, which trains agents to hesitate on searches that were fine. The footer is also appended to output that already went through the indexed grep tool — the rewrite happened, then the result gets told not to do what it just did.
Change
Suppress the footer when the target is an existing file, resolves outside the project root, or has an mtime inside a 60s window. Tree searches over indexed project paths keep it, which is the case the footer exists for. Errors and missing paths keep it too.
Nothing about the rewrite changes — same routing, same results, only the appended hint.
The mtime condition does real work on directories: a directory whose mtime moved recently had files added or removed, so the index may lag and a tree search there is reasonable.
Two implementations, both needed
add_grep_footerinbash_rewritecovers commands the Rust rewrite handles.maybeAppendGrepSearchHintinaft-bridge/src/bash-hints.tscovers the ones it rejects — including anything piped, since the rewrite bails on pipes.Fixing only the Rust side leaves this split:
So both paths got the same conditions. The TS side already handled the outside-root case, including
cdtracking across statements; only the file and freshness conditions were added there.Two things worth flagging:
bash-hints.tswas pure and now callsfs.statSync— one guarded stat per in-project operand, and any throw keeps the footer.For multi-operand greps like
grep foo src/app.ts src/, an explicit file suppresses. Naming a file is the signal that this isn't a tree search.Tests
Six unit tests in
rules.rsand five inbash-hints.test.ts, covering each condition and its negative.Two existing e2e fixtures needed their target directory backdated. They build a
tempdirmilliseconds before asserting, so the directory is newborn and now suppresses under the freshness rule — an artifact of the fixture, not of the behavior being tested. Backdating restores what they were written to check.cargo test bash_rewrite12 unit + 20 integration;cargo test --lib2142; aft-bridge 415; plugin suites at baseline.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Stop showing the grep/rg warning footer on single-file, external, or freshly modified targets. The hint still appears for tree searches in the indexed project where it's useful.
Bug Fixes
bash_rewritefooter) and in TS (@cortexkit/aft-bridgepiped/rejected greps).Tests
Written for commit b9d7ef8. Summary will update on new commits.