pr-learning

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PR Learning Extractor

PR学习提取器

Turn merged PRs into permanent, high-value learning artifacts by analyzing the full lifecycle: initial submission → review feedback → final merged state. Captures the delta between "what I thought was right" and "what was actually right."
将已合并的PR转化为永久、高价值的学习成果,分析完整生命周期:初始提交 → 评审反馈 → 最终合并状态。捕捉“我认为正确的内容”与“实际正确的内容”之间的差异。

Why This Matters

为何这很重要

The gap between a PR's first commit and its final merge represents concentrated learning:
  • Review comments reveal blind spots in your thinking
  • Code changes show patterns you didn't know existed
  • Approval requirements expose team standards you weren't aware of
This skill extracts that knowledge before it's lost to scrollback.
Your extraction goes under the user's name. Learnings become part of their permanent knowledge base. Omitting a lesson or softening a finding wastes the review cycle. Extract the full, unvarnished lesson — the user can decide what to act on. If you noticed something worth learning, include it.
PR首次提交与最终合并之间的差距浓缩了大量学习要点:
  • 评审意见揭示了你思维中的盲区
  • 代码变更展示了你此前未知的模式
  • 批准要求暴露了你未留意的团队标准
本技能会在这些知识被滚动记录淹没前将其提取出来。
提取的经验将归属到用户名下。 这些经验会成为用户永久知识库的一部分。遗漏任何一个教训或淡化发现的内容都会浪费评审周期。提取完整、真实的教训——用户可自行决定如何行动。如果你注意到值得学习的内容,请务必包含进去。

When to Use

使用场景

Good triggers:
  • "Learn from PR #123"
  • "Extract learnings from this PR"
  • "What can we learn from PR 456?"
  • "Add PR 789 to the knowledge base"
  • "Run /pr-learning on the last 5 merged PRs"
Not for:
  • Open PRs (no final state to compare against)
  • PRs with no review comments (nothing to learn)
  • Trivial PRs (dependency bumps, typo fixes)
适用触发词:
  • "从PR #123中学习"
  • "提取这个PR的经验"
  • "我们能从PR 456中学到什么?"
  • "将PR 789添加到知识库"
  • "对最近5个已合并PR运行/pr-learning"
不适用场景:
  • 未合并的PR(没有最终状态可供对比)
  • 无评审意见的PR(没有可学习的内容)
  • 无关紧要的PR(依赖版本更新、拼写错误修复)

Usage Modes

使用模式

Single PR Mode

单PR模式

/pr-learning 12345
/pr-learning https://github.com/owner/repo/pull/12345
Analyzes one merged PR and appends learnings to both documents.
/pr-learning 12345
/pr-learning https://github.com/owner/repo/pull/12345
分析单个已合并PR,并将经验追加到两份文档中。

Batch Mode

批量模式

/pr-learning last 5
/pr-learning --since 2026-01-01
Processes multiple recent PRs. Useful for catching up on learnings.
/pr-learning last 5
/pr-learning --since 2026-01-01
处理多个近期PR,适合批量补充学习经验。

No Argument Mode

无参数模式

If invoked with no arguments, prompt the user:
What 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
    )
