~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

A playground at /playground writes a view beside what it draws

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:web/playground

A playground at /playground: a view's JSON on the right, what it draws from live data on the left, redrawn as you type, shareable as a link. It works signed out and with sign-in off, and it lets an inline view name the origins bundled views already name, so its pictures load.

Claude Opus 5.5 · high

What changes

The page (web/playground.html, web/workspace/Playground.svelte, PlaygroundPage, PlaygroundEditor, PlaygroundPreview, TemplateMenu, CodeEditor, lib/playground/): CodeMirror 6 editors for the call (tool and arguments) and the view, the preview drawn by shared/Result.svelte as a tile draws it, at a column's, a wide, a phone's or the full width, in light, dark or any of HUD's themes, with Tree and Data tabs. The server's problems are marked where each is in the editor and listed under it; the catalog completes component and prop names. It starts from any bundled view (its call from examples.ts) or a blank one. Copy link puts the call and view, compressed, in #v=; the work is kept in localStorage. What a drawing opens is shown, not followed, with a button to load the call; actions and forms don't write here. On a phone, Edit and Preview are tabs.

Two methods, anyone's (schemas/place.hud.getPlayground.json, place.hud.previewView.json, crates/hud-server/src/xrpc.rs): getPlayground gives the bundled views a read tool draws, each as an inline view may be (view::inline_copy), with its app, the catalog and HUD's themes. previewView takes a tool, its arguments with the view, and optionally the answer read before: an invalid view answers every problem by where it is; with an answer it redraws over it (Hud::redraw, sharing drawn_query and drawn_records with the tools, so the drawing is the tool's own); without, it makes the call, as the account where a session is good, else as no one. The page edits a layout by redrawing and reads afresh only when the call or anything else in the view changes. Its input may be 4 MiB.

Served with sign-in off too: /playground (playground.rs), /favicon.svg, and /xrpc, where the workspace's methods then answer MethodNotImplemented.

Inline views' origins: an inline view may name origins (and thumbnails on them) that some bundled view names, and draws from them. Any other origin is refused, naming those allowed. The CSPs already allow exactly the bundled views' origins, so none widens. The catalog's grammar says so to models.

Why

Writing a view meant a model or a person sending inline views through /mcp and reading errors back. The playground shows the drawing and every problem at once. Redrawing over the answer read keeps typing off the PDSes and AppViews, and drawing through the tools' own code means the preview is what a tile shows. A subdomain was considered and dropped: the same origin needs no CORS or second cookie.

Inline views named no origins, so every AppView picture (Bluesky's avatars and images, Grain's photos) was missing from anything a model or the playground wrote. Allowing the bundled views' own origins fixes that without loading anything the page could not already load.

How it was checked

just check passes (100% lines and functions). Tests: a_view_drawn_again_over_its_answer (a redraw equals the call made afresh with that view, for a page, a record and a query, nothing read again), the_playground_draws_a_view and the_playground_with_sign_in_off through the router, every answer held to its lexicon, bundled_views_copied_to_draw_inline, and the inline-origin cases in documents and views_chosen. In Chromium against a local hud serve: the Bluesky profile, Grain gallery and plyr.fm templates read and draw with their pictures; a layout edit redraws with answer (one request, no read); a broken component is marked and listed; a copied link restores the view in a fresh tab; Paper theme, phone width, light desktop and dark phone looked at and critiqued by a reviewer agent, its findings fixed.

Shortcomings

bsky-chat, bsky-chat-with, bsky-chats call procedures and bsky-feed sends interactions in their layouts, which only a bundled view may, so those templates start with their problems shown. Actions and forms don't write from the playground. No just look state or e2e covers the page. The page is 739 KB (221 KB gzipped), CodeMirror most of it. Saving a view as a record isn't built: sharing is the link.

Review

The trust change first: view::origins and view_ctx. Then Hud::redraw and preview in xrpc.rs; the page last.

pr-gallery.png

pgC.png

Approved

This adds /playground, plus the anyone-callable getPlayground and previewView methods. It also lets an inline view name the origins and thumbnails that bundled views already name.

What I read. I read view.rs, tools.rs, xrpc.rs, playground.rs, lib.rs, playground.svelte.ts and share.ts in full, plus AGENTS.md on main. I did not read the rest of the web files (editors, preview, menus, CSS, package-lock.json), the lexicon files, the docs or harness/contrast.json. just check is the gate for those.

Trust change.

  • Inline origins are restricted to bundled_origins(), and parse checks every one.
  • view_ctx now passes the origins through. The tests cover both the refusal and the accepted case.
  • csp_origins(...) already puts these origins in every view's CSP in mcp.rs and in the workspace page's CSP in workspace.rs. So an inline view's pictures gain no new origin to load from, which matches the PR's claim.
  • AGENTS.md is updated to match.

previewView.

  • It is open to anyone, but a cookie caller must pass from_page (X-HUD: 1 and same origin), the same check the other procedures use. A bad or missing session falls back to no account, never to someone else's.
  • The tool is limited to the three that draw views, and an invalid view returns every problem before anything is read.
  • Replaying a client-supplied answer through redraw reads nothing from the answer's own source. Handle lookups are capped at 50 DIDs (HANDLES_MAX) and a short deadline, so the 4 MiB body does not become unbounded outbound work.
  • The answer comes from the caller and is drawn only back to them.
  • With sign-in off, the workspace's methods answer MethodNotImplemented, and the test covers that.

Non-blocking.

  • Without an answer, preview runs the tool as /mcp does, so an unauthenticated caller gets the same reads and any rate limits /mcp has. Confirm the deployment's limits cover /xrpc/place.hud.previewView as well, if they are per route.
  • fromLink inflates a #v= payload with no size cap. That only affects the person who opens the link, so it is minor.

No changes needed.

Merged as fb3a956