Repository navigation
Draw diagrams with Agentic Mermaid and drop the fidelity check - #907
Conversation
Beautiful Mermaid's parsers are total: a statement they cannot read still gets a reading, so a source the renderer only partly understands draws a plausible, wrong diagram and reports nothing. `lf-diagram` answered that with hand-written guards, each a slice of Mermaid grammar kept beside the parser it second-guessed, and each refusing only the divergence someone had already noticed (#312, #859). Both libraries already describe what they found: official Mermaid in its diagram database, Beautiful Mermaid in the `data-*` attributes of the SVG it drew. `lf-diagram-fidelity.js` reads both into one shape and reports where they differ, so Leaf holds the mapping between two vocabularies and no grammar. It covers all six diagram types, and because it compares against what was drawn it also catches a parser that read too much, which a record of unread text cannot. Official Mermaid is too heavy for a reader's page, so the comparison runs only in `version check --render`. `registerRenderCheck` is the general form: a widget registers a check, the render gate alone calls it, and what it finds arrives as that widget failing soft. `mermaid-reader.esm.js` is official Mermaid cut to the parts that read (2.9MB); it travels in the page directory beside the renderer it answers for, and no reader's browser fetches it. The contract for a diagram is now "valid Mermaid that Beautiful Mermaid draws faithfully". Sources Mermaid refuses are refused even where the renderer happened to draw them, unquoted parentheses in a label above all; quoting the label is the fix. A page never put through the render gate draws whatever the renderer made of its source. `UNSUPPORTED_DIRECTIVE` and `rejectCutLabel` are deleted, and their two browser tests give way to one gate test over twelve misdrawn sources and nine faithful controls. `examples/security-boundary.html` was itself misdrawn: a transition named `S0` before `state "S0 · Gate passed" as S0` declared it, so the box was labelled `S0`. The declarations now come first. Supersedes #860. Closes #859. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Agentic Mermaid 0.4.1 is a fork of Beautiful Mermaid that draws more of Mermaid as Mermaid reads it: quoted labels holding their own closer, `--o` and `--x` heads, arrows without spaces, slanted shapes, choice/fork/join states, state and class notes, concurrent regions, class namespaces, sequence boxes and `autonumber`, and edges routed from the node the source names. Under the render check, seven of the twelve sources the old renderer misdrew now draw faithfully, and every diagram in the shipped pages passes `version check --render`. The renderer documents `data-id`, `data-role`, `data-from` and `data-to` as the attributes to read, so the check's drawn half now reads those roles rather than the old renderer's class names, and its source half reads more of what Mermaid reports: notes, sequence boxes, ER aliases, invisible links, numbering, titles and links. Families outside the six Leaf documents are refused before any comparison, since the renderer draws pie, Gantt, mindmap and others that the check cannot compare. The check still refuses what this renderer gets wrong: a `click` target it draws as a node that goes nowhere, a sequence `title` it drops, a state statement ending in `;` that it drops, a state labelled before its declaration, and ER word cardinalities. The widget takes the palette, sans face and a per-rendering `idPrefix` through the renderer's options, which replaces Leaf's own id namespacing and font stripping; only the mono stack is still rewritten. `interactive: true` draws a dot per line-chart value, as the old renderer did, which is also what the check counts. Visual parts select boxes by role and skip ids the `parts` grammar cannot spell, so a quoted ER name no longer breaks the parts inventory. The cost is size and time: the bundle is 2.90MB against 1.56MB (869KB against 471KB gzipped), because the package ships its ASCII renderer, agent editing API and fifteen families in one module esbuild cannot cut down. A ten-diagram page presents about 200ms later locally, and the largest shipped diagram, a 17-transition state machine, renders in 101ms against 8ms. The XY chart draws solid full-width bars. Tests: the gate's misdrawn and faithful sets are re-sorted by what this renderer does; the failed-soft fixtures use `sankey-beta`, which it refuses, in place of `pie` and `gantt`, which it draws; the paint-token finding names the shape's own `data-id`; the font test accepts the renderer's trailing generic fallbacks. Co-Authored-By: Claude Opus 5 <[email protected]>
# Conflicts: # scripts/CLAUDE.md # scripts/vendor.py # skills/leaf/packages/diagram/widgets/lf-diagram-fidelity.js # skills/leaf/packages/diagram/widgets/lf-diagram.js # skills/leaf/references/authoring-evidence.md # tests/test_render_gate.py
A class inside a namespace of the same name shares its data-id with the namespace's group, and the role selector registered neither as a part; a group now gives way to the box under the same id. The fidelity module says that a frontmatter title never reaches it and why only an anchor counts as a drawn link, and the authoring guide names the renderer's frontmatter-title and autonumber departures. Co-Authored-By: Claude Opus 5 <[email protected]>
# Conflicts: # tests/test_render_startup.py
The render check now asks Mermaid which family a source is before reading it, so a family Leaf does not draw is refused under its own name rather than failing inside a layout library the reader bundle leaves out (architecture diagrams did). The reader also returns the configuration a frontmatter block or directive sets, which is where `showSequenceNumbers` lives; the check numbered those messages as unnumbered and refused a faithful drawing. Mermaid holds an entity code such as `#36;` as a placeholder until it draws, and the check now decodes it, so a refusal over one names the character. The renderer draws the code as written, which the gate and the authoring guide now say. Co-Authored-By: Claude Opus 5 <[email protected]>
# Conflicts: # tests/test_render_gate.py
With Agentic Mermaid drawing lf-diagram, the render gate's comparison against official Mermaid is Leaf maintaining a second reading of another library's grammar: a mapping between two vocabularies that moves whenever either library does. It goes, with the 2.9MB Mermaid reader bundle, its builder in scripts/vendor.py, and `registerRenderCheck`, which only lf-diagram used. #902's per-widget failure naming stays. Behavior that moved: - A family Agentic Mermaid draws is no longer refused because Leaf's guidance does not name it: pie, Gantt, mindmap and timeline pass the gate. A source the renderer cannot draw at all still fails soft and is reported (UNPARSABLE_DIAGRAM). - A source the renderer draws differently from Mermaid (a click target, a sequence title, a state statement ending in `;`) is no longer refused. The authoring guide says so and asks for a look at each diagram. - The guide routes quantities to lf-chart rather than Mermaid's XY or pie charts, whose Agentic Mermaid drawing ports Mermaid's own heavy style. test_the_gate_refuses_a_diagram_that_does_not_draw_its_source is replaced by test_the_gate_passes_every_family_the_renderer_draws, which fails on the previous commit. Co-Authored-By: Claude Opus 5 <[email protected]>
The fidelity test was the only assertion of two behaviors that still ship: #902's per-widget failure naming, and the filter that keeps a box whose id is several words out of the visual parts. The shim's gate test now requires the `<lf-diagram id='d-broken'>` form without the source, and the families test draws a multi-word mindmap node and a quoted ER entity beside every family the renderer adds. Each goes red when its behavior is undone. The authoring guide corrects two claims: the renderer draws many, not all, of Mermaid's other families, and quoting matters for a label holding its shape's closing bracket, not for parentheses. It lists again where the renderer parts from Mermaid, since the gate no longer sees those, and says the gate reports a diagram drawn empty as well as one refused. Co-Authored-By: Claude Opus 5 <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
An authored click or link directive now ships a tab stop the page cannot answer. Agentic Mermaid draws that target as <g data-id="A" data-label="Alpha" data-href="https://example.com" role="link" tabindex="0" data-role="node">, and renderMermaidSVG is the only thing lf-diagram imports — whatever makes data-href navigate lives in event wiring the widget never loads. A reader tabs into a diagram box announced as a link, presses Enter, and nothing happens. It reproduces on a flowchart click … href and on classDiagram link; click … call and a state click draw no stop.
On main that source was refused — click-directive was one of MISDRAWN_DIAGRAMS, so the gate failed the diagram soft. With the check gone the gate is silent: on this head, render_version over a page holding click A href "https://example.com" "Open" returns [], and the rendered document carries {tag: 'g', role: 'link', tab: '0', href: 'https://example.com'} inside lf-diagram.
That is also what makes one sentence in the paragraph now carrying the removed gate's weight false — "it draws no click or link target". The renderer does draw one; it draws an inert one. And the remedy the same paragraph prescribes is to "look at each diagram once", which is the one thing that cannot find this: a dead tab stop has no visual witness in either scheme, at any width, on paper or in an export.
The post-render pass is the boundary that already normalizes the renderer's fonts and its definition ids, so dropping the affordance there keeps the sentence true instead of correcting it — inline suggestion below. Wiring data-href into real navigation is the other direction, but an outbound link from a diagram box is a product decision rather than a normalization, so I did not assume it.
What I checked and found sound
Verified against the vendored bundle and the browser gate on this head, recorded so a later pass does not re-derive it:
idPrefixfully replacesnamespaceDefinitions. Rendering the same source twice under different prefixes gives disjointidsets, with no unprefixedidand no danglingurl(#…), across flowchart, sequence, class, ER, XY, architecture, mindmap and gantt. The removed pass also rewroteurl(#…)inside<style>text and the bare#idattribute form; neither shape survives in the new output.- Dropping the
@importstrip is safe. The bundle still contains the Google Fonts import, but behind a parameter that defaults off and a family-name test (/^[A-Za-z0-9][A-Za-z0-9 _-]*$/) thatvar(--sans)fails. No output under Leaf's options carries@import. - The mono rewrite still fires.
'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospaceis still the literal the renderer writes for class members and ER attributes. NAMEABLEmatches the registry exactly — the same[A-Za-z_][A-Za-z0-9_-]*token aslf-diagram'spartspattern, so it narrows nothing an author could declare. No family emits anode/group/actor/class-box/entitygroup without adata-id, andvisualPartProblemsonly reports declared parts that fail to register, so the extra synthetic registrations (_start, gitGraphc0) are inert.- The deleted
FAITHFUL_DIAGRAMScontrols all still hold. Each of the ten sources draws its boxes and edges under the new renderer, includingclassDefwithvar(--ok-tint)/var(--ok)/var(--ok-ink)andlinkStyle, which is the claim the authoring guide keeps. - The bundle passes
refuse_if_csp_forbids— nonew Function,eval(, orimport(— and its licenses cover Material Design Icons through the renderer's ownTHIRD_PARTY_NOTICES.mdandLICENSES/.
Test selection run on the merged tree: the diagram cases in test_render_gate.py, and the diagram cases in test_render_pages.py, test_render_startup.py, test_render_aim.py, test_render_reactions.py and test_render_semantic_selection.py — 11 passed. test_the_shim_runs_the_gate_from_anywhere could not run here: the installed Chrome does not launch in this sandbox, which is environmental and unrelated to the branch.
agentic-mermaid draws a `click … href` or class `link` target as a `role="link" tabindex="0"` group carrying `data-href`, and nothing on a Leaf page navigates it: a reader tabs to a box announced as a link and Enter does nothing. The renderer's own `security: "strict"` mode leaves that target out, and changes nothing else in any shipped or test diagram. That also makes the authoring guide's "it draws no `click` or `link` target" true. test_a_diagram_link_draws_no_tab_stop fails without the option. Co-Authored-By: Claude Opus 5 <[email protected]>
lf-diagramnow draws with agentic-mermaid 0.4.1, a fork of Beautiful Mermaid 1.1.3 that documents the SVG it writes and draws more of Mermaid. With a renderer that holds up on its own, the render gate stops re-reading each diagram with official Mermaid: #899's differential check, the 2.85MB Mermaid reader bundle it imported, and theregisterRenderCheckhook only it used are removed. The gate reports a diagram only when the renderer refuses it or draws it empty, and every family the renderer draws passes.What a reader sees
pr-walkthrough, TempIndex's three edges now leave TempIndex rather than running up a trunk from Committed changes. Sequence diagrams draw notes,autonumberand-xheads, which Beautiful Mermaid dropped.[/lean/]stops at its own closer instead of swallowing the next node.xychart/layout.ts): bars fill 95% of their band from a constant with no option, fills are solid and unstroked, and axes carry lines and ticks. The title overlapping the top gridline happens with the library's defaults too. Mermaid config and a tint on the documenteddata-role="bar"lighten it but keep the bars full-width, so this change leaves the chart as drawn and the authoring guide sends quantities tolf-chart.What the gate no longer catches
agentic-mermaid still departs from Mermaid in places, and those now draw silently: no
clickorlinktarget (the box draws as a plain one), no frontmatter or sequencetitle, a state statement ending in;dropped, a state labelled with its bare id when a transition names it beforestate "…" as S0declares it, ER relationships read only in symbol form, and an entity code such as#36;drawn as written.skills/leaf/references/authoring-evidence.mdlists them and asks for a look at each diagram. A diagram drawn empty (a lone[*] --> A;, or only word cardinalities) is still reported, as a widget with no usable size.Where to look
skills/leaf/packages/diagram/widgets/lf-diagram.js— the renderer's ownfontandidPrefixoptions replace Leaf's font rewrite and id namespacing;security: "strict"leaves out aclickorlinktarget, which the default mode draws as a focusable link nothing navigates;interactive: truegives chart values a hover tooltip and a line series its dots. Parts are read from the renderer's documenteddata-rolecontract; a namespace gives way to a class of the same name, and an id that is not one token (a quoted ER name, a multi-word mindmap node) is not offered as a part.scripts/vendor.py—build_agentic_mermaidreplaces the Beautiful Mermaid build;elkjs,entitiesandyamlare held by agentic-mermaid's declared ranges. The reader build and themermaidpin are gone.skills/leaf/assets/runtime/render-check.js,render-checks/widgets.js,render_gate/readings.py— the hook and its gate wiring removed; Name the widget a render-gate failure came from #902's per-widget failure naming stays.tests/test_render_gate.py—test_the_gate_passes_what_the_renderer_drawscovers every added family plus the multi-word and quoted ids, and fails on a head where the check still ran.test_the_shim_runs_the_gate_from_anywherenow holds Name the widget a render-gate failure came from #902's<lf-diagram id='d-broken'> failed soft:form without the source. Fixtures that relied on pie failing usesankey-beta, which the renderer does not implement.Validation
uv run pytest tests -qone3317831: 1215 passed. The one commit since addssecurity: "strict", which renders all 39 drawable shipped and test diagrams byte-identically, andtest_a_diagram_link_draws_no_tab_stop, which fails without it.npm run test:runtime: 33 passed.test_render_aim.py,test_render_reactions.pyandtest_render_semantic_selection.pypass: Alt+click andsstill target a declared box.version check --renderpassed on the four shipped pages with diagrams (security-boundary,pr-walkthrough,corpus,how-it-works) during the trial, when the check still ran; removing the check only relaxes the gate.scripts/verify-site-local.shphase profile was not run: it needs Docker, which was not available.🤖 Generated with Claude Code