Skip to content

bash_rewrite: stop the grep footer firing on single-file, external, and fresh targets - #176

Draft
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:fix/grep-footer-suppression
Draft

bash_rewrite: stop the grep footer firing on single-file, external, and fresh targets#176
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:fix/grep-footer-suppression

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Aug 2, 2026

Copy link
Copy Markdown

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:

  • a single named file — grep -n foo src/app.ts isn't a tree search
  • a path outside the indexed project root, like a scratch file in /tmp
  • a file written seconds ago, before the index has caught up

On 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_footer in bash_rewrite covers commands the Rust rewrite handles. maybeAppendGrepSearchHint in aft-bridge/src/bash-hints.ts covers the ones it rejects — including anything piped, since the rewrite bails on pipes.

Fixing only the Rust side leaves this split:

grep -n foo src/app.ts            → silent
grep -n foo src/app.ts | head -5  → still lectured

So both paths got the same conditions. The TS side already handled the outside-root case, including cd tracking across statements; only the file and freshness conditions were added there.

Two things worth flagging:

  • The 60s window is now a constant in each language and they can drift apart. Sharing it across the FFI boundary looked worse than the duplication, but say the word if you'd rather have it derived.
  • bash-hints.ts was pure and now calls fs.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.rs and five in bash-hints.test.ts, covering each condition and its negative.

Two existing e2e fixtures needed their target directory backdated. They build a tempdir milliseconds 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_rewrite 12 unit + 20 integration; cargo test --lib 2142; aft-bridge 415; plugin suites at baseline.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with 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

    • Suppress footer when: the target is an existing file, resolves outside the project root, or was modified within 60s (directories included).
    • Apply the same logic in Rust (bash_rewrite footer) and in TS (@cortexkit/aft-bridge piped/rejected greps).
    • Tree searches under the project keep the footer; missing paths and errors keep it.
    • Multi-operand greps suppress if any operand is an existing file.
    • No change to rewrite routing or results; only the appended hint behavior.
  • Tests

    • Added unit tests in Rust and TS for all conditions.
    • Updated e2e fixtures to backdate directories to avoid accidental freshness suppression.

Written for commit b9d7ef8. Summary will update on new commits.

Review in cubic

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.

1 participant