# Web

The Angular frontend — an agent workspace. Runs at <http://localhost:4200> in
development and is loaded by the Tauri window; a packaged build serves the
bundle in `dist/web/browser`.

```bash
npm run dev:web          # just this app
npm run lint -w @glassbeetle/web
npm test -w @glassbeetle/web
npm run build -w @glassbeetle/web
npm run format -w @glassbeetle/web
npm run format:check -w @glassbeetle/web
```

## What the UI covers

The workspace is built around conversations. The window opens on an empty
chat, ready to be typed into; the rail lists the conversations — grouped by
project, then by when they were last active — on every screen, and the
configuration surfaces (teams, memory, prompts, overview, spending) sit folded
at its foot.

| Surface | Endpoints |
| --- | --- |
| New chat | `POST /chats`, `POST /chats/:chatId/messages`, then a streamed completion |
| Chats · conversation | `/chats/:chatId`, `/chats/:chatId/messages`, `POST /chats/:chatId/completions` (SSE), `/chats/:chatId/context`, `POST /chats/:chatId/compact` |
| Chats · directory | `/chats` |
| Projects | `/projects`, plus `/chats` and `/artifacts` filtered by `projectId` |
| Artifacts | `/artifacts`, `/artifacts/:artifactId` |
| Agents · directory | `/agents` |
| Agents · workspace | `/agents/:agentId`, `/agents/:agentId/picture` |
| Agents · memory | `/agents/:agentId/memories` |
| Teams · directory | `/teams` |
| Teams · roster | `/teams/:teamId`, `/teams/:teamId/members` |
| Shared memory | `/memories` |
| System prompts | `/system-prompts` |
| Overview | `/health`, plus each collection's `total` and `updatedAt` |
| Profile | `/user`, `/user/picture` |
| Spending | `/budget` |

The model catalogue (`/models`) is read once by the shell so an agent is shown
with the model it runs on wherever it appears.

## Runs

A turn is sent in two requests the API keeps apart: the message is stored,
then the reply is streamed from `POST /chats/:chatId/completions`. The run
belongs to `core/workspace/chat-runs.service.ts`, not to the chat screen, so
it carries on when another conversation is opened; the rail marks a chat
while its agent is working, and flags one whose run finished unseen. Stopping
a run closes the connection, which the API turns into a cancelled model call.

What the transcript says an agent is doing — starting, reasoning, writing — is
read from the stream's own events, never guessed. A failed run is shown under
the stored turn with the API's reason and a retry, so nothing has to be typed
twice.

## What the UI does *not* invent

The schema in `data/` describes a product with chats, teams, tool calls,
artifacts and usage events. Several places where it would have been easy to mock something, and what is
shown instead:

**Agent state outside a run is readiness, not activity.** A chat shows an
agent working only while a run it started is streaming. Elsewhere nothing
reports whether an agent is busy, so `core/agents/agent-readiness.ts` derives
readiness from stored configuration — is anything steering this agent?

**The feed is recent changes, not a run history.** Nothing serves
`usage_events` as a feed. `core/activity/activity.service.ts` assembles one
from the `created_at` / `updated_at` every resource already carries, and the
panel is labelled as configuration history.

**Spending is real arithmetic over an unpriced log.** `/budget` does sum
`usage_events.cost_usd` for the current period, and completions do write those
rows — but with `cost_usd` still NULL until per-token pricing lands, so every
installation's chargeable count stays zero. The screen says so in as many words
instead of presenting a full budget as a measurement, and the deck's meter
draws no value ring until there is a limit to measure against.

**The agent's Context tab is not a rendered prompt.** `GET /chats/:chatId/context`
assembles one for a chat, but this tab has no chat — it shows the configured
layers (system prompt, personality, instructions, shared and private memory),
each with its real size and source, and says so on screen. Memory is counted in
entries rather than characters, because only a page of it is loaded and a
character total over a partial read would be wrong in a way the number would
not reveal.

## The models capability

`agents.model_id` is a foreign key into `models`, and `POST`/`PATCH /agents`
rejects any value that is not a real row with a 422 `MODEL_NOT_FOUND`.
`/api/v1/models` returns 404. **No agent can currently be given a model.**

`core/platform/capabilities.service.ts` probes `/models` once at startup, and
the UI adapts rather than blaming the user for a backend module that has not
shipped:

- readiness ignores the missing model and judges only what the user controls;
- the configuration meter excludes it, so 100% is reachable;
- the model field is disabled with the reason stated in place, instead of
  letting the user discover it by failing to save.

