Files
orca/src/shared/execution-host/project-runtime-preference.ts
T
Neil c10881fa8c refactor(shared): organize execution and automation defining owners (#39776)
* refactor: import journal queue state from defining owners

* refactor(shared): organize execution and automation owners

* fix: retain type imports used by surviving test cases

* refactor: finish work item owners and refresh validation metadata

* test: infer reconnect status fixture type

* test(claude): resolve source files beside same-named directories

* test(runtime): group repository creation mock registrations
2026-11-08 06:46:09 -08:00

86 lines
2.5 KiB
TypeScript

import { parseWslUncPath } from '../wsl-paths'
/**
* `git: 'windows-host'` keeps terminals and agents in WSL but runs Orca's own Git on Windows: for a
* project on a Windows drive, WSL Git is ~300x slower and misses Windows-side edits.
*/
export type ProjectGitRuntime = 'windows-host'
export type LocalWindowsRuntimePreference =
| { kind: 'inherit-global' }
| { kind: 'windows-host' }
| { kind: 'wsl'; distro: string; git?: ProjectGitRuntime }
export type GlobalWindowsRuntimeDefault =
| { kind: 'windows-host' }
| { kind: 'wsl'; distro: string | null }
export function normalizeProjectRuntimePreference(value: unknown): LocalWindowsRuntimePreference {
if (!isRecord(value)) {
return { kind: 'inherit-global' }
}
if (value.kind === 'inherit-global') {
return { kind: 'inherit-global' }
}
if (value.kind === 'windows-host') {
return { kind: 'windows-host' }
}
if (value.kind === 'wsl') {
const distro = normalizeDistro(value.distro)
if (!distro) {
return { kind: 'inherit-global' }
}
return value.git === 'windows-host'
? { kind: 'wsl', distro, git: 'windows-host' }
: { kind: 'wsl', distro }
}
return { kind: 'inherit-global' }
}
/** A project with no saved runtime runs a workspace that lives in a WSL share inside that distro. */
export function getWorkspaceRuntimePreference(
projectPreference: LocalWindowsRuntimePreference | undefined,
workspacePath: string | null | undefined
): LocalWindowsRuntimePreference {
if (projectPreference) {
return projectPreference
}
const distro = workspacePath ? parseWslUncPath(workspacePath)?.distro : undefined
return distro ? { kind: 'wsl', distro } : { kind: 'inherit-global' }
}
export function normalizeGlobalWindowsRuntimeDefault(value: unknown): GlobalWindowsRuntimeDefault {
if (!isRecord(value)) {
return { kind: 'windows-host' }
}
if (value.kind === 'wsl') {
return { kind: 'wsl', distro: normalizeDistro(value.distro) }
}
return { kind: 'windows-host' }
}
export function isKnownMissingDistro(
distro: string,
availableWslDistros: readonly string[] | null | undefined
): boolean {
return Array.isArray(availableWslDistros) && !availableWslDistros.includes(distro)
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null
}
export function normalizeDistro(value: unknown): string | null {
if (typeof value !== 'string') {
return null
}
const trimmed = value.trim()
return trimmed ? trimmed : null
}