pr-review-assistant by rysweet/amplihack
npx skills add https://github.com/rysweet/amplihack --skill pr-review-assistant基于哲学理念的 Pull Request 审查,超越语法和风格检查,确保代码符合 amplihack 的核心开发原则。本技能不仅审查代码的正确性,还审查其是否遵循极致的简洁性、模块化架构和无废话实现。
每一行代码都必须证明其存在的价值。我们提问:
代码应组织为具有清晰连接的自包含模块:
没有捷径、存根或技术债务:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
首先理解 PR 改变了什么:
根据 amplihack 原则审查每个变更:
寻找常见的过度工程化模式:
如果是新模块或模块变更:
充分的测试至关重要:
当建议变更时:
PR:向 API 添加用户权限检查
变更代码:
class PermissionValidator:
def __init__(self):
self.cache = {}
def validate(self, user, resource):
if user in self.cache:
return self.cache[user]
result = self._complex_validation(user, resource)
self.cache[user] = result
return result
def _complex_validation(self, user, resource):
# Complex business logic...
pass
审查评论:
FILE: permissions.py (lines 10-25)
这过度工程化了权限检查,添加了可能不需要的缓存。
缓存层增加了复杂性而没有证明的好处:
1. 如果用户权限更改,缓存可能变得陈旧
2. 不清楚何时/是否应该使缓存失效
3. 内存缓存无法跨进程扩展
4. 权限检查通常不在热点路径中
建议 - 从更简单开始:
```python
def check_permission(user, resource):
"""Check if user can access resource."""
# Direct implementation
return user.has_access_to(resource)
如果以后需要缓存,当性能分析显示有帮助时再添加。
这符合极致简洁性:在证明必要之前不要增加复杂性。
### 示例 2:识别缺少重构文档
**PR**:添加新的身份验证模块
**变更代码**:新文件 `~/.amplihack/.claude/tools/auth/auth.py`
**审查评论**:
FILE: .claude/tools/auth/ (新模块)
优点:模块职责清晰(JWT 验证、令牌刷新)。问题:缺少模块重构的规范文档。
砖块哲学要求:模块应该能够从规范重构。
需要采取的行动:
这使得未来如果需求变更可以重建。
参见 .claude/skills/pr-review-assistant/ 的规范模板。
### 示例 3:识别无废话问题
**PR**:添加数据处理管道
**变更代码**:
```python
def process_data(data):
"""Process data through pipeline."""
# TODO: Add error handling
result = validate(data)
if not result:
return None # swallowed error
# TODO: Implement caching
return transform(result)
审查评论:
FILE: pipeline.py (lines 5-15)
发现的无废话问题:
1. 第 6 行:TODO 注释 - 要么实现,要么删除
- "添加错误处理" - 要么现在添加,要么创建问题
- "实现缓存" - 现在还不需要;如果性能分析显示有好处再添加
2. 第 10 行:吞没的错误
- validate() 可能引发异常,但返回 None
- 使错误明确:raise ValueError("无效数据")
- 或者捕获并重新引发并提供上下文
3. 第 8 行:静默失败
- 如果返回 None,调用者不知道原因
- 要么引发异常,要么返回 Result 类型
建议:
```python
def process_data(data):
"""Process data through pipeline.
Raises:
ValueError: If data validation fails
"""
result = validate(data) # Raises if invalid
return transform(result)
所有代码都是生产就绪的,没有 TODO。
### 示例 4:识别缺少的测试
**PR**:添加用户角色管理
**变更代码**:用户模块中的新类 `RoleManager`
**审查评论**:
FILE: user.py (lines 50-100)
添加了新功能但没有充分的测试。
问题:RoleManager 公共接口未测试
缺少的边界情况:
契约验证:
添加:tests/test_role_manager.py,覆盖率 85% 以上
### 示例 5:认可良好设计
**PR**:添加简化的配置加载器
**变更代码**:
```python
def load_config(path):
"""Load YAML config from file.
Args:
path: Path to config file
Returns:
dict: Parsed config
Raises:
FileNotFoundError: If file doesn't exist
ValueError: If YAML is invalid
"""
with open(path) as f:
try:
return yaml.safe_load(f)
except yaml.YAMLError as e:
raise ValueError(f"Invalid YAML: {e}") from e
审查评论:
优秀 - 这正是我们想要的简洁性:
✅ 单一职责:加载和解析 YAML
✅ 清晰的错误处理:带有上下文的明确异常
✅ 没有 TODO 或存根:生产就绪
✅ 完整的文档:清晰的参数、返回值、异常
✅ 没有过度工程化:直接实现
✅ 可测试:清晰的行为可验证
这是极致简洁性的典范示例。
在评论 PR 时,使用此结构:
**FILE**: path/to/file.py (lines X-Y)
**ISSUE**: [违反的原则 - 简洁性/模块化/无废话/测试/文档]
**WHAT**: [描述代码中的内容]
**WHY IT'S PROBLEMATIC**: [它如何违反 amplihack 原则]
**SUGGESTION**: [具体的代码示例或方法]
**REFERENCE**: [相关哲学、原则或示例的链接]
该技能可以使用以下命令向 GitHub PR 发布审查评论:
gh pr comment <PR-NUMBER> -b "Review comment here"
# Or for specific file reviews:
gh pr diff <PR-NUMBER> | grep "^---" | head -1
# Then post review with specific file:line references
# 过度工程化:50 行配置类
class ConfigManager:
def __init__(self, env_file, schema_file, validators):
self.config = load_yaml(env_file)
self.schema = load_json(schema_file)
self.validators = validators
# 40 more lines...
# 简单:5 行
config = yaml.safe_load(open('.env.yaml'))
# 过度工程化:单一实现的工厂
class ValidationFactory:
def create_validator(self, type):
if type == "email":
return EmailValidator()
# ... more types
# 简单:直接函数
def validate_email(email):
return "@" in email and "." in email
# 过度工程化:从未被子类化的基类
class BaseRepository(ABC):
@abstractmethod
def find(self, id): pass
# ... 20 abstract methods
class UserRepository(BaseRepository):
# 被迫实现所有抽象方法
# 但只使用了其中 3 个
# 简单:直接类
class UserRepository:
def find(self, id):
return self.db.query(User).get(id)
# 过度工程化:不需要的复杂缓存
cache = LRUCache(maxsize=1000)
stats = CacheStats()
lock = threading.Lock()
# ... complex logic
# 简单:无 - 先进行性能分析,如果需要再优化
result = function(args)
审查时,问这些问题:
使用此技能成功进行 PR 审查:
该技能产生:
所有审查都基于这些文档:
~/.amplihack/.claude/context/PHILOSOPHY.md - 核心开发哲学~/.amplihack/.claude/context/PATTERNS.md - 批准的模式和反模式Specs/ - 用于架构验证的模块规范~/.amplihack/.claude/context/DISCOVERIES.md - 已知问题和解决方案此技能应根据使用情况演进:
将学习记录在 ~/.amplihack/.claude/context/DISCOVERIES.md 中。
每周安装次数
113
仓库
GitHub 星标数
39
首次出现
2026 年 1 月 23 日
安全审计
安装于
opencode105
codex99
cursor97
claude-code97
gemini-cli96
github-copilot95
Philosophy-aware pull request reviews that go beyond syntax and style to check alignment with amplihack's core development principles. This skill reviews PRs not just for correctness, but for ruthless simplicity, modular architecture, and zero-BS implementation.
Every line of code must justify its existence. We ask:
Code should be organized as self-contained modules with clear connections:
No shortcuts, stubs, or technical debt:
Start by understanding what the PR changes:
Review each change against amplihack principles:
Look for common over-engineering patterns:
If new modules or module changes:
Adequate testing is crucial:
When suggesting changes:
PR : Add user permission checking to API
Code Changed :
class PermissionValidator:
def __init__(self):
self.cache = {}
def validate(self, user, resource):
if user in self.cache:
return self.cache[user]
result = self._complex_validation(user, resource)
self.cache[user] = result
return result
def _complex_validation(self, user, resource):
# Complex business logic...
pass
Review Comment :
FILE: permissions.py (lines 10-25)
This over-engineers the permission checking with caching that may not be needed.
The caching layer adds complexity without proven benefit:
1. Cache can become stale if user permissions change
2. Unclear when/if cache should be invalidated
3. In-memory cache doesn't scale across processes
4. Permission checks are usually not in hot paths
SUGGESTION - Start simpler:
```python
def check_permission(user, resource):
"""Check if user can access resource."""
# Direct implementation
return user.has_access_to(resource)
If caching is needed later, add it when profiling shows it helps.
This aligns with ruthless simplicity: don't add complexity until proven necessary.
### Example 2: Identifying Lack of Regeneration Documentation
**PR**: Add new authentication module
**Code Changed**: New file `~/.amplihack/.claude/tools/auth/auth.py`
**Review Comment**:
FILE: .claude/tools/auth/ (new module)
Good: Module has clear responsibilities (JWT validation, token refresh). Issue: Missing specification documentation for module regeneration.
Brick Philosophy Requirement: Modules should be regeneratable from spec.
ACTION NEEDED:
This enables future rebuilding if requirements change.
See .claude/skills/pr-review-assistant/ for specification template.
### Example 3: Identifying Zero-BS Issues
**PR**: Add data processing pipeline
**Code Changed**:
```python
def process_data(data):
"""Process data through pipeline."""
# TODO: Add error handling
result = validate(data)
if not result:
return None # swallowed error
# TODO: Implement caching
return transform(result)
Review Comment :
FILE: pipeline.py (lines 5-15)
Zero-BS Issues Found:
1. LINE 6: TODO comments - implement or remove
- "Add error handling" - Either add it now or create issue
- "Implement caching" - Not needed yet; add if profiling shows benefit
2. LINE 10: Swallowed error
- validate() likely raised exception, but returns None
- Make error explicit: raise ValueError("Invalid data")
- Or catch and re-raise with context
3. LINE 8: Silent failures
- If None is returned, caller doesn't know why
- Either raise exception or return Result type
SUGGESTION:
```python
def process_data(data):
"""Process data through pipeline.
Raises:
ValueError: If data validation fails
"""
result = validate(data) # Raises if invalid
return transform(result)
All code is production-ready, no TODOs.
### Example 4: Identifying Missing Tests
**PR**: Add user role management
**Code Changed**: New class `RoleManager` in user module
**Review Comment**:
FILE: user.py (lines 50-100)
New functionality added without adequate tests.
ISSUE: RoleManager public interface not tested
EDGE CASES MISSING:
CONTRACT VERIFICATION:
ADD: tests/test_role_manager.py with 85%+ coverage
### Example 5: Recognizing Good Design
**PR**: Add simplified config loader
**Code Changed**:
```python
def load_config(path):
"""Load YAML config from file.
Args:
path: Path to config file
Returns:
dict: Parsed config
Raises:
FileNotFoundError: If file doesn't exist
ValueError: If YAML is invalid
"""
with open(path) as f:
try:
return yaml.safe_load(f)
except yaml.YAMLError as e:
raise ValueError(f"Invalid YAML: {e}") from e
Review Comment :
EXCELLENT - This is exactly the simplicity we want:
✅ Single responsibility: Load and parse YAML
✅ Clear error handling: Explicit exceptions with context
✅ No TODOs or stubs: Production ready
✅ Complete documentation: Clear args, returns, exceptions
✅ No over-engineering: Direct implementation
✅ Testable: Clear behavior to verify
This is a model example of ruthless simplicity.
When commenting on PRs, use this structure:
**FILE**: path/to/file.py (lines X-Y)
**ISSUE**: [Principle violated - Simplicity/Modularity/Zero-BS/Tests/Docs]
**WHAT**: [Describe what's in the code]
**WHY IT'S PROBLEMATIC**: [How it violates amplihack principles]
**SUGGESTION**: [Concrete code example or approach]
**REFERENCE**: [Link to relevant philosophy, principle, or example]
The skill can post review comments to GitHub PRs using:
gh pr comment <PR-NUMBER> -b "Review comment here"
# Or for specific file reviews:
gh pr diff <PR-NUMBER> | grep "^---" | head -1
# Then post review with specific file:line references
# OVER-ENGINEERED: 50-line config class
class ConfigManager:
def __init__(self, env_file, schema_file, validators):
self.config = load_yaml(env_file)
self.schema = load_json(schema_file)
self.validators = validators
# 40 more lines...
# SIMPLE: 5 lines
config = yaml.safe_load(open('.env.yaml'))
# OVER-ENGINEERED: Factory for single implementation
class ValidationFactory:
def create_validator(self, type):
if type == "email":
return EmailValidator()
# ... more types
# SIMPLE: Direct function
def validate_email(email):
return "@" in email and "." in email
# OVER-ENGINEERED: Base class never subclassed
class BaseRepository(ABC):
@abstractmethod
def find(self, id): pass
# ... 20 abstract methods
class UserRepository(BaseRepository):
# Forced to implement all abstract methods
# But only uses 3 of them
# SIMPLE: Direct class
class UserRepository:
def find(self, id):
return self.db.query(User).get(id)
# OVER-ENGINEERED: Complex caching for cache that's not needed
cache = LRUCache(maxsize=1000)
stats = CacheStats()
lock = threading.Lock()
# ... complex logic
# SIMPLE: None - profile first, optimize if needed
result = function(args)
When reviewing, ask these questions:
A successful PR review using this skill:
The skill produces:
Philosophy Compliance Report
Specific Recommendations
GitHub Comments (optional)
All reviews anchor in these documents:
~/.amplihack/.claude/context/PHILOSOPHY.md - Core development philosophy~/.amplihack/.claude/context/PATTERNS.md - Approved patterns and anti-patternsSpecs/ - Module specifications for architecture verification~/.amplihack/.claude/context/DISCOVERIES.md - Known issues and solutionsThis skill should evolve based on usage:
Document learnings in ~/.amplihack/.claude/context/DISCOVERIES.md.
Weekly Installs
113
Repository
GitHub Stars
39
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode105
codex99
cursor97
claude-code97
gemini-cli96
github-copilot95
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
118,000 周安装