Skip to content
This repository was archived by the owner on Sep 24, 2026. It is now read-only.

Repository files navigation

v4a

Deprecated: use github.com/fgn/applypatch. applypatch.Apply and applypatch.ApplyBatch behave like this package, and it adds a Codex-compatible mode and the Codex *** Begin Patch format.

Go Reference License

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.

Install

go get github.com/fgn/v4a

Usage

input := "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.

Behavior

  • 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_file diffs are supported. Creating, deleting, and moving files is left to the caller.
  • LF and CRLF newlines and a missing final newline are preserved.

Development

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.

License

MIT, see LICENSE. Based on the OpenAI Agents SDK for JavaScript, copyright (c) 2025 OpenAI, also MIT.

About

Strict Go port of the OpenAI Agents SDK applyDiff for V4A apply_patch update diffs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages