Design decisions

24. Documentation gate in scripts/check.sh --fast (2026-11-21)

  • 24.1 Fast docs verification runs on every commit. site/check_docs.py runs inside scripts/check.sh --fast right after site/bundle.py. It checks every cp fence in site/content/*.md and docs/one-page-cheat-sheet.md with one batched cpl check, executes every site/examples/*.cp fixture and write-code course reference through cpl run, enforces the 250-line cheat-sheet budget, and validates every local HTML link and heading fragment in site/_build/. Reason: site/test_site.py compiles every snippet with g++, taking ~55 s, so it sat outside the fast gate and docs drifted (the cheat sheet exceeded 250 lines). Running cpl check + cpl run keeps the fast gate under a few seconds while catching broken examples immediately; site/test_site.py remains the full C++17 verification suite. Reversible: remove the site/check_docs.py step from scripts/check.sh or replace with a faster Rust subcommand if the docs corpus grows past a few seconds.
  • 24.2 Generated Error & Lint Index (site/errors.py) with 100% compiler-code coverage. site/build.py generates errors.html plus one flat error-<CODE>.html page per diagnostic, warning, runtime trap, and lint code (currently 61 codes: 52 from cpl-diag + 9 from cpl-lint), indexed in search.json and packed into dist/cp-lang.html. site/check_docs.py parses crates/cpl-diag/src/lib.rs and crates/cpl-lint/src/lib.rs directly, failing the fast gate if any Rust code is missing or any trigger/fix pair stops reproducing its code or compiling cleanly. Reason: flat filenames integrate automatically with site/bundle.py (*.html glob) and relative asset paths, adding ~40 KiB gzipped; diffing against the Rust sources prevents the error index from ever drifting behind new diagnostics or lints. Reversible: move site/errors.py entries into Rust docstrings or a cpl explain --dump subcommand once cpl explain exists, keeping the same error-<CODE>.html URLs.
  • 24.3 Cookbook generated directly from validated ports (site/cookbook.py). site/build.py renders cookbook.html by reading live .cp sources from proto/ports/ecnerwala/ across 6 competitive programming categories (22 recipes covering trees/graphs, segment/Fenwick trees, DP, math/combinatorics, binary search/greedy/interactive, strings/geometry). site/check_docs.py verifies every referenced port exists, passes cpl check, and matches its sample cases via cpl run. Reason: reading directly from proto/ports/ecnerwala/ guarantees zero code duplication and keeps cookbook recipes automatically tested under the corpus gate and fast docs gate. Reversible: delete site/cookbook.py and its hook in site/build.py / site/check_docs.py, or expand into per-category pages if the recipe count outgrows one page.
  • 24.4 Stdlib module coverage enforced in site/check_docs.py. site/check_docs.py scans stdlib/*.cp (excluding prelude) and requires every module to be documented as std.<module> in site/content/stdlib.md (currently 24/24 modules). Reason: previously 12 of 24 non-prelude stdlib modules were absent from stdlib.md; checking against stdlib/*.cp prevents new modules from landing undocumented. Reversible: remove check_stdlib_module_coverage() from site/check_docs.py or replace with generated cpl doc stdlib HTML once docstrings cover every stdlib item.
  • 24.5 Writable-from-docs audit harness (scripts/writable-from-docs.py). Added scripts/writable-from-docs.py (with offline unit tests in scripts/test_writable_from_docs.py) to evaluate the AGENTS.md "Writable from the docs" rule: sends a fresh model ONLY the 8-file docs bundle plus an unseen statement from corpus/statements/ (filtering out already-ported IDs), then checks cpl check, cpl build, and cpl run on every sample case. Initial 10-problem audit (abc380b–abc387c, recorded in research/writable-from-docs.md) improved compile pass from 7/10 to 8/10 after fixing 5 docs gaps ("{n}" vs .to_str(), let k: Int = read() vs read(Int), free abs(x), 1-based array bounds, single-for comprehensions, Deque.push). Reason: turns the writable-from-docs principle into a repeatable, quantitative measurement that surfaces concrete docs gaps on unseen contest problems. Reversible: delete scripts/writable-from-docs.py, scripts/test_writable_from_docs.py, and research/writable-from-docs.md.
  • 24.6 Ports gallery page generated from research/PORTS.md and dream/*.cp (site/ports_gallery.py). site/build.py renders ports.html directly from research/PORTS.md plus live .cp, proto/ports/<group>/dream/<name>.cp, and accepted C++ originals, showing up to 16 featured side-by-side cards (prioritizing all dream-bearing ports, with client-side All / With dream / search filtering) plus a 60-row index table. site/check_docs.py verifies research/PORTS.md parsing, file existence, and rendered CP / dream / C++ panes. Reason: lets cold readers compare real validated CP Lang solutions, their unconstrained dream form, and accepted C++ side by side while keeping dist/cp-lang.html under the 2.6 MB cap (1,988 KiB). Reversible: delete site/ports_gallery.py and its hooks in site/build.py, site/check_docs.py, and site/assets/style.css.
  • 24.7 Playground shareable links, sample runner, and verbatim CLI error parity. Added URL-hash shareable links (#share=<base64url> encoding {source, stdin, samples} with no server dependency, working online and offline), a multi-case sample runner pre-populated with verified sample cases for all 23 playground presets, and verbatim CLI result.stderr rendering in [data-cli-stderr] alongside clickable jump-to-line diagnostics. Fixed Playground::check in crates/cpl-wasm/src/lib.rs to return exitCode = 0 on warning-only diagnostics (matching cpl check on the CLI). Added Rust parity test error_and_trap_stderr_matches_cli_verbatim in crates/cpl-wasm/tests/parity.rs and end-to-end Node/WASM + share-link + preset-sample parity tests in site/test_playground_parity.py, wired into site/check_docs.py. Reason: keeps browser playground errors byte-for-byte identical to the CLI and lets readers share and sample-test solutions directly in the browser without any backend. Reversible: revert the UI controls in site/compiler.py / site/assets/playground.js and remove site/test_playground_parity.py.
  • 24.8 Diagnostics registry (crates/cpl-diag/src/registry.rs) + cpl explain as single source of truth for error-index pages. Moved every diagnostic code's title, summary, explanation, trigger, and fix into crates/cpl-diag/src/registry.rs (REGISTRY: &[CodeInfo]) and crates/cpl-lint/src/lib.rs (LINTS), added cpl explain <CODE> and cpl explain --json in crates/cpl-cli, and refactored site/errors.py to generate all 69 error/lint pages directly from cpl explain --json. Reason: eliminates the 700-line Python catalog duplication so site error pages and CLI cpl explain always share one verified registry (and immediately picked up the 6 new taste lints L0501–L0506). Reversible: restore the static ERROR_CATALOG list in site/errors.py and remove crates/cpl-diag/src/registry.rs and explain_code in crates/cpl-cli/src/lib.rs.
  • 24.9 55-problem mixed-difficulty writable-from-docs benchmark, ratchet, and weekly workflow. Pinned 55 unseen mixed-difficulty statements (research/writable-from-docs-set.json: 35 CF Div2 B–E, 12 ABC D–E, 8 ARC A–B, verified unported), upgraded scripts/writable-from-docs.py to default to gpt-5.4 with parallel workers and ratchet JSON (research/writable-from-docs.json), wired offline ratchet enforcement into scripts/scoreboard.py --fast --check, and added weekly CI workflow .github/workflows/writable-from-docs.yml. Set the ratchet noise margin to 5% (max(prev, observed - 0.05)) because gpt-5.4 does not accept temperature=0 (~±2 problems variance on n = 55). Reason: turns writable-from-docs from a one-off small-set audit into an ongoing regression gate over realistic contest difficulty. Reversible: delete .github/workflows/writable-from-docs.yml, research/writable-from-docs.json, research/writable-from-docs-set.json, and the writable_from_docs block in scripts/scoreboard.py. Update: the workflow is workflow_dispatch only, like every workflow until Ryan turns automatic runs on (Actions minutes); restore schedule: cron "0 6 * * 1" to run it weekly.
  • 24.10 Gold-standard From C++ guide and Idioms page (site/content/cpp-guide.md, site/content/idioms.md). Upgraded site/content/cpp-guide.md with an editorial-first side-by-side C++17 vs CP Lang comparison (cf2069c), named-invariant structs, and zero-sentinel optionals, and added site/content/idioms.md covering domains, reductions, optionals, grids, sorting/heaps/maps, binary search, and stdlib structures — every cp fence verified by site/check_docs.py. Reason: gives C++ contestants and cold readers exemplar-grade patterns matching design/EXEMPLARS-PORTS.md while keeping every example mechanically checked against the compiler. Reversible: remove the idioms entry in site/build.py, delete site/content/idioms.md, and revert site/content/cpp-guide.md.
  • 24.11 Deterministic 55-problem writable-from-docs v2 set + float tolerance (1e-6). Audited the v1 55-problem manifest and replaced 15 un-evaluable problems (2 interactive, 5 CF redirect duplicates, 8 multi-answer constructive problems where valid answers failed exact string match) with 15 clean unique deterministic-output unseen problems, and added token-wise 1e-6 relative/absolute float tolerance to scripts/writable-from-docs.py::outputs_match. Reason: pass rate must reflect real correctness, not judge-harness false negatives on valid constructive outputs, redirected duplicates, or 3e-16 float rounding. Reversible: revert research/writable-from-docs-set.json and outputs_match in scripts/writable-from-docs.py.
  • 24.12 Generated Reading exemplars gallery (site/exemplars.py) and Try it buttons on every docs cp fence. Added site/exemplars.py generating exemplars.html directly from proto/ports/**/dream/*.cp paired with validated ports plus design/sketches/ioi2025/*.cp, and wired Try it links (playground.html#share=<base64url>) into site/build.py::code_block_html for every rendered cp code block, both gated in site/check_docs.py. Reason: lets cold readers compare dream vs port without hand-maintained drift and run, trace, or share any docs snippet in one click (online or in the offline dist/cp-lang.html bundle). Reversible: remove exemplars from site/build.py, delete site/exemplars.py, and remove try_it from code_block_html.
  • 24.13 Generated Stdlib API reference (site/stdlib_api.py) + zero-undocumented-pub fn gate. Wired site/stdlib_api.py onto the existing cpl doc --format json stdlib output (avoiding duplicating the dev-tools doc extractor) to generate stdlib-api.html, documented all 55 remaining undocumented pub fn / pub @get fn declarations across stdlib/*.cp with O(...) costs, and added check_stdlib_api_docs() in site/check_docs.py failing on any undocumented public function. Reason: keeps the stdlib API reference generated from one source of truth (/// comments) and prevents undocumented public stdlib functions from landing. Reversible: remove stdlib-api from site/build.py, delete site/stdlib_api.py, and remove check_stdlib_api_docs() from site/check_docs.py.