mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
feat: feature flag new tool
This commit is contained in:
@@ -23,13 +23,16 @@ pub(crate) struct MemoriesExtension;
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct MemoriesExtensionConfig {
|
||||
pub(crate) enabled: bool,
|
||||
pub(crate) custom_tools_enabled: bool,
|
||||
pub(crate) codex_home: AbsolutePathBuf,
|
||||
}
|
||||
|
||||
impl MemoriesExtensionConfig {
|
||||
fn from_config(config: &Config) -> Self {
|
||||
let enabled = config.features.enabled(Feature::MemoryTool) && config.memories.use_memories;
|
||||
Self {
|
||||
enabled: config.features.enabled(Feature::MemoryTool) && config.memories.use_memories,
|
||||
enabled,
|
||||
custom_tools_enabled: enabled && config.features.memories_custom_tools(),
|
||||
codex_home: config.codex_home.clone(),
|
||||
}
|
||||
}
|
||||
@@ -88,7 +91,7 @@ impl ToolContributor for MemoriesExtension {
|
||||
let Some(config) = thread_store.get::<MemoriesExtensionConfig>() else {
|
||||
return Vec::new();
|
||||
};
|
||||
if !config.enabled {
|
||||
if !config.custom_tools_enabled {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
@@ -101,7 +104,6 @@ pub fn install(registry: &mut ExtensionRegistryBuilder<Config>) {
|
||||
let extension = Arc::new(MemoriesExtension);
|
||||
registry.thread_lifecycle_contributor(extension.clone());
|
||||
registry.config_contributor(extension.clone());
|
||||
registry.prompt_contributor(extension);
|
||||
// Keep the read/retrieval tools out of app-server until that rollout is intentional.
|
||||
// registry.tool_contributor(extension);
|
||||
registry.prompt_contributor(extension.clone());
|
||||
registry.tool_contributor(extension);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::sync::Arc;
|
||||
|
||||
use codex_extension_api::ContextContributor;
|
||||
use codex_extension_api::ExtensionData;
|
||||
use codex_extension_api::ExtensionRegistryBuilder;
|
||||
use codex_extension_api::PromptSlot;
|
||||
use codex_extension_api::ToolCall;
|
||||
use codex_extension_api::ToolContributor;
|
||||
@@ -21,6 +22,15 @@ use crate::extension::MemoriesExtension;
|
||||
use crate::extension::MemoriesExtensionConfig;
|
||||
use crate::local::LocalMemoriesBackend;
|
||||
|
||||
#[test]
|
||||
fn install_registers_tool_contributor() {
|
||||
let mut builder = ExtensionRegistryBuilder::<codex_core::config::Config>::new();
|
||||
crate::install(&mut builder);
|
||||
let registry = builder.build();
|
||||
|
||||
assert_eq!(registry.tool_contributors().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tools_are_not_contributed_without_thread_config() {
|
||||
let extension = MemoriesExtension;
|
||||
@@ -41,6 +51,7 @@ fn tools_are_not_contributed_when_disabled() {
|
||||
let thread_store = ExtensionData::new("thread");
|
||||
thread_store.insert(MemoriesExtensionConfig {
|
||||
enabled: false,
|
||||
custom_tools_enabled: false,
|
||||
codex_home: test_path_buf("/tmp/codex-home").abs(),
|
||||
});
|
||||
|
||||
@@ -57,6 +68,7 @@ fn tools_are_contributed_when_enabled() {
|
||||
let thread_store = ExtensionData::new("thread");
|
||||
thread_store.insert(MemoriesExtensionConfig {
|
||||
enabled: true,
|
||||
custom_tools_enabled: true,
|
||||
codex_home: test_path_buf("/tmp/codex-home").abs(),
|
||||
});
|
||||
|
||||
@@ -77,6 +89,23 @@ fn tools_are_contributed_when_enabled() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tools_are_not_contributed_when_custom_tools_disabled() {
|
||||
let extension = MemoriesExtension;
|
||||
let thread_store = ExtensionData::new("thread");
|
||||
thread_store.insert(MemoriesExtensionConfig {
|
||||
enabled: true,
|
||||
custom_tools_enabled: false,
|
||||
codex_home: test_path_buf("/tmp/codex-home").abs(),
|
||||
});
|
||||
|
||||
assert!(
|
||||
extension
|
||||
.tools(&ExtensionData::new("session"), &thread_store)
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ad_hoc_tool_definition_includes_filename_contract() {
|
||||
let tool = memory_tool(
|
||||
@@ -115,6 +144,7 @@ async fn prompt_contribution_uses_memory_summary_when_enabled() {
|
||||
let thread_store = ExtensionData::new("thread");
|
||||
thread_store.insert(MemoriesExtensionConfig {
|
||||
enabled: true,
|
||||
custom_tools_enabled: false,
|
||||
codex_home: tempdir.path().abs(),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user