Skip to content

Add experimental_useServers to the plugin SDK - #6532

Merged
ymichael merged 1 commit into
mainfrom
bb/plugin-sdk-use-servers
Oct 29, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/plugin-sdk-use-servers

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Plugins had no way to see or use the server list that bb Desktop and the mobile app keep. Only core's command palette could switch servers, and only on desktop, through a desktop-only useServerChoices hook whose choices held just id, name and active. The mobile app had no switcher. New desktop windows registered with the main process only after their first page load, so their early IPC requests (for example the server list) were rejected.

What changed

  • Plugin SDK (@get-bb/plugin-sdk/app): new experimental_useServers() returns { status, servers, switchTo } on bb Desktop and the mobile app, and null in web browsers. Each ExperimentalServer has id, name, origin (scheme/host/port only, never login details or a path), kind (local | account | custom) and active. SDK version bumped to 0.6.99. The testing harness accepts a servers answer. Documented in docs/api_to_audit.md, the Plugin Guide surfaces list, and the plugin-authoring frontend API index.
  • App: useServerChoices / server-choices.ts now back both the palette and the plugin hook through one external store. Desktop starts loading until the main process answers, and a pushed change wins over an older in-flight read. The mobile shell's server list is read from the bridge handshake, so it starts ready.
  • Desktop: server choices include origin and kind. The preload adds listServerChoices (with getServerChoices kept as an alias). Windows register through the window factory's onWindowCreated, before their first page load.
  • Mobile bridge: MOBILE_BRIDGE_VERSION 3 → 4, with servers in the handshake, a servers shell-to-page event, and a switch-server page-to-shell message. ProfileWebViewScreen and useShellBridge push the list and handle the switch.
  • No server/daemon wire changes, so HOST_DAEMON_PROTOCOL_VERSION is unchanged.

How you verified

  • Unit tests added or updated: server-choices.test.ts, desktop server-list, server-choice-ipc, desktop-window-factory, preload-browser-api, menu, mobile shell-servers, and mobile-bridge inject/messages.
  • Live in a packaged pnpm desktop:worktree build on macOS, with a second custom server (http://localhost:20380) next to "This Mac" (http://127.0.0.1:20380):
    • Command palette "switch to" lists only the inactive server. Selecting it reloads the window on that server, and the palette then offers switching back.
    • A throwaway plugin with a sidebar footer item that renders experimental_useServers() showed ready, both servers with the right kind, origin and active flag. Its switchTo button switched servers.
    • bbDesktop.listServerChoices() returns only id, name, origin, kind and active.
    • File → New Window: the plugin item reads ready with both servers on the window's first load.
  • Note: while the desktop window is fully covered by another window, requestAnimationFrame is paused, so a palette selection made then runs only once the window is drawn again. A direct switchTo was immediate.
  • Not verified live: the mobile app path (bridge v4 servers event and switch-server), Connect account servers, and the brief loading state.

AGENT GENERATED

🤖 Generated with Claude Code

Plugins can read the servers bb Desktop and the mobile app can switch
between, and switch to one. The command palette server switcher uses the
same hook. Desktop server choices now carry origin and kind, desktop
windows register with the main process before their first page load, and
the mobile bridge (version 4) pushes the server list and accepts a
switch-server message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 214616a into main Oct 29, 2026
51 checks passed
@ymichael
ymichael deleted the bb/plugin-sdk-use-servers branch October 29, 2026 06:19
ymichael added a commit that referenced this pull request Nov 21, 2026
## Human comments

## What was wrong

bb Desktop and the mobile app keep a list of servers, and since #6532
the app reads it through `useServerChoices`. The only way to switch from
inside bb is the command palette, which only lists servers you already
have. Adding a server, and signing in to bb Connect so account servers
show up, live only in the desktop's native **Server** menu. On the
phone, adding a server means going to the app's Settings › Servers.
#3133 asks for a server selector in the app's sidebar.

## What changed

- **A bundled Server switcher plugin (`bb--server-switcher`), off by
default.** Once enabled, bb Desktop and the mobile app get a **Servers**
item in the sidebar footer. A web browser keeps no server list, so the
item isn't there. It opens a panel above the footer like any plugin
footer item: each server with its host and a check on the current one.
Choosing another server closes the panel, then switches, in the same
order as the palette. Opening the panel moves focus to the current
server, and Escape returns it to the footer button. It follows the
footer's order and visibility settings and opens from More like any
footer item. It ships off while it gets more use on real desktop and
mobile builds; existing installs follow the default until the user
toggles the plugin, so turning `defaultEnabled` on later reaches them. I
put it in the footer rather than the header #3133 suggests: #6532's
Plugin Guide entry already names the footer for switching servers, the
Mobile apps item sits there, and on a phone it is within thumb reach in
the sidebar drawer.
- **The plugin uses the existing footer API.** It registers through
`experimental_sidebarFooter` the way Provider usage does, so core gains
no footer code of its own.
- **`experimental_hasServers()`** (new, `@get-bb/plugin-sdk/app`) is
true where `experimental_useServers()` returns a value (bb Desktop and
the mobile app) and false in a browser. It is fixed for the life of the
page, so the plugin reads it inside `definePluginApp` and registers its
footer item only on those clients. Core implements it with the same
`getServerChoices()` the command palette uses. `loadPluginApp(source, {
hasServers: true })` lets plugin tests define the app the same way.
- **Add server…** opens the desktop's own Add Server dialog (the same
`openSetServerUrlDialog(true)` as Server › Add Server…). In the mobile
app, the shell opens Settings › Servers › Add (`open-native` screen
`add-server`, mobile bridge 4 → 5).
- **Sign in to bb Connect…** appears exactly when the Server menu shows
its sign-in item. One predicate in `@bb/desktop-contract`,
`bbDesktopConnectSignInLabel`, decides it for the menu, the page and the
main-process IPC handler. The handler ignores the request otherwise,
because opening the sign-in clears the Connect session cookie.
- **Desktop contract and preload.** The server list IPC also carries the
Connect sync skip reason (`getServerList`, `onServerListChange`), plus
`addServer` and `signInToConnect`. `listServerChoices`,
`getServerChoices` and `onServerChoicesChange` stay for older pages, and
new pages fall back to them on older desktop releases, without the two
new rows.
- **Plugin SDK 0.6.175.** `experimental_useServers()` gains `addServer`
and `accountSignIn`, and `experimental_hasServers()` is new.
`docs/api_to_audit.md`, the Plugin Guide's sidebar footer card,
`docs/configuration.md` and the bb guide are updated.
- No server or daemon wire changes, so `HOST_DAEMON_PROTOCOL_VERSION` is
unchanged.

