Skip to content

Commit bf8add6

Browse files
authored
Merge pull request #13 from juwenzhang/feat/ai-code-review
Feat/ai code review
2 parents 95f9eec + dd44f5b commit bf8add6

File tree

7 files changed

+1068
-0
lines changed

7 files changed

+1068
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
name: batch-openspec-platform-upgrades
3+
overview: 一次性创建 10 个 OpenSpec changes,覆盖用户提出的所有平台升级方向:Markdown 解析引擎、评论升级、存储优化、WebSocket 实时通知、埋点监控、新一代编辑器、无头浏览器截图、AI 智能总结、RAG+插件系统、前端子应用拆分。仅落地设计文档,不涉及代码实现。
4+
todos:
5+
- id: openspec-frontend-split
6+
content: Use [skill:openspec-propose] 创建前端子应用拆分评估的 OpenSpec change
7+
status: completed
8+
- id: openspec-md-parser
9+
content: Use [skill:openspec-propose] 创建 Markdown 解析引擎包的 OpenSpec change
10+
status: completed
11+
- id: openspec-storage-opt
12+
content: Use [skill:openspec-propose] 创建后端存储优化的 OpenSpec change
13+
status: completed
14+
dependencies:
15+
- openspec-md-parser
16+
- id: openspec-comment-upgrade
17+
content: Use [skill:openspec-propose] 创建评论系统升级的 OpenSpec change
18+
status: completed
19+
- id: openspec-websocket
20+
content: Use [skill:openspec-propose] 创建 WebSocket 实时通知的 OpenSpec change
21+
status: completed
22+
- id: openspec-analytics
23+
content: Use [skill:openspec-propose] 创建埋点+监控系统的 OpenSpec change
24+
status: completed
25+
- id: openspec-editor
26+
content: Use [skill:openspec-propose] 创建新一代文档编辑器的 OpenSpec change
27+
status: completed
28+
dependencies:
29+
- openspec-frontend-split
30+
- openspec-md-parser
31+
- id: openspec-screenshot
32+
content: Use [skill:openspec-propose] 创建无头浏览器截图服务的 OpenSpec change
33+
status: completed
34+
- id: openspec-ai-summary
35+
content: Use [skill:openspec-propose] 创建文章智能总结系统的 OpenSpec change
36+
status: completed
37+
- id: openspec-rag-plugins
38+
content: Use [skill:openspec-propose] 创建 RAG 检索增强+插件系统的 OpenSpec change
39+
status: completed
40+
dependencies:
41+
- openspec-ai-summary
42+
---
43+
44+
## Product Overview
45+
46+
用户在体验现有社区平台后,提出了一系列升级方向。核心诉求是将所有想法以 OpenSpec 设计文档形式落地到代码仓库中,即使不立即实现,也要确保思路被持久化。
47+
48+
## Core Features
49+
50+
需要为以下 9 个升级方向 + 1 个前端拆分评估创建完整的 OpenSpec 变更文档(proposal + design + tasks):
51+
52+
1. **前端子应用拆分评估** — 从 main 拆出 apps/article(文章详情+编辑)+ apps/search(搜索),评估 profile 拆分
53+
2. **Markdown 解析引擎包** (`@luhanxin/md-parser`) — 自定义 MD 解析、AST 提取、GFM 扩展、作为 packages 共享
54+
3. **后端存储优化** — 文章 content 压缩存储、新增 article_ast JSONB 列存 TOC/元数据、迁移脚本
55+
4. **评论系统升级** — 无限滚动、排序(热门/最新)、评论点赞、Markdown 评论渲染
56+
5. **WebSocket 实时通知** — Gateway 新增 /ws 端点、前端 WS client 替代轮询、NATS→WS 桥接
57+
6. **埋点+监控系统** (`@luhanxin/tracker`) — 自研 SDK、ClickHouse 存储、Grafana Dashboard、告警规则
58+
7. **新一代文档编辑器** (`@luhanxin/editor`) — 类飞书/语雀块编辑器、Yjs 协同编辑、版本历史、公开分享
59+
8. **无头浏览器截图服务** — Playwright 服务端渲染、OG 图片生成、PDF 导出、页面归档追溯
60+
9. **文章智能总结系统** — AI 摘要生成、自动标签提取、阅读时间估算、相关推荐
61+
10. **RAG 检索增强 + 插件系统** — 向量检索、开发者插件 API、平台增强市场
62+
63+
## Tech Stack
64+
65+
- 现有技术栈不变(Rust + Axum + Tonic + SeaORM + React + Garfish + Protobuf)
66+
- OpenSpec 工作流:使用 `[skill:openspec-propose]` 逐个生成变更文档
67+
- 新增基础设施组件:ClickHouse(埋点)、pgvector(RAG)、Playwright(截图服务)
68+
69+
## Implementation Approach
70+
71+
使用 `openspec-propose` skill 为每个升级方向生成完整的 proposal + design + tasks 三件套。按照依赖关系排序:
72+
73+
- 先做基础设施/拆分评估(不影响现有代码但影响后续设计)
74+
- 再做核心包和存储优化
75+
- 最后做复杂特性(编辑器、AI、RAG)
76+
77+
每个 change 的 proposal 遵循已有格式:Why / 非目标 / 与现有设计文档的关系 / What Changes。Design 文档中涉及 API 使用 Protobuf 定义,前端使用 TypeScript,后端使用 Rust。
78+
79+
此任务不涉及 UI 创建或改造,纯粹是 OpenSpec 文档生成工作。
80+
81+
## Agent Extensions
82+
83+
### Skill
84+
85+
- **openspec-propose**
86+
- Purpose: 为每个升级方向快速生成完整的 OpenSpec 变更文档(proposal + design + tasks)
87+
- Expected outcome: 10 个 OpenSpec change 目录,每个包含完整的提案、设计和技术任务拆分文档

