Skip to content

fix(extensions): parse command frontmatter after a UTF-8 BOM - #5562

Merged
mnriem merged 1 commit into
github:mainfrom
leninworld:fix/command-frontmatter-bom
Nov 25, 2026
Merged

mnriem merged 1 commit into
github:mainfrom
leninworld:fix/command-frontmatter-bom

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

Description

CommandRegistrar.parse_frontmatter only recognizes frontmatter when the content starts with ---. Command files are read with read_text(encoding="utf-8"), which keeps a UTF-8 BOM, so a command saved as "UTF-8 with BOM" (for example by Windows PowerShell 5.1 Set-Content -Encoding UTF8, or an editor set to that encoding) is treated as having no frontmatter. Its description, scripts and other fields are lost, and the BOM plus the raw --- block end up in the body of the generated agent command.

Reproduction on main (specify init --here --integration claude, then specify extension add --dev ./ext where commands/hello.md is ---\r\ndescription: Say hello from a BOM file\r\n---\r\n\r\nSay hello to $ARGUMENTS\r\n). The generated .claude/skills/speckit-bomdemo-hello/SKILL.md has

description: 'Spec-kit workflow command: speckit-bomdemo-hello'
...
---

---
description: Say hello from a BOM file
---

Say hello to $ARGUMENTS

With this change it has description: Say hello from a BOM file and the body is just Say hello to $ARGUMENTS.

The fix ignores one leading U+FEFF when looking for the opening ---, similar to #2283 for agent context files (#5556 reports the same BOM class for the bundler's JSON readers). When no complete frontmatter follows (BOM without frontmatter, BOM-only content, two BOMs, or unterminated frontmatter), the original content is still returned unchanged, BOM included, so callers that use the returned body as-is (preset wrapping, skill rendering) see no change. A U+FEFF anywhere else in the file is left alone.

Testing

Set up this checkout's .venv and editable install using the local development guide. Run commands from the checkout root.

  • Tested locally with .venv/bin/specify --help (Windows PowerShell: .\.venv\Scripts\specify.exe --help)

  • Ran relevant existing tests with .venv/bin/python -m pytest tests -q (Windows PowerShell: .\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks and LC_ALL=en_US.UTF-8 on macOS

  • Tested with a sample project (if applicable)

  • New tests in tests/test_extensions.py: a parametrized parse_frontmatter test (BOM + LF and BOM + CRLF frontmatter; and four negative cases that must come back unchanged: BOM without frontmatter, two BOMs, BOM with unterminated frontmatter, a non-leading U+FEFF) and a register_commands test that a BOM-prefixed command keeps its description and writes no BOM. On main the 3 positive cases fail and the 4 negative cases pass; with the fix all 7 pass.

  • tests/test_extensions.py, tests/test_extension_skills.py: pass. Full suite with -n auto on macOS: 17231 passed, 635 skipped, 1 failed: test_version_execution.py::TestWindowsUvToolEnvironment::test_non_windows_uv_tool_dry_run_still_previews_installer, which fails on main in my environment too. (An earlier run also had the Ctrl-C capture tests in test_step_capture.py and test_capture.py fail under xdist; they pass when rerun.)

  • uvx ruff@0.15.0 check src tests: all checks passed.

  • Sample project: the specify init / specify extension add --dev reproduction above, before and after.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: The bug was found by OpenAI Codex CLI (model: gpt-5.6-sol, medium reasoning, autonomous, read-only code review), which also wrote the fix and tests (code generation); Claude Code made a small follow-up edit to the fix. Claude Code (model: Claude Opus 5.5, autonomous) reproduced the bug end to end, reviewed the change, ran the tests and lint, and wrote this description. The commit carries an Assisted-by: trailer.

parse_frontmatter only looked for "---" at offset 0, so a command file
saved as UTF-8 with BOM lost its frontmatter (description, scripts) and
the BOM plus the raw frontmatter block ended up in the generated agent
command. Ignore one leading BOM when looking for the opening delimiter;
content without complete frontmatter is still returned unchanged.

Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous)
Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
@leninworld
leninworld requested a review from mnriem as a code owner November 25, 2026 03:20
Copilot AI adaptive review requested due to automatic review settings November 25, 2026 03:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change to handle BOM-prefixed frontmatter.

No open issues 🎉

What changed in this PR

Fixes Spec Kit command parsing so a single leading UTF-8 byte-order mark (BOM) no longer prevents frontmatter metadata from reaching generated agent commands.

Changes:

  • Ignores one leading BOM when parsing complete frontmatter, while preserving original content when no complete frontmatter is found.
  • Adds regression coverage for LF/CRLF inputs, unchanged fallback cases, and Claude command registration.
File Description
tests/​test_extensions.py Adds parser and command-registration regression tests for BOM-prefixed input.
src/​specify_cli/​agents.py Recognizes frontmatter after a single leading BOM.

Review effort: Balanced (adaptive)

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 25, 2026
@mnriem
mnriem requested a balanced review from Copilot November 25, 2026 15:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The BOM-aware frontmatter parsing change has no active review issues.

No open issues 🎉

Review effort: Balanced

@mnriem
mnriem merged commit 7609822 into github:main Nov 25, 2026
14 checks passed
@mnriem

mnriem commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

mnriem pushed a commit that referenced this pull request Nov 25, 2026
* fix(presets): detect command frontmatter after a UTF-8 BOM

PresetResolver only recognised command frontmatter when the first line
was exactly "---". A preset command saved as UTF-8 with BOM therefore
had its frontmatter `strategy:` ignored (an append/prepend/wrap command
replaced the core command), and with a manifest strategy the BOM and
the raw frontmatter block were composed into the command body.

Ignore one leading BOM when looking for the opening delimiter in the
legacy strategy fallback and in resolve_content's frontmatter split,
as #5562 did for CommandRegistrar.parse_frontmatter. Content without a
complete frontmatter block is still composed unchanged.

Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous)
Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)

* test(presets): write BOM command fixtures as UTF-8

_create_pack wrote command files with the platform default encoding, so the new BOM cases raised UnicodeEncodeError before reaching the resolver where the default is cp1252 (e.g. Windows).

Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)

Assisted-by: OpenAI Codex CLI (model: gpt-5.6-sol, autonomous)

---------

Co-authored-by: Lenin Mookiah <2639584+leninworld@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants