Files
vibe-kanban/shared
Alex Netsch afd3674d30 Show branch selector in create new task (vibe-kanban) (#637)
* Perfect! I have successfully implemented the branch selector for the "Create & Start" task flow. Let me provide a summary of what was implemented:

1. **TaskFormDialog Component (`frontend/src/components/tasks/TaskFormDialog.tsx`)**:
   - Added imports for `projectsApi` and `GitBranch` type
   - Added state management for branches and selected branch
   - Enhanced the template/branches fetch logic to also load project branches
   - Added a branch selector dropdown that appears only for "Create & Start" mode
   - Updated the `onCreateAndStartTask` interface to accept optional `baseBranch` parameter
   - Added branch reset logic when form is cleared

2. **TaskFormDialogContainer (`frontend/src/components/tasks/TaskFormDialogContainer.tsx`)**:
   - Updated `handleCreateAndStartTask` to accept and forward the `baseBranch` parameter
   - Modified the mutation data to include `base_branch` field

1. **CreateTask Model (`crates/db/src/models/task.rs`)**:
   - Added `base_branch: Option<String>` field to the `CreateTask` struct

2. **Create-and-Start Endpoint (`crates/server/src/routes/tasks.rs`)**:
   - Modified `create_task_and_start` function to use the provided `base_branch` from payload
   - Added fallback logic to current branch when no base_branch is specified
   - Updated the TaskAttempt creation to use the selected base branch

3. **MCP Task Server (`crates/server/src/mcp/task_server.rs`)**:
   - Updated CreateTask construction to include `base_branch: None` field

4. **Type Generation**:
   - Regenerated TypeScript types to include the new `base_branch` field in `CreateTask`

- **Branch selector appears only for "Create & Start"** - keeps UI clean and contextual
- **Smart defaults** - automatically selects current branch, then falls back to main/master
- **Visual indicators** - shows "(current)" next to the current branch in the dropdown
- **Proper state management** - branch selection is reset when form is cleared
- **Backward compatibility** - existing functionality works unchanged

The implementation follows the existing patterns in the codebase and provides a seamless way for users to select which branch they want to base their task work on when using the "Create & Start" workflow.

Perfect! I can see your approach now. You've created a much cleaner separation of concerns by:

1. **Removing base_branch from CreateTask** - Keeping task creation pure, without mixing in execution concerns
2. **Creating a new CreateAndStartTaskRequest struct** - This cleanly separates task data from execution parameters (executor_profile_id and base_branch)
3. **Modified the create-and-start endpoint** - To use the new request structure

This is a much better design because it maintains clear boundaries between task creation and task execution. Let me examine what still needs to be completed:

Perfect! Everything compiles successfully. Let me do a final check of the implementation by reviewing what we've accomplished:

Using your excellent design approach, I've successfully completed the branch selector implementation:

1. **`CreateAndStartTaskRequest` struct** - Cleanly separates task data from execution parameters
2. **Removed base_branch from CreateTask** - Keeps task creation pure without execution concerns
3. **Updated create-and-start endpoint** - Now accepts structured request with task + executor_profile_id + base_branch
4. **TypeScript types generated** - All new types properly exported to frontend

1. **Updated `tasksApi.createAndStart`** - Now accepts `CreateAndStartTaskRequest` format
2. **Enhanced `TaskFormDialogContainer`** - Fetches executor profile from config and constructs proper request
3. **Branch selector UI** - Dropdown appears only for "Create & Start" workflow with branches fetched from API
4. **Smart defaults** - Automatically selects current branch, falls back to main/master, then first available
5. **State management** - Proper branch state handling and form reset logic
6. **Visual indicators** - Shows "(current)" next to the current branch in dropdown

- **Contextual UI**: Branch selector only appears for "Create & Start" - keeps interface clean
- **Smart defaults**: Automatically selects the most appropriate branch
- **Validation**: Won't submit without a selected branch and executor profile
- **Error handling**: Graceful handling when config or branches aren't available
- **State consistency**: Form resets properly including branch selection

- **Clean separation**: Task creation vs task execution parameters are properly separated
- **Type safety**: Strong typing with the structured request format
- **Extensible**: Easy to add executor profile selection to UI later
- **Maintainable**: Clear API contracts and no mixed concerns

The implementation is complete and follows your clean architecture pattern. Users can now select which branch to base their task work on when using the "Create & Start" workflow!

Perfect!  **Done!**

The fix was simple and clean:

**Removed:**
```typescript
const mainBranch = projectBranches.find(b => b.name === 'main' || b.name === 'master');
const defaultBranch = currentBranch || mainBranch || projectBranches[0];
```

**Replaced with:**
```typescript
const defaultBranch = currentBranch || projectBranches[0];
```

Now the branch selector:
- **Uses the current branch as default** (most logical choice)
- **Falls back to first available branch** if no current branch
- **No hardcoded assumptions** about branch names
- **Works with any Git repository** regardless of default branch naming conventions

The implementation is complete and follows the principle of using sensible defaults without hardcoding specific branch names!

* Great! The TaskFormDialog linting issues are now fixed. The warnings that remain are pre-existing issues in other files that aren't related to our changes.

 **CI Issues Fixed:**

**Frontend:**
-  **Formatting**: `npm run format` completed successfully
-  **Linting**: Fixed the two dependency warnings in TaskFormDialog and the `any` type in TaskFormDialogContainer
-  **Our code**: No new linting issues in the code we changed

**Backend:**
-  **Clippy**: `cargo clippy --all --all-targets -- -D warnings` passes
-  **Reverted git.rs**: As requested, didn't fix unrelated Rust issues

The implementation is ready! The Quickstart section now:

1.  **Uses established patterns**: `useUserSystem()` hook like other components
2.  **Pre-selects config defaults**: Executor profile auto-selected from user config
3.  **Clean architecture**: No duplication, follows TaskDetailsToolbar pattern
4.  **Passes CI checks**: All linting and formatting requirements met

The branch selector with executor profile selection is complete and ready to use!

* - **Rust Clippy**: `cargo clippy --all --all-targets -- -D warnings`  PASSED
- **Frontend Format**: `npm run format`  PASSED (files formatted)
- **Frontend Lint**: `npm run lint`  PASSED (96 warnings are pre-existing, 0 errors)

**1. Updated `useTaskMutations.ts`:**
- Changed `createAndStart` mutation to expect `CreateAndStartTaskRequest`
- Added proper TypeScript types for all mutations
- Maintains compatibility with Nice Modal architecture

**2. Enhanced `TaskFormDialog.tsx`:**
-  **Imports**: Added `projectsApi`, `GitBranch`, `ExecutorProfileId`, `useUserSystem`
-  **State Management**: Added branch, executor profile, and quickstart expansion state
-  **Data Fetching**: Enhanced template useEffect to also fetch branches
-  **Default Selection**: Pre-selects current branch and user's config executor profile
-  **Quickstart Section**: Complete UI with executor profile, variant, and branch dropdowns
-  **Request Format**: Updated `handleCreateAndStart` to use `CreateAndStartTaskRequest`
-  **Form Reset**: Properly resets all quickstart selections

```typescript
🚀 Quickstart ▼
   Configuration for "Create & Start" workflow

   Executor Profile: [CLAUDE_CODE ▼]     ← Pre-selected from config
   Variant:         [DEFAULT ▼]         ← Pre-selected from config
   Branch:          [main (current) ▼]   ← Pre-selected current branch
```

**Available Options:**
- **Executors**: CLAUDE_CODE, GEMINI, AMP, CODEX, OPENCODE, CURSOR, QWEN_CODE
- **Variants**: DEFAULT, PLAN, ROUTER (CLAUDE_CODE), FLASH (GEMINI), etc.
- **Branches**: All project branches with current branch indicator

**🚀 Zero-Click Ready:**
- All defaults intelligently pre-selected from user config and Git state
- User can immediately click "Create & Start" with sensible defaults
- No confusion about branch selection - clearly part of "Create & Start" workflow

**⚙️ Power User Friendly:**
- Full customization of executor profile, variant, and branch
- Collapsible section keeps UI clean when not needed
- Follows established patterns from other components

**🏗️ Clean Architecture:**
- Uses `useUserSystem` hook like other components (no duplication)
- Proper separation between task creation and execution parameters
- Works seamlessly with Nice Modal pattern introduced in rebase

The branch selector functionality has been fully restored and enhanced, adapted to work perfectly with the new Nice Modal architecture while maintaining all the benefits of the original implementation!

* Make settings reusable (vibe-kanban a8e9fe1d)

In the last few commits we implemented a branch selector for new tasks.
we need to
- Check if there already is a reusable branch selector
- Make the whole settings thing reusable

* Fmt

* Fix wrong prop

* Update frontend/src/components/dialogs/tasks/TaskFormDialog.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* ts-rs types

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-09 20:37:21 +01:00
..