@alibaba-group/open-code-review 1.3.19 → 1.4.4
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/README.ja-JP.md +53 -4
- package/README.ko-KR.md +53 -4
- package/README.md +53 -4
- package/README.ru-RU.md +53 -4
- package/README.zh-CN.md +53 -4
- package/bin/ocr.js +11 -0
- package/imgs/benchmark-en.png +0 -0
- package/imgs/benchmark-zh.png +0 -0
- package/imgs/highlights-en.png +0 -0
- package/imgs/highlights-zh.png +0 -0
- package/imgs/logo-core.svg +1 -0
- package/package.json +7 -7
- package/scripts/update.js +38 -100
package/README.ja-JP.md
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div align="center">
|
|
2
2
|
<a href="https://alibaba.github.io/open-code-review/">
|
|
3
|
-
<img src="imgs/logo.svg" alt="OpenCodeReview logo" width="
|
|
3
|
+
<img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1>OpenCodeReview</h1>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://trendshift.io/repositories/41087" target="_blank">
|
|
10
|
+
<img src="https://trendshift.io/api/badge/trendshift/repositories/41087/weekly?language=Go" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 320px; height: 70px;" width="320" height="70" />
|
|
4
11
|
</a>
|
|
5
12
|
</p>
|
|
6
|
-
<p align="center">オープンソースのAIコードレビューエージェント。</p>
|
|
7
13
|
<p align="center">
|
|
8
14
|
<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
15
|
<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
16
|
<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>
|
|
11
17
|
<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>
|
|
18
|
+
<a href="https://deepwiki.com/alibaba/open-code-review"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
|
19
|
+
<a href="https://www.bestpractices.dev/projects/13328"><img alt="OpenSSF Best Practices" src="https://www.bestpractices.dev/projects/13328/badge" /></a>
|
|
20
|
+
</p>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#supported-platforms"><img alt="Windows" src="https://img.shields.io/badge/Windows-supported-blue.svg" /></a>
|
|
23
|
+
<a href="#supported-platforms"><img alt="macOS" src="https://img.shields.io/badge/macOS-supported-blue.svg" /></a>
|
|
24
|
+
<a href="#supported-platforms"><img alt="Linux" src="https://img.shields.io/badge/Linux-supported-blue.svg" /></a>
|
|
25
|
+
<a href="#supported-agents"><img alt="Claude Code" src="https://img.shields.io/badge/Claude_Code-supported-blueviolet.svg" /></a>
|
|
26
|
+
<a href="#supported-agents"><img alt="Codex" src="https://img.shields.io/badge/Codex-supported-blueviolet.svg" /></a>
|
|
12
27
|
</p>
|
|
13
28
|
<p align="center">
|
|
14
29
|
<a href="README.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | 日本語 | <a href="README.ko-KR.md">한국어</a> | <a href="README.ru-RU.md">Русский</a>
|
|
@@ -24,6 +39,22 @@ Gitのdiffを読み取り、変更されたファイルをツール利用機能
|
|
|
24
39
|
|
|
25
40
|

