Skip to main content

codetether_agent/tui/app/
codex_sessions.rs

1use crate::session::{Session, import_codex_sessions_for_directory, load_or_import_session};
2use crate::tui::app::message_text::sync_messages_from_session;
3use crate::tui::app::session_sync::{refresh_sessions, return_to_chat};
4use crate::tui::app::state::App;
5use std::path::Path;
6
7pub async fn load_selected_session(
8    app: &mut App,
9    cwd: &Path,
10    session: &mut Session,
11    session_id: &str,
12) {
13    match load_or_import_session(session_id).await {
14        Ok(loaded) => {
15            *session = loaded;
16            session.attach_global_bus_if_missing();
17            app.state.auto_apply_edits = session.metadata.auto_apply_edits;
18            app.state.use_worktree = session.metadata.use_worktree;
19            app.state.session_id = Some(session.id.clone());
20            sync_messages_from_session(app, session);
21            refresh_sessions(app, cwd).await;
22            app.state.clear_session_filter();
23            return_to_chat(app);
24            app.state.status = format!(
25                "Loaded session {}",
26                session.title.clone().unwrap_or_else(|| session.id.clone())
27            );
28        }
29        Err(error) => {
30            app.state.status = format!("Failed to load session: {error}");
31        }
32    }
33}
34
35pub async fn import_workspace_sessions(app: &mut App, cwd: &Path) {
36    match import_codex_sessions_for_directory(cwd).await {
37        Ok(report) => {
38            refresh_sessions(app, cwd).await;
39            app.state.status = format!(
40                "Imported {} Codex sessions, skipped {}",
41                report.imported, report.skipped
42            );
43        }
44        Err(error) => {
45            app.state.status = format!("Codex import failed: {error}");
46        }
47    }
48}