# Morph Compaction

Compacts structured transcript entries to reduce context window pressure before long-context AI steps.

Use after transcript entries exist. AI transcription and raw user request handling produce entries; this node consumes those entries and returns a smaller transcript representation.

## Configuration

**Connection** - Morph connection **id**. Use `list_connections`; pass the returned ULID `id`, not the connection name.

**Query** - What the compacted transcript should preserve. Required.

**Compression ratio** - Target fraction to keep. Must be greater than `0.0` and at most `1.0`. Default: `0.3`.

**Preserve recent** - Number of recent transcript entries to keep verbatim. Default: `8`.

## Inputs & Outputs

**Input:** canonical `input`.

Accepted shapes:

```json
[
  {
    "id": "u1",
    "timestamp": "2026-06-05T12:00:00Z",
    "kind": { "type": "user", "content": "What changed?" }
  }
]
```

```json
{
  "transcript": [
    { "kind": { "type": "assistant", "content": "Here is the diff." } }
  ]
}
```

Transcript entries require `kind.type`. Known types: `user`, `human`, `assistant`, `reasoning`, `tool`, `tool_call`, `tool_result`, `system`, `compaction`, `compact`. Optional top-level `id` and `timestamp` are included in the rendered transcript passed to Morph.

**Output:** canonical `output`.

```json
{
  "output": "compacted transcript",
  "input_kind": "transcript",
  "compression_ratio": 0.3,
  "preserve_recent": 8,
  "compacted_line_ranges": []
}
```

Output fields:

- `output`: compacted transcript text.
- `input_kind`: currently `transcript`.
- `compression_ratio`: ratio used for compaction.
- `preserve_recent`: recent entries preserved verbatim.
- `compacted_line_ranges`: source line ranges compacted by Morph.

## Example

```
[Conversation transcript]
    ↓
[Morph Compaction: preserve decisions and blockers]
    ↓ output
[AI Agent: continue with compacted context]
```
