mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
## Why After #28918, selected skill roots are `PathUri`, but the executor skill provider still converts them to the app-server host's `AbsolutePathBuf`. A foreign Windows root therefore cannot be discovered by a Unix host, and the inverse has the same problem. This PR keeps executor skill discovery and reads on the filesystem that owns the selected root while reusing the existing skill rules. ## What changed - Generalize the existing skill traversal to operate on `PathUri` through `ExecutorFileSystem`, preserving its depth, directory, symlink, and sibling-metadata concurrency behavior. - Add a small environment skill loader that reuses the shared discovery, frontmatter validation, dependency parsing, product policy, and prompt-visibility rules. - Keep the environment id and entrypoint `PathUri` in the skill catalog, then route `skills.read` back through the same environment filesystem. - Preserve the executor's path convention when deriving catalog handles, including literal backslashes in POSIX filenames. - Resolve plugin namespaces from nearby manifests through URI-native filesystem reads. - Cover foreign Windows roots, executor-owned reads, namespaces, metadata, policy, and path identity. ```text selected root (PathUri) | v shared discovery over ExecutorFileSystem | v environment-bound catalog entry --skills.read--> same ExecutorFileSystem ``` No second filesystem abstraction or duplicate traversal implementation is introduced. ## Stack 1. #29614 — add lexical `PathUri` containment. 2. #29620 — share URI-native manifest path resolution. 3. #28918 — keep selected plugin roots and resources URI-native. 4. **This PR** — load executor skills without host path conversion. 5. #29628 — resolve executor MCP working directories without host path conversion.
167 lines
6.1 KiB
Rust
167 lines
6.1 KiB
Rust
use std::sync::Arc;
|
|
|
|
use codex_core_skills::loader::EnvironmentSkillMetadata;
|
|
use codex_core_skills::loader::load_environment_skills_from_root;
|
|
use codex_exec_server::EnvironmentManager;
|
|
use codex_protocol::capabilities::CapabilityRootLocation;
|
|
use codex_protocol::protocol::Product;
|
|
use codex_utils_path_uri::PathConvention;
|
|
|
|
use crate::catalog::SkillAuthority;
|
|
use crate::catalog::SkillCatalog;
|
|
use crate::catalog::SkillCatalogEntry;
|
|
use crate::catalog::SkillPackageId;
|
|
use crate::catalog::SkillProviderError;
|
|
use crate::catalog::SkillReadResult;
|
|
use crate::catalog::SkillResourceId;
|
|
use crate::catalog::SkillSearchResult;
|
|
use crate::catalog::SkillSourceKind;
|
|
use crate::provider::SkillListQuery;
|
|
use crate::provider::SkillProvider;
|
|
use crate::provider::SkillProviderFuture;
|
|
use crate::provider::SkillReadRequest;
|
|
use crate::provider::SkillSearchRequest;
|
|
|
|
/// Discovers and reads skills through the filesystem owned by an execution environment.
|
|
#[derive(Clone, Debug)]
|
|
pub struct ExecutorSkillProvider {
|
|
environment_manager: Arc<EnvironmentManager>,
|
|
restriction_product: Option<Product>,
|
|
}
|
|
|
|
impl ExecutorSkillProvider {
|
|
pub fn new_with_restriction_product(
|
|
environment_manager: Arc<EnvironmentManager>,
|
|
restriction_product: Option<Product>,
|
|
) -> Self {
|
|
Self {
|
|
environment_manager,
|
|
restriction_product,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl SkillProvider for ExecutorSkillProvider {
|
|
fn list(&self, query: SkillListQuery) -> SkillProviderFuture<'_, SkillCatalog> {
|
|
Box::pin(async move {
|
|
let mut catalog = SkillCatalog::default();
|
|
for selected_root in query.executor_roots {
|
|
let selected_root_id = selected_root.id;
|
|
let CapabilityRootLocation::Environment {
|
|
environment_id,
|
|
path,
|
|
} = selected_root.location;
|
|
let authority =
|
|
SkillAuthority::new(SkillSourceKind::Executor, selected_root_id.clone());
|
|
let Some(environment) = self.environment_manager.get_environment(&environment_id)
|
|
else {
|
|
catalog.warnings.push(format!(
|
|
"Selected capability root `{selected_root_id}` references unavailable environment `{environment_id}`."
|
|
));
|
|
continue;
|
|
};
|
|
let file_system = environment.get_filesystem();
|
|
let outcome = load_environment_skills_from_root(
|
|
file_system.as_ref(),
|
|
&path,
|
|
self.restriction_product,
|
|
)
|
|
.await;
|
|
catalog.warnings.extend(outcome.warnings);
|
|
for skill in outcome.skills {
|
|
catalog.push_entry(catalog_entry_from_skill(
|
|
&skill,
|
|
authority.clone(),
|
|
&selected_root_id,
|
|
&environment_id,
|
|
));
|
|
}
|
|
}
|
|
|
|
Ok(catalog)
|
|
})
|
|
}
|
|
|
|
fn read(&self, request: SkillReadRequest) -> SkillProviderFuture<'_, SkillReadResult> {
|
|
Box::pin(async move {
|
|
if request.authority.kind != SkillSourceKind::Executor {
|
|
return Err(SkillProviderError::new(format!(
|
|
"executor skill provider cannot read {} resources",
|
|
request.authority.kind
|
|
)));
|
|
}
|
|
if request.package.0 != request.resource.as_str() {
|
|
return Err(SkillProviderError::new(
|
|
"executor skill resource does not match its package",
|
|
));
|
|
}
|
|
let Some((environment_id, resource_path)) = request.resource.environment_path() else {
|
|
return Err(SkillProviderError::new(
|
|
"executor skill resource is not bound to an environment",
|
|
));
|
|
};
|
|
let Some(environment) = self.environment_manager.get_environment(environment_id) else {
|
|
return Err(SkillProviderError::new(format!(
|
|
"executor skill resource references unavailable environment `{environment_id}`"
|
|
)));
|
|
};
|
|
let contents = environment
|
|
.get_filesystem()
|
|
.read_file_text(resource_path, /*sandbox*/ None)
|
|
.await
|
|
.map_err(|err| {
|
|
SkillProviderError::new(format!(
|
|
"failed to read executor skill resource {}: {err}",
|
|
request.resource.as_str()
|
|
))
|
|
})?;
|
|
|
|
Ok(SkillReadResult {
|
|
resource: request.resource,
|
|
contents,
|
|
})
|
|
})
|
|
}
|
|
|
|
fn search(&self, _request: SkillSearchRequest) -> SkillProviderFuture<'_, SkillSearchResult> {
|
|
Box::pin(async { Ok(SkillSearchResult::default()) })
|
|
}
|
|
}
|
|
|
|
fn catalog_entry_from_skill(
|
|
skill: &EnvironmentSkillMetadata,
|
|
authority: SkillAuthority,
|
|
selected_root_id: &str,
|
|
environment_id: &str,
|
|
) -> SkillCatalogEntry {
|
|
let skill_path = skill.path_to_skills_md.inferred_native_path_string();
|
|
let normalized_path = match skill.path_to_skills_md.infer_path_convention() {
|
|
Some(PathConvention::Windows) => skill_path.replace('\\', "/"),
|
|
Some(PathConvention::Posix) | None => skill_path,
|
|
};
|
|
let display_path = format!(
|
|
"skill://{selected_root_id}/{}",
|
|
normalized_path.trim_start_matches('/')
|
|
);
|
|
let entry = SkillCatalogEntry::new(
|
|
SkillPackageId(display_path.clone()),
|
|
authority,
|
|
skill.name.clone(),
|
|
skill.description.clone(),
|
|
SkillResourceId::environment(
|
|
display_path.clone(),
|
|
environment_id,
|
|
skill.path_to_skills_md.clone(),
|
|
),
|
|
)
|
|
.with_short_description(skill.short_description.clone())
|
|
.with_display_path(display_path)
|
|
.with_dependencies(skill.dependencies.clone());
|
|
|
|
if skill.allows_implicit_invocation() {
|
|
entry
|
|
} else {
|
|
entry.hidden_from_prompt()
|
|
}
|
|
}
|