# Refs and mentions

How a ticket points at docs, gotchas, code and decisions: explicit refs and mentions in the text.

## Refs and anchors

A ref can point to one section of a doc instead of the whole doc; the bundle then carries only that section.

```console
$ tkt ticket ref add PAY-001 doc://plan --anchor "## Refunds"
```

- Read one part yourself with `tkt doc get dontesek --anchor D214`: exactly what such a ref delivers. Never grep the store.
- Every `resolution` has `fullyDelivered` and `cutBy`; an own anchored ref the per-ref cap cut is `REF_TRUNCATED`: anchor a subsection or raise `bundleTokenBudget`.

### Details

**No heading matches:** `REF_ANCHOR_NOT_FOUND`, with suggestions (`data.suggestions`).

**Adding:** `location` and `kind` follow from the ref (`doc://`, `gotcha://`, `decision://`: server; `http(s)://`: external; a path: repo/code); `--kind` / `--location` override. A ref's identity is its string: a repeated `add` updates it in place. Quality problems (unknown target, bad `--line-range`) are warnings, exit 0; removing an absent ref is `ERR_NOT_FOUND`. `tkt group ref add` puts a new ref in `contextRefs`, with `--required` in `requiredReading`; `--required` / `--context` move it; `tkt group ref remove` with `--required` / `--all` drops it there too. Over REST a list is replaced only as a whole (PATCH).

**Section:** from the heading to the next one of the same or a higher level (a `#` in fenced code is none); case and whitespace do not matter; `## X (2)` is the second `## X`; without `#` any level; `resolution.section` is the anchor. A repo ref names its range (`originalRange`); its text only with `--inline`.

**Inline:** `tkt ticket ref add PAY-001 docs/audit.md --anchor "## SEC-010" --inline` stores `inline: true`; every `tkt ticket get` then carries that range's text from the worktree (Stage 2, `mode: excerpt`) within the per-ref cap and what the server's part left of the budget: cut at a whole line, `cutBy`, `cuts[]`. `--no-inline` turns it off; on a non-repo ref `ERR_CONTEXTREF_LOCATION_MISMATCH`.

**Line range:** a repo ref stores `lineRange` as `L<a>-L<b>` (one line: `L<a>`); Stage 2 reads only this form and checks that it lies inside the file (else `not_found`, `REPO_REF_NOT_FOUND`). A repo ref is a path inside the worktree: an absolute path, a path with a `..` part and a symlink that leads outside the worktree are `not_found` (`resolution.error`: `path outside the worktree`, `REPO_REF_NOT_FOUND`); tkt opens no file outside the worktree. Stage 2 reads the file in chunks; it looks an `anchor` up only in a file of at most 4 MB, a larger one is named whole (`REF_ANCHOR_NOT_FOUND`). A plan's `write` step also takes `N-M` and stores it as `L<N>-L<M>`. A stored `N-M` (an older plan) loses its range and the whole file is named; `tkt doctor` warns `CONTEXTREF_LINERANGE_LEGACY` with the fix, e.g. `tkt ticket ref add PAY-001 src/app.py --line-range L120-L168` (updates in place, the other fields stay).

**Row:** in a table-only doc (a decision log) `--anchor "D63"` or `--anchor "D63, D133"` delivers those rows with the header (`resolution.rows`); the first cell, exact (case-insensitive, without `**`, `_`, backticks); with several keys each must match one row. Over the cap it ends at a whole row: `resolution.rowsDelivered`, `reason`: "N of M rows".

**A doc too large:** an own unanchored doc ref larger than one ref may carry (at least 3200 chars, or a quarter of the budget): `UNANCHORED_LARGE_DOC`, `data.candidates` (the body's mentions, the H2s or the row keys; at most 8): `tkt ticket ref remove PAY-001 doc://plan`, then add it again with `--anchor`. An epic's unanchored doc ref: `EPIC_REF_TOO_BROAD` (`data.inheritingChildren`).

**Short:** `--anchor "6.2"` (`"### 6.2"`, `"6.2 FONTOS"`) matches like a body `›`; an exact heading wins, `6.2` is not `6.2.1`. Several: `ERR_BODY_SECTION_AMBIGUOUS` (`extra.candidates`), nothing written.

**Topic:** every reference prints as `id (topic)` (`refines: D1 (Use Postgres)`): the target's title (a group's name), else the first words of its `description`, at most 60 characters. In JSON it is `topic`; the command that gets it is `fetch`.

