Repository navigation
Unify the composer API and share draft editing with core - #4474
Merged
Merged
Conversation
One useComposer() returns a stable, live handle bound to its composer's
draft: key, layout, isRunning, isSubmitting, isSubmittingBlocked,
submittingBlockedReason, isEmpty, attachmentCount, text, structured draft
with full mention data, insert(parts, { at, block }), removeMention,
onSubmitted, submit (the Enter gate, waiting for uploads) and setSelection.
The editor publishes its send decision and cursor insert through a
per-composer registry. plusMenu/sendMenu items receive the composer, message
actions get the message's thread composer, and banners respect the suppress
flag. Replaced names are @internal: stripped from the published types but
still exported and implemented at runtime so existing plugins keep working.
Built-in plugins, the example plugin, the testing harness and docs are
migrated; Plugin SDK 0.6.0.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Panels and pages that write into a composer the user picks (file-tree, file-manager) built hidden banners and module buses to find the mounted composers. The editor registry now records each editor's host, and useComposers() returns a stable handle per composer that customizations mount in, oldest first. Listed handles share the message-action composer's detached controller, so visual effects and input locks are no-ops there. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The SDK testing harness carried its own copy of the composer handle (insert, mention ranges, pill text, mention rebasing, removeMention, the submit gate), which had already drifted from the app. The handle now lives in @get-bb/plugin-sdk/internal/composer-handle over the public ComposerDraft shape; the app supplies its stored draft and editor registry, the harness an in-memory draft and its log. Mention conversion uses spreads instead of two hand-written switches, the prompt box's pre-editor insert fallback reuses the shared append, and the unused removePluginMention and ComposerLog.inserts are gone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Switching a prompt box between drafts left the previous draft's editor registered: the passive cleanup for the old key read the shared ref after the new key's layout effect had overwritten it, so the registry rejected the mismatched bridge and useComposers() kept listing it. The layout effect now clears the previously published entry itself when the key changes. A scope change (the new-thread composer switching projects) dropped every onSubmitted listener while the handle kept its identity, so plugins that subscribe once per handle stopped hearing submissions. The shared handle now retains its listeners and moves a single subscription to the new scope. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Both actions send the draft, so they belong beside the send button rather than in the "+" menu. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ymichael
force-pushed
the
bb/composer-api-redesign
branch
from
September 29, 2026 16:51
61e4b83 to
95791d3
Compare
ymichael
added a commit
that referenced
this pull request
Sep 29, 2026
… plugins (#4502) ## Human comments ## What was wrong After #4474, plugins could write composer picker settings but could not reactively read them. The Automation and Plugin creation rows were also hard-coded in the core `+` menu, so the plugins that own those features could not contribute them. The menu's command rows edited the draft relative to the cursor (replacing a preceding action or a half-typed command, skipping duplicates), which plugins cannot reproduce because they cannot see the cursor. ## What changed - Added `composer.selection: ComposerSelection | null`, with stable snapshots and subscriptions in `useComposer` and `useComposers`. It reports the thread (including handoff) and new-thread pickers, and the read-only pickers of queued-message and sent-message editors: the thread's provider with the queued message's or the thread composer's settings. Composers without pickers return null. `setSelection` retains partial updates. - Plan, Goal, Automation, and Plugin rows now put their command or prompt at the start of the draft, replacing a leading command pill; clicking the same row again changes nothing. Commands work anywhere in a message, but Automation and Plugin are sentence starters and `/goal` is passed to Codex as text, so the start is the only position that matters. This removes the cursor-based replacement and duplicate logic from #194; a half-typed `/pl` is no longer replaced. Skills still inserts its trigger at the cursor because it opens the skills picker. - Moved the Automation row into the Automations plugin and Plugin creation into default-enabled BB Guide. Both insert their sentence ("Create a new bb automation to" / "Create a new bb plugin that") with the existing `composer.replace`; there is no new composer method. Core applies the same rule to its provider-declared Plan/Goal rows. Explicit menu-row icons now take precedence over plugin branding, so both rows keep their original icons. - Both rows appear in the same composers as on main, including the sent-message editor: plugin `+` menu rows are exempt from its customization suppression, while actions, banners, send-menu rows, and rich text remain suppressed there. - Removed the `/automation` macro from core: it is no longer offered in slash autocomplete, converted on paste, or expanded to the automation sentence on send (along with the legacy `/loop` alias). Core no longer knows about Automations. An unsent local draft that already holds an `/automation` pill now sends it as literal text. - Bumped the SDK to 0.6.2 for `selection`. Automations and BB Guide require SDK 0.6.0 for `replace`. Updated the Plugin Guide, authoring references, and API audit. These are client-local changes; no database, server/daemon wire, or CLI changes. ## How you verified - `pnpm exec turbo run test --filter=@bb/app` on the promptbox, plugin, embedded-chat, thread-detail, and lib suites plus useCommandSuggestions: 1931 passed. Covers the prefix rule (existing text, later pills shifting, replacing a leading command, repeated clicks), core/plugin row order and icons in new-thread, thread, and queued-message composers, menu rows re-rendering on selection changes, queued and sent-message selections (including a bottom handoff), and plus-menu rows under suppression. - Turbo tests for client-core (277), the SDK (361), Plugin Guide (82), Automations (135), and BB Guide (7) passed, including new unit tests for the two plugins' draft transforms. - Turbo lint/typecheck for the app, client-core, SDK, Automations, BB Guide, and Plugin Guide passed with no errors. The SDK version check passes. - Embedded chat's queued host has no test harness and is covered by typecheck only. This version has not yet been checked in the app. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
SawyerHood
added a commit
that referenced
this pull request
Oct 1, 2026
## Human comments ## What was wrong `usePromptDraftStorage` returned the live draft, so every component that needed any draft operation re-rendered on each keystroke: the composers, the plugin composer host with its banners and actions, and, through draft-presence ids threaded into the group builders, the sidebar tree. `useComposer()` subscribed every plugin composer contribution to draft and selection changes whether or not it read them. ## What changed Split out of #4532 (commits 087cbc3 and aab5c06 together, applied on current main). Part 6 of 6. Independent of the suggestion warm-up PR; the two merge cleanly. - `apps/app/src/hooks/usePromptDraftStorage.ts`: a stable `usePromptDraftController` plus opt-in `usePromptDraftSnapshot` and `usePromptDraftInputEmpty`. Debounce, flush on `pagehide`/`visibilitychange`, the cross-tab `storage` listener, `clearIfCurrentMatches` and `restoreIfEmpty` are unchanged. - `apps/app/src/components/plugin/plugin-composer-host.tsx`, `PluginComposerBanners.tsx`, `PluginComposerActions.tsx`, `promptbox/PromptBoxActionsMenu.tsx`: static scope/layout/run view split from the draft context; banner rows and the action list are memoized. - `apps/app/src/lib/plugin-sdk-hooks.ts`: `useComposer()` subscribes to the draft only once the caller reads `text`, `draft`, `isEmpty` or `attachmentCount`, and to selection only once it reads `selection`. Returned values are unchanged and no public SDK member is added. - `apps/app/src/components/promptbox/NewThreadComposer.tsx`: only `LiveDraftNewThreadPromptBox` follows the live draft. - `plugins/thread-list`: collapsed rows read draft presence from one published draft-id set (`list/sidebarDraftPresence.ts`) instead of a `draftThreadIds` argument through every group builder. Not included from #4532: the re-added `addQuote` (removed on main in #4474 and unused), the `ThreadDetailPromptArea` memo (needs stable props from another commit), and the scheduled-send formatter caching. Review note: lazy tracking writes two refs during the plugin's render, which adds one `react(refs)` lint warning at `plugin-sdk-hooks.ts`. A draft change between the render that first reads a field and its commit is seen on the following change. ## How you verified - `pnpm exec turbo run typecheck lint --filter=@bb/app --filter=bb-plugin-thread-list`: pass, 0 lint errors (app warnings 208 vs 207 on main, the one above). - `pnpm exec turbo run test --filter=@bb/app --filter=bb-plugin-thread-list --concurrency=1`: `@bb/app` 5,185 passed, 6 skipped; thread-list 443/443. - Two new tests in `plugin-slot-mounts.test.tsx`: a plugin that starts reading `text`/`isEmpty` only after a local toggle keeps updating, and a plugin that reads only `useComposer().selection` re-renders on picker changes. Both fail with tracking disabled (the state of 087cbc3 alone). - Not re-measured on this base. #4532 measured the first thread keystroke at 4× CPU throttle at 222 ms → 118 ms on its older baseline. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > AGENT GENERATED Co-authored-by: hemaaanth <[email protected]> Co-authored-by: Claude Code <[email protected]>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Composer state and actions were split across hooks, and plugins lacked a complete draft snapshot and atomic structured replacement. Core quoting, prefills, and history restoration bypassed the plugin editing contract. Plugins also built their own composer-discovery buses, and the send menu hard-coded first-party plugin IDs.
What changed
useComposer()provides a stable handle with draft identity, editor state, the same submission gate as Enter, and a complete{ text, mentions, attachments }snapshot.submit()waits for uploads and also works in embeddedThreadChat.insert(parts, { at, block })inserts text and pills at the cursor or end.replace(next)orreplace(current => next)commits text, explicit mention ranges, and optional uploaded attachments together. Omitted attachments are preserved;[]clears them. Invalid replacements and throwing updaters leave the draft unchanged. Replacement does not infer mention ranges, upload files, or focus the editor.useComposers()discovery; sent-message editors are excluded from discovery. Stale registration and submission-listener cases are covered.ComposerCustomization.sendMenureplaces hard-coded plugin IDs. Menu callbacks receive a composer handle; message actions receive their thread's composer when available. Save draft and Send later appear only in the send menu. First-party plugins and the customization example are migrated.setText,updateText,clear,addQuote,insertMention, andremoveMentionare stripped from published declarations but retained at runtime for older plugins. New plugins useinsertandreplace; replacement requires explicit mention ranges rather than automatic reconciliation. Annotations useinsertand a localreplacetransform. Earlier hook/type aliases and experimental composer method names retain their existing runtime compatibility.How you verified
setText,updateText,clear,addQuote,insertMention, andremoveMentionare absent; supported methods includinginsertandreplaceremain present.pnpm exec turbo run build:types typecheck --filter=@get-bb/plugin-sdkpassed, and the focused SDK harness/frontend-export/package-export suites passed again (57 tests). Runtime implementations are unchanged.flushSynclifecycle warning was observed during pill restoration; rendered and persisted data remained correct.