UI and access
How t12-ui serves an embedded React SPA and live SSE flow graphs, enforces CSP/CSRF, manages mode/approvals/Observer, and delegates git and pipeline writes to t12.
The web workbench (cmd/t12-ui) authenticates sessions from private JSON state, checks origin and CSRF tokens on every mutation, delegates git and pipeline writes to child t12 processes, and manages host control files (access/, approvals/, observer/) plus read-only Observer sessions directly.
Embedded React SPA
React 19 + Optics UI bundled via Vite and embedded with zero-inline CSP.
Auth, CSRF & RBAC
PBKDF2 passwords, 15m tokens, Tailscale Serve auth, and two-operator safety checks.
Subprocesses & SSE
Forks sibling t12 under lock sync, streams 500ms SSE graphs, and runs Observer.
Subprocess delegation and factory-wide controls
internal/ui (requests.go, control.go, mode.go, approvals.go, observer.go) reads projections directly from record.Home, 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 mode.json, and stream T12_UI_PROGRESS=1 output to liveBuffer (80 lines) and commands/<job>.log (0600). |
| 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 writes <home>/access/mode.json (review, default, auto, turbo). In Request Review, CommandApprovals posts decisions to <home>/approvals/<YYYY-MM-DDTHH>/<id>.decision.json. |
| Observer loop | <ObserverBubble> drawer and /observer write scoped projects/conversations to <home>/access/observer.json. Every 10s, SessionDecider resolves 9 kinds via Server handlers and logs to observer/log.jsonl. |
| Setup & docs chat | setup.Manager (setup.go) drives OAuth, API key, and test flows for GitHub, agy, omp, and claude; 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-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 access, approval, and Observer stores.
Click any node or press PlayAccess model and two-operator safety approval
internal/access (access.go, password.go) persists users, teams, PBKDF2 hashes, Tailscale aliases, tokens, sessions, testers, and pending requests in <home>/access/access.json (0600 under access/lock, audited to access/log.jsonl).
| Mechanism | Details |
|---|---|
| Secret & password storage | store.SHA256 hashes for tokens/sessions; salted PBKDF2-SHA256 (600,000 iterations) with rate limits (10/account, 30/IP per 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 & access asks | t12_session cookie (30 days); up to 50 pending access requests (24h TTL) verified via 6-char code |
| Roles | Operators (ui.Local first sign-up, --bootstrap, set-password --operator), Editors, Viewers, Acceptors, Bug-bash testers |
| 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) |
| Profiles & notifications | Per-user Observer profiles (access/profiles/<hash>.json) and notification state (access/notifications/<hash>.json) power /onboarding, /profile, /settings, and the header bell |
Changing a safety-group preference writes proposals/config-<key>-<ts>.json and requires Operator approval (POST /api/p/{project}/preferences/decide). With multiple Operators, authors cannot approve their own proposals; a sole Operator must pass confirm=1.
React 19 SPA architecture
The frontend under internal/ui/web uses React 19, React Router, Tailwind CSS v4, Optics UI primitives under src/components/optics/ (including popover.tsx, select.tsx, sheet.tsx, and switch.tsx), and OKLCH tokens in index.css. 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 or data.working is true |
Home cache & ProjectSync | Coalesced fetchHome/ensureFreshHome plus GET /api/projects on confirms, unseen projects, /access transfers, focus, and 60s timer (homeCache + project.NameAt on server) |
Global controls (useLive<T>) | Shared timer per key (mode 15s, approvals 3s, observer 3s), pausing when tab is hidden |
| Navigation & workspace | Sidebar search, click-to-expand project conversation trees, centered PromptBar composer on / with ModeMenu permission, and unified /c/:id workspace (JourneyBar, inline Confirm, LiveActivityCard, DeliveryWorkspace) |
| Intake, setup & guidance | RepoPicker, multi-issue IssuePicker (POST /api/c/{id}/issues), 5 images, AgentPicker (availability), ErrorBoundary, classifyError guidance, Decide for me, and ViewSwitch (?view=detailed) |
Live flow canvas & SSE (useFlowStream) | #flow-preview and #flow (layoutFlowGraph, useDiagramCamera) subscribe 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, lock files, and SSE projections.