Repository navigation
fix(extensions): parse command frontmatter after a UTF-8 BOM - #5562
Merged
Merged
Conversation
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)
Contributor
There was a problem hiding this comment.
🟢 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)
Collaborator
|
Thank you! |
4 of 5 tasks
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>
4 of 5 tasks
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.
Description
CommandRegistrar.parse_frontmatteronly recognizes frontmatter when the content starts with---. Command files are read withread_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.1Set-Content -Encoding UTF8, or an editor set to that encoding) is treated as having no frontmatter. Itsdescription,scriptsand 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, thenspecify extension add --dev ./extwherecommands/hello.mdis---\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.mdhasWith this change it has
description: Say hello from a BOM fileand the body is justSay 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
.venvand 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 andLC_ALL=en_US.UTF-8on macOSTested with a sample project (if applicable)
New tests in
tests/test_extensions.py: a parametrizedparse_frontmattertest (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 aregister_commandstest 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 autoon 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 intest_step_capture.pyandtest_capture.pyfail 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 --devreproduction above, before and after.AI Disclosure
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.