Simplify plugin skill root snapshot cache

This commit is contained in:
Matthew Zeng
2026-06-18 00:18:52 -07:00
parent 132972507a
commit 31491e461b
10 changed files with 80 additions and 156 deletions
+8 -8
View File
@@ -19,8 +19,8 @@ use codex_config::HooksFile;
use codex_config::types::McpServerConfig;
use codex_config::types::PluginConfig;
use codex_config::types::PluginMcpServerConfig;
use codex_core_skills::PluginSkillRootCache;
use codex_core_skills::SkillMetadata;
use codex_core_skills::SkillRootLoader;
use codex_core_skills::config_rules::SkillConfigRules;
use codex_core_skills::config_rules::resolve_disabled_skill_paths;
use codex_core_skills::config_rules::skill_config_rules_from_stack;
@@ -72,7 +72,7 @@ enum PluginLoadScope<'a> {
AllCapabilities {
restriction_product: Option<Product>,
skill_config_rules: &'a SkillConfigRules,
skill_root_loader: &'a SkillRootLoader,
plugin_skill_root_cache: &'a PluginSkillRootCache,
},
HooksOnly,
}
@@ -114,7 +114,7 @@ pub(crate) async fn load_plugins_from_layer_stack(
config_layer_stack: &ConfigLayerStack,
extra_plugins: HashMap<String, PluginConfig>,
store: &PluginStore,
skill_root_loader: &SkillRootLoader,
plugin_skill_root_cache: &PluginSkillRootCache,
restriction_product: Option<Product>,
prefer_remote_curated_conflicts: bool,
) -> Vec<LoadedPlugin<McpServerConfig>> {
@@ -127,7 +127,7 @@ pub(crate) async fn load_plugins_from_layer_stack(
PluginLoadScope::AllCapabilities {
restriction_product,
skill_config_rules: &skill_config_rules,
skill_root_loader,
plugin_skill_root_cache,
},
)
.await
@@ -716,7 +716,7 @@ async fn load_plugin(
PluginLoadScope::AllCapabilities {
restriction_product,
skill_config_rules,
skill_root_loader,
plugin_skill_root_cache,
} => {
loaded_plugin.manifest_name = Some(manifest.display_name().to_string());
loaded_plugin.manifest_description = manifest.description.clone();
@@ -727,7 +727,7 @@ async fn load_plugin(
&manifest,
*restriction_product,
skill_config_rules,
skill_root_loader,
plugin_skill_root_cache,
)
.await;
let has_enabled_skills = resolved_skills.has_enabled_skills();
@@ -796,7 +796,7 @@ pub async fn load_plugin_skills(
manifest: &PluginManifest,
restriction_product: Option<Product>,
skill_config_rules: &SkillConfigRules,
skill_root_loader: &SkillRootLoader,
plugin_skill_root_cache: &PluginSkillRootCache,
) -> ResolvedPluginSkills {
let roots = plugin_skill_roots(plugin_root, &manifest.paths)
.into_iter()
@@ -809,7 +809,7 @@ pub async fn load_plugin_skills(
plugin_root: Some(plugin_root.clone()),
})
.collect::<Vec<_>>();
let outcome = skill_root_loader.load_skills_from_roots(roots).await;
let outcome = plugin_skill_root_cache.load_skills_from_roots(roots).await;
let had_errors = !outcome.errors.is_empty();
let skills = outcome
.skills
+3 -3
View File
@@ -5,7 +5,7 @@ use codex_config::ConfigLayerEntry;
use codex_config::ConfigLayerSource;
use codex_config::ConfigRequirements;
use codex_config::ConfigRequirementsToml;
use codex_core_skills::SkillRootLoader;
use codex_core_skills::PluginSkillRootCache;
use codex_plugin::PluginId;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
@@ -156,13 +156,13 @@ enabled = true
)
.expect("valid config layer stack");
let store = PluginStore::new(temp_dir.path().to_path_buf());
let skill_root_loader = SkillRootLoader::default();
let plugin_skill_root_cache = PluginSkillRootCache::default();
let full = load_plugins_from_layer_stack(
&stack,
HashMap::new(),
&store,
&skill_root_loader,
&plugin_skill_root_cache,
Some(Product::Codex),
/*prefer_remote_curated_conflicts*/ false,
)
+10 -10
View File
@@ -59,8 +59,8 @@ use codex_config::set_user_plugin_enabled;
use codex_config::types::PluginConfig;
use codex_config::types::ToolSuggestDisabledTool;
use codex_config::types::ToolSuggestDiscoverableType;
use codex_core_skills::PluginSkillRootCache;
use codex_core_skills::SkillMetadata;
use codex_core_skills::SkillRootLoader;
use codex_core_skills::config_rules::SkillConfigRules;
use codex_core_skills::config_rules::skill_config_rules_from_stack;
use codex_hooks::plugin_hook_declarations;
@@ -355,7 +355,7 @@ pub struct PluginsManager {
// Keep the cache auth-independent so auth changes only need to resolve capabilities again.
loaded_plugins_cache: RwLock<LoadedPluginsCache>,
loaded_plugins_load_semaphore: Semaphore,
skill_root_loader: Arc<SkillRootLoader>,
plugin_skill_root_cache: Arc<PluginSkillRootCache>,
remote_installed_plugins_cache: RwLock<Option<Vec<RemoteInstalledPlugin>>>,
remote_installed_plugins_cache_refresh_state: RwLock<RemoteInstalledPluginsCacheRefreshState>,
global_remote_catalog_cache_refresh_state: RwLock<GlobalRemoteCatalogCacheRefreshState>,
@@ -412,7 +412,7 @@ impl PluginsManager {
non_curated_cache_refresh_state: RwLock::new(NonCuratedCacheRefreshState::default()),
loaded_plugins_cache: RwLock::new(LoadedPluginsCache::default()),
loaded_plugins_load_semaphore: Semaphore::new(/*permits*/ 1),
skill_root_loader: Arc::new(SkillRootLoader::default()),
plugin_skill_root_cache: Arc::new(PluginSkillRootCache::default()),
remote_installed_plugins_cache: RwLock::new(None),
remote_installed_plugins_cache_refresh_state: RwLock::new(
RemoteInstalledPluginsCacheRefreshState::default(),
@@ -438,9 +438,9 @@ impl PluginsManager {
true
}
/// Returns the loader whose plugin-root snapshots are populated while loading plugins.
pub fn skill_root_loader(&self) -> Arc<SkillRootLoader> {
Arc::clone(&self.skill_root_loader)
/// Returns the shared cache populated while loading plugin skill roots.
pub fn plugin_skill_root_cache(&self) -> Arc<PluginSkillRootCache> {
Arc::clone(&self.plugin_skill_root_cache)
}
pub fn auth_mode(&self) -> Option<AuthMode> {
@@ -513,7 +513,7 @@ impl PluginsManager {
&config.config_layer_stack,
self.remote_installed_plugin_configs(),
&self.store,
self.skill_root_loader.as_ref(),
self.plugin_skill_root_cache.as_ref(),
self.restriction_product,
config.remote_plugin_enabled,
)
@@ -560,7 +560,7 @@ impl PluginsManager {
}
fn clear_loaded_plugins_cache(&self) {
self.skill_root_loader.clear_cache();
self.plugin_skill_root_cache.clear_cache();
let mut cache = match self.loaded_plugins_cache.write() {
Ok(cache) => cache,
Err(err) => err.into_inner(),
@@ -582,7 +582,7 @@ impl PluginsManager {
config_layer_stack,
self.remote_installed_plugin_configs(),
&self.store,
self.skill_root_loader.as_ref(),
self.plugin_skill_root_cache.as_ref(),
self.restriction_product,
config.remote_plugin_enabled,
)
@@ -1607,7 +1607,7 @@ impl PluginsManager {
&codex_core_skills::config_rules::skill_config_rules_from_stack(
&config.config_layer_stack,
),
self.skill_root_loader.as_ref(),
self.plugin_skill_root_cache.as_ref(),
)
.await;
let plugin_data_root = self.store.plugin_data_root(&plugin_id);
+5 -5
View File
@@ -34,7 +34,7 @@ use codex_config::McpServerConfig;
use codex_config::McpServerOAuthConfig;
use codex_config::McpServerToolConfig;
use codex_config::types::McpServerTransportConfig;
use codex_core_skills::SkillRootLoader;
use codex_core_skills::PluginSkillRootCache;
use codex_core_skills::config_rules::SkillConfigRules;
use codex_login::CodexAuth;
use codex_plugin::AppDeclaration;
@@ -1467,7 +1467,7 @@ async fn load_plugin_skills_dedupes_overlapping_manifest_roots() {
interface: None,
};
let plugin_id = PluginId::parse("sample@test").expect("plugin id should parse");
let skill_root_loader = SkillRootLoader::default();
let plugin_skill_root_cache = PluginSkillRootCache::default();
let resolved = load_plugin_skills(
&plugin_root,
@@ -1475,7 +1475,7 @@ async fn load_plugin_skills_dedupes_overlapping_manifest_roots() {
&manifest,
/*restriction_product*/ None,
&SkillConfigRules::default(),
&skill_root_loader,
&plugin_skill_root_cache,
)
.await;
@@ -4823,12 +4823,12 @@ async fn load_plugins_ignores_project_config_files() {
)
.expect("config layer stack should build");
let skill_root_loader = SkillRootLoader::default();
let plugin_skill_root_cache = PluginSkillRootCache::default();
let plugins = load_plugins_from_layer_stack(
&stack,
std::collections::HashMap::new(),
&PluginStore::new(codex_home.path().to_path_buf()),
&skill_root_loader,
&plugin_skill_root_cache,
Some(Product::Codex),
/*prefer_remote_curated_conflicts*/ false,
)