fix(windows): better support MSYS/Git Bash path handling #6082
+54
−24
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.
Fix MSYS/Git Bash path handling on Windows
Summary
toNativePath()to convert MSYS/Git Bash/Cygwin paths (/c/Users/...) to Windows paths (C:\Users\...)safeRelative()to handle cross-drive paths and deep parent traversalsLocale.truncateMiddlefor long pathsDetails
When running opencode in Git Bash on Windows, the shell uses POSIX-style paths (
/f/test/file.txt) but Node.js/Bun APIs expect Windows paths (F:\test\file.txt). This caused:ENOENT: no such file or directorybecause Node can't resolve/f/...pathspath.relative()across different drives produced..\..\..\..\..\..\f\testBefore
After
Files Changed
packages/opencode/src/util/filesystem.ts- AddedtoNativePath()andsafeRelative()packages/opencode/src/tool/*.ts- Applied path conversion at entry points (read, write, edit, glob, grep, ls, patch)packages/opencode/src/cli/cmd/tui/routes/session/index.tsx- Fixed TUI display with path abbreviationTest Cases
Setup (run once in Git Bash)
I don't touch LSP or MultipleEdit tools because unsure about those. (But it's working by default)
Feature 1: MSYS/Git Bash Path Conversion
Tests that
/c/...and/f/...paths are converted toC:\...andF:\....LIST Tool
Expected:
→ List F:\test(not..\..\..\..\f\test)READ Tool
Expected:
→ Read F:\test\test.txtWRITE Tool
Expected:
→ Wrote F:\test\write-test.txtEDIT Tool
Expected:
→ Edit F:\test\test.txtGLOB Tool
Expected:
→ ✱ Glob "*.txt" in F:\test\ (4 matches)GREP Tool
Expected:
→ ✱ Grep "hello" in F:\test\ (1 matches)Feature 2: Parent Traversal Threshold (3+)
Paths with 3+ parent traversals (
../../..) show absolute path. Paths with 0-2 show relative.2 levels up - shows RELATIVE
Expected:
→ Read ..\..\.PR.md(relative path)3+ levels up - shows ABSOLUTE
Expected:
→ Read C:\Users\<user_name>\repo\testdir\three-up.txt(absolute path)Expected:
→ Read C:\Users\<user_name>\.config\opencode\opencode.jsonc(absolute path)Feature 3: Long Path Truncation
Long paths are truncated with
...in the middle, usingLocale.truncateMiddle.Long path on different drive
Expected:
→ Read F:\test\very\deeply\…\that\is\really\long\file.txt(truncated)Long path inside worktree
Expected:
→ Read ..\..\very\deeply\ne…\that\is\really\long\file.txt(truncated relative path)Checklist
toNativePath()(gated byprocess.platform === "win32")Locale.truncateMiddlefor path abbreviation (consistent with sidebar)