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 <cx:source> metadata block.
[?lib 'cx-stdlib/diagram' as=diagram]
[$diagram:extract-svg "<svg><metadata><cx:source>W3hd</cx:source></metadata></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, direction tb|lr defaulting to tb): 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 <metadata><cx:source> 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 "<svg></svg>" "[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 ten 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 ten-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:flow-rules
[$diagram:flow-rules] -> element — The sealed FLOW picture rule table as data (RULED: WF-17): one row per row of flow.md §4.17's construct table — thirteen, since 1316-b5 added the step re-attempt row — the five construct words that mint a document address, the closed role vocabulary for a construct's second node, and the two region tokens. A row whose construct — or whose named half of one — validate does not accept yet carries pending= and the reason naming its landing, so the picture never claims to draw a construct the grammar cannot carry.
[?lib 'cx-stdlib/diagram' as=diagram]
([$count [?for [in $r [$diagram:flow-rules]/*] [where [= [$name $r] "row"]] [yield $r]]],
[$count [?for [in $r [$diagram:flow-rules]/*] [where [?if [= [$name $r] "row"] [then [$exists $r@pending]] [else false]]] [yield $r]]])
(13, 5)
diagram:flow-node-id
[$diagram:flow-node-id] -> string — The picture node id for a construct's document address (RULED: 1316-a) — the ONE place the mermaid/dot id charset rule lives. It ESCAPES rather than replaces, so address to id is INJECTIVE: [A-Za-z0-9] passes through, _ doubles, the address punctuation / [ ] # - takes a one-letter mnemonic, and any other character becomes its UTF-8 bytes as _x<hex>_. The code-diagram subject's counter ids are a different discipline and are not unified with these.
[?lib 'cx-stdlib/diagram' as=diagram]
([$diagram:flow-node-id "a/b"], [$diagram:flow-node-id "a-b"], [$diagram:flow-node-id "a_b"])
(a_sb, a_hb, a__b)
diagram:flow-diagram
[$diagram:flow-diagram] -> string | err — The ONE derived canonical picture of a flow document as Mermaid text (RULED: WF-17), at the detail rung min|compact|full. Every drawn element carries the document address of the construct it draws: a node's id IS that address, sanitized (RULED: 1316-a), so the picture is selectable in its text form and not only in SVG. Steps are nodes on the main axis in document order, a pivot= step the marked hexagon, a branch a lane per [seq] between a fork bar and a join bar, a map one annotated lane with its body drawn once, when= a labeled edge plus the skip edge, needs= an edge from each named sibling. Region tokens ride as classes with no classDef: §4.17 binds topology and marks and never theme, so a tenant's picture is its own colors through the token cascade. Refuses CXER0281 for a value that is not a [flow …] document.
[?lib 'cx-stdlib/diagram' as=diagram]
[?let [= $doc [flow name="release"
[step name="build" [do 'repo/build']]
[step name="tag" pivot=true [do 'repo/tag']]
[step name="publish" [do 'repo/publish']]]]
[$diagram:flow-diagram $doc "min"]]
'flowchart TD\n _sflow_orelease_c(["flow release"])\n _sflow_orelease_c --> _sflow_orelease_c_sstep_obuild_c\n _sflow_orelease_c_sstep_obuild_c["build"]\n _sflow_orelease_c_sstep_otag_c{{"tag"}}\n _sflow_orelease_c_sstep_obuild_c --> _sflow_orelease_c_sstep_otag_c\n _sflow_orelease_c_sstep_opublish_c["publish"]\n _sflow_orelease_c_sstep_otag_c --> _sflow_orelease_c_sstep_opublish_c'
diagram:flow-overlay-rules
[$diagram:flow-overlay-rules] -> element — The sealed RUN-OVERLAY rule table as data (RULED: 1316-b2): one mark row per mark in flow.md §4.17's run-overlay sentence — eight — so the completeness gate diffs the table against that sentence for set equality. Four marks emit today (a construct's status=, its activated= — the fold ordinal of the transition that moved it off :waiting, which the EMITTER resolves to that transition's instant and paints elapsed from (RULED: 1316-c1, 1316-d) — a map's child-run counts, and the [conflict …] on an uncompensatable construct) and four carry pending= with the reason naming what each waits on: holder and quorum on the W3 performer axis, iteration on until, and run-state because pause/resume/cancel are named landings with no wave assigned. A mark that cannot be projected is registered rather than emitted empty, so "this run has no conflict" and "this build cannot draw conflicts" never read alike.
[?lib 'cx-stdlib/diagram' as=diagram]
([$count [?for [in $r [$diagram:flow-overlay-rules]/*] [where [= [$name $r] "mark"]] [yield $r]]],
[$count [?for [in $r [$diagram:flow-overlay-rules]/*] [where [?if [= [$name $r] "mark"] [then [$exists $r@pending]] [else false]]] [yield $r]]])
(8, 4)
diagram:flow-overlay
[$diagram:flow-overlay] -> element | err — The RUN overlay for a flow document and one of its [flow-run …] records (RULED: 1316-b1) — [flow-overlay run= status= [node id= status= …]…], a pure projection of the record keyed by the node id flow-diagram draws with, so a painter applies it to the base picture without re-running the layout walk and the flow keeps ONE diagram. The record is flat and keyed by name=; the picture's ids are the full document address, and the id being a pure function of that address is what joins them. A [seq] lane takes no row, because the record tracks no lane. Refuses CXER0281 for a value that is not a [flow …] document, for one that is not a [flow-run …] record, and for a record that pinned ANOTHER document at start — which would otherwise paint nothing and read like a run that has not begun.
[?lib 'cx-stdlib/diagram' as=diagram]
[?let [= $doc [flow name="release"
[step name="build" [do 'repo/build']]
[step name="tag" pivot=true [do 'repo/tag']]]]
[= $rec [flow-run id='flow:r1' status=:running
[step name=build status=:done ord=3]
[step name=tag status=:running pivot=true]]]
[$diagram:flow-overlay $doc $rec]]
[flow-overlay run=flow:r1 status=:running [node id=_sflow_orelease_c_sstep_obuild_c status=:done] [node id=_sflow_orelease_c_sstep_otag_c status=:running]]
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