Skip to content
Playground(another site)

Working on the docs

This Book lives in site/ and is built with Astro and Starlight, deployed to Cloudflare Pages at bynk-lang.org. The pages themselves are Markdown under site/src/content/docs/book/; the authoring conventions below — grammar includes, diagnostic transcripts, callouts, diagrams — are expanded at build time by a small remark plugin, so writing a page is mostly writing prose.

It is organised by kind first, then by concern (see the book’s front page). Start and Learn Bynk are read in order; Concepts holds the explanation pages, grouped by concern; Guides holds the how-to pages, grouped by what the reader is building. The Reference is a surface of its own, kept whole for looking things up: the language, architecture, adapters, tooling, diagnostics, the specification and the releases, under site/src/content/docs/reference/. Diátaxis governs each page — one mode per page — and the part a page sits in says which mode it is. A new page goes in the part for its mode, and its folder follows: an explanation in Concepts, as book/concepts/<concern>/<page>.md (served at /book/concepts/…); a how-to in Guides, as book/guides/<concern>/<page>.md, listed under the group for the task. Each concern’s hub, book/guides/<concern>/index.md, gathers both and stays in Guides, under “By topic”. Within a part, SUMMARY.md decides where a page shows.

The site’s brand comes from @bynk-lang/site-theme, which is published to GitHub Packages, and GitHub Packages needs a token even to read. Create a classic personal access token with only the read:packages scope, and add it to your user-level ~/.npmrc (never the project’s):

//npm.pkg.github.com/:_authToken=YOUR_TOKEN

site/.npmrc already tells npm that @bynk-lang packages live there.

Everything runs from site/:

Terminal window
npm install # one-time
npm run dev # live preview at localhost:4321
npm run build # full production build (the gate CI runs)
npm run preview # serve the built site to spot-check it

npm run build is astro build. It expands the authoring directives, renders the diagrams, builds the Pagefind search index, and runs the starlight-links-validator plugin, so a broken in-site link fails the build. The link validator is wired in site/astro.config.mjs alongside the directive plugin, the diagram renderer, and the bynk syntax highlighter.

On bynk-lang.org, search covers the blog too: the deploy sets BYNK_MERGE_SEARCH, and the site’s search then also loads the blog’s Pagefind index from /blog/pagefind/ (the blog does the same with this site’s). A local build leaves it off, because Pagefind returns nothing at all when a merged index fails to load, so npm run preview searches this site alone. (CI builds with it on, to check the config, but never serves the result.) The two sites should run the same minor version of Pagefind, because Pagefind loads a merged index with the host site’s code. CI warns when the blog’s live index was built with a different one, and the deploy then leaves the merge off, so search covers the docs alone until whichever site is behind is bumped.

Highlighting for bynk fenced blocks comes from a TextMate grammar (site/src/grammars/bynk.tmLanguage.json), a copy of the VS Code extension’s (bynk-lang/vscode-bynk), so code on the page matches the editor. Refresh the copy from the extension when its grammar changes. The site theme ships the same grammar, and CI fails if the two copies differ. Since the theme lives in its own repository, a grammar change goes in this order: change the extension’s grammar, release the theme with it, then in one pull request here bump @bynk-lang/site-theme and refresh site/src/grammars/bynk.tmLanguage.json. A Dependabot bump that brings a new theme grammar fails the same check until the site’s copy is refreshed on that branch.

The colours, fonts, header, footer, wordmark and code themes are not in this repository. They come from @bynk-lang/site-theme, a Starlight plugin the blog uses too, so the two sites cannot drift apart. That includes the page shell: the header’s sections (Book, Examples, Reference, Blog), the footer strip at the end of every page, and the site map at the end of the home page. A change to any of them is made in the theme, released, and taken here by bumping the version in site/package.json. The footer’s licence line is set here, in astro.config.mjs.

What is particular to this site stays here, and wins over the theme’s:

  • the Sidebar override, scoped to the surface being viewed;
  • the home page: src/content/docs/index.mdx, whose frontmatter hero holds the hero’s words; src/components/home/, which draws the hero, the “Four ways in” cards, “What Bynk checks for you” and “From the blog”; and src/snippets/home/greeter.bynk, the hero’s program, which the snippets gate compiles;
  • src/styles/site.css, for the home page’s sections.

