One patch tool for every AI edit format.
mend applies an edit that an AI model wrote to a tree of text files. Models write edits in four formats, and mend reads them all to one specification:
- unified diff — often with wrong line numbers; hunks are matched by their lines, nearest to the hunk header
- SEARCH/REPLACE blocks —
<<<<<<< SEARCH/=======/>>>>>>> REPLACE - V4A patch —
*** Begin Patch/*** Add File:/*** Update File:/*** Delete File:/*** End Patch - JSON tool calls — one edit object per line (JSON Lines) or a JSON array:
create,str_replace,insert
Matching is fuzzy in three tiers: exact lines, then lines equal once trailing whitespace is ignored, then lines equal once leading and trailing whitespace is ignored (re-indented to the file's own indentation). --strict matches exactly only.
Every file is changed or nothing is: a failed edit changes nothing, edits after it still run and are reported, and no file is written when any edit failed.
node main.ts [--format=NAME] [--check] [--strict] [PATCH]
PATCHis the patch file, relative to the working directory; when absent or-, the patch is read from standard input.--format=NAMEreads one format:unified,search-replace,v4a,json, orauto(the default, which detects it).--checkdoes everything but write: same output and exit code, no file created, changed or deleted.--strictmatches lines exactly (tier 0 only).
Exit codes: 0 applied (ok: <n> files), 1 some edits failed (failed: <k> of <n> edits), 2 usage, unreadable patch, unknown format or parse error.
Node 22 and its standard library only — nothing is installed before the program runs. Deterministic: the same check gives the same exit code, stdout and files every run.
MIT — see LICENSE.