Fix parsing of SKILL.md file frontmatter - regex
This commit is contained in:
parent
8b44fe5c74
commit
052970d017
1 changed files with 10 additions and 3 deletions
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var namePattern = regexp.MustCompile(`^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$`)
|
var namePattern = regexp.MustCompile(`^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$`)
|
||||||
|
|
@ -251,6 +253,11 @@ func (sl *SkillsLoader) BuildSkillsSummary() string {
|
||||||
func (sl *SkillsLoader) getSkillMetadata(skillPath string) *SkillMetadata {
|
func (sl *SkillsLoader) getSkillMetadata(skillPath string) *SkillMetadata {
|
||||||
content, err := os.ReadFile(skillPath)
|
content, err := os.ReadFile(skillPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.WarnCF("skills", "Failed to read skill metadata",
|
||||||
|
map[string]interface{}{
|
||||||
|
"skill_path": skillPath,
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,9 +313,9 @@ func (sl *SkillsLoader) parseSimpleYAML(content string) map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sl *SkillsLoader) extractFrontmatter(content string) string {
|
func (sl *SkillsLoader) extractFrontmatter(content string) string {
|
||||||
// (?s) enables DOTALL mode so . matches newlines
|
// Support both Unix (\n) and Windows (\r\n) line endings for frontmatter blocks
|
||||||
// Match first ---, capture everything until next --- on its own line
|
// (?s) enables DOTALL so . matches newlines; ^--- at start, then ... --- at start of line
|
||||||
re := regexp.MustCompile(`(?s)^---\n(.*)\n---`)
|
re := regexp.MustCompile(`(?s)^---\r?\n(.*?)\r?\n---`)
|
||||||
match := re.FindStringSubmatch(content)
|
match := re.FindStringSubmatch(content)
|
||||||
if len(match) > 1 {
|
if len(match) > 1 {
|
||||||
return match[1]
|
return match[1]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue