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
fix(glyphgrid): the plate is the node BODY, and the atlas sampler stops guessing
enes3a16c3c4b447
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.mdindex 13c087c0d..0ba12be95 100644--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md@@ -58,18 +58,24 @@ Auto after you switched builds, that is why: re-select Shared and carry on.256-color/truecolor ramps match the DOM rendering. Reverse-video cells (selected row in`htop`, `vim` visual mode) are inverted, not blank.- [ ] **2.4 Plate is the body background.** The terminal body's background is the theme background,- not the canvas dot grid — including the strip under the last row and around the padding.+ not the canvas dot grid — **edge to edge**: under the last row, past the last column, and+ around the host padding on all four sides. The plate is the BODY rect now, so there is no+ band left to except (see 2.13).- [ ] **2.5 Wide chars.** CJK (`日本語`) and emoji occupy two columns each, with the following textstill on the same column grid as the DOM rendering. A wide glyph is not clipped in half.- [ ] **2.6 Combining sequences.** A decomposed grapheme (e.g. `e` + U+0301) renders the BASEcharacter — the accent may be missing, but never a lone accent mark on a blank cell.- [ ] **2.7 Atlas fidelity at dpr 1 and 2.** On the retina display and on an external 1x display,with a non-default font family and size (e.g. Menlo 11, JetBrains Mono 16): text is crisp,- not soft or doubled. **If any softness remains at zoom 1, report it** — the atlas is now- rasterized at xterm's exact device cell, which puts the sampler on a float tie: `MIN_FILTER`- selection sits on the λ=0 mag/min boundary, and a driver resolving that to minification uses- LINEAR (soft) instead of MAG NEAREST (crisp). The deterministic fallback is NEAREST min at- zoom ≥ 1.+ not soft or doubled. The float tie this item used to warn about is **closed**: the atlas is+ rasterized at xterm's exact device cell (1:1 texels) *and* the filter no longer depends on+ which side of the λ=0 mag/min boundary a driver resolves to — `MIN_FILTER` is set from the+ camera (**NEAREST at zoom ≥ 1**, where the snapped pan makes it bit-exact; **LINEAR below 1**,+ so a zoomed-out thumbnail stays readable), and MAG stays NEAREST. **Report any softness that+ remains AFTER this**: with the sampler made deterministic, what is left points at the atlas+ RASTER itself (the canvas rasterizer's antialiasing / baseline rounding, or L14's+ first-terminal cell latch), not at the sampler. Also zoom OUT past 1 and confirm the text+ degrades smoothly rather than speckling.- [ ] **2.8 Selection visual.** Drag-select inside a terminal: the selection band covers exactlythe 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@@ -82,9 +88,13 @@ Auto after you switched builds, that is why: re-select Shared and carry on.hollow outline — known limitation L2), and the selection stays visible in the same color aswhen focused (known limitation L3). Judge whether either is acceptable to ship.- [ ] **2.13 Plate geometry.** Look at the four corners and the right/bottom edges of a terminal- body: the plate is a SQUARE rect under a node with rounded corners (L4), and up to one cell- of fit slack at the right/bottom may show canvas rather than terminal background (L5). Judge- how visible these are at normal zoom, and whether any padding seam shows on the left/top.+ body. Expected: **no bands anywhere** — the plate is the body rect, so the fit slack at the+ right/bottom and the padding seams on the left/top are all inside it (the round-2 fix; the+ previous grid-sized plate is what put them there). The one artifact that REMAINS is L4: the+ plate is a SQUARE rect under a node with `border-radius: 10px`, so the body's four corners+ read square. Judge how visible that is at normal zoom, and report any band you still see —+ a band now means the plate rect is not tracking the body, not that it is undersized by+ design.- [ ] **2.14 Scroll area after a font change.** Change the font size while shared is on, then lookat the scrollbar/scroll area geometry: the thumb matches the content, no phantom region.- [ ] **2.15 Cursor on a wide glyph.** Put the cursor ON a double-width character (type `日本語`@@ -119,8 +129,14 @@ Auto after you switched builds, that is why: re-select Shared and carry on.- [ ] **3.10 Group-parented terminal.** A terminal inside a group frame: its text sits exactly inits body (offset chain resolves through the parent), and its paint order relative toungrouped terminals is sane (known limitation L7).-- [ ] **3.11 Letterboxed / oddly-sized node.** Resize a node so the fit leaves slack: the text- stays inside the body, aligned with the mouse.+- [ ] **3.11 Letterboxed / oddly-sized node.** Resize a node so the fit leaves slack, and open a+ co-attached node that a smaller peer is letterboxing: the text stays inside the body, aligned+ with the mouse, **and the letterbox bands are terminal background, not canvas**. Reasoning to+ verify by eye rather than assume: `.term-node__xterm.letterboxed` centers a SMALLER `.xterm`+ inside the body, so the leftover space sits on all four sides — the plate is the body rect,+ which contains the centred screen whichever way the slack falls, so it covers every band.+ This was L5's worst case (tens of pixels of dot grid); it is the sharpest test that the plate+ really is body-sized.- [ ] **3.12 Programmatic camera.** ⌘K jump to a node, a notification click, and a fitView: thetext lands with the node — no frame where glyphs sit at the old position or at the origin.- [ ] **3.13 Stacking.** The canvas is ABOVE the dot grid and BELOW node chrome; the bottom-left@@ -226,14 +242,19 @@ Auto after you switched builds, that is why: re-select Shared and carry on.- **L4 — Square plate corners.** The grid's plate is a rectangle; the node has `border-radius: 10px`and cannot clip the canvas (it is not a DOM child), so the body's corners read square in sharedmode. Phase 2: rounded/stencilled plate.-- **L5 — The plate is sized to the GRID, so any band wider than the padding shows canvas.** The- plate covers the grid plus one scalar of host padding (`padPx`, the 6px max of- `.term-node__xterm`'s asymmetric CSS padding), so every band of body that the cell fit does not- fill shows the canvas/dot grid through the transparent node body instead of the terminal- background. Two shapes of the same defect: (a) up to one cell of **fit slack** at the right/bottom- edge; (b) the **letterbox** bands of a node whose aspect leaves more than 6px unfilled — most- visible on co-attach/letterboxed nodes, where the band can be tens of pixels. Same Phase-2 fix as- L4: size the plate to the BODY rect rather than the grid rect.+- **L5 — FIXED in round 2 (bands at the bottom/right).** Kept here as the record, because it is the+ one item on this list whose expected observation INVERTED. It used to read: the plate covers the+ grid plus one scalar of host padding (`padPx`, the 6px max of `.term-node__xterm`'s asymmetric+ padding), so every band of body the cell fit does not fill shows the canvas dot grid through the+ transparent node — as (a) up to one cell of **fit slack** at the right/bottom, and (b) the+ **letterbox** bands of a co-attached node, tens of pixels wide. Both were reported from the+ device. The plate is now an INDEPENDENT world rect set to the node **body** (`GridSpec.plateX/Y/+ W/H` ← `bodyPlateRect`, pushed on the ResizeObserver's settled tick and carried by the position+ effect during a drag), so it covers the padding, the fit slack and the letterbox bands alike —+ they all lie inside the body box. Verify by items **2.4**, **2.13** and **3.11**: a band now means+ the plate is not TRACKING the body (a bug), not that it is undersized by design.+ **L4 is unaffected and remains** — the plate's square corners are a separate Phase-2 question+ (a rounded / stencilled plate), and no rect size fixes them.- **L6 — Adopting a parked terminal after a font change may keep a stale cell size.** The grid isregistered from the cell xterm reports at adopt time; a font change applied in the same commitcan land after it. Refreshing the node re-registers at the correct size.diff --git a/src/renderer/glyphgrid/addon.test.ts b/src/renderer/glyphgrid/addon.test.tsindex c0efbbccf..3f8ea33da 100644--- a/src/renderer/glyphgrid/addon.test.ts+++ b/src/renderer/glyphgrid/addon.test.ts@@ -69,6 +69,9 @@ function recordingHandle(): GridHandle & {rows.push({ row, cells: cells.slice(), buf: cells })},setOrigin() {},+ // The addon owns CELLS, never geometry — the plate is the node's business. A stub, present+ // only to satisfy the handle contract.+ setPlateRect() {},setZ() {},resize(cols, r) {log.push(`resize:${cols}x${r}`)diff --git a/src/renderer/glyphgrid/engine.test.ts b/src/renderer/glyphgrid/engine.test.tsindex ac974c7fd..6613ac3ad 100644--- a/src/renderer/glyphgrid/engine.test.ts+++ b/src/renderer/glyphgrid/engine.test.ts@@ -75,6 +75,9 @@ function loadedAtlas(sizePx = 512, cellW = 7, cellH = 15) {}}+/** A 2×1 grid of 10×20 cells → a 20×20 cell rect at (x, 0). The plate DEFAULTS to exactly that+ * rect, so a test that says nothing about the plate reads as if the two coincided; the tests that+ * care about the two being different rects pass their own `plate*`. */const spec = (id: string, x: number, z = 0, over: Partial<GridSpec> = {}): GridSpec => ({id,cols: 2,@@ -85,7 +88,10 @@ const spec = (id: string, x: number, z = 0, over: Partial<GridSpec> = {}): GridSoriginY: 0,z,bgColor: 0,- padPx: 0,+ plateX: x,+ plateY: 0,+ plateW: 20,+ plateH: 20,...over})@@ -134,17 +140,79 @@ describe('GlyphGridEngine', () => {expect(e.drawOrder()).toEqual(['in'])})- it('culls against the PADDED rect: a grid whose plate still overlaps the viewport is drawn', () => {+ it('culls against the plate rect: a grid whose plate alone overlaps the viewport is drawn', () => {const e = new GlyphGridEngine(fakeGL(), atlas())e.setViewport(100, 100, 1)e.setCamera({ x: 0, y: 0, zoom: 1 })// Cells start exactly at the right viewport edge (x=100, visible world rect is 0..100), so// the character matrix alone is off-screen — but the plate is the node's opaque BODY and- // extends padPx further left, into view. Culling on the cell rect would leave a visible strip- // of the node body unpainted at every viewport edge.- e.register(spec('padded', 100, 0, { padPx: 8 }))- e.register(spec('bare', 100, 0, { padPx: 0 }))- expect(e.drawOrder()).toEqual(['padded'])+ // reaches further left, into view. Culling on the cell rect would leave a visible strip of+ // node body unpainted at every viewport edge, and would skip the plate that occludes whatever+ // sits underneath it.+ e.register(spec('plated', 100, 0, { plateX: 92, plateW: 36 }))+ e.register(spec('bare', 100, 0))+ expect(e.drawOrder()).toEqual(['plated'])+ })++ it('culls against the CELL rect too: a grid whose cells alone overlap the viewport is drawn', () => {+ const e = new GlyphGridEngine(fakeGL(), atlas())+ e.setViewport(100, 100, 1)+ e.setCamera({ x: 0, y: 0, zoom: 1 })+ // The other half of the union, and the reason it is a union rather than "the plate contains+ // the grid, so test the plate". Nothing structurally guarantees containment — the two rects+ // are pushed by different observers (`setOrigin` follows .xterm-screen, `setPlateRect` the+ // body box), so mid-resize a stale plate can sit off-screen while the cells are in plain+ // view. Culling on the plate alone would blank a visible terminal.+ e.register(spec('cells-only', 90, 0, { plateX: 500, plateY: 500 }))+ expect(e.drawOrder()).toEqual(['cells-only'])+ })++ it('culls a grid whose plate AND cells are both off-screen', () => {+ const e = new GlyphGridEngine(fakeGL(), atlas())+ e.setViewport(100, 100, 1)+ e.setCamera({ x: 0, y: 0, zoom: 1 })+ // The union must not be a BOUNDING BOX of the two rects: the box spanning (500,0)-(520,20)+ // and (0,500)-(20,520) covers the origin, so a bounding-box union would keep drawing a grid+ // that paints no pixel at all.+ e.register(spec('gone', 500, 0, { plateX: 0, plateY: 500 }))+ expect(e.drawOrder()).toEqual([])+ })++ it('setPlateRect moves the plate, change-gated like every other mutator', () => {+ const e = new GlyphGridEngine(fakeGL(), atlas())+ e.setViewport(800, 600, 1)+ e.setCamera({ x: 0, y: 0, zoom: 1 })+ const h = e.register(spec('a', 0))+ e.frame()+ // Same rect → nothing changed on screen. The caller is a ResizeObserver firing on every+ // layout tick, so an unconditional dirty here would keep the shared canvas redrawing forever.+ h.setPlateRect(0, 0, 20, 20)+ expect(e.frame()).toBe(false)+ h.setPlateRect(-6, -4, 40, 44)+ expect(e.frame()).toBe(true)+ })++ it('setPlateRect on a disposed handle is inert — it must not un-idle the canvas', () => {+ const e = new GlyphGridEngine(fakeGL(), atlas())+ e.setViewport(800, 600, 1)+ e.setCamera({ x: 0, y: 0, zoom: 1 })+ const h = e.register(spec('a', 0))+ h.dispose()+ e.frame()+ h.setPlateRect(-6, -4, 40, 44)+ expect(e.frame()).toBe(false)+ })++ it('a plate change reaches drawGrid', () => {+ const gl = fakeGL()+ const e = new GlyphGridEngine(gl, atlas())+ e.setViewport(800, 600, 1)+ e.setCamera({ x: 0, y: 0, zoom: 1 })+ const h = e.register(spec('a', 0))+ e.frame()+ h.setPlateRect(-6, -4, 40, 44)+ e.frame()+ expect(gl.params.at(-1)).toMatchObject({ plateX: -6, plateY: -4, plateW: 40, plateH: 44 })})it('draws in z order ascending, ties by registration order', () => {@@ -579,13 +647,15 @@ describe('per-grid buffers + row-range damage', () => {expect(e.frame()).toBe(false)})- it('drawGrid receives the plate params (bgColor, padPx) with the grid geometry', () => {+ it('drawGrid receives the plate params (bgColor + plate rect) with the grid geometry', () => {const gl = fakeGL()const e = new GlyphGridEngine(gl, atlas())e.setViewport(800, 600, 1)e.setCamera({ x: 0, y: 0, zoom: 1 })const bg = packColor(20, 20, 24, 255)- e.register(spec('a', 0, 0, { bgColor: bg, padPx: 8 }))+ // A plate that is NOT the cell rect — the body overhangs the matrix by 6 left/top and leaves+ // fit slack right/bottom, which is the shape every real terminal has.+ e.register(spec('a', 0, 0, { bgColor: bg, plateX: -6, plateY: -4, plateW: 40, plateH: 44 }))e.frame()// Exact object: cell DATA must NOT travel here any more — it lives in the grid's own GPU// buffer, and re-sending it per draw is the ~90 MB/s this task exists to remove.@@ -599,7 +669,10 @@ describe('per-grid buffers + row-range damage', () => {originX: 0,originY: 0,bgColor: bg,- padPx: 8+ plateX: -6,+ plateY: -4,+ plateW: 40,+ plateH: 44}])})diff --git a/src/renderer/glyphgrid/engine.ts b/src/renderer/glyphgrid/engine.tsindex 9e9bfa0ed..8185bb65d 100644--- a/src/renderer/glyphgrid/engine.ts+++ b/src/renderer/glyphgrid/engine.ts@@ -18,9 +18,13 @@ export interface GridSpec {originY: numberz: numberbgColor: number- /** Padding around the grid rect, in world units, that the opaque plate also covers — the node- * body's inset. See gl.ts's GridDrawParams. */- padPx: number+ /** The opaque plate's own world rect — the node BODY, which is generally larger than the+ * character matrix. Independent of the grid geometry on purpose; see gl.ts's+ * `GridDrawParams.plateX`. */+ plateX: number+ plateY: number+ plateW: number+ plateH: number}export interface GridHandle {@@ -41,6 +45,14 @@ export interface GridHandle {*/updateRow(row: number, cells: Uint32Array): voidsetOrigin(x: number, y: number): void+ /**+ * Move/resize the opaque plate — the node BODY rect in world units. Separate from `setOrigin`+ * because the two move for different reasons and at different times: the grid follows the+ * terminal SCREEN inside the node, the plate follows the body box. A resize changes the body+ * on every layout tick while the screen offset may not move at all, so the owner (a+ * ResizeObserver) calls both and each change-gates itself.+ */+ setPlateRect(x: number, y: number, w: number, h: number): voidsetZ(z: number): voidresize(cols: number, rows: number): void/** Drops the grid. After this the handle is INERT — every mutator above becomes a silent@@ -175,6 +187,19 @@ export class GlyphGridEngine {grid.originY = yengine.dirty = true},+ setPlateRect(x, y, w, h) {+ if (grid.dead) return+ // Change-gated like every other mutator, and for the usual reason: the caller is a+ // ResizeObserver / origin sync that fires on every layout tick, and an unconditional+ // dirty there would keep the shared canvas redrawing forever.+ if (grid.plateX === x && grid.plateY === y && grid.plateW === w && grid.plateH === h)+ return+ grid.plateX = x+ grid.plateY = y+ grid.plateW = w+ grid.plateH = h+ engine.dirty = true+ },setZ(z) {if (grid.dead) returnif (grid.z === z) return@@ -274,23 +299,31 @@ export class GlyphGridEngine {* band (a stats read-out, a test) can only write the same answer the next frame would, and* every input that could change it dirties the engine.*- * Culled against the PADDED rect, not the character matrix: a grid draws its opaque plate- * (the node body, `padPx` world units wider on every side) before its cells, so a grid whose- * cells have just left the viewport may still owe it a visible strip of body. Culling on the- * cell rect alone would pop that strip away at every viewport edge — and, worse, would skip- * the plate that occludes whatever sits underneath it. */+ * Culled against the UNION of the plate rect and the cell rect, never one alone. A grid draws+ * its opaque plate — the node BODY, an independent rect that is normally larger than the+ * character matrix but is NOT guaranteed to contain it — before its cells, and either part can+ * be the only one on screen:+ * - cells offscreen, plate visible: a grid scrolled just past the edge still owes a strip of+ * body, and skipping it would also skip the plate that occludes whatever sits underneath;+ * - plate offscreen, cells visible: nothing structurally forbids a grid drawn outside its own+ * body (a stale plate rect mid-resize), and culling it would blank a terminal that is in+ * plain view.+ * Two intersection tests, not one bounding-box union: the bounding box of two disjoint rects+ * covers ground neither of them does, so it would keep grids alive that draw no pixel. */drawOrder(): string[] {const visible: Rect = visibleWorldRect(this.camera, this.viewW, this.viewH)return [...this.grids.values()].filter((g) => {// Written for EVERY grid, not just the survivors — a grid that has just left the// viewport has to learn it is hidden, and only the filter's own answer can tell it.- g.lastVisible = rectsIntersect(visible, {- x: g.originX - g.padPx,- y: g.originY - g.padPx,- w: g.cols * g.cellW + 2 * g.padPx,- h: g.rows * g.cellH + 2 * g.padPx- })+ g.lastVisible =+ rectsIntersect(visible, { x: g.plateX, y: g.plateY, w: g.plateW, h: g.plateH }) ||+ rectsIntersect(visible, {+ x: g.originX,+ y: g.originY,+ w: g.cols * g.cellW,+ h: g.rows * g.cellH+ })return g.lastVisible}).sort((a, b) => a.z - b.z || a.seq - b.seq)@@ -381,7 +414,10 @@ export class GlyphGridEngine {originX: g.originX,originY: g.originY,bgColor: g.bgColor,- padPx: g.padPx+ plateX: g.plateX,+ plateY: g.plateY,+ plateW: g.plateW,+ plateH: g.plateH})}this.gl.endFrame()diff --git a/src/renderer/glyphgrid/gl-webgl2.ts b/src/renderer/glyphgrid/gl-webgl2.tsindex 3253e3152..8c8eb6e72 100644--- a/src/renderer/glyphgrid/gl-webgl2.ts+++ b/src/renderer/glyphgrid/gl-webgl2.ts@@ -86,13 +86,47 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {/** The camera of the frame in flight — the plate rect is computed on the CPU (world → screen),* so drawGrid needs it. */let cam: Camera = { x: 0, y: 0, zoom: 1 }+ /** Last value pushed to `TEXTURE_MIN_FILTER`, so the per-frame call below costs one comparison+ * instead of a driver round trip. 0 is not a valid enum — it means "never set", which is what+ * makes the first frame always reach the texture. */+ let atlasMinFilter = 0++ /**+ * Pick the atlas's MINIFICATION filter from the camera zoom — the fix for "text is nearly, but+ * not quite, crisp at 100%".+ *+ * The atlas is rasterized at xterm's exact DEVICE cell, so at zoom 1 a glyph's quad is exactly+ * as many device pixels as the slot has texels: a 1:1 mapping, which puts the sampler's+ * level-of-detail on the **λ = 0 tie** between magnification and minification. Which side a+ * driver resolves that tie to is not specified, and a driver that lands on MINIFICATION used+ * `MIN_FILTER = LINEAR` — a four-texel average of an exact 1:1 sample, i.e. the residual+ * softness reported from the device after the atlas was already made 1:1.+ *+ * So make the answer deterministic instead of hoping both sides agree:+ * - **zoom >= 1 → NEAREST.** The pan is snapped to whole device pixels (`snapPanToDevicePx`)+ * and the texels are 1:1, so NEAREST is bit-exact — whichever side of the tie the driver+ * picks, it now samples the same texel MAG would have.+ * - **zoom < 1 → LINEAR.** Genuine minification: several texels really do fall into one pixel,+ * and NEAREST there aliases a zoomed-out canvas into unreadable speckle. Thumbnails stay+ * readable.+ *+ * MAG stays NEAREST unconditionally — it was never the ambiguous half.+ */+ const applyAtlasMinFilter = (zoom: number): void => {+ const want = zoom >= 1 ? gl.NEAREST : gl.LINEAR+ if (want === atlasMinFilter) return+ atlasMinFilter = want+ gl.bindTexture(gl.TEXTURE_2D, atlasTex)+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, want)+ }gl.useProgram(program)gl.enable(gl.BLEND)gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)/**- * The occlusion plate: a scissored `clear` of the grid rect expanded by `padPx` world units.+ * The occlusion plate: a scissored `clear` of the grid's PLATE rect — the node body's full+ * world rect, not the character matrix (see `GridDrawParams.plateX`).** A clear, not a blended quad, on purpose — it WRITES the colour (blending is bypassed), which* is what makes it occlude rather than tint whatever was drawn beneath. Callers therefore pass@@ -106,7 +140,13 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {// narrowing, so `gl` would be `WebGL2RenderingContext | null` inside the body.const drawPlate = (g: GridDrawParams): void => {// Null = the plate covers no pixel of the drawing buffer; skip it entirely.- const r = plateRectDevice(g, cam, dpr, deviceW, deviceH)+ const r = plateRectDevice(+ { x: g.plateX, y: g.plateY, w: g.plateW, h: g.plateH },+ cam,+ dpr,+ deviceW,+ deviceH+ )if (!r) returnconst c = unpackColor(g.bgColor)gl.enable(gl.SCISSOR_TEST)@@ -131,8 +171,12 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {uploadAtlas(source, sizePx, cellW, cellH, strideX, strideY) {gl.bindTexture(gl.TEXTURE_2D, atlasTex)gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source)- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)+ // MIN belongs to the camera now (see applyAtlasMinFilter), but it is asserted HERE too, and+ // not only in beginFrame: GL's default min filter is NEAREST_MIPMAP_LINEAR, which makes a+ // texture with no mip chain INCOMPLETE (it samples black). Filter params live on the texture+ // object and survive texImage2D, so this is a one-time cost the change gate absorbs.+ applyAtlasMinFilter(cam.zoom)// Columns follow the PITCH (that is how the atlas laid the page out), while the sampled// extent stays the exact cell — mixing the two shifts every glyph by a fraction of a cell.atlasCols = Math.floor(sizePx / strideX)@@ -181,6 +225,9 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {// its node. See `snapPanToDevicePx`; the plate reads the same snapped camera, so plate and// cells can never drift a pixel apart.cam = snapPanToDevicePx(camera, dpr)+ // Resolve the mag/min tie for THIS frame's zoom before anything samples the atlas. Change-+ // gated, so a still camera costs one comparison per frame and zero GL calls.+ applyAtlasMinFilter(cam.zoom)gl.clearColor(0, 0, 0, 0)gl.clear(gl.COLOR_BUFFER_BIT)gl.useProgram(program)@@ -198,7 +245,7 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {// buffer happened to be bound from the previous grid.if (!grid) return- // --- (1) the plate: an opaque scissored clear of the grid rect expanded by padPx. It is+ // --- (1) the plate: an opaque scissored clear of the node BODY's world rect. It is// drawn BEFORE this grid's cells and AFTER everything below it in z, so painter's order// gives total occlusion of overlapping terminals with no depth buffer.drawPlate(g)diff --git a/src/renderer/glyphgrid/gl.ts b/src/renderer/glyphgrid/gl.tsindex ab9975a1d..8a81412b4 100644--- a/src/renderer/glyphgrid/gl.ts+++ b/src/renderer/glyphgrid/gl.ts@@ -20,14 +20,25 @@ export interface GridDrawParams {/** world position of the grid's top-left corner */originX: numberoriginY: number- /** packColor() — the opaque plate drawn BEFORE this grid's cells, covering the grid rect- * expanded by `padPx` on every side. This is the Phase-1 occlusion story: painter's order- * makes it cover anything drawn beneath it (overlapping terminals), and it fills the node- * body's padding around the character matrix. */+ /** packColor() — the colour the plate is cleared to. This is the Phase-1 occlusion story:+ * painter's order makes the plate cover anything drawn beneath it (overlapping terminals). */bgColor: number- /** Plate padding around the grid rect, in WORLD units (scaled by the camera zoom like any- * other world length). */- padPx: number+ /**+ * The PLATE rect in WORLD units (top-left origin, like `originX/originY`): the opaque ground+ * this terminal paints under itself — the transparent DOM window's FULL area, i.e. the node+ * body rect, not the character matrix.+ *+ * The grid may be (and normally is) SMALLER than this: a body's height/width are not exact+ * cell multiples, so xterm letterboxes the remainder, and in shared mode nothing else paints+ * that remainder — the node body is transparent. A plate sized to the grid therefore left a+ * band of raw canvas at the bottom and right of every terminal. The plate is an INDEPENDENT+ * rect for exactly that reason; painter's order still applies to it unchanged (plate first,+ * then this grid's cells, then whatever is drawn above).+ */+ plateX: number+ plateY: number+ plateW: number+ plateH: number}/** Everything engine.ts is allowed to know about the GPU. Draw order is the painter's@@ -65,7 +76,7 @@ export interface GlyphGL {): void/** Clears the frame and sets the camera uniforms. */beginFrame(camera: Camera): void- /** Draws the plate (a scissored clear of the padded grid rect) and then the instanced cells+ /** Draws the plate (a scissored clear of the grid's PLATE rect) and then the instanced cells* from the grid's OWN buffer, in call order (painter's algorithm). */drawGrid(g: GridDrawParams): voidendFrame(): voiddiff --git a/src/renderer/glyphgrid/harness/GlyphGridHarness.tsx b/src/renderer/glyphgrid/harness/GlyphGridHarness.tsxindex db4875fa3..f73edbfb0 100644--- a/src/renderer/glyphgrid/harness/GlyphGridHarness.tsx+++ b/src/renderer/glyphgrid/harness/GlyphGridHarness.tsx@@ -36,9 +36,21 @@ const TOTAL_GRIDS = GRIDS + OVERLAP_GRIDSconst CELL_W = 9const CELL_H = 18const ATLAS_PX = 1024-/** World-unit padding the occlusion plate adds around each grid — a stand-in for the terminal- * node body's inset. Well under the 40/60 layout pitch, so plates stay separated. */-const PAD_PX = 8+/**+ * How far each synthetic grid's PLATE overhangs its character matrix, in world units.+ *+ * The plate is an INDEPENDENT rect now (the node BODY, which is larger than the matrix — see+ * `GridDrawParams.plateX`), so the harness has to keep supplying one that is genuinely bigger than+ * the grid or it would exercise a case the app never runs: a plate-sized-to-grid draws no band, and+ * the overlap trio's occlusion would be judged on the matrices alone. Asymmetric on purpose — 8+ * left/top, 8 + SLACK right/bottom — because the defect this replaced (`padPx`, one symmetric+ * scalar) was invisible precisely at the right and bottom, where a real terminal's fit slack lives.+ *+ * Well under the 40/60 layout pitch, so the 40 disjoint plates still stay separated.+ */+const PLATE_PAD = 8+/** The extra right/bottom overhang, standing in for the fit slack a real body leaves. */+const PLATE_SLACK = 10// --- Layout. Derived, not duplicated: register() below places grids from these same constants,// so the initial camera and the meter can never drift from where the grids actually are. ---@@ -73,6 +85,18 @@ const FIT_MARGIN = 0.92const ZOOM_MIN = 0.05const ZOOM_MAX = 4+/** The plate rect for a grid whose matrix starts at (x, y): the matrix plus PLATE_PAD on every+ * side and PLATE_SLACK more on the right and bottom. One helper so the two register loops below+ * cannot drift apart. */+function plateFor(x: number, y: number): { plateX: number; plateY: number; plateW: number; plateH: number } {+ return {+ plateX: x - PLATE_PAD,+ plateY: y - PLATE_PAD,+ plateW: COLS * CELL_W + 2 * PLATE_PAD + PLATE_SLACK,+ plateH: ROWS * CELL_H + 2 * PLATE_PAD + PLATE_SLACK+ }+}+/*** The camera the harness OPENS on: the whole layout framed in a `w x h` window.*@@ -150,6 +174,8 @@ export function GlyphGridHarness() {const tints: number[] = []for (let i = 0; i < GRIDS; i++) {tints.push(BASE_BG)+ const x = (i % PER_ROW) * PITCH_X+ const y = Math.floor(i / PER_ROW) * PITCH_Yhandles.push(engine.register({id: `t${i}`,@@ -157,13 +183,13 @@ export function GlyphGridHarness() {rows: ROWS,cellW: CELL_W,cellH: CELL_H,- originX: (i % PER_ROW) * PITCH_X,- originY: Math.floor(i / PER_ROW) * PITCH_Y,+ originX: x,+ originY: y,z: i,bgColor: BASE_BG,- // Non-zero so the occlusion plate is actually VISIBLE in the harness: it extends the- // opaque body past the character matrix, the way a terminal node's padding does.- padPx: PAD_PX+ // Larger than the matrix so the occlusion plate is actually VISIBLE in the harness: it+ // is the opaque BODY the terminal paints under itself, the way a node's body is.+ ...plateFor(x, y)}))}@@ -173,6 +199,8 @@ export function GlyphGridHarness() {// to occlude is a defect you can point at rather than argue about.for (let i = 0; i < OVERLAP_GRIDS; i++) {tints.push(OVERLAP_BG[i])+ const x = OVERLAP_X0 + i * OVERLAP_STEP_X+ const y = OVERLAP_Y0 + i * OVERLAP_STEP_Yhandles.push(engine.register({id: `ov${i}`,@@ -180,11 +208,13 @@ export function GlyphGridHarness() {rows: ROWS,cellW: CELL_W,cellH: CELL_H,- originX: OVERLAP_X0 + i * OVERLAP_STEP_X,- originY: OVERLAP_Y0 + i * OVERLAP_STEP_Y,+ originX: x,+ originY: y,z: 100 + i,bgColor: OVERLAP_BG[i],- padPx: PAD_PX+ // Same oversized plate as the disjoint grids — and here it is what the trio is FOR: a+ // higher-z member's plate must bury the band of the member below it, not just its cells.+ ...plateFor(x, y)}))}diff --git a/src/renderer/glyphgrid/plate.test.ts b/src/renderer/glyphgrid/plate.test.tsindex 7adb88b36..ed2e57cb8 100644--- a/src/renderer/glyphgrid/plate.test.ts+++ b/src/renderer/glyphgrid/plate.test.ts@@ -1,20 +1,9 @@import { describe, expect, it } from 'vitest'-import type { GridDrawParams } from './gl'+import type { Rect } from './camera'import { plateRectDevice } from './plate'-/** A 5×2 grid of 8×20 cells → a 40×40 world rect at the given origin. */-const grid = (over: Partial<GridDrawParams> = {}): GridDrawParams => ({- id: 'a',- cols: 5,- rows: 2,- cellW: 8,- cellH: 20,- originX: 10,- originY: 10,- bgColor: 0,- padPx: 0,- ...over-})+/** A 40×40 world rect at the given origin — the shape a small terminal BODY has. */+const plate = (over: Partial<Rect> = {}): Rect => ({ x: 10, y: 10, w: 40, h: 40, ...over })const CAM = { x: 0, y: 0, zoom: 1 }@@ -23,19 +12,19 @@ describe('plateRectDevice', () => {// Derived by hand. World rect (10,10)-(50,50) at zoom 1, pan 0 → the same in CSS px. At// dpr 1 that is device px too. GL's scissor origin is BOTTOM-left, so the rect's device y is// the distance from the buffer's BOTTOM to the rect's BOTTOM edge: 100 - 50 = 50.- expect(plateRectDevice(grid(), CAM, 1, 200, 100)).toEqual({ x: 10, y: 50, w: 40, h: 40 })+ expect(plateRectDevice(plate(), CAM, 1, 200, 100)).toEqual({ x: 10, y: 50, w: 40, h: 40 })})it('scales into device pixels by dpr, not by devicePixelRatio at call time', () => {// Same world rect at dpr 2 against a 400×200 drawing buffer: every extent doubles and the// flip is taken against the DEVICE height (200 - (20 + 80) = 100), never the CSS one.- expect(plateRectDevice(grid(), CAM, 2, 400, 200)).toEqual({ x: 20, y: 100, w: 80, h: 80 })+ expect(plateRectDevice(plate(), CAM, 2, 400, 200)).toEqual({ x: 20, y: 100, w: 80, h: 80 })})it('applies the camera: pan then zoom, exactly as the vertex shader does', () => {// screen = world * zoom + pan. Origin (10,10) at zoom 2 pan (5,5) → CSS (25,25), extent 80.// Flip: 200 - (25 + 80) = 95.- expect(plateRectDevice(grid(), { x: 5, y: 5, zoom: 2 }, 1, 400, 200)).toEqual({+ expect(plateRectDevice(plate(), { x: 5, y: 5, zoom: 2 }, 1, 400, 200)).toEqual({x: 25,y: 95,w: 80,@@ -43,14 +32,17 @@ describe('plateRectDevice', () => {})})- it('expands the rect by padPx on every side, in world units', () => {- // padPx 5 grows the 40×40 rect to 50×50 and moves its top-left to (5,5).- // Flip: 100 - (5 + 50) = 45.- expect(plateRectDevice(grid({ padPx: 5 }), CAM, 1, 200, 100)).toEqual({- x: 5,- y: 45,- w: 50,- h: 50+ it('takes the rect it is GIVEN — it does not derive one from the grid geometry', () => {+ // The regression this signature exists to prevent. The plate is the node BODY, which is+ // larger than the character matrix in both axes (a body's size is not an exact cell multiple,+ // and xterm letterboxes the remainder); a plate re-derived from cols×cellW leaves exactly that+ // remainder showing raw canvas at the bottom and right — the reported bands.+ // Body (4,4) 52×54 while the matrix would be (10,10) 40×40. Flip: 100 - (4 + 54) = 42.+ expect(plateRectDevice({ x: 4, y: 4, w: 52, h: 54 }, CAM, 1, 200, 100)).toEqual({+ x: 4,+ y: 42,+ w: 52,+ h: 54})})@@ -59,7 +51,7 @@ describe('plateRectDevice', () => {// outside the viewport, but pushing the origin to 0 without shrinking the extent would move// the far edge — and a NEGATIVE extent is a GL_INVALID_VALUE.// Visible CSS span: x 0..30, y 0..30 → device y from 100-30 = 70, height 30.- expect(plateRectDevice(grid({ originX: -10, originY: -10 }), CAM, 1, 200, 100)).toEqual({+ expect(plateRectDevice(plate({ x: -10, y: -10 }), CAM, 1, 200, 100)).toEqual({x: 0,y: 70,w: 30,@@ -70,13 +62,21 @@ describe('plateRectDevice', () => {it('is null when the rect is entirely off-screen', () => {// Null, not a zero-area rect: the caller must SKIP the clear, and a {w:0,h:0} scissor would// still cost the state changes around it.- expect(plateRectDevice(grid({ originX: 500 }), CAM, 1, 200, 100)).toBeNull()- expect(plateRectDevice(grid({ originY: -500 }), CAM, 1, 200, 100)).toBeNull()+ expect(plateRectDevice(plate({ x: 500 }), CAM, 1, 200, 100)).toBeNull()+ expect(plateRectDevice(plate({ y: -500 }), CAM, 1, 200, 100)).toBeNull()})it('is null when the rect touches an edge without covering a pixel', () => {// A 40-wide rect at x=-40 ends exactly at x=0: it shares an edge with the viewport and// covers zero pixels, so it must be null rather than a zero-width scissor.- expect(plateRectDevice(grid({ originX: -40 }), CAM, 1, 200, 100)).toBeNull()+ expect(plateRectDevice(plate({ x: -40 }), CAM, 1, 200, 100)).toBeNull()+ })++ it('is null for a zero-extent plate (an unmeasured body), never a degenerate scissor', () => {+ // `bodyPlateRect` collapses a non-finite/negative client size to 0 rather than propagating a+ // NaN. That reaches here as a zero-area rect, and the contract is the same as off-screen:+ // skip the clear.+ expect(plateRectDevice(plate({ w: 0 }), CAM, 1, 200, 100)).toBeNull()+ expect(plateRectDevice(plate({ h: 0 }), CAM, 1, 200, 100)).toBeNull()})})diff --git a/src/renderer/glyphgrid/plate.ts b/src/renderer/glyphgrid/plate.tsindex 703ef60e1..433b9ffed 100644--- a/src/renderer/glyphgrid/plate.ts+++ b/src/renderer/glyphgrid/plate.ts@@ -1,5 +1,4 @@-import type { Camera } from './camera'-import type { GridDrawParams } from './gl'+import type { Camera, Rect } from './camera'/** A rectangle in DEVICE pixels with a BOTTOM-LEFT origin — GL's scissor convention, not the* browser's. Deliberately not camera.ts's `Rect`: that one is world-space and top-left, and@@ -12,11 +11,16 @@ export interface DeviceRect {}/**- * The occlusion plate's scissor rect: the grid's world rect expanded by `padPx`, projected- * through the camera and clamped to the drawing buffer. Pure, so the four coordinate hops below- * are testable without a GL context — which is the point of the extraction, since a Y-flip or a+ * The occlusion plate's scissor rect: the plate's WORLD rect (`GridDrawParams.plateX/Y/W/H` — the+ * node body's full area, which is generally LARGER than the character matrix), projected through+ * the camera and clamped to the drawing buffer. Pure, so the four coordinate hops below are+ * testable without a GL context — which is the point of the extraction, since a Y-flip or a* missing `* dpr` is invisible in a code review and obvious in a unit test.*+ * Takes the rect itself rather than the whole `GridDrawParams`: the plate stopped being derived+ * from the grid geometry (it was `grid rect + padPx`, which is what left bands of raw canvas at+ * the bottom and right of every terminal), so there is nothing here that needs cols/rows/cellW.+ ** Returns null when the rect covers no pixel of the drawing buffer: the caller must SKIP the* clear entirely. A clamped-empty rect is not merely wasteful — a NEGATIVE scissor extent is a* GL_INVALID_VALUE, and clamping the origin to 0 without shrinking the extent would silently@@ -31,17 +35,17 @@ export interface DeviceRect {* 4. Clamp to [0, deviceW] × [0, deviceH].*/export function plateRectDevice(- g: GridDrawParams,+ plate: Rect,cam: Camera,dpr: number,deviceW: number,deviceH: number): DeviceRect | null {// (1) world → screen (CSS px).- const leftCss = (g.originX - g.padPx) * cam.zoom + cam.x- const topCss = (g.originY - g.padPx) * cam.zoom + cam.y- const wCss = (g.cols * g.cellW + 2 * g.padPx) * cam.zoom- const hCss = (g.rows * g.cellH + 2 * g.padPx) * cam.zoom+ const leftCss = plate.x * cam.zoom + cam.x+ const topCss = plate.y * cam.zoom + cam.y+ const wCss = plate.w * cam.zoom+ const hCss = plate.h * cam.zoom// (2) CSS px → DEVICE px.const left = Math.round(leftCss * dpr)const top = Math.round(topCss * dpr)diff --git a/src/renderer/lib/glyphGridNode.test.ts b/src/renderer/lib/glyphGridNode.test.tsindex e6a4afe69..4c8a42669 100644--- a/src/renderer/lib/glyphGridNode.test.ts+++ b/src/renderer/lib/glyphGridNode.test.ts@@ -2,9 +2,9 @@ import { describe, expect, it } from 'vitest'import { unpackColor } from '../glyphgrid/cells'import {DEFAULT_TERMINAL_BG,+ bodyPlateRect,bodyWorldRect,packThemeBg,- platePadPx,validCellSize} from './glyphGridNode'@@ -22,28 +22,57 @@ describe('bodyWorldRect', () => {})})-describe('platePadPx', () => {- it('takes the MAXIMUM side, so no padded strip is left uncovered', () => {- // .term-node__xterm's real padding: 4px 2px 2px 6px. The node body is transparent under- // `.term-node--glyphgrid`, so a strip the plate misses shows raw canvas while one it- // over-covers hides under the node's own opaque chrome — the max leaves nothing bare.- expect(platePadPx({ top: 4, right: 2, bottom: 2, left: 6 })).toBe(6)+describe('bodyPlateRect', () => {+ it('is the body box in world space: node position + body offset, at the body client size', () => {+ expect(bodyPlateRect({ x: 100, y: 200 }, { x: 0, y: 28 }, 480, 300)).toEqual({+ x: 100,+ y: 228,+ w: 480,+ h: 300+ })})- it('passes a symmetric padding through', () => {- expect(platePadPx({ top: 8, right: 8, bottom: 8, left: 8 })).toBe(8)+ it('CONTAINS a grid the cell fit could not fill — the whole point of the rect', () => {+ // The reported defect, in numbers. A 300px-tall body at a 20px cell fits 15 rows exactly, but+ // a 310px one fits 15 and letterboxes 10px; the host's padding (4px top, 2px bottom) does not+ // reach that. The plate is the BODY, so the band is inside it whatever the fit leaves over.+ const plate = bodyPlateRect({ x: 0, y: 0 }, { x: 0, y: 0 }, 500, 310)+ const gridBottom = 4 + 15 * 20 // body padding-top + the rows that fit+ expect(plate.h).toBeGreaterThan(gridBottom)+ expect(plate.y + plate.h).toBe(310)})- it('is 0 for a zero padding — the plate is then exactly the grid rect', () => {- expect(platePadPx({ top: 0, right: 0, bottom: 0, left: 0 })).toBe(0)+ it('handles negative world positions (the canvas has no origin quadrant)', () => {+ expect(bodyPlateRect({ x: -1200.5, y: -40 }, { x: 6, y: 34 }, 200, 100)).toEqual({+ x: -1194.5,+ y: -6,+ w: 200,+ h: 100+ })+ })++ it('collapses a non-finite extent to 0 rather than propagating NaN into a GL scissor', () => {+ // An element that is not laid out yet reports a garbage/zero client box. 0 is a rect the+ // plate math answers `null` for (skip the clear); NaN would reach glScissor.+ expect(bodyPlateRect({ x: 0, y: 0 }, { x: 0, y: 0 }, NaN, 100)).toEqual({+ x: 0,+ y: 0,+ w: 0,+ h: 100+ })+ expect(bodyPlateRect({ x: 0, y: 0 }, { x: 0, y: 0 }, 100, Infinity)).toMatchObject({ h: 0 })})- it('collapses negative sides to 0 rather than growing the rect off a bad parse', () => {- expect(platePadPx({ top: -4, right: -2, bottom: -2, left: -6 })).toBe(0)+ it('collapses a negative extent to 0', () => {+ expect(bodyPlateRect({ x: 0, y: 0 }, { x: 0, y: 0 }, -20, -1)).toMatchObject({ w: 0, h: 0 })})- it('collapses an unparseable (NaN) side to 0', () => {- expect(platePadPx({ top: NaN, right: 2, bottom: 2, left: 6 })).toBe(0)+ it('shares its origin with bodyWorldRect — one sum, two callers', () => {+ const pos = { x: 12.5, y: -3 }+ const off = { x: 6, y: 34 }+ const origin = bodyWorldRect(pos, off)+ const plate = bodyPlateRect(pos, off, 10, 10)+ expect({ x: plate.x, y: plate.y }).toEqual(origin)})})diff --git a/src/renderer/lib/glyphGridNode.ts b/src/renderer/lib/glyphGridNode.tsindex 11633cba1..f4f6eb430 100644--- a/src/renderer/lib/glyphGridNode.ts+++ b/src/renderer/lib/glyphGridNode.ts@@ -16,14 +16,6 @@ export interface Vec2 {y: number}-/** CSS insets, in world units (canvas CSS px at zoom 1). */-export interface Insets {- top: number- right: number- bottom: number- left: number-}-/*** World position of the grid's TOP-LEFT CELL.*@@ -41,32 +33,47 @@ export function bodyWorldRect(nodePos: Vec2, bodyOffset: Vec2): Vec2 {return { x: nodePos.x + bodyOffset.x, y: nodePos.y + bodyOffset.y }}+/** A world-space rectangle, top-left origin — the engine's plate rect (`GridSpec.plateX/Y/W/H`). */+export interface WorldRect {+ x: number+ y: number+ w: number+ h: number+}+/**- * The engine's plate padding — ONE scalar, expanded on all four sides (see `GridSpec.padPx`) —- * resolved from the terminal host's CSS padding, which is NOT symmetric (`.term-node__xterm` is- * `4px 2px 2px 6px`).+ * The opaque plate's world rect: the terminal BODY's full area.*- * The MAXIMUM is the safe reduction, and WHICH end is safe is decided by the node's background. A- * glyph-attached terminal is a transparent WINDOW onto the shared canvas (`.term-node--glyphgrid`- * drops the background from the node root and its body), so the plate IS the terminal's- * background: ground the plate does not cover shows raw canvas, while ground it over-covers is- * hidden under the node's own opaque DOM chrome, which paints above the canvas. Under-covering is- * the visible failure; over-covering is free.+ * A glyph-attached terminal is a transparent WINDOW onto the shared canvas+ * (`.term-node--glyphgrid` drops the background from the node root and its body), so the plate IS+ * the terminal's background — every square of body the plate does not cover shows raw canvas+ * through the node. The GRID cannot supply that rect: a body's width/height are not exact cell+ * multiples, so xterm letterboxes the remainder, and the plate is therefore sized to the BODY+ * (`bodyEl.clientWidth/clientHeight`) rather than derived from cols×cellW.*- * This was the MINIMUM while the plan still called for an opaque node body — the reasoning- * inverted with it. Do not restore the minimum without restoring that opaque body too.+ * This replaced a `padPx` scalar taken from the host's asymmetric CSS padding (`4px 2px 2px 6px`,+ * reduced to its 6px maximum). That covered the left/top insets and nothing else, which is exactly+ * why bands showed at the BOTTOM and RIGHT — the fit slack there routinely exceeds 6px, and a+ * letterboxed node's bands are tens of pixels. The padding does not need reading at all now: it+ * lies INSIDE the body box, so a body-sized plate covers it on all four sides.*- * Negative/NaN inputs (a computed style that failed to parse) collapse to 0 rather than- * propagating into the engine's rect math.+ * `nodePos` + `bodyOffset` is the same LAYOUT sum `bodyWorldRect` does (zoom-independent — the+ * canvas transform scales pixels, not offsets). Non-finite or negative extents (an element that+ * is not laid out yet) collapse to 0 rather than propagating a NaN into the engine's rect math and+ * from there into a GL scissor.*/-export function platePadPx(pad: Insets): number {- const sides = [pad.top, pad.right, pad.bottom, pad.left]- let max = 0- for (const v of sides) {- if (!Number.isFinite(v)) return 0- if (v > max) max = v- }- return max+export function bodyPlateRect(+ nodePos: Vec2,+ bodyOffset: Vec2,+ bodyW: number,+ bodyH: number+): WorldRect {+ const origin = bodyWorldRect(nodePos, bodyOffset)+ return { x: origin.x, y: origin.y, w: extent(bodyW), h: extent(bodyH) }+}++function extent(v: number): number {+ return Number.isFinite(v) && v > 0 ? v : 0}/** Fallback background — the colour `TerminalNode` builds every xterm with. Used when the themediff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex f95bb0b2b..4622ed9a1 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -65,11 +65,10 @@ import {useSharedGlyph} from '../canvas/SharedGlyphLayer'import {+ bodyPlateRect,bodyWorldRect,packThemeBg,- platePadPx,validCellSize,- type Insets,type Vec2} from '../lib/glyphGridNode'import { deliverCommand, type DeliveryIo } from '../terminal/command-delivery'@@ -310,7 +309,20 @@ function glyphWarn(key: string, message: string): void {* never reaches a `.react-flow__node` (a parked, detached element).*/function screenOffsetInNode(term: Terminal): Vec2 | null {- const el = (term.element?.querySelector('.xterm-screen') as HTMLElement | null) ?? term.element+ return offsetInNode(+ (term.element?.querySelector('.xterm-screen') as HTMLElement | null) ?? term.element ?? null+ )+}++/**+ * The `offsetParent` walk itself — see `screenOffsetInNode` for the coordinate contract.+ *+ * Called with two different elements, which is why it is not folded back into that one. The+ * terminal SCREEN places the grid; the terminal BODY (`.term-node__body`) places the opaque PLATE.+ * The body is the node's transparent window onto the shared canvas, so its offset + client size IS+ * the ground the plate owes — and `.term-node__xterm`'s padding lies inside it, covered for free.+ */+function offsetInNode(el: HTMLElement | null): Vec2 | null {if (!el) return nulllet x = 0let y = 0@@ -326,18 +338,6 @@ function screenOffsetInNode(term: Terminal): Vec2 | null {return null}-/** The terminal host's CSS padding, which the plate covers. Unparseable sides come back NaN and- * `platePadPx` collapses them to 0 — the engine never sees one. */-function hostPadding(el: HTMLElement): Insets {- const cs = getComputedStyle(el)- return {- top: parseFloat(cs.paddingTop),- right: parseFloat(cs.paddingRight),- bottom: parseFloat(cs.paddingBottom),- left: parseFloat(cs.paddingLeft)- }-}-/*** xterm's CSS cell size, read off whatever renderer the render service currently holds.*@@ -572,6 +572,11 @@ export function TerminalNode({// in the default renderer modes, which is what makes the effects below a single null check.const glyphGridRef = useRef<GridHandle | null>(null)const glyphBodyOffsetRef = useRef<Vec2>({ x: 0, y: 0 })+ /** The PLATE's box in NODE-relative layout coordinates — the body's offset inside the node plus+ * its client size. Kept apart from `glyphBodyOffsetRef` (which tracks `.xterm-screen`) because+ * plate and grid are independent rects; the position effect below re-derives the plate's world+ * origin from this while the node is dragged, without re-measuring the DOM per frame. */+ const glyphPlateBoxRef = useRef<{ offset: Vec2; w: number; h: number } | null>(null)// Mutated (never reassigned) so the lifecycle effect's closures read the CURRENT position without// re-running; a drag rewrites these two numbers per frame.const nodePosRef = useRef<Vec2>({ x: positionAbsoluteX, y: positionAbsoluteY })@@ -1119,16 +1124,41 @@ export function TerminalNode({// respawn for it. Teardown ordering is only correct while the grid's lifetime is nested inside// the terminal's.- /** Push the grid to where the terminal screen actually is, re-measuring the screen's offset- * inside the node. One null check when this terminal holds no grid. */+ /**+ * Push the grid to where the terminal screen actually is, and the PLATE to where the body is,+ * re-measuring both offsets inside the node. One null check when this terminal holds no grid.+ *+ * Two independent rects on purpose (see `GridSpec.plateX`): the grid follows `.xterm-screen`+ * and the plate follows `.term-node__body`, which is larger — the character matrix rarely+ * divides the body exactly, and the leftover bands at the bottom/right are transparent node,+ * i.e. raw canvas, unless the plate covers them. Both mutators change-gate themselves, so a+ * settle tick that moved neither costs two comparisons.+ */const syncGridOrigin = (): void => {const grid = glyphGridif (!grid) returnconst offset = screenOffsetInNode(term)- if (!offset) return- glyphBodyOffsetRef.current = offset- const origin = bodyWorldRect(nodePosRef.current, offset)- grid.setOrigin(origin.x, origin.y)+ if (offset) {+ glyphBodyOffsetRef.current = offset+ const origin = bodyWorldRect(nodePosRef.current, offset)+ grid.setOrigin(origin.x, origin.y)+ }+ const plate = measurePlateRect()+ if (plate) grid.setPlateRect(plate.x, plate.y, plate.w, plate.h)+ }++ /** The body's world rect — the plate. Null when the body is not laid out inside a React Flow+ * node (a parked, detached element): leave the plate where it is rather than collapse it. */+ const measurePlateRect = (): { x: number; y: number; w: number; h: number } | null => {+ const offset = offsetInNode(container)+ if (!offset) return null+ // `clientWidth/Height` at the RO tick, the same measurement that positions the grid: LAYOUT+ // px, so it is zoom-independent and already in world units (the canvas transform scales+ // rendered pixels, never offsets or client boxes).+ const w = container.clientWidth+ const h = container.clientHeight+ glyphPlateBoxRef.current = { offset, w, h }+ return bodyPlateRect(nodePosRef.current, offset, w, h)}/**@@ -1215,6 +1245,16 @@ export function TerminalNode({}glyphBodyOffsetRef.current = offsetconst origin = bodyWorldRect(nodePosRef.current, offset)+ // The plate is the BODY rect, measured here so the grid is never registered with a+ // zero/absent plate that a later RO tick has to repair — a frame of un-plated terminal is a+ // frame of dot grid showing through the node. Falls back to the CELL rect (the pre-fix+ // behaviour, minus the padding) if the body cannot be measured; the RO tick corrects it.+ const plate = measurePlateRect() ?? {+ x: origin.x,+ y: origin.y,+ w: term.cols * cell.cellW,+ h: term.rows * cell.cellH+ }let handle: GridHandletry {handle = ctx.engine.register({@@ -1232,9 +1272,12 @@ export function TerminalNode({// The theme background this xterm was built with — the colour the plate clears to, so a// grid's own background matches the terminal it belongs to.bgColor: packThemeBg(term.options.theme?.background),- // The host's CSS padding (`.term-node__xterm`, `4px 2px 2px 6px`) reduced to the one- // scalar the engine takes; see `platePadPx` for why it is the MAXIMUM side.- padPx: platePadPx(hostPadding(container))+ // The opaque ground this terminal paints under itself: the BODY rect, not the character+ // matrix. See `bodyPlateRect` for why the host's CSS padding no longer appears here.+ plateX: plate.x,+ plateY: plate.y,+ plateW: plate.w,+ plateH: plate.h})} catch (err) {glyphWarn(`${id}:register`, `could not register a grid for node ${id}: ${String(err)}`)@@ -2083,11 +2126,17 @@ export function TerminalNode({useEffect(() => {const grid = glyphGridRef.currentif (!grid) return- const origin = bodyWorldRect(- { x: positionAbsoluteX, y: positionAbsoluteY },- glyphBodyOffsetRef.current- )+ const nodePos = { x: positionAbsoluteX, y: positionAbsoluteY }+ const origin = bodyWorldRect(nodePos, glyphBodyOffsetRef.current)grid.setOrigin(origin.x, origin.y)+ // The PLATE travels with the node too, and from the SAME cached box — a drag moves the node,+ // never the body's offset or size inside it, so this is arithmetic rather than a DOM+ // measurement sixty times a second. Skipped until the body has been measured once (the+ // register path does that), so a drag can never collapse the plate to a zero rect.+ const box = glyphPlateBoxRef.current+ if (!box) return+ const plate = bodyPlateRect(nodePos, box.offset, box.w, box.h)+ grid.setPlateRect(plate.x, plate.y, plate.w, plate.h)}, [positionAbsoluteX, positionAbsoluteY])// Live-apply font/cursor/scrollback settings to the running terminal, so a Settings changediff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex e67c8db8e..3d21feab6 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -1618,8 +1618,9 @@ body,nodes (z-index 0 against the renderer's 4 — it cannot simply be raised above them, or aterminal's glyphs would paint over any sticky / editor / subagent chrome that overlaps its bodyrect; the plate only orders terminals among themselves). So the node root and its body give up- their backgrounds, and the grid's own opaque PLATE — the packed theme background, expanded by- padPx — becomes the terminal body's background. That is precisely what the plate is for.+ their backgrounds, and the grid's own opaque PLATE — the packed theme background, sized to the+ BODY's own rect — becomes the terminal body's background. That is precisely what the plate is+ for.The class is on the root only while a grid is ACTUALLY attached, so collapse, the ⌘M view, afailed attach and every default renderer mode leave the node opaque exactly as today.@@ -1631,20 +1632,18 @@ body,background) and the strip under the header showed the raw canvas through the node. The selectionring and the unread glow are border-color + box-shadow, both independent of the background.- Accepted degradations, all plate GEOMETRY, all Phase 2's call (a rounded / stencilled plate, or- a plate sized to the BODY rect instead of the grid rect) and all judged on the device checklist.- `padPx` is ONE symmetric scalar taken from the LARGEST side of the host's `4px 2px 2px 6px`- padding (= 6; see `lib/glyphGridNode.ts` `platePadPx`), which covers the left and top insets- completely — over-covering them is free, since the node's own opaque chrome paints above the- canvas. What is left:- 1. the plate is a square rect while the node has border-radius 10px, so the body's corners read- square in shared mode (the node's `overflow: hidden` clips DOM children, and the canvas is- not one);- 2. the right/bottom edges do not land exactly: a fit leaves up to one cell of slack there, so- when the slack EXCEEDS 6px a strip of that slack shows the canvas behind the node instead of- the terminal background, and when it is under 6px the plate reaches up to ~4px past the- node's outer edge — visible only against the canvas, since a neighbouring node's DOM paints- over it. */+ The plate is the BODY rect (`lib/glyphGridNode.ts` `bodyPlateRect`: the body's offset inside the+ node plus its client size, pushed on the ResizeObserver's settled tick and carried along by the+ position effect during a drag). It is deliberately NOT derived from the grid: cols×cellW rarely+ divides a body exactly, xterm letterboxes the remainder, and nothing else paints it — a+ grid-sized plate is what left a band of raw dot grid at the bottom and right of every terminal,+ and tens of pixels of it on a letterboxed co-attach node. Being body-sized, it also swallows the+ host's asymmetric `4px 2px 2px 6px` padding, which lies inside the body box, on all four sides.++ ONE accepted degradation is left, and it is Phase 2's call (a rounded / stencilled plate),+ judged on the device checklist: the plate is a square rect while the node has border-radius+ 10px, so the body's corners read square in shared mode — the node's `overflow: hidden` clips DOM+ children, and the canvas is not one. */.term-node--glyphgrid,.term-node--glyphgrid .term-node__body {background: transparent;