GeezerVison is showing github.com — fix(core): omit grep matches from files whose read is not allowed by knp-sap · Pull Request #64625 · anomalyco/opencode
Conversation
knp-sap
commented
Nov 18, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Part of #64059: the grep half. I first filed this as #64623, which was closed as a duplicate of #64059.
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
grep asked only for its own permission and then quoted lines from every matching file. Files whose read rule asks or denies, such as .env under the default agent rules, were shown without asking.
Grep now checks each matched file's read rule with permission.allows, as the read tool already does for its path suggestions, and returns matches only from files that are allowed without asking. The output says how many files were left out, and a truncated result says how many of the searched matches it shows, so the model can still use read, which asks, or narrow the search.
The tools docs now say so too.
No feature flag: this is a bug fix.
How did you verify your code works?
- New test in
packages/core/test/tool-search.test.ts using the default agent rules: matches in .env and local.env.production are left out, while notes.txt and sample.env.example are returned. A second test covers a truncated search whose matches were all left out. Both fail without the fix.
- In
packages/core: bun run script/test.ts (7562 pass, 0 fail), bun typecheck, and bun run typecheck:tsc.
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #64059
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Grep checked only its pattern, so it quoted lines from files that the read rules deny or ask for, such as .env under the default agent rules. Return matches only from files whose read is already allowed, and tell the model how many files were omitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix works. I reproduced it in the TUI with the simulated model and read *.env: ask: on the base, grep returned API_KEY=example-value from .env to the model. With this PR, only notes.txt is returned, plus the omitted-files note. The new test fails on the base and passes here, and tsc -b passes.
Public API is unchanged. The only output change is the new note in the grep tool's model content.
One behaviour change maintainers should know about: ask is treated like deny and the file is left out without a prompt, which matches the read tool's path suggestions. Users with a global read: ask will now get only the omitted note from grep. I think that's the right trade-off for a search tool, but it should be a deliberate choice.
One inline point: the match limit is applied before filtering.
Related: #64059
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
}),
|
|
|
)
|
|
|
// Matches quote file contents, so only files the read rules already allow are returned.
|
|
|
const files = [...new Set(result.items.map((match) => path.resolve(cwd, match.entry.path)))]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering happens after ToolSearch.bounded has applied the limit, so omitted files still count toward it. In a repo with many .env* matches, the readable results can be well under limit even though more readable matches exist. The truncation note then says showing first N results with N counting only the files that were kept. Could the truncation message (or the counts) take omitted matches into account, e.g. by reporting the omitted count next to the truncation so the model knows to narrow the search instead of assuming it saw everything?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done in 899197e. When a truncated search left files out, the note now says how many of the searched matches are shown, for example "showing 3 of the first 100 results", next to the omitted-files note, so the model knows to narrow the search. A new test covers a truncated search whose matches were all left out.
On ask being treated like deny: that is deliberate. Prompting for each matched file would turn one search into many prompts, and the model can still read a file it needs, which asks. It is the same rule the read tool uses for its path suggestions.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commit only updates tools.mdx, and the added text matches the new grep behaviour. The code is unchanged, so my earlier check still applies. The point about the match limit being applied before unreadable files are left out is still open.
Public API is unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The result limit applies before unreadable files are left out, so a truncated grep could show far fewer matches than it searched while claiming to show the first N. Say how many of the searched matches are shown, so the model knows to narrow the search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The truncation note now reports matches shown out of those searched when files were left out, which addresses my earlier thread. The counts are correct: searched is taken after ToolSearch.bounded applies the limit. The note is unchanged when nothing was truncated, and the new test is small and clear. Tests and tsc -b pass. Treating ask as deny is a reasonable choice and matches the read tool's path suggestions.
Public API is unchanged.
Related: #64059
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|