Skip to content

The agent that grows with you

fix(desktop): intro ends on the layout Continue, the way out skips, every ending stays on default

alt-glitch9c624df8566f
diff --git a/apps/desktop/src/components/onboarding/first-run/intro.ts b/apps/desktop/src/components/onboarding/first-run/intro.ts
index 330834df06b..4c326f0b5fd 100644
--- a/apps/desktop/src/components/onboarding/first-run/intro.ts
+++ b/apps/desktop/src/components/onboarding/first-run/intro.ts
@@ -1,8 +1,6 @@
import { atom, computed } from 'nanostores'
-import { DEMO_LAYOUT_ID } from '@/app/contrib/layout-presets'
import { PANE_TOGGLE_REVEAL_EVENT } from '@/components/pane-shell'
-import { $activePresetId } from '@/components/pane-shell/tree/store'
import { TIP_CATALOG } from '@/lib/tips/catalog'
import { $sidebarOpen, CHAT_SIDEBAR_PANE_ID } from '@/store/layout'
import { $introView } from '@/store/onboarding-intro'
@@ -69,7 +67,7 @@ export function leaveIntro(): void {
endIntroView()
}
-/** A layout pick (the layout card, `set_theme`, the layout picker) ends the intro and keeps the pick. */
+/** A committed layout (the layout card's Continue, a `set_theme` layout) ends the intro and keeps the pick. */
export function leaveIntroOnLayout(): void {
endIntroView(true)
}
@@ -98,7 +96,6 @@ function watchLeaveActions(): () => void {
const stops = [
() => window.removeEventListener(PANE_TOGGLE_REVEAL_EVENT, onReveal),
$sidebarOpen.listen(() => leaveIntro()),
- $activePresetId.listen(id => id !== DEMO_LAYOUT_ID && leaveIntroOnLayout()),
$activeGatewayProfile.listen(profile => profile !== introProfile && leaveIntro()),
$selectedStoredSessionId.listen(id => (!id || !$chatOnboardingThreadIds.get().includes(id)) && leaveIntro())
]
diff --git a/apps/desktop/src/components/onboarding/first-run/kickoff.test.ts b/apps/desktop/src/components/onboarding/first-run/kickoff.test.ts
index a38a147b4e7..07e946b7178 100644
--- a/apps/desktop/src/components/onboarding/first-run/kickoff.test.ts
+++ b/apps/desktop/src/components/onboarding/first-run/kickoff.test.ts
@@ -35,6 +35,7 @@ beforeEach(() => {
$chatOnboardingSolo.set(false)
$selectedStoredSessionId.set(null)
size.mockClear()
+ adopt.mockClear()
})
describe('first-run kickoff', () => {
@@ -55,8 +56,10 @@ describe('first-run kickoff', () => {
expect($introCopy.get()).toBe('playing')
})
- it('reopens the chat without the demo layout once the user left the intro on an earlier launch', async () => {
- const opened = await startOnboarding(request, adopt, { ensureProfile, intro: firstRunIntro(), introSeen: true })
+ it('reopens a resumed run without the demo layout, at normal size', async () => {
+ // SAFETY: the fake answers onboarding.start with its contract result; nothing else reads the answer.
+ const resumed = async <T>(): Promise<T> => ({ ...started, resumed: true }) as T
+ const opened = await startOnboarding(resumed, adopt, { ensureProfile, intro: firstRunIntro() })
expect(opened).toBe(true)
expect(size).not.toHaveBeenCalled()
@@ -64,15 +67,18 @@ describe('first-run kickoff', () => {
expect($introView.get()).toBe('ended')
})
- it('waits on a slow start with no deadline, and the way out fails it', async () => {
+ it('waits on a slow start with no deadline, and the way out skips the run once the start answers', async () => {
vi.useFakeTimers()
- const deadlines: (number | undefined)[] = []
+ const calls: [string, unknown, number | undefined][] = []
- // A cold start that answers only when abandoned.
- const slow: OnboardingRequest = async <T>(...[, , timeoutMs, signal]: Parameters<OnboardingRequest>): Promise<T> => {
- deadlines.push(timeoutMs)
+ let answer: () => void = () => {}
- return new Promise<T>((_resolve, reject) => signal?.addEventListener('abort', () => reject(new Error('aborted'))))
+ // A cold start that answers late.
+ const slow: OnboardingRequest = async <T>(...[method, params, timeoutMs]: Parameters<OnboardingRequest>): Promise<T> => {
+ calls.push([method, params, timeoutMs])
+
+ // SAFETY: the fake answers onboarding.start with its contract result; the skip's answer is unread.
+ return method === 'onboarding.start' ? new Promise<T>(resolve => (answer = () => resolve(started as T))) : ({} as T)
}
const opening = startOnboarding(slow, adopt, { ensureProfile, intro: firstRunIntro() })
@@ -80,9 +86,13 @@ describe('first-run kickoff', () => {
$introStartExit.get()?.()
vi.useRealTimers()
- expect(await opening).toBe(false)
- expect(deadlines).toEqual([0])
expect($introView.get()).toBe('off')
- expect($onboardingPhase.get()).toBe('failed')
+ expect($onboardingPhase.get()).toBe('skipped')
+ answer()
+
+ expect(await opening).toBe(false)
+ expect(calls.map(([method, , timeout]) => [method, timeout])).toEqual([['onboarding.start', 0], ['onboarding.skip', undefined]])
+ expect(calls[1][1]).toEqual({ session_id: 'rt-1' })
+ expect(adopt).not.toHaveBeenCalledWith('st-1', true)
})
})
diff --git a/apps/desktop/src/components/onboarding/first-run/kickoff.ts b/apps/desktop/src/components/onboarding/first-run/kickoff.ts
index 5d655819e19..07a290b8338 100644
--- a/apps/desktop/src/components/onboarding/first-run/kickoff.ts
+++ b/apps/desktop/src/components/onboarding/first-run/kickoff.ts
@@ -21,12 +21,11 @@ function hasAssistantWords(runtimeId: null | string): boolean {
* 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.
* `onboarding.start` has no deadline: past the boot budget the starting screen offers a way out, which
- * fails the start (`failed` below) so the chat stays closed this launch.
+ * counts as Skip setup. A resumed run (a relaunch mid-run) reopens as a normal chat at normal size.
*/
export function firstRunIntro(): OnboardingIntroHooks {
let offerExit: ReturnType<typeof setTimeout> | undefined
- // The user left this run's intro on an earlier launch: the chat reopens as a normal chat, no demo.
- let left = false
+ let resumed = false
const clearExit = () => {
clearTimeout(offerExit)
@@ -34,16 +33,16 @@ export function firstRunIntro(): OnboardingIntroHooks {
}
return {
- starting: (abandon, seen) => {
- left = seen
+ starting: skip => {
startIntro()
$introTurnSent.set(false)
- offerExit = setTimeout(() => $introStartExit.set(abandon), BACKEND_BOOT_WAIT_TIMEOUT_MS)
+ offerExit = setTimeout(() => $introStartExit.set(skip), BACKEND_BOOT_WAIT_TIMEOUT_MS)
},
- started: () => {
+ started: (started: OnboardingStartResult) => {
clearExit()
+ resumed = started.resumed
- if (!left) {
+ if (!resumed) {
openDemoLayout()
}
},
@@ -56,7 +55,7 @@ export function firstRunIntro(): OnboardingIntroHooks {
// onboarding.start has already submitted the opening turn.
$introTurnSent.set(true)
- if (left) {
+ if (resumed) {
$introView.set('ended')
} else {
openIntro(!hasAssistantWords(runtimeId))
diff --git a/apps/desktop/src/store/onboarding-run.test.ts b/apps/desktop/src/store/onboarding-run.test.ts
index 6c5b2bd125f..d6d2f1d55d3 100644
--- a/apps/desktop/src/store/onboarding-run.test.ts
+++ b/apps/desktop/src/store/onboarding-run.test.ts
@@ -1,6 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
-import { $introView } from './onboarding-intro'
import { $onboardingPhase } from './onboarding-phase'
import { $onboardingDecided, $onboardingSurfaceClear } from './onboarding-presence'
import {
@@ -92,17 +91,17 @@ describe('onboarding run', () => {
expect($onboardingEnded.get()).toBeNull()
})
- it('returns the window to the profile it launched on when the start fails', async () => {
+ it('stays on the default profile when the start fails', async () => {
$activeGatewayProfile.set('work')
const switched = vi.fn(async (_profile: string) => undefined)
const refuse = async (): Promise<never> => Promise.reject(new Error('backend down'))
expect(await startOnboarding(refuse, resume, { ensureProfile: switched })).toBe(false)
- expect(switched.mock.calls).toEqual([['default'], ['work']])
+ expect(switched.mock.calls).toEqual([['default']])
$activeGatewayProfile.set('default')
})
- it('opens a new chat in the launch profile on Skip setup', async () => {
+ it('opens a new chat in the default profile on Skip setup', async () => {
$activeGatewayProfile.set('work')
const { request } = backend({ eligible: true, run: true })
await startOnboarding(request, resume, { ensureProfile })
@@ -113,7 +112,7 @@ describe('onboarding run', () => {
expect($onboardingEnded.get()).toBe('skipped')
expect($freshSessionRequest.get()).toBe(fresh + 1)
- expect($newChatProfile.get()).toBe('work')
+ expect($newChatProfile.get()).toBe('default')
})
it('acks the free-tier notice when the onboarding intro opens', async () => {
@@ -126,15 +125,24 @@ describe('onboarding run', () => {
expect(calls).toContain('free_tier.ack_notice')
})
- it('records the intro as seen when the user first leaves it mid-run', async () => {
- const { calls, request } = backend({ eligible: true, run: true })
- const intro = { failed: vi.fn(), opened: () => $introView.set('intro'), started: vi.fn(), starting: vi.fn() }
+ it("keeps a rerun going when the old run's withdrawn card reports skipped_all first", async () => {
+ const { request } = backend({ eligible: true, run: true })
+ await startOnboarding(request, resume, { ensureProfile })
- await startOnboarding(request, resume, { ensureProfile, intro })
- $introView.set('ended')
- $introView.set('off')
+ // The backend withdraws the old card while the rerun's start is still answering.
+ const rerun = async <T,>(method: string): Promise<T> => {
+ if (method === 'onboarding.start') {
+ noteSetupBeatResult(['rt-1', 'st-1'], { skipped_all: true })
+ }
- expect(calls.filter(method => method === 'onboarding.intro_seen')).toHaveLength(1)
+ // SAFETY: the fake answers onboarding.start with its contract result shape.
+ return { resumed: false, session_id: 'rt-2', stored_session_id: 'st-2' } as T
+ }
+
+ await startOnboarding(rerun, resume, { ensureProfile, rerun: true })
+
+ expect($onboardingPhase.get()).toBe('shown')
+ expect($onboardingEnded.get()).toBeNull()
})
it('keeps the run when the backend refuses the skip', async () => {
diff --git a/apps/desktop/src/store/onboarding-run.ts b/apps/desktop/src/store/onboarding-run.ts
index 77efbe41d5a..d3de48eb85b 100644
--- a/apps/desktop/src/store/onboarding-run.ts
+++ b/apps/desktop/src/store/onboarding-run.ts
@@ -1,6 +1,6 @@
/**
* First-run onboarding as this window runs it: one chat in the default profile, opened by the
- * backend's `onboarding.start`, ended by the model (`setup_beat(beat="done")`) or by Skip setup.
+ * backend's `onboarding.start`, ended by the answer to the first-task card or by Skip setup.
*
* This module is the one writer of `$onboardingPhase` and of the `onboarding` presence surface. The
* surface is open while a run is starting or its chat is on screen; in any other chat the app behaves
@@ -19,13 +19,11 @@ import { getRuntimeI18nLocale } from '@/i18n/runtime'
import type { GatewayRequester } from '@/lib/yolo-session'
import { ackFreeTierNotice } from './free-tier'
-import { activeGatewayConnectionId } from './gateway'
import { clearFreeTierIntro } from './onboarding'
-import { $introView } from './onboarding-intro'
import { $onboardingPhase } from './onboarding-phase'
import { markOnboardingDecided, setOnboardingSurfaceActive } from './onboarding-presence'
import { $onboardingSession } from './onboarding-session'
-import { $activeGatewayProfile, ensureGatewayAgent, ensureGatewayProfile, newSessionInProfile } from './profile'
+import { ensureGatewayProfile, newSessionInProfile } from './profile'
import { $connection, $selectedStoredSessionId } from './session'
import type { SetupBeatToolResult } from './setup-beat'
@@ -49,17 +47,10 @@ export const $onboardingEnded = atom<'done' | 'skipped' | null>(null)
* ended, or the user first left its chat mid-run. Null until then. */
export const $onboardingSettleFrom = atom<null | number>(null)
-// The backend runs onboarding in its root profile whichever profile the app was on.
+// The backend runs onboarding in its root profile whichever profile the app was on; every ending
+// stays there, because the chats the run leaves behind live there.
const ONBOARDING_PROFILE = 'default'
-/** The profile (and registry source) the window was on before the run moved it to the default profile. */
-interface LaunchSource {
- connectionId: null | string
- profile: string
-}
-
-let launch: LaunchSource | null = null
-
/** The run's chat has been on screen at least once; until then a route still opening is not a leave. */
const $onboardingChatSeen = atom(false)
@@ -109,9 +100,9 @@ async function factsSource(request: OnboardingRequest): Promise<'local' | 'remot
/** The first-run intro around a start (`components/onboarding/first-run/kickoff.ts`). */
export interface OnboardingIntroHooks {
- /** Before `onboarding.start`: the boot overlay holds. `abandon`: the user went on without setup; the
- * start fails and the chat stays closed. `seen`: the user left this run's intro on an earlier launch. */
- starting: (abandon: () => void, seen: boolean) => void
+ /** Before `onboarding.start`: the boot overlay holds. `skip`: the user went on without setup while
+ * the start was slow, which counts as Skip setup. */
+ starting: (skip: () => void) => void
/** The start answered, the chat not open yet. */
started: (started: OnboardingStartResult) => void
/** The chat is the one on screen. */
@@ -123,8 +114,6 @@ interface StartOptions {
/** Points the window's gateway at the profile onboarding runs in (`store/profile.ts::ensureGatewayProfile`). */
ensureProfile?: (profile: string) => Promise<void>
intro?: OnboardingIntroHooks
- /** The user left this run's intro on an earlier launch (`onboarding.intro_seen`). */
- introSeen?: boolean
rerun?: boolean
}
@@ -132,26 +121,38 @@ interface StartOptions {
export async function startOnboarding(
request: OnboardingRequest,
resume: OnboardingResume,
- { ensureProfile = ensureGatewayProfile, intro, introSeen = false, rerun = false }: StartOptions = {}
+ { ensureProfile = ensureGatewayProfile, intro, rerun = false }: StartOptions = {}
): Promise<boolean> {
+ // A rerun withdraws the old run's card; its skipped_all must not match this window's session.
+ $onboardingSession.set(null)
$onboardingPhase.set('shown')
$onboardingEnded.set(null)
$onboardingChatSeen.set(false)
- const abandon = new AbortController()
- intro?.starting(() => abandon.abort(), introSeen)
- launch = { connectionId: activeGatewayConnectionId(), profile: $activeGatewayProfile.get() }
+ let skipped = false
+
+ intro?.starting(() => {
+ skipped = true
+ intro?.failed()
+ leaveSkipped()
+ })
try {
await ensureProfile(ONBOARDING_PROFILE)
+ // The request stays alive past the way out: its answer names the run the skip ends.
const started = await request<OnboardingStartResult>(
'onboarding.start',
{ facts_source: await factsSource(request), locale: getRuntimeI18nLocale(), rerun },
- NO_DEADLINE,
- abandon.signal
+ NO_DEADLINE
)
+ if (skipped) {
+ await request('onboarding.skip', { session_id: started.session_id })
+
+ return false
+ }
+
intro?.started(started)
// The chat is on screen before the run names it, so the presence never sees a gap.
@@ -161,20 +162,17 @@ export async function startOnboarding(
if (intro) {
intro.opened(started)
ackFreeTierIntro(request)
- markSeenOnLeave(request)
}
return true
} catch (error) {
- // Going on without setup is the user's choice, not an error.
- if (!abandon.signal.aborted) {
- console.warn('[onboarding] could not start', error)
- }
+ console.warn('[onboarding] could not start', error)
- $onboardingSession.set(null)
- $onboardingPhase.set('failed')
- intro?.failed()
- await returnToLaunchProfile(ensureProfile)
+ if (!skipped) {
+ $onboardingSession.set(null)
+ $onboardingPhase.set('failed')
+ intro?.failed()
+ }
return false
}
@@ -190,34 +188,10 @@ function ackFreeTierIntro(request: OnboardingRequest): void {
})
}
-// Main's rule: once the user leaves the intro mid-run, a relaunch reopens the chat without the demo.
-function markSeenOnLeave(request: OnboardingRequest): void {
- if ($introView.get() !== 'intro') {
- return
- }
-
- const stop = $introView.listen(view => {
- stop()
-
- if (view === 'ended' && $onboardingPhase.get() === 'shown') {
- void request('onboarding.intro_seen').catch(error => console.warn('[onboarding] intro_seen failed', error))
- }
- })
-}
-
-// Like main's failed kickoff: the window goes back to where it was before the switch.
-async function returnToLaunchProfile(ensureProfile: (profile: string) => Promise<void>): Promise<void> {
- if (!launch) {
- return
- }
-
- const { connectionId, profile } = launch
-
- try {
- await (connectionId ? ensureGatewayAgent(connectionId, profile) : ensureProfile(profile))
- } catch (error) {
- console.warn('[onboarding] could not return to the launch profile', error)
- }
+// Skip setup's ending, like main's: the run is over and a fresh chat opens in the onboarding profile.
+function leaveSkipped(): void {
+ endOnboarding('skipped')
+ newSessionInProfile(ONBOARDING_PROFILE)
}
let decision: null | Promise<void> = null
@@ -242,7 +216,7 @@ async function readAndStart(request: OnboardingRequest, resume: OnboardingResume
const state = await request<OnboardingRunStateResult>('onboarding.state')
if (state.run && state.eligible) {
- await startOnboarding(request, resume, { ...options, introSeen: state.intro_seen })
+ await startOnboarding(request, resume, options)
}
} catch (error) {
console.warn('[onboarding] state could not be read', error)
@@ -263,16 +237,14 @@ export function endOnboarding(outcome: 'done' | 'skipped'): void {
$onboardingSettleFrom.set($onboardingSettleFrom.get() ?? Date.now())
}
-/** Skip setup: the backend ends the run and closes the card that waits, and a new chat opens in the
- * profile the window launched on (main's rule). A failed skip leaves the run going, so Skip setup
- * stays on offer; the caller reports the error. */
+/** Skip setup: the backend ends the run and closes the card that waits, and a new chat opens. A failed
+ * skip leaves the run going, so Skip setup stays on offer; the caller reports the error. */
export async function skipOnboarding(request: OnboardingRequest, runtimeId: string): Promise<void> {
await request('onboarding.skip', { session_id: runtimeId })
- endOnboarding('skipped')
- newSessionInProfile(launch?.profile ?? ONBOARDING_PROFILE)
+ leaveSkipped()
}
-/** A `setup_beat` result that ends the run: `completed` (the model said done) or `skipped_all`. `ids`:
+/** A `setup_beat` result that ends the run: `completed` (the first-task card answered) or `skipped_all`. `ids`:
* the event's runtime and stored session; a rerun closes the old chat's card, which must not end the new run. */
export function noteSetupBeatResult(ids: readonly (null | string)[], result: SetupBeatToolResult): void {
const session = $onboardingSession.get()