.deepsource.toml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# DeepSource Configuration
2+
# https://deepsource.io/docs/config/
3+
4+
version = 1
5+
6+
# 全局配置
7+
test_patterns = [
8+
"tests/**",
9+
"**/*_test.*",
10+
"**/*.test.*",
11+
"**/*.spec.*"
12+
]
13+
14+
# 排除路径
15+
exclude_patterns = [
16+
"docs/**",
17+
".github/**",
18+
"node_modules/**",
19+
"dist/**",
20+
"build/**",
21+
"*.min.js",
22+
"*.min.css"
23+
]
24+
25+
# 分析器配置
26+
[[analyzers]]
27+
name = "javascript"
28+
enabled = true
29+
30+
[analyzers.meta]
31+
runtime_version = "20.x"
32+
environment = "browser"
33+
34+
[[analyzers]]
35+
name = "typescript"
36+
enabled = true
37+
38+
[analyzers.meta]
39+
runtime_version = "20.x"
40+
environment = "browser"
41+
42+
[[analyzers]]
43+
name = "rust"
44+
enabled = true
45+
46+
[analyzers.meta]
47+
rust_edition = "2024"
48+
rust_version = "1.85"
49+
50+
[[analyzers]]
51+
name = "python"
52+
enabled = true
53+
54+
[analyzers.meta]
55+
runtime_version = "3.12.x"
56+
type_checker = "mypy"
57+
58+
[[analyzers]]
59+
name = "go"
60+
enabled = true
61+
62+
[analyzers.meta]
63+
go_version = "1.22"
64+
65+
# 安全分析器
66+
[[analyzers]]
67+
name = "secrets"
68+
enabled = true
69+
70+
# Dockerfile 分析
71+
[[analyzers]]
72+
name = "dockerfile"
73+
enabled = true
74+
75+
# YAML 配置分析
76+
[[analyzers]]
77+
name = "yaml"
78+
enabled = true
79+
80+
# SQL 分析
81+
[[analyzers]]
82+
name = "sql"
83+
enabled = true

