diff --git a/codex-rs/core/src/config.rs b/codex-rs/core/src/config.rs index fd6356ab..de97b36e 100644 --- a/codex-rs/core/src/config.rs +++ b/codex-rs/core/src/config.rs @@ -1,6 +1,9 @@ use crate::config_profile::ConfigProfile; +use crate::config_types::History; +use crate::config_types::McpServerConfig; +use crate::config_types::Tui; +use crate::config_types::UriBasedFileOpener; use crate::flags::OPENAI_DEFAULT_MODEL; -use crate::mcp_server_config::McpServerConfig; use crate::model_provider_info::ModelProviderInfo; use crate::model_provider_info::built_in_model_providers; use crate::protocol::AskForApproval; @@ -93,75 +96,6 @@ pub struct Config { pub tui: Tui, } -/// Settings that govern if and what will be written to `~/.codex/history.jsonl`. -#[derive(Deserialize, Debug, Clone, PartialEq, Default)] -pub struct History { - /// If true, history entries will not be written to disk. - pub persistence: HistoryPersistence, - - /// If set, the maximum size of the history file in bytes. - /// TODO(mbolin): Not currently honored. - pub max_bytes: Option, -} - -#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Default)] -#[serde(rename_all = "kebab-case")] -pub enum HistoryPersistence { - /// Save all history entries to disk. - #[default] - SaveAll, - /// Do not write history to disk. - None, -} - -/// Collection of settings that are specific to the TUI. -#[derive(Deserialize, Debug, Clone, PartialEq, Default)] -pub struct Tui { - /// By default, mouse capture is enabled in the TUI so that it is possible - /// to scroll the conversation history with a mouse. This comes at the cost - /// of not being able to use the mouse to select text in the TUI. - /// (Most terminals support a modifier key to allow this. For example, - /// text selection works in iTerm if you hold down the `Option` key while - /// clicking and dragging.) - /// - /// Setting this option to `true` disables mouse capture, so scrolling with - /// the mouse is not possible, though the keyboard shortcuts e.g. `b` and - /// `space` still work. This allows the user to select text in the TUI - /// using the mouse without needing to hold down a modifier key. - pub disable_mouse_capture: bool, -} - -#[derive(Deserialize, Debug, Copy, Clone, PartialEq)] -pub enum UriBasedFileOpener { - #[serde(rename = "vscode")] - VsCode, - - #[serde(rename = "vscode-insiders")] - VsCodeInsiders, - - #[serde(rename = "windsurf")] - Windsurf, - - #[serde(rename = "cursor")] - Cursor, - - /// Option to disable the URI-based file opener. - #[serde(rename = "none")] - None, -} - -impl UriBasedFileOpener { - pub fn get_scheme(&self) -> Option<&str> { - match self { - UriBasedFileOpener::VsCode => Some("vscode"), - UriBasedFileOpener::VsCodeInsiders => Some("vscode-insiders"), - UriBasedFileOpener::Windsurf => Some("windsurf"), - UriBasedFileOpener::Cursor => Some("cursor"), - UriBasedFileOpener::None => None, - } - } -} - /// Base config deserialized from ~/.codex/config.toml. #[derive(Deserialize, Debug, Clone, Default)] pub struct ConfigToml { @@ -523,6 +457,8 @@ pub fn parse_sandbox_permission_with_base_path( #[cfg(test)] mod tests { #![allow(clippy::expect_used, clippy::unwrap_used)] + use crate::config_types::HistoryPersistence; + use super::*; use pretty_assertions::assert_eq; use tempfile::TempDir; diff --git a/codex-rs/core/src/config_types.rs b/codex-rs/core/src/config_types.rs new file mode 100644 index 00000000..22c3e856 --- /dev/null +++ b/codex-rs/core/src/config_types.rs @@ -0,0 +1,88 @@ +//! Types used to define the fields of [`crate::config::Config`]. + +// Note this file should generally be restricted to simple struct/enum +// definitions that do not contain business logic. + +use std::collections::HashMap; + +use serde::Deserialize; + +#[derive(Deserialize, Debug, Clone, PartialEq)] +pub struct McpServerConfig { + pub command: String, + + #[serde(default)] + pub args: Vec, + + #[serde(default)] + pub env: Option>, +} + +#[derive(Deserialize, Debug, Copy, Clone, PartialEq)] +pub enum UriBasedFileOpener { + #[serde(rename = "vscode")] + VsCode, + + #[serde(rename = "vscode-insiders")] + VsCodeInsiders, + + #[serde(rename = "windsurf")] + Windsurf, + + #[serde(rename = "cursor")] + Cursor, + + /// Option to disable the URI-based file opener. + #[serde(rename = "none")] + None, +} + +impl UriBasedFileOpener { + pub fn get_scheme(&self) -> Option<&str> { + match self { + UriBasedFileOpener::VsCode => Some("vscode"), + UriBasedFileOpener::VsCodeInsiders => Some("vscode-insiders"), + UriBasedFileOpener::Windsurf => Some("windsurf"), + UriBasedFileOpener::Cursor => Some("cursor"), + UriBasedFileOpener::None => None, + } + } +} + +/// Settings that govern if and what will be written to `~/.codex/history.jsonl`. +#[derive(Deserialize, Debug, Clone, PartialEq, Default)] +pub struct History { + /// If true, history entries will not be written to disk. + pub persistence: HistoryPersistence, + + /// If set, the maximum size of the history file in bytes. + /// TODO(mbolin): Not currently honored. + pub max_bytes: Option, +} + +#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Default)] +#[serde(rename_all = "kebab-case")] +pub enum HistoryPersistence { + /// Save all history entries to disk. + #[default] + SaveAll, + /// Do not write history to disk. + None, +} + +/// Collection of settings that are specific to the TUI. +#[derive(Deserialize, Debug, Clone, PartialEq, Default)] +pub struct Tui { + /// By default, mouse capture is enabled in the TUI so that it is possible + /// to scroll the conversation history with a mouse. This comes at the cost + /// of not being able to use the mouse to select text in the TUI. + /// (Most terminals support a modifier key to allow this. For example, + /// text selection works in iTerm if you hold down the `Option` key while + /// clicking and dragging.) + /// + /// Setting this option to `true` disables mouse capture, so scrolling with + /// the mouse is not possible, though the keyboard shortcuts e.g. `b` and + /// `space` still work. This allows the user to select text in the TUI + /// using the mouse without needing to hold down a modifier key. + pub disable_mouse_capture: bool, +} diff --git a/codex-rs/core/src/lib.rs b/codex-rs/core/src/lib.rs index 00a65a67..759f1029 100644 --- a/codex-rs/core/src/lib.rs +++ b/codex-rs/core/src/lib.rs @@ -13,6 +13,7 @@ pub use codex::Codex; pub mod codex_wrapper; pub mod config; pub mod config_profile; +pub mod config_types; mod conversation_history; pub mod error; pub mod exec; @@ -22,7 +23,6 @@ mod is_safe_command; #[cfg(target_os = "linux")] pub mod landlock; mod mcp_connection_manager; -pub mod mcp_server_config; mod mcp_tool_call; mod message_history; mod model_provider_info; diff --git a/codex-rs/core/src/mcp_connection_manager.rs b/codex-rs/core/src/mcp_connection_manager.rs index 714c9452..6ae1865f 100644 --- a/codex-rs/core/src/mcp_connection_manager.rs +++ b/codex-rs/core/src/mcp_connection_manager.rs @@ -19,7 +19,7 @@ use mcp_types::Tool; use tokio::task::JoinSet; use tracing::info; -use crate::mcp_server_config::McpServerConfig; +use crate::config_types::McpServerConfig; /// Delimiter used to separate the server name from the tool name in a fully /// qualified tool name. diff --git a/codex-rs/core/src/mcp_server_config.rs b/codex-rs/core/src/mcp_server_config.rs deleted file mode 100644 index 30845431..00000000 --- a/codex-rs/core/src/mcp_server_config.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::collections::HashMap; - -use serde::Deserialize; - -#[derive(Deserialize, Debug, Clone, PartialEq)] -pub struct McpServerConfig { - pub command: String, - - #[serde(default)] - pub args: Vec, - - #[serde(default)] - pub env: Option>, -} diff --git a/codex-rs/core/src/message_history.rs b/codex-rs/core/src/message_history.rs index 6c201dfd..29970c2a 100644 --- a/codex-rs/core/src/message_history.rs +++ b/codex-rs/core/src/message_history.rs @@ -28,7 +28,7 @@ use tokio::io::AsyncReadExt; use uuid::Uuid; use crate::config::Config; -use crate::config::HistoryPersistence; +use crate::config_types::HistoryPersistence; #[cfg(unix)] use std::os::unix::fs::OpenOptionsExt; diff --git a/codex-rs/tui/src/markdown.rs b/codex-rs/tui/src/markdown.rs index 118eaa59..a56ce774 100644 --- a/codex-rs/tui/src/markdown.rs +++ b/codex-rs/tui/src/markdown.rs @@ -1,5 +1,5 @@ use codex_core::config::Config; -use codex_core::config::UriBasedFileOpener; +use codex_core::config_types::UriBasedFileOpener; use ratatui::text::Line; use ratatui::text::Span; use std::borrow::Cow;