New skill to help manage forks where you contribute PRs but also use improvements before they're merged upstream. Features: - Track open PRs and their branch status - Sync main with upstream - Rebase PR branches on upstream/main - Build production branch with all pending PRs merged - Generate status reports Useful for maintaining forks of actively developed projects.
5.8 KiB
5.8 KiB
| name | description | metadata | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| fork-manager | Manage forks with open PRs - sync upstream, rebase branches, track PR status, and maintain production branches with pending contributions. |
|
Fork Manager Skill
Skill para gerenciar forks de repositórios onde você contribui com PRs mas também usa as melhorias antes de serem mergeadas no upstream.
Quando usar
- Usuário pede para atualizar/sincronizar um fork
- Usuário quer saber status dos PRs abertos
- Usuário quer fazer rebase das branches de PR
- Usuário quer criar uma branch de produção com todos os PRs
Configuração
Configs ficam em ~/.clawdbot/fork-manager/<repo-name>.json:
{
"repo": "owner/repo",
"fork": "your-user/repo",
"localPath": "/path/to/local/clone",
"mainBranch": "main",
"productionBranch": "main-with-all-prs",
"upstreamRemote": "upstream",
"originRemote": "origin",
"openPRs": [123, 456],
"prBranches": {
"123": "fix/issue-123",
"456": "feat/feature-456"
},
"lastSync": "2026-01-28T12:00:00Z"
}
Fluxo de Análise
1. Carregar config
CONFIG_DIR=~/.clawdbot/fork-manager
cat "$CONFIG_DIR/<repo>.json"
2. Navegar para o repositório
cd <localPath>
3. Fetch de ambos remotes
git fetch <upstreamRemote>
git fetch <originRemote>
4. Analisar estado do main
# Commits que upstream tem e origin/main não tem
git log --oneline <originRemote>/<mainBranch>..<upstreamRemote>/<mainBranch>
# Contar commits atrás
git rev-list --count <originRemote>/<mainBranch>..<upstreamRemote>/<mainBranch>
5. Verificar PRs abertos via GitHub CLI
# Listar PRs abertos do usuário
gh pr list --state open --author @me --json number,title,headRefName,state
# Verificar status de um PR específico
gh pr view <number> --json state,mergedAt,closedAt,title
6. Classificar cada PR
Para cada PR no config, verificar:
| Estado | Condição | Ação |
|---|---|---|
| open | PR aberto no GitHub | Manter, verificar se precisa rebase |
| merged | PR foi mergeado | Remover do config, deletar branch local |
| closed | PR fechado sem merge | Verificar motivo, possivelmente remover |
| conflict | Branch tem conflitos com upstream | Precisa rebase manual |
| outdated | Branch está atrás do upstream | Precisa rebase |
Comando para verificar se branch precisa rebase:
git log --oneline <upstreamRemote>/<mainBranch>..<originRemote>/<branch> | wc -l # commits à frente
git log --oneline <originRemote>/<branch>..<upstreamRemote>/<mainBranch> | wc -l # commits atrás
Comandos do Agente
status - Verificar estado atual
- Carregar config
- Fetch remotes
- Contar commits atrás do upstream
- Listar PRs e seus estados
- Reportar ao usuário
sync - Sincronizar main com upstream
cd <localPath>
git fetch <upstreamRemote>
git checkout <mainBranch>
git merge <upstreamRemote>/<mainBranch>
git push <originRemote> <mainBranch>
rebase <branch> - Rebase de uma branch específica
git checkout <branch>
git fetch <upstreamRemote>
git rebase <upstreamRemote>/<mainBranch>
# Se conflito: resolver e git rebase --continue
git push <originRemote> <branch> --force-with-lease
rebase-all - Rebase de todas as branches de PR
Para cada branch em prBranches:
- Checkout da branch
- Rebase no upstream/main
- Push com --force-with-lease
- Reportar sucesso/falha
update-config - Atualizar config com PRs atuais
# Buscar PRs abertos
gh pr list --state open --author @me --repo <repo> --json number,headRefName
# Atualizar o arquivo JSON com os PRs atuais
build-production - Criar branch de produção com todos os PRs
cd <localPath>
git fetch <upstreamRemote>
git fetch <originRemote>
# Deletar branch antiga se existir
git branch -D <productionBranch> 2>/dev/null || true
# Criar nova branch a partir do upstream
git checkout -b <productionBranch> <upstreamRemote>/<mainBranch>
# Mergear cada PR branch
for branch in <prBranches>; do
git merge <originRemote>/$branch -m "Merge PR #<number>: <title>"
# Se conflito, resolver
done
# Push
git push <originRemote> <productionBranch> --force
# Build
bun run build
full-sync - Sincronização completa
sync- Atualizar mainupdate-config- Atualizar lista de PRsrebase-all- Rebase de todas as branchesbuild-production- Recriar branch de produçãobun run build- Rebuild
Relatório para o Usuário
Após qualquer operação, gerar relatório:
## 🍴 Fork Status: <repo>
### Upstream Sync
- **Main branch:** X commits behind upstream
- **Last sync:** <date>
### Open PRs (Y total)
| # | Branch | Status | Action Needed |
|---|--------|--------|---------------|
| 123 | fix/issue-123 | ✅ Up to date | None |
| 456 | feat/feature | ⚠️ Needs rebase | Run rebase |
| 789 | fix/bug | ❌ Has conflicts | Manual resolution |
### Production Branch
- **Branch:** main-with-all-prs
- **Contains:** PRs #123, #456, #789
- **Status:** ✅ Up to date / ⚠️ Needs rebuild
### Recommended Actions
1. ...
2. ...
Notas Importantes
- Sempre usar
--force-with-leaseem vez de--forcepara push - Sempre fazer backup antes de operações destrutivas
- Usar
bun runem vez denpm run - Verificar se há trabalho não commitado antes de operações git
- Manter o config atualizado após cada operação
Exemplo de Uso
Usuário: "atualiza meu fork do claude-mem"
Agente:
- Lê config de
~/.clawdbot/fork-manager/claude-mem.json - Executa
statuspara entender situação atual - Se main está atrás, executa
sync - Se PRs precisam rebase, executa
rebase-all - Atualiza
productionBranchse necessário - Executa
bun run build - Reporta resultado ao usuário