Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function runChecks(
diagnostics.push(...checkToolsOverloaded(v));
diagnostics.push(...checkDescriptionLength(v));
diagnostics.push(...checkNameDrift(v));
diagnostics.push(...checkEmptyBody(v));
}

diagnostics.push(...checkCollisions(validated));
Expand Down Expand Up @@ -144,6 +145,20 @@ function checkNameDrift(v: ValidatedSkill): Diagnostic[] {
return [];
}

function checkEmptyBody(v: ValidatedSkill): Diagnostic[] {
if (v.body.trim().length === 0) {
return [
{
severity: "warn",
rule: "empty-body",
message: "skill body is empty; add instructions for Claude to follow",
file: v.file,
},
];
}
return [];
}

function tokenize(s: string): Set<string> {
return new Set(
s
Expand Down
8 changes: 8 additions & 0 deletions src/sarif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export const RULES: readonly SarifRule[] = [
helpUri: HELP_BASE,
defaultLevel: "warning",
},
{
id: "empty-body",
name: "emptyBody",
shortDescription:
"Skill body is empty; the file has frontmatter but no instructions for Claude.",
helpUri: HELP_BASE,
defaultLevel: "warning",
},
];

const SEVERITY_TO_LEVEL: Record<Severity, SarifLevel> = {
Expand Down
33 changes: 33 additions & 0 deletions test/checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,37 @@ describe("runChecks", () => {
const d = ds.find((d) => d.rule === "tools-overloaded");
expect(d?.message).toContain("11");
});

it("warns when skill body is empty", () => {
const s = mkSkill("/test/foo/foo.md", {
name: "foo",
description: "do the foo thing",
}, "");
const ds = runChecks([s], config);
expect(ds.some((d) => d.rule === "empty-body")).toBe(true);
});

it("warns when skill body is whitespace only", () => {
const s = mkSkill("/test/foo/foo.md", {
name: "foo",
description: "do the foo thing",
}, " \n\n ");
const ds = runChecks([s], config);
expect(ds.some((d) => d.rule === "empty-body")).toBe(true);
});

it("does not warn on empty-body when body has content", () => {
const s = mkSkill("/test/foo/foo.md", {
name: "foo",
description: "do the foo thing",
}, "Use Read to read a file, then summarize it.");
const ds = runChecks([s], config);
expect(ds.find((d) => d.rule === "empty-body")).toBeUndefined();
});

it("does not fire empty-body when frontmatter is invalid", () => {
const s = mkSkill("/test/foo/foo.md", { name: "foo" }, "");
const ds = runChecks([s], config);
expect(ds.find((d) => d.rule === "empty-body")).toBeUndefined();
});
});