Valkyrian Labs

Source-Backed Reference Tables

Bind reference tables to facts extracted from the code, fill blanks and catch drift in CI with pmdocs facts.

Source-Backed Reference Tables

pmdocs facts keeps hand-written reference tables honest. The author writes the table where it belongs, a binding ties its rows to facts taken from the code, and the CLI fills blank cells and reports cells that contradict the source. Nothing reaches a page that the author did not put there: the values stay in the Markdown, so the page is complete on GitHub, in llms-full.txt and when it is rendered.

The model

A fact is a flat record: a stable id <source>:<rest> and an open set of fields with JSON values.

1{"id": "cli:remote create --retries", "kind": "option", "type": "n", "default": 3, "range": "1..20", "summary": "How often a request is retried."}

The id is the source's own name for the thing, independent of how a page labels the row, so renaming a column or a label never breaks a binding.

Absent is not the same as empty. A field the fact does not have means "the source does not know": the cell is the author's and anything written there is accepted. An explicit null, false, 0 or "" is a statement and is checked like any other value.

Facts are never stored. Every pmdocs facts command runs the sources against the current tree. A source that cannot run, exits non-zero, times out, prints nothing or prints a malformed line fails the command (exit 3) before anything is reported or written; nothing falls back to earlier data.

facts.toml

Sources are declared in docs/facts.toml:

1# Optional. Relative to this file. Default: the parent of the docs directory.2root = ".."3# Optional: a directive-spec.json with the site's own kinds or presets.4spec = "directive-spec.json"5 6[[source]]7name = "cli"                       # every id it prints starts with "cli:"8run = ["python3", "docs/_tools/cli-facts.py", "build/core/usage.json"]9timeout = 120                      # seconds, optional, default 12010 11[[source]]12name = "config"13scan = ["core/include/config/*.hpp", "core/src/**/*.cpp"]14literal = "default"                # optional: the field a marked line's literal fills

The file is strict: an unknown key, a source with both or neither of run and scan, a duplicate name or an empty array is a configuration error (exit 2) that names the key. --config <file> reads another file and --root <dir> overrides root.

Project extractors (run)

run is an argument vector, executed without a shell in root, with stdin from /dev/null. Its stderr is shown when it fails. It inherits the environment plus PMDOCS_FACTS_ROOT, PMDOCS_FACTS_SOURCE and PMDOCS_FACTS_DOCS.

It prints UTF-8 JSON Lines: one object per line, blank lines ignored.

  • id is a full fact id whose source part is the source's name.
  • Other keys are fields with scalar values (string, number, boolean, null); an array or object is malformed.
  • Keys starting with _ are metadata, never bound or compared. _source (a string such as path:line) is shown in diagnostics.
  • The same id twice is a failure.

The extractor is where project knowledge lives: it decides what is public, shortens descriptions and reads whatever registry the project has (a usage JSON, an OpenAPI file, a schema). Write it once as docs/_tools/<name>-facts.* and commit it.

The marker scanner (scan)

