Skip to content

Start a new session in the main checkout or a selected/new worktree - #15

Draft
felipeorlando wants to merge 1 commit into
mainfrom
issue-2-worktree-sessions
Draft

felipeorlando wants to merge 1 commit into
mainfrom
issue-2-worktree-sessions

Conversation

@felipeorlando

Copy link
Copy Markdown
Owner

Closes #2

New sessions in a git repo can now start in the main checkout, an existing worktree, or a newly created one.

What the removed history actually said

48403fa made the composer branch picker implicitly create/enter a worktree at <git-common-dir>/monocode-worktrees/<branch> — a hidden folder inside .git/ — every time you picked a branch. The session's cwd moved out from under the user and the provider session was dropped with it. fc8cbb8 (0.1.10) reverted all 274 lines.

The removal was about implicitness and an invisible destination, not about worktrees. This design is explicit, chosen once at session creation, and lands in a visible sibling folder. The lesson carried over: the branch picker must not be the thing that moves a session.

Implementation

Rust — three new commands: git_worktrees (list, main-first), git_worktree_create (new branch + start-from ref), git_worktree_verify. New worktrees go to <repo>-worktrees/<slug> next to the repo — not inside .git/ like the reverted version, and not inside the repo where they would be untracked noise. git worktree add never moves the main checkout's HEAD; the start point is resolved before any directory is created, and specs starting with - are rejected.

TypeScriptsessionCheckout.ts holds pure picker-row and session-binding logic. CheckoutPicker.tsx follows BranchPicker's structure and renders only for empty sessions in a git repo. restoreSessionCheckout was inverted: it used to delete the pin on every restore, and now verifies the worktree and keeps it, falling back to the main checkout only when the tree is really gone — this is what makes sessions durably bound.

Behavior change to an existing control — please review

BranchPicker was receiving cwd (the repo root). A worktree-bound session using it would have switched the main checkout's branch, violating the issue's own constraint. It now receives executionCwd, and onBranchChange no longer unpins the session's worktree.

Verification

  • npm run check:web — exit 0, 128 files / 1343 tests, tsc --noEmit clean
  • cargo fmt --check clean, clippy -D warnings clean, cargo test 217 passed

8 new Rust #[test]s on real temp repos, including one asserting the main checkout keeps its branch and its newer commit after a create from an older ref, and one asserting a rejected name/start point leaves zero registered worktrees. 20 new TS tests.

Not verified / out of scope

  • The running app was never launched — picker layout in the composer toolbar, popover placement and keyboard flow are unexercised. Logic and types are tested; pixels are not.
  • Removing a worktree from the UI (destructive with uncommitted work) and cleaning up a worktree when its session is deleted are deliberately out of scope — worktrees outlive sessions.
  • Prunable (directory-gone) worktrees are filtered out of the picker rather than offered with a repair action.

…tree

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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

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.

Start a new session in the main checkout or a selected/new worktree

1 participant