Repository navigation
fix(frontmatter): handle CRLF and BOM in SKILL.md parsing - #378
Merged
jeff-r2026 merged 1 commit intoSep 1, 2026
Merged
Conversation
The frontmatter regex only matched LF line endings, so SKILL.md files with CRLF or a UTF-8 BOM were treated as having no frontmatter. On pull/push a second frontmatter block was then injected at the top, corrupting the file with duplicate name/description. Extract a gray-matter-based helper (src/utils/frontmatter.ts) that tolerates BOM, CRLF/LF and malformed YAML, and route all 10 hand-written frontmatter parse/inject sites through it. Adds CRLF/BOM regression tests. Closes Tencent#372 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
m0Nst3r873
force-pushed
the
fix/frontmatter-crlf-bom-injection
branch
from
September 1, 2026 09:45
a6cc4dd to
dc77451
Compare
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…om-injection fix(frontmatter): handle CRLF and BOM in SKILL.md parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #372 — SKILL.md files with CRLF line endings or a UTF-8 BOM were corrupted on
pull/pushwith a duplicated frontmatter block.Root cause: the frontmatter regex
/^---\n[\s\S]*?\n---/only matched LF. A CRLF file's opening line is---\r\n, and a BOM sits before---, so^---\nfailed to match.ensureSkillFrontmatterthen treated the file as having no frontmatter and injected a second block at the top → duplicatename/description, corrupted body. This changed the file on every pull.The same LF-only assumption existed in 10 hand-written parse/inject sites across the codebase.
Changes
src/utils/frontmatter.ts— a single gray-matter-based helper (splitFrontmatter/parseFrontmatter/stripFrontmatter/hasFrontmatter/stringifyFrontmatter) that tolerates UTF-8 BOM, CRLF/LF, and malformed YAML (never throws).gray-matterwas already a dependency.resources/skills.ts,agent-skills.ts,skill-command.ts,source.ts,local-agent.ts,resources/marketplace.ts,codebase.ts,section-patcher.ts, and two spots inimport-repo.ts.FRONTMATTER_REGEXconstants and unusedyamlimports.Test Plan
npx tsc --noEmit— cleannpx vitest run— 147 files / 1846 tests pass, including new CRLF + BOM regression tests infrontmatter.test.tsandskills.test.tsname/descriptiononce each) with the body intact — no duplicate injection🤖 Generated with Claude Code