Skip to content

The agent that grows with you

feat(desktop): point an open HUD at the tab you toggle from

Brooklyn Nicholsonf444e0c5e7bb
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 4fc687ebd30..7be534f59b3 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -9270,6 +9270,17 @@ function restoreMainWindowFromHud() {
function openHudWindow(sessionId) {
if (hudWindow && !hudWindow.isDestroyed()) {
+ // Already up, but pointed somewhere else — switch it rather than just
+ // raising it. Asking for HUD mode from another tab means "put THIS
+ // conversation in the HUD", and a plain focus leaves the wrong one there.
+ if (sessionId && sessionId !== hudSessionId) {
+ hudSessionId = sessionId
+ hudWindow.webContents.send('hermes:hud:goto', sessionId)
+ // Keep every window's idea of where the HUD is pointed in step, so the
+ // toggle keeps reading "switch" vs "dismiss" correctly.
+ broadcastHudState(true)
+ }
+
focusWindow(hudWindow)
return hudWindow
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index 2406798e40a..fbce8197951 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -53,9 +53,16 @@ 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),
+ 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.
setSession: sessionId => ipcRenderer.send('hermes:hud:session', sessionId),
+ onGoto: callback => {
+ const listener = (_event, sessionId) => callback(sessionId)
+ ipcRenderer.on('hermes:hud:goto', listener)
+
+ return () => ipcRenderer.removeListener('hermes:hud:goto', listener)
+ },
onChanged: callback => {
const listener = (_event, state) => callback(state)
ipcRenderer.on('hermes:hud:changed', listener)
diff --git a/apps/desktop/src/app/hud/handoff.ts b/apps/desktop/src/app/hud/handoff.ts
index 750a6ce1664..dfd41a57f9a 100644
--- a/apps/desktop/src/app/hud/handoff.ts
+++ b/apps/desktop/src/app/hud/handoff.ts
@@ -25,6 +25,7 @@ import { isHudWindow } from '@/store/windows'
import { getActiveComposer } from '../chat/composer/focus'
import { openSession, type OpenSessionNavigate } from '../open-session'
+import { sessionRoute } from '../routes'
/** Session tiles route on `tile:<storedSessionId>` (see session-tile.tsx). */
const TILE_TARGET_PREFIX = 'tile:'
@@ -104,6 +105,15 @@ export function useHudHandoff({ navigate, resumeSession }: HudHandoffParams): vo
}, [])
}
+/** HUD side: follow a retarget. Asking for HUD mode from another tab while the
+ * HUD is already up switches the conversation showing in it. */
+export function useHudGoto(navigate: OpenSessionNavigate): void {
+ const navigateRef = useRef(navigate)
+ navigateRef.current = navigate
+
+ useEffect(() => window.hermesDesktop?.hud?.onGoto?.(id => navigateRef.current(sessionRoute(id))), [])
+}
+
/** HUD side: keep main told which session this window is on. */
export function useReportHudSession(): void {
const selectedStoredSessionId = useStore($selectedStoredSessionId)
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 6d2a570a1db..d33d17f682c 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -70,7 +70,9 @@ declare global {
open: (request?: { sessionId?: null | string }) => Promise<{ ok: boolean }>
close: () => Promise<{ ok: boolean }>
setIgnoreMouse: (ignore: boolean) => void
+ setVibrancy: (on: boolean) => Promise<{ ok: boolean }>
setSession: (sessionId: null | string) => void
+ onGoto: (callback: (sessionId: string) => void) => () => void
onChanged: (callback: (state: { open: boolean; sessionId: null | string }) => void) => () => void
}
// Quick Entry: a global-hotkey mini composer window. Main owns the OS
diff --git a/apps/desktop/src/store/hud.ts b/apps/desktop/src/store/hud.ts
index e16f1f11a7a..6135081508e 100644
--- a/apps/desktop/src/store/hud.ts
+++ b/apps/desktop/src/store/hud.ts
@@ -33,6 +33,10 @@ export const $hudActive = atom(isHudWindow())
* never invalidates a render path mid-session. */
export const $hudMode = atom(isHudWindow())
+/** Which conversation the HUD is showing, as far as this window knows. Lets the
+ * toggle tell "switch the HUD to this tab" apart from "dismiss the HUD". */
+export const $hudSession = atom<null | string>(null)
+
/** True when the shell exposes HUD mode (desktop only). */
export const canUseHud = (): boolean =>
typeof window !== 'undefined' && typeof window.hermesDesktop?.hud?.open === 'function'
@@ -50,6 +54,7 @@ export function openHud(sessionId?: null | string): void {
requestComposerDraftSync('flush')
$hudActive.set(true)
+ $hudSession.set(sessionId ?? null)
void api.open({ sessionId: sessionId ?? null })
}
@@ -63,6 +68,7 @@ export function closeHud(): void {
}
$hudActive.set(false)
+ $hudSession.set(null)
void api.close()
}
@@ -82,6 +88,7 @@ export const reportHudSession = (sessionId: null | string): void => window.herme
export function watchHudState(onClosed?: (sessionId: null | string) => void): () => void {
const off = window.hermesDesktop?.hud?.onChanged?.(({ open, sessionId }) => {
$hudActive.set(open)
+ $hudSession.set(open ? sessionId : null)
if (!open) {
onClosed?.(sessionId)