**Delivery:** `fullyDelivered` is `true` (all arrived), `false` (anchor missed, cut, degraded, target missing) or `null` (repo, URL, a mention without a section); `cutBy`: `per_ref_cap` (a ref), `section_cap`, `budget` (a group part, the inherited `## Value`), `excluded` (the ticket left it out). `REF_TRUNCATED`: `data: {ref, anchor, chars, cap}`; `tkt lint` exits 2 on it. Total: `refsNotFullyDelivered` in the [report](/en/docs/guides/plan/reports.md#context-report).

**doc get, gotcha get:** `--anchor` takes a row key, `"D63, D133"` or a heading (`tkt gotcha get li-urn --anchor Fix`); a miss is `ERR_NOT_FOUND`, exit 1, `extra.suggestions`; `--json`: `{id, anchor, content, rows?, section?}`.

## Mentions in the body

`gotcha://x` and `doc://plan › Auth` in a ticket body are delivered like refs (`_source: "mention"`); the text after `›` picks the one heading that starts with or contains it. A doc mention without a section is a pointer: add a real ref when the whole doc matters.

- Rows: `doc://dontesek › D63, › D133`; all rows a body names of one doc are one entry.
- A mention that names nothing: `DANGLING_MENTION`. Always write the full id.

### Details

**Bare `D63`:** `tkt config set mentionPatterns "[{pattern: '\bD\d+\b', doc: dontesek}]"` (`via: "mentionPatterns"`, `viaRows`).

Tier: 1 when the AC or `## In Scope` names it, else 3; an anchored mention claims with tier 1. A critical gotcha mention is never a bare pointer. When the `›` text matches no heading: an info `REF_ANCHOR_NOT_FOUND`, and the doc is a pointer. The `›` text ends at `;` `,` `(` `)` `:`, a quote or a sentence end (in inline code at the closing backtick) unless `›` or `, ›` goes on; a `D9` after it is text again. Rows an own ref carries are left out. `mentionPatterns` match outside fenced code and outside `doc://` / `gotcha://` mentions (single quotes keep the backslashes); `set` checks it (a `{pattern, doc}` list, the regex compiles and never matches empty; else `ERR_SCHEMA_INVALID_ENUM`), a missing doc is a warning, a broken hand-written value is ignored on read. `DANGLING_MENTION`: lint, `tkt doctor` and every body write report it with a did-you-mean; info on a closed ticket and for a known id plus a word suffix (`doc://dontesek-ben`); globs (`gotcha://li-*`) are ignored; one per pattern: `data: {pattern, ref, tokens, suggestions}`. Nothing is linked for you.

## Commands on this page

- [`tkt ticket ref add`](/en/docs/reference/commands/ticket.md#tkt-ticket-ref-add): Add a ref, or update it in place if the ticket already has it (no duplicates)
- [`tkt ticket ref remove`](/en/docs/reference/commands/ticket.md#tkt-ticket-ref-remove): Remove a ref (every occurrence) from the ticket's contextRefs
- [`tkt ticket ref list`](/en/docs/reference/commands/ticket.md#tkt-ticket-ref-list): List the ticket's contextRefs, then the inherited refs it excludes
- [`tkt group ref add`](/en/docs/reference/commands/setup.md#tkt-group-ref-add): Add a ref, or update it in place if the group already has it (no duplicates)
- [`tkt group ref remove`](/en/docs/reference/commands/setup.md#tkt-group-ref-remove): Remove a ref (every occurrence) from contextRefs, requiredReading (--required) or both (--all)
- [`tkt group ref list`](/en/docs/reference/commands/setup.md#tkt-group-ref-list): List a group's refs (both lists unless filtered)

## Related

- Guide: [Reports](/en/docs/guides/plan/reports.md): The three tkt report commands on one page: value, release and context.
- Hint · warning: [`REF_ANCHOR_NOT_FOUND`](/en/docs/reference/hints.md#REF_ANCHOR_NOT_FOUND): A ref's anchor matches no heading or row; the bundle has the doc's start, data.suggestions the closest ones
- Hint · warning: [`REF_TRUNCATED`](/en/docs/reference/hints.md#REF_TRUNCATED): An anchored section the ticket names was cut by the per-ref cap (fullyDelivered: false)
- Hint · warning: [`UNANCHORED_LARGE_DOC`](/en/docs/reference/hints.md#UNANCHORED_LARGE_DOC): An own doc ref without an anchor is larger than one ref may carry; data.candidates lists anchors
- Hint · info: [`EPIC_REF_TOO_BROAD`](/en/docs/reference/hints.md#EPIC_REF_TOO_BROAD): An epic's unanchored doc ref is inherited by every open child
- Doctor · warning: [`CONTEXTREF_LINERANGE_LEGACY`](/en/docs/reference/doctor.md#doctor-CONTEXTREF_LINERANGE_LEGACY): A ticket's repo ref stores lineRange as N-M, not L\<a\>-L\<b\>: the hint is the tkt ticket ref add that fixes it
- Hint · warning: [`STALE_DOC`](/en/docs/reference/hints.md#STALE_DOC): A referenced doc passed its staleAfterDays, or changed since the item's review stamp of it (tkt review)
- Hint · warning: [`DANGLING_MENTION`](/en/docs/reference/hints.md#DANGLING_MENTION): A doc:// / gotcha:// mention in the body names nothing (info on a closed ticket)
- Config key: [`mentionPatterns`](/en/docs/reference/config.md#mentionPatterns): Patterns that turn a body word into a doc ref ({pattern, doc} items)
