Skip to content

Draw SVG, Mermaid, math and HTML pages as pictures in Sonny - #147

Merged
lydakis merged 38 commits into
mainfrom
claude/project-thread-45hlbm-pictures
Oct 26, 2026
Merged

lydakis merged 38 commits into
mainfrom
claude/project-thread-45hlbm-pictures

Conversation

@lydakis

@lydakis lydakis commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Fourth of five stacked PRs. It is based on #146.

What

In a terminal that speaks the Kitty graphics protocol (Rex, Kitty, Ghostty), Sonny draws parts of a reply as pictures where the fence is. Pictures are placed with Unicode placeholders, so they scroll with the text.

Fence How it's drawn
```svg drawn by resvg
```mermaid Pele (vendored, MIT, the same renderer as #140), run by the machine's node or bun. Colors are written in for the terminal's light or dark background.
```math, $$…$$ MathJax (vendored, Apache-2.0) under node or bun. Inline $…$ stays Unicode text, as before.
```html laid out by a headless Chrome-family browser, or Quick Look on macOS. The top ~30 lines are shown; /open opens the whole page.
  • Cache: drawn pictures are cached in the temp folder, so reattaching or a theme switch doesn't redraw them.
  • Probe: a Kitty graphics query and a cell-size query join the existing background probe.
  • Rendering off the reader: rendering never blocks the reader. A reader that stalls is dropped by the daemon as lagging; Sonny runs on two threads and preloads fonts.
  • Skill: a pictures skill tells agents they can reply with SVG and Mermaid.
  • Fallback: where a terminal can't draw pictures, Sonny shows exactly what Add Sonny, a terminal coordinator for a folder's agents #146 shows: the source, with math as text.

Screenshot

This one is put together from Sonny's real output. Sonny ran in a pty that answered its probe the way a dark Kitty-graphics terminal does. Each PNG it transmitted was placed over its placeholder cells, on top of the replayed screen (demo model, xterm.js):

pictures

Tests

  • cargo test -p sonny: 42 pass.
  • Clippy is clean.
  • Earlier versions of these pictures were seen in Rex on George's Mac. I didn't recheck this exact build in Rex.

Stack

  1. Add configure: change a bot's model, effort, instructions and gate #144 configure
  2. Share the project file and ~/.agent/env reader in agent-client #145 shared project file and env reader
  3. Add Sonny, a terminal coordinator for a folder's agents #146 Sonny
  4. This PR: pictures
  5. Sonny Homebrew formula

Protocol 14. configure replaces what a bot's client chose when it made
it: its instructions, a model of the same family with an optional
effort, and a root bot's gate (approve: [] alone removes it; a bot
another bot made keeps the gates it descends from). It is refused
while a turn runs or waits parked, answers which fields changed, and
tells followers with a live configured event. ready.providers now
names the efforts each binding's family takes, and the client keeps
it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
The app's project file helpers and its ~/.agent/env reader move to
agent-client, so a terminal client composes a lead the app's way.
Finding a folder's project now stops at its repository's top, and the
home folder's project applies to home itself only, so a repo under
home is never claimed by it. The coordinator lists only its own
project's agents when it names or finds a task.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
Sonny opens a folder's lead in a Codex-style TUI, lays each task out as
a Rex window, and offers /model, /approvals, /status, /sound, /copy,
/open and /quit. Agents get a rex-windows skill, and an errand skill
when Errand is installed; Errand runs are drawn as calls, and detached
jobs open in their own Rex window. Pictures come in a follow-up.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
In a terminal that speaks the Kitty graphics protocol (Rex, Kitty,
Ghostty), Sonny draws a reply's SVG, Mermaid (through Pele), math
(through MathJax) and HTML pages as pictures, and agents get a
pictures skill saying so. Elsewhere they stay text.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
A steer restarts the demo script within a turn, and a turn keys its
calls by id, so each request now names its calls afresh.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T02:35:36.629846Z 0b2c27f New commits
🔒 Security Review ✅ Completed 2026-10-26T02:37:47.042213Z 0b2c27f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53647ead5d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sonny/src/image.rs Resolved
Comment thread sonny/src/transcript.rs Resolved
Comment thread sonny/src/mermaid.rs Resolved
claude added 19 commits October 26, 2026 00:55
Clearing the thinking binding makes the next request strip thinking
written under the old instructions. The docs now say a client-made
fork's gates can be replaced too, since that client could make an
ungated bot anyway.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
…nect

