[Bug] A UTF-8 BOM makes agents.config.json, preferences and command frontmatter silently unreadable
Summary
Files that start with a UTF-8 byte order mark are not parsed. The config and preferences files become "unreadable", and a command's frontmatter is treated as part of the prompt body.
Steps to reproduce
- Write
agents.config.jsonwith a leading BOM (\uFEFF), for example with Windows PowerShell 5.1Set-Content -Encoding UTF8. Setnanocoder.retries.maxEmptyTurnsto 7. - Run
nanocoder config show nanocoder.retries.maxEmptyTurnsandnanocoder config diff. - Create
.nanocoder/commands/bomcmd.mdthat starts with a BOM, then---,description: BOM command,aliases:with- bc, then---and a body. - Load it with the command parser.
Expected behaviour
BOM files load like the same file without a BOM (value 7; description and aliases read from the frontmatter).
Actual behaviour
nanocoder.retries.maxEmptyTurns
value 2 <- default; 7 expected
layer default
config diff: global ...\agents.config.json unreadable: Unexpected token '', "{"nanocod"... is not valid JSON
The BOM command parses with no metadata, and its content is ---\ndescription: BOM command\naliases:\n - bc\n---\nDo the thing. A spec calling splitFrontmatter('\uFEFF---\ndescription: Hello\n---\nBody') fails:
t.true(r.hasFrontmatter) -> Value is not `true`: false
nanocoder-preferences.json with a BOM is also reported as unreadable.
Environment
Windows 11, Node v22.22.3, Nanocoder 1.31.0 (main at 948a4e74)
Suggested fix
source/config/index.ts:81: strip a leading\uFEFFbeforeJSON.parse. Do the same in the preferences reader.source/utils/frontmatter.ts:22-27: strip it at the start ofsplitFrontmatter.source/custom-commands/parser.ts:209is one caller.source/skills/install.ts:262already strips a BOM for the skills index. Move that into one shared read helper and use it everywhere.
Hi @bfs2021 @Mahdi-Hasan , thanks for your contributions! Please don’t open a PR without first commenting on the issue and being assigned to it. That keeps us from duplicate work and makes sure the approach is agreed on before you spend time on it. Thanks for understanding!
Hi @addyCooks, noted. Just to clarify, I don't have a PR for this one, and I'll leave it to #1946. Going forward I'll comment and wait for assignment before opening anything.
Thanks @Mahdi-Hasan, appreciated. And thanks for picking up the "comment and wait for assignment" flow.
@bfs2021 your PR #1946 is the only one for this issue, so we'll keep it. It currently has a merge conflict with main, so please merge main into your branch, and I'll take another look. If you'd like to be assigned to this issue, say so here.
Thanks !
Hi! I'd like to work on this.
Plan, similar to what #1946 sketched:
- Add a shared
stripUtf8Bom()helper and run file contents through it beforeJSON.parseat theagents.config.json,nanocoder-preferences.jsonand.mcp.jsonread sites insource/config/, and before frontmatter splitting insource/utils/frontmatter.tsso custom commands, subagents, tools and skills all benefit. - Update the
parseCommandFile handles file with BOMspec (it currently asserts the broken behaviour) and add regression specs for the config and preferences paths. - Patch changeset.
Could you assign it to me? Happy to adjust the approach if you'd rather strip at a different layer.