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(agentic-ide): give every pane a scrollbar, hidden until reached for

Ruben Lütke4dd28c752912
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.scrollbar.test.ts b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.scrollbar.test.ts
deleted file mode 100644
index 708276d9a1..0000000000
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.scrollbar.test.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { readFileSync } from "node:fs";
-import { resolve } from "node:path";
-import { describe, expect, it } from "vitest";
-
-const css = readFileSync(resolve(process.cwd(), "src/index.css"), "utf8");
-const component = readFileSync(
- resolve(process.cwd(), "src/components/agentic/AgenticTerminal.tsx"),
- "utf8",
-);
-
-describe("AgenticTerminal scrollbar", () => {
- it("styles the shared xterm viewport with a visible track and interactive thumb", () => {
- const host = ".agentic-terminal-host .xterm-viewport";
-
- expect(component).toContain('className="agentic-terminal-host ');
- expect(css).toContain(`${host} {`);
- expect(css).toContain("scrollbar-gutter: stable;");
- expect(css).toContain(`${host}::-webkit-scrollbar-track`);
- expect(css).toContain(`${host}::-webkit-scrollbar-thumb`);
- expect(css).toContain(`${host}::-webkit-scrollbar-thumb:hover`);
- expect(css).toContain(`${host}::-webkit-scrollbar-thumb:active`);
- });
-});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 6a70ec8202..f26dde429e 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -76,6 +76,7 @@ import { attachTerminalBridge } from "@/lib/editActions";
import { robustPaste } from "@/lib/clipboard";
import { installPasteBridge } from "./terminalPaste";
import { OffscreenBuffer } from "./offscreenBuffer";
+import { PaneScrollbar } from "./PaneScrollbar";
import { openPaneSocket, type PaneSocket } from "./paneSocket";
export type PaneStatus = "connecting" | "live" | "exited" | "error";
@@ -173,6 +174,9 @@ export function AgenticTerminal({
restartToken = 0,
}: AgenticTerminalProps) {
const containerRef = useRef<HTMLDivElement | null>(null);
+ // The padded box around the xterm host. The pane's scrollbar overlays it and
+ // measures hover against it — see ./PaneScrollbar.
+ const scrollRegionRef = useRef<HTMLDivElement | null>(null);
const termRef = useRef<Terminal | null>(null);
const fitRef = useRef<FitAddon | null>(null);
// Lets the font-size effect trigger a REAL resize (xterm + the terminal
@@ -182,6 +186,11 @@ export function AgenticTerminal({
// Mirrored into state purely so the header can show/hide the restart button;
// it transitions a handful of times per pane, never per output chunk.
const [visibleStatus, setVisibleStatus] = useState<PaneStatus>("connecting");
+ // Bumped once per built terminal. The scrollbar subscribes to xterm events,
+ // and the instance behind `termRef` is replaced on every restart — without a
+ // signal it would keep listening to a disposed one.
+ const [termEpoch, setTermEpoch] = useState(0);
+ const getTerminal = useCallback(() => termRef.current, []);
// Latest callbacks/appearance without re-running the connect effect.
const onStatusRef = useRef(onStatus);
const onAttachErrorRef = useRef(onAttachError);
@@ -252,6 +261,7 @@ export function AgenticTerminal({
}
termRef.current = term;
fitRef.current = fit;
+ setTermEpoch((epoch) => epoch + 1);
// Let the app-wide right-click menu reach this terminal. It cannot use the
// browser selection here — the canvas renderer above paints the text, so
// there is no selectable DOM to read — and it must paste through xterm so
@@ -613,12 +623,26 @@ export function AgenticTerminal({
`min-h-0` is equally load-bearing: this is a shrinking flex child, and
xterm's canvas must not become its implicit minimum height.
*/}
- <div className="min-h-0 flex-1 overflow-hidden px-2 pb-1 pt-1">
+ <div
+ ref={scrollRegionRef}
+ className="relative min-h-0 flex-1 overflow-hidden px-2 pb-1 pt-1"
+ >
<div
ref={containerRef}
data-testid={`agentic-terminal-host-${name}`}
className="agentic-terminal-host h-full min-h-0 w-full overflow-hidden"
/>
+ {/* Overlaid rather than laid out, and deliberately not the browser's
+ own bar — see ./PaneScrollbar for why a CSS-only scrollbar could
+ never work in a Claude Code pane. */}
+ <PaneScrollbar
+ name={name}
+ regionRef={scrollRegionRef}
+ hostRef={containerRef}
+ getTerminal={getTerminal}
+ epoch={termEpoch}
+ appearance={appearance}
+ />
</div>
{(dragging || attaching) && (
<div className="pointer-events-none absolute inset-0 flex items-center justify-center bg-background/70 backdrop-blur-[2px]">
diff --git a/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx
new file mode 100644
index 0000000000..df22c4d191
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx
@@ -0,0 +1,180 @@
+import { useCallback, useRef } from "react";
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import type { Terminal } from "@xterm/xterm";
+import { PaneScrollbar } from "./PaneScrollbar";
+
+const REGION = { top: 0, bottom: 300, left: 0, right: 400 };
+
+interface FakeOptions {
+ type?: "normal" | "alternate";
+ length?: number;
+ rows?: number;
+ viewportY?: number;
+ mouseTrackingMode?: string;
+}
+
+function fakeTerminal({
+ type = "normal",
+ length = 1000,
+ rows = 24,
+ viewportY = 0,
+ mouseTrackingMode = "none",
+}: FakeOptions = {}) {
+ const noop = () => ({ dispose() {} });
+ return {
+ rows,
+ modes: { mouseTrackingMode },
+ buffer: {
+ active: { type, length, viewportY, baseY: length - rows },
+ onBufferChange: noop,
+ },
+ onScroll: noop,
+ onRender: noop,
+ onResize: noop,
+ scrollToLine: vi.fn(),
+ scrollLines: vi.fn(),
+ } as unknown as Terminal;
+}
+
+function Harness({ term }: { term: Terminal }) {
+ const regionRef = useRef<HTMLDivElement | null>(null);
+ const hostRef = useRef<HTMLDivElement | null>(null);
+ const getTerminal = useCallback(() => term, [term]);
+ return (
+ <div ref={regionRef} data-testid="region">
+ <div ref={hostRef} className="agentic-terminal-host">
+ <div className="xterm-screen" />
+ </div>
+ <PaneScrollbar
+ name="Dana"
+ regionRef={regionRef}
+ hostRef={hostRef}
+ getTerminal={getTerminal}
+ epoch={1}
+ appearance="dark"
+ />
+ </div>
+ );
+}
+
+/** Move the pointer into the strip along the pane's right edge. */
+function reachForTheBar() {
+ fireEvent.mouseMove(screen.getByTestId("region"), {
+ clientX: REGION.right - 6,
+ clientY: 150,
+ });
+}
+
+describe("PaneScrollbar", () => {
+ beforeEach(() => {
+ // jsdom measures nothing, and both the hover zone and the thumb's size are
+ // pure geometry — so the two measurements the component takes are staged.
+ Object.defineProperty(HTMLElement.prototype, "clientHeight", {
+ configurable: true,
+ value: 300,
+ });
+ HTMLElement.prototype.getBoundingClientRect = () =>
+ ({
+ ...REGION,
+ width: REGION.right - REGION.left,
+ height: REGION.bottom - REGION.top,
+ x: REGION.left,
+ y: REGION.top,
+ toJSON: () => REGION,
+ }) as DOMRect;
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it("stays out of the way until the pointer reaches for it", () => {
+ render(<Harness term={fakeTerminal()} />);
+
+ expect(screen.queryByTestId("pane-scrollbar-Dana")).toBeNull();
+
+ reachForTheBar();
+
+ const bar = screen.getByTestId("pane-scrollbar-Dana");
+ expect(bar.dataset.shown).toBe("true");
+ expect(bar.className).toContain("opacity-100");
+ expect(screen.getByTestId("pane-scrollbar-thumb-Dana")).toBeTruthy();
+ });
+
+ it("fades out again once the pointer leaves the edge", () => {
+ vi.useFakeTimers();
+ try {
+ render(<Harness term={fakeTerminal()} />);
+ reachForTheBar();
+ fireEvent.mouseMove(screen.getByTestId("region"), {
+ clientX: 40,
+ clientY: 150,
+ });
+ act(() => vi.advanceTimersByTime(1000));
+ } finally {
+ vi.useRealTimers();
+ }
+
+ const bar = screen.getByTestId("pane-scrollbar-Dana");
+ expect(bar.dataset.shown).toBe("false");
+ expect(bar.className).toContain("opacity-0");
+ // Invisible AND intangible — a transparent strip that still swallowed
+ // clicks would break selecting text at the pane's right edge.
+ expect(bar.className).toContain("pointer-events-none");
+ });
+
+ it("gives a Claude-Code-style pane a bar the terminal cannot provide", () => {
+ // Alternate screen + mouse tracking: no scrollback in the terminal at all,
+ // which is why the native viewport scrollbar was dead in these panes.
+ render(
+ <Harness
+ term={fakeTerminal({
+ type: "alternate",
+ length: 24,
+ mouseTrackingMode: "any",
+ })}
+ />,
+ );
+
+ reachForTheBar();
+
+ const bar = screen.getByTestId("pane-scrollbar-Dana");
+ expect(bar.dataset.mode).toBe("app");
+ expect(screen.getByTestId("pane-scrollbar-thumb-Dana")).toBeTruthy();
+ });
+
+ it("hands wheel turns over the bar to the CLI that owns the screen", () => {
+ render(
+ <Harness
+ term={fakeTerminal({
+ type: "alternate",
+ length: 24,
+ mouseTrackingMode: "any",
+ })}
+ />,
+ );
+ reachForTheBar();
+
+ const relayed: number[] = [];
+ document
+ .querySelector(".xterm-screen")!
+ .addEventListener("wheel", (event) =>
+ relayed.push((event as WheelEvent).deltaY),
+ );
+
+ fireEvent.wheel(screen.getByTestId("pane-scrollbar-Dana"), { deltaY: 120 });
+
+ expect(relayed).toEqual([1, 1, 1]);
+ });
+
+ it("scrolls the viewport itself when the terminal holds the history", () => {
+ const term = fakeTerminal({ length: 1000 });
+ render(<Harness term={term} />);
+ reachForTheBar();
+
+ fireEvent.wheel(screen.getByTestId("pane-scrollbar-Dana"), { deltaY: -120 });
+
+ expect(term.scrollLines).toHaveBeenCalledWith(-3);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx
new file mode 100644
index 0000000000..67b5bfcc3f
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx
@@ -0,0 +1,360 @@
+/**
+ * A pane's own scrollbar — hidden until you reach for it.
+ *
+ * Replaces the native `.xterm-viewport` bar, for two reasons the CSS version
+ * could not solve:
+ *
+ * 1. **It was always there.** `overflow-y: scroll` draws a permanent track down
+ * the side of every pane, and in a grid of eight terminals that is eight
+ * stripes of furniture nobody asked for. This one appears when the pointer
+ * comes within reach of the pane's right edge, and while you are scrolled
+ * back through history — and is otherwise invisible.
+ * 2. **It only worked for half the CLIs.** Why, and what this does about it,
+ * is in ./paneScroll — in short: Claude Code runs on the alternate screen
+ * with mouse tracking, so the terminal holds no scrollback to drag through
+ * and the wheel belongs to the CLI. That pane gets a grip which relays wheel
+ * notches to Claude Code instead of a thumb that would be lying about a
+ * position it cannot know.
+ *
+ * The bar is an overlay, not a layout box: xterm reserves a gutter on the right
+ * for the scrollbar it thinks it has, and the bar sits in that gutter, so
+ * nothing is drawn underneath it.
+ */
+import {
+ useCallback,
+ useEffect,
+ useLayoutEffect,
+ useRef,
+ useState,
+} from "react";
+import type { Terminal } from "@xterm/xterm";
+import { cn } from "@/lib/utils";
+import type { TerminalAppearance } from "./terminalThemes";
+import {
+ IDLE_STATE,
+ jogNotches,
+ lineForThumbTop,
+ readScrollState,
+ relayWheelNotch,
+ thumbGeometry,
+ type PaneScrollState,
+} from "./paneScroll";
+
+/** How close to the pane's right edge the pointer reveals the bar. */
+const HOT_ZONE_PX = 28;
+
+/** Grace period before a bar the pointer left disappears again. */
+const HIDE_DELAY_MS = 260;
+
+/** How long the bar stays up after scrolling back through history. */
+const FLASH_MS = 900;
+
+interface PaneScrollbarProps {
+ /** Pane call-sign — used for labels and test ids. */
+ name: string;
+ /**
+ * The pane's terminal area. Hover is measured against THIS element rather
+ * than the xterm host, because the bar itself sits inside it: with the host
+ * as the reference, moving onto the bar would count as leaving the pane and
+ * the bar would vanish under the pointer.
+ */
+ regionRef: React.RefObject<HTMLElement | null>;
+ /** The xterm host, where a relayed wheel event is dispatched. */
+ hostRef: React.RefObject<HTMLElement | null>;
+ /** The live terminal, or null before it is built. */
+ getTerminal: () => Terminal | null;
+ /**
+ * Bumped whenever the terminal behind `getTerminal` is replaced, so the
+ * subscriptions below are torn down and rebuilt against the new instance.
+ */
+ epoch: number;
+ appearance: TerminalAppearance;
+}
+
+export function PaneScrollbar({
+ name,
+ regionRef,
+ hostRef,
+ getTerminal,
+ epoch,
+ appearance,
+}: PaneScrollbarProps) {
+ const trackRef = useRef<HTMLDivElement | null>(null);
+ const [state, setState] = useState<PaneScrollState>(IDLE_STATE);
+ const [trackPx, setTrackPx] = useState(0);
+ const [nearEdge, setNearEdge] = useState(false);
+ const [flashing, setFlashing] = useState(false);
+ const [dragging, setDragging] = useState(false);
+ // Live grip offset in `app` mode: the grip follows the drag and springs back.
+ const [jogPx, setJogPx] = useState(0);
+
+ const shown = nearEdge || flashing || dragging;
+ const stateRef = useRef(state);
+ stateRef.current = state;
+
+ // ------------------------------------------------------------------ hover
+ useEffect(() => {
+ const region = regionRef.current;
+ if (!region) return;
+ let hideTimer: number | undefined;
+
+ const clearHide = () => {
+ if (hideTimer !== undefined) window.clearTimeout(hideTimer);
+ hideTimer = undefined;
+ };
+ const leave = () => {
+ clearHide();
+ hideTimer = window.setTimeout(() => setNearEdge(false), HIDE_DELAY_MS);
+ };
+ const onMove = (event: MouseEvent) => {
+ const rect = region.getBoundingClientRect();
+ const inside =
+ event.clientY >= rect.top &&
+ event.clientY <= rect.bottom &&
+ rect.right - event.clientX <= HOT_ZONE_PX &&
+ event.clientX <= rect.right;
+ if (inside) {
+ clearHide();
+ setNearEdge(true);
+ } else {
+ leave();
+ }
+ };
+
+ region.addEventListener("mousemove", onMove);
+ region.addEventListener("mouseleave", leave);
+ return () => {
+ clearHide();
+ region.removeEventListener("mousemove", onMove);
+ region.removeEventListener("mouseleave", leave);
+ };
+ }, [regionRef]);
+
+ // ------------------------------------------------- flash while scrolled back
+ // Deliberately NOT "flash on any scroll": a pane pinned to the bottom scrolls
+ // on every line an agent prints, and a bar that lit up for each of them would
+ // be the permanent stripe this replaces. Only a viewport sitting ABOVE the
+ // live end means somebody is reading history.
+ useEffect(() => {
+ const term = getTerminal();
+ if (!term?.onScroll) return;
+ let timer: number | undefined;
+ const subscription = term.onScroll(() => {
+ const buffer = term.buffer?.active;
+ if (!buffer || buffer.viewportY >= buffer.baseY) return;
+ setFlashing(true);
+ if (timer !== undefined) window.clearTimeout(timer);
+ timer = window.setTimeout(() => setFlashing(false), FLASH_MS);
+ });
+ return () => {
+ if (timer !== undefined) window.clearTimeout(timer);
+ subscription.dispose();
+ };
+ }, [getTerminal, epoch]);
+
+ // ---------------------------------------------------------------- metrics
+ // Only while the bar is on screen. A hidden bar needs no numbers, and reading
+ // them on every frame of a busy pane is exactly the kind of work the grid
+ // spends its frame budget avoiding.
+ useEffect(() => {
+ if (!shown) return;
+ const term = getTerminal();
+ if (!term) return;
+
+ let frame: number | undefined;
+ const sync = () => {
+ frame = undefined;
+ const next = readScrollState(term);
+ const previous = stateRef.current;
+ if (
+ next.mode !== previous.mode ||
+ next.total !== previous.total ||
+ next.rows !== previous.rows ||
+ next.top !== previous.top
+ ) {
+ setState(next);
+ }
+ const track = trackRef.current;
+ if (track) {
+ const height = track.clientHeight;
+ setTrackPx((current) => (current === height ? current : height));
+ }
+ };
+ const schedule = () => {
+ if (frame === undefined) frame = requestAnimationFrame(sync);
+ };
+
+ sync();
+ const subscriptions = [
+ term.onRender?.(schedule),
+ term.onResize?.(schedule),
+ term.buffer?.onBufferChange?.(schedule),
+ ];
+ return () => {
+ if (frame !== undefined) cancelAnimationFrame(frame);
+ for (const subscription of subscriptions) subscription?.dispose();
+ };
+ }, [shown, getTerminal, epoch]);
+
+ // The track's height decides the thumb's, and it is only knowable once the
+ // track is in the document. Measured on every commit rather than from the
+ // metrics effect above, because a pane whose agent is idle emits no render
+ // events at all — and a bar that waited for one would come up thumbless.
+ useLayoutEffect(() => {
+ const track = trackRef.current;
+ if (!track) return;
+ const height = track.clientHeight;
+ setTrackPx((current) => (current === height ? current : height));
+ });
+
+ // ------------------------------------------------------------------ input
+ const relay = useCallback(
+ (notches: number) => {
+ const direction = notches > 0 ? 1 : -1;
+ for (let i = 0; i < Math.abs(notches); i += 1) {
+ relayWheelNotch(hostRef.current, direction);
+ }
+ },
+ [hostRef],
+ );
+
+ const onThumbPointerDown = useCallback(
+ (event: React.PointerEvent<HTMLDivElement>) => {
+ const term = getTerminal();
+ const track = trackRef.current;
+ if (!term || !track) return;
+ event.preventDefault();
+ event.stopPropagation();
+
+ const current = stateRef.current;
+ const height = track.clientHeight;
+ const startY = event.clientY;
+ const geometry = thumbGeometry(current, height);
+ const startTop = geometry?.topPx ?? 0;
+ let sentNotches = 0;
+
+ const target = event.currentTarget;
+ target.setPointerCapture(event.pointerId);
+ setDragging(true);
+
+ const onMove = (move: PointerEvent) => {
+ const delta = move.clientY - startY;
+ if (current.mode === "app") {
+ const wanted = jogNotches(delta);
+ if (wanted !== sentNotches) {
+ relay(wanted - sentNotches);
+ sentNotches = wanted;
+ }
+ setJogPx(delta);
+ return;
+ }
+ const line = lineForThumbTop(startTop + delta, height, current);
+ term.scrollToLine?.(line);
+ };
+ const onUp = () => {
+ target.releasePointerCapture?.(event.pointerId);
+ target.removeEventListener("pointermove", onMove);
+ target.removeEventListener("pointerup", onUp);
+ target.removeEventListener("pointercancel", onUp);
+ setDragging(false);
+ setJogPx(0);
+ };
+
+ target.addEventListener("pointermove", onMove);
+ target.addEventListener("pointerup", onUp);
+ target.addEventListener("pointercancel", onUp);
+ },
+ [getTerminal, relay],
+ );
+
+ // A click on the empty part of the track pages towards it, the way every
+ // other scrollbar does. In `app` mode there is no "towards it" to aim at, so
+ // one page of wheel notches goes to the CLI instead.
+ const onTrackPointerDown = useCallback(
+ (event: React.PointerEvent<HTMLDivElement>) => {
+ const term = getTerminal();
+ const track = trackRef.current;
+ if (!term || !track) return;
+ event.preventDefault();
+ event.stopPropagation();
+ const current = stateRef.current;
+ const rect = track.getBoundingClientRect();
+ const geometry = thumbGeometry(current, rect.height);
+ if (!geometry) return;
+ const down = event.clientY - rect.top > geometry.topPx;
+ const pages = Math.max(1, current.rows - 1);
+ if (current.mode === "app") relay(down ? pages : -pages);
+ else term.scrollLines?.(down ? pages : -pages);
+ },
+ [getTerminal, relay],
+ );
+
+ const onWheel = useCallback(
+ (event: React.WheelEvent<HTMLDivElement>) => {
+ const term = getTerminal();
+ if (!term) return;
+ const current = stateRef.current;
+ const notches = event.deltaY > 0 ? 1 : -1;
+ if (current.mode === "app") relay(notches * 3);
+ else term.scrollLines?.(notches * 3);
+ },
+ [getTerminal, relay],
+ );
+
+ // ----------------------------------------------------------------- render
+ const geometry = thumbGeometry(state, trackPx, jogPx);
+ if (state.mode === "none") return null;
+
+ const light = appearance === "light";
+ const strength = dragging ? 0.95 : 0.62;
+ const maxTop = Math.max(0, state.total - state.rows);
+
+ return (
+ <div
+ ref={trackRef}
+ role="scrollbar"
+ aria-orientation="vertical"
+ aria-label={
+ state.mode === "app"
+ ? `Scroll ${name} — drag to move through the agent's own history`
+ : `Scroll ${name}`
+ }
+ aria-valuemin={0}
+ aria-valuemax={state.mode === "app" ? 0 : maxTop}
+ aria-valuenow={state.mode === "app" ? 0 : Math.min(state.top, maxTop)}
+ data-testid={`pane-scrollbar-${name}`}
+ data-mode={state.mode}
+ data-shown={shown ? "true" : "false"}
+ onPointerDown={onTrackPointerDown}
+ onWheel={onWheel}
+ onMouseDown={(event) => event.stopPropagation()}
+ className={cn(
+ "absolute bottom-1 right-1 top-1 z-10 w-[10px] rounded-full transition-opacity duration-150",
+ shown ? "opacity-100" : "pointer-events-none opacity-0",
+ )}
+ style={{
+ background: shown
+ ? light
+ ? "rgba(0,0,0,0.06)"
+ : "rgba(255,255,255,0.06)"
+ : "transparent",
+ }}
+ >
+ {geometry && (
+ <div
+ data-testid={`pane-scrollbar-thumb-${name}`}
+ onPointerDown={onThumbPointerDown}
+ className={cn(
+ "absolute left-0 w-full cursor-grab rounded-full",
+ dragging ? "cursor-grabbing" : "transition-[top] duration-75",
+ )}
+ style={{
+ top: geometry.topPx,
+ height: geometry.heightPx,
+ background: `rgb(var(--jarvis-yellow) / ${strength})`,
+ }}
+ />
+ )}
+ </div>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneScroll.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneScroll.test.ts
new file mode 100644
index 0000000000..0c3961e36a
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneScroll.test.ts
@@ -0,0 +1,184 @@
+import { describe, expect, it } from "vitest";
+import type { Terminal } from "@xterm/xterm";
+import {
+ GRIP_PX,
+ GRIP_TRAVEL_PX,
+ JOG_STEP_PX,
+ MIN_THUMB_PX,
+ jogNotches,
+ lineForThumbTop,
+ readScrollState,
+ relayWheelNotch,
+ thumbGeometry,
+} from "./paneScroll";
+
+interface FakeOptions {
+ type?: "normal" | "alternate";
+ length?: number;
+ rows?: number;
+ viewportY?: number;
+ mouseTrackingMode?: string;
+}
+
+function fakeTerminal({
+ type = "normal",
+ length = 100,
+ rows = 24,
+ viewportY = 0,
+ mouseTrackingMode = "none",
+}: FakeOptions = {}): Terminal {
+ return {
+ rows,
+ modes: { mouseTrackingMode },
+ buffer: { active: { type, length, viewportY, baseY: length - rows } },
+ } as unknown as Terminal;
+}
+
+describe("readScrollState", () => {
+ it("reports scrollback for a terminal that holds its own history", () => {
+ const state = readScrollState(fakeTerminal({ length: 100, rows: 24 }));
+
+ expect(state).toEqual({ mode: "scrollback", total: 100, rows: 24, top: 0 });
+ });
+
+ it("reports nothing to scroll while the buffer still fits on screen", () => {
+ expect(readScrollState(fakeTerminal({ length: 24, rows: 24 })).mode).toBe(
+ "none",
+ );
+ });
+
+ /*
+ * The regression this whole component exists for. Claude Code 2.1.220 opens a
+ * session with ESC[?1049h (alternate screen) plus ESC[?1000h/1002h/1003h/1006h
+ * (SGR mouse tracking): the terminal keeps no scrollback, so the native
+ * viewport scrollbar has nothing to move, and the wheel belongs to the CLI.
+ */
+ it("reports app mode for a full-screen CLI that took the mouse", () => {
+ const state = readScrollState(
+ fakeTerminal({ type: "alternate", mouseTrackingMode: "any", rows: 30 }),
+ );
+
+ expect(state.mode).toBe("app");
+ expect(state.rows).toBe(30);
+ });
+
+ it("stays away from a full-screen app that did not take the mouse", () => {
+ // Relaying a wheel notch to one of those would arrive in its input as the
+ // raw escape sequence, so no bar is the correct answer.
+ expect(
+ readScrollState(fakeTerminal({ type: "alternate" })).mode,
+ ).toBe("none");
+ });
+
+ it("survives a terminal that is not built yet", () => {
+ expect(readScrollState(null).mode).toBe("none");
+ expect(readScrollState({} as Terminal).mode).toBe("none");
+ });
+});
+
+describe("thumbGeometry", () => {
+ it("sizes the thumb by how much of the buffer is on screen", () => {
+ const state = readScrollState(fakeTerminal({ length: 400, rows: 100 }));
+
+ expect(thumbGeometry(state, 400)).toEqual({ topPx: 0, heightPx: 100 });
+ });
+
+ it("keeps a deep scrollback's thumb grabbable", () => {
+ const state = readScrollState(fakeTerminal({ length: 10000, rows: 24 }));
+
+ expect(thumbGeometry(state, 300)?.heightPx).toBe(MIN_THUMB_PX);
+ });
+
+ it("puts the thumb at the bottom when the viewport is at the live end", () => {
+ const state = readScrollState(
+ fakeTerminal({ length: 124, rows: 24, viewportY: 100 }),
+ );
+ const geometry = thumbGeometry(state, 400);
+
+ expect(geometry).not.toBeNull();
+ expect(geometry!.topPx + geometry!.heightPx).toBe(400);
+ });
+
+ it("centres a fixed grip in app mode — it encodes no position", () => {
+ const state = readScrollState(
+ fakeTerminal({ type: "alternate", mouseTrackingMode: "any" }),
+ );
+
+ expect(thumbGeometry(state, 300)).toEqual({ topPx: 128, heightPx: GRIP_PX });
+ });
+
+ it("lets the app-mode grip follow a drag, within its travel", () => {
+ const state = readScrollState(
+ fakeTerminal({ type: "alternate", mouseTrackingMode: "any" }),
+ );
+
+ expect(thumbGeometry(state, 300, 40)?.topPx).toBe(168);
+ // A long drag keeps relaying wheel notches, but the grip stops moving —
+ // it would otherwise sit at the bottom of the track claiming to be at the
+ // end of a history whose length nobody knows.
+ expect(thumbGeometry(state, 300, 9000)?.topPx).toBe(128 + GRIP_TRAVEL_PX);
+ });
+
+ it("draws nothing when there is nothing to scroll", () => {
+ expect(thumbGeometry(readScrollState(null), 300)).toBeNull();
+ expect(
+ thumbGeometry(readScrollState(fakeTerminal({ length: 400 })), 0),
+ ).toBeNull();
+ });
+});
+
+describe("lineForThumbTop", () => {
+ it("maps the ends of the track to the ends of the scrollback", () => {
+ const state = readScrollState(fakeTerminal({ length: 1024, rows: 24 }));
+
+ expect(lineForThumbTop(0, 400, state)).toBe(0);
+ expect(lineForThumbTop(400, 400, state)).toBe(1000);
+ });
+
+ it("clamps a drag that ran past the track", () => {
+ const state = readScrollState(fakeTerminal({ length: 1024, rows: 24 }));
+
+ expect(lineForThumbTop(-500, 400, state)).toBe(0);
+ expect(lineForThumbTop(5000, 400, state)).toBe(1000);
+ });
+});
+
+describe("jogNotches", () => {
+ it("converts a drag distance into whole wheel notches", () => {
+ expect(jogNotches(0)).toBe(0);
+ expect(jogNotches(JOG_STEP_PX - 1)).toBe(0);
+ expect(jogNotches(JOG_STEP_PX * 3)).toBe(3);
+ expect(jogNotches(-JOG_STEP_PX * 2)).toBe(-2);
+ });
+});
+
+describe("relayWheelNotch", () => {
+ function host(): HTMLElement {
+ const element = document.createElement("div");
+ const screen = document.createElement("div");
+ screen.className = "xterm-screen";
+ element.appendChild(screen);
+ document.body.appendChild(element);
+ return element;
+ }
+
+ it("dispatches a wheel event xterm can encode for the running CLI", () => {
+ const element = host();
+ const seen: WheelEvent[] = [];
+ element.addEventListener("wheel", (event) => seen.push(event as WheelEvent));
+
+ relayWheelNotch(element, -1);
+
+ expect(seen).toHaveLength(1);
+ // Lines, not pixels: xterm divides a pixel delta by the row height and
+ // carries the remainder, so a synthetic pixel delta can round to no lines
+ // at all and be dropped before it is ever encoded.
+ expect(seen[0].deltaMode).toBe(1);
+ expect(seen[0].deltaY).toBe(-1);
+ });
+
+ it("does nothing without a rendered terminal to aim at", () => {
+ expect(relayWheelNotch(null, 1)).toBe(false);
+ expect(relayWheelNotch(document.createElement("div"), 1)).toBe(false);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneScroll.ts b/jarvis/ui/web/frontend/src/components/agentic/paneScroll.ts
new file mode 100644
index 0000000000..849b9eca69
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneScroll.ts
@@ -0,0 +1,194 @@
+/**
+ * What a terminal pane can scroll right now, and where its scrollbar sits.
+ *
+ * ## Why this is not just CSS on the xterm viewport
+ *
+ * The obvious way to give a pane a scrollbar is to style `.xterm-viewport` and
+ * let the browser draw the native one. That works for a CLI which prints line
+ * by line — Codex does, and its bar behaved perfectly. It does nothing at all
+ * for Claude Code, and the reason is a property of the CLI rather than a bug in
+ * the styling: measured against Claude Code 2.1.220, the moment it opens a real
+ * session it emits
+ *
+ * ESC[?1049h switch to the ALTERNATE screen buffer
+ * ESC[?1000h ESC[?1002h ESC[?1003h ESC[?1006h full SGR mouse tracking
+ *
+ * In the alternate buffer a terminal has no scrollback by definition — the
+ * application owns the whole screen and keeps its own history, exactly like
+ * `vim` or `less`. So `.xterm-viewport` has nothing to scroll, the native thumb
+ * fills its track, and no amount of CSS can move it. Meanwhile the mouse
+ * tracking means the wheel is no longer the terminal's to handle: xterm
+ * forwards it and Claude Code scrolls its own transcript.
+ *
+ * Hence two modes, and a scrollbar that reads which one it is in:
+ *
+ * * `scrollback` — the terminal holds the history (Codex, a plain shell). The
+ * thumb is proportional and exact, and dragging it moves the viewport.
+ * * `app` — a full-screen application holds the history and accepts wheel
+ * events (Claude Code). There is no honest position to draw, so the bar
+ * becomes a centred grip: dragging it relays wheel notches to the CLI, which
+ * scrolls itself. It springs back rather than pretending to know where it is.
+ * * `none` — nothing to scroll (a fresh pane, or a full-screen app that does
+ * not take the mouse). The bar stays away instead of drawing a dead track.
+ */
+import type { Terminal } from "@xterm/xterm";
+
+/** Which of the two scrolling worlds a pane is in — see the file header. */
+export type PaneScrollMode = "scrollback" | "app" | "none";
+
+export interface PaneScrollState {
+ mode: PaneScrollMode;
+ /** Buffer lines in total, scrollback included. */
+ total: number;
+ /** Lines visible at once. */
+ rows: number;
+ /** Buffer line currently at the top of the viewport. */
+ top: number;
+}
+
+export interface ThumbGeometry {
+ topPx: number;
+ heightPx: number;
+}
+
+export const IDLE_STATE: PaneScrollState = {
+ mode: "none",
+ total: 0,
+ rows: 0,
+ top: 0,
+};
+
+/** A thumb shorter than this is impossible to grab in a tall pane. */
+export const MIN_THUMB_PX = 26;
+
+/** Height of the `app`-mode grip. Fixed: it encodes no position. */
+export const GRIP_PX = 44;
+
+/** How far the `app`-mode grip may travel from centre while dragged. */
+export const GRIP_TRAVEL_PX = 60;
+
+/** Drag distance that relays one wheel notch in `app` mode. */
+export const JOG_STEP_PX = 12;
+
+function clamp(value: number, low: number, high: number): number {
+ return value < low ? low : value > high ? high : value;
+}
+
+/**
+ * Read a pane's scroll situation off the live terminal.
+ *
+ * Defensive by design: this runs against whatever xterm build the app was
+ * bundled with, and a missing field must degrade to "nothing to scroll" rather
+ * than throw inside a render.
+ */
+export function readScrollState(term: Terminal | null): PaneScrollState {
+ const buffer = term?.buffer?.active;
+ const rows = term?.rows ?? 0;
+ if (!term || !buffer || rows < 1) return IDLE_STATE;
+
+ const total = buffer.length ?? rows;
+ const top = buffer.viewportY ?? 0;
+
+ if (buffer.type !== "alternate") {
+ if (total > rows) return { mode: "scrollback", total, rows, top };
+ return IDLE_STATE;
+ }
+ // Alternate buffer: the application draws the screen. It can only be
+ // scrolled if it asked for the mouse, because relaying a wheel notch to a CLI
+ // that did not would inject the escape sequence as if it had been typed.
+ if (appTakesWheel(term)) return { mode: "app", total: rows, rows, top: 0 };
+ return IDLE_STATE;
+}
+
+/** True when the running application receives wheel events itself. */
+export function appTakesWheel(term: Terminal | null): boolean {
+ const tracking = term?.modes?.mouseTrackingMode;
+ return Boolean(tracking) && tracking !== "none";
+}
+
+/**
+ * Where to draw the thumb inside a track of `trackPx`, or null for no bar.
+ *
+ * In `app` mode `offsetPx` is the live drag offset, so the grip follows the
+ * pointer while it is held and returns to the middle when it is let go.
+ */
+export function thumbGeometry(
+ state: PaneScrollState,
+ trackPx: number,
+ offsetPx = 0,
+): ThumbGeometry | null {
+ if (trackPx <= 0) return null;
+
+ if (state.mode === "app") {
+ const heightPx = Math.min(GRIP_PX, trackPx);
+ const centre = (trackPx - heightPx) / 2;
+ const travel = clamp(offsetPx, -GRIP_TRAVEL_PX, GRIP_TRAVEL_PX);
+ return {
+ heightPx,
+ topPx: Math.round(clamp(centre + travel, 0, trackPx - heightPx)),
+ };
+ }
+
+ if (state.mode !== "scrollback" || state.total <= state.rows) return null;
+
+ const heightPx = Math.min(
+ trackPx,
+ Math.max(MIN_THUMB_PX, Math.round((trackPx * state.rows) / state.total)),
+ );
+ const maxTop = state.total - state.rows;
+ const progress = maxTop > 0 ? clamp(state.top / maxTop, 0, 1) : 0;
+ return { heightPx, topPx: Math.round((trackPx - heightPx) * progress) };
+}
+
+/** The buffer line a thumb dragged to `topPx` is asking for. */
+export function lineForThumbTop(
+ topPx: number,
+ trackPx: number,
+ state: PaneScrollState,
+): number {
+ const geometry = thumbGeometry(state, trackPx);
+ if (!geometry || state.mode !== "scrollback") return state.top;
+ const span = trackPx - geometry.heightPx;
+ const maxTop = state.total - state.rows;
+ if (span <= 0 || maxTop <= 0) return 0;
+ return Math.round(clamp(topPx / span, 0, 1) * maxTop);
+}
+
+/** How many wheel notches a drag of `deltaPx` is worth in `app` mode. */
+export function jogNotches(deltaPx: number): number {
+ return Math.trunc(deltaPx / JOG_STEP_PX);
+}
+
+/**
+ * Hand one wheel notch to the application running in `host`.
+ *
+ * Synthesized as a real `wheel` event on xterm's screen element rather than
+ * written to the socket by hand, deliberately: xterm already knows which mouse
+ * protocol the application negotiated (X10, VT200, SGR, …) and encodes the
+ * report accordingly. Writing the bytes ourselves would mean guessing, and a
+ * guess wrong by one protocol arrives in the CLI's prompt as garbage.
+ *
+ * `direction` is +1 to scroll down (towards newer output), -1 for up.
+ */
+export function relayWheelNotch(
+ host: HTMLElement | null,
+ direction: 1 | -1,
+): boolean {
+ if (!host || typeof WheelEvent === "undefined") return false;
+ const screen = host.querySelector<HTMLElement>(".xterm-screen");
+ if (!screen) return false;
+ const rect = screen.getBoundingClientRect();
+ return screen.dispatchEvent(
+ new WheelEvent("wheel", {
+ bubbles: true,
+ cancelable: true,
+ clientX: rect.left + rect.width / 2,
+ clientY: rect.top + rect.height / 2,
+ // Lines, not pixels: xterm divides a pixel delta by the row height and
+ // carries the remainder, so a synthetic pixel delta can round to zero
+ // lines and be dropped entirely.
+ deltaMode: 1,
+ deltaY: direction,
+ }),
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/index.css b/jarvis/ui/web/frontend/src/index.css
index ea8528db88..74f2fa4c4f 100644
--- a/jarvis/ui/web/frontend/src/index.css
+++ b/jarvis/ui/web/frontend/src/index.css
@@ -28,47 +28,22 @@
display: none;
}
-/* Agentic IDE terminal scrollbar. This targets the shared xterm host rather
- than a coding CLI, so Claude Code, Codex, and future agents all get the same
- native scrollback controls. The visible track makes the scroll range easy to
- discover; the inset thumb stays quiet until hover/drag. Keep this top-level:
- xterm creates the viewport at runtime and Tailwind would purge it in a layer. */
+/* Agentic IDE panes draw their OWN scrollbar (components/agentic/PaneScrollbar)
+ and hide the browser's, for two reasons the native bar could not meet: it is
+ permanently on screen, and it is powered by the xterm viewport — which a
+ full-screen CLI like Claude Code leaves empty, because it runs on the
+ alternate screen buffer and keeps its history in its own process. Hiding it
+ here rather than switching the viewport to `overflow: hidden` is deliberate:
+ xterm still needs a scrollable viewport for the wheel and for `scrollToLine`.
+ Keep this top-level — xterm creates the viewport at runtime, so Tailwind
+ would purge a rule for it out of an @layer. */
.agentic-terminal-host .xterm-viewport {
- scrollbar-color: rgb(var(--jarvis-yellow) / 0.5) rgba(127, 127, 127, 0.14);
- scrollbar-gutter: stable;
- scrollbar-width: thin;
+ scrollbar-width: none;
}
.agentic-terminal-host .xterm-viewport::-webkit-scrollbar {
- width: 10px;
-}
-
-.agentic-terminal-host .xterm-viewport::-webkit-scrollbar-track {
- background: rgba(127, 127, 127, 0.14);
- border-radius: 999px;
- box-shadow: inset 1px 0 rgba(255, 255, 255, 0.06);
-}
-
-.agentic-terminal-host .xterm-viewport::-webkit-scrollbar-thumb {
- min-height: 32px;
- background: rgb(var(--jarvis-yellow) / 0.5);
- background-clip: padding-box;
- border: 2px solid transparent;
- border-radius: 999px;
-}
-
-.agentic-terminal-host .xterm-viewport::-webkit-scrollbar-thumb:hover {
- background: rgb(var(--jarvis-yellow) / 0.72);
- background-clip: padding-box;
-}
-
-.agentic-terminal-host .xterm-viewport::-webkit-scrollbar-thumb:active {
- background: rgb(var(--jarvis-yellow) / 0.92);
- background-clip: padding-box;
-}
-
-.agentic-terminal-host .xterm-viewport::-webkit-scrollbar-corner {
- background: transparent;
+ width: 0;
+ height: 0;
}
@layer base {