Skip to content

fix: suppress spinner output when --json or --silent flag is passed#7982

Merged
DavidWells merged 2 commits intomainfrom
DavidWells/agent-cmd-json-fix
Mar 4, 2026
Merged

fix: suppress spinner output when --json or --silent flag is passed#7982
DavidWells merged 2 commits intomainfrom
DavidWells/agent-cmd-json-fix

Conversation

@DavidWells
Copy link
Contributor

Summary

  • When --json or --silent is passed, startSpinner now returns a no-op spinner that satisfies the Spinner interface but writes nothing
  • This matches the existing behavior of log() in command-helpers.ts, which already no-ops on --json and --silent

Problem

We hit this in CI where a script captures CLI output with 2>&1 (merging stderr into stdout) and pipes it to jq:

AGENT_OUTPUT=$(netlify agents:create "$TRIGGER_TEXT" --json 2>&1 || true)
AGENT_ID=$(echo "$AGENT_OUTPUT" | jq -r '.id // empty')

Even though nanospinner writes to stderr by default, the 2>&1 pulls spinner frames (⠋ Creating agent task...) into the captured output. jq then sees the spinner text before the JSON and fails to parse.

While the script could avoid 2>&1, when --json is passed the CLI should produce machine-friendly output only — no spinners, no decorative text, regardless of which stream they target.

Approach

Rather than adding if (!options.json) guards at every spinner call site, the suppression is handled centrally in startSpinner. When --json or --silent is detected in process.argv, it returns a no-op object implementing the full Spinner interface. This means:

  • Zero changes needed at call sites — existing .stop(), .success(), .error() calls work as before
  • Consistent with how log() already handles --json/--silent globally
  • No risk of future commands forgetting the check

Test plan

  • netlify agents:create "test" --json --agent claude outputs clean JSON with no spinner text on stderr
  • netlify agents:create "test" --json --agent claude 2>&1 | jq -r '.id' parses successfully
  • Interactive mode (no --json) still shows spinners as before
  • npm run typecheck passes

@DavidWells DavidWells requested a review from a team as a code owner March 3, 2026 20:25
@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Spinner output is now properly suppressed when using the --json or --silent command-line flags, ensuring cleaner output in these modes.

Walkthrough

Runtime suppression logic was added to the spinner module to conditionally disable spinner output based on command-line arguments (--json, --silent). A noopSpinner object implementing the Spinner interface was introduced to serve as a no-op replacement. The startSpinner function signature was updated to return a Spinner type and now conditionally returns either the no-op spinner or a real spinner instance depending on whether output suppression is enabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: suppress spinner output when --json or --silent flag is passed' directly and clearly summarizes the main change in the changeset.
Description check ✅ Passed The description is well-related to the changeset, providing detailed context about the problem, the approach, and testing plan for suppressing spinner output.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch DavidWells/agent-cmd-json-fix

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

📊 Benchmark results

Comparing with df4d195

  • Dependency count: 1,081 (no change)
  • Package size: 330 MB (no change)
  • Number of ts-expect-error directives: 362 (no change)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/lib/spinner.ts (1)

3-10: Avoid freezing CLI flags at import time.

Line [3] snapshots process.argv once. If argv is changed after module import (common in tests/programmatic usage), suppression can drift. Prefer reading argv inside shouldSuppressOutput().

♻️ Proposed tweak
-const argv = process.argv.slice(2)
-
-const shouldSuppressOutput = () => argv.includes('--json') || argv.includes('--silent')
+const shouldSuppressOutput = () => {
+  const argv = process.argv.slice(2)
+  return argv.includes('--json') || argv.includes('--silent')
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/spinner.ts` around lines 3 - 10, The module currently snapshots
process.argv into the top-level const argv which freezes CLI flags at import
time; remove the top-level argv constant and modify shouldSuppressOutput() to
call process.argv.slice(2) inside the function and check .includes('--json') ||
.includes('--silent') so flags are read each time; keep DOTS_SPINNER unchanged
and only update shouldSuppressOutput (and remove references to the removed argv
symbol).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lib/spinner.ts`:
- Around line 3-10: The module currently snapshots process.argv into the
top-level const argv which freezes CLI flags at import time; remove the
top-level argv constant and modify shouldSuppressOutput() to call
process.argv.slice(2) inside the function and check .includes('--json') ||
.includes('--silent') so flags are read each time; keep DOTS_SPINNER unchanged
and only update shouldSuppressOutput (and remove references to the removed argv
symbol).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b527545 and 2aa73e2.

📒 Files selected for processing (1)
  • src/lib/spinner.ts

@jaredm563
Copy link
Contributor

nice!

@DavidWells DavidWells enabled auto-merge (squash) March 4, 2026 19:50
@DavidWells DavidWells merged commit 510aea6 into main Mar 4, 2026
71 checks passed
@DavidWells DavidWells deleted the DavidWells/agent-cmd-json-fix branch March 4, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants