apply_patch tool
使用结构化的 patch 格式应用文件修改。这个 tool 特别适合多文件或多区块编辑的场景,比单次调用 edit 更稳定可靠。
这个 tool 接受一个 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(必需):完整的 patch 内容,包括*** Begin Patch和*** End Patch。
注意事项
- 路径相对于 workspace 根目录解析。
- 在
*** Update File:区块中使用*** Move to:可以重命名文件。 *** End of File标记仅在文件末尾插入内容时使用。- 这是实验性功能,默认禁用。通过
tools.exec.applyPatch.enabled启用。 - 仅支持 OpenAI(包括 OpenAI Codex)。可以通过
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"
}