Skip to content

Docs built on facts

pyeye's docs state many facts that the code owns: tool names and parameters, edges, environment variables, entry points, the coverage threshold, the supported Pythons. Copied by hand, those facts drift. So the docs don't copy them. They name a fact, and scripts/docs_facts.py fills it in from the code (#818, #824).

There are two layers:

  • Facts come from the code and are never edited by hand.
  • Prose (explanation, ordering, examples) is written by hand and links to facts.

Using a fact in a page

Wrap the place a fact appears in a named marker block. The block's content is generated, so you can leave it empty and run generate.

Inline, inside a sentence (begin and end on one line):

Coverage must stay above <!-- fact:begin ci.coverage_threshold -->85%<!-- fact:end -->.

As a block, for tables and lists (the markers on their own lines):

<!-- fact:begin edges.table -->
<!-- fact:end -->

HTML comments don't render, so on GitHub the page reads normally. Markers inside code fences or inline code are plain text, which is how this page shows them.

Every fact ID and its current value is listed in docs/facts/facts.json. Group IDs, which render a table or list over several facts (for example edges.table, env.all or tool.<name>.params), aren't in the snapshot because they have no value of their own.

For a large table, link to the generated reference page instead of inlining it: docs/reference/.

Commands

uv run python scripts/docs_facts.py generate   # rewrite blocks, reference pages, snapshot and ledgers
uv run python scripts/docs_facts.py check      # fail if anything differs from the code
uv run python scripts/docs_facts.py changed --base origin/main   # facts this branch changed

Pre-commit runs generate. If it changes a file, the commit fails like a formatter would: stage the result and commit again. CI runs check in the pre-commit job.

check fails when:

  • a block's content differs from its fact (the value changed, or someone edited inside the block, which is the same failure);
  • a block names an unknown fact ID (the fact was removed or renamed);
  • a marker is malformed (an unclosed block, a nested one, or an inline block that spans lines);
  • a reference page, the snapshot, removed.json or uncovered.json is stale;
  • a file in the doc registry doesn't exist;
  • a live page names a removed name (see below), or a registry entry's covers names an unknown fact.

The doc registry

docs/facts/docs.toml lists every documentation file, with its audience (human, claude or both) and its kind. It is data, named by the docs key of pyeye's docs-facts config, the same way any repository can keep its registry in a file:

Kind Meaning
prose hand-written explanation
reference a page generated by generate (docs/reference/)
skill a skill, or a reference file a skill loads
history a record that has to name removed things (changelog, migration guide)
record a measurement record: its front matter gives the date, command and commit, and a line that links it may state the number it measured (D12)

Every docs check reads this list and nothing else. tests/test_docs_facts_registry.py fails if a Markdown file isn't registered, so a new .md file needs an entry in the same PR. The only trees outside the registry are the historical records (docs/superpowers/, docs/decisions/, docs/audits/) and test fixtures (tests/fixtures/).

Executed examples

A tool example in docs/api/, docs/reference/, a skill, or any prose page for humans (audience human or both, outside .claude/) can be executed instead of trusted (#828). Tag the fenced block, and give the call's arguments as a JSON object. Leave out project_path; the runner supplies it:

```json pyeye-example tool=inspect
{"handle": "myapp.config.Settings"}
```

```json pyeye-output
{"found": true, "kind": "class", "edge_counts": {"members": 3, "superclasses": 1},
 "…": "<omitted>"}
```

An example whose result depends on earlier calls (state that accumulates over a session, #953) gives a JSON array of argument objects instead: the runner calls the tool with each in order, on the same project, and a shown output matches the last call's response.

The json pyeye-output block is optional. It must come straight after its example, with only blank lines between them. fixture=<name> runs the example against tests/fixtures/<name>/ instead of the default, tests/fixtures/docs_examples/ (a small myapp package).

tests/test_docs_examples.py calls each example through the MCP server. It checks a primitive's response with the conformance linter, and matches a shown output on structure, not values (design C10):

In a shown output Means Fails when
a key the response has it, with the same JSON kind it's missing or a different kind
"…": "<omitted>" this level leaves keys out it's missing while keys are left out, or present when none are
"<omitted>" as the last array item items are left out it's missing while items are left out, or present when none are
"k": "<absent>" the response does not have k the response has k
found, kind, reason, ambiguous compared by value the value differs

A reader must never take a trimmed example for the whole response, so every trim is marked. check also fails on a malformed tag (anything mentioning pyeye- that doesn't fit), an output block with no example straight before it, a body that isn't JSON, and an example anywhere else: a history page (it records the past, which may no longer run), Claude-only prose, or a page under .claude/ other than a skill. Untagged blocks are prose.

Removed names

A fact that disappears from the code can't fail a block once nothing binds it, but prose can still name it. So generate records every removal in docs/facts/removed.json: when a tool, parameter, env var, entry point or edge leaves the snapshot, it's appended with "removed_in": "unreleased", and scripts/changelog.py prepare writes the release over it. Entries are never deleted. The file also holds the names removed before the registry existed (the v1 tools).

Each entry's match says how prose is scanned for it, and it's the only field to edit by hand:

match Fails on Default for
word any mention tools, env vars, entry points
heading only an API heading (## name), for a name that lives on as an internal method set by hand
code only a mention in inline code (`callers`) edges, whose names are common words
none nothing: recorded, not scanned parameters (runnable examples catch those, #828)

On a prose or skill page, a line that names a removed name passes only if it also says "removed", and each such mention must also be in the page's allow-list in the registry, allow={"removed-name": (...)}, by its exact message (for example names removed tool '<name>' beside 'removed'). The list only shrinks: a new mention fails until it's added on purpose in the diff, and an allowance whose mention is gone fails until it's deleted. Messages carry no line numbers, so editing elsewhere on the page doesn't disturb them, and one allowance covers exactly one mention. From the next major release after an entry's removed_in (the newest release in CHANGELOG.md), even a marked line fails: only history pages may name it then. history and reference pages aren't scanned.

Uncovered facts

A fact is covered when a prose or skill page explains it: the page shows it in a marker block, or its registry entry lists it in covers (a group ID stands for its members). A link to docs/reference/ doesn't count, since those pages list every fact.

generate writes every uncovered fact to docs/facts/uncovered.json. The baseline section holds the facts that were uncovered when the ledger was created; it's triaged once (#831) and only shrinks. Facts uncovered after that are listed under new with first_seen, the release they first appeared in. The ledger never fails a check: a new entry shows up in the PR diff, for the reviewer and for /docs-review. An entry leaves when its fact is covered or no longer exists. check prints how many new entries the ledger holds, as information only.

generate derives the ledger and removed.json from their copies at the merge base of HEAD and origin/main (--base names another branch), not from the working tree (#1112). So an earlier local run doesn't leave a trace. Without that run, a fact covered or deleted for a moment on your branch would fall out of baseline for good, or get a permanent removed.json entry. From the working tree it keeps only what a person or a release wrote: an entry's hand-edited match or note, a hand-written entry, and a first_seen that scripts/changelog.py prepare stamped. Without git or a merge base it uses the working tree and prints a note saying so. check needs no git: the files generate writes are already up to date with themselves, so it compares them as they are.

Some fact families are reference data rather than claims a page should explain, such as the list of pre-commit hooks. A setup declares those families reference-only: their facts never enter the ledger, and generate and check print a note naming them (#1108). The facts still bind into pages and still show in the snapshot and the changed-fact list.

A large family can also keep its own snapshot file, so facts.json diffs stay readable. Its facts move out of facts.json into that file. The removed-name record and the changed-fact list read every snapshot file together, so moving a family to its own file removes nothing.

Changed facts

changed --base <rev> diffs the snapshot against the one at <rev> and lists the facts added, changed and removed, with the pages that bind each one. CI writes it to the pre-commit job's summary on pull requests. It never fails: it's the scope of a change-triggered /docs-review.

A group ID (a view) that gained a member is listed too, under "Views with a new member", with the pages that bind it. A new member counts as covered as soon as it exists, so this is what sends those pages to review (#1108). A view that lost a member is listed under "Views that lost a member", and the gone member names the pages that bound its view. Each snapshot file records every view's members for this (#1114), so the comparison needs nothing but the two snapshots.

Adding a fact

Facts come from extractors in src/pyeye/docs_facts/extractors/, listed once in EXTRACTORS (src/pyeye/docs_facts/registry.py). Each extractor owns ID prefixes, so no two can produce the same fact. To add a family, write an extractor that reads the code, add it to EXTRACTORS and add tests that compare its output with the code read another way (see tests/test_docs_facts_extractors.py). An extractor that can no longer read its source fails loudly instead of yielding nothing.

Running it on another repository

The package ships the same commands as

python -m pyeye.docs_facts generate|check|changed (#1162). It runs on the working directory, or on --root <repo>. A skill runs it on a user's repository from the pyeye plugin's environment:

uv run --no-project python "${CLAUDE_PLUGIN_ROOT}/scripts/plugin_runtime.py" python -m pyeye.docs_facts check

python -m pyeye.docs_facts (or scripts/docs_facts.py --root <repo>) runs on any Python repository that declares what to check in [tool.pyeye.docs_facts] in its pyproject.toml, or under "docs_facts" in its .pyeye.json (which wins). Only the repository's own files are read for this config, never the user's global pyeye config. A repository with neither has nothing to check, and the command says so (#1091).

pyeye's own repository is configured the same way, in data (#1107):

  • docs = "docs/facts/docs.toml": the doc registry in a file (TOML, JSON or YAML) whose doc key lists the entries. An inline list of tables works too.
  • extractors: pyeye's extractors are built-in kinds. Most are pyeye-* kinds. They read pyeye's source by pyeye's conventions, so each runs only on the repository whose pyproject.toml declares [project] name = "pyeye-mcp"; anywhere else, extraction stops with an error that says so. Each kind's docstring says why no generic kind can express it yet. #1119 converts them into generic kinds any repository can use, such as entry-points (below), and counts how many remain:

10. - pages: the built-in reference pages under docs/reference/, also pyeye's only.

tests/fixtures/docs_facts_inline is a small repository configured inline, checked in CI.

The config is data only. docs-facts never imports or runs the analysed repository's code: facts come from kinds built into pyeye, which read files.

[tool.pyeye.docs_facts]
changelog = "CHANGELOG.md"        # optional: read for the current release

[[tool.pyeye.docs_facts.facts]]
id = "settings.concurrent_requests"
from = "literal"                  # a module-level constant, folded from the source
file = "app/settings.py"
name = "CONCURRENT_REQUESTS"

[[tool.pyeye.docs_facts.facts]]
id = "project.requires_python"
from = "toml"                     # or "json" / "yaml": a dotted key path
file = "pyproject.toml"
key = "project.requires-python"

[[tool.pyeye.docs_facts.docs]]
path = "docs/architecture.md"
audience = "human"                # human, claude or both
kind = "prose"                    # how the checks treat the page
  • facts reads a value from a file. literal folds a Python constant (literals, names bound in the same file, f-strings and set or string operators); it never follows the file's imports. toml, json and yaml read a dotted key path; YAML is read with yaml.safe_load only. A fact's ID is prefix.name.
  • extractors names other built-in kinds with their options: [[tool.pyeye.docs_facts.extractors]], with kind = "<name>" and the kind's options. Unknown options are refused.
  • entry-points (#1119) gives the repository's entry points. <prefix>.script.<name> is each console script in [project.scripts], with its target. <prefix>.module.<dotted> is each package under package that holds a __main__.py, so python -m <dotted> runs it. The view <prefix>.all tables both. Its options are package (a directory, optional), module (that package's import name, by default the directory's name) and prefix (by default cli). pyeye's own config gives it package = "src/pyeye".
  • docs is the doc registry, written as tables or as the path of a data file that holds them under doc. rules is "all" (the default) or a list of rule IDs. A rule whose facts the repository doesn't have, such as pyeye's own edge rules, is skipped and reported, never run.
  • paths moves the records (snapshot, removed, uncovered, review_state) from their default docs/facts/ files. Its snapshots table gives a fact family its own snapshot file: [tool.pyeye.docs_facts.paths.snapshots] with arch = "docs/facts/arch.json".
  • reference_only lists the fact families kept out of the uncovered-fact ledger, e.g. reference_only = ["arch"].

Anything that names code to import, such as a package.module:attr value, is refused, as are unknown keys, kinds and rules, and files outside the repository.

Architecture facts: the structure kind

structure is a generic built-in kind for architecture docs on any codebase (RFC #1083, #1092). It asks pyeye about every module in scope and yields facts under its prefix (default arch):

Fact What it holds
arch.members.<module or class> its functions, classes and methods, with signatures, one-line docstrings and the definitions pyeye couldn't read
arch.imports.<module> what it imports at runtime, only under TYPE_CHECKING, and unresolved; measured says whether pyeye answered
arch.imported_by.<module> the areas whose modules import it, when areas are configured, else the top-level packages (a set, not a count)
arch.cross.<area> scored and curated pairs touching the area that pyeye's facts label delegates, override or sibling, and the sides deprecated unconditionally
arch.pairs.<area> every curated pair touching the area, labelled or "possible duplicate (unverified)": what an area doc's "Similar elsewhere" footer binds
arch.coverage.gaps definitions on disk the facts don't account for, by category
arch.coverage.unreadable, arch.coverage.refused what pyeye listed as unreadable, and the compiled modules strict_source refused
[[tool.pyeye.docs_facts.extractors]]
kind = "structure"
include = ["src/*"]                # fnmatch patterns on file paths; * crosses /
exclude = ["*/tests/*"]
min_score = 0.9                    # the lowest score a scored candidate needs
candidates_page = "docs/facts/arch.candidates.md"
architecture_pages = ["docs/architecture/**"]  # the default: pages whose handles must resolve
areas = "docs/architecture/areas.toml"     # a committed data file, or an inline table
pairs = "docs/architecture/pairs.toml"     # a committed data file, or an inline list

[tool.pyeye.docs_facts]
reference_only = ["arch"]          # reference data: out of the uncovered-fact ledger

[tool.pyeye.docs_facts.paths.snapshots]
arch = "docs/facts/arch.json"      # its own snapshot file, so it doesn't swamp diffs

The areas and pairs files are data the planner writes and the user commits, so a change to them arrives as a reviewable diff. They are TOML, JSON or YAML, chosen by suffix, and are only read, never run. Each must be inside the repository:

# docs/architecture/areas.toml     # docs/architecture/pairs.toml
[areas]                            [[pair]]
console = ["mypkg.console*"]       a = "mypkg.console.init.InitCommand._get_pool"
storage = ["mypkg.store*"]         b = "mypkg.factory.Factory.create_pool"

                                   [[pair]]
                                   a = "mypkg.store.read"
                                   b = "mypkg.cache.read"
                                   rejected = "different jobs: one fills the cache"

Inline, areas is a table of area ID to module-name patterns, and pairs is a list whose entries are [a, b] or {a, b, rejected}.

  • Areas. Candidate pairs are formed across areas. With no areas, every module is its own area. With areas, a module no area matches is a coverage gap (unassigned), the signal to run the planner again; it still gets facts, as its own area. A module that matches two areas stops extraction with an error. within_areas = true also pairs callables inside one area.
  • Candidates are advice, not facts. A pair is scored from name, docstring and parameter overlap. A score is a judgement, so the pairs and their scores appear only on the candidates_page, which says so and states its threshold and filters. generate writes that page and check never compares it, so tuning the scoring fails nothing. It can't be a registered doc, so it is never bound or on the site. Only the labels pyeye's facts support are facts in arch.cross.<area>.
  • The scorer alone misses real duplicates. On the RFC #1083 trial's Poetry and Scrapy runs, all four confirmed Poetry duplicates scored below 0.6, and 46 of the pairs the trial's planner kept share no word in their names, so no threshold finds them. pairs gives the planner's pairs as data, and each is labelled from pyeye's facts like a scored candidate. Curated pairs are committed data, not a score, so each one is a fact in arch.pairs.<area>: a pair no rule labels is a possible duplicate (unverified). A pair naming a handle the dump lacks is a coverage gap (unknown_pairs).
  • A rejected pair stays rejected. A pair with rejected = "<reason>" is never labelled, never in arch.pairs, and never on the candidates page again, so a planner re-run doesn't bring it back. One naming a handle the dump lacks is also a gap, so a stale rejection gets cleaned up.
  • Deprecation is a flag. An unconditionally deprecated side is listed under deprecated. It never labels the pair, because a deprecated copy is still a copy.
  • Coverage gaps fail check. The structure-coverage rule reports each gap: definitions pyeye's dump misses, phantom ones, files that don't parse or map to no module, unresolved modules, files pyeye's project scan skipped, handles that can't be a fact ID, curated or rejected pairs naming a handle the dump lacks, and modules in no area. generate still writes everything. Unreadable definitions are reported in their own fact and are not gaps.
  • Importers by area. With areas, arch.imported_by.<module> is the set of areas that import it, so a page can say which parts of the system use a module. An importer outside the collected scope, such as an excluded test, is in no area and isn't listed. Raw counts are available from pyeye's expand(imported_by).
  • Layering checks. A page line CHECK no-import: <A> -> <B> (dotted module prefixes) fails check when a module under A imports something under B at runtime. TYPE_CHECKING imports don't count, an unresolved import of B does, and a check whose A names no module can't be verified, so it fails too.
  • Handles on architecture pages resolve (architecture-handles, #1176). On each registered page matching architecture_pages (by default docs/architecture/**), every handle in the prose must name something. A handle is a dotted name starting with a top-level name the dump knows, such as mypkg.factory.Factory or mypkg.factory.Factory.create_pool. Write it in a code span; plain prose is checked the same way. A name glued to /, ., - or a letter is part of something else (a path, a URL, my-pkg.x) and isn't checked, and fact-block content is never checked. Each handle is looked up in the dump's members facts first. One the dump doesn't list then goes through pyeye's resolve, so a re-exported path resolves to its definition. Only a handle neither finds fails check, with its file and line. A dotted name that only looks like a handle, such as a file named mypkg.lock, is allowed in that page's allow entry. Only architecture pages are checked, for now.
  • The three rules follow the configured prefix. They are skipped and reported where the facts are absent. One structure kind per repository: a second would bring the same rules twice, so the config refuses it.

The docs site

The same Markdown is published to GitHub Pages with MkDocs and the Material theme. Nothing on the site is written separately:

  • What's published comes from the doc registry (src/pyeye/docs_facts/site.py): pages for human readers, plus the generated reference pages. Skills and Claude's instructions stay off. A history page waits until its honest-claims seeds are gone. An entry's site=True or site=False overrides the rule (the PR template and changes/ are site=False).
  • The nav is built from the same list by scripts/mkdocs_hooks.py. mkdocs.yml lists no pages, so a page reaches the site only by being registered.
  • Paths are repo paths: README.md is the home page and docs/api/README.md is /docs/api/. A relative link works the same on GitHub and on the site. A link to a repo file the site doesn't publish points at that file on GitHub.

CI builds the site with mkdocs build --strict in the pre-commit job, so a broken link fails the PR, and deploys it on every push to main. To preview it locally:

uv sync --frozen --group docs
uv run --frozen --group docs mkdocs serve