Skip to content

Add the thread actions slot and render both thread menus from it - #5145

Closed
ymichael wants to merge 2 commits into
mainfrom
bb/cherry-pick-and-summarize-changes-thr_te6hx5v9vm
Closed

ymichael wants to merge 2 commits into
mainfrom
bb/cherry-pick-and-summarize-changes-thr_te6hx5v9vm

Conversation

@ymichael

@ymichael ymichael commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

bb's thread header menu (in core) and the thread-list plugin's row menus (dropdown, right-click, compact drawer, hover quick-action buttons) each kept their own copy of the same thread actions — split, copy link, mark read, pin, move to section, rename, archive, delete. The two copies could drift, and there was no way for a plugin to add a row to either menu. Separately, the thread-list plugin had moved organizationMode and manualSectionOrder into its own KV, so core's section-move context and sidebar reveal were reading a stale copy left in core UI preferences.

What changed

  • New experimental plugin API (@get-bb/plugin-sdk/app, SDK 0.6.29):
    • app.slots.experimental_threadAction({ id, title, resolve }) — resolve({ thread, surface, metadata, rpc }) returns a data description of the action (label, icon, group: open | organize | lifecycle, and either run or a choices list with select), or null to hide it. It gets the plugin's own thread_plugin_metadata row for the thread and the plugin's RPC client; the host refetches that metadata after run/select settles.
    • experimental_useThreadActions(target, surface) — returns the ordered core + plugin action list, so replacement thread lists render the same menu.
    • Documented in docs/api_to_audit.md, the Plugin Guide surfaces, and the bb-plugin-authoring skill references.
  • Core actions use the same shape (apps/app/src/lib/thread-actions/core-thread-actions.ts). Both the header menu and every sidebar row surface now render from the hook. The duplicated section-move submenus, the plugin's own ThreadSectionMoveProvider, and the plugin's row-action model are deleted.
  • rowActions preference stores action keys (core:archive, <pluginId>/<id>). Legacy bare ids (archive, pin, …) migrate to core:<id> when read. Docs and the thread-list skill are updated.
  • Thread-list preferences go back to core. organizationMode and manualSectionOrder are stored in core UI preferences (sidebar.*) again, with a one-time reverse migration from the plugin KV, so core reads live values.
  • No server/daemon wire changes; no DB schema changes.

