mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
50 lines
2.2 KiB
TypeScript
50 lines
2.2 KiB
TypeScript
import { createHash } from 'node:crypto'
|
|
import { existsSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import { getAppEnvironment } from '../../shared/app-environment'
|
|
import { windowsPowerShellPath } from '@orca/process-host/windows-system-binary'
|
|
import { writeShellWrapperFiles } from '../pty/shell-startup/shell-wrapper-file-writer'
|
|
import { getBundledLauncherPath, LINUX_CLI_COMMAND_NAME } from './bundled-cli-launcher-path'
|
|
import { DEV_COMMAND_NAME } from './cli-install-constants'
|
|
import { buildColocatedWslLauncher, buildWslBridgeScript } from './wsl-cli-scripts'
|
|
|
|
/** Packaged builds share `orca-ide` with guest registration; dev builds get their own name. */
|
|
export function getWslCliCommandName(isPackaged: boolean): string {
|
|
return isPackaged ? LINUX_CLI_COMMAND_NAME : DEV_COMMAND_NAME
|
|
}
|
|
|
|
let warnedMissingRuntime = false
|
|
|
|
// Content-addressed, atomically published files let builds share userData without overwriting peers.
|
|
export function getManagedWslCliDir(opts: {
|
|
isPackaged: boolean
|
|
userDataPath: string
|
|
resourcesPath?: string
|
|
}): string | null {
|
|
const cliEntryPath = opts.isPackaged
|
|
? undefined
|
|
: join(getAppEnvironment().getAppPath(), 'out', 'cli', 'index.js')
|
|
const launcherPath = opts.isPackaged
|
|
? opts.resourcesPath && getBundledLauncherPath('win32', opts.resourcesPath)
|
|
: process.execPath
|
|
if (!launcherPath || !existsSync(cliEntryPath ?? launcherPath)) {
|
|
if (!warnedMissingRuntime) {
|
|
warnedMissingRuntime = true
|
|
console.warn('[WSL CLI] Orca CLI runtime is missing; WSL terminals will not provide it.')
|
|
}
|
|
return null
|
|
}
|
|
const launcher = buildColocatedWslLauncher(launcherPath, windowsPowerShellPath())
|
|
const bridge = buildWslBridgeScript({ userDataPath: opts.userDataPath, cliEntryPath })
|
|
const digest = createHash('sha256').update(launcher).update(bridge).digest('hex').slice(0, 20)
|
|
const directory = join(opts.userDataPath, 'wsl-managed-cli', digest)
|
|
const files = [
|
|
[join(directory, getWslCliCommandName(opts.isPackaged)), launcher],
|
|
[join(directory, 'orca-wsl-bridge.ps1'), bridge]
|
|
] as const
|
|
const ready =
|
|
files.every(([path]) => existsSync(path)) ||
|
|
writeShellWrapperFiles(files, '[WSL CLI]', 'WSL terminals will start without the Orca CLI')
|
|
return ready ? directory : null
|
|
}
|