Only a definitive 404 counts as a completed probe — an unreachable API says
nothing about the capability. **When the providers and models endpoints ship,
delete nothing: the probe starts returning 200 and all three behaviours switch
back on their own.**

## The deck

The window chrome is the app's, not the operating system's. Everything along
the top is one component — the deck — and each control on it earns its place by
showing something the screen below cannot.

**The workspace control** (the settings gear) sits in the foot of the rail, 
not on the deck. It opens a panel, not a menu. A menu is a list of commands; 
this answers what am I connected to, what is in it, is it healthy with live values, 
and offers the few actions that belong to the workspace rather than to a screen. 
The backend's state shows on the gear as a single dot on its corner, 
so a degraded API is noticed without a second widget.

**The fleet gauge** is the agents, in the chrome. The rail lists them too, but
the rail collapses and the chrome never does — so this is what remains on a
narrow window. It is not a second roster: it answers *is the fleet ready*, and
surfaces only the agents that are not, as overlapping avatars that lead
straight to them. It is derived from the roster the rail already loaded, so it
costs no request.

**The spine** is the sheet's top edge: a two-pixel line, split proportionally by agent 
readiness. It costs no height and adds no control. It means the sheet itself reports 
how much of the fleet is configured, on every screen. An unreachable API overrides it, 
because nothing it could report would be trustworthy while the backend is silent.

## Window chrome

The window is **undecorated** (`decorations: false`), so the title bar, the
controls and the drag surface are all drawn by the app. That has consequences
worth knowing before changing any of it.

**The controls are the only ones there are** — not a skin over native buttons.
They keep the platform's *position* (left on macOS, right elsewhere), because
that is muscle memory worth more than symmetry, while the look is the
product's: flat glyphs that only take on colour under the cursor.

**Dragging needs `core:window:allow-start-dragging`.** `core:window:default` is
read-only and grants none of the window operations, so without it the call is
denied silently and the window cannot be moved at all. The same applies to
`allow-minimize`, `allow-toggle-maximize` and `allow-close`.

**Resizing is the app's job off macOS.** An undecorated window on macOS still
resizes from its borders; on Windows and Linux that border belonged to the
frame that is no longer there, so the shell renders invisible edge strips that
call `startResizeDragging`. `DesktopService.needsResizeEdges` decides. 

The window is transparent (`transparent: true`, with `macOSPrivateApi: true`) and carries 
`windowEffects` (`liquidGlassRegular`, `hudWindow`, `acrylic`) with `state: 
followsWindowActiveState`, so the OS glass shows through the chrome. It has no OS shadow
(`shadow: false`), because a transparent window's shadow would trace the old rectangle; 
the edge is a lit rim drawn in CSS instead. The glass view ignores the corner radius 
it is given, so `apps/desktop/src-tauri/src/corners.rs` reaches into AppKit to round and clip 
the window's own views. The radius is pinned at 32 in three places: `WINDOW_RADIUS` 
in `corners.rs`, `--gb-radius-window` in `styles.scss`, and `windowEffects.radius` 
in `tauri.conf.json`. Change all three together.

## The native menu

Small on purpose. Product navigation lives in the deck, where it can show state
a menu cannot; rebuilding it as a tree of labels would be a worse copy of what
is already on screen. The menu keeps what the OS owns and the webview cannot
provide: the application menu macOS expects, clipboard and undo for text
fields, window commands, and the two links that belong in the system browser.

The handful of product items that remain are there because macOS users look for
them in the menu bar. They emit an action id and implement nothing — the
keyboard, the menu and the workspace panel all route to `runAction` in the
shell, so an action behaves identically however it was reached. Adding one
means a case in `ShellAction` and a case in the switch; forgetting the second
is a compile error.

Shortcuts are bound in the frontend rather than only as menu accelerators, so
they work the same in a browser tab.

## Window reveal

The window is created with `visible: false` and shown when the shell emits
`glassbeetle://ready` after its first render, because a webview shown before
that is a white rectangle for a moment — very visible against a dark
workspace. Rust also reveals it unconditionally after four seconds: a window
that waits on the frontend is only as reliable as the frontend, and a window
showing an error beats no window at all.

## System accessibility settings

When the browser reports reduced transparency or increased contrast, the chrome
and the desktop backdrop use opaque colors and the glass blur is off.
Forced-colors mode also removes decorative shadows and rims so the system
palette can draw the surfaces. These preferences take effect while the page is
open. The native Tauri window still uses the transparency configured at startup.

## Layout

