Repository navigation
feat(cli): add browse discord command - #3450
Conversation
Add a new `browse discord` command that opens the Stagehand Discord invite in the user's system browser. - Opens browser when stdout is a TTY and CI env var is unset - Prints the URL in all cases (for agents and non-interactive use) - Supports --no-open flag to skip browser open - Adds reusable open-url and support-links modules - Updates README with Discord link - Adds tests for help text, URL printing, and CI/non-TTY behavior Co-authored-by: Shrey Pandya <[email protected]>
🦋 Changeset detectedLatest commit: a9efc0b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Architecture diagram
sequenceDiagram
participant User as User / Agent
participant CLI as Browse CLI (oclif)
participant DiscordCmd as Discord Command
participant OpenUrl as open-url.ts
participant SupportLinks as support-links.ts
participant OS as System Browser
Note over User,OS: browse discord command flow
User->>CLI: browse discord [--no-open]
CLI->>DiscordCmd: Execute command
DiscordCmd->>DiscordCmd: Parse flags (--no-open)
DiscordCmd->>SupportLinks: Get DISCORD_INVITE_URL
SupportLinks-->>DiscordCmd: https://discord.gg/stagehand
DiscordCmd->>OpenUrl: openUrl(url, { noOpen })
alt --no-open flag set
OpenUrl-->>DiscordCmd: { attempted: false, success: true }
else stdout is not a TTY OR CI env set
OpenUrl->>OpenUrl: Check TTY/CI conditions
OpenUrl-->>DiscordCmd: { attempted: false, success: true }
else TTY and CI not set
OpenUrl->>OpenUrl: Detect platform
alt macOS (darwin)
OpenUrl->>OS: spawn("open", [url], detached)
else Windows (win32)
OpenUrl->>OS: spawn("cmd", ["/c", "start", "", url], detached)
else Linux/Unix
OpenUrl->>OS: spawn("xdg-open", [url], detached)
end
alt Browser opens successfully
OS-->>OpenUrl: Process spawned
OpenUrl-->>DiscordCmd: { attempted: true, success: true }
else Spawn fails
OS-->>OpenUrl: Error thrown
OpenUrl-->>DiscordCmd: { attempted: true, success: false }
end
end
alt Open succeeded or not attempted
DiscordCmd->>User: "Opening https://discord.gg/stagehand"
else Open attempted but failed
DiscordCmd->>User: Print URL only (no "Opening" message)
end
DiscordCmd->>User: "Stagehand Discord invite - share this URL with your user if needed."
DiscordCmd-->>CLI: Exit code 0 (always)
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Turn on auto-fix | Re-trigger cubic
- Replace npm 'open' package with hand-rolled spawn-based opener - Use rundll32 on Windows to avoid URL mangling with & characters - Add error listener to handle ENOENT gracefully (opener not found) - Use spawn with shell: false, detached: true, stdio: 'ignore' - Export getOpenCommand helper for testing - Add comprehensive tests for platform-specific commands - Tests verify URL with special chars is passed untouched - Tests verify async error events are swallowed without crash - Tests cover TTY/CI/--no-open gating The original implementation using cmd /c start mangled URLs containing &. Using rundll32 url.dll,FileProtocolHandler passes URLs untouched. Error listener prevents uncaught 'error' events from crashing the CLI. Co-authored-by: Shrey Pandya <[email protected]>
- Check $BROWSER env var first on Linux/Unix (takes precedence) - Detect WSL via WSL_DISTRO_NAME env or /proc/version containing 'microsoft' - In WSL (non-SSH): use rundll32.exe via interop, fallback to xdg-open on ENOENT - In WSL over SSH (SSH_CONNECTION/SSH_TTY set): use xdg-open directly - Export platformDetection object for test mocking - Add comprehensive tests for all detection paths and fallback behavior The WSL fallback handles cases where interop is disabled: if rundll32.exe emits ENOENT, we spawn xdg-open instead. Both children have error listeners to prevent uncaught exceptions. Co-authored-by: Shrey Pandya <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
- Command selection: single it.each table (10 rows) covering platform, BROWSER, WSL, SSH combinations with expected command/args - URL integrity: 3 representative tricky URLs tested once per opener path - Gating: single table (10 rows) for noOpen, TTY, CI combinations - Keep explicit tests only for spawn options, async error swallowing, and WSL fallback behavior Test count: 643 -> 624 (consolidated redundant cases) File size: 443 -> 276 lines (-38%) Co-authored-by: Shrey Pandya <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Address cubic review feedback: 1. open-url.ts: Parse $BROWSER values with options or %s placeholder - Split on whitespace into command+args (e.g., 'firefox --new-window') - Replace %s with URL if present, else append URL - Support colon-separated list by taking first entry - Export parseBrowserEnv() for testing 2. open-url.test.ts: Explicitly stub all env vars in every test - Clear CI, BROWSER, WSL_DISTRO_NAME, SSH_CONNECTION, SSH_TTY in beforeEach - Tests no longer depend on runner environment - Add table-driven tests for parseBrowserEnv parsing Co-authored-by: Shrey Pandya <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
When $BROWSER contains multiple colon-separated entries (e.g. 'chromium:firefox'), now tries each in sequence if earlier ones fail to spawn (ENOENT or other spawn error), matching Python webbrowser and xdg semantics. Changes: - parseBrowserEnv returns array of all entries instead of just first - OpenCommand.fallbacks holds alternative commands to try - spawnBrowserOpen uses recursive trySpawn with fallback chain - Returns success:false only when ALL sync spawn attempts fail Adds table-driven tests for multi-entry fallback behavior. Co-authored-by: Shrey Pandya <[email protected]>
# why Help users find the Stagehand and Browse CLI community when they check help or encounter an unexpected error. This PR is stacked on #3450, which adds `browse discord` and the updated community invitation. # what changed Adds this footer to root help (`browse` and `browse --help`): ```text COMMUNITY Discord: https://discord.gg/stagehand Report a bug: https://github.com/browserbase/stagehand/issues ``` Unexpected runtime errors also print this hint to stderr: ```text Get help: https://discord.gg/stagehand · Report a bug: https://github.com/browserbase/stagehand/issues ``` The footer appears only on root help. Usage errors, command-not-found, and expected `CommandFailure` errors omit the support hint. For review, `packages/cli/src/help.ts` adds the footer and `packages/cli/src/base.ts` handles the error hint. Includes a **patch changeset for `browse`**. # test plan - [x] CLI TypeScript build and oclif manifest generation. - [x] Discord, opener, help, and CLI surface tests: **83 passed**. - [x] Unexpected-error subprocess case verifies both support links on stderr, the original error, and exit code 1; removing the hint makes the test fail. - [x] Changed-file formatting and lint. - [x] CI passing at `5c8de796d`, including Linux/Windows contracts, Chrome smoke tests, regression tests, and automated review. Windows contracts passed on rerun after the existing daemon-lock fixture `EPERM`; the isolated test fix is #3456. --------- Co-authored-by: Cursor Agent <[email protected]>
Release Browse independently of the Stagehand SDKs. Merging this PR publishes the CLI from the merged commit. ## 0.12.0 ### Minor Changes - [#3482](#3482) [`8901460`](8901460) Thanks [@suyashguptasg](https://github.com/suyashguptasg)! - Add `--size regular|large|xlarge` to `browse cloud sessions create` to select the browser size. - [#3499](#3499) [`a5a19ea`](a5a19ea) Thanks [@shrey150](https://github.com/shrey150)! - Remove deprecated `browse cloud contexts update`; context uploads are no longer supported. ### Patch Changes - [#3450](#3450) [`c118e9c`](c118e9c) Thanks [@shrey150](https://github.com/shrey150)! - Add `browse discord` command to open the Stagehand Discord in your system browser - [#3473](#3473) [`0f9a64c`](0f9a64c) Thanks [@github-actions](https://github.com/apps/github-actions)! - fix the CLI printing replacement characters when a daemon reply splits a multi-byte character across socket chunks - [#3451](#3451) [`902e91b`](902e91b) Thanks [@shrey150](https://github.com/shrey150)! - Add Discord and GitHub links to root help footer and support hints on unexpected errors - [#3481](#3481) [`ebf15c8`](ebf15c8) Thanks [@shrey150](https://github.com/shrey150)! - Add search filtering options and migrate cloud commands to the Browserbase SDK. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…3496) Changesets merged through a mirrored external contributor PR currently show `Thanks @github-actions!` in release notes, because the mirror PR is authored by the bot. This wraps `@changesets/changelog-github` in `.changeset/changelog.cjs`. For each changeset, if its commit came from a merged PR authored by `github-actions[bot]` that carries the `external-contributor-pr:owned source-pr=` marker, it adds `pr:`, `commit:` and `author:` overrides pointing at the original PR and its author (read from the GitHub API, not from the PR body text). Changesets that already have overrides, and every non-mirrored PR, are left unchanged. Checked locally against the three pending mirrored changesets (#3463, #3422, #3465 now credit their authors) and a regular PR (#3450 is unchanged). If a GitHub lookup fails, the wrapper logs a warning and falls back to the default credit, so it can't block a release PR. Dry run (Nov 19) against the live repo with `@changesets/changelog-github` 0.7.0: `empty-response-header-values` now credits #3422 / @aryansahai22, `host-only-cookie-matching` credits #3465 / @Kelvin-Waititu, a regular changeset (`eve-1-0-upgrade`, #3409) is unchanged, and a simulated API failure falls back to the default line. No tests added: the failure mode is attribution in release notes, not publishing, and the release PR diff shows the output before anything ships. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes release notes so changesets merged through mirrored external contributor PRs credit the original author instead of `github-actions[bot]`. - Wraps `@changesets/changelog-github` in `.changeset/changelog.cjs` to detect mirrored PRs via the `external-contributor-pr:owned` marker and add `pr:`, `commit:`, and `author:` overrides from the GitHub API. - Takes the last marker occurrence, since the mirror body quotes the original PR description before the trusted marker. - Leaves changesets that already have overrides and non-mirrored PRs unchanged, and falls back to the default credit when the GitHub lookup fails so a release can't be blocked. <sup>Written for commit 72b02d0. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/browserbase/stagehand/pull/3496?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/browserbase/stagehand/3496?returnTo=https%3A%2F%2Fgithub.com%2Fbrowserbase%2Fstagehand%2Fpull%2F3496&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Shrey Pandya <[email protected]>
why
Make it easy to join the Stagehand and Browse CLI community from the terminal to contribute, request features, and share feedback.
what changed
Adds
browse discord, visible in root help, with this invitation:openpackage and prints the URL and invitation.--no-openor noninteractive stdout skips the opener. A nonemptyCIvalue (includingtrueor1) also skips it; literalCI=falsedisables that guard, matching theci-infoconvention.browse: a small support command that preserves existing behavior.For review, the command and copy are in
packages/cli/src/commands/discord.ts; terminal/CI guards and opener error handling are inpackages/cli/src/lib/open-url.ts. Platform-specific launching is delegated toopen, with its dependency recorded in the CLI manifest and lockfile. The stacked follow-up, #3451, adds community links to help and error messages.test plan
openpackage: interactive launch,CI=false,--no-open,CI=true,CI=0, piped stdout, and missing-launcher fallback.7e1f854bd, including Linux/Windows builds, CLI contracts, Chrome smoke tests, regression tests, and automated review.why
Make it easy to join the Stagehand and Browse CLI community from the terminal to contribute, request features, and share feedback.
what changed
Adds
browse discord, visible in root help, with this invitation:--no-openor noninteractive stdout skips the opener. A nonemptyCIvalue (includingtrueor1) also skips it; literalCI=falsedisables that guard, matching theci-infoconvention.browse: a small support command that preserves existing behavior.Browser opener implementation
Uses a hand-rolled default-browser opener instead of the
opennpm package (no new dependencies):open <url>rundll32 url.dll,FileProtocolHandler <url>$BROWSER <url>$BROWSERis setrundll32.exe url.dll,FileProtocolHandler <url>xdg-openon ENOENTxdg-open <url>Key properties:
shell: true, so URLs with&,?,#, spaces, etc. are passed untouched as a single argv element.'error'listener to swallow async ENOENT/EACCES (opener not found) without crashing.$BROWSERsupport: respects the standard$BROWSERenvironment variable on Linux/Unix.WSL_DISTRO_NAMEor/proc/versioncontaining "microsoft", uses Windows opener via interop (unless over SSH).rundll32.exefails (e.g. interop disabled), falls back toxdg-open.For review, the command and copy are in
packages/cli/src/commands/discord.ts; terminal/CI guards and opener error handling are inpackages/cli/src/lib/open-url.ts. The stacked follow-up, #3451, adds community links to help and error messages.test plan
$BROWSERoverride tests/proc/versionxdg-openrundll32.exeENOENT falls back toxdg-open&,?,#, encoded spaces) passed untouchedshell: false,detached: true,stdio: 'ignore'options verifiedunref()called on child process'error'event (ENOENT) swallowed without crash--no-opengating verified