Files
orca/src/shared/windows-terminal-shell.ts
T
Jinjing 2b5f6af0e9 Respect terminalWindowsShell setting for local Windows agent launches (#7526)
Ensure agent CLI startup and draft launch commands use the correct quoting
format based on the user's configured local Windows shell (e.g., cmd.exe).
This avoids using host settings for remote/SSH targets where local shell
preferences do not apply.
2026-07-06 01:05:56 -07:00

51 lines
1.7 KiB
TypeScript

import type { AgentStartupShell } from './tui-agent-startup-shell'
export const WINDOWS_GIT_BASH_SHELL = 'git-bash'
export type BuiltInWindowsTerminalShell =
| 'powershell.exe'
| 'cmd.exe'
| 'wsl.exe'
| typeof WINDOWS_GIT_BASH_SHELL
/**
* Classifies a configured `terminalWindowsShell` value into the startup-shell
* family used to quote queued commands. Git Bash / wsl.exe run a POSIX shell;
* cmd.exe needs cmd quoting; everything else (PowerShell, pwsh, unknown) is
* treated as PowerShell, matching the Windows default.
*/
export function resolveWindowsShellStartupFamily(
shell: string | null | undefined
): AgentStartupShell {
const trimmed = shell?.trim()
if (!trimmed) {
return 'powershell'
}
if (trimmed === WINDOWS_GIT_BASH_SHELL) {
return 'posix'
}
const basename = trimmed.replaceAll('\\', '/').split('/').pop()?.toLowerCase() ?? ''
if (basename === 'cmd.exe') {
return 'cmd'
}
// Why: wsl.exe and bash.exe (Git for Windows) launch POSIX shells, so queued
// commands must use POSIX quoting and `cd '<cwd>'` rather than cmd/PowerShell.
if (basename === 'wsl.exe' || basename === 'wsl' || basename === 'bash.exe') {
return 'posix'
}
return 'powershell'
}
export function resolveLocalWindowsAgentStartupShell(args: {
platform: NodeJS.Platform
isRemote: boolean
terminalWindowsShell?: string | null
}): AgentStartupShell | undefined {
// Why: terminalWindowsShell describes the local host shell; SSH/remote
// targets need their own shell signal before we can safely override quoting.
if (args.platform !== 'win32' || args.isRemote) {
return undefined
}
return resolveWindowsShellStartupFamily(args.terminalWindowsShell)
}