The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): clamp cascaded instance windows to the work area they land on
teknium117c7f73a18ff
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 3ad303adcee..d6ff99058cb 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -13623,10 +13623,11 @@ const instanceWindows = new Set<any>()// when there's no live source window (e.g. all windows closed on macOS). The// pure cascade math lives in session-windows.ts (instanceWindowBounds).function nextInstanceBounds(source: BrowserWindow | null = BrowserWindow.getFocusedWindow() || mainWindow) {- const fallback = computeWindowOptions(readWindowState(), screen.getAllDisplays())+ const displays = screen.getAllDisplays()+ const fallback = computeWindowOptions(readWindowState(), displays)const base = source && !source.isDestroyed() ? source.getBounds() : null- return instanceWindowBounds(base, fallback)+ return instanceWindowBounds(base, fallback, displays)}// Open a new full-chrome instance window. Mirrors createWindow()'s windowdiff --git a/apps/desktop/electron/session-windows.test.ts b/apps/desktop/electron/session-windows.test.tsindex 9c21f9c1732..9c673864986 100644--- a/apps/desktop/electron/session-windows.test.ts+++ b/apps/desktop/electron/session-windows.test.ts@@ -130,6 +130,14 @@ test('instanceWindowBounds cascades a new window off its source bounds', () => {assert.deepEqual(bounds, { width: 1400, height: 900, x: 132, y: 152 })})+test('instanceWindowBounds keeps the cascaded window inside the work area it lands on', () => {+ const displays = [{ workArea: { x: 0, y: 0, width: 1920, height: 1040 } }]+ // Source docked at the bottom-right: a raw +32/+32 cascade would overshoot both edges.+ const bounds = instanceWindowBounds({ x: 700, y: 240, width: 1220, height: 800 }, { width: 1, height: 1 }, displays)++ assert.deepEqual(bounds, { width: 1220, height: 800, x: 700, y: 240 })+})+test('instanceWindowBounds falls back to the persisted geometry with no source window', () => {const fallback = { width: 1280, height: 800 }diff --git a/apps/desktop/electron/session-windows.ts b/apps/desktop/electron/session-windows.tsindex ff66425a1da..8785b04d4dc 100644--- a/apps/desktop/electron/session-windows.ts+++ b/apps/desktop/electron/session-windows.ts@@ -6,6 +6,7 @@import { pathToFileURL } from 'node:url'import type { DesktopWindowLaunch } from './desktop-profile'+import { computeWindowOptions } from './window-state'// Secondary windows open at the minimum usable size — a compact side panel for// subagent watch / cmd-click session pop-out, not a second full desktop.@@ -112,20 +113,29 @@ function buildInstanceWindowUrl({ connectionId, devServer, profile, profileWindo// it's unit-testable; the Electron glue (reading the focused window's bounds,// constructing the BrowserWindow) stays in main.ts. `base` is the source// window's current bounds, or null when there's no live source window — then the-// persisted primary geometry (`fallback`) is used as-is.+// persisted primary geometry (`fallback`) is used as-is. The cascaded rect is+// clamped to the work area it lands on (a source docked at the bottom/right edge+// would otherwise push the new window past the screen); with no matching+// display it is kept as computed.const INSTANCE_CASCADE_OFFSET = 32-function instanceWindowBounds(base: { x: number; y: number; width: number; height: number } | null, fallback: any) {+function instanceWindowBounds(+ base: { x: number; y: number; width: number; height: number } | null,+ fallback: any,+ displays: any[] = []+) {if (!base) {return fallback}- return {+ const bounds = {width: base.width,height: base.height,x: base.x + INSTANCE_CASCADE_OFFSET,y: base.y + INSTANCE_CASCADE_OFFSET}++ return { ...bounds, ...computeWindowOptions(bounds, displays) }}// A small registry keyed by sessionId that guarantees one window per chat: