The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): accent and layout picks preview live and Continue commits them
alt-glitch935b1837c2db
diff --git a/apps/desktop/src/components/assistant-ui/setup-beat/setup-beat-tool.tsx b/apps/desktop/src/components/assistant-ui/setup-beat/setup-beat-tool.tsxindex 7e3a9f2ac8a..0eba297a441 100644--- a/apps/desktop/src/components/assistant-ui/setup-beat/setup-beat-tool.tsx+++ b/apps/desktop/src/components/assistant-ui/setup-beat/setup-beat-tool.tsx@@ -28,9 +28,11 @@ import { PluginsCard } from './plugins-card'import { SETUP_BEAT_SHELL_CLASS, type SetupBeatOutcome, setupBeatOutcome, SetupBeatReceipt } from './receipt'/** The card body for one beat; `answer` sends the beat's picks and settles the card. */-function BeatBody({ answer, request }: { answer: (picks: SetupBeatAnswer) => void; request: SetupBeatRequest }) {+function BeatBody({ answer, request }: { answer: (picks: SetupBeatAnswer) => boolean; request: SetupBeatRequest }) {const { card } = request+ const commit = (applied: boolean, picks: SetupBeatAnswer): boolean => applied && answer(picks)+switch (request.beat) {case 'name':return (@@ -43,24 +45,12 @@ function BeatBody({ answer, request }: { answer: (picks: SetupBeatAnswer) => voicase 'theme':return (<AccentPickerCard- onPick={accent => {- if (applyAppearance({ accent: accent ?? 'theme' }).success) {- answer({ accent })- }- }}+ onContinue={accent => commit(applyAppearance({ accent: accent ?? 'theme' }).success, { accent })}/>)case 'layout':- return (- <LayoutPickerCard- onPick={layout => {- if (applyAppearance({ layout }).success) {- answer({ layout })- }- }}- />- )+ return <LayoutPickerCard onContinue={layout => commit(applyAppearance({ layout }).success, { layout })} />case 'plugins':return (@@ -144,10 +134,14 @@ export function SetupBeatTool(props: ToolCallMessagePartProps) {return null}- const answer = (picks: SetupBeatAnswer) => {- if (answerSetupBeat(sessionId, picks)) {- setSettled({ answer: picks, beat: request.beat, kind: 'answer' })+ const answer = (picks: SetupBeatAnswer): boolean => {+ if (!answerSetupBeat(sessionId, picks)) {+ return false}++ setSettled({ answer: picks, beat: request.beat, kind: 'answer' })++ return true}// The directory card has its own header and plug icon; a frame label above it would be a second header.diff --git a/apps/desktop/src/components/assistant-ui/theme-picker/accent-picker-card.tsx b/apps/desktop/src/components/assistant-ui/theme-picker/accent-picker-card.tsxindex 9c3d9390f9d..5b9f41bfdbc 100644--- a/apps/desktop/src/components/assistant-ui/theme-picker/accent-picker-card.tsx+++ b/apps/desktop/src/components/assistant-ui/theme-picker/accent-picker-card.tsx@@ -3,49 +3,61 @@import { useState } from 'react'import { AccentSwatch } from '@/components/ui/accent-swatch'-import { Codicon } from '@/components/ui/codicon'+import { Button } from '@/components/ui/button'import { useI18n } from '@/i18n'import { useTheme } from '@/themes'import { accentsFor, CUSTOM_ACCENT_PREFIX, NOUS_ACCENT } from '@/themes/accents'+import { CARD_ACTION_CLASS } from '../setup-beat/card-type'++import { useLookPreview } from './look-preview'+export interface AccentPickerCardProps {- /** A swatch id, `custom:#rrggbb`, or null for the theme's own accent (Nous blue). */- onPick: (accent: null | string) => void+ /** Answers with a swatch id, `custom:#rrggbb`, or null for the theme's own accent (Nous blue); true once sent. */+ onContinue: (accent: null | string) => boolean}-/** The eight accent swatches plus a custom colour well; a swatch click is the pick. */-export function AccentPickerCard({ onPick }: AccentPickerCardProps) {+/** The eight accent swatches plus a custom colour well; a click previews the accent, Continue answers with it. */+export function AccentPickerCard({ onContinue }: AccentPickerCardProps) {const { t } = useI18n()const { renderedMode } = useTheme()const [custom, setCustom] = useState<null | string>(null)+ const look = useLookPreview('accent', renderedMode === 'dark')+ const staged = look.stagedreturn (- <div className="flex flex-wrap items-center gap-2.5 p-1" role="group">- {accentsFor(renderedMode === 'dark').map(swatch => (+ <div className="grid gap-3">+ <div className="flex flex-wrap items-center gap-2.5 p-1" role="group">+ {accentsFor(renderedMode === 'dark').map(swatch => {+ const value = swatch.id === 'nous' ? null : swatch.id++ return (+ <AccentSwatch+ active={staged?.value === value}+ hex={swatch.hex}+ key={swatch.id}+ name={swatch.name}+ onPick={() => look.stage(value)}+ />+ )+ })}<AccentSwatch- active={false}- hex={swatch.hex}- key={swatch.id}- name={swatch.name}- onPick={() => onPick(swatch.id === 'nous' ? null : swatch.id)}+ active={custom !== null && staged?.value === `${CUSTOM_ACCENT_PREFIX}${custom}`}+ hex={custom ?? NOUS_ACCENT}+ name={t.assistant.themePicker.customColor}+ onColorChange={hex => {+ const value = hex.toLowerCase()++ setCustom(value)+ look.stage(`${CUSTOM_ACCENT_PREFIX}${value}`)+ }}/>- ))}- <AccentSwatch- active={custom !== null}- hex={custom ?? NOUS_ACCENT}- name={t.assistant.themePicker.customColor}- onColorChange={setCustom}- />- {custom !== null && (- <button- aria-label={t.assistant.themePicker.customColor}- className="grid size-7 place-items-center rounded-full border border-(--ui-stroke-tertiary) text-(--ui-text-secondary) hover:bg-(--chrome-action-hover)"- onClick={() => onPick(`${CUSTOM_ACCENT_PREFIX}${custom.toLowerCase()}`)}- type="button"- >- <Codicon name="check" size="0.875rem" />- </button>- )}+ </div>+ <div>+ <Button className={CARD_ACTION_CLASS} disabled={!staged} onClick={() => look.commit(onContinue)} size="sm">+ {t.common.continue}+ </Button>+ </div></div>)}diff --git a/apps/desktop/src/components/assistant-ui/theme-picker/layout-picker-card.tsx b/apps/desktop/src/components/assistant-ui/theme-picker/layout-picker-card.tsxindex 5d9fd178b6e..8ecc540d83e 100644--- a/apps/desktop/src/components/assistant-ui/theme-picker/layout-picker-card.tsx+++ b/apps/desktop/src/components/assistant-ui/theme-picker/layout-picker-card.tsx@@ -6,15 +6,19 @@ import { isLayoutNode } from '@/components/pane-shell/tree/model'import { layoutPresetResting, LAYOUTS_AREA } from '@/components/pane-shell/tree/presets'import { TreeThumbnail } from '@/components/pane-shell/tree/renderer/layout-picker'import { $activePresetId } from '@/components/pane-shell/tree/store'+import { Button } from '@/components/ui/button'import { useContributions } from '@/contrib/react/use-contributions'import { useI18n } from '@/i18n'import { selectableCardClass } from '@/lib/selectable-card'import { cn } from '@/lib/utils'-import { CARD_DETAIL_CLASS, CARD_OPTION_CLASS } from '../setup-beat/card-type'+import { CARD_ACTION_CLASS, CARD_DETAIL_CLASS, CARD_OPTION_CLASS } from '../setup-beat/card-type'++import { useLookPreview } from './look-preview'export interface LayoutPickerCardProps {- onPick: (preset: string) => void+ /** Answers with the staged preset id; true once sent. */+ onContinue: (preset: string) => boolean}/** Basic is the Simple shell's sidebar-left; Elite is the Advanced terminal deck. */@@ -23,44 +27,59 @@ const CHOICES = [{ id: 'terminal-deck', name: 'elite', detail: 'eliteDetail' }] as const-/** The two first-run layouts as the layout picker's own preset cards; a card click is the pick. */-export function LayoutPickerCard({ onPick }: LayoutPickerCardProps) {- const copy = useI18n().t.assistant.themePicker+/** The two first-run layouts as the layout picker's own preset cards; a click previews the layout, Continue answers with it. */+export function LayoutPickerCard({ onContinue }: LayoutPickerCardProps) {+ const { t } = useI18n()+ const copy = t.assistant.themePicker+ const look = useLookPreview('layout', false)+ const staged = look.staged?.value ?? nullconst presets = useContributions(LAYOUTS_AREA)const activeId = useStore($activePresetId)return (- <div className="grid grid-cols-2 gap-3 p-1" role="group">- {CHOICES.map(choice => {- const tree = presets.find(preset => preset.id === choice.id)?.data- const active = choice.id === activeId+ <div className="grid gap-3">+ <div className="grid grid-cols-2 gap-3 p-1" role="group">+ {CHOICES.map(choice => {+ const tree = presets.find(preset => preset.id === choice.id)?.data+ const active = choice.id === (staged ?? activeId)- return (- <button- aria-pressed={active}- className={cn(selectableCardClass({ active, prominent: true }), 'flex flex-col gap-2 p-2 text-left')}- key={choice.id}- onClick={() => onPick(choice.id)}- type="button"- >- <span className="flex aspect-[10/7] w-full">- {isLayoutNode(tree) && <TreeThumbnail node={tree} resting={layoutPresetResting(choice.id)} />}- </span>- <span className="flex flex-col gap-0.5">- <span- className={cn(- CARD_OPTION_CLASS,- 'font-medium',- active ? 'text-foreground' : 'text-(--ui-text-secondary)'- )}- >- {copy[choice.name]}+ return (+ <button+ aria-pressed={active}+ className={cn(selectableCardClass({ active, prominent: true }), 'flex flex-col gap-2 p-2 text-left')}+ key={choice.id}+ onClick={() => look.stage(choice.id)}+ type="button"+ >+ <span className="flex aspect-[10/7] w-full">+ {isLayoutNode(tree) && <TreeThumbnail node={tree} resting={layoutPresetResting(choice.id)} />}+ </span>+ <span className="flex flex-col gap-0.5">+ <span+ className={cn(+ CARD_OPTION_CLASS,+ 'font-medium',+ active ? 'text-foreground' : 'text-(--ui-text-secondary)'+ )}+ >+ {copy[choice.name]}+ </span>+ <span className={cn(CARD_DETAIL_CLASS, 'text-(--ui-text-tertiary)')}>{copy[choice.detail]}</span></span>- <span className={cn(CARD_DETAIL_CLASS, 'text-(--ui-text-tertiary)')}>{copy[choice.detail]}</span>- </span>- </button>- )- })}+ </button>+ )+ })}+ </div>+ <div>+ <Button+ className={CARD_ACTION_CLASS}+ disabled={!staged}+ onClick={() => look.commit(value => value !== null && onContinue(value))}+ size="sm"+ >+ {t.common.continue}+ </Button>+ </div></div>)}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.tsnew file mode 100644index 00000000000..4c38700976a--- /dev/null+++ b/apps/desktop/src/components/assistant-ui/theme-picker/look-preview.ts@@ -0,0 +1,81 @@+import { useEffect, useRef, useState } from 'react'++import { snapshotChatLayout } from '@/components/onboarding/first-run/assembly'+import { applyAppearance } from '@/store/appearance-apply'+import { $accentOverride, setAccentOverride } from '@/themes/accent-override'+import { NOUS_ACCENT, resolveAccentPick } from '@/themes/accents'++/** A staged pick; `value` null is the theme's own accent. */+export interface StagedLook {+ value: null | string+}++interface LiveLook {+ apply: (value: null | string, dark: boolean) => void+ snapshot: () => () => void+}++// The accent previews through the unsaved override so nothing is persisted before Continue; the theme's own+// accent previews as Nous blue because an empty override would keep the current colour.+const ACCENT: LiveLook = {+ apply: (value, dark) => setAccentOverride(resolveAccentPick(value ?? 'theme', dark)?.hex ?? NOUS_ACCENT),+ snapshot: () => {+ const override = $accentOverride.get()++ return () => setAccentOverride(override)+ }+}++const LAYOUT: LiveLook = {+ apply: value => {+ if (value) {+ applyAppearance({ layout: value })+ }+ },+ snapshot: snapshotChatLayout+}++export interface LookPreview {+ /** Answer with the staged pick; leaving keeps it when `send` returns true. */+ commit: (send: (value: null | string) => boolean) => void+ stage: (value: null | string) => void+ 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. */+export function useLookPreview(kind: 'accent' | 'layout', dark: boolean): LookPreview {+ const live = kind === 'accent' ? ACCENT : LAYOUT+ const [staged, setStaged] = useState<null | StagedLook>(null)+ const revert = useRef<(() => void) | null>(null)+ const settled = useRef(false)++ useEffect(+ () => () => {+ if (!settled.current) {+ revert.current?.()+ }++ revert.current = null+ },+ []+ )++ return {+ // Settled before sending: the answer can unmount the card before `send` returns.+ commit: send => {+ if (!staged) {+ return+ }++ settled.current = true+ settled.current = send(staged.value)+ },+ stage: value => {+ revert.current ??= live.snapshot()+ live.apply(value, dark)+ setStaged({ value })+ },+ staged+ }+}diff --git a/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.test.tsx b/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.test.tsxindex 6e5d610c23e..f42bbf993d0 100644--- a/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.test.tsx+++ b/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.test.tsx@@ -8,6 +8,7 @@ import { registerLayoutPresets } from '@/app/contrib/layout-presets'import { I18nProvider } from '@/i18n'import { rememberServerRequest, resetServerRequestsForTests } from '@/store/server-requests'import { $themePicks, parkThemePick } from '@/store/theme-pick'+import { $accentOverride } from '@/themes/accent-override'import { ThemeProvider } from '@/themes/context'import { ThemeTool } from './theme-tool'@@ -16,21 +17,25 @@ const SESSION = 'theme-session'const view: SessionView = { ...PRIMARY_SESSION_VIEW, $runtimeId: atom(SESSION), $storedId: atom('stored-theme') }-function renderRow(props: Partial<ToolCallMessagePartProps>) {+function row(props: Partial<ToolCallMessagePartProps>) {// SAFETY: ThemeTool reads only args, result, toolName and toolCallId; the rest of the part API is unused.- const row = { args: {}, toolCallId: 'call-1', toolName: 'set_theme', ...props } as ToolCallMessagePartProps+ const part = { args: {}, toolCallId: 'call-1', toolName: 'set_theme', ...props } as ToolCallMessagePartProps- return render(+ return (<I18nProvider configClient={null} initialLocale="en"><ThemeProvider><SessionViewProvider value={view}>- <ThemeTool {...row} />+ <ThemeTool {...part} /></SessionViewProvider></ThemeProvider></I18nProvider>)}+function renderRow(props: Partial<ToolCallMessagePartProps>) {+ return render(row(props))+}+function park(picker: 'accent' | 'layout') {const respond = vi.fn()@@ -48,19 +53,38 @@ describe('ThemeTool', () => {afterEach(() => {cleanup()$themePicks.set({})+ $accentOverride.set(null)resetServerRequestsForTests()})- it('answers the waiting card with the swatch the user clicked, then shows the receipt', () => {+ it('previews a clicked swatch without answering, then Continue answers with the last one staged', () => {const respond = park('accent')renderRow({ args: { picker: 'accent' } })fireEvent.click(screen.getByRole('button', { name: 'Ultraviolet' }))+ expect(respond).not.toHaveBeenCalled()+ expect($accentOverride.get()).not.toBeNull()++ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))+expect(respond).toHaveBeenCalledWith({ picked: { accent: 'violet' } })expect(screen.getByText('Ultraviolet').closest('[data-theme-settled]')).not.toBeNull()})+ it('puts the previous accent back when the card settles without a pick', () => {+ const respond = park('accent')++ const { rerender } = renderRow({ args: { picker: 'accent' } })++ fireEvent.click(screen.getByRole('button', { name: 'Ultraviolet' }))+ // The backend's cancel or timeout settles the row with a result and no pick.+ rerender(row({ args: { picker: 'accent' }, result: { cancelled: true } }))++ expect(respond).not.toHaveBeenCalled()+ expect($accentOverride.get()).toBeNull()+ })+it('draws the layout card for a call made through the tool_call bridge', () => {const respond = park('layout')@@ -70,6 +94,10 @@ describe('ThemeTool', () => {})fireEvent.click(screen.getByRole('button', { name: /Elite/ }))+ expect(respond).not.toHaveBeenCalled()++ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))+expect(respond).toHaveBeenCalledWith({ picked: { layout: 'terminal-deck' } })})})diff --git a/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.tsx b/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.tsxindex f2e427e614a..50acd00c690 100644--- a/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.tsx+++ b/apps/desktop/src/components/assistant-ui/theme-picker/theme-tool.tsx@@ -134,10 +134,14 @@ export function ThemeTool(props: ToolCallMessagePartProps) {return <ToolFallback {...props} />}- const answer = (values: AppliedAppearance, apply: () => boolean) => {- if (apply()) {- setPicked(values)+ const answer = (values: AppliedAppearance, apply: () => boolean): boolean => {+ if (!apply()) {+ return false}++ setPicked(values)++ return true}return (@@ -155,10 +159,10 @@ export function ThemeTool(props: ToolCallMessagePartProps) {</div>{picker === 'accent' ? (<AccentPickerCard- onPick={accent => answer({ accent }, () => pickTheme(sessionId, { accent: accent ?? 'theme' }))}+ onContinue={accent => answer({ accent }, () => pickTheme(sessionId, { accent: accent ?? 'theme' }))}/>) : (- <LayoutPickerCard onPick={layout => answer({ layout }, () => pickTheme(sessionId, { layout }))} />+ <LayoutPickerCard onContinue={layout => answer({ layout }, () => pickTheme(sessionId, { layout }))} />)}</div>)