Skip to content

fix(tui): redraw native scrollback one earlier page at a time - #2249

Merged
zjywill merged 13 commits into
mainfrom
fix/scrollback-history
Nov 28, 2026
Merged

zjywill merged 13 commits into
mainfrom
fix/scrollback-history

Conversation

@zjywill

@zjywill zjywill commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Each /earlier in native scrollback reveals one preceding page and redraws the loaded conversation in chronological order in the same terminal. Maintainer decision: replacing native scrollback, including shell output from before Dim started, is accepted. The hint above the oldest message warns about that loss before paging. There is no alternate screen, new window, or draft submission. At the beginning, the command only reports that there are no older messages.

Fullscreen reveals one preceding page in place and leaves the viewport at the join. Both modes show the paging hint above the oldest drawn message, not at the bottom.

Design rule checklist

  • Scope, commands/results, handover, before, batch and context: n/a to agent events; this is a client-side history read and redraw, not a new input or Timeline write.
  • Infrastructure, core mechanisms, plugin state, service faces, loader configuration and missing mechanisms: unchanged. The UI uses the existing history API; no plugin reads or new public service.

Documentation

Updated the native CLI contract, Timeline UI and the terminal test routing. No accepted ADR, unrelated module contract or delivery roadmap changed.

Verification

  • The 69-turn PTY regression covers two successive single-page reveals on the display and legacy history APIs, including split Thinking and a live event received during paging.
  • With tmux 3.6a, a shell printed pre-Dim shell output before execing the native CLI. The test captured the entire pane, including scrollback, before and after /earlier. Below are selected lines from those captures (only the first and last turn are printed for each). The scenario checks all 16 turns, the draft, and the absence of an alternate-screen switch. Fullscreen was tested separately with the same session: no clearing warning, viewport at the page join.
before /earlier (sentinel matches: 1 )
pre-Dim shell output
 ↑ Earlier messages · /earlier · Clears terminal output from before Dim started
 ┃ history-turn-15
 ┃ history-turn-16
after /earlier (sentinel matches: 0 )
 ┃ history-turn-01
 ┃ history-turn-16
 │ › draft stays here                                                                            │

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] A full replay makes the Session worker do quadratic work before it prints anything. The older-page handler prepends each batch to the same live projection, then queues another page until it reaches the start. Projection::prepend linearly searches all accumulated rows for every incoming row. On a long transcript of distinct messages, each prior page makes the next search longer, and this work runs in the same worker that handles commands and live updates. After replay, each snapshot also clones the full vector of row references, even for one new live row.

Please keep full terminal replay separate from the working projection, or otherwise avoid rescanning the accumulated transcript on each page and cloning it on ordinary live updates. Keep the chronological join and duplicate-ID stitching for split responses. An automated long-history fixture should cross many page boundaries and assert near-linear work (for example, count row-identity lookups rather than timing CI) as well as one live update after replay. The 80-turn smoke checks output order, but not the new scaling behavior. This finding is from source; I did not rerun the PTY scenario.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes /earlier reprint the shown branch from the beginning in native scrollback under a "Full conversation history" separator, keeps the draft and the original terminal output, and pages at the join in fullscreen while both modes show the unread-history hint only above the oldest drawn message. The normal resume, the separator, the join, and the live handoff work; the replay itself has two reachable correctness holes, and its page loop confirms the scaling concern.

[P2] A replay applied before the resume window is armed prints only the newest 100 messages.
Update::ReplayHistory calls rebuild_window(0) (crates/dim-cli/src/ui/tui.rs:2590-2596), but frame calls arm_window() first (crates/dim-cli/src/ui/tui.rs:6182), and while awaiting_window is true arm_window sets window_floor to the last 100 messages and turns load_more back on (crates/dim-cli/src/ui/tui.rs:7181-7183). That overwrites the replay floor, so the separator is followed by only the newest 100 messages and then the resumed boundary. The app applies every drained update before it draws (crates/dim-cli/src/ui/tui.rs:324-327), so this order is reachable.
Scenario: /earlier is typed while a resume is loading. The host records replay_all even when the window is not done (crates/dim-cli/src/session_host.rs:2000-2005), and when the replay reaches the start it publishes and sends Update::ReplayHistory back to back (crates/dim-cli/src/session_host/tasks.rs:291-294). If the replay finishes before the first frame that arms the window, the first /earlier prints a "Full conversation history" separator over a truncated tail; a second /earlier prints everything, so the first result is silently wrong.
Evidence: a local test at this head with 150 loaded messages, switch_session(Resumed), then Update::Snapshot and Update::ReplayHistory before the first draw(), prints the separator, ask 50 through ask 149, and the resumed boundary; ask 0 is missing.
Fix: arm the window before rebuilding, or defer the replay until it has armed (for example call self.arm_window() at the start of the Update::ReplayHistory handler, then rebuild_window(0) and clear load_more), and cover the batched order with a test.

[P2] Page boundaries drop user messages and split thoughts during the replay.
Each older page is replayed into a fresh Projection and merged with Projection::prepend (crates/dim-cli/src/session_host/tasks.rs:676-685). prepend stitches only row ids for assistant text and tool calls and discards the older projection's inputs, withdrawals, and thinking state (crates/dim-cli/src/projection.rs:1345-1368). A page that starts at input/applied without its older input/message never creates the user row, because the row is built from the pending input in the same projection (crates/dim-cli/src/projection.rs:416-428); a page that starts inside a thought leaves the older chunk as a separate streaming row, which the scrollback transcript places in the live tail after newer content (crates/dim-cli/src/ui/tui.rs:7314-7317).
Scenario: on a long branch, /earlier reads many pages. Display pages cut on event position and bytes, not on message boundaries, so a cut between a user input and its applied marker silently drops that user message from the replayed transcript while the line's cut count still includes it, and a cut inside a reasoning stream pushes the first half to the bottom of the replay, where it can stay streaming.
Evidence: local tests at this head; prepending a projection with only the input message to one with only the applied marker leaves ["the answer"], and prepending the early half of a thought leaves two thinking rows, the earlier one streaming.
Fix: collect the replay pages and replay them once in chronological order into one projection, or carry the input and thinking state through prepend. The first option also removes the rescan below.

The existing rescan concern is confirmed: I measured the real Projection at 1.1 s for 20k rows and 8.7 s for 50k rows in page-sized stalls on the worker, and the single-pass replay in finding 2 removes it.

[P3] The new replay path has no boundary-crossing test in CI.
replay_all, continue_replay, and Update::ReplayHistory have no unit test; the cli_flow fixture answers both pages before /earlier and asserts no further history read, so it never pages during the replay; and the new tmux scenario is not run by any workflow (scripts/tui-tmux.test.mjs asserts that no workflow invokes the suite). The tmux scenario is also the only test with a live turn after the replay, and it has 16 turns. Add a fixture whose replay crosses several page boundaries, assert the printed order and one live turn after the replay, and count row-identity lookups instead of wall time for the scaling check.

Verification: cargo test -p dim-cli --lib passes at this head (818 tests). I reproduced the first two findings with local tests at this head; I did not run the tmux scenario. CI at this head is green.

REQUEST_CHANGES

Comment thread crates/dim-cli/src/ui/tui.rs Outdated
self.set_notice(text);
}
}
Update::ReplayHistory => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arm order: frame calls arm_window() before it consumes full_history_section (crates/dim-cli/src/ui/tui.rs:6182-6183), and while awaiting_window is true arm_window rewrites window_floor to the newest 100 messages and sets load_more (crates/dim-cli/src/ui/tui.rs:7181-7183). A replay applied before the first arming frame therefore heads a Full conversation history separator over only the last 100 messages. I reproduced this at this head with 150 loaded messages and Snapshot plus ReplayHistory before the first draw(): ask 0 is missing. Arm first in this handler, or defer the replay until arm_window has run, and test the batched order.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a9db9d0.

Ok(())
}

