Allow callers to disable executor skills per environment (#46015)

## Why

Executor skill discovery enabled every discovered skill, with no provider option for callers to disable selected skills.

## What changed

Add `ExecutorSkillProvider::with_disabled_skill_paths` to accept `SKILL.md` paths grouped by environment ID. Mark matching catalog entries disabled in both discovery routes so they are omitted from model context. Skills remain enabled by default, and paths configured for another environment have no effect.

## Testing

Extend catalog tests to cover default enablement, matching paths, and environment isolation across both discovery routes. Add a model-context snapshot test confirming that an active skill appears while a disabled skill is omitted.

GitOrigin-RevId: 7426eb94566db2bcf7e49a5dee28673ab743ad25
This commit is contained in:
vkg-oai authored and copyberry committed 2026-09-16 20:05:37 +00:00
1 parent a2f62e88cf
commit fc2ea82e7e
4 files changed
+312 -2

No files matched your search

+26 -1
View File
@@ -1,3 +1,5 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
use codex_exec_server::EnvironmentManager;
@@ -34,6 +36,7 @@ use crate::provider::SkillSearchRequest;
pub struct ExecutorSkillProvider {
environment_manager: Arc<EnvironmentManager>,
restriction_product: Option<Product>,
disabled_skill_paths: HashMap<String, HashSet<PathUri>>,
}
impl ExecutorSkillProvider {
@@ -44,8 +47,20 @@ impl ExecutorSkillProvider {
Self {
environment_manager,
restriction_product,
disabled_skill_paths: HashMap::new(),
}
}
/// Applies caller-owned disablement to executor catalogs. Paths identify SKILL.md
/// documents in their executor's filesystem; other executors are unaffected.
/// By default, all discovered skills remain enabled.
pub fn with_disabled_skill_paths(
mut self,
disabled_skill_paths: HashMap<String, HashSet<PathUri>>,
) -> Self {
self.disabled_skill_paths = disabled_skill_paths;
self
}
}
pub(crate) fn attribute_executor_plugins(
@@ -113,6 +128,7 @@ impl SkillProvider for ExecutorSkillProvider {
path,
environment_id,
/*instructions*/ None,
&self.disabled_skill_paths,
));
}
}
@@ -223,6 +239,7 @@ impl ExecutorSkillProvider {
path,
environment_id,
Some(skill.instructions),
&self.disabled_skill_paths,
));
}
}
@@ -237,6 +254,7 @@ fn catalog_entry_from_skill(
selected_root_path: &PathUri,
environment_id: &str,
instructions: Option<String>,
disabled_skill_paths: &HashMap<String, HashSet<PathUri>>,
) -> SkillCatalogEntry {
let handle_prefix = format!("skill://{selected_root_id}/");
let alias_root = format!(
@@ -269,7 +287,7 @@ fn catalog_entry_from_skill(
skill.path_to_skills_md.clone(),
),
};
let entry = SkillCatalogEntry::new(
let mut entry = SkillCatalogEntry::new(
SkillPackageId(package),
authority,
skill.name.clone(),
@@ -281,6 +299,13 @@ fn catalog_entry_from_skill(
.with_alias_root(alias_root)
.with_dependencies(skill.dependencies.clone());
if disabled_skill_paths
.get(environment_id)
.is_some_and(|paths| paths.contains(&skill.path_to_skills_md))
{
entry = entry.disabled();
}
if skill.allows_implicit_invocation() {
entry
} else {
@@ -613,7 +613,7 @@ async fn executor_discovery_routes_produce_equivalent_catalog_metadata() {
.snapshot(&executor_roots, &Default::default())
.await;
let bundled = provider
.list(query(Some(discovery)))
.list(query(Some(discovery.clone())))
.await
.expect("list bundled executor skills");
@@ -661,6 +661,7 @@ async fn executor_discovery_routes_produce_equivalent_catalog_metadata() {
.find(|entry| entry.name == "catalog:repaired")
.expect("repaired skill");
assert_eq!(repaired.description, "Build for AWS: ECS");
assert!(repaired.prompt_visible);
let invalid_metadata = direct
.entries
.iter()
@@ -668,6 +669,45 @@ async fn executor_discovery_routes_produce_equivalent_catalog_metadata() {
.expect("invalid metadata skill");
assert_eq!(invalid_metadata.dependencies, None);
assert!(direct.entries.iter().all(|entry| entry.enabled));
// Match the discovery path, including aliases such as macOS's /var -> /private/var.
let disabled_path = PathUri::from_host_native_path(&repaired_skill).expect("skill URI");
for environment_id in ["local", "other-executor"] {
let configured = provider.clone().with_disabled_skill_paths(HashMap::from([(
environment_id.to_string(),
std::collections::HashSet::from([disabled_path.clone()]),
)]));
let mut expected = direct.clone();
if environment_id == "local" {
expected
.entries
.iter_mut()
.find(|entry| entry.name == "catalog:repaired")
.expect("repaired skill")
.enabled = false;
}
for discovery in [None, Some(discovery.clone())] {
let actual = configured
.list(query(discovery))
.await
.expect("list configured executor skills");
assert_eq!(comparable_entries(&actual), comparable_entries(&expected));
assert_eq!(actual.warnings, expected.warnings);
let visible_names = actual
.entries
.iter()
.filter(|entry| entry.enabled && entry.prompt_visible)
.map(|entry| entry.name.as_str())
.collect::<Vec<_>>();
let expected_visible_names = if environment_id == "local" {
vec!["catalog:invalid-metadata"]
} else {
vec!["catalog:invalid-metadata", "catalog:repaired"]
};
assert_eq!(visible_names, expected_visible_names);
}
}
std::fs::remove_dir_all(test_root).expect("remove skill directory");
}