1---2name: visual-diagram3description: Use when asked to diagram, or a tool or --quick flag renders a structured spec to HTML. Modes: interactive, quick-render. Not for Excalidraw or documents: use visual-argument-diagram or embed-diagram.4---56# Visual diagram78## Contract910| Field | Bound contract |11|---|---|12| Trigger | User asks to diagram, draw, map out, walk through, illustrate, or visually explain a topic, system, process, or architecture. A model tool call or the literal `--quick` flag asks to render a structured spec for `diagram`, `diff-review`, `plan-review`, or `project-recap` to a self-contained HTML document. |13| Authority | Reversible local: HTML artifact mode writes one named local HTML file; rollback is deleting that file. No remote mutation. SVG mode is read-only with no file mutation. |14| Side effect | Writes a self-contained HTML file under the output path and may open it; or emits an SVG in a chat visualizer fence. |15| Done | For HTML and quick-render modes: a complete, validated, self-contained HTML file exists at the output path. For SVG mode: a valid SVG diagram is in the visualizer fence. |1617## Refusals1819- Slides, fact-check, visual plans, PPTX, themes, or updates with the `--quick` flag: this skill does not apply. Stop.20- Partial HTML artifact surviving on disk after any failure: rejected. Any partial output is deleted.2122## Inputs2324- Mode (required): `interactive` or `quick-render`.25- Mode `interactive`:26 - Diagram request (required): the concept, system, process, or structure to visualise; and an optional diagram family (`flowchart`, `structural`, `illustrative`).27 - Output format (required): `html` or `svg`. Infer from the request; see Procedure step 1.28 - Style direction (optional): color, font, or layout hint for HTML format.29 - Surrounding context (optional): code, architecture, or conversation context.30- Mode `quick-render`:31 - Source spec (required): the structured spec object from an upstream outcome.32 - Output filename (optional): name under the output jail. Defaults to `render-<timestamp>.html`.33 - Visual format (optional): `diagram`, `flowchart`, `tree`, `timeline`, `grid`, or `table`. Inferred from the spec if omitted.34 - Schema (required): the JSON schema that defines a valid spec plan.3536## Procedure37381. **Determine the mode and inputs.** Select `quick-render` when the invocation carries the literal `--quick` flag or is a model tool call that carries a structured spec. Select `interactive` when the user asks for a diagram, map, illustration, or visual explanation. If the request is ambiguous, ask the user to clarify before generating. State the chosen mode and its authority. Done when: the mode is chosen and its authority is stated, or clarification is requested.392. **Classify the content.**40 - Mode `interactive`: classify the diagram family from the request and context. Classify as `flowchart` (sequential steps, decision points, process walkthrough), `structural` (components, relationships, containment, data flow), or `illustrative` (conceptual explanation, not strictly sequential or structural). If ambiguous, ask the user to clarify. Done when: family is classified or clarification is requested.41 - Mode `quick-render`: confirm the outcome type is one of `diagram`, `diff-review`, `plan-review`, or `project-recap`. If the outcome is `slides`, `fact-check`, `visual-plans`, `pptx`, `themes`, or `updates`, stop. If the format hint is absent, infer the visual format from the spec structure: list or bullet to `diagram`; sequential steps to `flowchart`; nested hierarchy to `tree`; dated or ordered events to `timeline`; two-axis data to `grid`; pairwise items to `table`. Done when: the outcome type is allowed and the visual format is set.423. **Build the source.**43 - Mode `interactive`: extract entities and relationships from the request and context. Identify nodes, edges, and labels. Do not invent entities not grounded in the request or context. Done when: entities and relationships are extracted from grounded sources.44 - Mode `quick-render`: validate the spec against the supplied schema. If validation fails, stop and report the errors verbatim; delete any partially written HTML. Done when: the spec passes schema validation.454. **Compose the visual artifact.**46 - Mode `interactive`:47 - HTML format: write a self-contained HTML file using these rules:48 - Embed all CSS inline in a `<style>` block and all JavaScript inline in a `<script>` block.49 - If using Mermaid, embed the Mermaid library inline; do not use a CDN script.50 - Apply a dual-theme strategy unless the user requests a single theme.51 - Use responsive layout, flexbox, or CSS grid to prevent horizontal overflow.52 - Label every Mermaid edge with a descriptive text annotation.53 - Add a `<figcaption>` or equivalent caption to each figure that states the claim it illustrates.54 - Derive the filename from the topic: lowercase, spaces to hyphens, append `.html`. Resolve the output directory from the user diagrams directory if known, else derive from session context or use a `diagrams/` folder under the project root. Create the directory if missing.55 - SVG format: compose the SVG following `references/svg-families.md`:56 - Set `xmlns="http://www.w3.org/2000/svg"` and a `viewBox` that fits content with padding.57 - Use `<g>` groups for logical clusters.58 - Use `<rect>`, `<circle>`, `<ellipse>`, `<polygon>`, `<path>`, `<line>`, and `<text>` for nodes and edges.59 - Every text label is a `<text>` element with `font-family`, `font-size`, and `fill`; no text-as-path.60 - Define arrow markers in `<defs>` with unique `id` values and use `marker-end` on edge paths.61 - Set explicit `width`/`height` or rely on `viewBox` with `preserveAspectRatio="xMidYMid meet"`.62 - No external resources; no `href` to external files, no `<image>`, no CSS `url()` to external assets.63 - Mode `quick-render`: render the validated spec to a single self-contained HTML document. Embed all required styles inline. Do not use a CDN, external fonts, external scripts, `<script>` tags, `eval`, `data:` URLs, `<object>`, `<embed>`, or `<iframe>`. All styles live in a `<style>` block inside `<head>`. All markup is static.64 Done when: the artifact is composed with all mode-specific and format-specific rules applied.655. **Validate the output.**66 - Mode `interactive`:67 - HTML format: confirm zero console errors, no horizontal overflow, dual theme or documented single theme, every Mermaid edge has a label, every figure has a caption.68 - SVG format: verify the root is `<svg>` with `xmlns`; every opening tag has a matching closing tag; all `id` references resolve; no unclosed paths or malformed polygon points; text elements have content and positioning attributes.69 - Mode `quick-render`: verify the HTML is a complete document with `<!DOCTYPE html>`, `<html>`, `<head>`, `<body>`, `utf-8` charset, all tags closed, and only inline assets. Read back the written file and verify it is well-formed HTML.70 Done when: every validation check for the chosen mode and format passes.716. **Deliver the result.**72 - Mode `interactive`:73 - HTML format: open the HTML file in the default browser and report its path. If opening is not possible, report the file path and ask the user to open it.74 - SVG format: wrap the SVG in a fenced code block tagged for the client's visualizer renderer. The fence must contain exactly one `<svg>` root element and nothing else. Do not modify files, repositories, or external resources. Do not offer to save, export, or deploy.75 - Mode `quick-render`: write the normalized HTML to the output jail under the chosen filename. Report the file path and open status to the user. Optionally open the file in a browser or Glimpse viewer.76 Done when: the file is opened or its path is reported, or the fenced SVG is the only chat output.7778## Failure and recovery7980| Failure class | Mode | Condition | Result |81|---|---|---|---|82| `unsupported-diagram-type` | interactive | Request does not match any diagram family and clarification is not possible | Stop; report the request could not be mapped to a diagram; ask the user to specify flowchart, structural, or illustrative. |83| `write-error` | interactive HTML, quick-render | File write fails (permissions, disk full, path not found) | Stop; report the error; do not claim the file exists. |84| `console-error` | interactive HTML | Headless DOM check detects a console error | Stop; report the error; do not open the file. |85| `overflow-error` | interactive HTML | Horizontal overflow detected | Stop; report the overflow; do not open the file. |86| `missing-labels` | interactive HTML | Unlabeled Mermaid edge or missing figure caption | Stop; report the missing labels; do not open the file. |87| `malformed-svg` | interactive SVG | Generated SVG fails validation | Regenerate once, applying the specific fix; if it fails a second time, return the partial SVG with a note listing the remaining structural issues. |88| `scope-violation` | interactive SVG | Procedure would require file mutation, external resource access, or entity invention beyond the request and context | Stop; report which boundary was hit; do not widen scope. |89| `unsupported-spec-type` | quick-render | Outcome type is not `diagram`, `diff-review`, `plan-review`, or `project-recap` | Stop; report the unsupported outcome type. |90| `schema-validation-failure` | quick-render | The spec fails schema validation | Report validation errors verbatim; delete any partial output; stop. |91| `render-error` | quick-render | Rendering produces an error | Report the error verbatim; delete any partial output; stop. |92| `missing-required-spec-field` | quick-render | A required spec field is absent | Treat as a schema validation failure. |93| `malformed-output` | quick-render | Normalization fails after rendering | Discard the partial file; stop. |9495Partial-result rule (HTML and quick-render modes): if write succeeds but validation fails, delete the written file before reporting the failure.96Rollback (HTML and quick-render modes): delete the written file to restore the pre-invocation state.97No failure class swallows an error or pretends the done predicate holds when it does not.9899## Output100101- Mode `interactive`, HTML format: one self-contained HTML file at `<user diagrams directory>/<derived-filename>.html`, opened in the browser or its path reported. The file contains inline CSS/JS, dual-theme support, labeled Mermaid edges, and figcaption claims.102- Mode `interactive`, SVG format: a single SVG diagram wrapped in a visualizer fence, with `xmlns`, a `viewBox` containing all content, `<text>` elements for labels, arrow markers in `<defs>` for directed edges, no external resource references, and logical grouping via `<g>`.103- Mode `quick-render`: a single self-contained HTML file at the specified output path, with all styles embedded inline and no external resources, or on failure no output file and a report naming the failure class and exact error.