Sequence invert hunks
sequence-invert-hunks · version 1.0.0 · Sequences & diffs · free, no key needed
Invert sequence hunks by swapping delete/insert and old/new counts.
Use when you need to: sequence invert hunks · invert sequence diff hunks · reverse sequence hunks.
Supported
- sequence invert hunks
- invert sequence diff hunks
- reverse sequence hunks
Not supported
- fuzzy matching
- offset search
- unified text invert
- RFC 6902 JSON Patch
Behavior
- Input hunks have keys old_start, old_count, new_start, new_count, and ops. Extra keys are rejected.
- Inversion swaps delete with insert and old_* with new_*. keep ops stay keep.
- Every hunk op.value must be a sequence item. Line records and other objects are rejected.
- Op values are copied. Empty hunks invert to empty hunks.
- The context-0 hunk that deletes B and inserts X inverts to delete X and insert B with swapped starts.
- Unknown input fields are rejected.
Input
hunks(array of any, required): max items 1024
Output
hunks(array of any, required): max items 1024
Limits
- max hunks: 1024
- max output bytes: 1048576
Example
Request input:
{
"hunks": [
{
"old_start": 1,
"old_count": 1,
"new_start": 1,
"new_count": 1,
"ops": [
{
"op": "delete",
"value": "B"
},
{
"op": "insert",
"value": "X"
}
]
}
]
}
Response:
{
"result": {
"hunks": [
{
"old_start": 1,
"old_count": 1,
"new_start": 1,
"new_count": 1,
"ops": [
{
"op": "insert",
"value": "B"
},
{
"op": "delete",
"value": "X"
}
]
}
]
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "sequence-invert-hunks",
"version": "1.0.0",
"input": {
"hunks": [
{
"old_start": 1,
"old_count": 1,
"new_start": 1,
"new_count": 1,
"ops": [
{
"op": "delete",
"value": "B"
},
{
"op": "insert",
"value": "X"
}
]
}
]
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/sequence-invert-hunks/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"hunks":[{"old_start":1,"old_count":1,"new_start":1,"new_count":1,"ops":[{"op":"delete","value":"B"},{"op":"insert","value":"X"}]}]}'
The machine-readable contract is at /v1/tools/sequence-invert-hunks/versions/1.0.0.
CLI
node cli.mjs run sequence-invert-hunks 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Sequence apply hunks: Apply disjoint original-address sequence hunks with exact context and no fuzz.
- Sequence diff hunks: Group a Myers sequence edit script into context hunks with 0-based original addresses.
- Sequence apply edit script: Apply a keep/delete/insert edit script to a bounded sequence with exact value matching and no fuzz.
- Sequence compose edit scripts: Compose two sequence edit scripts into one per-item keep/delete/insert script.
- Sequence edit script: Compute the Myers shortest edit script between two bounded sequences, with keep/delete/insert counts.
- Sequence index map: Map each left-sequence index to a kept right index, or null if deleted, and list inserted right indices.