Skip to content

fix: read hand-written settings files that start with a byte-order mark - #67

Merged
blockmandev merged 1 commit into
mainfrom
fix/bom-authored-files
Oct 24, 2026
Merged

blockmandev merged 1 commit into
mainfrom
fix/bom-authored-files

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Found while trying #22 by hand on Windows.

The bug

A UTF-8 file can start with an invisible byte-order mark (U+FEFF). Windows PowerShell 5.1's Set-Content -Encoding utf8 writes one, and so do some editors. incode read hand-written files with std::fs::read_to_string and parsed them as they came, so:

  • Plugins: incode plugin add refused the plugin with "name is missing".
  • Custom commands: the front matter was not recognised, so allowed-tools was silently not applied, and a "Read only" command could use every tool.
  • Settings files: admin.json, mcp.json/.mcp.json, the project's .incode/settings.json (permission rules), managed.toml, guards.json, contracts.json and lifecycle.json were refused or ignored.
  • First line dropped: the first keybinding, the first VERIFICATION.md check and the first spec/PRD heading.

Only the agent-definition reader (subagents.rs) handled the mark.

The fix

One reader, text::read_authored, drops a leading mark and keeps read_to_string's errors. Every reader of a hand-written file now uses it. A mark in the middle of a file is kept.

Verified

  • Reproduced first: the official v0.1.0 refused a plugin whose manifest had the mark (first bytes 239 187 191), and installed the same plugin without it (the control).
  • New tests: 8 tests drive the real loaders with such a file (plugin install, command allowed-tools, admin, MCP, a project deny rule, a keybinding, a verification check, the reader itself). All 8 fail with the fix disabled and pass with it.
  • Local gate: fmt and clippy -D warnings clean; cargo test 2335 lib + 59 bin passed.

…rk (refs #22)

Root cause: every reader of a file a person writes by hand called
std::fs::read_to_string and parsed the text as it came. Windows PowerShell
5.1's `Set-Content -Encoding utf8` and some editors start a UTF-8 file with
U+FEFF; str::trim keeps it and serde_json/toml refuse it. So:

- a plugin manifest was refused with "`name` is missing" (found by hand
  under #22);
- a custom command's front matter was not recognised, so its allowed-tools
  were silently not applied and the command ran with every tool;
- admin settings, MCP server files, the project's permission settings,
  managed settings, guards, contracts and lifecycle files were refused or
  ignored; the first keybinding, the first verification check and the first
  spec/PRD heading were dropped.

Only subagents.rs stripped the mark. Now one reader, text::read_authored,
drops a leading mark and keeps read_to_string's errors, and every
hand-authored reader uses it. A mark inside the text is kept.

Tests: one per consequential reader (plugin install, command allowed-tools,
admin, MCP, project deny rule, keybinding, verification check) plus the
reader itself; all 8 fail with the strip disabled.
@blockmandev
blockmandev merged commit 5d64e1f into main Oct 24, 2026
12 checks passed
@blockmandev
blockmandev deleted the fix/bom-authored-files branch October 24, 2026 03:56
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.

1 participant