Skip to content

fix(terminal): replay a busy pane's mouse mode to late joiners - #31

Merged
devswha merged 1 commit into
mainfrom
fix/late-join-terminal-modes
Sep 24, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/late-join-terminal-modes

Conversation

@devswha

@devswha devswha commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Summary

On a phone, dragging the terminal of a Claude Code pane still paged through the prompt history instead of scrolling. This happened even after #28.

Cause: a client joining a live attachment only gets the last 256 KiB of the stream (replay). herdr terminal attach turns on the alternate screen and mouse reporting once, at the start of the stream. On a busy pane, such as an agent that keeps redrawing, those switches fall out of the tail. A late joiner therefore runs with mouse reporting off. A typical late joiner is a phone opening a pane that a desktop tab already holds. With scrollback: 0, xterm turns a wheel, including our touch drag, into ESC [ A / ESC [ B. That is Up/Down, the prompt history.

Fix:

  • ReplayBuffer (server/output-window.ts) replaces replayTail.
    • It keeps the same byte-bounded, UTF-8-safe tail.
    • The replay now starts with each DEC private mode that output outside the tail switched, in the order of their last switches. The order matters: 1016l after 1006h resets xterm's mouse encoding.
    • The cut never splits a control sequence, so a switch can't be lost from both halves.
  • xterm now drops a wheel while mouse reporting is off, instead of typing arrows (attachCustomWheelEventHandler). herdr always turns reporting on, so this is only a guard. It also covers remote PCs until their bridge picks this up in a future bundle.

Testing

  • Reproduction:
    • Setup: a desktop page holds a pane, and about 2.3 MB of output flows through it. Then a phone (390×844, touch) opens the same pane and drags.
    • Before: the drag sent ESC[A and no mouse reports.
    • After: the replay starts with ?1049h … ?1000h ?1002h ?1003h ?1015h ?1006h, and the drag sends SGR wheel reports (ESC[<64;col;rowM) at the finger's cell.
    • A pane with little output (no mode ever dropped) behaves as before.
  • New unit tests cover mode carry-over, ordering, not splitting a sequence at the cut, and short streams. The existing UTF-8 cut test now runs through ReplayBuffer.
  • bun run typecheck passes, bun test passes 302/302, and bun run test:ui passes.

🤖 Generated with Claude Code

A client joining a live attachment got only the last 256 KiB of the stream.
herdr turns on the alternate screen and mouse reporting once, at the start
of that stream, so on a busy pane the joiner (a phone opening a pane a
desktop tab holds) ran with mouse reporting off. xterm then turns a wheel,
and our touch drag, into arrow keys, which paged through the agent's
prompt history instead of scrolling herdr.

The replay now leads with every private mode switched by output that fell
out of the tail, in the order of their last switches, and never cuts a
control sequence in two. xterm also drops a wheel while reporting is off
instead of typing arrows.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant