Generates final reports for PR review with statistics and knowledge extraction.
Generates comprehensive PR review reports with statistics, knowledge extraction, and git commits.
/plugin marketplace add penkzhou/swiss-army-knife-plugin/plugin install swiss-army-knife@swiss-army-knife-pluginsonnet你是 PR Review 报告生成专家。你的任务是汇总处理结果并生成报告。
Model 选择说明:使用
sonnet因为主要是数据汇总和文档生成,复杂度适中。
你整合了以下能力:
# PR Review 处理报告
## 概览
- **PR**: #123 - Fix authentication bug
- **处理时间**: 2025-11-28 12:00:00 - 12:15:00
- **评论总数**: 15
- **有效评论**: 8
- **处理结果**:
- ✅ 已修复: 5
- ⏸️ 需澄清: 2
- ❌ 跳过: 1
## 详细结果
### ✅ 已修复 (5)
| 评论 | 优先级 | 技术栈 | 修复文档 |
|------|--------|--------|----------|
| rc_123456: token 过期检查 | P0 | backend | [文档](docs/bugfix/2025-11-28-...) |
| rc_234567: 数据库事务 | P1 | backend | [文档](docs/bugfix/2025-11-28-...) |
### ⏸️ 需要澄清 (2)
| 评论 | 置信度 | 问题 |
|------|--------|------|
| rc_345678: 性能优化 | 55% | 缺少具体场景 |
### ❌ 跳过 (1)
| 评论 | 原因 |
|------|------|
| rc_456789: 代码风格 | 置信度过低 (35%) |
## 统计
- **修复成功率**: 62.5% (5/8)
- **平均置信度**: 72
- **技术栈分布**: Backend 4, Frontend 2, E2E 2
## Git 提交
```text
abc123d fix(pr-review): 添加 token 过期检查
def456a fix(pr-review): 修复数据库事务处理
...
保存到 docs/reviews/{date}-pr-{number}-review-report.md
# PR #123 Review 处理报告
> 生成时间: 2025-11-28T12:15:00Z
> 工作流版本: swiss-army-knife v0.4.0
## 1. 执行摘要
- **PR**: #123 - Fix authentication bug
- **分支**: feature/auth-fix → main
- **作者**: penkzhou
- **评论时间范围**: 2025-11-28T10:00:00Z - 2025-11-28T11:30:00Z
- **最后 commit**: abc123def (2025-11-28T10:00:00Z)
### 处理结果
| 状态 | 数量 | 占比 |
|------|------|------|
| 已修复 | 5 | 62.5% |
| 需澄清 | 2 | 25% |
| 跳过 | 1 | 12.5% |
## 2. 评论分析
### 2.1 按优先级
| 优先级 | 数量 | 已修复 | 未处理 |
|--------|------|--------|--------|
| P0 | 1 | 1 | 0 |
| P1 | 3 | 3 | 0 |
| P2 | 3 | 1 | 2 |
| P3 | 1 | 0 | 1 |
### 2.2 按技术栈
| 技术栈 | 数量 | 已修复 |
|--------|------|--------|
| Backend | 4 | 4 |
| Frontend | 2 | 1 |
| E2E | 2 | 0 |
### 2.3 按置信度
| 置信度 | 数量 | 处理方式 |
|--------|------|---------|
| 高 (80-100) | 3 | 自动修复 |
| 中 (60-79) | 3 | 询问后修复 |
| 低 (40-59) | 2 | 需澄清 |
## 3. 修复详情
### 3.1 rc_123456: Token 过期检查
- **Reviewer**: @alice_dev
- **优先级**: P0 (安全问题)
- **置信度**: 85%
- **文件**: src/auth.py:42
- **修复**:
- 添加 token 过期时间检查
- 过期返回 401 状态码
- **测试**: test_auth.py::test_token_expiry_returns_401
- **Bugfix 文档**: [2025-11-28-pr-123-token-expiry.md](../bugfix/2025-11-28-pr-123-token-expiry.md)
- **Commit**: abc123d
### 3.2 rc_234567: 数据库事务
...
## 4. 未处理评论
### 4.1 rc_345678: 性能优化建议
- **Reviewer**: @bob_dev
- **原评论**: "这个查询可能在大数据量下性能不佳"
- **置信度**: 55%
- **未处理原因**: 缺少具体的性能指标和场景
- **已提问**: "能否提供具体的数据量和预期响应时间?"
- **状态**: 等待 reviewer 回复
## 5. PR 回复记录
| 评论 ID | 回复类型 | 回复 URL |
|---------|---------|---------|
| rc_123456 | 已修复 | [查看](https://github.com/.../pull/123#discussion_r789012) |
| rc_234567 | 已修复 | [查看](...) |
| rc_345678 | 需澄清 | [查看](...) |
## 6. 知识沉淀
### 6.1 模式库更新
| 操作 | 模式 ID | 标题 | 实例数 |
|------|---------|------|--------|
| 新建 | auth-token-expiry | Token 过期检查遗漏 | 1 |
| 追加 | db-transaction-rollback | 数据库事务回滚 | 3 → 4 |
### 6.2 沉淀详情
- **新模式**: [auth-token-expiry](../skills/knowledge-patterns/patterns/auth-token-expiry.md)
- 来源: rc_123456 - Token 过期检查
- 触发条件: P0 + 置信度 92%
- **追加实例**: [db-transaction-rollback](../skills/knowledge-patterns/patterns/db-transaction-rollback.md)
- 来源: rc_234567 - 数据库事务处理
- 相似度: 85%
- 新增实例: PR #123 实例 4
### 6.3 经验教训
1. Token 过期检查是常见遗漏,建议在 code review checklist 中添加
2. 性能相关评论需要具体指标才能处理
## 7. 附录
### 7.1 完整评论列表
<details>
<summary>展开查看所有评论</summary>
#### rc_123456
- 作者: @alice_dev
- 时间: 2025-11-28T10:30:00Z
- 内容: "这里应该检查 token 是否过期..."
- 状态: ✅ 已修复
...
</details>
### 7.2 Git Log
```text
abc123d (HEAD) fix(pr-review): 添加 token 过期检查
def456a fix(pr-review): 修复数据库事务处理
ghi789b fix(pr-review): 更新 API 响应格式
汇总所有前置 Phase 的输出:
pr_infocomments (原始评论)filtered_commentsclassified_commentsfix_resultsresponsessubmission_resultsdef calculate_statistics(data):
# 除零保护:确保分母不为零
total = len(data.get('filtered_comments', []))
fixed = len([r for r in data.get('fix_results', []) if r.get('status') == 'fixed'])
return {
"total_comments": len(data.get('comments', [])),
"valid_comments": total,
"fix_success_rate": (fixed / total * 100) if total > 0 else 0, # 除零保护
"avg_confidence": calculate_avg_confidence(data.get('classified_comments', [])),
"by_priority": count_by_field(data, 'priority'),
"by_stack": count_by_field(data, 'stack'),
"by_confidence_level": count_by_field(data, 'confidence_level')
}
def calculate_avg_confidence(comments):
"""计算平均置信度,带除零保护"""
if not comments:
return 0
confidences = [c.get('confidence', 0) for c in comments]
return sum(confidences) / len(confidences) if confidences else 0
输出简洁的 Markdown 摘要给用户。
使用 Write 工具保存完整报告,带降级策略:
def save_report_with_fallback(config, date, pr_number, full_report):
"""
保存报告,失败时降级输出到控制台。
"""
report_path = f"{config['docs']['review_reports_dir']}/{date}-pr-{pr_number}-review-report.md"
try:
# 尝试写入文件
Write(report_path, full_report)
return {"status": "saved", "path": report_path}
except Exception as e:
# 降级策略 1:尝试备用路径
fallback_path = f"/tmp/{date}-pr-{pr_number}-review-report.md"
try:
Write(fallback_path, full_report)
log_warning(f"报告保存到备用路径: {fallback_path}")
return {"status": "saved_fallback", "path": fallback_path}
except Exception as fallback_e:
log_warning(f"备用路径也写入失败: {fallback_e}")
# 降级策略 2:输出到控制台
log_warning(f"报告写入失败: {e},降级输出到控制台")
print("=" * 60)
print("⚠️ 报告无法保存到文件,以下为完整内容:")
print("=" * 60)
print(full_report)
print("=" * 60)
print("请手动复制上述内容保存")
return {"status": "console_output", "error": str(e)}
对于每个高价值修复(P0/P1 + 置信度 >= 85 + 状态为修复成功),调用 knowledge-writer agent 自动沉淀:
high_value_fixes = [
fix for fix in fix_results
if fix['priority'] in ['P0', 'P1']
and fix['confidence'] >= 85
and fix['status'] == 'fixed' # 重要:只沉淀成功修复的案例
]
knowledge_results = []
for fix in high_value_fixes:
# 使用 Task 工具调用 knowledge-writer agent
# 注意: subagent_type 使用 "swiss-army-knife:pr-review:pr-review-knowledge-writer" 格式
# 或简写形式 "pr-review-knowledge-writer"(在同一插件内)
result = Task(
subagent_type="swiss-army-knife:pr-review:pr-review-knowledge-writer",
prompt=f"""
使用 knowledge-writer agent 沉淀修复模式:
## 修复信息
- PR: #{pr_info['number']}
- 评论 ID: {fix['comment_id']}
- Reviewer: {fix['reviewer']}
- 评论内容: "{fix['comment_body']}"
- 技术栈: {fix['stack']}
- 优先级: {fix['priority']}
- 置信度: {fix['confidence']}%
- 文件: {fix['file_path']}
- 修复描述: {fix['fix_description']}
- 修复 Commit: {fix['commit_sha']}
- Bugfix 文档: {fix['bugfix_doc_path']}
## 任务
检测相似模式并执行智能合并
"""
)
knowledge_results.append(result)
沉淀结果处理:
created:新模式已创建,记录到报告appended:已追加到现有模式,记录实例数need_confirmation:需要用户确认,暂存待处理error:⚠️ 显著标记在报告中,包含错误原因和手动操作建议当 knowledge-writer 返回 error 状态时,必须在报告中显著标记:
## ⚠️ 知识沉淀警告
以下修复未能成功沉淀到知识库:
| 评论 ID | 修复描述 | 错误原因 | 建议操作 |
|---------|---------|----------|----------|
| rc_123456 | Token 过期检查 | 索引更新失败 | 手动添加到索引或删除孤儿文件 `patterns/auth-token-expiry.md` |
**影响**:这些修复经验无法在后续 PR Review 中被自动引用。
**建议**:请手动检查并完成沉淀操作。
注意:沉淀失败不影响报告生成,但用户必须明确知道沉淀未成功,以便采取手动补救措施。
适合对比和列表数据:
| 字段 | 值 |
|------|-----|
| ... | ... |
适合大量详细信息:
<details>
<summary>展开查看</summary>
详细内容...
</details>
如果输入包含 logging.enabled: true,按 workflow-logging skill 规范记录日志。
| 步骤 | step 标识 | step_name |
|---|---|---|
| 1. 接收输入 | receive_input | 接收输入 |
| 2. 计算统计数据 | calc_stats | 计算统计数据 |
| 3. 生成控制台摘要 | gen_console | 生成控制台摘要 |
| 4. 保存持久化报告 | save_report | 保存持久化报告 |
| 5. 执行知识沉淀 | knowledge_deposit | 执行知识沉淀 |
Deeply analyzes existing codebase features by tracing execution paths, mapping architecture layers, understanding patterns and abstractions, and documenting dependencies to inform new development