Keep interrupt guidance visible during TUI streaming (#64018)

## Why

Streaming output hides the working status row and its interrupt shortcut.
When a message without a phase finishes before the turn does, the status
row can also stay hidden while Codex is still working.

## What changed

Show the configured interrupt shortcut in the composer footer while output
streams and the status row is hidden. With the default binding, the footer
shows `esc twice to interrupt` in Vim insert mode.

Keep the status row visible through whitespace-only output. Restore it
after a message without a phase completes and the stream queues drain if
the turn is still running.

## Testing

Cover whitespace-only output, footer hints with a draft and in Vim modes,
hint layout at narrow widths, and status restoration before turn completion.

GitOrigin-RevId: 246180593baf2d6ead0e84634bf7bd8ee4ec3ea5
This commit is contained in:
Eric Traut
2026-11-25 23:35:26 +00:00
committed by copyberry
parent 80ea5901ad
commit 58b14699ec
12 changed files with 144 additions and 45 deletions
@@ -1498,6 +1498,12 @@ impl ChatComposer {
self.draft.textarea.is_vim_enabled()
}
pub(super) fn is_agent_command(&self) -> bool {
!self.draft.is_bash_mode
&& parse_slash_name(self.draft.textarea.text())
.is_some_and(|(name, _, _)| matches!(name, "agents" | "subagents"))
}
/// Return whether Escape should be routed to the textarea before popups.
///
/// Vim insert mode owns Escape as a transition back to normal mode. The app
@@ -81,6 +81,7 @@ pub(crate) struct ComposerRenderOptions<'a> {
Option<&'a std::cell::RefCell<crate::rendered_selection::RenderedSelection>>,
/// Reserve a shared hint row independently of whether it currently contains a notice.
pub(crate) composer_gap: Option<&'a crate::bottom_pane::ComposerGap>,
pub(crate) stream_interrupt_key: Option<ShortcutHint>,
pub(crate) working_tip: Option<&'a crate::turn_tip::TurnTip>,
pub(crate) warning_count: usize,
pub(crate) textarea_right_reserve: u16,
@@ -18,6 +18,7 @@ enum Kind {
Agents,
Shortcuts,
Action,
Interrupt,
Side,
SideNav,
AgentName,
@@ -38,7 +39,10 @@ impl Kind {
}
fn left(self) -> bool {
matches!(self, Agents | Shortcuts | Action | Side | SideNav)
matches!(
self,
Agents | Shortcuts | Action | Interrupt | Side | SideNav
)
}
fn row(self, two_rows: bool) -> usize {
@@ -176,8 +180,8 @@ impl Hints {
}
}
for kind in [
Action, Side, Shell, Vim, Plan, Goal, Ide, Warning, Context, SideNav, AgentName,
Agents, Shortcuts,
Action, Side, Shell, Vim, Plan, Interrupt, Goal, Ide, Warning, Context, SideNav,
AgentName, Agents, Shortcuts,
] {
if !overflow[kind.row(two)] {
continue;
@@ -313,8 +317,9 @@ impl ChatComposer {
[Line::from(agent.clone().set_style(secondary_text_style()))],
);
}
if mode == FooterMode::ComposerEmpty && can_navigate && !self.is_in_paste_burst() {
if self.agents_navigation_available() {
if can_navigate && !self.is_in_paste_burst() {
let empty = mode == FooterMode::ComposerEmpty;
if empty && self.agents_navigation_available() {
hints.add(
Agents,
[shortcut(
@@ -323,7 +328,22 @@ impl ChatComposer {
)],
);
}
if let Some(key) = self.footer.toggle_shortcuts_key {
let escape = KeyEvent::from(KeyCode::Esc);
if let Some(key) = options.stream_interrupt_key
&& !(matches!(key, key_hint::ShortcutHint::Single(binding) if binding.parts().0 == KeyCode::Esc)
&& self.is_agent_command())
{
let label = if key.is_press(escape) && self.should_handle_vim_insert_escape(escape)
{
" twice to interrupt"
} else {
" to interrupt"
};
hints.add(
if empty { Action } else { Interrupt },
[shortcut(key, label)],
);
} else if empty && let Some(key) = self.footer.toggle_shortcuts_key {
hints.add(Shortcuts, [shortcut(key, " for shortcuts")]);
}
}
+2 -9
View File
@@ -268,7 +268,6 @@ pub(crate) enum CancellationEvent {
NotHandled,
}
use crate::bottom_pane::prompt_args::parse_slash_name;
pub(crate) use chat_composer::ChatComposer;
pub(crate) use chat_composer::ChatComposerConfig;
pub(crate) use chat_composer::ClipboardPasteTarget;
@@ -1895,18 +1894,11 @@ impl BottomPane {
}
pub(crate) fn should_interrupt_running_task(&self, key_event: KeyEvent) -> bool {
let is_agent_command = self
.composer_text()
.lines()
.next()
.and_then(parse_slash_name)
.is_some_and(|(name, _, _)| matches!(name, "agents" | "subagents"));
self.keymap.chat.interrupt_turn.is_pressed(key_event)
&& !(self.shortcut_overlay_visible()
&& key_hint::plain(KeyCode::Esc).is_press(key_event))
&& self.is_task_running
&& !(is_agent_command && key_event.code == KeyCode::Esc)
&& !(key_event.code == KeyCode::Esc && self.composer.is_agent_command())
&& self.no_modal_or_popup_active()
&& !self.composer_should_handle_vim_insert_escape(key_event)
}
@@ -2691,6 +2683,7 @@ impl BottomPane {
let composer: RenderableItem<'_> = if let Some(questions) = question_editor {
RenderableItem::Borrowed(questions.as_ref())
} else if options.max_height.is_none()
&& options.stream_interrupt_key.is_none()
&& options.image_previews.is_none()
&& options.textarea_right_reserve == 0
&& options.warning_count == 0
+11
View File
@@ -369,6 +369,17 @@ impl ChatWidget {
};
options.rendered_selection = Some(&self.rendered_selection);
options.image_previews = self.composer_images.as_ref();
if self.turn_lifecycle.agent_turn_running
&& !self.statusline_disconnected
&& self.bottom_pane.status_widget().is_none()
&& self.input_queue.pending_steers.is_empty()
&& (self.stream_controller.is_some() || self.plan_stream_controller.is_some())
{
options.stream_interrupt_key = self
.bottom_pane
.keymap()
.primary_hint(KeymapContext::Chat, "interrupt_turn");
}
options.warning_count = self.warning_display_state.count;
options.textarea_right_reserve = right_reserve;
options.separate_status_line = options.command_popup_placement
@@ -0,0 +1,12 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "hook_status_frame(&chat, 60)"
---
" "
"• Working (0s • esc to interrupt) "
" "
" "
"› Ask Codex to do anything "
" "
" GPT-5.6-Sol default · /tmp/project "
" ? for shortcuts "
@@ -0,0 +1,9 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "hints.join(\"\\n\")"
---
" esc to interrupt "
" tab to queue message · esc to interrupt "
" tab to queue "
" esc twice to interrupt Vim: Insert "
" esc to interrupt Vim: Normal "
+14 -8
View File
@@ -195,12 +195,12 @@ impl ChatWidget {
.unwrap_or(true)
}
/// Restore the status indicator only after commentary completion is pending,
/// Restore the status indicator only after message completion is pending,
/// the turn is still running, and all stream queues have drained.
///
/// This gate prevents flicker while normal output is still actively
/// streaming, but still restores a visible "working" affordance when a
/// commentary block ends before the turn itself has completed.
/// message ends before the turn itself has completed.
pub(super) fn maybe_restore_status_indicator_after_stream_idle(&mut self) {
if !self.status_state.pending_status_indicator_restore
|| !self.bottom_pane.is_task_running()
@@ -300,7 +300,13 @@ impl ChatWidget {
message: &str,
phase: Option<MessagePhase>,
) {
if self.stream_controller.is_none() && !message.is_empty() {
if !message.trim().is_empty()
&& self
.stream_controller
.as_ref()
.is_none_or(|stream| !stream.has_text())
{
self.stream_controller = None;
let displayed =
parse_assistant_markdown(message, self.config.cwd.as_path()).visible_markdown;
self.handle_streaming_delta(displayed);
@@ -563,9 +569,7 @@ impl ChatWidget {
/// Handle completion of an `AgentMessage` turn item.
///
/// Commentary completion sets a deferred restore flag so the status row
/// returns once stream queues are idle. Final-answer completion (or absent
/// phase for legacy models) clears the flag to preserve historical behavior.
/// An unphased message can finish while the turn still has work to do.
pub(super) fn on_agent_message_item_completed(
&mut self,
item: AgentMessageItem,
@@ -755,7 +759,9 @@ impl ChatWidget {
}
self.status_state.pending_status_indicator_restore = item.questions.is_some()
|| match item.phase {
// Models that don't support preambles only output AgentMessageItems on turn completion.
None if self.turn_lifecycle.agent_turn_running && !self.statusline_disconnected => {
true
}
Some(MessagePhase::FinalAnswer) | None => {
!self.input_queue.pending_steers.is_empty()
}
@@ -784,7 +790,7 @@ impl ChatWidget {
///
/// `scope` selects paced, catch-up, or replay draining. While lines are actively streaming
/// we hide the status row to avoid duplicate "in progress" affordances. We only re-show
/// the row after commentary completion once stream queues are idle.
/// the row after message completion once stream queues are idle.
pub(crate) fn run_commit_tick_with_scope(&mut self, scope: CommitTickScope) {
let now = Instant::now();
let outcome = run_commit_tick(
@@ -2684,22 +2684,53 @@ fn assert_goal_paused_event(
}
#[tokio::test]
async fn idle_commit_ticks_do_not_restore_status_without_commentary_completion() {
async fn unphased_stream_keeps_activity_visible_until_turn_completion() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
handle_turn_started(&mut chat, "turn-1");
chat.on_task_started();
assert_eq!(chat.bottom_pane.status_indicator_visible(), true);
chat.on_agent_message_delta("Final answer line\n".to_string());
let whitespace = "\u{3000}\n";
handle_agent_message_delta(&mut chat, whitespace);
chat.on_commit_tick();
drain_insert_history(&mut rx);
assert!(drain_insert_history(&mut rx).is_empty());
assert!(chat.bottom_pane.status_indicator_visible());
complete_assistant_message(&mut chat, "msg-1", whitespace, /*phase*/ None);
assert!(chat.bottom_pane.status_indicator_visible());
assert_eq!(chat.bottom_pane.status_indicator_visible(), false);
assert_eq!(chat.bottom_pane.is_task_running(), true);
// A second idle tick should not toggle the row back on and cause jitter.
chat.on_agent_message_delta("Checking the workbook.\n".to_string());
chat.on_commit_tick();
assert_eq!(chat.bottom_pane.status_indicator_visible(), false);
chat.on_commit_tick();
let footer = |chat: &ChatWidget, width| {
hook_status_frame(chat, width)
.lines()
.last()
.unwrap()
.to_owned()
};
assert!(!chat.bottom_pane.status_indicator_visible());
let mut hints = vec![footer(&chat, 60)];
chat.apply_external_edit("Follow up".into());
hints.push(footer(&chat, 60));
hints.push(footer(&chat, 26));
chat.apply_external_edit(String::new());
chat.bottom_pane.set_vim_enabled(/*enabled*/ true);
chat.handle_key_event(KeyCode::Insert.into());
hints.push(footer(&chat, 60));
chat.handle_key_event(KeyCode::Esc.into());
hints.push(footer(&chat, 60));
chat.bottom_pane.set_vim_enabled(/*enabled*/ false);
assert_chatwidget_snapshot!("streaming_interrupt_hint", hints.join("\n"));
complete_assistant_message(
&mut chat,
"msg-2",
"Checking the workbook.",
/*phase*/ None,
);
assert_chatwidget_snapshot!(
"paused_unphased_message",
hook_status_frame(&chat, /*width*/ 60)
);
handle_turn_completed(&mut chat, "turn-1", /*duration_ms*/ None);
assert!(!chat.bottom_pane.status_indicator_visible());
}
#[tokio::test]
@@ -20,7 +20,7 @@ Zoomed
› xchild draft!
GPT-6.2-Sol default · Agent
tab to queue message · Side from main thread · ⌃/ to switch · ⌃c to close
tab to queue message · esc to interrupt · Side from main thread · ⌃/ to switch · ⌃c to close
Restored
parent-24 │ Side chat × +
│• unfinished answer
@@ -39,7 +39,7 @@ parent-29
› xparent draft-! │› xchild draft!
second line │
GPT-6.2-Sol default │ GPT-6.2-Sol default · Agent
│ tab to queue message · Side from main thread · ⌃/ to switch · ⌃c to close
│ tab to queue message · esc to interrupt · Side from main thread · ⌃/ to switch · ⌃c to close
Equalized
parent-24 │ Side chat × +
│• unfinished answer
@@ -58,4 +58,4 @@ parent-29
› xparent draft-! │› xchild draft!
second line │
GPT-6.2-Sol default │ GPT-6.2-Sol default · Agent
│ tab to queue message · Side from main thread · ⌃/ to switch · ⌃c to close
│ tab to queue message · esc to interrupt · Side from main thread · ⌃/ to switch · ⌃c to close
+15 -5
View File
@@ -148,16 +148,19 @@ impl StreamCore {
/// immediately disappear on the next delta. Unterminated prose gets a separate,
/// bounded preview that never advances the stable boundary.
fn push_delta(&mut self, delta: &str) -> bool {
if !delta.is_empty() {
self.state.has_seen_delta = true;
}
self.state.collector.push_delta(delta);
// Keep leading whitespace for Markdown indentation, but don't display it on its own.
let first_text = !self.state.has_text;
if first_text && delta.trim().is_empty() {
return false;
}
self.state.has_text = true;
if delta.contains('\n') {
self.preview = ProsePreview::default();
}
let mut enqueued = false;
if delta.contains('\n')
if (first_text || delta.contains('\n'))
&& let Some(range) = self.state.collector.commit_complete_source()
{
let source = self.state.collector.committed_source();
@@ -179,6 +182,9 @@ impl StreamCore {
}
fn refresh_preview(&mut self) -> bool {
if !self.state.has_text {
return false;
}
let pending = self.state.collector.pending_source();
let prose_preview = self.holdback_scanner.allows_prose_preview();
let math = self.render_mode == HistoryRenderMode::Rich
@@ -626,6 +632,10 @@ impl StreamController {
}
}
pub(crate) fn has_text(&self) -> bool {
self.core.state.has_text
}
pub(crate) fn push(&mut self, delta: &str) -> bool {
self.core.push_delta(delta)
}
@@ -634,7 +644,7 @@ impl StreamController {
/// markdown source for consolidation.
pub(crate) fn finalize(&mut self) -> (Option<Box<dyn HistoryCell>>, Option<String>) {
let (remaining, source) = self.core.finalize_remaining();
if source.is_empty() {
if !self.has_text() {
self.core.reset();
return (None, None);
}
+3 -3
View File
@@ -37,7 +37,7 @@ struct QueuedLine {
pub(crate) struct StreamState {
pub(crate) collector: MarkdownStreamCollector,
queued_lines: VecDeque<QueuedLine>,
pub(crate) has_seen_delta: bool,
pub(crate) has_text: bool,
}
impl StreamState {
@@ -49,14 +49,14 @@ impl StreamState {
Self {
collector: MarkdownStreamCollector::new(width, cwd),
queued_lines: VecDeque::new(),
has_seen_delta: false,
has_text: false,
}
}
/// Resets collector and queue state for the next stream lifecycle.
pub(crate) fn clear(&mut self) {
self.collector.clear();
self.queued_lines.clear();
self.has_seen_delta = false;
self.has_text = false;
}
/// Drains one queued line from the front of the queue.
pub(crate) fn step(&mut self) -> Vec<HyperlinkLine> {