Lightweight coding agent that runs in your terminal
Rust
feat: drop `CodexExtension` (#22140)
jif-oaiebd3d534516a
diff --git a/codex-rs/app-server/src/extensions.rs b/codex-rs/app-server/src/extensions.rsindex 9449f8dcad..9fe468dc05 100644--- a/codex-rs/app-server/src/extensions.rs+++ b/codex-rs/app-server/src/extensions.rs@@ -5,9 +5,7 @@ use codex_extension_api::ExtensionRegistry;use codex_extension_api::ExtensionRegistryBuilder;pub(crate) fn thread_extensions() -> Arc<ExtensionRegistry<Config>> {- Arc::new(- ExtensionRegistryBuilder::<Config>::new()- .with_extension(codex_git_attribution::extension())- .build(),- )+ let mut builder = ExtensionRegistryBuilder::<Config>::new();+ codex_git_attribution::install(&mut builder);+ Arc::new(builder.build())}diff --git a/codex-rs/ext/extension-api/examples/enabled_extensions.rs b/codex-rs/ext/extension-api/examples/enabled_extensions.rsindex f091aa7ab5..9a267d6919 100644--- a/codex-rs/ext/extension-api/examples/enabled_extensions.rs+++ b/codex-rs/ext/extension-api/examples/enabled_extensions.rs@@ -1,29 +1,23 @@#[path = "enabled_extensions/shared_state_extension.rs"]mod shared_state_extension;-use std::sync::Arc;-use codex_extension_api::ExtensionData;use codex_extension_api::ExtensionRegistryBuilder;-use shared_state_extension::SharedStateExtension;use shared_state_extension::recorded_style_contributions;use shared_state_extension::recorded_usage_contributions;fn main() {- // 1. Build the extension value owned by the host.- let extension = Arc::new(SharedStateExtension);-- // 2. Install it into the registry for the thread-start input type this host exposes.- let registry = ExtensionRegistryBuilder::<()>::new()- .with_extension(extension)- .build();+ // 1. Install the contributors for the thread-start input type this host exposes.+ let mut builder = ExtensionRegistryBuilder::<()>::new();+ shared_state_extension::install(&mut builder);+ let registry = builder.build();- // 3. The host decides which stores are shared.+ // 2. The host decides which stores are shared.let session_store = ExtensionData::new();let first_thread_store = ExtensionData::new();let second_thread_store = ExtensionData::new();- // 4. Reusing the same session store shares session state across threads.+ // 3. Reusing the same session store shares session state across threads.let first_thread_fragments = contribute_prompt(®istry, &session_store, &first_thread_store);contribute_prompt(®istry, &session_store, &first_thread_store);contribute_prompt(®istry, &session_store, &second_thread_store);diff --git a/codex-rs/ext/extension-api/examples/enabled_extensions/shared_state_extension.rs b/codex-rs/ext/extension-api/examples/enabled_extensions/shared_state_extension.rsindex 9b6612e3ae..25ab027c88 100644--- a/codex-rs/ext/extension-api/examples/enabled_extensions/shared_state_extension.rs+++ b/codex-rs/ext/extension-api/examples/enabled_extensions/shared_state_extension.rs@@ -2,21 +2,15 @@ use std::sync::Arc;use std::sync::atomic::AtomicU64;use std::sync::atomic::Ordering;-use codex_extension_api::CodexExtension;use codex_extension_api::ContextContributor;use codex_extension_api::ExtensionData;use codex_extension_api::ExtensionRegistryBuilder;use codex_extension_api::PromptFragment;-/// Small tutorial extension that installs two prompt contributors.-#[derive(Debug, Default)]-pub struct SharedStateExtension;--impl CodexExtension<()> for SharedStateExtension {- fn install(self: Arc<Self>, registry: &mut ExtensionRegistryBuilder<()>) {- registry.prompt_contributor(Arc::new(StyleContributor));- registry.prompt_contributor(Arc::new(UsageContributor));- }+/// Installs the tutorial contributors used by the example host.+pub fn install(registry: &mut ExtensionRegistryBuilder<()>) {+ registry.prompt_contributor(Arc::new(StyleContributor));+ registry.prompt_contributor(Arc::new(UsageContributor));}#[derive(Debug)]diff --git a/codex-rs/ext/extension-api/src/extension.rs b/codex-rs/ext/extension-api/src/extension.rsdeleted file mode 100644index c38f22e9cb..0000000000--- a/codex-rs/ext/extension-api/src/extension.rs+++ /dev/null@@ -1,12 +0,0 @@-use std::sync::Arc;--use crate::ExtensionRegistryBuilder;--/// First-party extension that can install one or more typed runtime contributions.-///-/// Implementations should use [`Self::install`] only to register the concrete-/// providers they own.-pub trait CodexExtension<C>: Send + Sync {- /// Registers this extension's concrete typed contributions.- fn install(self: Arc<Self>, registry: &mut ExtensionRegistryBuilder<C>);-}diff --git a/codex-rs/ext/extension-api/src/lib.rs b/codex-rs/ext/extension-api/src/lib.rsindex 0b07f9e285..951ffab22e 100644--- a/codex-rs/ext/extension-api/src/lib.rs+++ b/codex-rs/ext/extension-api/src/lib.rs@@ -1,5 +1,4 @@mod contributors;-mod extension;mod registry;mod state;@@ -14,7 +13,6 @@ pub use contributors::ToolContributor;pub use contributors::ToolHandler;pub use contributors::TurnItemContributionFuture;pub use contributors::TurnItemContributor;-pub use extension::CodexExtension;pub use registry::ExtensionRegistry;pub use registry::ExtensionRegistryBuilder;pub use registry::empty_extension_registry;diff --git a/codex-rs/ext/extension-api/src/registry.rs b/codex-rs/ext/extension-api/src/registry.rsindex 4a90e2e606..e4039ec29c 100644--- a/codex-rs/ext/extension-api/src/registry.rs+++ b/codex-rs/ext/extension-api/src/registry.rs@@ -1,13 +1,12 @@use std::sync::Arc;use crate::ApprovalInterceptorContributor;-use crate::CodexExtension;use crate::ContextContributor;use crate::ThreadStartContributor;use crate::ToolContributor;use crate::TurnItemContributor;-/// Mutable registry used while extensions install their typed contributions.+/// Mutable registry used while hosts register typed runtime contributions.pub struct ExtensionRegistryBuilder<C> {thread_start_contributors: Vec<Arc<dyn ThreadStartContributor<C>>>,context_contributors: Vec<Arc<dyn ContextContributor>>,@@ -34,24 +33,6 @@ impl<C> ExtensionRegistryBuilder<C> {Self::default()}- /// Installs one extension and returns the builder.- #[must_use]- pub fn with_extension<E>(mut self, extension: Arc<E>) -> Self- where- E: CodexExtension<C> + 'static,- {- self.install_extension(extension);- self- }-- /// Installs one extension into the registry under construction.- pub fn install_extension<E>(&mut self, extension: Arc<E>)- where- E: CodexExtension<C> + 'static,- {- extension.install(self);- }-/// Registers one approval interceptor contributor.pub fn approval_interceptor_contributor(&mut self,@@ -128,7 +109,7 @@ impl<C> ExtensionRegistry<C> {}}-/// Creates an empty shared registry for hosts that do not install extensions.+/// Creates an empty shared registry for hosts that do not register contributions.pub fn empty_extension_registry<C>() -> Arc<ExtensionRegistry<C>> {Arc::new(ExtensionRegistryBuilder::new().build())}diff --git a/codex-rs/ext/git-attribution/src/lib.rs b/codex-rs/ext/git-attribution/src/lib.rsindex d4b711d555..bb73a83011 100644--- a/codex-rs/ext/git-attribution/src/lib.rs+++ b/codex-rs/ext/git-attribution/src/lib.rs@@ -1,7 +1,6 @@use std::sync::Arc;use codex_core::config::Config;-use codex_extension_api::CodexExtension;use codex_extension_api::ContextContributor;use codex_extension_api::ExtensionData;use codex_extension_api::ExtensionRegistryBuilder;@@ -11,17 +10,10 @@ use codex_features::Feature;const DEFAULT_ATTRIBUTION_VALUE: &str = "Codex <[email protected]>";-/// Prompt-only extension that contributes the configured git-attribution instruction.+/// Contributes the configured git-attribution instruction.#[derive(Clone, Copy, Debug, Default)]pub struct GitAttributionExtension;-impl GitAttributionExtension {- /// Creates an extension instance.- pub fn new() -> Self {- Self- }-}-impl ContextContributor for GitAttributionExtension {fn contribute(&self,@@ -61,16 +53,11 @@ impl ThreadStartContributor<Config> for GitAttributionExtension {}}-impl CodexExtension<Config> for GitAttributionExtension {- fn install(self: Arc<Self>, registry: &mut ExtensionRegistryBuilder<Config>) {- registry.thread_start_contributor(self.clone());- registry.prompt_contributor(self);- }-}--/// Creates a shared git-attribution extension instance.-pub fn extension() -> Arc<GitAttributionExtension> {- Arc::new(GitAttributionExtension::new())+/// Installs the git-attribution contributors into the extension registry.+pub fn install(registry: &mut ExtensionRegistryBuilder<Config>) {+ let extension = Arc::new(GitAttributionExtension);+ registry.thread_start_contributor(extension.clone());+ registry.prompt_contributor(extension);}fn build_commit_message_trailer(config_attribution: Option<&str>) -> Option<String> {