Loading...
Loading...
Extract actionable learnings from merged PRs by comparing initial submission vs final merged state. Analyzes review cycles to capture what changed and why. Use when the user says "learn from PR", "extract PR learnings", "what did we learn from this PR", or wants to build a knowledge base from merged PRs.
npx skill4agent add harshitsinghbhandari/domain-expansion pr-learning/pr-learning 12345
/pr-learning https://github.com/owner/repo/pull/12345/pr-learning last 5
/pr-learning --since 2026-01-01What PR would you like to extract learnings from?
- A PR number or URL (e.g.,
)/pr-learning 12345- Recent PRs (e.g.,
)/pr-learning last 5
./learnings/pr-learnings.md~/learnings/general-learnings.md# Get PR state
gh pr view <PR_NUMBER> --json state,merged,mergedAt,author
# Reject if not mergedThis PR hasn't been merged yet. Learning extraction works best on completed PRs where we can see the full review cycle. Would you like me to do a standard PR review instead?
# Get first commit(s) in PR
gh pr view <PR_NUMBER> --json commits
# Get the diff at first commit
git show <first_commit_sha> --stat
git show <first_commit_sha> --no-stat# Get all review comments
gh pr view <PR_NUMBER> --json reviews,comments
# Get review threads with context
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments# Get final merged diff
gh pr diff <PR_NUMBER>
# Get commit messages showing evolution
gh pr view <PR_NUMBER> --json commits --jq '.commits[].messageHeadline'| Field | Description |
|---|---|
| Category | |
| Scope | |
| Severity | |
| Confidence | |
# Pseudo-logic for deduplication
for existing_learning in document:
if semantic_similarity(new_learning, existing_learning) > 0.8:
# Enhance existing instead of duplicating
enhance_with_new_evidence(existing_learning, new_learning)
return
# No match - add as new entry
append_learning(document, new_learning)./learnings/pr-learnings.md# PR Learnings - [Project Name]
> Auto-generated knowledge base from merged PR reviews.
> Last updated: [timestamp]
## Key Patterns (Auto-consolidated)
[Recurring themes extracted from 10+ PRs appear here]
---
## Recent Learnings
### [YYYY-MM-DD] PR #123: [PR Title]
**Author:** @username | **Reviewers:** @reviewer1, @reviewer2
#### Learning: [Concise title]
**Category:** `pattern` | **Severity:** `important`
**What happened:**
[Brief description of what the author originally submitted]
**What changed:**
[What reviewers requested and why]
**The lesson:**
[Actionable takeaway in imperative form]
**Evidence:**
- Review comment by @reviewer: "[quote]"
- Changed: `src/module.py:42-58`
**Related PRs:** #100, #89 (similar feedback)
---~/learnings/general-learnings.md# General Engineering Learnings
> Transferable knowledge extracted from PR reviews across all projects.
> Last updated: [timestamp]
## Patterns by Category
### Security
- [Learning entries...]
### Performance
- [Learning entries...]
### Testing
- [Learning entries...]
---
## Recent Additions
### [YYYY-MM-DD] From: owner/repo#123
**Learning:** [Title]
**Category:** `security` | **Confidence:** `high`
**Context:**
[What triggered this learning]
**The principle:**
[Generalized, transferable lesson]
**Example:**
```[language]
// Before (problematic)
[code]
// After (correct)
[code]
### Step 7: Smart Consolidation (Periodic)
Trigger consolidation when:
- Document exceeds 50KB
- 10+ new entries since last consolidation
- User explicitly requests: `/pr-learning consolidate`
**Consolidation process:**
1. **Extract recurring themes** from individual entries
2. **Create "Key Patterns" section** at document top
3. **Archive old entries** (move to bottom, collapse details)
4. **Update cross-references** between related learnings
### Step 8: Create Backup
Before any write operation:
```bash
# Backup existing files
cp ./learnings/pr-learnings.md "./learnings/pr-learnings_$(date +%Y%m%d_%H%M%S).md.bak"## PR Learning Extraction Complete
**PR:** #123 - [Title]
**Author:** @username
**Merged:** 2026-04-10
### Learnings Extracted: 3
| # | Learning | Category | Scope | Destination |
|---|----------|----------|-------|-------------|
| 1 | Use `pytest.raises` context manager | testing | general | ~/learnings/general-learnings.md |
| 2 | Always validate webhook signatures | security | general | ~/learnings/general-learnings.md |
| 3 | Service layer must not import from handlers | architecture | project | ./learnings/pr-learnings.md |
### Deduplication Actions: 1
- Enhanced existing learning "Prefer pytest fixtures over setUp" with new evidence from this PR
### Files Updated:
- `./learnings/pr-learnings.md` (2 new entries)
- `~/learnings/general-learnings.md` (2 new entries, 1 enhanced)| Condition | Action |
|---|---|
| No review comments | Skip with message: "PR merged without review feedback - no learnings to extract" |
| All comments are nits | Flag: "Only minor style feedback - learnings may be low-value" |
| Author == only reviewer | Skip: "Self-merged PR - no external perspective" |
| PR is revert | Skip: "Revert PR - original PR may have learnings" |
| Trivial change | Skip: "Trivial change (dependency bump, typo fix)" |
/pr-learning 456src/middleware/rate_limit.pyRateLimiterarchitectureimportantsrc/middleware/src/middleware/src/utils/ARCHITECTURE.mdarchitecturecritical# Wrong: In-memory (fails in multi-pod)
request_counts = {} # Lost on restart, not shared across pods
# Right: External store
redis_client.incr(f"rate_limit:{user_id}")testingimportant./learnings/pr-learnings.md~/learnings/general-learnings.md./learnings/pr-learnings.md# PR Learnings - [Repository Name]
> Knowledge base auto-generated from merged PR reviews.
> Run `/pr-learning <PR>` to add learnings from any merged PR.
---
## Key Patterns
[Consolidated patterns will appear here after 10+ entries]
---
## Recent Learnings
[Individual PR learnings will be added below]~/learnings/general-learnings.md# General Engineering Learnings
> Transferable knowledge extracted from PR reviews across all projects.
> This file grows across all repositories you work in.
---
## Patterns by Category
### Security
### Performance
### Testing
### Architecture
### Tooling
---
## Recent Additions
[Learnings will be added below]/pr-review/pr-learning