From 07355f0f5838432afd8a739655da2952c0a5d19d Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 06:11:34 -0800 Subject: [PATCH] fix(cloud): Start in Orca Cloud premerge fixes (localized copy, no casts, derived draft restore, line limits) --- .../CloudWorkspacesStates.tsx | 4 +- .../components/landing/LandingCloudCard.tsx | 3 +- .../NewWorkspaceComposerFooter.tsx | 2 +- .../run-on/CloudStart.fixture.tsx | 3 +- .../run-on/OrcaCloudSetupPanel.tsx | 9 +- .../run-on/RunOnSegmentedControl.tsx | 6 +- .../run-on/cloud-start-actions.ts | 52 ++++++++ .../run-on/cloud-start-model.test.ts | 15 ++- .../run-on/use-cloud-start-composer.ts | 113 +++++------------- .../repository/RepositoryRunOnSection.tsx | 12 +- .../sidebar/NewWorkspaceMoreMenu.tsx | 4 +- src/renderer/src/i18n/locales/en.json | 90 +++++++++++++- .../orca-cloud/cloud-setup-session-seam.ts | 12 ++ .../src/lib/orca-cloud/cloud-start-draft.ts | 6 +- .../src/lib/orca-cloud/run-on-memory.ts | 16 ++- 15 files changed, 237 insertions(+), 110 deletions(-) create mode 100644 src/renderer/src/components/new-workspace/run-on/cloud-start-actions.ts diff --git a/src/renderer/src/components/cloud-workspaces/CloudWorkspacesStates.tsx b/src/renderer/src/components/cloud-workspaces/CloudWorkspacesStates.tsx index 1776b4adc2e..a1d1fec9261 100644 --- a/src/renderer/src/components/cloud-workspaces/CloudWorkspacesStates.tsx +++ b/src/renderer/src/components/cloud-workspaces/CloudWorkspacesStates.tsx @@ -160,7 +160,7 @@ export function EmptyState({ : [ t('auto.components.cloudWorkspaces.emptyMineTitle', 'No cloud workspaces yet'), t( - 'auto.components.cloudWorkspaces.emptyMineBody', + 'components.cloudWorkspaces.emptyMineStartBody', 'Start one and it keeps running while your laptop sleeps.' ) ] @@ -174,7 +174,7 @@ export function EmptyState({ - diff --git a/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx b/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx index 33b4538f5db..6c135a39f91 100644 --- a/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx +++ b/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx @@ -79,7 +79,7 @@ export function NewWorkspaceComposerFooter({ type="button" variant="ghost" size="sm" - className="ml-auto text-xs" + className="ml-auto" onClick={cloudStart.onUseThisComputer} > {t('components.newWorkspace.cloudStart.useThisComputer', 'Use this computer instead')} diff --git a/src/renderer/src/components/new-workspace/run-on/CloudStart.fixture.tsx b/src/renderer/src/components/new-workspace/run-on/CloudStart.fixture.tsx index 082cb94ac10..df2198f01c5 100644 --- a/src/renderer/src/components/new-workspace/run-on/CloudStart.fixture.tsx +++ b/src/renderer/src/components/new-workspace/run-on/CloudStart.fixture.tsx @@ -14,7 +14,8 @@ import { isCloudSetupPanelVisible, type CloudSetupStep } from './cloud-start-model' -import { getCloudPrimaryLabel, type CloudStartView } from './use-cloud-start-composer' +import type { CloudStartView } from './use-cloud-start-composer' +import { getCloudPrimaryLabel } from './cloud-start-actions' import { NewWorkspaceMoreMenu } from '../../sidebar/NewWorkspaceMoreMenu' import { LandingCloudCard } from '../../landing/LandingCloudCard' import { EmptyState } from '../../cloud-workspaces/CloudWorkspacesStates' diff --git a/src/renderer/src/components/new-workspace/run-on/OrcaCloudSetupPanel.tsx b/src/renderer/src/components/new-workspace/run-on/OrcaCloudSetupPanel.tsx index 84063a49ec3..aff153603a3 100644 --- a/src/renderer/src/components/new-workspace/run-on/OrcaCloudSetupPanel.tsx +++ b/src/renderer/src/components/new-workspace/run-on/OrcaCloudSetupPanel.tsx @@ -73,7 +73,14 @@ function planDetail(step: CloudSetupStep, t: Translate): string | null { return t('components.newWorkspace.cloudSetup.spendCap', 'Spend cap reached.') + memberSuffix case 'payment': return t('components.newWorkspace.cloudSetup.paymentFailed', 'Payment failed.') + memberSuffix - default: + case 'github': + return t( + 'components.newWorkspace.cloudSetup.githubNeeded', + 'Orca Cloud clones your code from GitHub. Give access to this repository once.' + ) + case 'sign-in': + case 'plan': + case undefined: return step.canFix === false ? t( 'components.newWorkspace.cloudSetup.planMember', diff --git a/src/renderer/src/components/new-workspace/run-on/RunOnSegmentedControl.tsx b/src/renderer/src/components/new-workspace/run-on/RunOnSegmentedControl.tsx index 1a29e9c8d51..73d54ffd8b8 100644 --- a/src/renderer/src/components/new-workspace/run-on/RunOnSegmentedControl.tsx +++ b/src/renderer/src/components/new-workspace/run-on/RunOnSegmentedControl.tsx @@ -26,7 +26,7 @@ export type RunOnSegmentedControlProps = RunTargetComboboxProps & { /** ⌥⌘1 / ⌥⌘2 (Ctrl+Alt on Windows/Linux) while the composer is open (spec D1, N8). */ export function matchRunOnShortcut( - event: KeyboardEvent, + event: Pick, mac: boolean ): 'local' | 'orca-cloud' | null { const mod = mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey @@ -153,7 +153,7 @@ export default function RunOnSegmentedControl( label: ( - Orca Cloud + {t('components.newWorkspace.runOn.orcaCloud', 'Orca Cloud')} ), disabled: cloudState === 'unreachable', @@ -216,7 +216,7 @@ export default function RunOnSegmentedControl( /> - + void) | null { + if (steps.some((step) => step.id === 'account' && step.state === 'needed')) { + const pick = getOrcaCloudPick({ state: 'signed-out' }) + return pick.kind === 'act' ? pick.run : null + } + const effective: OrcaCloudRunTargetAccess = + availability === 'needs-capability' && access.state !== 'no-plan' + ? { state: 'no-plan', lapsed: false, canManageBilling: true } + : access + const pick = getOrcaCloudPick(effective) + return pick.kind === 'act' ? pick.run : null +} diff --git a/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts b/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts index 9dee26e6934..3ea92cb14b9 100644 --- a/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts +++ b/src/renderer/src/components/new-workspace/run-on/cloud-start-model.test.ts @@ -57,8 +57,19 @@ describe('Run on segment', () => { }) it('matches ⌥⌘1 / ⌥⌘2 on mac and Ctrl+Alt elsewhere', () => { - const key = (init: Partial): KeyboardEvent => - ({ metaKey: false, ctrlKey: false, altKey: false, shiftKey: false, ...init }) as KeyboardEvent + const key = (init: { + code: string + metaKey?: boolean + ctrlKey?: boolean + altKey?: boolean + shiftKey?: boolean + }) => ({ + metaKey: false, + ctrlKey: false, + altKey: false, + shiftKey: false, + ...init + }) expect(matchRunOnShortcut(key({ code: 'Digit1', metaKey: true, altKey: true }), true)).toBe( 'local' ) diff --git a/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts b/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts index fa197909b09..0e3b69b27bb 100644 --- a/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts +++ b/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts @@ -2,9 +2,11 @@ // setup instead of a build that billing would refuse, starts by itself once setup finishes, keeps // the draft on disk, and remembers where each project last started. import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react' -import { translate } from '@/i18n/i18n' import { useAppStore } from '@/store/index' -import type { ReadyProjectHostSetupOption } from '@/lib/project-host-setup-options' +import type { + ProjectHostSetupOption, + ReadyProjectHostSetupOption +} from '@/lib/project-host-setup-options' import { clearCloudStartDraft, readCloudStartDraft, @@ -15,15 +17,16 @@ import { CLOUD_SETUP_AUTO_START, getCloudSetupStarter, readCloudSetupSession, - subscribeCloudSetupSession + getCloudSetupSessionRevision, + subscribeCloudSetupSessionRevision } from '@/lib/orca-cloud/cloud-setup-session-seam' import { readRunOnMemory, recordSuccessfulRunOn } from '@/lib/orca-cloud/run-on-memory' import { LOCAL_EXECUTION_HOST_ID } from '../../../../../shared/execution-host' import { ORCA_CLOUD_RECIPE_ID } from '../../../../../shared/hosted-sandbox/orca-cloud-recipe-id' import type { OrcaCloudAvailability } from '../../../../../shared/orca-yaml-hook-types' -import type { ProjectHostSetupOption } from '@/lib/project-host-setup-options' import { useOrcaCloudRunTargetAccess } from '../orca-cloud-billing-cache' -import { getOrcaCloudPick, type OrcaCloudRunTargetAccess } from '../orca-cloud-run-target-access' +import type { OrcaCloudRunTargetAccess } from '../orca-cloud-run-target-access' +import { getCloudPrimaryLabel, setupActionFor } from './cloud-start-actions' import { deriveCloudSetupSteps, getCloudPrimaryAction, @@ -31,7 +34,6 @@ import { getOrcaCloudSegmentState, isCloudSetupPanelVisible, resolveDefaultRunOn, - type CloudPrimaryAction, type CloudSetupStep } from './cloud-start-model' @@ -46,52 +48,6 @@ export type CloudStartView = { onUseThisComputer?: () => void } -export function getCloudPrimaryLabel(action: CloudPrimaryAction): string { - switch (action) { - case 'start': - return translate('components.newWorkspace.cloudStart.start', 'Start in Orca Cloud') - case 'setUpAndStart': - return translate('components.newWorkspace.cloudStart.setUpAndStart', 'Set up and start') - case 'choosePlanAndStart': - return translate( - 'components.newWorkspace.cloudStart.choosePlanAndStart', - 'Choose plan and start' - ) - case 'renewAndStart': - return translate('components.newWorkspace.cloudStart.renewAndStart', 'Renew and start') - case 'giveAccessAndStart': - return translate( - 'components.newWorkspace.cloudStart.giveAccessAndStart', - 'Give access and start' - ) - case 'useThisComputer': - return translate( - 'components.newWorkspace.cloudStart.useThisComputer', - 'Use this computer instead' - ) - case 'checking': - return translate('components.newWorkspace.cloudStart.checking', 'Checking Orca Cloud…') - } -} - -/** The fix one click on the primary button runs: sign in first, else the plan/billing action. */ -function setupActionFor( - steps: readonly CloudSetupStep[], - access: OrcaCloudRunTargetAccess, - availability: OrcaCloudAvailability -): (() => void) | null { - if (steps.some((step) => step.id === 'account' && step.state === 'needed')) { - const pick = getOrcaCloudPick({ state: 'signed-out' }) - return pick.kind === 'act' ? pick.run : null - } - const effective: OrcaCloudRunTargetAccess = - availability === 'needs-capability' && access.state !== 'no-plan' - ? { state: 'no-plan', lapsed: false, canManageBilling: true } - : access - const pick = getOrcaCloudPick(effective) - return pick.kind === 'act' ? pick.run : null -} - function prefersReducedMotion(): boolean { return ( typeof window !== 'undefined' && @@ -99,17 +55,6 @@ function prefersReducedMotion(): boolean { ) } -let sessionRevision = 0 -function subscribeSessionRevision(listener: () => void): () => void { - return subscribeCloudSetupSession(() => { - sessionRevision += 1 - listener() - }) -} -function getSessionRevision(): number { - return sessionRevision -} - export function useCloudStartComposer({ active, availability, @@ -154,10 +99,18 @@ export function useCloudStartComposer({ const cloudSelected = selectedRecipeId === ORCA_CLOUD_RECIPE_ID const fetched = useOrcaCloudRunTargetAccess(segment === 'enabled' && !accessOverride) const access = accessOverride ?? fetched - const [setupSessionId, setSetupSessionId] = useState(null) - // Re-read the session after each poll; the poller notifies through the seam. + const [startedSessionId, setSetupSessionId] = useState(null) + // A composer reopened after setup (e.g. the Checkout return) resumes its saved draft: derived, + // not copied into state, so it is right on the first render. + const restoredDraft = useMemo( + () => (active && cloudSelected ? readCloudStartDraft(profileId) : null), + [active, cloudSelected, profileId] + ) + const [restoreDone, setRestoreDone] = useState(false) + const restored = restoredDraft !== null && restoredDraft.repoId === repoId && !restoreDone + const setupSessionId = startedSessionId ?? (restored ? restoredDraft.setupSessionId : null) // Subscribing re-renders on each poll; the read itself is a cheap synchronous lookup. - useSyncExternalStore(subscribeSessionRevision, getSessionRevision) + useSyncExternalStore(subscribeCloudSetupSessionRevision, getCloudSetupSessionRevision) const session = readCloudSetupSession(setupSessionId) const steps = useMemo( () => session?.steps ?? deriveCloudSetupSteps({ availability, access }), @@ -206,25 +159,26 @@ export function useCloudStartComposer({ }, [setRecipeId]) // "Use this computer instead": switch, then submit once the switch has rendered. - const [localSubmitPending, setLocalSubmitPending] = useState(false) + const localSubmitPendingRef = useRef(false) const useThisComputer = useCallback(() => { if (!localOption) { return } touchedRef.current = true + localSubmitPendingRef.current = true setRecipeId?.(null) onHostChange?.(localOption.id) - setLocalSubmitPending(true) }, [localOption, onHostChange, setRecipeId]) useEffect(() => { - if (localSubmitPending && !cloudSelected) { - setLocalSubmitPending(false) + if (localSubmitPendingRef.current && !cloudSelected) { + localSubmitPendingRef.current = false onCreate() } - }, [cloudSelected, localSubmitPending, onCreate]) + }, [cloudSelected, onCreate]) // Setup started from this composer: when every required row is done, say "All set" and start. - const [setupStarted, setSetupStarted] = useState(false) + const [startedHere, setSetupStarted] = useState(false) + const setupStarted = startedHere || restored const [allSet, setAllSet] = useState(false) useEffect(() => { const done = action === 'start' || session?.finished === true @@ -235,6 +189,7 @@ export function useCloudStartComposer({ const timer = window.setTimeout( () => { setSetupStarted(false) + setRestoreDone(true) setAllSet(false) onCreate() }, @@ -275,20 +230,6 @@ export function useCloudStartComposer({ .catch(() => fallback?.()) }, [access, agent, availability, profileId, prompt, repoId, setupSessionId, steps]) - // A composer reopened after setup (e.g. the Checkout return) gets its prompt back. - const restoredRef = useRef(false) - useEffect(() => { - if (restoredRef.current || !active || !cloudSelected) { - return - } - restoredRef.current = true - const draft = readCloudStartDraft(profileId) - if (draft && draft.repoId === repoId) { - setSetupSessionId(draft.setupSessionId) - setSetupStarted(true) - } - }, [active, cloudSelected, profileId, repoId]) - const recordCreated = useCallback(() => { if (!repoId) { return diff --git a/src/renderer/src/components/settings/repository/RepositoryRunOnSection.tsx b/src/renderer/src/components/settings/repository/RepositoryRunOnSection.tsx index 5e0f263c8ac..7fe7dfb78c6 100644 --- a/src/renderer/src/components/settings/repository/RepositoryRunOnSection.tsx +++ b/src/renderer/src/components/settings/repository/RepositoryRunOnSection.tsx @@ -18,7 +18,12 @@ export function getRepositoryRunOnSearchEntry(): SettingsSearchEntry { 'components.settings.repository.runOn.description', 'Where new workspaces in this project start. Orca Cloud is used only when it can start.' ), - keywords: ['run on', 'orca cloud', 'this computer', 'default'] + keywords: [ + translate('components.settings.repository.runOn.keywordRunOn', 'run on'), + translate('components.settings.repository.runOn.keywordCloud', 'orca cloud'), + translate('components.settings.repository.runOn.keywordThisComputer', 'this computer'), + translate('components.settings.repository.runOn.keywordDefault', 'default') + ] } } @@ -67,7 +72,10 @@ export function RepositoryRunOnSection({ value: 'local', label: translate('components.newWorkspace.runOn.thisComputer', 'This computer') }, - { value: 'orca-cloud', label: 'Orca Cloud' } + { + value: 'orca-cloud', + label: translate('components.newWorkspace.runOn.orcaCloud', 'Orca Cloud') + } ]} /> diff --git a/src/renderer/src/components/sidebar/NewWorkspaceMoreMenu.tsx b/src/renderer/src/components/sidebar/NewWorkspaceMoreMenu.tsx index 0c964a0b30e..5e96844a749 100644 --- a/src/renderer/src/components/sidebar/NewWorkspaceMoreMenu.tsx +++ b/src/renderer/src/components/sidebar/NewWorkspaceMoreMenu.tsx @@ -32,10 +32,10 @@ export function NewWorkspaceMoreMenu({