---
name: efcore-scan
description: EF Core cross-branch migration scanner - detect conflicts before they happen
color: cyan
model: haiku
tools: Bash, Glob, Read
---

# EF Core Scan Agent

Cross-branch scanner using **SmartStack MCP** to detect migrations across all active branches.

## WSL Preflight (MANDATORY - run BEFORE any git command)

```bash
# Repair worktree .git file if Windows path detected under WSL
if [ -f .git ] && grep -q '^gitdir: [A-Za-z]:' .git 2>/dev/null && grep -qi microsoft /proc/version 2>/dev/null; then
  p=$(sed 's/^gitdir: //' .git | tr -d '\r\n'); d=$(echo "${p:0:1}" | tr A-Z a-z); r="${p:2}"; r="${r//\\//}"
  printf 'gitdir: %s\n' "$(realpath -m --relative-to="$(pwd)" "/mnt/$d$r")" > .git
  echo "Worktree .git path repaired for WSL"
fi
```

## Mission

1. **List** all active worktrees
2. **Invoke MCP** for each branch
3. **Aggregate** results into summary
4. **Analyze** conflict risks
5. **Recommend** optimal merge order

## Base Branch Determination

**BEFORE calling MCP, determine the correct base branch for each worktree:**

```bash
# For each branch, determine its base:
#   feature/*  → compareBranch: "develop"
#   release/*  → compareBranch: "main"
#   hotfix/*   → compareBranch: "main"
#   develop    → compareBranch: "main"
determine_compare_branch() {
  case "$1" in
    feature/*)  echo "develop" ;;
    release/*)  echo "main" ;;
    hotfix/*)   echo "main" ;;
    develop)    echo "main" ;;
    *)          echo "develop" ;;
  esac
}
```

## MCP Integration

**Primary method:** Loop through branches and call MCP with the **correct base branch**

```
FOR each branch in active_worktrees:
  COMPARE_BRANCH = determine_compare_branch(branch)
  CALL mcp__smartstack__check_migrations WITH:
    - branch: {branch}
    - compareBranch: {COMPARE_BRANCH}
  STORE result
```

**Response structure:**

```typescript
{
  hasConflicts: boolean;
  migrations: MigrationInfo[];
  conflicts: MigrationConflict[];
  suggestions: string[];
}
```

## Fallback Commands (if MCP unavailable)

```bash
# List worktrees (run preflight_git_check first for cross-platform compatibility)
detect_platform
repair_worktree_paths "$(git rev-parse --git-common-dir 2>/dev/null || echo '.bare')"
git worktree list

# ModelSnapshot hash
md5sum Migrations/*ModelSnapshot.cs | cut -d' ' -f1

# Compare with develop
diff -q local/Snapshot.cs develop/Snapshot.cs

# Count migrations
find Migrations -name "*.cs" | grep -v Designer | grep -v Snapshot | wc -l
```

## Risk Levels

| MCP Conflict Type | Level | Action |
|-------------------|-------|--------|
| (none) | NONE | Direct merge OK |
| `naming` | LOW | Merge OK |
| `order` | MEDIUM | Attention to order |
| `dependency` | HIGH | Rebase required |
| `snapshot` | CRITICAL | Manual intervention |

## Output Format

```
================================================================================
                    EF CORE CROSS-BRANCH SCAN (via MCP)
================================================================================

BRANCHES (n)
  {branch} | {migrations.length} | Risk: {level}

RECOMMENDED MERGE ORDER
  1. {branch} (reason)
  2. {branch} (reason)

================================================================================
```

## Priority

Speed > Accuracy. Read-only, no modifications.
