mirror of
https://github.com/stablyai/orca.git
synced 2026-11-04 02:57:36 +00:00
Extract subprocess execution and process contracts into @orca/process-host with explicit public entry points, independent checks, and one Node 18 compatible CommonJS runtime. Migrate application consumers and integrate package builds, dependency selection, import enforcement, and runtime resource staging. Preserve daemon startup ownership and profile isolation, and qualify development rebuild recovery and concurrent output publication. Remove unnecessary aliases, test forwarding exports, and a duplicate output scan. Validation: full typechecks, changed-code quality, package and artifact checks, native Windows builds/types plus 306 runtime tests, and independent native reviews. Matched full E2E controls on original main and unchanged reviewed head both pass all 17 applicable tests (nine skips). Earlier intermittent E2E failures are documented in the PR; no assertions were weakened. The final combined-tree audit preserves both branches with no import-boundary violations.
54 lines
2.4 KiB
TypeScript
54 lines
2.4 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 '../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
|
|
|
|
/**
|
|
* Directory holding this app's WSL launcher and bridge, or null when the CLI runtime is
|
|
* missing or unwritable. Content-addressed like shell-ready wrappers: builds sharing userData
|
|
* never overwrite each other, and a present file is complete because each one lands by rename.
|
|
*/
|
|
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
|
|
}
|