pr-learning
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePR 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/12345Analyzes 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-01Processes 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: (in the repository)
./learnings/pr-learnings.mdContains 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: (machine-wide)
~/learnings/general-learnings.mdContains 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
undefinedbash
undefinedGet 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
undefinedGet 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**
```bashgit show <first_commit_sha> --stat
git show <first_commit_sha> --no-stat
**Agent 2:评审意见与反馈**
```bashGet 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**
```bashgh api repos/{owner}/{repo}/pulls/{pr_number}/comments
**Agent 3:最终状态**
```bashGet 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'
undefinedgh pr view <PR_NUMBER> --json commits --jq '.commits[].messageHeadline'
undefinedStep 3: Analyze the Delta
步骤3:分析差异
Compare initial submission vs final merge to identify:
-
Code Changes After Review
- What code was added/removed/modified after review feedback?
- Which review comments led to code changes?
-
Pattern Corrections
- Where did reviewers suggest different patterns?
- What conventions were enforced?
-
Blind Spots Exposed
- What did the author miss that reviewers caught?
- Security issues, edge cases, performance concerns?
-
Knowledge Gaps
- What did the author not know about the codebase?
- What framework features were suggested?
对比初始提交与最终合并状态,识别以下内容:
-
评审后的代码变更
- 评审反馈后,哪些代码被添加/删除/修改?
- 哪些评审意见导致了代码变更?
-
模式修正
- 评审者建议了哪些不同的模式?
- 执行了哪些约定规范?
-
暴露的盲区
- 作者遗漏了哪些被评审者发现的内容?
- 安全问题、边缘情况、性能隐患?
-
知识缺口
- 作者对代码库有哪些不了解的地方?
- 评审者建议了哪些框架特性?
Step 4: Classify Learnings
步骤4:经验分类
For each learning, determine:
| Field | Description |
|---|---|
| Category | |
| Scope | |
| Severity | |
| Confidence | |
针对每条经验,确定以下属性:
| 字段 | 描述 |
|---|---|
| 类别 | |
| 范围 | |
| 严重程度 | |
| 可信度 | |
Step 5: Deduplicate Against Existing Learnings
步骤5:与现有经验去重
Before adding a new learning, scan both documents for semantic duplicates:
python
undefined添加新经验前,扫描两份文档查找语义重复内容:
python
undefinedPseudo-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 PRappend_learning(document, new_learning)
**去重信号:**
- 讨论相同的代码模式
- 引用相同的文件/模块
- 评审反馈主题一致
- 应用了相同的修复方案
若存在近似重复内容,**增强现有条目**:
- 添加来自新PR的额外证据
- 更新“出现频率”计数
- 添加指向新PR的交叉引用Step 6: Write Learnings
步骤6:写入经验
Project-specific document ():
./learnings/pr-learnings.mdmarkdown
undefined项目专属文档():
./learnings/pr-learnings.mdmarkdown
undefinedPR 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: | Severity:
patternimportantWhat 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类别: | 严重程度:
patternimportant原提交内容:
[作者最初提交内容的简要描述]
变更内容:
[评审者的要求及原因]
经验总结:
[命令式的可落地要点]
证据:
- @reviewer的评审意见:“[引用内容]”
- 变更文件:
src/module.py:42-58
相关PR: #100, #89(类似反馈)
**通用经验文档(`~/learnings/general-learnings.md`):**
```markdownGeneral 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: | Confidence:
securityhighContext:
[What triggered this learning]
The principle:
[Generalized, transferable lesson]
Example:
// Before (problematic)
[code]
// After (correct)
[code]undefined经验: [标题]
类别: | 可信度:
securityhigh背景:
[触发该经验的场景]
原则:
[通用、可迁移的经验]
示例:
// 之前(存在问题)
[代码]
// 之后(正确写法)
[代码]undefinedStep 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:
- Extract recurring themes from individual entries
- Create "Key Patterns" section at document top
- Archive old entries (move to bottom, collapse details)
- Update cross-references between related learnings
满足以下条件时触发整合:
- 文档大小超过50KB
- 自上次整合后新增10+条条目
- 用户明确请求:
/pr-learning consolidate
整合流程:
- 从单个条目中提取重复主题
- 在文档顶部创建“关键模式”板块
- 归档旧条目(移至底部,折叠详情)
- 更新相关经验之间的交叉引用
Step 8: Create Backup
步骤8:创建备份
Before any write operation:
bash
undefined执行任何写入操作前:
bash
undefinedBackup 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
undefinedPR Learning Extraction Complete
PR经验提取完成
PR: #123 - [Title]
Author: @username
Merged: 2026-04-10
PR: #123 - [标题]
作者: @username
合并时间: 2026-04-10
Learnings Extracted: 3
提取的经验:3条
| # | Learning | Category | Scope | Destination |
|---|---|---|---|---|
| 1 | Use | 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 |
| 序号 | 经验内容 | 类别 | 范围 | 存储位置 |
|---|---|---|---|---|
| 1 | 使用 | testing | general | ~/learnings/general-learnings.md |
| 2 | 始终验证webhook签名 | security | general | ~/learnings/general-learnings.md |
| 3 | 服务层不得从处理器导入内容 | architecture | project | ./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:
更新的文件:
- (2 new entries)
./learnings/pr-learnings.md - (2 new entries, 1 enhanced)
~/learnings/general-learnings.md
undefined- (新增2条条目)
./learnings/pr-learnings.md - (新增2条条目,增强1条)
~/learnings/general-learnings.md
undefinedQuality Filters
质量过滤
Not all PRs have extractable learnings. Skip or flag when:
| 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都能提取出有价值的经验,遇到以下情况时跳过或标记:
| 条件 | 操作 |
|---|---|
| 无评审意见 | 跳过并提示:“PR无评审反馈合并,无经验可提取” |
| 所有意见均为细节优化 | 标记:“仅包含次要风格反馈,经验价值可能较低” |
| 作者为唯一评审者 | 跳过:“自合并PR,无外部视角” |
| PR为回退操作 | 跳过:“回退PR,原PR可能包含可学习内容” |
| 无关紧要的变更 | 跳过:“无关紧要的变更(依赖版本更新、拼写错误修复)” |
Example Session
示例会话
User:
/pr-learning 456Agent gathers data, then outputs:
用户:
/pr-learning 456Agent收集数据后输出:
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:
- @bob: "We have a rate limiter middleware in - please use that instead of rolling your own"
src/middleware/rate_limit.py - @carol: "In-memory counters won't work in our multi-pod deployment - need Redis-backed limiting"
- @bob: "Missing tests for the 429 response case"
Final changes:
- Removed custom counter implementation
- Integrated existing middleware
RateLimiter - Added Redis backend configuration
- Added test for rate limit exceeded scenario
初始提交: 使用自定义内存计数器为每个端点添加限流。
评审反馈:
- @bob:“我们在中有一个限流中间件,请使用该组件而非自行实现”
src/middleware/rate_limit.py - @carol:“内存计数器在多Pod部署环境中无法正常工作,需要基于Redis的限流方案”
- @bob:“缺少429响应场景的测试”
最终变更:
- 删除自定义计数器实现
- 集成现有中间件
RateLimiter - 添加Redis后端配置
- 添加限流超出场景的测试
Learnings Extracted: 3
提取的经验:3条
1. Check for existing infrastructure before implementing (Project)
1. 实现前先检查现有基础设施(项目专属)
Category: | Severity:
architectureimportantThe lesson: Before implementing cross-cutting concerns (auth, rate limiting, caching, logging), search the codebase for existing solutions. This project has middleware in for common concerns.
src/middleware/Files to check: , ,
src/middleware/src/utils/ARCHITECTURE.md类别: | 严重程度:
architectureimportant经验总结: 在实现横切关注点(认证、限流、缓存、日志)前,先在代码库中查找现有解决方案。本项目在目录下有针对常见关注点的中间件。
src/middleware/需检查的文件: , ,
src/middleware/src/utils/ARCHITECTURE.md2. Stateless services need external state stores (General)
2. 无状态服务需要外部状态存储(通用)
Category: | Severity:
architecturecriticalThe 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类别: | 严重程度:
architecturecritical经验总结: 在容器化/多实例部署环境中,内存状态(计数器、缓存、会话)无法正常工作。需使用外部存储(Redis、Memcached、数据库)来存储共享状态。
模式:
python
undefinedWrong: 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: | Severity:
testingimportantThe 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.
类别: | 严重程度:
testingimportant经验总结: 添加可能返回错误响应的功能(限流、验证错误、认证失败)时,需明确测试这些错误路径,包括响应码和错误消息格式。
Files Updated:
更新的文件:
- (1 new entry)
./learnings/pr-learnings.md - (2 new entries)
~/learnings/general-learnings.md
- (新增1条条目)
./learnings/pr-learnings.md - (新增2条条目)
~/learnings/general-learnings.md
Important Rules
重要规则
- Only process merged PRs - Open PRs don't have final state
- Require review feedback - No comments = no learnings
- Preserve evidence - Always link to specific review comments
- Deduplicate aggressively - Enhance existing over creating duplicates
- Classify scope correctly - Project-specific stays in repo, general goes machine-wide
- Back up before writing - Never lose existing learnings
- Keep learnings actionable - "Do X" not "X is important"
- 仅处理已合并PR - 未合并PR没有最终状态
- 需要评审反馈 - 无意见则无经验可提取
- 保留证据 - 始终链接到具体的评审意见
- 积极去重 - 优先增强现有经验而非重复添加
- 正确分类范围 - 项目专属经验保留在仓库内,通用经验存储在全局
- 写入前备份 - 绝不丢失现有经验
- 保持经验可落地 - 使用“执行X”而非“X很重要”的表述
File Initialization
文件初始化
If learning files don't exist, create them with headers:
./learnings/pr-learnings.mdmarkdown
undefined若经验文件不存在,将自动创建并添加头部内容:
./learnings/pr-learnings.mdmarkdown
undefinedPR Learnings - [Repository Name]
PR经验 - [仓库名称]
Knowledge base auto-generated from merged PR reviews. Runto add learnings from any merged PR./pr-learning <PR>
从已合并PR评审中自动生成的知识库。 运行可添加任意已合并PR的经验。/pr-learning <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`:**
```markdownGeneral 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[经验将添加至下方]
undefinedIntegration 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 on PRs that had significant review cycles.
/pr-learning本技能与互补:
/pr-review- pr-review:在PR合并前进行评审(前瞻性)
- pr-learning:在PR合并后提取经验(回顾性)
为获取最大价值,对有重要评审周期的PR运行。
/pr-learning