Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(canvas): group the node menu — Transfer ▸ and Restart ▸ submenus

review7874fb3c8f06
diff --git a/CLAUDE.md b/CLAUDE.md
index 1943badc1..422c580de 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -3592,7 +3592,13 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mea
right-click; nothing running is interrupted), restart-agent
(single agent node — the in-place CLI restart above; absent for a CLI we cannot quit + resume,
disabled with a hint while the session is busy or has no id yet), delete. Actions live
- in `Canvas.tsx`, operate on `targetIds`. The non-destructive rows are user-hideable from
+ in `Canvas.tsx`, operate on `targetIds`. **Conversation actions are grouped** so an agent node's
+ menu fits on screen: **Transfer conversation ▸** holds one row per target (a model-capable target
+ nests its gateway models one level further), and **Restart ▸** holds every quit-and-resume
+ variant — restart, restart + fresh shell, restart on subscription, then Reopen as / Switch model /
+ Switch account. `ContextMenu` renders submenus to any depth (`MenuRows` is recursive); a flyout
+ that hosts a submenu drops its scroll (`.ctx-submenu--host` — `overflow: auto` would clip the
+ nested flyout) and `useSubmenuFlip` lifts a flyout that would run off the bottom. The non-destructive rows are user-hideable from
**Settings → Appearance** ("Node menu items" / "Terminal header buttons"), stored as HIDDEN
lists in `settings.hiddenNodeMenuItems` / `settings.hiddenHeaderButtons` (empty = everything
shows). `lib/ui-visibility.ts` owns the two inventories and `isHidden`, which only answers for
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index e1257ad80..42ce9019c 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -8244,28 +8244,6 @@ export function Canvas() {
}
] as MenuItem[])
: []),
- ...(ids.length === 1 && (() => {
- const a = agentIdOf(ids[0])
- return !!a && canBranch(a)
- })()
- ? ([
- {
- label: 'Branch conversation',
- icon: <IconBranch />,
- onClick: () => void branchClaude(ids[0], { at })
- }
- ] as MenuItem[])
- : []),
- ...(ids.length === 1
- ? transferConversationItems(ids[0], at, {
- sourceAgentId: agentIdOf(ids[0]),
- sessionId: useAgentStatus.getState().byId[ids[0]]?.sessionId,
- disabledAgents: useSettings.getState().settings.disabledAgents,
- customAgents: useSettings.getState().settings.customAgents,
- gatewayModels,
- relaySession: session.source === 'relay'
- }, transferConversation)
- : []),
...(isHidden('collapse', hidden)
? []
: ([
@@ -8298,6 +8276,32 @@ export function Canvas() {
])
] as MenuItem[])
: []),
+ // Conversation actions — Branch, Transfer ▸ (targets, then models), Restart ▸, Pause — sit
+ // together below the view actions, each ONE row: the per-target Transfer list and the six-odd
+ // restart variants used to be spliced in flat, which made an agent node's menu run off screen.
+ { type: 'separator' },
+ ...(ids.length === 1 && (() => {
+ const a = agentIdOf(ids[0])
+ return !!a && canBranch(a)
+ })()
+ ? ([
+ {
+ label: 'Branch conversation',
+ icon: <IconBranch />,
+ onClick: () => void branchClaude(ids[0], { at })
+ }
+ ] as MenuItem[])
+ : []),
+ ...(ids.length === 1
+ ? transferConversationItems(ids[0], at, {
+ sourceAgentId: agentIdOf(ids[0]),
+ sessionId: useAgentStatus.getState().byId[ids[0]]?.sessionId,
+ disabledAgents: useSettings.getState().settings.disabledAgents,
+ customAgents: useSettings.getState().settings.customAgents,
+ gatewayModels,
+ relaySession: session.source === 'relay'
+ }, transferConversation)
+ : []),
// Restart the agent CLI itself (single selection): quit it and relaunch with `--resume`, so a
// newly released model appears in its model list with the conversation intact. Unlike "Reload
// terminal" above (which re-attaches the pane and leaves the CLI running) this one types into
@@ -8353,7 +8357,7 @@ export function Canvas() {
? 'This session is busy — try again once its turn (or permission prompt) is done.'
: 'Nothing to resume yet — this session has not reported an id.'
: undefined
- return [
+ const restartRows: MenuItem[] = [
{
label: 'Restart agent',
icon: <IconPower />,
@@ -8420,6 +8424,8 @@ export function Canvas() {
}
]
: []),
+ // Below the plain restarts: the variants that restart INTO something else.
+ { type: 'separator' },
...(variants.length
? ([
{
@@ -8578,6 +8584,16 @@ export function Canvas() {
] as MenuItem[]
})()
: []),
+ ]
+ return [
+ // Every quit-and-resume action — plain restart, fresh shell, subscription, reopen as
+ // another agent, switch model / account — behind ONE row.
+ {
+ type: 'submenu',
+ label: 'Restart',
+ icon: <IconPower />,
+ children: tidySeparators(restartRows)
+ },
// Pause session: quit the CLI (and, for the deeper choice, also end the tmux
// session) so it does NOT auto-resume on the next reveal or reopen — only an
// explicit Resume brings it back. Same eligibility as Restart above (`why`): a node
@@ -12867,8 +12883,8 @@ export function Canvas() {
]
// For the ACTIVE project, reuse the SAME single-node menu the canvas right-click builds —
// full parity (Color, Group, Duplicate, Branch, Collapse, Markdown view, Refresh terminal,
- // Restart agent, Restart agent and shell, Reopen session as, Switch model, Transfer with its
- // nested model submenus) so the two surfaces can't drift. `selectionItems` reads the live
+ // Transfer ▸ with its nested model submenus, Restart ▸ with every restart variant) so the two
+ // surfaces can't drift. `selectionItems` reads the live
// node from `nodesRef.current` (active-project only), which is exactly why this is gated.
// `at` is undefined: the row has no flow position, so spawned nodes (Duplicate/Branch/
// Transfer) place beside the source — the same as the row's existing Transfer behavior.
diff --git a/src/renderer/components/ContextMenu.submenu-depth.test.tsx b/src/renderer/components/ContextMenu.submenu-depth.test.tsx
index 0517f8dac..03380be11 100644
--- a/src/renderer/components/ContextMenu.submenu-depth.test.tsx
+++ b/src/renderer/components/ContextMenu.submenu-depth.test.tsx
@@ -1,17 +1,13 @@
// @vitest-environment jsdom
//
-// MEASURES the submenu depth cap, rather than asserting it from the source.
+// MEASURES submenu nesting, rather than asserting it from the source.
//
-// `ContextMenu` renders a submenu's children with
-// `if (child.type === 'colors' || child.type === 'submenu') return null` — so a THIRD level is
-// dropped with no error, no warning and nothing on screen. That is not a style rule anybody can
-// choose to ignore: it is why `lib/addMenuSpec`'s `isPinnedAgentEntry` refuses to nest an agent
-// row that is already a submenu. Claude's and Codex's account pickers ARE such rows, so nesting
-// one would silently delete the account picker for exactly the users who have managed accounts —
-// the "looks like it worked" failure, visible only to the people it breaks.
-//
-// If someone teaches ContextMenu to render a third level, this test goes red and the pin in
-// addMenuSpec can be reconsidered deliberately. Until then it is the fact the grouping rests on.
+// `ContextMenu` used to render a submenu's children with
+// `if (child.type === 'colors' || child.type === 'submenu') return null`, so a THIRD level was
+// dropped with no error, no warning and nothing on screen. The node menu now needs three levels
+// ("Transfer conversation ▸ Codex ▸ <model>", "Restart ▸ Switch model ▸ <model>"), so rows render
+// recursively — and this test is what proves a nested row is actually REACHABLE, including the
+// scroll rule that would otherwise clip it (`.ctx-submenu--host`).
import { act } from 'react'
import { createRoot } from 'react-dom/client'
import { afterEach, describe, expect, it } from 'vitest'
@@ -35,6 +31,18 @@ afterEach(() => {
document.body.innerHTML = ''
})
+/** Hovers the submenu row whose OWN label is `label`, so its flyout opens. */
+function hover(label: string): void {
+ const row = [...document.querySelectorAll('.ctx-item--submenu')].find(
+ (el) => el.firstChild?.nextSibling?.textContent === label
+ )
+ if (!row) throw new Error(`no submenu row labelled ${label}`)
+ // React synthesises onMouseEnter from the delegated mouseover event.
+ act(() => {
+ row.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }))
+ })
+}
+
/** Renders into a body portal; hovers the row with `label` so its flyout opens. */
function renderMenu(items: MenuItem[], hoverLabel?: string): void {
const host = document.createElement('div')
@@ -42,15 +50,7 @@ function renderMenu(items: MenuItem[], hoverLabel?: string): void {
act(() => {
createRoot(host).render(<ContextMenu x={0} y={0} items={items} onClose={noop} />)
})
- if (!hoverLabel) return
- const row = [...document.querySelectorAll('.ctx-item--submenu')].find((el) =>
- el.textContent?.includes(hoverLabel)
- )
- if (!row) throw new Error(`no submenu row labelled ${hoverLabel}`)
- // React synthesises onMouseEnter from the delegated mouseover event.
- act(() => {
- row.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }))
- })
+ if (hoverLabel) hover(hoverLabel)
}
describe('ContextMenu submenu depth', () => {
@@ -77,29 +77,46 @@ describe('ContextMenu submenu depth', () => {
expect(leaf?.getAttribute('title')).toBe('Not supported in SSH')
})
- it('DROPS a third-level submenu silently — nothing is rendered for it', () => {
+ it('renders a third-level submenu and its leaves', () => {
+ let picked = ''
renderMenu(
[
{
type: 'submenu',
- label: 'New agent',
+ label: 'Transfer conversation',
children: [
- { label: 'New Gemini', onClick: noop },
+ { label: 'Gemini', onClick: noop },
{
type: 'submenu',
- label: 'New Codex',
- children: [{ label: '[email protected]', onClick: noop }]
+ label: 'Codex',
+ children: [{ label: 'gpt-5', onClick: () => (picked = 'gpt-5') }]
}
]
}
],
- 'New agent'
+ 'Transfer conversation'
)
const flyout = document.querySelector('.ctx-submenu')
- expect(flyout?.textContent).toContain('New Gemini')
- // The measurement this whole design rests on: the nested submenu row is GONE, and so is the
- // account it held. No error, no placeholder — which is why the grouping must never create one.
- expect(flyout?.textContent).not.toContain('New Codex')
- expect(flyout?.textContent).not.toContain('[email protected]')
+ expect(flyout?.textContent).toContain('Gemini')
+ expect(flyout?.textContent).toContain('Codex')
+ // A flyout that hosts a submenu must not scroll — overflow would clip the nested flyout.
+ expect(flyout?.classList.contains('ctx-submenu--host')).toBe(true)
+ hover('Codex')
+ const leaf = [...document.querySelectorAll('.ctx-submenu .ctx-submenu button')].find(
+ (b) => b.textContent?.includes('gpt-5')
+ ) as HTMLButtonElement | undefined
+ expect(leaf).toBeDefined()
+ act(() => leaf!.click())
+ expect(picked).toBe('gpt-5')
+ })
+
+ it('keeps a leaf-only flyout scrollable (no host class)', () => {
+ renderMenu(
+ [{ type: 'submenu', label: 'Models', children: [{ label: 'a', onClick: noop }] }],
+ 'Models'
+ )
+ expect(document.querySelector('.ctx-submenu')?.classList.contains('ctx-submenu--host')).toBe(
+ false
+ )
})
})
diff --git a/src/renderer/components/ContextMenu.tsx b/src/renderer/components/ContextMenu.tsx
index a02b08e3d..ce0998310 100644
--- a/src/renderer/components/ContextMenu.tsx
+++ b/src/renderer/components/ContextMenu.tsx
@@ -2,7 +2,7 @@ import { useState, type ReactNode } from 'react'
import { createPortal } from 'react-dom'
import { NodeColorSwatches } from './NodeColorSwatches'
import { useMenuFlip } from '../ui/useMenuFlip'
-import { useSubmenuFlip } from '../ui/useSubmenuFlip'
+import { SUBMENU_TOP_PX, useSubmenuFlip } from '../ui/useSubmenuFlip'
export type MenuItem =
| {
@@ -58,8 +58,6 @@ export function ContextMenu({ x, y, items, onClose, zIndex, scroll }: ContextMen
zIndex != null
? { top: flip.top, left: flip.left, zIndex: zIndex + 1 }
: { top: flip.top, left: flip.left }
- // Index of the row whose submenu flyout is currently open (hover-driven).
- const [openSub, setOpenSub] = useState<number | null>(null)
return createPortal(
<>
<div
@@ -74,78 +72,85 @@ export function ContextMenu({ x, y, items, onClose, zIndex, scroll }: ContextMen
style={menuStyle}
onClick={(e) => e.stopPropagation()}
>
- {items.map((item, i) => {
- if (item.type === 'separator') return <div key={i} className="ctx-sep" />
- if (item.type === 'label') return <div key={i} className="ctx-label">{item.label}</div>
- if (item.type === 'colors') {
- return (
- <NodeColorSwatches
- key={i}
- className="ctx-colors"
- onPick={(c) => {
- item.onPick(c)
- onClose()
- }}
- />
- )
- }
- if (item.type === 'submenu') {
- return (
- <div
- key={i}
- className="ctx-item ctx-item--submenu"
- onMouseEnter={() => setOpenSub(i)}
- onMouseLeave={() => setOpenSub((cur) => (cur === i ? null : cur))}
- >
- <span className="ctx-icon">{item.icon}</span>
- {item.label}
- {openSub === i && (
- <SubmenuFlyout>
- {item.children.map((child, j) => {
- if (child.type === 'separator') return <div key={j} className="ctx-sep" />
- if (child.type === 'label')
- return <div key={j} className="ctx-label">{child.label}</div>
- if (child.type === 'colors' || child.type === 'submenu') return null
- return (
- <button
- key={j}
- className={`ctx-item${child.danger ? ' danger' : ''}`}
- disabled={child.disabled}
- title={child.hint}
- onClick={() => {
- child.onClick()
- onClose()
- }}
- >
- <span className="ctx-icon">{child.icon}</span>
- {child.label}
- </button>
- )
- })}
- </SubmenuFlyout>
- )}
- </div>
- )
- }
+ <MenuRows items={items} onClose={onClose} />
+ </div>
+ </>,
+ document.body
+ )
+}
+
+/**
+ * The rows of one menu level — the root menu or any flyout. Recursive: a submenu row's flyout
+ * renders its children through this same component, so nesting has no depth cap (the node menu's
+ * "Transfer conversation ▸ Codex ▸ <model>" is three levels deep). Each level owns its own
+ * open-flyout index, so hovering inside a flyout never closes its parent's.
+ *
+ * `colors` renders only at the root: the swatch strip is a menu-wide row, not a flyout entry.
+ */
+function MenuRows({
+ items,
+ onClose,
+ nested = false
+}: {
+ items: MenuItem[]
+ onClose: () => void
+ nested?: boolean
+}): JSX.Element {
+ // Index of the row whose submenu flyout is currently open (hover-driven).
+ const [openSub, setOpenSub] = useState<number | null>(null)
+ return (
+ <>
+ {items.map((item, i) => {
+ if (item.type === 'separator') return <div key={i} className="ctx-sep" />
+ if (item.type === 'label') return <div key={i} className="ctx-label">{item.label}</div>
+ if (item.type === 'colors') {
+ if (nested) return null
return (
- <button
+ <NodeColorSwatches
key={i}
- className={`ctx-item${item.danger ? ' danger' : ''}`}
- disabled={item.disabled}
- title={item.hint}
- onClick={() => {
- item.onClick()
+ className="ctx-colors"
+ onPick={(c) => {
+ item.onPick(c)
onClose()
}}
+ />
+ )
+ }
+ if (item.type === 'submenu') {
+ return (
+ <div
+ key={i}
+ className="ctx-item ctx-item--submenu"
+ onMouseEnter={() => setOpenSub(i)}
+ onMouseLeave={() => setOpenSub((cur) => (cur === i ? null : cur))}
>
<span className="ctx-icon">{item.icon}</span>
{item.label}
- </button>
+ {openSub === i && (
+ <SubmenuFlyout hostsSubmenus={item.children.some((c) => c.type === 'submenu')}>
+ <MenuRows items={item.children} onClose={onClose} nested />
+ </SubmenuFlyout>
+ )}
+ </div>
)
- })}
- </div>
- </>,
- document.body
+ }
+ return (
+ <button
+ key={i}
+ className={`ctx-item${item.danger ? ' danger' : ''}`}
+ disabled={item.disabled}
+ title={item.hint}
+ onClick={() => {
+ item.onClick()
+ onClose()
+ }}
+ >
+ <span className="ctx-icon">{item.icon}</span>
+ {item.label}
+ </button>
+ )
+ })}
+ </>
)
}
@@ -158,13 +163,24 @@ export function ContextMenu({ x, y, items, onClose, zIndex, scroll }: ContextMen
* last decision. `data-side` is what the stylesheet anchors on; the default stays `right`, so a
* flyout with room renders exactly as it always did.
*/
-function SubmenuFlyout({ children }: { children: ReactNode }): JSX.Element {
- const { ref, side } = useSubmenuFlip()
+function SubmenuFlyout({
+ children,
+ hostsSubmenus
+}: {
+ children: ReactNode
+ /** The flyout holds submenu rows of its own. It must not scroll then: `overflow-y: auto` clips
+ * every absolutely-positioned descendant, i.e. the nested flyout would open invisible. Such
+ * flyouts are short action lists; long data lists (models, accounts) are leaves and keep
+ * scrolling. */
+ hostsSubmenus: boolean
+}): JSX.Element {
+ const { ref, side, lift } = useSubmenuFlip()
return (
<div
ref={ref}
- className="ctx-menu ctx-submenu"
+ className={`ctx-menu ctx-submenu${hostsSubmenus ? ' ctx-submenu--host' : ''}`}
data-side={side}
+ style={lift ? { top: SUBMENU_TOP_PX - lift } : undefined}
onClick={(e) => e.stopPropagation()}
>
{children}
diff --git a/src/renderer/lib/addMenuSpec.test.tsx b/src/renderer/lib/addMenuSpec.test.tsx
index fa6611e13..3ef03df7d 100644
--- a/src/renderer/lib/addMenuSpec.test.tsx
+++ b/src/renderer/lib/addMenuSpec.test.tsx
@@ -324,8 +324,8 @@ describe('buildGroupedAddMenu', () => {
for (const a of agents) if ('label' in a.item) expect(reachable).toContain(a.item.label)
})
- // The structural invariant the whole shape rests on (MEASURED in
- // components/ContextMenu.submenu-depth.test.tsx: a third level renders as NOTHING).
+ // The shape keeps account pickers one hover away: ContextMenu renders any depth now, so this is a
+ // design choice (see the grouping section of addMenuSpec), not a renderer limit.
it('never emits a third level', () => {
const items = buildGroupedAddMenu(CONTENT_ADD_ITEMS, handlers(), ctx, agents)
for (const item of items) {
diff --git a/src/renderer/lib/addMenuSpec.tsx b/src/renderer/lib/addMenuSpec.tsx
index fc96e4f7b..da748e387 100644
--- a/src/renderer/lib/addMenuSpec.tsx
+++ b/src/renderer/lib/addMenuSpec.tsx
@@ -20,7 +20,7 @@
*
* Three render adapters map the same {@link AddItem} list to the menu worlds:
* - {@link buildGroupedAddMenu} → the GROUPED tree the two `ContextMenu` surfaces show (see the
- * grouping section at the bottom of this file for why, and for the submenu depth cap).
+ * grouping section at the bottom of this file for why).
* - {@link contentAddItemsToMenuItems} → the {@link MenuItem} type the `ContextMenu` component
* consumes (pane menu, project-header "+").
* - {@link contentAddItemsToDockRows} → the Dock's custom `<button>` JSX.
@@ -338,11 +338,11 @@ export function contentAddItemsToDockRows(
// EXHAUSTIVE; it has to be FAST. Grouping trades one hover for a target you can hit without
// reading, and leaves the exhaustive paths exactly where they already were.
//
-// **The depth cap is structural, not stylistic.** `ContextMenu` renders a submenu's children with
-// `if (child.type === 'colors' || child.type === 'submenu') return null` — a third level is
-// silently dropped, with no error and nothing on screen. That single line decides the whole shape
-// below: an agent row that is ALREADY a submenu (Claude's and Codex's account pickers) can never
-// be nested, or the picker disappears for exactly the users who have managed accounts.
+// **Two levels here is a choice, not a cap.** `ContextMenu` used to drop a third level silently
+// (`if (child.type === 'submenu') return null`), and this shape was built around that. It now
+// renders any depth (the node menu's "Transfer conversation ▸ <agent> ▸ <model>" needs three), but
+// the rule below is kept: an agent row that is ALREADY a submenu (Claude's and Codex's account
+// pickers) stays at the first level, so picking an account never costs two hovers.
/** Which section of the grouped menu a content kind belongs to. `top` = stays a first-level row. */
export type AddGroupId = 'top' | 'view' | 'files' | 'orchestrate'
@@ -391,13 +391,11 @@ export interface AgentAddEntry {
}
/**
- * Whether an agent row must stay at the FIRST level. Two independent reasons, and both are
- * refusals rather than preferences:
+ * Whether an agent row must stay at the FIRST level. Two independent reasons:
*
- * 1. **It is already a submenu.** Nesting it makes `ContextMenu` render it as nothing (see the
- * depth cap above) — the account picker would vanish silently, for exactly the users who have
- * accounts. This half is derived from the row itself, so an agent that grows a picker later is
- * protected on the day it does.
+ * 1. **It is already a submenu.** Nesting it would put the account picker two hovers deep, for
+ * exactly the users who have accounts. This half is derived from the row itself, so an agent
+ * that grows a picker later is kept at the top on the day it does.
* 2. **It CAN own a managed account** (`ACCOUNT_CAPABLE_AGENT_IDS`). Rule 1 alone would move a
* row in and out of the submenu as the user adds or removes accounts — a menu that rearranges
* itself is a menu you cannot learn. Pinning the account-capable agents keeps the shape stable
@@ -446,7 +444,7 @@ const GROUP_ICON: Record<Exclude<AddGroupId, 'top'>, ReactNode> = {
* the Dock use — so a row's label, icon, handler and **disabled reason** are written exactly once.
* That is what keeps "New worktree…" greyed with `WORKTREE_SSH_HINT` inside its submenu instead of
* quietly losing the explanation on the way in: a `hint` on a leaf renders in a flyout the same as
- * at the top level (the depth cap drops nested SUBMENUS, never a leaf's disabled state).
+ * at the top level.
*
* Order is the canonical one: top rows, then agents, then view / files / orchestrate. A group
* whose rows are all filtered out emits no submenu at all.
diff --git a/src/renderer/lib/transferItems.test.tsx b/src/renderer/lib/transferItems.test.tsx
index 33e354748..351bf2ebb 100644
--- a/src/renderer/lib/transferItems.test.tsx
+++ b/src/renderer/lib/transferItems.test.tsx
@@ -3,6 +3,7 @@ import { transferTargets, transferConversationItems, type TransferConversationAr
import type { AgentId } from '@shared/agents/config'
import type { CustomAgent } from '@shared/types'
import type { GatewayModel } from '@shared/agents/model-gateway'
+import type { MenuItem } from '../components/ContextMenu'
const customs: CustomAgent[] = [
{ id: 'custom:a', label: 'Agent A', launchCmd: 'a', promptInjectionMode: 'argv' },
@@ -63,13 +64,21 @@ describe('transferTargets', () => {
})
})
+/** The targets inside the single "Transfer conversation ▸" submenu the builder returns. */
+function rowsOf(items: MenuItem[]): MenuItem[] {
+ expect(items).toHaveLength(1)
+ const sub = items[0]
+ if (sub.type !== 'submenu') throw new Error('expected the Transfer conversation submenu')
+ expect(sub.label).toBe('Transfer conversation')
+ return sub.children
+}
+
describe('transferConversationItems', () => {
const handler = () => {}
- it('returns the label + one item per target for a transfer-capable agent with a session', () => {
+ it('returns ONE submenu holding a row per target for a transfer-capable agent with a session', () => {
const items = transferConversationItems('node-1', undefined, args({}), handler)
- expect(items.length).toBeGreaterThan(1)
- expect(items[0]).toMatchObject({ type: 'label', label: 'Transfer conversation to' })
+ expect(rowsOf(items).length).toBeGreaterThan(1)
})
it('returns [] when the agent is not transfer-capable', () => {
@@ -92,10 +101,8 @@ describe('transferConversationItems', () => {
args({ sourceAgentId: 'grok' as AgentId, customAgents: [] }),
handler
)
- expect(items.length).toBeGreaterThan(1)
- expect(items[0]).toEqual({ type: 'label', label: 'Transfer conversation to' })
// grok is never offered as a destination for itself; every other builtin still is.
- const labels = items.slice(1).map((i) => ('label' in i ? i.label : ''))
+ const labels = rowsOf(items).map((i) => ('label' in i ? i.label : ''))
expect(labels).not.toContain('Grok')
expect(labels).toContain('Claude Code')
})
@@ -129,7 +136,7 @@ describe('transferConversationItems', () => {
args({ sourceAgentId: 'claude' as AgentId, customAgents: [], gatewayModels: models }),
handler
)
- const codex = items.find(
+ const codex = rowsOf(items).find(
(i): i is Extract<typeof i, { type: 'submenu' }> => i.type === 'submenu' && i.label === 'Codex'
)
expect(codex).toBeDefined()
@@ -147,7 +154,7 @@ describe('transferConversationItems', () => {
args({ sourceAgentId: 'codex' as AgentId, customAgents: [claudeCustom], gatewayModels: models }),
handler
)
- const proxy = items.find(
+ const proxy = rowsOf(items).find(
(i): i is Extract<typeof i, { type: 'submenu' }> => i.type === 'submenu' && i.label === 'Claude Proxy'
)
expect(proxy).toBeDefined()
@@ -161,7 +168,7 @@ describe('transferConversationItems', () => {
args({ sourceAgentId: 'claude' as AgentId, customAgents: [], gatewayModels: models }),
handler
)
- const gemini = items.find((i) => 'label' in i && i.label === 'Gemini')
+ const gemini = rowsOf(items).find((i) => 'label' in i && i.label === 'Gemini')
expect(gemini).toBeDefined()
expect(gemini).not.toMatchObject({ type: 'submenu' }) // flat row, not a submenu
})
@@ -174,7 +181,7 @@ describe('transferConversationItems', () => {
args({ sourceAgentId: 'claude' as AgentId, customAgents: [], gatewayModels: [] }),
handler
)
- const codex = items.find((i) => 'label' in i && i.label === 'Codex')
+ const codex = rowsOf(items).find((i) => 'label' in i && i.label === 'Codex')
expect(codex).toBeDefined()
expect(codex).not.toMatchObject({ type: 'submenu' })
})
@@ -186,7 +193,7 @@ describe('transferConversationItems', () => {
args({ sourceAgentId: 'claude' as AgentId, customAgents: [], gatewayModels: models, relaySession: true }),
handler
)
- const codex = items.find((i) => 'label' in i && i.label === 'Codex')
+ const codex = rowsOf(items).find((i) => 'label' in i && i.label === 'Codex')
expect(codex).toBeDefined()
expect(codex).not.toMatchObject({ type: 'submenu' })
})
@@ -201,7 +208,7 @@ describe('transferConversationItems', () => {
args({ sourceAgentId: 'claude' as AgentId, customAgents: [], gatewayModels: models }),
handler as never
)
- const codex = items.find(
+ const codex = rowsOf(items).find(
(i): i is Extract<typeof i, { type: 'submenu' }> => i.type === 'submenu' && i.label === 'Codex'
)!
// "Default model" row → no model
diff --git a/src/renderer/lib/transferItems.tsx b/src/renderer/lib/transferItems.tsx
index ccdcb357a..973f49eca 100644
--- a/src/renderer/lib/transferItems.tsx
+++ b/src/renderer/lib/transferItems.tsx
@@ -23,6 +23,7 @@ import type { GatewayModel } from '@shared/agents/model-gateway'
import type { CustomAgent } from '@shared/types'
import type { MenuItem } from '../components/ContextMenu'
import { AgentIcon } from './agentIcons'
+import { IconMoveTo } from '../components/icons'
/**
* Resolve an agent's base harness from the records passed in, WITHOUT the runtime's injected
@@ -89,8 +90,10 @@ export type TransferConversationHandler = (
) => void
/**
- * Build the "Transfer conversation to" menu block (a label + one entry per target), or `[]` when
- * the node can't be a transfer source (not a transfer-capable agent, or no session id yet).
+ * Build the "Transfer conversation ▸" submenu (one entry per target), or `[]` when the node can't
+ * be a transfer source (not a transfer-capable agent, or no session id yet). It is ONE row in the
+ * node menu — the target list used to be spliced in flat under a label, which alone added a row
+ * per enabled agent to every agent node's right-click menu.
*
* A switch-capable target with discovered models becomes a submenu: a "Default model" row (transfer
* with no `--model`) plus one row per gateway model. A non-capable target, a relay source, or a
@@ -113,43 +116,43 @@ export function transferConversationItems(
if (!sourceAgentId || !sessionId || !canTransferFrom(sourceAgentId)) return []
const targets = transferTargets(sourceAgentId, disabledAgents, customAgents)
if (targets.length === 0) return []
- return [
- { type: 'label', label: 'Transfer conversation to' },
- ...targets.map((tg): MenuItem => {
- // A model submenu only for a switch-capable target with discovered models, and never for a
- // relay source (its gateway is on another machine). Capability is resolved from the passed-in
- // `customAgents` (base-resolved, so a claude-base custom agent qualifies) rather than the
- // runtime's injected resolver, so this stays pure and testable. gemini/grok and baseless
- // customs stay flat — no model grammar. The gateway is shared across harnesses, so the full
- // model list applies to any capable target.
- const base = baseOf(tg.id, customAgents)
- const capable = !!base && (MODEL_SWITCH_CAPABLE as readonly string[]).includes(base)
- const models = capable && !relaySession ? (gatewayModels as GatewayModel[]) : []
- if (models.length === 0) {
- return {
- label: tg.label,
- icon: <AgentIcon agentId={tg.id} />,
- onClick: () => void handler(nodeId, tg.id, at)
- }
- }
+ const rows = targets.map((tg): MenuItem => {
+ // A model submenu only for a switch-capable target with discovered models, and never for a
+ // relay source (its gateway is on another machine). Capability is resolved from the passed-in
+ // `customAgents` (base-resolved, so a claude-base custom agent qualifies) rather than the
+ // runtime's injected resolver, so this stays pure and testable. gemini/grok and baseless
+ // customs stay flat — no model grammar. The gateway is shared across harnesses, so the full
+ // model list applies to any capable target.
+ const base = baseOf(tg.id, customAgents)
+ const capable = !!base && (MODEL_SWITCH_CAPABLE as readonly string[]).includes(base)
+ const models = capable && !relaySession ? (gatewayModels as GatewayModel[]) : []
+ if (models.length === 0) {
return {
- type: 'submenu',
label: tg.label,
icon: <AgentIcon agentId={tg.id} />,
- children: [
- // The agent's own default model — transfer with no `--model` flag.
- {
- label: 'Default model',
- onClick: () => void handler(nodeId, tg.id, at)
- },
- ...models.map(
- (m): MenuItem => ({
- label: m.id,
- onClick: () => void handler(nodeId, tg.id, at, m.id)
- })
- )
- ]
+ onClick: () => void handler(nodeId, tg.id, at)
}
- })
+ }
+ return {
+ type: 'submenu',
+ label: tg.label,
+ icon: <AgentIcon agentId={tg.id} />,
+ children: [
+ // The agent's own default model — transfer with no `--model` flag.
+ {
+ label: 'Default model',
+ onClick: () => void handler(nodeId, tg.id, at)
+ },
+ ...models.map(
+ (m): MenuItem => ({
+ label: m.id,
+ onClick: () => void handler(nodeId, tg.id, at, m.id)
+ })
+ )
+ ]
+ }
+ })
+ return [
+ { type: 'submenu', label: 'Transfer conversation', icon: <IconMoveTo />, children: rows }
]
}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index caec75eb2..bf48a36dc 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -3560,12 +3560,24 @@ body,
left: auto;
right: calc(100% - 4px);
}
+/* A flyout that holds submenu rows of its own must not scroll: `overflow-y: auto` would clip
+ the nested (absolutely positioned) flyout to nothing. Only short action lists host submenus;
+ long data lists (models, accounts) are leaves and keep the scroll cap above. */
+.ctx-submenu--host {
+ overflow: visible;
+ max-height: none;
+}
.ctx-submenu .ctx-item {
/* Keep the label and its default ✓ on one line (labels ellipsize past max-width). */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
+/* …except a submenu row inside a flyout: its own flyout is an absolutely positioned CHILD of the
+ row, and `overflow: hidden` would clip it away entirely. */
+.ctx-submenu .ctx-item--submenu {
+ overflow: visible;
+}
.ctx-sep {
height: 1px;
diff --git a/src/renderer/ui/useSubmenuFlip.test.ts b/src/renderer/ui/useSubmenuFlip.test.ts
index fc2104256..73242b0c0 100644
--- a/src/renderer/ui/useSubmenuFlip.test.ts
+++ b/src/renderer/ui/useSubmenuFlip.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { submenuSide, SUBMENU_OVERLAP_PX } from './useSubmenuFlip'
+import { submenuLift, submenuSide, SUBMENU_OVERLAP_PX } from './useSubmenuFlip'
/** A 200px-wide submenu row, placed by its left edge in a 1000px viewport. */
const row = (left: number): { rowLeft: number; rowRight: number } => ({
@@ -38,3 +38,20 @@ describe('submenuSide', () => {
expect(submenuSide({ ...row(10), width: 240, viewportWidth: W })).toBe('right')
})
})
+
+describe('submenuLift', () => {
+ const H = 700
+ it('does not move a flyout that fits below its row', () => {
+ expect(submenuLift({ rowTop: 100, height: 200, viewportHeight: H })).toBe(0)
+ })
+
+ it('lifts a flyout exactly as far as its bottom overflows the margin', () => {
+ // top = 566 - 6 = 560; bottom 560 + 180 = 740 vs 700 - 6 = 694 → lift 46.
+ expect(submenuLift({ rowTop: 566, height: 180, viewportHeight: H })).toBe(46)
+ })
+
+ it('never lifts a flyout past the top margin', () => {
+ // Taller than the viewport: it stops at the margin and scrolls via its own max-height.
+ expect(submenuLift({ rowTop: 400, height: 2000, viewportHeight: H })).toBe(400 - 6 - 6)
+ })
+})
diff --git a/src/renderer/ui/useSubmenuFlip.ts b/src/renderer/ui/useSubmenuFlip.ts
index 70132fd79..65d017d44 100644
--- a/src/renderer/ui/useSubmenuFlip.ts
+++ b/src/renderer/ui/useSubmenuFlip.ts
@@ -40,8 +40,33 @@ export function submenuSide(input: {
return roomLeft > roomRight ? 'left' : 'right'
}
+/** The flyout's resting offset above its row's top edge (the CSS `top: -6px`). */
+export const SUBMENU_TOP_PX = -6
+
+/**
+ * How far to lift a flyout so its bottom stays inside the viewport. The side flip only fixes the
+ * horizontal axis; a flyout opened from a row near the bottom (typically a nested one — a model
+ * list three levels down) otherwise runs off-screen. Never lifts it above the top margin: a flyout
+ * taller than the viewport is capped by its own `max-height` and scrolls instead. Pure.
+ */
+export function submenuLift(input: {
+ /** The submenu ROW's viewport top. */
+ rowTop: number
+ /** Measured flyout height. */
+ height: number
+ viewportHeight: number
+ margin?: number
+}): number {
+ const margin = input.margin ?? M
+ const top = input.rowTop + SUBMENU_TOP_PX
+ const overflow = top + input.height - (input.viewportHeight - margin)
+ if (overflow <= 0) return 0
+ return Math.max(0, Math.min(overflow, top - margin))
+}
+
/**
- * Measure an open submenu flyout and answer which side it should open towards.
+ * Measure an open submenu flyout and answer which side it should open towards, and how far to
+ * lift it so it stays on screen vertically.
*
* Measured after render but BEFORE paint (`useLayoutEffect`), so a flyout never appears on the
* wrong side first and jumps. Re-measured on size changes for the same reason `useMenuFlip` is: a
@@ -50,9 +75,14 @@ export function submenuSide(input: {
* The rect read is the flyout's OFFSET PARENT — the submenu row — because the flyout's own rect
* already carries the side we are deciding.
*/
-export function useSubmenuFlip(): { ref: RefObject<HTMLDivElement>; side: SubmenuSide } {
+export function useSubmenuFlip(): {
+ ref: RefObject<HTMLDivElement>
+ side: SubmenuSide
+ lift: number
+} {
const ref = useRef<HTMLDivElement>(null)
const [side, setSide] = useState<SubmenuSide>('right')
+ const [lift, setLift] = useState(0)
useLayoutEffect(() => {
const el = ref.current
const row = el?.offsetParent as HTMLElement | null
@@ -66,11 +96,17 @@ export function useSubmenuFlip(): { ref: RefObject<HTMLDivElement>; side: Submen
viewportWidth: window.innerWidth
})
setSide((cur) => (cur === next ? cur : next))
+ const up = submenuLift({
+ rowTop: r.top,
+ height: el.offsetHeight,
+ viewportHeight: window.innerHeight
+ })
+ setLift((cur) => (cur === up ? cur : up))
}
measure()
const ro = new ResizeObserver(measure)
ro.observe(el)
return () => ro.disconnect()
}, [])
- return { ref, side }
+ return { ref, side, lift }
}