gitdataai/libs/agent/skills/templates.rs
ZhenYi 78598b4586 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
2026-05-17 17:32:24 +08:00

320 lines
9.9 KiB
Rust

//! Built-in skill templates.
use once_cell::sync::Lazy;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct BuiltInSkill {
pub slug: &'static str,
pub name: &'static str,
pub description: &'static str,
pub trigger_keywords: Vec<&'static str>,
pub trigger_tools: Vec<&'static str>,
pub content: String,
}
impl BuiltInSkill {
pub fn new(
slug: &'static str,
name: &'static str,
description: &'static str,
trigger_keywords: Vec<&'static str>,
trigger_tools: Vec<&'static str>,
content: &'static str,
) -> Self {
Self {
slug,
name,
description,
trigger_keywords,
trigger_tools,
content: content.to_string(),
}
}
}
pub static SKILL_TEMPLATES: Lazy<HashMap<&'static str, BuiltInSkill>> = Lazy::new(|| {
let skills = [
BuiltInSkill::new(
"code-review",
"Code Review",
"Expert code review with security, performance, and quality checks",
vec![
"review",
"code review",
"review code",
"代码审查",
"审查",
"review pr",
"security",
"性能",
"performance",
"bug",
"vulnerability",
],
vec!["git_diff", "git_diff_stats", "git_blame", "code_review"],
include_str!("./templates/code-review.md"),
),
BuiltInSkill::new(
"git-log",
"Git Log Analysis",
"Analyze commit history and understand code evolution",
vec![
"commit",
"history",
"log",
"提交",
"历史",
"author",
"git log",
"查看提交",
"commits",
],
vec!["git_log", "git_graph", "git_reflog", "git_search_commits"],
include_str!("./templates/git-log.md"),
),
BuiltInSkill::new(
"git-diff",
"Git Diff Analysis",
"Understand code changes between commits or branches",
vec![
"diff", "change", "修改", "变更", "compare", "对比", "改动", "patch", "delta",
"changes",
],
vec!["git_diff", "git_diff_stats", "git_blame"],
include_str!("./templates/git-diff.md"),
),
BuiltInSkill::new(
"git-branch",
"Git Branch Management",
"Manage branches and understand branch relationships",
vec![
"branch",
"branches",
"分支",
"HEAD",
"main",
"develop",
"feature",
"hotfix",
"merged",
"compare branches",
],
vec![
"git_branch_list",
"git_branch_info",
"git_branches_merged",
"git_branch_diff",
],
include_str!("./templates/git-branch.md"),
),
BuiltInSkill::new(
"file-reader",
"File Reading & Search",
"Read file contents and search for patterns in code",
vec![
"read", "view", "show", "显示", "读取", "file", "content", "search", "grep",
"find", "配置", "csv", "json",
],
vec![
"git_file_content",
"git_tree_ls",
"read_csv",
"read_json",
"read_markdown",
"git_grep",
],
include_str!("./templates/file-reader.md"),
),
BuiltInSkill::new(
"repo-manager",
"Repository Management",
"List, create, and manage project repositories",
vec![
"repo",
"repository",
"仓库",
"project",
"项目",
"create repo",
"update repo",
"仓库管理",
],
vec![
"project_list_repos",
"project_create_repo",
"project_update_repo",
],
include_str!("./templates/repo-manager.md"),
),
BuiltInSkill::new(
"issue-manager",
"Issue Management",
"Manage issues with triage, labels, and priorities",
vec![
"issue", "bug", "task", "任务", "问题", "triage", "priority", "label", "assign",
"状态",
],
vec!["list_issues_exec", "create_issue_exec", "update_issue_exec"],
include_str!("./templates/issue-manager.md"),
),
BuiltInSkill::new(
"board-manager",
"Board & Kanban Management",
"Manage project boards, cards, and kanban workflows",
vec![
"board", "kanban", "看板", "card", "task", "sprint", "column", "lane", "泳道",
"进度",
],
vec![
"list_boards_exec",
"create_board_exec",
"create_board_card_exec",
"update_board_card_exec",
],
include_str!("./templates/board-manager.md"),
),
BuiltInSkill::new(
"member-manager",
"Team Member Management",
"Manage team members, roles, and permissions",
vec![
"member",
"team",
"user",
"成员",
"团队",
"role",
"permission",
"权限",
"admin",
"maintainer",
"contributor",
],
vec!["list_members_exec"],
include_str!("./templates/member-manager.md"),
),
BuiltInSkill::new(
"http-requester",
"HTTP Request & API Testing",
"Make HTTP requests and test APIs",
vec![
"http", "api", "endpoint", "request", "response", "curl", "webhook", "POST", "GET",
"REST",
],
vec!["curl_exec", "project_curl"],
include_str!("./templates/http-requester.md"),
),
BuiltInSkill::new(
"pr-summary",
"PR Summary",
"Generate clear pull request summaries following conventional format",
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 issues with labels and components",
vec![
"triage",
"classify",
"priority",
"severity",
"component",
"分诊",
],
vec!["list_issues_exec"],
include_str!("./templates/issue-triage.md"),
),
BuiltInSkill::new(
"doc-generator",
"Documentation Generator",
"Generate README, API docs, and code documentation",
vec!["doc", "document", "readme", "api doc", "文档", "生成文档"],
vec!["read_markdown", "read_json"],
include_str!("./templates/doc-generator.md"),
),
BuiltInSkill::new(
"test-generator",
"Test Generator",
"Write comprehensive unit tests following AAA pattern",
vec!["test", "testing", "unit test", "测试", "spec"],
vec!["git_file_content"],
include_str!("./templates/test-generator.md"),
),
BuiltInSkill::new(
"commit-message",
"Commit Message Generator",
"Generate conventional commit messages following best practices",
vec!["commit", "message", "conventional", "提交信息"],
vec!["git_diff", "git_log"],
include_str!("./templates/commit-message.md"),
),
BuiltInSkill::new(
"code-explainer",
"Code Explainer",
"Explain complex code in simple, accessible terms",
vec!["explain", "understand", "what does", "解释", "说明"],
vec!["git_file_content", "git_blame"],
include_str!("./templates/code-explainer.md"),
),
];
skills
.into_iter()
.map(|skill| (skill.slug, skill))
.collect()
});
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_all_skills_loaded() {
let expected = [
"code-review",
"git-log",
"git-diff",
"git-branch",
"file-reader",
"repo-manager",
"issue-manager",
"board-manager",
"member-manager",
"http-requester",
"pr-summary",
"issue-triage",
"doc-generator",
"test-generator",
"commit-message",
"code-explainer",
];
for slug in expected {
assert!(
SKILL_TEMPLATES.contains_key(slug),
"Missing skill: {}",
slug
);
}
}
#[test]
fn test_skill_has_triggers() {
for skill in SKILL_TEMPLATES.values() {
assert!(
!skill.trigger_keywords.is_empty() || !skill.trigger_tools.is_empty(),
"Skill {} has no triggers",
skill.slug
);
assert!(
skill.content.len() > 100,
"Skill {} content too short",
skill.slug
);
}
}
}