- History and live results read Anthropic tool_use/tool_result blocks
  as calls and outputs, so Claude bots' calls show with their output.
- A history read the daemon cut at its byte limit asks for the rest.
- Calls still running when Sonny attaches finish live.
- After a reconnect the fleet reads the project's bots again, opening
  tasks that started meanwhile and marking stopped ones idle.
- An Errand listing that runs past three seconds is killed.
- A new lead takes the project file's model and effort first.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
A tool_started event carries a 2 KiB preview of a call's arguments, so
a truncated one is read from the bot's items. The bot is inspected
after the replay is skipped, so a turn that ended meanwhile is not
shown as running.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
- CSS variables are filled in inside tags only, so a Mermaid label
  that reads var(--x) stays as written.
- Image ids keep a 16-bit count, so pictures still in scrollback keep
  theirs for the first 65,535.
- A fence a reply never closed shows its lines as code when the reply
  ends, instead of vanishing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
…figure

A turn that ran before configure moved the bot keeps the model and effort
it ran at, in its record and as the cache the next turn takes as held. A
keyed creation keeps a fingerprint of the instructions it was sent with,
so a resend still matches after they are replaced. Schema 49.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
A failed edit, write or read shows its error instead of the change it
asked for. A call denied before it started is read from the bot's items
and shown as denied. Sonny opened anywhere in a project attaches to the
lead working in the project's folder, makes it there when missing, and
refuses a same-named lead working elsewhere. Reconnecting pages back to
the last node drawn and matches results to calls kept from before. The
next page of approvals shows once the first is answered. An unclosed
$( and a backslash before a non-ASCII character no longer crash the
renderer.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
- Reconnecting reads the bot after the replay, so a turn that ends
  meanwhile is not lost, and starts the approver again in auto mode.
- A turn whose prompt history already drew still counts as running.
- Errand handles are read from the matching result, Anthropic too.
- `sonny show` finds a dotted project by its lead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
claude added 11 commits October 26, 2026 01:42
- A hunk range that doesn't start with - or + is read as line 1 rather
  than sliced mid-character.
- While /status holds the screen, the newest 5,000 transcript lines wait
  for it and a note says how many earlier ones went by.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
- A call waiting on the person is written above the status row in full,
  every line of its command, before y can allow it.
- Bots Sonny makes get the default compaction instructions, as the CLI's
  and the app's do, so long conversations can compact.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
…, unclosed fences

A call listed with cut arguments is shown whole, read from the node that
planned it; when that read fails, y is refused and n denies it. Errand runs
are keyed by bot and call, since call ids repeat across bots. Transcript
lines go into scrollback in chunks a u16 row count holds. A fence or $$
block still open when a reply ends shows as code instead of vanishing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LutDnsMA6fqW8Qwj2Wcoks
…-thread-45hlbm-pictures

# Conflicts:
#	sonny/src/main.rs
#	sonny/src/transcript.rs
@lydakis
lydakis changed the base branch from claude/project-thread-45hlbm-sonny to main October 26, 2026 02:32
# Conflicts:
#	Cargo.lock
#	sonny/Cargo.toml
#	sonny/src/main.rs
#	sonny/src/math.rs
#	sonny/src/rex.rs
#	sonny/src/term.rs
#	sonny/src/transcript.rs
@lydakis
lydakis merged commit ea882fb into main Oct 26, 2026
This was referenced Oct 26, 2026
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