|
1 | 1 | use anyhow::{Context, Result}; |
2 | | -use codex_core::config::{ |
3 | | - find_codex_home, load_config_as_toml_with_cli_overrides, Config, ConfigOverrides, ConfigToml, |
4 | | -}; |
| 2 | +use codex_core::config::{find_codex_home, Config, ConfigOverrides, ConfigToml}; |
5 | 3 | use codex_core::protocol::{EventMsg, InputItem}; |
6 | 4 | use codex_core::{AuthManager, ConversationManager}; |
7 | 5 | // use of SandboxMode is handled within core::config; not needed here |
@@ -42,7 +40,6 @@ fn run_exec_collect( |
42 | 40 | async fn run_exec_impl(prompt: String, config: Config) -> Result<Vec<JsonValue>> { |
43 | 41 | let conversation_manager = ConversationManager::new(AuthManager::shared( |
44 | 42 | config.codex_home.clone(), |
45 | | - config.preferred_auth_method, |
46 | 43 | )); |
47 | 44 | let new_conv = conversation_manager.new_conversation(config).await?; |
48 | 45 | let conversation = new_conv.conversation.clone(); |
@@ -274,10 +271,22 @@ fn build_config( |
274 | 271 | } |
275 | 272 |
|
276 | 273 | if load_default_config { |
| 274 | + // Start from built-in defaults and apply CLI + typed overrides. |
277 | 275 | Ok(Config::load_with_cli_overrides(cli_overrides, overrides_struct)?) |
278 | 276 | } else { |
| 277 | + // Do NOT read any on-disk config. Build a TOML value purely from CLI-style overrides |
| 278 | + // and then apply the strongly-typed overrides on top. We still resolve CODEX_HOME to |
| 279 | + // pass through for paths/auth handling, but we avoid parsing a config file. |
279 | 280 | let codex_home = find_codex_home()?; |
280 | | - let cfg = load_config_as_toml_with_cli_overrides(&codex_home, cli_overrides)?; |
| 281 | + |
| 282 | + // Build a base TOML value from dotted CLI overrides only (no file IO). |
| 283 | + let mut base_tbl: TomlTable = TomlTable::new(); |
| 284 | + for (k, v) in cli_overrides.into_iter() { |
| 285 | + insert_dotted_toml(&mut base_tbl, &k, v); |
| 286 | + } |
| 287 | + |
| 288 | + let root_value = TomlValue::Table(base_tbl); |
| 289 | + let cfg: ConfigToml = root_value.try_into().map_err(|e| anyhow::anyhow!(e))?; |
281 | 290 | Ok(Config::load_from_base_config_with_overrides(cfg, overrides_struct, codex_home)?) |
282 | 291 | } |
283 | 292 | } |
@@ -350,12 +359,46 @@ fn flatten_overrides(out: &mut Vec<(String, TomlValue)>, prefix: &str, val: Toml |
350 | 359 | } |
351 | 360 | } |
352 | 361 |
|
| 362 | +/// Insert a TOML value into `tbl` at a dotted path like "a.b.c". |
| 363 | +fn insert_dotted_toml(tbl: &mut TomlTable, dotted: &str, val: TomlValue) { |
| 364 | + let parts: Vec<&str> = dotted.split('.').collect(); |
| 365 | + insert_parts(tbl, &parts, val); |
| 366 | +} |
| 367 | + |
| 368 | +fn insert_parts(current: &mut TomlTable, parts: &[&str], val: TomlValue) { |
| 369 | + if parts.is_empty() { |
| 370 | + return; |
| 371 | + } |
| 372 | + if parts.len() == 1 { |
| 373 | + current.insert(parts[0].to_string(), val); |
| 374 | + return; |
| 375 | + } |
| 376 | + |
| 377 | + let key = parts[0].to_string(); |
| 378 | + // Get or create an intermediate table at this segment. |
| 379 | + if let Some(existing) = current.get_mut(&key) { |
| 380 | + match existing { |
| 381 | + TomlValue::Table(ref mut t) => { |
| 382 | + insert_parts(t, &parts[1..], val); |
| 383 | + } |
| 384 | + _ => { |
| 385 | + let mut next = TomlTable::new(); |
| 386 | + insert_parts(&mut next, &parts[1..], val); |
| 387 | + *existing = TomlValue::Table(next); |
| 388 | + } |
| 389 | + } |
| 390 | + } else { |
| 391 | + let mut next = TomlTable::new(); |
| 392 | + insert_parts(&mut next, &parts[1..], val); |
| 393 | + current.insert(key, TomlValue::Table(next)); |
| 394 | + } |
| 395 | +} |
| 396 | + |
353 | 397 | fn run_exec_stream_impl(prompt: String, config: Config, tx: mpsc::Sender<JsonValue>) -> Result<()> { |
354 | 398 | let rt = tokio::runtime::Runtime::new()?; |
355 | 399 | rt.block_on(async move { |
356 | 400 | let conversation_manager = ConversationManager::new(AuthManager::shared( |
357 | 401 | config.codex_home.clone(), |
358 | | - config.preferred_auth_method, |
359 | 402 | )); |
360 | 403 | let new_conv = conversation_manager.new_conversation(config).await?; |
361 | 404 | let conversation = new_conv.conversation.clone(); |
|
0 commit comments