Skip to content

The agent that grows with you

fix(desktop): first-run kickoff opens the onboarding chat on screen inside main's intro

alt-glitche52742df32c7
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsx
index e66ca109e54..3472f38af40 100644
--- a/apps/desktop/src/app/contrib/wiring.tsx
+++ b/apps/desktop/src/app/contrib/wiring.tsx
@@ -23,6 +23,7 @@ import { FreeTierSignInDialog } from '@/components/free-tier/sign-in-dialog'
import { GatewayConnectingOverlay } from '@/components/gateway-connecting-overlay'
import { NotificationStack } from '@/components/notifications'
import { DesktopOnboardingOverlay } from '@/components/onboarding'
+import { firstRunIntro } from '@/components/onboarding/first-run/kickoff'
import { OnboardingEnd } from '@/components/onboarding/onboarding-end'
import { $newSessionTabAction, registerPaneCloser } from '@/components/pane-shell/tree/store'
import {
@@ -600,15 +601,38 @@ export function ContribWiring({ children }: { children: ReactNode }) {
}
}, [startSessionInWorkspace, startWorkSessionRequest])
- // The main window asks the backend whether first-run onboarding is due and opens it; every other
- // window never runs it, so its first-run surfaces are free at once.
+ // Opens a stored chat on screen: resume it, then route to it (resume alone selects it, the route
+ // stays where it was). Throws when the chat did not become the selected one.
+ const adoptSessionRoute = useCallback(
+ async (storedSessionId: string) => {
+ creatingSessionRef.current = true
+
+ try {
+ await resumeSession(storedSessionId, true)
+
+ if ($selectedStoredSessionId.get() !== storedSessionId) {
+ throw new Error('The onboarding chat could not be opened.')
+ }
+
+ navigate(sessionRoute(storedSessionId), { replace: true })
+ } finally {
+ window.setTimeout(() => {
+ creatingSessionRef.current = false
+ }, 0)
+ }
+ },
+ [navigate, resumeSession]
+ )
+
+ // The main window asks the backend whether first-run onboarding is due and opens it with main's
+ // intro around it; every other window never runs it, so its first-run surfaces are free at once.
useEffect(() => {
if (!isMainWindow()) {
markOnboardingDecided()
} else if (gatewayState === 'open') {
- void decideOnboarding(requestGateway, resumeSession)
+ void decideOnboarding(requestGateway, adoptSessionRoute, { intro: firstRunIntro() })
}
- }, [gatewayState, requestGateway, resumeSession])
+ }, [adoptSessionRoute, gatewayState, requestGateway])
// "New project" DRAG completion: the dialog created a project that was
// dropped onto a chat zone (tab-strip slot / pane edge / pane center). Open
diff --git a/apps/desktop/src/components/onboarding/first-run/kickoff.ts b/apps/desktop/src/components/onboarding/first-run/kickoff.ts
new file mode 100644
index 00000000000..e619dcb9d2b
--- /dev/null
+++ b/apps/desktop/src/components/onboarding/first-run/kickoff.ts
@@ -0,0 +1,81 @@
+import type { OnboardingStartResult } from '@hermes/shared'
+
+import { chatMessageText } from '@/lib/chat-messages'
+import { BACKEND_BOOT_WAIT_TIMEOUT_MS } from '@/lib/with-timeout'
+import { $introStartExit } from '@/store/onboarding-intro'
+import { $onboardingEnded, type OnboardingIntroHooks } from '@/store/onboarding-run'
+import { $activeSessionId } from '@/store/session'
+import { $sessionStates } from '@/store/session-states'
+
+import { $chatOnboardingThreadIds, openDemoLayout } from './assembly'
+import { $introTurnSent, failIntro, leaveIntro, openIntro, startIntro } from './intro'
+
+// The opening turn writes the scripted greeting; a chat that already shows it (a relaunch) skips the copy.
+function hasAssistantWords(runtimeId: null | string): boolean {
+ const messages = runtimeId ? ($sessionStates.get()[runtimeId]?.messages ?? []) : []
+
+ return messages.some(message => message.role === 'assistant' && !message.hidden && chatMessageText(message).trim())
+}
+
+/**
+ * Main's first-run start around `onboarding.start`: the boot overlay holds, the window takes the demo
+ * layout once the start answers, and the intro opens once the returned chat is the one on screen.
+ * Past the boot budget the starting screen offers a way out; the chat then stays closed this launch.
+ */
+export function firstRunIntro(): OnboardingIntroHooks {
+ let abandoned = false
+ let offerExit: ReturnType<typeof setTimeout> | undefined
+
+ const clearExit = () => {
+ clearTimeout(offerExit)
+ $introStartExit.set(null)
+ }
+
+ return {
+ starting: () => {
+ startIntro()
+ $introTurnSent.set(false)
+ offerExit = setTimeout(
+ () =>
+ $introStartExit.set(() => {
+ abandoned = true
+ clearExit()
+ failIntro()
+ }),
+ BACKEND_BOOT_WAIT_TIMEOUT_MS
+ )
+ },
+ started: () => {
+ clearExit()
+
+ if (abandoned) {
+ return false
+ }
+
+ openDemoLayout()
+
+ return true
+ },
+ opened: (started: OnboardingStartResult) => {
+ const runtimeId = $activeSessionId.get()
+
+ $chatOnboardingThreadIds.set([
+ ...new Set([started.stored_session_id, started.session_id, ...(runtimeId ? [runtimeId] : [])])
+ ])
+ // onboarding.start has already submitted the opening turn.
+ $introTurnSent.set(true)
+ openIntro(!hasAssistantWords(runtimeId))
+ },
+ failed: () => {
+ clearExit()
+ failIntro()
+ }
+ }
+}
+
+// The run ended (the model said done, or Skip setup): the intro ends with it.
+$onboardingEnded.listen(outcome => {
+ if (outcome) {
+ leaveIntro()
+ }
+})
diff --git a/apps/desktop/src/store/onboarding-run.ts b/apps/desktop/src/store/onboarding-run.ts
index b21d43919fc..0259c5fd3ea 100644
--- a/apps/desktop/src/store/onboarding-run.ts
+++ b/apps/desktop/src/store/onboarding-run.ts
@@ -90,9 +90,21 @@ async function factsSource(request: OnboardingRequest): Promise<'local' | 'remot
return same ? 'local' : 'remote'
}
+/** The first-run intro around a start (`components/onboarding/first-run/kickoff.ts`). */
+export interface OnboardingIntroHooks {
+ /** Before `onboarding.start`: the boot overlay holds. */
+ starting: () => void
+ /** The start answered, the chat not open yet. False: the user went on without setup, so it stays closed. */
+ started: (started: OnboardingStartResult) => boolean
+ /** The chat is the one on screen. */
+ opened: (started: OnboardingStartResult) => void
+ failed: () => void
+}
+
interface StartOptions {
/** Points the window's gateway at the profile onboarding runs in (`store/profile.ts::ensureGatewayProfile`). */
ensureProfile?: (profile: string) => Promise<void>
+ intro?: OnboardingIntroHooks
rerun?: boolean
}
@@ -100,11 +112,12 @@ interface StartOptions {
export async function startOnboarding(
request: OnboardingRequest,
resume: OnboardingResume,
- { ensureProfile = ensureGatewayProfile, rerun = false }: StartOptions = {}
+ { ensureProfile = ensureGatewayProfile, intro, rerun = false }: StartOptions = {}
): Promise<boolean> {
$onboardingPhase.set('shown')
$onboardingEnded.set(null)
$onboardingChatSeen.set(false)
+ intro?.starting()
try {
await ensureProfile(ONBOARDING_PROFILE)
@@ -115,15 +128,24 @@ export async function startOnboarding(
rerun
})
+ if (intro && !intro.started(started)) {
+ $onboardingSession.set(null)
+ $onboardingPhase.set('failed')
+
+ return false
+ }
+
// The chat is on screen before the run names it, so the presence never sees a gap.
await resume(started.stored_session_id, true)
$onboardingSession.set({ runtimeId: started.session_id, storedId: started.stored_session_id })
+ intro?.opened(started)
return true
} catch (error) {
console.warn('[onboarding] could not start', error)
$onboardingSession.set(null)
$onboardingPhase.set('failed')
+ intro?.failed()
return false
}