fn continue_replay(&mut self, branch: &str) -> bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop makes the pre-existing merge problems systematic. Projection::prepend scans all accumulated rows per incoming row (crates/dim-cli/src/projection.rs:1346-1349) and merges only rows (crates/dim-cli/src/projection.rs:1345-1368), so a full replay is O(N^2) on the worker, and a page boundary that splits input/message from input/applied, or a thought, loses that state. Measured locally: 20k rows 1.1 s, 50k rows 8.7 s of rescan, in page-sized stalls. Collect the pages and replay them once in chronological order, or index row ids for the merge.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a9db9d0.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user benefit is clear: read the shown branch from the beginning without leaving native scrollback, losing the draft, or changing Session state. Under PRODUCT.md, this is a capability extension on the existing history API. The separate chronological replay now addresses my earlier quadratic projection finding; the new fixtures cover split history and the first-frame replay order.

[P2] An unrelated snapshot can cancel the requested fullscreen page reveal before it starts. show_earlier queues Command::Earlier and sets reveal_pending when the window has no older loaded rows and the worker reports Unread. If a snapshot already queued by a live update still says Unread, the snapshot handler sees no new rows and clears the flag because the state isn't Reading. The later page can load successfully, but it no longer moves the viewport to the join. Keep the reveal intent until a matching read completes or explicitly fails/is cancelled; an unacknowledged Unread snapshot is neither. Please add a deterministic fullscreen test: request the page at the loaded top, apply an unchanged Unread snapshot, then the page, and assert that the first gesture reveals the join.

Please also attach the current head's terminal capture (ASCII/text is fine) for native replay and the fullscreen join, alongside behavioral results. The PR body currently reports interactive evidence from before the rebase; the replay path has since changed. This is a source-derived finding; I did not rerun tmux, and head CI was still running at review time.

@zjywill

zjywill commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Verified a9db9d0 in tmux (16-turn resumed session, isolated home). Excerpts below are from capture-pane, filtered to message labels, the paging hint and the divider.

Fullscreen — after one /earlier, without another scroll or keypress. The initial window began at turn 15; the viewport now includes earlier turns and the old boundary. Home/End also reached turns 01/16.

┃ history-turn-07
┃ history-turn-08
┃ history-turn-09
┃ history-turn-10
┃ history-turn-11
┃ history-turn-12
┃ history-turn-13
┃ history-turn-14
┃ history-turn-15

Native scrollback — replay and next live turn. No alternate screen or scrollback clear; the draft stayed in the composer until Enter. Every turn after the divider had exactly one matching answer in order.

↑ Earlier messages · /earlier
┃ history-turn-15
┃ history-turn-16
─ Full conversation history ─
┃ history-turn-01
┃ history-turn-02
┃ history-turn-03
┃ history-turn-04
┃ history-turn-05
┃ history-turn-06
┃ history-turn-07
┃ history-turn-08
┃ history-turn-09
┃ history-turn-10
┃ history-turn-11
┃ history-turn-12
┃ history-turn-13
┃ history-turn-14
┃ history-turn-15
┃ history-turn-16
┃ draft stays here

The deterministic fullscreen test injected an unchanged Unread snapshot between the first gesture and Reading. It failed on the previous head, then passed on this fix and checked that the jump targets the old first message. All 820 dim-cli library tests and Clippy for dim-cli + dimcode passed.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes /earlier reprint the shown branch from the beginning in native scrollback under a "Full conversation history" separator, keeps the draft and the original terminal output, lets new output follow the replay, and has fullscreen reveal a loaded page at the join while both modes show the paging hint only above the oldest drawn message.

Both P2s from the previous round are fixed and withdrawn. The replay waits for the window to arm and is drawn after arm_window (crates/dim-cli/src/ui/tui.rs:6182-6184), its captured window is only usable once through is set (crates/dim-cli/src/session_host/tasks.rs:70-75, crates/dim-cli/src/session_host/tasks.rs:383-390), and draw_replay recomputes the floor from that window (crates/dim-cli/src/ui/tui.rs:7200-7211); the batched pre-first-frame test covers 151 loaded messages (crates/dim-cli/src/ui/tui.rs:23387). The replay folds every page into one Projection in order (crates/dim-cli/src/session_host/tasks.rs:61-98, crates/dim-cli/src/session_host/tasks.rs:627-658, crates/dim-cli/src/projection.rs:315-317), so a page boundary no longer drops a user message or splits a thought; the split-thought fixture (crates/dim-cli/src/session_host/tasks.rs:1106) and the 384-message flow fixture (crates/dimcode/tests/cli_flow/tasks.rs:679) pass. The rescan is gone: the prepend loop is removed, each event folds once, and the fixture bounds folds and row copies.

The fullscreen reveal race is closed at this head. The worker publishes a snapshot with the Reading state after a fullscreen page request (crates/dim-cli/src/session_host.rs:2010-2012), and the snapshot handler keeps the reveal intent across queued and unchanged Unread snapshots, clearing it only when the page is revealed or the read ends without one (crates/dim-cli/src/ui/tui.rs:2640-2650). The test applies an unchanged Unread snapshot before the page and asserts the join jump (crates/dim-cli/src/ui/tui.rs:23443-23444, crates/dim-cli/src/ui/tui.rs:23486-23488). I reproduced the previous failure at the old head; the same sequence now reveals, including several queued Unread snapshots, and a failed read still cancels the intent.

[P3] The native replay and fullscreen join still have no CI end-to-end test.
The logic is covered by fast fixtures, but the only test that exercises a real PTY, the hint position, the absence of an alternate screen or cleared scrollback, and the fullscreen viewport at the join is the tmux scenario (scripts/tui-tmux/scenarios.mjs:185), and no workflow runs that suite (scripts/tui-tmux.test.mjs:116 asserts that none invokes it). Scenario: a change that clears scrollback or moves the hint below the oldest drawn message would pass CI, because the Rust fixtures cannot observe terminal output. Fix: run the suite from a workflow or add a small PTY fixture for these cases, as a follow-up rather than a change to this PR.

[P3] The guard's failure half and the worker's Reading publish have no test.
The added test covers an unchanged Unread snapshot and the page arriving, but not a read that ends Unread after the Reading snapshot, which is the branch that clears the intent, and nothing directly asserts that Command::Earlier { all: false } publishes a Reading snapshot (crates/dim-cli/src/session_host.rs:2010-2012). Scenario: a later change to either side could hold the reveal forever or lose the cancellation without a failing test. Fix: add one TUI test for the failed read and one worker test for the published Reading snapshot.

Verification: cargo test -p dim-cli --lib passes at this head (820 tests); the replay, split-thought, batched-window, and the changed line and window cli_flow tests pass. I did not run the tmux suite because tmux is not installed here. CI at this head has macos-native, windows-cli, scripts and changes passing, with verify (linux) still running when I checked.

APPROVE

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier first-frame truncation, split-page projection, quadratic work, and fullscreen reveal issues are resolved on this head. One new regression remains in the native replay handoff (crates/dim-cli/src/ui/tui.rs:7180–7233). While a live turn shows a provisional reasoning row, invoke /earlier. If its first durable reasoning event changes the row ID before the replay frame, the live window starts at zero and repeats rows already printed. If the ID changes just after that frame, the live window starts past the reasoning row and omits it. Both orderings reproduced using the projection and frame renderer. Acceptance: in both orderings, each recorded message appears once in the replay, and the settled live thought appears once below it.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two original reasoning handoff fixtures now pass. The same acceptance criterion is still unmet if a background member result arrives after the provisional thought and before /earlier captures the window. In crates/dim-cli/src/ui/tui.rs:7180–7215, a durable reasoning ID arriving before the replay frame can restart the live window and repeat recorded messages; arriving after the frame can skip the settled thought. Both orders reproduced in isolated projection and frame tests. Acceptance: in both orders, every recorded message and member result appears once and the settled live thought appears once below the replay. No other code blocker from this round; the Linux compaction failure is tracked separately.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes /earlier reprint the shown branch from the beginning in native scrollback under a "Full conversation history" separator, keeps the draft and the terminal output, lets later live output follow the replay, and pages the fullscreen join in place.

