# Docs and gotchas

The store's docs and gotchas (`doc://<id>`, `gotcha://<id>`) are edited in place, never with `sed`: every byte outside the edited part stays.

- Docs: `tkt doc append` (a row or an item: it joins the table or list), `tkt doc section set|append`, `tkt doc replace`.
- Gotchas: the body `tkt gotcha edit <id> --file new.md`, one section `tkt gotcha section set|append`; every command prints a severity change.
- Give every doc and gotcha a `--description`: a ref carries it even as a pointer.
- Who references it: `tkt doc refs <id>` (also `tkt gotcha refs`): every kind; `via` says how: own ref, `affects`, `mention` (`not bound` if nothing binds it), inherited `group:<id>`/`epic:<id>`, `appliesTo`, or `derived via SG-2` (a milestone or release, through a member); all: `tkt gotcha list --refs`.

## Details

**doc append:** scope `--section H` (see **Sections**) or the whole doc; no blank line before it, `--new-block` adds one. A text of only table rows (`| … |`) goes under the scope's last table even when a list follows; `--table N` picks another; a wrong cell count or table: `ERR_TABLE_INVALID`, nothing written. `--after "<text>"` inserts after the one line containing it. The frontmatter stays byte for byte except `timestamp`: when there is one, `tkt doc append|replace`, `tkt doc section set|append` and `tkt gotcha edit|section` set it to now, in UTC, whenever they change the body. **doc replace:** swaps an exact text that occurs once (`--old`, `--new` / `--new-file`; `--new ""` deletes); 0: `ERR_TEXT_NO_MATCH`, more: `ERR_TEXT_AMBIGUOUS`. `--text` and `--file` exclude each other; for Markdown with backticks use `--file -` with a heredoc.

**Sections:** `--section H`, `tkt doc section set|append` and `tkt gotcha section set|append` find the full heading at any level (H2 to H6), like the `--anchor` of `tkt doc get`; `### H` keeps one level, `## H (2)` is the second `## H`. A section ends at the next heading of its level or higher. A title at two levels: `ERR_BODY_SECTION_AMBIGUOUS`; a short form (`10.2`): `ERR_BODY_SECTION_MISSING`; both list the exact forms, nothing written. Only a heading found nowhere is created, at the end, at its `#`s' level (`##` by default).

**new / edit:** an existing id is `ERR_ID_DUPLICATE` unless `--force` (`tkt doc new --force` overwrites all; `tkt gotcha new --force` replaces the body and keeps the fields not given). `edit` writes only the fields given, `''` clears one; a severity change prints `severity critical → warn`. A doc's `--description` (300 chars) is its `summary` when the budget runs out; `tkt doctor` flags a bad path (`ERR_APPLIES_TO_INVALID`) and an unknown group.

**Groups:** the body `tkt group section set|append`, whole with `tkt group edit <id> --file body.md`; `tkt group get --raw` prints the whole file; `tkt group edit` merges the anchor field by field (`--no-repo-anchor` clears it), `--body` / `--file` replace the whole body; `tkt group delete` deletes a non-empty group only with `--force`. Never hand-write `_group.md`.

**get:** a plain `tkt doc get <id>`, `tkt gotcha get <id>` or `tkt group get <id>` prints the header and metadata lines, then the whole body verbatim: no markup is read (`[x]` stays), nothing is wrapped. For a group that is every section of the descriptor; `--raw` adds the frontmatter.

- Metadata of `tkt doc new|edit` and `tkt gotcha new|edit`: `--type` (docs: `concept`, `howto`, `reference`, `decision`, `plan`), `--title`, `--description`, `--tag`, `--timestamp`, `--applies-path`, `--applies-keyword`, `--applies-group`. `tkt gotcha edit --json`: `severityChange` `{from, to}` or null.
- The `Referenced by` block of `tkt doc get` and `tkt gotcha get` names five per kind, the rest as `+N more` with the refs command; `--json` `referencedBy` is the whole list, as the refs command's `--json` (with `shownAs`, `unbound`, `derived`).

## Commands on this page

