# highlight_source_prefixes

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/tui/widgets/diff/highlight_source_prefixes)

Keep the bounded source prefixes needed to highlight a diff.

Idempotent, and rehydration depends on it: `DiffMessage.__init__` calls this
on whatever it is handed, which is the full file from the live path but an
already-trimmed prefix from `MessageData`. Re-trimming a prefix must return it
unchanged, so any future trimming rule has to stay keyed on the diff's line
numbers rather than on a count relative to the input, and has to survive the
split/join round trip — see the trailing-newline case in
`_highlight_source_prefix`. `test_trimming_a_prefix_again_returns_it_unchanged`
pins this.

## Signature

```python
highlight_source_prefixes(
    diff: str,
    before: str,
    after: str,
) -> tuple[str, str]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `diff` | `str` | Yes | Unified diff string. |
| `before` | `str` | Yes | Content before the change — the whole file, or a prefix this function previously returned. |
| `after` | `str` | Yes | Content after the change, same contract. |

## Returns

`tuple[str, str]`

Before and after prefixes, with oversized sides omitted.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/caaa7e7c12d214afa5cf0a1afed8eb6232aa6f7b/libs/code/deepagents_code/tui/widgets/diff.py#L752)