The two orderings reported at a9db9d0 are fixed and withdrawn in those forms. draw_replay removes a trailing provisional thinking row before aligning the captured window with the replayed rows (crates/dim-cli/src/ui/tui.rs:7187-7190), and follow_floors follows a thinking row across its provisional id (crates/dim-cli/src/ui/tui.rs:8036-8055). I checked each half by removing it in a scratch checkout: without the truncation, the settle-before run prints answer. twice and the settle-after run loses Settled thought.; without the provisional-id match, the settle-after run falls back to floor zero and repeats answer.. The new fixture (crates/dim-cli/src/ui/tui.rs:23432-23491) fails under both mutations and passes at this head, so both orderings are pinned.

[P2] A recorded row after the provisional thinking row still breaks the replay handoff.
Problem: the truncation removes live-only rows only when they end the captured window. A background member result is appended to the requesting branch's timeline when the member settles (crates/dim-app-server/src/collaboration.rs:2502) and becomes a MemberResult row behind the live thinking row (crates/dim-cli/src/projection.rs:527). When /earlier captures the window after that row, replay.window is [..., thinking (streaming, provisional), member result]. recorded_end keeps the thinking row because the member result follows it (crates/dim-cli/src/ui/tui.rs:7187-7190); the overlap matches only the member result, and the floor is computed at its index (crates/dim-cli/src/ui/tui.rs:7204-7214), so the live window starts past the thought.
Failure scenario, inline mode while a background agent result lands during a progress-only reasoning row and the user then runs /earlier:

  • First durable reasoning event before the replay frame: the floor lookup matches only row_id (crates/dim-cli/src/ui/tui.rs:7212), the thinking row's id has changed, the lookup returns 0, and the next frame writes the recorded messages again below the replay.
  • First durable reasoning event after the replay frame: the floor stays on the member result and the settled thought never appears below the replay.
    I reproduced both with a scratch fixture at this head: the settle-before run printed ask 0 and ask 1 twice, the settle-after run printed Settled thought. zero times, and the member result appeared once in both. The acceptance is therefore still unmet with a member result, not only with a second reasoning row.
    Fix: do not let a live-only row decide the floor. Skip Thinking rows with provisional_id.is_none() wherever they appear in replay.window, not only at its tail, and pick the floor from the last window row the replay actually printed, for example by walking skipped - 1 back over those rows, then match that row to the snapshot by row_id or provisional_id. Walking the floor candidate back over provisional rows made both member-result orderings print each recorded message, the member result and the settled thought once while the current fixture still passed. Add this ordering to scrollback_replay_keeps_a_live_thought_settled_on_either_side_of_its_frame.

Nothing else blocks. The one-pass replay, the pre-first-frame ordering, the fullscreen reveal through queued Unread snapshots and the draft behaviour still hold. The earlier P3s (tmux coverage in CI, the failed-read half of the reveal guard) remain optional; the queued Unread snapshot is now covered.

