From 74e67743e4272fbed454a2c8d3123df64cda2746 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 28 Aug 2026 08:38:53 +0000 Subject: [PATCH 1/2] ci: build + release codex CLI binaries for the desktop fork --- .github/workflows/codex-binaries.yml | 69 ++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/codex-binaries.yml diff --git a/.github/workflows/codex-binaries.yml b/.github/workflows/codex-binaries.yml new file mode 100644 index 000000000000..39ceb6faa8f8 --- /dev/null +++ b/.github/workflows/codex-binaries.yml @@ -0,0 +1,69 @@ +name: codex-binaries + +# Builds the codex CLI (incl. app-server) from this fork and attaches the +# binaries to a GitHub release. CodexDesktop-Rebuild bundles these via +# CODEX_VENDOR_BIN / vendor/codex// so the desktop app ships our +# profile-based model selector. + +on: + workflow_dispatch: + push: + branches: [main] + paths: + - "codex-rs/**" + - ".github/workflows/codex-binaries.yml" + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - { os: macos-14, triple: aarch64-apple-darwin } + - { os: macos-13, triple: x86_64-apple-darwin } + - { os: windows-latest, triple: x86_64-pc-windows-msvc } + - { os: ubuntu-latest, triple: x86_64-unknown-linux-gnu } + runs-on: ${{ matrix.os }} + defaults: + run: + working-directory: codex-rs + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: "1.95.0" + - uses: Swatinem/rust-cache@v2 + with: + workspaces: codex-rs + - name: Build codex + run: cargo build --release -p codex-cli + - name: Stage artifact (unix) + if: runner.os != 'Windows' + run: cp target/release/codex codex-${{ matrix.triple }} + - name: Stage artifact (windows) + if: runner.os == 'Windows' + shell: pwsh + run: Copy-Item target/release/codex.exe codex-${{ matrix.triple }} + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: codex-${{ matrix.triple }} + path: codex-rs/codex-${{ matrix.triple }} + if-no-files-found: error + + release: + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@v4 + with: + pattern: codex-* + merge-multiple: true + - name: Upload to rolling release + uses: softprops/action-gh-release@v2 + with: + tag_name: fork-binaries + name: fork binaries (rolling) + files: codex-* From 342dcd37eede04ab001702d165f98cfe9779c149 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 28 Aug 2026 08:49:18 +0000 Subject: [PATCH 2/2] app-server: surface config profiles in model/list as picker entries Profiles ([profiles.] in config.toml or .config.toml in CODEX_HOME) now appear as model/list entries so desktop/app clients get a working model selector for custom providers without hand-writing a model catalog. - profiles.rs: discovery (legacy table + profile files) and expansion - models.rs: synthesize picker presets from profiles - thread/start: expand a selected profile into model + model_provider (+ model_reasoning_effort via request overrides) - turn/settings/update, thread/settings/update: expand model/effort; reject cross-provider profiles with guidance since providers are fixed per thread --- codex-rs/app-server/src/lib.rs | 1 + codex-rs/app-server/src/models.rs | 55 ++++++- codex-rs/app-server/src/profiles.rs | 145 ++++++++++++++++++ .../request_processors/catalog_processor.rs | 3 + .../request_processors/thread_processor.rs | 8 + .../src/request_processors/turn_processor.rs | 28 +++- 6 files changed, 234 insertions(+), 6 deletions(-) create mode 100644 codex-rs/app-server/src/profiles.rs diff --git a/codex-rs/app-server/src/lib.rs b/codex-rs/app-server/src/lib.rs index fcf9ecff1b59..e3c3902babf9 100644 --- a/codex-rs/app-server/src/lib.rs +++ b/codex-rs/app-server/src/lib.rs @@ -120,6 +120,7 @@ mod models; mod models_refresh_worker; mod otel_reloader; mod outgoing_message; +mod profiles; mod realtime_event_handling; mod realtime_history; mod request_processors; diff --git a/codex-rs/app-server/src/models.rs b/codex-rs/app-server/src/models.rs index 1063e64c339a..5ac107026442 100644 --- a/codex-rs/app-server/src/models.rs +++ b/codex-rs/app-server/src/models.rs @@ -5,23 +5,74 @@ use codex_app_server_protocol::ModelServiceTier; use codex_app_server_protocol::ModelUpgradeInfo; use codex_app_server_protocol::ReasoningEffortOption; use codex_core::ThreadManager; +use codex_core::config::Config; use codex_http_client::HttpClientFactory; use codex_models_manager::manager::RefreshStrategy; use codex_protocol::openai_models::ModelPreset; +use codex_protocol::openai_models::ReasoningEffort; use codex_protocol::openai_models::ReasoningEffortPreset; +use codex_protocol::openai_models::default_input_modalities; + +use crate::profiles::SelectableProfile; +use crate::profiles::selectable_profiles; pub async fn supported_models( thread_manager: Arc, include_hidden: bool, http_client_factory: HttpClientFactory, + config: &Config, ) -> Vec { - thread_manager + let mut models: Vec = thread_manager .list_models(RefreshStrategy::OnlineIfUncached, http_client_factory) .await .into_iter() .filter(|preset| include_hidden || preset.show_in_picker) .map(model_from_preset) - .collect() + .collect(); + + // Config-defined profiles join the picker so clients can switch routes + // (model + provider) without hand-writing a model catalog file. + for profile in selectable_profiles(config) { + if models.iter().any(|model| model.model == profile.name) { + continue; + } + models.push(model_from_preset(preset_from_profile(&profile))); + } + models +} + +fn preset_from_profile(profile: &SelectableProfile) -> ModelPreset { + let effort = profile + .reasoning_effort + .clone() + .unwrap_or(ReasoningEffort::Medium); + let description = match &profile.model_provider { + Some(provider) => format!("{} ยท {provider}", profile.model), + None => profile.model.clone(), + }; + ModelPreset { + id: profile.name.clone(), + model: profile.name.clone(), + display_name: profile.name.clone(), + description, + model_specialty: None, + default_reasoning_effort: effort.clone(), + supported_reasoning_efforts: vec![ReasoningEffortPreset { + effort, + description: String::new(), + }], + supports_personality: false, + additional_speed_tiers: Vec::new(), + service_tiers: Vec::new(), + default_service_tier: None, + is_default: false, + upgrade: None, + show_in_picker: true, + multi_agent_version: None, + availability_nux: None, + supported_in_api: true, + input_modalities: default_input_modalities(), + } } fn model_from_preset(preset: ModelPreset) -> Model { diff --git a/codex-rs/app-server/src/profiles.rs b/codex-rs/app-server/src/profiles.rs new file mode 100644 index 000000000000..f2b97292200b --- /dev/null +++ b/codex-rs/app-server/src/profiles.rs @@ -0,0 +1,145 @@ +//! Config-defined profile discovery for the model picker. +//! +//! Profiles (`[profiles.]` in `config.toml` or `.config.toml` +//! files in CODEX_HOME) describe a model + provider route. We surface them as +//! `model/list` entries and expand the profile name back into its real +//! model/provider pair when a thread starts with one selected. + +use std::collections::HashMap; + +use codex_core::config::Config; +use codex_protocol::openai_models::ReasoningEffort; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub(crate) struct SelectableProfile { + pub name: String, + pub model: String, + pub model_provider: Option, + pub reasoning_effort: Option, +} + +pub(crate) fn selectable_profiles(config: &Config) -> Vec { + let mut profiles = legacy_config_profiles(config); + for profile in file_config_profiles(config) { + if !profiles.iter().any(|existing| existing.name == profile.name) { + profiles.push(profile); + } + } + profiles.retain(|profile| !profile.name.is_empty() && !profile.model.is_empty()); + profiles.sort_by(|a, b| a.name.cmp(&b.name)); + profiles +} + +pub(crate) fn find_profile<'a>( + profiles: &'a [SelectableProfile], + name: &str, +) -> Option<&'a SelectableProfile> { + profiles.iter().find(|profile| profile.name == name) +} + +/// Resolve a picker selection at thread start: a `model` value matching a +/// profile name expands into the profile's real model, provider, and effort. +pub(crate) fn expand_profile_for_new_thread( + config: &Config, + model: Option, + model_provider: Option, + mut overrides: Option>, +) -> ( + Option, + Option, + Option>, +) { + let Some(requested) = model.as_deref() else { + return (model, model_provider, overrides); + }; + let profiles = selectable_profiles(config); + let Some(profile) = find_profile(&profiles, requested) else { + return (model, model_provider, overrides); + }; + + let model_provider = model_provider.or_else(|| profile.model_provider.clone()); + if let Some(effort) = &profile.reasoning_effort { + overrides + .get_or_insert_with(HashMap::new) + .entry("model_reasoning_effort".to_string()) + .or_insert_with(|| serde_json::Value::String(effort.as_str().to_string())); + } + (Some(profile.model.clone()), model_provider, overrides) +} + +/// Resolve a picker selection on a live thread. Providers cannot change +/// mid-thread, so a profile routing elsewhere is rejected with guidance. +pub(crate) fn expand_profile_for_active_thread( + config: &Config, + active_provider: &str, + model: Option, + effort: Option, +) -> Result<(Option, Option), String> { + let Some(requested) = model.as_deref() else { + return Ok((model, effort)); + }; + let profiles = selectable_profiles(config); + let Some(profile) = find_profile(&profiles, requested) else { + return Ok((model, effort)); + }; + + if let Some(provider) = &profile.model_provider + && provider != active_provider + { + return Err(format!( + "profile `{}` routes to provider `{provider}` but this thread uses `{active_provider}`; start a new thread to switch providers", + profile.name + )); + } + Ok(( + Some(profile.model.clone()), + effort.or(profile.reasoning_effort.clone()), + )) +} + +fn legacy_config_profiles(config: &Config) -> Vec { + let effective = config.config_layer_stack.effective_config(); + let Some(profiles) = effective.get("profiles").and_then(|value| value.as_table()) else { + return Vec::new(); + }; + profiles + .iter() + .filter_map(|(name, value)| profile_from_toml_table(name.clone(), value.as_table()?)) + .collect() +} + +fn file_config_profiles(config: &Config) -> Vec { + let Ok(entries) = std::fs::read_dir(config.codex_home.as_path()) else { + return Vec::new(); + }; + entries + .filter_map(|entry| { + let path = entry.ok()?.path(); + let file_name = path.file_name()?.to_str()?; + let name = file_name.strip_suffix(".config.toml")?; + let contents = std::fs::read_to_string(&path).ok()?; + let parsed = contents.parse::().ok()?; + profile_from_toml_table(name.to_string(), parsed.as_table()?) + }) + .collect() +} + +fn profile_from_toml_table( + name: String, + table: &toml::map::Map, +) -> Option { + let model = table.get("model")?.as_str()?.to_string(); + let model_provider = table + .get("model_provider") + .and_then(|value| value.as_str()) + .map(str::to_string); + let reasoning_effort = table + .get("model_reasoning_effort") + .and_then(|value| value.clone().try_into::().ok()); + Some(SelectableProfile { + name, + model, + model_provider, + reasoning_effort, + }) +} diff --git a/codex-rs/app-server/src/request_processors/catalog_processor.rs b/codex-rs/app-server/src/request_processors/catalog_processor.rs index 9c7bd4e80690..95037ed3a1f0 100644 --- a/codex-rs/app-server/src/request_processors/catalog_processor.rs +++ b/codex-rs/app-server/src/request_processors/catalog_processor.rs @@ -172,6 +172,7 @@ impl CatalogRequestProcessor { Self::list_models( self.thread_manager.clone(), self.config.http_client_factory(), + &self.config, params, ) .await @@ -242,6 +243,7 @@ impl CatalogRequestProcessor { async fn list_models( thread_manager: Arc, http_client_factory: codex_http_client::HttpClientFactory, + config: &Config, params: ModelListParams, ) -> Result { let ModelListParams { @@ -253,6 +255,7 @@ impl CatalogRequestProcessor { thread_manager, include_hidden.unwrap_or(false), http_client_factory, + config, ) .await; let total = models.len(); diff --git a/codex-rs/app-server/src/request_processors/thread_processor.rs b/codex-rs/app-server/src/request_processors/thread_processor.rs index 0803fb1445ef..b35a28688e82 100644 --- a/codex-rs/app-server/src/request_processors/thread_processor.rs +++ b/codex-rs/app-server/src/request_processors/thread_processor.rs @@ -1141,6 +1141,14 @@ impl ThreadRequestProcessor { project_id, environments, } = params; + // A picker selection naming a config-defined profile arrives as + // `model`; expand it into the profile's real model/provider/effort. + let (model, model_provider, config) = crate::profiles::expand_profile_for_new_thread( + &self.config, + model, + model_provider, + config, + ); if matches!( history_mode, Some(codex_app_server_protocol::ThreadHistoryMode::Paginated) diff --git a/codex-rs/app-server/src/request_processors/turn_processor.rs b/codex-rs/app-server/src/request_processors/turn_processor.rs index 84047d2d2fa9..0e284d55b5fe 100644 --- a/codex-rs/app-server/src/request_processors/turn_processor.rs +++ b/codex-rs/app-server/src/request_processors/turn_processor.rs @@ -209,6 +209,16 @@ impl TurnRequestProcessor { let (_, thread) = self.load_thread(¶ms.thread_id).await?; self.ensure_direct_input_allowed(request_id, thread.as_ref()) .await?; + // Expand a profile selection into its real model; providers are fixed + // per thread, so a cross-provider profile is rejected with guidance. + let active_provider = thread.config().await.model_provider_id.clone(); + let (model, effort) = crate::profiles::expand_profile_for_active_thread( + &self.config, + &active_provider, + params.model, + params.effort, + ) + .map_err(invalid_request)?; let (reply, outcome) = oneshot::channel(); self.submit_core_op( request_id, @@ -216,9 +226,9 @@ impl TurnRequestProcessor { Op::TurnSettings { turn_id: params.turn_id, update: TurnSettingsUpdate { - model: params.model, + model, // Match thread/settings/update: public null does not clear effort. - effort: params.effort.map(Some), + effort: effort.map(Some), summary: params.summary, service_tier: params.service_tier, }, @@ -909,6 +919,16 @@ impl TurnRequestProcessor { /*environment_selections*/ None, ) .await; + // Expand a profile selection into its real model; providers are fixed + // per thread, so a cross-provider profile is rejected with guidance. + let active_provider = thread.config().await.model_provider_id.clone(); + let (model, effort) = crate::profiles::expand_profile_for_active_thread( + &self.config, + &active_provider, + params.model, + params.effort, + ) + .map_err(invalid_request)?; let thread_settings = self .build_thread_settings_overrides( thread.as_ref(), @@ -919,9 +939,9 @@ impl TurnRequestProcessor { approvals_reviewer: params.approvals_reviewer, sandbox_policy: params.sandbox_policy, permissions: params.permissions, - model: params.model, + model, service_tier: params.service_tier, - effort: params.effort, + effort, summary: params.summary, collaboration_mode: params.collaboration_mode, personality: params.personality,