Files
orca/src/shared/local-account-runtime.ts
OrcaWinandBrennan Benson 6444be3a01 fix(accounts): follow the runtime for WSL provider account detection (#9537) (#9611)
* fix(accounts): follow the runtime for WSL provider account detection (#9537)

On Windows + WSL, provider-account detection (usage recognition and the
status-bar account switcher) was pinned to the Windows host even when the
project runs in WSL, so WSL accounts were never recognized and the WSL
switcher group never appeared.

Root cause: `localAccountRuntime` hard-defaulted to 'host', which
short-circuited `getInitialClaude/CodexRateLimitTarget` before the existing
"follow the global Windows runtime default" branch could run. That branch was
therefore dead for every real user.

Fix: add an 'auto' value for `localAccountRuntime`, make it the default, and
migrate the untouched legacy 'host' default to 'auto' once (guarded by
`localAccountRuntimeDefaultedToAutoForAllUsers`; explicit 'wsl' is preserved).
'auto' resolves via a shared `resolveLocalAccountRuntimeTarget` helper: on a
windows-host default it stays host (no behavior change); on a WSL default it
follows WSL, so WSL accounts are recognized and the WSL group appears.

Wired the shared resolver into the managed-account default target, the
status-bar WSL-group gate, and the Accounts settings location toggle.

Note: detection follows the global Windows runtime default, not the live
active project's runtime (the fetch target is a single global value); the
latter is a larger follow-up.

* fix(accounts): align auto runtime consumers

* fix(accounts): keep runtime polling aligned with settings

---------

Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
2026-07-20 18:35:14 -07:00

41 lines
1.4 KiB
TypeScript

import type { GlobalSettings } from './types'
import { normalizeGlobalWindowsRuntimeDefault } from './project-execution-runtime'
export type LocalAccountRuntimeTarget = {
runtime: 'host' | 'wsl'
wslDistro: string | null
}
type LocalAccountRuntimeSettings = Pick<
GlobalSettings,
'localAccountRuntime' | 'localAccountWslDistro' | 'localWindowsRuntimeDefault'
>
/** Resolves the persisted account policy to a concrete host or WSL target. */
export function resolveLocalAccountRuntimeTarget(
settings: LocalAccountRuntimeSettings,
platform: NodeJS.Platform = process.platform
): LocalAccountRuntimeTarget {
if (settings.localAccountRuntime === 'host') {
return { runtime: 'host', wslDistro: null }
}
if (settings.localAccountRuntime === 'wsl') {
return { runtime: 'wsl', wslDistro: normalizeDistro(settings.localAccountWslDistro) }
}
// 'auto' (or any unset legacy value): follow the global Windows runtime default.
if (platform !== 'win32') {
return { runtime: 'host', wslDistro: null }
}
const runtimeDefault = normalizeGlobalWindowsRuntimeDefault(settings.localWindowsRuntimeDefault)
if (runtimeDefault.kind === 'wsl') {
return { runtime: 'wsl', wslDistro: runtimeDefault.distro }
}
return { runtime: 'host', wslDistro: null }
}
function normalizeDistro(value: string | null | undefined): string | null {
const trimmed = value?.trim()
return trimmed ? trimmed : null
}