Skip to content

fix(frontmatter): handle CRLF and BOM in SKILL.md parsing - #378

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:fix/frontmatter-crlf-bom-injection
Sep 1, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:fix/frontmatter-crlf-bom-injection

Conversation

@m0Nst3r873

Copy link
Copy Markdown
Collaborator

Summary

Fixes #372 — SKILL.md files with CRLF line endings or a UTF-8 BOM were corrupted on pull/push with 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 ^---\n failed to match. ensureSkillFrontmatter then treated the file as having no frontmatter and injected a second block at the top → duplicate name/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

  • New 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-matter was already a dependency.
  • Migrated all 10 hand-written frontmatter sites to the helper: 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 in import-repo.ts.
  • Removed the now-orphaned FRONTMATTER_REGEX constants and unused yaml imports.

Test Plan

  • npx tsc --noEmit — clean
  • npx vitest run — 147 files / 1846 tests pass, including new CRLF + BOM regression tests in frontmatter.test.ts and skills.test.ts
  • Real-CLI e2e against the built artifact: CRLF, BOM, and missing-field SKILL.md fixtures each produce exactly one frontmatter block (name/description once each) with the body intact — no duplicate injection

🤖 Generated with Claude Code

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
m0Nst3r873 force-pushed the fix/frontmatter-crlf-bom-injection branch from a6cc4dd to dc77451 Compare September 1, 2026 09:45
@jeff-r2026
jeff-r2026 merged commit 1bbb376 into Tencent:main Sep 1, 2026
7 checks passed
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
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] 换行符不一致导致skill有两份名字跟描述,正则只匹配LF

2 participants