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.
Build and preview locally
Section titled “Build and preview locally”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_TOKENsite/.npmrc already tells npm that @bynk-lang packages live there.
Everything runs from site/:
npm install # one-timenpm run dev # live preview at localhost:4321npm run build # full production build (the gate CI runs)npm run preview # serve the built site to spot-check itnpm 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 brand
Section titled “The brand”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
Sidebaroverride, scoped to the surface being viewed; - the home page:
src/content/docs/index.mdx, whose frontmatterheroholds 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”; andsrc/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.
Licences
Section titled “Licences”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 sidebar
Section titled “The sidebar”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:
node site/scripts/generate-sidebar.mjs # rewrite every sidebarnode site/scripts/generate-sidebar.mjs --check # CI: fail if one drifted or a page is unlistedThe --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 and callouts
Section titled “Diagrams and callouts”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:
| Callout | Aside | Means |
|---|---|---|
> [!NOTE] | note | an aside or clarification |
> [!TIP] | tip | a better or faster way |
> [!WARNING] | caution | easy to get wrong; proceed carefully |
> [!DANGER] | danger | will break, or is forbidden |
> [!WARNING]> Body text — ordinary Markdown, rendered normally.Embedding a grammar production
Section titled “Embedding a grammar production”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.
Showing a real diagnostic
Section titled “Showing a real diagnostic”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:
- Write a standalone failing program at
site/src/diagnostics/<id>.bynk(acommonsorcontextblock, like a doc example, but one that must error). - 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>.bynklabel — tosite/src/diagnostics/<id>.txt. - On the page, show the source in a
bynk,failfence and the transcript in atextfence, each holding a single{{#include}}line pointing at the fixture and its transcript — e.g.{{#include ../../diagnostics/<id>.bynk}}. The plugin resolves thediagnostics/…suffix againstsite/src/(theincludeBaseset inastro.config.mjs), so only thediagnostics/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).
The before/after device
Section titled “The before/after device”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
typescriptblock that genuinely compiles with the exact bug Bynk targets. Tag ittypescript(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,failfixture 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.
The guardrails
Section titled “The guardrails”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.
-
Every example compiles.
bynk-tests/tests/doc_examples.rsextracts every fenced```bynkblock fromsite/src/content/docs/book/**and compiles it —commonsblocks in-process,contextblocks as a temp project, and a block with neither header inside a syntheticcommons(orcontext). 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). -
Generated reference is generated. Three reference pages are emitted from the compiler/grammar and guarded by tests, so they cannot drift:
Page Source Test reference/diagnostics.mdbynk-syntax/src/diagnostics.rsregistrydiagnostics_registry.rsreference/keywords.mdthe lexer’s keyword tokens keywords_reference.rsreference/grammar-appendix.mdtree-sitter-bynk/src/grammar.jsongrammar_reference.rsEach 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.jsonandgrammar-semantics.json— are guarded the same way (xtask’sgenerated_grammar_jsonandgenerated_site_json); re-bless them withBYNK_BLESS=1too.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 itsExplainentry inbynk-syntax/src/diagnostics.rs, whichbynk 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 bysite/src/pages/reference/diagnostics/[code].astrofromsite/src/generated/diagnostics.json, whichdiagnostics_registry.rsguards like the index page. A page lists the Book pages that explain its code fromsite/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 tosite/src/data/published-routes.txt(see Link checking, below). -
Link checking.
starlight-links-validatorvalidates internal links on everyastro build. Separately,site/scripts/check-llms-links.mjsconfirms each/book/route named in the hand-authoredllms.txtindex still maps to a real page, andsite/scripts/check-redirects.mjscheckssite/public/_redirects(the Cloudflare Pages redirects that keep moved pages working) against the builtsite/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/:codeit 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_redirectsdoesn’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: runnode site/scripts/check-redirects.mjs --updateafternpm 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 afternpm run buildwhenever you move or retire a page. -
Drift checks.
node site/scripts/generate-sidebar.mjs --checkandnode site/scripts/build-llms-full.mjs --checkfail CI if the committedsidebar.jsonorllms-full.txtno longer matches its source (see Machine-readable Book, below). The sidebar check also fails when a Book page is missing fromSUMMARY.md. -
Version banners.
xtask/tests/docs_consistency/doc_version.rschecks the Book’s current-version banners;scripts/bump-version.shrewrites them, so there is no manual bump step (see Docs ship with the feature).
Machine-readable Book
Section titled “Machine-readable Book”Two files under site/public/ give tools a text view of the Book:
llms.txtis the hand-authored curated index — a short primer plus links into the Book. Because it is hand-authored it can drift, socheck-llms-links.mjslink-checks its/book/routes.llms-full.txtis generated bysite/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;--checkguards it in CI.
node site/scripts/build-llms-full.mjs # rewrite public/llms-full.txtnode 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.shto 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
enumform. A sum whose variants all carry no payload is writtenenum { A, B, C }in examples — it is the canonical spelling (types). Reserve the| A | Bpipe form for sums where a variant carries a payload (or the grammar reference teaching thesum_typeproduction itself). The two are the same type; the convention keeps examples uniform.
The four voices
Section titled “The four voices”“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
countfield. Bynk needs a starting value for a brand-new key, so every state field must have a zero —Int’s is0, so we’re set. Run it and watch a fresh counter read0.” - 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
statefield 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.”
Glossary first-use linking
Section titled “Glossary first-use linking”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 language specification
Section titled “The language specification”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.
Docs ship with the feature
Section titled “Docs ship with the feature”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.