Skip to content

fix(discover): handle Windows paths in command and path normalization - #3617

Open
rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:fix/windows-path-normalisation
Open

rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:fix/windows-path-normalisation

Conversation

@rhishi99

Copy link
Copy Markdown
Contributor

Problem

Two path helpers assume Unix separators, so on Windows input they silently do nothing.

strip_absolute_path (src/discover/registry.rs) normalizes /usr/bin/grep -rn foo → grep -rn foo so a command invoked by absolute path still classifies (#485). It tests only for /, so:

C:\Windows\System32\cmd.exe   →  unchanged  →  command not recognized

That is exactly the case where an agent is most likely to use a full path.

compact_path shortens paths for display by splitting on /. A backslash path has no / to split on, so it stays full length — the entire purpose of the helper, cutting output width, is lost on Windows.

Fix

New core::path_utils module that splits on either separator and understands drive letters and UNC prefixes. Unix input comes out byte-identical — the Unix behaviour is covered by its own tests.

It also removes a duplicate: the same compact_path body existed in three places (system/search.rs, python/ruff_cmd.rs, system/format_cmd.rs). All three now call one implementation.

Note

An is_absolute_path helper was written alongside these and is not included — nothing calls it, and shipping an unused public function with #[allow(dead_code)] is not worth the surface.

Testing

Unit tests in path_utils cover both separators, drive letters, UNC paths, relative paths, and the existing Unix cases (test_strip_absolute_path_unix, test_normalize_path_unix/_windows, test_path_basename, plus the compact_path cases).

Full suite on x86_64-pc-windows-gnu: 2623 passed. cargo fmt --check and cargo clippy --all-targets clean. The single unrelated failure on this toolchain is the code-page assertion fixed in #3615.

🤖 Generated with Claude Code

Two path helpers assumed Unix separators and silently did nothing on
Windows input.

`strip_absolute_path` normalizes `/usr/bin/grep -rn foo` to `grep -rn
foo` so a command invoked by absolute path still classifies. It only
looked for `/`, so `C:\Windows\System32\cmd.exe` passed through
unstripped and the command went unrecognized -- exactly the case where
an agent is most likely to use a full path.

`compact_path` shortens paths for display by splitting on `/`, so a
backslash path stayed full length: the whole point of the helper, cutting
output width, was lost on Windows.

Both now live in a new `core::path_utils` module that splits on either
separator, understands drive letters and UNC prefixes, and leaves Unix
input byte-identical. Three copies of the same `compact_path` body
(search, ruff, black/format) collapse onto it.

The `is_absolute_path` variant was dropped rather than moved: nothing
called it.

Co-Authored-By: Claude Opus 5 <[email protected]>
@CLAassistant

CLAassistant commented Aug 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

aeppling pushed a commit that referenced this pull request Sep 1, 2026
…eled

`configuration.md` said an excluded tool "is covered however it is invoked".
The stated limits then covered only tools without their own filter, and exactness
— leaving three invocation forms of *filtered* tools promised but not delivered.

Scope the sentence to the wrapper, interpreter and path spellings that are
actually peeled, and table the three that are not, each with its cause:

- `head -20 f` / `tail -n 5 f` — the line-range fast path returns before the
  exclusion is consulted (#2823); `head f` is excluded normally
- `gradlew.bat build` / `mvnw.cmd test` — path stripping splits on `/`, so a
  `.bat`/`.cmd` spelling never reduces to the tool name (#3617)
- `golangci run ./...` — `golangci run` is one of the rule's own aliases and is
  kept whole, so it misses a `golangci-lint` entry

Each row verified against a build on `develop` at e533c40, including the
documented workaround: `["golangci"]` excludes the alias form but not
`golangci-lint run`, so both entries are needed.

Docs only, no behaviour change.

Co-Authored-By: Claude Opus 5 <[email protected]>
@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks @rhishi99, and sorry for the wait. I tested this on Linux and native Windows against its base (29f9bb71).

Rebase first. The branch now conflicts with develop in src/discover/registry.rs and src/core/mod.rs. Could you rebase on the latest develop? While you're at it, compact_path now has 6 copies on develop rather than 3: golangci_cmd.rs, lint_cmd.rs, ruff_cmd.rs, sqlfluff_cmd.rs, format_cmd.rs and search.rs. Please fold all of them into core::path_utils.

What I saw:

  • rtk discover splits Windows paths much better. C:\Program Files\...\grep.exe is no longer cut at the space, and the quoted and unquoted forms are grouped together. 👍

  • The .exe suffix is kept, though, so grep.exe, git.exe status and cmd.exe still show up as unhandled. Before vs after on the same history:

    • before: C:\Program, "C:\Program, C:\tools\git.exe status → unhandled
    • after: grep.exe ×6, git.exe status ×3, cmd.exe ×3 → still unhandled

    Could strip_absolute_path also drop .exe / .cmd / .bat (case-insensitive), with a test that C:\...\grep.exe -rn foo is classified as rtk grep?

  • \grep is now counted as grep. That's fine, since it only affects discover stats, not the hook rewrite.

  • On Windows, rtk grep output looks the same before and after. The grep filter doesn't parse lines that start with a drive letter (C:\...:1:...), so compact_path never runs there. That's a separate issue (same root cause as fix(ast-grep): parse Windows drive-letter paths #4060 / fix(pipe): support Windows drive paths and tee recovery hints in grep filter #5066), so it isn't needed for this PR.

Once it's rebased with the .exe handling, I'll test it again on both platforms.

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.

3 participants