Repository navigation
Description
layerfs_exec cannot run on Windows at all. runShell in layerfs.mjs:302 spawns /bin/sh with no platform branch, so the call fails before the command starts — which means turning the plugin's exec option on does nothing for Windows users.
{"project":"demo","branch":"main","exitCode":-1,"stdout":"",
"stderr":"Error: ENOENT: no such file or directory, uv_spawn '/bin/sh'",
"changed":false,"commit":null}
Repro
Windows 11 (10.0.26300), magpie 0.1.4452, @magpie-community/tools-layerfs@0.10.3:
magpie plugin options tools-layerfs '{"exec": true}'provisiona project, answer a workspace path (this part works fine)execany command, e.g.echo hello
Expected: the command runs in the workspace and its changes are committed, as on POSIX.
Actual: ENOENT, exitCode: -1, no command runs, nothing commits. No workspace is modified, so it reads like the exec switch did nothing.
Cause
const child = spawn("/bin/sh", ["-c", command], {
cwd: dir,
detached: true,
...
env: { ...process.env, TMPDIR: join(dir, ".tmp"), XDG_CACHE_HOME: join(dir, ".cache") },
})Windows has no /bin/sh (Node resolves it from the current drive root, e.g. C:\bin\sh.EXE). The shell there is %ComSpec% — cmd.exe /d /s /c <command>.
Two related Windows gaps in the same function
- Scratch is not actually kept in the workspace. Only
TMPDIRandXDG_CACHE_HOMEare redirected; Windows programs readTEMP/TMP. Even with a shell, toolchain temp files would still land in the host's temp directory instead of the workspace.tmp. - The timeout does not kill the tree.
detached: trueplusprocess.kill(-child.pid, "SIGKILL")is POSIX process-group semantics: on Windowsdetachedopens a new console and the negative-PID kill throws, so thecatchfallback kills onlycmd.exeand its children keep running past the 55 s cap.
Patch that makes it work here
+const IS_WIN = process.platform === "win32"
+function shellFor(command) {
+ if (IS_WIN) {
+ return {
+ file: process.env.ComSpec || process.env.COMSPEC || "cmd.exe",
+ args: ["/d", "/s", "/c", command],
+ }
+ }
+ return { file: "/bin/sh", args: ["-c", command] }
+}
+
function runShell(command, dir, timeoutMs) {
return new Promise((resolvePromise) => {
ensureScratch(dir)
- const child = spawn("/bin/sh", ["-c", command], {
+ const scratchEnv = IS_WIN
+ ? { TMPDIR: join(dir, ".tmp"), TMP: join(dir, ".tmp"), TEMP: join(dir, ".tmp"), XDG_CACHE_HOME: join(dir, ".cache") }
+ : { TMPDIR: join(dir, ".tmp"), XDG_CACHE_HOME: join(dir, ".cache") }
+ const sh = shellFor(command)
+ const child = spawn(sh.file, sh.args, {
cwd: dir,
- detached: true,
+ detached: !IS_WIN,
stdio: ["ignore", "pipe", "pipe"],
- env: { ...process.env, TMPDIR: join(dir, ".tmp"), XDG_CACHE_HOME: join(dir, ".cache") },
+ env: { ...process.env, ...scratchEnv },
})With this applied, on the same machine:
echo hello→exitCode 0,changed: false,commit: null(a no-change command commits nothing, as documented)- create a file + append to another →
exitCode 0, auto-commit withadded 1 / modified 1 ... && exit 3→exitCode 3, changes still checkpointedTMP,TEMPandXDG_CACHE_HOMEall resolve inside the workspace.tmp/.cache
Two things a real fix has to decide, which the patch above does not: the command language becomes cmd on Windows (&&, &, %VAR%, and </> need quoting — an unquoted < in echo fails with was unexpected at this time), and the 55 s cap needs a real tree kill (e.g. taskkill /T /F /PID), otherwise children outlive the timeout.
Activity