@diagrammo/dgmo 0.6.2 → 0.6.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 (44) hide show
  1. package/.claude/commands/dgmo.md +231 -13
  2. package/AGENTS.md +148 -0
  3. package/dist/cli.cjs +327 -153
  4. package/dist/index.cjs +305 -177
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +24 -3
  7. package/dist/index.d.ts +24 -3
  8. package/dist/index.js +303 -177
  9. package/dist/index.js.map +1 -1
  10. package/package.json +5 -3
  11. package/src/c4/layout.ts +0 -5
  12. package/src/c4/parser.ts +0 -16
  13. package/src/c4/renderer.ts +1 -5
  14. package/src/class/layout.ts +0 -1
  15. package/src/class/parser.ts +28 -0
  16. package/src/class/renderer.ts +5 -26
  17. package/src/cli.ts +563 -14
  18. package/src/completion.ts +58 -0
  19. package/src/d3.ts +58 -106
  20. package/src/dgmo-router.ts +0 -57
  21. package/src/echarts.ts +96 -55
  22. package/src/er/parser.ts +30 -1
  23. package/src/er/renderer.ts +1 -2
  24. package/src/graph/flowchart-parser.ts +27 -4
  25. package/src/graph/flowchart-renderer.ts +1 -2
  26. package/src/graph/state-parser.ts +0 -1
  27. package/src/graph/state-renderer.ts +1 -3
  28. package/src/index.ts +10 -0
  29. package/src/infra/compute.ts +0 -7
  30. package/src/infra/layout.ts +0 -2
  31. package/src/infra/parser.ts +46 -4
  32. package/src/infra/renderer.ts +1 -15
  33. package/src/initiative-status/renderer.ts +5 -25
  34. package/src/kanban/parser.ts +0 -2
  35. package/src/org/layout.ts +0 -4
  36. package/src/org/renderer.ts +7 -28
  37. package/src/sequence/parser.ts +14 -11
  38. package/src/sequence/renderer.ts +0 -2
  39. package/src/sequence/tag-resolution.ts +0 -1
  40. package/src/sitemap/layout.ts +1 -14
  41. package/src/sitemap/parser.ts +1 -2
  42. package/src/sitemap/renderer.ts +0 -3
  43. package/src/utils/arrows.ts +7 -7
  44. package/src/utils/export-container.ts +40 -0
@@ -4,7 +4,94 @@ You are helping the user author, render, and share diagrams using the `dgmo` CLI
4
4
 
5
5
  ## What is dgmo?
6
6
 
7
- `dgmo` is a CLI tool that renders `.dgmo` diagram files to PNG, SVG, or shareable URLs. Diagrams are written in a plain-text DSL.
7
+ `dgmo` is a CLI tool and library that renders `.dgmo` diagram files to PNG, SVG, or shareable URLs. Diagrams are written in a plain-text DSL.
8
+
9
+ ## Setup Check — Run This First
10
+
11
+ **Before doing anything else**, check whether the MCP tools are available in this session by attempting to call `mcp__dgmo__list_chart_types`. If that tool exists and succeeds, skip this section entirely.
12
+
13
+ If the MCP tools are **not** available, run the setup flow below — do not ask the user, just do it:
14
+
15
+ ### Step 1 — Install the CLI (if missing)
16
+
17
+ ```bash
18
+ which dgmo || npm install -g @diagrammo/dgmo
19
+ ```
20
+
21
+ ### Step 2 — Install the MCP server (if missing)
22
+
23
+ ```bash
24
+ which dgmo-mcp || npm install -g @diagrammo/dgmo-mcp
25
+ ```
26
+
27
+ ### Step 3 — Configure the MCP server
28
+
29
+ Ask the user:
30
+
31
+ > "Where should I configure the MCP server?
32
+ > 1) This project only — write `.mcp.json` here [default]
33
+ > 2) Globally — add to `~/.claude/settings.json` (works in all projects)"
34
+
35
+ **Option 1 (default):** Create or update `.mcp.json` in the current working directory:
36
+
37
+ ```json
38
+ {
39
+ "mcpServers": {
40
+ "dgmo": {
41
+ "command": "dgmo-mcp"
42
+ }
43
+ }
44
+ }
45
+ ```
46
+
47
+ If `.mcp.json` already exists and has other servers, merge the `dgmo` entry in — do not overwrite the file.
48
+
49
+ **Option 2 (global):** Add the `dgmo` entry to the `mcpServers` object in `~/.claude/settings.json`. Read the file first and merge — do not overwrite other keys.
50
+
51
+ ### Step 4 — Prompt restart
52
+
53
+ Tell the user:
54
+
55
+ > "Done. **Restart Claude Code** to activate the MCP server — diagram preview and rendering will be available in the next session."
56
+
57
+ Then proceed with the user's original request using CLI fallback (see "Other output options" below).
58
+
59
+ > **Note for future users:** To set up in one step from the terminal before starting a Claude Code session, run `dgmo --install-claude-code-integration`. It handles everything: installs `@diagrammo/dgmo-mcp`, writes the skill, and configures the MCP server.
60
+
61
+ ## Getting Syntax Help
62
+
63
+ **Always use the MCP tool first** if it's available in this session:
64
+
65
+ ```
66
+ mcp__dgmo__get_language_reference // full reference
67
+ mcp__dgmo__get_language_reference("sequence") // specific chart type
68
+ ```
69
+
70
+ This is the authoritative, always-up-to-date syntax reference. Use it before guessing syntax.
71
+
72
+ ## Your Workflow
73
+
74
+ **Primary goal: get the user seeing a visualization as fast as possible.**
75
+
76
+ When the user asks you to create or edit a diagram:
77
+
78
+ 1. **Get syntax** — call `mcp__dgmo__get_language_reference("<type>")` if you're unsure of the syntax.
79
+ 2. **Write the `.dgmo` content** — compose the markup.
80
+ 3. **Open in browser immediately** — call `mcp__dgmo__preview_diagram([{dgmo, title}])` without asking. This is always the right default. The browser preview includes the dgmo source collapsed at the bottom and a dark/light toggle.
81
+ 4. **Save the source file** (if working in a project) — write it to `<name>.dgmo` so the user has an editable copy.
82
+
83
+ Do not ask the user how they want to view the diagram. Just open it. They can ask for other formats if they want.
84
+
85
+ ### Other output options (only when explicitly requested)
86
+
87
+ | What the user wants | How to do it |
88
+ |---|---|
89
+ | **Quick look in the desktop app** | `mcp__dgmo__open_in_app(dgmo)` — opens directly in Diagrammo (macOS) |
90
+ | **View in macOS Preview** | `mcp__dgmo__render_diagram(dgmo, format:"png", theme:"dark", palette:"nord")` → get temp path → `open <path>` |
91
+ | **Save as PNG** | `mcp__dgmo__render_diagram(dgmo, format:"png", theme:"dark", palette:"nord")` → returns temp path; offer to copy to their preferred location. Or CLI: `dgmo file.dgmo -o out.png --theme dark --palette nord` |
92
+ | **Save as SVG** | `mcp__dgmo__render_diagram(dgmo, format:"svg", theme:"dark", palette:"nord")` returns SVG text — write it to the desired path. Or CLI: `dgmo file.dgmo -o out.svg --theme dark --palette nord` |
93
+ | **Shareable URL** | `mcp__dgmo__share_diagram(dgmo)` → returns a URL; immediately run `open <url>` — do NOT just display the URL |
94
+ | **Copy markup to clipboard** | Run `echo '<dgmo markup>' \| pbcopy` |
8
95
 
9
96
  ## CLI Reference
10
97
 
@@ -45,32 +132,163 @@ Key options:
45
132
  | `quadrant` | 2x2 positioning matrix |
46
133
  | `sequence` | Message / interaction flows |
47
134
  | `flowchart` | Decision trees, process flows |
135
+ | `state` | State machine / lifecycle |
48
136
  | `class` | UML class hierarchies |
49
137
  | `er` | Database schemas |
50
138
  | `org` | Hierarchical tree structures |
51
139
  | `kanban` | Task / workflow columns |
52
140
  | `c4` | System architecture (context → container → component → deployment) |
53
141
  | `initiative-status` | Project roadmap with dependency tracking |
142
+ | `sitemap` | Website / app navigation structure |
143
+ | `infra` | Infrastructure traffic flow with rps computation |
54
144
 
55
- ## Your Workflow
145
+ ## Key Syntax Patterns
56
146
 
57
- When the user asks you to create or edit a diagram:
147
+ ### Common to all diagrams
58
148
 
59
- 1. **Write or edit the `.dgmo` file** with the appropriate chart type and data.
60
- 2. **Render it** with `dgmo <file>.dgmo -o <file>.png` to verify it produces output without errors.
61
- 3. **Show the user** what was created and suggest a shareable URL with `dgmo <file>.dgmo -o url --copy` if they want to share it.
149
+ ```
150
+ chart: sequence // explicit type (optional auto-detected)
151
+ title: My Diagram
152
+ palette: catppuccin // override palette
62
153
 
63
- When the user asks for a **shareable link**, run:
154
+ // This is a comment (only // syntax — not #)
64
155
  ```
65
- dgmo <file>.dgmo -o url --copy
156
+
157
+ Inline colors on most elements: append `(colorname)` — e.g. `North(red): 850`, `[Process(blue)]`.
158
+ Named colors: `red`, `orange`, `yellow`, `green`, `blue`, `purple`, `teal`, `cyan`, `gray`.
159
+
160
+ ### sequence (most commonly used)
161
+
66
162
  ```
163
+ chart: sequence
164
+ title: Auth Flow
67
165
 
68
- ## Getting Syntax Help
166
+ // Participants auto-inferred, or declare explicitly:
167
+ User is an actor
168
+ API is a service
169
+ DB is a database
170
+
171
+ User -Login-> API
172
+ API -Find user-> DB
173
+ DB -user record-> API
174
+ note:
175
+ Indexed lookup on email column
176
+
177
+ if credentials valid
178
+ API -200 OK + token-> User
179
+ else
180
+ API -401 Unauthorized-> User
181
+
182
+ == Logout ==
183
+
184
+ note: session cleanup
185
+ User -Logout-> API
186
+ API -Delete session-> DB
187
+ ```
188
+
189
+ - Sync: `A -label-> B` · Async: `A ~label~> B` · Unlabeled: `A -> B`
190
+ - Blocks: `if` / `else`, `loop`, `parallel` — closed by indentation (no `end` keyword)
191
+ - Notes: place `note: text` after a message — it naturally associates with that position. Prefer this over `note on Participant:` anchoring; it's more compact and reads better.
192
+ - Single-line: `note: text`
193
+ - Multi-line: `note:` then indent continuation lines beneath it
194
+ - Sections: `== Title ==`
195
+ - Groups: `[Group Name]` with indented participants
196
+
197
+ ### flowchart
198
+
199
+ ```
200
+ (Start) -> <Valid Input?>
201
+ -yes-> [Process Data] -> (Done)
202
+ -no-> /Get Input/ -> <Valid Input?>
203
+ ```
204
+
205
+ Shapes: `(oval)` `[rect]` `<diamond>` `/parallelogram/` `[[subroutine]]` `[document~]`
206
+
207
+ ### bar / line / pie (data charts)
208
+
209
+ ```
210
+ // bar
211
+ title: Revenue by Region
212
+ series: Revenue
213
+ North: 850
214
+ South: 620
215
+
216
+ // line (multi-series)
217
+ series: Sales(red), Costs(blue)
218
+ Q1: 100, 50
219
+ Q2: 120, 55
69
220
 
70
- Run `dgmo --chart-types` to list types. For detailed syntax of a specific chart type, the best reference is the diagrammo.app documentation or existing `.dgmo` files in the project.
221
+ // pie
222
+ chart: pie
223
+ labels: percent
224
+ Company A: 40
225
+ Company B: 35
226
+ ```
227
+
228
+ ### er
229
+
230
+ ```
231
+ users
232
+ id: int [pk]
233
+ email: varchar [unique]
234
+ 1-writes-* posts
235
+
236
+ posts
237
+ id: int [pk]
238
+ author_id: int [fk]
239
+ ```
240
+
241
+ ### org
242
+
243
+ ```
244
+ CEO
245
+ VP Engineering
246
+ [Platform Team]
247
+ Lead
248
+ Dev 1
249
+ Dev 2
250
+ VP Marketing
251
+ ```
252
+
253
+ ### infra
254
+
255
+ ```
256
+ chart: infra
257
+ edge
258
+ rps: 10000
259
+ -> CDN
260
+
261
+ CDN
262
+ cache-hit: 80%
263
+ -> API
264
+
265
+ API
266
+ instances: 3
267
+ max-rps: 500
268
+ latency-ms: 45
269
+ ```
270
+
271
+ ## Anti-Patterns
272
+
273
+ ```
274
+ # comment ❌ use // comment
275
+ async A -> B: msg ❌ use A ~msg~> B
276
+ A <- B ❌ left-pointing arrows removed — use B -> A
277
+ parallel else ❌ not supported — use separate parallel blocks
278
+ == Foo(#ff0000) == ❌ hex colors not supported — use named colors: == Foo(red) ==
279
+ A -routes to /api-> B ❌ -> inside a label is ambiguous — rephrase the label
280
+ end ❌ not needed — indentation closes blocks in sequence diagrams
281
+ note on API: text ⚠️ prefer plain `note: text` after a message — anchoring to a participant is rarely needed
282
+ note: line1\nline2 ❌ multi-line notes use indented continuation, not \n:
283
+ note:
284
+ line1
285
+ line2
286
+ ```
71
287
 
