Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(terminal): measure characters on the same table as tmux and the CLIs

enes80e8df05dee6
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
index cda32b3d3..fdbd36148 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -304,17 +304,33 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
the block behind it — an un-inverted right half of 日 now means the follower's slot was keyed
on the wrong colours.
-- [ ] **2.16 A double-width character is WHOLE.** The 2026-08-05 report: ⭐ arrived as a fragment,
- because a slot's ink box is one cell and the follower cell was written blank. Print a row of
- wide characters — `printf '⭐ 👍 😄 日本語 中文\n'` — and compare against **GPU per terminal**
- on the same line. Each character is complete, and its two halves **meet without a step**: no
- seam of background down the middle, no visible offset between the halves, no doubled left
- half. Then repeat with **bold** on (`printf '\033[1m⭐ 日本語\033[0m\n'`) — the two halves must
- come off the same face, so a bold left half beside a regular right half is the failure.
- Expected residual: the seam may show a hairline difference in antialiasing, because the two
- halves are rasterized at different sub-texel phases (see `inkX` in `raster.ts`). A hairline is
- the accepted cost; a visible break or a colour seam is not. Characters wider than two cells
- are still cut — that is L16, unchanged.
+- [ ] **2.16 A double-width character is WHOLE — in EVERY renderer.** The 2026-08-05 report had two
+ faces and one cause: shared showed ⭐ as a fragment, GPU/DOM showed 👍😄 overlapping the next
+ character. xterm was measuring on the **Unicode 6** table, where every emoji is ONE cell wide,
+ while tmux and the agent CLIs measure on a modern one where they are two (see
+ `terminal/unicode-width.ts`). A renderer cannot draw a two-cell character correctly while the
+ buffer insists it is one cell.
+
+ Print a row of wide characters — `printf '⭐ 👍 😄 🎉 日本語 中文\n'` — and look at it in
+ **all three** renderer settings (Shared, GPU per terminal, Off). In each: every character is
+ complete, nothing overlaps its neighbour, and the two halves **meet without a step** — no
+ background seam down the middle, no offset, no doubled left half. Repeat with **bold**
+ (`printf '\033[1m⭐ 日本語\033[0m\n'`); a bold left half beside a regular right half is the
+ failure. Expected residual in SHARED only: the seam may show a hairline antialiasing
+ difference, because the two halves are rasterized at different sub-texel phases (`inkX` in
+ `raster.ts`). A hairline is the accepted cost; a visible break or a colour seam is not.
+ Characters wider than two cells are still cut — that is L16, unchanged.
+
+- [ ] **2.17 Column alignment after an emoji — the reason 2.16 matters.** Widths are not a looks
+ question: tmux repaints by ABSOLUTE cursor position, so if it and xterm disagree about how
+ many columns a character spans, the two screen models drift apart for the rest of the line and
+ a partial repaint can leave a column blank or doubled well away from the emoji. Run
+ `printf '⭐x⭐x⭐x\n123456789\n'` and check the `x`s line up with the digits they should; then
+ resize the node and confirm nothing shifts. **The real test is an agent session** — run one
+ that prints emoji and watch for a letter going missing mid-word, which is the other
+ 2026-08-05 report and a live candidate for the same cause. If misalignment appears **after**
+ this change, that host's tmux is the one on the old table (a build without utf8proc) — report
+ it as such; the fix is that tmux, not a return to Unicode 6.
## 3. Interactions
diff --git a/package-lock.json b/package-lock.json
index 14f5f78ff..beb3268a2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,15 +1,16 @@
{
"name": "node-terminal",
- "version": "0.2.33",
+ "version": "0.2.36",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "node-terminal",
- "version": "0.2.33",
+ "version": "0.2.36",
"hasInstallScript": true,
"license": "BUSL-1.1",
"dependencies": {
+ "@xterm/addon-unicode11": "^0.9.0",
"@xterm/addon-web-links": "^0.11.0",
"dompurify": "^3.4.11",
"electron-updater": "^6.8.9",
@@ -1467,9 +1468,6 @@
"arm"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1487,9 +1485,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1507,9 +1502,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1527,9 +1519,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1547,9 +1536,6 @@
"s390x"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1567,9 +1553,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1587,9 +1570,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1607,9 +1587,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1627,9 +1604,6 @@
"arm"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1653,9 +1627,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1679,9 +1650,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1705,9 +1673,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1731,9 +1696,6 @@
"s390x"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1757,9 +1719,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1783,9 +1742,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1809,9 +1765,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -2630,9 +2583,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2650,9 +2600,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2670,9 +2617,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2690,9 +2634,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -3262,6 +3203,12 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@xterm/addon-unicode11": {
+ "version": "0.9.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-unicode11/-/addon-unicode11-0.9.0.tgz",
+ "integrity": "sha512-FxDnYcyuXhNl+XSqGZL/t0U9eiNb/q3EWT5rYkQT/zuig8Gz/VagnQANKHdDWFM2lTMk9ly0EFQxxxtZUoRetw==",
+ "license": "MIT"
+ },
"node_modules/@xterm/addon-web-links": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@xterm/addon-web-links/-/addon-web-links-0.11.0.tgz",
diff --git a/package.json b/package.json
index 4df7dcd62..e909ebbc2 100644
--- a/package.json
+++ b/package.json
@@ -102,6 +102,7 @@
}
},
"dependencies": {
+ "@xterm/addon-unicode11": "^0.9.0",
"@xterm/addon-web-links": "^0.11.0",
"dompurify": "^3.4.11",
"electron-updater": "^6.8.9",
diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsx
index 442dc26e0..0e3a15070 100644
--- a/src/renderer/components/kanban/ModalTerminal.tsx
+++ b/src/renderer/components/kanban/ModalTerminal.tsx
@@ -12,6 +12,7 @@ import { useTerminalSearch } from '../../terminal/useTerminalSearch'
import { LocalTransport } from '../../terminal/local-transport'
import { clipboardImages, droppedPaths, pasteHasText, pastedFiles } from '../../terminal/file-drop'
import { parseOsc52 } from '../../terminal/osc52'
+import { activateUnicode11 } from '../../terminal/unicode-width'
import {
attachReplay,
seedPaint,
@@ -122,6 +123,10 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: Moda
// view of one session, and a card that renders it in different colours reads as a different
// terminal. (It used to hardcode its own background, which is exactly what happened.)
const term = new Terminal(xtermOptionsFromSettings(s))
+ // The modal is a second view of the SAME tmux session, so it has to measure characters the way
+ // the canvas node does. Two views on two width tables would disagree about where the columns
+ // are — and the pty runs at the SMALLEST subscriber's grid, so the disagreement would be live.
+ activateUnicode11(term)
const fit = new FitAddon()
term.loadAddon(fit)
const searchAddon = new SearchAddon()
diff --git a/src/renderer/components/settings/TerminalPreview.tsx b/src/renderer/components/settings/TerminalPreview.tsx
index 704b77fce..396f95a5a 100644
--- a/src/renderer/components/settings/TerminalPreview.tsx
+++ b/src/renderer/components/settings/TerminalPreview.tsx
@@ -3,6 +3,7 @@ import { Terminal } from '@xterm/xterm'
import { useSettings } from '../../state/settings'
import { applyLiveOptions, xtermOptionsFromSettings } from '../../terminal/terminal-config'
import { useXtermVisualSettings } from '../../terminal/useXtermVisualSettings'
+import { activateUnicode11 } from '../../terminal/unicode-width'
/** Fixed grid — the preview is a sample, not a fitted terminal, so there is no FitAddon and no
* ResizeObserver to keep in sync. Wide enough for the sample lines below without wrapping. */
@@ -56,6 +57,11 @@ export function TerminalPreview(): React.JSX.Element {
rows: PREVIEW_ROWS,
disableStdin: true
})
+ // The sample happens to hold no wide character today, so this changes nothing on screen. It is
+ // here so the invariant stays "every Terminal in this app measures characters the same way" —
+ // cheaper to keep than "every Terminal except the preview", and the day someone puts an emoji
+ // in the sample it would otherwise preview at a width no real terminal uses.
+ activateUnicode11(term)
termRef.current = term
term.open(hostRef.current!)
term.write(SAMPLE)
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 50475e8d2..49502ef7f 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -21,6 +21,7 @@ import { clipboardImages, droppedPaths, pasteHasText, pastedFiles } from '../ter
import type { TerminalTransport } from '../terminal/transport'
import { patchTerminalScale } from '../terminal/scale-fix'
import { parseOsc52 } from '../terminal/osc52'
+import { activateUnicode11 } from '../terminal/unicode-width'
import {
createFileLinkProvider,
createUrlLinkProvider,
@@ -870,6 +871,9 @@ export function TerminalNode({
// Appearance comes from ONE place, shared with the kanban card modal's viewer of this same
// session (`ModalTerminal`) — see `xtermOptionsFromSettings`.
const term = parked?.term ?? new Terminal(xtermOptionsFromSettings(s))
+ // Only on a FRESH instance: a parked terminal already carries the table, and the buffer it kept
+ // alive was measured with it — re-registering under a live buffer buys nothing.
+ if (!parked) activateUnicode11(term)
const fit = parked ? parked.fit : new FitAddon()
const searchAddon = parked ? parked.search : new SearchAddon()
termRef.current = term
diff --git a/src/renderer/terminal/unicode-width.test.ts b/src/renderer/terminal/unicode-width.test.ts
new file mode 100644
index 000000000..78ce8abb3
--- /dev/null
+++ b/src/renderer/terminal/unicode-width.test.ts
@@ -0,0 +1,102 @@
+import { describe, expect, it, vi } from 'vitest'
+import type { Terminal } from '@xterm/xterm'
+import { activateUnicode11 } from './unicode-width'
+
+/**
+ * These tests pin the FACT the 2026-08-05 emoji fix rests on, not the plumbing.
+ *
+ * The defect was a width disagreement: xterm shipped Unicode 6 widths, where an emoji is ONE cell,
+ * while tmux and the agent CLIs measure on a modern table where it is two. Every visible symptom —
+ * ⭐ clipped to a sliver in the shared renderer, 👍 overlapping its neighbour in the GPU/DOM ones —
+ * followed from that one number, and so does the glyphgrid fix that draws a wide character across
+ * both of its cells: without width 2 there is no second cell to draw into.
+ *
+ * So the number is what gets pinned. An xterm or addon upgrade that quietly moved these back, or a
+ * refactor that dropped the activation, would otherwise reintroduce the whole class silently — the
+ * kind of regression that only shows up as a screenshot from a device weeks later.
+ *
+ * Node has no DOM, so the terminal is a stub. That is enough: this file's whole job is to hand a
+ * real provider to a real terminal, and the provider is what the assertions interrogate.
+ */
+
+interface WidthProvider {
+ version: string
+ wcwidth(code: number): number
+}
+
+function stubTerminal(): { term: Terminal; provider: () => WidthProvider; version: () => string } {
+ let registered: WidthProvider | null = null
+ let active = '6'
+ const term = {
+ loadAddon: (addon: { activate: (t: unknown) => void }) => addon.activate(term),
+ unicode: {
+ register: (p: WidthProvider) => {
+ registered = p
+ },
+ get activeVersion() {
+ return active
+ },
+ set activeVersion(v: string) {
+ active = v
+ }
+ }
+ }
+ return {
+ term: term as unknown as Terminal,
+ provider: () => {
+ if (!registered) throw new Error('no width provider was registered')
+ return registered
+ },
+ version: () => active
+ }
+}
+
+describe('activateUnicode11', () => {
+ it('puts the terminal on the Unicode 11 table', () => {
+ const t = stubTerminal()
+ activateUnicode11(t.term)
+ expect(t.provider().version).toBe('11')
+ // Registering the provider is not enough — xterm keeps using the ACTIVE version, so a missing
+ // assignment here would leave every terminal on the old widths with no other symptom.
+ expect(t.version()).toBe('11')
+ })
+
+ describe('the widths the emoji fix depends on', () => {
+ // Each of these was reported from the device, or is the control that proves the change is
+ // narrow. Two cells is what tmux and the CLIs already believe; one cell was xterm alone.
+ const wide = ['⭐', '👍', '😄', '🎉', '日', '中']
+ const narrow = ['A', ' ', '─', '✓']
+
+ it('reports 2 for the characters that were rendering as fragments or overlaps', () => {
+ const t = stubTerminal()
+ activateUnicode11(t.term)
+ const w = t.provider()
+ expect(wide.map((c) => [c, w.wcwidth(c.codePointAt(0) as number)])).toEqual(
+ wide.map((c) => [c, 2])
+ )
+ })
+
+ it('leaves ordinary single-cell characters alone', () => {
+ const t = stubTerminal()
+ activateUnicode11(t.term)
+ const w = t.provider()
+ expect(narrow.map((c) => [c, w.wcwidth(c.codePointAt(0) as number)])).toEqual(
+ narrow.map((c) => [c, 1])
+ )
+ })
+ })
+
+ it('a terminal that refuses the addon still opens', () => {
+ // Fail-open on purpose: a terminal on yesterday's widths renders as it did yesterday, which is
+ // a far better outcome than a terminal that throws on construction.
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ const broken = {
+ loadAddon: () => {
+ throw new Error('nope')
+ }
+ } as unknown as Terminal
+ expect(() => activateUnicode11(broken)).not.toThrow()
+ expect(warn).toHaveBeenCalled()
+ warn.mockRestore()
+ })
+})
diff --git a/src/renderer/terminal/unicode-width.ts b/src/renderer/terminal/unicode-width.ts
new file mode 100644
index 000000000..6590b17cd
--- /dev/null
+++ b/src/renderer/terminal/unicode-width.ts
@@ -0,0 +1,56 @@
+import { Unicode11Addon } from '@xterm/addon-unicode11'
+import type { Terminal } from '@xterm/xterm'
+
+/**
+ * Put xterm on the SAME character-width table as everything else in the stack.
+ *
+ * xterm.js ships Unicode **6** widths and makes them the default, and nothing here ever changed
+ * that. Everyone else the bytes pass through is on a modern table: tmux measures with utf8proc,
+ * and the agent CLIs measure with `string-width`/`wcwidth` built from current Unicode. The two
+ * disagree about a whole class of characters — every emoji, and the symbols that gained Emoji
+ * Presentation along the way:
+ *
+ * ⭐ U+2B50 👍 U+1F44D 😄 U+1F604 🎉 U+1F389 xterm V6: 1 tmux/CLI: 2
+ * 日 U+65E5 中 U+4E2D xterm V6: 2 tmux/CLI: 2
+ *
+ * That single disagreement is what the 2026-08-05 device round reported, from both ends at once:
+ *
+ * - **Overlap** (GPU / DOM renderers). xterm advances ONE cell for an emoji whose ink is nearly
+ * two, and those renderers let ink overhang, so the glyph lands on top of whatever the next
+ * cell holds.
+ * - **A fragment** (shared renderer). The same one-cell advance, but glyphgrid clips every glyph
+ * to its own cell — deliberately, since ink in the gutter would ghost into a neighbour's mip —
+ * so the overflow is cut instead of overlapping. ⭐ arrived as a sliver.
+ *
+ * Same cause, two symptoms, and NEITHER is a renderer bug: a renderer cannot draw a two-cell
+ * character correctly while the buffer insists it is one cell wide. The glyphgrid fix that draws a
+ * wide character across both of its cells (`GlyphAtlas.glyphFor`'s `half`) is the other half of
+ * this one — it is what makes the second cell this table grants actually get painted.
+ *
+ * THE DEEPER SYMPTOM IS COLUMN ACCOUNTING, not looks. tmux keeps its own screen model and repaints
+ * xterm by ABSOLUTE cursor position, so when tmux believes an emoji spans columns 12–13 and xterm
+ * believes it spans 12 alone, the two models are shifted against each other for the rest of the
+ * line. A partial repaint then writes at coordinates that mean different things on the two sides,
+ * which can leave a column blank or doubled well away from the emoji that caused it. That is a
+ * live candidate for the "a letter goes missing mid-word" report of the same device round — a
+ * defect the blank-cell probe in `glyphgrid/feed.ts` stayed SILENT on, which is exactly what it
+ * would do if the buffer cell were genuinely empty rather than mis-drawn.
+ *
+ * WHAT TO WATCH, because this cuts both ways. Agreement is the goal, not the number 11: if a host's
+ * tmux were built WITHOUT utf8proc it would use a width-1 table and this would introduce the same
+ * mismatch in the opposite direction. Homebrew and Debian both build tmux with utf8proc, so the
+ * realistic case is the one this fixes; a host that misaligns AFTER this change is the case to
+ * report, and the fix there is that host's tmux, not a return to Unicode 6.
+ *
+ * Applies to every renderer, so it is loaded at terminal construction rather than anywhere near
+ * glyphgrid. Failure is non-fatal by design: a terminal on the old table renders as it did
+ * yesterday, which is far better than a terminal that does not open.
+ */
+export function activateUnicode11(term: Terminal): void {
+ try {
+ term.loadAddon(new Unicode11Addon())
+ term.unicode.activeVersion = '11'
+ } catch (err) {
+ console.warn('[terminal] could not activate Unicode 11 widths; staying on xterm’s default', err)
+ }
+}