From f0f3d650b0e0fcb5041385d7ef75205e5d509ef3 Mon Sep 17 00:00:00 2001 From: jif Date: Wed, 25 Nov 2026 11:28:05 +0000 Subject: [PATCH] Move plugin skill namespace resolution into the skills loader (#63897) ## Why The skills loader is the only consumer of the plugin namespace lookup that uses the execution environment's filesystem. Keeping the lookup there lets the shared plugin utilities drop their dependency on `codex-exec-server`. ## What changed Move the manifest name lookup into the skills loader. It still uses the shared manifest search order and falls back to the plugin directory name when the manifest name is missing or blank. ## Testing Cover namespace resolution through the skills loader for Codex, Claude, and Cursor manifests. Extend the local manifest lookup test to verify that it falls back to the Cursor manifest after the other two are removed. GitOrigin-RevId: 1f2cea60f660880377b0a39cb1e4f42034aded95 --- codex-rs/Cargo.lock | 4 - codex-rs/ext/skills/src/loader/namespace.rs | 44 +++++- .../ext/skills/src/loader/namespace_tests.rs | 17 +++ codex-rs/utils/plugins/Cargo.toml | 4 - codex-rs/utils/plugins/src/lib.rs | 1 - .../utils/plugins/src/plugin_namespace.rs | 135 ++---------------- 6 files changed, 69 insertions(+), 136 deletions(-) diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 8769637d16..d3b2f9b8e1 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -5762,14 +5762,10 @@ dependencies = [ name = "codex-utils-plugins" version = "0.0.0" dependencies = [ - "codex-exec-server", "codex-exec-server-protocol", "codex-utils-absolute-path", - "codex-utils-path-uri", - "serde", "serde_json", "tempfile", - "tokio", ] [[package]] diff --git a/codex-rs/ext/skills/src/loader/namespace.rs b/codex-rs/ext/skills/src/loader/namespace.rs index d991b6c4ca..921800022d 100644 --- a/codex-rs/ext/skills/src/loader/namespace.rs +++ b/codex-rs/ext/skills/src/loader/namespace.rs @@ -2,8 +2,11 @@ use std::collections::HashMap; use std::collections::HashSet; use codex_exec_server::EnvironmentAccess; +use codex_exec_server::EnvironmentAccessExt; +use codex_exec_server::GetMetadataOptions; +use codex_exec_server::ReadFileOptions; use codex_utils_path_uri::PathUri; -use codex_utils_plugins::plugin_namespace_for_root_uri; +use codex_utils_plugins::DISCOVERABLE_PLUGIN_MANIFEST_PATHS; use futures::StreamExt; use super::discovery::MAX_CONCURRENT_SKILL_LOADS; @@ -181,6 +184,45 @@ impl ResolvedSkillNamespace { } } +#[derive(serde::Deserialize)] +#[serde(rename_all = "camelCase")] +struct RawPluginManifestName { + #[serde(default)] + name: String, +} + +/// Returns the plugin manifest `name` defined directly below `plugin_root`. +async fn plugin_namespace_for_root_uri( + fs: &dyn EnvironmentAccess, + plugin_root: &PathUri, +) -> Option { + let mut manifest_path = None; + for relative_path in DISCOVERABLE_PLUGIN_MANIFEST_PATHS { + let candidate = plugin_root.join(relative_path).ok()?; + match fs + .get_metadata(&candidate, GetMetadataOptions::default()) + .await + { + Ok(metadata) if metadata.is_file => { + manifest_path = Some(candidate); + break; + } + Ok(_) | Err(_) => {} + } + } + let contents = fs + .read_file_text(&manifest_path?, ReadFileOptions::default()) + .await + .ok()?; + let RawPluginManifestName { name: raw_name } = serde_json::from_str(&contents).ok()?; + Some( + plugin_root + .basename() + .filter(|_| raw_name.trim().is_empty()) + .unwrap_or(raw_name), + ) +} + #[cfg(test)] #[path = "namespace_tests.rs"] mod tests; diff --git a/codex-rs/ext/skills/src/loader/namespace_tests.rs b/codex-rs/ext/skills/src/loader/namespace_tests.rs index d5e172c923..e980ecacbe 100644 --- a/codex-rs/ext/skills/src/loader/namespace_tests.rs +++ b/codex-rs/ext/skills/src/loader/namespace_tests.rs @@ -62,6 +62,23 @@ async fn namespaces_for( .collect() } +#[tokio::test] +async fn uses_manifest_name_from_each_discoverable_path() { + for directory in [".codex-plugin", ".claude-plugin", ".cursor-plugin"] { + let root = TempDir::new().expect("root temp dir"); + let manifest_dir = root.path().join(directory); + fs::create_dir(&manifest_dir).expect("create manifest directory"); + fs::write(manifest_dir.join("plugin.json"), r#"{"name":"sample"}"#) + .expect("write manifest"); + let skill = write_skill(root.path(), "skills/search"); + + let namespaces = + namespaces_for(root.path(), &[skill], HashSet::new(), HashSet::new()).await; + + assert_eq!(namespaces, vec!["sample:skill"], "{directory}"); + } +} + #[tokio::test] async fn nested_plugin_namespaces_do_not_apply_to_plain_siblings() { let root = TempDir::new().expect("root temp dir"); diff --git a/codex-rs/utils/plugins/Cargo.toml b/codex-rs/utils/plugins/Cargo.toml index 1a4576d59d..aa9728bd06 100644 --- a/codex-rs/utils/plugins/Cargo.toml +++ b/codex-rs/utils/plugins/Cargo.toml @@ -14,13 +14,9 @@ path = "src/lib.rs" workspace = true [dependencies] -codex-exec-server = { workspace = true } codex-exec-server-protocol = { workspace = true } codex-utils-absolute-path = { workspace = true } -codex-utils-path-uri = { workspace = true } -serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } [dev-dependencies] tempfile = { workspace = true } -tokio = { workspace = true, features = ["macros", "rt"] } diff --git a/codex-rs/utils/plugins/src/lib.rs b/codex-rs/utils/plugins/src/lib.rs index 8372e9170d..e6cc457d99 100644 --- a/codex-rs/utils/plugins/src/lib.rs +++ b/codex-rs/utils/plugins/src/lib.rs @@ -15,7 +15,6 @@ pub use plugin_namespace::AgentPluginSchemaStatus; pub use plugin_namespace::SUPPORTED_AGENT_PLUGIN_SCHEMA_URIS; pub use plugin_namespace::agent_plugin_schema_status; pub use plugin_namespace::find_plugin_manifest_path; -pub use plugin_namespace::plugin_namespace_for_root_uri; #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)] pub enum SkillDiscoveryMode { diff --git a/codex-rs/utils/plugins/src/plugin_namespace.rs b/codex-rs/utils/plugins/src/plugin_namespace.rs index f64c3897d3..d91b11d853 100644 --- a/codex-rs/utils/plugins/src/plugin_namespace.rs +++ b/codex-rs/utils/plugins/src/plugin_namespace.rs @@ -1,11 +1,6 @@ -//! Resolve plugin namespace from skill file paths by walking ancestors for `plugin.json`. +//! Locate local plugin manifests and recognize Agent Plugins schemas. -use codex_exec_server::EnvironmentAccess; -use codex_exec_server::EnvironmentAccessExt; -use codex_exec_server::GetMetadataOptions; -use codex_exec_server::ReadFileOptions; use codex_exec_server_protocol::DISCOVERABLE_PLUGIN_MANIFEST_PATHS; -use codex_utils_path_uri::PathUri; use std::path::Path; use std::path::PathBuf; @@ -79,134 +74,17 @@ pub fn find_plugin_manifest_path(plugin_root: &Path) -> Option { None } -#[derive(serde::Deserialize)] -#[serde(rename_all = "camelCase")] -struct RawPluginManifestName { - #[serde(default)] - name: String, -} - -/// Returns the plugin manifest `name` defined directly below `plugin_root`. -pub async fn plugin_namespace_for_root_uri( - fs: &dyn EnvironmentAccess, - plugin_root: &PathUri, -) -> Option { - let mut manifest_path = None; - for relative_path in DISCOVERABLE_PLUGIN_MANIFEST_PATHS { - let candidate = plugin_root.join(relative_path).ok()?; - match fs - .get_metadata(&candidate, GetMetadataOptions::default()) - .await - { - Ok(metadata) if metadata.is_file => { - manifest_path = Some(candidate); - break; - } - Ok(_) | Err(_) => {} - } - } - let contents = fs - .read_file_text(&manifest_path?, ReadFileOptions::default()) - .await - .ok()?; - let RawPluginManifestName { name: raw_name } = serde_json::from_str(&contents).ok()?; - Some( - plugin_root - .basename() - .filter(|_| raw_name.trim().is_empty()) - .unwrap_or(raw_name), - ) -} - #[cfg(test)] mod tests { use super::AGENT_PLUGIN_MANIFEST_RELATIVE_PATH; use super::AGENT_PLUGIN_SCHEMA_URI; use super::find_plugin_manifest_path; - use super::plugin_namespace_for_root_uri; - use codex_exec_server::FileSystemEnvironmentAccessor; - use codex_exec_server::LOCAL_FS; - use codex_utils_absolute_path::test_support::PathBufExt; - use codex_utils_path_uri::PathUri; use std::fs; use tempfile::tempdir; const ALTERNATE_PLUGIN_CLA_MANIFEST_RELATIVE_PATH: &str = ".claude-plugin/plugin.json"; const ALTERNATE_PLUGIN_CUR_MANIFEST_RELATIVE_PATH: &str = ".cursor-plugin/plugin.json"; - #[tokio::test] - async fn uses_manifest_name() { - let tmp = tempdir().expect("tempdir"); - let plugin_root = tmp.path().join("plugins/sample"); - let skill_path = plugin_root.join("skills/search/SKILL.md"); - - fs::create_dir_all(skill_path.parent().expect("parent")).expect("mkdir"); - fs::create_dir_all(plugin_root.join(".codex-plugin")).expect("mkdir manifest"); - fs::write( - plugin_root.join(".codex-plugin/plugin.json"), - r#"{"name":"sample"}"#, - ) - .expect("write manifest"); - fs::write(&skill_path, "---\ndescription: search\n---\n").expect("write skill"); - - assert_eq!( - plugin_namespace_for_root_uri( - &FileSystemEnvironmentAccessor::unrestricted(&LOCAL_FS), - &PathUri::from_abs_path(&plugin_root.abs()), - ) - .await, - Some("sample".to_string()) - ); - } - - #[tokio::test] - async fn uses_name_from_alternate_discoverable_manifest_path() { - let tmp = tempdir().expect("tempdir"); - let plugin_root = tmp.path().join("plugins/sample"); - let skill_path = plugin_root.join("skills/search/SKILL.md"); - let manifest_path = plugin_root.join(ALTERNATE_PLUGIN_CLA_MANIFEST_RELATIVE_PATH); - - fs::create_dir_all(skill_path.parent().expect("parent")).expect("mkdir"); - fs::create_dir_all(manifest_path.parent().expect("manifest parent")) - .expect("mkdir manifest"); - fs::write(&manifest_path, r#"{"name":"sample"}"#).expect("write manifest"); - fs::write(&skill_path, "---\ndescription: search\n---\n").expect("write skill"); - - assert_eq!( - plugin_namespace_for_root_uri( - &FileSystemEnvironmentAccessor::unrestricted(&LOCAL_FS), - &PathUri::from_abs_path(&plugin_root.abs()), - ) - .await, - Some("sample".to_string()) - ); - assert_eq!(find_plugin_manifest_path(&plugin_root), Some(manifest_path)); - } - - #[tokio::test] - async fn uses_name_from_cur_plugin_manifest_path() { - let tmp = tempdir().expect("tempdir"); - let plugin_root = tmp.path().join("plugins/sample"); - let skill_path = plugin_root.join("skills/search/SKILL.md"); - let manifest_path = plugin_root.join(ALTERNATE_PLUGIN_CUR_MANIFEST_RELATIVE_PATH); - - fs::create_dir_all(skill_path.parent().expect("parent")).expect("mkdir"); - fs::create_dir_all(manifest_path.parent().expect("manifest parent")) - .expect("mkdir manifest"); - fs::write(&manifest_path, r#"{"name":"sample"}"#).expect("write manifest"); - fs::write(&skill_path, "---\ndescription: search\n---\n").expect("write skill"); - - assert_eq!( - plugin_namespace_for_root_uri( - &FileSystemEnvironmentAccessor::unrestricted(&LOCAL_FS), - &PathUri::from_abs_path(&plugin_root.abs()), - ) - .await, - Some("sample".to_string()) - ); - assert_eq!(find_plugin_manifest_path(&plugin_root), Some(manifest_path)); - } - #[test] fn recognizes_schema_declared_root_plugin_manifest() { let tmp = tempdir().expect("tempdir"); @@ -349,8 +227,8 @@ mod tests { let tmp = tempdir().expect("tempdir"); let plugin_root = tmp.path().join("plugins/sample"); let codex_path = plugin_root.join(".codex-plugin/plugin.json"); - let claude_path = plugin_root.join(".claude-plugin/plugin.json"); - let cursor_path = plugin_root.join(".cursor-plugin/plugin.json"); + let claude_path = plugin_root.join(ALTERNATE_PLUGIN_CLA_MANIFEST_RELATIVE_PATH); + let cursor_path = plugin_root.join(ALTERNATE_PLUGIN_CUR_MANIFEST_RELATIVE_PATH); for path in [&codex_path, &claude_path, &cursor_path] { fs::create_dir_all(path.parent().expect("parent")).expect("mkdir"); fs::write(path, r#"{"name":"sample"}"#).expect("write manifest"); @@ -361,6 +239,11 @@ mod tests { Some(codex_path.clone()) ); fs::remove_file(codex_path).expect("remove Codex manifest"); - assert_eq!(find_plugin_manifest_path(&plugin_root), Some(claude_path)); + assert_eq!( + find_plugin_manifest_path(&plugin_root), + Some(claude_path.clone()) + ); + fs::remove_file(claude_path).expect("remove Claude manifest"); + assert_eq!(find_plugin_manifest_path(&plugin_root), Some(cursor_path)); } }