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
66 changes: 64 additions & 2 deletions lib/skill-check.gen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions lib/skill-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const fs = require("fs");
const path = require("path");
const { execFileSync } = require("child_process");
const { checkSkillFormat, SKILL_FILE_NAMES, BUILT_FROM } = require("./skill-check.gen");
const { changelogWarnings, checkSkillFormat, SKILL_FILE_NAMES, BUILT_FROM } = require("./skill-check.gen");

const SAID = {
none: "No skill here: the repo needs one top-level folder with a SKILL.md.",
Expand Down Expand Up @@ -81,6 +81,18 @@ function findSkill(dir, entries) {
return { dir: path.join(dir, folder), folder, entries: inside };
}

/** The release-notes format's warnings for the CHANGELOG.md beside the skill: in its folder, else at the repo's
* top, with the repo's v<major>.<minor>.<patch> tags so a tag with no section is named. None when there's no file. */
function changelog(top, dir) {
const file = [path.join(dir, "CHANGELOG.md"), path.join(top, "CHANGELOG.md")].find((p) => kindOf(p) === "file");
if (!file) return [];
let tags = [];
try {
tags = execFileSync("git", ["-C", top, "tag", "--list", "v*"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).split("\n").filter(Boolean);
} catch (_) { /* not a git repo: no tags to check */ }
return changelogWarnings(fs.readFileSync(file, "utf8"), tags);
}

/** The check, as data: what `--json` prints. */
function lint(target) {
if (!isDir(target)) throw new Error(`${target} isn't a folder`);
Expand All @@ -98,6 +110,7 @@ function lint(target) {
const mismatch = `SKILL.md: Directory name '${where.folder}' must match skill name '`;
const problems = r.problems.map((p) => (p.startsWith(mismatch) && p.endsWith("'") ? SAID.differ(where.folder, p.slice(mismatch.length, -1)) : p));
const f = r.facts;
const warnings = [...r.warnings.filter((w) => !w.startsWith("CHANGELOG.md")), ...changelog(target, where.dir)];
return {
ok: problems.length === 0,
folder: shown,
Expand All @@ -106,7 +119,7 @@ function lint(target) {
files: f ? f.files.length : files.length,
bytes: files.reduce((n, x) => n + x.bytes.length, 0),
problems,
warnings: r.warnings,
warnings,
spec_valid: r.spec_valid,
spec_problems: r.spec_problems,
declares: r.declares,
Expand Down
2 changes: 1 addition & 1 deletion scripts/skill-check-bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const here = dirname(fileURLToPath(import.meta.url));
export const OUT = join(here, "..", "lib", "skill-check.gen.js");
/** The only files of the app's repo the bundle may hold. */
export const SOURCES = ["shared/skill-format.ts", "shared/skill-files.ts"];
const ENTRY = `export { checkSkillFormat, DECLARED_KEYS, SKILL_FILE_NAMES, SKILL_FORMAT_LIMITS } from "./shared/skill-format";
const ENTRY = `export { changelogWarnings, checkSkillFormat, DECLARED_KEYS, SKILL_FILE_NAMES, SKILL_FORMAT_LIMITS } from "./shared/skill-format";
`;

/** Where the app's repo is: --core, $SPACESHEEP_CORE, or ../spacesheep beside this repo. */
Expand Down
19 changes: 19 additions & 0 deletions test/skill-lint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ test("a repo: the one top-level skill folder is checked, and the repo's own file
assert.strictEqual(c.hash, lint(path.join(root, "my-skill")).hash);
});

test("the repo's CHANGELOG.md is held to Keep a Changelog 1.1, with its tags: warnings, never a refusal", () => {
const good = "# Changelog\n\n## [Unreleased]\n\n## [1.0.0] - 2026-11-27\n\n### Added\n\n- The first release.\n\n[1.0.0]: https://example.com\n";
const root = write({ ...skill(), "CHANGELOG.md": good });
const git = (...a) => execFileSync("git", ["-C", root, ...a], { stdio: "ignore" });
execFileSync("git", ["init", "-q", root]);
git("add", "-A");
git("-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "-qm", "one");
git("tag", "v1.0.0");
assert.deepStrictEqual(lint(root).warnings.filter((w) => w.startsWith("CHANGELOG.md")), []);
git("tag", "v1.1.0");
fs.appendFileSync(path.join(root, "CHANGELOG.md"), "\n## v2.0.0\n- x\n");
const c = lint(root);
assert.strictEqual(c.ok, true);
assert.deepStrictEqual(c.warnings.filter((w) => w.startsWith("CHANGELOG.md")), [
'CHANGELOG.md: "## v2.0.0" isn\'t a release heading: write ## [X.Y.Z] - YYYY-MM-DD',
"CHANGELOG.md: the tag v1.1.0 has no ## [1.1.0] section",
]);
});

test("the three refusals are the import's words, and refuse", () => {
const none = lint(write({ "README.md": "# Nothing\n", "docs/a.md": "a\n" }));
assert.deepStrictEqual([none.ok, none.problems], [false, [SAID.none]]);
Expand Down