@alibaba-group/open-code-review 1.3.14 → 1.3.19

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.
@@ -1,35 +0,0 @@
1
- ---
2
- description: Run OpenCodeReview (OCR) to review code changes and autonomously apply fixes.
3
- ---
4
-
5
- Invoke the professional code review Agent CLI tool OpenCodeReview (OCR) to review current code changes, and let the Agent autonomously decide whether to apply fixes.
6
-
7
- ## Workflow
8
-
9
- ### Step 1: Run Code Review
10
-
11
- Run the OCR command:
12
-
13
- ```bash
14
- ocr review --audience agent [user-args]
15
- ```
16
- - Default (no user arguments): reviews staged, unstaged, and untracked changes (workspace mode).
17
- - If the user provides `--commit` or `--c`: pass through as-is.
18
- - If the user provides `--from` and `--to`: pass through as-is.
19
- - (Optional) Provide `--background "requirement context"` to review whether the requirements are correctly implemented.
20
- - Capture full stdout. Set a 5-minute timeout.
21
- - If the `ocr` command is not found, install it by running `npm i -g @alibaba-group/open-code-review`.
22
-
23
- ### Step 2: Filter and Evaluate
24
-
25
- For each comment, assess its validity and quality:
26
-
27
- - **High**: Obvious bugs, security issues, clear mistakes, or well-founded suggestions with precise fix proposals
28
- - **Medium**: Reasonable concerns but context-dependent, style/performance suggestions, or fixes that require manual implementation
29
- - **Low**: Likely false positives, lacking sufficient context, nitpicks, or meaningless suggestions
30
-
31
- Silently discard low-confidence comments. Display the remaining comments.
32
-
33
- ### Step 3: Fix
34
-
35
- Automatically fix issues and suggestions that are worth adopting.
@@ -1,236 +0,0 @@
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
@@ -1,171 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- const assert = require("assert");
5
- const fs = require("fs");
6
- const path = require("path");
7
- const vm = require("vm");
8
-
9
- const repoRoot = path.join(__dirname, "..", "..");
10
- const workflowFiles = [
11
- ".github/workflows/ocr-review.yml",
12
- "examples/github_actions/ocr-review.yml",
13
- ];
14
-
15
- function extractPostReviewScript(workflowPath) {
16
- const text = fs.readFileSync(path.join(repoRoot, workflowPath), "utf8");
17
- const lines = text.split("\n");
18
-
19
- for (let i = 0; i < lines.length; i++) {
20
- const line = lines[i];
21
- const marker = line.match(/^(\s*)script:\s*\|\s*$/);
22
- if (!marker) continue;
23
-
24
- const blockIndent = marker[1].length + 2;
25
- const block = [];
26
- for (let j = i + 1; j < lines.length; j++) {
27
- const current = lines[j];
28
- if (current.trim() === "") {
29
- block.push("");
30
- continue;
31
- }
32
- const indent = current.match(/^ */)[0].length;
33
- if (indent < blockIndent) break;
34
- block.push(current.slice(blockIndent));
35
- }
36
-
37
- const script = block.join("\n");
38
- if (script.includes("/tmp/ocr-result.json")) {
39
- return script;
40
- }
41
- }
42
-
43
- throw new Error(`post review script not found in ${workflowPath}`);
44
- }
45
-
46
- function mockFs(resultText, stderrText) {
47
- return {
48
- readFileSync(file) {
49
- if (file === "/tmp/ocr-result.json") return resultText;
50
- if (file === "/tmp/ocr-stderr.log") return stderrText;
51
- throw new Error(`unexpected read: ${file}`);
52
- },
53
- };
54
- }
55
-
56
- function mockGithub(options) {
57
- const createReviewCalls = [];
58
- const issueComments = [];
59
-
60
- return {
61
- createReviewCalls,
62
- issueComments,
63
- rest: {
64
- pulls: {
65
- get: async () => ({ data: { head: { sha: "head-sha" } } }),
66
- createReview: async (params) => {
67
- createReviewCalls.push(params);
68
- if (createReviewCalls.length === 1 && options.bulkError) {
69
- throw new Error(options.bulkError);
70
- }
71
- if (createReviewCalls.length > 1 && options.individualError) {
72
- throw new Error(options.individualError);
73
- }
74
- return { data: {} };
75
- },
76
- },
77
- issues: {
78
- createComment: async (params) => {
79
- issueComments.push(params);
80
- return { data: {} };
81
- },
82
- },
83
- },
84
- };
85
- }
86
-
87
- async function runPostReviewScript(workflowPath, options) {
88
- const script = extractPostReviewScript(workflowPath);
89
- const github = mockGithub(options);
90
- const context = {
91
- repo: { owner: "owner", repo: "repo" },
92
- issue: { number: 123 },
93
- eventName: "pull_request_target",
94
- payload: { pull_request: { head: { sha: "head-sha" } } },
95
- };
96
- const sandbox = {
97
- github,
98
- context,
99
- console: { log() {} },
100
- require(name) {
101
- if (name === "fs") return options.fs;
102
- throw new Error(`unexpected require: ${name}`);
103
- },
104
- };
105
-
106
- await vm.runInNewContext(`(async () => {\n${script}\n})()`, sandbox, {
107
- timeout: 1000,
108
- });
109
-
110
- return github;
111
- }
112
-
113
- async function testFailedInlineCommentsAreSummarized(workflowPath) {
114
- const result = {
115
- comments: [
116
- {
117
- path: "docs/no-line.md",
118
- content:
119
- "No-line content with a fenced block:\n\n```js\nconsole.log('still visible');\n```",
120
- existing_code: "",
121
- suggestion_code: "",
122
- start_line: 0,
123
- end_line: 0,
124
- },
125
- {
126
- path: "src/app.js",
127
- content: "Failed inline content must remain visible in the PR summary.",
128
- existing_code: "oldCall();",
129
- suggestion_code: "newCall();",
130
- start_line: 10,
131
- end_line: 10,
132
- },
133
- ],
134
- warnings: [],
135
- };
136
-
137
- const github = await runPostReviewScript(workflowPath, {
138
- fs: mockFs(JSON.stringify(result), ""),
139
- bulkError: 'Unprocessable Entity: "Line could not be resolved"',
140
- individualError: 'Unprocessable Entity: "Line could not be resolved"',
141
- });
142
-
143
- assert.strictEqual(github.createReviewCalls.length, 2);
144
- assert.strictEqual(github.issueComments.length, 1);
145
- const body = github.issueComments[0].body;
146
- assert.match(body, /No-line content with a fenced block/);
147
- assert.match(body, /Failed inline content must remain visible/);
148
- assert.match(body, /Line could not be resolved/);
149
- }
150
-
151
- async function testErrorCommentUsesSafeFence(workflowPath) {
152
- const github = await runPostReviewScript(workflowPath, {
153
- fs: mockFs("not json", "stderr includes a fence\n```js\nbroken();\n```"),
154
- });
155
-
156
- assert.strictEqual(github.issueComments.length, 1);
157
- const body = github.issueComments[0].body;
158
- assert.match(body, /\n````\nstderr includes a fence/);
159
- }
160
-
161
- async function main() {
162
- for (const workflowPath of workflowFiles) {
163
- await testFailedInlineCommentsAreSummarized(workflowPath);
164
- await testErrorCommentUsesSafeFence(workflowPath);
165
- }
166
- }
167
-
168
- main().catch((err) => {
169
- console.error(err);
170
- process.exit(1);
171
- });
@@ -1,231 +0,0 @@
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
- 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.
25
-
26
- ## Prerequisites check
27
-
28
- Before starting a review, verify the environment:
29
-
30
- ```bash
31
- # 1. Check the CLI is installed
32
- which ocr || echo "NOT INSTALLED"
33
-
34
- # 2. Verify LLM connectivity
35
- ocr llm test
36
- ```
37
-
38
- If `ocr` is not installed, install it first:
39
-
40
- ```bash
41
- npm install -g @alibaba-group/open-code-review
42
- ```
43
-
44
- If `ocr llm test` fails, the user must configure an LLM. Guide them with one of these options:
45
-
46
- **Option A — Environment variables (highest priority, recommended for CI):**
47
-
48
- ```bash
49
- export OCR_LLM_URL=https://api.anthropic.com/v1/messages
50
- export OCR_LLM_TOKEN=<api-key>
51
- export OCR_LLM_MODEL=claude-opus-4-6
52
- export OCR_USE_ANTHROPIC=true
53
- ```
54
-
55
- **Option B — Persistent config:**
56
-
57
- ```bash
58
- ocr config set llm.url https://api.anthropic.com/v1/messages
59
- ocr config set llm.auth_token <api-key>
60
- ocr config set llm.model claude-opus-4-6
61
- ocr config set llm.use_anthropic true
62
- ```
63
-
64
- Stop here and ask the user to provide credentials — never invent or hardcode API keys.
65
-
66
- ## Workflow
67
-
68
- ### Step 1: Gather Business Context
69
-
70
- Analyze the review target (commits, branch, or changes) to extract concise business context. Pass this context via `--background` to improve review quality.
71
-
72
- ### Step 2: Run Code Review
73
-
74
- Run the OCR command with appropriate flags. **Always pass business context via `--background`** when available:
75
-
76
- ```bash
77
- ocr review --audience agent --background "business context here" [user-args]
78
- ```
79
-
80
- **Argument handling:**
81
-
82
- - **Background context** (RECOMMENDED): use `--background "context"` or `-b "context"` to provide business context for better review quality
83
- - **Default** (no user arguments): reviews staged, unstaged, and untracked changes (workspace mode)
84
- - **Specific commit**: use `--commit` or `-c` to review a single commit against its parent
85
- - **Branch comparison**: use `--from <ref>` and `--to <ref>` to review diff between two refs
86
- - **Timeout**: default timeout is 10 minutes per file; adjust with `--timeout <minutes>`
87
- - **Concurrency**: default concurrency is 8 file workers; reduce with `--concurrency <n>` if rate limits are hit
88
- - **Preview mode**: use `--preview` or `-p` to preview which files will be reviewed without running the LLM
89
- - **Installation**: if `ocr` command is not found, install it by running `npm i -g @alibaba-group/open-code-review`
90
-
91
- **Common invocation patterns:**
92
-
93
- | User says | Command to run |
94
- |-----------|---------------|
95
- | "review my changes" / "review the working copy" | `ocr review --audience agent -b "context"` |
96
- | "review this PR" / "review feature branch" | `ocr review --audience agent -b "context" --from main --to <branch>` |
97
- | "review commit abc123" | `ocr review --audience agent -b "context" --commit abc123` |
98
- | "what would be reviewed?" (dry-run) | `ocr review --preview` |
99
-
100
- **Output mode:**
101
-
102
- - Always use `--audience agent` to suppress progress UI and emit only the final summary
103
-
104
- ### Step 3: Classify and Report
105
-
106
- For each comment from the review output, classify by priority and report all issues to the user:
107
-
108
- - **High**: Obvious bugs, security issues, clear mistakes, or well-founded suggestions with precise fix proposals
109
- - **Medium**: Reasonable concerns but context-dependent, style/performance suggestions, or fixes that require manual implementation
110
- - **Low**: Likely false positives, lacking sufficient context, nitpicks, or meaningless suggestions
111
-
112
- Report all comments grouped by priority level.
113
-
114
- ### Step 4: Fix
115
-
116
- Before applying fixes, check whether the user requested automatic fixes:
117
-
118
- - If the user explicitly requested "review and fix" or similar, proceed with automatic fixes
119
- - If the user only requested "review" without fix intent, ask for permission before applying any changes
120
-
121
- When fixing issues and suggestions:
122
-
123
- - Focus on High and Medium priority items
124
- - Apply fixes directly to the code when safe and well-defined
125
- - For complex fixes requiring manual intervention, clearly describe what needs to be done
126
- - Always verify fixes with the user before committing
127
-
128
- ## Output Format
129
-
130
- Each comment contains:
131
-
132
- - `path`: File path
133
- - `content`: Review comment text
134
- - `start_line` / `end_line`: Line range (both 0 means positioning failed)
135
- - `suggestion_code`: Optional fix suggestion
136
- - `existing_code`: Optional original code snippet
137
- - `thinking`: Optional LLM reasoning process
138
-
139
- After filtering comments by priority, present results using this template:
140
-
141
- ```markdown
142
- ## Code Review Results
143
-
144
- **Files reviewed**: N
145
- **Issues found**: X high priority / Y medium priority
146
-
147
- ### High Priority
148
-
149
- - **`path/to/file.java:42`** — Brief description
150
- > Recommendation: How to fix
151
-
152
- ### Medium Priority
153
-
154
- - **`path/to/file.ts:88`** — Brief description
155
- > Recommendation: How to fix (if applicable)
156
- ```
157
-
158
- If the review found no issues after filtering, simply state: "Review complete — no issues found in N files."
159
-
160
- **Priority classification:**
161
-
162
- - **High**: Obvious bugs, security issues, clear mistakes, or well-founded suggestions with precise fix proposals
163
- - **Medium**: Reasonable concerns but context-dependent, style/performance suggestions, or fixes that require manual implementation
164
- - **Low**: Discarded silently (likely false positives, lacking context, nitpicks, or meaningless suggestions)
165
-
166
- **Handling mispositioned comments:**
167
-
168
- When `start_line` and `end_line` are both `0`, the comment failed to locate the exact position in the file. In such cases:
169
-
170
- 1. Read the comment content to understand the issue
171
- 2. Examine the target file mentioned in the comment
172
- 3. Identify the relevant code section based on the comment's context
173
- 4. Apply the fix or suggestion to the correct location
174
-
175
- ## Custom Review Rules
176
-
177
- If the user wants project-specific rules, OCR resolves them in this priority order:
178
-
179
- 1. `--rule <path>` flag (highest)
180
- 2. `<repo>/.opencodereview/rule.json`
181
- 3. `~/.opencodereview/rule.json`
182
- 4. Built-in system defaults (lowest)
183
-
184
- Rule file format:
185
-
186
- ```json
187
- {
188
- "rules": [
189
- {
190
- "path": "**/*.java",
191
- "rule": "All new methods must validate required parameters for null"
192
- },
193
- {
194
- "path": "**/*mapper*.xml",
195
- "rule": "Check SQL for injection risks and missing closing tags"
196
- }
197
- ]
198
- }
199
- ```
200
-
201
- To preview which rule applies to a file before reviewing:
202
-
203
- ```bash
204
- ocr rules check src/main/java/com/example/Foo.java
205
- ```
206
-
207
- ## Gotchas
208
-
209
- - **LLM must be configured first** — `ocr review` will fail loudly if no LLM is reachable. Always run `ocr llm test` before the first review.
210
- - **Working directory matters** — `ocr review` operates on the Git repo at the current directory. Use `--repo /path/to/repo` to run from elsewhere.
211
- - **Untracked files are reviewed in workspace mode** — running bare `ocr review` includes staged, unstaged, *and* untracked changes. Stage selectively if you want narrower scope.
212
- - **Large diffs may hit token limits** — files with very large diffs may be truncated. The default `MAX_TOKENS` is 58888 per request.
213
- - **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.
214
- - **Don't pass `--audience human`** — it streams progress UI that pollutes output. Always use `--audience agent`.
215
- - **Comment language follows config** — set `language` config to `English` or `Chinese` (default: Chinese) to control review comment language.
216
-
217
- ## Validation
218
-
219
- After the review completes, verify success by checking:
220
-
221
- 1. The command exited with code 0
222
- 2. Comments were generated (or "No comments generated" message appears)
223
- 3. Warnings (if any) are displayed in stderr
224
-
225
- If errors occurred, check the stderr warnings for details about which files failed and why.
226
-
227
- ## References
228
-
229
- - Full docs: https://github.com/alibaba/open-code-review
230
- - NPM package: https://www.npmjs.com/package/@alibaba-group/open-code-review
231
- - Issue tracker: https://github.com/alibaba/open-code-review/issues