Skip to content

Unify the composer API and share draft editing with core - #4474

Merged
ymichael merged 8 commits into
mainfrom
bb/composer-api-redesign
Sep 29, 2026
Merged

ymichael merged 8 commits into
mainfrom
bb/composer-api-redesign

Conversation

@ymichael

@ymichael ymichael commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

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 embedded ThreadChat.
  • insert(parts, { at, block }) inserts text and pills at the cursor or end. replace(next) or replace(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.
  • Core quoting, prefills, and history restoration use the shared replacement implementation. Quotes append blockquoted text and merge independent draft attachments by path, then focus. History conversion is centralized in the app adapter; quote transforms no longer convert mention formats. Stored/editor formats remain unchanged.
  • The SDK handle implementation is shared with the test harness. The app adapter connects it to storage, editor insertion, selection, and lifecycle. A mounted-editor registry supports live state and useComposers() discovery; sent-message editors are excluded from discovery. Stale registration and submission-listener cases are covered.
  • ComposerCustomization.sendMenu replaces 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, and removeMention are stripped from published declarations but retained at runtime for older plugins. New plugins use insert and replace; replacement requires explicit mention ranges rather than automatic reconciliation. Annotations use insert and a local replace transform. Earlier hook/type aliases and experimental composer method names retain their existing runtime compatibility.
  • No new public editing-helper exports. Mention/text transforms remain internal. Command autocomplete's trigger-range replacement and dismissal remain an explicit API gap.
  • Updated Plugin Guide surfaces, authoring references, guide templates, and SDK declarations. SDK version is 0.6.0; migrated plugins require it. Final composer names are recorded exceptions to the experimental-prefix rule. No server/daemon wire change.

How you verified

  • Turbo typechecks and lint passed for app, SDK, annotations, Plugin Guide, and client-core; lint reports warnings, zero errors.
  • Focused suites passed: 288 app, 57 SDK, 4 annotation, 13 Plugin Guide, and 18 client-core tests during the consolidation. After hiding the quote and mention helpers, reran SDK harness/export tests, annotation tests, and Plugin Guide tests successfully.
  • Coverage includes atomic history restoration, metadata-only pill changes, attachment preservation/clearing, immutable snapshots, updater errors, invalid ranges, closed editors, multi-pill removal, Unicode offsets, foreign-plugin mentions, stable handles, and composer discovery.
  • Rebuilt and inspected both generated SDK declaration bundles: setText, updateText, clear, addQuote, insertMention, and removeMention are absent; supported methods including insert and replace remain present.
  • After hiding the legacy text methods, pnpm exec turbo run build:types typecheck --filter=@get-bb/plugin-sdk passed, and the focused SDK harness/frontend-export/package-export suites passed again (57 tests). Runtime implementations are unchanged.
  • Isolated Chromium checks confirmed home prefills, core quoting with uploaded attachments, history recall, plugin draft restoration, command-pill removal/restoration, invalid-update rejection, insertion, and persisted drafts after reload. The final type-only change and annotation migration were verified through declarations and tests. Queued/sent editor paths were tested automatically; iOS was not exercised.
  • Existing React/Tiptap flushSync lifecycle warning was observed during pill restoration; rendered and persisted data remained correct.

AGENT GENERATED

@ymichael ymichael changed the title Redesign the plugin composer API Unify the composer API and share draft editing with core Sep 29, 2026
ymichael and others added 8 commits September 29, 2026 09:50
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
ymichael force-pushed the bb/composer-api-redesign branch from 61e4b83 to 95791d3 Compare September 29, 2026 16:51
@ymichael
ymichael merged commit c51f38c into main Sep 29, 2026
19 checks passed
@ymichael
ymichael deleted the bb/composer-api-redesign branch September 29, 2026 17:12
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]>
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