mirror of
https://github.com/stablyai/orca.git
synced 2026-11-04 11:07:42 +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.
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { resolveStartupShell, tokenizeStartupCommand } from '../../shared/tui-agent-startup-shell'
|
|
import { runProcess } from '@orca/process-host'
|
|
import { resolveCommandOnLocalPath } from '../ipc/command-path-resolver'
|
|
|
|
export async function resolveOpenCodeDirectModelExecutable(options: {
|
|
command: string | undefined
|
|
model: string
|
|
env: NodeJS.ProcessEnv
|
|
cwd?: string
|
|
wsl?: { distro?: string }
|
|
}): Promise<string | null> {
|
|
// WSL needs the same guest account/profile environment as its actual launch.
|
|
if (options.wsl || !options.cwd) {
|
|
return null
|
|
}
|
|
const parsed = tokenizeStartupCommand(
|
|
options.command ?? '',
|
|
resolveStartupShell(process.platform)
|
|
)
|
|
if (
|
|
!parsed.ok ||
|
|
parsed.tokens.length !== 1 ||
|
|
parsed.spans.some((span) => span.divergesFromShell)
|
|
) {
|
|
return null
|
|
}
|
|
return resolveCommandOnLocalPath(parsed.tokens[0], {
|
|
env: options.env,
|
|
cwd: options.cwd
|
|
})
|
|
}
|
|
|
|
export async function probeOpenCodeModelAvailability(
|
|
options: Parameters<typeof resolveOpenCodeDirectModelExecutable>[0]
|
|
): Promise<boolean> {
|
|
const executable = await resolveOpenCodeDirectModelExecutable(options)
|
|
if (!executable) {
|
|
return false
|
|
}
|
|
try {
|
|
const result = await runProcess({
|
|
program: executable,
|
|
args: ['models'],
|
|
cwd: options.cwd,
|
|
env: options.env,
|
|
timeoutMs: 10_000,
|
|
maxOutputBytes: 1_048_576
|
|
})
|
|
return (
|
|
result.code === 0 &&
|
|
!result.timedOut &&
|
|
!result.outputTruncated &&
|
|
result.stdout.endsWith('\n') &&
|
|
result.stdout.split(/\r?\n/).some((line) => line === options.model)
|
|
)
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|