Verification: cargo test -p dim-cli --lib passes at this head (821 tests); the replay, first-frame, show_earlier, follow_floors, fullscreen load-more and split-page fixtures pass. CI at this head has macos-native, windows-cli, scripts and changes passing. verify (linux) failed in context_flow::product_summary::compaction_chunks_images_as_markers_and_legacy_screenshots_as_text with Storage("unknown session ...") (crates/dim-agent-capabilities/tests/context_flow/product_summary.rs:67), a file this PR does not touch, and base main 7880f6e has a failed verify job of its own, so I do not attribute it here. origin/main is now 3cfbba4 (#2262, CI scripts and the build page); no conflict with this PR's files, and #2264, #1881, #2255, #2263 share no hunk with this PR (#1881 already conflicts with main on its own).

REQUEST_CHANGES

Comment thread crates/dim-cli/src/ui/tui.rs Outdated
{
common -= 1;
}
let skipped = window.len() - common;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The floor assumes every window row before the common suffix was printed by the replay. A live-only reasoning row that a later recorded row keeps inside the window breaks that: a background member result is appended after the live thinking row (crates/dim-app-server/src/collaboration.rs:2502, crates/dim-cli/src/projection.rs:527), so recorded_end keeps the provisional thinking row (crates/dim-cli/src/ui/tui.rs:7187-7190). The overlap then matches only the member result and this floor lands at its index, past the thinking row. If the thinking row's id changes before the replay frame, the row_id lookup at line 7212 returns None and floor 0 repeats the recorded messages; if it changes after, the thought is skipped. Walk skipped - 1 back over provisional rows and match the row by row_id or provisional_id; both orderings reproduce at this head.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in af19660: first_preview now splits the captured window at the live-only row, so the floor row is a recorded prefix row, and settled rows the replay prints from the live suffix are planned as committed. The fixture runs both member-result settle orders; removing either half fails it.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remaining replay handoff issue is resolved. With a recorded member result behind provisional reasoning, both durable-ID orderings now print each recorded message and result once, and the settled thought once below the replay. All eight focused tests passed. Native and fullscreen tmux passed once inventory was ready; the immediate-gesture limitation is also present on the base and is not a blocker for this change. No remaining code blockers.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed af19660e. The fullscreen reveal now survives an unchanged Unread snapshot and moves to the join on the first gesture. Native replay is separate from the live projection, and the live handoff no longer uses the provisional thought as the replay boundary: the member-result fixture covers both durable-ID orderings and asserts that recorded rows and the settled thought each appear once. The terminal captures and independent tmux check show the intended behavior in both modes, including the preserved draft and scrollback. I checked the source and exact-head Linux test log rather than rerunning tmux; it shows the fullscreen reveal, live handoff, long-history budget, and draft-preserving flow tests passing. The previous compaction-test failure did not recur and ci-ok passed. No remaining blockers from my review.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes /earlier reprint the shown branch from the beginning in native scrollback under a "Full conversation history" separator, keeps the draft and the original terminal output, lets later live output follow the replay, and pages the fullscreen join in place. The new head also keeps a live thought through a member result that arrives between the provisional row and the replay frame.

All earlier blocking points are fixed and withdrawn:

  • One forward replay pass: each page folds once into one projection (crates/dim-cli/src/session_host/tasks.rs:87-97), with a split-thought fixture and a fold budget (crates/dim-cli/src/session_host/tasks.rs:1106) and a 384-message flow fixture crossing page boundaries (crates/dimcode/tests/cli_flow/tasks.rs:679).
  • The batched pre-first-frame order: the replay is drawn after arm_window (crates/dim-cli/src/ui/tui.rs:6182-6184), and the worker captures its window and watermark only after the line's window is done (crates/dim-cli/src/session_host/tasks.rs:377-390).
  • The fullscreen reveal through queued Unread snapshots (crates/dim-cli/src/ui/tui.rs:2637-2650).
  • The provisional-thought orderings, settled before or after the replay frame (crates/dim-cli/src/ui/tui.rs:23443-23523).
  • The member-result interleaving reported at 31b68a9. The split at first_preview (crates/dim-cli/src/ui/tui.rs:7187) now leaves the live suffix out of the overlap, so the floor row is always a recorded prefix row, and a settled row the replay prints from that suffix is committed through self.commits.plan (crates/dim-cli/src/ui/tui.rs:7229-7248). The fixture runs both member-result settle orders and asserts each recorded message and member result once, with the settled thought once below.

I removed each half in a scratch checkout to confirm the fixture pins them: restoring the old tail truncation prints answer. twice in the settle-before run and loses Settled thought. in the settle-after run; dropping the live-id skip and the commit plan prints Member finished. twice in both orders. Each mutation fails the fixture; the head passes it.

No blocking findings remain. The two earlier P3s stay optional and non-blocking: the tmux scenario is still not run by a workflow, and the failed-read half of the reveal guard has no test.

Verification: cargo test -p dim-cli --lib passes (821 tests); the 384-message cli_session_flow resume and replay test and the changed line-mode flow tests pass. CI at af19660 is fully green, including verify (linux). I did not run the tmux suite. Cross-PR: no conflict with origin/main 3cfbba4; #2255, #2263 and #2264 merge cleanly; #1881's only pairwise conflict is docs/design/plugins/Report.md, which already conflicts with main, and its tui.rs and i18n hunks merge.

APPROVE

@zjywill zjywill changed the title fix(tui): replay the full conversation in native scrollback fix(tui): append one earlier page at a time in native scrollback Nov 27, 2026

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 42f35a39 as a different interaction from the full replay I approved on af19660e. One page per gesture is a reasonable smaller scope, with the same no-resubmit/no-reattach boundary, but it needs to preserve all messages across reads.

[P2] Separate earlier reads can silently lose a user message at the page boundary. The worker folds each older read into a fresh projection and then prepend merges rows, not the pending input state. If the newer read begins with input/applied and the matching input/message arrives in the preceding read, the newer fold created no user row; the older fold only queues the input. Continuing to the start therefore never displays that user message. This is the same split-event defect raised earlier in the PR; the removed forward replay had addressed it. Please preserve enough boundary state to fold the pair, or make the reads projection-safe, and add a PTY regression where the events are split between two separate /earlier invocations. Assert one user message, in order, for the display and legacy paths.

Please attach a current terminal capture for two successive pages and the beginning notice (the old capture showed full replay, not this interaction). The 69-turn scenario establishes ordinary paging but doesn't force the split. This is source evidence; I didn't rerun tmux.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This head replaces the native full-replay behavior approved at af19660 with a different product behavior. On a resumed session with turns 61–69 already visible, /earlier appends 11–60, then 1–10, so native scrollback does not contain a chronological full-history section. The current PTY tests explicitly confirm the page-at-a-time result. Please retain the previously reviewed one-command chronological replay (including draft and live handoff) or get an explicit product decision accepting reverse-ordered pages instead. The current page/draft/fullscreen tests pass; this is a delivery-scope change, not a new implementation preference.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes native scrollback /earlier append one preceding page per invocation, oldest first inside the page, continue backward without reprinting the boundary message, report the beginning instead of another page, and keep the draft, the terminal and live output; fullscreen reveals the preceding page at the join. The all flag, HistoryReplay, ReplayHistory, draw_replay and the missing-prefix notice are gone with no leftovers, and no client/server wire changed.

Earlier points: the replay truncation, the pre-first-frame replay order, the quadratic replay rescan, and the provisional thought and member-result orderings were replay-only and are obsolete at this head. My approval at af19660 is withdrawn because the head changed. The fullscreen reveal guard is still fixed (crates/dim-cli/src/ui/tui.rs:2636-2643, crates/dim-cli/src/session_host.rs:2000-2004). One earlier P2 is not obsolete: page boundaries still lose cross-page state, now in the page the scrollback prints.

[P2] A page boundary drops a user message and leaves a thought unsettled.

Problem: each earlier read folds into a fresh Projection and prepends it (crates/dim-cli/src/session_host/tasks.rs:671-682), and Projection::prepend (crates/dim-cli/src/projection.rs:1343-1392) carries only assistant and tool rows, not pending inputs, applied markers or thinking state. A user row exists only when input/applied finds its pending input in the same projection (crates/dim-cli/src/projection.rs:390-430), and a thought settles only when the same projection sees the event that moves the request on (crates/dim-cli/src/projection.rs:2083-2094). The fold and prepend are main's code, but main's native /earlier loaded the page without printing it; this head prints it and the rescope deleted the single-pass replay that fixed the same boundary at af19660.

Failure scenario: backward paging makes the current projection start at the boundary event and the next page end just before it. If the boundary is input/applied (the two are separate atomic batches at crates/dim-agent-capabilities/src/input_queue/recovery.rs:54-96), the applied has no input and the older page's input has no applied, so the question is never drawn and that /earlier can print no page at all. If the boundary falls after a durable Thinking event but before the event that settles it, close_thinking runs only in the projection that sees the settle (crates/dim-cli/src/projection.rs:2083-2094), so the older row stays streaming forever: fullscreen keeps it in the live tail, scrollback loses its settled duration, and a request with a second Thinking event also becomes a second row. Server pages cut at arbitrary event positions, not turns (display_tail at crates/dim-app-server/src/connection/tree.rs:1490-1533, display_transcript at crates/dim-app-server/src/connection/tree.rs:1301-1485), so both boundaries are reachable.

Evidence: I reproduced the projection state at this head. Prepending an input-only page to an applied-plus-answer projection yields only the answer row. Prepending a Thinking event to its settled continuation yields a row that stays streaming: true because the continuation's close finds no open thought in its own projection, and two Thinking rows when the request has two events. The deleted af19660 fixture full_replay_stitches_split_thoughts_with_a_linear_projection_budget pinned the stitched thought across 256-event pages; the new paging fixtures cut only between messages (crates/dimcode/tests/cli_flow/tasks.rs:733-781), so CI cannot see this.

Fix: carry the boundary state through prepend. Remember an applied marker that had no pending input and create the user row when the prepended page supplies that input, and merge a prepended streaming thought into its continuation row by request id (keep the request key on the row or a closed-thought index). Add fixtures that cut between input/message and input/applied and between a step/thinking event and the event that settles it. If paging ships with this limitation, it needs an explicit note and a follow-up, but a silently missing user message is content loss in the new scrollback page.

[P3] The earlier-conversation example is stale. docs/design/cli-commands.md:3816-3821 still shows the pre-paging layout: a top row labelled [earlier content not loaded] (a notice this PR removes), the older rows above the initial window, and live output last, while the paragraph above now says scrollback appends the page below the terminal's existing output. The header format is Earlier history · {id} · {count} messages in the code (crates/dim-cli/src/ui/tui.rs:7481-7488). Update the block to the new hint, header and append order (or scope it to fullscreen), and show the beginning notice.

[P3] Remaining coverage gaps. The PTY flow pins the no-repeat boundary, the two pages and the third-invocation notice (crates/dimcode/tests/cli_flow/tasks.rs:818-839), and it preserves a draft typed while the initial window loads (crates/dimcode/tests/cli_flow/tasks.rs:799-815), but no CI test types a draft and then runs /earlier; only the local tmux scenario does. The fullscreen join is asserted as a jump target and as block order, not at the viewport in CI, and the tmux suite is local-only by AGENTS.md. The failed-read half of the reveal guard and the worker's Reading publish (crates/dim-cli/src/session_host.rs:2000-2004) still have no test.

Verification: cargo test -p dim-cli --lib passes (818). The cli_session_flow paging test, both changed cli_flow/lines tests, cli_tui_flow/windows and tui_lines_count_a_cut_read_from_a_transcript_window pass. node scripts/tui-tmux.test.mjs passes. tmux is not installed here, so I did not run the scenario. CI at 42f35a3 is green: verify (linux), macos-native, windows-cli, scripts, changes and ci-ok passed; static-checks, acp-registry, dependencies and web were skipped. Cross-PR: merge-tree shows no conflict with origin/main 3cfbba4 or with #2255, #2263, #2264 and #1881.

REQUEST_CHANGES

@zjywill

zjywill commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@zerob13 Single-page native scrollback is a confirmed product decision: the maintainer explicitly chose one preceding page per /earlier, appended in the current terminal. Pages arrive newest to oldest, rows within a page read oldest first. There is no one-command replay, screen switch or clear. Fullscreen reveals one page in place at the join. The earlier full-replay recording is superseded.

@eric8810 Fixed the split-input case in bc5a1528e. The first gesture reads input/applied and input/consumed for turn 11; only the second gesture reads its input/message. Before the fix that second page stopped at reply 010 (20 rows). After the fix it ends with message 011 (21 rows). The next gesture only reports the beginning. The test checks each row in order and the totals; both display and legacy passed. No extra reads or resubmission.

Scrollback PTY capture: two gestures and the start notice (all transcript rows, identical on display and legacy)

Extracted from terminal output with ANSI, blank lines and composer repaints removed:

Earlier history · paged · 99 messages
paged-reply-011
┃ paged-message-012
paged-reply-012
┃ paged-message-013
paged-reply-013
┃ paged-message-014
paged-reply-014
┃ paged-message-015
paged-reply-015
┃ paged-message-016
paged-reply-016
┃ paged-message-017
paged-reply-017
┃ paged-message-018
paged-reply-018
┃ paged-message-019
paged-reply-019
┃ paged-message-020
paged-reply-020
┃ paged-message-021
paged-reply-021
┃ paged-message-022
paged-reply-022
┃ paged-message-023
paged-reply-023
┃ paged-message-024
paged-reply-024
┃ paged-message-025
paged-reply-025
┃ paged-message-026
paged-reply-026
┃ paged-message-027
paged-reply-027
┃ paged-message-028
paged-reply-028
┃ paged-message-029
paged-reply-029
┃ paged-message-030
paged-reply-030
┃ paged-message-031
paged-reply-031
┃ paged-message-032
paged-reply-032
┃ paged-message-033
paged-reply-033
┃ paged-message-034
paged-reply-034
┃ paged-message-035
paged-reply-035
┃ paged-message-036
paged-reply-036
┃ paged-message-037
paged-reply-037
┃ paged-message-038
paged-reply-038
┃ paged-message-039
paged-reply-039
┃ paged-message-040
paged-reply-040
┃ paged-message-041
paged-reply-041
┃ paged-message-042
paged-reply-042
┃ paged-message-043
paged-reply-043
┃ paged-message-044
paged-reply-044
┃ paged-message-045
paged-reply-045
┃ paged-message-046
paged-reply-046
┃ paged-message-047
paged-reply-047
┃ paged-message-048
paged-reply-048
┃ paged-message-049
paged-reply-049
┃ paged-message-050
paged-reply-050
┃ paged-message-051
paged-reply-051
┃ paged-message-052
paged-reply-052
┃ paged-message-053
paged-reply-053
┃ paged-message-054
paged-reply-054
┃ paged-message-055
paged-reply-055
┃ paged-message-056
paged-reply-056
┃ paged-message-057
paged-reply-057
┃ paged-message-058
paged-reply-058
┃ paged-message-059
paged-reply-059
┃ paged-message-060
paged-reply-060
Earlier history · paged · 21 messages
┃ paged-message-001
paged-reply-001
┃ paged-message-002
paged-reply-002
┃ paged-message-003
paged-reply-003
┃ paged-message-004
paged-reply-004
┃ paged-message-005
paged-reply-005
┃ paged-message-006
paged-reply-006
┃ paged-message-007
paged-reply-007
┃ paged-message-008
paged-reply-008
┃ paged-message-009
paged-reply-009
┃ paged-message-010
paged-reply-010
┃ paged-message-011
Beginning of conversation

Fullscreen, real tmux pane after /earlier: the viewport straddles the join. Captured user rows (assistant rows and scrollbar omitted):

┃ history-turn-07
┃ history-turn-08
┃ history-turn-09
┃ history-turn-10
┃ history-turn-11
┃ history-turn-12
┃ history-turn-13
┃ history-turn-14
┃ history-turn-15

Home reached history-turn-01; End returned to history-turn-16; PageUp at the start displayed Beginning of conversation. The same production CLI and App Server passed the scrollback tmux scenario with the draft intact, no alternate screen and no scrollback clear.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This head keeps one preceding page per native scrollback /earlier and fixes the user-message half of my last P2. Window::take_transcript carries input/applied and input/consumed back to the page that holds their input (crates/dim-client/src/window.rs:141-158), both earlier-read paths use it (crates/dim-cli/src/session_host/tasks.rs:667, crates/dim-cli/src/session_host/member.rs:591), and the PTY flow now cuts between input/message and input/applied at 10 * 7 + 1, asserts the message after 001 to 010, and counts 60 user messages and 60 replies across the two pages (crates/dimcode/tests/cli_flow/tasks.rs:763-783, crates/dimcode/tests/cli_flow/tasks.rs:822-841). I ran that test at this head and it passes; that half is fixed and withdrawn. The thinking half of the same finding is not fixed.

[P2] A page cut between a thinking event and the event that settles it still leaves the older row open.

Problem: each earlier read is still folded into a fresh Projection and prepended (crates/dim-cli/src/session_host/tasks.rs:671-683), and Projection::prepend merges only row ids for assistant text and tool calls and drops the older projection's thinking_rows (crates/dim-cli/src/projection.rs:1343-1391). A durable thinking event opens a streaming row in the projection that sees it (crates/dim-cli/src/projection.rs:528-558, crates/dim-cli/src/projection.rs:1999-2018), and only the projection that later sees the settling event closes it (crates/dim-cli/src/projection.rs:2083-2094). When the page boundary falls between the two events, the settling event ran before the row existed and never runs for it.

Failure scenario: resume a branch whose newest 32-event window starts at a text event that follows the request's last step/thinking event; the first /earlier page then ends at that thinking event. The imported thought stays streaming: true with no duration forever. Fullscreen treats a streaming Thinking row as live and draws it at the bottom of the transcript (crates/dim-cli/src/ui/tui.rs:7297-7300), so a thought from older history stays in the running tail and moves out of place; in native scrollback the printed thought loses its settled duration, and a request whose thinking spans the boundary (a second step/thinking in the newer page) prints one thought as two rows.

Evidence: I reproduced both states at this head with projection unit tests. Prepending [Thinking(5)] to [Text(6)] yields [Thinking(streaming=true, elapsed_ms=None), answer]; splitting two Thinking events across the boundary yields two Thinking rows because the row id is thinking-{event.id} (crates/dim-cli/src/projection.rs:555-560). The fixture that pinned this at af19660, full_replay_stitches_split_thoughts_with_a_linear_projection_budget (crates/dim-cli/src/session_host/tasks.rs:1106 there), was deleted with the one-pass replay, and the paging fixture has no thinking events (crates/dimcode/tests/cli_flow/tasks.rs:734-751).

Fix: mirror the input carry for thoughts. Keep, per request, the closed_at of a thought the projection settles, and when prepend places an open Thinking row of the same request before it, mark that row settled with that duration and merge the two chunks. The row needs a request key or a closed-thought index in Projection. Add a fixture that cuts between step/thinking and the settling event and one that cuts between two Thinking events, asserting one non-streaming thought row.

[P2] The head does not pass the required format check.

Problem: crates/dimcode/tests/cli_flow/tasks.rs:764 is 118 columns. cargo fmt --all -- --check --config error_on_line_overflow=true fails on it, so verify (linux) and ci-ok are red at bc5a152.

Failure scenario: the required check stays red until this is fixed, so the PR cannot merge.

Evidence: CI at bc5a152: verify (linux) and ci-ok failed; macos-native, windows-cli, scripts and changes passed; static-checks, acp-registry, dependencies and web were skipped. The same command fails locally at the same line.

Fix: wrap the page array over several lines and rerun the check.

[P3] The earlier-conversation example is still stale. docs/design/cli-commands.md:3816-3821 still shows [earlier content not loaded], older rows above the initial window, and live output last, while the paragraph above now says scrollback appends the page below the terminal's output and docs/design/timeline-ui.md says pages arrive newest to oldest. The label is Earlier history · {id} · {count} messages (crates/dim-cli/src/ui/tui.rs:7482) and the start notice is Beginning of conversation (crates/dim-cli/src/ui/tui.rs:7898). Update the block or scope it to line mode.

[P3] Coverage. No CI test covers the thinking boundary above. The draft survives /earlier only in the local tmux scenario, and the fullscreen viewport at the join is still asserted only there; a CI test types a draft during the initial window but submits it before /earlier (crates/dimcode/tests/cli_flow/tasks.rs:799-816). The failed-read half of the reveal guard still has no test.

Verification: cargo test -p dim-cli --lib passes (818); cargo test -p dim-client passes (3 connection tests); cargo test -p dimcode --test cli_session_flow tui_task_history_resume_windows_complete_main_pages_and_preserves_the_draft passes, so the input boundary and the no-repeat are pinned; cargo clippy -p dim-cli -p dim-client -p dimcode --all-targets -- -D warnings is clean; the fmt check above fails. I did not run the tmux suite. Cross-PR: merge-tree is clean with origin/main 1997683, #2227, #2255 and #2264; #1881 conflicts only on docs/design/plugins/Report.md, which already conflicts with main on its own.

REQUEST_CHANGES

Comment thread crates/dimcode/tests/cli_flow/tasks.rs Outdated
json!({"sessionId":"paged","branchId":"main","event":event}));
notice(wire, &configured_event(WINDOW_HEAD as u64 + 1, "before-page", json!({})));
let split = 10 * 7 + 1;
for (lower, upper) in [(45 * 7, start), (35 * 7, 45 * 7), (25 * 7, 35 * 7), (split, 25 * 7), (0, split)] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is 118 columns, so cargo fmt --all -- --check --config error_on_line_overflow=true fails here and CI verify (linux) plus ci-ok are red at bc5a152. Wrap the page array over several lines so the head passes the required check. The paging assertions themselves pass.

