Files
orca/src/shared/windows-terminal-shell.ts
T
Brennan Benson 12edee3ac6 Choose default models and effort for agents (#36210)
* Add host-owned model and effort defaults to agent settings

* Unify terminal defaults and raw argument precedence

* Keep agent model defaults typed through creation

* Preserve quick-create prompt through preparation

* fix: complete execution-host preference boundary and CI contracts

* Preserve raw options until a replacement is emitted

* Complete launch choice ownership and consumer contracts

* Align launch contracts with compiler boundaries and consolidate proof

* Name exported fixture mocks and verify ordered chip removal

* Preserve typed choices across compound legacy publication edits

* Preserve non-emitted composed launch choices through legacy edits

* Preserve rollback omissions and settle agent launches before success

* Carry terminal draft ownership through launch completion

* Keep inline draft delivery independent of terminal projection

* test: consolidate launch ownership contracts

* test: check web launch fixture array types

* test: align launch fixtures and conformity records

* test: import the shell-ready marker from its declaring module

* test: give caller routing the web host tab's completion contract
2026-10-30 15:17:52 -07:00

100 lines
3.6 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
/** Choose startup quoting from terminalWindowsShell: Git Bash/WSL use POSIX, cmd.exe uses cmd, others use the PowerShell 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'
}
// WSL/Git Bash need POSIX quoting/cd; extensionless names resolve through PATHEXT too.
if (
basename === 'wsl.exe' ||
basename === 'wsl' ||
basename === 'bash.exe' ||
basename === 'bash'
) {
return 'posix'
}
return 'powershell'
}
/** The shell a command typed into a new pane runs in on its host: the tab's override, then that
* host's own Windows shell setting, then the platform default (undefined for a remote host). */
export function resolveHostAgentStartupShell(args: {
platform: NodeJS.Platform | null | undefined
isRemote: boolean
tabShellOverride?: string | null
/** The executing host's setting: this client's for a local host, the reported one for a remote host. */
hostTerminalWindowsShell?: string | null
}): AgentStartupShell | undefined {
if (args.platform !== 'win32') {
return undefined
}
const shell = args.tabShellOverride?.trim() || args.hostTerminalWindowsShell?.trim()
if (!shell) {
return args.isRemote ? undefined : resolveWindowsShellStartupFamily(undefined)
}
return resolveWindowsShellStartupFamily(canonicalizeWindowsShellOverride(shell) ?? shell)
}
export function resolveLocalWindowsAgentStartupShell(args: {
platform: NodeJS.Platform | null | undefined
isRemote: boolean
terminalWindowsShell?: string | null
}): AgentStartupShell | undefined {
// Local shell settings cannot describe SSH or paired hosts.
return resolveHostAgentStartupShell({
platform: args.platform,
isRemote: args.isRemote,
hostTerminalWindowsShell: args.isRemote ? undefined : args.terminalWindowsShell
})
}
/** Share accepted Windows shell overrides across RPC validation and relay spawn.
* Canonical .exe/marker names keep exact-match quoting and Git Bash lookup aligned; pwsh and powershell remain distinct binaries. */
const WINDOWS_SHELL_OVERRIDE_CANONICAL_NAMES: ReadonlyMap<string, string> = new Map([
['powershell.exe', 'powershell.exe'],
['powershell', 'powershell.exe'],
['pwsh.exe', 'pwsh.exe'],
['pwsh', 'pwsh.exe'],
['cmd.exe', 'cmd.exe'],
['cmd', 'cmd.exe'],
['wsl.exe', 'wsl.exe'],
['wsl', 'wsl.exe'],
// Both bash spellings already work with local/daemon PTYs; keep relay acceptance aligned.
['bash.exe', 'bash.exe'],
['bash', 'bash.exe'],
[WINDOWS_GIT_BASH_SHELL, WINDOWS_GIT_BASH_SHELL]
])
/** Canonical spelling for an accepted override (case-insensitive), or undefined when refused. */
export function canonicalizeWindowsShellOverride(shell: string): string | undefined {
return WINDOWS_SHELL_OVERRIDE_CANONICAL_NAMES.get(shell.toLowerCase())
}
export function isSupportedWindowsShellOverride(shell: string): boolean {
return canonicalizeWindowsShellOverride(shell) !== undefined
}
/** Sorted for a stable error message; callers list these when refusing a value. */
export function listSupportedWindowsShellOverrides(): string[] {
return [...WINDOWS_SHELL_OVERRIDE_CANONICAL_NAMES.keys()].sort()
}