diff --git a/epiphany-codex-bridge/src/retrieve.rs b/epiphany-codex-bridge/src/retrieve.rs index 2c771488..049d85a5 100644 --- a/epiphany-codex-bridge/src/retrieve.rs +++ b/epiphany-codex-bridge/src/retrieve.rs @@ -7,10 +7,57 @@ use codex_app_server_protocol::ThreadEpiphanyRetrieveShardSummary; use codex_core::CodexThread; use codex_protocol::protocol::EpiphanyRetrievalState; use codex_utils_absolute_path::AbsolutePathBuf; +use epiphany_core::EpiphanyRetrieveQuery; use epiphany_core::EpiphanyRetrieveResponse as CoreEpiphanyRetrieveResponse; use epiphany_core::EpiphanyRetrieveResult as CoreEpiphanyRetrieveResult; use epiphany_core::EpiphanyRetrieveResultKind as CoreEpiphanyRetrieveResultKind; +pub async fn thread_epiphany_retrieval_state(thread: &CodexThread) -> EpiphanyRetrievalState { + let config = thread.config_snapshot().await; + let workspace_root = config.cwd.to_path_buf(); + let codex_home = thread.codex_home().await; + let fallback_workspace_root = workspace_root.clone(); + let fallback_codex_home = codex_home.clone(); + tokio::task::spawn_blocking(move || { + epiphany_core::retrieval_state_for_workspace(&workspace_root, codex_home.as_path()) + }) + .await + .unwrap_or_else(|_| { + epiphany_core::retrieval_state_for_workspace( + &fallback_workspace_root, + fallback_codex_home.as_path(), + ) + }) +} + +pub async fn index_thread_epiphany_retrieval_state( + thread: &CodexThread, + force_full_rebuild: bool, +) -> anyhow::Result { + let config = thread.config_snapshot().await; + let workspace_root = config.cwd.to_path_buf(); + let codex_home = thread.codex_home().await; + tokio::task::spawn_blocking(move || { + epiphany_core::index_workspace(&workspace_root, codex_home.as_path(), force_full_rebuild) + }) + .await + .map_err(|err| anyhow::anyhow!("epiphany index worker failed: {err}"))? +} + +pub async fn retrieve_thread_epiphany( + thread: &CodexThread, + query: EpiphanyRetrieveQuery, +) -> anyhow::Result { + let config = thread.config_snapshot().await; + let workspace_root = config.cwd.to_path_buf(); + let codex_home = thread.codex_home().await; + tokio::task::spawn_blocking(move || { + epiphany_core::retrieve_workspace(&workspace_root, codex_home.as_path(), query) + }) + .await + .map_err(|err| anyhow::anyhow!("epiphany retrieval worker failed: {err}"))? +} + pub fn map_epiphany_retrieve_response( response: CoreEpiphanyRetrieveResponse, ) -> anyhow::Result { @@ -29,8 +76,7 @@ pub async fn index_thread_epiphany_retrieval( thread: &CodexThread, force_full_rebuild: bool, ) -> anyhow::Result { - let index_summary = thread - .epiphany_index(force_full_rebuild) + let index_summary = index_thread_epiphany_retrieval_state(thread, force_full_rebuild) .await .and_then(map_epiphany_retrieve_index_summary)?; Ok(ThreadEpiphanyIndexResponse { index_summary }) diff --git a/epiphany-codex-bridge/src/state.rs b/epiphany-codex-bridge/src/state.rs index 22be773d..bbd416bf 100644 --- a/epiphany-codex-bridge/src/state.rs +++ b/epiphany-codex-bridge/src/state.rs @@ -13,6 +13,8 @@ use epiphany_core::load_memory_graph_snapshot; use epiphany_core::write_thread_state; use tracing::warn; +use crate::retrieve::thread_epiphany_retrieval_state; + pub async fn load_epiphany_state_from_rollout_path( rollout_path: &Path, ) -> std::result::Result, String> { @@ -36,7 +38,7 @@ pub async fn live_thread_epiphany_state(thread: &CodexThread) -> Option PathBuf { + self.codex.session.codex_home().await.to_path_buf() + } + pub async fn epiphany_state(&self) -> Option { self.codex.session.epiphany_state().await } @@ -383,56 +384,6 @@ impl CodexThread { Ok(next_state) } - pub async fn epiphany_retrieval_state(&self) -> EpiphanyRetrievalState { - let config = self.codex.thread_config_snapshot().await; - let workspace_root = config.cwd.to_path_buf(); - let codex_home = self.codex.session.codex_home().await; - let fallback_workspace_root = workspace_root.clone(); - let fallback_codex_home = codex_home.clone(); - tokio::task::spawn_blocking(move || { - epiphany_core::retrieval_state_for_workspace(&workspace_root, codex_home.as_path()) - }) - .await - .unwrap_or_else(|_| { - epiphany_core::retrieval_state_for_workspace( - &fallback_workspace_root, - fallback_codex_home.as_path(), - ) - }) - } - - pub async fn epiphany_index( - &self, - force_full_rebuild: bool, - ) -> anyhow::Result { - let config = self.codex.thread_config_snapshot().await; - let workspace_root = config.cwd.to_path_buf(); - let codex_home = self.codex.session.codex_home().await; - tokio::task::spawn_blocking(move || { - epiphany_core::index_workspace( - &workspace_root, - codex_home.as_path(), - force_full_rebuild, - ) - }) - .await - .map_err(|err| anyhow::anyhow!("epiphany index worker failed: {err}"))? - } - - pub async fn epiphany_retrieve( - &self, - query: EpiphanyRetrieveQuery, - ) -> anyhow::Result { - let config = self.codex.thread_config_snapshot().await; - let workspace_root = config.cwd.to_path_buf(); - let codex_home = self.codex.session.codex_home().await; - tokio::task::spawn_blocking(move || { - epiphany_core::retrieve_workspace(&workspace_root, codex_home.as_path(), query) - }) - .await - .map_err(|err| anyhow::anyhow!("epiphany retrieval worker failed: {err}"))? - } - pub async fn read_mcp_resource( &self, server: &str,