# Text line diff

`text-line-diff` · version 1.0.0 · Text · free, no key needed

Diff two texts as line records, preserving each line terminator.

**Use when you need to: text line diff · line record text diff · diff texts by lines.**

## Supported

- text line diff
- line record text diff
- diff texts by lines

## Not supported

- fuzzy matching
- patience/histogram diff
- unicode normalization
- locale-aware line breaking
- binary patches
- git diff --git headers
- filesystem access

## Behavior

- left and right are split with splitRecords: only CRLF, LF, and CR terminate lines.
- Record equality is text plus eol; the same characters with CRLF versus LF are different lines.
- Empty text yields no records; a missing final newline is stored as eol "".
- U+2028, U+2029, and U+FEFF stay inside line text and are not terminators.
- The Myers SES uses recordEqual; when D-paths tie, the library prefers delete from the left.
- Hunks come from hunksFromSes. context defaults to 3, may be 0, and is at most 16.
- Hunk op values are {text, eol} objects. identical is true iff there are no change ops.
- lines_left and lines_right are the record counts of left and right.
- Unknown input fields are rejected. Prototype-like line texts such as "__proto__" are ordinary strings.

## Input

- `left` (string, required): max length 262144
- `right` (string, required): max length 262144
- `context` (integer, optional): min 0; max 16

## Output

- `hunks` (array of object, required): max items 1024
- `identical` (boolean, required)
- `lines_left` (integer, required): min 0
- `lines_right` (integer, required): min 0

## Limits

- max text bytes: 262144
- max line count: 4096
- max line bytes: 16384
- max context: 16
- max hunks: 1024
- max output bytes: 1048576

## Example

Request input:

```json
{
  "left": "a\nb\n",
  "right": "a\nc\n",
  "context": 0
}
```

Response:

```json
{
  "result": {
    "hunks": [
      {
        "old_start": 1,
        "old_count": 1,
        "new_start": 1,
        "new_count": 1,
        "ops": [
          {
            "op": "delete",
            "value": {
              "text": "b",
              "eol": "\n"
            }
          },
          {
            "op": "insert",
            "value": {
              "text": "c",
              "eol": "\n"
            }
          }
        ]
      }
    ],
    "identical": false,
    "lines_left": 2,
    "lines_right": 2
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "text-line-diff",
  "version": "1.0.0",
  "input": {
    "left": "a\nb\n",
    "right": "a\nc\n",
    "context": 0
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/text-line-diff/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"left":"a\nb\n","right":"a\nc\n","context":0}'
```

The machine-readable contract is at [/v1/tools/text-line-diff/versions/1.0.0](/v1/tools/text-line-diff/versions/1.0.0).

### CLI

```sh
node cli.mjs run text-line-diff 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [Text word diff](/tools/text-word-diff): Diff two texts as whitespace versus non-whitespace word tokens.
- [Text diff stats](/tools/text-diff-stats): Summarize a line-record diff as keep, insert, delete, and hunk counts.
- [Text lines chunk](/tools/text-lines-chunk): Split parsed lines into consecutive chunks of size lines each.
- [Text lines count](/tools/text-lines-count): Count exact line multiplicities in first-seen order.
- [Text lines difference](/tools/text-lines-difference): Set difference a minus b using exact line equality.
- [Text lines multiset subtract](/tools/text-lines-multiset-subtract): Multiset subtract b from a: remaining counts, first-seen order from a.
