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(glass): bound panel verdicts; re-run the background pass when a colour turns opaque

iceclatterWT82128e90b6a7
diff --git a/CLAUDE.md b/CLAUDE.md
index 8fa5f5bdc..dbff73044 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -3888,7 +3888,11 @@ glass never sits over plain black; a wallpaper the user chose is never replaced.
than #1e1e1e yet dark on a #e4e4e4 bar — judged by the theme, that bar went translucent at 1.00:1).
**One verdict per panel colour per terminal** (`panelVerdicts`): fill computed once, each text
colour checked once, opaque sticks (a multi-row light box never stripes), reset on alpha or theme
- bg/fg change — addon-webgl rebuilds every row on any cell change, cursor blink included. The wrap
+ bg/fg change — addon-webgl rebuilds every row on any cell change, cursor blink included. Capped at
+ `PANEL_VERDICTS_MAX` (4096) colours, cleared past it (truecolor images add thousands). A colour
+ that turns opaque mid-pass re-runs `updateBackgrounds` once (also wrapped), so the rows already
+ drawn in that pass do not stay translucent on an idle screen — `term.refresh` would not do it: the
+ addon calls `updateBackgrounds` only when a model cell changed. The wrap
body after the stock rectangle is try/caught per call (fail open per frame, not only at install). Reduce Transparency (t = 1) → opaque. Written premultiplied as `(c·√k, √k)` — the
canvas is premultiplied and the addon blends alpha with SRC_ALPHA, so this stores exactly `(c·k, k)`.
Only terminals registered through `setGlassCellAlpha` (TerminalNode, `glassOn` only) are touched —
diff --git a/src/renderer/terminal/glass-cell-backgrounds.test.ts b/src/renderer/terminal/glass-cell-backgrounds.test.ts
index b1d28f006..1b9527b99 100644
--- a/src/renderer/terminal/glass-cell-backgrounds.test.ts
+++ b/src/renderer/terminal/glass-cell-backgrounds.test.ts
@@ -9,6 +9,7 @@ import {
installGlassCellBackgrounds,
GLASS_CELL_REBUILD_MS,
oklab,
+ PANEL_VERDICTS_MAX,
scheduleGlassCellAlpha,
setGlassCellAlpha
} from './glass-cell-backgrounds'
@@ -230,6 +231,13 @@ function fakeAddon(cells: Record<number, FakeCell>, rows: Record<number, Record<
v.attributes.set([0, 0, 1, 1, ((rgba >>> 24) & 255) / 255, ((rgba >>> 16) & 255) / 255, ((rgba >>> 8) & 255) / 255, 1], offset)
void fg
}
+ /** Like the real one: a full rebuild of every run from the model, through `_updateRectangle`. */
+ _vertices = { attributes: new Float32Array(64) }
+ passes = 0
+ updateBackgrounds(model: { fg: number; bg: number; x: number; endX: number; y: number }[]): void {
+ this.passes++
+ model.forEach((r, i) => this._updateRectangle(this._vertices, 8 * i, r.fg, r.bg, r.x, r.endX, r.y))
+ }
}
const rr = new RectangleRenderer()
const addon = { _renderer: { _rectangleRenderer: { value: rr } } } as unknown as WebglAddon
@@ -281,6 +289,40 @@ describe('installGlassCellBackgrounds', () => {
expect(draw(0, bar, 0, 2, 0)[7]).toBeLessThan(1)
})
+ it('a colour that turns opaque mid-pass re-runs the pass once, so earlier rows are not left translucent', () => {
+ const bar = CM_RGB | 0xe0e0e0
+ const blank = { 0: { bg: bar }, 1: { bg: bar } }
+ const texted = { 0: { bg: bar }, 1: { bg: bar, fg: CM_RGB | 0x000000, ch: 'x' } }
+ const { addon, rr } = fakeAddon({}, { 0: blank, 1: texted, 2: blank })
+ installGlassCellBackgrounds(addon)
+ setGlassCellAlpha(rr._terminal, 0.675)
+ const model = [0, 1, 2].map((y) => ({ fg: 0, bg: bar, x: 0, endX: 2, y }))
+ const alphas = (): number[] => model.map((_, i) => rr._vertices.attributes[8 * i + 7])
+ rr.updateBackgrounds(model)
+ expect(alphas()).toEqual([1, 1, 1]) // row 0 was drawn translucent before row 1 flipped it
+ expect(rr.passes).toBe(2)
+ rr.updateBackgrounds(model) // no flip: one pass, no loop
+ expect(rr.passes).toBe(3)
+ })
+
+ it('panel verdicts are bounded: past PANEL_VERDICTS_MAX colours they start over', () => {
+ const bar = CM_RGB | 0xe0e0e0
+ const rows: Record<number, Record<number, FakeCell>> = {
+ 0: { 0: { bg: bar }, 1: { bg: bar } },
+ 1: { 0: { bg: bar }, 1: { bg: bar, fg: CM_RGB | 0x000000, ch: 'x' } }
+ }
+ const colour = (i: number): number => CM_RGB | (0x100000 + i) // distinct, never the bar
+ for (let i = 0; i < PANEL_VERDICTS_MAX; i++) rows[2 + i] = { 0: { bg: colour(i) } }
+ const { addon, rr, draw } = fakeAddon({}, rows)
+ installGlassCellBackgrounds(addon)
+ setGlassCellAlpha(rr._terminal, 0.675)
+ draw(0, bar, 0, 2, 1) // the bar turns opaque
+ for (let i = 0; i < PANEL_VERDICTS_MAX - 1; i++) draw(0, colour(i), 0, 1, 2 + i) // map now full
+ expect(draw(0, bar, 0, 2, 0)[7]).toBe(1) // still remembered at the cap
+ draw(0, colour(PANEL_VERDICTS_MAX - 1), 0, 1, 1 + PANEL_VERDICTS_MAX) // one more: cleared
+ expect(draw(0, bar, 0, 2, 0)[7]).toBeLessThan(1) // forgotten, decided afresh
+ })
+
it('an exception after the original leaves the stock rectangle instead of breaking the frame', () => {
const { addon, rr, draw } = fakeAddon({ 0: { bg: panel } })
installGlassCellBackgrounds(addon)
diff --git a/src/renderer/terminal/glass-cell-backgrounds.ts b/src/renderer/terminal/glass-cell-backgrounds.ts
index 1cd8aac37..163fcbd53 100644
--- a/src/renderer/terminal/glass-cell-backgrounds.ts
+++ b/src/renderer/terminal/glass-cell-backgrounds.ts
@@ -187,8 +187,9 @@ export function setGlassCellAlpha(term: Terminal, alpha: number | null): boolean
* rectangles on any cell change (each cursor blink included), and deciding each row alone striped a
* multi-row light box (rows with dark text opaque, the blank rows of the same box lifted). The fill
* is computed once; each text colour is checked once; a failure makes the colour opaque for good —
- * the rows drawn before it catch up on the next rebuild. Dropped whenever the slider alpha or the
- * theme's bg/fg changes.
+ * and the pass that saw it is re-run (see the `updateBackgrounds` wrap) so the rows drawn before it
+ * do not stay translucent on an idle screen. Dropped whenever the slider alpha or the theme's bg/fg
+ * changes, and wholesale past `PANEL_VERDICTS_MAX` colours (truecolor images/video paint thousands).
* ponytail: an OSC 4 palette-only change keeps the old verdicts until the next alpha/theme change;
* key on the ANSI table too if an app is ever seen recolouring its panels that way.
*/
@@ -197,6 +198,10 @@ interface PanelVerdicts {
panels: Map<number, { fill: PanelFill | null; ok: Set<number> }>
}
const panelVerdicts = new WeakMap<Terminal, PanelVerdicts>()
+/** ponytail: a full clear past this many panel colours, not an LRU — verdicts are cheap to redo. */
+export const PANEL_VERDICTS_MAX = 4096
+/** Set when a panel colour turns opaque mid-pass; read by the `updateBackgrounds` wrap. */
+let flippedThisPass = false
/** The colour part of a packed fg/bg word (mode + palette index or RGB), flags stripped. */
const COLOR_BITS = CM_MASK | 0xffffff
@@ -248,6 +253,7 @@ interface CellLike {
/** Kept on the prototype, not in module state, so a hot-reloaded copy of this module re-wraps the
* ORIGINAL instead of stacking a second wrap over the first. */
const ORIGINAL = Symbol.for('nodeterm.glassCellBackgrounds.original')
+const ORIGINAL_UPDATE_BACKGROUNDS = Symbol.for('nodeterm.glassCellBackgrounds.originalUpdateBackgrounds')
const rgbOf = (rgba: number): Rgb => [(rgba >>> 24) & 255, (rgba >>> 16) & 255, (rgba >>> 8) & 255]
@@ -312,7 +318,10 @@ export function installGlassCellBackgrounds(addon: WebglAddon): boolean {
const run: Rgb = [a[offset + 4] * 255, a[offset + 5] * 255, a[offset + 6] * 255]
const theme = { bg: rgbOf(back), fg: rgbOf(fore) }
let panel = verdicts.panels.get(bg & COLOR_BITS)
- if (!panel) verdicts.panels.set(bg & COLOR_BITS, (panel = { fill: panelFill(run, theme, t), ok: new Set() }))
+ if (!panel) {
+ if (verdicts.panels.size >= PANEL_VERDICTS_MAX) verdicts.panels.clear()
+ verdicts.panels.set(bg & COLOR_BITS, (panel = { fill: panelFill(run, theme, t), ok: new Set() }))
+ }
// The run's text colours: a run spans cells of one bg but any fg, and the fg the renderer
// passes is only the first cell's. Each colour is checked once per panel colour.
for (let x = startX; x < endX && panel.fill && line && scratch; x++) {
@@ -328,7 +337,10 @@ export function installGlassCellBackgrounds(addon: WebglAddon): boolean {
? rgbOf(colors.ansi[f & 0xff].rgba)
: rgbOf(fore)
if (panelTextOk(text, run, panel.fill, theme, t)) panel.ok.add(f & COLOR_BITS)
- else panel.fill = null // opaque sticks for this colour
+ else {
+ panel.fill = null // opaque sticks for this colour
+ flippedThisPass = true
+ }
}
if (panel.fill) writeFill(a, offset, panel.fill.rgb, panel.fill.alpha)
}
@@ -353,6 +365,23 @@ export function installGlassCellBackgrounds(addon: WebglAddon): boolean {
/* stock rectangle */
}
}
+ // A verdict that turns opaque mid-pass leaves the rows ALREADY drawn in this pass translucent,
+ // and `term.refresh` would not fix them: the addon calls `updateBackgrounds` only when a model
+ // cell changed. `updateBackgrounds` is a full rebuild from the model, so re-run it once — the
+ // re-run cannot flip again (an opaque colour's text loop is skipped). Optional: missing ⇒ the
+ // rows catch up on the next rebuild, as before.
+ const origUpdate = (proto[ORIGINAL_UPDATE_BACKGROUNDS] ?? proto.updateBackgrounds) as
+ | ((model: unknown) => void)
+ | undefined
+ if (typeof origUpdate === 'function') {
+ proto[ORIGINAL_UPDATE_BACKGROUNDS] = origUpdate
+ proto.updateBackgrounds = function (this: unknown, model: unknown): void {
+ flippedThisPass = false
+ origUpdate.call(this, model)
+ if (flippedThisPass) origUpdate.call(this, model)
+ flippedThisPass = false
+ }
+ }
return true
} catch {
return false