mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Use default-on-error config enum warnings
This commit is contained in:
Generated
+1
@@ -2391,6 +2391,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_path_to_error",
|
||||
"serde_with",
|
||||
"sha2",
|
||||
"tempfile",
|
||||
"thiserror 2.0.18",
|
||||
|
||||
@@ -34,6 +34,7 @@ schemars = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
serde_path_to_error = { workspace = true }
|
||||
serde_with = { workspace = true, features = ["macros"] }
|
||||
sha2 = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tokio = { workspace = true, features = ["fs"] }
|
||||
|
||||
@@ -44,6 +44,7 @@ use codex_protocol::config_types::SandboxMode;
|
||||
use codex_protocol::config_types::ServiceTier;
|
||||
use codex_protocol::config_types::TrustLevel;
|
||||
use codex_protocol::config_types::Verbosity;
|
||||
use codex_protocol::config_types::WebSearchContextSize;
|
||||
use codex_protocol::config_types::WebSearchMode;
|
||||
use codex_protocol::config_types::WebSearchToolConfig;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
@@ -57,6 +58,10 @@ use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::de::Error as SerdeError;
|
||||
use serde_with::DefaultOnError;
|
||||
use serde_with::serde_as;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
const RESERVED_MODEL_PROVIDER_IDS: [&str; 4] = [
|
||||
AMAZON_BEDROCK_PROVIDER_ID,
|
||||
@@ -88,6 +93,7 @@ const fn default_hide_agent_reasoning() -> Option<bool> {
|
||||
}
|
||||
|
||||
/// Base config deserialized from ~/.codex/config.toml.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct ConfigToml {
|
||||
@@ -106,11 +112,15 @@ pub struct ConfigToml {
|
||||
pub model_auto_compact_token_limit: Option<i64>,
|
||||
|
||||
/// Default approval policy for executing commands.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub approval_policy: Option<AskForApproval>,
|
||||
|
||||
/// Configures who approval requests are routed to for review once they have
|
||||
/// been escalated. This does not disable separate safety checks such as
|
||||
/// ARC.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub approvals_reviewer: Option<ApprovalsReviewer>,
|
||||
|
||||
/// Optional policy instructions for the guardian auto-reviewer.
|
||||
@@ -132,6 +142,8 @@ pub struct ConfigToml {
|
||||
pub allow_login_shell: Option<bool>,
|
||||
|
||||
/// Sandbox mode to use.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub sandbox_mode: Option<SandboxMode>,
|
||||
|
||||
/// Sandbox configuration to apply if `sandbox` is `WorkspaceWrite`.
|
||||
@@ -186,6 +198,7 @@ pub struct ConfigToml {
|
||||
|
||||
/// When set, restricts the login mechanism users may use.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub forced_login_method: Option<ForcedLoginMethod>,
|
||||
|
||||
/// Preferred backend for storing CLI auth credentials.
|
||||
@@ -193,6 +206,7 @@ pub struct ConfigToml {
|
||||
/// keyring: Use an OS-specific keyring service.
|
||||
/// auto: Use the keyring if available, otherwise use a file.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub cli_auth_credentials_store: Option<AuthCredentialsStoreMode>,
|
||||
|
||||
/// Definition for MCP servers that Codex can reach out to for tool calls.
|
||||
@@ -207,6 +221,7 @@ pub struct ConfigToml {
|
||||
/// file: Use a file in the Codex home directory.
|
||||
/// auto (default): Use the OS-specific keyring service if available, otherwise use a file.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub mcp_oauth_credentials_store: Option<OAuthCredentialsStoreMode>,
|
||||
|
||||
/// Optional fixed port for the local HTTP callback server used during MCP OAuth login.
|
||||
@@ -274,6 +289,8 @@ pub struct ConfigToml {
|
||||
|
||||
/// Optional URI-based file opener. If set, citations to files in the model
|
||||
/// output will be hyperlinked using the specified URI scheme.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub file_opener: Option<UriBasedFileOpener>,
|
||||
|
||||
/// Collection of settings that are specific to the TUI.
|
||||
@@ -288,10 +305,18 @@ pub struct ConfigToml {
|
||||
/// Defaults to `false`.
|
||||
pub show_raw_agent_reasoning: Option<bool>,
|
||||
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub model_reasoning_effort: Option<ReasoningEffort>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub plan_mode_reasoning_effort: Option<ReasoningEffort>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub model_reasoning_summary: Option<ReasoningSummary>,
|
||||
/// Optional verbosity control for GPT-5 models (Responses API `text.verbosity`).
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub model_verbosity: Option<Verbosity>,
|
||||
|
||||
/// Override to force-enable reasoning summaries for the configured model.
|
||||
@@ -302,9 +327,13 @@ pub struct ConfigToml {
|
||||
pub model_catalog_json: Option<AbsolutePathBuf>,
|
||||
|
||||
/// Optionally specify a personality for the model
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub personality: Option<Personality>,
|
||||
|
||||
/// Optional explicit service tier preference for new turns (`fast` or `flex`).
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub service_tier: Option<ServiceTier>,
|
||||
|
||||
/// Base URL for requests to ChatGPT (as opposed to the OpenAI API).
|
||||
@@ -351,10 +380,14 @@ pub struct ConfigToml {
|
||||
pub experimental_thread_config_endpoint: Option<String>,
|
||||
|
||||
/// Experimental / do not use. Selects the thread store implementation.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub experimental_thread_store: Option<ThreadStoreToml>,
|
||||
pub projects: Option<HashMap<String, ProjectConfig>>,
|
||||
|
||||
/// Controls the web search tool mode: disabled, cached, or live.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub web_search: Option<WebSearchMode>,
|
||||
|
||||
/// Nested tools section for feature toggles
|
||||
@@ -577,13 +610,22 @@ pub struct RealtimeConfig {
|
||||
pub voice: Option<RealtimeVoice>,
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct RealtimeToml {
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub version: Option<RealtimeWsVersion>,
|
||||
#[serde(rename = "type")]
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub session_type: Option<RealtimeWsMode>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub transport: Option<RealtimeTransport>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub voice: Option<RealtimeVoice>,
|
||||
}
|
||||
|
||||
@@ -621,15 +663,35 @@ fn deserialize_optional_web_search_tool_config<'de, D>(
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let value = Option::<WebSearchToolConfigInput>::deserialize(deserializer)?;
|
||||
let Some(value) = Option::<TomlValue>::deserialize(deserializer)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let value = match value.clone().try_into::<WebSearchToolConfigInput>() {
|
||||
Ok(value) => value,
|
||||
Err(err) => {
|
||||
let mut without_context_size = value.clone();
|
||||
let removed_context_size = without_context_size
|
||||
.as_table_mut()
|
||||
.and_then(|table| table.remove("context_size"))
|
||||
.is_some_and(|context_size| {
|
||||
context_size.try_into::<WebSearchContextSize>().is_err()
|
||||
});
|
||||
if !removed_context_size {
|
||||
return Err(SerdeError::custom(err.to_string()));
|
||||
}
|
||||
without_context_size
|
||||
.try_into::<WebSearchToolConfigInput>()
|
||||
.map_err(SerdeError::custom)?
|
||||
}
|
||||
};
|
||||
|
||||
Ok(match value {
|
||||
None => None,
|
||||
Some(WebSearchToolConfigInput::Enabled(enabled)) => {
|
||||
WebSearchToolConfigInput::Enabled(enabled) => {
|
||||
let _ = enabled;
|
||||
None
|
||||
}
|
||||
Some(WebSearchToolConfigInput::Config(config)) => Some(config),
|
||||
WebSearchToolConfigInput::Config(config) => Some(config),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+282
-283
@@ -1,318 +1,317 @@
|
||||
use crate::config_toml::ConfigToml;
|
||||
use crate::config_toml::RealtimeTransport;
|
||||
use crate::config_toml::RealtimeVoice;
|
||||
use crate::config_toml::RealtimeWsMode;
|
||||
use crate::config_toml::RealtimeWsVersion;
|
||||
use crate::config_toml::ThreadStoreToml;
|
||||
use crate::mcp_types::AppToolApproval;
|
||||
use crate::types::AltScreenMode;
|
||||
use crate::types::ApprovalsReviewer;
|
||||
use crate::types::AuthCredentialsStoreMode;
|
||||
use crate::types::HistoryPersistence;
|
||||
use crate::types::MarketplaceSourceType;
|
||||
use crate::types::NotificationCondition;
|
||||
use crate::types::NotificationMethod;
|
||||
use crate::types::Notifications;
|
||||
use crate::types::OAuthCredentialsStoreMode;
|
||||
use crate::types::SessionPickerViewMode;
|
||||
use crate::types::UriBasedFileOpener;
|
||||
use crate::types::WindowsSandboxModeToml;
|
||||
use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use codex_protocol::config_types::Personality;
|
||||
use codex_protocol::config_types::ReasoningSummary;
|
||||
use codex_protocol::config_types::SandboxMode;
|
||||
use codex_protocol::config_types::ServiceTier;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicyInherit;
|
||||
use codex_protocol::config_types::Verbosity;
|
||||
use codex_protocol::config_types::WebSearchContextSize;
|
||||
use codex_protocol::config_types::WebSearchMode;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_path_to_error::Path as SerdePath;
|
||||
use serde_path_to_error::Segment as SerdeSegment;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
const WEB_SEARCH_TOOL_CONFIG_INPUT_ERROR: &str =
|
||||
"data did not match any variant of untagged enum WebSearchToolConfigInput";
|
||||
const NOTIFICATIONS_ERROR: &str = "data did not match any variant of untagged enum Notifications";
|
||||
const CONTEXT_SIZE_KEY: &str = "context_size";
|
||||
const NOTIFICATIONS_KEY: &str = "notifications";
|
||||
const SHELL_ENVIRONMENT_POLICY: &str = "shell_environment_policy";
|
||||
const CONTEXT_SIZE: &str = "context_size";
|
||||
const DEFAULT_TOOLS_APPROVAL_MODE: &str = "default_tools_approval_mode";
|
||||
const APPROVAL_MODE: &str = "approval_mode";
|
||||
|
||||
/// Deserializes TOML while turning invalid enum-valued settings into warnings.
|
||||
macro_rules! check_fields {
|
||||
($value:expr, $path:expr, $warnings:expr, $( $key:expr => $ty:ty ),+ $(,)?) => {
|
||||
$(
|
||||
check_value::<$ty>($value, &child_path($path, $key), $warnings);
|
||||
)+
|
||||
};
|
||||
}
|
||||
|
||||
/// Deserializes config while turning known invalid enum-valued settings into warnings.
|
||||
///
|
||||
/// Serde reports enum failures as normal deserialization errors, which would
|
||||
/// otherwise reject the whole assembled config. Config files are user-editable,
|
||||
/// so this helper keeps the strongly typed destination type and handles enum
|
||||
/// leniency at the load boundary: deserialize, find the first invalid enum
|
||||
/// value, remove only that TOML key, record a startup warning, and retry.
|
||||
pub(crate) fn deserialize_with_enum_warnings<T>(
|
||||
mut value: TomlValue,
|
||||
) -> Result<(TomlValue, T, Vec<String>), toml::de::Error>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
/// The config structs use `serde_with::DefaultOnError` on their enum fields so
|
||||
/// an invalid field can default instead of rejecting the whole file. This helper
|
||||
/// runs the companion best-effort scan over the raw TOML first. When a known
|
||||
/// enum-bearing leaf fails to parse as its real type, the leaf is removed from
|
||||
/// the sanitized TOML and a startup warning is recorded.
|
||||
pub(crate) fn deserialize_with_enum_warnings(
|
||||
value: TomlValue,
|
||||
) -> Result<(TomlValue, ConfigToml, Vec<String>), toml::de::Error> {
|
||||
let mut sanitized = value;
|
||||
let warnings = remove_invalid_enum_values(&mut sanitized);
|
||||
let parsed = sanitized.clone().try_into::<ConfigToml>()?;
|
||||
Ok((sanitized, parsed, warnings))
|
||||
}
|
||||
|
||||
fn remove_invalid_enum_values(value: &mut TomlValue) -> Vec<String> {
|
||||
let mut warnings = Vec::new();
|
||||
|
||||
loop {
|
||||
// serde_path_to_error gives us the config path that failed, so we can
|
||||
// remove the offending TOML value without making invalid enum state
|
||||
// representable inside ConfigToml or its nested structs.
|
||||
match serde_path_to_error::deserialize(value.clone()) {
|
||||
Ok(parsed) => return Ok((value, parsed, warnings)),
|
||||
Err(err) => {
|
||||
let Some(path) = path_segments(err.path()) else {
|
||||
return Err(err.into_inner());
|
||||
};
|
||||
let toml_error = err.into_inner();
|
||||
|
||||
let removed = if is_unknown_variant_error(&toml_error) {
|
||||
remove_unknown_variant_value::<T>(
|
||||
&mut value,
|
||||
&path,
|
||||
unknown_variant(&toml_error),
|
||||
toml_error.message(),
|
||||
)
|
||||
} else if is_web_search_tool_config_input_error(&toml_error) {
|
||||
remove_invalid_web_search_context_size(&mut value, &path)
|
||||
} else if is_notifications_error(&toml_error) {
|
||||
remove_invalid_notifications_value(&mut value, &path)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let Some((removed_path, invalid_value)) = removed else {
|
||||
return Err(toml_error);
|
||||
};
|
||||
warnings.push(format!(
|
||||
"Ignoring invalid config value at {}: {invalid_value}",
|
||||
display_path(&removed_path)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
let path = Vec::new();
|
||||
scan_config_toml(value, &path, &mut warnings);
|
||||
warnings
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
enum PathSegment {
|
||||
Key(String),
|
||||
Index(usize),
|
||||
fn scan_config_toml(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
"approval_policy" => AskForApproval,
|
||||
"approvals_reviewer" => ApprovalsReviewer,
|
||||
"sandbox_mode" => SandboxMode,
|
||||
"forced_login_method" => ForcedLoginMethod,
|
||||
"cli_auth_credentials_store" => AuthCredentialsStoreMode,
|
||||
"mcp_oauth_credentials_store" => OAuthCredentialsStoreMode,
|
||||
"file_opener" => UriBasedFileOpener,
|
||||
"model_reasoning_effort" => ReasoningEffort,
|
||||
"plan_mode_reasoning_effort" => ReasoningEffort,
|
||||
"model_reasoning_summary" => ReasoningSummary,
|
||||
"model_verbosity" => Verbosity,
|
||||
"personality" => Personality,
|
||||
"service_tier" => ServiceTier,
|
||||
"experimental_thread_store" => ThreadStoreToml,
|
||||
"web_search" => WebSearchMode,
|
||||
);
|
||||
|
||||
scan_shell_environment_policy(value, &child_path(path, SHELL_ENVIRONMENT_POLICY), warnings);
|
||||
scan_history(value, &child_path(path, "history"), warnings);
|
||||
scan_tui(value, &child_path(path, "tui"), warnings);
|
||||
scan_realtime(value, &child_path(path, "realtime"), warnings);
|
||||
scan_tools(value, &child_path(path, "tools"), warnings);
|
||||
scan_windows(value, &child_path(path, "windows"), warnings);
|
||||
scan_profiles(value, &child_path(path, "profiles"), warnings);
|
||||
scan_mcp_servers(value, &child_path(path, "mcp_servers"), warnings);
|
||||
scan_apps(value, &child_path(path, "apps"), warnings);
|
||||
scan_plugins(value, &child_path(path, "plugins"), warnings);
|
||||
scan_marketplaces(value, &child_path(path, "marketplaces"), warnings);
|
||||
}
|
||||
|
||||
/// Converts Serde's structured path into the TOML traversal path used below.
|
||||
///
|
||||
/// Root-level or unknown paths are not safe to remove because they do not name
|
||||
/// a specific user-authored key.
|
||||
fn path_segments(path: &SerdePath) -> Option<Vec<PathSegment>> {
|
||||
let mut segments = Vec::new();
|
||||
for segment in path {
|
||||
match segment {
|
||||
SerdeSegment::Map { key } | SerdeSegment::Enum { variant: key } => {
|
||||
segments.push(PathSegment::Key(key.clone()));
|
||||
}
|
||||
SerdeSegment::Seq { index } => segments.push(PathSegment::Index(*index)),
|
||||
SerdeSegment::Unknown => return None,
|
||||
}
|
||||
}
|
||||
(!segments.is_empty()).then_some(segments)
|
||||
}
|
||||
|
||||
/// Detects Serde's enum-variant failures without swallowing unrelated errors.
|
||||
///
|
||||
/// toml::de::Error does not expose a structured enum-kind discriminator, so the
|
||||
/// loader keeps the match deliberately narrow and lets all other parse and type
|
||||
/// errors flow through the existing config-error path.
|
||||
fn is_unknown_variant_error(err: &toml::de::Error) -> bool {
|
||||
err.message().contains("unknown variant")
|
||||
}
|
||||
|
||||
/// Extracts the rejected enum variant from Serde's diagnostic string.
|
||||
///
|
||||
/// The TOML error type does not expose this value directly, but Serde formats
|
||||
/// enum errors consistently as `unknown variant \`value\``. The value lets us
|
||||
/// recover a leaf key when Serde reports the containing table for flattened
|
||||
/// config structs.
|
||||
fn unknown_variant(err: &toml::de::Error) -> Option<&str> {
|
||||
let message = err.message();
|
||||
let variant = message.strip_prefix("unknown variant `")?;
|
||||
let (variant, _) = variant.split_once('`')?;
|
||||
Some(variant)
|
||||
}
|
||||
|
||||
/// Detects the custom `tools.web_search` deserializer's collapsed error.
|
||||
fn is_web_search_tool_config_input_error(err: &toml::de::Error) -> bool {
|
||||
err.message() == WEB_SEARCH_TOOL_CONFIG_INPUT_ERROR
|
||||
}
|
||||
|
||||
/// Detects the untagged TUI notification setting error.
|
||||
fn is_notifications_error(err: &toml::de::Error) -> bool {
|
||||
err.message() == NOTIFICATIONS_ERROR
|
||||
}
|
||||
|
||||
/// Removes an ordinary enum leaf, but only when the TOML value matches the
|
||||
/// rejected variant Serde reported.
|
||||
fn remove_unknown_variant_value<T>(
|
||||
fn scan_shell_environment_policy(
|
||||
value: &mut TomlValue,
|
||||
path: &[PathSegment],
|
||||
unknown_variant: Option<&str>,
|
||||
original_message: &str,
|
||||
) -> Option<(Vec<PathSegment>, TomlValue)>
|
||||
path: &[String],
|
||||
warnings: &mut Vec<String>,
|
||||
) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
"inherit" => ShellEnvironmentPolicyInherit,
|
||||
);
|
||||
}
|
||||
|
||||
fn scan_history(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
"persistence" => HistoryPersistence,
|
||||
);
|
||||
}
|
||||
|
||||
fn scan_tui(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
"notifications" => Notifications,
|
||||
"notification_method" => NotificationMethod,
|
||||
"notification_condition" => NotificationCondition,
|
||||
"alternate_screen" => AltScreenMode,
|
||||
"session_picker_view" => SessionPickerViewMode,
|
||||
);
|
||||
}
|
||||
|
||||
fn scan_realtime(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
"version" => RealtimeWsVersion,
|
||||
"type" => RealtimeWsMode,
|
||||
"transport" => RealtimeTransport,
|
||||
"voice" => RealtimeVoice,
|
||||
);
|
||||
}
|
||||
|
||||
fn scan_tools(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
check_fields!(
|
||||
value,
|
||||
&child_path(path, "web_search"),
|
||||
warnings,
|
||||
CONTEXT_SIZE => WebSearchContextSize,
|
||||
);
|
||||
}
|
||||
|
||||
fn scan_windows(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
"sandbox" => WindowsSandboxModeToml,
|
||||
);
|
||||
}
|
||||
|
||||
fn scan_profiles(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
for profile_path in child_table_paths(value, path) {
|
||||
scan_profile(value, &profile_path, warnings);
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_profile(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
"service_tier" => ServiceTier,
|
||||
"approval_policy" => AskForApproval,
|
||||
"approvals_reviewer" => ApprovalsReviewer,
|
||||
"sandbox_mode" => SandboxMode,
|
||||
"model_reasoning_effort" => ReasoningEffort,
|
||||
"plan_mode_reasoning_effort" => ReasoningEffort,
|
||||
"model_reasoning_summary" => ReasoningSummary,
|
||||
"model_verbosity" => Verbosity,
|
||||
"personality" => Personality,
|
||||
"web_search" => WebSearchMode,
|
||||
);
|
||||
scan_tools(value, &child_path(path, "tools"), warnings);
|
||||
scan_windows(value, &child_path(path, "windows"), warnings);
|
||||
check_fields!(
|
||||
value,
|
||||
&child_path(path, "tui"),
|
||||
warnings,
|
||||
"session_picker_view" => SessionPickerViewMode,
|
||||
);
|
||||
}
|
||||
|
||||
fn scan_mcp_servers(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
for server_path in child_table_paths(value, path) {
|
||||
scan_tool_approval_overrides(value, &server_path, warnings);
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_apps(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
for app_path in child_table_paths(value, path) {
|
||||
scan_tool_approval_overrides(value, &app_path, warnings);
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_plugins(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
for plugin_path in child_table_paths(value, path) {
|
||||
for server_path in child_table_paths(value, &child_path(&plugin_path, "mcp_servers")) {
|
||||
scan_tool_approval_overrides(value, &server_path, warnings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_tool_approval_overrides(
|
||||
value: &mut TomlValue,
|
||||
path: &[String],
|
||||
warnings: &mut Vec<String>,
|
||||
) {
|
||||
check_fields!(
|
||||
value,
|
||||
path,
|
||||
warnings,
|
||||
DEFAULT_TOOLS_APPROVAL_MODE => AppToolApproval,
|
||||
);
|
||||
for tool_path in child_table_paths(value, &child_path(path, "tools")) {
|
||||
check_fields!(
|
||||
value,
|
||||
&tool_path,
|
||||
warnings,
|
||||
APPROVAL_MODE => AppToolApproval,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_marketplaces(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>) {
|
||||
for marketplace_path in child_table_paths(value, path) {
|
||||
check_fields!(
|
||||
value,
|
||||
&marketplace_path,
|
||||
warnings,
|
||||
"source_type" => MarketplaceSourceType,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks one known enum leaf by parsing the raw TOML value as the real field type.
|
||||
fn check_value<T>(value: &mut TomlValue, path: &[String], warnings: &mut Vec<String>)
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let variant = unknown_variant?;
|
||||
if value_at_segments(value, path).and_then(TomlValue::as_str) == Some(variant) {
|
||||
return remove_value_at_segments(value, path).map(|removed| (path.to_vec(), removed));
|
||||
let Some(raw_value) = value_at_path(value, path) else {
|
||||
return;
|
||||
};
|
||||
if raw_value.clone().try_into::<T>().is_ok() {
|
||||
return;
|
||||
}
|
||||
remove_direct_string_child_that_unblocks::<T>(value, path, variant, original_message)
|
||||
let Some(invalid_value) = remove_value_at_path(value, path) else {
|
||||
return;
|
||||
};
|
||||
warnings.push(format!(
|
||||
"Ignoring invalid config value at {}: {invalid_value}",
|
||||
display_path(path)
|
||||
));
|
||||
}
|
||||
|
||||
/// Removes `tools.web_search.context_size` after the untagged table/boolean
|
||||
/// deserializer hides the inner enum error.
|
||||
///
|
||||
/// The explicit path keeps this from swallowing unrelated `tools.web_search`
|
||||
/// shape errors such as a bad `allowed_domains` value.
|
||||
fn remove_invalid_web_search_context_size(
|
||||
value: &mut TomlValue,
|
||||
web_search_path: &[PathSegment],
|
||||
) -> Option<(Vec<PathSegment>, TomlValue)> {
|
||||
remove_invalid_leaf_value::<WebSearchContextSize>(value, web_search_path, CONTEXT_SIZE_KEY)
|
||||
/// Returns table child paths in TOML map order without holding a borrow.
|
||||
fn child_table_paths(value: &TomlValue, path: &[String]) -> Vec<Vec<String>> {
|
||||
let Some(table) = value_at_path(value, path).and_then(TomlValue::as_table) else {
|
||||
return Vec::new();
|
||||
};
|
||||
table
|
||||
.iter()
|
||||
.filter_map(|(key, value)| value.is_table().then(|| child_path(path, key)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Removes `tui.notifications` when its untagged bool/list parser fails.
|
||||
///
|
||||
/// This is separate from ordinary enum handling because Serde's untagged error
|
||||
/// does not include the rejected value text. The candidate path is constrained
|
||||
/// to the `notifications` leaf so a flattened-parent error cannot delete the
|
||||
/// entire `[tui]` table.
|
||||
fn remove_invalid_notifications_value(
|
||||
value: &mut TomlValue,
|
||||
path: &[PathSegment],
|
||||
) -> Option<(Vec<PathSegment>, TomlValue)> {
|
||||
remove_invalid_leaf_value::<Notifications>(value, path, NOTIFICATIONS_KEY)
|
||||
}
|
||||
|
||||
/// Reads a TOML value by structured path without flattening map keys into text.
|
||||
fn value_at_segments<'a>(value: &'a TomlValue, segments: &[PathSegment]) -> Option<&'a TomlValue> {
|
||||
fn value_at_path<'a>(value: &'a TomlValue, path: &[String]) -> Option<&'a TomlValue> {
|
||||
let mut current = value;
|
||||
for segment in segments {
|
||||
match segment {
|
||||
PathSegment::Key(key) => current = current.as_table()?.get(key)?,
|
||||
PathSegment::Index(index) => current = current.as_array()?.get(*index)?,
|
||||
}
|
||||
for key in path {
|
||||
current = current.as_table()?.get(key)?;
|
||||
}
|
||||
Some(current)
|
||||
}
|
||||
|
||||
/// Removes a flattened enum child only after proving it unblocks parsing.
|
||||
///
|
||||
/// For `#[serde(flatten)]`, serde_path_to_error can report the containing
|
||||
/// table instead of the enum leaf. Recursing through the whole subtree can
|
||||
/// remove the wrong setting, so this fallback only tries direct string children
|
||||
/// with the rejected value and accepts exactly one child that moves
|
||||
/// deserialization past the original error.
|
||||
fn remove_direct_string_child_that_unblocks<T>(
|
||||
value: &mut TomlValue,
|
||||
path: &[PathSegment],
|
||||
variant: &str,
|
||||
original_message: &str,
|
||||
) -> Option<(Vec<PathSegment>, TomlValue)>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let mut unblocking_key = None;
|
||||
for end in (0..=path.len()).rev() {
|
||||
let parent_path = &path[..end];
|
||||
let Some(table) = value_at_segments(value, parent_path).and_then(TomlValue::as_table)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let keys = table
|
||||
.iter()
|
||||
.filter_map(|(key, child)| (child.as_str() == Some(variant)).then_some(key.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for key in keys {
|
||||
let mut child_path = parent_path.to_vec();
|
||||
child_path.push(PathSegment::Key(key.clone()));
|
||||
|
||||
let mut candidate_value = value.clone();
|
||||
remove_value_at_segments(&mut candidate_value, &child_path)?;
|
||||
let parsed: Result<T, serde_path_to_error::Error<toml::de::Error>> =
|
||||
serde_path_to_error::deserialize(candidate_value);
|
||||
let removes_original_error = match parsed {
|
||||
Ok(_) => true,
|
||||
Err(err) => {
|
||||
path_segments(err.path()).as_deref() != Some(path)
|
||||
|| err.inner().message() != original_message
|
||||
}
|
||||
};
|
||||
if !removes_original_error {
|
||||
continue;
|
||||
}
|
||||
if unblocking_key
|
||||
.replace((parent_path.to_vec(), key))
|
||||
.is_some()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let (mut child_path, key) = unblocking_key?;
|
||||
child_path.push(PathSegment::Key(key));
|
||||
remove_value_at_segments(value, &child_path).map(|removed| (child_path, removed))
|
||||
}
|
||||
|
||||
/// Removes a named leaf after proving that leaf still fails typed parsing.
|
||||
///
|
||||
/// Untagged enum errors can point at a containing table, or at an internal
|
||||
/// deserializer segment that is not a real TOML key. Walking ancestors lets us
|
||||
/// recover `path.leaf` without ever searching unrelated descendants.
|
||||
fn remove_invalid_leaf_value<T>(
|
||||
value: &mut TomlValue,
|
||||
path: &[PathSegment],
|
||||
leaf: &str,
|
||||
) -> Option<(Vec<PathSegment>, TomlValue)>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
for end in (0..=path.len()).rev() {
|
||||
let mut candidate = path[..end].to_vec();
|
||||
if !candidate
|
||||
.last()
|
||||
.is_some_and(|segment| matches!(segment, PathSegment::Key(key) if key == leaf))
|
||||
{
|
||||
candidate.push(PathSegment::Key(leaf.to_string()));
|
||||
}
|
||||
|
||||
let parsed: Result<T, toml::de::Error> = {
|
||||
let Some(raw_value) = value_at_segments(value, &candidate) else {
|
||||
continue;
|
||||
};
|
||||
raw_value.clone().try_into()
|
||||
};
|
||||
if parsed.is_ok() {
|
||||
return None;
|
||||
}
|
||||
return remove_value_at_segments(value, &candidate).map(|removed| (candidate, removed));
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// Deletes the offending TOML value by structured path.
|
||||
fn remove_value_at_segments(value: &mut TomlValue, segments: &[PathSegment]) -> Option<TomlValue> {
|
||||
let (last, parents) = segments.split_last()?;
|
||||
fn remove_value_at_path(value: &mut TomlValue, path: &[String]) -> Option<TomlValue> {
|
||||
let (last, parents) = path.split_last()?;
|
||||
let mut current = value;
|
||||
for segment in parents {
|
||||
match segment {
|
||||
PathSegment::Key(key) => current = current.as_table_mut()?.get_mut(key)?,
|
||||
PathSegment::Index(index) => current = current.as_array_mut()?.get_mut(*index)?,
|
||||
}
|
||||
}
|
||||
match last {
|
||||
PathSegment::Key(key) => current.as_table_mut()?.remove(key),
|
||||
PathSegment::Index(index) => {
|
||||
let array = current.as_array_mut()?;
|
||||
if *index >= array.len() {
|
||||
return None;
|
||||
}
|
||||
Some(array.remove(*index))
|
||||
}
|
||||
for key in parents {
|
||||
current = current.as_table_mut()?.get_mut(key)?;
|
||||
}
|
||||
current.as_table_mut()?.remove(last)
|
||||
}
|
||||
|
||||
/// Formats paths for warnings, quoting literal table keys that contain dots.
|
||||
fn display_path(segments: &[PathSegment]) -> String {
|
||||
let mut path = String::new();
|
||||
for segment in segments {
|
||||
match segment {
|
||||
PathSegment::Key(key) => {
|
||||
if !path.is_empty() {
|
||||
path.push('.');
|
||||
}
|
||||
path.push_str(&display_key(key));
|
||||
}
|
||||
PathSegment::Index(index) => path.push_str(&format!("[{index}]")),
|
||||
}
|
||||
}
|
||||
path
|
||||
fn child_path(path: &[String], key: &str) -> Vec<String> {
|
||||
let mut child = path.to_vec();
|
||||
child.push(key.to_string());
|
||||
child
|
||||
}
|
||||
|
||||
fn display_path(path: &[String]) -> String {
|
||||
path.iter()
|
||||
.map(|key| display_key(key))
|
||||
.collect::<Vec<_>>()
|
||||
.join(".")
|
||||
}
|
||||
|
||||
/// Formats one TOML key segment for warning paths.
|
||||
fn display_key(key: &str) -> String {
|
||||
if !key.is_empty()
|
||||
&& key
|
||||
|
||||
@@ -877,7 +877,7 @@ pub fn resolve_relative_paths_in_config_toml(
|
||||
// the final config load can still surface the startup warning.
|
||||
let _guard = AbsolutePathBufGuard::new(base_dir);
|
||||
let Ok((_sanitized, resolved, _enum_warnings)) =
|
||||
deserialize_with_enum_warnings::<ConfigToml>(value_from_config_toml.clone())
|
||||
deserialize_with_enum_warnings(value_from_config_toml.clone())
|
||||
else {
|
||||
return Ok(value_from_config_toml);
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@ use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::de::Error as SerdeError;
|
||||
use serde_with::DefaultOnError;
|
||||
use serde_with::serde_as;
|
||||
|
||||
use crate::RequirementSource;
|
||||
|
||||
@@ -48,11 +50,13 @@ impl fmt::Display for McpServerDisabledReason {
|
||||
}
|
||||
|
||||
/// Per-tool approval settings for a single MCP server tool.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct McpServerToolConfig {
|
||||
/// Approval mode for this tool.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub approval_mode: Option<AppToolApproval>,
|
||||
}
|
||||
|
||||
@@ -185,6 +189,7 @@ pub struct McpServerConfig {
|
||||
/// Keep `TryFrom<RawMcpServerConfig> for McpServerConfig` exhaustively
|
||||
/// destructuring this struct so new TOML fields cannot be added here without
|
||||
/// updating the validation/mapping logic that produces [`McpServerConfig`].
|
||||
#[serde_as]
|
||||
#[derive(Deserialize, Clone, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct RawMcpServerConfig {
|
||||
@@ -225,6 +230,7 @@ pub struct RawMcpServerConfig {
|
||||
#[serde(default)]
|
||||
pub supports_parallel_tool_calls: Option<bool>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub default_tools_approval_mode: Option<AppToolApproval>,
|
||||
#[serde(default)]
|
||||
pub enabled_tools: Option<Vec<String>>,
|
||||
|
||||
@@ -2,6 +2,8 @@ use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_with::DefaultOnError;
|
||||
use serde_with::serde_as;
|
||||
|
||||
use crate::config_toml::ToolsToml;
|
||||
use crate::types::AnalyticsConfigToml;
|
||||
@@ -20,24 +22,43 @@ use codex_protocol::protocol::AskForApproval;
|
||||
|
||||
/// Collection of common configuration options that a user can define as a unit
|
||||
/// in `config.toml`.
|
||||
#[serde_as]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct ConfigProfile {
|
||||
pub model: Option<String>,
|
||||
/// Optional explicit service tier preference for new turns (`fast` or `flex`).
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub service_tier: Option<ServiceTier>,
|
||||
/// The key in the `model_providers` map identifying the
|
||||
/// [`ModelProviderInfo`] to use.
|
||||
pub model_provider: Option<String>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub approval_policy: Option<AskForApproval>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub approvals_reviewer: Option<ApprovalsReviewer>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub sandbox_mode: Option<SandboxMode>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub model_reasoning_effort: Option<ReasoningEffort>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub plan_mode_reasoning_effort: Option<ReasoningEffort>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub model_reasoning_summary: Option<ReasoningSummary>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub model_verbosity: Option<Verbosity>,
|
||||
/// Optional path to a JSON model catalog (applied on startup only).
|
||||
pub model_catalog_json: Option<AbsolutePathBuf>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub personality: Option<Personality>,
|
||||
pub chatgpt_base_url: Option<String>,
|
||||
/// Optional path to a file containing model instructions.
|
||||
@@ -62,6 +83,8 @@ pub struct ConfigProfile {
|
||||
pub experimental_use_freeform_apply_patch: Option<bool>,
|
||||
pub tools_view_image: Option<bool>,
|
||||
pub tools: Option<ToolsToml>,
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub web_search: Option<WebSearchMode>,
|
||||
pub analytics: Option<AnalyticsConfigToml>,
|
||||
/// TUI settings scoped to this profile.
|
||||
@@ -78,12 +101,14 @@ pub struct ConfigProfile {
|
||||
}
|
||||
|
||||
/// TUI settings supported inside a named profile.
|
||||
#[serde_as]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct ProfileTui {
|
||||
/// Preferred layout for resume/fork session picker results.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub session_picker_view: Option<SessionPickerViewMode>,
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use super::fingerprint::version_for_toml;
|
||||
use super::key_aliases::normalized_with_key_aliases;
|
||||
use super::lenient::deserialize_with_enum_warnings;
|
||||
use super::merge::merge_toml_values;
|
||||
use crate::config_toml::ConfigToml;
|
||||
use codex_app_server_protocol::ConfigLayer;
|
||||
use codex_app_server_protocol::ConfigLayerMetadata;
|
||||
use codex_app_server_protocol::ConfigLayerSource;
|
||||
@@ -323,12 +324,9 @@ impl ConfigLayerStack {
|
||||
/// invalid enum values while consumers still receive a fully typed config.
|
||||
/// Each layer is sanitized before it is merged so a higher-precedence
|
||||
/// invalid enum value falls back to a valid lower-precedence value.
|
||||
pub fn deserialize_effective_config_with_warnings<T>(
|
||||
pub fn deserialize_effective_config_with_warnings(
|
||||
&self,
|
||||
) -> Result<(TomlValue, T, Vec<String>), toml::de::Error>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
) -> Result<(TomlValue, ConfigToml, Vec<String>), toml::de::Error> {
|
||||
let mut merged = TomlValue::Table(toml::map::Map::new());
|
||||
let mut warnings = Vec::new();
|
||||
|
||||
@@ -339,13 +337,13 @@ impl ConfigLayerStack {
|
||||
let mut normalized_layer = TomlValue::Table(toml::map::Map::new());
|
||||
merge_toml_values(&mut normalized_layer, &layer.config);
|
||||
let (sanitized_layer, _typed_layer, layer_warnings) =
|
||||
deserialize_with_enum_warnings::<T>(normalized_layer)?;
|
||||
deserialize_with_enum_warnings(normalized_layer)?;
|
||||
warnings.extend(layer_warnings);
|
||||
merge_toml_values(&mut merged, &sanitized_layer);
|
||||
}
|
||||
|
||||
let (sanitized_effective, typed_effective, effective_warnings) =
|
||||
deserialize_with_enum_warnings::<T>(merged)?;
|
||||
deserialize_with_enum_warnings(merged)?;
|
||||
warnings.extend(effective_warnings);
|
||||
Ok((sanitized_effective, typed_effective, warnings))
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ use std::fmt;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_with::DefaultOnError;
|
||||
use serde_with::serde_as;
|
||||
|
||||
pub use crate::tui_keymap::KeybindingSpec;
|
||||
pub use crate::tui_keymap::KeybindingsSpec;
|
||||
@@ -118,9 +120,12 @@ pub enum WindowsSandboxModeToml {
|
||||
Unelevated,
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct WindowsToml {
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub sandbox: Option<WindowsSandboxModeToml>,
|
||||
/// Defaults to `true`. Set to `false` to launch the final sandboxed child
|
||||
/// process on `Winsta0\\Default` instead of a private desktop.
|
||||
@@ -159,11 +164,13 @@ impl UriBasedFileOpener {
|
||||
}
|
||||
|
||||
/// Settings that govern if and what will be written to `~/.codex/history.jsonl`.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[serde(default)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct History {
|
||||
/// If true, history entries will not be written to disk.
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub persistence: HistoryPersistence,
|
||||
|
||||
/// If set, the maximum size of the history file in bytes. The oldest entries
|
||||
@@ -389,6 +396,7 @@ pub struct AppsDefaultConfig {
|
||||
}
|
||||
|
||||
/// Per-tool settings for a single app tool.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct AppToolConfig {
|
||||
@@ -398,6 +406,7 @@ pub struct AppToolConfig {
|
||||
|
||||
/// Approval mode for this tool.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub approval_mode: Option<AppToolApproval>,
|
||||
}
|
||||
|
||||
@@ -411,6 +420,7 @@ pub struct AppToolsConfig {
|
||||
}
|
||||
|
||||
/// Config values for a single app/connector.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct AppConfig {
|
||||
@@ -428,6 +438,7 @@ pub struct AppConfig {
|
||||
|
||||
/// Approval mode for tools in this app unless a tool override exists.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub default_tools_approval_mode: Option<AppToolApproval>,
|
||||
|
||||
/// Whether tools are enabled by default for this app.
|
||||
@@ -589,22 +600,26 @@ impl fmt::Display for NotificationCondition {
|
||||
}
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct TuiNotificationSettings {
|
||||
/// Enable desktop notifications from the TUI.
|
||||
/// Defaults to `true`.
|
||||
#[serde(default, rename = "notifications")]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub notifications: Notifications,
|
||||
|
||||
/// Notification method to use for terminal notifications.
|
||||
/// Defaults to `auto`.
|
||||
#[serde(default, rename = "notification_method")]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub method: NotificationMethod,
|
||||
|
||||
/// Controls whether TUI notifications are delivered only when the terminal is unfocused or
|
||||
/// regardless of focus. Defaults to `unfocused`.
|
||||
#[serde(default, rename = "notification_condition")]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub condition: NotificationCondition,
|
||||
}
|
||||
|
||||
@@ -620,6 +635,7 @@ pub struct ModelAvailabilityNuxConfig {
|
||||
pub const DEFAULT_TERMINAL_RESIZE_REFLOW_FALLBACK_MAX_ROWS: usize = 1_000;
|
||||
|
||||
/// Collection of settings that are specific to the TUI.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct Tui {
|
||||
@@ -655,6 +671,7 @@ pub struct Tui {
|
||||
/// Using alternate screen provides a cleaner fullscreen experience but prevents
|
||||
/// scrollback in terminal multiplexers like Zellij that follow the xterm spec.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub alternate_screen: AltScreenMode,
|
||||
|
||||
/// Ordered list of status line item identifiers.
|
||||
@@ -687,6 +704,7 @@ pub struct Tui {
|
||||
|
||||
/// Preferred layout for resume/fork session picker results.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub session_picker_view: Option<SessionPickerViewMode>,
|
||||
|
||||
/// Keybinding overrides for the TUI.
|
||||
@@ -773,6 +791,7 @@ pub struct PluginConfig {
|
||||
///
|
||||
/// This intentionally excludes transport settings: plugin manifests own how the
|
||||
/// MCP server is launched, while user config owns enablement and tool policy.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct PluginMcpServerConfig {
|
||||
@@ -782,6 +801,7 @@ pub struct PluginMcpServerConfig {
|
||||
|
||||
/// Approval mode for tools in this server unless a tool override exists.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub default_tools_approval_mode: Option<AppToolApproval>,
|
||||
|
||||
/// Explicit allow-list of tools exposed from this server.
|
||||
@@ -809,6 +829,7 @@ impl Default for PluginMcpServerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct MarketplaceConfig {
|
||||
@@ -820,6 +841,7 @@ pub struct MarketplaceConfig {
|
||||
pub last_revision: Option<String>,
|
||||
/// Source kind used to install this marketplace.
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub source_type: Option<MarketplaceSourceType>,
|
||||
/// Source location used when the marketplace was added.
|
||||
#[serde(default)]
|
||||
@@ -865,9 +887,12 @@ impl From<SandboxWorkspaceWrite> for codex_app_server_protocol::SandboxSettings
|
||||
|
||||
/// Policy for building the `env` when spawning a process via either the
|
||||
/// `shell` or `local_shell` tool.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct ShellEnvironmentPolicyToml {
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub inherit: Option<ShellEnvironmentPolicyInherit>,
|
||||
|
||||
pub ignore_default_excludes: Option<bool>,
|
||||
|
||||
@@ -336,10 +336,20 @@
|
||||
"$ref": "#/definitions/AnalyticsConfigToml"
|
||||
},
|
||||
"approval_policy": {
|
||||
"$ref": "#/definitions/AskForApproval"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AskForApproval"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"approvals_reviewer": {
|
||||
"$ref": "#/definitions/ApprovalsReviewer"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ApprovalsReviewer"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"chatgpt_base_url": {
|
||||
"type": "string"
|
||||
@@ -646,25 +656,55 @@
|
||||
"type": "string"
|
||||
},
|
||||
"model_reasoning_effort": {
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"model_reasoning_summary": {
|
||||
"$ref": "#/definitions/ReasoningSummary"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReasoningSummary"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"model_verbosity": {
|
||||
"$ref": "#/definitions/Verbosity"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Verbosity"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"oss_provider": {
|
||||
"type": "string"
|
||||
},
|
||||
"personality": {
|
||||
"$ref": "#/definitions/Personality"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Personality"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"plan_mode_reasoning_effort": {
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"sandbox_mode": {
|
||||
"$ref": "#/definitions/SandboxMode"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/SandboxMode"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"service_tier": {
|
||||
"allOf": [
|
||||
@@ -672,6 +712,7 @@
|
||||
"$ref": "#/definitions/ServiceTier"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optional explicit service tier preference for new turns (`fast` or `flex`)."
|
||||
},
|
||||
"tools": {
|
||||
@@ -690,7 +731,12 @@
|
||||
"description": "TUI settings scoped to this profile."
|
||||
},
|
||||
"web_search": {
|
||||
"$ref": "#/definitions/WebSearchMode"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/WebSearchMode"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"windows": {
|
||||
"allOf": [
|
||||
@@ -2070,16 +2116,36 @@
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"transport": {
|
||||
"$ref": "#/definitions/RealtimeTransport"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/RealtimeTransport"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/RealtimeWsMode"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/RealtimeWsMode"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"version": {
|
||||
"$ref": "#/definitions/RealtimeConversationVersion"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/RealtimeConversationVersion"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"voice": {
|
||||
"$ref": "#/definitions/RealtimeVoice"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/RealtimeVoice"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
@@ -2252,7 +2318,12 @@
|
||||
"type": "array"
|
||||
},
|
||||
"inherit": {
|
||||
"$ref": "#/definitions/ShellEnvironmentPolicyInherit"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ShellEnvironmentPolicyInherit"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"set": {
|
||||
"additionalProperties": {
|
||||
@@ -3723,7 +3794,12 @@
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"sandbox": {
|
||||
"$ref": "#/definitions/WindowsSandboxModeToml"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/WindowsSandboxModeToml"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"sandbox_private_desktop": {
|
||||
"description": "Defaults to `true`. Set to `false` to launch the final sandboxed child process on `Winsta0\\\\Default` instead of a private desktop.",
|
||||
@@ -3774,6 +3850,7 @@
|
||||
"$ref": "#/definitions/AskForApproval"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Default approval policy for executing commands."
|
||||
},
|
||||
"approvals_reviewer": {
|
||||
@@ -3782,6 +3859,7 @@
|
||||
"$ref": "#/definitions/ApprovalsReviewer"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Configures who approval requests are routed to for review once they have been escalated. This does not disable separate safety checks such as ARC."
|
||||
},
|
||||
"apps": {
|
||||
@@ -3896,6 +3974,7 @@
|
||||
"$ref": "#/definitions/ThreadStoreToml"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Experimental / do not use. Selects the thread store implementation."
|
||||
},
|
||||
"experimental_thread_store_endpoint": {
|
||||
@@ -4179,6 +4258,7 @@
|
||||
"$ref": "#/definitions/UriBasedFileOpener"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optional URI-based file opener. If set, citations to files in the model output will be hyperlinked using the specified URI scheme."
|
||||
},
|
||||
"forced_chatgpt_workspace_id": {
|
||||
@@ -4339,10 +4419,20 @@
|
||||
"type": "object"
|
||||
},
|
||||
"model_reasoning_effort": {
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"model_reasoning_summary": {
|
||||
"$ref": "#/definitions/ReasoningSummary"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReasoningSummary"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"model_supports_reasoning_summaries": {
|
||||
"description": "Override to force-enable reasoning summaries for the configured model.",
|
||||
@@ -4354,6 +4444,7 @@
|
||||
"$ref": "#/definitions/Verbosity"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optional verbosity control for GPT-5 models (Responses API `text.verbosity`)."
|
||||
},
|
||||
"notice": {
|
||||
@@ -4403,10 +4494,16 @@
|
||||
"$ref": "#/definitions/Personality"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optionally specify a personality for the model"
|
||||
},
|
||||
"plan_mode_reasoning_effort": {
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReasoningEffort"
|
||||
}
|
||||
],
|
||||
"default": null
|
||||
},
|
||||
"plugins": {
|
||||
"additionalProperties": {
|
||||
@@ -4476,6 +4573,7 @@
|
||||
"$ref": "#/definitions/SandboxMode"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Sandbox mode to use."
|
||||
},
|
||||
"sandbox_workspace_write": {
|
||||
@@ -4492,6 +4590,7 @@
|
||||
"$ref": "#/definitions/ServiceTier"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optional explicit service tier preference for new turns (`fast` or `flex`)."
|
||||
},
|
||||
"shell_environment_policy": {
|
||||
@@ -4569,6 +4668,7 @@
|
||||
"$ref": "#/definitions/WebSearchMode"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Controls the web search tool mode: disabled, cached, or live."
|
||||
},
|
||||
"windows": {
|
||||
|
||||
@@ -150,7 +150,7 @@ context_size = "galactic"
|
||||
|
||||
// The invalid enum leaves are removed before ConfigToml is produced, but
|
||||
// unrelated valid settings still survive in the effective config.
|
||||
let (effective_config, _config_toml, enum_warnings): (TomlValue, ConfigToml, Vec<String>) =
|
||||
let (effective_config, _config_toml, enum_warnings) =
|
||||
layers.deserialize_effective_config_with_warnings()?;
|
||||
let expected_config = toml::from_str::<TomlValue>(
|
||||
r#"
|
||||
@@ -165,8 +165,8 @@ theme = "loudly"
|
||||
.expect("expected config should parse");
|
||||
let expected_startup_warnings = vec![
|
||||
"Ignoring invalid config value at sandbox_mode: \"make-it-so\"".to_string(),
|
||||
"Ignoring invalid config value at tools.web_search.context_size: \"galactic\"".to_string(),
|
||||
"Ignoring invalid config value at tui.notification_method: \"loudly\"".to_string(),
|
||||
"Ignoring invalid config value at tools.web_search.context_size: \"galactic\"".to_string(),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
@@ -203,7 +203,7 @@ async fn invalid_higher_precedence_enum_falls_back_to_lower_layer() -> anyhow::R
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (effective_config, config_toml, enum_warnings): (TomlValue, ConfigToml, Vec<String>) =
|
||||
let (effective_config, config_toml, enum_warnings) =
|
||||
layers.deserialize_effective_config_with_warnings()?;
|
||||
|
||||
assert_eq!(
|
||||
@@ -277,7 +277,7 @@ theme = "sometimes"
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (effective_config, _config_toml, enum_warnings): (TomlValue, ConfigToml, Vec<String>) =
|
||||
let (effective_config, _config_toml, enum_warnings) =
|
||||
layers.deserialize_effective_config_with_warnings()?;
|
||||
let expected = (
|
||||
toml::from_str::<TomlValue>(
|
||||
@@ -317,7 +317,7 @@ sandbox_mode = "hold-my-coffee"
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (effective_config, _config_toml, enum_warnings): (TomlValue, ConfigToml, Vec<String>) =
|
||||
let (effective_config, _config_toml, enum_warnings) =
|
||||
layers.deserialize_effective_config_with_warnings()?;
|
||||
let expected = (
|
||||
toml::from_str::<TomlValue>(
|
||||
|
||||
@@ -976,11 +976,11 @@ impl ConfigBuilder {
|
||||
// respective config file, so we should be safe to deserialize without
|
||||
// AbsolutePathBufGuard here.
|
||||
//
|
||||
// Invalid enum-valued settings are dropped during deserialization and
|
||||
// returned as warnings. This keeps ConfigToml strict and prevents raw
|
||||
// invalid values from leaking into downstream config consumers.
|
||||
// Invalid enum-valued settings default at the typed field boundary and
|
||||
// are removed from the merged TOML view when the best-effort scan can
|
||||
// identify the offending leaf.
|
||||
let (_merged_toml, config_toml, enum_warnings) = match config_layer_stack
|
||||
.deserialize_effective_config_with_warnings::<ConfigToml>()
|
||||
.deserialize_effective_config_with_warnings()
|
||||
{
|
||||
Ok(result) => result,
|
||||
Err(err) => {
|
||||
@@ -1309,7 +1309,7 @@ pub async fn load_config_as_toml_with_cli_and_loader_overrides(
|
||||
// not surfaced here. The full ConfigBuilder path is responsible for
|
||||
// attaching them to startup warnings.
|
||||
let (_merged_toml, cfg, _enum_warnings) = config_layer_stack
|
||||
.deserialize_effective_config_with_warnings::<ConfigToml>()
|
||||
.deserialize_effective_config_with_warnings()
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
|
||||
.map_err(|e| {
|
||||
tracing::error!("Failed to deserialize overridden config: {e}");
|
||||
|
||||
Reference in New Issue
Block a user