Skip to content

Commit 5746561

Browse files
authored
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.
1 parent d766e84 commit 5746561

File tree

7 files changed

+98
-88
lines changed

7 files changed

+98
-88
lines changed

codex-rs/core/src/config.rs

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::config_profile::ConfigProfile;
2+
use crate::config_types::History;
3+
use crate::config_types::McpServerConfig;
4+
use crate::config_types::Tui;
5+
use crate::config_types::UriBasedFileOpener;
26
use crate::flags::OPENAI_DEFAULT_MODEL;
3-
use crate::mcp_server_config::McpServerConfig;
47
use crate::model_provider_info::ModelProviderInfo;
58
use crate::model_provider_info::built_in_model_providers;
69
use crate::protocol::AskForApproval;
@@ -93,75 +96,6 @@ pub struct Config {
9396
pub tui: Tui,
9497
}
9598

96-
/// Settings that govern if and what will be written to `~/.codex/history.jsonl`.
97-
#[derive(Deserialize, Debug, Clone, PartialEq, Default)]
98-
pub struct History {
99-
/// If true, history entries will not be written to disk.
100-
pub persistence: HistoryPersistence,
101-
102-
/// If set, the maximum size of the history file in bytes.
103-
/// TODO(mbolin): Not currently honored.
104-
pub max_bytes: Option<usize>,
105-
}
106-
107-
#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Default)]
108-
#[serde(rename_all = "kebab-case")]
109-
pub enum HistoryPersistence {
110-
/// Save all history entries to disk.
111-
#[default]
112-
SaveAll,
113-
/// Do not write history to disk.
114-
None,
115-
}
116-
117-
/// Collection of settings that are specific to the TUI.
118-
#[derive(Deserialize, Debug, Clone, PartialEq, Default)]
119-
pub struct Tui {
120-
/// By default, mouse capture is enabled in the TUI so that it is possible
121-
/// to scroll the conversation history with a mouse. This comes at the cost
122-
/// of not being able to use the mouse to select text in the TUI.
123-
/// (Most terminals support a modifier key to allow this. For example,
124-
/// text selection works in iTerm if you hold down the `Option` key while
125-
/// clicking and dragging.)
126-
///
127-
/// Setting this option to `true` disables mouse capture, so scrolling with
128-
/// the mouse is not possible, though the keyboard shortcuts e.g. `b` and
129-
/// `space` still work. This allows the user to select text in the TUI
130-
/// using the mouse without needing to hold down a modifier key.
131-
pub disable_mouse_capture: bool,
132-
}
133-
134-
#[derive(Deserialize, Debug, Copy, Clone, PartialEq)]
135-
pub enum UriBasedFileOpener {
136-
#[serde(rename = "vscode")]
137-
VsCode,
138-
139-
#[serde(rename = "vscode-insiders")]
140-
VsCodeInsiders,
141-
142-
#[serde(rename = "windsurf")]
143-
Windsurf,
144-
145-
#[serde(rename = "cursor")]
146-
Cursor,
147-
148-
/// Option to disable the URI-based file opener.
149-
#[serde(rename = "none")]
150-
None,
151-
}
152-
153-
impl UriBasedFileOpener {
154-
pub fn get_scheme(&self) -> Option<&str> {
155-
match self {
156-
UriBasedFileOpener::VsCode => Some("vscode"),
157-
UriBasedFileOpener::VsCodeInsiders => Some("vscode-insiders"),
158-
UriBasedFileOpener::Windsurf => Some("windsurf"),
159-
UriBasedFileOpener::Cursor => Some("cursor"),
160-
UriBasedFileOpener::None => None,
161-
}
162-
}
163-
}
164-
16599
/// Base config deserialized from ~/.codex/config.toml.
166100
#[derive(Deserialize, Debug, Clone, Default)]
167101
pub struct ConfigToml {
@@ -523,6 +457,8 @@ pub fn parse_sandbox_permission_with_base_path(
523457
#[cfg(test)]
524458
mod tests {
525459
#![allow(clippy::expect_used, clippy::unwrap_used)]
460+
use crate::config_types::HistoryPersistence;
461+
526462
use super::*;
527463
use pretty_assertions::assert_eq;
528464
use tempfile::TempDir;

codex-rs/core/src/config_types.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//! Types used to define the fields of [`crate::config::Config`].
2+
3+
// Note this file should generally be restricted to simple struct/enum
4+
// definitions that do not contain business logic.
5+
6+
use std::collections::HashMap;
7+
8+
use serde::Deserialize;
9+
10+
#[derive(Deserialize, Debug, Clone, PartialEq)]
11+
pub struct McpServerConfig {
12+
pub command: String,
13+
14+
#[serde(default)]
15+
pub args: Vec<String>,
16+
17+
#[serde(default)]
18+
pub env: Option<HashMap<String, String>>,
19+
}
20+
21+
#[derive(Deserialize, Debug, Copy, Clone, PartialEq)]
22+
pub enum UriBasedFileOpener {
23+
#[serde(rename = "vscode")]
24+
VsCode,
25+
26+
#[serde(rename = "vscode-insiders")]
27+
VsCodeInsiders,
28+
29+
#[serde(rename = "windsurf")]
30+
Windsurf,
31+
32+
#[serde(rename = "cursor")]
33+
Cursor,
34+
35+
/// Option to disable the URI-based file opener.
36+
#[serde(rename = "none")]
37+
None,
38+
}
39+
40+
impl UriBasedFileOpener {
41+
pub fn get_scheme(&self) -> Option<&str> {
42+
match self {
43+
UriBasedFileOpener::VsCode => Some("vscode"),
44+
UriBasedFileOpener::VsCodeInsiders => Some("vscode-insiders"),
45+
UriBasedFileOpener::Windsurf => Some("windsurf"),
46+
UriBasedFileOpener::Cursor => Some("cursor"),
47+
UriBasedFileOpener::None => None,
48+
}
49+
}
50+
}
51+
52+
/// Settings that govern if and what will be written to `~/.codex/history.jsonl`.
53+
#[derive(Deserialize, Debug, Clone, PartialEq, Default)]
54+
pub struct History {
55+
/// If true, history entries will not be written to disk.
56+
pub persistence: HistoryPersistence,
57+
58+
/// If set, the maximum size of the history file in bytes.
59+
/// TODO(mbolin): Not currently honored.
60+
pub max_bytes: Option<usize>,
61+
}
62+
63+
#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Default)]
64+
#[serde(rename_all = "kebab-case")]
65+
pub enum HistoryPersistence {
66+
/// Save all history entries to disk.
67+
#[default]
68+
SaveAll,
69+
/// Do not write history to disk.
70+
None,
71+
}
72+
73+
/// Collection of settings that are specific to the TUI.
74+
#[derive(Deserialize, Debug, Clone, PartialEq, Default)]
75+
pub struct Tui {
76+
/// By default, mouse capture is enabled in the TUI so that it is possible
77+
/// to scroll the conversation history with a mouse. This comes at the cost
78+
/// of not being able to use the mouse to select text in the TUI.
79+
/// (Most terminals support a modifier key to allow this. For example,
80+
/// text selection works in iTerm if you hold down the `Option` key while
81+
/// clicking and dragging.)
82+
///
83+
/// Setting this option to `true` disables mouse capture, so scrolling with
84+
/// the mouse is not possible, though the keyboard shortcuts e.g. `b` and
85+
/// `space` still work. This allows the user to select text in the TUI
86+
/// using the mouse without needing to hold down a modifier key.
87+
pub disable_mouse_capture: bool,
88+
}

codex-rs/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use codex::Codex;
1313
pub mod codex_wrapper;
1414
pub mod config;
1515
pub mod config_profile;
16+
pub mod config_types;
1617
mod conversation_history;
1718
pub mod error;
1819
pub mod exec;
@@ -22,7 +23,6 @@ mod is_safe_command;
2223
#[cfg(target_os = "linux")]
2324
pub mod landlock;
2425
mod mcp_connection_manager;
25-
pub mod mcp_server_config;
2626
mod mcp_tool_call;
2727
mod message_history;
2828
mod model_provider_info;

codex-rs/core/src/mcp_connection_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use mcp_types::Tool;
1919
use tokio::task::JoinSet;
2020
use tracing::info;
2121

22-
use crate::mcp_server_config::McpServerConfig;
22+
use crate::config_types::McpServerConfig;
2323

2424
/// Delimiter used to separate the server name from the tool name in a fully
2525
/// qualified tool name.

codex-rs/core/src/mcp_server_config.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

codex-rs/core/src/message_history.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use tokio::io::AsyncReadExt;
2828
use uuid::Uuid;
2929

3030
use crate::config::Config;
31-
use crate::config::HistoryPersistence;
31+
use crate::config_types::HistoryPersistence;
3232

3333
#[cfg(unix)]
3434
use std::os::unix::fs::OpenOptionsExt;

codex-rs/tui/src/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use codex_core::config::Config;
2-
use codex_core::config::UriBasedFileOpener;
2+
use codex_core::config_types::UriBasedFileOpener;
33
use ratatui::text::Line;
44
use ratatui::text::Span;
55
use std::borrow::Cow;

0 commit comments

Comments
 (0)