Agent archetypes: how the list stays current

How swarm-controller learns which archetypes the create form offers, and what it stores. The operator's view is the archetypes page.

The refresh

  1. swarm-controller asks the builder for the list on the queue subject $SWARM.builder.archetypes once the queue connects, and every 10 minutes after that. The controller asks again after a pass that gets no answer or a failed evaluation: after 10 seconds, then 20, doubling up to 10 minutes, until one succeeds.

  2. The builder evaluates the meta of each hyperhiveArchetypes entry on its own hyperhive and nixpkgs sources, and answers with the JSON or the last lines nix printed:

    nix eval --json <hyperhive>#hyperhiveArchetypes \
      --apply 'builtins.mapAttrs (_: a: a.meta)'
    
  3. The controller checks each archetype the way POST /api/agents checks its settings and stores the result in the agent-archetypes KV bucket, under the key hyperhive, when it differs from the stored one. The list leaves out an archetype that fails the check, and its name and reason go into the record's refused map and the controller's journal. An archetype's flows pass the router's archetype check here too; the notification router reads them from this record.

  4. GET /api/archetypes answers from that record, and the create form lists from it.

A builder host redeploy can change the list. The next pass, within 10 minutes, picks it up. When no builder answers, the controller keeps the stored list and logs a warning on each pass. A swarm whose builder connects after the controller has no list until a retry succeeds. A swarm with no builder enabled shows no archetype select.

The stored value:

{
  "source": "/nix/store/…-hyperhive-flake-source",
  "archetypes": {
    "reviewer": {
      "description": "…",
      "permissions": ["messaging", "inbox", "execution"]
    }
  },
  "refused": { "broken": "limits: …" }
}

The built-in prompts

Each built-in archetype's meta.prompt is builtins.readFile of nix/archetypes/prompts/<name>.md. The file read gives a plain string, so meta stays plain data and the nix eval above prints it as JSON. The controller's check holds the prompt to 64 KiB.