Avoid duplicate settled messages when toggling reasoning visibility #31
Description
Problem
Toggling reasoning visibility with Tab can append already displayed user messages to the transcript again. This was reproduced on main 9fb0d50 (0.3.3) and PR #29's original head ccf79b4, so it is an existing issue rather than a regression from the unchanged-footer optimization.
Reproduction
- Start an interactive CLI in a visible 80×24 terminal.
- Submit a prompt such as
CASE_REASONINGand keep the response in the reasoning-stream phase (a local SSE fixture with explicitreasoning_contentworks). - Press Tab to show reasoning, then toggle again.
- Inspect the user transcript and scrollback.
Actual: the already printed > CASE_REASONING appears again. Expected: the reasoning view changes without appending another copy of previously committed user messages.
Observed with xterm.js 6.0.0 connected to a real macOS PTY running each built CLI. This does not depend on a real model or credential.
Investigation and scope
Start with Screen.toggleThinking() in packages/tui/src/screen.ts: it resets CommitTracker and calls the ordinary append-oriented paint path. Review how a visible transcript rebuild differs from new transcript emission. toggleVerbose() and setCwd() use related paths and deserve focused regression checks, but duplication in those paths has not yet been independently confirmed.
This differs from #28: #28 concerns live footer rows entering scrollback; this concerns previously settled transcript being emitted again after a display option changes. Keep the terminal's existing main-screen behavior and avoid an unrelated renderer rewrite.
Acceptance criteria
- Repeated show/hide reasoning toggles do not append duplicate settled user/assistant messages.
- Reasoning can still be revealed and hidden, both during streaming and after completion.
- Newly settled messages are committed exactly once after a toggle; redraw preserves composer text and cursor.
- Regression tests distinguish rebuilding visible content from appending new scrollback, and visible PTY-backed terminal checks cover repeated toggles with a populated transcript.
Please propose a focused correction with tests; this is not tagged as a good first issue because it touches transcript/scrollback ownership.
Activity