feat(discover): classify PowerShell cmdlets - #3620
Open
rhishi99 wants to merge 1 commit into
Open
Conversation
The rewrite registry only knew POSIX command names, so on the default Windows shell almost nothing classified: `Get-ChildItem`, `Get-Content` and `Select-String` are the everyday equivalents of `ls`, `cat` and `grep`, and all three passed through unrecognized. Add rules for those cmdlets and their standard aliases, mapping each to the rtk command that already handles it. Ordering matters here and is easy to get wrong. `classify_command` takes `matches.last()`, so a specific pattern placed *before* the broader one it refines never wins -- `Get-ChildItem -Recurse` would resolve to `rtk ls` instead of `rtk tree`, and the `-Head`/`-Tail` variant of `Get-Content` would be dead code. General rules therefore go first, specific ones last, and the tests assert the resolution rather than just the patterns. Two candidate rules were dropped rather than shipped: - `Test-Path` -> `rtk test-path`, a command that does not exist. It would have replaced a working command with an error. - `Get-Location`/`pwd` -> `rtk pwd` at a claimed 30% saving. The output is one line, and bare `pwd` is already in `IGNORED_PREFIXES`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
The rewrite registry only knows POSIX command names. On the default Windows shell almost nothing classifies —
Get-ChildItem,Get-ContentandSelect-Stringare the everyday equivalents ofls,catandgrep, and all three pass through unrecognized. A Windows user gets close to zero rewrites on the commands they type most.Fix
Rules for those cmdlets and their standard aliases (
gci,dir,gc,sls, …), each mapped to the rtk command that already handles it.Ordering is the whole trick
classify_commandtakesmatches.last(), so a specific pattern placed before the broader one it refines never wins. Written the natural way — specific first — this happens:Get-ChildItem -Recurse srcrtk lsrtk treeGet-ChildItem Env:rtk lsrtk envGet-Content -Head 50 f.txtrtk readat 60%General rules go first, specific ones last. The tests assert the resolution, not just that a pattern matches, so this ordering cannot silently regress.
Two rules deliberately dropped
Test-Path→rtk test-path— that command does not exist. Verified:rtk test-path .printsFailed to resolve 'test-path' via PATH ... [rtk: program not found]. It would have replaced a working user command with an error.Get-Location/pwd→rtk pwdat a claimed 30% saving — the output is one line, and barepwdis already inIGNORED_PREFIXES.Testing
Seven new classification tests in
registry.rscovering each cmdlet, alias equivalence (gci≡Get-ChildItem), and the three ordering cases in the table above.Full suite on
x86_64-pc-windows-gnu: 2622 passed.cargo fmt --checkandcargo clippy --all-targetsclean. The single unrelated failure on this toolchain is fixed in #3615.🤖 Generated with Claude Code