diff --git a/codex-rs/config/src/config_requirements.rs b/codex-rs/config/src/config_requirements.rs index 8e37a3175a..05aa8ba20f 100644 --- a/codex-rs/config/src/config_requirements.rs +++ b/codex-rs/config/src/config_requirements.rs @@ -772,7 +772,9 @@ pub struct ConfigRequirementsToml { #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConfigDeprecationNotice { + /// Concise summary of what is deprecated. pub summary: String, + /// Optional extra guidance, such as migration steps or rationale. pub details: Option, } @@ -897,6 +899,7 @@ pub struct ConfigRequirementsWithSources { pub network: Option>, pub permissions: Option>, pub guardian_policy_config: Option>, + pub deprecation_notices: Vec, } impl ConfigRequirementsWithSources { @@ -915,6 +918,8 @@ impl ConfigRequirementsWithSources { }; } + self.extend_deprecation_notices(other.deprecation_notices()); + // Destructure without `..` so adding fields to `ConfigRequirementsToml` // forces this merge logic to be updated. let ConfigRequirementsToml { @@ -981,6 +986,18 @@ impl ConfigRequirementsWithSources { } } + pub fn deprecation_notices(&self) -> &[ConfigDeprecationNotice] { + &self.deprecation_notices + } + + fn extend_deprecation_notices(&mut self, notices: Vec) { + for notice in notices { + if !self.deprecation_notices.contains(¬ice) { + self.deprecation_notices.push(notice); + } + } + } + pub fn into_toml(self) -> ConfigRequirementsToml { let ConfigRequirementsWithSources { allowed_approval_policies, @@ -1001,6 +1018,7 @@ impl ConfigRequirementsWithSources { network, permissions, guardian_policy_config, + deprecation_notices: _, } = self; ConfigRequirementsToml { allowed_approval_policies: allowed_approval_policies.map(|sourced| sourced.value), @@ -1170,6 +1188,7 @@ impl TryFrom for ConfigRequirements { network, permissions, guardian_policy_config, + deprecation_notices: _, } = toml; let approval_policy = match allowed_approval_policies { @@ -1459,6 +1478,7 @@ mod tests { } fn with_unknown_source(toml: ConfigRequirementsToml) -> ConfigRequirementsWithSources { + let deprecation_notices = toml.deprecation_notices(); let ConfigRequirementsToml { allowed_approval_policies, allowed_approvals_reviewers, @@ -1509,6 +1529,7 @@ mod tests { permissions: permissions.map(|value| Sourced::new(value, RequirementSource::Unknown)), guardian_policy_config: guardian_policy_config .map(|value| Sourced::new(value, RequirementSource::Unknown)), + deprecation_notices, } } @@ -1729,6 +1750,7 @@ mod tests { network: None, permissions: None, guardian_policy_config: Some(Sourced::new(guardian_policy_config, source)), + deprecation_notices: Vec::new(), } ); } @@ -1772,6 +1794,7 @@ mod tests { network: None, permissions: None, guardian_policy_config: None, + deprecation_notices: Vec::new(), } ); Ok(()) @@ -1823,6 +1846,7 @@ mod tests { network: None, permissions: None, guardian_policy_config: None, + deprecation_notices: Vec::new(), } ); Ok(()) diff --git a/codex-rs/config/src/loader/mod.rs b/codex-rs/config/src/loader/mod.rs index 3c1723e51b..6bb79e1e35 100644 --- a/codex-rs/config/src/loader/mod.rs +++ b/codex-rs/config/src/loader/mod.rs @@ -376,11 +376,13 @@ pub async fn load_config_layers_state( )); } + let config_deprecation_notices = config_requirements_toml.deprecation_notices().to_vec(); let config_layer_stack = ConfigLayerStack::new( layers, config_requirements_toml.clone().try_into()?, config_requirements_toml.into_toml(), )? + .with_config_deprecation_notices(config_deprecation_notices) .with_user_and_project_exec_policy_rules_ignored(ignore_user_and_project_exec_policy_rules); Ok(match startup_warnings { Some(startup_warnings) => config_layer_stack.with_startup_warnings(startup_warnings), diff --git a/codex-rs/config/src/state.rs b/codex-rs/config/src/state.rs index 3ec0bfb314..ba6cb6c901 100644 --- a/codex-rs/config/src/state.rs +++ b/codex-rs/config/src/state.rs @@ -1,3 +1,4 @@ +use crate::config_requirements::ConfigDeprecationNotice; use crate::config_requirements::ConfigRequirements; use crate::config_requirements::ConfigRequirementsToml; @@ -231,6 +232,9 @@ pub struct ConfigLayerStack { /// surfaced via APIs. requirements_toml: ConfigRequirementsToml, + /// Deprecation notices discovered while loading config requirements. + config_deprecation_notices: Vec, + /// Whether execpolicy should skip `.rules` files from user and project config-layer folders. ignore_user_and_project_exec_policy_rules: bool, @@ -253,6 +257,7 @@ impl ConfigLayerStack { user_layer_index, requirements, requirements_toml, + config_deprecation_notices: Vec::new(), ignore_user_and_project_exec_policy_rules: false, startup_warnings: None, }) @@ -266,6 +271,14 @@ impl ConfigLayerStack { self } + pub fn with_config_deprecation_notices( + mut self, + config_deprecation_notices: Vec, + ) -> Self { + self.config_deprecation_notices = config_deprecation_notices; + self + } + pub fn ignore_user_and_project_exec_policy_rules(&self) -> bool { self.ignore_user_and_project_exec_policy_rules } @@ -342,6 +355,10 @@ impl ConfigLayerStack { &self.requirements_toml } + pub fn config_deprecation_notices(&self) -> &[ConfigDeprecationNotice] { + &self.config_deprecation_notices + } + /// Creates a new [ConfigLayerStack] using the specified values to inject one /// user layer into the stack. If such a layer already exists, it is replaced; /// otherwise, it is inserted into the stack at the appropriate position @@ -400,6 +417,7 @@ impl ConfigLayerStack { user_layer_index, requirements: self.requirements.clone(), requirements_toml: self.requirements_toml.clone(), + config_deprecation_notices: self.config_deprecation_notices.clone(), ignore_user_and_project_exec_policy_rules: self .ignore_user_and_project_exec_policy_rules, startup_warnings: self.startup_warnings.clone(), @@ -442,6 +460,7 @@ impl ConfigLayerStack { user_layer_index, requirements: self.requirements.clone(), requirements_toml: self.requirements_toml.clone(), + config_deprecation_notices: self.config_deprecation_notices.clone(), ignore_user_and_project_exec_policy_rules: self .ignore_user_and_project_exec_policy_rules, startup_warnings: self.startup_warnings.clone(), diff --git a/codex-rs/core/src/config/config_loader_tests.rs b/codex-rs/core/src/config/config_loader_tests.rs index bcdd56a193..490c133c6e 100644 --- a/codex-rs/core/src/config/config_loader_tests.rs +++ b/codex-rs/core/src/config/config_loader_tests.rs @@ -5,6 +5,7 @@ use codex_app_server_protocol::ConfigLayerSource; use codex_config::CONFIG_TOML_FILE; use codex_config::CloudRequirementsLoadError; use codex_config::CloudRequirementsLoader; +use codex_config::ConfigDeprecationNotice; use codex_config::ConfigError; use codex_config::ConfigLayerEntry; use codex_config::ConfigLayerStackOrdering; @@ -1837,6 +1838,54 @@ async fn load_config_layers_applies_matching_remote_sandbox_config() -> anyhow:: Ok(()) } +#[tokio::test] +async fn load_preserves_legacy_remote_sandbox_config_deprecation_notice() -> anyhow::Result<()> { + let tmp = tempdir()?; + let codex_home = tmp.path().join("home"); + tokio::fs::create_dir_all(&codex_home).await?; + let cwd = AbsolutePathBuf::from_absolute_path(tmp.path())?; + + let requirements: ConfigRequirementsToml = toml::from_str( + r#" + [[remote_sandbox_config]] + hostname_patterns = ["*"] + allowed_sandbox_modes = ["read-only", "workspace-write"] + "#, + )?; + let cloud_requirements = CloudRequirementsLoader::new(async move { Ok(Some(requirements)) }); + let layers = load_config_layers_state( + LOCAL_FS.as_ref(), + &codex_home, + Some(cwd), + &[] as &[(String, TomlValue)], + LoaderOverrides::default(), + cloud_requirements, + &codex_config::NoopThreadConfigLoader, + ) + .await?; + + assert_eq!( + layers.config_deprecation_notices(), + [ConfigDeprecationNotice { + summary: "`[[remote_sandbox_config]]` requirements are deprecated".to_string(), + details: Some( + "Use keyed `[remote_sandbox_config.]` tables instead. Keep the same `hostname_patterns` and `allowed_sandbox_modes` fields under each named table." + .to_string() + ), + }] + ); + assert_eq!(layers.requirements_toml().remote_sandbox_config, None); + assert_eq!( + layers.requirements_toml().allowed_sandbox_modes, + Some(vec![ + codex_config::SandboxModeRequirement::ReadOnly, + codex_config::SandboxModeRequirement::WorkspaceWrite, + ]) + ); + + Ok(()) +} + #[tokio::test] async fn load_config_layers_fails_when_cloud_requirements_loader_fails() -> anyhow::Result<()> { let tmp = tempdir()?; diff --git a/codex-rs/core/src/session/session.rs b/codex-rs/core/src/session/session.rs index 0392060d22..45deb624c0 100644 --- a/codex-rs/core/src/session/session.rs +++ b/codex-rs/core/src/session/session.rs @@ -726,12 +726,12 @@ impl Session { }), }); } - for notice in config.config_layer_stack.requirements_toml().deprecation_notices() { + for notice in config.config_layer_stack.config_deprecation_notices() { post_session_configured_events.push(Event { id: INITIAL_SUBMIT_ID.to_owned(), msg: EventMsg::DeprecationNotice(DeprecationNoticeEvent { - summary: notice.summary, - details: notice.details, + summary: notice.summary.clone(), + details: notice.details.clone(), }), }); }