Skip to Content
turbo-12f
Architecture

UI and access

How t12-ui serves an embedded React SPA and live SSE flow graphs, enforces CSP/CSRF, keeps accounts, teams, per-user connections and Observer state in Postgres, and delegates git and pipeline writes to t12.

Explanation

The web workbench (cmd/t12-ui) authenticates sessions against the identity tables in Postgres, checks origin and CSRF tokens on every mutation, delegates git and pipeline writes to child t12 processes, and reads and writes accounts, teams, approvals, and Observer state through the same database. Nothing about people or access lives in files under <home>.

Frontend

Embedded React SPA

React 19, React Router, and Tailwind v4 bundled via Vite and embedded with zero-inline CSP.

Security

Auth, CSRF & roles

PBKDF2 passwords, GitHub or email sign-up, 15m links, Tailscale Serve auth, and team roles.

Engine

Subprocesses & SSE

Forks sibling t12, streams 500ms SSE graphs, and runs the Observer loop.

Subprocess delegation and factory-wide controls

internal/ui (requests.go, control.go, mode.go, approvals.go, observer.go) reads projections through record.Home (backed by the database), internal/rollup, internal/roles/context, and internal/roles/release.

Control surfaceMechanism
Sibling t12 forksMutations spawn sibling("t12") (Setpgid: true), inject T12_AUTONOMY from the stored approval mode, and stream T12_UI_PROGRESS=1 output to liveBuffer (80 lines) and the job-log:<key> log stream.
External lock syncactionSlot probes LockContext/LockAsk/LockConfirm/LockRelease via Home.RequestLocked; buildSlot probes LockRun; controlOf clears stale Paused/Stopped markers when external CLI locks run.
Graceful haltPause, stop, and shutdown terminate process groups (SIGTERM, 5s haltGrace, SIGKILL); Server.Close() closes s.closed and BaseContext so open SSE streams exit cleanly.
Permission & approvalsModeMenu inside PromptBar sets the host mode (review, default, auto, turbo; POST /api/mode, Operators only) stored as the approval-mode document. In Request Review, CommandApprovals decides rows of the approvals table.
Observer loop<ObserverBubble> drawer and /observer let an Operator write scoped projects/conversations to the observer-setting document. Every 10s, SessionDecider resolves 9 kinds via Server handlers and appends to the observer log stream. The loop runs only in t12-ui, never in the Vercel function.
Setup & docs chatsetup.Manager (setup.go) drives sign-in, API-key, and test flows for the GitHub, agy, and omp connections; docschat.Wrap serves /api/docs-chat SSE answers on t12-ui and --serve-dir.

Embedded SPA and CSP hardening

server.go embeds the built frontend via //go:embed all:web/dist and enforces strict browser headers:

Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' blob:; connect-src 'self'; form-action 'self'; frame-src 'self'; frame-ancestors 'none'; base-uri 'none'
  • Headers & images: Pairs zero-inline CSP with X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Referrer-Policy: same-origin, and Cache-Control: no-store. GET /api/c/{id}/images/{name} checks conversation access and image MIME types.
  • Origin, CSRF & cookies: sameOrigin matches Origin to Server.BaseURL or r.Host; signed-in POSTs verify X-CSRF-Token with subtle.ConstantTimeCompare against store.SHA256("csrf:" + session)[:32]. Cookies set HttpOnly, SameSiteLaxMode, and Secure on https.
  • Build-time CSP patches: cspSafeLibraries in vite.config.ts rewrites runtime <style> injectors in sonner, vaul-base, and number-flow.

The app only presses buttons

Flow
100%
cookiePOSTroleallowedrunsappendsderivesreadsproposesAuth & sign-inpw · GitHub · linkBrowser sessionteam role or testerAccess tablesusers · teams · docsRequest guardsOrigin · CSRF · RBACt12-ui serverSSE · slots · ObserverRollup viewsread-only snapshotRecord logwrites evidence chaint12 CLI coret12 <verb> --by <mail>proposal documentsnon-OS safety keys

Every UI POST passes Origin, CSRF, and role guards before executing sibling t12 verbs or updating accounts, approvals, and Observer state in Postgres.

Click any node or press Play

Access model, teams, and connections

internal/access (access.go, db.go, password.go) keeps accounts and access in Postgres (ADR 0005), never in a file under <home>. Each change reads one snapshot, edits it in memory, and writes the differing rows in one transaction that bumps access_head; a writer with a stale snapshot is rolled back and retried, so there is no lock.

A process keeps what it read: it asks access_head again after 5s (headFresh) and reuses a snapshot or a session's account for up to 30s, and a change or sign-out made by that process drops the cache at once (cache.go).

