Skip to content

npx agmsg fails on Windows: bash receives backslash path from os.tmpdir() #262

Description

@masa6161

Summary

npx agmsg fails on Windows because bin/agmsg.js passes a backslash-separated path to bash.

Reproduction

# Windows 11, PowerShell, Git Bash on PATH
npx agmsg
/bin/bash: C:Users<user>AppDataLocalTempagmsg-bootstrap-OXDr4qsetup.sh: No such file or directory

Root cause

runInstaller() in bin/agmsg.js (L94-95) builds a tempfile path with os.tmpdir() + path.join(), which returns backslash-separated paths on Windows (e.g. C:\Users\...\Temp\agmsg-bootstrap-XXXXXX\setup.sh). This path is passed directly to spawnSync('bash', [setupPath]) at L109, where bash interprets the backslashes as escape characters and mangles the path.

The bug was introduced in 9768445 (PR #100), which replaced the pipe-to-bash flow with a tempfile download. That commit was verified on Debian 12 only.

Proposed fix

Normalise backslashes to forward slashes before handing the path to external processes (bash and curl), while keeping the native-separator path for Node.js filesystem calls (fs.rmSync):

const bashPath = setupPath.replace(/\/g, '/');

The replacement is a no-op on Linux/macOS (no backslashes to replace).

curl -o and bash both accept forward-slash paths on Windows. fs.rmSync continues to use the native tmpDir.

Verification

Tested on Windows 11 (PowerShell, Git Bash on PATH per README recommendation):

  • node bin/agmsg.js --version — passes
  • Path normalisation unit test — C:\...\setup.shC:/.../setup.sh, no backslashes remain
  • Linux noop test — /tmp/... path unchanged by .replace()
  • E2E: node bin/agmsg.js from PowerShell (with Git Bash in PATH) — full install completes successfully

Notes

  • On systems with WSL installed, bash may resolve to WSL's bash.exe (C:\Windows\System32\bash.exe) before Git Bash. This is a separate environment-configuration issue, already documented in the README under "Windows: Git Bash & Codex" with the Set-Alias recommendation. The backslash bug affects all Windows environments regardless of WSL.
  • The fix scope is minimal: 1 file, ~3 lines changed, limited to runInstaller().
  • I'm planning to open a PR for this fix. If there are additional verification scenarios or considerations I should address, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions