<?xml version="1.0" encoding="UTF-8"?>
<!--
  The website's content model: what a page says and in what order, never how
  it looks. A document is either the site (site.xml: its name, navigation and
  pages) or one page (pages/*.xml). render/site.xsl turns them into HTML; the
  design system decides the rest.

  The vocabulary is semantic on purpose. There is no element for a column, a
  colour, a card or a button: a page has a hero, sections, prose, claims with
  their sources, examples and actions, and the stylesheet decides how each one
  looks. A claim cannot be written without its source.

  XSD 1.1 (sxml validate). Links between documents (a link's or an action's
  `to` naming a page, a section's anchor) and a page's references to the
  audiences of site.xml (a purpose's `for`, a section's `answers`) are
  checked when the site is built, since a schema sees one document at a
  time.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="https://www.tinyactors.dev/ns/site"
           targetNamespace="https://www.tinyactors.dev/ns/site"
           elementFormDefault="qualified"
           xpathDefaultNamespace="##targetNamespace"
           version="1.1">

  <!-- ===================================================== the site -->

  <xs:element name="site">
    <xs:annotation><xs:documentation>
      The site: its name, origin, navigation, the pages it is made of (in the
      order the sitemap lists them) and its footer.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="plain"/>
        <xs:element name="tagline" type="plain"/>
        <xs:element ref="audiences"/>
        <xs:element ref="voices"/>
        <xs:element name="nav" type="navigation"/>
        <xs:element name="pages">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="page" maxOccurs="unbounded">
                <xs:annotation><xs:documentation>A page file, relative to site.xml.</xs:documentation></xs:annotation>
                <xs:complexType>
                  <xs:attribute name="src" type="path" use="required"/>
                  <xs:attribute name="preview-path">
                    <xs:annotation><xs:documentation>Optional second address for reviewing a page's presentation. It uses the same content and canonical address and is excluded from discovery.</xs:documentation></xs:annotation>
                    <xs:simpleType>
                      <xs:restriction base="xs:token">
                        <xs:pattern value="/preview/[a-z0-9-]+/"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:attribute>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element ref="packages"/>
        <xs:element ref="namespaces"/>
        <xs:element name="footer">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="note" type="inline" minOccurs="0"/>
              <xs:element name="links" type="links"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="presence" minOccurs="0">
          <xs:annotation><xs:documentation>
            Presence: an ant for every open tab, crawling behind every page
            (docs/presence.md). The words of its ant menu, the floating
            button that opens the site's navigation, the ants switch and the
            greeting line. `server` is the presence server's WebSocket.
          </xs:documentation></xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:element name="label" type="plain">
                <xs:annotation><xs:documentation>The ant button's accessible name: it opens the menu.</xs:documentation></xs:annotation>
              </xs:element>
              <xs:element name="switch" type="plain">
                <xs:annotation><xs:documentation>The switch that takes this tab's ant in and out.</xs:documentation></xs:annotation>
              </xs:element>
              <xs:element name="greet" type="plain">
                <xs:annotation><xs:documentation>The menu's action that greets an ant, for keyboards and screen readers.</xs:documentation></xs:annotation>
              </xs:element>
              <xs:element name="greeted" type="with-country">
                <xs:annotation><xs:documentation>What a greeted tab reads; {country} is the greeter's country, named in the reader's language.</xs:documentation></xs:annotation>
              </xs:element>
              <xs:element name="greeted-anonymous" type="plain">
                <xs:annotation><xs:documentation>What a greeted tab reads when the greeter's country is not known.</xs:documentation></xs:annotation>
              </xs:element>
              <xs:element name="count" type="with-ants">
                <xs:annotation><xs:documentation>What a screen reader says for the menu's count, which shows as the ant mark and a number; {ants} is how many ants this tab sees.</xs:documentation></xs:annotation>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="server" use="required">
              <xs:simpleType>
                <xs:restriction base="xs:anyURI">
                  <xs:pattern value="wss://[a-z0-9.-]+"/>
                </xs:restriction>
              </xs:simpleType>
            </xs:attribute>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="origin" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:anyURI">
            <xs:pattern value="https://[a-z0-9.-]+"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="alias">
        <xs:annotation><xs:documentation>
          Another origin of the site, which redirects to `origin` with the
          path and query kept (https://www.tinyactors.dev to
          https://tinyactors.dev). Nothing is linked at it, but a namespace's
          URI may name it: a namespace is a name, and a name minted under the
          alias stays, its page served at the same path on `origin`.
        </xs:documentation></xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:anyURI">
            <xs:pattern value="https://[a-z0-9.-]+"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
    <xs:key name="voice-ids">
      <xs:selector xpath="voices/voice"/>
      <xs:field xpath="@id"/>
    </xs:key>
    <xs:keyref name="voice-extends" refer="voice-ids">
      <xs:selector xpath="voices/voice"/>
      <xs:field xpath="@extends"/>
    </xs:keyref>
    <xs:key name="audience-ids">
      <xs:selector xpath="audiences/audience"/>
      <xs:field xpath="@id"/>
    </xs:key>
    <xs:unique name="package-ids">
      <xs:selector xpath="packages/package"/>
      <xs:field xpath="@id"/>
    </xs:unique>
    <xs:unique name="page-files">
      <xs:selector xpath="pages/page"/>
      <xs:field xpath="@src"/>
    </xs:unique>
  </xs:element>

  <!-- ===================================================== namespaces -->

  <xs:element name="namespaces">
    <xs:annotation><xs:documentation>
      The XML namespaces the site names under its own origin (the site's
      content, its stylesheet's functions, the audience and voice files it
      publishes), each published at its own URI, so a reader who opens a
      namespace in a document lands on what it is. A URI is of the site's
      `origin` or of its `alias`, which redirects to the origin with the
      path kept. The build writes a page at each URI's path ("/ns/audience"
      as ns/audience.html) and stops at a URI of neither; `mise run test`
      fails when a document of the build or its sources names a namespace
      of either with no page.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="namespace" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="namespace-uris">
      <xs:selector xpath="namespace"/>
      <xs:field xpath="@uri"/>
    </xs:unique>
  </xs:element>

  <xs:element name="namespace">
    <xs:annotation><xs:documentation>
      One namespace: `uri` is the namespace's name and where its page is
      served; `title` and `description` are the page's, as a page's are; the
      blocks say what the namespace names and link its schema and the
      documentation of its convention.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" type="title"/>
        <xs:element name="description" type="sentence"/>
        <xs:group ref="blocks" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="uri" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:anyURI">
            <xs:pattern value="https://[a-z0-9.-]+(/[a-z0-9-]+)+"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <!-- ===================================================== audiences -->

  <xs:element name="audiences">
    <xs:annotation><xs:documentation>
      Who reads the site, defined once. Each page names its audiences in
      its `purpose`, and each section names the needs it answers, by these
      ids. The build publishes each audience as /audiences/&lt;id&gt;.xml
      (schema/audience.xsd), which every page's head links to.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="audience" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="audience">
    <xs:annotation><xs:documentation>
      One kind of reader: who they are (`name`, `description`), what they
      know already (`knows`), and their needs, one line each: what they
      want to find (`want`), what they came to do (`task`), and what makes
      them doubt (`objection`, in their words). A need's id is short and
      stable; a page names it as "audience.need" ("tech-lead.host-dies"),
      so it is unique within its audience.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="plain"/>
        <xs:element name="description" type="words"/>
        <xs:element name="knows" type="words"/>
        <xs:element name="want" type="need" maxOccurs="unbounded"/>
        <xs:element name="task" type="need" maxOccurs="unbounded"/>
        <xs:element name="objection" type="need" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="id" type="audience-id" use="required"/>
    </xs:complexType>
    <xs:unique name="need-ids">
      <xs:selector xpath="want|task|objection"/>
      <xs:field xpath="@id"/>
    </xs:unique>
  </xs:element>

  <!-- ===================================================== voices -->

  <xs:element name="voices">
    <xs:annotation><xs:documentation>
      How the site writes, with one default voice for each kind of page.
      The build publishes every voice as /voices/&lt;id&gt;.xml
      (schema/voice.xsd), its rules whole. Pages link their kind's default.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="voice" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:assert test="(: every kind of page has exactly one default voice :) every $k in ('pitch', 'tutorial', 'how-to', 'reference', 'explanation') satisfies count(voice[not(@role = 'alternate')][tokenize(@kinds) = $k]) eq 1"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="voice">
    <xs:annotation><xs:documentation>
      One way of writing: its `name`, what it is for (`description`) and
      its rules, one line each with a short, stable id. `kinds` are the
      kinds of page written in it. A voice that `extends` another keeps
      that voice's rules, in order, and replaces those of the same id;
      its other rules come after them.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="plain"/>
        <xs:element name="description" type="words"/>
        <xs:element name="rule" type="need" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="id" type="audience-id" use="required"/>
      <xs:attribute name="kinds" use="required">
        <xs:simpleType>
          <xs:list>
            <xs:simpleType>
              <xs:restriction base="xs:token">
                <xs:enumeration value="pitch"/><xs:enumeration value="tutorial"/><xs:enumeration value="how-to"/>
                <xs:enumeration value="reference"/><xs:enumeration value="explanation"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:list>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="extends" type="audience-id"/>
      <xs:attribute name="role">
        <xs:simpleType><xs:restriction base="xs:token"><xs:enumeration value="alternate"/></xs:restriction></xs:simpleType>
      </xs:attribute>
      <xs:assert test="(: a voice does not extend itself :) not(@extends = @id)"/>
    </xs:complexType>
    <xs:unique name="rule-ids">
      <xs:selector xpath="rule"/>
      <xs:field xpath="@id"/>
    </xs:unique>
  </xs:element>

  <xs:complexType name="need">
    <xs:annotation><xs:documentation>One line with an id: a need of an audience, or a rule of a voice, unique within it.</xs:documentation></xs:annotation>
    <xs:simpleContent>
      <xs:extension base="words">
        <xs:attribute name="id" type="audience-id" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:simpleType name="audience-id">
    <xs:annotation><xs:documentation>An audience's or a need's id: lowercase words joined by hyphens ("agent-platform", "host-dies").</xs:documentation></xs:annotation>
    <xs:restriction base="xs:token">
      <xs:pattern value="[a-z][a-z0-9]*(-[a-z0-9]+)*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="words">
    <xs:annotation><xs:documentation>Plain text with no markup, which may wrap across lines.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:token">
      <xs:minLength value="1"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- ===================================================== purposes -->

  <xs:element name="purpose">
    <xs:annotation><xs:documentation>
      What a page is for, and whom: its kind, and its audiences in order,
      the first its main audience (`for`, ids of site.xml's audiences).
      `answers` names needs the page answers as a whole ("audience.need"),
      where no one section does. When needs conflict, the page's purpose
      wins: a need of another kind or audience is linked to the page that
      answers it, never squeezed in. The build checks every id against
      site.xml, since a schema sees one document at a time.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:attribute name="kind" type="kind" use="required"/>
      <xs:attribute name="for" type="audience-ids" use="required"/>
      <xs:attribute name="answers" type="need-references"/>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="kind">
    <xs:annotation><xs:documentation>
      What a reader came to do on a page or a section, from Diátaxis's four
      kinds of documentation and one more:
      `pitch`: decide whether to adopt the idea; a claim, a demonstration
      that runs, proof with its source, and a next step.
      `tutorial`: learn by doing; steps that each run, in order.
      `how-to`: reach a goal they already have; the steps to it.
      `reference`: look up a fact; complete and terse.
      `explanation`: understand why; the reasons and the trade.
    </xs:documentation></xs:annotation>
    <xs:restriction base="xs:token">
      <xs:enumeration value="pitch"/>
      <xs:enumeration value="tutorial"/>
      <xs:enumeration value="how-to"/>
      <xs:enumeration value="reference"/>
      <xs:enumeration value="explanation"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="audience-ids">
    <xs:annotation><xs:documentation>Audience ids, in order, each once.</xs:documentation></xs:annotation>
    <xs:restriction>
      <xs:simpleType><xs:list itemType="audience-id"/></xs:simpleType>
      <xs:minLength value="1"/>
      <xs:assertion test="(: each audience once :) count($value) eq count(distinct-values($value))"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="need-references">
    <xs:annotation><xs:documentation>Needs, each as "audience.need" ("tech-lead.host-dies"), each once.</xs:documentation></xs:annotation>
    <xs:restriction>
      <xs:simpleType>
        <xs:list>
          <xs:simpleType>
            <xs:restriction base="xs:token">
              <xs:pattern value="[a-z][a-z0-9]*(-[a-z0-9]+)*\.[a-z][a-z0-9]*(-[a-z0-9]+)*"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:list>
      </xs:simpleType>
      <xs:minLength value="1"/>
      <xs:assertion test="(: each need once :) count($value) eq count(distinct-values($value))"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="packages">
    <xs:annotation><xs:documentation>
      What a reader installs, one package per platform, each named for the
      reader (`for`: "Node.js and Bun", "Python", "C") and with the
      platforms it runs on (`runs-on`), which the pages show as their icons
      wherever they name the package's platform, `for` as its accessible
      name. The element's text
      is the package's name; `changelog` is its CHANGELOG.md, relative to
      site.xml, whose newest "## [version] - date" section gives the
      version and date every install command and changelog shows, so no
      version is written in the content. `source` is the repository the
      changelogs are in, on its branch main.
      `changes` is the words of the link from an install command to its
      changelog.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="changes" type="plain"/>
        <xs:element name="package" maxOccurs="unbounded">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="plain-attribute">
                <xs:attribute name="id" type="xs:NCName" use="required"/>
                <xs:attribute name="for" type="plain-attribute" use="required"/>
                <xs:attribute name="runs-on" use="required">
                  <xs:simpleType>
                    <xs:restriction>
                      <xs:simpleType>
                        <xs:list>
                          <xs:simpleType>
                            <xs:restriction base="xs:token">
                              <xs:enumeration value="node"/>
                              <xs:enumeration value="bun"/>
                              <xs:enumeration value="browser"/>
                              <xs:enumeration value="python"/>
                              <xs:enumeration value="c"/>
                            </xs:restriction>
                          </xs:simpleType>
                        </xs:list>
                      </xs:simpleType>
                      <xs:minLength value="1"/>
                    </xs:restriction>
                  </xs:simpleType>
                </xs:attribute>
                <xs:attribute name="changelog" type="path" use="required"/>
                <xs:assert test="(: a component's changelog :) matches(@changelog, '^(\.\./)+[a-z0-9-]+/CHANGELOG\.md$')"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="source" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:anyURI"><xs:pattern value="https://github\.com/[A-Za-z0-9-]+/[A-Za-z0-9-]+"/></xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="navigation">
    <xs:annotation><xs:documentation>
      The site's navigation, in order: links, and groups of links. The
      header's row shows each link and each group's `label`; the site's
      menu shows a group as its label, which opens to the group's links in
      place.
    </xs:documentation></xs:annotation>
    <xs:choice maxOccurs="unbounded">
      <xs:element name="link" type="link"/>
      <xs:element name="group">
        <xs:annotation><xs:documentation>
          Pages that belong together, such as the guides: the first link
          is the group's own page (the index), which the header's row links
          the label to; the rest are the pages under it.
        </xs:documentation></xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element name="link" type="link" minOccurs="2" maxOccurs="unbounded"/>
          </xs:sequence>
          <xs:attribute name="label" type="plain-attribute" use="required"/>
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="links">
    <xs:sequence>
      <xs:element name="link" type="link" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <!-- ===================================================== a page -->

  <xs:element name="page">
    <xs:annotation><xs:documentation>
      One page. `path` is where it is served: "/" or "/name/" for a
      directory, "/404" for a file of its own (404.html). Its sections come
      in reading order; each has an id, which is its anchor.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" type="plain">
          <xs:annotation><xs:documentation>The document's title, as a browser tab and a search result show it.</xs:documentation></xs:annotation>
        </xs:element>
        <xs:element name="description" type="sentence">
          <xs:annotation><xs:documentation>One or two sentences for search results, link previews and llms.txt.</xs:documentation></xs:annotation>
        </xs:element>
        <xs:element ref="purpose" minOccurs="0"/>
        <xs:choice>
          <xs:sequence>
            <xs:element ref="hero"/>
            <xs:element ref="section" minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
          <xs:element ref="reference"/>
          <xs:element ref="app"/>
        </xs:choice>
      </xs:sequence>
      <xs:attribute name="id" type="xs:ID" use="required"/>
      <xs:attribute name="path" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:pattern value="/([a-z0-9-]+/)*|/[a-z0-9-]+"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="preview" type="xs:boolean" default="false">
        <xs:annotation><xs:documentation>A page for direct review, omitted from public indexes.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:assert test="(: never 'formal verification': there is no model checker :) not(contains(lower-case(normalize-space(.)), 'formal verification'))"/>
      <xs:assert test="(: a passage is the explanation or the tutorial voice, for explanation and tutorial pages only :) not(.//passage) or purpose/@kind = ('explanation', 'tutorial')"/>
      <xs:assert test="(: a problem opens a section of an explanation page, right under its heading :) not(.//problem) or (purpose/@kind = 'explanation' and (every $p in .//problem satisfies $p/preceding-sibling::*[1][self::heading]))"/>
      <xs:assert test="(: every page but the 404 declares its purpose :) exists(purpose) or @path = '/404'"/>
      <xs:assert test="(: a section's kind differs from its page's :) every $kind in section/@kind satisfies $kind != string(purpose/@kind)"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="hero">
    <xs:annotation><xs:documentation>
      What the page is about, said once: the headline, one lede paragraph,
      how to install, and what to do next. No label above the headline: the
      headline says it. A `playground` here is the page's picture, a live
      scene beside the words (the home page's ants): a module with no
      controls of its own, which runs only while it is seen, holds still
      for a reader who asked for reduced motion, and takes no focus. Its
      `description` says what the scene shows, for a reader without
      scripts and for the Markdown.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="headline" type="title"/>
        <xs:element name="lede" type="inline"/>
        <xs:element ref="stats" minOccurs="0"/>
        <xs:element ref="author" minOccurs="0"/>
        <xs:element ref="published" minOccurs="0"/>
        <xs:element ref="install" minOccurs="0"/>
        <xs:element ref="actions" minOccurs="0"/>
        <xs:element ref="playground" minOccurs="0"/>
      </xs:sequence>
      <xs:assert test="(: a post names who wrote it :) not(published) or exists(author)"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="app">
    <xs:annotation><xs:documentation>
      A page that is one application, a tool the reader works in (the
      snapshot inspector): no headline to read past, no prose, no actions.
      `name` is the tool's short name, said once for screen readers and the
      Markdown; the `playground` is the application, which fills the window
      below the site's header. Its `description` says what a reader without
      scripts would have seen, and is what an agent reads of the page.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="title"/>
        <xs:element ref="playground"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="reference">
    <xs:annotation><xs:documentation>
      A page the reader comes to look something up on, not to be won over:
      it has no hero. Its headline is the page's name ("Changelog"); the
      facts the reader came for come at once below it (`versions`, each
      package's newest), then the blocks that hold the rest.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="headline" type="title"/>
        <xs:element ref="versions" minOccurs="0"/>
        <xs:group ref="blocks" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="versions">
    <xs:annotation><xs:documentation>
      The newest version of each package of site.xml's `packages`, read from
      its changelog, each linking to that release on the page's changelog.
    </xs:documentation></xs:annotation>
    <xs:complexType/>
  </xs:element>

  <xs:element name="author">
    <xs:annotation><xs:documentation>
      Who wrote a page that speaks in the first person: the name (the
      element's text), a portrait (`src`, an image under content/images/,
      served at /assets/images/) and where to find them (`href`, https).
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="plain-attribute">
          <xs:attribute name="src" type="path" use="required"/>
          <xs:attribute name="href" use="required">
            <xs:simpleType>
              <xs:restriction base="xs:string"><xs:pattern value="https://.+"/></xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:assert test="(: a portrait from content/images :) matches(@src, '^\.\./images/[a-z0-9-]+\.(jpg|png|webp)$')"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

  <xs:element name="published" type="xs:date">
    <xs:annotation><xs:documentation>
      The day a post was published, which makes its page a post: an
      announcement or an essay with a named author (the hero's `author`,
      which a post must have) and a date, in the voice of its kind (an
      explanation's "we" for what the maintainers built, tried or
      measured). A post is served under the path of the page that lists
      the posts (`posts`, the blog: "/blog/name/"), which lists it by this
      date and puts it in the blog's Atom feed.
    </xs:documentation></xs:annotation>
  </xs:element>

  <xs:element name="stats">
    <xs:annotation><xs:documentation>
      The measured numbers that back the hero's claim, read before anything
      else: two to four, each a `value` (the number and its unit, as short
      as "530 B") and a `label` (what was measured, 2 to 8 words). Each
      links (`to` and `section`, or `href`) to where it was measured: no
      number without its source.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="stat" minOccurs="2" maxOccurs="4">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="value" type="plain"/>
              <xs:element name="label" type="plain"/>
            </xs:sequence>
            <xs:attribute name="to" type="xs:NCName"/>
            <xs:attribute name="section" type="xs:NCName"/>
            <xs:attribute name="href" type="external"/>
            <xs:assert test="(: a number has its source :) exists(@to) != exists(@href)"/>
            <xs:assert test="(: a value is short :) string-length(normalize-space(value)) le 12"/>
            <xs:assert test="(: a label is 2 to 8 words :) count(tokenize(normalize-space(label))) = (2 to 8)"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="features">
    <xs:annotation><xs:documentation>
      Several claims of equal weight, each a `feature`: a `name` (a
      heading's words) and a `text` (a paragraph), linking (`to` and
      `section`) to the page that proves it. The page shows them side by
      side as cards, so a reader sees all of them at once and follows the
      one they doubt. Two to six.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="feature" minOccurs="2" maxOccurs="6">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="name" type="title"/>
              <xs:element name="text" type="paragraph"/>
            </xs:sequence>
            <xs:attribute name="to" type="xs:NCName" use="required"/>
            <xs:attribute name="section" type="xs:NCName"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="posts">
    <xs:annotation><xs:documentation>
      Every post of the site (each page whose hero has a `published` date),
      newest first: its headline linking to it, its date, its author and its
      description. One page holds it, the blog; the build writes that page's
      Atom feed beside it ("/blog/" as /blog/feed.xml), an entry per post,
      and the blog and every post link the feed in their head.
    </xs:documentation></xs:annotation>
    <xs:complexType/>
  </xs:element>

  <xs:element name="section">
    <xs:annotation><xs:documentation>
      A part of a page: a heading, then its blocks. `kind` is the section's
      own kind, only where it differs from its page's (a pitch's section of
      reference numbers); `answers` names the needs of site.xml's audiences
      the section's text answers ("tech-lead.host-dies"), only those it
      actually answers. `layout` is how a pitch lays the section out:
      "split" sets the words beside what they talk about (the section's
      first code, example, program, figure or playground, which must come
      after the words), "closing" makes it the page's last word, its heading,
      one paragraph, install and actions set apart at the end.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="heading" type="title"/>
        <xs:group ref="blocks" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="id" type="xs:ID" use="required"/>
      <xs:attribute name="kind" type="kind"/>
      <xs:attribute name="answers" type="need-references"/>
      <xs:attribute name="layout">
        <xs:simpleType>
          <xs:restriction base="xs:token">
            <xs:enumeration value="split"/>
            <xs:enumeration value="closing"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:assert test="(: a split section shows one thing beside its words :) not(@layout = 'split')
                       or count((code, example, program, figure, playground)) = 1"/>
      <xs:assert test="(: a closing section is short :) not(@layout = 'closing')
                       or (every $b in * except heading satisfies $b/(self::p, self::install, self::actions, self::prompt))"/>
    </xs:complexType>
  </xs:element>

  <!-- ===================================================== blocks -->

  <xs:group name="blocks">
    <xs:choice>
      <xs:element name="p" type="paragraph"/>
      <xs:element name="passage" type="passage"/>
      <xs:element name="problem" type="problem"/>
      <xs:element ref="list"/>
      <xs:element ref="code"/>
      <xs:element ref="example"/>
      <xs:element ref="program"/>
      <xs:element ref="claims"/>
      <xs:element ref="install"/>
      <xs:element ref="actions"/>
      <xs:element ref="prompt"/>
      <xs:element ref="live"/>
      <xs:element ref="table"/>
      <xs:element ref="figure"/>
      <xs:element ref="demo"/>
      <xs:element ref="drawing"/>
      <xs:element ref="playground"/>
      <xs:element ref="changelog"/>
      <xs:element ref="posts"/>
      <xs:element ref="features"/>
      <xs:element ref="commands"/>
      <xs:element ref="api"/>
    </xs:choice>
  </xs:group>

  <xs:element name="prompt">
    <xs:annotation><xs:documentation>
      Instructions a reader can give to a coding agent. The label names the
      copy action, copied confirms it and preview opens the readable text.
      The text is plain multiline content. Its internal whitespace is kept
      in the preview, on the clipboard and in the page's Markdown.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="label" type="plain"/>
        <xs:element name="copied" type="plain"/>
        <xs:element name="preview" type="plain"/>
        <xs:element name="text" type="xs:string"/>
      </xs:sequence>
      <xs:assert test="(: a prompt has instructions to copy :) normalize-space(text) != ''"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="figure">
    <xs:annotation><xs:documentation>
      A drawing of how parts fit together (a host and its segments): an SVG
      file under content/images/ (`src`), written into the page itself so
      it takes the design system's colors in both themes. Its shapes carry
      the classes `figure__line`, `figure__fill`, `figure__accent`,
      `figure__text` and `figure__muted`, never a color of their own.
      `description` says what the drawing shows, for a reader who cannot
      see it and for the page's Markdown; it is shown under the drawing.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="description" type="inline"/>
      </xs:sequence>
      <xs:attribute name="src" type="path" use="required"/>
      <xs:assert test="(: a drawing from content/images :) matches(@src, '^\.\./images/[a-z0-9-]+\.svg$')"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="demo">
    <xs:annotation><xs:documentation>
      A video demo: a recording of tinyactors doing something end to end,
      made by a program in the repository (website/demos/NAME/, `mise run
      demo NAME`), never filmed by hand. `src` is the MP4 under
      content/videos/ (a .webm of the same name beside it, for browsers
      without H.264) and `poster` its still; `description` says what the
      video shows (its caption, and what a reader without video reads),
      and each `step` is a moment of it: `at` its time (m:ss), the text what
      the video says then. The steps are the transcript: the page lists
      them, each one seeking the video, and the Markdown keeps them.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="description" type="inline"/>
        <xs:element name="step" maxOccurs="unbounded">
          <xs:complexType mixed="true">
            <xs:complexContent>
              <xs:extension base="inline">
                <xs:attribute name="at" use="required">
                  <xs:simpleType>
                    <xs:restriction base="xs:string"><xs:pattern value="[0-9]+:[0-5][0-9]"/></xs:restriction>
                  </xs:simpleType>
                </xs:attribute>
              </xs:extension>
            </xs:complexContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="src" type="path" use="required"/>
      <xs:attribute name="poster" type="path" use="required"/>
      <xs:assert test="(: a video from content/videos :) matches(@src, '^\.\./videos/[a-z0-9-]+\.mp4$')"/>
      <xs:assert test="(: its poster beside it :) @poster = replace(@src, '\.mp4$', '.jpg')"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="drawing">
    <xs:annotation><xs:documentation>
      A picture a program drew, shown as it drew it: an SVG file under
      examples/ (`src`) that a page's commands wrote, such as the
      tutorial's `tinyactors graph -f svg` (mise run test compares the file
      with what the command writes now). `alt` says what it shows, for a
      reader who cannot see it and for the page's Markdown. The command
      pages' drawings (an example of the help that writes an SVG) are made
      by the build, with `href` in place of `src`.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:attribute name="src" type="path" use="required"/>
      <xs:attribute name="alt" type="plain-attribute" use="required"/>
      <xs:assert test="(: an SVG under examples/ :) matches(@src, '^(\.\./)+examples/[a-z0-9/-]+\.svg$')"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="playground">
    <xs:annotation><xs:documentation>
      A program the reader plays with, in the browser, with controls of its
      own: `src` names a module under examples/ that exports
      `mount(element)`. Its logic is tested as any example's is (its
      `main.mjs` runs the same code in Node.js); `description` says what a
      reader without scripts would have seen.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="description" type="inline"/>
      </xs:sequence>
      <xs:attribute name="src" type="path" use="required"/>
      <xs:assert test="contains(@src, 'examples/') and ends-with(@src, '.mjs')"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="table">
    <xs:annotation><xs:documentation>
      A table of measurements or options. Either written here, a `head` row
      and then each `row`, every row as many `cell`s as the head (the first
      cell of a row names it); or transcluded from a guide of the
      repository: the `index`-th table (counted from 1) in the section of
      `src` headed `section`, read at every build, so the site shows what
      the guide says now. `caption` says what was measured, when and on
      what.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="caption" type="inline" minOccurs="0"/>
        <xs:sequence minOccurs="0">
          <xs:element name="head" type="cells"/>
          <xs:element name="row" type="cells" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:sequence>
      <xs:attribute name="src" type="path"/>
      <xs:attribute name="section" type="plain-attribute"/>
      <xs:attribute name="index" type="xs:positiveInteger"/>
      <xs:assert test="(: transcluded or written, not both :) if (@src) then (ends-with(@src, '.md') and @section and not(*:head)) else (*:head and not(@section or @index))"/>
      <xs:assert test="(: every row as wide as the head :) every $row in *:row satisfies count($row/*:cell) = count(*:head/*:cell)"/>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="cells">
    <xs:sequence>
      <xs:element name="cell" type="cell" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="cell" mixed="true">
    <xs:annotation><xs:documentation>A table's cell: running text, which may be empty.</xs:documentation></xs:annotation>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="em" type="emphasis"/>
      <xs:element name="strong" type="emphasis"/>
      <xs:element name="code" type="nonempty"/>
      <xs:element name="link" type="link"/>
    </xs:choice>
  </xs:complexType>

  <xs:element name="live">
    <xs:annotation><xs:documentation>
      An example that runs in the reader's browser. `src` names a module
      under examples/ (the build serves it with the packages it imports),
      and `call` one of its exports, which a button runs: its label is the
      `label`. What the export answers is shown as the run's output, and the
      spans of a traced run as a trace view. The module's code is tested
      like any example's: the same functions run in Node.js under
      `mise run test`.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="label" type="plain"/>
      </xs:sequence>
      <xs:attribute name="src" type="path" use="required"/>
      <xs:attribute name="call" type="xs:NCName" use="required"/>
      <xs:assert test="contains(@src, 'examples/') and ends-with(@src, '.mjs')"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="list">
    <xs:annotation><xs:documentation>
      Items in no particular order, or in order with ordered="true". An item
      may lead with a term: the thing the rest of the item is about. With
      as="questions" each item's term is a question a reader asks and its
      text the answer, shown under the question when the reader opens it.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="item" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="term" type="inline" minOccurs="0"/>
              <xs:element name="text" type="inline"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="ordered" type="xs:boolean" default="false"/>
      <xs:attribute name="as">
        <xs:simpleType>
          <xs:restriction base="xs:token"><xs:enumeration value="questions"/></xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:assert test="(: a question has its words :) not(@as = 'questions') or (every $i in item satisfies exists($i/term))"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="code">
    <xs:annotation><xs:documentation>
      Code exactly as written, shown verbatim. Either its text is here (the
      build removes the common leading indentation and blank first and last
      lines), or `src` names a file, relative to this document, whose text it
      is: an example under examples/, which the tests run, so the code a
      page shows is code that ran. `file` names it as a reader would save
      it; `language` is what it is written in; `role` is "output" for what a
      program prints.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute name="src" type="path"/>
          <xs:attribute name="section" type="plain-attribute">
            <xs:annotation><xs:documentation>
              With a Markdown `src` (a guide of the repository): the heading
              of its section ("Turning it on", the text after "## "), whose
              `fence`-th fenced block, counted from 1, this is. The guides'
              examples are run by `mise run test` against their output.
            </xs:documentation></xs:annotation>
          </xs:attribute>
          <xs:attribute name="fence" type="xs:positiveInteger"/>
          <xs:attribute name="lines">
            <xs:annotation><xs:documentation>
              With `src`: the lines of the file to show, "first-last",
              counted from 1, for an excerpt of a program that runs whole.
            </xs:documentation></xs:annotation>
            <xs:simpleType>
              <xs:restriction base="xs:token">
                <xs:pattern value="[1-9][0-9]*-[1-9][0-9]*"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:attribute name="language" type="language" use="required"/>
          <xs:attribute name="file" type="xs:token"/>
          <xs:attribute name="role" default="source">
            <xs:simpleType>
              <xs:restriction base="xs:token">
                <xs:enumeration value="source"/>
                <xs:enumeration value="output"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:assert test="if (@src) then normalize-space(.) = '' else normalize-space(.) != ''"/>
          <xs:assert test="not(@lines) or (@src and xs:integer(substring-before(@lines, '-')) le xs:integer(substring-after(@lines, '-')))"/>
          <xs:assert test="if (ends-with(@src, '.md')) then (@section and @fence and not(@lines)) else not(@section or @fence)"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

  <xs:element name="example">
    <xs:annotation><xs:documentation>
      Code that belongs together, read in order: a chart and the program that
      runs it, then what it prints.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="code" maxOccurs="unbounded"/>
        <xs:element name="caption" type="inline" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="program">
    <xs:annotation><xs:documentation>
      One program, written for several packages of site.xml's `packages`:
      how a reader's code uses tinyactors, not how a chart is written. Each
      `in` is the program for one package (`package`, its id), as its files:
      the program first, then what it reads (the chart). Every file is a
      `code` with `src` and `file`, under examples/, where `mise run test`
      runs each language's program and compares what it prints with the
      one output the block ends with. The page shows one package at a time,
      behind tabs whose choice is the install commands' (the reader's
      platform holds), and one file at a time behind tabs of its own.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="in" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element ref="code" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="package" type="xs:NCName" use="required"/>
            <xs:assert test="(: every file is one that ran :) every $code in *:code satisfies ($code/@src and $code/@file and not($code/@role = 'output') and not($code/@lines))"/>
            <xs:assert test="(: one file of each name :) count(distinct-values(*:code/@file)) = count(*:code)"/>
          </xs:complexType>
        </xs:element>
        <xs:element ref="diagram" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="code"/>
      </xs:sequence>
      <xs:assert test="(: a diagram is of a chart the programs read :) every $diagram in *:diagram satisfies $diagram/@chart = *:in/*:code[@language = 'scxml']/@file"/>
      <xs:assert test="(: one program per package :) count(distinct-values(*:in/@package)) = count(*:in)"/>
      <xs:assert test="(: it ends with what the programs print :) *:code[last()]/@role = 'output'"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="diagram">
    <xs:annotation><xs:documentation>
      How the diagram of a program's chart (`chart`, its file) is run by a
      reader. An `event` is one the reader may send, with its `data` (a JSON
      object): the first `event` of a name is what clicking that event's
      transition label sends, and an `event` with words is also a button
      under the diagram, its words the button's (an action: 2 to 4 words),
      so a reader sends specific data ("Add a pen"). The reader plays each
      I/O processor the chart sends to by clicking the label of its reply.
      With first="true" the diagram is the program's first view, before
      its files: the program is shown for what it does.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="event" maxOccurs="unbounded">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="name" type="xs:token" use="required"/>
                <xs:attribute name="data" type="xs:string" use="required"/>
                <xs:assert test="(: data is a JSON object :) parse-json(@data) instance of map(*)"/>
                <xs:assert test="(: a button's words are an action :) normalize-space(.) = '' or count(tokenize(normalize-space(.))) = (2 to 4)"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="chart" type="xs:token" use="required"/>
      <xs:attribute name="first" type="xs:boolean" default="false"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="claims">
    <xs:annotation><xs:documentation>
      Statements a reader may doubt, each with what backs it. A claim says
      one thing; its text says what makes it true; its sources are where a
      reader checks it (a file in a repository, a decision record, a
      measurement). A claim with no source does not validate.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="claim" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="statement" type="title"/>
              <xs:element name="p" type="paragraph" maxOccurs="unbounded"/>
              <xs:element name="source" type="source" maxOccurs="unbounded"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="install">
    <xs:annotation><xs:documentation>
      How to install: one command per package of site.xml's `packages`
      (`package`, its id), which names it for the reader and gives its
      version: the command shows the version and date, with a link to the
      package's changelog. "{version}" in a command is that version. Each
      has the guide to read next (`guide`). The commands do the same thing
      in different words, so a page shows one at a time, behind tabs, and
      the reader's choice holds for every install on the page.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="command" maxOccurs="unbounded">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="nonempty">
                <xs:attribute name="package" type="xs:NCName" use="required"/>
                <xs:attribute name="guide" type="external"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="changelog">
    <xs:annotation><xs:documentation>
      Every package's releases, newest first, behind the same tabs as the
      install commands (the reader's platform holds): each release's
      version, date and the hand-written part of its changelog section
      (Summary, Upgrading), quoted as the release wrote it; the newest
      open, the older ones folded. `more` is the words of each release's
      link to its whole section (every commit, every API change) in the
      changelog on the repository's main branch. One page holds it: the install
      commands link there.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="more" type="plain"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="api">
    <xs:annotation><xs:documentation>
      The API reference of a package (`package`, its name as one of
      site.xml's `packages` gives it), made from the package as the
      site's examples pin it: their package-lock.json for @tinyactors/node,
      their uv.lock for tinyactors (mise/api.rb). The build reads the
      published declarations, @tinyactors/node's index.d.ts with
      TypeScript's parser (tools/api-node.mjs) and the tinyactors module
      with Python's introspection (tools/api-python.py), and the block is
      every exported class, function, interface, type and constant, each
      with its signature (each overload's), its doc comment and its
      members, grouped as the package groups them (index.d.ts's banners
      and "---- name ----" comments; the module docstring's parts and
      list), each with its anchor (its name; a member's
      "Class.member"), after the package's version, its introduction (the
      declarations' opening comment, the module docstring's first
      paragraph) and a table of contents. Nothing of it is written by
      hand: the doc comments are its copy, and a new export appears when
      the examples move to a new release. The build stops at a package it
      cannot read.

      The children are the words the block adds: `contents`, the heading
      of the table of contents; `examples`, the label of a doc comment's
      example; `others`, the heading of the names the package's own
      groups leave out (required when there are any: the build says so).
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="contents" type="title"/>
        <xs:element name="examples" type="plain"/>
        <xs:element name="others" type="title" minOccurs="0"/>
      </xs:sequence>
      <xs:attribute name="package" type="plain" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="commands">
    <xs:annotation><xs:documentation>
      The tinyactors command's commands, as the released command describes
      itself: the build runs the binary website/mise.toml pins (mise/cli.rb;
      TINYACTORS_CLI names another, for development), reads its help as XML
      (`help -f xml`, `help COMMAND -f xml`, the tables its argument parser
      reads) and runs each example of its help on the charts of
      examples/cli/. Here the block is the program's usage and a list of its
      commands, each with its summary; and each command gets a page of its
      own, at this page's path followed by its name ("/cli/compile/"), with
      the id of this page followed by "-" and its name ("cli-compile"): its
      usage and description, its options and the options every command
      takes (each a term and its description, the values it takes after
      it), each example with its caption (when the help gives one) and
      what it printed (and the pictures it drew), its exit statuses (when
      the help gives them), then what `related` and `artifact` add.
      Nothing on those pages is written by hand: a new command or option
      appears when the site builds against a new release. One page of the
      site holds it.

      The children are the words those pages use, since the help gives
      only its own: `title`, each command page's title, with "{command}"
      for the command's name; the headings `usage`, `options`,
      `program-options` (the options every command takes), `examples`,
      `exit-status` and `see` (the links that follow); `all`, the heading
      of the way to every other command, which ends each command's page; `values`, the word
      before the values an option takes; and `status`, added to an
      example's caption when it exits with another status than 0, with
      "{status}". `for` is the command pages' audiences, as a purpose's.

      `related` adds a link (a page of this site that explains what the
      help cannot carry) to the page of its `command`; `artifact` a file
      the build writes from the binary (its `arguments`, run as
      `tinyactors ARGUMENTS`, their standard output) and serves at the
      commands page's path followed by `file`, linked with its words from
      the page of its `command`. The build stops at a `command` the binary
      does not have.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" type="with-command"/>
        <xs:element name="usage" type="title"/>
        <xs:element name="options" type="title"/>
        <xs:element name="program-options" type="title"/>
        <xs:element name="examples" type="title"/>
        <xs:element name="exit-status" type="title"/>
        <xs:element name="see" type="title"/>
        <xs:element name="all" type="title"/>
        <xs:element name="values" type="plain"/>
        <xs:element name="status" type="with-status"/>
        <xs:element name="shared" type="inline" minOccurs="0">
          <xs:annotation><xs:documentation>
            The sentence each command's page shows in place of the options every
            command takes, linking to where this page lists them (its
            section "program-options").
          </xs:documentation></xs:annotation>
        </xs:element>
        <xs:element name="job" minOccurs="0" maxOccurs="unbounded">
          <xs:annotation><xs:documentation>
            A job the command does, and the commands that do it (`commands`,
            names separated by spaces; a command may do two jobs): this page
            lists the commands by job, under its `name` and `summary`, and
            each command's page ends with every job's commands. With jobs,
            every command of the help must be in one: the build stops
            otherwise, so a new command cannot drop out of the reference.
          </xs:documentation></xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:element name="name" type="title"/>
              <xs:element name="summary" type="paragraph"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:NCName" use="required"/>
            <xs:attribute name="commands" use="required">
              <xs:simpleType>
                <xs:list itemType="command-name"/>
              </xs:simpleType>
            </xs:attribute>
          </xs:complexType>
        </xs:element>
        <xs:element name="related" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="link" type="link"/>
            </xs:sequence>
            <xs:attribute name="command" type="command-name" use="required"/>
          </xs:complexType>
        </xs:element>
        <xs:element name="artifact" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="plain-attribute">
                <xs:attribute name="command" type="command-name" use="required"/>
                <xs:attribute name="arguments" type="plain-attribute" use="required"/>
                <xs:attribute name="file" use="required">
                  <xs:simpleType>
                    <xs:restriction base="xs:token"><xs:pattern value="[a-z0-9][a-z0-9.-]*\.[a-z]+"/></xs:restriction>
                  </xs:simpleType>
                </xs:attribute>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="for" type="audience-ids" use="required"/>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="command-name">
    <xs:restriction base="xs:token"><xs:pattern value="[a-z]+"/></xs:restriction>
  </xs:simpleType>

  <xs:element name="actions">
    <xs:annotation><xs:documentation>
      What to do next, most important first: the first action is the one
      the page wants the reader to take.
    </xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="action" type="link" maxOccurs="3"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!-- ===================================================== inline -->

  <xs:complexType name="inline" mixed="true">
    <xs:annotation><xs:documentation>
      Running text: emphasis, a strong word, code, a link. No line breaks,
      no styling.
    </xs:documentation></xs:annotation>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="em" type="emphasis"/>
      <xs:element name="strong" type="emphasis"/>
      <xs:element name="code" type="nonempty"/>
      <xs:element name="link" type="link"/>
    </xs:choice>
    <xs:assert test="normalize-space(.) != ''"/>
  </xs:complexType>

  <xs:complexType name="paragraph" mixed="true">
    <xs:annotation><xs:documentation>
      A paragraph of a section: one to three sentences, each at most 30 words
      (the reference voice's "rhythm" and "paragraphs" rules, content/site.xml).
      A sentence ends at ".", "?" or "!" followed by a space; words are what
      spaces separate, code included. Write more as another paragraph, or
      as a list.
    </xs:documentation></xs:annotation>
    <xs:complexContent>
      <xs:extension base="inline">
        <xs:assert test="(: at most three sentences :) count(tokenize(replace(normalize-space(.), '([.?!]) ', '$1&#10;'), '&#10;')) le 3"/>
        <xs:assert test="(: at most 30 words a sentence :) every $sentence in tokenize(replace(normalize-space(.), '([.?!]) ', '$1&#10;'), '&#10;') satisfies count(tokenize($sentence, ' ')) le 30"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="passage" mixed="true">
    <xs:annotation><xs:documentation>
      A paragraph in the explanation voice or the tutorial voice
      (website/AGENTS.md): the prose of an explanation page that a reader
      follows from start to end, as a chapter of a book, or of a tutorial
      step that says what you do, what you see and why. Up to five
      sentences, each at most 32 words, with the same sentence rules as a
      paragraph. Only explanation and tutorial pages have them (the page's
      assertion).
    </xs:documentation></xs:annotation>
    <xs:complexContent>
      <xs:extension base="inline">
        <xs:assert test="(: at most five sentences :) count(tokenize(replace(normalize-space(.), '([.?!]) ', '$1&#10;'), '&#10;')) le 5"/>
        <xs:assert test="(: at most 32 words a sentence :) every $sentence in tokenize(replace(normalize-space(.), '([.?!]) ', '$1&#10;'), '&#10;') satisfies count(tokenize($sentence, ' ')) le 32"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="problem" mixed="true">
    <xs:annotation><xs:documentation>
      The problem a section of an explanation page solves, stated as the
      reader meets it: a concrete situation with its stakes ("A deploy
      must not stop the orders already paying"), never a question. One to
      three sentences of at most 32 words; it stands right under the
      section's heading, and the page sets it apart. The passages after
      it answer it.
    </xs:documentation></xs:annotation>
    <xs:complexContent>
      <xs:extension base="inline">
        <xs:assert test="(: one to three sentences :) count(tokenize(replace(normalize-space(.), '([.?!]) ', '$1&#10;'), '&#10;')) le 3"/>
        <xs:assert test="(: at most 32 words a sentence :) every $sentence in tokenize(replace(normalize-space(.), '([.?!]) ', '$1&#10;'), '&#10;') satisfies count(tokenize($sentence, ' ')) le 32"/>
        <xs:assert test="(: a statement, not a question :) not(contains(., '?'))"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="title" mixed="true">
    <xs:annotation><xs:documentation>
      A headline, a section's heading or a claim's statement: one to eight
      words, in sentence case, with no period at the end ("Build a team
      chat"). A question keeps its question mark.
    </xs:documentation></xs:annotation>
    <xs:complexContent>
      <xs:extension base="emphasis">
        <xs:assert test="(: one to eight words :) count(tokenize(normalize-space(.), ' ')) le 8"/>
        <xs:assert test="(: no period at the end :) not(ends-with(normalize-space(.), '.'))"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="emphasis" mixed="true">
    <xs:annotation><xs:documentation>A heading's or a statement's text: words, one of them emphasised, or code.</xs:documentation></xs:annotation>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="em" type="plain"/>
      <xs:element name="code" type="nonempty"/>
    </xs:choice>
    <xs:assert test="normalize-space(.) != ''"/>
  </xs:complexType>

  <xs:complexType name="link" mixed="true">
    <xs:annotation><xs:documentation>
      A link names a page of the site (`to`, its id, with an optional
      `section` for an anchor) or a location elsewhere (`href`), never both.
      Its text is what the reader clicks; a link to a page may leave it
      empty, and gets the page's title.
    </xs:documentation></xs:annotation>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="em" type="plain"/>
      <xs:element name="code" type="nonempty"/>
    </xs:choice>
    <xs:attribute name="to" type="xs:NCName"/>
    <xs:attribute name="section" type="xs:NCName"/>
    <xs:attribute name="href" type="external"/>
    <xs:assert test="count((@to, @href)) = 1"/>
    <xs:assert test="not(@section) or @to"/>
    <xs:assert test="@to or normalize-space(.) != ''"/>
  </xs:complexType>

  <xs:complexType name="source" mixed="true">
    <xs:annotation><xs:documentation>
      Where a claim can be checked: the text names it; `to` (and `section`)
      a page of this site that shows the evidence, or `href` a primary
      source elsewhere (a standard). A page of the site is the better one:
      the reader stays here.
    </xs:documentation></xs:annotation>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="code" type="nonempty"/>
    </xs:choice>
    <xs:attribute name="to" type="xs:NCName"/>
    <xs:attribute name="section" type="xs:NCName"/>
    <xs:attribute name="href" type="external"/>
    <xs:assert test="count((@to, @href)) = 1"/>
    <xs:assert test="not(@section) or @to"/>
    <xs:assert test="normalize-space(.) != ''"/>
  </xs:complexType>

  <!-- ===================================================== simple types -->

  <xs:simpleType name="nonempty">
    <xs:restriction base="xs:string">
      <xs:pattern value=".*\S.*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="plain">
    <xs:annotation><xs:documentation>Text with no markup, on one line.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="\s*\S[^\n]*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="with-country">
    <xs:annotation><xs:documentation>Plain text that names {country}, where the page puts a country's name.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="[^\n]*\{country\}[^\n]*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="with-ants">
    <xs:annotation><xs:documentation>Plain text that holds {ants}, where the page puts a number of ants.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="[^\n]*\{ants\}[^\n]*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="with-command">
    <xs:annotation><xs:documentation>Plain text that holds {command}, where a command page puts the command's name.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="[^\n]*\{command\}[^\n]*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="with-status">
    <xs:annotation><xs:documentation>Plain text that holds {status}, where a command page puts an example's exit status.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="[^\n]*\{status\}[^\n]*"/>
    </xs:restriction>
  </xs:simpleType>


  <xs:simpleType name="plain-attribute">
    <xs:restriction base="xs:token">
      <xs:minLength value="1"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="sentence">
    <xs:annotation><xs:documentation>Plain text that ends as a sentence does, at most 200 characters.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="\s*\S[\s\S]*[.!?]\s*"/>
      <xs:maxLength value="200"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="external">
    <xs:annotation><xs:documentation>An absolute https URL: links to pages of this site use `to`.</xs:documentation></xs:annotation>
    <xs:restriction base="xs:anyURI">
      <xs:pattern value="https://\S+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="path">
    <xs:restriction base="xs:token">
      <xs:pattern value="[A-Za-z0-9._/-]+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="language">
    <xs:restriction base="xs:token">
      <xs:enumeration value="xml"/>
      <xs:enumeration value="scxml"/>
      <xs:enumeration value="javascript"/>
      <xs:enumeration value="typescript"/>
      <xs:enumeration value="python"/>
      <xs:enumeration value="c"/>
      <xs:enumeration value="shell"/>
      <xs:enumeration value="yaml"/>
      <xs:enumeration value="toml"/>
      <xs:enumeration value="json"/>
      <xs:enumeration value="jsonl"/>
      <xs:enumeration value="markdown"/>
      <xs:enumeration value="text"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
