npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cw-aigit

v1.0.0

Published

AI-driven Git diff reviewer

Downloads

113

Readme

Check Review CLI

npm version License: MIT

🤖 AI 驅動的 Git Diff 程式碼審查工具

這是一個基於 OpenAI GPT 的智能程式碼審查工具,能夠自動分析您的 Git diff 並提供專業的程式碼審查建議。

✨ 功能特色

  • 🔍 智能分析 - 使用 OpenAI GPT 模型分析程式碼變更
  • 📊 評分系統 - 提供 0-10 分的程式碼品質評分
  • 📝 詳細報告 - 生成包含風險點、優化建議的完整審查報告
  • 🎯 檔案篩選 - 支援 include/exclude 模式過濾檔案
  • 批次處理 - 自動將大量檔案分批處理以提高效率
  • 💰 成本追蹤 - 顯示 API 使用量和預估費用

📦 安裝

全域安裝

npm install -g cw-aigit

本地安裝

npm install cw-aigit

🚀 快速開始

1. 建立配置檔案

在您的專案根目錄建立 reviewer.config.js

module.exports = {
  apiKey: 'your-openai-api-key',  // 必填:您的 OpenAI API Key
  model: 'gpt-4.1-nano',          // 可選:使用的模型,預設 gpt-4.1-nano
  include: ['src/**/*.js', 'app/**/*.vue'],  // 可選:要包含的檔案模式
  exclude: ['**/*.test.js', 'dist/**'],      // 可選:要排除的檔案模式
  keepPhrases: [                   // 可選:審查時要遵守的規則
    '不要批評 XXX 函式',
    '忽略 test 檔案改動',
  ],
};

2. 執行審查

check-review <target-branch>

例如:

# 比較當前分支與 main 分支的差異
check-review main

# 比較當前分支與 develop 分支的差異
check-review develop

3. 生成時間區間 Commit 摘要

cw-aigit commit-range <start-date> <end-date>

例如:

# 分析 2024-01-01 到 2024-01-31 期間的 commit
cw-aigit commit-range 2024-01-01 2024-01-31

4. 生成 PR Description

cw-aigit pr-description <source-branch> <target-branch>

生成專業的 Pull Request 描述,包含:

  • 💡 建議的 PR 標題 - 3-5 個精簡的標題選項
  • 📝 變更摘要 - 整體變更說明
  • 主要變更 - 功能新增和修改
  • 🐛 問題修正 - Bug 修復項目
  • 🧹 其他調整 - 重構、文件更新等
  • ⚠️ 注意事項 - 需要特別關注的項目
  • 🧪 測試項目 - 建議的測試範圍

例如:

# 生成 feature/login 要合併到 main 分支的 PR description
cw-aigit pr-description feature/login main

# 生成 develop 要合併到 master 分支的 PR description  
cw-aigit pr-description develop master

5. 查看結果

工具會在專案根目錄生成 review.md 檔案,包含完整的審查報告。

⚙️ 配置選項

| 參數 | 類型 | 必填 | 說明 | 預設值 | |------|------|------|------|--------| | apiKey | string | ✅ | OpenAI API Key | - | | model | string | ❌ | 使用的 OpenAI 模型 | gpt-4.1-nano | | include | string[] | ❌ | 要包含的檔案模式(glob 語法) | 所有檔案 | | exclude | string[] | ❌ | 要排除的檔案模式(glob 語法) | 無 | | keepPhrases | string[] | ❌ | 審查時要遵守的規則 | 無 |

檔案模式範例

module.exports = {
  // 只審查 JavaScript 和 TypeScript 檔案
  include: [
    'src/**/*.js',
    'src/**/*.ts',
    'lib/**/*.js',
  ],
  
  // 排除測試檔案和建置產物
  exclude: [
    '**/*.test.js',
    '**/*.spec.ts',
    'dist/**',
    'build/**',
    'node_modules/**',
  ],
};

📊 審查報告範例

生成的 review.md 包含以下內容:

# AI Review 分析報告

來源:`origin/main...HEAD`

## 🟢 建議 Approve

**整體平均評分:** 8.5 / 10

### 🔎 整體簡述摘要:
本次變更主要新增了使用者認證功能,包含登入、註冊和權限驗證機制。
程式碼結構清晰,遵循最佳實踐,建議進行簡單的錯誤處理優化後即可合併。

---

## 🔹 第 1 批檔案分析

**包含檔案:**
- src/auth/login.js
- src/auth/register.js

### 改動做了什麼事
新增了完整的使用者認證系統...

### 潛在風險點
1. 密碼加密強度需要確認...
2. Session 管理可能存在安全風險...

### 可以優化的地方
1. 建議加入更詳細的錯誤處理...

### 建議 Reviewer 檢查重點
1. 檢查密碼加密是否使用足夠強度...

