fix(terminal): force Git for Windows bash + convert native CWD for bash cd - #330
Merged
Conversation
|
Review Complete Risk: 🟢 Low (12/100) — no findings · 125 LOC across 3 files PR adds new Windows MSYS2/Git Bash terminal backend test coverage and refactors local environment classes for clarity. No defects found — all 6 scanner passes returned clean. Files Reviewed (3 files) |
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
Windows terminal commands launched from PowerShell/cmd now work instead of failing with exit 126 — fixed at the root by forcing one canonical bash, not by translating around whichever shell PATH happened to resolve.
Root cause was two-layered:
_find_bash()calledshutil.which("bash")before checking Git-for-Windows install paths. On any machine with WSL installed, PATH returnsC:\Windows\System32\bash.exe(the WSL shim), so Hermes silently ran WSL bash instead of Git Bash — a different drive-mount dialect (/mnt/cvs/c).C:\Users\x) was embedded verbatim into bashcd, which no bash dialect can resolve →cd: C:\Users\...: No such file or directory→exit 126on the first command of every session.Changes
tools/environments/local.py(@Icather): reorder_find_bash()so explicit Git-for-Windows paths win overshutil.which("bash"). Git Bash always beats the WSL shim → one canonical MSYS shell, one path dialect. Fixes [Bug]: _find_bash() resolves to WSL bash before checking system Git-for-Windows paths on Native Windows NousResearch/hermes-agent#47837.tools/environments/local.py(@LeonSGP43): add_windows_to_msys_path()(C:\Users\x→/c/Users/x) + aLocalEnvironment._quote_cwd_for_cdoverride that applies it. No-op on non-Windows.tools/environments/base.py(follow-up): route theinit_sessionsnapshot bootstrapcdthrough_quote_cwd_for_cdtoo — the override previously only reached_wrap_command, so the bootstrapcdstill leaked the raw Windows path andpwd -Pcaptured the login shell's dir instead ofterminal.cwd. Also add--for hyphen-safety to match_wrap_command._windows_to_msys_path, the_wrap_commandcd conversion, and theinit_sessionbootstrap conversion.Why force one shell instead of dialect-detecting
Several competing PRs proposed detecting whether the resolved bash is Git Bash or WSL and emitting
/c/vs/mnt/c/accordingly. That translates around the symptom. The design intent (_find_bash's own error: "requires Git for Windows") is one canonical shell. Fixing the resolution order makes the whole/mnt/cdialect-mismatch bug class impossible rather than handling it downstream.Validation
_find_bash()w/ WSL on PATH + Git for Windowscdin_wrap_commandon Windowscd C:\Users\x→ exit 126cd -- /c/Users/x✓cdininit_sessionbootstrapcd C:\Users\x(fails silently)cd -- /c/Users/x✓E2E tested with real imports against a simulated Windows env (fake Git-for-Windows + WSL shim on PATH); both layers verified. Targeted suite: 17/17 green.
Supersedes NousResearch#50596, NousResearch#42105 (same MSYS conversion, less complete), NousResearch#53475 (wrong premise — WSL is not always the shell), NousResearch#54321 (dialect detection unnecessary once the shell is forced; also bundled an unrelated coding_context change), NousResearch#13397 (mistitled — never converted paths), NousResearch#47920 (duplicate of the
_find_bashreorder).Fixes NousResearch#50594, NousResearch#35459, NousResearch#47837.
Infographic
Mirror-of: NousResearch#56384
NousResearch#56384