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): restore native terminal scrolling

Ruben Lütkeda4412f7975d
diff --git a/jarvis/agentic_ide/transcript.py b/jarvis/agentic_ide/transcript.py
index cf4139f9a1..32da602d7e 100644
--- a/jarvis/agentic_ide/transcript.py
+++ b/jarvis/agentic_ide/transcript.py
@@ -52,6 +52,10 @@ _CSI_TAIL_RE = re.compile(r"\[?[0-?]*[ -/]*[@-~]")
#: ``ESC [ ? <params> h|l`` — how a CLI turns terminal features on and off.
_PRIVATE_MODE_RE = re.compile(r"\x1b\[\?([0-9;]+)([hl])")
+# A private-mode prefix at the END of the bytes seen so far. PTY reads can cut
+# after any byte, including between ``ESC[?10`` and ``00h``.
+_PRIVATE_MODE_PARTIAL_RE = re.compile(r"\x1b(?:\[(?:\?(?:[0-9;]*))?)?$")
+_PRIVATE_MODE_PARTIAL_MAX = 128
_DECORATION_CHARS = set("─│┌┐└┘├┤┬┴┼━┃╭╮╯╰═║╔╗╚╝╠╣╦╩╬▀▄█▌▐░▒▓▔▁·.-_=*#~ ")
_SPINNER_CHARS = set("|/\\-◐◓◑◒✻✽✢·✳✶⣿")
@@ -224,6 +228,8 @@ class ReplayBuffer:
#: value it was last given. Insertion order matters: a screen switch has to
#: be replayed before what was drawn on that screen.
_modes: dict[str, bool] = field(default_factory=dict, init=False)
+ #: Incomplete private-mode prefix from the preceding PTY read.
+ _mode_scan_tail: str = field(default="", init=False)
def feed(self, chunk: str) -> None:
if not chunk:
@@ -243,12 +249,20 @@ class ReplayBuffer:
``ESC[?1000;1006h`` sets several at once, so each parameter is recorded
on its own. Modes are kept whichever way they were set — a mode the
agent turned OFF is restored as off, because several of them (wraparound,
- the cursor) are ON in a terminal that was just built.
+ the cursor) are ON in a terminal that was just built. The scan carries
+ an incomplete prefix across PTY reads because the kernel may split the
+ sequence after any byte.
"""
- for params, action in _PRIVATE_MODE_RE.findall(chunk):
+ scanned = self._mode_scan_tail + chunk
+ for params, action in _PRIVATE_MODE_RE.findall(scanned):
for param in params.split(";"):
if param:
self._modes[param] = action == "h"
+ partial = _PRIVATE_MODE_PARTIAL_RE.search(scanned)
+ candidate = partial.group(0) if partial is not None else ""
+ self._mode_scan_tail = (
+ candidate if len(candidate) <= _PRIVATE_MODE_PARTIAL_MAX else ""
+ )
def _mode_prologue(self) -> str:
"""The negotiation a truncated replay lost, re-stated in order."""
@@ -293,6 +307,7 @@ class ReplayBuffer:
self.truncated = False
self._open_escape = False
self._modes.clear()
+ self._mode_scan_tail = ""
__all__ = [
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index ebfd071fac..fe28c51f83 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -95,7 +95,7 @@ import {
PARKED_RECHECK_MS,
} from "./offscreenBuffer";
import { installQuerySuppression } from "./terminalQueries";
-import { PaneScrollbar } from "./PaneScrollbar";
+import { bindTerminalScrollSurface } from "./terminalScrollSurface";
import {
openPaneSocket,
type PaneSocket,
@@ -301,17 +301,8 @@ export function AgenticTerminal({
layoutBusy = false,
}: 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 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);
@@ -442,7 +433,7 @@ export function AgenticTerminal({
}
termRef.current = term;
fitRef.current = fit;
- setTermEpoch((epoch) => epoch + 1);
+ const disposeScrollSurface = bindTerminalScrollSurface(container, term);
// 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
@@ -921,6 +912,7 @@ export function AgenticTerminal({
disposePasteBridge();
disposeNewlineBridge();
disposeQuerySuppression();
+ disposeScrollSurface();
try {
socket?.close();
} catch {
@@ -1142,10 +1134,7 @@ 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
- ref={scrollRegionRef}
- className="relative min-h-0 flex-1 overflow-hidden px-1.5 pb-0.5 pt-0.5"
- >
+ <div className="relative min-h-0 flex-1 overflow-hidden px-1.5 pb-0.5 pt-0.5">
<div
ref={containerRef}
data-testid={`agentic-terminal-host-${name}`}
@@ -1155,17 +1144,6 @@ 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}
- />
{/*
The pane says it is starting, instead of being a black rectangle.
diff --git a/tests/unit/agentic_ide/test_transcript.py b/tests/unit/agentic_ide/test_transcript.py
index f050c1f2a9..70fdf2e1af 100644
--- a/tests/unit/agentic_ide/test_transcript.py
+++ b/tests/unit/agentic_ide/test_transcript.py
@@ -239,6 +239,30 @@ def test_a_truncated_replay_still_says_who_owns_the_screen() -> None:
assert replay.index("\x1b[?1049h") < replay.index("x" * 20)
+def test_private_modes_survive_every_pty_chunk_boundary() -> None:
+ """The terminal negotiation may be split after any byte by a PTY read."""
+ mode = "\x1b[?1000;1006h"
+ for cut in range(1, len(mode)):
+ buffer = ReplayBuffer(limit=16)
+ buffer.feed(mode[:cut])
+ buffer.feed(mode[cut:] + "screen")
+ buffer.feed("x" * 64)
+
+ replay = buffer.text()
+ assert "\x1b[?1000h" in replay, f"mode 1000 lost at byte {cut}"
+ assert "\x1b[?1006h" in replay, f"mode 1006 lost at byte {cut}"
+
+
+def test_clearing_a_replay_forgets_an_incomplete_mode_prefix() -> None:
+ buffer = ReplayBuffer(limit=16)
+ buffer.feed("\x1b[?10")
+ buffer.clear()
+ buffer.feed("00hplain output")
+ buffer.feed("x" * 64)
+
+ assert "\x1b[?1000h" not in buffer.text()
+
+
def test_a_mode_the_agent_turned_off_comes_back_off() -> None:
"""Several private modes are ON in a terminal that was just built.