Integrations

Brain Town reader

The Brain Town feed is GAOS pushing its own changes out. This page is the other direction: GAOS pulling the town's pull-request events, so a card can open when a pull request appears and another when it merges. The reader is off by default and reads only what the operator declares it needs.

Why a reader and not the public stream

The public stream is masked on purpose: a hidden product appears under its alias and every title is removed. That is right for a public town and wrong for a platform that has to act on a pull request — GAOS needs the repository's real name and the pull request's title the moment the event arrives.

So GAOS reads a scoped path: a machine token that opens one stream, filtered by the owners, repositories, kinds and event types the operator registered in Brain Town. Brain Town keeps the payload it already stores; the reader gets the repository's real name and the pull request's title, and no diff, no pull-request body and no login, because Brain Town never stored them.

The six settings

SettingDefaultMeaning
BRAIN_TOWN_CONSUMER_ENABLEDofftrue or 1 turns the reader on. Anything else: no listener, no goroutine, no request.
BRAIN_TOWN_CONSUMER_URLunsetThe town's base address (for example https://town.example.org). https only; no path, userinfo, query or fragment; redirects are refused; an address or a loopback host is refused.
BRAIN_TOWN_CONSUMER_TOKEN_FILEunsetA file holding the reader's bearer token, mode 600. In production it is deploy/stacks/prod.bt-consumer-token. The token must start with bt_c_: a bt_live_ token (the town's input credential) and a gaos_ token are refused. A file others can read is refused, not warned about.
BRAIN_TOWN_CONSUMER_CURSOR_FILEunsetA file, mode 600, holding the last event the reader handed over. It is what makes a restart resume instead of replaying the whole retention.
BRAIN_TOWN_CONSUMER_TYPESpr.opened,pr.mergedThe town event types the reader accepts. An empty list means these two.
BRAIN_TOWN_CONSUMER_KINDSgithubThe event kinds the reader accepts, a comma list. It is sent as the stream's kind parameter and filtered again on the client. Add gitlab for a GitLab product (GitLab).

An unusable setting never stops GAOS: the reader stays off, the boot log says why (brain town: consumer unusable (…)) and the back office's Integrations view shows the reason.

The scope GAOS declares

The operator registers the scope in Brain Town's back office: the owners, the repositories, the kinds and the event types the reader may see. Brain Town filters by it.

GAOS filters again, by the repositories its own products declare (owner/repo pairs). The match is owner-qualified: a repository of the same name under another owner does not match, and a bare name never matches. So a scope that is broader than GAOS's products still cannot make GAOS act on a repository it does not own — and the repository GAOS acts on is always the product's, never the event's.

So a repository linked to a product in GAOS (Linked repositories) must also be inside this scope; otherwise Brain Town never sends its events.

One scope per GAOS instance. GAOS runs a second instance with its own database; two instances pointing at one scope would each open the same cards.

What the reader sees

The frame has the public frame's own shape — seq, id, type, source, at, payload — with the payload unmasked, plus productKey and orgLogin from the town's store:

id: 1975
event: pr.opened
data: {"seq":1975,"id":"gh-…","type":"pr.opened","source":"github","at":"…",
       "productKey":"sample-service","orgLogin":"acme-org",
       "payload":{"product":{"key":"sample-service","name":"sample-service","visibility":"hidden"},
                  "task":{"id":"4931","kind":"pr","title":"Fix export"},
                  "data":{"pr":4931,"draft":false}}}

The pull request's title is untrusted text: it is capped at 200 characters, stripped of control characters and screened for anything that looks like a credential before it reaches a card.

A GitLab frame (D-114) is read differently: GAOS takes the repository only from payload.data.gitlab — host, pathWithNamespace and projectId, which Brain Town takes from the integration’s own instance — never from productKey or orgLogin. A frame without the three is skipped as gitlab-frame-incomplete; one whose path no product lists is skipped as not-owned; the project id must be the one the repository is pinned to.

Reading, losing and replaying

Turn it on

  1. In the town's back office, open Consumers, create one for GAOS and give it the scope: the owners, the repositories, the kinds and the event types. Copy the token — it is shown once.
  2. Create the token file and the cursor directory, as the deploy user: install -m 600 /dev/null deploy/stacks/prod.bt-consumer-token and mkdir -m 700 deploy/stacks/prod.bt-state, then put the token in the file. Both must exist before up; the deploy refuses a missing directory, one owned by someone else, or one that is not mode 700. The container runs as the deploy user and writes cursor inside it.
  3. Redeploy with the settings on the line, and repeat them on every redeploy: BRAIN_TOWN_CONSUMER_ENABLED=true BRAIN_TOWN_CONSUMER_URL=https://town.example.org ./deploy/rebuild-restart.sh prod deploy --tag vX.Y.Z.
  4. Open the back office's Integrations view: the Brain Town reader block says enabled, the host, and how many events were handed over.

The town must already serve the reader's path. A GAOS that ships the reader first leaves it off with the reason the stream answers 404, which is the expected state until the town ships it.