-
Notifications
You must be signed in to change notification settings - Fork 525
dofs: Add exclusions to recursive grep #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aron-cf
wants to merge
1
commit into
main
Choose a base branch
from
grep-exclude
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| "@cloudflare/dofs": minor | ||
| "@cloudflare/computer": minor | ||
| --- | ||
|
|
||
| Add an `exclude` option to `fs.grep`, matching `fs.find` | ||
|
|
||
| `find` could already prune directories from a traversal but `grep` could not, so | ||
| there was no way to search a workspace while skipping `node_modules` — the one | ||
| thing callers most often want to skip. The exclusion globs are passed to the | ||
| same find walker `grep` already traverses with, so an excluded directory is | ||
| pruned before its children are queried rather than being read and filtered. | ||
|
|
||
| ```ts | ||
| const todos = await workspace.fs.grep("TODO", "/", { | ||
| include: "**/*.ts", | ||
| exclude: ["node_modules", "node_modules/**"], | ||
| }); | ||
| ``` | ||
|
|
||
| Exclusion is matched against the same directory-relative path as `include` and | ||
| applied first, so an exclusion always wins. As with `find`, name both the | ||
| directory and its contents to prune the subtree: `node_modules/**` matches what | ||
| is below `node_modules`, not `node_modules` itself. Grepping a single file | ||
| ignores `exclude`, since the caller named the file and there is no traversal to | ||
| prune. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ interface GrepOptions { | |
| limit?: number; | ||
| offset?: number; | ||
| include?: string; | ||
| exclude?: string[]; | ||
| } | ||
|
|
||
| export interface GrepWorkspaceLike { | ||
|
|
@@ -43,6 +44,12 @@ const inputSchema = z.object({ | |
| .string() | ||
| .optional() | ||
| .describe('Glob relative to path that limits searched files, for example "**/*.ts".'), | ||
| exclude: z | ||
| .array(z.string()) | ||
| .optional() | ||
| .describe( | ||
| 'Glob patterns to leave out, for example ["node_modules/**", "**/.git/**"]. An excluded directory is skipped along with everything below it.', | ||
| ), | ||
|
Comment on lines
+47
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Agent-tool docs omit The dedicated grep tool interface still omits Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| regex: z.boolean().optional().describe("Interpret query as a regular expression."), | ||
| ignoreCase: z.boolean().optional().describe("Ignore letter case."), | ||
| context: z.number().int().min(0).max(10).optional(), | ||
|
|
@@ -55,7 +62,17 @@ export function createGrepTool(options: GrepToolOptions): Tool<z.infer<typeof in | |
| description: | ||
| "Search workspace text with a literal string or regular expression. Results include paths and line numbers and can include surrounding lines.", | ||
| inputSchema, | ||
| execute: async ({ path, query, include, regex, ignoreCase, context, limit, offset }) => { | ||
| execute: async ({ | ||
| path, | ||
| query, | ||
| include, | ||
| exclude, | ||
| regex, | ||
| ignoreCase, | ||
| context, | ||
| limit, | ||
| offset, | ||
| }) => { | ||
| try { | ||
| const pageSize = limit ?? DEFAULT_LIMIT; | ||
| const pageOffset = offset ?? 0; | ||
|
|
@@ -67,6 +84,7 @@ export function createGrepTool(options: GrepToolOptions): Tool<z.infer<typeof in | |
| const matches = await options.workspace.fs.grep(query, path, { | ||
| ...searchOptions, | ||
| include, | ||
| exclude, | ||
| limit: pageSize + 1, | ||
| offset: pageOffset, | ||
| }); | ||
|
|
||
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
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
Oops, something went wrong.
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.
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.
🔍 Tool contract omits
excludeThe exported
WorkspaceLikestill modelsgrepwithoutexclude. Update this structural contract alongside the new agent-tool option.Was this helpful? React with 👍 or 👎 to provide feedback.