Skip to content

fix(terminal): normalize Windows cwd for Git Bash bootstrap - #42105

Closed
kingshukkundu wants to merge 2 commits into
NousResearch:mainfrom
kingshukkundu:fix/windows-terminal-msys-path-conversion
Closed

kingshukkundu wants to merge 2 commits into
NousResearch:mainfrom
kingshukkundu:fix/windows-terminal-msys-path-conversion

Conversation

@kingshukkundu

Copy link
Copy Markdown

What does this PR do?

Fixes a Windows terminal bootstrap bug where Hermes stores native cwd values like C:\Users\Kingshuk and injects them directly into Git Bash cd commands. Git Bash expects MSYS-style paths like /c/Users/Kingshuk, so session bootstrap and wrapped commands can fail before the terminal is usable.

This keeps self.cwd in native OS format for Python-side filesystem handling and converts only at the bash boundary. LocalEnvironment normalizes Windows and UNC paths for cd, and BaseEnvironment.init_session() now routes bootstrap cwd handling through the same quoting and normalization helper used for wrapped commands.

This complements #23866, which focuses on MSYS-to-Windows normalization for paths coming back from bash. This PR fixes the opposite direction: native Windows cwd values going into bash.

Related Issue

N/A

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • Route BaseEnvironment.init_session() cwd handling through _quote_cwd_for_cd
  • Add overridable _normalize_cwd_for_cd() in tools/environments/base.py
  • Add _windows_to_msys_path() and LocalEnvironment._normalize_cwd_for_cd() in tools/environments/local.py
  • Add Windows regression coverage in tests/tools/test_windows_native_support.py

How to Test

  1. On Windows with Git Bash, set the terminal cwd to a native Windows path like C:\Users\Kingshuk.
  2. Trigger Hermes terminal session bootstrap and run a simple command like pwd.
  3. Confirm the session initializes successfully and no longer fails with cd: C:\Users\Kingshuk: No such file or directory.
  4. Confirm wrapped commands still preserve native cwd values for Python-side path handling.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • My PR contains only changes related to this fix
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested targeted behavior on my platform: Windows 11

Documentation & Housekeeping

  • I've considered cross-platform impact (Windows, macOS) — the normalization hook is overridden only in LocalEnvironment and preserves existing behavior elsewhere
  • No config, schema, or workflow docs changes were needed

Screenshots / Logs

  • Targeted local validation confirmed:
    • C:\Users\Some Name\project -> '/c/Users/Some Name/project'
    • \\server\share\folder -> //server/share/folder
  • Full pytest was not available in the system Python used for this local checkout

… bash

On Windows, Python's os.getcwd() returns native paths (C:\Users\x) but
Git Bash requires MSYS-style POSIX paths (/c/Users/x). The existing
_msys_to_windows_path handled the reverse direction only, causing every
bash command to fail on the initial 'builtin cd' with:

  /bin/bash: line 2: cd: C:\Users\<user>: No such file or directory

Add _windows_to_msys_path() as the inverse converter and override
_normalize_cwd_for_cd() in LocalEnvironment to apply it before passing
CWD into bash scripts. Mirrors the existing pattern where base.py provides
a no-op hook that subclasses override for platform-specific behaviour.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management backend/local Local shell execution labels Jun 8, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Looks Good

  • Fixes Git Bash bootstrap on Windows: paths with spaces (e.g. C:\Users\Some Name\project) are now properly converted to MSYS-style POSIX paths (/c/Users/Some Name/project) before being passed to builtin cd.
  • Handles both regular Windows paths and UNC paths (\\server\share\folder).
  • _normalize_cwd_for_cd override in LocalEnvironment for Windows-specific path translation.
  • No security concerns, no debug artifacts.

Reviewed by Hermes Agent

@teknium1

teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Superseded by PR #56384, which fixes this at the root: it reorders _find_bash() so Git for Windows always beats the WSL shim on PATH (one canonical MSYS bash), then converts the native cwd C:\Users\x/c/Users/x at both cd sites. This makes the /mnt/c vs /c dialect mismatch impossible rather than translating around it. Thanks for the fix — the cleanest implementation of the same conversion was salvaged with authorship preserved.
#56384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/local Local shell execution P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants