mirror of
https://github.com/openai/codex.git
synced 2026-10-29 19:08:43 +00:00
## What changed - Use the managed configuration loader in CLI, exec, TUI, and app-server configuration flows so `requirements.toml` can select a config server. - Sign in to the config server when needed during interactive TUI startup and CLI login, reload configuration after CLI sign-in, and clear config-server credentials on CLI logout. - Preserve the app-server's config-server settings and refresh worker across OpenAI login and logout. - Require config-server settings to be applied when loading CLI and doctor configuration. ## Testing Add app-server integration tests using a local HTTPS config server to verify managed provider and instruction settings at startup, preservation across API-key login and logout, and cache reuse after restart and thread resume. GitOrigin-RevId: 27ee81f7943d2290a5c3fcc0ac556579ec63f8b4
81 lines
2.9 KiB
Rust
81 lines
2.9 KiB
Rust
use anyhow::Context;
|
|
use anyhow::Result;
|
|
use codex_app_server::in_process::EmbeddedNetworkPolicy;
|
|
use codex_cloud_config::managed_config_bundle_loader_for_storage;
|
|
use codex_config::CloudConfigBundleLoader;
|
|
use codex_config::ConfigLoadOptions;
|
|
use codex_core::config::Config;
|
|
use codex_core::config::ConfigBuilder;
|
|
use codex_core::config::ConfigOverrides;
|
|
use codex_core::config::LoaderOverrides;
|
|
use codex_core::config::bootstrap_auth_config;
|
|
use codex_core::config::find_codex_home;
|
|
use codex_core::config::load_config_toml_with_layer_stack;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use codex_utils_cli::CliConfigOverrides;
|
|
|
|
pub async fn load_config(
|
|
config_overrides: &CliConfigOverrides,
|
|
loader_overrides: LoaderOverrides,
|
|
) -> Result<Config> {
|
|
let mut config = config_builder(
|
|
config_overrides,
|
|
loader_overrides,
|
|
ConfigOverrides::default(),
|
|
)
|
|
.await?
|
|
.build()
|
|
.await
|
|
.context("failed to load configuration")?;
|
|
config.config_layer_stack.ensure_config_server_applied()?;
|
|
EmbeddedNetworkPolicy::default().activate(&mut config);
|
|
Ok(config)
|
|
}
|
|
|
|
pub async fn config_builder(
|
|
config_overrides: &CliConfigOverrides,
|
|
loader_overrides: LoaderOverrides,
|
|
harness_overrides: ConfigOverrides,
|
|
) -> Result<ConfigBuilder> {
|
|
let network_policy = EmbeddedNetworkPolicy::load(&loader_overrides).await;
|
|
let cli_overrides = config_overrides
|
|
.parse_overrides()
|
|
.map_err(anyhow::Error::msg)?;
|
|
let codex_home = find_codex_home().context("failed to resolve CODEX_HOME")?;
|
|
let cwd = match harness_overrides.cwd.as_deref() {
|
|
Some(cwd) => AbsolutePathBuf::relative_to_current_dir(cwd),
|
|
None => AbsolutePathBuf::current_dir(),
|
|
}
|
|
.context("failed to resolve current directory")?;
|
|
let bootstrap_config = load_config_toml_with_layer_stack(
|
|
codex_home.as_path(),
|
|
Some(&cwd),
|
|
cli_overrides.clone(),
|
|
ConfigLoadOptions {
|
|
loader_overrides: loader_overrides.clone(),
|
|
strict_config: false,
|
|
cloud_config_bundle: CloudConfigBundleLoader::default(),
|
|
},
|
|
)
|
|
.await
|
|
.context("failed to load bootstrap configuration")?;
|
|
let cloud_config_bundle = managed_config_bundle_loader_for_storage(
|
|
network_policy.bind_bootstrap_auth(
|
|
bootstrap_auth_config(codex_home.as_path(), &bootstrap_config)
|
|
.context("failed to resolve cloud configuration authentication")?,
|
|
),
|
|
bootstrap_config.config_layer_stack.requirements_toml(),
|
|
/*enable_codex_api_key_env*/ false,
|
|
)
|
|
.await
|
|
.context("failed to initialize cloud configuration authentication")?;
|
|
|
|
Ok(ConfigBuilder::default()
|
|
.codex_home(codex_home.to_path_buf())
|
|
.cli_overrides(cli_overrides)
|
|
.loader_overrides(loader_overrides)
|
|
.harness_overrides(harness_overrides)
|
|
.cloud_config_bundle(cloud_config_bundle)
|
|
.fallback_cwd(Some(cwd.to_path_buf())))
|
|
}
|