Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 36 additions & 192 deletions .claude/skills/restack/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,221 +1,65 @@
# Restack

Use when user asks to "restack", "resolve conflicts", "gt restack", or mentions restack conflicts. Guides through gt restack conflicts with intelligent diagnostics and resolution. (project)
---
name: restack
description: Use when user asks to "restack", "resolve conflicts", "gt restack", or mentions restack conflicts. Guides through gt restack conflicts with intelligent diagnostics and resolution.
allowed-tools: Bash(gt restack:*), Bash(gt continue:*), Bash(git show:*), Bash(git diff:*), Bash(git log:*), Bash(git ls-tree:*), Bash(pnpm install:*), Bash(git status:*), Bash(gt log:*), Bash(rm pnpm-lock.yaml), Bash(gt add -A:*), Bash(git checkout --theirs:*), Bash(git checkout --ours:*)
---

<critical>
- ALWAYS check current state first (supports both: starting fresh or mid-conflict)
- If already in conflict, skip running gt restack and go straight to resolution
- Differentiate simple (lockfile-only) vs complex (multi-file) conflicts
- Analyze embedded state below before acting
- If conflict shown, skip gt restack and route immediately
- Loop until restack completes successfully
- Use AskUserQuestion for confirmations and choices
- Use AskUserQuestion for all confirmations
</critical>

## Workflow
## Current State

### 1. Detect Current State
**Repository status:**
!`git --no-pager -c color.ui=false status`

First, check if restack is already in progress:
**Current stack:**
!`gt --no-color log short --stack`

```bash
git status
```
## Workflow

**Check for**:
- "rebase in progress"
- "You are currently rebasing"
- "Unmerged paths"
- "both modified:" or other conflict indicators
### 1. Analyze State

**Outcomes**:
- Already in conflict (user ran `gt restack` manually) → Skip to step 3 (Gather Diagnostics)
- Clean state → Proceed to step 2 (Run Restack)
Check `git status` output above:
- **"rebase in progress"** or **"Unmerged paths"** → Already in conflict, skip to step 3
- **Clean working tree** → Proceed to step 2

### 2. Run Restack (if not already in progress)
### 2. Run Restack (if clean state)

```bash
gt restack
```

**Outcomes**:
- Success → Acknowledge and exit
- Conflicts → Proceed to step 3

### 3. Gather Diagnostics

When conflicts are detected (either from step 1 or step 2), run:

```bash
# Check which files are conflicted
git status

# Show stack structure (where conflict occurred)
gt log short

# Check for broken lockfile warning
pnpm install --dry-run 2>&1 | grep -i "broken\|duplicated\|ignoring"

# For each conflicted file, show diff
git diff <file>
```

### 3. Explain Conflict Type

**Simple conflict** (lockfile-only):
- Only `pnpm-lock.yaml` in unmerged files
- Explain: Lockfile is generated content, safe to regenerate
- Propose: `pnpm install && gt add -A && gt continue`

**Complex conflict** (multi-file):
- Multiple files in unmerged files
- Explain each file's conflict
- Guide through resolution strategy

### 4. Resolve Based on Type

#### Simple Conflict Resolution

Use AskUserQuestion:
```
question: "Only pnpm-lock.yaml is conflicted. Regenerate and continue?"
header: "Simple Resolution"
options:
- label: "Yes, run one-liner"
description: "pnpm install && gt add -A && gt continue"
- label: "Let me inspect first"
description: "Show git diff pnpm-lock.yaml before proceeding"
```

If confirmed → Execute → Check output of `gt continue`:
- Another conflict → Loop back to step 3 (Gather Diagnostics)
- Success message → Proceed to step 6 (Success & Reminder)
**Outcomes:**
- **Success** → Acknowledge and skip to step 4
- **Conflicts** → Proceed to step 3

#### Complex Conflict Resolution
### 3. Route by Conflict Type

For each non-lockfile conflict:
Analyze conflicted files from status above:

**a) Show the conflict**:
```bash
git diff <file>
```

**b) Explain the conflict** (extract from diff):
- What changed in base (HEAD)
- What changed in branch (incoming)
- Why it conflicts
**Only pnpm-lock.yaml conflicted?**
→ See [lockfile-conflict.md](lockfile-conflict.md)

**c) Ask resolution strategy** using AskUserQuestion:
```
question: "How to resolve <file>?"
header: "Resolution"
options:
- label: "--theirs (main's version)"
description: "Accept base branch - good for style/formatting consistency"
- label: "--ours (branch's version)"
description: "Keep your branch changes - good for features/dependencies"
- label: "Manual edit"
description: "I'll resolve it manually, just continue after I'm done"
- label: "Show original file"
description: "Show git show HEAD:<file> and git show :<stage>:<file> to inspect"
```
**Multiple files conflicted?**
→ See [complex-conflict.md](complex-conflict.md)

**d) Execute choice**:
- `--theirs`: `git checkout --theirs <file>`
- `--ours`: `git checkout --ours <file>`
- Manual: Wait for user confirmation
- Show original: Display and ask again

**e) After all non-lockfile conflicts resolved**:
```bash
pnpm install && gt add -A && gt continue
```
**Unexpected errors or state?**
→ See [troubleshooting.md](troubleshooting.md)

**f) Check output of `gt continue`**:
- Another conflict → Loop back to step 3 (Gather Diagnostics)
- Success message → Proceed to step 6 (Success & Reminder)
### 4. Success

### 5. Handle Broken Lockfile

If diagnostics show "broken lockfile" warning:

