From 4e850e5a3fa0fadf471ef50cc5c67e9e17724954 Mon Sep 17 00:00:00 2001 From: Willie Date: Fri, 9 Oct 2026 12:10:08 +0800 Subject: [PATCH] fix(sync): decode the whole block when the name line is not a string A multi-line quoted name such as "proto\ followed by an indented line fails to decode alone, and the literal first line was returned, so the skill was skipped. Decode the whole frontmatter whenever the name line does not decode to a string; keep the literal only for frontmatter YAML rejects. --- internal/utils/frontmatter.go | 14 +++++++++----- internal/utils/frontmatter_entrypoints_test.go | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/utils/frontmatter.go b/internal/utils/frontmatter.go index 442e48945..c66ca89a0 100644 --- a/internal/utils/frontmatter.go +++ b/internal/utils/frontmatter.go @@ -17,7 +17,7 @@ import ( // allows (flow mapping, block scalar, alias, merge key, explicit key, ...) leaves the // scan without a name, and then the whole block is decoded. func ParseSkillName(skillPath string) (string, error) { - name, indent := "", -1 + name, literal, indent := "", "", -1 path := filepath.Join(skillPath, "SKILL.md") err := scanLenientBlock(path, func(raw []byte) bool { line := string(raw) @@ -35,7 +35,9 @@ func ParseSkillName(skillPath string) (string, error) { if v := strings.TrimSpace(value); v != "" && strings.ContainsRune("*|>&!", rune(v[0])) { return false // alias, block scalar, anchor or tag: decode the whole block } - // The line alone decodes quotes and a trailing comment; a value YAML rejects is read as is. + // The line alone decodes quotes and a trailing comment. When it does not decode to + // a string (a multi-line quoted scalar, a number), the whole block is decoded, and + // the line read as is is kept for frontmatter YAML rejects. var fm map[string]any if yaml.Unmarshal([]byte("name:"+value), &fm) == nil { if v, isString := fm["name"].(string); isString { @@ -43,7 +45,7 @@ func ParseSkillName(skillPath string) (string, error) { return false } } - name = strings.Trim(strings.TrimSpace(value), `"'`) + literal = strings.Trim(strings.TrimSpace(value), `"'`) return false }) if err != nil || name != "" { @@ -53,8 +55,10 @@ func ParseSkillName(skillPath string) (string, error) { if err != nil { return "", err } - name, _ = decodeFrontmatter(raw)["name"].(string) - return name, nil + if name, isString := decodeFrontmatter(raw)["name"].(string); isString { + return name, nil + } + return literal, nil } // isYAMLBlockIndicator returns true for YAML block scalar indicators (>, >-, >+, |, |-, |+). diff --git a/internal/utils/frontmatter_entrypoints_test.go b/internal/utils/frontmatter_entrypoints_test.go index 174975bac..d69eb3c38 100644 --- a/internal/utils/frontmatter_entrypoints_test.go +++ b/internal/utils/frontmatter_entrypoints_test.go @@ -377,6 +377,7 @@ func TestParseSkillName_ValidYAMLForms(t *testing.T) { "base: &n prototype\nname: *n", "defaults: &d {name: prototype}\n<<: *d", "? name\n: prototype", + "name: \"proto\\\n type\"", "name: prototype\nbad: [unclosed", // not YAML: the name: line is still read } { dir, _ := writeSkill(t, []byte("---\n"+fm+"\n---\nbody\n"))