scan lists globs relative to root (*, ? and **; * does not match a leading dot). A pattern that matches no file fails the extraction, since it means the configuration is stale. The scanner is deliberately small. On each line:

  1. @fact followed by whitespace and an id that starts with <name>:;
  2. then key=value pairs up to the end of the line or a comment closer (*/, -->). A double-quoted value (with \" and \\ escapes) is a string; otherwise true, false, null and JSON numbers are typed and anything else is a string;
  3. when the code before the line's first comment opener (//, /*, #, --, <!--) ends with = or : and a plain literal (a decimal number, a quoted string, true or false, optionally followed by ; or ,), that literal is the field value unless value= is given. literal = "<field>" on the source makes it fill that field instead; an explicit <field>= on the marker still wins.
1uint32_t max_parts_in_flight = 4;            // @fact config:transfer.max_parts_in_flight2auto max_part_bytes = 64ull << 20;           // @fact config:transfer.max_part_bytes value=671088643rhs.port = node["port"].as<uint16_t>(8080);  // @fact config:websocket_server.port default=8080

Every @fact followed by whitespace on a scanned line is a marker, so a stray one (in prose, or an id of another source) fails the extraction with its path:line; anything that is not key=value after the id fails too.

A source whose marked lines are configuration defaults:

1[[source]]2name = "config"3scan = ["src/config.hpp"]4literal = "default"
1uint32_t worker_threads = 0;  // @fact config:sync.worker_threads

gives {"id": "config:sync.worker_threads", "default": 0, "_source": "src/config.hpp:12"}, which a column headed "Default" compares against. literal is a field name (not id, not starting with _) and only applies to scan sources.

Expressions are never evaluated: 64ull << 20, 4u or as<uint16_t>(8080) give no value. Write it on the marker, or use a project extractor. _source is path:line.

Bindings

Bindings are payload-markdown docs-table attributes, read with the renderer's own grammar:

1::docs-table[orbit remote create]{kind="options" from="cli:remote create"}2| Option | Type | Default | Range | Summary |3| --- | --- | --- | --- | --- |4| `--quota <size>` | `size` | — | | Storage quota. |5| `--retries` | `n` | `3` | `1..20` | |
  • Implicit: a row of a table with from binds to from + joiner + the row's key (its name with <…> positionals removed). The joiner is nothing when from ends with :, else the table's tree separator, else a space.
  • Explicit: a column headed fact, or fact="…" on an :::entry, holds the id, full or relative to from. A row the author adds on purpose is marked fact = -: it is never bound.
  • Columns map to fields through the kind's header aliases, else the header's slug (Max parts is the field max_parts).
  • Not bound: a fact cell or fact="…" attribute that is exactly - (a `-` code span counts too) marks a row the author adds on purpose. It has no explicit and no implicit id, is never unknown-fact, never duplicate-key, and complete does not count it.
  • keep="<row key>:<field>, …" marks cells whose authored value wins.
  • complete asks for an error when the table does not list a source row; omit="<key>, …" exempts deliberate gaps (and everything below them).

Values in prose: :fact

One value in a sentence, a heading, a list item or any table cell is bound with the inline :fact directive:

1The device listens on port :fact[36972]{id="config:device.port"}2and uploads in parts of :fact[`64 MiB`]{id="config:transfer.part_size" field="default"}.
  • The label is the value as written; it renders exactly as written, with no trace of the binding. It compares like a cell: code marks, emphasis and escapes do not matter.
  • id is a full fact id (<source>:<id>); field is optional and defaults to value. A missing or relative id, or a malformed field, is invalid-binding.
  • An empty label (:fact[]{…}) is a blank that fill writes.
  • Not a directive: \:fact[…], a :fact in a code span or fence, and a :fact directly after a letter, digit, _ or : (x:fact[…]).

A :fact in a table cell makes the cell compare as its label, so a bound table can hold one too.

Bindings are optional at every level: a table without from is not bound, a bound table may hold rows without a fact, and a bound row may have blank cells.

Commands

Command Does
pmdocs facts ls [<prefix>] Ids (sorted) with the start of their summary. --json: the facts.
pmdocs facts show <id> One fact, its _source, and where the docs bind it. Exit 1 for an unknown id.
pmdocs facts scaffold <id-or-prefix> Prints a ready ::docs-table and pipe table for the facts directly below an id, to paste and prune. The kind follows the facts' kind field (option gives options); --kind and --columns a,b override.
pmdocs facts fill [<path>…] Writes blank bound cells. --fix also rewrites drifted cells (never keep ones, never prose); --dry-run writes nothing.
pmdocs facts check [<path>…] The CI gate. --json for machines.
pmdocs facts unused [<prefix>] Facts bound nowhere (by a row or a :fact), minus those an omit covers. --exit-code exits 1 when the list is not empty.
pmdocs facts export The extracted facts as JSON Lines; --json for one array.

Every command takes --docs <dir> (default ./docs), --config <file> and --root <dir>.

fill edits only the cell's text; the rest of the line and the file (line endings, a missing final newline) are kept. Code and type fields are written in backticks with \| escapes, booleans as yes/no, prose fields (the summary) as plain text, and only when blank. An explicit null writes nothing. On an :::entry, only an attribute that exists with an empty value (type="") on a one-line marker is filled; anything else is reported as "fill by hand". For a :fact, only the label changes: a blank label is written, and --fix rewrites a drifted one, as plain text, or as a code span when the label was one.

What check reports

Findings print as path:line:col: code: message, errors first, then a summary.

Code Severity When
drift error A bound cell states a value and the fact a different one. The message gives both values and the fact's _source.
unknown-fact error A binding names an id no source has (an explicit fact, a :fact, or a row's implicit id).
unknown-source error A binding's source is not declared in facts.toml.
incomplete error A complete table does not list source rows (they are listed).
invalid-binding, duplicate-key error The renderer's binding diagnostics.
fillable note A blank bound cell or :fact whose fact has a value.
unchecked-fact note A :fact whose field the fact does not have: nothing is compared. The message lists the fields it has.

Never reported: blank cells, fields the fact lacks, prose fields, the name column, unbound tables and rows, and source rows a table without complete does not list.

Values compare by value, not text: code marks, emphasis, escapes and whitespace do not matter. A boolean fact accepts true/yes/on or false/no/off; a number compares numerically only when the fact's value is a JSON number (a string "1.10" is compared as text, so versions are safe); null matches a blank cell or the kind's empty marks (—, –, -).

When the docs are right and the source is wrong, fix the source registry; that is the preferred remedy. keep="row:field" is the fallback for a source that cannot be changed.

Exit codes

Code Meaning
0 Success.
1 Findings: check errors, unused --exit-code with results, show of an unknown id.
2 Usage or configuration error: no or bad facts.toml, unreadable docs.
3 Extraction failure. Nothing is reported or written.

In CI

Run the check after the build that produces the registry the extractors read:

1- name: Build2  run: make build3- name: Check source-backed tables4  run: pmdocs facts check5- name: Validate docs6  run: pmdocs validate --source main-docs

A later change in the code then fails CI with the file, line and cell to update.