Conversation naming (#8991)

Session renaming:
- `/rename my_session`
- `/rename` without arg and passing an argument in `customViewPrompt`
- AppExitInfo shows resume hint using the session name if set instead of
uuid, defaults to uuid if not set
- Names are stored in `CODEX_HOME/sessions.jsonl`

Session resuming:
- codex resume <name> lookup for `CODEX_HOME/sessions.jsonl` first entry
matching the name and resumes the session

---------

Co-authored-by: jif-oai <jif@openai.com>
This commit is contained in:
pap-openaiandjif-oai authored and GitHub committed 2026-01-30 10:40:09 +00:00
1 parent 25ad414680
commit 1ef5455eb6
33 files changed
+908 -30

No files matched your search

+82 -2
View File
@@ -23,6 +23,7 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
@@ -197,7 +198,6 @@ use self::skills::collect_tool_mentions;
use self::skills::find_app_mentions;
use self::skills::find_skill_mentions_with_tool_mentions;
use crate::streaming::controller::StreamController;
use std::path::Path;
use chrono::Local;
use codex_common::approval_presets::ApprovalPreset;
@@ -517,6 +517,7 @@ pub(crate) struct ChatWidget {
// Previous status header to restore after a transient stream retry.
retry_status_header: Option<String>,
thread_id: Option<ThreadId>,
thread_name: Option<String>,
forked_from: Option<ThreadId>,
frame_requester: FrameRequester,
// Whether to include the initial welcome banner on session configured
@@ -788,6 +789,7 @@ impl ChatWidget {
self.set_skills(None);
self.bottom_pane.set_connectors_snapshot(None);
self.thread_id = Some(event.session_id);
self.thread_name = event.thread_name.clone();
self.forked_from = event.forked_from_id;
self.current_rollout_path = event.rollout_path.clone();
let initial_messages = event.initial_messages.clone();
@@ -828,6 +830,13 @@ impl ChatWidget {
}
}
fn on_thread_name_updated(&mut self, event: codex_core::protocol::ThreadNameUpdatedEvent) {
if self.thread_id == Some(event.thread_id) {
self.thread_name = event.thread_name;
self.request_redraw();
}
}
fn set_skills(&mut self, skills: Option<Vec<SkillMetadata>>) {
self.bottom_pane.set_skills(skills);
}
@@ -2167,6 +2176,7 @@ impl ChatWidget {
current_status_header: String::from("Working"),
retry_status_header: None,
thread_id: None,
thread_name: None,
forked_from: None,
queued_user_messages: VecDeque::new(),
show_welcome_banner: is_first_run,
@@ -2307,6 +2317,7 @@ impl ChatWidget {
current_status_header: String::from("Working"),
retry_status_header: None,
thread_id: None,
thread_name: None,
forked_from: None,
saw_plan_update_this_turn: false,
queued_user_messages: VecDeque::new(),
@@ -2436,6 +2447,7 @@ impl ChatWidget {
current_status_header: String::from("Working"),
retry_status_header: None,
thread_id: None,
thread_name: None,
forked_from: None,
queued_user_messages: VecDeque::new(),
show_welcome_banner: false,
@@ -2706,6 +2718,9 @@ impl ChatWidget {
SlashCommand::Review => {
self.open_review_popup();
}
SlashCommand::Rename => {
self.show_rename_prompt();
}
SlashCommand::Model => {
self.open_model_popup();
}
@@ -2907,6 +2922,17 @@ impl ChatWidget {
let trimmed = args.trim();
match cmd {
SlashCommand::Rename if !trimmed.is_empty() => {
let Some(name) = codex_core::util::normalize_thread_name(trimmed) else {
self.add_error_message("Thread name cannot be empty.".to_string());
return;
};
let cell = Self::rename_confirmation_cell(&name, self.thread_id);
self.add_boxed_history(Box::new(cell));
self.request_redraw();
self.app_event_tx
.send(AppEvent::CodexOp(Op::SetThreadName { name }));
}
SlashCommand::Collab | SlashCommand::Plan => {
let _ = trimmed;
self.dispatch_command(cmd);
@@ -2925,6 +2951,38 @@ impl ChatWidget {
}
}
fn show_rename_prompt(&mut self) {
let tx = self.app_event_tx.clone();
let has_name = self
.thread_name
.as_ref()
.is_some_and(|name| !name.is_empty());
let title = if has_name {
"Rename thread"
} else {
"Name thread"
};
let thread_id = self.thread_id;
let view = CustomPromptView::new(
title.to_string(),
"Type a name and press Enter".to_string(),
None,
Box::new(move |name: String| {
let Some(name) = codex_core::util::normalize_thread_name(&name) else {
tx.send(AppEvent::InsertHistoryCell(Box::new(
history_cell::new_error_event("Thread name cannot be empty.".to_string()),
)));
return;
};
let cell = Self::rename_confirmation_cell(&name, thread_id);
tx.send(AppEvent::InsertHistoryCell(Box::new(cell)));
tx.send(AppEvent::CodexOp(Op::SetThreadName { name }));
}),
);
self.bottom_pane.show_view(Box::new(view));
}
pub(crate) fn handle_paste(&mut self, text: String) {
self.bottom_pane.handle_paste(text);
}
@@ -3125,7 +3183,10 @@ impl ChatWidget {
/// distinguish replayed events from live ones.
fn replay_initial_messages(&mut self, events: Vec<EventMsg>) {
for msg in events {
if matches!(msg, EventMsg::SessionConfigured(_)) {
if matches!(
msg,
EventMsg::SessionConfigured(_) | EventMsg::ThreadNameUpdated(_)
) {
continue;
}
// `id: None` indicates a synthetic/fake id coming from replay.
@@ -3169,6 +3230,7 @@ impl ChatWidget {
match msg {
EventMsg::SessionConfigured(e) => self.on_session_configured(e),
EventMsg::ThreadNameUpdated(e) => self.on_thread_name_updated(e),
EventMsg::AgentMessage(AgentMessageEvent { message }) => self.on_agent_message(message),
EventMsg::AgentMessageDelta(AgentMessageDeltaEvent { delta }) => {
self.on_agent_message_delta(delta)
@@ -3468,6 +3530,7 @@ impl ChatWidget {
token_info,
total_usage,
&self.thread_id,
self.thread_name.clone(),
self.forked_from,
self.rate_limit_snapshot.as_ref(),
self.plan_type,
@@ -5275,6 +5338,20 @@ impl ChatWidget {
self.request_redraw();
}
fn rename_confirmation_cell(name: &str, thread_id: Option<ThreadId>) -> PlainHistoryCell {
let resume_cmd = codex_core::util::resume_command(Some(name), thread_id)
.unwrap_or_else(|| format!("codex resume {name}"));
let name = name.to_string();
let line = vec![
"• ".into(),
"Thread renamed to ".into(),
name.cyan(),
", to resume this thread run ".into(),
resume_cmd.cyan(),
];
PlainHistoryCell::new(vec![line.into()])
}
pub(crate) fn add_mcp_output(&mut self) {
if self.config.mcp_servers.is_empty() {
self.add_to_history(history_cell::empty_mcp_output());
@@ -5796,6 +5873,9 @@ impl ChatWidget {
self.thread_id
}
pub(crate) fn thread_name(&self) -> Option<String> {
self.thread_name.clone()
}
pub(crate) fn rollout_path(&self) -> Option<PathBuf> {
self.current_rollout_path.clone()
}