Skip to content

dofs: Add exclusions to recursive grep - #150

Open
aron-cf wants to merge 1 commit into
mainfrom
grep-exclude
Open

aron-cf wants to merge 1 commit into
mainfrom
grep-exclude

Conversation

@aron-cf

@aron-cf aron-cf commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Add exclude to grep.

await fs.grep("TODO", "/workspace", {
  exclude: ["node_modules", "node_modules/**"],
});

Combine with include — exclusion is applied first, so it always wins:

await fs.grep("TODO", "/workspace", {
  include: "**/*.ts",
  exclude: ["**/*.test.ts"],
});

Several subtrees at once:

await fs.grep("deprecated", "/workspace", {
  exclude: ["node_modules", "node_modules/**", "dist", "dist/**"],
});

Same option on the agent-facing tool, matching the one find already exposes:

{ "path": "/workspace", "query": "TODO",
  "include": "**/*.ts", "exclude": ["node_modules/**"] }

Devin Review

find could prune directories from a traversal but grep could not, so
there was no way to search a workspace while skipping node_modules --
the thing callers most often want to skip. A caller could pass include
to name what they wanted, but not exclude to name what they did not.

grep already delegates its traversal to find's walker via
iterateFoundEntries, which has accepted exclusion globs since find
gained them. So this passes them through rather than reimplementing
matching: an excluded directory is pruned before its children are
queried, instead of being walked and read with its matches discarded
afterwards.

Semantics follow find exactly, because sharing the walker means sharing
its rules: globs match the directory-relative path, exclusion is applied
before inclusion so it always wins, and a subtree needs both forms
(node_modules and node_modules/**) since /** matches what is below a
directory rather than the directory itself. A single-file search ignores
exclude -- the caller named the file and there is no traversal to prune.

The pruning test asserts the query count rather than just the results,
because filtering after the walk would produce identical matches while
still paying for the excluded tree. Writing it first with only
'vendor/**' showed the walker descending and excluding each child, which
is what pinned the both-forms requirement.

Also threads exclude through the computer-level grep tool, matching the
option find's tool already exposes.
@changeset-bot

changeset-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ddebdd3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@cloudflare/dofs Minor
@cloudflare/computer Minor
@cloudflare/computer-rpc Minor
@cloudflare/computerd Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Devin Review

limit?: number;
offset?: number;
include?: string;
exclude?: string[];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Tool contract omits exclude

The exported WorkspaceLike still models grep without exclude. Update this structural contract alongside the new agent-tool option.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +47 to +52
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.',
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Agent-tool docs omit exclude

The dedicated grep tool interface still omits exclude. Consumers relying on the tool contract cannot discover it.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@pkg-pr-new

pkg-pr-new Bot commented Sep 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@150

commit: ddebdd3

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