The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): say why window enumeration failed instead of swallowing it
Brooklyn Nicholson5ef1409f5048
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 2046c1c84c5..ca852ad820f 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -340,7 +340,7 @@ import {} from './venv-blocker-scan'import { fetchMarketplaceThemes, searchMarketplaceThemes } from './vscode-marketplace'import { createWakeIndicatorWindowController } from './wake-indicator-window'-import { enumerateWindowsFrontToBack, readWindowBelow } from './window-below'+import { enumerateWindowsFrontToBack, enumerationFailed, readWindowBelow } from './window-below'import { installWindowRendererLifecycle } from './window-renderer-lifecycle'import { createWindowRevealController } from './window-reveal'import {@@ -11833,8 +11833,29 @@ function startHudGameOverlayFeed(win: BrowserWindow) {// did-finish-load also covers HMR full reloads during development.win.webContents.on('did-finish-load', () => push(last))+ // The watch gives up after two failed enumerations and never says so, which+ // is how a HUD that cannot see the screen at all — no game cue, and+ // read_window_below failing beside it — leaves nothing in the log to explain+ // itself. Report the reason once; the null keeps the watch's contract.+ let reported = false++ const enumerate = async () => {+ const windows = await enumerateWindowsFrontToBack(process.pid, titlesAvailable)++ if (!enumerationFailed(windows)) {+ return windows+ }++ if (!reported) {+ reported = true+ console.warn(`[hermes] HUD cannot enumerate windows: ${windows.reason}`)+ }++ return null+ }+const dispose = startHudGameOverlayWatch({- enumerate: () => enumerateWindowsFrontToBack(process.pid, titlesAvailable),+ enumerate,displayBounds: () => screen.getDisplayMatching(win.getBounds()).bounds,selfPid: process.pid,send: state => {diff --git a/apps/desktop/electron/window-below.test.ts b/apps/desktop/electron/window-below.test.tsindex 6a34384518a..d1e2b684ebc 100644--- a/apps/desktop/electron/window-below.test.ts+++ b/apps/desktop/electron/window-below.test.ts@@ -125,4 +125,23 @@ describe('enumerationFailureNote', () => {expect(note.length).toBeGreaterThan(0)}})++ // The macOS/Windows note used to be one fixed sentence, so a real report came+ // back saying only "could not enumerate windows on this system" — the module+ // failing to load, the helper failing to spawn, and the OS answering with+ // nothing are three different fixes and all three said that.+ it('carries the enumerator\u2019s own reason where there is no environmental fork', () => {+ for (const platform of ['darwin', 'win32']) {+ expect(enumerationFailureNote(platform, {}, 'the helper failed: spawn EACCES')).toMatch(/spawn EACCES/)+ }+ })++ // Linux's notes name the fix (change session type, install xprop); the raw+ // exception underneath would only bury it.+ it('keeps the actionable Linux advice instead of the raw reason', () => {+ const note = enumerationFailureNote('linux', { XDG_SESSION_TYPE: 'x11', DISPLAY: ':0' }, 'ENOENT')++ expect(note).toMatch(/xprop/)+ expect(note).not.toMatch(/ENOENT/)+ })})diff --git a/apps/desktop/electron/window-below.ts b/apps/desktop/electron/window-below.tsindex 966c7cb1f5a..3faa078d562 100644--- a/apps/desktop/electron/window-below.ts+++ b/apps/desktop/electron/window-below.ts@@ -57,10 +57,18 @@ export interface WindowBelowUnavailable {* A session with both `WAYLAND_DISPLAY` and `DISPLAY` is Wayland running* XWayland, where `xprop` can still answer — so it is treated as X11 and gets* the tooling advice rather than being told to change session type.+ *+ * macOS and Windows have no environmental fork like that, so their note is+ * whatever the enumerator actually said. That `detail` is the whole point: a+ * bare "could not enumerate windows on this system" is what a real report came+ * back with (macOS 26, packaged app), and neither the tool result nor the+ * desktop log said whether the module failed to load, the helper failed to+ * spawn, or the OS answered with nothing — three failures with three different+ * fixes, all collapsed into one sentence.*/-export function enumerationFailureNote(platform: string, env: NodeJS.ProcessEnv): string {+export function enumerationFailureNote(platform: string, env: NodeJS.ProcessEnv, detail?: string): string {if (platform !== 'linux') {- return 'Could not enumerate windows on this system.'+ return detail ? `Could not enumerate windows: ${detail}` : 'Could not enumerate windows on this system.'}// Hyprland is asked over its own IPC, so reaching here means the socket@@ -128,9 +136,21 @@ type GetWindowsModule = {>}-let getWindowsModule: Promise<GetWindowsModule | null> | null = null+/** Enumeration couldn't run at all, and why. Distinct from an empty list,+ * which is a real answer meaning "nothing else is on screen". */+export interface EnumerationFailure {+ reason: string+}++export const enumerationFailed = <T>(result: EnumerationFailure | T): result is EnumerationFailure =>+ typeof result === 'object' && result !== null && 'reason' in result++const describeError = (error: unknown): string =>+ error instanceof Error ? error.message : String(error ?? 'unknown error')-const loadGetWindows = (): Promise<GetWindowsModule | null> => {+let getWindowsModule: Promise<GetWindowsModule | EnumerationFailure> | null = null++const loadGetWindows = (): Promise<GetWindowsModule | EnumerationFailure> => {// get-windows is an optionalDependency: `npm ci` can skip it when its native// install fails, including Linux and Windows ARM64 where 9.3.0 has no// prebuilt. A missing module is therefore a normal state on those targets,@@ -150,52 +170,63 @@ const loadGetWindows = (): Promise<GetWindowsModule | null> => {// the binding directly, so it is the more reliable of the two everywhere.getWindowsModule ??= (async () => {const staged = path.join(app.getAppPath(), 'dist', 'node_modules', 'get-windows', 'index.js')+ let stagedError = 'not staged in this build'if (fs.existsSync(staged)) {- const mod = await import(pathToFileURL(staged).href).catch(() => null)-- if (mod) {- return mod as GetWindowsModule+ try {+ return (await import(pathToFileURL(staged).href)) as GetWindowsModule+ } catch (error) {+ stagedError = describeError(error)}}- return import('get-windows').catch(() => null)+ try {+ return (await import('get-windows')) as GetWindowsModule+ } catch (error) {+ return {+ reason:+ 'the get-windows module could not be loaded ' ++ `(staged copy: ${stagedError}; node_modules copy: ${describeError(error)})`+ }+ }})()return getWindowsModule}/**- * Enumerate windows and serialize the one underneath `selfBounds`.+ * Every window `get-windows` can see, front-to-back, or why it could not look.** `titlesAvailable` is the macOS Screen Recording grant (pass true on other- * platforms, where titles are free). When enumeration itself is unavailable- * (Wayland, missing xprop, addon load failure) this answers with the reason- * rather than nothing, so the agent can tell the user what to fix instead of- * reporting a blank failure.+ * platforms, where titles are free). The three ways this can fail — the module+ * not loading, the enumerator throwing, the enumerator answering with+ * something that isn't a list — each say so, because they have three different+ * fixes and the caller has no other way to tell them apart.*/-async function enumerateViaGetWindows(titlesAvailable: boolean): Promise<EnumeratedWindow[] | null> {- let raw+async function enumerateViaGetWindows(titlesAvailable: boolean): Promise<EnumeratedWindow[] | EnumerationFailure> {+ const getWindows = await loadGetWindows()- try {- const getWindows = await loadGetWindows()+ if (enumerationFailed(getWindows)) {+ return getWindows+ }- if (!getWindows) {- return null- }+ let raw- const { openWindows } = getWindows- raw = await openWindows(+ try {+ raw = await getWindows.openWindows(process.platform === 'darwin'? { accessibilityPermission: false, screenRecordingPermission: titlesAvailable }: undefined)- } catch {- return null+ } catch (error) {+ // On macOS this is the helper binary failing to spawn — a missing or+ // non-executable `main`, or the OS refusing to run it — which is invisible+ // from the outside and used to surface as the generic note.+ return { reason: `the window enumerator failed: ${describeError(error)}` }}if (!Array.isArray(raw)) {- return null+ return { reason: 'the window enumerator returned no window list' }}// get-windows documents openWindows() as front-to-back, and macOS/Windows@@ -220,7 +251,7 @@ async function enumerateViaGetWindows(titlesAvailable: boolean): Promise<Enumera}/**- * Front-to-back window enumeration, or null when the platform cannot answer.+ * Front-to-back window enumeration, or why the platform could not answer.** Hyprland first, and only ever on Hyprland — its own IPC sees native Wayland* windows, which the X11 enumerator cannot, and it answers null everywhere@@ -231,7 +262,7 @@ async function enumerateViaGetWindows(titlesAvailable: boolean): Promise<Enumeraexport async function enumerateWindowsFrontToBack(selfPid: number,titlesAvailable: boolean-): Promise<EnumeratedWindow[] | null> {+): Promise<EnumeratedWindow[] | EnumerationFailure> {return (await readHyprlandWindows(selfPid)) ?? (await enumerateViaGetWindows(titlesAvailable))}@@ -242,9 +273,9 @@ export async function readWindowBelow(): Promise<WindowBelowResult | WindowBelowUnavailable> {const windows = await enumerateWindowsFrontToBack(selfPid, titlesAvailable)- if (!windows) {+ if (enumerationFailed(windows)) {return {- error: enumerationFailureNote(process.platform, process.env),+ error: enumerationFailureNote(process.platform, process.env, windows.reason),platform: process.platform}}