The screenshots below are from the first version of this PR, when the
switcher was in core; the plugin renders the same panel.

| | Before (`main`) | After |
| --- | --- | --- |
| Desktop | <img
src="https://raw.githubusercontent.com/salemsayed/bb/2afcae09d64db6aef6ec62108b5da02049eaaf80/sidebar-server-switcher/desktop-before.png"
width="340" alt="Desktop sidebar footer on main: Mobile apps, Provider
usage, Report a bug"> | <img
src="https://raw.githubusercontent.com/salemsayed/bb/2afcae09d64db6aef6ec62108b5da02049eaaf80/sidebar-server-switcher/desktop-after.png"
width="340" alt="Servers panel above the footer: three servers, Sign in
to bb Connect, Add server"> |
| Phone (390 px, touch) | <img
src="https://raw.githubusercontent.com/salemsayed/bb/2afcae09d64db6aef6ec62108b5da02049eaaf80/sidebar-server-switcher/phone-before.png"
width="340" alt="Phone sidebar footer on main"> | <img
src="https://raw.githubusercontent.com/salemsayed/bb/2afcae09d64db6aef6ec62108b5da02049eaaf80/sidebar-server-switcher/phone-after.png"
width="340" alt="Servers panel in the phone sidebar"> |

| Dark, opened with the keyboard | bb Desktop (packaged Linux build),
after adding a server | Add server… in bb Desktop |
| --- | --- | --- |
| <img
src="https://raw.githubusercontent.com/salemsayed/bb/2afcae09d64db6aef6ec62108b5da02049eaaf80/sidebar-server-switcher/desktop-dark-keyboard.png"
width="300" alt="Dark theme, focus on the current server"> | <img
src="https://raw.githubusercontent.com/salemsayed/bb/2afcae09d64db6aef6ec62108b5da02049eaaf80/sidebar-server-switcher/desktop-app-panel.png"
width="300" alt="Real desktop app: This Computer and a custom server,
sign-in and Add server rows"> | <img
src="https://raw.githubusercontent.com/salemsayed/bb/2afcae09d64db6aef6ec62108b5da02049eaaf80/sidebar-server-switcher/desktop-app-add-server-dialog.png"
width="300" alt="The desktop's Add Server dialog opened from the panel">
|

