Skip to content

Commit 01edae4

Browse files
committed
fix(core): spawn shell non-interactively without sourcing rc files
ShellSelect.args() ran zsh/bash with -l and explicitly sourced .zshrc/.bashrc, loading user functions and aliases that can shadow builtins and return non-zero exit codes, breaking && chains. Match the old tool behavior: plain non-login non-interactive shell -c command with cwd passed via spawn options.
1 parent 381d675 commit 01edae4

4 files changed

Lines changed: 8 additions & 37 deletions

File tree

‎packages/core/src/shell.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const layer = Layer.effect(
159159
const cwd = input.cwd ?? location.directory
160160
const configShell = Config.latest(yield* config.entries(), "shell")
161161
const shell = ShellSelect.preferred(configShell)
162-
const args = ShellSelect.args(shell, input.command, cwd)
162+
const args = ShellSelect.args(shell, input.command)
163163
const file = path.join(outputDir, `${id}.out`)
164164
const env = {
165165
...process.env,

‎packages/core/src/shell/select.ts‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -163,37 +163,10 @@ function info(file: string): Item {
163163
}
164164
}
165165

166-
export function args(file: string, command: string, cwd: string) {
166+
export function args(file: string, command: string) {
167167
const n = name(file)
168168
if (n === "nu" || n === "fish") return ["-c", command]
169-
if (n === "zsh") {
170-
return [
171-
"-l",
172-
"-c",
173-
`
174-
[[ -f ~/.zshenv ]] && source ~/.zshenv >/dev/null 2>&1 || true
175-
[[ -f "\${ZDOTDIR:-$HOME}/.zshrc" ]] && source "\${ZDOTDIR:-$HOME}/.zshrc" >/dev/null 2>&1 || true
176-
cd -- "$1"
177-
eval ${JSON.stringify(command)}
178-
`,
179-
"opencode",
180-
cwd,
181-
]
182-
}
183-
if (n === "bash") {
184-
return [
185-
"-l",
186-
"-c",
187-
`
188-
shopt -s expand_aliases
189-
[[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
190-
cd -- "$1"
191-
eval ${JSON.stringify(command)}
192-
`,
193-
"opencode",
194-
cwd,
195-
]
196-
}
169+
if (n === "zsh" || n === "bash") return ["-c", command]
197170
if (n === "cmd") return ["/c", command]
198171
if (ps(file)) return ["-NoProfile", "-Command", command]
199172
return ["-c", command]

‎packages/core/test/shell.test.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ describe("shell", () => {
5555
})
5656

5757
test("builds command args per shell family", () => {
58-
expect(ShellSelect.args("/bin/sh", "echo hi", "/tmp")).toEqual(["-c", "echo hi"])
59-
expect(ShellSelect.args("/usr/bin/fish", "echo hi", "/tmp")).toEqual(["-c", "echo hi"])
60-
const zsh = ShellSelect.args("/bin/zsh", "echo hi", "/tmp")
61-
expect(zsh[0]).toBe("-l")
62-
expect(zsh[1]).toBe("-c")
63-
expect(zsh.at(-1)).toBe("/tmp")
58+
expect(ShellSelect.args("/bin/sh", "echo hi")).toEqual(["-c", "echo hi"])
59+
expect(ShellSelect.args("/usr/bin/fish", "echo hi")).toEqual(["-c", "echo hi"])
60+
expect(ShellSelect.args("/bin/zsh", "echo hi")).toEqual(["-c", "echo hi"])
61+
expect(ShellSelect.args("/bin/bash", "echo hi")).toEqual(["-c", "echo hi"])
6462
})
6563

6664
if (process.platform === "win32") {

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export const layer = Layer.effect(
521521

522522
const cfg = yield* config.get()
523523
const sh = ShellSelect.preferred(cfg.shell)
524-
const args = ShellSelect.args(sh, input.command, cwd)
524+
const args = ShellSelect.args(sh, input.command)
525525
let output = ""
526526
let aborted = false
527527

0 commit comments

Comments
 (0)