Use AskUserQuestion:
```
question: "Lockfile is corrupted. Delete and regenerate?"
header: "Broken Lockfile"
options:
- label: "Yes, delete and regenerate"
description: "rm pnpm-lock.yaml && pnpm install && gt add -A && gt continue"
- label: "Try pnpm install first"
description: "pnpm might auto-fix, try without deleting first"
```

After executing choice, check output of command:
- Another conflict → Loop back to step 3 (Gather Diagnostics)
- Success message → Proceed to step 6 (Success & Reminder)

### 6. Success & Reminder

When `gt restack` completes without conflicts:

```
Restack completed successfully!

Next step: Force push your stack
gt stack submit --force
# Or individual branch:
git push --force-with-lease origin <branch-name>

Note: Always use --force-with-lease for safety
```

## Quick Reference

**Simple lockfile conflict**:
```bash
pnpm install && gt add -A && gt continue
```
**Next step:** Force push your stack

**Multiple files conflicted**:
```bash
git diff <file> # Inspect
git checkout --ours/--theirs <file> # Resolve
pnpm install && gt add -A && gt continue
gt stack submit --force
# Or individual branch:
git push --force-with-lease origin <branch-name>
```

**Broken lockfile**:
```bash
rm pnpm-lock.yaml
pnpm install && gt add -A && gt continue
```

**Cancel restack**:
```bash
gt abort
```

## Resolution Strategy Guide

**When to use `--theirs` (accept main's version)**:
- Style/formatting conflicts (e.g., quoted vs unquoted YAML)
- Configuration files where consistency with main matters
- Files you didn't intentionally change

**When to use `--ours` (keep branch's version)**:
- Your branch added dependencies (e.g., pnpm-workspace.yaml)
- Feature changes you need to preserve
- Files where your changes are the whole point

**Rule of thumb**: When in doubt, choose consistency with main (`--theirs`).

## Troubleshooting

**Problem**: `gt continue` fails with error
**Solution**: Check `git status` for unresolved conflicts or unstaged files

**Problem**: pnpm install shows warnings about bin files
**Solution**: Usually safe to ignore - supabase CLI has known installation quirks

**Problem**: Not sure whether to use --ours or --theirs
**Solution**: Skill will show both versions and explain - use AskUserQuestion to decide

**Problem**: Multiple files conflicted, unclear which to resolve first
**Solution**: Skill resolves non-lockfiles first, then regenerates lockfile last
**Note:** Always use `--force-with-lease` for safety
80 changes: 80 additions & 0 deletions .claude/skills/restack/complex-conflict.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Multi-File Conflict Resolution

Multiple files are conflicted. Resolve non-lockfiles first, then regenerate lockfile.

## Conflicted Files

!`git --no-pager -c color.ui=false diff --name-only --diff-filter=U --no-renames`

## Resolution Strategy

For each non-lockfile conflict:

### 1. Show the conflict

```bash
git --no-pager -c color.ui=false diff <file>
```

### 2. Explain conflict

Extract from diff:
- What changed in base (HEAD)
- What changed in branch (incoming)
- Why it conflicts

### 3. Ask resolution via AskUserQuestion

```
question: "How to resolve <file>?"
header: "Resolution"
options:
- label: "--theirs (main's version)"
description: "Accept base branch - good for style/formatting consistency"
- label: "--ours (branch's version)"
description: "Keep your branch changes - good for features/dependencies"
- label: "Manual edit"
description: "I'll resolve manually, continue after I'm done"
- label: "Show context"
description: "Show git show HEAD:<file> to inspect"
```

### 4. Execute choice

```bash
# --theirs
git checkout --theirs <file>

# --ours
git checkout --ours <file>

# Manual: Wait for user confirmation
```

## After All Non-Lockfiles Resolved

Regenerate lockfile and continue:

```bash
pnpm install && gt add -A && gt continue
```

## Check Result

After `gt continue`:
- **Another conflict** → Loop back (return to SKILL.md routing)
- **Success** → Proceed to success message in SKILL.md

## Resolution Guidelines

**Use `--theirs` (main's version) for:**
- Style/formatting conflicts (e.g., quoted vs unquoted YAML)
- Configuration files where consistency with main matters
- Files you didn't intentionally change

**Use `--ours` (branch's version) for:**
- Your branch added dependencies (e.g., pnpm-workspace.yaml)
- Feature changes you need to preserve
- Files where your changes are the whole point

**Rule of thumb:** When in doubt, choose consistency with main (`--theirs`).
43 changes: 43 additions & 0 deletions .claude/skills/restack/lockfile-conflict.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Lockfile-Only Conflict Resolution

Simple case: Only `pnpm-lock.yaml` is conflicted. Lockfile is generated content, safe to regenerate.

## Resolution

Use AskUserQuestion:

```
question: "Only pnpm-lock.yaml is conflicted. Regenerate and continue?"
header: "Simple Resolution"
options:
- label: "Yes, regenerate"
description: "pnpm install && gt add -A && gt continue"
- label: "Inspect first"
description: "Show git diff pnpm-lock.yaml before proceeding"
```

If confirmed, execute:

```bash
pnpm install && gt add -A && gt continue
```

## Check Result

After `gt continue`:
- **Another conflict** → Return to SKILL.md routing
- **Success** → Proceed to success message in SKILL.md

## Broken Lockfile

If `pnpm install` shows "broken lockfile" warnings, ask:

```
question: "Lockfile corrupted. Delete and regenerate?"
header: "Broken Lockfile"
options:
- label: "Yes, delete"
description: "rm pnpm-lock.yaml && pnpm install && gt add -A && gt continue"
- label: "Try auto-fix"
description: "pnpm install might auto-fix without deleting"
```
Loading