mirror of
https://github.com/stablyai/orca.git
synced 2026-11-02 18:17:36 +00:00
* feat(wsl): run Git for Windows for a WSL project on a Windows drive A project on C:\ whose runtime is WSL ran every Orca Git command through wsl.exe on /mnt/c: ~300x slower than Windows Git, and blind to Windows-side edits. The project's WSL runtime preference gains an optional `git: 'windows-host'`. With it, Orca's Git (and where new worktrees go) is Windows; terminals, agents, accounts and hooks still resolve to WSL, so nothing else changes. Older builds drop the field and go back to WSL Git. The conversion checks first, then the caller saves the returned preference through the normal project update: - Git for Windows must exist. - New worktrees must not be set to go inside the distro. - No linked worktree may have a Linux-path link. WSL Git made those; Windows Git sees them as prunable, and Orca's prune after a worktree removal would delete their metadata. - Optionally writes core.autocrlf=true into the repo when Windows Git uses it, so WSL Git in the project's terminals stops seeing CRLF changes. Never core.checkStat. IPC is refused off Windows and with the internal WSL hosts gate closed. Co-Authored-By: Claude <noreply@anthropic.com> * test(wsl): mock the drive-project IPC in the core handler registration test Co-Authored-By: Claude <noreply@anthropic.com> * test(wsl): pin WSL Git for a drive project that never chose Windows Git, and record which Git ran * fix(wsl): base-ref lookups and the remote-identity sweep run Git where the project's runtime does * fix(wsl): route base-ref and remote-identity reads by runtime only with WSL hosts on These reads ran host Git on main. Routing them into a WSL-runtime project's distro is part of D1c, so with the WSL hosts gate closed they run host Git exactly as before. (cherry picked from commit 2ed82987dc5b82c3a86ea7e03ce05e9efc3e77fb) * refactor(ipc): register the filesystem handlers in one call, keeping core registration under its line cap The optional commit-message resolvers pass straight through, so the call is the same with or without them. #34059 left this file at the 300-line cap and the WSL drive-project wiring adds to it. Co-Authored-By: Claude <noreply@anthropic.com> * fix(wsl): skip folder repos in the Windows Git check, and read worktree links with the prune guard's reader Folder repos run no Git, so rev-parse on them always failed the preview. The link reader and the WSL-authored test now come from worktree-prune-guard.ts; the copy's startsWith('/') wrongly refused //wsl.localhost links, which Windows Git writes itself. Co-Authored-By: Claude <noreply@anthropic.com> * fix(wsl): the remote-identity sweep checks the distro a drive project's Git runs in, so it never boots a stopped one --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
328 lines
9.2 KiB
TypeScript
328 lines
9.2 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 type ProjectExecutionRuntimeReason =
|
|
| 'project-override'
|
|
| 'global-default'
|
|
| 'migration-fallback'
|
|
| 'non-windows'
|
|
|
|
export type ResolvedProjectExecutionRuntime =
|
|
| {
|
|
kind: 'local-host'
|
|
hostPlatform: string
|
|
projectId: string
|
|
reason: 'non-windows'
|
|
cacheKey: string
|
|
}
|
|
| {
|
|
kind: 'windows-host'
|
|
hostPlatform: 'win32'
|
|
projectId: string
|
|
reason: Exclude<ProjectExecutionRuntimeReason, 'non-windows'>
|
|
cacheKey: string
|
|
}
|
|
| {
|
|
kind: 'wsl'
|
|
hostPlatform: 'wsl'
|
|
projectId: string
|
|
distro: string
|
|
reason: 'project-override' | 'global-default'
|
|
git?: ProjectGitRuntime
|
|
cacheKey: string
|
|
}
|
|
|
|
export type ProjectExecutionRuntimeRepairReason =
|
|
| 'wsl-unavailable'
|
|
| 'wsl-distro-required'
|
|
| 'wsl-distro-missing'
|
|
|
|
export type ProjectExecutionRuntimeRepair = {
|
|
projectId: string
|
|
preferredRuntime: { kind: 'wsl'; distro: string | null }
|
|
reason: ProjectExecutionRuntimeRepairReason
|
|
source: 'project-override' | 'global-default'
|
|
cacheKey: string
|
|
}
|
|
|
|
export type ProjectExecutionRuntimeResolution =
|
|
| { status: 'resolved'; runtime: ResolvedProjectExecutionRuntime }
|
|
| { status: 'repair-required'; repair: ProjectExecutionRuntimeRepair }
|
|
|
|
export type LegacyWindowsRuntimeSettings = {
|
|
localAgentRuntime?: unknown
|
|
localAgentWslDistro?: unknown
|
|
terminalWindowsShell?: unknown
|
|
terminalWindowsWslDistro?: unknown
|
|
}
|
|
|
|
export type LegacyWindowsRuntimeMigrationContext = {
|
|
wslAvailable?: boolean
|
|
availableWslDistros?: readonly string[] | null
|
|
}
|
|
|
|
export type LegacyWindowsRuntimeFallbackReason =
|
|
| 'legacy-wsl-unavailable'
|
|
| 'legacy-wsl-distro-missing'
|
|
|
|
export type LegacyWindowsRuntimeDefaultMigration = {
|
|
defaultRuntime: GlobalWindowsRuntimeDefault
|
|
fallbackReason: LegacyWindowsRuntimeFallbackReason | null
|
|
}
|
|
|
|
export type ResolveProjectExecutionRuntimeArgs = {
|
|
appPlatform: string
|
|
projectId: string
|
|
projectRuntimePreference?: unknown
|
|
globalWindowsRuntimeDefault?: unknown
|
|
wslAvailable?: boolean
|
|
availableWslDistros?: readonly string[] | null
|
|
}
|
|
|
|
type RuntimeSource = 'project-override' | 'global-default'
|
|
|
|
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 deriveGlobalWindowsRuntimeDefaultFromLegacySettings(
|
|
settings: LegacyWindowsRuntimeSettings | null | undefined,
|
|
context: LegacyWindowsRuntimeMigrationContext = {}
|
|
): LegacyWindowsRuntimeDefaultMigration {
|
|
const selectedRuntime = settings?.localAgentRuntime
|
|
if (selectedRuntime === 'host') {
|
|
return { defaultRuntime: { kind: 'windows-host' }, fallbackReason: null }
|
|
}
|
|
|
|
if (selectedRuntime === 'wsl' || isWslShell(settings?.terminalWindowsShell)) {
|
|
const distro =
|
|
normalizeDistro(settings?.localAgentWslDistro) ??
|
|
normalizeDistro(settings?.terminalWindowsWslDistro)
|
|
const fallbackReason = getLegacyWslFallbackReason(distro, context)
|
|
if (fallbackReason) {
|
|
return { defaultRuntime: { kind: 'windows-host' }, fallbackReason }
|
|
}
|
|
return { defaultRuntime: { kind: 'wsl', distro }, fallbackReason: null }
|
|
}
|
|
|
|
return { defaultRuntime: { kind: 'windows-host' }, fallbackReason: null }
|
|
}
|
|
|
|
export function resolveProjectExecutionRuntime(
|
|
args: ResolveProjectExecutionRuntimeArgs
|
|
): ProjectExecutionRuntimeResolution {
|
|
if (args.appPlatform !== 'win32') {
|
|
return {
|
|
status: 'resolved',
|
|
runtime: {
|
|
kind: 'local-host',
|
|
hostPlatform: args.appPlatform,
|
|
projectId: args.projectId,
|
|
reason: 'non-windows',
|
|
cacheKey: `${args.projectId}:local-host:${args.appPlatform}`
|
|
}
|
|
}
|
|
}
|
|
|
|
const projectPreference = normalizeProjectRuntimePreference(args.projectRuntimePreference)
|
|
if (projectPreference.kind === 'windows-host') {
|
|
return resolvedWindowsHost(args.projectId, 'project-override')
|
|
}
|
|
|
|
if (projectPreference.kind === 'wsl') {
|
|
return resolveWslRuntime(
|
|
args,
|
|
projectPreference.distro,
|
|
'project-override',
|
|
projectPreference.git
|
|
)
|
|
}
|
|
|
|
const globalDefault = normalizeGlobalWindowsRuntimeDefault(args.globalWindowsRuntimeDefault)
|
|
if (globalDefault.kind === 'wsl') {
|
|
return resolveWslRuntime(args, globalDefault.distro, 'global-default')
|
|
}
|
|
|
|
return resolvedWindowsHost(args.projectId, 'global-default')
|
|
}
|
|
|
|
function resolveWslRuntime(
|
|
args: ResolveProjectExecutionRuntimeArgs,
|
|
distro: string | null,
|
|
source: RuntimeSource,
|
|
git?: ProjectGitRuntime
|
|
): ProjectExecutionRuntimeResolution {
|
|
if (!distro) {
|
|
return {
|
|
status: 'repair-required',
|
|
repair: {
|
|
projectId: args.projectId,
|
|
preferredRuntime: { kind: 'wsl', distro },
|
|
reason: 'wsl-distro-required',
|
|
source,
|
|
cacheKey: `${args.projectId}:repair:wsl-distro-required:default`
|
|
}
|
|
}
|
|
}
|
|
|
|
const repairReason = getWslRepairReason(distro, {
|
|
wslAvailable: args.wslAvailable,
|
|
availableWslDistros: args.availableWslDistros
|
|
})
|
|
if (repairReason) {
|
|
return {
|
|
status: 'repair-required',
|
|
repair: {
|
|
projectId: args.projectId,
|
|
preferredRuntime: { kind: 'wsl', distro },
|
|
reason: repairReason,
|
|
source,
|
|
cacheKey: `${args.projectId}:repair:${repairReason}:${distro ?? 'default'}`
|
|
}
|
|
}
|
|
}
|
|
|
|
const resolvedDistro = distro
|
|
return {
|
|
status: 'resolved',
|
|
runtime: {
|
|
kind: 'wsl',
|
|
hostPlatform: 'wsl',
|
|
projectId: args.projectId,
|
|
distro: resolvedDistro,
|
|
reason: source,
|
|
...(git ? { git } : {}),
|
|
cacheKey: `${args.projectId}:wsl:${resolvedDistro}${git ? `:git-${git}` : ''}`
|
|
}
|
|
}
|
|
}
|
|
|
|
function resolvedWindowsHost(
|
|
projectId: string,
|
|
reason: 'project-override' | 'global-default' | 'migration-fallback'
|
|
): ProjectExecutionRuntimeResolution {
|
|
return {
|
|
status: 'resolved',
|
|
runtime: {
|
|
kind: 'windows-host',
|
|
hostPlatform: 'win32',
|
|
projectId,
|
|
reason,
|
|
cacheKey: `${projectId}:windows-host`
|
|
}
|
|
}
|
|
}
|
|
|
|
function getLegacyWslFallbackReason(
|
|
distro: string | null,
|
|
context: LegacyWindowsRuntimeMigrationContext
|
|
): LegacyWindowsRuntimeFallbackReason | null {
|
|
if (context.wslAvailable === false) {
|
|
return 'legacy-wsl-unavailable'
|
|
}
|
|
if (distro && isKnownMissingDistro(distro, context.availableWslDistros)) {
|
|
return 'legacy-wsl-distro-missing'
|
|
}
|
|
return null
|
|
}
|
|
|
|
function getWslRepairReason(
|
|
distro: string,
|
|
context: LegacyWindowsRuntimeMigrationContext
|
|
): ProjectExecutionRuntimeRepairReason | null {
|
|
if (context.wslAvailable === false) {
|
|
return 'wsl-unavailable'
|
|
}
|
|
if (isKnownMissingDistro(distro, context.availableWslDistros)) {
|
|
return 'wsl-distro-missing'
|
|
}
|
|
return null
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
function normalizeDistro(value: unknown): string | null {
|
|
if (typeof value !== 'string') {
|
|
return null
|
|
}
|
|
const trimmed = value.trim()
|
|
return trimmed ? trimmed : null
|
|
}
|
|
|
|
function isWslShell(value: unknown): boolean {
|
|
if (typeof value !== 'string') {
|
|
return false
|
|
}
|
|
const shellName = value.trim().split(/[\\/]/).pop()?.toLowerCase()
|
|
return shellName === 'wsl.exe' || shellName === 'wsl'
|
|
}
|