Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(skills): accept UTF-8 BOM in skill manifests

wizardchen918c20342cb2
diff --git a/internal/agent/skills/skill.go b/internal/agent/skills/skill.go
index 5d2a21595..c9c9a3d99 100644
--- a/internal/agent/skills/skill.go
+++ b/internal/agent/skills/skill.go
@@ -160,6 +160,8 @@ func (s *Skill) ToMetadata() *SkillMetadata {
// It handles YAML frontmatter enclosed in --- delimiters
func ParseSkillFile(content string) (*Skill, error) {
skill := &Skill{}
+ // Some editors emit a UTF-8 BOM, which strings.TrimSpace does not remove.
+ content = strings.TrimPrefix(content, "\ufeff")
// Check for YAML frontmatter
if !strings.HasPrefix(strings.TrimSpace(content), "---") {
diff --git a/internal/agent/skills/skills_test.go b/internal/agent/skills/skills_test.go
index cb2a4cf2c..8b3128d3d 100644
--- a/internal/agent/skills/skills_test.go
+++ b/internal/agent/skills/skills_test.go
@@ -2,6 +2,7 @@ package skills
import (
"context"
+ "fmt"
"os"
"path/filepath"
"strings"
@@ -50,6 +51,30 @@ Use this skill when testing.
skill.Name, skill.Description, len(skill.Instructions))
}
+func TestParseSkillFileUTF8BOM(t *testing.T) {
+ for _, newline := range []string{"\n", "\r\n"} {
+ t.Run(fmt.Sprintf("newline=%q", newline), func(t *testing.T) {
+ content := "\ufeff---\nname: test-skill\ndescription: A test skill.\n---\nKeep this \ufeff character.\n"
+ content = strings.ReplaceAll(content, "\n", newline)
+ skill, err := ParseSkillFile(content)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if skill.Name != "test-skill" || skill.Description != "A test skill." ||
+ skill.Instructions != "Keep this \ufeff character." {
+ t.Fatalf("unexpected parsed skill: %+v", skill)
+ }
+ metadata, err := ParseSkillMetadata(content)
+ if err != nil || metadata.Name != "test-skill" {
+ t.Fatalf("unexpected metadata: %+v, error: %v", metadata, err)
+ }
+ })
+ }
+ if _, err := ParseSkillFile("\ufeff# Missing frontmatter"); err == nil {
+ t.Fatal("BOM must not bypass frontmatter validation")
+ }
+}
+
func TestSkillValidation(t *testing.T) {
tests := []struct {
name string
diff --git a/internal/application/service/tenant_skill_bundle.go b/internal/application/service/tenant_skill_bundle.go
index 90bd3d4df..75826136c 100644
--- a/internal/application/service/tenant_skill_bundle.go
+++ b/internal/application/service/tenant_skill_bundle.go
@@ -391,6 +391,7 @@ func validateSkillEntryName(name string) error {
}
func parseSkillBundleVersion(manifest string) (string, error) {
+ manifest = strings.TrimPrefix(manifest, "\ufeff")
lines := strings.Split(manifest, "\n")
frontmatterStart := -1
for i, line := range lines {
diff --git a/internal/application/service/tenant_skill_bundle_test.go b/internal/application/service/tenant_skill_bundle_test.go
index 3c6b7fa19..e21f0b2eb 100644
--- a/internal/application/service/tenant_skill_bundle_test.go
+++ b/internal/application/service/tenant_skill_bundle_test.go
@@ -242,6 +242,18 @@ Use scripts/extract.py to pull text out of a PDF.
require.Equal(t, "1.2.3", bundle.Version)
})
+ t.Run("reads UTF-8 BOM frontmatter including version", func(t *testing.T) {
+ manifest := "\ufeff---\nname: pdf-tools\nversion: 1.2.3\n" +
+ "description: Extract text from PDF files\n---\nUse PDF tools.\n"
+ data := zipBundle(t, map[string]string{"SKILL.md": manifest})
+ bundle, err := ParseSkillBundle(data)
+ require.NoError(t, err)
+ require.Equal(t, "pdf-tools", bundle.Name)
+ require.Equal(t, "1.2.3", bundle.Version)
+ require.Equal(t, "Use PDF tools.", bundle.Instructions)
+ require.Equal(t, []byte(manifest), bundle.Files["SKILL.md"])
+ })
+
t.Run("uses slug when name is a display title", func(t *testing.T) {
data := zipBundle(t, map[string]string{
"SKILL.md": `---
diff --git a/internal/application/service/tenant_skill_source.go b/internal/application/service/tenant_skill_source.go
index 2323c81f4..f159f8e63 100644
--- a/internal/application/service/tenant_skill_source.go
+++ b/internal/application/service/tenant_skill_source.go
@@ -914,7 +914,7 @@ func looksLikeJSON(contentType string, body []byte) bool {
}
func looksLikeSkillMarkdown(body []byte) bool {
- trimmed := bytes.TrimSpace(body)
+ trimmed := bytes.TrimSpace(bytes.TrimPrefix(body, []byte("\ufeff")))
if !bytes.HasPrefix(trimmed, []byte("---")) {
return false
}
diff --git a/internal/application/service/tenant_skill_source_test.go b/internal/application/service/tenant_skill_source_test.go
index 3cb486718..e0703de88 100644
--- a/internal/application/service/tenant_skill_source_test.go
+++ b/internal/application/service/tenant_skill_source_test.go
@@ -515,18 +515,23 @@ func TestFetchSkillArchiveFollowsGitHubHandoff(t *testing.T) {
}
func TestFetchSkillArchiveFromSkillMarkdown(t *testing.T) {
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
- w.Header().Set("Content-Type", "text/markdown")
- _, _ = w.Write([]byte(validSkillMD))
- }))
- t.Cleanup(server.Close)
- allowLoopbackSkillFetch(t)
-
- got, err := fetchSkillArchive(t.Context(), server.URL+"/SKILL.md", server.Client())
- require.NoError(t, err)
- bundle, err := ParseSkillBundle(got)
- require.NoError(t, err)
- require.Equal(t, "pdf-tools", bundle.Name)
+ for _, prefix := range []string{"", "\ufeff"} {
+ t.Run(fmt.Sprintf("prefix=%q", prefix), func(t *testing.T) {
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.Header().Set("Content-Type", "text/markdown")
+ _, _ = w.Write([]byte(prefix + validSkillMD))
+ }))
+ t.Cleanup(server.Close)
+ allowLoopbackSkillFetch(t)
+
+ got, err := fetchSkillArchive(t.Context(), server.URL+"/SKILL.md", server.Client())
+ require.NoError(t, err)
+ bundle, err := ParseSkillBundle(got)
+ require.NoError(t, err)
+ require.Equal(t, "pdf-tools", bundle.Name)
+ require.Equal(t, []byte(prefix+validSkillMD), bundle.Files["SKILL.md"])
+ })
+ }
}
func TestParseSkillBundleNestedRemoteArchive(t *testing.T) {