Skip to main content

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  # 審查特定檔案的變更 (基於 git diff)
aireview --scan src/app.py  # 直接掃描檔案的完整內容 (不依賴 git diff)
aireview -s a.py b.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aireview_joy-0.1.2.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aireview_joy-0.1.2-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file aireview_joy-0.1.2.tar.gz.

File metadata

  • Download URL: aireview_joy-0.1.2.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aireview_joy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bd1b9382c96b7b1c6dc2bb40dd0f44898fd568af374ca9872debf473188cca2c
MD5 02cea4774b2f53cec033df3d363317f6
BLAKE2b-256 23c67b191c498327d93663b19598cac3e42f5782c2f55d93a9071ae22d6954e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for aireview_joy-0.1.2.tar.gz:

Publisher: ci.yml on Joy0130/aireview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aireview_joy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aireview_joy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aireview_joy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 040849c25221d1e05c9411bd1e93f43850917f79bfce1729b962565a9715207a
MD5 8ee3b1d8613f3a78c2586f3d1aade1f0
BLAKE2b-256 ef905eb580715cbc078f6a7e98ed45cfbb621afa2dd8514e04063b03cd350d88

See more details on using hashes here.

Provenance

The following attestation bundles were made for aireview_joy-0.1.2-py3-none-any.whl:

Publisher: ci.yml on Joy0130/aireview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page