@senad-d/drawme 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.
- package/README.md +6 -0
- package/docs/agent-guide.md +519 -0
- package/package.json +13 -6
- package/src/index.ts +4 -2
- package/src/workflow.ts +6 -2
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ DrawMe is a native Pi **extension** that exposes the diagram-authoring workflow
|
|
|
42
42
|
## Table of Contents
|
|
43
43
|
|
|
44
44
|
- [Implementation Status](#implementation-status)
|
|
45
|
+
- [Agent Reference](#agent-reference)
|
|
45
46
|
- [Quick Start](#quick-start)
|
|
46
47
|
- [Installation](#installation)
|
|
47
48
|
- [Commands](#commands)
|
|
@@ -68,6 +69,10 @@ This checkout implements the DrawMe core loop as a Pi extension:
|
|
|
68
69
|
- draw.io binary resolution across macOS/Linux/Windows/WSL, headless-Linux `xvfb-run` handling, and version-gated Mermaid conversion + ELK auto-layout (draw.io v30+).
|
|
69
70
|
- Validation pipeline: golden asset-integrity check, TypeScript typecheck, ESLint, a custom format check, and unit + real-CLI integration tests.
|
|
70
71
|
|
|
72
|
+
## Agent Reference
|
|
73
|
+
|
|
74
|
+
[`docs/agent-guide.md`](docs/agent-guide.md) is the official operational reference for AI agents. It documents every command, tool option, default, authoring mode, workflow, output behavior, and functional limitation. The `/drawme` command instructs the agent to read this packaged reference before starting.
|
|
75
|
+
|
|
71
76
|
## Quick Start
|
|
72
77
|
|
|
73
78
|
### 1) Install the draw.io desktop CLI
|
|
@@ -176,6 +181,7 @@ The extension factory in `src/index.ts` only registers tools and commands. Each
|
|
|
176
181
|
|
|
177
182
|
The model reads these on demand; all are network-free and ship in the package.
|
|
178
183
|
|
|
184
|
+
- `docs/agent-guide.md` — official agent-facing command, tool, option, workflow, output, and limitation reference.
|
|
179
185
|
- `assets/references/xml-authoring.md` — `.drawio` skeleton, cell/edge forms, containers, palette, spacing.
|
|
180
186
|
- `assets/references/diagram-types.md` — per-type presets (ERD, UML, sequence, C4, architecture, ML, flowchart, SysML, BPMN, network, swimlane).
|
|
181
187
|
- `assets/references/mermaid-authoring.md` — Mermaid authoring for the v30+ conversion path.
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
# DrawMe Extension Agent Reference
|
|
2
|
+
|
|
3
|
+
> Official operational reference for AI agents using the DrawMe Pi extension.
|
|
4
|
+
|
|
5
|
+
DrawMe turns diagram requirements into editable `.drawio` sources and local PNG, SVG, PDF, or JPG exports. The extension provides commands that start guided workflows and tools for CLI detection, Mermaid conversion, XML layout, structural validation, shape lookup, export, explanation, and file opening.
|
|
6
|
+
|
|
7
|
+
This document defines the extension's public functionality, options, defaults, decision rules, and expected agent behavior.
|
|
8
|
+
|
|
9
|
+
## Core operating rules
|
|
10
|
+
|
|
11
|
+
1. Treat the `.drawio` file as the source of truth. Exports are derived artifacts.
|
|
12
|
+
2. Call `drawio_check` once before conversion, layout, preview, or final export.
|
|
13
|
+
3. Use DrawMe tools for draw.io CLI operations; do not invoke `drawio` through a shell.
|
|
14
|
+
4. Use `drawio_shapesearch` instead of guessing official shape styles.
|
|
15
|
+
5. Keep hand-authored XML uncompressed and structurally valid.
|
|
16
|
+
6. Run `drawio_validate` and fix all errors before export.
|
|
17
|
+
7. Use `drawio_export` with `mode: "preview"` for visual inspection and `mode: "final"` for deliverables.
|
|
18
|
+
8. Inspect every tool's text result. Several tools return failure text rather than throwing a tool-call error.
|
|
19
|
+
9. Offer `drawio_open` for manual fine-tuning; call it only when the user wants a desktop application opened.
|
|
20
|
+
|
|
21
|
+
DrawMe performs all extension operations locally. It does not provide network-based rendering, icon downloads, or browser fallbacks.
|
|
22
|
+
|
|
23
|
+
## Functional availability
|
|
24
|
+
|
|
25
|
+
| Functionality | draw.io CLI required | draw.io 30+ required |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| Write or edit uncompressed `.drawio` XML with normal file tools | No | No |
|
|
28
|
+
| `drawio_validate` | No | No |
|
|
29
|
+
| `drawio_shapesearch` | No | No |
|
|
30
|
+
| `drawio_explain` | No | No |
|
|
31
|
+
| `drawio_open` | No CLI check; requires an OS file handler | No |
|
|
32
|
+
| `drawio_export` | Yes | No |
|
|
33
|
+
| `drawio_from_mermaid` | Yes | Yes |
|
|
34
|
+
| `drawio_layout` | Yes | Yes |
|
|
35
|
+
|
|
36
|
+
When the CLI is unavailable, an agent can still author, edit, validate, explain, and search for shapes. It must skip conversion, layout, preview, and final export.
|
|
37
|
+
|
|
38
|
+
When the CLI is older than version 30, export remains available. Mermaid conversion and ELK layout do not.
|
|
39
|
+
|
|
40
|
+
## Commands
|
|
41
|
+
|
|
42
|
+
Commands are user-facing shortcuts. Agents should use model-callable tools when they need explicit options or structured results.
|
|
43
|
+
|
|
44
|
+
| Command | Functionality |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `/drawme <description>` | Starts the full diagram creation workflow: check, plan, author, validate, preview, review, and final export. |
|
|
47
|
+
| `/drawme-check` | Displays the detected draw.io path and version, or reports that the CLI is unavailable. |
|
|
48
|
+
| `/drawme-export <file> [png\|svg\|pdf\|jpg]` | Performs a final export of an existing `.drawio`; format defaults to PNG. |
|
|
49
|
+
|
|
50
|
+
`/drawme-export` intentionally exposes only the source path and format. Use `drawio_export` for output naming, dimensions, border, transparency, embedding, page selection, or binary selection. The command uses whitespace-separated arguments and is unsuitable for paths containing spaces.
|
|
51
|
+
|
|
52
|
+
## Tools
|
|
53
|
+
|
|
54
|
+
DrawMe registers eight model-callable tools.
|
|
55
|
+
|
|
56
|
+
### `drawio_check`
|
|
57
|
+
|
|
58
|
+
Detects the draw.io desktop CLI, its version, and version-gated features.
|
|
59
|
+
|
|
60
|
+
#### Options
|
|
61
|
+
|
|
62
|
+
| Option | Type | Required | Description |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `binary` | string | No | Explicit binary path to test first. Standard platform candidates are tried afterward if it fails. |
|
|
65
|
+
|
|
66
|
+
#### Result behavior
|
|
67
|
+
|
|
68
|
+
A successful result includes:
|
|
69
|
+
|
|
70
|
+
- `available: true`;
|
|
71
|
+
- resolved `binary` path or command;
|
|
72
|
+
- `version` and numeric `major` version;
|
|
73
|
+
- `supportsMermaid` and `supportsLayout` flags.
|
|
74
|
+
|
|
75
|
+
An unavailable result includes `available: false` and guidance that XML authoring can continue without export.
|
|
76
|
+
|
|
77
|
+
#### Use
|
|
78
|
+
|
|
79
|
+
Call once at the start of any workflow that may use conversion, layout, preview, or export.
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
drawio_check({})
|
|
83
|
+
drawio_check({ "binary": "/custom/path/to/drawio" })
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### `drawio_export`
|
|
89
|
+
|
|
90
|
+
Exports an existing `.drawio` through the local draw.io desktop CLI.
|
|
91
|
+
|
|
92
|
+
#### Options
|
|
93
|
+
|
|
94
|
+
| Option | Type | Required | Default | Description |
|
|
95
|
+
| --- | --- | --- | --- | --- |
|
|
96
|
+
| `input` | string | Yes | — | Existing `.drawio` source path. |
|
|
97
|
+
| `format` | `png` \| `svg` \| `pdf` \| `jpg` | No | `png` | Output format. |
|
|
98
|
+
| `mode` | `preview` \| `final` | No | `final` | Selects inspection or deliverable defaults. |
|
|
99
|
+
| `output` | string | No | Derived beside input | Explicit output path. |
|
|
100
|
+
| `scale` | number | No | `2` | Scale for final PNG/JPG when `width` is absent. |
|
|
101
|
+
| `width` | number | No | Preview: `2000` | Target width in pixels. Overrides `scale`. |
|
|
102
|
+
| `transparent` | boolean | No | `false` | Enables transparency for PNG only. |
|
|
103
|
+
| `border` | number | No | `10` | Export border in pixels. Use `0` for no border. |
|
|
104
|
+
| `pageIndex` | number | No | draw.io default | Positive, 1-based page number for multi-page files. |
|
|
105
|
+
| `embed` | boolean | No | Mode/format dependent | Controls embedding of editable diagram XML. |
|
|
106
|
+
| `binary` | string | No | Auto-detected | Explicit binary path to test first. |
|
|
107
|
+
|
|
108
|
+
#### Mode and naming behavior
|
|
109
|
+
|
|
110
|
+
For an input named `name.drawio`:
|
|
111
|
+
|
|
112
|
+
| Export | Default output | Raster sizing | Embedded XML |
|
|
113
|
+
| --- | --- | --- | --- |
|
|
114
|
+
| Preview PNG | `name.png` | Width 2000 | No |
|
|
115
|
+
| Final PNG | `name.drawio.png` | Scale 2 | Yes |
|
|
116
|
+
| Final SVG | `name.svg` | Vector | Yes |
|
|
117
|
+
| Final PDF | `name.pdf` | Vector | Yes |
|
|
118
|
+
| Final JPG | `name.jpg` | Scale 2 | No |
|
|
119
|
+
|
|
120
|
+
Additional behavior:
|
|
121
|
+
|
|
122
|
+
- An explicit `output` replaces the derived name.
|
|
123
|
+
- An explicit `width` replaces raster scaling.
|
|
124
|
+
- `scale` is ignored in preview mode and for vector formats.
|
|
125
|
+
- `transparent` has no effect outside PNG.
|
|
126
|
+
- Preview mode defaults to unembedded output suitable for vision inspection.
|
|
127
|
+
- Final PNG, SVG, and PDF default to embedded/editable output.
|
|
128
|
+
- JPG cannot carry editable XML; never set `embed: true` for JPG.
|
|
129
|
+
- Embedded PNG exports are checked for draw.io's known truncated IEND chunk and repaired automatically when necessary.
|
|
130
|
+
- Headless Linux handling is automatic, including `xvfb-run`, GPU disabling, and the root sandbox flag.
|
|
131
|
+
|
|
132
|
+
#### Use
|
|
133
|
+
|
|
134
|
+
```text
|
|
135
|
+
# Vision-safe inspection artifact
|
|
136
|
+
drawio_export({ "input": "architecture.drawio", "mode": "preview" })
|
|
137
|
+
|
|
138
|
+
# Editable final SVG
|
|
139
|
+
drawio_export({
|
|
140
|
+
"input": "architecture.drawio",
|
|
141
|
+
"format": "svg",
|
|
142
|
+
"mode": "final"
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
# A specific page with an unambiguous path
|
|
146
|
+
drawio_export({
|
|
147
|
+
"input": "system.drawio",
|
|
148
|
+
"format": "pdf",
|
|
149
|
+
"mode": "final",
|
|
150
|
+
"pageIndex": 2,
|
|
151
|
+
"output": "system-page-2.pdf"
|
|
152
|
+
})
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Use a distinct `output` for each format or page. Never present a preview artifact as the final deliverable when a final export was requested.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### `drawio_validate`
|
|
160
|
+
|
|
161
|
+
Structurally lints uncompressed `.drawio` XML without launching draw.io.
|
|
162
|
+
|
|
163
|
+
#### Options
|
|
164
|
+
|
|
165
|
+
| Option | Type | Required | Description |
|
|
166
|
+
| --- | --- | --- | --- |
|
|
167
|
+
| `input` | string | Yes | Path to the `.drawio` file. |
|
|
168
|
+
|
|
169
|
+
#### Checks
|
|
170
|
+
|
|
171
|
+
Errors include:
|
|
172
|
+
|
|
173
|
+
- duplicate cell IDs;
|
|
174
|
+
- vertices or edges reusing reserved root IDs `0` or `1`;
|
|
175
|
+
- references to missing parents;
|
|
176
|
+
- edge references to missing sources or targets;
|
|
177
|
+
- missing or invalid vertex geometry.
|
|
178
|
+
|
|
179
|
+
Warnings include:
|
|
180
|
+
|
|
181
|
+
- non-positive vertex dimensions;
|
|
182
|
+
- negative vertex positions;
|
|
183
|
+
- overlapping sibling leaf vertices;
|
|
184
|
+
- explicitly waypointed edges routed through unrelated vertices;
|
|
185
|
+
- explicitly waypointed edges crossing one another;
|
|
186
|
+
- compressed pages that cannot be inspected.
|
|
187
|
+
|
|
188
|
+
The result also includes a readability score:
|
|
189
|
+
|
|
190
|
+
- route through vertex: 20 points;
|
|
191
|
+
- edge crossing: 10 points;
|
|
192
|
+
- overlap: 5 points.
|
|
193
|
+
|
|
194
|
+
Lower is better, but scores are meaningful only when comparing layout variants of the same graph.
|
|
195
|
+
|
|
196
|
+
#### Use
|
|
197
|
+
|
|
198
|
+
Fix every error and rerun validation. Investigate warnings before preview.
|
|
199
|
+
|
|
200
|
+
```text
|
|
201
|
+
drawio_validate({ "input": "architecture.drawio" })
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Validation is structural rather than visual. It cannot guarantee readable labels, correct semantic content, valid rendering of a guessed shape, color contrast, visual balance, or clear auto-routed edges. It does not replace preview inspection.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
### `drawio_from_mermaid`
|
|
209
|
+
|
|
210
|
+
Converts Mermaid into an automatically laid-out, editable native `.drawio`. Requires draw.io 30 or newer.
|
|
211
|
+
|
|
212
|
+
#### Options
|
|
213
|
+
|
|
214
|
+
| Option | Type | Required | Default | Description |
|
|
215
|
+
| --- | --- | --- | --- | --- |
|
|
216
|
+
| `mermaid` | string | One of `mermaid`/`input` | — | Inline Mermaid text. A temporary `.mmd` is removed after conversion. |
|
|
217
|
+
| `input` | string | One of `mermaid`/`input` | — | Existing `.mmd` source path. |
|
|
218
|
+
| `output` | string | No | See below | Destination `.drawio` path. |
|
|
219
|
+
| `binary` | string | No | Auto-detected | Explicit binary path to test first. |
|
|
220
|
+
|
|
221
|
+
Output defaults:
|
|
222
|
+
|
|
223
|
+
- file input: same directory and stem with `.drawio`;
|
|
224
|
+
- inline Mermaid: `diagram.drawio` in the current working directory.
|
|
225
|
+
|
|
226
|
+
Provide exactly one of `mermaid` or `input`. Normally provide `output` explicitly to avoid ambiguous names or accidental replacement.
|
|
227
|
+
|
|
228
|
+
#### Best use
|
|
229
|
+
|
|
230
|
+
Use for standard structure-first diagrams without precise draw.io styling requirements, including:
|
|
231
|
+
|
|
232
|
+
- flowcharts;
|
|
233
|
+
- sequence diagrams;
|
|
234
|
+
- class diagrams;
|
|
235
|
+
- state diagrams;
|
|
236
|
+
- ER diagrams;
|
|
237
|
+
- gantt charts;
|
|
238
|
+
- mind maps.
|
|
239
|
+
|
|
240
|
+
Do not choose Mermaid conversion when the requested artifact needs official vendor icons, exact UML/BPMN styles, custom containers or swimlanes, precise coordinates, explicit edge waypoints, or multi-page drill-down behavior.
|
|
241
|
+
|
|
242
|
+
The conversion already lays out the graph. Never run `drawio_layout` afterward.
|
|
243
|
+
|
|
244
|
+
```text
|
|
245
|
+
drawio_from_mermaid({
|
|
246
|
+
"mermaid": "flowchart LR\n A[Client] --> B[API]\n B --> C[(Database)]",
|
|
247
|
+
"output": "request-flow.drawio"
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Continue with validation, preview, visual inspection, and final export.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
### `drawio_layout`
|
|
256
|
+
|
|
257
|
+
Repositions nodes and routes edges in an XML-authored `.drawio` using a safe ELK preset. Requires draw.io 30 or newer.
|
|
258
|
+
|
|
259
|
+
#### Options
|
|
260
|
+
|
|
261
|
+
| Option | Type | Required | Default | Description |
|
|
262
|
+
| --- | --- | --- | --- | --- |
|
|
263
|
+
| `input` | string | Yes | — | Existing `.drawio` source. |
|
|
264
|
+
| `preset` | layout preset | Yes | — | One of the six allowlisted values below. |
|
|
265
|
+
| `output` | string | No | `<name>.layout.drawio` | Destination path beside the input. May equal `input` for intentional in-place layout. |
|
|
266
|
+
| `binary` | string | No | Auto-detected | Explicit binary path to test first. |
|
|
267
|
+
|
|
268
|
+
#### Presets
|
|
269
|
+
|
|
270
|
+
| Preset | Functionality |
|
|
271
|
+
| --- | --- |
|
|
272
|
+
| `verticalFlow` | Layered top-to-bottom process or pipeline layout. |
|
|
273
|
+
| `horizontalFlow` | Layered left-to-right process or pipeline layout. |
|
|
274
|
+
| `verticalTree` | Top-to-bottom hierarchy or org-chart layout. |
|
|
275
|
+
| `horizontalTree` | Left-to-right hierarchy layout. |
|
|
276
|
+
| `radialTree` | Tree arranged around a center. |
|
|
277
|
+
| `organic` | Force-directed network or mind-map-like layout. |
|
|
278
|
+
|
|
279
|
+
Use this tool for large or graph-heavy hand-authored XML, typically above approximately 15 nodes. Unknown presets are rejected because unsupported values can open a modal dialog and hang a headless process.
|
|
280
|
+
|
|
281
|
+
```text
|
|
282
|
+
drawio_layout({
|
|
283
|
+
"input": "services-rough.drawio",
|
|
284
|
+
"preset": "horizontalFlow",
|
|
285
|
+
"output": "services.drawio"
|
|
286
|
+
})
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
After layout, treat the returned output path as the current source and validate it again. Do not apply this tool to Mermaid-converted diagrams.
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
### `drawio_shapesearch`
|
|
294
|
+
|
|
295
|
+
Searches a bundled local index of more than 10,000 official draw.io shapes.
|
|
296
|
+
|
|
297
|
+
#### Options
|
|
298
|
+
|
|
299
|
+
| Option | Type | Required | Default | Description |
|
|
300
|
+
| --- | --- | --- | --- | --- |
|
|
301
|
+
| `query` | string | Yes | — | Shape keywords such as `aws lambda`, `uml actor`, `bpmn timer event`, or `k8s pod`. |
|
|
302
|
+
| `limit` | number | No | `10` | Maximum number of ranked results. |
|
|
303
|
+
|
|
304
|
+
Each result contains:
|
|
305
|
+
|
|
306
|
+
- official shape title;
|
|
307
|
+
- exact draw.io `style=` string;
|
|
308
|
+
- recommended width and height.
|
|
309
|
+
|
|
310
|
+
Copy the selected style exactly and start with the returned dimensions. If the top result is not correct, search again with more specific vendor, notation, and component terms. The index contains official draw.io library shapes; it does not retrieve third-party logos.
|
|
311
|
+
|
|
312
|
+
```text
|
|
313
|
+
drawio_shapesearch({ "query": "aws lambda", "limit": 5 })
|
|
314
|
+
drawio_shapesearch({ "query": "bpmn exclusive gateway" })
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
### `drawio_explain`
|
|
320
|
+
|
|
321
|
+
Reads a `.drawio` and returns a structured Markdown description without launching draw.io.
|
|
322
|
+
|
|
323
|
+
#### Options
|
|
324
|
+
|
|
325
|
+
| Option | Type | Required | Description |
|
|
326
|
+
| --- | --- | --- | --- |
|
|
327
|
+
| `input` | string | Yes | Path to the `.drawio` file. |
|
|
328
|
+
|
|
329
|
+
The result:
|
|
330
|
+
|
|
331
|
+
- lists leaf components;
|
|
332
|
+
- groups components by named container;
|
|
333
|
+
- lists relations between labeled endpoints;
|
|
334
|
+
- uses edge labels as relation verbs;
|
|
335
|
+
- produces a separate section for each page.
|
|
336
|
+
|
|
337
|
+
Use it to understand an existing diagram before editing, verify high-level structure, or create documentation text. It returns Markdown in the tool result but does not create a Markdown file.
|
|
338
|
+
|
|
339
|
+
Compressed pages cannot be explained.
|
|
340
|
+
|
|
341
|
+
```text
|
|
342
|
+
drawio_explain({ "input": "current-architecture.drawio" })
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Explanation is a structural summary, not a validator and not a visual renderer.
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
### `drawio_open`
|
|
350
|
+
|
|
351
|
+
Opens a local `.drawio` source or exported file with the operating system's default application.
|
|
352
|
+
|
|
353
|
+
#### Options
|
|
354
|
+
|
|
355
|
+
| Option | Type | Required | Description |
|
|
356
|
+
| --- | --- | --- | --- |
|
|
357
|
+
| `path` | string | Yes | Existing local file to open. |
|
|
358
|
+
|
|
359
|
+
Platform behavior:
|
|
360
|
+
|
|
361
|
+
- macOS: `open`;
|
|
362
|
+
- Windows: `start`;
|
|
363
|
+
- Linux: `xdg-open`.
|
|
364
|
+
|
|
365
|
+
Use it when the user requests desktop review or accepts an offer to fine-tune the source manually. Opening an application is a user-visible side effect.
|
|
366
|
+
|
|
367
|
+
```text
|
|
368
|
+
drawio_open({ "path": "architecture.drawio" })
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## Authoring-mode selection
|
|
372
|
+
|
|
373
|
+
| Requirement | Recommended path |
|
|
374
|
+
| --- | --- |
|
|
375
|
+
| Standard diagram with no custom styling and CLI 30+ | Mermaid → `drawio_from_mermaid`. |
|
|
376
|
+
| Vendor icons, exact UML/BPMN notation, custom styling, swimlanes, containers, precise routing, or multi-page output | Hand-authored uncompressed XML plus `drawio_shapesearch`. |
|
|
377
|
+
| Large hand-authored graph and CLI 30+ | Rough XML → `drawio_layout`. |
|
|
378
|
+
| CLI unavailable or older than 30 | Hand-authored XML; validation and shape search remain available. |
|
|
379
|
+
| Existing diagram must be understood | `drawio_explain`, then inspect the source XML. |
|
|
380
|
+
| Existing diagram only needs validation | `drawio_validate`; no CLI check is necessary. |
|
|
381
|
+
| Existing diagram only needs export | `drawio_check` → `drawio_export`; do not rebuild it. |
|
|
382
|
+
|
|
383
|
+
DrawMe does not expose a single natural-language-to-file tool. The agent authors or edits Mermaid/XML with normal file tools, then uses DrawMe for conversion, layout, validation, rendering, explanation, or opening.
|
|
384
|
+
|
|
385
|
+
## Creation workflow
|
|
386
|
+
|
|
387
|
+
### 1. Check
|
|
388
|
+
|
|
389
|
+
Call `drawio_check` and record whether export is available and whether Mermaid/layout features are supported.
|
|
390
|
+
|
|
391
|
+
### 2. Plan
|
|
392
|
+
|
|
393
|
+
Choose:
|
|
394
|
+
|
|
395
|
+
- diagram type;
|
|
396
|
+
- components and relations;
|
|
397
|
+
- groups or containers;
|
|
398
|
+
- top-to-bottom or left-to-right direction;
|
|
399
|
+
- Mermaid or XML authoring mode;
|
|
400
|
+
- source path, pages, and final formats.
|
|
401
|
+
|
|
402
|
+
Call `drawio_shapesearch` during planning whenever an exact library shape is required.
|
|
403
|
+
|
|
404
|
+
### 3. Author
|
|
405
|
+
|
|
406
|
+
For Mermaid, write concise valid Mermaid and convert it with `drawio_from_mermaid`.
|
|
407
|
+
|
|
408
|
+
For XML, use an uncompressed `<mxGraphModel>`. The minimum authoring contract is:
|
|
409
|
+
|
|
410
|
+
- include root cells `id="0"` and `id="1"`;
|
|
411
|
+
- reserve IDs `0` and `1` for those root cells;
|
|
412
|
+
- assign every other cell a unique ID and valid parent;
|
|
413
|
+
- assign every vertex positive geometry;
|
|
414
|
+
- assign every edge valid source and target IDs;
|
|
415
|
+
- include `<mxGeometry relative="1" as="geometry" />` in every edge;
|
|
416
|
+
- escape XML attribute characters and use `
` for label line breaks;
|
|
417
|
+
- use coordinates relative to the actual parent container;
|
|
418
|
+
- leave spacing and routing corridors for labels, edges, and arrowheads.
|
|
419
|
+
|
|
420
|
+
For large XML graphs on draw.io 30+, run `drawio_layout` and continue using its returned path.
|
|
421
|
+
|
|
422
|
+
### 4. Validate
|
|
423
|
+
|
|
424
|
+
Run `drawio_validate` on the exact source that will be exported. Fix every error and rerun validation. Assess warnings before continuing.
|
|
425
|
+
|
|
426
|
+
### 5. Preview and inspect
|
|
427
|
+
|
|
428
|
+
Export a PNG with:
|
|
429
|
+
|
|
430
|
+
```text
|
|
431
|
+
drawio_export({ "input": "<source>.drawio", "mode": "preview" })
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Read the PNG with vision and verify:
|
|
435
|
+
|
|
436
|
+
- requested components and relations are present;
|
|
437
|
+
- labels are readable and not clipped;
|
|
438
|
+
- nodes do not overlap or leave the canvas;
|
|
439
|
+
- edges connect the intended endpoints;
|
|
440
|
+
- arrowheads and decision labels are visible;
|
|
441
|
+
- edges do not stack, cross unnecessarily, or route through unrelated nodes;
|
|
442
|
+
- grouping, alignment, spacing, contrast, and hierarchy are clear.
|
|
443
|
+
|
|
444
|
+
Make targeted source corrections, validate again, and re-preview. Limit automatic visual correction to two rounds before requesting focused feedback or offering desktop fine-tuning.
|
|
445
|
+
|
|
446
|
+
### 6. Final export
|
|
447
|
+
|
|
448
|
+
After visual review, export each requested format and page with `mode: "final"`. Report:
|
|
449
|
+
|
|
450
|
+
- source `.drawio` path;
|
|
451
|
+
- validation status and retained warnings;
|
|
452
|
+
- preview path when relevant;
|
|
453
|
+
- every final output path and format;
|
|
454
|
+
- whether each output embeds editable XML;
|
|
455
|
+
- any unavailable or skipped functionality.
|
|
456
|
+
|
|
457
|
+
## Existing-diagram workflows
|
|
458
|
+
|
|
459
|
+
### Explain
|
|
460
|
+
|
|
461
|
+
Use `drawio_explain` for a structured read-back. For exact edits, inspect the XML after obtaining the summary.
|
|
462
|
+
|
|
463
|
+
### Validate
|
|
464
|
+
|
|
465
|
+
Use `drawio_validate` directly. A CLI check is unnecessary unless an export will follow.
|
|
466
|
+
|
|
467
|
+
### Edit
|
|
468
|
+
|
|
469
|
+
1. Preserve the original unless replacement was requested.
|
|
470
|
+
2. Explain and inspect the source.
|
|
471
|
+
3. Make the smallest targeted XML change.
|
|
472
|
+
4. Validate the edited source.
|
|
473
|
+
5. Preview and compare the requested behavior visually.
|
|
474
|
+
6. Export to a new path unless in-place replacement was requested.
|
|
475
|
+
|
|
476
|
+
Do not blindly edit compressed pages. The validator and explainer cannot inspect them; they must first be saved as uncompressed XML through a compatible editor.
|
|
477
|
+
|
|
478
|
+
### Export
|
|
479
|
+
|
|
480
|
+
Check the CLI, then call `drawio_export` with the requested format and options. Do not reconstruct a valid existing source merely to export it.
|
|
481
|
+
|
|
482
|
+
### Re-layout
|
|
483
|
+
|
|
484
|
+
Use `drawio_layout` only for XML-authored or existing native diagrams on draw.io 30+. Preserve the original by using a distinct output unless replacement is intentional. Validate and preview the layout result.
|
|
485
|
+
|
|
486
|
+
## Output and editability semantics
|
|
487
|
+
|
|
488
|
+
- `.drawio` is always the canonical editable source.
|
|
489
|
+
- Final PNG, SVG, and PDF embed XML by default and can be reopened in draw.io where supported.
|
|
490
|
+
- JPG cannot embed XML.
|
|
491
|
+
- Preview PNG is intentionally clean and unembedded for vision compatibility.
|
|
492
|
+
- A final embedded PNG normally uses the `.drawio.png` double extension.
|
|
493
|
+
- Multi-page exports should use `pageIndex` and explicit unique output names.
|
|
494
|
+
- `drawio_explain` returns Markdown as text; it does not write a documentation file.
|
|
495
|
+
- `drawio_layout` creates a sibling `.layout.drawio` unless `output` is supplied.
|
|
496
|
+
- Inline Mermaid conversion creates `diagram.drawio` in the working directory unless `output` is supplied.
|
|
497
|
+
|
|
498
|
+
## Functional limitations
|
|
499
|
+
|
|
500
|
+
- Validation cannot inspect compressed pages.
|
|
501
|
+
- Explanation cannot describe compressed pages.
|
|
502
|
+
- Structural validation cannot replace visual inspection.
|
|
503
|
+
- Route-through and crossing analysis is limited to edges with explicit waypoints.
|
|
504
|
+
- Shape search covers bundled official draw.io shapes, not arbitrary third-party logos.
|
|
505
|
+
- Mermaid conversion cannot express all draw.io styles, containers, routing, or multi-page behavior.
|
|
506
|
+
- ELK layout accepts only the six registered presets; arbitrary JSON layouts are not exposed.
|
|
507
|
+
- The extension does not expose XML compression/decompression, Python generators, browser editor fallbacks, icon downloads, or arbitrary draw.io CLI arguments.
|
|
508
|
+
- A failed operation may be returned as text beginning with `Export failed`, `Layout failed`, `Mermaid conversion failed`, `Explain failed`, or `Open failed`. Treat that result as failure.
|
|
509
|
+
|
|
510
|
+
## Authoring references
|
|
511
|
+
|
|
512
|
+
Use these packaged references when additional notation or XML detail is needed:
|
|
513
|
+
|
|
514
|
+
- [`../assets/references/xml-authoring.md`](../assets/references/xml-authoring.md) — XML cells, containers, edges, palette, and spacing;
|
|
515
|
+
- [`../assets/references/diagram-types.md`](../assets/references/diagram-types.md) — notation-specific shapes and layout conventions;
|
|
516
|
+
- [`../assets/references/mermaid-authoring.md`](../assets/references/mermaid-authoring.md) — Mermaid syntax and conversion guidance;
|
|
517
|
+
- [`../assets/references/troubleshooting.md`](../assets/references/troubleshooting.md) — rendering and platform failure patterns.
|
|
518
|
+
|
|
519
|
+
Some inherited reference text mentions upstream Python scripts or direct CLI commands. Those references provide background authoring knowledge only. They do not add extension functionality. Agents must use the registered DrawMe tools and options documented here.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senad-d/drawme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Pi extension: turn natural-language descriptions into .drawio diagrams and export to PNG/SVG/PDF/JPG via the draw.io desktop CLI. Local-only, no network.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"pi",
|
|
18
|
+
"pi-package",
|
|
18
19
|
"pi-extension",
|
|
19
20
|
"drawio",
|
|
20
21
|
"diagram",
|
|
@@ -31,11 +32,13 @@
|
|
|
31
32
|
"pi": {
|
|
32
33
|
"extensions": [
|
|
33
34
|
"./src/index.ts"
|
|
34
|
-
]
|
|
35
|
+
],
|
|
36
|
+
"image": "https://raw.githubusercontent.com/senad-d/DrawMe/main/example/drawme-how-it-works.drawio.png"
|
|
35
37
|
},
|
|
36
38
|
"files": [
|
|
37
39
|
"src",
|
|
38
|
-
"assets"
|
|
40
|
+
"assets",
|
|
41
|
+
"docs"
|
|
39
42
|
],
|
|
40
43
|
"scripts": {
|
|
41
44
|
"typecheck": "tsc --noEmit",
|
|
@@ -50,16 +53,20 @@
|
|
|
50
53
|
"dev": "pi --no-extensions -e ."
|
|
51
54
|
},
|
|
52
55
|
"dependencies": {
|
|
53
|
-
"@xmldom/xmldom": "^0.9.8"
|
|
54
|
-
|
|
56
|
+
"@xmldom/xmldom": "^0.9.8"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
60
|
+
"typebox": "*"
|
|
55
61
|
},
|
|
56
62
|
"devDependencies": {
|
|
57
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
63
|
+
"@earendil-works/pi-coding-agent": "^0.79.0",
|
|
58
64
|
"@eslint/js": "^10.0.1",
|
|
59
65
|
"@types/node": "^26.1.2",
|
|
60
66
|
"@vitest/coverage-v8": "^4.1.10",
|
|
61
67
|
"eslint": "^10.8.0",
|
|
62
68
|
"globals": "^17.8.0",
|
|
69
|
+
"typebox": "1.3.9",
|
|
63
70
|
"typescript": "^5.6.0",
|
|
64
71
|
"typescript-eslint": "^8.10.0",
|
|
65
72
|
"vitest": "^4.1.10"
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* CLI. It exposes the skill's workflow as plain commands + tools instead of a
|
|
5
5
|
* skill, and does zero network I/O (see the audit note in the README).
|
|
6
6
|
*
|
|
7
|
-
* Tools: drawio_check · drawio_export · drawio_validate
|
|
7
|
+
* Tools: drawio_check · drawio_export · drawio_validate · drawio_from_mermaid
|
|
8
|
+
* drawio_layout · drawio_shapesearch · drawio_explain · drawio_open
|
|
8
9
|
* Commands: /drawme · /drawme-check · /drawme-export
|
|
9
10
|
*/
|
|
10
11
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
@@ -28,6 +29,7 @@ import { drawmeWorkflow } from "./workflow";
|
|
|
28
29
|
|
|
29
30
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
30
31
|
const REF_DIR = resolve(HERE, "..", "assets", "references");
|
|
32
|
+
const AGENT_REFERENCE_PATH = resolve(HERE, "..", "docs", "agent-guide.md");
|
|
31
33
|
|
|
32
34
|
const FORMAT = Type.Union([Type.Literal("png"), Type.Literal("svg"), Type.Literal("pdf"), Type.Literal("jpg")]);
|
|
33
35
|
const MODE = Type.Union([Type.Literal("preview"), Type.Literal("final")]);
|
|
@@ -232,7 +234,7 @@ export default function drawme(pi: ExtensionAPI): void {
|
|
|
232
234
|
ctx.ui.notify("Usage: /drawme <description of the diagram to create>", "info");
|
|
233
235
|
return;
|
|
234
236
|
}
|
|
235
|
-
pi.sendUserMessage(drawmeWorkflow(desc, REF_DIR));
|
|
237
|
+
pi.sendUserMessage(drawmeWorkflow(desc, REF_DIR, AGENT_REFERENCE_PATH));
|
|
236
238
|
},
|
|
237
239
|
});
|
|
238
240
|
|
package/src/workflow.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* self-check→final loop while pointing it at the DrawMe tools and the bundled,
|
|
5
5
|
* network-free authoring references.
|
|
6
6
|
*/
|
|
7
|
-
export function drawmeWorkflow(description: string, refDir: string): string {
|
|
7
|
+
export function drawmeWorkflow(description: string, refDir: string, agentReferencePath: string): string {
|
|
8
8
|
const quoted = description.replaceAll("\n", "\n> ");
|
|
9
9
|
return [
|
|
10
10
|
"# DrawMe — create a diagram",
|
|
@@ -13,7 +13,11 @@ export function drawmeWorkflow(description: string, refDir: string): string {
|
|
|
13
13
|
"",
|
|
14
14
|
`> ${quoted}`,
|
|
15
15
|
"",
|
|
16
|
-
"
|
|
16
|
+
"Before starting, read `" +
|
|
17
|
+
agentReferencePath +
|
|
18
|
+
"`, the official DrawMe extension reference for agent behavior, tool options, decision rules, and limitations.",
|
|
19
|
+
"",
|
|
20
|
+
"Produce a `.drawio` file and export it, following the workflow below. For anything that touches the draw.io CLI, use the DrawMe tools — do NOT shell out to `drawio` yourself. Everything runs locally; there is no network access.",
|
|
17
21
|
"",
|
|
18
22
|
"1. **Check** — call `drawio_check` once (note the version: v30+ unlocks Mermaid conversion and the auto-layout pass). If the CLI is unavailable, still author the `.drawio` XML, tell the user how to install draw.io / open the file, and skip the export + self-check steps.",
|
|
19
23
|
"2. **Plan** — choose the diagram type, shapes, relationships, and layout direction (LR or TB). For a specific type (ERD, UML class, sequence, C4, architecture, ML/DL, flowchart, SysML, BPMN, network, swimlane), read `" +
|