@senad-d/drawme 0.1.3 → 0.1.5
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/CHANGELOG.md +39 -2
- package/README.md +34 -23
- package/assets/references/troubleshooting.md +3 -3
- package/assets/references/xml-authoring.md +21 -1
- package/docs/{agent-guide.md → reference.md} +66 -140
- package/docs/visual-review-implementation-tasks.md +271 -0
- package/example/drawme-extension-waterfall-overview.drawio +72 -0
- package/example/drawme-how-it-works.drawio +127 -77
- package/example/drawme-installation-guide.drawio +98 -64
- package/package.json +1 -1
- package/src/drawio.ts +67 -15
- package/src/fitcanvas.ts +172 -0
- package/src/geometry.ts +259 -0
- package/src/index.ts +107 -15
- package/src/validate.ts +405 -223
- package/src/workflow.ts +86 -21
package/CHANGELOG.md
CHANGED
|
@@ -6,10 +6,47 @@ All notable changes to this project are documented here. The format is based on
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- New `drawio_fit_canvas` tool: deterministically resizes each page's canvas to its visible content plus
|
|
12
|
+
a margin (default 40px) and shifts content to the margin origin — the fix for cramped pages where
|
|
13
|
+
elements overlap because they were squeezed into a too-small canvas. The workflow now defers page
|
|
14
|
+
dimensions until content exists (author with generous spacing → fit the canvas), and validation/docs
|
|
15
|
+
direct overlap and bounds findings to "spread elements, then refit" instead of shrinking content.
|
|
16
|
+
Shared `.drawio` geometry moved into `src/geometry.ts`.
|
|
17
|
+
|
|
9
18
|
### Changed
|
|
10
19
|
|
|
11
|
-
-
|
|
12
|
-
|
|
20
|
+
- `/drawme` now pre-loads its context: the command handler resolves the draw.io CLI itself and embeds the
|
|
21
|
+
check result plus the diagram-types, XML-authoring, and (v30+) Mermaid references directly into the
|
|
22
|
+
injected workflow message. The references remain editable Markdown files under `assets/references/`;
|
|
23
|
+
they are just no longer read via tool calls at run start. Only the rarely needed troubleshooting
|
|
24
|
+
reference stays on-demand.
|
|
25
|
+
|
|
26
|
+
- `drawio_export` previews are now vision-aware: the PNG image block is attached only when the active
|
|
27
|
+
model can view images (checked per call via the extension context, failing open for unknown models),
|
|
28
|
+
the result text always states whether it was attached, and `details.imageAttached` reports the outcome.
|
|
29
|
+
- Replaced the five mandatory visual passes with a critique-first review: one holistic preview with a
|
|
30
|
+
structured all-category critique, focused re-previews only for categories with findings, and a final
|
|
31
|
+
holistic confirmation. Models that cannot view images get an explicit structural-review path
|
|
32
|
+
(`drawio_validate` + `drawio_explain`) instead of a silent image placeholder.
|
|
33
|
+
- Rewrote the packaged extension reference and workflow text in second person without agent terminology.
|
|
34
|
+
- The `/drawme` run is now fully autonomous: the human approval gate before final export is removed.
|
|
35
|
+
After the holistic confirmation (or on hitting the five-retry correction limit, reporting the unresolved
|
|
36
|
+
finding), the workflow proceeds straight to final export; mid-run user feedback is treated as new
|
|
37
|
+
critique findings rather than a pause point. Docs, packaged troubleshooting guidance, and the example
|
|
38
|
+
diagrams were updated to match, and the golden asset baseline was intentionally refreshed.
|
|
39
|
+
- The `/drawme` workflow no longer instructs a mandatory reference read: the injected message plus the
|
|
40
|
+
registered tool descriptions are self-contained (the failure-text and compressed-page rules moved into
|
|
41
|
+
them), saving a file read and several thousand tokens per run. `docs/agent-guide.md` became
|
|
42
|
+
`docs/reference.md`, a pure command/tool catalog for other projects; topic references under
|
|
43
|
+
`assets/references/` are still read on demand.
|
|
44
|
+
- Added focused visual quality passes, stronger deterministic canvas/edge/readability checks, attached PNG
|
|
45
|
+
previews, warning-resolution gates, and explicit approval before final export.
|
|
46
|
+
- Intentionally re-baselined the golden asset hash after adding finite-page sizing, typography, preview
|
|
47
|
+
readability, and five-retry correction guidance to the packaged authoring references.
|
|
48
|
+
- Each successful preview now removes the previous preview file for the same `.drawio` source, leaving only
|
|
49
|
+
the latest review artifact; final export removes that remaining preview.
|
|
13
50
|
- Refocused the documentation on DrawMe's current diagram-authoring workflow and removed obsolete
|
|
14
51
|
guidance inherited from the earlier documentation set.
|
|
15
52
|
- Improved npm and Pi gallery metadata, packaged linked diagram examples, and added a package-content
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
-
DrawMe is a native Pi **extension** for diagram authoring. Describe a diagram and Pi plans it, writes editable `.drawio` XML (or Mermaid on draw.io v30+), lints
|
|
20
|
+
DrawMe is a native Pi **extension** for diagram authoring. Describe a diagram and Pi plans it, writes editable `.drawio` XML (or Mermaid on draw.io v30+), lints every source revision, critiques the rendered preview when the active model can view images, and exports the final deliverable — fully autonomously, with no human intervention once started.
|
|
21
21
|
|
|
22
22
|
<table align="center">
|
|
23
23
|
<tr>
|
|
@@ -28,20 +28,26 @@ DrawMe is a native Pi **extension** for diagram authoring. Describe a diagram an
|
|
|
28
28
|
<img src="https://raw.githubusercontent.com/senad-d/DrawMe/main/example/drawme-how-it-works.drawio.png" alt="DrawMe: from a prompt to an editable diagram" title="DrawMe" width="820">
|
|
29
29
|
</td>
|
|
30
30
|
</tr>
|
|
31
|
+
<tr>
|
|
32
|
+
<td align="center">
|
|
33
|
+
<img src="https://raw.githubusercontent.com/senad-d/DrawMe/main/example/drawme-installation-guide.drawio.png" alt="DrawMe: Installation guide" title="DrawMe" width="820">
|
|
34
|
+
</td>
|
|
35
|
+
</tr>
|
|
31
36
|
</table>
|
|
32
37
|
|
|
33
38
|
- **Natural-language authoring:** flowcharts, architecture, UML, BPMN, ERD, C4, network, ML — as native `.drawio`, or as Mermaid with automatic layout on v30+.
|
|
34
|
-
- **Guided workflow:** CLI detection, planning, authoring, validation, visual review, and final export
|
|
35
|
-
- **Deterministic validation:** a structural linter catches dangling edges, duplicate/reserved ids,
|
|
39
|
+
- **Guided workflow:** CLI detection, planning, authoring, validation, a critique-first visual review across canvas/node/connector/semantic categories, and final export run end to end from a single `/drawme` — no approval pauses.
|
|
40
|
+
- **Deterministic validation:** a structural linter catches dangling edges, duplicate/reserved ids, malformed geometry, page/container overflow, inadequate margins, conservative readability defects, overlaps, and explicit edge-routing defects before you look at a pixel.
|
|
41
|
+
- **Vision-aware previews:** successful PNG previews attach the actual image only when the active model can view images — the result text says which case applies — so text-only models get an honest structural-review path instead of a placeholder; each replacement removes the previous same-source preview file so only the latest remains on disk.
|
|
36
42
|
- **Exact shapes, not guesses:** search 10k+ official AWS/Azure/GCP/Cisco/Kubernetes/UML/BPMN styles from a bundled local index.
|
|
37
|
-
- **Editable source of truth:** final PNG/SVG/PDF exports embed the diagram XML, the truncated `-e` PNG chunk is auto-repaired, and
|
|
43
|
+
- **Editable source of truth:** final PNG/SVG/PDF exports embed the diagram XML, the truncated `-e` PNG chunk is auto-repaired, and final export removes the one remaining latest preview.
|
|
38
44
|
|
|
39
45
|
> **Security:** Pi packages run with your full system permissions. DrawMe reads and writes diagram files and can launch the draw.io CLI or your OS file opener. Review [`SECURITY.md`](SECURITY.md) before installation.
|
|
40
46
|
|
|
41
47
|
## Table of Contents
|
|
42
48
|
|
|
43
49
|
- [Implementation Status](#implementation-status)
|
|
44
|
-
- [
|
|
50
|
+
- [Extension Reference](#extension-reference)
|
|
45
51
|
- [Quick Start](#quick-start)
|
|
46
52
|
- [Installation](#installation)
|
|
47
53
|
- [Commands](#commands)
|
|
@@ -62,15 +68,15 @@ DrawMe is a native Pi **extension** for diagram authoring. Describe a diagram an
|
|
|
62
68
|
|
|
63
69
|
This checkout implements the DrawMe core loop as a Pi extension:
|
|
64
70
|
|
|
65
|
-
-
|
|
66
|
-
- A guided `/drawme` workflow that steers authoring, validation, a
|
|
71
|
+
- Nine model-callable tools (`drawio_check`, `drawio_export`, `drawio_validate`, `drawio_fit_canvas`, `drawio_shapesearch`, `drawio_from_mermaid`, `drawio_layout`, `drawio_explain`, `drawio_open`) and three commands (`/drawme`, `/drawme-check`, `/drawme-export`).
|
|
72
|
+
- A guided `/drawme` workflow that steers authoring, validation after every edit, a critique-first visual review, and autonomous final multi-format export.
|
|
67
73
|
- Pure-TypeScript structural linting, `-e` PNG IEND repair, shape search over a bundled index, and diagram-to-Markdown description — no Python runtime required.
|
|
68
74
|
- 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
75
|
- Validation pipeline: golden asset-integrity check, TypeScript typecheck, ESLint, a custom format check, and unit + real-CLI integration tests.
|
|
70
76
|
|
|
71
|
-
##
|
|
77
|
+
## Extension Reference
|
|
72
78
|
|
|
73
|
-
[`docs/
|
|
79
|
+
[`docs/reference.md`](docs/reference.md) catalogs the extension's public surface — every command, tool option, default, output behavior, and functional limitation — for other projects and integrations that use DrawMe. It is documentation, not runtime input: the `/drawme` workflow and the registered tool descriptions carry the complete operational instructions themselves.
|
|
74
80
|
|
|
75
81
|
## Quick Start
|
|
76
82
|
|
|
@@ -107,7 +113,7 @@ Inside Pi:
|
|
|
107
113
|
/drawme a flowchart of a user login: enter credentials, validate, then success or retry
|
|
108
114
|
```
|
|
109
115
|
|
|
110
|
-
Pi checks the CLI, plans and writes the `.drawio`, validates
|
|
116
|
+
Pi checks the CLI, plans and writes the `.drawio`, validates every revision, critiques the rendered preview when the active model can view images (or reviews structurally when it cannot), and exports the final editable deliverable — all in one run, without asking for approval along the way.
|
|
111
117
|
|
|
112
118
|
### Run from a source checkout
|
|
113
119
|
|
|
@@ -133,7 +139,7 @@ pi --no-extensions -e .
|
|
|
133
139
|
|
|
134
140
|
| Command | Description |
|
|
135
141
|
| --- | --- |
|
|
136
|
-
| `/drawme <description>` | Kick off
|
|
142
|
+
| `/drawme <description>` | Kick off authoring, per-edit validation, critique-first visual review, and autonomous final export. |
|
|
137
143
|
| `/drawme-check` | Report whether the draw.io CLI is available, its version, and v30+ feature support. |
|
|
138
144
|
| `/drawme-export <file> [png\|svg\|pdf\|jpg]` | One-shot final export of an existing `.drawio`. |
|
|
139
145
|
|
|
@@ -144,8 +150,9 @@ Registered for the model to call directly.
|
|
|
144
150
|
| Tool | Purpose |
|
|
145
151
|
| --- | --- |
|
|
146
152
|
| `drawio_check` | Resolve the draw.io binary, version, and whether it supports Mermaid import / `--layout` (v30+). |
|
|
147
|
-
| `drawio_export` | Export a `.drawio` to PNG/SVG/PDF/JPG. `mode:"preview"` → clean width-capped PNG
|
|
148
|
-
| `drawio_validate` | Deterministic
|
|
153
|
+
| `drawio_export` | Export a `.drawio` to PNG/SVG/PDF/JPG. `mode:"preview"` → clean width-capped PNG returned as text/metadata, with the image block attached when the active model can view images (the text states which); each successful preview removes the previous same-source preview file so only the latest remains. `mode:"final"` → embedded editable deliverable, with truncated PNG repair and cleanup of the remaining preview. |
|
|
154
|
+
| `drawio_validate` | Deterministic lint: dangling edges, duplicate/reserved ids, broken parents, malformed vertex/edge geometry; warnings for page/container bounds, margins, conservative readability, overlap, and explicit routes through/crossing shapes; observations and readability score are reported separately. |
|
|
155
|
+
| `drawio_fit_canvas` | Fit each page's canvas to its content plus a margin (default 40px): grows cramped pages, tightens oversized ones, and shifts content to the margin origin — instead of shrinking or cramming elements. Deterministic, no CLI. |
|
|
149
156
|
| `drawio_shapesearch` | Exact official `style=` strings for 10k+ AWS/Azure/GCP/Cisco/Kubernetes/UML/BPMN shapes, from a bundled local index. Use instead of guessing a style. |
|
|
150
157
|
| `drawio_from_mermaid` | Convert Mermaid text (inline or a `.mmd`) to a native `.drawio` with automatic layout. Requires draw.io **v30+**. |
|
|
151
158
|
| `drawio_layout` | Re-place nodes / route edges with an ELK preset (`verticalFlow`, `horizontalFlow`, `verticalTree`, `horizontalTree`, `radialTree`, `organic`) for large graphs. Requires draw.io **v30+**. |
|
|
@@ -166,21 +173,25 @@ The extension factory in `src/index.ts` registers the tools and commands. Render
|
|
|
166
173
|
|
|
167
174
|
## The /drawme Workflow
|
|
168
175
|
|
|
169
|
-
`/drawme` injects a guided
|
|
176
|
+
`/drawme` injects a guided nine-step workflow that the model follows using the tools above:
|
|
177
|
+
|
|
178
|
+
1. **Check** — the command itself resolves the CLI and embeds the result plus the authoring references into the workflow message (v30+ unlocks Mermaid conversion and ELK layout), so the run starts with everything in context — no upfront tool calls or file reads.
|
|
179
|
+
2. **Plan** — pick the diagram type, relationships, finite canvas, and layout direction.
|
|
180
|
+
3. **Author** — write editable uncompressed XML (or Mermaid on v30+), using exact searched shapes and optional ELK layout.
|
|
181
|
+
4. **Validate after every edit** — fix all errors; fix each warning or record why it is reviewed and acceptable.
|
|
182
|
+
5. **Visual review, critique first** — export one holistic preview; the tool result states whether the image is attached. With the image, the model walks all four categories (canvas/composition, nodes/typography, connectors, semantics) and records findings or explicit pass reasons before editing. Without it, the model reviews structurally with validation and explanation instead of describing renders.
|
|
183
|
+
6. **Fix and confirm** — each finding becomes a targeted edit, validation, and a focused category preview; a final holistic preview confirms no regressions. Each successful preview removes the previous preview file, leaving only the current image.
|
|
184
|
+
7. **Bound corrections** — the initial critique and final confirmation do not count as retries; permit at most five targeted edit → validation → replacement-preview correction retries total, then request focused feedback or offer `drawio_open`.
|
|
185
|
+
8. **No human gate** — the run never pauses for approval or feedback; if the user interrupts with feedback, it is handled as new critique findings and the run continues.
|
|
186
|
+
9. **Final export** — immediately after the holistic confirmation, export requested embedded/editable formats, remove the one remaining latest review preview, and report deliverables (including any unresolved finding from the correction limit) plus cleanup warnings.
|
|
170
187
|
|
|
171
|
-
|
|
172
|
-
2. **Plan** — pick the diagram type, shapes, relationships, and layout direction.
|
|
173
|
-
3. **Author** — write editable, uncompressed `.drawio` XML (or Mermaid on v30+); use `drawio_shapesearch` for exact vendor/UML/BPMN shapes; use `drawio_layout` for large graphs.
|
|
174
|
-
4. **Validate** — run `drawio_validate` and fix every error before exporting.
|
|
175
|
-
5. **Preview & self-check** — export a clean, width-capped PNG and inspect it visually; fix overlaps, clipping, and edge defects (max two rounds).
|
|
176
|
-
6. **Review** — show the preview, apply targeted edits from your feedback, re-preview until approved.
|
|
177
|
-
7. **Final export** — export each requested format (embedded/editable), automatically remove previews for that source, report final paths, and offer to open the source in the desktop app.
|
|
188
|
+
Deterministic checks cover XML contracts, IDs/references, finite page and container bounds, outer margins, overlaps, explicit waypoint routes, and conservative font/wrapping cases. Rendered clipping and wrapping, contrast, typography at full-diagram scale, visual balance, semantics, and draw.io's automatic connector routes can only be judged from the preview image, so they are critiqued when the active model can view images and reported as unverified when it cannot. A 2000px preview that makes labels unreadable requires a tighter/simpler layout, page splitting, or a focused re-export — it must never be accepted as-is.
|
|
178
189
|
|
|
179
190
|
## Bundled References and Assets
|
|
180
191
|
|
|
181
|
-
|
|
192
|
+
These stay plain Markdown files for easy editing. `/drawme` embeds the diagram-types, XML-authoring, and (on v30+) Mermaid references directly into its workflow message, so the model starts with them in context; the troubleshooting reference is read on demand when an export fails.
|
|
182
193
|
|
|
183
|
-
- `docs/
|
|
194
|
+
- `docs/reference.md` — catalog of commands, tool options, defaults, output behavior, and limitations (documentation only; not read at runtime).
|
|
184
195
|
- `assets/references/xml-authoring.md` — `.drawio` skeleton, cell/edge forms, containers, palette, spacing.
|
|
185
196
|
- `assets/references/diagram-types.md` — per-type presets (ERD, UML, sequence, C4, architecture, ML, flowchart, SysML, BPMN, network, swimlane).
|
|
186
197
|
- `assets/references/mermaid-authoring.md` — Mermaid authoring for the v30+ conversion path.
|
|
@@ -10,13 +10,13 @@ Read this when something looks wrong in the output (rendering, export, layout, e
|
|
|
10
10
|
| `--` inside XML comments | Illegal per XML spec — use single hyphens or rephrase |
|
|
11
11
|
| Special characters in `value` | Use XML entities: `&` `<` `>` `"` |
|
|
12
12
|
| Literal `\n` in label text | Use `
` for line breaks in `value` attributes |
|
|
13
|
-
| Overlapping shapes | Scale spacing with complexity (200–350px)
|
|
13
|
+
| Overlapping shapes | Scale spacing with complexity (200–350px) and leave routing corridors; move elements apart and run `drawio_fit_canvas` so the page grows around the content — never shrink elements to fit the page |
|
|
14
14
|
| Edges crossing through shapes | Add waypoints, distribute entry/exit points, or increase spacing |
|
|
15
15
|
| Arrowhead overlaps bend | Final edge segment before target must be ≥20px — increase spacing or add waypoints |
|
|
16
|
-
|
|
|
16
|
+
| Automatic correction loop reaches its limit | The initial critique pass and the final holistic confirmation do not consume retries. Allow at most **5 correction retries total**; each retry is one targeted source edit → `drawio_validate` → replacement preview cycle. If a finding remains at the limit, stop editing, keep the best validated state, continue to final export, and name the unresolved finding and its category in the final report — never loop or wait for input. |
|
|
17
17
|
| `command not found: draw.io` after `brew install --cask drawio` | Homebrew installs the binary as `drawio` (no dot). Use `drawio --version`, not `draw.io --version`. The dot-name only exists inside the `.app` bundle (`/Applications/draw.io.app/Contents/MacOS/draw.io`) and on Windows (`draw.io.exe`). |
|
|
18
18
|
| Export command not found on macOS | Try full path `/Applications/draw.io.app/Contents/MacOS/draw.io` |
|
|
19
|
-
| Vision reports that the preview dimensions are too large | Re-export with `drawio_export` in preview mode and set a smaller `width`. |
|
|
19
|
+
| Vision reports that the preview dimensions are too large | Re-export with `drawio_export` in preview mode and set a smaller `width`. If a 2000px full-diagram preview makes labels unreadable, tighten the canvas, simplify or split the layout, or use a focused review artifact. |
|
|
20
20
|
| Linux: blank/error output headlessly | Prefix command with `xvfb-run -a` |
|
|
21
21
|
| Linux: `--no-sandbox` placed before input file (parsed as filename) | Move `--no-sandbox` to the very end of the command (drawio-desktop#249, #1056) |
|
|
22
22
|
| Linux: `Failed to get 'appData' path` / `Home directory not accessible` | `export HOME=/tmp` before invoking drawio (drawio-desktop#127) |
|
|
@@ -9,7 +9,7 @@ Read this **before hand-writing any `.drawio` XML** (workflow step 3). Skip it w
|
|
|
9
9
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
10
10
|
<mxfile host="drawio" version="26.0.0">
|
|
11
11
|
<diagram name="Page-1">
|
|
12
|
-
<mxGraphModel>
|
|
12
|
+
<mxGraphModel grid="1" gridSize="10" page="1" pageScale="1" pageWidth="1200" pageHeight="800">
|
|
13
13
|
<root>
|
|
14
14
|
<mxCell id="0" />
|
|
15
15
|
<mxCell id="1" parent="0" />
|
|
@@ -28,6 +28,25 @@ Read this **before hand-writing any `.drawio` XML** (workflow step 3). Skip it w
|
|
|
28
28
|
- **Never use `--` inside XML comments** — it's illegal per XML spec and causes parse errors
|
|
29
29
|
- Escape special characters in attribute values: `&`, `<`, `>`, `"`
|
|
30
30
|
- **Multi-line text in labels:** use `
` for line breaks inside `value` attributes (not literal `\n`). Example: `value="Line 1
Line 2"`
|
|
31
|
+
- Keep `page="1"` and `pageScale="1"` for a normal finite page, and resize `pageWidth`/`pageHeight` to the finished content. Use `page="0"` only when the user explicitly wants an infinite/non-page canvas; deterministic page-boundary, outer-margin, and empty-space checks are then intentionally skipped.
|
|
32
|
+
- If `pageWidth` or `pageHeight` is omitted, DrawMe still validates cells and containment but records that page-boundary, outer-margin, and empty-space checks were skipped. Prefer explicit dimensions for deliverables.
|
|
33
|
+
|
|
34
|
+
### Canvas sizing and content bounds
|
|
35
|
+
|
|
36
|
+
The page follows from the layout, never the reverse: author elements with generous spacing first, then run `drawio_fit_canvas` to resize `pageWidth`/`pageHeight` to the visible content plus a margin (default 40px) and shift content to the margin origin. Run it again after every move, resize, container change, layout pass, legend addition, or waypoint edit, and treat each run as a source edit to validate.
|
|
37
|
+
|
|
38
|
+
When elements overlap or cannot fit, do not shrink or cram them to preserve the current page: move them apart with proper spacing and refit the canvas so the page grows around them. The reverse problem — a page much larger than content — creates unreadable full-diagram previews and an excessive-empty-space warning; the same fit run tightens it.
|
|
39
|
+
|
|
40
|
+
Background for manual sizing (what the fit computes): visible top-level vertex/container rectangles as `(x, y, x + width, y + height)` with ancestor container offsets added for nested children, expanded by separately sized edge labels and explicit waypoints; content shifted so minimum `x`/`y` sit at the margin (DrawMe warns below the **20px minimum**); `pageWidth`/`pageHeight` set to the bounds plus the margin on each side. Automatic edge routes still need preview inspection, and invisible helpers or intentional relative border ports never count as page-extending content.
|
|
41
|
+
|
|
42
|
+
### Typography, padding, and labels
|
|
43
|
+
|
|
44
|
+
- Use at least **12px for body/node labels** and **10px for connector labels**. Headings usually need 16px or more. Compact border ports and notation-mandated annotations may use 8–9px when their short labels remain legible; record the exception during review.
|
|
45
|
+
- Add `whiteSpace=wrap;html=1;` to labeled nodes. Use about 10–16px visual padding (`spacing=10;` or directional spacing) between text and shape borders.
|
|
46
|
+
- Size a node for the rendered lines, not only character count. A conservative height is `line count × (fontSize × 1.25) + top/bottom padding`; allow additional room for container title bands and icon shapes.
|
|
47
|
+
- Estimate width from the longest line (`characters × fontSize × 0.6 + left/right padding`), then verify by preview. Insert deliberate `
` breaks for long labels rather than forcing a very wide node.
|
|
48
|
+
- Prefer two or three concise lines. If a label remains long, enlarge the node, shorten the wording without changing meaning, or split details into a note/legend. Never reduce important body text merely to fit existing geometry.
|
|
49
|
+
- A 2000px full-diagram preview scales the entire page. If labels become unreadable at that width, simplify the layout, tighten the canvas, split the diagram into pages, or use a focused review export; never accept an unreadable full view as passing typography.
|
|
31
50
|
|
|
32
51
|
### Shape types (vertex)
|
|
33
52
|
|
|
@@ -187,6 +206,7 @@ Rules: swatch colors come from the active palette (preset or the table above) wi
|
|
|
187
206
|
**Grid alignment:** snap all `x`, `y`, `width`, `height` values to **multiples of 10** — this ensures shapes align cleanly on draw.io's default grid and makes manual editing easier.
|
|
188
207
|
|
|
189
208
|
**General rules:**
|
|
209
|
+
- Run `drawio_fit_canvas` after every layout change so `pageWidth`/`pageHeight` track the content; it keeps the recommended 40px outer margin (DrawMe warns below the 20px minimum)
|
|
190
210
|
- Plan a grid before assigning x/y coordinates — sketch node positions on paper/mentally first
|
|
191
211
|
- Group related nodes in the same horizontal or vertical band
|
|
192
212
|
- Use `swimlane` cells for logical grouping with visible borders
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
# DrawMe Extension
|
|
1
|
+
# DrawMe Extension Reference
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Catalog of the commands and tools the DrawMe Pi extension provides, for any project or session that uses it.
|
|
4
4
|
|
|
5
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
6
|
|
|
7
|
-
This document
|
|
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. A successful final export removes previews previously created for the same source.
|
|
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.
|
|
7
|
+
This document lists the extension's public surface: commands, tools, options, defaults, output behavior, and limitations. It is not a workflow guide — the `/drawme` command injects the full authoring workflow itself, and the registered tool descriptions carry the operational rules. Two conventions apply everywhere: the `.drawio` file is the source of truth (exports are derived artifacts), and several tools report failures as a text result (`Export failed`, `Layout failed`, `Mermaid conversion failed`, `Fit canvas failed`, `Explain failed`, `Open failed`) rather than a tool-call error, so results must always be read.
|
|
20
8
|
|
|
21
9
|
## Functional availability
|
|
22
10
|
|
|
@@ -24,6 +12,7 @@ This document defines the extension's public functionality, options, defaults, d
|
|
|
24
12
|
| --- | --- | --- |
|
|
25
13
|
| Write or edit uncompressed `.drawio` XML with normal file tools | No | No |
|
|
26
14
|
| `drawio_validate` | No | No |
|
|
15
|
+
| `drawio_fit_canvas` | No | No |
|
|
27
16
|
| `drawio_shapesearch` | No | No |
|
|
28
17
|
| `drawio_explain` | No | No |
|
|
29
18
|
| `drawio_open` | No CLI check; requires an OS file handler | No |
|
|
@@ -31,17 +20,17 @@ This document defines the extension's public functionality, options, defaults, d
|
|
|
31
20
|
| `drawio_from_mermaid` | Yes | Yes |
|
|
32
21
|
| `drawio_layout` | Yes | Yes |
|
|
33
22
|
|
|
34
|
-
When the CLI is unavailable,
|
|
23
|
+
When the CLI is unavailable, you can still author, edit, validate, explain, and search for shapes. Skip conversion, layout, preview, and final export.
|
|
35
24
|
|
|
36
25
|
When the CLI is older than version 30, export remains available. Mermaid conversion and ELK layout do not.
|
|
37
26
|
|
|
38
27
|
## Commands
|
|
39
28
|
|
|
40
|
-
Commands are user-facing shortcuts.
|
|
29
|
+
Commands are user-facing shortcuts. Use the model-callable tools when you need explicit options or structured results.
|
|
41
30
|
|
|
42
31
|
| Command | Functionality |
|
|
43
32
|
| --- | --- |
|
|
44
|
-
| `/drawme <description>` | Starts the full
|
|
33
|
+
| `/drawme <description>` | Starts the full autonomous workflow: check, plan, author, validate, critique-first visual review, and final export — no human intervention once started. The command pre-resolves the draw.io CLI and embeds the diagram-types, XML-authoring, and (on v30+) Mermaid references into the injected message, so the run starts without tool calls or file reads; only the troubleshooting reference is read on demand. |
|
|
45
34
|
| `/drawme-check` | Displays the detected draw.io path and version, or reports that the CLI is unavailable. |
|
|
46
35
|
| `/drawme-export <file> [png\|svg\|pdf\|jpg]` | Performs a final export of an existing `.drawio`; format defaults to PNG. |
|
|
47
36
|
|
|
@@ -49,7 +38,7 @@ Commands are user-facing shortcuts. Agents should use model-callable tools when
|
|
|
49
38
|
|
|
50
39
|
## Tools
|
|
51
40
|
|
|
52
|
-
DrawMe registers
|
|
41
|
+
DrawMe registers nine model-callable tools.
|
|
53
42
|
|
|
54
43
|
### `drawio_check`
|
|
55
44
|
|
|
@@ -121,17 +110,17 @@ Additional behavior:
|
|
|
121
110
|
- An explicit `width` replaces raster scaling.
|
|
122
111
|
- `scale` is ignored in preview mode and for vector formats.
|
|
123
112
|
- `transparent` has no effect outside PNG.
|
|
124
|
-
- Preview mode defaults to unembedded output suitable for
|
|
125
|
-
- Final PNG, SVG, and PDF default to embedded/editable output.
|
|
113
|
+
- Preview mode defaults to unembedded output suitable for visual inspection. When the current model can view images, a successful PNG preview tool result contains its normal text/metadata block followed by an `image/png` base64 image block; otherwise the image is omitted. The result text always states which case applies, and the output path in the text stays usable either way.
|
|
114
|
+
- Final exports stay text-only; final PNG, SVG, and PDF default to embedded/editable output.
|
|
126
115
|
- JPG cannot carry editable XML; never set `embed: true` for JPG.
|
|
127
116
|
- Embedded PNG exports are checked for draw.io's known truncated IEND chunk and repaired automatically when necessary.
|
|
128
|
-
- Every successful preview output is tracked, including explicit `output` paths.
|
|
117
|
+
- Every successful preview output is tracked, including explicit `output` paths. After a replacement preview exists, the tool automatically removes the previous preview file for the same source, so only the latest artifact remains. The first successful final export removes that remaining preview. Cleanup failures are returned as warnings without invalidating the new export.
|
|
129
118
|
- Headless Linux handling is automatic, including `xvfb-run`, GPU disabling, and the root sandbox flag.
|
|
130
119
|
|
|
131
120
|
#### Use
|
|
132
121
|
|
|
133
122
|
```text
|
|
134
|
-
#
|
|
123
|
+
# Inspection preview (image attached when the current model can view images)
|
|
135
124
|
drawio_export({ "input": "architecture.drawio", "mode": "preview" })
|
|
136
125
|
|
|
137
126
|
# Editable final SVG
|
|
@@ -151,7 +140,7 @@ drawio_export({
|
|
|
151
140
|
})
|
|
152
141
|
```
|
|
153
142
|
|
|
154
|
-
Use a distinct `output` for each format or page. Never present a preview artifact as the final deliverable when a final export was requested. Do not manually delete
|
|
143
|
+
Use a distinct `output` for each format or page. Never present a preview artifact as the final deliverable when a final export was requested. Do not manually delete superseded or final-review previews; the tool replaces and cleans them automatically.
|
|
155
144
|
|
|
156
145
|
---
|
|
157
146
|
|
|
@@ -173,34 +162,71 @@ Errors include:
|
|
|
173
162
|
- vertices or edges reusing reserved root IDs `0` or `1`;
|
|
174
163
|
- references to missing parents;
|
|
175
164
|
- edge references to missing sources or targets;
|
|
176
|
-
- missing or invalid vertex geometry
|
|
165
|
+
- missing or invalid vertex geometry;
|
|
166
|
+
- missing edge geometry, or edge geometry without both `relative="1"` and `as="geometry"`.
|
|
177
167
|
|
|
178
|
-
|
|
168
|
+
Actionable warnings include:
|
|
179
169
|
|
|
180
|
-
- non-positive vertex dimensions;
|
|
181
|
-
- negative vertex positions;
|
|
170
|
+
- non-positive vertex dimensions and negative vertex positions;
|
|
182
171
|
- overlapping sibling leaf vertices;
|
|
183
|
-
-
|
|
184
|
-
-
|
|
172
|
+
- visible children extending outside parent containers (relative ports and edge labels are excluded);
|
|
173
|
+
- content outside finite page boundaries or below the 20px minimum outer margin;
|
|
174
|
+
- a canvas conservatively detected as substantially larger than its visible content;
|
|
175
|
+
- very small explicit label fonts and long labels in narrow nodes without wrapping;
|
|
176
|
+
- explicitly waypointed edges routed through unrelated vertices or crossing one another;
|
|
185
177
|
- compressed pages that cannot be inspected.
|
|
186
178
|
|
|
187
|
-
|
|
179
|
+
Informational observations identify checks intentionally skipped for infinite canvases or omitted/invalid page dimensions. All normal-page diagnostics are page-specific. Content bounds account for nested container offsets, visible nodes/containers, explicit waypoints, and separately sized edge labels on resolvable explicit routes where practical.
|
|
180
|
+
|
|
181
|
+
The result text and details also include a readability score:
|
|
188
182
|
|
|
189
183
|
- route through vertex: 20 points;
|
|
190
184
|
- edge crossing: 10 points;
|
|
191
185
|
- overlap: 5 points.
|
|
192
186
|
|
|
193
|
-
Lower is better, but scores are meaningful only when comparing layout variants of the same graph.
|
|
187
|
+
Lower is better, but scores are meaningful only when comparing layout variants of the same graph. Canvas, containment, and typography warnings do not change this established score. The text result separately reports error, unresolved-warning, and observation counts.
|
|
194
188
|
|
|
195
189
|
#### Use
|
|
196
190
|
|
|
197
|
-
Fix every error and rerun validation.
|
|
191
|
+
Fix every error and rerun validation. Fix each warning or record an explicit reviewed-and-acceptable reason before final export. Informational observations do not require correction.
|
|
198
192
|
|
|
199
193
|
```text
|
|
200
194
|
drawio_validate({ "input": "architecture.drawio" })
|
|
201
195
|
```
|
|
202
196
|
|
|
203
|
-
Validation is structural rather than
|
|
197
|
+
Validation is structural rather than rendered. Its static typography checks are deliberately conservative: it cannot guarantee label fit, correct semantic content, valid rendering of a guessed shape, color contrast, visual balance, or clear auto-routed edges. It does not replace preview inspection when the current model can view images.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
### `drawio_fit_canvas`
|
|
202
|
+
|
|
203
|
+
Resizes each page's canvas to its visible content plus an outer margin, without launching draw.io.
|
|
204
|
+
|
|
205
|
+
#### Options
|
|
206
|
+
|
|
207
|
+
| Option | Type | Required | Default | Description |
|
|
208
|
+
| --- | --- | --- | --- | --- |
|
|
209
|
+
| `input` | string | Yes | — | Path to the `.drawio` file. |
|
|
210
|
+
| `margin` | number | No | `40` | Outer margin in px between content and page edge. |
|
|
211
|
+
| `output` | string | No | Overwrites `input` | Destination path. |
|
|
212
|
+
|
|
213
|
+
#### Behavior
|
|
214
|
+
|
|
215
|
+
Per page:
|
|
216
|
+
|
|
217
|
+
- computes the visible content bounding box (nested containers, explicit edge waypoints, and separately sized edge labels included);
|
|
218
|
+
- sets `pageWidth`/`pageHeight` to the content size plus twice the margin, honoring `pageScale`;
|
|
219
|
+
- shifts top-level content (absolute vertices, edge waypoints, floating edge endpoints) so the content origin lands exactly at the margin — children of containers and relative geometry move with their parents and are untouched;
|
|
220
|
+
- grows cramped pages and tightens oversized ones; element sizes and relative positions never change;
|
|
221
|
+
- skips compressed pages, intentional infinite canvases (`page="0"`), and pages without measurable content;
|
|
222
|
+
- reports old → new dimensions and any applied shift per page.
|
|
223
|
+
|
|
224
|
+
The result is a source edit: validate afterwards and re-export previews. Use it whenever content overflows the page, margins fall below the minimum, the canvas has excessive empty space, or elements need more room — spread elements apart and refit the canvas instead of shrinking content.
|
|
225
|
+
|
|
226
|
+
```text
|
|
227
|
+
drawio_fit_canvas({ "input": "architecture.drawio" })
|
|
228
|
+
drawio_fit_canvas({ "input": "architecture.drawio", "margin": 60 })
|
|
229
|
+
```
|
|
204
230
|
|
|
205
231
|
---
|
|
206
232
|
|
|
@@ -247,7 +273,7 @@ drawio_from_mermaid({
|
|
|
247
273
|
})
|
|
248
274
|
```
|
|
249
275
|
|
|
250
|
-
|
|
276
|
+
The converted file is a normal `.drawio` source: it can be validated, previewed, and exported like any other.
|
|
251
277
|
|
|
252
278
|
---
|
|
253
279
|
|
|
@@ -379,115 +405,14 @@ drawio_open({ "path": "architecture.drawio" })
|
|
|
379
405
|
| Existing diagram only needs validation | `drawio_validate`; no CLI check is necessary. |
|
|
380
406
|
| Existing diagram only needs export | `drawio_check` → `drawio_export`; do not rebuild it. |
|
|
381
407
|
|
|
382
|
-
DrawMe does not expose a single natural-language-to-file tool.
|
|
383
|
-
|
|
384
|
-
## Creation workflow
|
|
385
|
-
|
|
386
|
-
### 1. Check
|
|
387
|
-
|
|
388
|
-
Call `drawio_check` and record whether export is available and whether Mermaid/layout features are supported.
|
|
389
|
-
|
|
390
|
-
### 2. Plan
|
|
391
|
-
|
|
392
|
-
Choose:
|
|
393
|
-
|
|
394
|
-
- diagram type;
|
|
395
|
-
- components and relations;
|
|
396
|
-
- groups or containers;
|
|
397
|
-
- top-to-bottom or left-to-right direction;
|
|
398
|
-
- Mermaid or XML authoring mode;
|
|
399
|
-
- source path, pages, and final formats.
|
|
400
|
-
|
|
401
|
-
Call `drawio_shapesearch` during planning whenever an exact library shape is required.
|
|
402
|
-
|
|
403
|
-
### 3. Author
|
|
404
|
-
|
|
405
|
-
For Mermaid, write concise valid Mermaid and convert it with `drawio_from_mermaid`.
|
|
406
|
-
|
|
407
|
-
For XML, use an uncompressed `<mxGraphModel>`. The minimum authoring contract is:
|
|
408
|
-
|
|
409
|
-
- include root cells `id="0"` and `id="1"`;
|
|
410
|
-
- reserve IDs `0` and `1` for those root cells;
|
|
411
|
-
- assign every other cell a unique ID and valid parent;
|
|
412
|
-
- assign every vertex positive geometry;
|
|
413
|
-
- assign every edge valid source and target IDs;
|
|
414
|
-
- include `<mxGeometry relative="1" as="geometry" />` in every edge;
|
|
415
|
-
- escape XML attribute characters and use `
` for label line breaks;
|
|
416
|
-
- use coordinates relative to the actual parent container;
|
|
417
|
-
- leave spacing and routing corridors for labels, edges, and arrowheads.
|
|
418
|
-
|
|
419
|
-
For large XML graphs on draw.io 30+, run `drawio_layout` and continue using its returned path.
|
|
420
|
-
|
|
421
|
-
### 4. Validate
|
|
422
|
-
|
|
423
|
-
Run `drawio_validate` on the exact source that will be exported. Fix every error and rerun validation. Assess warnings before continuing.
|
|
424
|
-
|
|
425
|
-
### 5. Preview and inspect
|
|
426
|
-
|
|
427
|
-
Export a PNG with:
|
|
428
|
-
|
|
429
|
-
```text
|
|
430
|
-
drawio_export({ "input": "<source>.drawio", "mode": "preview" })
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
Read the PNG with vision and verify:
|
|
434
|
-
|
|
435
|
-
- requested components and relations are present;
|
|
436
|
-
- labels are readable and not clipped;
|
|
437
|
-
- nodes do not overlap or leave the canvas;
|
|
438
|
-
- edges connect the intended endpoints;
|
|
439
|
-
- arrowheads and decision labels are visible;
|
|
440
|
-
- edges do not stack, cross unnecessarily, or route through unrelated nodes;
|
|
441
|
-
- grouping, alignment, spacing, contrast, and hierarchy are clear.
|
|
442
|
-
|
|
443
|
-
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.
|
|
444
|
-
|
|
445
|
-
### 6. Final export
|
|
446
|
-
|
|
447
|
-
After visual review, export each requested format and page with `mode: "final"`. The first successful final export automatically removes preview artifacts for that source. Report:
|
|
448
|
-
|
|
449
|
-
- source `.drawio` path;
|
|
450
|
-
- validation status and retained warnings;
|
|
451
|
-
- preview inspection outcome, noting that the temporary artifact was removed;
|
|
452
|
-
- every final output path and format;
|
|
453
|
-
- whether each output embeds editable XML;
|
|
454
|
-
- any unavailable or skipped functionality.
|
|
455
|
-
|
|
456
|
-
## Existing-diagram workflows
|
|
457
|
-
|
|
458
|
-
### Explain
|
|
459
|
-
|
|
460
|
-
Use `drawio_explain` for a structured read-back. For exact edits, inspect the XML after obtaining the summary.
|
|
461
|
-
|
|
462
|
-
### Validate
|
|
463
|
-
|
|
464
|
-
Use `drawio_validate` directly. A CLI check is unnecessary unless an export will follow.
|
|
465
|
-
|
|
466
|
-
### Edit
|
|
467
|
-
|
|
468
|
-
1. Preserve the original unless replacement was requested.
|
|
469
|
-
2. Explain and inspect the source.
|
|
470
|
-
3. Make the smallest targeted XML change.
|
|
471
|
-
4. Validate the edited source.
|
|
472
|
-
5. Preview and compare the requested behavior visually.
|
|
473
|
-
6. Export to a new path unless in-place replacement was requested.
|
|
474
|
-
|
|
475
|
-
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.
|
|
476
|
-
|
|
477
|
-
### Export
|
|
478
|
-
|
|
479
|
-
Check the CLI, then call `drawio_export` with the requested format and options. Do not reconstruct a valid existing source merely to export it.
|
|
480
|
-
|
|
481
|
-
### Re-layout
|
|
482
|
-
|
|
483
|
-
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.
|
|
408
|
+
DrawMe does not expose a single natural-language-to-file tool. Author or edit Mermaid/XML with normal file tools, then use DrawMe for conversion, layout, validation, rendering, explanation, or opening.
|
|
484
409
|
|
|
485
410
|
## Output and editability semantics
|
|
486
411
|
|
|
487
412
|
- `.drawio` is always the canonical editable source.
|
|
488
413
|
- Final PNG, SVG, and PDF embed XML by default and can be reopened in draw.io where supported.
|
|
489
414
|
- JPG cannot embed XML.
|
|
490
|
-
- Preview PNG is intentionally clean and unembedded for
|
|
415
|
+
- Preview PNG is intentionally clean and unembedded for visual inspection. Its successful tool result includes the image when the current model can view images, and the text always states whether it was attached and reports the output path. Each successful replacement removes the prior same-source preview file, and final export removes the latest remaining preview.
|
|
491
416
|
- A final embedded PNG normally uses the `.drawio.png` double extension.
|
|
492
417
|
- Multi-page exports should use `pageIndex` and explicit unique output names.
|
|
493
418
|
- `drawio_explain` returns Markdown as text; it does not write a documentation file.
|
|
@@ -498,8 +423,9 @@ Use `drawio_layout` only for XML-authored or existing native diagrams on draw.io
|
|
|
498
423
|
|
|
499
424
|
- Validation cannot inspect compressed pages.
|
|
500
425
|
- Explanation cannot describe compressed pages.
|
|
501
|
-
-
|
|
502
|
-
-
|
|
426
|
+
- Deterministic validation cannot replace visual inspection; rendered clipping, wrapping, contrast, and automatic routes can only be judged from the preview image. When the current model cannot view images, these remain unverified and must be reported as such.
|
|
427
|
+
- Removing a superseded preview file does not rewrite Pi session history: image blocks already stored in earlier tool-result messages can remain visible in the transcript even though only the latest preview file remains on disk.
|
|
428
|
+
- Route-through and crossing analysis is limited to edges with explicit waypoints; dense auto-routed graphs can validate without connector-route warnings.
|
|
503
429
|
- Shape search covers bundled official draw.io shapes, not arbitrary third-party logos.
|
|
504
430
|
- Mermaid conversion cannot express all draw.io styles, containers, routing, or multi-page behavior.
|
|
505
431
|
- ELK layout accepts only the six registered presets; arbitrary JSON layouts are not exposed.
|