Repository navigation
Conversation
The environments-into-plugins migration (#3227) replaced the composer's fixed workspace rows with plugin-provided environment provider rows. The "Existing worktree" row was dropped with them, so `reuse:<id>` values became unreachable from the picker: the ReuseEnvironmentPicker only renders once the selection is already a reuse value, which now only happens when a thread seeds it (the thread "+" button or the workspace header). Reusing an environment from the root composer was impossible. Add the row back as "Reuse existing" rather than "Existing worktree", since environments are no longer worktree-coupled, and select any provider's environment through the existing reuse selection. The label shares its verb with the selected-state pill ("Reuse") and the reuse dropdown's heading ("Reuse an existing environment"), so the three surfaces read as one option. The row sits in its own section below the provider rows and is disabled with "No environments to reuse yet" when the project has nothing to reuse, matching the pre-migration affordance. Verified in the app: with a project that has a live git-worktree environment, the picker offers the row, selecting it reveals the environment dropdown, and submitting creates a thread on the existing environment id rather than provisioning a new one. A project with no environments shows the row disabled with its reason. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The popover primitive defaults to `w-96`, and the environment menu has only ever clamped it: `max-w-80` capped it at 320px, and #3563's switch to `w-80` replaced it with the same 320px. Either way a three-row provider menu rendered as wide as the machine search menu it never shows. Override the primitive's width instead of clamping it, and keep the fixed 320px only for the searchable multi-machine menu, where a content-sized box would resize as the machine list filters. Measured in Ladle: the provider menu drops from 320px to its 208px `min-w-52` floor, the machine-grouped menu is also 208px with host names, status dots and provider rows still on one line each, and the searchable menu stays at 320px. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Enablement was derived from the sidebar thread payload: the row went disabled whenever no thread in the project currently pointed at an environment. That answered the wrong question. It read as empty while the sidebar query was still settling, and it read as empty for a project whose worktrees are all still on disk but whose threads have been archived. Always offer the row. The reuse dropdown behind it already renders "Nothing to reuse yet." for the genuinely empty case, so the empty state keeps a home and the row stops making a claim it cannot support. The list itself is still thread-derived, so an environment whose threads are all archived remains absent from the dropdown. Fixing that needs a project-scoped environments query and is left for separate work. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Selecting the reuse row on a project with nothing to reuse did nothing at all: core resolved a bare `reuse` value back to the project-checkout fallback whenever the option list was empty, so the menu closed and the pill never changed. The rule was invisible while the row was disabled in exactly that case — the disabled row and this fallback were covering for each other, and removing one exposed the other. Let a bare `reuse` stand. The reuse pill appears, the environment picker reads "Pick an environment", its dropdown explains "Nothing to reuse yet.", and submit blocks on "Select an environment." A selection that names a missing environment still falls back, and the loading guard on that path is unchanged. Covers the branch with a test; nothing exercised a bare `reuse` value before. Also drops the `project · reuse unavailable` story. It documented a disabled reuse row that no longer exists, and seeded it with a `host:<id>:local` value that `parseEnvironmentValue` stopped recognising in #3227. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The picker stories drove the machine-grouped menu without `onSelectReuse`, so no fixture rendered the combination the real composer always produces: multiple machines plus a wired reuse row. That left the row's placement below every machine group, its selected state, and its behaviour beside a disabled offline machine without any visual coverage. Add four stories over the existing machine fixtures: the grouped menu with reuse offered, the same menu with a `reuse:<id>` value active, an offline machine whose provider rows stay disabled while reuse stays selectable, and the machine-search variant. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Content sizing was applied only when the machine search input was hidden, so the searching variant kept a fixed `w-80` and still rendered wider than its contents. The search input stretches to whatever width the menu has, so there was no reason to pin it. Drop the conditional and size every variant to content between `min-w-52` and `max-w-80`. Measured across the picker stories the searching menu now settles at 208-309px instead of a flat 320px, and holds its width while results filter because the floor covers the search placeholder. This also matches `ModelReasoningPicker`, which already sizes to content. With the floor now unconditional, the `isLoading` arm that re-applied `min-w-52` was dead; the loading menu still measures 208px without it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The reuse dropdown rendered every option in a plain DropdownMenu with no filter, so a project with many live environments gave a long unsearchable list. Replace it with the cmdk Command the other pickers use, showing a search input once the list reaches seven entries and matching each whitespace-separated term against the environment label, name, branch, path, machine name, and the titles of the threads living in it. Separately, "New thread in environment" seeds `reuse:<id>` directly, but `resolveRootComposeEffectiveEnvironmentValue` only kept such a value when the id appeared in the thread-derived option list. That list is built from the sidebar's non-archived threads, so a seeded environment that no live thread points at was silently replaced by the default provider, and knowing the exact environment id saved no work. Resolve that case through the existing `GET /environments/:id` query instead: the composer looks the seeded id up only when it is absent from the thread-derived list, holds the selection while that lookup is pending, keeps it once the environment comes back, and falls back only when the environment is gone or destroyed. The resolved environment is appended to the picker options so the trigger shows its real label rather than "Pick an environment". No new route, and no lookup at all when the seeded id is already in the list. Adds picker stories for the empty, short, selected, disabled, and searchable states. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ymichael
deleted the
bb/split-composer-reuse-restoration-into-its-own-pr-thr_2iiuw7rwx5
branch
September 19, 2026 03:43
ymichael
added a commit
that referenced
this pull request
Sep 19, 2026
…#3932) ## Human comments ## What was wrong The worktree provider could create a new worktree but could not select an existing one. Attaching a path also needed to distinguish an external worktree from one BB already managed: recreating provider metadata for an existing environment could lose its cleanup identity. Meanwhile, the generic branch picker mixed branch selection with worktree-specific default behavior. ## What changed - Normalize supplied worktree paths and the managed-storage root before matching Git paths. Trailing slashes and symlink aliases resolve correctly while main checkouts and managed worktrees remain excluded from adoption. - Add existing-worktree selection to the worktree plugin. Discover worktrees only when that section is selected, scope results to the project and host, and handle loading, errors, retries, and stale responses. - Make section selection immediate, support searching paths and branches, and keep picker dimensions stable while loading. Rows show the full path with left truncation and a second line for branch or detached status; the selected value shows `parent-dir/dir`. - Look up an existing environment before provider creation. Preserve ownership, resource metadata, merge base, and cleanup identity on reuse, including the late-binding race. External adopted paths remain externally owned; existing managed worktrees retain their cleanup policy. Reject incompatible managed-path ownership. - Keep worktree default-base resolution in the plugin, separate from discovery. Retain explicit local and remote branch choices. The generic branch hook retains its existing return shape; the generic picker uses its label for the heading and its placeholder for an empty selection. - Add the optional provider callback `experimental_existingPath` for reuse before creation, validate its registration, and document it in the Plugin Guide inventory and API audit. Bump the SDK to 0.4.106. There are no server/daemon wire changes. Composer environment reuse restoration landed separately in #3929; this branch is rebased onto that merge. ## How you verified - Path normalization: all three new real-Git host regression tests failed before the fix. After the fix, `pnpm exec turbo run test typecheck --filter=bb-plugin-environment-git-worktree` passed all 95 plugin tests and the plugin typecheck. Coverage includes trailing slashes, symlink aliases, managed-root aliases, and missing/prunable worktrees. `git diff --check` passed. - After rebasing onto #3929: 120 targeted app tests (including composer reuse), all 92 plugin tests, and app/plugin typechecks passed. - Turbo plugin tests: 92 passed, covering discovery, selection/search, stale responses, provider adoption, and cleanup. Re-ran the 21 plugin UI tests after the final path-label changes; passed. - Turbo targeted server tests: 76 passed across provider orchestration, shared workspace paths, path claims, and managed-storage recognition. - Turbo targeted core picker tests: 17 passed. Branch-hook tests also passed during the branch verification. - App and worktree-plugin typechecks passed. `git diff --check` passed. - Ran an isolated `pnpm start:worktree` app and exercised it through the matching BB CLI and browser: adopted and reused an external worktree, reused a managed worktree, compared lifecycle metadata before/after reuse, archived threads and ran cleanup. External files remained; the managed worktree was removed. Verified default creation, foreign-project refusal, ordinary checkout creation, and submitting a thread from the UI. - Browser checks confirmed no proactive worktree discovery, immediate mode checkmarks, search/Enter selection, error recovery, two-line rows, left truncation, and the selected parent/directory label. Desktop picker dimensions stayed 288 × 367 across loading and loaded states. - Verification covered desktop web and one live host; cross-host response races were covered by component tests. Mobile/native and the full repository test suite were not run. > AGENT GENERATED --------- Co-authored-by: Claude Opus 5 (1M context) <[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
The environments-into-plugins migration (#3227) replaced the composer's fixed workspace rows with plugin-provided environment provider rows, and the "Existing worktree" row was dropped along with them.
ReuseEnvironmentPickeronly renders once the selection is already a reuse value, soreuse:<id>became unreachable from the root composer — reuse mode could only be entered when a thread seeded it (the thread "+" button or the workspace header). Choosing an existing environment for a new thread from the root composer was impossible.This PR is the reuse-restoration half of a branch split; the external Git worktree adoption work ships separately.
What changed
App-only, seven files under
apps/app/src, no SDK/server/daemon/wire changes.components/pickers/EnvironmentPicker.tsx— adds an optionalonSelectReuseprop and aReuseEnvironmentOptionrow ("Reuse existing",REUSE_ENVIRONMENT_ICON_NAME) rendered in its ownCommandGroupbelow the provider rows, separated by aCommandSeparator. The row is omitted entirely whenonSelectReuseis not wired, and marked selected while the active value parses astype: "reuse". The label shares its verb with the selected-state pill ("Reuse") and the reuse dropdown heading ("Reuse an existing environment") so the three surfaces read as one option. The row is always offered rather than disabled-when-empty: the reuse dropdown already explains an empty project, and a disabled row is a dead end.components/pickers/EnvironmentPicker.tsx(menu width) — the popover was pinned tow-80for every variant. Every variant now sizes to content betweenmin-w-52andmax-w-80, including the machine-search menu: the search input stretches to whatever width the menu has, so there was no reason to pin it. Measured across the picker stories the searching menu settles at 208–309px instead of a flat 320px, and holds its width while results filter because the floor covers the search placeholder. This matchesModelReasoningPicker, which already sizes to content. With the floor unconditional, theisLoadingarm that re-appliedmin-w-52became dead and was removed.components/promptbox/NewThreadComposer.tsx—handleSelectReusesetsREUSE_VALUE_WITHOUT_ENVIRONMENTthrough the existingchangeEnvironmentpath.components/promptbox/NewThreadPromptBox.tsx— threadsonSelectReusethroughNewThreadEnvironmentConfigtoEnvironmentSlot.views/root-compose-environment-selection.ts—resolveRootComposeEffectiveEnvironmentValueno longer rewrites a pendingreuse(null environment id) selection to the fallback value when the project has nothing to reuse. Selecting "Reuse existing" now holds reuse mode and shows the "Pick an environment" dropdown instead of silently snapping back to the default provider.components/promptbox/NewThreadEnvironmentOptions.stories.tsx— wiresonSelectReuseinto the strip and drops the now-obsolete "reuse unavailable" story row.components/pickers/EnvironmentPicker.stories.tsx— no fixture drove the machine-grouped menu withonSelectReuse, the combination the real composer always produces, so the row's placement below every machine group, its selected state, and its behaviour beside a disabled offline machine had no visual coverage. Adds four stories over the existing machine fixtures: reuse offered, reuse selected, offline machine, and the machine-search variant.Tests:
EnvironmentPicker.test.tsxandRootComposeView.test.ts(see below).components/pickers/ReuseEnvironmentPicker.tsx— the reuse dropdown rendered every option in a plainDropdownMenuwith no filter. Replaced with the cmdkCommandthe other pickers use: a search input appears once the list reaches seven entries, and each whitespace-separated term is matched against the environment label, name, branch, path, machine name, and the titles of the threads living in it.views/root-compose-environment-selection.ts+NewThreadComposer.tsx— "New thread in environment" seedsreuse:<id>directly, but the resolver only kept such a value when the id appeared in the thread-derived option list. That list comes from the sidebar's non-archived threads, so a seeded environment that no live thread points at was silently replaced by the default provider, and knowing the exact id saved no work. The composer now resolves that id through the existingGET /environments/:idquery (no new route), only when it is absent from the thread-derived list: the selection is held while the lookup is pending, kept once the environment returns, and dropped only when it is gone or destroyed. The resolved environment is appended to the picker options so the trigger shows its real label instead of "Pick an environment".components/pickers/ReuseEnvironmentPicker.stories.tsx— new stories for the empty, short, selected, disabled, and searchable states.How you verified
Tests added, all failing before these changes and passing after:
EnvironmentPicker.test.tsx— the row is offered alongside the providers and invokesonSelectReuse; the row reportsaria-current="true"while areuse:<id>value is active; the row is omitted whenonSelectReuseis not supplied.RootComposeView.test.ts—resolveRootComposeEffectiveEnvironmentValueholds"reuse"both with an emptyreuseThreadOptionslist and with one available, rather than falling back. Four more cover the seeded path: a seeded environment absent from the thread-derived list is kept, a pending lookup holds the selection, a missing environment falls back, and a lookup for a different id does not rescue an unrelated reuse value.ReuseEnvironmentPicker.test.ts—filterReuseThreadOptionsreturns everything for a blank query, matches branch/thread-title/machine-name, ignores case, requires every whitespace-separated term to match, and returns nothing when no option matches.Commands run from the worktree:
pnpm exec turbo run typecheck lint --filter=@bb/app— 5/5 tasks successful,Found 191 warnings and 0 errors. Warning count and the per-fileNewThreadComposer.tsxwarning count (4) are identical toorigin/mainwith these files reverted, so no new lint warnings are introduced. Thepreserve-manual-memoizationwarning on that hook is pre-existing (inferredsetCommandState, unrelated to the added dependency).pnpm exec turbo run test --filter=@bb/app -- --run src/components/pickers/EnvironmentPicker.test.tsx src/views/RootComposeView.test.ts src/components/pickers/ReuseEnvironmentPicker.test.ts— 3 files, 110 tests passed.Visual check via Ladle (
promptbox--environment-options--overview) in headless Chrome:Project checkout(current),Worktree, thenReuse existingbelow a separator, witharia-disabled="false"on the reuse row.isLoadingwidth arm removed.Reuse+Pick an environmentrather than reverting to a provider, confirming reuse mode is held before an environment is chosen.Reuse-picker search driven in headless Chrome against its new story: with eight environments the search input appears;
paymentnarrows to the one matching on branch and thread title;build-boxnarrows to the two on that machine;zzzzrenders the "No environments match." empty state. With three environments no search input renders, selecting a row closes the menu, and the empty-options variant shows only "Nothing to reuse yet.".