Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(agentic-ide): shrink a narrow pane's text instead of clipping its lines

rubenluetke10-beep486ef01fccf4
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
index 097ce2d509..e966245240 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
@@ -8,6 +8,16 @@ const terminalHarness = vi.hoisted(() => ({
fit: vi.fn(),
/** What the terminal reports after a fit — a test moves it to grow the pane. */
size: { cols: 80, rows: 24 },
+ /**
+ * The grid a tile holds at a given font size; `null` answers with `size`.
+ *
+ * Staged by the auto-shrink tests: the pane probes several text sizes while
+ * fitting its font to a narrow tile (see `fitFontToTile`), and a fixed
+ * answer could never tell it that shrinking helped.
+ */
+ sizeForFont: null as
+ | ((fontSize: number) => { cols: number; rows: number })
+ | null,
/** Every frame the pane hands its socket. Returns whether it went out. */
send: vi.fn<(payload: unknown) => boolean>(() => true),
/** Every explicit grid resize — how the pane pins itself below the floors. */
@@ -153,8 +163,16 @@ vi.mock("@xterm/addon-fit", () => ({
}
// The pane measures before it applies (see `sendResize`), so the double
// answers with whatever size the test has staged — the same value fit()
- // would land on.
+ // would land on. With `sizeForFont` staged the answer depends on the
+ // newest terminal's CURRENT font size, which is what lets a test watch
+ // the auto-shrink walk (see `fitFontToTile`).
proposeDimensions() {
+ const byFont = terminalHarness.sizeForFont;
+ if (byFont) {
+ const last =
+ terminalHarness.instances[terminalHarness.instances.length - 1];
+ return { ...byFont(Number(last?.options.fontSize ?? 0)) };
+ }
return { ...terminalHarness.size };
}
},
@@ -221,6 +239,7 @@ describe("AgenticTerminal layout", () => {
terminalHarness.modes.mouseTrackingMode = "none";
terminalHarness.bufferType = "normal";
terminalHarness.scrollLines.mockClear();
+ terminalHarness.sizeForFont = null;
globalThis.ResizeObserver = ResizeObserverHarness;
});
@@ -1162,6 +1181,7 @@ describe("pane refit", () => {
terminalHarness.resize.mockClear();
terminalHarness.handlers.current = null;
terminalHarness.size = { cols: 80, rows: 24 };
+ terminalHarness.sizeForFont = null;
vi.spyOn(document, "hasFocus").mockReturnValue(true);
});
@@ -1342,6 +1362,64 @@ describe("pane refit", () => {
});
});
+ it("shrinks its text until the floor grid fits a narrow tile", () => {
+ // The reported 2026-08-11 pane: a tile too narrow for 60 columns at the
+ // reader's size used to clip the right half of every line behind its edge
+ // — the left ~25 characters of each 60-column line, reading as shredded
+ // word-salad. The pane now walks its own text size down until the floor
+ // grid fits the tile, so the same 60 columns read small instead of cut.
+ const view = render(pane(false));
+ settle();
+ terminalHarness.send.mockClear();
+ terminalHarness.fit.mockClear();
+
+ // This tile holds 40 columns at the reader's 13px and the floor's 60 from
+ // 10px down. The walk must land on 10 — the LARGEST size that fits, not
+ // the smallest it may use.
+ terminalHarness.sizeForFont = (fontSize) =>
+ fontSize <= 10 ? { cols: 62, rows: 20 } : { cols: 40, rows: 20 };
+ view.rerender(pane(true));
+ settle();
+
+ const term =
+ terminalHarness.instances[terminalHarness.instances.length - 1];
+ expect(term?.options.fontSize).toBe(10);
+ // At the shrunken size the grid fits honestly — fit(), not a clamp.
+ expect(terminalHarness.fit).toHaveBeenCalled();
+ expect(terminalHarness.send).toHaveBeenCalledWith({
+ t: "r",
+ cols: 62,
+ rows: 20,
+ });
+ });
+
+ it("returns to the reader's text size when the tile widens again", () => {
+ const view = render(pane(false));
+ settle();
+ terminalHarness.sizeForFont = (fontSize) =>
+ fontSize <= 10 ? { cols: 62, rows: 20 } : { cols: 40, rows: 20 };
+ view.rerender(pane(true));
+ settle();
+ const term =
+ terminalHarness.instances[terminalHarness.instances.length - 1];
+ expect(term?.options.fontSize).toBe(10);
+ terminalHarness.send.mockClear();
+
+ // The tile widens (a sibling closed, the pane was maximized) — the shrink
+ // must not outlive its reason, or one crowded afternoon leaves the pane
+ // small forever.
+ terminalHarness.sizeForFont = () => ({ cols: 90, rows: 30 });
+ view.rerender(pane(false));
+ settle();
+
+ expect(term?.options.fontSize).toBe(13);
+ expect(terminalHarness.send).toHaveBeenCalledWith({
+ t: "r",
+ cols: 90,
+ rows: 30,
+ });
+ });
+
it("tells a fresh socket the pane's size whatever the last one heard", () => {
render(pane(false));
settle();
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 5b4a810cf6..5adc1e1beb 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -270,7 +270,9 @@ const MAX_TERMINAL_NAME = 40;
* moves then land on rows that no longer hold what they held when it drew
* them — every squeezed pane came back as shredded one-word fragments (also
* 2026-08-10). The tile's overflow-hidden container clips what the clamped
- * grid cannot show.
+ * grid cannot show — though clipping is now the LAST resort: the pane first
+ * shrinks its own text until the floor grid fits the tile (see
+ * MIN_AUTO_FONT_PX below), so a narrow tile reads small rather than cut off.
*
* Both the resize path and the connect-time handshake below refuse anything
* under these floors; the backend enforces the same ones
@@ -280,6 +282,27 @@ const MAX_TERMINAL_NAME = 40;
const MIN_REAL_COLS = 60;
const MIN_REAL_ROWS = 15;
+/**
+ * The smallest text the auto-shrink below may pick for a pane.
+ *
+ * A tile too narrow to hold the 60-column floor at the reader's text size has
+ * exactly three honest options: squeeze the PTY under the floor (what printed
+ * an answer one character per line — see the floors above), clip the right
+ * half of every line behind the tile's edge (what the floors' first fix did —
+ * a pane showing the left ~25 characters of each 60-column line reads as
+ * shredded word-salad, reported 2026-08-11), or draw the SAME 60 columns in
+ * smaller text. The pane now takes the third: `fitFontToTile` walks this
+ * pane's own text size down from the reader's choice until the floor grid
+ * fits the tile, and back up the moment the tile widens again. The toolbar's
+ * size is never touched — it stays the reader's choice, and every pane wide
+ * enough simply draws at it.
+ *
+ * 8px is where the walk stops. Beneath that the text is no more readable than
+ * the clipping it replaces, so a tile still too narrow at 8px falls back to
+ * clipping — now over far fewer hidden columns.
+ */
+export const MIN_AUTO_FONT_PX = 8;
+
export type PaneStatus = "connecting" | "live" | "exited" | "error";
/**
@@ -1230,27 +1253,112 @@ export function AgenticTerminal({
typeof document.hasFocus !== "function" ||
document.hasFocus());
- const sendResize = (claimOwner = false) => {
- // A hidden pane measures 0x0 (maximizing another one hides this one), and
- // fitting to that would resize the PTY to zero columns — which permanently
- // wrecks the agent's full-screen drawing. Skip while not measurable; the
- // ResizeObserver fires again when the pane comes back.
- if (container.clientWidth < 8 || container.clientHeight < 8) return;
- // Measured WITHOUT being applied yet: what the tile can show is a
- // PROPOSAL, and the floors above have the last word on it.
+ /**
+ * What the tile could hold at `size` — applied first when the terminal is
+ * not already drawing at it, because FitAddon measures the LIVE cell.
+ */
+ const measureAt = (size: number): { cols: number; rows: number } | null => {
+ if (term.options.fontSize !== size) {
+ term.options.fontSize = size;
+ // A new size is a new glyph advance, and so a new floored fraction for
+ // the canvas renderer to give back — same order as the fontSize effect.
+ alignTerminalCells(term);
+ }
let proposed: { cols: number; rows: number } | undefined;
try {
proposed = fit.proposeDimensions();
} catch {
- return;
+ return null;
}
if (
!proposed ||
!Number.isFinite(proposed.cols) ||
!Number.isFinite(proposed.rows)
) {
- return;
+ return null;
+ }
+ return proposed;
+ };
+
+ /** Can a coding CLI still lay its interface out in this grid? */
+ const holdsFloor = (
+ grid: { cols: number; rows: number } | null,
+ ): grid is { cols: number; rows: number } =>
+ grid !== null && grid.cols >= MIN_REAL_COLS && grid.rows >= MIN_REAL_ROWS;
+
+ /**
+ * Fit the pane's TEXT to the tile, before the grid is fit to the text.
+ *
+ * The reader's size is measured first, every time — growing back when the
+ * tile widens is as much of the contract as shrinking when it narrows, and
+ * starting from the current (possibly shrunken) size would leave a pane
+ * small forever. Only when the reader's size cannot hold the floor does
+ * the walk begin: the LARGEST smaller size whose grid still holds 60x15,
+ * found by bisection (column count only grows as text shrinks, so the
+ * answer is a boundary — a handful of integer sizes, four measures at
+ * most). See MIN_AUTO_FONT_PX for why the walk exists and where it stops.
+ *
+ * Returns the grid measured at the size it settled on, or null when the
+ * tile cannot be measured at all.
+ */
+ const fitFontToTile = (): { cols: number; rows: number } | null => {
+ const desired = Math.max(fontSizeRef.current, MIN_AUTO_FONT_PX);
+ const started = term.options.fontSize ?? desired;
+ let chosen = desired;
+ let proposed = measureAt(desired);
+ if (
+ proposed !== null &&
+ !holdsFloor(proposed) &&
+ desired > MIN_AUTO_FONT_PX
+ ) {
+ let lo = MIN_AUTO_FONT_PX;
+ let hi = desired - 1;
+ let best: {
+ size: number;
+ grid: { cols: number; rows: number };
+ } | null = null;
+ while (lo <= hi) {
+ const mid = Math.floor((lo + hi) / 2);
+ const grid = measureAt(mid);
+ if (holdsFloor(grid)) {
+ best = { size: mid, grid };
+ lo = mid + 1;
+ } else {
+ hi = mid - 1;
+ }
+ }
+ if (best) {
+ chosen = best.size;
+ proposed = best.grid;
+ } else {
+ // Not even the smallest text holds the floor. Clip — but at the
+ // smallest text, which hides the fewest columns behind the edge.
+ chosen = MIN_AUTO_FONT_PX;
+ proposed = measureAt(MIN_AUTO_FONT_PX);
+ }
}
+ // The bisection leaves the terminal at whatever it measured LAST.
+ if (term.options.fontSize !== chosen) {
+ term.options.fontSize = chosen;
+ alignTerminalCells(term);
+ }
+ // The canvas renderer caches glyphs per size; cleared once, at the end,
+ // never per probe — the probes happen between paints.
+ if (chosen !== started) term.clearTextureAtlas?.();
+ return proposed;
+ };
+
+ const sendResize = (claimOwner = false) => {
+ // A hidden pane measures 0x0 (maximizing another one hides this one), and
+ // fitting to that would resize the PTY to zero columns — which permanently
+ // wrecks the agent's full-screen drawing. Skip while not measurable; the
+ // ResizeObserver fires again when the pane comes back.
+ if (container.clientWidth < 8 || container.clientHeight < 8) return;
+ // Measured WITHOUT being applied yet: what the tile can show is a
+ // PROPOSAL, and the floors above have the last word on it. The pane's
+ // text size may have moved on the way — see fitFontToTile.
+ const proposed = fitFontToTile();
+ if (proposed === null) return;
// The one size everyone gets — the grid here, the agent below. Clamped
// per dimension (see the floors' comment): a narrow tile still hands
// the agent its honest HEIGHT, which is what keeps the CLI's