fix: Use bash instead of sh on Unix systems

The bash tool is named "bash" and described as executing bash commands,
but was using sh on Unix. On many distros (Ubuntu, Debian, Alpine, etc.),
/bin/sh is a POSIX-only shell that doesn't support bash syntax like [[ ]],
arrays, or here-strings. This caused the LLM to write bash syntax that
failed, wasting tokens on rewrites.

Now prefers /bin/bash on Unix, falling back to sh only if bash isn't found.
This commit is contained in:
Daniel Nouri 2025-12-26 23:06:03 +01:00
parent bd276e6931
commit 8fc0610a53

View file

@ -26,8 +26,9 @@ function findBashOnPath(): string | null {
* Get shell configuration based on platform.
* Resolution order:
* 1. User-specified shellPath in settings.json
* 2. On Windows: Git Bash in known locations
* 3. Fallback: bash on PATH (Windows) or sh (Unix)
* 2. On Windows: Git Bash in known locations, then bash on PATH
* 3. On Unix: /bin/bash
* 4. Fallback: sh
*/
export function getShellConfig(): { shell: string; args: string[] } {
if (cachedShellConfig) {
@ -83,6 +84,12 @@ export function getShellConfig(): { shell: string; args: string[] } {
);
}
// Unix: prefer bash over sh
if (existsSync("/bin/bash")) {
cachedShellConfig = { shell: "/bin/bash", args: ["-c"] };
return cachedShellConfig;
}
cachedShellConfig = { shell: "sh", args: ["-c"] };
return cachedShellConfig;
}