Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

applypatch

Go Reference License

Apply the patches OpenAI models write with the apply_patch tool, to strings in memory. It handles both the V4A update diffs of the Responses API apply_patch tool and the *** Begin Patch format of the Codex CLI, and it exports the Codex tool definition.

Install

go get github.com/fgn/applypatch

Usage

// One text and one update diff.
output, err := applypatch.Apply(input, diff)

// A Codex patch over several files: add, delete, update, move.
files, err := applypatch.Codex.ApplyFiles(files, patch)

// The tool to offer a model; send its input to ApplyFiles.
tool := applypatch.CodexTool()

Modes

  • Strict, the default, never guesses. Anchors, context, and removed lines must match byte for byte and exactly once, or the patch is an error the model can fix.
  • Codex does what the Codex CLI does with line-ending preservation on: first match, then fallbacks that ignore whitespace and Unicode punctuation, insertions without context at the end of the file, and a newline after every line. It is checked against the real Codex binary.

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, including the Codex parity, fuzz, and mutation tasks.

License

MIT, except the parts ported from OpenAI Codex, which are Apache-2.0; see NOTICE. Strict mode is a Go port of applyDiff from the OpenAI Agents SDK for JavaScript (MIT), and Codex mode, the patch parser, and the tool definition are a Go port of apply_patch from OpenAI Codex (Apache-2.0).

About

Apply OpenAI apply_patch patches in Go: strict, or exactly like the Codex CLI, checked against the Codex binary

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages