fix(core): scope composite filesystem searches to requested paths
What changes
Fix composite filesystem grep/glob routing so a directory search only visits its own namespace. A /notes/ mount must not intercept /notes2; unrelated or missing scopes must not include every mount. Canonicalize dot segments before selecting a backend, include nested mounts and honor the longest-prefix ownership used for reads.
Relative globs are evaluated in the caller's search directory. For example, /notes + shared/*.txt finds /notes/shared/file.txt even though that child backend stores it as /file.txt.
Implementation
- Validate/canonicalize paths and select mounts at directory boundaries.
- Collect descendant mounts and exclude files hidden by a more specific mount.
- Translate literal directory prefixes and simple recursive globs before querying child backends; skip simple filename globs that cannot match descendants.
- For complex globs or overlapping mounts, identify visible matching files before grep runs. Query escaped literal file globs in bounded batches, so unrelated or shadowed matches cannot exhaust a backend's grep limit first.
- Add regressions with real in-memory and temporary native backends, plus a core patch changeset. No public API or dependency changes.
Validation
- Initial regression suite against unchanged main: 10 failed, 6 passed.
- Final capped-result regressions/controls against previous PR head
89cd3a2: 6 failed, 58 passed. The patched source was restored byte-for-byte afterwards. - Final filesystem suite: 69 passed across four files. Covers sibling prefixes, missing/root/relative/dot paths, nested ownership, directory globs, braces/extglobs, native file queries, escaped filenames, multiple batches and 5,000-result boundary cases.
- Core TypeScript check and ESM/CommonJS/declaration builds: passed.
- Public built-export checks: 56 standard + 14 capped-result checks passed across ESM and CommonJS imports.
- Biome for both changed TypeScript files, Prettier for the changeset, changeset release plan and
git diff --check: passed.
Boundaries
Complex patterns that cannot be safely projected into one backend glob still enumerate candidate files in the affected mount; this favors correct namespace matching over a custom glob parser. Common directory/recursive globs retain backend filtering. Bounded literal batches avoid unbounded generated glob strings.
Composite fallback glob matching uses micromatch with dotfile support, matching the in-memory utilities. Direct native-backend fast paths retain that backend's dotfile policy; this difference is documented on grepRaw rather than claiming all backends have identical defaults.
Offline validation only; no live provider or browser tests. Reused this task's existing dependency installation with the same lockfile. The full monorepo suite was not run.
Related issue: none; reproduced from current main and followed up on PR review findings. Prepared and validated with OpenAI Codex.
Summary by CodeRabbit
- Bug Fixes
- Filesystem searches now stay within the requested directory and correctly resolve paths containing dot segments.
- Searches include files from nested mounted directories, while respecting mount precedence and avoiding duplicate or shadowed results.
- Glob patterns now match relative to the requested search directory across mounted filesystems, including hidden files and supported brace patterns.
- Grep results are filtered to files visible within the requested scope before result limits are applied, preventing hidden or shadowed files from displacing matching results.