diff --git a/product/README.md b/product/README.md index 91175acf..90a49506 100644 --- a/product/README.md +++ b/product/README.md @@ -171,6 +171,7 @@ The same binary runs as a read-only MCP server (`drift_feed_status`, `pins_repor rugsnare skills scan # pin all skill files (SKILL.md, .mdc, etc.) rugsnare skills diff # exit 1 if anything changed rugsnare skills report # visual report in your browser +rugsnare skills report --json # same report data as JSON to stdout, for CI and other tools ``` Discovers skill files across Claude Code, Cursor, Windsurf, Continue, ZCode, Copilot, Codex, and Cline. When a skill changes after you approved it, the HTML report shows what was added/removed, classifies severity (DANGEROUS / REVIEW / SAFE), and explains in plain language why it matters. diff --git a/product/src/cli.js b/product/src/cli.js index 84ae0d17..26ed8d27 100644 --- a/product/src/cli.js +++ b/product/src/cli.js @@ -1329,8 +1329,13 @@ async function cmdSkills(flags) { } catch { /* MCP fetch failed - skills report still works */ } } - const { auditCurrentSkills } = await import('./skills-pin.js'); + const { auditCurrentSkills } = await import('./skills-pin.js'); const currentAudit = auditCurrentSkills(cwd, home); + if (flags.json) { + const { buildSkillsReportJson } = await import('./skills-report.js'); + console.log(JSON.stringify(buildSkillsReportJson(results, { mcpResults, currentAudit }), null, 2)); + return; + } const { reportPath, counts } = writeSkillsReport(results, cwd, mcpResults, currentAudit); console.log(`Report: ${reportPath}`); const totalBad = counts.dangerous + mcpResults.reduce((n, r) => n + r.verdicts.length, 0); diff --git a/product/src/skills-report.js b/product/src/skills-report.js index 57e6f0d1..8a7aecdc 100644 --- a/product/src/skills-report.js +++ b/product/src/skills-report.js @@ -272,6 +272,28 @@ ${mcpFindings.join('\n')}`; return { html, counts: { total: results.length, dangerous: dangerous.length, review: review.length, safe: safe.length, unchanged: unchanged.length, new: allNew.length, removed: removed.length } }; } +/** + * Machine-readable version of the same report data the HTML report uses. + * Returned as a plain object so callers can JSON.stringify it to stdout + * for CI pipelines and other tools. + */ +export function buildSkillsReportJson(results, { generatedAt, mcpResults = [], currentAudit = [] } = {}) { + const { counts } = generateSkillsReport(results, { generatedAt, mcpResults, currentAudit }); + return { + generatedAt: new Date(generatedAt ?? Date.now()).toISOString(), + counts, + skills: results.map((r) => ({ + key: r.key, + status: r.status, + severity: r.severity ?? null, + changes: r.changes ?? null, + advisory: r.advisory ? { score: r.advisory.score, signals: r.advisory.signals } : null, + })), + mcp: mcpResults, + currentAudit, + }; +} + /** * Write the report to a file and return the path. */ diff --git a/product/test/skills-pin.test.js b/product/test/skills-pin.test.js index 78f6706b..a58ff277 100644 --- a/product/test/skills-pin.test.js +++ b/product/test/skills-pin.test.js @@ -277,6 +277,30 @@ test('CLI: scan -> diff clean -> report', async () => { } finally { cleanup(); } }); +test('CLI: skills report --json outputs valid JSON to stdout', async () => { + const { dir, cleanup } = tmp(); + try { + mkdeploy(dir, CLEAN); + const s = await cli(dir, ['skills', 'scan']); + assert.equal(s.code, 0, s.stderr); + const r = await cli(dir, ['skills', 'report', '--json']); + assert.equal(r.code, 0, r.stderr); + const parsed = JSON.parse(r.stdout); + assert.equal(typeof parsed.generatedAt, 'string'); + assert.ok(!Number.isNaN(Date.parse(parsed.generatedAt))); + assert.equal(parsed.counts.total, parsed.skills.length); + assert.ok(parsed.skills.length >= 1); + for (const skill of parsed.skills) { + assert.equal(typeof skill.key, 'string'); + assert.ok(['UNCHANGED', 'DRIFT', 'NEW', 'REMOVED'].includes(skill.status)); + assert.ok('severity' in skill && 'changes' in skill && 'advisory' in skill); + } + assert.ok(Array.isArray(parsed.mcp)); + assert.ok(Array.isArray(parsed.currentAudit)); + assert.ok(!fs.existsSync(path.join(dir, '.rugsnare', 'skills-report.html'))); + } finally { cleanup(); } +}); + test('CLI: diff exit 1 on DANGEROUS', async () => { const { dir, cleanup } = tmp(); try {