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(canvas): mount presence layer, facepile and name prompt
enes10963ed18e29
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 99614afde..9ec3dd814 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -78,6 +78,11 @@ import { ExplorerPanel } from '../components/ExplorerPanel'import { SessionsSidebar } from '../components/SessionsSidebar'import type { SessionNodeInput } from '../lib/sessionList'import { UsageIndicator } from '../components/UsageIndicator'+import { PresenceLayer } from '../components/PresenceLayer'+import { Facepile } from '../components/Facepile'+import { PresenceNamePrompt } from '../components/PresenceNamePrompt'+import { connectPresence, reportProject } from '../state/presence'+import { nodeTravel, projectTravel } from '../lib/presenceTravel'import { RemoteSessionView } from './RemoteSessionView'import { RemoteAccessDialog } from '../components/RemoteAccessDialog'import { SshProjectDialog } from '../components/SshProjectDialog'@@ -722,6 +727,12 @@ export function Canvas() {// 2) Whenever the active project changes, load its canvas into React Flow.useEffect(() => {+ // Team presence: tell the hub which canvas we are on (this effect fires on load AND on every+ // tab switch). Peers only draw each other's cursors and node chips when the project matches —+ // each project is its own canvas with its own coordinate space. No project open (welcome+ // screen) → null, which is exactly what the early returns below mean. reportProject dedups,+ // and Canvas deliberately never READS the presence store (see the connectPresence effect).+ reportProject(activeProjectId || null)if (!activeProjectId) returnconst project = useProjects.getState().getProject(activeProjectId)if (!project) return@@ -2636,6 +2647,13 @@ export function Canvas() {useEffect(() => window.nodeTerminal.onFocusNode(focusNodeById), [focusNodeById])+ // Team presence: subscribe to the peer stream and announce ourselves ONCE per session ([] deps —+ // connectPresence is idempotent, but a second live connection whose teardown ran first would tear+ // the shared one down under the survivor). Canvas deliberately does NOT read the presence store:+ // only PresenceLayer / Facepile / PresenceChips subscribe, so a peer's 20 Hz cursor never+ // re-renders this component (docs/team-presence.md → UI).+ useEffect(() => connectPresence(), [])+// A browser guest's new-window (target=_blank / window.open) request → open another browser node// (never a real popup; main denies the real one) roped below/right of the source. Reads the// latest nodes via nodesRef so the deps stay []. Rope is display-only (controlEdges, not persisted).@@ -3553,6 +3571,39 @@ export function Canvas() {[commitActiveToStore, writeDisk])+ // ---- presence travel ("go to where my teammate is", from the facepile) ----+ // A peer may be working in a project we have CLOSED — the facepile shows off-project peers on+ // purpose. A closed project still lives in the store (`closed: true`), so `setActive` alone would+ // activate a canvas the tab bar does not show: route it through reopenProject instead. An+ // `unavailable` project (its file is unreadable) is not travelled to at all. See lib/presenceTravel.+ const travelToProject = useCallback(+ (projectId: string) => {+ const { projects, activeProjectId: active } = useProjects.getState()+ const travel = projectTravel(projects, active, projectId)+ if (travel.kind === 'reopen') reopenProject(travel.projectId)+ else if (travel.kind === 'switch') switchProject(travel.projectId)+ },+ [reopenProject, switchProject]+ )++ // Jump to the node a peer is focused on. focusNodeById already handles the same-project focus and+ // the switch to another OPEN project; the closed-project case has to reopen the tab first and let+ // the active-project effect finish the focus (pendingFocusRef, same mechanism as a notification).+ const travelToNode = useCallback(+ (nodeId: string) => {+ const { projects, activeProjectId: active } = useProjects.getState()+ const travel = nodeTravel(projects, active, nodeId)+ if (travel.kind === 'blocked') return+ if (travel.kind === 'reopen') {+ pendingFocusRef.current = nodeId+ reopenProject(travel.projectId)+ return+ }+ focusNodeById(nodeId)+ },+ [focusNodeById, reopenProject]+ )+// Permanently remove a project (from the "Recently closed" list): end every terminal's tmux// session, drop persisted agent status, tear down any SSH master, then delete it from disk.const deleteProject = useCallback(@@ -3928,9 +3979,18 @@ export function Canvas() {/><Controls showInteractive={false} position="bottom-left" /><UsageIndicator />+ {/* Peer cursors live INSIDE <ReactFlow>: PresenceLayer uses ViewportPortal ++ useReactFlow, which throw outside the provider — and cursors are flow coordinates. */}+ <PresenceLayer /><StatusAwareMiniMap onNodeDoubleClick={goToNode} /></ReactFlow>+ {/* Mounted unconditionally, even when we are alone: the facepile renders null with no peers,+ but it is also what prunes the presence store's face cache — gating its mount on a peer+ count would leak departed peers' faces forever (state/presence.ts → selectFaces). */}+ <Facepile onJump={travelToNode} onSwitchProject={travelToProject} />+ <PresenceNamePrompt />+{(!hasProjects || welcomeOpen) && (<WelcomeScreenonNewProject={() => {diff --git a/src/renderer/lib/presenceTravel.test.ts b/src/renderer/lib/presenceTravel.test.tsnew file mode 100644index 000000000..58cbbca98--- /dev/null+++ b/src/renderer/lib/presenceTravel.test.ts@@ -0,0 +1,63 @@+import { describe, expect, it } from 'vitest'+import { nodeTravel, projectTravel, type TravelProject } from './presenceTravel'++const projects: TravelProject[] = [+ { id: 'open', nodes: [{ id: 'n-open' }] },+ { id: 'active', nodes: [{ id: 'n-active' }] },+ { id: 'closed', closed: true, nodes: [{ id: 'n-closed' }] },+ { id: 'gone', closed: true, unavailable: true, nodes: [{ id: 'n-gone' }] }+]++describe('projectTravel', () => {+ it('does nothing for the project we are already on', () => {+ expect(projectTravel(projects, 'active', 'active')).toEqual({ kind: 'none' })+ })++ it('switches to another open project', () => {+ expect(projectTravel(projects, 'active', 'open')).toEqual({ kind: 'switch', projectId: 'open' })+ })++ it('reopens a closed project rather than activating an invisible tab', () => {+ expect(projectTravel(projects, 'active', 'closed')).toEqual({+ kind: 'reopen',+ projectId: 'closed'+ })+ })++ it('blocks an unavailable project (reopening it would show an empty canvas)', () => {+ expect(projectTravel(projects, 'active', 'gone')).toEqual({ kind: 'blocked' })+ })++ it('does nothing for a project we do not have', () => {+ expect(projectTravel(projects, 'active', 'nope')).toEqual({ kind: 'none' })+ })++ it('travels from the welcome screen (no active project)', () => {+ expect(projectTravel(projects, '', 'open')).toEqual({ kind: 'switch', projectId: 'open' })+ })+})++describe('nodeTravel', () => {+ it('needs no travel for a node on the active canvas', () => {+ expect(nodeTravel(projects, 'active', 'n-active')).toEqual({ kind: 'none' })+ })++ it('switches to the open project that owns the node', () => {+ expect(nodeTravel(projects, 'active', 'n-open')).toEqual({ kind: 'switch', projectId: 'open' })+ })++ it('reopens the closed project that owns the node', () => {+ expect(nodeTravel(projects, 'active', 'n-closed')).toEqual({+ kind: 'reopen',+ projectId: 'closed'+ })+ })++ it('blocks a node in an unavailable project', () => {+ expect(nodeTravel(projects, 'active', 'n-gone')).toEqual({ kind: 'blocked' })+ })++ it('does nothing for an unknown node', () => {+ expect(nodeTravel(projects, 'active', 'n-ghost')).toEqual({ kind: 'none' })+ })+})diff --git a/src/renderer/lib/presenceTravel.ts b/src/renderer/lib/presenceTravel.tsnew file mode 100644index 000000000..71ff3a965--- /dev/null+++ b/src/renderer/lib/presenceTravel.ts@@ -0,0 +1,60 @@+// Pure routing logic behind "go to where my teammate is" (the facepile's click, see+// components/Facepile.tsx). Kept out of Canvas because vitest runs in the node environment (no+// jsdom), so a React component cannot be unit-tested — this can.+//+// WHY THIS EXISTS AT ALL: the facepile deliberately shows peers who are NOT on our canvas, and a+// peer may well be working in a project we have CLOSED. A closed project is still in the projects+// store (`closed: true`) — it is only hidden from the tab bar — so a bare `setActive` would make an+// invisible project the active canvas. Travelling to it must go through `reopenProject` instead.+// And a project that is closed AND `unavailable` (its .nodeterm file is unreadable — folder moved+// or unmounted) must not be travelled to at all: reopening it would load an empty canvas, exactly+// the case Canvas already excludes from the welcome screen's "Recently closed" list.++/** The little the routing needs to know about a project. */+export interface TravelProject {+ id: string+ closed?: boolean+ unavailable?: boolean+ nodes: { id: string }[]+}++/**+ * What Canvas should do to land on a peer's canvas:+ * - `none` — nothing to do (already there, or we have no such project/node).+ * - `switch` — an open project: the normal tab switch.+ * - `reopen` — a closed project: restore its tab, then activate it.+ * - `blocked` — a project whose files we cannot read: travelling there would show an empty canvas.+ */+export type Travel =+ | { kind: 'none' }+ | { kind: 'blocked' }+ | { kind: 'switch'; projectId: string }+ | { kind: 'reopen'; projectId: string }++/** How to get to `targetId` from the project we are on (`activeProjectId`, '' on the welcome+ * screen). */+export function projectTravel(+ projects: readonly TravelProject[],+ activeProjectId: string,+ targetId: string+): Travel {+ const target = projects.find((p) => p.id === targetId)+ if (!target) return { kind: 'none' } // a canvas we do not have — the facepile marks it inert+ if (target.unavailable) return { kind: 'blocked' }+ if (target.id === activeProjectId && !target.closed) return { kind: 'none' }+ if (target.closed) return { kind: 'reopen', projectId: target.id }+ return { kind: 'switch', projectId: target.id }+}++/** How to get to the project that owns `nodeId` — the travel half of "jump to the node my teammate+ * is working in". `none` also covers "the node is on the canvas we are already on": there is no+ * travel to do, only a focus. */+export function nodeTravel(+ projects: readonly TravelProject[],+ activeProjectId: string,+ nodeId: string+): Travel {+ const owner = projects.find((p) => p.nodes.some((n) => n.id === nodeId))+ if (!owner) return { kind: 'none' }+ return projectTravel(projects, activeProjectId, owner.id)+}