Sequence diff hunks
sequence-diff-hunks · version 1.0.0 · Sequences & diffs · free, no key needed
Group a Myers sequence edit script into context hunks with 0-based original addresses.
Use when you need to: sequence diff hunks · grouped sequence diff hunks · sequence context hunks.
Supported
- sequence diff hunks
- grouped sequence diff hunks
- sequence context hunks
Not supported
- fuzzy matching
- patience diff
- histogram diff
- offset search
- RFC 6902 JSON Patch
- csv row diff
Behavior
- left and right are sequences of JSON null, boolean, string, or IEEE-754 safe integer items.
- Hunks are built from the Myers SES via hunksFromSes. context defaults to 3, may be 0, and is at most 16.
- Changes separated by fewer than 2*context keep ops merge into one hunk.
- old_start and new_start are 0-based. When old_count is 0, old_start is the insertion index in [0, left.length].
- Hunk ops are {op, value} only. identical is true iff there are no change ops.
- For left ["A","B","C"] and right ["A","X","C"] with context 0 there is one hunk at old_start 1 replacing B with X.
- The string "__proto__" is an ordinary item. Unknown input fields are rejected.
Input
left(array of null or boolean or string or integer, required): max items 1024right(array of null or boolean or string or integer, required): max items 1024context(integer, optional): min 0; max 16
Output
hunks(array of any, required): max items 1024identical(boolean, required)
Limits
- max sequence items: 1024
- max item string bytes: 4096
- max text bytes: 262144
- max context: 16
- max hunks: 1024
- max output bytes: 1048576
Example
Request input:
{
"left": [
"A",
"B",
"C"
],
"right": [
"A",
"X",
"C"
],
"context": 0
}
Response:
{
"result": {
"hunks": [
{
"old_start": 1,
"old_count": 1,
"new_start": 1,
"new_count": 1,
"ops": [
{
"op": "delete",
"value": "B"
},
{
"op": "insert",
"value": "X"
}
]
}
],
"identical": false
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "sequence-diff-hunks",
"version": "1.0.0",
"input": {
"left": [
"A",
"B",
"C"
],
"right": [
"A",
"X",
"C"
],
"context": 0
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/sequence-diff-hunks/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"left":["A","B","C"],"right":["A","X","C"],"context":0}'
The machine-readable contract is at /v1/tools/sequence-diff-hunks/versions/1.0.0.
CLI
node cli.mjs run sequence-diff-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 invert hunks: Invert sequence hunks by swapping delete/insert and old/new counts.
- 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.