Skip to content

fix(pi-fff): preserve path/exclude in fuzzy grep fallback (#697) - #699

Merged
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-697
Jul 23, 2026
Merged

fix(pi-fff): preserve path/exclude in fuzzy grep fallback (#697)#699
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-697

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #697

Root cause

packages/pi-fff/src/index.ts:727 invoked the fuzzy fallback with the raw pattern, discarding the constrained query built at src/index.ts:665-667 via buildQuery (src/query.ts:80). Since query is the only carrier of the normalized path include and !<exclude> clauses, the fallback searched the entire index — leaking matches from excluded directories or files outside the requested path.

Fix

Pass the constrained query to the fallback picker.grep call instead of pattern. The fallback still broadens matching (fuzzy vs. plain) but no longer broadens scope.

Steps to reproduce

Setup on origin/main (pre-fix):

git checkout 05a35c6d4856455393a2dc8aadaeae4b2823ddf6
cd packages/pi-fff

Fixture:

/tmp/fff-repro/
  target.json          # does not contain "needle"
  sessions/history.jsonl  # contains "needle"

Call ffgrep via pi-fff with:

{
  "pattern": "needle",
  "path": "/tmp/fff-repro/target.json",
  "exclude": "sessions/",
  "context": 0,
  "limit": 5
}

Actual (pre-fix):

[0 exact matches. Maybe you meant this?]
sessions/history.jsonl
  1: ...needle...

Expected:

No matches found

The sessions/ directory is explicitly excluded AND is outside the requested path (a specific file). The fuzzy fallback discarded both constraints because it re-ran with pattern (needle) rather than the constrained query (target.json !sessions/ needle).

How verified

  • Unit tests: bun test in packages/pi-fff/ — 44 pass, 0 fail.
  • Diff inspection: fallback now consumes the same query string as the primary search; the only difference between the two picker.grep calls is mode: "fuzzy" vs. the auto-detected mode.
  • Behavior under maintainer's original intent (broadening pattern matches across the workspace when no path/exclude is set) is preserved because buildQuery returns just pattern when no constraints are supplied.

Automated triage via Gustav. Honk-Honk 🪿

…back (#697)

The automatic fuzzy fallback in the pi-fff `grep` tool passed the raw
`pattern` to `picker.grep`, discarding the constrained `query` built via
`buildQuery`. As a result, the fallback ignored the caller's `path` and
`exclude` constraints and could return matches from explicitly excluded
directories or files outside the requested path.

Pass the constrained `query` to the fallback instead, so it only broadens
matching (fuzzy vs. plain) without broadening scope.

Closes #697
@dmtrKovalenko

dmtrKovalenko commented Jul 22, 2026

Copy link
Copy Markdown
Owner

@gustav-fff update the pr to preserve it ONLY if there is no extension (I mean when there is path like /some/file/path.ts INSIDE the cwd or any aux pickers we use the whole picker fuzzy match) but if there is a directory we use the standard aux picker finding and preserver the queries

When the caller pinned a specific file (path has an extension), the
fuzzy fallback broadens across the whole picker so a mistyped filename
can still surface matches. For directory constraints (or no path), keep
the constrained query so the fallback does not leak matches from
excluded / out-of-scope directories.
@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] DIRECTED: pushed d500af2.

Behavior split by the last segment of params.path:

  • File path (matches \.[a-zA-Z][a-zA-Z0-9]{0,9}$) — fuzzy fallback re-runs with the raw pattern, broadening across the whole picker (workspace or aux). Rationale: caller pinned a specific file that returned zero exact hits — likely misnamed — so widening scope is what the user wants.
  • Directory / glob / absent path — fuzzy fallback keeps the constrained query so it cannot leak from excluded dirs or out-of-scope trees.

Extension detection uses the same regex as normalizePathConstraint in packages/pi-fff/src/query.ts:49, so file vs. directory classification stays consistent across query build + fallback.

Tests: bun test in packages/pi-fff/ — 44 pass, 0 fail.

Honk-Honk 🪿

@dmtrKovalenko
dmtrKovalenko merged commit 829bfa9 into main Jul 23, 2026
52 checks passed
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.

[Bug]: pi-fff fuzzy fallback ignores path and exclude constraints

2 participants