mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Improve side-chat discovery and navigation in the TUI (#60319)
## What changed - Show latest user-prompt previews beneath saved side-chat titles, fetching previews only for visible entries when the chooser refreshes. - Keep cached chats available during discovery, show loading and refresh status, and offer an inline retry action on failure. - Preserve the selected chat across list updates and prevent asynchronous changes or held activation keys from opening an unintended entry. Account for preview rows in paging and mouse selection. - Explain that side chats become available after the first main-chat message, and let `Ctrl+C` dismiss the chooser while preserving the main draft. - Separate tabs with noninteractive gaps and improve hover styling for tabs, overflow arrows, and the add button. ## Testing Extend integration tests and snapshots for discovery failures and retries, refreshed prompt previews, activation guards, variable-height paging, draft preservation, and tab hover states across light, dark, and fallback colors. GitOrigin-RevId: 34423f5aeccb566682f7aa219f54ca5c7c8304fb
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//! Discovers local side chats from their own rollouts and reads their visible labels.
|
||||
//! Discovers local side chats from their own rollouts and reads titles and prompts from child history.
|
||||
|
||||
use super::*;
|
||||
use crate::chatwidget::ChatWidget;
|
||||
use codex_app_server_protocol::SortDirection;
|
||||
use codex_app_server_protocol::ThreadItemPayload;
|
||||
use codex_app_server_protocol::ThreadItemsListResponse;
|
||||
@@ -11,6 +12,8 @@ use codex_protocol::models::ContentItem;
|
||||
use codex_rollout::ResponseItemEnvelope;
|
||||
use codex_rollout::RolloutItem;
|
||||
use codex_rollout::read_session_meta_line;
|
||||
use futures::StreamExt;
|
||||
use itertools::Itertools;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -66,27 +69,32 @@ impl From<ThreadId> for SideChat {
|
||||
}
|
||||
|
||||
pub(crate) fn side_chat_prompt_preview(content: &[UserInput]) -> Option<&str> {
|
||||
side_chat_prompt_parts(content)?
|
||||
.next()?
|
||||
.lines()
|
||||
.next()
|
||||
.map(str::trim)
|
||||
}
|
||||
|
||||
fn side_chat_prompt_parts(content: &[UserInput]) -> Option<impl Iterator<Item = &str>> {
|
||||
if crate::chatwidget::realtime_delegation_input(content).is_some() {
|
||||
return None;
|
||||
}
|
||||
content
|
||||
.iter()
|
||||
.find_map(|input| match input {
|
||||
UserInput::Text { text, .. } => {
|
||||
codex_protocol::protocol::strip_user_message_prefix(text)
|
||||
.lines()
|
||||
.next()
|
||||
.map(str::trim)
|
||||
}
|
||||
let mut text = content.iter().filter_map(|input| {
|
||||
let UserInput::Text { text, .. } = input else {
|
||||
return None;
|
||||
};
|
||||
let text = codex_protocol::protocol::strip_user_message_prefix(text);
|
||||
(!text.is_empty()).then_some(text)
|
||||
});
|
||||
let first = text.next().or_else(|| {
|
||||
content.iter().find_map(|input| match input {
|
||||
UserInput::Image { .. } | UserInput::LocalImage { .. } => Some("[Image]"),
|
||||
UserInput::Audio { .. } | UserInput::LocalAudio { .. } => Some("[Audio]"),
|
||||
_ => None,
|
||||
})
|
||||
.or_else(|| {
|
||||
content.iter().find_map(|input| match input {
|
||||
UserInput::Image { .. } | UserInput::LocalImage { .. } => Some("[Image]"),
|
||||
UserInput::Audio { .. } | UserInput::LocalAudio { .. } => Some("[Audio]"),
|
||||
_ => None,
|
||||
})
|
||||
})
|
||||
})?;
|
||||
Some(std::iter::once(first).chain(text))
|
||||
}
|
||||
|
||||
pub(super) fn is_attached_thread_store_unsupported(err: &color_eyre::Report) -> bool {
|
||||
@@ -203,7 +211,7 @@ impl AppServerSession {
|
||||
true
|
||||
});
|
||||
let preview = if name.is_none() {
|
||||
self.first_side_chat_prompt(id)
|
||||
self.side_chat_prompt(id, SortDirection::Asc)
|
||||
.await
|
||||
.unwrap_or_else(|error| {
|
||||
tracing::debug!(%id, %error, "failed to load side-chat prompt");
|
||||
@@ -289,7 +297,29 @@ impl AppServerSession {
|
||||
}
|
||||
}
|
||||
|
||||
async fn first_side_chat_prompt(&mut self, id: ThreadId) -> Result<String> {
|
||||
pub(crate) async fn latest_side_chat_prompts(
|
||||
&self,
|
||||
ids: Vec<ThreadId>,
|
||||
) -> HashMap<ThreadId, String> {
|
||||
// Bound the number of paginated reads in flight when a tall chooser shows many chats.
|
||||
futures::stream::iter(ids)
|
||||
.map(|id| async move {
|
||||
let mut view = self.request_view();
|
||||
let prompt = view
|
||||
.side_chat_prompt(id, SortDirection::Desc)
|
||||
.await
|
||||
.unwrap_or_else(|error| {
|
||||
tracing::debug!(%id, %error, "failed to load side-chat prompt");
|
||||
String::new()
|
||||
});
|
||||
(id, prompt)
|
||||
})
|
||||
.buffer_unordered(4)
|
||||
.collect()
|
||||
.await
|
||||
}
|
||||
|
||||
async fn side_chat_prompt(&mut self, id: ThreadId, order: SortDirection) -> Result<String> {
|
||||
// The summary preview can come from inherited model context. Item pages only contain
|
||||
// the child's visible history, including for chats saved by older clients.
|
||||
let mut cursor = None;
|
||||
@@ -297,23 +327,48 @@ impl AppServerSession {
|
||||
loop {
|
||||
let mut params =
|
||||
thread_items_page_params(id, /*turn_id*/ None, cursor, /*limit*/ 16);
|
||||
params.sort_direction = Some(SortDirection::Asc);
|
||||
params.sort_direction = Some(order);
|
||||
let request_id = self.next_request_id();
|
||||
let page: ThreadItemsListResponse = self
|
||||
.request_handle
|
||||
.request_typed(ClientRequest::ThreadItemsList { request_id, params })
|
||||
.await?;
|
||||
if let Some(preview) = page
|
||||
if let Some(prompt) = page
|
||||
.data
|
||||
.iter()
|
||||
.find_map(|entry| match &entry.item.payload {
|
||||
ThreadItemPayload::UserMessage { content, .. } => {
|
||||
side_chat_prompt_preview(content)
|
||||
}
|
||||
ThreadItemPayload::UserMessage { content, .. } => match order {
|
||||
SortDirection::Asc => side_chat_prompt_preview(content).map(str::to_owned),
|
||||
SortDirection::Desc => {
|
||||
if crate::chatwidget::realtime_delegation_input(content).is_some() {
|
||||
return None;
|
||||
}
|
||||
let mut prompt =
|
||||
ChatWidget::user_message_display_from_inputs(content).message;
|
||||
if prompt.trim().is_empty() {
|
||||
prompt =
|
||||
content
|
||||
.iter()
|
||||
.find_map(|input| match input {
|
||||
UserInput::Image { .. }
|
||||
| UserInput::LocalImage { .. } => Some("[Image]"),
|
||||
UserInput::Audio { .. }
|
||||
| UserInput::LocalAudio { .. } => Some("[Audio]"),
|
||||
_ => None,
|
||||
})?
|
||||
.to_owned();
|
||||
}
|
||||
Some(
|
||||
crate::history_cell::sanitize_user_text(prompt.into())
|
||||
.split_whitespace()
|
||||
.join(" "),
|
||||
)
|
||||
}
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
{
|
||||
return Ok(preview.to_owned());
|
||||
return Ok(prompt);
|
||||
}
|
||||
let Some(next) = page.next_cursor else {
|
||||
return Ok(String::new());
|
||||
|
||||
Reference in New Issue
Block a user