Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib/formatters/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ function renderCodespan(token: Tokens.Codespan): string {
/**
* Render a single inline token to an ANSI string.
*/
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: inline token switch is inherently branchy
function renderOneInline(token: Token): string {
switch (token.type) {
case "strong":
Expand Down
7 changes: 6 additions & 1 deletion src/lib/init/wizard-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MastraClient } from "@mastra/client-js";
import { captureException, getTraceData } from "@sentry/node-core/light";
import { formatBanner } from "../banner.js";
import { CLI_VERSION } from "../constants.js";
import { detectAgent } from "../detect-agent.js";
import { EXIT, WizardError } from "../errors.js";
import { terminalLink } from "../formatters/colors.js";
import {
Expand Down Expand Up @@ -328,7 +329,11 @@ async function preamble(
);
}

process.stderr.write(`\n${formatBanner()}\n\n`);
// Suppress the ASCII art banner for agent-driven runs — it wastes tokens
// and adds noise to structured output without providing value to the agent.
if (!detectAgent()) {
process.stderr.write(`\n${formatBanner()}\n\n`);
}
intro("sentry init");

let confirmed: boolean;
Expand Down
43 changes: 43 additions & 0 deletions test/lib/init/wizard-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import * as clack from "@clack/prompts";
import { MastraClient } from "@mastra/client-js";
// biome-ignore lint/performance/noNamespaceImport: spyOn requires object reference
import * as banner from "../../../src/lib/banner.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";
import { WizardCancelledError } from "../../../src/lib/init/clack-utils.js";
// biome-ignore lint/performance/noNamespaceImport: spyOn requires object reference
Expand Down Expand Up @@ -223,6 +225,9 @@ afterEach(() => {
} else {
process.env.SENTRY_PLAIN_OUTPUT = savedPlainOutput;
}

// Restore the env sandbox in case any test used setEnv without try/finally.
setEnv(process.env);
});

describe("runWizard", () => {
Expand Down Expand Up @@ -278,6 +283,44 @@ describe("runWizard", () => {
expect(getWorkflowSpy).not.toHaveBeenCalled();
});

test("suppresses the ASCII art banner when an agent is detected", async () => {
setEnv({ ...process.env, CLAUDE_CODE: "1" } as NodeJS.ProcessEnv);
try {
await runWizard(makeOptions());
} finally {
setEnv(process.env);
}

expect(formatBannerSpy).not.toHaveBeenCalled();
expect(stderrSpy).not.toHaveBeenCalledWith(
expect.stringContaining("BANNER")
);
});

test("prints the ASCII art banner when no agent is detected", async () => {
// Strip all agent-detection env vars so detectAgent() returns undefined
// even when running inside an agent environment (e.g. OpenCode in CI).
const agentKeys = new Set([
"AI_AGENT",
"AGENT",
"CLAUDECODE",
"CLAUDE_CODE",
...ENV_VAR_AGENTS.keys(),
]);
const cleanEnv = Object.fromEntries(
Object.entries(process.env).filter(([k]) => !agentKeys.has(k))
);
setEnv(cleanEnv as NodeJS.ProcessEnv);
try {
await runWizard(makeOptions());
} finally {
setEnv(process.env);
}

expect(formatBannerSpy).toHaveBeenCalled();
expect(stderrSpy).toHaveBeenCalledWith(expect.stringContaining("BANNER"));
});

test("dispatches tool payloads through the registry", async () => {
const payload: ToolPayload = {
type: "tool",
Expand Down
Loading