# Docs governance

Agents run one command. It fails on what a program can judge, and names the pages a change may have outdated.

1. `pre-commit` Staged pages
2. `affected_tests` Changed files
3. `refresh-dev-instance.sh` Since last deploy, report only
4. `publish-github.sh` Every page
5. `docs_site.check`
6. **Errors** file, line, fix Warnings: content band Affected pages: ask, or acknowledge

## Entry point

| Command | Does |
| --- | --- |
| `python -m scripts.docs_site.check a.py docs/x.html` | Named paths. Blocks. |
| `… check` | Changes against HEAD. Blocks in a worktree. Only reports in the shared checkout on `dev`. |
| `… check --base REV` | A revision range. Blocks. |
| `… check --staged` | The index, for the hook. Blocks. |
| `… check --all` | Every page, plus site-wide rules. Blocks. |
| `--report-only` | Exit 0 unless the tool itself failed |
| `--json` | Findings and impact, for scripts |
| `--unfiltered` | Turns the diff filter off: every page citing a changed file |
| `--ack PAGE … --reason TEXT` | Record that a page was checked for this change |

Budget: 5 s changed, 15 s everything. Standard library and the CLI parser only: no node, no site build, no network. Exit 0: no error in scope, or `--report-only`. Exit 1: an error in scope. Exit 2: the tool itself failed, or a usage error such as a bad `--ack`.

## Format

| Rule | Fix |
| --- | --- |
| `format.style-element` `format.script-element` | Move to `site.css`, or delete |
| `format.event-handler` `format.javascript-url` `format.embed` | Delete it: a page runs and embeds no code |
| `format.style-attribute` `format.stylesheet-link` | Use a site class |
| `format.missing-title` `format.missing-description` `format.missing-h1` `format.multiple-h1` | Each page has exactly one of each |
| `format.missing-pair` `format.orphan-zh` | Add the other language |
| `format.structure-mismatch` | Same sequence of headings, tables, rows, list items, code, folds and figures in both languages |
| `format.unregistered` | Add to a section of `TAB_SECTIONS`; a design page's section title must be listed in `DESIGN_AREAS`. Editing `nav.py` rechecks every page. |
| `format.cjk-in-english` | Move the text to the `.zh.html` |
| `format.markdown-source` | Convert to HTML. Only generated reference pages stay Markdown. |
| `format.prototype-stale` | A listed prototype has no script: remove it from the list |
| `format.zh-stale` | Warning: the English text changed and the Chinese page did not |
| `links.broken` `links.fragment` | Fix the source link. Checked in the sources, so no build is needed. |

| Case | Behaviour |
| --- | --- |
| Failing page outside the list | `build.py` raises `DocsFormatError`, with file, line and fix. There is no iframe fallback. |
| `OPENPROGRAM_DOCS_FORMAT=quarantine` | Markup unsafe to show publishes as a visible error page, in that language only; other faults are logged and the page renders. Set only by deploys and self-update. |
| `PROTOTYPE_PAGES` | The list is in `governance/policy.py`. A new page there needs a reason in `LOOSENED_BECAUSE`. |

## Content

| Measure | Measured on 363 English pages | Error | Warning |
| --- | --- | --- | --- |
| Words in a paragraph | p50 19, p95 48, p99 64, max 78 | > 80 | > 60 |
| Prose words on a page | p50 188, p95 1139, p99 1957, max 10199 | > 2000 | > 1500 |
| Prose share, at 150 or more prose words | 27 pages above 0.60, 8 above 0.70 | > 0.70 | > 0.60 |
| Same sentence twice on a page | 0 | any | – |
| Same sentence across pages: 6 or more content words, Jaccard 0.8 | 7 pairs | any | – |
| Sentence covered by one table row, a table of up to 4 rows, or a figure: 6 or more content words; a row counts its column headers | 0 at 0.8, 17 at 0.7, of 7077 | ≥ 0.8 | ≥ 0.7 |
| Words in a table cell | p50 6, p95 27, p99 42, max 138 | > 140 | > 80 |
| Section of bullets only, notes aside | 115 sections, 21 with 6 or more, max 15 | ≥ 8 items | ≥ 6 items |
| One block sequence across a tab of 10 or more pages (`--all` only) | Highest: `reference` 8%, `capabilities` 3%, `design` 1% | > 25% | > 15% |

The repository holds 726 HTML sources, 363 pairs. Content rules read English; Chinese follows through structure. Prose means `p`, `li`, `dd`, `blockquote`, `figcaption` and any text sitting directly in a container, outside tables, figures, code and flow twins.

| Baseline | `governance/baseline.json` |
| --- | --- |
| What can enter | Content rules only, never format or claims |
| Entry | `rule`, `path`, `subject` hash and a `reason` of at least 20 characters; page-level rules also store `max`, the measured size |
| Grows | An entry absent from the fixed reference (`refs/publish/last`, else the merge base with `stable`) is an error on every run, and never hides a finding |
| Shrinks | An entry that no longer matches is an error: delete it |
| Editing the text | A sentence or paragraph rule: the hash changes, so the finding returns. A page-level rule: the page may not exceed `max`, which only comes down. |

## Claims

| Reference | Verified against | Measured |
| --- | --- | --- |
| Commands and flags | Lines starting `openprogram`, split with `shlex`, walked through `build_parser()` | 505 commands, 113 flags |
| Removed verbs and flags | A verb or flag the range removed, written as a whole code span. A flag other commands keep counts only on a page that names its command. A top-level verb counts where the page writes `openprogram` with it or lists it among two or more other top-level verbs, because such a word often names an application or a target too. | Only in a range that changes the parser |
| Repository paths | Tracked file or directory; git-ignored build output counts; patterns skipped | 1004 |
| Partial paths and bare file names | On product pages, a source suffix and a known top segment must resolve somewhere. On any page, one that resolved before this change and no longer does. | 1310 and 1080; 7 product and 229 record hits unresolved before the rule |
| Modules | Dotted `openprogram.*` that resolves to a file, or an attribute of one; domains excluded | 134 |
| Routes | `/api/*` and `/healthz` found in `interfaces/server`; a literal route wins, a parameter fits only if this change did not remove that literal, and only a reference ending `*` fits what is beneath | 235 |
| Environment variables | `OPENPROGRAM_*` present in tracked files | 74 distinct |
| Settings keys | Argument of `openprogram config`, or a key that vanished from `SETTINGS` in the range and a page still names | 139 exact; 74 lookalikes are not settings |

| Marker | Meaning |
| --- | --- |
| `<code data-claim="example">` | An illustrative path or command, or a name a design rejected. Not checked. |
| `data-claim="invalid"` | A command shown as deliberately wrong. A real command cannot be marked as an example. |
| `references/` | Git-ignored peer clones: path syntax only |

## Code to docs

| Part | Rule |
| --- | --- |
| Reference | File path, or directory 3 or more levels deep, from the claims above. Bare file names count only if unique. |
| Command, key, route | Mapped to their source: `cli/parser.py`, `state/settings.py`, `interfaces/server/routes/`. A code span equal to a key is a setting reference. |
| `<meta name="covers" content="openprogram/x/ scripts/y.py">` | Explicit, English page only, always counts. Required where a page has no reference. `content="none"` declares an index or study that describes no code. |
| Filter | With more than 3 pages on a file, a page counts only when a code word on it is an identifier on the changed lines, not a string, comment or call keyword. For `cli/parser.py` the parser diff decides: only pages with a command under a changed command path. For `state/settings.py`, the keys of the changed blocks count as changed. The output says how many pages were left out; `--unfiltered` turns the filter off. |
| Reported | The English text of the page did not change and no acknowledgement; a page edited without visible change is shown as edited, please confirm; all of them, ranked |

