Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Training a site

A business describes itself in plain words: what it does, who comes to it, what it keeps track of and through which stages, and who handles what. The trainer, bratac plan and bratac build, turns that into a working content repo: a question series for every role, the state machines behind them, and a desk per handling role. No software is written for the business; the only thing produced is content, and every line of it is held to the lint (iris check), which is the same code as the site, at the same version.

The real sites’ plans, words and documents, and runs/, the lab notebook of every session so far, are private, in uhhm/sessions: every runs/... path on this page is there. The plans and intakes beside the trainer in this repo are invented examples.

Build: structure from the plan, words from the model

bratac build --plan plans/contractor.yaml --out out/nordvik \
    --lint "portal lint" --llm "MODEL=sonnet engines/claude.sh"

A plan.yaml is a needs spec that also says what each form collects and, per need, max_fields: how many required fields that person will tolerate, taken from what the business said about them, never from the form. build refuses a form over its budget, and hands the budget to the verifier, so the check still means something after handover. Everything structural is derived from the plan with no model involved: the state machines (read off stages: walk the line, be turned down at any point, succeed only from the end, pass over skippable stages), the front door, a followup page per need, a gated directory per group with its desk and the pages only that group may open, and every button the machine allows. The verifier accepts the result by construction; what it still checks is the budget.

The model writes words only, one page at a time, into a JSON object whose shape is fixed. Its strings are merged over built-in fallbacks key by key, so a bad reply costs wording, never a working site. --llm-for <path prefix> points the model at some pages only (aggregates.yaml for the mails alone), and --llm-note <text> adds a word to each of those pages’ prompts, for a page asked again (what was wrong with the last reply, or two headings that read alike). The prompt shows a page’s slots, not the words they hold, so a note that asks for a rewrite names the words it means. A plan with one tone gets that voice; with several, each pass is told to keep to its own. A reply in the wrong language for the plan is refused, and a mail that lost the submitter’s link gets it back.

Onboarding from the plan

invites_by: [board] on a plan, or invited_by: [...] on a group, puts an invite form on the inviting group’s desk for each group it may fill, and a list of the invites sent. Portal does the rest (an account in Kanidm, the group, a one-time credential link) through invite: on the alternative. Every group with a desk invites into itself by default.

Facts on a card

A need may carry facts, each { about, title, text }, with about one of cost, time, outcome, fit, not_for, prepare and place. They are what a visitor choosing between this card and the ones beside it can use: “Most kitchens take three to five weeks”. build puts them on the card word for word, after what you need and before what happens next, each with an icon for what it is about. No model rewords them. A fact informs and never acts: an order, a question or a button is refused. For a real business no fact is invented. --facts off builds the same site without them, to measure what they do.

Rebuilding a live site

--words-from <repo> lifts the words a repo already has back into the words map by what each card is (its bucket, the page it leads to, the group it invites into), across the whole repo, so a rebuild keeps hand-edited wording even when a card moves page (a door taken away, a need brought onto the front door) and adds only the new slots. Cards are matched by what they are (the bucket they record into, the page they lead to, a field’s name, the group they invite into), not by position, so a rebuild that reorders or reshapes a page still hands each card its own words; on uhhm.no the live front door’s three headings follow their buckets onto the new page. --words <json> overrides slots by page and may repeat, each file layered over the last (the words a build used, then a round of hand changes); words.json in the output is the words as used. See runs/tomtervel-invites-2026-09-23 and runs/uhhm-2026-09-23.

Same contractor, same local model (nemotron 30B-A3B on ergo)Free-form generatebuild
A site the verifier acceptsnever, in 6 rounds and 16 minfirst try, 130 s
Held-out personas, with descriptions-8 of 8
Held-out personas, headings only-7 of 8

The wording numbers are from the re-score of 2026-09-22, one task per call (runs/contractor-build-2026-09-21/rescore-2026-09-22/). The first score, all tasks in one prompt, said 8 of 8 on headings only; the apprentice picking the building survey over “Join our carpentry team” only showed once no other visitor was in the prompt.

For comparison, a Sonnet-class model writing everything free-form scored 8 of 10 on headings only and silently dropped a stage the owner had described. build cannot drop a stage: it never decides one. The denominators differ: the build site gives the two crew personas a one-option page, so they generate no task, and 8 of 8 is eight public personas where the generate number is ten. Held out means held out from the model: the plan’s who and wants lines and the personas were written by the same person about the same needs, and the fallback heading is the need’s wants, so the two are cousins.

The front door opens modestly

A front door with more buttons than text leaves a visitor paralysed. So the built front door opens with what the business does, in one or two features and no button at all (does: on the plan, at most two, each for: a need so it speaks to one role and is headed by what that role gets); then a look-around card, things a visitor may inspect before asking for anything (shows:, each a portal resource block passed through verbatim, plus every public view the plan opens); and only then the offers, as more alternatives on the same page. Nothing is layered: doors still exist for a plan that wants them, but a second tier is what this shape is there to avoid, and on uhhm.no a flat front door with an opener routed better than the doored one.

The house and its players: a role the opener invites in has to see its win, and the machine has to give it something to do after it sits down. build warns when a featured need gives the submitter neither a move (moves_by: {<stage>: [submitter, ...]}) nor a public view; a player with no move is a spectator.

Doors: a first question before the forms

A plan can put public needs behind doors: each door is one alternative on the front door leading to a page of its own, where the needs that name it sit.

A door is built as a page only where the plan’s offers outgrow one front door: more than seven public needs. Where they all fit, a door would only pass the visitor along, to a page holding a few of the things the front door could have held, so build reads the needs as the front door’s own and says so among its readings (“the plan’s 2 door(s) hold what fits the front door”). Measured both ways: six offers sat better on one page than behind two doors, ten better behind four. The lint counts what is left of passing along (see the lint), and score carries the count.

doors:
  - id: patients
    who: someone with pain or an injury, or a patient who already has a time here
needs:
  - id: new-patient
    door: patients
    ...

The door’s page is a nav page, public, holding the forms. The spec gives such a need max_steps: 2 and pins via to the door’s heading, so the verifier walks both pages. A door nobody is behind, a door on an internal need, or a door named like a group is refused, and a front door over five alternatives is warned about. The visitor is scored on both pages: a persona who picks the wrong door is a misroute on /, one who picks the wrong form is a misroute on the door’s page.

Cases with doors: plans/building-permits.yaml (a building authority, nine public needs) is built behind its two. The plans whose doors hold what fits one page are built with their needs on the front door: plans/physio.yaml (a physiotherapy clinic, patients and referrers), plans/fotballklubb.yaml (a football club, in Norwegian, parents and helpers), plans/hire.yaml (a machine hire yard, hiring and firms), and plans/contractor-full.yaml (six public needs). Each has an intake under intakes/ in the business’s own words and held-out personas.

What a plan can say about a form and its readers

  • multiple: true on a select: pick any number (portal renders toggles). What a volunteer can do, which events, which committees.
  • groups: at the top, a list of { id, label }: the groups with a name the public knows, such as a vel’s committees. A select with options_from: groups offers exactly those labels, so the application form and the desks cannot drift apart.
  • watched_by: [public]: an ungated read-only page of the bucket at /status/<bucket>, linked from the followup page. Everyone sees what was sent in and where it stands. email and tel fields, and any field marked private: true, are projected away before it is shown.
  • events: { open: applied, active: onboarded } on a need: the event name a stage is entered by, where the builder’s default (the stage’s own name, received for the first) is not what a live site already has. Portal replays every record by event name, so a rebuild of a site that holds records keeps the names its aggregates.yaml has, or every record vanishes from its desk. uhhm.no’s plan (in uhhm/sessions) rebuilds it this way.
  • mails: { <stage>: submitter | <address> } on a need: who hears when a case enters that stage, sent by portal the moment it moves (delivered by gdo, beside the site). submitter goes to the email the form collected, so the form must collect a required email; an address is the treasurer, the board. The plan then needs mail: { from, reply_to } at the top, the sender every mail carries into site.yaml. The words model writes each mail’s subject and body (aggregates.yaml in the words map); the fallback says what happened and, where the submitter has a move from that stage, the link to make it.
  • stages_text: { <stage>: <words> } on a need: each stage in the plan’s language, where the ASCII id will not do (ikke_lost reads as English). Used by the fallback mails, the “what happens next” line, the desk buttons’ fallback labels, and written into needs.yaml as stage_words so the desk score describes an outcome in the site’s own words. With them, the vel’s desks score 26 of 26.
  • turned_down_from: [<stage>, ...] on a need: the unfinished stages a case can still be turned down from; omitted, every one. An applicant is declined before they start and departs after, which is what uhhm.no’s live machine says and what two near-synonymous desk buttons had been standing in for.
  • reached_from: { <stage>: [<stage>, ...] } on a need: where a stage is entered from, when the line a case walks does not say it. Two shapes need it and nothing else does - a case SENT BACK to a stage it was already past (a building application returned for the drawing it was missing, after the hearing turned something up), and a GOOD ENDING PARTWAY ALONG (an authority that changes its own decision while it is looking at the appeal, rather than passing it up to the board). A stage named there is entered from exactly those stages and nowhere else, so saying where a refusal may come from also says where it may not: an applicant may withdraw from anywhere, and be refused only once the papers are in, which turned_down_from could not express because it was one list for every bad ending at once. Found by replaying a building authority’s real cases through portal’s engine, which refused three legal paths and accepted two illegal ones until the plan could say this; see runs/permits-2026-09-25/README.md.
  • attended_by: on a need: who moves cases that no desk button moves, an automation listening on the bucket’s events, written into aggregates.yaml as portal’s own annotation for the reader.