- [`tkt doc new`](/en/docs/reference/commands/knowledge.md#tkt-doc-new): Create a managed doc (an existing one only with --force), with optional metadata
- [`tkt doc edit`](/en/docs/reference/commands/knowledge.md#tkt-doc-edit): Change a doc's metadata (type, title, description, tags, appliesTo); the body stays
- [`tkt doc delete`](/en/docs/reference/commands/knowledge.md#tkt-doc-delete): Delete a managed doc
- [`tkt doc append`](/en/docs/reference/commands/knowledge.md#tkt-doc-append): Append to the doc (or a section at any heading level)
- [`tkt doc replace`](/en/docs/reference/commands/knowledge.md#tkt-doc-replace): Replace one exact, unique text in the doc (e.g. its status line)
- [`tkt doc get`](/en/docs/reference/commands/knowledge.md#tkt-doc-get): Show a managed doc, or with --anchor the table rows / section a ref with that anchor delivers
- [`tkt doc list`](/en/docs/reference/commands/knowledge.md#tkt-doc-list): List all managed docs
- [`tkt doc refs`](/en/docs/reference/commands/knowledge.md#tkt-doc-refs): List the tickets and groups that reference a doc, and how (contextRef, requiredReading, mention, inherited from a group:\<id\> or epic:\<id\>, or its appliesTo matches them: appliesTo:group:\<id\>, appliesTo:keyword:\<k\>, appliesTo:path:\<glob\>), with the sections they name
- [`tkt doc section set`](/en/docs/reference/commands/knowledge.md#tkt-doc-section-set): Replace a section's content, up to the next heading of the same or a higher level (heading kept; created at the end only when the heading exists nowhere)
- [`tkt doc section append`](/en/docs/reference/commands/knowledge.md#tkt-doc-section-append): Append to a section at any heading level (= `doc append --section`; created at the end only when the heading exists nowhere)
- [`tkt gotcha new`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-new): Create a managed gotcha (an existing one only with --force), with optional metadata
- [`tkt gotcha edit`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-edit): Change a gotcha's body (--body / --file), severity or metadata; only the fields given change
- [`tkt gotcha delete`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-delete): Delete a managed gotcha
- [`tkt gotcha get`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-get): Show a managed gotcha, or with --anchor the section / table rows a ref with that anchor delivers
- [`tkt gotcha list`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-list): List all managed gotchas
- [`tkt gotcha refs`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-refs): List who references or inherits a gotcha: the groups that name it (requiredReading, contextRef), the tickets under them (group:\<id\>), an epic's children (epic:\<id\>), and the tickets that name it themselves (contextRef, mention) or that its appliesTo matches (appliesTo:group:\<id\>, appliesTo:keyword:\<k\>, appliesTo:path:\<glob\>)
- [`tkt gotcha section set`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-section-set): Replace a section's content, up to the next heading of the same or a higher level (heading kept; created at the end only when the heading exists nowhere)
- [`tkt gotcha section append`](/en/docs/reference/commands/knowledge.md#tkt-gotcha-section-append): Append after the section's last line, at any heading level (no blank line unless --new-block; created at the end only when the heading exists nowhere)
- [`tkt group section set`](/en/docs/reference/commands/setup.md#tkt-group-section-set): Replace a section's content (heading kept; empty content clears it)
- [`tkt group section append`](/en/docs/reference/commands/setup.md#tkt-group-section-append): Append content after the section's last line (no blank line unless --new-block)
- [`tkt group edit`](/en/docs/reference/commands/setup.md#tkt-group-edit): Edit a group (partial update)
- [`tkt group get`](/en/docs/reference/commands/setup.md#tkt-group-get): Show a group: its header, then the descriptor body (overview and every section) verbatim
- [`tkt group list`](/en/docs/reference/commands/setup.md#tkt-group-list): List all groups
- [`tkt group delete`](/en/docs/reference/commands/setup.md#tkt-group-delete): Delete a group

## Related

- Error code · 422: [`ERR_TABLE_INVALID`](/en/docs/reference/errors.md#ERR_TABLE_INVALID): doc append: no such table, or a row's cell count differs
- Error code · 422: [`ERR_TEXT_NO_MATCH`](/en/docs/reference/errors.md#ERR_TEXT_NO_MATCH): The --old text is not in the target
- Error code · 422: [`ERR_TEXT_AMBIGUOUS`](/en/docs/reference/errors.md#ERR_TEXT_AMBIGUOUS): The --old text occurs more than once
- Error code · 422: [`ERR_APPLIES_TO_INVALID`](/en/docs/reference/errors.md#ERR_APPLIES_TO_INVALID): A doc or gotcha appliesTo path is not a usable repo glob (doctor only)
