Skip to content

Pick every exclusive plugin slot with one rule and one synced store - #7962

Merged
ymichael merged 3 commits into
mainfrom
bb/implement-plugin-winner-rule-api-thr_iiq29hrnps
Nov 23, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/implement-plugin-winner-rule-api-thr_iiq29hrnps

Conversation

@ymichael

@ymichael ymichael commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb's one-plugin surfaces each had their own winner rule and store. The composer, thread list and navigation used a pinned synced preference with "installed before bundled", but file openers sorted by plugin id (so bb's bundled Docs beat an installed .md opener) and fell back to bb's preview when a pinned opener was gone; the thread header title took whichever plugin sorted first with no way to choose; a code-fence language or message directive claimed by two plugins rendered nobody's view, only a console warning. The diff/source renderer and file-opener picks lived in device localStorage, so they did not follow the user or show up in bb settings ui. The composer and thread list had no last-known cache, so a cold load painted the Automatic winner for ~1.7 s before the user's pin arrived (kill-test 4 of the design, failed on main). A crashed composer or thread list left an empty "crashed" placeholder.

Design: design-winner-rule.md (section 2 as amended by section 6) from the plugin API audit.

What changed

  • One resolver. resolveExclusive (apps/app/src/lib/plugin-replacement-preference.ts) decides every exclusive slot and keyed surface: a present pick wins; __builtin__ means core's own where core has one (diff, source, header title, file preview, code block, directive-as-text); an absent pick waits while plugins first load, then behaves as Automatic; Automatic is the first claimant the user chose over bb's defaults, by (plugin id, registration order), then bb's own (bundled or from bb's official marketplace), then core's own. "From bb's official marketplace" reuses the UI's official check, now one function (isOfficialPlugin / isOfficialMarketplace in apps/app/src/lib/official-plugins.ts, also used by the plugin cards, detail page, author page and listing), so Docs, Tasks and Browser Automation rank as bb's defaults however they were installed. Keybinding conflict resolution still uses only bundled (builtin) plugins. bb's bundled Composer, Thread list, Navigation, Docs, Tasks and inline-vis are ordinary claimants through it. Message directives use the same resolver with no Automatic winner: a name several plugins claim renders as its source text in a card like a code block, with a "Choose plugin" menu in its top right (one item per plugin with its icon, a divider, then Settings…). A pick there writes messageDirective.byName, the same value as the Settings row.
  • Surfaces routed through it: composer (composer-provider.ts, ComposerBox), thread list (threadListProvider.ts, PluginThreadList), sidebar navigation (sidebarNavigationProvider.ts, placement and remembered-winner kept as extras), diff and source renderers (codeRendererProvider.ts), thread header title (PluginThreadHeaderTitle.tsx, ThreadDetailHeader), file openers (resolveFileOpenerReplacement), code fences (resolveCodeFenceRendererRegistry) and message directives (resolveMessageDirectiveRegistry, markdown-message-directives.tsx).
  • One store, only new keys. New synced UI preferences in @bb/domain: diff.provider, sourceCode.provider, threadHeader.titleProvider, and the maps fileOpener.byExtension, codeFence.byLanguage, messageDirective.byName (a missing map key means Automatic). No key is renamed or retired. Every pick key, including the existing composer.provider and sidebar.threadListProvider, now has a device last-known cache so first paint uses the user's pick; composer and thread list also remember their last Automatic winner and wait for it during boot instead of painting another claimant. The wait applies only until plugin frontends first settle (navigation used the same wait on main, re-armed on every later plugin reload), so a plugin install or update later in the session never blanks these surfaces after the Automatic winner changed.
  • Migration. The device-only localStorage picks (bb.appearance.diffRenderer, bb.appearance.sourceCodeRenderer, bb.fileOpenerByExtension with pluginId:id → pluginId/id) seed first paint and move to the server once, only while the server value is still the default (a conflict re-reads and keeps another device's pick); the legacy key is then removed.
  • Crash. A crashed non-bundled composer or thread list now renders the bundled one (same host draft and attachments for the composer) with a persistent "X crashed" toast whose action is Reload; the pick does not change.
  • Settings. Each pick row sits with what it changes, as on main: Navigation, Sidebar thread list, Source code, Diffs and Composer in Settings → Appearance → Interface (plus the new Thread header title row), and per-extension openers in Settings → Files → File openers. Code-block and directive rows go in a new Settings → Appearance → Markdown section ("Choose how code blocks and directives are rendered in Markdown."), with a row for every language or directive any plugin draws, so a single plugin's renderer can still be switched back to bb's own. Single-surface rows appear only when there is a real choice; keys with the same claimants and the same pick share a row (e.g. "bash, console, sh, shell, terminal, zsh code blocks"). Settings search indexes every row where it lives.
  • CLI / docs / Guide / skill. bb settings ui set help mentions maps take JSON; bb settings ui list descriptions state the rule. Updated docs/configuration.md, the customization guide template, the Plugin Guide (one "Exclusive slots" card in Plugin backend; per-slot cards link to it), SDK JSDoc (per-slot exclusivity notes now point to that card and name the pick key), the bb-plugin-authoring skill (an "Exclusive slots" section, onInstall example that only writes over __automatic__), docs/api_to_audit.md entries for the affected experimental slots, plugin READMEs/overviews that pointed at Appearance/Files, and the verify-bb settings feature map. The thread-list section the skill now keeps in frontend-thread-list.md states the exclusivity rule and the bundled-list crash fallback; the replacement-lab example points at Appearance → Sidebar thread list. Plugin SDK 0.6.184 (JSDoc only, no new member).
  • No new SDK member, no server/daemon wire change (HOST_DAEMON_PROTOCOL_VERSION unchanged).
  • Choices kept from review: sourceCode.provider is included (the source code renderer slot still exists, and leaving its pick in localStorage would keep a second store); __builtin__ for a directive means "show as text" and dismisses the in-message picker; the crash toast stays until dismissed (an auto-closing one left no way back to the crashed plugin); a file opened before plugins first finish loading, whose picked opener hasn't arrived yet, opens in bb's preview, because a one-shot open has no loading state.

Follow-ups

  • CLI command names are another keyed exclusive surface with no pick: with Tasks and tasks-plus both enabled, bb plugin list shows command: bb tasks for both with no warning, and bb tasks always routes to Tasks, so tasks-plus's CLI can't be reached by name.

Community plugins that can migrate (not edited here): nav-rail and compact-nav write the retired sidebar.headerProvider in onInstall and throw on preferences[key].revision; stewards already writes only over __automatic__; bang-shell/inline-terminal users can now pick per language; tasks-plus and scott-tasks users get an in-message plugin picker for ::task.

How you verified

Tests that fail on main for the class of bug:

  • apps/app/src/lib/pinned-replacement-surfaces.test.tsx: one contract table run against all eight surfaces (composer, thread list, navigation, source, diff, header title, .md opener, bash fence): pinned wins and Settings names it; absent pin behaves as Automatic once settled; installed ranks ahead of bundled and official-marketplace plugins by id; loading waits for the pin. On main the opener, header-title and fence rows fail (id-sorted bundled first, no pick, collision renders nobody).
  • exclusive-pick-first-paint.test.ts: every pick key, including composer.provider and sidebar.threadListProvider, starts from the device's last pick after a reload; a pre-upgrade pluginId:id opener map seeds first paint as pluginId/id.
  • ui-preferences-sync.test.ts: a legacy pick is written to the server only while it is at its default, dropped otherwise, and a concurrent device's write wins.
  • PluginChoiceSettings.test.tsx: two shell renderers share one row and one pick writes all six languages; a contested ::task row is "Not chosen" until picked; a code block or directive only one plugin draws still gets a row whose "bb (built-in)" / "Show as text" writes __builtin__.
  • markdown-message-directives.test.tsx / .test.ts: a contested directive renders its source with a "Choose plugin" menu listing both plugins then Settings…, and picking one renders that plugin; picks, __builtin__ and loading states.
  • PluginThreadList.test.tsx: a crashed installed list shows the bundled list and the toast's Reload remounts the installed one.

Commands: pnpm exec turbo run typecheck lint --filter=@bb/app --filter=@bb/domain --filter=@get-bb/plugin-sdk --filter=@bb/cli --filter=@bb/server --filter=bb-plugin-plugin-api-docs --filter=bb-plugin-bb-guide --filter=@bb/templates (pass), lint:type-aware for app/domain/cli (pass), turbo run test for the same packages (pass after fixes; app 7368, server 4425, cli 1413, sdk 445, domain 361 tests).

Live (pnpm start:worktree, community plugins installed from the 503-repo corpus, headless Chrome):

  • Kill-test 2: bang-shell + inline-terminal with a streamed 120-line ```bash reply: one plugin root element for the whole stream, bang-shell by id; one Settings → Appearance → Markdown row "bash, console, sh, shell, terminal, zsh code blocks" switched all six to inline-terminal (bb settings ui get codeFence.byLanguage matches, thread re-renders with inline-terminal). Main: both claimants → bb's block plus six console warnings.
  • Kill-test 3: on main, device A pinned Diffs to bb and three pluginId:id openers, device B pinned image-diff. After upgrading A then B: the CLI shows A's picks in / form (revision 1), B's local pick was dropped, both devices' legacy keys are gone, and both render what the CLI reports.
  • Kill-test 4: pins bb--composer/composer and thread-list/thread-list with t3-composer and stewards installed, GET /api/v1/preferences/ui delayed 2 s by CDP Fetch, screencast: 3 runs, zero frames of t3-composer or stewards (main: ~1.7 s of both). With both on Automatic, t3-composer and stewards paint first with no bb flash.
  • Later plugin reloads: with a local thread-list plugin as the remembered Automatic winner, disabling it mid-session and then enabling an unrelated plugin painted the thread-list loading placeholder for a frame before the boot-only wait; after it, 0 placeholder frames in 3 runs (control with no winner change: 0). A cold reload with that plugin remembered still shows 0 frames of the bundled list before it (3 runs).
  • Kill-test 6: t3-composer crashed mid-draft ("second draft" + attachment): bb's composer shows the same text and attachment, the toast stays, Reload brings t3-composer back with the draft.
  • Kill-test 7: with obsidian-at-home (wikilinks) and Docs installed, README.md opens in wikilinks under Automatic (main: Docs) and Docs stays in the file link's Open with menu; a .md pick on a disabled markdown-reader opens with Automatic's opener, not bb's preview (main: bb's preview).
  • Contested directive (two local plugins claiming ::zz-card): the reply shows ::zz-card{label="…"} as text in a card with "Choose plugin" top right; the menu lists both plugins, a divider and Settings…; picking one replaces the card with that plugin's view and bb settings ui get messageDirective.byName returns {"zz-card":"zz-shell-b/zz-card"}; Settings… opens Appearance with the Markdown section in view. Checked at 1280 px and 390 px (menu opens as a bottom sheet).

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/implement-plugin-winner-rule-api-thr_iiq29hrnps branch 3 times, most recently from 89b544f to 1e66bdf Compare November 23, 2026 18:43
ymichael and others added 3 commits November 23, 2026 12:03
One resolver (resolveExclusive) now decides the composer, thread list,
sidebar navigation, diff and source renderers, thread header title, file
openers, code fences and message directives. bb's bundled plugins are
ordinary claimants. A present pick wins, an absent one waits for plugins to
load and then behaves as Automatic (first plugin the user installed by id,
then bb's own, bundled or from bb's official marketplace, then core's). A message directive several plugins claim has no
Automatic winner and renders its source with a Choose link.

Picks are synced UI preferences only: new keys diff.provider,
sourceCode.provider, threadHeader.titleProvider, fileOpener.byExtension,
codeFence.byLanguage and messageDirective.byName; no key is renamed or
retired. Every pick key has a device last-known cache so first paint uses
the user's pick. Device-only diff, source and file-opener picks move to the
server once while it is still at its default.

A crashed installed composer or thread list renders the bundled one with a
persistent Reload toast. Settings → Installed plugins → Plugin choices
replaces the Appearance and Files rows. Docs, Plugin Guide, SDK JSDoc and
the plugin-authoring skill describe the rule. Plugin SDK 0.6.177.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The composer, thread list and navigation remembered their last Automatic
winner when they mounted and waited for it whenever plugin frontends were
not settled. Settled goes false on every later plugin install, enable or
update, so after the Automatic winner changed in a session each later
plugin reload blanked the surface to its loading placeholder. The wait now
applies only until plugins first settle, and the exclusive resolver no
longer takes the settled flag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hoice where it applies

A message directive that several plugins claim now shows as text in a card
like a code block, with a "Choose plugin" menu in its top right: one item per
plugin, then a divider and Settings. A pick there writes
messageDirective.byName like the Settings row does.

The Plugin choices section is gone. Each row sits with what it changes, as
on main: Navigation, Sidebar thread list, Source code, Diffs and Composer in
Settings → Appearance → Interface (now with Thread header title), and file
openers in Settings → Files → File openers. Code block and directive rows go
in a new Appearance → Markdown section, with a row for every language or
directive a plugin draws, so the user can switch one back to bb's own even
when only one plugin claims it. Search, docs, the Guide and the skill point
at those places.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/implement-plugin-winner-rule-api-thr_iiq29hrnps branch from 1e66bdf to 66d72c4 Compare November 23, 2026 20:11
@ymichael
ymichael merged commit 94fcbd1 into main Nov 23, 2026
53 checks passed
@ymichael
ymichael deleted the bb/implement-plugin-winner-rule-api-thr_iiq29hrnps branch November 23, 2026 20:21
ymichael added a commit that referenced this pull request Dec 1, 2026
…8507)

## Human comments

## What was wrong

Boot JavaScript grew from 393.2 KB to 418.9 KB brotli between #7744 (Nov
18) and main, leaving 0.2 KB under the 419.1 KB limit. Two of the
largest steps were static edges from the boot path into page-only code:

- #8089: `plugin-navigation-hooks` imports `useTimelinePaneThreadId`
from `timeline-viewport.tsx`, which also defined
`TimelineViewportScrollSource`. That put `bottom-anchored-scroll-body`
and `scroll-position-keeper` on boot.
- #7960: `active-composer.ts` built the active composer's plugin handle
itself, so the action-context binder (on boot) pulled in
`plugin-composer-handle`, the SDK's `composer-handle` and
`composer-draft-actions`, `plugin-composer-host` and
`composer-editor-registry`. #8050 added a second path to the same
modules: plugin navigation converts `initialPrompt` parts through
`plugin-composer-handle.ts`.

#7962's boot growth (~1 KB brotli) is the exclusive-pick logic the
sidebar thread list and navigation need before they paint, so it stays.

## What changed

- `TimelineViewportScrollSource` moved to
`apps/app/src/lib/timeline-viewport-scroll-source.tsx`;
`timeline-viewport.tsx` exports `useTimelineViewportStore` for it.
- `ActiveComposerCandidate` gained `handle(pluginId)`. `composer-root`
registers a factory built by the new `active-composer-handle.ts`, and
`getActiveComposerHandle` calls it, so `active-composer.ts` no longer
imports the handle code. `experimental_useActiveComposer` uses the same
builder.
- `initialPromptSeedFromComposer` and `mentionText` moved to
`apps/app/src/lib/initial-prompt-seed.ts`. It imports
`composerDraftFromInsertParts` from a new SDK internal subpath,
`@get-bb/plugin-sdk/internal/composer-draft-transforms`, where that
function now lives. A re-export through `internal/composer-handle` still
kept the whole module on boot.
- Plugin SDK 0.6.216 for the new subpath.
- `bundle-budget.json`: `splitBoundaries` boot guards for
`bottom-anchored-scroll-body.tsx`, `active-composer-handle.ts` and
`plugin-composer-handle.ts`, plus a dated `$comment` entry. Limits
unchanged.

## How you verified

Real builds of main (e0c49e2) and this branch, brotli bytes from the
`.br` files `check-bundle-budget.mjs` counts:

| Closure | main | branch | Δ |
|---|---|---|---|
| boot | 428,920 | 419,163 | −9,757 |
| ThreadPage | 498,511 | 507,873 | +9,362 |
| NewThreadPage | 268,226 | 277,858 | +9,632 |
| PluginFrontend | 219,813 | 229,475 | +9,662 |
| boot + each page | | | −95 to −395 |

Raw boot: 1,708,056 → 1,668,548. Every page shell uses the scroll body
(`page-shell.tsx`) and every page loads the plugin runtime that needs
the composer handle, so the code moved into the shared page chunks. The
shell's critical path shrinks, the total before page content is
unchanged, and boot is back to 2.3% headroom. I didn't measure paint
timings.

- Negative control: re-adding the `timeline-viewport` → scroll-body
import and a `plugin-navigation-hooks` → `plugin-composer-handle` import
fails the check with both new guards, and boot returns to 418.6 KB.
- `pnpm exec turbo run test --filter=@bb/app
--filter=@get-bb/plugin-sdk`: 709 + 47 test files pass.
- `pnpm exec turbo run typecheck lint --filter=@bb/app
--filter=@get-bb/plugin-sdk`, `node
apps/app/scripts/check-bundle-budget.mjs`, `oxfmt --check`.
- Live `pnpm start:worktree` with a real Claude Code thread, driven in
headless Chrome: no console errors, scroll-to-latest works, the outline
rail's active tick follows scrolling, and typing in the composer works.

> AGENT GENERATED

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

Co-authored-by: Claude Opus 5.5 <[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