From 78598b4586a4aacb474fb1eae822ea99821d7eeb Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Sun, 17 May 2026 17:32:24 +0800 Subject: [PATCH] refactor(skills): simplify BuiltInSkill and update triggers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Refactor SKILL_TEMPLATES to use array.into_iter().collect() - Add Chinese trigger keywords (审查, 性能, 总结, 分诊) - Remove duplicate test and dead code --- libs/agent/skills/templates.rs | 55 +++++++++++----------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/libs/agent/skills/templates.rs b/libs/agent/skills/templates.rs index de4f297..25c529d 100644 --- a/libs/agent/skills/templates.rs +++ b/libs/agent/skills/templates.rs @@ -1,30 +1,19 @@ //! Built-in skill templates. -//! -//! Each skill is a Markdown file containing instructions and guidelines -//! for the AI to follow when performing that task. use once_cell::sync::Lazy; use std::collections::HashMap; -/// A built-in skill template. #[derive(Debug, Clone)] pub struct BuiltInSkill { - /// URL-safe identifier (e.g., "code-review") pub slug: &'static str, - /// Human-readable name (e.g., "Code Review") pub name: &'static str, - /// Short description (e.g., "Review code changes...") pub description: &'static str, - /// Primary keywords that trigger this skill pub trigger_keywords: Vec<&'static str>, - /// Tool names that trigger this skill pub trigger_tools: Vec<&'static str>, - /// The skill content/instructions pub content: String, } impl BuiltInSkill { - /// Create a new built-in skill. pub fn new( slug: &'static str, name: &'static str, @@ -44,10 +33,7 @@ impl BuiltInSkill { } } -/// All built-in skill templates. pub static SKILL_TEMPLATES: Lazy> = Lazy::new(|| { - let mut map = HashMap::new(); - let skills = [ BuiltInSkill::new( "code-review", @@ -58,13 +44,15 @@ pub static SKILL_TEMPLATES: Lazy> = Lazy::ne "code review", "review code", "代码审查", + "审查", "review pr", "security", + "性能", "performance", "bug", "vulnerability", ], - vec!["git_diff", "git_diff_stats", "git_blame"], + vec!["git_diff", "git_diff_stats", "git_blame", "code_review"], include_str!("./templates/code-review.md"), ), BuiltInSkill::new( @@ -126,7 +114,7 @@ pub static SKILL_TEMPLATES: Lazy> = Lazy::ne "Read file contents and search for patterns in code", vec![ "read", "view", "show", "显示", "读取", "file", "content", "search", "grep", - "find", "search", "配置", "csv", "json", + "find", "配置", "csv", "json", ], vec![ "git_file_content", @@ -221,15 +209,22 @@ pub static SKILL_TEMPLATES: Lazy> = Lazy::ne "pr-summary", "PR Summary", "Generate clear pull request summaries following conventional format", - vec!["pr", "pull request", "merge", "summary", "describe"], + vec!["pr", "pull request", "merge", "summary", "describe", "总结"], vec!["git_diff", "git_log"], include_str!("./templates/pr-summary.md"), ), BuiltInSkill::new( "issue-triage", "Issue Triage", - "Classify and prioritize GitHub issues with labels and components", - vec!["triage", "classify", "priority", "severity", "component"], + "Classify and prioritize issues with labels and components", + vec![ + "triage", + "classify", + "priority", + "severity", + "component", + "分诊", + ], vec!["list_issues_exec"], include_str!("./templates/issue-triage.md"), ), @@ -267,11 +262,10 @@ pub static SKILL_TEMPLATES: Lazy> = Lazy::ne ), ]; - for skill in skills { - map.insert(skill.slug, skill); - } - - map + skills + .into_iter() + .map(|skill| (skill.slug, skill)) + .collect() }); #[cfg(test)] @@ -322,17 +316,4 @@ mod tests { ); } } - - #[test] - fn test_skill_uniqueness() { - let mut slugs = Vec::new(); - for skill in SKILL_TEMPLATES.values() { - assert!( - !slugs.contains(&skill.slug), - "Duplicate skill slug: {}", - skill.slug - ); - slugs.push(skill.slug); - } - } }