diff --git a/src/main/orca-cloud-agents/claude-setup-code.test.ts b/src/main/orca-cloud-agents/claude-setup-code.test.ts index 50b58d21f37..9f43fc3acf2 100644 --- a/src/main/orca-cloud-agents/claude-setup-code.test.ts +++ b/src/main/orca-cloud-agents/claude-setup-code.test.ts @@ -235,6 +235,24 @@ describe('service: the code from the strip, Settings or the chat UI', () => { expect(service.setups().claude).toMatchObject({ phase: 'browser', canReopen: false }) }) + it('Cancel ends the attempt: the CLI is killed and setup goes back to idle, even mid-paste', async () => { + const { service, children, broadcasts } = setup() + service.start('claude') + await tick() + children[0]!.emit(`${AUTHORIZE}\n${PROMPT}`) + service.submitClaudeCode(CODE) + await service.cancel('claude') + await tick() + expect(children[0]!.kill).toHaveBeenCalled() + expect(service.setups().claude).toEqual({ phase: 'idle' }) + expect(broadcasts.at(-1)?.claude).toEqual({ phase: 'idle' }) + // Nothing the dead run says afterwards brings the paste state back. + children[0]!.emit(`${AUTHORIZE}\n${PROMPT}`) + children[0]!.exit() + await tick() + expect(service.setups().claude).toEqual({ phase: 'idle' }) + }) + it('the 10-minute timeout also ends as expired, not a silent spin', async () => { vi.useFakeTimers() try { diff --git a/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.fixture.tsx b/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.fixture.tsx index 06e9bf9da12..f3b2e74e4f3 100644 --- a/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.fixture.tsx +++ b/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.fixture.tsx @@ -237,3 +237,8 @@ export const notSetUpBrowserCodeRejectedNarrow = fixture({ }, width: 420 }) +/** The moment after a refusal, before the fresh link: field and "Open again" stay, disabled. */ +export const notSetUpBrowserCodeGapNarrow = fixture({ + setUp: { setup: { phase: 'browser', startedAt: 0, canReopen: false, code: 'rejected' } }, + width: 420 +}) diff --git a/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.tsx b/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.tsx index 2b2b2f31fb9..13fb0dc77e3 100644 --- a/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.tsx +++ b/src/renderer/src/components/agent-sign-in-strip/CloudAgentSignInStrip.tsx @@ -147,6 +147,15 @@ export function CloudAgentSignInStrip({ wrap?: boolean }): React.JSX.Element { const sectionRef = useRef(null) + // The strip had focus and its focused control went away with a state change ("Set up once" becomes + // the paste step): focus stays on the strip, so Escape still cancels (it only listens inside). + const focusInside = useRef(false) + useLayoutEffect(() => { + const section = sectionRef.current + if (focusInside.current && section && document.activeElement === document.body) { + section.focus({ preventScroll: true }) + } + }) const width = useLiveStripWidth(sectionRef, initialWidth) const compact = width === 'compact' // The detail leaves the line when there's no room for it beside the title: below 360 px, and on the @@ -174,6 +183,15 @@ export function CloudAgentSignInStrip({ aria-labelledby={titleId} aria-describedby={detailId} tabIndex={-1} + onFocus={() => { + focusInside.current = true + }} + onBlur={(event) => { + // A control removed under focus blurs with no next target: the strip keeps the focus. + if (event.relatedTarget !== null && !event.currentTarget.contains(event.relatedTarget)) { + focusInside.current = false + } + }} data-cloud-sign-in-strip onKeyDown={(event) => { if (event.key === 'Escape') { @@ -321,7 +339,10 @@ export function CloudAgentSignInStrip({ {stacked && setupCode ? ( // Row 2, under the text: [Paste code ……] [Finish setup] then "Open again" as a quiet button. -
+
(model.primary ? actions.primary(model.primary.action) : undefined)} + aria-disabled={model.primary.busy || undefined} + onClick={() => + model.primary && !model.primary.busy + ? actions.primary(model.primary.action) + : undefined + } > {model.primary.label} diff --git a/src/renderer/src/components/agent-sign-in-strip/CloudStripPasteForm.tsx b/src/renderer/src/components/agent-sign-in-strip/CloudStripPasteForm.tsx index 3d9b42a25e5..fb32333f80e 100644 --- a/src/renderer/src/components/agent-sign-in-strip/CloudStripPasteForm.tsx +++ b/src/renderer/src/components/agent-sign-in-strip/CloudStripPasteForm.tsx @@ -30,7 +30,7 @@ export function CloudStripPasteForm({ const [code, setCode] = useState('') const inputRef = useRef(null) const setupCode = paste.setupCode - const busy = paste.submitting + const busy = paste.submitting || paste.disabled === true // A refused code: the field is already empty; keep the person's place in it. useEffect(() => { if (paste.refusal) { @@ -79,11 +79,7 @@ export function CloudStripPasteForm({ } }} variant="code" - className={cn( - 'h-7 min-w-0', - setupCode && !fill && 'w-40', - fill && 'flex-1' - )} + className={cn('h-7 min-w-0', setupCode && !fill && 'w-40', fill && 'flex-1')} />