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
feat(glyphgrid): the occlusion plate is a rounded quad, not a rectangle
enes86d14b29a947
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.mdindex 1cd5ecdd9..4a62b52a0 100644--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md@@ -247,12 +247,24 @@ Auto after you switched builds, that is why: re-select Shared and carry on.terminal) and back to `outline`. **The outline is the DEFAULT** — every terminal on the canvasexcept the focused one is drawing it, so judge it at normal zoom on a busy canvas, not only onone node.-- [ ] **2.13 Plate geometry.** Look at the four corners and the right/bottom edges of a terminal- 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 —+- [ ] **2.13 Plate geometry, and the rounded corners.** Look at the four corners and the+ right/bottom edges of a terminal 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 plate+ is a rounded QUAD now rather than a square clear, so the body's two **bottom** corners follow+ the node's own `border-radius` and no square shoulder pokes out past the node's curve. Put a+ shared terminal over something that makes the corner visible (a group frame, another node,+ the light theme) and check four things: the curve **matches the node's own chrome** — compare+ it with the rounded header at the top of the same node, and with a DOM-renderer terminal+ beside it, in BOTH themes; the corner is **smooth, not stepped**; the **straight** edges are+ still opaque edge-to-edge, with no half-lit hairline of canvas along them; and the **top two+ corners stay square**, which is correct — they sit against the opaque header/labels row and+ are not corners on screen, so rounding them would carve a notch of canvas out of the body.+ Then **zoom out to ~0.3 and in to ~3**: the corner keeps its proportion at every zoom, and it+ never inverts into a corner-shaped hole. Finally **drag a node's bottom edge up until the+ body collapses to a few pixels tall** — the radius clamps at half the shorter side, so the+ plate goes stadium-shaped and then to a sliver; what must not appear at any point is a+ flash of missing background. Report any band you still see —a band now means the plate rect is not tracking the body, not that it is undersized bydesign. **Judge bands only AFTER a resize gesture settles.** The plate is re-pushed on theResizeObserver's coalesced tick (80 ms after the last resize event — the same settle the@@ -479,9 +491,6 @@ Auto after you switched builds, that is why: re-select Shared and carry on.- **L1 — The cursor does not blink.** The shared renderer paints a static block cursor regardlessof the "Cursor blink" setting. Decide on device whether this ships as-is or the setting should begated in shared mode.-- **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 shared- mode. Phase 2: rounded/stencilled plate.- **L5 — FIXED in round 2 (bands at the bottom/right).** Kept here as the record, because it is theone item on this list whose expected observation INVERTED. It used to read: the plate covers thegrid plus one scalar of host padding (`padPx`, the 6px max of `.term-node__xterm`'s asymmetric@@ -493,8 +502,9 @@ Auto after you switched builds, that is why: re-select Shared and carry on.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 meansthe 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.+ The plate's square CORNERS were a separate question from its size — no rect size ever fixed them+ — and they are answered separately too: the plate is a rounded quad as of Phase 2, so the SHAPE+ is item **2.13** and the SIZE is this entry.- **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/engine.test.ts b/src/renderer/glyphgrid/engine.test.tsindex 2f330497b..7e5df9050 100644--- a/src/renderer/glyphgrid/engine.test.ts+++ b/src/renderer/glyphgrid/engine.test.ts@@ -769,11 +769,28 @@ describe('plate params', () => {plateY: -4,plateW: 40,plateH: 44,+ // A grid registered without a radius plates a SQUARE rect — bit-for-bit the shape every+ // grid had before the plate became a quad, which is what keeps this expectation (and the+ // harness, which registers no radius either) meaning what it always meant.+ plateRadius: 0,// A grid nobody has told about a cursor draws none — the overlay pass is skipped whole.cursor: null}])})++ it('carries the plate RADIUS from the spec to drawGrid', () => {+ const gl = fakeGL()+ const e = new GlyphGridEngine(gl, atlas())+ e.setViewport(800, 600, 1)+ e.setCamera({ x: 0, y: 0, zoom: 1 })+ // WORLD units — the node's own corner radius at zoom 1. The engine neither scales nor clamps+ // it: that is `plateRadiusDevice`'s job, once per draw, because both things it clamps against+ // (the camera and the plate's device extent) are known only at draw time.+ e.register(spec('a', 0, 0, { plateRadius: 9 }))+ e.frame()+ expect(gl.params.at(-1)).toMatchObject({ plateRadius: 9 })+ })})/** THE CURSOR OVERLAY — the per-grid spec the GL layer turns into a bar / underline / outline.diff --git a/src/renderer/glyphgrid/engine.ts b/src/renderer/glyphgrid/engine.tsindex 520280b79..32e7ecf66 100644--- a/src/renderer/glyphgrid/engine.ts+++ b/src/renderer/glyphgrid/engine.ts@@ -26,6 +26,22 @@ export interface GridSpec {plateY: numberplateW: numberplateH: number+ /**+ * The plate's corner radius in world units — the node's own `border-radius`, so the opaque+ * ground under a rounded node stops reading square (see `GridDrawParams.plateRadius`, which+ * states which corners it shapes and why).+ *+ * OPTIONAL, defaulting to 0 = square, for two reasons that point the same way: 0 reproduces the+ * plate's pre-Phase-2 shape exactly, and a surface with no rounded chrome of its own (the dev+ * harness) should not have to name a radius to say so.+ *+ * REGISTRATION-TIME ONLY — there is deliberately no `setPlateRadius` on the handle. The radius+ * comes from a stylesheet constant, not from layout: unlike the plate RECT (which a+ * ResizeObserver re-pushes on every tick) nothing moves it while a node lives, and the paths+ * that could change it — a font/theme generation bump — already tear the grid down and register+ * a fresh one. Add a setter when something can actually change it, not before.+ */+ plateRadius?: number}export interface GridHandle {@@ -514,6 +530,10 @@ export class GlyphGridEngine {plateY: g.plateY,plateW: g.plateW,plateH: g.plateH,+ // `?? 0` here rather than at registration, so an omitted radius reads as "square" at+ // the one place that has to answer the GL layer — and `GridSpec.plateRadius` stays+ // honestly optional instead of being silently rewritten on the grid.+ plateRadius: g.plateRadius ?? 0,cursor: g.cursor})}diff --git a/src/renderer/glyphgrid/gl-webgl2.ts b/src/renderer/glyphgrid/gl-webgl2.tsindex b11cc8570..6d3ca319d 100644--- a/src/renderer/glyphgrid/gl-webgl2.ts+++ b/src/renderer/glyphgrid/gl-webgl2.ts@@ -3,7 +3,7 @@ import { snapPanToDevicePx, type Camera } from './camera'import { CELL_STRIDE, unpackColor } from './cells'import { cursorOverlays, cursorThicknessWorld, MAX_CURSOR_RECTS } from './cursor'import type { GlyphGL, GridDrawParams } from './gl'-import { plateRectDevice } from './plate'+import { plateRadiusDevice, plateRectDevice, plateShapeDevice } from './plate'/*** The deepest mip level the atlas may ever be sampled at (`TEXTURE_MAX_LOD`).@@ -169,6 +169,70 @@ uniform vec4 uColor;out vec4 outColor;void main() { outColor = uColor; }`+/**+ * The OCCLUSION PLATE program: one quad per grid, its corners shaped by a rounded-rect SDF.+ *+ * It replaced a scissored `gl.clear`, which was a rectangle by construction — and a node has+ * `border-radius`, while a canvas that is not that node's DOM child cannot be clipped by it. That+ * mismatch is limitation L4: every shared terminal's body corners read square against its own+ * rounded chrome. Rounding needs the plate to be DRAWN rather than cleared, which is this program.+ *+ * DEVICE SPACE, NOT WORLD SPACE — the one thing that makes it different from every other shader in+ * this file. A corner radius is authored against the node's own pixels, and the shape has to stay+ * pixel-exact under a camera the user pans by fractions of a pixel, so the rect and the radius are+ * projected on the CPU (`plateShapeDevice` / `plateRadiusDevice`, both pure and unit-tested) and+ * arrive here already in device px. `gl_FragCoord.xy` is in exactly those coordinates. It is also+ * why NEITHER shader below flips Y: the device rect is already bottom-up, GL's own convention.+ */+const PLATE_VERT = `#version 300 es+uniform vec4 uQuad; // x, y, w, h in DEVICE px, bottom-left origin — the VISIBLE part of the plate+uniform vec2 uDevice; // drawing-buffer size in device px+void main() {+ int corner = gl_VertexID;+ vec2 unit = vec2((corner == 1 || corner == 4 || corner == 5) ? 1.0 : 0.0,+ (corner == 2 || corner == 3 || corner == 5) ? 1.0 : 0.0);+ // No Y flip: uQuad is already bottom-up, and so is NDC. Every other vertex shader here starts+ // from top-left world/CSS coordinates and has to flip; this one would DOUBLE-flip if it did.+ gl_Position = vec4((uQuad.xy + unit * uQuad.zw) / uDevice * 2.0 - 1.0, 0.0, 1.0);+}`++const PLATE_FRAG = `#version 300 es+precision highp float;+uniform vec4 uRect; // the WHOLE plate rect (x, y, w, h) in device px — never the clipped one+uniform float uRadius; // corner radius in device px, already clamped to half the shorter side+uniform vec4 uColor;+out vec4 outColor;+void main() {+ vec2 halfExtent = uRect.zw * 0.5;+ vec2 p = gl_FragCoord.xy - (uRect.xy + halfExtent);+ // ONLY THE BOTTOM CORNERS ARE ROUNDED, and this line is the whole of that rule. The plate rect+ // is a node BODY, and the body is the node's LAST child: its bottom edge IS the node's bottom+ // (rounded, with nothing behind it but canvas), while its top edge is an interior seam against+ // opaque chrome — the header, the labels row, the find bar. Rounding the top corners would not+ // shape a visible corner at all, it would carve two wedges out of the body that nothing else+ // paints, i.e. trade L4 for a new artifact. Device Y grows UP, so the node's visual bottom is+ // the p.y < 0 half.+ //+ // The two halves cannot seam: away from a corner the rounded and square fields are IDENTICAL+ // (the inner box is inset by r on both axes and the distance has r added back), so they agree+ // exactly along p.y = 0, which is the mid-height of the body and as far from a corner as a+ // fragment gets.+ float r = p.y < 0.0 ? uRadius : 0.0;+ vec2 q = abs(p) - (halfExtent - vec2(r));+ float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;+ // ONE DEVICE PIXEL OF COVERAGE, CENTRED ON THE EDGE — so the corner is antialiased instead of+ // stepped (a hard corner on the terminal's own background reads as a rendering fault, not as a+ // shape), while a STRAIGHT edge stays fully opaque. That centring is load-bearing and is where+ // this deviates from the obvious "1.0 - smoothstep(-1.0, 0.0, d)": the plate's device rect is+ // rounded to whole pixels, so an edge lands exactly on a pixel BOUNDARY, whose neighbouring+ // fragment centres sit at d = -0.5 (inside) and d = +0.5 (outside). A window centred on 0 puts+ // those at alpha 1 and 0 — the same pixels the old clear wrote, exactly. A window running+ // from -1 to 0 would put the last inside row at alpha 0.5 and let a half-covered line of the+ // TRANSPARENT node body (i.e. raw canvas) show around all four straight edges: the band this+ // plate exists to remove.+ outColor = vec4(uColor.rgb, uColor.a * clamp(0.5 - d, 0.0, 1.0));+}`+export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {const gl = canvas.getContext('webgl2', { alpha: true, antialias: false, depth: false })if (!gl) return null@@ -203,6 +267,22 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {/** Scratch for the overlay's rect uniforms — one allocation for the life of the context rather* than one per cursor per frame. */const cursorRectData = new Float32Array(MAX_CURSOR_RECTS * 4)+ /** The plate program, and null when it failed to build. Null is NOT the cursor's kind of+ * degrade: without a plate a terminal has no opaque ground at all, and the node body is+ * transparent in shared mode — the canvas dot grid would show straight through every terminal,+ * and overlapping terminals would stop occluding each other. So the null path falls back to the+ * scissored `clear` this program replaced (square corners, i.e. L4) rather than to nothing. */+ const plateProgram = buildProgram(gl, PLATE_VERT, PLATE_FRAG)+ const plateUniforms = new Map<string, WebGLUniformLocation | null>()+ const pu = (name: string): WebGLUniformLocation | null => {+ if (!plateProgram) return null+ let loc = plateUniforms.get(name)+ if (loc === undefined) {+ loc = gl.getUniformLocation(plateProgram, name)+ plateUniforms.set(name, loc)+ }+ return loc+ }/** One GPU buffer PER GRID, so a change costs only the rows that changed (bufferSubData)* instead of re-uploading every visible grid's whole cell array into one shared buffer. */const grids = new Map<string, { buf: WebGLBuffer; cols: number; rows: number }>()@@ -286,40 +366,106 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {gl.useProgram(program)gl.enable(gl.BLEND)- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)+ /**+ * Straight (non-premultiplied) source colours over a PREMULTIPLIED drawing buffer — which is+ * what `getContext('webgl2', {alpha: true})` gives, since `premultipliedAlpha` defaults to true+ * and nothing above overrides it.+ *+ * The alpha channel needs its OWN source factor, and this used to be a plain `blendFunc`. With+ * one factor for all four channels the destination alpha comes out as `srcA²` over an empty+ * buffer, so a fragment at half coverage leaves the surface a QUARTER opaque, and the browser —+ * compositing premultiplied — then lets 75% of the page through a pixel that is 50% covered. A+ * bright halo along a soft edge, on the light theme especially.+ *+ * It changes NOTHING that was already drawn: every source this renderer produced before the+ * plate became a quad is either fully opaque (cells, cursor overlay) or fully transparent (a+ * grid's zeroed buffer before its first packed row), and `srcA * srcA` equals `1 * srcA` at both+ * ends. The plate's antialiased corner is the first partial coverage in the pipeline, and this+ * is the factor that makes it composite as the coverage it claims.+ */+ gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA)/**- * 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`).+ * The occlusion plate: an opaque quad over the grid's PLATE rect — the node body's full world+ * rect, not the character matrix (see `GridDrawParams.plateX`) — with its bottom corners rounded+ * to the node's own radius.*- * 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- * an OPAQUE bgColor; a translucent one would punch the frame's alpha down to that value.+ * **PAINTER ORDER IS UNCHANGED, and saying so is the point of this paragraph.** The plate is+ * still drawn BEFORE this grid's cells and AFTER every lower grid, exactly where the scissored+ * `clear` sat; the whole Phase-1a occlusion story is that call order, and moving from a clear to+ * a BLENDED draw is precisely the change that could break it without looking like it had. It+ * does not, because the plate is opaque: `bgColor` carries alpha 0xff (`packThemeBg` forces it,+ * for this reason), and the blend func above at srcA = 1 resolves to `dst = src` for colour AND+ * alpha — the same bits the clear wrote. Only the corner fragments, where the SDF's+ * coverage falls below 1, blend at all, and blending is exactly what a rounded corner wants+ * there. **A translucent bgColor would now TINT what is underneath instead of punching a hole in+ * the frame's alpha** — a better failure than the clear's, but still not a supported input.*- * The rect math (camera projection, dpr, the Y flip, clamping) lives in the pure- * `plate.ts` — it is unit-tested there, since none of it is observable through a GL mock.- * What stays here is the GL state dance around it.+ * TWO RECTS, and conflating them is the trap. `plateRectDevice` answers which pixels are worth+ * drawing (clamped to the buffer, null when none are); `plateShapeDevice` answers where the node+ * ACTUALLY is (unclamped). The quad is drawn over the first — minimal overdraw, and no reliance+ * on the rasterizer to clip a rect that may sit far outside the viewport — while the SDF, and+ * the radius clamp, measure against the second. Feeding the clamped rect to the shader would+ * draw the node's rounded corner at the VIEWPORT edge on any node merely half scrolled off.+ *+ * All of that math is pure and lives in `plate.ts`, unit-tested, since none of it is observable+ * through a GL mock. What stays here is the GL state dance around it.+ *+ * COST, stated because it did go up: a scissored clear is a fast path most GPUs answer without+ * running a fragment shader, and this is a shaded quad over the same area — one invocation of+ * four arithmetic ops and a `length()` per body pixel per visible grid. It is strictly less work+ * than the CELL pass over that same area (which fetches a texture per fragment) and it is+ * culled by the same `drawOrder`, so it does not change the shape of the frame's cost. If it+ * ever shows up in a profile the escalation is a stencil or a scissored clear plus four small+ * corner quads — not speculative work.+ *+ * STATE TOUCHED, AND RESTORED. (1) the current PROGRAM — switched to the plate program and put+ * back to the cell program on the way out, the same discipline `drawCursor` follows, since+ * `beginFrame` binds the cell program once for the whole frame. (2) the `aCell` attribute ARRAY+ * — disabled here and re-enabled by `drawGrid` for every grid immediately after; a driver that+ * fetches enabled-but-unused arrays would read the previous grid's buffer at divisor 1. Nothing+ * else: no buffer is bound (positions come from uniforms and `gl_VertexID`), no texture, no+ * blend change, no viewport change — and, unlike the clear it replaced, no SCISSOR_TEST, which+ * is now never enabled at all.*/// An arrow const, not a `function` declaration: declarations hoist above the `if (!gl) return`// 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(- { x: g.plateX, y: g.plateY, w: g.plateW, h: g.plateH },- cam,- dpr,- deviceW,- deviceH- )- if (!r) return+ const world = { x: g.plateX, y: g.plateY, w: g.plateW, h: g.plateH }+ // Null = the plate covers no pixel of the drawing buffer; skip it entirely. Kept from the+ // clear-based version, where it also guarded against a GL_INVALID_VALUE scissor; here it is+ // purely the early-out that keeps an off-screen node free.+ const clip = plateRectDevice(world, cam, dpr, deviceW, deviceH)+ if (!clip) returnconst c = unpackColor(g.bgColor)- gl.enable(gl.SCISSOR_TEST)- gl.scissor(r.x, r.y, r.w, r.h)- gl.clearColor(c.r / 255, c.g / 255, c.b / 255, c.a / 255)- gl.clear(gl.COLOR_BUFFER_BIT)- // Disabled again immediately: the scissor is global GL state, and leaving it on would clip- // the next grid's cells (and the next frame's full-surface clear in beginFrame).- gl.disable(gl.SCISSOR_TEST)+ if (!plateProgram) {+ // The degrade: no plate program, so fall back to the scissored clear. Square corners (L4)+ // beat no occlusion at all — see `plateProgram`.+ gl.enable(gl.SCISSOR_TEST)+ gl.scissor(clip.x, clip.y, clip.w, clip.h)+ gl.clearColor(c.r / 255, c.g / 255, c.b / 255, c.a / 255)+ gl.clear(gl.COLOR_BUFFER_BIT)+ // Disabled again immediately: the scissor is global GL state, and leaving it on would clip+ // the next grid's cells (and the next frame's full-surface clear in beginFrame).+ gl.disable(gl.SCISSOR_TEST)+ return+ }+ const shape = plateShapeDevice(world, cam, dpr, deviceH)+ // `cam.zoom * dpr` is the same world → device scale every extent above went through, so the+ // radius can never drift out of proportion with the rect it rounds.+ const radius = plateRadiusDevice(g.plateRadius, cam.zoom * dpr, shape)+ gl.disableVertexAttribArray(aCellLoc)+ gl.useProgram(plateProgram)+ gl.uniform4f(pu('uQuad'), clip.x, clip.y, clip.w, clip.h)+ gl.uniform2f(pu('uDevice'), deviceW, deviceH)+ gl.uniform4f(pu('uRect'), shape.x, shape.y, shape.w, shape.h)+ gl.uniform1f(pu('uRadius'), radius)+ gl.uniform4f(pu('uColor'), c.r / 255, c.g / 255, c.b / 255, c.a / 255)+ // Two triangles from gl_VertexID, no vertex buffer — the same trick the cell and cursor+ // programs use. NOT instanced: there is exactly one plate per grid.+ gl.drawArrays(gl.TRIANGLES, 0, 6)+ // RESTORED, always — see the state note above.+ gl.useProgram(program)}/**@@ -498,9 +644,11 @@ 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 node BODY's world rect. It is+ // --- (1) the plate: an opaque rounded quad over 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.+ // gives total occlusion of overlapping terminals with no depth buffer. This call site is+ // where that order lives, and it has not moved — see `drawPlate` on why a blended draw+ // still occludes.drawPlate(g)// --- (2) the cells, instanced from the grid's own buffer.@@ -531,6 +679,7 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {gl.deleteTexture(atlasTex)gl.deleteProgram(program)if (cursorProgram) gl.deleteProgram(cursorProgram)+ if (plateProgram) gl.deleteProgram(plateProgram)}}}diff --git a/src/renderer/glyphgrid/gl.ts b/src/renderer/glyphgrid/gl.tsindex 3f5f679ff..059528b51 100644--- a/src/renderer/glyphgrid/gl.ts+++ b/src/renderer/glyphgrid/gl.ts@@ -40,6 +40,27 @@ export interface GridDrawParams {plateY: numberplateW: numberplateH: number+ /**+ * The plate's corner radius in WORLD units (CSS px at zoom 1). **0 = a square rect**, which is+ * exactly the shape the plate had when it was a scissored `clear`, so a caller that says nothing+ * gets the pre-Phase-2 rectangle bit for bit.+ *+ * WHY THE PLATE HAS TO CARRY ONE. The plate is a node BODY (see `plateX`) and a node has+ * `border-radius`; the shared canvas is not a DOM child of that node, so nothing can clip it to+ * the node's shape. A square plate under a rounded node is what made every shared terminal's+ * corners read square against its own chrome (limitation L4).+ *+ * WHICH CORNERS ARE ROUNDED IS PART OF THIS CONTRACT: the BOTTOM two, never the top. The plate+ * rect is the node's body, which is the node's LAST child — its bottom edge is the node's own+ * bottom (rounded, and behind it nothing but canvas), while its top edge is an interior seam+ * against opaque chrome (the header, the labels row, the find bar). Rounding the top corners+ * would not shape a visible corner at all; it would UNCOVER two wedges of body that nothing else+ * paints, which is a new artifact rather than a fixed one. See PLATE_FRAG in gl-webgl2.ts.+ *+ * Scaling and clamping are the implementation's job, per draw (`plateRadiusDevice`): both inputs+ * — the camera and the plate's device extent — are known only at draw time.+ */+ plateRadius: number/*** The cursor to draw OVER this grid's cells, or null for none.*@@ -90,8 +111,8 @@ export interface GlyphGL {): void/** Clears the frame and sets the camera uniforms. */beginFrame(camera: Camera): void- /** Draws the plate (a scissored clear of the grid's PLATE rect), then the instanced cells from- * the grid's OWN buffer, then the cursor overlay if it has one — in call order (painter's+ /** Draws the plate (an opaque rounded quad over the grid's PLATE rect), then the instanced cells+ * from the grid's OWN buffer, then the cursor overlay if it has one — in call order (painter's* algorithm), so a grid drawn later covers all three. */drawGrid(g: GridDrawParams): voidendFrame(): voiddiff --git a/src/renderer/glyphgrid/plate.test.ts b/src/renderer/glyphgrid/plate.test.tsindex ed2e57cb8..23a270ad8 100644--- a/src/renderer/glyphgrid/plate.test.ts+++ b/src/renderer/glyphgrid/plate.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest'import type { Rect } from './camera'-import { plateRectDevice } from './plate'+import { plateRadiusDevice, plateRectDevice, plateShapeDevice } from './plate'/** 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 })@@ -80,3 +80,75 @@ describe('plateRectDevice', () => {expect(plateRectDevice(plate({ h: 0 }), CAM, 1, 200, 100)).toBeNull()})})++describe('plateShapeDevice', () => {+ it('agrees with plateRectDevice while the plate is fully on screen', () => {+ // The two only differ at the viewport edge, so the common case pins them together: a rect+ // wholly inside the buffer is its own visible part, and the rounded shape must be defined+ // against exactly the same pixels the clipped draw covers.+ expect(plateShapeDevice(plate(), CAM, 1, 100)).toEqual({ x: 10, y: 50, w: 40, h: 40 })+ })++ it('does NOT clamp — the corner must stay where the node is, not at the viewport edge', () => {+ // The whole reason this exists next to plateRectDevice. Origin (-10,-10) hangs off the left+ // and the top; the CLAMPED rect starts at x 0, and rounding a corner against that would draw+ // the node's rounded corner in the MIDDLE of the screen, ten pixels in from an edge the node+ // does not have there. Flip: 100 - (-10 + 40) = 70.+ expect(plateShapeDevice(plate({ x: -10, y: -10 }), CAM, 1, 100)).toEqual({+ x: -10,+ y: 70,+ w: 40,+ h: 40+ })+ })++ it('answers a rect even when the plate covers no pixel — visibility is the other function’s job', () => {+ // Never null: this is a SHAPE, and the caller has already decided (via plateRectDevice) that+ // there is something to draw. Two responsibilities, two answers.+ expect(plateShapeDevice(plate({ x: 500 }), CAM, 1, 100)).toEqual({+ x: 500,+ y: 50,+ w: 40,+ h: 40+ })+ })++ it('takes the same camera/dpr hops as the scissor rect', () => {+ // dpr 2 against a 200-tall buffer: extents double and the flip is taken against the DEVICE+ // height — 200 - (20 + 80) = 100, exactly as plateRectDevice's own dpr test derives it.+ expect(plateShapeDevice(plate(), CAM, 2, 200)).toEqual({ x: 20, y: 100, w: 80, h: 80 })+ })+})++describe('plateRadiusDevice', () => {+ it('scales the radius with zoom and dpr', () => {+ // The radius is authored in WORLD units (CSS px at zoom 1) because that is where the node's+ // stylesheet defines it; on screen it has to follow the same `zoom * dpr` every extent does,+ // or a zoomed-in terminal keeps a corner a quarter of its apparent size.+ expect(plateRadiusDevice(10, 2, { w: 200, h: 100 })).toBe(20)+ })++ it('never exceeds half the shorter side', () => {+ // A 10px radius on a 12px-tall plate would round the rect into a stadium and then INVERT the+ // SDF (the inner box's half-extent goes negative), which paints a corner-shaped hole instead+ // of a corner. Clamping at half the shorter side is what keeps a COLLAPSING node — a body+ // dragged down to nothing — from flickering through that inversion.+ expect(plateRadiusDevice(10, 1, { w: 200, h: 12 })).toBe(6)+ expect(plateRadiusDevice(10, 1, { w: 8, h: 200 })).toBe(4)+ })++ it('is 0 for a square plate — every caller that asks for no radius keeps today’s rectangle', () => {+ expect(plateRadiusDevice(0, 2, { w: 200, h: 100 })).toBe(0)+ })++ it('is 0 for a degenerate radius, scale or rect rather than a NaN in a uniform', () => {+ // These reach the shader as a uniform the corner SDF subtracts, so a NaN here would not+ // round a corner — it would make every fragment of the plate fail the coverage test and the+ // terminal's whole background disappear. Guarded, like `cursorThicknessWorld`.+ expect(plateRadiusDevice(-4, 1, { w: 200, h: 100 })).toBe(0)+ expect(plateRadiusDevice(Number.NaN, 1, { w: 200, h: 100 })).toBe(0)+ expect(plateRadiusDevice(10, 0, { w: 200, h: 100 })).toBe(0)+ expect(plateRadiusDevice(10, 1, { w: 0, h: 100 })).toBe(0)+ expect(plateRadiusDevice(10, 1, { w: 200, h: -5 })).toBe(0)+ })+})diff --git a/src/renderer/glyphgrid/plate.ts b/src/renderer/glyphgrid/plate.tsindex 433b9ffed..6465a22ad 100644--- a/src/renderer/glyphgrid/plate.ts+++ b/src/renderer/glyphgrid/plate.ts@@ -11,36 +11,35 @@ export interface DeviceRect {}/**- * 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.+ * The plate's WHOLE device rect — where the node BODY is, whether or not it is on screen.*- * 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- * move the rect's far edge.+ * This is the rect the plate's SHAPE is defined against: the rounded-corner SDF measures a+ * fragment's distance from these four edges, so it has to be the node's real rect. Its clamped+ * sibling below answers a different question (which pixels are worth drawing), and the two must+ * not be conflated — a shape measured against the CLAMPED rect would put a rounded corner at the+ * VIEWPORT edge, i.e. draw the node's corner ten pixels into open canvas on a node that is merely+ * half scrolled off. Never null for the same reason: a rect that covers no pixel still has a+ * shape, and whether to draw at all is `plateRectDevice`'s answer.** The hops, in order:* 1. world → screen (CSS px): `screen = world * zoom + pan`, exactly as the vertex shader does.* 2. CSS px → DEVICE px via `dpr` — the ratio captured at `resize`, never `devicePixelRatio`* read at call time (they disagree the moment a window crosses monitors mid-frame).- * 3. Y FLIP: GL's scissor origin is bottom-left while world/CSS Y grows downward, so the- * device y is measured from the buffer's BOTTOM: `deviceH - (top + height)`.- * 4. Clamp to [0, deviceW] × [0, deviceH].+ * 3. Y FLIP: GL's window origin is bottom-left (both `gl_FragCoord` and the scissor) while+ * world/CSS Y grows downward, so the device y is measured from the buffer's BOTTOM:+ * `deviceH - (top + height)`.+ *+ * ROUNDED, not truncated, on every hop — and that rounding is load-bearing beyond tidiness: it+ * puts the plate's straight edges exactly on device-pixel boundaries, which is what lets the+ * fragment shader's one-pixel coverage window leave a straight edge at full alpha (see+ * PLATE_FRAG). A fractional edge would feather the body's own border by half a pixel.*/-export function plateRectDevice(+export function plateShapeDevice(plate: Rect,cam: Camera,dpr: number,- deviceW: number,deviceH: number-): DeviceRect | null {+): DeviceRect {// (1) world → screen (CSS px).const leftCss = plate.x * cam.zoom + cam.xconst topCss = plate.y * cam.zoom + cam.y@@ -52,13 +51,67 @@ export function plateRectDevice(const width = Math.round(wCss * dpr)const height = Math.round(hCss * dpr)// (3) Y FLIP.- const bottom = deviceH - (top + height)- // (4) Clamp.- const x0 = Math.max(0, left)- const y0 = Math.max(0, bottom)- const x1 = Math.min(deviceW, left + width)- const y1 = Math.min(deviceH, bottom + height)+ return { x: left, y: deviceH - (top + height), w: width, h: height }+}++/**+ * The occlusion plate's VISIBLE device rect: `plateShapeDevice` clamped to the drawing buffer.+ * Pure, so the coordinate hops 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+ * plate entirely. A clamped-empty rect is not merely wasteful — it was a GL_INVALID_VALUE while+ * this drove a `scissor`, and it is a degenerate quad now that it bounds a DRAW; either way,+ * clamping the origin to 0 without shrinking the extent would silently move the rect's far edge.+ */+export function plateRectDevice(+ plate: Rect,+ cam: Camera,+ dpr: number,+ deviceW: number,+ deviceH: number+): DeviceRect | null {+ const r = plateShapeDevice(plate, cam, dpr, deviceH)+ const x0 = Math.max(0, r.x)+ const y0 = Math.max(0, r.y)+ const x1 = Math.min(deviceW, r.x + r.w)+ const y1 = Math.min(deviceH, r.y + r.h)// `<=`, not `<`: a rect that only shares an edge with the viewport covers zero pixels.if (x1 <= x0 || y1 <= y0) return nullreturn { x: x0, y: y0, w: x1 - x0, h: y1 - y0 }}++/**+ * The plate's corner radius in DEVICE pixels, from the WORLD-unit radius the node's stylesheet+ * defines and the frame's `zoom * dpr`.+ *+ * CLAMPED AT HALF THE SHORTER SIDE, which is the whole reason this is a function rather than a+ * multiplication at the call site. The rounded-rect SDF works by shrinking the rect by the radius+ * on every side and measuring distance to that inner box; a radius past half the shorter side+ * makes the inner box's half-extent NEGATIVE, and the field it produces is no longer the+ * rectangle's — it paints a corner-shaped hole rather than a corner. A node being dragged shut+ * passes through every height between its body and zero, so this is a state the renderer reaches+ * in ordinary use, not a pathological input.+ *+ * Degenerate inputs answer 0 — a square plate, i.e. exactly the pre-Phase-2 rectangle — rather+ * than NaN or Infinity. The result is a uniform the SDF SUBTRACTS, so a NaN would not merely+ * unround the corner: every fragment's coverage test would fail and the terminal's background+ * would vanish. Same discipline as `cursorThicknessWorld`, and for the same class of reason.+ *+ * Takes `{w, h}` rather than a whole `DeviceRect` so the caller cannot accidentally pass the+ * CLAMPED rect's extent: the radius belongs to the node's real size, and clamping it against a+ * half-scrolled-off rect would shrink the corner as the node leaves the screen.+ */+export function plateRadiusDevice(+ radiusWorld: number,+ dprZoom: number,+ size: { w: number; h: number }+): number {+ if (!(radiusWorld > 0) || !(dprZoom > 0) || !(size.w > 0) || !(size.h > 0)) return 0+ return Math.min(radiusWorld * dprZoom, size.w / 2, size.h / 2)+}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 0484e96f0..a4a0b0968 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -1231,6 +1231,42 @@ export function TerminalNode({return bodyPlateRect(nodePosRef.current, offset, w, h)}+ /**+ * The plate's corner radius in WORLD units — how far the node's own bottom corners are+ * rounded, so the opaque ground the shared canvas paints under this terminal stops reading+ * square against it (limitation L4). 0 means "square", and every failure below answers 0: a+ * merely rectangular plate is the shape this renderer has always drawn.+ *+ * READ FROM THE NODE'S OWN COMPUTED STYLE, never a literal. **This deliberately does not read+ * the `--radius-lg` token**: `.term-node` is authored as a literal `border-radius: 10px` while+ * the token is `12px`, so taking the token would round the plate MORE than the node clips+ * itself and leave a crescent of canvas inside each bottom corner — the same class of artifact+ * as L4, mirrored. Asking the element resolves whatever the stylesheet actually says (token,+ * literal, or a future theme override) and cannot desync from it.+ *+ * The BORDER WIDTH is subtracted because `border-radius` describes the BORDER box while the+ * plate is the body box, which sits one border inside it. CSS rounds that inner box by+ * `radius - border`, so a plate rounded by the OUTER radius would curve slightly tighter than+ * the node's own clip all the way round the corner.+ *+ * Only the bottom corners are shaped, and the GL layer owns that rule rather than this call+ * site — see `GridDrawParams.plateRadius`. The body is the node's last child, so its top+ * corners butt against opaque chrome and are not corners on screen at all.+ */+ const measurePlateRadius = (): number => {+ const root = rootRef.current+ if (!root) return 0+ const style = getComputedStyle(root)+ // A computed `border-radius` is a px length here. A PERCENTAGE resolves as a percentage+ // string, and parseFloat would turn it into a number that is not a radius at all — refused+ // rather than guessed, the same way `packThemeBg` refuses a colour form it does not parse.+ if (style.borderBottomLeftRadius.includes('%')) return 0+ const radius = parseFloat(style.borderBottomLeftRadius)+ const border = parseFloat(style.borderBottomWidth)+ if (!Number.isFinite(radius) || radius <= 0) return 0+ return Math.max(0, radius - (Number.isFinite(border) ? border : 0))+ }+/*** Hand the shared canvas back. Order is fixed: the ATTACHMENT first — it is the only thing* that can still write into the grid, and disposing it is what puts xterm back on its own DOM@@ -1368,7 +1404,13 @@ export function TerminalNode({plateX: plate.x,plateY: plate.y,plateW: plate.w,- plateH: plate.h+ plateH: plate.h,+ // Registration-time only, and that is a property of the value rather than a shortcut:+ // the radius is a stylesheet constant, so unlike the plate RECT nothing moves it while+ // this node lives, and the paths that could change it (a font/theme generation bump)+ // tear this grid down and register a fresh one. There is no `setPlateRadius` for the+ // same reason — see `GridSpec.plateRadius`.+ plateRadius: measurePlateRadius()})} catch (err) {glyphWarn(`${id}:register`, `could not register a grid for node ${id}: ${String(err)}`)