---
name: diagram
description: Draw a flow, structure or plan as a color picture from Mermaid text, in the desktop app or a terminal.
---

# Diagram

1. Write the Mermaid text to `<name>.mmd`, in `.empstack/diagrams/` unless the diagram belongs in the repo's docs. Start with `flowchart TB` unless the picture is short and wide.
2. Color nodes by kind with `class` lines, such as `class A,B teal`. The colors are gray, purple, teal, coral, pink, blue, green, amber and red. Use gray for start and end, and at most three colors. Write no `classDef` or `style` line, since those fix one color for both light and dark.
3. Keep a picture to about 12 nodes. Split a bigger one into an overview and one picture per part. A subgraph whose nodes have edges to the outside ignores its `direction` line and runs those edges through its boxes, so put the group's name in each node's label instead.
4. Run `node <skill dir>/scripts/diagram.mjs <name>.mmd --png`. It writes `<name>.svg` and `<name>.png` and prints the size.
   - Exit 3 means Pele, the renderer, is not installed. Tell the user in one line that empstack installs `pele@1.9.0` from npm (2.3 MB, no dependencies) into `~/.claude/empstack/diagram`. Run the `--install` command the script printed, then step 4 again. If the install fails, give the user the error and the command, and show the Mermaid text in a ```` ```mermaid ```` block until then.
   - Exit 1 names the Mermaid line to fix.
   - Wider than 1200 shrinks in a narrow pane. Turn the flow or split it.
5. Read the PNG. Redraw while a label is cut off, an edge runs through a box or a label, or an edge seems to start at the wrong box. Without Chrome or Edge there is no PNG, so say the picture is unchecked.
6. Show the SVG. In the desktop app, where `CLAUDE_CODE_ENTRYPOINT` is `claude-desktop`, send it with `SendUserFile`, display `render`. In a terminal, open it in the browser (`start "" <file>` on Windows, `open` on macOS, `xdg-open` on Linux) and give its path. Never send the `.mmd` file as the picture. The desktop app shows it as plain text.

In a Markdown doc or PR body, use a ```` ```mermaid ```` block. GitHub draws it.