| Replay of 252 commits | Pages p50 | Pages p90 | Commits with none | Doc commits predicted, of 123 |
| --- | --- | --- | --- | --- |
| Any directory reference | 17 | 34 | 2 | 42 |
| Exact file, deep directory | 7 | 23 | 21 | 40 |
| Plus diff filter on every file | 5 | 17 | 37 | 38 |
| Plus diff filter above 3 pages (chosen) | 6 | 17 | 24 | 40 |

With the `covers` declarations in place: p50 6, p90 26, 12 commits with no page; 36 of the 41 commits that changed both code and docs were predicted.

| Acknowledgement | Rule |
| --- | --- |
| Key | Page, changed file, and the blobs the decision went from and to. A range counts only when acknowledged steps chain from its base to its tip. |
| Store | `<git-common-dir>/openprogram-docs/acknowledgements.jsonl`, shared by worktrees, appended |
| Editing the file again | A new blob, so the page is asked again |
| Limits | Each page is named and must be in this change's impact report; only files pointing at it are recorded; the shared checkout needs explicit paths. A script looping over `--json` can still do it blindly. |
| Lost store | Warnings return. Nothing breaks, so it need not be versioned. |

## Where it runs

| Point | Runs | Blocks | Why |
| --- | --- | --- | --- |
| Commit in the main checkout | `pre-commit`, `--staged`, when docs, the baseline or the policy are staged | Errors on staged pages | The author is known; with `git commit -- <paths>` the index excludes other sessions' files |
| Commit in a worktree | `commit_gate.py`, a PreToolUse hook in the tracked `.claude/settings.json`, blocks `git commit` and `git merge`. | Errors in the branch | `~/.git-hooks` cuts the `.git` path at its first space, so no Git hook runs here |
| Merge or fast-forward in the main checkout | `post-merge`: `--base ORIG_HEAD --report-only` | Nothing | Runs no pre-commit; a cherry-pick runs nothing at all, so it is caught by the next deploy report or at publish |
| `affected_tests --run` | Every change | Errors on named paths or a worktree's own changes | Agents already run it |
| `affected_tests --run`, shared checkout, no paths | Every change | Nothing: reports | The dirty tree holds other sessions' pages |
| `refresh-dev-instance.sh` | `--base <last deployed> --report-only`, then quarantine build | Nothing | Commits there come from all sessions |
| `publish-github.sh` | `--all`, before pushing | Every error | The whole product leaves the machine; rare and deliberate |

Affected pages and warnings only inform: whether a page needs rewriting takes judgement. Hooks are unversioned, so `scripts/git-hooks/install.sh` copies them on every deploy and publish, recording the commit beside them so an older checkout cannot downgrade them; the main checkout warns when one is stale. A hook without a venv, or exit 2, never blocks.

## Test selection

| Case | Behaviour |
| --- | --- |
| A change only under `apps/web` | Any non-empty change builds the graph and runs all 27 contract files, 579 tests in 21 s |
| A docs change | `Selection.docs_check` runs the entry point. `checklinks` fails when `docs/_site` is missing. |
| A code change | The entry point runs on every change for impact |
| A worktree with no `node_modules` | `--run` clones both `node_modules` from the main checkout with `cp -c`, like `stage-release-assets.sh`: 10 s, 160 MB. Never links. |
| A selected Python test that runs `node` | Marked by its source; the clone runs for it too. If it cannot, it is left out and counted, exit 2 |
| No source to clone, or no `node` | Exit 2, naming how many tests could not run and why |
| A Web run reporting `tests 0`, or nothing selected for a real change | Failure, never success |

## Implementation status

Everything above is implemented. The three pages in `baseline.json` still need an editorial split. Staged and range checks read `nav.py` and `parser.py` from the snapshot, but the provider verbs come from disk, so claims against a dirty copy of them only warn.
