---
name: gitflow
description: GitFlow workflow with versioning, worktrees, and EF Core migration management. Progressive step loading for minimal context usage.
argument-hint: "[-a] [-f|-r|-h] <action> [name]"
---

<objective>
Execute GitFlow workflows with automatic versioning, worktree management, and EF Core migration validation. Uses progressive step loading to minimize context and maintain fresh state at each phase.
</objective>

<quick_start>
**Manual workflow (step-by-step, recommended):**
```bash
/gitflow -f user-auth     # Start feature → STOPS
# ... code ...
/gitflow commit           # Commit → STOPS
/gitflow pr               # Create PR → STOPS (wait review)
/gitflow merge            # Merge → STOPS
/gitflow finish           # Cleanup → DONE
```

**Automatic workflow (all-in-one):**
```bash
/gitflow -a -f my-feature   # Full auto: all steps
/gitflow -a -r 1.20.0       # Full auto: release
```

**Flags:**
- `-a` (auto): **Execute ALL steps automatically** (without = one step then stop)
- `-f` (feature): Feature workflow (target: develop)
- `-r` (release): Release workflow (target: main)
- `-h` (hotfix): Hotfix workflow (target: main)
- `-s` (status): Show status only
</quick_start>

<parameters>

<flags>
**Mode flags (mutually exclusive):**
| Short | Long | Description |
|-------|------|-------------|
| `-f` | `--feature` | Feature workflow (target: develop) |
| `-r` | `--release` | Release workflow (target: main, merge-back develop) |
| `-h` | `--hotfix` | Hotfix workflow (target: main, merge-back develop) |

**Behavior flags:**
| Short | Long | Description |
|-------|------|-------------|
| `-a` | `--auto` | **Full automatic mode**: execute ALL steps without stopping |
| `-s` | `--status` | Status mode: show state only, no actions |
| `-v` | `--verbose` | Verbose output |
| `--dry-run` | | Preview actions without executing |

**⚠️ CRITICAL: Without `-a`, each command executes ONLY its own step then STOPS.**

**Disable flags:**
| Short | Long | Description |
|-------|------|-------------|
| `-A` | `--no-auto` | Disable auto mode |
</flags>

<actions>
**Primary actions:**
| Action | Description | Step |
|--------|-------------|------|
| `init` | Initialize GitFlow config | step-init |
| `start` | Create new branch + worktree | step-start |
| `commit` | Commit with EF Core validation | step-commit |
| `sync` | Sync + rebase with remote | step-sync |
| `plan` | Generate integration plan | step-plan |
| `pr` | Create pull request | step-pr |
| `merge` | Merge PR after review | step-merge |
| `finish` | Finalize (tag + cleanup) | step-finish |

**Standalone phases:**
| Action | Description | Phase |
|--------|-------------|-------|
| `status` | Show complete state | phases/status |
| `abort` | Rollback/recovery | phases/abort |
| `cleanup` | Audit worktrees | phases/cleanup |
</actions>

<examples>
```bash
# ══════════════════════════════════════════════════════════════
# STEP-BY-STEP MODE (default - recommended)
# Each command executes ONE step, then waits for user
# ══════════════════════════════════════════════════════════════

# Feature workflow (manual steps)
/gitflow -f my-feature    # 1. Creates branch → STOPS
# ... user codes ...
/gitflow commit           # 2. Commits changes → STOPS
/gitflow pr               # 3. Creates PR → STOPS (wait for review)
/gitflow merge            # 4. Merges PR → STOPS
/gitflow finish           # 5. Cleanup → DONE

# Release workflow (manual steps)
/gitflow -r 1.20.0        # 1. Creates branch + bump version → STOPS
/gitflow pr               # 2. Creates PR to main → STOPS (wait for review)
/gitflow merge            # 3. Merges PR → STOPS
/gitflow finish           # 4. Tag + merge-back + cleanup → DONE

# ══════════════════════════════════════════════════════════════
# AUTOMATIC MODE (-a flag)
# Executes ALL steps without stopping
# ══════════════════════════════════════════════════════════════

/gitflow -a -f my-feature  # Full auto: branch → commit → pr → merge → finish
/gitflow -a -r 1.20.0      # Full auto: branch → bump → pr → merge → tag → cleanup
/gitflow -a -h fix-bug     # Full auto: hotfix complete cycle

# ══════════════════════════════════════════════════════════════
# UTILITY COMMANDS
# ══════════════════════════════════════════════════════════════

/gitflow status           # Show current state
/gitflow -s               # Shorthand for status
/gitflow abort            # Rollback current operation
/gitflow cleanup          # Audit and remove orphan worktrees
```
</examples>

</parameters>

<workflows>
```
FEATURE WORKFLOW
────────────────
start ──► commit* ──► sync ──► pr ──► merge ──► finish
  │        (loop)      │               │
  └── worktree ────────┴── rebase? ────┴── squash merge

RELEASE WORKFLOW
────────────────
start ──► commit* ──► sync ──► pr ──► merge ──► finish
  │        (loop)             (main)    │        │
  └── worktree ───────────────────────────── merge-back develop
                                              + tag vX.Y.Z

HOTFIX WORKFLOW
───────────────
start ──► commit* ──► sync ──► pr ──► merge ──► finish
  │        (loop)             (main)    │        │
  └── worktree ───────────────────────────── merge-back develop
                                              + tag vX.Y.Z+1
```
</workflows>

