Zenpatch
A robust library for applying text-based patches, designed for AI coding agents. It operates on an in-memory Virtual File System (VFS).
Patching is a crucial component of AI-driven coding. AI-generated patches are often imperfect and require lenient rules for application, especially concerning whitespace and special characters. Inspired in part by https://github.com/openai/codex
's approach to whitespace, Zenpatch offers a novel solution.
To the best of our knowledge, Zenpatch is a unique implementation that uses backtracking to apply patches. This approach has several advantages:
- Simplicity: It avoids the need for complex, hand-written heuristics for patch application.
- Precision: It is precise and will not apply an ambiguous patch. Ambiguity is detected by counting the number of possible solutions; a correct patch must have exactly one unique solution.
Usage
The primary function is zenpatch::apply
, which takes a patch string and a Vfs
(a HashMap<String, String>
), and returns the patched Vfs
.
Example
use ;
Patch Format
For detailed instructions on the text-based patch format, especially for use in AI coding agents, please refer to the llms.txt
file in this crate. The content of this file is also available programmatically via the zenpatch::get_llm_instructions()
function.