Repository navigation
Description
The workflow
A plugin that ships both a provider (bb.providers.register) and composer UI needs two things. They apply to any provider plugin, not just the one that prompted this (Polytoken). Mode, profile, or agent selectors for ACP/OpenCode-style agents (#1093, #2787) are potential consumers when exposed through a provider plugin. This request does not add native ACP mode controls.
- Know which provider the composer is targeting. A composer plugin should only show its provider-specific control (for example a mode, profile, or "facet" chip) when its own provider is selected in that composer. It should hide the control after the user switches to Codex or Claude Code.
- Carry a choice made in the new-thread draft into the provider's configuration. The user picks something in the new-thread composer before the thread exists. That value should be persisted with the thread and handed to the provider plugin's
deriveProviderOptionshook on each dispatch, so the bridge can start the session in that state.
What happens today
On public main at d81d3d1f8a5c55d7dafbd86b61d086aced02df90:
ComposerViewexposes scope, layout, draft, and run state, but not the provider selected in that composer. Plugins have to guess from project defaults, which differ from the live picker value after a switch.- feat(plugin-sdk): add thread plugin metadata with review fixes #3555 added per-thread plugin metadata. A thread can be seeded with it only via
createThreadRequestSchema.pluginMetadata, which requiresorigin: "plugin"(a plugin creating its own thread). A user-created thread from the ordinary new-thread composer cannot carry any plugin's namespace, and a composer plugin has no draft-scoped place to store it. PluginProviderOptionsContextgivesderiveProviderOptionsthe thread, project, model, permission mode, prompt mode, and settings, but not the provider plugin's own thread metadata. So even stored metadata cannot influence provider options without a separate side channel.
What you would expect
Three experimental, opt-in additions. A working prototype is linked below.
ComposerView.experimental_selectedProviderId: string | null: the effective provider in the composer where the plugin is mounted. It is reactive to provider switches, including when a project default differs from the selected value. It isnullwhile unresolved or where the host does not supply it; the prototype wires new-thread and follow-up composers, and other surfaces reportnull. It exposes no provider metadata or server state.- New-thread draft metadata:
useComposer().experimental_pluginMetadata/experimental_setPluginMetadata(obj). This is a persistent JSON object per plugin, keyed by the existing prompt-draft storage key. A plugin reads and writes only its own namespace, and an empty object clears it. The getter isnulland the setter absent when the host composer doesn't support it. On submit, the map is sent ascreateThreadRequestSchema.experimental_pluginMetadataByPluginand written into each plugin's feat(plugin-sdk): add thread plugin metadata with review fixes #3555 namespace in the same transaction as thread creation.- It is rejected with
origin: "plugin",originKind, orsourceThreadId(forks). Plugin-origin requests keep usingpluginMetadata. - The aggregate limit is 256 KiB.
- It is not echoed in thread responses.
- On submit it is cleared together with the text draft and restored together with it if creation fails, so newer edits are never mixed with the old pair.
- CLI (
bb thread spawn) and SDK (threads.create) can pass the map and keep their normal origin.
- It is rejected with
PluginProviderOptionsContext.experimental_pluginMetadata: the owning provider plugin's own per-thread metadata, read synchronously on each dispatch. It is deep-frozen,{}when absent or corrupt, and treated as untrusted, user-writable, nonsecret JSON. The hook decides which values to use. A test asserts the raw snapshot is not serialized into command output. No server/daemon wire change:deriveProviderOptionsruns server-side.
Non-goals / limits:
- No provider-state observation, no model-ownership semantics, and no native mode/facet placement. Those are a separate design-alignment topic (see Context).
- No metadata for forks or follow-up turns. Only thread creation seeds it; after that, existing feat(plugin-sdk): add thread plugin metadata with review fixes #3555 thread metadata APIs apply.
- All three members use the
experimental_prefix, withdocs/api_to_audit.mdentries listing the stabilization audits: cross-surface consistency forselectedProviderId, namespace ownership, reload/provider-switch isolation, concurrency, and size semantics.
Context and alternatives
Prototype (fork branch, not a PR; opening an issue first per CONTRIBUTING):
- Branch: https://github.com/samanthar0se/bb/tree/plugin-composer-provider-context
- Stable review diff, pinned to base
d81d3d1f8and head15ceec34b: d81d3d1...samanthar0se:bb:15ceec34ba40b065ad83f80b01171d2081d2af88 - Commits on top of
d81d3d1f8: - Total: 43 files, +1418/−89, mostly tests. It touches plugin-sdk (app + backend contracts, test harness), app composer hosts, server-contract, server thread create/dispatch, db
createThread, CLIthread spawn, SDKthreads.create, Plugin Guide surfaces,docs/api_to_audit.md,docs/provider-plugin-api.md, anddocs/cli-guide-and-skill.md. No DB schema change and noHOST_DAEMON_PROTOCOL_VERSIONbump.
Verification on the prototype (rebased onto d81d3d1f8, macOS, Node 26.8.2):
-
pnpm exec turbo run typecheckpassed for app, server, cli, db, plugin-sdk, sdk, and server-contract. Lint passed with 0 errors (warnings only). -
Targeted tests:
Package Tests @bb/app(10 composer/prompt-box/plugin-host files)191/191 @bb/server(test/threads+ provider registration)529/529 @bb/db(test/data)438/438 @bb/cli(thread-spawn)48/48 @get-bb/plugin-sdk(public types, app harness)65/65 @bb/sdk113/113 @bb/server-contract84/84 scheduled-send plugin 22/22 -
Mutation checks: removing the ROOT-fork metadata guard makes the fork-rejection test fail, and the remaining metadata tests cover stale-generation writes, clear/restore pairing, contract rejections, 256 KiB limit, and runtime-config injection.
Related, not duplicates:
- feat(plugin-sdk): add thread plugin metadata with review fixes #3555 (merged): per-thread plugin metadata. This builds on it; it adds no new storage.
- Support private launch context for plugin-created threads #3438 (closed): private launch context for plugin-created threads. Plugin-origin only; this covers user-created threads.
- Session context policy: let a plugin narrow what one agent session loads (BB plugins, skills, MCP, CLI plugins, instructions) — working prototype #4233: plugin-narrowed session context policy. It is adjacent (plugin influence over a session) but concerns loaded capabilities, not provider options.
- Make OpenCode custom models and agents clear and selectable #1093 / Add provider-specific profile selection for ACP agents (Hermes) #2787: mode and profile selection for ACP agents. Provider plugins that expose such selectors could consume these APIs. This issue does not implement native ACP mode controls, mode placement, or model-ownership semantics; a separate provider session-controls proposal covers those.
- Render plugin composer actions in compact layouts #3358: compact composer plugin actions. It is orthogonal (layout), though a provider-specific control would also want it.
Alternatives considered:
- Deriving the provider from project defaults in the plugin breaks after an in-composer switch.
- Storing draft state in plugin-private storage and patching thread metadata after creation leaves a race with the first dispatch, and the first turn misses the value.
- A plugin-side RPC from the bridge to fetch metadata puts a side channel on the hot dispatch path, where the server already holds the data.
Verification limit: fork rejection is tested by seeding the fork through useRootComposeForkSeed. The location-state fork path has a separately reproduced upstream test regression on current main, not verified in the live app. The prototype was not exercised in the live app.
Checks
- I searched open and closed issues for the same request.
- If an agent wrote this, the body ends with
> AGENT GENERATED.
AGENT GENERATED
Activity