“From the blog” lists the newest three posts from the blog’s /blog/posts.json, read when the site builds. Offline, or if the blog is down, the section shows only its link to the blog and the build carries on. BYNK_BLOG_POSTS points the build at another URL or a local JSON file.

The links these components draw aren’t in Markdown, so the link validator doesn’t see them. After the build, CI runs scripts/check-shell-links.mjs, which checks every site link on the home page and a Book page against the built pages. A link that _redirects forwards to a built page passes, with a note to update it where it is written.

The pages’ prose is CC BY 4.0, and the code snippets in them (code blocks, and site/src/snippets/) are MIT, as the blog’s are. Bynk itself stays MIT or Apache-2.0. A contribution to the docs is taken on the same terms; the README’s “Licence” section has the details.

The sidebars are generated, not hand-maintained. Each tree has an authored table of contents: site/src/SUMMARY.md for the Book (book/, served at /book/), site/src/REFERENCE.md for the Reference (reference/, served at /reference/), and site/src/PROJECT.md for the Project pages (project/, served at /project/). site/scripts/generate-sidebar.mjs turns them into the committed site/src/generated/sidebar.json, reference-sidebar.json and project-sidebar.json that astro.config.mjs imports. After editing one, regenerate and commit:

Terminal window
node site/scripts/generate-sidebar.mjs # rewrite every sidebar
node site/scripts/generate-sidebar.mjs --check # CI: fail if one drifted or a page is unlisted

The --check mode runs in CI, so a contents edit that you forget to regenerate fails the build.

Every page must be listed in its tree’s contents. A sidebar comes from the contents, not from the folders, so a page nobody lists exists but no sidebar shows it. When you add a page under site/src/content/docs/book/, add its entry to SUMMARY.md; under site/src/content/docs/reference/, to REFERENCE.md; under site/src/content/docs/project/, to PROJECT.md; in the same change. --check fails naming any page that isn’t listed, and any entry that names no page.

Which tree a page goes in follows what the reader is doing. Learning, understanding and getting a task done are the Book; looking up exact behaviour — a construct’s rules, a tool’s flags, a code, the specification, a release — is the Reference. Pages for the people who build Bynk or follow where it is going (contributing, versioning and the roadmap) are the Project pages, linked from the footer. In the Reference a page’s folder decides its URL and REFERENCE.md decides its section, so a page can sit in Architecture while its file is under tooling/.

