Repository navigation
terminal: the live pane keeps its history and its place across a refresh (#152) - #159
Conversation
…esh (#152) A re-attach bootstrapped the browser from `capture-pane -p -e` — the visible screen only. A page refresh therefore threw away everything above it, and the xterm's own scrollback started empty: the pane came back with no way to read the turn that had just scrolled off. The horizontal offset was lost with it. Server: `captureScreen(name, historyLines)` adds `-S -N` and `attach()` forwards a `historyLines` option, bounded by BOOTSTRAP_HISTORY_LINES (2000 — tmux's default history-limit, and under xterm's 10000-line scrollback). The compositor's repaint and every existing caller keep the old visible-only shape. `/ws/terminal` reads `hist`, clamps it to 0..10000 (client input) and passes it to BOTH attach paths. Client: only a NEW xterm asks for the history (first open, page load, reload). A reconnect of a live one sends nothing — its buffer already holds it, and a second replay would duplicate every line the reader scrolls back through. `booted` flips on the first PARSED frame, not on open, so a connect that dies before painting asks again on its retry. The reader's place is stored as lines ABOVE the bottom (a replayed buffer of a different length lands in the same place) plus the pane's scrollLeft, and restored from the first frame's write callback, which is the only moment the buffer exists to scroll. Verified locally: test/terminal-history.test.js (new, 21 checks, the save/restore pair RUN against a fake xterm), composer-terminal, terminal-session, terminal-schema, tmux-composite, engine-pane, engine-idle-reaper, engine-prompts, engine-prompt-replay, terminal-keys, terminal-clipboard, terminal-addons, terminal-pane-guard, responsive-ui, i18n-completeness, running-sessions, session-liveness, frontend-recovery, frontend-refresh-races, script-scope/pane-font/engine-default — all green. tmux is not installed on this host, so the new integration check (a 120-line pane: visible-only capture loses line 1, a bootstrap with history has it) runs in CI, where tmux is.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c266cb52f4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return; | ||
| } | ||
| const screen = captureScreen(name); // synchronous — see the bootstrap note above | ||
| const screen = captureScreen(name, historyLines); // synchronous — see the bootstrap note above |
There was a problem hiding this comment.
Preserve trailing screen rows when replaying history
When a pane has scrollback and blank rows below its current content (for example, after clearing the screen and returning to a prompt), the history bootstrap misaligns the visible screen. captureScreen() removes all trailing newlines, including those representing the blank screen rows. Replaying history then leaves the last populated row at the bottom of xterm, while cursorSeq() positions the cursor at its original screen row. For example, replaying 30 history lines plus a prompt originally on row 0 into a 24-row xterm places the prompt on row 23 but the cursor on row 0, so subsequent output overwrites unrelated text. Preserve the trailing screen rows for history captures, removing only the capture's final output delimiter.
Useful? React with 👍 / 👎.
Fixes #152.
What was wrong
A re-attach bootstrapped the browser from
capture-pane -p -e— the visible screen only.terminal-bridge.jsalready had-S -for the reaper's saved scrollback, so the history existed on the server side and was simply never sent to a viewer. A refresh therefore came back with the current screen and nothing above it, and xterm's ownscrollback: 10000started empty. The pane's horizontal offset was lost with the same reload.What changed
Server
captureScreen(name, historyLines)— adds-S -Nand keeps the old argv byte-identical whenhistoryLinesis 0, so the compositor's repaint and every existing caller are untouched.attach({ …, historyLines })forwards it to the bootstrap only;BOOTSTRAP_HISTORY_LINES = 2000(tmux's defaulthistory-limit, under xterm's 10000-line scrollback)./ws/terminalreadshist, clamps it to 0..10000 — it is client input — and passes it to both attach paths (the engine viewer and an ordinary terminal).Client
entry.bootedflips on the first parsed frame, not onopen, so a connect that dies before painting asks again on its retry instead of leaving an empty buffer with no history either.viewportYwould land elsewhere in a replayed buffer of a different length — plus the pane'sscrollLeft(engine panes wider than the window scroll sideways), and restored from the first frame'sterm.writecallback, the only moment the buffer exists to scroll.localStoragecarries it across a reload; the in-memory Map avoids a storage write per scroll frame.Verification
test/terminal-history.test.js(new): the argv shape (including the unchanged visible-only form), the server clamp and both attach call sites, the client's ask-once wiring, and the save/restore pair run against a fake xterm — including a different-length buffer and a storage that refuses writes.test/terminal-bridge.integration.test.jsgains a real-tmux case: a 120-line pane, where the visible-only capture has lost the first line and a bootstrap with history has it. tmux is not installed on this host, so that one runs in CI.node -c server.jsandnode -c terminal-bridge.js.The full
npm testcannot complete on this host:task-backlog.test.jsspawns a server withHOST=localhost, which binds::1here, while itsfetch('http://localhost:…')probe reaches127.0.0.1first and never connects. That is a local resolver/binding mismatch, unrelated to this change, and the same suite is green in this PR's CI on Node 20 and 24.