Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.4 KB
Raw Blame
import type { GlobalSettings } from './global-settings-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
}