diff --git a/src/renderer/src/components/feature-wall/AgentCapabilitiesSetupAction.tsx b/src/renderer/src/components/feature-wall/AgentCapabilitiesSetupAction.tsx index 1bb1d5bc9..7ba461093 100644 --- a/src/renderer/src/components/feature-wall/AgentCapabilitiesSetupAction.tsx +++ b/src/renderer/src/components/feature-wall/AgentCapabilitiesSetupAction.tsx @@ -3,8 +3,10 @@ import { Check, Globe2, Loader2, MonitorCog, Terminal, Workflow } from 'lucide-r import { toast } from 'sonner' import { Button } from '@/components/ui/button' import { cn } from '@/lib/utils' +import { useActiveProjectSkillRuntime } from '@/hooks/useActiveProjectSkillRuntime' import { useAppStore } from '@/store' import { FeatureSetupInlineTerminal } from '../onboarding/FeatureSetupInlineTerminal' +import type { OnboardingFeatureSetupRuntimeContext } from '../onboarding/onboarding-feature-setup-runtime' import { DEFAULT_ONBOARDING_FEATURE_SETUP_SELECTION, hasSelectedOnboardingFeatureSetup, @@ -37,8 +39,11 @@ export function AgentCapabilitiesSetupAction(props: { const [featureSetupCommand, setFeatureSetupCommand] = useState(null) const [featureSetupCommandSelection, setFeatureSetupCommandSelection] = useState(null) + const [featureSetupRuntime, setFeatureSetupRuntime] = + useState(null) const [setupBusyLabel, setSetupBusyLabel] = useState(null) const recordFeatureInteraction = useAppStore((s) => s.recordFeatureInteraction) + const activeSkillRuntime = useActiveProjectSkillRuntime() useEffect(() => { onBrowserUseSkillInstalledChange(readiness.browserUseSkillInstalled) }, [onBrowserUseSkillInstalledChange, readiness.browserUseSkillInstalled]) @@ -65,7 +70,7 @@ export function AgentCapabilitiesSetupAction(props: { } setSetupBusyLabel('Setting up capabilities...') try { - const result = await runOnboardingFeatureSetup(featureSetup) + const result = await runOnboardingFeatureSetup(featureSetup, undefined, activeSkillRuntime) if (featureSetup.browserUse) { recordFeatureInteraction('agent-browser-setup') } @@ -111,12 +116,19 @@ export function AgentCapabilitiesSetupAction(props: { } if (result.skillInstallCommand) { setFeatureSetupCommandSelection(featureSetup) + setFeatureSetupRuntime(activeSkillRuntime) setFeatureSetupCommand(result.skillInstallCommand) } } finally { setSetupBusyLabel(null) } - }, [featureSetup, featureSetupCommand, recordFeatureInteraction, setupBusyLabel]) + }, [ + activeSkillRuntime, + featureSetup, + featureSetupCommand, + recordFeatureInteraction, + setupBusyLabel + ]) return (
@@ -125,6 +137,7 @@ export function AgentCapabilitiesSetupAction(props: { onFeatureSetupChange={handleFeatureSetupChange} featureSetupCommand={featureSetupCommand} featureSetupCommandSelection={featureSetupCommandSelection} + featureSetupRuntime={featureSetupRuntime} setupBusyLabel={setupBusyLabel} onStartFeatureSetup={() => void handleStartFeatureSetup()} installStatus={capabilitySetupStatus.installStatus} @@ -196,6 +209,7 @@ function AgentCapabilitySetupControls(props: { onFeatureSetupChange: (value: OnboardingFeatureSetupSelection) => void featureSetupCommand: string | null featureSetupCommandSelection: OnboardingFeatureSetupSelection | null + featureSetupRuntime: OnboardingFeatureSetupRuntimeContext | null setupBusyLabel: string | null onStartFeatureSetup: () => void installStatus: Record @@ -236,6 +250,7 @@ function AgentCapabilitySetupControls(props: { {props.featureSetupCommand ? ( ) : null} diff --git a/src/renderer/src/components/feature-wall/FeatureWallBrowserAction.tsx b/src/renderer/src/components/feature-wall/FeatureWallBrowserAction.tsx index 2b14007cc..2e039c2f2 100644 --- a/src/renderer/src/components/feature-wall/FeatureWallBrowserAction.tsx +++ b/src/renderer/src/components/feature-wall/FeatureWallBrowserAction.tsx @@ -4,8 +4,10 @@ import { toast } from 'sonner' import { Button } from '@/components/ui/button' import { translate } from '@/i18n/i18n' import { activateAndRevealWorktree } from '@/lib/worktree-activation' +import { useActiveProjectSkillRuntime } from '@/hooks/useActiveProjectSkillRuntime' import { useAppStore } from '@/store' import { FeatureSetupInlineTerminal } from '../onboarding/FeatureSetupInlineTerminal' +import type { OnboardingFeatureSetupRuntimeContext } from '../onboarding/onboarding-feature-setup-runtime' import { runOnboardingFeatureSetup, type OnboardingFeatureSetupSelection @@ -84,7 +86,11 @@ const BROWSER_ONLY_FEATURE_SETUP: OnboardingFeatureSetupSelection = { function BrowserSkillInstallButton(): React.JSX.Element { const recordFeatureInteraction = useAppStore((s) => s.recordFeatureInteraction) const [command, setCommand] = useState(null) + const [runtimeContext, setRuntimeContext] = useState( + null + ) const [busy, setBusy] = useState(false) + const activeSkillRuntime = useActiveProjectSkillRuntime() const handleInstall = useCallback(async () => { if (busy || command !== null) { @@ -92,7 +98,11 @@ function BrowserSkillInstallButton(): React.JSX.Element { } setBusy(true) try { - const result = await runOnboardingFeatureSetup(BROWSER_ONLY_FEATURE_SETUP) + const result = await runOnboardingFeatureSetup( + BROWSER_ONLY_FEATURE_SETUP, + undefined, + activeSkillRuntime + ) recordFeatureInteraction('agent-browser-setup') const firstWarning = result.warnings[0] if (firstWarning) { @@ -118,6 +128,7 @@ function BrowserSkillInstallButton(): React.JSX.Element { ) } if (result.skillInstallCommand) { + setRuntimeContext(activeSkillRuntime) setCommand(result.skillInstallCommand) } } catch (error) { @@ -140,10 +151,16 @@ function BrowserSkillInstallButton(): React.JSX.Element { } finally { setBusy(false) } - }, [busy, command, recordFeatureInteraction]) + }, [activeSkillRuntime, busy, command, recordFeatureInteraction]) if (command) { - return + return ( + + ) } return ( diff --git a/src/renderer/src/components/onboarding/FeatureSetupInlineTerminal.test.tsx b/src/renderer/src/components/onboarding/FeatureSetupInlineTerminal.test.tsx new file mode 100644 index 000000000..024e61749 --- /dev/null +++ b/src/renderer/src/components/onboarding/FeatureSetupInlineTerminal.test.tsx @@ -0,0 +1,100 @@ +// @vitest-environment happy-dom +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { render } from '@testing-library/react' +import { FeatureSetupInlineTerminal } from './FeatureSetupInlineTerminal' + +const mocks = vi.hoisted(() => ({ + runtime: { + agentRuntime: { runtime: 'wsl' as const, wslDistro: 'Ubuntu', label: 'WSL Ubuntu' }, + installDisabledReason: null as string | null, + terminalShellOverride: 'powershell.exe' + }, + buildCommand: vi.fn( + (command: string, runtime?: { runtime: 'host' | 'wsl' }) => + `${runtime?.runtime ?? 'host'}:${command}` + ), + terminalProps: null as { command: string; shellOverride?: string } | null +})) + +vi.mock('@/hooks/useActiveProjectSkillRuntime', () => ({ + useActiveProjectSkillRuntime: () => mocks.runtime +})) + +vi.mock('../settings/CliSkillRuntimeSetup', () => ({ + buildSkillCommandForRuntime: mocks.buildCommand +})) + +vi.mock('./OnboardingInlineCommandTerminal', () => ({ + OnboardingInlineCommandTerminal: (props: { command: string; shellOverride?: string }) => { + mocks.terminalProps = props + return null + } +})) + +const SELECTION = { + browserUse: false, + computerUse: false, + orchestration: true, + linearTickets: false +} + +describe('FeatureSetupInlineTerminal', () => { + beforeEach(() => { + mocks.runtime.installDisabledReason = null + mocks.terminalProps = null + mocks.buildCommand.mockClear() + }) + + it('runs the command through the resolved WSL runtime', () => { + render( + + ) + + expect(mocks.buildCommand).toHaveBeenCalledWith('npx skills add orchestration', { + runtime: 'wsl', + wslDistro: 'Ubuntu', + label: 'WSL Ubuntu' + }) + expect(mocks.terminalProps).toMatchObject({ + command: 'wsl:npx skills add orchestration', + shellOverride: 'powershell.exe' + }) + }) + + it('uses the host command builder when the WSL runtime needs repair', () => { + mocks.runtime.installDisabledReason = 'The selected WSL distro is unavailable.' + + render( + + ) + + expect(mocks.buildCommand).toHaveBeenCalledWith('npx skills add orchestration', undefined) + expect(mocks.terminalProps).toMatchObject({ + command: 'host:npx skills add orchestration', + shellOverride: 'powershell.exe' + }) + }) + + it('keeps the runtime captured when setup started', () => { + render( + + ) + + expect(mocks.buildCommand).toHaveBeenCalledWith('npx skills add orchestration', { + runtime: 'host', + label: 'Windows' + }) + expect(mocks.terminalProps).toMatchObject({ + command: 'host:npx skills add orchestration', + shellOverride: 'cmd.exe' + }) + }) +}) diff --git a/src/renderer/src/components/onboarding/FeatureSetupInlineTerminal.tsx b/src/renderer/src/components/onboarding/FeatureSetupInlineTerminal.tsx index e15c796d4..3d7f2fcb3 100644 --- a/src/renderer/src/components/onboarding/FeatureSetupInlineTerminal.tsx +++ b/src/renderer/src/components/onboarding/FeatureSetupInlineTerminal.tsx @@ -1,7 +1,13 @@ import { useCallback, useMemo, useRef, type KeyboardEvent } from 'react' import { track } from '@/lib/telemetry' import { notifyInstalledAgentSkillsChanged } from '@/hooks/useInstalledAgentSkills' +import { useActiveProjectSkillRuntime } from '@/hooks/useActiveProjectSkillRuntime' +import { buildSkillCommandForRuntime } from '../settings/CliSkillRuntimeSetup' import { OnboardingInlineCommandTerminal } from './OnboardingInlineCommandTerminal' +import { + getOnboardingFeatureSetupAgentRuntime, + type OnboardingFeatureSetupRuntimeContext +} from './onboarding-feature-setup-runtime' import { onboardingFeatureSetupTelemetrySelection, type OnboardingFeatureSetupSelection @@ -10,15 +16,23 @@ import { translate } from '@/i18n/i18n' type FeatureSetupInlineTerminalProps = { command: string + runtimeContext?: OnboardingFeatureSetupRuntimeContext selection: OnboardingFeatureSetupSelection } export function FeatureSetupInlineTerminal({ command, + runtimeContext, selection }: FeatureSetupInlineTerminalProps): React.JSX.Element { const terminalOpenedTrackedRef = useRef(false) const terminalInteractedTrackedRef = useRef(false) + const activeSkillRuntime = useActiveProjectSkillRuntime() + const setupRuntime = runtimeContext ?? activeSkillRuntime + const runtimeCommand = buildSkillCommandForRuntime( + command, + getOnboardingFeatureSetupAgentRuntime(setupRuntime) + ) const selectionTelemetry = useMemo( () => onboardingFeatureSetupTelemetrySelection(selection), @@ -56,7 +70,8 @@ export function FeatureSetupInlineTerminal({ return ( { + afterEach(() => { + vi.unstubAllGlobals() + }) + it('defaults every setup item on so first-launch setup is ready to run', () => { expect(DEFAULT_ONBOARDING_FEATURE_SETUP_SELECTION).toEqual({ browserUse: true, @@ -123,6 +129,72 @@ describe('onboarding feature setup runner', () => { ) }) + it('wraps the copied command for a WSL runtime', () => { + const text = buildOnboardingFeatureSetupClipboardText( + { browserUse: false, computerUse: false, orchestration: true, linearTickets: false }, + { runtime: 'wsl', wslDistro: 'Ubuntu', label: 'WSL Ubuntu' } + ) + + expect(text).toContain("wsl.exe -d 'Ubuntu'") + expect(text).not.toBe(ORCHESTRATION_ONLY_SKILL_INSTALL_COMMAND) + }) + + it('leaves the copied command bare for a host runtime', () => { + const text = buildOnboardingFeatureSetupClipboardText( + { browserUse: false, computerUse: false, orchestration: true, linearTickets: false }, + { runtime: 'host', label: 'Windows' } + ) + + expect(text).toBe(ORCHESTRATION_ONLY_SKILL_INSTALL_COMMAND) + }) + + it('falls back to the host when the selected runtime needs repair', () => { + expect( + getOnboardingFeatureSetupAgentRuntime({ + agentRuntime: { runtime: 'wsl', wslDistro: 'Missing', label: 'WSL Missing' }, + installDisabledReason: 'The selected WSL distro is unavailable.' + }) + ).toBeUndefined() + }) + + it('uses the WSL CLI APIs for the selected distro', async () => { + const getInstallStatus = vi.fn() + const install = vi.fn() + const getWslInstallStatus = vi.fn(async () => INSTALLED_CLI_STATUS) + const installWsl = vi.fn(async () => INSTALLED_CLI_STATUS) + vi.stubGlobal('window', { + api: { cli: { getInstallStatus, install, getWslInstallStatus, installWsl } } + }) + const deps = createOnboardingFeatureSetupDeps({ + runtime: 'wsl', + wslDistro: 'Ubuntu', + label: 'WSL Ubuntu' + }) + + await deps.getCliStatus() + await deps.installCli() + + expect(getWslInstallStatus).toHaveBeenCalledWith({ distro: 'Ubuntu' }) + expect(installWsl).toHaveBeenCalledWith({ distro: 'Ubuntu' }) + expect(getInstallStatus).not.toHaveBeenCalled() + expect(install).not.toHaveBeenCalled() + }) + + it('keeps the runner on the host when the selected WSL runtime needs repair', async () => { + const deps = createDeps() + + await runOnboardingFeatureSetup( + { browserUse: false, computerUse: false, orchestration: true, linearTickets: false }, + deps, + { + agentRuntime: { runtime: 'wsl', wslDistro: 'Missing', label: 'WSL Missing' }, + installDisabledReason: 'The selected WSL distro is unavailable.' + } + ) + + expect(deps.clipboardWrites).toEqual([ORCHESTRATION_ONLY_SKILL_INSTALL_COMMAND]) + }) + it('builds privacy-safe telemetry payloads for selected feature setup items', () => { const selection: OnboardingFeatureSetupSelection = { browserUse: true, diff --git a/src/renderer/src/components/onboarding/onboarding-feature-setup.ts b/src/renderer/src/components/onboarding/onboarding-feature-setup.ts index 21ab97a13..c5d22985e 100644 --- a/src/renderer/src/components/onboarding/onboarding-feature-setup.ts +++ b/src/renderer/src/components/onboarding/onboarding-feature-setup.ts @@ -13,6 +13,12 @@ import { import { BROWSER_USE_ENABLED_STORAGE_KEY } from '@/lib/browser-use-setup-state' import { e2eConfig } from '@/lib/e2e-config' import { showOrcaCliRegistrationPromptToast } from '@/lib/agent-skill-cli-prerequisite' +import type { ProjectAgentSkillRuntime } from '@/lib/project-skill-runtime' +import type { OnboardingFeatureSetupRuntimeContext } from './onboarding-feature-setup-runtime' +import { + buildSkillCommandForRuntime, + getWslCliDistroRequest +} from '../settings/CliSkillRuntimeSetup' import { ORCHESTRATION_ENABLED_STORAGE_KEY, ORCHESTRATION_SETUP_DISMISSED_STORAGE_KEY, @@ -104,9 +110,12 @@ export function selectedOnboardingFeatureSetupIds( } export function buildOnboardingFeatureSetupClipboardText( - selection: OnboardingFeatureSetupSelection + selection: OnboardingFeatureSetupSelection, + agentRuntime?: ProjectAgentSkillRuntime ): string | null { - return buildOnboardingFeatureSetupSkillCommand(selection) + const command = buildOnboardingFeatureSetupSkillCommand(selection) + // Keep clipboard and terminal commands on the same runtime (#12103). + return command === null ? null : buildSkillCommandForRuntime(command, agentRuntime) } export function buildOnboardingFeatureSetupSkillCommand( @@ -160,16 +169,26 @@ export function onboardingFeatureSetupRunTelemetry( } } -export function createOnboardingFeatureSetupDeps(): OnboardingFeatureSetupDeps { +export function createOnboardingFeatureSetupDeps( + agentRuntime?: ProjectAgentSkillRuntime +): OnboardingFeatureSetupDeps { const e2eDeps = getE2EOnboardingFeatureSetupDeps() if (e2eDeps) { return e2eDeps } + // Register `orca` on the same PATH used by the skill install (#12103). + const wslDistroRequest = + agentRuntime?.runtime === 'wsl' ? getWslCliDistroRequest(agentRuntime) : undefined + const isWsl = agentRuntime?.runtime === 'wsl' return { - getCliStatus: () => window.api.cli.getInstallStatus(), + getCliStatus: () => + isWsl + ? window.api.cli.getWslInstallStatus(wslDistroRequest) + : window.api.cli.getInstallStatus(), showCliRegistrationPrompt: showOrcaCliRegistrationPromptToast, - installCli: () => window.api.cli.install(), + installCli: () => + isWsl ? window.api.cli.installWsl(wslDistroRequest) : window.api.cli.install(), writeClipboardText: (text) => window.api.ui.writeClipboardText(text), getComputerUsePermissionStatus: () => window.api.computerUsePermissions.getStatus(), openComputerUsePermissionSetup: () => window.api.computerUsePermissions.openSetup(), @@ -191,8 +210,13 @@ function getE2EOnboardingFeatureSetupDeps(): OnboardingFeatureSetupDeps | null { export async function runOnboardingFeatureSetup( selection: OnboardingFeatureSetupSelection, - deps: OnboardingFeatureSetupDeps = createOnboardingFeatureSetupDeps() + explicitDeps?: OnboardingFeatureSetupDeps, + runtimeContext?: OnboardingFeatureSetupRuntimeContext ): Promise { + const agentRuntime = runtimeContext?.installDisabledReason + ? undefined + : runtimeContext?.agentRuntime + const deps = explicitDeps ?? createOnboardingFeatureSetupDeps(agentRuntime) const selectedIds = selectedOnboardingFeatureSetupIds(selection) const warnings: OnboardingFeatureSetupWarning[] = [] let cliTouched = false @@ -278,7 +302,7 @@ export async function runOnboardingFeatureSetup( } } - skillCommandsCopied = await copySkillCommands(selection, deps, warnings) + skillCommandsCopied = await copySkillCommands(selection, deps, warnings, agentRuntime) return { selectedIds, @@ -297,9 +321,10 @@ function formatFeatureSetupError(error: unknown): string { async function copySkillCommands( selection: OnboardingFeatureSetupSelection, deps: OnboardingFeatureSetupDeps, - warnings: OnboardingFeatureSetupWarning[] + warnings: OnboardingFeatureSetupWarning[], + agentRuntime?: ProjectAgentSkillRuntime ): Promise { - const clipboardText = buildOnboardingFeatureSetupClipboardText(selection) + const clipboardText = buildOnboardingFeatureSetupClipboardText(selection, agentRuntime) if (!clipboardText) { return false } diff --git a/src/renderer/src/hooks/useActiveProjectSkillRuntime.test.tsx b/src/renderer/src/hooks/useActiveProjectSkillRuntime.test.tsx index 71a725767..2d92fc42e 100644 --- a/src/renderer/src/hooks/useActiveProjectSkillRuntime.test.tsx +++ b/src/renderer/src/hooks/useActiveProjectSkillRuntime.test.tsx @@ -4,6 +4,7 @@ import { renderHook } from '@testing-library/react' import { getDefaultSettings } from '../../../shared/constants' import { useAppStore } from '@/store' import { + hasLocalSkillRuntimeAuthority, shouldUseLocalSkillFreshness, useActiveProjectSkillRuntime } from './useActiveProjectSkillRuntime' @@ -20,10 +21,20 @@ function setWindowsShell(terminalWindowsShell: string): void { }) } +function setGlobalWslDefault(distro: string): void { + useAppStore.setState({ + settings: { + ...getDefaultSettings('/tmp'), + localWindowsRuntimeDefault: { kind: 'wsl', distro } + } + }) +} + describe('useActiveProjectSkillRuntime', () => { beforeEach(() => { setPlatform('win32') setWindowsShell('git-bash') + useAppStore.setState({ runtimeEnvironmentCatalogSettled: true, runtimeEnvironments: [] }) }) afterEach(() => { @@ -39,6 +50,48 @@ describe('useActiveProjectSkillRuntime', () => { expect(result.current.terminalShellOverride).toBe('powershell.exe') }) + it('adopts the global WSL default when no project is active', () => { + setGlobalWslDefault('Ubuntu') + const { result } = renderHook(() => useActiveProjectSkillRuntime()) + + expect(result.current.agentRuntime).toEqual({ + runtime: 'wsl', + wslDistro: 'Ubuntu', + label: 'WSL Ubuntu' + }) + }) + + it('ignores a windows-host global default so skill discovery keeps no target', () => { + const { result } = renderHook(() => useActiveProjectSkillRuntime()) + + expect(result.current.projectRuntime).toBeUndefined() + expect(result.current.discoveryTarget).toBeUndefined() + }) + + it('does not adopt the global default once a project is active', () => { + setGlobalWslDefault('Ubuntu') + useAppStore.setState({ activeRepoId: 'repo-1' }) + const { result } = renderHook(() => useActiveProjectSkillRuntime()) + + expect(result.current.agentRuntime).toBeUndefined() + useAppStore.setState({ activeRepoId: null }) + }) + + it('does not inject the local WSL runtime or shell into a remote environment', () => { + setGlobalWslDefault('Ubuntu') + useAppStore.setState({ + settings: { + ...useAppStore.getState().settings!, + activeRuntimeEnvironmentId: 'ssh-production' + }, + runtimeEnvironments: [{ id: 'ssh-production' }] as never + }) + const { result } = renderHook(() => useActiveProjectSkillRuntime()) + + expect(result.current.agentRuntime).toBeUndefined() + expect(result.current.terminalShellOverride).toBeUndefined() + }) + it('leaves the shell alone on non-Windows hosts', () => { setPlatform('darwin') const { result } = renderHook(() => useActiveProjectSkillRuntime()) @@ -62,4 +115,12 @@ describe('useActiveProjectSkillRuntime', () => { ).toBe(false) expect(shouldUseLocalSkillFreshness(null, undefined)).toBe(false) }) + + it('limits the no-project Windows fallback to local runtime authority', () => { + expect(hasLocalSkillRuntimeAuthority({ kind: 'local' })).toBe(true) + expect( + hasLocalSkillRuntimeAuthority({ kind: 'environment', environmentId: 'ssh-production' }) + ).toBe(false) + expect(hasLocalSkillRuntimeAuthority(null)).toBe(false) + }) }) diff --git a/src/renderer/src/hooks/useActiveProjectSkillRuntime.ts b/src/renderer/src/hooks/useActiveProjectSkillRuntime.ts index 1a6df80b4..2d82512b9 100644 --- a/src/renderer/src/hooks/useActiveProjectSkillRuntime.ts +++ b/src/renderer/src/hooks/useActiveProjectSkillRuntime.ts @@ -4,7 +4,10 @@ import type { ProjectExecutionRuntimeResolution } from '../../../shared/project- import type { SkillDiscoveryTarget } from '../../../shared/skills' import { useActiveSkillDiscoveryRuntimeTarget } from './use-active-skill-discovery-runtime-target' import type { RuntimeClientTarget } from '@/runtime/runtime-rpc-client' -import { getLocalProjectExecutionRuntimeContext } from '@/lib/local-preflight-context' +import { + getGlobalWindowsExecutionRuntimeContext, + getLocalProjectExecutionRuntimeContext +} from '@/lib/local-preflight-context' import { getProjectAgentSkillRuntime, getProjectAgentSkillTerminalShellOverride, @@ -36,6 +39,10 @@ export function shouldUseLocalSkillFreshness( return runtimeTarget?.kind === 'local' && agentRuntime?.runtime !== 'wsl' } +export function hasLocalSkillRuntimeAuthority(runtimeTarget: RuntimeClientTarget | null): boolean { + return runtimeTarget?.kind === 'local' +} + // Why: on Windows the runtime resolution is rebuilt from scratch on every // worktree-store change, so a same-runtime result still arrives with a fresh // identity. Downstream skill discovery keys effects off `discoveryTarget`, so @@ -46,6 +53,17 @@ function activeProjectSkillRuntimeIdentity(runtime: ActiveProjectSkillRuntime): return JSON.stringify(runtime) } +/** Keeps only a WSL-targeting resolution; a windows-host one is the same as having none here. */ +function wslOnly( + resolution: ProjectExecutionRuntimeResolution | undefined +): ProjectExecutionRuntimeResolution | undefined { + if (!resolution) { + return undefined + } + const targetsWsl = resolution.status === 'repair-required' || resolution.runtime.kind === 'wsl' + return targetsWsl ? resolution : undefined +} + export function useActiveProjectSkillRuntime(): ActiveProjectSkillRuntime { const runtimeState = useAppStore( useShallow((state) => ({ @@ -62,23 +80,38 @@ export function useActiveProjectSkillRuntime(): ActiveProjectSkillRuntime { const runtimeTarget = useActiveSkillDiscoveryRuntimeTarget() const resolved = useMemo(() => { - const projectRuntime = getLocalProjectExecutionRuntimeContext( - runtimeState, - undefined, - currentPlatform, - { - wslAvailable: windowsCapabilities.isLoading ? undefined : windowsCapabilities.wslAvailable, - availableWslDistros: windowsCapabilities.isLoading ? null : windowsCapabilities.wslDistros - } - ) + const wslContext = { + wslAvailable: windowsCapabilities.isLoading ? undefined : windowsCapabilities.wslAvailable, + availableWslDistros: windowsCapabilities.isLoading ? null : windowsCapabilities.wslDistros + } + const projectRuntime = + getLocalProjectExecutionRuntimeContext( + runtimeState, + undefined, + currentPlatform, + wslContext + ) ?? + // Global WSL is the only no-project default that changes the install target (#12103). + (hasLocalSkillRuntimeAuthority(runtimeTarget) + ? wslOnly( + getGlobalWindowsExecutionRuntimeContext( + runtimeState, + undefined, + currentPlatform, + wslContext + ) + ) + : undefined) if (!projectRuntime) { // Why: buildSkillCommandForRuntime still builds a Windows host command // without a project runtime, so the terminal has to match that shell. - const terminalShellOverride = getProjectAgentSkillTerminalShellOverride( - currentPlatform, - runtimeState.settings, - undefined - ) + const terminalShellOverride = hasLocalSkillRuntimeAuthority(runtimeTarget) + ? getProjectAgentSkillTerminalShellOverride( + currentPlatform, + runtimeState.settings, + undefined + ) + : undefined const canUseLocalSkillFreshness = shouldUseLocalSkillFreshness(runtimeTarget) if (!terminalShellOverride && !canUseLocalSkillFreshness) { return EMPTY_ACTIVE_PROJECT_SKILL_RUNTIME diff --git a/src/renderer/src/lib/local-preflight-context.ts b/src/renderer/src/lib/local-preflight-context.ts index bfe08d4a8..ddabde956 100644 --- a/src/renderer/src/lib/local-preflight-context.ts +++ b/src/renderer/src/lib/local-preflight-context.ts @@ -78,6 +78,31 @@ export function getLocalProjectExecutionRuntimeContext( }) } +/** Resolves the Windows default only when no project can own the runtime. */ +export function getGlobalWindowsExecutionRuntimeContext( + state: LocalProjectRuntimeState, + worktreeId?: string | null, + appPlatform: NodeJS.Platform = getRendererAppPlatform(), + wslContext: LocalProjectRuntimeWslContext = {} +): ProjectExecutionRuntimeResolution | undefined { + if ( + appPlatform !== 'win32' || + worktreeId || + state.activeRepoId || + state.activeWorktreeId || + !state.settings?.localWindowsRuntimeDefault + ) { + return undefined + } + return resolveProjectExecutionRuntime({ + appPlatform: 'win32', + projectId: getLocalPreflightProjectId(state, worktreeId), + projectRuntimePreference: { kind: 'inherit-global' }, + globalWindowsRuntimeDefault: state.settings.localWindowsRuntimeDefault, + ...wslContext + }) +} + export function getLocalRepoProjectExecutionRuntimeContext( state: LocalProjectRuntimeState, repoId: string | null | undefined, @@ -148,24 +173,16 @@ export function getLocalAgentPreflightContext( return getProjectRuntimePreflightContext(projectRuntime) } - if ( - appPlatform === 'win32' && - !worktreeId && - !state.activeRepoId && - !state.activeWorktreeId && - state.settings?.localWindowsRuntimeDefault - ) { - // Why: Settings -> Agents is global and can mount before any project is - // active; still respect the Windows/WSL runtime default for PATH detection. - return getProjectRuntimePreflightContext( - resolveProjectExecutionRuntime({ - appPlatform: 'win32', - projectId: getLocalPreflightProjectId(state, worktreeId), - projectRuntimePreference: { kind: 'inherit-global' }, - globalWindowsRuntimeDefault: state.settings.localWindowsRuntimeDefault, - ...wslContext - }) - ) + // Why: Settings -> Agents is global and can mount before any project is + // active; still respect the Windows/WSL runtime default for PATH detection. + const globalRuntime = getGlobalWindowsExecutionRuntimeContext( + state, + worktreeId, + appPlatform, + wslContext + ) + if (globalRuntime) { + return getProjectRuntimePreflightContext(globalRuntime) } const explicitAgentRuntime = appPlatform === 'win32' ? state.settings?.localAgentRuntime : null