Text invert unified patch
text-invert-unified-patch · version 1.0.0 · Text · free, no key needed
Invert a one-file unified patch by swapping file names and delete/insert ops.
Use when you need to: text invert unified patch · reverse a unified diff · invert unified patch hunks.
Supported
- text invert unified patch
- reverse a unified diff
- invert unified patch hunks
Not supported
- offset or fuzz patch apply
- preserve original CR/LF through unified text
- git diff --git headers
- binary patches
- fuzzy matching
- filesystem access
Behavior
- unified is one-file unified diff text; strip is an integer 0..8 (default 0) applied to ---/+++ paths before names are swapped.
- An empty patch (no hunks) inverts to an empty unified string.
- Inversion swaps from_name with to_name, swaps old_* with new_* on each hunk, maps delete to insert and insert to delete, and leaves keep ops unchanged.
- Emitted unified always writes both hunk counts with a comma and a newline after every line including the last.
- No-newline markers follow inverted body lines whose record eol is empty.
- Git multi-file headers, binary markers, and original CR/LF through unified body text are not supported.
Input
unified(string, required): max length 262144strip(integer, optional): min 0; max 8
Output
unified(string, required): max length 1048576
Limits
- max text bytes: 262144
- max hunks: 1024
- max path bytes: 1024
- max strip: 8
- max output bytes: 1048576
Example
Request input:
{
"unified": "--- a\n+++ b\n@@ -1,2 +1,2 @@\n a\n-b\n+c\n"
}
Response:
{
"result": {
"unified": "--- b\n+++ a\n@@ -1,2 +1,2 @@\n a\n+b\n-c\n"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "text-invert-unified-patch",
"version": "1.0.0",
"input": {
"unified": "--- a\n+++ b\n@@ -1,2 +1,2 @@\n a\n-b\n+c\n"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/text-invert-unified-patch/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"unified":"--- a\n+++ b\n@@ -1,2 +1,2 @@\n a\n-b\n+c\n"}'
The machine-readable contract is at /v1/tools/text-invert-unified-patch/versions/1.0.0.
CLI
node cli.mjs run text-invert-unified-patch 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Text apply unified patch: Apply a one-file unified patch to text at original line addresses with exact hunk matches.
- Text parse unified patch: Parse a one-file unified patch into path names and 0-based hunks.
- Text unified diff: Emit a one-file unified diff of two texts with comma counts and LF document breaks.
- Text diff stats: Summarize a line-record diff as keep, insert, delete, and hunk counts.
- Text line diff: Diff two texts as line records, preserving each line terminator.
- Text word diff: Diff two texts as whitespace versus non-whitespace word tokens.