Generated state diagrams: why spells draw what they computed

Why some Arcane spells end their output with a Mermaid diagram built only from values they already computed, and when they draw none.

Documented for v1.24.1 · Checked

Written against v1.14.0; current release is v1.24.1.

Some Arcane spells end their report with a small Mermaid diagram. The diagram is not decoration and it is not the model's interpretation: it is drawn only from values the spell has already computed, by a fixed recipe, so the same state should produce the same picture.

The convention

Arcane's universal agent rules ask for Mermaid wherever a diagram helps: flow charts, architecture and sequence diagrams. One case gets a stricter rule. When a spell's output describes state the spell already computed, such as versions it read or branches it found, the diagram must be deterministic and data-derived: built only from values in scope, never modelled or invented. The rule is advisory: no lint or check enforces it.

The rule also says when not to draw. A one-line output, a spell built for speed, or a state with only one reading gets no diagram. The picture is there to make the relationship between several computed values legible, and a single value has no relationship to show.

An example: version drift

spell-open-session checks two things at the start of a session: whether the repository's managed files are behind the installed CLI, and whether the installed CLI is behind the latest release on npm. That gives three readings: the version recorded in the repository, the CLI's version, and npm's latest. When either check shows drift, the spell draws them as a gitGraph:

Git graph; its Mermaid source follows.
Diagram source
gitGraph
   commit id: "<repo-files version>"
   branch repo-files
   checkout main
   commit id: "<installed-CLI version>"
   branch installed-cli
   checkout main
   commit id: "<npm-latest version>" tag: "latest"

One commit per distinct version, in that order, and a branch off each reading that has fallen behind. The last commit is tagged latest. This is the case where both checks drift. When a check is current, its branch is left out, and equal versions collapse into one commit. The dangling branches are the drift, so the diagram needs no legend. When everything is current, the spell reports that and draws nothing.

Why deterministic

A diagram the model composes freely could be wrong in ways that are hard to spot, and a different run could draw the same state differently. A diagram derived by a fixed recipe from computed values is checkable: anyone can recompute the three versions and confirm the picture. It also means two sessions in the same state produce the same diagram, which makes the diagrams safe to compare.

Mermaid is text. It sits in the spell's Markdown output, diffs like any other text, and renders wherever Mermaid does. The spell also changes its fencing to :::mermaid when the output is going to an Azure DevOps wiki, and the source stays readable in a terminal with no renderer at all.

Was this page helpful?

Your answer

Please don't include personal information.