# Agent — Rebase-snapshot (fix snapshot conflicts)

Read `_shared.md` first.

## Goal

Resync `ModelSnapshot.cs` after a `git rebase` pulled in changes that
conflict with the local branch's snapshot. The CLI re-uses the squash
mechanics to re-anchor the snapshot on the base ref, delete branch-only
migrations, then regenerate a single consolidated migration on top.

## When to use this

- `git rebase develop` emitted merge conflicts on `ModelSnapshot.cs`.
- Snapshot shows surprising schema after a pull — the model no longer
  matches any migration.
- Squash would work but the branch has already been rebased.

Unlike `squash` (which needs ≥2 branch-only migrations to do anything), this
operation acts on **a single** branch-only migration and, when there are
**zero**, still re-anchors `ModelSnapshot.cs` on the reference branch — because
repairing the snapshot is the whole point.

After a clean rebase you are not *behind* the reference, so the behind-base
guard won't trigger. If you intentionally rebased onto an older base, pass
`"allowBehindBase": true`.

## Steps

1. Abort or resolve the rebase *except* for the snapshot file. Leave the
   snapshot in its conflicted state — the CLI will reset it.

2. Dry-run:

   ```bash
   npx --prefer-offline tsx skills/efcore/cli/rebase-snapshot/index.ts --spec '{
     "cwd": "<WORKTREE>",
     "contextName": "CoreDbContext",
     "description": "FeatureOnRebased",
     "dryRun": true
   }'
   ```

3. Review: what gets deleted, which snapshot gets reset, new migration
   name. Confirm with the user.

4. Run for real. The CLI performs exactly the squash workflow but intent
   is post-rebase recovery.

5. `dotnet build` to verify. If it fails, check:
   - The DbContext file — did the rebase leave stale entities?
   - The Migrations folder — any stragglers still around?

## What NOT to do

- Do not run this without first finishing (or aborting) the rebase.
- Do not run it while there are uncommitted non-snapshot changes in the
  migrations folder — they will be caught in the backup but it muddies
  recovery.
