Skip to content

Commit 4e605f8

Browse files
t3dotggclaude
andcommitted
Skip skills with malformed frontmatter instead of renaming them
A SKILL.md whose frontmatter fails to parse won't load in Claude Code, so surfacing it in the picker under its directory name advertised a skill the runtime can't run. Distinguish missing frontmatter (directory name fallback still applies) from malformed frontmatter (entry skipped). Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 97d4a66 commit 4e605f8

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎apps/server/src/provider/Drivers/ClaudeSkills.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
9393
}),
9494
);
9595

96-
it.effect("falls back to the directory name and tolerates malformed frontmatter", () =>
96+
it.effect("falls back to the directory name and skips malformed frontmatter", () =>
9797
Effect.gen(function* () {
9898
const fs = yield* FileSystem.FileSystem;
9999
const path = yield* Path.Path;
@@ -109,14 +109,14 @@ it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
109109

110110
const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
111111

112+
// A skill with no frontmatter falls back to its directory name; a skill
113+
// whose frontmatter fails to parse is skipped entirely (Claude Code
114+
// won't load it either).
112115
assert.deepEqual(
113116
skills.map((skill) => skill.name),
114-
["broken-yaml", "no-frontmatter"],
115-
);
116-
assert.equal(
117-
skills.every((skill) => skill.description === undefined),
118-
true,
117+
["no-frontmatter"],
119118
);
119+
assert.equal(skills[0]?.description, undefined);
120120
}),
121121
);
122122

‎apps/server/src/provider/Drivers/ClaudeSkills.ts‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,32 @@ type ClaudeSkillScope = "user" | "project";
2424

2525
const FRONTMATTER_PATTERN = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
2626

27-
function parseSkillFrontmatter(contents: string): {
28-
readonly name?: string;
29-
readonly description?: string;
30-
} {
27+
type SkillFrontmatter =
28+
| { readonly kind: "missing" }
29+
| { readonly kind: "malformed" }
30+
| { readonly kind: "parsed"; readonly name?: string; readonly description?: string };
31+
32+
function parseSkillFrontmatter(contents: string): SkillFrontmatter {
3133
const match = FRONTMATTER_PATTERN.exec(contents);
3234
if (!match) {
33-
return {};
35+
return { kind: "missing" };
3436
}
3537

3638
let parsed: unknown;
3739
try {
3840
parsed = parseYamlDocument(match[1] ?? "");
3941
} catch {
40-
return {};
42+
return { kind: "malformed" };
4143
}
4244
if (typeof parsed !== "object" || parsed === null) {
43-
return {};
45+
return { kind: "malformed" };
4446
}
4547

4648
const record = parsed as Record<string, unknown>;
4749
const name = typeof record.name === "string" ? record.name.trim() : "";
4850
const description = typeof record.description === "string" ? record.description.trim() : "";
4951
return {
52+
kind: "parsed",
5053
...(name ? { name } : {}),
5154
...(description ? { description } : {}),
5255
};
@@ -111,7 +114,14 @@ export const discoverClaudeSkills = Effect.fn("discoverClaudeSkills")(function*
111114
}
112115

113116
const frontmatter = parseSkillFrontmatter(contents);
114-
const name = frontmatter.name ?? entry.trim();
117+
// Malformed frontmatter means the skill won't load in Claude Code
118+
// either — skip it rather than surfacing a broken entry under its
119+
// directory name.
120+
if (frontmatter.kind === "malformed") {
121+
continue;
122+
}
123+
124+
const name = (frontmatter.kind === "parsed" ? frontmatter.name : undefined) ?? entry.trim();
115125
if (!name) {
116126
continue;
117127
}
@@ -121,7 +131,9 @@ export const discoverClaudeSkills = Effect.fn("discoverClaudeSkills")(function*
121131
path: skillPath,
122132
enabled: true,
123133
scope: root.scope,
124-
...(frontmatter.description ? { description: frontmatter.description } : {}),
134+
...(frontmatter.kind === "parsed" && frontmatter.description
135+
? { description: frontmatter.description }
136+
: {}),
125137
});
126138
}
127139
}

0 commit comments

Comments
 (0)