Skip to content

The agent that grows with you

feat(desktop): give the in-app Browser its own OS window

Brooklyn Nicholsona608799689e4
diff --git a/apps/desktop/electron/browser-windows.test.ts b/apps/desktop/electron/browser-windows.test.ts
new file mode 100644
index 00000000000..8b055bb5403
--- /dev/null
+++ b/apps/desktop/electron/browser-windows.test.ts
@@ -0,0 +1,35 @@
+import assert from 'node:assert/strict'
+
+import { test } from 'vitest'
+
+import { buildBrowserWindowUrl } from './browser-windows'
+
+test('buildBrowserWindowUrl puts win=browser before the hash (dev server)', () => {
+ const url = buildBrowserWindowUrl('url:browser-1', { devServer: 'http://localhost:5173' })
+
+ assert.equal(url, 'http://localhost:5173/?win=browser&tab=url%3Abrowser-1#/')
+ assert.ok(url.indexOf('?win=browser') < url.indexOf('#'))
+})
+
+test('buildBrowserWindowUrl encodes the tab id', () => {
+ const url = buildBrowserWindowUrl('url:browser a/b', { devServer: 'http://localhost:5173' })
+
+ assert.equal(url, 'http://localhost:5173/?win=browser&tab=url%3Abrowser%20a%2Fb#/')
+})
+
+test('buildBrowserWindowUrl avoids a double slash when the dev server has a trailing slash', () => {
+ const url = buildBrowserWindowUrl('t', { devServer: 'http://localhost:5173/' })
+
+ assert.equal(url, 'http://localhost:5173/?win=browser&tab=t#/')
+})
+
+test('buildBrowserWindowUrl omits a blank tab', () => {
+ assert.equal(buildBrowserWindowUrl(' ', { devServer: 'http://localhost:5173' }), 'http://localhost:5173/?win=browser#/')
+ assert.equal(buildBrowserWindowUrl(null, { devServer: 'http://localhost:5173' }), 'http://localhost:5173/?win=browser#/')
+})
+
+test('buildBrowserWindowUrl builds a packaged file URL with the flag before the hash', () => {
+ const url = buildBrowserWindowUrl('abc', { rendererIndexPath: '/opt/app/index.html' })
+
+ assert.match(url, /^file:\/\/.*index\.html\?win=browser&tab=abc#\/$/)
+})
diff --git a/apps/desktop/electron/browser-windows.ts b/apps/desktop/electron/browser-windows.ts
new file mode 100644
index 00000000000..526e5b177cf
--- /dev/null
+++ b/apps/desktop/electron/browser-windows.ts
@@ -0,0 +1,31 @@
+// Popped-out in-app Browser windows. Same query-before-hash contract as
+// session-windows / hud-url: `?win=browser` MUST sit in the search string
+// before the '#', or HashRouter swallows it as part of the route.
+
+import { pathToFileURL } from 'node:url'
+
+export const BROWSER_WINDOW_WIDTH = 960
+export const BROWSER_WINDOW_HEIGHT = 720
+export const BROWSER_WINDOW_MIN_WIDTH = 480
+export const BROWSER_WINDOW_MIN_HEIGHT = 400
+
+/**
+ * Renderer URL for a popped-out Browser. `tab` is the `$previewTabs` id the
+ * window should show — the tab stays in storage so closing the window can
+ * dock it again. Absent/blank tab is still a valid Browser window (blank page).
+ */
+export function buildBrowserWindowUrl(
+ tabId: null | string | undefined,
+ { devServer, rendererIndexPath }: { devServer?: null | string; rendererIndexPath?: string } = {}
+): string {
+ const tab = typeof tabId === 'string' ? tabId.trim() : ''
+ const query = `?win=browser${tab ? `&tab=${encodeURIComponent(tab)}` : ''}`
+
+ if (devServer) {
+ const base = devServer.endsWith('/') ? devServer.slice(0, -1) : devServer
+
+ return `${base}/${query}#/`
+ }
+
+ return `${pathToFileURL(rendererIndexPath!).toString()}${query}#/`
+}
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 1ff042cfb4e..e98a6d0d852 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -282,6 +282,13 @@ import {
} from './remote-liveness'
import { missingRendererAssets } from './renderer-bundle'
import { attachRendererConsoleCapture, formatRendererBoundaryReport } from './renderer-log'
+import {
+ BROWSER_WINDOW_HEIGHT,
+ BROWSER_WINDOW_MIN_HEIGHT,
+ BROWSER_WINDOW_MIN_WIDTH,
+ BROWSER_WINDOW_WIDTH,
+ buildBrowserWindowUrl
+} from './browser-windows'
import {
classifyStoredSecret,
readSecretStoragePolicy,
@@ -11598,6 +11605,87 @@ function createSessionWindow(sessionId, { watch = false } = {}) {
return sessionWindows.openOrFocus(sessionId, () => spawnSecondaryWindow({ sessionId, watch }))
}
+// Popped-out in-app Browser: same webview + address bar as a docked Browser
+// tab, in its own OS window. One window per tab id (re-open focuses); closing
+// it tells the other renderers so they can dock the tab again.
+const browserWindows = createSessionWindowRegistry()
+
+function notifyBrowserPopoutClosed(tabId) {
+ if (typeof tabId !== 'string' || !tabId) {
+ return
+ }
+
+ for (const other of BrowserWindow.getAllWindows()) {
+ if (!other.isDestroyed()) {
+ other.webContents.send('hermes:browser-popout:closed', tabId)
+ }
+ }
+}
+
+function spawnBrowserWindow(tabId) {
+ const icon = getAppIconPath()
+
+ const win = new BrowserWindow({
+ width: BROWSER_WINDOW_WIDTH,
+ height: BROWSER_WINDOW_HEIGHT,
+ minWidth: BROWSER_WINDOW_MIN_WIDTH,
+ minHeight: BROWSER_WINDOW_MIN_HEIGHT,
+ title: 'Hermes',
+ titleBarStyle: 'hidden',
+ titleBarOverlay: getTitleBarOverlayOptions(),
+ trafficLightPosition: IS_MAC ? WINDOW_BUTTON_POSITION : undefined,
+ ...chatWindowSurfaceOptions(),
+ icon,
+ show: false,
+ webPreferences: chatWindowWebPreferences(PRELOAD_PATH)
+ })
+
+ translucencyBackedWindows.add(win)
+
+ if (IS_MAC) {
+ win.setWindowButtonPosition?.(WINDOW_BUTTON_POSITION)
+ }
+
+ wireWindowReveal(win)
+
+ win.on('enter-full-screen', () => sendWindowStateChanged(true))
+ win.on('leave-full-screen', () => sendWindowStateChanged(false))
+
+ streamThrottle.register(win)
+ wireCommonWindowHandlers(win, zoomWiringForWindowKind('chat'))
+ attachRendererConsoleCapture(win, 'browser-window', rememberLog)
+
+ installWindowRendererLifecycle(win, {
+ kind: 'browser',
+ callbacks: {
+ log: rememberLog,
+ reload: () => {
+ win.webContents.reload()
+ }
+ },
+ reloadWindowMs: RENDERER_RELOAD_WINDOW_MS,
+ reloadMax: RENDERER_RELOAD_MAX,
+ recentReloadTimesRef: rendererReloadTimesRef
+ })
+
+ win.on('closed', () => notifyBrowserPopoutClosed(tabId))
+
+ loadWindowUrl(
+ win,
+ buildBrowserWindowUrl(tabId, {
+ devServer: DEV_SERVER,
+ rendererIndexPath: DEV_SERVER ? undefined : resolveRendererIndex()
+ }),
+ 'Browser window'
+ )
+
+ return win
+}
+
+function createBrowserWindow(tabId) {
+ return browserWindows.openOrFocus(tabId, () => spawnBrowserWindow(tabId))
+}
+
// Additional full "instance" windows — peers of the primary that render the
// COMPLETE app (sidebar, routing, its own draft) against the shared backend, so
// a user can run multiple GUI windows at once (⌘⇧N / the "New Window" palette
@@ -12881,6 +12969,15 @@ ipcMain.handle('hermes:window:openInstance', async () => {
return { ok: true }
})
+ipcMain.handle('hermes:window:openBrowser', async (_event, tabId) => {
+ if (typeof tabId !== 'string' || !tabId.trim()) {
+ return { ok: false, error: 'invalid-tab-id' }
+ }
+
+ createBrowserWindow(tabId.trim())
+
+ return { ok: true }
+})
// Hand a session to the user's OWN terminal emulator, running the TUI against
// it (`hermes --tui --resume <id>`). Not the in-app terminal pane: the point is
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index 143b1e74a7c..f406f67cdfc 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -29,6 +29,13 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
openSessionWindow: (sessionId, opts) => ipcRenderer.invoke('hermes:window:openSession', sessionId, opts),
openSessionInTerminal: (sessionId, opts) => ipcRenderer.invoke('hermes:window:openInTerminal', sessionId, opts),
openWindow: () => ipcRenderer.invoke('hermes:window:openInstance'),
+ openBrowserWindow: tabId => ipcRenderer.invoke('hermes:window:openBrowser', tabId),
+ onBrowserPopoutClosed: callback => {
+ const listener = (_event, tabId) => callback(tabId)
+ ipcRenderer.on('hermes:browser-popout:closed', listener)
+
+ return () => ipcRenderer.removeListener('hermes:browser-popout:closed', listener)
+ },
claimAmbientCue: key => ipcRenderer.invoke('hermes:ambient:claim', key),
wakeIndicator: {
getState: () => ipcRenderer.invoke('hermes:wake-indicator:get'),
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 2942cbc16af..5e8d1c8154a 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -63,6 +63,11 @@ declare global {
// renders the complete app against the shared backend, so the user can run
// multiple GUI windows at once.
openWindow: () => Promise<{ ok: boolean; error?: string }>
+ // Pop the in-app Browser (webview + address bar) into its own OS window.
+ // `tabId` is the `$previewTabs` id; closing the window fires
+ // `onBrowserPopoutClosed` so the caller can dock the tab again.
+ openBrowserWindow: (tabId: string) => Promise<{ ok: boolean; error?: string }>
+ onBrowserPopoutClosed: (callback: (tabId: string) => void) => () => void
// Claim a one-shot cross-window ambient cue (turn-end sound / spoken
// reply). Resolves true for the first window to claim a key, false for
// peers — so N open windows don't all fire the same cue.
diff --git a/apps/desktop/src/store/translucency.ts b/apps/desktop/src/store/translucency.ts
index 1b89e4a2e36..c9cc7667bfd 100644
--- a/apps/desktop/src/store/translucency.ts
+++ b/apps/desktop/src/store/translucency.ts
@@ -151,7 +151,7 @@ export function setTranslucencyScope(scope: GlassScope): void {
// secondary session windows). The HUD, pet overlay, quick entry and wake
// indicator are transparent special-purpose windows that manage their own
// backgrounds — a page-surface rewrite there would fight them.
-const CHAT_WINDOW_KINDS = new Set([null, 'secondary'])
+const CHAT_WINDOW_KINDS = new Set([null, 'secondary', 'browser'])
export const isChatWindow = (search = typeof window === 'undefined' ? '' : window.location.search): boolean => {
try {
diff --git a/apps/desktop/src/store/windows.test.ts b/apps/desktop/src/store/windows.test.ts
index d6b745be858..7c032a07f08 100644
--- a/apps/desktop/src/store/windows.test.ts
+++ b/apps/desktop/src/store/windows.test.ts
@@ -1,9 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
+ canOpenBrowserWindow,
canOpenNewWindow,
canOpenSessionWindow,
isPeerInstanceWindow,
+ openBrowserInNewWindow,
openNewWindow,
openSessionInNewWindow
} from './windows'
@@ -19,11 +21,13 @@ vi.mock('./notifications', () => ({
function installBridge(
openSessionWindow?: Window['hermesDesktop']['openSessionWindow'],
- openWindow?: Window['hermesDesktop']['openWindow']
+ openWindow?: Window['hermesDesktop']['openWindow'],
+ openBrowserWindow?: Window['hermesDesktop']['openBrowserWindow']
) {
desktopWindow.hermesDesktop = {
...(openSessionWindow ? { openSessionWindow } : {}),
- ...(openWindow ? { openWindow } : {})
+ ...(openWindow ? { openWindow } : {}),
+ ...(openBrowserWindow ? { openBrowserWindow } : {})
} as unknown as Window['hermesDesktop']
}
@@ -173,3 +177,61 @@ describe('openNewWindow', () => {
expect(notifyError).toHaveBeenCalledTimes(1)
})
})
+
+describe('canOpenBrowserWindow', () => {
+ it('is false when the desktop bridge is absent', () => {
+ delete desktopWindow.hermesDesktop
+ expect(canOpenBrowserWindow()).toBe(false)
+ })
+
+ it('is false when the bridge lacks openBrowserWindow', () => {
+ installBridge(vi.fn().mockResolvedValue({ ok: true }))
+ expect(canOpenBrowserWindow()).toBe(false)
+ })
+
+ it('is true when the bridge exposes openBrowserWindow', () => {
+ installBridge(undefined, undefined, vi.fn().mockResolvedValue({ ok: true }))
+ expect(canOpenBrowserWindow()).toBe(true)
+ })
+})
+
+describe('openBrowserInNewWindow', () => {
+ it('returns false without a tab id', async () => {
+ const open = vi.fn().mockResolvedValue({ ok: true })
+ installBridge(undefined, undefined, open)
+
+ expect(await openBrowserInNewWindow('')).toBe(false)
+ expect(open).not.toHaveBeenCalled()
+ expect(notifyError).not.toHaveBeenCalled()
+ })
+
+ it('returns false when the bridge is absent', async () => {
+ delete desktopWindow.hermesDesktop
+
+ expect(await openBrowserInNewWindow('tab-1')).toBe(false)
+ expect(notifyError).not.toHaveBeenCalled()
+ })
+
+ it('invokes the bridge with the tab id', async () => {
+ const open = vi.fn().mockResolvedValue({ ok: true })
+ installBridge(undefined, undefined, open)
+
+ expect(await openBrowserInNewWindow('tab-1')).toBe(true)
+ expect(open).toHaveBeenCalledWith('tab-1')
+ expect(notifyError).not.toHaveBeenCalled()
+ })
+
+ it('returns false and notifies on an ok:false result', async () => {
+ installBridge(undefined, undefined, vi.fn().mockResolvedValue({ ok: false, error: 'invalid-tab-id' }))
+
+ expect(await openBrowserInNewWindow('tab-1')).toBe(false)
+ expect(notifyError).toHaveBeenCalledTimes(1)
+ })
+
+ it('returns false and notifies when the bridge throws', async () => {
+ installBridge(undefined, undefined, vi.fn().mockRejectedValue(new Error('boom')))
+
+ expect(await openBrowserInNewWindow('tab-1')).toBe(false)
+ expect(notifyError).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/apps/desktop/src/store/windows.ts b/apps/desktop/src/store/windows.ts
index 1403863d536..8015893d882 100644
--- a/apps/desktop/src/store/windows.ts
+++ b/apps/desktop/src/store/windows.ts
@@ -76,12 +76,42 @@ export function isWatchWindow(): boolean {
return result
}
+// A "browser" window is a popped-out in-app Browser: the same webview +
+// address bar as the docked tab, in its own OS window. The tab id rides
+// `?tab=` next to `win=browser` (before the hash, same contract as secondary).
+let browserWindowCache: boolean | null = null
+
+export function isBrowserWindow(): boolean {
+ if (browserWindowCache !== null) {
+ return browserWindowCache
+ }
+
+ let result = false
+
+ try {
+ result = new URLSearchParams(window.location.search).get('win') === 'browser'
+ } catch {
+ result = false
+ }
+
+ browserWindowCache = result
+
+ return result
+}
+
+export function windowBrowserTabId(): null | string {
+ try {
+ return new URLSearchParams(window.location.search).get('tab')?.trim() || null
+ } catch {
+ return null
+ }
+}
+
// True for any window that is NOT the primary app instance — a secondary
-// session window or the HUD. Single-claim channels (the quick-entry capture
-// bridge, the pet overlay control bridge) and the install/onboarding overlays
-// belong to the primary alone: two windows answering one channel turns one
-// keystroke into N prompts, and a HUD is the last place to paint onboarding.
-export const isAuxiliaryWindow = (): boolean => isSecondaryWindow() || isHudWindow()
+// session window, the HUD, or a popped-out Browser. Single-claim channels
+// (the quick-entry capture bridge, the pet overlay control bridge) and the
+// install/onboarding overlays belong to the primary alone.
+export const isAuxiliaryWindow = (): boolean => isSecondaryWindow() || isHudWindow() || isBrowserWindow()
// A full peer window renders the ordinary app shell against the backend that
// Electron already has running. It is not an auxiliary/specialized renderer,
@@ -122,6 +152,11 @@ export function canOpenNewWindow(): boolean {
return typeof window !== 'undefined' && typeof window.hermesDesktop?.openWindow === 'function'
}
+// True when the shell can pop the in-app Browser into its own OS window.
+export function canOpenBrowserWindow(): boolean {
+ return typeof window !== 'undefined' && typeof window.hermesDesktop?.openBrowserWindow === 'function'
+}
+
// True when the shell can hand a session to the user's own terminal emulator.
// Desktop-only, and a REMOTE connection is excluded by the caller: the terminal
// we'd open is on this machine, but the session lives on the remote host.
@@ -133,15 +168,21 @@ type WindowOpenResult = { ok: boolean; error?: string } | undefined
// Run a window-open bridge call, surfacing any failure as a toast. Shared by the
// session pop-out and the new-window opener.
-async function runWindowOpen(call: () => Promise<WindowOpenResult>, failMessage: string): Promise<void> {
+async function runWindowOpen(call: () => Promise<WindowOpenResult>, failMessage: string): Promise<boolean> {
try {
const result = await call()
if (!result?.ok) {
notifyError(new Error(result?.error || 'unknown error'), failMessage)
+
+ return false
}
+
+ return true
} catch (err) {
notifyError(err, failMessage)
+
+ return false
}
}
@@ -169,6 +210,16 @@ export async function openNewWindow(): Promise<void> {
await runWindowOpen(() => window.hermesDesktop.openWindow(), 'Could not open a new window')
}
+/** Pop the in-app Browser into its own OS window. Returns whether the
+ * window opened so the caller can dock the tab again on failure. */
+export async function openBrowserInNewWindow(tabId: string): Promise<boolean> {
+ if (!tabId || !canOpenBrowserWindow()) {
+ return false
+ }
+
+ return runWindowOpen(() => window.hermesDesktop.openBrowserWindow(tabId), 'Could not pop out browser')
+}
+
// Resume a session in the user's own terminal emulator, running the TUI there.
// `cwd` starts the shell in the session's workspace; `profile` pins the runtime
// to the profile that owns the session. No-ops gracefully outside Electron.