pi-mono/packages/coding-agent/src/utils
Petr Houška 6454d07ec3
fix(coding-agent): start WSL interop helpers from / and report external editor failures (#11627)
Fixes #11592.

## Problem

WSL starts Windows programs in the current directory, translated to
`\\wsl.localhost\<distro>\<cwd>`. When that path exceeds MAX_PATH, every
Windows program fails to start with `Invalid argument`. pi inherits its
cwd when spawning `powershell.exe`, so in a deep directory:

- clipboard image paste returns `null` (the PowerShell backend fails,
stderr is discarded)
- copy via `powershell.exe` (WSL without WSLg) fails
- opening the browser for sign-in fails (`xdg-open` on WSL runs
`explorer.exe`)

Reproduced on WSL (FedoraLinux-44): `powershell.exe` and `cmd.exe` work
from a 225-char cwd and fail from 230. With an image on the Windows
clipboard, `readClipboardImage()` returns the PNG from `/tmp` and `null`
from a 245-char cwd; with this change it returns the PNG from both.
`LongPathsEnabled=1` does not help.

## Changes

- `runClipboardCommand` and `openBrowser` run from `/` on POSIX. These
tools never use the cwd (temp files are passed by absolute path), and
`/` is always the shortest UNC path. `tmpdir()` was not used because
`$TMPDIR` can itself be deep.
- The external editor keeps pi's cwd on purpose, so project-relative
paths and integrated terminals keep working. A Windows editor such as
`code` can still fail from a deep WSL directory, as with git's
`core.editor`. A comment documents this.
- External editor failures were silent: the UI redrew over the error
immediately. pi now shows `Failed to launch external editor: <cmd>`,
`External editor exited with code N; prompt unchanged`, or the signal
name. This shows in the status line for the main editor and inline in
the extension editor dialog.

## Testing

- New tests: clipboard commands run from `/` (POSIX); an editor that
cannot be launched is reported (POSIX); the existing failure test checks
the message.
- Verified on WSL by running the real modules: clipboard image paste
from a deep cwd, and editor success, exit code 1, launch failure, and
SIGTERM.
- On Windows, the 3 existing `external-editor.test.ts` tests already
fail on `main`: the editor command is split on spaces, so `C:\Program
Files\nodejs\node.exe` breaks. Not addressed here.

This PR is AI-generated.
2026-10-30 21:47:58 +01:00
..
abort.ts fix(coding-agent): make model refresh cancellation caller-owned 2026-08-04 00:03:52 +02:00
ansi.ts fix(coding-agent): strip private-parameter CSI sequences in stripAnsi 2026-10-28 20:14:09 +01:00
changelog.ts fix(coding-agent): fix changelog links 2026-06-08 20:31:20 +02:00
child-process.ts fix: drain stdout before resolving when a child holds the pipe past exit (#5753) 2026-06-15 09:55:45 +02:00
clipboard-command.ts fix(coding-agent): start WSL interop helpers from / and report external editor failures (#11627) 2026-10-30 21:47:58 +01:00
clipboard-image.ts fix(coding-agent): require advertised X11 clipboard images 2026-09-24 09:15:58 +02:00
clipboard.ts feat(coding-agent): add PI_CLIPBOARD_OSC52 to force OSC 52 copies 2026-10-12 18:07:27 +02:00
deprecation.ts fix(coding-agent): make config env references explicit 2026-05-28 11:58:38 +02:00
exif-orientation.ts fix(coding-agent): scan past non-EXIF APP1 segments (#8616) 2026-09-03 11:02:39 +02:00
frontmatter.ts fix(coding-agent): normalize UTF-8 BOMs in text inputs 2026-08-19 14:11:02 +02:00
fs-watch.ts fix(coding-agent,mom): retry fs watchers on async errors closes #3564 2026-04-22 23:03:19 +02:00
git.ts fix(coding-agent): refresh temporary git sources pinned to a branch ref 2026-10-29 21:43:11 +01:00
highlight-js.d.ts feat(coding-agent): defer uncommon syntax grammars 2026-08-22 22:50:12 +02:00
html.ts chore(deps): replace cli-highlight (#4468) 2026-05-13 12:19:45 +02:00
image-convert.ts fix(tui,coding-agent): convert non-PNG images for Kitty in Image 2026-10-03 00:14:52 +02:00
image-process.ts fix(coding-agent): process BMP images from disk 2026-06-25 12:52:21 +02:00
image-resize-core.ts fix(coding-agent): pick the smaller of PNG and JPEG when resizing images (#11577) 2026-10-29 16:14:56 +01:00
image-resize-worker.ts fix(coding-agent): ignore Node's own worker messages in image resize 2026-10-07 12:26:43 +02:00
image-resize.ts fix(coding-agent): ignore Node's own worker messages in image resize 2026-10-07 12:26:43 +02:00
json.ts fix(coding-agent): make config env references explicit 2026-05-28 11:58:38 +02:00
management-http.ts fix(coding-agent): retry hung model catalog requests 2026-08-17 12:55:56 +02:00
mime.ts fix: require complete GIF image signatures 2026-09-21 10:30:42 +02:00
open-browser.ts fix(coding-agent): start WSL interop helpers from / and report external editor failures (#11627) 2026-10-30 21:47:58 +01:00
output-files.ts feat(coding-agent): save codemode image() output to temp files 2026-10-04 23:32:43 +02:00
paths.ts fix(coding-agent): compare paths case-insensitively on Windows (#11588) 2026-10-29 21:53:06 +01:00
photon.ts fix(coding-agent): load photon wasm in compiled binaries 2026-01-18 17:11:49 +01:00
pi-user-agent.ts feat(ai,agent,coding-agent): move client identity and provider attribution into pi-ai 2026-10-21 11:17:02 +00:00
shell.ts fix(coding-agent): stop macOS shell groups before killing them 2026-10-22 20:22:20 +02:00
sleep.ts refactor(coding-agent): simplify AgentSession 2026-01-24 01:38:58 +01:00
syntax-highlight.ts fix(coding-agent): keep syntax colors on multiline tokens (#10356) 2026-10-05 10:35:43 +02:00
text.ts fix(coding-agent): normalize UTF-8 BOMs in text inputs 2026-08-19 14:11:02 +02:00
tool-result-images.ts feat(ai,coding-agent): add image input limits (closes #9631) 2026-09-20 22:59:16 +02:00
tools-manager.ts fix(coding-agent): skip fd/rg downloads on unsupported architectures 2026-10-23 19:48:59 +02:00
version-check.ts fix: build error on request info (#7645) 2026-08-05 09:56:43 +02:00
windows-self-update.ts chore(ts): use source import extensions 2026-05-20 00:04:03 +02:00
wsl.ts fix(coding-agent): restore OSC 52 clipboard fallback for headless sessions 2026-09-20 12:42:15 +02:00
zip.ts feat(coding-agent): add bug reporting 2026-09-19 17:55:49 +02:00