Skip to content

Add show_visual: Claude draws SVG charts and stats, shown sandboxed - #66

Merged
a-Fig merged 3 commits into
mainfrom
visuals-61
Nov 13, 2026
Merged

a-Fig merged 3 commits into
mainfrom
visuals-61

Conversation

@a-Fig

@a-Fig a-Fig commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Closes #65

Why

Tyler (#61): Cue's screen "is lacking in visuals and relies too much on words". A bar chart of numbers just said, or one big number with an icon, reads across a Meet tile; bullets don't, and Mermaid can't draw either.

Change

  • show_visual tool (agent.js): Claude writes one SVG (viewBox="0 0 1136 470", which fills the frame) or a small HTML/CSS block. Prompt: one new tool line and two new rule lines (it counts as a visual; brand colours, fonts, type ≥22px, ≤~25 words, no invented data). No existing rule reworded (Make Cue act unprompted, as the intern running the projector #58 owns that wording).
  • Two layers against hostile markup (How do we keep what Cue shows right, and safe for a room? #14), since pages Claude read can steer what it writes:
    • public/views/sanitize.js: allowlist of drawing and text elements; drops on* handlers, <script>, <foreignObject>, <image>, <a>, <meta>/<base>/<link>/forms, any URL attribute that isn't #id, url() other than url(#id), data:/javascript:, @import, image-set(), CSS escapes, <animate>/<set> on href, and < in style text (so </style> can't break out on reparse).
    • public/views/visual.js: renders in an <iframe sandbox=""> via srcdoc (no scripts, opaque origin, no navigation) under a CSP of default-src 'none', allowing only Google Fonts for the brand faces. Model markup never enters the page's own DOM.
  • scripts/sanitize-check.mjs runs 14 hostile cases under linkedom as part of npm run check.
  • public/app.js, evals/replay.mjs: one dispatch case each.

Screenshots

What Claude itself drew in the replay (claude-haiku-5-5, low) when Maya read out four quarterly numbers, after 3788eeb (colour classes, no hex values), rendered by this view:

visual-real2.png

Two hand-written mocks: A bar chart of numbers just said (title above), and a stat with an icon (no title; this one's mock also carried the hostile markup, all stripped):

visual-chart.png
visual-stat.png

Verified

  • npm run check passes (including the 14 sanitizer cases).
  • Playwright at 1280×720 with /api/think mocked: the chart and the stat render with the brand fonts. The stat's mock carried onload="alert(1)", a <script> calling fetch('https://evil.example/x'), an external <image> and a url(https://evil.example/…) fill: no dialog, no request to any host but the server and Google Fonts, and none of them in the iframe's srcdoc.
  • Replay of the two new transcripts in Add show_image: a freely licensed picture, found and served by the server #70 (claude-haiku-5-5, low): 5/5, $0.002; the chart tick drew the SVG above, with every number from the transcript.
  • Not run: a real Recall call.

Review

Opus review of e289337: no way found for markup to run script, make a request, navigate, read the token or leave the frame. Its rendering and prompt findings are fixed in fea2a1a: viewBox from 100%, a two-line title shrinking text below 22px, tall HTML losing its top, svg-inside-HTML sizing, serif flash, data: in harmless attributes, nested <use> blow-up (capped), and the overlap with stat slides, Mermaid timelines and two_columns. Not taken: putting show_visual into the "one visual per turn" list on line 34, which is #58's wording, so it stays a line of its own. 3788eeb (colours from the page's live tokens, for #73's restyle) came after the review and is page and prompt only.

🤖 Generated with Claude Code

a-Fig pushed a commit that referenced this pull request Nov 13, 2026
a-Fig pushed a commit that referenced this pull request Nov 13, 2026
a-Fig pushed a commit that referenced this pull request Nov 13, 2026
smash and others added 3 commits November 13, 2026 14:05
Cue's screen leaned on words (#61). Bars, a big number with an icon, a
timeline read across a Meet tile where bullets don't, and Mermaid can't
draw them. So Claude can now write an SVG (or a small HTML/CSS block).

Model output can be steered by pages it read (#14), so the markup gets two
layers: sanitize.js keeps an allowlist of drawing and text elements and
drops handlers, external URLs, url() other than #id, @import and CSS
escapes; then it renders in an iframe with an empty sandbox (no scripts,
opaque origin) under a CSP that loads only the brand's Google Fonts. The
page never inserts model markup into its own DOM. scripts/sanitize-check.mjs
runs the hostile cases in npm run check under linkedom.

Prompt: one new tool line and two new rule lines (colours, viewBox,
type sizes); no existing rule reworded, since #58 owns that wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A viewBox comes only from a plain width and height: width="100%"
  gave "0 0 100 100" and zoomed into the drawing's corner.
- An svg beside a <style> or inside a <div> gets the viewBox too, and
  shrinks to fit there instead of clipping.
- The title stays on one line, so the frame stays 470 tall and 22px text
  stays 22px; the schema asks for under 40 characters.
- HTML taller than the frame keeps its top (safe center).
- At most 40 <use> copies and 3000 elements: nested <use> can ask for
  millions of copies in a few kilobytes and stall the 15 fps page.
- data: in a harmless attribute (aria-label="Revenue data: Q3") stays;
  URL attributes still must start with #.
- Prompt: when show_visual wins over a stat slide, a Mermaid timeline or
  two_columns; markup under 4,000 characters (it's the slowest tool to
  write); font fallbacks so text never flashes in serif.

The "one visual per turn" list itself (line 34) is #58's wording, so the
new tool stays a line of its own for now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es, for #65

inland-ocelot's restyle (#73) changes every brand value while keeping the
token names. Hex values in the prompt would leave drawings in the old
palette, so the iframe now gets the page's computed --cue-* values and
font stylesheet, and Claude colours with classes (accent, ink, muted,
line, paper, hl, display). Whichever palette is live, drawings match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

show_visual: Claude draws SVG charts and stats, sandboxed (part of #61)

1 participant