fix(grep): hint when a zero-result literal search looks like a regex#47
Merged
Conversation
aden grep matches literal substrings by default; regex is opt-in
(regex=true). A pattern like `Ready|ready` passed without that flag is
searched literally — pipe and all — and matches nothing. A human sees the
empty result and adjusts, but an agent consuming `{"total": 0}` concludes
the term is absent and acts on it. That exact footgun produced a
false-negative "aden ready doesn't exist" in this repo.
Keep the literal-default semantics (changing them would break literal
searches for code like `a|b` or `foo()`), but stop the silent miss: when a
zero-result search ran in literal mode and the pattern carries regex
metacharacters (| [ ( \ .* .+), emit a hint to retry with regex=true (or
ignore_case=true). Surfaced in both the human output and the JSON envelope
as a new `hint` field that is present ONLY when firing, so a successful
search is never cluttered and existing consumers are unaffected.
looks_like_regex deliberately skips bare . * + ? — they appear in literal
code searches too often to be a reliable signal. Unit tests cover both the
flagged idioms and the literals that must stay quiet.
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.
Summary
Root-causes and fixes a silent false-negative in
aden grepthat I tripped over while auditing docs (it produced a wrong "aden readydoesn't exist" conclusion).What happened:
aden grepmatches literal substrings by default; regex is opt-in (regex=true). A pattern likeReady|readypassed without that flag is searched literally — pipe included — and matches nothing. A human sees the empty terminal and self-corrects; an agent consuming{"total": 0}concludes the term is absent and acts on it.Confirmed with a controlled experiment:
"Ready|ready",regex:false(default)"Ready|ready",regex:true"ready",ignore_case:trueThe fix keeps literal-default semantics (auto-promoting to regex would break literal searches for code like
a|borfoo()), but stops the silent miss: when a search returns zero results in literal mode and the pattern carries regex metacharacters (| [ ( \ .* .+), emit a hint to retry withregex=true(orignore_case=true). Surfaced in both human output and the JSON envelope as a newhintfield — present only when firing, so successful searches are unchanged and existing consumers are unaffected.looks_like_regexdeliberately skips bare. * + ?(too common in literal code searches to be a reliable signal). Unit tests cover both the flagged idioms and the literals that must stay quiet.Verified end-to-end on the built binary:
total:0+hint--regex→ 8 matches, no hintKnown follow-up (not in this PR)
Separately noticed: the
[PATH]argument scopes only project-root discovery, not the search —grep <pat> some/file.rsstill searches the whole project (and can dump megabytes when it matches minified asset lines). Filed for its own investigation; not touched here.Test plan
cargo test -p aden-cligreen (newflags_regex_idioms/ignores_plain_literalspass)cargo clippy --workspacecleancargo fmt --allappliedLicense checklist