block / block/berd

Windows: Terminal panel uses \\?\ extended-length path prefix, breaking cmd.exe child processes (npm, npx, etc.)

Open
#108 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
909
Forks
116
Avg merge
1d 1h
Merged PRs (30d)
156

Description

## Description

The terminal panel in Berd spawns PowerShell with the session's `working_dir` set to the repository path. When the path is under `C:\Users\...` (or any long path), PowerShell resolves it to the Win32 extended-length path format `\\?\C:\Users\...`. This breaks any child process that spawns `cmd.exe` — including `npm`, `npx`, and many Node.js toolchains.

## Symptoms

1. **Terminal prompt shows the extended-length path format:**
```
PS Microsoft.PowerShell.Core\FileSystem::\\?\C:\Users\0\.buzz\REPOS\inferencesaver>
```

2. **Running `npm run dev` (or any npm/npx command) fails with:**
```
'\\?\C:\Users\0\.buzz\REPOS\inferencesaver'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
```

3. **`next dev` crashes with:**
```
Error: EISDIR: illegal operation on a directory, lstat 'C:'
```

4. **`npm run dev:docs` fails with:**
```
Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\Windows\package.json'
```

## Root Cause

- Berd's terminal panel spawns PowerShell with the session's `working_dir` as the initial CWD
- When the working directory is a normal Windows path like `C:\Users\0\.buzz\REPOS\inferencesaver`, PowerShell's FileSystem provider resolves it to the extended-length path format `\\?\C:\Users\...`
- `cmd.exe` (spawned by npm/npx) does not support `\\?` UNC paths as a CWD and falls back to `C:\Windows`
- This causes all downstream Node.js processes to fail because they're running from the wrong directory
- Even Git Bash (`C:\Program Files\Git\bin\bash.exe --login`) spawned from this terminal inherits the `\\?` CWD environment

## Workaround

Run `cd C:\Users\0\.buzz\REPOS\inferencesaver` once in the terminal to reset the PowerShell provider path to the normal format. This is not obvious and wastes time every time a new terminal is opened.

## Affected Environment

- **Berd version:** v0.6.2
- **OS:** Windows 10 (build 26100)
- **Shell:** PowerShell 5.1 (default Windows PowerShell)
- **Node.js:** v24.18.1

## Suggested Fix

When spawning the terminal, Berd should normalize the `working_dir` path to its non-extended-length form (`C:\...` instead of `\\?\C:\...`) before passing it to PowerShell. This could be done by:

1. Passing the path without the `\\?` prefix when spawning the shell process
2. Or, if using PowerShell, prepending a `cd` to the non-extended path in the initial command
3. Or, using Git Bash or Windows Terminal as an alternative shell option

## Impact

This is a significant UX issue for any Windows user of Berd who works with Node.js projects, Python projects, or any toolchain that spawns `cmd.exe` subprocesses. It makes the terminal unusable out of the box for running dev servers, builds, and package managers.

Contributor guide

Open the contributing guide

Research direction

Start at the terminal panel code that spawns PowerShell and passes the session's working_dir; reproduce the issue on Windows using a repository under C:\Users\... and npm or npx. The fix is complete when a new terminal starts with a normal C:\... working directory and child cmd.exe-based tools run from the repository rather than C:\Windows.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, powershell, typescript
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.