| 工具 | Plan | Main | 用途 |
|---|---|---|---|
task_done | ✗ | ✓ | 「我完成了」——終止迴圈 |
code_comment | ✗ | ✓ | 發出一條帶行範圍 + 建議的評審評論 |
file_read | ✗ | ✓ | 讀變更後快照中某檔的一段 |
file_read_diff | ✓ | ✓ | 讀另一檔的 diff 確認跨檔關切 |
file_find | ✓ | ✓ | 依檔名關鍵字定位檔案 |
code_search | ✓ | ✓ | 全倉 grep(git grep) |
task_done 與 code_comment 在 plan 階段有意不可用——plan 是唯讀的。
file_read / file_read_diff / file_find / code_search 讓模型更好理解目前檔的 diff;收集脈絡時發現的問題按設計被忽略。跨檔關切只有在目前檔 diff 中可觀察時,才會成為評論。{ "name": "task_done", "input": { "state": "DONE" } }
agent 看到 task_done 後停止呼叫 LLM,開始處理已累積的 code_comment。state 可為 DONE 或 FAILED。
{
"name": "code_comment",
"input": {
"comments": [{
"content": "`tx.Rollback()` is never deferred — early returns leak the transaction.",
"existing_code": "tx, err := db.Begin()\nif err != nil {\n return err\n}",
"suggestion_code": "tx, err := db.Begin()\nif err != nil {\n return err\n}\ndefer tx.Rollback()"
}]
}
}
comments 是陣列,一次可發多條。每條錨定到 existing_code 片段,OCR 自動算行號。
RE_LOCATION_TASK。比對對空白不敏感。最後手段以 start_line=0 交付——問題是真的,但需自行定位。
{ "name": "file_read", "input": { "file_path": "src/foo.go", "start_line": 10, "end_line": 80 } }
讀變更後形式的一段行(每行以 1 起始行號 + | 前綴)。每次最多 500 行。
{ "name": "file_read_diff", "input": { "path_array": ["src/api/handler.go", "src/db/queries.go"] } }
讀同一變更集中其他檔的 diff。路徑不在變更集則靜默省略。
{ "name": "file_find", "input": { "query_name": "UserService", "case_sensitive": false } }
與每個檔的 basename 做子串匹配,最多 100 條。無匹配回 // The file was not found。
{
"name": "code_search",
"input": {
"search_text": "TODO|FIXME",
"file_patterns": ["*.go", ":(exclude)vendor/"],
"case_sensitive": false,
"use_perl_regexp": true
}
}
由 git grep 驅動,理解 pathspec、遵循 .gitignore。每檔命中上限 100。
| 目標 | file_patterns |
|---|---|
| 所有 Go 檔 | ["*.go"] |
| 除測試外所有 Go | ["*.go", ":(exclude)*_test.go"] |
| 僅一個目錄 | ["src/api/"] |
| 多型別、排除 vendor | ["*.go", "*.ts", ":(exclude)vendor/", ":(exclude)node_modules/"] |
tools.json 刪掉不要的條目,跑 ocr review --tools ./my-tools.json。name、改 description 引導模型(如「讀 file_read 時至少讀變更附近 30 行」)。新增新工具名需在 Go 側接入(internal/tool/definitions.go)——單靠 JSON 無法加新行為。
Plan 階段只能用 file_read_diff、file_find、code_search——三個脈絡工具。task_done 和 code_comment 被禁用。為什麼?Plan 是唯讀分析階段——只收集脈絡,不做決策。這確保 plan 產出是純指引,不附帶評論。
錨定不是一次性嘗試:
existing_codeRE_LOCATION_TASK 請模型重新錨定比對對空白不敏感。最後手段以 start_line=0 交付——問題是真的,但需自行定位。
file_read、file_read_diff、file_find、code_search 都是唯讀脈絡工具。它們讓模型更好理解目前檔的 diff,但收集脈絡時發現的問題按設計被忽略。只有在目前檔 diff 中可觀察的跨檔問題才會成為評論。這是刻意的——避免「噪音評論」。
code_comment 的錨定三階段。延伸閱讀:架構 · 程式碼:internal/tool · MCP 伺服器