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): dev-server ports chip on the session card

Mina Sameh30ef77bb3b81
diff --git a/src/renderer/components/kanban/GlobalKanbanView.tsx b/src/renderer/components/kanban/GlobalKanbanView.tsx
index 91cbe81e4..fb3f9c1ad 100644
--- a/src/renderer/components/kanban/GlobalKanbanView.tsx
+++ b/src/renderer/components/kanban/GlobalKanbanView.tsx
@@ -106,6 +106,20 @@ const Swimlane = memo(function Swimlane({
const [labelFilter, setLabelFilter] = useState<string[]>([])
const [collapsed, setCollapsed] = useState(false)
const activePortsProjectId = useProjects((s) => s.activeProjectId)
+ // The card face's Ports chip, for the active project's lane only: the dev-port scanner covers the
+ // project on the canvas and nothing else, so a background lane would show a stale or empty list.
+ const portsRemote = useProjects((s) => !!s.getProject(projectId)?.ssh)
+ const cardPorts = useMemo(
+ () => (projectId === activePortsProjectId ? { projectId, remote: portsRemote } : undefined),
+ [projectId, activePortsProjectId, portsRemote]
+ )
+ const openPort = useCallback(
+ (nodeId: string, url: string) => {
+ window.dispatchEvent(new CustomEvent('nodeterm:open-url-node', { detail: { url, sourceNodeId: nodeId } }))
+ onOpenNode(nodeId, projectId)
+ },
+ [onOpenNode, projectId]
+ )
const customAgents = useSettings((s) => s.settings.customAgents)
const disabledAgents = useSettings((s) => s.settings.disabledAgents)
@@ -236,6 +250,8 @@ const Swimlane = memo(function Swimlane({
onTravel={travel}
columnCategory={category}
liveLinkSource={liveLinkSource}
+ ports={cardPorts}
+ onOpenPort={openPort}
/>
))
}]
diff --git a/src/renderer/components/kanban/KanbanView.tsx b/src/renderer/components/kanban/KanbanView.tsx
index aaa8841d9..79807c101 100644
--- a/src/renderer/components/kanban/KanbanView.tsx
+++ b/src/renderer/components/kanban/KanbanView.tsx
@@ -297,6 +297,19 @@ export const KanbanView = memo(function KanbanView({
// Which machine this board's nodes run on — only a local board shows this machine's LIVE chips
// (R57). A primitive, so the memoized cards are not re-rendered by it.
const liveLinkSource = projectSessionSource(projectId)
+ // The card face's Ports chip: this board is always the project on the canvas, which is the one
+ // the dev-port scanner covers. Stable identities, because SessionCard is memoized.
+ const portsRemote = useProjects((s) => !!s.getProject(projectId)?.ssh)
+ const cardPorts = useMemo(() => ({ projectId, remote: portsRemote }), [projectId, portsRemote])
+ const openPort = useCallback(
+ (nodeId: string, url: string) => {
+ // Same hand-over as the card modal's chip: the browser node is placed beside the node ON THE
+ // CANVAS, so the board hands over to the canvas to show it.
+ window.dispatchEvent(new CustomEvent('nodeterm:open-url-node', { detail: { url, sourceNodeId: nodeId } }))
+ onOpenNode(nodeId)
+ },
+ [onOpenNode]
+ )
// Per-user display: whether `closed` columns are on screen (localStorage, never the board).
const showClosed = useKanbanDisplay((s) => s.byProject[projectId]?.showClosed === true)
const setShowClosed = useKanbanDisplay((s) => s.setShowClosed)
@@ -932,6 +945,8 @@ export const KanbanView = memo(function KanbanView({
onTravel={onOpenNode}
columnCategory={category}
liveLinkSource={liveLinkSource}
+ ports={cardPorts}
+ onOpenPort={openPort}
/>
))
})
diff --git a/src/renderer/components/kanban/SessionCard.ports.test.tsx b/src/renderer/components/kanban/SessionCard.ports.test.tsx
new file mode 100644
index 000000000..1a8942259
--- /dev/null
+++ b/src/renderer/components/kanban/SessionCard.ports.test.tsx
@@ -0,0 +1,89 @@
+// @vitest-environment jsdom
+//
+// The card face carries the canvas node header's Ports chip (one component), for a terminal card
+// of the project the dev-port scanner covers. Opening a port is the board handing over to the
+// canvas, never opening the card.
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { SessionCard } from './SessionCard'
+import type { KanbanSession } from './KanbanView'
+
+vi.mock('../ContextMeter', () => ({ ContextMeter: () => null }))
+vi.mock('../PortsChip', () => ({
+ PortsChip: (p: { projectId: string; remote: boolean; onOpenUrl: (url: string) => void }) => (
+ <button
+ className="ports-mock"
+ data-project={p.projectId}
+ data-remote={String(p.remote)}
+ onClick={(e) => {
+ e.stopPropagation()
+ p.onOpenUrl('http://localhost:5173')
+ }}
+ />
+ )
+}))
+
+const terminal: KanbanSession = { id: 'n1', title: 'dev', color: '#fff', kind: 'terminal', spawn: {} }
+const sticky: KanbanSession = { id: 's1', title: 'note', color: '#fff', kind: 'sticky', text: '', spawn: {} }
+const ports = { projectId: 'p1', remote: true }
+
+let root: Root
+let host: HTMLDivElement
+beforeEach(() => {
+ ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+ host = document.createElement('div')
+ document.body.append(host)
+ root = createRoot(host)
+})
+afterEach(() => {
+ act(() => root.unmount())
+ document.body.innerHTML = ''
+})
+
+function render(session: KanbanSession, extra: { ports?: typeof ports; onOpenPort?: (id: string, url: string) => void; onOpen?: (id: string) => void } = {}): void {
+ const noop = (): void => {}
+ act(() =>
+ root.render(
+ <SessionCard
+ session={session}
+ onOpen={extra.onOpen ?? noop}
+ onDragStart={noop}
+ onDragEnd={noop}
+ onDropAt={noop}
+ onContext={noop}
+ liveLinkSource="local"
+ ports={extra.ports}
+ onOpenPort={extra.onOpenPort}
+ />
+ )
+ )
+}
+
+describe('SessionCard — Ports chip', () => {
+ it('a terminal card of the scanned project shows the chip for that project', () => {
+ render(terminal, { ports, onOpenPort: vi.fn() })
+ const chip = document.querySelector<HTMLElement>('.ports-mock')
+ expect(chip?.dataset.project).toBe('p1')
+ expect(chip?.dataset.remote).toBe('true')
+ })
+
+ it('no chip without the scanned project (an Omni lane of a background project)', () => {
+ render(terminal, { onOpenPort: vi.fn() })
+ expect(document.querySelector('.ports-mock')).toBeNull()
+ })
+
+ it('no chip on a note', () => {
+ render(sticky, { ports, onOpenPort: vi.fn() })
+ expect(document.querySelector('.ports-mock')).toBeNull()
+ })
+
+ it('opening a port hands the node and url over, and does not open the card', () => {
+ const onOpenPort = vi.fn()
+ const onOpen = vi.fn()
+ render(terminal, { ports, onOpenPort, onOpen })
+ act(() => document.querySelector<HTMLButtonElement>('.ports-mock')!.click())
+ expect(onOpenPort).toHaveBeenCalledWith('n1', 'http://localhost:5173')
+ expect(onOpen).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/renderer/components/kanban/SessionCard.tsx b/src/renderer/components/kanban/SessionCard.tsx
index b846d0910..39602517a 100644
--- a/src/renderer/components/kanban/SessionCard.tsx
+++ b/src/renderer/components/kanban/SessionCard.tsx
@@ -21,6 +21,7 @@ import { cardAssignees } from '@shared/kanban-labels'
import { TeamProgressChip } from '../TeamProgressChip'
import type { TeamStation } from '../../lib/teamProgress'
import { cardShowsOverdue, sessionNameRepeatsTitle } from '../../lib/cardRedundancy'
+import { PortsChip } from '../PortsChip'
const PRIO_COLOR = Object.fromEntries(PRIORITIES.map((p) => [p.id, p.color])) as Record<KanbanPriority, string>
@@ -54,11 +55,17 @@ interface SessionCardProps {
* this machine's LIVE chip, or counts a link as card detail — a relay tab's node with the same
* id is another machine's terminal (R57). */
liveLinkSource: SessionSource | null
+ /** The card's project, when the dev-port scanner covers it (the project on the canvas). Absent =
+ * no Ports chip: the scanner scans the active project only, so an Omni lane of a background
+ * project would only ever show a stale or empty list. A stable object per board (memo). */
+ ports?: { projectId: string; remote: boolean }
+ /** A port row was picked: open it in a browser node beside the card's node (on the canvas). */
+ onOpenPort?: (nodeId: string, url: string) => void
}
export const SessionCard = memo(function SessionCard({
session, meta, labels = [], onOpen, onDragStart, onDragEnd, onDropAt, onContext, pulls,
- pullFreshness = 'fresh', onOpenIssue, team, onTravel, columnCategory, liveLinkSource
+ pullFreshness = 'fresh', onOpenIssue, team, onTravel, columnCategory, liveLinkSource, ports, onOpenPort
}: SessionCardProps) {
// THIS card's agent status, subscribed per card rather than threaded down from the board.
// KanbanView used to hold `useAgentStatus((s) => s.byId)` and pass the map through the column:
@@ -157,6 +164,16 @@ export const SessionCard = memo(function SessionCard({
{session.kind === 'terminal' && team && team.length > 0 && onTravel && (
<TeamProgressChip stations={team} onTravel={onTravel} />
)}
+ {/* The canvas node header's Ports chip — one component, so the two views of a session
+ cannot disagree. It stops its own clicks, so opening it never opens the card. */}
+ {session.kind === 'terminal' && ports && onOpenPort && (
+ <PortsChip
+ nodeId={session.id}
+ projectId={ports.projectId}
+ remote={ports.remote}
+ onOpenUrl={(url) => onOpenPort(session.id, url)}
+ />
+ )}
{session.kind === 'sticky' && <span className="kanban-card__kind">note</span>}
{session.kind === 'browser' && <span className="kanban-card__kind">web</span>}
{badge === 'dropped' && (