mirror of
https://github.com/stablyai/orca.git
synced 2026-11-02 18:17:36 +00:00
GUI-launched Orca often inherits a minimal PATH, so bare `code` fails with spawn ENOENT for Open in VS Code, including Remote-SSH worktrees. When PATH and install-dir lookup leave `code`/`code-insiders` unresolved, fall back to the CLI bundled in the standard macOS app bundle (/Applications or ~/Applications) or the Windows user/system install. Linux packages already link the CLI onto PATH, so no Linux candidates are added. Fixes #14008 Co-authored-by: Neil <neil@stably.ai>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { homedir } from 'node:os'
|
|
import { posix, win32 } from 'node:path'
|
|
|
|
function listVsCodeCliInstallPaths(command: string, platform: NodeJS.Platform): string[] {
|
|
if (command !== 'code' && command !== 'code-insiders') {
|
|
return []
|
|
}
|
|
const insiders = command === 'code-insiders'
|
|
if (platform === 'darwin') {
|
|
// The bundled macOS CLI is named `code` for both stable and Insiders.
|
|
const cli = posix.join(
|
|
insiders ? 'Visual Studio Code - Insiders.app' : 'Visual Studio Code.app',
|
|
'Contents/Resources/app/bin/code'
|
|
)
|
|
return [posix.join('/Applications', cli), posix.join(homedir(), 'Applications', cli)]
|
|
}
|
|
if (platform === 'win32') {
|
|
const cli = win32.join(
|
|
insiders ? 'Microsoft VS Code Insiders' : 'Microsoft VS Code',
|
|
'bin',
|
|
`${command}.cmd`
|
|
)
|
|
const { LOCALAPPDATA, ProgramFiles } = process.env
|
|
return [
|
|
...(LOCALAPPDATA ? [win32.join(LOCALAPPDATA, 'Programs', cli)] : []),
|
|
...(ProgramFiles ? [win32.join(ProgramFiles, cli)] : [])
|
|
]
|
|
}
|
|
// Linux packages link /usr/bin or /snap/bin, which PATH resolution already covers.
|
|
return []
|
|
}
|
|
|
|
/** VS Code's bundled CLI, for GUI launches whose PATH lacks the optional `code` shim. */
|
|
export function findInstalledVsCodeCli(
|
|
command: string,
|
|
platform: NodeJS.Platform,
|
|
fileExists: (path: string) => boolean
|
|
): string | null {
|
|
return listVsCodeCliInstallPaths(command, platform).find((path) => fileExists(path)) ?? null
|
|
}
|