Deprecated: use
github.com/fgn/applypatch.applypatch.Applyandapplypatch.ApplyBatchbehave like this package, and it adds a Codex-compatible mode and the Codex*** Begin Patchformat.
A strict Go applier for V4A diffs, the patch format OpenAI models emit through
the apply_patch
tool. It is a Go port of
applyDiff
from the OpenAI Agents SDK for JavaScript,
changed to fail closed instead of guessing.
go get github.com/fgn/v4ainput := "def greet():\n print(\"Hi\")\n"
diff := "@@ def greet():\n- print(\"Hi\")\n+ print(\"Hello\")"
output, err := v4a.Apply(input, diff)ApplyBatch applies several diffs for one file against the same original
input and fails as a whole if any diff fails or two diffs overlap.
- Anchors, context, and removed lines must match byte for byte and exactly once. There is no whitespace trimming or Unicode normalization.
- An insertion without context needs an anchor,
*** End of File, or an empty input. - Only
update_filediffs are supported. Creating, deleting, and moving files is left to the caller. - LF and CRLF newlines and a missing final newline are preserved.
Development tasks run through Task, which you can
install from taskfile.dev/docs/installation.
Run task to format, lint, and test, and task --list to see the rest.
MIT, see LICENSE. Based on the OpenAI Agents SDK for JavaScript, copyright (c) 2025 OpenAI, also MIT.