Skip to content

Scratchpad visual design: text metrics foundation + research doc#26

Open
molefrog wants to merge 1 commit into
mainfrom
claude/scratchpad-visual-design-xkgqd6
Open

Scratchpad visual design: text metrics foundation + research doc#26
molefrog wants to merge 1 commit into
mainfrom
claude/scratchpad-visual-design-xkgqd6

Conversation

@molefrog

@molefrog molefrog commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Problem

Agent-drawn scratchpad diagrams don't look human-made: labels overflow their boxes mid-word ("localhost:30 00"), the title overlaps shapes, nothing aligns. Root causes: no server-side text measurement, absolute-coordinate drawing, and no feedback loop (view needs an open tab).

This PR (foundation for three approach branches)

  • server/scratchpad-metrics.ts — text measurement with the actual canvas font: Shantell Sans Informal woff2 from @tldraw/assets (version-matched to our tldraw), read via fontkit. Exposes measureLine, wrapText, textBlockSize, and fitRectToLabel (smallest grid-rounded rect whose label fits, using tldraw's real font sizes, 1.35 line height, and 16px label padding — those constants aren't exported by tldraw, so they're pinned with provenance comments). Heuristic char-width fallback if the font can't load.
  • docs/scratchpad-visual-design.md — the research/comparison doc: root causes, how D2/Mermaid/Graphviz vs. humans solve layout, and the three composable approach bets, each implemented end-to-end on a branch stacked on this one:
  • 9 new tests, including a regression window pinning measured width against the browser-rendered value.

Merge this first; the three approach PRs target this branch. To compare them, ask each to reproduce the "expose a Tailscale service" diagram from the motivating screenshot and judge: no overlaps, no clipped text, straight rows, consistent gaps, and how many agent turns it took.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A4d4g5CV89L1AanPrEYp7p

The agent's scratchpad drawings overflow labels and misalign because
nothing measures text server-side. Add server/scratchpad-metrics.ts:
exact measurement with the real canvas font (Shantell Sans Informal via
@tldraw/assets + fontkit), word wrap, and fitRectToLabel. Document the
three approach branches this anchors in docs/scratchpad-visual-design.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A4d4g5CV89L1AanPrEYp7p
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.

2 participants