Skip to content

Add PathFilter module, PathFilter-based FileSystem.glob and IgnoreFile parsers - #10274

Merged
tim-smart merged 41 commits into
v4/next-minorfrom
agent/nelson-effect-bot/f5d6036722ef
Nov 8, 2026
Merged

tim-smart merged 41 commits into
v4/next-minorfrom
agent/nelson-effect-bot/f5d6036722ef

Conversation

@effect-bot

@effect-bot effect-bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Adds a general PathFilter module (unstable): an ordered list of exclusion and inclusion rules with a default for unmatched paths. FileSystem.glob now takes a single PathFilter.Input (a filter, a pattern, or patterns and rules) plus root, and derives its traversal from the rules. IgnoreFile (experimental) parses .gitignore and .dockerignore sources into PathFilters.

yield* fs.glob(["src/**/*.ts", "!**/*.test.ts"])

const ignored = Result.getOrThrow(IgnoreFile.dockerignore(source))
yield* fs.glob(PathFilter.restrict(PathFilter.select("**", { dot: true }), ignored), { root: context })

Model

The redesign follows prior art: ripgrep's ignore crate, git dir.c, moby patternmatcher with BuildKit fsutil, node-ignore and python pathspec.

  • A rule is Exclude or Include with:
    • a matcher: a Glob string or a custom PathMatcher;
    • directoryOnly;
    • a scope directory;
    • a subtree policy.
  • The last applicable rule wins, except that nothing inside a directory decided by a barrier exclusion can be included again.
  • subtree is the only place Git and Docker differ:
    • barrier: Git exclusions and the default for exclude.
    • inherit: Docker; a match on a directory also counts for everything inside it, if it changed the directory's result at that point in rule order (BuildKit's MatchesUsingParentResults).
    • self: Git ! and the default for include.
  • PathFilter.match returns None, Exclude or Include together with the rule that decided it. excludes is the boolean form.
  • Whether a path is a directory is an explicit { directory } argument; a trailing / means nothing.
  • Every filter has a default for paths no rule decides: make, empty and the IgnoreFile parsers keep them, while select builds a selection, which drops them. match returns None for such a path and excludes applies the default.
  • PathFilter.Input is a filter, a string, or an iterable of strings and rules. A string includes paths and a ! string excludes them (\! for a literal !). An input with at least one including string is a selection. Including strings skip dot names; ! strings match them. fromInput converts an input and returns a filter unchanged, with its default.
  • select(rules, { dot }) builds a selection from strings and rules; dot applies to its including strings.
  • restrict(self, by) (curried: restrict(by)(self)) keeps a path only when self keeps it and by doesn't exclude it. The two are evaluated separately, so an ignore file's !keep.log can't add a path the selection dropped. For match, the last restriction that excludes the path decides it, even through its default; otherwise self does.
  • concat appends the rules of two filters with the same default. Different defaults or a restricted operand are defects.
  • include and exclude take a PathMatcher overload, so a custom matcher's parameters are inferred.
  • Formats are only parsers, so another ignore format needs no changes to PathFilter or FileSystem.

FileSystem.glob

glob(input: PathFilter.Input, options?: { root }) finds the paths under root that the filter keeps. The pattern argument and the dot and exclude options are gone; composition lives in PathFilter.

