agentic-mermaid 0.1.0 → 0.1.2

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 (333) hide show
  1. package/CHANGELOG.md +149 -4
  2. package/LICENSES/Apache-2.0.txt +202 -0
  3. package/README.md +25 -32
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/assets/fonts/FONT-LICENSES.md +9 -5
  6. package/assets/fonts/Inter-Bold.ttf +0 -0
  7. package/assets/fonts/Inter-Medium.ttf +0 -0
  8. package/assets/fonts/Inter-Regular.ttf +0 -0
  9. package/assets/fonts/Inter-SemiBold.ttf +0 -0
  10. package/dist/agent-core.d.ts +463 -0
  11. package/dist/agent-core.js +397 -0
  12. package/dist/agent.d.ts +81 -1822
  13. package/dist/agent.js +336 -36839
  14. package/dist/agentic-mermaid-mcp.js +7 -37908
  15. package/dist/am.js +33638 -36261
  16. package/dist/chunk-4QECACIA.js +4702 -0
  17. package/dist/chunk-CDPKJ2BQ.js +37 -0
  18. package/dist/chunk-QKDLMOJJ.js +3487 -0
  19. package/dist/chunk-WI35L7IR.js +615 -0
  20. package/dist/chunk-WN3YDOBG.js +149 -0
  21. package/dist/chunk-ZYMMKQ3I.js +62637 -0
  22. package/dist/index-D54dqSdC.d.ts +6777 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +310 -32836
  25. package/dist/mcp-cli-SBQSTJFC.js +17 -0
  26. package/docs/README.md +14 -6
  27. package/docs/schemas/style-spec.schema.json +1221 -30
  28. package/examples/styles/catalog.json +54 -0
  29. package/examples/styles/cloudflare-workers-inspired-prototype.mmd +9 -0
  30. package/examples/styles/cloudflare-workers-inspired-prototype.style.json +110 -0
  31. package/examples/styles/cupertino-prototype.mmd +10 -0
  32. package/examples/styles/cupertino-prototype.style.json +63 -0
  33. package/examples/styles/mid-century-report.style.json +2 -2
  34. package/examples/styles/star-chart-atlas.style.json +2 -1
  35. package/examples/styles/transit-route-map.style.json +2 -2
  36. package/examples/styles/vercel-inspired-prototype.mmd +6 -0
  37. package/examples/styles/vercel-inspired-prototype.style.json +87 -0
  38. package/package.json +70 -43
  39. package/server.json +41 -0
  40. package/skills/agentic-mermaid-diagram-workflow/SKILL.md +17 -36
  41. package/skills/agentic-mermaid-diagram-workflow/references/cli.md +4 -5
  42. package/skills/agentic-mermaid-diagram-workflow/references/code-mode.md +15 -31
  43. package/skills/agentic-mermaid-diagram-workflow/references/sequence.md +10 -14
  44. package/skills/agentic-mermaid-live-editor/SKILL.md +100 -206
  45. package/AGENT_NATIVE.md +0 -602
  46. package/Instructions_for_agents.md +0 -83
  47. package/TODO.md +0 -662
  48. package/assets/hero.png +0 -0
  49. package/dist/index-x2Cj1dVv.d.ts +0 -1089
  50. package/docs/agent-api-cookbook.md +0 -308
  51. package/docs/agent-mutation-policy.md +0 -104
  52. package/docs/agent-workflow-examples.md +0 -46
  53. package/docs/api.md +0 -203
  54. package/docs/ascii.md +0 -103
  55. package/docs/assets/improvements/box-start-connector.png +0 -0
  56. package/docs/assets/improvements/comment-dropped-lint.png +0 -0
  57. package/docs/assets/improvements/er-content-loss.png +0 -0
  58. package/docs/assets/improvements/fan-in-trunks.png +0 -0
  59. package/docs/assets/improvements/gantt-family.png +0 -0
  60. package/docs/assets/improvements/gantt-milestone-clamp.png +0 -0
  61. package/docs/assets/improvements/gantt-verify-seam.png +0 -0
  62. package/docs/assets/improvements/subgraph-container-edges.png +0 -0
  63. package/docs/assets/improvements/wrapper-frontmatter.png +0 -0
  64. package/docs/assets/improvements/wrapper-init-directive.png +0 -0
  65. package/docs/assets/improvements/wrapper-leading-comment.png +0 -0
  66. package/docs/assets/style-cookbook/mid-century-report.png +0 -0
  67. package/docs/assets/style-cookbook/star-chart-atlas.png +0 -0
  68. package/docs/assets/style-cookbook/transit-route-map.png +0 -0
  69. package/docs/comparison.md +0 -94
  70. package/docs/config.md +0 -105
  71. package/docs/contributing/adding-diagram-types.md +0 -144
  72. package/docs/contributing/diagram-family-citizenship.matrix.json +0 -2127
  73. package/docs/contributing/diagram-family-citizenship.md +0 -82
  74. package/docs/contributing/harvesting-upstream-tests.md +0 -126
  75. package/docs/contributing/lessons-learned.md +0 -276
  76. package/docs/contributing/releasing.md +0 -71
  77. package/docs/contributing/visual-review-evidence.md +0 -53
  78. package/docs/custom-style-cookbook.md +0 -154
  79. package/docs/design/families/README.md +0 -26
  80. package/docs/design/families/architecture-beta.md +0 -48
  81. package/docs/design/families/flowchart-parser-conformance.md +0 -22
  82. package/docs/design/families/gantt-research.md +0 -137
  83. package/docs/design/families/gantt.md +0 -329
  84. package/docs/design/families/journey-agentic-cards-before.png +0 -0
  85. package/docs/design/families/journey-mermaid-classic-implementation.png +0 -0
  86. package/docs/design/families/journey-mermaid-classic-prototype.png +0 -0
  87. package/docs/design/families/journey-mermaid-classic-prototype.svg +0 -163
  88. package/docs/design/families/journey-mermaid-classic-prototype.svg.png +0 -0
  89. package/docs/design/families/journey-migration-parity.md +0 -433
  90. package/docs/design/families/journey-usage-research.md +0 -423
  91. package/docs/design/families/journey.md +0 -125
  92. package/docs/design/families/xychart.md +0 -85
  93. package/docs/design/system/README.md +0 -45
  94. package/docs/design/system/abstraction-audit.md +0 -224
  95. package/docs/design/system/abstraction-recommendations.md +0 -655
  96. package/docs/design/system/architecture.mmd +0 -29
  97. package/docs/design/system/architecture.svg +0 -137
  98. package/docs/design/system/layout-guarantees-and-robustness.md +0 -351
  99. package/docs/design/system/layout-rubric.md +0 -138
  100. package/docs/design/system/route-contracts.md +0 -848
  101. package/docs/design/system/source-preservation-ladder.md +0 -52
  102. package/docs/design/system/styles-rollout.md +0 -216
  103. package/docs/design/system/ugly-layouts.md +0 -119
  104. package/docs/diagram-families.md +0 -193
  105. package/docs/features.md +0 -147
  106. package/docs/fork-differences.md +0 -130
  107. package/docs/getting-started.md +0 -175
  108. package/docs/issue-derived-test-cases.md +0 -156
  109. package/docs/layout-characterization/README.md +0 -245
  110. package/docs/layout-characterization/contact-sheet-families.md +0 -496
  111. package/docs/layout-characterization/contact-sheet.md +0 -638
  112. package/docs/layout-characterization/properties.md +0 -281
  113. package/docs/layout-characterization/visual-quality.md +0 -160
  114. package/docs/layout-characterization/visual-snapshots/architecture.svg +0 -79
  115. package/docs/layout-characterization/visual-snapshots/class.svg +0 -60
  116. package/docs/layout-characterization/visual-snapshots/er.svg +0 -61
  117. package/docs/layout-characterization/visual-snapshots/flowchart.svg +0 -58
  118. package/docs/layout-characterization/visual-snapshots/gantt.svg +0 -52
  119. package/docs/layout-characterization/visual-snapshots/journey.svg +0 -118
  120. package/docs/layout-characterization/visual-snapshots/pie.svg +0 -36
  121. package/docs/layout-characterization/visual-snapshots/quadrant.svg +0 -47
  122. package/docs/layout-characterization/visual-snapshots/sequence.svg +0 -59
  123. package/docs/layout-characterization/visual-snapshots/state.svg +0 -52
  124. package/docs/layout-characterization/visual-snapshots/timeline.svg +0 -64
  125. package/docs/layout-characterization/visual-snapshots/xychart.svg +0 -97
  126. package/docs/mcp-code-mode-rationale.md +0 -101
  127. package/docs/mcp-http-transport.md +0 -223
  128. package/docs/mermaid-layout-complaints.md +0 -837
  129. package/docs/mutation-testing.md +0 -206
  130. package/docs/project/divergences.md +0 -98
  131. package/docs/project/dogfooding-docs-strategy.md +0 -66
  132. package/docs/project/hosted-mcp-cloudflare-plan.md +0 -338
  133. package/docs/project/lessons-learned.md +0 -1019
  134. package/docs/project/remove-role-styling-plan.md +0 -176
  135. package/docs/quality.md +0 -212
  136. package/docs/react.md +0 -97
  137. package/docs/style-authoring.md +0 -133
  138. package/docs/testing-strategy.md +0 -335
  139. package/docs/theming.md +0 -162
  140. package/examples/agent-improve-auth-flow.ts +0 -206
  141. package/examples/agent-loop.ts +0 -53
  142. package/examples/mcp-vs-cli-complex-diagrams.ts +0 -133
  143. package/llms.txt +0 -104
  144. package/skill-evals/README.md +0 -77
  145. package/skill-evals/fixtures/architecture-cache/input.mmd +0 -5
  146. package/skill-evals/fixtures/class-payment/input.mmd +0 -4
  147. package/skill-evals/fixtures/er-orders/input.mmd +0 -10
  148. package/skill-evals/fixtures/flowchart-cache/input.mmd +0 -3
  149. package/skill-evals/fixtures/gantt-release/input.mmd +0 -7
  150. package/skill-evals/fixtures/journey-checkout/input.mmd +0 -6
  151. package/skill-evals/fixtures/pie-exports/input.mmd +0 -5
  152. package/skill-evals/fixtures/quadrant-priorities/input.mmd +0 -11
  153. package/skill-evals/fixtures/sequence-retry/input.mmd +0 -8
  154. package/skill-evals/fixtures/state-lifecycle/input.mmd +0 -5
  155. package/skill-evals/fixtures/timeline-release/input.mmd +0 -6
  156. package/skill-evals/fixtures/xychart-growth/input.mmd +0 -5
  157. package/skill-evals/shared-benchmark.json +0 -510
  158. package/src/agent/analyze.ts +0 -157
  159. package/src/agent/apply.ts +0 -146
  160. package/src/agent/architecture-body.ts +0 -458
  161. package/src/agent/certificates.ts +0 -110
  162. package/src/agent/class-body.ts +0 -319
  163. package/src/agent/core.ts +0 -207
  164. package/src/agent/create.ts +0 -106
  165. package/src/agent/describe.ts +0 -364
  166. package/src/agent/er-body.ts +0 -224
  167. package/src/agent/facts.ts +0 -337
  168. package/src/agent/families-builtin.ts +0 -934
  169. package/src/agent/families.ts +0 -232
  170. package/src/agent/family-layouts.ts +0 -826
  171. package/src/agent/flowchart-body.ts +0 -372
  172. package/src/agent/flowchart-unsupported.ts +0 -243
  173. package/src/agent/gantt-body.ts +0 -495
  174. package/src/agent/index.ts +0 -10
  175. package/src/agent/journey-body.ts +0 -414
  176. package/src/agent/label-metrics.ts +0 -28
  177. package/src/agent/layout-to-rendered.ts +0 -63
  178. package/src/agent/mutate.ts +0 -97
  179. package/src/agent/mutation-ops.ts +0 -51
  180. package/src/agent/op-schema.ts +0 -439
  181. package/src/agent/parse.ts +0 -223
  182. package/src/agent/pie-body.ts +0 -270
  183. package/src/agent/png.ts +0 -117
  184. package/src/agent/quadrant-body.ts +0 -336
  185. package/src/agent/quality.ts +0 -363
  186. package/src/agent/readability-audit.ts +0 -92
  187. package/src/agent/rendered-route-audit.ts +0 -61
  188. package/src/agent/sequence-body.ts +0 -345
  189. package/src/agent/serialize.ts +0 -214
  190. package/src/agent/state-body.ts +0 -589
  191. package/src/agent/structural-count.ts +0 -150
  192. package/src/agent/timeline-body.ts +0 -280
  193. package/src/agent/trace-log.ts +0 -43
  194. package/src/agent/types.ts +0 -979
  195. package/src/agent/verify.ts +0 -571
  196. package/src/agent/xychart-body.ts +0 -472
  197. package/src/architecture/config.ts +0 -282
  198. package/src/architecture/layout.ts +0 -496
  199. package/src/architecture/parser.ts +0 -375
  200. package/src/architecture/renderer.ts +0 -611
  201. package/src/architecture/types.ts +0 -113
  202. package/src/ascii/ansi.ts +0 -423
  203. package/src/ascii/architecture.ts +0 -210
  204. package/src/ascii/canvas.ts +0 -443
  205. package/src/ascii/class-diagram.ts +0 -697
  206. package/src/ascii/converter.ts +0 -475
  207. package/src/ascii/draw.ts +0 -1693
  208. package/src/ascii/edge-bundling.ts +0 -328
  209. package/src/ascii/edge-routing.ts +0 -330
  210. package/src/ascii/er-diagram.ts +0 -439
  211. package/src/ascii/gantt.ts +0 -276
  212. package/src/ascii/grid.ts +0 -747
  213. package/src/ascii/index.ts +0 -196
  214. package/src/ascii/journey.ts +0 -189
  215. package/src/ascii/meta.ts +0 -244
  216. package/src/ascii/multiline-utils.ts +0 -80
  217. package/src/ascii/pathfinder.ts +0 -301
  218. package/src/ascii/pie.ts +0 -67
  219. package/src/ascii/quadrant.ts +0 -158
  220. package/src/ascii/reverse.ts +0 -216
  221. package/src/ascii/sequence.ts +0 -499
  222. package/src/ascii/shapes/circle.ts +0 -27
  223. package/src/ascii/shapes/corners.ts +0 -143
  224. package/src/ascii/shapes/diamond.ts +0 -27
  225. package/src/ascii/shapes/hexagon.ts +0 -27
  226. package/src/ascii/shapes/index.ts +0 -106
  227. package/src/ascii/shapes/rectangle.ts +0 -168
  228. package/src/ascii/shapes/rounded.ts +0 -27
  229. package/src/ascii/shapes/special.ts +0 -332
  230. package/src/ascii/shapes/stadium.ts +0 -110
  231. package/src/ascii/shapes/state.ts +0 -192
  232. package/src/ascii/shapes/types.ts +0 -73
  233. package/src/ascii/timeline.ts +0 -128
  234. package/src/ascii/types.ts +0 -312
  235. package/src/ascii/validate.ts +0 -120
  236. package/src/ascii/width.ts +0 -81
  237. package/src/ascii/xychart.ts +0 -919
  238. package/src/browser.ts +0 -29
  239. package/src/class/layout.ts +0 -240
  240. package/src/class/parser.ts +0 -332
  241. package/src/class/renderer.ts +0 -638
  242. package/src/class/types.ts +0 -129
  243. package/src/cli/agent-instructions.ts +0 -1
  244. package/src/cli/am-bin.ts +0 -6
  245. package/src/cli/exit-codes.ts +0 -18
  246. package/src/cli/index.ts +0 -1117
  247. package/src/cli/init-agent.ts +0 -147
  248. package/src/color-resolver.ts +0 -152
  249. package/src/elk-instance.ts +0 -114
  250. package/src/er/layout.ts +0 -187
  251. package/src/er/parser.ts +0 -226
  252. package/src/er/renderer.ts +0 -792
  253. package/src/er/types.ts +0 -99
  254. package/src/font-manifest.ts +0 -27
  255. package/src/gantt/layout.ts +0 -365
  256. package/src/gantt/parser.ts +0 -282
  257. package/src/gantt/pipeline.ts +0 -27
  258. package/src/gantt/renderer.ts +0 -414
  259. package/src/gantt/schedule.ts +0 -513
  260. package/src/gantt/types.ts +0 -255
  261. package/src/index.ts +0 -368
  262. package/src/journey/layout.ts +0 -520
  263. package/src/journey/parser.ts +0 -218
  264. package/src/journey/renderer.ts +0 -811
  265. package/src/journey/types.ts +0 -144
  266. package/src/layout/geometry.ts +0 -182
  267. package/src/layout/pass.ts +0 -142
  268. package/src/layout/passes/index.ts +0 -3916
  269. package/src/layout-engine.ts +0 -1565
  270. package/src/layout-rubric.ts +0 -659
  271. package/src/mcp/artifacts.ts +0 -137
  272. package/src/mcp/dynamic-harness.ts +0 -31
  273. package/src/mcp/dynamic-modules.d.ts +0 -7
  274. package/src/mcp/facade.ts +0 -608
  275. package/src/mcp/harness-runtime.ts +0 -203
  276. package/src/mcp/hosted-server.ts +0 -468
  277. package/src/mcp/mcp-bin.ts +0 -3
  278. package/src/mcp/mcp-cli.ts +0 -82
  279. package/src/mcp/protocol.ts +0 -13
  280. package/src/mcp/sandbox.ts +0 -195
  281. package/src/mcp/sdk-decl.ts +0 -387
  282. package/src/mcp/server.ts +0 -362
  283. package/src/mcp/tool-surface.ts +0 -146
  284. package/src/mermaid-source.ts +0 -655
  285. package/src/multiline-utils.ts +0 -228
  286. package/src/parser.ts +0 -1031
  287. package/src/pie/layout.ts +0 -168
  288. package/src/pie/parser.ts +0 -136
  289. package/src/pie/renderer.ts +0 -234
  290. package/src/pie/types.ts +0 -82
  291. package/src/quadrant/layout.ts +0 -191
  292. package/src/quadrant/parser.ts +0 -183
  293. package/src/quadrant/renderer.ts +0 -322
  294. package/src/quadrant/types.ts +0 -113
  295. package/src/render-family-hooks.ts +0 -244
  296. package/src/renderer.ts +0 -1099
  297. package/src/route-contracts.ts +0 -2723
  298. package/src/scene/backend.ts +0 -76
  299. package/src/scene/fidelity.ts +0 -183
  300. package/src/scene/hybrid-backend.ts +0 -174
  301. package/src/scene/ir.ts +0 -181
  302. package/src/scene/marks.ts +0 -127
  303. package/src/scene/rough-backend.ts +0 -378
  304. package/src/scene/seed.ts +0 -46
  305. package/src/scene/style-registry.ts +0 -556
  306. package/src/sequence/layout.ts +0 -456
  307. package/src/sequence/parser.ts +0 -255
  308. package/src/sequence/renderer.ts +0 -604
  309. package/src/sequence/types.ts +0 -154
  310. package/src/shape-clipping.ts +0 -351
  311. package/src/shared/accessibility-directives.ts +0 -22
  312. package/src/shared/batched.ts +0 -61
  313. package/src/shared/color-math.ts +0 -72
  314. package/src/shared/svg-a11y.ts +0 -29
  315. package/src/shared/syntax-error.ts +0 -17
  316. package/src/shared/unicode-ranges.ts +0 -135
  317. package/src/styles.ts +0 -318
  318. package/src/svg-paths.ts +0 -28
  319. package/src/text-metrics.ts +0 -248
  320. package/src/theme.ts +0 -639
  321. package/src/timeline/layout.ts +0 -381
  322. package/src/timeline/parser.ts +0 -215
  323. package/src/timeline/renderer.ts +0 -538
  324. package/src/timeline/types.ts +0 -105
  325. package/src/types.ts +0 -454
  326. package/src/website-worker-modules.d.ts +0 -18
  327. package/src/xychart/axis-utils.ts +0 -109
  328. package/src/xychart/colors.ts +0 -124
  329. package/src/xychart/config.ts +0 -88
  330. package/src/xychart/layout.ts +0 -656
  331. package/src/xychart/parser.ts +0 -504
  332. package/src/xychart/renderer.ts +0 -640
  333. package/src/xychart/types.ts +0 -282
