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.

fix(agentic-ide): stop the pane scrollbar reading one CLI's words

Ruben Lütke5d16e7db23aa
diff --git a/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx
index 5ff21d13e4..f8c12351da 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.test.tsx
@@ -3,7 +3,7 @@ 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, SETTLE_MS } from "./scrollbarModel";
+import { ASSUMED_SCREENS, LINES_PER_NOTCH, SETTLE_MS } from "./scrollbarModel";
const REGION = { top: 0, bottom: 300, left: 0, right: 400 };
const TRACK_PX = 300;
@@ -20,7 +20,7 @@ interface TermState {
viewportY: number;
baseY: number;
mouseTrackingMode: string;
- /** What the screen shows, for the overlay anchor; row index → text. */
+ /** What the screen shows, for the movement fingerprint; row index → text. */
lines: string[];
}
@@ -264,11 +264,31 @@ describe("PaneScrollbar", () => {
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));
+ // A full pull up asks for the whole assumed span, in notches — more than
+ // one step may relay, so the release has to carry the remainder.
+ expect(seen.length).toBe(
+ Math.trunc((24 * ASSUMED_SCREENS) / LINES_PER_NOTCH),
+ );
expect(new Set(seen)).toEqual(new Set([-1]));
});
+ it("counts a real wheel turn by the rows it covers, not by the event", async () => {
+ // One turn of a physical wheel is ~100 px, which xterm hands the CLI as
+ // one report PER ROW. Counting the turn as a single notch under-counted
+ // every real scroll and parked the thumb near a bottom it had left.
+ render(<Harness term={appTerminal(24).term} />);
+ reachThePane();
+
+ // The staged pane is 300 px over 24 rows: 100 px is eight rows.
+ fireEvent.wheel(host(), { deltaY: -100, deltaMode: 0 });
+
+ await waitFor(() =>
+ expect(bar()!.getAttribute("aria-valuemax")).toBe(
+ String(8 * LINES_PER_NOTCH + 24 * ASSUMED_SCREENS),
+ ),
+ );
+ });
+
it("pages towards a press on the empty part of the track", () => {
const { term } = fakeTerminal();
render(<Harness term={term} />);
@@ -326,44 +346,79 @@ describe("PaneScrollbar", () => {
});
/*
- * The reported bug, at the level the user met it: the pane stood at its
- * newest output while the thumb hung mid-track, because notches the CLI had
- * silently ignored at the transcript's top stayed counted. The CLI's own
- * scrolled-back overlay is the anchor: the moment it leaves the screen, the
- * thumb comes home — no wheel traffic required.
+ * The reported bug, at the level the user met it (2026-07-29): the pane
+ * showed the very TOP of a long transcript while the thumb sat pinned at
+ * the very bottom of the track, and the bar could only ever scroll up.
+ *
+ * The count was being snapped to zero on every repaint that carried no
+ * `Jump to bottom` — a string this CLI replaces with `N new messages` the
+ * moment output arrives while the view is parked, and one no other CLI
+ * paints at all. Nothing the screen SAYS may move the count now.
*/
- it("snaps home the moment the CLI's scrolled-back overlay disappears", async () => {
+ it("holds its ground while a scrolled-back CLI keeps repainting", async () => {
const { state, term, fire } = appTerminal(24);
state.lines = Array.from({ length: 24 }, (_, i) => `transcript row ${i}`);
- state.lines[20] = " 86 Jump to bottom (ctrl+End) ↓";
render(<Harness term={term} />);
- // A pile of wheel-ups, some of which the CLI ignored at its top.
- for (let i = 0; i < 40; i += 1) fireEvent.wheel(host(), { deltaY: -1 });
+ for (let i = 0; i < 10; i += 1) fireEvent.wheel(host(), { deltaY: -1 });
reachThePane();
- expect(thumbTop() + thumbHeight()).toBeLessThan(TRACK_PX);
-
- // The CLI returns to the live end and erases its overlay.
- state.lines[20] = "";
- fire("render");
+ // The reads are coalesced into frames, so let one pass before taking the
+ // position this test is about to hold the bar to.
+ await act(
+ () =>
+ new Promise<void>((resolve) => requestAnimationFrame(() => resolve())),
+ );
+ const parked = thumbTop();
+ expect(parked + thumbHeight()).toBeLessThan(TRACK_PX);
+
+ // The agent talks on while the user reads: twenty repaints, including the
+ // overlay swap that used to be read as "you are at the newest output".
+ for (let i = 0; i < 20; i += 1) {
+ state.lines[3] = `agent still talking ${i}`;
+ state.lines[20] = i % 2 ? " 1 new message (ctrl+End) ↓" : "";
+ fire("render");
+ // eslint-disable-next-line no-await-in-loop
+ await act(
+ () =>
+ new Promise<void>((resolve) => requestAnimationFrame(() => resolve())),
+ );
+ }
- await waitFor(() => expect(thumbTop() + thumbHeight()).toBe(TRACK_PX));
+ expect(thumbTop()).toBe(parked);
});
- it("keeps standing away from the live end while the overlay is up", async () => {
- const { state, term } = appTerminal(24);
+ /*
+ * The live-end anchor that replaced the English string: a down the CLI has
+ * nothing left to answer with means the newest output is already on screen.
+ * Works for a CLI in any language, and for CLIs that paint no overlay.
+ */
+ it("comes home when downs stop changing the screen", async () => {
+ let clock = 2_000_000;
+ vi.spyOn(Date, "now").mockImplementation(() => clock);
+ const { state, term, fire } = appTerminal(24);
state.lines = Array.from({ length: 24 }, (_, i) => `transcript row ${i}`);
- state.lines[20] = " 12 Jump to bottom (ctrl+End) ↓";
render(<Harness term={term} />);
-
- // Enough wheel-downs to clamp any count to zero — but the CLI's screen
- // still says the view is away, and the overlay outranks the count.
- for (let i = 0; i < 10; i += 1) fireEvent.wheel(host(), { deltaY: 1 });
reachThePane();
- await waitFor(() =>
- expect(thumbTop() + thumbHeight()).toBeLessThan(TRACK_PX),
+ // Ten notches back, and the screen visibly follows: the episode moved.
+ for (let i = 0; i < 10; i += 1) fireEvent.wheel(host(), { deltaY: -1 });
+ state.lines[0] = "transcript moved";
+ fire("render");
+ await act(
+ () =>
+ new Promise<void>((resolve) =>
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
+ ),
);
+ expect(thumbTop() + thumbHeight()).toBeLessThan(TRACK_PX);
+
+ // Two notches forward that change nothing: the CLI is already showing its
+ // newest output, however far the count still claims to be from it.
+ for (let i = 0; i < 2; i += 1) fireEvent.wheel(host(), { deltaY: 1 });
+ clock += SETTLE_MS + 100;
+ fire("render");
+
+ await waitFor(() => expect(thumbTop() + thumbHeight()).toBe(TRACK_PX));
});
/*
@@ -377,7 +432,6 @@ describe("PaneScrollbar", () => {
vi.spyOn(Date, "now").mockImplementation(() => clock);
const { state, term, fire } = appTerminal(24);
state.lines = Array.from({ length: 24 }, (_, i) => `transcript row ${i}`);
- state.lines[20] = " 12 Jump to bottom (ctrl+End) ↓";
render(<Harness term={term} />);
reachThePane();
diff --git a/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx
index 5492ed7bd2..19602fd89f 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/PaneScrollbar.tsx
@@ -49,7 +49,6 @@ import {
hasScroll,
notchesFor,
screenTravel,
- SCROLLED_BACK_MARKERS,
SETTLE_MS,
thumbBox,
travelView,
@@ -65,6 +64,23 @@ const LINGER_MS = 200;
/** How long a wheel turn keeps the bar visible as a position readout. */
const FLASH_MS = 800;
+/**
+ * Rows at the bottom of a full-screen CLI's screen that repaint on their own:
+ * the input box, the spinner, a status line, a token counter. They must stay
+ * out of the fingerprint below — a spinner ticking once a frame would read as
+ * "the transcript moved" and no brake could ever engage.
+ *
+ * A count rather than a marker on purpose. The row the chrome starts at used
+ * to be found by matching one CLI's English overlay text, which is how a bar
+ * that worked for Claude Code worked for nothing else and then stopped
+ * working for Claude Code too (AP-27). Eight rows is generous for every CLI
+ * measured, and being wrong about it costs sensitivity, never correctness.
+ */
+const CHROME_ROWS = 8;
+
+/** Row height assumed when the pane cannot be measured, in px. */
+const FALLBACK_CELL_PX = 17;
+
/** True when the running application receives wheel events itself. */
function appOwnsScreen(term: Terminal | null): boolean {
if (!term) return false;
@@ -99,14 +115,14 @@ export function readScrollView(
}
/**
- * One look at an application-held pane's screen: is the scrolled-back
- * overlay up, and what does the transcript region above it say?
+ * One look at an application-held pane's screen: what does its transcript
+ * region say right now?
*
- * The overlay's row splits the screen — transcript above, the CLI's animated
- * chrome (spinner, input box, status bars) below — so the fingerprint stops
- * there: a spinner repainting every frame must not read as "the transcript
- * moved". Returns null when the buffer cannot be read; the caller keeps its
- * estimate rather than inventing one.
+ * Only whether this changes between two looks is ever used, so the content is
+ * never interpreted — see ./scrollbarModel on why reading a CLI's words was
+ * the bug rather than the fix. The bottom {@link CHROME_ROWS} rows are left
+ * out because they animate on their own. Returns null when the buffer cannot
+ * be read; the caller keeps its estimate rather than inventing one.
*/
export function readScreen(term: Terminal | null): ScreenGlance | null {
const buffer = term?.buffer?.active;
@@ -116,21 +132,54 @@ export function readScreen(term: Terminal | null): ScreenGlance | null {
}
try {
const text: string[] = [];
- for (let y = 0; y < rows; y += 1) {
+ for (let y = 0; y < Math.max(1, rows - CHROME_ROWS); y += 1) {
text.push(buffer.getLine(y)?.translateToString(true) ?? "");
}
- const markerRow = text.findIndex((row) =>
- SCROLLED_BACK_MARKERS.some((marker) => marker.test(row)),
- );
- return {
- markerRow,
- fingerprint: markerRow > 0 ? text.slice(0, markerRow).join("\n") : "",
- };
+ return { fingerprint: text.join("\n") };
} catch {
return null;
}
}
+/**
+ * How many mouse reports xterm will send the application for this wheel
+ * event, signed the way `deltaY` is.
+ *
+ * The count of where a full-screen CLI's pane stands is only as good as this
+ * conversion, and taking every DOM wheel event for a single notch — as this
+ * did — under-counted a real mouse wheel roughly five-fold: one turn of a
+ * physical wheel is ~100 px, which xterm turns into one report PER ROW it
+ * covers, each of which moves the application again. The pane drifted further
+ * behind the truth with every turn, and the thumb sat near the bottom of a
+ * transcript the user had scrolled minutes into.
+ *
+ * Mirrors xterm's own `getLinesScrolled`: line and page deltas are already in
+ * the terminal's units, a pixel delta is divided by the measured row height.
+ */
+export function wheelNotches(
+ event: WheelEvent,
+ host: HTMLElement | null,
+ rows: number,
+): number {
+ const magnitude = Math.abs(event.deltaY);
+ if (!Number.isFinite(magnitude) || magnitude === 0) return 0;
+ let lines: number;
+ if (event.deltaMode === 1) {
+ lines = magnitude;
+ } else if (event.deltaMode === 2) {
+ lines = magnitude * Math.max(1, rows);
+ } else {
+ const screen = host?.querySelector<HTMLElement>(".xterm-screen");
+ const height = screen?.clientHeight ?? 0;
+ const cell = rows > 0 && height > 0 ? height / rows : FALLBACK_CELL_PX;
+ lines = magnitude / Math.max(1, cell);
+ }
+ // A turn too small for a whole row still moved the application by one: xterm
+ // carries the remainder over, and dropping it here would lose the scroll.
+ const whole = Math.max(1, Math.round(lines));
+ return event.deltaY < 0 ? -whole : whole;
+}
+
/**
* Hand `count` wheel notches to whatever runs in `host` (direction -1 is
* towards older output, matching a wheel turned away from the hand).
@@ -197,8 +246,8 @@ export function PaneScrollbar({
// Where a full-screen CLI's pane stands, counted off the wheel traffic —
// the user's own turns and this bar's relays alike, since both pass the
- // same observer below — and reconciled against the screen's own anchors
- // (see ./scrollbarModel, "the three anchors").
+ // same observer below — and reconciled against whether the screen moved
+ // (see ./scrollbarModel, "the two brakes").
const travelRef = useRef<Travel>(freshTravel());
// 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
@@ -255,10 +304,11 @@ export function PaneScrollbar({
let timer: number | undefined;
const onWheel = (event: WheelEvent) => {
if (event.deltaY === 0) return;
- if (appOwnsScreen(getTerminal())) {
+ const term = getTerminal();
+ if (appOwnsScreen(term)) {
travelRef.current = wheelTravel(
travelRef.current,
- event.deltaY,
+ wheelNotches(event, host, term?.rows ?? 0),
Date.now(),
);
}
@@ -298,17 +348,19 @@ export function PaneScrollbar({
}
lastKindRef.current = kind;
if (appHeld) {
- // Reconcile the count with the screen's own anchors — the overlay
- // and the saturation brake (see ./scrollbarModel).
+ // Reconcile the count against whether the screen moved — the two
+ // brakes that replaced the old overlay anchor (see ./scrollbarModel).
travelRef.current = screenTravel(
travelRef.current,
readScreen(term),
Date.now(),
);
- // Unconfirmed ups need a second look once the pty has had its say,
- // even if no event arrives to prompt one.
+ // Unconfirmed notches need a second look once the pty has had its
+ // say, even if no event arrives to prompt one. This is the ONLY thing
+ // that ever brings a pane home again, so it must cover both
+ // directions: an unanswered down is what proves the live end.
if (settleTimer !== undefined) window.clearTimeout(settleTimer);
- if (travelRef.current.pendingUp > 0) {
+ if (travelRef.current.pendingUp > 0 || travelRef.current.pendingDown > 0) {
settleTimer = window.setTimeout(schedule, SETTLE_MS + 50);
}
}
@@ -431,16 +483,30 @@ export function PaneScrollbar({
setDragging(true);
setHeldTopPx(startTop);
+ let lastTopPx = 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);
+ lastTopPx = topPx;
+ // A coordinate that cannot be worked with leaves the thumb where the
+ // count says it is, rather than writing NaN into the layout.
+ setHeldTopPx(Number.isFinite(topPx) ? topPx : null);
scrollTo(backAtThumbTop(topPx, height, grabbed));
};
const finish = () => {
+ // One last ask at the position the thumb was let go of. A fast pull
+ // across a long history wants more notches than a single step may
+ // relay (MAX_NOTCHES_PER_STEP), and the remainder normally rides on
+ // the next pointer move — a hand that stops at the end of the track
+ // never sends one, and the pane used to stay short of where it was
+ // dropped with no way to tell why. Not while the top brake holds:
+ // there a step means one probe notch, and this would be a second.
+ if (!travelRef.current.saturated) {
+ scrollTo(backAtThumbTop(lastTopPx, height, grabbed));
+ }
try {
target.releasePointerCapture(event.pointerId);
} catch {
diff --git a/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.test.ts b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.test.ts
index 0ffd76004c..d3c565e036 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.test.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import {
+ ASSUMED_SCREENS,
backAtThumbTop,
exactView,
freshTravel,
@@ -34,15 +35,24 @@ describe("exactView", () => {
});
describe("travelView", () => {
- it("claims the travelled distance plus one screen of headroom", () => {
+ it("claims the travelled distance plus the assumed headroom", () => {
expect(travelView(60, 24)).toEqual({
kind: "travel",
- above: 84,
+ above: 60 + 24 * ASSUMED_SCREENS,
back: 60,
rows: 24,
});
});
+ it("draws a graspable thumb, not half the track, at the live end", () => {
+ // The maintainer's report: on a pane at its newest output the thumb filled
+ // half the bar, which claims a two-screen history no agent ever has.
+ const box = thumbBox(travelView(0, 24), 300)!;
+ expect(box.heightPx).toBeLessThan(100);
+ expect(box.heightPx).toBeGreaterThanOrEqual(MIN_THUMB_PX);
+ expect(box.topPx + box.heightPx).toBe(300);
+ });
+
it("never stands behind the live end", () => {
expect(travelView(-5, 24).back).toBe(0);
});
@@ -124,6 +134,23 @@ describe("wheelTravel", () => {
expect(wheelTravel(t, 1, 1001).travelled).toBe(0);
});
+ it("counts every report of one turn, not the turn", () => {
+ // A physical wheel covers several rows, and xterm sends one report per
+ // row — taking the whole turn for a single notch under-counted every
+ // real scroll five-fold and left the thumb near a bottom it had left.
+ const t = wheelTravel(freshTravel(), -6, 1000);
+ expect(t.travelled).toBe(6 * LINES_PER_NOTCH);
+ expect(wheelTravel(t, 6, 1001).travelled).toBe(0);
+ });
+
+ it("holds a down pending, so an unanswered one can prove the live end", () => {
+ const t = wheelTravel({ ...freshTravel(), travelled: 30 }, 2, 1000);
+ expect(t.pendingDown).toBe(2 * LINES_PER_NOTCH);
+ expect(t.lastDownAt).toBe(1000);
+ // An up in the other direction retracts that claim.
+ expect(wheelTravel(t, -1, 1001).pendingDown).toBe(0);
+ });
+
it("clamps at zero however far past the live end the wheel turns", () => {
let t = wheelTravel(freshTravel(), -1, 0);
for (let i = 0; i < 10; i += 1) t = wheelTravel(t, 1, i);
@@ -150,125 +177,129 @@ describe("wheelTravel", () => {
});
describe("screenTravel", () => {
- const seen = (travelled: number): Travel => ({
+ const standing = (travelled: number): Travel => ({
...freshTravel(),
travelled,
- markerSeen: true,
fingerprint: "same",
});
- it("learns that this application paints a scrolled-back overlay", () => {
- const t = screenTravel(
- freshTravel(),
- { markerRow: 22, fingerprint: "a" },
- 0,
- );
- expect(t.markerSeen).toBe(true);
- });
-
- it("snaps to the live end the moment the overlay disappears", () => {
- // The user's reported bug: at the newest output with the thumb mid-track.
- const t = screenTravel(seen(300), { markerRow: -1, fingerprint: "" }, 0);
- expect(t.travelled).toBe(0);
- expect(t.saturated).toBe(false);
- });
-
- it("does not treat a missing overlay as an anchor before one was ever seen", () => {
- const t: Travel = { ...freshTravel(), travelled: 60 };
- expect(
- screenTravel(t, { markerRow: -1, fingerprint: "" }, 0).travelled,
- ).toBe(60);
- });
-
it("keeps the estimate when the screen cannot be read", () => {
- const t = seen(60);
+ const t = standing(60);
expect(screenTravel(t, null, 0)).toBe(t);
});
- it("confirms pending ups when the transcript moved", () => {
- const t: Travel = { ...seen(60), pendingUp: 30, lastUpAt: 0 };
- const next = screenTravel(t, { markerRow: 22, fingerprint: "moved" }, 1);
+ it("confirms pending notches when the transcript moved", () => {
+ const t: Travel = {
+ ...standing(60),
+ pendingUp: 30,
+ lastUpAt: 0,
+ pendingDown: 9,
+ lastDownAt: 0,
+ };
+ const next = screenTravel(t, { fingerprint: "moved" }, 1);
expect(next.travelled).toBe(60);
expect(next.pendingUp).toBe(0);
+ expect(next.pendingDown).toBe(0);
expect(next.saturated).toBe(false);
});
it("un-counts ups the application ignored at the top, and measures it", () => {
- // The user's other reported bug: scrolling past a top nobody can see.
- const t: Travel = { ...seen(90), pendingUp: 30, lastUpAt: 0, moved: true };
- const next = screenTravel(
- t,
- { markerRow: 22, fingerprint: "same" },
- SETTLE_MS,
- );
+ // Scrolling past a top nobody can see: the notches emit no bytes at all,
+ // so only the unchanged screen can tell.
+ const t: Travel = {
+ ...standing(90),
+ pendingUp: 30,
+ lastUpAt: 0,
+ moved: true,
+ };
+ const next = screenTravel(t, { fingerprint: "same" }, SETTLE_MS);
expect(next.travelled).toBe(60);
expect(next.saturated).toBe(true);
expect(next.ceiling).toBe(60);
});
+ it("re-anchors at the live end when downs stop changing the screen", () => {
+ // The word-agnostic replacement for one CLI's English overlay: a down the
+ // application had nothing left to answer with means the newest output is
+ // already on screen, in whatever language it happens to be printed.
+ const t: Travel = {
+ ...standing(42),
+ pendingDown: 9,
+ lastDownAt: 0,
+ moved: true,
+ };
+ const next = screenTravel(t, { fingerprint: "same" }, SETTLE_MS);
+ expect(next.travelled).toBe(0);
+ expect(next.pendingDown).toBe(0);
+ // The episode closes: the next one has to prove movement afresh.
+ expect(next.moved).toBe(false);
+ });
+
it("waits for the pty before judging an unmoved screen", () => {
- const t: Travel = { ...seen(90), pendingUp: 30, lastUpAt: 0, moved: true };
- const next = screenTravel(
- t,
- { markerRow: 22, fingerprint: "same" },
- SETTLE_MS - 1,
+ const up: Travel = {
+ ...standing(90),
+ pendingUp: 30,
+ lastUpAt: 0,
+ moved: true,
+ };
+ expect(screenTravel(up, { fingerprint: "same" }, SETTLE_MS - 1)).toBe(up);
+ const down: Travel = {
+ ...standing(90),
+ pendingDown: 9,
+ lastDownAt: 0,
+ moved: true,
+ };
+ expect(screenTravel(down, { fingerprint: "same" }, SETTLE_MS - 1)).toBe(
+ down,
);
- expect(next.travelled).toBe(90);
- expect(next.saturated).toBe(false);
});
it("never calls an episode that has not moved a top", () => {
// The pinned-thumb deadlock: a busy CLI leaves the screen unchanged far
// past the settle window without a single notch having reached the top.
// The ups still leave the count, but no brake and no false ceiling.
- const t: Travel = { ...seen(30), pendingUp: 30, lastUpAt: 0 };
- const next = screenTravel(
- t,
- { markerRow: 22, fingerprint: "same" },
- SETTLE_MS,
- );
- expect(next.travelled).toBe(3);
+ const t: Travel = { ...standing(30), pendingUp: 30, lastUpAt: 0 };
+ const next = screenTravel(t, { fingerprint: "same" }, SETTLE_MS);
+ expect(next.travelled).toBe(0);
expect(next.saturated).toBe(false);
expect(next.ceiling).toBeNull();
});
+ it("never calls an episode that has not moved the live end either", () => {
+ // Same deadlock, mirrored: a busy CLI must not be able to claim the pane
+ // is at its newest output while the user is reading its history.
+ const t: Travel = { ...standing(60), pendingDown: 9, lastDownAt: 0 };
+ const next = screenTravel(t, { fingerprint: "same" }, SETTLE_MS);
+ expect(next.travelled).toBe(60);
+ expect(next.pendingDown).toBe(0);
+ });
+
it("a fingerprint CHANGE proves movement; the first look only records", () => {
- const first = screenTravel(
- freshTravel(),
- { markerRow: 22, fingerprint: "a" },
- 0,
- );
+ const first = screenTravel(freshTravel(), { fingerprint: "a" }, 0);
expect(first.moved).toBe(false);
- const second = screenTravel(
- first,
- { markerRow: 22, fingerprint: "b" },
- 1,
- );
+ const second = screenTravel(first, { fingerprint: "b" }, 1);
expect(second.moved).toBe(true);
});
- it("closing the episode at the live end demands fresh proof next time", () => {
- const t: Travel = { ...seen(60), moved: true };
- const home = screenTravel(t, { markerRow: -1, fingerprint: "" }, 0);
- expect(home.moved).toBe(false);
+ it("holds its ground while a scrolled-back pane keeps repainting", () => {
+ // The reported bug, at model level: the count used to snap to zero on
+ // every repaint that carried no known overlay string, so a pane parked at
+ // the TOP of its transcript drew its thumb at the very bottom.
+ let t: Travel = { ...standing(300), moved: true };
+ for (let i = 0; i < 20; i += 1) {
+ t = screenTravel(t, { fingerprint: `agent still talking ${i}` }, i);
+ }
+ expect(t.travelled).toBe(300);
});
it("keeps the ceiling graspable however small the measured top", () => {
- const t: Travel = { ...seen(3), pendingUp: 3, lastUpAt: 0, moved: true };
- const next = screenTravel(
- t,
- { markerRow: 22, fingerprint: "same" },
- SETTLE_MS,
- );
+ const t: Travel = {
+ ...standing(3),
+ pendingUp: 3,
+ lastUpAt: 0,
+ moved: true,
+ };
+ const next = screenTravel(t, { fingerprint: "same" }, SETTLE_MS);
expect(next.ceiling).toBeGreaterThanOrEqual(LINES_PER_NOTCH);
});
-
- it("floors the count while the overlay says the view is away", () => {
- const t = screenTravel(
- { ...seen(0), fingerprint: "a" },
- { markerRow: 22, fingerprint: "a" },
- 0,
- );
- expect(t.travelled).toBe(LINES_PER_NOTCH);
- });
});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.ts b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.ts
index c703984c58..929b63dc42 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/scrollbarModel.ts
@@ -8,44 +8,46 @@
* 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.
+ * (Claude Code, Gemini, OpenCode and Kimi all take 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
+ * assumes {@link ASSUMED_SCREENS} screens of history until the top has
+ * actually been measured, so there is always somewhere left to go.
*
- * ## The three anchors that keep the count honest
+ * ## Nothing here reads the application's words
*
- * Pure counting drifts, and the drift was visible in the product within a day:
- * notches relayed at the transcript's TOP are silently ignored by the CLI but
- * were still counted, so the claimed position inflated — and after scrolling
- * back down the thumb hung mid-track at the live end. Probed against the real
- * CLI (2026-07-28, hidden pty): an ignored notch emits ZERO bytes, so the
- * stream cannot tell. What CAN tell, and what the count is anchored to:
+ * An earlier generation anchored "you are at the live end" on Claude Code's
+ * `Jump to bottom (ctrl+End)` overlay: absence of that string was taken as
+ * proof of the live end. It broke twice over. Claude Code paints a SECOND
+ * overlay once output arrives while the view is parked (`1 new message
+ * (ctrl+End)`), so the regex missed and the bar snapped to the bottom on every
+ * repaint of a pane that was in fact at the very top — and no other CLI ever
+ * paints either string, so for all of them the count was unanchored forever.
+ * That is AP-27 in a second place: a verdict gated on transcript CONTENT is a
+ * verdict that fails for every wording and every language it did not foresee.
*
- * 1. **The scrolled-back overlay.** Claude Code paints "Jump to bottom
- * (ctrl+End)" onto the screen whenever the view left the live end, and
- * erases it there. Once a pane has seen that overlay ONCE (capability
- * learned, not provider-gated), its absence is proof of "at the newest
- * output" and snaps the count to zero — the anchor that ends thumb-stuck-
- * mid-track. Its presence floors the count at one notch.
- * 2. **The saturation brake.** Up-notches whose repaint never arrives (the
- * transcript region above the overlay unchanged once the pty had time to
- * answer) were ignored by the CLI: they are un-counted, and further ups are
- * neither counted nor relayed until the screen moves again. The top stops
- * being scrollable-forever.
- * 3. **The measured ceiling.** The moment the brake engages, the total travel
- * to the top is KNOWN, and the thumb maps the real span — top means top.
+ * What replaces it are two symmetric brakes that read only whether the screen
+ * MOVED, never what it says:
*
- * An application that paints no overlay keeps the plain counted behaviour.
- * An earlier generation of this feature tried to MEASURE the second kind by
- * nudging the application and comparing screens as its ONLY source of truth,
- * and every unreadable screen came out as "nothing to scroll". The brake
- * fails the other way: judging nothing, it merely keeps the old estimate.
+ * 1. **The top brake.** Up-notches whose repaint never arrives (the transcript
+ * region unchanged once the pty had time to answer) were ignored by the
+ * application: they are un-counted, and further ups are neither counted nor
+ * relayed until the screen moves again. The top stops being scrollable
+ * forever. The total travel is then KNOWN, so the thumb maps the real span
+ * ({@link Travel.ceiling}) — top means top.
+ * 2. **The bottom brake.** Down-notches that likewise change nothing mean the
+ * newest output is already on screen: the count re-anchors at zero. This is
+ * the live-end anchor, and it works for a CLI in any language.
+ *
+ * Both brakes require having SEEN the transcript move earlier in the same
+ * scroll-back episode ({@link Travel.moved}): a busy CLI can leave the screen
+ * unchanged long past {@link SETTLE_MS} without any boundary being involved,
+ * and a verdict measured from that once pinned a pane's thumb for good.
+ * Judging nothing, a brake merely keeps the old estimate — this module fails
+ * open by design.
*/
/** Lines one relayed wheel notch moves a full-screen CLI (measured: ~3). */
@@ -62,11 +64,26 @@ export const MIN_THUMB_PX = 24;
* 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. Kept small also to bound how far a burst can overrun
- * the transcript's top before the saturation brake can see it.
+ * been relayed so far, and the drag's release sends whatever a capped burst
+ * still owes. Kept small also to bound how far a burst can overrun the
+ * transcript's top before the top brake can see it.
*/
export const MAX_NOTCHES_PER_STEP = 30;
+/**
+ * Screens of history a `travel` pane assumes above an unmeasured transcript.
+ *
+ * Nothing can be read about a full-screen CLI's history until the top has been
+ * hit, so this number alone decides how big the thumb looks on a pane at its
+ * live end. One screen made the thumb fill HALF the track — a bar that size
+ * claims the pane holds two screens in total, which no working agent ever
+ * does, and it is what the maintainer reported as "far too big". Four keeps it
+ * a fifth of the track: unmistakably a scrollbar, without inventing a history
+ * length nobody measured. Once the top HAS been reached the real span replaces
+ * it ({@link Travel.ceiling}).
+ */
+export const ASSUMED_SCREENS = 4;
+
/** What a pane can scroll right now, in lines. */
export interface ScrollView {
/** How the numbers were obtained — see the file header. */
@@ -119,10 +136,10 @@ export function exactView(
/**
* The view of a pane whose application owns the screen.
*
- * With the top never reached, the span is the distance travelled plus one
- * screenful of assumed headroom, so there is always somewhere left to go.
- * Once the top HAS been reached the total is known ({@link Travel.ceiling})
- * and the span is that measurement — the thumb can then genuinely say "top".
+ * With the top never reached, the span is the distance travelled plus the
+ * assumed headroom, so there is always somewhere left to go. Once the top HAS
+ * been reached the total is known ({@link Travel.ceiling}) and the span is
+ * that measurement — the thumb can then genuinely say "top".
*/
export function travelView(
travelled: number,
@@ -130,15 +147,18 @@ export function travelView(
ceiling: number | null = null,
): ScrollView {
const back = Math.max(0, Math.round(travelled));
- const above = ceiling === null ? back + rows : Math.max(back, ceiling);
+ const above =
+ ceiling === null
+ ? back + Math.max(1, rows) * ASSUMED_SCREENS
+ : Math.max(back, ceiling);
return { kind: "travel", above, back, rows };
}
// ---------------------------------------------------------------- travel
/**
- * How long the pty gets to answer an up-notch before an unchanged screen
- * counts as proof the notch fell off the top. The CLI answers a notch in
+ * How long the pty gets to answer a relayed notch before an unchanged screen
+ * counts as proof the notch fell off an end. The CLI answers a notch in
* 1–30 ms when idle (measured), but a CLI mid-task plus a loaded render
* loop can stretch far past that — and a wrong verdict here once pinned a
* pane's thumb to a false top (2026-07-28). Hence the generous window AND
@@ -146,39 +166,33 @@ export function travelView(
*/
export const SETTLE_MS = 500;
-/**
- * Overlays a full-screen CLI paints while its view is away from the live
- * end. Matched against the visible screen; the row that matches also splits
- * the transcript (above it) from the animated chrome (below it), which is
- * why the fingerprint in {@link screenTravel} covers only the rows above.
- */
-export const SCROLLED_BACK_MARKERS = [/Jump to bottom/i];
-
/** What a full-screen CLI's pane knows about where it stands. */
export interface Travel {
/** Best estimate of lines back from the live end. */
travelled: number;
- /** This application paints a scrolled-back overlay — learned, never assumed. */
- markerSeen: boolean;
/** Total travel measured at the transcript's top, once reached. */
ceiling: number | null;
/** Up-lines counted but not yet confirmed by a repaint. */
pendingUp: number;
/** When the newest unconfirmed up was counted. */
lastUpAt: number;
- /** The transcript region's last known content, for the brake. */
+ /** Down-lines counted but not yet confirmed by a repaint. */
+ pendingDown: number;
+ /** When the newest unconfirmed down was counted. */
+ lastDownAt: number;
+ /** The transcript region's last known content, for the brakes. */
fingerprint: string | null;
/** Ups are known to be falling off the top right now. */
saturated: boolean;
/**
* The transcript has been SEEN to move during this scroll-back episode.
*
- * The brake's precondition, and the fix for the pinned-thumb deadlock: a
+ * Both brakes' precondition, and the fix for the pinned-thumb deadlock: a
* busy CLI can leave the screen unchanged long past {@link SETTLE_MS}
- * without a single notch having fallen off the top. Genuinely reaching
- * the top requires having scrolled through content first, which repaints
+ * without a single notch having fallen off an end. Genuinely reaching a
+ * boundary requires having scrolled through content first, which repaints
* — so an episode that never moved proves latency, not a boundary, and
- * must neither saturate nor measure a ceiling.
+ * must neither saturate nor measure a ceiling nor claim the live end.
*/
moved: boolean;
}
@@ -186,10 +200,11 @@ export interface Travel {
export function freshTravel(): Travel {
return {
travelled: 0,
- markerSeen: false,
ceiling: null,
pendingUp: 0,
lastUpAt: 0,
+ pendingDown: 0,
+ lastDownAt: 0,
fingerprint: null,
saturated: false,
moved: false,
@@ -198,23 +213,38 @@ export function freshTravel(): Travel {
/** What one look at the screen saw — see {@link readScreen} in the component. */
export interface ScreenGlance {
- /** Index of the scrolled-back overlay's row, or -1 when absent. */
- markerRow: number;
- /** Content of the transcript region above the overlay ("" without one). */
+ /** Content of the transcript region, excluding the self-animating chrome. */
fingerprint: string;
}
-/** The count after one observed wheel event (real or relayed alike). */
-export function wheelTravel(travel: Travel, deltaY: number, now: number): Travel {
- if (!Number.isFinite(deltaY) || deltaY === 0) return travel;
- if (deltaY > 0) {
+/**
+ * The count after one observed wheel event, real or relayed alike.
+ *
+ * `notches` is signed the way a wheel's `deltaY` is — POSITIVE towards the
+ * live end (the hand pulled towards itself), negative into the history — and
+ * counts the mouse reports the terminal will actually send, not the DOM
+ * events. One physical wheel turn is several reports, and counting it as one
+ * was a systematic five-fold under-count of every real scroll.
+ */
+export function wheelTravel(
+ travel: Travel,
+ notches: number,
+ now: number,
+): Travel {
+ if (!Number.isFinite(notches) || Math.trunc(notches) === 0) return travel;
+ const lines = Math.abs(Math.trunc(notches)) * LINES_PER_NOTCH;
+ if (notches > 0) {
// Towards the live end: a down always has somewhere to go while the
- // count is positive, and leaving the top ends the saturation.
+ // count is positive, and leaving the top ends the saturation. The lines
+ // stay pending until a repaint confirms them — an unanswered down is how
+ // the bottom brake learns the newest output is already on screen.
return {
...travel,
- travelled: Math.max(0, travel.travelled - LINES_PER_NOTCH),
+ travelled: Math.max(0, travel.travelled - lines),
pendingUp: 0,
saturated: false,
+ pendingDown: travel.pendingDown + lines,
+ lastDownAt: now,
};
}
// Away from the live end. While saturated these are known to be ignored by
@@ -222,9 +252,10 @@ export function wheelTravel(travel: Travel, deltaY: number, now: number): Travel
if (travel.saturated) return travel;
return {
...travel,
- travelled: travel.travelled + LINES_PER_NOTCH,
- pendingUp: travel.pendingUp + LINES_PER_NOTCH,
+ travelled: travel.travelled + lines,
+ pendingUp: travel.pendingUp + lines,
lastUpAt: now,
+ pendingDown: 0,
};
}
@@ -241,67 +272,57 @@ export function screenTravel(
): Travel {
if (!glance) return travel;
- if (glance.markerRow < 0) {
- // No overlay. From an application known to paint one, that is proof of
- // the live end — the anchor that ends "thumb stuck mid-track". It also
- // closes the scroll-back episode: the next one proves movement afresh.
- if (!travel.markerSeen) return travel;
- if (
- travel.travelled === 0 &&
- travel.pendingUp === 0 &&
- !travel.saturated &&
- !travel.moved
- ) {
- return travel;
- }
+ if (travel.fingerprint !== glance.fingerprint) {
+ // The transcript moved: whatever was pending has been answered. Only a
+ // CHANGE proves movement — the episode's first look merely records.
return {
...travel,
- travelled: 0,
+ fingerprint: glance.fingerprint,
pendingUp: 0,
+ pendingDown: 0,
saturated: false,
- fingerprint: null,
- moved: false,
+ moved: travel.moved || travel.fingerprint !== null,
};
}
- let next: Travel = travel.markerSeen
- ? travel
- : { ...travel, markerSeen: true };
-
- if (next.fingerprint !== glance.fingerprint) {
- // The transcript moved: whatever was pending has been answered. Only a
- // CHANGE proves movement — the episode's first look merely records.
- next = {
- ...next,
- fingerprint: glance.fingerprint,
- pendingUp: 0,
- saturated: false,
- moved: next.moved || next.fingerprint !== null,
- };
- } else if (next.pendingUp > 0 && now - next.lastUpAt >= SETTLE_MS) {
+ // The screen stood still. Whichever direction was asked for and not
+ // answered has run into that end of the transcript — provided this episode
+ // has scrolled at all (see Travel.moved).
+ if (travel.pendingUp > 0 && now - travel.lastUpAt >= SETTLE_MS) {
// Counted ups, an answered pty, an unmoved screen: those notches did
- // nothing, so they leave the count either way. But they only prove a
- // TOP when this episode has scrolled before — an episode that never
- // moved is a busy CLI, and a ceiling measured from it pinned a pane's
- // thumb to a false top with every further relay refused (2026-07-28).
- const travelled = Math.max(0, next.travelled - next.pendingUp);
- next = next.moved
+ // nothing, so they leave the count either way. But they only prove a TOP
+ // when this episode has scrolled before — an episode that never moved is
+ // a busy CLI, and a ceiling measured from it pinned a pane's thumb to a
+ // false top with every further relay refused (2026-07-28).
+ const travelled = Math.max(0, travel.travelled - travel.pendingUp);
+ return travel.moved
? {
- ...next,
+ ...travel,
travelled,
pendingUp: 0,
saturated: true,
ceiling: Math.max(travelled, LINES_PER_NOTCH),
}
- : { ...next, travelled, pendingUp: 0 };
+ : { ...travel, travelled, pendingUp: 0 };
}
- // The overlay itself says the view is away from the live end — a count of
- // zero would draw the thumb at a bottom the application denies.
- if (next.travelled === 0) {
- next = { ...next, travelled: LINES_PER_NOTCH };
+ if (travel.pendingDown > 0 && now - travel.lastDownAt >= SETTLE_MS) {
+ if (!travel.moved) return { ...travel, pendingDown: 0 };
+ // Downs the application had nothing left to answer with: the newest
+ // output is on screen. This is the live-end anchor — the one that used to
+ // be a hardcoded English string — and it also closes the episode, so the
+ // next one has to prove movement afresh.
+ return {
+ ...travel,
+ travelled: 0,
+ pendingDown: 0,
+ saturated: false,
+ fingerprint: null,
+ moved: false,
+ };
}
- return next;
+
+ return travel;
}
/** Is there anywhere for this pane to go? */
@@ -348,4 +369,3 @@ 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);
}
-