Skip to content

feat(cli): add browse discord command - #3450

Merged
shrey150 merged 9 commits into
mainfrom
cursor/browse-discord-621e
Nov 18, 2026
Merged

shrey150 merged 9 commits into
mainfrom
cursor/browse-discord-621e

Conversation

@shrey150

@shrey150 shrey150 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

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:

$ browse discord --no-open
https://discord.gg/stagehand
Join our Discord community to contribute to Stagehand and the Browse CLI, request features, and share feedback!
  • In an interactive terminal outside CI, opens the invite using the maintained open package and prints the URL and invitation.
  • --no-open or noninteractive stdout skips the opener. A nonempty CI value (including true or 1) also skips it; literal CI=false disables that guard, matching the ci-info convention.
  • If the opener cannot start, the command still prints the invitation and exits successfully.
  • Adds a Discord link to the CLI README and shared support URLs.
  • Includes a patch changeset for 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 in packages/cli/src/lib/open-url.ts. Platform-specific launching is delegated to open, 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

  • CLI TypeScript build and oclif manifest generation.
  • Discord, CLI surface, and opener regression tests: 73 passed.
  • Seven compiled CLI smoke checks using the real open package: interactive launch, CI=false, --no-open, CI=true, CI=0, piped stdout, and missing-launcher fallback.
  • Changed-file formatting and lint checks, plus changeset validation.
  • CI passing at 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:

$ browse discord --no-open
https://discord.gg/stagehand
Join our Discord community to contribute to Stagehand and the Browse CLI, request features, and share feedback!
  • In an interactive terminal outside CI, opens the invite using a hand-rolled browser opener and prints the URL and invitation.
  • --no-open or noninteractive stdout skips the opener. A nonempty CI value (including true or 1) also skips it; literal CI=false disables that guard, matching the ci-info convention.
  • If the opener cannot start, the command still prints the invitation and exits successfully.
  • Adds a Discord link to the CLI README and shared support URLs.
  • Includes a patch changeset for browse: a small support command that preserves existing behavior.

Browser opener implementation

Uses a hand-rolled default-browser opener instead of the open npm package (no new dependencies):

Platform Command Notes
macOS open <url>
Windows rundll32 url.dll,FileProtocolHandler <url> Avoids URL mangling
Linux/Unix $BROWSER <url> If $BROWSER is set
WSL (non-SSH) rundll32.exe url.dll,FileProtocolHandler <url> Falls back to xdg-open on ENOENT
Linux/Unix/WSL-SSH xdg-open <url> Default fallback

Key properties:

  • No shell: spawns without shell: true, so URLs with &, ?, #, spaces, etc. are passed untouched as a single argv element.
  • Detached + unref: the opener process continues after the CLI exits.
  • Error-safe: registers an 'error' listener to swallow async ENOENT/EACCES (opener not found) without crashing.
  • $BROWSER support: respects the standard $BROWSER environment variable on Linux/Unix.
  • WSL-aware: detects WSL via WSL_DISTRO_NAME or /proc/version containing "microsoft", uses Windows opener via interop (unless over SSH).
  • WSL fallback: if rundll32.exe fails (e.g. interop disabled), falls back to xdg-open.

For review, the command and copy are in packages/cli/src/commands/discord.ts; terminal/CI guards and opener error handling are in packages/cli/src/lib/open-url.ts. The stacked follow-up, #3451, adds community links to help and error messages.

test plan

  • CLI TypeScript build and oclif manifest generation.
  • Discord, CLI surface, and opener regression tests: 643 passed.
  • Comprehensive unit tests for the browser opener:
    • Platform-specific command verification (darwin, linux, win32)
    • $BROWSER override tests
    • WSL detection via env and /proc/version
    • WSL over SSH uses xdg-open
    • rundll32.exe ENOENT falls back to xdg-open
    • URLs with special characters (&, ?, #, encoded spaces) passed untouched
    • shell: false, detached: true, stdio: 'ignore' options verified
    • unref() called on child process
    • Async 'error' event (ENOENT) swallowed without crash
    • TTY/CI/--no-open gating verified
  • Changed-file formatting and lint checks, plus changeset validation.
Open in Web Open in Cursor 

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-bot

changeset-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a9efc0b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
browse Patch

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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)
Loading

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/cli/tests/discord.test.ts Resolved
Comment thread packages/cli/src/lib/open-url.ts Resolved
Comment thread packages/cli/src/commands/discord.ts Resolved
Comment thread packages/cli/src/lib/open-url.ts Resolved
Comment thread packages/cli/src/lib/open-url.ts Resolved
@shrey150
shrey150 added this pull request to stack #3455 November 13, 2026 22:50
cursoragent and others added 2 commits November 16, 2026 21:15
- 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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread packages/cli/src/lib/open-url.ts Resolved
- 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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread packages/cli/tests/open-url.test.ts Resolved
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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread packages/cli/src/lib/open-url.ts Resolved
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]>
@shrey150
shrey150 merged commit c118e9c into main Nov 18, 2026
69 checks passed
@shrey150
shrey150 deleted the cursor/browse-discord-621e branch November 18, 2026 20:24
shrey150 added a commit that referenced this pull request Nov 18, 2026
# 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]>
shrey150 pushed a commit that referenced this pull request Nov 19, 2026
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>
shrey150 added a commit that referenced this pull request Nov 20, 2026
…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]>
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