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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agentic-ide): detect and self-repair overlapping terminal panes
rubenluetke10-beep8f0dd44431f8
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsxindex 234bcf0858..a7d3356471 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx@@ -70,6 +70,12 @@ import {type PaneWeights,} from "./paneLayout";import { loadStoredArrangement, saveStoredArrangement, usePaneWeights } from "./usePaneWeights";+import {+ describeLayoutViolations,+ findLayoutViolations,+ hasLayoutViolations,+ type MeasuredPane,+} from "./paneLayoutGuard";import { ContinueInterrupted } from "./ContinueInterrupted";import { DeckStage, type DeckAgent } from "./deck/DeckStage";import type { CardState } from "./deck/AgentCard";@@ -1889,6 +1895,141 @@ export function AgenticGrid({[registerCell],);+ /*+ * The layout watchdog: the screen has to MATCH the layout, and when it does+ * not, the grid repairs itself instead of standing there looking broken.+ *+ * `paneLayout` cannot produce overlapping boxes, but the boxes reach the+ * screen through several hands — React's style props, the imperative drag+ * painter above, the 300 ms move glide, the maximize style swap — and any of+ * them interrupted at the wrong moment leaves a pane standing on its+ * neighbour while every status the app shows stays green, because the data+ * is right and only the pixels are wrong (maintainer report 2026-08-11: a+ * terminal half-covered by the pane beside it, workspace claiming all well).+ *+ * So, a beat after every layout change and every few seconds after that, the+ * visible cells are measured and judged by `findLayoutViolations`: no two+ * panes may intersect AT ALL, none may reach past the canvas into its+ * overflow clip, and no terminal's rendered screen may be bigger than its+ * pane. A fault is answered by rewriting every cell and seam from the layout+ * React already believes in — the truth is right here, it just has to be put+ * back on screen — and a stale terminal fit by the same resize pass a real+ * window resize triggers. The console says what was found, once per+ * incident, so a repair that did not hold leaves evidence instead of a loop.+ *+ * Held back whenever the pixels are ALLOWED to disagree for a moment: while+ * a seam or the prompt bar is dragged (painted imperatively), while a pane+ * is held for rearranging, under a maximize or a single-pane view (the+ * others measure 0x0 and there is nothing to overlap), and while nobody is+ * looking. The first check waits out the move glide, and a layout change+ * restarts the wait — mid-glide panes genuinely do cross each other.+ */+ const guardActive =+ onScreen &&+ documentVisible &&+ !chatView &&+ !deckView &&+ maximized === null &&+ arrange.held === null &&+ !layoutBusy;+ useEffect(() => {+ if (!guardActive) return;+ let cancelled = false;+ // One warning per incident, one escalation per failed repair — the guard+ // runs forever, and a console filling with the same line every three+ // seconds would bury the evidence it exists to leave.+ let announced = false;+ let escalated = false;++ const measure = () => {+ const surface = canvasRef.current?.getBoundingClientRect();+ if (!surface || surface.width <= 0 || surface.height <= 0) return null;+ const panes: MeasuredPane[] = [];+ for (const term of session.terminals) {+ const node = paneNodes.current.get(term.name);+ if (!node) continue;+ const rect = node.getBoundingClientRect();+ const content = node.querySelector(".xterm-screen")?.getBoundingClientRect();+ panes.push({+ name: term.name,+ left: rect.left,+ top: rect.top,+ width: rect.width,+ height: rect.height,+ content: content+ ? {+ left: content.left,+ top: content.top,+ width: content.width,+ height: content.height,+ }+ : undefined,+ });+ }+ return {+ panes,+ canvas: {+ left: surface.left,+ top: surface.top,+ width: surface.width,+ height: surface.height,+ },+ };+ };++ const check = () => {+ if (cancelled) return;+ const measured = measure();+ if (!measured) return;+ const violations = findLayoutViolations(measured.panes, measured.canvas);+ if (!hasLayoutViolations(violations)) {+ announced = false;+ escalated = false;+ return;+ }+ if (!announced) {+ announced = true;+ console.warn(+ "Agentic IDE: the workspace drifted from its layout — repairing:",+ describeLayoutViolations(violations),+ );+ } else if (!escalated) {+ escalated = true;+ console.error(+ "Agentic IDE: the workspace layout fault survived a repair:",+ describeLayoutViolations(violations),+ );+ }+ // Positions come back from the layout React already holds — the same+ // numbers its style props carry, written directly because a stale+ // inline style is invisible to React's diff (an unchanged prop is an+ // unwritten prop).+ session.terminals.forEach((term, index) => {+ const node = paneNodes.current.get(term.name);+ const box = layout.boxes[index];+ if (node && box) writePosition(node, paneBoxStyle(box));+ });+ for (const seam of layout.seams) {+ const node = seamNodes.current.get(seam.id);+ if (node) writePosition(node, seamStyle(seam));+ }+ // A terminal bigger than its pane is a missed refit; every pane listens+ // to window resizes with a debounced, no-op-when-unchanged fit, so this+ // is the ordinary path to a fresh measurement, not a special one.+ if (violations.clipped.length > 0) window.dispatchEvent(new Event("resize"));+ };++ // Past the 300 ms glide, then a slow patrol — measuring a dozen rects is+ // cheap, but forcing layout more often than this buys nothing.+ const first = window.setTimeout(check, 450);+ const patrol = window.setInterval(check, 3000);+ return () => {+ cancelled = true;+ window.clearTimeout(first);+ window.clearInterval(patrol);+ };+ }, [guardActive, layout, session.terminals]);+/** A pane that appears has to be SEEN appearing.*diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneLayoutGuard.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneLayoutGuard.test.tsnew file mode 100644index 0000000000..d8016c7386--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/paneLayoutGuard.test.ts@@ -0,0 +1,111 @@+import { describe, expect, it } from "vitest";+import {+ describeLayoutViolations,+ findLayoutViolations,+ hasLayoutViolations,+ type MeasuredCanvas,+ type MeasuredPane,+} from "./paneLayoutGuard";++const canvas: MeasuredCanvas = { left: 0, top: 0, width: 1000, height: 600 };++const at = (+ name: string,+ left: number,+ top: number,+ width: number,+ height: number,+ content?: MeasuredPane["content"],+): MeasuredPane => ({ name, left, top, width, height, content });++describe("findLayoutViolations", () => {+ it("calls a healthy gapped workspace healthy", () => {+ // Two columns 4 px apart, two panes stacked 4 px apart — the shape+ // `paneLayout` + `paneBoxStyle` actually produce.+ const report = findLayoutViolations(+ [+ at("T1", 0, 0, 498, 600),+ at("T2", 502, 0, 498, 298),+ at("T3", 502, 302, 498, 298),+ ],+ canvas,+ );+ expect(hasLayoutViolations(report)).toBe(false);+ });++ it("flags ANY overlap, however small past the tolerance", () => {+ // The report this guard exists for said it explicitly: it does not matter+ // by how much — overlapping at all is the bug.+ const report = findLayoutViolations(+ [at("T1", 0, 0, 500, 600), at("T2", 497, 0, 503, 600)],+ canvas,+ );+ expect(report.overlaps).toEqual([["T1", "T2"]]);+ });++ it("flags a pane standing on half of its neighbour", () => {+ const report = findLayoutViolations(+ [at("T1", 0, 0, 750, 600), at("T2", 500, 0, 500, 600)],+ canvas,+ );+ expect(report.overlaps).toEqual([["T1", "T2"]]);+ expect(hasLayoutViolations(report)).toBe(true);+ });++ it("lets sub-pixel rounding jitter pass", () => {+ // Browsers round fractional percentages per element; edges 0.4 px into+ // each other are noise, not a fault to repair every three seconds.+ const report = findLayoutViolations(+ [at("T1", 0, 0, 500.4, 600), at("T2", 500, 0, 500, 600)],+ canvas,+ );+ expect(report.overlaps).toEqual([]);+ });++ it("ignores hidden panes, which measure as sizeless", () => {+ // Under a maximize every other pane is display:none and reports 0x0 at+ // 0,0 — stacked on each other, and none of it on screen.+ const report = findLayoutViolations(+ [at("T1", 0, 0, 1000, 600), at("T2", 0, 0, 0, 0), at("T3", 0, 0, 0, 0)],+ canvas,+ );+ expect(hasLayoutViolations(report)).toBe(false);+ });++ it("flags a pane reaching past the canvas edge", () => {+ // The canvas clips silently (`overflow-hidden`), so a pane past its edge+ // is text cut off mid-word with nothing saying why.+ const report = findLayoutViolations([at("T1", 600, 0, 500, 600)], canvas);+ expect(report.escaped).toEqual(["T1"]);+ });++ it("flags terminal content bigger than its pane", () => {+ // A missed refit: the PTY still thinks the pane is wide, xterm renders+ // that width, and the pane clips the right half of every line.+ const report = findLayoutViolations(+ [at("T1", 0, 0, 500, 600, { left: 8, top: 40, width: 620, height: 500 })],+ canvas,+ );+ expect(report.clipped).toEqual(["T1"]);+ });++ it("accepts content a little smaller than its pane", () => {+ // The fit leaves the remainder under one character cell unused — that is+ // letterboxing, not a fault.+ const report = findLayoutViolations(+ [at("T1", 0, 0, 500, 600, { left: 8, top: 40, width: 484, height: 540 })],+ canvas,+ );+ expect(report.clipped).toEqual([]);+ });++ it("names what it found, for the console", () => {+ const report = findLayoutViolations(+ [at("T1", 0, 0, 750, 600), at("T2", 500, 0, 600, 600)],+ canvas,+ );+ const line = describeLayoutViolations(report);+ expect(line).toContain("T1+T2");+ expect(line).toContain("outside the canvas");+ });+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneLayoutGuard.ts b/jarvis/ui/web/frontend/src/components/agentic/paneLayoutGuard.tsnew file mode 100644index 0000000000..a0f912738c--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/paneLayoutGuard.ts@@ -0,0 +1,161 @@+/**+ * Detects a workspace whose PIXELS disagree with its layout.+ *+ * `paneLayout` cannot produce overlapping boxes — its fractions partition the+ * canvas exactly. But the boxes reach the screen through more than one hand:+ * React writes them as style props, a seam drag paints them straight onto the+ * DOM (`paintDraggedLayout`), moves glide there over 300 ms, and maximize swaps+ * the whole style object. Any of those paths interrupted at the wrong moment+ * can leave a pane standing where another one is — and every status the app+ * shows stays green, because the DATA is correct and only the pixels lie+ * (maintainer report 2026-08-11: a terminal half-covered by its neighbour+ * while the workspace claimed all was well).+ *+ * So the grid measures what is actually on screen and asks three questions no+ * healthy workspace ever answers yes to:+ *+ * * do two visible panes overlap? Neighbours are a `GRID_GAP_PX` apart by+ * construction, so ANY intersection is a bug — how deep does not matter.+ * * does a pane stick out of the canvas? The canvas is `overflow-hidden`, so+ * an escaped pane is silently clipped mid-word.+ * * is a terminal's rendered content bigger than its pane? That is a missed+ * refit: the PTY still thinks the pane is wide, and everything past the edge+ * is cut off.+ *+ * Pure functions over plain rectangles, so the answer is testable without a+ * browser laying anything out. The grid owns the measuring and the repair.+ */++/** One visible pane, measured from the DOM. All values are viewport px. */+export interface MeasuredPane {+ name: string;+ left: number;+ top: number;+ width: number;+ height: number;+ /**+ * The terminal's rendered screen (xterm's `.xterm-screen`), when the pane+ * holds one. Sized `cols x cellWidth` by the fit — so it may be a little+ * SMALLER than the pane (the remainder under one character cell) but must+ * never be bigger. Absent for a pane still connecting.+ */+ content?: { left: number; top: number; width: number; height: number };+}++/** The canvas the panes must stay inside, measured from the DOM. */+export interface MeasuredCanvas {+ left: number;+ top: number;+ width: number;+ height: number;+}++/** Everything wrong with what is on screen. Every list empty = healthy. */+export interface LayoutViolations {+ /** Pairs of pane names whose boxes intersect. */+ overlaps: Array<[string, string]>;+ /** Panes reaching past the canvas edge, into the overflow clip. */+ escaped: string[];+ /** Panes whose terminal content is wider or taller than the pane itself. */+ clipped: string[];+}++/**+ * Sub-pixel slack before a fault counts.+ *+ * Fractional percentages resolve to fractional pixels, and the browser rounds+ * them per element — two neighbours can honestly report edges 0.4 px into each+ * other. One pixel is far above that noise and far below anything a person+ * could see, let alone the half-a-terminal the report was about.+ */+const TOLERANCE_PX = 1;++/**+ * Extra slack for the content check only.+ *+ * The measured screen is the live xterm element mid-everything — font metrics+ * settling, a devicePixelRatio rounding the cell width up — so it gets a+ * little more room than the boxes do. A stale fit is off by whole character+ * cells (8–17 px each), never by three pixels.+ */+const CONTENT_TOLERANCE_PX = 3;++function intersects(a: MeasuredPane, b: MeasuredPane): boolean {+ return (+ a.left + TOLERANCE_PX < b.left + b.width &&+ b.left + TOLERANCE_PX < a.left + a.width &&+ a.top + TOLERANCE_PX < b.top + b.height &&+ b.top + TOLERANCE_PX < a.top + a.height+ );+}++/** Measure a set of visible panes against the three rules above. */+export function findLayoutViolations(+ panes: readonly MeasuredPane[],+ canvas: MeasuredCanvas,+): LayoutViolations {+ const overlaps: Array<[string, string]> = [];+ const escaped: string[] = [];+ const clipped: string[] = [];++ for (let i = 0; i < panes.length; i += 1) {+ const pane = panes[i];+ // A pane the browser reports as sizeless is hidden (`display: none` under+ // a maximize, a jsdom test with no layout at all) — nothing to judge.+ if (pane.width <= 0 || pane.height <= 0) continue;++ for (let j = i + 1; j < panes.length; j += 1) {+ const other = panes[j];+ if (other.width <= 0 || other.height <= 0) continue;+ if (intersects(pane, other)) overlaps.push([pane.name, other.name]);+ }++ if (+ pane.left < canvas.left - TOLERANCE_PX ||+ pane.top < canvas.top - TOLERANCE_PX ||+ pane.left + pane.width > canvas.left + canvas.width + TOLERANCE_PX ||+ pane.top + pane.height > canvas.top + canvas.height + TOLERANCE_PX+ ) {+ escaped.push(pane.name);+ }++ const content = pane.content;+ if (+ content &&+ content.width > 0 &&+ content.height > 0 &&+ (content.left + content.width > pane.left + pane.width + CONTENT_TOLERANCE_PX ||+ content.top + content.height > pane.top + pane.height + CONTENT_TOLERANCE_PX)+ ) {+ clipped.push(pane.name);+ }+ }++ return { overlaps, escaped, clipped };+}++/** Is there anything to repair at all? */+export function hasLayoutViolations(violations: LayoutViolations): boolean {+ return (+ violations.overlaps.length > 0 ||+ violations.escaped.length > 0 ||+ violations.clipped.length > 0+ );+}++/** One line for the console, naming what was found. */+export function describeLayoutViolations(violations: LayoutViolations): string {+ const parts: string[] = [];+ if (violations.overlaps.length > 0) {+ parts.push(+ `overlapping panes: ${violations.overlaps.map((pair) => pair.join("+")).join(", ")}`,+ );+ }+ if (violations.escaped.length > 0) {+ parts.push(`panes outside the canvas: ${violations.escaped.join(", ")}`);+ }+ if (violations.clipped.length > 0) {+ parts.push(`terminals bigger than their pane: ${violations.clipped.join(", ")}`);+ }+ return parts.join("; ");+}