Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/codex-binaries.yml
Original file line number Diff line number Diff line change
@@ -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/<triple>/ 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-*
1 change: 1 addition & 0 deletions codex-rs/app-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
55 changes: 53 additions & 2 deletions codex-rs/app-server/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadManager>,
include_hidden: bool,
http_client_factory: HttpClientFactory,
config: &Config,
) -> Vec<Model> {
thread_manager
let mut models: Vec<Model> = 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 {
Expand Down
145 changes: 145 additions & 0 deletions codex-rs/app-server/src/profiles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
//! Config-defined profile discovery for the model picker.
//!
//! Profiles (`[profiles.<name>]` in `config.toml` or `<name>.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<String>,
pub reasoning_effort: Option<ReasoningEffort>,
}

pub(crate) fn selectable_profiles(config: &Config) -> Vec<SelectableProfile> {
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<String>,
model_provider: Option<String>,
mut overrides: Option<HashMap<String, serde_json::Value>>,
) -> (
Option<String>,
Option<String>,
Option<HashMap<String, serde_json::Value>>,
) {
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<String>,
effort: Option<ReasoningEffort>,
) -> Result<(Option<String>, Option<ReasoningEffort>), 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<SelectableProfile> {
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<SelectableProfile> {
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::<codex_config::TomlValue>().ok()?;
profile_from_toml_table(name.to_string(), parsed.as_table()?)
})
.collect()
}

fn profile_from_toml_table(
name: String,
table: &toml::map::Map<String, codex_config::TomlValue>,
) -> Option<SelectableProfile> {
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::<ReasoningEffort>().ok());
Some(SelectableProfile {
name,
model,
model_provider,
reasoning_effort,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl CatalogRequestProcessor {
Self::list_models(
self.thread_manager.clone(),
self.config.http_client_factory(),
&self.config,
params,
)
.await
Expand Down Expand Up @@ -242,6 +243,7 @@ impl CatalogRequestProcessor {
async fn list_models(
thread_manager: Arc<ThreadManager>,
http_client_factory: codex_http_client::HttpClientFactory,
config: &Config,
params: ModelListParams,
) -> Result<ModelListResponse, JSONRPCErrorError> {
let ModelListParams {
Expand All @@ -253,6 +255,7 @@ impl CatalogRequestProcessor {
thread_manager,
include_hidden.unwrap_or(false),
http_client_factory,
config,
)
.await;
let total = models.len();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 24 additions & 4 deletions codex-rs/app-server/src/request_processors/turn_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,26 @@ impl TurnRequestProcessor {
let (_, thread) = self.load_thread(&params.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,
&thread,
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,
},
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand Down
Loading