This is a cherry-pick of 299d3484b0 onto current main. Conflict resolutions: kept main's SidebarRenameProvider wrapper and new hover-hidden class in ThreadRow.test.tsx; dropped main's edit to the deleted plugin ThreadSectionMoveProvider (moves now go through core's useMoveThreadToSection mutation); took main's cache-owner test, which no longer has the import inventory; bumped the SDK 0.6.28 → 0.6.29.

How you verified

  • pnpm exec turbo run typecheck lint --filter=@bb/app --filter=@get-bb/plugin-sdk --filter=./plugins/thread-list --filter=./plugins/plugin-api-docs: passes (warnings only).
  • pnpm exec turbo run test on the same filters: app 5578 passed, plugin-sdk 365, thread-list 461, plugin-api-docs 74.
  • @bb/server plugin-authoring-docs.test.ts: 22 passed.
  • .github/workflows/check-plugin-sdk-version.mjs: the SDK surface change comes with a version bump.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits October 7, 2026 15:22
Core's thread header menu and the thread-list plugin's row menus each
kept their own copy of the same actions, and no plugin could add a row.
`app.slots.experimental_threadAction({ id, title, resolve })` describes a
thread action as data: a leaf with `run` or a choice list with `select`,
grouped open / organize / lifecycle. `resolve` receives the thread
target, the surface, the plugin's own thread metadata row and a
plugin-bound rpc client; the host refetches that metadata after the
action settles. `experimental_useThreadActions(target, surface)` returns
the ordered core + plugin list and is public so replacement thread lists
render the same menu.

The seven core actions are defined with the same type. Both menus render
from the hook across dropdown, context menu, compact drawer step and
sidebar quick-action button surfaces; the duplicated section-move
submenus and row action model are deleted. `rowActions` stores action
keys (`core:archive`, `<pluginId>/<id>`) with a read-side migration of
the legacy ids.

The thread-list plugin stores `organizationMode` and
`manualSectionOrder` in core UI preferences again, with a one-time
reverse migration from its KV, so the host section-move context and the
sidebar reveal read live values instead of the stale copy left behind by
the earlier migration.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ymichael added a commit that referenced this pull request Oct 9, 2026
…thread menu actions (#5243)

## Human comments

## What was wrong

Core's thread header menu
(`apps/app/src/components/thread/ThreadActionsMenu.tsx`) and the
thread-list plugin's row menus
(`plugins/thread-list/app/rows/ThreadActionsMenu.tsx`) each hardcoded
the same eight actions, so the two drifted and no plugin could add an
entry. Earlier registry attempts paid for it per sidebar row: hooks per
row (about 40 observers per row on a 100-row sidebar) or a server-side
resolve with round trips and stale labels. This is step 1 of the thread
action registry plan: a registry whose cost scales with the number of
registered actions, never with rows. It supersedes #5145.

## What changed

**API (`@get-bb/plugin-sdk/app`, SDK 0.6.34, all experimental and listed
in `docs/api_to_audit.md`)**

- `app.slots.experimental_threadAction({ id, title, icon, group, order?,
useData?, item })`. `useData` is a hook the host runs once for the whole
app, in one collector per registration under `ThreadActionsProvider`.
`item({ thread, data, sdk, navigate })` is pure and returns the action
for one thread, or null. Placement (`group`, `order`) is static. The
host keeps registrations sorted by group string, then order, then
registration order, and menus put a separator between groups. bb's
groups are `experimental_THREAD_ACTION_GROUPS` (`1_open`, `2_organize`,
`3_settings`, `4_lifecycle`).
- An action is `{ label, icon, variant?, disabled?, choices?, run({
value, requestRename }) }`. `choices` is data: a submenu on desktop, a
drawer step at compact width, a popover from a row quick-action button.
- `experimental_useThreadActions(thread, { keys?, requestRename? })`
returns entries whose `run(value?)` is already bound to the caller's
rename editor, never throws, and resolves when the action settles.
`experimental_useThreadActionRegistrations()` lists every registration's
static title and icon in menu order.
- `experimental_ThreadActionsMenu` and
`experimental_ThreadActionsContextMenu` are bb's menus. The context menu
opens on right-click, and on long-press at compact width. Both take
`inline` items (`{ key, group, action }`) and `requestRename`. `trigger`
is a render function that must spread `PluginThreadActionsTriggerProps`
(props, ref, className) onto its button. The host logs a trigger that
drops them, and the SDK test fake throws.
- `useBbNavigate().toThread(id, { split })` and `toCompose({ projectId,
placement, environmentId, hostId, … })`.
`experimental_useArchiveEnvironmentThreads()` returns core's own
environment-archive flow.
- The bound SDK gains optimistic `threads.markRead` / `markUnread`.
- `experimental_useSidebarThreadActions`, `PluginSidebarThreadActions`,
and the testing harness's `SidebarActionCall` /
`inspection.sidebarActionCalls` are tagged `@internal`, like
`useComposerView`: they are gone from the published declarations, so
upgrading plugins get type errors, while the runtime keeps exporting the
hook, so installed plugins and host builds of plugins that still import
it keep working. Nothing in the repo calls it.
- Archive, Delete, and bb's rename dialog fetch a thread bb has not
cached (a plugin rendering the menu for a thread it fetched itself)
instead of doing nothing. A registration's `navigate.openThreadPanel`
opens in the focused thread view, as plugin commands do.

**Core.** bb's eight actions (Open in split, New thread in environment,
Copy thread link, Mark read/unread, Pin/Unpin, Rename,
Archive/Unarchive, Delete) are registrations of the public shape under
the reserved `bb--core` owner (`apps/app/src/lib/thread-actions/`). The
header menu, mobile recents, both sidebar row menus, and the archive
keyboard command all go through the registry. The header edits its title
inline from the menu and from the rename command. Core's
`ThreadSectionMoveProvider`, `useMoveThreadToSection`, and
`useUnpinAndMoveThread` are deleted.

**Thread list.** It registers Move to section (`thread-list/move`) from
its own section-order and organization preferences. Rows render the host
menus with a "Customize row actions" inline item and the row's inline
rename. Hover quick actions come from `experimental_useThreadActions`
with `keys`, and the picker lists registrations. `rowActions` stores
`<owner>/<id>` keys; bare legacy ids and `core/<id>` migrate on read and
write. The row-action model, the section-move provider, and the plugin's
menu fork are deleted.

**Also fixed:** a pre-existing race when archiving an environment while
one of its threads was in a split beside an unrelated thread. The split
area's stale-pane watcher could prune the archived pane before the
provider ran, and the provider then navigated away from a stale route,
closing the unrelated pane (7/7 on main). The environment archive now
runs as an `archive_thread` mutation like thread archive, so the watcher
waits and the provider closes panes deterministically.

No server or daemon wire changes. Docs: `docs/api_to_audit.md`,
`docs/configuration.md`, the thread-list skill, the plugin-authoring
references, and the Plugin Guide surface.

**Accepted deviations from main** (all accepted by Michael):

1. The header menu's Rename edits inline on desktop, as does the rename
keyboard command (the dialog remains at compact width).
2. Open in split is hidden for the thread in view and reads "Focus
split" for a thread open in another split pane, on every surface.
3. The row-actions picker lists every registration, which adds Delete
and New thread in environment.
4. Mobile recents long-press gains New thread in environment.
5. Row quick-action buttons are labelled with the action label
(`Archive`, `Unarchive`), not `Archive thread` / `Unarchive thread`.
6. A failed sidebar inline rename shows its error in the editor, without
the extra toast.
7. A failed drag-to-pin toasts the drop's failure message instead of
"Failed to pin thread.".
8. Phone thread-menu drawers are announced as "Thread actions" instead
of "Menu".

## How you verified

- One contract test table
(`apps/app/src/components/thread/ThreadActionsMenu.test.tsx`) runs four
surfaces against the same registrations: desktop dropdown, desktop
context menu, compact drawer, and compact long press. It checks items
and order per thread state (top-level, archived, pinned, unread child,
already in view, compact), each action's effect, the surface rename
editor versus bb's dialog, a throwing registration, a trigger that drops
its ref or classes, and registration order.
- Thread-list tests cover quick actions, Customize, inline rename from
both menus, Move destinations and the unpin-then-move writes, and the
`rowActions` migration. SDK harness tests cover the fake menu's trigger
contract.
- `SplitThreadArea.environment-archive.test.tsx` resolves the archive at
the moment a pane is pruned. It failed 3/3 before the fix and passes
after.
- `pnpm exec turbo run typecheck lint test --filter=@bb/app
--filter=@get-bb/plugin-sdk --filter=./plugins/thread-list
--filter=./plugins/plugin-api-docs --filter=@bb/server` passes (lint: 0
errors). In the gate run, three `install-machine-script` server tests
failed while a `pnpm install` ran alongside; the server suite passes
alone (3398). `turbo run typecheck --filter='...[2511116]'` (89
packages) and all plugin test suites (46 tasks) pass.
- Manual verification in two rounds on a dev instance against main:
thr_c6z735wvsd and thr_paxegndau4. The second round passed:
  - Row "..." on desktop and on archived rows, items identical to main.
  - Keyboard open, focus, and Escape.
  - Trigger accessibility attributes match main.
  - Narrow-width drawer with the Move step.
  - Picker order with Move between Pin and Rename.
  - Environment-group archive with Undo.
- Legacy `rowActions` values restored, and UI and CLI writes persist the
new keys.
  
Its findings (the trigger's lost `select-none` and the split race) are
fixed here.

Sidebar benchmark (`BB_SIDEBAR_BENCH=1`, 3,000 threads, 81 rendered
rows; median of 8 alternating runs). The branch's bench mounts core's
collectors and the thread-list Move registration as the app does:

| metric | main 2511116 | this branch |
|---|---|---|
| mountMs | 481 | 467.5 |
| statusPatchMs | 145 | 139.5 |
| membershipRefetchMs | 118 | 97.5 |
| pinMs | 152.5 | 148 |
| React Query observers | 1146 | 821 |
| observers per rendered row | 14.15 | 10.14 |

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

> AGENT GENERATED

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: qa <qa@x>
@ymichael ymichael closed this Oct 14, 2026
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