@eric8810 eric8810 added this to the v0.1.0-alpha.30 milestone Nov 27, 2026
@zjywill

zjywill commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Please re-review the latest commit, 543c929. The maintainer tested the installed build and confirmed the intended behavior: each /earlier in Scrollback reveals one preceding page, redrawing the loaded conversation oldest first in the same terminal. It does not append older messages below newer ones or open an alternate screen. Fullscreen still reveals the older page at the join. The installed binary passed both modes in tmux, and the 69-turn PTY test covered two successive pages and split Thinking.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] /earlier now removes terminal output outside Dim. The latest commit changes the interaction again: the native branch of reveal_earlier requests the reflow used for width changes, and the new contract explicitly says this replaces scrollback including output from before the UI started. The PR summary still promises not to clear scrollback. Staying on the same screen and keeping the draft do not preserve that output. Someone who runs Dim after a build or another shell command can lose that earlier terminal output just by browsing the session.

Please preserve pre-existing terminal output, or record an explicit maintainer decision that accepts losing it and make that consequence visible before users invoke the command. Confirming oldest-first paging does not by itself confirm clearing unrelated output. Update the PR summary and native CLI README to match the decision, and include an actual tmux capture with a pre-Dim sentinel so we can verify what survives. Fullscreen can continue to reveal one page at the join. This is source and contract evidence; I have not rerun tmux or verified the in-progress CI for this head.

