Frontend design

From google/capsem · View interactive version

Frontend design is an AI agent skill from the GitHub repository google/capsem. Capsem frontend design system. Use when building UI components, styling views, choosing colors, or working with Svelte 5 runes and the component library.

How to use this skill

Skill file

Frontend Design

Stack

Loading into capsem-app (Tauri)

tauri::generate_context!() bakes web/app/dist/** into the capsem-app binary at cargo compile time (via the custom-protocol feature). This means:

Also: iframe src for bundled pages must end in index.html (e.g. /vm/terminal/index.html). Tauri's custom protocol on macOS does not auto-append index.html for trailing-slash paths the way Vite/Astro dev server does. A /vm/terminal/ src loads fine in Chrome dev mode and silently 404s in the Tauri app.

Design principles

Simplicity and correctness above all else. Every line of frontend code must earn its place.

Framework references

Surface hierarchy (global.css overrides)

The UI uses a two-tone surface system. Semantic token names map to specific roles:

| Token | Light | Dark | Role |

|-------|-------|------|------|

| --background | #ffffff (white) | #282828 (rgb 40,40,40) | Main canvas (content area) |

| --background-1 | #f4f3f2 (rgb 244,243,242) | #282828 | Recessed (address bar, inset panels) |

| --background-2 | #f4f3f2 | #282828 | Most recessed (inactive tabs) |

| --layer | #ffffff (white) | #3c3c3c (rgb 60,60,60) | Elevated/selected (active tab, toolbar, cards) |

The pattern: selected = white/lighter, inactive = slightly gray/darker. In dark mode, the base is very dark (#282828) and elevated surfaces pop with #3c3c3c. In light mode, the canvas is white and recessed areas use a warm off-white.

These are set in :root and .dark blocks in global.css. All accent themes share the same surfaces -- only --primary-* changes per accent.

Color scheme (firm -- do not deviate)

Terminal theme contrast

All 24 terminal themes (12 families x dark/light) must pass WCAG AA 4.5:1 contrast ratio for foreground text and all 6 ANSI colors (red, green, yellow, blue, magenta, cyan) against their background. This is enforced by theme-contrast.test.ts.

Contrast utilities (parseHex, relativeLuminance, contrastRatio) are exported from themes.ts and used in tests. When adding or modifying terminal themes, run pnpm test to catch any violations.

Component patterns

Use Capsem's semantic token classes for all UI components. Historical pattern references may guide layout, but no upstream CSS or JavaScript may enter the build.

Do NOT use raw Tailwind colors (bg-gray-200, text-blue-600) for UI chrome. Always use semantic tokens so themes work.

Settings section layout (SettingsSection.svelte)

The Appearance section in SettingsPage.svelte is the reference pattern. All dynamic settings sections must match it:

Custom design tokens (`global.css`)

Domain-specific tokens defined in @theme { } block:

| Category | Tokens | Purpose |

|----------|--------|---------|

| Status | --color-allowed, --color-denied, --color-caution | Decision states |

| Providers | --color-provider-anthropic, -google, -openai, -mistral | Brand identity |

| Token types | --color-token-input, -output, -cache | Usage tracking |

| File actions | --color-file-created, -modified, -deleted | FS events |

| Syntax | --color-json-*, --color-sh-* | Code highlighting |

| Spans | --color-span-thinking, -tool, -answer | Trace viewer |

| Charts | --color-chart-grid, -label | Chart infrastructure |

Svelte 5 rune patterns (mandatory -- no legacy `$:`)

All components and stores use Svelte 5 runes exclusively. No legacy reactive statements.

Store pattern

// stores/example.svelte.ts
class ExampleStore {
  items = $state<Item[]>([]);
  activeId = $state<string | null>(null);
  active = $derived(this.items.find(i => i.id === this.activeId));

  async load() { this.items = await api.getItems(); }
  setActive(id: string) { this.activeId = id; }
}
export const exampleStore = new ExampleStore();

Icon pattern

<script lang="ts">
  let { class: cls = 'size-5' }: { class?: string } = $props();
</script>
<svg class={cls}>...</svg>

View routing

Chrome browser shell. Tabs = sessions, toolbar = controls. Views switched by tabStore.active.view:

Tab store (stores/tabs.svelte.ts): openVM() creates a terminal tab or activates existing.

Data fetching

The frontend talks to the backend through capsem-gateway -- a TCP-to-UDS reverse proxy (default port 19222) that forwards HTTP requests to capsem-service over UDS. Bearer token auth is required (token generated at gateway startup, written to ~/.capsem/run/gateway.token).

Key gateway endpoints:

| Endpoint | Purpose |

|----------|---------|

| GET / | Health check (no auth) |

| GET /status | Aggregated VM status (1s cache TTL) |

| GET /vms/{id}/stream | capsem.stream.v3 WebSocket (terminal, streaming exec, container attach), tunneled to the service |

| Explicit allowlist | Settings, session, stats, enforcement, detection, plugin, MCP, credential, and debug routes used by the UI/TUI |

The gateway forwards only routes that are deliberately registered in its route table.

Unknown, retired, or misspelled routes must return 404 instead of falling through to

capsem-service.

Typed data contract:

/vms/{id}/timeline, /vms/{id}/security/latest,

/vms/{id}/detection/latest, and protocol-specific routes.

/stats, /vms/list, and settings/plugin/MCP routes.

surfaces are burned; UI code reflects typed API contracts only.

Mocks must exercise the same typed routes the product uses.

Code reuse

Before creating new components, stores, or helpers, check what exists:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.