feat: introduce --profile for Rust CLI (#921)

This introduces a much-needed "profile" concept where users can specify
a collection of options under one name and then pass that via
`--profile` to the CLI.

This PR introduces the `ConfigProfile` struct and makes it a field of
`CargoToml`. It further updates
`Config::load_from_base_config_with_overrides()` to respect
`ConfigProfile`, overriding default values where appropriate. A detailed
unit test is added at the end of `config.rs` to verify this behavior.

Details on how to use this feature have also been added to
`codex-rs/README.md`.
This commit is contained in:
Michael Bolin
2025-05-13 16:52:52 -07:00
committed by GitHub
parent ae809f3721
commit 3c03c25e56
14 changed files with 309 additions and 15 deletions

View File

@@ -22,6 +22,10 @@ pub(crate) struct CodexToolCallParam {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
/// Configuration profile from config.toml to specify default options.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub profile: Option<String>,
/// Working directory for the session. If relative, it is resolved against
/// the server process's current working directory.
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -144,6 +148,7 @@ impl CodexToolCallParam {
let Self {
prompt,
model,
profile,
cwd,
approval_policy,
sandbox_permissions,
@@ -156,11 +161,12 @@ impl CodexToolCallParam {
// Build ConfigOverrides recognised by codex-core.
let overrides = codex_core::config::ConfigOverrides {
model,
config_profile: profile,
cwd: cwd.map(PathBuf::from),
approval_policy: approval_policy.map(Into::into),
sandbox_policy,
disable_response_storage,
provider: None,
model_provider: None,
};
let cfg = codex_core::config::Config::load_with_overrides(overrides)?;
@@ -218,6 +224,10 @@ mod tests {
"description": "Optional override for the model name (e.g. \"o3\", \"o4-mini\")",
"type": "string"
},
"profile": {
"description": "Configuration profile from config.toml to specify default options.",
"type": "string"
},
"prompt": {
"description": "The *initial user prompt* to start the Codex conversation.",
"type": "string"