Skip to content

Bug Fix: Fix parsing of SKILL.md file frontmatter - regex#411

Merged
Leeaandrob merged 3 commits intosipeed:mainfrom
harshbansal7:frontmatter_fix
Feb 18, 2026
Merged

Bug Fix: Fix parsing of SKILL.md file frontmatter - regex#411
Leeaandrob merged 3 commits intosipeed:mainfrom
harshbansal7:frontmatter_fix

Conversation

@harshbansal7
Copy link
Collaborator

📝 Description

SKILLS.md files contain frontmatter, that is further used to populate Name and Description for Skills. Current regex for frontmatter parsing did not account for different types of newline characters.

  • This PR add parsing for \r\n and \ron top of existing\n`.
  • Fixes WARN invalid skill from workspace name=summarize error="description is required"

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

Fixes / Closes #398

📚 Technical Context (Skip for Docs)

🧪 Test Environment

Tested on Docker

📸 Evidence (Optional)

Click to view Logs/Screenshots image

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

@harshbansal7 harshbansal7 marked this pull request as ready for review February 18, 2026 11:33
Copilot AI review requested due to automatic review settings February 18, 2026 11:33
@harshbansal7 harshbansal7 changed the title Fix parsing of SKILL.md file frontmatter - regex Bug Fix: Fix parsing of SKILL.md file frontmatter - regex Feb 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in the SKILL.md frontmatter parsing that prevented skills from being loaded on systems using Windows (\r\n) or classic Mac (\r) line endings. The original regex pattern only supported Unix line endings (\n), causing the parser to fail to extract the required name and description metadata from skill files. This resulted in "description is required" validation errors when loading skills.

Changes:

  • Updated the extractFrontmatter regex to support \r\n, \n, and \r line endings
  • Added logging for skill metadata read failures to aid debugging

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 327 to 329
func (sl *SkillsLoader) stripFrontmatter(content string) string {
re := regexp.MustCompile(`^---\n.*?\n---\n`)
return re.ReplaceAllString(content, "")
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stripFrontmatter function needs to be updated to handle different line endings (\r\n, \n, \r) consistently with the extractFrontmatter function. Currently, it only handles Unix line endings (\n), which means it will fail to strip frontmatter from files with Windows or classic Mac line endings. This inconsistency could cause the frontmatter to remain in the skill content when it's loaded for use.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parseSimpleYAML function splits content by \n only (line 296), which won't correctly parse YAML frontmatter from files with Windows (\r\n) or classic Mac (\r) line endings. Since extractFrontmatter now supports all three line ending types, parseSimpleYAML should normalize line endings or use a more robust splitting approach to handle the extracted frontmatter content correctly. Consider using strings.Split with a custom function that handles all three line ending types, or normalize the content before splitting.

Copilot uses AI. Check for mistakes.
Comment on lines 315 to 325
func (sl *SkillsLoader) extractFrontmatter(content string) string {
// (?s) enables DOTALL mode so . matches newlines
// Match first ---, capture everything until next --- on its own line
re := regexp.MustCompile(`(?s)^---\n(.*)\n---`)
// Support \n (Unix), \r\n (Windows), and \r (classic Mac) line endings for frontmatter blocks
// (?s) enables DOTALL so . matches newlines;
// ^--- at start, then ... --- at start of line, honoring all three line ending types
re := regexp.MustCompile(`(?s)^---(?:\r\n|\n|\r)(.*?)(?:\r\n|\n|\r)---`)
match := re.FindStringSubmatch(content)
if len(match) > 1 {
return match[1]
}
return ""
}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extractFrontmatter function lacks test coverage for the new multi-line-ending support. Since this fix addresses a critical bug (skills not being loaded due to line ending issues), it would be valuable to add tests that verify the regex correctly extracts frontmatter from content with \n (Unix), \r\n (Windows), and \r (classic Mac) line endings. This would prevent regression and ensure the fix works as intended across all platforms.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer to confirm if this is necessary or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@Leeaandrob Leeaandrob merged commit f7ec89d into sipeed:main Feb 18, 2026
SebastianBoehler pushed a commit to SebastianBoehler/picoclaw that referenced this pull request Feb 22, 2026
Bug Fix: Fix parsing of SKILL.md file frontmatter - regex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Invalid Skill from Workspace Warnings

3 participants