* fix(onboarding): run skill setup in the configured Windows runtime (#12103) Onboarding was the one skill-setup surface that did not route its install command through the resolved runtime. Settings, the feature-wall panels and the Linear prompt all wrap theirs as `wsl.exe -d <distro> -- sh -c ...` and pass a matching shell override; onboarding spawned a bare terminal and handed it the raw `npx skills add ...`. With Node inside WSL, npx is not on the Windows PATH, so the install failed. The runtime resolver had a second gap behind that: it only consulted per-project settings, and onboarding runs before any project exists. With no project it returned undefined and fell through to the Windows host, ignoring a global WSL default entirely. `getLocalAgentPreflightContext` already had a no-project fallback for PATH detection; the skill-install path had none. - extract that fallback as `getGlobalWindowsExecutionRuntimeContext` and rewire the existing agent-preflight branch through it so the two cannot drift - adopt it in `useActiveProjectSkillRuntime` when no project is active. WSL only: a windows-host default already matches the old no-project behavior, and resolving it would hand skill discovery a target where it had none, re-triggering scans for every host-default user - build the onboarding terminal's command for the runtime and pass its shell override - register the CLI in WSL rather than on the host, so `orca` lands on the PATH the install actually runs on, and wrap the copied command to match * fix(onboarding): keep skill setup runtime consistent * test(onboarding): satisfy runtime settings contract --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -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<string | null>(null)
|
||||
const [featureSetupCommandSelection, setFeatureSetupCommandSelection] =
|
||||
useState<OnboardingFeatureSetupSelection | null>(null)
|
||||
const [featureSetupRuntime, setFeatureSetupRuntime] =
|
||||
useState<OnboardingFeatureSetupRuntimeContext | null>(null)
|
||||
const [setupBusyLabel, setSetupBusyLabel] = useState<string | null>(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 (
|
||||
<div className="space-y-5">
|
||||
@@ -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<OnboardingFeatureSetupId, AgentCapabilityInstallStatus>
|
||||
@@ -236,6 +250,7 @@ function AgentCapabilitySetupControls(props: {
|
||||
{props.featureSetupCommand ? (
|
||||
<FeatureSetupInlineTerminal
|
||||
command={props.featureSetupCommand}
|
||||
runtimeContext={props.featureSetupRuntime ?? undefined}
|
||||
selection={props.featureSetupCommandSelection ?? props.featureSetup}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -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<string | null>(null)
|
||||
const [runtimeContext, setRuntimeContext] = useState<OnboardingFeatureSetupRuntimeContext | null>(
|
||||
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 <FeatureSetupInlineTerminal command={command} selection={BROWSER_ONLY_FEATURE_SETUP} />
|
||||
return (
|
||||
<FeatureSetupInlineTerminal
|
||||
command={command}
|
||||
runtimeContext={runtimeContext ?? undefined}
|
||||
selection={BROWSER_ONLY_FEATURE_SETUP}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -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(
|
||||
<FeatureSetupInlineTerminal command="npx skills add orchestration" selection={SELECTION} />
|
||||
)
|
||||
|
||||
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(
|
||||
<FeatureSetupInlineTerminal command="npx skills add orchestration" selection={SELECTION} />
|
||||
)
|
||||
|
||||
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(
|
||||
<FeatureSetupInlineTerminal
|
||||
command="npx skills add orchestration"
|
||||
runtimeContext={{
|
||||
agentRuntime: { runtime: 'host', label: 'Windows' },
|
||||
installDisabledReason: null,
|
||||
terminalShellOverride: 'cmd.exe'
|
||||
}}
|
||||
selection={SELECTION}
|
||||
/>
|
||||
)
|
||||
|
||||
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'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -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 (
|
||||
<OnboardingInlineCommandTerminal
|
||||
command={command}
|
||||
command={runtimeCommand}
|
||||
shellOverride={setupRuntime.terminalShellOverride}
|
||||
title={translate(
|
||||
'auto.components.onboarding.FeatureSetupInlineTerminal.c767ab7061',
|
||||
'Skill setup'
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { ProjectAgentSkillRuntime } from '@/lib/project-skill-runtime'
|
||||
|
||||
export type OnboardingFeatureSetupRuntimeContext = {
|
||||
agentRuntime?: ProjectAgentSkillRuntime
|
||||
installDisabledReason: string | null
|
||||
terminalShellOverride?: string
|
||||
}
|
||||
|
||||
export function getOnboardingFeatureSetupAgentRuntime(
|
||||
context: OnboardingFeatureSetupRuntimeContext
|
||||
): ProjectAgentSkillRuntime | undefined {
|
||||
return context.installDisabledReason ? undefined : context.agentRuntime
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { CliInstallStatus } from '../../../../shared/cli-install-types'
|
||||
import type {
|
||||
ComputerUsePermissionSetupResult,
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
DEFAULT_ONBOARDING_FEATURE_SETUP_SELECTION,
|
||||
buildOnboardingFeatureSetupClipboardText,
|
||||
createOnboardingFeatureSetupDeps,
|
||||
onboardingFeatureSetupRunTelemetry,
|
||||
onboardingFeatureSetupTelemetryFeature,
|
||||
onboardingFeatureSetupTelemetrySelection,
|
||||
@@ -26,6 +27,7 @@ import {
|
||||
type OnboardingFeatureSetupDeps,
|
||||
type OnboardingFeatureSetupSelection
|
||||
} from './onboarding-feature-setup'
|
||||
import { getOnboardingFeatureSetupAgentRuntime } from './onboarding-feature-setup-runtime'
|
||||
|
||||
const ALL_SKILL_INSTALL_COMMAND = buildAgentFeatureSkillInstallCommand([
|
||||
ORCA_CLI_SKILL_NAME,
|
||||
@@ -100,6 +102,10 @@ function createDeps(
|
||||
}
|
||||
|
||||
describe('onboarding feature setup runner', () => {
|
||||
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,
|
||||
|
||||
@@ -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<OnboardingFeatureSetupResult> {
|
||||
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<boolean> {
|
||||
const clipboardText = buildOnboardingFeatureSetupClipboardText(selection)
|
||||
const clipboardText = buildOnboardingFeatureSetupClipboardText(selection, agentRuntime)
|
||||
if (!clipboardText) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user