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(glyphgrid): repack the cursor row when the inactive cursor style flips block-ness

enes117171470881
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
index 1cd5ecdd9..4f570e170 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -224,8 +224,9 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
clamps sampling). Report it rather than living with it — the revert costs ~0.35 MB per page.
- [ ] **2.8 Selection visual.** Drag-select inside a terminal: the selection band covers exactly
the selected cells, with correct fg/bg inversion, and matches what the DOM renderer draws.
-- [ ] **2.9 Cursor.** A focused terminal shows a solid block cursor at the right cell. It is
- **static** — it does not blink even with "Cursor blink" on (known limitation L1).
+- [ ] **2.9 Cursor.** A focused terminal shows a cursor at the right cell (a solid block, with the
+ default setting). It is **static** — it does not blink even with "Cursor blink" on (known
+ limitation L1).
**The cursor honours Settings → Terminal → Cursor style.** Walk all three: `block` INVERTS the
glyph under it (the letter goes dark on a bright cell — a block is drawn as a CELL, and that is
the only path that can invert), `bar` is a hairline down the LEFT edge with the glyph still
diff --git a/src/renderer/glyphgrid/addon.test.ts b/src/renderer/glyphgrid/addon.test.ts
index 40adbb6f9..1813771e0 100644
--- a/src/renderer/glyphgrid/addon.test.ts
+++ b/src/renderer/glyphgrid/addon.test.ts
@@ -633,6 +633,80 @@ describe('GlyphGridRendererAddonCore cursor shape', () => {
core.handleFocus()
expect(last(handle)?.shape).toBe('bar')
})
+
+ it('repacks the cursor row when a style flip changes BLOCK-ness under a pack that misses it', () => {
+ // The two halves run on different schedules: the overlay is re-pushed by EVERY pack, the cell
+ // half only by one that covers the cursor row. Flip `cursorInactiveStyle` from block to outline
+ // on a BLURRED terminal and then do something that packs other rows — a drag-select — and the
+ // outline would be drawn around a cell still holding the inverted block. Self-healing
+ // eventually, but checklist 2.12 walks a tester straight into it.
+ const style = { style: 'block', inactiveStyle: 'block' }
+ const { core, handle } = make({
+ rows: 8,
+ cols: 4,
+ cursorY: 0,
+ cursorX: 1,
+ focus: false,
+ cursorStyle: style
+ })
+ core.renderRows(0, 7)
+ expect(readCell(handle.rows.find((r) => r.row === 0)!.cells, 1).flags & FLAG_CURSOR).toBe(
+ FLAG_CURSOR
+ )
+ handle.rows.length = 0
+ style.inactiveStyle = 'outline'
+ core.renderRows(4, 5)
+ expect(handle.rows.map((r) => r.row)).toContain(0)
+ expect(readCell(handle.rows.find((r) => r.row === 0)!.cells, 1).flags & FLAG_CURSOR).toBe(0)
+ expect(last(handle)?.shape).toBe('outline')
+ })
+
+ it('repacks it the other way too — the overlay goes at once, so the block must arrive at once', () => {
+ const style = { style: 'block', inactiveStyle: 'outline' }
+ const { core, handle } = make({
+ rows: 8,
+ cols: 4,
+ cursorY: 0,
+ cursorX: 1,
+ focus: false,
+ cursorStyle: style
+ })
+ core.renderRows(0, 7)
+ expect(last(handle)?.shape).toBe('outline')
+ handle.rows.length = 0
+ style.inactiveStyle = 'block'
+ core.renderRows(4, 5)
+ expect(last(handle)).toBe(null)
+ // Without the repair this terminal would show NO cursor at all until its cursor row happened
+ // to be packed by something else.
+ expect(readCell(handle.rows.find((r) => r.row === 0)!.cells, 1).flags & FLAG_CURSOR).toBe(
+ FLAG_CURSOR
+ )
+ })
+
+ it('repairs nothing when the pack already covers the cursor row', () => {
+ // Both halves of the cost/termination argument: the repair re-enters packRows, so it must fire
+ // only when the cursor row is genuinely stale AND is a row a pack can reach.
+ const style = { style: 'block', inactiveStyle: 'block' }
+ const { core, handle } = make({
+ rows: 4,
+ cols: 4,
+ cursorY: 1,
+ cursorX: 1,
+ focus: false,
+ cursorStyle: style
+ })
+ core.renderRows(0, 3)
+ handle.rows.length = 0
+ style.inactiveStyle = 'outline'
+ core.renderRows(1, 1) // the cursor row itself — repainted once, not twice
+ expect(handle.rows.map((r) => r.row)).toEqual([1])
+
+ handle.rows.length = 0
+ style.inactiveStyle = 'block'
+ core.renderRows(3, 3) // flips back, and now the cursor row is NOT in range
+ expect(handle.rows.map((r) => r.row).sort((a, b) => a - b)).toEqual([1, 3])
+ })
})
/** BLUR AND THE SELECTION — limitation L3.
diff --git a/src/renderer/glyphgrid/addon.ts b/src/renderer/glyphgrid/addon.ts
index b301d99a4..20a912f46 100644
--- a/src/renderer/glyphgrid/addon.ts
+++ b/src/renderer/glyphgrid/addon.ts
@@ -135,6 +135,25 @@ export class GlyphGridRendererAddonCore {
/** Viewport row the cursor was on at the last cursor-move — the row a move has to REPAINT to
* erase the old block. Geometric (not focus-gated), so blur/focus and moves stay independent. */
private lastCursorRow: number
+ /**
+ * Whether the CELLS currently hold an inverted block cursor — i.e. the block-ness of the last pack
+ * that actually covered the cursor row.
+ *
+ * The two halves of the cursor are updated on different schedules: the OVERLAY is re-pushed by
+ * every pack (it is a property of the terminal, not of the rows), while the CELL half only changes
+ * on a pack that covers the cursor row. A style change that flips block-ness between those two —
+ * `cursorInactiveStyle` going `block` → `outline` while the terminal is blurred, then a
+ * drag-select, which packs only the selected rows — would leave an outline drawn AROUND a cell
+ * that is still inverted, or (the other direction) clear the overlay and leave no cursor at all.
+ * Remembering what the cells show is what lets `packRows` notice and repaint the cursor row.
+ *
+ * Kept HERE rather than closing the same gap by subscribing to xterm's
+ * `onSpecificOptionChange('cursorInactiveStyle')` through the shell: that would widen the shell's
+ * private-xterm surface (the thing this whole split exists to keep small) for a setting nobody
+ * touches at runtime, and it would only cover the option — this covers every way the two halves
+ * can drift apart, including a focus change racing a pack.
+ */
+ private cellCursorBlock: boolean
/** Mutable because `readCellBound` closes over it: one closure for the lifetime of the addon
* instead of one per packed row. */
@@ -164,6 +183,10 @@ export class GlyphGridRendererAddonCore {
this.workCell = internals.makeWorkCell()
this.focused = internals.hasFocus()
this.lastCursorRow = this.cursorViewportRow()
+ // Seeded from the CURRENT shape rather than from `false`: no row has been packed yet, so there
+ // is no stale block to heal, and seeding the other way would spend one repack of the cursor row
+ // on the first pack of every terminal that misses it.
+ this.cellCursorBlock = this.cursorShape() === 'block'
this.updateDims()
// EVERY subscription goes last, and they go TOGETHER. The shell catches a failing construction
// and restores the DOM renderer without ever holding an addon to dispose, so anything
@@ -485,6 +508,32 @@ export class GlyphGridRendererAddonCore {
})
this.handle.updateRow(row, this.rowBuf)
}
+ this.settleCursorCells(cursorRow, cursorShape === 'block', start, end)
+ }
+
+ /**
+ * Keep the CELL half of the cursor in step with the OVERLAY half across packs.
+ *
+ * Runs after the loop, so the ordinary case is a bookkeeping write: a pack that covered the cursor
+ * row has just repainted it, and what it painted is now what the cells show. The other branch is
+ * the repair — the cursor row was NOT in this range and its block-ness has changed since it was
+ * last packed, which is the `cursorInactiveStyle` flip described on `cellCursorBlock`. Left alone
+ * it shows as an outline drawn around a still-inverted cell, or as no cursor at all.
+ *
+ * TERMINATION, because this re-enters `packRows`: the repack it asks for covers the cursor row by
+ * construction, so the nested call takes the first branch and cannot ask again. A cursor row
+ * outside the grid (scrolled away, hidden by the app) takes neither branch — there is no stale
+ * block to heal there, and asking for a row the pack would clamp away is what a loop would be
+ * made of.
+ */
+ private settleCursorCells(cursorRow: number, block: boolean, start: number, end: number): void {
+ if (cursorRow < 0 || cursorRow >= this.rows) return
+ if (cursorRow >= start && cursorRow <= end) {
+ this.cellCursorBlock = block
+ return
+ }
+ if (this.cellCursorBlock === block) return
+ this.packCursorRow()
}
/** Column span [start, endExclusive) of the selection on one ABSOLUTE buffer row, or null.
diff --git a/src/renderer/glyphgrid/feed.ts b/src/renderer/glyphgrid/feed.ts
index ae67180fd..1045ba89c 100644
--- a/src/renderer/glyphgrid/feed.ts
+++ b/src/renderer/glyphgrid/feed.ts
@@ -242,10 +242,12 @@ export function packViewportRow(
const selEnd = selection ? selection[1] : -1
// Only a block is a cell rewrite; every other shape is the overlay pass's business (cursor.ts).
const blockCursor = (opts.cursorShape ?? 'block') === 'block'
- // Resolved ONCE per row: the selection colour cannot change mid-row, and blending it per cell
- // would put a multiply and four roundings in the hot loop for an answer that never differs.
+ // Resolved ONCE per row, and only for a row that HAS a selection: the blend is four roundings, and
+ // `focused === false` is true of every terminal on the canvas except one — computing it per row
+ // regardless would charge a colour nobody paints to every row of every unfocused terminal. The
+ // same standard the `decorations` hoist below is written to.
const selectionBg =
- opts.focused === false
+ opts.focused === false && selection
? blendLane(theme.selectionBg, theme.bg, INACTIVE_SELECTION_BLEND)
: theme.selectionBg
// Hoisted out of the loop: `empty()` is answered ONCE per row rather than once per cell, and a
diff --git a/src/renderer/glyphgrid/gl-webgl2.ts b/src/renderer/glyphgrid/gl-webgl2.ts
index b11cc8570..29585d751 100644
--- a/src/renderer/glyphgrid/gl-webgl2.ts
+++ b/src/renderer/glyphgrid/gl-webgl2.ts
@@ -368,7 +368,9 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {
gl.uniform2f(cu('uPan'), cam.x, cam.y)
gl.uniform1f(cu('uZoom'), cam.zoom)
gl.uniform2f(cu('uView'), view[0], view[1])
- gl.uniform4fv(cu('uRects'), cursorRectData.subarray(0, n * 4))
+ // WebGL2's srcOffset/srcLength overload, NOT a `subarray`: the view would be an allocation per
+ // cursor per frame, which is precisely what the scratch buffer above exists to avoid.
+ gl.uniform4fv(cu('uRects'), cursorRectData, 0, n * 4)
const col = unpackColor(c.color)
gl.uniform4f(cu('uColor'), col.r / 255, col.g / 255, col.b / 255, col.a / 255)
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, n)