The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): drag the HUD by holding the composer
Brooklyn Nicholsondd11b8e8e8e3
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex ed61fabb260..94d45ce544e 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -10034,6 +10034,23 @@ ipcMain.on('hermes:hud:ignore-mouse', (_event, ignore) => {}})+ipcMain.on('hermes:hud:move-by', (event, delta) => {+ if (!hudWindow || hudWindow.isDestroyed() || event.sender !== hudWindow.webContents) {+ return+ }++ const dx = Number(delta?.x)+ const dy = Number(delta?.y)++ if (!Number.isFinite(dx) || !Number.isFinite(dy)) {+ return+ }++ const [x, y] = hudWindow.getPosition()++ hudWindow.setPosition(Math.round(x + dx), Math.round(y + dy))+})+// The HUD renderer reporting which session it is on, so the close broadcast// can hand it back to the app window (see hudSessionId).ipcMain.on('hermes:hud:session', (event, sessionId) => {diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.tsindex 1695a1ccb81..792ee07ba05 100644--- a/apps/desktop/electron/preload.ts+++ b/apps/desktop/electron/preload.ts@@ -53,6 +53,7 @@ contextBridge.exposeInMainWorld('hermesDesktop', {open: request => ipcRenderer.invoke('hermes:hud:open', request),close: () => ipcRenderer.invoke('hermes:hud:close'),setIgnoreMouse: ignore => ipcRenderer.send('hermes:hud:ignore-mouse', ignore),+ moveBy: delta => ipcRenderer.send('hermes:hud:move-by', delta),setVibrancy: on => ipcRenderer.invoke('hermes:hud:vibrancy', on),// The HUD tells main which session it is on; main hands that back to the// app window when the HUD closes, so the app can re-home onto it.diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsxindex 28dbcf23a67..1c5bd36ae4a 100644--- a/apps/desktop/src/app/chat/composer/index.tsx+++ b/apps/desktop/src/app/chat/composer/index.tsx@@ -2,6 +2,7 @@ import { ComposerPrimitive } from '@assistant-ui/react'import { useStore } from '@nanostores/react'import { type ClipboardEvent, type FormEvent, type KeyboardEvent, useCallback, useEffect, useMemo, useRef } from 'react'+import { useHudComposerDrag } from '@/app/hud/composer-drag'import { composerFill, composerFloatingStrip, composerSurfaceGlass } from '@/components/chat/composer-dock'import { Button } from '@/components/ui/button'import { Slot as ContribSlot } from '@/contrib/react/slot'@@ -16,6 +17,7 @@ import { sessionCompacting } from '@/store/compaction'import { browseBackward, browseForward, deriveUserHistory, isBrowsingHistory } from '@/store/composer-input-history'import { POPOUT_WIDTH_REM } from '@/store/composer-popout'import { parkQueuedPrompts, removeQueuedPrompt, unparkQueuedPrompts } from '@/store/composer-queue'+import { $hudMode } from '@/store/hud'import { toggleReview } from '@/store/review'import { $gatewayState } from '@/store/session'import { $threadScrolledUp } from '@/store/thread-scroll'@@ -100,6 +102,9 @@ export function ChatBar({onSubmit: onSubmitProp,onTranscribeAudio}: ChatBarProps) {+ const hudMode = useStore($hudMode)+ const { grabbing: hudGrabbing, onPointerDown: onHudDragPointerDown } = useHudComposerDrag(hudMode)+// Typed stop phrase during an active voice conversation ends it — same// semantics as SAYING "stop" (voice-stop-word.ts) or clicking the pill's// end control. Populated after useComposerVoice below (the submit wrapper@@ -1123,11 +1128,14 @@ export function ChatBar({data-slot="composer-root"data-status-stack={statusStackVisible ? '' : undefined}data-thread-scrolled-up={scrolledUp ? '' : undefined}+ data-hud-grabbing={hudGrabbing ? '' : undefined}onDragEnter={handleDragEnter}onDragLeave={handleDragLeave}onDragOver={handleDragOver}onDrop={handleDrop}- onPointerDown={popoutAllowed ? onComposerGesturePointerDown : undefined}+ onPointerDown={+ hudMode ? onHudDragPointerDown : popoutAllowed ? onComposerGesturePointerDown : undefined+ }onSubmit={e => {e.preventDefault()diff --git a/apps/desktop/src/app/hud/click-through.ts b/apps/desktop/src/app/hud/click-through.tsindex 76b61069bd2..9990658e2b5 100644--- a/apps/desktop/src/app/hud/click-through.ts+++ b/apps/desktop/src/app/hud/click-through.ts@@ -26,6 +26,13 @@ export function hudIgnoresMouse(active: Element | null,windowFocused: boolean): boolean {+ // A long-press drag in progress owns the window until it lets go. The cursor+ // outruns the window it is moving, so the hit test goes empty mid-drag and+ // would otherwise hand the mouse away underneath the user's own hand.+ if (root.querySelector('[data-hud-grabbing]') !== null) {+ return false+ }+const overSomething = hit !== null && !hit.contains(root)// `windowFocused` is what stops a stale `active` — the composer keeps focus// after you click away to another app — pinning the HUD solid forever.@@ -52,6 +59,12 @@ export function hudIgnoresMouse(* whenever a portalled overlay holds focus. `forward: true` keeps mousemove* flowing while ignoring, which is what lets it re-arm when the cursor comes* back to the bar.+ *+ * It follows that nothing in HUD mode may declare `-webkit-app-region: drag`+ * at all: a draggable region swallows the page's mouse events, so the moves+ * never arrive and the window is stranded on whatever it last decided —+ * usually transparent, which is also why pressing the handle fell through to+ * the app behind. Dragging is `useHudComposerDrag` instead.*/export function useHudClickThrough(rootRef: RefObject<HTMLElement | null>): void {useEffect(() => {@@ -89,14 +102,31 @@ export function useHudClickThrough(rootRef: RefObject<HTMLElement | null>): voidapply()}+ // Whenever we stop knowing where the cursor is, hand the window back. Solid+ // is only ever right under a cursor we can still see: the last point we saw+ // is usually the bar, and holding that answer means the whole rectangle+ // keeps eating clicks long after the cursor has left for another app. It+ // costs nothing to give up — `forward: true` keeps the moves arriving while+ // ignoring, so the bar is solid again well before a click reaches it.+ const onLost = () => {+ point = null+ apply()+ }+apply()window.addEventListener('mousemove', onMove)+ window.addEventListener('blur', onLost)+ window.addEventListener('focus', apply)+ document.addEventListener('mouseleave', onLost)document.addEventListener('focusin', apply)document.addEventListener('focusout', apply)return () => {setIgnoreMouse(false)window.removeEventListener('mousemove', onMove)+ window.removeEventListener('blur', onLost)+ window.removeEventListener('focus', apply)+ document.removeEventListener('mouseleave', onLost)document.removeEventListener('focusin', apply)document.removeEventListener('focusout', apply)}diff --git a/apps/desktop/src/app/hud/composer-drag.ts b/apps/desktop/src/app/hud/composer-drag.tsnew file mode 100644index 00000000000..aa52598f695--- /dev/null+++ b/apps/desktop/src/app/hud/composer-drag.ts@@ -0,0 +1,164 @@+import { type PointerEvent as ReactPointerEvent, useCallback, useEffect, useRef, useState } from 'react'++import { triggerHaptic } from '@/lib/haptics'++/** Hold anywhere on the HUD composer before the bar becomes draggable. Short+ * enough to feel like grabbing it, long enough that a click still clicks. */+const LONG_PRESS_MS = 140+/** Slop before the hold is read as a text selection instead of a grab. */+const MOVE_TOLERANCE = 8++interface PressState {+ armed: boolean+ lastX: number+ lastY: number+ pointerId: number+ startX: number+ startY: number+ target: HTMLElement+}++/**+ * HUD-only: press and hold the composer, then drag to move the window.+ *+ * The only way to move the HUD. An `-webkit-app-region: drag` handle is the+ * obvious alternative and cannot work here: the window manager takes a drag+ * region's mouse input whole, which starves `useHudClickThrough` of the moves+ * it decides solidity from, so the window is already transparent by the time+ * the press lands and it falls through to the app behind. See click-through.ts.+ *+ * Deltas are read in SCREEN coordinates. Client coordinates are relative to the+ * window we are moving, so a window that keeps up with the cursor reports the+ * same clientX every frame — zero delta, and the drag dies one pixel in.+ */+export function useHudComposerDrag(enabled: boolean) {+ const [grabbing, setGrabbing] = useState(false)+ const stateRef = useRef<PressState | null>(null)+ const timerRef = useRef<number | null>(null)++ const reset = useCallback(() => {+ if (timerRef.current !== null) {+ window.clearTimeout(timerRef.current)+ timerRef.current = null+ }++ const state = stateRef.current++ if (state?.target.hasPointerCapture(state.pointerId)) {+ state.target.releasePointerCapture(state.pointerId)+ }++ stateRef.current = null+ setGrabbing(false)+ }, [])++ const onPointerDown = useCallback(+ (event: ReactPointerEvent<HTMLElement>) => {+ if (!enabled || event.button !== 0) {+ return+ }++ const target = event.currentTarget++ stateRef.current = {+ armed: false,+ lastX: event.screenX,+ lastY: event.screenY,+ pointerId: event.pointerId,+ startX: event.screenX,+ startY: event.screenY,+ target+ }++ if (timerRef.current !== null) {+ window.clearTimeout(timerRef.current)+ }++ timerRef.current = window.setTimeout(() => {+ const state = stateRef.current++ if (!state || state.armed) {+ return+ }++ state.armed = true+ setGrabbing(true)+ triggerHaptic('selection')++ // Capture so the moves keep arriving once the cursor outruns the bar,+ // and drop the caret so the drag isn't also extending a selection.+ state.target.setPointerCapture(state.pointerId)++ if (document.activeElement instanceof HTMLElement) {+ document.activeElement.blur()+ }+ }, LONG_PRESS_MS)+ },+ [enabled]+ )++ // eslint-disable-next-line no-restricted-syntax -- pointer session, not atom mirror+ useEffect(() => {+ if (!enabled) {+ return+ }++ const onMove = (event: PointerEvent) => {+ const state = stateRef.current++ if (!state || event.pointerId !== state.pointerId) {+ return+ }++ if (!state.armed) {+ if (+ Math.abs(event.screenX - state.startX) > MOVE_TOLERANCE ||+ Math.abs(event.screenY - state.startY) > MOVE_TOLERANCE+ ) {+ reset()+ }++ return+ }++ event.preventDefault()++ const dx = event.screenX - state.lastX+ const dy = event.screenY - state.lastY++ state.lastX = event.screenX+ state.lastY = event.screenY++ window.hermesDesktop?.hud?.moveBy?.({ x: dx, y: dy })+ }++ const onUp = (event: PointerEvent) => {+ const state = stateRef.current++ if (!state || event.pointerId !== state.pointerId) {+ return+ }++ // A completed hold is a grab, not a click on whatever was underneath it.+ if (state.armed) {+ window.addEventListener('click', click => click.stopPropagation(), { capture: true, once: true })+ }++ reset()+ }++ window.addEventListener('pointermove', onMove)+ window.addEventListener('pointerup', onUp)+ window.addEventListener('pointercancel', onUp)++ return () => {+ window.removeEventListener('pointermove', onMove)+ window.removeEventListener('pointerup', onUp)+ window.removeEventListener('pointercancel', onUp)+ }+ }, [enabled, reset])++ useEffect(() => reset, [reset])++ return { grabbing, onPointerDown }+}diff --git a/apps/desktop/src/app/hud/hud-shell.tsx b/apps/desktop/src/app/hud/hud-shell.tsxindex 4908494f184..19266893b0c 100644--- a/apps/desktop/src/app/hud/hud-shell.tsx+++ b/apps/desktop/src/app/hud/hud-shell.tsx@@ -224,8 +224,9 @@ export function HudShell() {// native vibrancy and therefore the WINDOW's content view — it fills the whole// rectangle and nothing in the page can clip it to the sheet. Whenever the// sheet is shorter than the window, the difference is frost over empty space:- // a grey slab hanging under the bar with nothing in it, worst on a fresh- // thread where the sheet is zero and the slab is the entire window.+ // a grey slab hanging under the bar with nothing in it. Now that the band is+ // capped it almost never covers the window, so this is almost always false —+ // which is correct, and asking anything looser paints the slab back.const [filled, setFilled] = useState(false)const rootRef = useRef<HTMLDivElement | null>(null)@@ -333,7 +334,6 @@ export function HudShell() {className="relative flex h-screen w-screen flex-col overflow-hidden"data-hud-edge={edge}data-hud-recent={recent || held ? '' : undefined}- data-hud-scrollable={scrollable ? '' : undefined}data-hud-shell// Letting go of the composer re-arms the hold, so the transcript steps// down to its glanceable opacity and lingers there instead of jumping@@ -356,23 +356,8 @@ export function HudShell() {<WiredPane part="chatRoutes" />- {/* The top fade band, as a drag handle. Its text is masked to nothing up- there, so handing the band's mouse input to the window manager costs- no readable content — and it gives the HUD a grab area that isn't the- composer.-- LAST child on purpose. Electron collects draggable regions by walking- the layout tree in order, uniting `drag` rects and subtracting- `no-drag` ones, so later elements win. Above `WiredPane` this strip- was silently subtracted away by the scrollback's full-height `no-drag`- rect (z-index does not enter into it — the region math is rect-based,- not paint-order-based). */}- <div aria-hidden data-hud-drag-strip />-- {/* The way back. HUD mode has no titlebar, so without this the only- exits are ⌘⇧H and ⌘W — both invisible. Floats over the scrollback- (which is short and top-fades, so it rarely collides with text) and- carves itself out of the drag region so the click lands. */}+ {/* The way back — without it the only exits are ⌘⇧H and ⌘W, both+ invisible. Placed and revealed entirely from styles.css. */}<Tip label={t.titlebar.exitHud}><Buttonaria-label={t.titlebar.exitHud}diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.tsindex 1ff99e37551..7a7ba89b84e 100644--- a/apps/desktop/src/global.d.ts+++ b/apps/desktop/src/global.d.ts@@ -70,6 +70,7 @@ declare global {open: (request?: { sessionId?: null | string }) => Promise<{ ok: boolean }>close: () => Promise<{ ok: boolean }>setIgnoreMouse: (ignore: boolean) => void+ moveBy: (delta: { x: number; y: number }) => voidsetVibrancy: (on: boolean) => Promise<{ ok: boolean }>setSession: (sessionId: null | string) => voidonGoto: (callback: (sessionId: string) => void) => () => voiddiff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.cssindex 53140b2eed0..74d6bfe1427 100644--- a/apps/desktop/src/styles.css+++ b/apps/desktop/src/styles.css@@ -2251,9 +2251,6 @@ button[data-slot='aui_msg-reactions'] svg {[data-hud-shell] {background: transparent;- /* Empty space drags the window; anything that needs the mouse carves itself- back out below. */- -webkit-app-region: drag;/* Arrive decisively and settle; leave gently and get out of the way. Linearboth directions is what made this feel mechanical. */--hud-ease-enter: cubic-bezier(0.16, 1, 0.3, 1);@@ -2524,21 +2521,6 @@ button[data-slot='aui_msg-reactions'] svg {display: none !important;}-/* SCROLLING vs DRAGGING — pick one, per element, per STATE.- `-webkit-app-region: drag` hands an element's mouse input to the window- manager, wheel included — and the region math is rect-based, so a `no-drag`- band subtracts its rectangle even when it's pointer-transparent. The band is- most of the window, so giving its rect away permanently made the HUD nearly- immovable in practice (the composer almost always has focus while in use).-- So the carve-out needs BOTH: composer focused AND actual overflow to scroll- (data-hud-scrollable, set by HudShell). A short conversation leaves the- whole window grabbable; the band only becomes a scroll surface when- scrolling is a real thing you could do with it. */-[data-hud-shell][data-hud-scrollable]:focus-within [data-slot='composer-bounds'] {- -webkit-app-region: no-drag;-}-/* ── Edge flip ───────────────────────────────────────────────────────────────Parked in the top half of the screen (data-hud-edge='top', broadcast bymain on move/resize), the whole HUD mirrors vertically: composer hugs the@@ -2565,27 +2547,6 @@ button[data-slot='aui_msg-reactions'] svg {padding-block-start: calc(var(--hud-bar-height, var(--composer-fallback-height)) + 0.25rem) !important;}-[data-hud-shell][data-hud-edge='top'] [data-hud-drag-strip] {- top: auto;- bottom: 0;-}--/* The drag handle is the top strip of the WINDOW, above the band. The band- itself scrolls (a drag region eats wheel events, so it can never be the- handle); this strip is dead space either way, so it drags. */-[data-hud-shell] [data-hud-drag-strip] {- position: absolute;- top: 0;- left: 0;- right: 0;- height: 2rem;- z-index: 10;- -webkit-app-region: drag;- /* Blank to the eye, but this is the grab handle: a strip the window ignores- is a strip you cannot drag the HUD by. */- pointer-events: auto;-}-/* Tighten the thread on every side. The docked chat's gutters (px-6 py-8 plusa 1.5rem inline pad) are sized for a full window column; in a bar a fewlines tall they're most of the surface. Bottom pad drops to a hairline —@@ -2636,39 +2597,21 @@ button[data-slot='aui_msg-reactions'] svg {--thread-viewport-height: 100%;}-/* The composer BAR is the drag handle: it's the one surface that isn't a- scroll container, so it's the only one that can be. Its frame drags; the- controls carve themselves back out (a drag region eats their clicks too). */+/* NOTHING in HUD mode declares `-webkit-app-region: drag`. The window manager+ takes a draggable region's mouse input whole, so the page never sees the+ cursor arrive there — and `useHudClickThrough`, which decides whether the+ window is solid from exactly those moves, has already handed the window away+ by the time you press. Every version of the app-region handle was therefore+ both unusable (the press fell through to the app behind) and the reason the+ HUD stayed solid over dead space once you left it. The two mechanisms cannot+ share a window; click-through wins, and dragging is `useHudComposerDrag` —+ press and hold the bar, then move. */[data-hud-shell] [data-slot='composer-dock'] {- -webkit-app-region: drag;/* The one surface that is always there, so the one that always takes themouse — everything else in the shell earns it by being on screen. */pointer-events: auto;}-/* Focusables, not a list of the controls that happen to be in the bar today —- a drag region eats the clicks of anything it covers, so anything missed here- is a dead control. */-[data-hud-shell] [data-slot='composer-rich-input'],-[data-hud-shell]- [data-slot='composer-dock']- :is(- a[href],- button,- input,- label,- select,- textarea,- [contenteditable],- [role='button'],- [role='combobox'],- [role='menuitem'],- [role='switch'],- [tabindex]:not([tabindex='-1'])- ) {- -webkit-app-region: no-drag;-}-/* HUD mode is the input and the log — nothing else. The dock stacks[micro-action pills] · [status stack] · [composer] · [underside slot], andonly the composer belongs here: the status stack (todos, subagents,@@ -2831,17 +2774,6 @@ button[data-slot='aui_msg-reactions'] svg {display: none !important;}-/* Portaled overlays (model picker, menus, dialogs, tooltips, the command- palette) mount into <body>, OUTSIDE [data-hud-shell] — so they never inherit- its `no-drag` carve-outs. And Electron's draggable region is RECT math, not- paint order: the shell's window-sized `drag` rect covers wherever the menu- opens, and anything that doesn't explicitly subtract itself is handed to the- window manager. The menu rendered, sat correctly, and swallowed every click- ("I can't even select a model"). Carve every portal back out. */-html:has([data-hud-shell]) body > *:not(#root) {- -webkit-app-region: no-drag;-}-/* Popovers in a ~320px-tall window. Two separate problems:1. Radix clamps the popover to --radix-*-available-height, but fixed