---
name: pr-walkthrough
description: Walk through a PR — generate a hierarchical explanation with Mermaid diagrams covering background, motivation, solution approach, then flag blocking/non-blocking issues. Output a walkthrough document to docs/.
title: pr-walkthrough
canonical_url: https://skilld.dev/gh/mohasarc/mo-skills/pr-walkthrough
last_updated: 2026-09-29T05:57:00.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install mohasarc/mo-skills/pr-walkthrough`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/pr-walkthrough`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/mohasarc/mo-skills/pr-walkthrough) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/pr-walkthrough`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/pr-walkthrough --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/pr-walkthrough --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# PR Walkthrough & Review

Walk through a pull request — explain its background, motivation, and solution with Mermaid diagrams, then identify blocking and non-blocking issues. Output is saved as a `.md` file in `docs/`.

## Useful Commands Reference

These commands are your toolkit for gathering PR context. Use them throughout the steps below.

```bash
# Get PR number for current branch
gh pr view --json number --jq .number

# Get PR metadata (title, body, base branch, author, labels, state)
gh pr view {pr_number} --json title,body,baseRefName,headRefName,author,labels,state,url,additions,deletions,changedFiles

# Get the full diff of the PR
gh pr diff {pr_number}

# Get the list of changed files
gh pr diff {pr_number} --name-only

# Get PR description / body only
gh pr view {pr_number} --json body --jq .body

# Get all review comments (inline code comments)
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
  --jq '[.[] | {id, path, line, body, user: .user.login}]'

# Get review-level comments (top-level reviews including approvals)
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews \
  --jq '[.[] | {id, state, body, user: .user.login}]'

# Get general issue-style comments on the PR
gh api repos/{owner}/{repo}/issues/{pr_number}/comments \
  --jq '[.[] | {id, body, user: .user.login}]'

# Get repo owner/name
gh repo view --json nameWithOwner --jq .nameWithOwner

# Get commit list for the PR
gh pr view {pr_number} --json commits --jq '.commits[] | "\(.oid[:7]) \(.messageHeadline)"'

# Checkout a PR branch by number (if not already on it)
gh pr checkout {pr_number}

# Get the merge base between PR branch and target
git merge-base origin/{baseRefName} origin/{headRefName}
```

---

## Step 1: Identify the PR

Determine which PR to review:

- **Current branch**: If the user says "review current PR" or "review this PR", run:
  ```bash
  gh pr view --json number,title,headRefName,baseRefName,url,body,author,additions,deletions,changedFiles,labels,state
  ```
- **PR number given**: If the user provides a PR number, run:
  ```bash
  gh pr view {pr_number} --json number,title,headRefName,baseRefName,url,body,author,additions,deletions,changedFiles,labels,state
  ```
- **PR URL given**: Extract the number from the URL and proceed as above.

If no PR exists for the current branch, tell the user and stop.

Store: `pr_number`, `title`, `baseRefName`, `headRefName`, `body`, `url`, `author`.

## Step 2: Gather Full Context

Run these in parallel:

```bash
# 1. Full diff
gh pr diff {pr_number}

# 2. Changed file list
gh pr diff {pr_number} --name-only

# 3. Commit history
gh pr view {pr_number} --json commits --jq '.commits[] | "\(.oid[:7]) \(.messageHeadline)"'

# 4. All review comments (if any exist already)
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments \
  --jq '[.[] | {path, line, body, user: .user.login}]'

# 5. Review-level bodies
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews \
  --jq '[.[] | {state, body, user: .user.login}]'

# 6. Issue comments
gh api repos/{owner}/{repo}/issues/{pr_number}/comments \
  --jq '[.[] | {body, user: .user.login}]'
