agentic-mermaid 0.4.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/AGENT_NATIVE.md +94 -627
  2. package/CHANGELOG.md +651 -0
  3. package/Instructions_for_agents.md +44 -23
  4. package/LICENSES/Khroma-MIT.txt +21 -0
  5. package/LICENSES/Mermaid-MIT.txt +21 -0
  6. package/LICENSES/es-toolkit-MIT.txt +21 -0
  7. package/LICENSES/pele-MIT.txt +40 -0
  8. package/LICENSES/zenuml-core-MIT.txt +21 -0
  9. package/README.md +93 -50
  10. package/SECURITY.md +28 -12
  11. package/THIRD_PARTY_NOTICES.md +60 -0
  12. package/assets/hero.png +0 -0
  13. package/dist/agent-core.d.ts +478 -210
  14. package/dist/agent-core.js +1 -396
  15. package/dist/agent.d.ts +17 -8
  16. package/dist/agent.js +1 -408
  17. package/dist/agentic-mermaid-mcp.js +1 -11
  18. package/dist/am.js +1 -34562
  19. package/dist/browser-lazy/chunks/agentic-producer-core-CC6OOLDW.js +1 -0
  20. package/dist/browser-lazy/chunks/architecture-QUFVKYJR.js +13 -0
  21. package/dist/browser-lazy/chunks/block-6J3Q63BO.js +11 -0
  22. package/dist/browser-lazy/chunks/builtin-backends-7SOZZHPF.js +12 -0
  23. package/dist/browser-lazy/chunks/c4-SQVBZAKJ.js +10 -0
  24. package/dist/browser-lazy/chunks/chunk-2GPK4VFF.js +5 -0
  25. package/dist/browser-lazy/chunks/chunk-2I4UPL7Q.js +3 -0
  26. package/dist/browser-lazy/chunks/chunk-2SH76OTH.js +1 -0
  27. package/dist/browser-lazy/chunks/chunk-2UIA2IME.js +3 -0
  28. package/dist/browser-lazy/chunks/chunk-4LHYF3BS.js +1 -0
  29. package/dist/browser-lazy/chunks/chunk-5B2Z7575.js +1 -0
  30. package/dist/browser-lazy/chunks/chunk-5FQ534HP.js +1 -0
  31. package/dist/browser-lazy/chunks/chunk-5UVGUSD6.js +1 -0
  32. package/dist/browser-lazy/chunks/chunk-5X6MJX3H.js +1 -0
  33. package/dist/browser-lazy/chunks/chunk-AMJLVPUB.js +4 -0
  34. package/dist/browser-lazy/chunks/chunk-BU5LHXNJ.js +3 -0
  35. package/dist/browser-lazy/chunks/chunk-BY2CPG6B.js +1 -0
  36. package/dist/browser-lazy/chunks/chunk-CN7WTBWB.js +1 -0
  37. package/dist/browser-lazy/chunks/chunk-CQE4HQEW.js +1 -0
  38. package/dist/browser-lazy/chunks/chunk-CSFUKSU6.js +1 -0
  39. package/dist/browser-lazy/chunks/chunk-DF6765YX.js +17 -0
  40. package/dist/browser-lazy/chunks/chunk-E2WMJZNM.js +1 -0
  41. package/dist/browser-lazy/chunks/chunk-FAIMVOX5.js +6 -0
  42. package/dist/browser-lazy/chunks/chunk-GVOEAY52.js +1 -0
  43. package/dist/browser-lazy/chunks/chunk-HLWUNUCM.js +1 -0
  44. package/dist/browser-lazy/chunks/chunk-ICC7HBJX.js +1 -0
  45. package/dist/browser-lazy/chunks/chunk-J35HAQQF.js +20 -0
  46. package/dist/browser-lazy/chunks/chunk-J7FFAFQF.js +1 -0
  47. package/dist/browser-lazy/chunks/chunk-LH7HUDKW.js +1 -0
  48. package/dist/browser-lazy/chunks/chunk-N5ELX7LR.js +2 -0
  49. package/dist/browser-lazy/chunks/chunk-NMQQMRIR.js +1 -0
  50. package/dist/browser-lazy/chunks/chunk-NO7ZIVRU.js +1 -0
  51. package/dist/browser-lazy/chunks/chunk-OZ443IVJ.js +16 -0
  52. package/dist/browser-lazy/chunks/chunk-PQGPS2YV.js +7 -0
  53. package/dist/browser-lazy/chunks/chunk-QA6GJQ4X.js +1 -0
  54. package/dist/browser-lazy/chunks/chunk-RIVTHZAQ.js +1 -0
  55. package/dist/browser-lazy/chunks/chunk-SZELX2EJ.js +1 -0
  56. package/dist/browser-lazy/chunks/chunk-TYZOZXUJ.js +22 -0
  57. package/dist/browser-lazy/chunks/chunk-UL6NDWLL.js +1 -0
  58. package/dist/browser-lazy/chunks/chunk-VQYYGAXP.js +1 -0
  59. package/dist/browser-lazy/chunks/chunk-VWVZGQE2.js +1 -0
  60. package/dist/browser-lazy/chunks/chunk-X2UYKWKM.js +4 -0
  61. package/dist/browser-lazy/chunks/chunk-YCEICNM6.js +1 -0
  62. package/dist/browser-lazy/chunks/chunk-Z3FDIVLN.js +20 -0
  63. package/dist/browser-lazy/chunks/class-5QA4SCTS.js +13 -0
  64. package/dist/browser-lazy/chunks/decode-63UIZGD2.js +1 -0
  65. package/dist/browser-lazy/chunks/elk.bundled-L4CADV5W.js +24 -0
  66. package/dist/browser-lazy/chunks/er-7ZSKGN7Y.js +11 -0
  67. package/dist/browser-lazy/chunks/eventmodeling-2BPLHWRN.js +19 -0
  68. package/dist/browser-lazy/chunks/flowchart-NEIMZTB5.js +4 -0
  69. package/dist/browser-lazy/chunks/forest-implementation-AEP24AIP.js +1 -0
  70. package/dist/browser-lazy/chunks/gantt-RDPIFYAF.js +11 -0
  71. package/dist/browser-lazy/chunks/gitgraph-N4Y5RYB7.js +9 -0
  72. package/dist/browser-lazy/chunks/ishikawa-LD3YBDJN.js +6 -0
  73. package/dist/browser-lazy/chunks/journey-6YQR5DJX.js +16 -0
  74. package/dist/browser-lazy/chunks/kanban-PLMJ7NBW.js +20 -0
  75. package/dist/browser-lazy/chunks/mermaid-yaml-runtime-QVYX4EWK.js +136 -0
  76. package/dist/browser-lazy/chunks/mindmap-K2UBFO3Y.js +12 -0
  77. package/dist/browser-lazy/chunks/packet-CUW4QY6Y.js +7 -0
  78. package/dist/browser-lazy/chunks/pie-7F7UUCG3.js +15 -0
  79. package/dist/browser-lazy/chunks/quadrant-TOONO2WC.js +10 -0
  80. package/dist/browser-lazy/chunks/radar-J6JVWVAX.js +16 -0
  81. package/dist/browser-lazy/chunks/render-core-BZOM3K7D.js +3 -0
  82. package/dist/browser-lazy/chunks/requirement-CMAKDJPO.js +19 -0
  83. package/dist/browser-lazy/chunks/sankey-AWXQEP3F.js +13 -0
  84. package/dist/browser-lazy/chunks/sequence-Q2RJRB4L.js +5 -0
  85. package/dist/browser-lazy/chunks/state-WRBFQEDX.js +4 -0
  86. package/dist/browser-lazy/chunks/timeline-D2KILFXM.js +6 -0
  87. package/dist/browser-lazy/chunks/treemap-N3VYX5D4.js +6 -0
  88. package/dist/browser-lazy/chunks/xychart-G73OGK66.js +16 -0
  89. package/dist/browser-lazy/chunks/zenuml-H4BXNYXR.js +16 -0
  90. package/dist/browser-lazy/index.d.ts +544 -275
  91. package/dist/browser-lazy/index.js +1 -1
  92. package/dist/browser.global.js +802 -565
  93. package/dist/chunk-3LGLPG33.js +2 -0
  94. package/dist/chunk-7CRDX2QR.js +2 -0
  95. package/dist/chunk-7PPW2BMO.js +2 -0
  96. package/dist/chunk-DQDKA5ND.js +2 -0
  97. package/dist/chunk-EHCMJUMD.js +52 -0
  98. package/dist/chunk-GVCHLSHH.js +4 -0
  99. package/dist/chunk-H3NCS2XZ.js +19 -0
  100. package/dist/chunk-JZOJ4YGS.js +201 -0
  101. package/dist/chunk-MKE7GNYU.js +146 -0
  102. package/dist/chunk-NKNFOREZ.js +2 -0
  103. package/dist/chunk-O7H2UX5K.js +2 -0
  104. package/dist/chunk-OMY6NRQD.js +58 -0
  105. package/dist/chunk-UA234O4M.js +4 -0
  106. package/dist/chunk-VUFVLGTH.js +2 -0
  107. package/dist/chunk-XU5LPD2D.js +2 -0
  108. package/dist/cli-YGGTJZH7.js +226 -0
  109. package/dist/elk-constructor.js +2 -0
  110. package/dist/elk-constructor.node.js +11 -0
  111. package/dist/index-EeXqJXr5.d.ts +1223 -0
  112. package/dist/index.d.ts +4 -1
  113. package/dist/index.js +1 -334
  114. package/dist/jsonl-RPJY6YWO.js +2 -0
  115. package/dist/mcp-cli-63DYXTVD.js +2 -0
  116. package/dist/{index-BGA_-6LV.d.ts → paint-certification-6rwQjIv_.d.ts} +5283 -6173
  117. package/dist/server-5NEOHOFS.js +524 -0
  118. package/dist/svg-styles-BdnoM7AT.d.ts +724 -0
  119. package/dist/svg-styles.d.ts +1 -0
  120. package/dist/svg-styles.js +2 -0
  121. package/dist/svg.d.ts +13 -0
  122. package/dist/svg.js +2 -0
  123. package/dist/types-BcS52Mjt.d.ts +1360 -0
  124. package/dist/zenuml/chunks/appearance-UOQ5KA6O.js +1 -0
  125. package/dist/zenuml/chunks/builtin-backends-KDKE7YHO.js +12 -0
  126. package/dist/zenuml/chunks/chunk-42DXZ5C6.js +4 -0
  127. package/dist/zenuml/chunks/chunk-7TVYPTDW.js +1 -0
  128. package/dist/zenuml/chunks/chunk-EVPSMEKN.js +1 -0
  129. package/dist/zenuml/chunks/chunk-OXQWRSBM.js +20 -0
  130. package/dist/zenuml/chunks/chunk-QWX77U7G.js +2 -0
  131. package/dist/zenuml/chunks/chunk-RLJEI7YN.js +29 -0
  132. package/dist/zenuml/chunks/chunk-RZ6XK5CD.js +29 -0
  133. package/dist/zenuml/chunks/decode-BWERFDGK.js +1 -0
  134. package/dist/zenuml/chunks/mermaid-yaml-runtime-KZVU74WU.js +136 -0
  135. package/dist/zenuml/chunks/render-core-V5RQ737O.js +3 -0
  136. package/dist/zenuml/chunks/zenuml-EA2ZFRUX.js +20 -0
  137. package/dist/zenuml-frame.global.js +3626 -0
  138. package/dist/zenuml.d.ts +83 -0
  139. package/dist/zenuml.js +1 -0
  140. package/docs/MCP-DIRECTORY-LISTINGS.md +5 -1
  141. package/docs/README.md +59 -103
  142. package/docs/agent-api-cookbook.md +26 -16
  143. package/docs/agent-mutation-policy.md +86 -15
  144. package/docs/agent-workflow-examples.md +1 -1
  145. package/docs/api-advanced.md +385 -0
  146. package/docs/api.md +320 -366
  147. package/docs/ascii.md +40 -4
  148. package/docs/browser.md +46 -7
  149. package/docs/choosing-a-diagram.md +148 -0
  150. package/docs/code-mode-impact.md +1 -0
  151. package/docs/comparison.md +244 -28
  152. package/docs/computational-aesthetics-prototype-plan.md +10 -10
  153. package/docs/config.md +60 -2
  154. package/docs/custom-fonts.md +78 -21
  155. package/docs/diagram-families.md +160 -10
  156. package/docs/eventmodeling-and-zenuml.md +165 -0
  157. package/docs/features.md +21 -19
  158. package/docs/fork-differences.md +105 -32
  159. package/docs/getting-started.md +56 -51
  160. package/docs/layout-certification.md +126 -0
  161. package/docs/mcp-code-mode-rationale.md +20 -12
  162. package/docs/mcp-http-transport.md +14 -8
  163. package/docs/quality.md +145 -15
  164. package/docs/react.md +76 -31
  165. package/docs/style-authoring.md +23 -11
  166. package/docs/svg-semantic-contract.md +104 -4
  167. package/docs/testing-strategy.md +684 -126
  168. package/docs/theming.md +27 -8
  169. package/examples/styles/readme-hero.md +25 -0
  170. package/examples/styles/readme-hero.mmd +13 -0
  171. package/examples/styles/readme-hero.style.json +7 -0
  172. package/package.json +114 -57
  173. package/server.json +2 -2
  174. package/skills/agentic-mermaid-diagram-workflow/SKILL.md +26 -8
  175. package/skills/agentic-mermaid-diagram-workflow/references/cli.md +13 -3
  176. package/skills/agentic-mermaid-diagram-workflow/references/code-mode.md +2 -1
  177. package/skills/agentic-mermaid-diagram-workflow/references/flowchart.md +9 -6
  178. package/skills/agentic-mermaid-diagram-workflow/references/hosted-mcp.md +1 -0
  179. package/skills/agentic-mermaid-diagram-workflow/references/sequence.md +4 -3
  180. package/skills/agentic-mermaid-diagram-workflow/references/timeline.md +7 -6
  181. package/skills/agentic-mermaid-diagram-workflow/references/upstream/agentflow.md +574 -0
  182. package/skills/agentic-mermaid-diagram-workflow/references/upstream/architecture.md +10 -2
  183. package/skills/agentic-mermaid-diagram-workflow/references/upstream/c4.md +18 -0
  184. package/skills/agentic-mermaid-diagram-workflow/references/upstream/classDiagram.md +123 -0
  185. package/skills/agentic-mermaid-diagram-workflow/references/upstream/cynefin.md +6 -1
  186. package/skills/agentic-mermaid-diagram-workflow/references/upstream/entityRelationshipDiagram.md +129 -9
  187. package/skills/agentic-mermaid-diagram-workflow/references/upstream/eventmodeling.md +22 -0
  188. package/skills/agentic-mermaid-diagram-workflow/references/upstream/flowchart.md +188 -60
  189. package/skills/agentic-mermaid-diagram-workflow/references/upstream/gitgraph.md +13 -7
  190. package/skills/agentic-mermaid-diagram-workflow/references/upstream/mindmap.md +110 -1
  191. package/skills/agentic-mermaid-diagram-workflow/references/upstream/packet.md +38 -0
  192. package/skills/agentic-mermaid-diagram-workflow/references/upstream/requirementDiagram.md +115 -0
  193. package/skills/agentic-mermaid-diagram-workflow/references/upstream/sequenceDiagram.md +101 -0
  194. package/skills/agentic-mermaid-diagram-workflow/references/upstream/stateDiagram.md +87 -0
  195. package/skills/agentic-mermaid-diagram-workflow/references/upstream/swimlanes.md +105 -2
  196. package/skills/agentic-mermaid-diagram-workflow/references/upstream/timeline.md +12 -6
  197. package/skills/agentic-mermaid-diagram-workflow/references/upstream/usecase.md +953 -0
  198. package/skills/agentic-mermaid-diagram-workflow/references/upstream/venn.md +77 -0
  199. package/skills/agentic-mermaid-diagram-workflow/references/upstream/xyChart.md +1 -1
  200. package/dist/browser-lazy/chunks/architecture-KTHE2HX3.js +0 -31
  201. package/dist/browser-lazy/chunks/chunk-2XCPFAD5.js +0 -46
  202. package/dist/browser-lazy/chunks/chunk-3H4F7RBT.js +0 -1
  203. package/dist/browser-lazy/chunks/chunk-4EVLW2NJ.js +0 -1
  204. package/dist/browser-lazy/chunks/chunk-5Q4S74UO.js +0 -1
  205. package/dist/browser-lazy/chunks/chunk-6OAPWSDO.js +0 -1
  206. package/dist/browser-lazy/chunks/chunk-A7L4WWVW.js +0 -143
  207. package/dist/browser-lazy/chunks/chunk-C7FJO2I3.js +0 -4
  208. package/dist/browser-lazy/chunks/chunk-D3XXDKIO.js +0 -1
  209. package/dist/browser-lazy/chunks/chunk-DXA5WL7H.js +0 -4
  210. package/dist/browser-lazy/chunks/chunk-EPFMQPXX.js +0 -1
  211. package/dist/browser-lazy/chunks/chunk-FFOHLPDA.js +0 -2
  212. package/dist/browser-lazy/chunks/chunk-FLD63DXE.js +0 -2
  213. package/dist/browser-lazy/chunks/chunk-G6OLSHRG.js +0 -7
  214. package/dist/browser-lazy/chunks/chunk-GRXCKTHX.js +0 -0
  215. package/dist/browser-lazy/chunks/chunk-I6VE56S7.js +0 -1
  216. package/dist/browser-lazy/chunks/chunk-KJVNXJ5Y.js +0 -1
  217. package/dist/browser-lazy/chunks/chunk-L227EPFP.js +0 -11
  218. package/dist/browser-lazy/chunks/chunk-LNIHDJSF.js +0 -1
  219. package/dist/browser-lazy/chunks/chunk-M6BT2HIP.js +0 -1
  220. package/dist/browser-lazy/chunks/chunk-NZRUMODH.js +0 -1
  221. package/dist/browser-lazy/chunks/chunk-OFRMKQA6.js +0 -1
  222. package/dist/browser-lazy/chunks/chunk-P7HMSKHJ.js +0 -1
  223. package/dist/browser-lazy/chunks/chunk-PXKL3O6H.js +0 -1
  224. package/dist/browser-lazy/chunks/chunk-PZEWZT35.js +0 -1
  225. package/dist/browser-lazy/chunks/chunk-STQRDZ67.js +0 -1
  226. package/dist/browser-lazy/chunks/chunk-SUFMSWTX.js +0 -1
  227. package/dist/browser-lazy/chunks/chunk-T7IJ6V4B.js +0 -3
  228. package/dist/browser-lazy/chunks/chunk-UAEZO5VL.js +0 -1
  229. package/dist/browser-lazy/chunks/chunk-WEUWIFG3.js +0 -1
  230. package/dist/browser-lazy/chunks/chunk-X64T74C5.js +0 -24
  231. package/dist/browser-lazy/chunks/class-F7R6TJ73.js +0 -9
  232. package/dist/browser-lazy/chunks/er-BDK7CM5L.js +0 -9
  233. package/dist/browser-lazy/chunks/flowchart-KFU6XV7S.js +0 -4
  234. package/dist/browser-lazy/chunks/gantt-I64VVDSP.js +0 -28
  235. package/dist/browser-lazy/chunks/gitgraph-EDUVJ5IJ.js +0 -8
  236. package/dist/browser-lazy/chunks/journey-TLO2RNM3.js +0 -40
  237. package/dist/browser-lazy/chunks/mindmap-OJCNDYPM.js +0 -9
  238. package/dist/browser-lazy/chunks/pie-HVG6XO7K.js +0 -19
  239. package/dist/browser-lazy/chunks/quadrant-U6S2L4MJ.js +0 -24
  240. package/dist/browser-lazy/chunks/radar-ZDLOBTVG.js +0 -32
  241. package/dist/browser-lazy/chunks/render-core-Y2DFNMQG.js +0 -12
  242. package/dist/browser-lazy/chunks/sequence-Z4WFS3VB.js +0 -12
  243. package/dist/browser-lazy/chunks/state-2HV2YGN3.js +0 -4
  244. package/dist/browser-lazy/chunks/timeline-XM4UFPOC.js +0 -20
  245. package/dist/browser-lazy/chunks/xychart-7JDHWTQY.js +0 -36
  246. package/dist/chunk-GGXCNCNA.js +0 -4118
  247. package/dist/chunk-IVD4NXNE.js +0 -615
  248. package/dist/chunk-JDMRPUAG.js +0 -37
  249. package/dist/chunk-JWAAW3FH.js +0 -149
  250. package/dist/chunk-LCGBT32P.js +0 -62036
  251. package/dist/chunk-RWMZRUIC.js +0 -4715
  252. package/dist/mcp-cli-4MLKC3ZH.js +0 -17
  253. package/docs/mutation-testing.md +0 -285
