-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Load executor skills without host path conversion #29626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d41611e
Load executor skills with PathUri
jif-oai bb7b1cf
Share URI-native skill discovery
jif-oai f3b6dcc
Preserve selected skill root paths
jif-oai 4ed0594
Drop redundant executor skill path test
jif-oai 6c4df90
Fix goal test Bazel recursion limit
jif-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| use std::io; | ||
|
|
||
| use codex_exec_server::ExecutorFileSystem; | ||
| use codex_protocol::protocol::Product; | ||
| use codex_utils_path_uri::PathUri; | ||
| use codex_utils_plugins::plugin_namespace_for_skill_uri; | ||
|
|
||
| use crate::model::SkillDependencies; | ||
| use crate::model::SkillPolicy; | ||
|
|
||
| use super::MAX_QUALIFIED_NAME_LEN; | ||
| use super::ParsedSkillFrontmatter; | ||
| use super::SKILLS_METADATA_DIR; | ||
| use super::SKILLS_METADATA_FILENAME; | ||
| use super::SkillMetadataFile; | ||
| use super::SymlinkPolicy; | ||
| use super::discover_skills_under_root; | ||
| use super::parse_skill_frontmatter_metadata_inner; | ||
| use super::resolve_dependencies; | ||
| use super::resolve_policy; | ||
| use super::sanitize_single_line; | ||
| use super::validate_len; | ||
|
|
||
| /// URI-native metadata for one skill owned by an execution environment. | ||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| pub struct EnvironmentSkillMetadata { | ||
| pub path_to_skills_md: PathUri, | ||
| pub name: String, | ||
| pub description: String, | ||
| pub short_description: Option<String>, | ||
| pub dependencies: Option<SkillDependencies>, | ||
| pub policy: Option<SkillPolicy>, | ||
| } | ||
|
|
||
| impl EnvironmentSkillMetadata { | ||
| pub fn allows_implicit_invocation(&self) -> bool { | ||
| self.policy | ||
| .as_ref() | ||
| .and_then(|policy| policy.allow_implicit_invocation) | ||
| .unwrap_or(true) | ||
| } | ||
|
|
||
| fn matches_product_restriction(&self, restriction_product: Option<Product>) -> bool { | ||
| match &self.policy { | ||
| Some(policy) => { | ||
| policy.products.is_empty() | ||
| || restriction_product.is_some_and(|product| { | ||
| product.matches_product_restriction(&policy.products) | ||
| }) | ||
| } | ||
| None => true, | ||
| } | ||
| } | ||
|
|
||
| async fn parse(file_system: &dyn ExecutorFileSystem, path: &PathUri) -> Result<Self, String> { | ||
| let contents = file_system | ||
| .read_file_text(path, /*sandbox*/ None) | ||
| .await | ||
| .map_err(|err| format!("failed to read file: {err}"))?; | ||
| let ParsedSkillFrontmatter { | ||
| name: base_name, | ||
| description, | ||
| short_description, | ||
| } = parse_skill_frontmatter_metadata_inner(&contents, || default_skill_name(path)) | ||
| .map_err(|err| err.to_string())?; | ||
| let name = plugin_namespace_for_skill_uri(file_system, path) | ||
| .await | ||
| .map(|namespace| format!("{namespace}:{base_name}")) | ||
| .unwrap_or(base_name); | ||
| validate_len(&name, MAX_QUALIFIED_NAME_LEN, "qualified name") | ||
| .map_err(|err| err.to_string())?; | ||
| let (dependencies, policy) = load_skill_metadata(file_system, path).await; | ||
|
|
||
| Ok(Self { | ||
| path_to_skills_md: path.clone(), | ||
| name, | ||
| description, | ||
| short_description, | ||
| dependencies, | ||
| policy, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Default)] | ||
| pub struct EnvironmentSkillLoadOutcome { | ||
| pub skills: Vec<EnvironmentSkillMetadata>, | ||
| pub warnings: Vec<String>, | ||
| } | ||
|
|
||
| /// Discovers skills without converting environment-owned paths to host paths. | ||
| pub async fn load_environment_skills_from_root( | ||
| file_system: &dyn ExecutorFileSystem, | ||
| root: &PathUri, | ||
| restriction_product: Option<Product>, | ||
| ) -> EnvironmentSkillLoadOutcome { | ||
| let mut outcome = EnvironmentSkillLoadOutcome::default(); | ||
| let discovery = | ||
| discover_skills_under_root(file_system, root, SymlinkPolicy::FollowDirectories).await; | ||
| outcome.warnings.extend(discovery.warnings); | ||
| for path in discovery.skill_files { | ||
| match EnvironmentSkillMetadata::parse(file_system, &path).await { | ||
| Ok(skill) if skill.matches_product_restriction(restriction_product) => { | ||
| outcome.skills.push(skill); | ||
| } | ||
| Ok(_) => {} | ||
| Err(message) => outcome.warnings.push(format!( | ||
| "Failed to load environment skill at {path}: {message}" | ||
| )), | ||
| } | ||
| } | ||
| outcome.skills.sort_by(|left, right| { | ||
| left.name.cmp(&right.name).then_with(|| { | ||
| left.path_to_skills_md | ||
| .to_string() | ||
| .cmp(&right.path_to_skills_md.to_string()) | ||
| }) | ||
| }); | ||
| outcome | ||
| } | ||
|
|
||
| async fn load_skill_metadata( | ||
| file_system: &dyn ExecutorFileSystem, | ||
| skill_path: &PathUri, | ||
| ) -> (Option<SkillDependencies>, Option<SkillPolicy>) { | ||
| let Some(skill_dir) = skill_path.parent() else { | ||
| return (None, None); | ||
| }; | ||
| let Ok(metadata_path) = | ||
| skill_dir.join(&format!("{SKILLS_METADATA_DIR}/{SKILLS_METADATA_FILENAME}")) | ||
| else { | ||
| return (None, None); | ||
| }; | ||
| match file_system | ||
| .get_metadata(&metadata_path, /*sandbox*/ None) | ||
| .await | ||
| { | ||
| Ok(metadata) if metadata.is_file => {} | ||
| Ok(_) => return (None, None), | ||
| Err(error) if error.kind() == io::ErrorKind::NotFound => return (None, None), | ||
| Err(error) => { | ||
| tracing::warn!("ignoring {metadata_path}: failed to stat metadata: {error}"); | ||
| return (None, None); | ||
| } | ||
| } | ||
| let contents = match file_system | ||
| .read_file_text(&metadata_path, /*sandbox*/ None) | ||
| .await | ||
| { | ||
| Ok(contents) => contents, | ||
| Err(error) => { | ||
| tracing::warn!("ignoring {metadata_path}: failed to read metadata: {error}"); | ||
| return (None, None); | ||
| } | ||
| }; | ||
| let parsed: SkillMetadataFile = match serde_yaml::from_str(&contents) { | ||
| Ok(parsed) => parsed, | ||
| Err(error) => { | ||
| tracing::warn!("ignoring {metadata_path}: invalid metadata: {error}"); | ||
| return (None, None); | ||
| } | ||
| }; | ||
|
|
||
| ( | ||
| resolve_dependencies(parsed.dependencies), | ||
| resolve_policy(parsed.policy), | ||
| ) | ||
| } | ||
|
|
||
| fn default_skill_name(path: &PathUri) -> String { | ||
| path.parent() | ||
| .and_then(|parent| parent.basename()) | ||
| .map(|name| sanitize_single_line(&name)) | ||
| .filter(|name| !name.is_empty()) | ||
| .unwrap_or_else(|| "skill".to_string()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[path = "environment_tests.rs"] | ||
| mod tests; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| use std::fs; | ||
|
|
||
| use codex_exec_server::LOCAL_FS; | ||
| use codex_protocol::protocol::Product; | ||
| use codex_utils_path_uri::PathUri; | ||
| use pretty_assertions::assert_eq; | ||
| use tempfile::tempdir; | ||
|
|
||
| use crate::model::SkillDependencies; | ||
| use crate::model::SkillPolicy; | ||
| use crate::model::SkillToolDependency; | ||
|
|
||
| use super::EnvironmentSkillMetadata; | ||
| use super::load_environment_skills_from_root; | ||
|
|
||
| #[tokio::test] | ||
| async fn loads_plugin_namespace_dependencies_and_policy() { | ||
| let root = tempdir().expect("tempdir"); | ||
| let skill_dir = root.path().join("skills/deploy"); | ||
| fs::create_dir_all(root.path().join(".codex-plugin")).expect("manifest dir"); | ||
| fs::create_dir_all(skill_dir.join("agents")).expect("metadata dir"); | ||
| fs::write( | ||
| root.path().join(".codex-plugin/plugin.json"), | ||
| r#"{"name":"demo-plugin"}"#, | ||
| ) | ||
| .expect("manifest"); | ||
| fs::write( | ||
| skill_dir.join("SKILL.md"), | ||
| "---\nname: deploy\ndescription: Deploy the service.\n---\n", | ||
| ) | ||
| .expect("skill"); | ||
| fs::write( | ||
| skill_dir.join("agents/openai.yaml"), | ||
| r#" | ||
| dependencies: | ||
| tools: | ||
| - type: mcp | ||
| value: deploy-server | ||
| description: Deploy MCP | ||
| policy: | ||
| allow_implicit_invocation: false | ||
| products: [codex] | ||
| "#, | ||
| ) | ||
| .expect("metadata"); | ||
|
|
||
| let root_uri = PathUri::from_host_native_path(root.path()).expect("root URI"); | ||
| let outcome = | ||
| load_environment_skills_from_root(LOCAL_FS.as_ref(), &root_uri, Some(Product::Codex)).await; | ||
|
|
||
| assert_eq!( | ||
| outcome.skills, | ||
| vec![EnvironmentSkillMetadata { | ||
| path_to_skills_md: PathUri::from_host_native_path(skill_dir.join("SKILL.md"),).unwrap(), | ||
| name: "demo-plugin:deploy".to_string(), | ||
| description: "Deploy the service.".to_string(), | ||
| short_description: None, | ||
| dependencies: Some(SkillDependencies { | ||
| tools: vec![SkillToolDependency { | ||
| r#type: "mcp".to_string(), | ||
| value: "deploy-server".to_string(), | ||
| description: Some("Deploy MCP".to_string()), | ||
| transport: None, | ||
| command: None, | ||
| url: None, | ||
| }], | ||
| }), | ||
| policy: Some(SkillPolicy { | ||
| allow_implicit_invocation: Some(false), | ||
| products: vec![Product::Codex], | ||
| }), | ||
| }] | ||
| ); | ||
| let filtered = | ||
| load_environment_skills_from_root(LOCAL_FS.as_ref(), &root_uri, Some(Product::Chatgpt)) | ||
| .await; | ||
| assert!(filtered.skills.is_empty()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #![recursion_limit = "256"] | ||
| #![allow(clippy::expect_used)] | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.