From ba0e1c2473715ecf469044a4a65daa9cc3cdcb39 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Sat, 9 May 2026 14:31:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=20project?= =?UTF-8?q?=5Fopenclaw=20=E6=8A=80=E8=83=BD=E6=BA=90=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E5=92=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/config/mod.rs | 2 ++ src/skills/mod.rs | 49 +++++++++++++++++++++++++++++++++++++++ src/tools/skill_manage.rs | 4 +++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 92d7bc9..16b6129 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ Cargo.lock .venv PicoBot.code-workspace .picobot +.claude diff --git a/src/config/mod.rs b/src/config/mod.rs index 4bbd416..fec0690 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -74,6 +74,7 @@ fn default_skills_sources() -> Vec { "user_agent".to_string(), "project".to_string(), "project_agent".to_string(), + "project_openclaw".to_string(), ] } @@ -894,6 +895,7 @@ mod tests { "user_agent".to_string(), "project".to_string(), "project_agent".to_string(), + "project_openclaw".to_string(), ] ); } diff --git a/src/skills/mod.rs b/src/skills/mod.rs index e0b7381..d833a90 100644 --- a/src/skills/mod.rs +++ b/src/skills/mod.rs @@ -30,6 +30,7 @@ pub enum SkillSource { UserAgent, Project, ProjectAgent, + ProjectOpenclaw, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -329,6 +330,7 @@ impl SkillSource { SkillSource::UserAgent => "user_agent", SkillSource::Project => "project", SkillSource::ProjectAgent => "project_agent", + SkillSource::ProjectOpenclaw => "project_openclaw", } } } @@ -565,6 +567,11 @@ fn source_order(sources: &[String]) -> Vec { result.push(SkillSource::ProjectAgent); } } + "project_openclaw" => { + if !result.contains(&SkillSource::ProjectOpenclaw) { + result.push(SkillSource::ProjectOpenclaw); + } + } unknown => { tracing::warn!(source = %unknown, "Unknown skills source ignored"); } @@ -577,6 +584,7 @@ fn source_order(sources: &[String]) -> Vec { SkillSource::UserAgent, SkillSource::Project, SkillSource::ProjectAgent, + SkillSource::ProjectOpenclaw, ] } else { result @@ -603,6 +611,10 @@ fn project_agent_skills_root(cwd: &Path) -> PathBuf { cwd.join(".agents").join("skills") } +fn project_openclaw_skills_root(cwd: &Path) -> PathBuf { + cwd.join(".openclaw").join("skills") +} + fn project_skill_state_path(cwd: &Path) -> PathBuf { cwd.join(".picobot").join("skill-state.json") } @@ -625,6 +637,7 @@ fn source_root(source: SkillSource, cwd: &Path) -> Option { SkillSource::UserAgent => user_agent_skills_root(), SkillSource::Project => Some(cwd.join(".picobot").join("skills")), SkillSource::ProjectAgent => Some(project_agent_skills_root(cwd)), + SkillSource::ProjectOpenclaw => Some(project_openclaw_skills_root(cwd)), } } @@ -1025,6 +1038,7 @@ mod tests { "user_agent".to_string(), "project".to_string(), "project_agent".to_string(), + "project_openclaw".to_string(), "project".to_string(), "unknown".to_string(), ]); @@ -1036,6 +1050,7 @@ mod tests { SkillSource::UserAgent, SkillSource::Project, SkillSource::ProjectAgent, + SkillSource::ProjectOpenclaw, ] ); } @@ -1244,4 +1259,38 @@ mod tests { assert!(user_enabled.disabled_in_scopes.is_empty()); assert!(runtime.get_skill("demo").is_some()); } + + #[test] + fn test_discover_loads_project_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 openclaw_skill_dir = project_dir + .join(".openclaw") + .join("skills") + .join("demo-openclaw"); + fs::create_dir_all(&openclaw_skill_dir).unwrap(); + fs::write( + openclaw_skill_dir.join("SKILL.md"), + "---\ndescription: openclaw skill\n---\nUse openclaw", + ) + .unwrap(); + + let catalog = SkillCatalog::discover(&SkillsConfig { + enabled: true, + sources: vec!["project_openclaw".to_string()], + max_index_chars: 4000, + max_listed_skills: 32, + }); + + assert_eq!(catalog.len(), 1); + let payload = catalog.activation_event_payload("demo-openclaw").unwrap(); + assert_eq!(payload["source"], "project_openclaw"); + } } diff --git a/src/tools/skill_manage.rs b/src/tools/skill_manage.rs index 534ac33..a66102d 100644 --- a/src/tools/skill_manage.rs +++ b/src/tools/skill_manage.rs @@ -32,7 +32,7 @@ impl Tool for SkillManageTool { } fn description(&self) -> &str { - "Manage PicoBot skills stored under .picobot/skills or ~/.picobot/skills, while discovery also reads .agents/skills and ~/.agents/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, and .openclaw/skills. Supports actions: list, get, create, update, delete, disable, reload." } fn parameters_schema(&self) -> serde_json::Value { @@ -123,6 +123,7 @@ impl Tool for SkillManageTool { crate::skills::SkillSource::UserAgent => "user_agent", crate::skills::SkillSource::Project => "project", crate::skills::SkillSource::ProjectAgent => "project_agent", + crate::skills::SkillSource::ProjectOpenclaw => "project_openclaw", }, "path": skill.path.display().to_string(), }), @@ -325,6 +326,7 @@ fn list_skills_payload(skills: &Arc) -> serde_json::Value { crate::skills::SkillSource::UserAgent => "user_agent", crate::skills::SkillSource::Project => "project", crate::skills::SkillSource::ProjectAgent => "project_agent", + crate::skills::SkillSource::ProjectOpenclaw => "project_openclaw", }, "path": skill.path.display().to_string(), })).collect::>()