@@ -1,979 +0,0 @@
1
- // ============================================================================
2
- // Agentic Mermaid — IR and verb types (v4)
3
- //
4
- // v4 removes the seed/RNG/clock/font-metric apparatus that the empirical
5
- // probe proved was theater (ELK is already deterministic; seeding changed
6
- // nothing). The only verify knob is labelCharCap. See AGENT_NATIVE.md § (1).
7
- // ============================================================================
8
-
9
- import type { MermaidGraph, NodeShape, EdgeStyle, EdgeRouteCertificate, RegionContainmentCertificate, RouteCertificate, RouteClass } from '../types.ts'
10
- import type { MermaidFrontmatterMap, MermaidConfigMap } from '../mermaid-source.ts'
11
-
12
- // ---- Result ---------------------------------------------------------------
13
-
14
- export type Result<T, E> = { ok: true; value: T } | { ok: false; error: E }
15
- export function ok<T, E = never>(value: T): Result<T, E> { return { ok: true, value } }
16
- export function err<E, T = never>(error: E): Result<T, E> { return { ok: false, error } }
17
-
18
- // ---- Families -------------------------------------------------------------
19
-
20
- export type DiagramKind =
21
- | 'flowchart' | 'state' | 'sequence' | 'class' | 'er'
22
- | 'timeline' | 'journey' | 'xychart' | 'architecture' | 'pie' | 'quadrant' | 'gantt'
23
-
24
- // ---- Sequence body --------------------------------------------------------
25
-
26
- export interface SequenceParticipant {
27
- id: string
28
- label: string
29
- kind: 'participant' | 'actor'
30
- }
31
-
32
- export type SequenceMessageStyle =
33
- | 'sync' // ->>
34
- | 'reply' // -->>
35
- | 'async' // ->
36
- | 'async-dashed' // -->
37
- | 'lost' // -x
38
- | 'lost-dashed' // --x
39
-
40
- export interface SequenceMessage {
41
- from: string
42
- to: string
43
- text: string
44
- style: SequenceMessageStyle
45
- }
46
-
47
- // BUILD-18: ordered statement list. Refs index into the participants/messages
48
- // arrays (which remain the canonical views the SDK declaration, synthesize
49
- // payloads, describe, verify, and tests consume). Opaque-block segments carry
50
- // unmodeled lines (Note/alt/loop/par/activate/autonumber/title…) VERBATIM so
51
- // they ride along in their original position. Messages/participants INSIDE an
52
- // opaque-block are invisible to mutation ops and the messages/participants
53
- // arrays — only top-level structured statements are addressable.
54
- export type SequenceStatement =
55
- | { kind: 'participant'; ref: number } // index into participants
56
- | { kind: 'message'; ref: number } // index into messages
57
- | { kind: 'opaque-block'; lines: string[] }
58
-
59
- export interface SequenceBody {
60
- kind: 'sequence'
61
- participants: SequenceParticipant[]
62
- messages: SequenceMessage[]
63
- // Optional for back-compat: synthesizeFromGraph payloads and hand-built
64
- // bodies may omit it; the serializer falls back to participants-then-messages
65
- // ordering when absent. Parsed bodies always populate it.
66
- statements?: SequenceStatement[]
67
- }
68
-
69
- // ---- Timeline body --------------------------------------------------------
70
-
71
- export interface TimelineEvent {
72
- /** Stable within one parse; recomputed each parse. Not a durable identifier. */
73
- id: string
74
- text: string
75
- }
76
-
77
- export interface TimelinePeriod {
78
- id: string
79
- /** The temporal label (e.g., "2020", "Q1 2024"). */
80
- label: string
81
- events: TimelineEvent[]
82
- }
83
-
84
- export interface TimelineSection {
85
- id: string
86
- /** Undefined = implicit/ungrouped section. */
87
- label?: string
88
- periods: TimelinePeriod[]
89
- }
90
-
91
- export interface TimelineBody {
92
- kind: 'timeline'
93
- title?: string
94
- sections: TimelineSection[]
95
- }
96
-
97
- // ---- Journey body ----------------------------------------------------------
98
-
99
- export interface JourneyTask {
100
- /** Stable within one parse; recomputed each parse. Not a durable identifier. */
101
- id: string
102
- text: string
103
- /** Satisfaction score, integer 1..5 (Mermaid journey convention). */
104
- score: number
105
- actors: string[]
106
- }
107
-
108
- export interface JourneySection {
109
- id: string
110
- /** Undefined = implicit/ungrouped section. */
111
- label?: string
112
- tasks: JourneyTask[]
113
- }
114
-
115
- export interface JourneyBody {
116
- kind: 'journey'
117
- title?: string
118
- /** Optional accessibility title from Mermaid accTitle. */
119
- accessibilityTitle?: string
120
- /** Optional accessibility description from Mermaid accDescr. */
121
- accessibilityDescription?: string
122
- sections: JourneySection[]
123
- }
124
-
125
- // ---- Class diagram body ---------------------------------------------------
126
-
127
- export type ClassRelationKind =
128
- | 'inheritance' // <|--
129
- | 'composition' // *--
130
- | 'aggregation' // o--
131
- | 'association' // --> (or --)
132
- | 'dependency' // ..>
133
- | 'realization' // ..|>
134
- | 'link-solid' // --
135
- | 'link-dashed' // ..
136
-
137
- export interface ClassNode {
138
- /** The bare class name (e.g., 'Animal'). */
139
- id: string
140
- /** Optional display label (e.g., from `class X["My Label"]` or `class X as "..."`). */
141
- label?: string
142
- /** Members, each as the raw source string ('+String name', '+eat()', '<<interface>>'). */
143
- members: string[]
144
- }
145
-
146
- export interface ClassRelation {
147
- from: string
148
- to: string
149
- kind: ClassRelationKind
150
- /** Optional relationship label, e.g., from `A --> B : uses`. */
151
- label?: string
152
- /** Optional cardinality on the `from` side (e.g., '"1"'). */
153
- fromCardinality?: string
154
- /** Optional cardinality on the `to` side. */
155
- toCardinality?: string
156
- }
157
-
158
- export interface ClassNote {
159
- text: string
160
- /** Class id the note is attached to (undefined = freestanding). */
161
- for?: string
162
- }
163
-
164
- export interface ClassBody {
165
- kind: 'class'
166
- title?: string
167
- classes: ClassNode[]
168
- relations: ClassRelation[]
169
- notes: ClassNote[]
170
- }
171
-
172
- // ---- ER body --------------------------------------------------------------
173
-
174
- export type ErCardinality =
175
- | 'one-only' // ||
176
- | 'zero-or-one' // |o or o|
177
- | 'zero-or-many' // }o or o{
178
- | 'one-or-many' // }| or |{
179
-
180
- export interface ErAttribute {
181
- /** The full source line (e.g., 'string name PK "comment"'). */
182
- text: string
183
- }
184
-
185
- export interface ErEntity {
186
- id: string
187
- attributes: ErAttribute[]
188
- }
189
-
190
- export interface ErRelation {
191
- from: string
192
- to: string
193
- leftCard: ErCardinality
194
- rightCard: ErCardinality
195
- /** Solid (--) or dashed (..) line. */
196
- dashed: boolean
197
- label?: string
198
- }
199
-
200
- export interface ErBody {
201
- kind: 'er'
202
- entities: ErEntity[]
203
- relations: ErRelation[]
204
- }
205
-
206
- // ---- Architecture body -----------------------------------------------------
207
-
208
- export type ArchitectureSide = 'L' | 'R' | 'T' | 'B'
209
-
210
- export interface ArchitectureGroup {
211
- id: string
212
- label: string
213
- icon?: string
214
- /** Undefined = root (not nested in another group). */
215
- parentId?: string
216
- }
217
-
218
- export interface ArchitectureService {
219
- id: string
220
- label: string
221
- icon?: string
222
- /** Undefined = ungrouped (not inside a group). */
223
- parentId?: string
224
- }
225
-
226
- export interface ArchitectureJunction {
227
- id: string
228
- parentId?: string
229
- }
230
-
231
- export interface ArchitectureEndpoint {
232
- id: string
233
- side: ArchitectureSide
234
- }
235
-
236
- export interface ArchitectureEdge {
237
- source: ArchitectureEndpoint
238
- target: ArchitectureEndpoint
239
- label?: string
240
- hasArrowStart: boolean
241
- hasArrowEnd: boolean
242
- }
243
-
244
- export interface ArchitectureBody {
245
- kind: 'architecture'
246
- groups: ArchitectureGroup[]
247
- services: ArchitectureService[]
248
- junctions: ArchitectureJunction[]
249
- edges: ArchitectureEdge[]
250
- }
251
-
252
- // ---- XY chart body ---------------------------------------------------------
253
-
254
- /** A single chart axis: an optional bare-text name plus EITHER categorical
255
- * labels (x-axis only) OR a numeric range. All three fields are optional;
256
- * a structured axis carries at least one of them. */
257
- export interface XyChartAxis {
258
- /** Optional bare-text axis name/title. */
259
- name?: string
260
- /** Categorical labels (x-axis only) — mutually exclusive with range. */
261
- categories?: string[]
262
- /** Numeric range — mutually exclusive with categories. */
263
- range?: { min: number; max: number }
264
- }
265
-
266
- export interface XyChartSeries {
267
- /** Stable within one parse; recomputed each parse. Not a durable identifier. */
268
- id: string
269
- kind: 'bar' | 'line'
270
- /** Optional bare-text series name. */
271
- name?: string
272
- /** Data values; all finite. */
273
- values: number[]
274
- }
275
-
276
- export interface XyChartBody {
277
- kind: 'xychart'
278
- title?: string
279
- /** Header orientation suffix: `xychart-beta horizontal`. Default vertical. */
280
- horizontal?: boolean
281
- xAxis?: XyChartAxis
282
- yAxis?: XyChartAxis
283
- series: XyChartSeries[]
284
- }
285
-
286
- // ---- Pie body ---------------------------------------------------------------
287
-
288
- export interface PieSlice {
289
- /** Stable within one parse; recomputed each parse. Not a durable identifier. */
290
- id: string
291
- /** The slice label (contents of the `"..."` quotes). */
292
- label: string
293
- /** The slice value — a positive finite number. */
294
- value: number
295
- }
296
-
297
- export interface PieBody {
298
- kind: 'pie'
299
- title?: string
300
- /** When true (`pie showData`), the legend shows each slice's numeric value. */
301
- showData: boolean
302
- /** Slices in source order (drawn clockwise). */
303
- slices: PieSlice[]
304
- }
305
-
306
- // ---- Quadrant body ----------------------------------------------------------
307
-
308
- /** Axis label pair. The "far" side is optional in the grammar. */
309
- export interface QuadrantAxis {
310
- /** x-axis: left label / y-axis: bottom label. */
311
- near: string
312
- /** x-axis: right label / y-axis: top label. Optional. */
313
- far?: string
314
- }
315
-
316
- export interface QuadrantPoint {
317
- label: string
318
- /** Normalized x in [0, 1] (0 = left, 1 = right). */
319
- x: number
320
- /** Normalized y in [0, 1] (0 = bottom, 1 = top). */
321
- y: number
322
- }
323
-
324
- export interface QuadrantBody {
325
- kind: 'quadrant'
326
- title?: string
327
- xAxis?: QuadrantAxis
328
- yAxis?: QuadrantAxis
329
- /**
330
- * Quadrant region labels indexed 1..4 by Mermaid's numbering:
331
- * 1 = top-right, 2 = top-left, 3 = bottom-left, 4 = bottom-right.
332
- * Stored 0-based where index `n-1` holds quadrant-`n`.
333
- */
334
- quadrants: [string?, string?, string?, string?]
335
- /** Plotted points in source order. */
336
- points: QuadrantPoint[]
337
- }
338
-
339
- // ---- Gantt body --------------------------------------------------------------
340
-
341
- export type GanttBodyTaskTag = 'active' | 'done' | 'crit' | 'milestone' | 'vert'
342
-
343
- export interface GanttBodyTask {
344
- /** Stable within one parse; recomputed each parse. Not a durable identifier. */
345
- id: string
346
- /** Mermaid task id from `:id, start, end` — referenced by after/until/click. */
347
- taskId?: string
348
- label: string
349
- /** Status/shape tags in canonical order (active/done/crit/milestone/vert). */
350
- tags: GanttBodyTaskTag[]
351
- /** Raw start expression: a date in the diagram's dateFormat or `after id…`.
352
- * Undefined = starts when the previous task ends (Mermaid default). */
353
- start?: string
354
- /** Raw end expression: a date, a duration token (`3d`), or `until id…`. */
355
- end: string
356
- }
357
-
358
- export interface GanttBodySection {
359
- id: string
360
- /** Undefined = implicit/ungrouped section. */
361
- label?: string
362
- tasks: GanttBodyTask[]
363
- }
364
-
365
- /**
366
- * Segment-preserving statement list (the sequence-body pattern): typed ops see
367
- * sections/tasks/title; calendar directives (dateFormat, excludes, weekend…),
368
- * click lines, comments, and markers ride along VERBATIM as opaque-block
369
- * segments — never dropped, edited at the source level only.
370
- */
371
- export type GanttStatement =
372
- | { kind: 'title' }
373
- | { kind: 'section'; ref: number } // index into sections
374
- | { kind: 'task'; section: number; ref: number } // section + task index
375
- | { kind: 'opaque-block'; lines: string[] }
376
-
377
- export interface GanttBody {
378
- kind: 'gantt'
379
- title?: string
380
- sections: GanttBodySection[]
381
- /** Optional for synthesized payloads; parsed bodies always populate it. */
382
- statements?: GanttStatement[]
383
- }
384
-
385
- // ---- State diagram body -----------------------------------------------------
386
-
387
- /**
388
- * A state node. Simple states carry an optional display label; composite states
389
- * additionally carry their own nested `states` + `transitions` (and an optional
390
- * per-composite `direction`). The reserved pseudostate `[*]` is NOT a StateNode
391
- * — it is modeled contextually as the endpoint id '[*]' on transitions (source
392
- * = start pseudostate, target = end pseudostate), scoped per composite level.
393
- */
394
- export interface StateNode {
395
- id: string
396
- /** Optional display label (`state "Label" as id` / `id : Label`). */
397
- label?: string
398
- /** Composite children — present iff this is a composite state. */
399
- states?: StateNode[]
400
- /** Composite-internal transitions — present iff this is a composite state. */
401
- transitions?: StateTransition[]
402
- /** Optional per-composite layout direction. */
403
- direction?: import('../types.ts').Direction
404
- }
405
-
406
- export interface StateTransition {
407
- /** Source state id, or '[*]' for a start pseudostate. */
408
- from: string
409
- /** Target state id, or '[*]' for an end pseudostate. */
410
- to: string
411
- label?: string
412
- }
413
-
414
- export interface StateBody {
415
- kind: 'state'
416
- states: StateNode[]
417
- transitions: StateTransition[]
418
- /** Optional top-level layout direction. */
419
- direction?: import('../types.ts').Direction
420
- }
421
-
422
- // ---- Meta + IR ------------------------------------------------------------
423
-
424
- export interface SourceComment { text: string; line: number }
425
- export interface InitDirective { raw: string; parsed: MermaidConfigMap }
426
- export interface Accessibility { title?: string; descr?: string }
427
-
428
- export interface ValidDiagramMeta {
429
- frontmatter?: MermaidFrontmatterMap
430
- initDirectives: InitDirective[]
431
- comments: SourceComment[]
432
- accessibility: Accessibility
433
- /**
434
- * The leading source wrapper (frontmatter block, `%%{init}%%` directives,
435
- * `%%` comments, and blank lines before the diagram header), preserved
436
- * byte-verbatim. serializeMermaid re-emits it untouched by default;
437
- * canonical wrapper synthesis is opt-in via `{ wrapper: 'canonical' }`.
438
- * Absent on diagrams synthesized from JSON payloads, which fall back to
439
- * canonical synthesis.
440
- */
441
- wrapperSource?: string
442
- /**
443
- * In-body `%%` comments that structured serialization does not preserve,
444
- * computed at parse time by diffing against the canonical serialization.
445
- * Surfaced by verify as the Tier 3 `COMMENT_DROPPED` lint. Opaque bodies
446
- * preserve comments verbatim and never set this.
447
- */
448
- droppedComments?: SourceComment[]
449
- }
450
-
451
- export interface SourceLocation { line: number; col: number }
452
-
453
- export interface SourceMap {
454
- nodes: Map<string, SourceLocation>
455
- edges: Map<string, SourceLocation>
456
- groups: Map<string, SourceLocation>
457
- /** Stable label spans where known: `node:<id>`, `edge#<i>:<from>-><to>`, `group:<id>`. */
458
- labels: Map<string, SourceLocation>
459
- }
460
-
461
- export type DiagramActionKind = 'href' | 'call' | 'callback'
462
- export type DiagramActionSecurity = 'safe' | 'unsafe' | 'source-only' | 'unsupported'
463
-
464
- export interface DiagramActionRecord {
465
- /** Stable source-side action id (`action:<family>:<target>:<n>`). */
466
- id?: string
467
- /** Region id this action attaches to when a rendered layout exposes regions. */
468
- regionId?: string
469
- family: DiagramKind
470
- target: string
471
- action: DiagramActionKind
472
- /** Original action payload after the target id; never executed by analysis. */
473
- raw: string
474
- line?: number
475
- href?: string
476
- security: DiagramActionSecurity
477
- executable: false
478
- message?: string
479
- }
480
-
481
- export interface FeedbackEdgeAnalysis {
482
- edgeIndex: number
483
- from: NodeId
484
- to: NodeId
485
- label?: string
486
- routeClass: RouteClass
487
- }
488
-
489
- export interface GanttScheduleAnalysisSummary {
490
- criticalPathTaskIds: string[]
491
- slackByTaskId: Record<string, number>
492
- projectStart: number
493
- projectEnd: number
494
- entryTaskIds: string[]
495
- sinkTaskIds: string[]
496
- }
497
-
498
- export interface DiagramAnalysis {
499
- kind: DiagramKind
500
- feedbackEdges: FeedbackEdgeAnalysis[]
501
- actions: DiagramActionRecord[]
502
- gantt?: GanttScheduleAnalysisSummary
503
- }
504
-
505
- export type DiagramBody =
506
- | { kind: 'flowchart'; graph: MermaidGraph }
507
- | StateBody
508
- | SequenceBody
509
- | TimelineBody
510
- | ClassBody
511
- | ErBody
512
- | JourneyBody
513
- | ArchitectureBody
514
- | XyChartBody
515
- | PieBody
516
- | QuadrantBody
517
- | GanttBody
518
- /**
519
- * Opaque body — the parser understood the family header but encountered
520
- * unmodeled syntax. `source` is the ORIGINAL body with indentation, blank
521
- * lines, and comments PRESERVED (per the Loop 5 Phase A fix), so the
522
- * serializer can re-emit byte-for-byte. Distinct from `ValidDiagram.canonicalSource`,
523
- * which for structured bodies is the rebuilt canonical form.
524
- */
525
- | { kind: 'opaque'; family: DiagramKind; source: string }
526
-
527
- export interface ValidDiagram {
528
- readonly kind: DiagramKind
529
- readonly meta: ValidDiagramMeta
530
- readonly body: DiagramBody
531
- readonly source: SourceMap
532
- /**
533
- * Load-bearing round-trip pillar. See AGENT_NATIVE.md § (3).
534
- *
535
- * For STRUCTURED bodies, `canonicalSource` is the normalized text
536
- * (`normalized.text` from `mermaid-source.ts`) — used by `renderMermaidSVG`
537
- * + the legacy parser for the flowchart pathway. After `serializeMermaid`,
538
- * the re-emitted source is rebuilt from the structured body.
539
- *
540
- * For OPAQUE bodies, the serializer emits `body.source` directly (NOT
541
- * `canonicalSource`) so original indentation and blank lines round-trip
542
- * byte-for-byte. `canonicalSource` is still set, but it's the normalized
543
- * (line-trimmed) form — useful for layout / rendering, not for fidelity.
544
- *
545
- * This split exists because the legacy flowchart parser needs trimmed
546
- * lines, but opaque-fallback round-trip needs the original. Treat
547
- * `body.source` as the source of truth for opaque-body fidelity.
548
- */
549
- readonly canonicalSource: string
550
- }
551
-
552
- export type FlowchartValidDiagram = ValidDiagram & { body: { kind: 'flowchart'; graph: MermaidGraph } }
553
- export type StateValidDiagram = ValidDiagram & { body: StateBody }
554
- export type SequenceValidDiagram = ValidDiagram & { body: SequenceBody }
555
- export type TimelineValidDiagram = ValidDiagram & { body: TimelineBody }
556
- export type ClassValidDiagram = ValidDiagram & { body: ClassBody }
557
- export type ErValidDiagram = ValidDiagram & { body: ErBody }
558
- export type JourneyValidDiagram = ValidDiagram & { body: JourneyBody }
559
- export type ArchitectureValidDiagram = ValidDiagram & { body: ArchitectureBody }
560
- export type XyChartValidDiagram = ValidDiagram & { body: XyChartBody }
561
- export type PieValidDiagram = ValidDiagram & { body: PieBody }
562
- export type QuadrantValidDiagram = ValidDiagram & { body: QuadrantBody }
563
- export type GanttValidDiagram = ValidDiagram & { body: GanttBody }
564
- export type MutableValidDiagram = FlowchartValidDiagram | StateValidDiagram | SequenceValidDiagram | TimelineValidDiagram | ClassValidDiagram | ErValidDiagram | JourneyValidDiagram | ArchitectureValidDiagram | XyChartValidDiagram | PieValidDiagram | QuadrantValidDiagram | GanttValidDiagram
565
-
566
- export function asFlowchart(d: ValidDiagram): FlowchartValidDiagram | null {
567
- return d.body.kind === 'flowchart' ? (d as FlowchartValidDiagram) : null
568
- }
569
- export function asState(d: ValidDiagram): StateValidDiagram | null {
570
- return d.body.kind === 'state' ? (d as StateValidDiagram) : null
571
- }
572
- export function asSequence(d: ValidDiagram): SequenceValidDiagram | null {
573
- return d.body.kind === 'sequence' ? (d as SequenceValidDiagram) : null
574
- }
575
-
576
- export function asTimeline(d: ValidDiagram): TimelineValidDiagram | null {
577
- return d.body.kind === 'timeline' ? (d as TimelineValidDiagram) : null
578
- }
579
-
580
- export function asClass(d: ValidDiagram): ClassValidDiagram | null {
581
- return d.body.kind === 'class' ? (d as ClassValidDiagram) : null
582
- }
583
-
584
- export function asEr(d: ValidDiagram): ErValidDiagram | null {
585
- return d.body.kind === 'er' ? (d as ErValidDiagram) : null
586
- }
587
-
588
- export function asJourney(d: ValidDiagram): JourneyValidDiagram | null {
589
- return d.body.kind === 'journey' ? (d as JourneyValidDiagram) : null
590
- }
591
-
592
- export function asArchitecture(d: ValidDiagram): ArchitectureValidDiagram | null {
593
- return d.body.kind === 'architecture' ? (d as ArchitectureValidDiagram) : null
594
- }
595
-
596
- export function asXyChart(d: ValidDiagram): XyChartValidDiagram | null {
597
- return d.body.kind === 'xychart' ? (d as XyChartValidDiagram) : null
598
- }
599
-
600
- export function asPie(d: ValidDiagram): PieValidDiagram | null {
601
- return d.body.kind === 'pie' ? (d as PieValidDiagram) : null
602
- }
603
-
604
- export function asQuadrant(d: ValidDiagram): QuadrantValidDiagram | null {
605
- return d.body.kind === 'quadrant' ? (d as QuadrantValidDiagram) : null
606
- }
607
-
608
- export function asGantt(d: ValidDiagram): GanttValidDiagram | null {
609
- return d.body.kind === 'gantt' ? (d as GanttValidDiagram) : null
610
- }
611
-
612
- // ---- Errors ---------------------------------------------------------------
613
-
614
- export interface ParseError { code: string; message: string; line?: number; col?: number }
615
-
616
- export interface MutationError {
617
- code:
618
- | 'NODE_NOT_FOUND' | 'EDGE_NOT_FOUND'
619
- | 'PARTICIPANT_NOT_FOUND' | 'MESSAGE_NOT_FOUND'
620
- | 'SECTION_NOT_FOUND' | 'PERIOD_NOT_FOUND' | 'EVENT_NOT_FOUND'
621
- | 'TASK_NOT_FOUND' | 'ACTOR_NOT_FOUND'
622
- | 'CLASS_NOT_FOUND' | 'MEMBER_NOT_FOUND' | 'RELATION_NOT_FOUND' | 'NOTE_NOT_FOUND'
623
- | 'ENTITY_NOT_FOUND' | 'ATTRIBUTE_NOT_FOUND'
624
- | 'SERVICE_NOT_FOUND' | 'GROUP_NOT_FOUND'
625
- | 'SERIES_NOT_FOUND'
626
- | 'SLICE_NOT_FOUND' | 'POINT_NOT_FOUND'
627
- | 'STATE_NOT_FOUND' | 'TRANSITION_NOT_FOUND'
628
- | 'DUPLICATE_NODE' | 'DUPLICATE_PARTICIPANT' | 'DUPLICATE_CLASS' | 'DUPLICATE_ENTITY' | 'DUPLICATE_STATE' | 'DUPLICATE_TASK'
629
- | 'INVALID_OP'
630
- message: string
631
- }
632
-
633
- // ---- MutationOp -----------------------------------------------------------
634
-
635
- export type NodeId = string
636
- export type EdgeId = string
637
- export type GroupId = string
638
- export type ParticipantId = string
639
-
640
- export type FlowchartMutationOp =
641
- | { kind: 'add_node'; id: NodeId; label: string; shape?: NodeShape; parent?: GroupId }
642
- | { kind: 'remove_node'; id: NodeId }
643
- | { kind: 'rename_node'; from: NodeId; to: NodeId }
644
- | { kind: 'set_label'; target: NodeId | EdgeId; label: string }
645
- | { kind: 'add_edge'; from: NodeId; to: NodeId; label?: string; style?: EdgeStyle }
646
- | { kind: 'remove_edge'; id: EdgeId }
647
-
648
- export type SequenceMutationOp =
649
- | { kind: 'add_participant'; id: ParticipantId; label?: string; participantKind?: 'participant' | 'actor' }
650
- | { kind: 'remove_participant'; id: ParticipantId }
651
- | { kind: 'add_message'; from: ParticipantId; to: ParticipantId; text: string; style?: SequenceMessageStyle }
652
- | { kind: 'remove_message'; index: number }
653
- | { kind: 'set_message_text'; index: number; text: string }
654
-
655
- export type TimelineMutationOp =
656
- | { kind: 'set_title'; title: string | null }
657
- | { kind: 'add_section'; label: string }
658
- | { kind: 'remove_section'; index: number }
659
- | { kind: 'set_section_label'; index: number; label: string }
660
- | { kind: 'add_period'; sectionIndex: number; label: string; events?: string[] }
661
- | { kind: 'remove_period'; sectionIndex: number; periodIndex: number }
662
- | { kind: 'set_period_label'; sectionIndex: number; periodIndex: number; label: string }
663
- | { kind: 'add_event'; sectionIndex: number; periodIndex: number; text: string }
664
- | { kind: 'remove_event'; sectionIndex: number; periodIndex: number; eventIndex: number }
665
- | { kind: 'set_event_text'; sectionIndex: number; periodIndex: number; eventIndex: number; text: string }
666
-
667
- export type ClassMutationOp =
668
- | { kind: 'set_title'; title: string | null }
669
- | { kind: 'add_class'; id: string; label?: string; members?: string[] }
670
- | { kind: 'remove_class'; id: string }
671
- | { kind: 'rename_class'; from: string; to: string }
672
- | { kind: 'add_member'; class: string; text: string }
673
- | { kind: 'remove_member'; class: string; index: number }
674
- | { kind: 'add_relation'; from: string; to: string; relKind: ClassRelationKind; label?: string }
675
- | { kind: 'remove_relation'; index: number }
676
- | { kind: 'add_note'; text: string; for?: string }
677
- | { kind: 'remove_note'; index: number }
678
-
679
- export type ErMutationOp =
680
- | { kind: 'add_entity'; id: string; attributes?: string[] }
681
- | { kind: 'remove_entity'; id: string }
682
- | { kind: 'rename_entity'; from: string; to: string }
683
- | { kind: 'add_attribute'; entity: string; text: string }
684
- | { kind: 'remove_attribute'; entity: string; index: number }
685
- | { kind: 'add_relation'; from: string; to: string; leftCard: ErCardinality; rightCard: ErCardinality; dashed?: boolean; label?: string }
686
- | { kind: 'remove_relation'; index: number }
687
-
688
- export type JourneyMutationOp =
689
- | { kind: 'set_title'; title: string | null }
690
- | { kind: 'add_section'; label: string }
691
- | { kind: 'remove_section'; index: number }
692
- | { kind: 'set_section_label'; index: number; label: string }
693
- | { kind: 'add_task'; sectionIndex: number; text: string; score: number; actors?: string[] }
694
- | { kind: 'remove_task'; sectionIndex: number; taskIndex: number }
695
- | { kind: 'set_task_text'; sectionIndex: number; taskIndex: number; text: string }
696
- | { kind: 'set_task_score'; sectionIndex: number; taskIndex: number; score: number }
697
- | { kind: 'set_task_actors'; sectionIndex: number; taskIndex: number; actors: string[] }
698
- | { kind: 'rename_actor'; from: string; to: string }
699
-
700
- export type ArchitectureMutationOp =
701
- | { kind: 'add_service'; id: string; label?: string; icon?: string | null; group?: string | null }
702
- | { kind: 'remove_service'; id: string }
703
- | { kind: 'rename_service'; from: string; to: string }
704
- | { kind: 'set_service_label'; id: string; label: string }
705
- | { kind: 'set_service_icon'; id: string; icon: string | null }
706
- | { kind: 'move_service'; id: string; group: string | null }
707
- | { kind: 'add_group'; id: string; label?: string; icon?: string | null; parent?: string | null }
708
- | { kind: 'remove_group'; id: string }
709
- | { kind: 'add_edge'; from: string; to: string; fromSide: ArchitectureSide; toSide: ArchitectureSide; label?: string | null; hasArrowStart?: boolean; hasArrowEnd?: boolean }
710
- | { kind: 'remove_edge'; index?: number; id?: string }
711
-
712
- export type StateMutationOp =
713
- | { kind: 'add_state'; id: string; label?: string | null; parent?: string | null }
714
- | { kind: 'remove_state'; id: string }
715
- | { kind: 'rename_state'; from: string; to: string }
716
- | { kind: 'set_state_label'; id: string; label: string | null }
717
- | { kind: 'add_transition'; from: string; to: string; label?: string | null; parent?: string | null }
718
- | { kind: 'remove_transition'; index?: number; from?: string; to?: string; parent?: string | null }
719
- | { kind: 'set_transition_label'; index?: number; from?: string; to?: string; label: string | null; parent?: string | null }
720
- | { kind: 'make_composite'; id: string; members: string[]; label?: string | null }
721
-
722
- export type XyChartAxisSpec = { name?: string | null; categories?: string[]; range?: { min: number; max: number } }
723
-
724
- export type XyChartMutationOp =
725
- | { kind: 'set_title'; title: string | null }
726
- | { kind: 'set_x_axis'; axis: XyChartAxisSpec | null }
727
- | { kind: 'set_y_axis'; axis: XyChartAxisSpec | null }
728
- | { kind: 'add_series'; kind2: 'bar' | 'line'; name?: string | null; values: number[] }
729
- | { kind: 'remove_series'; index: number }
730
- | { kind: 'set_series_values'; index: number; values: number[] }
731
- | { kind: 'set_series_name'; index: number; name: string | null }
732
- | { kind: 'reorder_series'; from: number; to: number }
733
-
734
- export type PieMutationOp =
735
- | { kind: 'set_title'; title: string | null }
736
- | { kind: 'set_show_data'; showData: boolean }
737
- | { kind: 'add_slice'; label: string; value: number }
738
- | { kind: 'remove_slice'; label: string }
739
- | { kind: 'rename_slice'; from: string; to: string }
740
- | { kind: 'set_slice_value'; label: string; value: number }
741
- | { kind: 'reorder_slice'; from: number; to: number }
742
-
743
- export type QuadrantMutationOp =
744
- | { kind: 'set_title'; title: string | null }
745
- | { kind: 'set_axis_labels'; axis: 'x' | 'y'; near: string | null; far?: string | null }
746
- | { kind: 'set_quadrant_label'; quadrant: number; label: string | null }
747
- | { kind: 'add_point'; label: string; x: number; y: number }
748
- | { kind: 'remove_point'; label: string }
749
- | { kind: 'move_point'; label: string; x: number; y: number }
750
- | { kind: 'rename_point'; from: string; to: string }
751
-
752
- export type GanttMutationOp =
753
- | { kind: 'set_title'; title: string | null }
754
- | { kind: 'add_section'; label: string }
755
- | { kind: 'rename_section'; index: number; label: string }
756
- | { kind: 'remove_section'; index: number }
757
- | { kind: 'add_task'; sectionIndex: number; label: string; taskId?: string; tags?: GanttBodyTaskTag[]; start?: string; end: string }
758
- | { kind: 'remove_task'; sectionIndex: number; taskIndex: number }
759
- | { kind: 'rename_task'; sectionIndex: number; taskIndex: number; label: string }
760
- | { kind: 'set_task_status'; sectionIndex: number; taskIndex: number; status: 'active' | 'done' | 'crit' | null }
761
- | { kind: 'set_task_dates'; sectionIndex: number; taskIndex: number; start?: string | null; end?: string }
762
-
763
- export type AnyMutationOp = FlowchartMutationOp | StateMutationOp | SequenceMutationOp | TimelineMutationOp | ClassMutationOp | ErMutationOp | JourneyMutationOp | ArchitectureMutationOp | XyChartMutationOp | PieMutationOp | QuadrantMutationOp | GanttMutationOp
764
- export type MutationOp = FlowchartMutationOp // legacy alias
765
-
766
- // ---- Branded Finite -------------------------------------------------------
767
-
768
- declare const FINITE_BRAND: unique symbol
769
- export type Finite = number & { readonly [FINITE_BRAND]: true }
770
-
771
- export function toFinite(n: number): Finite {
772
- if (!Number.isFinite(n)) throw new RangeError(`expected a finite number, got ${String(n)}`)
773
- return n as Finite
774
- }
775
-
776
- // ---- Verify ---------------------------------------------------------------
777
-
778
- export type WarningSeverity = 'error' | 'warning'
779
- export type WarningTier = 'structural' | 'geometric' | 'lint'
780
-
781
- export type Tier1WarningCode =
782
- | 'EMPTY_DIAGRAM' | 'EDGE_MISANCHORED' | 'OFF_CANVAS'
783
- | 'GROUP_BREACH' | 'UNKNOWN_SHAPE' | 'LABEL_OVERFLOW' | 'UNRESOLVABLE_SCHEDULE'
784
- | 'RENDER_FAILED'
785
- export type Tier2WarningCode =
786
- | 'NODE_OVERLAP' | 'ROUTE_SELF_CROSS' | 'ROUTE_HITCH'
787
- | 'ROUTE_UNEXPLAINED_BEND' | 'ROUTE_LABEL_ON_SHARED_TRUNK'
788
- | 'ROUTE_CONTAINER_MISANCHOR' | 'ROUTE_SHAPE_MISANCHOR' | 'ROUTE_STALE_AFTER_NODE_MOVE'
789
- /**
790
- * Tier 3 (advisory lint). Family-specific quality hints for common agent
791
- * mistakes that still parse and render. Lint warnings never flip verify.ok.
792
- */
793
- export type Tier3WarningCode = 'DUPLICATE_EDGE' | 'UNREACHABLE_NODE' | 'DECISION_BRANCH_UNLABELED' | 'COMMENT_DROPPED' | 'UNSUPPORTED_SYNTAX' | 'CONTENT_DROPPED_ON_ROUNDTRIP'
794
- export type WarningCode = Tier1WarningCode | Tier2WarningCode | Tier3WarningCode
795
-
796
- export type LayoutWarning =
797
- | { code: 'EMPTY_DIAGRAM' }
798
- | { code: 'EDGE_MISANCHORED'; edge: EdgeId; from?: NodeId; to?: NodeId }
799
- | { code: 'OFF_CANVAS'; target: NodeId | EdgeId; axis: 'x' | 'y' }
800
- | { code: 'GROUP_BREACH'; group: GroupId; member: NodeId }
801
- | { code: 'UNKNOWN_SHAPE'; node: NodeId; shape: string }
802
- | { code: 'LABEL_OVERFLOW'; target: NodeId | EdgeId; charCount: number; limit: number }
803
- /**
804
- * The diagram parses (and round-trips) but its semantics cannot resolve, so
805
- * rendering will fail loudly — e.g. a Gantt whose schedule hits a bad
806
- * calendar date, a dependency cycle, or an everything-excluded calendar.
807
- * `reason` carries the named renderer error (GANTT_*…). Closes the
808
- * "verify ok but render throws" seam for structured gantt bodies.
809
- */
810
- | { code: 'UNRESOLVABLE_SCHEDULE'; reason: string }
811
- /**
812
- * The diagram parses on the agent side (possibly with unmodeled syntax
813
- * preserved verbatim) but the STRICT render parser throws on its canonical
814
- * source — `am render` would exit 4. Generalizes UNRESOLVABLE_SCHEDULE's
815
- * "verify ok but render throws" seam-closing to every family: found live
816
- * when onboarding agents followed verify-before-commit and still shipped
817
- * unrenderable quadrant/architecture diagrams. `reason` carries the
818
- * renderer's error message.
819
- */
820
- | { code: 'RENDER_FAILED'; reason: string }
821
- | { code: 'NODE_OVERLAP'; a: NodeId; b: NodeId; areaPx: number }
822
- | { code: 'ROUTE_SELF_CROSS'; edge: EdgeId; count: number }
823
- | { code: 'ROUTE_HITCH'; edge: EdgeId; deviationPx: number }
824
- | { code: 'ROUTE_UNEXPLAINED_BEND'; edge: EdgeId }
825
- | { code: 'ROUTE_LABEL_ON_SHARED_TRUNK'; edge: EdgeId; sharedWith: EdgeId }
826
- | { code: 'ROUTE_CONTAINER_MISANCHOR'; edge: EdgeId; container: GroupId }
827
- | { code: 'ROUTE_SHAPE_MISANCHOR'; edge: EdgeId; node: NodeId }
828
- | { code: 'ROUTE_STALE_AFTER_NODE_MOVE'; edge: EdgeId; node: NodeId }
829
- | { code: 'DUPLICATE_EDGE'; edge: EdgeId; duplicateOf: EdgeId; from: NodeId; to: NodeId; label?: string }
830
- | { code: 'UNREACHABLE_NODE'; node: NodeId }
831
- | { code: 'DECISION_BRANCH_UNLABELED'; node: NodeId; edge: EdgeId }
832
- | { code: 'COMMENT_DROPPED'; count: number; lines: number[] }
833
- | { code: 'UNSUPPORTED_SYNTAX'; line?: number; syntax: string; message: string }
834
- /**
835
- * Structured content was lost across a parse → serialize → re-parse cycle:
836
- * the {nodes, edges, groups} tally changed, so canonical serialization is
837
- * silently dropping (or duplicating) a node/edge/group even though the bytes
838
- * may re-parse. The faithfulness analogue of COMMENT_DROPPED — "100% parse
839
- * success is not faithfulness" (Loop 17). Lint, never flips verify.ok.
840
- */
841
- | { code: 'CONTENT_DROPPED_ON_ROUNDTRIP'; before: { nodes: number; edges: number; groups: number }; after: { nodes: number; edges: number; groups: number } }
842
-
843
- export const WARNING_SEVERITY: Record<WarningCode, WarningSeverity> = {
844
- EMPTY_DIAGRAM: 'error',
845
- UNRESOLVABLE_SCHEDULE: 'error',
846
- RENDER_FAILED: 'error',
847
- EDGE_MISANCHORED: 'error',
848
- OFF_CANVAS: 'error',
849
- GROUP_BREACH: 'error',
850
- UNKNOWN_SHAPE: 'warning',
851
- LABEL_OVERFLOW: 'warning',
852
- NODE_OVERLAP: 'warning',
853
- ROUTE_SELF_CROSS: 'warning',
854
- ROUTE_HITCH: 'warning',
855
- ROUTE_UNEXPLAINED_BEND: 'warning',
856
- ROUTE_LABEL_ON_SHARED_TRUNK: 'warning',
857
- ROUTE_CONTAINER_MISANCHOR: 'warning',
858
- ROUTE_SHAPE_MISANCHOR: 'warning',
859
- ROUTE_STALE_AFTER_NODE_MOVE: 'warning',
860
- DUPLICATE_EDGE: 'warning',
861
- UNREACHABLE_NODE: 'warning',
862
- DECISION_BRANCH_UNLABELED: 'warning',
863
- COMMENT_DROPPED: 'warning',
864
- UNSUPPORTED_SYNTAX: 'warning',
865
- CONTENT_DROPPED_ON_ROUNDTRIP: 'warning',
866
- }
867
-
868
- export const WARNING_TIER: Record<WarningCode, WarningTier> = {
869
- EMPTY_DIAGRAM: 'structural',
870
- UNRESOLVABLE_SCHEDULE: 'structural',
871
- RENDER_FAILED: 'structural',
872
- EDGE_MISANCHORED: 'structural',
873
- OFF_CANVAS: 'structural',
874
- GROUP_BREACH: 'structural',
875
- UNKNOWN_SHAPE: 'structural',
876
- LABEL_OVERFLOW: 'structural',
877
- NODE_OVERLAP: 'geometric',
878
- ROUTE_SELF_CROSS: 'geometric',
879
- ROUTE_HITCH: 'geometric',
880
- ROUTE_UNEXPLAINED_BEND: 'geometric',
881
- ROUTE_LABEL_ON_SHARED_TRUNK: 'geometric',
882
- ROUTE_CONTAINER_MISANCHOR: 'geometric',
883
- ROUTE_SHAPE_MISANCHOR: 'geometric',
884
- ROUTE_STALE_AFTER_NODE_MOVE: 'geometric',
885
- DUPLICATE_EDGE: 'lint',
886
- UNREACHABLE_NODE: 'lint',
887
- DECISION_BRANCH_UNLABELED: 'lint',
888
- COMMENT_DROPPED: 'lint',
889
- UNSUPPORTED_SYNTAX: 'lint',
890
- CONTENT_DROPPED_ON_ROUNDTRIP: 'lint',
891
- }
892
-
893
- export const DEFAULT_LABEL_CHAR_CAP = 40
894
-
895
- export interface VerifyOptions {
896
- suppress?: WarningCode[]
897
- labelCharCap?: number
898
- }
899
-
900
- export type RenderedRegionKind = 'node' | 'edge' | 'label' | 'group' | 'canvas'
901
-
902
- export interface RenderedRegion {
903
- id: string
904
- kind: RenderedRegionKind
905
- elementId?: string
906
- parentId?: string
907
- bounds: { x: Finite; y: Finite; w: Finite; h: Finite }
908
- sourceLine?: number
909
- }
910
-
911
- export interface RenderedLayoutNode {
912
- id: NodeId; x: Finite; y: Finite; w: Finite; h: Finite; shape: string; label?: string
913
- }
914
- export interface RenderedLayoutEdge {
915
- id: EdgeId; from: NodeId; to: NodeId; path: [Finite, Finite][]
916
- label?: { x: Finite; y: Finite; text: string }
917
- /** Edge route certificate; present only under layoutMermaid(d, { debug: true }) for families with an edge certificate model. */
918
- route?: EdgeRouteCertificate
919
- }
920
- export interface RenderedLayoutGroup {
921
- id: GroupId; x: Finite; y: Finite; w: Finite; h: Finite; members: NodeId[]; label?: string
922
- /** Parent group id for flattened region-tree consumers; undefined means root-level group. */
923
- parentId?: GroupId
924
- }
925
- export interface RenderedLayout {
926
- version: 1
927
- kind: DiagramKind
928
- nodes: RenderedLayoutNode[]
929
- edges: RenderedLayoutEdge[]
930
- groups: RenderedLayoutGroup[]
931
- /** Region-containment certificates for non-edge invariants; present only under layoutMermaid(d, { debug: true }). */
932
- certificates?: RegionContainmentCertificate[]
933
- /** Optional region sidecar for renderer/action alignment; debug-only in layoutMermaid V1. */
934
- regions?: RenderedRegion[]
935
- /** Optional source-only actions aligned to region ids; debug-only in layoutMermaid V1. */
936
- actions?: DiagramActionRecord[]
937
- bounds: { w: Finite; h: Finite }
938
- }
939
-
940
- export interface VerifyResult {
941
- ok: boolean
942
- warnings: LayoutWarning[]
943
- layout: RenderedLayout
944
- }
945
-
946
- // ---- synthesizeFromGraph payload -----------------------------------------
947
-
948
- export interface SerializedFlowchartGraph {
949
- direction: import('../types.ts').Direction
950
- nodes: Record<string, import('../types.ts').MermaidNode> | Array<[string, import('../types.ts').MermaidNode]>
951
- edges?: import('../types.ts').MermaidEdge[]
952
- // Loose by design: payloads built from the SDK-declared shape may omit
953
- // `children`/`direction` on subgraphs, or styling maps entirely.
954
- // synthesizeFromGraph normalizes all of these defensively.
955
- subgraphs?: unknown
956
- classDefs?: unknown
957
- classAssignments?: unknown
958
- nodeStyles?: unknown
959
- linkStyles?: unknown
960
- }
961
-
962
- export interface ValidDiagramPayload {
963
- kind: DiagramKind
964
- meta?: Partial<ValidDiagramMeta>
965
- body:
966
- | { kind: 'flowchart'; graph: SerializedFlowchartGraph }
967
- | StateBody
968
- | SequenceBody
969
- | TimelineBody
970
- | ClassBody
971
- | ErBody
972
- | JourneyBody
973
- | ArchitectureBody
974
- | XyChartBody
975
- | PieBody
976
- | QuadrantBody
977
- | GanttBody
978
- | { kind: 'opaque'; family: DiagramKind; source: string }
979
- }