| 模式 | 誰呼叫 LLM? | 適用場景 |
|---|---|---|
| Agent Skill | OCR | agent 呼叫 ocr review,OCR 驅動完整評審(修復前先問) |
| Command(Claude Code) | OCR | Claude Code 的斜線命令,OCR 驅動評審(預設自動修復) |
| OpenCode 工具 | OCR | 註冊 ocr_review / ocr_health 原生工具 |
| 委託模式 | 宿主 Agent | OCR 提供工程架構,宿主 Agent 用自己的 LLM |
把 OCR 註冊為可呼叫的 skill,讓 agent 框架以正確的參數、前置檢查與分級標準呼叫它。
npx skills add alibaba/open-code-review --skill open-code-review
SKILL.md 讓 agent 執行七步:前置檢查 → CLI 缺失自動安裝 → 無 LLM 停下詢問 → 提取業務脈絡 → 跑評審 → 分級(High/Medium/Low)→ 按需修復。完整 prompt 在 skills/open-code-review/SKILL.md。
在 Claude Code 內端到端跑——評審 diff、分類發現、自動套用值得採納的修復。
/plugin marketplace add alibaba/open-code-review
/plugin install open-code-review@open-code-review
註冊 /open-code-review:review 斜線命令。與 Agent Skill 不同,此命令預設自動修復——適合「評審並清理」工作流。命令檔是帶 frontmatter 的純 markdown,其他支援 command 約定的 agent 也能用。
mkdir -p ~/.config/opencode/plugins
curl -fsSL \
https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/opencode/open-code-review.ts \
-o ~/.config/opencode/plugins/open-code-review.ts
註冊原生工具:ocr_review(評審工作區 / commit / ref 範圍,回傳結構化 JSON)、ocr_health(顯示版本與 LLM 連通性),以及 /ocr-review、/ocr-health 斜線命令。評審用 --audience agent + JSON 輸出、15 分鐘超時、10 MiB 輸出上限。
讓宿主 Agent 用自己的 LLM 執行評審,OCR 只負責檔案篩選與規則解析——詳見 委託模式專頁。
在每個 PR / MR 上跑 OCR。上游提供 GitHub Actions 與 GitLab CI 兩條現成管線——詳見 CI/CD 專頁。
問三個問題:① OCR 的 LLM 要用誰的?② 要自動修復嗎?③ 用什麼 agent 框架?
SKILL.md 讓 agent 執行:① 前置檢查(Git? LLM?)→ ② CLI 缺失自動安裝 → ③ 無 LLM 停下詢問 → ④ 提取業務脈絡 → ⑤ 跑評審 → ⑥ 分級(High/Medium/Low)→ ⑦ 按需修復。關鍵:第 ⑦ 步是修復前先問,不像 Command 的預設自動修復。
把 open-code-review.ts 放到 ~/.config/opencode/plugins/ 就自動註冊。它暴露 ocr_review(結構化 JSON)和 ocr_health(版本+連通性),以及 /ocr-review、/ocr-health 斜線命令。審計用 --audience agent + JSON 輸出、15 分鐘超時、10 MiB 輸出上限。
ocr_review / ocr_health 工具。你在 OpenCode 開發一個功能,改了 6 個檔。你要不離開 OpenCode:讓 agent 呼叫 ocr_review 取得結構化評論 → 讀取 ocr_health 確認環境 → 依分級修復 → 再呼叫一次 ocr_review 驗證已修。
mkdir -p ~/.config/opencode/plugins
curl -fsSL \
https://raw.githubusercontent.com/alibaba/open-code-review/main/plugins/open-code-review/opencode/open-code-review.ts \
-o ~/.config/opencode/plugins/open-code-review.ts
ocr_health
# → version: 1.9.2, LLM: connected, provider: anthropic
ocr_review(scope: "workspace")
# → JSON: 6 files reviewed, 4 comments
# HIGH: auth.go — token 過期未驗證
# MED: store.go — 未驗證 user-supplied path
先修 HIGH(auth.go)再修 MED(store.go),Low 跳過。修完 git add 進 staged。
ocr_review(scope: "workspace")
# → 若 HIGH 已消失、原 HIGH 位置乾淨 → 確認修復
OpenCode 原生工具把「評審」變成 agent 可程式化的函式——評審 → 修復 → 復審是單一閉環,不需要開新終端、不需要手動貼 JSON。ocr_health 是前置檢查(避免對壞掉的 LLM 端點白跑一次評審),ocr_review 回傳的結構化 JSON 讓 agent 能「依 severity 排修復順序」而不是一股腦全改。
預期產出
round 1: HIGH(1) MED(1) LOW(2) → 修 HIGH + MED
round 2: HIGH(0) MED(0) LOW(2) → 乾淨通過(Low 可留)
→ 修復閉環完成
| 方式 | 誰呼叫 LLM | 修復動作 | 執行者 |
|---|---|---|---|
| Agent Skill | OCR | 修復前先問 | 宿主 agent 執行 |
| Command | OCR | 預設自動修復 | Claude Code 執行 |
| OpenCode 工具 | OCR | agent 自行決定 | OpenCode agent 執行 |
原生工具是「工具呼叫即函式」——agent 拿到的是結構化 JSON,不是一段要它照做的 prompt。這比 skill 更「確定性」:沒有 prompt 解析歧義,agent 直接讀 comments[] 的欄位決定下一步。
# OpenCode agent 收到 4 條評論,直接全數自動修復:
# 1. 依建議改了 auth.go 的邏輯
# 2. 但建議是「引用外部檔案」的脈絡性建議,agent 沒讀那個檔案
# 3. 修完跑測試 → 通過(測試沒覆蓋到)
# 4. 復審 ocr_review → HIGH 消失(因為行號變了,錨定不到)
「HIGH 消失」在復審裡不一定是「修好了」——行號變動後錨定可能失敗,評論被 REVIEW_FILTER_TASK 當「不匹配」濾掉。防禦:復審前對照「被修的位置的程式碼」而非只看「評論數歸零」;修復後跑一次 git diff 確認改動落在預期範圍;對「引用型」建議,先讀被引用的檔案再動手。
| 症狀 | 可能原因 | 解決方案 |
|---|---|---|
plugin 註冊後 ocr_review 不存在 | plugin 檔沒放對路徑 / 沒重載 | 確認在 ~/.config/opencode/plugins/;重啟 OpenCode 或重載 plugin |
ocr_health 顯示 LLM 未連線 | OCR 端點解析鏈沒找到三元組 | 跑 ocr config set 或匯出 OCR_LLM_* env,再 ocr_health |
| agent 修復後復審「HIGH 消失但沒修好」 | 行號變動導致錨定失敗,filter 誤刪 | 對照 git diff 確認修復落在預期位置;看 re_location_task 泳道 |
| skill 停在「修復前先問」你不想要 | Skill 設計如此 | 改用 Command(預設自動修復)或 OpenCode 工具 |
| 自動修復引入了新 bug | agent 沒讀被引用的檔案就套用建議 | 要求 agent 修復前先 file_read 引用檔;修復後跑測試 |