# Text lines multiset union

`text-lines-multiset-union` · version 1.0.0 · Text · free, no key needed

Multiset sum of two line bags: counts add, first-seen order from a then new from b.

**Use when you need to: text lines multiset union · bag union lines · sum line counts.**

## Supported

- text lines multiset union
- bag union lines
- sum line counts

## Not supported

- max-count union
- set union
- trim

## Behavior

- Split on CR LF, LF, or CR. Do not treat other Unicode separators as line breaks.
- A trailing terminator does not create an extra empty line.
- Empty document -> zero lines, trailing_terminator false.
- A document that is only a terminator -> one empty line, trailing_terminator true.
- A document with no terminator -> last line kept, trailing_terminator false.
- Preserve empty lines in the middle.
- Output reconstruction uses LF. If the result has at least one line, append a trailing LF iff the selected window includes the original trailing terminator or includes a line that was followed by a separator in the source.
- No trimming, case folding, Unicode normalization, or locale rules.
- count(x) = count_a(x) + count_b(x).
- Emit x repeated count(x) times.
- Order: all first-seen keys from a (with summed counts), then keys only in b in first-seen order from b.
- Trailing terminator follows a when result non-empty and a had a trailing terminator; if a is empty, follow b.

## Input

- `a` (string, required): max length 256000
- `b` (string, required): max length 256000

## Output

- `text` (string, required)
- `lines_in_a` (integer, required)
- `lines_in_b` (integer, required)
- `lines_out` (integer, required)

## Limits

- max input bytes: 256000
- max lines: 10000
- max output lines: 10000

## Example

Request input:

```json
{
  "a": "a\na\nb\n",
  "b": "a\nc\n"
}
```

Response:

```json
{
  "result": {
    "text": "a\na\na\nb\nc\n",
    "lines_in_a": 3,
    "lines_in_b": 2,
    "lines_out": 5
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "text-lines-multiset-union",
  "version": "1.0.0",
  "input": {
    "a": "a\na\nb\n",
    "b": "a\nc\n"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/text-lines-multiset-union/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"a":"a\na\nb\n","b":"a\nc\n"}'
```

The machine-readable contract is at [/v1/tools/text-lines-multiset-union/versions/1.0.0](/v1/tools/text-lines-multiset-union/versions/1.0.0).

### CLI

```sh
node cli.mjs run text-lines-multiset-union 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [Text lines multiset subtract](/tools/text-lines-multiset-subtract): Multiset subtract b from a: remaining counts, first-seen order from a.
- [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 lines difference](/tools/text-lines-difference): Set difference a minus b using exact line equality.
- [Text count](/tools/text-count): Count Unicode code points, UTF-16 code units, UTF-8 bytes, and lines.
- [Text diff stats](/tools/text-diff-stats): Summarize a line-record diff as keep, insert, delete, and hunk counts.
