# Sequence compose edit scripts

`sequence-compose-edit-scripts` · version 1.0.0 · Sequences & diffs · free, no key needed

Compose two sequence edit scripts into one per-item keep/delete/insert script.

**Use when you need to: sequence compose edit scripts · compose two sequence edit scripts · compose keep delete insert scripts.**

## Supported

- sequence compose edit scripts
- compose two sequence edit scripts
- compose keep delete insert scripts

## Not supported

- fuzzy matching
- patience diff
- histogram diff
- RFC 6902 JSON Patch
- unicode normalization
- locale compare

## Behavior

- first and second are op arrays in apply-edit-script shape: each op requires op and value; extra keys are rejected.
- Optional left_index and right_index are accepted on input ops but the composed script is reindexed from the walk.
- first transforms some L to M; second must consume M and produce R. Values that cannot pair are rejected.
- Composition: first deletes pass through, second inserts pass through, insert-then-delete cancels.
- The output script is per-item (adjacent keeps are not collapsed) with keeps, deletions, and insertions counts.
- Example: keep A, delete B, insert C composed with keep A, keep C, insert D yields keep A, delete B, insert C, insert D.
- The string "__proto__" is an ordinary item. Unknown input fields are rejected.

## Input

- `first` (array of object, required): max items 4096
- `second` (array of object, required): max items 4096

## Output

- `ops` (array of object, required): max items 4096
- `keeps` (integer, required): min 0
- `deletions` (integer, required): min 0
- `insertions` (integer, required): min 0

## Limits

- max sequence items: 1024
- max item string bytes: 4096
- max edit ops: 4096
- max output bytes: 1048576

## Example

Request input:

```json
{
  "first": [
    {
      "op": "keep",
      "value": "A"
    },
    {
      "op": "delete",
      "value": "B"
    },
    {
      "op": "insert",
      "value": "C"
    }
  ],
  "second": [
    {
      "op": "keep",
      "value": "A"
    },
    {
      "op": "keep",
      "value": "C"
    },
    {
      "op": "insert",
      "value": "D"
    }
  ]
}
```

Response:

```json
{
  "result": {
    "ops": [
      {
        "op": "keep",
        "value": "A",
        "left_index": 0,
        "right_index": 0
      },
      {
        "op": "delete",
        "value": "B",
        "left_index": 1
      },
      {
        "op": "insert",
        "value": "C",
        "right_index": 1
      },
      {
        "op": "insert",
        "value": "D",
        "right_index": 2
      }
    ],
    "keeps": 1,
    "deletions": 1,
    "insertions": 2
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "sequence-compose-edit-scripts",
  "version": "1.0.0",
  "input": {
    "first": [
      {
        "op": "keep",
        "value": "A"
      },
      {
        "op": "delete",
        "value": "B"
      },
      {
        "op": "insert",
        "value": "C"
      }
    ],
    "second": [
      {
        "op": "keep",
        "value": "A"
      },
      {
        "op": "keep",
        "value": "C"
      },
      {
        "op": "insert",
        "value": "D"
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/sequence-compose-edit-scripts/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"first":[{"op":"keep","value":"A"},{"op":"delete","value":"B"},{"op":"insert","value":"C"}],"second":[{"op":"keep","value":"A"},{"op":"keep","value":"C"},{"op":"insert","value":"D"}]}'
```

The machine-readable contract is at [/v1/tools/sequence-compose-edit-scripts/versions/1.0.0](/v1/tools/sequence-compose-edit-scripts/versions/1.0.0).

### CLI

```sh
node cli.mjs run sequence-compose-edit-scripts 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [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 edit script](/tools/sequence-edit-script): Compute the Myers shortest edit script between two bounded sequences, with keep/delete/insert counts.
- [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.
- [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 three way merge](/tools/sequence-three-way-merge): Three-way merge two sequence descendants against a shared base into clean or conflict regions.
