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.

perf(terminal): stop xterm drawing under the kanban board; count the Omni board as covering

Brandon Bridges7af76d08edd4
diff --git a/CLAUDE.md b/CLAUDE.md
index f98b2dd0d..2487903a9 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -9071,6 +9071,19 @@ one attribute with two owners is a race over who clears it. The claim is refcoun
mount the incoming view before unmounting the outgoing one, and a plain set/clear pair would let
that unmount erase the live view's claim.
+**The board gate does not stop xterm; `terminal/board-render-pause.ts` does.** CSS reaches the glows,
+not the terminals: xterm pauses only on its own GEOMETRIC IntersectionObserver, and a node under
+the board still intersects. MEASURED (audit GT-6, dev, 12 streaming terminals): board open 36.5 %
+GPU vs 0.0 % over silent terminals, and `visibility: hidden` on the canvas 35.5 % — no help. Each
+TerminalNode wraps its RenderService's `_handleIntersectionChange` so xterm is told "not
+intersecting" while `boardOpen` (Omni included) is up and the node is not the focus-mode node (the
+focus surface, z 40, sits above the board, z 25); uncovering replays the real entry through xterm's
+own resume and then `fullRepaint`. Parsing never stops, so nothing is lost. Two rules: never fold
+the board into `reportVisible` / the WebGL budget's visibility (that verdict drives hibernation and
+the offscreen teardown — the board would put the very sessions it shows to sleep), and any other
+"is the board up" predicate must OR in `isGlobalKanbanOpen()` (`boardCoversCanvas` missed the Omni
+board until GT-6, the same omission 12564a20 fixed for focus restore).
+
**Specificity is the quiet failure mode in all of this, and it has already happened twice.** The
three glows carry their own `animation:` shorthand, which RESETS `animation-play-state` — so
inheriting the variable does nothing for them and every gate has to name them explicitly. A first
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 796c7c4dc..8d810e3f9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1348,6 +1348,10 @@ bite most often:
- macOS memory pressure comes from the kernel's level (`onKernelPressure` in
`core/memory-pressure.ts`), fired on escalations only. Never re-fire it on a held level, and
never route it through `hostMemReader`/`MemInfo`: the session reaper shares that reader.
+- A terminal under the kanban board must not draw. CSS can't stop xterm; its render pause is
+ `terminal/board-render-pause.ts`. Every "is the board up" check includes the Omni board
+ (`isGlobalKanbanOpen()`), and the board never feeds the visibility verdict that drives
+ hibernation and the WebGL budget.
**SSH projects on Windows** run over an in-process transport (`src/core/remote-ssh/native/`),
not the ssh binary. If you add an ssh call site, route it through `useNativeSsh()` like the
diff --git a/src/renderer/canvas/SharedGlyphLayer.test.ts b/src/renderer/canvas/SharedGlyphLayer.test.ts
index ca8bd2436..14d52e897 100644
--- a/src/renderer/canvas/SharedGlyphLayer.test.ts
+++ b/src/renderer/canvas/SharedGlyphLayer.test.ts
@@ -11,7 +11,11 @@ import { fakeTerm, recordingAtlas, recordingHandle } from '../glyphgrid/addon-fa
import { FLAG_CURSOR, readCell } from '../glyphgrid/cells'
import type { GridHandle } from '../glyphgrid/engine'
import { createFrameLoop, type FrameLoop, type FrameLoopHost } from '../glyphgrid/frame-driver'
+import { useProjects } from '../state/projects'
+import { useSettings } from '../state/settings'
+import { useViewMode } from '../state/viewMode'
import {
+ boardCoversCanvas,
createBoardFrameGate,
createCellRebuildGuard,
createContextLossPolicy,
@@ -1238,6 +1242,53 @@ describe('createPixelRatioWatcher', () => {
* that a stopped loop really stops (a wake cannot resurrect it) and that a reopened canvas really
* draws, and both of those are the frame driver's contract, not this file's.
*/
+describe('boardCoversCanvas', () => {
+ // The predicate the board frame gate and the blink clock read. It must say "covered" for BOTH
+ // full-page boards, because Canvas's `kanbanOpen` does: the Omni board was missing (audit GT-6),
+ // so the shared canvas kept drawing under the all-projects board.
+ const setOmni = (enabled: boolean): void => {
+ useSettings.setState((s) => ({ settings: { ...s.settings, omniKanbanEnabled: enabled } }))
+ }
+ beforeEach(() => {
+ useViewMode.setState({ viewByProject: {}, defaultView: 'canvas', globalKanban: false })
+ useProjects.setState({ activeProjectId: 'p1' })
+ setOmni(false)
+ })
+
+ it('is false on the canvas', () => {
+ expect(boardCoversCanvas()).toBe(false)
+ })
+
+ it('is true for the active project’s own board', () => {
+ useViewMode.getState().setView('p1', 'kanban')
+ expect(boardCoversCanvas()).toBe(true)
+ })
+
+ it('is true for the Omni (all-projects) board', () => {
+ setOmni(true)
+ useViewMode.setState({ globalKanban: true })
+ expect(boardCoversCanvas()).toBe(true)
+ })
+
+ it('is true for the Omni board with no active project — Canvas’s Omni term needs none either', () => {
+ setOmni(true)
+ useViewMode.setState({ globalKanban: true })
+ useProjects.setState({ activeProjectId: '' })
+ expect(boardCoversCanvas()).toBe(true)
+ })
+
+ it('ignores a stale persisted Omni flag while the feature is off', () => {
+ useViewMode.setState({ globalKanban: true })
+ expect(boardCoversCanvas()).toBe(false)
+ })
+
+ it('is false with no active project even when the global default view is the board', () => {
+ useViewMode.setState({ defaultView: 'kanban' })
+ useProjects.setState({ activeProjectId: '' })
+ expect(boardCoversCanvas()).toBe(false)
+ })
+})
+
describe('createBoardFrameGate', () => {
function harness(): {
host: FrameLoopHost
diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsx
index b13132d88..c13a4eb6e 100644
--- a/src/renderer/canvas/SharedGlyphLayer.tsx
+++ b/src/renderer/canvas/SharedGlyphLayer.tsx
@@ -55,7 +55,7 @@ import { cellSnapEnabled, createWebgl2GL, setCellSnap } from '../glyphgrid/gl-we
import { createCanvasRasterizer, type AtlasPageHealth } from '../glyphgrid/raster'
import { useProjects } from '../state/projects'
import { useSettings } from '../state/settings'
-import { useViewMode, viewFor } from '../state/viewMode'
+import { isGlobalKanbanOpen, useViewMode, viewFor } from '../state/viewMode'
import { readLocal } from '../lib/localStore'
/** Atlas page edge, in DEVICE pixels. 2048 (not Phase 0's 1024) because the atlas cells are
@@ -1547,8 +1547,15 @@ export function setSharedGlyphCamera(cam: Camera): void {
* predicate Canvas derives `kanbanOpen` from, and it has to stay literally the same one — two
* answers to "is the board up" that can disagree is how a canvas ends up not drawing for a reason
* nobody can find.
+ *
+ * Including the OMNI board (`isGlobalKanbanOpen`, which already folds in the feature flag): it is
+ * the same opaque full-page overlay, and Canvas's `kanbanOpen` is `globalKanbanOpen ||
+ * perProjectKanbanOpen`. Leaving it out kept the shared canvas drawing under the all-projects
+ * board — the same omission 12564a20 fixed for the window-activation focus restore (audit GT-6).
+ * Like Canvas's own term, Omni needs no active project.
*/
export function boardCoversCanvas(): boolean {
+ if (isGlobalKanbanOpen()) return true
const { activeProjectId } = useProjects.getState()
return !!activeProjectId && viewFor(useViewMode.getState(), activeProjectId) === 'kanban'
}
@@ -2243,7 +2250,14 @@ export function SharedGlyphLayer(): JSX.Element {
// The two gates that can move without the board moving: the blink SETTING and which terminal
// holds focus. Both are change-gated inside `sync`.
const unsubBlinkTarget = subscribeCursorBlinkTarget(() => clock.sync())
- const unsubBlinkSetting = useSettings.subscribe(() => clock.sync())
+ // The settings store moves the board too (the Omni feature flag gates `globalKanban`), so this
+ // one subscription re-syncs the gate as well — `syncBoard` below, inlined because it is
+ // declared after; both members are change-gated, so a settings write that moved neither is
+ // two comparisons.
+ const unsubBlinkSetting = useSettings.subscribe(() => {
+ gate.sync()
+ clock.sync()
+ })
// ...and the cursor MOVING, which is not a gate at all: it holds the cursor solid and starts
// the period over, exactly as xterm does while you type. Its own channel, because `sync` is
// deliberately a no-op while the interval is already running.
diff --git a/src/renderer/nodes/TerminalNode.global-kanban.test.ts b/src/renderer/nodes/TerminalNode.global-kanban.test.ts
index 3de32bb65..045f96cdd 100644
--- a/src/renderer/nodes/TerminalNode.global-kanban.test.ts
+++ b/src/renderer/nodes/TerminalNode.global-kanban.test.ts
@@ -16,3 +16,34 @@ describe('TerminalNode global kanban sizing', () => {
expect(boardOpen).toContain('omniKanbanEnabled')
})
})
+
+describe('TerminalNode board render pause wiring', () => {
+ // The same `boardOpen` (Omni included) also stops xterm DRAWING under the board (audit GT-6:
+ // 36.5 % GPU board-open over streaming terminals vs 0.0 % over silent ones). The decision itself
+ // is unit-tested in `terminal/board-render-pause.test.ts`; this pins that the node feeds it the
+ // right inputs and re-syncs it on both things it reads.
+ it('pauses on the board flag, except for the focus-mode node that sits above the board', () => {
+ expect(TERMINAL_SRC).toContain('covered: () => boardOpenRef.current && focusedNodeId() !== id')
+ expect(TERMINAL_SRC).toContain('onUncover: fullRepaint')
+ })
+
+ it('re-syncs after the board flag moves and when focus mode moves', () => {
+ const effect = TERMINAL_SRC.slice(TERMINAL_SRC.indexOf('boardOpenRef.current = boardOpen'))
+ const body = effect.slice(0, effect.indexOf('}, [boardOpen])'))
+ // After the ref write, so the pause reads the new value.
+ expect(body.indexOf('boardPauseRef.current?.sync()')).toBeGreaterThan(0)
+ const focus = TERMINAL_SRC.slice(TERMINAL_SRC.indexOf('subscribeFocusedNode(() => {'))
+ expect(focus.slice(0, focus.indexOf('[]'))).toContain('boardPauseRef.current?.sync()')
+ })
+
+ it('is removed by the run that installed it, before a park keeps the xterm', () => {
+ expect(TERMINAL_SRC).toContain('boardPause?.dispose()')
+ })
+
+ it('never feeds the visibility verdict (budget, hibernation, offscreen teardown)', () => {
+ const report = TERMINAL_SRC.slice(TERMINAL_SRC.indexOf('const reportVisible = (visible: boolean): void => {'))
+ const body = report.slice(0, report.indexOf('visibilityReportRef.current = reportVisible'))
+ expect(body).not.toContain('boardOpen')
+ expect(body).not.toContain('boardPause')
+ })
+})
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 704aa4059..647719557 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -251,6 +251,7 @@ import { useTerminalSearch } from '../terminal/useTerminalSearch'
import { useCopyFeedback } from '../terminal/useCopyFeedback'
import { pasteWithImageReceipt } from '../terminal/image-paste-confirm'
import { usePasteReceipt } from '../terminal/usePasteReceipt'
+import { installBoardRenderPause, type BoardRenderPause } from '../terminal/board-render-pause'
import { ContextMeter } from '../components/ContextMeter'
import { isZoomModifierHeld } from '../lib/zoomModifier'
import { HoverGuard } from './HoverGuard'
@@ -1559,6 +1560,11 @@ export function TerminalNode({
viewFor(s, useProjects.getState().activeProjectId ?? '') === 'kanban'
)
const boardOpenRef = useRef(boardOpen)
+ // The live session's board render pause (set by the lifecycle effect): while the board covers
+ // this node, xterm stops DRAWING but keeps parsing (audit GT-6: 36.5 % GPU board-open over
+ // streaming terminals vs 0.0 % over silent ones). Synced from the two effects that already re-run
+ // on what "covered" reads — the board flag and focus mode. See `terminal/board-render-pause.ts`.
+ const boardPauseRef = useRef<BoardRenderPause | null>(null)
const dwellRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const [showColors, setShowColors] = useState(false)
const [armed, setArmed] = useState(true)
@@ -3408,6 +3414,20 @@ export function TerminalNode({
})
}
}
+ // Board render pause — per effect run, NOT through `cleanups`: a park keeps the xterm but this
+ // run's closures die with it, so the wrapper is removed by this run's cleanup and the adopting
+ // run installs its own (the module also refuses to stack a second layer). Installed after
+ // open/reattach because the render service only exists once the terminal is open.
+ // Covered = the board is up AND this node is not the focus-mode node: the focus surface (z 40)
+ // sits ABOVE the board (z 25), so a node focused before the board opened is still on screen.
+ // Deliberately NOT folded into `reportVisible`: that verdict feeds the WebGL budget,
+ // hibernation and the offscreen teardown, and the board must not hibernate the sessions it
+ // shows cards for (audit GT-6, refuted fix shapes).
+ const boardPause = installBoardRenderPause(term as unknown as Parameters<typeof installBoardRenderPause>[0], {
+ covered: () => boardOpenRef.current && focusedNodeId() !== id,
+ onUncover: fullRepaint
+ })
+ boardPauseRef.current = boardPause
// Cmd+C (mac) / Ctrl+Shift+C (Linux, Windows) / Ctrl+Insert copy the terminal selection — xterm
// renders to a canvas, so the DOM-selection copy used elsewhere can't see it. Plain Ctrl+C is
@@ -5141,6 +5161,10 @@ export function TerminalNode({
searchAddonRef.current = null
if (applyFitRef.current === applyFit) applyFitRef.current = null
if (fullRepaintRef.current === fullRepaint) fullRepaintRef.current = null
+ // Hand xterm its own pause back before the terminal is parked or disposed: a parked xterm
+ // must not carry a wrapper whose `covered` reads a dead mount's refs.
+ boardPause?.dispose()
+ if (boardPauseRef.current === boardPause) boardPauseRef.current = null
// Free the GPU context on unmount (park or teardown) either way, and unregister from the
// budget coordinator (which releases any held grant + cancels its timers). The park path must
// keep releasing it as it always has (contexts are capped ~16, and a parked terminal is
@@ -5605,12 +5629,22 @@ export function TerminalNode({
useEffect(() => {
boardOpenRef.current = boardOpen
applyFitRef.current?.()
+ // …and stop (or resume) drawing under it. After the ref write: the pause reads it.
+ boardPauseRef.current?.sync()
}, [boardOpen])
// Focus mode engaged/exited anywhere on the canvas: re-run our size vote (applyFit reads
// focusedNodeId() live). Mount-stable — the focused-node subscription above only re-renders
// the node whose own membership flipped, and every OTHER terminal is the one being covered.
- useEffect(() => subscribeFocusedNode(() => applyFitRef.current?.()), [])
+ // The board pause reads focus too (a focus-mode node stays visible over the board).
+ useEffect(
+ () =>
+ subscribeFocusedNode(() => {
+ applyFitRef.current?.()
+ boardPauseRef.current?.sync()
+ }),
+ []
+ )
const toggleCollapse = () => setNodes((ns) => toggleCollapsed(ns as CanvasNode[], [id]))
diff --git a/src/renderer/terminal/board-render-pause.test.ts b/src/renderer/terminal/board-render-pause.test.ts
new file mode 100644
index 000000000..5b5b9b097
--- /dev/null
+++ b/src/renderer/terminal/board-render-pause.test.ts
@@ -0,0 +1,193 @@
+import { describe, expect, it } from 'vitest'
+import {
+ installBoardRenderPause,
+ renderPaused,
+ type IntersectionVerdict,
+ type PausableTerminal
+} from './board-render-pause'
+
+/**
+ * A structural fake of xterm 5.5's RenderService pause machinery — the same three fields and the
+ * same `_handleIntersectionChange` body as `node_modules/@xterm/xterm/src/browser/services/
+ * RenderService.ts`, with the method on the PROTOTYPE (as in the real class) and the observer
+ * reaching it through `this.`, which is what makes an instance property shadow it.
+ */
+class FakeRenderService {
+ _isPaused = false
+ _needsFullRefresh = false
+ /** Rows actually handed to the renderer — the work the board pause exists to stop. */
+ painted = 0
+ /** Full refreshes the resume path flushed. */
+ resumes = 0
+ _handleIntersectionChange(entry: IntersectionVerdict): void {
+ this._isPaused = entry.isIntersecting === undefined ? entry.intersectionRatio === 0 : !entry.isIntersecting
+ if (!this._isPaused && this._needsFullRefresh) {
+ this.resumes++
+ this.refreshRows()
+ this._needsFullRefresh = false
+ }
+ }
+ refreshRows(): void {
+ if (this._isPaused) {
+ this._needsFullRefresh = true
+ return
+ }
+ this.painted++
+ }
+ /** The geometric IntersectionObserver delivering an entry. */
+ observe(intersecting: boolean): void {
+ this._handleIntersectionChange({ isIntersecting: intersecting, intersectionRatio: intersecting ? 1 : 0 })
+ }
+}
+
+function fake(): { term: PausableTerminal; rs: FakeRenderService } {
+ const rs = new FakeRenderService()
+ return { term: { _core: { _renderService: rs as never } }, rs }
+}
+
+describe('renderPaused', () => {
+ it('pauses when covered, when off screen, and when both', () => {
+ expect(renderPaused(false, true)).toBe(false)
+ expect(renderPaused(true, true)).toBe(true)
+ expect(renderPaused(false, false)).toBe(true)
+ expect(renderPaused(true, false)).toBe(true)
+ })
+})
+
+describe('installBoardRenderPause', () => {
+ it('stops painting while covered and keeps the refresh owed (nothing is lost)', () => {
+ const { term, rs } = fake()
+ let covered = false
+ const pause = installBoardRenderPause(term, { covered: () => covered })!
+ rs.refreshRows()
+ expect(rs.painted).toBe(1)
+ covered = true
+ pause.sync()
+ expect(rs._isPaused).toBe(true)
+ // Streaming output while the board is up: every refresh is deferred, none painted.
+ for (let i = 0; i < 50; i++) rs.refreshRows()
+ expect(rs.painted).toBe(1)
+ expect(rs._needsFullRefresh).toBe(true)
+ })
+
+ it('resumes through xterm’s own flush on uncover — one full refresh — and asks for the guaranteed repaint', () => {
+ const { term, rs } = fake()
+ let covered = true
+ let repaints = 0
+ const pause = installBoardRenderPause(term, { covered: () => covered, onUncover: () => repaints++ })!
+ rs.refreshRows()
+ rs.refreshRows()
+ covered = false
+ pause.sync()
+ expect(rs._isPaused).toBe(false)
+ expect(rs.resumes).toBe(1)
+ expect(rs.painted).toBe(1)
+ expect(repaints).toBe(1)
+ })
+
+ it('pauses at install when mounted under a board that is already up', () => {
+ const { term, rs } = fake()
+ installBoardRenderPause(term, { covered: () => true })
+ expect(rs._isPaused).toBe(true)
+ })
+
+ it('an observer delivery while covered cannot unpause (a node mounting under the board)', () => {
+ const { term, rs } = fake()
+ installBoardRenderPause(term, { covered: () => true })
+ rs.observe(true) // xterm's initial "intersecting" entry
+ expect(rs._isPaused).toBe(true)
+ })
+
+ it('uncovering a terminal that went off screen meanwhile stays paused, with no repaint', () => {
+ const { term, rs } = fake()
+ let covered = true
+ let repaints = 0
+ const pause = installBoardRenderPause(term, { covered: () => covered, onUncover: () => repaints++ })!
+ rs.observe(false)
+ covered = false
+ pause.sync()
+ expect(rs._isPaused).toBe(true)
+ expect(repaints).toBe(0)
+ rs.observe(true) // panned back into view: xterm's own resume, untouched
+ expect(rs._isPaused).toBe(false)
+ })
+
+ it('a terminal re-adopted off screen (already paused, no new observer delivery) stays paused through a cover/uncover', () => {
+ // Park re-adopt: the detached element's observer reported not-intersecting BEFORE install,
+ // and reattached still off screen it has nothing new to deliver during the wrapper's life.
+ const { term, rs } = fake()
+ rs.observe(false)
+ let covered = false
+ let repaints = 0
+ const pause = installBoardRenderPause(term, { covered: () => covered, onUncover: () => repaints++ })!
+ covered = true
+ pause.sync()
+ covered = false
+ pause.sync()
+ expect(rs._isPaused).toBe(true)
+ expect(repaints).toBe(0)
+ for (let i = 0; i < 10; i++) rs.refreshRows()
+ expect(rs.painted).toBe(0) // streaming output off screen: nothing drawn
+ pause.dispose()
+ expect(rs._isPaused).toBe(true) // dispose hands back the real (off-screen) geometry
+ rs.observe(true) // panned into view: xterm's own resume
+ expect(rs._isPaused).toBe(false)
+ expect(rs.resumes).toBe(1)
+ })
+
+ it('leaves xterm’s geometric pause alone when nothing covers it', () => {
+ const { term, rs } = fake()
+ installBoardRenderPause(term, { covered: () => false })
+ rs.observe(false)
+ expect(rs._isPaused).toBe(true)
+ rs.observe(true)
+ expect(rs._isPaused).toBe(false)
+ })
+
+ it('sync is change-gated: no repeated replay or repaint for an unmoved board', () => {
+ const { term, rs } = fake()
+ let covered = false
+ let repaints = 0
+ const pause = installBoardRenderPause(term, { covered: () => covered, onUncover: () => repaints++ })!
+ pause.sync()
+ pause.sync()
+ expect(repaints).toBe(0)
+ covered = true
+ pause.sync()
+ covered = false
+ pause.sync()
+ pause.sync()
+ expect(repaints).toBe(1)
+ expect(rs._isPaused).toBe(false)
+ })
+
+ it('dispose restores the prototype method and hands back the real geometry', () => {
+ const { term, rs } = fake()
+ const pause = installBoardRenderPause(term, { covered: () => true })!
+ expect(Object.prototype.hasOwnProperty.call(rs, '_handleIntersectionChange')).toBe(true)
+ pause.dispose()
+ expect(Object.prototype.hasOwnProperty.call(rs, '_handleIntersectionChange')).toBe(false)
+ expect(rs._isPaused).toBe(false)
+ pause.dispose() // idempotent
+ pause.sync() // inert
+ expect(rs._isPaused).toBe(false)
+ })
+
+ it('a second install (park re-adopt) replaces the first instead of stacking a wrapper', () => {
+ const { term, rs } = fake()
+ let firstReads = 0
+ installBoardRenderPause(term, { covered: () => (firstReads++, true) })
+ const second = installBoardRenderPause(term, { covered: () => false })!
+ firstReads = 0
+ rs.observe(true)
+ expect(firstReads).toBe(0) // the stale controller's predicate is no longer in the chain
+ expect(rs._isPaused).toBe(false)
+ second.dispose()
+ expect(Object.prototype.hasOwnProperty.call(rs, '_handleIntersectionChange')).toBe(false)
+ })
+
+ it('returns null and changes nothing when the private method is missing', () => {
+ expect(installBoardRenderPause({}, { covered: () => true })).toBeNull()
+ expect(installBoardRenderPause({ _core: { _renderService: {} } }, { covered: () => true })).toBeNull()
+ })
+})
diff --git a/src/renderer/terminal/board-render-pause.ts b/src/renderer/terminal/board-render-pause.ts
new file mode 100644
index 000000000..cd2d81970
--- /dev/null
+++ b/src/renderer/terminal/board-render-pause.ts
@@ -0,0 +1,163 @@
+/**
+ * Stop a terminal DRAWING while the kanban board covers it, without stopping it PARSING.
+ *
+ * WHY. The canvas stays mounted under the board on purpose (`display: none` would 0x0-resize every
+ * terminal into a tmux SIGWINCH — see the kanban section of CLAUDE.md), and nothing told xterm it
+ * was covered: its only pause is its own GEOMETRIC IntersectionObserver (`RenderService`), and a
+ * node under an opaque overlay still intersects the viewport. MEASURED (audit GT-6, dev build, 12
+ * streaming terminals, glass on, 60 s windows): board open over streaming terminals 36.5 % GPU /
+ * 15.8 % renderer — no better than the canvas itself (30-32 %) — against 0.0 % / 2.4 % with the same
+ * board over SILENT terminals, so essentially all of it was xterm painting output nobody could see
+ * (140 RenderDebouncer refreshes per 5 s). Hiding the canvas with `visibility: hidden` measured
+ * 35.5 %: CSS does not stop xterm's render service or WebGL's presents. The pause has to be xterm's.
+ *
+ * HOW: through xterm's OWN pause, never beside it. RenderService already knows how to be paused —
+ * `refreshRows` on a paused service just sets `_needsFullRefresh`, renderer resizes queue on
+ * `_pausedResizeTask`, and the transition back to intersecting flushes both and re-measures the
+ * char size of a terminal that was opened hidden. All of that hangs off ONE method,
+ * `_handleIntersectionChange(entry)`, which the observer reaches through `this.` (so an instance
+ * property shadows it). We wrap it: the real entry is RECORDED, and what xterm is told is "not
+ * intersecting" while covered, else the real entry. Covering and uncovering replay through the same
+ * method, so the resume runs xterm's own bookkeeping rather than a copy of it that drifts.
+ * Poking `_isPaused` directly would skip exactly that bookkeeping.
+ *
+ * The parser path is untouched: `term.write` still lands every byte in the buffer while paused, so
+ * nothing is lost — the board-up period is one full repaint on the way out.
+ *
+ * WHAT THIS DOES NOT DO, ON PURPOSE. It never feeds the app's own visibility verdict
+ * (`reportVisible` / the WebGL budget's `setVisible` / hibernation / the offscreen teardown):
+ * folding the board into that verdict would let the board hibernate or tear down the sessions it
+ * is showing cards for (audit GT-6, "refuted fix shapes"). The WebGL context stays held while the
+ * board is up; only the draws stop.
+ *
+ * Private xterm API (`_core._renderService`), exactly as TerminalNode's renderer-swap net and
+ * addon-fit already use it. Feature-detected: a build without the method gets no pause (today's
+ * behaviour), never a throw.
+ */
+
+/** The slice of an IntersectionObserverEntry xterm's handler reads. */
+export interface IntersectionVerdict {
+ isIntersecting: boolean
+ intersectionRatio: number
+}
+
+/** The private RenderService surface this module touches. */
+export interface PausableRenderService {
+ _handleIntersectionChange(entry: IntersectionVerdict): void
+}
+
+/** Minimal xterm shape, so the unit test needs no DOM and no real Terminal. */
+export interface PausableTerminal {
+ _core?: { _renderService?: Partial<PausableRenderService> }
+}
+
+/**
+ * The decision, alone: should xterm render right now? Paused when covered OR when it is
+ * geometrically out of view (xterm's own rule, kept). Exported so the rule is tested by name.
+ */
+export function renderPaused(covered: boolean, intersecting: boolean): boolean {
+ return covered || !intersecting
+}
+
+/** An entry's own answer, the way xterm reads it (`isIntersecting` absent → ratio 0 = hidden). */
+function intersects(entry: Partial<IntersectionVerdict>): boolean {
+ return entry.isIntersecting === undefined ? entry.intersectionRatio !== 0 : entry.isIntersecting
+}
+
+const verdict = (intersecting: boolean): IntersectionVerdict => ({
+ isIntersecting: intersecting,
+ intersectionRatio: intersecting ? 1 : 0
+})
+
+export interface BoardRenderPause {
+ /** Re-read `covered()` and act on a change. Change-gated: a call that moved nothing is free. */
+ sync(): void
+ /** Restore xterm's own handler and leave it in its natural (geometric) state. Idempotent. */
+ dispose(): void
+}
+
+export interface BoardRenderPauseOptions {
+ /** Is this terminal covered right now? Read at every sync and at every observer delivery. */
+ covered: () => boolean
+ /** Covered → uncovered while geometrically on screen: the caller's guaranteed full repaint.
+ * xterm's own resume refresh is debounced and can be swallowed (see `fullRepaint` in
+ * TerminalNode), so the board's exit owes the one that cannot be. */
+ onUncover?: () => void
+}
+
+/** Marker so a second install on the same render service (a park re-adopt that skipped a
+ * dispose) replaces the first instead of stacking a wrapper on a wrapper. */
+const INSTALLED = Symbol('nt.boardRenderPause')
+
+type Wrapped = PausableRenderService & { [INSTALLED]?: BoardRenderPause }
+
+/**
+ * Wrap `term`'s render service. Returns null (and changes nothing) when the private method is
+ * missing — an xterm upgrade that renamed it degrades to today's behaviour.
+ */
+export function installBoardRenderPause(
+ term: PausableTerminal,
+ opts: BoardRenderPauseOptions
+): BoardRenderPause | null {
+ const rs = term._core?._renderService as Wrapped | undefined
+ if (!rs || typeof rs._handleIntersectionChange !== 'function') return null
+ // One layer, ever: an earlier controller still attached gives its original back first.
+ rs[INSTALLED]?.dispose()
+ const hadOwn = Object.prototype.hasOwnProperty.call(rs, '_handleIntersectionChange')
+ const ownBefore = rs._handleIntersectionChange
+ const original = ownBefore.bind(rs)
+ // Seed the geometry from what xterm is ACTING ON right now, read after the earlier controller
+ // (if any) handed its real verdict back. Not a blanket `true`: a terminal re-adopted after a park
+ // was detached, so its observer already delivered not-intersecting (`_isPaused = true`); reattached
+ // still off screen, the observer has nothing new to report, and a `true` seed made the next board
+ // cover/uncover UNPAUSE it — streaming output painted off screen until a pan in and out (review
+ // of the GT-6 fix, reproduced against xterm 5.5's handler). A fresh xterm starts unpaused with no
+ // delivery yet, so the same read gives intersecting there. A build without the field: `true`.
+ const pausedNow = (rs as { _isPaused?: unknown })._isPaused
+ let geometric = typeof pausedNow === 'boolean' ? !pausedNow : true
+ let covered = opts.covered()
+ let disposed = false
+
+ const apply = (): void => original(verdict(!renderPaused(covered, geometric)))
+
+ const controller: BoardRenderPause = {
+ sync(): void {
+ if (disposed) return
+ const now = opts.covered()
+ if (now === covered) return
+ covered = now
+ apply()
+ if (!covered && geometric) opts.onUncover?.()
+ },
+ dispose(): void {
+ if (disposed) return
+ disposed = true
+ if (hadOwn) rs._handleIntersectionChange = ownBefore
+ else delete (rs as Partial<Wrapped>)._handleIntersectionChange
+ if (rs[INSTALLED] === controller) delete rs[INSTALLED]
+ // Hand xterm back the geometry it would have had all along. A no-op when nothing was
+ // covered; when something was, it is xterm's own resume (flush + refresh).
+ // Replayed on a PARK too, on purpose, even though the element is about to be detached: left
+ // paused, a park whose detach and re-adopt land between two observer deliveries (the
+ // observer reports changes only at a rendering step) would come back on screen with
+ // `_isPaused` stuck true and nothing left to clear it. The cost is a single refresh into a
+ // detached element, and the WebGL dispose that follows does its own full refresh anyway.
+ if (covered) original(verdict(geometric))
+ }
+ }
+
+ rs._handleIntersectionChange = (entry: IntersectionVerdict): void => {
+ if (disposed) return original(entry)
+ geometric = intersects(entry)
+ // The board can have opened between syncs (a node mounted under it, an observer delivery
+ // racing the view switch), so the observer path re-reads rather than trusting the cache.
+ covered = opts.covered()
+ if (!covered) return original(entry)
+ original(verdict(false))
+ }
+ rs[INSTALLED] = controller
+ // Mounted under a board that is already up (a card's "new session", a project switch onto a
+ // board-view project): pause before the first frame rather than waiting for a change.
+ if (covered) apply()
+ return controller
+}