# /fix — Bug Fix Workflow

Two-mode bug fix workflow: quick in-place fix or full worktree + PR pipeline.

## Usage

```
/fix <description>                    # Quick fix, no branch/PR
/fix <branch-name> <description>      # Full worktree + PR workflow
```

**Examples:**
- `/fix button text is wrong on pricing page` (quick fix)
- `/fix fix-auth token expiry causes logout loop` (full workflow)
- `/fix fix-rtl Arabic layout broken in dashboard sidebar` (full workflow)

## Mode Detection

- If the first argument looks like a branch name (kebab-case, no spaces before second word), use **Full Mode**
- If the entire input is a description (natural language sentence), use **Quick Mode**

---

## Quick Mode (no branch name)

### Steps:
1. **Infrastructure check first** (per CLAUDE.md debugging guidelines):
   ```bash
   docker compose ps                    # Containers healthy?
   npx prisma migrate status            # Pending migrations?
   ```
2. Investigate the issue — use parallel Task agents for multi-file searches
3. Identify root cause
4. Apply the fix
5. Run verification:
   ```bash
   npx tsc --noEmit
   npx next lint
   ```
6. Show the user what changed (git diff)
7. Do NOT commit — let the user decide when to commit

---

## Full Mode (with branch name)

### Steps:
1. **Infrastructure check first**
2. Create worktree:
   ```bash
   git worktree add ../mawidi-<branch-name> -b fix/<branch-name>
   ```
3. Investigate and diagnose the bug in the worktree
4. **Present diagnosis to user** — explain root cause and proposed fix
5. Wait for approval, then implement the fix
6. Write a regression test for the bug
7. Run full verification:
   ```bash
   npx tsc --noEmit
   npx next lint
   npm run test:unit
   ```
8. Commit, push, create PR:
   ```bash
   git add <specific-files>
   git commit -m "fix(<scope>): <description>"
   git push -u origin fix/<branch-name>
   gh pr create --title "fix: <title>" --body "<body>"
   ```
9. Report PR URL to user

## Debugging Protocol (MANDATORY)

Always check in this order:
1. `docker compose ps` — are all containers healthy?
2. `npx prisma migrate status` — any pending migrations?
3. Verify .env vars are loaded in the Docker container
4. Confirm you're editing files on the branch Docker is actually mounting
5. ONLY THEN investigate code-level causes

## Key Rules
- Infrastructure before code — always
- Write regression tests for full-mode fixes
- Follow conventional commits: `fix(<scope>): <description>`
- Use `npx prisma` not global prisma
