# Sequence three way merge

`sequence-three-way-merge` · version 1.0.0 · Sequences & diffs · free, no key needed

Three-way merge two sequence descendants against a shared base into clean or conflict regions.

**Use when you need to: sequence three way merge · three-way merge two sequences against a base · sequence merge regions.**

## Supported

- sequence three way merge
- three-way merge two sequences against a base
- sequence merge regions

## Not supported

- fuzzy matching
- text conflict markers
- RFC 7396 JSON merge patch
- RFC 6902 JSON Patch
- csv row diff
- patience merge

## Behavior

- base, ours, and theirs are sequences of JSON null, boolean, string, or IEEE-754 safe integer items.
- Regions come from mergeRegions on the Myers SES of base→ours and base→theirs.
- Non-empty abutting ranges do not overlap. Empty spans at the same base index overlap. An insertion index inside another span overlaps.
- Identical overlapping replacements collapse to one ok region. Distinct overlapping replacements are a conflict.
- status is clean or conflict. result concatenates ok items when clean and is null when any conflict exists.
- A clean result must not exceed 1024 items.
- Ok regions are {type, items}. Conflict regions are {type, base, ours, theirs}.
- base ["A","B","C"], ours ["A","X","C"], theirs ["A","B","Y"] is clean with result ["A","X","Y"].
- ours ["A","X","C"] vs theirs ["A","Y","C"] is a conflict on B. The string "__proto__" is an ordinary item.

## Input

- `base` (array of null or boolean or string or integer, required): max items 1024
- `ours` (array of null or boolean or string or integer, required): max items 1024
- `theirs` (array of null or boolean or string or integer, required): max items 1024

## Output

- `status` (one of "clean", "conflict", required)
- `regions` (array of any, required)
- `result` (array or null, required)

## Limits

- max sequence items: 1024
- max item string bytes: 4096
- max text bytes: 262144
- max output bytes: 1048576

## Example

Request input:

```json
{
  "base": [
    "A",
    "B",
    "C"
  ],
  "ours": [
    "A",
    "X",
    "C"
  ],
  "theirs": [
    "A",
    "B",
    "Y"
  ]
}
```

Response:

```json
{
  "result": {
    "status": "clean",
    "regions": [
      {
        "type": "ok",
        "items": [
          "A",
          "X",
          "Y"
        ]
      }
    ],
    "result": [
      "A",
      "X",
      "Y"
    ]
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "sequence-three-way-merge",
  "version": "1.0.0",
  "input": {
    "base": [
      "A",
      "B",
      "C"
    ],
    "ours": [
      "A",
      "X",
      "C"
    ],
    "theirs": [
      "A",
      "B",
      "Y"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/sequence-three-way-merge/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"base":["A","B","C"],"ours":["A","X","C"],"theirs":["A","B","Y"]}'
```

The machine-readable contract is at [/v1/tools/sequence-three-way-merge/versions/1.0.0](/v1/tools/sequence-three-way-merge/versions/1.0.0).

### CLI

```sh
node cli.mjs run sequence-three-way-merge 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Sequence edit script](/tools/sequence-edit-script): Compute the Myers shortest edit script between two bounded sequences, with keep/delete/insert counts.
- [Sequence LCS](/tools/sequence-lcs): Compute the longest common subsequence of two bounded sequences from the Myers shortest edit script.
- [Sequence longest common substring](/tools/sequence-lcsubstring): Find the longest contiguous common subarray of two bounded sequences.
- [Sequence apply edit script](/tools/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](/tools/sequence-compose-edit-scripts): Compose two sequence edit scripts into one per-item keep/delete/insert script.
- [Sequence index map](/tools/sequence-index-map): Map each left-sequence index to a kept right index, or null if deleted, and list inserted right indices.
