Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ codex-models-manager = { git = "https://github.com/openai/codex", tag = "rust-v0
codex-protocol = { git = "https://github.com/openai/codex", tag = "rust-v0.129.0" }
codex-login = { git = "https://github.com/openai/codex", tag = "rust-v0.129.0" }
codex-shell-command = { git = "https://github.com/openai/codex", tag = "rust-v0.129.0" }
codex-thread-store = { git = "https://github.com/openai/codex", tag = "rust-v0.129.0" }
codex-utils-approval-presets = { git = "https://github.com/openai/codex", tag = "rust-v0.129.0" }
codex-utils-cli = { git = "https://github.com/openai/codex", tag = "rust-v0.129.0" }
diffy = { version = "0.5.0", features = ["std"] }
Expand Down
51 changes: 37 additions & 14 deletions src/codex_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use agent_client_protocol as acp;
use codex_config::{McpServerConfig, McpServerTransportConfig};
use codex_core::{
NewThread, RolloutRecorder, SortDirection, StateDbHandle, ThreadManager, ThreadSortKey,
config::Config, find_thread_path_by_id_str, init_state_db, parse_cursor,
resolve_installation_id, thread_store_from_config,
config::Config, find_thread_names_by_ids, find_thread_path_by_id_str, init_state_db,
parse_cursor, resolve_installation_id, thread_store_from_config,
};
use codex_exec_server::{EnvironmentManager, EnvironmentManagerArgs, ExecServerRuntimePaths};
use codex_login::{
Expand All @@ -28,11 +28,11 @@ use codex_protocol::{
protocol::{InitialHistory, SessionSource},
};
use std::{
collections::HashMap,
collections::{HashMap, HashSet},
path::{Path, PathBuf},
sync::{Arc, Mutex},
};
use tracing::{debug, info};
use tracing::{debug, info, warn};
use unicode_segmentation::UnicodeSegmentation;

use crate::thread::Thread;
Expand Down Expand Up @@ -566,11 +566,13 @@ impl CodexAgent {
.lock()
.unwrap()
.insert(session_id.clone(), config.cwd.to_path_buf());
let thread_store = thread_store_from_config(&config, self.state_db.clone());
let thread = Arc::new(Thread::new(
session_id.clone(),
thread,
self.auth_manager.clone(),
Arc::new(self.thread_manager.get_models_manager()),
thread_store,
self.client_capabilities.clone(),
config.clone(),
cx,
Expand Down Expand Up @@ -640,11 +642,13 @@ impl CodexAgent {
.await
.map_err(|e| Error::internal_error().data(e.to_string()))?;

let thread_store = thread_store_from_config(&config, self.state_db.clone());
let thread = Arc::new(Thread::new(
session_id.clone(),
thread,
self.auth_manager.clone(),
Arc::new(self.thread_manager.get_models_manager()),
thread_store,
self.client_capabilities.clone(),
config.clone(),
cx,
Expand Down Expand Up @@ -695,7 +699,7 @@ impl CodexAgent {
.await
.map_err(|err| Error::internal_error().data(format!("failed to list sessions: {err}")))?;

let sessions = page
let session_items = page
.items
.into_iter()
.filter_map(|item| {
Expand All @@ -708,17 +712,36 @@ impl CodexAgent {
return None;
}

let title = item
.first_user_message
.as_deref()
.and_then(format_session_title);
let updated_at = item.updated_at.or(item.created_at);

Some(
SessionInfo::new(SessionId::new(thread_id.to_string()), item_cwd)
.title(title)
.updated_at(updated_at),
)
Some((thread_id, item_cwd, item.first_user_message, updated_at))
})
.collect::<Vec<_>>();

let thread_ids = session_items
.iter()
.map(|(thread_id, _, _, _)| *thread_id)
.collect::<HashSet<_>>();
let thread_names =
match find_thread_names_by_ids(&self.config.codex_home, &thread_ids).await {
Ok(thread_names) => thread_names,
Err(err) => {
warn!("failed to read Codex thread names: {err}");
HashMap::new()
}
};

let sessions = session_items
.into_iter()
.map(|(thread_id, item_cwd, first_user_message, updated_at)| {
let title = thread_names
.get(&thread_id)
.cloned()
.or_else(|| first_user_message.as_deref().and_then(format_session_title));

SessionInfo::new(SessionId::new(thread_id.to_string()), item_cwd)
.title(title)
.updated_at(updated_at)
})
.collect::<Vec<_>>();

Expand Down
Loading