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(kanban): card menu takes the node's own rows

Mina Samehdddd3371e164
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index ac156b11d..76b73091f 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -116,7 +116,6 @@ import { tidySeparators } from '../lib/tidySeparators'
import { createNodeWriteRouter, type NodeWrites } from '../lib/nodeWriteRouter'
import {
BOARD_NODE_ACTION_IDS,
- buildAccountSwitchRows,
buildNodeActionItems,
offCanvasNodeActionCtx,
OFF_CANVAS_REFUSAL,
@@ -10354,13 +10353,6 @@ export function Canvas() {
[liveNodeActionCtx]
)
- /** The node's "Switch Claude/Codex account ▸" rows for the kanban card menu — the same builder
- * the canvas node menu uses. */
- const accountSwitchRows = useCallback(
- (nodeId: string): MenuItem[] => buildAccountSwitchRows(nodeId, liveNodeActionCtx()),
- [liveNodeActionCtx]
- )
-
/** The node action context for a node of `projectId`: the live canvas when React Flow holds
* that project, else its stored copy (lib/nodeActionItems `offCanvasNodeActionCtx`). Writes go
* through the project's router either way, so a board write can never land on the wrong canvas. */
@@ -15934,6 +15926,25 @@ export function Canvas() {
[renameSession]
)
+ // A kanban card's "Name with AI": the sidebar's funnel (`aiNameSession`), with the node's cwd
+ // read from wherever the node lives — the live canvas when it holds the project, else the store.
+ const aiNameFromKanban = useCallback(
+ (projectId: string, nodeId: string) => {
+ const live = liveCanvasHolds(nodesProjectIdRef.current, useProjects.getState().activeProjectId, projectId)
+ ? nodesRef.current.find((n) => n.id === nodeId)
+ : undefined
+ const cwd =
+ (live?.data.cwd as string | undefined) ??
+ useProjects.getState().getProject(projectId)?.nodes.find((n) => n.id === nodeId)?.cwd
+ void aiNameSession(projectId, nodeId, cwd)
+ },
+ [aiNameSession]
+ )
+ const aiNameFromActiveKanban = useCallback(
+ (nodeId: string) => aiNameFromKanban(activeProjectId, nodeId),
+ [aiNameFromKanban, activeProjectId]
+ )
+
// Sidebar "Name with AI" for a canvas group: generate a title from its member terminals'
// captured output, then apply it to the group node (renameSession renames any node by id).
const aiNameGroup = useCallback(
@@ -18470,8 +18481,8 @@ export function Canvas() {
onModalNodeChange={setKanbanModalNode}
onBrowserNav={browserNavFromKanban}
onSetIcon={setNodeIcon}
- accountMenuItems={accountSwitchRows}
- liveLinkMenuItems={liveLinkMenuItems}
+ nodeActionItems={activeBoardNodeActionItems}
+ onAiName={aiNameFromActiveKanban}
onAutoMoveFromPulls={autoMoveCardFromPulls}
issueAgentMenu={issueAgentMenu}
issueWorktreeMenu={issueWorktreeMenu}
diff --git a/src/renderer/canvas/live-link-wiring.test.ts b/src/renderer/canvas/live-link-wiring.test.ts
index 91a9e0904..f15f5d88b 100644
--- a/src/renderer/canvas/live-link-wiring.test.ts
+++ b/src/renderer/canvas/live-link-wiring.test.ts
@@ -120,7 +120,12 @@ describe('Canvas live-link wiring', () => {
it('R49: every surface gets the row — non-active sidebar projects, both boards', () => {
const row = src.slice(src.indexOf('const onRowContextMenu = useCallback('))
expect(row.slice(0, row.indexOf('\n // Stream live subagent'))).toContain('...liveLinkMenuItems(id, projectId),')
- expect(src).toContain('liveLinkMenuItems={liveLinkMenuItems}\n onAutoMoveFromPulls')
+ // Both boards take the node rows from the builder, built for the CARD's project.
+ const ctx = src.slice(src.indexOf('const nodeActionCtxFor = useCallback('))
+ expect(ctx.slice(0, ctx.indexOf('\n const boardNodeActionItems'))).toContain(
+ 'const liveLink = (nodeId: string): MenuItem[] => liveLinkMenuItems(nodeId, projectId)'
+ )
+ expect(src).toContain('nodeActionItems={activeBoardNodeActionItems}')
expect(src).toMatch(/<GlobalKanbanView[\s\S]{0,200}liveLinkMenuItems=\{liveLinkMenuItems\}/)
})
diff --git a/src/renderer/components/kanban/CardModal.tsx b/src/renderer/components/kanban/CardModal.tsx
index 06d4ec5ce..59fdeb262 100644
--- a/src/renderer/components/kanban/CardModal.tsx
+++ b/src/renderer/components/kanban/CardModal.tsx
@@ -116,6 +116,9 @@ interface CardModalProps {
mentionables?: readonly MentionCandidate[]
/** The stations this session opened (lib/teamProgress) — the same ring the card shows. */
team?: readonly TeamStation[]
+ /** Open on the ⌘M view (the card menu's "Open card in chat / markdown view"). Terminal cards
+ * only; read per card, like the view itself. */
+ initialView?: 'md'
/** A station was picked from the ring's list: close the modal and go to that node. */
onTravel?: (nodeId: string) => void
}
@@ -124,7 +127,7 @@ interface CardModalProps {
* canvas under it) stay mounted. Terminal cards carry the node header's actions too:
* search / dictate / AI-name / the ⌘M view — ChatPanel or the output markdown, the same face the
* canvas node shows (the node itself is hidden under the board). */
-export function CardModal({ session, projectId, projectName, projectColor, columnTitle, board, onChangeBoard, onClose, portsProjectId, onOpenCanvas, onRename, onEditSticky, onBrowserNav, onSetIcon, onOpenIssue, mentionables, team, onTravel }: CardModalProps) {
+export function CardModal({ session, projectId, projectName, projectColor, columnTitle, board, onChangeBoard, onClose, portsProjectId, onOpenCanvas, onRename, onEditSticky, onBrowserNav, onSetIcon, onOpenIssue, mentionables, team, onTravel, initialView }: CardModalProps) {
const { api } = useSession()
// The header slot decides "icon or smiley" on the NORMALIZED value, the answer NodeIconView
// itself gives — on the raw one, an invalid stored icon drew an empty, un-muted slot.
@@ -182,9 +185,10 @@ export function CardModal({ session, projectId, projectName, projectColor, colum
// Per OPENING, not sticky per card: showing another card resets it, so A → B → A comes back to
// A's live terminal. (The id key above is what keeps the render between the switch and this
// reset from flashing the view onto the new card.)
+ // `initialView` opens this card on the ⌘M view instead (the card menu's row asked for it).
useEffect(() => {
- setMdFor(null)
- }, [session.id])
+ setMdFor(initialView === 'md' ? session.id : null)
+ }, [session.id, initialView])
const toggleMd = useCallback(() => {
setMdFor((cur) => (cur === session.id ? null : session.id))
setSearchOpen(false) // the FindBar searches the xterm the view now covers
diff --git a/src/renderer/components/kanban/KanbanView.accountMenu.test.tsx b/src/renderer/components/kanban/KanbanView.accountMenu.test.tsx
index 9cac9cba0..0261cd7fd 100644
--- a/src/renderer/components/kanban/KanbanView.accountMenu.test.tsx
+++ b/src/renderer/components/kanban/KanbanView.accountMenu.test.tsx
@@ -1,8 +1,9 @@
// @vitest-environment jsdom
//
-// The card right-click menu carries the node's account-switch rows — the SAME builder the canvas
-// node menu uses (Canvas `accountSwitchRows`), passed in as `accountMenuItems`. A card is a second
-// view of its node, so the switch must be reachable from the board without going back to the canvas.
+// The card right-click menu carries the node's own rows — the SAME builder the canvas node menu
+// uses (lib/nodeActionItems, narrowed by Canvas to BOARD_NODE_ACTION_IDS), passed in as
+// `nodeActionItems`. A card is a second view of its node, so color, icon, live link and the
+// account switch must be reachable from the board without going back to the canvas.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { act } from 'react'
import { createRoot, type Root } from 'react-dom/client'
@@ -13,6 +14,11 @@ import type { MenuItem } from '../ContextMenu'
vi.mock('../../session/session', () => ({
useSession: () => ({ source: 'local', api: window.nodeTerminal })
}))
+vi.mock('./CardModal', () => ({
+ CardModal: (p: { session: { id: string }; initialView?: string }) => (
+ <div className="card-modal-mock" data-node={p.session.id} data-view={p.initialView ?? ''} />
+ )
+}))
let root: Root
let host: HTMLElement
@@ -48,7 +54,7 @@ afterEach(() => {
vi.unstubAllGlobals()
})
-function render(accountMenuItems?: (id: string) => MenuItem[], liveLinkMenuItems?: (id: string) => MenuItem[]): void {
+function render(nodeActionItems?: (id: string) => MenuItem[], onAiName?: (id: string) => void): void {
host = document.createElement('div')
document.body.appendChild(host)
root = createRoot(host)
@@ -67,8 +73,8 @@ function render(accountMenuItems?: (id: string) => MenuItem[], liveLinkMenuItems
onModalNodeChange={noop}
onBrowserNav={noop}
onSetIcon={noop}
- accountMenuItems={accountMenuItems}
- liveLinkMenuItems={liveLinkMenuItems}
+ nodeActionItems={nodeActionItems}
+ onAiName={onAiName}
/>
)
)
@@ -80,16 +86,23 @@ function openCardMenu(): void {
card.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 10, clientY: 10 }))
})
}
+function clickRow(label: string): void {
+ const rowEl = [...document.querySelectorAll<HTMLElement>('.ctx-item')].find((el) => el.textContent?.includes(label))
+ if (!rowEl) throw new Error(`no row ${label}`)
+ act(() => rowEl.click())
+}
-describe('KanbanView — card menu account switch', () => {
- it('shows the node’s account-switch rows, built for that card’s node', () => {
+describe('KanbanView — card menu node rows', () => {
+ it('shows the node’s rows from the shared builder, built for that card’s node', () => {
const rows = vi.fn((id: string): MenuItem[] => [
- { label: `Switch Claude account (${id})`, onClick: () => {} }
+ { label: `Switch Claude account (${id})`, onClick: () => {} },
+ { label: `Share live link… (${id})`, onClick: () => {} }
])
render(rows)
openCardMenu()
expect(rows).toHaveBeenCalledWith('n1')
expect(document.body.textContent).toContain('Switch Claude account (n1)')
+ expect(document.body.textContent).toContain('Share live link… (n1)')
})
it('shows none without a builder (no canvas behind the board)', () => {
@@ -97,23 +110,30 @@ describe('KanbanView — card menu account switch', () => {
openCardMenu()
expect(document.body.textContent).toContain('Open card')
expect(document.body.textContent).not.toContain('Switch Claude account')
+ expect(document.body.textContent).not.toContain('Share live link')
})
-})
-describe('KanbanView — card menu Share live link (Task 17)', () => {
- it('shows the node’s "Share live link…" row from the canvas builder, after the account rows', () => {
- const live = vi.fn((id: string): MenuItem[] => [{ label: `Share live link… (${id})`, onClick: () => {} }])
- render(() => [{ label: 'Switch Claude account', onClick: () => {} }], live)
+ it('"Open card in chat / markdown view" opens the card modal on that view', () => {
+ render()
openCardMenu()
- expect(live).toHaveBeenCalledWith('n1')
- const text = document.body.textContent ?? ''
- expect(text).toContain('Share live link… (n1)')
- expect(text.indexOf('Share live link… (n1)')).toBeGreaterThan(text.indexOf('Switch Claude account'))
+ clickRow('Open card in chat / markdown view')
+ const modal = document.querySelector<HTMLElement>('.card-modal-mock')
+ expect(modal?.dataset.node).toBe('n1')
+ expect(modal?.dataset.view).toBe('md')
})
- it('shows none without a builder', () => {
+ it('a plain "Open card" opens it on the live terminal', () => {
render()
openCardMenu()
- expect(document.body.textContent).not.toContain('Share live link')
+ clickRow('Open card')
+ expect(document.querySelector<HTMLElement>('.card-modal-mock')?.dataset.view).toBe('')
+ })
+
+ it('"Name with AI" names that card’s session', () => {
+ const ai = vi.fn()
+ render(undefined, ai)
+ openCardMenu()
+ clickRow('Name with AI')
+ expect(ai).toHaveBeenCalledWith('n1')
})
})
diff --git a/src/renderer/components/kanban/KanbanView.tsx b/src/renderer/components/kanban/KanbanView.tsx
index 4239bc24f..672ae86e2 100644
--- a/src/renderer/components/kanban/KanbanView.tsx
+++ b/src/renderer/components/kanban/KanbanView.tsx
@@ -36,7 +36,8 @@ import { GitHubPullCard } from './GitHubPullCard'
import { kanbanSource, sourceVisible } from '../../lib/kanbanSources'
import type { ModalSpawn } from './ModalTerminal'
import { ContextMenu, type MenuItem } from '../ContextMenu'
-import { IconAgent, IconBranch, IconExternal, IconNote, IconSwitch, IconTerminal, IconTrash, IconWeb } from '../icons'
+import { buildCardMenuItems } from './cardMenu'
+import { IconAgent, IconBranch, IconExternal, IconNote, IconTerminal, IconWeb } from '../icons'
import { issueWorktreeMenuRow, type IssueWorktreeMenuAnswer } from '../../lib/issueWorktree'
import type { GitHubCloseReason, GitHubIssueCardView } from '@shared/github-issues'
import { issueKey, issueRefFromHtmlUrl, issueUrl, type IssueRef } from '@shared/github-issue-ref'
@@ -131,18 +132,14 @@ export interface KanbanViewProps {
/** Set (or clear, with `undefined`) a node's icon — the card modal's icon button. */
onSetIcon: (nodeId: string, icon: NodeIcon | undefined) => void
/**
- * The node's "Switch Claude/Codex account ▸" rows — the SAME builder the canvas node menu uses
- * (`accountSwitchRows` in Canvas), so a card offers exactly what its node does. Optional: a board
- * with no canvas behind it (a test, a future read-only view) simply shows no rows.
+ * The node's own rows for its card menu — the SAME builder the canvas node menu and the sessions
+ * sidebar use (lib/nodeActionItems), narrowed by Canvas to `BOARD_NODE_ACTION_IDS`: stop agent
+ * control, color, icon, Share live link…, Switch Claude/Codex account. Optional: a board with no
+ * canvas behind it (a test, a future read-only view) shows none.
*/
- accountMenuItems?: (nodeId: string) => MenuItem[]
- /**
- * The node's "Share live link…" row — the SAME builder the canvas node menu and the sessions
- * sidebar use (`liveLinkMenuItems` in Canvas), so a card offers what its node does, disabled with
- * the same reason. Optional for the same reason as `accountMenuItems`: a board with no canvas
- * behind it offers none.
- */
- liveLinkMenuItems?: (nodeId: string) => MenuItem[]
+ nodeActionItems?: (nodeId: string) => MenuItem[]
+ /** "Name with AI" on a card (Canvas `aiNameSession`, the sessions sidebar's funnel). Optional. */
+ onAiName?: (nodeId: string) => void
/** The board moving a session card itself because its linked pull requests merged (Canvas owns
* the compare-and-set + board-log line). Optional: without it nothing ever auto-moves. */
onAutoMoveFromPulls?: (
@@ -242,14 +239,24 @@ function useCanvasCovered(): void {
export const KanbanView = memo(function KanbanView({
board, sessions, onChange, onOpenNode, onCreateNode, onRenameNode, onEditSticky, onDeleteNode,
- onModalNodeChange, onBrowserNav, onSetIcon, accountMenuItems, onAutoMoveFromPulls, issueAgentMenu,
- issueWorktreeMenu, teams, onIssueMoved, liveLinkMenuItems
+ onModalNodeChange, onBrowserNav, onSetIcon, nodeActionItems, onAiName, onAutoMoveFromPulls, issueAgentMenu,
+ issueWorktreeMenu, teams, onIssueMoved
}: KanbanViewProps) {
useCanvasCovered()
const { api } = useSession()
const dragRef = useRef<Drag>(null)
// One card modal at a time; a deleted node closes it via the byId.has render guard.
const [modalNodeId, setModalNodeId] = useState<string | null>(null)
+ // The card the menu's "Open card in chat / markdown view" opened. Paired with the open card so
+ // stepping to another card (J/K) or closing the modal never carries the view along.
+ const [mdOpenFor, setMdOpenFor] = useState<string | null>(null)
+ useEffect(() => {
+ if (mdOpenFor !== null && modalNodeId !== mdOpenFor) setMdOpenFor(null)
+ }, [modalNodeId, mdOpenFor])
+ const openCard = useCallback((nodeId: string, view?: 'md') => {
+ setMdOpenFor(view === 'md' ? nodeId : null)
+ setModalNodeId(nodeId)
+ }, [])
// Right-click card menu (open on canvas / move / delete).
const [cardMenu, setCardMenu] = useState<{ x: number; y: number; nodeId: string } | null>(null)
// Board label filter — transient (per board session; resets when you leave the board). Empty =
@@ -994,31 +1001,22 @@ export const KanbanView = memo(function KanbanView({
return lanes
}
- // Right-click menu for a card: open on canvas, move to another column, delete.
+ // Right-click menu for a card — the one list both boards share (cardMenu.tsx).
const cardMenuItems = (nodeId: string): MenuItem[] => {
- const curColId = columnForNode(board, nodeId)?.id ?? null
- const moveTargets: MenuItem[] = [
- ...(curColId !== null
- ? [{ label: 'Ungrouped', onClick: () => commit(assignNode(board, nodeId, null, null)) }]
- : []),
- ...board.columns
- .filter((c) => c.id !== curColId)
- .map((c) => ({
- label: c.title,
- onClick: () => commit(assignNode(board, nodeId, c.id, null))
- }))
- ]
- return [
- { label: 'Open card', icon: <IconExternal />, onClick: () => setModalNodeId(nodeId) },
- { label: 'Open on canvas', icon: <IconExternal />, onClick: () => onOpenNode(nodeId) },
- ...(moveTargets.length
- ? ([{ type: 'submenu', label: 'Move to', icon: <IconSwitch />, children: moveTargets }] as MenuItem[])
- : []),
- ...(accountMenuItems?.(nodeId) ?? []),
- ...(liveLinkMenuItems?.(nodeId) ?? []),
- { type: 'separator' },
- { label: 'Delete', icon: <IconTrash />, danger: true, onClick: () => onDeleteNode(nodeId) }
- ]
+ const card = byId.get(nodeId)
+ if (!card) return []
+ return buildCardMenuItems({
+ card,
+ board,
+ hidden: useSettings.getState().settings.hiddenNodeMenuItems,
+ commit,
+ openCard,
+ openOnCanvas: onOpenNode,
+ rename: onRenameNode,
+ aiName: onAiName,
+ nodeActions: nodeActionItems,
+ remove: onDeleteNode
+ })
}
return (
@@ -1261,6 +1259,7 @@ export const KanbanView = memo(function KanbanView({
board={board}
onChangeBoard={commit}
onClose={() => setModalNodeId(null)}
+ initialView={mdOpenFor === modalNodeId ? 'md' : undefined}
portsProjectId={projectId}
onOpenCanvas={() => {
setModalNodeId(null)
diff --git a/src/renderer/components/kanban/cardMenu.test.tsx b/src/renderer/components/kanban/cardMenu.test.tsx
new file mode 100644
index 000000000..a321daba5
--- /dev/null
+++ b/src/renderer/components/kanban/cardMenu.test.tsx
@@ -0,0 +1,95 @@
+// @vitest-environment jsdom
+import { describe, expect, it, vi } from 'vitest'
+import type { ProjectKanban } from '@shared/types'
+import type { MenuItem } from '../ContextMenu'
+import { buildCardMenuItems, type CardMenuArgs } from './cardMenu'
+
+const prompt = vi.hoisted(() => ({ answer: null as string | null }))
+vi.mock('../promptDialog', () => ({ promptDialog: vi.fn(async () => prompt.answer) }))
+
+const board: ProjectKanban = { columns: [{ id: 'c1', title: 'To Do', color: '#fff' }], assignments: [] }
+
+function args(over: Partial<CardMenuArgs> = {}): CardMenuArgs {
+ return {
+ card: { id: 'n1', kind: 'terminal', title: 'Agent' },
+ board,
+ hidden: [],
+ commit: vi.fn(),
+ openCard: vi.fn(),
+ openOnCanvas: vi.fn(),
+ rename: vi.fn(),
+ aiName: vi.fn(),
+ nodeActions: () => [{ label: 'Share live link…', onClick: () => {} }],
+ remove: vi.fn(),
+ ...over
+ }
+}
+const labels = (items: MenuItem[]): string[] =>
+ items.map((it) => (it.type === 'separator' ? '—' : it.type === 'colors' ? '[colors]' : 'label' in it ? it.label : '?'))
+const click = (items: MenuItem[], label: string): void => {
+ const it = items.find((x) => 'label' in x && x.label === label)
+ if (!it || !('onClick' in it)) throw new Error(`no row ${label}`)
+ it.onClick()
+}
+
+describe('buildCardMenuItems', () => {
+ it('a terminal card: open, view, move, rename, AI name, node rows, delete', () => {
+ expect(labels(buildCardMenuItems(args()))).toEqual([
+ 'Open card',
+ 'Open card in chat / markdown view',
+ 'Open on canvas',
+ 'Move to',
+ '—',
+ 'Rename…',
+ 'Name with AI',
+ '—',
+ 'Share live link…',
+ '—',
+ 'Delete'
+ ])
+ })
+
+ it('the view row opens the card modal on its chat / markdown view, never the canvas node', () => {
+ const a = args()
+ click(buildCardMenuItems(a), 'Open card in chat / markdown view')
+ expect(a.openCard).toHaveBeenCalledWith('n1', 'md')
+ })
+
+ it('the view row follows the markdown-view hide id', () => {
+ expect(labels(buildCardMenuItems(args({ hidden: ['markdown-view'] })))).not.toContain(
+ 'Open card in chat / markdown view'
+ )
+ })
+
+ it('Rename and Name with AI stay whatever the hide list says', () => {
+ const rows = labels(buildCardMenuItems(args({ hidden: ['ai-name', 'markdown-view', 'colors'] })))
+ expect(rows).toContain('Rename…')
+ expect(rows).toContain('Name with AI')
+ })
+
+ it('rename asks for a name and applies only a non-empty one', async () => {
+ const a = args()
+ prompt.answer = ' Build '
+ click(buildCardMenuItems(a), 'Rename…')
+ await vi.waitFor(() => expect(a.rename).toHaveBeenCalledWith('n1', 'Build'))
+ prompt.answer = ' '
+ click(buildCardMenuItems(a), 'Rename…')
+ await new Promise((r) => setTimeout(r, 0))
+ expect(a.rename).toHaveBeenCalledTimes(1)
+ })
+
+ it('a sticky gets no rename, no view row and no AI name', () => {
+ const rows = labels(buildCardMenuItems(args({ card: { id: 'n1', kind: 'sticky', title: 'note' } })))
+ expect(rows).not.toContain('Rename…')
+ expect(rows).not.toContain('Open card in chat / markdown view')
+ expect(rows).not.toContain('Name with AI')
+ })
+
+ it('Delete goes through the board remove (its confirm), with no node rows supplied too', () => {
+ const a = args({ nodeActions: undefined, aiName: undefined })
+ const items = buildCardMenuItems(a)
+ expect(labels(items).at(-1)).toBe('Delete')
+ click(items, 'Delete')
+ expect(a.remove).toHaveBeenCalledWith('n1')
+ })
+})
diff --git a/src/renderer/components/kanban/cardMenu.tsx b/src/renderer/components/kanban/cardMenu.tsx
new file mode 100644
index 000000000..e6f6a3bf9
--- /dev/null
+++ b/src/renderer/components/kanban/cardMenu.tsx
@@ -0,0 +1,92 @@
+/**
+ * The kanban card right-click menu, for BOTH boards (per-project and the Omni lanes) — one list,
+ * so the two views of a card cannot offer different things.
+ *
+ * Board-only rows come first (open, move, rename); then the node's own rows from the shared node
+ * builder (`nodeActions`: lib/nodeActionItems, narrowed to `BOARD_NODE_ACTION_IDS` by Canvas);
+ * then Delete, which goes through the board's own confirm.
+ *
+ * Hide lists: "Open card in chat / markdown view" follows the `markdown-view` id (it replaces the
+ * canvas row of that name on a card). Rename is in no inventory and stays unhideable. "Name with
+ * AI" is NOT gated by the header's `ai-name` id, because the card modal's ✦ button never was:
+ * hiding one and not the other would make the same action vanish from half of the board.
+ */
+import type { ProjectKanban } from '@shared/types'
+import type { MenuItem } from '../ContextMenu'
+import { IconEditor, IconExternal, IconMarkdown, IconSparkle, IconSwitch, IconTrash } from '../icons'
+import { promptDialog } from '../promptDialog'
+import { assignNode, columnForNode } from '../../lib/kanban'
+import { isHidden } from '../../lib/ui-visibility'
+import { tidySeparators } from '../../lib/tidySeparators'
+import type { KanbanSession } from './KanbanView'
+
+export interface CardMenuArgs {
+ card: Pick<KanbanSession, 'id' | 'kind' | 'title'>
+ board: ProjectKanban
+ /** `settings.hiddenNodeMenuItems`. */
+ hidden: readonly string[]
+ /** The board's pruned commit. */
+ commit: (next: ProjectKanban) => void
+ /** Open the card modal; `'md'` opens it on its chat / markdown view. */
+ openCard: (nodeId: string, view?: 'md') => void
+ openOnCanvas: (nodeId: string) => void
+ rename: (nodeId: string, title: string) => void
+ /** Absent = no "Name with AI" row (a board with no canvas behind it). */
+ aiName?: (nodeId: string) => void
+ /** The node's rows from the shared builder. Absent = none. */
+ nodeActions?: (nodeId: string) => MenuItem[]
+ /** The board's Delete — routed through the canvas confirm. */
+ remove: (nodeId: string) => void
+}
+
+export function buildCardMenuItems(a: CardMenuArgs): MenuItem[] {
+ const { card, board } = a
+ const isTerminal = card.kind === 'terminal'
+ const curColId = columnForNode(board, card.id)?.id ?? null
+ const moveTargets: MenuItem[] = [
+ ...(curColId !== null
+ ? [{ label: 'Ungrouped', onClick: () => a.commit(assignNode(board, card.id, null, null)) }]
+ : []),
+ ...board.columns
+ .filter((c) => c.id !== curColId)
+ .map((c) => ({ label: c.title, onClick: () => a.commit(assignNode(board, card.id, c.id, null)) }))
+ ]
+ return tidySeparators([
+ { label: 'Open card', icon: <IconExternal />, onClick: () => a.openCard(card.id) },
+ ...(isTerminal && !isHidden('markdown-view', a.hidden)
+ ? [
+ {
+ label: 'Open card in chat / markdown view',
+ icon: <IconMarkdown />,
+ onClick: () => a.openCard(card.id, 'md')
+ }
+ ]
+ : []),
+ { label: 'Open on canvas', icon: <IconExternal />, onClick: () => a.openOnCanvas(card.id) },
+ ...(moveTargets.length
+ ? ([{ type: 'submenu', label: 'Move to', icon: <IconSwitch />, children: moveTargets }] as MenuItem[])
+ : []),
+ { type: 'separator' },
+ // Not on a sticky: a note's label IS its first line (the card modal does not rename it either).
+ ...(card.kind !== 'sticky'
+ ? [
+ {
+ label: 'Rename…',
+ icon: <IconEditor />,
+ onClick: () => {
+ void promptDialog({ message: 'Rename session', initialValue: card.title }).then((t) => {
+ if (t && t.trim()) a.rename(card.id, t.trim())
+ })
+ }
+ }
+ ]
+ : []),
+ ...(isTerminal && a.aiName
+ ? [{ label: 'Name with AI', icon: <IconSparkle />, onClick: () => a.aiName!(card.id) }]
+ : []),
+ { type: 'separator' },
+ ...(a.nodeActions?.(card.id) ?? []),
+ { type: 'separator' },
+ { label: 'Delete', icon: <IconTrash />, danger: true, onClick: () => a.remove(card.id) }
+ ])
+}