Auto task.restack

From gpsaggese/helpers · View interactive version

Auto task.restack is an AI agent skill from the GitHub repository gpsaggese/helpers. Propagate reviewed changes down an existing PR stack, keeping every PR mergeable

How to use this skill

Skill file

Goal

changes reviewed in an earlier PR into every PR stacked on top of it

When to Use This Skill

and the branches stacked on top of it need those changes

/auto_task.execute_with_stacked_prs instead

Before Executing an Unclear Plan" when a PR's description is unclear. Do not

guess and merge blind

Workflow

Discover the Full Stack

```bash

> gh pr view --json number,title,baseRefName,headRefName,url

```

(gh pr list --head <base> --state all), until reaching the default branch

(master). This is the bottom of the stack

baseRefName equals the previous PR's headRefName

(gh pr list --base <branch> --state open). This is the top

```bash

> gh pr view <bottom PR> --json mergeable,mergeStateStatus

```

If mergeable is CONFLICTING (or the branch is just behind), treat the

default branch as an implicit PR_0 at the bottom. It needs the same

merge-forward treatment as every other pair

Print the Stack

e.g.:

```

+---+--------------------+-----------------------------------------------+--------+

| # | Branch | PR | Base |

+---+--------------------+-----------------------------------------------+--------+

| 1 | ..._invoke_tasks | #1423 -- auto-pick suffix in git_branch_create | master |

| 2 | ..._invoke_tasks_2 | #1424 -- unit tests for git_/gh_ tasks | #1423 |

+---+--------------------+-----------------------------------------------+--------+

```

Create and Confirm the Propagation Plan

(PR_i, PR_i+1), including (master, PR_1) when the bottom PR is behind the

default branch:

git diff <base_i>...<head_i>

(touched by both)

Propagate Changes Down the Stack

propagated so far. Start with (master, PR_1) when it is in the plan

conflicts by its intent, not blindly

origin/<branch_i+1>. Another process or session can push mid-stack, and

merging on a stale copy silently drops those commits

```bash

> git fetch origin <branch_i> <branch_i+1>

> git checkout <branch_i+1>

> git reset --hard origin/<branch_i+1>

> git merge origin/<branch_i>

```

git rebase or force-push

while resolving conflicts in code and tests

origin/<branch_i+1> moved, re-fetch and redo the merge. Do not force-push

over it

Make Every PR Mergeable

its CI green

```bash

> gh pr view <NUM> --json mergeable,mergeStateStatus

```

Report Only Failures

one comment explaining the problem:

```bash

> gh pr comment <NUM> --body "<what failed and why>"

```

comment

Conventions

CI green

Constraints

only, to preserve review history

concurrent session or auto-commit/auto-push process can move a branch in the

stack while this skill runs

Verification

GitHub's actual base chain, and the bottom PR's mergeability against

master was checked

by the user before any branch was touched

branch was force-pushed

stack

human input

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.