Skip to main content

Module apply_patch

Module apply_patch 

Source
Expand description

Pure apply_patch engine — parser, graduated fuzzy matcher, and applier — adapted from OpenAI Codex’s apply-patch crate.

It lives in the runtime crate (rather than beside the tool) so BOTH the main crate’s apply_patch tool AND the approval-replay path can apply patches without duplicating the engine. It is PURE: parsing and applying operate on &str; all file I/O stays with the callers (via the confined pathguard).

Trimmed from Codex: no Lark grammar, no local_shell/heredoc extraction, no lenient GPT-4.1 mode, no streaming — the patch arrives as one string.

Structs§

AppliedFile
The result of applying chunks: the new file text and whether any chunk had to be located fuzzily (whitespace/Unicode-normalized rather than byte-exact).
UpdateFileChunk
One contiguous edit region within an UpdateFile hunk. old_lines is the span to locate (context + removed lines, in file order); new_lines is its replacement (context + added lines).

Enums§

ApplyError
Why applying an update hunk failed. Rendered back to the model.
Hunk
One file operation in a patch.
ParseError
A patch parse failure, rendered back to the model so it can fix the envelope.

Functions§

derive_new_contents
Apply chunks to original, returning the new file contents.
parse_patch
Parse a complete patch into its hunks. Strict: requires the Begin/End markers (tolerating surrounding blank lines) and rejects stray lines.