Skip to content

Make PATH-based command lookup / near-match shell-agnostic (currently PowerShell-only) #421

Description

@vanzue

Summary

resolve_command (and the autofix near-match push path) is gated PowerShell-only via is_powershell(shell). In a non-PowerShell pane (cmd / bash / WSL) the tool returns status:"unsupported" and does no grounded resolution — including the parts that are inherently shell-agnostic.

This is an enhancement, not a bug: today's behavior is a deliberate v1 scoping (see #286 / PR #418). The agent falls back to its own native probing (where, type, etc.), so nothing is broken. But we bundle two conceptually different things under one PowerShell-only gate:

  1. Alias / function resolution — inherently shell-specific (a PowerShell profile alias, a bash function, …). Correctly shell-gated.
  2. PATH executable existence + "did you mean" near-matchOS-level and shell-agnostic. which::which and the set of .exe/scripts on %PATH% don't depend on the shell.

Because the near-match enumeration + ranking is implemented with PowerShell (Get-Command -CommandType Application,ExternalScript,…), the shell-agnostic PATH lookup is currently unavailable in cmd/bash/WSL too.

Proposed enhancement

Split the PATH-only portion out of the PowerShell gate so a not-found command in any shell can still get:

  • a grounded "does this executable exist on PATH" answer, and
  • a "did you mean <x>" near-match against PATH executables,

while alias/function resolution stays shell-specific (PowerShell today).

Sketch:

  • Add a shell-agnostic PATH enumerator (walk %PATH% / $PATH dirs for executables) feeding the existing rank_near_matches, independent of Get-Command.
  • In resolve_command, for a non-PowerShell shell, instead of returning unsupported immediately, still attempt the PATH-only near-match; only the alias/function/type resolution is reported as unavailable.
  • Keep PowerShell on the richer Get-Command path (types + profile aliases) as today.

Context / code pointers

Notes

  • cmd.exe has essentially no persisted alias/function system, so for cmd the PATH near-match is the only meaningful grounded signal — which is exactly the shell-agnostic part this enhancement would unlock.
  • bash/WSL could later also get native alias/function resolution (type -a, compgen) as a separate follow-up, with the WSL /mnt/* PATH-leakage caveat in mind.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions