feat(system): native Windows ls/grep/wc/tree + PowerShell cmdlet rewrites#2547
Open
tienthegainz wants to merge 2 commits into
Open
feat(system): native Windows ls/grep/wc/tree + PowerShell cmdlet rewrites#2547tienthegainz wants to merge 2 commits into
tienthegainz wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
• 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)