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): exclude host padding from fitted row dimensions

review3f8fcb5250cd
diff --git a/CLAUDE.md b/CLAUDE.md
index f108819c7..025a52b7f 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1151,6 +1151,13 @@ session.
class the same way and no per-element opt-out can reach it); hoisting it to the whole NODE would
additionally take wheel-zoom-to-cursor away over every node, which is exactly where a
`wheelZoom` user aims.
+- **FitAddon reads the host's computed size, not its content rect.** The absolute, inset
+ canvas host uses `box-sizing: content-box` so its padding is excluded from that size
+ (#671). Its outer hit/plate rect still fills the body. The board modal instead keeps
+ padding on a separate wrapper. Do not put border-box padding back on a fit host:
+ it over-reports rows and clips the last line. `scripts/terminal-fit-layout.test.ts`
+ measures real xterm layout through resize sweeps at DPR 1, 1.25, 1.5 and 2 in Chrome
+ (`CHROME_BIN` overrides the executable); this does not verify GPU row-seam rendering.
- A `ResizeObserver` drives `FitAddon.fit()` + `transport.resize`. Canvas zoom is a CSS
transform, so it does *not* change `clientWidth` — cols/rows stay stable across zoom.
`scale-fix.ts` patches xterm's mouse coords so text selection stays aligned when zoomed.
diff --git a/scripts/terminal-fit-layout.test.ts b/scripts/terminal-fit-layout.test.ts
new file mode 100644
index 000000000..829db8c31
--- /dev/null
+++ b/scripts/terminal-fit-layout.test.ts
@@ -0,0 +1,95 @@
+import { spawn } from 'node:child_process'
+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { pathToFileURL } from 'node:url'
+import WebSocket from 'ws'
+import { build } from 'esbuild'
+import { expect, it } from 'vitest'
+
+// Real layout + hit testing, not jsdom's zero rectangles. CI/device runs can supply CHROME_BIN.
+const chrome = process.env.CHROME_BIN ?? '/usr/bin/google-chrome'
+it.skipIf(!existsSync(chrome)).each([1, 1.25, 1.5, 2])('at DPR %s fits complete terminal rows inside the padded canvas host at fractional display scales', async (dpr) => {
+ const dir = mkdtempSync(join(tmpdir(), 'terminal-fit-layout-'))
+ try {
+ const bundle = await build({
+ entryPoints: ['test/fixtures/terminal-fit-layout.tsx'], bundle: true, write: false,
+ loader: { '.svg': 'dataurl' }, tsconfig: 'tsconfig.web.json', define: { 'process.env.NODE_ENV': '"production"' }
+ })
+ const css = readFileSync('node_modules/@xterm/xterm/css/xterm.css', 'utf8') + readFileSync('src/renderer/styles.css', 'utf8')
+ writeFileSync(join(dir, 'index.html'), `<style>${css}</style><div id="root"></div><pre id="result">WAIT</pre><script>${bundle.outputFiles[0].text}</script>`)
+ const browser = spawn(chrome, [
+ '--headless', '--no-sandbox', '--disable-gpu', `--user-data-dir=${join(dir, 'profile')}`,
+ '--window-size=1800,1100', '--remote-debugging-port=0', 'about:blank'
+ ])
+ const exited = new Promise(resolve => browser.once('exit', resolve))
+ try {
+ const endpoint = await new Promise<string>((resolve, reject) => {
+ let output = ''
+ browser.stderr.on('data', chunk => {
+ output += chunk
+ const match = output.match(/DevTools listening on (ws:\/\/[^\s]+)/)
+ if (match) resolve(match[1])
+ })
+ browser.on('error', reject)
+ browser.on('exit', code => reject(new Error(`Chrome exited: ${code}`)))
+ })
+ const ws = new WebSocket(endpoint)
+ await new Promise(resolve => ws.once('open', resolve))
+ let id = 0
+ const call = (method: string, params = {}, sessionId?: string): Promise<any> => {
+ const next = ++id
+ return new Promise((resolve, reject) => {
+ const onMessage = (raw: WebSocket.RawData): void => {
+ const message = JSON.parse(raw.toString())
+ if (message.id !== next) return
+ ws.off('message', onMessage)
+ if (message.error) reject(new Error(JSON.stringify(message.error)))
+ else resolve(message.result)
+ }
+ ws.on('message', onMessage)
+ ws.send(JSON.stringify({ id: next, method, params, sessionId }))
+ })
+ }
+ try {
+ const { targetId } = await call('Target.createTarget', { url: 'about:blank' })
+ const { sessionId } = await call('Target.attachToTarget', { targetId, flatten: true })
+ await call('Emulation.setDeviceMetricsOverride', { width: 1800, height: 1100, deviceScaleFactor: dpr, mobile: false }, sessionId)
+ await call('Page.enable', {}, sessionId)
+ const loaded = new Promise<void>(resolve => {
+ const listener = (raw: WebSocket.RawData): void => {
+ const msg = JSON.parse(raw.toString())
+ if (msg.sessionId === sessionId && msg.method === 'Page.loadEventFired') {
+ ws.off('message', listener)
+ resolve()
+ }
+ }
+ ws.on('message', listener)
+ })
+ await call('Page.navigate', { url: pathToFileURL(join(dir, 'index.html')).href }, sessionId)
+ await loaded
+ const value = await call('Runtime.evaluate', {
+ expression: `new Promise(resolve => { const timer = setInterval(() => {
+ const text = document.getElementById('result')?.textContent;
+ if (text && text !== 'WAIT') { clearInterval(timer); resolve(text); }
+ }, 50); setTimeout(() => { clearInterval(timer); resolve('TIMEOUT'); }, 15000); })`,
+ awaitPromise: true, returnByValue: true
+ }, sessionId)
+ const result = value.result.value
+ expect(result).toMatch(/^PASS /)
+ writeFileSync(join(tmpdir(), `terminal-fit-layout-${dpr}.json`), result)
+ } finally {
+ await call('Browser.close')
+ // The CDP acknowledgement precedes profile flush/child shutdown. Wait for the process
+ // to finish normally before the fallback kill, or it can leave writers racing cleanup.
+ await exited
+ ws.close()
+ }
+ } finally {
+ browser.kill()
+ await exited
+ }
+ } finally {
+ rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 })
+ }
+}, 40000)
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index caec75eb2..eb69fbfde 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -2515,18 +2515,14 @@ body,
.term-node__xterm {
position: absolute;
inset: 0;
- /* The BOTTOM inset is the one that has to be deliberate. FitAddon derives rows from this host's
- * CONTENT height, so the space under the last line is `padding-bottom + fit slack` — and the
- * slack swings between 0 and a full cell as the node is resized, which leaves padding-bottom as
- * the only GUARANTEED gap there is. At 2px that guarantee sat under the selection ring, so a
- * selected node's last line read as CLIPPED (reported 2026-08-05, with the ring drawn through
- * the text). 6px matches the left inset and stays under the 8px the same terminal gets on the
- * board (`.kanban-modal__termwrap`).
- *
- * Do NOT unify this with the modal by moving padding onto ITS host: that one is a flex item and
- * padding there was measured to cost a whole row (see `.kanban-modal__term`). This host is
- * `position: absolute; inset: 0` and has carried vertical padding all along without losing one.
- * Two elements, two measured behaviours — re-measure before merging them. */
+ /* FitAddon reads the host's computed height/width and only subtracts padding on the
+ * xterm child. With the global border-box rule it counts this host's padding as cells,
+ * allowing the last row to extend under the node's clip (#671). For this auto-sized,
+ * absolutely inset host, content-box keeps the same outer rect while exposing the actual
+ * content dimensions to FitAddon. Keep the padding here: wheel hit testing and the shared
+ * glyph renderer's plate both use the host's full body-sized rect.
+ * The modal already puts its inset on a separate wrapper, outside its fit host. */
+ box-sizing: content-box;
padding: 4px 2px 6px 6px;
}
diff --git a/test/fixtures/terminal-fit-layout.tsx b/test/fixtures/terminal-fit-layout.tsx
new file mode 100644
index 000000000..8089405a3
--- /dev/null
+++ b/test/fixtures/terminal-fit-layout.tsx
@@ -0,0 +1,47 @@
+import { Terminal } from '@xterm/xterm'
+import { FitAddon } from '@xterm/addon-fit'
+import { quantizeCharSize } from '../../src/renderer/terminal/char-size-quantize'
+
+const frame = (): Promise<void> => new Promise(resolve => requestAnimationFrame(() => resolve()))
+const assert = (ok: boolean, message: string): void => { if (!ok) throw new Error(message) }
+
+async function run(): Promise<void> {
+ document.getElementById('root')!.innerHTML = `<div class="term-node" style="width:1282px;height:901px">
+ <div style="height:36px;flex-shrink:0"></div>
+ <div class="term-node__body"><div class="term-node__xterm"></div></div></div>`
+ const node = document.querySelector<HTMLElement>('.term-node')!
+ const host = document.querySelector<HTMLElement>('.term-node__xterm')!
+ const body = document.querySelector<HTMLElement>('.term-node__body')!
+ const term = new Terminal({ fontSize: 13, lineHeight: 1, fontFamily: 'monospace' })
+ const fit = new FitAddon()
+ term.loadAddon(fit)
+ term.open(host)
+ quantizeCharSize(term)
+ await new Promise<void>(resolve => term.write('preserved-session-marker', resolve))
+ const measurements: { height: number; dpr: number; rows: number; cell: number; screenHeight: number; available: number; overflow: number; clipOverflow: number }[] = []
+ try {
+ for (const height of [901, ...Array.from({ length: 31 }, (_, i) => 880 + i), 901]) {
+ node.style.height = height + 'px'
+ await frame()
+ fit.fit()
+ assert(Array.from({ length: term.buffer.active.length }, (_, i) =>
+ term.buffer.active.getLine(i)?.translateToString(true)).some(line =>
+ line?.includes('preserved-session-marker')), 'buffer lost during resize')
+ await new Promise<void>(resolve => term.write('\x1b[' + term.rows + ';1Hbottom gyjp', resolve))
+ await frame()
+ const cell = (term as any)._core._renderService.dimensions.css.cell.height as number
+ const screen = host.querySelector('.xterm-screen')!.getBoundingClientRect()
+ const clip = body.getBoundingClientRect()
+ const padding = parseFloat(getComputedStyle(host).paddingBottom)
+ const measurement = { height, dpr: devicePixelRatio, rows: term.rows, cell,
+ screenHeight: screen.height, available: clip.bottom - padding - screen.top,
+ overflow: screen.bottom - (clip.bottom - padding), clipOverflow: screen.bottom - clip.bottom }
+ measurements.push(measurement)
+ assert(Math.abs(host.getBoundingClientRect().height - clip.height) < 0.05, 'host no longer covers body')
+ assert(term.buffer.active.getLine(term.buffer.active.baseY + term.rows - 1)?.translateToString(true).startsWith('bottom') === true, 'bottom missing')
+ }
+ assert(measurements.every(m => m.overflow <= 0.05), JSON.stringify(measurements.reduce((a, b) => a.overflow > b.overflow ? a : b)))
+ document.getElementById('result')!.textContent = 'PASS ' + JSON.stringify(measurements)
+ } finally { term.dispose() }
+}
+run().catch(error => { document.getElementById('result')!.textContent = 'FAIL ' + error.message })