apply_patch 工具
apply_patch 工具
Section titled “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 Patchinput(必需):完整的补丁内容,包括*** 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"}