@spaceflow/review 0.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +533 -0
- package/README.md +124 -0
- package/dist/551.js +9 -0
- package/dist/index.js +5704 -0
- package/package.json +50 -0
- package/src/README.md +364 -0
- package/src/__mocks__/@anthropic-ai/claude-agent-sdk.js +3 -0
- package/src/__mocks__/json-stringify-pretty-compact.ts +4 -0
- package/src/deletion-impact.service.spec.ts +974 -0
- package/src/deletion-impact.service.ts +879 -0
- package/src/dto/mcp.dto.ts +42 -0
- package/src/index.ts +32 -0
- package/src/issue-verify.service.spec.ts +460 -0
- package/src/issue-verify.service.ts +309 -0
- package/src/locales/en/review.json +31 -0
- package/src/locales/index.ts +11 -0
- package/src/locales/zh-cn/review.json +31 -0
- package/src/parse-title-options.spec.ts +251 -0
- package/src/parse-title-options.ts +185 -0
- package/src/review-report/formatters/deletion-impact.formatter.ts +144 -0
- package/src/review-report/formatters/index.ts +4 -0
- package/src/review-report/formatters/json.formatter.ts +8 -0
- package/src/review-report/formatters/markdown.formatter.ts +291 -0
- package/src/review-report/formatters/terminal.formatter.ts +130 -0
- package/src/review-report/index.ts +4 -0
- package/src/review-report/review-report.module.ts +8 -0
- package/src/review-report/review-report.service.ts +58 -0
- package/src/review-report/types.ts +26 -0
- package/src/review-spec/index.ts +3 -0
- package/src/review-spec/review-spec.module.ts +10 -0
- package/src/review-spec/review-spec.service.spec.ts +1543 -0
- package/src/review-spec/review-spec.service.ts +902 -0
- package/src/review-spec/types.ts +143 -0
- package/src/review.command.ts +244 -0
- package/src/review.config.ts +58 -0
- package/src/review.mcp.ts +184 -0
- package/src/review.module.ts +52 -0
- package/src/review.service.spec.ts +3007 -0
- package/src/review.service.ts +2603 -0
- package/tsconfig.json +8 -0
- package/vitest.config.ts +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @spaceflow/review
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@spaceflow/review)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
> Spaceflow AI 代码审查扩展,使用 LLM 对 PR 代码进行自动审查。支持 OpenAI、Claude Code、Gemini 等多种 LLM 模式。
|
|
7
|
+
|
|
8
|
+
## 安装
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm spaceflow install @spaceflow/review
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 功能特性
|
|
15
|
+
|
|
16
|
+
- **多 LLM 支持** — OpenAI、Claude Code、Gemini 可选
|
|
17
|
+
- **行级评论** — 在 PR 中精确定位问题代码行
|
|
18
|
+
- **增量审查** — 多次运行时自动去重,追踪问题修复状态
|
|
19
|
+
- **删除代码分析** — 评估删除代码可能带来的风险
|
|
20
|
+
- **AI 生成 PR 描述** — 自动总结 PR 功能变更
|
|
21
|
+
- **审查规范** — 支持自定义 Markdown 格式的审查规则
|
|
22
|
+
- **远程规范引用** — 支持从远程仓库 URL 拉取审查规范
|
|
23
|
+
|
|
24
|
+
## 使用
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 审查 PR
|
|
28
|
+
spaceflow review -p 123 -l openai
|
|
29
|
+
|
|
30
|
+
# 审查两个分支之间的差异
|
|
31
|
+
spaceflow review -b main --head feature/xxx -l openai
|
|
32
|
+
|
|
33
|
+
# 仅审查指定文件
|
|
34
|
+
spaceflow review -f src/app.ts -l openai
|
|
35
|
+
|
|
36
|
+
# 详细输出(含提示词)
|
|
37
|
+
spaceflow review -p 123 -l openai -vv
|
|
38
|
+
|
|
39
|
+
# 仅分析删除代码
|
|
40
|
+
spaceflow review -p 123 --deletion-only -l openai
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 命令行参数
|
|
44
|
+
|
|
45
|
+
| 参数 | 简写 | 说明 |
|
|
46
|
+
| --------------------------------- | ---- | ----------------------------------------------- |
|
|
47
|
+
| `--pr-number <number>` | `-p` | PR 编号 |
|
|
48
|
+
| `--base <ref>` | `-b` | 基准分支/tag |
|
|
49
|
+
| `--head <ref>` | | 目标分支/tag |
|
|
50
|
+
| `--llm-mode <mode>` | `-l` | LLM 模式(`openai` / `claude-code` / `gemini`) |
|
|
51
|
+
| `--files <files...>` | `-f` | 仅审查指定文件 |
|
|
52
|
+
| `--commits <commits...>` | | 仅审查指定 commits |
|
|
53
|
+
| `--includes <patterns...>` | `-i` | 文件 glob 过滤模式 |
|
|
54
|
+
| `--verbose [level]` | `-v` | 详细输出(1: 过程日志,2: 含提示词) |
|
|
55
|
+
| `--dry-run` | `-d` | 仅打印将要执行的操作 |
|
|
56
|
+
| `--ci` | `-c` | 在 CI 环境中运行 |
|
|
57
|
+
| `--verify-fixes` | | 验证历史问题是否已修复 |
|
|
58
|
+
| `--no-verify-fixes` | | 禁用历史问题验证 |
|
|
59
|
+
| `--analyze-deletions` | | 分析删除代码影响 |
|
|
60
|
+
| `--deletion-only` | | 仅执行删除代码分析 |
|
|
61
|
+
| `--deletion-analysis-mode <mode>` | | 删除分析模式(`openai` / `claude-code`) |
|
|
62
|
+
| `--generate-description` | | 使用 AI 生成 PR 功能描述 |
|
|
63
|
+
| `--output-format <format>` | `-o` | 输出格式(`markdown` / `terminal` / `json`) |
|
|
64
|
+
|
|
65
|
+
## 配置
|
|
66
|
+
|
|
67
|
+
在 `spaceflow.json` 中配置 `review` 字段:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"review": {
|
|
72
|
+
"includes": ["*/**/*.ts", "!*/**/*.spec.*", "!*/**/*.config.*"],
|
|
73
|
+
"references": ["./references"],
|
|
74
|
+
"generateDescription": true,
|
|
75
|
+
"lineComments": true,
|
|
76
|
+
"verifyFixes": true,
|
|
77
|
+
"analyzeDeletions": false,
|
|
78
|
+
"concurrency": 5,
|
|
79
|
+
"retries": 3,
|
|
80
|
+
"retryDelay": 1000
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## PR 标题参数
|
|
86
|
+
|
|
87
|
+
支持在 PR 标题末尾添加参数覆盖默认配置:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
feat: 添加新功能 [/ai-review -l openai -v 2]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## CI 工作流示例
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
name: AI Review
|
|
97
|
+
on:
|
|
98
|
+
pull_request:
|
|
99
|
+
types: [opened, synchronize]
|
|
100
|
+
|
|
101
|
+
jobs:
|
|
102
|
+
review:
|
|
103
|
+
runs-on: ubuntu-latest
|
|
104
|
+
steps:
|
|
105
|
+
- uses: actions/checkout@v4
|
|
106
|
+
- run: pnpm spaceflow review --ci -l openai
|
|
107
|
+
env:
|
|
108
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
109
|
+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 环境变量
|
|
113
|
+
|
|
114
|
+
| 变量 | 说明 |
|
|
115
|
+
| ------------------- | ----------------------------- |
|
|
116
|
+
| `GITHUB_TOKEN` | GitHub API Token |
|
|
117
|
+
| `GITHUB_REPOSITORY` | 仓库名称(`owner/repo` 格式) |
|
|
118
|
+
| `OPENAI_BASE_URL` | OpenAI API 地址 |
|
|
119
|
+
| `OPENAI_API_KEY` | OpenAI API Key |
|
|
120
|
+
| `OPENAI_MODEL` | OpenAI 模型名称 |
|
|
121
|
+
|
|
122
|
+
## 许可证
|
|
123
|
+
|
|
124
|
+
[MIT](../../LICENSE)
|