Keeping explainer pages current¶
The pages in docs/explainers/ state facts about the code: setting defaults, status codes, Redis key shapes, and file:line citations for every step they show. A gate fails CI as soon as a change makes one of those facts wrong, and tells you which part of the page to update.
The gate is scripts/docs/check_explainers.py. It uses the standard library only.
What it checks¶
| Check | Fails when | Source of truth |
|---|---|---|
| Manifest values | A value in the page's manifest block no longer equals the value in source, or the rule can no longer find it. | scripts/docs/explainer-rules/<page>.json, manifest |
| Cited code | The code at any cited range changed, moved, or no longer exists. | The page's citation-anchors block: first line, last line, line count and a hash of each cited range |
| Citations | The page cites a range with no anchor, keeps an anchor nothing cites, or names a file it cannot resolve. | The page itself, plus aliases in the rules file |
| Beat log | A chapter title or beat caption in the data block is missing from the static beat log, so the no-JS page says less than the animated one. | The page's data block |
| Registration | A page in docs/explainers/ has no rules file. |
scripts/docs/explainer-rules/ |
Citations are read from the page's markup, its data block, and its script, including the P.token + ':38-48' form the session-lifecycle script uses.
Where it runs¶
- Pull requests and pushes to
main: theDocs Checkworkflow (.github/workflows/docs-check.yml) runs on every pull request, not only docs changes, because a backend or frontend change is what makes a page stale. A failure annotates the changed source lines, and the job summary lists each problem with the diff inside the cited range, where on the page it is used, and the command that fixes it. - Docs deploy:
.github/workflows/docs.ymlruns the check beforemkdocs build, so a stale page is never published. - Before a commit: the
explainer-driftpre-commit hook runs when you changebackend/app/,react-frontend/src/,docs/explainers/orscripts/docs/.
Run it yourself:
When it fails¶
Read the report. Each problem says what changed, where the page uses it, and how to fix it.
Cited code moved. The code is unchanged but its line numbers shifted, for example after lines were added above it. Run:
This rewrites the line numbers everywhere the page prints them (text, tooltips, data block and script) and moves the anchors with them. Review the diff and commit it.
Sometimes the code moved and was also copied, so the same lines now appear more than once. The report lists every copy, and --fix leaves the citation alone because it cannot tell which copy the page means. Check the code, then name the copy by its first line:
--move refuses if the code at that line is not the anchored code.
Cited code changed. Someone edited code the page describes. This needs a person:
- Open the page and go to each place the report lists ("chapter 7 (origin-mismatch), beat 8", "Refresh: every check, in order", "page script, line 6530").
- Compare what the page says with the new code. Update the caption, inspector detail, stage label or reference text if it is now wrong. If the change moved the range's first or last line,
--fixcorrects the line numbers first. - Re-anchor the citation once the page is right:
--accept <file> accepts every changed citation in that file, but refuses one whose first or last line changed. Accept that one by its full citation after checking the line numbers.
Do not accept a change without reading the page. Accepting re-anchors the page on whatever the code says now, so an unreviewed accept turns a stale page green.
Manifest value no longer matches. Update the manifest value, and every place the page states it (stage labels, captions, beat log, sandbox, reference). If the rule stopped finding the value because the code was refactored, update the rule in scripts/docs/explainer-rules/<page>.json.
Citation with no anchor. You added a citation. Check that the page's claim is true at those lines, then run:
--stamp also drops anchors that nothing on the page cites any more.
Adding a page¶
- Write the page to
docs/explainers/<slug>.html(theexplainerskill does this; its repository configuration isdocs/agents/explainer.md). - Give it a manifest block (
<script type="application/json" id="<slug>-manifest">) holding only values that exist in source. - Add
scripts/docs/explainer-rules/<slug>.json: the manifest and data block ids, analiasesentry for every bare filename the page cites,scriptPathMapsif its script builds citations from a path map, and one rule per manifest key. Copysession-lifecycle.jsonfor the rule types (int,arith,bool,str,list,pairs,map,concat,present). - Run
python scripts/docs/check_explainers.py --stamponce every citation has been checked against the code. - Add the page to
docs/explainers/index.mdand to theExplainerssection ofmkdocs.yml.