Skip to content

fix(cli): stop reprinting streamed assistant text after 'Done' in non-compact text mode#3273

Open
nankingjing wants to merge 1 commit into
ultraworkers:mainfrom
nankingjing:fix-duplicate-assistant-text-3258
Open

fix(cli): stop reprinting streamed assistant text after 'Done' in non-compact text mode#3273
nankingjing wants to merge 1 commit into
ultraworkers:mainfrom
nankingjing:fix-duplicate-assistant-text-3258

Conversation

@nankingjing

Copy link
Copy Markdown

Summary

Fixes #3258.

In non-compact text mode (and the interactive REPL), LiveCli::run_turn
prints the entire assistant response twice:

  1. It runs the turn with emit_output = true, so AnthropicRuntimeClient::consume_stream
    already streams and renders every text delta to the terminal live
    (main.rs, ContentBlockDelta::TextDelta / MessageStop).
  2. After spinner.finish("✨ Done") it then calls
    println!("{final_text}"), reprinting the whole message that was just streamed.

The reprint was originally added because Spinner::finish runs
MoveToColumn(0) + Clear(ClearType::CurrentLine) and would otherwise erase
the last streamed line (the streamed tail has no trailing newline). Reprinting
the full text "fixed" the erased line but duplicated everything above it.

Fix

Protect only the last streamed line instead of reprinting the whole message:

  • When there is streamed assistant text, emit a single println!() before
    spinner.finish so the line-clear lands on a fresh empty line rather than the
    last content line.
  • Remove the println!("{final_text}") reprint.

final_text is still computed and used to decide whether a newline is needed,
so the empty-response path (tool-only turns) is unchanged. Compact/JSON paths
use emit_output = false and print the message exactly once — they are
untouched.

Scope

  • 1 file, rust/crates/rusty-claude-cli/src/main.rs (LiveCli::run_turn), +9 -4.
  • No signature/API changes; no test depended on the duplicate output.

Verification

Verified by reading and tracing the streaming path (consume_stream writes each
text delta live when emit_output is true; prepare_turn_runtime(true) is used
by run_turn, while the compact/JSON paths use prepare_turn_runtime(false))
and by inspecting Spinner::finish's line-clear behavior. Not compiled or
executed
in this environment (full Rust workspace build not available here).
The change is a local reordering plus removal of one println!; final_text
remains used, so no unused-variable warning is introduced.

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.

fix(cli): resolve duplicate assistant text printing after 'Done' in non-compact text mode

1 participant