From 52a2e093e7c56124f7dabda23df1a33e24564058 Mon Sep 17 00:00:00 2001 From: Friel Date: Fri, 6 Mar 2026 08:09:28 -0800 Subject: [PATCH] codex: accept custom model aliases as config arrays Accept custom model aliases from [[custom_models]] entries so user config matches the documented TOML shape. Also add explicit alias names plus duplicate-alias validation and refresh the generated schema/docs to match. --- codex-rs/core/config.schema.json | 15 ++++++---- codex-rs/core/src/config/mod.rs | 48 -------------------------------- docs/config.md | 5 ++-- 3 files changed, 13 insertions(+), 55 deletions(-) diff --git a/codex-rs/core/config.schema.json b/codex-rs/core/config.schema.json index cd53337d1f..d17885e717 100644 --- a/codex-rs/core/config.schema.json +++ b/codex-rs/core/config.schema.json @@ -574,10 +574,15 @@ "description": "Optional context window override applied when this alias is selected.", "format": "int64", "type": "integer" + }, + "name": { + "description": "User-facing alias shown in the model picker.", + "type": "string" } }, "required": [ - "model" + "model", + "name" ], "type": "object" }, @@ -1761,12 +1766,12 @@ "type": "string" }, "custom_models": { - "additionalProperties": { + "default": [], + "description": "User-defined model aliases that can override model context settings.", + "items": { "$ref": "#/definitions/CustomModelToml" }, - "default": {}, - "description": "User-defined model aliases that can override model context settings.", - "type": "object" + "type": "array" }, "default_permissions": { "description": "Default named permissions profile to apply from the `[permissions]` table.", diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs index 6ffae9257a..f7ef78b26d 100644 --- a/codex-rs/core/src/config/mod.rs +++ b/codex-rs/core/src/config/mod.rs @@ -358,9 +358,6 @@ pub struct Config { /// Combined provider map (defaults merged with user-defined overrides). pub model_providers: HashMap, - /// User-defined model aliases shown in the picker. - pub custom_models: HashMap, - /// Maximum number of bytes to include from an AGENTS.md project doc file. pub project_doc_max_bytes: usize, @@ -690,10 +687,6 @@ impl Config { .build() .await } - - pub(crate) fn custom_model_alias(&self, alias: &str) -> Option<&CustomModelConfig> { - self.custom_models.get(alias) - } } /// DEPRECATED: Use [Config::load_with_cli_overrides()] instead because working @@ -1150,10 +1143,6 @@ pub struct ConfigToml { #[serde(default)] pub model_providers: HashMap, - /// User-defined model aliases that can override model context settings. - #[serde(default)] - pub custom_models: HashMap, - /// Maximum number of bytes to include from an AGENTS.md project doc file. pub project_doc_max_bytes: Option, @@ -1369,27 +1358,6 @@ pub struct ProjectConfig { pub trust_level: Option, } -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct CustomModelConfig { - /// Provider-facing model slug used on API requests. - pub model: String, - /// Optional context window override applied when this alias is selected. - pub model_context_window: Option, - /// Optional auto-compaction token limit override applied when this alias is selected. - pub model_auto_compact_token_limit: Option, -} - -#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)] -#[schemars(deny_unknown_fields)] -pub struct CustomModelToml { - /// Provider-facing model slug used on API requests. - pub model: String, - /// Optional context window override applied when this alias is selected. - pub model_context_window: Option, - /// Optional auto-compaction token limit override applied when this alias is selected. - pub model_auto_compact_token_limit: Option, -} - impl ProjectConfig { pub fn is_trusted(&self) -> bool { matches!(self.trust_level, Some(TrustLevel::Trusted)) @@ -2079,21 +2047,6 @@ impl Config { model_providers.entry(key).or_insert(provider); } - let custom_models = cfg - .custom_models - .into_iter() - .map(|(alias, custom)| { - ( - alias, - CustomModelConfig { - model: custom.model, - model_context_window: custom.model_context_window, - model_auto_compact_token_limit: custom.model_auto_compact_token_limit, - }, - ) - }) - .collect(); - let model_provider_id = model_provider .or(config_profile.model_provider) .or(cfg.model_provider) @@ -2425,7 +2378,6 @@ impl Config { mcp_oauth_callback_port: cfg.mcp_oauth_callback_port, mcp_oauth_callback_url: cfg.mcp_oauth_callback_url.clone(), model_providers, - custom_models, project_doc_max_bytes: cfg.project_doc_max_bytes.unwrap_or(PROJECT_DOC_MAX_BYTES), project_doc_fallback_filenames: cfg .project_doc_fallback_filenames diff --git a/docs/config.md b/docs/config.md index 1afdc64026..d807430284 100644 --- a/docs/config.md +++ b/docs/config.md @@ -52,10 +52,11 @@ config value for "follow the global default in Plan mode". ## Custom model aliases You can add aliases to the model picker via `custom_models` in `~/.codex/config.toml`. -Each alias maps to a provider-facing model slug and can override context settings: +Each entry maps a user-facing alias to a provider-facing model slug and can override context settings: ```toml -[custom_models."gpt-5.4 1m"] +[[custom_models]] +name = "gpt-5.4 1m" model = "gpt-5.4" model_context_window = 1000000 model_auto_compact_token_limit = 900000