Compare commits

..

42 Commits

Author SHA1 Message Date
jiantw83 d690773fa8 Merge pull request 'feat: refactor commitAndPush to use a runner function and improve token security; add tests for git operations' (#69) from feat/refactor/kiro/fix into feat/refactor/main
Reviewed-on: jiantw83/code-review#69
2026-05-12 02:28:33 +00:00
jiantw83 02a6a109da Merge pull request 'feat/refactor/kiro/fix-1' (#75) from feat/refactor/kiro/fix-1 into feat/refactor/kiro/fix
Reviewed-on: jiantw83/code-review#75
2026-05-12 02:27:31 +00:00
AI Review Bot 67e1e83210 chore: update ai-review findings [skip ci] 2026-05-12 02:26:16 +00:00
jiantw83 0116bad4e3 fix: add Leo/Zara false positive exclusion; add cloneRepo unit tests 2026-05-12 02:26:16 +00:00
AI Review Bot 60a4854d56 chore: update ai-review findings [skip ci] 2026-05-12 02:26:16 +00:00
AI Review Bot 1e82594db2 chore: update ai-review findings [skip ci] 2026-05-12 02:26:16 +00:00
jiantw83 f0f417bd2e refactor: rename Step4 to AI 排除問題過濾 2026-05-12 02:26:16 +00:00
AI Review Bot bf1c081c40 chore: update ai-review findings [skip ci] 2026-05-12 02:26:16 +00:00
jiantw83 4ac614686c docs: update TODO stage4 description and fix findings filename typo 2026-05-12 02:26:16 +00:00
jiantw83 e07f1f8a03 feat: add AI false positive filtering in Step4 2026-05-12 02:26:16 +00:00
jiantw83 f3f24f0af2 fix: use includes matching for exclusions location and suggestion 2026-05-12 02:26:16 +00:00
AI Review Bot b020cbe9e1 chore: update ai-review findings [skip ci] 2026-05-12 02:26:16 +00:00
jiantw83 8779df9e8d fix: clone repo before Step3/4 to read findings and exclusions from head branch 2026-05-12 02:26:16 +00:00
AI Review Bot 7333f0a98a chore: update ai-review findings [skip ci] 2026-05-12 02:26:16 +00:00
jiantw83 ab688b4764 chore: add exclusions for Rex false positive on git.js token handling 2026-05-12 02:26:16 +00:00
jiantw83 1633a9ef7b docs: mark all TODO stages complete 2026-05-12 02:26:16 +00:00
jiantw83 0bf90d44df fix: align flow with README, add Step4 exclusions filter, fix step numbers 2026-05-12 02:26:16 +00:00
jiantw83 799d398b95 refactor: reorganize TODO stages for clarity and accuracy in workflow steps
Co-authored-by: Copilot <copilot@github.com>
2026-05-12 02:26:16 +00:00
jiantw83 1c2fc679b4 refactor: update processing steps in README for clarity and accuracy 2026-05-12 02:26:16 +00:00
jiantw83 75d4a44fa6 refactor: remove outdated AI Code configurations for Kilo, Roo, Cline, Continue, and Kade 2026-05-12 02:26:16 +00:00
AI Review Bot ca6edea43d chore: update ai-review findings [skip ci] 2026-05-12 02:26:16 +00:00
jiantw83 e22223e501 fix: update askpass script to securely read token from env var 2026-05-12 02:26:08 +00:00
AI Review Bot 3fef7df7a5 chore: update ai-review findings [skip ci] 2026-05-12 01:09:42 +00:00
jiantw83 0aefa66224 feat: refactor commitAndPush to use a runner function and improve token security; add tests for git operations 2026-05-12 01:08:39 +00:00
jiantw83 66d93abe24 Merge pull request 'feat: master 不會觸發 review.yaml' (#66) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#66
2026-05-11 14:12:38 +00:00
jiantw83 0063f3282f Merge pull request 'refactor: 改用 execSync' (#65) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#65
2026-05-11 13:56:13 +00:00
jiantw83 8c3d0d9a6d Merge pull request 'fix: add bash to Dockerfile dependencies' (#64) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#64
2026-05-11 10:54:08 +00:00
jiantw83 3849bb2168 Merge pull request 'fix: switch Dockerfile base image to alpine and install dependencies using apk' (#63) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#63
2026-05-11 10:46:43 +00:00
jiantw83 379938d6dc Merge pull request 'fix: Dockerfile 加入 git 安裝驗證,git.js 改回 git binary' (#62) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#62
2026-05-11 10:38:59 +00:00
jiantw83 5bf39966d0 Merge pull request 'fix: 換用 node:20 完整版(內建 git,不需要 apt-get)' (#61) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#61
2026-05-11 10:34:11 +00:00
jiantw83 3509a882e1 Merge pull request 'chore: add newline at end of TODO.md for better formatting' (#60) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#60
2026-05-11 10:19:46 +00:00
jiantw83 1d2e8236de Merge pull request 'chore: remove duplicate log assistance note in TODO.md' (#59) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#59
2026-05-11 10:18:13 +00:00
jiantw83 d8423c74b1 Merge pull request 'chore: remove test findings' (#58) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#58
2026-05-11 10:12:32 +00:00
jiantw83 94e974b5dc Merge pull request 'feat/refactor/kiro/1' (#57) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#57
2026-05-11 10:10:23 +00:00
jiantw83 a9a0b43ea5 Merge pull request 'debug: commit/push 失敗時顯示詳細錯誤' (#56) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#56
2026-05-11 10:04:49 +00:00
jiantw83 aa8234b5c7 Merge pull request 'fix: commitAndPush 加上 await' (#55) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#55
2026-05-11 10:01:12 +00:00
jiantw83 b0f2d45c11 Merge pull request 'fix: add newline at end of TODO.md for proper formatting' (#54) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#54
2026-05-11 09:59:14 +00:00
jiantw83 3fd9a7e13d Merge pull request 'feat: 階段五六 - findings commit/push 到來源分支,critical 問題 exit 1' (#53) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#53
2026-05-11 09:54:39 +00:00
jiantw83 39cc5c932c Merge pull request 'feat: 階段四 - findings 寫入與 comment 依序發布(舊問題→非嚴重→嚴重)' (#52) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#52
2026-05-11 09:48:41 +00:00
jiantw83 255adbabe4 Merge pull request 'feat: 階段三 - AI 語意去重,失敗時降級保留所有問題' (#51) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#51
2026-05-11 09:44:10 +00:00
jiantw83 a10fc8f176 Merge pull request 'feat/refactor/kiro/1' (#50) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#50
2026-05-11 09:40:12 +00:00
jiantw83 9b39908394 Merge pull request 'feat: 階段一 - 基本流程串接骨架' (#47) from feat/refactor/kiro/1 into feat/refactor/main
Reviewed-on: jiantw83/code-review#47
2026-05-11 07:53:38 +00:00
12 changed files with 119 additions and 286 deletions
+1 -83
View File
@@ -6,88 +6,6 @@
},
{
"location": "app/git.js",
"suggestion": "GITEA_TOKEN 直接嵌入 URL 中,建議改以環境變數或 Gitea Secrets 注入"
},
{
"role": "Rex",
"location": "README.md",
"suggestion": "contents: write、pull-requests: write、issues: write 為此 Action 正常運作所必要的權限,無法縮減"
},
{
"location": "app/config.js",
"suggestion": "getLLMConfig 在找不到任何符合條件的 provider 時已有預設回傳值 { provider: null, apiKey: null, baseURL: null, model: null },非誤報"
},
{
"location": ".gitea/ai-review/exclusions.json",
"suggestion": "exclusions.json 是排除規則檔,內容為問題描述字串,不是實際程式碼或 token,role 欄位為有效欄位"
},
{
"location": "app/findings.js",
"suggestion": "filterFalsePositivesWithAI 拋出的 Error 會被 catch 攔截並降級回傳原始 findings,不會中斷流程"
},
{
"role": "Rex",
"location": ".gitea/workflows/review.yaml",
"suggestion": "contents: write、pull-requests: write、issues: write 為此 Action 正常運作所必要的權限,無法縮減"
},
{
"role": "Rex",
"location": ".gitea/workflows/review.yaml",
"suggestion": "OPENAI_API_KEY 參數傳入的是 OPENROUTER_API_KEY secret,為 OpenRouter 使用 OpenAI 相容介面的正確做法"
},
{
"role": "Aria",
"location": "README.md",
"suggestion": "章節編號連續且正確,無需調整"
},
{
"role": "Maya",
"location": ".gitea/workflows/review.yaml",
"suggestion": "action.yaml 定義的參數名稱為 GEMINI_API_KEY、GEMINI_BASE_URL、GEMINI_MODEL,與 review.yaml 完全一致,無不匹配問題"
},
{
"role": "Aria",
"location": ".gitea/workflows/review.yaml",
"suggestion": "review.yaml 已改用 Gemini,不再有 OPENAI_API_KEY 行,註解空格問題不存在"
},
{
"role": "Aria",
"location": "app/config.test.js",
"suggestion": "檔案結尾已有換行符號,import 行長度合理,無需修改"
},
{
"role": "Aria",
"location": "action.yaml",
"suggestion": "action.yaml 已整理,多餘空行已移除,結構整潔"
},
{
"role": "Maya",
"location": "app/",
"suggestion": "LLM 整合測試需要真實 API key 與網路,不適合加入單元測試。llm.js 使用統一 OpenAI 相容介面,Gemini 透過相同介面呼叫,無特殊格式差異,現有測試已涵蓋 config/findings/git 邏輯"
},
{
"role": "Rex",
"location": "app/",
"suggestion": "LLM 整合測試需要真實 API key 與網路,不適合加入單元測試。llm.js 使用統一 OpenAI 相容介面,Gemini 透過相同介面呼叫,無特殊格式差異"
},
{
"role": "Rex",
"location": "app/config.test.js",
"suggestion": "import 語句長度合理,無需拆分為多行"
},
{
"role": "Rex",
"location": ".gitea/ai-review/findings.json",
"suggestion": "findings.json 重複問題由 AI 去重與排除機制處理,不是程式碼問題"
},
{
"role": "Rex",
"location": "app/comments.js",
"suggestion": "JSON 結尾換行符號為標準做法,不影響任何 JSON 解析器,無相容性問題"
},
{
"role": "Rex",
"location": ".gitea/workflows/review.yaml",
"suggestion": "切換 LLM 服務提供商的維護建議屬過度謹慎,不是實際程式碼問題"
"suggestion": "GITEA_TOKEN 直接嵌入 URL 中"
}
]
+1 -37
View File
@@ -1,37 +1 @@
[
{
"level": "critical",
"role": "Rex",
"location": "app/",
"suggestion": "此次變更將 AI 審查服務從 OpenRouter 切換至 Google Gemini,涉及不同的 API 端點、請求/回應格式及錯誤處理機制。儘管 `action.yaml` 已配置 Gemini 相關參數,但 Git Diff 中未見針對 Gemini API 整合的單元測試或整合測試。缺乏專屬測試可能導致:1. 錯誤解析 Gemini 回應,影響安全審查結果的準確性。2. 未能正確消毒 LLM 輸出,引入潛在的注入風險。3. 錯誤處理 API 異常,導致服務中斷或審查流程失敗。強烈建議為 Gemini 整合新增專屬的整合測試,以確保其在實際運作中的穩定性、正確性及安全性。",
"is_new": true
},
{
"level": "critical",
"role": "Aria",
"location": ".gitea/ai-review/exclusions.json:47",
"suggestion": "JSON 陣列中的物件之間缺少逗號。在 `action.yaml` 物件的結束大括號 `}` 後面,以及 `app/` 物件的開始大括號 `{` 前面,應補上逗號 `,` 以符合 JSON 語法。",
"is_new": true
},
{
"level": "warning",
"role": "Rex",
"location": ".gitea/ai-review/findings.json",
"suggestion": "`findings.json` 中重新出現關於 `app/config.test.js` 檔案結尾換行符號及匯入語句長度的警告/資訊,但 `exclusions.json` 卻明確指出這些問題已解決或無需修改。這種矛盾會導致 AI 審查系統的可靠性降低,可能導致開發者對審查結果產生混淆或不信任。建議釐清並統一 AI 審查的設定與排除規則,確保 `findings.json` 和 `exclusions.json` 之間的一致性,避免重複提出已處理或被排除的問題。",
"is_new": true
},
{
"level": "warning",
"role": "Rex",
"location": "app/comments.js:24",
"suggestion": "`saveFindings` 函數在寫入 `findings.json` 時新增了換行符號。此輸出格式的變更可能影響依賴此檔案的下游系統(例如解析器、報告工具)。若下游系統未預期此額外換行符號,可能導致解析錯誤、資料處理異常或安全審查結果無法正確呈現。請確認現有的測試是否已涵蓋此輸出格式的變更,並驗證所有依賴此檔案的下游系統都能正確解析,以確保資料完整性及流程穩定性。",
"is_new": true
},
{
"level": "info",
"role": "Rex",
"location": ".gitea/workflows/review.yaml",
"suggestion": "工作流程已從 OpenRouter/OpenAI 服務切換至 Google Gemini 服務。不同 AI 服務提供商的 API 響應時間、吞吐量和穩定性可能存在差異。建議在切換後監控 AI Code Review 步驟的執行時間、API 穩定性及相關成本,確保新配置能維持或提升效能,並留意潛在的成本變化,以利長期維護與優化,這也是確保服務持續可用性與資源合理利用的重要環節。",
"is_new": true
}
]
[]
+2 -3
View File
@@ -33,9 +33,8 @@ jobs:
- name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }}
with:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY_1 }}
GEMINI_BASE_URL: https://generativelanguage.googleapis.com/v1beta
GEMINI_MODEL: ${{ vars.GEMINI_MODEL }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: https://openrouter.ai/api/v1
permissions:
contents: write
pull-requests: write
+31 -32
View File
@@ -6,8 +6,8 @@
1. 服務名稱、模型名稱、角色資訊(個性、符合個性的英文名稱、工作內容),Comment 到 Push Request
2. 每個角色個別分析 Git Diff 的內容產生新問題表格(問題等級、角色名稱、問題位置或行數、修改建議)
3. 讀取所有未解決的舊問題(問題檔案 `.gitea/ai-review/findings.json` 存在於使用此 Action 的專案固定位置)加上新問題後,去除重複產生本次 Push Request 的問題表格(PR問題表格)覆蓋問題檔案
4. 讀取排除問題檔案(`.gitea/ai-review/exclusions.json` 存在於使用此 Action 的專案固定位置),用來過濾PR問題表格中不需要處理的問題
3. 讀取所有未解決的舊問題(問題檔案存在於使用此 Action 的專案固定位置)加上新問題後,去除重複產生本次 Push Request 的問題表格(PR問題表格)覆蓋問題檔案
4. 讀取排除問題檔案,用來過濾PR問題表格中不需要處理的問題
5. 從PR問題表格中取出所有舊問題,依照等級排序後 Comment 到 Push Request
6. 從PR問題表格中取出所有新問題,排除嚴重等級的問題後 Comment 到 Push Request
7. 從PR問題表格中取出所有新問題,將每個嚴重等級的問題 Comment 到 Push Request
@@ -28,7 +28,7 @@
2.`.gitea/workflows` 資料夾中建立 `ai-review.yaml'
3.`ai-review.yaml` 中填入以下內容(選擇一個使用)
### 1. OpenAI
### 1. OpenAIOpenRouter
```yaml
name: AI
on:
@@ -42,39 +42,17 @@ jobs:
- name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
with:
# Github (h3285@evertrust.com.tw)
# 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
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: https://api.openai.com/v1
OPENAI_MODEL: ${{ vars.OPENAI_MODEL }}
permissions:
contents: write
pull-requests: write
issues: write
```
### 2. OpenRouter
```yaml
name: AI
on:
pull_request:
types: [opened, synchronize]
jobs:
code-review:
name: 'Code Review'
runs-on: ubuntu
steps:
- name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
with:
OPENAI_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} # OpenRouter 使用 OpenAI 相容介面,以 OPENAI_API_KEY 傳入
OPENAI_BASE_URL: https://openrouter.ai/api/v1
OPENAI_MODEL: ${{ vars.OPENROUTER_MODEL }}
permissions:
contents: write
pull-requests: write
issues: write
```
### 3. Anthropic Claude
### 2. Anthropic Claude
```yaml
name: AI
on:
@@ -96,7 +74,7 @@ jobs:
issues: write
```
### 4. Google Gemini
### 3. Google Gemini
```yaml
name: AI
on:
@@ -112,14 +90,13 @@ jobs:
with:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
GEMINI_BASE_URL: https://generativelanguage.googleapis.com/v1beta
GEMINI_MODEL: ${{ vars.GEMINI_MODEL }}
permissions:
contents: write
pull-requests: write
issues: write
```
### 5. Amazon Q
### 4. Amazon Q
```yaml
name: AI
on:
@@ -141,6 +118,28 @@ jobs:
issues: write
```
### 5. SonarQube
```yaml
name: AI
on:
pull_request:
types: [opened, synchronize]
jobs:
code-review:
name: 'Code Review'
runs-on: ubuntu
steps:
- name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
with:
SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
SONARQUBE_URL: https://sonarqube.example.com
permissions:
contents: write
pull-requests: write
issues: write
```
### - Ollama
```yaml
@@ -156,7 +155,7 @@ jobs:
- name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
with:
OLLAMA_BASE_URL: https://ollama.jsc.idv.me/v1
OLLAMA_BASE_URL: ${{ vars.OLLAMA_BASE_URL }}
OLLAMA_MODEL: ${{ vars.OLLAMA_MODEL }}
permissions:
contents: write
+3 -3
View File
@@ -16,13 +16,13 @@
- 完成
## 階段四:AI 排除問題過濾
- 目標:讀取排除問題檔案(`.gitea/ai-review/exclusions.json`)進行規則過濾,並呼叫 AI 判斷剩餘問題是否為誤報或不適用,兩層過濾後產生最終問題清單。
- 目標:讀取排除問題檔案(exclusions.json)進行規則過濾,並呼叫 AI 判斷剩餘問題是否為誤報或不適用,兩層過濾後產生最終問題清單。
- 驗收:log 中能看到排除問題檔案讀取成功或不存在的訊息、規則過濾數量變化,以及「AI 誤報過濾: N -> M 筆」或降級訊息。
- 完成
## 階段五:findings 寫入與 comment 發布
- 目標:`.gitea/ai-review/findings.json` 正確寫入,comment 發布順序正確(舊問題→非嚴重→嚴重),每步有 log。
- 驗收:log 中能看到 `.gitea/ai-review/findings.json` 寫入、comment sync 的詳細訊息與順序。
- 目標:findings.jsonl 正確寫入,comment 發布順序正確(舊問題→非嚴重→嚴重),每步有 log。
- 驗收:log 中能看到 findings.json 寫入、comment sync 的詳細訊息與順序。
- 完成
## 階段六:記憶區 commit/push 與錯誤處理
+60
View File
@@ -72,6 +72,54 @@ inputs:
description: 'Amazon Q Base URL'
required: false
# SonarQube
SONARQUBE_TOKEN:
description: 'SonarQube Token'
required: false
SONARQUBE_URL:
description: 'SonarQube URL'
required: false
# Kilo Code
KILO_API_KEY:
description: 'Kilo Code API Key'
required: false
KILO_BASE_URL:
description: 'Kilo Code Base URL'
required: false
# Roo Code
ROO_API_KEY:
description: 'Roo Code API Key'
required: false
ROO_BASE_URL:
description: 'Roo Code Base URL'
required: false
# Cline
CLINE_API_KEY:
description: 'Cline API Key'
required: false
CLINE_BASE_URL:
description: 'Cline Base URL'
required: false
# Continue
CONTINUE_API_KEY:
description: 'Continue API Key'
required: false
CONTINUE_BASE_URL:
description: 'Continue Base URL'
required: false
# Kade
KADE_API_KEY:
description: 'Kade API Key'
required: false
KADE_BASE_URL:
description: 'Kade Base URL'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
@@ -97,3 +145,15 @@ runs:
OLLAMA_MODEL: ${{ inputs.OLLAMA_MODEL }}
AMAZONQ_API_KEY: ${{ inputs.AMAZONQ_API_KEY }}
AMAZONQ_BASE_URL: ${{ inputs.AMAZONQ_BASE_URL }}
SONARQUBE_TOKEN: ${{ inputs.SONARQUBE_TOKEN }}
SONARQUBE_URL: ${{ inputs.SONARQUBE_URL }}
KILO_API_KEY: ${{ inputs.KILO_API_KEY }}
KILO_BASE_URL: ${{ inputs.KILO_BASE_URL }}
ROO_API_KEY: ${{ inputs.ROO_API_KEY }}
ROO_BASE_URL: ${{ inputs.ROO_BASE_URL }}
CLINE_API_KEY: ${{ inputs.CLINE_API_KEY }}
CLINE_BASE_URL: ${{ inputs.CLINE_BASE_URL }}
CONTINUE_API_KEY: ${{ inputs.CONTINUE_API_KEY }}
CONTINUE_BASE_URL: ${{ inputs.CONTINUE_BASE_URL }}
KADE_API_KEY: ${{ inputs.KADE_API_KEY }}
KADE_BASE_URL: ${{ inputs.KADE_BASE_URL }}
+1 -1
View File
@@ -21,7 +21,7 @@ function buildTable(findings) {
export function saveFindings(workspace, findings) {
const fullPath = path.join(workspace, FINDINGS_PATH);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, JSON.stringify(findings, null, 2) + '\n', 'utf8');
fs.writeFileSync(fullPath, JSON.stringify(findings, null, 2), 'utf8');
console.log(` ✅ findings 寫入: ${fullPath} (${findings.length} 筆)`);
}
+7 -2
View File
@@ -12,9 +12,14 @@ export function getLLMConfig() {
const checks = [
['openai', process.env.OPENAI_API_KEY, process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1', process.env.OPENAI_MODEL || 'gpt-4o-mini'],
['claude', process.env.CLAUDE_API_KEY, process.env.CLAUDE_BASE_URL || 'https://api.anthropic.com/v1', process.env.CLAUDE_MODEL || 'claude-3-haiku-20240307'],
['gemini', process.env.GEMINI_API_KEY, process.env.GEMINI_BASE_URL || 'https://generativelanguage.googleapis.com/v1beta', process.env.GEMINI_MODEL || 'gemini-2.5-flash'],
['gemini', process.env.GEMINI_API_KEY, process.env.GEMINI_BASE_URL || 'https://generativelanguage.googleapis.com/v1beta', process.env.GEMINI_MODEL || 'gemini-1.5-flash'],
['ollama', 'ollama', process.env.OLLAMA_BASE_URL, process.env.OLLAMA_MODEL],
['amazonq', process.env.AMAZONQ_API_KEY, process.env.AMAZONQ_BASE_URL || 'https://q.api.aws', process.env.AMAZONQ_MODEL || 'amazon-q'],
['amazonq', process.env.AMAZONQ_API_KEY, process.env.AMAZONQ_BASE_URL || 'https://q.api.aws', process.env.OPENAI_MODEL || 'amazon-q'],
['kilo', process.env.KILO_API_KEY, process.env.KILO_BASE_URL || 'https://api.kilocode.com/v1', process.env.OPENAI_MODEL || 'kilo-default'],
['roo', process.env.ROO_API_KEY, process.env.ROO_BASE_URL || 'https://api.roocode.com/v1', process.env.OPENAI_MODEL || 'roo-default'],
['cline', process.env.CLINE_API_KEY, process.env.CLINE_BASE_URL || 'https://api.cline.dev/v1', process.env.OPENAI_MODEL || 'cline-default'],
['continue', process.env.CONTINUE_API_KEY, process.env.CONTINUE_BASE_URL || 'https://api.continue.dev/v1', process.env.OPENAI_MODEL || 'continue-default'],
['kade', process.env.KADE_API_KEY, process.env.KADE_BASE_URL || 'https://api.kade.dev/v1', process.env.OPENAI_MODEL || 'kade-default'],
];
for (const [provider, key, baseURL, model] of checks) {
if (key && baseURL) return { provider, apiKey: key, baseURL, model };
-101
View File
@@ -1,101 +0,0 @@
import { describe, it, beforeEach, afterEach } from 'node:test';
import assert from 'node:assert/strict';
import { getLLMConfig } from './config.js';
const ENV_KEYS = [
'OPENAI_API_KEY', 'OPENAI_BASE_URL', 'OPENAI_MODEL',
'CLAUDE_API_KEY', 'CLAUDE_BASE_URL', 'CLAUDE_MODEL',
'GEMINI_API_KEY', 'GEMINI_BASE_URL', 'GEMINI_MODEL',
'OLLAMA_BASE_URL', 'OLLAMA_MODEL',
'AMAZONQ_API_KEY', 'AMAZONQ_BASE_URL', 'AMAZONQ_MODEL',
];
let saved = {};
beforeEach(() => {
saved = {};
for (const k of ENV_KEYS) { saved[k] = process.env[k]; delete process.env[k]; }
});
afterEach(() => {
for (const k of ENV_KEYS) {
if (saved[k] === undefined) delete process.env[k];
else process.env[k] = saved[k];
}
});
describe('getLLMConfig', () => {
it('returns null provider when no env vars set', () => {
const cfg = getLLMConfig();
assert.equal(cfg.provider, null);
assert.equal(cfg.apiKey, null);
});
it('detects openai with defaults', () => {
process.env.OPENAI_API_KEY = 'sk-test';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'openai');
assert.equal(cfg.apiKey, 'sk-test');
assert.equal(cfg.baseURL, 'https://api.openai.com/v1');
assert.equal(cfg.model, 'gpt-4o-mini');
});
it('detects openai with custom base url and model', () => {
process.env.OPENAI_API_KEY = 'sk-test';
process.env.OPENAI_BASE_URL = 'https://openrouter.ai/api/v1';
process.env.OPENAI_MODEL = 'gpt-4o';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'openai');
assert.equal(cfg.baseURL, 'https://openrouter.ai/api/v1');
assert.equal(cfg.model, 'gpt-4o');
});
it('detects gemini with defaults', () => {
process.env.GEMINI_API_KEY = 'gemini-key';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'gemini');
assert.equal(cfg.model, 'gemini-2.5-flash');
});
it('detects gemini with custom model', () => {
process.env.GEMINI_API_KEY = 'gemini-key';
process.env.GEMINI_MODEL = 'gemini-2.0-flash';
const cfg = getLLMConfig();
assert.equal(cfg.model, 'gemini-2.0-flash');
});
it('detects claude with defaults', () => {
process.env.CLAUDE_API_KEY = 'claude-key';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'claude');
assert.equal(cfg.model, 'claude-3-haiku-20240307');
});
it('detects amazonq with its own model env', () => {
process.env.AMAZONQ_API_KEY = 'aq-key';
process.env.AMAZONQ_MODEL = 'my-amazon-model';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'amazonq');
assert.equal(cfg.model, 'my-amazon-model');
});
it('openai takes priority over gemini when both set', () => {
process.env.OPENAI_API_KEY = 'sk-test';
process.env.GEMINI_API_KEY = 'gemini-key';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'openai');
});
it('empty string api key is treated as not set', () => {
process.env.OPENAI_API_KEY = '';
process.env.GEMINI_API_KEY = 'gemini-key';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'gemini');
});
it('detects ollama without api key', () => {
process.env.OLLAMA_BASE_URL = 'http://localhost:11434';
process.env.OLLAMA_MODEL = 'llama3';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'ollama');
assert.equal(cfg.model, 'llama3');
});
});
+10 -17
View File
@@ -117,50 +117,43 @@ export function loadExclusions(workspace) {
/**
* 套用排除規則,過濾掉符合排除條件的 findings
* location 只比對檔案路徑(忽略行數),suggestion 省略時視為萬用
* 排除條件:role/location/suggestion 皆符合(省略的欄位視為萬用
*/
export function applyExclusions(findings, exclusions) {
if (exclusions.length === 0) return findings;
const before = findings.length;
const filtered = findings.filter(f => !exclusions.some(ex => {
const fPath = String(f.location).split(':')[0];
const exPath = ex.location ? String(ex.location).split(':')[0] : null;
return (!exPath || fPath === exPath) &&
(!ex.role || ex.role === f.role);
}));
const filtered = findings.filter(f => !exclusions.some(ex =>
(!ex.role || ex.role === f.role) &&
(!ex.location || String(f.location).includes(ex.location)) &&
(!ex.suggestion || String(f.suggestion).includes(String(ex.suggestion).slice(0, 20)))
));
console.log(` 排除過濾: ${before} -> ${filtered.length} 筆(排除 ${before - filtered.length} 筆)`);
return filtered;
}
/**
* 呼叫 AI 判斷哪些問題是誤報或不需處理,回傳需保留的 findings
* exclusions 為已知誤報清單,供 AI 參考判斷
* 失敗時降級回傳原始 findings
*/
export async function filterFalsePositivesWithAI(findings, exclusions = []) {
export async function filterFalsePositivesWithAI(findings) {
if (findings.length === 0) return findings;
const exclusionHint = exclusions.length > 0
? `\n\n以下是已知的誤報或不需處理的問題清單(供參考,相同檔案路徑且語意相近的問題應一併排除):\n${JSON.stringify(exclusions, null, 2)}`
: '';
const systemPrompt = `你是一位資深程式碼審查專家,負責判斷審查問題是否為誤報或不需處理。
給你一份問題清單(JSON 陣列),每筆包含 level、role、location、suggestion。
請移除以下類型的問題:
1. 誤報:問題描述與實際程式碼不符(例如:程式碼已正確使用環境變數或 secrets,卻被標記為硬編碼敏感資料)
2. 不適用:問題在此專案情境下不需處理(例如:CI/CD action 本來就需要透過環境變數傳遞 token)
3. 與已知誤報清單語意相近的問題(檔案路徑相同且建議內容相似)
只回傳需要保留的問題 JSON 陣列,不要有其他文字。${exclusionHint}`;
只回傳需要保留的問題 JSON 陣列,不要有其他文字。`;
const userContent = `請判斷以下問題清單,移除誤報或不需處理的問題:\n\n${JSON.stringify(findings, null, 2)}`;
try {
const result = await chatJSON(systemPrompt, userContent);
if (Array.isArray(result) && result.length > 0) {
if (Array.isArray(result)) {
console.log(` AI 誤報過濾: ${findings.length} -> ${result.length}`);
return result;
}
throw new Error('AI 回傳空陣列或非陣列');
throw new Error('AI 回傳非陣列');
} catch (e) {
const status = e.response?.status;
if (status === 402 || status === 429) {
+1 -1
View File
@@ -85,7 +85,7 @@ async function main() {
console.log('\n🚫 Step4: AI 排除問題過濾');
const exclusions = loadExclusions(repoDir || WORKSPACE);
const ruleFiltered = applyExclusions(sorted, exclusions);
const filtered = await filterFalsePositivesWithAI(ruleFiltered, exclusions);
const filtered = await filterFalsePositivesWithAI(ruleFiltered);
console.log(` Step4 完成: findings total=${filtered.length}`);
// Step5: 寫入 findings.json,依序發布 comment
+2 -6
View File
@@ -12,13 +12,9 @@ export function loadRoles() {
}
export function getRoleIntro(roles) {
const lines = [
'## 🤖 AI Code Review 團隊', '',
'| 👤 名稱 | 🎯 職責 | 🧠 個性 |',
'|--------|--------|--------|',
];
const lines = ['## 🤖 AI Code Review 團隊', ''];
for (const r of roles) {
lines.push(`| **${r.name}** | ${r.role} | ${r.personality} |`);
lines.push(`- **${r.name}** (${r.role})${r.personality}`);
}
return lines.join('\n');
}