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.
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>.
Embedded React SPA
React 19, React Router, and Tailwind v4 bundled via Vite and embedded with zero-inline CSP.
Auth, CSRF & roles
PBKDF2 passwords, GitHub or email sign-up, 15m links, Tailscale Serve auth, and team roles.
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 surface | Mechanism |
|---|---|
Sibling t12 forks | Mutations 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 sync | actionSlot probes LockContext/LockAsk/LockConfirm/LockRelease via Home.RequestLocked; buildSlot probes LockRun; controlOf clears stale Paused/Stopped markers when external CLI locks run. |
| Graceful halt | Pause, stop, and shutdown terminate process groups (SIGTERM, 5s haltGrace, SIGKILL); Server.Close() closes s.closed and BaseContext so open SSE streams exit cleanly. |
| Permission & approvals | ModeMenu 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 chat | setup.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. |
- Socket path:
StartAdminopens<home>/admin.sock(0600) or$T12_ADMIN_SOCKET, falling back to$XDG_RUNTIME_DIR/t12-<hash12>.sock(non-symlink0700dir) or/tmp/t12-<uid>/<hash12>.sockwhen exceeding the 100-byte socket limit (skippingchmodonEINVAL/ENOTSUPfor Colima VirtioFS). - Drain lifecycle:
drainGatetransitionsserving→draining(up to5mmaxDrainHoldholding<home>/active.lockexclusively) →closing→closedfort12-ui --status,--drain, and--shutdown.
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, andCache-Control: no-store.GET /api/c/{id}/images/{name}checks conversation access and image MIME types. - Origin, CSRF & cookies:
sameOriginmatchesOrigintoServer.BaseURLorr.Host; signed-inPOSTs verifyX-CSRF-Tokenwithsubtle.ConstantTimeCompareagainststore.SHA256("csrf:" + session)[:32]. Cookies setHttpOnly,SameSiteLaxMode, andSecureonhttps. - Build-time CSP patches:
cspSafeLibrariesin vite.config.ts rewrites runtime<style>injectors insonner,vaul-base, andnumber-flow.
The app only presses buttons
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 PlayAccess 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).
| Data | Where it lives |
|---|---|
| People & sign-in | users (handle, avatar, GitHub id and login, Tailscale login, password hash), sessions and auth_tokens (hashes only) |
| Teams | workspaces (the team), workspace_members (role per person), workspace_projects; team_members holds direct per-project levels |
| Requests & testers | team_access_requests (per-team join requests), testers (bug-bash invitees per request) |
| Profiles & notifications | documents kinds user-profile, public-profile, and notifications, keyed by email |
| Audit trail | log_entries stream access, written in the same transaction as the change |
| Connections | user_connections (sealed per person and kind), run_credentials (per-run references); the tables come from the migrations in internal/db/schema/migrations |
| Mechanism | Details |
|---|---|
| Password storage | Salted PBKDF2-SHA256 (600,000 iterations); sign-in rate limits of 10 failures per account and 30 per IP in 15m |
| Sign-in links | LinkTTL (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-up | t12_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 GitHub | One 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 Operator | The 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 requests | One 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 connections | internal/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 & profiles | Unique 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 & lifecycle | Operators 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.
| Role | Project level | What the UI lets them do |
|---|---|---|
| Operator | Editor everywhere | Everything, plus factory-wide controls: mode, Observer, safety-group approvals, archive and delete |
| Team owner / member | Editor | Write in conversations, start builds, share project access; they are Acceptors of the team's requests |
| Team viewer | Viewer | Read only |
| Team client | Client | Open requests and file board tickets; confirm and sign off their own requests; read the client view; never start builds |
| Bug-bash tester | None | The 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
| Layer | Implementation 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 pages | A 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 & ProjectSync | Coalesced 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 & workspace | Sidebar 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 & guidance | RepoPicker, 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
Release and SRE
How lanes enter staging through the lease-serialized merge queue, clear merge policies and proof bisection, record sign-offs and promotions in Postgres, and stay monitored after promotion.
CLI reference
Every binary under cmd/, exit codes, signal handling, v2 t12 subcommands (including t12 db), and legacy v1 commands.