# React App Shell (`style: app`)

> The app shell is a React interface for the PraisonAIUI dashboard: a sidebar,

The app shell is a React interface for the PraisonAIUI dashboard: a sidebar,
a header with a command palette (⌘K / Ctrl+K), a React chat and a host that
runs every existing dashboard page inside it. **It is the default style**
(owner decision, 2026-11-22): `create_app()`, `aiui run app.py` and an app
that registers pages all open it. The vanilla-JS `dashboard` is the legacy
UI; it still renders exactly as before when you ask for it:

| Where | Legacy dashboard |
|---|---|
| YAML config | `style: dashboard` |
| Python | `aiui.set_style("dashboard")` |
| CLI | `aiui run app.py --style dashboard` (prints a one-line legacy notice) |
| Environment | `AIUI_SHELL=legacy` |

## Turn it on explicitly

Any one of these:

| Where | How |
|---|---|
| YAML config | `style: app` |
| Python | `aiui.set_style("app")` before the server starts |
| CLI | `aiui run app.py --style app` |
| Environment | `AIUI_SHELL=app aiui run app.py` (alias: `AIUI_SHELL=react`) |

`AIUI_SHELL=app` only changes the `dashboard` style into
`app`. Other styles (`chat`, `docs`, `agents`, `playground`, `custom`) are
never rewritten.

### Kill switch

`AIUI_SHELL=legacy` turns `app` back into `dashboard`, whatever the config
says. It is the documented way back once the default flips (see
[flip criteria](#when-the-default-flipped)).

```bash
AIUI_SHELL=legacy aiui run app.py   # always the vanilla dashboard
```

## What you get

- **Every page you have today.** A page is resolved in this order:
    1. a React page registered through the SDK (built-in ports such as chat, or
       a [UI plugin](https://ui.praison.ai/docs/features/plugins.md) page);
    2. a server-driven page (`register_page` with a handler, `@aiui.page`),
       rendered from its `_components` tree as blocks;
    3. otherwise the original dashboard view, mounted inside the shell.

  Nothing disappears: dashboard plugins (`kanban`, `sample-board`,
  `video-studio`), `set_custom_js` and `custom.js` `registerView` pages keep
  working as hosted pages.
- **React chat** over the WebSocket `/api/chat/ws` (streaming, tool calls,
  reasoning, inline approvals and questions, attachments, Stop, history).
  When the socket cannot open it falls back to Server-Sent Events (`POST /run`);
  on SSE an agent's question says that answering needs a live connection.
- **One markdown renderer** (Streamdown) for chat and docs, with lazy code
  highlighting (74 languages), Mermaid and KaTeX. In chat, external links open
  in a new tab with `rel="noopener noreferrer nofollow"`, and remote images
  are shown as a click-to-load placeholder naming their host (same-origin,
  `data:image/` and `blob:` images load directly).
- **Approval toasts.** A new approval anywhere raises a toast with a
  "Review" button that opens the Approvals page. On the chat page the
  approval is shown in the thread instead.

## Compatibility

| Existing API | `dashboard` (default) | `app` (opt-in) |
|---|---|---|
| `register_page` with a handler / `@aiui.page` | unchanged | server-driven blocks page |
| `register_page` without a handler | unchanged | hosted `custom.js` `registerView` page |
| `register_page_action` | unchanged | the page's action endpoint |
| `set_pages`, `pages.enabled/disabled` | unchanged | applied |
| `set_custom_js` | unchanged | injected; runs when the hosted runtime loads |
| `set_custom_css` | unchanged | unchanged; HSL triples warn (see below) |
| `set_theme`, `set_brand_color`, `register_theme` | unchanged | converted to theme seeds |
| dashboard plugins | unchanged | hosted pages; `dashboard.plugins` allowlist honoured |
| `chat`, `docs`, `agents`, `playground`, `custom` styles | same app, now lazy-loaded with the new markdown renderer and tokens | n/a |
| `aiui build` static docs | same app; loads content-named copies `index-<hash>.js`/`.css` | n/a |

## Theme seeds (migration)

Colours now come from a small set of **seeds** (`--seed-accent`,
`--seed-ink`, `--seed-paper`, …). Everything else (`--background`,
`--primary`, sidebar and chart colours) is derived from them in CSS with
`color-mix()`, separately for light and dark. Python emits seeds only
(`praisonaiui.themes.get_seed_theme_css(preset, radius, accent, density)`):

- neutral presets (`zinc`, `slate`, `stone`, `gray`, `neutral`) are
  monochrome: the accent follows the ink;
- colour presets (`rose`, `blue`, …) seed the accent from the 600 shade in
  light mode, and the button text colour is picked automatically for
  at least 4.5:1 contrast;
- radius presets are unchanged.

`get_theme_css()` is kept for API compatibility but the compiler no longer
uses it. Runtime themes (`register_theme`, named presets) are converted to
seeds in the browser.

### Breaking change: bare HSL triples

Listed in the [changelog](https://github.com/MervinPraison/PraisonAIUI/blob/main/CHANGELOG.md) for the release that ships the
app shell.

shadcn variables used to hold bare HSL triples that the stylesheet wrapped in
`hsl()`. They are now complete colours:

```css
/* before (no longer valid) */
:root { --primary: 221 83% 53%; }

/* after: any CSS colour */
:root { --primary: hsl(221 83% 53%); }

/* better: set the seed, and every derived colour follows in both modes */
:root { --seed-accent: hsl(221 83% 53%); }
```

`aiui validate` warns (code 5001) when `site.custom_css` sets one of these
variables to a bare triple. Custom CSS and runtime themes that still use
triples are converted in the browser where possible, but update the CSS.

## Caching and deploys

- Code chunks are content-hashed (`assets/<name>-<hash>.js`) and served with
  `Cache-Control: immutable`. `assets/index.js` and `assets/index.css` keep
  fixed names in the bundle; the server references them as `?v=<hash>`, so a
  release never mixes an old entry with new chunks.
- `aiui build` writes content-named copies of both,
  `assets/index-<sha256[:10]>.js` and `assets/index-<sha256[:10]>.css`, and
  loads them from `index.html` and every route page. A static host such as
  GitHub Pages ignores the query string, so `?v=` alone could pair a cached
  old page with the new entry. `index.js` and `index.css` stay in the build,
  so a page cached before the switch still loads, and the copies are listed in
  the site's `aiui-manifest.json` (keys `aiui-entry-copy:<file>`), so the
  deploy's carry-forward keeps them next to the chunks. When a chunk imports
  the entry module (none does today) the build keeps `index.js?v=`, which
  would otherwise load the entry twice.
- The docs deploy keeps the previous build's chunks, and with its ledger
  (`aiui-carried.json`) older builds' chunks for `--keep-days` (default 2)
  (`src/frontend/scripts/carry-forward-assets.mjs`), so a reader with an
  old page open can still load its lazy parts.
- A stale chunk that does fail to load triggers one automatic reload, and
  only when the server's HTML (fetched past the cache) names another build.
  The reload opens the page as `?aiui-build=<build>`, a URL no browser or CDN
  cache holds, and the boot removes the parameter again. When the boot
  chunks themselves cannot load, the page says so and offers Reload.
- A docs page never waits for good: each markdown request has a time limit
  for its headers and one for its body, a stalled request is sent again,
  and a page that still cannot load shows "Couldn't load this page" with
  Retry (`src/frontend/src/docs/docLoader.ts`). A retry also moves to a
  fresh connection (it switches between requests with and without
  credentials, which the browser keeps on separate connection pools), so a
  connection that a router dropped while idle does not cost the page. An
  attempt with no response headers after 1 s (0.4 s after 10 s without a
  request) also goes out on the other pool and the first answer wins; a
  request that fails outright switches at once. A visitor coming back after
  10 s without input sends one small request (`ui-config.json`) the same way,
  so the next click already uses a working connection.
  `python -m preqa netfault` reproduces the dead connection (budget 2.5 s;
  measured 0.15-0.19 s).
- Static files are sent gzip-compressed. Each file is compressed once per
  version (path, mtime, size) in a worker thread and kept in memory (at most
  64 MB), so a cold page load does not compress the bundle again on the
  event loop. Range requests get the plain bytes. The page HTML,
  `/api/shell/manifest`, `/api/pages` and dashboard-plugin files are
  compressed too.
- `aiui run app.py` serves the bundle from the installed package; it no
  longer copies it into `./aiui` on every start (a `./aiui` left by an older
  version is ignored for a chat app; delete it). A site built with
  `aiui run --config` is served gzip-compressed with `Cache-Control:
  no-cache`, like `aiui serve`, and its own `assets/` (for example
  `theme.css`) is looked up after the package's.
- `aiui serve` answers a page's canonical URL (`/docs/x`) from `docs/x.html`
  directly, without a redirect to `/docs/x/`.

## Quality gates

| Gate | Command (in `src/frontend`) | Limit |
|---|---|---|
| Types | `npx tsc -b` | 0 errors |
| Unit tests | `npm test`, `npm run test:scripts` | all pass |
| Size (gzip) | `npm run size` | shell boot ≤ 151.3 kB, chat route ≤ 144,500 B, /chat first-screen JS ≤ 264,400 B, `index.css` ≤ 32 kB, Streamdown ≤ 100 kB, shikiPlugin ≤ 55 kB, legacy App path ≤ 250 kB, docs Try it chunk ≤ 7,566 B, Pro fonts (Geist + Geist Mono woff2) ≤ 58 kB, Paper fonts (Newsreader + Source Sans 3 + JetBrains Mono woff2) ≤ 140 kB, all assets ≤ 11,180,139 B uncompressed |
| First screen stays light | `npm run check:closure` | no Streamdown, Shiki, Mermaid, KaTeX or assistant-ui in the static closure of the entry, the shell or the legacy App |
| Committed bundle | `npm run check:bundle` | `templates/frontend` equals a fresh build (pull requests that touch the frontend only) |
| Browser suites | `npm run test:e2e` | see `src/frontend/e2e/README.md` |

The docs style preloads Streamdown before first paint (about 98 kB gzip on
that path). The HTML parser it needs for raw HTML and docs components
(rehype-raw, about 48 kB) is a chunk of its own that only pages whose
markdown has HTML load (`markdown/rehypeRawGate.ts`). This is an accepted
exception until docs pages are pre-rendered at build time.

## When the default flipped

The owner made `app` the default on 2026-11-22, before every criterion below
was met. The table is kept as the remaining work list:

| # | Criterion | Status |
|---|---|---|
| 1 | Every page renders in the shell with status ready, 0 page errors and 0 leak delta in the Playwright sweep | **Not met.** Every manifest page is ready (a page that prints a JSON error body, or whose own data endpoint fails, now counts as an error; the Inspector was one and is fixed), 0 page errors, no page grows per visit, and every page opens by URL. Three pages keep a one-time residue after their first visit that does not grow, each listed with its reason in the sweep's `FIRST_VISIT_ALLOWANCE` (any other or larger residue fails): `chat` (13 window listeners and the composer's hidden measuring textarea), `chat-canvas` (one window listener) and `code-studio` (Monaco's interval, listener and two body nodes) |
| 2 | Chat parity complete | **Not met.** Done: streaming, tools, reasoning, approvals, ask, attachments, Stop, history, feedback, session rail, reconnect. Missing: message queue, channel messages with unread dots, context ring and compaction banner, cost chip, memory panel, floating and focus modes |
| 3 | Light mode correct on every page; owner signs off the light and dark screenshots | **Not met.** Awaiting owner review |
| 4 | Gates green: size, bundle-sync, entry closure, screenshots, pytest, tsc | **Partly.** All run green locally; screenshot comparison is not enforced in CI until Linux baselines exist |
| 5 | `set_custom_js`, `custom.js` `registerView` and the three bundled dashboard plugins work under `app` | **Met in this build.** The three dashboard plugins pass the sweep; the e2e app-shell server sets `set_custom_js` with a `registerView` for a page that also has a server handler, and the client view wins (as in the legacy dashboard) |
| 6 | One minor release with `app` opt-in, then two weeks with no open P1 from opt-in users | **Not met** |

## Plugins and trust

See [UI Plugins](https://ui.praison.ai/docs/features/plugins.md). Installing a plugin package means trusting it:
its Python runs in the server process and its JavaScript runs in the page
with no sandbox. An `iframe` page is the sandboxed option.

## Related pages

- [UI Plugins](https://ui.praison.ai/docs/features/plugins.md)
- [PraisonAIUI → ADP Field Mapping](https://ui.praison.ai/docs/protocols/adp/aiui-mapping.md)
- [Theme System](https://ui.praison.ai/docs/features/theme-system.md)
