@itechmeat/open-code-review 0.0.0-stage → 1.13.1-fork.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +209 -2
- package/bin/ocr.js +141 -0
- package/imgs/benchmark-en.png +0 -0
- package/imgs/benchmark-ja.png +0 -0
- package/imgs/benchmark-ko.png +0 -0
- package/imgs/benchmark-ru.png +0 -0
- package/imgs/benchmark-zh.png +0 -0
- package/imgs/highlights-en.png +0 -0
- package/imgs/highlights-ja.png +0 -0
- package/imgs/highlights-ko.png +0 -0
- package/imgs/highlights-ru.png +0 -0
- package/imgs/highlights-zh.png +0 -0
- package/imgs/logo-core.svg +1 -0
- package/imgs/logo.svg +1 -0
- package/imgs/providers.jpg +0 -0
- package/package.json +43 -4
- package/scripts/install.js +272 -0
- package/scripts/platform.js +69 -0
- package/scripts/update.js +172 -0
- package/scripts/version.js +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this definition, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a complaint) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that you distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act on
|
|
170
|
+
Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the same
|
|
186
|
+
"printed page" as the copyright notice for easier identification within
|
|
187
|
+
third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 alibaba/open-code-review Contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,210 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://open-codereview.ai">
|
|
3
|
+
<img src="imgs/logo-core.svg" alt="OpenCodeReview logo" width="180" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1>OpenCodeReview</h1>
|
|
6
|
+
</div>
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://trendshift.io/repositories/41087?utm_source=repository-badge&utm_medium=badge&utm_campaign=badge-repository-41087" target="_blank" rel="noopener noreferrer">
|
|
10
|
+
<img src="https://trendshift.io/api/badge/repositories/41087" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 280px; height: 60px;" width="280" height="60" />
|
|
11
|
+
</a>
|
|
12
|
+
</p>
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://trendshift.io/repositories/41087" target="_blank">
|
|
15
|
+
<img src="https://trendshift.io/api/badge/trendshift/repositories/41087/weekly" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 280px; height: 60px;" width="280" height="60" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://trendshift.io/repositories/41087" target="_blank">
|
|
18
|
+
<img src="https://trendshift.io/api/badge/trendshift/repositories/41087/monthly?language=Go" alt="alibaba%2Fopen-code-review | Trendshift" style="width: 280px; height: 60px;" width="280" height="60" />
|
|
19
|
+
</a>
|
|
20
|
+
</p>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="https://www.npmjs.com/package/@itechmeat/open-code-review"><img alt="npm" src="https://img.shields.io/npm/v/@itechmeat/open-code-review?style=flat-square" /></a>
|
|
23
|
+
<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>
|
|
24
|
+
<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>
|
|
25
|
+
<a href="https://deepwiki.com/alibaba/open-code-review"><img alt="Ask DeepWiki" src="https://img.shields.io/badge/Ask-DeepWiki-blue?style=flat-square" /></a>
|
|
26
|
+
<a href="https://www.bestpractices.dev/projects/13328"><img alt="OpenSSF Best Practices" src="https://img.shields.io/badge/OpenSSF-Gold-D4AF37?style=flat-square" /></a>
|
|
27
|
+
</p>
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a href="#supported-platforms"><img alt="Windows" src="https://img.shields.io/badge/Windows-supported-blue.svg" /></a>
|
|
30
|
+
<a href="#supported-platforms"><img alt="macOS" src="https://img.shields.io/badge/macOS-supported-blue.svg" /></a>
|
|
31
|
+
<a href="#supported-platforms"><img alt="Linux" src="https://img.shields.io/badge/Linux-supported-blue.svg" /></a>
|
|
32
|
+
<a href="#supported-agents"><img alt="Claude Code" src="https://img.shields.io/badge/Claude_Code-supported-blueviolet.svg" /></a>
|
|
33
|
+
<a href="#supported-agents"><img alt="Codex" src="https://img.shields.io/badge/Codex-supported-blueviolet.svg" /></a>
|
|
34
|
+
<a href="#supported-agents"><img alt="Cursor" src="https://img.shields.io/badge/Cursor-supported-blueviolet.svg" /></a>
|
|
35
|
+
<a href="#supported-agents"><img alt="Kimi Code" src="https://img.shields.io/badge/Kimi_Code-supported-blueviolet.svg" /></a>
|
|
36
|
+
</p>
|
|
37
|
+
<p align="center">
|
|
38
|
+
English | <a href="docs/i18n/README.zh-CN.md">简体中文</a> | <a href="docs/i18n/README.ja-JP.md">日本語</a> | <a href="docs/i18n/README.ko-KR.md">한국어</a> | <a href="docs/i18n/README.ru-RU.md">Русский</a>
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
> **About this fork.** This is a fork of [alibaba/open-code-review](https://github.com/alibaba/open-code-review) that tracks upstream and adds a small set of changes. Install it with `npm install -g @itechmeat/open-code-review`, or with the install scripts: `curl -fsSL https://raw.githubusercontent.com/itechmeat/open-code-review/main/install.sh | sh` on macOS and Linux, `irm https://raw.githubusercontent.com/itechmeat/open-code-review/main/install.ps1 | iex` on Windows. The documentation at open-codereview.ai describes upstream. The release scheme and other details are in [docs/fork-release.md](docs/fork-release.md).
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## What is Open Code Review?
|
|
46
|
+
|
|
47
|
+
Open Code Review is an AI-powered code review CLI tool. It originated as Alibaba Group's internal official AI code review assistant — over the past two years, it has served tens of thousands of developers and identified millions of code defects. After thorough validation at massive scale, we incubated it into an open source project for the community. Simply configure a model endpoint to get started.
|
|
48
|
+
|
|
49
|
+
It reads Git diffs, sends changed files to a configurable LLM via an agent with tool-use capabilities, and generates structured review comments with line-level precision. The agent can read full file contents, search the codebase, inspect other changed files for context, and produce deep reviews — not just surface-level diff feedback. Beyond diff review, `ocr scan` reviews entire files for auditing unfamiliar codebases or directories that have no meaningful diff.
|
|
50
|
+
|
|
51
|
+
Visit the [official website](https://open-codereview.ai) for more details.
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
## Benchmark
|
|
56
|
+
|
|
57
|
+
> 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.
|
|
58
|
+
|
|
59
|
+
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).
|
|
60
|
+
|
|
61
|
+
<a href="https://huggingface.co/datasets/Alibaba-Aone/aacr-bench"><img src="https://huggingface.co/favicon.ico" alt="Hugging Face" width="20" height="20" /> Explore the AACR-Bench dataset on Hugging Face</a>.
|
|
62
|
+
|
|
63
|
+
| Metric | What it measures | Why it matters |
|
|
64
|
+
|--------|-----------------|----------------|
|
|
65
|
+
| **F1** | Harmonic mean of precision and recall | Best single number for overall review quality |
|
|
66
|
+
| **Precision** | Proportion of reported issues that are real defects | Higher = fewer false alarms to triage |
|
|
67
|
+
| **Recall** | Proportion of real defects that are found | Higher = fewer issues slip through review |
|
|
68
|
+
| **Avg Time** | Wall-clock time per review | Matters for CI pipeline latency |
|
|
69
|
+
| **Avg Token** | Total tokens consumed per review | Directly impacts API cost |
|
|
70
|
+
|
|
71
|
+

|
|
72
|
+
|
|
73
|
+
## Why Open Code Review?
|
|
74
|
+
|
|
75
|
+
### The Problem with General-Purpose Agents
|
|
76
|
+
|
|
77
|
+
If you've used general-purpose agents like Claude Code with Skills for code review, you've likely encountered these pain points:
|
|
78
|
+
|
|
79
|
+
- **Incomplete coverage** — On larger changesets, agents tend to "cut corners," selectively reviewing only some files and missing others.
|
|
80
|
+
- **Position drift** — Reported issues frequently don't match the actual code location, with line numbers or file references drifting off target.
|
|
81
|
+
- **Unstable quality** — Natural-language-driven Skills are hard to debug, and review quality fluctuates significantly with minor prompt variations.
|
|
82
|
+
|
|
83
|
+
The root cause: a purely language-driven architecture lacks hard constraints on the review process.
|
|
84
|
+
|
|
85
|
+
### Core Design: Deterministic Engineering × Agent Hybrid
|
|
86
|
+
|
|
87
|
+
Open Code Review's core philosophy is to combine deterministic engineering with an agent, each handling what it does best.
|
|
88
|
+
|
|
89
|
+
**Deterministic Engineering — Hard Constraints**
|
|
90
|
+
|
|
91
|
+
For review steps that *must not go wrong*, engineering logic — not the language model — guarantees correctness:
|
|
92
|
+
|
|
93
|
+
- **Precise file selection** — Determines exactly which files need review and which should be filtered, ensuring no important change is missed.
|
|
94
|
+
- **Smart file bundling** — Groups related files into a single review unit (e.g., `message_en.properties` and `message_zh.properties` are bundled together). Each bundle runs as a sub-agent with isolated context — a divide-and-conquer strategy that stays stable on very large changesets and naturally supports concurrent review.
|
|
95
|
+
- **Fine-grained rule matching** — Matches review rules to each file's characteristics, keeping the model's attention sharply focused and eliminating information noise at the source. Compared to purely language-driven rule guidance, template-engine-based rule matching is more stable and predictable.
|
|
96
|
+
- **External positioning and reflection modules** — Independent comment-positioning and comment-reflection modules systematically improve both the location accuracy and content accuracy of AI feedback.
|
|
97
|
+
|
|
98
|
+
**Agent — Dynamic Decision-Making**
|
|
99
|
+
|
|
100
|
+
The agent's strengths are concentrated where they matter most — dynamic decisions and dynamic context retrieval:
|
|
101
|
+
|
|
102
|
+
- **Scenario-tuned prompts** — Prompt templates deeply optimized for code review, improving effectiveness while reducing token consumption.
|
|
103
|
+
- **Scenario-tuned toolset** — Distilled from deep analysis of tool-call traces in large-scale production data — including call frequency distributions, per-tool repetition rates, and the impact of new tools on the overall call chain — resulting in a purpose-built toolset that is more stable and predictable for code review than a generic agent toolkit.
|
|
104
|
+
|
|
105
|
+
## How to Use
|
|
106
|
+
|
|
107
|
+
### Prerequisites
|
|
108
|
+
|
|
109
|
+
- **Git >= 2.41** — Open Code Review relies on Git for diff generation, code search, and repository operations.
|
|
110
|
+
|
|
111
|
+
### CLI
|
|
112
|
+
|
|
113
|
+
#### Install
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npm install -g @itechmeat/open-code-review
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
After installation, the `ocr` command is available globally.
|
|
120
|
+
|
|
121
|
+
For other installation methods (install script, GitHub Release binary, from source), see [Installation](https://open-codereview.ai/docs/installation).
|
|
122
|
+
|
|
123
|
+
#### Quick Start
|
|
124
|
+
|
|
125
|
+
**1. Configure LLM**
|
|
126
|
+
|
|
127
|
+
If the Claude Code CLI (`claude`) is installed and logged in, no setup is needed: with nothing else configured, OCR reviews through the `claude-code` provider on your Claude subscription, with the `opus` model. Otherwise configure an LLM before reviewing code, unless you use [Delegation Mode](https://open-codereview.ai/docs/delegate).
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
ocr config provider # Select a built-in provider or add a custom one
|
|
131
|
+
ocr config model # Pick a model for the active provider
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+

|
|
135
|
+
|
|
136
|
+
The interactive UI guides you through provider selection, API key entry, and model configuration, then automatically tests connectivity.
|
|
137
|
+
|
|
138
|
+
For CLI setup, environment variables, custom providers, and other advanced configuration, see [Configuration](https://open-codereview.ai/docs/configuration).
|
|
139
|
+
|
|
140
|
+
`--provider` and `--model` switch the provider or model for one run (`ocr review --provider claude-code --model sonnet`); `ocr config set provider <name>` changes the default.
|
|
141
|
+
|
|
142
|
+
**2. Review**
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
cd your-project
|
|
146
|
+
|
|
147
|
+
# Workspace mode — review all staged, unstaged, and untracked changes
|
|
148
|
+
ocr review
|
|
149
|
+
|
|
150
|
+
# Branch range — reviews feature-branch's changes since it diverged from main (merge-base mode)
|
|
151
|
+
ocr review --from main --to feature-branch
|
|
152
|
+
|
|
153
|
+
# Single commit
|
|
154
|
+
ocr review --commit abc123
|
|
155
|
+
|
|
156
|
+
# Resume an interrupted range or commit review
|
|
157
|
+
ocr session list
|
|
158
|
+
ocr review --from main --to feature-branch --resume <session-id>
|
|
159
|
+
|
|
160
|
+
# Full-file scan — review whole files instead of a diff (no git history needed)
|
|
161
|
+
ocr scan # scan the entire repository
|
|
162
|
+
ocr scan --path internal/agent # scan a directory or specific files
|
|
163
|
+
ocr scan --resume <session-id> # resume an interrupted full-file scan
|
|
164
|
+
|
|
165
|
+
# Save results to a file (recommended for AI host agents)
|
|
166
|
+
ocr review --format json --output result.json
|
|
167
|
+
|
|
168
|
+
# Delegation mode — let your AI coding agent perform the review itself
|
|
169
|
+
# OCR handles file selection and rule resolution; no LLM configuration needed
|
|
170
|
+
ocr delegate preview
|
|
171
|
+
ocr delegate rule src/main.go src/handler.go
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Documentation
|
|
175
|
+
|
|
176
|
+
Full documentation lives at **[open-codereview.ai/docs](https://open-codereview.ai/docs)**:
|
|
177
|
+
|
|
178
|
+
- [Quickstart](https://open-codereview.ai/docs/quickstart) — install and run your first review
|
|
179
|
+
- [Installation](https://open-codereview.ai/docs/installation) — all platforms and package managers
|
|
180
|
+
- [CLI Reference](https://open-codereview.ai/docs/cli-reference) — every command and flag
|
|
181
|
+
- [Review Rules](https://open-codereview.ai/docs/review-rules) — customize review rules with path filtering and targeting
|
|
182
|
+
- [Configuration](https://open-codereview.ai/docs/configuration) — config keys and environment variables
|
|
183
|
+
- [MCP Server](https://open-codereview.ai/docs/mcp) — extend the review agent with external tools
|
|
184
|
+
- Coding Agent Integrations — choose the platform you use
|
|
185
|
+
- [Claude Code](plugins/open-code-review/README.md#claude-code) — install a plugin with review slash commands
|
|
186
|
+
- [Codex](plugins/open-code-review/README.md#codex) — install a plugin with callable review skills
|
|
187
|
+
- [Cursor](plugins/open-code-review/README.md#cursor) — install a plugin with portable review skills
|
|
188
|
+
- [Kimi Code](plugins/open-code-review/README.md#kimi-code) — install a plugin with review slash commands and skills
|
|
189
|
+
- [OpenCode](plugins/open-code-review/opencode/README.md) — install native review tools and slash commands
|
|
190
|
+
- [QCA Forward](plugins/open-code-review/qca/README.md) — run delegation mode with the QCA host model and a ready-to-publish template
|
|
191
|
+
- [Skill-compatible agents](https://open-codereview.ai/docs/agent-skill) — install the portable agent skill
|
|
192
|
+
- Review Execution Modes — after integration, choose which LLM performs the review
|
|
193
|
+
- [Default (OCR-managed)](https://open-codereview.ai/docs/configuration) — OCR runs the review using its configured LLM
|
|
194
|
+
- [Delegation Mode](https://open-codereview.ai/docs/delegate) — your coding agent runs the review using its own LLM; no OCR API key required
|
|
195
|
+
- [CI/CD Integration](https://open-codereview.ai/docs/cicd) — GitHub Actions, GitLab CI, GitFlic CI, and Gerrit integration
|
|
196
|
+
- [Session Viewer](https://open-codereview.ai/docs/viewer) — browse and replay review sessions in browser, mark comments as fixed or ignored and hide them while you work through the findings
|
|
197
|
+
- [Telemetry](https://open-codereview.ai/docs/telemetry) — OpenTelemetry integration for observability
|
|
198
|
+
- [FAQ](https://open-codereview.ai/docs/faq) — common questions and troubleshooting
|
|
199
|
+
|
|
200
|
+
## Contributing
|
|
201
|
+
|
|
202
|
+
This project exists thanks to all the people who contribute. See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding guidelines, and how to submit pull requests.
|
|
203
|
+
|
|
204
|
+
<a href="https://github.com/alibaba/open-code-review/graphs/contributors">
|
|
205
|
+
<img src="https://contrib.rocks/image?repo=alibaba/open-code-review" />
|
|
206
|
+
</a>
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
[Apache-2.0](LICENSE) — Copyright 2026 Alibaba
|
package/bin/ocr.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Copyright 2026 alibaba/open-code-review Contributors
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { spawn } = require("child_process");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const os = require("os");
|
|
12
|
+
|
|
13
|
+
const { resolveNativeBinary } = require("../scripts/platform");
|
|
14
|
+
const { version: packageVersion } = require("../package.json");
|
|
15
|
+
const { shouldShowUpdateHint } = require("../scripts/version");
|
|
16
|
+
|
|
17
|
+
// Maps a child process result to the launcher exit code.
|
|
18
|
+
// A child killed by a signal has status = null, which must not fall through
|
|
19
|
+
// to a clean 0 — pipelines gating on the exit code would read an OOM kill
|
|
20
|
+
// (or any signal death) as success. Conventional 128+signo is used instead.
|
|
21
|
+
function launcherExitCode(result) {
|
|
22
|
+
if (result.signal) {
|
|
23
|
+
return 128 + (os.constants.signals[result.signal] ?? 1);
|
|
24
|
+
}
|
|
25
|
+
return result.status ?? (result.error ? 1 : 0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Returns a signal handler that forwards the signal to a child process.
|
|
29
|
+
function forwardSignal(child, signal) {
|
|
30
|
+
return () => {
|
|
31
|
+
child.kill(signal);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function installSignalHandlers(child, platform, signalTarget) {
|
|
36
|
+
const handlers = [];
|
|
37
|
+
function add(signal, handler) {
|
|
38
|
+
handlers.push([signal, handler]);
|
|
39
|
+
signalTarget.on(signal, handler);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Windows sends console Ctrl+C to both attached processes. Keep the wrapper
|
|
43
|
+
// alive so it can wait for the binary, but do not call child.kill("SIGINT"):
|
|
44
|
+
// Node maps that operation to an abrupt TerminateProcess call on Windows.
|
|
45
|
+
if (platform === "win32") {
|
|
46
|
+
add("SIGINT", () => {});
|
|
47
|
+
} else {
|
|
48
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
49
|
+
add(signal, forwardSignal(child, signal));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
for (const [signal, handler] of handlers) {
|
|
55
|
+
signalTarget.removeListener(signal, handler);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { launcherExitCode, forwardSignal, installSignalHandlers };
|
|
61
|
+
|
|
62
|
+
if (require.main !== module) {
|
|
63
|
+
// Required as a module (tests); the launcher body below must not run.
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const resolved = resolveNativeBinary();
|
|
68
|
+
if (!resolved) {
|
|
69
|
+
console.error(
|
|
70
|
+
"[ERROR] OpenCodeReview binary not found. Run: npm install -g @itechmeat/open-code-review"
|
|
71
|
+
);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
const binaryPath = resolved.path;
|
|
75
|
+
|
|
76
|
+
const hintFile = path.join(os.homedir(), ".opencodereview", "update-available");
|
|
77
|
+
try {
|
|
78
|
+
const hint = JSON.parse(fs.readFileSync(hintFile, "utf8"));
|
|
79
|
+
if (hint.pkg === require("../package.json").name && shouldShowUpdateHint(hint.version, packageVersion)) {
|
|
80
|
+
console.error(
|
|
81
|
+
`\x1b[33m[ocr] A new version (v${hint.version}) is available. Run to update:\x1b[0m\n` +
|
|
82
|
+
`\x1b[33m npm i -g ${hint.pkg}@${hint.version}\x1b[0m\n`
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
fs.unlinkSync(hintFile);
|
|
86
|
+
}
|
|
87
|
+
} catch (_) {}
|
|
88
|
+
|
|
89
|
+
if (!process.env.OCR_NO_UPDATE) {
|
|
90
|
+
const stateDir = path.join(os.homedir(), ".opencodereview");
|
|
91
|
+
const tsFile = path.join(stateDir, "last-update-check");
|
|
92
|
+
const cooldownMs =
|
|
93
|
+
(parseInt(process.env.OCR_UPDATE_INTERVAL, 10) || 18) * 60 * 1000;
|
|
94
|
+
|
|
95
|
+
let shouldCheck = true;
|
|
96
|
+
try {
|
|
97
|
+
const mt = fs.statSync(tsFile).mtimeMs;
|
|
98
|
+
if (Date.now() - mt < cooldownMs) shouldCheck = false;
|
|
99
|
+
} catch (_) {}
|
|
100
|
+
|
|
101
|
+
if (shouldCheck) {
|
|
102
|
+
const updateScript = path.join(__dirname, "..", "scripts", "update.js");
|
|
103
|
+
const child = spawn(process.execPath, [updateScript], {
|
|
104
|
+
detached: true,
|
|
105
|
+
stdio: "ignore",
|
|
106
|
+
env: Object.assign({}, process.env, { OCR_NO_UPDATE: "1" }),
|
|
107
|
+
});
|
|
108
|
+
child.unref();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
113
|
+
stdio: "inherit",
|
|
114
|
+
env: process.env,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const removeSignalHandlers = installSignalHandlers(
|
|
118
|
+
child,
|
|
119
|
+
process.platform,
|
|
120
|
+
process
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
let settled = false;
|
|
124
|
+
function settle(result) {
|
|
125
|
+
if (settled) return;
|
|
126
|
+
settled = true;
|
|
127
|
+
removeSignalHandlers();
|
|
128
|
+
process.exitCode = launcherExitCode(result);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Spawn failures surface through "error", not "close" alone. Setting
|
|
132
|
+
// exitCode lets a piped diagnostic drain before the wrapper terminates.
|
|
133
|
+
child.on("error", (err) => {
|
|
134
|
+
console.error(`[ERROR] Failed to start ${binaryPath}: ${err.message}`);
|
|
135
|
+
settle({ error: err });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Wait for child to exit and propagate its exit status
|
|
139
|
+
child.on("close", (code, signal) => {
|
|
140
|
+
settle({ status: code, signal: signal });
|
|
141
|
+
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" version="1.1" width="64" height="64" viewBox="0 0 64 64"><path d="M16.011564254260254,24.651044499999998C14.199108154260253,26.0486085,12.604812654260254,27.6949085,11.290275574260255,29.5567475C11.202753064260254,29.6807115,10.984476089260253,29.5737765,11.051337242260255,29.4375555C12.365951554260254,26.7591665,14.005819354260254,24.3629835,15.886684454260255,22.313341100000002L15.886684454260255,14.091053C15.886684454260255,13.28568935,16.539560354260253,12.6328125,17.344924954260254,12.6328125L46.644013054260256,12.6328125C47.449376054260256,12.6328125,48.10225405426026,13.28568935,48.10225405426026,14.091054L48.10225405426026,24.7461315C43.604340054260255,21.2891407,37.94170905426026,19.4149723,31.994634054260253,19.4149723C26.104784054260254,19.4149723,20.491794554260252,21.2537956,16.011564254260254,24.651044499999998ZM31.994557054260255,36.8882445C35.14015305426025,36.8882445,37.690160054260254,34.3323665,37.690160054260254,31.1795235C37.690160054260254,30.5937725,37.60022405426025,30.0115585,37.423505054260254,29.4532315C36.96355905426026,30.4290525,35.98299105426025,31.0517195,34.906236054260255,31.0517195C33.36864905426025,31.0517195,32.122189054260254,29.8023895,32.122189054260254,28.2612605C32.122189054260254,27.1816535,32.74318005426025,26.199264499999998,33.71711105426026,25.738142500000002C33.160027054260254,25.5609745,32.57901505426025,25.4708005,31.994557054260255,25.4708005C28.848966054260252,25.4708005,26.298958054260254,28.026681500000002,26.298958054260254,31.1795235C26.298958054260254,34.3323665,28.848966054260252,36.8882445,31.994557054260255,36.8882445ZM47.15295105426026,40.7200085C49.430203054260254,38.5980795,51.40581205426025,36.0023425,52.94698805426025,33.029174499999996C53.01721305426025,32.8936925,52.805627054260256,32.7626725,52.716546054260256,32.8865775C51.36659305426026,34.7642635,49.73017205426025,36.4189305,47.87169405426025,37.8158765C47.87339505426026,37.8053205,47.87509205426026,37.7947615,47.87677505426026,37.7842025C43.46611505426026,41.092453500000005,37.971620054260256,42.9006615,32.199830054260254,42.9434055C32.19153705426025,42.9434665,32.18324405426026,42.9435235,32.174951054260255,42.9435765C32.11482705426025,42.943946499999996,32.054662054260255,42.9441415,31.994454054260252,42.9441415C26.150606054260255,42.9441185,20.577615754260254,41.1334415,16.112119654260255,37.7839245C17.329820654260253,45.4193075,23.367437054260254,51.7093845,31.457871054260252,54.2405735C31.808347054260253,54.3502275,32.18059205426025,54.3502275,32.53106805426025,54.2405775C39.557904054260256,52.0421445,45.03618705426025,47.0081745,47.15295105426026,40.7200085Z" fill-rule="evenodd" fill="#2BDE5E"/></svg>
|
package/imgs/logo.svg
ADDED
|
@@ -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_2815"><rect x="0" y="0" width="500" height="500" rx="0"/></clipPath></defs><g clip-path="url(#master_svg0_3_2815)"><rect x="0" y="0" width="500" height="500" rx="0" fill="#35BD5F" fill-opacity="1"/><path d="M369.391824777832,207.16973852783204L369.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.16844852783203C135.42535377783202,207.120678527832,135.47695877783204,207.07293852783204,135.52861377783202,207.02521852783204Q150.71416877783201,194.43234852783203,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.37405352783202,369.391824777832,207.16973852783204ZM252.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.510884777832,356.763438527832,357.584414777832,331.664328527832,365.268044777832,303.130198527832Q389.75965477783205,285.49699852783203,408.07666477783204,260.794778527832C408.73459477783206,259.907508527832,408.54608477783205,258.641948527832,407.65244477783205,257.99271852783204L398.67002477783205,251.46689852783203C397.77640477783206,250.81766852783204,396.535654777832,251.00403852783202,395.877174777832,251.89087852783203Q383.89688477783204,268.02576852783204,369.057804777832,280.89220852783205L369.05826477783205,280.885928527832L368.94913477783206,280.98634852783204Q352.69916477783204,295.05307852783204,333.02570477783206,305.20590852783204Q296.653174777832,323.976558527832,256.24495477783205,325.33028852783207C254.95948477783202,325.35753852783205,253.67179477783202,325.37118852783203,252.38211477783204,325.37118852783203C208.41640477783204,325.37118852783203,166.76860077783203,309.49235852783204,135.70742077783203,280.887278527832C138.50840777783202,318.39349852783204,158.79283877783203,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="#121519" fill-opacity="1"/></g></svg>
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itechmeat/open-code-review",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.13.1-fork.1",
|
|
4
|
+
"description": "OpenCodeReview CLI — AI-powered code review tool",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ocr": "bin/ocr.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/ocr.js",
|
|
10
|
+
"scripts/install.js",
|
|
11
|
+
"scripts/update.js",
|
|
12
|
+
"scripts/version.js",
|
|
13
|
+
"scripts/platform.js",
|
|
14
|
+
"imgs/"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"postinstall": "node scripts/install.js",
|
|
18
|
+
"test:github-actions": "node scripts/github-actions/post-review-comments.test.js && node scripts/github-actions/check-translation-sync.test.js && node scripts/github-actions/action-contract.test.js && node scripts/github-actions/check-plugin-contract.test.js && node scripts/github-actions/release-contract.test.js",
|
|
19
|
+
"test:update": "node scripts/version.test.js",
|
|
20
|
+
"test:launcher": "node bin/ocr.test.js"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/itechmeat/open-code-review.git"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"ocrConfig": {
|
|
30
|
+
"urlPattern": "https://github.com/itechmeat/open-code-review/releases/download/v{version}/opencodereview-{os}-{arch}",
|
|
31
|
+
"checksumPattern": "https://github.com/itechmeat/open-code-review/releases/download/v{version}/sha256sum.txt"
|
|
32
|
+
},
|
|
33
|
+
"optionalDependencies": {
|
|
34
|
+
"@itechmeat/ocr-darwin-arm64": "1.13.1-fork.1",
|
|
35
|
+
"@itechmeat/ocr-darwin-x64": "1.13.1-fork.1",
|
|
36
|
+
"@itechmeat/ocr-linux-arm64": "1.13.1-fork.1",
|
|
37
|
+
"@itechmeat/ocr-linux-x64": "1.13.1-fork.1",
|
|
38
|
+
"@itechmeat/ocr-win32-arm64": "1.13.1-fork.1",
|
|
39
|
+
"@itechmeat/ocr-win32-x64": "1.13.1-fork.1"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=14"
|
|
43
|
+
},
|
|
44
|
+
"license": "Apache-2.0"
|
|
45
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Copyright 2026 alibaba/open-code-review Contributors
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const https = require("https");
|
|
11
|
+
const crypto = require("crypto");
|
|
12
|
+
|
|
13
|
+
const { IS_WINDOWS, BINARY_FILENAME: BINARY_NAME, resolveNativeBinary } = require("./platform");
|
|
14
|
+
|
|
15
|
+
const packageRoot = path.join(__dirname, "..");
|
|
16
|
+
const binDir = path.join(packageRoot, "bin");
|
|
17
|
+
const binaryDest = path.join(binDir, BINARY_NAME);
|
|
18
|
+
|
|
19
|
+
function info(msg) {
|
|
20
|
+
console.log(`[INFO] ${msg}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function warn(msg) {
|
|
24
|
+
console.warn(`[WARN] ${msg}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function error(msg) {
|
|
28
|
+
console.error(`[ERROR] ${msg}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function detectPlatform() {
|
|
32
|
+
let os = process.platform;
|
|
33
|
+
let arch = process.arch;
|
|
34
|
+
|
|
35
|
+
switch (arch) {
|
|
36
|
+
case "x64":
|
|
37
|
+
arch = "amd64";
|
|
38
|
+
break;
|
|
39
|
+
case "arm64":
|
|
40
|
+
arch = "arm64";
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Unsupported architecture: ${arch}. Supported: amd64 (x64), arm64`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
switch (os) {
|
|
49
|
+
case "linux":
|
|
50
|
+
case "darwin":
|
|
51
|
+
break;
|
|
52
|
+
case "win32":
|
|
53
|
+
os = "windows";
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Unsupported operating system: ${os}. Supported: linux, darwin, win32`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { os, arch };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function loadPackageJson() {
|
|
65
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf8"));
|
|
66
|
+
if (!pkg.version) {
|
|
67
|
+
throw new Error("Missing version field in package.json");
|
|
68
|
+
}
|
|
69
|
+
if (!pkg.ocrConfig || !pkg.ocrConfig.urlPattern) {
|
|
70
|
+
throw new Error("Missing ocrConfig.urlPattern in package.json");
|
|
71
|
+
}
|
|
72
|
+
return pkg;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function resolveVersion(pkg) {
|
|
76
|
+
const envVersion = process.env.OCR_VERSION;
|
|
77
|
+
if (envVersion) {
|
|
78
|
+
const v = envVersion.startsWith("v") ? envVersion.slice(1) : envVersion;
|
|
79
|
+
info(`Using pinned version from OCR_VERSION: ${v}`);
|
|
80
|
+
return v;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
info(`Using version from package.json: ${pkg.version}`);
|
|
84
|
+
return pkg.version;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function buildUrl(pattern, vars) {
|
|
88
|
+
return pattern
|
|
89
|
+
.replace(/\{version\}/g, vars.version)
|
|
90
|
+
.replace(/\{os\}/g, vars.os)
|
|
91
|
+
.replace(/\{arch\}/g, vars.arch);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function download(url, maxRedirects = 10) {
|
|
95
|
+
if (!url.startsWith("https")) {
|
|
96
|
+
return Promise.reject(new Error(`Refusing non-HTTPS download: ${url}`));
|
|
97
|
+
}
|
|
98
|
+
if (maxRedirects <= 0) {
|
|
99
|
+
return Promise.reject(new Error(`Too many redirects fetching ${url}`));
|
|
100
|
+
}
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
https.get(url, (res) => {
|
|
103
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
104
|
+
res.resume();
|
|
105
|
+
download(res.headers.location, maxRedirects - 1).then(resolve).catch(reject);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (res.statusCode !== 200) {
|
|
109
|
+
res.resume();
|
|
110
|
+
reject(new Error(`HTTP ${res.statusCode} fetching ${url}`));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
resolve(res);
|
|
114
|
+
}).on("error", reject);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function downloadText(url) {
|
|
119
|
+
const res = await download(url);
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
let data = "";
|
|
122
|
+
res.on("data", (chunk) => (data += chunk));
|
|
123
|
+
res.on("end", () => resolve(data));
|
|
124
|
+
res.on("error", reject);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function downloadBinary(url, destPath) {
|
|
129
|
+
const res = await download(url);
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
const fileStream = fs.createWriteStream(destPath);
|
|
132
|
+
res.on("error", (err) => {
|
|
133
|
+
fileStream.destroy();
|
|
134
|
+
fs.unlink(destPath, () => {});
|
|
135
|
+
reject(err);
|
|
136
|
+
});
|
|
137
|
+
res.pipe(fileStream);
|
|
138
|
+
fileStream.on("finish", () => fileStream.close(() => resolve()));
|
|
139
|
+
fileStream.on("error", (err) => {
|
|
140
|
+
fs.unlink(destPath, () => {});
|
|
141
|
+
reject(err);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function computeChecksum(filePath) {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
const hash = crypto.createHash("sha256");
|
|
149
|
+
const stream = fs.createReadStream(filePath);
|
|
150
|
+
stream.on("data", (chunk) => hash.update(chunk));
|
|
151
|
+
stream.on("end", () => resolve(hash.digest("hex")));
|
|
152
|
+
stream.on("error", reject);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function main() {
|
|
157
|
+
info("OpenCodeReview Installer");
|
|
158
|
+
info("=========================");
|
|
159
|
+
|
|
160
|
+
const existing = resolveNativeBinary();
|
|
161
|
+
if (existing && existing.fromPlatformPkg) {
|
|
162
|
+
info("Binary provided by platform package, skipping download.");
|
|
163
|
+
info(` ${existing.path}`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const { os, arch } = detectPlatform();
|
|
168
|
+
info(`Detected platform: ${os}/${arch}`);
|
|
169
|
+
|
|
170
|
+
const pkg = loadPackageJson();
|
|
171
|
+
const version = resolveVersion(pkg);
|
|
172
|
+
const config = pkg.ocrConfig;
|
|
173
|
+
|
|
174
|
+
if (!fs.existsSync(binDir)) {
|
|
175
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!IS_WINDOWS) {
|
|
179
|
+
const jsWrapper = path.join(binDir, "ocr.js");
|
|
180
|
+
if (fs.existsSync(jsWrapper)) {
|
|
181
|
+
try {
|
|
182
|
+
fs.chmodSync(jsWrapper, 0o755);
|
|
183
|
+
} catch (e) {
|
|
184
|
+
warn(`Could not make ocr.js executable: ${e.message}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const vars = { version, os, arch };
|
|
190
|
+
let downloadUrl = buildUrl(config.urlPattern, vars);
|
|
191
|
+
if (IS_WINDOWS) {
|
|
192
|
+
downloadUrl += ".exe";
|
|
193
|
+
}
|
|
194
|
+
info(`Downloading ${downloadUrl} ...`);
|
|
195
|
+
|
|
196
|
+
await downloadBinary(downloadUrl, binaryDest);
|
|
197
|
+
if (!IS_WINDOWS) {
|
|
198
|
+
fs.chmodSync(binaryDest, 0o755);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (config.checksumPattern) {
|
|
202
|
+
const checksumUrl = buildUrl(config.checksumPattern, vars);
|
|
203
|
+
info("Verifying checksum...");
|
|
204
|
+
let shaContent;
|
|
205
|
+
try {
|
|
206
|
+
shaContent = await downloadText(checksumUrl);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
try { fs.unlinkSync(binaryDest); } catch (_) {}
|
|
209
|
+
throw new Error(`Failed to download checksum from ${checksumUrl}: ${e.message}`);
|
|
210
|
+
}
|
|
211
|
+
let actualSha;
|
|
212
|
+
try {
|
|
213
|
+
actualSha = await computeChecksum(binaryDest);
|
|
214
|
+
} catch (e) {
|
|
215
|
+
try { fs.unlinkSync(binaryDest); } catch (_) {}
|
|
216
|
+
throw new Error(`Failed to compute checksum for ${binaryDest}: ${e.message}`);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
let verified = false;
|
|
220
|
+
for (const line of shaContent.split("\n")) {
|
|
221
|
+
const trimmed = line.trim();
|
|
222
|
+
if (trimmed.includes(`-${os}-${arch}`)) {
|
|
223
|
+
const expectedSha = trimmed.split(/\s+/)[0].toLowerCase();
|
|
224
|
+
if (expectedSha) {
|
|
225
|
+
if (actualSha !== expectedSha) {
|
|
226
|
+
try { fs.unlinkSync(binaryDest); } catch (_) {}
|
|
227
|
+
throw new Error(
|
|
228
|
+
`Checksum mismatch! Expected: ${expectedSha}, Got: ${actualSha}`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
info("Checksum verified.");
|
|
232
|
+
verified = true;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!verified) {
|
|
238
|
+
try { fs.unlinkSync(binaryDest); } catch (_) {}
|
|
239
|
+
throw new Error(
|
|
240
|
+
`No matching checksum entry for ${os}-${arch} in ${checksumUrl}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
info(`Installed: ${binaryDest}`);
|
|
246
|
+
info("");
|
|
247
|
+
info("OpenCodeReview is ready!");
|
|
248
|
+
info("");
|
|
249
|
+
info("Quick start:");
|
|
250
|
+
info(" ocr version Show version info");
|
|
251
|
+
info(" ocr config set Configure your LLM provider");
|
|
252
|
+
info(" ocr review Start a code review");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (require.main === module) {
|
|
256
|
+
main().catch((err) => {
|
|
257
|
+
error(err.message);
|
|
258
|
+
process.exit(1);
|
|
259
|
+
});
|
|
260
|
+
} else {
|
|
261
|
+
module.exports = {
|
|
262
|
+
IS_WINDOWS,
|
|
263
|
+
BINARY_NAME,
|
|
264
|
+
detectPlatform,
|
|
265
|
+
loadPackageJson,
|
|
266
|
+
buildUrl,
|
|
267
|
+
download,
|
|
268
|
+
downloadText,
|
|
269
|
+
downloadBinary,
|
|
270
|
+
computeChecksum,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2026 alibaba/open-code-review Contributors
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
|
|
9
|
+
const IS_WINDOWS = process.platform === "win32";
|
|
10
|
+
const BINARY_FILENAME = IS_WINDOWS ? "opencodereview.exe" : "opencodereview";
|
|
11
|
+
|
|
12
|
+
const PLATFORM_PKG = {
|
|
13
|
+
"darwin-arm64": "@itechmeat/ocr-darwin-arm64",
|
|
14
|
+
"darwin-x64": "@itechmeat/ocr-darwin-x64",
|
|
15
|
+
"linux-arm64": "@itechmeat/ocr-linux-arm64",
|
|
16
|
+
"linux-x64": "@itechmeat/ocr-linux-x64",
|
|
17
|
+
"win32-arm64": "@itechmeat/ocr-win32-arm64",
|
|
18
|
+
"win32-x64": "@itechmeat/ocr-win32-x64",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function getPlatformPackageName() {
|
|
22
|
+
const key = `${process.platform}-${process.arch}`;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const parentPkg = JSON.parse(
|
|
26
|
+
fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8")
|
|
27
|
+
);
|
|
28
|
+
const optDeps = parentPkg.optionalDependencies || {};
|
|
29
|
+
for (const name of Object.keys(optDeps)) {
|
|
30
|
+
if (name.endsWith(`-${key}`)) {
|
|
31
|
+
return name;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} catch (_) {}
|
|
35
|
+
|
|
36
|
+
return PLATFORM_PKG[key] || null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function resolveNativeBinary() {
|
|
40
|
+
const pkgName = getPlatformPackageName();
|
|
41
|
+
if (pkgName) {
|
|
42
|
+
try {
|
|
43
|
+
const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`));
|
|
44
|
+
const binPath = path.join(pkgDir, "bin", BINARY_FILENAME);
|
|
45
|
+
if (fs.existsSync(binPath)) {
|
|
46
|
+
return { path: binPath, fromPlatformPkg: true };
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (err.code !== "MODULE_NOT_FOUND") {
|
|
50
|
+
console.warn(`[WARN] Unexpected error resolving ${pkgName}: ${err.message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const legacyPath = path.join(__dirname, "..", "bin", BINARY_FILENAME);
|
|
56
|
+
if (fs.existsSync(legacyPath)) {
|
|
57
|
+
return { path: legacyPath, fromPlatformPkg: false };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = {
|
|
64
|
+
IS_WINDOWS,
|
|
65
|
+
BINARY_FILENAME,
|
|
66
|
+
PLATFORM_PKG,
|
|
67
|
+
getPlatformPackageName,
|
|
68
|
+
resolveNativeBinary,
|
|
69
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Copyright 2026 alibaba/open-code-review Contributors
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const os = require("os");
|
|
11
|
+
const https = require("https");
|
|
12
|
+
const { spawnSync } = require("child_process");
|
|
13
|
+
|
|
14
|
+
const { resolveNativeBinary } = require("./platform");
|
|
15
|
+
const { loadPackageJson } = require("./install.js");
|
|
16
|
+
const { SEMVER_RE, parseVersionOutput, semverGt } = require("./version");
|
|
17
|
+
|
|
18
|
+
const stateDir = path.join(os.homedir(), ".opencodereview");
|
|
19
|
+
const tsFile = path.join(stateDir, "last-update-check");
|
|
20
|
+
const lockFile = path.join(stateDir, "update.lock");
|
|
21
|
+
const hintFile = path.join(stateDir, "update-available");
|
|
22
|
+
|
|
23
|
+
const DEFAULT_REGISTRY = "https://registry.npmjs.org";
|
|
24
|
+
|
|
25
|
+
function touchTimestamp() {
|
|
26
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
27
|
+
const now = new Date();
|
|
28
|
+
try {
|
|
29
|
+
fs.utimesSync(tsFile, now, now);
|
|
30
|
+
} catch (_) {
|
|
31
|
+
fs.writeFileSync(tsFile, now.toISOString());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function acquireLock() {
|
|
36
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
37
|
+
try {
|
|
38
|
+
fs.writeFileSync(lockFile, String(process.pid), { flag: "wx" });
|
|
39
|
+
return true;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (e.code !== "EEXIST") return false;
|
|
42
|
+
try {
|
|
43
|
+
const pid = parseInt(fs.readFileSync(lockFile, "utf8").trim(), 10);
|
|
44
|
+
process.kill(pid, 0);
|
|
45
|
+
return false;
|
|
46
|
+
} catch (_) {
|
|
47
|
+
try {
|
|
48
|
+
fs.unlinkSync(lockFile);
|
|
49
|
+
fs.writeFileSync(lockFile, String(process.pid), { flag: "wx" });
|
|
50
|
+
return true;
|
|
51
|
+
} catch (_2) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function releaseLock() {
|
|
59
|
+
try {
|
|
60
|
+
fs.unlinkSync(lockFile);
|
|
61
|
+
} catch (_) {}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getInstalledVersion(binPath) {
|
|
65
|
+
try {
|
|
66
|
+
const result = spawnSync(binPath, ["version"], {
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
timeout: 3000,
|
|
69
|
+
windowsHide: true,
|
|
70
|
+
});
|
|
71
|
+
return parseVersionOutput(result.stdout);
|
|
72
|
+
} catch (_) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function fetchLatestVersion(pkg) {
|
|
78
|
+
const registry = (pkg.publishConfig && pkg.publishConfig.registry) || DEFAULT_REGISTRY;
|
|
79
|
+
const pkgName = pkg.name;
|
|
80
|
+
if (!pkgName) return Promise.resolve(null);
|
|
81
|
+
const encodedName = pkgName.replace(/\//g, "%2F");
|
|
82
|
+
const url = `${registry.replace(/\/$/, "")}/${encodedName}/latest`;
|
|
83
|
+
if (!url.startsWith("https://")) return Promise.resolve(null);
|
|
84
|
+
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
const options = {
|
|
87
|
+
headers: { "User-Agent": "ocr-updater", Accept: "application/json" },
|
|
88
|
+
timeout: 15000,
|
|
89
|
+
};
|
|
90
|
+
const req = https
|
|
91
|
+
.get(url, options, (res) => {
|
|
92
|
+
if (res.statusCode !== 200) {
|
|
93
|
+
res.resume();
|
|
94
|
+
resolve(null);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
let data = "";
|
|
98
|
+
res.on("data", (chunk) => (data += chunk));
|
|
99
|
+
res.on("end", () => {
|
|
100
|
+
try {
|
|
101
|
+
const json = JSON.parse(data);
|
|
102
|
+
resolve(json.version || null);
|
|
103
|
+
} catch (_) {
|
|
104
|
+
resolve(null);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
res.on("error", () => resolve(null));
|
|
108
|
+
})
|
|
109
|
+
.on("error", () => resolve(null));
|
|
110
|
+
req.on("timeout", () => {
|
|
111
|
+
req.destroy();
|
|
112
|
+
resolve(null);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function writeHint(latestVersion, pkgName) {
|
|
118
|
+
try {
|
|
119
|
+
fs.writeFileSync(hintFile, JSON.stringify({ version: latestVersion, pkg: pkgName }));
|
|
120
|
+
} catch (_) {}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function removeHint() {
|
|
124
|
+
try {
|
|
125
|
+
fs.unlinkSync(hintFile);
|
|
126
|
+
} catch (_) {}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function main() {
|
|
130
|
+
touchTimestamp();
|
|
131
|
+
|
|
132
|
+
if (!acquireLock()) return;
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const resolved = resolveNativeBinary();
|
|
136
|
+
if (!resolved) return;
|
|
137
|
+
|
|
138
|
+
const installedVersion = getInstalledVersion(resolved.path);
|
|
139
|
+
if (!installedVersion) return;
|
|
140
|
+
|
|
141
|
+
const pkg = loadPackageJson();
|
|
142
|
+
const latestVersion = await fetchLatestVersion(pkg);
|
|
143
|
+
if (!latestVersion) return;
|
|
144
|
+
|
|
145
|
+
if (!SEMVER_RE.test(latestVersion)) return;
|
|
146
|
+
|
|
147
|
+
if (!semverGt(latestVersion, installedVersion)) {
|
|
148
|
+
removeHint();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const pkgName = pkg.name;
|
|
153
|
+
const IS_WINDOWS = process.platform === "win32";
|
|
154
|
+
const result = spawnSync("npm", ["i", "-g", `${pkgName}@${latestVersion}`], {
|
|
155
|
+
encoding: "utf8",
|
|
156
|
+
timeout: 120000,
|
|
157
|
+
shell: IS_WINDOWS,
|
|
158
|
+
windowsHide: true,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
if (result.status === 0) {
|
|
162
|
+
removeHint();
|
|
163
|
+
} else {
|
|
164
|
+
writeHint(latestVersion, pkgName);
|
|
165
|
+
}
|
|
166
|
+
} catch (_) {
|
|
167
|
+
} finally {
|
|
168
|
+
releaseLock();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
main().catch(() => {});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2026 alibaba/open-code-review Contributors
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
const SEMVER_RE =
|
|
7
|
+
/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
8
|
+
|
|
9
|
+
function parseVersionOutput(output) {
|
|
10
|
+
const match = String(output || "").match(
|
|
11
|
+
/v(\d+\.\d+(?:\.\d+)?(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)/
|
|
12
|
+
);
|
|
13
|
+
return match ? match[1] : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function semverGt(a, b) {
|
|
17
|
+
if (!SEMVER_RE.test(a) || !SEMVER_RE.test(b)) return false;
|
|
18
|
+
|
|
19
|
+
const aWithoutBuild = a.replace(/\+.*$/, "");
|
|
20
|
+
const bWithoutBuild = b.replace(/\+.*$/, "");
|
|
21
|
+
const pa = aWithoutBuild.replace(/-.*$/, "").split(".").map(Number);
|
|
22
|
+
const pb = bWithoutBuild.replace(/-.*$/, "").split(".").map(Number);
|
|
23
|
+
for (let i = 0; i < 3; i++) {
|
|
24
|
+
if (pa[i] > pb[i]) return true;
|
|
25
|
+
if (pa[i] < pb[i]) return false;
|
|
26
|
+
}
|
|
27
|
+
const aPre = aWithoutBuild.includes("-");
|
|
28
|
+
const bPre = bWithoutBuild.includes("-");
|
|
29
|
+
if (bPre && !aPre) return true;
|
|
30
|
+
if (!aPre || !bPre) return false;
|
|
31
|
+
const ia = aWithoutBuild.slice(aWithoutBuild.indexOf("-") + 1).split(".");
|
|
32
|
+
const ib = bWithoutBuild.slice(bWithoutBuild.indexOf("-") + 1).split(".");
|
|
33
|
+
for (let i = 0; i < Math.min(ia.length, ib.length); i++) {
|
|
34
|
+
if (ia[i] === ib[i]) continue;
|
|
35
|
+
const na = /^\d+$/.test(ia[i]);
|
|
36
|
+
const nb = /^\d+$/.test(ib[i]);
|
|
37
|
+
if (na && nb) return Number(ia[i]) > Number(ib[i]);
|
|
38
|
+
// Numeric identifiers have lower precedence than alphanumeric ones.
|
|
39
|
+
if (na !== nb) return nb;
|
|
40
|
+
return ia[i] > ib[i];
|
|
41
|
+
}
|
|
42
|
+
return ia.length > ib.length;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function shouldShowUpdateHint(hintVersion, installedVersion) {
|
|
46
|
+
if (!SEMVER_RE.test(hintVersion) || !SEMVER_RE.test(installedVersion)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return semverGt(hintVersion, installedVersion);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
SEMVER_RE,
|
|
54
|
+
parseVersionOutput,
|
|
55
|
+
semverGt,
|
|
56
|
+
shouldShowUpdateHint,
|
|
57
|
+
};
|