# 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 262144
- `strip` (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:

```json
{
  "unified": "--- a\n+++ b\n@@ -1,2 +1,2 @@\n a\n-b\n+c\n"
}
```

Response:

```json
{
  "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](/docs#connect)), then call `execute` with:

```json
{
  "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)

```sh
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](/v1/tools/text-invert-unified-patch/versions/1.0.0).

### CLI

```sh
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/](/clients/cli/).

## Related tools

- [Text apply unified patch](/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](/tools/text-parse-unified-patch): Parse a one-file unified patch into path names and 0-based hunks.
- [Text unified diff](/tools/text-unified-diff): Emit a one-file unified diff of two texts with comma counts and LF document breaks.
- [Text diff stats](/tools/text-diff-stats): Summarize a line-record diff as keep, insert, delete, and hunk counts.
- [Text line diff](/tools/text-line-diff): Diff two texts as line records, preserving each line terminator.
- [Text word diff](/tools/text-word-diff): Diff two texts as whitespace versus non-whitespace word tokens.