package/docs/api.md CHANGED
@@ -1,418 +1,372 @@
1
- # API reference
1
+ # Library API
2
2
 
3
- Agentic Mermaid exposes these library surfaces:
3
+ Render artifacts, read painted geometry, or edit Mermaid source with typed operations.
4
4
 
5
- - `agentic-mermaid` — runtime-neutral renderer API for SVG, ASCII/Unicode,
6
- and host-injected browser PNG output.
7
- - `agentic-mermaid/agent` — agent-native API with
8
- parse/narrow/mutate/verify/serialize plus SVG, native Node/Bun PNG, and ASCII
9
- output helpers.
10
- - `agentic-mermaid/agent/core` — the same structured-edit, SVG, and ASCII
11
- surface without the native PNG dependency; use this entry in browser and
12
- workerd bundles.
5
+ ```ts
6
+ import { renderMermaidSVG } from 'agentic-mermaid'
13
7
 
14
- Capability reports, the pinned upstream manifest, and trusted Node-host
15
- resource resolution remain repository audit/host tooling rather than published
16
- runtime entry points.
8
+ const source = 'flowchart LR\n Idea --> Ship'
9
+ const svg = renderMermaidSVG(source, { style: ['hand-drawn', 'nord'] })
10
+ console.log(svg)
11
+ ```
17
12
 
