The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a layout preview never touches saved layouts, and a committed layout leaves the demo first
alt-glitch5ddcffe4bd74
diff --git a/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts b/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.tsindex 4c38700976a..7da8059865e 100644--- a/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts+++ b/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts@@ -1,7 +1,7 @@import { useEffect, useRef, useState } from 'react'import { snapshotChatLayout } from '@/components/onboarding/first-run/assembly'-import { applyAppearance } from '@/store/appearance-apply'+import { applyDesktopLayoutPreset } from '@/store/pane-focus'import { $accentOverride, setAccentOverride } from '@/themes/accent-override'import { NOUS_ACCENT, resolveAccentPick } from '@/themes/accents'@@ -26,15 +26,40 @@ const ACCENT: LiveLook = {}}+// A layout previews as an arrangement in the current mode; Continue applies it for real (switching+// Simple/Advanced when the preset needs it), so a cancelled preview never touches either mode's saved layout.const LAYOUT: LiveLook = {apply: value => {if (value) {- applyAppearance({ layout: value })+ applyDesktopLayoutPreset(value)}},snapshot: snapshotChatLayout}+// One undo per look while any card previews it: two open cards share the value from before the first+// preview, and only the last card to close without Continue puts it back.+/** One open card's claim on a look's undo. */+interface PreviewOwner {+ readonly card: symbol+}++interface Baseline {+ owners: Set<PreviewOwner>+ revert: () => void+}++const baselines = new Map<LiveLook, Baseline>()++function release(live: LiveLook, owner: PreviewOwner): void {+ const baseline = baselines.get(live)++ if (baseline?.owners.delete(owner) && baseline.owners.size === 0) {+ baselines.delete(live)+ baseline.revert()+ }+}+export interface LookPreview {/** Answer with the staged pick; leaving keeps it when `send` returns true. */commit: (send: (value: null | string) => boolean) => void@@ -42,23 +67,21 @@ export interface LookPreview {staged: null | StagedLook}-/** Click previews a look live and keeps the value it replaced; a card that unmounts without `settle`- * (cancel, timeout, Skip setup, words in the composer) puts that value back. */+/** Click previews a look live; a card that unmounts without Continue (cancel, timeout, Skip setup,+ * words in the composer) puts back the value from before the preview. */export function useLookPreview(kind: 'accent' | 'layout', dark: boolean): LookPreview {const live = kind === 'accent' ? ACCENT : LAYOUTconst [staged, setStaged] = useState<null | StagedLook>(null)- const revert = useRef<(() => void) | null>(null)+ const owner = useRef<PreviewOwner>({ card: Symbol('look-preview') }).currentconst settled = useRef(false)useEffect(() => () => {if (!settled.current) {- revert.current?.()+ release(live, owner)}-- revert.current = null},- []+ [live, owner])return {@@ -70,9 +93,17 @@ export function useLookPreview(kind: 'accent' | 'layout', dark: boolean): LookPrsettled.current = truesettled.current = send(staged.value)++ // The sent value is the new truth: no open card puts the old one back.+ if (settled.current) {+ baselines.delete(live)+ }},stage: value => {- revert.current ??= live.snapshot()+ const baseline = baselines.get(live) ?? { owners: new Set<PreviewOwner>(), revert: live.snapshot() }++ baseline.owners.add(owner)+ baselines.set(live, baseline)live.apply(value, dark)setStaged({ value })},diff --git a/apps/desktop/src/components/onboarding/first-run/assembly.ts b/apps/desktop/src/components/onboarding/first-run/assembly.tsindex 29ddfd09cd1..b813ca07e14 100644--- a/apps/desktop/src/components/onboarding/first-run/assembly.ts+++ b/apps/desktop/src/components/onboarding/first-run/assembly.ts@@ -150,32 +150,17 @@ export function assembleChatOnboarding(id: string, tree: LayoutNode, mode?: IntereconcileLayout(id, tree)}+/** A layout preview's undo: the arrangement it replaced. A preview never switches Simple/Advanced and+ * never ends the intro, so the arrangement is all there is to put back. */export function snapshotChatLayout(): () => void {const snapshot = {id: $activePresetId.get(),- mode: $interfaceMode.get(),panes: $paneStates.get(),- picked: $chatLayoutPicked.get(),placed: $userPlacedPanes.get(),- previous: previousLayout,- solo: $chatOnboardingSolo.get(),tree: $layoutTree.get()}return () => {- if (snapshot.mode !== $interfaceMode.get()) {- setInterfaceMode(snapshot.mode)- }-- // A pick made in the demo ended the intro, so undoing it lands on the user's own layout.- if (snapshot.solo) {- previousLayout = snapshot.previous- restorePreviousLayout()- $chatLayoutPicked.set(snapshot.picked)-- return- }-if (snapshot.tree) {$layoutTree.set(snapshot.tree)$paneStates.set(snapshot.panes)@@ -183,9 +168,6 @@ export function snapshotChatLayout(): () => void {markActivePreset(snapshot.id)persistTree()}-- previousLayout = snapshot.previous- $chatLayoutPicked.set(snapshot.picked)}}diff --git a/apps/desktop/src/components/onboarding/first-run/intro.ts b/apps/desktop/src/components/onboarding/first-run/intro.tsindex 4c326f0b5fd..a7dca3d9abc 100644--- a/apps/desktop/src/components/onboarding/first-run/intro.ts+++ b/apps/desktop/src/components/onboarding/first-run/intro.ts@@ -2,6 +2,7 @@ import { atom, computed } from 'nanostores'import { PANE_TOGGLE_REVEAL_EVENT } from '@/components/pane-shell'import { TIP_CATALOG } from '@/lib/tips/catalog'+import { onLayoutCommit } from '@/store/appearance-apply'import { $sidebarOpen, CHAT_SIDEBAR_PANE_ID } from '@/store/layout'import { $introView } from '@/store/onboarding-intro'import { $activeGatewayProfile } from '@/store/profile'@@ -62,6 +63,10 @@ function endIntroView(keepLayout = false): boolean {return true}+// A committed layout (the layout card's Continue, a set_theme layout) ends the intro on the user's own+// layout before it applies, so the pick lands at normal size over the user's layout, never the demo's.+onLayoutCommit(() => void endIntroView())+/** Any leave action (sidebar, another chat, a profile, a Cmd-K command) ends the intro. */export function leaveIntro(): void {endIntroView()diff --git a/apps/desktop/src/components/onboarding/first-run/layout.test.ts b/apps/desktop/src/components/onboarding/first-run/layout.test.tsindex 28d3b39b51e..61ea8d9b13b 100644--- a/apps/desktop/src/components/onboarding/first-run/layout.test.ts+++ b/apps/desktop/src/components/onboarding/first-run/layout.test.ts@@ -1,8 +1,11 @@-import { beforeEach, describe, expect, it, vi } from 'vitest'+import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'+import { registerLayoutPresets } from '@/app/contrib/layout-presets'import { group } from '@/components/pane-shell/tree/model'import { applyLayoutPreset } from '@/components/pane-shell/tree/presets'import { $activePresetId } from '@/components/pane-shell/tree/store'+import { applyAppearance } from '@/store/appearance-apply'+import { $interfaceMode, setInterfaceMode } from '@/store/interface-mode'import { $chatOnboardingSolo, $introView } from '@/store/onboarding-intro'import { openDemoLayout } from './assembly'@@ -10,6 +13,10 @@ import { openIntro, skipIntro } from './intro'const size = vi.fn()+beforeAll(() => {+ registerLayoutPresets()+})+beforeEach(() => {Object.defineProperty(window, 'hermesDesktop', {configurable: true,@@ -22,13 +29,19 @@ beforeEach(() => {})describe('first-run layout beat', () => {- it('grows the window to normal size on the picked layout when a layout is applied', () => {+ it('keeps the intro through a preview and grows the window when a layout is committed', () => {+ setInterfaceMode('advanced')applyLayoutPreset('picked', group(['workspace']))+ expect($introView.get()).toBe('intro')+ expect(size).not.toHaveBeenCalled()++ expect(applyAppearance({ layout: 'sidebar-left' }).success).toBe(true)expect(size).toHaveBeenCalledWith('normal')expect($chatOnboardingSolo.get()).toBe(false)expect($introView.get()).toBe('ended')- expect($activePresetId.get()).toBe('picked')+ expect($interfaceMode.get()).toBe('simple')+ expect($activePresetId.get()).toBe('sidebar-left')})it('sizes the window normal on Skip setup', () => {diff --git a/apps/desktop/src/store/appearance-apply.ts b/apps/desktop/src/store/appearance-apply.tsindex b0bac65f698..836c56f0d72 100644--- a/apps/desktop/src/store/appearance-apply.ts+++ b/apps/desktop/src/store/appearance-apply.ts@@ -55,7 +55,17 @@ function paintsDark(mode: ThemeMode | undefined): boolean {return mode === undefined ? document.documentElement.classList.contains('dark') : mode === 'dark'}+// The first-run demo layout is borrowed (components/onboarding/first-run/intro.ts registers this): a+// committed layout ends it first, so a Simple/Advanced switch saves the user's own layout, not the demo.+let releaseBorrowedLayout = (): void => {}++export function onLayoutCommit(release: () => void): void {+ releaseBorrowedLayout = release+}+function applyLayout(id: string): void {+ releaseBorrowedLayout()+// A user's saved layouts are Advanced, like the layout picker's Custom section.const mode = layoutPresetTier(id) === 'simple' ? 'simple' : 'advanced'