@zjywill zjywill changed the title fix(tui): append one earlier page at a time in native scrollback fix(tui): redraw native scrollback one earlier page at a time Nov 27, 2026

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tmux capture on 3c0ac29d establishes what happens: the pre-Dim sentinel disappears, the draft stays, and there is no alternate-screen switch. It does not establish that the warning is visible before paging from the normal typing position.

[P2] The warning can be above the viewport when /earlier clears shell output. The hint is committed above the transcript, and the composer directly runs the command. Resume into a transcript taller than the terminal, stay at the bottom, and type /earlier: the only warning is already offscreen. A full-pane capture including scrollback can see it when the user cannot. If replacing native scrollback is the agreed design, use an in-view warning with a chance to cancel before the first destructive redraw, and test from the composer with the hint offscreen. Assert that cancel preserves the shell sentinel and draft, and that confirmation reveals the page. Fullscreen and at-start paging should not need that confirmation. Please also link or name the maintainer decision credited in the summary so the accepted boundary is verifiable.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes native scrollback /earlier redraw the loaded branch in chronological order in the same terminal, one earlier page per invocation, keeps the draft and the live output, and has fullscreen reveal the page at the join. This head adds a native-only warning to the paging hint that paging replaces terminal output from before Dim started.

The maintainer decision recorded in the PR body accepts replacing native scrollback, including shell output from before Dim started, and the new warning is present on the native hint. I agree with the existing changes-requested review on whether that warning is visible from the normal typing position; I do not repeat that finding.

