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.
//!
//! 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<HashMap<&'static str, BuiltInSkill>> = Lazy::new(|| {
let mut map = HashMap::new();
let skills = [
BuiltInSkill::new(
"code-review",
@ -58,13 +44,15 @@ pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = 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<HashMap<&'static str, BuiltInSkill>> = 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<HashMap<&'static str, BuiltInSkill>> = 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<HashMap<&'static str, BuiltInSkill>> = 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);
}
}
}