Skip to content

feat(system): native Windows ls/grep/wc/tree + PowerShell cmdlet rewrites#2875

Open
sresam89 wants to merge 1 commit into
rtk-ai:developfrom
sresam89:feat/search-windows-no-binary-fallback
Open

feat(system): native Windows ls/grep/wc/tree + PowerShell cmdlet rewrites#2875
sresam89 wants to merge 1 commit into
rtk-ai:developfrom
sresam89:feat/search-windows-no-binary-fallback

Conversation

@sresam89

@sresam89 sresam89 commented Jul 7, 2026

Copy link
Copy Markdown

• Make rtk ls / grep / wc / tree work on Windows. These filters previously shelled out to Unix binaries ( ls , rg / grep , wc , tree ) that aren't present on a stock Windows install, so they failed with "Binary not found on PATH" (or tree.com 's "Too many parameters"). Each now has a native Rust execution path used when the Unix binary is absent (detected via tool_exists ; tree always goes native on Windows). All native paths reuse the existing compression filters, so token-savings behavior is unchanged.
• Auto-rewrite common PowerShell cmdlets to their rtk equivalents so the hook saves tokens for Windows/PowerShell agents: Get-Content / gc / type → rtk read , Get-ChildItem / gci / dir → rtk ls ( -Recurse → rtk tree , -Force → -a ), Select-String / sls → rtk grep ( -i unless -CaseSensitive ). Only single, non-piped invocations are rewritten so PowerShell pipelines are never broken; unmappable params (e.g. -Filter ) and unknown cmdlets pass through untouched.
• Adds a backslash-safe PowerShell tokenizer ( ps_split ) so Windows paths like src\cmds survive rewriting, plus docs in src/cmds/system/README.md .

Test plan
✓ cargo fmt --all && cargo clippy --all-targets && cargo test
• fmt clean; clippy zero warnings; 2235 tests pass. (The 16 failing core::stream::tests::* are pre-existing Windows-environment failures — they spawn Unix sh / cat / echo / sleep — and are unrelated to this change; verified core/stream.rs is untouched.)
• 30 new tests added: native wc counts/columns, ls synthetic-line round-trip, tree arg parsing, native grep matching ( -i / -v , NUL-format parse round-trip), and 16 PowerShell-rewrite cases incl. backslash-path and piped-passthrough regressions.
✓ Manual testing: rtk output inspected on Windows (rtk 0.42.4):
• rtk ls src\cmds\system → compact name size listing + summary (was: "Binary 'ls' not found")
• rtk grep "fn run" src\cmds\system → 34 matches in 14 files: grouped output, no rg/grep warnings (was: "Binary 'rg'/'grep' not found")
• rtk wc Cargo.toml → 72L 246W 1796B (was: "Binary 'wc' not found")
• rtk tree -L 1 src → compact pruned tree (was: "Too many parameters")
• rtk hook check --agent copilot "Get-ChildItem -Recurse src\cmds" → rtk tree src\cmds
• rtk gain --history confirms commands tracked (~80% savings)

Covers #2547

…ng on PATH

Plain Windows PowerShell (no Git Bash/WSL, no ripgrep installed) has neither
grep nor rg on PATH, so `rtk grep`/`rtk rg` hard-failed instead of running.
engine_capture now checks tool_exists(engine.bin()) and, only when the
requested binary is absent, walks paths with the already-vendored `ignore`
crate and matches lines with the already-vendored `regex` crate. This never
substitutes one engine for the other — grep still only falls back when grep
itself is missing, same for rg. Output is emitted in the exact
file\0line:content shape parse_match_line already expects, so grouping/
truncation/display code is untouched. Context lines (-A/-B/-C) are not
supported in fallback mode; only -i/--ignore-case is honored from extra_args.

Forward-ports unreleased fork-local work (originally against the pre-refactor
grep_cmd.rs) onto develop's search.rs/Engine design. Not tied to a GitHub
issue; staged for maintainer discussion before submission.
@CLAassistant

CLAassistant commented Jul 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sresam89 sresam89 changed the title feat(system): native Windows ls/grep/wc/tree + PowerShell cmdlet rewrites #2547 feat(system): native Windows ls/grep/wc/tree + PowerShell cmdlet rewrites Jul 7, 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.

2 participants