18
- Use `agentic-mermaid/agent` when you want one import path for agents.
19
- Use `agentic-mermaid/agent/core` when the target runtime cannot load Node native
20
- addons.
13
+ Choose the task, then use the matching surface:
21
14
 
22
- ### Canonical requests and comparable receipts
15
+ | Task | Start here | Result |
16
+ |---|---|---|
17
+ | Render an artifact | [Rendering](#rendering) | SVG, PNG bytes, or terminal text |
18
+ | Draw or animate the artwork yourself | [Resolved paths and text](#resolved-paths-and-text) | JSON with painted paths, text, transforms and semantic parts |
19
+ | Change existing source | [Editing](#editing) | A typed edit, verification findings and serialized Mermaid |
23
20
 
24
- Every first-party renderer enters through the same immutable internal request
25
- boundary: source wrappers/config, the Style stack, colors, font, security, and
26
- shared options are normalized once. Receipt-bearing variants make that boundary
27
- observable without exporting its executable implementation types or changing
28
- the existing convenience return types:
21
+ Agents with a shell can use `am capabilities --json` and `am styles --json` to
22
+ discover installed support. In MCP, use `describe_sdk` for mutation fields and
23
+ `execute` for the documented Code Mode functions. Resolved scenes are currently
24
+ available from the main library entry only, not Code Mode.
29
25
 
30
- ```ts
31
- import {
32
- renderMermaidASCIIWithReceipt,
33
- renderMermaidPNGWithReceipt,
34
- renderMermaidSVGWithReceipt,
35
- } from 'agentic-mermaid/agent'
36
-
37
- const options = { style: 'hand-drawn', seed: 7, embedFontImport: false }
38
- const svg = renderMermaidSVGWithReceipt(source, options)
39
- const png = renderMermaidPNGWithReceipt(source, options)
40
- const text = renderMermaidASCIIWithReceipt(source, { ...options, colorMode: 'none' })
41
-
42
- console.assert(svg.receipt.sharedRequestDigest === png.receipt.sharedRequestDigest)
43
- console.assert(svg.receipt.appearanceDigest === text.receipt.appearanceDigest)
44
- ```
26
+ ## Vocabulary
45
27
 
46
- Each `RenderRequestReceipt` contains `version`, `output`,
47
- `sharedRequestDigest`, output-specific `requestDigest`, and
48
- `appearanceDigest`. Its `diagnostics` array records stable request-resolution,
49
- compatibility, applicability, projection, and output-policy decisions. In
50
- particular, `RENDER_OPTION_NOT_APPLICABLE` makes an authored family-scoped
51
- option that the selected family does not consume observable instead of letting
52
- it change request identity silently. CLI JSON results and local/hosted MCP
53
- render results expose the same receipt. Use `validateSerializableRenderOptions(value)` and
54
- `sharedRenderOptionsJsonSchema()` for untrusted advanced option objects, or
55
- `styleInputJsonSchema()` for a standalone convenience `style` field; unknown
56
- fields, `null`, functions, prototype keys, and non-finite values are rejected.
28
+ <!-- BEGIN GENERATED: diagram-terminology -->
29
+ A **family** is a Mermaid diagram type, such as Flowchart or Sequence. A **part** is an identified element of a Scene, such as a shape, connector, text or group. A **resolved primitive** is one painted path or text run; a part can contain many primitives. A **Scene primitive** is a unit of the pre-paint drawing contract, including document structure, shapes, text and markers. Source nodes, edges and other family-specific objects are distinct from drawing parts.
30
+ <!-- END GENERATED: diagram-terminology -->
57
31
 
58
- ## Output helpers
32
+ <!-- BEGIN GENERATED: family-narrowing -->
33
+ Narrowing selects a structured, typed family with an as* helper. It does not select one element or freeze layout coordinates.
34
+ <!-- END GENERATED: family-narrowing -->
59
35
 
60
- ### SVG
36
+ The API names stay specific to their layer:
61
37
 
62
- ```ts
63
- import { renderMermaidSVG } from 'agentic-mermaid/agent'
38
+ | API name | Meaning |
39
+ |---|---|
40
+ | `ParsedDiagram.kind`, `DiagramKind` | The source family discriminator. Other `kind` fields discriminate operations, Scene parts or resolved primitives. |
41
+ | `SceneNode`, `ShapeMark`, `ConnectorMark`, `TextMark`, `GroupMark` | Existing type names for Scene parts. A Scene node is not necessarily a source node; **mark** in these names means part. |
42
+ | `ResolvedPart.node` | The semantic Scene part paired with its backend-painted `primitives`. |
43
+ | `ResolvedPrimitive` | `ResolvedPath` or `ResolvedText`, after backend painting. |
44
+ | `ScenePrimitive`, `Geometry` | Scene primitive capability names and geometry, before backend painting. These are not `ResolvedPrimitive`. |
45
+
46
+ A **marker** decorates a path or connector at its start, end or interior
47
+ vertices, such as an arrowhead; it is distinct from the older word *mark*.
48
+ Use source-facing IDs for source objects and Scene IDs for parts. One source
49
+ object can produce several parts, and one part can produce several painted
50
+ primitives. Resolved primitives have no independent stable IDs. Entries in
51
+ `part.primitives` are associated through that part and its source-facing
52
+ identity where available. Entries in `scene.frame` have no containing part
53
+ or independent stable IDs.
54
+ The resolved-scene API's separate `marker-mid` limitation still applies.
55
+
56
+ ## Versions
57
+
58
+ <!-- BEGIN GENERATED: api-versions -->
59
+ This reference describes source version **0.5.3**. The latest release recorded in the [changelog](../CHANGELOG.md) is **0.5.3** (2026-10-29). [Read that version's reference](https://github.com/adewale/agentic-mermaid/blob/v0.5.3/docs/api.md). Changes under **Unreleased**, including new exports, are not part of that recorded release.
60
+ <!-- END GENERATED: api-versions -->
64
61
 
65
- const svg = renderMermaidSVG(`flowchart TD
66
- A --> B`, { security: 'strict' })
62
+ ```bash
63
+ npm ls agentic-mermaid
64
+ npm view agentic-mermaid version
67
65
  ```
68
66
 
69
- `renderMermaidSVG(input, options?)` accepts a Mermaid source string or any open
70
- `ParsedDiagram` envelope returned by `parseRegisteredMermaid` and returns an SVG
71
- string.
67
+ The first command shows the installed version; the second asks npm for its
68
+ current release. For released APIs, read documentation at the release's Git tag.
69
+ A source checkout and successful build do not establish publication.
70
+
71
+ ## Imports and runtimes
72
+
73
+ | Import | Use it for | Runtime |
74
+ |---|---|---|
75
+ | `agentic-mermaid` | SVG, ASCII/Unicode, resolved scenes and styles | Node, Bun, browsers and Workers; no native PNG addon imported |
76
+ | `agentic-mermaid/agent/core` | Parsing, typed editing, verification, layout, SVG and terminal rendering | Node, Bun, browsers and Workers |
77
+ | `agentic-mermaid/agent` | The agent/core operations plus native PNG | Node or Bun |
78
+ | `agentic-mermaid/browser/lazy` | `renderMermaidSVGAsync` with families loaded on demand | Browser ESM |
79
+
80
+ Use `/agent/core` for runtime-neutral editing and `/agent` when you also need
81
+ native PNG. The synchronous browser bundle is `agentic-mermaid/browser`.
82
+ Host-injected browser PNG is covered in the [advanced reference](./api-advanced.md#trusted-host-selected-graphical-backends).
83
+
84
+ ## Rendering
72
85
 
73
- ### PNG
86
+ These functions accept source text or a `ParsedDiagram` returned by
87
+ `parseRegisteredMermaid`. Parsing first is optional for artifact-only tasks.
88
+ Rendering is synchronous except for explicit async and browser PNG helpers.
89
+
90
+ ```typescript
91
+ renderMermaidSVG(input: ParsedDiagram | string, options?: RenderOptions): string
92
+ renderMermaidASCII(input: ParsedDiagram | string, options?: AsciiRenderOptions): string
93
+ renderMermaidPNG(input: ParsedDiagram | string, options?: PngOptions): Uint8Array
94
+ ```
95
+
96
+ | Function | Return value | Notes |
97
+ |---|---|---|
98
+ | `renderMermaidSVG` | One SVG document string | `idPrefix` separates resource IDs when embedding several diagrams. |
99
+ | `renderMermaidASCII` | Terminal text | Unicode by default; `{ useAscii: true }` selects seven-bit ASCII. |
100
+ | `renderMermaidPNG` | PNG bytes | Import from `/agent`. Use `scale` or `fitTo` for size. |
101
+ | `renderMermaidSVGWithReceipt` | `{ svg, receipt }` | Adds request identity and diagnostics. |
102
+ | `renderMermaidASCIIWithMeta` | `{ ascii, regions, actions, warnings, routeParity }` | Import from `/agent/core` or `/agent` for element/cell mapping. |
103
+ | `renderMermaidWithActions` | Artifact and inert action regions | Import from `/agent` for SVG, PNG, ASCII or Unicode interaction metadata. |
74
104
 
75
105
  ```ts
76
106
  import { writeFileSync } from 'node:fs'
77
107
  import { renderMermaidPNG } from 'agentic-mermaid/agent'
78
108
 
79
- const png = renderMermaidPNG(`flowchart TD
80
- A --> B`, {
81
- fitTo: { width: 1200 },
82
- background: '#fff',
109
+ const png = renderMermaidPNG('flowchart LR\n Idea --> Ship', {
110
+ fitTo: { width: 1200 }, background: '#ffffff',
83
111
  })
84
-
85
112
  writeFileSync('diagram.png', png)
86
113
  ```
87
114
 
88
- `renderMermaidPNG(input, options?)` accepts a Mermaid source string or any open
89
- `ParsedDiagram` envelope returned by `parseRegisteredMermaid` and returns
90
- `Uint8Array` PNG bytes. SVG, ASCII/Unicode, layout, native PNG, and browser PNG
91
- accept the same parsed-or-source input contract; an unregistered preserved
92
- envelope round-trips exactly and returns its stable capability diagnostic rather
93
- than falling through to Flowchart.
115
+ Use the same render options for verification and rendering. A style can affect
116
+ layout and typography as well as paint. Changing `seed` rerolls styled ink
117
+ without changing the semantic layout.
94
118
 
95
- `PngOptions` extends the shared `RenderOptions` contract used by SVG. The
96
- canonical machine-readable field set is returned by
97
- `sharedRenderOptionsJsonSchema()`; the table below contains only PNG-specific
98
- controls:
119
+ ### Graph layout selection
99
120
 
100
- | Option | Type | Default | Availability and meaning |
101
- |---|---|---:|---|
102
- | `scale` | `number` | `2` | Portable: native/browser library, CLI, and local/hosted MCP. Zoom multiplier when `fitTo` is not set. |
103
- | `background` | `string` | artifact background, then white | Portable on the same surfaces. Safe explicit PNG background color. |
104
- | `fitTo` | `{ width?: number; height?: number }` | — | Portable on the same surfaces. Constrain output to exactly one positive width or height. |
105
- | `fontDirs` | `string[]` | — | Trusted native-host input: Node/Bun library, CLI, and local MCP only. Extra font directories for unbundled families and scripts the bundled fonts do not cover. CLI: `--font-dirs <dirs>` (comma-separated). |
106
- | `loadSystemFonts` | `boolean` | `false` | Trusted native-host input on the same native surfaces. Trades cross-machine determinism for glyph coverage. CLI: `--system-fonts`. |
107
- | `onWarning` | `(w: PngFontWarning) => void` | stderr | Native library callback only. Receives `PNG_FONT_COVERAGE` warnings; callbacks never enter serializable requests or receipts. |
108
-
109
- PNG rasterization uses offline `@resvg/resvg-js` with bundled fonts for
110
- deterministic same-machine output: Inter (the default face — the same family
111
- the SVG requests and the family `src/text-metrics.ts` is calibrated for, so
112
- rasterized labels match their measured boxes), DejaVu Sans as a per-glyph
113
- fallback for symbols Inter lacks, plus the faces the built-in styles
114
- reference (Caveat, EB Garamond, Architects Daughter, Share Tech Mono — see
115
- `assets/fonts/FONT-LICENSES.md`). A style whose `font` is neither bundled
116
- nor supplied via `fontDirs` rasterizes with Inter. Characters no loaded font
117
- covers (CJK, most emoji) draw as tofu boxes and raise a `PNG_FONT_COVERAGE`
118
- warning naming the script and the escape hatches (`fontDirs` /
119
- `loadSystemFonts`).
120
- Note for third-party rasterizers: the SVG declares fonts as
121
- `font-family: var(--font, 'Face')`, and static rasterizers (resvg, librsvg)
122
- do not resolve CSS custom properties — `renderMermaidPNG` inlines the
123
- resolved family before rasterizing; do the same if you feed the raw SVG to
124
- your own pipeline.
125
-
126
- For complete custom-Style recipes using `font`, `fontDirs`, browser faces, and
127
- SVG font declarations, see [Fonts in custom styles](./custom-fonts.md).
128
-
129
- PNG output declares the shared sRGB policy with `sRGB` and `cICP` metadata,
130
- places `cICP` before image data, and deliberately emits no conflicting ICC
131
- profile. SVG and PNG consume the same resolved graphical colors before
132
- rasterization.
133
-
134
- #### Trusted host-selected graphical backends
135
-
136
- Executable backends are bound by the host, never selected by `RenderOptions` or
137
- serialized Style data. These factories apply the same canonical request,
138
- Scene-admission, SVG-security, receipt, PNG-output-policy, and color-profile
139
- contracts as their default counterparts:
121
+ Omitting `graphLayout` retains the existing automatic policy, including the
122
+ guarded forest optimization. Force ELK with `graphLayout: { backend: 'elk' }`,
123
+ or opt into the owned producer:
140
124
 
141
125
  ```ts
142
- import {
143
- createMermaidBrowserPNGRenderer,
144
- createMermaidRenderer,
145
- } from 'agentic-mermaid'
146
- import { createMermaidPNGRenderer } from 'agentic-mermaid/agent'
147
-
148
- const backendPolicy = { selectBackend: () => 'backend:acme/renderer' }
149
- const svgRenderer = createMermaidRenderer({ backendPolicy })
150
- const nodePngRenderer = createMermaidPNGRenderer({ backendPolicy })
151
- const browserPngRenderer = createMermaidBrowserPNGRenderer({
152
- backendPolicy,
153
- rasterize: async (securedSvg, context) => ({
154
- png: await rasterizeWithCanvas(securedSvg, context.outputPolicy),
155
- }),
126
+ import { renderMermaidSVGWithReceipt } from 'agentic-mermaid'
127
+
128
+ const source = 'flowchart LR; Idea --> Ship'
129
+ const { svg, receipt } = renderMermaidSVGWithReceipt(source, {
130
+ graphLayout: { backend: 'agentic', fallback: 'elk' },
156
131
  })
132
+ console.log(receipt.layoutDecisions)
157
133
  ```
158
134
 
159
- Register and conformance-check the named backend before constructing these
160
- renderers. The Node/Bun factory reuses the built-in `@resvg/resvg-js` adapter;
161
- the browser factory wraps a trusted injected rasterizer, which receives only
162
- the admitted and secured SVG plus the complete resolved portable output policy.
163
- Its rasterizer must apply `fitTo` and `background`, not only `scale`.
164
- `renderMermaidSVG`, `renderMermaidPNG`, and
165
- `renderMermaidPNGInBrowserWithReceipt` remain the compatible default-backend
166
- entry points.
167
-
168
- ### ASCII / Unicode
135
+ Agentic currently supports measured Flowchart and State graphs, including directed
136
+ cycles, self-loops, shapes and edge labels, fan-in, parallel edges, disconnected
137
+ components and long links. Independent nested scopes retain frame endpoints,
138
+ headers and local directions, including State composites and concurrent regions. State pseudostates, configured fork/join dimensions and notes
139
+ use the shared family sizing and projection rules.
140
+ The shared geometry pipeline clips ports to each actual shape outline.
141
+ Bounded cross-hierarchy leaf and frame routes retain authored endpoints, and
142
+ empty frames retain measured headers. Class cards/namespaces, ER frames and
143
+ relations, Requirement cards, and Architecture compounds use the owned kernel
144
+ with their specialized family geometry. Architecture applies final authored
145
+ side constraints and routing after placement. Unsupported hints and constraints, overlapping
146
+ node/frame identities, and exhausted bounded searches still decline explicitly. ELK support remains available for every existing
147
+ ELK family. Omitting fallback makes an unsupported Agentic request throw
148
+ `GraphLayoutUnsupportedError`; requesting `fallback: 'elk'` records the actual
149
+ selection in `layoutDecisions` and emits a fallback diagnostic. An ELK fallback
150
+ is not an Agentic completion. Unexpected engine defects and global work limits
151
+ are not hidden by fallback.
152
+
153
+ The async `agentic-mermaid/browser/lazy` entry downloads ELK only when the
154
+ selected layout actually needs it. A successful strict Agentic render does not
155
+ fetch ELK; requested fallback still loads it when native placement declines.
156
+ ELK selection likewise leaves the native solver unfetched. Backend payload
157
+ reports include the selected solver's dynamic dependencies.
158
+ The synchronous `agentic-mermaid/browser` entry remains an all-in-one bundle.
159
+
160
+ The CLI accepts `am render diagram.mmd --graph-layout agentic
161
+ --graph-layout-fallback elk`. Mermaid source configuration is preserved and is
162
+ not an alias for these options. Terminal-cell placement retains its family
163
+ rules; optional graphical companions and Architecture's pixel placement honor
164
+ the selector. See the [backend design](https://github.com/adewale/agentic-mermaid/blob/ce240587211b90395a820115d2503b73bf5ff4e3/docs/design/system/layout-backends.md) for
165
+ qualification and comparative measurement.
166
+
167
+ ## Resolved paths and text
168
+
169
+ Use this API when another renderer needs the artwork AM actually drew,
170
+ including sketch strokes, expanded markers and multiline text runs.
171
+
172
+ ```typescript
173
+ renderResolvedScene(input: ParsedDiagram | string, options?: RenderOptions): ResolvedScene
174
+ ```
169
175
 
170
176
  ```ts
171
- import { renderMermaidASCII } from 'agentic-mermaid/agent'
177
+ import { renderResolvedScene } from 'agentic-mermaid'
172
178
 
173
- const unicode = renderMermaidASCII(`flowchart LR
174
- A --> B`)
175
- const ascii = renderMermaidASCII(`flowchart LR
176
- A --> B`, { useAscii: true })
179
+ const scene = renderResolvedScene('flowchart LR\n Idea --> Ship', { style: 'hand-drawn' })
180
+ for (const part of scene.parts) {
181
+ console.log(part.id, part.node.identity, part.primitives)
182
+ }
177
183
  ```
178
184
 
179
- `renderMermaidASCII(input, options?)` accepts a Mermaid source string or any open
180
- `ParsedDiagram` envelope returned by `parseRegisteredMermaid` and returns terminal
181
- text.
182
-
183
- `AsciiRenderOptions` also extends the same shared `RenderOptions` contract.
184
- Terminal-only controls and the explicit losses involved in projecting a
185
- graphical appearance onto terminal cells are documented in
186
- [`ascii.md`](./ascii.md).
187
- `colorMode: 'html'` returns an escaped terminal projection through this same
188
- function; it is not a separate CLI output format or a `renderMermaidHTML` API.
189
-
190
- `AsciiRenderOptions`:
191
-
192
- | Option | Type | Default | Meaning |
193
- |---|---|---:|---|
194
- | `useAscii` | `boolean` | `false` | Use 7-bit ASCII instead of Unicode box drawing. |
195
- | `paddingX` | `number` | `5` | Horizontal spacing. |
196
- | `paddingY` | `number` | `5` | Vertical spacing. |
197
- | `boxBorderPadding` | `number` | `1` | Inner box padding. |
198
- | `colorMode` | `string` | `'auto'` | `'none'`, `'auto'`, `'ansi16'`, `'ansi256'`, `'truecolor'`, or `'html'`. |
199
- | `theme` | `Partial<AsciiTheme>` | — | Override ASCII colors. |
200
- | `targetWidth` | `number` | unset | Hard maximum line width in terminal display cells. Uses grapheme-safe fitting; impossible geometry throws `AsciiWidthError`. |
201
- | `maxWidth` | `number` | unset | Deprecated best-effort label wrapping. It does **not** guarantee the output width. Do not combine with `targetWidth`. |
202
- | `onProjectionDiagnostic` | `(diagnostic: TerminalProjectionDiagnostic) => void` | — | Host callback for explicit graphical-to-terminal projection losses; non-serializable and excluded from receipts. |
203
-
204
- `AsciiWidthError` has code `ASCII_TARGET_WIDTH_IMPOSSIBLE` plus
205
- `requestedWidth`, `requiredWidth`, `family`, and `reason` (`MINIMUM_GEOMETRY`,
206
- `UNBREAKABLE_GRAPHEME`, or `INVALID_WIDTH`). The same fields are returned by
207
- CLI JSON and hosted MCP errors. CLI: `am render diagram.mmd --format unicode
208
- --target-width 80`; hosted `render_ascii`: `{ source, targetWidth: 80 }`.
209
- Omitting both width options preserves the unconstrained output path.
210
-
211
- ## Shared render options
212
-
213
- SVG, PNG, ASCII, and Unicode adapters accept this serializable `RenderOptions`
214
- field set. The built-in-family column exposes family applicability; the
215
- terminal column records whether text output consumes a field, projects it with
216
- an explicit diagnostic, or declares it inapplicable. Output-specific controls
217
- remain in their respective sections.
218
-
219
- <!-- BEGIN GENERATED SHARED RENDER OPTIONS -->
220
- | Option | Type | Effective default | Meaning | Built-in families | Terminal |
221
- |---|---|---|---|---|---|
222
- | `bg` | `string` | `#FFFFFF` | Background color or CSS variable. | all | consumed |
223
- | `fg` | `string` | `#27272A` | Primary foreground and text color. | all | consumed |
224
- | `line` | `string` | derived | Connector and secondary-line color. | all | consumed |
225
- | `accent` | `string` | derived | Arrowhead, highlight, and data accent color. | all | consumed |
226
- | `muted` | `string` | derived | Secondary text and label color. | all | projected — terminal themes have no dedicated muted-text role |
227
- | `surface` | `string` | derived | Node and group surface color. | all | projected — terminal cells do not paint graphical surfaces |
228
- | `border` | `string` | derived | Node and group border color. | all | consumed |
229
- | `font` | `string` | `Inter` | CSS font family or stack. | all | projected — the host terminal owns the font face |
230
- | `style` | `StyleInput \| StyleInput[]` | `crisp` | Registered Style/Palette name, inline StyleSpec, or left-to-right stack. | all | consumed |
231
- | `padding` | `number` | `40` | Canvas padding in SVG user units. | flowchart, state, architecture | not-applicable — terminal output uses paddingX, paddingY, and boxBorderPadding |
232
- | `nodeSpacing` | `number` | `24` | Horizontal spacing between sibling nodes. | flowchart, state, class, er, architecture | not-applicable — terminal layout has a cell-grid spacing contract |
233
- | `layerSpacing` | `number` | `40` | Vertical spacing between graph layers. | flowchart, state, class, er, architecture | not-applicable — terminal layout has a cell-grid spacing contract |
234
- | `wrappingWidth` | `number` | unset | Flowchart measured-label wrapping budget in pixels. | flowchart | not-applicable — terminal output uses maxWidth or targetWidth |
235
- | `componentSpacing` | `number` | extension-defined | Spacing between disconnected graph components for compatible extension families; no built-in family currently consumes it. | none — extension-defined | not-applicable — terminal layout has a cell-grid spacing contract |
236
- | `transparent` | `boolean` | `false` | Omit the painted SVG canvas background. | all | projected — terminal output has no painted canvas background |
237
- | `interactive` | `boolean` | `false` | Enable hover tooltips for supported chart data points. | xychart, pie, quadrant | projected — terminal output is a static semantic projection |
238
- | `shadow` | `boolean` | `false` | Paint explicit drop shadows on node shapes. | flowchart, state, sequence, timeline, class, er, journey, xychart, pie, quadrant, gantt, mindmap, gitgraph | projected — elevation projects to borders and labels |
239
- | `class` | `{ hierarchicalNamespaces?: boolean }` | `hierarchicalNamespaces: true` | Class-diagram rendering controls. | class | not-applicable — this option configures graphical class layout |
240
- | `architecture` | `{ visual?: ArchitectureVisualOverrides }` | built-in metrics | Sparse architecture renderer visual metric and paint overrides. | architecture | not-applicable — this option configures graphical architecture rendering |
241
- | `timeline` | `{ maxWidth?: number }` | `maxWidth`: unset | Timeline layout controls. | timeline | not-applicable — terminal output uses maxWidth or targetWidth |
242
- | `journey` | `{ experienceCurve?: boolean }` | `experienceCurve: true` | User-journey graphical controls. | journey | not-applicable — experience curves are graphical-only |
243
- | `gantt` | `{ dependencyArrows?: boolean; criticalPath?: boolean }` | both `false` | Gantt dependency and critical-path overlays. | gantt | not-applicable — graphical Gantt connector emphasis is not represented in cells |
244
- | `mermaidConfig` | `MermaidRuntimeConfig` | source config | Mermaid-style recursive runtime configuration. | all | consumed |
245
- | `embedFontImport` | `boolean` | `false` | Embed the Google Fonts import in SVG styles; PNG forces this off for offline rasterization. | all | not-applicable — terminal output embeds no web-font import |
246
- | `compact` | `boolean` | `false` | Compact SVG serialization while preserving agent hooks. | all | not-applicable — compact controls SVG serialization |
247
- | `idPrefix` | `string` | unset | Non-empty namespace for generated SVG definition IDs and local references. | all | not-applicable — terminal output has no SVG definition ids |
248
- | `security` | `'default' \| 'strict'` | `default` | Active SVG content is rejected in every mode; strict additionally rejects every external reference. Raw Mermaid themeCSS is rejected in both modes. | all | not-applicable — terminal text has its own control-character and HTML-color safety projection |
249
- | `ganttToday` | `string` | unset | Explicit deterministic date for the Gantt today marker. | gantt | consumed |
250
- | `seed` | `number` | `0` | Deterministic re-roll seed for stochastic Styles. | all | not-applicable — terminal glyph geometry is deterministic and has no stochastic ink |
251
- <!-- END GENERATED SHARED RENDER OPTIONS -->
252
-
253
- `Built-in families: all` means the field is family-neutral. `none —
254
- extension-defined` means no built-in currently consumes it. An external
255
- `FamilyDescriptor` opts into any family-scoped field it consumes through its
256
- frozen `applicableRenderOptions` array; an omitted or empty declaration means
257
- none, and authored values receive `RENDER_OPTION_NOT_APPLICABLE` in the render
258
- receipt.
259
-
260
- `onConfigDiagnostic?: (diagnostic: ConfigDiagnostic) => void` is deliberately
261
- outside the serializable field set. Library callers can collect qualified
262
- `INEFFECTIVE_CONFIG` warnings without changing output bytes; CLI, MCP, editor,
263
- and JSON Schema surfaces return diagnostics as data instead of accepting a
264
- function.
265
-
266
- ### SVG semantic identity and accessibility
267
-
268
- All built-in families expose the same inspectable element contract:
269
-
270
- - every source-semantic Scene mark has a deterministic `data-id` and closed
271
- `data-role`; identity is unique within one SVG (layout furniture retains typed
272
- Scene identity without bloating the DOM);
273
- - source relations use `data-from` and `data-to`; source `className` tokens stay
274
- on the identified element's `class` attribute;
275
- - typed relations expose `role="graphics-symbol"`,
276
- `aria-roledescription="relation"`, and an `aria-label` derived from endpoints
277
- plus the authored relation label;
278
- - public Scene types expose `SvgSemanticIdentity`,
279
- `SvgSemanticAccessibility`, and `SvgRelationSemantics`;
280
- - `idPrefix` rewrites local DOM `id` references, not source-facing `data-id`.
281
-
282
- Built-in concrete palettes are contrast-normalized at render time: normal text
283
- roles meet WCAG AA 4.5:1 and meaningful relation lines/markers meet 3:1 against
284
- the page background. Unresolved runtime CSS variables cannot be statically
285
- certified and pass through unchanged. See
286
- [`svg-semantic-contract.md`](./svg-semantic-contract.md) for the complete contract.
287
-
288
- For JSON files, use
289
- [`docs/schemas/style-spec.schema.json`](./schemas/style-spec.schema.json). The
290
- same schema is exported from the npm package as
291
- `agentic-mermaid/style-spec.schema.json`; see
292
- [`custom-style-cookbook.md`](./custom-style-cookbook.md) for complete style
293
- files and screenshots, and [`custom-fonts.md`](./custom-fonts.md) for font
294
- resolution across output surfaces.
295
-
296
- ## Agent edit API
185
+ | `ResolvedScene` field | Meaning |
186
+ |---|---|
187
+ | `version` | `RESOLVED_SCENE_VERSION`, currently `2`. |
188
+ | `family` | Registered family ID of the input diagram: both `stateDiagram` and `stateDiagram-v2` report `state`, even though State shares Flowchart's internal Scene lowering. Extension IDs retain their `family:` namespace. |
189
+ | `width`, `height` | Final viewport dimensions in root SVG user units. |
190
+ | `svg` | Byte-identical to `renderMermaidSVG(input, options)` for the same request. |
191
+ | `colors` | Resolved diagram colors. |
192
+ | `parts` | Top-level non-document Scene parts in Scene order, each with `id`, `role`, `kind`, semantic `node` and painted resolved `primitives`. |
193
+ | `frame` | Painted leaves outside those parts, including style backdrops. |
194
+
195
+ Resolved primitives describe what the selected backend actually drew, including sketch
196
+ strokes. Shapes become local SVG path data; `matrix: [a,b,c,d,e,f]` maps local
197
+ coordinates to root user space. Paint, stroke widths, dashes and text sizes
198
+ are resolved in local units. Paint colors are lowercase six-digit hex or
199
+ `none`; color alpha is folded into fill/stroke opacity, while `opacity`
200
+ includes group opacity. Markers follow their decorated path with
201
+ `marker: true`. Multiline labels become separate text runs, retaining font,
202
+ anchor, baseline and text-length fitting.
203
+
204
+ Hidden artwork is omitted. Filters, clip paths, masks, marker-mid, paint
205
+ servers, unsupported elements and unresolved live palettes throw an error
206
+ naming the owning part (or `frame`). This API requires a family with Scene
207
+ lowering. It does not execute interactive/hover rules or fetch fonts.
208
+ `RESOLVED_SCENE_VERSION` changes for removals or semantic changes; additive
209
+ fields keep the version. See the changelog for contract changes.
210
+
211
+ `part.id` is a Scene part ID. `part.node.identity?.id` is source-facing identity
212
+ where provided; they can differ (`node:A` and `A`). Use typed endpoints and
213
+ ownership where available rather than parsing identifier spelling. Ownership
214
+ is not yet populated for every companion part.
215
+
216
+ The result is detached JSON. This function does not accept host text-measurement
217
+ profiles. Its [types](https://github.com/adewale/agentic-mermaid/blob/main/src/scene/resolved-types.ts) describe every primitive
218
+ field; the [changelog](../CHANGELOG.md) records availability. Default Sankey
219
+ gradients require a solid-color configuration under this version's paint-server
220
+ limitation.
221
+
222
+ ## Editing
223
+
224
+ For new diagrams, author source, parse, verify, then render or return it. For
225
+ existing structured diagrams, parse, select the typed family, mutate, verify,
226
+ then serialize.
297
227
 
298
228
  ```ts
299
229
  import {
300
- parseRegisteredMermaid,
301
- asFlowchart,
302
- mutate,
303
- verifyMermaid,
304
- analyzeMermaid,
305
- analyzeMermaidSource,
306
- describeMermaidFacts,
307
- checkMermaid,
308
- serializeMermaid,
309
- } from 'agentic-mermaid/agent'
230
+ parseRegisteredMermaid, asFlowchart, mutate,
231
+ verifyMermaid, serializeMermaid,
232
+ } from 'agentic-mermaid/agent/core'
233
+
234
+ const parsed = parseRegisteredMermaid('flowchart LR\n API --> DB')
235
+ if (!parsed.ok) throw new Error(parsed.error.map(error => error.message).join('\n'))
236
+ const flow = asFlowchart(parsed.value)
237
+ if (!flow) throw new Error('Expected a structured flowchart')
238
+ const changed = mutate(flow, { kind: 'add_node', id: 'Cache', label: 'Cache' })
239
+ if (!changed.ok) throw new Error(changed.error.message)
240
+ const verified = verifyMermaid(changed.value)
241
+ if (!verified.ok) throw new Error(JSON.stringify(verified.warnings))
242
+ console.log(serializeMermaid(changed.value))
310
243
  ```
311
244
 
312
- Core functions:
245
+ The family narrower `asFlowchart` returns the structured flowchart or `null`.
246
+ As defined in the [vocabulary](#vocabulary), narrowing selects the typed family;
247
+ a structural edit can recompute layout.
248
+
249
+ ```typescript
250
+ parseRegisteredMermaid(source: string): Result<ParsedDiagram, ParseError[]>
251
+ mutate(diagram: ParsedDiagram, operation: AnyMutationOp): Result<ParsedDiagram, MutationError>
252
+ verifyMermaid(input: ParsedDiagram | string, options?: VerifyOptions): VerifyResult
253
+ serializeMermaid(diagram: ParsedDiagram, options?: SerializeOptions): string
254
+ ```
313
255
 
314
- | Function | Purpose |
256
+ | Function | Result and use |
315
257
  |---|---|
316
- | `parseRegisteredMermaid(source)` | Parse Mermaid source to `Result<ValidDiagram, ParseError[]>`. |
317
- | Family narrower | Narrow to a mutable family or return `null`; obtain the current generated name from `am capabilities --json`. |
318
- | `mutate(d, op)` | Apply a kind-discriminated typed mutation. |
319
- | `verifyMermaid(d)` | Return structural warnings and layout evidence. |
320
- | `analyzeMermaid(d)` / `analyzeMermaidSource(source)` | Return deterministic non-rendering analysis: feedback edges, source-only action records, and Gantt critical-path/slack summary when available. |
321
- | `describeMermaidFacts(d)` / `checkMermaid(d, spec)` | Return deterministic semantic fact lines, or check required/forbidden facts such as `edge Processing -> [*] : done`, `member Duck +quack()`, `task Docs start after core`. |
322
- | `serializeMermaid(d)` | Emit source only after verifying. |
323
- | `layoutMermaid(d)` | Return layout JSON for quality/inspection; `layoutMermaid(d, { debug: true })` includes graph route certificates, family edge-route certificates (class/ER/architecture/sequence), region-containment certificates (timeline/charts), and semantic region/action sidecars (`cluster`, `lane`, `band`, `compartment`, `plot`, `ring`). Edge certificates include exact ports plus side/slot/role port assignments where applicable. |
324
- | `renderMermaidWithActions(d, request)` | Render SVG, PNG, ASCII, or Unicode and return one inert action/hit-region sidecar for admitted Flowchart/Class/Gantt interactions and Sequence actor-menu links. An SVG href is `embedded-inert` only when matching inert metadata is present in the returned SVG; PNG/terminal actions, strict-mode hrefs, and all callbacks are `sidecar-only` and never execute. Terminal artifacts also return projection `warnings`, and terminal render failure throws instead of returning an empty success artifact. |
325
- | `measureQuality(layout, colors?)` / `checkQuality(layout, bounds?, colors?)` | Perceptual quality metrics, including fail-closed contrast (`null` when requested paints are unresolved), nearest-node spacing, and element density. Rendered audits can supply exact foreground/background associations through `textPairs`. |
326
- | `describeMermaid(d, { format })` | Prose, AX-tree, or facts summary (`format: "text" | "json" | "facts"`). |
327
-
328
- The family registry is the operation authority. Use `am capabilities --json`
329
- for the current roster and field schemas, or call `describeOps(family)` and
330
- `opSignatures(family)` at runtime. The generated SDK declaration projects the
331
- same descriptors; this reference deliberately does not copy an exhaustive
332
- family/operation table.
333
-
334
- Opaque fallback bodies (any unmodeled syntax) are source-level-only: edit source deliberately, then parse and verify again.
335
-
336
- ## Capability and extension discovery
337
-
338
- Repository audit tooling can import `createSectionACapabilityReport()` from
339
- `src/section-a-capability-report.ts`. It returns the JSON-safe, registry-derived
340
- request/backend/output/family/Scene matrix. `am capabilities --json` →
341
- `sectionA` intentionally exposes only its version, pin, digest, counts,
342
- no-absent status, and directions to this full report. Validate a stored snapshot with
343
- `validateSectionACapabilityReport(report)`. The generated human projection is
344
- [`project/section-a-capability-report.md`](./project/section-a-capability-report.md).
345
- Keeping this audit surface out of the package prevents the full characterization
346
- and upstream syntax corpora from entering renderer/browser bundles.
347
-
348
- Canonical extension identities are kind-qualified (`look:`, `palette:`,
349
- `backend:`, `family:`, `role:`, and `resource:`), versioned, provenance-bearing,
350
- and collision-safe. New graphical backends declare feature/operation-level
351
- Scene primitive capability claims; the registry rejects an empty, duplicate,
352
- cross-target, or otherwise invalid claim set. Every external backend, and every
353
- external family that supplies `lowerScene`, must also declare an explicit
354
- compatible `identity.compatibility.scene` range (Scene v2: `^2.0.0`). The host
355
- checks that range before running backend conformance or other executable
356
- witnesses; only the internal built-in enrollment path receives compatibility
357
- defaults.
358
-
359
- ### Current customization and extension inventory
360
-
361
- This is the current authoritative inventory. Field-level `RenderOptions` and
362
- `StyleSpec` details remain in their generated tables above rather than being
363
- copied here.
364
-
365
- | Level | Public seam | What it can change | Boundary and availability |
258
+ | `parseRegisteredMermaid` | `{ ok: true, value }` or `{ ok: false, error: ParseError[] }`. Preserving unsupported source does not grant typed edit support. |
259
+ | Family narrower, such as `asFlowchart` | The typed family value or `null`. Discover names with `am capabilities --json`. |
260
+ | `describeOps(family)`, `opSignatures(family)` | Exact mutation fields or a compact menu. Look up unfamiliar operations instead of guessing. |
261
+ | `mutate` | A changed diagram or structured mutation error. The operation's `kind` selects its fields. |
262
+ | `verifyMermaid` | `ok`, `warnings`, layout and check evidence. Inspect severity and verification scope. |
263
+ | `serializeMermaid` | Mermaid source. **Does not run verification.** The caller must inspect verification before saving, sending or showing an edit. |
264
+ | `describeMermaidFacts`, `checkMermaid` | Semantic read-back and required/forbidden-fact checks for task-critical meaning. |
265
+ | `analyzeMermaid` | Non-rendering feedback-edge, action and available Gantt scheduling analysis. |
266
+ | `layoutMermaid`, `layoutMermaidWithReceipt` | Positioned boxes, routes, labels and optional regions. The latter accepts source too and includes a receipt. This is layout geometry, not backend-painted artwork. |
267
+ | `buildMermaid`, `createMermaid` | Programmatic authoring from typed operations; ordinary new diagrams can start directly as source. |
268
+
269
+ Opaque bodies preserve source but have no structured mutation. Report the
270
+ unsupported operation, or deliberately edit source and re-parse when requested.
271
+ See the [agent cookbook](./agent-api-cookbook.md) for batch edits and rollback.
272
+
273
+ ## Render options
274
+
275
+ SVG, PNG, terminal text, layout and resolved scenes share `RenderOptions`;
276
+ applicability depends on output and family. See [style authoring](./style-authoring.md)
277
+ for precedence and custom looks. This table is generated from runtime descriptors:
278
+
279
+ <!-- BEGIN GENERATED: render-options -->
280
+ | Option | Type | Default | Meaning and applicability |
366
281
  |---|---|---|---|
367
- | Mermaid-authored appearance | frontmatter/init config, theme variables, family style statements such as classes and link styles | Syntax-defined colors, labels, family geometry, and interaction metadata where the family advertises support | Source-level and family-dependent. Raw `themeCSS` is recognized but diagnosed at the render boundary because its selectors and markup can escape an imported SVG; use `StyleSpec` instead. |
368
- | One-off render overrides | `RenderOptions` | Palette channels, font family, spacing/geometry controls, deterministic seed, security, accessibility-related output options, and a Style stack | The generated field×surface matrix marks each serializable shared field `forwarded`, `host-enforced`, or `unavailable`. Hosted SVG and editor SVG enforce strict security with external font imports disabled; effective receipts reflect those constraints. Host callbacks are library-only and never enter receipts. |
369
- | One-off declarative style | inline `StyleSpec` or a left-to-right `StyleInput[]` stack | Safe palette, font, stroke/fill treatment, backdrop, exact semantic-role defaults, named semantic slots, V1 `category` bindings, non-color cues, and inspect-only contrast/accent-area/mono-role constraints | JSON-safe and executable-code-free. Bindings supply defaults beneath authored family paint and semantics; constraints diagnose final effective paint without repainting or relayout. This is the lowest-complexity custom Style path. |
370
- | Named Palette/Look | `registerStyle`, `getStyle`, `knownStyleDescriptors` | Installs a versioned `palette:` or `look:` name backed by exactly the same `StyleSpec` accepted inline | Descriptors expose one `kind` (`look` or `palette`), explicit `isDefault`, and one stable `inputName`. In-process host registry. A CLI/MCP/server sees a registration only when that host installs it at startup. |
371
- | Theme conversion | `fromShikiTheme` | Converts a Shiki-compatible editor theme into diagram colors | Pure library helper; the result is ordinary declarative color input. |
372
- | Live host retheming | CSS custom-property values in graphical color/font inputs | Lets a host page switch SVG palette and font values without re-rendering | SVG/browser-only and limited to safe property values; this is not a raw CSS rule or selector hook. Static outputs need values resolved under their rasterization environment to remain reproducible. |
373
- | Terminal output projection | `AsciiRenderOptions` (`useAscii`, `paddingX`, `paddingY`, `boxBorderPadding`, `colorMode`, `theme`, `targetWidth`/`maxWidth`, `onProjectionDiagnostic`) | Selects Unicode/ASCII encoding, cell spacing, width policy, ANSI/HTML colors, terminal-only theme overrides, and projection-loss reporting | Output-adapter customization, not a second shared Style system. Serializable fields have transport-specific availability; the diagnostic callback is host-only and remains outside receipts. |
374
- | Fonts and installed resources | `font`, Node PNG `fontDirs`/`loadSystemFonts`/`onWarning`, browser `BrowserPngRasterizer`, `ResourceManifest`, and repository host tooling via `NodeResourceResolver` | Selects a safe font stack, supplies host-dependent raster fonts, reports missing glyph coverage, or verifies bounded installed bytes | Font family names do not install fonts. Browser and warning callbacks remain outside serializable options and every digest. Node `fontDirs`/`loadSystemFonts` are trusted host inputs outside shared `RenderOptions` and the shared/appearance digests, but their resolved PNG output policy is included in the output-specific request digest; runtime provenance still marks host-dependent resources explicitly. Manifests require path, size, media-type, digest, and licence evidence and never fall back to network access. |
375
- | Graphical backend | `registerBackend`, `runBackendConformance`, `createMermaidRenderer`, `createMermaidPNGRenderer`, `createMermaidBrowserPNGRenderer` (each with a host-only `backendPolicy`) | Serializes the typed Scene contract with a different drawing implementation for SVG, native Node/Bun PNG, and injected-rasterizer browser PNG | Trusted in-process host only. Host registrations must explicitly declare compatible core and Scene ranges; identity/compatibility admission precedes executable conformance. Registration then must pass bounded, deterministic, semantic, well-formed, secure SVG conformance plus an exact witness for every first-party core primitive/feature/operation claim; namespaced extension claims without a core witness remain explicitly unverified. All listed factories use the same admitted and secured graphical request; PNG adapters do not reparse or rerender source. Serializable styles and `RenderOptions` cannot select arbitrary executable backends. |
376
- | Diagram family | `registerFamily`, `getFamilyConformanceReport`, `parseRegisteredMermaid`, `projectPositionedView` | Adds a namespaced language with detection, parse/preservation, verification, layout, Scene/SVG, terminal, and discovery claims | Every versioned `family:<owner/name>` descriptor declares a compatible core range and supplies one bounded canonical `example`. It also lists consumed family-scoped shared fields in `applicableRenderOptions`; omission means none, unknown or duplicate fields fail registration, and the frozen declaration appears in the capability report. Registration stages the frozen candidate, runs native claims twice through canonical parse/serialize, non-empty positive-bounds layout, strict SVG, portable PNG pre-raster, terminal, Scene and verify paths, and rolls back on failure, reentrancy or nondeterminism. Discovery reports `native` only beside a passed per-capability witness. Native tuples still require layout + `projectPositioned`, Scene requires layout + `lowerScene`, and extension verification requires its hook plus executable SVG. An external Scene family additionally declares a compatible Scene range, and its example witnesses every positive role/primitive cell. Built-in-only unions stay closed; extension bodies use the open envelope. Remote transports gain the family only when their trusted host installs it. |
377
- | Scene semantics | `SceneDoc`, typed connectors/markers/hit geometry, namespaced `SceneRole` | Lets a family/backend exchange identity, relationship, accessibility, geometry, and terminal-projection intent | This is a versioned typed contract, not a raw SVG hook. Unknown namespaced roles deliberately receive inert identity-only traits and cannot acquire core behavior by local-name collision. There is no public arbitrary primitive/trait mutation registry. |
378
- | Browser PNG host adapter | `renderMermaidPNGInBrowserWithReceipt(..., rasterize)` or reusable `createMermaidBrowserPNGRenderer({ rasterize, backendPolicy? })` | Supplies Canvas/OffscreenCanvas rasterization and reports font provenance | Trusted callback receives only the admitted, secured canonical SVG; the library re-applies the PNG color-profile gate and retains the same logical receipt as the native PNG path. |
379
- | Identity plumbing | `canonicalExtensionId`, `parseExtensionId`, `createExtensionIdentity`, `registerExtension`, `ExtensionCollisionError` | Gives kind-specific registries stable names, parsing, versions, provenance, compatibility ranges, and collision rejection | Low-level plumbing, not a stand-alone extension registry or rendering hook. Stable short inputs belong to kind-specific descriptors. |
380
-
381
- There is currently no BrandPack registry, public role-trait registration,
382
- arbitrary SVG/CSS hook, or Treatment hook. Semantic slots and the closed V1
383
- `category` binding API are ordinary `StyleSpec` fields; other Scene channels are
384
- not publicly bindable without new executable family witnesses. B4 remains the
385
- unpromoted, evidence-gated BrandPack distribution envelope only. A future
386
- Treatment seam is a separate decision and is not implied by B4.
387
-
388
- ## CLI
282
+ | `layoutHints` | `{ ranks?: Record<string, number>; adjacent?: string[][]; shortEdges?: string[] }` | unset | Relative ranks, sibling adjacency and short-edge preferences. Built-in families: flowchart, state. Not consumed by terminal output. |
283
+ | `graphLayout` | `{ backend: 'elk' \| 'agentic'; fallback?: 'none' \| 'elk' }` | `elk`, no fallback | Graph geometry producer and explicit Agentic fallback policy. Built-in families: flowchart, state, architecture, class, er, requirement. |
284
+ | `layoutSafety` | `'report' \| 'strict'` | `report` | Report bounded layout evidence, or require a passed final certificate. Strict mode rejects missing or unverified evidence. |
285
+ | `bg` | `string` | `#FFFFFF` | Background color or CSS variable. |
286
+ | `fg` | `string` | `#27272A` | Primary foreground and text color. |
287
+ | `line` | `string` | derived | Connector and secondary-line color. |
288
+ | `accent` | `string` | derived | Arrowhead, highlight, and data accent color. |
289
+ | `muted` | `string` | derived | Secondary text and label color. |
290
+ | `surface` | `string` | derived | Node and group surface color. |
291
+ | `border` | `string` | derived | Node and group border color. |
292
+ | `font` | `string` | `Inter` | CSS font family or stack. |
293
+ | `style` | `StyleInput \| StyleInput[]` | `crisp` | Registered Style/Palette name, inline StyleSpec, or left-to-right stack. |
294
+ | `padding` | `number` | `40` | Canvas padding in SVG user units. Built-in families: flowchart, state, architecture, c4. Not consumed by terminal output. |
295
+ | `nodeSpacing` | `number` | `24` | Horizontal spacing between sibling nodes. Built-in families: flowchart, state, class, er, architecture, c4. Not consumed by terminal output. |
296
+ | `layerSpacing` | `number` | `40` | Vertical spacing between graph layers. Built-in families: flowchart, state, class, er, architecture, c4. Not consumed by terminal output. |
297
+ | `wrappingWidth` | `number` | unset | Flowchart measured-label wrapping budget in pixels. Built-in families: flowchart. Not consumed by terminal output. |
298
+ | `componentSpacing` | `number` | extension-defined | Spacing between disconnected graph components for compatible extension families; no built-in family currently consumes it. Built-in families: none; extension-defined. Not consumed by terminal output. |
299
+ | `transparent` | `boolean` | `false` | Omit the painted SVG canvas background. |
300
+ | `interactive` | `boolean` | `false` | Enable hover tooltips for supported chart data points. Built-in families: xychart, pie, quadrant. |
301
+ | `shadow` | `boolean` | `false` | Paint explicit drop shadows on node shapes. Built-in families: flowchart, state, sequence, timeline, class, er, journey, xychart, pie, quadrant, gantt, mindmap, gitgraph, sankey. |
302
+ | `class` | `{ hierarchicalNamespaces?: boolean }` | `hierarchicalNamespaces: true` | Class-diagram rendering controls. Built-in families: class. Not consumed by terminal output. |
303
+ | `kanban` | `{ maxWidth?: number }` | `maxWidth`: unset | Opt-in Kanban column wrapping with readable column widths. Built-in families: kanban. Not consumed by terminal output. |
304
+ | `pie` | `{ maxWidth?: number }` | `maxWidth`: unset | Opt-in Pie title and legend fitting without shrinking typography. Built-in families: pie. Not consumed by terminal output. |
305
+ | `radar` | `{ maxWidth?: number }` | `maxWidth`: unset | Opt-in Radar plot and legend fitting without shrinking typography. Built-in families: radar. Not consumed by terminal output. |
306
+ | `architecture` | `{ visual?: ArchitectureVisualOverrides }` | built-in metrics | Sparse architecture renderer visual metric and paint overrides. Built-in families: architecture. Not consumed by terminal output. |
307
+ | `timeline` | `{ maxWidth?: number }` | `maxWidth`: unset | Timeline layout controls. Built-in families: timeline. Not consumed by terminal output. |
308
+ | `journey` | `{ experienceCurve?: boolean }` | `experienceCurve: true` | User-journey graphical controls. Built-in families: journey. Not consumed by terminal output. |
309
+ | `gantt` | `{ dependencyArrows?: boolean; criticalPath?: boolean }` | both `false` | Gantt dependency and critical-path overlays. Built-in families: gantt. Not consumed by terminal output. |
310
+ | `mermaidConfig` | `MermaidRuntimeConfig` | source config | Mermaid-style recursive runtime configuration. |
311
+ | `embedFontImport` | `boolean` | `false` | Embed the Google Fonts import in SVG styles; PNG forces this off for offline rasterization. Not consumed by terminal output. |
312
+ | `compact` | `boolean` | `false` | Compact SVG serialization while preserving agent hooks. Not consumed by terminal output. |
313
+ | `idPrefix` | `string` | unset | Non-empty namespace for generated SVG definition IDs and local references. Not consumed by terminal output. |
314
+ | `security` | `'default' \| 'strict'` | `default` | Active SVG content is rejected in every mode; strict additionally rejects every external reference. Raw Mermaid themeCSS is rejected in both modes. Not consumed by terminal output. |
315
+ | `ganttToday` | `string` | unset | Explicit deterministic date for the Gantt today marker. Built-in families: gantt. |
316
+ | `seed` | `number` | `0` | Deterministic re-roll seed for stochastic Styles. Not consumed by terminal output. |
317
+ <!-- END GENERATED: render-options -->
318
+
319
+ Inapplicable family-scoped fields produce `RENDER_OPTION_NOT_APPLICABLE` in a
320
+ receipt. `onConfigDiagnostic` is a library callback outside serializable options.
321
+ For untrusted JSON, use `validateSerializableRenderOptions` or the
322
+ [render-options JSON Schema](https://agentic-mermaid.dev/schemas/render-options.schema.json).
323
+ Terminal-only controls are in the [ASCII reference](./ascii.md).
324
+
325
+ ### PNG options
389
326
 
390
- ```bash
391
- am render diagram.mmd --format svg > diagram.svg
392
- am render diagram.mmd --format png --output diagram.png --fit-width 1200 --bg '#fff'
393
- am render diagram.mmd --format ascii > diagram.txt
394
- am render diagram.mmd --format layout --certificates > layout-with-routes.json
395
- am verify diagram.mmd
396
- am describe diagram.mmd --format facts
397
- am mutate diagram.mmd --op '{"kind":"add_node","id":"Cache","label":"Cache"}' --json
398
- am capabilities --json
399
- am init-agent --dir . --json
400
- ```
327
+ | Option | Type | Default | Availability and meaning |
328
+ |---|---|---:|---|
329
+ | `scale` | `number` | `2` | Portable: native/browser library, CLI, and local/hosted MCP. Zoom multiplier when `fitTo` is not set. |
330
+ | `background` | `string` | artifact background, then white | Portable on the same surfaces. Safe explicit PNG background color. |
331
+ | `fitTo` | `{ width?: number; height?: number }` | — | Portable on the same surfaces. Constrain output to exactly one positive width or height. |
332
+ | `minLabelPx` | `number` | `9` | Portable on the same surfaces. Warn with `BELOW_READABLE_SIZE` when rasterization puts the smallest measurable label below this effective-pixel floor; `0` disables the gate. The default is provisional product policy for general-purpose screen diagrams, not a universal readability or accessibility threshold. |
333
+ | `fontDirs` | `string[]` | — | Trusted native-host input: Node/Bun library, CLI, and local MCP only. Extra font directories for unbundled families and scripts the bundled fonts do not cover. CLI: `--font-dirs <dirs>` (comma-separated). |
334
+ | `loadSystemFonts` | `boolean` | `false` | Trusted native-host input on the same native surfaces. Trades cross-machine determinism for glyph coverage. CLI: `--system-fonts`. |
335
+ | `onWarning` | `(w: PngRasterWarning) => void` | stderr | Native library callback only. Receives `PNG_FONT_COVERAGE` and `BELOW_READABLE_SIZE` warnings; callbacks never enter serializable requests or receipts. |
401
336
 
402
- PNG is single-input and requires `--output` so binary bytes are never accidentally printed to a terminal. Portable controls are `--scale`, `--bg`, and the mutually exclusive `--fit-width`/`--fit-height`; native-host font controls are `--font-dirs` and `--system-fonts`. `am init-agent` writes a non-clobbering agent-agnostic onboarding bundle (`AGENTS.md`, root `skills/`, and `.mcp.json`) into a consumer repo.
337
+ SVG font declarations do not load fonts. See [custom fonts](./custom-fonts.md)
338
+ and [rasterization details](./api-advanced.md#png-fonts-portability-and-rasterization).
403
339
 
404
- ## MCP
340
+ ## Errors and recovery
405
341
 
406
- The published package exposes Node-runnable bins: `am`, the package-runner
407
- alias `agentic-mermaid`, and `agentic-mermaid-mcp`.
342
+ | Operation | Failure shape | Recovery |
343
+ |---|---|---|
344
+ | Parse | `{ ok: false, error: ParseError[] }` | Inspect every error's message and available source position. |
345
+ | Mutate | `{ ok: false, error }` | Use the code/message and operation schema; preserve the previous value. |
346
+ | Verify | `ok: false` with structured warnings | Inspect code, severity, origin and available evidence. |
347
+ | Render | Throws | Catch at the artifact boundary. Family/capability failures have exported error types; other failures can be ordinary `Error`. |
348
+ | Resolve artwork | Throws, naming the part and unsupported feature | Report the unsupported artwork or choose a supported representation. These errors currently have no dedicated stable code. |
408
349
 
409
- Local `agentic-mermaid-mcp` is Code Mode-first and exposes:
350
+ ```ts
351
+ import { parseRegisteredMermaid } from 'agentic-mermaid/agent/core'
352
+
353
+ const result = parseRegisteredMermaid('flowchart LR\n Idea --> Ship')
354
+ if (result.ok) {
355
+ console.log(result.value.kind)
356
+ } else {
357
+ console.error(result.error.map(error => error.message).join('\n'))
358
+ }
359
+ ```
410
360
 
411
- - `execute(code)` — primary Code Mode tool with global `mermaid.*` SDK.
412
- - `describe_sdk({ family, detail })` — version-matched compact signatures or exact mutation fields for one family.
413
- - `render_png` — narrow helper returning base64 PNG bytes, or managed file/URL artifacts via `output: "file"|"url"`; accepts portable `scale`/`background`/`fitTo`, plus local-only `fontDirs`/`loadSystemFonts`, and returns configuration/font-coverage warnings with every output mode.
414
- - `describe` — narrow summary helper; pass `format: "facts"` for deterministic semantic fact lines.
361
+ `verify.ok` means no unsuppressed error was detected by the checks performed.
362
+ It does not establish visual perfection, complete semantic correctness or
363
+ portable, lossless canonical export. Check task-specific facts and review the
364
+ artifact when appearance matters. See [verification scope](./agent-mutation-policy.md).
415
365
 
416
- Use Code Mode for multi-step parse/narrow/mutate/verify/serialize loops. Use `render_png` or host/library code for binary PNG output. The default transport is stdio; `agentic-mermaid-mcp --transport http --host 127.0.0.1 --port 3000` starts the HTTP/SSE transport. HTTP mode serves managed artifacts from `/artifacts/<name>` with MIME type, byte count, and SHA-256 metadata in tool responses. Non-loopback HTTP binding requires `--auth-token`; that bearer token protects `/rpc`, `/sse`, `/message`, and `/artifacts/*`.
366
+ ## Advanced use
417
367
 
418
- A hosted Streamable HTTP endpoint also runs at `https://agentic-mermaid.dev/mcp`. It is MCP JSON-RPC only (not REST), stateless, public/unauthenticated, and capped at 64 KB inputs. Hosted tools are `execute`, `describe_sdk`, `render_svg`, `render_ascii`, `render_png`, `verify`, `describe`, `mutate`, and `build`; `describe_sdk` returns compact signatures or exact mutation fields for one family, hosted `execute` uses a Cloudflare Dynamic Worker isolate with no network, and hosted `render_png` returns base64 only while retaining portable `scale`/`background`/`fitTo`. Prefer local CLI/library/MCP for sensitive diagrams, offline work, larger inputs, native font controls, or file/URL PNG artifacts. See [`mcp-http-transport.md`](./mcp-http-transport.md) for JSON-RPC examples and option details.
368
+ Use the [advanced reference](./api-advanced.md) for receipts, host-selected
369
+ backends, custom text metrics, parser observation, detailed source-preservation
370
+ examples and extension contracts. Use the [CLI](https://agentic-mermaid.dev/docs/cli/),
371
+ [MCP](./mcp-http-transport.md) or [agent cookbook](./agent-api-cookbook.md) for those
372
+ channels. You do not need those protocols to render or edit with the library.