Plan: the intake, read by a model, checked by a person

bratac plan --intake intakes/contractor.yaml --out out/nordvik \
    --personas sectors/construction/needs.yaml \
    --llm "MODEL=nemotron-3.5-lightning:30b-a3b engines/ollama.sh"

This is the one step where a model decides structure: which needs the intake implies, the stages, who handles what, the form, the budget. Its YAML is parsed and validated exactly as build will, the errors go back to it, and what passes is written verbatim for a person to read before building from it. Personas are never asked of this model; they are attached from a file, and where their need: names an id the plan does not have, plan says so and leaves the mapping to the reader.

generate (below) is the older path, a model writing pages free-form against the lint. It is kept for the record of what it measured.

Interview: the intake, one question at a time

bratac interview is plan for a business that has not written an intake: a conversation that ends in a plan.

bratac interview --out runs/nordvik-interview --human --llm engines/ollama.sh
bratac interview --out runs/nordvik-interview --person intakes/contractor.yaml \
  --llm engines/ollama.sh          # unattended: a model plays the owner

Each turn the model is handed the plan format, the conversation so far, the current draft and what a checker still finds missing, and returns the whole updated draft, what it does not yet know, and one next question in plain words. The draft is held to two things the model cannot talk its way past: a semantic checklist (every kind of person named is a need; every need has its stages, what ends them, a desk whose role the owner has described, and a form within its budget), and the real plan parser, which is what build reads. When both are satisfied and the model has nothing left to ask, the plan is read back for the owner to confirm, written as plan.yaml, and built into site/ with the same model writing the words (--no-build to stop at the plan).

Lessons from a larger model. A small interviewer asks questions that close nothing: “Tell me about your processes.” Every interview already marks them, since transcript.jsonl carries what the checker found missing before each turn and what the turn closed. bratac teach hands each such turn to a larger model, with the conversation up to it and what was missing, and keeps the question that model would have asked:

bratac teach --out lessons.jsonl --llm "MODEL=glm-5.3-flash engines/llama.sh" \
    runs/*/transcript.jsonl
bratac interview --out runs/nordvik-2 --person intakes/contractor.yaml \
    --llm engines/ollama.sh --lessons lessons.jsonl

A lesson is {missing, asked, better, source} and is about a kind of gap, not a business: the need’s own id is taken out of the checker’s phrase, so what a physio’s interview taught is shown in a contractor’s when the same is missing. --lessons shows the interviewer at most three, those that share the most with what is missing now, and tells it to take the manner and not the words. A lesson quotes the two questions and never an answer; teach itself sends the whole conversation to the teacher’s command, so a real owner’s interview is for a model on this machine. The web interview does not read lessons yet.

--experts adds a second, short phase after the interview has what it needs. An expert is a file under crates/bratac/experts/ that knows one thing and is only called when that thing came up. The first is money (money.yaml): it fires when the owner used a word for paying, when a stage reads like invoiced or paid, or, failing both, after one plain question (“Does anyone pay you for any of this?”) that only a plain no turns away. It has three questions at most, and what it learns goes into the plan as the bucket’s existing ledger: (ledger: { amount: 2500 } or { amount: { field: price } } on a need). It may only write an amount the owner said in so many words, or a field the need already asks for as money or number; a guess is refused, as is a question that talks shop (fields, JSON, ledgers). What it could not settle is listed under open: in the plan, one line a need, and said back to the owner as still open. The web interview has no experts yet.

Three rules came out of the first runs, where an 8B model never wrote a need in twelve turns. Settled facts are merged forward, so a model that rewrites the draft from scratch cannot forget the owner’s name and ask for it three times. An incomplete draft is let through, so the conversation keeps moving while the plan fills in. And a key the parser refuses is dropped rather than refused, because a small model that pastes its own notes into the plan should not stall an interview. With those, qwen3:8b built a four-need contractor site in seven turns; what it got wrong (one mention of a safety officer became the whole office) is now a gap the checker names, so the next question asks who the desk’s people are.

What the interviewer puts right by itself. Sixty test interviews on qwen3:8b showed where the turns went: into the interviewer’s own draft, and into asking the owner again what they had answered. Four of the checker’s complaints are now settled as the draft is merged, and never reach the owner:

  • A field budget below what the form already asks is raised to it, up to five. The budget is the interviewer’s guess, and no owner has heard of it.
  • An ending that is no stage goes when another ending is one. When none is, the case ends at its last stage.
  • A role whose words are in the owner’s own answers is described: it joins groups under those words. A role they never spoke of is still asked about.
  • A question the owner has answered is not put to them a third time: told it repeats and repeating all the same, the interviewer keeps its draft and asks about the checker’s biggest gap.
  • That gap is put to the owner in their own words and language: the case as who comes and what they want, then what is open about it (“Housing boards: a survey of the building. Who with you takes care of that?”). The checker’s own line names a need by its id and a key by its name, which is the model’s to read. Each time it is the next gap that has not been asked about; with all of them asked, what else a normal week holds.

On twenty test businesses, three passes each, the first four of these took the interviews from 99, 98 and 105 turns to 75, 84 and 97, and “the role has not been described” from 19, 56 and 115 lines to 0, 3 and 8. The pass of 97 held an interview that ran out of turns over endings none of which was a stage, which is what the last-stage rule was added for, and one where the model never wrote the stages the owner had told it. Ending as the kit does (--brief-only), one pass went from 184 turns and 12 confirmed briefs of 20 to 147 and 14. What this does not reach: an owner who corrects the readback three times leaves with no brief, and nearly every such correction is about a desk the interviewer named in words the owner never used.

A confirmed draft is a plan. The checker above is not the builder: an owner could say yes to a draft that bratac build then refused, over things no owner is read. Of 46 drafts confirmed in four passes over the twenty test businesses, 15 were refused, on five rules. Each is now put right as the draft is merged, before the owner is read it:

  • What went well is one of the endings. A stage on the way (resolved, on a case that ends closed) leaves the good endings; which ending is the good one is never guessed.
  • The stage a case starts in is no ending.
  • Needs in one bucket are one kind of case. A need whose stages, endings or desk differ from the first in its bucket gets a bucket of its own, named after the need; so does one whose bucket is named after a stage.
  • A role is in groups once, under an id: “board’s upkeep parent” written where an id goes becomes one, keeps its spelling as the label, and a second entry for the same words is folded into the first. A need’s id, a bucket and a field’s name written as words are ids of those words.
  • A kind of field the builder has not (time) is one the person types.

All 46 build with these, and 142 of 143 confirmed drafts from every pass (the one left has no desk for a need). The kit’s job does the same to the draft it is handed (put_right), so a brief confirmed earlier builds too; what a draft lacks is never added, and a draft that is no plan still fails as before.

A run leaves transcript.md, every prompt and reply under llm/, and transcript.jsonl: one line per turn with the question, the answer, the gaps and the draft. That file is the training set for an interviewer of our own; it grows one real owner at a time.

From a conversation to a site

The kit puts the steps above in the order a business owner meets them. They talk with a medium model and are told “we’ll email you”; a large model writes the plan in the background; portal builds the site, lints it and draws its map; and the owner gets a mail with the map and a link to look at the site. Nobody waits on the large model.

bratac interview --human --brief-only --out runs/wagtail --lang en \
    --llm "MODEL=qwen3:8b engines/ollama.sh" [--enqueue <site key>@<address>]
bratac job run runs/wagtail [--plan-llm 'cmd'] [--mail-to addr]
bratac job worker --site <site key>@<address> --dir /data

The interview ends in a brief. With --brief-only the conversation is the one above, gaps, checker and all, but when the checker is satisfied the plan is read back in plain sentences and the owner is asked to confirm it (“Is that right? Answer yes, or tell me what to change”). A plain yes is read without a model; anything else is the model’s to judge, and a yes with a correction is not a yes. A correction is one more turn: the model takes it like any answer and the readback comes again. On a yes, brief.json is written: the business, the owner’s name and address, the language, the facts the checker saw settled, the readback they said yes to, the conversation, and the last draft as a starting point, under a job id like 20261027-wagtail-grooming-3f9a1c. The owner is thanked and told they will hear at their address. The opening question, the readback and the thanks are in Norwegian when --lang is no, nb or nn.

Who else comes. The checker only knows the people already named, and in the pitch sketches of 2026-10-28 the interview stopped at two and three needs where the owners had named seven and five. So before the first readback the owner is asked who else gets in touch and what they keep track of that nobody sends them, with the kinds of person heard of so far; an answer that brings a new need is followed by the questions its gaps raise and then the same question again, until an answer brings nothing new (never on the last turn, which belongs to the readback). The readback then lists every need on a line of its own with the role that handles it, by the label the owner gave it, under the model’s sentences. The interviewer calls the place what the owner calls it (a borettslag, a café, a club), never “the business” or “bedriften” unless it is one; the opening question names no kind.

A model owner is not a yes-man. A model playing the owner (--person) said “Ja, det stemmer” to a readback that put every case with the wrong people. Its prompt now has it compare a readback with its intake first, and the harness holds it to that: a yes, however it goes on, to a readback whose draft has a handling role that the intake’s who_is_involved never names, or fewer needs than the sentences of its who_comes_to_us, counts as a no, and the owner’s answer becomes the correction the intake gives. A person at the terminal or on the web is never second-guessed.

--enqueue <site key>@<address> queues the brief on that site then and there, with the terminal’s own key (KIT_KEY, else ~/.config/portal/kit.key, which the site names <key>=kit); without it, bratac job run <dir> runs it by hand. Every line of transcript.jsonl now also says how long the owner waited for the next question (interviewer_s), and a line answering a readback carries confirmed.

The job is plan, build, the lint, map and the mail, in that order, in-process, each step moving the job’s stage on (queued, planning, building, linting, mapping, mailing, done, or failed from any of them) and rewriting result.json with the stage, the seconds each step took, the lint’s counts by code, and the paths. The plan is written from the brief rendered as an intake (intake.md: the owner’s words, the readback, the settled facts, the conversation, the draft), by the large model with the rounds and checks plan already has; when it gives no plan (no round passed, or the call timed out), the fallback model is asked, and when neither writes one, the interview’s confirmed draft is built if it holds up to everything build checks (plan_llm says interview draft). The owner’s language and address go into the plan as the brief has them, whatever the model wrote. A failing lint finding fails the job: no mail goes out for a site the lint refused. The map is drawn as map.svg, and as map.png where rsvg-convert is installed; both are copied into the site, so the preview serves them at /site/map.png.

flagenvdefault
the plan model--plan-llmKIT_PLAN_LLM, or KIT_PLAN_MODEL on Ollamaqwen3.6:27b
its fallback--plan-fallback-llm (none)KIT_PLAN_FALLBACK_LLM, KIT_PLAN_FALLBACK_MODELnone
a call’s time limitKIT_PLAN_TIMEOUT (seconds)5400
plan rounds, per model--plan-roundsKIT_PLAN_ROUNDS4
the site’s words--words-llm (none for the builder’s own)KIT_WORDS_LLM, or KIT_WORDS_MODEL and KIT_WORDS_CTX on Ollamaqwen3:8b with NUM_CTX=12288 on Ollama; none on another engine
the engineKIT_ENGINEengines/ollama.sh

The plan can be another engine’s while the words stay on Ollama: KIT_PLAN_LLM is a whole command, so KIT_PLAN_LLM="MODEL=glm-5.3-flash TIMEOUT=5400 engines/llama.sh" writes the plan on a llama.cpp server at LLAMA_HOST (measured on ergo, 2026-11-26: GLM-5.3-Flash wrote a plan that parsed in two rounds of 14 and 11 minutes, at 2.3 tokens a second).

The mail is to the brief’s contact (or --mail-to), in Norwegian bokmål when the brief’s language is no, nb or nn and in English otherwise: a first draft is ready, a link to see it (KIT_PREVIEW_URL, where {id} is the job’s id for a preview per job), the map shown in the message and linked (KIT_MAP_URL, else the preview’s /site/map.png), that everything on it is checked by machine, and that a reply puts anything right. It is rendered into portal’s own mail contract (Mail) and goes to the site with the job’s end, which hands it to gdo like any site’s mail; that contract has no attachments, so there the map is shown from its link. Either way the same mail is written to the job’s mail.eml, with the PNG shown from inside the message and the SVG attached; in a kit with no gdo that file is the mail. The sender is KIT_MAIL_FROM (default uhhm <post@uhhm.no>), replies go to KIT_MAIL_REPLY_TO when set.

The queue is the site’s own. A brief is a record in the built-in bucket portal_kit, queued until its job ends, and the row written with it in the kit outbox is the worker’s: it serves kit over dhd/1 with a key the site names <key>=kit in DHD_KEYS, and says that key as it starts (<data>/kit.key, or KIT_KEY). One job runs at a time, because the large model is one slot. A row stays the worker’s until the site has taken the job’s end: a move to built or failed that carries what the record says (the preview, the map, an error), the job’s mails, and, for a job that waits for a yes, the desk it is filed on. A worker that stops mid-job is handed the row again, and a job that ended before finds its result.json and says its end again (word.json) rather than running twice. The site lets a kit key mail only the brief’s contact and the site’s own address. When a job is done the worker names it in <data>/preview.

The preview is a plain portal serve. bratac job content --root <data> answers the three Gitea calls portal loads content with (the tree, a file’s bytes, a file’s entry) from disk: repo kit/<job id> is <data>/jobs/<job id>/site, and repo kit/preview is the job named in <data>/preview. A portal started with CONTENT_REPO=http://127.0.0.1:3001/kit/preview therefore shows each new site as its job finishes, without a restart, where it is the site the worker serves (KIT_PREVIEW_LOAD=site, with load beside kit in its DHD_KEYS): the worker asks it to Load over its own call. One preview at a time.

The client’s place on Gitea, and the owner’s way in. With --gitea <url> (KIT_GITEA_URL) the interview also proposes a name for the site’s organisation, made from the business’s name (lowercase ASCII, æ as ae, ø as o, å as a, words joined by dashes, at most 40 characters, none of Gitea’s reserved names), and says it in the readback the owner confirms. Organisations and users share one namespace in Gitea, so both GET /api/v1/orgs/<name> and GET /api/v1/users/<name> must answer 404. When the name is taken the readback offers up to three free variants (-as, then numbers) and the owner picks one, or gives a short name of their own, which is checked the same way; when Gitea cannot be reached the name goes into the brief unchecked (org: {name, checked}), for the job to check. A private organisation is invisible to a token outside it, so the interview’s check is advice; creating the organisation is the last word.

The job then has a provisioning stage between the map and the mail. With KIT_PROVISION=auto it runs then and there when KIT_GITEA_URL and KIT_GITEA_TOKEN are set (the token is never logged); by default (approve) the job is filed on the site owner’s desk instead, and the same steps run once the owner approves (see The owner says yes):

  1. The organisation, private unless KIT_GITEA_VISIBILITY says otherwise, its description saying which job it was made for (kit job <id>). If Gitea refuses the name (someone else has it), or the organisation is there and was not made for this job (another caller asked for the same name, or the bot is in it for another reason), the first free variant is taken and result.json says which name was asked for (org_asked).
  2. <org>/questions with the built content: site.yaml, questions/, aggregates.yaml, needs.yaml, words.json, map.svg, a README in the owner’s language, and two workflows modelled on uhhm’s content repos: lint-and-reload.yml (the lint at the pinned release, then a Load of the commit that passed) and deploy.yml (the pinned PORTAL_RELEASE, the service env, the unit, the Caddy route). Nothing secret is committed: the deploy names the variables and secrets a person fills in (PUBLIC_URL, SITE_HOST, PORTAL_PORT, KANIDM_URL, OAUTH2_CLIENT_ID; LOAD_TOKEN, OAUTH2_CLIENT_SECRET, KANIDM_API_TOKEN, and on the host the unit’s StateDirectory= drop-in) and refuses to run until they are there, and the README says so.
  3. <org>/infra: compose.yml (portal from the release tarball, its store on a volume of its own, the portal port on 127.0.0.1), its Dockerfile, env.example, a README and a .gitignore for .env.

All of it is idempotent: a job run again finds its organisation (the token’s user is a member, and the description names the job) and its repos, and commits only the files whose content changed (compared by git blob id), in one commit, or none. result.json gets provisioned: the organisation, the repo URLs, how many files each run changed.

With KANIDM_URL and KANIDM_API_TOKEN set, the stage also gives the owner a way in, through the same Kanidm client portal’s own invites use: the person is found by their address, or made, and put in KIT_DEVELOPER_GROUP (default developers) and in <org>_owners (both made when missing); someone new gets a link to set their own password or passkey. KIT_INVITE_TTL asks for its lifetime (default 7 days); Kanidm 1.11 gives at most one day, and the mail and result.json (invite_expires, invite_seconds) say what it gave. The link goes in the mail and nowhere else. The mail says the way in, and where the source is only when KIT_MAIL_SHOW_SOURCE=true.

Gitea makes an account at a person’s first sign-in through Kanidm, so the owner cannot be put in their organisation’s Owners team before that. The job leaves a pending grant (grant.json in the job’s directory: the organisation, the team, the Gitea name to expect, until when), tries it once at once, and the worker looks again every 30 seconds for the first hour and every five minutes after, until the person is there or the link has run out; bratac job grants --dir <data> does one round by hand. Gitea names the account after the local part of Kanidm’s preferred_username (maddie@id.example becomes maddie), which is the Kanidm name the invite made. This was chosen over the two others after trying them against a throwaway Gitea 1.27.3 and Kanidm 1.11.2:

  • A groups claim with Gitea’s group-team map (<org>_owners to the organisation’s Owners team) needs the claim on Kanidm’s Gitea client and the auth source’s whole map rewritten for every new organisation, which Gitea only does from its own CLI (gitea admin auth update-oauth) on the Gitea host: a job would need a shell there.
  • Making the Gitea account first and letting ACCOUNT_LINKING = auto link it at the first sign-in needs a site-administrator token for the job, and access by a matching name or address is exactly what that setting warns about.
  • The pending grant needs only an organisation owner’s token (the bot that made the organisation is one) and the REST API, and a sign-in before the grant is no harm: the person sees nothing until they are in the team.

To have this on uhhm’s Gitea and Kanidm, the user (not the kit) creates:

# Gitea: a bot account for the kit, and its token (the scopes the job uses).
# In the official container, run the CLI as its git user with its config:
#   docker exec -u git gitea gitea --config /data/gitea/conf/app.ini admin ...
# A --random-password account is created "must change password", and Gitea
# refuses every API token of such an account until the flag is cleared.
gitea admin user create --username uhhm-kit --email kit@uhhm.no \
    --random-password --must-change-password=false
gitea admin user generate-access-token --username uhhm-kit --token-name kit \
    --scopes write:organization,write:repository,read:user --raw
# Kanidm: a service account for invites and groups. Managed by the
# idm_admins group, so an idm_admins member (not only idm_admin) can
# handle it, and its token is made BEFORE it joins the admin groups:
# once it is in them it counts as high-privilege, and only idm_admin or
# admin may issue its credentials.
kanidm service-account create kit-bot "uhhm kit" idm_admins
kanidm service-account api-token generate kit-bot kit --readwrite
kanidm group add-members idm_people_admins kit-bot     # make people, reset links
kanidm group add-members idm_group_admins kit-bot      # make developers, <org>_owners
kanidm group add-members idm_people_pii_read kit-bot   # find a person by address

and sets KIT_GITEA_URL, KIT_GITEA_TOKEN, KANIDM_URL, KANIDM_API_TOKEN (and KIT_DEVELOPER_GROUP if not developers) on the worker. Where these come from a content repo’s Actions secrets, name the secrets so they don’t start with GITEA_ (Gitea refuses such names) and don’t collide with the site’s own: uhhm’s deploy maps secrets.KIT_KANIDM_API_TOKEN onto the worker’s KANIDM_API_TOKEN. Nothing on Gitea’s or Kanidm’s own configuration has to change: the Gitea client already maps idm_all_persons to openid profile email, and auto-registration is on. A Kanidm behind a private CA is trusted through PORTAL_EXTRA_CA.

The interview on a site

The same conversation can be had in a browser, in a card of a portal site that declares it (interview: on an alternative, see Content reference). A line says that a model asks the questions, that the conversation is kept to build the visitor’s site, and that it is not used to train models unless they are asked first; then the question, a box and Send.

One step, two front ends. trainer::interview::step takes one answer and moves a State on (the draft, the turns, the readback waiting for a yes, the organisation’s name): bratac interview calls it in a loop at the terminal, and the site calls it once per answer. On the site the step runs in the background: the answer is posted (interview_send), the card says it is thinking, and the browser asks (interview_state) every three seconds until the next question is there, so nothing in front of portal holds a request open for the 20-60 seconds a turn takes on qwen3:8b. Between answers the conversation waits in the site’s store (portal_interviews, kept 14 days after its last answer) under a random id; the address bar carries ?interview=<id>, and that link brings a closed tab back to where it was. A turn lost to a restart is offered the address form after twenty minutes.

The yes. The readback and the confirmation happen in the chat, as at the terminal. On the yes the brief is written to the conversation and queued in the site’s store (a portal_kit record from the card’s page), and the visitor is told “We’ll email you when your map is ready, at <address>”. The page’s responsible contact (else site.yaml’s mail.reply_to, else mail.from) gets a note with the readback, the settled facts, the conversation and the job id: the owner hears about every caller.

Guard rails, beside portal’s per-caller rate limit:

envdefault
conversations under way at onceINTERVIEW_MAX_LIVE6
of them from one addressINTERVIEW_PER_CALLER2
answers in one conversationINTERVIEW_MAX_ANSWERS16 (and the engine’s 12 turns plus the yes)
characters in one answerINTERVIEW_MAX_CHARS2000
model turns at once (the rest wait up to four minutes)INTERVIEW_PARALLEL1

When the model does not answer (it is then thought out of reach for a minute, and new conversations go straight to the form), when no turn with it comes within four minutes, when the caps are full, or when the conversation runs out of turns or readbacks, the visitor is offered to leave their address and a line instead (interview_leave), and the contact gets that request with whatever was said. Answers are never logged; the log says how a turn went.

The model. Content names it (interview.model, else INTERVIEW_MODEL, else qwen3:8b); the instance runs it: INTERVIEW_LLM is a whole command, else INTERVIEW_ENGINE (else KIT_ENGINE, else engines/ollama.sh from the release, which now ships engines/) with MODEL, NUM_CTX=12288 (INTERVIEW_NUM_CTX) and TIMEOUT=180 (INTERVIEW_TIMEOUT), and Ollama at OLLAMA_HOST. English only for now: the language is a parameter (interview.lang, else the site’s lang), and the chat’s own words have one place to be translated (interview::words).

A worker beside the site. The queue is the site’s own, so a worker on the same host takes the jobs with the same release: bratac ships in it beside portal, and started bare it runs what PORTAL_COMMAND says, so a second app@ instance whose ExecStart is the release’s bratac, with PORTAL_COMMAND=job worker --dir /srv/app/<instance>/data and PORTAL_DHD=<site key>@127.0.0.1:4300, is the worker; the site names its key in DHD_KEYS as <key>=kit. Without provisioning (no KIT_GITEA_URL/KIT_GITEA_TOKEN) and with KIT_PREVIEW_URL=none, the mail to the visitor shows the map and says we will be in touch about setting up the site, and the worker switches no preview. With KIT_MAPS_DIR set to the worker’s data directory, the site serves each job’s map at /kit/map/<job id>.png, which KIT_MAP_URL=https://<site>/kit/map/{id}.png puts in the mail.

The owner says yes

A public interview is open to anyone, so on a site the kit does not make anything for a caller on its own: no organisation, no repos, no account. The caller gets their map by mail as before; the job is filed on the site owner’s desk, and the organisation, <org>/questions, <org>/infra, the Kanidm invite and the Owners grant after the first sign-in come only after the owner approves.

KIT_PROVISION says which:

KIT_PROVISIONat the end of a job
approvefiled on the owner’s desk; set up when they approvethe default when Gitea or Kanidm settings are there
autoset up at once, as the kit always didfor a private kit whose callers are known
offnothingthe default with neither

The owner’s desk is a bucket in the site’s own store. The worker files there and hears of each approval through the site, over dhd/1; it never opens the store.

A value it does not know is read as the default, never as auto. With approve and no KIT_GITEA_URL/KIT_GITEA_TOKEN, jobs are still filed, and an approval moves to failed with “provisioning is not configured” (Kanidm alone gives an account nobody can use).

On the desk. The site’s content declares the bucket and puts a card over it on the owner’s desk. In aggregates.yaml:

  - bucket: kit_jobs
    attended_by: the kit worker (bratac job worker), which files finished jobs here and sets up the approved ones
    initial: awaiting
    states:
      awaiting: { event: filed }
      approved: { event: approved }
      declined: { event: declined }
      provisioned: { event: provisioned }
      failed: { event: failed }
    transitions:
      awaiting: [approved, declined]
      approved: [provisioned, failed]
      failed: [approved, declined]

and on the owners’ desk (questions/review/index.yaml on uhhm.no, under qualifies: owners):

  - name: Sites to set up
    description: >
      Each one had the conversation and has their map. Nothing is made
      for them until you approve: then their organisation and repos,
      and a way in by mail.
    action: /review
    consequence: [Confirm]
    features:
      - name: ""
        description: ""
        resource:
          source: { bucket: kit_jobs }
          requires_group: owners
          transitions:
            - { from: awaiting, to: approved, label: Approve and set up }
            - { from: awaiting, to: declined, label: Decline }
            - { from: failed, to: approved, label: Try again }
            - { from: failed, to: declined, label: Decline }

The card offers no move out of approved: the access policy, compiled from the desk, gives no person and no visitor approved -> provisioned or approved -> failed, and no form fills the bucket. The worker makes those two moves itself, through the site with its kit key, which the site takes only for a job the kit filed and only out of approved; the event says by: kit. The bucket’s name is KIT_APPROVAL_BUCKET (default kit_jobs), and the site files nothing in a bucket that does not start in awaiting or lacks one of the moves above.

The record. The site files it with the job’s end, under the job’s id, in the answers outbox like a form’s answer: business, name and email of the caller, org (the organisation name they confirmed, or the one proposed from the business), map (the link the mail shows), job, and needs (one line: who comes and what they want). A job said again is not filed twice. result.json says filed: {bucket, record}. The site’s owner gets a note, “Kit: <business> is waiting on your desk”, with the same and a link to the desk (KIT_APPROVAL_DESK). The owner is KIT_OWNER_MAIL, else KIT_MAIL_REPLY_TO, else KIT_MAIL_FROM, and has to be one of the site’s own addresses (site.yaml’s mail.from or mail.reply_to): the site lets the kit mail nobody else but the caller.

The yes. The owner’s move to approved hands the job to the worker in the same batch, as a row in the kit’s outbox, so it reaches the worker at once and waits for it when it is down or busy with an hour-long plan. Beside whatever job is running, the worker reads the brief and checks the job finished, runs the provisioning steps above (the organisation name is checked again, and a free variant taken when someone has it now), and settles the record in one move: to provisioned with outcome and site on it (never the link), the caller’s mail with where their site lives (<gitea>/<org>, the two repos) and their way in, with when the link runs out, and the owner’s one line: “Wagtail Grooming is set up as https://git.example/wagtail-grooming; the invite went to maddie@wagtail.example, its link works until …”. When anything fails, the record goes to failed with the reason in outcome, the owner hears it in one line, and the desk offers “Try again”. The mail to the caller is also written beside the job as setup.eml.

An approval is set up once: approval.json beside the job says which approval it was (the row that handed it over), what came of it, and holds the caller’s mail until the site has taken it, so one handed over again is only settled, and a record approved again after a failure is another round. A settling move the site cannot take yet is said again until it can; nothing is set up twice, so no second link is minted. One worker per site.

A job the desk cannot take (the site’s content does not declare the bucket, or not as above) still mails the caller their map: the worker says the job’s end again without filing it, result.json says filed.error, and the owner gets “Kit: <business> is not on your desk” with the reason. bratac job run by hand has no desk: with approve it says so and sets nothing up. The standalone kit (kit/compose.yml) is a private one and sets KIT_PROVISION=auto.

A job that finished before its site asked for the owner’s yes (or one whose filing failed) is put on the desk with the worker’s settings, without planning or building it again:

bratac job file <job id> --dir /srv/app/uhhm-kit/data --site <site key>@<address>   # or the job's directory

It goes in as awaiting like a job that ends today, the owner gets the same note, and result.json says filed. It refuses a job that is not done, was set up already (provisioned in result.json), has been approved (approval.json), or is on the desk already. It dials the site with the terminal’s key, which the site names <key>=kit; the site keeps the job as a brief that built, from the brief beside it.

Which models, measured 2026-10-27 on ergo (8 GB GPU, 28 cores) with two fictional owners (an English dog groomer, a Norwegian bike workshop) played by granite4.1:8b on the CPU, so the interviewer kept the GPU:

interviewerownerseconds per turn (median, range)outcome
nemotron-3.5-lightning:30b-a3ben24 (11-32)never wrote a need in 14 turns
nemotron-3.5-lightning:30b-a3bnb35 (16-42)never wrote a need in 14 turns
qwen3:8b, 32k contexten76 (24-97)confirmed brief, 7 turns, 2 corrections
qwen3:8b, 32k contextnb64 (27-134)confirmed brief, 8 turns, 2 corrections
qwen3:8b, 12k contexten24 (16-33)confirmed brief, 4 turns
qwen3:8b, 12k contextnb43 (7-83)three readbacks corrected, no brief

qwen3:8b with NUM_CTX=12288 is the kit’s interviewer (kit/interview.sh); at 32k its context no longer fits the GPU and a turn takes three times as long. For the plan, mistral-medium-3.5:128b on the CPU took 28.6 and 25.5 minutes for two rounds and passed neither (a front-door card for a group, a form over its budget); qwen3.6:27b passed on its fourth round for the English brief (27 minutes, beside an image build) and on its second for the Norwegian one (15 minutes), so qwen3.6:27b is the kit’s plan model and the 128b is only used when named (KIT_PLAN_MODEL, or as the fallback with KIT_PLAN_FALLBACK_MODEL). The words for a three-need site take qwen3:8b about three minutes, with the same 12k context (NUM_CTX=12288) the interviewer has.

In containers, kit/Dockerfile builds portal (with its site bundle) and learn from the checkout and ships them with engines/, jq, curl and rsvg-convert as a non-root user, data on /data. kit/compose.yml runs one container: the kit’s site, which keeps the queue and shows the newest finished job on 127.0.0.1:8090, and the worker beside it, dialling it over dhd/1. The interview is docker compose -f kit/compose.yml exec kit /app/kit/interview.sh with a person at the terminal (KIT_LANG=nb for Norwegian). Models are read from OLLAMA_HOST, by default the host’s Ollama through host.docker.internal.

Changing a site from a conversation

The person a page names as responsible (see Content reference), signed in, finds “Suggest a change to this page” at its foot. On an instance with EDIT_GITEA_TOKEN that card is a conversation which ends with the change applied to the site’s content repo, after their yes and a thorough check; without the token it is the plain form it was (the suggestion becomes a case for whoever keeps the site, and the card says changes are not applied from there). The server checks on every call that the session is the page’s responsible person, as the plain form does.

The conversation. The site’s interview model (EDIT_TALK_MODEL, else INTERVIEW_MODEL, else qwen3:8b, run as the interview is) reads the page’s file as it is on main, aggregates.yaml and needs.yaml when there is one, and asks one question at a time until the change is clear: what to add, change or remove, where, and in whose words. It never shows the person YAML. It may take EDIT_MAX_ANSWERS (10) answers of EDIT_MAX_CHARS (2000) characters; on the last it must say the change as well as it can. When the model does not answer, nothing changes and the person is asked to send the answer again, or to send what was said as a plain suggestion instead.

The draft. When the change is clear, a larger model (EDIT_MODEL, default qwen3.6:27b, at EDIT_NUM_CTX 32768 and EDIT_TIMEOUT 1800 on the same engine; EDIT_LLM is a whole command) writes it in the background as edits to the content files: a few lines found and replaced, a new file, or a file removed. It reads the agreed change, the conversation, a short form of this reference, the page, its cards’ ids, aggregates.yaml, needs.yaml and the other pages (whole while they fit in 48 KB). Only pages under questions/, aggregates.yaml and needs.yaml may be written; never site.yaml, the workflows or anything else. The edits are resolved to whole files against main and the result is linted; a miss (text not found, a file it may not write, something the lint fails) is told to the model, EDIT_DRAFT_ROUNDS (3) tries at most. The card says “Drafting your change…” and the browser asks every four seconds; the person may leave and come back.

The read-back. Both sides are loaded as the lint loads a checkout and compared, and the card shows, in plain words: the model’s summary; what changes (questions, cards, fields with their kind, buttons on desks with the move they make, lists, states and moves in the graphs, who may open a page, who is responsible); who gains or loses access, from the access policy the site would compile before and after (access::Policy::from_content, rule by rule: “Anyone may now open /desk and send its forms”, “Members of board may no longer move cases in applicants from open to invited”), and who a state puts into a group or takes out of one (grants:, revokes:), or “Nobody gains or loses access”; links that would stop landing (a card id or a page that would be gone, an in-site link that would break); what the lint would newly warn about; and iris map before and after, side by side (one under the other on a phone), each opening full size. Then “Apply this change”, “Not quite” (back into the conversation, which asks what should be different) and “Withdraw”.

Words, or how the work goes. What happens on the yes depends on what the change is, and that is read from the change itself, never asked of a model (edit::kind):

the changeon the yes
only words a person reads, only on the asker’s own pageapplied: checked, committed, merged by portal, and theirs to undo
anything elsehanded over: the same draft as a PR for whoever maintains the site, which portal does not merge
anything, asked by a member of portal_maintainerapplied

Words are a question’s heading and text, a card’s heading, text, button and the lines under it, a feature’s heading and text, a field’s label, placeholder and the words for a pattern, a list’s empty line and a desk button’s label. Everything else is how the work goes: a field’s kind or stored key, where a card leads, what a list reads, who may open or see something, a state graph, another page, a new link out of the site, a storyline more or fewer. A rewording that would change who may do something, or where a link lands, is not only a rewording.

A change handed over says why (“It changes more than words: …”) under the read-back, and its button says “Send it to whoever maintains the site”. On the yes it is checked as any change is, the PR is opened, the site’s inbox is mailed with the read-back and the PR, the case rests in handed, and the page is free for the next change. The site looks in on the PR every ten minutes: merged, the person is mailed as for any applied change and the undo is theirs; closed, their case says so.

portal_maintainer is a group like any other: an invite or a state puts people in it, a site’s mfa_groups may hold it to a strong sign-in, and EDIT_MAINTAINER_GROUP names another group for the role. Its members still open the box only on pages they answer for.

The check, after the yes, on main as it is then:

  • a file the change touches has changed since the draft: refused;
  • size: at most 8 files, 64 KB a file, 256 KB in all;
  • the schema, the lint’s failures and the structure needs.yaml asks for (everything iris check --path questions says), counting only what the change brings, plus the repo’s CI command itself (iris check --path questions, run with this binary or EDIT_LINT_BIN) when a workflow runs it;
  • access: every rule it adds must be one the read-back showed;
  • links: a card id it removes must have been shown, and no in-site link may break;
  • live cases: for each state (or whole graph) it removes, the records in that state are counted in the site’s store; any at all refuses it, since a changed graph never rewrites a record (see State machines) and they would stand where nobody can move them.

New warnings are listed and do not refuse it. A refusal goes back into the conversation in plain words (“The check stopped it, so nothing changed: 2 cases in applicants are still invited. …”).

The commit and the merge. A branch suggest/<id> is made at the very commit that was checked, the change is committed on it in one commit with the person as author (name and address from their session) and the token’s account as committer (EDIT_COMMITTER_NAME/_EMAIL to name another), and a PR is opened with the read-back as its description. Portal merges it itself: every ten seconds the site’s sweeper reads the PR, the statuses on the commit, main’s head and main’s protection, and decides (edit::merge::decide):

  • a repo whose workflows run on pull_request is waited for until at least one check has reported and all have passed, and every context main’s protection requires is among them and green;
  • a repo with no checks on PRs merges on portal’s own check;
  • a failed check, a PR closed on Gitea, a push to the branch by anyone else, or a PR that no longer merges cleanly ends it: the PR is closed with the reason and the conversation goes on;
  • when main has moved, the check runs again on main as it is now with the change on top, and only then does it merge, so what lands is what was checked;
  • the merge names the checked commit (head_commit_id), so Gitea refuses it if the branch moved; nothing waits longer than EDIT_CHECK_MINUTES (30).

Gitea’s own “merge when checks succeed” was not used: without branch protection it merges at once when no check has reported yet (the CI run starts a moment after the PR opens), it would merge whatever main had become, and nothing would tell the person when a check failed. The content repo’s lint-and-reload then lints main and loads the content into the site, as for any push. The card says “Waiting for the site’s own check…” with a link to the PR, then “Applied”, and the person gets a mail with the summary and the PR (mail::suggestion_words, applied); the site’s inbox gets a line too.

The record. The first draft files the change as a case in portal_edit_suggestions, as the plain form files a suggestion (name, email, by, page, question, text with the agreed change, talk), and portal moves it through the bucket’s built-in graph: drafting, awaiting_yes, checking, then applied (with summary, readback, pr and commit), failed (with reason; the conversation goes on and the next draft moves it back to drafting) or withdrawn, and applied to undone. The states are only added to the graph, so every suggestion filed before fits it. “What you have suggested here” lists them with their state. The conversation itself (turns, the change as whole files before and after, the read-back, the PR) waits in the site’s store (portal_edit_talks, 180 days; never the person’s words in the log), the maps in portal_edit_maps (30 days), served only to the person at /edit/map/<id>/before.svg and after.svg.

Undo. Once a change of theirs is applied, the card offers “Undo my last change”: the same change turned round (each file back as it was), read back, and on the yes through the same check, PR and merge. When a file it touched has changed again since, it is refused, and the person is asked to say what should change instead. An applied undo moves the change it undid to undone, and “Undo my last change” then offers the change before it.

Guard rails. Only the responsible person, checked on the server on every call and for the maps; one change at a time per page (another responsible person is told someone is changing it; a change left waiting on its person for two hours lets go of the page); the turn and length caps above; one model turn and one draft at a time per site; a model that fails, a check that refuses and a Gitea that does not answer each leave the content as it was. A restart takes up a turn, a draft, a check or a waiting PR where it was.

Measured 2026-10-27 on ergo, a scratch copy of uhhm.no’s content on a throwaway Gitea, qwen3:8b and qwen3.6:27b on the local Ollama: a turn of the conversation took 13 to 17 seconds (under a minute when the model had to load first), and a clear first answer was enough for a change of one card; the drafts took 140 to 265 seconds (one file for a new field, three for removing a state with its desk buttons and a follow-up’s feature), each usable on its first round; the read-back took under a second; from the yes to “Applied” took 11 to 14 seconds with a CI that reports a few seconds after the PR opens. Removing invited from applicants while two cases were in it was refused by the check with the count, and nothing was opened.

Credentials. A token that can push a branch, open a PR and merge it on the site’s content repo, and nothing else. For uhhm.no the kit’s bot uhhm-kit can be that account; the user (not portal) would:

# 1. uhhm-kit as a collaborator with write on uhhm/questions
#    (Gitea: uhhm/questions -> Settings -> Collaborators -> uhhm-kit, Write), or:
curl -X PUT -H "authorization: token <an owner's token>" -H 'content-type: application/json' \
  https://project.uhhm.no/api/v1/repos/uhhm/questions/collaborators/uhhm-kit -d '{"permission":"write"}'
# 2. a token for it with only what this needs
gitea admin user generate-access-token --username uhhm-kit --token-name edit \
    --scopes write:repository,read:user --raw
# 3. if main is protected with a merge whitelist, add uhhm-kit to it; keep
#    "Lint and reload / lint (pull_request)" as a required status check
# 4. the token as the secret EDIT_GITEA_TOKEN in uhhm/questions
#    (Settings -> Actions -> Secrets), and in deploy.yml's service env:
#      EDIT_GITEA_TOKEN=${{ secrets.EDIT_GITEA_TOKEN }}
#    with a PORTAL_RELEASE that has this feature

CONTENT_REPO and CONTENT_BRANCH name the repo, as for loading the content. The token reads the content at a commit, makes branches and commits on the repo, opens, comments on, closes and merges PRs, and reads main’s protection; it never touches another repo.

How it works

 intake (plain words)
    │
    ▼  phase 1                       frozen after this phase: the generator
 needs.yaml ───────────────────────  may not weaken the spec to pass
    │
    ▼  phase 2   ◄── iris findings, until it exits 0
 aggregates.yaml + questions/** + desks
    │
    ▼  phase 3   ◄── misroutes from a blind visitor model
 wording
  1. Needs. The intake becomes needs.yaml: one need per kind of person and thing they want, including the roles inside the business. Each names the bucket the answer lands in, the group that handles it, the states that count as finished, and the effort the visitor will tolerate.
  2. Structure. Pages, state machines and desks are generated, then revised against the lint, iris check, until every need is met: a path within budget, a desk held by the right group, every state of every bucket reachable and none stranding a record. The page-writing model sees the needs and never the personas. Each round the lint writes its findings with stable ids (--findings, kept in <out>/findings/round-N.jsonl), and the round is logged as what it fixed, what is still open, what is new and what it reopened. A fix round is shown only the open findings, each with the change that closes it, and the files they name (the whole repo when a finding is about getting around the site). A change that reopens a closed finding is undone and the model told what it broke. A round that closes nothing, or leaves as many open as it found, ends the phase: what is left is written to run.log rather than polished at again.
  3. Wording. A separate model plays each persona, blind, first with headings only and then with descriptions. A misroute is a wording defect and goes back to the generator; a visitor who chose right but hesitated is reported and rewrites nothing by itself. A rewrite that breaks structure is reverted.

Model output is only ever written to aggregates.yaml, site.yaml and questions/**.yaml inside the output directory.

bratac generate --intake intakes/contractor.yaml --out out/nordvik \
    --lint "portal lint" --llm engines/ollama.sh
bratac answer --tasks tasks.jsonl --llm engines/ollama.sh > answers.jsonl

answer puts one task per call to the visitor model, with the options shuffled per task and the call seeded from the task id: no visitor sees another visitor’s situation, a heading’s place on the page cannot carry the answer, and a rerun on the same site is the same experiment. The earlier runs under runs/ answered all tasks in one prompt.

The verifier is iris, the lint: it reads portal’s own content types and ships in every portal release, so a generated repo’s CI keeps enforcing its needs after handover.

LLM backends

A backend is any command that takes a prompt on stdin and prints text.

BackendUse
engines/ollama.shLocal Ollama. MODEL=qwen3:8b answers a task in about two seconds on ergo’s GPU and is the default visitor. Generation wants a larger model (MODEL=qwen3.6:27b), which runs mostly on CPU there.
engines/llama.shA llama.cpp server (llama-server), or anything else that speaks OpenAI’s chat completions, at LLAMA_HOST (default http://127.0.0.1:8081). For a model Ollama does not run well: a large mixture-of-experts model whose experts stay in RAM. MODEL is the name the server serves under; the context is the server’s own (-c), so NUM_CTX is not read.
engines/claude.shClaude through Claude Code’s own login (a Max or Pro subscription), no API key. MODEL=sonnet or opus, EFFORT=low by default. It drops any ANTHROPIC_API_KEY from the environment, because a key outranks the login and a stale one fails every call. Log in once with claude auth login.
engines/anthropic.shThe Anthropic API, given a working ANTHROPIC_API_KEY from the Console. That is separate, prepaid billing; a subscription does not cover it.
engines/mailbox.shWrites each prompt to a directory and waits for a reply file: drive the generator from an agent session, or by hand.

The visitor and the generator should be different models. A model grading its own wording agrees with itself.

The onboarding site

portal-portal/ is the front end of this: a portal content repo whose front door is the intake interview. A submission lands in onboardings (open → drafted ⇄ revising → live | declined) and is worked from an owners’ desk. Today the desk step is a person running generate and sending the link; the intake record already carries every field the generator reads, so the step that remains is a program taking the answers outbox that runs it and pushes the draft to a new repo. It passes its own needs.yaml.

The whole card, not the heading

A visitor never sees a bare heading and description. Portal renders a card: a button, an encouragement, one or more sections each with an icon, a title and a line of guidance, and the fields with their labels and placeholders. Since 2026-09-23 the builder fills all of it and the scorers read all of it.

  • Slots. Beside the heading and description, each form alternative gets a button, an encouragement, an icon, a form title and guidance line, and a placeholder per field. A door gets an icon and a “for whom” line. Icons are picked from a fixed list of Iconify lucide names; anything else is dropped.
  • Context from the plan. Every form alternative also carries two sections built from what the plan already knows, before the form: what happens next (the stages, in order, as one sentence) and who reads it (the handling group and the contact). Their fallbacks are true before a model has written a word; the model rewords them.
  • Scoring. answer --repo <content dir> shows the visitor each option as its whole card (headings-only tasks stay headings only). rate --repo does the same and asks a fourth question, “where”: do you know where you are, who this is for, and what the button does. All four are controlled against the gutted twin.

Scoring a built site

bratac score --site out/nordvik --out out/scored \
    --iris /var/local/cargo-target/release/iris \
    --llm "MODEL=qwen3:8b engines/ollama.sh"

One command for the whole grading, which every run under runs/ before 2026-09-23 carried as its own score.sh: iris writes the visitor tasks and the simulation model, the blind visitor answers them with descriptions and with headings only, iris scores the answers (the misroutes are printed), and rate reads the cards. The two routing numbers land in summary.json, the rating in rated/rate.json. --routing stops after the two routing numbers: what a round of mending a wording is scored on, at a fraction of the visitor’s calls. The pieces still run alone: answer --tasks for one visitor model against tasks iris wrote, and:

iris check --path out/nordvik/questions --needs-sim model.json
bratac rate --model model.json --out out/rated --repo out/nordvik \
    --llm "MODEL=qwen3:8b engines/ollama.sh"

How sure the wording makes a visitor: --seeds N. One run of a small visitor model is noisy: about one persona in a round changes its mind on nothing but the seed. With --seeds 5 the visitor answers every task five times, each with its options in another order, and the score is how the five split:

SPLIT: anna@/: right 0.80, the rest to "Join a group" 0.20
brier: 0.110 over 5 seeds (0 is every seed right)
wording: 7/8 routed right (88%)
  • brier is the mean over tasks of the squared share of seeds that went wrong: 0 when every seed of every task routed right, 1 when none did. It moves when a wording gets steadier, which 7/8 cannot show. Compare two wordings on it.
  • wording counts a task right when most of its seeds were; half and half is wrong.
  • SPLIT names each task the seeds did not agree on and where the others went: the cards that read alike to that person.

summary.json carries seeds, and per mode brier and split beside right and of. What the model says of its own confidence is recorded in the answers and not scored. One seed (the default) scores as before.

One card that takes them all: DRAW. Each misroute names the card its visitor passed over, and five of them read like five wordings to mend. Often it is one: a card wide enough that visitors of several needs see themselves in it.

DRAW: on / the card "someone qualified to come and look at it and say
  what it takes" took 2.3 visitor(s) of 2 needs (build-enquiry,
  warranty-claim): its wording is the one to narrow

A card is a draw when it took a visitor’s worth of picks or more (the shares of the seeds, added up) from tasks of two needs or more, none of which it meets. Narrow that card’s heading (in a plan, the wants of its need) before touching the cards the visitors passed over, and score again. One need’s visitors all going to one wrong card is left as misroutes: there the need’s own card is as likely the cause. Per mode, summary.json carries the cards as draws.

A heading that leans on its description: LEANS. A visitor who went right with the descriptions and wrong on the headings alone was carried by the description. score names each and the card they should have taken, whose heading is the one to mend:

== leaning on the description: 2 visitor(s) went right with the
   descriptions and wrong on the headings alone; the heading to mend
   is the one each should have taken
LEANS: apprentice@/: "to be considered, without writing a letter"

In a plan that is a wants that leans on its who: “to be considered” (for what?), “it ordered” (what?). Behind a door the door said who the cards were for; on one front door the heading stands alone, and says it itself. summary.json carries them as leans.

The two lines above are the contractor plan’s, before they were acted on. Two rounds by hand, each scored with --routing (three seeds, the local visitor): narrowing the drawn card to “a survey of a building, and a report on what is wrong and what it takes” took the visitors routed right with descriptions from 9 of 12 to 11; having three more headings name their object (“to be considered for a job with us”) took them to 12, and on headings alone from 8 of 12 to 10. Four wants changed, nothing else in the plan.

Seeds are spent where they tell something: every task is asked under the first three (--first), and under the rest only where those three did not agree. Most tasks are answered alike three times over, so --seeds 7 costs little more than three. --first 7 asks every seed of every task.

rate takes the same two flags, and score passes them on: each persona answers the understanding questions under the first three seeds, and under more only while its answers do not agree. A yes is most of the seeds. With seeds, each page in rate.json also carries understanding_share and control_share: the share of all answers that were yes, per question, which tells a page nine in ten understand from one that six in ten do when both count as a yes.

With several seeds the answers are a file per seed, answers-<mode>-seed<n>.jsonl, which is how learn extract reads a run’s seeds as votes: a scored run under runs/ is training rows with soft labels, and choose --validate holds its formula to them, with nothing more to do. The lint scores them from one file of them all, scored-<mode>.jsonl. One seed is answers-<mode>.jsonl, as before.

Four yes-or-no questions per persona (which option is mine, where am I and what does the button do, what will I be asked, what happens after I send it), each also put to a gutted twin of the page with headings, descriptions, the form and the followup removed. A question the twin still gets a yes on is not measuring the page, and rate says which. The followup page is read from the repo (--repo); without it “what happens next” is reported as not measured rather than as zero. LIX is over the prose only (question, descriptions, followup): headings and labels are not sentences and would pull every page down to “very easy”. The rate.json in runs/contractor-build-2026-09-21/ predates this and its asked and next columns are the old, pinned ones.

rate --repo also scores the desks, the inside of the business, which reads button labels and nothing else: for every desk and bucket with two or more buttons, a worker is told what has just happened to a case (in the state’s own words, never the label’s) and picks the button among the ones a row in that state shows, in a rotated order. Scored per desk as right of total, with what each miss was mistaken for. Measured on 2026-09-24 on the live vel: 24 of 26, the misses one button each on the neighbour-help desk and the notice board. Two limits: the outcome is put from the state id, and a Norwegian id with its accents stripped (ikke_lost) reads as English even to a strong model; and a first version that offered every button of the bucket, not the row’s, scored the same desks 17 of 26 and sent a rewrite chasing an instrument fault. A desk that scores full marks has labels a stranger to the business could press right. prefer has a positive control on record (runs/tomtervel-opener-2026-09-23, “The friendliness judge”): the live vel front door against a bureaucratic twin, friendlier 9 of 10 to the live page and 0 to the twin. A pair that comes back “no preference” throughout is alike in tone, not an instrument that cannot see; and the rejected door rewrite that was judged clearer on 5 of 10 needs routed worse across three seeds, so clarity as judged and routing as measured are different things, and routing decides.

Measured so far

Generated: a building contractor (runs/contractor-2026-09-21/), from intakes/contractor.yaml, a Sonnet-class model generating.

  • Phase 1 derived six needs from the owner’s prose, including one nobody asked for: a project manager logging a phone enquiry, taken from “enquiries arrive by phone, email and text and get lost”.
  • Phase 2 was green on the first round: 14 files, four state machines (enquiries: open → quoted → won | lost, subcontractors with an awaiting_papers loop, applicants, site_issues), two desks.
  • Phase 3, its own personas: 10 of 10 in both modes. That number is flattering, because in that run the pages were written with the personas in view. Against ten held-out personas, with qwen3:8b as the visitor:
Visitor could readRouted right
Headings and descriptions10 of 10
Headings only8 of 10

A scaffolding firm asking “how do I get to do jobs for you?” chose “Ask about working with us” (the hiring door). An attic conversion chose “Get someone to look at a building”. The generator has since been changed to hide personas from the page-writing phase.

Built: the same contractor from a plan (runs/contractor-build-2026-09-21/), nemotron writing words only, and re-scored one task per call the day after (rescore-2026-09-22/ in it): 8 of 8 with descriptions, 7 of 8 on headings alone, the miss being an apprentice bricklayer reading “Join our carpentry team” as not for them. rate on the same site, with the followup shown and every question controlled, passes its controls and puts the pages at LIX 18 to 35.

Built behind doors, 2026-09-22. Five plans with a first question before the forms, each built and then scored by qwen3:8b one task per call, against held-out personas. Behind a door a persona is asked twice, on the front door and on the door’s page.

CaseWords byWith descriptionsHeadings onlyNotes
Machine hire (hire)nemotron10 of 1010 of 10doors that ask a question the visitor already knows the answer to
Physio clinic (physio)nemotron8 of 109 of 10“Book your first appointment” fails a daughter booking for her mother
Football club, Norwegian (fotballklubb)nemotron14 of 1611 of 16three parents walk past “Er det på tide å melde inn?”
Football club, NorwegianClaude Sonnet13 of 1612 of 16better sentences, same driver/sponsor blur
Whole contractor (contractor-full)nemotron18 of 2215 of 22“Apply to work with us” and “Find a job with us” cross over for all four
Tomter Vel, Norwegian (tomtervel), first planClaude Sonnet25 of 3022 of 30“utstyr” for a swing, hearing input behind the wrong door
Tomter Vel, plan revised 2026-09-23, whole cardClaude Sonnet31 of 3830 of 38committees as groups, public lists, hearing input on the front door

Each run’s README names the misroutes and what in the plan or the heading caused them. A stronger word model did not route better on the one plan built with both: routing is decided by which distinctions sit on one page, and the visitor grades that the same whoever wrote the words.

Planned: the contractor intake read by a local model (runs/contractor-plan-2026-09-22/), nemotron, one round, 41 s. The plan passed every check build makes and a reader finds three structural misses in it the checks cannot: the crew’s report made public, the “papers missing” stage dropped, and no need for the project manager logging a call. The person reading the plan is not optional.

Existing site: uhhm.no (runs/uhhm-2026-09-21/), eight tasks.

Visitor modelWith descriptionsHeadings only
small LLM, blind7 of 85 of 8
qwen3:8b (Ollama)7 of 87 of 8
granite4.1:8b (Ollama)7 of 86 of 8

All three send a paying client through “Work happens through dialogue, not tickets”, the collaborator door. Different models, same defect: that is what a wording problem looks like.

The noise floor, 2026-09-23 (runs/spread.sh, answer --seed). The same tasks answered by qwen3:8b with four seeds (0 is the run every score above used):

RunWith descriptionsHeadings only
uhhm.no round 6, 15 tasks11, 10, 10, 1012, 12, 7, 7
Tomter Vel with the opener, 38 tasks30, 29, 29, 3126, 24, 26, 23

With descriptions the visitor is steady: one task in fifteen, two in thirty-eight. On headings alone it is not: five of fifteen on uhhm.no between seeds, three of thirty-eight on the vel. A headings-only difference smaller than that is the visitor’s mood. Compare descriptions-mode scores; read headings-only as a sanity check, and run several seeds before believing it. Small numbers, one run each. Leads, not measurements.

What else is here

  • skill/SKILL.md - the same procedure for an agent or a person working by hand.
  • sectors/ - needs specs to start from. construction/ doubles as the held-out persona set above.
  • generator/reference.md - everything the generating model is told about portal content. When the lint rejects something the reference did not warn about, the fix belongs there.

Toward a trained model

The runs are now a training set. learn, a second binary in this repo, turns every run and every night of synthetic personas into rows labelled by the plan’s own truth, trains a small route model on a frozen encoder, calibrates it, and answers as a visitor (engines/learn.sh) and as a ranker (learn rank). The visitor models are its factory and its yardstick, never its judge: a model trained against a judge that is often wrong learns the judge. What it is, how it is measured on sites it has never seen, and how to retrain it are in Learning.

The generator side is not trained yet: generating many wordings per need and keeping the ones that route best is the next step, and those winners are the fine-tuning set for a small generator.