| Phase | 3 — Execution & sandboxing |
| Status | Not started |
| Depends on | 01 |
| Size | M |
| Drop-in critical | ★★ (byte-compatible patch format) |
Port codex-apply-patch: parse and apply the Codex patch envelope
(*** Begin Patch … *** End Patch) with add/update/delete/move operations and
context-seeking hunks. The grammar and application semantics must be byte-compatible
since the model emits these directly.
reference-codex/codex-rs/apply-patch/src/parser.rs(the Lark grammar + lenient parsing).apply-patch/src/application logic, delta tracking, Unicode normalization.
- Parse the grammar exactly:
*** Begin Patch/*** End Patch, optional*** Environment ID: <file>.*** Add File: <path>++-prefixed lines.*** Delete File: <path>.*** Update File: <path>+ optional*** Move to: <path>+ change blocks of@@/@@ <ctx>context markers and+/-/change lines, optional*** End of Fileterminator.
- Lenient mode (strip surrounding whitespace around markers), context-seeking chunk application, Unicode fuzzy matching (EN DASH / non-breaking hyphen).
- EOF handling: final empty line omitted from the line array and re-added on serialization.
- Delta tracking: capture before/after, mark partial/inexact application
(
AppliedPatchDelta.exact), perform move = write-dest + delete-src. - Available both as a library (for the tool) and as the
apply_patch/applypatcharg0 multitool entry (spec 41) andcodex apply(git applyof latest diff).
- Golden corpus: every captured
apply_patchinput from Codex applied bycodexgoyields byte-identical file results and the sameexact/inexact status. - Marker strings match byte-for-byte (
"*** Begin Patch","*** Update File: ", etc.). - Move + delete-source semantics match, including failure tracking.
- Malformed-patch error messages are in the same class as Codex.
- The lenient parser + context-seeking has many edge cases; build the test corpus early from upstream tests.
- Unicode normalization must match the exact code points Codex special-cases.
- Approval UI for patches (specs 30/38).