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): balance tall terminal panes

Ruben Lütke5c8eae66e127
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx
index e930c52eef..111990d08e 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx
@@ -489,6 +489,31 @@ describe("grid layout", () => {
expect(box("Kai").left).toBe(75);
});
+ it("wraps four tall full-screen TUIs into two balanced bands", async () => {
+ const previous = globalThis.ResizeObserver;
+ class AreaObserver {
+ constructor(private readonly callback: ResizeObserverCallback) {}
+ observe(): void {
+ this.callback(
+ [{ contentRect: { width: 2048, height: 1100 } } as ResizeObserverEntry],
+ this as unknown as ResizeObserver,
+ );
+ }
+ unobserve(): void {}
+ disconnect(): void {}
+ }
+ globalThis.ResizeObserver = AreaObserver as unknown as typeof ResizeObserver;
+ try {
+ renderGrid(sessionWith([["Mika", 0], ["Nova", 1], ["Aria", 2], ["Kai", 3]]));
+ await waitFor(() =>
+ expect(box("Aria")).toMatchObject({ left: 0, top: 50, width: 50, height: 50 }),
+ );
+ expect(box("Kai")).toMatchObject({ left: 50, top: 50, width: 50, height: 50 });
+ } finally {
+ globalThis.ResizeObserver = previous;
+ }
+ });
+
it("a downward split takes only its OWN column, not the whole width", () => {
// The reported bug: splitting one pane used to open a window-wide row and
// squash every other pane to half height. Nova's column holds two panes;
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
index cb327bda6b..eff6c7477f 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
@@ -54,7 +54,7 @@ import {
} from "./AgenticTerminal";
import type { TerminalAppearance } from "./terminalThemes";
import {
- bandCapacityFor,
+ bandCapacityForArea,
GRID_HORIZONTAL_PADDING_PX,
MIN_PANE_HEIGHT_PX,
} from "./layout";
@@ -704,7 +704,21 @@ export function AgenticGrid({
resizeComposer(composerCollapsed ? COMPOSER_DEFAULT_PX : COMPOSER_COLLAPSED_PX);
}, [composerCollapsed, resizeComposer]);
- const perBand = useMemo(() => bandCapacityFor(gridWidth), [gridWidth]);
+ // A split-down pane adds height inside an existing column; it must not make
+ // the whole workspace re-wrap. Only independent side-by-side columns decide
+ // the band shape.
+ const layoutColumnCount = useMemo(
+ () => new Set(session.terminals.map((term) => term.column)).size,
+ [session.terminals],
+ );
+ // Height now influences wrapping too, so give it the same coarse step as
+ // width. A one-pixel WebView animation must not flip a whole band back and
+ // forth around the aspect threshold.
+ const layoutHeight = Math.round(gridHeight / 16) * 16;
+ const perBand = useMemo(
+ () => bandCapacityForArea(gridWidth, layoutHeight, layoutColumnCount),
+ [gridWidth, layoutHeight, layoutColumnCount],
+ );
/*
* The sizes the panes are drawn at, and the seams between them.
diff --git a/jarvis/ui/web/frontend/src/components/agentic/layout.ts b/jarvis/ui/web/frontend/src/components/agentic/layout.ts
index 5aa5d2aed5..ad5707fc79 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/layout.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/layout.ts
@@ -77,6 +77,23 @@ export const MIN_PANE_WIDTH_PX = 380;
*/
export const MIN_PANE_HEIGHT_PX = 240;
+/**
+ * Tallest useful shape for a full-screen coding-agent terminal, width / height.
+ *
+ * Width alone is not enough to decide how many panes belong on one line. A
+ * Claude Code or Codex TUI keeps its live status and input at the BOTTOM of the
+ * PTY while completed output stays above it. Four panes across a merely wide
+ * desktop can each be roughly 450 x 1,050 px: every line is still readable, so
+ * the width floor accepts the layout, but half the pane becomes blank ground
+ * between the last answer and the status bar. Four ordinary tiled terminals
+ * would be 2 x 2 instead.
+ *
+ * 0.58 keeps three panes side by side in the reported 2K window, wraps four to
+ * 2 x 2 there, and still permits four across on a genuinely ultrawide display.
+ * This is a shape floor, not a preferred ratio: wider panes remain untouched.
+ */
+export const MIN_PANE_ASPECT_RATIO = 0.58;
+
/**
* Horizontal padding of the rendered grid — 4 px on each side.
*
@@ -102,6 +119,49 @@ export function bandCapacityFor(
return Math.max(1, Math.min(MAX_PANES_PER_BAND, fits));
}
+/**
+ * Width capacity refined by the height the panes would have to fill.
+ *
+ * The return value remains the input expected by {@link paneColumns}; it is a
+ * ceiling, not necessarily the final column count. This matters for four panes:
+ * lowering the ceiling from four to three lets `paneColumns` balance them as
+ * two bands of two instead of producing a three-plus-one stub.
+ *
+ * Unknown height keeps the width-only answer. That is both the SSR/test-safe
+ * fallback and the least surprising first paint before ResizeObserver reports
+ * the real viewport.
+ */
+export function bandCapacityForArea(
+ widthPx: number,
+ heightPx: number,
+ columnCount: number,
+ minPaneWidth: number = MIN_PANE_WIDTH_PX,
+ minPaneAspect: number = MIN_PANE_ASPECT_RATIO,
+): number {
+ const widthCapacity = bandCapacityFor(widthPx, minPaneWidth);
+ if (
+ !Number.isFinite(widthPx) ||
+ widthPx <= 0 ||
+ !Number.isFinite(heightPx) ||
+ heightPx <= 0 ||
+ !Number.isFinite(columnCount) ||
+ columnCount <= 1 ||
+ !Number.isFinite(minPaneAspect) ||
+ minPaneAspect <= 0
+ ) {
+ return widthCapacity;
+ }
+
+ const count = Math.max(1, Math.trunc(columnCount));
+ for (let capacity = widthCapacity; capacity > 1; capacity -= 1) {
+ const columns = paneColumns(count, capacity);
+ const bands = Math.ceil(count / Math.max(1, columns));
+ const paneAspect = (widthPx / columns) / (heightPx / bands);
+ if (paneAspect >= minPaneAspect) return capacity;
+ }
+ return 1;
+}
+
/**
* Columns that fit inside the grid's content box.
*
@@ -115,6 +175,19 @@ export function workspaceBandCapacityFor(containerWidthPx: number): number {
);
}
+/** Area-aware counterpart for an outer box that still includes grid padding. */
+export function workspaceBandCapacityForArea(
+ containerWidthPx: number,
+ heightPx: number,
+ columnCount: number,
+): number {
+ return bandCapacityForArea(
+ Math.max(0, containerWidthPx - GRID_HORIZONTAL_PADDING_PX),
+ heightPx,
+ columnCount,
+ );
+}
+
/**
* Ceiling on the grid's row unit (see `paneGrid`).
*
diff --git a/jarvis/ui/web/frontend/src/components/agentic/layout.width.test.ts b/jarvis/ui/web/frontend/src/components/agentic/layout.width.test.ts
index 61d90ca31b..049bc1c22d 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/layout.width.test.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/layout.width.test.ts
@@ -3,6 +3,7 @@ import {
MAX_PANES_PER_BAND,
MIN_PANE_WIDTH_PX,
bandCapacityFor,
+ bandCapacityForArea,
paneColumns,
paneGrid,
} from "./layout";
@@ -50,6 +51,35 @@ describe("bandCapacityFor", () => {
});
});
+describe("bandCapacityForArea", () => {
+ it("turns four tall terminal columns into a balanced two-by-two workspace", () => {
+ // Reported 2026-07-30: at roughly this 2K desktop size, Claude Code kept
+ // its status at the bottom of each full-height TUI and its answer at the
+ // top. The width-only layout accepted four 500 x 1,100 panes, leaving a
+ // conspicuous empty half-screen between them.
+ const capacity = bandCapacityForArea(2048, 1100, 4);
+ expect(paneColumns(4, capacity)).toBe(2);
+ });
+
+ it("keeps three panes side by side in the same window", () => {
+ const capacity = bandCapacityForArea(2048, 1100, 3);
+ expect(paneColumns(3, capacity)).toBe(3);
+ });
+
+ it("still permits four across on a genuinely ultrawide display", () => {
+ const capacity = bandCapacityForArea(3840, 1000, 4);
+ expect(paneColumns(4, capacity)).toBe(4);
+ });
+
+ it("uses the width-only layout until height has been measured", () => {
+ expect(bandCapacityForArea(2048, 0, 4)).toBe(bandCapacityFor(2048));
+ });
+
+ it("does not collapse to one column before width has been measured", () => {
+ expect(bandCapacityForArea(0, 1100, 4)).toBe(MAX_PANES_PER_BAND);
+ });
+});
+
describe("wrapping with a measured capacity", () => {
const panes = Array.from({ length: 8 }, (_, i) => ({ column: i, slot: 0 }));