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.

fix(presence): shallow-stable facepile selectors, reachable tooltip, honest actionability

enesa961af7d29e4
diff --git a/src/renderer/components/Facepile.tsx b/src/renderer/components/Facepile.tsx
index ccaf7fddd..c2d22cf7e 100644
--- a/src/renderer/components/Facepile.tsx
+++ b/src/renderer/components/Facepile.tsx
@@ -1,7 +1,7 @@
import { useShallow } from 'zustand/react/shallow'
-import { selectFaces, usePresence } from '../state/presence'
+import { selectFaces, selectOthers, usePresence } from '../state/presence'
import { useProjects } from '../state/projects'
-import { faceClickTarget, facepileEntries } from '../lib/facepile'
+import { faceClickTarget, facepileEntries, type FacepileFocus } from '../lib/facepile'
/**
* Who is connected, top-right, in their colors. THE ONE SURFACE THAT SHOWS OFF-PROJECT PEERS:
@@ -13,9 +13,11 @@ import { faceClickTarget, facepileEntries } from '../lib/facepile'
* only surfaces, so being invisible here would mean being invisible entirely.
*
* PERF: subscribes to `selectFaces`, NOT `selectOthers` — the face projection is cursor-immune
- * (see state/presence.ts), so a peer moving their mouse at 20 Hz does not re-render this. The
- * peer's `focus` is deliberately not part of a face either; it is read from the store at CLICK
- * time (getState — no subscription).
+ * (see state/presence.ts), so a peer moving their mouse at 20 Hz does not re-render this. `focus`
+ * IS subscribed, but only as a clientId → nodeId record of STRINGS: it decides whether a face is
+ * clickable at all (a peer on our own canvas is only worth clicking when they have a node to
+ * centre on), and it changes when a teammate moves between nodes — not at cursor rate. The click
+ * handler still reads focus live from the store (it can move between render and click).
*
* Renders nothing when you are alone: presence is silent, and costs nothing, solo.
*/
@@ -29,27 +31,50 @@ export function Facepile({
// useShallow: the selector derives a new array each call (its ELEMENTS are cached — that is what
// makes cursor traffic invisible here). See PresenceLayer for the same pattern.
const faces = usePresence(useShallow(selectFaces))
+ // Where each peer is working. A record of strings, so useShallow can actually compare it.
+ const focus = usePresence(
+ useShallow((s): FacepileFocus => {
+ const map: Record<number, string | null> = {}
+ for (const p of selectOthers(s)) map[p.clientId] = p.focus ?? null
+ return map
+ })
+ )
const activeProjectId = useProjects((s) => s.activeProjectId)
- // Only id+name: recomputing on every projects-store write is fine, re-rendering on one is not.
- const projects = useProjects(useShallow((s) => s.projects.map((p) => ({ id: p.id, name: p.name }))))
+ // id → name, a record of STRINGS: useShallow compares the values with Object.is, so this
+ // re-renders only when a project is added/removed/renamed — not on every projects-store write
+ // (a node commit, a rename of some other project's node, dirty-marking). An array of freshly
+ // built {id,name} objects would NOT be stable: Object.is on two new objects is always false.
+ const projects = useProjects(
+ useShallow((s): Record<string, string> => {
+ const names: Record<string, string> = {}
+ for (const p of s.projects) names[p.id] = p.name
+ return names
+ })
+ )
if (faces.length === 0) return null
- const entries = facepileEntries(faces, projects, activeProjectId || null)
+ const entries = facepileEntries(faces, projects, activeProjectId || null, focus)
return (
<div className="presence-facepile">
{entries.map((e) => (
<button
key={e.clientId}
+ type="button"
className={`presence-face${e.away ? ' presence-face--away' : ''}`}
style={{ background: e.color }}
title={e.title}
- disabled={!e.actionable}
+ // aria-disabled, NOT `disabled`: Chromium (Electron and the browser edition alike)
+ // suppresses mouse events on a disabled button, so its `title` never shows — and the
+ // tooltip ("Ada — on a canvas you do not have") is the whole point exactly there.
+ // Screen readers still announce it as unavailable; the click is a no-op.
+ aria-disabled={!e.actionable}
onClick={() => {
- // Read focus live: it is not part of a face (see PERF above), and by click time the
- // peer may well have moved to another node anyway.
- const focus = usePresence.getState().peers[e.clientId]?.focus ?? null
- const target = faceClickTarget(e, focus)
+ if (!e.actionable) return
+ // Read focus live: the subscribed map above is what decided actionability, but by
+ // click time the peer may well have moved to another node.
+ const live = usePresence.getState().peers[e.clientId]?.focus ?? null
+ const target = faceClickTarget(e, live)
if (target?.kind === 'node') onJump(target.nodeId)
else if (target?.kind === 'project') onSwitchProject(target.projectId)
}}
diff --git a/src/renderer/lib/facepile.test.ts b/src/renderer/lib/facepile.test.ts
index 8e3d95000..226e7cec1 100644
--- a/src/renderer/lib/facepile.test.ts
+++ b/src/renderer/lib/facepile.test.ts
@@ -14,13 +14,13 @@ function face(clientId: number, over: Partial<PeerFace> = {}): PeerFace {
}
}
-const PROJECTS = [
- { id: 'web', name: 'web' },
- { id: 'api', name: 'api' }
-]
+const PROJECTS = { web: 'web', api: 'api' }
-const only = (faces: PeerFace[], active: string | null): FacepileEntry =>
- facepileEntries(faces, PROJECTS, active)[0]
+const only = (
+ faces: PeerFace[],
+ active: string | null,
+ focus: Record<number, string | null> = {}
+): FacepileEntry => facepileEntries(faces, PROJECTS, active, focus)[0]
describe('initials', () => {
it('takes the first letter of the first two words', () => {
@@ -37,12 +37,21 @@ describe('initials', () => {
describe('facepileEntries', () => {
it('shows a peer on this canvas undimmed, labelled by name alone', () => {
- const e = only([face(8, { name: 'Ada' })], 'web')
+ const e = only([face(8, { name: 'Ada' })], 'web', { 8: 'term-1' })
expect(e.away).toBe(false)
expect(e.label).toBe('Ada')
expect(e.initials).toBe('AD')
expect(e.projectName).toBe('web')
- expect(e.actionable).toBe(true)
+ expect(e.actionable).toBe(true) // clicking centers their node
+ })
+
+ it('does not pretend a peer on this canvas focused on nothing is clickable', () => {
+ // The only thing a click could resolve to is "switch to the project you are already on".
+ const e = only([face(8, { name: 'Ada' })], 'web', {})
+ expect(e.away).toBe(false)
+ expect(e.projectName).toBe('web')
+ expect(e.actionable).toBe(false)
+ expect(faceClickTarget(e, null)).toBeNull()
})
it('shows an off-project peer dimmed and labelled with their project ("Ada · api")', () => {
@@ -83,6 +92,16 @@ describe('facepileEntries', () => {
expect(only([face(8)], 'web').isPhone).toBe(false)
})
+ it('does not stutter "phone" in the title when the name already says it', () => {
+ // The hub's default name for a phone peer IS "Phone" — "Phone · phone" is noise.
+ expect(only([face(8, { name: 'Phone', kind: 'phone' })], 'web').title).toBe('Phone')
+ expect(only([face(8, { name: "Ada's iPhone", kind: 'phone' })], 'web').title).toBe(
+ "Ada's iPhone"
+ )
+ // A named phone still gets the qualifier — that is the only hint it has no cursor.
+ expect(only([face(8, { name: 'Ada', kind: 'phone' })], 'web').title).toBe('Ada · phone')
+ })
+
it('carries the peer color through untouched (palette-sanitized on the wire)', () => {
expect(only([face(8, { color: PRESENCE_COLORS[3] })], 'web').color).toBe(PRESENCE_COLORS[3])
})
@@ -95,14 +114,23 @@ describe('facepileEntries', () => {
describe('faceClickTarget', () => {
const entry = (over: Partial<FacepileEntry> = {}): FacepileEntry =>
- ({ projectId: 'api', actionable: true, ...over }) as FacepileEntry
+ ({ projectId: 'api', away: true, actionable: true, ...over }) as FacepileEntry
it('jumps to the peer’s focused node when they have one (focusNodeById switches projects)', () => {
expect(faceClickTarget(entry(), 'term-1')).toEqual({ kind: 'node', nodeId: 'term-1' })
})
it('falls back to their project when they are focused on nothing', () => {
- expect(faceClickTarget(entry(), null)).toEqual({ kind: 'project', projectId: 'api' })
+ expect(faceClickTarget(entry({ away: true }), null)).toEqual({
+ kind: 'project',
+ projectId: 'api'
+ })
+ })
+
+ it('goes nowhere for a peer on the canvas we are already on with no focused node', () => {
+ // Focus is read live at click time, so it can go null between render and click — the click
+ // must then be inert rather than "switch to the project you are already on".
+ expect(faceClickTarget(entry({ away: false, projectId: 'web' }), null)).toBeNull()
})
it('goes nowhere for a peer we cannot follow (unknown / no project)', () => {
diff --git a/src/renderer/lib/facepile.ts b/src/renderer/lib/facepile.ts
index 02d1e231b..2f77a8c75 100644
--- a/src/renderer/lib/facepile.ts
+++ b/src/renderer/lib/facepile.ts
@@ -11,11 +11,20 @@
import type { PeerFace } from '../state/presence'
-/** The minimum a project has to be for the facepile: an id and a display name (structural, so the
- * helper stays testable without the whole Project type). */
-export interface FacepileProject {
- id: string
- name: string
+/** All the facepile needs to know about the workspace: project id → display name. A flat record of
+ * STRINGS on purpose — the component derives it straight out of the projects store under
+ * `useShallow`, and a record of primitives is the only projection that is genuinely
+ * shallow-stable (an array of freshly built {id,name} objects compares unequal every time). */
+export type FacepileProjects = Readonly<Record<string, string>>
+
+/** clientId → the node that peer is focused on (null = nowhere). Focus changes when a teammate
+ * clicks into another node — not at cursor rate — so it is cheap for the facepile to know. */
+export type FacepileFocus = Readonly<Record<number, string | null>>
+
+/** True when the qualifier " · phone" would only repeat what the name already says (the hub's
+ * default name for a cursorless peer IS "Phone"). */
+function nameSaysPhone(name: string): boolean {
+ return /phone/i.test(name)
}
export interface FacepileEntry {
@@ -34,8 +43,10 @@ export interface FacepileEntry {
/** "Ada · api" for a known off-project peer, plain "Ada" otherwise (NEVER "Ada · undefined"). */
label: string
title: string
- /** True when we can actually follow them (we have their project). Clicking a peer whose project
- * is not in our workspace could only fail, so their avatar is inert. */
+ /** True when a click actually takes us somewhere: we have their project (a peer on a canvas we
+ * do not have could only fail) AND there is somewhere to go — for a peer on the canvas we are
+ * already on that means a focused node, since "switch to this project" would be a no-op.
+ * Everyone still renders; a non-actionable face is just inert. */
actionable: boolean
}
@@ -56,24 +67,27 @@ export function initials(name: string): string {
/**
* Project the cursor-immune faces (selectFaces) into what the facepile draws. `activeProjectId`
* is the canvas WE are on — null/'' on the welcome screen, where everyone is "away" but still
- * reachable (clicking a teammate is a legitimate way off the welcome screen).
+ * reachable (clicking a teammate is a legitimate way off the welcome screen). `focus` says where
+ * each peer is working: it is what makes a peer on OUR canvas worth clicking (there is a node to
+ * centre on) — without it the click could only re-open the project we are already in.
*/
export function facepileEntries(
faces: readonly PeerFace[],
- projects: readonly FacepileProject[],
- activeProjectId: string | null
+ projects: FacepileProjects,
+ activeProjectId: string | null,
+ focus: FacepileFocus = {}
): FacepileEntry[] {
const active = activeProjectId || null
- const names = new Map(projects.map((p) => [p.id, p.name]))
return faces.map((f) => {
- const projectName = f.projectId ? (names.get(f.projectId) ?? null) : null
+ const projectName = f.projectId ? (projects[f.projectId] ?? null) : null
const away = f.projectId !== active
- // Following a peer means opening their canvas — only possible for a project we have.
- const actionable = projectName !== null
+ // Following a peer means opening their canvas (only possible for a project we have) or
+ // centering their node. On our own canvas only the node is left — see FacepileEntry.actionable.
+ const actionable = projectName !== null && (away || !!focus[f.clientId])
const label = away && projectName ? `${f.name} · ${projectName}` : f.name
const isPhone = f.kind === 'phone'
const where = away
- ? actionable
+ ? projectName
? `${label} (click to go there)`
: f.projectId
? `${f.name} — on a canvas you do not have`
@@ -89,7 +103,7 @@ export function facepileEntries(
projectId: f.projectId,
projectName,
label,
- title: isPhone ? `${where} · phone` : where,
+ title: isPhone && !nameSaysPhone(f.name) ? `${where} · phone` : where,
actionable
}
})
@@ -106,6 +120,8 @@ export function facepileEntries(
export function faceClickTarget(entry: FacepileEntry, focus: string | null): FaceTarget {
if (!entry.actionable) return null
if (focus) return { kind: 'node', nodeId: focus }
- if (entry.projectId) return { kind: 'project', projectId: entry.projectId }
+ // No node to centre on: all that is left is opening their canvas — which is nowhere at all when
+ // it is the canvas we are on (focus can go null between render and click, so re-check here).
+ if (entry.away && entry.projectId) return { kind: 'project', projectId: entry.projectId }
return null
}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index ac9ab4dc9..edf65e72f 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -5262,7 +5262,9 @@ body,
justify-content: center;
}
-.presence-face:disabled {
+/* Non-actionable (a peer on a canvas we do not have, or one sitting on ours with no node focused):
+ inert, but NOT the `disabled` attribute — Chromium eats mouse events on those, tooltip and all. */
+.presence-face[aria-disabled='true'] {
cursor: default;
}
@@ -5274,7 +5276,7 @@ body,
overflow: visible;
}
-.presence-face--away:hover:enabled {
+.presence-face--away:not([aria-disabled='true']):hover {
opacity: 0.75;
}