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
@ feat(agentic-ide): split a pane in half, and let every seam be dragged
Ruben Lütkeeba202cd0021
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsxindex beaf54abb4..4a067a58fd 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx@@ -49,8 +49,15 @@ import {bandCapacityFor,GRID_HORIZONTAL_PADDING_PX,MIN_PANE_HEIGHT_PX,- paneGrid,} from "./layout";+import {+ paneLayout,+ remapColumnWeights,+ weightsAfterSplit,+ type PaneBox,+ type PaneSeam,+} from "./paneLayout";+import { usePaneWeights } from "./usePaneWeights";import { ContinueInterrupted } from "./ContinueInterrupted";import { PromptPreview } from "./PromptPreview";import { WorkspaceSettings } from "./WorkspaceSettings";@@ -211,6 +218,75 @@ const GRID_RESERVED_PX = 200;*/const GRID_GAP_PX = 4;+/** Half of it — what each pane gives up on the sides it shares with a neighbour. */+const HALF_GAP_PX = GRID_GAP_PX / 2;++/** A maximized pane simply fills the workspace. */+const MAXIMIZED_BOX: React.CSSProperties = {+ position: "absolute",+ inset: 0,+};++/** True when a fraction is at an edge of the workspace, allowing for float drift. */+function atEdge(value: number): boolean {+ return value <= 0.0001 || value >= 0.9999;+}++/**+ * Where one pane is drawn.+ *+ * The percentage is the pane's share; the pixels are the gap around it. A pane+ * gives up half a gap on each side it SHARES with a neighbour and nothing on a+ * side that faces the workspace edge — so neighbours end up one full gap apart+ * while the outer margin stays the container's own padding, whichever pane+ * happens to be on the outside.+ */+function paneBoxStyle(box: PaneBox | undefined): React.CSSProperties {+ if (!box) return MAXIMIZED_BOX;+ const left = atEdge(box.x) ? 0 : HALF_GAP_PX;+ const right = atEdge(box.x + box.w) ? 0 : HALF_GAP_PX;+ const top = atEdge(box.y) ? 0 : HALF_GAP_PX;+ const bottom = atEdge(box.y + box.h) ? 0 : HALF_GAP_PX;+ // Plain percentages where no gap is subtracted: a pane against two edges is+ // the whole workspace, and `calc(100% - 0px)` only makes that harder to read+ // in the inspector.+ const span = (fraction: number, trim: number) =>+ trim === 0 ? `${fraction * 100}%` : `calc(${fraction * 100}% - ${trim}px)`;+ const start = (fraction: number, shift: number) =>+ shift === 0 ? `${fraction * 100}%` : `calc(${fraction * 100}% + ${shift}px)`;+ return {+ position: "absolute",+ left: start(box.x, left),+ top: start(box.y, top),+ width: span(box.w, left + right),+ height: span(box.h, top + bottom),+ };+}++/**+ * Where one seam is drawn — centred on the boundary, spanning what it divides.+ *+ * The grip is 6 px wide against a 4 px gap, so it deliberately overlaps its two+ * panes by a pixel each. A seam narrower than the gap it sits in would be a+ * coordination test rather than a control.+ */+function seamStyle(seam: PaneSeam): React.CSSProperties {+ const half = 3;+ return seam.orientation === "vertical"+ ? {+ position: "absolute",+ left: `calc(${seam.x * 100}% - ${half}px)`,+ top: `${seam.y * 100}%`,+ height: `${seam.h * 100}%`,+ }+ : {+ position: "absolute",+ top: `calc(${seam.y * 100}% - ${half}px)`,+ left: `${seam.x * 100}%`,+ width: `${seam.w * 100}%`,+ };+}+/** Terminal appearance and text size are remembered, and the appearance follows* the app's own theme until the user says otherwise.@@ -287,6 +363,7 @@ export function AgenticGrid({accounts = [],onStateChanged,workspaceBar,+ appActions,}: AgenticGridProps) {const t = useT();const pushToast = useEventStore((s) => s.pushToast);@@ -471,17 +548,25 @@ export function AgenticGrid({*/const gridRef = useRef<HTMLDivElement | null>(null);const [gridWidth, setGridWidth] = useState(0);+ // How tall the workspace's visible area is. Panes are sized as FRACTIONS of+ // it now rather than by grid tracks, so unlike the width this is not only a+ // wrapping question — it is the number a percentage height resolves against,+ // and the floor under it (below) is what makes the workspace scroll instead+ // of squeezing every pane to three unreadable rows.+ const [gridHeight, setGridHeight] = useState(0);useEffect(() => {const node = gridRef.current;if (!node) return;const fallback = () =>Math.max(0, node.clientWidth - GRID_HORIZONTAL_PADDING_PX);setGridWidth(fallback());+ setGridHeight(node.clientHeight);const observer = new ResizeObserver((entries) => {const width = entries[0]?.contentRect.width ?? fallback();// Round to a step so a one-pixel drift cannot churn the layout (and with// it every pane's resize) on window animations.setGridWidth(Math.round(width / 16) * 16);+ setGridHeight(Math.round(entries[0]?.contentRect.height ?? node.clientHeight));});observer.observe(node);return () => observer.disconnect();@@ -603,6 +688,27 @@ export function AgenticGrid({// A fresh pane should receive the next prompt — that is why it was opened.const known = new Set(session.terminals.map((t) => t.name));const added = next.terminals.find((t) => !known.has(t.name));+ /*+ * A split HALVES the pane it was asked of, and touches nothing else.+ *+ * This is the behaviour people expect from every tiling terminal and+ * editor, and the one the old workspace did not have: a new pane became a+ * new full-height column, so every other pane on the line lost width to+ * make room for it. Splitting the pane you clicked should be a local+ * event — see `weightsAfterSplit`.+ */+ sizes.setWeights((current) =>+ anchor && added+ ? weightsAfterSplit(+ current,+ session.terminals,+ next.terminals,+ anchor,+ added.name,+ perBand,+ )+ : remapColumnWeights(current, session.terminals, next.terminals),+ );// ...unless it is a plain terminal — that one is typed into by hand, and// stealing the target would silently redirect the next prompt into a pane// that refuses it.@@ -693,6 +799,9 @@ export function AgenticGrid({const result = await closeTerminals(names);setPendingSelectionClose(null);setSelectedTerminals(new Set(result.failed.map((item) => item.name)));+ sizes.setWeights((current) =>+ remapColumnWeights(current, session.terminals, result.session.terminals),+ );onSessionChanged?.(result.session);const remaining = new Set(result.session.terminals.map((term) => term.name));if (maximized && !remaining.has(maximized)) setMaximized(null);@@ -1065,12 +1174,24 @@ export function AgenticGrid({onConfirm={onClose}/></Dialog.Root>++ {/* The shell's own actions, last in the row and separated from the+ workspace's — closing a workspace and restarting the whole app are+ not neighbours you want to confuse at a glance. */}+ {appActions && (+ <div+ data-testid="agentic-app-actions"+ className="ml-1 flex shrink-0 items-center gap-2 border-l border-border pl-2"+ >+ {appActions}+ </div>+ )}</div>{/* ------------------------------------------------------------- grid */}{/*- ONE grid, and every pane is a direct child of it — placed by the- coordinates `paneGrid` computed rather than by where it sits in a tree+ ONE container, and every pane is a direct child of it — placed by the+ fractions `paneLayout` computed rather than by where it sits in a treeof row and column elements.That is not a style choice. Every pane must stay MOUNTED for its whole@@ -1327,6 +1448,7 @@ export function AgenticGrid({</div>)}</div>+ </div>{/* Closing a terminal kills a working agent, so it always asks first. */}{pendingClose && (diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneLayout.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneLayout.test.tsnew file mode 100644index 0000000000..a9117bf36b--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/paneLayout.test.ts@@ -0,0 +1,262 @@+import { describe, expect, it } from "vitest";+import {+ dragSeam,+ evenSeam,+ evenWeights,+ MIN_SEAM_PANE_PX,+ paneLayout,+ remapColumnWeights,+ weightsAfterSplit,+ type PaneSeam,+ type PaneWeights,+ type Sized,+} from "./paneLayout";++/** A pane, the way the workspace state carries one. */+const pane = (name: string, column: number, slot = 0): Sized => ({ name, column, slot });++/** Rounded to the nearest hundredth — fractions carry float noise. */+const round = (value: number) => Math.round(value * 100) / 100;++function seamOf(seams: PaneSeam[], id: string): PaneSeam {+ const found = seams.find((seam) => seam.id === id);+ if (!found) throw new Error(`no seam ${id} in ${seams.map((s) => s.id).join(", ")}`);+ return found;+}++describe("paneLayout", () => {+ it("splits an untouched workspace evenly, which is where it starts", () => {+ const { boxes } = paneLayout([pane("A", 0), pane("B", 1), pane("C", 2)], 10);+ expect(boxes.map((box) => round(box.w))).toEqual([0.33, 0.33, 0.33]);+ expect(boxes.map((box) => round(box.x))).toEqual([0, 0.33, 0.67]);+ expect(boxes.every((box) => box.h === 1)).toBe(true);+ });++ it("gives a column its weight and leaves every other column alone", () => {+ // The whole point of weights: the middle column is twice as wide, and the+ // two beside it are unchanged relative to each other.+ const weights: PaneWeights = { ...evenWeights(), columns: [1, 2, 1] };+ const { boxes } = paneLayout([pane("A", 0), pane("B", 1), pane("C", 2)], 10, weights);+ expect(boxes.map((box) => round(box.w))).toEqual([0.25, 0.5, 0.25]);+ });++ it("stacks a column's panes by their own weights", () => {+ const weights: PaneWeights = { ...evenWeights(), panes: { B: 3 } };+ const { boxes } = paneLayout(+ [pane("A", 0), pane("B", 0, 1), pane("C", 0, 2)],+ 10,+ weights,+ );+ expect(boxes.map((box) => round(box.h))).toEqual([0.2, 0.6, 0.2]);+ expect(boxes.map((box) => round(box.y))).toEqual([0, 0.2, 0.8]);+ });++ it("lets two bands have DIFFERENT column widths", () => {+ // A CSS grid cannot express this — `grid-template-columns` is shared by+ // every row — and that limitation is why the workspace stopped being one.+ const panes = Array.from({ length: 4 }, (_, i) => pane(`T${i}`, i));+ const weights: PaneWeights = { ...evenWeights(), columns: [3, 1, 1, 1] };+ const { boxes } = paneLayout(panes, 2, weights);+ expect(round(boxes[0].w)).toBe(0.75);+ expect(round(boxes[1].w)).toBe(0.25);+ // The second band never saw the first band's weights.+ expect(round(boxes[2].w)).toBe(0.5);+ expect(round(boxes[3].w)).toBe(0.5);+ });++ it("offers a seam for every boundary and none for an edge", () => {+ const { seams } = paneLayout(+ [pane("A", 0), pane("B", 0, 1), pane("C", 1)],+ 10,+ );+ expect(seams.map((seam) => seam.id).sort()).toEqual(["column:0:1", "pane:A:B"]);+ expect(seamOf(seams, "column:0:1").orientation).toBe("vertical");+ expect(seamOf(seams, "pane:A:B").orientation).toBe("horizontal");+ });++ it("offers a seam between two bands", () => {+ const panes = Array.from({ length: 4 }, (_, i) => pane(`T${i}`, i));+ const { seams } = paneLayout(panes, 2);+ const band = seamOf(seams, "band:0:1");+ expect(band.orientation).toBe("horizontal");+ expect(band.y).toBe(0.5);+ expect(band.w).toBe(1);+ });++ it("reports the height below which the workspace scrolls instead of shrinking", () => {+ // Two bands whose tallest columns hold 2 and 1 panes: three minimum pane+ // heights, not the six a least-common-multiple row grid used to demand.+ const panes = [+ pane("A", 0),+ pane("B", 0, 1),+ pane("C", 1),+ pane("D", 2),+ pane("E", 3),+ ];+ expect(paneLayout(panes, 2).minHeightUnits).toBe(3);+ });++ it("closes gaps in column numbers rather than rendering a blank stripe", () => {+ const { boxes } = paneLayout([pane("A", 0), pane("B", 7)], 10);+ expect(boxes.map((box) => round(box.x))).toEqual([0, 0.5]);+ });++ it("has nothing to lay out for an empty workspace", () => {+ expect(paneLayout([], 10)).toEqual({+ boxes: [],+ seams: [],+ bands: 0,+ minHeightUnits: 0,+ });+ });+});++describe("dragSeam", () => {+ const twoColumns = paneLayout([pane("A", 0), pane("B", 1)], 10);+ const seam = seamOf(twoColumns.seams, "column:0:1");++ it("moves width from one side to the other and nowhere else", () => {+ // 1000 px wide, dragged 250 px right: the left pane takes three quarters.+ const next = dragSeam(evenWeights(), seam, 250, 1000);+ const { boxes } = paneLayout([pane("A", 0), pane("B", 1)], 10, next);+ expect(round(boxes[0].w)).toBe(0.75);+ expect(round(boxes[1].w)).toBe(0.25);+ });++ it("leaves a third column untouched while its neighbours trade", () => {+ const panes = [pane("A", 0), pane("B", 1), pane("C", 2)];+ const three = paneLayout(panes, 10);+ // 900 px wide, dragged 300 px right: A would swallow B whole, so B stops at+ // its 120 px minimum and A takes the rest of the two-thirds they share.+ const next = dragSeam(evenWeights(), seamOf(three.seams, "column:0:1"), 300, 900);+ const { boxes } = paneLayout(panes, 10, next);+ expect(round(boxes[0].w)).toBe(0.53);+ expect(round(boxes[1].w)).toBe(0.13);+ // The one that was not part of the drag keeps exactly its third.+ expect(round(boxes[2].w)).toBe(0.33);+ });++ it("stops a pane at the minimum instead of dragging it out of existence", () => {+ // A control that can be dragged to nothing has no way back.+ const next = dragSeam(evenWeights(), seam, 100000, 1000);+ const { boxes } = paneLayout([pane("A", 0), pane("B", 1)], 10, next);+ expect(Math.round(boxes[1].w * 1000)).toBe(MIN_SEAM_PANE_PX);+ });++ it("shares evenly when neither side can meet the minimum", () => {+ const next = dragSeam(evenWeights(), seam, 500, MIN_SEAM_PANE_PX);+ const { boxes } = paneLayout([pane("A", 0), pane("B", 1)], 10, next);+ expect(round(boxes[0].w)).toBe(0.5);+ });++ it("converts pixels against the BAND's height, not the window's", () => {+ // Two panes stacked in a column of a two-band workspace share half the+ // height, so 100 px is twice the fraction it would be across the whole one.+ const panes = [pane("A", 0), pane("B", 0, 1), pane("C", 1), pane("D", 2)];+ const layout = paneLayout(panes, 2);+ const stacked = seamOf(layout.seams, "pane:A:B");+ expect(stacked.axisFraction).toBe(0.5);+ const next = dragSeam(evenWeights(), stacked, 100, 1000);+ const { boxes } = paneLayout(panes, 2, next);+ // 100 px of a 500 px band is a fifth, moved from B to A.+ expect(round(boxes[0].h / 0.5)).toBe(0.7);+ });++ it("does nothing when the workspace has not been measured yet", () => {+ expect(dragSeam(evenWeights(), seam, 40, 0)).toEqual(evenWeights());+ });+});++describe("evenSeam", () => {+ it("makes two neighbours equal without disturbing the rest", () => {+ const panes = [pane("A", 0), pane("B", 1), pane("C", 2)];+ const seams = paneLayout(panes, 10).seams;+ const lopsided: PaneWeights = { ...evenWeights(), columns: [3, 1, 4] };+ const next = evenSeam(lopsided, seamOf(seams, "column:0:1"));+ expect(next.columns).toEqual([2, 2, 4]);+ });+});++describe("weightsAfterSplit", () => {+ it("halves the pane it was asked of and touches nothing else", () => {+ // The complaint this fixes: opening a terminal beside a pane used to make+ // every other pane on the line narrower.+ const before = [pane("A", 0), pane("B", 1), pane("C", 2)];+ const after = [pane("A", 0), pane("New", 1), pane("B", 2), pane("C", 3)];+ const next = weightsAfterSplit(evenWeights(), before, after, "A", "New", 10);+ const { boxes } = paneLayout(after, 10, next);+ // A held a third of the line; it and the pane split off it now hold a sixth+ // each — the same third between them.+ expect(round(boxes[0].w)).toBe(0.17);+ expect(round(boxes[1].w)).toBe(0.17);+ // ...and B and C are still exactly the third they each were.+ expect(round(boxes[2].w)).toBe(0.33);+ expect(round(boxes[3].w)).toBe(0.33);+ });++ it("halves a column that had already been dragged wide", () => {+ const before = [pane("A", 0), pane("B", 1)];+ const after = [pane("A", 0), pane("New", 1), pane("B", 2)];+ const wide: PaneWeights = { ...evenWeights(), columns: [3, 1] };+ const next = weightsAfterSplit(wide, before, after, "A", "New", 10);+ expect(next.columns).toEqual([1.5, 1.5, 1]);+ });++ it("halves the anchor's HEIGHT when the split went downwards", () => {+ const before = [pane("A", 0), pane("B", 1)];+ const after = [pane("A", 0), pane("New", 0, 1), pane("B", 1)];+ const next = weightsAfterSplit(evenWeights(), before, after, "A", "New", 10);+ const { boxes } = paneLayout(after, 10, next);+ expect(round(boxes[0].h)).toBe(0.5);+ expect(round(boxes[1].h)).toBe(0.5);+ // The pane beside them keeps its full height — that is what makes a split+ // down local to its own column.+ expect(boxes[2].h).toBe(1);+ });++ it("splits a stacked pane in half without resizing its neighbours", () => {+ const before = [pane("A", 0), pane("B", 0, 1)];+ const after = [pane("A", 0), pane("B", 0, 1), pane("New", 0, 2)];+ const next = weightsAfterSplit(evenWeights(), before, after, "B", "New", 10);+ const { boxes } = paneLayout(after, 10, next);+ expect(round(boxes[0].h)).toBe(0.5);+ expect(round(boxes[1].h)).toBe(0.25);+ expect(round(boxes[2].h)).toBe(0.25);+ });++ it("leaves the anchor alone when the new column wrapped onto another band", () => {+ // Halving would be a lie there: the two are not sharing a line, so the+ // anchor would just end up oddly narrow beside columns it never split from.+ const before = [pane("A", 0), pane("B", 1)];+ const after = [pane("A", 0), pane("New", 1), pane("B", 2)];+ const next = weightsAfterSplit(evenWeights(), before, after, "A", "New", 2);+ const { boxes } = paneLayout(after, 2, next);+ expect(round(boxes[0].w)).toBe(0.5);+ expect(round(boxes[1].w)).toBe(0.5);+ });+});++describe("remapColumnWeights", () => {+ it("keeps a dragged width on the column that kept its panes", () => {+ // The backend packs column numbers on every close, so column 2 afterwards+ // is not the column 2 that was dragged wide.+ const before = [pane("A", 0), pane("B", 1), pane("C", 2)];+ const after = [pane("A", 0), pane("C", 1)];+ const wide: PaneWeights = { ...evenWeights(), columns: [1, 1, 4] };+ expect(remapColumnWeights(wide, before, after).columns).toEqual([1, 4]);+ });++ it("starts a column nobody has seen before at the even width", () => {+ const before = [pane("A", 0)];+ const after = [pane("A", 0), pane("New", 1)];+ const wide: PaneWeights = { ...evenWeights(), columns: [4] };+ expect(remapColumnWeights(wide, before, after).columns).toEqual([4, 1]);+ });++ it("forgets the height of a pane that is gone", () => {+ const before = [pane("A", 0), pane("B", 0, 1)];+ const after = [pane("A", 0)];+ const weights: PaneWeights = { ...evenWeights(), panes: { A: 2, B: 3 } };+ expect(remapColumnWeights(weights, before, after).panes).toEqual({ A: 2 });+ });+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneLayout.ts b/jarvis/ui/web/frontend/src/components/agentic/paneLayout.tsnew file mode 100644index 0000000000..2be799f156--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/paneLayout.ts@@ -0,0 +1,492 @@+/**+ * What size every pane actually gets, and where the seams between them are.+ *+ * `./layout` answers "which column and which slot" — the arrangement. This+ * module answers "how much room", which used to have no answer at all: the grid+ * asked CSS for equal tracks, so every pane in a band was the same width and+ * every pane in a column the same height, always.+ *+ * That is wrong in the two ways people actually notice:+ *+ * * **Splitting a pane resized the whole workspace.** "Split right" added a+ * column, and a column is a share of the window — so splitting one pane made+ * every OTHER pane narrower. Splitting means halving the thing you split+ * everywhere else, and that is what it means here now: the new pane takes half+ * of its anchor's room and nothing else moves.+ * * **The seams could not be moved.** A workspace is not a set of equally+ * interesting panes. The one being read wants width; the three being watched+ * do not. So every boundary — between two columns, between two bands, between+ * two panes stacked in one column — is draggable.+ *+ * ## Weights, not pixels+ *+ * A pane's size is stored as a WEIGHT relative to its siblings, never as pixels.+ * Pixels do not survive a window resize, a second monitor, or the app opening on+ * a laptop; a weight does, and it is also what makes "half" mean half at every+ * window size.+ *+ * Three families of weight, each attached to the most stable identity available:+ *+ * * `columns` — by column index, because a column has no id of its own (the+ * backend renumbers them on every open and close). `remapColumnWeights` carries+ * them across such a renumber by matching on the panes each column holds.+ * * `bands` — by band index. A band is a line of columns, and which columns share+ * one depends on the window width, so there is nothing stabler to key on.+ * * `panes` — by call-sign, which IS stable for a pane's whole life.+ *+ * ## Fractions, not a CSS grid+ *+ * The layout is returned as fractional rectangles because one CSS grid cannot+ * express it: `grid-template-columns` is shared by every row, so two bands could+ * never have different column widths. Panes are therefore positioned absolutely+ * inside one container — which keeps the property the grid was chosen for in the+ * first place, that a pane is never re-parented and so never unmounts (see the+ * header of `./layout`).+ */+import { paneColumns, type Positioned } from "./layout";++/** Smallest a pane may be dragged to, on either axis. */+export const MIN_SEAM_PANE_PX = 120;++/** A pane's place in the workspace: what this module needs on top of `Positioned`. */+export interface Sized extends Positioned {+ /** Call-sign — the key its height weight is stored under. */+ name: string;+}++/**+ * How the workspace is divided, relative to its siblings at each level.+ *+ * Every value is a plain multiplier against its neighbours: two columns at 1 and+ * 1 are equal, at 2 and 1 the first is twice as wide. A missing entry is 1, so+ * an empty object is the even split the workspace has always started with, and a+ * layout stored by an older build simply picks up defaults for what it lacks.+ */+export interface PaneWeights {+ /** Width of each column, by column index (left to right). */+ columns: number[];+ /** Height of each band, by band index (top to bottom). */+ bands: number[];+ /** Height of each pane within its own column's stack, by call-sign. */+ panes: Record<string, number>;+}++/** The even split — what a workspace looks like before anything is dragged. */+export function evenWeights(): PaneWeights {+ return { columns: [], bands: [], panes: {} };+}++/** A pane's rectangle, as fractions of the workspace on both axes. */+export interface PaneBox {+ x: number;+ y: number;+ w: number;+ h: number;+ /** Which band it sits in, top to bottom. */+ band: number;+ /** Its column's index among all columns, left to right. */+ columnIndex: number;+ /** Its place in that column's stack, top to bottom. */+ slotIndex: number;+}++/** Which boundary a seam is, and therefore which weights a drag changes. */+export type SeamKind = "column" | "band" | "pane";++/**+ * A draggable boundary between two neighbours.+ *+ * `x`/`y`/`w`/`h` describe the LINE: a vertical seam has no width and a+ * horizontal one no height, so the renderer positions it by its centre and+ * stretches it along the other axis.+ */+export interface PaneSeam {+ id: string;+ kind: SeamKind;+ orientation: "vertical" | "horizontal";+ x: number;+ y: number;+ w: number;+ h: number;+ /**+ * The two neighbours, as keys into the matching weight family: column indexes+ * for `column`, band indexes for `band`, call-signs for `pane`.+ */+ before: string | number;+ after: string | number;+ /** Combined weight of every sibling the drag redistributes within. */+ groupWeight: number;+ /**+ * Fraction of the workspace axis those siblings span — 1 for columns (a band+ * is the full width) and bands (the full height), the band's own height for+ * panes stacked inside one column. Turns a pointer's pixels into weight.+ */+ axisFraction: number;+ /** Plain-language name, used as the seam's tooltip and accessible label. */+ label: string;+}++/** Everything a workspace needs to draw itself at the sizes it was given. */+export interface WorkspaceLayout {+ /** One box per input pane, in input order. */+ boxes: PaneBox[];+ seams: PaneSeam[];+ /** Lines of columns the workspace wraps into. */+ bands: number;+ /**+ * Height below which panes stop shrinking and the workspace scrolls instead,+ * in multiples of one minimum pane height — the tallest stack of each band,+ * added up. See `MIN_PANE_HEIGHT_PX` in `./layout` for why there is a floor.+ */+ minHeightUnits: number;+}++function weightAt(list: readonly number[], index: number): number {+ const value = list[index];+ return Number.isFinite(value) && (value as number) > 0 ? (value as number) : 1;+}++function paneWeight(weights: PaneWeights, name: string): number {+ const value = weights.panes[name];+ return Number.isFinite(value) && value > 0 ? value : 1;+}++/**+ * Lay a workspace out.+ *+ * `maxPerBand` is the width-derived cap from `bandCapacityFor` — the same number+ * the arrangement in `./layout` is computed from, so the two never disagree+ * about where a workspace wraps.+ */+export function paneLayout<T extends Sized>(+ panes: readonly T[],+ maxPerBand: number,+ weights: PaneWeights = evenWeights(),+): WorkspaceLayout {+ if (panes.length === 0) {+ return { boxes: [], seams: [], bands: 0, minHeightUnits: 0 };+ }++ // Columns in left-to-right order with gaps closed, exactly as `paneGrid` does+ // — a half-applied close must never render as a blank stripe.+ const ordered = [...new Set(panes.map((p) => p.column))].sort((a, b) => a - b);+ const columnIndex = new Map(ordered.map((column, index) => [column, index]));++ // Each column's panes, top to bottom, as indexes into `panes`.+ const stacks: number[][] = ordered.map(() => []);+ panes.forEach((pane, index) => {+ stacks[columnIndex.get(pane.column) ?? 0].push(index);+ });+ for (const stack of stacks) stack.sort((a, b) => panes[a].slot - panes[b].slot);++ const perBand = Math.max(1, paneColumns(ordered.length, maxPerBand));+ const bandCount = Math.ceil(ordered.length / perBand);++ // ------------------------------------------------------------------ bands+ const bandWeights = Array.from({ length: bandCount }, (_, band) =>+ weightAt(weights.bands, band),+ );+ const bandTotal = bandWeights.reduce((sum, w) => sum + w, 0) || 1;+ const bandY: number[] = [];+ const bandH: number[] = [];+ let yCursor = 0;+ for (let band = 0; band < bandCount; band += 1) {+ const height = bandWeights[band] / bandTotal;+ bandY.push(yCursor);+ bandH.push(height);+ yCursor += height;+ }++ const boxes: PaneBox[] = new Array(panes.length);+ const seams: PaneSeam[] = [];+ let minHeightUnits = 0;++ for (let band = 0; band < bandCount; band += 1) {+ const first = band * perBand;+ const inBand = ordered.slice(first, first + perBand).map((_, i) => first + i);+ const columnWeights = inBand.map((index) => weightAt(weights.columns, index));+ const columnTotal = columnWeights.reduce((sum, w) => sum + w, 0) || 1;++ let tallest = 1;+ let xCursor = 0;+ inBand.forEach((index, position) => {+ const width = columnWeights[position] / columnTotal;+ const stack = stacks[index];+ tallest = Math.max(tallest, stack.length);++ // ------------------------------------------------- panes in this column+ const stackWeights = stack.map((pane) => paneWeight(weights, panes[pane].name));+ const stackTotal = stackWeights.reduce((sum, w) => sum + w, 0) || 1;+ let stackCursor = 0;+ stack.forEach((pane, slot) => {+ const share = stackWeights[slot] / stackTotal;+ boxes[pane] = {+ x: xCursor,+ y: bandY[band] + bandH[band] * stackCursor,+ w: width,+ h: bandH[band] * share,+ band,+ columnIndex: index,+ slotIndex: slot,+ };+ if (slot > 0) {+ seams.push({+ id: `pane:${panes[stack[slot - 1]].name}:${panes[pane].name}`,+ kind: "pane",+ orientation: "horizontal",+ x: xCursor,+ y: bandY[band] + bandH[band] * stackCursor,+ w: width,+ h: 0,+ before: panes[stack[slot - 1]].name,+ after: panes[pane].name,+ groupWeight: stackTotal,+ axisFraction: bandH[band],+ label: `Drag to resize ${panes[stack[slot - 1]].name} and ${panes[pane].name}`,+ });+ }+ stackCursor += share;+ });++ if (position > 0) {+ seams.push({+ id: `column:${inBand[position - 1]}:${index}`,+ kind: "column",+ orientation: "vertical",+ x: xCursor,+ y: bandY[band],+ w: 0,+ h: bandH[band],+ before: inBand[position - 1],+ after: index,+ groupWeight: columnTotal,+ axisFraction: 1,+ label: "Drag to resize these two columns of terminals",+ });+ }+ xCursor += width;+ });++ minHeightUnits += tallest;++ if (band > 0) {+ seams.push({+ id: `band:${band - 1}:${band}`,+ kind: "band",+ orientation: "horizontal",+ x: 0,+ y: bandY[band],+ w: 1,+ h: 0,+ before: band - 1,+ after: band,+ groupWeight: bandTotal,+ axisFraction: 1,+ label: "Drag to resize these two rows of terminals",+ });+ }+ }++ return { boxes, seams, bands: bandCount, minHeightUnits };+}++// ---------------------------------------------------------------- dragging++function readSide(weights: PaneWeights, seam: PaneSeam, side: string | number): number {+ if (seam.kind === "pane") return paneWeight(weights, String(side));+ const list = seam.kind === "column" ? weights.columns : weights.bands;+ return weightAt(list, Number(side));+}++function writeSide(+ weights: PaneWeights,+ seam: PaneSeam,+ side: string | number,+ value: number,+): PaneWeights {+ if (seam.kind === "pane") {+ return { ...weights, panes: { ...weights.panes, [String(side)]: value } };+ }+ const key = seam.kind === "column" ? "columns" : "bands";+ const list = [...weights[key]];+ const index = Number(side);+ // A weight nobody has dragged yet is absent, not zero — fill the gap with the+ // default so writing index 5 of an empty list does not create four holes that+ // read back as 0 and collapse their columns.+ while (list.length <= index) list.push(1);+ list[index] = value;+ return { ...weights, [key]: list };+}++/**+ * Move one seam by ``deltaPx`` and hand back the weights that produce it.+ *+ * The two neighbours trade weight and nothing else changes — that is what makes+ * a drag local rather than a re-layout. `axisPx` is the workspace's size along+ * the drag axis, which is how pixels become weight, and both sides are held at+ * `MIN_SEAM_PANE_PX` so a seam can be pushed to the edge but never through it.+ */+export function dragSeam(+ weights: PaneWeights,+ seam: PaneSeam,+ deltaPx: number,+ axisPx: number,+): PaneWeights {+ const span = axisPx * seam.axisFraction;+ if (!Number.isFinite(span) || span <= 0) return weights;++ const before = readSide(weights, seam, seam.before);+ const after = readSide(weights, seam, seam.after);+ const total = before + after;+ const perPx = seam.groupWeight / span;+ const min = MIN_SEAM_PANE_PX * perPx;++ // Two panes that cannot both meet the minimum share what there is evenly —+ // better a pair of equally cramped panes than one dragged out of existence.+ if (total <= min * 2) {+ const half = total / 2;+ return writeSide(writeSide(weights, seam, seam.before, half), seam, seam.after, half);+ }++ const wanted = before + deltaPx * perPx;+ const next = Math.min(total - min, Math.max(min, wanted));+ return writeSide(+ writeSide(weights, seam, seam.before, next),+ seam,+ seam.after,+ total - next,+ );+}++/**+ * Give a seam's two neighbours the same size, leaving every other pane alone.+ *+ * This is what a double-click on a splitter does elsewhere, and it is genuinely+ * the useful reset: "make these two even again" is a request people have, while+ * "put the whole workspace back" almost never is.+ */+export function evenSeam(weights: PaneWeights, seam: PaneSeam): PaneWeights {+ const half = (readSide(weights, seam, seam.before) + readSide(weights, seam, seam.after)) / 2;+ return writeSide(writeSide(weights, seam, seam.before, half), seam, seam.after, half);+}++// ------------------------------------------------------- splits and closes++/** Which column index each pane sits in, gaps closed, for a set of panes. */+function columnIndexes<T extends Sized>(panes: readonly T[]): Map<string, number> {+ const ordered = [...new Set(panes.map((p) => p.column))].sort((a, b) => a - b);+ const byColumn = new Map(ordered.map((column, index) => [column, index]));+ return new Map(panes.map((pane) => [pane.name, byColumn.get(pane.column) ?? 0]));+}++/** How many columns a set of panes occupies. */+function columnCount<T extends Sized>(panes: readonly T[]): number {+ return new Set(panes.map((p) => p.column)).size;+}++/**+ * Carry column widths across a renumber.+ *+ * The backend packs column numbers on every open and close, so column 3 after a+ * split is not the column 3 that was dragged wide a minute ago. Matching on the+ * panes each column HOLDS survives that: a column keeps its width as long as it+ * keeps most of its panes, and a column with no predecessor starts even.+ */+export function remapColumnWeights<T extends Sized>(+ weights: PaneWeights,+ before: readonly T[],+ after: readonly T[],+): PaneWeights {+ const wasIn = columnIndexes(before);+ const nowIn = columnIndexes(after);++ // For each new column, how many of its panes came from each old column.+ const votes = new Map<number, Map<number, number>>();+ for (const pane of after) {+ const old = wasIn.get(pane.name);+ if (old === undefined) continue;+ const now = nowIn.get(pane.name) ?? 0;+ const tally = votes.get(now) ?? new Map<number, number>();+ tally.set(old, (tally.get(old) ?? 0) + 1);+ votes.set(now, tally);+ }++ const claimed = new Set<number>();+ const columns: number[] = [];+ for (let index = 0; index < columnCount(after); index += 1) {+ const tally = votes.get(index);+ let best: number | null = null;+ let bestCount = 0;+ for (const [old, count] of tally ?? []) {+ // Ties go to the leftmost old column, so a split's two halves cannot both+ // claim the same ancestor and end up with the same width by accident.+ if (count > bestCount || (count === bestCount && best !== null && old < best)) {+ best = old;+ bestCount = count;+ }+ }+ if (best !== null && !claimed.has(best)) {+ claimed.add(best);+ columns.push(weightAt(weights.columns, best));+ } else {+ columns.push(1);+ }+ }++ const live = new Set(after.map((pane) => pane.name));+ const panes = Object.fromEntries(+ Object.entries(weights.panes).filter(([name]) => live.has(name)),+ );+ return { columns, bands: [...weights.bands], panes };+}++/**+ * The weights a workspace has right after ``added`` was split off ``anchor``.+ *+ * A split HALVES its anchor. That is the whole point of the change: opening a+ * terminal beside a pane used to be a workspace-wide event — every other pane+ * lost width to make room for a new full-height column — and people reasonably+ * expect the pane they clicked to be the only one that changes.+ *+ * Halving is skipped in the one case where it would be a lie: when the new+ * column wrapped onto a different line than its anchor, the two are not sharing+ * anything, and shrinking the anchor to half of its band would leave it oddly+ * narrow next to neighbours it never split from.+ */+export function weightsAfterSplit<T extends Sized>(+ weights: PaneWeights,+ before: readonly T[],+ after: readonly T[],+ anchor: string,+ added: string,+ maxPerBand: number,+): PaneWeights {+ const carried = remapColumnWeights(weights, before, after);+ const nowIn = columnIndexes(after);+ const anchorColumn = nowIn.get(anchor);+ const addedColumn = nowIn.get(added);+ if (anchorColumn === undefined || addedColumn === undefined) return carried;++ if (anchorColumn === addedColumn) {+ // Split down: the new pane takes half of the anchor's height, and every+ // other pane in the column keeps exactly the height it had.+ const half = paneWeight(carried, anchor) / 2;+ return {+ ...carried,+ panes: { ...carried.panes, [anchor]: half, [added]: half },+ };+ }++ const perBand = Math.max(1, paneColumns(columnCount(after), maxPerBand));+ if (Math.floor(anchorColumn / perBand) !== Math.floor(addedColumn / perBand)) {+ return carried;+ }++ // Split right: the two halves together occupy the width the anchor had.+ const half = weightAt(carried.columns, anchorColumn) / 2;+ const columns = [...carried.columns];+ while (columns.length <= Math.max(anchorColumn, addedColumn)) columns.push(1);+ columns[anchorColumn] = half;+ columns[addedColumn] = half;+ return { ...carried, columns };+}diff --git a/jarvis/ui/web/frontend/src/components/agentic/usePaneWeights.ts b/jarvis/ui/web/frontend/src/components/agentic/usePaneWeights.tsnew file mode 100644index 0000000000..d7852fab7d--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/usePaneWeights.ts@@ -0,0 +1,185 @@+/**+ * The workspace's own sizes: held while you drag them, remembered afterwards.+ *+ * Deliberately localStorage rather than the backend. How wide one person likes+ * a pane on a 4K monitor is a property of that screen, not of the workspace —+ * pushing it through the session state would make a laptop and a desktop fight+ * over one set of numbers, and cost a config write per drag frame. It sits+ * beside the terminal appearance and font size, which are stored the same way+ * for the same reason.+ *+ * The stored value is keyed by workspace, so switching tabs restores the sizes+ * that workspace was left at rather than inheriting the last one's.+ */+import { useCallback, useEffect, useRef, useState } from "react";+import {+ dragSeam,+ evenSeam,+ evenWeights,+ type PaneSeam,+ type PaneWeights,+} from "./paneLayout";++const STORAGE_PREFIX = "jarvis.agenticIde.paneWeights.v1.";++/** How far one arrow-key press moves a seam. Matches `PaneResizer`. */+const KEY_STEP_PX = 16;++function storageKey(workspaceId: string): string {+ return `${STORAGE_PREFIX}${workspaceId}`;+}++/** Read stored weights, tolerating anything that is not the shape we wrote. */+export function loadWeights(workspaceId: string): PaneWeights {+ try {+ const raw = window.localStorage.getItem(storageKey(workspaceId));+ if (!raw) return evenWeights();+ const parsed = JSON.parse(raw) as Partial<PaneWeights>;+ return {+ columns: Array.isArray(parsed.columns) ? parsed.columns.map(Number) : [],+ bands: Array.isArray(parsed.bands) ? parsed.bands.map(Number) : [],+ panes:+ parsed.panes && typeof parsed.panes === "object"+ ? (parsed.panes as Record<string, number>)+ : {},+ };+ } catch {+ // Corrupt entry, private mode, storage disabled — an even workspace is a+ // perfectly good workspace, and losing sizes must never cost the panes.+ return evenWeights();+ }+}++function saveWeights(workspaceId: string, weights: PaneWeights): void {+ try {+ window.localStorage.setItem(storageKey(workspaceId), JSON.stringify(weights));+ } catch {+ /* quota / private mode — sizes simply will not survive this session */+ }+}++/** How big the workspace currently is, in px, along each axis. */+export interface WorkspaceExtent {+ width: number;+ height: number;+}++export interface PaneWeightControls {+ weights: PaneWeights;+ /** Replace the weights — used when a split or a close rewrites them. */+ setWeights: (next: PaneWeights | ((current: PaneWeights) => PaneWeights)) => void;+ /** Id of the seam being dragged right now, if any. */+ dragging: string | null;+ /** Begin a drag — wire to a seam's `onPointerDown`. */+ startDrag: (seam: PaneSeam, event: React.PointerEvent) => void;+ /** Move a seam by ``deltaPx`` — the keyboard equivalent of a drag. */+ nudge: (seam: PaneSeam, deltaPx: number) => void;+ /** Give a seam's two neighbours the same size — wire to `onDoubleClick`. */+ even: (seam: PaneSeam) => void;+}++/**+ * Drag state for every seam in one workspace.+ *+ * `extent` is read as a function rather than taken as a value because the+ * workspace can be resized mid-drag (a window animation, the prompt bar opening)+ * and the pixels-to-weight conversion has to use the size the seam is actually+ * being dragged across.+ */+export function usePaneWeights(+ workspaceId: string,+ extent: () => WorkspaceExtent,+): PaneWeightControls {+ const [weights, setWeights] = useState<PaneWeights>(() => loadWeights(workspaceId));+ const [dragging, setDragging] = useState<string | null>(null);++ // Switching workspaces loads that workspace's sizes. Guarded by a ref so the+ // save effect below cannot write the outgoing workspace's weights under the+ // incoming one's key in the render between the two.+ const loadedFor = useRef(workspaceId);+ useEffect(() => {+ loadedFor.current = workspaceId;+ setWeights(loadWeights(workspaceId));+ }, [workspaceId]);++ useEffect(() => {+ if (dragging || loadedFor.current !== workspaceId) return;+ saveWeights(workspaceId, weights);+ }, [weights, dragging, workspaceId]);++ // Drag anchors — refs so the move handler never reads a stale closure. The+ // drag works from the weights it STARTED with, so a slow pointer cannot+ // accumulate rounding drift over a hundred frames.+ const active = useRef<{+ seam: PaneSeam;+ point: number;+ from: PaneWeights;+ } | null>(null);++ const weightsRef = useRef(weights);+ weightsRef.current = weights;++ const extentRef = useRef(extent);+ extentRef.current = extent;++ const startDrag = useCallback((seam: PaneSeam, event: React.PointerEvent) => {+ event.preventDefault();+ active.current = {+ seam,+ point: seam.orientation === "vertical" ? event.clientX : event.clientY,+ from: weightsRef.current,+ };+ setDragging(seam.id);+ }, []);++ useEffect(() => {+ if (!dragging) return;++ const axisPx = (seam: PaneSeam) => {+ const size = extentRef.current();+ return seam.orientation === "vertical" ? size.width : size.height;+ };++ const onMove = (event: PointerEvent) => {+ const drag = active.current;+ if (!drag) return;+ const now = drag.seam.orientation === "vertical" ? event.clientX : event.clientY;+ setWeights(dragSeam(drag.from, drag.seam, now - drag.point, axisPx(drag.seam)));+ };+ const onUp = () => {+ active.current = null;+ setDragging(null);+ };++ window.addEventListener("pointermove", onMove);+ window.addEventListener("pointerup", onUp);+ // Lock the cursor and suppress text selection for the whole drag, so the+ // pointer can wander off the 6px grip without the drag looking broken.+ const previousCursor = document.body.style.cursor;+ const previousSelect = document.body.style.userSelect;+ document.body.style.cursor =+ active.current?.seam.orientation === "vertical" ? "col-resize" : "row-resize";+ document.body.style.userSelect = "none";++ return () => {+ window.removeEventListener("pointermove", onMove);+ window.removeEventListener("pointerup", onUp);+ document.body.style.cursor = previousCursor;+ document.body.style.userSelect = previousSelect;+ };+ }, [dragging]);++ const nudge = useCallback((seam: PaneSeam, deltaPx: number) => {+ const size = extentRef.current();+ const axis = seam.orientation === "vertical" ? size.width : size.height;+ setWeights((current) => dragSeam(current, seam, deltaPx, axis));+ }, []);++ const even = useCallback((seam: PaneSeam) => {+ setWeights((current) => evenSeam(current, seam));+ }, []);++ return { weights, setWeights, dragging, startDrag, nudge, even };+}++export { KEY_STEP_PX };diff --git a/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx b/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsxindex 9ed129e9d2..9a85ffb7c5 100644--- a/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx+++ b/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx@@ -33,6 +33,20 @@ export interface PaneResizerProps {active: boolean;/** Hover tooltip. Also used as the accessible name. */title: string;+ /**+ * Where to put the seam, for layouts that place it rather than flow it.+ *+ * A splitter between two flex children needs nothing here — it sits in the+ * flow between them. A tiled workspace has no such flow: its panes are+ * positioned by fraction, so its seams are too, and they arrive as absolute+ * coordinates. The look and the behaviour stay in this one component either+ * way, which is the whole reason it exists.+ */+ style?: React.CSSProperties;+ /** Extra classes for the same reason as `style`. */+ className?: string;+ /** Overrides the default test id, for screens that render several seams. */+ testId?: string;}/** How far one arrow-key press moves the seam. */@@ -47,6 +61,9 @@ export function PaneResizer({onNudge,active,title,+ style,+ className,+ testId,}: PaneResizerProps) {const vertical = orientation === "vertical";@@ -71,15 +88,17 @@ export function PaneResizer({aria-label={title}title={title}tabIndex={0}- data-testid={`pane-resizer-${orientation}`}+ data-testid={testId ?? `pane-resizer-${orientation}`}onPointerDown={onPointerDown}onDoubleClick={onDoubleClick}onKeyDown={onKeyDown}+ style={style}className={cn("group relative z-10 flex shrink-0 touch-none select-none outline-none",vertical? "w-1.5 cursor-col-resize items-stretch": "h-1.5 cursor-row-resize justify-stretch",+ className,)}>{/* The visible line — it replaces the border it sits on top of. */}