Mechanical rename produced by scripts/msd-rename.cjs: gsd/Gsd/GSD -> msd/Msd/MSD across contents and paths, upstream package/repo coordinates -> @golem15/msd-core and golem15com/msd-core. Deep links into upstream history, sibling upstream packages, the GSD-2 import feature, CHANGELOG.md and .changeset/ are kept as-is. Hand edits on top: MSD block-letter banner and logos, LICENSE copyright line, package/plugin identity, regenerated lockfile, install-tree fixtures, derived registries and benchmark baseline; migration checksum baseline re-locked (MSD keeps its own install state, so no install had applied the old sums); sort-order and regex-escaped expectations in tests adjusted.
186 lines
5.9 KiB
JavaScript
186 lines
5.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* lint-skill-deps.cjs
|
|
*
|
|
* Two checks:
|
|
*
|
|
* a) Frontmatter to body consistency:
|
|
* For each commands/msd/*.md, parse requires: and walk the body for
|
|
* references to other MSD skills (pattern: /msd:<stem> or msd:<stem>).
|
|
* Fail if a skill body references a skill not listed in requires:.
|
|
*
|
|
* b) Profile closure satisfaction:
|
|
* Load PROFILES from install-profiles.cjs. For each non-full profile,
|
|
* compute closure(profile.base) using the manifest. If any skill in
|
|
* the closure references a skill NOT in the closure, fail.
|
|
*
|
|
* Usage:
|
|
* node scripts/lint-skill-deps.cjs # scans commands/msd/
|
|
* node scripts/lint-skill-deps.cjs --dir <path> # scan a custom dir (testing)
|
|
*
|
|
* Exits 0 if all pass; exits 1 if any violation.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { runMain } = require('./lib/cli-exit.cjs');
|
|
|
|
const PROFILES_MODULE = path.join(__dirname, '..', 'msd-core', 'bin', 'lib', 'install-profiles.cjs');
|
|
const { PROFILES, loadSkillsManifest, resolveProfile } = require(PROFILES_MODULE);
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Argument parsing
|
|
// ---------------------------------------------------------------------------
|
|
|
|
let commandsDir = path.join(__dirname, '..', 'commands', 'msd');
|
|
const args = process.argv.slice(2);
|
|
for (let i = 0; i < args.length; i++) {
|
|
if (args[i] === '--dir' && args[i + 1]) {
|
|
commandsDir = args[i + 1];
|
|
i++;
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Reference extraction from skill body
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function extractBodyReferences(body) {
|
|
const refs = new Set();
|
|
const re = /(?:\/?)msd:([a-z0-9_-]+)/g;
|
|
let m;
|
|
while ((m = re.exec(body)) !== null) {
|
|
refs.add(m[1]);
|
|
}
|
|
return refs;
|
|
}
|
|
|
|
function extractBody(content) {
|
|
const fmEnd = content.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n/m);
|
|
if (!fmEnd) return content;
|
|
return content.slice(fmEnd[0].length);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Check a: frontmatter to body consistency
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function checkFrontmatterBodyConsistency(manifest, allStems) {
|
|
const violations = [];
|
|
|
|
for (const [stem, declared] of manifest) {
|
|
if (stem.startsWith('_calls_agents_')) continue;
|
|
const filePath = path.join(commandsDir, stem + '.md');
|
|
let content;
|
|
try {
|
|
content = fs.readFileSync(filePath, 'utf8');
|
|
} catch {
|
|
continue;
|
|
}
|
|
const body = extractBody(content);
|
|
const referenced = extractBodyReferences(body);
|
|
const declaredSet = new Set(declared);
|
|
for (const ref of referenced) {
|
|
if (ref === stem) continue;
|
|
if (!allStems.has(ref)) {
|
|
violations.push({
|
|
stem,
|
|
filePath,
|
|
undeclared: ref,
|
|
message: 'body references unknown skill msd:' + ref,
|
|
});
|
|
continue;
|
|
}
|
|
if (!declaredSet.has(ref)) {
|
|
violations.push({
|
|
stem,
|
|
filePath,
|
|
undeclared: ref,
|
|
message: 'body references msd:' + ref + ' but requires: does not list it',
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return violations;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Check b: profile closure satisfaction
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function checkProfileClosure(manifest) {
|
|
const violations = [];
|
|
|
|
for (const profileName of Object.keys(PROFILES)) {
|
|
const base = PROFILES[profileName];
|
|
if (base === '*') continue;
|
|
const resolved = resolveProfile({ modes: [profileName], manifest });
|
|
if (resolved.skills === '*') continue;
|
|
|
|
const closure = resolved.skills;
|
|
for (const stem of closure) {
|
|
const deps = manifest.get(stem) || [];
|
|
for (const dep of deps) {
|
|
if (!closure.has(dep)) {
|
|
violations.push({
|
|
profile: profileName,
|
|
stem,
|
|
missingDep: dep,
|
|
message: 'profile "' + profileName + '" includes "' + stem + '" which requires "' + dep + '", but "' + dep + '" is not in the closure',
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return violations;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Main
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function main() {
|
|
const manifest = loadSkillsManifest(commandsDir);
|
|
const allStems = new Set(
|
|
[...manifest.keys()].filter((k) => !k.startsWith('_calls_agents_'))
|
|
);
|
|
|
|
const consistencyViolations = checkFrontmatterBodyConsistency(manifest, allStems);
|
|
const closureViolations = checkProfileClosure(manifest);
|
|
|
|
const totalViolations = consistencyViolations.length + closureViolations.length;
|
|
|
|
if (totalViolations === 0) {
|
|
const checked = manifest.size;
|
|
process.stdout.write('ok lint-skill-deps: ' + checked + ' skill(s) checked, 0 violations\n');
|
|
return 0;
|
|
}
|
|
|
|
process.stderr.write('\nERROR lint-skill-deps: ' + totalViolations + ' violation(s) found\n\n');
|
|
|
|
if (consistencyViolations.length > 0) {
|
|
process.stderr.write('Frontmatter to body consistency violations (' + consistencyViolations.length + '):\n\n');
|
|
for (const v of consistencyViolations) {
|
|
process.stderr.write(' ' + v.filePath + '\n');
|
|
process.stderr.write(' ' + v.message + '\n\n');
|
|
}
|
|
process.stderr.write('Fix: add missing deps to requires: in the skill frontmatter.\n\n');
|
|
}
|
|
|
|
if (closureViolations.length > 0) {
|
|
process.stderr.write('Profile closure violations (' + closureViolations.length + '):\n\n');
|
|
for (const v of closureViolations) {
|
|
process.stderr.write(' ' + v.message + '\n');
|
|
}
|
|
process.stderr.write('\nFix: add the missing skills to the profile base set in install-profiles.cjs.\n\n');
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
runMain(main);
|