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 mouse-drag scrollbar that leaves the wheel alone

Ruben Lütkef9a186ef8f1d
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 4d6aca493e..9598169a85 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -86,6 +86,7 @@ import {
PARKED_RECHECK_MS,
} from "./offscreenBuffer";
import { installQuerySuppression } from "./terminalQueries";
+import { PaneScrollbar } from "./PaneScrollbar";
import { openPaneSocket, type PaneSocket } from "./paneSocket";
export type PaneStatus = "connecting" | "live" | "exited" | "error";
@@ -273,10 +274,16 @@ export function AgenticTerminal({
}: AgenticTerminalProps) {
const containerRef = useRef<HTMLDivElement | null>(null);
// The padded box around the xterm host — the pane's visible inset, kept off
- // the host itself because FitAddon reads the host's border-box.
+ // the host itself because FitAddon reads the host's border-box. The pane's
+ // scrollbar overlays this box and measures hover against it.
const scrollRegionRef = useRef<HTMLDivElement | null>(null);
const termRef = useRef<Terminal | null>(null);
const fitRef = useRef<FitAddon | null>(null);
+ // 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, []);
// Lets the font-size effect trigger a REAL resize (xterm + the terminal
// process together) without reaching into the connect effect's socket.
const resizeRef = useRef<(() => void) | null>(null);
@@ -370,6 +377,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
@@ -976,6 +984,17 @@ export function AgenticTerminal({
data-layout-busy={layoutBusy ? "true" : "false"}
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 scrollbar has nothing
+ to move in a full-screen CLI's 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..eb8edbec53
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx
@@ -0,0 +1,334 @@
+import { useCallback, useRef } from "react";
+import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import type { Terminal } from "@xterm/xterm";
+import { PaneScrollbar } from "./PaneScrollbar";
+import { LINES_PER_NOTCH } from "./scrollbarModel";
+
+const REGION = { top: 0, bottom: 300, left: 0, right: 400 };
+const TRACK_PX = 300;
+
+/**
+ * A fake terminal over a mutable state object, so a test can grow the buffer
+ * underneath the bar the way a live agent does, and captured subscriptions so
+ * it can fire the events xterm would.
+ */
+interface TermState {
+ type: "normal" | "alternate";
+ length: number;
+ rows: number;
+ viewportY: number;
+ baseY: number;
+ mouseTrackingMode: string;
+}
+
+function fakeTerminal(overrides: Partial<TermState> = {}) {
+ const state: TermState = {
+ type: "normal",
+ length: 1000,
+ rows: 24,
+ viewportY: 976,
+ baseY: 976,
+ mouseTrackingMode: "none",
+ ...overrides,
+ };
+ const listeners: Record<string, (() => void)[]> = {};
+ const on = (event: string) => (handler: () => void) => {
+ (listeners[event] ??= []).push(handler);
+ return { dispose() {} };
+ };
+ const term = {
+ get rows() {
+ return state.rows;
+ },
+ modes: {
+ get mouseTrackingMode() {
+ return state.mouseTrackingMode;
+ },
+ },
+ buffer: {
+ active: {
+ get type() {
+ return state.type;
+ },
+ get length() {
+ return state.length;
+ },
+ get viewportY() {
+ return state.viewportY;
+ },
+ get baseY() {
+ return state.baseY;
+ },
+ },
+ onBufferChange: on("bufferChange"),
+ },
+ onRender: on("render"),
+ onResize: on("resize"),
+ onScroll: on("scroll"),
+ scrollToLine: vi.fn(),
+ scrollLines: vi.fn(),
+ } as unknown as Terminal;
+ const fire = (event: string) => {
+ for (const handler of listeners[event] ?? []) handler();
+ };
+ return { term, state, fire };
+}
+
+/** A Claude-Code-style pane: the CLI owns the screen and the wheel. */
+function appTerminal(rows = 24) {
+ return fakeTerminal({
+ type: "alternate",
+ length: rows,
+ rows,
+ viewportY: 0,
+ baseY: 0,
+ mouseTrackingMode: "any",
+ });
+}
+
+function Harness({ term, epoch = 1 }: { term: Terminal; epoch?: number }) {
+ 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="Kite"
+ regionRef={regionRef}
+ hostRef={hostRef}
+ getTerminal={getTerminal}
+ epoch={epoch}
+ appearance="dark"
+ />
+ </div>
+ );
+}
+
+/**
+ * A pointer move with coordinates on it. jsdom ships no `PointerEvent`, and
+ * the synthetic one Testing Library falls back to carries no `clientY` — a
+ * `MouseEvent` of the same name does.
+ */
+function dragTo(element: Element, clientY: number) {
+ fireEvent(element, new MouseEvent("pointermove", { clientY, bubbles: true }));
+}
+
+const bar = () => screen.queryByTestId("pane-scrollbar-Kite");
+const thumb = () => screen.getByTestId("pane-scrollbar-thumb-Kite");
+const thumbTop = () => parseFloat(thumb().style.top || "0");
+const thumbHeight = () => parseFloat(thumb().style.height || "0");
+const host = () => document.querySelector(".agentic-terminal-host")!;
+
+function reachThePane() {
+ fireEvent.mouseEnter(screen.getByTestId("region"));
+}
+
+function leaveThePane() {
+ fireEvent.mouseLeave(screen.getByTestId("region"));
+}
+
+/** Every wheel event that reaches the CLI's screen, by deltaY. */
+function watchScreen(): number[] {
+ const seen: number[] = [];
+ document
+ .querySelector(".xterm-screen")!
+ .addEventListener("wheel", (event) => {
+ seen.push((event as WheelEvent).deltaY);
+ });
+ return seen;
+}
+
+describe("PaneScrollbar", () => {
+ beforeEach(() => {
+ // jsdom measures nothing; the two boxes the component reads are staged.
+ Object.defineProperty(HTMLElement.prototype, "clientHeight", {
+ configurable: true,
+ value: TRACK_PX,
+ });
+ 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 arrives", () => {
+ render(<Harness term={fakeTerminal().term} />);
+ expect(bar()).toBeNull();
+
+ reachThePane();
+
+ expect(bar()!.dataset.shown).toBe("true");
+ });
+
+ it("becomes intangible again after the pointer leaves", () => {
+ vi.useFakeTimers();
+ try {
+ render(<Harness term={fakeTerminal().term} />);
+ reachThePane();
+ leaveThePane();
+ act(() => vi.advanceTimersByTime(1000));
+ } finally {
+ vi.useRealTimers();
+ }
+
+ expect(bar()!.dataset.shown).toBe("false");
+ // Invisible AND untouchable: a transparent strip that still swallowed
+ // pointer events would break selecting text at the pane's right edge.
+ expect(bar()!.className).toContain("pointer-events-none");
+ });
+
+ it("shows nothing on a pane with nothing to scroll", () => {
+ render(<Harness term={fakeTerminal({ length: 24 }).term} />);
+
+ reachThePane();
+
+ expect(bar()).toBeNull();
+ });
+
+ it("gives a full-screen CLI's pane a bar with nothing measured at all", () => {
+ render(<Harness term={appTerminal().term} />);
+
+ reachThePane();
+
+ expect(bar()!.dataset.kind).toBe("travel");
+ // Standing at the newest output: the thumb rests on the bottom.
+ expect(thumbTop() + thumbHeight()).toBe(TRACK_PX);
+ });
+
+ it("draws a scrolled-back terminal's thumb where it really stands", () => {
+ render(<Harness term={fakeTerminal({ viewportY: 0 }).term} />);
+
+ reachThePane();
+
+ expect(bar()!.dataset.kind).toBe("exact");
+ expect(thumbTop()).toBe(0);
+ });
+
+ it("keeps the thumb honest while the agent keeps talking", async () => {
+ const { term, state, fire } = fakeTerminal();
+ render(<Harness term={term} />);
+ reachThePane();
+ expect(bar()!.getAttribute("aria-valuemax")).toBe("976");
+
+ // The agent prints another thousand lines while the bar is up.
+ state.length = 2000;
+ state.baseY = 1976;
+ fire("scroll");
+
+ await waitFor(() =>
+ expect(bar()!.getAttribute("aria-valuemax")).toBe("1976"),
+ );
+ });
+
+ it("takes a dragged thumb straight to the line it was dropped on", () => {
+ const { term } = fakeTerminal();
+ render(<Harness term={term} />);
+ reachThePane();
+ const grabbed = thumbTop();
+
+ fireEvent.pointerDown(thumb(), { clientY: 200, pointerId: 1 });
+ dragTo(thumb(), 200 - grabbed);
+
+ // Dropped at the very top of the track: the top of the scrollback.
+ expect(term.scrollToLine).toHaveBeenLastCalledWith(0);
+
+ fireEvent.pointerUp(thumb(), { pointerId: 1 });
+ });
+
+ it("drags a full-screen CLI by relaying wheel notches to its screen", () => {
+ render(<Harness term={appTerminal(24).term} />);
+ reachThePane();
+ const seen = watchScreen();
+ const grabbed = thumbTop();
+
+ fireEvent.pointerDown(thumb(), { clientY: 200, pointerId: 1 });
+ dragTo(thumb(), 200 - grabbed);
+ fireEvent.pointerUp(thumb(), { pointerId: 1 });
+
+ // A full pull up asks for the whole assumed span — one screen, in notches.
+ expect(seen.length).toBe(Math.trunc(24 / LINES_PER_NOTCH));
+ expect(new Set(seen)).toEqual(new Set([-1]));
+ });
+
+ it("pages towards a press on the empty part of the track", () => {
+ const { term } = fakeTerminal();
+ render(<Harness term={term} />);
+ reachThePane();
+
+ // The thumb rests at the bottom, so a press at the top pages backwards.
+ fireEvent.pointerDown(bar()!, { clientY: REGION.top + 4 });
+
+ expect(term.scrollLines).toHaveBeenCalledWith(-23);
+ });
+
+ it("forwards a wheel over the bar to the terminal, untouched", () => {
+ render(<Harness term={fakeTerminal().term} />);
+ reachThePane();
+ const seen = watchScreen();
+
+ const notCancelled = fireEvent.wheel(bar()!, {
+ deltaY: 120,
+ deltaMode: 0,
+ });
+
+ expect(seen).toEqual([120]);
+ // The bar has no wheel behaviour of its own and never cancels the event.
+ expect(notCancelled).toBe(true);
+ });
+
+ it("never lays a hand on a wheel turned over the terminal", () => {
+ render(<Harness term={appTerminal().term} />);
+
+ let untouched = false;
+ act(() => {
+ untouched = host().dispatchEvent(
+ new WheelEvent("wheel", {
+ deltaY: -1,
+ bubbles: true,
+ cancelable: true,
+ }),
+ );
+ });
+
+ expect(untouched).toBe(true);
+ });
+
+ it("counts a CLI-held pane's travel and re-anchors at the live end", async () => {
+ render(<Harness term={appTerminal(24).term} />);
+
+ // Four notches back, before the bar was ever shown.
+ for (let i = 0; i < 4; i += 1) fireEvent.wheel(host(), { deltaY: -1 });
+ reachThePane();
+ expect(thumbTop() + thumbHeight()).toBeLessThan(TRACK_PX);
+
+ // Forward far past the live end: the count clamps, the thumb comes home.
+ for (let i = 0; i < 8; i += 1) fireEvent.wheel(host(), { deltaY: 1 });
+ await waitFor(() => expect(thumbTop() + thumbHeight()).toBe(TRACK_PX));
+ });
+
+ it("starts a fresh terminal's count from zero", async () => {
+ const first = appTerminal(24).term;
+ const { rerender } = render(<Harness term={first} epoch={1} />);
+ for (let i = 0; i < 4; i += 1) fireEvent.wheel(host(), { deltaY: -1 });
+ reachThePane();
+ expect(thumbTop() + thumbHeight()).toBeLessThan(TRACK_PX);
+
+ // The pane restarted its agent: same component, replaced terminal.
+ rerender(<Harness term={appTerminal(24).term} epoch={2} />);
+
+ await waitFor(() => expect(thumbTop() + thumbHeight()).toBe(TRACK_PX));
+ });
+});
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..149f4a43d2
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx
@@ -0,0 +1,497 @@
+/**
+ * A pane's drag scrollbar: a thin overlay on the right edge, driven by the
+ * mouse and by nothing else.
+ *
+ * ## The one hard rule — the wheel is not this component's business
+ *
+ * A predecessor of this bar is remembered as "it broke scrolling in the
+ * terminal". The root cause was elsewhere (a replay buffer dropping the CLI's
+ * mouse negotiation), but the lesson stands, so this build makes it a law:
+ * nothing here ever calls `preventDefault` on a wheel event, reinterprets one,
+ * or stands between the wheel and xterm. The two places wheel events appear
+ * at all are (a) a **passive** observer that only counts them, and (b) the
+ * track forwarding a clone of any wheel it happens to catch to the terminal's
+ * screen, so that scrolling over the bar behaves exactly like scrolling next
+ * to it. Everything the bar does itself is done by dragging its thumb or
+ * clicking its track — mouse only, by design.
+ *
+ * ## Why the pane draws its own bar instead of styling the browser's
+ *
+ * Half the panes have nothing a browser scrollbar could move. A line-printing
+ * CLI (Codex, a shell) keeps its history in xterm's scrollback and could use
+ * the native bar — but a full-screen CLI (Claude Code) runs on the alternate
+ * buffer, where the terminal holds no scrollback at all and the transcript
+ * lives inside the application. For those panes the thumb is dragged in
+ * relayed wheel notches, and where it stands is COUNTED from the wheel
+ * traffic rather than measured from a screen that cannot be read — see
+ * ./scrollbarModel for what that claim means and why it re-anchors at the
+ * live end. The synthetic notches are dispatched as real wheel events on
+ * xterm's screen, because xterm already knows which mouse protocol the
+ * application negotiated and encodes the report accordingly; guessing those
+ * bytes here would put junk in the CLI's prompt.
+ *
+ * ## Cost discipline
+ *
+ * A grid holds a dozen live terminals. While the pointer is elsewhere this
+ * component owns two hover listeners and one passive wheel observer, and
+ * reads nothing. Terminal state is read only while the bar is on screen, all
+ * reads are coalesced into animation frames, and hover is enter/leave rather
+ * than per-move tracking.
+ */
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import type { Terminal } from "@xterm/xterm";
+import { cn } from "@/lib/utils";
+import type { TerminalAppearance } from "./terminalThemes";
+import {
+ backAtThumbTop,
+ countWheel,
+ hasScroll,
+ notchesFor,
+ thumbBox,
+ type ScrollView,
+ exactView,
+ travelView,
+} from "./scrollbarModel";
+
+/** How long the bar lingers after the pointer leaves, so it cannot flicker. */
+const LINGER_MS = 200;
+
+/** How long a wheel turn keeps the bar visible as a position readout. */
+const FLASH_MS = 800;
+
+/** True when the running application receives wheel events itself. */
+function appOwnsScreen(term: Terminal | null): boolean {
+ if (!term) return false;
+ const tracking = term.modes?.mouseTrackingMode;
+ if (Boolean(tracking) && tracking !== "none") return true;
+ return term.buffer?.active?.type === "alternate";
+}
+
+/**
+ * What this pane can scroll right now, or null when nothing is known.
+ *
+ * Defensive against the bundled xterm's shape on purpose: a missing field
+ * must mean "no bar", never an exception inside a render.
+ */
+export function readScrollView(
+ term: Terminal | null,
+ travelled: number,
+): ScrollView | null {
+ const buffer = term?.buffer?.active;
+ const rows = term?.rows ?? 0;
+ if (!term || !buffer || rows < 1) return null;
+ if (appOwnsScreen(term)) return travelView(travelled, rows);
+ const view = exactView(
+ buffer.length ?? rows,
+ buffer.baseY ?? 0,
+ buffer.viewportY ?? 0,
+ rows,
+ );
+ return hasScroll(view) ? view : null;
+}
+
+/**
+ * Hand `count` wheel notches to whatever runs in `host` (direction -1 is
+ * towards older output, matching a wheel turned away from the hand).
+ */
+export function relayNotches(
+ host: HTMLElement | null,
+ direction: 1 | -1,
+ count: number,
+): void {
+ if (!host || count <= 0 || typeof WheelEvent === "undefined") return;
+ const screen = host.querySelector<HTMLElement>(".xterm-screen");
+ if (!screen) return;
+ const box = screen.getBoundingClientRect();
+ for (let i = 0; i < count; i += 1) {
+ screen.dispatchEvent(
+ new WheelEvent("wheel", {
+ bubbles: true,
+ cancelable: true,
+ clientX: box.left + box.width / 2,
+ clientY: box.top + box.height / 2,
+ deltaMode: 1,
+ deltaY: direction,
+ }),
+ );
+ }
+}
+
+interface PaneScrollbarProps {
+ /** Pane call-sign — labels and test ids. */
+ name: string;
+ /**
+ * The pane's terminal area, which hover is measured against. It has to be
+ * the region the bar sits INSIDE — measured against the xterm host, moving
+ * onto the bar itself would already count as having left.
+ */
+ regionRef: React.RefObject<HTMLElement | null>;
+ /** The xterm host, where relayed and forwarded wheel events are aimed. */
+ hostRef: React.RefObject<HTMLElement | null>;
+ /** The live terminal, or null before the pane has built one. */
+ getTerminal: () => Terminal | null;
+ /** Bumped whenever the terminal behind `getTerminal` is replaced. */
+ epoch: number;
+ appearance: TerminalAppearance;
+}
+
+export function PaneScrollbar({
+ name,
+ regionRef,
+ hostRef,
+ getTerminal,
+ epoch,
+ appearance,
+}: PaneScrollbarProps) {
+ const trackRef = useRef<HTMLDivElement | null>(null);
+ const [view, setView] = useState<ScrollView | null>(null);
+ const [trackPx, setTrackPx] = useState(0);
+ const [hovering, setHovering] = useState(false);
+ const [flashing, setFlashing] = useState(false);
+ const [dragging, setDragging] = useState(false);
+ // The thumb's position while it is held. A full-screen CLI answers relayed
+ // notches a beat later, so a thumb drawn only from the counted position
+ // would trail the pointer that is holding it.
+ const [heldTopPx, setHeldTopPx] = useState<number | null>(null);
+
+ // Lines a full-screen CLI has been scrolled away from its live end, counted
+ // off the wheel traffic — the user's own turns and this bar's relays alike,
+ // since both pass the same observer below.
+ const travelledRef = useRef(0);
+ // Which kind of pane the last reading saw. A CLI that enters or leaves the
+ // alternate screen mid-session (a shell running `less`) starts a different
+ // history, and a count carried across that line would describe the old one.
+ const lastKindRef = useRef<ScrollView["kind"] | null>(null);
+ // The sync scheduler, parked here so the always-on wheel observer can poke
+ // the read loop that only exists while the bar is visible.
+ const scheduleRef = useRef<(() => void) | null>(null);
+
+ const shown = hovering || flashing || dragging;
+ const viewRef = useRef(view);
+ viewRef.current = view;
+
+ // A replaced terminal is a fresh transcript.
+ useEffect(() => {
+ travelledRef.current = 0;
+ lastKindRef.current = null;
+ setView(null);
+ }, [epoch]);
+
+ // ------------------------------------------------------------------ hover
+ // Enter and leave only: a grid of a dozen panes must not pay per pixel of
+ // pointer movement to know which one is being reached for.
+ useEffect(() => {
+ const region = regionRef.current;
+ if (!region) return;
+ let timer: number | undefined;
+ const enter = () => {
+ if (timer !== undefined) window.clearTimeout(timer);
+ timer = undefined;
+ setHovering(true);
+ };
+ const leave = () => {
+ if (timer !== undefined) window.clearTimeout(timer);
+ timer = window.setTimeout(() => setHovering(false), LINGER_MS);
+ };
+ region.addEventListener("mouseenter", enter);
+ region.addEventListener("mouseleave", leave);
+ return () => {
+ if (timer !== undefined) window.clearTimeout(timer);
+ region.removeEventListener("mouseenter", enter);
+ region.removeEventListener("mouseleave", leave);
+ };
+ }, [regionRef]);
+
+ // -------------------------------------------------------------- observing
+ // The wheel, watched but never touched. Passive so it CANNOT interfere with
+ // what xterm does next, capture so it also sees the synthetic notches this
+ // bar dispatches, and always on so a pane scrolled a minute ago comes up
+ // already knowing how far back it stands.
+ useEffect(() => {
+ const host = hostRef.current;
+ if (!host) return;
+ let timer: number | undefined;
+ const onWheel = (event: WheelEvent) => {
+ if (event.deltaY === 0) return;
+ if (appOwnsScreen(getTerminal())) {
+ travelledRef.current = countWheel(travelledRef.current, event.deltaY);
+ }
+ scheduleRef.current?.();
+ setFlashing(true);
+ if (timer !== undefined) window.clearTimeout(timer);
+ timer = window.setTimeout(() => setFlashing(false), FLASH_MS);
+ };
+ host.addEventListener("wheel", onWheel, { capture: true, passive: true });
+ return () => {
+ if (timer !== undefined) window.clearTimeout(timer);
+ host.removeEventListener("wheel", onWheel, { capture: true });
+ };
+ }, [hostRef, getTerminal, epoch]);
+
+ // ---------------------------------------------------------------- reading
+ // Terminal state is read only while the bar is on screen, at most once per
+ // animation frame — a grid of live agents cannot afford more.
+ useEffect(() => {
+ if (!shown) {
+ scheduleRef.current = null;
+ return;
+ }
+ const term = getTerminal();
+ if (!term) return;
+ let frame: number | undefined;
+
+ const sync = () => {
+ frame = undefined;
+ const next = readScrollView(term, travelledRef.current);
+ // Crossing between a terminal-held and an application-held screen resets
+ // the count: it described a history that is no longer on stage.
+ if (next && lastKindRef.current && next.kind !== lastKindRef.current) {
+ travelledRef.current = 0;
+ }
+ if (next) lastKindRef.current = next.kind;
+ const settled =
+ next && next.kind === "travel"
+ ? readScrollView(term, travelledRef.current)
+ : next;
+ setView((current) => (sameView(current, settled) ? current : settled));
+ };
+ const schedule = () => {
+ if (frame === undefined) frame = requestAnimationFrame(sync);
+ };
+ scheduleRef.current = schedule;
+
+ sync();
+ const subscriptions = [
+ term.onRender?.(schedule),
+ term.onResize?.(schedule),
+ term.onScroll?.(schedule),
+ term.buffer?.onBufferChange?.(schedule),
+ ];
+ return () => {
+ scheduleRef.current = null;
+ if (frame !== undefined) cancelAnimationFrame(frame);
+ for (const subscription of subscriptions) subscription?.dispose();
+ };
+ }, [shown, getTerminal, epoch]);
+
+ // -------------------------------------------------------------- geometry
+ // Measured outside the render, and only when the box actually changes.
+ useEffect(() => {
+ const track = trackRef.current;
+ if (!track) return;
+ const measure = () => {
+ setTrackPx((current) =>
+ current === track.clientHeight ? current : track.clientHeight,
+ );
+ };
+ measure();
+ if (typeof ResizeObserver === "undefined") return;
+ const observer = new ResizeObserver(measure);
+ observer.observe(track);
+ return () => observer.disconnect();
+ }, [view !== null]);
+
+ // ----------------------------------------------------------------- input
+ /** Scroll the pane by `lines` towards older output (negative: newer). */
+ const scrollBy = useCallback(
+ (lines: number) => {
+ const term = getTerminal();
+ if (!term || lines === 0) return;
+ if (appOwnsScreen(term)) {
+ const notches = notchesFor(lines);
+ relayNotches(
+ hostRef.current,
+ notches > 0 ? -1 : 1,
+ Math.abs(notches),
+ );
+ return;
+ }
+ term.scrollLines?.(-lines);
+ },
+ [getTerminal, hostRef],
+ );
+
+ /** Take the pane to `wanted` lines back from its newest output. */
+ const scrollTo = useCallback(
+ (wanted: number) => {
+ const term = getTerminal();
+ if (!term) return;
+ if (appOwnsScreen(term)) {
+ // Asked in notches, against what has actually been relayed so far —
+ // the observer above moves the count as each notch goes past.
+ scrollBy(wanted - travelledRef.current);
+ return;
+ }
+ // A terminal that owns its scrollback is told the line outright, so a
+ // fast drag cannot overshoot by however far a reading lags the pointer.
+ const base = term.buffer?.active?.baseY ?? 0;
+ term.scrollToLine?.(Math.max(0, base - Math.max(0, wanted)));
+ },
+ [getTerminal, scrollBy],
+ );
+
+ const onThumbPointerDown = useCallback(
+ (event: React.PointerEvent<HTMLDivElement>) => {
+ const track = trackRef.current;
+ if (!track || !getTerminal()) return;
+ // A drag on the thumb must not start a text selection in the terminal
+ // under it, and must not count as clicking into the pane.
+ event.preventDefault();
+ event.stopPropagation();
+
+ const height = track.clientHeight;
+ // The mapping is frozen at the grab. A travel-counted pane's claimed
+ // span grows while it is scrolled back, and a thumb measured against a
+ // span that moves underneath slides away from the hand holding it.
+ const grabbed = viewRef.current;
+ const box = thumbBox(grabbed, height);
+ const startTop = box?.topPx ?? 0;
+ const startY = event.clientY;
+ const travel = Math.max(0, height - (box?.heightPx ?? 0));
+
+ const target = event.currentTarget;
+ // Capture keeps the drag alive when the pointer leaves the thin bar —
+ // but a build without it (some test environments) still gets a working
+ // thumb from the listeners below.
+ try {
+ target.setPointerCapture(event.pointerId);
+ } catch {
+ /* no capture here — the drag survives on the listeners alone */
+ }
+ setDragging(true);
+ setHeldTopPx(startTop);
+
+ const onMove = (move: PointerEvent) => {
+ if (!Number.isFinite(move.clientY)) return;
+ const topPx = Math.min(
+ Math.max(startTop + (move.clientY - startY), 0),
+ travel,
+ );
+ setHeldTopPx(topPx);
+ scrollTo(backAtThumbTop(topPx, height, grabbed));
+ };
+ const finish = () => {
+ try {
+ target.releasePointerCapture(event.pointerId);
+ } catch {
+ /* never captured */
+ }
+ target.removeEventListener("pointermove", onMove);
+ target.removeEventListener("pointerup", finish);
+ target.removeEventListener("pointercancel", finish);
+ setDragging(false);
+ setHeldTopPx(null);
+ };
+ target.addEventListener("pointermove", onMove);
+ target.addEventListener("pointerup", finish);
+ target.addEventListener("pointercancel", finish);
+ },
+ [getTerminal, scrollTo],
+ );
+
+ // A press on the empty track pages towards the pointer, like every other
+ // scrollbar.
+ const onTrackPointerDown = useCallback(
+ (event: React.PointerEvent<HTMLDivElement>) => {
+ const track = trackRef.current;
+ const current = viewRef.current;
+ if (!track || !current) return;
+ event.preventDefault();
+ event.stopPropagation();
+ const box = track.getBoundingClientRect();
+ const geometry = thumbBox(current, box.height);
+ if (!geometry) return;
+ const page = Math.max(1, current.rows - 1);
+ const towardsNewer = event.clientY - box.top > geometry.topPx;
+ scrollBy(towardsNewer ? -page : page);
+ },
+ [scrollBy],
+ );
+
+ // Wheel over the bar: forwarded to the terminal untouched, so the strip of
+ // pixels the bar occupies scrolls exactly like every other part of the
+ // pane. The bar itself has no wheel behaviour at all.
+ const onTrackWheel = useCallback(
+ (event: React.WheelEvent<HTMLDivElement>) => {
+ const screen =
+ hostRef.current?.querySelector<HTMLElement>(".xterm-screen");
+ if (!screen || typeof WheelEvent === "undefined") return;
+ screen.dispatchEvent(
+ new WheelEvent("wheel", {
+ bubbles: true,
+ cancelable: true,
+ clientX: event.clientX,
+ clientY: event.clientY,
+ deltaMode: event.deltaMode,
+ deltaY: event.deltaY,
+ deltaX: event.deltaX,
+ }),
+ );
+ },
+ [hostRef],
+ );
+
+ // ---------------------------------------------------------------- render
+ const box = useMemo(() => thumbBox(view, trackPx), [view, trackPx]);
+ if (!hasScroll(view)) return null;
+
+ const light = appearance === "light";
+
+ return (
+ <div
+ ref={trackRef}
+ role="scrollbar"
+ aria-orientation="vertical"
+ aria-label={`Scroll ${name}`}
+ aria-valuemin={0}
+ aria-valuemax={view?.above ?? 0}
+ aria-valuenow={(view?.above ?? 0) - (view?.back ?? 0)}
+ data-testid={`pane-scrollbar-${name}`}
+ data-shown={shown ? "true" : "false"}
+ data-kind={view?.kind}
+ onPointerDown={onTrackPointerDown}
+ onWheel={onTrackWheel}
+ onMouseDown={(event) => event.stopPropagation()}
+ className={cn(
+ "absolute bottom-1 top-1 z-10 w-[9px] rounded-full transition-opacity duration-150",
+ shown ? "opacity-100" : "pointer-events-none opacity-0",
+ )}
+ style={{
+ right: 2,
+ background: shown
+ ? light
+ ? "rgba(0,0,0,0.06)"
+ : "rgba(255,255,255,0.07)"
+ : "transparent",
+ }}
+ >
+ {box && (
+ <div
+ data-testid={`pane-scrollbar-thumb-${name}`}
+ onPointerDown={onThumbPointerDown}
+ className={cn(
+ "absolute left-0 w-full rounded-full",
+ dragging ? "cursor-grabbing" : "cursor-grab transition-[top]",
+ )}
+ style={{
+ top: heldTopPx ?? box.topPx,
+ height: box.heightPx,
+ background: `rgb(var(--jarvis-yellow) / ${dragging ? 0.95 : 0.6})`,
+ transitionDuration: dragging ? undefined : "80ms",
+ }}
+ />
+ )}
+ </div>
+ );
+}
+
+function sameView(a: ScrollView | null, b: ScrollView | null): boolean {
+ if (a === b) return true;
+ if (!a || !b) return false;
+ return (
+ a.kind === b.kind &&
+ a.above === b.above &&
+ a.back === b.back &&
+ a.rows === b.rows
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.test.ts b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.test.ts
new file mode 100644
index 0000000000..00eb6548c5
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.test.ts
@@ -0,0 +1,124 @@
+import { describe, expect, it } from "vitest";
+import {
+ backAtThumbTop,
+ countWheel,
+ exactView,
+ hasScroll,
+ LINES_PER_NOTCH,
+ MAX_NOTCHES_PER_STEP,
+ MIN_THUMB_PX,
+ notchesFor,
+ thumbBox,
+ travelView,
+} from "./scrollbarModel";
+
+describe("exactView", () => {
+ it("reads a scrolled-back terminal off its own numbers", () => {
+ // 1000 lines, 24 on screen, viewport 100 lines above the newest screen.
+ const view = exactView(1000, 976, 876, 24);
+ expect(view).toEqual({ kind: "exact", above: 976, back: 100, rows: 24 });
+ });
+
+ it("clamps a viewport reading that ran past either end", () => {
+ expect(exactView(1000, 976, 1200, 24).back).toBe(0);
+ expect(exactView(1000, 976, -50, 24).back).toBe(976);
+ });
+
+ it("treats a garbage field as the safe end, not a crash", () => {
+ expect(exactView(1000, Number.NaN, 0, 24).back).toBe(0);
+ });
+});
+
+describe("travelView", () => {
+ it("claims the travelled distance plus one screen of headroom", () => {
+ expect(travelView(60, 24)).toEqual({
+ kind: "travel",
+ above: 84,
+ back: 60,
+ rows: 24,
+ });
+ });
+
+ it("never stands behind the live end", () => {
+ expect(travelView(-5, 24).back).toBe(0);
+ });
+});
+
+describe("hasScroll", () => {
+ it("says no for an unscrollable or missing view", () => {
+ expect(hasScroll(null)).toBe(false);
+ expect(hasScroll(exactView(24, 0, 0, 24))).toBe(false);
+ });
+
+ it("says yes the moment there is history above the screen", () => {
+ expect(hasScroll(exactView(25, 1, 1, 24))).toBe(true);
+ expect(hasScroll(travelView(0, 24))).toBe(true);
+ });
+});
+
+describe("thumbBox", () => {
+ it("rests the thumb at the very bottom on the newest output", () => {
+ const box = thumbBox(exactView(1000, 976, 976, 24), 300)!;
+ expect(box.topPx + box.heightPx).toBe(300);
+ });
+
+ it("parks the thumb at the top of a fully scrolled-back pane", () => {
+ expect(thumbBox(exactView(1000, 976, 0, 24), 300)!.topPx).toBe(0);
+ });
+
+ it("keeps the thumb graspable however long the history grows", () => {
+ expect(thumbBox(exactView(100000, 99976, 99976, 24), 300)!.heightPx).toBe(
+ MIN_THUMB_PX,
+ );
+ });
+
+ it("draws nothing without a view or a measured track", () => {
+ expect(thumbBox(null, 300)).toBeNull();
+ expect(thumbBox(exactView(1000, 976, 0, 24), 0)).toBeNull();
+ });
+});
+
+describe("backAtThumbTop", () => {
+ it("round-trips the position the thumb is drawn at", () => {
+ const view = exactView(1000, 976, 776, 24);
+ const box = thumbBox(view, 300)!;
+ expect(backAtThumbTop(box.topPx, 300, view)).toBeCloseTo(view.back, -1);
+ });
+
+ it("maps the track's ends to the history's ends", () => {
+ const view = exactView(1000, 976, 776, 24);
+ expect(backAtThumbTop(0, 300, view)).toBe(976);
+ expect(backAtThumbTop(10000, 300, view)).toBe(0);
+ });
+});
+
+describe("notchesFor", () => {
+ it("converts lines to whole notches", () => {
+ expect(notchesFor(LINES_PER_NOTCH * 4)).toBe(4);
+ expect(notchesFor(-LINES_PER_NOTCH * 4)).toBe(-4);
+ expect(notchesFor(LINES_PER_NOTCH - 1)).toBe(0);
+ });
+
+ it("caps a single step so a fast drag cannot flood the pty", () => {
+ expect(notchesFor(1000000)).toBe(MAX_NOTCHES_PER_STEP);
+ expect(notchesFor(-1000000)).toBe(-MAX_NOTCHES_PER_STEP);
+ });
+});
+
+describe("countWheel", () => {
+ it("counts a turn away from the hand as travelling back", () => {
+ expect(countWheel(0, -1)).toBe(LINES_PER_NOTCH);
+ expect(countWheel(LINES_PER_NOTCH, 1)).toBe(0);
+ });
+
+ it("re-anchors at zero however far past the live end the wheel turns", () => {
+ let travelled = countWheel(0, -1);
+ for (let i = 0; i < 10; i += 1) travelled = countWheel(travelled, 1);
+ expect(travelled).toBe(0);
+ });
+
+ it("ignores a turn that moved nothing", () => {
+ expect(countWheel(6, 0)).toBe(6);
+ expect(countWheel(6, Number.NaN)).toBe(6);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.ts b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.ts
new file mode 100644
index 0000000000..d984e4f3dc
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.ts
@@ -0,0 +1,160 @@
+/**
+ * The arithmetic behind a pane's drag scrollbar — no DOM, no xterm, no timers.
+ *
+ * A pane runs one of two kinds of program, and the bar has to be honest about
+ * which one it is standing on:
+ *
+ * * **`exact`** — the terminal owns the history. A CLI that prints line by
+ * line (Codex, a plain shell) leaves everything in xterm's scrollback, and
+ * every number here is read straight off that buffer. The thumb is a map.
+ * * **`travel`** — the application owns the screen. A full-screen CLI
+ * (Claude Code takes the alternate buffer and the mouse within milliseconds
+ * of starting) keeps its transcript in its own process, where nothing about
+ * it can be observed from the outside. The only true statements available
+ * are "you are at the live end" and "you have scrolled N lines away from
+ * it", so that is all the thumb says: it rests at the bottom on the newest
+ * output, climbs with the distance travelled, and always leaves one
+ * screenful of assumed headroom so it never claims a top nobody verified.
+ * Whenever the user returns to the live end the count re-anchors at zero,
+ * so the one position that matters is always right.
+ *
+ * An earlier generation of this feature tried to MEASURE the second kind by
+ * nudging the application and comparing screens, and every unreadable screen
+ * came out as "nothing to scroll". Nothing in this module measures anything.
+ */
+
+/** Lines one relayed wheel notch moves a full-screen CLI (measured: ~3). */
+export const LINES_PER_NOTCH = 3;
+
+/** A thumb shorter than this cannot be grabbed in a tall pane. */
+export const MIN_THUMB_PX = 24;
+
+/**
+ * The most notches one drag step may relay at once.
+ *
+ * A fast drag across a long history asks for hundreds of lines in a single
+ * pointer move. The application answers each notch individually, so a burst
+ * without a ceiling floods the pty with mouse reports it will spend seconds
+ * working through — long after the hand has stopped. The next move sends the
+ * remainder anyway, because each step is computed against what has actually
+ * been relayed so far.
+ */
+export const MAX_NOTCHES_PER_STEP = 90;
+
+/** What a pane can scroll right now, in lines. */
+export interface ScrollView {
+ /** How the numbers were obtained — see the file header. */
+ kind: "exact" | "travel";
+ /** Lines of history above the current screen. */
+ above: number;
+ /** Lines the view stands back from the live end; 0 = newest output. */
+ back: number;
+ /** Lines on screen at once. */
+ rows: number;
+}
+
+/** Thumb box inside a track of known height, in px from the track's top. */
+export interface ThumbBox {
+ topPx: number;
+ heightPx: number;
+}
+
+/**
+ * Clamp with a hard rule about garbage: these values come from pointer
+ * coordinates and third-party terminal fields, and a single NaN that gets
+ * through moves a pane to nowhere. Anything non-finite becomes the low bound.
+ */
+function clamp(value: number, low: number, high: number): number {
+ if (!Number.isFinite(value)) return low;
+ return value < low ? low : value > high ? high : value;
+}
+
+/**
+ * The view of a pane whose terminal owns the scrollback — xterm's own numbers.
+ *
+ * `length` is the buffer's total line count, `baseY` the top line of the
+ * newest screen, `viewportY` the top line currently shown.
+ */
+export function exactView(
+ length: number,
+ baseY: number,
+ viewportY: number,
+ rows: number,
+): ScrollView {
+ const above = Math.max(0, length - rows);
+ return {
+ kind: "exact",
+ above,
+ back: clamp(baseY - viewportY, 0, above),
+ rows,
+ };
+}
+
+/**
+ * The view of a pane whose application owns the screen: the distance
+ * travelled from the live end, plus one screenful of assumed headroom.
+ */
+export function travelView(travelled: number, rows: number): ScrollView {
+ const back = Math.max(0, Math.round(travelled));
+ return { kind: "travel", above: back + rows, back, rows };
+}
+
+/** Is there anywhere for this pane to go? */
+export function hasScroll(view: ScrollView | null): boolean {
+ return Boolean(view && view.above > 0 && view.rows > 0);
+}
+
+/** Where the thumb sits in a `trackPx`-tall track; null when there is no bar. */
+export function thumbBox(
+ view: ScrollView | null,
+ trackPx: number,
+): ThumbBox | null {
+ if (!view || !hasScroll(view) || trackPx <= 0) return null;
+ const total = view.above + view.rows;
+ const heightPx = clamp(
+ Math.round((trackPx * view.rows) / total),
+ Math.min(MIN_THUMB_PX, trackPx),
+ trackPx,
+ );
+ // 0 back = live end = thumb at the very bottom of the track.
+ const away = clamp(view.back / view.above, 0, 1);
+ return { heightPx, topPx: Math.round((trackPx - heightPx) * (1 - away)) };
+}
+
+/** How far back a thumb whose top edge is at `topPx` is asking to be. */
+export function backAtThumbTop(
+ topPx: number,
+ trackPx: number,
+ view: ScrollView | null,
+): number {
+ const box = thumbBox(view, trackPx);
+ if (!box || !view) return 0;
+ const travel = trackPx - box.heightPx;
+ if (travel <= 0) return view.back;
+ const away = 1 - clamp(topPx / travel, 0, 1);
+ return Math.round(away * view.above);
+}
+
+/**
+ * Whole notches that carry an application `lines` further back (negative:
+ * towards the live end), capped per step — see {@link MAX_NOTCHES_PER_STEP}.
+ */
+export function notchesFor(lines: number): number {
+ const whole = Math.trunc(lines / LINES_PER_NOTCH);
+ return clamp(whole, -MAX_NOTCHES_PER_STEP, MAX_NOTCHES_PER_STEP);
+}
+
+/**
+ * The travel count after one observed wheel event.
+ *
+ * Counted per event rather than per delta pixel: the application scrolls per
+ * received notch, and both a gentle and a violent turn of a real wheel arrive
+ * as one event per notch. The count can only be an estimate either way — what
+ * keeps it honest is the clamp at zero, where it re-anchors against the one
+ * position the application also stops at.
+ */
+export function countWheel(travelled: number, deltaY: number): number {
+ if (!Number.isFinite(deltaY) || deltaY === 0) return travelled;
+ const step = deltaY < 0 ? LINES_PER_NOTCH : -LINES_PER_NOTCH;
+ return Math.max(0, travelled + step);
+}
diff --git a/jarvis/ui/web/frontend/src/index.css b/jarvis/ui/web/frontend/src/index.css
index 81fc897fe3..f50c1afee0 100644
--- a/jarvis/ui/web/frontend/src/index.css
+++ b/jarvis/ui/web/frontend/src/index.css
@@ -66,13 +66,13 @@
display: none;
}
-/* Agentic IDE panes carry NO scroll track at all — maintainer's call, after a
- custom one was built, rebuilt and removed again. The native bar cannot stand
- in for it: it is permanently on screen down the side of every pane in the
- grid, 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 and keeps
- its history in its own process. Scrolling is the wheel, which reaches
- whichever of the two owns the screen.
+/* Agentic IDE panes never show the BROWSER's scroll track. It is permanently
+ on screen down the side of every pane in the grid, 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 and keeps its history in its own
+ process. The pane draws its own hover-only bar instead (PaneScrollbar),
+ which can also drive a full-screen CLI; the wheel keeps reaching whichever
+ side owns the screen either way.
Hiding it here rather than switching the viewport to `overflow: hidden` is
deliberate: xterm still needs a scrollable viewport for the wheel itself.