Metadata-Version: 2.4
Name: aireview-joy
Version: 0.1.1
Summary: AI-powered code review CLI using Gemini API
License: MIT
Project-URL: Homepage, https://github.com/yourusername/aireview
Project-URL: Repository, https://github.com/yourusername/aireview
Project-URL: Issues, https://github.com/yourusername/aireview/issues
Keywords: code-review,ai,gemini,git,cli,developer-tools
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Version Control :: Git
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: google-genai>=1.0.0
Requires-Dist: pyyaml>=6.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"

# 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)
```bash
brew install pipx
```

```bash
# 從 PyPI 全域安裝 (推薦)
pipx install aireview-joy
```

### From source

```bash
git clone https://github.com/Joy0130/aireview.git
cd aireview
pipx install .
```

## Setup

Set your Gemini API key as an environment variable:

```bash
export GEMINI_API_KEY="your-key-here"
```

Or add it to a `.env` file in your repository root:

```env
GEMINI_API_KEY=your-key-here
```

Get a free API key at [Google AI Studio](https://aistudio.google.com).

## Usage

```bash
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

```bash
# 審查已暫存的變更，如果沒有問題則進行 commit
aireview && aicommit

# 或者將精簡版的審查摘要傳遞給 aicommit
aireview --output compact | aicommit
```

## Configuration

Create `.aireview.yml` in your repo root or `~/.aireview.yml`:

```yaml
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
