Prepare the TUI for conversation recaps (#40696)

## What changed

- Forward terminal focus changes through the TUI event stream and handle them across interactive screens.
- Track completed turns and recap eligibility across active, resumed, and switched threads.
- Add bounded recent-conversation prompt construction and a wrapping `Conversation recap` history cell.
- Cover focus timing, repeat eligibility, restored progress, UTF-8 prompt limits, and recap rendering with unit and snapshot tests.

GitOrigin-RevId: d7542c18b2bb1e72f5906f563898645bb526255f
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-08-25 20:51:34 +00:00
1 parent 725b3a44f8
commit 7c1e36c23f
25 files changed
+867 -34

No files matched your search

+18 -2
View File
@@ -226,6 +226,7 @@ mod permission_shortcuts;
mod pets;
mod platform_actions;
mod plugin_mentions;
mod recap;
mod replay_filter;
mod resize_reflow;
mod safety_buffering;
@@ -633,6 +634,7 @@ pub(crate) struct App {
// Serialize hook enablement writes per hook so stale completions cannot
// persist an older toggle after a newer one.
pending_hook_enabled_writes: HashMap<String, Option<bool>>,
recap: recap::RecapState,
}
#[derive(Debug, Clone, PartialEq)]
@@ -754,7 +756,10 @@ impl App {
event: TuiEvent,
) -> Result<AppRunControl> {
let screen_size = tui.screen_size_for_event(&event)?;
if !matches!(&event, TuiEvent::Key(_) | TuiEvent::Paste(_)) {
if !matches!(
&event,
TuiEvent::Key(_) | TuiEvent::Paste(_) | TuiEvent::FocusLost
) {
self.expire_pending_key_chord();
self.handle_draw_pre_render(tui, screen_size)?;
}
@@ -768,6 +773,16 @@ impl App {
event
};
match &event {
TuiEvent::FocusLost => {
self.recap.note_focus_lost(Instant::now());
}
TuiEvent::FocusGained => {
self.recap.note_focus_gained();
}
_ => {}
}
if self.overlay.is_some() {
let _ = self
.handle_backtrack_overlay_event(tui, app_server, event)
@@ -786,7 +801,7 @@ impl App {
let pasted = pasted.replace("\r\n", "\n").replace('\r', "\n");
self.chat_widget.handle_paste(pasted);
}
TuiEvent::Draw | TuiEvent::Resume | TuiEvent::Resize(_) => {
TuiEvent::Draw | TuiEvent::Resume | TuiEvent::Resize(_) | TuiEvent::FocusGained => {
if self.backtrack_render_pending {
self.rebuild_transcript_after_backtrack(tui, screen_size.into())?;
self.backtrack_render_pending = false;
@@ -839,6 +854,7 @@ impl App {
self.app_event_tx.send(AppEvent::LaunchExternalEditor);
}
}
TuiEvent::FocusLost => {}
}
}
Ok(AppRunControl::Continue)