```
src/app/
├── core/          Services with no UI: one per API resource, plus readiness,
│                  activity, capabilities, roster, theme, notifications.
│                  Nothing here imports a component.
├── shared/        `ui/` primitives (panel, skeleton, readiness badge),
│                  `styles/` mixins, list state, dialogs, pipes.
└── features/      One folder per surface, each lazily loaded by the router.
```

## Conventions

**Theme.** One `mat.theme()` with `theme-type: color-scheme`, then
`mat.theme-overrides()` swaps Material's generated neutrals for the product
palette in `src/styles/_palette.scss`. That is what stops this looking like a
default Material app, and it means no component restyles itself: everything
reads `--mat-sys-*`. Density is -2. Light and dark are one stylesheet; switching
flips `color-scheme` on `<html>`. Dark is the default.

**Surfaces.** `gb-panel` is the surface primitive — a hairline border and a flat
fill, not elevation. A screen shows several at once, and stacked elevated cards
read as a pile of documents rather than regions of one workspace.

**Screen layout.** `shared/styles/_view.scss` holds the `view`, `blank-state`,
`pill`, `toolbar`, `rows` and `tags` mixins. A new screen `@use`s those rather
than re-typing the idioms; that shared vocabulary is what keeps the surfaces
looking like one product.

**Loading.** Skeletons shaped like the result, not spinners: the layout does not
jump when the data lands.

**Team order.** A team's roster is its turn order, so the list is explicitly
ranked and moved with controls rather than sorted by anything incidental. A
move sends the whole order to `PUT /teams/:teamId/members/order`, which is what
that endpoint takes: a move renumbers several rows, and sending the end state
makes it one atomic write rather than a sequence that can half-apply. The
roster is re-read afterwards instead of patched in place — positions are
renumbered server-side on every add, remove and reorder, and guessing the
result here would be a second implementation of the same rule. Agent names come
from the roster the shell already holds; the API returns ids, so there is one
source for a name and the rail and the team page cannot disagree.

**Chat ownership.** A chat belongs to exactly one agent or one team, and the
API refuses to move it afterwards — the history was produced under that owner.
So the owner is asked for when the chat is created and shown as a fact, not a
field, on its page. The chat list filters by title, like the other lists, and
by owner; both go to `GET /chats` as `search` and `agentId`/`teamId`, so the
filtering happens before pagination. Only the title is searched: the compaction
summary is not, since nothing writes it yet. Both
owner columns are nullable, since deleting an agent or a team keeps its chats,
so "owner deleted" is a state the list renders and can filter for.

**Avatars.** One component, `gb-avatar`, draws a stored picture when there is
one and initials when there is not — with the hue derived from the name, so a
subject keeps its colour without the server holding a palette. A picture that
fails to load falls back to the initials, because `GET /user/picture` can
legitimately 404 for a database restored without its files, and a broken-image
glyph would be a worse answer. The agent roster and the user's own avatar are
the same component.

**Talking to the API.** Every resource has a service extending `ApiClient`,
which holds the absolute base URL from `src/environments/` — a packaged Tauri
app is served from `tauri://localhost`, so a relative `/api` would resolve
against the custom protocol. Query parameters go through `toHttpParams`, which
drops `undefined`, `null` and empty strings: the API reads `?search=` as a
search for the empty string, not as the absence of a filter. The literal
`'null'` is preserved, because the agents endpoint uses it to select rows whose
foreign key is NULL.

**Errors.** `toApiError` normalises an `HttpErrorResponse` into the envelope
from [`docs/api-conventions.md`](../../docs/api-conventions.md). Status 0 means
the request never got a response, reported as "the API is unreachable" rather
than as whatever empty body came back. Validation failures carry one `details`
entry per failing constraint and a generic `message`, so `describeApiError`
shows the details.

**Patching.** A PATCH body carries only the fields that changed. An omitted key
leaves the column alone, an explicit `null` clears it, and `""` would store an
empty string the API then reports as set — so a cleared field is sent as `null`,
never `""`. An unchanged form sends nothing, which the API treats as a no-op and
which keeps `updated_at` honest.

**Lists.** Paging, sorting and debounced search live in `ListState`, which every
collection instantiates as a component field. Requests go through `switchMap`,
so a slow page-1 response cannot land after a fast page-2 one. Deleting the last
row on a page steps back rather than leaving an empty one. `resource()` and
`rxResource()` would cover some of this but are still experimental in Angular 21.

**Offline assets.** The icon font is bundled (`material-symbols`) and the
typography uses the platform UI font. A packaged Tauri app cannot rely on
reaching the Google Fonts CDN.
