Public: anyone can read this; the crew can change it.

OG cards as SVG: `/og/:kind/:ref.svg` composed from live data with the studio's tokens, cached by input hash #1008

Closed opened this
Closed without merging

GET /og/:kind/:ref.svg now serves 1200×630 SVG cards for app, repo, issue, pull and run, with zero new dependencies and forge.json untouched. The new tests, reserved-names and check-list pass (45 tests) and tsc --noEmit is clean. I did not run the whole suite.

Notes

stopped closed without shipping deploy 8384404

opened this

GET /og/:kind/:ref.svg now serves 1200×630 SVG cards for app, repo, issue, pull and run, with zero new dependencies and forge.json untouched. The new tests, reserved-names and check-list pass (45 tests) and tsc --noEmit is clean. I did not run the whole suite. The pull kind has no route test (below). The tests only ran with the sandbox off, because it refuses the unix-socket listen the server needs.

What changed

  • src/web/og/card.ts: a pure renderCard({kind, title, lines, stat}). Colours come from the Porcelain tokens in src/design/themes.ts. The font is the stylesheet's system stack, copied in because src/design has no type tokens. Text is stripped of XML-illegal characters, clamped to the width it is drawn in with an ellipsis, then escaped. The clamp uses a deliberately generous per-character width estimate rather than real font metrics.
  • src/web/pages/og.ts: resolves the ref to a card, hashes the inputs with sha256, and keeps the SVG in an in-memory map (500 entries). The ETag is that hash, Cache-Control is public, max-age=300, and a matching If-None-Match gets a 304.
  • src/http/server.ts: the route, registered above /:owner. og is added to the reserved names, because the existing test requires every top-level route to be reserved.
  • scripts/gate.ts: adds test/og-card.test.ts to the gate.

Ref format

  • App: its slug.
  • Repo: owner~name.
  • Issue or pull: owner~name~N.
  • Run: the run id.

For example, /og/issue/alice~open~1.svg.

Visibility

  • Only public repos are drawn, and only to a viewer who can read them. A private repo is a 404 even for its owner, because the response is public-cacheable and must not carry private data.
  • A sealed issue or pull is also a 404.
  • An unknown kind, a missing thing and a bad ref are the same 404.

Tests (test/og-card.test.ts)

  • Each kind renders balanced, escaped XML at 1200×630.
  • A hostile title (<script>, &, 500 characters) is escaped and clamped.
  • Control characters and lone surrogates are removed.
  • Private, sealed, missing and malformed refs return 404, and the owner's own credentials don't widen that.
  • An ETag match returns 304.
  • A warm request has a median under 5 ms.

Left out

  • PNG, which is the next issue.
  • The OG designs (#454, #455), and the og:image meta tags that point at these URLs.
  • A route-level test for the pull kind. Making a pull needs a real git repo, so the pull card is only covered by the render test. The pull branch of the route is untested.
  • Real font metrics, so clamping is conservative and may cut text a little early.

Try it

  • Run bun run src/main.ts, then open /og/repo/<owner>~<name>.svg for any public repo.
  • Run bun test test/og-card.test.ts.

🤖 Generated with Claude Code

Closes #567

commented

Parked by the crew: the check failed ("capacity: only a forge admin reads or changes it > an admin changes each one from the page, the API and MCP; a wrong value is refused; every change is kept") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs