fix(tools): convert Windows native CWD to MSYS format for bash cd - #50596
fix(tools): convert Windows native CWD to MSYS format for bash cd#50596Icather wants to merge 2 commits into
Conversation
When hermes is started from PowerShell or cmd.exe, os.getcwd() returns a Windows native path (C:\Users\...) which gets stored as the session working directory. Both init_session() and _wrap_command() embed this path into bash scripts via cd, but Git Bash cannot parse Windows drive-letter paths. Add _windows_to_msys_path() to BaseEnvironment: - C:\Users\x -> /c/Users/x (Git Bash compatible) - No-op on non-Windows or already-Msys paths Applied in init_session() and _wrap_command().
There was a problem hiding this comment.
Pull request overview
Fixes Windows terminal execution when Hermes is launched from PowerShell/cmd.exe by converting session CWDs from Windows-native drive-letter paths (e.g., C:\Users\...) into Git Bash/MSYS paths (e.g., /c/Users/...) before embedding them into bash cd commands.
Changes:
- Added
BaseEnvironment._windows_to_msys_path()to translate Windows-native paths to MSYS form (no-op off-Windows / already-MSYS). - Applied the conversion in
BaseEnvironment.init_session()and_wrap_command()so bootstrap and per-command scriptscdreliably in Git Bash. - Added
reandsysimports to support the conversion helper.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…indows_to_msys_path Copilot review follow-up: init_session bootstrap used builtin cd without double-dash; a cwd starting with dash could be parsed as an option. _wrap_command already guards. Added 6 unit tests for _windows_to_msys_path().
|
Thanks for the Windows terminal fix. The premise checks out on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
|
Superseded by PR #56384, which fixes this at the root: it reorders |
What does this PR do?
When Hermes is started from PowerShell or cmd.exe on Windows,
os.getcwd()returns a Windows native path (C:\Users\...) which gets stored as the session working directory. Bothinit_session()and_wrap_command()embed this path directly into bash scripts viacd, but Git Bash cannot parse Windows drive-letter paths.Impact: Every terminal tool call fails with exit code 126 the first time any command runs. The agent cannot write files, search, or execute shell commands. It wastes tokens diagnosing the failure, may produce incorrect results, and can fail entirely on tasks requiring shell execution. This affects ALL Windows users launching Hermes from non-Msys terminals (PowerShell, cmd.exe).
The existing
_msys_to_windows_path()inlocal.pyhandles reverse conversion (bash output -> PythonPopencwd). No forward helper existed.This PR adds
_windows_to_msys_path()toBaseEnvironmentand applies it in bothinit_session()and_wrap_command().Related Issue
Fixes #50594
Type of Change
Changes Made
tools/environments/base.py— Added_windows_to_msys_path()static method:C:\Users\x->/c/Users/x. No-op on non-Windows or already-Msys pathstools/environments/base.py—init_session(): convertself.cwdvia_windows_to_msys_path()beforeshlex.quote()tools/environments/base.py—_wrap_command(): convertcwdvia_windows_to_msys_path()before_quote_cwd_for_cd()import reandimport systo module importsHow to Test
cd C:\Users\YourNamehermesChecklist
Code
Documentation & Housekeeping
_windows_to_msys_path()is a no-op on non-Windows