Repository navigation
Read a thread by id and let the host hand focus between a segment's toggle and collapse controls - #7955
Merged
ymichael merged 2 commits intoNov 23, 2026
Conversation
ymichael
force-pushed
the
bb/implement-thread-api-gaps-9-and-10-thr_uk8ggvt9pp
branch
from
November 21, 2026 14:14
1b65181 to
00e51d3
Compare
ymichael
force-pushed
the
bb/implement-thread-api-gaps-9-and-10-thr_uk8ggvt9pp
branch
2 times, most recently
from
November 23, 2026 21:32
4211cc8 to
176d0a6
Compare
…ent's toggle and collapse controls Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/implement-thread-api-gaps-9-and-10-thr_uk8ggvt9pp
branch
from
November 23, 2026 22:18
176d0a6 to
288c92b
Compare
ymichael
deleted the
bb/implement-thread-api-gaps-9-and-10-thr_uk8ggvt9pp
branch
November 23, 2026 22:26
ymichael
added a commit
that referenced
this pull request
Nov 23, 2026
## Human comments ## What was wrong #7107 merged at 22:25:17 with plugin SDK 0.6.189. #7955 had been rebased and bumped to 0.6.189 a few minutes earlier, while that number was still free, and squash-merged at 22:26:18. Git saw its version line as identical to main's, so the squash left `package.json` and `plugin-sdk-version.ts` alone. Main now ships #7955's SDK additions (`experimental_useThread`, `ExperimentalThreadState`, `ExperimentalThread`, the segment `toggleRef`/`collapseRef`, and the `renderSlot({ threads })` harness support) under the same 0.6.189 that #7107 already used, so one version number names two different SDK surfaces. ## What changed - `node scripts/bump-plugin-sdk.mjs 0.6.190`: `packages/plugin-sdk/package.json` and `packages/domain/src/plugin-sdk-version.ts`. - `docs/api_to_audit.md`: the two lines #7955 added that name its required version ("Requires SDK 0.6.189" under `experimental_useThread`, and the `toggleRef`/`collapseRef` note under thread context segments) now say 0.6.190. The other 0.6.189 reference, `plugins/storage-retention`'s `bbPluginSdk: ">=0.6.189"`, belongs to #7107 and stays. ## How you verified - `node .github/workflows/check-plugin-sdk-version.mjs` and `node .github/workflows/check-version-lockstep.mjs` pass locally. - `pnpm exec turbo run typecheck test --filter=@bb/domain --filter=@get-bb/plugin-sdk` passes. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 25, 2026
…ver (#8087) ## Human comments ## What was wrong Every surface that hosts thread actions built its own `PluginThreadActionTarget`, and they disagreed on `environment`. The thread header (`ThreadDetailView`) passed it only when a new thread could reuse it: environment `ready`, host active, path set. The sidebar, mobile recents, thread-list and Conductor passed any environment the thread had. So one action saw different targets in different menus. Live on main at phone width, for a thread whose worktree is still running its setup script (`provisioning`, path set), the header menu has no "New thread in environment" while the same thread's sidebar long-press menu offers it. thread-list (`rows/threadActionTarget.ts`) and Conductor (`thread-target.ts`) carried byte-identical copies of the mapper, and so do five community plugins. Separately, a thread action's `useData` received only ids. Git's Commit therefore called `sdk.threads.get` for every open thread, plus one subscription per thread, and fetched again on each environment change and reconnect, only to learn the environment the target already carried (audit a-thread F8b and F18's git item). ## What changed **One resolver, on `experimental_useThread`'s path.** `apps/app/src/lib/thread-actions/thread-action-target.tsx` builds the target on #7955's thread-by-id resolution in `thread-state.ts`, not on a store of its own: - `thread-state.ts` now has one `readThread` resolution, used by both `useThreadState` and a new non-hook `threadReadSource`. It reads the held sidebar entry, otherwise the thread query, and keeps the last entry while a thread leaves the sidebar. - The target is that thread plus its environment's path. A held entry carries the path itself; a fetched thread reads the environment query. - For ids the sidebar doesn't hold, `ThreadActionCollectors` mounts a loader that calls `useThreadState` and `useEnvironment`. Those are the same queries the thread page uses, so the open thread adds no request. - Sidebar rows mount no query observers. There are no module-level caches; value-stable targets live in each snapshot source's closure. The registry evaluates `item`, `experimental_bulkItem` and `useData` from that single resolution, so every surface gets the same target: the header, row menus and quick actions, the long-press drawer, selection menus, the pin/read/archive palette commands, mobile recents, and plugin lists. **SDK (0.6.202)** - `PluginThreadActionDataInput.experimental_threads: readonly PluginThreadActionTarget[]`: the targets for `threadIds`, in the same order, leaving out threads not loaded yet. - `experimental_useThreadActions(thread: { id: string }, options?)`, `PluginThreadActionsMenuBaseProps.thread: { id: string }`, and `experimental_bulkThreads?: readonly { id: string }[]`: bb reads only `id`. Existing callers that pass hand-built targets or `PluginSidebarThread`s still type-check. - `PluginThreadActionTarget.environment` now means "the thread's environment" on every surface: `{ id, path, status, hostLifecycle }`, with `path` null while there is no checkout, or null when the thread has none or bb cannot read it. The JSDoc said "when a new thread can reuse it" but held something else on the sidebar. - The SDK test fake's `TestThreadActionsResolver` and `TestThreadBulkActionsResolver` now receive the `{ id }` the plugin passed. **Callers** - Core: `ThreadDetailView` (header, header menu, `PaneThreadActionCommandHandler`) and `RootComposeMobileRecents` pass the thread they hold. `toThreadActionTarget` and `threadListEntryActionTarget` are deleted. - thread-list: `ThreadRow` and the selection store pass `SidebarThread`s. `rows/threadActionTarget.ts` is deleted. - Conductor: `WorkspaceTabs` and `WorkspaceSidebar` pass the thread. `thread-target.ts` is deleted. - Git's Commit `useData` reads `experimental_threads[].environment` and no longer calls `threads.get` or subscribes per thread. - The engine floors for git, thread-list and conductor are now `>=0.6.202`. **Visible changes.** One rule now decides where "New thread in environment" shows: the environment has a checkout, is ready or still provisioning, and its machine is active. Core's action reads it from the target, and the thread page's own button uses the same condition. - Compact header menu: now offers it while the environment provisions, as the sidebar row already did. The new thread is created in that environment and waits on "Preparing workspace". - Sidebar long-press, mobile recents and header: no longer offer it when setup failed or the machine is being removed or gone. Before, the sidebar offered it there, and it ended in "Failed to create thread / Workspace setup failed." or "Machine removal has begun; wait for a replacement machine". - Thread page composer button: now also shows while the environment provisions (it required "ready"). To give every surface that state without extra requests, `PluginThreadActionTarget.environment` gains `status` and `hostLifecycle`. Sidebar entries get them from the server: `ThreadListEntry` gains `environmentStatus` and `environmentHostLifecycle`, joined from the environment and its host in the thread list query. An environment `status-changed` event (host lifecycle changes also send it) now refreshes the sidebar threads in that environment. A thread outside the sidebar reads them from the environment query, as before. Git's Commit is not visible in any of these states. Its status RPC answers "Workspace is still starting.", "Workspace setup failed." or "Workspace status unavailable.", so the action hides from its own data. **Docs** - `docs/api_to_audit.md`: a "One target" paragraph naming the core callers, `experimental_threads`, and an updated audit item 1. - Plugin Guide: `PluginThreadActionDataInput.experimental_threads` in `surfaces.ts`. - bb-plugin-authoring: `frontend-registration.md` and `frontend-sidebar-navigation.md` say to pass the thread and read `experimental_threads`. **Community callers (not edited).** All still compile. Their mappers are now unnecessary, and their thread actions see the host-resolved target: - nosenss/bb-plugin-attention-sidebar (`components/thread-row.tsx` `toActionTarget`) - grishaster80/bb-plugin-focus-sidebar (`app.tsx` `actionTarget`) - nikushiks/bb-plugin-top-tabs - tobi/bb-bots-sidebar (`lib/thread-action-target.ts`) - OXI-717/oxi-thread-list (`rows/threadActionTarget.ts` and its selection store). Its `ThreadRow.test` resolver reads target fields from the object it passes, so it needs a lookup by id once it moves to SDK 0.6.202. - `useData` users notpritam/bb-plugin-inbox, yusuf8834/bb-git-history and jgnagy/bb-plugin-madmax are unaffected (the field is additive). ## How you verified **Live repro, `pnpm start:worktree`.** The fixture is a git project whose `.bb-env-setup.sh` sleeps, which keeps a worktree environment `provisioning` with its path set. - Main, 390×844 touch: the header menu for that thread lists Copy link, Pin, … with no "New thread in environment". The sidebar row's long-press menu for the same thread lists Copy link, **New thread in environment**, Pin, …. - Branch: both menus list "New thread in environment" while the environment provisions and for a ready checkout. For a failed setup, neither menu lists it. After killing a provisioning thread's setup script, the already-open mobile recents row's long-press menu dropped it without a reload. - Creating a worktree thread: the environment `status-changed` events arrived in the same batch as `metadata-changed` events, which already refresh the sidebar, so the new refresh added no `sidebar-bootstrap` fetch of its own. - Branch, desktop: the right-click row menu is unchanged. A shift-click selection gives "Actions for 3 threads" with Pin, Mark unread, Notifications, Move to section, Archive 3 threads, Delete 3 threads, Clear selection. Commit appears in the header for a dirty workspace with `showCommitButton` on. **Git requests.** Script: open a thread, then click 5 more sidebar rows, and attribute each `GET /api/v1/threads/:id` by its request initiator stack. - Main: 6 such GETs, all from the `bb--git` bundle (one per opened thread). - Branch: 0, both with `showCommitButton` off and on. Total API requests for the walk fell from 152 to 141. **Sidebar render cost.** `sidebar.bench.test.tsx` with 3000 threads and the real thread-list plugin, alternating main and branch under `taskpolicy -a`. - Quietest pair (host load average about 32): mount 571 ms main vs 479 ms branch; status patch 37 vs 34 ms; pin 62 vs 59 ms. - Query observers: 15 on both (0.19 per row), so sidebar rows mount no loaders. **Tests** - `ThreadActionsMenu.test.tsx` "thread action target": every menu surface (desktop dropdown, desktop context menu, compact drawer, compact long press), header entries, a two-thread selection and both placements' `useData` receive the same target, resolved from an id. A thread outside the sidebar resolves through the thread and environment queries. - `ThreadActionsMenu.test.tsx` on both compact surfaces: New thread in environment shows for ready and provisioning environments on an active machine, and hides for failed setup and for machines being removed or gone. - `thread-runtime-display.test.ts`: list entries carry the environment's status and the host's lifecycle, and follow both when they change. - `realtime-cache-effects.test.ts`: an environment `status-changed` event invalidates the sidebar when it holds a thread in that environment. - `ThreadDetailView.contract.test.tsx`: header actions get the thread's environment while it provisions. On main that target's `environment` is null, so the test fails there. - `commit-action.test.tsx`: Commit appears from `experimental_threads`, with `threads.get` rejecting and never called. - Existing app tests now hold threads in the sidebar store through `holdSidebarThreads` (active threads in navigation, archived ones in the archive list), as the app does. **Commands** - `pnpm exec turbo run typecheck lint --filter=@bb/app --filter=@get-bb/plugin-sdk --filter=bb-plugin-bb--git --filter=bb-plugin-thread-list --filter=bb-plugin-conductor --filter=bb-plugin-push-notifications --filter=bb-plugin-plugin-api-docs --filter=bb-plugin-bb-guide`: green. - `turbo run test`: green for the same packages. - plugin-sdk passed 448/448 when run alone. Its two timeouts (shared-declaration-emit, kill-processes) and one plugin-api-docs timeout (mobile-guide) happened only while other suites ran in parallel. - `@bb/app` passed 7453 tests with 3 failures, in composer-contract, PromptBoxInternal and exclusive-pick-first-paint. All 313 tests in those files pass when the three run alone. - `ThreadDetailSecondaryContent.test.tsx` fails 7/8 when run directly with `npx vitest` on both this branch and origin/main, and passes under turbo. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Core's parent-thread segment was built on private plumbing that plugins can't use. It read its parent through a banner-only React context (
CoreThreadContext, filled byThreadScreen→ThreadDetailPromptArea). Its focus handoff between the summary toggle and the details collapse row came from the banner's ownuseDisclosureFocusHandoff. A plugin segment gets neither.Plugins that need one thread run
threads.find((t) => t.id === id)overexperimental_useSidebarThreads(), which re-renders on every list change and misses archived and unloaded threads, or write their ownthreads.getfetch. The bundled Git segment wrote its own handoff with a module-level map. That handoff never fired on keyboard expand:ChangedFilesSegmentViewgives every non-summary part the "collapse" target, so theactionmount's effect ran first, consumed the pending focus, and focused its null ref. Separately, with an archived parent the segment rendered the placeholderParent thr_xxxxfor a frame before hiding (2 of 3 cold loads on main).What changed
experimental_useThread(threadId): ExperimentalThreadState(@get-bb/plugin-sdk/app). The state is{ status: "loading" | "notFound" | "error", thread: null }or{ status: "ready", thread: ExperimentalThread }. A thread the sidebar's per-thread entry store holds is ready at once with no request and re-renders the component only when that thread changes. Any other thread (archived, unloaded, before the sidebar's first load) is read through the same thread queryuseSdk().threads.getserves, then kept current by realtime. A 404 (unknown, deleted, or in a deleted project) isnotFound, including for a thread deleted while watched, whose query still holds the earlier data; so is any data carryingdeletedAt. Other failures areerror. A thread that leaves the sidebar while watched (archived) staysreadywith its last sidebar value until the fetch answers, with noloadingin between. An empty id isnotFoundwith no request.ExperimentalThreadis the domainThreadWithRuntime: whatthreads.getreturns minus the five fields only that request computes (activeBackgroundAgentCount,canRestoreEnvironment,canEditMessages,canSpawnChild,queuedMessageCount). Both sources are projected onto exactly those fields, so a held and a fetched thread have the same shape. This follows the siblingthreads.getrather thanPluginSidebarThread: it carriesdeletedAtand none of the row-only fields (indicator,activity). Returning the fullthreads.gettype would have meant inventing the five request-only values for held threads or fetching every thread. The status union followsexperimental_useSidebarThreads'status, withnotFoundsplit out oferror.toggleRef/collapseRef: RefCallback<HTMLElement>onExperimentalThreadContextSegmentProps. Both banners getisExpanded,onToggleand the refs from oneuseThreadContextSegmentDisclosure(PluginThreadContextSegments.tsx). WhenonToggleruns while focus is on one control, the host focuses the other after the commit. Focus anywhere else (composer, another segment) stays put, and a segment that attaches neither ref behaves as before. The type isRefCallback<HTMLElement>, not the design'sRef<HTMLElement>: aRefObject<HTMLElement>member would not type-check on<button ref>.useParentThreadSection(threadId)callsuseThreadState, the implementation behindexperimental_useThread, for the current thread and its parent or fork source, with no fetch or fallback of its own. It renders nothing until the related thread is known (no placeholder). It feeds the parent segment (summary, details,useVisible, and the read-only banner) and the context card's parent row.CoreThreadContext, thecorebanner prop and theparentThreadSectionprop chain are deleted. The parent segment attachestoggleRef/collapseRefand has no focus code.useFocusHandoff/pendingFocus. The shared-ui disclosurebuttonRef/collapseRefprops widen fromRefObjecttoRef(registry item regenerated).docs/api_to_audit.md(newexperimental_useThreadentry; the context-segment entry describes the refs and core callers), Plugin GuideapiSymbols, and bb-plugin-authoringfrontend-registration.md,frontend-thread-list.mdandfrontend-thread-context-card.md, and the plugin testing harness (renderSlot({ threads })). Plugin SDK 0.6.188.experimental_threadHref(threadId, { experimental_messageSeq }), so it waits until both land.Community callers that can migrate (not edited):
experimental_useThread: work-map (app.tsx:829,875,886,1395), attention-sidebar (lib/model.ts:150), and the other ~50threads.findsites from the audit.statusbar/StatusBar.tsx:146hand-rolls the collapse→toggle handoff).How you verified
Kill-tests, run live (
pnpm start:worktree, headless Chrome, a fixture project with a child thread, its parent and uncommitted changes):detailsfound that 12 keep focus on their expand button (none has a collapse control insidedetails). The design's "6 community segments lose focus" premise doesn't hold, so the refs' callers are core's parent segment, Git and flexible-worktrees. cache-watch can drop focus when its own button unmounts on collapse, which refs don't address.onToggle) leaves the composer focused, for parent, Git and the fixture.experimental_useThread+0 renders,threads.find+2 (React batched two of the updates). Renaming the watched thread → +1 with the new title.Tests (fail before, pass after):
ThreadPromptContextBanner.segments.test.tsx: one focus-handoff case table run against core's parent (writable and read-only), Git and a plugin segment with refs, plus no-refs and focus-elsewhere cases. With main's Git segment code the Git row fails.thread-state.test.tsx: a held thread is read with no request and re-renders only for itself against a whole-list subscriber (reading the whole list instead fails it); a fetched thread has a held one's exact shape; 404 isnotFound, 500 iserror; a fetched thread deleted while watched and data carryingdeletedAtarenotFound; a thread leaving the sidebar never reportsloadingbefore its fetch answers; an empty id makes no request. The last three fail on the hook's first version.ThreadPromptContextBanner.test.tsx: no placeholder while a parent missing from the store loads, hidden once it reads as archived; an archived thread's parent read through the fallback.pnpm exec turbo run typecheck lint lint:type-aware testfor@bb/app,bb-plugin-bb--git,@get-bb/plugin-sdk,@bb/shared-ui,@bb/plugin-registry,bb-plugin-plugin-api-docs,bb-plugin-bb-guide,@bb/domain: all green (@bb/app7343 passed), plus@bb/server'sshipped-skills-quality.test.ts.🤖 Generated with Claude Code