mend is a command-line tool that applies an edit an AI model wrote to a tree of
text files. Models write edits in four formats — a unified diff (often with wrong
line numbers), SEARCH/REPLACE blocks, the V4A patch format, and text-editor tool
calls as JSON — and mend reads all four to one written contract, SPEC.md:
it finds the lines each edit names even when the model drifted their whitespace
or indentation, and changes every file or none.
Node 22 and its standard library only; there is nothing to install.
node main.ts [--format=NAME] [--check] [--strict] [PATCH]
- The working directory is the root of the tree; every path in a patch is relative to it.
PATCHis the patch file. When it is absent or-, the patch is read from standard input.--format=NAMEreads the patch asunified,search-replace,v4aorjson; the default,auto, detects the format from the patch text.--checkdoes everything but write: the same output and exit code, and no file is created, changed or deleted.--strictmatches lines exactly (tier 0 only). Without it, lines also match with trailing whitespace removed (tier 1), then with leading and trailing whitespace removed (tier 2), and added lines are re-indented to the file's own indentation at tier 2.
- Exit 0: one line per changed path (
Aadded,Ddeleted,Mmodified,R <old> -> <new>moved), in byte order of the paths, thenok: <n> files. - Exit 1: nothing is written. One
error: <code> <path>line per failed edit (no-match,ambiguous,missing,exists,unsafe), in the patch's order, thenfailed: <k> of <n> edits. - Exit 2: a single line —
error: usage,error: no-patch,error: formatorerror: parse <N>.
SPEC.md is the whole contract: formats, matching tiers, line endings
(LF/CRLF, final line breaks), safe paths and atomicity are all specified there.
main.ts— the CLI.runner.ts— the make.fun trial runner (hands checks from the trial env tomain.ts); kept as the kit ships it.check.ts— runsmain.tsover the kit's 100 public practice checks:node check.ts <practice.json>.SPEC.md— the specification mend implements.