diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 2183d91b64..bd1f9b23fc 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -2703,8 +2703,6 @@ dependencies = [ "codex-config", "codex-context-fragments", "codex-exec-server", - "codex-login", - "codex-model-provider", "codex-otel", "codex-protocol", "codex-skills", @@ -2715,14 +2713,12 @@ dependencies = [ "dunce", "pretty_assertions", "serde", - "serde_json", "serde_yaml", "shlex", "tempfile", "tokio", "toml 0.9.11+spec-1.1.0", "tracing", - "zip 2.4.2", ] [[package]] @@ -8835,7 +8831,6 @@ dependencies = [ "os_info", "pretty_assertions", "rmcp", - "serde", "serde_json", "shlex", "tokio", diff --git a/codex-rs/chatgpt/Cargo.toml b/codex-rs/chatgpt/Cargo.toml index 6b0e010964..cc733fb6ce 100644 --- a/codex-rs/chatgpt/Cargo.toml +++ b/codex-rs/chatgpt/Cargo.toml @@ -20,13 +20,13 @@ codex-model-provider = { workspace = true } codex-plugin = { workspace = true } codex-utils-cli = { workspace = true } serde = { workspace = true, features = ["derive"] } -tokio = { workspace = true, features = ["full"] } [dev-dependencies] codex-utils-cargo-bin = { workspace = true } pretty_assertions = { workspace = true } serde_json = { workspace = true } tempfile = { workspace = true } +tokio = { workspace = true, features = ["full"] } [lib] doctest = false diff --git a/codex-rs/core-plugins/src/remote_legacy.rs b/codex-rs/core-plugins/src/remote_legacy.rs index cd5a1f031c..a7ebb2240f 100644 --- a/codex-rs/core-plugins/src/remote_legacy.rs +++ b/codex-rs/core-plugins/src/remote_legacy.rs @@ -4,12 +4,10 @@ use codex_login::default_client::build_reqwest_client; use codex_protocol::protocol::Product; use serde::Deserialize; use std::time::Duration; -use url::Url; const DEFAULT_REMOTE_MARKETPLACE_NAME: &str = "openai-curated"; const REMOTE_PLUGIN_FETCH_TIMEOUT: Duration = Duration::from_secs(30); const REMOTE_FEATURED_PLUGIN_FETCH_TIMEOUT: Duration = Duration::from_secs(10); -const REMOTE_PLUGIN_MUTATION_TIMEOUT: Duration = Duration::from_secs(30); #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] pub struct RemotePluginStatusSummary { @@ -19,13 +17,6 @@ pub struct RemotePluginStatusSummary { pub enabled: bool, } -#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] -#[serde(rename_all = "camelCase")] -struct RemotePluginMutationResponse { - pub id: String, - pub enabled: bool, -} - #[derive(Debug, thiserror::Error)] pub enum RemotePluginMutationError { #[error("chatgpt authentication required for remote plugin mutation")] @@ -194,87 +185,6 @@ pub async fn fetch_remote_featured_plugin_ids( }) } -fn ensure_codex_backend_auth( - auth: Option<&CodexAuth>, -) -> Result<&CodexAuth, RemotePluginMutationError> { - let Some(auth) = auth else { - return Err(RemotePluginMutationError::AuthRequired); - }; - if !auth.uses_codex_backend() { - return Err(RemotePluginMutationError::UnsupportedAuthMode); - } - Ok(auth) -} - fn default_remote_marketplace_name() -> String { DEFAULT_REMOTE_MARKETPLACE_NAME.to_string() } - -async fn post_remote_plugin_mutation( - config: &RemotePluginServiceConfig, - auth: Option<&CodexAuth>, - plugin_id: &str, - action: &str, -) -> Result { - let auth = ensure_codex_backend_auth(auth)?; - let url = remote_plugin_mutation_url(config, plugin_id, action)?; - let client = build_reqwest_client(); - let request = client - .post(url.clone()) - .timeout(REMOTE_PLUGIN_MUTATION_TIMEOUT) - .headers(codex_model_provider::auth_provider_from_auth(auth).to_auth_headers()); - - let response = request - .send() - .await - .map_err(|source| RemotePluginMutationError::Request { - url: url.clone(), - source, - })?; - let status = response.status(); - let body = response.text().await.unwrap_or_default(); - if !status.is_success() { - return Err(RemotePluginMutationError::UnexpectedStatus { url, status, body }); - } - - let parsed: RemotePluginMutationResponse = - serde_json::from_str(&body).map_err(|source| RemotePluginMutationError::Decode { - url: url.clone(), - source, - })?; - let expected_enabled = action == "enable"; - if parsed.id != plugin_id { - return Err(RemotePluginMutationError::UnexpectedPluginId { - expected: plugin_id.to_string(), - actual: parsed.id, - }); - } - if parsed.enabled != expected_enabled { - return Err(RemotePluginMutationError::UnexpectedEnabledState { - plugin_id: plugin_id.to_string(), - expected_enabled, - actual_enabled: parsed.enabled, - }); - } - - Ok(parsed) -} - -fn remote_plugin_mutation_url( - config: &RemotePluginServiceConfig, - plugin_id: &str, - action: &str, -) -> Result { - let mut url = Url::parse(config.chatgpt_base_url.trim_end_matches('/')) - .map_err(RemotePluginMutationError::InvalidBaseUrl)?; - { - let mut segments = url - .path_segments_mut() - .map_err(|()| RemotePluginMutationError::InvalidBaseUrlPath)?; - segments.pop_if_empty(); - segments.push("plugins"); - segments.push(plugin_id); - segments.push(action); - } - Ok(url.to_string()) -} diff --git a/codex-rs/core-skills/Cargo.toml b/codex-rs/core-skills/Cargo.toml index 3c18bee603..18d704bd63 100644 --- a/codex-rs/core-skills/Cargo.toml +++ b/codex-rs/core-skills/Cargo.toml @@ -19,8 +19,6 @@ codex-app-server-protocol = { workspace = true } codex-config = { workspace = true } codex-context-fragments = { workspace = true } codex-exec-server = { workspace = true } -codex-login = { workspace = true } -codex-model-provider = { workspace = true } codex-otel = { workspace = true } codex-protocol = { workspace = true } codex-skills = { workspace = true } @@ -30,13 +28,11 @@ codex-utils-plugins = { workspace = true } dirs = { workspace = true } dunce = { workspace = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } serde_yaml = { workspace = true } shlex = { workspace = true } tokio = { workspace = true, features = ["fs", "macros", "rt"] } toml = { workspace = true } tracing = { workspace = true } -zip = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } diff --git a/codex-rs/core-skills/src/remote.rs b/codex-rs/core-skills/src/remote.rs index c643a7a08d..6debdbb65e 100644 --- a/codex-rs/core-skills/src/remote.rs +++ b/codex-rs/core-skills/src/remote.rs @@ -1,14 +1,4 @@ -use anyhow::Context; -use anyhow::Result; -use serde::Deserialize; -use std::path::Component; -use std::path::Path; use std::path::PathBuf; -use std::time::Duration; - -use codex_login::CodexAuth; - -const REMOTE_SKILLS_API_TIMEOUT: Duration = Duration::from_secs(30); // Low-level client for the remote skill API. This is intentionally kept around for // future wiring, but it is not used yet by any active product surface. @@ -29,36 +19,6 @@ pub enum RemoteSkillProductSurface { Atlas, } -fn as_query_scope(scope: RemoteSkillScope) -> Option<&'static str> { - match scope { - RemoteSkillScope::WorkspaceShared => Some("workspace-shared"), - RemoteSkillScope::AllShared => Some("all-shared"), - RemoteSkillScope::Personal => Some("personal"), - RemoteSkillScope::Example => Some("example"), - } -} - -fn as_query_product_surface(product_surface: RemoteSkillProductSurface) -> &'static str { - match product_surface { - RemoteSkillProductSurface::Chatgpt => "chatgpt", - RemoteSkillProductSurface::Codex => "codex", - RemoteSkillProductSurface::Api => "api", - RemoteSkillProductSurface::Atlas => "atlas", - } -} - -fn ensure_codex_backend_auth(auth: Option<&CodexAuth>) -> Result<&CodexAuth> { - let Some(auth) = auth else { - anyhow::bail!("chatgpt authentication required for remote skill scopes"); - }; - if !auth.uses_codex_backend() { - anyhow::bail!( - "chatgpt authentication required for remote skill scopes; api key auth is not supported" - ); - } - Ok(auth) -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct RemoteSkillSummary { pub id: String, @@ -71,84 +31,3 @@ pub struct RemoteSkillDownloadResult { pub id: String, pub path: PathBuf, } - -#[derive(Debug, Deserialize)] -struct RemoteSkillsResponse { - #[serde(rename = "hazelnuts")] - skills: Vec, -} - -#[derive(Debug, Deserialize)] -struct RemoteSkill { - id: String, - name: String, - description: String, -} - -fn safe_join(base: &Path, name: &str) -> Result { - let path = Path::new(name); - for component in path.components() { - match component { - Component::Normal(_) => {} - _ => { - anyhow::bail!("Invalid file path in remote skill payload: {name}"); - } - } - } - Ok(base.join(path)) -} - -fn is_zip_payload(bytes: &[u8]) -> bool { - bytes.starts_with(b"PK\x03\x04") - || bytes.starts_with(b"PK\x05\x06") - || bytes.starts_with(b"PK\x07\x08") -} - -fn extract_zip_to_dir( - bytes: Vec, - output_dir: &Path, - prefix_candidates: &[String], -) -> Result<()> { - let cursor = std::io::Cursor::new(bytes); - let mut archive = zip::ZipArchive::new(cursor).context("Failed to open zip archive")?; - for i in 0..archive.len() { - let mut file = archive.by_index(i).context("Failed to read zip entry")?; - if file.is_dir() { - continue; - } - let raw_name = file.name().to_string(); - let normalized = normalize_zip_name(&raw_name, prefix_candidates); - let Some(normalized) = normalized else { - continue; - }; - let file_path = safe_join(output_dir, &normalized)?; - if let Some(parent) = file_path.parent() { - std::fs::create_dir_all(parent) - .with_context(|| format!("Failed to create parent dir for {normalized}"))?; - } - let mut out = std::fs::File::create(&file_path) - .with_context(|| format!("Failed to create file {normalized}"))?; - std::io::copy(&mut file, &mut out) - .with_context(|| format!("Failed to write skill file {normalized}"))?; - } - Ok(()) -} - -fn normalize_zip_name(name: &str, prefix_candidates: &[String]) -> Option { - let mut trimmed = name.trim_start_matches("./"); - for prefix in prefix_candidates { - if prefix.is_empty() { - continue; - } - let prefix = format!("{prefix}/"); - if let Some(rest) = trimmed.strip_prefix(&prefix) { - trimmed = rest; - break; - } - } - if trimmed.is_empty() { - None - } else { - Some(trimmed.to_string()) - } -} diff --git a/codex-rs/feedback/src/lib.rs b/codex-rs/feedback/src/lib.rs index 3ca4829083..68e0424147 100644 --- a/codex-rs/feedback/src/lib.rs +++ b/codex-rs/feedback/src/lib.rs @@ -385,6 +385,7 @@ pub struct FeedbackUploadOptions<'a> { } impl FeedbackSnapshot { + #[cfg(test)] pub(crate) fn as_bytes(&self) -> &[u8] { &self.bytes } diff --git a/codex-rs/mcp-server/tests/common/Cargo.toml b/codex-rs/mcp-server/tests/common/Cargo.toml index e97042dd53..515aa01b5a 100644 --- a/codex-rs/mcp-server/tests/common/Cargo.toml +++ b/codex-rs/mcp-server/tests/common/Cargo.toml @@ -21,7 +21,6 @@ codex-utils-cargo-bin = { workspace = true } rmcp = { workspace = true } os_info = { workspace = true } pretty_assertions = { workspace = true } -serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true, features = [ "io-std", diff --git a/codex-rs/rollout/src/recorder.rs b/codex-rs/rollout/src/recorder.rs index b2dd98640b..a3040b1359 100644 --- a/codex-rs/rollout/src/recorder.rs +++ b/codex-rs/rollout/src/recorder.rs @@ -42,6 +42,7 @@ use super::list::get_threads; use super::list::get_threads_in_root; use super::list::parse_cursor; use super::list::parse_timestamp_uuid_from_filename; +#[cfg(test)] use super::metadata; use super::session_index::find_thread_names_by_ids; use crate::config::RolloutConfigView; @@ -61,6 +62,7 @@ use codex_protocol::protocol::SessionMetaLine; use codex_protocol::protocol::SessionSource; use codex_protocol::protocol::ThreadSource; use codex_state::StateRuntime; +#[cfg(test)] use codex_utils_path as path_utils; /// Writes canonical session rollout items to JSONL. @@ -1655,31 +1657,7 @@ fn thread_item_from_state_metadata(item: codex_state::ThreadMetadata) -> ThreadI } } -async fn select_resume_path( - page: &ThreadsPage, - filter_cwd: Option<&Path>, - default_provider: &str, -) -> Option { - match filter_cwd { - Some(cwd) => { - for item in &page.items { - if resume_candidate_matches_cwd( - item.path.as_path(), - item.cwd.as_deref(), - cwd, - default_provider, - ) - .await - { - return Some(item.path.clone()); - } - } - None - } - None => page.items.first().map(|item| item.path.clone()), - } -} - +#[cfg(test)] async fn resume_candidate_matches_cwd( rollout_path: &Path, cached_cwd: Option<&Path>, @@ -1707,31 +1685,7 @@ async fn resume_candidate_matches_cwd( .is_ok_and(|outcome| cwd_matches(outcome.metadata.cwd.as_path(), cwd)) } -async fn select_resume_path_from_db_page( - page: &codex_state::ThreadsPage, - filter_cwd: Option<&Path>, - default_provider: &str, -) -> Option { - match filter_cwd { - Some(cwd) => { - for item in &page.items { - if resume_candidate_matches_cwd( - item.rollout_path.as_path(), - Some(item.cwd.as_path()), - cwd, - default_provider, - ) - .await - { - return Some(item.rollout_path.clone()); - } - } - None - } - None => page.items.first().map(|item| item.rollout_path.clone()), - } -} - +#[cfg(test)] fn cwd_matches(session_cwd: &Path, cwd: &Path) -> bool { path_utils::paths_match_after_normalization(session_cwd, cwd) } diff --git a/codex-rs/shell-command/src/command_safety/mod.rs b/codex-rs/shell-command/src/command_safety/mod.rs index 60bed2effc..d78fe0327f 100644 --- a/codex-rs/shell-command/src/command_safety/mod.rs +++ b/codex-rs/shell-command/src/command_safety/mod.rs @@ -1,7 +1,7 @@ +#[cfg(windows)] mod powershell_parser; pub mod is_dangerous_command; pub mod is_safe_command; #[cfg(windows)] pub(crate) mod windows_safe_commands; -pub(crate) use powershell_parser::try_parse_powershell_ast_commands;