@alibaba-group/open-code-review 1.2.4 → 1.2.5
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/CONTRIBUTING.ko-KR.md +223 -0
- package/CONTRIBUTING.md +6 -2
- package/README.ja-JP.md +87 -2
- package/README.ko-KR.md +421 -0
- package/README.md +87 -2
- package/README.zh-CN.md +87 -2
- package/package.json +1 -1
- package/plugins/open-code-review/.codex-plugin/plugin.json +34 -0
- package/plugins/open-code-review/CODEX.ko-KR.md +108 -0
- package/plugins/open-code-review/skills/open-code-review/SKILL.md +236 -0
package/README.zh-CN.md
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/@alibaba-group/open-code-review"><img alt="npm" src="https://img.shields.io/npm/v/@alibaba-group/open-code-review?style=flat-square" /></a>
|
|
9
9
|
<a href="https://github.com/alibaba/open-code-review/actions/workflows/release.yml"><img alt="Build status" src="https://img.shields.io/github/actions/workflow/status/alibaba/open-code-review/release.yml?style=flat-square" /></a>
|
|
10
|
+
<a href="https://goreportcard.com/report/github.com/alibaba/open-code-review"><img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/alibaba/open-code-review?style=flat-square" /></a>
|
|
10
11
|
<a href="https://github.com/alibaba/open-code-review/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/alibaba/open-code-review?style=flat-square" /></a>
|
|
11
12
|
</p>
|
|
12
13
|
<p align="center">
|
|
13
|
-
<a href="README.md">English</a> | 简体中文 | <a href="README.ja-JP.md">日本語</a>
|
|
14
|
+
<a href="README.md">English</a> | 简体中文 | <a href="README.ja-JP.md">日本語</a> | <a href="README.ko-KR.md">한국어</a>
|
|
14
15
|
</p>
|
|
15
16
|
|
|
16
17
|
---
|
|
@@ -116,18 +117,22 @@ sudo cp dist/opencodereview /usr/local/bin/ocr
|
|
|
116
117
|
# 方式 A:交互式配置
|
|
117
118
|
ocr config set llm.url https://api.anthropic.com/v1/messages
|
|
118
119
|
ocr config set llm.auth_token your-api-key-here
|
|
120
|
+
ocr config set llm.auth_header x-api-key
|
|
119
121
|
ocr config set llm.model claude-opus-4-6
|
|
120
122
|
ocr config set llm.use_anthropic true
|
|
121
123
|
|
|
122
124
|
# 方式 B:环境变量(优先级最高)
|
|
123
125
|
export OCR_LLM_URL=https://api.anthropic.com/v1/messages
|
|
124
126
|
export OCR_LLM_TOKEN=your-api-key-here
|
|
127
|
+
export OCR_LLM_AUTH_HEADER=x-api-key
|
|
125
128
|
export OCR_LLM_MODEL=claude-opus-4-6
|
|
126
129
|
export OCR_USE_ANTHROPIC=true
|
|
127
130
|
```
|
|
128
131
|
|
|
129
132
|
配置存储于 `~/.opencodereview/config.json`。
|
|
130
133
|
|
|
134
|
+
对于 Anthropic,标准 `sk-ant-*` API key 使用 `x-api-key`;OAuth token 使用 `authorization`。如果未配置 `llm.auth_header` / `OCR_LLM_AUTH_HEADER`,OCR 会保留现有的 `authorization` bearer-token 行为。
|
|
135
|
+
|
|
131
136
|
同时兼容了 Claude Code 环境变量(`ANTHROPIC_BASE_URL`、`ANTHROPIC_AUTH_TOKEN`、`ANTHROPIC_MODEL`),并解析 `~/.zshrc` / `~/.bashrc` 中的相关导出。
|
|
132
137
|
|
|
133
138
|
> **CC-Switch 用户特别提醒**:如果你使用 [CC-Switch](https://github.com/farion1231/cc-switch) 并开启了[路由服务](https://www.ccswitch.io/zh/docs?section=proxy&item=service),可以将 `llm.url` 配置成 CC-Switch 启动的代理地址,无需额外配置:
|
|
@@ -183,7 +188,43 @@ npx skills add alibaba/open-code-review --skill open-code-review
|
|
|
183
188
|
|
|
184
189
|
此命令注册 `/open-code-review:review` 斜杠命令,运行 OCR 并自动过滤和修复问题。
|
|
185
190
|
|
|
186
|
-
####
|
|
191
|
+
#### 方式三:作为 Codex Plugin 安装
|
|
192
|
+
|
|
193
|
+
对于本地 Codex,可以从此仓库安装 Open Code Review plugin:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
codex plugin marketplace add alibaba/open-code-review
|
|
197
|
+
codex
|
|
198
|
+
/plugins
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
对于本地 checkout 或 fork:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
codex plugin marketplace add .
|
|
205
|
+
codex
|
|
206
|
+
/plugins
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
安装并启用 `Open Code Review` 后,启动新的 Codex thread 并显式调用:
|
|
210
|
+
|
|
211
|
+
```text
|
|
212
|
+
@Open Code Review review my current changes
|
|
213
|
+
@Open Code Review review this branch against main
|
|
214
|
+
@Open Code Review review and fix high-confidence issues
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
这会注册一个 Codex skill,用于运行本地 OCR CLI:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
ocr review --audience agent
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
此集成不会改变 OCR 的内部 LLM backend,也不需要为 Codex 配置 OpenAI Responses API endpoint。OCR 本身仍需要按照 CLI setup 部分安装并配置 `ocr` CLI。
|
|
224
|
+
|
|
225
|
+
韩文指南:[`plugins/open-code-review/CODEX.ko-KR.md`](plugins/open-code-review/CODEX.ko-KR.md)
|
|
226
|
+
|
|
227
|
+
#### 方式四:直接复制命令文件
|
|
187
228
|
|
|
188
229
|
如果不想使用任何包管理器,可以直接复制命令文件,在 Claude Code 中使用 `/open-code-review` 斜杠命令。
|
|
189
230
|
|
|
@@ -316,6 +357,48 @@ OCR 通过四层优先级链解析评审规则。每层采用首次匹配原则
|
|
|
316
357
|
- 在每一层内,规则按声明顺序评估 —— 首次匹配生效。
|
|
317
358
|
- 如果规则文件不存在,将被静默跳过。
|
|
318
359
|
|
|
360
|
+
### 路径过滤
|
|
361
|
+
|
|
362
|
+
规则文件同时支持 `include` 和 `exclude` 字段,用于控制哪些文件进入审查范围:
|
|
363
|
+
|
|
364
|
+
```json
|
|
365
|
+
{
|
|
366
|
+
"rules": [
|
|
367
|
+
{"path": "**/*.java", "rule": "检查空值安全"}
|
|
368
|
+
],
|
|
369
|
+
"include": ["src/main/**/*.java", "lib/**/*.kt"],
|
|
370
|
+
"exclude": ["**/generated/**", "vendor/**"]
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**过滤决策优先级(从高到低):**
|
|
375
|
+
|
|
376
|
+
| 步骤 | 条件 | 结果 |
|
|
377
|
+
|------|------|------|
|
|
378
|
+
| 1 | 文件为二进制文件 | 排除 |
|
|
379
|
+
| 2 | 路径匹配用户 `exclude` 模式 | 排除 |
|
|
380
|
+
| 3 | 文件扩展名不在支持列表中 | 排除 |
|
|
381
|
+
| 4 | 配置了 `include` 且路径匹配 | **纳入审查**(跳过步骤 5) |
|
|
382
|
+
| 5 | 路径匹配内置默认排除模式(测试文件等) | 排除 |
|
|
383
|
+
| 6 | 以上均不满足 | 纳入审查 |
|
|
384
|
+
|
|
385
|
+
**生效逻辑:**
|
|
386
|
+
|
|
387
|
+
- `include` 和 `exclude` 遵循与评审规则相同的优先级链(`--rule` > 项目配置 > 全局配置),取**最高优先级中配置了 include/exclude 的那一层**整体生效,不会跨层合并。
|
|
388
|
+
- `exclude` 始终优先于 `include` —— 同时匹配两者的文件会被排除。
|
|
389
|
+
- `include` 的作用是**绕过内置默认排除模式**(如测试文件),而非限制审查范围 —— 未匹配 `include` 的文件仍会正常进入后续的默认过滤判断。
|
|
390
|
+
- 模式语法:支持 `**` 递归匹配、`*` 单级匹配和 `{a,b}` 大括号展开,匹配时不区分大小写。
|
|
391
|
+
|
|
392
|
+
**内置默认排除模式**(用于过滤测试文件等,可通过 `include` 覆盖):
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
**/*_test.go, **/*Test.java, **/*Tests.java, **/*_test.rs,
|
|
396
|
+
**/*.test.{js,jsx,ts,tsx}, **/*.spec.{js,jsx,ts,tsx}, **/__tests__/**,
|
|
397
|
+
**/src/test/java/**/*.java, **/src/test/**/*.kt,
|
|
398
|
+
**/test/**/*_test.py, **/tests/**/*_test.py, **/*_test.py,
|
|
399
|
+
**/*_spec.rb, **/spec/**/*_spec.rb, **/oh_modules/**
|
|
400
|
+
```
|
|
401
|
+
|
|
319
402
|
## 配置参考
|
|
320
403
|
|
|
321
404
|
配置文件:`~/.opencodereview/config.json`
|
|
@@ -324,6 +407,7 @@ OCR 通过四层优先级链解析评审规则。每层采用首次匹配原则
|
|
|
324
407
|
|----|------|------|
|
|
325
408
|
| `llm.url` | string | `https://api.openai.com/v1/chat/completions` |
|
|
326
409
|
| `llm.auth_token` | string | `sk-xxxxxxx` |
|
|
410
|
+
| `llm.auth_header` | string | 仅 Anthropic:`x-api-key` \| `authorization` |
|
|
327
411
|
| `llm.model` | string | `claude-opus-4-6` |
|
|
328
412
|
| `llm.use_anthropic` | boolean | `true` \| `false` |
|
|
329
413
|
| `language` | string | `English` \| `Chinese`(默认:Chinese) |
|
|
@@ -340,6 +424,7 @@ OCR 通过四层优先级链解析评审规则。每层采用首次匹配原则
|
|
|
340
424
|
|------|------|
|
|
341
425
|
| `OCR_LLM_URL` | LLM API 端点 URL |
|
|
342
426
|
| `OCR_LLM_TOKEN` | API 密钥 / 认证令牌 |
|
|
427
|
+
| `OCR_LLM_AUTH_HEADER` | Anthropic 认证头(`x-api-key` 或 `authorization`) |
|
|
343
428
|
| `OCR_LLM_MODEL` | 模型名称 |
|
|
344
429
|
| `OCR_USE_ANTHROPIC` | `true` = Anthropic,`false` = OpenAI |
|
|
345
430
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "open-code-review",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Use Alibaba Open Code Review from local Codex.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Alibaba"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/alibaba/open-code-review",
|
|
9
|
+
"repository": "https://github.com/alibaba/open-code-review",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"code-review",
|
|
13
|
+
"codex",
|
|
14
|
+
"ocr",
|
|
15
|
+
"open-code-review"
|
|
16
|
+
],
|
|
17
|
+
"skills": "./skills/",
|
|
18
|
+
"interface": {
|
|
19
|
+
"displayName": "Open Code Review",
|
|
20
|
+
"shortDescription": "Run structured code reviews from local Codex.",
|
|
21
|
+
"longDescription": "Adds a Codex skill that invokes the local Open Code Review CLI to review Git workspace changes, commits, and branch comparisons.",
|
|
22
|
+
"developerName": "Alibaba",
|
|
23
|
+
"category": "Developer Tools",
|
|
24
|
+
"capabilities": [
|
|
25
|
+
"Read"
|
|
26
|
+
],
|
|
27
|
+
"websiteURL": "https://github.com/alibaba/open-code-review",
|
|
28
|
+
"defaultPrompt": [
|
|
29
|
+
"Use Open Code Review to review my current changes.",
|
|
30
|
+
"Use Open Code Review to review this branch against main.",
|
|
31
|
+
"Use Open Code Review to review and fix high-confidence issues."
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Open Code Review Codex 플러그인 사용법
|
|
2
|
+
|
|
3
|
+
이 문서는 로컬 Codex에서 Alibaba Open Code Review를 사용하는 방법을 설명합니다.
|
|
4
|
+
|
|
5
|
+
## 개요
|
|
6
|
+
|
|
7
|
+
이 플러그인은 Open Code Review를 Codex 내부 LLM backend로 바꾸지 않습니다. Codex에서 로컬 `ocr` CLI를 호출할 수 있도록 skill을 제공하는 통합입니다.
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
Codex
|
|
11
|
+
└─ Open Code Review plugin
|
|
12
|
+
└─ ocr review --audience agent
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 사전 준비
|
|
16
|
+
|
|
17
|
+
`ocr` CLI가 설치되어 있어야 합니다.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @alibaba-group/open-code-review
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
설치 확인:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
command -v ocr
|
|
27
|
+
ocr version
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
OCR 자체의 LLM 설정도 필요합니다.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
ocr llm test
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
이 명령이 실패하면 Codex 플러그인 설치와 별개로 OCR의 LLM 설정을 먼저 완료해야 합니다.
|
|
37
|
+
|
|
38
|
+
## Codex에서 설치
|
|
39
|
+
|
|
40
|
+
Codex에서 이 repo를 marketplace로 추가합니다.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
codex plugin marketplace add alibaba/open-code-review
|
|
44
|
+
codex
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Codex 안에서 `/plugins`를 열고 `Open Code Review`를 설치 및 활성화합니다.
|
|
48
|
+
|
|
49
|
+
로컬 checkout 또는 fork에서 테스트할 때는 다음을 사용할 수 있습니다.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
codex plugin marketplace add .
|
|
53
|
+
codex
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 사용 예시
|
|
57
|
+
|
|
58
|
+
새 Codex thread에서 다음처럼 요청합니다.
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
@Open Code Review review my current changes
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
브랜치 비교:
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
@Open Code Review review this branch against main
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
검토 후 안전한 항목만 수정:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
@Open Code Review review and fix high-confidence issues
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 내부적으로 실행되는 명령
|
|
77
|
+
|
|
78
|
+
현재 workspace 변경사항 검토:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
ocr review --audience agent
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
특정 commit 검토:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ocr review --audience agent --commit <sha>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
브랜치 비교:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
ocr review --audience agent --from <base-ref> --to <head-ref>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
미리보기:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
ocr review --preview
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 주의사항
|
|
103
|
+
|
|
104
|
+
- 이 플러그인은 OpenAI Responses API endpoint를 설정하지 않습니다.
|
|
105
|
+
- 이 플러그인은 `OPENAI_API_KEY`나 `gpt-5.1-codex-max` 설정을 요구하지 않습니다.
|
|
106
|
+
- OCR 자체는 별도의 LLM 설정이 필요합니다.
|
|
107
|
+
- 파일 수정은 사용자가 명시적으로 요청한 경우에만 수행합니다.
|
|
108
|
+
- commit 생성은 사용자가 명시적으로 요청한 경우에만 수행합니다.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: open-code-review
|
|
3
|
+
description: >
|
|
4
|
+
Performs AI-powered code review on Git changes using the `ocr` CLI from
|
|
5
|
+
alibaba/open-code-review. Use when the user asks to review code, review
|
|
6
|
+
a pull request, review staged/unstaged changes, review a commit, or
|
|
7
|
+
compare branches for code quality issues. Produces line-level review
|
|
8
|
+
comments and can automatically apply fixes when requested. With appropriate
|
|
9
|
+
review rules, can detect various types of issues including bugs, security
|
|
10
|
+
vulnerabilities, performance problems, and code quality concerns.
|
|
11
|
+
license: Apache-2.0
|
|
12
|
+
compatibility: >
|
|
13
|
+
Requires the `ocr` CLI installed (via `npm install -g
|
|
14
|
+
@alibaba-group/open-code-review` or GitHub release binary). Requires a
|
|
15
|
+
configured LLM (Anthropic or OpenAI-compatible) before first run.
|
|
16
|
+
metadata:
|
|
17
|
+
author: alibaba
|
|
18
|
+
homepage: https://github.com/alibaba/open-code-review
|
|
19
|
+
version: "1.0.0"
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# Open Code Review
|
|
23
|
+
|
|
24
|
+
This Codex plugin skill intentionally mirrors the canonical skill at
|
|
25
|
+
`skills/open-code-review/SKILL.md`. Keep both files synchronized when updating
|
|
26
|
+
OCR agent instructions; a symlink is avoided because plugin installs may only
|
|
27
|
+
materialize the plugin subtree.
|
|
28
|
+
|
|
29
|
+
A skill for invoking [open-code-review](https://github.com/alibaba/open-code-review) (`ocr`) — an open-source AI code review CLI that reads Git diffs and generates structured, line-level review comments.
|
|
30
|
+
|
|
31
|
+
## Prerequisites check
|
|
32
|
+
|
|
33
|
+
Before starting a review, verify the environment:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# 1. Check the CLI is installed
|
|
37
|
+
which ocr || echo "NOT INSTALLED"
|
|
38
|
+
|
|
39
|
+
# 2. Verify LLM connectivity
|
|
40
|
+
ocr llm test
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If `ocr` is not installed, install it first:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install -g @alibaba-group/open-code-review
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If `ocr llm test` fails, the user must configure an LLM. Guide them with one of these options:
|
|
50
|
+
|
|
51
|
+
**Option A — Environment variables (highest priority, recommended for CI):**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
export OCR_LLM_URL=https://api.anthropic.com/v1/messages
|
|
55
|
+
export OCR_LLM_TOKEN=<api-key>
|
|
56
|
+
export OCR_LLM_MODEL=claude-opus-4-6
|
|
57
|
+
export OCR_USE_ANTHROPIC=true
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Option B — Persistent config:**
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
ocr config set llm.url https://api.anthropic.com/v1/messages
|
|
64
|
+
ocr config set llm.auth_token <api-key>
|
|
65
|
+
ocr config set llm.model claude-opus-4-6
|
|
66
|
+
ocr config set llm.use_anthropic true
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Stop here and ask the user to provide credentials — never invent or hardcode API keys.
|
|
70
|
+
|
|
71
|
+
## Workflow
|
|
72
|
+
|
|
73
|
+
### Step 1: Gather Business Context
|
|
74
|
+
|
|
75
|
+
Analyze the review target (commits, branch, or changes) to extract concise business context. Pass this context via `--background` to improve review quality.
|
|
76
|
+
|
|
77
|
+
### Step 2: Run Code Review
|
|
78
|
+
|
|
79
|
+
Run the OCR command with appropriate flags. **Always pass business context via `--background`** when available:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
ocr review --audience agent --background "business context here" [user-args]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Argument handling:**
|
|
86
|
+
|
|
87
|
+
- **Background context** (RECOMMENDED): use `--background "context"` or `-b "context"` to provide business context for better review quality
|
|
88
|
+
- **Default** (no user arguments): reviews staged, unstaged, and untracked changes (workspace mode)
|
|
89
|
+
- **Specific commit**: use `--commit` or `-c` to review a single commit against its parent
|
|
90
|
+
- **Branch comparison**: use `--from <ref>` and `--to <ref>` to review diff between two refs
|
|
91
|
+
- **Timeout**: default timeout is 10 minutes per file; adjust with `--timeout <minutes>`
|
|
92
|
+
- **Concurrency**: default concurrency is 8 file workers; reduce with `--concurrency <n>` if rate limits are hit
|
|
93
|
+
- **Preview mode**: use `--preview` or `-p` to preview which files will be reviewed without running the LLM
|
|
94
|
+
- **Installation**: if `ocr` command is not found, install it by running `npm i -g @alibaba-group/open-code-review`
|
|
95
|
+
|
|
96
|
+
**Common invocation patterns:**
|
|
97
|
+
|
|
98
|
+
| User says | Command to run |
|
|
99
|
+
|-----------|---------------|
|
|
100
|
+
| "review my changes" / "review the working copy" | `ocr review --audience agent -b "context"` |
|
|
101
|
+
| "review this PR" / "review feature branch" | `ocr review --audience agent -b "context" --from main --to <branch>` |
|
|
102
|
+
| "review commit abc123" | `ocr review --audience agent -b "context" --commit abc123` |
|
|
103
|
+
| "what would be reviewed?" (dry-run) | `ocr review --preview` |
|
|
104
|
+
|
|
105
|
+
**Output mode:**
|
|
106
|
+
|
|
107
|
+
- Always use `--audience agent` to suppress progress UI and emit only the final summary
|
|
108
|
+
|
|
109
|
+
### Step 3: Classify and Report
|
|
110
|
+
|
|
111
|
+
For each comment from the review output, classify by priority and report all issues to the user:
|
|
112
|
+
|
|
113
|
+
- **High**: Obvious bugs, security issues, clear mistakes, or well-founded suggestions with precise fix proposals
|
|
114
|
+
- **Medium**: Reasonable concerns but context-dependent, style/performance suggestions, or fixes that require manual implementation
|
|
115
|
+
- **Low**: Likely false positives, lacking sufficient context, nitpicks, or meaningless suggestions
|
|
116
|
+
|
|
117
|
+
Report all comments grouped by priority level.
|
|
118
|
+
|
|
119
|
+
### Step 4: Fix
|
|
120
|
+
|
|
121
|
+
Before applying fixes, check whether the user requested automatic fixes:
|
|
122
|
+
|
|
123
|
+
- If the user explicitly requested "review and fix" or similar, proceed with automatic fixes
|
|
124
|
+
- If the user only requested "review" without fix intent, ask for permission before applying any changes
|
|
125
|
+
|
|
126
|
+
When fixing issues and suggestions:
|
|
127
|
+
|
|
128
|
+
- Focus on High and Medium priority items
|
|
129
|
+
- Apply fixes directly to the code when safe and well-defined
|
|
130
|
+
- For complex fixes requiring manual intervention, clearly describe what needs to be done
|
|
131
|
+
- Always verify fixes with the user before committing
|
|
132
|
+
|
|
133
|
+
## Output Format
|
|
134
|
+
|
|
135
|
+
Each comment contains:
|
|
136
|
+
|
|
137
|
+
- `path`: File path
|
|
138
|
+
- `content`: Review comment text
|
|
139
|
+
- `start_line` / `end_line`: Line range (both 0 means positioning failed)
|
|
140
|
+
- `suggestion_code`: Optional fix suggestion
|
|
141
|
+
- `existing_code`: Optional original code snippet
|
|
142
|
+
- `thinking`: Optional LLM reasoning process
|
|
143
|
+
|
|
144
|
+
After filtering comments by priority, present results using this template:
|
|
145
|
+
|
|
146
|
+
```markdown
|
|
147
|
+
## Code Review Results
|
|
148
|
+
|
|
149
|
+
**Files reviewed**: N
|
|
150
|
+
**Issues found**: X high priority / Y medium priority
|
|
151
|
+
|
|
152
|
+
### High Priority
|
|
153
|
+
|
|
154
|
+
- **`path/to/file.java:42`** — Brief description
|
|
155
|
+
> Recommendation: How to fix
|
|
156
|
+
|
|
157
|
+
### Medium Priority
|
|
158
|
+
|
|
159
|
+
- **`path/to/file.ts:88`** — Brief description
|
|
160
|
+
> Recommendation: How to fix (if applicable)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
If the review found no issues after filtering, simply state: "Review complete — no issues found in N files."
|
|
164
|
+
|
|
165
|
+
**Priority classification:**
|
|
166
|
+
|
|
167
|
+
- **High**: Obvious bugs, security issues, clear mistakes, or well-founded suggestions with precise fix proposals
|
|
168
|
+
- **Medium**: Reasonable concerns but context-dependent, style/performance suggestions, or fixes that require manual implementation
|
|
169
|
+
- **Low**: Discarded silently (likely false positives, lacking context, nitpicks, or meaningless suggestions)
|
|
170
|
+
|
|
171
|
+
**Handling mispositioned comments:**
|
|
172
|
+
|
|
173
|
+
When `start_line` and `end_line` are both `0`, the comment failed to locate the exact position in the file. In such cases:
|
|
174
|
+
|
|
175
|
+
1. Read the comment content to understand the issue
|
|
176
|
+
2. Examine the target file mentioned in the comment
|
|
177
|
+
3. Identify the relevant code section based on the comment's context
|
|
178
|
+
4. Apply the fix or suggestion to the correct location
|
|
179
|
+
|
|
180
|
+
## Custom Review Rules
|
|
181
|
+
|
|
182
|
+
If the user wants project-specific rules, OCR resolves them in this priority order:
|
|
183
|
+
|
|
184
|
+
1. `--rule <path>` flag (highest)
|
|
185
|
+
2. `<repo>/.opencodereview/rule.json`
|
|
186
|
+
3. `~/.opencodereview/rule.json`
|
|
187
|
+
4. Built-in system defaults (lowest)
|
|
188
|
+
|
|
189
|
+
Rule file format:
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"rules": [
|
|
194
|
+
{
|
|
195
|
+
"path": "**/*.java",
|
|
196
|
+
"rule": "All new methods must validate required parameters for null"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"path": "**/*mapper*.xml",
|
|
200
|
+
"rule": "Check SQL for injection risks and missing closing tags"
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
To preview which rule applies to a file before reviewing:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
ocr rules check src/main/java/com/example/Foo.java
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Gotchas
|
|
213
|
+
|
|
214
|
+
- **LLM must be configured first** — `ocr review` will fail loudly if no LLM is reachable. Always run `ocr llm test` before the first review.
|
|
215
|
+
- **Working directory matters** — `ocr review` operates on the Git repo at the current directory. Use `--repo /path/to/repo` to run from elsewhere.
|
|
216
|
+
- **Untracked files are reviewed in workspace mode** — running bare `ocr review` includes staged, unstaged, *and* untracked changes. Stage selectively if you want narrower scope.
|
|
217
|
+
- **Large diffs may hit token limits** — files with very large diffs may be truncated. The default `MAX_TOKENS` is 58888 per request.
|
|
218
|
+
- **Plan phase triggers at 50 lines** — diffs exceeding 50 changed lines run an extra risk-analysis phase before main review. This adds latency but improves quality.
|
|
219
|
+
- **Don't pass `--audience human`** — it streams progress UI that pollutes output. Always use `--audience agent`.
|
|
220
|
+
- **Comment language follows config** — set `language` config to `English` or `Chinese` (default: Chinese) to control review comment language.
|
|
221
|
+
|
|
222
|
+
## Validation
|
|
223
|
+
|
|
224
|
+
After the review completes, verify success by checking:
|
|
225
|
+
|
|
226
|
+
1. The command exited with code 0
|
|
227
|
+
2. Comments were generated (or "No comments generated" message appears)
|
|
228
|
+
3. Warnings (if any) are displayed in stderr
|
|
229
|
+
|
|
230
|
+
If errors occurred, check the stderr warnings for details about which files failed and why.
|
|
231
|
+
|
|
232
|
+
## References
|
|
233
|
+
|
|
234
|
+
- Full docs: https://github.com/alibaba/open-code-review
|
|
235
|
+
- NPM package: https://www.npmjs.com/package/@alibaba-group/open-code-review
|
|
236
|
+
- Issue tracker: https://github.com/alibaba/open-code-review/issues
|