fix(non-interactive-env): honor Windows ComSpec shell

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-13 22:47:37 +09:00
parent fef1d4530b
commit 47d60a74d3
2 changed files with 49 additions and 12 deletions
@@ -20,24 +20,36 @@ function detectBannedCommand(command: string): string | undefined {
return undefined
}
function detectWindowsShellType(shellPath: string | undefined): ShellType | undefined {
if (!shellPath) {
return undefined
}
const shellName = shellPath.replace(/\\/g, "/").split("/").pop()?.toLowerCase()
if (shellName === "cmd" || shellName === "cmd.exe") {
return "cmd"
}
if (
shellName === "powershell" ||
shellName === "powershell.exe" ||
shellName === "pwsh" ||
shellName === "pwsh.exe"
) {
return "powershell"
}
return undefined
}
function detectCommandShellType(): ShellType {
if (process.platform === "win32" && process.env.SHELL) {
const shellName = process.env.SHELL.replace(/\\/g, "/").split("/").pop()?.toLowerCase()
if (shellName === "cmd" || shellName === "cmd.exe") {
return "cmd"
}
if (
shellName === "powershell" ||
shellName === "powershell.exe" ||
shellName === "pwsh" ||
shellName === "pwsh.exe"
) {
return "powershell"
const shellType = detectWindowsShellType(process.env.SHELL)
if (shellType) {
return shellType
}
}
if (process.platform === "win32" && !process.env.SHELL && !process.env.MSYSTEM) {
return "cmd"
return detectWindowsShellType(process.env.ComSpec) ?? "cmd"
}
return detectShellType()