Skip to content

fix(init): suppress ASCII banner for agent-driven invocations#894

Open
MathurAditya724 wants to merge 2 commits intomainfrom
issue-889-suppress-banner-agent
Open

fix(init): suppress ASCII banner for agent-driven invocations#894
MathurAditya724 wants to merge 2 commits intomainfrom
issue-889-suppress-banner-agent

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

Summary

  • Gate the sentry init ASCII art banner on !detectAgent() in preamble() inside wizard-runner.ts
  • The existing synchronous detectAgent() function (env-var-based) reliably identifies agent-driven runs without relying on TTY detection alone
  • Add two tests: one asserting the banner is suppressed when AI_AGENT is set, one asserting it is shown when no agent is detected

Why

When an AI agent runs sentry init (e.g. sentry init --features errors,tracing,logs,replay,profiling,sourcemaps -y) without the required org context, the CLI emitted the large Sentry ASCII art banner to stderr before failing with exit code 61 (Needs the org specified.). This wastes tokens and adds noise to agent output. TTY detection alone is insufficient because agents often run with a pseudo-TTY attached. The existing detectAgent() function already distinguishes agent-invoked runs reliably.

Closes #889

Testing

bun test test/lib/init/wizard-runner.test.ts
# 22 pass, 0 fail

bun test test/lib/detect-agent.test.ts
# 47 pass, 0 fail

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-894/

Built to branch gh-pages at 2026-05-02 04:00 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

Codecov Results 📊

6595 passed | Total: 6595 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +2
Passed Tests 📈 +2
Failed Tests
Skipped Tests

All tests are passing successfully.

❌ Patch coverage is 66.67%. Project has 13320 uncovered lines.
✅ Project coverage is 76.11%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/lib/init/wizard-runner.ts 66.67% ⚠️ 2 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    76.08%    76.11%    +0.03%
==========================================
  Files          296       296         —
  Lines        55764     55744       -20
  Branches         0         0         —
==========================================
+ Hits         42421     42424        +3
- Misses       13343     13320       -23
- Partials         0         0         —

Generated by Codecov Action

@MathurAditya724 MathurAditya724 force-pushed the issue-889-suppress-banner-agent branch 2 times, most recently from 77b0411 to c6231e3 Compare May 1, 2026 05:00
@MathurAditya724
Copy link
Copy Markdown
Member Author

ci-fixer: starting attempt 1 of 3

@MathurAditya724
Copy link
Copy Markdown
Member Author

ci-fixer: result — fix import order and remove stale biome suppression

  • failed run: https://github.com/getsentry/cli/actions/runs/25203009317
  • category: lint
  • fix: Moved the `setEnv` import in `wizard-runner.test.ts` to its alphabetically-correct position (after `banner.js`, before `errors.js`) to satisfy Biome's `organizeImports` rule. Also removed a stale `biome-ignore lint/complexity/noExcessiveCognitiveComplexity` comment in `markdown.ts` that had no effect (the function no longer triggers that rule).

Re-running CI now.

@MathurAditya724
Copy link
Copy Markdown
Member Author

ci-fixer: starting attempt 2 of 3

@MathurAditya724
Copy link
Copy Markdown
Member Author

ci-fixer: result — lint already fixed by attempt 1; CI is green on latest commit

  • failed run: https://github.com/getsentry/cli/actions/runs/25203009317
  • category: lint
  • fix: The check suite that triggered this run was on SHA c6231e3 (before the attempt-1 fix commit). The fix commit 4aeb0a0 ("Fix CI: sort imports and remove unused biome suppression") already resolved both lint errors: (1) stale biome-ignore lint/complexity/noExcessiveCognitiveComplexity suppression in markdown.ts and (2) unsorted setEnv import in wizard-runner.test.ts. All GitHub Actions check suites on the latest commit are passing.

No new commit needed — the branch is already clean.

Fixes #889

When an AI agent invokes `sentry init` and the run fails early (e.g.
missing org context), the large Sentry ASCII art banner was printed
unconditionally before the error, wasting tokens and adding noise to
structured agent output.

Call `detectAgent()` synchronously in `preamble()` and skip the
`process.stderr.write` banner call when an agent is detected. The
`intro("sentry init")` line and all subsequent wizard logic are
unaffected.
@MathurAditya724 MathurAditya724 force-pushed the issue-889-suppress-banner-agent branch from 4aeb0a0 to 363fcdc Compare May 2, 2026 03:46
@MathurAditya724
Copy link
Copy Markdown
Member Author

ci-fixer: starting attempt 3 of 3

Two lint errors caused the Build job to fail:

1. test/lib/init/wizard-runner.test.ts: Biome's organizeImports rule
   flagged the three new local imports (detect-agent.js, env.js,
   errors.js) as out of alphabetical order. Sorted them so
   detect-agent.js and env.js precede errors.js.

2. src/lib/formatters/markdown.ts:281: A biome-ignore suppression for
   lint/complexity/noExcessiveCognitiveComplexity on renderOneInline()
   was flagged as unused (the function's complexity score no longer
   exceeds the threshold). Removed the now-stale suppression comment.

Failed run: https://github.com/getsentry/cli/actions/runs/25243031491
@MathurAditya724
Copy link
Copy Markdown
Member Author

ci-fixer: result — sorted imports + removed unused biome-ignore suppression

  • failed run: https://github.com/getsentry/cli/actions/runs/25243031491
  • category: lint
  • fix: (1) Sorted the three new local imports in test/lib/init/wizard-runner.test.ts into alphabetical order (detect-agent.jsenv.jserrors.js) to satisfy Biome's organizeImports rule. (2) Removed the now-unused biome-ignore lint/complexity/noExcessiveCognitiveComplexity suppression comment from src/lib/formatters/markdown.ts:281 — the function's complexity score no longer exceeds the threshold.

Re-running CI now.

@MathurAditya724
Copy link
Copy Markdown
Member Author

ci-fixer: result — BLOCKED: attempt budget exhausted (3/3 prior attempts used)

Failed run: https://github.com/getsentry/cli/actions/runs/25243031491/job/74022857731
Category: lint

The CI lint job is still failing with two Biome errors. Here is exactly what needs to be fixed manually:

Fix 1 — Remove unused suppression in src/lib/formatters/markdown.ts line 281

The biome-ignore lint/complexity/noExcessiveCognitiveComplexity comment no longer suppresses anything (Biome reports suppressions/unused). Delete that comment line:

-// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: inline token switch is inherently branchy
 function renderOneInline(token: Token): string {

Fix 2 — Sort imports in test/lib/init/wizard-runner.test.ts lines 15-17

Biome's organizeImports requires alphabetical order by import path. Reorder:

-import { WizardError } from "../../../src/lib/errors.js";
-import { ENV_VAR_AGENTS } from "../../../src/lib/detect-agent.js";
-import { setEnv } from "../../../src/lib/env.js";
+import { ENV_VAR_AGENTS } from "../../../src/lib/detect-agent.js";
+import { setEnv } from "../../../src/lib/env.js";
+import { WizardError } from "../../../src/lib/errors.js";

Or simply run bun run lint:fix locally — it will auto-sort and the suppression removal must be done manually.

Recommended next step: Apply the two changes above, commit, and push. The fix touches only 2 files and is straightforward.

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.

Suppress CLI banner for agent-run init errors

2 participants