The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): wire the three electron modules merge b3bfc3afe5 left orphaned
ethernetd93e040598ab
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 700cb591473..8aafaf431fb 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -272,7 +272,10 @@ import {import { cursorPointInWindow } from './hud-cursor'import { startHudGameOverlayWatch } from './hud-game-overlay'import { applyHudResetBounds, defaultHudBounds } from './hud-geometry'+import { requestHudClose } from './hud-close'import { registerHudIpc } from './hud-ipc'+import { resolveRemoteOauthTicket, rosterSourceEnumerationTimeoutMs } from './remote-oauth-ticket'+import { PrimaryProfilePin } from './primary-profile-pin'import { applyHudElectronOverlay, promoteHudOverlay } from './hud-overlay'import { snapHudBounds } from './hud-snap'import { createHudSnapShortcut } from './hud-snap-shortcut'@@ -8868,52 +8871,10 @@ async function buildRemoteConnection(const host = remoteHost || hostLabelFromBaseUrl(baseUrl)if (authMode === 'oauth') {- // OAuth gateway: auth comes from EITHER a native bearer token (cookieless- // RFC 8252 flow) OR the session cookies in the OAuth partition. Liveness is- // NOT "is the access-token cookie present?" — Portal issues a 24h rotating- // refresh token (hermes #37247), and the gateway middleware transparently- // rotates a fresh ~15-min access token from it on the next authenticated- // request. So a session with an expired AT cookie but a live RT cookie is- // still perfectly connectable. We early-out only when NEITHER a native- // token NOR any cookie is present, then mint a ws-ticket (which itself- // prefers the native bearer) as the authoritative liveness check.- //- // The native-token check is essential: the native login stores bearer- // tokens (no cookie is ever set), so gating solely on hasLiveOauthSession- // here would reject a freshly-completed native sign-in and loop the UI back- // into "not signed in" even though mintGatewayWsTicket would succeed with- // the stored bearer.- if (- !oauthSessionIsLive(hasNativeSession(baseUrl), await hasLiveOauthSession(baseUrl)) &&- oauthGuardMayHardFail(await gatewayAuthProviders(baseUrl, remoteHeaders))- ) {- throw makeUnsignedOauthError()- }-- let ticket-- try {- ticket = await mintGatewayWsTicket(baseUrl, remoteHeaders)- } catch (error) {- // For a Nous-managed Cloud agent, a 502/503/504 from the WS-ticket mint- // means the backend server itself is down — the actionable Cloud-down- // error. This boundary runs BEFORE the readiness loop, so without this- // the ticket wrapper below would swallow the server-fault classification- // and the renderer would never see isCloudBackendDown. Preserve the- // existing 401/403 reauth and generic transport behavior for everything- // else (#85335).- const cloudError = makeNousCloudBackendDownError(baseUrl, error)-- if (cloudError !== null) {- throw cloudError- }-- throw gatewayTicketFailure(- error,- oauthTicketFailureAuthMessage(hasNativeSession(baseUrl)),- 'Could not reach the remote Hermes gateway while refreshing its WebSocket ticket. Try reconnecting.'- )- }+ const ticket = await resolveRemoteOauthTicket(baseUrl, remoteHeaders, {+ hasNativeSession,+ mintGatewayWsTicket+ })const wsUrl = buildGatewayWsUrlWithTicket(baseUrl, ticket)@@ -10143,6 +10104,8 @@ function resetHermesConnectionState({ soft = false }: { soft?: boolean } = {}):backendStartFailure = nullremoteReauthFailure = nullremoteLiveness.clear()+ // The next startHermes() re-reads active-profile.json for its launch profile.+ primaryProfilePin.clear()invalidatePrimaryConnection()if (!soft) {@@ -10208,11 +10171,13 @@ function broadcastConnectionsChanged(payload: { connectionId: string; reason: 'r}}-// The profile the primary (window) backend runs as. readActiveDesktopProfile()-// returns the desktop's stored preference, or null when unset (legacy launch-// that defers to active_profile / default).+// The profile the primary (window) backend was actually LAUNCHED as. Pinned by+// startHermes() and cleared when the primary is torn down; while a primary is+// live this must NOT follow active-profile.json (see primary-profile-pin.ts).+const primaryProfilePin = new PrimaryProfilePin()+function primaryProfileKey() {- return readActiveDesktopProfile() || 'default'+ return primaryProfilePin.resolve(readActiveDesktopProfile)}// Options describing the current connection setup for `resolveProfileBackendRoute`.@@ -11866,6 +11831,9 @@ async function runHermesStart(): Promise<Awaited<ReturnType<typeof backendConnecconst connectionAttempt = backendConnectionState.startAttempt()const primaryProfile = primaryProfileKey()+ // Pin the routing table to the profile this primary actually boots as; a+ // later hermes:profile:remember must not retarget requests mid-life.+ primaryProfilePin.pin(primaryProfile)// Legacy path callers without an explicit profile belong to the primary// window backend. Profile-scoped callers still pass their key directly.@@ -13266,16 +13234,17 @@ function spawnHudWindow(sessionId, profile) {win.on('closed', () => {if (hudWindow === win) {hudWindow = null+ } else if (hudWindow && !hudWindow.isDestroyed()) {+ // Superseded by a profile respawn: the replacement owns the shortcut,+ // the main-window restore and the toggles. Nothing to hand back.+ return}- // Closed from its own side (⌘W) — closeHudWindow()'s dispose() never ran,- // so the global snap shortcut would otherwise stay registered (and stuck- // taken) with no HUD left to apply it to. dispose() is idempotent, so- // this is safe even if closeHudWindow() already released it.+ // Whether the close came from closeHudWindow() or from the window's own+ // side (a crashed renderer, a native close), this is the one teardown:+ // release the global snap shortcut, put the app back so the user is never+ // left with no surface, and correct every window's toggle.hudSnapShortcut.dispose()-- // Put the app back so the user is never left with no surface, and- // correct every window's toggle.restoreMainWindowFromHud()broadcastHudState(false)})@@ -13289,17 +13258,31 @@ function spawnHudWindow(sessionId, profile) {return win}-// Put the app window back the way HUD mode found it.+// Put the app window back, and give it the keyboard. `focusWindow`, not a bare+// `show()`: show() alone leaves a minimized window minimized, and on macOS a+// shown-but-not-key window means the user is looking at the app with the+// caret still belonging to whatever the HUD was floating over.function restoreMainWindowFromHud() {if (!hudRestoreMainWindow) {return}hudRestoreMainWindow = false+ focusWindow(mainWindow)+}- if (mainWindow && !mainWindow.isDestroyed()) {- mainWindow.show()+// Take the HUD window down. The 'closed' handler stays attached so ONE path+// owns the teardown (snap shortcut, main-window restore, close broadcast)+// whether the window went via the exit button, ⌘W, a profile respawn, or the+// grace deadline — detaching it before close() was how a renderer that never+// answered the close left an always-on-top HUD nobody could dismiss and no+// broadcast to correct the toggles.+function destroyHudWindow(win: BrowserWindow) {+ if (hudWindow === win) {+ hudWindow = null}++ requestHudClose(win)}function openHudWindow(sessionId, profile) {@@ -13309,16 +13292,16 @@ function openHudWindow(sessionId, profile) {// Pointed at another PROFILE: the live renderer is bound to the old// profile's backend, and a renderer adopts its backend exactly once at// boot — an in-place goto would resolve the id against the wrong backend- // (the #82285 fallback). Respawn against the right one.+ // (the #82285 fallback). Respawn against the right one. The old window's+ // 'closed' handler sees `hudWindow` already pointing at the replacement,+ // so it neither restores main nor broadcasts a false "closed".if (profileKey && hudProfile !== profileKey) {- const win = hudWindow- hudWindow = null- win.removeAllListeners('closed')- win.destroy()+ const previous = hudWindowhudSessionId = sessionId || nullhudProfile = profileKeyhudWindow = spawnHudWindow(sessionId, profileKey)+ previous.destroy()broadcastHudState(true)registerHudSnapShortcut()@@ -13352,23 +13335,20 @@ function openHudWindow(sessionId, profile) {}function closeHudWindow() {- hudSnapShortcut.dispose()-const win = hudWindow- hudWindow = nullif (win && !win.isDestroyed()) {- // Null'd first so the 'closed' handler doesn't broadcast a second time.- win.removeAllListeners('closed')- win.close()+ destroyHudWindow(win)++ return}+ // No live HUD (a renderer that died, a toggle racing the close): still+ // release what an open HUD holds, so the toggles read right.+ hudWindow = null+ hudSnapShortcut.dispose()restoreMainWindowFromHud()broadcastHudState(false)-- if (mainWindow && !mainWindow.isDestroyed()) {- focusWindow(mainWindow)- }}// ── Quick Entry ─────────────────────────────────────────────────────────────@@ -14676,16 +14656,14 @@ async function enumerateRegistryAgentSources(registry = readDesktopConnectionsRe// the renderer painted stale rows for the entire outage (and the roster IPC// hung >30s in live repro). Bound each source's enumeration; a timeout is// reported like any other unreachable source and retried on the next poll.- const perSourceTimeoutMs = 10_000-- const withEnumerationDeadline = async <T>(work: Promise<T>): Promise<T> => {+ const withEnumerationDeadline = async <T>(work: Promise<T>, timeoutMs: number): Promise<T> => {let timer: ReturnType<typeof setTimeout> | null = nulltry {return await Promise.race([work,new Promise<never>((_resolve, reject) => {- timer = setTimeout(() => reject(new Error('roster enumeration timed out')), perSourceTimeoutMs)+ timer = setTimeout(() => reject(new Error('roster enumeration timed out')), timeoutMs)})])} finally {@@ -14742,7 +14720,8 @@ async function enumerateRegistryAgentSources(registry = readDesktopConnectionsRebackendDialClaims.run(backendScopeKey(connection.id, null), () =>ensureRegistryBackend(connection.id, null))- )+ ),+ rosterSourceEnumerationTimeoutMs(connection))const { body, installId } = await fetchRosterSourceData(