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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(ui): system-resource pill beside the usage pill
enes3f3de78c88ca
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 9f881d0c0..043304540 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -127,6 +127,7 @@ import { NotifyConsentDialog } from '../components/NotifyConsentDialog'import { SessionsSidebar } from '../components/SessionsSidebar'import type { SessionNodeInput } from '../lib/sessionList'import { UsageIndicator } from '../components/UsageIndicator'+import { SystemResourcePill } from '../components/SystemResourcePill'import { PresenceLayer } from '../components/PresenceLayer'import { Facepile } from '../components/Facepile'import { PresenceNamePrompt } from '../components/PresenceNamePrompt'@@ -7886,11 +7887,15 @@ export function Canvas() {{/* MUST stay OUTSIDE <ReactFlow>. The library's wrapper carries inline`position: relative; z-index: 0`, which makes the whole flow one stacking contextpainted at 0 among flow-wrap's siblings — so no z-index INSIDE it, however large,- can ever rise above the sessions sidebar (z 12). Mounted here, the indicator's own+ can ever rise above the sessions sidebar (z 12). Mounted here, each pill's ownz-index (5 collapsed, 13 with the popover open) competes in the same context as the- sidebar and the open popover wins. It uses no React Flow hooks, and .flow-wrap is- position:relative, so its absolute left/bottom anchors are unchanged. */}- <UsageIndicator overBoard={kanbanOpen} />+ sidebar and the open popover wins. Neither uses React Flow hooks, and .flow-wrap is+ position:relative, so the cluster's absolute left/bottom anchor is unchanged.+ The cluster itself deliberately has NO z-index — see .canvas-pills in styles.css. */}+ <div className="canvas-pills">+ <UsageIndicator overBoard={kanbanOpen} />+ <SystemResourcePill overBoard={kanbanOpen} />+ </div><PresenceNamePrompt />diff --git a/src/renderer/canvas/fit-view.ts b/src/renderer/canvas/fit-view.tsindex 92f4467b5..f5cb9381d 100644--- a/src/renderer/canvas/fit-view.ts+++ b/src/renderer/canvas/fit-view.ts@@ -20,6 +20,7 @@ export const CANVAS_CHROME_SELECTOR = ['.minimap','.react-flow__controls','.usage-indicator',+ '.sysres-indicator','.controls-cluster','.sessions-sidebar','.sessions-icon-cluster',diff --git a/src/renderer/components/SystemResourcePill.test.tsx b/src/renderer/components/SystemResourcePill.test.tsxnew file mode 100644index 000000000..4f7c12604--- /dev/null+++ b/src/renderer/components/SystemResourcePill.test.tsx@@ -0,0 +1,146 @@+// @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 { MemInfo, Project } from '@shared/types'+import { useProjects } from '../state/projects'+import { useSshConn } from '../state/sshConn'+import { useSessionMemory } from '../state/sessionMemory'+import { SystemResourcePill } from './SystemResourcePill'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++const project = (over: Partial<Project> = {}): Project => ({+ id: 'p1',+ name: 'p',+ color: '#fff',+ viewport: { x: 0, y: 0, zoom: 1 },+ nodes: [],+ ...over+})++const sshProject = (): Project =>+ project({ id: 'ssh1', ssh: { server: { host: 'box', user: 'enes', port: 22 } as never, remoteCwd: '/srv' } })++/**+ * The FIXTURE is the whole test. `used = totalMb - availableMb` must be distinguishable from every+ * other number in the object, or a component that printed `availableMb` (or `totalMb`) would pass:+ * total 64000, available 48000 ⇒ used 16000, and 15.6 / 46.9 / 62.5 GB are three different strings.+ */+const MEM: MemInfo = { totalMb: 64000, availableMb: 48000 }++let host: HTMLDivElement+let root: Root+let startHostPoll: Mock<(scopeKey: string, projectId?: string) => void>+let stopHostPoll: Mock<() => void>++/** Mount with the store's poll actions stubbed — the real ones would talk to a session registry+ * that does not exist in a jsdom test, and `refreshHost` would clear the `mem` fixture on the way+ * through `enterScope`. */+function mount(mem: MemInfo | null, overBoard = false): void {+ useSessionMemory.setState({ mem, startHostPoll, stopHostPoll })+ host = document.createElement('div')+ root = createRoot(host)+ act(() => root.render(<SystemResourcePill overBoard={overBoard} />))+}++beforeEach(() => {+ startHostPoll = vi.fn<(scopeKey: string, projectId?: string) => void>()+ stopHostPoll = vi.fn<() => void>()+ useProjects.setState({ projects: [project()], activeProjectId: 'p1' })+ useSshConn.setState({ byProject: {} })+})++afterEach(() => {+ act(() => root.unmount())+})++describe('SystemResourcePill', () => {+ it('renders used / total, never the available or total figure alone', () => {+ mount(MEM)+ const pill = host.querySelector('.sysres-pill')+ expect(pill?.textContent).toContain('15.6 GB')+ expect(pill?.textContent).toContain('62.5 GB')+ expect(pill?.textContent).not.toContain('46.9 GB')+ })++ it('fills the bar by memory USED, not by what is free', () => {+ mount(MEM)+ const fill = host.querySelector<HTMLElement>('.sysres-pill__minibar-fill')+ expect(fill?.style.width).toBe('25%')+ })++ it('pulses instead of claiming a number when the reading is null', () => {+ mount(null)+ const pill = host.querySelector('.sysres-pill')+ expect(pill).not.toBeNull()+ expect(host.querySelector('.sysres-pill__pulse')).not.toBeNull()+ // The one thing this pill must never say. `0 GB` is the shape a confident zero takes, but so+ // is any digit at all — there is no number we are entitled to print without a reading.+ expect(pill?.textContent).not.toMatch(/\d/)+ expect(pill?.textContent).not.toContain('GB')+ expect(host.querySelector('.sysres-pill__minibar')).toBeNull()+ })++ it('treats a zero total as unreadable rather than dividing by it', () => {+ mount({ totalMb: 0, availableMb: 0 })+ expect(host.querySelector('.sysres-pill__pulse')).not.toBeNull()+ expect(host.querySelector('.sysres-pill')?.textContent).not.toMatch(/\d/)+ })++ it('starts the host poll for the active project and stops it on unmount', () => {+ mount(MEM)+ expect(startHostPoll).toHaveBeenCalledTimes(1)+ // Explicit project id — the store's `activeSessionApi()` fallback is the only path that can+ // address the wrong machine.+ expect(startHostPoll).toHaveBeenCalledWith('', 'p1')+ act(() => root.unmount())+ expect(stopHostPoll).toHaveBeenCalledTimes(1)+ // The afterEach unmount must not throw on an already-unmounted root.+ root = createRoot(document.createElement('div'))+ })++ it('polls an SSH project under its HOST key, never the local scope', () => {+ useProjects.setState({ projects: [sshProject()], activeProjectId: 'ssh1' })+ mount(MEM)+ expect(startHostPoll).toHaveBeenCalledWith('enes@box', 'ssh1')+ })++ it('re-reads when the SSH project connection comes up', () => {+ useProjects.setState({ projects: [sshProject()], activeProjectId: 'ssh1' })+ mount(MEM)+ expect(startHostPoll).toHaveBeenCalledTimes(1)+ // An SSH scope is read ONCE with no timer behind it, so a first read that landed before the+ // ControlMaster was up would leave the pill blank until the panel was opened.+ act(() => {+ useSshConn.setState({ byProject: { ssh1: { controlPath: '/tmp/cm' } } })+ })+ expect(startHostPoll).toHaveBeenCalledTimes(2)+ expect(startHostPoll).toHaveBeenLastCalledWith('enes@box', 'ssh1')+ })++ it('renders nothing and polls nothing without an active project', () => {+ useProjects.setState({ projects: [], activeProjectId: '' })+ mount(MEM)+ expect(host.querySelector('.sysres-pill')).toBeNull()+ expect(startHostPoll).not.toHaveBeenCalled()+ })++ it('rises above the kanban overlay only when the board is open', () => {+ mount(MEM, true)+ expect(host.querySelector('.sysres-indicator--board')).not.toBeNull()+ act(() => root.unmount())+ mount(MEM, false)+ expect(host.querySelector('.sysres-indicator--board')).toBeNull()+ })++ it('toggles its open state — the pill is the panel´s only entry point', () => {+ mount(MEM)+ const pill = host.querySelector<HTMLButtonElement>('.sysres-pill')!+ expect(pill.getAttribute('aria-expanded')).toBe('false')+ act(() => pill.click())+ expect(host.querySelector('.sysres-pill')?.getAttribute('aria-expanded')).toBe('true')+ act(() => host.querySelector<HTMLButtonElement>('.sysres-pill')!.click())+ expect(host.querySelector('.sysres-pill')?.getAttribute('aria-expanded')).toBe('false')+ })+})diff --git a/src/renderer/components/SystemResourcePill.tsx b/src/renderer/components/SystemResourcePill.tsxnew file mode 100644index 000000000..3c5b6f799--- /dev/null+++ b/src/renderer/components/SystemResourcePill.tsx@@ -0,0 +1,116 @@+import { useEffect, useState } from 'react'+import { formatBytes } from '@shared/fsLimits'+import { useProjects } from '../state/projects'+import { useSshConn } from '../state/sshConn'+import { useSessionMemory } from '../state/sessionMemory'+import { usageScopeKey } from '../lib/usageScope'++/** `formatBytes` speaks bytes; every number in this feature is MB. */+const MB = 1024 * 1024++/** Used-RAM thresholds the bar changes colour at. Pressure, not quota — see the bar's comment. */+const WARN_PERCENT = 75+const DANGER_PERCENT = 90++/**+ * 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.+ */+export function SystemResourcePill({ overBoard = false }: { overBoard?: boolean }): JSX.Element | null {+ const [open, setOpen] = useState(false)++ const mem = useSessionMemory((s) => s.mem)+ const startHostPoll = useSessionMemory((s) => s.startHostPoll)+ const stopHostPoll = useSessionMemory((s) => s.stopHostPoll)++ // The pill follows the ACTIVE project, exactly like UsageIndicator: on a local project this is+ // this machine, on an SSH project it is that host. Selecting the scope KEY (one primitive) rather+ // than the project object keeps this out of the re-render path of every canvas edit.+ const activeProjectId = useProjects((s) => s.activeProjectId)+ const scopeKey = useProjects((s) =>+ usageScopeKey(s.projects.find((p) => p.id === s.activeProjectId))+ )+ const sshUp = useSshConn((s) => !!s.byProject[activeProjectId])++ // OWNERSHIP CONTRACT — do not add a second caller.+ // `useSessionMemory`'s poll timer and its active-scope stamp are MODULE SINGLETONS, and this+ // component is their single owner: only this effect may call `startHostPoll` / `stopHostPoll`.+ // The panel must NOT call `stopHostPoll` on unmount — it would clear this pill's interval with+ // nothing left to restart it, and the number would silently freeze until the next scope change.+ //+ // `sshUp` is in the deps for the same reason remote usage re-reads on connect (CLAUDE.md, Remote+ // usage): an SSH project is opened before its ControlMaster is ready, and an SSH scope is read+ // ONCE with no timer behind it — so a first read that landed on a dead master would leave the pill+ // blank until the user opened the panel. A local project never appears in `byProject`, so this+ // never disturbs the 30 s local cadence. A connection DROP re-reads too, which is right: the read+ // fails and the pill returns to "unknown" instead of holding a stale number under a dead master.+ useEffect(() => {+ // No active project (welcome screen) = no machine to describe. Passing an empty project id+ // would fall through the store's `activeSessionApi()` fallback, which is the one path that can+ // address the wrong machine.+ if (!activeProjectId) return+ startHostPoll(scopeKey, activeProjectId)+ return () => stopHostPoll()+ }, [scopeKey, activeProjectId, sshUp, startHostPoll, stopHostPoll])++ if (!activeProjectId) return null++ let body: JSX.Element+ // `null` = could not read — the normal answer on a non-Linux SSH host, and on any host whose+ // first read has not landed yet. Pulse, NEVER "0 GB": a confident zero is the one thing this pill+ // must never say, since the number is the whole reason anyone looks at it. A `totalMb` of zero is+ // the same fact wearing a plausible shape (and would render the bar as NaN%).+ if (mem === null || mem.totalMb <= 0) {+ body = <span className="sysres-pill__dim sysres-pill__pulse">···</span>+ } else {+ const usedMb = Math.max(0, mem.totalMb - mem.availableMb)+ const usedPercent = Math.min(100, (usedMb / mem.totalMb) * 100)+ // The bar fills as memory is CONSUMED — the opposite direction to the usage pill's bar beside+ // it, which drains as quota is spent. Deliberate: every system monitor draws RAM this way, and+ // "the bar is nearly full" is the reading a user already has for memory pressure.+ const color =+ usedPercent >= DANGER_PERCENT+ ? 'var(--danger)'+ : usedPercent >= WARN_PERCENT+ ? 'var(--warn)'+ : 'var(--success)'+ body = (+ <>+ <span className="sysres-pill__minibar" aria-hidden>+ <span+ className="sysres-pill__minibar-fill"+ style={{ width: `${usedPercent}%`, background: color }}+ />+ </span>+ <span className="sysres-pill__num">+ {formatBytes(usedMb * MB)}+ <span className="sysres-pill__sep"> / </span>+ {formatBytes(mem.totalMb * MB)}+ </span>+ </>+ )+ }++ 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. */}+ <button+ className="sysres-pill"+ onClick={() => setOpen((v) => !v)}+ aria-expanded={open}+ // 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'}+ >+ <span className="sysres-pill__icon">RAM</span>+ {body}+ </button>+ </div>+ )+}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex b6d80ccbe..82ae67461 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -5453,11 +5453,28 @@ body,background: rgba(10, 132, 255, 0.14);}-/* ---- Claude usage indicator (bottom-left, right of React Flow Controls) ---- */-.usage-indicator {+/* ---- Bottom-left pill cluster (usage + system resources) ----+ ONE flex row, because neither pill can hard-code an offset for the other: the usage pill's width+ changes with every number it prints, and it is absent altogether for a user with no agent+ subscription at all.+ Deliberately carries NO z-index: an absolutely positioned box with `z-index: auto` establishes no+ stacking context, so each pill's own z-index (5 / 13 / 26 / 60) keeps competing with the sessions+ sidebar and the kanban overlay exactly as it did when each was anchored on its own. Do not add+ z-index, transform, filter or opacity here — any of them would trap both pills below the sidebar. */+.canvas-pills {position: absolute;left: 60px; /* clear the React Flow Controls column */bottom: 18px;+ display: flex;+ align-items: center;+ gap: 8px;+}++/* ---- Claude usage indicator (in the bottom-left cluster) ---- */+.usage-indicator {+ /* Positioned — so the z-index rules below still apply and the popover anchors here — but PLACED+ by the cluster above rather than by its own left/bottom. */+ position: relative;z-index: 5;display: flex;align-items: center;@@ -5480,7 +5497,10 @@ body,.usage-indicator--board:has(.usage-popover) {z-index: 60; /* over the board + banners, below ConfirmDialog/palette (70) */}-.usage-pill {+/* The two pills share one shell so they read as a single control rather than as two widgets that+ happen to be adjacent. Grouped rather than duplicated, so tuning one can never drift the other. */+.usage-pill,+.sysres-pill {display: inline-flex;align-items: center;gap: 6px;@@ -5496,7 +5516,8 @@ body,}.usage-pill:hover { background: rgba(44, 44, 46, 0.95); }.usage-pill__icon { color: #d97757; font-size: 13px; }-.usage-pill__minibar {+.usage-pill__minibar,+.sysres-pill__minibar {display: inline-block;width: 42px;height: 6px;@@ -5504,16 +5525,53 @@ body,background: rgba(var(--tint-rgb), 0.14);overflow: hidden;}-.usage-pill__minibar-fill { display: block; height: 100%; border-radius: 3px; }-.usage-pill__num { color: var(--text-strong); }-.usage-pill__sep { color: rgba(var(--tint-rgb), 0.4); }+.usage-pill__minibar-fill,+.sysres-pill__minibar-fill { display: block; height: 100%; border-radius: 3px; }+.usage-pill__num,+.sysres-pill__num { color: var(--text-strong); }+.usage-pill__sep,+.sysres-pill__sep { color: rgba(var(--tint-rgb), 0.4); }/* Non-Claude provider segments read one step quieter than the Claude numbers, so a long pillstill scans as "Claude first, others after" without needing separate icons per provider. */.usage-pill__provider .usage-pill__num { color: rgba(var(--tint-rgb), 0.75); font-size: 11px; }-.usage-pill__dim { color: rgba(var(--tint-rgb), 0.5); }-.usage-pill__pulse { animation: usage-pulse 1.2s ease-in-out infinite; }+.usage-pill__dim,+.sysres-pill__dim { color: rgba(var(--tint-rgb), 0.5); }+.usage-pill__pulse,+.sysres-pill__pulse { animation: usage-pulse 1.2s ease-in-out infinite; }@keyframes usage-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }+/* ---- System-resource pill (RAM of the machine the active project runs on) ----+ Shares the usage pill's shell above; only the bits that differ live here. */+.sysres-indicator {+ position: relative;+ z-index: 5;+ display: flex;+ align-items: center;+}+/* Kanban board is an opaque overlay at z 25; while it's open this pill must sit ABOVE it (same+ layer as the controls cluster), or the board's bottom-left corner swallows it. Mirrors+ `.usage-indicator--board`. */+.sysres-indicator--board {+ z-index: 26;+}+/* 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). */+.sysres-pill:hover {+ background:+ linear-gradient(rgba(var(--tint-rgb), 0.08), rgba(var(--tint-rgb), 0.08)),+ rgba(var(--card-rgb), 0.92);+}+/* A word, not a glyph: "12.4 GB / 62.5 GB" beside a quota pill is ambiguous about what is being+ measured, and every symbol for memory is either an emoji or a guess. Set quiet — it is a unit+ label, not a value. */+.sysres-pill__icon {+ color: rgba(var(--tint-rgb), 0.5);+ font-size: 10px;+ font-weight: 600;+ letter-spacing: 0.04em;+}+.usage-refresh {display: inline-flex;align-items: center;