feat(desktop,host-service): add right-click import of untracked worktrees
What
Adds an Import untracked worktrees action to the project right-click menu in the v2 sidebar. It lists every git worktree of the project's repo that has no workspace row and imports them as workspaces via the existing workspaces.create adopt path (no git worktree add).
Clicking the menu item opens a confirmation dialog showing the count and the list (branch + path) of worktrees that will be imported, plus a Run setup script checkbox that defaults to off — imported worktrees are usually already set up.
How
- host-service
workspaceCreation.listProjectWorktrees: entries now carryhasWorkspace(workspace row matches by branch — the canonical tracking key — or by realpath-normalized path, catching rows whose branch was renamed) andisMainWorktree(never offer the main repo checkout). Additive, so the v1→v2 importer callers are unaffected. - host-service
workspaces.create: new optionalrunSetupinput;falseskips the setup terminal. All existing callers omit it, so behavior is unchanged for them. Old hosts strip the unknown key and keep today's behavior. - desktop: new
ImportWorktreesDialog(borderless rows matching the V1 ImportRow pattern, truncation withtitletooltips,max-h-64scroll withoverscroll-contain); the menu action fetches the untracked list and opens it; confirm submits each viauseWorkspaceCreates().submitwithrunSetup, so optimistic sidebar rows, pane layout, and failure cleanup are handled by the existing pipeline. Re-running when everything is tracked toasts instead of opening the dialog; adoption is idempotent server-side.
Verification
CDP-driven end-to-end against the dev app from this branch (instance ownership + session verified):
- Right-click → menu item → dialog with correct count/list; long branch names truncate; 8-row list scrolls.
- Confirm with checkbox off: workspaces created for exactly the untracked worktrees (main repo excluded), and a sentinel-writing
.superset/setup.shdid not run. - Confirm with checkbox on: sentinel files written in each imported workspace — setup ran.
- Re-run: "All of this project's worktrees are already tracked" toast, no new rows.
bun run lint, monorepo typecheck, and host-service workspace-creation/workspaces suites (incl. the main-loop-blocking ratchet) all green.
Summary by cubic
Add a right-click “Import untracked worktrees” action in the v2 desktop sidebar to adopt existing git worktrees as workspaces, with an optional setup step. This avoids creating new worktrees and makes adoption quick and safe.
- New Features
desktop: Project context menu gains “Import untracked worktrees,” opening a dialog that lists each untracked worktree (branch + path) and a “Run setup script” checkbox (off by default). If none are untracked, a toast is shown; otherwise, each is created via the existing create flow with optimistic UI; main checkout is excluded.host-service:workspaceCreation.listProjectWorktreesnow includeshasWorkspace(matched by branch or normalized path) andisMainWorktreeto support filtering.host-service:workspaces.createaccepts optionalrunSetup; whenfalse, the setup terminal is skipped. Existing callers are unchanged; older hosts ignore unknown input.
Summary by CodeRabbit
- New Features
- Added support for importing untracked worktrees directly from the project sidebar.
- Review available branches and paths before importing them as workspaces.
- Optionally run setup scripts during import.
- Import actions are available in both expanded and collapsed project menus.
- Bug Fixes
- Improved worktree detection to distinguish existing workspaces from the main repository and avoid duplicate imports.