Text apply unified patch
text-apply-unified-patch · version 1.0.0 · Text · free, no key needed
Apply a one-file unified patch to text at original line addresses with exact hunk matches.
Use when you need to: text apply unified patch · apply unified diff to text · apply a unified patch exactly.
Supported
- text apply unified patch
- apply unified diff to text
- apply a unified patch exactly
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) removing that many leading path components from ---/+++ names.
- text is split into line records; only CRLF, LF, and CR are terminators.
- Hunks apply against the original record array at the parsed 0-based old_start addresses. old ranges must be sorted and disjoint; empty ranges at the same index overlap and are rejected.
- Each hunk old side must equal the original slice; there is no search, fuzz, or offset.
- Parsed body records use eol LF, or empty when a no-newline marker follows that body line. Original CR/LF is not carried through unified text.
- identical is true iff the patch contains no hunks; an empty unified string is a no-op.
- Output text is joinRecords of the patched records and must fit the output byte budget.
Input
text(string, required): max length 262144unified(string, required): max length 262144strip(integer, optional): min 0; max 8
Output
text(string, required): max length 1048576identical(boolean, required)
Limits
- max text bytes: 262144
- max line count: 4096
- max line bytes: 16384
- max hunks: 1024
- max path bytes: 1024
- max strip: 8
- max output bytes: 1048576
Example
Request input:
{
"text": "a\nb\n",
"unified": "--- a\n+++ b\n@@ -1,2 +1,2 @@\n a\n-b\n+c\n"
}
Response:
{
"result": {
"text": "a\nc\n",
"identical": false
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "text-apply-unified-patch",
"version": "1.0.0",
"input": {
"text": "a\nb\n",
"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-apply-unified-patch/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"text":"a\nb\n","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-apply-unified-patch/versions/1.0.0.
CLI
node cli.mjs run text-apply-unified-patch 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Text invert unified patch: Invert a one-file unified patch by swapping file names and delete/insert ops.
- 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 line endings normalize: Normalize all line endings in a text to a specific format (LF, CRLF, or CR).