yield* fs.glob("src/**/*.ts")
yield* fs.glob(["**/*.ts", "!**/*.test.ts"])
yield* fs.glob(PathFilter.restrict(PathFilter.select("**", { dot: true }), dockerignore), { root: context })
  • Results are relative to root, depth-first with entries sorted by name. root itself is never a result.
  • Traversal comes from the rules, evaluated separately for the filter and each restriction. A path is a result when every one of them keeps it. For each directory, each filter gives a verdict:
    • A barrier exclusion stops.
    • An included baseline lists the directory.
    • An excluded baseline continues only when a later inclusion can match below, from its scope or matchesBelow.
    • Literal names are probed instead of listed when every reachable inclusion is a Glob rule with only literal states, so glob("src/index.ts") reads no directory, as before. A custom matcher lists.
  • Links: rules see each entry's own type, so link/ never matches a link to a directory. A link is followed only for inclusions that reach it through explicit segments, never through **, a default or an inherited inclusion. Exclusions keep applying inside.
  • A single absolute string such as "/abs/dir/**" keeps its previous behavior: it ignores root, returns absolute paths, and dir/** includes dir. "/" and "/**" include the filesystem root. The pattern is compiled whole as a Glob pattern, as before, so braces, normalization and dropped branches behave the same; the walk starts at its filesystem root and looks up its leading literal names. Absolute patterns anywhere else (in a list, after !, in select or restrict), .. segments, escaped / and UNC paths make the effect die.

Breaking (minor, FileSystem is unstable)

Before After
fs.glob("**/*.ts") unchanged
fs.glob(p, { dot: true }) fs.glob(PathFilter.select(p, { dot: true }))
fs.glob(p, { exclude: ["**/*.test.ts"] }) fs.glob([p, "!**/*.test.ts"])
fs.glob("../a/*.ts", { root }) fs.glob("*.ts", { root: path.join(root, "../a") })
fs.glob(".") fs.exists(root)

fs.glob("/abs/dir/**") itself is unchanged; fs.glob("/abs/dir/**", { dot: true }) becomes fs.glob(PathFilter.select("**", { dot: true }), { root: "/abs/dir" }) with relative results. Moving a prefix into root also drops that directory from the results, since root is never a result. A directory-only pattern such as link/ no longer matches a link to a directory. Everything else about string patterns is unchanged: results, ordering, the spelling of probed names, and read-error handling. The differential check below covers this.

IgnoreFile

  • gitignore(source, { scope? }) returns a PathFilter and never fails; as in Git, a malformed line matches nothing.
  • dockerignore(source) returns Result<PathFilter, ParseError>.
  • Combine nested .gitignore files with PathFilter.concat, giving each one its directory as scope, and remove what they ignore from a selection with PathFilter.restrict.
  • The parsers, the Docker state-set matcher and the documented deviations and rejections carry over from the previous version of this PR.
  • Docker's matchesBelow hint uses BuildKit's rule for skipping directories, applied per pattern. It strips only one trailing /** or /*, so !d/*/** still keeps d/sub/keep reachable.

BuildKit compatibility

Docker rules follow BuildKit's walk (tonistiigi/fsutil MatchesUsingParentResults), not moby's MatchesOrParentMatches: a pattern that repeats a directory's result so far is not passed down, so d, !d/keep, d keeps d/keep. Directory skipping starts from the inherited exclusion, so glob still reads d there.

