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(ui): session memory panel with travel and kill

enese50fb54b2efe
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 89171d53e..9ed0b7742 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -6560,6 +6560,44 @@ export function Canvas() {
[activeProjectId, deleteNodes, writeDisk]
)
+ /**
+ * End a session picked from the session-memory panel, which lists tmux sessions rather than
+ * canvas nodes — so a row may have no node behind it at all.
+ *
+ * The owner is resolved HERE, at click time, instead of being taken from the row's `orphan` flag:
+ * the panel's rows are a snapshot of the last sweep, and a node created since would otherwise be
+ * killed as an orphan — tmux dies, the canvas node stays, pointing at nothing. When there IS an
+ * owner this goes through `closeSession`, i.e. the exact path the sessions sidebar and the node's
+ * own × use (confirm → destroy → drop the node), so the panel can never invent a third one.
+ */
+ const killSessionById = useCallback(
+ (nodeId: string, orphan: boolean) => {
+ const owner = useProjects
+ .getState()
+ .projects.find((p) => p.nodes.some((n) => n.id === nodeId))
+ if (owner) {
+ closeSession(owner.id, nodeId)
+ return
+ }
+ setConfirm({
+ message: orphan
+ ? 'End this session? It has no node on any canvas — this stops its tmux session.'
+ : 'End this session? This stops its tmux session.',
+ confirmLabel: 'End session',
+ danger: true,
+ onConfirm: () => {
+ transport.destroy(nodeId)
+ // Nothing else to clean up: with no node anywhere, there is no canvas entry to remove and
+ // no parked terminal to dispose. Persisted agent status is dropped anyway, since a
+ // session id can outlive the node it belonged to.
+ useAgentStatus.getState().remove(nodeId)
+ setConfirm(null)
+ }
+ })
+ },
+ [closeSession, setConfirm]
+ )
+
const renameSession = useCallback(
(projectId: string, id: string, title: string) => {
if (projectId === activeProjectId) {
@@ -7897,7 +7935,14 @@ export function Canvas() {
parks a node underneath either pill. */}
<div className="canvas-pills" data-canvas-chrome>
<UsageIndicator overBoard={kanbanOpen} />
- <SystemResourcePill overBoard={kanbanOpen} />
+ {/* `travelToNode`, not `focusNodeById`: the panel resolves sessions in CLOSED projects
+ too (their tmux sessions keep running), and reaching one means reopening its tab
+ first — the same path a notification click and a peer jump take. */}
+ <SystemResourcePill
+ overBoard={kanbanOpen}
+ onGoToNode={travelToNode}
+ onKillSession={killSessionById}
+ />
</div>
<PresenceNamePrompt />
diff --git a/src/renderer/components/SessionMemoryPanel.test.tsx b/src/renderer/components/SessionMemoryPanel.test.tsx
new file mode 100644
index 000000000..78888e0b1
--- /dev/null
+++ b/src/renderer/components/SessionMemoryPanel.test.tsx
@@ -0,0 +1,301 @@
+// @vitest-environment jsdom
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest'
+import type { Project, SessionMemoryRow } from '@shared/types'
+import { useAgentStatus } from '../state/agentStatus'
+import { useProjects } from '../state/projects'
+import { useSessionMemory } from '../state/sessionMemory'
+import { SessionMemoryPanel } from './SessionMemoryPanel'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+const project = (over: Partial<Project> = {}): Project => ({
+ id: 'p1',
+ name: 'Web',
+ color: '#fff',
+ viewport: { x: 0, y: 0, zoom: 1 },
+ nodes: [],
+ ...over
+})
+
+const node = (id: string, title: string): Project['nodes'][number] =>
+ ({ id, kind: 'terminal', title, position: { x: 0, y: 0 } }) as unknown as Project['nodes'][number]
+
+const row = (over: Partial<SessionMemoryRow> & { nodeId: string }): SessionMemoryRow => ({
+ session: `nt-${over.nodeId}`,
+ panePid: 100,
+ selfMb: over.totalMb ?? 0,
+ childrenMb: 0,
+ childCount: 0,
+ totalMb: 0,
+ command: 'bash',
+ ...over
+})
+
+/**
+ * The FIXTURE is the whole test, so it has to discriminate every branch on its own:
+ * - `t1` has children, so `selfMb` and `totalMb` differ (a header that summed the pane process
+ * alone would print 1.2 GB where the truth is 1.5 GB).
+ * - `t3` lives in a CLOSED project — the one row that proves the panel feeds `resolveSessionRows`
+ * every project rather than the open tabs.
+ * - `t2` is a real node with NO agent state: the row that separates "orphan" from "no state". A
+ * fixture where every non-orphan happened to be `working` would let `state === null` pass as a
+ * stand-in for `orphan`.
+ * - `ghost` has no node anywhere — the actual orphan.
+ */
+const ROWS: SessionMemoryRow[] = [
+ row({ nodeId: 't1', selfMb: 600, childrenMb: 300, childCount: 2, totalMb: 900, command: 'claude' }),
+ row({ nodeId: 't3', selfMb: 500, totalMb: 500, command: 'codex' }),
+ row({ nodeId: 't2', selfMb: 120, totalMb: 120, command: 'bash' }),
+ row({ nodeId: 'ghost', selfMb: 40, totalMb: 40, command: 'zsh' })
+]
+
+const PROJECTS: Project[] = [
+ project({ id: 'p1', name: 'Web', nodes: [node('t1', 'Big agent'), node('t2', 'Plain shell')] }),
+ project({ id: 'p2', name: 'Old', closed: true, nodes: [node('t3', 'Parked session')] })
+]
+
+let host: HTMLDivElement
+let root: Root
+let onGoToNode: Mock<(nodeId: string) => void>
+let onKillSession: Mock<(nodeId: string, orphan: boolean) => void>
+let onClose: Mock<() => void>
+let refreshFull: Mock<(scopeKey: string, projectId?: string) => Promise<void>>
+let startHostPoll: Mock<(scopeKey: string, projectId?: string) => void>
+let stopHostPoll: Mock<() => void>
+
+function mount(over: Partial<ReturnType<typeof useSessionMemory.getState>> = {}): void {
+ useSessionMemory.setState({
+ ok: true,
+ rows: ROWS,
+ loadedScope: '',
+ loading: false,
+ refreshFull,
+ startHostPoll,
+ stopHostPoll,
+ ...over
+ })
+ host = document.createElement('div')
+ root = createRoot(host)
+ act(() =>
+ root.render(
+ <SessionMemoryPanel onGoToNode={onGoToNode} onKillSession={onKillSession} onClose={onClose} />
+ )
+ )
+}
+
+const rowsOf = (): HTMLElement[] => [...host.querySelectorAll<HTMLElement>('.sessmem-row')]
+const mainOf = (i: number): HTMLButtonElement =>
+ rowsOf()[i].querySelector<HTMLButtonElement>('.sessmem-row__main')!
+const killOf = (i: number): HTMLButtonElement =>
+ rowsOf()[i].querySelector<HTMLButtonElement>('.sessmem-row__kill')!
+const text = (): string => host.textContent ?? ''
+
+beforeEach(() => {
+ onGoToNode = vi.fn<(nodeId: string) => void>()
+ onKillSession = vi.fn<(nodeId: string, orphan: boolean) => void>()
+ onClose = vi.fn<() => void>()
+ refreshFull = vi.fn<(scopeKey: string, projectId?: string) => Promise<void>>(async () => {})
+ startHostPoll = vi.fn<(scopeKey: string, projectId?: string) => void>()
+ stopHostPoll = vi.fn<() => void>()
+ useProjects.setState({ projects: PROJECTS, activeProjectId: 'p1' })
+ useAgentStatus.setState({ byId: { t1: { state: 'working', unread: false } } })
+})
+
+afterEach(() => {
+ act(() => root.unmount())
+})
+
+describe('SessionMemoryPanel', () => {
+ it('renders every row in the order core sorted them', () => {
+ mount()
+ // No re-sort here: core already sorted by total descending, and a second sort would let the
+ // panel and the report disagree about which session is the biggest.
+ expect(rowsOf().map((r) => r.querySelector('.sessmem-row__title')?.textContent)).toEqual([
+ 'Big agent',
+ 'Parked session',
+ 'Plain shell',
+ 'nt-ghost'
+ ])
+ expect(rowsOf().map((r) => r.querySelector('.sessmem-row__cmd')?.textContent)).toEqual([
+ 'claude',
+ 'codex',
+ 'bash',
+ 'zsh'
+ ])
+ })
+
+ it('never truncates the list', () => {
+ // A cap would have to be a visible "showing top N" line; a silent slice would hide exactly the
+ // sessions a user opened this panel to find.
+ const many = Array.from({ length: 12 }, (_, i) =>
+ row({ nodeId: `n${i}`, selfMb: 100 - i, totalMb: 100 - i })
+ )
+ mount({ rows: many })
+ expect(rowsOf()).toHaveLength(12)
+ })
+
+ it('totals the row TOTAL, children included', () => {
+ mount()
+ // 900 + 500 + 120 + 40 = 1560 MB. Summing `selfMb` instead would print 1.2 GB.
+ expect(host.querySelector('.sessmem-panel__total')?.textContent).toBe('1.5 GB')
+ })
+
+ it("resolves a CLOSED project's session to its real title", () => {
+ // closeProject keeps the project and its nodes on disk. Passing only the open tabs would turn
+ // every parked session into an orphan — silently, in this file, with the suite green.
+ mount()
+ const parked = rowsOf()[1]
+ expect(parked.querySelector('.sessmem-row__title')?.textContent).toBe('Parked session')
+ expect(parked.querySelector('.sessmem-row__project')?.textContent).toBe('Old')
+ expect(mainOf(1).disabled).toBe(false)
+ expect(parked.querySelector('.sessmem-row__orphan')).toBeNull()
+ })
+
+ it('reads orphan-ness from the row, never from a missing agent state', () => {
+ mount()
+ // `t2` is a plain terminal: a real node with a real title that never enters the agent-status
+ // map. Deriving orphan-ness from `state === null` would flag it — and every other plain
+ // terminal on the canvas — as a session with nowhere to travel.
+ expect(mainOf(2).disabled).toBe(false)
+ expect(rowsOf()[2].querySelector('.sessmem-row__orphan')).toBeNull()
+ expect(rowsOf()[2].querySelector('.sessmem-row__dot--hollow')).toBeNull()
+ // The real orphan, by contrast.
+ expect(mainOf(3).disabled).toBe(true)
+ expect(rowsOf()[3].querySelector('.sessmem-row__orphan')).not.toBeNull()
+ expect(rowsOf()[3].querySelector('.sessmem-row__dot--hollow')).not.toBeNull()
+ })
+
+ it('travels to a resolvable row and closes', () => {
+ mount()
+ act(() => mainOf(0).click())
+ expect(onGoToNode).toHaveBeenCalledWith('t1')
+ expect(onClose).toHaveBeenCalledTimes(1)
+ })
+
+ it('travels to a CLOSED project session too', () => {
+ mount()
+ act(() => mainOf(1).click())
+ expect(onGoToNode).toHaveBeenCalledWith('t3')
+ })
+
+ it('leaves an orphan row inert but still killable', () => {
+ mount()
+ act(() => mainOf(3).click())
+ expect(onGoToNode).not.toHaveBeenCalled()
+ expect(onClose).not.toHaveBeenCalled()
+ act(() => killOf(3).click())
+ expect(onKillSession).toHaveBeenCalledWith('ghost', true)
+ })
+
+ it('kills a resolvable row as a non-orphan', () => {
+ mount()
+ act(() => killOf(0).click())
+ expect(onKillSession).toHaveBeenCalledWith('t1', false)
+ // Killing is not travelling: the panel stays put behind its confirm dialog.
+ expect(onGoToNode).not.toHaveBeenCalled()
+ })
+
+ it('names the extra processes as CHILD processes, not as MCP servers', () => {
+ mount()
+ // `childCount` counts every descendant of the pane — the agent CLI itself plus whatever it
+ // spawned — because `pane_pid` is the pane's SHELL. Calling them MCP servers would miscount
+ // (claude + 2 MCP servers reads as 3) and mislabel a plain `npm run dev`.
+ const kids = rowsOf()[0].querySelector('.sessmem-row__kids')?.textContent ?? ''
+ expect(kids).toContain('2 child processes')
+ expect(kids).toContain('300.0 MB')
+ expect(text()).not.toContain('MCP')
+ // Only the row that has children gets the sub-line.
+ expect(host.querySelectorAll('.sessmem-row__kids')).toHaveLength(1)
+ })
+
+ it('says it could not measure — never an empty list, never a zero', () => {
+ mount({ ok: false, rows: [], loadedScope: null })
+ expect(text()).toContain('Could not measure')
+ expect(rowsOf()).toHaveLength(0)
+ expect(host.querySelector('.sessmem-panel__total')).toBeNull()
+ expect(text()).not.toContain('0 MB')
+ expect(text()).not.toContain('0 sessions')
+ // "We could not look" is the one state where the retry matters most.
+ expect(host.querySelector<HTMLButtonElement>('.sessmem-panel__refresh')?.disabled).toBe(false)
+ })
+
+ it('distinguishes a measured-empty machine from a failed sweep', () => {
+ mount({ ok: true, rows: [], loadedScope: '' })
+ expect(text()).not.toContain('Could not measure')
+ expect(text()).toContain('No sessions')
+ })
+
+ it('says nothing at all before the first sweep lands', () => {
+ // `rows: []` with nothing loaded yet is not "there are no sessions" either.
+ mount({ ok: true, rows: [], loadedScope: null, loading: true })
+ expect(text()).not.toContain('No sessions')
+ expect(text()).not.toContain('Could not measure')
+ expect(text()).toContain('Measuring')
+ })
+
+ it('tells a relay tab it is unsupported here, not that the measurement failed', () => {
+ // A relay tab's renderer runs on the guest while its sessions live on the host, so its
+ // sessionMemory api is the ws-bridge stub: a permanent `ok:false`. That is the honest STUB
+ // value and the wrong user-facing story — there is nothing to retry.
+ useProjects.setState({
+ projects: [project({ id: 'r1', name: 'Mac', remote: true })],
+ activeProjectId: 'r1'
+ })
+ mount({ ok: false, rows: [], loadedScope: null })
+ expect(text()).not.toContain('Could not measure')
+ expect(text()).toContain('relay')
+ expect(host.querySelector('.sessmem-panel__refresh')).toBeNull()
+ // No point sweeping a machine whose answer is a stub.
+ expect(refreshFull).not.toHaveBeenCalled()
+ })
+
+ it('sweeps on open and on refresh, always naming the project', () => {
+ mount()
+ expect(refreshFull).toHaveBeenCalledTimes(1)
+ // The project id is explicit: the store's `activeSessionApi()` fallback is the one path that
+ // can address the wrong machine.
+ expect(refreshFull).toHaveBeenCalledWith('', 'p1')
+ act(() => host.querySelector<HTMLButtonElement>('.sessmem-panel__refresh')!.click())
+ expect(refreshFull).toHaveBeenCalledTimes(2)
+ expect(refreshFull).toHaveBeenLastCalledWith('', 'p1')
+ })
+
+ it('scopes the sweep and the header to an SSH project´s host', () => {
+ useProjects.setState({
+ projects: [
+ project({
+ id: 'ssh1',
+ name: 'Box',
+ ssh: { server: { host: 'box', user: 'enes', port: 22 } as never, remoteCwd: '/srv' }
+ })
+ ],
+ activeProjectId: 'ssh1'
+ })
+ mount({ loadedScope: 'enes@box' })
+ expect(refreshFull).toHaveBeenCalledWith('enes@box', 'ssh1')
+ expect(host.querySelector('.sessmem-panel__scope')?.textContent).toBe('enes@box')
+ })
+
+ it('labels the local scope as this machine', () => {
+ mount()
+ expect(host.querySelector('.sessmem-panel__scope')?.textContent).toBe('This machine')
+ })
+
+ it('counts the sessions it is showing', () => {
+ mount()
+ expect(host.querySelector('.sessmem-panel__count')?.textContent).toBe('4 sessions')
+ })
+
+ it('never touches the host poll — the pill owns that timer', () => {
+ // `timer` and `activeScope` in the store are MODULE singletons. A `stopHostPoll` here would
+ // clear the pill's interval on close with nothing left to restart it, and the pill's number
+ // would freeze until the next scope change.
+ mount()
+ act(() => root.unmount())
+ expect(startHostPoll).not.toHaveBeenCalled()
+ expect(stopHostPoll).not.toHaveBeenCalled()
+ root = createRoot(document.createElement('div'))
+ })
+})
diff --git a/src/renderer/components/SessionMemoryPanel.tsx b/src/renderer/components/SessionMemoryPanel.tsx
new file mode 100644
index 000000000..98e19b410
--- /dev/null
+++ b/src/renderer/components/SessionMemoryPanel.tsx
@@ -0,0 +1,210 @@
+// The panel behind the system-resource pill: which sessions are holding the machine's memory,
+// biggest first, each one travelable and killable.
+//
+// Three rules run through the whole file, and each of them is a fact this feature exists to stop
+// the app from getting wrong:
+// 1. "We could not look" and "there is nothing" are DIFFERENT ANSWERS. A failed sweep says so —
+// it never degrades into an empty list, a `0 MB` total or a "0 sessions" count.
+// 2. Orphan-ness comes from the resolved row, never from a missing agent state: a plain terminal
+// never enters the agent-status map at all.
+// 3. Every row is rendered. A cap would have to announce itself.
+
+import { useEffect, useMemo } from 'react'
+import type { AgentState } from '@shared/agents/normalize'
+import { formatBytes } from '@shared/fsLimits'
+import { useAgentStatus } from '../state/agentStatus'
+import { useProjects } from '../state/projects'
+import { useSessionMemory } from '../state/sessionMemory'
+import { resolveSessionRows, totalMb } from '../lib/sessionMemoryRows'
+import { usageScopeKey } from '../lib/usageScope'
+
+export interface SessionMemoryPanelProps {
+ /** Travel to the node behind a row. Canvas passes `travelToNode`, so a CLOSED project's tab is
+ * reopened first — the panel lists those sessions, so it has to be able to reach them. */
+ onGoToNode: (nodeId: string) => void
+ /** Confirm + end the session. `orphan` says whether the panel believes there is a node behind it;
+ * Canvas re-resolves the owner at click time and only uses this for the wording. */
+ onKillSession: (nodeId: string, orphan: boolean) => void
+ onClose: () => void
+}
+
+/** Every number in this feature is MB; `formatBytes` speaks bytes. One formatter, so the panel's
+ * units read like the rest of the app. */
+function formatMb(mb: number): string {
+ return formatBytes(mb * 1024 * 1024)
+}
+
+/**
+ * The node header's status vocabulary, as a dot: working is `--success`, waiting/blocked is
+ * `--warn` (the two states the header spells RUNNING and NEEDS YOU), everything else is quiet.
+ * Hollow = orphan: there is no node to have a state, and a filled neutral dot would read as "idle".
+ */
+function StatusDot({ state, hollow }: { state: AgentState | null; hollow: boolean }): JSX.Element {
+ const kind =
+ state === 'working' ? 'working' : state === 'waiting' || state === 'blocked' ? 'attention' : 'idle'
+ return (
+ <span
+ className={`sessmem-row__dot sessmem-row__dot--${kind}${hollow ? ' sessmem-row__dot--hollow' : ''}`}
+ aria-hidden
+ />
+ )
+}
+
+export function SessionMemoryPanel({
+ onGoToNode,
+ onKillSession,
+ onClose
+}: SessionMemoryPanelProps): JSX.Element {
+ const ok = useSessionMemory((s) => s.ok)
+ const rows = useSessionMemory((s) => s.rows)
+ const loading = useSessionMemory((s) => s.loading)
+ const loadedScope = useSessionMemory((s) => s.loadedScope)
+ const refreshFull = useSessionMemory((s) => s.refreshFull)
+
+ // EVERY project, closed ones included: `closeProject` keeps the project and its nodes on disk
+ // (only the tab goes away), so its sessions resolve to a real title. Filtering to the open tabs
+ // here would turn every deliberately parked session into an orphan.
+ const projects = useProjects((s) => s.projects)
+ const activeProjectId = useProjects((s) => s.activeProjectId)
+ const active = useMemo(
+ () => projects.find((p) => p.id === activeProjectId),
+ [projects, activeProjectId]
+ )
+ const scopeKey = usageScopeKey(active)
+ // A relay tab's renderer runs on the GUEST while its sessions live on the host, so its
+ // sessionMemory api is the ws-bridge stub — a permanent `ok:false`. That is the honest stub value
+ // and the wrong story to tell a human: nothing failed and there is nothing to retry. The runtime
+ // `remote` flag is how the rest of the renderer spots a relay tab (see TerminalNode's file links).
+ const relay = !!active?.remote
+
+ const byId = useAgentStatus((s) => s.byId)
+ // `resolveSessionRows` wants the bare states; an entry's `state` is optional, and an unknown one
+ // is null rather than a default.
+ const states = useMemo(
+ () => Object.fromEntries(Object.entries(byId).map(([id, v]) => [id, v.state])),
+ [byId]
+ )
+ const views = useMemo(
+ () => resolveSessionRows(rows, projects, states),
+ [rows, projects, states]
+ )
+
+ // The sweep runs on OPEN (the panel is unmounted while closed) and on ⟳ — never on a timer, and
+ // never from the pill: it walks the whole process table, and on an SSH scope that is an ssh exec
+ // plus a `ps` of somebody else's machine. The project id is explicit, because the store's
+ // `activeSessionApi()` fallback is the one path that can address the wrong machine.
+ //
+ // This component must NEVER call `startHostPoll` / `stopHostPoll`: the store's timer and its
+ // active-scope stamp are module singletons owned by the pill, and a `stopHostPoll` on unmount
+ // would clear the pill's interval with nothing left to restart it.
+ useEffect(() => {
+ if (relay || !activeProjectId) return
+ void refreshFull(scopeKey, activeProjectId)
+ }, [relay, scopeKey, activeProjectId, refreshFull])
+
+ // Have we got an answer for THIS machine yet? A `loadedScope` from the machine we just left says
+ // nothing about this one, so it is compared, not merely checked for existence.
+ const measured = ok && loadedScope === scopeKey
+
+ let body: JSX.Element
+ if (relay) {
+ body = (
+ <div className="sessmem-panel__note">
+ Session memory is not available on a relay tab — these sessions run on the other machine.
+ </div>
+ )
+ } else if (!ok) {
+ // Rendering an empty list here would report "nothing is using memory" at exactly the moment we
+ // failed to measure it.
+ body = <div className="sessmem-panel__note">Could not measure sessions on this machine.</div>
+ } else if (!measured) {
+ body = <div className="sessmem-panel__note">Measuring…</div>
+ } else if (views.length === 0) {
+ // We looked, and there really is nothing — a different sentence from the two above.
+ body = <div className="sessmem-panel__note">No sessions are running here.</div>
+ } else {
+ body = (
+ <ul className="sessmem-panel__rows">
+ {/* Every row, in core's order (already sorted by total, descending). */}
+ {views.map((v) => (
+ <li key={v.row.session} className="sessmem-row">
+ <button
+ className="sessmem-row__main"
+ // Nothing to travel to. The guard inside is not redundant: `disabled` is the DOM's
+ // answer and this is the code's.
+ disabled={v.orphan}
+ onClick={() => {
+ if (v.orphan) return
+ onGoToNode(v.row.nodeId)
+ onClose()
+ }}
+ title={v.orphan ? 'No node on any canvas' : `Go to ${v.title}`}
+ >
+ <StatusDot state={v.state} hollow={v.orphan} />
+ <span className="sessmem-row__title">{v.title}</span>
+ {v.orphan ? (
+ <span className="sessmem-row__orphan">no node</span>
+ ) : (
+ v.projectId !== activeProjectId && (
+ <span className="sessmem-row__project">{v.projectName}</span>
+ )
+ )}
+ <span className="sessmem-row__cmd">{v.row.command}</span>
+ <span className="sessmem-row__mb">{formatMb(v.row.totalMb)}</span>
+ </button>
+ <button
+ className="sessmem-row__kill"
+ title="End this session"
+ aria-label={`End ${v.title}`}
+ onClick={() => onKillSession(v.row.nodeId, v.orphan)}
+ >
+ ×
+ </button>
+ {v.row.childCount > 0 && (
+ // "child processes", NOT "MCP servers": `pane_pid` is the pane's SHELL, so the count
+ // is the agent CLI itself plus everything it spawned. A claude session with two MCP
+ // servers reads as 3, and a plain `npm run dev` has children too.
+ <div className="sessmem-row__kids">
+ └ +{v.row.childCount} child processes <span>{formatMb(v.row.childrenMb)}</span>
+ </div>
+ )}
+ </li>
+ ))}
+ </ul>
+ )
+ }
+
+ return (
+ <div className="sessmem-panel" id="sessmem-panel" role="region" aria-label="Session memory">
+ <div className="sessmem-panel__head">
+ <span className="sessmem-panel__title">Session memory</span>
+ {/* Which machine these numbers describe. The SSH panel is visually identical to the local
+ one, so the scope has to be written down. */}
+ <span className="sessmem-panel__scope">{scopeKey || 'This machine'}</span>
+ {/* No total unless we measured one: a grand total of `0 MB` beside a failure is the exact
+ conflation this panel exists to end. */}
+ {measured && <span className="sessmem-panel__total">{formatMb(totalMb(views))}</span>}
+ </div>
+
+ {body}
+
+ <div className="sessmem-panel__foot">
+ <span className="sessmem-panel__count">
+ {measured ? `${views.length} session${views.length === 1 ? '' : 's'}` : ''}
+ </span>
+ {/* A relay tab has nothing to retry — the answer is a stub, not a failure. */}
+ {!relay && (
+ <button
+ className={`sessmem-panel__refresh${loading ? ' spin' : ''}`}
+ title="Re-measure"
+ aria-label="Re-measure"
+ disabled={loading}
+ onClick={() => void refreshFull(scopeKey, activeProjectId)}
+ >
+ ⟳
+ </button>
+ )}
+ </div>
+ </div>
+ )
+}
diff --git a/src/renderer/components/SystemResourcePill.test.tsx b/src/renderer/components/SystemResourcePill.test.tsx
index f937020b3..e7fd369f5 100644
--- a/src/renderer/components/SystemResourcePill.test.tsx
+++ b/src/renderer/components/SystemResourcePill.test.tsx
@@ -47,7 +47,11 @@ function mount(mem: MemInfo | null, overBoard = false): void {
useSessionMemory.setState({ mem, startHostPoll, stopHostPoll, refreshFull })
host = document.createElement('div')
root = createRoot(host)
- act(() => root.render(<SystemResourcePill overBoard={overBoard} />))
+ act(() =>
+ root.render(
+ <SystemResourcePill overBoard={overBoard} onGoToNode={vi.fn()} onKillSession={vi.fn()} />
+ )
+ )
}
beforeEach(() => {
@@ -128,16 +132,22 @@ describe('SystemResourcePill', () => {
expect(refreshFull).not.toHaveBeenCalled()
})
- it('never runs the full sweep — the cheap read is the pill´s, the expensive one the panel´s', () => {
+ it('never runs the full sweep itself — the cheap read is the pill´s, the expensive one the panel´s', () => {
// `refreshFull` walks the whole process table, and on an SSH scope that is an ssh exec plus a
// remote `ps`. On this component's 30 s timer that would be a background cost nobody asked for,
// and the real action swallows its failures, so it would show no symptom at all.
mount(MEM)
expect(refreshFull).not.toHaveBeenCalled()
- // Not even when the pill is clicked: opening the panel is what triggers the sweep, and the
- // panel does it itself (Task 9).
+ // Clicking sweeps exactly once, and the call comes from the MOUNTED PANEL — never from a
+ // second caller here that a later timer could be attached to. (The sweep-on-open contract
+ // itself is pinned in SessionMemoryPanel.test.tsx.)
act(() => host.querySelector<HTMLButtonElement>('.sysres-pill')!.click())
- expect(refreshFull).not.toHaveBeenCalled()
+ expect(host.querySelector('.sessmem-panel')).not.toBeNull()
+ expect(refreshFull).toHaveBeenCalledTimes(1)
+ // Closing unmounts the panel, so nothing keeps sweeping behind it.
+ act(() => host.querySelector<HTMLButtonElement>('.sysres-pill')!.click())
+ expect(host.querySelector('.sessmem-panel')).toBeNull()
+ expect(refreshFull).toHaveBeenCalledTimes(1)
})
it('renders nothing and polls nothing without an active project', () => {
@@ -164,4 +174,18 @@ describe('SystemResourcePill', () => {
act(() => host.querySelector<HTMLButtonElement>('.sysres-pill')!.click())
expect(host.querySelector('.sysres-pill')?.getAttribute('aria-expanded')).toBe('false')
})
+
+ it('announces a region that actually exists', () => {
+ // `aria-expanded` on its own told assistive tech about an expandable region and expanded
+ // nothing. It may only ship pointing at the real panel.
+ mount(MEM)
+ const pill = host.querySelector<HTMLButtonElement>('.sysres-pill')!
+ const controls = pill.getAttribute('aria-controls')
+ expect(controls).toBeTruthy()
+ expect(host.querySelector(`#${controls}`)).toBeNull()
+ act(() => pill.click())
+ const panel = host.querySelector(`#${controls}`)
+ expect(panel).not.toBeNull()
+ expect(panel?.classList.contains('sessmem-panel')).toBe(true)
+ })
})
diff --git a/src/renderer/components/SystemResourcePill.tsx b/src/renderer/components/SystemResourcePill.tsx
index 3c5b6f799..1805c5b01 100644
--- a/src/renderer/components/SystemResourcePill.tsx
+++ b/src/renderer/components/SystemResourcePill.tsx
@@ -4,6 +4,7 @@ import { useProjects } from '../state/projects'
import { useSshConn } from '../state/sshConn'
import { useSessionMemory } from '../state/sessionMemory'
import { usageScopeKey } from '../lib/usageScope'
+import { SessionMemoryPanel } from './SessionMemoryPanel'
/** `formatBytes` speaks bytes; every number in this feature is MB. */
const MB = 1024 * 1024
@@ -12,15 +13,29 @@ const MB = 1024 * 1024
const WARN_PERCENT = 75
const DANGER_PERCENT = 90
+export interface SystemResourcePillProps {
+ overBoard?: boolean
+ /** Handed straight to the panel. Required, not optional: an omitted callback would compile into
+ * a panel whose rows silently do nothing. */
+ onGoToNode: (nodeId: string) => void
+ onKillSession: (nodeId: string, orphan: boolean) => void
+}
+
/**
* Bottom-left system-resource pill: how much RAM the machine the ACTIVE project runs on is using.
* Sits beside the usage pill in the same cluster and takes its scope from the same helper
* (`usageScopeKey`), so the two can never disagree about which machine they describe.
*
- * Clicking toggles the session-memory panel (Task 9 renders it into the slot below); this pill is
- * the panel's only entry point.
+ * Clicking toggles the session-memory panel; this pill is the panel's only entry point. The panel
+ * is UNMOUNTED while closed — its sweep is expensive (the whole process table, and over SSH an
+ * exec on someone else's machine) and must never run behind a closed panel. Mounting is what
+ * triggers the sweep, which is also why the pill itself never calls `refreshFull`.
*/
-export function SystemResourcePill({ overBoard = false }: { overBoard?: boolean }): JSX.Element | null {
+export function SystemResourcePill({
+ overBoard = false,
+ onGoToNode,
+ onKillSession
+}: SystemResourcePillProps): JSX.Element | null {
const [open, setOpen] = useState(false)
const mem = useSessionMemory((s) => s.mem)
@@ -97,13 +112,20 @@ export function SystemResourcePill({ overBoard = false }: { overBoard?: boolean
return (
<div className={`sysres-indicator${overBoard ? ' sysres-indicator--board' : ''}`}>
- {/* Task 9 renders <SessionMemoryPanel /> here while `open`. The pill owns the open state so
- the panel can be unmounted entirely when closed — its sweep is expensive and must never
- run behind a closed panel. */}
+ {open && (
+ <SessionMemoryPanel
+ onGoToNode={onGoToNode}
+ onKillSession={onKillSession}
+ onClose={() => setOpen(false)}
+ />
+ )}
<button
className="sysres-pill"
onClick={() => setOpen((v) => !v)}
aria-expanded={open}
+ // Points at the region `aria-expanded` announces. The panel is mounted only while open, so
+ // this resolves exactly when it claims to.
+ aria-controls="sessmem-panel"
// The SSH pill is visually identical to the local one, so the title is what answers
// "whose memory is this?" without opening the panel.
title={scopeKey ? `Memory on ${scopeKey}` : 'Memory on this machine'}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 82ae67461..f64ea3494 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -5554,6 +5554,16 @@ body,
.sysres-indicator--board {
z-index: 26;
}
+/* While the session-memory panel is open, rise above the sessions sidebar (z 12) — a tall sidebar
+ reaches the bottom-left corner and would cover the panel. Exactly the pairing
+ `.usage-indicator:has(.usage-popover)` uses, and it only works because the cluster is mounted
+ OUTSIDE <ReactFlow> (whose wrapper's inline `z-index: 0` would trap any inner value). */
+.sysres-indicator:has(.sessmem-panel) {
+ z-index: 13;
+}
+.sysres-indicator--board:has(.sessmem-panel) {
+ z-index: 60; /* over the board + banners, below ConfirmDialog/palette (70) */
+}
/* Not a copy of `.usage-pill:hover`: that rule's literal is a dark-theme colour, which would read
as a black smear on the light theme. An ink overlay over the same card surface lifts it in BOTH
themes (the tint token flips with the theme). */
@@ -5648,6 +5658,184 @@ body,
vertical-align: middle;
}
+/* ---- Session-memory panel (opened by the system-resource pill) ----
+ Same surface, border and shadow as `.usage-popover` above — the two panels open from adjacent
+ pills in the same corner, so anything that made them read as different kinds of thing would be
+ an accident. Wider, because a row carries a title, a project, a command and a number. */
+.sessmem-panel {
+ position: absolute;
+ bottom: 34px;
+ left: 0;
+ width: 380px;
+ padding: 12px 14px;
+ border-radius: 12px;
+ background: rgba(var(--popover-rgb), 0.98);
+ border: 1px solid rgba(var(--tint-rgb), 0.1);
+ box-shadow: 0 12px 40px rgba(0, 0, 0, calc(0.5 * var(--shadow-k)));
+ color: var(--text-strong);
+}
+.sessmem-panel__head {
+ display: flex;
+ align-items: baseline;
+ gap: 8px;
+ margin-bottom: 10px;
+}
+.sessmem-panel__title { font-size: 14px; font-weight: 600; }
+.sessmem-panel__scope {
+ flex: 1 1 auto;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ font-size: 11px;
+ color: rgba(var(--tint-rgb), 0.5);
+}
+.sessmem-panel__total {
+ font-size: 13px;
+ font-variant-numeric: tabular-nums;
+ color: var(--text-strong);
+}
+/* One voice for all four non-list states (relay / could-not-measure / measuring / nothing here).
+ They are different SENTENCES, deliberately, but they are the same kind of answer. */
+.sessmem-panel__note {
+ padding: 10px 2px;
+ font-size: 12px;
+ line-height: 1.45;
+ color: rgba(var(--tint-rgb), 0.6);
+}
+.sessmem-panel__rows {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ /* Every row is rendered — the list SCROLLS rather than truncating. A cap would have to say so. */
+ max-height: 320px;
+ overflow-y: auto;
+}
+.sessmem-row {
+ display: flex;
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 4px;
+}
+.sessmem-row__main {
+ flex: 1 1 auto;
+ min-width: 0;
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ padding: 5px 6px;
+ border: none;
+ border-radius: 6px;
+ background: transparent;
+ color: inherit;
+ font-size: 12px;
+ text-align: left;
+ cursor: pointer;
+}
+.sessmem-row__main:hover:not(:disabled) { background: rgba(var(--tint-rgb), 0.08); }
+/* An orphan has nowhere to travel to, so the row is inert rather than misleadingly clickable —
+ but it keeps full contrast: it is still a session the user may want to end. */
+.sessmem-row__main:disabled { cursor: default; }
+.sessmem-row__dot {
+ flex: 0 0 auto;
+ width: 7px;
+ height: 7px;
+ border-radius: 50%;
+}
+.sessmem-row__dot--working {
+ background: var(--success);
+ /* Reuse the terminal-header badge pulse rather than a bespoke keyframe. */
+ animation: nt-pulse 1.1s ease-in-out infinite;
+}
+.sessmem-row__dot--attention { background: var(--warn); }
+.sessmem-row__dot--idle { background: rgba(var(--tint-rgb), 0.3); }
+/* Hollow = orphan: there is no node to have a state, and a filled neutral dot would read "idle". */
+.sessmem-row__dot--hollow {
+ background: transparent;
+ border: 1px solid rgba(var(--tint-rgb), 0.35);
+ animation: none;
+}
+.sessmem-row__title {
+ flex: 1 1 auto;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+/* Where this session lives, shown only when it is NOT the project you are looking at — most often
+ a closed project, whose sessions keep running. */
+.sessmem-row__project,
+.sessmem-row__orphan {
+ flex: 0 0 auto;
+ padding: 1px 5px;
+ border-radius: 4px;
+ font-size: 10px;
+ color: rgba(var(--tint-rgb), 0.55);
+ background: rgba(var(--tint-rgb), 0.08);
+}
+.sessmem-row__cmd {
+ flex: 0 0 auto;
+ max-width: 90px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ font-size: 11px;
+ color: rgba(var(--tint-rgb), 0.45);
+}
+.sessmem-row__mb {
+ flex: 0 0 auto;
+ font-variant-numeric: tabular-nums;
+ color: var(--text-strong);
+}
+.sessmem-row__kill {
+ flex: 0 0 auto;
+ width: 20px;
+ height: 20px;
+ border: none;
+ border-radius: 10px;
+ background: transparent;
+ color: rgba(var(--tint-rgb), 0.45);
+ font-size: 14px;
+ line-height: 1;
+ cursor: pointer;
+}
+.sessmem-row__kill:hover { color: var(--danger); background: rgba(var(--tint-rgb), 0.08); }
+/* The pane's descendants — the agent CLI itself included, since pane_pid is the pane's shell. */
+.sessmem-row__kids {
+ flex: 1 0 100%;
+ padding: 0 6px 4px 20px;
+ font-size: 11px;
+ color: rgba(var(--tint-rgb), 0.45);
+ font-variant-numeric: tabular-nums;
+}
+.sessmem-panel__foot {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin-top: 10px;
+ padding-top: 8px;
+ border-top: 1px solid rgba(var(--tint-rgb), 0.1);
+ font-size: 11px;
+ color: rgba(var(--tint-rgb), 0.5);
+}
+.sessmem-panel__refresh {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 22px;
+ height: 22px;
+ border: none;
+ border-radius: 11px;
+ background: transparent;
+ color: rgba(var(--tint-rgb), 0.7);
+ font-size: 13px;
+ cursor: pointer;
+}
+.sessmem-panel__refresh:hover { color: var(--text-strong); background: rgba(var(--tint-rgb), 0.08); }
+.sessmem-panel__refresh:disabled { opacity: 0.4; cursor: default; }
+/* Same spin as the usage panel's refresh. */
+.sessmem-panel__refresh.spin { animation: usage-spin 0.9s linear infinite; }
+
/* ---- Claude context-window meter (per-node header pill + popover) ---- */
.ctx-meter {
position: relative;