mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 16:02:37 +00:00
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.
51 lines
1.7 KiB
TypeScript
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)
|
|
}
|