Repository navigation
CLI: Do not auto-open the browser in storybook dev under AI agents - #35412
Conversation
When detectAgent() (std-env) reports an AI agent environment (Claude Code, Codex, Cursor, explicit AI_AGENT, ...), resolve open: false for storybook dev so the system browser is not opened next to the agent's own preview. Claude-preview launch behavior, including PORT precedence, is unchanged. Part 1 of #35411
Both independent reviews flagged that detectAgent() silently bypassed the injected env seam of resolveDevCommandOptions. Expose it as an overridable 'agent' option (defaulting to ambient detection) so tests opt out with agent: null instead of scrubbing a hand-maintained agent env-var list.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 6 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughresolveDevCommandOptions now accepts an optional agent parameter defaulting to detectAgent(), and computes an isAgentSession flag (true for Claude preview or when an agent is detected) to suppress the open option. Tests add environment stub cleanup and new coverage for agent-detection opt-out and port precedence. ChangesAgent-aware Open Suppression
Estimated code review effort: 2 (Simple) | ~12 minutes Possibly related issues
Possibly related PRs
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
code/core/src/bin/dev-options.test.ts (1)
118-130: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueBroaden the integration matrix if you want end-to-end agent coverage
detectAgentalready has direct cases for Gemini CLI, opencode, Devin, and Kiro, but this test only exercisesCLAUDECODE,CODEX_SANDBOX,CODEX_THREAD_ID,CURSOR_AGENT, andAI_AGENT. Add the remaining signals here if you wantresolveDevCommandOptions()to cover every agent path directly.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@code/core/src/bin/dev-options.test.ts` around lines 118 - 130, The dev-options test matrix for resolveDevCommandOptions() does not cover all agent-detection signals already handled by detectAgent. Extend the it.each table in dev-options.test.ts to include the remaining environment markers for Gemini CLI, opencode, Devin, and Kiro, so the browser-suppression behavior is exercised for every agent path directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@code/core/src/bin/dev-options.test.ts`:
- Around line 118-130: The dev-options test matrix for
resolveDevCommandOptions() does not cover all agent-detection signals already
handled by detectAgent. Extend the it.each table in dev-options.test.ts to
include the remaining environment markers for Gemini CLI, opencode, Devin, and
Kiro, so the browser-suppression behavior is exercised for every agent path
directly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0e205cf5-a19c-4dc2-87f2-650c29f57d42
📒 Files selected for processing (2)
code/core/src/bin/dev-options.test.tscode/core/src/bin/dev-options.ts
|
let's also remove all the comments, it's not needed as obvious for us |
Part 1 of #35411 (the SB11 default flip and the storybookjs/mcp changes are tracked separately in that issue).
What I did
When
storybook devis launched from an AI agent environment (Claude Code, Codex, Cursor, Gemini CLI, opencode, Devin, Kiro, or an explicitAI_AGENTenv var), the system browser is no longer auto-opened. Agents usually start Storybook to verify changes — often next to their own in-app preview browser — so the extra Chrome tab is pure noise.resolveDevCommandOptionsnow resolvesopen: falsewhenever the existingdetectAgent()(backed bystd-envv4, already used for telemetry and onboarding-skip) reports an agent. The suppression is silent: no log line and no new CLI flag.isClaudePreviewLaunchhandling (including itsPORTprecedence behavior) is fully unchanged; agent detection is a superset for the open gate only.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
New cases in
code/core/src/bin/dev-options.test.tscover suppression viaCLAUDECODE,CODEX_SANDBOX,CODEX_THREAD_ID,CURSOR_AGENT, and explicitAI_AGENT(usingvi.stubEnv), plus no-regression coverage for the Claude-preview port precedence logic.Manual testing
yarn task sandbox --start-from auto --template react-vite/default-tsCLAUDECODE=1 yarn storybook— Storybook starts but no browser opens.yarn storybookfrom a regular shell (no agent env vars) — the browser still opens automatically.Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.Summary by CodeRabbit