Skip to content

Commit 2990c00

Browse files
authored
fix(skills): tolerate BOM-prefixed frontmatter
Fixes #66479. Workspace skills whose SKILL.md starts with a UTF-8 BOM now keep their shared markdown frontmatter metadata, so they remain discoverable through skills list. The fix strips one leading BOM at the parser boundary and adds parser plus workspace discovery regression coverage. Thanks @jbetala7 for the fix. Co-authored-by: Jayesh Betala <[email protected]>
1 parent 35cdd40 commit 2990c00

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/agents/skills.loadworkspaceskillentries.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,18 @@ describe("loadWorkspaceSkillEntries", () => {
370370
description: "Hidden prompt entry",
371371
frontmatterExtra: "disable-model-invocation: true",
372372
});
373+
const bomSkillDir = path.join(workspaceDir, "skills", "bom-skill");
374+
await fs.mkdir(bomSkillDir, { recursive: true });
375+
await fs.writeFile(
376+
path.join(bomSkillDir, "SKILL.md"),
377+
"\uFEFF---\nname: bom-skill\ndescription: BOM-prefixed skill\n---\n\n# BOM skill\n",
378+
"utf8",
379+
);
373380

374381
const entries = loadTestWorkspaceSkillEntries(workspaceDir);
375382

376383
expect(entries.map((entry) => entry.skill.name)).toContain("fallback-name");
384+
expect(entries.map((entry) => entry.skill.name)).toContain("bom-skill");
377385
const hiddenEntry = entries.find((entry) => entry.skill.name === "hidden-skill");
378386

379387
expect(hiddenEntry?.invocation?.disableModelInvocation).toBe(true);

‎src/markdown/frontmatter.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,12 @@ metadata:
101101
const content = "# No frontmatter";
102102
expect(parseFrontmatterBlock(content)).toStrictEqual({});
103103
});
104+
105+
it("parses frontmatter after a leading UTF-8 BOM", () => {
106+
const content = "\uFEFF---\nname: windows-skill\ndescription: Written by PowerShell\n---\n";
107+
const result = parseFrontmatterBlock(content);
108+
109+
expect(result.name).toBe("windows-skill");
110+
expect(result.description).toBe("Written by PowerShell");
111+
});
104112
});

‎src/markdown/frontmatter.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ function shouldPreferInlineLineValue(params: {
181181
}
182182

183183
function extractFrontmatterBlock(content: string): string | undefined {
184-
const normalized = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
184+
const normalized = content
185+
.replace(/^\uFEFF/, "")
186+
.replace(/\r\n/g, "\n")
187+
.replace(/\r/g, "\n");
185188
if (!normalized.startsWith("---")) {
186189
return undefined;
187190
}

0 commit comments

Comments
 (0)