## How you verified

- Tests added or extended: `server-choices.test.tsx` (store tests, and
the plugin hook against bb Desktop and the mobile app),
`plugins/server-switcher/app.test.tsx`, desktop `server-choice-ipc` (the
sign-in IPC opens exactly when `createServerMenuItems` shows the item,
for no reason and all five skip reasons) and `preload-browser-api`, and
mobile-bridge `messages`. The new store, IPC and bridge tests fail on
`main` (for example `{"type":"open-native","screen":"add-server"}:
expected false to be true`).
- Live, in a packaged Linux desktop build of this branch under Xvfb with
its own data directory and built-in server: `getServerList()` returned
the list with `connectServersSkipReason: "no-credential"`, and the panel
showed This Computer, Sign in to bb Connect… and Add server…. Add
server… opened the Add Server dialog, and saving a second local bb
server added it and moved the window there. Choosing either server in
the panel moved the window to it and back. Sign in to bb Connect… opened
the desktop's bb Connect sign-in window. Enter on the footer button put
focus on the current server with a visible ring, and Escape returned it
to the button.
- The sign-in gate, offline (a local dev Connect URL with nothing
listening): with a session cookie present and sync reporting
`not-paired`, so the menu offers no sign-in, a page call to
`window.bbDesktop.signInToConnect()` cleared the cookie before the gate
and leaves it in place with it.
- Headless Chromium against isolated `pnpm start:worktree` instances of
this branch and `main`, at 1440×900 and a 390×844 touch phone, light and
dark. It used a stub `window.bbDesktop` (three servers, a sign-in skip
reason, loading, one server, and an older desktop without the new
methods) and the real `buildBridgeInjectionScript` at bridge 5. On
`main` the footer items are `builtin:mobile`,
`plugin:bb--provider-usage/usage` and `builtin:report-bug` everywhere.
The first version of this branch added a Servers item on desktop and in
the mobile shell, and nothing in a plain browser. In the mobile shell
the panel posts `switch-server` and `open-native` `add-server`. A switch
the shell never completes leaves the panel closed and every row
choosable when reopened.
- `pnpm exec turbo run typecheck lint` for `@bb/app`, `@bb/desktop`,
`@bb/mobile`, `@bb/mobile-bridge`, `@bb/desktop-contract` and
`@get-bb/plugin-sdk`. Tests: desktop 647, mobile 356, plugin SDK 444,
mobile bridge 40, desktop contract 18, app 7,265 passed. `oxfmt --check`
on the changed files, `check-plugin-sdk-version.mjs`, and the `@bb/app`
build with `check-bundle-budget.mjs` ("Bundle budget OK").
- One app test also fails on `main` (351cb84, unchanged):
`ThreadDetailPromptArea.test.tsx` "dismisses a missing queued message
but keeps a stale edit recoverable".
- **Not checked:** the iOS and Android apps themselves (the page side
used the real bridge injection script), account servers from a signed-in
bb Connect, and bb Desktop on macOS and Windows.

- After moving the switcher into the plugin: `pnpm exec turbo run
typecheck lint --filter='...[origin/main]'` (183 tasks), and tests for
the plugin (registration only with `hasServers`, focus on the current
server, close-then-switch order, add-server and sign-in rows, a client
without either), `server-choices.test.tsx` (the hook against bb Desktop
and the mobile app, and `experimental_hasServers()` matching it), the
plugin SDK, Plugin Guide, templates, server built-in plugin and catalog,
web marketplace, and fork checks. Live on `pnpm start:worktree` with a
stub `window.bbDesktop`: the panel, switching, Add server…, Sign in…,
Escape and focus behave as before; a plain browser has no item; the
plugin starts disabled, and enabling or disabling it adds or removes the
footer item without a reload.

Related: #5740 (its smaller step, letting `open-native` reach the
Servers screen).

Fixes #3133

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Michael Yong <[email protected]>
Co-authored-by: ymichael <[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.

1 participant