diff --git a/packages/cli/src/commands/check.ts b/packages/cli/src/commands/check.ts index c6d338a2..35977d71 100644 --- a/packages/cli/src/commands/check.ts +++ b/packages/cli/src/commands/check.ts @@ -52,11 +52,15 @@ export class CheckCommand extends Command { description: 'Minimal output', }); + json = Option.Boolean('--json', false, { + description: 'Output as JSON', + }); + async execute(): Promise { const searchDirs = getSearchDirs(); const s = spinner(); - if (!this.quiet) { + if (!this.quiet && !this.json) { header('Check Updates'); } @@ -85,7 +89,7 @@ export class CheckCommand extends Command { return 0; } - if (!this.quiet) { + if (!this.quiet && !this.json) { step(`Checking ${skillsToCheck.length} skill(s) for updates...`); console.log(''); } @@ -195,6 +199,19 @@ export class CheckCommand extends Command { } } + if (this.json) { + console.log(JSON.stringify({ + skills: results.map((r) => ({ + name: r.name, + hasUpdate: r.hasUpdate, + quality: r.qualityScore ?? null, + stars: r.stars ?? null, + })), + updatesAvailable, + })); + return 0; + } + console.log(''); const withUpdates = results.filter(r => r.hasUpdate); diff --git a/packages/cli/src/commands/find.ts b/packages/cli/src/commands/find.ts index 03efd937..9f9aa663 100644 --- a/packages/cli/src/commands/find.ts +++ b/packages/cli/src/commands/find.ts @@ -65,11 +65,15 @@ export class FindCommand extends Command { hidden: true, }); + json = Option.Boolean("--json", false, { + description: "Output as JSON", + }); + async execute(): Promise { const s = spinner(); const limit = parseInt(this.limit, 10) || 10; - if (!this.quiet) { + if (!this.quiet && !this.json) { header("Find Skills"); } @@ -252,6 +256,18 @@ export class FindCommand extends Command { } } + if (this.json) { + console.log(JSON.stringify({ + results: results.map((r) => ({ + name: r.name, + description: r.description || "", + source: r.source, + })), + total: results.length, + })); + return 0; + } + if (results.length === 0) { console.log(colors.muted("No skills found matching your search")); console.log(""); diff --git a/packages/cli/src/commands/install.ts b/packages/cli/src/commands/install.ts index e317e2d6..7092261a 100644 --- a/packages/cli/src/commands/install.ts +++ b/packages/cli/src/commands/install.ts @@ -133,14 +133,18 @@ export class InstallCommand extends Command { description: "Run security scan before installing (default: true)", }); + json = Option.Boolean("--json", false, { + description: "Output as JSON", + }); + async execute(): Promise { const isInteractive = - process.stdin.isTTY && !this.skills && !this.all && !this.yes; + process.stdin.isTTY && !this.skills && !this.all && !this.yes && !this.json; const s = spinner(); let cloneResult: Awaited>["cloneResult"] = null; try { - if (process.stdin.isTTY && !this.quiet) { + if (process.stdin.isTTY && !this.quiet && !this.json) { welcome(); } @@ -657,6 +661,16 @@ export class InstallCommand extends Command { providerAdapter: ReturnType, isInteractive: boolean, ): Promise { + if (this.json) { + console.log(JSON.stringify({ + success: true, + installed: installResults.map((r) => r.skillName), + agents: targetAgents, + total: installResults.length, + })); + return; + } + if (installResults.length > 0) { if (isInteractive) { showInstallSummary({ diff --git a/packages/cli/src/commands/list.ts b/packages/cli/src/commands/list.ts index 8d38d534..d3ea50e1 100644 --- a/packages/cli/src/commands/list.ts +++ b/packages/cli/src/commands/list.ts @@ -59,7 +59,14 @@ export class ListCommand extends Command { : skills.map(s => ({ ...s, quality: null as number | null })); if (this.json) { - console.log(JSON.stringify(skillsWithQuality, null, 2)); + console.log(JSON.stringify({ + skills: skillsWithQuality.map((s) => ({ + name: s.name, + enabled: s.enabled, + path: s.path, + })), + total: skillsWithQuality.length, + })); return 0; } diff --git a/packages/cli/src/commands/publish.ts b/packages/cli/src/commands/publish.ts index 64ebe78d..91093e4a 100644 --- a/packages/cli/src/commands/publish.ts +++ b/packages/cli/src/commands/publish.ts @@ -453,6 +453,10 @@ export class PublishSubmitCommand extends Command { description: "Show what would be submitted", }); + json = Option.Boolean("--json", false, { + description: "Output as JSON", + }); + async execute(): Promise { const skillPath = this.skillPath || process.cwd(); const skillMdPath = this.findSkillMd(skillPath); @@ -465,7 +469,7 @@ export class PublishSubmitCommand extends Command { return 1; } - step("Submitting skill to SkillKit marketplace...\n"); + if (!this.json) step("Submitting skill to SkillKit marketplace...\n"); const content = readFileSync(skillMdPath, "utf-8"); const frontmatter = this.parseFrontmatter(content); @@ -508,26 +512,28 @@ export class PublishSubmitCommand extends Command { tags: frontmatter.tags || ["general"], }; - console.log(colors.primary("Skill details:")); - console.log(colors.muted(` ID: ${skillEntry.id}`)); - console.log(colors.muted(` Name: ${skillEntry.name}`)); - console.log(colors.muted(` Description: ${skillEntry.description}`)); - console.log(colors.muted(` Source: ${skillEntry.source}`)); - console.log(colors.muted(` Tags: ${skillEntry.tags.join(", ")}`)); - console.log(colors.muted(` Quality: ${qualityBadge}${qualityScore !== null ? ` (${qualityScore}/100)` : ""}`)); - if (activity) { - const stars = formatCount(activity.stars); - const pushed = activity.pushedAt ? timeAgo(activity.pushedAt) : "unknown"; - console.log(colors.muted(` Stars: ${stars}`)); - console.log(colors.muted(` Last push: ${pushed}`)); - } - if (quality && quality.warnings.length > 0) { - console.log(colors.warning(` Warnings:`)); - for (const w of quality.warnings.slice(0, 3)) { - console.log(colors.muted(` - ${w}`)); + if (!this.json) { + console.log(colors.primary("Skill details:")); + console.log(colors.muted(` ID: ${skillEntry.id}`)); + console.log(colors.muted(` Name: ${skillEntry.name}`)); + console.log(colors.muted(` Description: ${skillEntry.description}`)); + console.log(colors.muted(` Source: ${skillEntry.source}`)); + console.log(colors.muted(` Tags: ${skillEntry.tags.join(", ")}`)); + console.log(colors.muted(` Quality: ${qualityBadge}${qualityScore !== null ? ` (${qualityScore}/100)` : ""}`)); + if (activity) { + const stars = formatCount(activity.stars); + const pushed = activity.pushedAt ? timeAgo(activity.pushedAt) : "unknown"; + console.log(colors.muted(` Stars: ${stars}`)); + console.log(colors.muted(` Last push: ${pushed}`)); } + if (quality && quality.warnings.length > 0) { + console.log(colors.warning(` Warnings:`)); + for (const w of quality.warnings.slice(0, 3)) { + console.log(colors.muted(` - ${w}`)); + } + } + console.log(); } - console.log(); if (this.dryRun) { warn("Dry run - not submitting"); @@ -566,6 +572,15 @@ export class PublishSubmitCommand extends Command { }, ).trim(); + if (this.json) { + console.log(JSON.stringify({ + success: true, + source: `${repoInfo.owner}/${repoInfo.repo}`, + quality: qualityScore, + issueUrl: result || "", + })); + return 0; + } success("Submission created!"); if (result) { console.log(colors.muted(` ${result}`)); diff --git a/packages/cli/src/commands/remove.ts b/packages/cli/src/commands/remove.ts index e67062d8..e84590ea 100644 --- a/packages/cli/src/commands/remove.ts +++ b/packages/cli/src/commands/remove.ts @@ -33,6 +33,10 @@ export class RemoveCommand extends Command { description: 'Skip confirmation', }); + json = Option.Boolean('--json', false, { + description: 'Output as JSON', + }); + async execute(): Promise { const searchDirs = getSearchDirs(); @@ -75,6 +79,8 @@ export class RemoveCommand extends Command { let removed = 0; let failed = 0; + const removedNames: string[] = []; + const failedNames: string[] = []; for (const { name: skillName, path: skillPath } of skillsToRemove) { if (!existsSync(skillPath)) { @@ -89,15 +95,29 @@ export class RemoveCommand extends Command { if (existsSync(metaSibling)) rmSync(metaSibling); } removeSkillFromLock(skillName); - success(`Removed: ${skillName}`); + removedNames.push(skillName); + if (!this.json) success(`Removed: ${skillName}`); removed++; } catch (err) { - error(`Failed to remove: ${skillName}`); - console.error(colors.muted(err instanceof Error ? err.message : String(err))); + failedNames.push(skillName); + if (!this.json) { + error(`Failed to remove: ${skillName}`); + console.error(colors.muted(err instanceof Error ? err.message : String(err))); + } failed++; } } + if (this.json) { + console.log(JSON.stringify({ + success: failed === 0, + removed: removedNames, + failed: failedNames, + total: removed + failed, + })); + return failed > 0 ? 1 : 0; + } + if (removed > 0) { try { const agentsMdPath = join(process.cwd(), 'AGENTS.md'); diff --git a/packages/cli/src/commands/scan.ts b/packages/cli/src/commands/scan.ts index a3b61187..75792a08 100644 --- a/packages/cli/src/commands/scan.ts +++ b/packages/cli/src/commands/scan.ts @@ -47,6 +47,10 @@ export class ScanCommand extends Command { description: 'Comma-separated rule IDs or categories to skip', }); + json = Option.Boolean('--json', false, { + description: 'Output as JSON', + }); + async execute(): Promise { const targetPath = resolve(this.skillPath); @@ -79,6 +83,11 @@ export class ScanCommand extends Command { const result = await scanner.scan(targetPath); + if (this.json) { + this.context.stdout.write(formatResult(result, 'json') + '\n'); + return result.verdict === 'fail' ? 1 : 0; + } + this.context.stdout.write(formatResult(result, this.format) + '\n'); return result.verdict === 'fail' ? 1 : 0; diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index a8eaf27c..7271641a 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -23,6 +23,10 @@ export class UpdateCommand extends Command { description: 'Force update even if local changes exist', }); + json = Option.Boolean('--json', false, { + description: 'Output as JSON', + }); + async execute(): Promise { const s = spinner(); const searchDirs = getSearchDirs(); @@ -177,6 +181,11 @@ export class UpdateCommand extends Command { } } + if (this.json) { + console.log(JSON.stringify({ updated, skipped, failed })); + return failed > 0 ? 1 : 0; + } + console.log(); step(`Updated: ${updated}, Skipped: ${skipped}, Failed: ${failed}`);