# Writing

This guide governs documentation, user-facing text, comments, and commit
messages. [CONTRIBUTING.md](CONTRIBUTING.md) owns the development workflow.

## Voice

Lead with the result or the reader's task. Use active voice, present tense,
concrete nouns, and short sentences. Assume no shared conversation history:
explain what a referenced issue or decision means, not just its identifier.

Describe observable behavior. Name the handled failure instead of calling
code robust. Give measurements instead of calling it fast. Remove filler,
marketing claims, emojis, and tool signatures. Planned capabilities remain
explicitly planned until implementation and checks establish them.

## README and guides

Teach the task before the API. The README opens with purpose and
installation, then task sections as `## README shape` describes, then
support, packages and contributor links. Omit an installation or usage
example when no usable package exists.

Keep API contracts next to their definitions and conceptual explanations in
one guide. Link to each instead of maintaining duplicate descriptions.
Use tables for comparisons and lists for steps or parallel facts. Preserve
relative repository links; change a packaged copy only when an installed
consumer check demonstrates that a target breaks.

## README shape

The README is for scanning. A reader should find the call to use at a glance.

- Header: the logo block, a centered title, then a row of badges for CI, the
  Hex release, libtmux.org docs and the license. Write the whole header in
  HTML. ExDoc's Earmark does not parse Markdown inside an HTML block, so
  Markdown there shows as literal text. Add no badge or link for a registry or
  libtmux.org page that does not return 200; a 302 is fine for a port root.
- Each `##` section is a task in the reader's words, such as finding
  sessions, windows and panes.
- Each `###` heading is an API name linked to its libtmux.org reference page,
  then a colon and its job in plain words.
- Under a heading: a line or two naming linked sibling APIs, the example,
  what it prints, at most one short note and a `More:` link to the guide.
- No paragraph runs past three lines. A list of facts is a bullet list.
- No feature inventory. The sections and examples show what exists.
- Requirements are floors a reader can act on, such as "tmux 3.3 or newer".
  Leave out patch versions of the toolchain, CI matrix narration and kernel
  trivia, and link the page that holds them.
- Cut what a reader assumes or never needs: that examples are tested, how
  the docs are built, what the checks cover, and "evidence",
  "qualification" or "contract" boilerplate.
- Never remove an example, command block, index table or guide table to
  shorten the README. Shorten the prose and move detail to a guide.
- Support and status and What it leaves out are short bullets that open with
  a bold lead.
- A repository with more than one package lists them under Packages: one
  heading per package linked to its directory, a one-line description, then
  links to its API reference, registry page and changelog.
- Examples start with their imports, so a reader can paste one into a file
  and run it.
- Examples start and clean up their own tmux server through the library, not
  the shell. Wrap the example body in `Server.with_owned/2`, which starts a
  private server and stops it when the body ends. Say so where a step has no
  library call.
- Every displayed example comes from a file CI runs.
  `scripts/check_example_docs/check_example_docs.exs` keeps each displayed copy
  equal to its source, and the packed example check runs the source.
- The README shows the features the port has: queries and filters, and
  control connections. Show a query planner, command chaining and
  optimization switches when they exist. Until then, list them under What it
  leaves out.

## Markdown and examples

Use CommonMark with blank lines around headings and lists. Wrap repository
prose at about 80 columns, except tables and long links. Do not hard-wrap
GitHub issue or pull request paragraphs. Exclude personal information and
local absolute paths from published text.

Code blocks are paste-and-run units:

- Use `console` fences and a `$ ` prefix for shell commands.
- Put one command in each block. An explicit `&&`, `;`, or `\` chain counts
  as one command.
- Put prerequisites and explanations outside the fence.
- Split long commands with `\`, using one flag per continuation line.
- Run complete Elixir examples and check their stated results. Keep API
  proposals in design prose or tables until executable examples exist.

Examples that touch tmux own their socket and cleanup. When examples become
part of public documentation, extract snippets from checked source files
or add a drift check. A compile-only example does not prove tmux behavior.

## Elixir API documentation

Write `@moduledoc`, `@doc`, and `@typedoc` beside their definitions. The
first paragraph states the result and stands on its own. Use native ExDoc
references such as `Module.function/arity`, `c:Module.callback/arity`, and
`t:Module.type/arity`; verify that rendered links resolve once ExDoc is
configured.

Document the contract a caller needs: accepted inputs, defaults, tagged
results and exceptions, ownership, ordering, deadlines, cancellation, output
bounds, and cleanup. State whether a value is observed data and whether a
function performs I/O. Explain required coverage and the tmux feature floor
where they affect the call.

Use `## Examples` for worked use and doctests for pure examples that can run
without tmux. Add truthful `:since` metadata when a feature ships. Typespecs
document contracts; do not present them as runtime validation.

Source comments explain an invariant, constraint, failure mode, or
non-obvious intent. Prefer one or two lines. Delete comments that narrate
the next expression or repeat names, types, and control flow. Preserve
tooling directives and explanations of protocol or platform workarounds.

## Commits and pull requests

Use `scope(type[detail]) Concise description`. The detail is optional. Use
a lowercase scope unless it names a proper product or class. Follow the
subject with a `why:` paragraph and focused `what:` bullets explaining the
durable reason and changes. Keep each commit about one topic.

Review descriptions lead with the concrete problem and resulting behavior.
Explain the final change for someone who has not read the conversation.
Include relevant verification, failures, and skipped checks in the review;
temporary validation results do not belong in commit prose.

## Release notes

Each changelog bullet names one observable change and
links the relevant API or issue. Put migration advice beside the change.
Release notes state the upgrade benefit, compatibility change, and required
action. Support claims refer to that release's completed checks. Avoid
feature totals and narratives of internal cleanup.

An entry goes in `CHANGELOG.md`, the changelog of `libtmux`. A change to
documentation, CI or release tooling goes there too.
