feat: 添加对 user_openclaw 技能源的支持,更新相关描述和逻辑

This commit is contained in:
oudecheng 2026-05-09 14:38:06 +08:00
parent ba0e1c2473
commit e0a7f67dab
3 changed files with 64 additions and 4 deletions

View File

@ -72,6 +72,7 @@ fn default_skills_sources() -> Vec<String> {
vec![ vec![
"user".to_string(), "user".to_string(),
"user_agent".to_string(), "user_agent".to_string(),
"user_openclaw".to_string(),
"project".to_string(), "project".to_string(),
"project_agent".to_string(), "project_agent".to_string(),
"project_openclaw".to_string(), "project_openclaw".to_string(),
@ -893,6 +894,7 @@ mod tests {
vec![ vec![
"user".to_string(), "user".to_string(),
"user_agent".to_string(), "user_agent".to_string(),
"user_openclaw".to_string(),
"project".to_string(), "project".to_string(),
"project_agent".to_string(), "project_agent".to_string(),
"project_openclaw".to_string(), "project_openclaw".to_string(),

View File

@ -28,6 +28,7 @@ pub struct Skill {
pub enum SkillSource { pub enum SkillSource {
User, User,
UserAgent, UserAgent,
UserOpenclaw,
Project, Project,
ProjectAgent, ProjectAgent,
ProjectOpenclaw, ProjectOpenclaw,
@ -328,6 +329,7 @@ impl SkillSource {
match self { match self {
SkillSource::User => "user", SkillSource::User => "user",
SkillSource::UserAgent => "user_agent", SkillSource::UserAgent => "user_agent",
SkillSource::UserOpenclaw => "user_openclaw",
SkillSource::Project => "project", SkillSource::Project => "project",
SkillSource::ProjectAgent => "project_agent", SkillSource::ProjectAgent => "project_agent",
SkillSource::ProjectOpenclaw => "project_openclaw", SkillSource::ProjectOpenclaw => "project_openclaw",
@ -557,6 +559,11 @@ fn source_order(sources: &[String]) -> Vec<SkillSource> {
result.push(SkillSource::UserAgent); result.push(SkillSource::UserAgent);
} }
} }
"user_openclaw" => {
if !result.contains(&SkillSource::UserOpenclaw) {
result.push(SkillSource::UserOpenclaw);
}
}
"project" => { "project" => {
if !result.contains(&SkillSource::Project) { if !result.contains(&SkillSource::Project) {
result.push(SkillSource::Project); result.push(SkillSource::Project);
@ -582,6 +589,7 @@ fn source_order(sources: &[String]) -> Vec<SkillSource> {
vec![ vec![
SkillSource::User, SkillSource::User,
SkillSource::UserAgent, SkillSource::UserAgent,
SkillSource::UserOpenclaw,
SkillSource::Project, SkillSource::Project,
SkillSource::ProjectAgent, SkillSource::ProjectAgent,
SkillSource::ProjectOpenclaw, SkillSource::ProjectOpenclaw,
@ -619,22 +627,34 @@ fn project_skill_state_path(cwd: &Path) -> PathBuf {
cwd.join(".picobot").join("skill-state.json") cwd.join(".picobot").join("skill-state.json")
} }
fn home_dir() -> Option<PathBuf> {
// First check HOME environment variable (useful for testing)
std::env::var_os("HOME")
.map(PathBuf::from)
.or_else(|| dirs::home_dir())
}
fn user_skills_root() -> Option<PathBuf> { fn user_skills_root() -> Option<PathBuf> {
dirs::home_dir().map(|p| p.join(".picobot").join("skills")) home_dir().map(|p| p.join(".picobot").join("skills"))
} }
fn user_skill_state_path() -> Option<PathBuf> { fn user_skill_state_path() -> Option<PathBuf> {
dirs::home_dir().map(|p| p.join(".picobot").join("skill-state.json")) home_dir().map(|p| p.join(".picobot").join("skill-state.json"))
} }
fn user_agent_skills_root() -> Option<PathBuf> { fn user_agent_skills_root() -> Option<PathBuf> {
dirs::home_dir().map(|p| p.join(".agents").join("skills")) home_dir().map(|p| p.join(".agents").join("skills"))
}
fn user_openclaw_skills_root() -> Option<PathBuf> {
home_dir().map(|p| p.join(".openclaw").join("skills"))
} }
fn source_root(source: SkillSource, cwd: &Path) -> Option<PathBuf> { fn source_root(source: SkillSource, cwd: &Path) -> Option<PathBuf> {
match source { match source {
SkillSource::User => user_skills_root(), SkillSource::User => user_skills_root(),
SkillSource::UserAgent => user_agent_skills_root(), SkillSource::UserAgent => user_agent_skills_root(),
SkillSource::UserOpenclaw => user_openclaw_skills_root(),
SkillSource::Project => Some(cwd.join(".picobot").join("skills")), SkillSource::Project => Some(cwd.join(".picobot").join("skills")),
SkillSource::ProjectAgent => Some(project_agent_skills_root(cwd)), SkillSource::ProjectAgent => Some(project_agent_skills_root(cwd)),
SkillSource::ProjectOpenclaw => Some(project_openclaw_skills_root(cwd)), SkillSource::ProjectOpenclaw => Some(project_openclaw_skills_root(cwd)),
@ -1036,6 +1056,7 @@ mod tests {
let ordered = source_order(&[ let ordered = source_order(&[
"user".to_string(), "user".to_string(),
"user_agent".to_string(), "user_agent".to_string(),
"user_openclaw".to_string(),
"project".to_string(), "project".to_string(),
"project_agent".to_string(), "project_agent".to_string(),
"project_openclaw".to_string(), "project_openclaw".to_string(),
@ -1048,6 +1069,7 @@ mod tests {
vec![ vec![
SkillSource::User, SkillSource::User,
SkillSource::UserAgent, SkillSource::UserAgent,
SkillSource::UserOpenclaw,
SkillSource::Project, SkillSource::Project,
SkillSource::ProjectAgent, SkillSource::ProjectAgent,
SkillSource::ProjectOpenclaw, SkillSource::ProjectOpenclaw,
@ -1293,4 +1315,38 @@ mod tests {
let payload = catalog.activation_event_payload("demo-openclaw").unwrap(); let payload = catalog.activation_event_payload("demo-openclaw").unwrap();
assert_eq!(payload["source"], "project_openclaw"); assert_eq!(payload["source"], "project_openclaw");
} }
#[test]
fn test_discover_loads_user_openclaw_skills() {
let _lock = acquire_test_lock();
let temp_dir = tempfile::tempdir().unwrap();
let home_dir = temp_dir.path().join("home");
let project_dir = temp_dir.path().join("project");
fs::create_dir_all(&home_dir).unwrap();
fs::create_dir_all(&project_dir).unwrap();
let _home = HomeDirGuard::enter(&home_dir);
let _guard = CurrentDirGuard::enter(&project_dir);
let user_openclaw_skill_dir = home_dir
.join(".openclaw")
.join("skills")
.join("demo-user-openclaw");
fs::create_dir_all(&user_openclaw_skill_dir).unwrap();
fs::write(
user_openclaw_skill_dir.join("SKILL.md"),
"---\ndescription: user openclaw skill\n---\nUse user openclaw",
)
.unwrap();
let catalog = SkillCatalog::discover(&SkillsConfig {
enabled: true,
sources: vec!["user_openclaw".to_string()],
max_index_chars: 4000,
max_listed_skills: 32,
});
assert_eq!(catalog.len(), 1);
let payload = catalog.activation_event_payload("demo-user-openclaw").unwrap();
assert_eq!(payload["source"], "user_openclaw");
}
} }

View File

@ -32,7 +32,7 @@ impl Tool for SkillManageTool {
} }
fn description(&self) -> &str { fn description(&self) -> &str {
"Manage PicoBot skills stored under .picobot/skills or ~/.picobot/skills, while discovery also reads .agents/skills, ~/.agents/skills, and .openclaw/skills. Supports actions: list, get, create, update, delete, disable, reload." "Manage PicoBot skills stored under .picobot/skills or ~/.picobot/skills, while discovery also reads .agents/skills, ~/.agents/skills, .openclaw/skills, and ~/.openclaw/skills. Supports actions: list, get, create, update, delete, disable, reload."
} }
fn parameters_schema(&self) -> serde_json::Value { fn parameters_schema(&self) -> serde_json::Value {
@ -121,6 +121,7 @@ impl Tool for SkillManageTool {
"source": match skill.source { "source": match skill.source {
crate::skills::SkillSource::User => "user", crate::skills::SkillSource::User => "user",
crate::skills::SkillSource::UserAgent => "user_agent", crate::skills::SkillSource::UserAgent => "user_agent",
crate::skills::SkillSource::UserOpenclaw => "user_openclaw",
crate::skills::SkillSource::Project => "project", crate::skills::SkillSource::Project => "project",
crate::skills::SkillSource::ProjectAgent => "project_agent", crate::skills::SkillSource::ProjectAgent => "project_agent",
crate::skills::SkillSource::ProjectOpenclaw => "project_openclaw", crate::skills::SkillSource::ProjectOpenclaw => "project_openclaw",
@ -324,6 +325,7 @@ fn list_skills_payload(skills: &Arc<SkillRuntime>) -> serde_json::Value {
"source": match skill.source { "source": match skill.source {
crate::skills::SkillSource::User => "user", crate::skills::SkillSource::User => "user",
crate::skills::SkillSource::UserAgent => "user_agent", crate::skills::SkillSource::UserAgent => "user_agent",
crate::skills::SkillSource::UserOpenclaw => "user_openclaw",
crate::skills::SkillSource::Project => "project", crate::skills::SkillSource::Project => "project",
crate::skills::SkillSource::ProjectAgent => "project_agent", crate::skills::SkillSource::ProjectAgent => "project_agent",
crate::skills::SkillSource::ProjectOpenclaw => "project_openclaw", crate::skills::SkillSource::ProjectOpenclaw => "project_openclaw",