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.

feat(ide): choose where a new agent pane opens

rubenluetke10-beepba79dfe9b7e7
diff --git a/jarvis/agentic_ide/layout_tree.py b/jarvis/agentic_ide/layout_tree.py
index 11ec0a7680..afd5ffdcef 100644
--- a/jarvis/agentic_ide/layout_tree.py
+++ b/jarvis/agentic_ide/layout_tree.py
@@ -310,24 +310,26 @@ def split_pane(
root: LayoutNode | None,
anchor: str | None,
added: str,
- direction: Literal["right", "down"],
+ direction: Literal["right", "down", "left", "up", "above", "below"] = "right",
) -> LayoutNode:
"""The tree after ``added`` was split off ``anchor``.
- ``"right"`` puts the new pane beside the anchor, ``"down"`` beneath it —
- and in both cases the pair shares the room the anchor had, because that is
- what splitting A pane means. Nothing outside the anchor's rectangle moves.
+ ``"right"`` or ``"left"`` puts the new pane beside the anchor, ``"down"``
+ or ``"up"`` / ``"above"`` beneath or above it — and in each case the pair
+ shares the room the anchor had, because that is what splitting A pane means.
+ Nothing outside the anchor's rectangle moves.
Without an anchor (an empty tree, or a caller that named none) the pane
joins the ROOT as a new full-height column on the far right — the shape
"open one more terminal" has always produced, and the only honest reading
of a request that named no pane to split.
"""
- grown: Direction = "row" if direction == "right" else "column"
+ grown: Direction = "row" if direction in ("right", "left") else "column"
+ after = direction in ("right", "down", "below")
if root is None:
return Leaf(pane=added)
if anchor is not None:
- rewritten, found = _insert_beside(root, anchor, added, grown, after=True)
+ rewritten, found = _insert_beside(root, anchor, added, grown, after=after)
if found:
return _rows_outermost(normalize(rewritten))
return append_pane(root, added)
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index e8cd41e890..5b3fca3d38 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -4270,8 +4270,8 @@ class Registry:
raise SessionError(
f"This workspace already has the maximum of {MAX_TERMINALS} terminals."
)
- if direction not in ("right", "down"):
- raise SessionError("Direction must be 'right' or 'down'.")
+ if direction not in ("right", "down", "left", "up", "above", "below"):
+ raise SessionError("Direction must be 'right', 'down', 'left', or 'up'.")
base = session.find(anchor) if anchor else None
if anchor and base is None:
@@ -4365,7 +4365,7 @@ class Registry:
session.layout,
base.key,
term.key,
- "right" if direction == "right" else "down",
+ direction,
)
else:
session.layout = layout_tree.append_pane(session.layout, term.key)
diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.py
index 3627c3b5f6..718e8d5640 100644
--- a/jarvis/ui/web/agentic_ide_routes.py
+++ b/jarvis/ui/web/agentic_ide_routes.py
@@ -284,8 +284,9 @@ class AddTerminalRequest(BaseModel):
direction: str = Field(
default="right",
description=(
- "'right' opens a new column beside the anchor, 'down' splits the "
- "anchor's own column and stacks the new pane under it."
+ "'right' opens a new pane beside the anchor, 'down' splits the "
+ "anchor's own column under it, 'left' places it to the left, and "
+ "'up' / 'above' places it above the anchor."
),
)
account: str | None = Field(
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 2e1007e68f..5b7c71bd1d 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -374,7 +374,7 @@ function documentHidden(): boolean {
*/
export type { SplitAgentChoice };
-export type SplitDirection = "right" | "down";
+export type SplitDirection = "right" | "down" | "left" | "above";
/**
* Where a pane's recap came from, kept together rather than as five more props.
@@ -2313,7 +2313,7 @@ export function AgenticTerminal({
onArrangeStart={onArrangeStart}
onActivate={() => { onFocus?.(); takeOwnershipRef.current?.(); }}
onToggleMaximize={onToggleMaximize}
- onAdd={onSplit ? () => onSplit("right") : undefined}
+ onAdd={onSplit ? (direction) => onSplit(direction) : undefined}
onClose={onClose}
onRename={onRename}
onOpenConversation={() => setHistoryOpen(true)}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsx
index 2a6ab93db4..fade22180a 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsx
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { AgenticTerminal } from "./AgenticTerminal";
import { AgentMark } from "./AgentMark";
+import type { PaneSplitDirection } from "./WorkspaceTerminalHeader";
import type { SessionState, TerminalState } from "@/lib/agenticIdeApi";
import { moveTerminal, renameTerminal, type PaneMovePosition } from "@/lib/agenticIdeApi";
import { useThemeValue } from "@/hooks/useTheme";
@@ -16,7 +17,8 @@ const idOf = (terminal: TerminalState) => terminal.history_id ?? terminal.key;
interface Props {
session: SessionState;
onChanged: (session: SessionState) => void;
- onAdd: () => void;
+ /** Open the agent picker; with an anchor, the new pane splits off that pane. */
+ onAdd: (anchor?: string, direction?: PaneSplitDirection) => void;
onClose: (terminal: TerminalState) => void;
onSelect: (name: string) => void;
selected: string;
@@ -224,7 +226,7 @@ export function WorkspaceTerminalGrid({ session, onChanged, onAdd, onClose, onSe
onClose={() => onClose(terminal)} onAttachError={(message) => pushToast("error", message)}
onRename={(name) => rename(terminal, name)}
restartToken={restarts[id] ?? 0} onRestart={() => setRestarts((current) => ({ ...current, [id]: (current[id] ?? 0) + 1 }))}
- splitDisabled={tiles.length >= 8} onSplit={() => onAdd()} />
+ splitDisabled={tiles.length >= 8} onSplit={(direction) => onAdd(terminal.name, direction)} />
{drag?.target?.id === id && <div aria-hidden="true" data-testid="dock-preview" data-position={drag.target.position}
className={cn("pointer-events-none absolute z-20 flex items-center justify-center rounded-xl border-2 p-2", drag.target.allowed ? "border-ring/70 bg-accent/[0.15]" : "border-destructive bg-background/80",
drag.target.position === "left" ? "inset-y-1 left-1 w-1/2" : drag.target.position === "right" ? "inset-y-1 right-1 w-1/2" : drag.target.position === "above" ? "inset-x-1 top-1 h-1/2" : drag.target.position === "below" ? "inset-x-1 bottom-1 h-1/2" : "inset-1")}>
diff --git a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.test.tsx
index b04fa46fc6..f2fb4be53c 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.test.tsx
@@ -62,6 +62,32 @@ describe("compact workspace terminal header", () => {
expect(document.activeElement).toBe(title);
});
+ it("opens the pane menu on right-click with split, maximize and close actions", () => {
+ const add = vi.fn(), maximize = vi.fn(), close = vi.fn(), activate = vi.fn();
+ render(<WorkspaceTerminalHeader {...BASE} onAdd={add} onToggleMaximize={maximize} onClose={close} onActivate={activate} />);
+ const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: 40, clientY: 30 });
+ fireEvent(screen.getByText("Dana"), event);
+ expect(event.defaultPrevented).toBe(true);
+ expect(activate).toHaveBeenCalled();
+ const menu = screen.getByRole("menu", { name: "Actions for Dana" });
+ expect(within(menu).getAllByRole("menuitem").map((item) => item.textContent)).toEqual(expect.arrayContaining(
+ ["Split right…", "Split down…", "Split left…", "Split up…", "Maximize", "Close pane"]));
+ fireEvent.click(within(menu).getByRole("menuitem", { name: "Split left…" }));
+ expect(add).toHaveBeenCalledWith("left");
+ fireEvent(screen.getByText("Dana"), new MouseEvent("contextmenu", { bubbles: true, cancelable: true }));
+ fireEvent.click(screen.getByRole("menuitem", { name: "Split up…" }));
+ expect(add).toHaveBeenLastCalledWith("above");
+ fireEvent(screen.getByText("Dana"), new MouseEvent("contextmenu", { bubbles: true, cancelable: true }));
+ fireEvent.click(screen.getByRole("menuitem", { name: "Close pane" }));
+ expect(close).toHaveBeenCalledTimes(1);
+ });
+
+ it("hides split actions once the workspace is full", () => {
+ render(<WorkspaceTerminalHeader {...BASE} addDisabled onAdd={vi.fn()} />);
+ fireEvent(screen.getByText("Dana"), new MouseEvent("contextmenu", { bubbles: true, cancelable: true }));
+ expect(screen.queryByRole("menuitem", { name: "Split right…" })).toBeNull();
+ });
+
it("keeps menu focus navigable and restores focus on Escape", () => {
render(<WorkspaceTerminalHeader {...BASE} onRename={async () => true} onOpenConversation={() => {}} />);
const more = screen.getByRole("button", { name: "More actions for Dana" });
diff --git a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.tsx b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.tsx
index e04b91938f..26dbcb52b9 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalHeader.tsx
@@ -1,10 +1,13 @@
-import { useEffect, useId, useRef, useState, type CSSProperties, type PointerEvent } from "react";
+import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentType, type CSSProperties, type MouseEvent, type PointerEvent, type SVGProps } from "react";
import { createPortal } from "react-dom";
import { Check, Maximize2, Minimize2, MoreHorizontal, Plus, X } from "lucide-react";
import { AgentMark } from "./AgentMark";
import { PromptHistoryButton } from "./PromptHistoryButton";
+import { SplitAboveIcon, SplitBelowIcon, SplitLeftIcon, SplitRightIcon } from "./splitIcons";
import { PANE_BRAND, PANE_CHROME, themeFor, type PaneEdgeState, type TerminalAppearance } from "./terminalThemes";
+export type PaneSplitDirection = "right" | "down" | "left" | "above";
+
interface Props {
name: string;
workspaceId?: string;
@@ -20,7 +23,7 @@ interface Props {
onArrangeStart?: (event: PointerEvent) => void;
onActivate?: () => void;
onToggleMaximize?: () => void;
- onAdd?: () => void;
+ onAdd?: (direction: PaneSplitDirection) => void;
onClose?: () => void;
onRename?: (name: string) => Promise<boolean>;
onOpenConversation?: () => void;
@@ -28,6 +31,16 @@ interface Props {
onRestart?: () => void;
}
+type MenuIcon = ComponentType<SVGProps<SVGSVGElement>>;
+interface MenuItem { label: string; run: () => void; Icon?: MenuIcon; separated?: boolean }
+
+const SPLIT_ITEMS: { direction: PaneSplitDirection; label: string; Icon: MenuIcon }[] = [
+ { direction: "right", label: "Split right", Icon: SplitRightIcon },
+ { direction: "down", label: "Split down", Icon: SplitBelowIcon },
+ { direction: "left", label: "Split left", Icon: SplitLeftIcon },
+ { direction: "above", label: "Split up", Icon: SplitAboveIcon },
+];
+
const ACTION_CLASS = "flex h-7 w-7 shrink-0 items-center justify-center rounded text-[color:var(--pane-ink-muted)] hover:bg-[color:var(--pane-chip)] hover:text-[color:var(--pane-ink)] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[color:var(--pane-ink)] disabled:opacity-35";
/** Quiet workspace chrome; terminal rendering and connection state stay in AgenticTerminal. */
@@ -73,13 +86,28 @@ export function WorkspaceTerminalHeader({
};
}, [menuOpen]);
+ // Keep the opened menu inside the window once its real height is known.
+ useLayoutEffect(() => {
+ const menu = menuRef.current;
+ if (!menuPosition || !menu) return;
+ const top = Math.max(8, Math.min(menuPosition.top, window.innerHeight - menu.offsetHeight - 8));
+ const left = Math.max(8, Math.min(menuPosition.left, window.innerWidth - menu.offsetWidth - 8));
+ if (top !== menuPosition.top || left !== menuPosition.left) setMenuPosition({ left, top });
+ }, [menuPosition]);
+
const toggleMenu = () => {
const rect = moreRef.current?.getBoundingClientRect();
if (!rect) return;
- setMenuPosition((current) => current ? null : {
- left: Math.max(8, Math.min(rect.right - 200, window.innerWidth - 208)),
- top: Math.max(8, Math.min(rect.bottom + 4, window.innerHeight - 184)),
- });
+ setMenuPosition((current) => current ? null : { left: rect.right - 200, top: rect.bottom + 4 });
+ };
+ // Right-clicking the title bar opens the same menu at the cursor. Stopped
+ // here so the app-wide Cut/Copy/Paste menu does not open on top of it.
+ const openMenuAt = (event: MouseEvent) => {
+ if (event.shiftKey || draft !== null) return;
+ event.preventDefault();
+ event.stopPropagation();
+ onActivate?.();
+ setMenuPosition({ left: event.clientX, top: event.clientY });
};
const choose = (action: () => void) => { setMenuPosition(null); action(); };
const commitRename = async () => {
@@ -96,6 +124,7 @@ export function WorkspaceTerminalHeader({
<header data-testid={`workspace-terminal-header-${name}`}
className="relative flex h-9 min-h-9 shrink-0 select-none items-center gap-1 border-b pl-2.5 pr-1"
style={{ ...variables, borderColor: chrome.border, background: chrome.shell, touchAction: onArrangeStart ? "none" : undefined }}
+ onContextMenu={openMenuAt}
onPointerDown={(event) => {
if (event.button !== 0 || (event.target as HTMLElement).closest("[data-header-control]")) return;
setMenuPosition(null);
@@ -134,7 +163,7 @@ export function WorkspaceTerminalHeader({
<button type="button" aria-label={`${maximized ? "Restore" : "Maximize"} ${name}`} disabled={!onToggleMaximize}
onClick={onToggleMaximize} className={ACTION_CLASS}>{maximized ? <Minimize2 className="h-3.5 w-3.5" /> : <Maximize2 className="h-3.5 w-3.5" />}</button>
<button type="button" aria-label={`Add agent beside ${name}`} disabled={addDisabled || !onAdd}
- onClick={onAdd} className={ACTION_CLASS}><Plus className="h-4 w-4" /></button>
+ onClick={() => onAdd?.("right")} className={ACTION_CLASS}><Plus className="h-4 w-4" /></button>
<button type="button" aria-label={`Close ${name}`} disabled={!onClose} onClick={onClose} className={ACTION_CLASS}><X className="h-4 w-4" /></button>
</div>
</header>
@@ -156,17 +185,27 @@ export function WorkspaceTerminalHeader({
const index = event.key === "Home" ? 0 : event.key === "End" ? items.length - 1 : (at + (event.key === "ArrowDown" ? 1 : -1) + items.length) % items.length;
items[index]?.focus();
}}>
- {[
+ {([
onRename && { label: "Rename", run: () => { setDraft(name); setRenameError(""); } },
+ ...(onAdd && !addDisabled ? SPLIT_ITEMS.map((item, index) => ({
+ label: `${item.label}…`, Icon: item.Icon, separated: index === 0, run: () => onAdd(item.direction),
+ })) : []),
+ onToggleMaximize && { label: maximized ? "Restore size" : "Maximize", separated: true,
+ Icon: maximized ? Minimize2 : Maximize2, run: onToggleMaximize },
onOpenConversation && { label: "Conversation history", run: onOpenConversation },
onOpenChat && { label: "Open as chat", run: onOpenChat },
stopped && onRestart && { label: "Restart agent", run: onRestart },
- ].filter((item): item is { label: string; run: () => void } => Boolean(item)).map((item) =>
+ ] as (MenuItem | false | undefined | null)[]).filter((item): item is MenuItem => Boolean(item)).map((item) =>
<button type="button" role="menuitem" key={item.label} onClick={() => choose(item.run)}
- className="block w-full rounded px-2.5 py-2 text-left text-xs hover:bg-[color:var(--pane-chip)] focus:bg-[color:var(--pane-chip)] focus:outline-none">{item.label}</button>,
+ className={`flex w-full items-center gap-2 rounded px-2.5 py-2 text-left text-xs hover:bg-[color:var(--pane-chip)] focus:bg-[color:var(--pane-chip)] focus:outline-none ${item.separated ? "mt-1 border-t border-[color:var(--pane-chip)] pt-2" : ""}`}>
+ {item.Icon && <item.Icon className="h-3.5 w-3.5 shrink-0" aria-hidden="true" />}{item.label}
+ </button>,
)}
<PromptHistoryButton terminal={name} workspaceId={workspaceId} count={promptCount} triggerMode="menu-item"
onOpen={() => setMenuPosition(null)} restoreFocus={() => moreRef.current?.focus()} />
+ {onClose && <button type="button" role="menuitem" onClick={() => choose(onClose)}
+ className="mt-1 flex w-full items-center gap-2 rounded border-t border-[color:var(--pane-chip)] px-2.5 py-2 pt-2 text-left text-xs hover:bg-[color:var(--pane-chip)] focus:bg-[color:var(--pane-chip)] focus:outline-none">
+ <X className="h-3.5 w-3.5 shrink-0" aria-hidden="true" />Close pane</button>}
</div>, document.body)}
</>;
}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/splitIcons.tsx b/jarvis/ui/web/frontend/src/components/agentic/splitIcons.tsx
index 3400992e22..21310b5348 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/splitIcons.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/splitIcons.tsx
@@ -52,3 +52,42 @@ export function SplitBelowIcon(props: SVGProps<SVGSVGElement>) {
</svg>
);
}
+
+/** Divided pane; the arrow in the left half points where the new pane opens. */
+export function SplitLeftIcon(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ viewBox="0 0 24 24"
+ width="24"
+ height="24"
+ aria-hidden="true"
+ {...strokeProps}
+ {...props}
+ >
+ <rect x="3" y="4" width="18" height="16" rx="2" />
+ <path d="M14 4v16" />
+ <path d="M11 12H6" />
+ <path d="m8.5 9.5-2.5 2.5 2.5 2.5" />
+ </svg>
+ );
+}
+
+/** Divided pane; the arrow in the upper half points where the new pane opens. */
+export function SplitAboveIcon(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ viewBox="0 0 24 24"
+ width="24"
+ height="24"
+ aria-hidden="true"
+ {...strokeProps}
+ {...props}
+ >
+ <rect x="4" y="3" width="16" height="18" rx="2" />
+ <path d="M4 14h16" />
+ <path d="M12 11V6" />
+ <path d="m9.5 8.5 2.5-2.5 2.5 2.5" />
+ </svg>
+ );
+}
+
diff --git a/jarvis/ui/web/frontend/src/components/agentic/workspaceDocking.ts b/jarvis/ui/web/frontend/src/components/agentic/workspaceDocking.ts
index ff1fc61458..ea6809f9e3 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/workspaceDocking.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/workspaceDocking.ts
@@ -68,6 +68,43 @@ export function previewDock(tree: LayoutNode, source: string, target: string, po
return insert(remove(tree)!);
}
+/** Preview splitting a pane in a specific direction with a new terminal. */
+export function previewSplit(
+ tree: LayoutNode | null,
+ targetKey: string,
+ addedKey: string,
+ direction: "right" | "down" | "left" | "above"
+): LayoutNode {
+ if (!tree) return { pane: addedKey };
+ const insert = (node: LayoutNode): LayoutNode => {
+ if (isSplit(node)) return { ...node, children: node.children.map(insert) };
+ if (node.pane !== targetKey) return node;
+ const pair = [{ pane: addedKey }, node];
+ if (direction === "right" || direction === "down") pair.reverse();
+ return {
+ direction: direction === "left" || direction === "right" ? "row" : "column",
+ children: pair,
+ weights: [1, 1],
+ };
+ };
+ return insert(tree);
+}
+
+/** Check if splitting anchor in direction keeps the layout within 4 columns x 2 rows. */
+export function canSplitFit(
+ tree: LayoutNode | null | undefined,
+ terminals: readonly Pick<TerminalState, "key">[],
+ anchorKey: string | undefined,
+ direction: "right" | "down" | "left" | "above"
+): boolean {
+ if (terminals.length >= 8) return false;
+ if (terminals.length === 0 || !anchorKey) return true;
+ const current = workspaceLayout(tree, terminals);
+ if (!current) return true;
+ const preview = previewSplit(current, anchorKey, "__preview__", direction);
+ return fitsWorkspace(preview);
+}
+
/** The nearest outer quarter is a docking edge; the middle swaps whole panes. */
export function dockPosition(x: number, y: number, rect: Pick<DOMRect, "left" | "top" | "width" | "height">): PaneMovePosition {
const horizontal = (x - rect.left) / rect.width, vertical = (y - rect.top) / rect.height;
diff --git a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
index 260b5d1896..7c7b917998 100644
--- a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
+++ b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
@@ -1380,7 +1380,7 @@ export async function forgetResumeOffer(): Promise<void> {
export async function addTerminal(payload: {
workspace_id?: string;
anchor?: string;
- direction?: "right" | "down";
+ direction?: "right" | "down" | "left" | "above" | "up" | "below";
agent?: string;
name?: string;
/** Subscription for the new pane; omitted inherits the anchor's. */
diff --git a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx
index f295f2a2f4..699d1e5de7 100644
--- a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx
@@ -1,4 +1,4 @@
-import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { AgenticIdeView } from "./AgenticIdeView";
import { useIdeProjectsStore } from "@/store/ideProjects";
@@ -120,6 +120,26 @@ describe("Agentic IDE project flow", () => {
await waitFor(() => expect(api.addTerminal).toHaveBeenCalledWith({ workspace_id: "w1", agent: "codex", direction: "down" }));
});
+ it("lets the user choose which pane to split and in which direction", async () => {
+ const terminals = [{ key: "t1", history_id: "id1", name: "T1", display_name: "Codex" }, { key: "t2", history_id: "id2", name: "T2", display_name: "Codex" }];
+ const session = { id: "w1", project_id: "p1", folder: "/code/app", name: "App work", created_at: 0,
+ focus_mode: false, project: { name: "App" }, terminals, layout: balancedLayout(["t1", "t2"]) };
+ api.fetchIdeState.mockResolvedValue({ ...emptyState, active: true, active_id: "w1", session });
+ api.fetchIdeProjects.mockResolvedValue({ projects: [project], active_workspace_id: "w1" });
+ api.addTerminal.mockResolvedValue(session);
+ render(<AgenticIdeView />);
+ fireEvent.click(await screen.findByRole("button", { name: "Pane add" }));
+ const dialog = screen.getByRole("dialog", { name: "Add coding agent" });
+ // Still the automatic grid, so that is what the dialog offers first.
+ expect((within(dialog).getByRole("combobox", { name: "Split next to" }) as HTMLSelectElement).value).toBe("");
+ expect(within(dialog).queryByRole("radio", { name: "Split left" })).toBeNull();
+ fireEvent.change(within(dialog).getByRole("combobox", { name: "Split next to" }), { target: { value: "T2" } });
+ fireEvent.click(within(dialog).getByRole("radio", { name: "Split left" }));
+ fireEvent.click(within(dialog).getByRole("button", { name: "Codex" }));
+ await waitFor(() => expect(api.addTerminal).toHaveBeenCalledWith({ workspace_id: "w1", agent: "codex", anchor: "T2", direction: "left" }));
+ expect(api.reorderIdeTerminals).not.toHaveBeenCalled();
+ });
+
it("exposes compact workspace rename and close actions", async () => {
const session = { id: "w1", project_id: "p1", folder: "/code/app", name: "App work", created_at: 0,
focus_mode: false, project: { name: "App" }, terminals: [] };
diff --git a/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx b/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx
index 28bd2f0e78..1f9041a2f4 100644
--- a/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx
+++ b/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx
@@ -5,8 +5,11 @@ import { VoiceBubble, storedVoiceBubbleOpen, storeVoiceBubbleOpen } from "@/comp
import { WorkspaceTerminalGrid } from "@/components/agentic/WorkspaceTerminalGrid";
import { WorkspaceAgentSetup } from "@/components/agentic/WorkspaceAgentSetup";
import { WorkspaceOptionsDialog } from "@/components/agentic/WorkspaceOptionsDialog";
-import { fitsWorkspace, isBalancedWorkspace } from "@/components/agentic/workspaceDocking";
+import { fitsWorkspace, isBalancedWorkspace, canSplitFit } from "@/components/agentic/workspaceDocking";
import { AgentMark } from "@/components/agentic/AgentMark";
+import { SplitRightIcon, SplitBelowIcon, SplitLeftIcon, SplitAboveIcon } from "@/components/agentic/splitIcons";
+import type { PaneSplitDirection } from "@/components/agentic/WorkspaceTerminalHeader";
+import { cn } from "@/lib/utils";
import { useEventStore } from "@/store/events";
import { useIdeChatStore } from "@/store/ideChat";
import { useIdeProjectsStore } from "@/store/ideProjects";
@@ -19,6 +22,28 @@ import {
const FONT_KEY = "jarvis.agenticIde.terminalFontSize";
const APPEARANCE_KEY = "jarvis.agenticIde.terminalAppearance";
+const SPLIT_DIRECTION_KEY = "jarvis.agenticIde.splitDirection";
+
+const SPLIT_DIRECTIONS: { id: PaneSplitDirection; label: string; hint: string; Icon: typeof SplitRightIcon }[] = [
+ { id: "right", label: "Right", hint: "Open the new agent to the right of the pane", Icon: SplitRightIcon },
+ { id: "down", label: "Down", hint: "Open the new agent below the pane", Icon: SplitBelowIcon },
+ { id: "left", label: "Left", hint: "Open the new agent to the left of the pane", Icon: SplitLeftIcon },
+ { id: "above", label: "Up", hint: "Open the new agent above the pane", Icon: SplitAboveIcon },
+];
+
+const isSplitDirection = (value: unknown): value is PaneSplitDirection =>
+ SPLIT_DIRECTIONS.some((item) => item.id === value);
+
+/** The direction last picked in the dialog; storage may be blocked, so never throw. */
+function storedSplitDirection(): PaneSplitDirection {
+ try {
+ const stored = localStorage.getItem(SPLIT_DIRECTION_KEY);
+ return isSplitDirection(stored) ? stored : "right";
+ } catch { return "right"; }
+}
+function storeSplitDirection(direction: PaneSplitDirection): void {
+ try { localStorage.setItem(SPLIT_DIRECTION_KEY, direction); } catch { /* a convenience only */ }
+}
export interface AgenticIdeViewProps { onScreen?: boolean }
@@ -43,6 +68,10 @@ export function AgenticIdeView({ onScreen = true }: AgenticIdeViewProps) {
const [workspaceAgents, setWorkspaceAgents] = useState<string[]>([]);
const [selected, setSelected] = useState("");
const [agentPicker, setAgentPicker] = useState<{ id: string; name: string } | null>(null);
+ // Where the next agent opens: split off `splitAnchor` (a pane call-sign) in
+ // `splitDirection`, or — with no anchor — the automatic even grid.
+ const [splitDirection, setSplitDirection] = useState<PaneSplitDirection>(storedSplitDirection);
+ const [splitAnchor, setSplitAnchor] = useState("");
const [optionsOpen, setOptionsOpen] = useState(false);
const [renameOpen, setRenameOpen] = useState(false);
const [renameValue, setRenameValue] = useState("");
@@ -237,12 +266,23 @@ export function AgenticIdeView({ onScreen = true }: AgenticIdeViewProps) {
setWorkspaceProject(null);
});
- const addAgent = (agentName: string, workspaceId: string) => void run(async () => {
+ const addAgent = (
+ agentName: string,
+ workspaceId: string,
+ anchorName?: string,
+ direction: PaneSplitDirection = "down",
+ ) => void run(async () => {
const wasBalanced = session?.id === workspaceId && isBalancedWorkspace(session.layout, session.terminals);
- let next = await addTerminal({ workspace_id: workspaceId, agent: agentName, direction: "down" });
- // Grow an automatic grid evenly; keep a custom arrangement until another
- // pane would exceed the workspace bounds.
- if (next.id === workspaceId && next.terminals.length > 1 && (wasBalanced || (next.layout && !fitsWorkspace(next.layout)))) {
+ const hasExplicitAnchor = Boolean(anchorName);
+ let next = await addTerminal({
+ workspace_id: workspaceId,
+ agent: agentName,
+ anchor: anchorName || undefined,
+ direction,
+ });
+ // Grow an automatic grid evenly when adding without an explicit anchor;
+ // keep a custom arrangement until another pane would exceed the workspace bounds.
+ if (next.id === workspaceId && next.terminals.length > 1 && ((wasBalanced && !hasExplicitAnchor) || (next.layout && !fitsWorkspace(next.layout)))) {
const balanced = await reorderIdeTerminals(next.id, next.terminals.map((terminal) => terminal.history_id ?? terminal.key));
next = balanced.session ?? next;
}
@@ -261,7 +301,26 @@ export function AgenticIdeView({ onScreen = true }: AgenticIdeViewProps) {
const next = await reorderIdeTerminals(session.id, session.terminals.map((terminal) => terminal.history_id ?? terminal.key));
setState((current) => current?.session?.id === next.session?.id ? next : current);
});
- const openAgentPicker = () => { if (session) setAgentPicker({ id: session.id, name: session.name ?? session.project.name }); };
+ // A pane's own menu names the pane and direction. The workspace "+" names
+ // neither (and may pass a click event): an automatic even grid then stays
+ // automatic, a hand-arranged one splits the selected pane in the last
+ // direction the user picked. The dialog shows both and lets the user change it.
+ const openAgentPicker = useCallback((anchor?: unknown, direction?: PaneSplitDirection) => {
+ if (!session) return;
+ const named = typeof anchor === "string" ? anchor.trim() : "";
+ const pane = named || (isBalancedWorkspace(session.layout, session.terminals) ? "" : selected);
+ setSplitAnchor(session.terminals.some((terminal) => terminal.name === pane) ? pane : "");
+ setSplitDirection(isSplitDirection(direction) ? direction : storedSplitDirection());
+ setAgentPicker({ id: session.id, name: session.name ?? session.project.name });
+ }, [session, selected]);
+ // The chosen direction when it fits; otherwise the first that does; null
+ // when the anchor has no room at all (the agent then joins the even grid).
+ const pickerAnchorKey = session?.terminals.find((terminal) => terminal.name === splitAnchor)?.key;
+ const directionFits = (direction: PaneSplitDirection) =>
+ Boolean(session && pickerAnchorKey && canSplitFit(session.layout, session.terminals, pickerAnchorKey, direction));
+ const effectiveDirection = !pickerAnchorKey ? null
+ : directionFits(splitDirection) ? splitDirection
+ : SPLIT_DIRECTIONS.find((item) => directionFits(item.id))?.id ?? null;
const closeVoice = () => { setVoiceOpen(false); storeVoiceBubbleOpen(false); };
const jumpToPane = (workspaceId: string, pane: string) => void run(async () => {
if (workspaceId !== session?.id) setState(await activateWorkspace(workspaceId));
@@ -316,9 +375,41 @@ export function AgenticIdeView({ onScreen = true }: AgenticIdeViewProps) {
<div><h2 className="text-base font-semibold">Add coding agent</h2><p className="mt-1 text-xs text-muted-foreground">{agentPicker.name}</p></div>
<button type="button" aria-label="Close" onClick={() => setAgentPicker(null)} className="rounded-md p-1.5 hover:bg-muted"><X className="h-4 w-4" /></button>
</div>
+
+ {session && session.terminals.length > 0 && (() => {
+ const anchorTerminal = session.terminals.find((terminal) => terminal.name === splitAnchor);
+ return <div className="mb-4 space-y-2.5 rounded-xl border border-border bg-muted/40 p-3">
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ <span className="text-xs font-medium text-foreground">Where should it open?</span>
+ <label className="flex items-center gap-1.5 text-xs text-muted-foreground">
+ Next to
+ <select aria-label="Split next to" value={splitAnchor} disabled={busy} onChange={(event) => setSplitAnchor(event.target.value)}
+ className="h-7 rounded-md border border-input bg-background px-2 text-xs font-medium text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring">
+ {session.terminals.map((terminal) => <option key={terminal.name} value={terminal.name}>{terminal.name} · {terminal.display_name}</option>)}
+ <option value="">Automatic even grid</option>
+ </select>
+ </label>
+ </div>
+ {anchorTerminal ? <div className="grid grid-cols-4 gap-2" role="radiogroup" aria-label="Split direction">
+ {SPLIT_DIRECTIONS.map((item) => {
+ const fits = directionFits(item.id);
+ const checked = effectiveDirection === item.id;
+ return <button key={item.id} type="button" role="radio" aria-checked={checked} aria-label={`Split ${item.label.toLowerCase()}`}
+ disabled={busy || !fits} title={fits ? item.hint : "No room: a workspace holds at most four columns and two rows."}
+ onClick={() => { setSplitDirection(item.id); storeSplitDirection(item.id); }}
+ className={cn("flex flex-col items-center justify-center gap-1.5 rounded-lg border py-2 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-40",
+ checked ? "border-primary bg-primary/10 text-foreground ring-1 ring-primary/40" : "border-border bg-background text-muted-foreground hover:bg-muted hover:text-foreground")}>
+ <item.Icon className="h-4 w-4" /><span>{item.label}</span>
+ </button>;
+ })}
+ </div> : <p className="text-xs text-muted-foreground">The new agent joins the grid and every pane gets an equal share.</p>}
+ {anchorTerminal && !effectiveDirection && <p className="text-xs text-muted-foreground">No room beside {anchorTerminal.name}; the new agent joins the automatic grid instead.</p>}
+ </div>;
+ })()}
+
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
{installed.map((agent) => <button key={agent.name} type="button" disabled={busy}
- onClick={() => { const owner = agentPicker.id; setAgentPicker(null); addAgent(agent.name, owner); }}
+ onClick={() => { const owner = agentPicker.id; setAgentPicker(null); addAgent(agent.name, owner, effectiveDirection ? splitAnchor : undefined, effectiveDirection ?? "down"); }}
className="flex min-h-12 items-center gap-3 rounded-lg border border-border px-3 py-2 text-left text-sm font-medium hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
<AgentMark agent={agent.name} label={agent.display_name} logoUrl={agent.logo_url} variant="plain" />{agent.display_name}
</button>)}
diff --git a/tests/unit/agentic_ide/test_account_spawn.py b/tests/unit/agentic_ide/test_account_spawn.py
index 3568ce7e2d..4e65748c7d 100644
--- a/tests/unit/agentic_ide/test_account_spawn.py
+++ b/tests/unit/agentic_ide/test_account_spawn.py
@@ -20,6 +20,7 @@ from pathlib import Path
import pytest
from jarvis import agent_accounts
+from jarvis.agentic_ide import layout_tree
from jarvis.agentic_ide import session as session_mod
from jarvis.agentic_ide.session import Registry, SessionError
from tests.fakes.fake_pty_manager import FakePtyManager
@@ -154,6 +155,18 @@ async def test_a_split_stays_on_the_account_its_anchor_runs_on(
assert split.account == second.id
+async def test_a_split_can_open_left_of_or_above_its_anchor(
+ registry: Registry, tmp_path: Path
+) -> None:
+ """The pane menu offers all four sides; the new pane lands on the one picked."""
+ await registry.start(str(tmp_path), [{"agent": "claude"}])
+ anchor = registry.session.terminals[0]
+ left = await registry.add_terminal(anchor=anchor.name, direction="left")
+ assert layout_tree.leaves(registry.session.layout) == [left.key, anchor.key]
+ above = await registry.add_terminal(anchor=anchor.name, direction="above")
+ assert layout_tree.leaves(registry.session.layout) == [left.key, above.key, anchor.key]
+
+
async def test_a_split_onto_a_different_cli_does_not_inherit_the_account(
registry: Registry, tmp_path: Path
) -> None:
diff --git a/tests/unit/web/test_agentic_ide_layout_tree.py b/tests/unit/web/test_agentic_ide_layout_tree.py
index f2e7ff1419..428c3d87ae 100644
--- a/tests/unit/web/test_agentic_ide_layout_tree.py
+++ b/tests/unit/web/test_agentic_ide_layout_tree.py
@@ -151,6 +151,33 @@ def test_split_down_in_a_stack_halves_the_anchor_only() -> None:
assert tree.weights == [1.0, 1.0, 2.0]
+def test_split_left_puts_the_new_pane_before_the_anchor() -> None:
+ row = Split(
+ direction="row",
+ children=[Leaf(pane="t1"), Leaf(pane="t2")],
+ weights=[2.0, 2.0],
+ )
+ tree = lt.split_pane(row, "t2", "t3", "left")
+
+ assert isinstance(tree, Split) and tree.direction == "row"
+ assert lt.leaves(tree) == ["t1", "t3", "t2"]
+ assert tree.weights == [2.0, 1.0, 1.0]
+ check_canonical(tree)
+
+
+def test_split_above_puts_the_new_pane_over_the_anchor() -> None:
+ for direction in ("above", "up"):
+ row = lt.wizard_tree(["t1", "t2"], 1) # two panes side by side
+ tree = lt.split_pane(row, "t2", "t3", direction)
+
+ assert lt.leaves(tree) == ["t1", "t3", "t2"]
+ # t1 stays one whole column; t3 sits on top of t2 in the other.
+ column = next(child for child in tree.children if isinstance(child, Split))
+ assert column.direction == "column"
+ assert lt.leaves(column) == ["t3", "t2"]
+ check_canonical(tree)
+
+
def test_split_down_beside_a_neighbour_leaves_the_neighbour_whole() -> None:
row = lt.wizard_tree(["t1", "t2"], 1) # two panes side by side
tree = lt.split_pane(row, "t2", "t3", "down")
@@ -162,6 +189,22 @@ def test_split_down_beside_a_neighbour_leaves_the_neighbour_whole() -> None:
assert lt.leaves(right) == ["t2", "t3"]
+def test_split_left_places_new_pane_before_anchor() -> None:
+ leaf = Leaf(pane="t1")
+ tree = lt.split_pane(leaf, "t1", "t2", "left")
+
+ assert isinstance(tree, Split) and tree.direction == "row"
+ assert lt.leaves(tree) == ["t2", "t1"]
+
+
+def test_split_above_places_new_pane_over_anchor() -> None:
+ leaf = Leaf(pane="t1")
+ tree = lt.split_pane(leaf, "t1", "t2", "above")
+
+ assert isinstance(tree, Split) and tree.direction == "column"
+ assert lt.leaves(tree) == ["t2", "t1"]
+
+
def test_deep_splits_stay_local_at_any_depth() -> None:
tree: lt.LayoutNode | None = lt.wizard_tree(["t1", "t2"], 2)
tree = lt.split_pane(tree, "t1", "t3", "right")