web/ — the React frontend¶
The React frontend: the studio where people write, create and review content and follow agent runs, the shared packages it is built from, and the site renderer to come.
The one web frontend of zer0-CMS (ADR 0006 decisions 2 and 9; TARGET.md § The studio): the studio, where people write, create and review content, follow agent runs and work with the AI content layer (assistants, pipelines, output schemas, briefs, conversations, providers and models), and the shared packages its workspaces are built from — which the VS Code extension's webviews render as they are (PLAN G10), so a studio capability reaches the extension by construction. It talks to the platform (content/) only through the platform's API, through a client generated from the committed OpenAPI document. PLAN P4 built it; the site renderer (web/site/, PLAN P6) joins it later.
Layout¶
| Path | Package | What it is |
|---|---|---|
packages/api/ |
@zer0/api |
The platform's REST API: src/schema.d.ts, generated by openapi-typescript from schemas/openapi/openapi.json and committed; a small openapi-fetch client for the studio (same origin, the session cookie, Django's CSRF token on every unsafe request); the shapes the components pass around, named once. |
packages/tokens/ |
@zer0/tokens |
The zer0 design tokens as CSS custom properties (tokens.css, one light-dark() pair per colour, seeded from the zer0 UI tokens kit's values) and the Mantine theme that reads them — the theme holds no colour of its own, so a host that redefines a token restyles everything. |
packages/ui/ |
@zer0/ui |
The workspaces and their components: PageList (filters, the tree a level at a time), PageEditor (blocks, fields, SEO, the File tab — the file path and raw front matter of a page that is a file of its site —, save a draft, preview, publish, unpublish, schedule, the AI panel), BodyEditor and RichText (TipTap with the Markdown round trip; TableFields, a table's or a typed table's cells, rows, columns and column types in place; raw HTML and Liquid as their source), FieldsPanel (a field spec's kind as its input — boolean a switch, as noindex in the SEO tab), SuggestionInbox (diffs with jsdiff; accept, reject with a reason, accept all of a run), RevisionHistory (compare, revert), RunTimeline, RunList and useLiveRun, CreatePage, Overview; the Books workspace (books/, PLAN G9): BookShelf (the library's books, with status and progress; a new book from the template, or from a premise — outlined by a run, made when the person accepts it), BookView (facts and statistics — the switch for the brand guard's built-in bans on its chapters among the facts —, the outline with the outliner's proposal as a diff, characters, continuity and style guide, BookFiles — the act guides and README, edited one at a time as draft revisions — chapters in order, findings, the manuscript to download), ChapterWriter (the page editor beside BookAssist, the book assistant whose drafts arrive as suggestions and whose continuity check arrives as findings), PagePicker (searching the platform as the person types, so every page is within reach), Sharing (who sees a board, a collection, an idea or a source — only its owner, a site's editors, everyone signed in — and ListForm, which names and shares a board or a collection); ideas/ — IdeasWorkspace (boards and the inbox, a board made and shared beside them, ideas in columns by status, votes, CaptureIdea, Brainstorm, Clusters, IdeaDrawer with sharing, promotion and BriefCard); research/ — ResearchWorkspace (collections, made and shared beside the list, CaptureSource by URL, upload, note or web search, the source list, AskPanel, FeedsPanel, ResearchBrief), SourceView (with who sees it), and PageResearch, the editor's Research tab (cite, fact-check — what it read and left out, exact corrections — capture an idea); and in src/ai/ the AI content layer's (PLAN G8): ProviderList and ProviderStatus, ModelCatalog, AssistantList and AssistantEditor, PipelineList and PipelineEditor, SchemaList and SchemaEditor, BriefList and BriefWorkspace, ConversationList and ConversationThread, and AiPanel, the editor's.; and newsroom/ (PLAN G15): Newsroom — the story budget as a board by status (drag a card to move it with @dnd-kit, as the pipelines' steps are, or use its menu), the calendar by slot date, assignments, fronts, newsletters, authors and their pages, pitching — and StoryPanel, a story's moves, plan, bylines, page, AI help, corrections and history; voice/ (ADR 0010): Voice, a site's Voice tab — who is told the voice, the map of who reads which layer and the readers it never reaches, each layer as a section, and TestText, the brand guard on a text in a live region — which SiteView places and whose page and channel it holds across tabs; LevelBadge, a brand guard finding's level in a badge readable at 4.5:1 in either scheme, which the distribution post panel shares; sites/ (PLAN G4): SitesWorkspace (every site with how it renders, where its files are, its last sync and its doctor's counts; RegisterSite, a checkout workspace.yml or SITES_DIR offers, or a path, registered and synced), SiteView (overview and the registry fields — content source, renderer, theme tag and Jekyll server, domains, deploy target — the per-site settings, the doctor's findings filtered, its jobs; sync, write-back and the doctor started with an Idempotency-Key) and JobLog with useLiveJob (a job's log followed live over its event stream, cancel, its artifacts read through the client); and outbox/ (ADR 0007): OutboxDesk — the outbox harness's belt (its numbers, messages filtered by kind, station and trace, a message with its CloudEvent and its piece's journey, the dead letters, SendHandoff as the editor station, the relay run now), Trials and TrialView (a task card run in the worker, its result and the arena's ledger) and ClaimDesk and ClaimCheckView (claims checked against a source timeline, verdicts, resolution against the truth, calibration); and automations/ (PLAN G16): AutomationList (each automation's trigger, whether it runs, its last run; YAML import) and AutomationEditor — a trigger picker, the condition tried against the platform with the trigger's sample payload, the actions in order (reordered with @dnd-kit or the move buttons), enable and pause, the secret shown once and the webhook URL, a dry run and a real run, YAML export — over AutomationRuns, the run history with each action's outcome and a link to what it made; and aieo/ (PLAN G7): AieoWorkspace — audits of a text, a page, a URL or a site followed as runs (AuditView, ScoreCard with the five dimensions as a radar and as bars, the evidence, the nearest audits in meaning, the report), rewrites, the pattern library, the AIEO agents, citations and share of voice, connectors (each card drawn from what is saved, its synced rows a click away) and priorities, reports, the brand context and the lifecycle — and PageScore, the editor's Citability tab, whose rewrite of a page lands as suggestions; distribution/ (PLAN G5): Distribution — the queue (Queue); a post (PostPanel: its text, saved as what changed and sent back to draft when an approved or failed post's text changes, the brand guard's findings, every blocker, LinkedIn's exact payload, approve, reject, publish after asking and never with unsaved text, force, record, its notes — where its site ledger entry went); channels (Channels: add, a credential, connect LinkedIn, check and read statistics for those who manage channels, arm, the ledger file, remove after asking); the ledger and statistics (Ledger, Statistics) — at the destinations distribution (with its tab), distribution-post and channel — and Distribute (Compose), the editor's and a story panel's way into the queue, listing the page's or the story's site's channels; account/ (PLAN G3): SignInScreen and AccountWorkspace over the host's AuthHost (allauth.ts: the shapes of allauth's answers), and Tokens, a person's API tokens over the platform's client; SitePicker; and WORKSPACES, the registry of workspaces a host renders without knowing them — the studio's areas, Home to Distribution — with HOME, the workspace each destination is shown in |
packages/webview/ |
@zer0/webview |
The VS Code extension's webviews (PLAN G10): App — the dashboard (a tab per entry in WORKSPACES), the page behind the open file, the AI workspace — over a postMessage transport (transport.ts: the host sends every request, so the webview holds no credential; it carries JSON bodies, the Idempotency-Key and If-Match headers and the response headers a workspace reads, and refuses an upload with extension.unsupported_body), in the editor's theme (editor.css maps the --zer0-* tokens onto the extension's media/tokens.css). The repository root's esbuild.js bundles src/main.tsx into dist/studio.js and dist/studio.css. |
studio/ |
@zer0/studio |
The Vite + React app: the shell (every area of TARGET.md in the navigation, the site switcher, light and dark, sign-out), the routes that place the workspaces (src/ai/: the AI and Create areas, a tab and a route per section; /sites/aieo[/:section]: the AIEO workspace), the sign-in adapter, and the host side of the contract below. |
test/ |
— | The Vitest setup and the harness every suite shares: a fake platform behind the real openapi-fetch client, and the providers. |
Commands¶
cd web
npm ci # the committed lockfile
npm run dev # http://localhost:5173/studio/ against PLATFORM_URL (default http://127.0.0.1:8000)
npm run lint # ESLint, including the @zer0/ui host gate below
npm run typecheck # tsc --noEmit over every package, the studio and the tests
npm test # Vitest + Testing Library, in jsdom; nothing reaches a network
npm run build # studio/dist/, asset URLs under /static/studio/
npm run gen # regenerate @zer0/api's types after the platform's API changed
npm run check:api # fail when the committed types differ from a fresh generation
The API changes in the platform first: change a view or serializer in content/api/, regenerate the document (cd content && python manage.py spectacular --format openapi-json --urlconf ops.openapi --fail-on-warn --file ../schemas/openapi/openapi.json), then npm run gen here. CI (web.yml) runs check:api on every change to web/ or to the document, so a client and the API it calls cannot drift apart.
For a local studio with something in it: cd content && python manage.py migrate && python manage.py seed_demo && python manage.py runserver, then npm run dev here, and sign in as editor with the password zer0-demo (the default only under DEBUG). seed_demo makes a demo site with an article, a draft and an SEO agent's pending suggestions.
How the studio meets the platform¶
One origin. The platform serves the built studio at /studio/ (content/api/studio.py): its assets are static files under /static/studio/ (collected from studio/dist/, which settings add to STATICFILES_DIRS), and every other /studio/ path answers index.html, so the studio's router owns them. The session cookie and the CSRF token need no CORS. In development Vite proxies /api, /admin and /static to the platform instead. The platform image builds the studio in a Node stage (content/Dockerfile) and copies only studio/dist/.
Signing in is django-allauth's headless API (PLAN G3, content/accounts/README.md), and studio/src/auth.tsx is the one file that speaks it for the studio: its browser client (/_allauth/browser/v1/…, the session cookie, the CSRF token on every unsafe request), the form POST that leaves for an OpenID Connect IdP or GitHub and comes back to the studio (its home after signing in, /studio/account/provider/callback after connecting one to the account; ?error= when it did not finish), WebAuthn through the browser (PublicKeyCredential.parseCreationOptionsFromJSON and toJSON), and the QR code an authenticator app scans (qrcode.react) — handed to @zer0/ui as its AuthHost. The screens are @zer0/ui's: SignInScreen follows the flow allauth says is pending (a second factor, a code to verify an address, a sign-in or reset code, a provider sign-up) and AccountWorkspace is the account menu (password, TOTP and recovery codes, passkeys, connected providers, sessions, API tokens), asking for the password again when allauth does. GET /api/v2/me (content/api/session.py) is still who is signed in. A person the Wagtail or Django admin sent here (?next=/admin/…) goes back once signed in — to a path on the platform, never anywhere else.
An enforced CSP. The page /studio/ serves carries a Content-Security-Policy with a nonce made per request: scripts only from the platform, no inline style except the <style> elements Mantine writes, which carry the nonce (Vite writes a placeholder into <meta property="csp-nonce">, the platform replaces it, main.tsx hands it to Mantine, and to get-nonce for the <style> that a modal's or a drawer's scroll lock writes through react-style-singleton). TipTap runs with its injected CSS off; @zer0/ui/ui.css carries what ProseMirror needs. A Mantine Drawer or Modal runs with lockScroll={false}: its scroll lock writes a <style> element of its own, without the nonce, which the policy refuses. The extension's webviews run under the same policy and stricter — default-src 'none', no connection at all, images only from the extension, the platform, data: and blob: (src/core/studio/page.ts) — and the browser scenarios fail on any console error, a CSP violation included.
The host contract — why the packages can go into a webview¶
@zer0/ui never builds a client, opens a stream, reads a URL, a cookie or storage, or imports a router. A host wraps it in <StudioProvider api stream go auth>: api is an openapi-fetch client (the studio's speaks same-origin HTTP; the extension's, packages/webview/src/transport.ts, speaks postMessage to the extension host, which re-checks each request and adds the platform URL and the person's token — src/core/studio/bridge.ts), stream opens a server-sent event stream (the studio uses EventSource on /api/v2/agent-runs/<id>/stream/, and reports a stream the browser gave up on as the event error), auth (optional) carries django-allauth's headless API for a host with a browser session — the studio's auth.tsx; the extension's webviews leave it out, and the account workspace then lists and revokes the person's API tokens alone —, and go turns a Destination ({to: 'page', id}, {to: 'run', id}, {to: 'review', runId}, {to: 'story', id} …; a run by its public id, a UUID that a screen shows as its first eight characters, shortId) into a route or a panel — the studio gives a story's panel its own address, /studio/newsroom/stories/<id>. setDirty (optional) is told when the editor holds unsaved edits and when it no longer does: the studio asks before go or any navigation or account link leaves them (App.tsx, Shell.tsx), and a host without in-app navigation leaves it out. ESLint enforces it for packages/ui/src/**: no react-router or openapi-fetch import, no fetch, EventSource, XMLHttpRequest, WebSocket, storage, location or history global, no window.location or document.cookie, no dangerouslySetInnerHTML.
Rules the code keeps¶
- The editor never rewrites what nobody touched. A
markdownblock is kept verbatim by the platform, soRichTextopens a block in TipTap only when TipTap writes it back unchanged (roundTrips); anything else — Liquid, raw HTML, a list written with*— opens as source. Saving sends only the fields that changed, the body only if it changed, and the revision it was edited from, so the platform refuses a save over someone else's newer revision (409) rather than replacing it. Blocks keep their ids, so suggestions and provenance still find them; a block added in this session is keyed by a client key that follows it through edits, moves and removals, never by its position, because TipTap reads a block's content once. Aparagraphblock arrives in Wagtail's database format (internal links aslinktype/id), which TipTap cannot hold, so it opens as source and goes back in that format. - Unsaved edits are dropped only on the person's word. The editor keeps the revision its edits began from as their baseline. A newer revision (someone else's save, a suggestion accepted elsewhere, a pipeline) replaces a clean draft at once, and the editor's own save becomes the new baseline. Over a dirty draft it shows a notice instead: Keep my edits, after which a save is refused against the newer revision (409), or Discard and load latest. While the draft is dirty, the browser asks before a refresh or close (
beforeunload), and the host before navigating (setDirty). - Nothing publishes except the publish buttons. Save is a draft revision; accepting a suggestion or reverting is a draft revision; publish, schedule (a time to go live, a time to come down, or both) and unpublish are separate calls, each re-checked by the platform against the person's Wagtail permissions. A publish or a schedule names the revision the person reviewed — the one the save before it just made, else the one the editor shows — so a revision someone else saved in between is refused (409, shown as the failure notice) rather than published unseen (#61).
- A lock is shown, not worked around. A page a Wagtail lock keeps from the person (
page.lock: someone else's, a workflow task's, a scheduled publish's) opens read-only with the lock's own sentence; the platform refuses every write anyway (409resource.locked), and cancelling a schedule is the one action left. - "Accept all" is all that is shown. Accepting a run's suggestions sends the ids of the ones the inbox shows (stale ones left out), so a view filtered to one page, one site or the first hundred never accepts what nobody saw.
- A live timeline survives its stream. The run stream ends at the run's final status or at the server's time limit;
RunTimelinestops on a finalstatus, reopens a live run's stream after a pause, and backs off (1 s, 2 s, 4 s … up to 30 s) from a stream that broke. - Fields come from the platform.
FieldsPanelrenders the specs each page carries (field_specs: name, label, group, kind, choices), so a new field or page type needs no change here. Ajsonfield (a file's raw front matter) is Mantine'sJsonInput: its value is what the text parses to, key order kept, or the text itself while it does not parse, so a save sends what the person sees and the platform refuses it by field. - Every AI result is something a person reviews. A brief is applied as a new draft whose text waits as suggestions; the editor's AI panel asks for its answer as suggestions on the open page (the whole page, one block, or text selected in a block as saved —
run/withsuggest); a conversation's answer is read, asked again or promoted to a brief. Nothing an assistant writes is saved or published by the studio. - A selection is sent with where it is. The AI panel sends the field of a structured block it is in (each field's input carries
data-field) and the character it starts at, in code points, in the text a person sees: a field's own selection says where; a paragraph's source is HTML, so the place is counted in its readable text (DOMParser); in the rich editor it is counted in what TipTap shows — exact for a paragraph, and for Markdown only when the words show as often as they are written (else the platform takes a selection that appears once and refuses the rest with a reason). The platform swaps that text and nothing else. - A run is followed, never awaited. Anything that reaches a model answers
202with a run; the screen that started it showsRunProgress(useLiveRun, the run timeline's following) and reads what the run produced — the brief, the messages, the answer, the provider's health — once it is final. - One request per action. Every request that starts a run carries an
Idempotency-Keymade when the person acts (newKey, kept in the mutation's variables), so a repeat of that request replays the first run; its control waits while the request is out (and Ctrl+Enter with it); and a button that starts a run or makes a row ignores the second click of a double click (oneClick), however fast the platform answered the first. Saving a brief and generating it are two requests: a new brief is made once and opened whatever generating it answers, and every screen shows the latest request to generate a brief (useMutationState). A conversation opens on its newest messages and loads earlier ones on request (useInfiniteQuery,ordering=-seq), reading again only the pages it shows. - A credential only goes in. The provider form's credential field starts empty every time, sends a value only when one is typed (or an empty one when removing is asked for), and shows the stored one only as set or not set; the platform never returns it.
- Less code. Mantine for every control, TanStack Query for every request and cache, TipTap and
@mantine/tiptapfor rich text, jsdiff for diffs,openapi-typescript+openapi-fetchfor the client. A workspace adds a component to@zer0/ui, an entry toWORKSPACESand its destinations' workspace inHOME(which is all the extension needs to render it: a tab on its dashboard, and every destination it shows —HOMEis typed over the wholeDestinationunion, so a destination with no workspace fails the type check) and a route tostudio/src/App.tsx; an area that is not built yet already has its place in the navigation, naming its milestone. One limit of the extension's transport: it carries JSON and text, so a workspace that uploads a file (a PDF to capture, an image to the media library) works in the studio and says, in the extension, to do it there — recorded as a gap indocs/plan/capabilities.yml.
Libraries and versions¶
React 19, React Router 7 (the version TARGET.md names; 8 exists, and moving is a later, deliberate change), TanStack Query 5, qrcode.react (the studio host only: a TOTP set-up's QR code), Mantine 9 with @mantine/tiptap, TipTap 3 with @tiptap/markdown (also read-only, to render an answer's Markdown without injected HTML), jsdiff, get-nonce (the studio host only), @dnd-kit/core and @dnd-kit/sortable (a pipeline's steps, dragged with the pointer or the keyboard), openapi-typescript + openapi-fetch, Vite 8, Vitest 5 with Testing Library and jsdom, ESLint 10 with typescript-eslint, TypeScript 5.9 (typescript-eslint and openapi-typescript do not accept 6 yet). CI runs Node 24; jsdom needs Node 22.22 or newer.
The lockfile is committed and openapi-typescript is pinned exactly — a deviation from the hub's always-latest posture, recorded in AGENTS.md § Standard deviations: the committed schema.d.ts is that generator's output, so a floating generator would fail the drift check for no change of the API, and npm ci in CI and in the image needs the lockfile.
Tests¶
npm test runs the Vitest suites: packages/api/test (the client sends the CSRF token on unsafe requests only), packages/tokens/test (every token the theme reads exists, with both colours), packages/ui/test (the Markdown round trip and the source fallback; the editor's save, publish, schedule with an expiry and a locked page; a newer revision under a dirty draft kept, discarded or refused on save, taken silently by a clean one, and beforeunload held only while dirty; the SEO tab's Open Graph fields, canonical URL and noindex; the File tab's path and raw front matter, saved in the order written, and text that is not JSON refused by field; new blocks through removes and moves; a table's cells, rows and columns, a typed table's column types, a callout's fold and raw HTML's source, and a block of each new kind added; creating a page with and without the drafter; the inbox's diffs and decisions, and accepting only what it shows; revision compare and revert; the page list's tree and filters; the run timeline over a fake stream, its stop, reopen and back-off; the Ideas workspace's columns and votes, a board made and shared with a site and its sharing changed, capture with the topic template, a brainstorm followed to its reply and kept by picks, duplicates merged, the drawer's save of every field it edits, promotion to a draft; the Research workspace's sources, a collection made and shared, feeds subscribed to, paused and read now, capture by URL, note, upload and web search, a source's summary, kept quotes and sharing, cited answers with checked quotes, and the editor's citing and fact-checking), packages/ui/test/ai (providers — a credential never echoed, one check per double click — and the catalog; assistants created, edited, run and followed to their answer, exported and imported; pipelines created, reordered by dragging from the keyboard and by the buttons; schemas checked as typed and by the platform; briefs generated, reviewed and applied, made once when generating is refused; conversations answered live, sent once, asked again, promoted to a brief or a draft, filtered, and paged from the newest; the editor's AI panel on a page, a block and a selection — its field and occurrence — with an assistant or a pipeline; every run-starting request with its Idempotency-Key), packages/ui/test/outbox.test.tsx (the belt's numbers, filters, a message's journey and CloudEvent, an idea sent and a verdict answered with an approval, the relay run and followed, a refusal and missing permissions; a trial run once with its key and followed to its result and ledger; a claim check, its verdicts, its resolution and calibration), packages/ui/test/automations.test.tsx (an automation made paused from its trigger, condition and actions, once; its condition tried against the sample payload; its actions reordered from the keyboard; its secret shown once and kept while it is open; enabled and paused; a dry run, and a real run with its Idempotency-Key followed into the run history and its links; YAML export and import; read-only for someone it is shared with), packages/ui/test/distribution.test.tsx (the queue; a post approved, published after asking with force only when ticked, its text saved as what changed and Publish held while it is unsaved, a rejected post read-only, a post found after a failure recorded, its notes, an email post while the newsroom sends; Distribute from a page and a story; a channel's credential set once and never shown, LinkedIn's consent screen, arming, the ledger file downloaded and imported, check and statistics for managers only, removing it after asking and the platform's refusal; the ledger and statistics), packages/ui/test/account.test.tsx (the sign-in screen by password, username or email, its second factor and one left pending, a passkey, a provider, sign-up with a code, a sign-in code, a reset by code; the account menu's TOTP behind a password asked again, its key and QR code, sessions ended, a read-only token issued and shown once, revoked, and the tokens alone with no browser session), studio/test (sign-in through allauth and back to the admin that asked, the provider form POST, sign-out, the account routes, the navigation with every area and its question before leaving unsaved edits, the routes — the Outbox desk's tabs, a trial and a check among them — the AI and Create areas' tabs and destinations, the event-stream transport) and packages/webview/test (the extension's webviews as dist/studio.js mounts them, over a fake extension host and platform: a tab per registered workspace, the editor with its revisions and publish, the review inbox's diffs, the run list and a run followed over the host, the page behind the open file — one, none or several — requests that name a method, a path, a body and only the headers the platform reads, never a credential, and an upload refused rather than sent as text; and host.test.tsx, the extension's proof standard — the same App over connect(port) with every message handed to the real StudioBridge (src/core/studio/bridge.ts, imported across the tree because it imports nothing; web.yml runs on a change to it), whose only fakes are the platform behind fetch, the modal and the token: a row for every capability whose extension cell in docs/plan/capabilities.yml names it, and rows for workspaces whose cells still name webview.test.tsx or stay partial, each asserting the request reached the platform with its origin, the Bearer token and, where the workspace sends one, its Idempotency-Key, that the host asked exactly when the change is live, and that the workspace shows the reply). The platform's side is content/tests/api/, content/tests/ai/ and content/tests/outboxdesk/. The browser scenarios verify/scenarios/studio-*.yml drive the built studio on the seeded platform with Playwright (node verify/runner.mjs, set up by verify/verify.yml; the AI ones answered from verify/recordings/), with evidence under test/evidence/.