From 84f4453911e9e82523053bd9bc9d7bba8fca1ddb Mon Sep 17 00:00:00 2001 From: Dark aura Date: Thu, 7 May 2026 06:00:53 +0100 Subject: [PATCH] feat(tools): add ToolSkill metadata handling for community tool system - ToolSkill struct with Name, Description, Tags, UsageCount - LoadToolSkill() to read and parse tool skill files - Extract tags from content if not in frontmatter --- pkg/tools/toolskill.go | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pkg/tools/toolskill.go diff --git a/pkg/tools/toolskill.go b/pkg/tools/toolskill.go new file mode 100644 index 000000000..915d64679 --- /dev/null +++ b/pkg/tools/toolskill.go @@ -0,0 +1,53 @@ +// pkg/tools/toolskill.go +package tools + +import ( + "io/ioutil" + "path/filepath" + "strings" + + "gopkg.in/yaml.v3" +) + +type ToolSkill struct { + Name string `yaml:"name"` + Description string `yaml:"description"` + Type string `yaml:"type"` + Tags []string `yaml:"tags"` + Version string `yaml:"version"` + UsageCount int `yaml:"usage_count"` + LastUsed string `yaml:"last_used"` + Metadata map[string]interface{} `yaml:",inline"` +} + +// LoadToolSkill reads a tool skill file and parses it +func LoadToolSkill(filePath string) (*ToolSkill, error) { + data, err := ioutil.ReadFile(filePath) + if err != nil { + return nil, err + } + + var skill ToolSkill + if err := yaml.Unmarshal(data, &skill); err != nil { + return nil, err + } + + // Extract tags from content if not in frontmatter + if len(skill.Tags) == 0 { + skill.Tags = extractTagsFromContent(string(data)) + } + + return &skill, nil +} + +// extractTagsFromContent extracts tags from markdown content +func extractTagsFromContent(content string) []string { + // Look for #tag patterns + re := strings.NewReplacer(`#([a-zA-Z0-9_-]+)`, `$1`) + matches := re.FindAllStringSubmatch(content, -1) + tags := make([]string, 0, len(matches)) + for _, m := range matches { + tags = append(tags, m[1]) + } + return tags +}