<state_variables>
**Persist throughout all steps:**

| Variable | Type | Description |
|----------|------|-------------|
| `{branch_type}` | string | feature, release, hotfix |
| `{branch_name}` | string | Full branch name (e.g., feature/user-auth) |
| `{base_branch}` | string | Target branch (develop or main) |
| `{worktree_path}` | string | Path to worktree directory |
| `{version_current}` | string | Current version (X.Y.Z) |
| `{version_next}` | string | Next version after merge |
| `{auto_mode}` | boolean | Skip confirmations |
| `{has_migrations}` | boolean | EF Core migrations detected |
| `{pr_number}` | number | PR number (after creation) |
| `{git_provider}` | string | github or azuredevops |

</state_variables>

<entry_point>

**ROUTING LOGIC:**

1. Parse flags and action from input
2. Route to appropriate step or phase:

| Input Pattern | Route To |
|---------------|----------|
| `init` | `steps/step-init.md` |
| `start {type} {name}` | `steps/step-start.md` |
| `-f {name}` | `steps/step-start.md` (type=feature) |
| `-r {name}` | `steps/step-start.md` (type=release) |
| `-h {name}` | `steps/step-start.md` (type=hotfix) |
| `commit [msg]` | `steps/step-commit.md` |
| `sync` | `steps/step-sync.md` |
| `plan` | `steps/step-plan.md` |
| `pr` | `steps/step-pr.md` |
| `merge` | `steps/step-merge.md` |
| `finish` | `steps/step-finish.md` |
| `status` or `-s` | `phases/status.md` |
| `abort` | `phases/abort.md` |
| `cleanup` | `phases/cleanup.md` |
| (no action, on feature/*) | `steps/step-commit.md` |

</entry_point>

<step_files>
**Progressive loading - only load current step:**

| Step | File | Purpose |
|------|------|---------|
| init | `steps/step-init.md` | Configure GitFlow, create branches |
| start | `steps/step-start.md` | Create branch + worktree |
| commit | `steps/step-commit.md` | Commit with EF Core validation |
| sync | `steps/step-sync.md` | Push/pull + rebase if behind |
| plan | `steps/step-plan.md` | Generate integration plan |
| pr | `steps/step-pr.md` | Create pull request |
| merge | `steps/step-merge.md` | Review checklist + merge |
| finish | `steps/step-finish.md` | Tag + cleanup + version |

**Standalone phases:**

| Phase | File | Purpose |
|-------|------|---------|
| status | `phases/status.md` | Complete state diagnostic |
| abort | `phases/abort.md` | Rollback and recovery |
| cleanup | `phases/cleanup.md` | Audit and remove orphan worktrees |

</step_files>

<efcore_rules>
**EF Core validation (MANDATORY):**

1. **1 migration per feature** - Recreate, don't accumulate
2. **3 required files** per migration:
   - `{Migration}.cs`
   - `{Migration}.Designer.cs`
   - `{DbContext}ModelSnapshot.cs`
3. **Sync before merge** - Rebase on base branch
4. **ModelSnapshot conflict** - Accept theirs + Regenerate
5. **Release** - Generate idempotent SQL script

**Blocking conditions:**
- Missing migration files → Block commit
- Snapshot divergence → Require `/efcore:rebase-snapshot`
- Destructive changes → Require confirmation
</efcore_rules>

<versioning>
**Source priority:** csproj → Directory.Build.props → VERSION file → git tag

**Auto-increment rules:**
| Branch Type | Version Change | Example |
|-------------|----------------|---------|
| feature | minor | 1.2.0 → 1.3.0 |
| hotfix | patch | 1.2.0 → 1.2.1 |
| release | as specified | 1.2.0 → 2.0.0 |
</versioning>

<execution_rules>

- **Load one step at a time** - Only load the current step file
- **ULTRA THINK** before each action
- **Persist state variables** across all steps
- **Follow next_step directive** at end of each step
- **NEVER skip EF Core validation** - migrations are critical
- **Safety > Correctness > Speed**

**⚠️ CRITICAL - STEP EXECUTION POLICY:**

| Mode | Behavior |
|------|----------|
| **Without `-a`** | Execute ONLY the requested step, then **STOP and wait for user** |
| **With `-a`** | Execute ALL steps automatically (start → commit → pr → merge → finish) |

**Examples:**
```bash
/gitflow -r 1.20.0      # Creates branch + bump version → STOPS (user runs /gitflow pr next)
/gitflow -r -a 1.20.0   # Full automatic: branch → bump → PR → merge → tag → cleanup
/gitflow -f my-feature  # Creates branch → STOPS (user codes, then runs /gitflow commit)
/gitflow -f -a feature  # Full automatic: branch → commit → PR → merge → finish
```

**NEVER chain steps automatically without `-a` flag. The user decides the pace.**

</execution_rules>

<success_criteria>

- Branch created with worktree (if start)
- All commits validated (EF Core)
- PR created with proper target
- Merge completed with correct strategy
- Tags created for releases/hotfixes
- Worktrees cleaned up after finish
</success_criteria>
