From e9014e130c762ce6fab9a114afba322cdf6bbaff Mon Sep 17 00:00:00 2001 From: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> Date: Sun, 12 Apr 2026 11:31:21 +0100 Subject: [PATCH] fix: suppress all stdout pollution in --json mode across all commands - update: emit JSON on empty skills, gate warn/console.log on !json - remove: emit JSON on empty results, gate warn/log on !json - find: gate step() calls on !json - install: emit JSON error object in catch block instead of console.log --- packages/cli/src/commands/find.ts | 4 ++-- packages/cli/src/commands/install.ts | 8 ++++++-- packages/cli/src/commands/remove.ts | 16 ++++++++++++---- packages/cli/src/commands/update.ts | 12 ++++++++---- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/cli/src/commands/find.ts b/packages/cli/src/commands/find.ts index 8cb99f1a..a90c7637 100644 --- a/packages/cli/src/commands/find.ts +++ b/packages/cli/src/commands/find.ts @@ -121,7 +121,7 @@ export class FindCommand extends Command { ) .slice(0, limit); - if (!this.quiet) { + if (!this.quiet && !this.json) { step("Showing featured skills"); } } else if (this.query) { @@ -142,7 +142,7 @@ export class FindCommand extends Command { s.stop(`Found ${results.length} skill(s)`); } else { - if (!this.quiet) { + if (!this.quiet && !this.json) { step("Enter a search term or browse featured skills"); } diff --git a/packages/cli/src/commands/install.ts b/packages/cli/src/commands/install.ts index 9e53c679..66d06214 100644 --- a/packages/cli/src/commands/install.ts +++ b/packages/cli/src/commands/install.ts @@ -186,8 +186,12 @@ export class InstallCommand extends Command { return 0; } catch (err) { - s.stop(colors.error("Installation failed")); - console.log(colors.muted(err instanceof Error ? err.message : String(err))); + if (this.json) { + console.log(JSON.stringify({ success: false, error: err instanceof Error ? err.message : String(err) })); + } else { + s.stop(colors.error("Installation failed")); + console.log(colors.muted(err instanceof Error ? err.message : String(err))); + } return 1; } finally { if (cloneResult) this.cleanupTemp(cloneResult); diff --git a/packages/cli/src/commands/remove.ts b/packages/cli/src/commands/remove.ts index 27cf849c..91cf860a 100644 --- a/packages/cli/src/commands/remove.ts +++ b/packages/cli/src/commands/remove.ts @@ -55,22 +55,30 @@ export class RemoveCommand extends Command { return meta?.source?.includes(this.source!) ?? false; }).map((s) => ({ name: s.name, path: s.path })); if (skillsToRemove.length === 0) { - warn(`No skills found from source: ${this.source}`); + if (this.json) { + console.log(JSON.stringify({ success: true, removed: [], failed: [], total: 0 })); + } else { + warn(`No skills found from source: ${this.source}`); + } return 0; } } else { skillsToRemove = allSkills.map((s) => ({ name: s.name, path: s.path })); if (skillsToRemove.length === 0) { - warn('No installed skills found'); + if (this.json) { + console.log(JSON.stringify({ success: true, removed: [], failed: [], total: 0 })); + } else { + warn('No installed skills found'); + } return 0; } } - console.log(colors.muted(`Found ${skillsToRemove.length} skill(s) to remove`)); + if (!this.json) console.log(colors.muted(`Found ${skillsToRemove.length} skill(s) to remove`)); } else { for (const skillName of this.skills) { const skill = findSkill(skillName, searchDirs); if (!skill) { - warn(`Skill not found: ${skillName}`); + if (!this.json) warn(`Skill not found: ${skillName}`); continue; } skillsToRemove.push({ name: skill.name, path: skill.path }); diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index 1de3b1fa..b91ba65b 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -39,7 +39,7 @@ export class UpdateCommand extends Command { .filter((s): s is NonNullable => s !== null); const notFound = this.skills.filter(name => !findSkill(name, searchDirs)); - if (notFound.length > 0) { + if (notFound.length > 0 && !this.json) { warn(`Skills not found: ${notFound.join(', ')}`); } } else { @@ -47,7 +47,11 @@ export class UpdateCommand extends Command { } if (skillsToUpdate.length === 0) { - warn('No skills to update'); + if (this.json) { + console.log(JSON.stringify({ updated: 0, skipped: 0, failed: 0 })); + } else { + warn('No skills to update'); + } return 0; } @@ -61,7 +65,7 @@ export class UpdateCommand extends Command { const metadata = loadSkillMetadata(skill.path); if (!metadata) { - console.log(colors.muted(`Skipping ${skill.name} (no metadata, reinstall needed)`)); + if (!this.json) console.log(colors.muted(`Skipping ${skill.name} (no metadata, reinstall needed)`)); skipped++; continue; } @@ -176,7 +180,7 @@ export class UpdateCommand extends Command { } } catch (err) { s.stop(colors.error(`Failed to update ${skill.name}`)); - console.log(colors.muted(err instanceof Error ? err.message : String(err))); + if (!this.json) console.log(colors.muted(err instanceof Error ? err.message : String(err))); failed++; } }