Skip to content

Commit 62c68e8

Browse files
committed
tui: dedupe resume/fork thread id resolution
1 parent 5ecd1c7 commit 62c68e8

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

codex-rs/tui/src/lib.rs

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -574,21 +574,13 @@ async fn run_ratatui_app(
574574
};
575575
match path {
576576
Some(path) => {
577-
let thread_id = if is_uuid {
578-
match ThreadId::from_string(id_str) {
579-
Ok(thread_id) => thread_id,
580-
Err(_) => return missing_session_exit(id_str, "fork"),
581-
}
582-
} else {
583-
match read_session_meta_line(path.as_path())
577+
let thread_id =
578+
match resolve_session_thread_id(path.as_path(), is_uuid.then_some(id_str))
584579
.await
585-
.ok()
586-
.map(|meta_line| meta_line.meta.id)
587580
{
588581
Some(thread_id) => thread_id,
589582
None => return missing_session_exit(id_str, "fork"),
590-
}
591-
};
583+
};
592584
resume_picker::SessionSelection::Fork(resume_picker::SessionTarget {
593585
path,
594586
thread_id,
@@ -611,11 +603,7 @@ async fn run_ratatui_app(
611603
{
612604
Ok(page) => match page.items.first() {
613605
Some(item) => {
614-
match read_session_meta_line(item.path.as_path())
615-
.await
616-
.ok()
617-
.map(|meta_line| meta_line.meta.id)
618-
{
606+
match resolve_session_thread_id(item.path.as_path(), None).await {
619607
Some(thread_id) => resume_picker::SessionSelection::Fork(
620608
resume_picker::SessionTarget {
621609
path: item.path.clone(),
@@ -656,20 +644,14 @@ async fn run_ratatui_app(
656644
};
657645
match path {
658646
Some(path) => {
659-
let thread_id = if is_uuid {
660-
match ThreadId::from_string(id_str) {
661-
Ok(thread_id) => thread_id,
662-
Err(_) => return missing_session_exit(id_str, "resume"),
663-
}
664-
} else {
665-
match read_session_meta_line(path.as_path())
666-
.await
667-
.ok()
668-
.map(|meta_line| meta_line.meta.id)
669-
{
670-
Some(thread_id) => thread_id,
671-
None => return missing_session_exit(id_str, "resume"),
672-
}
647+
let thread_id = match resolve_session_thread_id(
648+
path.as_path(),
649+
is_uuid.then_some(id_str),
650+
)
651+
.await
652+
{
653+
Some(thread_id) => thread_id,
654+
None => return missing_session_exit(id_str, "resume"),
673655
};
674656
resume_picker::SessionSelection::Resume(resume_picker::SessionTarget {
675657
path,
@@ -697,11 +679,7 @@ async fn run_ratatui_app(
697679
)
698680
.await
699681
{
700-
Ok(Some(path)) => match read_session_meta_line(path.as_path())
701-
.await
702-
.ok()
703-
.map(|meta_line| meta_line.meta.id)
704-
{
682+
Ok(Some(path)) => match resolve_session_thread_id(path.as_path(), None).await {
705683
Some(thread_id) => {
706684
resume_picker::SessionSelection::Resume(resume_picker::SessionTarget {
707685
path,
@@ -824,6 +802,19 @@ async fn run_ratatui_app(
824802
app_result
825803
}
826804

805+
pub(crate) async fn resolve_session_thread_id(
806+
path: &Path,
807+
id_str_if_uuid: Option<&str>,
808+
) -> Option<ThreadId> {
809+
match id_str_if_uuid {
810+
Some(id_str) => ThreadId::from_string(id_str).ok(),
811+
None => read_session_meta_line(path)
812+
.await
813+
.ok()
814+
.map(|meta_line| meta_line.meta.id),
815+
}
816+
}
817+
827818
pub(crate) async fn read_session_cwd(
828819
config: &Config,
829820
thread_id: ThreadId,

codex-rs/tui/src/resume_picker.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use codex_core::ThreadsPage;
2121
use codex_core::config::Config;
2222
use codex_core::find_thread_names_by_ids;
2323
use codex_core::path_utils;
24-
use codex_core::read_session_meta_line;
2524
use codex_protocol::ThreadId;
2625
use color_eyre::eyre::Result;
2726
use crossterm::event::KeyCode;
@@ -413,10 +412,7 @@ impl PickerState {
413412
let path = row.path.clone();
414413
let thread_id = match row.thread_id {
415414
Some(thread_id) => Some(thread_id),
416-
None => read_session_meta_line(path.as_path())
417-
.await
418-
.ok()
419-
.map(|meta_line| meta_line.meta.id),
415+
None => crate::resolve_session_thread_id(path.as_path(), None).await,
420416
};
421417
if let Some(thread_id) = thread_id {
422418
return Ok(Some(self.action.selection(path, thread_id)));

0 commit comments

Comments
 (0)