Skip to content

feat(discover): classify PowerShell cmdlets - #3620

Open
rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:feat/powershell-cmdlet-rules
Open

feat(discover): classify PowerShell cmdlets#3620
rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:feat/powershell-cmdlet-rules

Conversation

@rhishi99

Copy link
Copy Markdown

Problem

The rewrite registry only knows POSIX command names. On the default Windows shell almost nothing classifies — Get-ChildItem, Get-Content and Select-String are the everyday equivalents of ls, cat and grep, 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_command takes matches.last(), so a specific pattern placed before the broader one it refines never wins. Written the natural way — specific first — this happens:

Command Resolves to Should be
Get-ChildItem -Recurse src rtk ls rtk tree
Get-ChildItem Env: rtk ls rtk env
Get-Content -Head 50 f.txt (dead rule) rtk read at 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-Pathrtk test-path — that command does not exist. Verified: rtk test-path . prints Failed to resolve 'test-path' via PATH ... [rtk: program not found]. It would have replaced a working user command with an error.
  • Get-Location/pwdrtk pwd at a claimed 30% saving — the output is one line, and bare pwd is already in IGNORED_PREFIXES.

Testing

Seven new classification tests in registry.rs covering each cmdlet, alias equivalence (gciGet-ChildItem), and the three ordering cases in the table above.

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

🤖 Generated with Claude Code

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>
@CLAassistant

CLAassistant commented Aug 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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