mirror of
https://github.com/openai/codex.git
synced 2026-11-26 07:26:11 +00:00
Suggest conversation-based thread titles in /rename (#40495)
## What changed - Generate a title suggestion from the latest substantive user and assistant messages when the TUI `/rename` prompt opens. - Prefill the prompt with the result while keeping it editable and preserving any text the user enters before generation finishes. - Bound and escape the conversation context, omit commentary and IDE context, and correlate responses with the active thread and prompt so stale suggestions are ignored. ## Testing - Cover conversation selection and prompt construction, generated-title delivery through the embedded app server, loading and prefilled prompt states, stale responses, and preservation of manual edits. GitOrigin-RevId: 1e7f1d5d4f6503ff9da0548388f610c446c130ca
This commit is contained in:
1 parent
0c992c305d
commit
5a51caf04d
13 files changed
+877
-2
No files matched your search
@@ -417,7 +417,10 @@ impl ChatWidget {
|
||||
} else {
|
||||
"Name thread"
|
||||
};
|
||||
let view = CustomPromptView::new(
|
||||
let suggestion_request = self
|
||||
.thread_id
|
||||
.map(|thread_id| (thread_id, uuid::Uuid::new_v4()));
|
||||
let mut view = CustomPromptView::new(
|
||||
title.to_string(),
|
||||
"Type a name and press Enter".to_string(),
|
||||
/*initial_text*/ existing_name.unwrap_or_default().to_string(),
|
||||
@@ -432,7 +435,32 @@ impl ChatWidget {
|
||||
tx.set_thread_name(name);
|
||||
}),
|
||||
);
|
||||
if let Some((_, request_id)) = suggestion_request {
|
||||
view = view.with_text_suggestion(
|
||||
request_id,
|
||||
"Generating a title suggestion…".to_string(),
|
||||
"Suggested from this conversation".to_string(),
|
||||
);
|
||||
}
|
||||
self.bottom_pane.show_text_prompt(view);
|
||||
if let Some((thread_id, request_id)) = suggestion_request {
|
||||
self.app_event_tx.send(AppEvent::SuggestThreadName {
|
||||
thread_id,
|
||||
request_id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn apply_thread_name_suggestion(
|
||||
&mut self,
|
||||
thread_id: ThreadId,
|
||||
request_id: uuid::Uuid,
|
||||
suggestion: Option<&str>,
|
||||
) {
|
||||
if self.thread_id == Some(thread_id) {
|
||||
self.bottom_pane
|
||||
.apply_text_suggestion(request_id, suggestion);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn ensure_thread_rename_allowed(&mut self) -> bool {
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||
expression: popup
|
||||
---
|
||||
▌ Rename thread
|
||||
▌ Generating a title suggestion…
|
||||
▌
|
||||
▌ Current project title
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||
expression: popup
|
||||
---
|
||||
▌ Rename thread
|
||||
▌ Suggested from this conversation
|
||||
▌
|
||||
▌ Fix login timeout
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
@@ -1621,6 +1621,37 @@ async fn live_app_server_manual_thread_name_is_visible_before_notification() {
|
||||
assert_eq!(drain_insert_history(&mut rx).len(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_name_suggestion_requires_matching_thread_and_request() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let thread_id = ThreadId::new();
|
||||
let request_id = uuid::Uuid::new_v4();
|
||||
chat.thread_id = Some(thread_id);
|
||||
|
||||
let view = CustomPromptView::new(
|
||||
"Rename thread".to_string(),
|
||||
"Type a name and press Enter".to_string(),
|
||||
/*initial_text*/ String::new(),
|
||||
/*context_label*/ None,
|
||||
Box::new(|_| {}),
|
||||
)
|
||||
.with_text_suggestion(request_id, "Loading".into(), "Ready".into());
|
||||
chat.bottom_pane.show_text_prompt(view);
|
||||
|
||||
chat.apply_thread_name_suggestion(ThreadId::new(), request_id, Some("Wrong thread"));
|
||||
chat.apply_thread_name_suggestion(thread_id, uuid::Uuid::new_v4(), Some("Wrong request"));
|
||||
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert!(popup.contains("Loading"));
|
||||
assert!(!popup.contains("Wrong"));
|
||||
|
||||
chat.apply_thread_name_suggestion(thread_id, request_id, Some("Suggested title"));
|
||||
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert!(popup.contains("Ready"));
|
||||
assert!(popup.contains("Suggested title"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn live_app_server_thread_closed_requests_immediate_exit() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
@@ -1214,6 +1214,78 @@ async fn slash_rename_prefills_existing_thread_name() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn slash_rename_requests_and_prefills_an_editable_title_suggestion() {
|
||||
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.thread_name = Some("Current project title".to_string());
|
||||
|
||||
chat.dispatch_command(SlashCommand::Rename);
|
||||
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert_chatwidget_snapshot!("slash_rename_suggestion_loading", popup);
|
||||
|
||||
let request_id = match rx.try_recv() {
|
||||
Ok(AppEvent::SuggestThreadName {
|
||||
thread_id: requested_thread_id,
|
||||
request_id,
|
||||
}) => {
|
||||
assert_eq!(requested_thread_id, thread_id);
|
||||
request_id
|
||||
}
|
||||
other => panic!("expected title suggestion request, got {other:?}"),
|
||||
};
|
||||
|
||||
chat.apply_thread_name_suggestion(thread_id, request_id, Some("Fix login timeout"));
|
||||
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert_chatwidget_snapshot!("slash_rename_suggestion_prefilled", popup);
|
||||
assert_eq!(chat.thread_name.as_deref(), Some("Current project title"));
|
||||
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
|
||||
assert_matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::CodexOp(Op::SetThreadName { name })) if name == "Fix login timeout"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn slash_rename_preserves_manual_edits_when_suggestion_arrives() {
|
||||
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.dispatch_command(SlashCommand::Rename);
|
||||
|
||||
let request_id = match rx.try_recv() {
|
||||
Ok(AppEvent::SuggestThreadName {
|
||||
thread_id: requested_thread_id,
|
||||
request_id,
|
||||
}) => {
|
||||
assert_eq!(requested_thread_id, thread_id);
|
||||
request_id
|
||||
}
|
||||
other => panic!("expected title suggestion request, got {other:?}"),
|
||||
};
|
||||
|
||||
chat.handle_paste("My own title".to_string());
|
||||
chat.apply_thread_name_suggestion(thread_id, request_id, Some("Generated title"));
|
||||
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
assert!(popup.contains("My own title"));
|
||||
assert!(!popup.contains("Generated title"));
|
||||
assert!(!popup.contains("Generating a title suggestion"));
|
||||
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
|
||||
assert_matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::CodexOp(Op::SetThreadName { name })) if name == "My own title"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn slash_rename_without_existing_thread_name_starts_empty() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
Reference in new issue
Block a user