AI-powered code review CLI using Gemini API
Project description
aireview
一款基於 Gemini API 的 AI 程式碼審查 CLI 工具。它能在你 commit 前分析已暫存(staged)的 git 變更,並直接在終端機中以繁體中文指出安全漏洞、Bug 以及改進建議。同時無縫整合了 ruff(針對 Python)與 actionlint(針對 GitHub Actions),為你提供全方位的程式碼品質檢查。
Demo
╔══════════════════════════════════════════════════════════╗
║ AI Code Review ║
╠══════════════════════════════════════════════════════════╣
║ Score: 85/100 [Python, YAML] ║
║ 1 critical 1 warning 0 suggestion ║
╚══════════════════════════════════════════════════════════╝
Summary: 發現潛在的路徑遍歷風險與靜態分析工具回報的格式問題,請在提交前修正。
✖ CRITICAL 存在路徑遍歷(Path Traversal)安全漏洞 🔒 security
└─ src/utils.py:12
在讀取檔案時直接使用了外部傳入的 `filepath`,惡意使用者可以構造包含 `../../` 的路徑來讀取系統上的任意檔案。
Fix:
在開啟檔案前,應使用 `os.path.abspath` 驗證檔案路徑是否位於當前工作目錄內。
```python
import os
base_dir = os.path.abspath(".")
abs_path = os.path.abspath(filepath)
if abs_path.startswith(base_dir):
with open(abs_path, "r") as f:
# ...
```
──────────────────────────────────────────────────────
▲ WARNING Ruff 靜態分析警告 ♻ code_quality
└─ src/app.py:5
Ruff 分析回報: `F401 [*] os imported but unused`。引入了未使用的模組會增加不必要的開銷並降低程式碼可讀性。
Fix:
請移除未使用的 `import os`。
──────────────────────────────────────────────────────
⚠ Critical issues found — review before committing.
Features
- Gemini AI Code Review:使用
gemini-3.1-flash-lite模型,以繁體中文提供精準、簡潔(不超過 300 字)的程式碼審查。 - Ruff 靜態分析整合:自動針對變更的 Python 檔案執行
ruff,並將檢查結果提供給 AI 一併分析。 - Actionlint 整合:自動針對 GitHub Actions 的 YAML 變更執行
actionlint檢查(若未安裝則使用基本 YAML 語法驗證)。 - 支援 .env 環境變數:自動從本地
.env檔案載入 API Key(支援export前綴與行內註解)。 - 靈活的使用方式:支援審查已暫存(staged)的變更、特定檔案,或是整個工作區的所有變更。
Installation
PyPI / pipx (recommended)
pipx installs the CLI in an isolated environment, making it available globally.
Homebrew (macOS)
brew install pipx
# 從 PyPI 全域安裝 (推薦)
pipx install aireview-joy
From source
git clone https://github.com/Joy0130/aireview.git
cd aireview
pipx install .
Setup
Set your Gemini API key as an environment variable:
export GEMINI_API_KEY="your-key-here"
Or add it to a .env file in your repository root:
GEMINI_API_KEY=your-key-here
Get a free API key at Google AI Studio.
Usage
aireview # 審查已暫存的變更 (需先執行 git add)
aireview --full # 審查工作區內的所有變更
aireview --file src/app.py # 審查特定的檔案
aireview --fix # 強調修正建議
aireview --strict # 嚴格模式 (會抓出更多細節問題)
aireview --output json # 輸出機器可讀的 JSON 格式
aireview --output compact # 輸出精簡格式 (適合用於腳本)
aireview --no-fail # 永遠以 exit 0 退出 (避免阻擋 CI 流程)
Integrate with aicommit
# 審查已暫存的變更,如果沒有問題則進行 commit
aireview && aicommit
# 或者將精簡版的審查摘要傳遞給 aicommit
aireview --output compact | aicommit
Configuration
Create .aireview.yml in your repo root or ~/.aireview.yml:
language: auto
strict_level: standard # relaxed | standard | strict
focus:
- security
- bugs
- code_quality
- performance
ignore_paths:
- "*.lock"
- "dist/"
- "node_modules/"
max_diff_lines: 3000
gemini_model: gemini-3.1-flash-lite
show_fix_suggestions: true
fail_on_critical: true
Exit codes
| Code | Meaning |
|---|---|
0 |
Review passed (no critical issues, or --no-fail) |
1 |
Critical issues found |
1 |
Configuration error or API failure |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aireview_joy-0.1.1.tar.gz.
File metadata
- Download URL: aireview_joy-0.1.1.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
330f91dee8ca7f8f21e527e671e330ef33baa661939ac0151118697db60ba4a6
|
|
| MD5 |
b9efa77b17eebb5a28e39b56b231d71f
|
|
| BLAKE2b-256 |
abee1db0c72449bf75dff10c07a2889c93afdc0581b9e70f5ce0427707ec19c4
|
Provenance
The following attestation bundles were made for aireview_joy-0.1.1.tar.gz:
Publisher:
ci.yml on Joy0130/aireview
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aireview_joy-0.1.1.tar.gz -
Subject digest:
330f91dee8ca7f8f21e527e671e330ef33baa661939ac0151118697db60ba4a6 - Sigstore transparency entry: 1754720859
- Sigstore integration time:
-
Permalink:
Joy0130/aireview@ba9fa94d2f6696549ffb9776c3696011a3d3734e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Joy0130
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ba9fa94d2f6696549ffb9776c3696011a3d3734e -
Trigger Event:
push
-
Statement type:
File details
Details for the file aireview_joy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aireview_joy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1aed98d1bd713232e5cf150c5d153cb8c3cf6f71514a9e8f37a0d3ed25b4ac0
|
|
| MD5 |
2f3be6de8e31355faedb1e40e9d214b5
|
|
| BLAKE2b-256 |
dd76a29fb3c5ebc8d05338286424876a899b95b04d2ddbc350d3ea39fdafa180
|
Provenance
The following attestation bundles were made for aireview_joy-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on Joy0130/aireview
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aireview_joy-0.1.1-py3-none-any.whl -
Subject digest:
f1aed98d1bd713232e5cf150c5d153cb8c3cf6f71514a9e8f37a0d3ed25b4ac0 - Sigstore transparency entry: 1754720882
- Sigstore integration time:
-
Permalink:
Joy0130/aireview@ba9fa94d2f6696549ffb9776c3696011a3d3734e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Joy0130
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ba9fa94d2f6696549ffb9776c3696011a3d3734e -
Trigger Event:
push
-
Statement type: