Skip to content

Show branch/worktree selector immediately for drafts - #158

Merged
soorya-u merged 1 commit into
mainfrom
146-composer-branch-worktree-selector
Aug 6, 2026
Merged

Show branch/worktree selector immediately for drafts#158
soorya-u merged 1 commit into
mainfrom
146-composer-branch-worktree-selector

Conversation

@soorya-u

@soorya-u soorya-u commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Removes the "Branch / worktree" intermediate toggle in the composer — it was a perf-deferral leftover, not a real UX step. For non-git-repo drafts, clicking it silently made the button vanish with nothing to replace it, since the git-status query it gated only resolved after the click.
  • ComposerBranchToolbar now renders immediately for any git-repo subject (draft or committed); the heavier ref-list fetch (listGitRefs/listProjectGitRefs) defers to the branch dropdown's first open instead, uniformly for drafts and committed threads.
  • Freezes a thread's workspace mode (Current checkout / New worktree) the instant it's committed, rather than only once it has a worktree — see docs/adr/0022-thread-workspace-frozen-at-commit-never-shared.md for the rationale, including why reusing a worktree across threads was explicitly rejected (unguarded concurrent-write risk if two threads shared one working directory).
  • Switches branch-checkout-conflict errors (branchAlreadyCheckedOutError) from an inline red-text span to a toast.
  • Adds a Worktree glossary entry to CONTEXT.md.

Frontend-only (apps/web) — no worker/backend changes.

Closes #146.

Test plan

  • bun run check:types (all packages)
  • bun run test:unit — 145 vitest + 119 bun tests pass
  • New component tests for ComposerBranchToolbar (deferred ref fetch, workspace lock, toast-not-inline error) and ComposerLowerChrome (toggle removed, toolbar renders directly)
  • ultracite check clean
  • Manual browser verification not run — change is confined to composer UI wiring with no backend/persistence/cross-process surface, so it wasn't exercised against the full local stack (D1/server/worker/browser)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added branch and workspace controls directly to the composer for Git repositories.
    • Added clearer handling when branch checkout actions cannot be completed.
    • Committed threads now retain their selected workspace and cannot switch workspace modes.
  • Bug Fixes

    • Branch information loads only when the branch menu is opened, improving responsiveness.
    • Checkout and workspace errors are now presented through notifications.
  • Documentation

    • Added terminology and guidance describing project worktrees and workspace behavior.

Removes the "Branch / worktree" intermediate toggle, which was a
perf-deferral leftover, not a real UX step: for non-git-repo drafts,
clicking it just made it vanish with nothing to replace it, since the
git-status query it gated only resolved after the click. The full
branch selector now renders immediately for any git-repo subject, and
the (heavier) ref-list fetch defers to the branch dropdown's first
open instead, uniformly for drafts and committed threads.

Also freezes a thread's workspace mode the instant it's committed
(rather than only once it has a worktree), and switches branch-
checkout-conflict errors from an inline span to a toast. See ADR 0022
for why worktree reuse across threads was rejected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cyrus Ready Ready Preview Aug 6, 2026 11:59am

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The composer now renders Git workspace controls directly for drafts. Branch references load only after menu activation. Committed composers lock workspace selection, and checkout errors use toast notifications. Documentation defines Worktree terminology and the frozen workspace policy.

Changes

Composer workspace flow

Layer / File(s) Summary
Direct Git workspace entry
apps/web/src/components/chat/composer/index.tsx, apps/web/src/components/chat/composer/composer-lower-chrome.tsx, apps/web/src/components/chat/composer/composer-lower-chrome.test.tsx
Draft Git state and obsolete props are removed. Git repositories render ComposerBranchToolbar directly. Tests cover Git and non-Git rendering.
Deferred refs and workspace locking
apps/web/src/components/chat/composer/composer-branch-toolbar.tsx, apps/web/src/components/chat/composer/composer-branch-toolbar.test.tsx
Ref queries activate when branch menus open. Non-draft composers lock workspace selection. Mutation errors display as toasts. Tests cover draft, committed, loading, and conflict behavior.
Workspace terminology and policy
CONTEXT.md, docs/adr/0022-thread-workspace-frozen-at-commit-never-shared.md
The terminology defines Worktree. ADR 0022 records frozen committed-thread workspace selection and isolated worktree creation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Composer
  participant ComposerLowerChrome
  participant ComposerBranchToolbar
  participant GitRefsQuery
  participant BranchMutation
  participant SonnerToast
  Composer->>ComposerLowerChrome: provide draft and Git repository state
  ComposerLowerChrome->>ComposerBranchToolbar: render workspace controls
  ComposerBranchToolbar->>GitRefsQuery: load refs when a branch menu opens
  ComposerBranchToolbar->>BranchMutation: request branch checkout
  BranchMutation-->>ComposerBranchToolbar: return checkout error
  ComposerBranchToolbar->>SonnerToast: display error toast
Loading

Possibly related PRs

  • soorya-u/cyrus#52: Introduced related ComposerBranchToolbar and composer Git/worktree behavior.
  • soorya-u/cyrus#71: Modified local-draft branch/worktree behavior and deferred Git queries.
  • soorya-u/cyrus#73: Modified ComposerBranchToolbar draft handling and deferred branch loading.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes workspace freezing and conflict-error handling, which are not required by issue #146. Separate workspace-freezing and conflict-error handling changes into a different PR, or link issues that define those requirements.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR removes the intermediate toggle and renders the actual branch/worktree options directly for Git repositories, satisfying issue #146.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the immediate branch/worktree selector for drafts, which is a central part of the pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 146-composer-branch-worktree-selector

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@soorya-u
soorya-u merged commit 0964dd7 into main Aug 6, 2026
9 checks passed
@soorya-u
soorya-u deleted the 146-composer-branch-worktree-selector branch August 6, 2026 12:17
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.

New-project 'Branch / Worktree' toggle text is confusing / unnecessary for drafts

1 participant