The one intended difference is the single trailing-glob strip above: BuildKit strips both from !node_modules/*/** and drops node_modules/pkg/index.ts; this keeps it.

Validation

  • Tests:
    • Node: PathFilter, IgnoreFile, Glob, FileSystem and NodeFileSystem, 278 tests.
    • Bun: NodeFileSystem, PathFilter, IgnoreFile and FileSystem, 245 tests.
    • Deno: DenoFileSystem, PathFilter, IgnoreFile and FileSystem, 198 tests and 1 skipped.
    • Type tests for PathFilter and FileSystem on TypeScript 5.9 and 6.0. The flat moby patternmatcher_test.go table is unchanged.
  • Repo checks: pnpm check, pnpm lint, pnpm jsdocs --check, pnpm circular and the doctests (23) pass.
  • Differential checks (outside the repo):
    • String patterns against the previous walker (58b3ad4086): random trees with dot names, nested directories, a link to a directory and a dangling link, and random patterns (braces, classes, **, .*, escapes, trailing /) with and without dot and a gitignore filter. About 22,500 comparisons across typed and untyped (Unknown) listings: identical, apart from 80 cases of a trailing-/ pattern meeting the link, the documented link/ change.
    • Earlier rounds, still covered by the unchanged tests: dockerignore against BuildKit's walk (120,000 path checks and 1,500 real-tree filters, 0 mismatches), PathFilter.match against an independent evaluator, and Docker/Git oracles for IgnoreFile.

Closes EFF-3231

@changeset-bot

changeset-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 65bf0c3

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

This PR includes changesets to release 33 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator 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

@effect-janitor effect-janitor Bot added the 4.0 label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.71 KB 39.71 KB 0.00 KB (0.00%)
basic.ts 7.35 KB 7.35 KB 0.00 KB (0.00%)
batching.ts 11.29 KB 11.29 KB 0.00 KB (0.00%)
brand.ts 7.00 KB 7.00 KB 0.00 KB (0.00%)
cache.ts 11.83 KB 11.83 KB 0.00 KB (0.00%)
config.ts 23.16 KB 23.16 KB 0.00 KB (0.00%)
differ.ts 22.30 KB 22.30 KB 0.00 KB (0.00%)
http-client.ts 27.43 KB 27.43 KB 0.00 KB (0.00%)
http-router.ts 37.30 KB 37.30 KB 0.00 KB (0.00%)
logger.ts 12.28 KB 12.28 KB 0.00 KB (0.00%)
metric.ts 9.74 KB 9.74 KB 0.00 KB (0.00%)
optic.ts 7.21 KB 7.21 KB 0.00 KB (0.00%)
pubsub.ts 16.34 KB 16.34 KB 0.00 KB (0.00%)
queue.ts 13.20 KB 13.20 KB 0.00 KB (0.00%)
schedule.ts 12.07 KB 12.07 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.33 KB 14.33 KB 0.00 KB (0.00%)
schema-binary.ts 42.48 KB 42.48 KB 0.00 KB (0.00%)
schema-class.ts 22.05 KB 22.05 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.00 KB 30.00 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.32 KB 28.32 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.64 KB 15.64 KB 0.00 KB (0.00%)
schema-string.ts 12.53 KB 12.53 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.51 KB 16.51 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.26 KB 39.26 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.46 KB 26.46 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.21 KB 21.21 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.38 KB 21.38 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.47 KB 21.47 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.47 KB 26.47 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.54 KB 21.54 KB 0.00 KB (0.00%)
schema.ts 21.14 KB 21.14 KB 0.00 KB (0.00%)
stm.ts 14.50 KB 14.50 KB 0.00 KB (0.00%)
stream.ts 10.66 KB 10.66 KB 0.00 KB (0.00%)
supervisor.ts 11.61 KB 11.61 KB 0.00 KB (0.00%)

@effect-bot effect-bot changed the title Add Ignore module and FileSystem.glob ignore option Add IgnoreFile module and FileSystem.glob ignore option Nov 2, 2026
@fubhy

fubhy commented Nov 2, 2026

Copy link
Copy Markdown
Member

@effect-bot This is garbage. Try again. Review prior art. Build a good general abstraction first before implement concrete ignore file formats.

@effect-bot

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, @fubhy. I've added it to the tracking issue (EFF-3231). The rework will start with a review of prior art and a general exclusion abstraction, and the concrete .gitignore/.dockerignore formats will be built on top of it afterwards. The design proposal will be posted before anything is reimplemented.

@effect-bot effect-bot changed the title Add IgnoreFile module and FileSystem.glob ignore option Add PathFilter module, FileSystem.glob filter option and IgnoreFile parsers Nov 2, 2026
@effect-bot
effect-bot force-pushed the agent/nelson-effect-bot/f5d6036722ef branch from eb0987f to 36834ed Compare November 2, 2026 22:32
@fubhy

fubhy commented Nov 4, 2026

Copy link
Copy Markdown
Member

@effect-bot instead of glob using a path finder as a filter option, would it not make sense to derive a globber from a path finder so that it can more efficiently traverse?

@effect-bot

Copy link
Copy Markdown
Contributor Author

Good point. I've added it to the rework in EFF-3231.

On this PR, glob doesn't filter results afterwards. The walk steps the filter one path segment per entry, alongside the glob automaton (visit in internal/glob.ts, step in internal/pathFilter.ts). It also stops reading a directory once nothing below it can be included. So it already skips directories. Doing what you suggest would still help in these ways:

  • Per-entry cost: each rule keeps its own automaton and is stepped separately, so each entry costs O(rules). A walker built from the filter could compile all rules into one combined automaton, like ripgrep's GlobSet in ignore::WalkBuilder.
  • API: the filter really decides the walk, and the pattern is secondary. As an option on glob, it needs special rules: absolute patterns and .. are defects only when filter is set, and an inclusion never brings back a path the pattern dropped. Deriving the walker from the filter would make that relationship explicit.
  • Nested ignore files: a walker that owns the filter can find and add nested .gitignore files as it goes down. A fixed filter passed to glob can't do that.

The design proposal will cover deriving the walker from a PathFilter. It will also say whether FileSystem.glob's filter option should stay as a shorthand over that walker.

@fubhy

fubhy commented Nov 4, 2026

Copy link
Copy Markdown
Member

@effect-bot Alternatively, we could replace exclude and dot with this and just use this new filtering api with the Fs.Glob. ./cc @tim-smart

@effect-bot

Copy link
Copy Markdown
Contributor Author

Thanks. I've added this to the rework in EFF-3231, next to the "derive the walker from the filter" idea, because the two choices depend on each other.

Some initial notes:

  • Compatibility: FileSystem.glob with root, exclude and dot is already in stable effect 4.1.x. Removing the options would be a breaking change. To avoid one, exclude could become shorthand for PathFilter exclusion rules and be deprecated later if we want the filter to be the only API. That decision is for the maintainers (cc @tim-smart, as you mentioned).
  • exclude maps onto PathFilter directly. Its patterns already match dot-names and prune excluded directories, the same as a barrier exclusion.
  • dot is harder, because it isn't really a filter. It changes what the pattern matches: a wildcard segment skips names that start with . unless that pattern segment itself starts with ., so .github/** still matches with dot: false. A filter applied after matching can't express "hidden unless the pattern named it". It either stays a pattern option, or PathFilter gets a "hidden entries" rule with defined behaviour for literal dot segments.

The design proposal will cover whether glob keeps exclude/dot, turns them into shorthands over PathFilter, or deprecates them.

@effect-bot
effect-bot changed the base branch from main to v4/next-minor November 4, 2026 18:12
@effect-janitor effect-janitor Bot removed the 4.0 label Nov 4, 2026
@fubhy

fubhy commented Nov 4, 2026

Copy link
Copy Markdown
Member

@effect-bot but even the pattern itself could be expressed as a PathFilter with include rules. So should we not replace that whole thing?

@effect-bot

Copy link
Copy Markdown
Contributor Author

Yes. A glob pattern is just an include rule, and I think the design should go this way. Then pattern, exclude and dot all become rules in one ordered list, and the walker has a single input. There's prior art for this: ripgrep's ignore::overrides (-g globs, where any glob without ! turns on whitelist mode), rsync's --include/--exclude filter lists, fast-glob/globby pattern arrays with ! negations, and Bazel's glob(include, exclude).

It also fixes the dot problem from my last comment. "Hidden unless the pattern named it" can't be done by a filter that runs after matching. It's easy as an option on the include rule's own matcher, and PathFilter.include in this PR already takes a dot option.

PathFilter would need a few things before it can replace the pattern:

  1. Default result. An ignore filter keeps paths no rule matches. A selection drops them. A filter needs an explicit default, or ripgrep's rule: once any include rule exists, unmatched paths are dropped. Without that, users must write exclude("**") first and get its subtree right.
  2. Descent separate from selection. In whitelist mode most directories match no include rule themselves, but they must still be read when a match could be below them. This is the classic rsync mistake: forgetting --include='*/' before --exclude='*'. The walker would rely on matchesBelow for every include rule, and a custom PathMatcher without it would make it read the whole tree.
  3. Start points. A pattern's leading literal segments (packages/*/src/**) let the walk stat its way in instead of reading everything from root. A walker built from a filter would have to work out those base directories from the include rules, as fast-glob does for each pattern. Otherwise it would be slower than glob is today.
  4. Paths relative to the root only. Rules are relative to root, so absolute patterns and ../ would have to move into root. This PR already has the same restriction whenever filter is set.
  5. Directories in results. A pattern like src/* also returns directories. The walker needs an explicit choice: files only, directories too, or controlled through directoryOnly rules.

Compatibility: FileSystem.glob(pattern, { root, exclude, dot }) is stable in 4.1.x, so I'd keep it as a thin wrapper instead of removing it:

// glob(pattern, { root, dot, exclude }) would mean: walk `root` with
PathFilter.make([
  PathFilter.include(pattern, { dot }),
  ...exclude.map((p) => PathFilter.exclude(p))
])

The primitive underneath would be a walker driven by a PathFilter. That matches your earlier point about deriving the walker from the filter. IgnoreFile output, nested ignore-file discovery and multiple patterns would all plug into that one place.

I've added this to the design work in EFF-3231. The proposal will cover making PathFilter (with a default result) the only input to the walker, with glob as a shorthand over it. Whether to later deprecate glob's own options is a decision for the maintainers.

@fubhy

fubhy commented Nov 4, 2026

Copy link
Copy Markdown
Member

@effect-bot glob is not marked stable. It's unstable.

@effect-bot

Copy link
Copy Markdown
Contributor Author

You're right, sorry, that was wrong. The FileSystem module and its service are marked @stability unstable (packages/effect/src/FileSystem.ts:11 and :77), and that includes glob. This PR's own description already treats removing exclude as a minor change for that reason.

So my compatibility point doesn't apply. We don't need to keep glob(pattern, { root, exclude, dot }) as a thin wrapper. glob's signature can change directly, with a PathFilter (with a default result) as the walker's only input, and the change can ship in a minor release with a migration note. Whether to keep a pattern shorthand is now only a question of convenience, not compatibility.

I've corrected this in EFF-3231 so the design proposal drops the wrapper requirement.

@effect-bot
effect-bot force-pushed the v4/next-minor branch 10 times, most recently from 7997bf7 to d64bb9a Compare November 5, 2026 08:35
effect-bot and others added 5 commits November 8, 2026 06:57
The rest of an absolute pattern keeps its positive, root-relative meaning:
a leading ! or drive-shaped name is escaped and leading empty segments are
dropped. The literal prefix stops at a decoded / so escaped separators
are still rejected, and / or /** return the filesystem root again.
A single absolute string is compiled as one Glob pattern, stepped past
its filesystem root and walked from there, so braces, normalization and
root matches follow the compiler. This drops the lexical prefix split and
its escapes, and shares the .. and escaped / check with filter rules.
The adapter passed a hand-written include rule to select, repeating the
constructor's defaults. It now hands the compiled matcher to include.
@effect-bot
effect-bot force-pushed the agent/nelson-effect-bot/f5d6036722ef branch from 435662d to 65bf0c3 Compare November 8, 2026 06:57
@tim-smart
tim-smart merged commit 814015e into v4/next-minor Nov 8, 2026
14 checks passed
@tim-smart
tim-smart deleted the agent/nelson-effect-bot/f5d6036722ef branch November 8, 2026 07:22
tim-smart added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 16, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 17, 2026
effect-bot added a commit that referenced this pull request Nov 18, 2026
effect-bot added a commit that referenced this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants