mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
1. Remove PUBLIC skills and introduce SYSTEM skills embedded in the binary and installed into $CODEX_HOME/skills/.system at startup. 2. Skills are now always enabled (feature flag removed). 3. Update skills/list to accept forceReload and plumb it through (not used by clients yet).
60 lines
1.9 KiB
Rust
60 lines
1.9 KiB
Rust
use std::collections::HashMap;
|
|
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
use std::sync::RwLock;
|
|
|
|
use crate::skills::SkillLoadOutcome;
|
|
use crate::skills::loader::load_skills_from_roots;
|
|
use crate::skills::loader::repo_skills_root;
|
|
use crate::skills::loader::system_skills_root;
|
|
use crate::skills::loader::user_skills_root;
|
|
use crate::skills::system::install_system_skills;
|
|
pub struct SkillsManager {
|
|
codex_home: PathBuf,
|
|
cache_by_cwd: RwLock<HashMap<PathBuf, SkillLoadOutcome>>,
|
|
}
|
|
|
|
impl SkillsManager {
|
|
pub fn new(codex_home: PathBuf) -> Self {
|
|
if let Err(err) = install_system_skills(&codex_home) {
|
|
tracing::error!("failed to install system skills: {err}");
|
|
}
|
|
|
|
Self {
|
|
codex_home,
|
|
cache_by_cwd: RwLock::new(HashMap::new()),
|
|
}
|
|
}
|
|
|
|
pub fn skills_for_cwd(&self, cwd: &Path) -> SkillLoadOutcome {
|
|
self.skills_for_cwd_with_options(cwd, false)
|
|
}
|
|
|
|
pub fn skills_for_cwd_with_options(&self, cwd: &Path, force_reload: bool) -> SkillLoadOutcome {
|
|
let cached = match self.cache_by_cwd.read() {
|
|
Ok(cache) => cache.get(cwd).cloned(),
|
|
Err(err) => err.into_inner().get(cwd).cloned(),
|
|
};
|
|
if !force_reload && let Some(outcome) = cached {
|
|
return outcome;
|
|
}
|
|
|
|
let mut roots = Vec::new();
|
|
if let Some(repo_root) = repo_skills_root(cwd) {
|
|
roots.push(repo_root);
|
|
}
|
|
roots.push(user_skills_root(&self.codex_home));
|
|
roots.push(system_skills_root(&self.codex_home));
|
|
let outcome = load_skills_from_roots(roots);
|
|
match self.cache_by_cwd.write() {
|
|
Ok(mut cache) => {
|
|
cache.insert(cwd.to_path_buf(), outcome.clone());
|
|
}
|
|
Err(err) => {
|
|
err.into_inner().insert(cwd.to_path_buf(), outcome.clone());
|
|
}
|
|
}
|
|
outcome
|
|
}
|
|
}
|