mirror of
https://github.com/openai/codex.git
synced 2026-05-16 17:23:57 +00:00
## Why `--profile-v2 <name>` gives launchers and runtime entry points a named profile config without making each profile duplicate the base user config. The base `$CODEX_HOME/config.toml` still loads first, then `$CODEX_HOME/<name>.config.toml` layers above it and becomes the active writable user config for that session. That keeps shared defaults, plugin/MCP setup, and managed/user constraints in one place while letting a named profile override only the pieces that need to differ. ## What Changed - Added the shared `--profile-v2 <name>` runtime option with validated plain names, now represented by `ProfileV2Name`. - Extended config layer state so the base user config and selected profile config are both `User` layers; APIs expose the active user layer and merged effective user config. - Threaded profile selection through runtime entry points: `codex`, `codex exec`, `codex review`, `codex resume`, `codex fork`, and `codex debug prompt-input`. - Made user-facing config writes go to the selected profile file when active, including TUI/settings persistence, app-server config writes, and MCP/app tool approval persistence. - Made plugin, marketplace, MCP, hooks, and config reload paths read from the merged user config so base and profile layers both participate. - Updated app-server config layer schemas to mark profile-backed user layers. ## Limits `--profile-v2` is still rejected for config-management subcommands such as feature, MCP, and marketplace edits. Those paths remain tied to the base `config.toml` until they have explicit profile-selection semantics. Some adjacent background writes may still update base or global state rather than the selected profile: - marketplace auto-upgrade metadata - automatic MCP dependency installs from skills - remote plugin sync or uninstall config edits - personality migration marker/default writes ## Verification Added targeted coverage for profile name validation, layer ordering/merging, selected-profile writes, app-server config writes, session hot reload, plugin config merging, hooks/config fixture updates, and MCP/app approval persistence. --------- Co-authored-by: Codex <noreply@openai.com>
71 lines
2.4 KiB
Rust
71 lines
2.4 KiB
Rust
use codex_config::CONFIG_TOML_FILE;
|
|
use codex_config::ConfigLayerStack;
|
|
use codex_config::TomlValue;
|
|
use codex_core::config::Config;
|
|
use codex_features::Feature;
|
|
use codex_hooks::HookListEntry;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
|
|
pub fn trust_discovered_hooks(config: &mut Config) {
|
|
if let Err(err) = config.features.enable(Feature::CodexHooks) {
|
|
panic!("test config should allow feature update: {err}");
|
|
}
|
|
|
|
let listed = codex_hooks::list_hooks(codex_hooks::HooksConfig {
|
|
feature_enabled: true,
|
|
config_layer_stack: Some(config.config_layer_stack.clone()),
|
|
..codex_hooks::HooksConfig::default()
|
|
});
|
|
assert!(
|
|
!listed.hooks.is_empty(),
|
|
"trusted hook fixture should discover at least one hook"
|
|
);
|
|
trust_hooks(config, listed.hooks);
|
|
}
|
|
|
|
pub fn trust_hooks(config: &mut Config, hooks: Vec<HookListEntry>) {
|
|
config.config_layer_stack =
|
|
trusted_config_layer_stack(&config.config_layer_stack, &config.codex_home, hooks);
|
|
}
|
|
|
|
pub fn trusted_config_layer_stack(
|
|
config_layer_stack: &ConfigLayerStack,
|
|
codex_home: &AbsolutePathBuf,
|
|
hooks: Vec<HookListEntry>,
|
|
) -> ConfigLayerStack {
|
|
let mut user_config = config_layer_stack
|
|
.get_active_user_layer()
|
|
.map(|layer| layer.config.clone())
|
|
.unwrap_or_else(|| TomlValue::Table(Default::default()));
|
|
let Some(user_table) = user_config.as_table_mut() else {
|
|
panic!("user config should be a table");
|
|
};
|
|
let Some(hooks_table) = user_table
|
|
.entry("hooks")
|
|
.or_insert_with(|| TomlValue::Table(Default::default()))
|
|
.as_table_mut()
|
|
else {
|
|
panic!("hooks config should be a table");
|
|
};
|
|
let Some(state_table) = hooks_table
|
|
.entry("state")
|
|
.or_insert_with(|| TomlValue::Table(Default::default()))
|
|
.as_table_mut()
|
|
else {
|
|
panic!("hook state config should be a table");
|
|
};
|
|
for hook in hooks {
|
|
let mut hook_state = TomlValue::Table(Default::default());
|
|
let Some(hook_state_table) = hook_state.as_table_mut() else {
|
|
panic!("hook state should be a table");
|
|
};
|
|
hook_state_table.insert(
|
|
"trusted_hash".to_string(),
|
|
TomlValue::String(hook.current_hash),
|
|
);
|
|
state_table.insert(hook.key, hook_state);
|
|
}
|
|
|
|
config_layer_stack.with_user_config(&codex_home.join(CONFIG_TOML_FILE), user_config)
|
|
}
|