Files
ruflo/scripts/audit-plugin-manifest.mjs
T
chaitanya-y20 13af5f1208 chore(plugins): give every plugin manifest a repository field
44 of the 48 `plugins/*/.claude-plugin/plugin.json` manifests had no
`repository`, while the four that do already point at the repo URL their
`homepage` names. The field is what the directory listing and
`npm view` read, and its absence is invisible until something reads it.

Add it to the 44 that lack it, then make `scripts/audit-plugin-manifest.mjs`
enforce it so the next plugin cannot ship without one:

- check 6 in the script header, the violation in `auditManifest`, and the
  clean-run summary line. A manifest may carry the repository as a string or
  as an object's `url`; anything else is reported as missing, and a value that
  is not an http(s) URL is reported separately.
- the required-field lists in `create-plugin` and `validate-plugin` skills, so
  a scaffolded plugin passes the gate it is told to satisfy.

Verified with the repo's own gates:

- `node scripts/audit-plugin-manifest.mjs` scans 48 manifests, clean.
- removing the field from one manifest reports `repository field: missing or
  empty` and exits 1; setting it to `ruvnet/ruflo` reports `repository is a URL`
  and exits 1; restoring it exits 0.
- `node scripts/check-plugin-manifests.mjs` is unchanged by this diff (its two
  nested-manifest findings belong to `ruflo-ai-team/directory` and
  `ruflo-x-gateway/directory`, which this change does not touch).
- `node scripts/audit-plugin-secrets.mjs` clean, 48 manifests.

No plugin version is bumped: the installed artifact's behaviour does not change
and no user-visible surface reads the field from an installed copy, so there is
nothing for a version bump to deliver. The `Plugin version bump` workflow will
flag the 44 manifests it sees as shipped files, and this PR needs the
`skip-plugin-version-check` label rather than 44 unrelated version bumps that
would collide with each plugin's own release cadence.

Closes #4774
2026-11-05 09:25:38 +05:30

188 lines
6.4 KiB
JavaScript
Executable File

