Tools
apply_patch 工具
使用結構化修補格式套用檔案變更。這很適合多檔案
或多區塊編輯,因為單一 edit 呼叫會很脆弱。
此工具接受單一 input 字串,其中包裝一個或多個檔案操作:
*** Begin Patch*** Add File: path/to/file.txt+line 1+line 2*** Update File: src/app.ts@@-old line+new line*** Delete File: obsolete.txt*** End Patch參數
input(必填):完整修補內容,包括*** Begin Patch和*** End Patch。
注意事項
- 修補路徑支援相對路徑(從工作區目錄起算)與絕對路徑。
tools.exec.applyPatch.workspaceOnly預設為true(限制在工作區內)。只有在你有意讓apply_patch寫入/刪除工作區目錄外的內容時,才將其設為false。- 在
*** Update File:區塊中使用*** Move to:來重新命名檔案。 *** End of File會在需要時標記僅限 EOF 的插入。- 預設可用於 OpenAI 和 OpenAI Codex 模型。設定
tools.exec.applyPatch.enabled: false可停用它。 - 可選擇透過模型使用
tools.exec.applyPatch.allowModels進行限制。 - 設定僅位於
tools.exec下。
範例
{ "tool": "apply_patch", "input": "*** Begin Patch\n*** Update File: src/index.ts\n@@\n-const foo = 1\n+const foo = 2\n*** End Patch"}