72
288
  ## Tips
73
289
 
74
- - Default theme is `light` and default palette is `nord` ask the user if they have a preference before rendering a final export.
75
- - For C4 diagrams, use `--c4-level` to drill from context → containers → components → deployment.
76
- - Stdin mode is useful for quick one-off renders: `echo "..." | dgmo -o out.png`
290
+ - Default theme: `dark`, default palette: `nord` (nord dark mode) use these unless the user requests otherwise.
291
+ - Stdin mode for quick renders: `echo "..." | dgmo -o out.png`
292
+ - For C4, `--c4-level` drills from context containers components deployment.
293
+ - When auto-detection picks the wrong chart type, add an explicit `chart:` directive.
294
+ - `mcp__dgmo__preview_diagram` accepts multiple diagrams at once — useful for showing variants side by side.
package/AGENTS.md ADDED
@@ -0,0 +1,148 @@
1
+ # DGMO Diagram Language — Codex Integration
2
+
3
+ Use dgmo tools to create, render, and share diagrams. dgmo is a text-based diagram markup language that renders to SVG/PNG.
4
+
5
+ ## Quick setup
6
+
7
+ If the MCP server is not yet configured:
8
+
9
+ ```bash
10
+ dgmo --install-codex-integration
11
+ ```
12
+
13
+ This installs the MCP server and writes the dgmo config to `.codex/config.toml`. Restart Codex to activate.
14
+
15
+ ## MCP Tools
16
+
17
+ When the `dgmo` MCP server is configured, use these tools directly:
18
+ - `preview_diagram` — renders diagram(s) and opens a live HTML preview in the browser (default for showing diagrams)
19
+ - `render_diagram` — renders to PNG or SVG, returns file path
20
+ - `share_diagram` — creates a shareable diagrammo.app URL
21
+ - `open_in_app` — opens diagram in Diagrammo desktop app (macOS)
22
+ - `list_chart_types` — lists all 32 supported chart types with descriptions
23
+ - `get_language_reference` — fetches full syntax for any chart type (call this before generating an unfamiliar chart type)
24
+ - `generate_report` — renders multiple diagrams into an HTML report with table of contents
25
+
26
+ ## When to use dgmo
27
+
28
+ - Architecture diagrams, sequence diagrams, flowcharts
29
+ - Data charts (bar, line, pie, scatter, heatmap, etc.)
30
+ - ER diagrams, class diagrams, org charts
31
+ - Project roadmaps, kanban boards, timelines
32
+
33
+ ## Quick syntax reference
34
+
35
+ ### Sequence diagram
36
+ ```
37
+ chart: sequence
38
+ title: Auth Flow
39
+
40
+ User -Login-> API
41
+ API -Find user-> DB
42
+ DB -user-> API
43
+ if valid
44
+ API -200 OK-> User
45
+ else
46
+ API -401-> User
47
+ ```
48
+
49
+ ### Flowchart
50
+ ```
51
+ chart: flowchart
52
+ title: Process
53
+
54
+ (Start) -> <Valid?>
55
+ -yes-> [Process] -> (Done)
56
+ -no-> /Get Input/ -> <Valid?>
57
+ ```
58
+
59
+ ### Bar chart
60
+ ```
61
+ chart: bar
62
+ title: Revenue
63
+ series: USD
64
+
65
+ North: 850
66
+ South: 620
67
+ East: 1100
68
+ ```
69
+
70
+ ### ER diagram
71
+ ```
72
+ chart: er
73
+ title: Schema
74
+
75
+ users
76
+ id: int [pk]
77
+ email: varchar [unique]
78
+
79
+ posts
80
+ id: int [pk]
81
+ user_id: int [fk]
82
+
83
+ users 1--* posts : writes
84
+ ```
85
+
86
+ ### Org chart
87
+ ```
88
+ chart: org
89
+
90
+ CEO
91
+ VP Engineering
92
+ Team Lead A
93
+ Team Lead B
94
+ VP Marketing
95
+ ```
96
+
97
+ ### Infra chart
98
+ ```
99
+ chart: infra
100
+ direction: LR
101
+
102
+ edge
103
+ rps: 10000
104
+ -> CDN
105
+
106
+ CDN
107
+ cache-hit: 80%
108
+ -> LB
109
+
110
+ LB
111
+ -> API | split: 70%
112
+ -> Web | split: 30%
113
+
114
+ API
115
+ instances: 3
116
+ max-rps: 500
117
+ latency-ms: 45
118
+ ```
119
+
120
+ ## All 32 chart types
121
+
122
+ bar, line, multi-line, area, pie, doughnut, radar, polar-area, bar-stacked, scatter, sankey, chord, function, heatmap, funnel, slope, wordcloud, arc, timeline, venn, quadrant, sequence, flowchart, state, class, er, org, kanban, c4, initiative-status, sitemap, infra
123
+
124
+ ## Common patterns
125
+
126
+ - `chart: type` — explicit chart type (auto-detected if unambiguous)
127
+ - `title: text` — diagram title
128
+ - `// comment` — only `//` comments (not `#`)
129
+ - `(colorname)` — inline colors: `Label(red): 100`
130
+ - `series: A(red), B(blue)` — multi-series with colors
131
+
132
+ ## Rendering via CLI
133
+
134
+ ```bash
135
+ dgmo file.dgmo -o output.svg # SVG
136
+ dgmo file.dgmo -o url # shareable link
137
+ dgmo file.dgmo --json # structured JSON output
138
+ ```
139
+
140
+ ## Mistakes to avoid
141
+
142
+ - Don't use `#` for comments — use `//`
143
+ - Don't use `end` to close sequence blocks — indentation closes them
144
+ - Don't use hex colors in section headers — use named colors
145
+ - Don't forget `chart:` directive when content is ambiguous
146
+ - Sequence arrows: `->` (sync), `~>` (async) — always left-to-right
147
+
148
+ Full reference: call `get_language_reference` MCP tool or visit diagrammo.app/docs