#!/usr/bin/env node
// audit-plugin-manifest — fleet-wide check on plugins/*/.claude-plugin/plugin.json.
//
// Each plugin's own smoke step 1 sentinel pins the EXPECTED version of
// its own plugin.json (e.g. cost-tracker hardcodes "expected 0.26.0").
// What no per-plugin smoke catches:
// - A plugin.json with non-semver version (e.g. "1.0", "1.0.0-alpha",
// "latest") — would break dist-tag publishing logic.
// - name field doesn't match the enclosing directory (drift after rename).
// - Required field empty (smoke 1 checks `"version"` presence via grep
// but not that it has a value).
// - A new plugin authored without ANY plugin.json (no smoke means no
// coverage at all).
//
// USAGE
// node scripts/audit-plugin-manifest.mjs # all plugins
// node scripts/audit-plugin-manifest.mjs --format json # CI-consumable
// node scripts/audit-plugin-manifest.mjs --only ruflo-cost-tracker
//
// CHECKS per plugins/<name>/.claude-plugin/plugin.json
// 1. File exists and parses as JSON.
// 2. Required fields present and non-empty: name / version / description.
// 3. version matches semver (N.N.N optionally with +/- suffix).
// 4. name matches the enclosing directory name (drift after rename).
// 5. keywords is an array (may be empty, but must be present).
// 6. repository is present and an http(s) URL, as a string or as an
// object's url: the directory listing and `npm view` both read it.
//
// EXIT CODES
// 0 all manifests clean
// 1 at least one violation
// 2 scan error (no plugins dir)
import { readdirSync, statSync, readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const SCRIPTS_DIR = dirname(fileURLToPath(import.meta.url));
const REPO_ROOT = dirname(SCRIPTS_DIR);
const PLUGINS_DIR = join(REPO_ROOT, 'plugins');
const ARGS = (() => {
const a = { format: 'table', only: null };
for (let i = 2; i < process.argv.length; i++) {
const v = process.argv[i];
if (v === '--format') a.format = process.argv[++i];
else if (v === '--only') {
a.only = new Set((process.argv[++i] || '').split(',').map((s) => s.trim()).filter(Boolean));
}
}
return a;
})();
const SEMVER_RE = /^\d+\.\d+\.\d+([+-][\w.-]+)?$/;
const REPO_URL_RE = /^https?:\/\/\S+$/i;
function existsSync(p) {
try { statSync(p); return true; } catch { return false; }
}
function discoverManifests() {
const out = [];
let plugins;
try { plugins = readdirSync(PLUGINS_DIR); } catch { return out; }
for (const plugin of plugins) {
if (ARGS.only && !ARGS.only.has(plugin)) continue;
const dir = join(PLUGINS_DIR, plugin);
let s;
try { s = statSync(dir); } catch { continue; }
if (!s.isDirectory()) continue;
const manifest = join(dir, '.claude-plugin', 'plugin.json');
// Only include plugins that opt into the SKILL convention (presence
// of .claude-plugin/). TS-source plugins like ruflo-arena have
// package.json instead — skip them silently.
if (!existsSync(manifest)) continue;
out.push({ plugin, path: manifest });
}
return out.sort((a, b) => a.plugin.localeCompare(b.plugin));
}
function auditManifest(entry) {
const violations = [];
let raw;
try { raw = readFileSync(entry.path, 'utf-8'); }
catch (e) {
violations.push({ check: 'readable', detail: e.message });
return violations;
}
let json;
try { json = JSON.parse(raw); }
catch (e) {
violations.push({ check: 'valid JSON', detail: e.message.slice(0, 120) });
return violations;
}
if (!json.name) violations.push({ check: 'name field', detail: 'missing or empty' });
if (json.name && json.name !== entry.plugin) {
violations.push({
check: 'name matches directory',
detail: `manifest name="${json.name}" but plugin dir is "${entry.plugin}"`,
});
}
if (!json.version) violations.push({ check: 'version field', detail: 'missing or empty' });
else if (!SEMVER_RE.test(json.version)) {
violations.push({
check: 'version semver',
detail: `"${json.version}" doesn't match X.Y.Z[±suffix]`,
});
}
if (!json.description) violations.push({ check: 'description field', detail: 'missing or empty' });
if (json.description && json.description.length < 10) {
violations.push({
check: 'description meaningful',
detail: `"${json.description}" is suspiciously short (< 10 chars)`,
});
}
if (!Array.isArray(json.keywords)) {
violations.push({ check: 'keywords is array', detail: `got ${typeof json.keywords}` });
}
const repository = typeof json.repository === 'string' ? json.repository : json.repository?.url;
if (!repository) {
violations.push({ check: 'repository field', detail: 'missing or empty' });
} else if (!REPO_URL_RE.test(repository)) {
violations.push({ check: 'repository is a URL', detail: `"${repository}" is not an http(s) URL` });
}
return violations;
}
function main() {
const manifests = discoverManifests();
if (manifests.length === 0) {
console.error('audit-plugin-manifest: no plugins/*/.claude-plugin/plugin.json found');
process.exit(2);
}
const findings = [];
for (const m of manifests) {
const v = auditManifest(m);
if (v.length > 0) {
findings.push({
plugin: m.plugin,
file: m.path.replace(REPO_ROOT + '/', ''),
violations: v,
});
}
}
if (ARGS.format === 'json') {
console.log(JSON.stringify({
manifestsScanned: manifests.length,
filesWithViolations: findings.length,
findings,
generatedAt: new Date().toISOString(),
}, null, 2));
} else {
console.log('# audit-plugin-manifest');
console.log('');
console.log(`Scanned **${manifests.length}** plugin manifests.`);
console.log('');
if (findings.length === 0) {
console.log('✓ Every plugin.json:');
console.log(' - parses as JSON');
console.log(' - has name / version / description / keywords[] / repository');
console.log(' - name matches the enclosing directory');
console.log(' - version matches semver X.Y.Z[±suffix]');
} else {
console.log(`⚠ Found ${findings.length} manifest(s) with violations:`);
console.log('');
for (const f of findings) {
console.log(`## ${f.file}`);
for (const v of f.violations) {
console.log(` - ${v.check}: ${v.detail}`);
}
console.log('');
}
}
console.log('');
}
process.exit(findings.length > 0 ? 1 : 0);
}
main();