Skip to content

dofs: Add exclusions to recursive grep - #150

Merged
aron-cf merged 4 commits into
mainfrom
grep-exclude
Sep 21, 2026
Merged

aron-cf merged 4 commits 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: 301ada1

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 Patch
@cloudflare/computer Patch
@cloudflare/computer-rpc Patch
@cloudflare/computerd Patch

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[bot]

This comment was marked as resolved.

@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: e19388c

Review caught two places the new option was missing from contracts a
consumer actually reads.

tools/fs/store.ts declares WorkspaceLike by inlining the grep options
rather than importing GrepOptions, so it kept typechecking while
silently not admitting exclude. A caller holding that structural type
could not pass the option the tool now accepts.

docs/09_tool_interface.md documents exclude under find but not grep, so
the two tools read as if only one supports pruning. Adds the field and
states the semantics it shares with find, including the both-forms
requirement.

Also drops PR.md, which was a description for review rather than
repository content.

Note: the same inlined WorkspaceLike omits exclude from find too, which
predates this change and is left alone here.
@aron-cf
aron-cf merged commit e5e28a7 into main Sep 21, 2026
15 of 16 checks passed
@aron-cf
aron-cf deleted the grep-exclude branch September 21, 2026 18:17
@github-actions github-actions Bot mentioned this pull request Sep 21, 2026
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