singularity-forge/packages/pi-coding-agent/src/utils
Tom Boucher 3542b17c97 fix: normalize Windows paths in LLM-visible text to prevent bash failures (#874) (#884)
On Windows, process.cwd() returns backslash paths (C:\Users\name\...).
When these paths are injected into system prompts, worktree context
blocks, or tool results, the model copies them into bash commands.
Bash interprets backslashes as escape characters, silently stripping
them — producing invalid paths like 'C:Usersnamedevelopmentapp-name'.

This is not a regex hack — it's a proper cross-platform boundary:
- Filesystem operations (fs, path.join, spawn cwd) use native paths
  unchanged. Node handles both separators correctly for I/O.
- LLM-visible text (prompts, tool results, extension messages) uses
  toPosixPath() to normalize to forward slashes. C:/Users/name/...
  is valid in Git Bash, WSL bash, PowerShell, and Node.js.

Changes:

- utils/path-display.ts: New toPosixPath() utility in pi-coding-agent
  package (for system prompt) and shared extension module (for
  extensions that can't import from the compiled package at dev time)

- system-prompt.ts: Normalize resolvedCwd before injecting into the
  'Current working directory' line

- gsd/index.ts: Normalize all process.cwd() and originalBase paths in
  worktree context blocks injected into the system prompt

- bg-shell/index.ts: Normalize cwd in tool result text (start, env
  actions) that the model reads and may reference in commands

- path-display.test.ts: 9 regression tests covering toPosixPath
  behavior and system prompt output verification. Includes a scanner
  that fails if any Windows absolute paths with backslashes appear in
  buildSystemPrompt() output.

Audit scope: Checked all process.cwd() usage across pi-coding-agent
and all bundled extensions. Filesystem-only paths (join, readFile,
spawn cwd, existsSync) are correct and left unchanged. Only paths
entering LLM text are normalized.
2026-03-17 09:02:23 -06:00
..
changelog.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
clipboard-image.ts fix: handle BMP clipboard images on WSL2 via wl-paste PNG conversion or ImageMagick (#813) (#841) 2026-03-17 07:59:56 -06:00
clipboard-native.ts feat: replace clipboard implementations with native @gsd/native module 2026-03-13 13:31:22 -06:00
clipboard.ts feat: replace clipboard implementations with native @gsd/native module 2026-03-13 13:31:22 -06:00
frontmatter.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
git.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
image-convert.ts feat: wire native Rust image module into image processing pipeline 2026-03-13 13:41:53 -06:00
image-resize.ts feat: wire native Rust image module into image processing pipeline 2026-03-13 13:41:53 -06:00
mime.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
path-display.ts fix: normalize Windows paths in LLM-visible text to prevent bash failures (#874) (#884) 2026-03-17 09:02:23 -06:00
photon.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
shell.ts fix: sanitize Windows NUL redirects to /dev/null in Git Bash (#157) 2026-03-13 09:33:28 -06:00
sleep.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
tools-manager.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00