The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): Run onboarding again replays the whole first-run intro
alt-glitchaf4a05154e53
diff --git a/apps/desktop/electron/window-growth.test.ts b/apps/desktop/electron/window-growth.test.tsindex 83aced6cb6d..d1dbacdba46 100644--- a/apps/desktop/electron/window-growth.test.ts+++ b/apps/desktop/electron/window-growth.test.ts@@ -4,9 +4,17 @@* placement must be saved.*/import type { Rectangle } from 'electron'-import { describe, expect, it } from 'vitest'+import { describe, expect, it, vi } from 'vitest'-import { isAppSized, markAppSized } from './window-growth'+import { isAppSized, markAppSized, registerWindowSizing } from './window-growth'++const ipc = vi.hoisted(() => new Map<string, (event: unknown, mode: string) => void>())+const WORK_AREA: Rectangle = { height: 1080, width: 1920, x: 0, y: 0 }++vi.mock('electron', () => ({+ ipcMain: { on: (channel: string, listener: (event: unknown, mode: string) => void) => ipc.set(channel, listener) },+ screen: { getDisplayMatching: () => ({ workArea: WORK_AREA }) }+}))function placedWindow(initial: Rectangle) {let bounds = { ...initial }@@ -40,3 +48,38 @@ describe('isAppSized', () => {expect(isAppSized(win)).toBe(false)})})++// The main window as the size IPC sees it: the renderer's webContents, and bounds setBounds moves.+function mainWindow(initial: Rectangle) {+ let bounds = { ...initial }+ const webContents = {}++ return {+ getBounds: () => ({ ...bounds }),+ getNormalBounds: () => ({ ...bounds }),+ isDestroyed: () => false,+ isFullScreen: () => false,+ isMaximized: () => false,+ setBounds: (next: Rectangle) => {+ bounds = { ...next }+ },+ webContents+ }+}++describe('window sizing for the first-run intro', () => {+ it("puts an existing user's window back where it was when the intro ends", () => {+ const placed: Rectangle = { height: 900, width: 1500, x: 40, y: 60 }+ const win = mainWindow(placed)+ // SAFETY: registerWindowSizing reads only the members mainWindow() fakes.+ registerWindowSizing({ enabled: true, mainWindow: () => win as never })+ const size = (mode: string) => ipc.get('hermes:window:size')?.({ sender: win.webContents }, mode)++ size('onboarding')+ expect(win.getBounds()).not.toEqual(placed)++ size('normal')+ expect(win.getBounds()).toEqual(placed)+ expect(isAppSized(win)).toBe(false)+ })+})diff --git a/apps/desktop/electron/window-growth.ts b/apps/desktop/electron/window-growth.tsindex b287b201149..dd57a49927b 100644--- a/apps/desktop/electron/window-growth.ts+++ b/apps/desktop/electron/window-growth.ts@@ -47,6 +47,10 @@ function sizedBounds(mode: WindowSizeMode, bounds: Rectangle, workArea: Rectanglreturn width === bounds.width && height === bounds.height ? null : centeredBounds(workArea, width, height)}+// The bounds each window had when onboarding sized it. Normal puts them back, so an intro replayed+// from Settings leaves an existing user's window where it was.+const beforeOnboarding = new WeakMap<BrowserWindow, Rectangle>()+export function registerWindowSizing({ enabled, mainWindow }: WindowSizingOptions): void {ipcMain.on('hermes:window:size', (event, mode: WindowSizeMode) => {const win = mainWindow()@@ -55,11 +59,28 @@ export function registerWindowSizing({ enabled, mainWindow }: WindowSizingOptionreturn}- if ((mode !== 'normal' && mode !== 'onboarding') || win.isMaximized() || win.isFullScreen()) {+ if (mode !== 'normal' && mode !== 'onboarding') {+ return+ }++ const before = beforeOnboarding.get(win)+ beforeOnboarding.delete(win)++ if (win.isMaximized() || win.isFullScreen()) {return}const bounds = win.getBounds()++ if (mode === 'onboarding') {+ beforeOnboarding.set(win, bounds)+ } else if (before) {+ // The user's own placement, not one this module chose: window-state.json saves it.+ win.setBounds(before, true)++ return+ }+const next = sizedBounds(mode, bounds, screen.getDisplayMatching(bounds).workArea)if (next) {diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsxindex 3472f38af40..72dce57a64c 100644--- a/apps/desktop/src/app/contrib/wiring.tsx+++ b/apps/desktop/src/app/contrib/wiring.tsx@@ -54,7 +54,7 @@ import { $interfaceMode, shownInMode } from '@/store/interface-mode'import { $pinnedSessionIds, pinSession, restoreWorktree, unpinSession } from '@/store/layout'import { notifyError } from '@/store/notifications'import { markOnboardingDecided } from '@/store/onboarding-presence'-import { decideOnboarding } from '@/store/onboarding-run'+import { $onboardingChatOpener, decideOnboarding } from '@/store/onboarding-run'import { $poolLimitsSettingsRequest } from '@/store/pool-limits'import { $previewTarget } from '@/store/preview'import {@@ -634,6 +634,17 @@ export function ContribWiring({ children }: { children: ReactNode }) {}}, [adoptSessionRoute, gatewayState, requestGateway])+ // Settings' Run onboarding again opens its chat the way the launch does.+ useEffect(() => {+ if (!isMainWindow()) {+ return+ }++ $onboardingChatOpener.set(adoptSessionRoute)++ return () => $onboardingChatOpener.set(null)+ }, [adoptSessionRoute])+// "New project" DRAG completion: the dialog created a project that was// dropped onto a chat zone (tab-strip slot / pane edge / pane center). Open// its fresh session draft exactly there — the same `openNewSessionTile`diff --git a/apps/desktop/src/app/settings/config-settings.test.tsx b/apps/desktop/src/app/settings/config-settings.test.tsxindex abbb504c7d7..8042833b24f 100644--- a/apps/desktop/src/app/settings/config-settings.test.tsx+++ b/apps/desktop/src/app/settings/config-settings.test.tsx@@ -54,6 +54,7 @@ vi.mock('@/store/settings-scope', () => ({}))vi.mock('@/store/projects', () => ({+ $worktreeRefreshToken: atom(0),repoDiscoveryPolicyFromConfig: () => ({ enabled: true, roots: [], exclude_paths: [] }),repoDiscoveryPolicySignature: (policy: unknown) => JSON.stringify(policy),scanAndRecordRepos: vi.fn().mockResolvedValue(undefined)diff --git a/apps/desktop/src/app/settings/onboarding-settings.test.tsx b/apps/desktop/src/app/settings/onboarding-settings.test.tsxnew file mode 100644index 00000000000..60e526dfa21--- /dev/null+++ b/apps/desktop/src/app/settings/onboarding-settings.test.tsx@@ -0,0 +1,115 @@+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'++import { DEMO_LAYOUT_ID, registerLayoutPresets } from '@/app/contrib/layout-presets'+import { endChatOnboardingSolo } from '@/components/onboarding/first-run/assembly'+import { $introCopy, skipIntro } from '@/components/onboarding/first-run/intro'+import { group } from '@/components/pane-shell/tree/model'+import { applyLayoutPreset } from '@/components/pane-shell/tree/presets'+import { $activePresetId, $layoutTree } from '@/components/pane-shell/tree/store'+import { $chatOnboardingSolo, $introView } from '@/store/onboarding-intro'+import { $onboardingPhase } from '@/store/onboarding-phase'+import { $onboardingChatOpener, noteOnboardingEnded, skipOnboarding } from '@/store/onboarding-run'+import { $activeSessionId, $connection, $selectedStoredSessionId } from '@/store/session'++import { OnboardingSettings } from './onboarding-settings'++const started = { resumed: false, run_id: 'run-2', session_id: 'rt-2', stored_session_id: 'st-2' }+const calls: [string, unknown][] = []++// SAFETY: the fake answers onboarding.start / onboarding.state with the fields the start reads.+const requestGateway = vi.fn(async <T,>(method: string, params?: unknown): Promise<T> => {+ calls.push([method, params])++ return (+ method === 'onboarding.state' ? { eligible: true, run: true, run_id: 'run-2', session_id: 'st-2' } : started+ ) as T+})++vi.mock('@/app/gateway/hooks/use-gateway-request', () => ({ useGatewayRequest: () => ({ requestGateway }) }))++const size = vi.fn()++// The shell's opener (wiring.tsx::adoptSessionRoute): the stored chat becomes the selected, routed one.+const adopt = vi.fn(async (storedId: string) => {+ $selectedStoredSessionId.set(storedId)+ $activeSessionId.set('rt-2')+})++beforeAll(() => {+ registerLayoutPresets()+})++beforeEach(() => {+ Object.defineProperty(window, 'hermesDesktop', {+ configurable: true,+ value: { chatOnboarding: { size }, guestOnboardingEnabled: true }+ })+ // SAFETY: factsSource reads only `mode`.+ $connection.set({ mode: 'local' } as never)+ $onboardingChatOpener.set(adopt)+ $onboardingPhase.set('idle')+ $introView.set('off')+ // Out of the last case's demo, if it left one up.+ endChatOnboardingSolo()+ // An existing user's own arrangement, from before the rerun.+ applyLayoutPreset('mine', group(['workspace']))+ // The chat the user was on.+ $selectedStoredSessionId.set('st-old')+ $activeSessionId.set('rt-old')+ calls.length = 0+ size.mockClear()+})++afterEach(cleanup)++async function runAgain() {+ const mine = $layoutTree.get()+ const views: string[] = []+ const stop = $introView.listen(view => views.push(view))++ render(<OnboardingSettings />)+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Run again' })))+ stop()++ return { mine, views }+}++describe('Settings > Run onboarding again', () => {+ it('replays the whole first-run intro in a new chat', async () => {+ const { views } = await runAgain()++ expect(calls.find(([method]) => method === 'onboarding.start')?.[1]).toMatchObject({ rerun: true })+ expect(adopt).toHaveBeenCalledWith('st-2', true)+ // The boot overlay holds while the chat opens, then the intro plays over the demo layout.+ expect(views).toEqual(['starting', 'intro'])+ expect(size).toHaveBeenCalledWith('onboarding')+ expect($chatOnboardingSolo.get()).toBe(true)+ expect($activePresetId.get()).toBe(DEMO_LAYOUT_ID)+ // The new chat is blank, so the intro copy plays.+ expect($introCopy.get()).toBe('playing')+ })++ it("puts the user's layout and window size back when the run ends", async () => {+ const { mine } = await runAgain()++ act(() => noteOnboardingEnded({ outcome: 'done', run_id: 'run-2', stored_session_id: 'st-2' }))++ expect($chatOnboardingSolo.get()).toBe(false)+ expect(size).toHaveBeenLastCalledWith('normal')+ expect($layoutTree.get()).toEqual(mine)+ expect($activePresetId.get()).toBe('mine')+ })++ it("puts the user's layout and window size back on Skip setup", async () => {+ const { mine } = await runAgain()++ // What the Skip setup button does.+ await act(async () => skipOnboarding(requestGateway, 'rt-2').then(skipIntro))++ expect($chatOnboardingSolo.get()).toBe(false)+ expect(size).toHaveBeenLastCalledWith('normal')+ expect($layoutTree.get()).toEqual(mine)+ expect($activePresetId.get()).toBe('mine')+ })+})diff --git a/apps/desktop/src/app/settings/onboarding-settings.tsx b/apps/desktop/src/app/settings/onboarding-settings.tsxindex f8dc7a18978..f3ba0b1f796 100644--- a/apps/desktop/src/app/settings/onboarding-settings.tsx+++ b/apps/desktop/src/app/settings/onboarding-settings.tsx@@ -1,13 +1,12 @@import { useState } from 'react'import { useGatewayRequest } from '@/app/gateway/hooks/use-gateway-request'-import { sessionRoute } from '@/app/routes'+import { firstRunIntro } from '@/components/onboarding/first-run/kickoff'import { Button } from '@/components/ui/button'import { useI18n } from '@/i18n'import { isOnboardingEnabled } from '@/lib/onboarding-enabled'import { notifyError } from '@/store/notifications'-import { startOnboarding } from '@/store/onboarding-run'-import { requestRoute } from '@/store/recovery-requests'+import { $onboardingChatOpener, startOnboarding } from '@/store/onboarding-run'import { ListRow } from './primitives'@@ -24,9 +23,12 @@ function RerunOnboardingRow() {const rerun = async () => {setStarting(true)- const started = await startOnboarding(requestGateway, async storedId => requestRoute(sessionRoute(storedId)), {- rerun: true- })+ // The whole first-run experience again: the boot overlay, the onboarding-sized window, the demo+ // layout and the intro, in a new chat opened the way the launch opens it.+ const open = $onboardingChatOpener.get()++ const started =+ open !== null && (await startOnboarding(requestGateway, open, { intro: firstRunIntro(), rerun: true }))setStarting(false)diff --git a/apps/desktop/src/components/gateway-connecting-overlay.test.tsx b/apps/desktop/src/components/gateway-connecting-overlay.test.tsxindex efaffa7d2ac..22e43a09644 100644--- a/apps/desktop/src/components/gateway-connecting-overlay.test.tsx+++ b/apps/desktop/src/components/gateway-connecting-overlay.test.tsx@@ -1,9 +1,11 @@import { act, cleanup, render, screen } from '@testing-library/react'-import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { $desktopBoot } from '@/store/boot'import { $gatewaySwitching } from '@/store/gateway-switch'import { $desktopOnboarding } from '@/store/onboarding'+import { $introView } from '@/store/onboarding-intro'+import { markOnboardingDecided } from '@/store/onboarding-presence'import { setGatewayState } from '@/store/session'import { BootFailureOverlay } from './boot-failure-overlay'@@ -174,3 +176,33 @@ describe('connecting overlay vs recovery surface', () => {expect(isConnectingShown()).toBe(false)})})++describe('first-run starting screen', () => {+ afterEach(() => {+ $introView.set('off')+ vi.useRealTimers()+ })++ it('comes back over a booted app while Run onboarding again opens its chat, then leaves', async () => {+ vi.useFakeTimers()+ setGatewayState('open')+ markOnboardingDecided()++ await act(async () => {+ render(<GatewayConnectingOverlay />)+ })+ expect(isConnectingShown()).toBe(false)++ await act(async () => $introView.set('starting'))+ expect(isConnectingShown()).toBe(true)++ await act(async () => $introView.set('intro'))++ // The exit choreography: text out, then the overlay fades.+ for (let step = 0; step < 3; step += 1) {+ await act(async () => vi.advanceTimersByTime(1_000))+ }++ expect(isConnectingShown()).toBe(false)+ })+})diff --git a/apps/desktop/src/components/gateway-connecting-overlay.tsx b/apps/desktop/src/components/gateway-connecting-overlay.tsxindex 597787b362b..de7ad209215 100644--- a/apps/desktop/src/components/gateway-connecting-overlay.tsx+++ b/apps/desktop/src/components/gateway-connecting-overlay.tsx@@ -117,7 +117,7 @@ function ConnectingOverlayView({ decoding, onExit, phase }: ConnectingOverlayVie* Held until the app knows whether onboarding runs, so the chat never flashes before it; the due* check has its own short deadline (`decideOnboarding`). Once onboarding runs, the first-run intro's* `starting` screen is this overlay and stays up until its chat is open, offering a way out when the- * start is slow.+ * start is slow. A rerun from Settings brings that screen back after boot.*/function useOnboardingHold(previewing: boolean) {const onboardingDecided = useStore($onboardingDecided)@@ -129,6 +129,7 @@ function useOnboardingHold(previewing: boolean) {return {holds: introStarting || (watching && !onboardingDecided),+ introStarting,onExit: introStarting ? introStartExit : null}}@@ -138,7 +139,7 @@ export function GatewayConnectingOverlay() {const boot = useStore($desktopBoot)const gatewaySwitching = useStore($gatewaySwitching)const [previewing] = useState(forcedPreview)- const { holds: onboardingHolds, onExit } = useOnboardingHold(previewing)+ const { holds: onboardingHolds, introStarting, onExit } = useOnboardingHold(previewing)const reduce = prefersReducedMotion()// Under reduced motion, skip the multi-phase exit choreography (text-out →// hold → overlay fade) and jump straight to gone so the overlay unmounts@@ -160,10 +161,17 @@ export function GatewayConnectingOverlay() {// kicks in doesn't unmount us and cause a flash.const shownRef = useRef(false)- if (previewing || connecting) {+ // Run onboarding again (Settings) brings the starting screen back over an app that already booted.+ if (previewing || connecting || introStarting) {shownRef.current = true}+ useEffect(() => {+ if (introStarting && phase !== 'live') {+ setPhase('live')+ }+ }, [introStarting, phase])+// Kick off the exit when connected: real connect, or a faked timer in preview.useEffect(() => {if (phase !== 'live') {diff --git a/apps/desktop/src/store/onboarding-run.ts b/apps/desktop/src/store/onboarding-run.tsindex a76909620b6..88700be9d57 100644--- a/apps/desktop/src/store/onboarding-run.ts+++ b/apps/desktop/src/store/onboarding-run.ts@@ -41,6 +41,10 @@ const NO_DEADLINE = 0/** Opens a stored session on screen, replacing the route (`useSessionActions().resumeSession`). */export type OnboardingResume = (storedId: string, replaceRoute?: boolean) => Promise<void>+/** Opens a stored chat on screen the way the launch does (`wiring.tsx::adoptSessionRoute`); the main+ * window's shell sets it. Settings' Run onboarding again opens its chat through it. */+export const $onboardingChatOpener = atom<null | OnboardingResume>(null)+/** How the last run in this window ended; the end-of-onboarding surfaces wake on it. */export const $onboardingEnded = atom<'done' | 'skipped' | null>(null)