refactor(skills): simplify metadata parsing using yaml.v3
Replace custom YAML parsing with yaml.v3 library and unify JSON/YAML handling
This commit is contained in:
parent
214b201bfa
commit
2dfd5a19ac
1 changed files with 11 additions and 39 deletions
|
|
@ -7,11 +7,13 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SkillMetadata struct {
|
type SkillMetadata struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description" yaml:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SkillInfo struct {
|
type SkillInfo struct {
|
||||||
|
|
@ -217,47 +219,17 @@ func (sl *SkillsLoader) getSkillMetadata(skillPath string) *SkillMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try JSON first (for backward compatibility)
|
// Try JSON first (for backward compatibility)
|
||||||
var jsonMeta struct {
|
var meta SkillMetadata
|
||||||
Name string `json:"name"`
|
if err := json.Unmarshal([]byte(frontmatter), &meta); err == nil {
|
||||||
Description string `json:"description"`
|
return &meta
|
||||||
}
|
|
||||||
if err := json.Unmarshal([]byte(frontmatter), &jsonMeta); err == nil {
|
|
||||||
return &SkillMetadata{
|
|
||||||
Name: jsonMeta.Name,
|
|
||||||
Description: jsonMeta.Description,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to simple YAML parsing
|
// Fall back to YAML parsing
|
||||||
yamlMeta := sl.parseSimpleYAML(frontmatter)
|
if err := yaml.Unmarshal([]byte(frontmatter), &meta); err == nil {
|
||||||
return &SkillMetadata{
|
return &meta
|
||||||
Name: yamlMeta["name"],
|
|
||||||
Description: yamlMeta["description"],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseSimpleYAML parses simple key: value YAML format
|
|
||||||
// Example: name: github\n description: "..."
|
|
||||||
func (sl *SkillsLoader) parseSimpleYAML(content string) map[string]string {
|
|
||||||
result := make(map[string]string)
|
|
||||||
|
|
||||||
for _, line := range strings.Split(content, "\n") {
|
|
||||||
line = strings.TrimSpace(line)
|
|
||||||
if line == "" || strings.HasPrefix(line, "#") {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.SplitN(line, ":", 2)
|
return nil
|
||||||
if len(parts) == 2 {
|
|
||||||
key := strings.TrimSpace(parts[0])
|
|
||||||
value := strings.TrimSpace(parts[1])
|
|
||||||
// Remove quotes if present
|
|
||||||
value = strings.Trim(value, "\"'")
|
|
||||||
result[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sl *SkillsLoader) extractFrontmatter(content string) string {
|
func (sl *SkillsLoader) extractFrontmatter(content string) string {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue