The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): stop the HUD frosting the window while a turn runs
Brooklyn Nicholson321d5c76bbb1
diff --git a/apps/desktop/src/app/hud/glass.test.tsx b/apps/desktop/src/app/hud/glass.test.tsxnew file mode 100644index 00000000000..49d529f9c49--- /dev/null+++ b/apps/desktop/src/app/hud/glass.test.tsx@@ -0,0 +1,76 @@+import { act, render } from '@testing-library/react'+import { useRef } from 'react'+import { afterEach, describe, expect, it, vi } from 'vitest'++import { useHudGlass } from './glass'++const setFrost = vi.fn()++/** The HUD's real shape as far as the frost is concerned: the shell, the+ * composer input that owns the caret, and — when it is open — the completion+ * drawer that takes the surface over. */+function Harness({ backing, drawer }: { backing: boolean; drawer?: boolean }) {+ const ref = useRef<HTMLDivElement | null>(null)++ useHudGlass(ref, backing)++ return (+ <div data-hud-shell ref={ref}>+ <input data-slot="composer-rich-input" />+ {drawer && <div data-slot="composer-completion-drawer" />}+ </div>+ )+}++const frostState = () => setFrost.mock.calls.at(-1)?.[0]++const nextFrame = () => act(() => new Promise(resolve => requestAnimationFrame(() => resolve(undefined))))++afterEach(() => {+ setFrost.mockClear()+})++Object.assign(window, { hermesDesktop: { hud: { setFrost } } })++describe('useHudGlass', () => {+ // The bug this replaced: the caller widened the gate to "recent or held", so+ // a turn merely running raised the window's material while the scrim that is+ // supposed to be painted over it — focus-gated in styles.css — stayed down.+ // On a light theme that is a white slab under the band's white ink.+ it('leaves the window bare while a turn runs with the composer unfocused', () => {+ render(<Harness backing />)++ expect(frostState()).toBe(false)+ })++ it('frosts once the caret is in the composer, and lets go when it leaves', () => {+ const { container } = render(<Harness backing />)+ const input = container.querySelector('input')!++ act(() => input.focus())+ expect(frostState()).toBe(true)++ act(() => input.blur())+ expect(frostState()).toBe(false)+ })++ it('stays off while the band is not covering the window, however engaged', () => {+ const { container } = render(<Harness backing={false} />)++ act(() => container.querySelector('input')!.focus())++ expect(frostState()).toBe(false)+ })++ it('drops the frost when a completion drawer takes the surface over', async () => {+ const { container, rerender } = render(<Harness backing />)++ act(() => container.querySelector('input')!.focus())+ expect(frostState()).toBe(true)++ rerender(<Harness backing drawer />)+ await nextFrame()++ expect(frostState()).toBe(false)+ })+})diff --git a/apps/desktop/src/app/hud/glass.ts b/apps/desktop/src/app/hud/glass.tsindex 2a917e44332..7225c6cc45b 100644--- a/apps/desktop/src/app/hud/glass.ts+++ b/apps/desktop/src/app/hud/glass.ts@@ -28,20 +28,27 @@ const DRAWER_SELECTOR = '[data-slot="composer-completion-drawer"]'* untinted frost on screen — a grey blurred rectangle that pops out at the end* instead of a band fading away.*- * Engaged means the caret is in the composer, matching the stylesheet. Merely- * holding window focus does not count: activating a window restores focus to- * whatever had it last, so grabbing the bar to drag the HUD would otherwise- * read as sitting down to use it. Queried live rather than tracked from- * document.activeElement, which stays put when the window is blurred and would- * latch the frost on forever once the user had ever typed here.+ * Engaged means the caret is in the composer, and it is the SAME gate the+ * `[data-hud-glass]` scrim runs on — the frost is what that scrim is painted+ * over, so a frost the scrim doesn't cover is bare material. The caller used+ * to widen this to "recent or held", which put the window's material up for+ * the whole of a turn while the scrim stayed down: on a light theme that is a+ * white slab under the band's unconditionally white ink, and there is nothing+ * to read. One gate, or the two drift again.+ *+ * Merely holding window focus does not count: activating a window restores+ * focus to whatever had it last, so grabbing the bar to drag the HUD would+ * otherwise read as sitting down to use it. Queried live rather than tracked+ * from document.activeElement, which stays put when the window is blurred and+ * would latch the frost on forever once the user had ever typed here — the+ * window's own focus changes are listened for so the query is re-run when+ * `:focus` stops matching under an inactive window.** Two vetoes sit over that:** - `backing` — because the frost is the window and not the sheet, it is only* ever right when the sheet covers the window; short of that the excess is- * frost over empty space. Gating the caller's `engaged` alone would not do- * it — focus turns the frost on by itself, which is how a brand new thread- * still frosted its whole empty window.+ * frost over empty space.* - An open completion drawer, which drops the band to 25% and blurs it* (see the `composer-completion-drawer` rule in styles.css). Full-strength* frost behind a band that has deliberately stepped back is the same bare@@ -53,7 +60,7 @@ const DRAWER_SELECTOR = '[data-slot="composer-completion-drawer"]'* that answer lives in main (`hudFrostFor`) next to the state it reads. This* hook reports what the band is doing; it does not decide the material.*/-export function useHudGlass(rootRef: RefObject<HTMLElement | null>, engaged: boolean, backing: boolean): void {+export function useHudGlass(rootRef: RefObject<HTMLElement | null>, backing: boolean): void {useEffect(() => {const root = rootRef.currentconst setFrost = window.hermesDesktop?.hud?.setFrost@@ -66,9 +73,7 @@ export function useHudGlass(rootRef: RefObject<HTMLElement | null>, engaged: booconst apply = () => {const next =- backing &&- root.querySelector(DRAWER_SELECTOR) === null &&- (engaged || root.querySelector(TYPING_SELECTOR) !== null)+ backing && root.querySelector(DRAWER_SELECTOR) === null && root.querySelector(TYPING_SELECTOR) !== nullif (on !== next) {on = next@@ -99,6 +104,12 @@ export function useHudGlass(rootRef: RefObject<HTMLElement | null>, engaged: booapply()root.addEventListener('focusin', apply)root.addEventListener('focusout', apply)+ // Clicking away to another APP fires no focusout — the composer stays+ // document.activeElement — but `:focus` stops matching, so the scrim goes+ // and the frost would be left behind as a bare slab. Deferred a frame so+ // the query runs after the deactivation has landed.+ window.addEventListener('blur', schedule)+ window.addEventListener('focus', schedule)return () => {void setFrost(false)@@ -110,6 +121,8 @@ export function useHudGlass(rootRef: RefObject<HTMLElement | null>, engaged: booroot.removeEventListener('focusin', apply)root.removeEventListener('focusout', apply)+ window.removeEventListener('blur', schedule)+ window.removeEventListener('focus', schedule)}- }, [backing, engaged, rootRef])+ }, [backing, rootRef])}diff --git a/apps/desktop/src/app/hud/hud-shell.tsx b/apps/desktop/src/app/hud/hud-shell.tsxindex b1743ea0d74..09958d664d1 100644--- a/apps/desktop/src/app/hud/hud-shell.tsx+++ b/apps/desktop/src/app/hud/hud-shell.tsx@@ -368,7 +368,7 @@ export function HudShell() {}}, [])- useHudGlass(rootRef, recent || held, filled)+ useHudGlass(rootRef, filled)useHudClickThrough(rootRef)useHudThreadFocus(rootRef)