Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
perf(agent-tui): scan the live reply for answer text once per frame
Akarshan Biswas72e9157e2d97
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex b70c2bdcb..7fe41c883 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -19372,7 +19372,7 @@ fn draw(f: &mut Frame, app: &mut App) {// inlines every block, so this only touches the default-folded case.let active_reasoning = app.status == Status::Running&& !app.show_reasoning- && !has_answer_text(&app.assistant_buf)+ && !answer_started&& last_answer.is_none_or(|a| i > a)&& app.reasoning_blocksdiff --git a/src-tauri/src/core/cli/tui/tests/perf.rs b/src-tauri/src/core/cli/tui/tests/perf.rsindex 8d26eb80a..fe4b921b4 100644--- a/src-tauri/src/core/cli/tui/tests/perf.rs+++ b/src-tauri/src/core/cli/tui/tests/perf.rs@@ -213,3 +213,21 @@ fn tui_perf_report() {println!(" /find + 20 n {:.1} ms ({hits} hits)", ms(find_time));println!(" resize 120->100 {:.1} ms", ms(resize));}++/// The active-reasoning check in `draw` runs per transcript row; the answer+/// scan it needs is the same for every row, so a frame must do it at most+/// once rather than once per row of history.+#[test]+fn a_streaming_frame_scans_the_reply_at_most_once() {+ let mut app = long_session(200);+ app.status = Status::Running;+ app.apply(StreamEvent::Token {+ text: "<think>weighing it</think>The answer so far".into(),+ });+ let mut term = terminal(100, 30);+ draw_on(&mut term, &mut app);+ take(&ANSWER_SCANS);+ draw_on(&mut term, &mut app);+ let scans = take(&ANSWER_SCANS);+ assert!(scans <= 1, "one frame scanned the reply {scans} times");+}