# Text three way merge

`text-three-way-merge` · version 1.0.0 · Text · free, no key needed

Three-way merge of text line records with merge or diff3 conflict markers.

**Use when you need to: text three way merge · three-way merge of text · merge base ours theirs with conflict markers.**

## Supported

- text three way merge
- three-way merge of text
- merge base ours theirs with conflict markers

## Not supported

- patience or histogram diff
- unicode normalization
- locale word break
- offset or fuzz patch apply
- RFC 6902 JSON Patch
- filesystem access

## Behavior

- base, ours, and theirs are split into line records; only CRLF, LF, and CR are terminators. Record equality is text plus eol.
- Regions come from mergeRegions on those records using Myers SES(base, ours) and SES(base, theirs) with the library overlap rule.
- status is clean when every region is ok; text is then joinRecords of the merged records, preserving each record eol.
- status is conflict when any region conflicts; text is renderConflictParts of regionsToParts using marker_style merge (default) or diff3.
- Conflict marker lines use LF. Nonempty conflict blocks that do not already end with LF get a trailing LF. merge omits the ||||||| base section; diff3 includes it.
- Labels default to ours, theirs, and base. Labels are nonempty, at most 256 UTF-8 bytes, and must not contain CR or LF.
- Identical replacements on overlapping spans collapse to one ok region. Abutting nonempty base ranges do not overlap.

## Input

- `base` (string, required): max length 262144
- `ours` (string, required): max length 262144
- `theirs` (string, required): max length 262144
- `marker_style` (one of "merge", "diff3", optional)
- `ours_label` (string, optional): min length 1; max length 256
- `theirs_label` (string, optional): min length 1; max length 256
- `base_label` (string, optional): min length 1; max length 256

## Output

- `status` (one of "clean", "conflict", required)
- `text` (string, required): max length 1048576

## Limits

- max text bytes: 262144
- max line count: 4096
- max line bytes: 16384
- max label bytes: 256
- max output bytes: 1048576

## Example

Request input:

```json
{
  "base": "a\nb\nc\n",
  "ours": "a\nx\nc\n",
  "theirs": "a\nb\ny\n"
}
```

Response:

```json
{
  "result": {
    "status": "clean",
    "text": "a\nx\ny\n"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "text-three-way-merge",
  "version": "1.0.0",
  "input": {
    "base": "a\nb\nc\n",
    "ours": "a\nx\nc\n",
    "theirs": "a\nb\ny\n"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/text-three-way-merge/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"base":"a\nb\nc\n","ours":"a\nx\nc\n","theirs":"a\nb\ny\n"}'
```

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

### CLI

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

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

## Related tools

- [Text conflict parse](/tools/text-conflict-parse): Parse merge or diff3 conflict-marker text into ordered text and conflict parts.
- [Text conflict render](/tools/text-conflict-render): Render text and conflict parts as merge or diff3 conflict-marker text.
- [Text extract between](/tools/text-extract-between): Extract exact substrings between start and end markers, left to right and non-overlapping.
- [Text prefix suffix check](/tools/text-prefix-suffix-check): Exact prefix and/or suffix boolean checks using JS string startsWith/endsWith.
- [Text tabs to spaces](/tools/text-tabs-to-spaces): Convert tab characters to spaces.
- [Text apply unified patch](/tools/text-apply-unified-patch): Apply a one-file unified patch to text at original line addresses with exact hunk matches.
