diagram
diagram:render-mermaid
[$diagram:render-mermaid] -> string | err — Render the engine-injected program image to Mermaid text (detail rung min|compact|full), refusing non-table top-level directives with CXER0281.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-mermaid [$diagram:render-mermaid [greet] "[greet]" "min"]]
'[greet]'
diagram:rules
[$diagram:rules] -> element — The sealed §10.1.2 render-rules table as data: rows, registry aliases, scaffolding, and nested-only emitters.
[?lib 'cx-stdlib/diagram' as=diagram]
[$count [?for [in $r [$diagram:rules]/*] [where [= [$name $r] "row"]] [yield $r]]]
26
diagram:admitted
[$diagram:admitted] -> bool — Whether a directive local name is admitted at top level (table rows, aliases, and scaffolding; nested-only emitters are not).
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:admitted "secret"]
false
diagram:extract-mermaid
[$diagram:extract-mermaid] -> string | err — Recover the verbatim embedded CX source from a rendered Mermaid diagram.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-mermaid "%%cx:W3hd%%"]
'[x]'
diagram:extract-svg
[$diagram:extract-svg] -> string | err — Recover the verbatim embedded CX source from an SVG rendering's
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-svg ""]
'[x]'
diagram:extract-png
[$diagram:extract-png] -> string | err — Recover the verbatim embedded CX source from a PNG rendering's cx-source tEXt chunk.
[?lib 'cx-stdlib/diagram' as=diagram]
[?lib 'cx-stdlib/bytes' as=bytes]
[?else [$diagram:extract-png [$bytes:from-base64 "iVBORw0KGgo="]] "no cx-source chunk"]
'no cx-source chunk'
diagram:render-dot
[$diagram:render-dot] -> string — Emit the DOT (graphviz) text for the engine-injected program image — the pure half of the SVG/PNG path.
[?lib 'cx-stdlib/diagram' as=diagram]
[?lib 'cx-stdlib/strings' as=strings]
[$strings:contains [$diagram:render-dot [greet]] "digraph CX {"]
true
diagram:render-svg
[$diagram:render-svg] -> string | err — Render the program image to SVG through graphviz (subprocess capability, allowlist dot); without the capability or without dot on PATH the round-trip-preserving 1x1 envelope is returned instead.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-svg [$diagram:render-svg [greet] "[greet]"]]
'[greet]'
diagram:render-png
[$diagram:render-png] -> bytes | err — Render the program image to PNG through graphviz, splicing the source into a cx-source tEXt chunk; degrades to the 1x1 envelope when dot is unavailable.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-png [$diagram:render-png [greet] "[greet]"]]
'[greet]'
diagram:of-source
[$diagram:of-source] -> string | bytes | err — Render CX SOURCE TEXT to a diagram in one call (format mermaid|dot|svg|png, detail rung defaulting to min): the program lift happens inside the module, and cx diagram renders through this same entry, so a CX caller and the CLI produce identical bytes.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-mermaid [$diagram:of-source "[greet]" "mermaid"]]
'[greet]'
diagram:code-diagram
[$diagram:code-diagram] -> string | err — The playground renderer: classify CX source text (data → ERD, sequence-shape code → SEQ, other code → CFG) and emit Mermaid at the requested level (min|compact|full).
[?lib 'cx-stdlib/diagram' as=diagram]
[?lib 'cx-stdlib/strings' as=strings]
[$strings:contains [$diagram:code-diagram "[user id=1]" "min"] "erDiagram"]
true
diagram:svg-envelope
[$diagram:svg-envelope] -> string — The dot-less SVG contract: a valid 1x1 SVG carrying only the embedded source, so the round trip holds on profiles without graphviz.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-svg [$diagram:svg-envelope "[x]"]]
'[x]'
diagram:png-envelope
[$diagram:png-envelope] -> bytes — The dot-less PNG contract: a valid 1x1 PNG whose cx-source tEXt chunk carries the embedded source.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-png [$diagram:png-envelope "[x]"]]
'[x]'
diagram:inject-svg-metadata
[$diagram:inject-svg-metadata] -> string — Splice a block carrying the base64 source into an SVG document (after its first >, reproducing the shipped placement — DRW2-2).
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-svg [$diagram:inject-svg-metadata "" "[x]"]]
'[x]'
diagram:inject-png-chunk
[$diagram:inject-png-chunk] -> bytes — Splice a cx-source tEXt chunk (with its CRC-32) into a PNG immediately after IHDR.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-png [$diagram:inject-png-chunk [$diagram:png-envelope "[y]"] "[x]"]]
'[x]'
diagram:crc32
[$diagram:crc32] -> int — The PNG chunk CRC-32 (IEEE 802.3 polynomial) over a byte buffer — the checksum the tEXt splice writes.
[?lib 'cx-stdlib/diagram' as=diagram]
[?lib 'cx-stdlib/bytes' as=bytes]
[$diagram:crc32 [$bytes:from-string-utf8 "IEND"]]
2923585666
diagram:code-rules
[$diagram:code-rules] -> element — The sealed wave-3 rule table as data: the sequence triggers, the directives that break a CFG basic block, the SEQ inner-dispatch classes, and the ERD scalar-type map. The emitters read it, so the table IS the set.
[?lib 'cx-stdlib/diagram' as=diagram]
[$count [?for [in $r [$diagram:code-rules]/*] [where [= [$name $r] "trigger"]] [yield $r]]]
5
diagram:code-class
[$diagram:code-class] -> string — The SEQ inner-dispatch class the playground renderer takes for a directive local name; generic (a Note over WORKER line) for a directive the table does not name.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:code-class "const"]
'generic'
diagram:effect-graph
[$diagram:effect-graph] -> string | err — The EFFECT/CAPABILITY graph of a CX source (RULED: DGX-1): which of security.md §2's nine capabilities the program reaches, through which call path, and which only under a branch — at min (the verdict), compact (the paths) or full (uncharged effects, [?with-caps] denials, colour classes). What it cannot resolve statically — a dynamic [?eval], an unresolvable callee, a source-text hatch, an unreadable [?lib], a Ring-2 pack verb — renders as an explicit UNKNOWN edge, never omitted. Reachability is syntactic and the resource scope is never shown: it answers "it can read", not "it reads /etc/passwd".
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:effect-graph "[?def double ($x) [* $x 2]]" "min"]
'flowchart TD\n prog(["program"])\n nocap["no capability-charging effect reached"]\n prog --> nocap'
diagram:effect-rules
[$diagram:effect-rules] -> element — The sealed effect-graph rule table as data: the nine-capability roster with its grant flags, the directive heads that charge a capability, the branch-arm carriers that make a reached effect conditional, and the opacity classes that must render as an unknown edge. The primitive→capability map is deliberately NOT here — it is read live from the engine, so this diagram cannot under-report a newly-gated effect point.
[?lib 'cx-stdlib/diagram' as=diagram]
[$count [?for [in $r [$diagram:effect-rules]/*] [where [= [$name $r] "cap"]] [yield $r]]]
9
diagram:effect-cap
[$diagram:effect-cap] -> string — The capability a PRIMITIVE charges, read live from the engine's own closed effect-point table (security.md §2.1); the empty string for a primitive that charges nothing.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:effect-cap "io-read-file"]
'read'