.github/AI_REVIEW_README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# 🤖 AI Code Review - 快速开始
2+
3+
## 一键配置
4+
5+
```bash
6+
# 运行配置脚本
7+
bash scripts/setup-ai-review.sh
8+
```
9+
10+
## 手动配置(3 步完成)
11+
12+
### Step 1: 获取 API Keys
13+
14+
| 服务 | 获取链接 | 免费额度 |
15+
|------|---------|---------|
16+
| **OpenAI** | https://platform.openai.com/api-keys | 无(按使用付费) |
17+
| **DeepSource** | https://deepsource.io/dashboard/ | 公开仓库免费 |
18+
| **CodeRabbit** | https://github.com/apps/coderabbitai | 200 次/月 |
19+
20+
### Step 2: 设置 GitHub Secrets
21+
22+
```bash
23+
# 方式 1: 使用 gh CLI
24+
gh secret set OPENAI_API_KEY --body "sk-..." --repo <username>/<repo>
25+
gh secret set DEEPSOURCE_DSN --body "..." --repo <username>/<repo>
26+
27+
# 方式 2: 在 GitHub 网页设置
28+
# Settings → Secrets and variables → Actions → New repository secret
29+
```
30+
31+
### Step 3: 提交配置文件
32+
33+
```bash
34+
git add .github/ .deepsource.toml
35+
git commit -m "feat(ci): add AI code review integration"
36+
git push origin master
37+
```
38+
39+
## 验证配置
40+
41+
### 创建测试 PR
42+
43+
```bash
44+
# 创建测试分支
45+
git checkout -b test-ai-review
46+
47+
# 修改一些代码
48+
echo "// test" >> src/main.rs
49+
50+
# 提交并推送
51+
git add .
52+
git commit -m "test: AI review test"
53+
git push origin test-ai-review
54+
55+
# 在 GitHub 创建 PR,观察 AI 分析结果
56+
```
57+
58+
### 查看 Actions 运行状态
59+
60+
```
61+
https://github.com/<username>/<repo>/actions/workflows/ai-code-review.yml
62+
```
63+
64+
## 成本估算
65+
66+
### 月度成本(小型项目,~100 PRs)
67+
68+
| 服务 | 使用量 | 成本 |
69+
|------|--------|------|
70+
| CodeRabbit | 100 次 | **$0**(免费额度内) |
71+
| DeepSource | 公开仓库 | **$0** |
72+
| OpenAI API | ~100K tokens | ~$0.25 |
73+
| **总计** | - | **~$0.25/月** |
74+
75+
### 中型项目(~500 PRs)
76+
77+
| 服务 | 使用量 | 成本 |
78+
|------|--------|------|
79+
| CodeRabbit | 500 次 | $12(需升级 Pro) |
80+
| DeepSource | 私有仓库 | $5 |
81+
| OpenAI API | ~500K tokens | ~$1.25 |
82+
| **总计** | - | **~$18.25/月** |
83+
84+
## 常见问题
85+
86+
### Q: 免费额度用完了怎么办?
87+
88+
**A:** 切换到以下方案:
89+
1. **DeepSource**(公开仓库永久免费)
90+
2. **GitHub Copilot**(企业订阅 $19/月)
91+
3. **自建 Ollama + Qwen**(完全免费,需本地部署)
92+
93+
### Q: 分析速度太慢?
94+
95+
**A:**`.github/workflows/ai-code-review.yml` 中调整:
96+
97+
```yaml
98+
with:
99+
openai_light_model: gpt-4o-mini # 快速模型
100+
openai_timeout_ms: 30000 # 减少超时
101+
```
102+
103+
### Q: 如何跳过某些文件的分析?
104+
105+
**A:** 在 `paths-ignore` 中添加:
106+
107+
```yaml
108+
paths-ignore:
109+
- '**.md'
110+
- 'docs/**'
111+
- '**/*.test.*'
112+
```
113+
114+
## 更多资源
115+
116+
- 📚 [完整配置指南](./docs/tech/10-github-ai-integration.md)
117+
- 🔧 [DeepSource 配置](./.deepsource.toml)
118+
- 🚀 [工作流定义](./.github/workflows/ai-code-review.yml)
119+
120+
---
121+
122+
**💡 提示**:首次使用建议先用测试分支验证配置是否正确,避免影响主分支开发流程。

0 commit comments

Comments
 (0)