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): color-atlas wiring + the acceptance items parity now makes checkable
enes1364e83a57bc
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.mdindex 7afeb128d..293c3eb7b 100644--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md@@ -83,35 +83,27 @@ Auto after you switched builds, that is why: re-select Shared and carry on.still 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. 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.- **Round 6 addressed exactly that raster.** The atlas is no longer drawn onto transparency:- the page is opaque BLACK, the ink is WHITE, and the shader reads coverage off the RED- channel — the same backdrop xterm's own `TextureAtlas._drawToCache` hands the platform- rasterizer before every `fillText`, and the reason its glyphs come out at full weight on- macOS. Judge plain text (a paragraph of prose, `man bash`, a source file) against the- per-terminal GPU renderer at dpr 2 and dpr 1. **If a weight/softness gap still remains after- this, stop tuning the rasterizer**: the next step is xterm's full approach — a COLOR atlas- keyed by `(code, style, fg, bg)` with per-glyph ink-box cropping — which reworks `atlas.ts`,- `raster.ts` and the cell/uv contract together and is therefore a **Phase 2** item, not a- round-7 patch. Report it as "2.7 raster gap → Phase 2 color atlas".- **Round 7b re-tuned the blend, not the raster.** The device read round 7's full 2.2 decode as- slightly TOO THICK, which brackets the answer (1.0 = sRGB-space mix read thin, 2.2 read- thick). The compositing gamma is now the single named constant `BLEND_GAMMA = 1.45` in- `gl-webgl2.ts` — the text-AA blend gamma Skia and FreeType use, and the right family of number- because the coverage in our atlas is CoreText's own rasterization, which already carries its- light-on-dark compensation. **If weight is still off, report only WHICH WAY** (thick or thin):- the fix is that one constant, down toward 1.0 or up toward 2.2. Do not report "not identical"- — that is the one answer nothing can be done with.+- [ ] **2.7 Zoom-1 parity at dpr 1 and 2 (rewritten for Phase 1c — parity is now STRUCTURAL).**+ Everything this item used to ask about a blend is gone, and so is the blend. Each atlas slot+ now holds the platform's own rasterization of one glyph **in its real foreground over its real+ background** — the same thing xterm's `TextureAtlas._drawToCache` builds for the GPU renderer+ you are comparing against — and at zoom 1 that slot is blitted **1:1** onto the cell: the atlas+ is rasterized at xterm's exact device cell, `MIN_FILTER` is NEAREST at zoom ≥ 1 (MAG always+ is), and the pan is snapped to whole device pixels. There is no coverage encoding, no shader+ mix and no gamma constant left in the pipeline — **`BLEND_GAMMA` and the linear-light blend+ were DELETED, not retuned.** The acceptance question changed with them: it is no longer "is the+ weight right", which was a knob, but "are these the same pixels", which is a fact.+ **How to run it.** 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), at zoom exactly 1, put a Shared terminal+ beside a **GPU per terminal** one running the same content. Judge a paragraph of prose,+ `man bash`, and a source file — and specifically the cases the colour keying introduced: bold,+ italic, dim, inverse, ANSI-coloured output, a selection band, and a block cursor sitting on a+ character.+ **What to report.** Any visible difference, and WHERE it lives: which glyphs, which colours,+ which dpr, plain vs bold/dim/inverse. A remaining gap can no longer be a blend setting, so+ "slightly thicker" / "slightly thinner" is no longer an actionable answer — the candidates left+ are the raster (baseline rounding, the ink clip at the cell rect) and L14's first-terminal cell+ latch, and those are found by knowing which glyphs are wrong, not by which way.- [ ] **2.7b One letter renders BLANK (open bug — this round collects EVIDENCE, not a fix).**Reported twice: `ç` in round 5 (which "went away" with no root cause found) and lowercase `x`in round 7 — one letter blank all session while its neighbours, including uppercase `X`,@@ -128,13 +120,56 @@ Auto after you switched builds, that is why: re-select Shared and carry on.2. Use the app until a letter goes blank. Note **which** letter, and whether itsuppercase/lowercase/bold/italic variants also fail.3. Run `await window.__glyphgridDump()` and open the returned `page` data URL in a new tab —- that is a PNG of the whole atlas. **Find the reported letter in it.**- - **Not in the atlas (its cell is black)** → the RASTERIZER is the suspect (font, baseline,- clip). Report the letter plus the `[glyphgrid] slot … code … at x,y` warn line for it.+ that is a PNG of the whole atlas. **Find the reported letter in it.** Since Phase 1c the+ page is COLOURED, which changes how it reads: each cell is that glyph over its own+ background (a dark theme gives a mostly dark-on-dark page), the ground between allocated+ slots is TRANSPARENT rather than black (so it shows as the tab's own backdrop), and the same+ letter legitimately appears once per colour pair it has been drawn in.+ - **Not in the atlas (its cell is an inkless expanse of its own background colour)** → the+ RASTERIZER is the suspect (font, baseline, clip). Report the letter plus the+ `[glyphgrid] slot … code … at x,y fg=… bg=…` warn line for it.- **In the atlas, correctly drawn** → the slot→uv mapping or the texture upload is. Report- its slot number and the `geometry` block from the dump alongside the PNG.+ its slot number and the `geometry` block from the dump alongside the PNG. `geometry` also+ carries `gutterPx` (a slot's ink starts one gutter inside its pitch cell, so stride+ arithmetic alone lands a couple of texels off) and `resetCount` (a slot INDEX only means+ something alongside the reset it was taken after — see 2.7c).4. Paste the console's `[glyphgrid]` lines for the letter and its working neighbours.This instrumentation is temporary and comes out when the bug closes.+- [ ] **2.7c Zoom-OUT quality (new in Phase 1c — the other half of the parity ask).** Keep the+ side-by-side from 2.7, then zoom the canvas out to roughly **50%** and again to roughly **25%**+ and compare the Shared terminals against the GPU-mode one at each stop. Pan while zoomed out —+ motion is where undersampling shows.+ **What should now be true.** Minified text degrades SMOOTHLY, in the same class as GPU mode:+ softer as it shrinks, but not speckling, crawling or shimmering under a pan. The atlas carries+ a real mip chain and every slot carries a 2-texel gutter filled with its own background, so a+ minified sample averages texels that belong to this cell instead of undersampling level 0 —+ which is exactly what made a zoomed-out canvas sparkle before this phase.+ **Expected residual 1 — the LOD clamp.** The sampler is forbidden to go deeper than mip level 2,+ because that is the deepest level the gutter can keep free of a neighbouring glyph's ink. Past+ roughly 25% the filter therefore cannot get any softer, and slight aliasing comes back. That is+ the accepted trade — a little aliasing at extreme zoom-out instead of a neighbour's glyph+ bleeding into every cell — and it is not a finding.+ **Expected residual 2 — the frontier rim.** While the atlas page is still FILLING (a young+ session, or the frames right after a reset), the mip average at a slot's outer edge includes+ unallocated, transparent page ground. The texture is non-premultiplied, so rgb and alpha are+ averaged independently and the blend then attenuates the already-darkened colour by that same+ alpha again: the outermost row/column of the affected cells reads as a slightly **DARKER,+ slightly TRANSLUCENT rim** at heavy zoom-out (~25%) — you can see the node's plate through it.+ It is bounded to one cell edge, purely cosmetic, and **self-heals as the page fills**. **Do not+ diagnose it as a gutter/bleed failure**: bleed would look like a NEIGHBOURING GLYPH appearing+ inside a cell, which is a different — and blocking — report. If the rim is objectionable in+ practice, say so and say at what zoom and how long into the session: the named escalation is+ uploading the atlas premultiplied (`pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, true)` with+ `blendFunc(ONE, ONE_MINUS_SRC_ALPHA)`), which is gated on exactly that device evidence and+ deliberately not built yet.+ **Atlas resets, while you are here.** The colour-keyed page is a working set — one slot per+ `(code, style, fg, bg)` — so filling it is normal, and the answer is to clear it and repack+ every row. On screen that is ONE frame of full repaint across the shared terminals: a flicker+ at most, never a blank. Each reset announces itself:+ `[glyphgrid] atlas page reset #N — colour key space full, every row repacks`, throttled to one+ line a second, a burst adding `(+K more since the last line)`. **Report the highest `N` you saw+ and roughly how long the session had run to get there.** "Rare" is this design's claim; frequent+ resets are the evidence that Phase 2 must build real LRU eviction instead.- [ ] **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@@ -425,6 +460,15 @@ Auto after you switched builds, that is why: re-select Shared and carry on.`warnOnCellDrift` logs one `[glyphgrid] atlas cell … does not match …` line per context lifetime,so a soft terminal can be told apart from a soft display. Phase 2 (re-rasterize on`document.fonts.ready` / per-cell atlas pages).++ **Phase 1c narrows what is latched.** The FACE never was: `ctx.font` is set per draw, so any slot+ rasterized after a webfont resolves already uses the real face. What used to make that invisible is+ that a cached slot was cached forever — and the colour-keyed page now CLEARS AND REFILLS when it+ fills up (2.7c), which re-inks every slot with whatever face is resolved at that moment. So a late+ webfont propagates to already-cached glyphs on the next reset instead of never. What remains+ latched for the life of the context is the CELL and the BASELINE, both computed once at+ construction — i.e. the late-webfont symptom is now "right face, fallback face's metrics", and only+ a context rebuild fixes that.- **L15 — A terminal that is STACKED OVER another node temporarily leaves the shared renderer.**(Rewritten in round 5. The round-4 entry — a hairline of the lower node's frame ghosting throughthe upper node's transparent body, plus "selection no longer raises a covered node" — described adiff --git a/src/renderer/canvas/SharedGlyphLayer.test.ts b/src/renderer/canvas/SharedGlyphLayer.test.tsindex 24113a961..d30392373 100644--- a/src/renderer/canvas/SharedGlyphLayer.test.ts+++ b/src/renderer/canvas/SharedGlyphLayer.test.ts@@ -8,6 +8,7 @@ import {gestureTerminalIds,hasActiveGesture,idsFromOrderSig,+ installAtlasResetLog,nodeIsOpaque,nodeOrderSig,nodeStackZ,@@ -22,6 +23,7 @@ import {subscribeNodeZOrder,subscribeOpaqueSet,useSharedGlyph,+ type AtlasResetSource,type StackedNode,type StackOrderNode} from './SharedGlyphLayer'@@ -957,3 +959,97 @@ describe('sharedGlyphAvailable', () => {expect(sharedGlyphAvailable()).toBe(true)})})++describe('installAtlasResetLog', () => {+ /** The atlas surface the log reads, with a manual trigger. */+ function fakeAtlas(): {+ source: AtlasResetSource+ fire(): void+ subs: number+ } {+ const cbs = new Set<() => void>()+ let count = 0+ return {+ source: {+ get resetCount() {+ return count+ },+ onReset(cb) {+ cbs.add(cb)+ return {+ dispose() {+ cbs.delete(cb)+ }+ }+ }+ },+ fire() {+ // The real atlas increments its counter BEFORE it notifies (see GlyphAtlas.reset), which is+ // what lets the log line carry the number of the reset it is reporting.+ count+++ for (const cb of [...cbs]) cb()+ },+ get subs() {+ return cbs.size+ }+ }+ }++ let warn: ReturnType<typeof vi.spyOn>+ beforeEach(() => {+ warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ })+ afterEach(() => {+ warn.mockRestore()+ })++ it('logs the first reset immediately, with its number', () => {+ const atlas = fakeAtlas()+ installAtlasResetLog(atlas.source, () => 0)+ atlas.fire()+ expect(warn).toHaveBeenCalledTimes(1)+ expect(String(warn.mock.calls[0][0])).toContain('[glyphgrid] atlas page reset #1')+ })++ // Resets are supposed to be RARE. A page too small for the canvas resets on every repack instead,+ // and an unthrottled line there would be a console write per frame — which costs frames itself+ // and buries the very signal the tester is being asked to report.+ it('throttles a burst to one line, and says how many it swallowed', () => {+ const atlas = fakeAtlas()+ let now = 0+ installAtlasResetLog(atlas.source, () => now)+ atlas.fire()+ now = 100+ atlas.fire()+ now = 200+ atlas.fire()+ expect(warn).toHaveBeenCalledTimes(1)+ now = 5000+ atlas.fire()+ expect(warn).toHaveBeenCalledTimes(2)+ const line = String(warn.mock.calls[1][0])+ expect(line).toContain('#4')+ expect(line).toContain('+2')+ })++ it('does not mention swallowed resets when none were', () => {+ const atlas = fakeAtlas()+ let now = 0+ installAtlasResetLog(atlas.source, () => now)+ atlas.fire()+ now = 5000+ atlas.fire()+ expect(warn).toHaveBeenCalledTimes(2)+ expect(String(warn.mock.calls[1][0])).not.toContain('+')+ })++ it('unsubscribes on dispose — the context that installed it is gone', () => {+ const atlas = fakeAtlas()+ const sub = installAtlasResetLog(atlas.source, () => 0)+ expect(atlas.subs).toBe(1)+ sub.dispose()+ expect(atlas.subs).toBe(0)+ atlas.fire()+ expect(warn).not.toHaveBeenCalled()+ })+})diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsxindex 17ac790f8..82ca7ab02 100644--- a/src/renderer/canvas/SharedGlyphLayer.tsx+++ b/src/renderer/canvas/SharedGlyphLayer.tsx@@ -30,7 +30,12 @@import { useEffect, useRef, useState } from 'react'import { create } from 'zustand'-import { GlyphAtlas, type GlyphSlotAllocation } from '../glyphgrid/atlas'+import {+ GUTTER_PX,+ GlyphAtlas,+ type GlyphAtlasSubscription,+ type GlyphSlotAllocation+} from '../glyphgrid/atlas'import type { Camera } from '../glyphgrid/camera'import { GlyphGridEngine } from '../glyphgrid/engine'import type { GlyphGL } from '../glyphgrid/gl'@@ -39,11 +44,20 @@ import { createCanvasRasterizer } from '../glyphgrid/raster'import { useSettings } from '../state/settings'/** Atlas page edge, in DEVICE pixels. 2048 (not Phase 0's 1024) because the atlas cells are- * device-sized: at dpr 2 a 13px terminal font is roughly a 16x32 device cell, so a 1024 page- * holds ~2000 glyphs — enough for ASCII plus a little, and nothing like enough for a session- * that also shows box drawing, powerline glyphs and CJK. A full page degrades to the blank slot- * (GlyphAtlas never throws), i.e. missing text, so the page is sized for the pathological- * session rather than the average one. 2048² RGBA = 16 MB of VRAM, once, for the whole canvas. */+ * device-sized AND the page is now keyed by COLOUR: at dpr 2 a 13px terminal font is roughly a+ * 16x32 device cell, which on a 2048 page (slot pitch = the cell plus a gutter each side) leaves+ * room for a few thousand `(code, style, fg, bg)` slots. Under the old monochrome keying that was+ * a whole session's glyph REPERTOIRE; under colour keying the same repertoire costs one slot per+ * colour pair it is ever drawn in, so the page is a working set rather than a cache of everything.+ *+ * Which is why filling it is a NORMAL event, not a failure: `GlyphAtlas` answers a full page by+ * clearing it and telling every addon to repack (see its `reset`), so the cost is one expensive+ * frame instead of the missing text an earlier version of this comment described. Sizing the page+ * generously is therefore about keeping resets RARE (they are logged — see `installAtlasResetLog`),+ * not about never reaching the end of it.+ *+ * 2048² RGBA = 16 MB, plus the mip chain the minification filter needs — clamped to MAX_SAFE_LOD,+ * so levels 1 and 2 only, about 5 MB more. ~21 MB of VRAM, once, for the whole canvas. */const ATLAS_PAGE_PX = 2048/** A cell larger than this would make the atlas page hold almost nothing. The number now comes@@ -623,6 +637,10 @@ export interface SharedGlyphContext {interface LiveContext extends SharedGlyphContext {canvas: HTMLCanvasElementgl: GlyphGL+ /** The console reset gauge's subscription, held so teardown can drop it: the atlas dies with the+ * context, but a subscription left on a rebuilt-and-then-disposed one would keep a closure alive+ * per font change. */+ resetLog: GlyphAtlasSubscription/** Font settings this context was rasterized for — a change tears it down. */fontKey: string/** Set by `disposeContext`, read by the rAF driver, which holds this object across a frame.@@ -701,7 +719,20 @@ function glyphDebugTap(): ((info: GlyphSlotAllocation) => void) | undefined {/** Exposes `window.__glyphgridDump()` → `{ page, ...geometry }`, where `page` is a PNG data URL of* the whole atlas. Installed only under the debug flag; the tester opens the data URL in a tab and- * looks for the reported letter. */+ * looks for the reported letter.+ *+ * READING THE PNG SINCE THE ATLAS WENT COLOURED. It is no longer white ink on a black page: each+ * slot holds the glyph in its real foreground over its real background, so a dark-theme page is+ * mostly dark-on-dark and the whole page ground OUTSIDE the allocated slots is TRANSPARENT (it+ * renders as the viewer's own backdrop — white in a browser tab, not black). "The letter's cell is+ * black" is therefore no longer the test for "missing": the test is whether the cell holds an+ * inkless expanse of its own BACKGROUND colour. The same letter can also legitimately appear MANY+ * times, once per colour pair it has been drawn in.+ *+ * `gutterPx` and `resetCount` ride along for that reading: a slot's ink starts one gutter inside+ * its pitch cell (so `strideX`-based arithmetic alone lands a couple of texels off), and a page+ * that has reset is a page whose slot numbering has been reused — a dumped slot index only means+ * something alongside the reset count it was taken at. */function installGlyphDump(atlas: GlyphAtlas, raster: { cellW: number; cellH: number }): void {if (!glyphDebugOn() || typeof window === 'undefined') return;(window as unknown as Record<string, unknown>).__glyphgridDump = async (): Promise<unknown> => {@@ -712,8 +743,10 @@ function installGlyphDump(atlas: GlyphAtlas, raster: { cellW: number; cellH: numcellH: raster.cellH,strideX: atlas.strideX,strideY: atlas.strideY,+ gutterPx: GUTTER_PX,cols: Math.floor(atlas.sizePx / atlas.strideX),- capacity: atlas.capacity+ capacity: atlas.capacity,+ resetCount: atlas.resetCount}// `source` is the rasterizer's OffscreenCanvas; convertToBlob is the only way to read it back.if (!source || typeof (source as OffscreenCanvas).convertToBlob !== 'function')@@ -728,6 +761,56 @@ function installGlyphDump(atlas: GlyphAtlas, raster: { cellW: number; cellH: num}}+/** The atlas surface the reset log reads. Structural rather than `GlyphAtlas` so the log can be+ * exercised without a page full of real glyphs — filling a real one takes a rasterizer, which this+ * environment does not have. */+export interface AtlasResetSource {+ resetCount: number+ onReset(cb: () => void): GlyphAtlasSubscription+}++/** Quiet period after a logged reset. */+const RESET_LOG_INTERVAL_MS = 1000++/**+ * Announce atlas page resets on the console.+ *+ * NOT gated on the debug flag, unlike the dump and the allocation tap. A reset is the v1+ * reset-on-full model's pressure gauge: it is supposed to be RARE, and the number that decides+ * whether Phase 2 has to build real LRU eviction is how often it actually happens in a day's use —+ * which nobody will have collected if seeing it required knowing to turn a flag on first. It costs a+ * console line per reset on a canvas where resets are rare, which is the case this design claims.+ *+ * THROTTLED, because the case where the claim is wrong is exactly the case that would drown in it: a+ * page too small for the canvas resets on every repack, i.e. once per frame, and an unthrottled warn+ * there is both a real frame cost and a console the tester cannot read the rest of. So at most one+ * line per `RESET_LOG_INTERVAL_MS`, carrying the count of the ones it swallowed — a burst still+ * reports as a burst, in one line instead of sixty.+ *+ * `now` is injected for the tests; production passes nothing.+ */+export function installAtlasResetLog(+ atlas: AtlasResetSource,+ now: () => number = Date.now+): GlyphAtlasSubscription {+ // -Infinity, not 0: the FIRST reset must always print, whatever the clock reads.+ let lastAt = -Infinity+ let swallowed = 0+ return atlas.onReset(() => {+ const t = now()+ if (t - lastAt < RESET_LOG_INTERVAL_MS) {+ swallowed+++ return+ }+ lastAt = t+ const extra = swallowed > 0 ? ` (+${swallowed} more since the last line)` : ''+ swallowed = 0+ console.warn(+ `[glyphgrid] atlas page reset #${atlas.resetCount} — colour key space full, every row repacks${extra}`+ )+ })+}+function createContext(cell: DeviceCell): LiveContext | null {if (typeof document === 'undefined' || typeof OffscreenCanvas === 'undefined') return nullconst { fontFamily, fontSize } = useSettings.getState().settings@@ -760,7 +843,15 @@ function createContext(cell: DeviceCell): LiveContext | null {installGlyphDump(atlas, raster)const engine = new GlyphGridEngine(gl, atlas)engine.setCamera(lastCamera)- return { engine, atlas, canvas, gl, fontKey: fontKeyOf(fontFamily, fontSize), disposed: false }+ return {+ engine,+ atlas,+ canvas,+ gl,+ resetLog: installAtlasResetLog(atlas),+ fontKey: fontKeyOf(fontFamily, fontSize),+ disposed: false+ }}/** Tear the context down and free the GPU objects. Every registered grid is left holding an@@ -776,6 +867,7 @@ function disposeContext(): void {// than submit against deleted objects (see `LiveContext.disposed`).ctx.disposed = truetry {+ ctx.resetLog.dispose()ctx.engine.disposeAll()ctx.gl.dispose()// `gl.dispose()` frees the buffers/texture/program but NOT the context itself, and thediff --git a/src/renderer/glyphgrid/addon.ts b/src/renderer/glyphgrid/addon.tsindex 0ead41a52..6b4e06d83 100644--- a/src/renderer/glyphgrid/addon.ts+++ b/src/renderer/glyphgrid/addon.ts@@ -285,6 +285,16 @@ export class GlyphGridRendererAddonCore {* cost of resets being rare; the alternative is a synchronous repack inside a pack loop, which is* a correctness problem rather than a cosmetic one.*+ * AND WHY A TERMINAL THAT IS OFF-SCREEN AT RESET TIME STILL HEALS — the mechanism the correctness+ * above quietly rests on. A redraw request for a grid nobody can see does not evaporate at either+ * end: xterm's RenderService answers `refreshRows` on a PAUSED terminal (its intersection observer+ * saw it leave the viewport) by setting `_needsFullRefresh` and flushing that full refresh the+ * moment the terminal intersects again, and the engine's damage is likewise visibility-scoped+ * rather than visibility-dropped — the repacked rows are uploaded on the frame that brings the+ * grid back. Note the timing, because it widens the "one frame" above: the observer lifts the+ * pause ASYNCHRONOUSLY and the refresh it schedules is debounced, so a grid panned back into view+ * right after a reset can show stale glyphs for a FEW frames, not exactly one.+ ** Bounded by nothing here on purpose: a page too small for the canvas would reset again on the* repack, request another redraw, and settle into a repaint per frame. That is the LRU escalation* Phase 2 names, and it needs to be VISIBLE (the atlas logs `resetCount`) rather than smootheddiff --git a/src/renderer/glyphgrid/atlas.ts b/src/renderer/glyphgrid/atlas.tsindex 561b2af88..dad34d760 100644--- a/src/renderer/glyphgrid/atlas.ts+++ b/src/renderer/glyphgrid/atlas.ts@@ -73,12 +73,11 @@ export function slotPitch(cell: number): number {* renders BLANK while its neighbours are fine. Every headless-auditable path was audited and is* clean — box-glyphs claims nothing below U+0300 and never returns an empty op list, the raster* repaints the slot's whole PITCH rect (unclipped, before the cell clip is installed) ahead of the- * ink on BOTH branches, `cellXY` is the single copy of the- * layout math and the shader recomputes it identically, `strideX >= cellW + 2*GUTTER_PX` always- * (the rasterizer's cell is captured at construction and never re-adopted), and the atlas's dirty- * flag is polled by the rAF driver every frame, so no wake-up can be missed. What is left needs a- * real font on a real device, which no test here can produce — so the next round collects- * evidence instead of guessing. */+ * ink on BOTH branches, `cellXY` is the single copy of the layout math and the shader recomputes it+ * identically, `strideX >= cellW + 2*GUTTER_PX` always (the rasterizer's cell is captured at+ * construction and never re-adopted), and the atlas's dirty flag is polled by the rAF driver every+ * frame, so no wake-up can be missed. What is left needs a real font on a real device, which no+ * test here can produce — so the next round collects evidence instead of guessing. */export interface GlyphSlotAllocation {slot: numbercode: numberdiff --git a/src/renderer/glyphgrid/box-glyphs.ts b/src/renderer/glyphgrid/box-glyphs.tsindex 090ebe056..4178e26f1 100644--- a/src/renderer/glyphgrid/box-glyphs.ts+++ b/src/renderer/glyphgrid/box-glyphs.ts@@ -53,9 +53,10 @@* make it possible to "simplify" them back into flat washes that no longer match the renderer* beside them. Everything this module draws is ink or nothing.*- * "Opaque" is the atlas's ink colour, not an alpha value: `raster.ts` fills these rects WHITE onto- * its opaque BLACK page, so a set pixel is coverage 1 and everything else is coverage 0 — the same- * two states the fillText path produces, and the reason this module never touches `globalAlpha`.+ * "Opaque" is about the ALPHA, not about a particular colour: `raster.ts` has already filled the+ * slot with the cell's real BACKGROUND, and it fills these rects in the cell's real FOREGROUND, so a+ * set pixel is fully fg and every other pixel is left as bg — the same two states the `fillText`+ * path produces on a colour-keyed atlas, and the reason this module never touches `globalAlpha`.*/export interface PaintOp {x: numberdiff --git a/src/renderer/glyphgrid/gl-webgl2.ts b/src/renderer/glyphgrid/gl-webgl2.tsindex 7b7d2e35c..a272c7aac 100644--- a/src/renderer/glyphgrid/gl-webgl2.ts+++ b/src/renderer/glyphgrid/gl-webgl2.ts@@ -14,11 +14,18 @@ import { plateRectDevice } from './plate'* separation, so the last safe level is `floor(log2(2 * GUTTER_PX))` = 2 for the gutter of 2 this* atlas lays out. Raising the gutter raises this on its own; the two can never disagree.*- * Levels deeper than this are still GENERATED (generateMipmap builds the whole pyramid, and- * building fewer levels is not something the API offers) — they are simply never sampled, which is- * what the clamp buys. The residual it accepts is stated in GUTTER_PX's comment: at level 2 a- * bilinear tap can reach a pure-gutter texel holding a blend of two BACKGROUND colours. That is a- * soft edge between backgrounds at heavy zoom-out, never a ghost glyph.+ * Levels deeper than this are neither generated nor sampled. `generateMipmap` builds levels+ * `base+1 .. q`, where `q` is clamped by `TEXTURE_MAX_LEVEL` (ES 3.0 §3.8.9) — so setting MAX_LEVEL+ * to this constant BEFORE the generate call is what stops the driver building nine levels nobody may+ * read (about 0.35 MB per 2048² page, plus the work). MAX_LOD then forbids the SAMPLER from reaching+ * past it, and the pyramid stays mipmap-COMPLETE because completeness asks only for levels+ * `base .. q` — exactly the ones a clamped generate produces, which is why LINEAR_MIPMAP_LINEAR is+ * still a valid min filter here. (An earlier version of this comment claimed the API offers no way+ * to build fewer levels. It does; that sentence was wrong.)+ *+ * The residual the clamp accepts is stated in GUTTER_PX's comment: at level 2 a bilinear tap can+ * reach a pure-gutter texel holding a blend of two BACKGROUND colours. That is a soft edge between+ * backgrounds at heavy zoom-out, never a ghost glyph.*/const MAX_SAFE_LOD = Math.floor(Math.log2(2 * GUTTER_PX))@@ -262,6 +269,14 @@ export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {// down to 1×1. WebGL2 also allows mipmaps on NPOT textures, so a future page size is not a// correctness hazard here — only a rounding one at the deepest levels, which MAX_SAFE_LOD// never lets the sampler reach.+ //+ // BEFORE the generate, never after: `generateMipmap` builds levels up to `q`, which+ // TEXTURE_MAX_LEVEL clamps, so setting it here is what makes the pyramid stop at the deepest+ // level the sampler is allowed to read (MAX_LOD below). Set afterwards it would only hide+ // levels that had already been built. The texture stays mipmap-COMPLETE — completeness wants+ // levels base..q and a clamped generate produces exactly those — which is what keeps+ // LINEAR_MIPMAP_LINEAR a legal min filter.+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAX_LEVEL, MAX_SAFE_LOD)gl.generateMipmap(gl.TEXTURE_2D)gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)// The clamp the gutters pay for: levels deeper than MAX_SAFE_LOD may mix a neighbouringdiff --git a/src/renderer/glyphgrid/raster.ts b/src/renderer/glyphgrid/raster.tsindex 8aadfa56d..befd6aa04 100644--- a/src/renderer/glyphgrid/raster.ts+++ b/src/renderer/glyphgrid/raster.ts@@ -107,11 +107,21 @@ function baselineIn(ctx: OffscreenCanvasRenderingContext2D, font: RasterFont): n* Stated that way on purpose — an earlier wording claimed the inter-slot page ground is "never* sampled at LOD <= MAX_SAFE_LOD", which overstates it. Unallocated pitch cells DO enter a level-2* texel wherever the page is not yet full: at the allocation frontier, in the page's right/bottom- * remainder strip, and throughout a repack that has just called `clearPage`. What enters there is- * transparent page ground blended into a slot's edge texel — the same accepted-residual class as- * the background-vs-background blend GUTTER_PX's comment already names, and it disappears as the- * page fills. The promise that actually matters, and the one the LOD derivation rests on, is about- * INK.+ * remainder strip, and throughout a repack that has just called `clearPage`.+ *+ * What that looks like is NOT the background-vs-background blend GUTTER_PX's comment names, and the+ * two must not be conflated — same accepted-residual STATUS, different visual signature. The atlas+ * texture is NON-premultiplied (the default `UNPACK_PREMULTIPLY_ALPHA_WEBGL` is false), so a mip+ * level averages rgb and alpha INDEPENDENTLY: an edge texel that is half opaque background and half+ * transparent ground comes out as a HALF-BRIGHTNESS colour at HALF alpha, and the `SRC_ALPHA`+ * blend then attenuates that already-darkened colour by that same alpha again. The result is a+ * darker, slightly translucent rim on the outermost row/column of the affected cells at heavy+ * zoom-out, with the node's plate showing through it — bounded, cosmetic, and self-healing as the+ * page fills. Should the device round judge it objectionable, the escalation is to upload+ * premultiplied (`UNPACK_PREMULTIPLY_ALPHA_WEBGL` true) and blend `ONE, ONE_MINUS_SRC_ALPHA`, which+ * makes the average correct instead of double-counted. Device evidence first — it is not built now.+ *+ * The promise that actually matters, and the one the LOD derivation rests on, is about INK.** Unpacked, the four things this file must not break:* 1. The page ground starts (and `clearPage` returns to) TRANSPARENT-black. The atlas's slot 0 —