chore: move types out of config.rs into config_types.rs (#1054)
`config.rs` is already quite long without these definitions. Since they have no real dependencies of their own, let's move them to their own file so `config.rs` can focus on the business logic of loading a config.
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
use crate::config_profile::ConfigProfile;
|
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::flags::OPENAI_DEFAULT_MODEL;
|
||||||
use crate::mcp_server_config::McpServerConfig;
|
|
||||||
use crate::model_provider_info::ModelProviderInfo;
|
use crate::model_provider_info::ModelProviderInfo;
|
||||||
use crate::model_provider_info::built_in_model_providers;
|
use crate::model_provider_info::built_in_model_providers;
|
||||||
use crate::protocol::AskForApproval;
|
use crate::protocol::AskForApproval;
|
||||||
@@ -93,75 +96,6 @@ pub struct Config {
|
|||||||
pub tui: Tui,
|
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<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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.
|
/// Base config deserialized from ~/.codex/config.toml.
|
||||||
#[derive(Deserialize, Debug, Clone, Default)]
|
#[derive(Deserialize, Debug, Clone, Default)]
|
||||||
pub struct ConfigToml {
|
pub struct ConfigToml {
|
||||||
@@ -523,6 +457,8 @@ pub fn parse_sandbox_permission_with_base_path(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::expect_used, clippy::unwrap_used)]
|
#![allow(clippy::expect_used, clippy::unwrap_used)]
|
||||||
|
use crate::config_types::HistoryPersistence;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|||||||
88
codex-rs/core/src/config_types.rs
Normal file
88
codex-rs/core/src/config_types.rs
Normal file
@@ -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<String>,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub env: Option<HashMap<String, String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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,
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ pub use codex::Codex;
|
|||||||
pub mod codex_wrapper;
|
pub mod codex_wrapper;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod config_profile;
|
pub mod config_profile;
|
||||||
|
pub mod config_types;
|
||||||
mod conversation_history;
|
mod conversation_history;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod exec;
|
pub mod exec;
|
||||||
@@ -22,7 +23,6 @@ mod is_safe_command;
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub mod landlock;
|
pub mod landlock;
|
||||||
mod mcp_connection_manager;
|
mod mcp_connection_manager;
|
||||||
pub mod mcp_server_config;
|
|
||||||
mod mcp_tool_call;
|
mod mcp_tool_call;
|
||||||
mod message_history;
|
mod message_history;
|
||||||
mod model_provider_info;
|
mod model_provider_info;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use mcp_types::Tool;
|
|||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
use tracing::info;
|
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
|
/// Delimiter used to separate the server name from the tool name in a fully
|
||||||
/// qualified tool name.
|
/// qualified tool name.
|
||||||
|
|||||||
@@ -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<String>,
|
|
||||||
|
|
||||||
#[serde(default)]
|
|
||||||
pub env: Option<HashMap<String, String>>,
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,7 @@ use tokio::io::AsyncReadExt;
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::config::HistoryPersistence;
|
use crate::config_types::HistoryPersistence;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::OpenOptionsExt;
|
use std::os::unix::fs::OpenOptionsExt;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use codex_core::config::Config;
|
use codex_core::config::Config;
|
||||||
use codex_core::config::UriBasedFileOpener;
|
use codex_core::config_types::UriBasedFileOpener;
|
||||||
use ratatui::text::Line;
|
use ratatui::text::Line;
|
||||||
use ratatui::text::Span;
|
use ratatui::text::Span;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|||||||
Reference in New Issue
Block a user