The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scope pane fallback menus to the clicked content
unsupportedpastels40a2637faed5
diff --git a/apps/desktop/src/app/context-menu/app-context-menu.test.tsx b/apps/desktop/src/app/context-menu/app-context-menu.test.tsxindex 9b30fbcabe3..82b40bde0f4 100644--- a/apps/desktop/src/app/context-menu/app-context-menu.test.tsx+++ b/apps/desktop/src/app/context-menu/app-context-menu.test.tsx@@ -397,9 +397,11 @@ describe('AppContextMenu', () => {it('lets editable targets inside a radix surface use the edit menu', async () => {installBridge()mountMenu()+const host = attach(- `<div data-slot="context-menu-trigger"><textarea>draft text</textarea></div>`+ `<div data-zone-body="test" data-slot="context-menu-trigger"><textarea>draft text</textarea></div>`)+const textarea = host.querySelector('textarea')!fireEvent.contextMenu(textarea)diff --git a/apps/desktop/src/app/context-menu/app-context-menu.tsx b/apps/desktop/src/app/context-menu/app-context-menu.tsxindex 4aac3b783c0..7da53ec8e42 100644--- a/apps/desktop/src/app/context-menu/app-context-menu.tsx+++ b/apps/desktop/src/app/context-menu/app-context-menu.tsx@@ -1,11 +1,10 @@import { useStore } from '@nanostores/react'import type { ReactNode } from 'react'import { useEffect } from 'react'-import { useNavigate } from 'react-router'import { terminalMenuHandleFor } from '@/app/right-sidebar/terminal/terminal-context-menu'import { openStarMapNodeMenuFor } from '@/app/starmap/context-menu-handle'-import { toggleTargetZoneTabStrip } from '@/components/pane-shell/tree/store'+import { DROPDOWN_KIT } from '@/components/ui/actions-menu'import { Codicon } from '@/components/ui/codicon'import { HERMES_CONTEXT_MENU_TRIGGER_ATTR } from '@/components/ui/context-menu'import { writeClipboardText } from '@/components/ui/copy-button'@@ -22,15 +21,9 @@ import { hostPathLabel, hudForcesNativeLinks, normalizeExternalUrl, openExternalimport { formatCombo } from '@/lib/keybinds/combo'import { isRemoteGateway } from '@/lib/media'import { reachablePreviewUrl } from '@/lib/preview-reach'-import { openCommandPalette } from '@/store/command-palette'import { openPreview } from '@/store/preview'-import { toggleProfileRailVisible } from '@/store/profile-rail-prefs'-import { toggleStatusbarVisible } from '@/store/statusbar-prefs'-import { requestActiveUpdate } from '@/store/updates'-import { canOpenNewWindow, openNewWindow } from '@/store/windows'--import { navigateToWorkspacePage, NEW_CHAT_ROUTE, SETTINGS_ROUTE } from '../routes'+import { ShellMenuItems } from './shell-menu-items'import {$contextMenu,augmentSpellcheck,@@ -92,11 +85,6 @@ function Item({)}-type ShellVerbs = {- navigate: ReturnType<typeof useNavigate>- t: Translations-}-function terminalSections(open: Extract<OpenContextMenu, { kind: 'terminal' }>, t: Translations): ReactNode[][] {const { terminal } = openconst selection = terminal.getSelection()@@ -540,66 +528,6 @@ function guestSections(open: Extract<OpenContextMenu, { kind: 'guest' }>, t: Trareturn sections}-/** Bare right-click on app chrome: the window verbs (the old shell fallback). */-function shellSections({ navigate, t }: ShellVerbs): ReactNode[][] {- return [- [- <Item- icon="add"- key="shell-new-chat"- label={t.commandCenter.nav.newChat.title}- onSelect={() => navigateToWorkspacePage(navigate, NEW_CHAT_ROUTE)}- />,- canOpenNewWindow() ? (- <Item- icon="multiple-windows"- key="shell-new-window"- label={t.keybinds.actions['session.newWindow']}- onSelect={() => void openNewWindow()}- />- ) : null,- <Item icon="search" key="shell-palette" label={t.commandCenter.paletteTitle} onSelect={openCommandPalette} />- ].filter(Boolean),- [- <Item- icon="layout-statusbar"- key="shell-statusbar"- label={t.keybinds.actions['view.toggleStatusbar']}- onSelect={toggleStatusbarVisible}- />,- <Item- icon="organization"- key="shell-profile-rail"- label={t.keybinds.actions['view.toggleProfileRail']}- onSelect={toggleProfileRailVisible}- />,- // The pointer-only way back to a hidden tab strip: right-clicking the- // shell reaches this menu from anywhere, including a zone that has no- // chrome left to right-click.- <Item- icon="layout-menubar"- key="shell-tabstrip"- label={t.keybinds.actions['view.toggleTabStrip']}- onSelect={() => void toggleTargetZoneTabStrip()}- />,- <Item- icon="settings-gear"- key="shell-settings"- label={t.commandCenter.settings}- onSelect={() => navigateToWorkspacePage(navigate, SETTINGS_ROUTE)}- />- ],- [- <Item- icon="cloud-download"- key="shell-update"- label={t.commandCenter.updateHermes}- onSelect={requestActiveUpdate}- />- ]- ]-}-/*** THE app context menu: one capture-phase listener, one store, one menu.*@@ -614,7 +542,6 @@ function shellSections({ navigate, t }: ShellVerbs): ReactNode[][] {*/export function AppContextMenu() {const { t } = useI18n()- const navigate = useNavigate()const open = useStore($contextMenu)useEffect(() => {@@ -625,6 +552,14 @@ export function AppContextMenu() {const onContextMenu = (event: MouseEvent) => {const element = event.target instanceof Element ? event.target : null+ const trigger = element?.closest(`[${HERMES_CONTEXT_MENU_TRIGGER_ATTR}], [data-slot="context-menu-trigger"]`)++ // Only the pane-body wrapper is a fallback menu. Explicit row, tab and+ // status-bar menus still own their whole gesture, even inside a pane.+ if (trigger && !trigger.hasAttribute('data-zone-body')) {+ return+ }+// The Star Map owns node hits, but empty canvas space still reaches the// shell fallback below. A canvas-wide opt-out would lose that fallback.if (openStarMapNodeMenuFor(element, event.clientX, event.clientY)) {@@ -646,15 +581,21 @@ export function AppContextMenu() {}const target = resolveDomTarget(element)- const owned = Boolean(target.linkUrl || target.onImage || target.editable || target.selectionText)-- // Radix surfaces keep gestures that do not belong to an editable or- // selection. Resolve first so the pane's zone wrapper cannot shadow the- // edit menu for content inside it.- if (- !owned &&- element?.closest(`[${HERMES_CONTEXT_MENU_TRIGGER_ATTR}], [data-slot="context-menu-trigger"]`)- ) {+ const selection = window.getSelection()++ const selected = Boolean(+ target.selectionText &&+ element &&+ selection &&+ Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index)).some(range =>+ range.intersectsNode(element)+ )+ )++ const owned = Boolean(target.linkUrl || target.onImage || target.editable || selected)++ // A selection elsewhere in the same pane must not take its bare menu.+ if (!owned && trigger) {return}@@ -686,7 +627,7 @@ export function AppContextMenu() {? terminalSections(open, t): open.kind === 'guest'? guestSections(open, t)- : (list => (list.length ? list : shellSections({ navigate, t })))(domSections(open, t))+ : (list => (list.length ? list : [[<ShellMenuItems key="shell" kit={DROPDOWN_KIT} />]]))(domSections(open, t))return (<DropdownMenudiff --git a/apps/desktop/src/app/context-menu/pane-context-menu.test.tsx b/apps/desktop/src/app/context-menu/pane-context-menu.test.tsxnew file mode 100644index 00000000000..1203d768e44--- /dev/null+++ b/apps/desktop/src/app/context-menu/pane-context-menu.test.tsx@@ -0,0 +1,135 @@+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { MemoryRouter } from 'react-router'+import { afterEach, expect, it, vi } from 'vitest'++import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@/components/ui/context-menu'++import { AppContextMenu } from './app-context-menu'+import { $contextMenu } from './store'++const desktopDescriptor = Object.getOwnPropertyDescriptor(window, 'hermesDesktop')+const editableDescriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'isContentEditable')++function setup() {+ // jsdom lacks the browser's isContentEditable property.+ Object.defineProperty(HTMLElement.prototype, 'isContentEditable', {+ configurable: true,+ get() {+ const host = this.closest('[contenteditable]')++ return !!host && host.getAttribute('contenteditable') !== 'false'+ }+ })+ Object.defineProperty(window, 'hermesDesktop', {+ configurable: true,+ value: { writeClipboard: vi.fn().mockResolvedValue(undefined) }+ })+ render(+ <MemoryRouter>+ <AppContextMenu />+ <ContextMenu>+ <ContextMenuTrigger asChild>+ <div data-zone-body="test">+ <textarea data-testid="empty" />+ <input data-testid="input" defaultValue="draft text" />+ <div contentEditable data-testid="editable">+ <span data-testid="editable-child">draft</span>+ </div>+ <p data-testid="selected">transcript words</p>+ <p data-testid="bare">empty space</p>+ <a data-testid="link" href="https://example.com">+ link+ </a>+ <img data-testid="image" src="https://example.com/pic.png" />+ <ContextMenu>+ <ContextMenuTrigger asChild>+ <div data-testid="nested">+ <a data-testid="nested-link" href="https://example.com/row">+ row+ </a>+ </div>+ </ContextMenuTrigger>+ <ContextMenuContent>+ <ContextMenuItem>Row action</ContextMenuItem>+ </ContextMenuContent>+ </ContextMenu>+ </div>+ </ContextMenuTrigger>+ <ContextMenuContent>+ <ContextMenuItem>Zone action</ContextMenuItem>+ </ContextMenuContent>+ </ContextMenu>+ </MemoryRouter>+ )+}++function select() {+ const range = document.createRange()+ range.selectNodeContents(screen.getByTestId('selected'))+ window.getSelection()!.removeAllRanges()+ window.getSelection()!.addRange(range)+}++afterEach(() => {+ $contextMenu.set(null)+ cleanup()+ window.getSelection()?.removeAllRanges()+ vi.restoreAllMocks()++ if (desktopDescriptor) {+ Object.defineProperty(window, 'hermesDesktop', desktopDescriptor)+ } else {+ Reflect.deleteProperty(window, 'hermesDesktop')+ }++ if (editableDescriptor) {+ Object.defineProperty(HTMLElement.prototype, 'isContentEditable', editableDescriptor)+ } else {+ Reflect.deleteProperty(HTMLElement.prototype, 'isContentEditable')+ }+})+it.each([+ ['empty', 'Paste'],+ ['input', 'Paste'],+ ['editable-child', 'Paste'],+ ['link', 'Copy URL'],+ ['image', 'Copy image']+])('content %s gets %s', async (id, label) => {+ setup()+ fireEvent.contextMenu(screen.getByTestId(id))+ expect(await screen.findByText(label)).toBeTruthy()+ expect(screen.queryByText('Zone action')).toBeNull()+})+it('selection offers Copy and copies actual text', async () => {+ setup()+ select()+ fireEvent.contextMenu(screen.getByTestId('selected'))+ fireEvent.click(await screen.findByText('Copy'))+ expect(window.hermesDesktop!.writeClipboard).toHaveBeenCalledWith('transcript words')+})+it('bare pane keeps zone menu', async () => {+ setup()+ fireEvent.contextMenu(screen.getByTestId('bare'))+ expect(await screen.findByText('Zone action')).toBeTruthy()+ expect($contextMenu.get()).toBeNull()+})+it('stale selection does not steal bare pane menu', async () => {+ setup()+ select()+ fireEvent.contextMenu(screen.getByTestId('bare'))+ expect(await screen.findByText('Zone action')).toBeTruthy()+ expect($contextMenu.get()).toBeNull()+})+it('nested explicit menu keeps links', async () => {+ setup()+ fireEvent.contextMenu(screen.getByTestId('nested-link'))+ expect(await screen.findByText('Row action')).toBeTruthy()+ expect($contextMenu.get()).toBeNull()+})+it('stale selection does not steal nested menu', async () => {+ setup()+ select()+ fireEvent.contextMenu(screen.getByTestId('nested'))+ expect(await screen.findByText('Row action')).toBeTruthy()+ expect($contextMenu.get()).toBeNull()+})diff --git a/apps/desktop/src/app/context-menu/shell-menu-items.tsx b/apps/desktop/src/app/context-menu/shell-menu-items.tsxnew file mode 100644index 00000000000..aa7d80e6980--- /dev/null+++ b/apps/desktop/src/app/context-menu/shell-menu-items.tsx@@ -0,0 +1,107 @@+import type { ReactNode } from 'react'+import { useNavigate } from 'react-router'++import { toggleTargetZoneTabStrip } from '@/components/pane-shell/tree/store'+import { type ActionItemSpec, type MenuKit, renderActionItem } from '@/components/ui/actions-menu'+import { type Translations, useI18n } from '@/i18n'+import { openCommandPalette } from '@/store/command-palette'+import { toggleProfileRailVisible } from '@/store/profile-rail-prefs'+import { toggleStatusbarVisible } from '@/store/statusbar-prefs'+import { requestActiveUpdate } from '@/store/updates'+import { canOpenNewWindow, openNewWindow } from '@/store/windows'++import { navigateToWorkspacePage, NEW_CHAT_ROUTE, SETTINGS_ROUTE } from '../routes'++/** Bare right-click on app chrome: the window verbs (the old shell fallback). */+function shellSections(+ kit: MenuKit,+ navigate: ReturnType<typeof useNavigate>,+ t: Translations,+ primaryOnly: boolean+): ReactNode[][] {+ const Item = ({ icon, label, onSelect }: ActionItemSpec) => renderActionItem(kit, { icon, label, onSelect })++ const newChat = (+ <Item+ icon="add"+ key="shell-new-chat"+ label={t.commandCenter.nav.newChat.title}+ onSelect={() => navigateToWorkspacePage(navigate, NEW_CHAT_ROUTE)}+ />+ )++ const settings = (+ <Item+ icon="settings-gear"+ key="shell-settings"+ label={t.commandCenter.settings}+ onSelect={() => navigateToWorkspacePage(navigate, SETTINGS_ROUTE)}+ />+ )++ const update = (+ <Item+ icon="cloud-download"+ key="shell-update"+ label={t.commandCenter.updateHermes}+ onSelect={requestActiveUpdate}+ />+ )++ if (primaryOnly) {+ return [[newChat, settings, update]]+ }++ return [+ [+ newChat,+ canOpenNewWindow() ? (+ <Item+ icon="multiple-windows"+ key="shell-new-window"+ label={t.keybinds.actions['session.newWindow']}+ onSelect={() => void openNewWindow()}+ />+ ) : null,+ <Item icon="search" key="shell-palette" label={t.commandCenter.paletteTitle} onSelect={openCommandPalette} />+ ].filter(Boolean),+ [+ <Item+ icon="layout-statusbar"+ key="shell-statusbar"+ label={t.keybinds.actions['view.toggleStatusbar']}+ onSelect={toggleStatusbarVisible}+ />,+ <Item+ icon="organization"+ key="shell-profile-rail"+ label={t.keybinds.actions['view.toggleProfileRail']}+ onSelect={toggleProfileRailVisible}+ />,+ // The pointer-only way back to a hidden tab strip: right-clicking the+ // shell reaches this menu from anywhere, including a zone that has no+ // chrome left to right-click.+ <Item+ icon="layout-menubar"+ key="shell-tabstrip"+ label={t.keybinds.actions['view.toggleTabStrip']}+ onSelect={() => void toggleTargetZoneTabStrip()}+ />,+ settings+ ],+ [update]+ ]+}++/** Shared by bare app chrome and the pane body's fallback section. */+export function ShellMenuItems({ kit, primaryOnly = false }: { kit: MenuKit; primaryOnly?: boolean }) {+ const navigate = useNavigate()+ const { t } = useI18n()++ return shellSections(kit, navigate, t, primaryOnly).map((section, index) => (+ <div className="contents" key={index}>+ {index > 0 && <kit.Separator />}+ {section}+ </div>+ ))+}diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsxindex 08de26aeb3a..6569e362f14 100644--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.test.tsx@@ -1,6 +1,7 @@import { fireEvent, screen } from '@testing-library/react'import { act, type ReactNode } from 'react'import { createRoot, type Root } from 'react-dom/client'+import { MemoryRouter } from 'react-router'import { afterEach, describe, expect, it, vi } from 'vitest'import { registry } from '@/contrib/registry'@@ -24,7 +25,7 @@ function render(ui: ReactNode) {}act(() => {- root!.render(ui)+ root!.render(<MemoryRouter>{ui}</MemoryRouter>)})}@@ -357,5 +358,8 @@ describe('TreeGroup', () => {// own close-flavored row) — what matters is that the BODY opens A menu// offering a Close verb.expect(screen.getAllByRole('menuitem', { name: /close/i }).length).toBeGreaterThan(0)+ expect(screen.getByRole('menuitem', { name: /new (chat|session)/i })).toBeTruthy()+ expect(screen.getByRole('menuitem', { name: /settings/i })).toBeTruthy()+ expect(screen.getByRole('menuitem', { name: /update/i })).toBeTruthy()})})diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsxindex 1a6dbadc1ec..84957b59e53 100644--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx@@ -1,3 +1,4 @@+import { useStore } from '@nanostores/react'/*** Group node renderer — a ZONE: header strip (tabs when stacked, minimize* chevron) + the active pane's content, resolved from the contribution@@ -8,10 +9,9 @@* every zone lights up as a whole-region drop target. Right-click opens the* contextual zone menu (tab close verbs + header/minimize toggles).*/--import { useStore } from '@nanostores/react'import { type CSSProperties, Fragment, type ReactNode, type RefObject, useEffect, useRef, useState } from 'react'+import { ShellMenuItems } from '@/app/context-menu/shell-menu-items'import { TITLEBAR_DRAG_HANDLE_WIDTH, TITLEBAR_HEIGHT } from '@/app/shell/titlebar'import { ActionsContextMenu, type MenuKit, renderActionItem } from '@/components/ui/actions-menu'import { Codicon } from '@/components/ui/codicon'@@ -99,6 +99,7 @@ import { paneChrome } from './track-model'function ZoneMenu({children,closable,+ includeAppActions = false,minimizable = true,minimizeLabel,minimized,@@ -108,6 +109,7 @@ function ZoneMenu({targetPane}: {children: ReactNode+ includeAppActions?: boolean/** The pane the menu closes (the right-clicked chip / the active pane);* undefined = not closable (the main zone). */closable?: () => string | undefined@@ -212,6 +214,12 @@ function ZoneMenu({label: minimized ? t.zones.restore : (minimizeLabel ?? t.zones.minimize),onSelect: () => setTreeGroupMinimized(nodeId, !minimized)})}+ {includeAppActions && (+ <>+ <kit.Separator />+ <ShellMenuItems kit={kit} primaryOnly />+ </>+ )}</>)}@@ -784,7 +792,7 @@ export function TreeGroup({wrap={!isEmpty? body => (- <ZoneMenu {...zoneMenu}>+ <ZoneMenu {...zoneMenu} includeAppActions><divaria-label={t.zones.zoneMenuLabel(String(tabLabel(activeId)))}data-zone-body={node.id}