```

## Step 3: Understand the Codebase Context

Before writing the walkthrough, build understanding of what the PR touches:

1. **Read every changed file** at its current state on the PR branch — not just the diff, but the full file to understand surrounding context.
2. **Trace dependencies** — if the PR modifies a function, find its callers. If it changes a component, find where it's rendered. If it changes a type, find what consumes it.
3. **Check related files** — look at tests, configs, translations, styles that relate to the changed code but may not be in the diff.

This step is critical. You cannot write a useful walkthrough from the diff alone — you need to understand the system the PR operates within.

## Step 4: Build the Hierarchical Explanation

Structure your understanding into three layers:

### Layer 1: Background & Problem
- What area of the product does this touch?
- What was the state before this PR? What problem or gap existed?
- Is there a linked issue, ticket, or user-facing symptom?
- Who is affected (users, developers, other systems)?

### Layer 2: Motivation & Decision
- Why is this change needed now?
- What alternatives exist? Why was this approach chosen?
- What constraints shaped the solution (backward compatibility, performance, existing patterns)?

### Layer 3: Solution & Implementation
- How does the PR solve the problem?
- What are the key changes, grouped logically (not file-by-file)?
- What is the control flow / data flow after this change?
- What side effects or behavioral changes result?

## Step 5: Generate Mermaid Diagrams

Create diagrams that clarify the PR's changes. Choose diagram types based on what the PR does:

| PR Type | Diagram Types |
|---|---|
| New feature / flow | `flowchart` showing the new user or data flow |
| Refactor / restructure | `flowchart` showing before vs. after architecture |
| State changes | `stateDiagram-v2` showing state transitions |
| Multi-system interaction | `sequenceDiagram` showing component communication |
| Data model changes | `classDiagram` or `erDiagram` showing schema |
| File/module reorganization | `flowchart` showing module dependency tree |

**Rules for diagrams:**
- Minimum 1 diagram, aim for 2-3 where they add clarity.
- Every diagram must have a descriptive title as a comment above it.
- Keep diagrams focused — one concept per diagram, not everything crammed in.
- Use consistent naming that matches the actual code (function names, class names, file names).
- If the PR changes behavior, show a "before" and "after" diagram.

## Step 6: Identify Issues

Review the diff and surrounding code for issues. Classify each as:

### Blocking Issues
Issues that **must** be fixed before merge. These indicate:
- **Bugs**: Logic errors, off-by-one, null/undefined access, race conditions
- **Security**: XSS, injection, auth bypass, secret exposure, unsafe input handling
- **Data loss**: Destructive operations without safeguards, missing migrations
- **Breaking changes**: API contract violations, type mismatches, removed public interfaces without migration
- **Missing critical logic**: Unhandled error paths that will crash in production, missing validation at system boundaries

### Non-Blocking Issues
Issues worth fixing but not merge-blocking:
- **Code quality**: Naming, readability, unnecessary complexity, dead code
- **Performance**: Avoidable re-renders, missing memoization, inefficient queries (only if measurable)
- **Consistency**: Deviation from project patterns or coding standards (reference `.ai/rules/coding-standards.mdc`)
- **Testing**: Missing test coverage for new behavior, brittle test patterns
- **Suggestions**: Alternative approaches, simplifications, better abstractions

**For each issue, include:**
1. **File and line** — exact location (e.g., `src/Foo.ts:42`)
2. **What** — one-sentence description
3. **Why** — why this is a problem (not just "this is wrong")
4. **Suggested fix** — concrete code or approach, not vague advice

## Step 7: Write the Walkthrough Document

Create the file at `docs/review-pr-{pr_number}-{slug}.md` where `{slug}` is a short kebab-case summary of the PR title (max 40 chars).

Use this structure:

```markdown
# PR Walkthrough: #{pr_number} — {title}

> **Branch**: `{headRefName}` -> `{baseRefName}`
> **Author**: {author}
> **PR**: {url}
> **Date**: {YYYY-MM-DD}
> **Changed files**: {count} | **+{additions}** / **-{deletions}**

---

## 1. Background & Problem

{Layer 1 explanation — what existed before, what problem/gap this addresses.}

## 2. Motivation

{Layer 2 explanation — why this change, why now, what shaped the approach.}

## 3. Solution Overview

{Layer 3 high-level explanation — how the PR solves the problem, grouped by logical concern.}

### Architecture / Flow

{Mermaid diagram(s) here — with ```mermaid code blocks.}

## 4. Key Changes

{Walk through the significant changes grouped by concern, not file-by-file. Reference specific files and lines. Use sub-headings for distinct concerns.}

### 4.1 {Concern A}
...

### 4.2 {Concern B}
...

## 5. Blocking Issues

{List of blocking issues, or "No blocking issues found." if clean.}

### 5.1 {Short title}
- **File**: `path/to/file.ts:42`
- **What**: ...
- **Why**: ...
- **Fix**: ...

## 6. Non-Blocking Issues

{List of non-blocking issues and suggestions.}

### 6.1 {Short title}
- **File**: `path/to/file.ts:88`
- **What**: ...
- **Why**: ...
- **Suggestion**: ...

## 7. Summary

| Category | Count |
|---|---|
| Blocking issues | N |
| Non-blocking issues | N |
| Files changed | N |

**Verdict**: {APPROVE / REQUEST CHANGES / NEEDS DISCUSSION}

{1-2 sentence overall assessment.}
```

## Step 8: Report to User

After writing the file:
1. Tell the user the file path
2. Print the **Summary** section (Section 7) directly
3. If there are blocking issues, list them briefly
4. Ask if they want to discuss any specific issue in detail

## Important Rules

- **Explain first, judge second.** The walkthrough is the primary value — the review builds on that understanding.
- **Read full files, not just diffs.** Context matters. A change that looks fine in isolation may break invariants visible only in the full file.
- **Check coding standards.** Reference `.ai/rules/coding-standards.mdc` — naming, patterns, localization rules all apply.
- **Be specific.** "This could be improved" is useless. Say exactly what and how.
- **Separate opinion from fact.** Blocking issues are objective (bugs, security). Non-blocking suggestions should be clearly framed as suggestions.
- **Don't nitpick formatting** that a linter or formatter handles. Focus on logic, correctness, and design.
- **Credit what's good.** If the PR does something well (clean abstraction, good error handling, thorough tests), mention it briefly in the summary.
