Skip to content

fix(subagents): read frontmatter from files saved with a UTF-8 BOM - #2516

Merged
vastsa merged 3 commits into
vastsa:mainfrom
Abhiram-745:fix/subagent-definition-bom
Nov 23, 2026
Merged

vastsa merged 3 commits into
vastsa:mainfrom
Abhiram-745:fix/subagent-definition-bom

Conversation

@Abhiram-745

Copy link
Copy Markdown
Contributor

Summary / 概要

A subagent definition or prompt template saved as "UTF-8 with BOM" loses its frontmatter. Windows editors can save files this way: older Notepad does by default, and VS Code or Notepad++ do when set to it.

Both loaders read the file with readFile(path, "utf8"), which keeps a leading \uFEFF. The frontmatter checks then fail on the first character:

  • parseSubagentDefinition (packages/shared/src/subagent-definition.ts, splitFrontmatter): startsWith("---\n") is false, so the whole file is treated as the body and the parse fails with missing `description` . The subagent never reaches the Task catalog, and the diagnostic points at a field that is in the file.
  • Prompt templates (packages/agent-runtime/src/prompt-templates.ts, parsePrompt): the template loads with no description, and the --- frontmatter block shows up in the template body.
parseSubagentDefinition("\uFEFF---\nname: code-reviewer\ndescription: Reviews a diff.\n---\nReview it.", …)
// before: { ok: false, … missing `description` }
// after:  { ok: true, definition: { name: "code-reviewer", description: "Reviews a diff.", … } }

Fix: strip one leading \uFEFF before looking for frontmatter. This is the same thing splitModeDocument in packages/agent-runtime/src/mode-definitions.ts already does for mode documents. Files without a BOM are handled exactly as before.

Requirement link / 需求关联

  • Small, self-contained fix. I didn't open an issue for it; happy to open one if you prefer.
  • No spec, ADR, protocol or persistence change. No UI change.

Validation

On a worktree from latest origin/main (pnpm check:pr-base passes):

  • New regression tests:
    • packages/shared/src/subagent-definition.test.ts: parses a BOM-prefixed definition.
    • packages/agent-runtime/src/prompt-templates.test.ts: loads a BOM-prefixed template file through loadComposerTemplates.
    • Both fail on main and pass with the fix.
  • packages/shared: vitest run gives 116 files and 1478 tests passed. tsc --noEmit is clean.
  • packages/agent-runtime: vitest run gives 2122 of 2123 passed, and tsc --noEmit is clean. The one failure, system-ca.test.ts > applyAdditiveDefaultCaCertificates keeps pre-existing default roots, depends on this machine's system CA store and also fails on main here.
  • pnpm lint: clean.
  • pnpm test:e2e:subagents: 34/34 checks passed.
  • pnpm test:e2e:composer-autocomplete: passes.

@vastsa
vastsa merged commit 866ac6e into vastsa:main Nov 23, 2026
5 checks passed
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.

2 participants