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
说明
- 路径相对于工作区根目录解析
- 在
*** Update File:块内使用*** Move to:重命名文件 *** End of File标记仅在需要时的 EOF 插入- 实验性功能,默认禁用。通过
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"
}