Fixed and withdrawn:

  • Warning coverage. The warning is appended only for native scrollback (crates/dim-cli/src/ui/transcript/blocks.rs:791-798), so fullscreen keeps its count and Enter form without it. All ten chrome tables define the key (crates/dim-cli/src/ui/i18n/*/chrome.rs), and cargo run --locked -p xtask-check reports i18n keys passed (10 tables, 1087 literal keys, 67 key arguments without a literal). The paging test passes.
  • ToolResult boundary. crates/dim-client/src/window.rs:65-68 is unchanged by this commit. A tool result is newer than its own request's thinking deltas and older than the next request's, so finishing pending thoughts there cannot cut a continuing thought; the extended PTY test still fails without the arm at 1a2178b9 and passes here.
  • Docs story. README (crates/dim-cli/README.md:1364-1375), English Timeline UI (docs/design/timeline-ui.md:131), cli-commands (docs/design/cli-commands.md:3802-3817) and the PR body agree on the replacement, the warning and the at-start notice. The zh mirror is the exception below.

Remaining findings:

[P2] The zh Timeline UI still describes append without clearing.

Problem: docs/zh/design/timeline-ui.md:131 says scrollback appends one page at the terminal end, does not reprint shown messages and does not clear the screen. The English paragraph (docs/design/timeline-ui.md:131) now says the same-terminal redraw, and the contract (docs/design/cli-commands.md:3802-3817) says the redraw replaces native scrollback. The implementation clears scrollback with CSI 3J and repaints (crates/dim-cli/src/ui/render/screen.rs:489). The PR edits this zh file, so the stale paragraph is in scope.

Failure scenario: a Chinese reader follows the zh design doc, expects append-only paging that keeps earlier terminal output, and loses it on the first /earlier.

Fix: replace the paragraph with the English meaning: one preceding page per /earlier, redraw of the loaded conversation oldest to newest, replacement of native scrollback including output from before Dim started, the hint warning, and the at-start notice without a redraw. I checked the rest of docs/zh; the zh cli-commands has no counterpart section, so line 131 is the only stale mirror of this behavior.

[P3] The cli-commands example omits the warning.

docs/design/cli-commands.md:3821-3826 shows the native hint without the warning in both /earlier columns, while the actual hint now ends with Clears terminal output from before Dim started (crates/dim-cli/src/ui/transcript/blocks.rs:791-798) and the README example shows it (crates/dim-cli/README.md:1375). Add the warning to both hint columns; the final column, where the beginning is loaded, correctly drops the hint. Optional.

[P3] The new warning is only asserted by the local tmux scenario, and the test routing row does not list it.

scripts/tui-tmux/scenarios.mjs:201-236 checks that the warning is on the native hint and absent in fullscreen and that the pre-Dim sentinel is gone after each redraw, but the tmux suite is local-only and tmux is not installed here. The PTY paging tests wait for Earlier messages · /earlier as a substring, so they pass even if the warning disappears. The scenario row (docs/architecture/tui-e2e.md:102) lists neither check. Add a flow assertion or a render_block unit test for Block::LoadMore with interactive false and true, and add the checks to the row. Optional.

[P3] The hint understates Dim's own committed output loss.

rebuild_window clears the commit state, cards, message blocks and history (crates/dim-cli/src/ui/tui.rs:7925-7939), and the redraw repaints only the projected transcript. Committed notices, reports, shell runs, the failure line and the resume boundary are not part of that history, so the first /earlier drops them. The warning says only Clears terminal output from before Dim started (crates/dim-cli/src/ui/transcript/blocks.rs:795), while cli-commands says the redraw replaces native scrollback. Scenario: a background report or a ! shell run output is on screen, then /earlier; it is gone and the hint did not warn about it. Say all terminal output in the hint, or reprint the committed non-transcript rows. Optional.

[P3] The carry and at_start gaps are unchanged.

The live-settle split in ThoughtBoundary still applies (crates/dim-client/src/window.rs:56-111, crates/dim-cli/src/projection.rs:1346-1395, crates/dim-cli/src/projection.rs:2086-2097): a thought whose first delta is in an older page and whose settle arrives live can still render as a duration-less row beside the settled live row. The member history path keeps the same carry and at_start computation with no test (crates/dim-cli/src/session_host/member.rs:570-599). A queued earlier read that ends at AtStart clears reveal_pending without the Beginning of conversation notice (crates/dim-cli/src/ui/tui.rs:2637-2642), so /earlier can appear to do nothing. The new commit does not touch these paths. Optional for this PR; a follow-up is fine.

Verification at 3c0ac29d: cargo fmt --all -- --check --config error_on_line_overflow=true exits 0; cargo test -p dim-cli --lib has 818 passed; cargo test -p dim-client has 3 passed; the six targeted cli_session_flow, cli_flow and cli_tui_flow tests pass; cargo run --locked -p xtask-check passes. tmux is not installed here, so I did not run the updated earlier_reveals_resumed_history_in_both_modes scenario. The paging test fails at base 1997683c (the paging hint is missing) and at 543c9292 before the redraw (the CLI closes) and passes here.

CI at this head: changes, macos-native, scripts and windows-cli passed; verify (linux) was in progress and ci-ok had not run when checked; static-checks, acp-registry, dependencies and web were skipped. Mergeable is true and the merge state is blocked by the pending checks and reviews. Merge-tree is clean against origin/main 7d9148bb and the open PRs #2227 69751839, #2274 33d5e306 and #2273 ce2fed1d.

REQUEST_CHANGES

Comment thread docs/zh/design/timeline-ui.md Outdated
- 跳转会关闭面板。全屏选中这条消息,与 Tab 选中一样,之后可用选取的按键。scrollback 不能往上走:还没画出的消息从它开始作为一页更早历史画出;已经画出的给出提示,`/tui` 可直接跳到它。

恢复会话时只画最新 100 条。全屏在 transcript 顶部放一行加载按钮(`↑ 130 earlier messages · Enter or click to load`)。点击它(或用 Tab 走到它再按 `Enter`)、在画出的顶部按 PageUp、或输入 `/earlier`,都会在已画出的消息上方画出前 100 条,没有加载过的就向 daemon 读取,并让原来最早的那条消息留在视图顶部。scrollback 没有这一行,更早的历史由 `/timeline` 跳转画出。它取代了 `/history`:后者把更早的消息接在最新消息之后翻页画出。
恢复会话时从最近的窗口显示最多 100 条消息。翻页提示只在已显示的最早一条消息上方。Scrollback 每次 `/earlier` 只在原终端末尾追加「更早的消息」一页,紧接在此前最早的消息之前,不重复打印已显示的消息。连续翻页时,后追加的页更早,每页内部仍从旧到新。到头后只提示已到对话开头。实时消息继续接在末尾;不切屏、不清屏、不重新连接会话,也不提交草稿。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph still says scrollback appends one page at the terminal end, does not reprint shown messages and does not clear the screen. The English paragraph (docs/design/timeline-ui.md:131) now says the same-terminal redraw, and the contract (docs/design/cli-commands.md:3802-3817) says the redraw replaces native scrollback. The implementation clears scrollback with CSI 3J and repaints (crates/dim-cli/src/ui/render/screen.rs:489). Replace this with the English meaning: one preceding page per /earlier, redraw of the loaded conversation oldest to newest, replacement of native scrollback including output from before Dim started, the hint warning, and the at-start notice without a redraw. The zh cli-commands has no counterpart section, so this is the only stale mirror. P2.

let mut label = tf("Earlier messages · {key}", &[("key", "/earlier")]);
if !interactive {
label.push_str(" · ");
label.push_str(t("Clears terminal output from before Dim started"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning names only output from before Dim started, but the redraw also clears Dim's own committed rows. rebuild_window clears the commit state and history (crates/dim-cli/src/ui/tui.rs:7925-7939), and the repaint contains only the projected transcript; committed notices, reports, shell runs, the failure line and the resume boundary are not reprinted. A background report or a ! run output on screen is lost on the first /earlier, and this hint does not warn about it. Say all terminal output, or reprint those rows. P3.

Comment thread docs/design/cli-commands.md Outdated
initial window
live output
Resume First /earlier Second /earlier
↑ Earlier messages ↑ Earlier messages messages 1–10

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example omits the warning. The actual native hint ends with Clears terminal output from before Dim started (crates/dim-cli/src/ui/transcript/blocks.rs:791-798), and the README example shows it (crates/dim-cli/README.md:1375). Both /earlier columns should show the warning while the hint is present; the final column, where the beginning is loaded, correctly drops the hint. P3.

Comment thread docs/architecture/tui-e2e.md Outdated

| Area | Scenario | Verifies |
| --- | --- | --- |
| terminal-modes | `earlier_reveals_resumed_history_in_both_modes` | Scrollback redraws the preceding page above newer messages without duplicates, switching screens or losing the draft; fullscreen reveals the preceding page at the join; both report the beginning |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The row does not list what the scenario now asserts: the pre-Dim sentinel is present before paging, the warning is on the native hint and absent in fullscreen, and the sentinel is gone after each redraw (scripts/tui-tmux/scenarios.mjs:201-236). The tmux suite is local-only and tmux is not installed here; the PTY paging tests wait for Earlier messages · /earlier as a substring, so CI would pass if the warning disappeared. Add the checks to the Verifies column and add a flow or render_block assertion for the native and fullscreen hint forms. P3.

@zjywill

zjywill commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@eric8810 @yyhhyyyyyy Keeping the warning at the top only, with no confirmation step, is my decision as maintainer. I understand that someone typing /earlier at the bottom of a long conversation may not see the warning. Even in that case the command should redraw in the same terminal without a second prompt. I accept that this replaces native scrollback, including pre-Dim shell output and output not represented in the conversation.

The documentation commit corrects the Chinese Timeline UI description and records this choice in the paging contract. It does not change runtime behavior. Please review against this decision.

@eric8810

Copy link
Copy Markdown
Collaborator

Noted \u2014 thanks for recording the maintainer decision. I won't make a technical/UI review call here; that remains with the PR reviewers.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At f8d6de09, the PR makes native scrollback /earlier redraw the loaded branch in chronological order in the same terminal, one earlier page per invocation, keeps the draft and live output, and shows the same page at the join in fullscreen. The new commit is docs-only and records the maintainer decision that the warning stays in the hint above the oldest message and that running /earlier from the composer does not ask for confirmation, even when the hint is offscreen.

The previous P2 in the zh mirror is fixed: docs/zh/design/timeline-ui.md:131-133 now describes the same-terminal redraw, replacement of native scrollback, the warning, no confirmation, and the at-start notice, and its link to ../../design/cli-commands.md#loading-earlier-conversation resolves. The cli-commands example P3 is fixed by the arrow legend and the full hint text. The tui-e2e routing row P3 is fixed and matches scripts/tui-tmux/scenarios.mjs:201-260. I withdraw the old hint-understatement P3 for the boundary the maintainer accepted, and I do not repeat the offscreen warning request. The carry and at_start gaps remain optional and unchanged.

P2. The new example says a ! shell run is not restored, but a recorded ! run is a transcript row and is redrawn.

Problem: docs/design/cli-commands.md:3808-3809 says "Only conversation rows are redrawn; other terminal output, such as the output of a ! shell command, is not restored." A recorded ! run is a conversation row.

Failure scenario: A user reads the contract and expects ! output to disappear after /earlier, or an implementation follows the sentence and drops it, even though the transcript contract keeps it and the redraw repaints it.

Evidence: crates/dim-cli/src/projection.rs:404 creates RowKind::Shell for the recorded <dim-shell-input> marker; crates/dim-cli/src/model/view.rs:47-52 counts Shell in the history window; crates/dim-cli/src/ui/transcript/block.rs:133-140 maps it to Block::Shell; crates/dim-cli/src/ui/tui.rs:6208-6222 records projected rows and reflow_history at crates/dim-cli/src/ui/tui.rs:8622-8636 repaints them. crates/dim-cli/src/ui/tui.rs:6312-6321 handles only private or unrecorded runs, the class the rebuild drops. docs/design/timeline-ui.md:198 lists a !! run, a notice, the failure line and the resume boundary as rows outside the transcript, not a recorded ! run. The redraw also reprints the banner (crates/dim-cli/src/ui/tui.rs:7868-7870), so "only conversation rows" is too narrow.

Fix: replace the example with a !! run, a notice, a report, the failure line or the resume boundary, and say that transcript rows and the banner are redrawn. This is a one-clause correction.

Verification at f8d6de09: git diff --check exits 0; cargo fmt --all -- --check --config error_on_line_overflow=true exits 0; node scripts/tui-tmux.test.mjs has 6 passing tests; node scripts/adr-check.mjs reports "ADR freeze passed: 3 changed files"; the zh link target and heading anchor exist. The code is unchanged from 3c0ac29d, where cargo test -p dim-cli --lib had 818 passing tests, cargo test -p dim-client had 3, the six targeted cli_flow and cli_tui_flow tests passed, and cargo run --locked -p xtask-check passed. CI at this head: changes, macos-native, scripts, verify (linux), windows-cli and ci-ok pass; static-checks, acp-registry, dependencies and web are skipped. The PR is open, not draft, mergeable true and blocked by this review.

REQUEST_CHANGES

Comment thread docs/design/cli-commands.md Outdated
this replaces native scrollback. Losing shell output from before Dim started is an
accepted consequence of keeping the loaded conversation in chronological order in the
same terminal. Only conversation rows are redrawn; other terminal output, such as the
output of a `!` shell command, is not restored. The warning appears only in the hint above

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. This example is wrong: a recorded ! run is a transcript row and is redrawn. crates/dim-cli/src/projection.rs:404 creates RowKind::Shell for the recorded <dim-shell-input> marker; crates/dim-cli/src/model/view.rs:47-52 counts Shell in the history window; crates/dim-cli/src/ui/transcript/block.rs:133-140 maps it to Block::Shell; crates/dim-cli/src/ui/tui.rs:6208-6222 records projected rows; and reflow_history at crates/dim-cli/src/ui/tui.rs:8622-8636 repaints them. crates/dim-cli/src/ui/tui.rs:6312-6321 handles only private or unrecorded runs, the class the rebuild drops. docs/design/timeline-ui.md:198 lists a !! run, a notice, the failure line and the resume boundary as rows outside the transcript, not a recorded ! run. The redraw also reprints the banner (crates/dim-cli/src/ui/tui.rs:7868-7870), so "only conversation rows" is too narrow.

Failure scenario: a user expects ! output to be lost and reports it as a bug when it returns, or an implementation drops a transcript row to follow this sentence.

Fix: replace the example with a !! run, a notice, a report, the failure line or the resume boundary, and say that transcript rows and the banner are redrawn.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 89f0049.

Keep the first durable delta and the closing timestamp together across backward reads so native scrollback does not commit a partial thought. Exercise splits between deltas and before settlement, and show the actual single-page append order in the command example.

Amp-Thread-ID: https://ampcode.com/threads/T-01a21717-81ee-72c0-b263-45c584e4b326
Indexed transcript pages omit model-start. Loop consumes input before it starts the next request, so a consumed input also bounds the backward scan for that request’s first thinking delta. Merely submitting or applying input does not establish this boundary.

Amp-Thread-ID: https://ampcode.com/threads/T-01a21717-81ee-72c0-b263-45c584e4b326
@zjywill
zjywill force-pushed the fix/scrollback-history branch from f8d6de0 to 89f0049 Compare November 28, 2026 02:06
@zjywill
zjywill requested a review from yyhhyyyyyy November 28, 2026 02:11

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two review items are resolved on 89f00496: the maintainer explicitly accepted a warning only at the oldest message, without a second prompt even when the warning is offscreen, and the paging contract now correctly says the banner and recorded ! runs are replayed while private !! runs are not. The earlier native tmux captures verify chronological redraw, draft survival and loss of pre-Dim scrollback without switching screens; fullscreen lands at the page join. On the rebased candidate, the exact Linux job passed the page/draft and complete-Thinking cases.

I am holding formal approval while ci-ok is red. The only failing test I found in that job is the image/screenshot compaction fixture, with the same History close fault seen outside this PR and tracked in #2265. That is separate from the /earlier behavior; the passing paging tests do not clear the CI gate.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes native scrollback /earlier reveal one preceding page and redraw the loaded branch in the same terminal, oldest to newest, with the draft below, and has fullscreen reveal the preceding page at the join; both modes report the beginning instead of drawing past it.

At 89f00496 the round-9 P2 is fixed. docs/design/cli-commands.md:3816-3820 now says the redraw restores the banner and conversation rows, including recorded ! shell runs, and that private !! runs are not part of the conversation and are not restored. That matches the code: a recorded shell marker becomes RowKind::Shell (crates/dim-cli/src/projection.rs:404), the native reveal clears the commit state and replays rows from the new floor (crates/dim-cli/src/ui/tui.rs:8088-8107, crates/dim-cli/src/ui/tui.rs:6434-6470), the banner is committed first on that frame (crates/dim-cli/src/ui/tui.rs:6391-6400), and private or unrecorded runs only enter the local shell_runs list (crates/dim-cli/src/ui/tui.rs:4320-4340), which the rebuilt history does not include (crates/dim-cli/src/ui/tui.rs:8161-8175). The warning is appended only to the scrollback hint (crates/dim-cli/src/ui/transcript/blocks.rs:791-800); its top-only placement and the absence of a confirmation are the maintainer's recorded decision, so I do not repeat them.

The zh mirror, the arrow legend in the example, and the tui-e2e row remain consistent. I withdraw the round-9 P2 and all older points. The branch was rebased onto c43003a1; apart from the final docs commit, every PR commit has the same added and removed lines as the previous head, so the rebase introduced no semantic drift, and the full PR at this head has no remaining blocker.

Verification at this head: git diff --check exits 0; cargo fmt --all -- --check --config error_on_line_overflow=true exits 0; cargo test -p dim-client has 3 passing tests; cargo test -p dim-cli --lib has 818 passing; targeted cli_session_flow tests tui_task_history_resume_windows_complete_main_pages_and_preserves_the_draft, tui_resume_draws_complete_thinking_in_the_first_indexed_window, and tui_lines_count_a_cut_read_from_a_transcript_window pass; targeted cli_flow tests tui_a_resumed_line_without_a_configuration_read_reports_it_once and tui_earlier_typed_before_a_queued_move_loads_no_new_centre pass; node scripts/tui-tmux.test.mjs has 6 passing tests; node scripts/adr-check.mjs reports "ADR freeze passed: 3 changed files"; cargo run --locked -p xtask-check exits 0. CI at this head: windows-cli, scripts, macos-native and changes pass; verify (linux) and ci-ok fail only in context_flow::product_summary::compaction_chunks_images_as_markers_and_legacy_screenshots_as_text at crates/dim-agent-capabilities/tests/context_flow/product_summary.rs:73 with "storage: unknown session" and "Compaction cut is outside the fixed context history". That file and subsystem are not in this PR, so the failure looks unrelated and needs a rerun. The PR is open, not draft, and mergeable.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial-resume blocker is resolved. The exact Linux PTY fixture renders one settled thought with its duration in both scrollback and fullscreen, including after an ordinary tool continuation, without loading an older page. The exact paging/draft test also passed; the earlier split-history and live handoff evidence still applies.

The native paging blocker is resolved. /earlier redraws the loaded conversation oldest first in the same terminal, fullscreen reveals at the page join, and the documented warning behavior is preserved. I found no remaining blocker in my review.

The image-marker compaction failure is separate from the paging behavior and the required Linux retry is still running. This approval does not clear that gate.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 89f00496. The paging contract now matches the behavior: one preceding page per action, chronological redraw in the same terminal with the draft preserved, recorded ! runs replayed, and private !! runs not restored. The maintained decision is to keep the warning at the oldest message without a second confirmation. The fullscreen join and native scrollback behavior have tmux evidence, and the exact rebased candidate passed the PTY paging/draft and complete-Thinking regressions.

The same-candidate Linux rerun passed all 715 capability tests and ci-ok is green. The earlier image-history fault remains tracked separately in #2265; the rerun does not establish a fix for it.

@zjywill
zjywill merged commit 0a5089a into main Nov 28, 2026
18 of 20 checks passed
@yyhhyyyyyy yyhhyyyyyy mentioned this pull request Nov 28, 2026
3 tasks done
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.

4 participants