DataWhere it lives
People & sign-inusers (handle, avatar, GitHub id and login, Tailscale login, password hash), sessions and auth_tokens (hashes only)
Teamsworkspaces (the team), workspace_members (role per person), workspace_projects; team_members holds direct per-project levels
Requests & testersteam_access_requests (per-team join requests), testers (bug-bash invitees per request)
Profiles & notificationsdocuments kinds user-profile, public-profile, and notifications, keyed by email
Audit traillog_entries stream access, written in the same transaction as the change
Connectionsuser_connections (sealed per person and kind), run_credentials (per-run references); the tables come from the migrations in internal/db/schema/migrations
MechanismDetails
Password storageSalted PBKDF2-SHA256 (600,000 iterations); sign-in rate limits of 10 failures per account and 30 per IP in 15m
Sign-in linksLinkTTL (15m), SignInEvery (1m) throttle, constant-shape responses; /link requires click POST (redeem)
Tailscale auto-login--trust-tailscale (T12_TRUST_TAILSCALE, auto on https://*.ts.net) reads Tailscale-User-Login over loopback unless t12_ts_out=1
Sessions & sign-upt12_session cookie (30 days). Sign-up is open and needs no Operator: with GitHub, or with an email proved by a one-time verify link (taken on trust on loopback or a trusted tailnet)
Sign in with GitHubOne GitHub App (T12_GITHUB_CLIENT_ID, T12_GITHUB_CLIENT_SECRET); the flow uses state plus PKCE at /api/signin/github. A linked GitHub id signs in, else a verified email matches or creates an account
First OperatorThe first sign-up on a loopback address (ui.Local), t12 ui --bootstrap, or set-password --operator. In the cloud, T12_OPERATOR_EMAIL with T12_OPERATOR_PASSWORD makes that account the Operator while none exists
Team access requestsOne live request per person and team with a random 6-character check code shown to the team's owners and Operators (People page, bell, mail with SMTP); 7d TTL, 5 per person, 50 per team
Per-user connectionsinternal/connections seals GitHub, agy, omp, and the optional Cloudflare and Vercel hosting accounts with AES-256-GCM under T12_PROJECT_ENV_KEY; runs get a per-run reference, the hosting accounts reach only a release's production deploy, and factory-wide credentials apply to Operators only with T12_SHARED_CREDENTIALS=1
Handles, avatars & profilesUnique handles, avatars in the blob store, /u/<handle> with an activity heat map (GET /api/people/{handle}/activity), and a team heat map (GET /api/t/{team}/activity)
Project access & lifecycleOperators or project Editors share project access (/api/p/{project}/access/*); Operators archive, restore, or delete projects (/api/p/{project}/archive and /api/p/{project}/delete)

Roles and what they may do

Roles resolve in State.RoleIn and State.Level (team.go); the request-level checks live in accessTo in internal/ui/requests.go.

RoleProject levelWhat the UI lets them do
OperatorEditor everywhereEverything, plus factory-wide controls: mode, Observer, safety-group approvals, archive and delete
Team owner / memberEditorWrite in conversations, start builds, share project access; they are Acceptors of the team's requests
Team viewerViewerRead only
Team clientClientOpen requests and file board tickets; confirm and sign off their own requests; read the client view; never start builds
Bug-bash testerNoneThe invited request's bug bash only

Acceptor is not a role someone is granted. accessTo sets Acceptor for every Editor (and Operator) on a team project, but for a client only on requests they opened; on a project no team owns it is the person who opened the request, or an Operator when no person opened it. The t12 confirm flag --acceptor records who confirmed. Confirm, approve, change, sign-off, and tester invites check it.

The view of a project is the viewer's role in the team that owns it (access.ViewOf): clients read the client view, everyone else the factory view. There is no switch and no saved choice.

Changing a safety-group preference stores a proposal document and requires an Operator (POST /api/p/{project}/preferences/decide). With several Operators, the author cannot approve their own proposal; a sole Operator must pass confirm=1.

React 19 SPA architecture

The frontend under internal/ui/web uses React 19, React Router 7, Zustand, Tailwind CSS v4, Recharts for charts, Optics UI primitives under src/components/optics/ (including popover.tsx, select.tsx, sheet.tsx, and switch.tsx), and the shared design tokens in design/tokens/tokens.css, imported by index.css. Vite builds it through vite-plus. That directory is the factory UI's own component set and evolves independently of the minimal starter subset under catalogue/templates/web-react/src/client/components/optics/.

Data fetching, live controls, and views

LayerImplementation and cadence
Page polling (usePage)Fetches JSON and polls every 5000ms while data.busy, data.working, or an activity is shown, skipping turns while the tab is hidden or idle and refreshing once on return; a conversation paused for waiting too long (waitPaused) is not polled
Conditional pagesA polled page carries a keyed-hash ETag built from the change-scope revisions it reads (the changes table, migration 0015), the viewer, the build, and the minute; a matching If-None-Match gets 304 without rebuilding the page. A paused conversation's version lasts an hour
Home cache & ProjectSyncCoalesced fetchHome/ensureFreshHome (15s freshness) plus GET /api/projects on confirms, unseen projects, tab focus, and a 15s timer
Global controls (useLive<T>)Shared timer per key (mode 15s, approvals 10s, observer 10s), pausing when the tab is hidden
Navigation & workspaceSidebar with team switcher and account menu, centered PromptBar composer on / with ModeMenu permission, and the /c/:id workspace (inline Confirm, LiveActivityCard, DeliveryWorkspace)
Board, metrics & people/p/:project/board (Backlog, Implement, Verify, Done), /usage and /p/:project/analytics metrics views with a Gantt timeline, /u/:handle profiles and /t/:team pages with heat maps
Intake, setup & guidanceRepoPicker, multi-issue IssuePicker (POST /api/c/{id}/issues), AgentPicker, ErrorBoundary, classifyError guidance, Decide for me, and ViewSwitchControl (?view=detailed)
Live flow canvas & SSE (useFlowStream)The flow canvas (layoutFlowGraph, useDiagramCamera) subscribes to GET /api/c/{id}/stream (500ms ticks, 15s keepalives, 300ms throttle) with 5000ms /graph fallback

Key takeaway

t12-ui never implements separate git or build logic: it acts as an authenticated, CSP-hardened control plane over t12 subprocesses, database state, and SSE projections.

Next steps

On this page