refactor(skills): simplify BuiltInSkill and update triggers

- Refactor SKILL_TEMPLATES to use array.into_iter().collect()
- Add Chinese trigger keywords (审查, 性能, 总结, 分诊)
- Remove duplicate test and dead code
This commit is contained in:
ZhenYi 2026-05-17 17:32:24 +08:00
parent 60100a025c
commit 78598b4586

View File

@ -1,30 +1,19 @@
//! Built-in skill templates. //! 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 once_cell::sync::Lazy;
use std::collections::HashMap; use std::collections::HashMap;
/// A built-in skill template.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BuiltInSkill { pub struct BuiltInSkill {
/// URL-safe identifier (e.g., "code-review")
pub slug: &'static str, pub slug: &'static str,
/// Human-readable name (e.g., "Code Review")
pub name: &'static str, pub name: &'static str,
/// Short description (e.g., "Review code changes...")
pub description: &'static str, pub description: &'static str,
/// Primary keywords that trigger this skill
pub trigger_keywords: Vec<&'static str>, pub trigger_keywords: Vec<&'static str>,
/// Tool names that trigger this skill
pub trigger_tools: Vec<&'static str>, pub trigger_tools: Vec<&'static str>,
/// The skill content/instructions
pub content: String, pub content: String,
} }
impl BuiltInSkill { impl BuiltInSkill {
/// Create a new built-in skill.
pub fn new( pub fn new(
slug: &'static str, slug: &'static str,
name: &'static str, name: &'static str,
@ -44,10 +33,7 @@ impl BuiltInSkill {
} }
} }
/// All built-in skill templates.
pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = Lazy::new(|| { pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = Lazy::new(|| {
let mut map = HashMap::new();
let skills = [ let skills = [
BuiltInSkill::new( BuiltInSkill::new(
"code-review", "code-review",
@ -58,13 +44,15 @@ pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = Lazy::ne
"code review", "code review",
"review code", "review code",
"代码审查", "代码审查",
"审查",
"review pr", "review pr",
"security", "security",
"性能",
"performance", "performance",
"bug", "bug",
"vulnerability", "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"), include_str!("./templates/code-review.md"),
), ),
BuiltInSkill::new( BuiltInSkill::new(
@ -126,7 +114,7 @@ pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = Lazy::ne
"Read file contents and search for patterns in code", "Read file contents and search for patterns in code",
vec![ vec![
"read", "view", "show", "显示", "读取", "file", "content", "search", "grep", "read", "view", "show", "显示", "读取", "file", "content", "search", "grep",
"find", "search", "配置", "csv", "json", "find", "配置", "csv", "json",
], ],
vec![ vec![
"git_file_content", "git_file_content",
@ -221,15 +209,22 @@ pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = Lazy::ne
"pr-summary", "pr-summary",
"PR Summary", "PR Summary",
"Generate clear pull request summaries following conventional format", "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"], vec!["git_diff", "git_log"],
include_str!("./templates/pr-summary.md"), include_str!("./templates/pr-summary.md"),
), ),
BuiltInSkill::new( BuiltInSkill::new(
"issue-triage", "issue-triage",
"Issue Triage", "Issue Triage",
"Classify and prioritize GitHub issues with labels and components", "Classify and prioritize issues with labels and components",
vec!["triage", "classify", "priority", "severity", "component"], vec![
"triage",
"classify",
"priority",
"severity",
"component",
"分诊",
],
vec!["list_issues_exec"], vec!["list_issues_exec"],
include_str!("./templates/issue-triage.md"), include_str!("./templates/issue-triage.md"),
), ),
@ -267,11 +262,10 @@ pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = Lazy::ne
), ),
]; ];
for skill in skills { skills
map.insert(skill.slug, skill); .into_iter()
} .map(|skill| (skill.slug, skill))
.collect()
map
}); });
#[cfg(test)] #[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);
}
}
} }