Skip to content

The agent that grows with you

fix(desktop): ⌘W on a remote bot screen closes nothing local; profile-group header rows keep one render identity

teknium154b034f611a5
diff --git a/apps/desktop/src/app/chat/close-tab.test.ts b/apps/desktop/src/app/chat/close-tab.test.ts
index 219f20df6d4..f0785a6bc98 100644
--- a/apps/desktop/src/app/chat/close-tab.test.ts
+++ b/apps/desktop/src/app/chat/close-tab.test.ts
@@ -7,6 +7,12 @@ const nextSessionTileForWorkspace = vi.fn<() => null | string>(() => null)
const closeSessionTile = vi.fn()
const requestFreshSession = vi.fn()
+const closeActiveTerminal = vi.fn()
+
+vi.mock('@/app/right-sidebar/terminal/terminals', () => ({
+ closeActiveTerminal: () => closeActiveTerminal()
+}))
+
vi.mock('@/components/pane-shell/tree/store', () => ({
closeFocusedSessionTab: () => closeFocusedSessionTab(),
closeFocusedToolTab: () => closeFocusedToolTab()
@@ -136,6 +142,20 @@ describe('closeWorkspaceTab', () => {
expect(requestFreshSession).toHaveBeenCalledTimes(1)
})
+ it('a focused remote bot screen swallows ⌘W: no terminal tab, no session tab closes', async () => {
+ loadedMainOnly()
+ const combo = await import('@/lib/keybinds/combo')
+ const spy = vi.spyOn(combo, 'isFocusWithin').mockImplementation(selector => selector === '[data-remote-screen]' || selector === '[data-terminal]')
+
+ try {
+ expect(closeActiveTab(vi.fn())).toBe(true)
+ expect(closeActiveTerminal).not.toHaveBeenCalled()
+ expect(requestFreshSession).not.toHaveBeenCalled()
+ } finally {
+ spy.mockRestore()
+ }
+ })
+
it('a focused tool panel (terminal / logs) claims ⌘W before main empties', () => {
loadedMainOnly()
closeFocusedToolTab.mockReturnValue(true)
diff --git a/apps/desktop/src/app/chat/close-tab.ts b/apps/desktop/src/app/chat/close-tab.ts
index 4304138904f..6aa681fba22 100644
--- a/apps/desktop/src/app/chat/close-tab.ts
+++ b/apps/desktop/src/app/chat/close-tab.ts
@@ -67,6 +67,12 @@ export function closeWorkspaceTab(loadSessionIntoWorkspace?: (storedSessionId: s
* with its own tab strip closes ITS tab instead of main's.
*/
export function closeActiveTab(loadSessionIntoWorkspace?: (storedSessionId: string) => void): boolean {
+ // A remote bot screen borrows the terminal's keyboard ownership marker so bare keys reach it; ⌘W
+ // there belongs to the remote desktop, never to a local terminal tab or the session tab behind it.
+ if (isFocusWithin('[data-remote-screen]')) {
+ return true
+ }
+
if (isFocusWithin('[data-terminal]')) {
closeActiveTerminal()
diff --git a/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx b/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx
index 65504ebb839..829c85ff081 100644
--- a/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx
+++ b/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx
@@ -2,7 +2,7 @@ import type { useSensors } from '@dnd-kit/core'
import { arrayMove } from '@dnd-kit/sortable'
import { useStore } from '@nanostores/react'
import type { ReactNode } from 'react'
-import { useState } from 'react'
+import { useMemo, useState } from 'react'
import { type NewSessionSplitHandler, startNewSessionDrag } from '@/app/chat/new-session-drag'
import { type ProfileGroupHeaderContribution, SIDEBAR_PROFILE_GROUP_HEADER_AREA } from '@/app/routes'
@@ -339,14 +339,28 @@ function ProfileGroupHeaderSlot({ connectionId, profile }: { connectionId: null
return null
}
- const render = data.render
-
return (
<ContribBoundary id={item.id} key={item.id} variant="chip">
- <ContribRender render={() => render({ connectionId, profile })} />
+ <ProfileGroupHeaderItem connectionId={connectionId} profile={profile} render={data.render} />
</ContribBoundary>
)
})}
</div>
)
}
+
+/** One stable render identity per (render, connection, profile): ContribRender mounts whatever
+ * function it is handed, so an inline closure would remount the contribution on every paint. */
+function ProfileGroupHeaderItem({
+ connectionId,
+ profile,
+ render
+}: {
+ connectionId: null | string
+ profile: string
+ render: ProfileGroupHeaderContribution['render']
+}) {
+ const Row = useMemo(() => () => render({ connectionId, profile }), [connectionId, profile, render])
+
+ return <ContribRender render={Row} />
+}