若调用时未传参数,请提示用户:
你想从哪个PR中提取经验?
  • PR编号或URL(例如:
    /pr-learning 12345
  • 近期PR(例如:
    /pr-learning last 5

Output Files

输出文件

Every run updates two living documents:
每次运行都会更新两份动态文档:

1. Project-Specific Learnings

1. 项目专属经验

Location:
./learnings/pr-learnings.md
(in the repository)
Contains learnings specific to this codebase:
  • Project conventions and patterns
  • Module-specific gotchas
  • Team preferences and standards
  • Architecture decisions
存储位置:
./learnings/pr-learnings.md
(仓库内)
包含针对本代码库的专属经验:
  • 项目约定与模式
  • 模块特定陷阱
  • 团队偏好与标准
  • 架构决策

2. General Learnings

2. 通用经验

Location:
~/learnings/general-learnings.md
(machine-wide)
Contains transferable knowledge:
  • Language idioms and best practices
  • Common review feedback patterns
  • Security and performance principles
  • Testing strategies
存储位置:
~/learnings/general-learnings.md
(全局)
包含可迁移的通用知识:
  • 语言惯用写法与最佳实践
  • 常见评审反馈模式
  • 安全与性能原则
  • 测试策略

Workflow

工作流程

Step 1: Validate PR State

步骤1:验证PR状态

bash
undefined
bash
undefined

Get PR state

获取PR状态

gh pr view <PR_NUMBER> --json state,merged,mergedAt,author
gh pr view <PR_NUMBER> --json state,merged,mergedAt,author

Reject if not merged

若未合并则拒绝处理


If PR is not merged, respond:
> This 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?

如果PR未合并,回复:
> 该PR尚未合并。经验提取工具最适用于已完成的PR,我们可以查看完整的评审周期。你需要我进行标准的PR评审吗?

Step 2: Gather PR Lifecycle Data

步骤2:收集PR生命周期数据

Spawn 3 sub-agents in parallel to collect:
Agent 1: Initial State
bash
undefined
并行启动3个子Agent来收集数据:
Agent 1:初始状态
bash
undefined

Get first commit(s) in PR

获取PR中的首个提交

gh pr view <PR_NUMBER> --json commits
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

**Agent 2: Review Comments & Feedback**
```bash
git show <first_commit_sha> --stat git show <first_commit_sha> --no-stat

**Agent 2:评审意见与反馈**
```bash

Get all review comments

获取所有评审意见

gh pr view <PR_NUMBER> --json reviews,comments
gh pr view <PR_NUMBER> --json reviews,comments

Get review threads with context

获取带上下文的评审线程

gh api repos/{owner}/{repo}/pulls/{pr_number}/comments

**Agent 3: Final State**
```bash
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments

**Agent 3:最终状态**
```bash

Get final merged diff

获取最终合并的差异

gh pr diff <PR_NUMBER>
gh pr diff <PR_NUMBER>

Get commit messages showing evolution

获取展示演变过程的提交信息

gh pr view <PR_NUMBER> --json commits --jq '.commits[].messageHeadline'
undefined
gh pr view <PR_NUMBER> --json commits --jq '.commits[].messageHeadline'
undefined

Step 3: Analyze the Delta

步骤3:分析差异

Compare initial submission vs final merge to identify:
  1. Code Changes After Review
    • What code was added/removed/modified after review feedback?
    • Which review comments led to code changes?
  2. Pattern Corrections
    • Where did reviewers suggest different patterns?
    • What conventions were enforced?
  3. Blind Spots Exposed
    • What did the author miss that reviewers caught?
    • Security issues, edge cases, performance concerns?
  4. Knowledge Gaps
    • What did the author not know about the codebase?
    • What framework features were suggested?
对比初始提交与最终合并状态,识别以下内容:
  1. 评审后的代码变更
    • 评审反馈后,哪些代码被添加/删除/修改?
    • 哪些评审意见导致了代码变更?
  2. 模式修正
    • 评审者建议了哪些不同的模式?
    • 执行了哪些约定规范?
  3. 暴露的盲区
    • 作者遗漏了哪些被评审者发现的内容?
    • 安全问题、边缘情况、性能隐患?
  4. 知识缺口
    • 作者对代码库有哪些不了解的地方?
    • 评审者建议了哪些框架特性?

Step 4: Classify Learnings

步骤4:经验分类

For each learning, determine:
FieldDescription
Category
pattern
,
convention
,
security
,
performance
,
testing
,
architecture
,
tooling
Scope
project
(specific to this repo) or
general
(transferable)
Severity
critical
(would cause bugs),
important
(quality impact),
minor
(style/preference)
Confidence
high
(explicit reviewer comment),
medium
(inferred from changes),
low
(speculative)
针对每条经验,确定以下属性:
字段描述
类别
pattern
,
convention
,
security
,
performance
,
testing
,
architecture
,
tooling
范围
project
(仅适用于本仓库)或
general
(可迁移)
严重程度
critical
(会导致bug),
important
(影响质量),
minor
(风格/偏好)
可信度
high
(明确的评审意见),
medium
(从变更中推断),
low
(推测)

Step 5: Deduplicate Against Existing Learnings

步骤5:与现有经验去重

Before adding a new learning, scan both documents for semantic duplicates:
python
undefined
添加新经验前,扫描两份文档查找语义重复内容:
python
undefined

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
for existing_learning in document: if semantic_similarity(new_learning, existing_learning) > 0.8: # 增强现有经验而非重复添加 enhance_with_new_evidence(existing_learning, new_learning) return

No match - add as new entry

无匹配项 - 添加为新条目

append_learning(document, new_learning)

**Deduplication signals:**
- Same code pattern discussed
- Same file/module referenced
- Same reviewer feedback theme
- Same fix applied

If a near-duplicate exists, **enhance the existing entry** with:
- Additional evidence from the new PR
- Updated "frequency" count
- Cross-reference to the new PR
append_learning(document, new_learning)

**去重信号:**
- 讨论相同的代码模式
- 引用相同的文件/模块
- 评审反馈主题一致
- 应用了相同的修复方案

若存在近似重复内容,**增强现有条目**:
- 添加来自新PR的额外证据
- 更新“出现频率”计数
- 添加指向新PR的交叉引用

Step 6: Write Learnings

步骤6:写入经验

Project-specific document (
./learnings/pr-learnings.md
):
markdown
undefined
项目专属文档(
./learnings/pr-learnings.md
):
markdown
undefined

PR Learnings - [Project Name]

PR经验 - [项目名称]

Auto-generated knowledge base from merged PR reviews. Last updated: [timestamp]
从已合并PR评审中自动生成的知识库。 最后更新时间:[时间戳]

Key Patterns (Auto-consolidated)

关键模式(自动整合)

[Recurring themes extracted from 10+ PRs appear here]

[从10+个PR中提取的重复主题将显示在此处]

Recent Learnings

近期经验

[YYYY-MM-DD] PR #123: [PR Title]

[YYYY-MM-DD] PR #123: [PR标题]

Author: @username | Reviewers: @reviewer1, @reviewer2
作者: @username | 评审者: @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)


**General learnings document (`~/learnings/general-learnings.md`):**

```markdown
类别:
pattern
| 严重程度:
important
原提交内容: [作者最初提交内容的简要描述]
变更内容: [评审者的要求及原因]
经验总结: [命令式的可落地要点]
证据:
  • @reviewer的评审意见:“[引用内容]”
  • 变更文件:
    src/module.py:42-58
相关PR: #100, #89(类似反馈)


**通用经验文档(`~/learnings/general-learnings.md`):**

```markdown

General Engineering Learnings

通用工程经验

Transferable knowledge extracted from PR reviews across all projects. Last updated: [timestamp]
从所有项目的PR评审中提取的可迁移知识。 最后更新时间:[时间戳]

Patterns by Category

按类别划分的模式

Security

Security

  • [Learning entries...]
  • [经验条目...]

Performance

Performance

  • [Learning entries...]
  • [经验条目...]

Testing

Testing

  • [Learning entries...]

  • [经验条目...]

Recent Additions

新增内容

[YYYY-MM-DD] From: owner/repo#123

[YYYY-MM-DD] 来源:owner/repo#123

Learning: [Title]
Category:
security
| Confidence:
high
Context: [What triggered this learning]
The principle: [Generalized, transferable lesson]
Example:
// Before (problematic)
[code]

// After (correct)
[code]

undefined
经验: [标题]
类别:
security
| 可信度:
high
背景: [触发该经验的场景]
原则: [通用、可迁移的经验]
示例:
// 之前(存在问题)
[代码]

// 之后(正确写法)
[代码]

undefined

Step 7: Smart Consolidation (Periodic)

步骤7:智能整合(定期执行)

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
满足以下条件时触发整合:
  • 文档大小超过50KB
  • 自上次整合后新增10+条条目
  • 用户明确请求:
    /pr-learning consolidate
整合流程:
  1. 从单个条目中提取重复主题
  2. 在文档顶部创建“关键模式”板块
  3. 归档旧条目(移至底部,折叠详情)
  4. 更新相关经验之间的交叉引用

Step 8: Create Backup

步骤8:创建备份

Before any write operation:
bash
undefined
执行任何写入操作前:
bash
undefined

Backup existing files

备份现有文件

cp ./learnings/pr-learnings.md "./learnings/pr-learnings_$(date +%Y%m%d_%H%M%S).md.bak"

Keep last 5 backups, delete older ones.
cp ./learnings/pr-learnings.md "./learnings/pr-learnings_$(date +%Y%m%d_%H%M%S).md.bak"

保留最近5份备份,删除更早的备份。

Step 9: Report Summary

步骤9:生成总结报告

After processing, output:
markdown
undefined
处理完成后,输出:
markdown
undefined

PR Learning Extraction Complete

PR经验提取完成

PR: #123 - [Title] Author: @username Merged: 2026-04-10
PR: #123 - [标题] 作者: @username 合并时间: 2026-04-10

Learnings Extracted: 3

提取的经验:3条

#LearningCategoryScopeDestination
1Use
pytest.raises
context manager
testinggeneral~/learnings/general-learnings.md
2Always validate webhook signaturessecuritygeneral~/learnings/general-learnings.md
3Service layer must not import from handlersarchitectureproject./learnings/pr-learnings.md
序号经验内容类别范围存储位置
1使用
pytest.raises
上下文管理器
testinggeneral~/learnings/general-learnings.md
2始终验证webhook签名securitygeneral~/learnings/general-learnings.md
3服务层不得从处理器导入内容architectureproject./learnings/pr-learnings.md

Deduplication Actions: 1

去重操作:1项

  • Enhanced existing learning "Prefer pytest fixtures over setUp" with new evidence from this PR
  • 使用来自本PR的新证据,增强现有经验“优先使用pytest fixtures而非setUp”

Files Updated:

更新的文件:

  • ./learnings/pr-learnings.md
    (2 new entries)
  • ~/learnings/general-learnings.md
    (2 new entries, 1 enhanced)
undefined
  • ./learnings/pr-learnings.md
    (新增2条条目)
  • ~/learnings/general-learnings.md
    (新增2条条目,增强1条)
undefined

Quality Filters

质量过滤

Not all PRs have extractable learnings. Skip or flag when:
ConditionAction
No review commentsSkip with message: "PR merged without review feedback - no learnings to extract"
All comments are nitsFlag: "Only minor style feedback - learnings may be low-value"
Author == only reviewerSkip: "Self-merged PR - no external perspective"
PR is revertSkip: "Revert PR - original PR may have learnings"
Trivial changeSkip: "Trivial change (dependency bump, typo fix)"
并非所有PR都能提取出有价值的经验,遇到以下情况时跳过或标记:
条件操作
无评审意见跳过并提示:“PR无评审反馈合并,无经验可提取”
所有意见均为细节优化标记:“仅包含次要风格反馈,经验价值可能较低”
作者为唯一评审者跳过:“自合并PR,无外部视角”
PR为回退操作跳过:“回退PR,原PR可能包含可学习内容”
无关紧要的变更跳过:“无关紧要的变更(依赖版本更新、拼写错误修复)”

Example Session

示例会话

User:
/pr-learning 456
Agent gathers data, then outputs:

用户:
/pr-learning 456
Agent收集数据后输出:

PR Learning Extraction Complete

PR经验提取完成

PR: #456 - Add rate limiting to public API endpoints Author: @alice Merged: 2026-04-08 Reviewers: @bob, @carol
PR: #456 - 为公开API端点添加限流 作者: @alice 合并时间: 2026-04-08 评审者: @bob, @carol

Analysis

分析

Initial submission: Added rate limiting using a custom in-memory counter per endpoint.
Review feedback:
  1. @bob: "We have a rate limiter middleware in
    src/middleware/rate_limit.py
    - please use that instead of rolling your own"
  2. @carol: "In-memory counters won't work in our multi-pod deployment - need Redis-backed limiting"
  3. @bob: "Missing tests for the 429 response case"
Final changes:
  • Removed custom counter implementation
  • Integrated existing
    RateLimiter
    middleware
  • Added Redis backend configuration
  • Added test for rate limit exceeded scenario
初始提交: 使用自定义内存计数器为每个端点添加限流。
评审反馈:
  1. @bob:“我们在
    src/middleware/rate_limit.py
    中有一个限流中间件,请使用该组件而非自行实现”
  2. @carol:“内存计数器在多Pod部署环境中无法正常工作,需要基于Redis的限流方案”
  3. @bob:“缺少429响应场景的测试”
最终变更:
  • 删除自定义计数器实现
  • 集成现有
    RateLimiter
    中间件
  • 添加Redis后端配置
  • 添加限流超出场景的测试

Learnings Extracted: 3

提取的经验:3条

1. Check for existing infrastructure before implementing (Project)

1. 实现前先检查现有基础设施(项目专属)

Category:
architecture
| Severity:
important
The lesson: Before implementing cross-cutting concerns (auth, rate limiting, caching, logging), search the codebase for existing solutions. This project has middleware in
src/middleware/
for common concerns.
Files to check:
src/middleware/
,
src/utils/
,
ARCHITECTURE.md

类别:
architecture
| 严重程度:
important
经验总结: 在实现横切关注点(认证、限流、缓存、日志)前,先在代码库中查找现有解决方案。本项目在
src/middleware/
目录下有针对常见关注点的中间件。
需检查的文件:
src/middleware/
,
src/utils/
,
ARCHITECTURE.md

2. Stateless services need external state stores (General)

2. 无状态服务需要外部状态存储(通用)

Category:
architecture
| Severity:
critical
The lesson: In containerized/multi-instance deployments, in-memory state (counters, caches, sessions) won't work correctly. Use external stores (Redis, Memcached, database) for shared state.
Pattern:
python
undefined
类别:
architecture
| 严重程度:
critical
经验总结: 在容器化/多实例部署环境中,内存状态(计数器、缓存、会话)无法正常工作。需使用外部存储(Redis、Memcached、数据库)来存储共享状态。
模式:
python
undefined

Wrong: In-memory (fails in multi-pod)

错误:内存存储(多Pod环境下失效)

request_counts = {} # Lost on restart, not shared across pods
request_counts = {} # 重启后丢失,无法在Pod间共享

Right: External store

正确:外部存储

redis_client.incr(f"rate_limit:{user_id}")

---
redis_client.incr(f"rate_limit:{user_id}")

---

3. Always test error responses (General)

3. 始终测试错误响应(通用)

Category:
testing
| Severity:
important
The lesson: When adding features that can return error responses (rate limits, validation errors, auth failures), explicitly test those error paths including response codes and error message format.

类别:
testing
| 严重程度:
important
经验总结: 添加可能返回错误响应的功能(限流、验证错误、认证失败)时,需明确测试这些错误路径,包括响应码和错误消息格式。

Files Updated:

更新的文件:

  • ./learnings/pr-learnings.md
    (1 new entry)
  • ~/learnings/general-learnings.md
    (2 new entries)

  • ./learnings/pr-learnings.md
    (新增1条条目)
  • ~/learnings/general-learnings.md
    (新增2条条目)

Important Rules

重要规则

  1. Only process merged PRs - Open PRs don't have final state
  2. Require review feedback - No comments = no learnings
  3. Preserve evidence - Always link to specific review comments
  4. Deduplicate aggressively - Enhance existing over creating duplicates
  5. Classify scope correctly - Project-specific stays in repo, general goes machine-wide
  6. Back up before writing - Never lose existing learnings
  7. Keep learnings actionable - "Do X" not "X is important"
  1. 仅处理已合并PR - 未合并PR没有最终状态
  2. 需要评审反馈 - 无意见则无经验可提取
  3. 保留证据 - 始终链接到具体的评审意见
  4. 积极去重 - 优先增强现有经验而非重复添加
  5. 正确分类范围 - 项目专属经验保留在仓库内,通用经验存储在全局
  6. 写入前备份 - 绝不丢失现有经验
  7. 保持经验可落地 - 使用“执行X”而非“X很重要”的表述

File Initialization

文件初始化

If learning files don't exist, create them with headers:
./learnings/pr-learnings.md
:
markdown
undefined
若经验文件不存在,将自动创建并添加头部内容:
./learnings/pr-learnings.md
markdown
undefined

PR Learnings - [Repository Name]

PR经验 - [仓库名称]

Knowledge base auto-generated from merged PR reviews. Run
/pr-learning <PR>
to add learnings from any merged PR.

从已合并PR评审中自动生成的知识库。 运行
/pr-learning <PR>
可添加任意已合并PR的经验。

Key Patterns

关键模式

[Consolidated patterns will appear here after 10+ entries]

[整合后的模式将在积累10+条条目后显示在此处]

Recent Learnings

近期经验

[Individual PR learnings will be added below]

**`~/learnings/general-learnings.md`:**
```markdown
[单个PR的经验将添加至下方]

**`~/learnings/general-learnings.md`:**
```markdown

General Engineering Learnings

通用工程经验

Transferable knowledge extracted from PR reviews across all projects. This file grows across all repositories you work in.

从所有项目的PR评审中提取的可迁移知识。 本文件会随着你参与的所有仓库不断积累内容。

Patterns by Category

按类别划分的模式

Security

Security

Performance

Performance

Testing

Testing

Architecture

Architecture

Tooling

Tooling



Recent Additions

新增内容

[Learnings will be added below]
undefined
[经验将添加至下方]
undefined

Integration with PR Review

与PR评审的集成

This skill complements
/pr-review
:
  • pr-review: Reviews PRs before merge (prospective)
  • pr-learning: Extracts lessons after merge (retrospective)
For maximum value, run
/pr-learning
on PRs that had significant review cycles.
本技能与
/pr-review
互补:
  • pr-review:在PR合并前进行评审(前瞻性)
  • pr-learning:在PR合并后提取经验(回顾性)
为获取最大价值,对有重要评审周期的PR运行
/pr-learning