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 feed reads decorations — search highlights are visible again
enesafc2e8767e77
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.mdindex 535193bc9..876413861 100644--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md@@ -345,9 +345,12 @@ Auto after you switched builds, that is why: re-select Shared and carry on.- [ ] **3.13 Stacking.** The canvas is ABOVE the dot grid and BELOW node chrome; the bottom-leftControls, the minimap and the drawers are all still clickable over a terminal's body.- [ ] **3.14 ⌘F in a busy terminal.** Open the find bar and search for a word well up in the- scrollback: matches are found and scrolled to, and the counter (`n of m`) is right;- KNOWN — the match HIGHLIGHTS are not visible (L12). Navigating next/previous still moves the- viewport to each hit, so judge whether searching is usable without the highlight.+ scrollback: matches are found and scrolled to, the counter (`n of m`) is right, **the matched+ cells are HIGHLIGHTED, and the highlight follows next/previous** (the active hit reads+ differently from the rest). Then, with the bar still open, scroll the viewport: the highlights+ stay on their own matches instead of sliding onto other rows. Close the bar: every highlight+ goes away, leaving no coloured cell behind. Select a run of text that covers a match — the+ selection band stays unbroken over it, and the cursor stays visible when it lands on a hit.## 4. Lifecycle@@ -510,12 +513,6 @@ Auto after you switched builds, that is why: re-select Shared and carry on.- **L11 — Grids keep drawing while the kanban board covers the canvas.** The board overlay isopaque, so nothing is visible; it is wasted work, measured by item 4.16 and closed in Phase 2 ifit shows up.-- **L12 — Terminal search (⌘F) finds, counts and scrolls, but the match HIGHLIGHTS are invisible.**- xterm's search addon marks hits as *decorations*, which are painted by the active renderer at- cell level; the shared feed carries cells and theme lanes only, with no decoration input, so the- engine has nothing to draw. Search itself is unaffected — the addon still walks the buffer, the- `n of m` counter is correct, and each hit is scrolled into view — you simply cannot see which- cells matched. Phase 2 (a decoration lane in the feed).- **L13 — The block cursor on a double-width glyph paints only the left half-cell.** The cursor rectis emitted at one cell's width, while a CJK/emoji cell occupies two columns, so the block coversthe left column and the right half of the glyph stays uncovered. Cosmetic and position-correctdiff --git a/src/renderer/glyphgrid/addon.test.ts b/src/renderer/glyphgrid/addon.test.tsindex 39267e142..cd658bb0c 100644--- a/src/renderer/glyphgrid/addon.test.ts+++ b/src/renderer/glyphgrid/addon.test.ts@@ -7,6 +7,7 @@ import {type DeviceMetrics,type TermInternals} from './addon'+import type { DecorationReader } from './decorations'import type { CellView, ThemeLanes } from './feed'const THEME: ThemeLanes = {@@ -116,6 +117,45 @@ function recordingAtlas(o: { onGlyphFor?: (fire: () => void) => void } = {}): Pi}}+/** The decoration surface the shell hands over: a reader plus the two "something changed" events.+ * `fire*` is the test's hand on xterm's decoration service — the search addon registering a hit. */+function fakeDecorations(+ entries: Array<{ col: number; row: number; layer?: string; bg?: number; fg?: number }> = []+): {+ reader: DecorationReader+ onDecorationRegistered(cb: () => void): { dispose(): void }+ onDecorationRemoved(cb: () => void): { dispose(): void }+ fireRegistered(): void+ fireRemoved(): void+ subCount(): number+} {+ const registered = new Set<() => void>()+ const removed = new Set<() => void>()+ const sub = (set: Set<() => void>, cb: () => void): { dispose(): void } => {+ set.add(cb)+ return {+ dispose: (): void => {+ set.delete(cb)+ }+ }+ }+ return {+ reader: {+ empty: () => entries.length === 0,+ atCell: (col, row, cb) => entries.filter((e) => e.col === col && e.row === row).forEach(cb)+ },+ onDecorationRegistered: (cb) => sub(registered, cb),+ onDecorationRemoved: (cb) => sub(removed, cb),+ fireRegistered: () => {+ for (const cb of [...registered]) cb()+ },+ fireRemoved: () => {+ for (const cb of [...removed]) cb()+ },+ subCount: () => registered.size + removed.size+ }+}+interface FakeTermOpts {cols?: numberrows?: number@@ -125,10 +165,13 @@ interface FakeTermOpts {cursorY?: numbercursorVisible?: booleanfocus?: boolean+ decorations?: ReturnType<typeof fakeDecorations>}-function fakeTerm(o: FakeTermOpts = {}): TermInternals & { state: Required<FakeTermOpts> } {- const state: Required<FakeTermOpts> = {+type FakeTermState = Required<Omit<FakeTermOpts, 'decorations'>>++function fakeTerm(o: FakeTermOpts = {}): TermInternals & { state: FakeTermState } {+ const state: FakeTermState = {cols: o.cols ?? 4,rows: o.rows ?? 6,viewportY: o.viewportY ?? 0,@@ -153,7 +196,12 @@ function fakeTerm(o: FakeTermOpts = {}): TermInternals & { state: Required<FakeTdeviceMetrics: () => ({ charW: 16, charH: 34, cellW: 16, cellH: 34 }),dpr: () => 2,theme: () => THEME,- hasFocus: () => state.focus+ hasFocus: () => state.focus,+ // Absent unless a test asks for them — an xterm build with no decoration service hands the+ // addon exactly this, and every other test in this file is that case.+ decorations: o.decorations?.reader,+ onDecorationRegistered: o.decorations?.onDecorationRegistered,+ onDecorationRemoved: o.decorations?.onDecorationRemoved}}@@ -484,6 +532,68 @@ describe('GlyphGridRendererAddonCore atlas resets', () => {})})+/** DECORATIONS. The terminal's decoration service colours cells (a ⌘F hit is one), and it changes+ * from OUTSIDE the render loop — the search addon registers a decoration per match while nothing+ * is being packed. The addon's job is to hand the reader through to the feed keyed by the right+ * row, and to get every row repacked when the set changes. */+describe('GlyphGridRendererAddonCore decorations', () => {+ const DECO_BG = packColor(0xff, 0xc8, 0x00, 0xff)++ it('feeds decorations keyed by the ABSOLUTE buffer row, not the viewport row', () => {+ // Viewport starts at absolute 100, so viewport row 1 is absolute 101 — the row the decoration+ // marker is on. Keyed by the viewport row instead, the highlight would slide with every scroll.+ const deco = fakeDecorations([{ col: 2, row: 101, bg: DECO_BG }])+ const { core, handle } = make({ rows: 4, cols: 4, viewportY: 100, baseY: 100, decorations: deco })+ core.renderRows(0, 3)+ const row1 = handle.rows.find((r) => r.row === 1)!+ expect(readCell(row1.cells, 2).bg).toBe(DECO_BG)+ const row0 = handle.rows.find((r) => r.row === 0)!+ expect(readCell(row0.cells, 2).bg).toBe(THEME.bg)+ })++ it('asks for a DEFERRED full redraw when a decoration is registered or removed', () => {+ // Same mechanism as an atlas reset: a decoration changes cell COLOURS, so every row has to be+ // re-fed — but the pack itself is xterm's to schedule, never a repack from inside this event.+ const deco = fakeDecorations()+ const { core, handle } = make({ rows: 5, decorations: deco })+ const seen: Array<{ start: number; end: number }> = []+ core.onRequestRedraw((e) => seen.push(e))+ handle.rows.length = 0++ deco.fireRegistered()+ expect(handle.rows).toEqual([])+ expect(seen).toEqual([{ start: 0, end: 4 }])++ deco.fireRemoved()+ expect(handle.rows).toEqual([])+ expect(seen).toEqual([+ { start: 0, end: 4 },+ { start: 0, end: 4 }+ ])+ })++ it('unsubscribes from BOTH decoration events on dispose', () => {+ const deco = fakeDecorations()+ const { core } = make({ rows: 3, decorations: deco })+ const seen: number[] = []+ core.onRequestRedraw(() => seen.push(1))+ expect(deco.subCount()).toBe(2)+ core.dispose()+ expect(deco.subCount()).toBe(0)+ deco.fireRegistered()+ deco.fireRemoved()+ expect(seen).toEqual([])+ })++ it('constructs and packs normally when the terminal has no decoration service at all', () => {+ // The degradation contract: an xterm build without `_decorationService` must render, minus the+ // highlights — never refuse the attach.+ const { core, handle } = make({ rows: 2, cols: 2 })+ core.renderRows(0, 1)+ expect(handle.rows.map((r) => r.row)).toEqual([0, 1])+ })+})+describe('GlyphGridRendererAddonCore.dispose', () => {it('makes every further call inert — a torn-down terminal must never touch the grid', () => {const { core, handle } = make({ rows: 6 })diff --git a/src/renderer/glyphgrid/addon.ts b/src/renderer/glyphgrid/addon.tsindex 6b4e06d83..7549d98b5 100644--- a/src/renderer/glyphgrid/addon.ts+++ b/src/renderer/glyphgrid/addon.ts@@ -10,6 +10,7 @@import type { GlyphAtlas, GlyphAtlasSubscription } from './atlas'import { CELL_STRIDE } from './cells'+import type { DecorationReader } from './decorations'import type { GridHandle } from './engine'import { packViewportRow, type CellView, type ThemeLanes } from './feed'@@ -47,6 +48,15 @@ export interface TermInternals {theme(): ThemeLanes/** Read ONCE, at construction — see `focused`. */hasFocus(): boolean+ /** The terminal's decorations — the cell colours a ⌘F hit paints — or undefined.+ *+ * ALL THREE DECORATION MEMBERS ARE OPTIONAL, together: an xterm build whose decoration service+ * is missing or reshaped must degrade to "this terminal has no highlights", never to a refused+ * attach or a terminal on no renderer at all. The shell decides that once and hands over either+ * the whole trio or none of it. */+ decorations?: DecorationReader+ onDecorationRegistered?(cb: () => void): { dispose(): void }+ onDecorationRemoved?(cb: () => void): { dispose(): void }}/** The exact shape of xterm's `IRenderer.dimensions`. RenderService reads it straight off the@@ -125,6 +135,12 @@ export class GlyphGridRendererAddonCore {* it to repack rows into a grid its node has already dropped. */private readonly atlasResetSub: GlyphAtlasSubscription+ /** The terminal's decoration events, empty when it has no decoration service. Disposed with the+ * addon for the same reason the atlas subscription is: a live subscription on a terminal that+ * outlives its renderer (an attach that was swapped back to DOM) would go on asking a dead addon+ * to redraw a grid its node has dropped. */+ private readonly decorationSubs: Array<{ dispose(): void }> = []+constructor(private readonly internals: TermInternals,private readonly handle: GridHandle,@@ -137,6 +153,13 @@ export class GlyphGridRendererAddonCore {this.focused = internals.hasFocus()this.lastCursorRow = this.cursorViewportRow()this.updateDims()+ // Before the atlas subscription on purpose: these two reach xterm's own internals through the+ // shell, so they are the pair that could plausibly throw, and a throw here leaves NO+ // subscription behind. (The shell guards them anyway — see glyphgrid-attach.)+ const onRegistered = internals.onDecorationRegistered+ const onRemoved = internals.onDecorationRemoved+ if (onRegistered) this.decorationSubs.push(onRegistered(() => this.handleDecorationChange()))+ if (onRemoved) this.decorationSubs.push(onRemoved(() => this.handleDecorationChange()))// LAST, so nothing above can throw after the subscription exists: the shell catches a failing// construction and restores the DOM renderer, and a subscription made before that throw would// never be disposed by anyone.@@ -259,6 +282,8 @@ export class GlyphGridRendererAddonCore {this.disposed = truethis.redrawListeners.clear()this.atlasResetSub.dispose()+ for (const sub of this.decorationSubs) sub.dispose()+ this.decorationSubs.length = 0}// ---------------------------------------------------------------- internals@@ -305,6 +330,24 @@ export class GlyphGridRendererAddonCore {this.emitRedraw(0, this.rows - 1)}+ /**+ * A decoration was registered or removed — a ⌘F search adding a hit, or the find bar closing and+ * dropping all of them. Decorations change cell COLOURS, so the rows have to be re-fed; the ATLAS+ * is untouched (its slots are keyed by colour, and the ones this asks for next are simply+ * different keys), so nothing needs clearing.+ *+ * DEFERRED, through the same `onRequestRedraw` path an atlas reset uses, and for the same reason:+ * this fires from wherever the decoration owner happens to be — the search addon's own loop, a+ * dispose, a marker being trimmed out of the buffer — and packing rows from inside someone else's+ * call is exactly the re-entrancy `handleAtlasReset` documents at length. Handing the repack to+ * RenderService also coalesces the burst a search produces (one event per match) into a single+ * debounced render pass, instead of repacking every row per hit.+ */+ private handleDecorationChange(): void {+ if (this.disposed || this.rows <= 0) return+ this.emitRedraw(0, this.rows - 1)+ }+private repackAll(): void {if (this.disposed) returnthis.packRows(0, this.rows - 1)@@ -340,6 +383,9 @@ export class GlyphGridRendererAddonCore {// unclamped it matches no column and the cursor simply VANISHES at the end of a full line —// which is where a shell prompt spends much of its time.const cursorCol = Math.min(this.internals.cursorX(), this.cols - 1)+ // Read once for the whole range, like the theme: the shell builds the reader once and keeps it+ // live for the terminal's lifetime.+ const decorations = this.internals.decorationsfor (let row = start; row <= end; row++) {this.absRow = viewportY + rowpackViewportRow(this.rowBuf, this.readCellBound, this.workCell, {@@ -350,7 +396,11 @@ export class GlyphGridRendererAddonCore {// A block cursor on a DOUBLE-WIDTH glyph paints the left half only: the cursor is one// column and the glyph is two. Known v1 limitation (the two-column rule needs the wide// flag honoured in the shader) — visible, harmless, tracked for Phase 2.- cursorCol: row === cursorRow ? cursorCol : -1+ cursorCol: row === cursorRow ? cursorCol : -1,+ decorations,+ // Decoration markers are keyed by ABSOLUTE buffer row, so this is the row the lookup needs+ // — the viewport row would slide the highlights off their matches on every scroll.+ bufferRow: this.absRow})this.handle.updateRow(row, this.rowBuf)}diff --git a/src/renderer/glyphgrid/decorations.test.ts b/src/renderer/glyphgrid/decorations.test.tsnew file mode 100644index 000000000..a9d3fb221--- /dev/null+++ b/src/renderer/glyphgrid/decorations.test.ts@@ -0,0 +1,99 @@+import { describe, expect, it } from 'vitest'+import { packColor } from './cells'+import { decorationAt, type DecorationReader } from './decorations'++/** The fake the whole module is tested against — the same shape the attach shell builds over+ * xterm's `_decorationService`, and the reason this module never sees xterm at all. */+function reader(+ entries: Array<{ col: number; row: number; layer?: string; bg?: number; fg?: number }>+): DecorationReader & { walks: number } {+ const r = {+ walks: 0,+ empty: (): boolean => entries.length === 0,+ atCell: (col: number, row: number, cb: (d: { layer?: string; bg?: number; fg?: number }) => void): void => {+ r.walks+++ entries.filter((e) => e.col === col && e.row === row).forEach(cb)+ }+ }+ return r+}++describe('decorationAt', () => {+ it('returns null when the terminal has no decorations', () => {+ expect(decorationAt(reader([]), 0, 0)).toBeNull()+ })++ it('skips the per-cell walk entirely when the reader reports empty', () => {+ // The common case by a wide margin — nobody has ⌘F open — and this runs per CELL, so the+ // answer has to cost one boolean and nothing else.+ const r = reader([])+ decorationAt(r, 0, 0)+ expect(r.walks).toBe(0)+ })++ it('returns the background a search hit paints', () => {+ const bg = packColor(255, 200, 0, 255)+ expect(decorationAt(reader([{ col: 3, row: 1, bg }]), 3, 1)).toEqual({ bg, fg: undefined })+ })++ it('returns a foreground override too', () => {+ const fg = packColor(0, 0, 0, 255)+ expect(decorationAt(reader([{ col: 3, row: 1, fg }]), 3, 1)).toEqual({ bg: undefined, fg })+ })++ it('returns null for a cell no decoration covers', () => {+ const bg = packColor(255, 200, 0, 255)+ expect(decorationAt(reader([{ col: 3, row: 1, bg }]), 4, 1)).toBeNull()+ })++ it('ignores the TOP layer — xterm paints those over the text itself, not as a cell colour', () => {+ const bg = packColor(255, 200, 0, 255)+ expect(decorationAt(reader([{ col: 3, row: 1, layer: 'top', bg }]), 3, 1)).toBeNull()+ })++ it('treats a decoration with no layer as the BOTTOM layer, exactly as xterm defaults it', () => {+ const bg = packColor(255, 200, 0, 255)+ expect(decorationAt(reader([{ col: 3, row: 1, layer: 'bottom', bg }]), 3, 1)).toEqual({+ bg,+ fg: undefined+ })+ })++ it('returns null when the only decoration on the cell carries no colours', () => {+ // A marker-only decoration (an element in the overlay, no cell colours) must not turn into a+ // black cell — it has nothing to say about this cell's paint.+ expect(decorationAt(reader([{ col: 0, row: 0 }]), 0, 0)).toBeNull()+ })++ it('lets a later decoration win, matching xterm’s last-writer order', () => {+ const first = packColor(10, 10, 10, 255)+ const second = packColor(20, 20, 20, 255)+ expect(+ decorationAt(+ reader([+ { col: 0, row: 0, bg: first },+ { col: 0, row: 0, bg: second }+ ]),+ 0,+ 0+ )+ ).toEqual({ bg: second, fg: undefined })+ })++ it('keeps an earlier override the later decoration does not restate', () => {+ // Two decorations on one cell, each carrying only half the pair: the fg from the first survives+ // the second's bg — "last writer" is per CHANNEL, which is how xterm's own accumulation reads.+ const fg = packColor(1, 2, 3, 255)+ const bg = packColor(4, 5, 6, 255)+ expect(+ decorationAt(+ reader([+ { col: 0, row: 0, fg },+ { col: 0, row: 0, bg }+ ]),+ 0,+ 0+ )+ ).toEqual({ bg, fg })+ })+})diff --git a/src/renderer/glyphgrid/decorations.ts b/src/renderer/glyphgrid/decorations.tsnew file mode 100644index 000000000..afc50f582--- /dev/null+++ b/src/renderer/glyphgrid/decorations.ts@@ -0,0 +1,65 @@+/** Decorations — the cell-level colour overrides a terminal paints UNDER its text. xterm's search+ * addon registers one per match, which is the whole reason this module exists: without it the+ * shared renderer finds and scrolls to a hit and shows nothing highlighted.+ *+ * Like the rest of this directory it imports NOTHING from xterm. The terminal's decoration service+ * is private internals, so `src/renderer/terminal/glyphgrid-attach.ts` wraps it into the+ * `DecorationReader` below and the feed consumes only that interface — the same injection shape+ * `atlas` and `theme` already use, and what lets this be unit-tested against a fake. */++/** The overrides one cell's decorations impose, in the engine's packed-colour space (`packColor`+ * lanes). `undefined` means "no override" — a decoration that carries only a background must not+ * repaint the foreground black. */+export interface CellDecoration {+ bg?: number+ fg?: number+}++export interface DecorationReader {+ /** True when the terminal currently has NO decorations at all — the whole per-cell walk is+ * skipped on this answer, which is the common case (nobody has ⌘F open). */+ empty(): boolean+ /** xterm's own `forEachDecorationAtCell` signature, narrowed: `row` is the ABSOLUTE buffer row+ * (decoration markers are keyed absolutely, so a viewport row would highlight the wrong line the+ * moment the buffer scrolls), and each entry arrives with its colours already packed. */+ atCell(+ col: number,+ row: number,+ cb: (d: { layer?: string; bg?: number; fg?: number }) => void+ ): void+}++/**+ * The overrides a cell's decorations impose, or null.+ *+ * WHY 'top' IS SKIPPED. xterm's own renderers walk decorations twice: once at cell level for the+ * `bottom` layer (a background the text is drawn OVER) and once above the text for `top`. This+ * engine has one cell pass, so it can honour the bottom layer exactly and cannot express the top+ * one at all — and painting a top-layer decoration as a cell colour would put it UNDER the glyph,+ * which is the opposite of what it asked for. Search highlights are bottom-layer, which is why this+ * is enough to close L12; a top-layer decoration keeps rendering as nothing, the same as before.+ * A decoration with no layer at all is BOTTOM, matching xterm's own `options.layer ?? 'bottom'`.+ *+ * LAST WRITER WINS, per channel, matching the callback order xterm hands out — two decorations on+ * one cell is already ambiguous, and agreeing with the renderer we are replacing is the only+ * defensible answer.+ *+ * THE `empty()` FAST PATH IS NOT AN OPTIMIZATION DETAIL. This runs for every cell of every packed+ * row; on the common canvas nothing is decorated at all, and one boolean per cell is the difference+ * between that costing nothing and costing a call into xterm's service per cell.+ */+export function decorationAt(+ reader: DecorationReader,+ col: number,+ row: number+): CellDecoration | null {+ if (reader.empty()) return null+ let bg: number | undefined+ let fg: number | undefined+ reader.atCell(col, row, (d) => {+ if (d.layer === 'top') return+ if (d.bg !== undefined) bg = d.bg+ if (d.fg !== undefined) fg = d.fg+ })+ return bg === undefined && fg === undefined ? null : { bg, fg }+}diff --git a/src/renderer/glyphgrid/feed.test.ts b/src/renderer/glyphgrid/feed.test.tsindex 05d4e8274..f92b5e96f 100644--- a/src/renderer/glyphgrid/feed.test.ts+++ b/src/renderer/glyphgrid/feed.test.ts@@ -1,6 +1,7 @@import { describe, expect, it } from 'vitest'import { CELL_STRIDE, FLAG_BOLD, FLAG_CURSOR, FLAG_ITALIC, FLAG_SELECTED, FLAG_UNDERLINE, FLAG_WIDE, packColor, readCell } from './cells'import type { GlyphAtlas } from './atlas'+import type { DecorationReader } from './decorations'import { packViewportRow, type CellView, type RowFeedOpts, type ThemeLanes } from './feed'const THEME: ThemeLanes = {@@ -80,9 +81,32 @@ function makeCell(}}+/** A `DecorationReader` over a literal list, plus a walk counter so "the per-cell walk was+ * SKIPPED" is assertable — that fast path is the whole reason a canvas with no search open pays+ * nothing for this feature. */+function decoReader(+ entries: Array<{ col: number; row?: number; layer?: string; bg?: number; fg?: number }>+): DecorationReader & { walks: number } {+ const r = {+ walks: 0,+ empty: (): boolean => entries.length === 0,+ atCell: (+ col: number,+ row: number,+ cb: (d: { layer?: string; bg?: number; fg?: number }) => void+ ): void => {+ r.walks+++ entries.filter((e) => e.col === col && (e.row ?? 0) === row).forEach(cb)+ }+ }+ return r+}+function pack(cells: readonly (CellView | undefined)[],- o: Partial<Pick<RowFeedOpts, 'cols' | 'selection' | 'cursorCol' | 'atlas'>> = {}+ o: Partial<+ Pick<RowFeedOpts, 'cols' | 'selection' | 'cursorCol' | 'atlas' | 'decorations' | 'bufferRow'>+ > = {}): { out: Uint32Array; atlas: ReturnType<typeof fakeAtlas> } {const atlas = (o.atlas as ReturnType<typeof fakeAtlas>) ?? fakeAtlas()const cols = o.cols ?? cells.length@@ -92,7 +116,9 @@ function pack(atlas,theme: THEME,selection: o.selection ?? null,- cursorCol: o.cursorCol ?? -1+ cursorCol: o.cursorCol ?? -1,+ decorations: o.decorations,+ bufferRow: o.bufferRow})return { out, atlas }}@@ -320,6 +346,103 @@ describe('packViewportRow — cursor and selection', () => {})})+/** DECORATIONS — a search hit's highlight, and the precedence that makes it readable.+ *+ * The order the feed resolves in is base (default/palette/RGB) → inverse → dim → DECORATION →+ * selection → cursor. Both ends of that are load-bearing: a decoration must beat the cell's own+ * colours (otherwise a hit on coloured output is invisible), and selection/cursor must beat the+ * decoration (a hit inside a drag-selection that punched a hole in the selection band, or a+ * cursor that vanished when it landed on a match, both read as a broken terminal rather than as a+ * highlight). */+describe('packViewportRow — decorations', () => {+ const DECO_BG = packColor(0xff, 0xc8, 0x00, 0xff)+ const DECO_FG = packColor(0x00, 0x00, 0x00, 0xff)++ it('paints the background a decoration asks for', () => {+ const { out } = pack([makeCell({ code: 0x41 })], {+ decorations: decoReader([{ col: 0, bg: DECO_BG }])+ })+ expect(readCell(out, 0).bg).toBe(DECO_BG)+ })++ it('paints the foreground a decoration asks for, leaving the bg resolved', () => {+ const { out } = pack([makeCell({ code: 0x41, bg: ['palette', 5] })], {+ decorations: decoReader([{ col: 0, fg: DECO_FG }])+ })+ const c = readCell(out, 0)+ expect(c.fg).toBe(DECO_FG)+ expect(c.bg).toBe(THEME.ansi[5])+ })++ it('decorates only the covered columns', () => {+ const { out } = pack([makeCell({ code: 0x41 }), makeCell({ code: 0x42 })], {+ decorations: decoReader([{ col: 1, bg: DECO_BG }])+ })+ expect(readCell(out, 0).bg).toBe(THEME.bg)+ expect(readCell(out, 1).bg).toBe(DECO_BG)+ })++ it('wins over the cell’s OWN colours, including inverse and dim', () => {+ const { out } = pack([makeCell({ code: 0x41, fg: ['palette', 2], inverse: true, dim: true })], {+ decorations: decoReader([{ col: 0, bg: DECO_BG, fg: DECO_FG }])+ })+ const c = readCell(out, 0)+ expect(c.bg).toBe(DECO_BG)+ expect(c.fg).toBe(DECO_FG)+ })++ it('loses to the SELECTION — a hit inside a drag must not punch a hole in the band', () => {+ const { out } = pack([makeCell({ code: 0x41 })], {+ decorations: decoReader([{ col: 0, bg: DECO_BG }]),+ selection: [0, 1]+ })+ expect(readCell(out, 0).bg).toBe(THEME.selectionBg)+ })++ it('loses to the CURSOR — both colours, so the cursor never disappears onto a match', () => {+ const { out } = pack([makeCell({ code: 0x41 })], {+ decorations: decoReader([{ col: 0, bg: DECO_BG, fg: DECO_FG }]),+ cursorCol: 0+ })+ const c = readCell(out, 0)+ expect(c.bg).toBe(THEME.cursorBg)+ expect(c.fg).toBe(THEME.cursorFg)+ })++ it('is keyed by the ABSOLUTE buffer row, not the viewport row', () => {+ // Decoration markers are keyed by absolute buffer line: pack viewport row 0 of a scrolled+ // buffer and the lookup must ask for row 100, or every highlight lands on the wrong line the+ // moment the user scrolls.+ const deco = decoReader([{ col: 0, row: 100, bg: DECO_BG }])+ const { out } = pack([makeCell({ code: 0x41 })], { decorations: deco, bufferRow: 100 })+ expect(readCell(out, 0).bg).toBe(DECO_BG)+ const miss = pack([makeCell({ code: 0x41 })], { decorations: deco, bufferRow: 7 })+ expect(readCell(miss.out, 0).bg).toBe(THEME.bg)+ })++ it('asks the atlas for a slot painted in the DECORATED colours', () => {+ // The Phase 1c contract: the atlas is colour-keyed and the request happens after every+ // override, so a highlighted cell's glyph is rasterized onto the highlight.+ const { atlas } = pack([makeCell({ code: 0x41 })], {+ decorations: decoReader([{ col: 0, bg: DECO_BG, fg: DECO_FG }])+ })+ expect(atlas.colors).toEqual([[DECO_FG, DECO_BG]])+ })++ it('skips the per-cell walk entirely when nothing is decorated', () => {+ // The common case: no ⌘F anywhere on the canvas. A call per cell per row per frame into+ // xterm's decoration service is a real cost, and `empty()` is what buys it back.+ const deco = decoReader([])+ pack([makeCell(), makeCell(), makeCell()], { decorations: deco })+ expect(deco.walks).toBe(0)+ })++ it('paints nothing when no reader is supplied at all', () => {+ const { out } = pack([makeCell({ code: 0x41 })])+ expect(readCell(out, 0).bg).toBe(THEME.bg)+ })+})+/** THE COLOURS THE ATLAS IS ASKED FOR — the whole point of a colour-keyed atlas.** The rasterizer bakes the requested fg/bg into the slot's pixels and the shader blits themdiff --git a/src/renderer/glyphgrid/feed.ts b/src/renderer/glyphgrid/feed.tsindex 999a6250a..b1fb7151a 100644--- a/src/renderer/glyphgrid/feed.ts+++ b/src/renderer/glyphgrid/feed.ts@@ -6,6 +6,7 @@* xterm's internals, which are the part of that library most likely to move under us. */import type { GlyphAtlas } from './atlas'+import { decorationAt, type DecorationReader } from './decorations'import {FLAG_BOLD,FLAG_CURSOR,@@ -60,6 +61,14 @@ export interface RowFeedOpts {selection: readonly [number, number] | null/** Block-cursor column on THIS row, or -1. (Bar/underline cursors: Phase 2 — block only.) */cursorCol: number+ /** The terminal's decorations (search highlights and anything else that colours cells), or+ * undefined for "this terminal has none" — which is what every caller that predates them passes,+ * and what an xterm build with no decoration service degrades to. */+ decorations?: DecorationReader+ /** ABSOLUTE buffer row this viewport row shows — the coordinate space decoration markers are+ * keyed in. Only read when `decorations` is set; defaults to 0 so every existing caller stays+ * valid. */+ bufferRow?: number}const MAX_CODE_POINT = 0x10ffff@@ -161,6 +170,13 @@ function resolveBg(cell: CellView, theme: ThemeLanes): number {* skipped: this row buffer is REUSED across frames, so "write nothing" would leave the previous* frame's lanes standing at that column. Every column in [0, cols) is always written.*+ * DECORATIONS (a search hit's highlight is one) sit between the cell's own colours and the+ * selection: they OVERRIDE base/inverse/dim — a hit on coloured output has to be visible — and+ * LOSE to selection and cursor. That end matters just as much: a highlight that punched a hole in+ * a drag-selection band, or that swallowed the cursor when it landed on a match, reads as a broken+ * terminal rather than as a highlight. The whole per-cell lookup is skipped when the terminal has+ * no decorations at all (the common case), which is what makes an undecorated canvas pay nothing.+ ** CURSOR and SELECTION are applied last, over whatever the cell resolved to. Selection repaints* only the background (the foreground must stay readable as itself); the cursor repaints both.* On overlap the CURSOR WINS the colors, and BOTH flags stay set — the flags describe the cell's@@ -183,6 +199,10 @@ export function packViewportRow(const { cols, atlas, theme, selection, cursorCol } = optsconst selStart = selection ? selection[0] : -1const selEnd = selection ? selection[1] : -1+ // Hoisted out of the loop: `empty()` is answered ONCE per row rather than once per cell, and a+ // terminal with no decorations leaves this null so the per-cell branch below is a null test.+ const decorations = opts.decorations && !opts.decorations.empty() ? opts.decorations : null+ const bufferRow = opts.bufferRow ?? 0// Colors carried from a wide lead into its zero-width follower (see the doc comment).let carryPending = false@@ -248,6 +268,15 @@ export function packViewportRow(carryPending = false}+ // Over the cell's own colours (base/inverse/dim), under the selection and the cursor below.+ if (decorations) {+ const deco = decorationAt(decorations, col, bufferRow)+ if (deco) {+ if (deco.bg !== undefined) bg = deco.bg+ if (deco.fg !== undefined) fg = deco.fg+ }+ }+if (col >= selStart && col < selEnd) {bg = theme.selectionBgflags |= FLAG_SELECTEDdiff --git a/src/renderer/terminal/glyphgrid-attach.ts b/src/renderer/terminal/glyphgrid-attach.tsindex 354534ec9..da86c4a57 100644--- a/src/renderer/terminal/glyphgrid-attach.ts+++ b/src/renderer/terminal/glyphgrid-attach.ts@@ -19,6 +19,7 @@ import {} from '../glyphgrid/addon'import type { GlyphAtlas } from '../glyphgrid/atlas'import { packColor } from '../glyphgrid/cells'+import type { DecorationReader } from '../glyphgrid/decorations'import type { GridHandle } from '../glyphgrid/engine'import type { CellView, ThemeLanes } from '../glyphgrid/feed'@@ -38,6 +39,28 @@ interface XtermLine {length: numberloadCell(col: number, cell: unknown): unknown}+/** One entry of xterm's decoration service, as its own renderers read it: the layer defaults to+ * `bottom`, and either colour may be absent (a marker-only decoration colours nothing). */+interface XtermDecoration {+ options?: { layer?: string }+ backgroundColorRGB?: XtermColor+ foregroundColorRGB?: XtermColor+}+/** xterm's `_decorationService`. OPTIONAL everywhere it appears — see `decorationsOf`. */+interface XtermDecorationService {+ /** A COPY of the decoration list on every read (`[...this._array].values()` in the bundle), so+ * this is read at attach time and on change events only — NEVER per cell. */+ decorations: Iterable<unknown>+ forEachDecorationAtCell(+ col: number,+ /** ABSOLUTE buffer row — decorations are keyed by their marker's line. */+ row: number,+ layer: string | undefined,+ cb: (d: XtermDecoration) => void+ ): void+ onDecorationRegistered(cb: () => void): { dispose(): void }+ onDecorationRemoved(cb: () => void): { dispose(): void }+}/** The private members of xterm 5.5 we depend on. Names verified against the shipped bundle. */interface XtermCore {_renderService: { setRenderer(r: unknown): void; handleResize(cols: number, rows: number): void }@@ -50,6 +73,10 @@ interface XtermCore {_coreBrowserService: { dpr: number; isFocused: boolean }_bufferService: { buffer: { lines: { get(row: number): XtermLine | undefined } } }coreService: { isCursorInitialized: boolean; isCursorHidden: boolean }+ /** OPTIONAL, unlike every other member here: decorations are an ENHANCEMENT (search highlights),+ * so an xterm that dropped or reshaped this service must cost the user their highlights, not+ * their renderer. `coreOf` never checks it; `decorationsOf` shape-checks it and answers null. */+ _decorationService?: Partial<XtermDecorationService>}/** Every internal read in this module starts here. Presence-checked rather than cast, so a bumped@@ -89,6 +116,104 @@ function lane(c: XtermColor | undefined): number {return packColor((v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff, 0xff)}+/** What `decorationsOf` hands the addon: the reader the feed consumes, plus the two change events+ * the addon turns into a deferred full repack. All three or none — see `TermInternals`. */+type DecorationInternals = Pick<+ TermInternals,+ 'decorations' | 'onDecorationRegistered' | 'onDecorationRemoved'+>++/** Wrap xterm's decoration service in the feed's `DecorationReader`, or answer null.+ *+ * THE COST MODEL IS THE WHOLE DESIGN HERE. `empty()` is asked once per packed ROW and+ * `forEachDecorationAtCell` once per CELL of a decorated terminal, so neither may be expensive:+ * - `empty()` reads a COUNTER, never the service's `decorations` getter — that getter copies the+ * whole decoration array on every read (`[...this._array].values()`), which per row per frame+ * per terminal would be a real allocation storm. The counter is seeded once from that getter+ * (so decorations registered BEFORE the shared renderer attached are not missed) and then+ * maintained by the same two events the addon repacks on. It only ever errs UPWARD: a missed+ * `removed` leaves it high and costs one wasted walk that finds nothing, which is invisible; a+ * count that lied LOW would silently hide highlights, so nothing is allowed to zero it.+ * - `atCell` reuses ONE entry object across the whole walk. The feed reads its fields inside the+ * callback and never retains it (`decorationAt` copies what it wants into locals), so a fresh+ * object per decoration per cell would be pure garbage.+ *+ * Colours go through the same `lane()` the theme uses, alpha forced opaque for the same reason:+ * the engine's plate owns occlusion, and a translucent highlight would punch a hole in the node. */+function decorationsOf(core: XtermCore): DecorationInternals | null {+ const svc = core._decorationService+ if (!svc || typeof svc.forEachDecorationAtCell !== 'function') return null+ if (typeof svc.onDecorationRegistered !== 'function') return null+ if (typeof svc.onDecorationRemoved !== 'function') return null+ const service = svc as XtermDecorationService++ let count = 0+ try {+ for (const _ of service.decorations ?? []) count+++ } catch {+ // Unreadable list: start at zero and let the first registration light it up. Guessing "some"+ // instead would walk every cell of every frame forever on a terminal that has none.+ count = 0+ }++ const entry: { layer?: string; bg?: number; fg?: number } = {}+ const decorations: DecorationReader = {+ empty: () => count <= 0,+ atCell: (col, row, cb) => {+ try {+ // `undefined` layer = every layer; `decorationAt` drops the top one, which is the same+ // filter xterm's own renderers apply at cell level.+ service.forEachDecorationAtCell(col, row, undefined, (d) => {+ entry.layer = d.options?.layer+ entry.bg = d.backgroundColorRGB ? lane(d.backgroundColorRGB) : undefined+ entry.fg = d.foregroundColorRGB ? lane(d.foregroundColorRGB) : undefined+ cb(entry)+ })+ } catch {+ // A decoration service that threw mid-frame must cost this cell its highlight, not the+ // frame — this runs inside the pack loop of a live terminal.+ }+ }+ }++ /** Both events are wrapped so a subscribe that throws cannot take the addon's construction down+ * with it — the addon treats a no-op disposable as "this terminal simply never changes". */+ const subscribe = (+ fn: (cb: () => void) => { dispose(): void },+ onEvent: () => void,+ cb: () => void+ ): { dispose(): void } => {+ try {+ return fn(() => {+ onEvent()+ cb()+ })+ } catch {+ return { dispose: (): void => {} }+ }+ }++ return {+ decorations,+ onDecorationRegistered: (cb) =>+ subscribe(+ (h) => service.onDecorationRegistered(h),+ () => {+ count+++ },+ cb+ ),+ onDecorationRemoved: (cb) =>+ subscribe(+ (h) => service.onDecorationRemoved(h),+ () => {+ count = Math.max(0, count - 1)+ },+ cb+ )+ }+}+function themeLanes(colors: XtermColors): ThemeLanes {return {fg: lane(colors.foreground),@@ -178,7 +303,10 @@ export function attachGlyphGrid(deviceMetrics: () => deviceMetrics(term, core),dpr: () => core._coreBrowserService.dpr || 1,theme: () => theme,- hasFocus: () => core._coreBrowserService.isFocused+ hasFocus: () => core._coreBrowserService.isFocused,+ // Spread, so a terminal with no usable decoration service leaves all three members undefined —+ // the addon's "this terminal has no highlights" case.+ ...(decorationsOf(core) ?? {})}let addon: GlyphGridRendererAddonCore