Diagrams. Write a fenced ```mermaid block. At build time rehype-mermaid renders it to inline SVG — offline, no client JS, no CDN. The diagrams wear the design system in light and dark: site/src/styles/mermaid.css styles them with the --bynk-* tokens, so leave out %%{init}%% theme blocks and colour classDefs, and let every diagram look alike. Accessibility rule — required: every diagram carries a caption and a text equivalent in the surrounding prose. No information may live only in a picture; a reader who cannot see the diagram must still get the full meaning from the text.

Callouts. Write a GitHub-style alert blockquote; the directive plugin turns it into a Starlight aside. Exactly four kinds, each with a fixed meaning — use them for what they say, not for decoration:

CalloutAsideMeans
> [!NOTE]notean aside or clarification
> [!TIP]tipa better or faster way
> [!WARNING]cautioneasy to get wrong; proceed carefully
> [!DANGER]dangerwill break, or is forbidden
> [!WARNING]
> Body text — ordinary Markdown, rendered normally.

A reference page can embed one grammar production by name. Put a line whose only content is the directive:

{{#grammar http_handler}}

The plugin replaces it with an EBNF code block holding that production, rendered from the committed site/src/generated/grammar.json (the same source the grammar appendix is built from) so it cannot drift from the parser. That JSON is itself a drift-guarded render of the grammar — xtask/tests/docs_consistency/generated_grammar_json.rs regenerates and checks it — so the rendered production is generated, never hand-edited. An unknown rule name throws at build time, so a typo cannot silently vanish.

Embedding a construct’s static semantics

Section titled “Embedding a construct’s static semantics”

A production says what parses; the diagnostics say what is legal beyond parsing. Embed the diagnostics that constrain a construct with:

{{#grammar-semantics http_handler}}

The plugin replaces it with a bullet list of the governing diagnostics, read from site/src/generated/grammar-semantics.json — the rule → diagnostics map. That file is generated from the grammar_symbol field on each diagnostic in the registry and drift-guarded by xtask/tests/docs_consistency/generated_site_json.rs, which also checks every grammar_symbol names a real grammar rule. A construct with no diagnostics yields a neutral line rather than failing, since an unconstrained production is legitimate; to add or change a mapping, edit grammar_symbol and re-bless.

The annotated reference (reference/grammar.md) must cover every production: xtask/tests/docs_consistency/grammar_coverage.rs asserts that each embeddable grammar rule has exactly one {{#grammar <rule>}} entry with a matching {#rule-<rule>} heading anchor (a custom heading id — see below), and that every directive argument names a real rule. So a new production cannot ship without a documented entry, and the diagnostic index’s Construct column deep-links to grammar#rule-<rule> and always resolves.

To show what the compiler actually says when it refuses a program — verbatim, not paraphrased — add a deliberately failing fixture and {{#include}} both it and its captured transcript:

  1. Write a standalone failing program at site/src/diagnostics/<id>.bynk (a commons or context block, like a doc example, but one that must error).
  2. Run BYNK_BLESS=1 cargo test -p bynk-tests --test it doc_diagnostics::. This compiles the fixture, asserts it fails, and writes the real diagnostic — colour-free, with a stable <id>.bynk label — to site/src/diagnostics/<id>.txt.
  3. On the page, show the source in a bynk,fail fence and the transcript in a text fence, each holding a single {{#include}} line pointing at the fixture and its transcript — e.g. {{#include ../../diagnostics/<id>.bynk}}. The plugin resolves the diagnostics/… suffix against site/src/ (the includeBase set in astro.config.mjs), so only the diagnostics/ part of the path matters. See the agent model for a live example to copy.

The .txt transcripts are generated — never hand-edit them; doc_diagnostics (run in CI) re-derives them from the compiler and fails if the committed copy drifts, and fails if a fixture ever starts compiling. The fixtures live outside the Book pages, so the doc-example gate skips a fenced block whose body is only an {{#include}} (it is display-only; the fixture’s own compile is what doc_diagnostics checks).

On explanation pages, pair the refusal with the bug it prevents — the most persuasive shape in the Book. Two panels:

  • The bug that ships. A short, idiomatic typescript block that genuinely compiles with the exact bug Bynk targets. Tag it typescript (the doc-example gate ignores it) and keep it honest — it must really compile.
  • The program that won’t build. The Bynk equivalent via the mechanism above: a bynk,fail fixture include, then the generated transcript.

Weave it into the prose where the page already asserts the bug, so the demonstration replaces the assertion rather than bolting on. Keep it to explanation pages; reference stays dry. See the type-system philosophy for the device in use.

Several mechanisms keep the docs honest. Some run inside the site build; the rest are Rust drift-guard tests and Node --check scripts that CI runs.

  1. Every example compiles. bynk-tests/tests/doc_examples.rs extracts every fenced ```bynk block from site/src/content/docs/book/** and compiles it — commons blocks in-process, context blocks as a temp project, and a block with neither header inside a synthetic commons (or context). Annotate blocks that should not be compiled as-is:

    • ```bynk,fragment — a partial snippet (a single member, a statement, or code naming types declared elsewhere on the page). It must still parse, inside the unit, agent, service, function or test body it comes from;
    • ```bynk,fail — a negative example that must fail to compile; ```bynk,fail=<code> also requires that diagnostic code, so a page explaining one error cannot drift onto another;
    • ```bynk,ignore — pseudo-syntax only (<Name> placeholders, … elisions), which is not Bynk at all.

    Bynk uses // for comments; a retired -- comment fails the gate (bynk.lex.legacy_comment).

  2. Generated reference is generated. Three reference pages are emitted from the compiler/grammar and guarded by tests, so they cannot drift:

    PageSourceTest
    reference/diagnostics.mdbynk-syntax/src/diagnostics.rs registrydiagnostics_registry.rs
    reference/keywords.mdthe lexer’s keyword tokenskeywords_reference.rs
    reference/grammar-appendix.mdtree-sitter-bynk/src/grammar.jsongrammar_reference.rs

    Each test renders the page and asserts it matches the committed file. They carry a “GENERATED FILE — do not edit by hand” banner. Regenerate after a relevant change:

    Terminal window
    BYNK_BLESS=1 cargo test -p xtask --test docs_consistency -- diagnostics_registry:: \
    keywords_reference:: \
    grammar_reference::

    The two generated JSON artifacts behind the directives — site/src/generated/grammar.json and grammar-semantics.json — are guarded the same way (xtask’s generated_grammar_json and generated_site_json); re-bless them with BYNK_BLESS=1 too.

    Each diagnostic code also has a page of its own, at /reference/diagnostics/<code>/, which /d/<code> redirects to and which every tool links (the editor, bynk explain, the MCP tools and the playground). What a code means and how to fix it is written once, in its Explain entry in bynk-syntax/src/diagnostics.rs, which bynk explain, the editor’s Explain panel and the code’s page all show; the Book has no separate page per error. The pages are rendered by site/src/pages/reference/diagnostics/[code].astro from site/src/generated/diagnostics.json, which diagnostics_registry.rs guards like the index page. A page lists the Book pages that explain its code from site/src/data/diagnostic-links.json; when you write a section that explains a code, add its link there. The same test checks that every entry names a registry code and a heading that exists. A new code also adds its /reference/diagnostics/<code>/ route to site/src/data/published-routes.txt (see Link checking, below).

  3. Link checking. starlight-links-validator validates internal links on every astro build. Separately, site/scripts/check-llms-links.mjs confirms each /book/ route named in the hand-authored llms.txt index still maps to a real page, and site/scripts/check-redirects.mjs checks site/public/_redirects (the Cloudflare Pages redirects that keep moved pages working) against the built site/dist/. It applies the rules first match wins, as Cloudflare does, and fails if a rule redirects a page that still exists, can never apply because an earlier rule catches its paths, or sends a reader to a page that does not exist. For a /* splat it maps every page under the target folder back to its old path, with and without the trailing slash; for /d/:code it tries a few registry codes.

    The same script remembers every page the site has published, in site/src/data/published-routes.txt, and fails if one of them is no longer a page and _redirects doesn’t send it to one. That catches a move that renames or drops a page, which the checks above can’t see because they only know the pages that exist now. The list only grows, and CI fails if a built page is missing from it, naming the routes. A PR that adds a page (a new diagnostic code is one) adds its route there: run node site/scripts/check-redirects.mjs --update after npm run build, or add the lines the failure names by hand. Remove a line only to retire a URL on purpose, with nowhere to send its readers. Run the check after npm run build whenever you move or retire a page.

  4. Drift checks. node site/scripts/generate-sidebar.mjs --check and node site/scripts/build-llms-full.mjs --check fail CI if the committed sidebar.json or llms-full.txt no longer matches its source (see Machine-readable Book, below). The sidebar check also fails when a Book page is missing from SUMMARY.md.

  5. Version banners. xtask/tests/docs_consistency/doc_version.rs checks the Book’s current-version banners; scripts/bump-version.sh rewrites them, so there is no manual bump step (see Docs ship with the feature).

Two files under site/public/ give tools a text view of the Book:

  • llms.txt is the hand-authored curated index — a short primer plus links into the Book. Because it is hand-authored it can drift, so check-llms-links.mjs link-checks its /book/ routes.
  • llms-full.txt is generated by site/scripts/build-llms-full.mjs: the whole Book concatenated in sidebar order with the authoring directives expanded against the same committed data the site uses, so it cannot drift from what renders. Regenerate with the script and commit; --check guards it in CI.
Terminal window
node site/scripts/build-llms-full.mjs # rewrite public/llms-full.txt
node site/scripts/build-llms-full.mjs --check # CI: fail if out of date
  • One Diátaxis mode per page. No explanation inside a tutorial; no how-to steps inside reference. Link outward to siblings instead of duplicating.
  • British English. Run site/scripts/check-british-english.sh to flag US spellings in the Book’s prose (it ignores fenced code). It is an advisory lint, not a CI gate — treat British spelling as a review-time convention.
  • Document the present. Write what compiles today; mark planned features as planned.
  • Payloadless sums use the enum form. A sum whose variants all carry no payload is written enum { A, B, C } in examples — it is the canonical spelling (types). Reserve the | A | B pipe form for sums where a variant carries a payload (or the grammar reference teaching the sum_type production itself). The two are the same type; the convention keeps examples uniform.

“One mode per page” is also a rule about voice: the same fact should sound different in each mode. Here is “an agent’s state must be zeroable”, written four ways — read them as a tuning fork before you draft a page.

  • Tutorial (warm, “we”, a guaranteed path): “We’ll give the counter a count field. Bynk needs a starting value for a brand-new key, so every state field must have a zero — Int’s is 0, so we’re set. Run it and watch a fresh counter read 0.”
  • How-to (imperative, goal-first): “Keep every agent state field zeroable: use a type with an implicit zero (Int, Bool, String, Option[T]), or give the field an initialiser (field: T = value).”
  • Reference (neutral, terse): “Each agent state field must be zeroable — it has an implicit zero value or an initialiser. A non-zeroable field without an initialiser is rejected (bynk.agents.non_zeroable_state_field).”
  • Explanation (discursive, a view): “Why insist on a zero? A fresh key has no stored state, and no constructor was required first, so the agent must still come into being with a defined value. Zeroability is how Bynk makes ‘never seen before’ honest instead of undefined.”

The glossary gives each load-bearing term a stable anchor, #term-<slug> (e.g. #term-refined-type). On a reader-facing page, link the first occurrence of a glossary term to its entry — [refined type](/reference/glossary/#term-refined-type) — and only the first; never inside a heading, a code fence, or on the glossary page itself.

site/scripts/check-glossary-links.sh is an advisory lint: it lists, per page, glossary terms that appear with no link to their entry, so first-use linking can be caught up page by page. It prints findings and exits 0 (set GLOSSARY_LINK_STRICT=1 to exit non-zero on findings). It deliberately does not auto-link — terms are common words, so a human decides each first use.

The Bynk Language Specification lives in site/src/content/docs/reference/spec/. It is the normative definition of the current language, updated in place per increment, distinct in register from the friendly grammar reference: the reference is per-construct lookup, the spec is the complete citable definition. The two share their generated facts.

It is translation-defined — syntax by the grammar, static semantics by the bynk.* well-formedness rules, dynamic meaning by emission plus the runtime contract — and it reuses the existing machinery: it embeds {{#grammar}} productions and {{#grammar-semantics}} diagnostics just like the reference (the rendered output is shared from one source, so there is no drift), and every example is covered by the doc-example gate. It adds nothing of its own.

Keeping the spec current. A language or grammar increment updates the affected spec chapters and records each language-defining call as a decision record in design/decisions/ — it does not spawn a standalone instalment document. An increment’s design draft is a transient proposal in design/proposals/: merged for sign-off before implementation, consumed by it, and deleted by the PR that lands the increment (the lifecycle is documented in that directory’s README). Much of the spec stays current for free: the {{#grammar}} productions (§3/§4/§11) and the {{#grammar-semantics}} diagnostic links (§5) re-render from the grammar and the registry, so syntax and the diagnostic catalogue never drift. The prose is hand-maintained — when behaviour changes, review §5 (static semantics), §6 (the type system), §7 / §7.4 (emission and the runtime library), §8 (compilation), §10 (conformance), and Appendix B (version history).

Verify against the compiler. Specification and reference claims are checked against the actual compiler — the emitter, the checker, and the fixtures — never against older design documents. Cite the historical design notes for intent only, never for current behaviour.

Treat docs as part of an increment’s definition of done (see Testing & fixtures): update the affected reference (regenerating the generated pages), update the affected specification chapters (per Keeping the spec current above), and write the changelog line in your design/pending/ file: the stamp adds it to Unreleased when the increment merges, and cutting a release moves it to that release’s page. The Book’s current-version banners are single-sourced — scripts/bump-version.sh rewrites them (and regenerates llms-full.txt) and xtask/tests/docs_consistency/doc_version.rs fails CI on drift, so there is no manual version-bump step. Finally, check that any touched tutorial or guide still compiles under the doc-example gate, and run npm run build from site/ to confirm the page renders and its links resolve.