Preview server

From linuxdevel/Avalonia-skills · View interactive version

Preview server is an AI agent skill from the GitHub repository linuxdevel/Avalonia-skills. Use when the user wants to see and choose between visual design alternatives for an Avalonia app before implementation — generates 3 design variants as real .axaml files, renders each to PNGs at multiple viewport sizes (compact/wide × light/dark) using Avalonia.Headless, and serves an HTML compariso

How to use this skill

Skill file

Preview Server — Visual Variant Picker for Avalonia

What this does

Lets the agent show the user 2–3 design alternatives as actual rendered Avalonia screens (not HTML mockups), in a browser-based side-by-side comparison gallery. The user picks one and the agent then builds the chosen design out into the real app.

Why "real Avalonia" matters: HTML mockups misrepresent how Avalonia's Skia renderer, FluentTheme, ControlThemes, acrylic, shadows and font rendering actually look. A user who approves an HTML mockup is often disappointed by the real app. Rendering the actual XAML guarantees fidelity.

When to use

Must use

Skip

High-level flow

1. Agent reads requirements        (uses brainstorming skill if unclear)
2. Agent generates 3 variant       .axaml files in .preview/variants/{1,2,3}/
3. Agent runs render script         renders each variant via Avalonia.Headless
                                    → .preview/output/{variant}/{viewport}-{theme}.png
                                    (e.g. 1/wide-light.png, 1/wide-dark.png,
                                          1/compact-light.png, 1/compact-dark.png)
4. Agent runs serve script          starts python http.server, builds index.html
                                    gallery, prints URL: http://localhost:PORT
5. User reviews in browser, replies "I like variant 2"
6. Agent stops the server, copies   .preview/variants/2/* into the real project
   the chosen variant into the
   actual app

The user never has to install anything beyond what's already needed for Avalonia development plus Python (already required by ui-ux-pro-max).

Prerequisites

The scratch project is a bare Avalonia console app referencing:

Optional packages added per variant if it uses them: FluentAvaloniaUI, SukiUI, Semi.Avalonia, Material.Avalonia, Lucide.Avalonia, Material.Icons.Avalonia, Svg.Skia.

Variant generation rules

Generate exactly 3 variants that are meaningfully different, not three shades of the same idea. Use this matrix:

| Slot | Variant identity | Typical theme combo |

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

| A — Conservative | Safe, professional, native-feeling. Lowest risk pick. | FluentTheme + FluentAvalonia |

| B — Modern Flat | Opinionated, low-chrome, accent-driven. "Linear/Vercel" energy. | SukiUI or Semi.Avalonia + custom tokens |

| C — Distinctive | A bigger swing — bold accent, heavier type, denser layout, or a Material-spec take. | Material.Avalonia or Semi.Avalonia + bold accent or SukiUI dark with neon accent |

If the user has already constrained the choice ("we're using Material"), generate 3 variants within that theme that differ in palette, density, or layout instead.

Each variant must include:

Reference the design-system, themes, and components sub-skills for the actual XAML content.

Workflow for the agent

Step 1 — Confirm scope

Before generating variants, confirm with the user:

Skip if the user has already given enough detail.

Step 2 — Scaffold the preview host (once per project)

python3 skills/avalonia/avalonia-pro-max/preview-server/scripts/scaffold_host.py

Creates .preview/AvaloniaPreviewHost/ if missing. Idempotent.

Step 3 — Write the 3 variants

Author the XAML files under .preview/variants/{1,2,3}/. The structure for each:

.preview/variants/1/
├── README.md              # 3-5 bullet design intent
├── Resources.axaml        # tokens (theme dictionaries)
├── Styles.axaml           # component styles
├── PreviewScene.axaml     # the screen to render
└── packages.txt           # optional: extra NuGet refs needed (one per line)

The render script will inject Resources.axaml + Styles.axaml into the host App and load PreviewScene.axaml as the window content.

Step 4 — Render to PNG

python3 skills/avalonia/avalonia-pro-max/preview-server/scripts/render_variants.py

What it does:

  1. For each variants/{N}/:
  1. Outputs total render time + path to gallery script

Default viewports:

Mobile viewports if --mobile flag passed:

Step 5 — Serve the gallery

python3 skills/avalonia/avalonia-pro-max/preview-server/scripts/serve_gallery.py

What it does:

  1. Generates .preview/output/index.html from the gallery template — side-by-side cards per variant, with theme toggle (light/dark) and viewport toggle (wide/compact).
  2. Starts python -m http.server on a free port (default 8765, falls back if taken).
  3. Prints:

```

Preview gallery serving at: http://localhost:8765

Press Ctrl+C to stop.

```

  1. Optionally opens the URL via xdg-open / open / start if --open flag passed.

The agent leaves the server running and tells the user:

I've put 3 design options on http://localhost:8765 — have a look and tell me which one to build (or describe what you'd change about one of them).

Step 6 — Apply the chosen variant

Once the user picks (e.g. "go with variant 2, but with a green accent instead of blue"):

  1. Stop the preview server (Ctrl+C or kill the process the agent spawned).
  2. Copy .preview/variants/2/Resources.axaml, Styles.axaml, and any necessary .axaml into the real project's Resources/ and Views/ folders.
  3. Apply any tweaks the user asked for (accent swap, etc.).
  4. Wire up via App.axaml (StyleInclude + ResourceInclude) — see design-system.
  5. Optionally clean up .preview/ or leave for next iteration.

Step 7 — Iterate (optional)

If the user says "I like variant 2 but make it tighter", generate 3 new variants based on variant 2 and re-run from Step 4. Keep iterations cheap — the host project is already scaffolded.

File layout summary

<project root>/
├── .preview/                                 # gitignored
│   ├── AvaloniaPreviewHost/                  # scratch .NET project (scaffolded once)
│   │   ├── AvaloniaPreviewHost.csproj
│   │   ├── Program.cs                        # CLI: --variant N --viewport X --theme T --out P
│   │   ├── App.axaml
│   │   └── Variant/                          # populated per render run
│   │       ├── Resources.axaml
│   │       ├── Styles.axaml
│   │       └── PreviewScene.axaml
│   ├── variants/
│   │   ├── 1/{Resources,Styles,PreviewScene}.axaml + README.md
│   │   ├── 2/...
│   │   └── 3/...
│   └── output/
│       ├── index.html                        # gallery
│       ├── 1/wide-light.png, wide-dark.png, compact-light.png, compact-dark.png
│       ├── 2/...
│       └── 3/...
└── .gitignore                                # ensure .preview/ is excluded

Add to .gitignore

The agent should ensure .gitignore contains:

.preview/

Limits and honest caveats

Future work (not in this sub-skill)

Common mistakes

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.