💡 **總共使用 1,250 tokens**
💰 **預估花費約 $0.0375**

🛠️ 進階用法

在 CI/CD 中使用

# GitHub Actions 範例
name: AI Code Review
on: [pull_request]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
    - uses: actions/setup-node@v3
      with:
        node-version: '18'
    - run: npm install -g cw-aigit
    - run: cw-aigit check-review main
      env:
        OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
    - uses: actions/upload-artifact@v3
      with:
        name: review-report
        path: review.md

自訂模型

支援的 OpenAI 模型:

  • gpt-4.1-nano (預設,成本較低)
  • gpt-4
  • gpt-3.5-turbo
module.exports = {
  model: 'gpt-4',  // 使用更強大的模型
  // ...其他配置
};

🔧 故障排除

常見問題

Q: 出現 "請在根目錄建立 reviewer.config.js" 錯誤 A: 請確認在專案根目錄建立 reviewer.config.js 配置檔案。

Q: API Key 錯誤 A: 請確認 OpenAI API Key 有效且有足夠額度。

Q: 沒有找到變更檔案 A: 請確認:

  1. 目標分支名稱正確
  2. 本地已經 fetch 最新的遠端分支
  3. include/exclude 設定是否過濾掉了所有檔案

Q: 審查結果不如預期 A: 可以嘗試:

  1. 調整 keepPhrases 設定更具體的審查規則
  2. 使用更強大的模型如 gpt-4
  3. 確認 diff 內容符合預期

📝 Prompt 自訂

現在 PR Description 和 Commit Range 功能使用分離的 prompt 文件,您可以根據需求自訂:

PR Description Prompt

文件位置:pr_description_prompt.md

此檔案控制 cw-aigit pr-description 的輸出格式,預設包含:

  • 💡 建議的 PR 標題
  • 📝 變更摘要
  • ✨ 主要變更
  • 🐛 問題修正
  • 🧹 其他調整
  • ⚠️ 注意事項
  • 🧪 測試項目

Commit Range Prompt

文件位置:commit_range_prompt.md

此檔案控制 cw-aigit commit-range 的輸出格式,預設包含:

  • 🚨 重大事項
  • ✨ 新增功能 (表格格式)
  • 🐛 錯誤修正 (表格格式)
  • 🎨 UI 調整 (表格格式)
  • 🧹 重構與優化 (表格格式)
  • 🔧 CI/CD & 環境 (表格格式)

自訂 Prompt

您可以直接編輯這些檔案來調整輸出格式,讓 AI 產出符合您團隊需求的內容:

# 編輯 PR Description 格式
vim pr_description_prompt.md

# 編輯 Commit Range 格式  
vim commit_range_prompt.md
# 複製專案
git clone <repository-url>
cd check-review

# 安裝依賴
npm install

# 本地測試
npx cw-aigit check-review main

🤝 貢獻

歡迎提交 Issue 和 Pull Request!

� 發佈流程

開發者發佈新版本

如果您是專案維護者,可以按照以下步驟發佈新版本:

1. 更新版本號

# 編輯 package.json 中的版本號
vim package.json

# 或使用 npm version 自動更新
npm version patch    # 0.0.4 -> 0.0.5 (修復)
npm version minor    # 0.0.4 -> 0.1.0 (新功能)
npm version major    # 0.0.4 -> 1.0.0 (破壞性變更)

2. 確認檔案包含

檢查 package.json 中的 files 欄位是否包含所有必要檔案:

{
  "files": [
    "bin",
    "lib", 
    "commands",
    "config.js",
    "*.md"
  ]
}

3. 本地測試

# 打包並檢查內容
npm pack

# 本地安裝測試
npm install -g ./cw-aigit-x.x.x.tgz

# 測試指令
cw-aigit check-review --help

4. 發佈到 npm

# 登入 npm (首次發佈需要)
npm login

# 發佈
npm publish

# 確認發佈成功
npm view cw-aigit versions --json

5. 建立 Git 標籤(可選)

# 建立版本標籤
git tag v0.0.5
git push origin v0.0.5

# 建立 GitHub Release(可選)
gh release create v0.0.5 --title "v0.0.5" --notes "發佈說明"

版本規劃

  • Patch (x.x.X): Bug 修復、文件更新
  • Minor (x.X.x): 新功能、向後相容的變更
  • Major (X.x.x): 破壞性變更、重大重構

發佈檢查清單

  • [ ] 更新 CHANGELOG.md
  • [ ] 測試所有功能正常運作
  • [ ] 確認文件更新完整
  • [ ] 版本號符合語意化版本規範
  • [ ] 執行 npm publish 發佈
  • [ ] 建立 Git 標籤
  • [ ] 更新相關文件連結

�📄 授權

MIT License - 詳見 LICENSE 檔案。

🔗 相關連結