Skip to content

The agent that grows with you

fix(desktop): preserve star map shell menu

Daniel Peng071b7113a623
diff --git a/apps/desktop/src/app/context-menu/app-context-menu.tsx b/apps/desktop/src/app/context-menu/app-context-menu.tsx
index b4bac2f2b9b..09780fd5db4 100644
--- a/apps/desktop/src/app/context-menu/app-context-menu.tsx
+++ b/apps/desktop/src/app/context-menu/app-context-menu.tsx
@@ -4,6 +4,7 @@ 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 { Codicon } from '@/components/ui/codicon'
import { HERMES_CONTEXT_MENU_TRIGGER_ATTR } from '@/components/ui/context-menu'
@@ -41,8 +42,8 @@ import {
import { isWebUrl, resolveDomTarget } from './target'
/** Marks a surface that owns PLAIN right-clicks itself (the user-message
- * reaction bubble and the Star Map canvas). Owned targets inside it — links,
- * images, editables, selections — still get the app menu. */
+ * reaction bubble). Owned targets inside it — links, images, editables,
+ * selections — still get the app menu. */
export const CONTEXT_MENU_SKIP_ATTR = 'data-context-menu-skip'
const LOOPBACK_HOST_RE = /^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[?::1\]?)$/i
@@ -604,8 +605,8 @@ function shellSections({ navigate, t }: ShellVerbs): ReactNode[][] {
*
* Every right-click in the app resolves here first. Radix-owned surfaces
* (session rows and other `context-menu-trigger` wrappers) keep their own
- * menus; the reaction bubble keeps plain right-clicks; terminals answer
- * through their registered xterm handles; everything else gets a menu
+ * menus; the reaction bubble keeps plain right-clicks; terminals and the
+ * Star Map answer through registered handles; everything else gets a menu
* assembled from what the click landed on — link, image, editable,
* selection — with the window verbs as the empty-target fallback. Replaced
* both the native Electron menu and the shell fallback wrapper, so labels
@@ -633,6 +634,15 @@ export function AppContextMenu() {
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)) {
+ event.preventDefault()
+ event.stopPropagation()
+
+ return
+ }
+
// A terminal's canvas has no DOM to resolve; its registered handle
// carries the xterm selection and paste path instead.
const terminal = terminalMenuHandleFor(element)
@@ -647,8 +657,8 @@ export function AppContextMenu() {
const target = resolveDomTarget(element)
const owned = Boolean(target.linkUrl || target.onImage || target.editable || target.selectionText)
- // Skip-marked surfaces own bare right-clicks; owned DOM targets inside
- // them still open the corresponding app menu.
+ // The reaction bubble owns bare right-clicks; a link inside it still
+ // opens the link menu.
if (!owned && element?.closest(`[${CONTEXT_MENU_SKIP_ATTR}]`)) {
return
}
diff --git a/apps/desktop/src/app/starmap/context-menu-handle.ts b/apps/desktop/src/app/starmap/context-menu-handle.ts
new file mode 100644
index 00000000000..a68b4cfc257
--- /dev/null
+++ b/apps/desktop/src/app/starmap/context-menu-handle.ts
@@ -0,0 +1,36 @@
+/**
+ * Registered context-menu ownership for the Star Map canvas.
+ *
+ * The app-wide menu listens on window during capture, before React's canvas
+ * handler. It asks this handle whether the click hit a node: hits belong to
+ * the Star Map, while misses keep flowing to the shell fallback.
+ */
+
+export interface StarMapContextMenuHandle {
+ openNodeMenuAt: (clientX: number, clientY: number) => boolean
+}
+
+const handles = new WeakMap<HTMLCanvasElement, StarMapContextMenuHandle>()
+
+/** Register the handle for a Star Map canvas. Returns an idempotent remove. */
+export function registerStarMapContextMenu(
+ canvas: HTMLCanvasElement,
+ handle: StarMapContextMenuHandle
+): () => void {
+ handles.set(canvas, handle)
+
+ return () => {
+ if (handles.get(canvas) === handle) {
+ handles.delete(canvas)
+ }
+ }
+}
+
+/** Open the node menu when element is a registered canvas and the point hits a node. */
+export function openStarMapNodeMenuFor(element: Element | null, clientX: number, clientY: number): boolean {
+ if (!(element instanceof HTMLCanvasElement)) {
+ return false
+ }
+
+ return handles.get(element)?.openNodeMenuAt(clientX, clientY) ?? false
+}
diff --git a/apps/desktop/src/app/starmap/star-map-context-menu.test.tsx b/apps/desktop/src/app/starmap/star-map-context-menu.test.tsx
index daa70d57e66..b73871a160f 100644
--- a/apps/desktop/src/app/starmap/star-map-context-menu.test.tsx
+++ b/apps/desktop/src/app/starmap/star-map-context-menu.test.tsx
@@ -95,4 +95,26 @@ describe('StarMap context menu ownership', () => {
expect(screen.getByText('Archive skill')).toBeTruthy()
expect($contextMenu.get()).toBeNull()
})
+
+ it('keeps the shell fallback on empty starfield', async () => {
+ vi.stubGlobal('ResizeObserver', TestResizeObserver)
+ vi.spyOn(window, 'requestAnimationFrame').mockReturnValue(1)
+ vi.spyOn(window, 'cancelAnimationFrame').mockImplementation(() => undefined)
+ vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue(null)
+
+ const { container } = render(
+ <MemoryRouter>
+ <AppContextMenu />
+ <StarMap graph={graph} />
+ </MemoryRouter>
+ )
+
+ const canvas = container.querySelector('canvas')!
+
+ await waitFor(() => expect(canvas.style.width).toBe('400px'))
+ fireEvent.contextMenu(canvas, { clientX: 20, clientY: 20 })
+
+ expect(await screen.findByText('Settings')).toBeTruthy()
+ expect(screen.queryByText('Edit skill…')).toBeNull()
+ })
})
diff --git a/apps/desktop/src/app/starmap/star-map.tsx b/apps/desktop/src/app/starmap/star-map.tsx
index 4acbf62e440..c8eb798fc3c 100644
--- a/apps/desktop/src/app/starmap/star-map.tsx
+++ b/apps/desktop/src/app/starmap/star-map.tsx
@@ -9,6 +9,7 @@ import type { StarmapGraph } from '@/types/hermes'
import { computePalette, memoryInkFor, resolveRgb, rgba } from './color'
import { RING_OUTER, TILT, ZOOM_MAX, ZOOM_MIN } from './constants'
+import { registerStarMapContextMenu } from './context-menu-handle'
import { clamp, distToSegmentSq, fitScale, fitViewport, nodeRadius } from './geometry'
import { NodeContextMenu, type NodeMenuTarget } from './node-context-menu'
import { shouldIgnorePlaybackHotkey } from './playback-hotkey'
@@ -692,7 +693,7 @@ export function StarMap({
}, [invalidate, size])
// ── Pointer interactions (invert the tilted projection for hit-testing) ─────
- const pickNode = (cssX: number, cssY: number): null | SimNode => {
+ const pickNode = useCallback((cssX: number, cssY: number): null | SimNode => {
const vp = viewportRef.current
// Hit radius mirrors the billboarded draw: rested fit scale, screen space.
const nodeK = fitScale(sizeRef.current.w, sizeRef.current.h, ringsRef.current)
@@ -712,7 +713,7 @@ export function StarMap({
}
return best
- }
+ }, [])
// Nearest link within ~5px of the cursor (screen space), or null.
const pickLink = (cssX: number, cssY: number): null | string => {
@@ -762,6 +763,37 @@ export function StarMap({
return { x: e.clientX - (rect?.left ?? 0), y: e.clientY - (rect?.top ?? 0) }
}
+ const openNodeMenuAt = useCallback(
+ (clientX: number, clientY: number): boolean => {
+ const rect = canvasRef.current?.getBoundingClientRect()
+ const node = pickNode(clientX - (rect?.left ?? 0), clientY - (rect?.top ?? 0))
+
+ if (!node) {
+ setMenuTarget(null)
+
+ return false
+ }
+
+ setSelectedId(node.id)
+ setMenuTarget({
+ id: node.id,
+ kind: node.kind === 'memory' ? 'memory' : 'skill',
+ label: node.label,
+ x: clientX,
+ y: clientY
+ })
+
+ return true
+ },
+ [pickNode]
+ )
+
+ useEffect(() => {
+ const canvas = canvasRef.current
+
+ return canvas ? registerStarMapContextMenu(canvas, { openNodeMenuAt }) : undefined
+ }, [openNodeMenuAt])
+
const resetView = () => {
setPlaying(false)
viewportRef.current = fitViewport(
@@ -872,22 +904,9 @@ export function StarMap({
}
const onContextMenu = (e: React.MouseEvent<HTMLCanvasElement>) => {
- e.preventDefault()
- const { x, y } = localXY(e)
- const node = pickNode(x, y)
-
- if (!node) {
- return setMenuTarget(null)
+ if (openNodeMenuAt(e.clientX, e.clientY)) {
+ e.preventDefault()
}
-
- setSelectedId(node.id)
- setMenuTarget({
- id: node.id,
- kind: node.kind === 'memory' ? 'memory' : 'skill',
- label: node.label,
- x: e.clientX,
- y: e.clientY
- })
}
const onWheel = (e: React.WheelEvent<HTMLCanvasElement>) => {
@@ -919,7 +938,6 @@ export function StarMap({
<div className="relative min-h-0 flex-1 overflow-hidden" ref={wrapRef}>
<canvas
className="block touch-none select-none text-foreground"
- data-context-menu-skip=""
onContextMenu={onContextMenu}
onDoubleClick={resetView}
onMouseDown={onMouseDown}