mirror of
https://github.com/openai/codex.git
synced 2026-11-26 07:26:11 +00:00
Improve automatic thread naming in the TUI (#42749)
## Why Automatic title generation used a provisional thread name and only applied the generated result while its thread remained active. Switching threads could therefore leave the originating thread without its generated name. ## What changed - Track title-generation requests by thread so results are persisted for the originating thread, while preserving any name set before generation finishes. - Show a `renaming...` spinner instead of a provisional name, including across thread switches and failure paths. - Add `thread-name` items to the status line and terminal title, and include the generated thread name in both default layouts. ## Testing - Cover automatic naming, manual-name precedence, thread switching, failed requests, deduplication, and status-surface rendering and animation. GitOrigin-RevId: a03ae4849bedec9f62f256fadad72c1685ce46e0
This commit is contained in:
1 parent
8e85265c39
commit
a1294e57f1
32 files changed
+642
-181
No files matched your search
@@ -213,7 +213,6 @@ impl ChatWidget {
|
||||
pet_image_support_override: None,
|
||||
thread_id: None,
|
||||
thread_name: None,
|
||||
pending_automatic_thread_names: HashSet::new(),
|
||||
thread_rename_block_message: None,
|
||||
active_side_conversation: false,
|
||||
blocks_direct_input: false,
|
||||
|
||||
@@ -30,7 +30,6 @@ impl ChatWidget {
|
||||
self.backend_banner_notice_model = None;
|
||||
self.automatic_model_switch_state =
|
||||
backend_banners::AutomaticModelSwitchState::default();
|
||||
self.pending_automatic_thread_names.clear();
|
||||
self.review.recent_auto_review_denials = RecentAutoReviewDenials::default();
|
||||
self.clear_thread_usage_state();
|
||||
}
|
||||
@@ -265,13 +264,7 @@ impl ChatWidget {
|
||||
)));
|
||||
}
|
||||
|
||||
/// Apply a persisted automatic name immediately and suppress its confirmation.
|
||||
pub(crate) fn expect_automatic_thread_name(&mut self, name: String) {
|
||||
self.thread_name = Some(name.clone());
|
||||
self.pending_automatic_thread_names.insert(name);
|
||||
}
|
||||
|
||||
/// Make a confirmed manual rename visible before its queued server notification arrives.
|
||||
/// Update status surfaces before a confirmed manual rename's server notification arrives.
|
||||
pub(crate) fn expect_manual_thread_name(&mut self, thread_id: ThreadId, name: String) {
|
||||
if self.thread_id == Some(thread_id) {
|
||||
self.thread_name = Some(name);
|
||||
@@ -280,23 +273,13 @@ impl ChatWidget {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_thread_name_updated(
|
||||
/// Update name metadata silently, including late and replayed notifications.
|
||||
pub(crate) fn on_thread_name_updated(
|
||||
&mut self,
|
||||
thread_id: ThreadId,
|
||||
thread_name: Option<String>,
|
||||
) {
|
||||
if self.thread_id == Some(thread_id) {
|
||||
let automatic = thread_name
|
||||
.as_ref()
|
||||
.is_some_and(|name| self.pending_automatic_thread_names.remove(name));
|
||||
|
||||
if let Some(name) = thread_name.as_deref()
|
||||
&& !automatic
|
||||
{
|
||||
let cell = Self::rename_confirmation_cell(name, self.thread_id);
|
||||
self.add_boxed_history(Box::new(cell));
|
||||
}
|
||||
|
||||
self.thread_name = thread_name;
|
||||
self.refresh_status_surfaces();
|
||||
self.request_redraw();
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/terminal_title.rs
|
||||
expression: "render_bottom_popup(&chat, 100)"
|
||||
---
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.6-sol default · /tmp/project · renaming... ⠋
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/app_server.rs
|
||||
expression: "format!(\"transcript:\\n{transcript}\\nfooter:\\n{footer}\\ntitle: {title}\")"
|
||||
---
|
||||
transcript:
|
||||
|
||||
footer:
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.6-sol default · /tmp/project · review-fix
|
||||
title: review-fix | project
|
||||
+1
-1
@@ -14,7 +14,7 @@ expression: terminal_title_popup_snapshot(&mut chat)
|
||||
[ ] current-dir Current working directory
|
||||
[ ] activity Spinner while working, action-required message while blocked.
|
||||
[ ] run-state Compact session run-state text (Ready, Working, Thinking)
|
||||
[ ] git-branch Current Git branch (omitted when unavailable)
|
||||
[ ] thread-name Current thread name (omitted when unnamed)
|
||||
|
||||
project | Mixed preview thread | Tasks 0/0
|
||||
Press space to toggle; ←/→ to move; enter to confirm and close; esc to close
|
||||
+1
-1
@@ -14,7 +14,7 @@ expression: terminal_title_popup_snapshot(&mut chat)
|
||||
[ ] current-dir Current working directory
|
||||
[ ] activity Spinner while working, action-required message while blocked.
|
||||
[ ] run-state Compact session run-state text (Ready, Working, Thinking)
|
||||
[ ] thread-title Current thread title, or thread identifier when unnamed
|
||||
[ ] thread-name Current thread name (omitted when unnamed)
|
||||
|
||||
monthly 65% left | weekly 50% left
|
||||
Press space to toggle; ←/→ to move; enter to confirm and close; esc to close
|
||||
+1
-1
@@ -14,7 +14,7 @@ expression: terminal_title_popup_snapshot(&mut chat)
|
||||
[ ] current-dir Current working directory
|
||||
[ ] activity Spinner while working, action-required message while blocked.
|
||||
[ ] run-state Compact session run-state text (Ready, Working, Thinking)
|
||||
[ ] thread-title Current thread title, or thread identifier when unnamed
|
||||
[ ] thread-name Current thread name (omitted when unnamed)
|
||||
|
||||
5.2 credits | ~$1.82
|
||||
Press space to toggle; ←/→ to move; enter to confirm and close; esc to close
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/app_server.rs
|
||||
expression: rendered
|
||||
---
|
||||
• Session renamed to review-fix. To resume this session run codex resume, then select review-fix (123e4567-e89b-12d3-a456-426614174000)
|
||||
@@ -116,6 +116,7 @@ pub(super) struct StatusState {
|
||||
pub(super) terminal_title_status_kind: TerminalTitleStatusKind,
|
||||
pub(super) retry_status_header: Option<String>,
|
||||
pub(super) pending_status_indicator_restore: bool,
|
||||
pub(super) thread_title_generation_pending: bool,
|
||||
}
|
||||
|
||||
impl Default for StatusState {
|
||||
@@ -127,6 +128,7 @@ impl Default for StatusState {
|
||||
terminal_title_status_kind: TerminalTitleStatusKind::Working,
|
||||
retry_status_header: None,
|
||||
pending_status_indicator_restore: false,
|
||||
thread_title_generation_pending: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,9 @@ use codex_utils_sandbox_summary::summarize_permission_profile;
|
||||
use super::status_state::TerminalTitleStatusKind;
|
||||
|
||||
/// Items shown in the terminal title when the user has not configured a
|
||||
/// custom selection. Intentionally minimal: activity indicator + project name.
|
||||
pub(super) const DEFAULT_TERMINAL_TITLE_ITEMS: [&str; 2] = ["activity", "project-name"];
|
||||
/// custom selection. Unnamed threads omit the name until generation starts.
|
||||
pub(super) const DEFAULT_TERMINAL_TITLE_ITEMS: [&str; 3] =
|
||||
["activity", "thread-name", "project-name"];
|
||||
|
||||
/// Braille-pattern dot-spinner frames for the terminal title animation.
|
||||
pub(super) const TERMINAL_TITLE_SPINNER_FRAMES: [&str; 10] =
|
||||
@@ -388,6 +389,26 @@ impl ChatWidget {
|
||||
&self,
|
||||
selections: &StatusSurfaceSelections,
|
||||
) -> Option<Duration> {
|
||||
if self.local_settings.tui.animations
|
||||
&& self.status_state.thread_title_generation_pending
|
||||
&& (selections.status_line_items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
StatusLineItem::ThreadName
|
||||
| StatusLineItem::ThreadTitle
|
||||
| StatusLineItem::SessionId
|
||||
)
|
||||
}) || selections.terminal_title_items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
TerminalTitleItem::ThreadName
|
||||
| TerminalTitleItem::Thread
|
||||
| TerminalTitleItem::SessionId
|
||||
)
|
||||
}))
|
||||
{
|
||||
return Some(TERMINAL_TITLE_SPINNER_INTERVAL);
|
||||
}
|
||||
if self.local_settings.tui.animations
|
||||
&& self.terminal_title_shows_action_required_with_selections(selections)
|
||||
{
|
||||
@@ -677,7 +698,7 @@ impl ChatWidget {
|
||||
/// Returning `None` means "omit this item for now", not "configuration error". Callers rely on
|
||||
/// this to keep partially available status lines readable while waiting for session, token, or
|
||||
/// git metadata.
|
||||
pub(super) fn status_line_value_for_item(&mut self, item: StatusLineItem) -> Option<String> {
|
||||
pub(super) fn status_line_value(&mut self, item: StatusLineItem) -> Option<String> {
|
||||
match item {
|
||||
StatusLineItem::ModelName => Some(self.model_display_name().to_string()),
|
||||
StatusLineItem::ModelWithReasoning => Some(self.model_with_reasoning_display_name()),
|
||||
@@ -784,17 +805,14 @@ impl ChatWidget {
|
||||
}
|
||||
}),
|
||||
StatusLineItem::RawOutput => self.raw_output_mode().then(|| "raw output".to_string()),
|
||||
StatusLineItem::ThreadTitle => self.thread_name.as_ref().map_or_else(
|
||||
|| self.thread_id.map(|id| id.to_string()),
|
||||
|name| {
|
||||
let trimmed = name.trim();
|
||||
if trimmed.is_empty() {
|
||||
self.thread_id.map(|id| id.to_string())
|
||||
} else {
|
||||
Some(trimmed.to_string())
|
||||
}
|
||||
},
|
||||
),
|
||||
StatusLineItem::ThreadName => {
|
||||
self.thread_name.as_deref().and_then(normalize_thread_name)
|
||||
}
|
||||
StatusLineItem::ThreadTitle => self
|
||||
.thread_name
|
||||
.as_deref()
|
||||
.and_then(normalize_thread_name)
|
||||
.or_else(|| self.thread_id.map(|id| id.to_string())),
|
||||
StatusLineItem::WorkspaceHeadline => self.status_line_workspace_headline.clone(),
|
||||
StatusLineItem::TaskProgress => self.terminal_title_task_progress(),
|
||||
}
|
||||
@@ -819,6 +837,7 @@ impl ChatWidget {
|
||||
StatusSurfacePreviewItem::TaskProgress => return self.terminal_title_task_progress(),
|
||||
StatusSurfacePreviewItem::CurrentDir => StatusLineItem::CurrentDir,
|
||||
StatusSurfacePreviewItem::Hostname => StatusLineItem::Hostname,
|
||||
StatusSurfacePreviewItem::ThreadName => StatusLineItem::ThreadName,
|
||||
StatusSurfacePreviewItem::ThreadTitle => StatusLineItem::ThreadTitle,
|
||||
StatusSurfacePreviewItem::GitBranch => StatusLineItem::GitBranch,
|
||||
StatusSurfacePreviewItem::PullRequestNumber => StatusLineItem::PullRequestNumber,
|
||||
@@ -864,9 +883,17 @@ impl ChatWidget {
|
||||
)),
|
||||
TerminalTitleItem::Spinner => self.terminal_title_spinner_text_at(now),
|
||||
TerminalTitleItem::Status => Some(self.run_state_status_text()),
|
||||
TerminalTitleItem::Thread => self
|
||||
.status_line_value_for_item(StatusLineItem::ThreadTitle)
|
||||
.map(|value| Self::truncate_terminal_title_part(value, /*max_chars*/ 48)),
|
||||
TerminalTitleItem::Thread | TerminalTitleItem::ThreadName => {
|
||||
let item = if item == TerminalTitleItem::ThreadName {
|
||||
StatusLineItem::ThreadName
|
||||
} else {
|
||||
StatusLineItem::ThreadTitle
|
||||
};
|
||||
let value = self
|
||||
.status_line_value(item)
|
||||
.map(|value| Self::truncate_terminal_title_part(value, /*max_chars*/ 48));
|
||||
self.with_thread_title_progress(value, now)
|
||||
}
|
||||
TerminalTitleItem::GitBranch => self.status_line_branch.as_ref().map(|branch| {
|
||||
Self::truncate_terminal_title_part(branch.clone(), /*max_chars*/ 32)
|
||||
}),
|
||||
@@ -900,9 +927,12 @@ impl ChatWidget {
|
||||
TerminalTitleItem::EstimatedThreadCost => self
|
||||
.status_line_value_for_item(StatusLineItem::EstimatedThreadCost)
|
||||
.map(|value| Self::truncate_terminal_title_part(value, /*max_chars*/ 32)),
|
||||
TerminalTitleItem::SessionId => self
|
||||
.status_line_value_for_item(StatusLineItem::SessionId)
|
||||
.map(|value| Self::truncate_terminal_title_part(value, /*max_chars*/ 32)),
|
||||
TerminalTitleItem::SessionId => {
|
||||
let value = self
|
||||
.status_line_value(StatusLineItem::SessionId)
|
||||
.map(|value| Self::truncate_terminal_title_part(value, /*max_chars*/ 32));
|
||||
self.with_thread_title_progress(value, now)
|
||||
}
|
||||
TerminalTitleItem::FastMode => self
|
||||
.status_line_value_for_item(StatusLineItem::FastMode)
|
||||
.map(|value| Self::truncate_terminal_title_part(value, /*max_chars*/ 32)),
|
||||
@@ -982,7 +1012,7 @@ impl ChatWidget {
|
||||
Some(self.terminal_title_spinner_frame_at(now).to_string())
|
||||
}
|
||||
|
||||
fn terminal_title_spinner_frame_at(&self, now: Instant) -> &'static str {
|
||||
pub(super) fn terminal_title_spinner_frame_at(&self, now: Instant) -> &'static str {
|
||||
let elapsed = now.saturating_duration_since(self.terminal_title_animation_origin);
|
||||
let frame_index =
|
||||
(elapsed.as_millis() / TERMINAL_TITLE_SPINNER_INTERVAL.as_millis()) as usize;
|
||||
|
||||
@@ -1735,12 +1735,14 @@ async fn live_app_server_invalid_thread_name_update_is_ignored() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn live_app_server_thread_name_update_shows_resume_hint() {
|
||||
async fn live_app_server_manual_thread_name_updates_status_surfaces() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let thread_id =
|
||||
ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").expect("thread id");
|
||||
chat.thread_id = Some(thread_id);
|
||||
|
||||
chat.expect_manual_thread_name(thread_id, "review-fix".to_string());
|
||||
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::ThreadNameUpdated(
|
||||
codex_app_server_protocol::ThreadNameUpdatedNotification {
|
||||
@@ -1753,46 +1755,53 @@ async fn live_app_server_thread_name_update_shows_resume_hint() {
|
||||
|
||||
assert_eq!(chat.thread_name, Some("review-fix".to_string()));
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
assert_eq!(cells.len(), 1);
|
||||
let rendered = lines_to_single_string(&cells[0]);
|
||||
assert_chatwidget_snapshot!("thread_name_update_resume_hint", rendered);
|
||||
let transcript = cells
|
||||
.iter()
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>();
|
||||
let footer = render_bottom_popup(&chat, /*width*/ 80);
|
||||
let title = chat.last_terminal_title.as_deref().unwrap();
|
||||
assert_chatwidget_snapshot!(
|
||||
"manual_thread_name_status_surfaces",
|
||||
normalize_snapshot_paths(format!(
|
||||
"transcript:\n{transcript}\nfooter:\n{footer}\ntitle: {title}"
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn live_app_server_automatic_thread_name_update_is_silent() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let thread_id = ThreadId::new();
|
||||
chat.thread_id = Some(thread_id);
|
||||
for title in ["Provisional title", "Generated title"] {
|
||||
chat.expect_automatic_thread_name(title.to_string());
|
||||
assert_eq!(chat.thread_name(), Some(title.to_string()));
|
||||
for replay_kind in [
|
||||
None,
|
||||
Some(ReplayKind::ThreadSnapshot),
|
||||
Some(ReplayKind::ResumeInitialMessages),
|
||||
] {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let thread_id = ThreadId::new();
|
||||
let mut session = configured_thread_session(thread_id);
|
||||
session.thread_name = Some("Generated title".to_string());
|
||||
chat.handle_thread_session(session);
|
||||
drain_insert_history(&mut rx);
|
||||
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::ThreadNameUpdated(
|
||||
codex_app_server_protocol::ThreadNameUpdatedNotification {
|
||||
thread_id: thread_id.to_string(),
|
||||
thread_name: Some(title.to_string()),
|
||||
thread_name: Some("Generated title".to_string()),
|
||||
},
|
||||
),
|
||||
/*replay_kind*/ None,
|
||||
replay_kind,
|
||||
);
|
||||
|
||||
assert_eq!(chat.thread_name, Some(title.to_string()));
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
assert_eq!(chat.thread_name(), Some("Generated title".to_string()));
|
||||
let transcript = drain_insert_history(&mut rx)
|
||||
.iter()
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>();
|
||||
insta::allow_duplicates! {
|
||||
assert_snapshot!(transcript, @"");
|
||||
}
|
||||
}
|
||||
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::ThreadNameUpdated(
|
||||
codex_app_server_protocol::ThreadNameUpdatedNotification {
|
||||
thread_id: thread_id.to_string(),
|
||||
thread_name: Some("Manual title".to_string()),
|
||||
},
|
||||
),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
assert_eq!(chat.thread_name, Some("Manual title".to_string()));
|
||||
assert_eq!(drain_insert_history(&mut rx).len(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1800,7 +1809,6 @@ async fn live_app_server_manual_thread_name_is_visible_before_notification() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let thread_id = ThreadId::new();
|
||||
chat.thread_id = Some(thread_id);
|
||||
chat.expect_automatic_thread_name("Provisional title".to_string());
|
||||
|
||||
chat.expect_manual_thread_name(thread_id, "Manual title".to_string());
|
||||
|
||||
@@ -1818,7 +1826,7 @@ async fn live_app_server_manual_thread_name_is_visible_before_notification() {
|
||||
);
|
||||
|
||||
assert_eq!(chat.thread_name(), Some("Manual title".to_string()));
|
||||
assert_eq!(drain_insert_history(&mut rx).len(), 1);
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/terminal_title.rs
|
||||
expression: "rendered.join(\"\\n\\n\")"
|
||||
---
|
||||
name=None, pending=false
|
||||
status: | 550e8400-e29b-41d4-a716-446655440000 | 550e8400-e29b-41d4-a716-446655440000
|
||||
title: | 550e8400-e29b-41d4-a716-446655440000 | 550e8400-e29b-41d4-a716-44665...
|
||||
default title: project
|
||||
|
||||
name=None, pending=true
|
||||
status: renaming... ⠋ | 550e8400-e29b-41d4-a716-446655440000 ⠋ | 550e8400-e29b-41d4-a716-446655440000 ⠋
|
||||
title: renaming... ⠋ | 550e8400-e29b-41d4-a716-446655440000 ⠋ | 550e8400-e29b-41d4-a716-44665... ⠋
|
||||
default title: renaming... ⠋ | project
|
||||
|
||||
name=Some("Fix login timeout"), pending=true
|
||||
status: Fix login timeout ⠋ | Fix login timeout ⠋ | 550e8400-e29b-41d4-a716-446655440000 ⠋
|
||||
title: Fix login timeout ⠋ | Fix login timeout ⠋ | 550e8400-e29b-41d4-a716-44665... ⠋
|
||||
default title: Fix login timeout ⠋ | project
|
||||
|
||||
name=Some("Fix login timeout"), pending=false
|
||||
status: Fix login timeout | Fix login timeout | 550e8400-e29b-41d4-a716-446655440000
|
||||
title: Fix login timeout | Fix login timeout | 550e8400-e29b-41d4-a716-44665...
|
||||
default title: Fix login timeout | project
|
||||
@@ -239,3 +239,125 @@ async fn terminal_title_activity_indicators_do_not_animate_when_animations_are_d
|
||||
);
|
||||
assert!(!chat.should_animate_terminal_title_action_required());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_title_progress_renders_names_and_fallbacks_on_both_surfaces() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::from_string("550e8400-e29b-41d4-a716-446655440000").unwrap());
|
||||
chat.local_settings.tui.animations = false;
|
||||
let mut rendered = Vec::new();
|
||||
for (name, pending) in [
|
||||
(None, false),
|
||||
(None, true),
|
||||
(Some("Fix login timeout"), true),
|
||||
(Some("Fix login timeout"), false),
|
||||
] {
|
||||
chat.thread_name = name.map(str::to_owned);
|
||||
chat.set_thread_title_generation_pending(pending);
|
||||
chat.refresh_status_surfaces();
|
||||
let status = [
|
||||
StatusLineItem::ThreadName,
|
||||
StatusLineItem::ThreadTitle,
|
||||
StatusLineItem::SessionId,
|
||||
]
|
||||
.into_iter()
|
||||
.map(|item| chat.status_line_value_for_item(item).unwrap_or_default())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" | ");
|
||||
let title = [
|
||||
TerminalTitleItem::ThreadName,
|
||||
TerminalTitleItem::Thread,
|
||||
TerminalTitleItem::SessionId,
|
||||
]
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
chat.terminal_title_value_for_item(item, Instant::now())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(" | ");
|
||||
rendered.push(format!(
|
||||
"name={name:?}, pending={pending}\nstatus: {status}\ntitle: {title}\ndefault title: {}",
|
||||
chat.last_terminal_title.as_deref().unwrap()
|
||||
));
|
||||
}
|
||||
insta::assert_snapshot!(
|
||||
"thread_title_generation_status_surfaces",
|
||||
rendered.join("\n\n")
|
||||
);
|
||||
chat.thread_name = Some(" ".to_string());
|
||||
assert_eq!(
|
||||
chat.status_line_value_for_item(StatusLineItem::ThreadName),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
chat.terminal_title_value_for_item(TerminalTitleItem::ThreadName, Instant::now()),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_title_progress_animates_when_main_turn_is_idle() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let (frame_requester, mut draw_rx) = FrameRequester::test_channel();
|
||||
chat.frame_requester = frame_requester;
|
||||
chat.local_settings.tui.terminal_title = Some(Vec::new());
|
||||
chat.local_settings.tui.status_line = Some(vec!["thread-name".to_string()]);
|
||||
chat.bottom_pane.set_task_running(/*running*/ false);
|
||||
chat.set_thread_title_generation_pending(/*pending*/ true);
|
||||
assert!(chat.terminal_title_next_refresh.is_some());
|
||||
while draw_rx.try_recv().is_ok() {}
|
||||
|
||||
let now = Instant::now();
|
||||
chat.terminal_title_animation_origin = now;
|
||||
assert_eq!(
|
||||
chat.terminal_title_value_for_item(TerminalTitleItem::ThreadName, now),
|
||||
Some("renaming... ⠋".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
chat.terminal_title_value_for_item(
|
||||
TerminalTitleItem::ThreadName,
|
||||
now + Duration::from_millis(/*millis*/ 100)
|
||||
),
|
||||
Some("renaming... ⠙".to_string())
|
||||
);
|
||||
chat.refresh_thread_title_progress_for_time_tick();
|
||||
assert!(draw_rx.try_recv().is_ok());
|
||||
|
||||
chat.local_settings.tui.status_line = Some(Vec::new());
|
||||
chat.local_settings.tui.terminal_title = Some(vec!["thread-name".to_string()]);
|
||||
chat.refresh_status_surfaces();
|
||||
assert!(chat.terminal_title_next_refresh.is_some());
|
||||
while draw_rx.try_recv().is_ok() {}
|
||||
chat.refresh_thread_title_progress_for_time_tick();
|
||||
assert!(draw_rx.try_recv().is_err());
|
||||
|
||||
chat.local_settings.tui.animations = false;
|
||||
chat.refresh_status_surfaces();
|
||||
assert!(chat.terminal_title_next_refresh.is_none());
|
||||
assert_eq!(chat.last_terminal_title, Some("renaming... ⠋".to_string()));
|
||||
chat.local_settings.tui.animations = true;
|
||||
chat.set_thread_title_generation_pending(/*pending*/ false);
|
||||
assert_eq!(chat.last_terminal_title, None);
|
||||
assert!(chat.terminal_title_next_refresh.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_title_progress_preserves_suffix_after_truncation_and_in_default_footer() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.local_settings.tui.animations = false;
|
||||
chat.set_thread_title_generation_pending(/*pending*/ true);
|
||||
chat.show_welcome_banner = false;
|
||||
assert_chatwidget_snapshot!(
|
||||
"default_footer_generating_thread_title",
|
||||
normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 100))
|
||||
);
|
||||
chat.thread_name = Some("Long title ".repeat(/*n*/ 12));
|
||||
for item in [TerminalTitleItem::ThreadName, TerminalTitleItem::Thread] {
|
||||
let title = chat
|
||||
.terminal_title_value_for_item(item, Instant::now())
|
||||
.unwrap();
|
||||
assert!(title.ends_with("... ⠋"), "{title}");
|
||||
assert_eq!(title.chars().count(), 50);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
//! Title-generation progress on thread identity items in both status surfaces.
|
||||
//!
|
||||
//! The app owns requests across thread switches. Only the displayed thread's pending state
|
||||
//! lives here; the existing terminal-title timer also redraws the footer while it is pending.
|
||||
|
||||
use super::ChatWidget;
|
||||
use super::status_surfaces::TERMINAL_TITLE_SPINNER_FRAMES;
|
||||
use crate::bottom_pane::StatusLineItem;
|
||||
use std::time::Instant;
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn set_thread_title_generation_pending(&mut self, pending: bool) {
|
||||
if self.status_state.thread_title_generation_pending != pending {
|
||||
self.status_state.thread_title_generation_pending = pending;
|
||||
self.refresh_status_surfaces();
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn status_line_value_for_item(&mut self, item: StatusLineItem) -> Option<String> {
|
||||
let value = self.status_line_value(item);
|
||||
if matches!(
|
||||
item,
|
||||
StatusLineItem::ThreadName | StatusLineItem::ThreadTitle | StatusLineItem::SessionId
|
||||
) {
|
||||
self.with_thread_title_progress(value, Instant::now())
|
||||
} else {
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn with_thread_title_progress(
|
||||
&self,
|
||||
value: Option<String>,
|
||||
now: Instant,
|
||||
) -> Option<String> {
|
||||
if !self.status_state.thread_title_generation_pending {
|
||||
return value;
|
||||
}
|
||||
let spinner = if self.local_settings.tui.animations {
|
||||
self.terminal_title_spinner_frame_at(now)
|
||||
} else {
|
||||
TERMINAL_TITLE_SPINNER_FRAMES[0]
|
||||
};
|
||||
let value = value.unwrap_or_else(|| "renaming...".to_string());
|
||||
Some(format!("{value} {spinner}"))
|
||||
}
|
||||
|
||||
pub(crate) fn refresh_thread_title_progress_for_time_tick(&mut self) {
|
||||
if self.status_state.thread_title_generation_pending
|
||||
&& self.local_settings.tui.animations
|
||||
&& self.configured_status_line_items().iter().any(|item| {
|
||||
matches!(
|
||||
item.parse::<StatusLineItem>(),
|
||||
Ok(StatusLineItem::ThreadName
|
||||
| StatusLineItem::ThreadTitle
|
||||
| StatusLineItem::SessionId)
|
||||
)
|
||||
})
|
||||
{
|
||||
self.refresh_status_line();
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user