Skip to content

Add show_image: a freely licensed picture, found and served by the server - #70

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

a-Fig merged 3 commits into
mainfrom
images-61

Conversation

@a-Fig

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

Copy link
Copy Markdown
Owner

Closes #69

Stacked on #66 (show_visual); this PR's own commits are 7b77f5c, f0b94a4 and 06a792c.

Why

Tyler (#61) wants Cue to "grab images" instead of leaning on words. A photo of the bridge, the product or the tram being discussed shows it faster than any summary.

Change

  • show_image tool (agent.js): Claude gives a plain query ("Golden Gate Bridge") and an optional title. One new tool line in the prompt (things a photo can show; never private people); the "one visual per turn" line from Add show_visual: Claude draws SVG charts and stats, shown sandboxed #66 now names it too.
  • GET /api/image?q= (server.js, new image.js): searches Wikimedia Commons (no key, reusable licences), then Openverse; returns a path on this server with title, credit, licence and source.
  • /api/image fetches the picture itself through page.js's fetchPublic (per-hop address checks, now exported), capped at 8 MB, JPEG/PNG/WebP/GIF only (an SVG from Cue's own origin could run script if opened directly). If a pick fails, it tries the next of the first three. It keeps the bytes (30 at most, an hour each). GET /api/image/raw?id= serves only those kept pictures, with nosniff and default-src 'none', and fetches nothing itself.
  • Safety: Commons has no safe-search, so queries and results (title, description, tags) with explicit, anatomical or gory words are refused, and the prompt rules those subjects out. Openverse uses mature=false and commercial-use licences only.
  • Picking: relevance first. The top result stays unless it is much taller than wide, and banners wider than 2.2:1 don't count as wide. Both routes need AGENT_TOKEN. The bot page never loads an image host directly.
  • public/views/image.js, image.css: the picture on ink, the credit small in mono under it.
  • Google Custom Search would be one more entry in image.js's SOURCES; it needs a key and a search-engine ID, which is Tyler's decision, so it isn't added.
  • scripts/check.mjs: /api/image needs the token and refuses an unsafe query; /raw serves only kept ids.

Screenshots

A titled picture, and an untitled one with a caption over it (real Commons results through /api/image/raw):

image-bridge.png
image-tram.png

Verified

  • npm run check passes.
  • After the fixes, a local server found: "Taylor Swift" → her 2023 VMAs portrait (before the fix, her logo), "breast cancer screening" → refused, "Pena Palace, Sintra" → the palace, and /raw?id=1 → 248 KB JPEG.
  • Before the fixes, a local server (not :3000) found real pictures on Commons for "Golden Gate Bridge" and "Lisbon tram 28"; Playwright at 1280×720 with /api/think mocked rendered them through /raw, and the browser made no request to any host but the server and Google Fonts.
  • evals/transcripts/numbers-to-chart.json and picture-helps.json (new): a chart, a picture, and quiet ticks around them. Replay on claude-haiku-5-5, low, run twice (before and after the fixes): 5/5 both times (2 helpful, 3 right-quiet), $0.002; Claude picked show_image("Pena Palace, Sintra") for "what does it even look like?".
  • Openverse returned 504 when tried (2026-11-13), so the fallback path is untested against a live answer.
  • Not run: a real Claude call, a real Recall call.

Review

Opus review of ed49d13 (now 7b77f5c after rebases): no SSRF, open-proxy or XSS hole found. Its findings are fixed in 06a792c: Commons nudity (safety filter plus a prompt rule), a logo picked over a portrait and banners counted as wide, no fallback when a pick fails (it now fetches while searching and tries the next result), TIFF originals skipped, Openverse NC licences and full-size originals, entity decoding, and the prompt naming one source. Not changed: show_image keeps state.busy while it searches (up to ~20 s in the worst case), which also rules out an older image landing over a newer view. Wikimedia's user-agent policy asks for contact details; we send a generic one, so it may need one if Commons starts refusing.

🤖 Generated with Claude Code

smash and others added 3 commits November 13, 2026 14:05
…rver

The other half of #61: a photo of the bridge, the product or the tram
being talked about shows it better than any summary. Claude names what to
picture; GET /api/image searches Wikimedia Commons (no key, reusable
licences), then Openverse, prefers a landscape result for the 16:9
screen, and returns a path on this server plus title, credit and licence.

The page loads pictures only from GET /api/image/raw, which serves only
URLs /api/image found in the last hour (not an open proxy), fetched with
page.js's per-hop address checks, capped at 8 MB, and only as JPEG, PNG,
WebP or GIF: an SVG served from Cue's own origin could run script if
opened directly. Both routes need AGENT_TOKEN. The credit shows small
under the picture, as the licences ask.

Sources are a list in image.js, so Google Custom Search could be added
as one; it needs a key and a search-engine ID, which is Tyler's call.

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

numbers-to-chart: four quarterly numbers read out, then a bar chart.
picture-helps: "what does Pena Palace even look like?", then a photo.
Each has quiet ticks around it, so a visual everywhere doesn't score.
First run (claude-haiku-5-5, low, 2026-11-13): 5/5, $0.002.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Commons has no safe-search: "breast" gave close-up nudity in its top
  results. Queries and results (title, description, tags) with explicit,
  anatomical or gory words are refused, and the prompt rules them out.
- The server now fetches the picture while searching and keeps the bytes
  (30 at most, an hour each); /api/image/raw?id= serves only those and
  fetches nothing itself. A pick that fails (gone, too big, an SVG)
  falls through to the next of the first three, so a found image always
  loads.
- Relevance first: the top result stays unless it's much taller than
  wide, and banners wider than 2.2:1 don't count as wide. "Taylor Swift"
  picked her logo before; now a portrait.
- Commons originals that are TIFFs are no longer skipped (the thumbnail
  is a JPEG; the fetch checks the real type).
- Openverse: commercial-use licences only (the default is mostly NC), its
  own thumbnail instead of the original, and "CC BY 2.0" / "CC0" /
  "Public domain" in the credit.
- Credits decode entities and end in an ellipsis when cut; the page's
  decode wait has a 5 s limit.
- Prompt: names both sources; says a missing image means none was found.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base automatically changed from visuals-61 to main November 13, 2026 22:06
@a-Fig
a-Fig merged commit d58d279 into main Nov 13, 2026
1 check passed
@a-Fig
a-Fig deleted the images-61 branch November 13, 2026 22:07
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_image: a freely licensed picture found by the server (part of #61)

1 participant