|
|
26
41
|
|
|
42
|
+
## ベンチマーク
|
|
43
|
+
|
|
44
|
+
> 汎用エージェント(Claude Code)と比較して、Open Code Reviewは同じ基盤モデルで有意に高い**精度(Precision)**と**F1スコア**を達成し、トークン消費量は**約1/9**にとどまり、レビューもより高速です。ただし、リコール(Recall)は汎用エージェントより低くなります——これはノイズを抑え精度を優先する設計上のトレードオフです。
|
|
45
|
+
|
|
46
|
+
実際のコードレビューに基づくベンチマーク。**50**の人気オープンソースリポジトリから**200**の実際のPull Requestを厳選し、**10**のプログラミング言語をカバー——80人以上のシニアエンジニアによるクロスバリデーション(**1,505**件のアノテーション済み欠陥)。
|
|
47
|
+
|
|
48
|
+
| 指標 | 測定内容 | 重要性 |
|
|
49
|
+
|------|----------|--------|
|
|
50
|
+
| **F1** | 精度とリコールの調和平均 | レビュー品質を示す最良の単一指標 |
|
|
51
|
+
| **精度 (Precision)** | 報告された問題のうち実際の欠陥の割合 | 高い = 確認すべき偽陽性が少ない |
|
|
52
|
+
| **リコール (Recall)** | 実際の欠陥のうち発見された割合 | 高い = 見逃しが少ない |
|
|
53
|
+
| **平均時間 (Avg Time)** | レビューあたりの実時間 | CIパイプラインの待機時間に影響 |
|
|
54
|
+
| **平均トークン (Avg Token)** | レビューあたりの総トークン消費量 | APIコストに直接影響 |
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
27
58
|
## なぜOpen Code Reviewなのか?
|
|
28
59
|
|
|
29
60
|
### 汎用エージェントの問題点
|
|
@@ -72,7 +103,23 @@ npm install -g @alibaba-group/open-code-review
|
|
|
72
103
|
|
|
73
104
|
**GitHub Releaseから**
|
|
74
105
|
|
|
75
|
-
|
|
106
|
+
1 つのコマンドで、お使いの OS / アーキテクチャ向けの最新バイナリをインストールできます(macOS / Linux):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh | sh
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
このスクリプトは適切なリリースバイナリを選択し、SHA-256 チェックサムを検証して、`ocr` として `/usr/local/bin` にインストールします。インストール先は `OCR_INSTALL_DIR` で、リリースバージョンは `OCR_VERSION` で上書きできます:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
OCR_INSTALL_DIR="$HOME/.local/bin" OCR_VERSION=v1.3.13 \
|
|
116
|
+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh)"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
<details>
|
|
120
|
+
<summary>手動ダウンロード(Windows を含む全プラットフォーム)</summary>
|
|
121
|
+
|
|
122
|
+
[GitHub Releases](https://github.com/alibaba/open-code-review/releases)からお使いのプラットフォーム向けのバイナリをダウンロードします:
|
|
76
123
|
|
|
77
124
|
```bash
|
|
78
125
|
# macOS (Apple Silicon)
|
|
@@ -98,6 +145,8 @@ curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/dow
|
|
|
98
145
|
curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe
|
|
99
146
|
```
|
|
100
147
|
|
|
148
|
+
</details>
|
|
149
|
+
|
|
101
150
|
**ソースから**
|
|
102
151
|
|
|
103
152
|
```bash
|
package/README.ko-KR.md
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div align="center">
|
|
2
2
|
<a href="https://alibaba.github.io/open-code-review/">
|
|
3
|
-
<img src="imgs/logo.svg" alt="OpenCodeReview logo" width="
|
|
3
|
+
<img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1>OpenCodeReview</h1>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://trendshift.io/repositories/41087" target="_blank">
|
|
10
|
+
<img src="https://trendshift.io/api/badge/trendshift/repositories/41087/weekly?language=Go" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 320px; height: 70px;" width="320" height="70" />
|
|
4
11
|
</a>
|
|
5
12
|
</p>
|
|
6
|
-
<p align="center">오픈 소스 AI 코드 리뷰 에이전트.</p>
|
|
7
13
|
<p align="center">
|
|
8
14
|
<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
15
|
<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
16
|
<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>
|
|
11
17
|
<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>
|
|
18
|
+
<a href="https://deepwiki.com/alibaba/open-code-review"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
|
19
|
+
<a href="https://www.bestpractices.dev/projects/13328"><img alt="OpenSSF Best Practices" src="https://www.bestpractices.dev/projects/13328/badge" /></a>
|
|
20
|
+
</p>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#supported-platforms"><img alt="Windows" src="https://img.shields.io/badge/Windows-supported-blue.svg" /></a>
|
|
23
|
+
<a href="#supported-platforms"><img alt="macOS" src="https://img.shields.io/badge/macOS-supported-blue.svg" /></a>
|
|
24
|
+
<a href="#supported-platforms"><img alt="Linux" src="https://img.shields.io/badge/Linux-supported-blue.svg" /></a>
|
|
25
|
+
<a href="#supported-agents"><img alt="Claude Code" src="https://img.shields.io/badge/Claude_Code-supported-blueviolet.svg" /></a>
|
|
26
|
+
<a href="#supported-agents"><img alt="Codex" src="https://img.shields.io/badge/Codex-supported-blueviolet.svg" /></a>
|
|
12
27
|
</p>
|
|
13
28
|
<p align="center">
|
|
14
29
|
<a href="README.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja-JP.md">日本語</a> | 한국어 | <a href="README.ru-RU.md">Русский</a>
|
|
@@ -24,6 +39,22 @@ Open Code Review는 AI 기반 코드 리뷰 CLI 도구입니다. Alibaba Group
|
|
|
24
39
|
|
|
25
40
|

|
|
26
41
|
|
|
42
|
+
## 벤치마크
|
|
43
|
+
|
|
44
|
+
> 범용 Agent(Claude Code)와 비교할 때, Open Code Review는 동일한 기반 모델에서 유의미하게 높은 **정밀도(Precision)**와 **F1 점수**를 달성하며, 토큰 소비량은 **약 1/9** 수준이고 리뷰 속도도 더 빠릅니다. 다만 재현율(Recall)은 범용 Agent보다 낮습니다 — 이는 노이즈를 줄이고 정밀도를 우선하는 설계적 트레이드오프입니다.
|
|
45
|
+
|
|
46
|
+
실제 코드 리뷰 기반 벤치마크. **50**개 인기 오픈소스 저장소에서 **200**개 실제 Pull Request를 엄선하고, **10**개 프로그래밍 언어를 커버 — 80명 이상의 시니어 엔지니어가 교차 검증(**1,505**개 어노테이션된 결함).
|
|
47
|
+
|
|
48
|
+
| 지표 | 측정 내용 | 중요한 이유 |
|
|
49
|
+
|------|-----------|-------------|
|
|
50
|
+
| **F1** | 정밀도와 재현율의 조화 평균 | 리뷰 품질을 나타내는 최적의 단일 지표 |
|
|
51
|
+
| **정밀도 (Precision)** | 보고된 이슈 중 실제 결함 비율 | 높을수록 확인할 오탐이 적음 |
|
|
52
|
+
| **재현율 (Recall)** | 실제 결함 중 발견된 비율 | 높을수록 놓치는 이슈가 적음 |
|
|
53
|
+
| **평균 시간 (Avg Time)** | 리뷰당 실제 소요 시간 | CI 파이프라인 대기 시간에 영향 |
|
|
54
|
+
| **평균 토큰 (Avg Token)** | 리뷰당 총 토큰 소비량 | API 비용에 직접 영향 |
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
27
58
|
## 왜 Open Code Review인가?
|
|
28
59
|
|
|
29
60
|
### 범용 Agent의 문제
|
|
@@ -72,7 +103,23 @@ npm install -g @alibaba-group/open-code-review
|
|
|
72
103
|
|
|
73
104
|
**GitHub Release 사용**
|
|
74
105
|
|
|
75
|
-
|
|
106
|
+
명령 한 번으로 사용 중인 OS/아키텍처에 맞는 최신 binary를 설치합니다 (macOS / Linux):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh | sh
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
이 스크립트는 알맞은 릴리스 binary를 선택하고 SHA-256 체크섬을 검증한 뒤 `ocr`로 `/usr/local/bin`에 설치합니다. 설치 위치는 `OCR_INSTALL_DIR`로, 릴리스 버전은 `OCR_VERSION`으로 재정의할 수 있습니다:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
OCR_INSTALL_DIR="$HOME/.local/bin" OCR_VERSION=v1.3.13 \
|
|
116
|
+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh)"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
<details>
|
|
120
|
+
<summary>수동 다운로드 (Windows 포함 모든 플랫폼)</summary>
|
|
121
|
+
|
|
122
|
+
[GitHub Releases](https://github.com/alibaba/open-code-review/releases)에서 사용 중인 플랫폼의 binary를 다운로드합니다.
|
|
76
123
|
|
|
77
124
|
```bash
|
|
78
125
|
# macOS (Apple Silicon)
|
|
@@ -98,6 +145,8 @@ curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/dow
|
|
|
98
145
|
curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe
|
|
99
146
|
```
|
|
100
147
|
|
|
148
|
+
</details>
|
|
149
|
+
|
|
101
150
|
**소스에서 빌드**
|
|
102
151
|
|
|
103
152
|
```bash
|
package/README.md
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div align="center">
|
|
2
2
|
<a href="https://alibaba.github.io/open-code-review/">
|
|
3
|
-
<img src="imgs/logo.svg" alt="OpenCodeReview logo" width="
|
|
3
|
+
<img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1>OpenCodeReview</h1>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://trendshift.io/repositories/41087" target="_blank">
|
|
10
|
+
<img src="https://trendshift.io/api/badge/trendshift/repositories/41087/weekly?language=Go" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 320px; height: 70px;" width="320" height="70" />
|
|
4
11
|
</a>
|
|
5
12
|
</p>
|
|
6
|
-
<p align="center">The open source AI code review agent.</p>
|
|
7
13
|
<p align="center">
|
|
8
14
|
<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
15
|
<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
16
|
<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>
|
|
11
17
|
<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>
|
|
18
|
+
<a href="https://deepwiki.com/alibaba/open-code-review"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
|
19
|
+
<a href="https://www.bestpractices.dev/projects/13328"><img alt="OpenSSF Best Practices" src="https://www.bestpractices.dev/projects/13328/badge" /></a>
|
|
20
|
+
</p>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#supported-platforms"><img alt="Windows" src="https://img.shields.io/badge/Windows-supported-blue.svg" /></a>
|
|
23
|
+
<a href="#supported-platforms"><img alt="macOS" src="https://img.shields.io/badge/macOS-supported-blue.svg" /></a>
|
|
24
|
+
<a href="#supported-platforms"><img alt="Linux" src="https://img.shields.io/badge/Linux-supported-blue.svg" /></a>
|
|
25
|
+
<a href="#supported-agents"><img alt="Claude Code" src="https://img.shields.io/badge/Claude_Code-supported-blueviolet.svg" /></a>
|
|
26
|
+
<a href="#supported-agents"><img alt="Codex" src="https://img.shields.io/badge/Codex-supported-blueviolet.svg" /></a>
|
|
12
27
|
</p>
|
|
13
28
|
<p align="center">
|
|
14
29
|
English | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja-JP.md">日本語</a> | <a href="README.ko-KR.md">한국어</a> | <a href="README.ru-RU.md">Русский</a>
|
|
@@ -24,6 +39,22 @@ It reads Git diffs, sends changed files to a configurable LLM via an agent with
|
|
|
24
39
|
|
|
25
40
|

|
|
26
41
|
|
|
42
|
+
## Benchmark
|
|
43
|
+
|
|
44
|
+
> Compared to general-purpose agents (Claude Code), Open Code Review achieves significantly higher **Precision** and **F1** with the same underlying model, while consuming only **~1/9 of the tokens** and completing reviews faster. Note that its Recall is lower than general-purpose agents — a deliberate trade-off favoring precision over noise.
|
|
45
|
+
|
|
46
|
+
A real-world code review benchmark built from **50** popular open-source repositories, **200** real Pull Requests, and **10** programming languages — cross-validated by 80+ senior engineers (**1,505** annotated ground-truth issues).
|
|
47
|
+
|
|
48
|
+
| Metric | What it measures | Why it matters |
|
|
49
|
+
|--------|-----------------|----------------|
|
|
50
|
+
| **F1** | Harmonic mean of precision and recall | Best single number for overall review quality |
|
|
51
|
+
| **Precision** | Proportion of reported issues that are real defects | Higher = fewer false alarms to triage |
|
|
52
|
+
| **Recall** | Proportion of real defects that are found | Higher = fewer issues slip through review |
|
|
53
|
+
| **Avg Time** | Wall-clock time per review | Matters for CI pipeline latency |
|
|
54
|
+
| **Avg Token** | Total tokens consumed per review | Directly impacts API cost |
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
27
58
|
## Why Open Code Review?
|
|
28
59
|
|
|
29
60
|
### The Problem with General-Purpose Agents
|
|
@@ -72,7 +103,23 @@ After installation, the `ocr` command is available globally.
|
|
|
72
103
|
|
|
73
104
|
**From GitHub Release**
|
|
74
105
|
|
|
75
|
-
|
|
106
|
+
Install the latest binary for your OS/architecture with one command (macOS / Linux):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh | sh
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The script picks the right release binary, verifies its SHA-256 checksum, and installs it as `ocr` in `/usr/local/bin`. Override the target with `OCR_INSTALL_DIR` or pin a release with `OCR_VERSION`:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
OCR_INSTALL_DIR="$HOME/.local/bin" OCR_VERSION=v1.3.13 \
|
|
116
|
+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh)"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
<details>
|
|
120
|
+
<summary>Manual download (all platforms, including Windows)</summary>
|
|
121
|
+
|
|
122
|
+
Download the binary for your platform from [GitHub Releases](https://github.com/alibaba/open-code-review/releases):
|
|
76
123
|
|
|
77
124
|
```bash
|
|
78
125
|
# macOS (Apple Silicon)
|
|
@@ -98,6 +145,8 @@ curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/dow
|
|
|
98
145
|
curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe
|
|
99
146
|
```
|
|
100
147
|
|
|
148
|
+
</details>
|
|
149
|
+
|
|
101
150
|
**From Source**
|
|
102
151
|
|
|
103
152
|
```bash
|
package/README.ru-RU.md
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div align="center">
|
|
2
2
|
<a href="https://alibaba.github.io/open-code-review/">
|
|
3
|
-
<img src="imgs/logo.svg" alt="OpenCodeReview logo" width="
|
|
3
|
+
<img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1>OpenCodeReview</h1>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://trendshift.io/repositories/41087" target="_blank">
|
|
10
|
+
<img src="https://trendshift.io/api/badge/trendshift/repositories/41087/weekly?language=Go" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 320px; height: 70px;" width="320" height="70" />
|
|
4
11
|
</a>
|
|
5
12
|
</p>
|
|
6
|
-
<p align="center">AI-агент код-ревью с открытым исходным кодом.</p>
|
|
7
13
|
<p align="center">
|
|
8
14
|
<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
15
|
<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
16
|
<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>
|
|
11
17
|
<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>
|
|
18
|
+
<a href="https://deepwiki.com/alibaba/open-code-review"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
|
19
|
+
<a href="https://www.bestpractices.dev/projects/13328"><img alt="OpenSSF Best Practices" src="https://www.bestpractices.dev/projects/13328/badge" /></a>
|
|
20
|
+
</p>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#supported-platforms"><img alt="Windows" src="https://img.shields.io/badge/Windows-supported-blue.svg" /></a>
|
|
23
|
+
<a href="#supported-platforms"><img alt="macOS" src="https://img.shields.io/badge/macOS-supported-blue.svg" /></a>
|
|
24
|
+
<a href="#supported-platforms"><img alt="Linux" src="https://img.shields.io/badge/Linux-supported-blue.svg" /></a>
|
|
25
|
+
<a href="#supported-agents"><img alt="Claude Code" src="https://img.shields.io/badge/Claude_Code-supported-blueviolet.svg" /></a>
|
|
26
|
+
<a href="#supported-agents"><img alt="Codex" src="https://img.shields.io/badge/Codex-supported-blueviolet.svg" /></a>
|
|
12
27
|
</p>
|
|
13
28
|
<p align="center">
|
|
14
29
|
<a href="README.md">English</a> | <a href="README.zh-CN.md">简体中文</a> | <a href="README.ja-JP.md">日本語</a> | <a href="README.ko-KR.md">한국어</a> | Русский
|
|
@@ -24,6 +39,22 @@ Open Code Review — это CLI-инструмент для код-ревью н
|
|
|
24
39
|
|
|
25
40
|

|
|
26
41
|
|
|
42
|
+
## Бенчмарк
|
|
43
|
+
|
|
44
|
+
> По сравнению с агентами общего назначения (Claude Code), Open Code Review при той же базовой модели достигает значительно более высоких показателей **Precision** и **F1**, потребляя лишь **~1/9 токенов** и выполняя ревью быстрее. При этом показатель Recall ниже, чем у агентов общего назначения — это осознанный компромисс в пользу точности и минимального шума.
|
|
45
|
+
|
|
46
|
+
Бенчмарк на основе реальных код-ревью: **50** популярных open-source-репозиториев, **200** реальных Pull Request, **10** языков программирования — перекрёстная валидация 80+ старшими инженерами (**1 505** размеченных дефектов).
|
|
47
|
+
|
|
48
|
+
| Метрика | Что измеряет | Почему важна |
|
|
49
|
+
|---------|-------------|--------------|
|
|
50
|
+
| **F1** | Гармоническое среднее precision и recall | Лучший единый показатель качества ревью |
|
|
51
|
+
| **Precision** | Доля найденных проблем, являющихся реальными дефектами | Выше = меньше ложных срабатываний |
|
|
52
|
+
| **Recall** | Доля реальных дефектов, которые были найдены | Выше = меньше пропущенных проблем |
|
|
53
|
+
| **Avg Time** | Время выполнения одного ревью | Влияет на задержки в CI-пайплайне |
|
|
54
|
+
| **Avg Token** | Суммарное потребление токенов за ревью | Прямо влияет на стоимость API |
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
27
58
|
## Почему Open Code Review?
|
|
28
59
|
|
|
29
60
|
### Проблема агентов общего назначения
|
|
@@ -72,7 +103,23 @@ npm install -g @alibaba-group/open-code-review
|
|
|
72
103
|
|
|
73
104
|
**Из GitHub Release**
|
|
74
105
|
|
|
75
|
-
|
|
106
|
+
Установите свежий бинарный файл для вашей ОС/архитектуры одной командой (macOS / Linux):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh | sh
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Скрипт сам выбирает подходящий бинарный файл релиза, проверяет его контрольную сумму SHA-256 и устанавливает его как `ocr` в `/usr/local/bin`. Каталог установки можно переопределить через `OCR_INSTALL_DIR`, а версию релиза зафиксировать через `OCR_VERSION`:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
OCR_INSTALL_DIR="$HOME/.local/bin" OCR_VERSION=v1.3.13 \
|
|
116
|
+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh)"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
<details>
|
|
120
|
+
<summary>Ручная загрузка (все платформы, включая Windows)</summary>
|
|
121
|
+
|
|
122
|
+
Скачайте бинарный файл для вашей платформы со страницы [GitHub Releases](https://github.com/alibaba/open-code-review/releases):
|
|
76
123
|
|
|
77
124
|
```bash
|
|
78
125
|
# macOS (Apple Silicon)
|
|
@@ -98,6 +145,8 @@ curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/dow
|
|
|
98
145
|
curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe
|
|
99
146
|
```
|
|
100
147
|
|
|
148
|
+
</details>
|
|
149
|
+
|
|
101
150
|
**Из исходников**
|
|
102
151
|
|
|
103
152
|
```bash
|
package/README.zh-CN.md
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div align="center">
|
|
2
2
|
<a href="https://alibaba.github.io/open-code-review/">
|
|
3
|
-
<img src="imgs/logo.svg" alt="OpenCodeReview logo" width="
|
|
3
|
+
<img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1>OpenCodeReview</h1>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://trendshift.io/repositories/41087" target="_blank">
|
|
10
|
+
<img src="https://trendshift.io/api/badge/trendshift/repositories/41087/weekly?language=Go" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 320px; height: 70px;" width="320" height="70" />
|
|
4
11
|
</a>
|
|
5
12
|
</p>
|
|
6
|
-
<p align="center">The open source AI code review agent.</p>
|
|
7
13
|
<p align="center">
|
|
8
14
|
<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
15
|
<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
16
|
<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>
|
|
11
17
|
<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>
|
|
18
|
+
<a href="https://deepwiki.com/alibaba/open-code-review"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
|
19
|
+
<a href="https://www.bestpractices.dev/projects/13328"><img alt="OpenSSF Best Practices" src="https://www.bestpractices.dev/projects/13328/badge" /></a>
|
|
20
|
+
</p>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#supported-platforms"><img alt="Windows" src="https://img.shields.io/badge/Windows-supported-blue.svg" /></a>
|
|
23
|
+
<a href="#supported-platforms"><img alt="macOS" src="https://img.shields.io/badge/macOS-supported-blue.svg" /></a>
|
|
24
|
+
<a href="#supported-platforms"><img alt="Linux" src="https://img.shields.io/badge/Linux-supported-blue.svg" /></a>
|
|
25
|
+
<a href="#supported-agents"><img alt="Claude Code" src="https://img.shields.io/badge/Claude_Code-supported-blueviolet.svg" /></a>
|
|
26
|
+
<a href="#supported-agents"><img alt="Codex" src="https://img.shields.io/badge/Codex-supported-blueviolet.svg" /></a>
|
|
12
27
|
</p>
|
|
13
28
|
<p align="center">
|
|
14
29
|
<a href="README.md">English</a> | 简体中文 | <a href="README.ja-JP.md">日本語</a> | <a href="README.ko-KR.md">한국어</a> | <a href="README.ru-RU.md">Русский</a>
|
|
@@ -24,6 +39,22 @@ Open Code Review 是一款 AI 驱动的代码审查 CLI 工具。它的前身是
|
|
|
24
39
|
|
|
25
40
|

|
|
26
41
|
|
|
42
|
+
## 基准测试
|
|
43
|
+
|
|
44
|
+
> 相比通用 Agent(Claude Code),Open Code Review 在相同底层模型下取得了显著更高的 **准确率(Precision)** 与 **F1 综合得分**,同时仅消耗 **约 1/9 的 token**、审查更快。但召回率(Recall)低于通用 Agent——这是以精准度换取低噪声的设计取舍。
|
|
45
|
+
|
|
46
|
+
基于真实场景的代码审查基准测试,从 **50** 个热门开源仓库中精选 **200** 个真实的 Pull Request,覆盖 **10** 种编程语言——由 80+ 位资深工程师交叉标注验证(共 **1,505** 个标注缺陷)。
|
|
47
|
+
|
|
48
|
+
| 指标 | 含义 | 为什么重要 |
|
|
49
|
+
|------|------|-----------|
|
|
50
|
+
| **F1** | 准确率与召回率的调和均值 | 综合衡量审查质量的最佳单一指标 |
|
|
51
|
+
| **准确率 (Precision)** | 报告的问题中真正有效的比例 | 越高 = 误报越少,减少人工确认成本 |
|
|
52
|
+
| **召回率 (Recall)** | 真实缺陷中被发现的比例 | 越高 = 漏报越少,更多问题不会遗漏 |
|
|
53
|
+
| **平均耗时 (Avg Time)** | 每次审查的实际耗时 | 决定 CI 流水线的等待时间 |
|
|
54
|
+
| **平均 Token (Avg Token)** | 每次审查消耗的总 token 数 | 直接影响 API 使用成本 |
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
27
58
|
## 为什么选择 Open Code Review?
|
|
28
59
|
|
|
29
60
|
### 通用 Agent 的局限
|
|
@@ -72,7 +103,23 @@ npm install -g @alibaba-group/open-code-review
|
|
|
72
103
|
|
|
73
104
|
**从 GitHub Release 下载**
|
|
74
105
|
|
|
75
|
-
|
|
106
|
+
使用一条命令为你的操作系统/架构安装最新二进制文件(macOS / Linux):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh | sh
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
该脚本会自动选择匹配的发布二进制文件,校验其 SHA-256 校验和,并将其作为 `ocr` 安装到 `/usr/local/bin`。可通过 `OCR_INSTALL_DIR` 覆盖安装目录,或通过 `OCR_VERSION` 指定发布版本:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
OCR_INSTALL_DIR="$HOME/.local/bin" OCR_VERSION=v1.3.13 \
|
|
116
|
+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/alibaba/open-code-review/main/install.sh)"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
<details>
|
|
120
|
+
<summary>手动下载(所有平台,包括 Windows)</summary>
|
|
121
|
+
|
|
122
|
+
从 [GitHub Releases](https://github.com/alibaba/open-code-review/releases) 下载适用于你平台的二进制文件:
|
|
76
123
|
|
|
77
124
|
```bash
|
|
78
125
|
# macOS (Apple Silicon)
|
|
@@ -98,6 +145,8 @@ curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/dow
|
|
|
98
145
|
curl -Lo ocr.exe https://github.com/alibaba/open-code-review/releases/latest/download/opencodereview-windows-arm64.exe
|
|
99
146
|
```
|
|
100
147
|
|
|
148
|
+
</details>
|
|
149
|
+
|
|
101
150
|
**从源码构建**
|
|
102
151
|
|
|
103
152
|
```bash
|
package/bin/ocr.js
CHANGED
|
@@ -17,6 +17,17 @@ if (!resolved) {
|
|
|
17
17
|
}
|
|
18
18
|
const binaryPath = resolved.path;
|
|
19
19
|
|
|
20
|
+
const hintFile = path.join(os.homedir(), ".opencodereview", "update-available");
|
|
21
|
+
try {
|
|
22
|
+
const hint = JSON.parse(fs.readFileSync(hintFile, "utf8"));
|
|
23
|
+
if (hint.version && hint.pkg) {
|
|
24
|
+
console.error(
|
|
25
|
+
`\x1b[33m[ocr] A new version (v${hint.version}) is available. Run to update:\x1b[0m\n` +
|
|
26
|
+
`\x1b[33m npm i -g ${hint.pkg}@${hint.version}\x1b[0m\n`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
} catch (_) {}
|
|
30
|
+
|
|
20
31
|
if (!process.env.OCR_NO_UPDATE) {
|
|
21
32
|
const stateDir = path.join(os.homedir(), ".opencodereview");
|
|
22
33
|
const tsFile = path.join(stateDir, "last-update-check");
|
|
Binary file
|
|
Binary file
|
package/imgs/highlights-en.png
CHANGED
|
Binary file
|
package/imgs/highlights-zh.png
CHANGED
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="500" height="500" viewBox="0 0 500 500"><defs><clipPath id="master_svg0_3_1846"><rect x="0" y="0" width="500" height="500" rx="0"/></clipPath></defs><g clip-path="url(#master_svg0_3_1846)"><path d="M369.391824777832,207.16971852783203L369.391854777832,131.60131852783203C369.391854777832,128.15557852783203,367.18552477783203,125.09696952783203,363.915744777832,124.00987252783203L265.002354777832,91.12426762783203C256.809764777832,88.40048217783203,247.95578477783204,88.40048217783203,239.76320477783204,91.12426762783203L140.84986477783204,124.00987252783203C137.58010877783204,125.09696952783203,135.37377977783203,128.15557852783203,135.37377977783203,131.60131052783203L135.37377977783203,187.979896527832Q110.36145377783203,206.39992852783203,91.91033172783203,231.29782852783202C91.25267028783203,232.18527852783203,91.45416259783204,233.43310852783202,92.34779357783204,234.08234852783204L101.33021547783203,240.60814852783204C102.22384677783204,241.25737852783203,103.48256677783203,241.04652852783204,104.14099877783204,240.15965852783202Q117.80681777783204,221.75247852783204,135.37377977783203,207.15375852783203L135.37377977783203,207.16845852783203C135.42538077783203,207.12065852783203,135.47701677783203,207.07290852783203,135.52869377783202,207.02515852783205Q150.71423377783202,194.43231852783202,168.80918877783205,184.679801527832Q209.221374777832,162.89910852783203,251.50217477783204,162.39883452783204C251.59465477783203,162.39774352783203,251.68558477783202,162.39046452783202,251.77458477783202,162.377410527832C251.97704477783202,162.37673952783203,252.17955477783204,162.37640352783203,252.38211477783204,162.37640352783203C296.51404477783205,162.37640352783203,338.303324777832,178.37404652783204,369.391824777832,207.16971852783203ZM252.38291477783204,295.414878527832C279.10971477783204,295.414878527832,300.776084777832,273.74850852783203,300.776084777832,247.02170852783203C300.776084777832,240.21207852783203,299.33893477783204,233.47909852783204,296.55858477783204,227.26292852783203C294.66187477783205,235.80182852783204,287.548164777832,242.19144852783202,278.85541477783204,243.16412852783202C279.03736477783207,244.42372852783203,279.131504777832,245.71170852783203,279.131504777832,247.02168852783203C279.131504777832,261.794608527832,267.155694777832,273.770428527832,252.38277477783203,273.770428527832C237.60985477783203,273.770428527832,225.63404477783203,261.794608527832,225.63404477783203,247.02168852783203C225.63404477783203,232.24876852783203,237.60985477783203,220.27295852783203,252.38277477783203,220.27295852783203C253.69280477783204,220.27295852783203,254.98084477783203,220.36711852783202,256.240474777832,220.54907852783202C257.21321477783204,211.85636852783205,263.60280477783203,204.742728527832,272.141634777832,202.84602852783203C265.925484777832,200.06567852783203,259.19254477783204,198.62853852783203,252.38291477783204,198.62853852783203C225.65610477783204,198.62853852783203,203.98974477783202,220.29489852783203,203.98974477783202,247.02170852783203C203.98974477783202,273.74850852783203,225.65610477783204,295.414878527832,252.38291477783204,295.414878527832ZM274.81439477783204,243.21481852783202C264.90529477783207,242.35698852783204,257.04755477783203,234.49919852783202,256.1897847778321,224.59009852783203C254.95186477783204,224.38151852783204,253.68000477783204,224.27295852783203,252.38277477783203,224.27295852783203C239.81899477783202,224.27295852783203,229.63404477783203,234.45790852783202,229.63404477783203,247.02168852783203C229.63404477783203,259.58546852783206,239.81899477783202,269.770428527832,252.38277477783203,269.770428527832C264.94655477783203,269.770428527832,275.131504777832,259.58546852783206,275.131504777832,247.02168852783203C275.131504777832,245.72450852783203,275.02294477783204,244.45268852783204,274.81439477783204,243.21481852783202ZM313.98419477783204,373.06705852783205C339.51094477783204,356.76340852783204,357.58451477783206,331.66420852783205,365.26810477783204,303.12996852783203Q389.75952477783204,285.49681852783203,408.076424777832,260.794778527832C408.73435477783204,259.907508527832,408.54584477783203,258.641948527832,407.65219477783205,257.99271852783204L398.669774777832,251.46689852783203C397.77616477783204,250.81766852783204,396.535404777832,251.00403852783202,395.87693477783205,251.89087852783203Q383.89679477783204,268.02557852783207,369.057804777832,280.89197852783207L369.05826477783205,280.88595852783203C369.02341477783204,280.91804852783207,368.98856477783204,280.950138527832,368.95362477783203,280.98224852783204Q352.70179477783205,295.05160852783206,333.025454777832,305.20590852783204Q296.652744777832,323.976658527832,256.24428477783204,325.33029852783204C254.95902477783204,325.35753852783205,253.67157477783203,325.37118852783203,252.38211477783204,325.37118852783203C208.41640477783204,325.37118852783203,166.76860077783203,309.49237852783205,135.70742077783203,280.88730852783203C138.50842277783204,318.39349852783204,158.79284677783204,352.636328527832,190.78138777783204,373.067088527832L248.07660477783202,409.660928527832C250.70246477783203,411.33801852783205,254.06308477783202,411.33801852783205,256.68894477783203,409.660928527832L313.98419477783204,373.06705852783205Z" fill-rule="evenodd" fill="#35BD5F" fill-opacity="1"/></g></svg>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alibaba-group/open-code-review",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "OpenCodeReview CLI — AI-powered code review tool",
|
|
5
5
|
"bin": {
|
|
6
6
|
"ocr": "bin/ocr.js"
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"checksumPattern": "https://github.com/alibaba/open-code-review/releases/download/v{version}/sha256sum.txt"
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
|
-
"@alibaba-group/ocr-darwin-arm64": "1.
|
|
32
|
-
"@alibaba-group/ocr-darwin-x64": "1.
|
|
33
|
-
"@alibaba-group/ocr-linux-arm64": "1.
|
|
34
|
-
"@alibaba-group/ocr-linux-x64": "1.
|
|
35
|
-
"@alibaba-group/ocr-win32-arm64": "1.
|
|
36
|
-
"@alibaba-group/ocr-win32-x64": "1.
|
|
31
|
+
"@alibaba-group/ocr-darwin-arm64": "1.4.4",
|
|
32
|
+
"@alibaba-group/ocr-darwin-x64": "1.4.4",
|
|
33
|
+
"@alibaba-group/ocr-linux-arm64": "1.4.4",
|
|
34
|
+
"@alibaba-group/ocr-linux-x64": "1.4.4",
|
|
35
|
+
"@alibaba-group/ocr-win32-arm64": "1.4.4",
|
|
36
|
+
"@alibaba-group/ocr-win32-x64": "1.4.4"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=14"
|
package/scripts/update.js
CHANGED
|
@@ -7,22 +7,13 @@ const os = require("os");
|
|
|
7
7
|
const https = require("https");
|
|
8
8
|
const { spawnSync } = require("child_process");
|
|
9
9
|
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
detectPlatform,
|
|
14
|
-
loadPackageJson,
|
|
15
|
-
buildUrl,
|
|
16
|
-
downloadText,
|
|
17
|
-
downloadBinary,
|
|
18
|
-
computeChecksum,
|
|
19
|
-
} = require("./install.js");
|
|
20
|
-
const packageRoot = path.join(__dirname, "..");
|
|
21
|
-
const binDir = path.join(packageRoot, "bin");
|
|
22
|
-
const binaryPath = path.join(binDir, BINARY_NAME);
|
|
10
|
+
const { resolveNativeBinary } = require("./platform");
|
|
11
|
+
const { loadPackageJson } = require("./install.js");
|
|
12
|
+
|
|
23
13
|
const stateDir = path.join(os.homedir(), ".opencodereview");
|
|
24
14
|
const tsFile = path.join(stateDir, "last-update-check");
|
|
25
15
|
const lockFile = path.join(stateDir, "update.lock");
|
|
16
|
+
const hintFile = path.join(stateDir, "update-available");
|
|
26
17
|
|
|
27
18
|
const DEFAULT_REGISTRY = "https://registry.npmjs.org";
|
|
28
19
|
|
|
@@ -65,9 +56,9 @@ function releaseLock() {
|
|
|
65
56
|
} catch (_) {}
|
|
66
57
|
}
|
|
67
58
|
|
|
68
|
-
function getInstalledVersion() {
|
|
59
|
+
function getInstalledVersion(binPath) {
|
|
69
60
|
try {
|
|
70
|
-
const result = spawnSync(
|
|
61
|
+
const result = spawnSync(binPath, ["version"], {
|
|
71
62
|
encoding: "utf8",
|
|
72
63
|
timeout: 3000,
|
|
73
64
|
});
|
|
@@ -118,24 +109,30 @@ function fetchLatestVersion(pkg) {
|
|
|
118
109
|
});
|
|
119
110
|
}
|
|
120
111
|
|
|
112
|
+
const SEMVER_RE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
113
|
+
|
|
121
114
|
function semverGt(a, b) {
|
|
122
|
-
const pa = a.split(".").map(Number);
|
|
123
|
-
const pb = b.split(".").map(Number);
|
|
115
|
+
const pa = a.replace(/-.*$/, "").split(".").map(Number);
|
|
116
|
+
const pb = b.replace(/-.*$/, "").split(".").map(Number);
|
|
124
117
|
for (let i = 0; i < 3; i++) {
|
|
125
118
|
if ((pa[i] || 0) > (pb[i] || 0)) return true;
|
|
126
119
|
if ((pa[i] || 0) < (pb[i] || 0)) return false;
|
|
127
120
|
}
|
|
121
|
+
const aPre = a.includes("-");
|
|
122
|
+
const bPre = b.includes("-");
|
|
123
|
+
if (bPre && !aPre) return true;
|
|
128
124
|
return false;
|
|
129
125
|
}
|
|
130
126
|
|
|
131
|
-
function
|
|
127
|
+
function writeHint(latestVersion, pkgName) {
|
|
132
128
|
try {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
fs.writeFileSync(hintFile, JSON.stringify({ version: latestVersion, pkg: pkgName }));
|
|
130
|
+
} catch (_) {}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function removeHint() {
|
|
134
|
+
try {
|
|
135
|
+
fs.unlinkSync(hintFile);
|
|
139
136
|
} catch (_) {}
|
|
140
137
|
}
|
|
141
138
|
|
|
@@ -144,97 +141,38 @@ async function main() {
|
|
|
144
141
|
|
|
145
142
|
if (!acquireLock()) return;
|
|
146
143
|
|
|
147
|
-
cleanupTemp();
|
|
148
|
-
|
|
149
144
|
try {
|
|
150
|
-
const { resolveNativeBinary } = require("./platform");
|
|
151
145
|
const resolved = resolveNativeBinary();
|
|
152
|
-
if (resolved
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
const installedVersion = getInstalledVersion();
|
|
146
|
+
if (!resolved) return;
|
|
147
|
+
|
|
148
|
+
const installedVersion = getInstalledVersion(resolved.path);
|
|
157
149
|
if (!installedVersion) return;
|
|
158
150
|
|
|
159
151
|
const pkg = loadPackageJson();
|
|
160
152
|
const latestVersion = await fetchLatestVersion(pkg);
|
|
161
153
|
if (!latestVersion) return;
|
|
162
154
|
|
|
163
|
-
if (!
|
|
164
|
-
|
|
165
|
-
const { os: platform, arch } = detectPlatform();
|
|
166
|
-
const config = pkg.ocrConfig;
|
|
155
|
+
if (!SEMVER_RE.test(latestVersion)) return;
|
|
167
156
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
downloadUrl += ".exe";
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const tempPath = path.join(binDir, `.opencodereview.tmp.${process.pid}`);
|
|
175
|
-
await downloadBinary(downloadUrl, tempPath);
|
|
176
|
-
if (!IS_WINDOWS) {
|
|
177
|
-
fs.chmodSync(tempPath, 0o755);
|
|
157
|
+
if (!semverGt(latestVersion, installedVersion)) {
|
|
158
|
+
removeHint();
|
|
159
|
+
return;
|
|
178
160
|
}
|
|
179
161
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
let actualSha;
|
|
190
|
-
try {
|
|
191
|
-
actualSha = await computeChecksum(tempPath);
|
|
192
|
-
} catch (_) {
|
|
193
|
-
fs.unlinkSync(tempPath);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
let verified = false;
|
|
198
|
-
for (const line of shaContent.split("\n")) {
|
|
199
|
-
const trimmed = line.trim();
|
|
200
|
-
if (trimmed.includes(`-${platform}-${arch}`)) {
|
|
201
|
-
const expectedSha = trimmed.split(/\s+/)[0].toLowerCase();
|
|
202
|
-
if (expectedSha && actualSha !== expectedSha) {
|
|
203
|
-
fs.unlinkSync(tempPath);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
verified = true;
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (!verified) {
|
|
211
|
-
fs.unlinkSync(tempPath);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
162
|
+
const pkgName = pkg.name;
|
|
163
|
+
const IS_WINDOWS = process.platform === "win32";
|
|
164
|
+
const result = spawnSync("npm", ["i", "-g", `${pkgName}@${latestVersion}`], {
|
|
165
|
+
encoding: "utf8",
|
|
166
|
+
timeout: 120000,
|
|
167
|
+
shell: IS_WINDOWS,
|
|
168
|
+
});
|
|
215
169
|
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
try { fs.unlinkSync(oldPath); } catch (_) {}
|
|
219
|
-
try {
|
|
220
|
-
fs.renameSync(binaryPath, oldPath);
|
|
221
|
-
} catch (e) {
|
|
222
|
-
if (fs.existsSync(binaryPath)) {
|
|
223
|
-
throw e;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
fs.renameSync(tempPath, binaryPath);
|
|
228
|
-
} catch (e) {
|
|
229
|
-
try { fs.renameSync(oldPath, binaryPath); } catch (_) {}
|
|
230
|
-
throw e;
|
|
231
|
-
}
|
|
232
|
-
try { fs.unlinkSync(oldPath); } catch (_) {}
|
|
170
|
+
if (result.status === 0) {
|
|
171
|
+
removeHint();
|
|
233
172
|
} else {
|
|
234
|
-
|
|
173
|
+
writeHint(latestVersion, pkgName);
|
|
235
174
|
}
|
|
236
175
|
} catch (_) {
|
|
237
|
-
cleanupTemp();
|
|
238
176
|
} finally {
|
|
239
177
|
releaseLock();
|
|
240
178
|
}
|