# Text diff stats

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

Summarize a line-record diff as keep, insert, delete, and hunk counts.

**Use when you need to: text diff stats · count line diff insertions and deletions · summarize text line differences.**

## Supported

- text diff stats
- count line diff insertions and deletions
- summarize text line differences

## Not supported

- character-level stats
- fuzzy matching
- patience/histogram diff
- binary patches
- git diff --git headers
- filesystem access

## Behavior

- left and right are split with splitRecords. Record equality is text plus eol.
- Counts come from the Myers line-record SES: keeps, insertions, and deletions are op-kind totals.
- hunks is the integer hunk count from hunksFromSes, not the hunk list. context defaults to 3, may be 0, and is at most 16.
- identical is true iff there are no change ops. lines_left and lines_right are record counts.
- A single isolated replacement is one hunk for any context 0..16. Far-apart changes may merge when context is large enough.
- Unknown input fields are rejected.

## Input

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

## Output

- `lines_left` (integer, required): min 0
- `lines_right` (integer, required): min 0
- `keeps` (integer, required): min 0
- `insertions` (integer, required): min 0
- `deletions` (integer, required): min 0
- `hunks` (integer, required): min 0
- `identical` (boolean, required)

## 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"
}
```

Response:

```json
{
  "result": {
    "lines_left": 2,
    "lines_right": 2,
    "keeps": 1,
    "insertions": 1,
    "deletions": 1,
    "hunks": 1,
    "identical": false
  }
}
```

## How to call it

### MCP

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

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

### HTTP (no key)

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

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

### CLI

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

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

## Related tools

- [Text line diff](/tools/text-line-diff): Diff two texts as line records, preserving each line terminator.
- [Text lines count](/tools/text-lines-count): Count exact line multiplicities in first-seen order.
- [Text parse unified patch](/tools/text-parse-unified-patch): Parse a one-file unified patch into path names and 0-based hunks.
- [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.
- [Text count](/tools/text-count): Count Unicode code points, UTF-16 code units, UTF-8 bytes, and lines.
- [Text extract between](/tools/text-extract-between): Extract exact substrings between start and end markers, left to right and non-overlapping.
