The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): the sign-in result shows where you signed in and refreshes connectors
alt-glitch5c3c01d6dc59
diff --git a/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsx b/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsxindex 526036e8f22..b01288e99b4 100644--- a/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsx+++ b/apps/desktop/src/app/capabilities/connectors/connectors-tab.tsx@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button'import type { HermesGateway, ProfileScope } from '@/hermes'import { useI18n } from '@/i18n'import { $freeTierStatus } from '@/store/free-tier'+import { $freeTierSignIn, $openAppWindows } from '@/store/free-tier-sign-in'import { notifyError } from '@/store/notifications'import { installBundledEntry } from '../mcp/install-catalog-entry'@@ -121,6 +122,8 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {const openCard = useMemo(() => cards.find(card => cardKey(card) === openKey) ?? null, [cards, openKey])+ useYieldToSignIn(openCard !== null, setOpenKey)+useOpenFromRoute(cards, profile, setOpenKey, setPendingRename)const bundledEntry = (card: ConnectorCardModel) =>@@ -276,6 +279,29 @@ export function ConnectorsTab({ gateway, profile }: ConnectorsTabProps) {)}+/** An open app window holds the sign-in offer back, and closes when a sign-in starts, so the two+ * never stack. The window's state is stale after a sign-in anyway. */+export function useYieldToSignIn(open: boolean, setOpenKey: (key: null) => void): void {+ useEffect(() => {+ if (!open) {+ return+ }++ $openAppWindows.set($openAppWindows.get() + 1)++ const stop = $freeTierSignIn.subscribe(state => {+ if (state.status !== 'closed') {+ setOpenKey(null)+ }+ })++ return () => {+ stop()+ $openAppWindows.set($openAppWindows.get() - 1)+ }+ }, [open, setOpenKey])+}+function useOpenFromRoute(cards: readonly ConnectorCardModel[],scope: ProfileScope,diff --git a/apps/desktop/src/app/capabilities/connectors/data/keys.ts b/apps/desktop/src/app/capabilities/connectors/data/keys.tsindex 6499a86245f..ac148a1b3e8 100644--- a/apps/desktop/src/app/capabilities/connectors/data/keys.ts+++ b/apps/desktop/src/app/capabilities/connectors/data/keys.ts@@ -54,6 +54,11 @@ export function invalidateConnectors(scope: ProfileScope, ...reads: [ConnectorRe}}+/** A sign-in changed the account the apps ride on, in whichever profile it ran: drop every cached read. */+export function invalidateAllConnectors(): void {+ void queryClient.invalidateQueries({ queryKey: [CONNECTORS_QUERY_ROOT] })+}+export function invalidateConnectorApp(scope: ProfileScope, slug: string): void {void queryClient.invalidateQueries({ queryKey: connectorToolsQueryKey(scope, slug) })void queryClient.invalidateQueries({ queryKey: connectorsListQueryKey(scope) })diff --git a/apps/desktop/src/app/capabilities/connectors/yield-to-sign-in.test.tsx b/apps/desktop/src/app/capabilities/connectors/yield-to-sign-in.test.tsxnew file mode 100644index 00000000000..74bbc9c36ab--- /dev/null+++ b/apps/desktop/src/app/capabilities/connectors/yield-to-sign-in.test.tsx@@ -0,0 +1,24 @@+import { act, renderHook } from '@testing-library/react'+import { afterEach, describe, expect, it, vi } from 'vitest'++import { $freeTierSignIn, $openAppWindows } from '@/store/free-tier-sign-in'++import { useYieldToSignIn } from './connectors-tab'++afterEach(() => $freeTierSignIn.set({ status: 'closed' }))++describe('an open app window and the sign-in', () => {+ it('holds the offer back while open, and closes when a sign-in starts', () => {+ const close = vi.fn()+ const { unmount } = renderHook(() => useYieldToSignIn(true, close))++ expect($openAppWindows.get()).toBe(1)+ expect(close).not.toHaveBeenCalled()++ act(() => $freeTierSignIn.set({ status: 'requested' }))+ expect(close).toHaveBeenCalledWith(null)++ unmount()+ expect($openAppWindows.get()).toBe(0)+ })+})diff --git a/apps/desktop/src/components/free-tier/sign-in-dialog.test.tsx b/apps/desktop/src/components/free-tier/sign-in-dialog.test.tsxindex 75f84794ee9..92d7b68429b 100644--- a/apps/desktop/src/components/free-tier/sign-in-dialog.test.tsx+++ b/apps/desktop/src/components/free-tier/sign-in-dialog.test.tsx@@ -125,17 +125,6 @@ describe('FreeTierSignInDialog', () => {expect($freeTierSignIn.get()).toEqual({ status: 'closed' })})- it('Reconnect for a sign-in made for another profile names that profile in the link', async () => {- const { connectorsTarget } = await import('./sign-in-dialog')- const handoff: AppHandoffStatus = { dropped_toolkits: ['slack'], lines: ['x'], state: 'claimed' }-- expect(connectorsTarget(handoff, { connectionId: 'athena', profile: 'work' })).toBe(- '/capabilities?tab=connectors&connector=slack&profile=work&connection=athena'- )- expect(connectorsTarget(handoff, 'work')).toBe('/capabilities?tab=connectors&connector=slack&profile=work')- expect(connectorsTarget(handoff)).toBe('/capabilities?tab=connectors&connector=slack')- })-it('a move still retrying is a waiting note with no connectors button', async () => {await renderCompleted({ lines: ['Moving your free-tier apps to this account.'], state: 'retrying' })diff --git a/apps/desktop/src/components/free-tier/sign-in-dialog.tsx b/apps/desktop/src/components/free-tier/sign-in-dialog.tsxindex 7bd9537d03e..976a1106f69 100644--- a/apps/desktop/src/components/free-tier/sign-in-dialog.tsx+++ b/apps/desktop/src/components/free-tier/sign-in-dialog.tsx@@ -14,7 +14,7 @@ import {DialogTitle,preventCloseButtonAutoFocus} from '@/components/ui/dialog'-import { getGlobalModelOptions, type ProfileScope } from '@/hermes'+import { getGlobalModelOptions } from '@/hermes'import { type Translations, useI18n } from '@/i18n'import { CheckCircle2, Loader2 } from '@/lib/icons'import {@@ -27,6 +27,7 @@ import {import {$freeTierSignIn,$freeTierTurnCompleted,+ $openAppWindows,beginFreeTierSignIn,claimFreeTierSignIn,closeFreeTierSignIn,@@ -100,6 +101,7 @@ export function FreeTierSignInDialog({ onSelectModel }: FreeTierSignInDialogProp$freeTierStatus.listen(sync),$onboardingSurfaceClear.listen(sync),$localModelOfferPending.listen(sync),+ $openAppWindows.listen(sync),$freeTierTurnCompleted.listen(() => void refreshFreeTierStatus(requestGateway, sameGatewayRoute()))]@@ -307,7 +309,7 @@ function SignedInScreen({finish: (model: null | string, after?: () => void) => voidstate: Extract<FreeTierSignInState, { status: 'completed' }>}) {- const { email, handoff, model, scope } = state+ const { email, handoff, model } = statereturn (<>@@ -336,13 +338,8 @@ function SignedInScreen({</div>)}<Actions>- {connectorsTarget(handoff, scope) ? (- <Button- onClick={() => finish(model, () => openConnectors(handoff, scope))}- size="sm"- type="button"- variant="text"- >+ {connectorsTarget(handoff) ? (+ <Button onClick={() => finish(model, () => openConnectors(handoff))} size="sm" type="button" variant="text">{handoff?.state === 'claimed' ? copy.reconnect : copy.openConnectors}</Button>) : null}@@ -356,7 +353,7 @@ function SignedInScreen({/** What the free tier's apps did, in the backend's own lines. While the move* is still retried the line is a small note that updates itself. */-function HandoffResult({ handoff }: { handoff: AppHandoffStatus }) {+export function HandoffResult({ handoff }: { handoff: AppHandoffStatus }) {if (!handoff.lines.length) {return null}@@ -376,10 +373,8 @@ function HandoffResult({ handoff }: { handoff: AppHandoffStatus }) {/** Where the completed screen's connectors button goes: the one app to* reconnect, the whole list for several, or the list to check when the apps- * probably moved already. Null when there is nothing to do there. A sign-in- * made for another profile names it (and its connection), the same way a- * chat's connector links do, so the page acts in that profile only. */-export function connectorsTarget(handoff: AppHandoffStatus | null, scope?: ProfileScope): null | string {+ * probably moved already. Null when there is nothing to do there. */+export function connectorsTarget(handoff: AppHandoffStatus | null): null | string {const dropped = handoff?.state === 'claimed' ? (handoff.dropped_toolkits ?? []) : []const checkMoved = handoff?.state === 'gone' && handoff.probably_moved === true@@ -393,22 +388,11 @@ export function connectorsTarget(handoff: AppHandoffStatus | null, scope?: Profiparams.set('connector', dropped[0])}- const profile = (typeof scope === 'object' ? scope?.profile : scope)?.trim()- const connectionId = typeof scope === 'object' ? scope?.connectionId?.trim() : null-- if (profile) {- params.set('profile', profile)-- if (connectionId) {- params.set('connection', connectionId)- }- }-return `${CAPABILITIES_ROUTE}?${params.toString()}`}-function openConnectors(handoff: AppHandoffStatus | null, scope?: ProfileScope) {- const target = connectorsTarget(handoff, scope)+function openConnectors(handoff: AppHandoffStatus | null) {+ const target = connectorsTarget(handoff)if (target) {window.location.hash = `#${target}`diff --git a/apps/desktop/src/components/onboarding/flow.test.tsx b/apps/desktop/src/components/onboarding/flow.test.tsxindex 7768b3cb691..7733fffb584 100644--- a/apps/desktop/src/components/onboarding/flow.test.tsx+++ b/apps/desktop/src/components/onboarding/flow.test.tsx@@ -125,3 +125,24 @@ describe('ConfirmingModelPanel model pick', () => {}})})++describe('ConfirmingModelPanel sign-in result', () => {+ it('names the account and what moved before Begin', async () => {+ $desktopOnboarding.set({+ ...confirmingModelState(),+ flow: {+ currentModel: 'gpt-5.6-terra',+ label: 'OpenAI OAuth (ChatGPT)',+ providerSlug: 'openai',+ saving: false,+ signedIn: { email: '[email protected]', handoff: { lines: ['Your apps moved.'], state: 'claimed' } },+ status: 'confirming_model'+ }+ })++ render(<Harness />)++ expect(screen.getByText('[email protected]')).toBeTruthy()+ expect(screen.getByText('Your apps moved.')).toBeTruthy()+ })+})diff --git a/apps/desktop/src/components/onboarding/flow.tsx b/apps/desktop/src/components/onboarding/flow.tsxindex 01c9c190bb6..91901f883c5 100644--- a/apps/desktop/src/components/onboarding/flow.tsx+++ b/apps/desktop/src/components/onboarding/flow.tsx@@ -1,6 +1,7 @@import { useQuery } from '@tanstack/react-query'import { useState } from 'react'+import { HandoffResult } from '@/components/free-tier/sign-in-dialog'import { ModelPickerDialog } from '@/components/model-picker'import { Button } from '@/components/ui/button'import { ErrorIcon } from '@/components/ui/error-state'@@ -16,6 +17,7 @@ import {copyExternalCommand,type OnboardingContext,type OnboardingFlow,+ type OnboardingSignedIn,recheckExternalSignin,setOnboardingCode,setOnboardingModel,@@ -272,6 +274,8 @@ function ConfirmingModelPanel({<div className="grid place-items-center gap-7 py-6 text-center"><DecodedLabel leaving={leaving} text={t.onboarding.connectedProvider(flow.label)} />+ {flow.signedIn ? <SignedInLines leaving={leaving} signedIn={flow.signedIn} /> : null}+<divclassName={cn('grid justify-items-center gap-1.5 transition duration-[360ms] ease-out',@@ -360,6 +364,27 @@ function ConfirmingModelPanel({)}+/** Which account the sign-in landed on and what moved: the free-tier result's own lines. */+function SignedInLines({ leaving, signedIn: { email, handoff } }: { leaving: boolean; signedIn: OnboardingSignedIn }) {+ const { t } = useI18n()++ return (+ <div+ className={cn(+ 'grid justify-items-center gap-1.5 transition duration-[360ms] ease-out',+ leaving ? 'opacity-0 saturate-0' : 'opacity-100 saturate-100'+ )}+ >+ {email ? (+ <p className="text-sm text-muted-foreground">+ {t.freeTier.signedInAsLabel} <span className="font-medium text-foreground">{email}</span>+ </p>+ ) : null}+ {handoff ? <HandoffResult handoff={handoff} /> : null}+ </div>+ )+}+export function DocsLink({ children, href }: { children: React.ReactNode; href: string }) {return (<Button asChild size="xs" variant="text">diff --git a/apps/desktop/src/store/free-tier-offer.test.ts b/apps/desktop/src/store/free-tier-offer.test.tsindex 000441d7ddb..5d4cb84346e 100644--- a/apps/desktop/src/store/free-tier-offer.test.ts+++ b/apps/desktop/src/store/free-tier-offer.test.ts@@ -1,7 +1,13 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { $freeTierStatus, type FreeTierRequester } from '@/store/free-tier'-import { $freeTierSignIn, closeFreeTierSignIn, stopFreeTierOffer, syncFreeTierOffer } from '@/store/free-tier-sign-in'+import {+ $freeTierSignIn,+ $openAppWindows,+ closeFreeTierSignIn,+ stopFreeTierOffer,+ syncFreeTierOffer+} from '@/store/free-tier-sign-in'import { activeGatewayProfileKey, ensureGatewayForProfile } from '@/store/gateway'import { $localModelOfferPending } from '@/store/local-model-offer'import { $onboardingDecided, markOnboardingDecided, setOnboardingSurfaceActive } from '@/store/onboarding-presence'@@ -83,6 +89,20 @@ describe('sign-in offer after a finished task', () => {expect($freeTierSignIn.get().status).toBe('offer')})+ it('waits while an app window is open, so it never covers it', async () => {+ const requestGateway = gateway({ statuses: [status(null)] })+ $openAppWindows.set(1)++ syncFreeTierOffer(status(0), requestGateway)+ await vi.advanceTimersByTimeAsync(0)+ expect(claims(requestGateway)).toBe(0)++ $openAppWindows.set(0)+ syncFreeTierOffer(status(0), requestGateway)+ await vi.advanceTimersByTimeAsync(0)+ expect($freeTierSignIn.get().status).toBe('offer')+ })+it('due now: claims once and opens the offer', async () => {const requestGateway = gateway({ statuses: [status(null)] })diff --git a/apps/desktop/src/store/free-tier-sign-in.test.ts b/apps/desktop/src/store/free-tier-sign-in.test.tsindex 0c80f5e84a8..afb28a35bc3 100644--- a/apps/desktop/src/store/free-tier-sign-in.test.ts+++ b/apps/desktop/src/store/free-tier-sign-in.test.ts@@ -2,7 +2,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import type * as HermesApi from '@/hermes'import type { FreeTierRequester } from '@/store/free-tier'-import { markOnboardingDecided, setOnboardingSurfaceActive } from '@/store/onboarding-presence'import type { AppHandoffStatus } from '@/types/hermes'const startOAuthLogin = vi.fn()@@ -210,39 +209,26 @@ describe('free-tier sign-in long-polls', () => {expect($freeTierSignIn.get()).toMatchObject({ handoff: retrying, status: 'completed' })})- it('shows the onboarding sign-in result only when it moved apps and nothing is on screen', async () => {- const { $freeTierSignIn, showFreeTierSignInResult } = await import('./free-tier-sign-in')- const claimed: AppHandoffStatus = { lines: ['Your apps moved.'], state: 'claimed', updated_at: 't2' }- markOnboardingDecided()-- showFreeTierSignInResult({ handoff_status: null, session_id: 's', status: 'approved' })- expect($freeTierSignIn.get()).toEqual({ status: 'closed' })-- $freeTierSignIn.set({ kind: 'trial', status: 'offer' })- showFreeTierSignInResult({ handoff_status: claimed, session_id: 's', status: 'approved' })- expect($freeTierSignIn.get()).toEqual({ kind: 'trial', status: 'offer' })-- $freeTierSignIn.set({ status: 'closed' })- showFreeTierSignInResult({- account_email: '[email protected]',- handoff_status: claimed,- session_id: 's',- status: 'approved'- })- expect($freeTierSignIn.get()).toMatchObject({ email: '[email protected]', handoff: claimed, status: 'completed' })- })-- it('holds the onboarding sign-in result until onboarding leaves the screen, since it sits above dialogs', async () => {- const { $freeTierSignIn, showFreeTierSignInResult } = await import('./free-tier-sign-in')- const claimed: AppHandoffStatus = { lines: ['Your apps moved.'], state: 'claimed', updated_at: 't2' }- const scope = { connectionId: 'athena', profile: 'work' }- markOnboardingDecided()- setOnboardingSurfaceActive('onboarding', true)+ it('a sign-in drops the cached connector reads, and again when a followed move settles', async () => {+ const { beginFreeTierSignIn } = await import('./free-tier-sign-in')+ const { queryClient } = await import('@/lib/query-client')+ const list = ['connectors', 'default', 'list']+ const stale = () => queryClient.getQueryState(list)?.isInvalidated+ let settle: (handoff: AppHandoffStatus) => void = () => undefined+ queryClient.setQueryData(list, [{ slug: 'linear', status: 'connected' }])+ startOAuthLogin.mockResolvedValueOnce(start('session-moved'))+ pollOAuthSession.mockResolvedValue(approvedWith(retrying))+ getNousHandoffStatus.mockReturnValueOnce(new Promise(resolve => (settle = resolve)))- showFreeTierSignInResult({ handoff_status: claimed, session_id: 's', status: 'approved' }, scope)- expect($freeTierSignIn.get()).toEqual({ status: 'closed' })+ await beginFreeTierSignIn(requestGateway)+ await vi.advanceTimersByTimeAsync(10)+ expect(stale()).toBe(true)- setOnboardingSurfaceActive('onboarding', false)- expect($freeTierSignIn.get()).toMatchObject({ handoff: claimed, scope, status: 'completed' })+ queryClient.setQueryData(list, [])+ expect(stale()).toBe(false)+ settle({ lines: ['Your apps moved.'], state: 'claimed', updated_at: 't2' })+ await vi.advanceTimersByTimeAsync(10)+ expect(stale()).toBe(true)+ queryClient.clear()})})diff --git a/apps/desktop/src/store/free-tier-sign-in.ts b/apps/desktop/src/store/free-tier-sign-in.tsindex 06b8c618eda..18e2c5da591 100644--- a/apps/desktop/src/store/free-tier-sign-in.ts+++ b/apps/desktop/src/store/free-tier-sign-in.ts@@ -1,6 +1,7 @@import type { FreeTierClaimNudgeResult } from '@hermes/shared'import { atom } from 'nanostores'+import { invalidateAllConnectors } from '@/app/capabilities/connectors/data/keys'import {cancelOAuthSession,getNousHandoffStatus,@@ -16,7 +17,7 @@ import type { AppHandoffStatus, FreeTierStatus, OAuthPollResponse } from '@/typeimport { type FreeTierRequester, NOUS_PROVIDER_ID, refreshFreeTierStatus } from './free-tier'import { $localModelOfferPending } from './local-model-offer'-import { afterOnboardingSurfaceClear, onboardingSurfaceActive } from './onboarding-presence'+import { onboardingSurfaceActive } from './onboarding-presence'/** Why a sign-in ended without tokens. Each maps to one ruled screen:* `busy` (the account service asked for a short wait — a busy account, a@@ -42,15 +43,7 @@ export type FreeTierSignInState =| { kind: FreeTierOfferKind; status: 'offer' }// `handoff`: the free tier's apps moving to this account (null when the// sign-in replaced no free tier). Followed while it is still retrying.- // `scope`: the profile the sign-in ran for when it is not the active one,- // so Reconnect opens that profile's apps.- | {- email: null | string- handoff: AppHandoffStatus | null- model: null | string- scope?: ProfileScope- status: 'completed'- }+ | { email: null | string; handoff: AppHandoffStatus | null; model: null | string; status: 'completed' }// `retryAfter`: the seconds the backend asked us to wait before trying// again (0 when it named none); only `busy` screens read it.| { kind: FreeTierSignInFailure; message: null | string; retryAfter: number; status: 'failed' }@@ -213,10 +206,14 @@ export function syncFreeTierOffer(status: FreeTierStatus | null, requestGateway:void claimFreeTierOffer(requestGateway, kind)}+/** Connector app windows on screen. The offer waits for them to close, so it never covers one. */+export const $openAppWindows = atom(0)+// The local-model offer after onboarding goes first; the sign-in offer is claimed once it is answered.const offerBlocked = () =>offerClaiming ||onboardingSurfaceActive() ||+ $openAppWindows.get() > 0 ||$localModelOfferPending.get() ||$freeTierSignIn.get().status !== 'closed'@@ -441,6 +438,7 @@ async function finishSignIn(result: OAuthPollResponse, requestGateway: FreeTierR// completed screen claims the user is signed in.await requestGateway('reload.env').catch(() => undefined)await refreshFreeTierStatus(requestGateway)+ invalidateAllConnectors()if (mine !== attempt) {return@@ -450,7 +448,17 @@ async function finishSignIn(result: OAuthPollResponse, requestGateway: FreeTierRset({ email: result.account_email ?? null, handoff, model: result.model ?? null, status: 'completed' })if (handoff && handoffStillMoving(handoff)) {- void followHandoff(handoff, mine)+ const live = () => mine === attempt && $freeTierSignIn.get().status === 'completed'++ const publish = (next: AppHandoffStatus) => {+ const screen = $freeTierSignIn.get()++ if (screen.status === 'completed') {+ set({ ...screen, handoff: next })+ }+ }++ void followHandoff(handoff, live, publish)}}@@ -459,43 +467,23 @@ export function handoffStillMoving(handoff: AppHandoffStatus): boolean {return handoff.state === 'pending' || handoff.state === 'retrying'}-/** A Nous sign-in that finished in the onboarding picker and replaced the free- * tier: show the same result screen this dialog shows. Onboarding paints above- * every dialog, so the result waits until it leaves the screen; never over a- * sign-in already on screen. `scope` is the profile the sign-in ran for. */-export function showFreeTierSignInResult(result: OAuthPollResponse, scope?: ProfileScope) {- const handoff = result.handoff_status-- if (!handoff) {- return- }-- afterOnboardingSurfaceClear(() => {- if ($freeTierSignIn.get().status !== 'closed') {- return- }-- const mine = ++attempt- clearTimers()- set({ email: result.account_email ?? null, handoff, model: null, scope, status: 'completed' })-- if (handoffStillMoving(handoff)) {- void followHandoff(handoff, mine, scope)- }- })-}-// Failed handoff reads in a row before the result stops following the move. The note on screen stays// true either way: the move continues in the background whether or not this window hears about it.const HANDOFF_READ_RETRIES = 4-// Keep the completed screen's handoff current while the move is retried, until it settles or the-// dialog closes. A failed read leaves the last answer on screen: it already says the move continues.-async function followHandoff(shown: AppHandoffStatus, mine: number, scope?: ProfileScope) {+/** Keep a shown handoff current while the move is retried, until it settles or `live` goes false+ * (the screen showing it left). A failed read leaves the last answer up: it already says the move+ * continues. A settled move changed the apps, so the cached connector reads are dropped. */+export async function followHandoff(+ shown: AppHandoffStatus,+ live: () => boolean,+ publish: (handoff: AppHandoffStatus) => void,+ scope?: ProfileScope+) {let current = shownlet failures = 0- while (mine === attempt && handoffStillMoving(current)) {+ while (live() && handoffStillMoving(current)) {const askedAt = Date.now()try {@@ -512,13 +500,18 @@ async function followHandoff(shown: AppHandoffStatus, mine: number, scope?: Profcontinue}- const screen = $freeTierSignIn.get()+ if (!live()) {+ return+ }++ publish(current)++ if (!handoffStillMoving(current)) {+ invalidateAllConnectors()- if (mine !== attempt || screen.status !== 'completed') {return}- set({ ...screen, handoff: current })await restOfLongPollGap(askedAt)}}diff --git a/apps/desktop/src/store/onboarding.test.ts b/apps/desktop/src/store/onboarding.test.tsindex c46cddfc6b2..9bb9392d68a 100644--- a/apps/desktop/src/store/onboarding.test.ts+++ b/apps/desktop/src/store/onboarding.test.ts@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import * as notifications from '@/store/notifications'import { markOnboardingDecided } from '@/store/onboarding-presence'import { makeOAuthProvider } from '@/test/oauth-provider'-import type { OAuthProvider } from '@/types/hermes'+import type { AppHandoffStatus, OAuthProvider } from '@/types/hermes'import {$desktopOnboarding,@@ -219,7 +219,10 @@ describe('refreshOnboarding', () => {}if (method === 'setup.runtime_check') {- return { ok: false, error: 'Hermes is not connected to any AI provider yet. Run `hermes model` to pick one.' } as never+ return {+ ok: false,+ error: 'Hermes is not connected to any AI provider yet. Run `hermes model` to pick one.'+ } as never}throw new Error(`unexpected gateway method: ${method}`)@@ -546,6 +549,42 @@ describe('OAuth onboarding', () => {vi.restoreAllMocks()})+ it('a Nous sign-in shows its account and what moved on the confirm screen, not in a dialog after it', async () => {+ const { startProviderOAuth } = await import('./onboarding')+ const { $freeTierSignIn } = await import('./free-tier-sign-in')+ const { setOnboardingSurfaceActive } = await import('./onboarding-presence')+ const handoff: AppHandoffStatus = { lines: ['Your apps moved to [email protected]: linear.'], state: 'claimed' }++ installApiMock(async ({ path }) => {+ if (path.endsWith('/start')) {+ return { expires_in: 600, flow: 'device_code', session_id: 's', user_code: 'C', verification_url: 'http://x' }+ }++ if (path.includes('/poll/')) {+ return { account_email: '[email protected]', handoff_status: handoff, session_id: 's', status: 'approved' }+ }++ if (path.startsWith('/api/model/options')) {+ return { providers: [{ models: ['nous/m'], name: 'Nous Portal', slug: 'nous' }] }+ }++ return path.startsWith('/api/model/recommended-default') ? { model: 'nous/m' } : { ok: true }+ })+ vi.spyOn(window, 'open').mockReturnValue(null)+ setOnboardingSurfaceActive('onboarding', true)++ await startProviderOAuth(makeOAuthProvider('nous', 'Nous Portal'), {+ requestGateway: async method =>+ // SAFETY: onboarding reads only `provider_configured` from setup.status and `ok` from the rest.+ (method === 'setup.status' ? { provider_configured: true } : { ok: true }) as never+ })+ await vi.waitFor(() => expect($desktopOnboarding.get().flow.status).toBe('confirming_model'), { timeout: 5000 })++ expect($desktopOnboarding.get().flow).toMatchObject({ signedIn: { email: '[email protected]', handoff } })+ setOnboardingSurfaceActive('onboarding', false)+ expect($freeTierSignIn.get()).toEqual({ status: 'closed' })+ })+it('clears stale readiness errors after OAuth succeeds and model confirmation is shown', async () => {const model = 'anthropic/claude-opus-4.8'const calls: { body?: unknown; path: string }[] = []diff --git a/apps/desktop/src/store/onboarding.ts b/apps/desktop/src/store/onboarding.tsindex d259883efcc..0a224235a57 100644--- a/apps/desktop/src/store/onboarding.ts+++ b/apps/desktop/src/store/onboarding.ts@@ -1,6 +1,7 @@import type { ModelOptionProvider } from '@hermes/shared'import { atom } from 'nanostores'+import { invalidateAllConnectors } from '@/app/capabilities/connectors/data/keys'import {cancelOAuthSession,getGlobalModelOptions,@@ -25,19 +26,31 @@ import {refreshFreeTierStatus,setFreeTierRoute} from '@/store/free-tier'-import { showFreeTierSignInResult } from '@/store/free-tier-sign-in'+import { followHandoff, handoffStillMoving } from '@/store/free-tier-sign-in'import { $gatewayBootGeneration } from '@/store/live-sync'import { setMainModelAssignment } from '@/store/model-assignment'import { dismissNotification, notify, notifyError } from '@/store/notifications'import { afterOnboardingSurfaceClear, onboardingSurfaceOpen } from '@/store/onboarding-presence'import { captureOnboardingScope, type OnboardingScope } from '@/store/onboarding-scope'-import type { OAuthProvider, OAuthStartResponse } from '@/types/hermes'+import type { AppHandoffStatus, OAuthPollResponse, OAuthProvider, OAuthStartResponse } from '@/types/hermes'type PkceStart = Extract<OAuthStartResponse, { flow: 'pkce' }>type DeviceStart = Extract<OAuthStartResponse, { flow: 'device_code' }>export type OnboardingMode = 'apikey' | 'oauth'+export interface OnboardingSignedIn {+ email: null | string+ handoff: AppHandoffStatus | null+}++function signedInFrom(result: OAuthPollResponse): OnboardingSignedIn | undefined {+ const email = result.account_email ?? null+ const handoff = result.handoff_status ?? null++ return email || handoff ? { email, handoff } : undefined+}+export type OnboardingFlow =| { status: 'idle' }| { provider: OAuthProvider; status: 'starting' }@@ -58,6 +71,8 @@ export type OnboardingFlow =label: stringproviderSlug: stringsaving: boolean+ // A Nous sign-in's account and what the free tier's apps did, shown on the screen it happened on.+ signedIn?: OnboardingSignedInstatus: 'confirming_model'}| { detail?: string; message: string; provider?: OAuthProvider; start?: OAuthStartResponse; status: 'error' }@@ -432,7 +447,8 @@ async function completeWithModelConfirm(// When true, a failing runtime check no longer blocks progression — the// user is allowed through onboarding regardless. Used by the API-key path,// where we intentionally don't validate the key (it blocked too many users).- ignoreRuntimeGate = false+ ignoreRuntimeGate = false,+ signedIn?: OnboardingSignedIn) {const generation = flowGeneration@@ -442,6 +458,9 @@ async function completeWithModelConfirm(await ctx.requestGateway('reload.env').catch(() => undefined)}+ // A sign-in can change the account the apps ride on.+ invalidateAllConnectors()+if (generation !== flowGeneration) {return}@@ -519,8 +538,36 @@ async function completeWithModelConfirm(providerSlug: defaults.providerSlug,currentModel: defaults.defaultModel,label: providerLabel,- saving: false+ saving: false,+ signedIn})++ void followSignedInMove(signedIn, generation, ctx.scope)+}++// Keep the confirm screen's line about the moving apps current until the move settles or the screen goes.+async function followSignedInMove(signedIn: OnboardingSignedIn | undefined, generation: number, scope?: ProfileScope) {+ const moving = signedIn?.handoff++ if (!signedIn || !moving || !handoffStillMoving(moving)) {+ return+ }++ const shown = () => {+ const { flow } = $desktopOnboarding.get()++ return generation === flowGeneration && flow.status === 'confirming_model' ? flow : null+ }++ const publish = (handoff: AppHandoffStatus) => {+ const flow = shown()++ if (flow) {+ setFlow({ ...flow, signedIn: { email: signedIn.email, handoff } })+ }+ }++ await followHandoff(moving, () => shown() !== null, publish, scope)}function providerResolutionFailure(reason: null | string) {@@ -974,15 +1021,13 @@ async function pollSession(provider: OAuthProvider, start: DeviceStart, ctx: Onbif (result.status === 'approved') {clearPoll()setFlow({ status: 'success', provider })- // A Nous sign-in that replaced the free tier shows what moved, the same screen the- // free-tier sign-in shows; onboarding carries on underneath.- showFreeTierSignInResult(result, ctx.scope)- await completeWithModelConfirm(ctx, provider.name, [provider.id], reason =>- setFlow({- status: 'error',- provider,- message: providerResolutionFailure(reason)- })+ await completeWithModelConfirm(+ ctx,+ provider.name,+ [provider.id],+ reason => setFlow({ status: 'error', provider, message: providerResolutionFailure(reason) }),+ false,+ signedInFrom(result))return