Pr stack

From rp1-run/rp1 · View interactive version

Pr stack is an AI agent skill from the GitHub repository rp1-run/rp1. Plan and execute splitting a large PR or branch into a reviewable stacked PR sequence.

How to use this skill

Skill file

PR Stack

Plan and execute splitting a large PR, local branch, or remote branch into an ordered stack of smaller reviewable PRs.

Use the pre-resolved projectRoot, kbRoot, workRoot, and codeRoot values from the generated Workflow Bootstrap section. Run all source-control commands from codeRoot, and write workflow artifacts only under workRoot.

Constraint: plan first; create branches/PRs only after explicit user approval.

STATE-MACHINE

stateDiagram-v2
    [*] --> planning
    planning --> executing : approved
    planning --> reporting : plan_only
    executing --> reporting : stack_created
    reporting --> [*] : done

On each phase transition, report via:

rp1 agent-tools emit \
  --workflow pr-stack \
  --type status_change \
  --run-id {RUN_ID} \
  --step {CURRENT_STATE} \
  --data '{"status": "running"}'

Example sequence:

rp1 agent-tools emit --workflow pr-stack --type status_change --run-id {RUN_ID} --name "PR Stack: PR #42" --step planning --data '{"status": "running"}'
rp1 agent-tools emit --workflow pr-stack --type waiting_for_user --run-id {RUN_ID} --step planning --data '{"prompt":"Approve this split plan and allow branch/PR creation?","context":"pr-stack requires explicit approval before creating branches, commits, pushes, or PRs"}'
rp1 agent-tools emit --workflow pr-stack --type status_change --run-id {RUN_ID} --step executing --data '{"status": "running"}'
rp1 agent-tools emit --workflow pr-stack --type status_change --run-id {RUN_ID} --step reporting --data '{"status": "running"}'
rp1 agent-tools emit --workflow pr-stack --type status_change --run-id {RUN_ID} --step reporting --data '{"status": "completed"}'

Governance

Procedure

Emit planning running before command execution.

1. Resolve Repo

  1. Use generated Workflow Bootstrap values. Do not call resolve-args, do not generate a UUID, and do not re-derive directories.
  2. Verify clean workspace with git -C {codeRoot} status.
  3. If dirty: report files and ask whether to continue, stash, or stop. Do not modify.

2. Identify SOURCE

3. Inventory Diff

4. Discover Checks

5. Produce Split Plan

Before any branch or PR creation, produce a user-facing split plan.

The plan is primarily for a human reviewer/maintainer deciding whether to approve execution. Keep it concise, scannable, and decision-oriented. Do not lead with internal workflow IDs, raw SHAs, merge-state dumps, long file lists, or test log excerpts. Put internal metadata in YAML frontmatter and put detailed evidence in a compact appendix only when it helps the user audit the plan.

Required plan format:

---
source: "{SOURCE_URL_OR_REF}"
source_title: "{SOURCE_TITLE_IF_KNOWN}"
source_branch: "{SOURCE_BRANCH_IF_KNOWN}"
source_head_sha: "{SOURCE_HEAD_SHA}"
base_branch: "{BASE_BRANCH}"
base_sha: "{BASE_SHA_IF_KNOWN}"
stack_id: "{STACK_ID}"
max_line_change: {MAX_LINE_CHANGE}
generated_exclusions: []
check_commands:
  - "{CHECK_COMMAND}"
workflow_run_id: "{RUN_ID}"
---

# PR Stack Plan: {human source label}

**Recommendation:** {Ready to execute after approval | Execution blocked until ... | Plan only}

{One short paragraph explaining why this split is the right review shape.}

## Stack At A Glance

| # | PR | Base | Size | What Reviewers Validate |
|---|----|------|------|-------------------------|
| 1 | {title} | `{base}` | {+/- total} | {one concrete review goal} |

## Proposed PRs

### 1. {PR title}

- Branch: `{branch}`
- Intent: {one sentence}
- Changes: {short file-area or commit summary, not a long path dump}
- Validation: `{check command}` plus any PR-specific check
- Size: {added + deleted} counted lines; generated exclusions: {none or named paths}
- Risk: {main risk in one sentence}
- Confidence: {Supported/Provisional/etc.}

## Approval Gate

Approve this split plan and allow branch/PR creation?

## Technical Appendix

- Recovery point: `{source ref}@{source head sha}`
- Reconstruction: {how top-of-stack diff will be compared to source diff}
- Commit groups: {short list only when cherry-pick order matters}
- Blockers: {conflicts, checks, source drift, or none}

Plan content requirements:

Derive STACK_ID as pr-{number} for PR sources, otherwise sanitize the source ref by lowercasing and replacing characters outside [a-z0-9._-] with -.

Write the plan to {workRoot}/pr-stacks/{STACK_ID}-stack-plan.md and register it:

rp1 agent-tools emit \
  --workflow pr-stack \
  --type artifact_registered \
  --run-id {RUN_ID} \
  --step planning \
  --data '{"path": "pr-stacks/{STACK_ID}-stack-plan.md", "feature": "{STACK_ID}", "storageRoot": "work_dir", "format": "markdown"}'

6. Approval Gate

Ask exactly:

Approve this split plan and allow branch/PR creation?

Also emit the waiting gate:

rp1 agent-tools emit \
  --workflow pr-stack \
  --type waiting_for_user \
  --run-id {RUN_ID} \
  --step planning \
  --data '{"prompt":"Approve this split plan and allow branch/PR creation?","context":"pr-stack requires explicit approval before creating branches, commits, pushes, or PRs"}'

If PLAN_ONLY=true, emit reporting running, then reporting completed, and stop after the plan.

Without exact approval, do not create branches, commits, pushes, or PRs. Emit reporting running, then reporting completed, and output the plan path.

7. Execute Stack After Approval

Emit executing running before creating a branch, commit, push, or PR.

## 🥞 Stack map

1. [PR title](TBD)
2. 👉 [Current PR title](TBD) ← you are here
3. [Next PR title](TBD)

8. Cross-Link Pass

9. Final Verification

Emit reporting running after stack creation, then verify:

Append the final report to {workRoot}/pr-stacks/{STACK_ID}-stack-plan.md, then emit reporting completed.

DONT

Output

During plan:

During execution:

Final:

Runtime Contract

{% include_shared "anti-loop.md" %}

File-specific constraints:

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.